@namzu/sdk 3.1.0 → 3.3.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 (297) hide show
  1. package/CHANGELOG.md +221 -0
  2. package/dist/advisory/__tests__/consultation-context.test.d.ts +2 -0
  3. package/dist/advisory/__tests__/consultation-context.test.d.ts.map +1 -0
  4. package/dist/advisory/__tests__/consultation-context.test.js +124 -0
  5. package/dist/advisory/__tests__/consultation-context.test.js.map +1 -0
  6. package/dist/advisory/context.d.ts +25 -0
  7. package/dist/advisory/context.d.ts.map +1 -1
  8. package/dist/advisory/context.js +18 -0
  9. package/dist/advisory/context.js.map +1 -1
  10. package/dist/advisory/executor.d.ts.map +1 -1
  11. package/dist/advisory/executor.js +25 -3
  12. package/dist/advisory/executor.js.map +1 -1
  13. package/dist/agents/SupervisorAgent.d.ts.map +1 -1
  14. package/dist/agents/SupervisorAgent.js +6 -0
  15. package/dist/agents/SupervisorAgent.js.map +1 -1
  16. package/dist/agents/__tests__/supervisor-hands-down-hitl.test.d.ts +2 -0
  17. package/dist/agents/__tests__/supervisor-hands-down-hitl.test.d.ts.map +1 -0
  18. package/dist/agents/__tests__/supervisor-hands-down-hitl.test.js +112 -0
  19. package/dist/agents/__tests__/supervisor-hands-down-hitl.test.js.map +1 -0
  20. package/dist/compaction/__tests__/context-reducer.test.d.ts +2 -0
  21. package/dist/compaction/__tests__/context-reducer.test.d.ts.map +1 -0
  22. package/dist/compaction/__tests__/context-reducer.test.js +197 -0
  23. package/dist/compaction/__tests__/context-reducer.test.js.map +1 -0
  24. package/dist/compaction/factory.d.ts +7 -0
  25. package/dist/compaction/factory.d.ts.map +1 -1
  26. package/dist/compaction/factory.js +7 -0
  27. package/dist/compaction/factory.js.map +1 -1
  28. package/dist/compaction/index.d.ts +2 -0
  29. package/dist/compaction/index.d.ts.map +1 -1
  30. package/dist/compaction/index.js +1 -0
  31. package/dist/compaction/index.js.map +1 -1
  32. package/dist/compaction/interface.d.ts +13 -0
  33. package/dist/compaction/interface.d.ts.map +1 -1
  34. package/dist/compaction/managers/null.d.ts +3 -0
  35. package/dist/compaction/managers/null.d.ts.map +1 -1
  36. package/dist/compaction/managers/null.js +3 -0
  37. package/dist/compaction/managers/null.js.map +1 -1
  38. package/dist/compaction/managers/slidingWindow.d.ts +6 -0
  39. package/dist/compaction/managers/slidingWindow.d.ts.map +1 -1
  40. package/dist/compaction/managers/slidingWindow.js +6 -0
  41. package/dist/compaction/managers/slidingWindow.js.map +1 -1
  42. package/dist/compaction/managers/structured.d.ts +10 -0
  43. package/dist/compaction/managers/structured.d.ts.map +1 -1
  44. package/dist/compaction/managers/structured.js +10 -0
  45. package/dist/compaction/managers/structured.js.map +1 -1
  46. package/dist/compaction/reducer.d.ts +86 -0
  47. package/dist/compaction/reducer.d.ts.map +1 -0
  48. package/dist/compaction/reducer.js +77 -0
  49. package/dist/compaction/reducer.js.map +1 -0
  50. package/dist/connector/builtins/__tests__/oauth2-auth.test.d.ts +2 -0
  51. package/dist/connector/builtins/__tests__/oauth2-auth.test.d.ts.map +1 -0
  52. package/dist/connector/builtins/__tests__/oauth2-auth.test.js +54 -0
  53. package/dist/connector/builtins/__tests__/oauth2-auth.test.js.map +1 -0
  54. package/dist/connector/builtins/http.d.ts.map +1 -1
  55. package/dist/connector/builtins/http.js +24 -2
  56. package/dist/connector/builtins/http.js.map +1 -1
  57. package/dist/connector/builtins/http.test.js +18 -2
  58. package/dist/connector/builtins/http.test.js.map +1 -1
  59. package/dist/connector/index.d.ts +3 -2
  60. package/dist/connector/index.d.ts.map +1 -1
  61. package/dist/connector/index.js +2 -1
  62. package/dist/connector/index.js.map +1 -1
  63. package/dist/connector/mcp/__tests__/prompt-as-tool.test.d.ts +2 -0
  64. package/dist/connector/mcp/__tests__/prompt-as-tool.test.d.ts.map +1 -0
  65. package/dist/connector/mcp/__tests__/prompt-as-tool.test.js +122 -0
  66. package/dist/connector/mcp/__tests__/prompt-as-tool.test.js.map +1 -0
  67. package/dist/connector/mcp/__tests__/prompts-and-lifecycle.test.d.ts +2 -0
  68. package/dist/connector/mcp/__tests__/prompts-and-lifecycle.test.d.ts.map +1 -0
  69. package/dist/connector/mcp/__tests__/prompts-and-lifecycle.test.js +214 -0
  70. package/dist/connector/mcp/__tests__/prompts-and-lifecycle.test.js.map +1 -0
  71. package/dist/connector/mcp/client.d.ts +52 -1
  72. package/dist/connector/mcp/client.d.ts.map +1 -1
  73. package/dist/connector/mcp/client.js +86 -0
  74. package/dist/connector/mcp/client.js.map +1 -1
  75. package/dist/connector/mcp/discovery.d.ts +27 -2
  76. package/dist/connector/mcp/discovery.d.ts.map +1 -1
  77. package/dist/connector/mcp/discovery.js +58 -5
  78. package/dist/connector/mcp/discovery.js.map +1 -1
  79. package/dist/connector/mcp/index.d.ts +4 -3
  80. package/dist/connector/mcp/index.d.ts.map +1 -1
  81. package/dist/connector/mcp/index.js +3 -2
  82. package/dist/connector/mcp/index.js.map +1 -1
  83. package/dist/connector/mcp/policy.d.ts +17 -0
  84. package/dist/connector/mcp/policy.d.ts.map +1 -1
  85. package/dist/connector/mcp/policy.js +18 -7
  86. package/dist/connector/mcp/policy.js.map +1 -1
  87. package/dist/connector/mcp/prompt-adapter.d.ts +39 -0
  88. package/dist/connector/mcp/prompt-adapter.d.ts.map +1 -0
  89. package/dist/connector/mcp/prompt-adapter.js +113 -0
  90. package/dist/connector/mcp/prompt-adapter.js.map +1 -0
  91. package/dist/connector/mcp/server.d.ts +42 -1
  92. package/dist/connector/mcp/server.d.ts.map +1 -1
  93. package/dist/connector/mcp/server.js +77 -4
  94. package/dist/connector/mcp/server.js.map +1 -1
  95. package/dist/manager/agent/__tests__/depth-limit-authority.test.d.ts +2 -0
  96. package/dist/manager/agent/__tests__/depth-limit-authority.test.d.ts.map +1 -0
  97. package/dist/manager/agent/__tests__/depth-limit-authority.test.js +58 -0
  98. package/dist/manager/agent/__tests__/depth-limit-authority.test.js.map +1 -0
  99. package/dist/manager/agent/__tests__/hitl-across-spawn.test.d.ts +2 -0
  100. package/dist/manager/agent/__tests__/hitl-across-spawn.test.d.ts.map +1 -0
  101. package/dist/manager/agent/__tests__/hitl-across-spawn.test.js +226 -0
  102. package/dist/manager/agent/__tests__/hitl-across-spawn.test.js.map +1 -0
  103. package/dist/manager/agent/lifecycle.d.ts.map +1 -1
  104. package/dist/manager/agent/lifecycle.js +13 -0
  105. package/dist/manager/agent/lifecycle.js.map +1 -1
  106. package/dist/plugin/__tests__/discovery-scopes.test.d.ts +2 -0
  107. package/dist/plugin/__tests__/discovery-scopes.test.d.ts.map +1 -0
  108. package/dist/plugin/__tests__/discovery-scopes.test.js +97 -0
  109. package/dist/plugin/__tests__/discovery-scopes.test.js.map +1 -0
  110. package/dist/plugin/__tests__/enable-contributions.test.js +5 -1
  111. package/dist/plugin/__tests__/enable-contributions.test.js.map +1 -1
  112. package/dist/plugin/__tests__/mcp-admission.test.d.ts +2 -0
  113. package/dist/plugin/__tests__/mcp-admission.test.d.ts.map +1 -0
  114. package/dist/plugin/__tests__/mcp-admission.test.js +227 -0
  115. package/dist/plugin/__tests__/mcp-admission.test.js.map +1 -0
  116. package/dist/plugin/lifecycle.d.ts +41 -0
  117. package/dist/plugin/lifecycle.d.ts.map +1 -1
  118. package/dist/plugin/lifecycle.js +39 -1
  119. package/dist/plugin/lifecycle.js.map +1 -1
  120. package/dist/plugin/loader.d.ts +39 -3
  121. package/dist/plugin/loader.d.ts.map +1 -1
  122. package/dist/plugin/loader.js +37 -4
  123. package/dist/plugin/loader.js.map +1 -1
  124. package/dist/public-runtime.d.ts +4 -2
  125. package/dist/public-runtime.d.ts.map +1 -1
  126. package/dist/public-runtime.js +5 -2
  127. package/dist/public-runtime.js.map +1 -1
  128. package/dist/public-types.d.ts +2 -2
  129. package/dist/public-types.d.ts.map +1 -1
  130. package/dist/rag/__tests__/namespace-isolation.test.d.ts +2 -0
  131. package/dist/rag/__tests__/namespace-isolation.test.d.ts.map +1 -0
  132. package/dist/rag/__tests__/namespace-isolation.test.js +80 -0
  133. package/dist/rag/__tests__/namespace-isolation.test.js.map +1 -0
  134. package/dist/rag/ingestion.d.ts.map +1 -1
  135. package/dist/rag/ingestion.js +1 -0
  136. package/dist/rag/ingestion.js.map +1 -1
  137. package/dist/rag/retriever.d.ts.map +1 -1
  138. package/dist/rag/retriever.js +2 -0
  139. package/dist/rag/retriever.js.map +1 -1
  140. package/dist/rag/vector-store.d.ts.map +1 -1
  141. package/dist/rag/vector-store.js +6 -0
  142. package/dist/rag/vector-store.js.map +1 -1
  143. package/dist/registry/tool/execute.d.ts.map +1 -1
  144. package/dist/registry/tool/execute.js +113 -109
  145. package/dist/registry/tool/execute.js.map +1 -1
  146. package/dist/runtime/query/__tests__/per-step-skills.test.d.ts +10 -0
  147. package/dist/runtime/query/__tests__/per-step-skills.test.d.ts.map +1 -0
  148. package/dist/runtime/query/__tests__/per-step-skills.test.js +122 -0
  149. package/dist/runtime/query/__tests__/per-step-skills.test.js.map +1 -0
  150. package/dist/runtime/query/__tests__/per-step-tool-choice.test.d.ts +2 -0
  151. package/dist/runtime/query/__tests__/per-step-tool-choice.test.d.ts.map +1 -0
  152. package/dist/runtime/query/__tests__/per-step-tool-choice.test.js +153 -0
  153. package/dist/runtime/query/__tests__/per-step-tool-choice.test.js.map +1 -0
  154. package/dist/runtime/query/__tests__/resume-run.test.d.ts +2 -0
  155. package/dist/runtime/query/__tests__/resume-run.test.d.ts.map +1 -0
  156. package/dist/runtime/query/__tests__/resume-run.test.js +211 -0
  157. package/dist/runtime/query/__tests__/resume-run.test.js.map +1 -0
  158. package/dist/runtime/query/index.d.ts +10 -0
  159. package/dist/runtime/query/index.d.ts.map +1 -1
  160. package/dist/runtime/query/index.js +26 -0
  161. package/dist/runtime/query/index.js.map +1 -1
  162. package/dist/runtime/query/iteration/index.d.ts.map +1 -1
  163. package/dist/runtime/query/iteration/index.js +50 -33
  164. package/dist/runtime/query/iteration/index.js.map +1 -1
  165. package/dist/runtime/query/iteration/phases/compaction-model-routing.test.d.ts +2 -0
  166. package/dist/runtime/query/iteration/phases/compaction-model-routing.test.d.ts.map +1 -0
  167. package/dist/runtime/query/iteration/phases/compaction-model-routing.test.js +96 -0
  168. package/dist/runtime/query/iteration/phases/compaction-model-routing.test.js.map +1 -0
  169. package/dist/runtime/query/iteration/phases/compaction.d.ts.map +1 -1
  170. package/dist/runtime/query/iteration/phases/compaction.js +95 -5
  171. package/dist/runtime/query/iteration/phases/compaction.js.map +1 -1
  172. package/dist/runtime/query/iteration/phases/context-reducer-dispatch.test.d.ts +2 -0
  173. package/dist/runtime/query/iteration/phases/context-reducer-dispatch.test.d.ts.map +1 -0
  174. package/dist/runtime/query/iteration/phases/context-reducer-dispatch.test.js +180 -0
  175. package/dist/runtime/query/iteration/phases/context-reducer-dispatch.test.js.map +1 -0
  176. package/dist/runtime/query/iteration/phases/context.d.ts +9 -0
  177. package/dist/runtime/query/iteration/phases/context.d.ts.map +1 -1
  178. package/dist/runtime/query/iteration/phases/context.js.map +1 -1
  179. package/dist/runtime/query/resume-run.d.ts +70 -0
  180. package/dist/runtime/query/resume-run.d.ts.map +1 -0
  181. package/dist/runtime/query/resume-run.js +46 -0
  182. package/dist/runtime/query/resume-run.js.map +1 -0
  183. package/dist/telemetry/__tests__/model-call-span.test.d.ts +2 -0
  184. package/dist/telemetry/__tests__/model-call-span.test.d.ts.map +1 -0
  185. package/dist/telemetry/__tests__/model-call-span.test.js +152 -0
  186. package/dist/telemetry/__tests__/model-call-span.test.js.map +1 -0
  187. package/dist/telemetry/__tests__/span-closure.test.d.ts +2 -0
  188. package/dist/telemetry/__tests__/span-closure.test.d.ts.map +1 -0
  189. package/dist/telemetry/__tests__/span-closure.test.js +124 -0
  190. package/dist/telemetry/__tests__/span-closure.test.js.map +1 -0
  191. package/dist/tools/advisory/index.js +1 -1
  192. package/dist/tools/advisory/index.js.map +1 -1
  193. package/dist/tools/coordinator/__tests__/plan-dependencies.test.d.ts +2 -0
  194. package/dist/tools/coordinator/__tests__/plan-dependencies.test.d.ts.map +1 -0
  195. package/dist/tools/coordinator/__tests__/plan-dependencies.test.js +126 -0
  196. package/dist/tools/coordinator/__tests__/plan-dependencies.test.js.map +1 -0
  197. package/dist/tools/coordinator/index.d.ts.map +1 -1
  198. package/dist/tools/coordinator/index.js +13 -1
  199. package/dist/tools/coordinator/index.js.map +1 -1
  200. package/dist/tools/coordinator/plan-dependencies.d.ts +43 -0
  201. package/dist/tools/coordinator/plan-dependencies.d.ts.map +1 -0
  202. package/dist/tools/coordinator/plan-dependencies.js +148 -0
  203. package/dist/tools/coordinator/plan-dependencies.js.map +1 -0
  204. package/dist/types/agent/base.d.ts +26 -0
  205. package/dist/types/agent/base.d.ts.map +1 -1
  206. package/dist/types/agent/supervisor.d.ts +15 -0
  207. package/dist/types/agent/supervisor.d.ts.map +1 -1
  208. package/dist/types/agent/task.d.ts +17 -0
  209. package/dist/types/agent/task.d.ts.map +1 -1
  210. package/dist/types/agent/task.js.map +1 -1
  211. package/dist/types/connector/core.d.ts +34 -0
  212. package/dist/types/connector/core.d.ts.map +1 -1
  213. package/dist/types/connector/definition.d.ts +10 -0
  214. package/dist/types/connector/definition.d.ts.map +1 -1
  215. package/dist/types/connector/mcp.d.ts +13 -0
  216. package/dist/types/connector/mcp.d.ts.map +1 -1
  217. package/dist/types/rag/retrieval.d.ts +16 -0
  218. package/dist/types/rag/retrieval.d.ts.map +1 -1
  219. package/dist/types/rag/storage.d.ts +9 -0
  220. package/dist/types/rag/storage.d.ts.map +1 -1
  221. package/dist/types/rag/vector.d.ts +11 -0
  222. package/dist/types/rag/vector.d.ts.map +1 -1
  223. package/dist/types/router/task-router.d.ts +19 -0
  224. package/dist/types/router/task-router.d.ts.map +1 -1
  225. package/dist/types/run/prepare-step.d.ts +56 -3
  226. package/dist/types/run/prepare-step.d.ts.map +1 -1
  227. package/dist/types/toolset/index.d.ts +22 -0
  228. package/dist/types/toolset/index.d.ts.map +1 -1
  229. package/package.json +1 -1
  230. package/src/advisory/__tests__/consultation-context.test.ts +191 -0
  231. package/src/advisory/context.ts +32 -0
  232. package/src/advisory/executor.ts +30 -3
  233. package/src/agents/SupervisorAgent.ts +6 -0
  234. package/src/agents/__tests__/supervisor-hands-down-hitl.test.ts +131 -0
  235. package/src/compaction/__tests__/context-reducer.test.ts +239 -0
  236. package/src/compaction/factory.ts +7 -0
  237. package/src/compaction/index.ts +8 -0
  238. package/src/compaction/interface.ts +13 -0
  239. package/src/compaction/managers/null.ts +3 -0
  240. package/src/compaction/managers/slidingWindow.ts +6 -0
  241. package/src/compaction/managers/structured.ts +10 -0
  242. package/src/compaction/reducer.ts +154 -0
  243. package/src/connector/builtins/__tests__/oauth2-auth.test.ts +73 -0
  244. package/src/connector/builtins/http.test.ts +28 -2
  245. package/src/connector/builtins/http.ts +26 -2
  246. package/src/connector/index.ts +7 -2
  247. package/src/connector/mcp/__tests__/prompt-as-tool.test.ts +157 -0
  248. package/src/connector/mcp/__tests__/prompts-and-lifecycle.test.ts +286 -0
  249. package/src/connector/mcp/client.ts +95 -0
  250. package/src/connector/mcp/discovery.ts +67 -5
  251. package/src/connector/mcp/index.ts +8 -3
  252. package/src/connector/mcp/policy.ts +23 -8
  253. package/src/connector/mcp/prompt-adapter.ts +139 -0
  254. package/src/connector/mcp/server.ts +101 -3
  255. package/src/manager/agent/__tests__/depth-limit-authority.test.ts +74 -0
  256. package/src/manager/agent/__tests__/hitl-across-spawn.test.ts +273 -0
  257. package/src/manager/agent/lifecycle.ts +12 -0
  258. package/src/plugin/__tests__/discovery-scopes.test.ts +133 -0
  259. package/src/plugin/__tests__/enable-contributions.test.ts +5 -1
  260. package/src/plugin/__tests__/mcp-admission.test.ts +286 -0
  261. package/src/plugin/lifecycle.ts +68 -1
  262. package/src/plugin/loader.ts +57 -3
  263. package/src/public-runtime.ts +10 -0
  264. package/src/public-types.ts +5 -0
  265. package/src/rag/__tests__/namespace-isolation.test.ts +109 -0
  266. package/src/rag/ingestion.ts +1 -0
  267. package/src/rag/retriever.ts +2 -0
  268. package/src/rag/vector-store.ts +5 -0
  269. package/src/registry/tool/execute.ts +123 -119
  270. package/src/runtime/query/__tests__/per-step-skills.test.ts +154 -0
  271. package/src/runtime/query/__tests__/per-step-tool-choice.test.ts +180 -0
  272. package/src/runtime/query/__tests__/resume-run.test.ts +262 -0
  273. package/src/runtime/query/index.ts +39 -0
  274. package/src/runtime/query/iteration/index.ts +55 -34
  275. package/src/runtime/query/iteration/phases/compaction-model-routing.test.ts +125 -0
  276. package/src/runtime/query/iteration/phases/compaction.ts +106 -5
  277. package/src/runtime/query/iteration/phases/context-reducer-dispatch.test.ts +238 -0
  278. package/src/runtime/query/iteration/phases/context.ts +11 -0
  279. package/src/runtime/query/resume-run.ts +93 -0
  280. package/src/telemetry/__tests__/model-call-span.test.ts +195 -0
  281. package/src/telemetry/__tests__/span-closure.test.ts +153 -0
  282. package/src/tools/advisory/index.ts +1 -1
  283. package/src/tools/coordinator/__tests__/plan-dependencies.test.ts +186 -0
  284. package/src/tools/coordinator/index.ts +14 -1
  285. package/src/tools/coordinator/plan-dependencies.ts +175 -0
  286. package/src/types/agent/base.ts +27 -0
  287. package/src/types/agent/supervisor.ts +15 -0
  288. package/src/types/agent/task.ts +18 -0
  289. package/src/types/connector/core.ts +34 -0
  290. package/src/types/connector/definition.ts +10 -0
  291. package/src/types/connector/mcp.ts +14 -0
  292. package/src/types/rag/retrieval.ts +16 -0
  293. package/src/types/rag/storage.ts +9 -0
  294. package/src/types/rag/vector.ts +11 -0
  295. package/src/types/router/task-router.ts +19 -0
  296. package/src/types/run/prepare-step.ts +58 -3
  297. package/src/types/toolset/index.ts +22 -0
@@ -1 +1 @@
1
- {"version":3,"file":"prepare-step.d.ts","sourceRoot":"","sources":["../../../src/types/run/prepare-step.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAClD,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SAAS,GAAG,OAAO,CAAC,iBAAiB,GAAG,SAAS,CAAC,CAAA;AAE3E;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,MAAM,gBAAgB,GAAG,WAAW,GAAG,SAAS,WAAW,EAAE,CAAA"}
@@ -1,4 +1,20 @@
1
1
  import type { LLMToolSchema, ToolDefinition, ToolPermission } from '../tool/index.js';
2
+ /**
3
+ * @deprecated Slated for removal in the next major. Nothing produces or
4
+ * reads it — no code constructs any member, and `ToolsetPolicy.surfaces`,
5
+ * the only field that carries it, is never consulted.
6
+ *
7
+ * It is also the wrong axis. Which tools a run may use is already
8
+ * expressible four ways, all of them per-run and dynamic where this is
9
+ * fixed at definition: `allowedTools` on the query, `ToolAvailability`
10
+ * (`active` / `deferred` / `suspended`) with mid-run activation,
11
+ * `runtimeToolOverrides`, and capability negotiation stripping tools a
12
+ * driver cannot carry. Prefer `allowedTools`.
13
+ *
14
+ * The member names encode deployment shapes this kernel does not own,
15
+ * which is the deeper reason not to keep them: a host's surfaces are the
16
+ * host's to name.
17
+ */
2
18
  export type ToolCatalogSurface = 'chat' | 'supervised' | 'managed-agent' | 'worker' | 'code';
3
19
  export type ToolSourceKind = 'host_tool' | 'provider_builtin' | 'mcp_server' | 'skill' | 'plugin' | 'connector';
4
20
  export type ToolLoadingMode = 'eager' | 'deferred' | 'disabled' | 'suspended';
@@ -30,6 +46,12 @@ export interface ToolsetPolicy {
30
46
  readonly enabled?: boolean;
31
47
  readonly loading?: ToolLoadingMode;
32
48
  readonly preferred?: boolean;
49
+ /**
50
+ * @deprecated Slated for removal in the next major. Never read by
51
+ * anything — setting it has no effect today. Use `allowedTools` on the
52
+ * query to bound which tools a run may use; it says the same thing per
53
+ * run instead of per definition. See {@link ToolCatalogSurface}.
54
+ */
33
55
  readonly surfaces?: readonly ToolCatalogSurface[];
34
56
  readonly providerConfig?: Record<string, unknown>;
35
57
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src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,QAAQ,CAAC,QAAQ,EAAE,SAAS,iBAAiB,EAAE,CAAA;IAC/C,QAAQ,CAAC,KAAK,EAAE,SAAS,gBAAgB,EAAE,CAAA;CAC3C"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@namzu/sdk",
3
- "version": "3.1.0",
3
+ "version": "3.3.0",
4
4
  "description": "Open-source AI agent SDK with a built-in runtime. Nothing between you and your agents.",
5
5
  "license": "FSL-1.1-MIT",
6
6
  "type": "module",
@@ -0,0 +1,191 @@
1
+ import { describe, expect, it, vi } from 'vitest'
2
+
3
+ import type { AdvisorDefinition } from '../../types/advisory/index.js'
4
+ import type { Message } from '../../types/message/index.js'
5
+ import { AdvisoryContext } from '../context.js'
6
+ import { TriggerEvaluator } from '../evaluator.js'
7
+ import { AdvisoryExecutor } from '../executor.js'
8
+ import { ADVISORY_RESPONSE_CONTRACT } from '../parse.js'
9
+ import { AdvisorRegistry } from '../registry.js'
10
+
11
+ /**
12
+ * An advisor consulted BY THE MODEL saw the question and nothing else.
13
+ *
14
+ * Two paths reach `AdvisoryExecutor.consult`. The trigger path
15
+ * (`iteration/phases/advisory.ts`) has always passed the live messages, the
16
+ * working state and the tool catalogue. The tool path passed
17
+ * `{ messages: [], iteration: 0 }` — a literal empty context — so the
18
+ * model's own `include_context: true` had nothing to include, and the
19
+ * advisor answered a question about a situation it could not see.
20
+ */
21
+
22
+ function recordingProvider(): { provider: AdvisorDefinition['provider']; calls: Message[][] } {
23
+ const calls: Message[][] = []
24
+ const provider = {
25
+ chatStream: async function* (params: { messages: Message[] }) {
26
+ calls.push(params.messages)
27
+ yield { id: 'a1', delta: { content: 'ADVICE: do the thing' } }
28
+ yield {
29
+ id: 'a1',
30
+ delta: {},
31
+ finishReason: 'stop',
32
+ usage: { promptTokens: 1, completionTokens: 1, totalTokens: 2 },
33
+ }
34
+ },
35
+ } as unknown as AdvisorDefinition['provider']
36
+ return { provider, calls }
37
+ }
38
+
39
+ function advisor(over: Partial<AdvisorDefinition> = {}): AdvisorDefinition {
40
+ return {
41
+ id: 'adv_1',
42
+ name: 'Reviewer',
43
+ provider: recordingProvider().provider,
44
+ model: 'mock-model',
45
+ ...over,
46
+ } as AdvisorDefinition
47
+ }
48
+
49
+ const log = {
50
+ debug: vi.fn(),
51
+ info: vi.fn(),
52
+ warn: vi.fn(),
53
+ error: vi.fn(),
54
+ child: () => log,
55
+ } as never
56
+
57
+ function contextFor(a: AdvisorDefinition): AdvisoryContext {
58
+ return new AdvisoryContext(
59
+ new AdvisorRegistry([a]),
60
+ new AdvisoryExecutor(log),
61
+ new TriggerEvaluator([]),
62
+ )
63
+ }
64
+
65
+ describe('the context a tool-initiated consultation is given', () => {
66
+ it('is empty until the runtime supplies one', () => {
67
+ const ctx = contextFor(advisor())
68
+
69
+ // The fallback exists for a context built without a runtime, and it is
70
+ // what every tool-initiated call used to get.
71
+ expect(ctx.callContext()).toEqual({ messages: [], iteration: 0 })
72
+ })
73
+
74
+ it('is the live run once the runtime wires it', () => {
75
+ const ctx = contextFor(advisor())
76
+ const messages: Message[] = [{ role: 'user', content: 'the situation', timestamp: 1 }]
77
+
78
+ ctx.setCallContextProvider(() => ({ messages, iteration: 7 }))
79
+
80
+ expect(ctx.callContext().messages).toBe(messages)
81
+ expect(ctx.callContext().iteration).toBe(7)
82
+ })
83
+
84
+ it('is read at call time, not at construction', () => {
85
+ const ctx = contextFor(advisor())
86
+ let iteration = 1
87
+ ctx.setCallContextProvider(() => ({ messages: [], iteration }))
88
+
89
+ iteration = 4
90
+
91
+ // The tool is built once per run and called at an unknown later point.
92
+ // A snapshot would hand every advisor the state the run started with.
93
+ expect(ctx.callContext().iteration).toBe(4)
94
+ })
95
+ })
96
+
97
+ describe('what the advisor actually receives', () => {
98
+ it('sees the conversation when context is included', async () => {
99
+ const { provider, calls } = recordingProvider()
100
+ const executor = new AdvisoryExecutor(log)
101
+
102
+ await executor.consult(
103
+ advisor({ provider }),
104
+ { advisorId: 'adv_1', question: 'what next?', includeContext: true },
105
+ { messages: [{ role: 'user', content: 'deploy is failing', timestamp: 1 }], iteration: 2 },
106
+ )
107
+
108
+ const sent = JSON.stringify(calls[0])
109
+ expect(sent).toContain('deploy is failing')
110
+ })
111
+
112
+ it('sees none of it when the caller says not to', async () => {
113
+ const { provider, calls } = recordingProvider()
114
+ const executor = new AdvisoryExecutor(log)
115
+
116
+ await executor.consult(
117
+ advisor({ provider }),
118
+ { advisorId: 'adv_1', question: 'what next?', includeContext: false },
119
+ { messages: [{ role: 'user', content: 'deploy is failing', timestamp: 1 }], iteration: 2 },
120
+ )
121
+
122
+ expect(JSON.stringify(calls[0])).not.toContain('deploy is failing')
123
+ })
124
+
125
+ it('is told when the caller marked the request urgent', async () => {
126
+ const { provider, calls } = recordingProvider()
127
+ const executor = new AdvisoryExecutor(log)
128
+
129
+ await executor.consult(
130
+ advisor({ provider }),
131
+ { advisorId: 'adv_1', question: 'what next?', urgency: 'high' },
132
+ { messages: [], iteration: 1 },
133
+ )
134
+
135
+ // The value used to reach exactly one debug log line, so 'high' and
136
+ // 'low' produced byte-identical requests.
137
+ expect(String(calls[0]?.[0]?.content)).toContain('URGENT')
138
+ })
139
+
140
+ it('is told when there is room to consider alternatives', async () => {
141
+ const { provider, calls } = recordingProvider()
142
+ const executor = new AdvisoryExecutor(log)
143
+
144
+ await executor.consult(
145
+ advisor({ provider }),
146
+ { advisorId: 'adv_1', question: 'what next?', urgency: 'low' },
147
+ { messages: [], iteration: 1 },
148
+ )
149
+
150
+ expect(String(calls[0]?.[0]?.content)).toContain('low urgency')
151
+ })
152
+
153
+ it("appends nothing at all for 'normal', which is the point of not stating it", async () => {
154
+ const { provider, calls } = recordingProvider()
155
+ const executor = new AdvisoryExecutor(log)
156
+ const a = advisor({ provider })
157
+
158
+ await executor.consult(
159
+ a,
160
+ { advisorId: 'adv_1', question: 'what next?', urgency: 'normal' },
161
+ { messages: [], iteration: 1 },
162
+ )
163
+ await executor.consult(
164
+ a,
165
+ { advisorId: 'adv_1', question: 'what next?', urgency: 'high' },
166
+ { messages: [], iteration: 1 },
167
+ )
168
+
169
+ // Asserting "does not contain the other two phrases" is too weak — it
170
+ // would let ANY new sentence in. The response contract is the last
171
+ // thing the prompt says when urgency contributes nothing, so ending on
172
+ // it is what "appended nothing" actually means.
173
+ expect(String(calls[0]?.[0]?.content).trimEnd().endsWith(ADVISORY_RESPONSE_CONTRACT)).toBe(true)
174
+ expect(String(calls[1]?.[0]?.content).trimEnd().endsWith(ADVISORY_RESPONSE_CONTRACT)).toBe(
175
+ false,
176
+ )
177
+ })
178
+
179
+ it('says nothing about urgency when the caller did not', async () => {
180
+ const { provider, calls } = recordingProvider()
181
+ const executor = new AdvisoryExecutor(log)
182
+
183
+ await executor.consult(
184
+ advisor({ provider }),
185
+ { advisorId: 'adv_1', question: 'what next?' },
186
+ { messages: [], iteration: 1 },
187
+ )
188
+
189
+ expect(String(calls[0]?.[0]?.content).trimEnd().endsWith(ADVISORY_RESPONSE_CONTRACT)).toBe(true)
190
+ })
191
+ })
@@ -1,8 +1,20 @@
1
1
  import type { AdvisoryBudget, AdvisoryCallRecord } from '../types/advisory/index.js'
2
2
  import type { TriggerEvaluator } from './evaluator.js'
3
+ import type { AdvisoryCallContext } from './executor.js'
3
4
  import type { AdvisoryExecutor } from './executor.js'
4
5
  import type { AdvisorRegistry } from './registry.js'
5
6
 
7
+ /**
8
+ * What the run looks like right now, for an advisory call that did not come
9
+ * from the iteration loop.
10
+ *
11
+ * A function rather than a snapshot because the tool is built once per run
12
+ * and called at an unknown later point: capturing the context at
13
+ * construction would hand every advisor the state the run had before it
14
+ * started.
15
+ */
16
+ export type AdvisoryCallContextProvider = () => AdvisoryCallContext
17
+
6
18
  export class AdvisoryContext {
7
19
  readonly registry: AdvisorRegistry
8
20
  readonly executor: AdvisoryExecutor
@@ -10,6 +22,7 @@ export class AdvisoryContext {
10
22
  readonly callHistory: AdvisoryCallRecord[] = []
11
23
 
12
24
  private readonly budget: AdvisoryBudget | undefined
25
+ private callContextProvider: AdvisoryCallContextProvider | undefined
13
26
 
14
27
  constructor(
15
28
  registry: AdvisorRegistry,
@@ -23,6 +36,25 @@ export class AdvisoryContext {
23
36
  this.budget = budget
24
37
  }
25
38
 
39
+ /** Wired by the runtime once the run exists. */
40
+ setCallContextProvider(provider: AdvisoryCallContextProvider): void {
41
+ this.callContextProvider = provider
42
+ }
43
+
44
+ /**
45
+ * The call context for a tool-initiated consultation.
46
+ *
47
+ * The trigger path (`iteration/phases/advisory.ts`) has always passed the
48
+ * live messages, working state and tool catalogue. The TOOL path passed
49
+ * `{ messages: [], iteration: 0 }` — a literal empty context — so an
50
+ * advisor consulted by the model saw the question and nothing else, and
51
+ * the model's `include_context` had nothing to include either way. The
52
+ * empty fallback survives only for a context built without a runtime.
53
+ */
54
+ callContext(): AdvisoryCallContext {
55
+ return this.callContextProvider?.() ?? { messages: [], iteration: 0 }
56
+ }
57
+
26
58
  recordCall(record: AdvisoryCallRecord): void {
27
59
  this.callHistory.push(record)
28
60
  }
@@ -11,6 +11,19 @@ import { calculateCost } from '../utils/cost.js'
11
11
  import { type Logger, getRootLogger } from '../utils/logger.js'
12
12
  import { ADVISORY_RESPONSE_CONTRACT, parseAdvisoryResponse } from './parse.js'
13
13
 
14
+ /**
15
+ * What the advisor is told about how urgent the caller said this is.
16
+ *
17
+ * `'normal'` says nothing on purpose. A sentence asserting the ordinary case
18
+ * is prompt weight that changes no answer, and stating it on every call
19
+ * would make the two that matter harder to notice.
20
+ */
21
+ const URGENCY_DIRECTION: Record<'low' | 'normal' | 'high', string | undefined> = {
22
+ high: 'This request is marked URGENT. Lead with the single most important action and keep the reasoning to what is needed to justify it.',
23
+ normal: undefined,
24
+ low: 'This request is marked low urgency. There is room to note secondary considerations and alternatives worth weighing.',
25
+ }
26
+
14
27
  export interface AdvisoryCallContext {
15
28
  readonly messages: Message[]
16
29
  readonly workingStateSummary?: string
@@ -53,7 +66,7 @@ export class AdvisoryExecutor {
53
66
  ): Promise<AdvisoryExecutionResult> {
54
67
  const startMs = Date.now()
55
68
 
56
- const systemPrompt = this.buildSystemPrompt(advisor)
69
+ const systemPrompt = this.buildSystemPrompt(advisor, request.urgency)
57
70
  const contextMessages = this.buildContext(advisor, request, callCtx)
58
71
 
59
72
  const messages: Message[] = [
@@ -100,11 +113,25 @@ export class AdvisoryExecutor {
100
113
  }
101
114
  }
102
115
 
103
- private buildSystemPrompt(advisor: AdvisorDefinition): string {
116
+ private buildSystemPrompt(
117
+ advisor: AdvisorDefinition,
118
+ urgency?: AdvisoryRequest['urgency'],
119
+ ): string {
104
120
  // The contract is appended to every branch, not folded into the
105
121
  // default: an advisor with its own prompt or a persona is still read
106
122
  // back by the same parser, and used to be the one never told so.
107
- return `${this.describeAdvisor(advisor)}\n\n${ADVISORY_RESPONSE_CONTRACT}`
123
+ const parts = [this.describeAdvisor(advisor), ADVISORY_RESPONSE_CONTRACT]
124
+
125
+ // The caller is invited to say how urgent this is, and the value used
126
+ // to reach exactly one debug log line — `urgency: 'high'` and
127
+ // `urgency: 'low'` produced byte-identical requests. Telling the
128
+ // ADVISOR is the honest minimum: it is the party that can act on the
129
+ // answer, and it costs one sentence rather than a routing policy this
130
+ // kernel has no business inventing.
131
+ const direction = URGENCY_DIRECTION[urgency ?? 'normal']
132
+ if (direction) parts.push(direction)
133
+
134
+ return parts.join('\n\n')
108
135
  }
109
136
 
110
137
  private describeAdvisor(advisor: AdvisorDefinition): string {
@@ -146,6 +146,12 @@ export class SupervisorAgent extends AbstractAgent<SupervisorAgentConfig, Superv
146
146
  remaining: config.tokenBudget,
147
147
  },
148
148
  factoryOptions: mergedFactoryOptions,
149
+ // The supervisor already hands this to its OWN run and its own
150
+ // coordinator tools; handing it to the spawn context is what
151
+ // makes a worker ask the same person the supervisor asks.
152
+ // Without it the two disagreed: the supervisor paused for a
153
+ // human and the workers it launched approved themselves.
154
+ ...(config.resumeHandler ? { resumeHandler: config.resumeHandler } : {}),
149
155
  tenantId,
150
156
  threadId,
151
157
  sessionId,
@@ -0,0 +1,131 @@
1
+ import { mkdtemp } from 'node:fs/promises'
2
+ import { tmpdir } from 'node:os'
3
+ import { join } from 'node:path'
4
+ import { describe, expect, it, vi } from 'vitest'
5
+
6
+ import { MockLLMProvider } from '../../provider/mock.js'
7
+ import { ToolRegistry } from '../../registry/tool/execute.js'
8
+ import type { AgentTaskContext } from '../../types/agent/task.js'
9
+ import type { ResumeHandler } from '../../types/hitl/index.js'
10
+ import { SupervisorAgent } from '../SupervisorAgent.js'
11
+
12
+ /**
13
+ * The supervisor already handed its resume handler to its OWN run and its
14
+ * own coordinator tools. It did not hand it to the spawn context, so the
15
+ * two disagreed: the supervisor paused for a human, and every worker it
16
+ * launched approved itself.
17
+ *
18
+ * This is the link a mutation run found untested — the previous version of
19
+ * these tests drove `AgentManager` with a context built by hand, which is
20
+ * not the path a host takes.
21
+ */
22
+
23
+ /** Captures the context the supervisor builds for its spawns. */
24
+ function spyManager(): {
25
+ contexts: AgentTaskContext[]
26
+ manager: unknown
27
+ } {
28
+ const contexts: AgentTaskContext[] = []
29
+ const manager = {
30
+ sendMessage: vi.fn(async (_options: unknown, context: AgentTaskContext) => {
31
+ contexts.push(context)
32
+ return {
33
+ taskId: 'task_1',
34
+ status: 'completed',
35
+ result: {
36
+ runId: 'run_child',
37
+ status: 'completed',
38
+ usage: { promptTokens: 1, completionTokens: 1, totalTokens: 2 },
39
+ cost: { totalCost: 0 },
40
+ iterations: 1,
41
+ durationMs: 1,
42
+ messages: [],
43
+ result: 'worker done',
44
+ },
45
+ }
46
+ }),
47
+ await: vi.fn(async () => undefined),
48
+ cancel: vi.fn(),
49
+ dispose: vi.fn(),
50
+ on: vi.fn(),
51
+ off: vi.fn(),
52
+ }
53
+ return { contexts, manager }
54
+ }
55
+
56
+ async function runSupervisor(resumeHandler?: ResumeHandler) {
57
+ const { contexts, manager } = spyManager()
58
+ const agent = new SupervisorAgent({
59
+ id: 'supervisor',
60
+ name: 'Supervisor',
61
+ version: '1',
62
+ category: 'test',
63
+ description: 'coordinates workers',
64
+ })
65
+
66
+ const provider = new MockLLMProvider({
67
+ turns: [
68
+ {
69
+ toolCalls: [
70
+ {
71
+ id: 'c1',
72
+ name: 'create_task',
73
+ rawArguments: JSON.stringify({
74
+ agent_id: 'worker',
75
+ prompt: 'do the thing',
76
+ description: 'a task',
77
+ }),
78
+ },
79
+ ],
80
+ },
81
+ { text: 'all done' },
82
+ ],
83
+ })
84
+
85
+ await agent
86
+ .run(
87
+ {
88
+ messages: [{ role: 'user', content: 'go', timestamp: 1 }],
89
+ workingDirectory: await mkdtemp(join(tmpdir(), 'namzu-sup-')),
90
+ },
91
+ {
92
+ provider,
93
+ agentIds: ['worker'],
94
+ agentManager: manager,
95
+ tools: new ToolRegistry(),
96
+ systemPrompt: 'You coordinate.',
97
+ model: 'mock-model',
98
+ tokenBudget: 100_000,
99
+ timeoutMs: 30_000,
100
+ maxIterations: 4,
101
+ sessionId: 'ses_sup',
102
+ threadId: 'thd_sup',
103
+ projectId: 'prj_sup',
104
+ tenantId: 'tnt_sup',
105
+ ...(resumeHandler ? { resumeHandler } : {}),
106
+ } as never,
107
+ )
108
+ .catch(() => undefined)
109
+
110
+ return contexts
111
+ }
112
+
113
+ describe('a supervisor hands its decision channel to the workers it launches', () => {
114
+ it('puts its own handler on the spawn context', async () => {
115
+ const handler = vi.fn(async () => ({ action: 'approve_tools' })) as unknown as ResumeHandler
116
+
117
+ const contexts = await runSupervisor(handler)
118
+
119
+ expect(contexts.length).toBeGreaterThan(0)
120
+ expect(contexts[0]?.resumeHandler).toBe(handler)
121
+ })
122
+
123
+ it('leaves the context without one when it has none itself', async () => {
124
+ const contexts = await runSupervisor()
125
+
126
+ expect(contexts.length).toBeGreaterThan(0)
127
+ // Absent still means the worker auto-approves, which is what every
128
+ // worker did before any of this.
129
+ expect(contexts[0]?.resumeHandler).toBeUndefined()
130
+ })
131
+ })