@namzu/sdk 52.0.0 → 52.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +29 -0
- package/README.md +1 -1
- package/dist/compaction/verifier.d.ts.map +1 -1
- package/dist/compaction/verifier.js +57 -17
- package/dist/compaction/verifier.js.map +1 -1
- package/dist/connector/tools/adapter.d.ts +2 -2
- package/dist/contracts/a2a.d.ts +94 -94
- package/dist/manager/resident/learning.d.ts +6 -6
- package/dist/manager/resident/store.d.ts +4 -4
- package/dist/pals/activity/subscription-schema.d.ts +48 -48
- package/dist/pals/communication/ingress-schema.d.ts +192 -192
- package/dist/pals/communication/schema.d.ts +18 -18
- package/dist/peers/protocol.d.ts +36 -36
- package/dist/provider/capabilities.d.ts +9 -0
- package/dist/provider/capabilities.d.ts.map +1 -1
- package/dist/provider/capabilities.js +15 -0
- package/dist/provider/capabilities.js.map +1 -1
- package/dist/provider/errors.d.ts.map +1 -1
- package/dist/provider/errors.js +13 -0
- package/dist/provider/errors.js.map +1 -1
- package/dist/provider/fallback.d.ts.map +1 -1
- package/dist/provider/fallback.js +10 -0
- package/dist/provider/fallback.js.map +1 -1
- package/dist/provider/idle-timeout.d.ts.map +1 -1
- package/dist/provider/idle-timeout.js +5 -0
- package/dist/provider/idle-timeout.js.map +1 -1
- package/dist/provider/image-input-refusal.d.ts +9 -0
- package/dist/provider/image-input-refusal.d.ts.map +1 -0
- package/dist/provider/image-input-refusal.js +54 -0
- package/dist/provider/image-input-refusal.js.map +1 -0
- package/dist/provider/index.d.ts +2 -1
- package/dist/provider/index.d.ts.map +1 -1
- package/dist/provider/index.js +2 -1
- package/dist/provider/index.js.map +1 -1
- package/dist/provider/retry.d.ts +7 -2
- package/dist/provider/retry.d.ts.map +1 -1
- package/dist/provider/retry.js +38 -4
- package/dist/provider/retry.js.map +1 -1
- package/dist/public-runtime.d.ts +2 -1
- package/dist/public-runtime.d.ts.map +1 -1
- package/dist/public-runtime.js +1 -1
- package/dist/public-runtime.js.map +1 -1
- package/dist/public-tools.d.ts +1 -0
- package/dist/public-tools.d.ts.map +1 -1
- package/dist/public-tools.js +1 -0
- package/dist/public-tools.js.map +1 -1
- package/dist/runtime/query/deferred-sandbox.d.ts +54 -0
- package/dist/runtime/query/deferred-sandbox.d.ts.map +1 -0
- package/dist/runtime/query/deferred-sandbox.js +75 -0
- package/dist/runtime/query/deferred-sandbox.js.map +1 -0
- package/dist/runtime/query/executor.d.ts +11 -0
- package/dist/runtime/query/executor.d.ts.map +1 -1
- package/dist/runtime/query/executor.js +25 -3
- package/dist/runtime/query/executor.js.map +1 -1
- package/dist/runtime/query/index.d.ts +2 -0
- package/dist/runtime/query/index.d.ts.map +1 -1
- package/dist/runtime/query/index.js +94 -25
- package/dist/runtime/query/index.js.map +1 -1
- package/dist/runtime/query/iteration/index.d.ts +26 -0
- package/dist/runtime/query/iteration/index.d.ts.map +1 -1
- package/dist/runtime/query/iteration/index.js +164 -21
- package/dist/runtime/query/iteration/index.js.map +1 -1
- package/dist/runtime/query/iteration/phases/compaction-breaker.d.ts +10 -7
- package/dist/runtime/query/iteration/phases/compaction-breaker.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/compaction-breaker.js +10 -7
- package/dist/runtime/query/iteration/phases/compaction-breaker.js.map +1 -1
- package/dist/runtime/query/iteration/phases/compaction.d.ts +42 -1
- package/dist/runtime/query/iteration/phases/compaction.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/compaction.js +119 -21
- package/dist/runtime/query/iteration/phases/compaction.js.map +1 -1
- package/dist/runtime/query/iteration/provider-rejected-image.d.ts +21 -1
- package/dist/runtime/query/iteration/provider-rejected-image.d.ts.map +1 -1
- package/dist/runtime/query/iteration/provider-rejected-image.js +53 -7
- package/dist/runtime/query/iteration/provider-rejected-image.js.map +1 -1
- package/dist/runtime/query/iteration/request-repair.d.ts +108 -0
- package/dist/runtime/query/iteration/request-repair.d.ts.map +1 -0
- package/dist/runtime/query/iteration/request-repair.js +593 -0
- package/dist/runtime/query/iteration/request-repair.js.map +1 -0
- package/dist/runtime/query/iteration/stream-turn.d.ts +6 -0
- package/dist/runtime/query/iteration/stream-turn.d.ts.map +1 -1
- package/dist/runtime/query/iteration/stream-turn.js +2 -2
- package/dist/runtime/query/iteration/stream-turn.js.map +1 -1
- package/dist/runtime/query/request-rich-content.d.ts +5 -1
- package/dist/runtime/query/request-rich-content.d.ts.map +1 -1
- package/dist/runtime/query/request-rich-content.js +67 -25
- package/dist/runtime/query/request-rich-content.js.map +1 -1
- package/dist/runtime/query/tooling.d.ts +1 -0
- package/dist/runtime/query/tooling.d.ts.map +1 -1
- package/dist/runtime/query/tooling.js +1 -0
- package/dist/runtime/query/tooling.js.map +1 -1
- package/dist/tools/builtins/browser.d.ts +4 -4
- package/dist/tools/builtins/code-analysis.d.ts +49 -0
- package/dist/tools/builtins/code-analysis.d.ts.map +1 -0
- package/dist/tools/builtins/code-analysis.js +409 -0
- package/dist/tools/builtins/code-analysis.js.map +1 -0
- package/dist/tools/builtins/computer-use.d.ts +25 -25
- package/dist/tools/builtins/computer-use.d.ts.map +1 -1
- package/dist/tools/builtins/computer-use.js +12 -5
- package/dist/tools/builtins/computer-use.js.map +1 -1
- package/dist/tools/builtins/index.d.ts +1 -0
- package/dist/tools/builtins/index.d.ts.map +1 -1
- package/dist/tools/builtins/index.js +1 -0
- package/dist/tools/builtins/index.js.map +1 -1
- package/dist/tools/builtins/lsp.d.ts +1 -1
- package/dist/tools/builtins/skill.d.ts +2 -2
- package/dist/types/code-analysis/index.d.ts +299 -0
- package/dist/types/code-analysis/index.d.ts.map +1 -0
- package/dist/types/code-analysis/index.js +30 -0
- package/dist/types/code-analysis/index.js.map +1 -0
- package/dist/types/plugin/index.d.ts +6 -6
- package/dist/types/provider/errors.d.ts.map +1 -1
- package/dist/types/provider/errors.js +30 -5
- package/dist/types/provider/errors.js.map +1 -1
- package/dist/types/provider/interface.d.ts +12 -0
- package/dist/types/provider/interface.d.ts.map +1 -1
- package/dist/types/provider/stream.d.ts +1 -1
- package/dist/types/session/config.d.ts +14 -0
- package/dist/types/session/config.d.ts.map +1 -1
- package/dist/types/session/events.d.ts +20 -5
- package/dist/types/session/events.d.ts.map +1 -1
- package/dist/types/session/events.js.map +1 -1
- package/dist/types/session/records.d.ts +127 -127
- package/dist/types/tool/index.d.ts +9 -0
- package/dist/types/tool/index.d.ts.map +1 -1
- package/dist/types/tool/index.js.map +1 -1
- package/package.json +2 -2
- package/src/compaction/verifier.ts +57 -20
- package/src/provider/capabilities.ts +17 -0
- package/src/provider/errors.ts +13 -0
- package/src/provider/fallback.ts +10 -0
- package/src/provider/idle-timeout.ts +5 -0
- package/src/provider/image-input-refusal.ts +54 -0
- package/src/provider/index.ts +2 -0
- package/src/provider/retry.ts +42 -4
- package/src/public-runtime.ts +28 -0
- package/src/public-tools.ts +5 -0
- package/src/runtime/query/deferred-sandbox.ts +110 -0
- package/src/runtime/query/executor.ts +27 -3
- package/src/runtime/query/index.ts +127 -49
- package/src/runtime/query/iteration/index.ts +188 -23
- package/src/runtime/query/iteration/phases/compaction-breaker.ts +10 -8
- package/src/runtime/query/iteration/phases/compaction.ts +151 -35
- package/src/runtime/query/iteration/provider-rejected-image.ts +71 -5
- package/src/runtime/query/iteration/request-repair.ts +743 -0
- package/src/runtime/query/iteration/stream-turn.ts +11 -1
- package/src/runtime/query/request-rich-content.ts +77 -27
- package/src/runtime/query/tooling.ts +2 -0
- package/src/tools/builtins/code-analysis.ts +486 -0
- package/src/tools/builtins/computer-use.ts +13 -4
- package/src/tools/builtins/index.ts +5 -0
- package/src/types/code-analysis/index.ts +325 -0
- package/src/types/provider/errors.ts +33 -5
- package/src/types/provider/interface.ts +13 -0
- package/src/types/provider/stream.ts +1 -1
- package/src/types/session/config.ts +14 -0
- package/src/types/session/events.ts +25 -5
- package/src/types/tool/index.ts +9 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isProviderRequestError } from '../../../provider/errors.js'
|
|
2
|
+
import { isImageInputRefusal } from '../../../provider/image-input-refusal.js'
|
|
2
3
|
import type { Message } from '../../../types/message/index.js'
|
|
3
4
|
import type {
|
|
4
5
|
ChatCompletionParams,
|
|
@@ -8,8 +9,11 @@ import type {
|
|
|
8
9
|
import {
|
|
9
10
|
type RequestImageIdentity,
|
|
10
11
|
findSingleRequestImage,
|
|
12
|
+
projectRequestRichContent,
|
|
11
13
|
projectRequestWithoutImage,
|
|
14
|
+
requestHasImages,
|
|
12
15
|
} from '../request-rich-content.js'
|
|
16
|
+
import type { RequestRepair } from './request-repair.js'
|
|
13
17
|
|
|
14
18
|
const IMAGE_REJECTION_PATTERNS: readonly RegExp[] = [
|
|
15
19
|
/\binvalid[_ -]?image\b/i,
|
|
@@ -52,6 +56,24 @@ function throwIfAborted(signal: AbortSignal | undefined): void {
|
|
|
52
56
|
if (signal?.aborted) throw signal.reason
|
|
53
57
|
}
|
|
54
58
|
|
|
59
|
+
/** The provider and model that refused a request for holding an image. */
|
|
60
|
+
export interface TextOnlyModelRefusal {
|
|
61
|
+
readonly providerId: string
|
|
62
|
+
readonly model: string | undefined
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** See {@link streamWithProviderRejectedImageRecovery}. */
|
|
66
|
+
export interface TextOnlyModelRecovery {
|
|
67
|
+
/**
|
|
68
|
+
* Who is serving the request. A fallback chain reports its head's id and
|
|
69
|
+
* moves between members, so without this the refusal would be filed against
|
|
70
|
+
* a model that never saw the request. Read when the refusal arrives.
|
|
71
|
+
*/
|
|
72
|
+
readonly servedBy?: () => { readonly providerId: string; readonly model?: string }
|
|
73
|
+
/** The retry without images was accepted: `refused` cannot read images. */
|
|
74
|
+
readonly onAccepted: (refused: TextOnlyModelRefusal) => void | Promise<void>
|
|
75
|
+
}
|
|
76
|
+
|
|
55
77
|
/**
|
|
56
78
|
* Retry one provider-invalid request without its only distinct image.
|
|
57
79
|
*
|
|
@@ -65,29 +87,73 @@ export async function* streamWithProviderRejectedImageRecovery(
|
|
|
65
87
|
params: ChatCompletionParams,
|
|
66
88
|
onAccepted: (identity: RequestImageIdentity) => Promise<void>,
|
|
67
89
|
onRequest?: (messages: readonly Message[]) => void,
|
|
90
|
+
textOnly?: TextOnlyModelRecovery,
|
|
91
|
+
repair?: RequestRepair,
|
|
68
92
|
): AsyncIterable<StreamChunk> {
|
|
93
|
+
// Every send, including the retries below, goes through the request repair.
|
|
94
|
+
// They share one repair budget: the original request and its retries are
|
|
95
|
+
// one request to the person, and each resend is a paid call.
|
|
96
|
+
const session = repair?.session()
|
|
97
|
+
const send = (request: ChatCompletionParams): AsyncIterable<StreamChunk> =>
|
|
98
|
+
repair ? repair.stream(provider, request, session) : provider.chatStream(request)
|
|
69
99
|
const candidate = findSingleRequestImage(params.messages)
|
|
70
100
|
onRequest?.(params.messages)
|
|
71
|
-
if (candidate === null) {
|
|
72
|
-
yield*
|
|
101
|
+
if (candidate === null && !requestHasImages(params.messages)) {
|
|
102
|
+
yield* send(params)
|
|
73
103
|
return
|
|
74
104
|
}
|
|
75
105
|
|
|
76
106
|
let produced = false
|
|
77
107
|
let confidence: ImageRejectionConfidence | null = null
|
|
108
|
+
let refused: TextOnlyModelRefusal | null = null
|
|
78
109
|
try {
|
|
79
|
-
for await (const chunk of
|
|
110
|
+
for await (const chunk of send(params)) {
|
|
80
111
|
if (isAcceptedChunk(chunk)) produced = true
|
|
81
112
|
yield chunk
|
|
82
113
|
}
|
|
83
114
|
return
|
|
84
115
|
} catch (error) {
|
|
85
116
|
throwIfAborted(params.signal)
|
|
117
|
+
if (produced) throw error
|
|
118
|
+
// A fault in one image (the server's own `invalid_image`, or wording that
|
|
119
|
+
// says an image could not be decoded) is about that image, not about the
|
|
120
|
+
// model, and it wins: the model reads images, so it keeps the others.
|
|
86
121
|
confidence = classifyProviderRejectedImageError(error)
|
|
87
|
-
if (
|
|
122
|
+
if (confidence === null && isImageInputRefusal(error)) {
|
|
123
|
+
// A model that reads text only refuses the request however many images
|
|
124
|
+
// it holds, so every image goes. Named now, while the member that
|
|
125
|
+
// refused is still the one serving.
|
|
126
|
+
const served = textOnly?.servedBy?.()
|
|
127
|
+
refused = {
|
|
128
|
+
providerId: served?.providerId ?? provider.id,
|
|
129
|
+
model: served?.model ?? params.model,
|
|
130
|
+
}
|
|
131
|
+
} else if (confidence === null || candidate === null) {
|
|
132
|
+
throw error
|
|
133
|
+
}
|
|
88
134
|
}
|
|
89
135
|
|
|
90
136
|
throwIfAborted(params.signal)
|
|
137
|
+
if (refused !== null) {
|
|
138
|
+
// One retry, without any image. The stored conversation is untouched, so
|
|
139
|
+
// a model that does read images gets them again.
|
|
140
|
+
const messages = projectRequestRichContent(params.messages, 0, { imagesReadable: false })
|
|
141
|
+
onRequest?.(messages)
|
|
142
|
+
let accepted = false
|
|
143
|
+
let reportedError = false
|
|
144
|
+
for await (const chunk of send({ ...params, messages })) {
|
|
145
|
+
if (chunk.error !== undefined) reportedError = true
|
|
146
|
+
if (!accepted && isAcceptedChunk(chunk)) {
|
|
147
|
+
throwIfAborted(params.signal)
|
|
148
|
+
await textOnly?.onAccepted(refused)
|
|
149
|
+
accepted = true
|
|
150
|
+
}
|
|
151
|
+
yield chunk
|
|
152
|
+
}
|
|
153
|
+
if (!accepted && !reportedError) await textOnly?.onAccepted(refused)
|
|
154
|
+
return
|
|
155
|
+
}
|
|
156
|
+
if (candidate === null) return
|
|
91
157
|
const retryParams: ChatCompletionParams = {
|
|
92
158
|
...params,
|
|
93
159
|
messages: projectRequestWithoutImage(params.messages, candidate),
|
|
@@ -95,7 +161,7 @@ export async function* streamWithProviderRejectedImageRecovery(
|
|
|
95
161
|
let accepted = false
|
|
96
162
|
let retryReportedError = false
|
|
97
163
|
onRequest?.(retryParams.messages)
|
|
98
|
-
for await (const chunk of
|
|
164
|
+
for await (const chunk of send(retryParams)) {
|
|
99
165
|
if (chunk.error !== undefined) retryReportedError = true
|
|
100
166
|
if (!accepted && isAcceptedChunk(chunk)) {
|
|
101
167
|
throwIfAborted(params.signal)
|