@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
|
@@ -42,7 +42,11 @@ import { generateMessageId, generateToolCallId } from '../../../utils/id.js'
|
|
|
42
42
|
import type { Logger } from '../../../utils/logger.js'
|
|
43
43
|
import type { EmitEvent } from '../events.js'
|
|
44
44
|
import type { RequestImageIdentity } from '../request-rich-content.js'
|
|
45
|
-
import {
|
|
45
|
+
import {
|
|
46
|
+
type TextOnlyModelRecovery,
|
|
47
|
+
streamWithProviderRejectedImageRecovery,
|
|
48
|
+
} from './provider-rejected-image.js'
|
|
49
|
+
import type { RequestRepair } from './request-repair.js'
|
|
46
50
|
import {
|
|
47
51
|
type ParsedToolArguments,
|
|
48
52
|
capPartialArguments,
|
|
@@ -237,6 +241,10 @@ export async function* streamProviderTurn(
|
|
|
237
241
|
announceAs?: import('../../../types/ids/index.js').MessageId,
|
|
238
242
|
imageRecovery?: {
|
|
239
243
|
readonly onAccepted: (identity: RequestImageIdentity) => Promise<void>
|
|
244
|
+
/** A model refused the request for holding an image it cannot read; the retry sent none. */
|
|
245
|
+
readonly textOnly?: TextOnlyModelRecovery
|
|
246
|
+
/** Repairs and resends a request the provider rejects as invalid. */
|
|
247
|
+
readonly repair?: RequestRepair
|
|
240
248
|
},
|
|
241
249
|
captureRequest = false,
|
|
242
250
|
/** The session the turn belongs to, named on the chat span as `gen_ai.conversation.id`. */
|
|
@@ -363,6 +371,8 @@ export async function* streamProviderTurn(
|
|
|
363
371
|
streamParams,
|
|
364
372
|
imageRecovery.onAccepted,
|
|
365
373
|
observeRequest,
|
|
374
|
+
imageRecovery.textOnly,
|
|
375
|
+
imageRecovery.repair,
|
|
366
376
|
)
|
|
367
377
|
: provider.chatStream(streamParams)
|
|
368
378
|
) as AsyncIterable<StreamChunk>
|
|
@@ -34,7 +34,8 @@ interface RichOccurrence {
|
|
|
34
34
|
readonly source: 'user' | 'tool'
|
|
35
35
|
readonly kind: RichKind
|
|
36
36
|
readonly bytes: number
|
|
37
|
-
readonly
|
|
37
|
+
readonly mediaType?: string
|
|
38
|
+
readonly reason: 'budget' | 'provider-rejected' | 'invalid-image' | 'model-text-only'
|
|
38
39
|
}
|
|
39
40
|
|
|
40
41
|
export interface RequestImageIdentity {
|
|
@@ -65,6 +66,24 @@ const invalidUserImageMarker = (): string =>
|
|
|
65
66
|
const invalidToolImageMarker = (): string =>
|
|
66
67
|
`[image omitted from this model request because the producing tool returned encoded bytes that are not a complete supported raster matching the declared media type. ${toolRecovery} Correct the image source before presenting it again.]`
|
|
67
68
|
|
|
69
|
+
/** `12 KB`-style size of an encoded payload, so the model can tell a thumbnail from a full screenshot. */
|
|
70
|
+
function describeEncodedSize(base64Length: number): string {
|
|
71
|
+
const bytes = Math.floor((base64Length * 3) / 4)
|
|
72
|
+
if (bytes < 1024) return `${bytes} B`
|
|
73
|
+
if (bytes < 1024 * 1024) return `${Math.round(bytes / 1024)} KB`
|
|
74
|
+
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* What stands in for an image the current model cannot read. It says so, and
|
|
79
|
+
* what the image was, because the model otherwise sees a tool that reported
|
|
80
|
+
* success next to nothing and tends to retry it or claim to have seen the screen.
|
|
81
|
+
*/
|
|
82
|
+
const textOnlyImageMarker = (mediaType: string | undefined, base64Length: number): string =>
|
|
83
|
+
`[image omitted: the current model cannot read images${
|
|
84
|
+
mediaType ? ` (${mediaType}, ${describeEncodedSize(base64Length)})` : ''
|
|
85
|
+
}]`
|
|
86
|
+
|
|
68
87
|
function assertInlineAttachment(
|
|
69
88
|
attachment: MessageAttachment,
|
|
70
89
|
): asserts attachment is Exclude<MessageAttachment, { readonly type: 'stored' }> {
|
|
@@ -75,7 +94,10 @@ function assertInlineAttachment(
|
|
|
75
94
|
}
|
|
76
95
|
}
|
|
77
96
|
|
|
78
|
-
function collectRichOccurrences(
|
|
97
|
+
function collectRichOccurrences(
|
|
98
|
+
messages: readonly Message[],
|
|
99
|
+
imagesReadable: boolean,
|
|
100
|
+
): RichOccurrence[] {
|
|
79
101
|
const occurrences: RichOccurrence[] = []
|
|
80
102
|
|
|
81
103
|
for (const [messageIndex, message] of messages.entries()) {
|
|
@@ -88,13 +110,17 @@ function collectRichOccurrences(messages: readonly Message[]): RichOccurrence[]
|
|
|
88
110
|
source: 'user',
|
|
89
111
|
kind: attachment.type === 'document' ? 'document' : 'image',
|
|
90
112
|
bytes: attachment.data.length,
|
|
113
|
+
mediaType: attachment.mediaType,
|
|
91
114
|
reason:
|
|
92
|
-
attachment.type !== 'document' &&
|
|
93
|
-
? '
|
|
115
|
+
attachment.type !== 'document' && !imagesReadable
|
|
116
|
+
? 'model-text-only'
|
|
94
117
|
: attachment.type !== 'document' &&
|
|
95
|
-
attachment.modelOmission?.reason === '
|
|
96
|
-
? '
|
|
97
|
-
: '
|
|
118
|
+
attachment.modelOmission?.reason === 'invalid-image'
|
|
119
|
+
? 'invalid-image'
|
|
120
|
+
: attachment.type !== 'document' &&
|
|
121
|
+
attachment.modelOmission?.reason === 'provider-rejected'
|
|
122
|
+
? 'provider-rejected'
|
|
123
|
+
: 'budget',
|
|
98
124
|
})
|
|
99
125
|
}
|
|
100
126
|
continue
|
|
@@ -109,12 +135,15 @@ function collectRichOccurrences(messages: readonly Message[]): RichOccurrence[]
|
|
|
109
135
|
source: 'tool',
|
|
110
136
|
kind: block.type,
|
|
111
137
|
bytes: block.data.length,
|
|
138
|
+
mediaType: block.mediaType,
|
|
112
139
|
reason:
|
|
113
|
-
block.type === 'image' &&
|
|
114
|
-
? '
|
|
115
|
-
: block.type === 'image' && block.modelOmission?.reason === '
|
|
116
|
-
? '
|
|
117
|
-
: '
|
|
140
|
+
block.type === 'image' && !imagesReadable
|
|
141
|
+
? 'model-text-only'
|
|
142
|
+
: block.type === 'image' && block.modelOmission?.reason === 'invalid-image'
|
|
143
|
+
? 'invalid-image'
|
|
144
|
+
: block.type === 'image' && block.modelOmission?.reason === 'provider-rejected'
|
|
145
|
+
? 'provider-rejected'
|
|
146
|
+
: 'budget',
|
|
118
147
|
})
|
|
119
148
|
}
|
|
120
149
|
}
|
|
@@ -130,11 +159,13 @@ function appendTextMarkers(content: string, markers: readonly string[]): string
|
|
|
130
159
|
|
|
131
160
|
function appendMarkers(content: string, occurrences: readonly RichOccurrence[]): string {
|
|
132
161
|
const markers = occurrences.map((occurrence) =>
|
|
133
|
-
occurrence.reason === '
|
|
134
|
-
?
|
|
135
|
-
: occurrence.reason === '
|
|
136
|
-
?
|
|
137
|
-
:
|
|
162
|
+
occurrence.reason === 'model-text-only'
|
|
163
|
+
? textOnlyImageMarker(occurrence.mediaType, occurrence.bytes)
|
|
164
|
+
: occurrence.reason === 'provider-rejected'
|
|
165
|
+
? rejectedUserImageMarker()
|
|
166
|
+
: occurrence.reason === 'invalid-image'
|
|
167
|
+
? invalidUserImageMarker()
|
|
168
|
+
: userMarker(occurrence.kind),
|
|
138
169
|
)
|
|
139
170
|
return appendTextMarkers(content, markers)
|
|
140
171
|
}
|
|
@@ -148,8 +179,12 @@ function appendMarkers(content: string, occurrences: readonly RichOccurrence[]):
|
|
|
148
179
|
* original array when nothing is omitted makes the no-op and exact-boundary
|
|
149
180
|
* cases observable and keeps the common path allocation-free.
|
|
150
181
|
*/
|
|
151
|
-
export function projectRequestRichContent(
|
|
152
|
-
|
|
182
|
+
export function projectRequestRichContent(
|
|
183
|
+
messages: Message[],
|
|
184
|
+
maxBytes: number,
|
|
185
|
+
options: { readonly imagesReadable?: boolean } = {},
|
|
186
|
+
): Message[] {
|
|
187
|
+
const occurrences = collectRichOccurrences(messages, options.imagesReadable ?? true)
|
|
153
188
|
if (occurrences.length === 0) return messages
|
|
154
189
|
|
|
155
190
|
const omitted = new Map<number, Map<number, RichOccurrence>>()
|
|
@@ -163,9 +198,7 @@ export function projectRequestRichContent(messages: Message[], maxBytes: number)
|
|
|
163
198
|
}
|
|
164
199
|
|
|
165
200
|
for (const occurrence of occurrences) {
|
|
166
|
-
if (occurrence.reason
|
|
167
|
-
omit(occurrence)
|
|
168
|
-
}
|
|
201
|
+
if (occurrence.reason !== 'budget') omit(occurrence)
|
|
169
202
|
}
|
|
170
203
|
|
|
171
204
|
let total = occurrences.reduce(
|
|
@@ -206,11 +239,13 @@ export function projectRequestRichContent(messages: Message[], maxBytes: number)
|
|
|
206
239
|
? {
|
|
207
240
|
type: 'text',
|
|
208
241
|
text:
|
|
209
|
-
occurrence.reason === '
|
|
210
|
-
?
|
|
211
|
-
: occurrence.reason === '
|
|
212
|
-
?
|
|
213
|
-
:
|
|
242
|
+
occurrence.reason === 'model-text-only'
|
|
243
|
+
? textOnlyImageMarker(occurrence.mediaType, occurrence.bytes)
|
|
244
|
+
: occurrence.reason === 'provider-rejected'
|
|
245
|
+
? rejectedToolImageMarker()
|
|
246
|
+
: occurrence.reason === 'invalid-image'
|
|
247
|
+
? invalidToolImageMarker()
|
|
248
|
+
: toolMarker(occurrence.kind),
|
|
214
249
|
}
|
|
215
250
|
: block
|
|
216
251
|
})
|
|
@@ -221,6 +256,21 @@ export function projectRequestRichContent(messages: Message[], maxBytes: number)
|
|
|
221
256
|
})
|
|
222
257
|
}
|
|
223
258
|
|
|
259
|
+
/** Whether the provider-bound request carries an image anywhere, in a user attachment or a tool result. */
|
|
260
|
+
export function requestHasImages(messages: readonly Message[]): boolean {
|
|
261
|
+
for (const message of messages) {
|
|
262
|
+
if (message.role === 'user') {
|
|
263
|
+
for (const attachment of message.attachments ?? []) {
|
|
264
|
+
if (attachment.type !== 'stored' && attachment.type !== 'document') return true
|
|
265
|
+
}
|
|
266
|
+
continue
|
|
267
|
+
}
|
|
268
|
+
if (message.role !== 'tool' || !Array.isArray(message.content)) continue
|
|
269
|
+
if (message.content.some((block) => block.type === 'image')) return true
|
|
270
|
+
}
|
|
271
|
+
return false
|
|
272
|
+
}
|
|
273
|
+
|
|
224
274
|
function sameImage(
|
|
225
275
|
image: { readonly data: string; readonly mediaType: string },
|
|
226
276
|
identity: RequestImageIdentity,
|
|
@@ -19,6 +19,7 @@ import type { EmitEvent } from './events.js'
|
|
|
19
19
|
|
|
20
20
|
export interface ToolingBootstrapConfig {
|
|
21
21
|
fileReadTracker?: import('../../types/tool/index.js').FileReadTracker
|
|
22
|
+
codeAnalysis?: import('../../types/code-analysis/index.js').CodeAnalysisProvider
|
|
22
23
|
tools: ToolManager
|
|
23
24
|
/** Exact runtime output-tool owner for opt-in JSON retention; see ToolExecutorConfig. */
|
|
24
25
|
durableStructuredOutputTool?: ToolDefinition
|
|
@@ -86,6 +87,7 @@ export class ToolingBootstrap {
|
|
|
86
87
|
? { durableStructuredOutputTool: config.durableStructuredOutputTool }
|
|
87
88
|
: {}),
|
|
88
89
|
...(config.fileReadTracker ? { fileReadTracker: config.fileReadTracker } : {}),
|
|
90
|
+
...(config.codeAnalysis ? { codeAnalysis: config.codeAnalysis } : {}),
|
|
89
91
|
sessionId: config.sessionId,
|
|
90
92
|
turnId: config.turnId,
|
|
91
93
|
workingDirectory: config.workingDirectory,
|