@namzu/sdk 46.0.0 → 48.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 (732) hide show
  1. package/CHANGELOG.md +325 -8
  2. package/README.md +7 -8
  3. package/dist/advisory/history.d.ts.map +1 -1
  4. package/dist/advisory/history.js +21 -1
  5. package/dist/advisory/history.js.map +1 -1
  6. package/dist/advisory/index.d.ts +1 -1
  7. package/dist/advisory/index.d.ts.map +1 -1
  8. package/dist/advisory/index.js +1 -1
  9. package/dist/advisory/index.js.map +1 -1
  10. package/dist/advisory/registry.d.ts +17 -0
  11. package/dist/advisory/registry.d.ts.map +1 -1
  12. package/dist/advisory/registry.js +26 -0
  13. package/dist/advisory/registry.js.map +1 -1
  14. package/dist/agents/PipelineAgent.d.ts +2 -46
  15. package/dist/agents/PipelineAgent.d.ts.map +1 -1
  16. package/dist/agents/PipelineAgent.js +2 -242
  17. package/dist/agents/PipelineAgent.js.map +1 -1
  18. package/dist/agents/QueryAgent.d.ts +21 -0
  19. package/dist/agents/QueryAgent.d.ts.map +1 -0
  20. package/dist/agents/QueryAgent.js +214 -0
  21. package/dist/agents/QueryAgent.js.map +1 -0
  22. package/dist/agents/ReactiveAgent.d.ts +4 -16
  23. package/dist/agents/ReactiveAgent.d.ts.map +1 -1
  24. package/dist/agents/ReactiveAgent.js +4 -183
  25. package/dist/agents/ReactiveAgent.js.map +1 -1
  26. package/dist/agents/RouterAgent.d.ts +2 -20
  27. package/dist/agents/RouterAgent.d.ts.map +1 -1
  28. package/dist/agents/RouterAgent.js +2 -266
  29. package/dist/agents/RouterAgent.js.map +1 -1
  30. package/dist/agents/SupervisorAgent.d.ts +3 -43
  31. package/dist/agents/SupervisorAgent.d.ts.map +1 -1
  32. package/dist/agents/SupervisorAgent.js +3 -418
  33. package/dist/agents/SupervisorAgent.js.map +1 -1
  34. package/dist/agents/defineAgent.d.ts +2 -1
  35. package/dist/agents/defineAgent.d.ts.map +1 -1
  36. package/dist/agents/defineAgent.js +6 -1
  37. package/dist/agents/defineAgent.js.map +1 -1
  38. package/dist/agents/examples/PipelineAgent.d.ts +46 -0
  39. package/dist/agents/examples/PipelineAgent.d.ts.map +1 -0
  40. package/dist/agents/examples/PipelineAgent.js +242 -0
  41. package/dist/agents/examples/PipelineAgent.js.map +1 -0
  42. package/dist/agents/examples/RouterAgent.d.ts +22 -0
  43. package/dist/agents/examples/RouterAgent.d.ts.map +1 -0
  44. package/dist/agents/examples/RouterAgent.js +268 -0
  45. package/dist/agents/examples/RouterAgent.js.map +1 -0
  46. package/dist/agents/examples/SupervisorAgent.d.ts +45 -0
  47. package/dist/agents/examples/SupervisorAgent.d.ts.map +1 -0
  48. package/dist/agents/examples/SupervisorAgent.js +406 -0
  49. package/dist/agents/examples/SupervisorAgent.js.map +1 -0
  50. package/dist/agents/explore.d.ts +6 -3
  51. package/dist/agents/explore.d.ts.map +1 -1
  52. package/dist/agents/explore.js +6 -3
  53. package/dist/agents/explore.js.map +1 -1
  54. package/dist/agents/forward-options.d.ts +11 -0
  55. package/dist/agents/forward-options.d.ts.map +1 -0
  56. package/dist/agents/forward-options.js +15 -0
  57. package/dist/agents/forward-options.js.map +1 -0
  58. package/dist/agents/index.d.ts +1 -0
  59. package/dist/agents/index.d.ts.map +1 -1
  60. package/dist/agents/index.js +2 -0
  61. package/dist/agents/index.js.map +1 -1
  62. package/dist/agents/runAgent.d.ts +19 -8
  63. package/dist/agents/runAgent.d.ts.map +1 -1
  64. package/dist/agents/runAgent.js +99 -29
  65. package/dist/agents/runAgent.js.map +1 -1
  66. package/dist/authorization/command-line.d.ts +2 -0
  67. package/dist/authorization/command-line.d.ts.map +1 -1
  68. package/dist/authorization/command-line.js +2 -2
  69. package/dist/authorization/command-line.js.map +1 -1
  70. package/dist/authorization/gate.d.ts +8 -0
  71. package/dist/authorization/gate.d.ts.map +1 -1
  72. package/dist/authorization/gate.js +12 -1
  73. package/dist/authorization/gate.js.map +1 -1
  74. package/dist/authorization/program.d.ts +151 -0
  75. package/dist/authorization/program.d.ts.map +1 -0
  76. package/dist/authorization/program.js +713 -0
  77. package/dist/authorization/program.js.map +1 -0
  78. package/dist/authorization/reexec-wrapper.d.ts +106 -0
  79. package/dist/authorization/reexec-wrapper.d.ts.map +1 -0
  80. package/dist/authorization/reexec-wrapper.js +532 -0
  81. package/dist/authorization/reexec-wrapper.js.map +1 -0
  82. package/dist/authorization/rules.d.ts +9 -0
  83. package/dist/authorization/rules.d.ts.map +1 -1
  84. package/dist/authorization/rules.js +8 -1
  85. package/dist/authorization/rules.js.map +1 -1
  86. package/dist/authorization/shell-lexer.d.ts +19 -4
  87. package/dist/authorization/shell-lexer.d.ts.map +1 -1
  88. package/dist/authorization/shell-lexer.js +91 -65
  89. package/dist/authorization/shell-lexer.js.map +1 -1
  90. package/dist/bridge/sse/mapper.d.ts.map +1 -1
  91. package/dist/bridge/sse/mapper.js +6 -0
  92. package/dist/bridge/sse/mapper.js.map +1 -1
  93. package/dist/capabilities/index.d.ts +54 -0
  94. package/dist/capabilities/index.d.ts.map +1 -0
  95. package/dist/capabilities/index.js +92 -0
  96. package/dist/capabilities/index.js.map +1 -0
  97. package/dist/config/registry.d.ts +2 -1
  98. package/dist/config/registry.d.ts.map +1 -1
  99. package/dist/config/registry.js +3 -2
  100. package/dist/config/registry.js.map +1 -1
  101. package/dist/connector/index.d.ts +4 -4
  102. package/dist/connector/index.d.ts.map +1 -1
  103. package/dist/connector/index.js +3 -3
  104. package/dist/connector/index.js.map +1 -1
  105. package/dist/connector/mcp/adapter.d.ts +16 -1
  106. package/dist/connector/mcp/adapter.d.ts.map +1 -1
  107. package/dist/connector/mcp/adapter.js +60 -4
  108. package/dist/connector/mcp/adapter.js.map +1 -1
  109. package/dist/connector/mcp/client.d.ts +13 -4
  110. package/dist/connector/mcp/client.d.ts.map +1 -1
  111. package/dist/connector/mcp/client.js +20 -3
  112. package/dist/connector/mcp/client.js.map +1 -1
  113. package/dist/connector/mcp/discovery.d.ts +24 -1
  114. package/dist/connector/mcp/discovery.d.ts.map +1 -1
  115. package/dist/connector/mcp/discovery.js +44 -0
  116. package/dist/connector/mcp/discovery.js.map +1 -1
  117. package/dist/connector/mcp/index.d.ts +2 -0
  118. package/dist/connector/mcp/index.d.ts.map +1 -1
  119. package/dist/connector/mcp/index.js +11 -0
  120. package/dist/connector/mcp/index.js.map +1 -1
  121. package/dist/connector/mcp/mcp-toolset.d.ts +133 -0
  122. package/dist/connector/mcp/mcp-toolset.d.ts.map +1 -0
  123. package/dist/connector/mcp/mcp-toolset.js +399 -0
  124. package/dist/connector/mcp/mcp-toolset.js.map +1 -0
  125. package/dist/connector/tools/index.d.ts +2 -2
  126. package/dist/connector/tools/index.d.ts.map +1 -1
  127. package/dist/connector/tools/index.js +1 -1
  128. package/dist/connector/tools/index.js.map +1 -1
  129. package/dist/connector/tools/router.d.ts +15 -13
  130. package/dist/connector/tools/router.d.ts.map +1 -1
  131. package/dist/connector/tools/router.js +30 -51
  132. package/dist/connector/tools/router.js.map +1 -1
  133. package/dist/contracts/a2a.d.ts +2 -2
  134. package/dist/directory/derive-supervisor.d.ts +2 -2
  135. package/dist/directory/derive-supervisor.d.ts.map +1 -1
  136. package/dist/directory/derive-supervisor.js +6 -7
  137. package/dist/directory/derive-supervisor.js.map +1 -1
  138. package/dist/directory/derive.d.ts.map +1 -1
  139. package/dist/directory/derive.js +5 -5
  140. package/dist/directory/derive.js.map +1 -1
  141. package/dist/execution/code-runtime/types.d.ts +2 -2
  142. package/dist/execution/code-runtime/types.js +1 -1
  143. package/dist/invariants/index.d.ts +2 -1
  144. package/dist/invariants/index.d.ts.map +1 -1
  145. package/dist/invariants/index.js +3 -2
  146. package/dist/invariants/index.js.map +1 -1
  147. package/dist/manager/agent/lifecycle.d.ts.map +1 -1
  148. package/dist/manager/agent/lifecycle.js +9 -0
  149. package/dist/manager/agent/lifecycle.js.map +1 -1
  150. package/dist/manager/connector/environment.d.ts +6 -0
  151. package/dist/manager/connector/environment.d.ts.map +1 -1
  152. package/dist/manager/connector/environment.js +11 -4
  153. package/dist/manager/connector/environment.js.map +1 -1
  154. package/dist/manager/connector/index.d.ts +2 -2
  155. package/dist/manager/connector/index.d.ts.map +1 -1
  156. package/dist/manager/connector/index.js +2 -2
  157. package/dist/manager/connector/index.js.map +1 -1
  158. package/dist/manager/connector/tenant.d.ts +6 -0
  159. package/dist/manager/connector/tenant.d.ts.map +1 -1
  160. package/dist/manager/connector/tenant.js +11 -4
  161. package/dist/manager/connector/tenant.js.map +1 -1
  162. package/dist/manager/index.d.ts +2 -2
  163. package/dist/manager/index.d.ts.map +1 -1
  164. package/dist/manager/index.js +2 -2
  165. package/dist/manager/index.js.map +1 -1
  166. package/dist/manager/resident/learning-observation.d.ts +4 -4
  167. package/dist/manager/resident/learning.d.ts +36 -36
  168. package/dist/manager/session/attribution.d.ts +22 -0
  169. package/dist/manager/session/attribution.d.ts.map +1 -0
  170. package/dist/manager/session/attribution.js +64 -0
  171. package/dist/manager/session/attribution.js.map +1 -0
  172. package/dist/manager/session/turn-recorder.d.ts +14 -0
  173. package/dist/manager/session/turn-recorder.d.ts.map +1 -1
  174. package/dist/manager/session/turn-recorder.js +208 -55
  175. package/dist/manager/session/turn-recorder.js.map +1 -1
  176. package/dist/peers/address.d.ts +36 -0
  177. package/dist/peers/address.d.ts.map +1 -0
  178. package/dist/peers/address.js +52 -0
  179. package/dist/peers/address.js.map +1 -0
  180. package/dist/peers/client.d.ts +47 -0
  181. package/dist/peers/client.d.ts.map +1 -0
  182. package/dist/peers/client.js +132 -0
  183. package/dist/peers/client.js.map +1 -0
  184. package/dist/peers/dir.d.ts +88 -0
  185. package/dist/peers/dir.d.ts.map +1 -0
  186. package/dist/peers/dir.js +139 -0
  187. package/dist/peers/dir.js.map +1 -0
  188. package/dist/peers/endpoint.d.ts +144 -0
  189. package/dist/peers/endpoint.d.ts.map +1 -0
  190. package/dist/peers/endpoint.js +420 -0
  191. package/dist/peers/endpoint.js.map +1 -0
  192. package/dist/peers/envelope.d.ts +42 -0
  193. package/dist/peers/envelope.d.ts.map +1 -0
  194. package/dist/peers/envelope.js +110 -0
  195. package/dist/peers/envelope.js.map +1 -0
  196. package/dist/peers/index.d.ts +30 -0
  197. package/dist/peers/index.d.ts.map +1 -0
  198. package/dist/peers/index.js +22 -0
  199. package/dist/peers/index.js.map +1 -0
  200. package/dist/peers/protocol.d.ts +645 -0
  201. package/dist/peers/protocol.d.ts.map +1 -0
  202. package/dist/peers/protocol.js +151 -0
  203. package/dist/peers/protocol.js.map +1 -0
  204. package/dist/peers/record.d.ts +71 -0
  205. package/dist/peers/record.d.ts.map +1 -0
  206. package/dist/peers/record.js +45 -0
  207. package/dist/peers/record.js.map +1 -0
  208. package/dist/peers/registry.d.ts +54 -0
  209. package/dist/peers/registry.d.ts.map +1 -0
  210. package/dist/peers/registry.js +213 -0
  211. package/dist/peers/registry.js.map +1 -0
  212. package/dist/plugin/define.d.ts +24 -0
  213. package/dist/plugin/define.d.ts.map +1 -0
  214. package/dist/plugin/define.js +42 -0
  215. package/dist/plugin/define.js.map +1 -0
  216. package/dist/plugin/index.d.ts +2 -0
  217. package/dist/plugin/index.d.ts.map +1 -1
  218. package/dist/plugin/index.js +1 -0
  219. package/dist/plugin/index.js.map +1 -1
  220. package/dist/plugin/lifecycle.d.ts +27 -3
  221. package/dist/plugin/lifecycle.d.ts.map +1 -1
  222. package/dist/plugin/lifecycle.js +242 -92
  223. package/dist/plugin/lifecycle.js.map +1 -1
  224. package/dist/plugin/resolver.d.ts +2 -2
  225. package/dist/plugin/resolver.d.ts.map +1 -1
  226. package/dist/plugin/resolver.js.map +1 -1
  227. package/dist/plugin/shell-hook.d.ts.map +1 -1
  228. package/dist/plugin/shell-hook.js +17 -3
  229. package/dist/plugin/shell-hook.js.map +1 -1
  230. package/dist/probe/errors.d.ts +2 -1
  231. package/dist/probe/errors.d.ts.map +1 -1
  232. package/dist/probe/errors.js +3 -2
  233. package/dist/probe/errors.js.map +1 -1
  234. package/dist/prompt/coding-agent-doctrine.d.ts +18 -7
  235. package/dist/prompt/coding-agent-doctrine.d.ts.map +1 -1
  236. package/dist/prompt/coding-agent-doctrine.js +11 -6
  237. package/dist/prompt/coding-agent-doctrine.js.map +1 -1
  238. package/dist/prompt/contributions.d.ts +4 -1
  239. package/dist/prompt/contributions.d.ts.map +1 -1
  240. package/dist/prompt/contributions.js +7 -2
  241. package/dist/prompt/contributions.js.map +1 -1
  242. package/dist/prompt/index.d.ts +1 -1
  243. package/dist/prompt/index.d.ts.map +1 -1
  244. package/dist/prompt/index.js +1 -1
  245. package/dist/prompt/index.js.map +1 -1
  246. package/dist/provider/collect-chat-completion.d.ts +6 -1
  247. package/dist/provider/collect-chat-completion.d.ts.map +1 -1
  248. package/dist/provider/collect-chat-completion.js +88 -10
  249. package/dist/provider/collect-chat-completion.js.map +1 -1
  250. package/dist/provider/mock.d.ts.map +1 -1
  251. package/dist/provider/mock.js +23 -6
  252. package/dist/provider/mock.js.map +1 -1
  253. package/dist/provider/registry.d.ts +2 -1
  254. package/dist/provider/registry.d.ts.map +1 -1
  255. package/dist/provider/registry.js +3 -2
  256. package/dist/provider/registry.js.map +1 -1
  257. package/dist/provider/tool-call-framing.d.ts +164 -0
  258. package/dist/provider/tool-call-framing.d.ts.map +1 -0
  259. package/dist/provider/tool-call-framing.js +163 -0
  260. package/dist/provider/tool-call-framing.js.map +1 -0
  261. package/dist/public-runtime.d.ts +24 -11
  262. package/dist/public-runtime.d.ts.map +1 -1
  263. package/dist/public-runtime.js +45 -9
  264. package/dist/public-runtime.js.map +1 -1
  265. package/dist/public-tools.d.ts +6 -4
  266. package/dist/public-tools.d.ts.map +1 -1
  267. package/dist/public-tools.js +8 -3
  268. package/dist/public-tools.js.map +1 -1
  269. package/dist/public-types.d.ts +13 -2
  270. package/dist/public-types.d.ts.map +1 -1
  271. package/dist/read-model/registry.d.ts +2 -1
  272. package/dist/read-model/registry.d.ts.map +1 -1
  273. package/dist/read-model/registry.js +3 -2
  274. package/dist/read-model/registry.js.map +1 -1
  275. package/dist/registry/ManagedRegistry.d.ts +30 -0
  276. package/dist/registry/ManagedRegistry.d.ts.map +1 -1
  277. package/dist/registry/ManagedRegistry.js +45 -6
  278. package/dist/registry/ManagedRegistry.js.map +1 -1
  279. package/dist/registry/collision.d.ts +57 -0
  280. package/dist/registry/collision.d.ts.map +1 -0
  281. package/dist/registry/collision.js +41 -0
  282. package/dist/registry/collision.js.map +1 -0
  283. package/dist/registry/command/index.d.ts +5 -3
  284. package/dist/registry/command/index.d.ts.map +1 -1
  285. package/dist/registry/command/index.js +6 -4
  286. package/dist/registry/command/index.js.map +1 -1
  287. package/dist/registry/index.d.ts +3 -4
  288. package/dist/registry/index.d.ts.map +1 -1
  289. package/dist/registry/index.js +2 -2
  290. package/dist/registry/index.js.map +1 -1
  291. package/dist/registry/plugin/index.d.ts.map +1 -1
  292. package/dist/registry/plugin/index.js +14 -1
  293. package/dist/registry/plugin/index.js.map +1 -1
  294. package/dist/registry/tool/callable.d.ts +7 -7
  295. package/dist/registry/tool/callable.d.ts.map +1 -1
  296. package/dist/registry/tool/callable.js +6 -7
  297. package/dist/registry/tool/callable.js.map +1 -1
  298. package/dist/registry/tool/execute.d.ts +14 -77
  299. package/dist/registry/tool/execute.d.ts.map +1 -1
  300. package/dist/registry/tool/execute.js +15 -727
  301. package/dist/registry/tool/execute.js.map +1 -1
  302. package/dist/registry/tool/portable.d.ts +25 -0
  303. package/dist/registry/tool/portable.d.ts.map +1 -1
  304. package/dist/registry/tool/portable.js +50 -0
  305. package/dist/registry/tool/portable.js.map +1 -1
  306. package/dist/registry/tool/presentation.d.ts +6 -5
  307. package/dist/registry/tool/presentation.d.ts.map +1 -1
  308. package/dist/registry/tool/presentation.js +3 -3
  309. package/dist/registry/tool/presentation.js.map +1 -1
  310. package/dist/runtime/bidi/session.d.ts +5 -4
  311. package/dist/runtime/bidi/session.d.ts.map +1 -1
  312. package/dist/runtime/bidi/session.js +18 -1
  313. package/dist/runtime/bidi/session.js.map +1 -1
  314. package/dist/runtime/query/executor/tool-call-admission.d.ts +45 -2
  315. package/dist/runtime/query/executor/tool-call-admission.d.ts.map +1 -1
  316. package/dist/runtime/query/executor/tool-call-admission.js +189 -5
  317. package/dist/runtime/query/executor/tool-call-admission.js.map +1 -1
  318. package/dist/runtime/query/executor.d.ts +33 -3
  319. package/dist/runtime/query/executor.d.ts.map +1 -1
  320. package/dist/runtime/query/executor.js +86 -10
  321. package/dist/runtime/query/executor.js.map +1 -1
  322. package/dist/runtime/query/file-evidence-replay.d.ts +1 -1
  323. package/dist/runtime/query/file-evidence-replay.d.ts.map +1 -1
  324. package/dist/runtime/query/file-evidence-replay.js +8 -7
  325. package/dist/runtime/query/file-evidence-replay.js.map +1 -1
  326. package/dist/runtime/query/fork/prepare.d.ts +4 -1
  327. package/dist/runtime/query/fork/prepare.d.ts.map +1 -1
  328. package/dist/runtime/query/fork/prepare.js +4 -0
  329. package/dist/runtime/query/fork/prepare.js.map +1 -1
  330. package/dist/runtime/query/guardrail-presets.d.ts +4 -3
  331. package/dist/runtime/query/guardrail-presets.d.ts.map +1 -1
  332. package/dist/runtime/query/guardrail-presets.js +4 -3
  333. package/dist/runtime/query/guardrail-presets.js.map +1 -1
  334. package/dist/runtime/query/index.d.ts +23 -10
  335. package/dist/runtime/query/index.d.ts.map +1 -1
  336. package/dist/runtime/query/index.js +149 -70
  337. package/dist/runtime/query/index.js.map +1 -1
  338. package/dist/runtime/query/iteration/index.d.ts.map +1 -1
  339. package/dist/runtime/query/iteration/index.js +8 -1
  340. package/dist/runtime/query/iteration/index.js.map +1 -1
  341. package/dist/runtime/query/iteration/phases/compaction.js +1 -1
  342. package/dist/runtime/query/iteration/phases/compaction.js.map +1 -1
  343. package/dist/runtime/query/iteration/phases/context.d.ts +2 -2
  344. package/dist/runtime/query/iteration/phases/context.d.ts.map +1 -1
  345. package/dist/runtime/query/iteration/phases/tool-review.d.ts.map +1 -1
  346. package/dist/runtime/query/iteration/phases/tool-review.js +55 -2
  347. package/dist/runtime/query/iteration/phases/tool-review.js.map +1 -1
  348. package/dist/runtime/query/iteration/stream-turn.d.ts.map +1 -1
  349. package/dist/runtime/query/iteration/stream-turn.js +342 -116
  350. package/dist/runtime/query/iteration/stream-turn.js.map +1 -1
  351. package/dist/runtime/query/iteration/tool-input.d.ts +79 -0
  352. package/dist/runtime/query/iteration/tool-input.d.ts.map +1 -0
  353. package/dist/runtime/query/iteration/tool-input.js +291 -0
  354. package/dist/runtime/query/iteration/tool-input.js.map +1 -0
  355. package/dist/runtime/query/observation-context.d.ts +2 -2
  356. package/dist/runtime/query/observation-context.d.ts.map +1 -1
  357. package/dist/runtime/query/observation-context.js.map +1 -1
  358. package/dist/runtime/query/prelude-lease.d.ts +18 -0
  359. package/dist/runtime/query/prelude-lease.d.ts.map +1 -0
  360. package/dist/runtime/query/prelude-lease.js +121 -0
  361. package/dist/runtime/query/prelude-lease.js.map +1 -0
  362. package/dist/runtime/query/prepare-turn.d.ts.map +1 -1
  363. package/dist/runtime/query/prepare-turn.js +386 -187
  364. package/dist/runtime/query/prepare-turn.js.map +1 -1
  365. package/dist/runtime/query/prompt-cache.d.ts +2 -2
  366. package/dist/runtime/query/prompt-cache.d.ts.map +1 -1
  367. package/dist/runtime/query/prompt.d.ts +2 -2
  368. package/dist/runtime/query/prompt.d.ts.map +1 -1
  369. package/dist/runtime/query/prompt.js +1 -1
  370. package/dist/runtime/query/prompt.js.map +1 -1
  371. package/dist/runtime/query/resume-session.d.ts.map +1 -1
  372. package/dist/runtime/query/resume-session.js +37 -2
  373. package/dist/runtime/query/resume-session.js.map +1 -1
  374. package/dist/runtime/query/review-policy.d.ts +22 -3
  375. package/dist/runtime/query/review-policy.d.ts.map +1 -1
  376. package/dist/runtime/query/review-policy.js +84 -6
  377. package/dist/runtime/query/review-policy.js.map +1 -1
  378. package/dist/runtime/query/tooling.d.ts +3 -2
  379. package/dist/runtime/query/tooling.d.ts.map +1 -1
  380. package/dist/runtime/query/tooling.js.map +1 -1
  381. package/dist/runtime/query/turn-state.d.ts.map +1 -1
  382. package/dist/runtime/query/turn-state.js +5 -0
  383. package/dist/runtime/query/turn-state.js.map +1 -1
  384. package/dist/runtime/system-events.d.ts +112 -0
  385. package/dist/runtime/system-events.d.ts.map +1 -0
  386. package/dist/runtime/system-events.js +183 -0
  387. package/dist/runtime/system-events.js.map +1 -0
  388. package/dist/scheduler/delegating.d.ts +2 -1
  389. package/dist/scheduler/delegating.d.ts.map +1 -1
  390. package/dist/scheduler/delegating.js +3 -2
  391. package/dist/scheduler/delegating.js.map +1 -1
  392. package/dist/skills/index.d.ts +1 -1
  393. package/dist/skills/index.d.ts.map +1 -1
  394. package/dist/skills/index.js +1 -1
  395. package/dist/skills/index.js.map +1 -1
  396. package/dist/skills/registry.d.ts +12 -0
  397. package/dist/skills/registry.d.ts.map +1 -1
  398. package/dist/skills/registry.js +19 -0
  399. package/dist/skills/registry.js.map +1 -1
  400. package/dist/store/evidence/index-page.d.ts +2 -2
  401. package/dist/store/session-log/conformance.d.ts +1 -1
  402. package/dist/store/session-log/conformance.d.ts.map +1 -1
  403. package/dist/store/session-log/conformance.js +49 -8
  404. package/dist/store/session-log/conformance.js.map +1 -1
  405. package/dist/store/session-log/core.d.ts +8 -3
  406. package/dist/store/session-log/core.d.ts.map +1 -1
  407. package/dist/store/session-log/core.js +2 -1
  408. package/dist/store/session-log/core.js.map +1 -1
  409. package/dist/store/session-log/fold.d.ts +12 -0
  410. package/dist/store/session-log/fold.d.ts.map +1 -1
  411. package/dist/store/session-log/fold.js +57 -7
  412. package/dist/store/session-log/fold.js.map +1 -1
  413. package/dist/store/session-log/index.d.ts +2 -2
  414. package/dist/store/session-log/index.d.ts.map +1 -1
  415. package/dist/store/session-log/index.js +1 -1
  416. package/dist/store/session-log/index.js.map +1 -1
  417. package/dist/test-support/toolset.d.ts +19 -0
  418. package/dist/test-support/toolset.d.ts.map +1 -0
  419. package/dist/test-support/toolset.js +20 -0
  420. package/dist/test-support/toolset.js.map +1 -0
  421. package/dist/tools/builtins/bash.d.ts +29 -0
  422. package/dist/tools/builtins/bash.d.ts.map +1 -1
  423. package/dist/tools/builtins/bash.js +19 -9
  424. package/dist/tools/builtins/bash.js.map +1 -1
  425. package/dist/tools/builtins/browser-url.d.ts +1 -1
  426. package/dist/tools/builtins/browser-url.js +1 -1
  427. package/dist/tools/builtins/browser.d.ts +6 -6
  428. package/dist/tools/builtins/computer-use.d.ts.map +1 -1
  429. package/dist/tools/builtins/computer-use.js +19 -11
  430. package/dist/tools/builtins/computer-use.js.map +1 -1
  431. package/dist/tools/builtins/edit.d.ts.map +1 -1
  432. package/dist/tools/builtins/edit.js +9 -1
  433. package/dist/tools/builtins/edit.js.map +1 -1
  434. package/dist/tools/builtins/json-string-hint.d.ts +15 -0
  435. package/dist/tools/builtins/json-string-hint.d.ts.map +1 -0
  436. package/dist/tools/builtins/json-string-hint.js +17 -0
  437. package/dist/tools/builtins/json-string-hint.js.map +1 -0
  438. package/dist/tools/builtins/search-tools.d.ts.map +1 -1
  439. package/dist/tools/builtins/search-tools.js +7 -15
  440. package/dist/tools/builtins/search-tools.js.map +1 -1
  441. package/dist/tools/builtins/write-file.d.ts.map +1 -1
  442. package/dist/tools/builtins/write-file.js +11 -0
  443. package/dist/tools/builtins/write-file.js.map +1 -1
  444. package/dist/tools/command-shell.d.ts +10 -0
  445. package/dist/tools/command-shell.d.ts.map +1 -1
  446. package/dist/tools/command-shell.js +45 -1
  447. package/dist/tools/command-shell.js.map +1 -1
  448. package/dist/tools/coordinator/agent.d.ts.map +1 -1
  449. package/dist/tools/coordinator/agent.js +5 -0
  450. package/dist/tools/coordinator/agent.js.map +1 -1
  451. package/dist/tools/coordinator/ask-user-question.d.ts.map +1 -1
  452. package/dist/tools/coordinator/ask-user-question.js +26 -13
  453. package/dist/tools/coordinator/ask-user-question.js.map +1 -1
  454. package/dist/tools/coordinator/index.d.ts.map +1 -1
  455. package/dist/tools/coordinator/index.js +5 -0
  456. package/dist/tools/coordinator/index.js.map +1 -1
  457. package/dist/tools/coordinator/question-options.d.ts +78 -0
  458. package/dist/tools/coordinator/question-options.d.ts.map +1 -0
  459. package/dist/tools/coordinator/question-options.js +153 -0
  460. package/dist/tools/coordinator/question-options.js.map +1 -0
  461. package/dist/tools/defineTool.d.ts +10 -0
  462. package/dist/tools/defineTool.d.ts.map +1 -1
  463. package/dist/tools/defineTool.js +17 -0
  464. package/dist/tools/defineTool.js.map +1 -1
  465. package/dist/tools/memory/search.d.ts.map +1 -1
  466. package/dist/tools/memory/search.js +4 -1
  467. package/dist/tools/memory/search.js.map +1 -1
  468. package/dist/tools/memory/update.d.ts.map +1 -1
  469. package/dist/tools/memory/update.js +8 -5
  470. package/dist/tools/memory/update.js.map +1 -1
  471. package/dist/tools/render-nonce.d.ts +47 -0
  472. package/dist/tools/render-nonce.d.ts.map +1 -0
  473. package/dist/tools/render-nonce.js +63 -0
  474. package/dist/tools/render-nonce.js.map +1 -0
  475. package/dist/tools/roster.d.ts +46 -19
  476. package/dist/tools/roster.d.ts.map +1 -1
  477. package/dist/tools/roster.js +63 -33
  478. package/dist/tools/roster.js.map +1 -1
  479. package/dist/tools/schedules/schedule-tool.d.ts.map +1 -1
  480. package/dist/tools/schedules/schedule-tool.js +94 -14
  481. package/dist/tools/schedules/schedule-tool.js.map +1 -1
  482. package/dist/tools/schedules/types.d.ts +52 -6
  483. package/dist/tools/schedules/types.d.ts.map +1 -1
  484. package/dist/tools/trusted-read-only.d.ts +9 -5
  485. package/dist/tools/trusted-read-only.d.ts.map +1 -1
  486. package/dist/tools/trusted-read-only.js +14 -10
  487. package/dist/tools/trusted-read-only.js.map +1 -1
  488. package/dist/tools/untrusted-envelope.d.ts +67 -28
  489. package/dist/tools/untrusted-envelope.d.ts.map +1 -1
  490. package/dist/tools/untrusted-envelope.js +108 -59
  491. package/dist/tools/untrusted-envelope.js.map +1 -1
  492. package/dist/toolsets/combine.d.ts +44 -0
  493. package/dist/toolsets/combine.d.ts.map +1 -0
  494. package/dist/toolsets/combine.js +153 -0
  495. package/dist/toolsets/combine.js.map +1 -0
  496. package/dist/toolsets/manager.d.ts +201 -0
  497. package/dist/toolsets/manager.d.ts.map +1 -0
  498. package/dist/toolsets/manager.js +837 -0
  499. package/dist/toolsets/manager.js.map +1 -0
  500. package/dist/toolsets/source-glob.d.ts +15 -0
  501. package/dist/toolsets/source-glob.d.ts.map +1 -0
  502. package/dist/toolsets/source-glob.js +23 -0
  503. package/dist/toolsets/source-glob.js.map +1 -0
  504. package/dist/toolsets/toolset.d.ts +20 -0
  505. package/dist/toolsets/toolset.d.ts.map +1 -0
  506. package/dist/toolsets/toolset.js +28 -0
  507. package/dist/toolsets/toolset.js.map +1 -0
  508. package/dist/toolsets/types.d.ts +128 -0
  509. package/dist/toolsets/types.d.ts.map +1 -0
  510. package/dist/toolsets/types.js +33 -0
  511. package/dist/toolsets/types.js.map +1 -0
  512. package/dist/toolsets/wrappers.d.ts +59 -0
  513. package/dist/toolsets/wrappers.d.ts.map +1 -0
  514. package/dist/toolsets/wrappers.js +165 -0
  515. package/dist/toolsets/wrappers.js.map +1 -0
  516. package/dist/types/agent/base.d.ts +27 -16
  517. package/dist/types/agent/base.d.ts.map +1 -1
  518. package/dist/types/agent/index.d.ts +1 -0
  519. package/dist/types/agent/index.d.ts.map +1 -1
  520. package/dist/types/agent/index.js +1 -0
  521. package/dist/types/agent/index.js.map +1 -1
  522. package/dist/types/agent/pipeline.d.ts +2 -0
  523. package/dist/types/agent/pipeline.d.ts.map +1 -1
  524. package/dist/types/agent/query.d.ts +117 -0
  525. package/dist/types/agent/query.d.ts.map +1 -0
  526. package/dist/types/agent/query.js +2 -0
  527. package/dist/types/agent/query.js.map +1 -0
  528. package/dist/types/agent/reactive.d.ts +2 -129
  529. package/dist/types/agent/reactive.d.ts.map +1 -1
  530. package/dist/types/agent/router.d.ts +2 -0
  531. package/dist/types/agent/router.d.ts.map +1 -1
  532. package/dist/types/agent/supervisor.d.ts +5 -2
  533. package/dist/types/agent/supervisor.d.ts.map +1 -1
  534. package/dist/types/authorization/index.d.ts +49 -12
  535. package/dist/types/authorization/index.d.ts.map +1 -1
  536. package/dist/types/authorization/index.js +6 -0
  537. package/dist/types/authorization/index.js.map +1 -1
  538. package/dist/types/connector/mcp.d.ts +32 -0
  539. package/dist/types/connector/mcp.d.ts.map +1 -1
  540. package/dist/types/errors/index.d.ts +15 -0
  541. package/dist/types/errors/index.d.ts.map +1 -1
  542. package/dist/types/errors/index.js.map +1 -1
  543. package/dist/types/hitl/index.d.ts +57 -0
  544. package/dist/types/hitl/index.d.ts.map +1 -1
  545. package/dist/types/hitl/index.js.map +1 -1
  546. package/dist/types/message/index.d.ts +130 -9
  547. package/dist/types/message/index.d.ts.map +1 -1
  548. package/dist/types/message/index.js +4 -1
  549. package/dist/types/message/index.js.map +1 -1
  550. package/dist/types/plugin/index.d.ts +22 -4
  551. package/dist/types/plugin/index.d.ts.map +1 -1
  552. package/dist/types/plugin/index.js +1 -0
  553. package/dist/types/plugin/index.js.map +1 -1
  554. package/dist/types/provider/chat.d.ts +5 -0
  555. package/dist/types/provider/chat.d.ts.map +1 -1
  556. package/dist/types/provider/config.d.ts +8 -3
  557. package/dist/types/provider/config.d.ts.map +1 -1
  558. package/dist/types/provider/stream.d.ts +39 -0
  559. package/dist/types/provider/stream.d.ts.map +1 -1
  560. package/dist/types/sandbox/index.d.ts +1 -1
  561. package/dist/types/session/events.d.ts +14 -3
  562. package/dist/types/session/events.d.ts.map +1 -1
  563. package/dist/types/session/events.js.map +1 -1
  564. package/dist/types/tool/index.d.ts +152 -91
  565. package/dist/types/tool/index.d.ts.map +1 -1
  566. package/dist/types/tool/index.js.map +1 -1
  567. package/dist/types/toolset/index.d.ts +10 -40
  568. package/dist/types/toolset/index.d.ts.map +1 -1
  569. package/package.json +1 -1
  570. package/src/advisory/history.ts +27 -2
  571. package/src/advisory/index.ts +1 -1
  572. package/src/advisory/registry.ts +33 -0
  573. package/src/agents/AGENTS.md +14 -7
  574. package/src/agents/PipelineAgent.ts +2 -303
  575. package/src/agents/QueryAgent.ts +269 -0
  576. package/src/agents/ReactiveAgent.ts +6 -216
  577. package/src/agents/RouterAgent.ts +2 -337
  578. package/src/agents/SupervisorAgent.ts +3 -476
  579. package/src/agents/defineAgent.ts +13 -2
  580. package/src/agents/examples/PipelineAgent.ts +302 -0
  581. package/src/agents/examples/RouterAgent.ts +338 -0
  582. package/src/agents/examples/SupervisorAgent.ts +472 -0
  583. package/src/agents/explore.ts +6 -3
  584. package/src/agents/forward-options.ts +37 -0
  585. package/src/agents/index.ts +2 -0
  586. package/src/agents/runAgent.ts +144 -37
  587. package/src/authorization/command-line.ts +2 -2
  588. package/src/authorization/gate.ts +21 -1
  589. package/src/authorization/program.ts +773 -0
  590. package/src/authorization/reexec-wrapper.ts +589 -0
  591. package/src/authorization/rules.ts +18 -1
  592. package/src/authorization/shell-lexer.ts +104 -59
  593. package/src/bridge/sse/mapper.ts +6 -0
  594. package/src/capabilities/index.ts +157 -0
  595. package/src/config/registry.ts +4 -1
  596. package/src/connector/index.ts +9 -2
  597. package/src/connector/mcp/adapter.ts +58 -3
  598. package/src/connector/mcp/client.ts +20 -4
  599. package/src/connector/mcp/discovery.ts +60 -0
  600. package/src/connector/mcp/index.ts +13 -0
  601. package/src/connector/mcp/mcp-toolset.ts +515 -0
  602. package/src/connector/tools/index.ts +2 -2
  603. package/src/connector/tools/router.ts +35 -58
  604. package/src/directory/derive-supervisor.ts +12 -8
  605. package/src/directory/derive.ts +8 -5
  606. package/src/execution/code-runtime/types.ts +2 -2
  607. package/src/invariants/index.ts +4 -1
  608. package/src/manager/agent/lifecycle.ts +9 -0
  609. package/src/manager/connector/environment.ts +17 -4
  610. package/src/manager/connector/index.ts +2 -2
  611. package/src/manager/connector/tenant.ts +17 -4
  612. package/src/manager/index.ts +2 -2
  613. package/src/manager/session/attribution.ts +79 -0
  614. package/src/manager/session/turn-recorder.ts +211 -55
  615. package/src/peers/address.ts +58 -0
  616. package/src/peers/client.ts +202 -0
  617. package/src/peers/dir.ts +176 -0
  618. package/src/peers/endpoint.ts +564 -0
  619. package/src/peers/envelope.ts +121 -0
  620. package/src/peers/index.ts +96 -0
  621. package/src/peers/protocol.ts +196 -0
  622. package/src/peers/record.ts +56 -0
  623. package/src/peers/registry.ts +241 -0
  624. package/src/plugin/define.ts +68 -0
  625. package/src/plugin/index.ts +2 -0
  626. package/src/plugin/lifecycle.ts +286 -106
  627. package/src/plugin/resolver.ts +6 -3
  628. package/src/plugin/shell-hook.ts +21 -5
  629. package/src/probe/errors.ts +4 -1
  630. package/src/prompt/coding-agent-doctrine.ts +22 -10
  631. package/src/prompt/contributions.ts +12 -2
  632. package/src/prompt/index.ts +1 -0
  633. package/src/provider/collect-chat-completion.ts +96 -11
  634. package/src/provider/mock.ts +24 -6
  635. package/src/provider/registry.ts +4 -1
  636. package/src/provider/tool-call-framing.ts +226 -0
  637. package/src/public-runtime.ts +136 -7
  638. package/src/public-tools.ts +24 -4
  639. package/src/public-types.ts +60 -6
  640. package/src/read-model/registry.ts +7 -2
  641. package/src/registry/ManagedRegistry.ts +57 -6
  642. package/src/registry/collision.ts +64 -0
  643. package/src/registry/command/index.ts +7 -3
  644. package/src/registry/index.ts +3 -9
  645. package/src/registry/plugin/index.ts +14 -1
  646. package/src/registry/tool/callable.ts +8 -9
  647. package/src/registry/tool/execute.ts +16 -846
  648. package/src/registry/tool/portable.ts +59 -0
  649. package/src/registry/tool/presentation.ts +6 -5
  650. package/src/runtime/bidi/session.ts +24 -5
  651. package/src/runtime/query/executor/tool-call-admission.ts +228 -6
  652. package/src/runtime/query/executor.ts +110 -12
  653. package/src/runtime/query/file-evidence-replay.ts +8 -7
  654. package/src/runtime/query/fork/prepare.ts +6 -1
  655. package/src/runtime/query/guardrail-presets.ts +4 -3
  656. package/src/runtime/query/index.ts +199 -101
  657. package/src/runtime/query/iteration/index.ts +13 -3
  658. package/src/runtime/query/iteration/phases/compaction.ts +1 -1
  659. package/src/runtime/query/iteration/phases/context.ts +2 -2
  660. package/src/runtime/query/iteration/phases/tool-review.ts +59 -2
  661. package/src/runtime/query/iteration/stream-turn.ts +390 -136
  662. package/src/runtime/query/iteration/tool-input.ts +284 -0
  663. package/src/runtime/query/observation-context.ts +2 -2
  664. package/src/runtime/query/prelude-lease.ts +132 -0
  665. package/src/runtime/query/prepare-turn.ts +477 -198
  666. package/src/runtime/query/prompt-cache.ts +2 -2
  667. package/src/runtime/query/prompt.ts +4 -4
  668. package/src/runtime/query/resume-session.ts +42 -3
  669. package/src/runtime/query/review-policy.ts +87 -9
  670. package/src/runtime/query/tooling.ts +3 -6
  671. package/src/runtime/query/turn-state.ts +4 -0
  672. package/src/runtime/system-events.ts +246 -0
  673. package/src/scheduler/delegating.ts +7 -2
  674. package/src/skills/index.ts +1 -1
  675. package/src/skills/registry.ts +25 -0
  676. package/src/store/session-log/conformance.ts +51 -8
  677. package/src/store/session-log/core.ts +10 -4
  678. package/src/store/session-log/fold.ts +33 -7
  679. package/src/store/session-log/index.ts +2 -0
  680. package/src/test-support/toolset.ts +23 -0
  681. package/src/tools/builtins/bash.ts +27 -10
  682. package/src/tools/builtins/browser-url.ts +1 -1
  683. package/src/tools/builtins/computer-use.ts +21 -11
  684. package/src/tools/builtins/edit.ts +12 -2
  685. package/src/tools/builtins/json-string-hint.ts +16 -0
  686. package/src/tools/builtins/search-tools.ts +7 -20
  687. package/src/tools/builtins/write-file.ts +12 -0
  688. package/src/tools/command-shell.ts +46 -1
  689. package/src/tools/coordinator/agent.ts +6 -0
  690. package/src/tools/coordinator/ask-user-question.ts +29 -15
  691. package/src/tools/coordinator/index.ts +6 -0
  692. package/src/tools/coordinator/question-options.ts +195 -0
  693. package/src/tools/defineTool.ts +28 -0
  694. package/src/tools/memory/search.ts +4 -1
  695. package/src/tools/memory/update.ts +8 -5
  696. package/src/tools/render-nonce.ts +69 -0
  697. package/src/tools/roster.ts +84 -33
  698. package/src/tools/schedules/schedule-tool.ts +107 -14
  699. package/src/tools/schedules/types.ts +52 -6
  700. package/src/tools/trusted-read-only.ts +19 -10
  701. package/src/tools/untrusted-envelope.ts +121 -57
  702. package/src/toolsets/combine.ts +181 -0
  703. package/src/toolsets/manager.ts +996 -0
  704. package/src/toolsets/source-glob.ts +22 -0
  705. package/src/toolsets/toolset.ts +31 -0
  706. package/src/toolsets/types.ts +154 -0
  707. package/src/toolsets/wrappers.ts +191 -0
  708. package/src/types/agent/base.ts +29 -16
  709. package/src/types/agent/index.ts +1 -0
  710. package/src/types/agent/pipeline.ts +2 -0
  711. package/src/types/agent/query.ts +129 -0
  712. package/src/types/agent/reactive.ts +5 -142
  713. package/src/types/agent/router.ts +2 -0
  714. package/src/types/agent/supervisor.ts +5 -2
  715. package/src/types/authorization/index.ts +12 -0
  716. package/src/types/connector/mcp.ts +32 -0
  717. package/src/types/errors/index.ts +15 -0
  718. package/src/types/hitl/index.ts +57 -0
  719. package/src/types/message/index.ts +135 -7
  720. package/src/types/plugin/index.ts +44 -21
  721. package/src/types/provider/chat.ts +5 -0
  722. package/src/types/provider/config.ts +8 -3
  723. package/src/types/provider/stream.ts +39 -0
  724. package/src/types/sandbox/index.ts +1 -1
  725. package/src/types/session/events.ts +14 -3
  726. package/src/types/tool/index.ts +154 -105
  727. package/src/types/toolset/index.ts +10 -47
  728. package/dist/registry/toolset/catalog.d.ts +0 -42
  729. package/dist/registry/toolset/catalog.d.ts.map +0 -1
  730. package/dist/registry/toolset/catalog.js +0 -234
  731. package/dist/registry/toolset/catalog.js.map +0 -1
  732. package/src/registry/toolset/catalog.ts +0 -308
@@ -1,74 +1,17 @@
1
- import { SpanStatusCode, context as otelContext, trace } from '@opentelemetry/api'
2
- import { assertStrictSchema } from '../../provider/strict-schema.js'
3
- import { GENAI, NAMZU, toolSpanName } from '../../telemetry/attributes.js'
4
- import { recordToolCall } from '../../telemetry/metrics.js'
5
- import { getTracer } from '../../telemetry/runtime-accessors.js'
6
- import { isTrustedReadOnly } from '../../tools/trusted-read-only.js'
7
- import type { ToolResultGuardrailSpec } from '../../types/guardrail/index.js'
8
- import { PLAN_MODE_REFUSAL } from '../../types/permission/index.js'
9
- import type {
10
- LLMToolSchema,
11
- PreparedToolExecution,
12
- ToolAvailability,
13
- ToolContext,
14
- ToolDefinition,
15
- ToolExecutionResult,
16
- ToolPreparationResult,
17
- ToolRegistryConfig,
18
- ToolTierConfig,
19
- } from '../../types/tool/index.js'
20
- import { toErrorMessage } from '../../utils/error.js'
21
- import { cloneJsonValue as clonePreparedInput } from '../../utils/json-snapshot.js'
22
- import { ManagedRegistry } from '../ManagedRegistry.js'
23
- import { callableToolNames, formatToolNames } from './callable.js'
24
- import { renderToolSchema, toolWireSchema } from './schema.js'
25
- import { ToolResultHalted, screenToolResult } from './screen.js'
1
+ import { RegistryCollisionError } from '../collision.js'
26
2
 
27
- export type { ToolExecutionResult }
28
-
29
- /** Options for an independent registry membership and availability snapshot. */
30
- export interface ToolRegistryForkOptions {
31
- /**
32
- * Defer currently active tools outside this exact list. Omission preserves
33
- * every availability; an empty list defers every active tool. Listed tools
34
- * that are already deferred or suspended keep that state. Names must be
35
- * unique, valid registered names; a misspelling is refused.
36
- */
37
- readonly deferExcept?: readonly string[]
38
- }
39
-
40
- // Tokens too generic to identify a tool by name — ignored when matching a
41
- // batched `search_tools` query so they can't activate the whole catalog
42
- // (every bridged tool name shares the `clawtool` prefix, for instance).
43
- // Generic CRUD verbs are stopped too: a query like "list deals" must rank
44
- // by "deals", not token-match every `list_*` tool in the deferred catalog.
45
- const SEARCH_STOP_TOKENS = new Set([
46
- 'clawtool',
47
- 'tool',
48
- 'tools',
49
- 'mcp',
50
- 'the',
51
- 'and',
52
- 'for',
53
- 'use',
54
- 'list',
55
- 'read',
56
- 'create',
57
- 'update',
58
- 'get',
59
- 'find',
60
- 'delete',
61
- 'search',
62
- ])
63
-
64
- // Weighted-scoring weights mirroring ToolCatalog.searchTools (the richer,
65
- // otherwise-unused catalog scorer): exact name 12, name substring 8,
66
- // description 5 — extended here with argument-name indexing (3), following
67
- // argument names are searched too, not only the tool's own name.
68
- const SEARCH_WEIGHT_NAME_EXACT = 12
69
- const SEARCH_WEIGHT_NAME_PARTIAL = 8
70
- const SEARCH_WEIGHT_DESCRIPTION = 5
71
- const SEARCH_WEIGHT_ARGUMENT = 3
3
+ /**
4
+ * Tool naming and a handful of small, stateless rendering helpers this file
5
+ * used to share with `ToolRegistry`.
6
+ *
7
+ * `ToolRegistry` itself — registration, availability, the execution
8
+ * pipeline — is gone (plan.md v3 §2): a runtime-owned `ToolManager`
9
+ * (`toolsets/manager.ts`) resolves toolsets instead, and carries its own
10
+ * copy of the pipeline this file used to define. What's left here is what
11
+ * had no toolset/manager analogue to move to: a tool name has to be valid
12
+ * regardless of which mechanism resolves it, and `describeWithOutput`/
13
+ * `toolDiscoveryHint` are pure string formatting `ToolManager` still calls.
14
+ */
72
15
 
73
16
  /**
74
17
  * What a tool name may be, everywhere it comes from.
@@ -114,11 +57,13 @@ export function assertToolName(name: string): void {
114
57
  * shadowing-by-name the only way to say "I do not want this tool", which is
115
58
  * precisely what now throws.
116
59
  */
117
- export class ToolNameCollisionError extends Error {
60
+ export class ToolNameCollisionError extends RegistryCollisionError {
118
61
  readonly toolName: string
119
62
 
120
63
  constructor(toolName: string, context: string) {
121
64
  super(
65
+ 'ToolRegistry',
66
+ toolName,
122
67
  `Tool name "${toolName}" is already registered by this host, and ${context} will not replace it. Rename the host tool, or decline the one being mounted with runtimeToolOverrides: { "${toolName}": "disabled" }.`,
123
68
  )
124
69
  this.name = 'ToolNameCollisionError'
@@ -148,688 +93,6 @@ export function describeWithOutput(
148
93
  return `${description}\n\nReturns (JSON Schema): ${JSON.stringify(outputSchema)}`
149
94
  }
150
95
 
151
- export class ToolRegistry extends ManagedRegistry<ToolDefinition> {
152
- private availability: Map<string, ToolAvailability> = new Map()
153
- private tierConfig?: ToolTierConfig
154
- private resultGuardrails?: readonly ToolResultGuardrailSpec[]
155
- private readonly preparations = new WeakMap<
156
- PreparedToolExecution,
157
- { readonly tool: ToolDefinition; readonly input: unknown }
158
- >()
159
-
160
- constructor(config?: ToolRegistryConfig) {
161
- super({
162
- componentName: 'ToolRegistry',
163
- idField: 'name',
164
- logger: config?.logger,
165
- })
166
- this.tierConfig = config?.tierConfig
167
- this.resultGuardrails = config?.resultGuardrails
168
- }
169
-
170
- /**
171
- * Snapshot membership and availability for another turn without changing this
172
- * registry. Discovery, registration and suspension then affect only the fork.
173
- * Definitions, handlers and configuration remain shared; this is not a deep
174
- * clone or an authorization boundary. Prepared executions belong only to the
175
- * registry that prepared them and do not transfer to the fork.
176
- */
177
- fork(options: ToolRegistryForkOptions = {}): ToolRegistry {
178
- let retained: Set<string> | undefined
179
- if (options.deferExcept !== undefined) {
180
- if (!Array.isArray(options.deferExcept))
181
- throw new TypeError('ToolRegistry.fork deferExcept must be an array of tool names.')
182
- retained = new Set()
183
- for (const name of options.deferExcept) {
184
- if (typeof name !== 'string' || !TOOL_NAME_PATTERN.test(name))
185
- throw new TypeError('ToolRegistry.fork deferExcept must contain valid tool names.')
186
- if (retained.has(name))
187
- throw new TypeError(`ToolRegistry.fork deferExcept contains duplicate tool "${name}".`)
188
- this.getOrThrow(name)
189
- retained.add(name)
190
- }
191
- }
192
-
193
- const fork = new ToolRegistry({
194
- logger: this.log,
195
- tierConfig: this.tierConfig,
196
- resultGuardrails: this.resultGuardrails,
197
- })
198
- fork.items = new Map(this.items)
199
- fork.availability = new Map(this.availability)
200
- if (retained) {
201
- for (const name of fork.listNames()) {
202
- if (fork.getAvailability(name) === 'active' && !retained.has(name))
203
- fork.availability.set(name, 'deferred')
204
- }
205
- }
206
- return fork
207
- }
208
-
209
- override register(id: string, tool: ToolDefinition): void
210
- override register(tool: ToolDefinition, initialState?: ToolAvailability): void
211
- override register(tools: ToolDefinition[], initialState?: ToolAvailability): void
212
- override register(
213
- idOrToolOrTools: string | ToolDefinition | ToolDefinition[],
214
- maybeTool?: ToolDefinition | ToolAvailability,
215
- ): void {
216
- if (Array.isArray(idOrToolOrTools)) {
217
- const state = (typeof maybeTool === 'string' ? maybeTool : 'active') as ToolAvailability
218
- for (const tool of idOrToolOrTools) {
219
- this.registerOne(tool.name, tool, state)
220
- }
221
- return
222
- }
223
-
224
- if (typeof idOrToolOrTools === 'string') {
225
- if (!maybeTool || typeof maybeTool === 'string') {
226
- throw new Error('register(id, tool) requires a ToolDefinition argument')
227
- }
228
- this.registerOne(idOrToolOrTools, maybeTool, 'active')
229
- return
230
- }
231
-
232
- const tool = idOrToolOrTools
233
- const state: ToolAvailability = typeof maybeTool === 'string' ? maybeTool : 'active'
234
-
235
- this.registerOne(tool.name, tool, state)
236
- }
237
-
238
- private registerOne(id: string, tool: ToolDefinition, state: ToolAvailability): void {
239
- assertToolName(id)
240
- // A model-facing schema is what the constraint is applied TO, so
241
- // asking for enforcement without one is a request that cannot be
242
- // honoured. Refusing at registration puts the error where the author
243
- // can fix it rather than at the first request.
244
- if (tool.enforceModelInput && !tool.modelInputSchema) {
245
- throw new Error(
246
- `Tool "${id}" enables enforceModelInput but does not define modelInputSchema. Constrained input generation requires an explicit provider-safe model schema.`,
247
- )
248
- }
249
- // …and the schema has to be one a constrained decoder can actually be
250
- // given. The check above asks whether a model schema EXISTS; this asks
251
- // whether it can carry the guarantee the tool just requested.
252
- //
253
- // Both belong here for the reason the comment above already states.
254
- // Strict validation runs against a SUBSET of JSON Schema, and a keyword
255
- // outside it is not degraded — the request is rejected whole, so one
256
- // unexpressible field takes down every other tool in the call. The
257
- // first version of this check lived in a provider driver, which meant
258
- // it fired per request, in one driver, long after the author had moved
259
- // on. A tool that asks for a guarantee its own schema cannot carry is
260
- // wrong at the moment it is declared, whichever model it later meets.
261
- if (tool.enforceModelInput) {
262
- assertStrictSchema(id, tool.modelInputSchema)
263
- }
264
- if (tool.tier && this.tierConfig) {
265
- const validIds = this.tierConfig.tiers.map((t) => t.id)
266
- if (!validIds.includes(tool.tier)) {
267
- throw new Error(
268
- `Tool "${id}" has tier "${tool.tier}" which is not defined. Valid tiers: ${validIds.join(', ')}`,
269
- )
270
- }
271
- }
272
- super.register(id, tool)
273
- this.availability.set(id, state)
274
- }
275
-
276
- override unregister(id: string): boolean {
277
- this.availability.delete(id)
278
- return super.unregister(id)
279
- }
280
-
281
- override clear(): void {
282
- this.availability.clear()
283
- super.clear()
284
- }
285
-
286
- activate(names: string[]): void {
287
- for (const name of names) {
288
- this.getOrThrow(name)
289
- this.availability.set(name, 'active')
290
- this.log.debug('Tool activated', { 'namzu.tool.name': name })
291
- }
292
- }
293
-
294
- defer(names: string[]): void {
295
- for (const name of names) {
296
- this.getOrThrow(name)
297
- this.availability.set(name, 'deferred')
298
- this.log.debug('Tool deferred', { 'namzu.tool.name': name })
299
- }
300
- }
301
-
302
- suspendAll(): void {
303
- for (const name of this.listIds()) {
304
- if (this.getAvailability(name) === 'active') {
305
- this.availability.set(name, 'suspended')
306
- }
307
- }
308
- this.log.info('All active tools suspended')
309
- }
310
-
311
- hasSuspended(): boolean {
312
- for (const state of this.availability.values()) {
313
- if (state === 'suspended') return true
314
- }
315
- return false
316
- }
317
-
318
- getAvailability(name: string): ToolAvailability {
319
- return this.availability.get(name) ?? 'active'
320
- }
321
-
322
- /**
323
- * Ranked lexical search over DEFERRED tools, score-descending (ties broken
324
- * by name) so callers can cap activation at a top-k. Each meaningful query
325
- * term (≥3 chars, not a stop token) is scored against the tool name
326
- * (exact/substring), description, and argument names; only tools with a
327
- * positive score are returned. Description matching is safe here precisely
328
- * because the result is RANKED — the `search_tools` builtin activates only
329
- * the top slice, so a shared word can no longer drag in the whole catalog.
330
- *
331
- * PARKED (phase 5 of the tool-loading plan): an embedding-backed semantic
332
- * upgrade was evaluated and deliberately NOT built — at ≤~35 deferred
333
- * in-house tools with distinct names, weighted lexical scoring sits inside
334
- * the literature's safe zone, and a weak retriever underperforms no
335
- * retriever at all. Revisit only when (a) the deferred catalog grows past
336
- * ~75-100 tools (realistic driver: connector-MCP growth), or (b) telemetry
337
- * shows a search_tools miss-rate above ~10%. Sticky activation is also
338
- * deliberate: activating inserts the schema into the tools array at its
339
- * registry position (a one-time prompt-cache prefix bust); re-defer/TTL
340
- * would churn that prefix repeatedly and is rejected.
341
- */
342
- searchDeferred(query: string): ToolDefinition[] {
343
- return this.searchByAvailability(query, ['deferred'])
344
- }
345
-
346
- /** Active matches use the same ranking, also recognizing exact short or generic names. */
347
- searchActive(query: string): ToolDefinition[] {
348
- return this.searchByAvailability(query, ['active'])
349
- }
350
-
351
- private searchByAvailability(query: string, states: ToolAvailability[]): ToolDefinition[] {
352
- const q = query.toLowerCase().trim()
353
- if (q.length === 0) return []
354
- const terms = q.split(/\s+/).filter((tok) => tok.length >= 3 && !SEARCH_STOP_TOKENS.has(tok))
355
-
356
- const scored: Array<{ tool: ToolDefinition; score: number }> = []
357
- for (const tool of this.getByAvailability(states)) {
358
- const name = tool.name.toLowerCase()
359
- const description = tool.description.toLowerCase()
360
- const argumentNames = listArgumentNames(tool)
361
- let score = terms.length === 0 && name === q ? SEARCH_WEIGHT_NAME_EXACT : 0
362
- for (const term of terms) {
363
- if (name === term) {
364
- score += SEARCH_WEIGHT_NAME_EXACT
365
- } else if (name.includes(term)) {
366
- score += SEARCH_WEIGHT_NAME_PARTIAL
367
- }
368
- if (description.includes(term)) {
369
- score += SEARCH_WEIGHT_DESCRIPTION
370
- }
371
- if (argumentNames.some((arg) => arg.includes(term))) {
372
- score += SEARCH_WEIGHT_ARGUMENT
373
- }
374
- }
375
- if (score > 0) {
376
- scored.push({ tool, score })
377
- }
378
- }
379
-
380
- scored.sort((a, b) => b.score - a.score || a.tool.name.localeCompare(b.tool.name))
381
- return scored.map((entry) => entry.tool)
382
- }
383
-
384
- assignTiers(mapping: Record<string, string>): void {
385
- for (const [toolName, tierId] of Object.entries(mapping)) {
386
- const tool = this.getOrThrow(toolName)
387
- if (this.tierConfig) {
388
- const validIds = this.tierConfig.tiers.map((t) => t.id)
389
- if (!validIds.includes(tierId)) {
390
- throw new Error(
391
- `Tier "${tierId}" for tool "${toolName}" is not defined. Valid tiers: ${validIds.join(', ')}`,
392
- )
393
- }
394
- }
395
- tool.tier = tierId
396
- }
397
- }
398
-
399
- toTierGuidance(): string | null {
400
- if (!this.tierConfig?.guidanceTemplate) return null
401
- return this.tierConfig.guidanceTemplate(this.tierConfig.tiers)
402
- }
403
-
404
- listNames(): string[] {
405
- return this.listIds()
406
- }
407
-
408
- toPromptSection(toolNames?: string[]): string {
409
- const active = this.getByAvailability(['active'], toolNames)
410
- const deferred = this.getByAvailability(['deferred'], toolNames)
411
-
412
- const parts: string[] = []
413
- const contractNote = `<tool_runtime_contract>
414
- Executable tool names, descriptions, and JSON input schemas are attached through the runtime tools parameter. Treat that runtime schema as authoritative; this prompt section is a discoverability summary only.
415
- </tool_runtime_contract>`
416
-
417
- if (active.length > 0) {
418
- // Name-only: every active tool's full description + JSON schema
419
- // already rides the runtime tools parameter on each request —
420
- // repeating descriptions here double-bills the same tokens.
421
- const entries = active.map((t) => `- ${t.name}`).join('\n')
422
- parts.push(`<available_tools>\n${entries}\n</available_tools>`)
423
- }
424
-
425
- if (deferred.length > 0) {
426
- // Name + one-line hint: deferred schemas stay off the wire, so the
427
- // hint is the model's only signal of what a deferred tool does. A
428
- // bare name list caused a real discovery failure in production
429
- // (the agent never found read_document behind search_tools).
430
- const entries = deferred
431
- .map((t) => {
432
- const hint = toolDiscoveryHint(t.description)
433
- return hint.length > 0 ? `- ${t.name}: ${hint}` : `- ${t.name}`
434
- })
435
- .join('\n')
436
- const deferredIntro =
437
- this.has('search_tools') &&
438
- this.getAvailability('search_tools') === 'active' &&
439
- (!toolNames || toolNames.includes('search_tools'))
440
- ? 'Use search_tools to load these before use:'
441
- : 'Deferred tools are discoverable but not executable until the runtime activates them:'
442
- parts.push(`<deferred_tools>\n${deferredIntro}\n${entries}\n</deferred_tools>`)
443
- }
444
-
445
- if (parts.length === 0) return ''
446
- return [contractNote, ...parts].join('\n\n')
447
- }
448
-
449
- toLLMTools(toolNames?: string[]): LLMToolSchema[] {
450
- const toolsToConvert = this.getByAvailability(['active', 'suspended'], toolNames)
451
-
452
- return toolsToConvert.map((tool) => {
453
- let description = tool.description
454
- if (this.tierConfig?.labelInDescription && tool.tier) {
455
- const tierDef = this.tierConfig.tiers.find((t) => t.id === tool.tier)
456
- if (tierDef) {
457
- description = `[${tierDef.label}] ${description}`
458
- }
459
- }
460
- return {
461
- type: 'function' as const,
462
- function: {
463
- name: tool.name,
464
- description: describeWithOutput(description, tool.outputSchema),
465
- parameters: toolWireSchema(tool),
466
- },
467
- }
468
- })
469
- }
470
-
471
- getCallableTools(toolNames?: string[]): ToolDefinition[] {
472
- return this.getByAvailability(['active'], toolNames)
473
- }
474
-
475
- prepareExecution(toolName: string, rawInput: unknown): ToolPreparationResult {
476
- const tool = this.getOrThrow(toolName)
477
- const parseResult = tool.inputSchema.safeParse(rawInput)
478
- if (!parseResult.success) {
479
- return {
480
- success: false,
481
- result: this.validationFailure(tool, rawInput, parseResult.error),
482
- }
483
- }
484
-
485
- let retainedInput: unknown
486
- let reviewInput: unknown
487
- try {
488
- retainedInput = clonePreparedInput(parseResult.data, false)
489
- reviewInput = clonePreparedInput(retainedInput, true)
490
- } catch (err) {
491
- const message = `Tool "${toolName}" produced an input that cannot be safely prepared for review and execution: ${toErrorMessage(err)}`
492
- this.log.error('Prepared tool input could not be detached for review and execution', {
493
- 'namzu.tool.name': toolName,
494
- 'exception.message': toErrorMessage(err),
495
- })
496
- return {
497
- success: false,
498
- result: { success: false, output: '', error: message },
499
- }
500
- }
501
-
502
- const prepared = Object.freeze({ toolName, input: reviewInput })
503
- this.preparations.set(prepared, { tool, input: retainedInput })
504
- return { success: true, prepared }
505
- }
506
-
507
- async executePrepared(
508
- prepared: PreparedToolExecution,
509
- context: ToolContext,
510
- ): Promise<ToolExecutionResult> {
511
- const retained = this.preparations.get(prepared)
512
- if (!retained) {
513
- return {
514
- success: false,
515
- output: '',
516
- error: `Tool "${prepared.toolName}" preparation is not owned by this registry or is no longer valid.`,
517
- }
518
- }
519
- if (this.get(prepared.toolName) !== retained.tool) {
520
- return {
521
- success: false,
522
- output: '',
523
- error: `Tool "${prepared.toolName}" changed after its input was reviewed; prepare the call again.`,
524
- }
525
- }
526
- return this.executeRetained(prepared.toolName, retained.tool, retained.input, context)
527
- }
528
-
529
- async execute(
530
- toolName: string,
531
- rawInput: unknown,
532
- context: ToolContext,
533
- ): Promise<ToolExecutionResult> {
534
- let preparation: ToolPreparationResult
535
- try {
536
- preparation = this.prepareExecution(toolName, rawInput)
537
- } catch (err) {
538
- return this.rejectPreparationWithClosedSpan(toolName, context, err)
539
- }
540
- if (!preparation.success) return preparation.result
541
- return this.executePrepared(preparation.prepared, context)
542
- }
543
-
544
- private rejectPreparationWithClosedSpan(
545
- toolName: string,
546
- context: ToolContext,
547
- err: unknown,
548
- ): Promise<never> {
549
- const tracer = getTracer()
550
- const parentCtx = context.parentSpan
551
- ? trace.setSpan(otelContext.active(), context.parentSpan)
552
- : otelContext.active()
553
- return tracer.startActiveSpan(toolSpanName(toolName), {}, parentCtx, async (span) => {
554
- try {
555
- span.setAttributes({
556
- [GENAI.TOOL_NAME]: toolName,
557
- [GENAI.TOOL_TYPE]: 'function',
558
- ...(context.toolUseId !== undefined ? { [GENAI.TOOL_CALL_ID]: context.toolUseId } : {}),
559
- ...toolSpanIdentity(context),
560
- [NAMZU.TOOL_SUCCESS]: false,
561
- [NAMZU.TOOL_ERROR]: toErrorMessage(err),
562
- })
563
- span.setStatus({ code: SpanStatusCode.ERROR, message: toErrorMessage(err) })
564
- throw err
565
- } finally {
566
- span.end()
567
- }
568
- })
569
- }
570
-
571
- private async executeRetained(
572
- toolName: string,
573
- tool: ToolDefinition,
574
- finalInput: unknown,
575
- context: ToolContext,
576
- ): Promise<ToolExecutionResult> {
577
- const tracer = getTracer()
578
-
579
- // Explicit parent, not the ambient context. Every span-owning body
580
- // upstream is an async generator, and a generator resumes on its
581
- // consumer's async context — so by the time a tool executes, whatever
582
- // `startActiveSpan` established upstream is long gone and this span
583
- // would emit as a root. `context.parentSpan` is threaded through
584
- // `ToolContext`, which already reaches here.
585
- const parentCtx = context.parentSpan
586
- ? trace.setSpan(otelContext.active(), context.parentSpan)
587
- : otelContext.active()
588
-
589
- return tracer.startActiveSpan(toolSpanName(toolName), {}, parentCtx, async (span) => {
590
- try {
591
- // The call id joins this span to the assistant block that asked
592
- // for it. Without it a trace shows that `Bash` ran four times
593
- // this turn and cannot say which span answers which
594
- // `tool_use` — and the id was already in hand here, threaded
595
- // through `ToolContext` for the tools that reply
596
- // asynchronously.
597
- //
598
- // Conditional because `toolUseId` is optional: a host calling
599
- // a tool directly, outside a turn, has no call to correlate to,
600
- // and an attribute set to `undefined` is worse than an absent
601
- // one — it reaches the exporter as a key with no value.
602
- span.setAttributes({
603
- [GENAI.TOOL_NAME]: toolName,
604
- [GENAI.TOOL_TYPE]: 'function',
605
- ...(context.toolUseId !== undefined ? { [GENAI.TOOL_CALL_ID]: context.toolUseId } : {}),
606
- ...toolSpanIdentity(context),
607
- })
608
-
609
- const availability = this.getAvailability(toolName)
610
- if (availability !== 'active') {
611
- const msg = `Tool "${toolName}" is ${availability} and cannot be executed`
612
- this.log.warn(msg)
613
- span.setAttributes({
614
- [NAMZU.TOOL_SUCCESS]: false,
615
- [NAMZU.TOOL_ERROR]: msg,
616
- })
617
- span.setStatus({ code: SpanStatusCode.ERROR, message: msg })
618
- return {
619
- success: false,
620
- output: '',
621
- error: msg,
622
- }
623
- }
624
-
625
- // A turn that was narrowed may only call what it was narrowed to.
626
- //
627
- // This used to be enforced nowhere. `allowedTools` decided which
628
- // schemas went into the request and was then carried into this
629
- // context and read by nothing, so the restriction was a statement
630
- // about the menu rather than about the kitchen: a model that named
631
- // a withheld tool — from earlier context, from a gateway holding
632
- // its own tool list, from a replayed cache prefix — had it run.
633
- // The type says "restrict which tools the model may call"; this is
634
- // the line that makes that true.
635
- //
636
- // Absent means unrestricted. An EMPTY list does not: it is a turn
637
- // that may call nothing, and treating it as "no restriction" is
638
- // the fail-open reading this codebase has already been bitten by
639
- // once, in the delegate roster.
640
- //
641
- // What it says is available is what would run, not the list
642
- // itself: the list was taken when the request was built, and a
643
- // name on it may since have been unregistered, or be deferred or
644
- // suspended. Echoing it sent a model to a name that was then
645
- // answered "unknown tool". See `callableToolNames`.
646
- const allowed = context.allowedTools
647
- if (allowed !== undefined && !allowed.includes(toolName)) {
648
- const msg = `Tool "${toolName}" is not available on this step. Available: ${formatToolNames(callableToolNames(this, allowed))}`
649
- this.log.warn('Blocked a tool outside the step allow-list', {
650
- [GENAI.TOOL_NAME]: toolName,
651
- 'namzu.registry.allowed': allowed.length,
652
- })
653
- span.setAttributes({
654
- [NAMZU.TOOL_SUCCESS]: false,
655
- [NAMZU.TOOL_ERROR]: msg,
656
- })
657
- span.setStatus({ code: SpanStatusCode.ERROR, message: msg })
658
- return {
659
- success: false,
660
- output: '',
661
- error: msg,
662
- permissionDenied: true,
663
- }
664
- }
665
-
666
- const mode = context.permissionContext?.mode ?? 'auto'
667
- if (mode === 'plan') {
668
- const isReadOnly = isTrustedReadOnly(tool, finalInput)
669
- if (!isReadOnly) {
670
- // The same words the review-time policy uses, so the model gets one
671
- // instruction whichever door refused it.
672
- const msg = `plan mode: non-read-only tool "${toolName}" blocked. ${PLAN_MODE_REFUSAL}`
673
- span.setAttributes({
674
- [NAMZU.TOOL_SUCCESS]: false,
675
- [NAMZU.TOOL_ERROR]: msg,
676
- })
677
- span.setStatus({ code: SpanStatusCode.ERROR, message: msg })
678
- return {
679
- success: false,
680
- output: '',
681
- error: msg,
682
- permissionDenied: true,
683
- permissionMessage: msg,
684
- }
685
- }
686
- }
687
-
688
- try {
689
- this.log.debug('Executing tool', { 'namzu.tool.name': toolName })
690
- const startedAt = Date.now()
691
- const runResultGuardrails = context.toolResultGuardrails
692
- const produced = await tool.execute(finalInput, context)
693
- // Screened here, which is the only place a result can be
694
- // examined before anything acts on it: the executor applies
695
- // the output budget to what this returns, and compaction
696
- // summarises later still. `provenance` is carried in so a
697
- // screen can tell a connected server's words from a
698
- // first-party tool's — a connector's result is framed with
699
- // the server's name, and a screen reading only the value
700
- // cannot use that.
701
- const result = await screenToolResult(
702
- // Explicit configuration wins, at whichever boundary it
703
- // was made. A registry built WITH `resultGuardrails`
704
- // has stated its policy — including `[]`, which means
705
- // none — and a turn must not overrule it. A registry
706
- // built without one declared none, so the turn's apply;
707
- // that is the ordinary case, since a host assembles a
708
- // registry and hands it to a turn it does not own.
709
- this.resultGuardrails ?? runResultGuardrails,
710
- produced,
711
- {
712
- toolName,
713
- input: finalInput,
714
- ...(tool.provenance ? { provenance: tool.provenance } : {}),
715
- },
716
- this.log,
717
- )
718
- const durationMs = Date.now() - startedAt
719
- this.log.debug('Tool completed', {
720
- 'namzu.tool.name': toolName,
721
- 'namzu.registry.success': result.success,
722
- })
723
-
724
- span.setAttribute(NAMZU.TOOL_SUCCESS, result.success)
725
- recordToolCall(
726
- toolName,
727
- result.success,
728
- result.success ? undefined : result.error,
729
- durationMs,
730
- )
731
- if (!result.success && result.error) {
732
- span.setAttribute(NAMZU.TOOL_ERROR, result.error)
733
- span.setStatus({
734
- code: SpanStatusCode.ERROR,
735
- message: result.error,
736
- })
737
- } else {
738
- span.setStatus({ code: SpanStatusCode.OK })
739
- }
740
-
741
- return result
742
- } catch (err) {
743
- // A terminal refusal must not be converted into a failed
744
- // tool call. Everything below turns an exception into a
745
- // result the model reads and works around, which is what
746
- // `refuse` is for — doing it to a `halt` would silently
747
- // demote the one verdict that says the turn must not
748
- // continue.
749
- if (err instanceof ToolResultHalted) {
750
- span.setAttributes({
751
- [NAMZU.TOOL_SUCCESS]: false,
752
- [NAMZU.TOOL_ERROR]: err.message,
753
- })
754
- span.setStatus({
755
- code: SpanStatusCode.ERROR,
756
- message: err.message,
757
- })
758
- throw err
759
- }
760
- const errorMessage = toErrorMessage(err)
761
- this.log.error('Tool execution error', {
762
- 'namzu.tool.name': toolName,
763
- 'exception.message': errorMessage,
764
- })
765
-
766
- span.setAttributes({
767
- [NAMZU.TOOL_SUCCESS]: false,
768
- [NAMZU.TOOL_ERROR]: errorMessage,
769
- })
770
- span.setStatus({
771
- code: SpanStatusCode.ERROR,
772
- message: errorMessage,
773
- })
774
- span.recordException(err instanceof Error ? err : new Error(errorMessage))
775
-
776
- return {
777
- success: false,
778
- output: '',
779
- error: `Tool "${toolName}" execution failed: ${errorMessage}`,
780
- }
781
- }
782
- } finally {
783
- // The only place this span ends. It used to be ended at three
784
- // early returns and in a finally that opened below them, so
785
- // anything throwing before that try — `getOrThrow` on a name the
786
- // registry does not hold, for one — left the span open and the
787
- // tool's trace unclosed.
788
- span.end()
789
- }
790
- })
791
- }
792
-
793
- private validationFailure(
794
- tool: ToolDefinition,
795
- rawInput: unknown,
796
- error: {
797
- readonly issues: readonly {
798
- readonly path: readonly PropertyKey[]
799
- readonly message: string
800
- }[]
801
- },
802
- ): ToolExecutionResult {
803
- const errorMessage = error.issues
804
- .map((issue) => `${issue.path.join('.')}: ${issue.message}`)
805
- .join('; ')
806
- const isEmptyInput =
807
- rawInput === null ||
808
- rawInput === undefined ||
809
- (typeof rawInput === 'object' &&
810
- !Array.isArray(rawInput) &&
811
- Object.keys(rawInput as Record<string, unknown>).length === 0)
812
- const requiredHint = describeRequiredInput(tool.inputSchema)
813
- const recoveryHint = tool.validationErrorHint?.trim()
814
- ? ` ${tool.validationErrorHint.trim()}`
815
- : ''
816
- const enrichedMessage = isEmptyInput
817
- ? `Tool "${tool.name}" was called with no arguments. ${requiredHint}${recoveryHint} Retry the call with the required parameters populated.`
818
- : `Validation failed for "${tool.name}": ${errorMessage}. ${requiredHint}${recoveryHint}`
819
- this.log.error('Tool input validation failed', {
820
- 'namzu.tool.name': tool.name,
821
- 'namzu.registry.errors': errorMessage,
822
- 'namzu.registry.empty': isEmptyInput,
823
- })
824
- return { success: false, output: '', error: enrichedMessage }
825
- }
826
-
827
- private getByAvailability(states: ToolAvailability[], filter?: string[]): ToolDefinition[] {
828
- const candidates = filter ? filter.map((n) => this.getOrThrow(n)) : this.getAll()
829
- return candidates.filter((t) => states.includes(this.getAvailability(t.name)))
830
- }
831
- }
832
-
833
96
  /**
834
97
  * One-line discoverability hint for a deferred tool: the first sentence of
835
98
  * its description, capped at ~100 chars. Used for the `<deferred_tools>`
@@ -844,96 +107,3 @@ export function toolDiscoveryHint(description: string, maxLength = 100): string
844
107
  if (sentence.length <= maxLength) return sentence
845
108
  return `${sentence.slice(0, maxLength - 1).trimEnd()}…`
846
109
  }
847
-
848
- /**
849
- * Lower-cased argument (property) names of a tool's input schema, used by
850
- * `searchDeferred` ranking. Walks the JSON-Schema rendering (already a
851
- * registration dependency) instead of Zod internals; opaque schemas simply
852
- * contribute no argument matches.
853
- */
854
- function listArgumentNames(tool: ToolDefinition): string[] {
855
- try {
856
- // The model-facing schema when there is one: that is what the model
857
- // was shown, so it is what a search over "which tool takes this
858
- // argument" has to match against.
859
- const json = tool.modelInputSchema ?? renderToolSchema(tool.inputSchema)
860
- return [...collectSchemaPropertyNames(json)].map((key) => key.toLowerCase())
861
- } catch {
862
- return []
863
- }
864
- }
865
-
866
- /**
867
- * Every property name a schema can accept, including the ones that only
868
- * appear inside a branch.
869
- *
870
- * A conditional schema puts its real arguments under `anyOf`/`oneOf`, so
871
- * reading the top-level `properties` alone finds nothing and the tool is
872
- * unfindable by the very argument it takes. `seen` guards a schema that
873
- * refers back to itself.
874
- */
875
- function collectSchemaPropertyNames(
876
- schema: unknown,
877
- names: Set<string> = new Set(),
878
- seen: Set<object> = new Set(),
879
- ): Set<string> {
880
- if (!schema || typeof schema !== 'object' || Array.isArray(schema)) return names
881
- if (seen.has(schema)) return names
882
- seen.add(schema)
883
-
884
- const record = schema as Record<string, unknown>
885
- const properties = record.properties
886
- if (properties && typeof properties === 'object' && !Array.isArray(properties)) {
887
- for (const name of Object.keys(properties)) names.add(name)
888
- }
889
- for (const keyword of ['anyOf', 'oneOf', 'allOf'] as const) {
890
- const branches = record[keyword]
891
- if (!Array.isArray(branches)) continue
892
- for (const branch of branches) collectSchemaPropertyNames(branch, names, seen)
893
- }
894
- return names
895
- }
896
-
897
- /**
898
- * Build a one-sentence "Required: <field>: <type>, <field>: <type>"
899
- * hint from a Zod schema, used to enrich tool-input validation
900
- * errors so the model can self-correct without round-tripping the
901
- * full JSON schema again. Walks the schema's JSON-Schema rendering
902
- * (already a dependency for tool registration) so we don't have to
903
- * branch over Zod's internal type tree.
904
- *
905
- * Returns a fallback string for opaque/non-object schemas — the
906
- * caller still ships the raw Zod issues separately, so the hint
907
- * here is bonus context, not the only signal.
908
- */
909
- function describeRequiredInput(schema: { _def?: unknown }): string {
910
- try {
911
- const json = renderToolSchema(schema as never) as {
912
- properties?: Record<string, { type?: string; description?: string }>
913
- required?: string[]
914
- }
915
- const required = json.required ?? []
916
- if (required.length === 0) return 'No required parameters known.'
917
- const props = json.properties ?? {}
918
- const lines = required.map((name) => {
919
- const def = props[name] ?? {}
920
- const type = def.type ?? 'value'
921
- const desc = def.description ? ` — ${def.description}` : ''
922
- return `${name}: ${type}${desc}`
923
- })
924
- return `Required: ${lines.join(', ')}.`
925
- } catch {
926
- return 'Could not introspect required parameters.'
927
- }
928
- }
929
-
930
- /**
931
- * The session and turn a tool span belongs to. A host calling a tool
932
- * directly may pass a context without them, so each is set only when present.
933
- */
934
- function toolSpanIdentity(context: ToolContext): Record<string, string> {
935
- return {
936
- ...(context.sessionId ? { [GENAI.CONVERSATION_ID]: context.sessionId } : {}),
937
- ...(context.turnId ? { [NAMZU.TURN_ID]: context.turnId } : {}),
938
- }
939
- }