@namzu/sdk 1.3.0 → 1.4.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 (114) hide show
  1. package/CHANGELOG.md +87 -0
  2. package/dist/compaction/__tests__/verifier-empty-reply.test.d.ts +12 -0
  3. package/dist/compaction/__tests__/verifier-empty-reply.test.d.ts.map +1 -0
  4. package/dist/compaction/__tests__/verifier-empty-reply.test.js +73 -0
  5. package/dist/compaction/__tests__/verifier-empty-reply.test.js.map +1 -0
  6. package/dist/compaction/verifier.d.ts.map +1 -1
  7. package/dist/compaction/verifier.js +10 -1
  8. package/dist/compaction/verifier.js.map +1 -1
  9. package/dist/config/__tests__/compaction-budget-schema.test.d.ts +18 -0
  10. package/dist/config/__tests__/compaction-budget-schema.test.d.ts.map +1 -0
  11. package/dist/config/__tests__/compaction-budget-schema.test.js +96 -0
  12. package/dist/config/__tests__/compaction-budget-schema.test.js.map +1 -0
  13. package/dist/config/runtime.d.ts.map +1 -1
  14. package/dist/config/runtime.js +20 -11
  15. package/dist/config/runtime.js.map +1 -1
  16. package/dist/manager/run/persistence.d.ts +2 -1
  17. package/dist/manager/run/persistence.d.ts.map +1 -1
  18. package/dist/manager/run/persistence.js +3 -1
  19. package/dist/manager/run/persistence.js.map +1 -1
  20. package/dist/provider/__tests__/errors.test.d.ts +2 -0
  21. package/dist/provider/__tests__/errors.test.d.ts.map +1 -0
  22. package/dist/provider/__tests__/errors.test.js +61 -0
  23. package/dist/provider/__tests__/errors.test.js.map +1 -0
  24. package/dist/provider/errors.d.ts +108 -0
  25. package/dist/provider/errors.d.ts.map +1 -0
  26. package/dist/provider/errors.js +311 -0
  27. package/dist/provider/errors.js.map +1 -0
  28. package/dist/provider/index.d.ts +2 -0
  29. package/dist/provider/index.d.ts.map +1 -1
  30. package/dist/provider/index.js +1 -0
  31. package/dist/provider/index.js.map +1 -1
  32. package/dist/public-runtime.d.ts +11 -11
  33. package/dist/public-runtime.d.ts.map +1 -1
  34. package/dist/public-runtime.js +11 -11
  35. package/dist/public-runtime.js.map +1 -1
  36. package/dist/registry/tool/execute.d.ts.map +1 -1
  37. package/dist/registry/tool/execute.js +5 -2
  38. package/dist/registry/tool/execute.js.map +1 -1
  39. package/dist/registry/tool/execute.test.js +11 -0
  40. package/dist/registry/tool/execute.test.js.map +1 -1
  41. package/dist/runtime/query/__tests__/stream-recovery.test.js +54 -1
  42. package/dist/runtime/query/__tests__/stream-recovery.test.js.map +1 -1
  43. package/dist/runtime/query/iteration/phases/compaction-safe-cut.test.d.ts +32 -0
  44. package/dist/runtime/query/iteration/phases/compaction-safe-cut.test.d.ts.map +1 -0
  45. package/dist/runtime/query/iteration/phases/compaction-safe-cut.test.js +152 -0
  46. package/dist/runtime/query/iteration/phases/compaction-safe-cut.test.js.map +1 -0
  47. package/dist/runtime/query/iteration/phases/compaction.d.ts.map +1 -1
  48. package/dist/runtime/query/iteration/phases/compaction.js +52 -12
  49. package/dist/runtime/query/iteration/phases/compaction.js.map +1 -1
  50. package/dist/runtime/query/iteration/stream-turn.d.ts.map +1 -1
  51. package/dist/runtime/query/iteration/stream-turn.js +11 -5
  52. package/dist/runtime/query/iteration/stream-turn.js.map +1 -1
  53. package/dist/runtime/query/result.d.ts.map +1 -1
  54. package/dist/runtime/query/result.js +11 -1
  55. package/dist/runtime/query/result.js.map +1 -1
  56. package/dist/tools/builtins/__tests__/edit.test.js +54 -0
  57. package/dist/tools/builtins/__tests__/edit.test.js.map +1 -1
  58. package/dist/tools/builtins/edit.d.ts +1 -1
  59. package/dist/tools/builtins/edit.d.ts.map +1 -1
  60. package/dist/tools/builtins/edit.js +11 -13
  61. package/dist/tools/builtins/edit.js.map +1 -1
  62. package/dist/tools/coordinator/__tests__/task-list.test.js +14 -0
  63. package/dist/tools/coordinator/__tests__/task-list.test.js.map +1 -1
  64. package/dist/tools/coordinator/agent.d.ts +6 -8
  65. package/dist/tools/coordinator/agent.d.ts.map +1 -1
  66. package/dist/tools/coordinator/agent.js.map +1 -1
  67. package/dist/tools/coordinator/index.d.ts.map +1 -1
  68. package/dist/tools/coordinator/index.js +11 -32
  69. package/dist/tools/coordinator/index.js.map +1 -1
  70. package/dist/tools/defineTool.d.ts +1 -0
  71. package/dist/tools/defineTool.d.ts.map +1 -1
  72. package/dist/tools/defineTool.js +1 -0
  73. package/dist/tools/defineTool.js.map +1 -1
  74. package/dist/types/provider/error.d.ts +22 -0
  75. package/dist/types/provider/error.d.ts.map +1 -0
  76. package/dist/types/provider/error.js +2 -0
  77. package/dist/types/provider/error.js.map +1 -0
  78. package/dist/types/provider/index.d.ts +1 -0
  79. package/dist/types/provider/index.d.ts.map +1 -1
  80. package/dist/types/run/entity.d.ts +2 -0
  81. package/dist/types/run/entity.d.ts.map +1 -1
  82. package/dist/types/run/events.d.ts +2 -0
  83. package/dist/types/run/events.d.ts.map +1 -1
  84. package/dist/types/run/events.js.map +1 -1
  85. package/dist/types/tool/index.d.ts +6 -0
  86. package/dist/types/tool/index.d.ts.map +1 -1
  87. package/package.json +1 -1
  88. package/src/compaction/__tests__/verifier-empty-reply.test.ts +96 -0
  89. package/src/compaction/verifier.ts +10 -1
  90. package/src/config/__tests__/compaction-budget-schema.test.ts +114 -0
  91. package/src/config/runtime.ts +20 -11
  92. package/src/manager/run/persistence.ts +3 -1
  93. package/src/provider/__tests__/errors.test.ts +85 -0
  94. package/src/provider/errors.ts +344 -0
  95. package/src/provider/index.ts +15 -0
  96. package/src/public-runtime.ts +53 -10
  97. package/src/registry/tool/execute.test.ts +14 -0
  98. package/src/registry/tool/execute.ts +5 -2
  99. package/src/runtime/query/__tests__/stream-recovery.test.ts +64 -1
  100. package/src/runtime/query/iteration/phases/compaction-safe-cut.test.ts +186 -0
  101. package/src/runtime/query/iteration/phases/compaction.ts +54 -12
  102. package/src/runtime/query/iteration/stream-turn.ts +11 -6
  103. package/src/runtime/query/result.ts +11 -1
  104. package/src/tools/builtins/__tests__/edit.test.ts +76 -0
  105. package/src/tools/builtins/edit.ts +12 -12
  106. package/src/tools/coordinator/__tests__/task-list.test.ts +16 -0
  107. package/src/tools/coordinator/agent.ts +6 -8
  108. package/src/tools/coordinator/index.ts +11 -34
  109. package/src/tools/defineTool.ts +2 -0
  110. package/src/types/provider/error.ts +29 -0
  111. package/src/types/provider/index.ts +5 -0
  112. package/src/types/run/entity.ts +2 -0
  113. package/src/types/run/events.ts +7 -1
  114. package/src/types/tool/index.ts +6 -0
@@ -227,28 +227,6 @@ export function buildCoordinatorTools(opts: CoordinatorToolsOptions): ToolDefini
227
227
  },
228
228
  })
229
229
 
230
- const cancelTask = defineTool({
231
- name: 'cancel_task',
232
- description:
233
- 'Cancel a running agent task. Only use this with a task_id from a previous create_task.',
234
- inputSchema: z.object({
235
- task_id: z.string().describe('Agent task ID from a previous create_task'),
236
- }),
237
- category: 'custom',
238
- permissions: [],
239
- readOnly: false,
240
- destructive: false,
241
- concurrencySafe: true,
242
- async execute({ task_id }) {
243
- gateway.cancelTask(task_id as TaskId)
244
- return {
245
- success: true,
246
- output: `Task ${task_id} cancelled`,
247
- data: { task_id },
248
- }
249
- },
250
- })
251
-
252
230
  const agentTaskList = defineTool({
253
231
  name: 'agent_task_list',
254
232
  description:
@@ -305,19 +283,18 @@ export function buildCoordinatorTools(opts: CoordinatorToolsOptions): ToolDefini
305
283
  },
306
284
  })
307
285
 
308
- // `continue_task` was a follow-up channel for a still-alive worker
309
- // task. With `create_task` now blocking + tool_result returning
310
- // the worker's final output, every worker reaches a terminal
311
- // state by the time the supervisor wants to follow up and the
312
- // agent manager rejects `continue` on terminal tasks. The
313
- // industrial pattern is to issue a fresh `create_task` that
314
- // references the prior worker's output path, so we drop
315
- // `continue_task` from the registered surface entirely. The
316
- // definition stays in this file for now in case a future
317
- // non-default gateway (one that keeps the worker process alive
318
- // for follow-ups) wants to re-register it.
286
+ // `continue_task` and model-facing per-task cancellation both
287
+ // belonged to the old non-blocking worker protocol. With
288
+ // `create_task` now blocking + tool_result returning the worker's
289
+ // final output, every worker is terminal by the time a later model
290
+ // turn learns its task id. The old cancel tool additionally called
291
+ // a void/no-op gateway method and manufactured "cancelled" even for
292
+ // a missing id. Host-owned run interruption still uses the gateway
293
+ // cancellation contract directly; it does not need a model tool.
294
+ // Keep only the follow-up definition for a future non-default
295
+ // gateway that deliberately preserves live workers between turns.
319
296
  void continueTask
320
- const tools: ToolDefinition[] = [createTask, cancelTask, agentTaskList]
297
+ const tools: ToolDefinition[] = [createTask, agentTaskList]
321
298
 
322
299
  if (getPlanManager) {
323
300
  const approvePlan = defineTool({
@@ -11,6 +11,7 @@ export interface DefineToolOptions<S extends z.ZodType> {
11
11
  name: string
12
12
  description: string
13
13
  inputSchema: S
14
+ validationErrorHint?: string
14
15
  category: ToolDefinition['category']
15
16
  permissions: ToolPermission[]
16
17
  readOnly: boolean
@@ -29,6 +30,7 @@ export function defineTool<S extends z.ZodType>(
29
30
  name: options.name,
30
31
  description: options.description,
31
32
  inputSchema: options.inputSchema,
33
+ validationErrorHint: options.validationErrorHint,
32
34
  tier: options.tier,
33
35
  category: options.category,
34
36
  permissions: options.permissions,
@@ -0,0 +1,29 @@
1
+ /** What went wrong, at the coarsest granularity a caller can act on. */
2
+ export type ProviderErrorKind =
3
+ | 'throttle'
4
+ | 'network'
5
+ | 'auth'
6
+ | 'context_overflow'
7
+ | 'bad_request'
8
+ | 'server'
9
+
10
+ /**
11
+ * Serializable provider-failure metadata carried by failed runs and events.
12
+ *
13
+ * No response body, vendor message, URL, or `cause` belongs here.
14
+ */
15
+ export interface ProviderErrorInfo {
16
+ readonly kind: ProviderErrorKind
17
+ readonly providerId: string
18
+ readonly status?: number
19
+ readonly retryAfterMs?: number
20
+ }
21
+
22
+ export interface ProviderRequestErrorInit extends ProviderErrorInfo {
23
+ /**
24
+ * Optional extra clause for the message. MUST be text this codebase
25
+ * authored — never a fragment of a response body, a header, or a vendor
26
+ * error.
27
+ */
28
+ readonly detail?: string
29
+ }
@@ -8,6 +8,11 @@ export type {
8
8
  export type { StreamChunk } from './stream.js'
9
9
  export type { ModelInfo } from './model.js'
10
10
  export type { LLMProvider } from './interface.js'
11
+ export type {
12
+ ProviderErrorInfo,
13
+ ProviderErrorKind,
14
+ ProviderRequestErrorInit,
15
+ } from './error.js'
11
16
  export type {
12
17
  ProviderConfigRegistry,
13
18
  ProviderType,
@@ -1,6 +1,7 @@
1
1
  import type { AgentStatus, CostInfo, TokenUsage } from '../common/index.js'
2
2
  import type { RunId } from '../ids/index.js'
3
3
  import type { Message } from '../message/index.js'
4
+ import type { ProviderErrorInfo } from '../provider/index.js'
4
5
  import type { AgentRunConfig } from './config.js'
5
6
  import type { ReplayAttribution } from './replay.js'
6
7
  import type { StopReason } from './stop-reason.js'
@@ -37,6 +38,7 @@ export interface Run {
37
38
  endedAt?: number
38
39
  stopReason?: StopReason
39
40
  lastError?: string
41
+ lastProviderError?: ProviderErrorInfo
40
42
  result?: string
41
43
 
42
44
  parentRunId?: RunId
@@ -14,6 +14,7 @@ import type {
14
14
  } from '../ids/index.js'
15
15
  import type { PlanStep } from '../plan/index.js'
16
16
  import type { PluginHookEvent, PluginHookResult } from '../plugin/index.js'
17
+ import type { ProviderErrorInfo } from '../provider/index.js'
17
18
  import type { TaskStatus } from '../task/index.js'
18
19
  import type { Lineage } from './lineage.js'
19
20
  import type { MessageStopReason } from './stop-reason.js'
@@ -98,7 +99,12 @@ type CoreRunEvent =
98
99
  fromCheckpointId: CheckpointId
99
100
  }
100
101
  | { type: 'run_completed'; runId: RunId; result: string }
101
- | { type: 'run_failed'; runId: RunId; error: string }
102
+ | {
103
+ type: 'run_failed'
104
+ runId: RunId
105
+ error: string
106
+ providerError?: ProviderErrorInfo
107
+ }
102
108
  // Additive 2026-07 (provider capability negotiation): emitted once per
103
109
  // run when the request asks for something the provider DRIVER declared
104
110
  // it cannot do — tools registered against a no-tools driver (tool
@@ -64,6 +64,12 @@ export interface ToolDefinition<TInput = unknown> {
64
64
  name: string
65
65
  description: string
66
66
  inputSchema: z.ZodType<TInput, z.ZodTypeDef, unknown>
67
+ /**
68
+ * Concise, model-readable recovery guidance appended when inputSchema
69
+ * rejects a call. Use for conditional schemas whose required shapes
70
+ * cannot be reconstructed from JSON Schema's top-level `required` list.
71
+ */
72
+ validationErrorHint?: string
67
73
  execute(input: TInput, context: ToolContext): Promise<ToolResult>
68
74
  tier?: string
69
75
  permissions?: ToolPermission[]