@namzu/sdk 31.0.0 → 32.0.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.
Files changed (133) hide show
  1. package/CHANGELOG.md +67 -0
  2. package/dist/agents/ReactiveAgent.d.ts.map +1 -1
  3. package/dist/agents/ReactiveAgent.js +4 -0
  4. package/dist/agents/ReactiveAgent.js.map +1 -1
  5. package/dist/agents/SupervisorAgent.d.ts.map +1 -1
  6. package/dist/agents/SupervisorAgent.js +4 -0
  7. package/dist/agents/SupervisorAgent.js.map +1 -1
  8. package/dist/agents/runAgent.d.ts +4 -0
  9. package/dist/agents/runAgent.d.ts.map +1 -1
  10. package/dist/agents/runAgent.js +4 -0
  11. package/dist/agents/runAgent.js.map +1 -1
  12. package/dist/directory/derive-supervisor.d.ts.map +1 -1
  13. package/dist/directory/derive-supervisor.js +5 -0
  14. package/dist/directory/derive-supervisor.js.map +1 -1
  15. package/dist/directory/derive.d.ts.map +1 -1
  16. package/dist/directory/derive.js +5 -0
  17. package/dist/directory/derive.js.map +1 -1
  18. package/dist/directory/load.d.ts.map +1 -1
  19. package/dist/directory/load.js +1 -0
  20. package/dist/directory/load.js.map +1 -1
  21. package/dist/directory/types.d.ts +2 -0
  22. package/dist/directory/types.d.ts.map +1 -1
  23. package/dist/execution/code-runtime/types.d.ts +11 -1
  24. package/dist/execution/code-runtime/types.d.ts.map +1 -1
  25. package/dist/execution/code-runtime/types.js.map +1 -1
  26. package/dist/execution/code-runtime/worker.d.ts.map +1 -1
  27. package/dist/execution/code-runtime/worker.js +67 -9
  28. package/dist/execution/code-runtime/worker.js.map +1 -1
  29. package/dist/manager/agent/lifecycle.d.ts.map +1 -1
  30. package/dist/manager/agent/lifecycle.js +1 -0
  31. package/dist/manager/agent/lifecycle.js.map +1 -1
  32. package/dist/provider/errors.d.ts +1 -0
  33. package/dist/provider/errors.d.ts.map +1 -1
  34. package/dist/provider/errors.js +39 -1
  35. package/dist/provider/errors.js.map +1 -1
  36. package/dist/public-runtime.d.ts +5 -3
  37. package/dist/public-runtime.d.ts.map +1 -1
  38. package/dist/public-runtime.js +7 -2
  39. package/dist/public-runtime.js.map +1 -1
  40. package/dist/public-types.d.ts +2 -1
  41. package/dist/public-types.d.ts.map +1 -1
  42. package/dist/run/reporter.d.ts.map +1 -1
  43. package/dist/run/reporter.js +6 -1
  44. package/dist/run/reporter.js.map +1 -1
  45. package/dist/runtime/query/executor.d.ts.map +1 -1
  46. package/dist/runtime/query/executor.js +214 -29
  47. package/dist/runtime/query/executor.js.map +1 -1
  48. package/dist/runtime/query/index.d.ts +5 -0
  49. package/dist/runtime/query/index.d.ts.map +1 -1
  50. package/dist/runtime/query/index.js +1 -0
  51. package/dist/runtime/query/index.js.map +1 -1
  52. package/dist/runtime/query/iteration/index.d.ts +1 -0
  53. package/dist/runtime/query/iteration/index.d.ts.map +1 -1
  54. package/dist/runtime/query/iteration/index.js +34 -14
  55. package/dist/runtime/query/iteration/index.js.map +1 -1
  56. package/dist/runtime/query/iteration/phases/advisory.js +2 -2
  57. package/dist/runtime/query/iteration/phases/advisory.js.map +1 -1
  58. package/dist/runtime/query/iteration/provider-rejected-image.d.ts +13 -0
  59. package/dist/runtime/query/iteration/provider-rejected-image.d.ts.map +1 -0
  60. package/dist/runtime/query/iteration/provider-rejected-image.js +91 -0
  61. package/dist/runtime/query/iteration/provider-rejected-image.js.map +1 -0
  62. package/dist/runtime/query/iteration/stream-turn.d.ts +4 -1
  63. package/dist/runtime/query/iteration/stream-turn.d.ts.map +1 -1
  64. package/dist/runtime/query/iteration/stream-turn.js +7 -3
  65. package/dist/runtime/query/iteration/stream-turn.js.map +1 -1
  66. package/dist/runtime/query/request-rich-content.d.ts +13 -0
  67. package/dist/runtime/query/request-rich-content.d.ts.map +1 -1
  68. package/dist/runtime/query/request-rich-content.js +153 -17
  69. package/dist/runtime/query/request-rich-content.js.map +1 -1
  70. package/dist/runtime/query/result.d.ts.map +1 -1
  71. package/dist/runtime/query/result.js +1 -0
  72. package/dist/runtime/query/result.js.map +1 -1
  73. package/dist/store/attachment/index.d.ts +24 -2
  74. package/dist/store/attachment/index.d.ts.map +1 -1
  75. package/dist/store/attachment/index.js +52 -5
  76. package/dist/store/attachment/index.js.map +1 -1
  77. package/dist/tools/builtins/lsp.d.ts +1 -1
  78. package/dist/tools/builtins/run-code.d.ts.map +1 -1
  79. package/dist/tools/builtins/run-code.js +15 -5
  80. package/dist/tools/builtins/run-code.js.map +1 -1
  81. package/dist/types/agent/base.d.ts +4 -0
  82. package/dist/types/agent/base.d.ts.map +1 -1
  83. package/dist/types/agent/factory.d.ts +1 -0
  84. package/dist/types/agent/factory.d.ts.map +1 -1
  85. package/dist/types/message/index.d.ts +35 -4
  86. package/dist/types/message/index.d.ts.map +1 -1
  87. package/dist/types/message/index.js +42 -0
  88. package/dist/types/message/index.js.map +1 -1
  89. package/dist/types/provider/error.d.ts +4 -1
  90. package/dist/types/provider/error.d.ts.map +1 -1
  91. package/dist/types/provider/index.d.ts +1 -1
  92. package/dist/types/provider/index.d.ts.map +1 -1
  93. package/dist/types/provider/model.d.ts +12 -0
  94. package/dist/types/provider/model.d.ts.map +1 -1
  95. package/dist/types/run/events.d.ts +10 -2
  96. package/dist/types/run/events.d.ts.map +1 -1
  97. package/dist/types/run/events.js.map +1 -1
  98. package/dist/types/tool/index.d.ts +52 -6
  99. package/dist/types/tool/index.d.ts.map +1 -1
  100. package/dist/types/tool/index.js.map +1 -1
  101. package/package.json +1 -1
  102. package/src/agents/ReactiveAgent.ts +4 -0
  103. package/src/agents/SupervisorAgent.ts +4 -0
  104. package/src/agents/runAgent.ts +8 -0
  105. package/src/directory/derive-supervisor.ts +5 -0
  106. package/src/directory/derive.ts +5 -0
  107. package/src/directory/load.ts +1 -0
  108. package/src/directory/types.ts +2 -0
  109. package/src/execution/code-runtime/types.ts +15 -1
  110. package/src/execution/code-runtime/worker.ts +72 -9
  111. package/src/manager/agent/lifecycle.ts +1 -0
  112. package/src/provider/errors.ts +40 -1
  113. package/src/public-runtime.ts +16 -1
  114. package/src/public-types.ts +11 -0
  115. package/src/run/reporter.ts +7 -1
  116. package/src/runtime/query/executor.ts +235 -26
  117. package/src/runtime/query/index.ts +6 -0
  118. package/src/runtime/query/iteration/index.ts +69 -29
  119. package/src/runtime/query/iteration/phases/advisory.ts +2 -2
  120. package/src/runtime/query/iteration/provider-rejected-image.ts +106 -0
  121. package/src/runtime/query/iteration/stream-turn.ts +12 -2
  122. package/src/runtime/query/request-rich-content.ts +188 -15
  123. package/src/runtime/query/result.ts +1 -0
  124. package/src/store/attachment/index.ts +100 -15
  125. package/src/tools/builtins/run-code.ts +15 -5
  126. package/src/types/agent/base.ts +4 -0
  127. package/src/types/agent/factory.ts +1 -0
  128. package/src/types/message/index.ts +81 -4
  129. package/src/types/provider/error.ts +4 -1
  130. package/src/types/provider/index.ts +1 -1
  131. package/src/types/provider/model.ts +13 -0
  132. package/src/types/run/events.ts +18 -4
  133. package/src/types/tool/index.ts +74 -9
@@ -4,10 +4,26 @@ export type MessageRole = 'system' | 'user' | 'assistant' | 'tool'
4
4
 
5
5
  export type CacheHint = 'cache' | 'ephemeral' | 'none'
6
6
 
7
+ /** Why durable rich content must not be sent to a model again. */
8
+ export interface ModelContentOmission {
9
+ readonly reason: 'provider-rejected'
10
+ }
11
+
12
+ /** Runtime validation for persisted model-delivery metadata. */
13
+ export function isModelContentOmission(value: unknown): value is ModelContentOmission {
14
+ return (
15
+ typeof value === 'object' &&
16
+ value !== null &&
17
+ !Array.isArray(value) &&
18
+ (value as { readonly reason?: unknown }).reason === 'provider-rejected'
19
+ )
20
+ }
21
+
7
22
  /**
8
- * An image attached to a user message (vision input). Additive: providers
9
- * that support vision emit it as an image content block
10
- * alongside the text; providers that don't simply ignore it.
23
+ * An image attached to a user message (vision input). Drivers that declare
24
+ * vision support emit it alongside the text. A shipped driver that cannot
25
+ * map it refuses or causes the runtime to warn according to capability
26
+ * policy; silently ignoring image bytes is not a supported fallback.
11
27
  */
12
28
  export interface ImageAttachment {
13
29
  /**
@@ -21,6 +37,8 @@ export interface ImageAttachment {
21
37
  readonly data: string
22
38
  /** IANA media type, e.g. `image/png`, `image/jpeg`, `image/webp`. */
23
39
  readonly mediaType: string
40
+ /** Durable delivery state; the original image bytes remain in history. */
41
+ readonly modelOmission?: ModelContentOmission
24
42
  }
25
43
 
26
44
  /**
@@ -211,7 +229,38 @@ export interface ProjectInstructionMessageSource {
211
229
  readonly files: readonly string[]
212
230
  }
213
231
 
214
- export type UserMessageSource = GoalRoundMessageSource | ProjectInstructionMessageSource
232
+ /**
233
+ * Why the runtime, rather than the operator, inserted one user-role message.
234
+ *
235
+ * Providers require several pieces of host context to occupy the `user` role:
236
+ * a continuation after an output ceiling, reviewer feedback, task completion
237
+ * notices, and similar prompts. Role alone therefore cannot answer who wrote a
238
+ * durable message. Keeping that provenance on the message prevents a resumed
239
+ * transcript, export, or previous-prompt editor from presenting kernel context
240
+ * as something the operator typed.
241
+ */
242
+ export const RUNTIME_CONTEXT_MESSAGE_KINDS = [
243
+ 'advisory',
244
+ 'answer-review',
245
+ 'auto-continuation',
246
+ 'limit-finalization',
247
+ 'steering',
248
+ 'structured-output',
249
+ 'task-completion',
250
+ ] as const
251
+
252
+ export type RuntimeContextMessageKind = (typeof RUNTIME_CONTEXT_MESSAGE_KINDS)[number]
253
+
254
+ /** Host-generated context carried in the provider's required user role. */
255
+ export interface RuntimeContextMessageSource {
256
+ readonly type: 'runtime-context'
257
+ readonly kind: RuntimeContextMessageKind
258
+ }
259
+
260
+ export type UserMessageSource =
261
+ | GoalRoundMessageSource
262
+ | ProjectInstructionMessageSource
263
+ | RuntimeContextMessageSource
215
264
 
216
265
  /** A bounded source list keeps untrusted persisted metadata cheap to validate. */
217
266
  export const MAX_PROJECT_INSTRUCTION_SOURCE_FILES = 256
@@ -253,6 +302,22 @@ export function isProjectInstructionMessageSource(
253
302
  return true
254
303
  }
255
304
 
305
+ /** Runtime validation for durable host-generated user-message provenance. */
306
+ export function isRuntimeContextMessageSource(
307
+ value: unknown,
308
+ ): value is RuntimeContextMessageSource {
309
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) return false
310
+ const candidate = value as {
311
+ readonly type?: unknown
312
+ readonly kind?: unknown
313
+ }
314
+ return (
315
+ candidate.type === 'runtime-context' &&
316
+ typeof candidate.kind === 'string' &&
317
+ (RUNTIME_CONTEXT_MESSAGE_KINDS as readonly string[]).includes(candidate.kind)
318
+ )
319
+ }
320
+
256
321
  /**
257
322
  * The configured model route that produced or is about to receive a message.
258
323
  *
@@ -348,6 +413,7 @@ export type ToolResultBlock =
348
413
  readonly type: 'image'
349
414
  readonly data: string
350
415
  readonly mediaType: string
416
+ readonly modelOmission?: ModelContentOmission
351
417
  }
352
418
  | DocumentAttachment
353
419
 
@@ -400,6 +466,17 @@ export function createUserMessage(
400
466
  }
401
467
  }
402
468
 
469
+ /** Build provider-visible context that no operator authored. */
470
+ export function createRuntimeContextMessage(
471
+ content: string,
472
+ kind: RuntimeContextMessageKind,
473
+ ): UserMessage {
474
+ return createUserMessage(content, undefined, {
475
+ type: 'runtime-context',
476
+ kind,
477
+ })
478
+ }
479
+
403
480
  /** Build the retained user-context message that carries live project policy. */
404
481
  export function createProjectInstructionMessage(
405
482
  content: string,
@@ -11,11 +11,14 @@ export type ProviderErrorKind =
11
11
  * Serializable provider-failure metadata carried by failed runs and events.
12
12
  *
13
13
  * No response body, URL, or `cause` belongs here. `detail` is the one thing
14
- * the provider itself said, and it arrives scrubbed see below.
14
+ * the provider itself said, and it arrives scrubbed. `providerCode` preserves
15
+ * a bounded machine identifier independently of wording — see below.
15
16
  */
16
17
  export interface ProviderErrorInfo {
17
18
  readonly kind: ProviderErrorKind
18
19
  readonly providerId: string
20
+ /** Provider-defined machine code, preserved only when it is a bounded safe token. */
21
+ readonly providerCode?: string
19
22
  readonly status?: number
20
23
  readonly retryAfterMs?: number
21
24
  /**
@@ -8,7 +8,7 @@ export type {
8
8
  ThinkingConfig,
9
9
  } from './chat.js'
10
10
  export type { StreamChunk } from './stream.js'
11
- export type { ModelInfo } from './model.js'
11
+ export type { ModelInfo, ModelInputModality } from './model.js'
12
12
  export type { LLMProvider } from './interface.js'
13
13
  export type {
14
14
  ProviderErrorInfo,
@@ -1,6 +1,19 @@
1
+ /** A kind of input a model is known to accept. */
2
+ export type ModelInputModality = 'text' | 'image' | 'document'
3
+
1
4
  export interface ModelInfo {
2
5
  id: string
3
6
  name: string
7
+ /**
8
+ * Input kinds this exact model is known to accept.
9
+ *
10
+ * This is model metadata, not a replacement for
11
+ * `LLMProvider.capabilities`: the provider capability says whether the
12
+ * DRIVER can map an input kind at all, while this field says which models
13
+ * behind that driver accept it. Absent means the listing did not establish
14
+ * the answer; it must not be read as text-only.
15
+ */
16
+ inputModalities?: readonly ModelInputModality[]
4
17
  /**
5
18
  * Tokens the model's context holds, when the driver knows.
6
19
  *
@@ -320,7 +320,12 @@ type CoreRunEvent =
320
320
  * draws eleven siblings where there is one call with eleven
321
321
  * children.
322
322
  */
323
- via?: { readonly tool: string; readonly toolUseId: ToolUseId }
323
+ via?: {
324
+ readonly tool: string
325
+ readonly toolUseId: ToolUseId
326
+ /** The code runtime's request id, when that was the dispatch source. */
327
+ readonly runtimeToolCallId?: string
328
+ }
324
329
  }
325
330
  /**
326
331
  * A tool saying how far along it is.
@@ -334,7 +339,10 @@ type CoreRunEvent =
334
339
  * duration: the host could show that a tool had started and then nothing
335
340
  * at all until it either finished or timed out. The model never sees
336
341
  * these; they answer "is it still working?", which is a question only a
337
- * human asks.
342
+ * human asks. It is latest state rather than a lossless log: the executor
343
+ * bounds each UTF-8 message and coalesces intermediate updates when the
344
+ * live consumer falls behind. Complete output belongs to the terminal
345
+ * `tool_completed` result.
338
346
  */
339
347
  | {
340
348
  type: 'tool_progress'
@@ -412,7 +420,11 @@ type CoreRunEvent =
412
420
  isError: boolean
413
421
  /** See {@link tool_executing}'s `via`. Carried on both, so a
414
422
  * consumer can pair them without holding the start event. */
415
- via?: { readonly tool: string; readonly toolUseId: ToolUseId }
423
+ via?: {
424
+ readonly tool: string
425
+ readonly toolUseId: ToolUseId
426
+ readonly runtimeToolCallId?: string
427
+ }
416
428
  /**
417
429
  * Wall-clock the tool took. Computed since the first version of
418
430
  * the executor but only ever logged; a host asking "which tool
@@ -603,10 +615,12 @@ type CoreRunEvent =
603
615
  | {
604
616
  type: 'message_history_repaired'
605
617
  runId: RunId
606
- source: 'fresh-history' | 'abandoned-checkpoint'
618
+ source: 'fresh-history' | 'abandoned-checkpoint' | 'provider-rejected-image'
607
619
  duplicateToolResultsRemoved: number
608
620
  orphanedToolResultsRemoved: number
609
621
  syntheticToolResultsInserted: number
622
+ /** Exact number of durable image occurrences withheld from later requests. */
623
+ providerRejectedImagesSuppressed?: number
610
624
  }
611
625
  | {
612
626
  type: 'token_usage_updated'
@@ -68,7 +68,10 @@ export interface SkillRegistryRef {
68
68
  * outlives, or is billed to, somebody else's run.
69
69
  */
70
70
  export interface BackgroundJobRegistryRef {
71
- start(params: { command: string; workingDirectory: string }): { id: string; status: string }
71
+ start(params: { command: string; workingDirectory: string }): {
72
+ id: string
73
+ status: string
74
+ }
72
75
  get(id: string): { id: string; status: string; exitCode?: number }
73
76
  read(
74
77
  id: string,
@@ -158,6 +161,39 @@ export type ToolPauseOutcome =
158
161
 
159
162
  export type RequestToolPause = (request: ToolPauseRequest) => Promise<ToolPauseOutcome>
160
163
 
164
+ /**
165
+ * Where one tool execution entered the runtime from.
166
+ *
167
+ * The executor owns this value. A nested caller supplies only its private
168
+ * operation context to {@link ToolContext.dispatchTool}; the executor derives
169
+ * the parent id from the context it already issued, so a tool cannot relabel
170
+ * itself as somebody else's child.
171
+ */
172
+ export type ToolCallSource =
173
+ | { readonly kind: 'direct' }
174
+ | { readonly kind: 'nested'; readonly parentToolUseId: string }
175
+ | {
176
+ readonly kind: 'code'
177
+ readonly parentToolUseId: string
178
+ /** The code runtime's id, unique within the parent program. */
179
+ readonly runtimeToolCallId: string
180
+ }
181
+
182
+ /**
183
+ * Operation authority a trusted tool may narrow when it dispatches another
184
+ * tool.
185
+ *
186
+ * `signal` is fused with the parent call's signal; it can revoke authority
187
+ * earlier but can never extend the parent's lifetime. `runtimeToolCallId`
188
+ * identifies one request inside a model-authored program. The executor still
189
+ * chooses the child's event identity and the parent lineage; durable pause
190
+ * ownership stays with the model-issued ancestor present in the checkpoint.
191
+ */
192
+ export interface ToolDispatchOptions {
193
+ readonly signal?: AbortSignal
194
+ readonly runtimeToolCallId?: string
195
+ }
196
+
161
197
  export interface ToolContext {
162
198
  runId: RunId
163
199
  workingDirectory: string
@@ -242,7 +278,11 @@ export interface ToolContext {
242
278
  }>
243
279
  }
244
280
  readonly search?: {
245
- search(request: { query: string; limit?: number; signal?: AbortSignal }): Promise<{
281
+ search(request: {
282
+ query: string
283
+ limit?: number
284
+ signal?: AbortSignal
285
+ }): Promise<{
246
286
  query: string
247
287
  hits: readonly { title: string; url: string; snippet?: string }[]
248
288
  }>
@@ -257,7 +297,10 @@ export interface ToolContext {
257
297
  * the next batch — a skill loaded alongside other calls must not
258
298
  * retroactively refuse them.
259
299
  */
260
- adoptSkillScope?: (scope: { skill: string; allowedTools: readonly string[] }) => void
300
+ adoptSkillScope?: (scope: {
301
+ skill: string
302
+ allowedTools: readonly string[]
303
+ }) => void
261
304
 
262
305
  /**
263
306
  * Run another tool through the same dispatch this call came through.
@@ -275,7 +318,11 @@ export interface ToolContext {
275
318
  * dispatch, so a tool calling through here reaches exactly what a
276
319
  * `tool_use` block would have.
277
320
  */
278
- dispatchTool?: (name: string, input: unknown) => Promise<ToolResult>
321
+ dispatchTool?: (
322
+ name: string,
323
+ input: unknown,
324
+ options?: ToolDispatchOptions,
325
+ ) => Promise<ToolResult>
279
326
 
280
327
  /**
281
328
  * The `tool_use_id` of the assistant block that triggered this
@@ -287,6 +334,14 @@ export interface ToolContext {
287
334
  */
288
335
  toolUseId?: string
289
336
 
337
+ /**
338
+ * How this execution entered the tool registry.
339
+ *
340
+ * Present on executor-owned calls. Optional because a host may invoke a
341
+ * tool directly outside a run and construct its own minimal context.
342
+ */
343
+ source?: ToolCallSource
344
+
290
345
  /**
291
346
  * Raise a durable pause and wait for a human to resolve it.
292
347
  *
@@ -335,10 +390,16 @@ export interface ToolContext {
335
390
  * timed out.
336
391
  *
337
392
  * Fire-and-forget and never throws, so a tool can call it freely
338
- * without wrapping it. The model never sees these: progress answers
339
- * "is it still working?", which is a question only a human asks, and
340
- * putting it in the conversation would spend tokens telling the model
341
- * something it cannot act on.
393
+ * without wrapping it. This is latest state, not a log: while a host is
394
+ * consuming one update, later calls replace the single pending update.
395
+ * Each published message is capped at 8 KiB of UTF-8 with a visible
396
+ * omission marker, and every accepted update settles before that call's
397
+ * terminal event. Put complete output in `ToolResult`, not here.
398
+ *
399
+ * The model never sees these: progress answers "is it still working?",
400
+ * which is a question only a human asks, and putting it in the
401
+ * conversation would spend tokens telling the model something it cannot
402
+ * act on.
342
403
  *
343
404
  * Absent when the executing surface has no event stream to write to.
344
405
  */
@@ -626,4 +687,8 @@ export interface ToolRegistryContract {
626
687
 
627
688
  export * from './repair.js'
628
689
 
629
- export type { ToolCallView, ToolPresentation, ToolResultView } from './presentation.js'
690
+ export type {
691
+ ToolCallView,
692
+ ToolPresentation,
693
+ ToolResultView,
694
+ } from './presentation.js'