@namzu/sdk 18.1.0 → 20.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 (48) hide show
  1. package/CHANGELOG.md +131 -0
  2. package/dist/agents/ReactiveAgent.d.ts.map +1 -1
  3. package/dist/agents/ReactiveAgent.js +1 -0
  4. package/dist/agents/ReactiveAgent.js.map +1 -1
  5. package/dist/agents/runAgent.d.ts +20 -0
  6. package/dist/agents/runAgent.d.ts.map +1 -1
  7. package/dist/agents/runAgent.js +2 -1
  8. package/dist/agents/runAgent.js.map +1 -1
  9. package/dist/manager/run/persistence.d.ts +27 -0
  10. package/dist/manager/run/persistence.d.ts.map +1 -1
  11. package/dist/manager/run/persistence.js +28 -0
  12. package/dist/manager/run/persistence.js.map +1 -1
  13. package/dist/runtime/query/executor.d.ts.map +1 -1
  14. package/dist/runtime/query/executor.js +44 -9
  15. package/dist/runtime/query/executor.js.map +1 -1
  16. package/dist/runtime/query/iteration/index.d.ts.map +1 -1
  17. package/dist/runtime/query/iteration/index.js +54 -0
  18. package/dist/runtime/query/iteration/index.js.map +1 -1
  19. package/dist/runtime/query/plugin-hooks.d.ts.map +1 -1
  20. package/dist/runtime/query/plugin-hooks.js +1 -0
  21. package/dist/runtime/query/plugin-hooks.js.map +1 -1
  22. package/dist/store/run/disk.d.ts.map +1 -1
  23. package/dist/store/run/disk.js +6 -0
  24. package/dist/store/run/disk.js.map +1 -1
  25. package/dist/tools/coordinator/agent.d.ts.map +1 -1
  26. package/dist/tools/coordinator/agent.js +20 -5
  27. package/dist/tools/coordinator/agent.js.map +1 -1
  28. package/dist/tools/coordinator/index.d.ts.map +1 -1
  29. package/dist/tools/coordinator/index.js +19 -2
  30. package/dist/tools/coordinator/index.js.map +1 -1
  31. package/dist/types/agent/base.d.ts +20 -0
  32. package/dist/types/agent/base.d.ts.map +1 -1
  33. package/dist/types/plugin/index.d.ts +30 -1
  34. package/dist/types/plugin/index.d.ts.map +1 -1
  35. package/dist/types/plugin/index.js +1 -0
  36. package/dist/types/plugin/index.js.map +1 -1
  37. package/package.json +1 -1
  38. package/src/agents/ReactiveAgent.ts +1 -0
  39. package/src/agents/runAgent.ts +24 -1
  40. package/src/manager/run/persistence.ts +28 -0
  41. package/src/runtime/query/executor.ts +59 -11
  42. package/src/runtime/query/iteration/index.ts +56 -0
  43. package/src/runtime/query/plugin-hooks.ts +1 -0
  44. package/src/store/run/disk.ts +6 -0
  45. package/src/tools/coordinator/agent.ts +20 -5
  46. package/src/tools/coordinator/index.ts +22 -2
  47. package/src/types/agent/base.ts +20 -0
  48. package/src/types/plugin/index.ts +27 -1
@@ -288,6 +288,26 @@ function readPositiveIntEnv(key: string, fallback: number): number {
288
288
  return Number.isSafeInteger(parsed) && parsed > 0 ? parsed : fallback
289
289
  }
290
290
 
291
+ /**
292
+ * The answer a delegated child produced, as the string a parent model reads.
293
+ *
294
+ * One function because two delegation surfaces ask the same question, and the
295
+ * comment on the other one records what happens when a rule lives at one site
296
+ * only: create_task shipped without the success check that agent already had.
297
+ *
298
+ * A schema-configured child answers with an object. Reading structuredOutput
299
+ * first is what stops a supervisor receiving prose it then has to re-parse.
300
+ */
301
+ function delegatedAnswer(
302
+ result: { structuredOutput?: unknown; result?: string } | undefined,
303
+ ): string | undefined {
304
+ const structured = result?.structuredOutput
305
+ if (structured !== undefined) {
306
+ return typeof structured === 'string' ? structured : JSON.stringify(structured)
307
+ }
308
+ return result?.result
309
+ }
310
+
291
311
  export function buildCoordinatorTools(opts: CoordinatorToolsOptions): ToolDefinition[] {
292
312
  const {
293
313
  gateway,
@@ -614,7 +634,7 @@ export function buildCoordinatorTools(opts: CoordinatorToolsOptions): ToolDefini
614
634
  // the work had been done.
615
635
  const success = taskSucceeded(completed)
616
636
  const resultText =
617
- completed.result?.result ??
637
+ delegatedAnswer(completed.result) ??
618
638
  completed.result?.lastError ??
619
639
  `Task finished with state: ${failureLabel(completed)}`
620
640
 
@@ -744,7 +764,7 @@ export function buildCoordinatorTools(opts: CoordinatorToolsOptions): ToolDefini
744
764
 
745
765
  const success = completed.state === 'completed'
746
766
  const resultText =
747
- completed.result?.result ??
767
+ delegatedAnswer(completed.result) ??
748
768
  completed.result?.lastError ??
749
769
  `Task finished with state: ${completed.state}`
750
770
  return {
@@ -186,6 +186,26 @@ export interface BaseAgentResult {
186
186
  durationMs: number
187
187
  messages: Message[]
188
188
  result?: string
189
+ /**
190
+ * The schema-validated answer, when the run was configured to produce one.
191
+ *
192
+ * `Run.structuredOutput` has carried this all along and every ergonomic
193
+ * boundary above it dropped the value three lines from its caller: an
194
+ * archetype's result literal did not copy it, `runAgent` did not even
195
+ * forward the config that produces it, and both delegation tools handed a
196
+ * parent the child's prose. So a supervisor fanning out to five
197
+ * schema-configured specialists received five strings and had to make the
198
+ * model re-parse what it had just caused to be serialized.
199
+ *
200
+ * `unknown` rather than a generic, deliberately. The schema lives on the
201
+ * run's config and a result type parameter would have to be threaded
202
+ * through every archetype, both delegation tools and the task record to
203
+ * reach here — and at the delegation boundary the parent does not hold the
204
+ * child's schema anyway, so the parameter would be `unknown` again at the
205
+ * only place it was wanted. Narrow it at the call site with the schema you
206
+ * already have.
207
+ */
208
+ structuredOutput?: unknown
189
209
  lastError?: string
190
210
  }
191
211
 
@@ -9,7 +9,7 @@ import {
9
9
  PLUGIN_NAME_MAX_LENGTH,
10
10
  } from '../../constants/plugin/index.js'
11
11
  import type { PluginId, RunId } from '../ids/index.js'
12
- import type { Message } from '../message/index.js'
12
+ import type { Message, ToolResultContent } from '../message/index.js'
13
13
  import type { ToolResult } from '../tool/index.js'
14
14
 
15
15
  // ---------------------------------------------------------------------------
@@ -191,6 +191,31 @@ export type PluginHookResult =
191
191
  | { action: 'modify'; input: unknown }
192
192
  | { action: 'error'; message: string }
193
193
  | { action: 'retry' }
194
+ /**
195
+ * Replace what the model sees, WITHOUT reporting the call as failed.
196
+ *
197
+ * The substitution seam already existed and was typed as a failure channel:
198
+ * the only way a `post_tool_use` hook could change the output was
199
+ * `action: 'error'`, which prefixes `Error: ` and sets the error flag. So
200
+ * redacting a credential out of a successful result was delivered to the
201
+ * model as a tool failure, and the model routed around a call that had
202
+ * worked — retrying it, or reporting to the user that it had failed.
203
+ *
204
+ * That is the difference this variant exists for. `error` says the call went
205
+ * wrong; this says the call went right and the model may not see all of it.
206
+ *
207
+ * `modify` is not this. It carries `input` and belongs to the pre-call
208
+ * hooks, which is why `post_tool_use` rejects it — a result is not an input,
209
+ * and reusing the variant would have made one action mean two things
210
+ * depending on where it was returned.
211
+ *
212
+ * Rich content blocks SURVIVE a replace unless `content` is given, because
213
+ * the common case is redacting text from a result whose image or resource
214
+ * is unaffected. A hook that needs to drop them passes `content: []`, and a
215
+ * hook redacting a secret that also appears in an image must — this variant
216
+ * cannot inspect what it is preserving.
217
+ */
218
+ | { action: 'replace'; output: string; content?: ToolResultContent }
194
219
 
195
220
  export function assertPluginHookResult(result: PluginHookResult): asserts result {
196
221
  const action = result.action
@@ -200,6 +225,7 @@ export function assertPluginHookResult(result: PluginHookResult): asserts result
200
225
  case 'modify':
201
226
  case 'error':
202
227
  case 'retry':
228
+ case 'replace':
203
229
  break
204
230
  default: {
205
231
  const _exhaustive: never = action