@theoremjs/agents 0.3.0 → 0.3.1

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 (568) hide show
  1. package/README.md +276 -995
  2. package/esm/mod.d.ts +33 -19
  3. package/esm/mod.js +18 -11
  4. package/esm/src/cli/commands/bench.js +36 -14
  5. package/esm/src/cli/commands/detect-compile.d.ts +17 -0
  6. package/esm/src/cli/commands/detect-compile.js +22 -0
  7. package/esm/src/cli/commands/eval.d.ts +3 -3
  8. package/esm/src/cli/commands/fuzz-canary.js +55 -16
  9. package/esm/src/cli/commands/profile.js +4 -4
  10. package/esm/src/cli/commands/run.d.ts +2 -2
  11. package/esm/src/cli/commands/run.js +1 -1
  12. package/esm/src/cli/commands/test.d.ts +4 -3
  13. package/esm/src/cli/commands/test.js +2 -2
  14. package/esm/src/cli/index.js +9 -9
  15. package/esm/src/cli/matrix/fixtures.js +25 -30
  16. package/esm/src/evals/attachments.d.ts +1 -0
  17. package/esm/src/evals/attachments.js +4 -2
  18. package/esm/src/evals/breakdown.d.ts +2 -0
  19. package/esm/src/evals/breakdown.js +1 -0
  20. package/esm/src/evals/graders/answer.d.ts +3 -0
  21. package/esm/src/evals/graders/answer.js +1 -0
  22. package/esm/src/evals/graders/code.d.ts +7 -31
  23. package/esm/src/evals/graders/code.js +4 -25
  24. package/esm/src/evals/graders/judge.d.ts +4 -0
  25. package/esm/src/evals/graders/judge.js +7 -5
  26. package/esm/src/evals/graders/latency.d.ts +1 -0
  27. package/esm/src/evals/graders/latency.js +3 -2
  28. package/esm/src/evals/graders/live.d.ts +3 -0
  29. package/esm/src/evals/graders/live.js +2 -0
  30. package/esm/src/evals/graders/media.js +1 -2
  31. package/esm/src/evals/graders/shared.js +1 -1
  32. package/esm/src/evals/graders/transcript.d.ts +2 -0
  33. package/esm/src/evals/graders/transcript.js +5 -3
  34. package/esm/src/evals/mod.d.ts +1 -9
  35. package/esm/src/evals/mod.js +1 -9
  36. package/esm/src/evals/record.d.ts +6 -0
  37. package/esm/src/evals/record.js +4 -2
  38. package/esm/src/evals/rubrics/mod.d.ts +1 -1
  39. package/esm/src/evals/rubrics/mod.js +1 -1
  40. package/esm/src/evals/rubrics/mustache.js +1 -1
  41. package/esm/src/evals/rubrics/types.js +1 -1
  42. package/esm/src/evals/run.d.ts +9 -52
  43. package/esm/src/evals/run.js +12 -46
  44. package/esm/src/evals/suite.d.ts +12 -3
  45. package/esm/src/evals/suite.js +9 -4
  46. package/esm/src/evals/summary.d.ts +3 -0
  47. package/esm/src/evals/summary.js +1 -0
  48. package/esm/src/evals/trial.d.ts +3 -16
  49. package/esm/src/evals/trial.js +7 -30
  50. package/esm/src/evals/types.d.ts +30 -121
  51. package/esm/src/evals/types.js +3 -16
  52. package/esm/src/evals/verdict.d.ts +5 -0
  53. package/esm/src/evals/verdict.js +4 -1
  54. package/esm/src/guardrails/boundaries.d.ts +41 -0
  55. package/esm/src/guardrails/boundaries.js +103 -0
  56. package/esm/src/guardrails/canary-gate.d.ts +1 -0
  57. package/esm/src/guardrails/canary.d.ts +49 -15
  58. package/esm/src/guardrails/canary.js +103 -30
  59. package/esm/src/guardrails/compile-egress.d.ts +6 -5
  60. package/esm/src/guardrails/compile-egress.js +6 -5
  61. package/esm/src/guardrails/corpus/canary-egress-attacks.d.ts +3 -1
  62. package/esm/src/guardrails/corpus/canary-egress-attacks.js +4 -2
  63. package/esm/src/guardrails/corpus/fuzz-inbound.js +14 -17
  64. package/esm/src/guardrails/corpus/inbound-payloads.d.ts +2 -0
  65. package/esm/src/guardrails/corpus/inbound-payloads.js +4 -2
  66. package/esm/src/guardrails/corpus/live-attacks.d.ts +2 -0
  67. package/esm/src/guardrails/corpus/live-attacks.js +6 -1
  68. package/esm/src/guardrails/corpus/mod.d.ts +1 -1
  69. package/esm/src/guardrails/corpus/secrets.d.ts +3 -3
  70. package/esm/src/guardrails/corpus/secrets.js +2 -2
  71. package/esm/src/guardrails/corpus/strings.d.ts +1 -1
  72. package/esm/src/guardrails/corpus/strings.js +1 -1
  73. package/esm/src/guardrails/corpus/types.d.ts +5 -1
  74. package/esm/src/guardrails/credential-rules.d.ts +36 -0
  75. package/esm/src/guardrails/credential-rules.js +3001 -0
  76. package/esm/src/guardrails/credential-scan.d.ts +45 -0
  77. package/esm/src/guardrails/credential-scan.js +172 -0
  78. package/esm/src/guardrails/destinations.d.ts +45 -0
  79. package/esm/src/guardrails/destinations.js +234 -0
  80. package/esm/src/guardrails/detect-at.d.ts +107 -0
  81. package/esm/src/guardrails/detect-at.js +434 -0
  82. package/esm/src/guardrails/detect-reply.d.ts +61 -0
  83. package/esm/src/guardrails/detect-reply.js +95 -0
  84. package/esm/src/guardrails/detect-stream.d.ts +33 -0
  85. package/esm/src/guardrails/detect-stream.js +77 -0
  86. package/esm/src/guardrails/detectors.d.ts +216 -0
  87. package/esm/src/guardrails/detectors.js +503 -0
  88. package/esm/src/guardrails/egress-automata.d.ts +4 -6
  89. package/esm/src/guardrails/egress-automata.js +24095 -4572
  90. package/esm/src/guardrails/egress-compiler.d.ts +38 -16
  91. package/esm/src/guardrails/egress-compiler.js +254 -60
  92. package/esm/src/guardrails/egress-patterns.d.ts +4 -2
  93. package/esm/src/guardrails/egress-patterns.js +6 -2
  94. package/esm/src/guardrails/egress-stream.d.ts +54 -36
  95. package/esm/src/guardrails/egress-stream.js +253 -124
  96. package/esm/src/guardrails/egress-urls.d.ts +6 -3
  97. package/esm/src/guardrails/egress-urls.js +14 -22
  98. package/esm/src/guardrails/egress.d.ts +26 -86
  99. package/esm/src/guardrails/egress.js +59 -309
  100. package/esm/src/guardrails/error.d.ts +13 -8
  101. package/esm/src/guardrails/error.js +23 -18
  102. package/esm/src/guardrails/event-schemas.d.ts +46 -3
  103. package/esm/src/guardrails/event-schemas.js +12 -5
  104. package/esm/src/guardrails/events.d.ts +5 -1
  105. package/esm/src/guardrails/events.js +4 -1
  106. package/esm/src/guardrails/hints.d.ts +14 -0
  107. package/esm/src/guardrails/hints.js +57 -0
  108. package/esm/src/guardrails/hits.d.ts +7 -1
  109. package/esm/src/guardrails/hits.js +12 -1
  110. package/esm/src/guardrails/host-patterns.d.ts +85 -0
  111. package/esm/src/guardrails/host-patterns.js +173 -0
  112. package/esm/src/guardrails/injection-patterns.d.ts +6 -1
  113. package/esm/src/guardrails/injection-patterns.js +33 -1
  114. package/esm/src/guardrails/injection-reversed.d.ts +9 -0
  115. package/esm/src/guardrails/injection-reversed.js +49 -0
  116. package/esm/src/guardrails/injection.d.ts +17 -1
  117. package/esm/src/guardrails/injection.js +259 -36
  118. package/esm/src/guardrails/labels.d.ts +40 -0
  119. package/esm/src/guardrails/labels.js +874 -0
  120. package/esm/src/guardrails/live-outbound-gate.d.ts +9 -8
  121. package/esm/src/guardrails/live-outbound-gate.js +100 -107
  122. package/esm/src/guardrails/mod.d.ts +29 -21
  123. package/esm/src/guardrails/mod.js +18 -13
  124. package/esm/src/guardrails/network.d.ts +4 -0
  125. package/esm/src/guardrails/network.js +21 -19
  126. package/esm/src/guardrails/normalize.d.ts +15 -1
  127. package/esm/src/guardrails/normalize.js +34 -1
  128. package/esm/src/guardrails/policy.d.ts +2 -17
  129. package/esm/src/guardrails/policy.js +12 -41
  130. package/esm/src/guardrails/progressive-yield.d.ts +65 -24
  131. package/esm/src/guardrails/progressive-yield.js +191 -147
  132. package/esm/src/guardrails/prompt-echo.d.ts +4 -2
  133. package/esm/src/guardrails/prompt-echo.js +87 -6
  134. package/esm/src/guardrails/quota.d.ts +1 -0
  135. package/esm/src/guardrails/quota.js +1 -1
  136. package/esm/src/guardrails/rules.d.ts +20 -29
  137. package/esm/src/guardrails/rules.js +23 -30
  138. package/esm/src/guardrails/sanitize.d.ts +32 -15
  139. package/esm/src/guardrails/sanitize.js +100 -124
  140. package/esm/src/guardrails/sensitive-groups.d.ts +21 -0
  141. package/esm/src/guardrails/sensitive-groups.js +12 -0
  142. package/esm/src/guardrails/sensitive.d.ts +16 -23
  143. package/esm/src/guardrails/sensitive.js +168 -47
  144. package/esm/src/guardrails/serialize.d.ts +1 -0
  145. package/esm/src/guardrails/testing.d.ts +4 -2
  146. package/esm/src/guardrails/testing.js +4 -2
  147. package/esm/src/guardrails/theorem-error.d.ts +4 -1
  148. package/esm/src/guardrails/theorem-error.js +3 -2
  149. package/esm/src/guardrails/thought-guard.d.ts +34 -13
  150. package/esm/src/guardrails/thought-guard.js +264 -64
  151. package/esm/src/guardrails/tool-directives.d.ts +29 -10
  152. package/esm/src/guardrails/tool-directives.js +133 -47
  153. package/esm/src/guardrails/tool-leak.d.ts +26 -0
  154. package/esm/src/guardrails/tool-leak.js +45 -0
  155. package/esm/src/guardrails/tool-result.d.ts +45 -14
  156. package/esm/src/guardrails/tool-result.js +94 -70
  157. package/esm/src/guardrails/types.d.ts +79 -71
  158. package/esm/src/guardrails/types.js +11 -7
  159. package/esm/src/host/client-turn.d.ts +29 -2
  160. package/esm/src/host/client-turn.js +46 -4
  161. package/esm/src/host/mint-trace.d.ts +1 -0
  162. package/esm/src/host/mint-trace.js +3 -2
  163. package/esm/src/host/mod.d.ts +2 -2
  164. package/esm/src/host/mod.js +1 -1
  165. package/esm/src/host/readStreamingJsonStringField.js +2 -43
  166. package/esm/src/host/reply.d.ts +6 -0
  167. package/esm/src/host/reply.js +7 -1
  168. package/esm/src/interface/blocks.d.ts +3 -0
  169. package/esm/src/interface/blocks.js +84 -14
  170. package/esm/src/interface/composer-actions.d.ts +4 -0
  171. package/esm/src/interface/composer-actions.js +5 -3
  172. package/esm/src/interface/draft.d.ts +6 -0
  173. package/esm/src/interface/draft.js +22 -11
  174. package/esm/src/interface/from-profile.d.ts +13 -1
  175. package/esm/src/interface/from-profile.js +66 -31
  176. package/esm/src/interface/history.d.ts +9 -3
  177. package/esm/src/interface/history.js +33 -24
  178. package/esm/src/interface/inputs.d.ts +1 -0
  179. package/esm/src/interface/inputs.js +3 -0
  180. package/esm/src/interface/mod.d.ts +4 -2
  181. package/esm/src/interface/mod.js +3 -2
  182. package/esm/src/interface/models.d.ts +7 -0
  183. package/esm/src/interface/models.js +5 -0
  184. package/esm/src/interface/pending.d.ts +9 -0
  185. package/esm/src/interface/pending.js +9 -3
  186. package/esm/src/interface/profile-interface.js +54 -40
  187. package/esm/src/interface/session.d.ts +12 -5
  188. package/esm/src/interface/session.js +17 -10
  189. package/esm/src/interface/stop.d.ts +13 -0
  190. package/esm/src/interface/stop.js +28 -0
  191. package/esm/src/interface/tool-calls.d.ts +14 -2
  192. package/esm/src/interface/tool-calls.js +64 -10
  193. package/esm/src/interface/tool-invoke.d.ts +2 -0
  194. package/esm/src/interface/tool-invoke.js +3 -1
  195. package/esm/src/interface/tool-media.d.ts +2 -0
  196. package/esm/src/interface/tool-media.js +2 -1
  197. package/esm/src/interface/types.d.ts +105 -40
  198. package/esm/src/interface/types.js +1 -0
  199. package/esm/src/kernel/api-catalog.d.ts +85 -0
  200. package/esm/src/kernel/api-catalog.js +229 -0
  201. package/esm/src/kernel/auth/crypto.d.ts +7 -2
  202. package/esm/src/kernel/auth/crypto.js +12 -10
  203. package/esm/src/kernel/auth/oauth.d.ts +2 -1
  204. package/esm/src/kernel/auth/oauth.js +23 -22
  205. package/esm/src/kernel/auth/typed-secret.js +2 -2
  206. package/esm/src/kernel/auth/types.d.ts +13 -0
  207. package/esm/src/kernel/checkpoint.d.ts +43 -0
  208. package/esm/src/kernel/checkpoint.js +58 -0
  209. package/esm/src/kernel/default-scope.d.ts +43 -5
  210. package/esm/src/kernel/default-scope.js +54 -5
  211. package/esm/src/kernel/engine/call-trace.d.ts +19 -0
  212. package/esm/src/kernel/engine/call-trace.js +29 -0
  213. package/esm/src/kernel/engine/compaction.d.ts +6 -5
  214. package/esm/src/kernel/engine/compaction.js +12 -11
  215. package/esm/src/kernel/engine/decision.d.ts +10 -8
  216. package/esm/src/kernel/engine/decision.js +173 -146
  217. package/esm/src/kernel/engine/embedding.d.ts +8 -0
  218. package/esm/src/kernel/engine/embedding.js +118 -0
  219. package/esm/src/kernel/engine/live-inbound.d.ts +14 -4
  220. package/esm/src/kernel/engine/live-inbound.js +36 -11
  221. package/esm/src/kernel/engine/live-ingress.d.ts +6 -0
  222. package/esm/src/kernel/engine/live-ingress.js +6 -1
  223. package/esm/src/kernel/engine/repair.js +12 -12
  224. package/esm/src/kernel/engine/runner/gates.d.ts +2 -2
  225. package/esm/src/kernel/engine/runner/gates.js +287 -101
  226. package/esm/src/kernel/engine/runner/mod.d.ts +19 -5
  227. package/esm/src/kernel/engine/runner/mod.js +107 -56
  228. package/esm/src/kernel/engine/runner/nested.d.ts +32 -0
  229. package/esm/src/kernel/engine/runner/nested.js +134 -0
  230. package/esm/src/kernel/engine/runner/schema-validation.d.ts +24 -3
  231. package/esm/src/kernel/engine/runner/schema-validation.js +78 -4
  232. package/esm/src/kernel/engine/runner/stages.d.ts +1 -1
  233. package/esm/src/kernel/engine/runner/stages.js +1 -8
  234. package/esm/src/kernel/engine/runner/state.d.ts +33 -12
  235. package/esm/src/kernel/engine/runner/state.js +11 -1
  236. package/esm/src/kernel/engine/runner/step-order.d.ts +27 -0
  237. package/esm/src/kernel/engine/runner/step-order.js +165 -0
  238. package/esm/src/kernel/engine/runner/steps.d.ts +2 -2
  239. package/esm/src/kernel/engine/runner/steps.js +328 -169
  240. package/esm/src/kernel/engine/runner/stream.d.ts +42 -11
  241. package/esm/src/kernel/engine/runner/stream.js +197 -46
  242. package/esm/src/kernel/engine/runner/usage.d.ts +5 -5
  243. package/esm/src/kernel/engine/runner/usage.js +12 -14
  244. package/esm/src/kernel/engine/session/mod.d.ts +8 -6
  245. package/esm/src/kernel/engine/session/mod.js +360 -129
  246. package/esm/src/kernel/engine/session/session-trace.d.ts +10 -10
  247. package/esm/src/kernel/engine/session/session-trace.js +41 -30
  248. package/esm/src/kernel/engine/token-estimate.d.ts +10 -64
  249. package/esm/src/kernel/engine/token-estimate.js +14 -194
  250. package/esm/src/kernel/engine/tool-trace.d.ts +3 -3
  251. package/esm/src/kernel/engine/tool-trace.js +2 -1
  252. package/esm/src/kernel/engine/turn-trace.d.ts +8 -7
  253. package/esm/src/kernel/engine/turn-trace.js +28 -36
  254. package/esm/src/kernel/engine/usage.d.ts +6 -0
  255. package/esm/src/kernel/engine/usage.js +17 -0
  256. package/esm/src/kernel/interaction-parts.d.ts +3 -0
  257. package/esm/src/kernel/interaction-parts.js +18 -0
  258. package/esm/src/kernel/json.d.ts +10 -0
  259. package/esm/src/kernel/json.js +3 -0
  260. package/esm/src/kernel/mod.d.ts +38 -11
  261. package/esm/src/kernel/mod.js +22 -7
  262. package/esm/src/kernel/profile-graph.d.ts +11 -6
  263. package/esm/src/kernel/profile-graph.js +14 -7
  264. package/esm/src/kernel/profile-presence.d.ts +10 -1
  265. package/esm/src/kernel/profile-presence.js +90 -75
  266. package/esm/src/kernel/profile-scope.d.ts +7 -3
  267. package/esm/src/kernel/profile-scope.js +67 -55
  268. package/esm/src/kernel/protocols/binding.d.ts +65 -0
  269. package/esm/src/kernel/protocols/binding.js +125 -0
  270. package/esm/src/kernel/protocols/limits.d.ts +15 -0
  271. package/esm/src/kernel/protocols/limits.js +28 -0
  272. package/esm/src/kernel/protocols/mod.d.ts +5 -0
  273. package/esm/src/kernel/protocols/mod.js +5 -0
  274. package/esm/src/kernel/protocols/prices.d.ts +36 -0
  275. package/esm/src/kernel/protocols/prices.js +37 -0
  276. package/esm/src/kernel/protocols/protocol.d.ts +253 -0
  277. package/esm/src/kernel/protocols/protocol.js +253 -0
  278. package/esm/src/kernel/protocols/provider.d.ts +108 -0
  279. package/esm/src/kernel/protocols/provider.js +143 -0
  280. package/esm/src/kernel/protocols/runtime.d.ts +55 -0
  281. package/esm/src/kernel/protocols/runtime.js +534 -0
  282. package/esm/src/kernel/provider-budget.d.ts +32 -0
  283. package/esm/src/kernel/provider-budget.js +262 -0
  284. package/esm/src/kernel/provider-dispatch.d.ts +13 -0
  285. package/esm/src/kernel/provider-dispatch.js +36 -0
  286. package/esm/src/kernel/provider-live.d.ts +7 -0
  287. package/esm/src/kernel/provider-live.js +189 -0
  288. package/esm/src/kernel/provider-runtime.d.ts +57 -0
  289. package/esm/src/kernel/provider-runtime.js +524 -0
  290. package/esm/src/kernel/registry/attachments.d.ts +15 -4
  291. package/esm/src/kernel/registry/attachments.js +31 -22
  292. package/esm/src/kernel/registry/catalog.d.ts +6 -0
  293. package/esm/src/kernel/registry/catalog.js +9 -2
  294. package/esm/src/kernel/registry/embedding-rules.d.ts +28 -0
  295. package/esm/src/kernel/registry/embedding-rules.js +66 -0
  296. package/esm/src/kernel/registry/ingress.d.ts +6 -2
  297. package/esm/src/kernel/registry/ingress.js +55 -10
  298. package/esm/src/kernel/registry/kernel-registry.d.ts +3 -0
  299. package/esm/src/kernel/registry/kernel-registry.js +9 -2
  300. package/esm/src/kernel/registry/profile-outputs.js +4 -1
  301. package/esm/src/kernel/registry/profiles.d.ts +38 -14
  302. package/esm/src/kernel/registry/profiles.js +280 -205
  303. package/esm/src/kernel/registry/provider-request.d.ts +3 -3
  304. package/esm/src/kernel/registry/provider-request.js +5 -13
  305. package/esm/src/kernel/registry/resolve.d.ts +4 -1
  306. package/esm/src/kernel/registry/resolve.js +59 -58
  307. package/esm/src/kernel/registry/schemas.d.ts +3 -0
  308. package/esm/src/kernel/registry/schemas.js +3 -1
  309. package/esm/src/kernel/registry/slot-fill.d.ts +7 -0
  310. package/esm/src/kernel/registry/slot-fill.js +22 -0
  311. package/esm/src/kernel/registry/system-prompt.js +7 -8
  312. package/esm/src/kernel/registry/vault.d.ts +14 -13
  313. package/esm/src/kernel/registry/vault.js +1 -14
  314. package/esm/src/kernel/schema.d.ts +100 -46
  315. package/esm/src/kernel/schema.js +499 -257
  316. package/esm/src/kernel/scope.d.ts +12 -5
  317. package/esm/src/kernel/scope.js +23 -3
  318. package/esm/src/kernel/stages.d.ts +38 -3
  319. package/esm/src/kernel/stages.js +82 -39
  320. package/esm/src/kernel/stop.d.ts +29 -6
  321. package/esm/src/kernel/stop.js +16 -4
  322. package/esm/src/kernel/system-parts.js +6 -6
  323. package/esm/src/kernel/tools/activity-label.d.ts +12 -6
  324. package/esm/src/kernel/tools/activity-label.js +258 -32
  325. package/esm/src/kernel/tools/agent.d.ts +66 -0
  326. package/esm/src/kernel/tools/agent.js +212 -0
  327. package/esm/src/kernel/tools/coordinate.d.ts +4 -0
  328. package/esm/src/kernel/tools/coordinate.js +165 -0
  329. package/esm/src/kernel/tools/events.d.ts +21 -6
  330. package/esm/src/kernel/tools/events.js +53 -18
  331. package/esm/src/kernel/tools/execute.d.ts +47 -11
  332. package/esm/src/kernel/tools/execute.js +508 -136
  333. package/esm/src/kernel/tools/gate-answer.d.ts +12 -2
  334. package/esm/src/kernel/tools/gate-answer.js +17 -6
  335. package/esm/src/kernel/tools/handler-events.d.ts +45 -0
  336. package/esm/src/kernel/tools/handler-events.js +106 -0
  337. package/esm/src/kernel/tools/harness.d.ts +1 -0
  338. package/esm/src/kernel/tools/harness.js +2 -1
  339. package/esm/src/kernel/tools/http-limit.d.ts +27 -0
  340. package/esm/src/kernel/tools/http-limit.js +85 -0
  341. package/esm/src/kernel/tools/invoke.d.ts +27 -5
  342. package/esm/src/kernel/tools/invoke.js +223 -70
  343. package/esm/src/kernel/tools/mcp-sessions.d.ts +4 -1
  344. package/esm/src/kernel/tools/mcp-sessions.js +13 -8
  345. package/esm/src/kernel/tools/mod.d.ts +4 -3
  346. package/esm/src/kernel/tools/mod.js +3 -2
  347. package/esm/src/kernel/tools/model-text.d.ts +10 -5
  348. package/esm/src/kernel/tools/model-text.js +18 -12
  349. package/esm/src/kernel/tools/operation.d.ts +76 -0
  350. package/esm/src/kernel/tools/operation.js +100 -0
  351. package/esm/src/kernel/tools/page-answer.d.ts +8 -0
  352. package/esm/src/kernel/tools/page-answer.js +19 -0
  353. package/esm/src/kernel/tools/permission.d.ts +11 -2
  354. package/esm/src/kernel/tools/permission.js +12 -12
  355. package/esm/src/kernel/tools/project.d.ts +4 -1
  356. package/esm/src/kernel/tools/project.js +32 -2
  357. package/esm/src/kernel/tools/registry.d.ts +9 -2
  358. package/esm/src/kernel/tools/registry.js +69 -10
  359. package/esm/src/kernel/tools/remote.d.ts +40 -6
  360. package/esm/src/kernel/tools/remote.js +219 -92
  361. package/esm/src/kernel/tools/resolve.d.ts +3 -0
  362. package/esm/src/kernel/tools/resolve.js +12 -4
  363. package/esm/src/kernel/tools/run.d.ts +28 -0
  364. package/esm/src/kernel/tools/run.js +86 -0
  365. package/esm/src/kernel/tools/schema.d.ts +3 -3
  366. package/esm/src/kernel/tools/schema.js +21 -100
  367. package/esm/src/kernel/tools/signed-in-fetch.d.ts +2 -1
  368. package/esm/src/kernel/tools/signed-in-fetch.js +3 -3
  369. package/esm/src/kernel/tools/stage-run.d.ts +27 -4
  370. package/esm/src/kernel/tools/stage-run.js +75 -17
  371. package/esm/src/kernel/tools/types.d.ts +235 -25
  372. package/esm/src/kernel/tools/unchecked-output.d.ts +14 -0
  373. package/esm/src/kernel/tools/unchecked-output.js +18 -0
  374. package/esm/src/kernel/turn-events.d.ts +208 -31
  375. package/esm/src/kernel/turn-events.js +127 -9
  376. package/esm/src/kernel/types.d.ts +302 -161
  377. package/esm/src/kernel/util/base64.d.ts +2 -0
  378. package/esm/src/kernel/util/base64.js +2 -0
  379. package/esm/src/kernel/util/partial-json.d.ts +23 -0
  380. package/esm/src/kernel/util/partial-json.js +128 -0
  381. package/esm/src/kernel/util/record.d.ts +1 -0
  382. package/esm/src/kernel/util/record.js +1 -0
  383. package/esm/src/observability/destinations.d.ts +5 -0
  384. package/esm/src/observability/destinations.js +7 -2
  385. package/esm/src/observability/jsonl.d.ts +2 -2
  386. package/esm/src/observability/jsonl.js +15 -22
  387. package/esm/src/observability/mod.d.ts +3 -3
  388. package/esm/src/observability/mod.js +2 -2
  389. package/esm/src/observability/openinference.d.ts +1 -1
  390. package/esm/src/observability/openinference.js +3 -3
  391. package/esm/src/observability/otlp.d.ts +3 -0
  392. package/esm/src/observability/otlp.js +3 -3
  393. package/esm/src/observability/phoenix.d.ts +1 -0
  394. package/esm/src/observability/policy.d.ts +3 -0
  395. package/esm/src/observability/policy.js +5 -1
  396. package/esm/src/observability/resolve-policy.js +11 -5
  397. package/esm/src/observability/spans.d.ts +8 -2
  398. package/esm/src/observability/spans.js +21 -5
  399. package/esm/src/observability/trace-catalog.d.ts +19 -2
  400. package/esm/src/observability/trace-catalog.js +128 -87
  401. package/esm/src/observability/trace-record.js +22 -17
  402. package/esm/src/observability/trace-schema.d.ts +3 -0
  403. package/esm/src/observability/trace-schema.js +1 -1
  404. package/esm/src/observability/trace-sink.d.ts +1 -0
  405. package/esm/src/observability/trace-sink.js +1 -1
  406. package/esm/src/observability/trace-span.d.ts +7 -1
  407. package/esm/src/observability/trace-span.js +3 -1
  408. package/esm/src/observability/trace.d.ts +2 -0
  409. package/esm/src/observability/trace.js +4 -2
  410. package/esm/src/observability/types.d.ts +35 -11
  411. package/esm/src/observability/types.js +1 -1
  412. package/esm/src/presets/google/speech-voices.d.ts +1 -0
  413. package/esm/src/presets/google-limits.d.ts +1 -0
  414. package/esm/src/presets/google.d.ts +27 -12
  415. package/esm/src/presets/google.js +34 -25
  416. package/esm/src/presets/local.d.ts +26 -0
  417. package/esm/src/presets/local.js +30 -0
  418. package/esm/src/presets/mod.d.ts +5 -4
  419. package/esm/src/presets/mod.js +4 -4
  420. package/esm/src/presets/openrouter.d.ts +14 -1
  421. package/esm/src/presets/openrouter.js +19 -1
  422. package/esm/src/providers/embedding-limits.d.ts +7 -0
  423. package/esm/src/providers/embedding-limits.js +12 -0
  424. package/esm/src/providers/gemini/embedding-protocol.d.ts +8 -0
  425. package/esm/src/providers/gemini/embedding-protocol.js +125 -0
  426. package/esm/src/providers/gemini/interactions-protocol.d.ts +8 -0
  427. package/esm/src/providers/gemini/interactions-protocol.js +105 -0
  428. package/esm/src/providers/gemini/live-protocol.d.ts +3 -0
  429. package/esm/src/providers/gemini/live-protocol.js +191 -0
  430. package/esm/src/providers/gemini/prices.d.ts +3 -0
  431. package/esm/src/providers/gemini/prices.js +63 -0
  432. package/esm/src/providers/gemini/provider.d.ts +7 -0
  433. package/esm/src/providers/gemini/provider.js +39 -0
  434. package/esm/src/providers/google/builtins.d.ts +14 -0
  435. package/esm/src/providers/google/builtins.js +57 -0
  436. package/esm/src/providers/google/grounding.d.ts +4 -4
  437. package/esm/src/providers/google/interactions/framing.d.ts +20 -8
  438. package/esm/src/providers/google/interactions/framing.js +85 -44
  439. package/esm/src/providers/google/interactions/steps.d.ts +5 -5
  440. package/esm/src/providers/google/interactions/steps.js +4 -4
  441. package/esm/src/providers/google/interactions/stream.d.ts +10 -11
  442. package/esm/src/providers/google/interactions/stream.js +33 -100
  443. package/esm/src/providers/google/live/framing.d.ts +15 -5
  444. package/esm/src/providers/google/live/framing.js +25 -25
  445. package/esm/src/providers/google/live/stream.d.ts +6 -44
  446. package/esm/src/providers/google/live/stream.js +3 -209
  447. package/esm/src/providers/google/urls.d.ts +1 -3
  448. package/esm/src/providers/google/urls.js +1 -3
  449. package/esm/src/providers/google/usage.js +2 -2
  450. package/esm/src/providers/live.d.ts +6 -0
  451. package/esm/src/providers/live.js +6 -0
  452. package/esm/src/providers/local/embedding-protocol.d.ts +7 -0
  453. package/esm/src/providers/local/embedding-protocol.js +60 -0
  454. package/esm/src/providers/local/provider.d.ts +7 -0
  455. package/esm/src/providers/local/provider.js +28 -0
  456. package/esm/src/providers/mod.d.ts +28 -7
  457. package/esm/src/providers/mod.js +19 -3
  458. package/esm/src/providers/open-ai/protocol.d.ts +3 -0
  459. package/esm/src/providers/open-ai/protocol.js +189 -0
  460. package/esm/src/providers/openrouter/embedding-protocol.d.ts +6 -0
  461. package/esm/src/providers/openrouter/embedding-protocol.js +86 -0
  462. package/esm/src/providers/openrouter/image.d.ts +0 -9
  463. package/esm/src/providers/openrouter/image.js +0 -153
  464. package/esm/src/providers/openrouter/images-protocol.d.ts +3 -0
  465. package/esm/src/providers/openrouter/images-protocol.js +82 -0
  466. package/esm/src/providers/openrouter/openai/compat.d.ts +2 -2
  467. package/esm/src/providers/openrouter/openai/compat.js +6 -6
  468. package/esm/src/providers/openrouter/openai/image-payload.d.ts +2 -2
  469. package/esm/src/providers/openrouter/openai/reasoning-state.d.ts +2 -0
  470. package/esm/src/providers/openrouter/openai/reasoning-state.js +31 -0
  471. package/esm/src/providers/openrouter/protocol.d.ts +8 -0
  472. package/esm/src/providers/openrouter/protocol.js +171 -0
  473. package/esm/src/providers/openrouter/provider.d.ts +10 -0
  474. package/esm/src/providers/openrouter/provider.js +50 -0
  475. package/esm/src/providers/shared/carried-tool-files.d.ts +7 -0
  476. package/esm/src/providers/shared/carried-tool-files.js +43 -0
  477. package/esm/src/providers/shared/pcm.js +2 -2
  478. package/esm/src/providers/shared/protocol-events.d.ts +8 -0
  479. package/esm/src/providers/shared/protocol-events.js +20 -0
  480. package/esm/src/providers/shared/response-identity.d.ts +2 -2
  481. package/esm/src/providers/shared/retry.d.ts +17 -0
  482. package/esm/src/providers/shared/retry.js +90 -0
  483. package/esm/src/providers/shared/sse.d.ts +0 -4
  484. package/esm/src/providers/shared/sse.js +50 -36
  485. package/esm/src/providers/shared/tool-args.d.ts +6 -7
  486. package/esm/src/providers/shared/tool-args.js +10 -6
  487. package/esm/src/providers/shared/tool-draft.d.ts +16 -0
  488. package/esm/src/providers/shared/tool-draft.js +14 -0
  489. package/esm/src/providers/shared/upstream-tap.d.ts +2 -2
  490. package/esm/src/providers/shared/upstream-tape.js +1 -1
  491. package/esm/src/providers/system-one/protocol.d.ts +8 -0
  492. package/esm/src/providers/system-one/protocol.js +93 -0
  493. package/esm/src/providers/types.d.ts +48 -16
  494. package/esm/src/providers/types.js +2 -1
  495. package/esm/src/providers/typesafe/provider.d.ts +7 -0
  496. package/esm/src/providers/typesafe/provider.js +24 -0
  497. package/esm/src/surface/formats.d.ts +19 -1
  498. package/esm/src/surface/formats.js +68 -29
  499. package/esm/src/surface/mod.d.ts +4 -2
  500. package/esm/src/surface/mod.js +4 -2
  501. package/esm/src/surface/runtime.d.ts +4 -0
  502. package/esm/src/surface/runtime.js +2 -0
  503. package/esm/src/surface/tools.d.ts +2 -8
  504. package/esm/src/surface/tools.js +4 -22
  505. package/esm/src/surface/types.d.ts +6 -0
  506. package/package.json +5 -13
  507. package/esm/src/cli/commands/egress-compile.d.ts +0 -17
  508. package/esm/src/cli/commands/egress-compile.js +0 -25
  509. package/esm/src/guardrails/egress-policy.d.ts +0 -27
  510. package/esm/src/guardrails/egress-policy.js +0 -76
  511. package/esm/src/guardrails/egress-rules.d.ts +0 -54
  512. package/esm/src/guardrails/egress-rules.js +0 -49
  513. package/esm/src/guardrails/lexicon.d.ts +0 -30
  514. package/esm/src/guardrails/lexicon.js +0 -478
  515. package/esm/src/kernel/engine/media-probe/audio.d.ts +0 -7
  516. package/esm/src/kernel/engine/media-probe/audio.js +0 -342
  517. package/esm/src/kernel/engine/media-probe/bytes.d.ts +0 -6
  518. package/esm/src/kernel/engine/media-probe/bytes.js +0 -26
  519. package/esm/src/kernel/engine/media-probe/image.d.ts +0 -5
  520. package/esm/src/kernel/engine/media-probe/image.js +0 -171
  521. package/esm/src/kernel/engine/media-probe/iso-bmff.d.ts +0 -19
  522. package/esm/src/kernel/engine/media-probe/iso-bmff.js +0 -48
  523. package/esm/src/kernel/engine/media-probe/matroska.d.ts +0 -35
  524. package/esm/src/kernel/engine/media-probe/matroska.js +0 -226
  525. package/esm/src/kernel/engine/media-probe/mp4.d.ts +0 -22
  526. package/esm/src/kernel/engine/media-probe/mp4.js +0 -279
  527. package/esm/src/kernel/engine/media-probe/opus.d.ts +0 -4
  528. package/esm/src/kernel/engine/media-probe/opus.js +0 -23
  529. package/esm/src/kernel/engine/media-probe/pdf.d.ts +0 -5
  530. package/esm/src/kernel/engine/media-probe/pdf.js +0 -117
  531. package/esm/src/kernel/engine/media-probe/video.d.ts +0 -15
  532. package/esm/src/kernel/engine/media-probe/video.js +0 -49
  533. package/esm/src/presets/typesafe.d.ts +0 -2
  534. package/esm/src/presets/typesafe.js +0 -2
  535. package/esm/src/providers/create-provider.d.ts +0 -21
  536. package/esm/src/providers/create-provider.js +0 -90
  537. package/esm/src/providers/decision/usage.d.ts +0 -3
  538. package/esm/src/providers/decision/usage.js +0 -25
  539. package/esm/src/providers/google/interactions/mod.d.ts +0 -2
  540. package/esm/src/providers/google/interactions/mod.js +0 -2
  541. package/esm/src/providers/google/keys.d.ts +0 -20
  542. package/esm/src/providers/google/keys.js +0 -87
  543. package/esm/src/providers/google/live/mod.d.ts +0 -7
  544. package/esm/src/providers/google/live/mod.js +0 -7
  545. package/esm/src/providers/google/live/openapi-schema.d.ts +0 -1
  546. package/esm/src/providers/google/live/openapi-schema.js +0 -42
  547. package/esm/src/providers/google/live/session.d.ts +0 -14
  548. package/esm/src/providers/google/live/session.js +0 -150
  549. package/esm/src/providers/local/local.d.ts +0 -12
  550. package/esm/src/providers/local/local.js +0 -186
  551. package/esm/src/providers/local/mod.d.ts +0 -8
  552. package/esm/src/providers/local/mod.js +0 -8
  553. package/esm/src/providers/openrouter/cache-control.d.ts +0 -5
  554. package/esm/src/providers/openrouter/cache-control.js +0 -4
  555. package/esm/src/providers/openrouter/chat.d.ts +0 -64
  556. package/esm/src/providers/openrouter/chat.js +0 -490
  557. package/esm/src/providers/openrouter/openai/sdk-messages.d.ts +0 -10
  558. package/esm/src/providers/openrouter/openai/sdk-messages.js +0 -99
  559. package/esm/src/providers/openrouter/resolve-api-key.d.ts +0 -3
  560. package/esm/src/providers/openrouter/resolve-api-key.js +0 -8
  561. package/esm/src/providers/openrouter/speech.d.ts +0 -18
  562. package/esm/src/providers/openrouter/speech.js +0 -109
  563. package/esm/src/providers/probe.d.ts +0 -5
  564. package/esm/src/providers/probe.js +0 -15
  565. package/esm/src/providers/shared/builtin-wire.d.ts +0 -4
  566. package/esm/src/providers/shared/builtin-wire.js +0 -9
  567. package/esm/src/providers/shared/vault.d.ts +0 -13
  568. package/esm/src/providers/shared/vault.js +0 -41
@@ -0,0 +1,212 @@
1
+ import { z } from 'zod';
2
+ import { TheoremError } from '../../guardrails/error.js';
3
+ import { interactionPartSchema, keptReply, sourceSchema } from '../turn-events.js';
4
+ import { findLast } from '../util/find-last.js';
5
+ import { profileToolAllow } from './resolve.js';
6
+ /** A call that settled without a reply; the model reads `failure`. */
7
+ class AgentCallFailed extends Error {
8
+ failure;
9
+ constructor(failure) {
10
+ super(failure.message);
11
+ this.failure = failure;
12
+ }
13
+ }
14
+ /** The agents an agent tool can run: each has a turn that takes text. */
15
+ const AGENT_TOOL_TYPES = new Set(['text', 'image', 'speech']);
16
+ // why: Bytes that are not base64, or a text of only spaces, would be refused inside the called turn as the host's error and end the caller's turn; checked here, the model reads a failed call.
17
+ const textInput = z.string().regex(/\S/);
18
+ const blobInput = z.strictObject({
19
+ mimeType: z.string(),
20
+ data: z.base64(),
21
+ name: z.string().optional(),
22
+ });
23
+ const mediaRefInput = z.strictObject({
24
+ mimeType: z.string(),
25
+ uri: z.string(),
26
+ name: z.string().optional(),
27
+ });
28
+ const speechInput = z.strictObject({
29
+ voice: z.string().optional(),
30
+ style: z.string().optional(),
31
+ speed: z.number().positive().optional(),
32
+ });
33
+ /** One choice per declared slot; a slot or a value the profile does not declare is refused. */
34
+ function slotsInput(slots) {
35
+ return z.strictObject(Object.fromEntries(Object.entries(slots).map(([slot, choices]) => [slot, z.enum(choices).optional()])));
36
+ }
37
+ /** The fields an agent tool's input can carry to the called agent; a host field takes none of these names. */
38
+ const AGENT_INPUT_FIELDS = new Set([
39
+ 'text',
40
+ 'attachments',
41
+ 'voice',
42
+ 'slots',
43
+ 'speech',
44
+ ]);
45
+ /**
46
+ * What the model sent, split into what goes to the called agent and what only the host reads.
47
+ *
48
+ * why: A host field is the host's own word for something (an id it resolves); the called profile does not take it, so it never reaches the agent's turn.
49
+ */
50
+ function splitHostInput(tool, input) {
51
+ if (!tool.hostFields)
52
+ return { sent: input };
53
+ const all = { ...input };
54
+ const hostInput = {};
55
+ for (const field of Object.keys(tool.hostFields)) {
56
+ if (all[field] !== undefined)
57
+ hostInput[field] = all[field];
58
+ }
59
+ const { text, attachments, voice, slots, speech } = input;
60
+ return {
61
+ sent: {
62
+ text,
63
+ ...(attachments ? { attachments } : {}),
64
+ ...(voice ? { voice } : {}),
65
+ ...(slots ? { slots } : {}),
66
+ ...(speech ? { speech } : {}),
67
+ },
68
+ hostInput,
69
+ };
70
+ }
71
+ /**
72
+ * The input of an agent tool that runs `agent`: text, and each channel the
73
+ * profile's `inputs` declares. Anything else is refused, never dropped. The
74
+ * called turn's own ingress checks MIME types and sizes.
75
+ */
76
+ function agentToolInputFor(agent, tool) {
77
+ const { inputs } = agent;
78
+ const shape = { text: textInput };
79
+ if (inputs?.attachments) {
80
+ shape.attachments = z.array(z.union([blobInput, mediaRefInput])).optional();
81
+ }
82
+ if (inputs?.voice)
83
+ shape.voice = z.array(blobInput).optional();
84
+ if (inputs?.slots)
85
+ shape.slots = slotsInput(inputs.slots).optional();
86
+ if (agent.type === 'speech')
87
+ shape.speech = speechInput.optional();
88
+ for (const channel of tool?.hostOnly ?? []) {
89
+ if (!shape[channel]) {
90
+ throw new TheoremError('config', `Tool '${tool?.name}' keeps '${channel}' for the host, which its profile does not take`);
91
+ }
92
+ delete shape[channel];
93
+ }
94
+ for (const [field, text] of Object.entries(tool?.fieldText ?? {})) {
95
+ const schema = shape[field];
96
+ if (!schema) {
97
+ throw new TheoremError('config', `Tool '${tool?.name}' describes '${field}', which its profile does not take`);
98
+ }
99
+ shape[field] = schema.describe(text);
100
+ }
101
+ for (const [field, schema] of Object.entries(tool?.hostFields ?? {})) {
102
+ if (AGENT_INPUT_FIELDS.has(field)) {
103
+ throw new TheoremError('config', `Tool '${tool?.name}' declares the host field '${field}', which is a field of every agent tool`);
104
+ }
105
+ shape[field] = schema;
106
+ }
107
+ // why: The shape is built key by key from the profile, which zod cannot type; each key is an `AgentToolInput` field.
108
+ return z.strictObject(shape);
109
+ }
110
+ const agentToolOutput = z.object({
111
+ text: z.string().optional(),
112
+ structured: z.unknown().optional(),
113
+ removed: z
114
+ .array(z.object({ path: z.string(), reason: z.string(), item: z.unknown() }))
115
+ .optional(),
116
+ parts: z.array(interactionPartSchema).optional(),
117
+ sources: z.array(sourceSchema).optional(),
118
+ });
119
+ function profileTakesText(profile) {
120
+ if (profile.type === 'speech')
121
+ return true;
122
+ return (profile.type === 'text' || profile.type === 'image') && profile.inputs.text !== false;
123
+ }
124
+ /** A tool that can stop the turn on a gate: a gate inside the called agent has no one to answer it. */
125
+ function toolCanGate(tool) {
126
+ if (tool.type === 'builtin')
127
+ return false;
128
+ if (tool.permission !== 'auto')
129
+ return true;
130
+ return ('auth' in tool && tool.auth !== undefined && (tool.auth.onUnauthenticated ?? 'gate') === 'gate');
131
+ }
132
+ /** Why `profile` can't be run by an agent tool, or `undefined` when it can. */
133
+ function agentProfileProblem(profile, find) {
134
+ if (!AGENT_TOOL_TYPES.has(profile.type)) {
135
+ return `it is a ${profile.type} profile; an agent tool runs a text, image, or speech profile`; // labels-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
136
+ }
137
+ if (!profileTakesText(profile))
138
+ return 'it does not take text'; // labels-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
139
+ for (const id of profileToolAllow(profile)) {
140
+ const tool = find(id);
141
+ if (!tool)
142
+ return `its tool '${id}' is not registered; register it first`; // labels-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
143
+ if (toolCanGate(tool)) {
144
+ return `its tool '${id}' can stop on a gate; give it permission 'auto' and no sign-in`; // labels-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
145
+ }
146
+ }
147
+ return undefined;
148
+ }
149
+ /** The profile an agent tool runs; throws `config` when the tool can't run it. */
150
+ function agentToolProfile(def, findProfile, findTool) {
151
+ const tag = `Agent tool "${def.name}"`; // labels-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
152
+ const max = def.maxCallsPerTurn;
153
+ if (max !== undefined && !(Number.isInteger(max) && max > 0)) {
154
+ throw new TheoremError('config', `${tag}: maxCallsPerTurn must be a whole number above 0`); // labels-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
155
+ }
156
+ const profile = findProfile(def.profile);
157
+ if (!profile) {
158
+ throw new TheoremError('config', `${tag}: profile '${def.profile}' must be registered before the tool`);
159
+ }
160
+ const problem = agentProfileProblem(profile, findTool);
161
+ if (problem) {
162
+ throw new TheoremError('config', `${tag} can't run '${def.profile}': ${problem}`); // labels-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
163
+ }
164
+ return profile;
165
+ }
166
+ /** An agent with no tools of its own read only what it was sent; one with tools may have read outside content. */
167
+ function agentToolOrigin(profile) {
168
+ if (!profile)
169
+ return 'delegated';
170
+ const builtins = 'models' in profile
171
+ ? Object.values(profile.models).some((binding) => (binding.builtInTools?.length ?? 0) > 0)
172
+ : false;
173
+ return profileToolAllow(profile).length === 0 && !builtins ? 'local' : 'delegated';
174
+ }
175
+ /**
176
+ * The called agent's reply: its text or its last structured reply, its media as parts, and what it cited.
177
+ *
178
+ * why: A structured reply's text is the same JSON as a string, so returning both would have the caller's model read the answer twice.
179
+ */
180
+ function agentToolOutputOf(turn) {
181
+ const events = keptReply(turn);
182
+ const text = events.flatMap((e) => (e.type === 'text' ? [e.text] : [])).join('');
183
+ const reply = findLast(events, (e) => e.type === 'structured');
184
+ const structured = reply?.structured;
185
+ const parts = events.flatMap((e) => e.type === 'media'
186
+ ? [
187
+ {
188
+ type: e.media.mimeType.startsWith('audio/') ? 'audio' : 'image',
189
+ mimeType: e.media.mimeType,
190
+ data: e.media.data,
191
+ },
192
+ ]
193
+ : []);
194
+ const sources = events.flatMap((e) => (e.type === 'citation' ? e.sources : []));
195
+ return {
196
+ ...(structured === undefined ? { text } : { structured }),
197
+ ...(reply?.removed?.length ? { removed: reply.removed } : {}),
198
+ ...(parts.length > 0 ? { parts } : {}),
199
+ ...(sources.length > 0 ? { sources } : {}),
200
+ };
201
+ }
202
+ function normalizeAgent(def, input, schemas) {
203
+ return {
204
+ ...def,
205
+ type: 'agent',
206
+ input,
207
+ output: agentToolOutput,
208
+ sources: (output) => output.sources ?? [],
209
+ ...schemas,
210
+ };
211
+ }
212
+ export { AgentCallFailed, agentProfileProblem, agentToolInputFor, agentToolOrigin, agentToolOutput, agentToolOutputOf, agentToolProfile, normalizeAgent, splitHostInput, };
@@ -0,0 +1,4 @@
1
+ import type { TurnEvent } from '../types.js';
2
+ import type { ToolExecuteSettlement } from './execute.js';
3
+ import { type ToolExecutionCoordinator, type ToolOperationClaim, type ToolOperationIdentity, type ToolOperationOutcome } from './operation.js';
4
+ export declare function coordinateTool(coordinator: ToolExecutionCoordinator | undefined, identity: Omit<ToolOperationIdentity, 'invocationHash'>, invocation: unknown, signal: AbortSignal | undefined, run: (beginBody?: (preparedInput: unknown) => Promise<ToolOperationClaim | undefined>) => AsyncGenerator<TurnEvent, ToolExecuteSettlement>, authorizeReplay?: (outcome: ToolOperationOutcome) => void | Promise<void>): AsyncGenerator<TurnEvent, ToolExecuteSettlement>;
@@ -0,0 +1,165 @@
1
+ import { TheoremError, throwIfAborted } from '../../guardrails/error.js';
2
+ import { labelText } from '../../guardrails/labels.js';
3
+ import { jsonObjectSchema } from '../json.js';
4
+ import { operationUnavailable, operationWireValue, toolInvocationHash, toolOperationOutcomeSchema, } from './operation.js';
5
+ class ReplayedOperation {
6
+ outcome;
7
+ constructor(outcome) {
8
+ this.outcome = outcome;
9
+ }
10
+ }
11
+ function uncertainError(cause) {
12
+ return new TheoremError('unavailable', labelText('tool.execution_uncertain'), {
13
+ copy: { key: 'tool.execution_uncertain' },
14
+ cause,
15
+ });
16
+ }
17
+ class CoordinatedExecution {
18
+ coordinator;
19
+ operation;
20
+ accepted;
21
+ signal;
22
+ claim;
23
+ committed = false;
24
+ writeFailed = false;
25
+ terminal;
26
+ constructor(coordinator, operation, accepted, signal) {
27
+ this.coordinator = coordinator;
28
+ this.operation = operation;
29
+ this.accepted = accepted;
30
+ this.signal = signal;
31
+ }
32
+ async beginBody(preparedInput) {
33
+ throwIfAborted(this.signal);
34
+ const operation = {
35
+ ...this.operation,
36
+ invocation: { accepted: this.accepted, preparedInput: operationWireValue(preparedInput) },
37
+ };
38
+ const result = await this.coordinator.begin(operation);
39
+ if (result.kind === 'settled')
40
+ throw new ReplayedOperation(result.outcome);
41
+ if (result.kind === 'running' || result.kind === 'uncertain')
42
+ throw uncertainError();
43
+ if (result.kind !== 'acquired' || typeof result.claimToken !== 'string' || !result.claimToken)
44
+ throw operationUnavailable();
45
+ this.claim = { ...operation, claimToken: result.claimToken };
46
+ throwIfAborted(this.signal);
47
+ return this.claim;
48
+ }
49
+ observe(event) {
50
+ if (event.type !== 'tool')
51
+ return true;
52
+ if (event.tool.phase === 'complete' || event.tool.phase === 'error') {
53
+ this.terminal = { ...event, tool: event.tool };
54
+ return false;
55
+ }
56
+ if (this.claim && event.tool.phase === 'gate')
57
+ throw uncertainError();
58
+ return true;
59
+ }
60
+ async finish(settlement) {
61
+ if (settlement.gated) {
62
+ if (this.claim)
63
+ throw uncertainError();
64
+ return undefined;
65
+ }
66
+ if (!this.terminal)
67
+ throw operationUnavailable();
68
+ const { modelResult, outputRaw, failure, awaiting, denied, callNotStarted, aborted, pendingInject, } = settlement;
69
+ const effects = this.claim ? (failure ? 'unknown' : 'completed') : 'not_started';
70
+ const outcome = {
71
+ event: this.terminal,
72
+ effects,
73
+ replay: {
74
+ modelResult,
75
+ outputRaw,
76
+ failure,
77
+ awaiting,
78
+ denied,
79
+ callNotStarted,
80
+ aborted,
81
+ pendingInject,
82
+ },
83
+ };
84
+ this.writeFailed = true;
85
+ const saved = toolOperationOutcomeSchema.parse(operationWireValue(outcome));
86
+ if (this.claim)
87
+ await this.coordinator.settle(this.claim, saved);
88
+ else
89
+ await this.coordinator.settleNotStarted(this.operation, saved);
90
+ this.committed = true;
91
+ return saved.event;
92
+ }
93
+ replay(error) {
94
+ const saved = toolOperationOutcomeSchema.parse(operationWireValue(error.outcome));
95
+ const { operationId, callId, toolId } = this.operation;
96
+ if (saved.event.tool.operationId !== operationId ||
97
+ saved.event.tool.callId !== callId ||
98
+ saved.event.tool.name !== toolId)
99
+ throw operationUnavailable();
100
+ this.committed = true;
101
+ return saved;
102
+ }
103
+ failure(error) {
104
+ return this.claim && !this.committed ? uncertainError(error) : error;
105
+ }
106
+ async close() {
107
+ if (this.claim && !this.committed) {
108
+ await this.coordinator.markUncertain(this.claim, this.writeFailed ? 'settlement_write_failed' : 'execution_interrupted');
109
+ }
110
+ }
111
+ }
112
+ export async function* coordinateTool(coordinator, identity, invocation, signal, run, authorizeReplay) {
113
+ if (!coordinator)
114
+ return yield* run();
115
+ const accepted = jsonObjectSchema.parse(operationWireValue(invocation));
116
+ const operation = { ...identity, invocationHash: await toolInvocationHash(accepted) };
117
+ const execution = new CoordinatedExecution(coordinator, operation, accepted, signal);
118
+ throwIfAborted(signal);
119
+ const existing = await coordinator.lookup(operation);
120
+ throwIfAborted(signal);
121
+ if (existing?.kind === 'running' || existing?.kind === 'uncertain')
122
+ throw uncertainError();
123
+ if (existing?.kind === 'settled') {
124
+ if (!authorizeReplay)
125
+ throw operationUnavailable();
126
+ const saved = execution.replay(new ReplayedOperation(existing.outcome));
127
+ await authorizeReplay(saved);
128
+ throwIfAborted(signal);
129
+ yield saved.event;
130
+ return saved.replay;
131
+ }
132
+ const iterator = run((input) => execution.beginBody(input));
133
+ try {
134
+ for (;;) {
135
+ const next = await iterator.next();
136
+ if (next.done) {
137
+ const terminal = await execution.finish(next.value);
138
+ if (terminal)
139
+ yield terminal;
140
+ return next.value;
141
+ }
142
+ if (execution.observe(next.value))
143
+ yield next.value;
144
+ }
145
+ }
146
+ catch (error) {
147
+ if (error instanceof ReplayedOperation) {
148
+ if (!authorizeReplay)
149
+ throw operationUnavailable();
150
+ const saved = execution.replay(error);
151
+ await authorizeReplay(saved);
152
+ yield saved.event;
153
+ return saved.replay;
154
+ }
155
+ throw execution.failure(error);
156
+ }
157
+ finally {
158
+ try {
159
+ await execution.close();
160
+ }
161
+ finally {
162
+ await iterator.return({});
163
+ }
164
+ }
165
+ }
@@ -1,32 +1,47 @@
1
1
  import type { z } from 'zod';
2
+ import { type LabelOverrides } from '../../guardrails/labels.js';
2
3
  import type { GuardrailEvent, NetworkGuardrailSpec } from '../../guardrails/types.js';
3
4
  import type { SpanHandle } from '../../observability/trace-span.js';
4
5
  import { type Source } from '../turn-events.js';
5
6
  import type { TurnEvent, TurnEventOf } from '../types.js';
7
+ import type { ToolOperationClaim } from './operation.js';
6
8
  import type { ToolCallRequest, ToolContext, ToolFailure, ToolLabels, ToolPhaseEvent } from './types.js';
7
- export type ToolCallBase = Pick<ToolPhaseEvent, 'name' | 'callId'>;
9
+ export type ToolCallBase = Pick<ToolPhaseEvent, 'name' | 'callId'> & {
10
+ operationId?: string;
11
+ /** The call's failed label, from {@linkcode failedActivity}; absent, a failure names the tool. */
12
+ activityFailed?: string;
13
+ };
8
14
  export type DistributiveOmit<T, K extends PropertyKey> = T extends unknown ? Omit<T, K> : never;
9
15
  export type ToolPhasePatch = DistributiveOmit<ToolPhaseEvent, keyof ToolCallBase | 'at'>;
10
16
  export declare function toolEvent(base: ToolCallBase, patch: ToolPhasePatch): TurnEventOf<'tool'>;
17
+ /**
18
+ * The label a failed call shows: the tool's own, filled from the input the model sent, else the
19
+ * labels' line naming the tool in words.
20
+ */
21
+ export declare function failedActivity(name: string, profileLabels?: LabelOverrides, labels?: ToolLabels, input?: unknown): string;
22
+ /** The failed label of the call `base` names. */
23
+ export declare function failedActivityOf(base: ToolCallBase): string;
11
24
  /** `readBack` is passed when the call's result guard already wrote the model's text. */
12
25
  export declare function failureEvent(base: ToolCallBase, failure: ToolFailure, readBack?: string): TurnEventOf<'tool'>;
13
26
  /** The first event of every call. */
14
- export declare function toolCallRequestEvent(base: ToolCallBase, args: Record<string, unknown>, { thoughtSignature, stepId }?: Pick<ToolCallRequest, 'thoughtSignature' | 'stepId'>): TurnEventOf<'tool'>;
27
+ export declare function toolCallRequestEvent(base: ToolCallBase, args: Record<string, unknown>, { reasoning, stepId, stepCallCount, }?: Pick<ToolCallRequest, 'reasoning' | 'stepId' | 'stepCallCount'>): TurnEventOf<'tool'>;
15
28
  /** Unique: readers join a call's events by it. */
16
29
  export declare function newCallId(name: string): string;
17
30
  export declare function toolCallArguments(safeInput: unknown): Record<string, unknown>;
18
31
  export declare function messageOf(err: unknown): string;
19
32
  export declare function sourceEvents(base: ToolCallBase, sources: (output: unknown) => Source[], output: unknown): Generator<TurnEvent>;
20
- /** `{ ok: false }` comes after the failure event is emitted, so callers only bail. */
33
+ export declare function dispatchToolBody(tool: {
34
+ labels?: ToolLabels;
35
+ }, input: unknown, ctx: ToolContext, base: ToolCallBase, beginBody?: (preparedInput: unknown) => Promise<ToolOperationClaim | undefined>): AsyncGenerator<TurnEvent, ToolOperationClaim | undefined>;
21
36
  export declare function startToolExecution<T>(tool: {
22
37
  input: z.ZodType<T>;
23
- labels?: ToolLabels;
24
- }, rawInput: unknown, ctx: ToolContext, base: ToolCallBase): Generator<TurnEvent, {
38
+ }, rawInput: unknown, ctx: ToolContext): {
25
39
  ok: true;
26
40
  data: T;
27
41
  } | {
28
42
  ok: false;
29
- }>;
43
+ failure: ToolFailure;
44
+ };
30
45
  export declare function networkBlockedEvent(): GuardrailEvent;
31
46
  export declare function networkBlocked(err: unknown, guardrail?: GuardrailEvent): Generator<TurnEvent, ToolFailure>;
32
47
  /**
@@ -1,32 +1,58 @@
1
1
  import { throwIfAborted } from '../../guardrails/error.js';
2
+ import { labelText } from '../../guardrails/labels.js';
2
3
  import { assertSafeUrl } from '../../guardrails/network.js';
3
4
  import { resolveGuardrailPolicy } from '../../guardrails/policy.js';
4
5
  import { NETWORK_RULES } from '../../guardrails/rules.js';
5
6
  import { recordToolCheck } from '../engine/tool-trace.js';
6
7
  import { sourceSchema } from '../turn-events.js';
7
8
  import { isRecord } from '../util/record.js';
8
- import { fillActivityLabel } from './activity-label.js';
9
+ import { fillActivityLabel, toolNameInWords } from './activity-label.js';
9
10
  import { formatToolFailureForModel, formatToolResult } from './model-text.js';
10
11
  export function toolEvent(base, patch) {
11
12
  return {
12
13
  type: 'tool',
13
- tool: { ...patch, name: base.name, callId: base.callId, at: Date.now() },
14
+ tool: {
15
+ ...patch,
16
+ name: base.name,
17
+ callId: base.callId,
18
+ ...(base.operationId ? { operationId: base.operationId } : {}),
19
+ at: Date.now(),
20
+ },
14
21
  };
15
22
  }
23
+ /**
24
+ * The label a failed call shows: the tool's own, filled from the input the model sent, else the
25
+ * labels' line naming the tool in words.
26
+ */
27
+ export function failedActivity(name, profileLabels, labels, input) {
28
+ return (fillActivityLabel(labels?.activityFailed, { input }) ??
29
+ labelText('tool.activity_failed', { tool: toolNameInWords(name) }, profileLabels));
30
+ }
31
+ /** The failed label of the call `base` names. */
32
+ export function failedActivityOf(base) {
33
+ return base.activityFailed ?? failedActivity(base.name);
34
+ }
16
35
  /** `readBack` is passed when the call's result guard already wrote the model's text. */
17
36
  export function failureEvent(base, failure, readBack = formatToolResult(formatToolFailureForModel(failure))) {
18
- return toolEvent(base, { phase: 'error', failure, readBack });
37
+ return toolEvent(base, {
38
+ phase: 'error',
39
+ failure,
40
+ readBack,
41
+ activityPast: failedActivityOf(base),
42
+ });
19
43
  }
20
44
  /** The first event of every call. */
21
- export function toolCallRequestEvent(base, args, { thoughtSignature, stepId } = {}) {
45
+ export function toolCallRequestEvent(base, args, { reasoning, stepId, stepCallCount, } = {}) {
22
46
  return {
23
47
  type: 'tool',
24
48
  tool: {
25
49
  name: base.name,
26
50
  callId: base.callId,
51
+ ...(base.operationId ? { operationId: base.operationId } : {}),
27
52
  arguments: args,
28
- ...(thoughtSignature ? { thoughtSignature } : {}),
53
+ ...(reasoning?.length ? { reasoning } : {}),
29
54
  ...(stepId ? { stepId } : {}),
55
+ ...(stepCallCount ? { stepCallCount } : {}),
30
56
  },
31
57
  };
32
58
  }
@@ -54,11 +80,11 @@ export function* sourceEvents(base, sources, output) {
54
80
  listed = sources(output);
55
81
  }
56
82
  catch (err) {
57
- yield sourcesInvalid(base, `sources threw: ${messageOf(err)}`); // lexicon-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
83
+ yield sourcesInvalid(base, `sources threw: ${messageOf(err)}`); // labels-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
58
84
  return;
59
85
  }
60
86
  if (!Array.isArray(listed)) {
61
- yield sourcesInvalid(base, 'sources must return an array'); // lexicon-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
87
+ yield sourcesInvalid(base, 'sources must return an array'); // labels-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
62
88
  return;
63
89
  }
64
90
  const cited = [];
@@ -71,30 +97,39 @@ export function* sourceEvents(base, sources, output) {
71
97
  invalid.push(`[${String(index)}] ${parsed.error.issues.map((i) => `${i.path.join('.') || 'source'}: ${i.message}`).join('; ')}`);
72
98
  });
73
99
  if (invalid.length > 0) {
74
- yield sourcesInvalid(base, `sources not cited: ${invalid.join(' | ')}`); // lexicon-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
100
+ yield sourcesInvalid(base, `sources not cited: ${invalid.join(' | ')}`); // labels-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
75
101
  }
76
102
  if (cited.length > 0)
77
103
  yield { type: 'citation', sources: cited, callId: base.callId };
78
104
  }
79
- /** `{ ok: false }` comes after the failure event is emitted, so callers only bail. */
80
- export function* startToolExecution(tool, rawInput, ctx, base) {
105
+ function toolRunningEvent(tool, rawInput, ctx, base) {
81
106
  const edited = ctx.resume?.edited;
82
107
  const activity = fillActivityLabel(tool.labels?.activity, { input: rawInput });
83
- yield toolEvent(base, {
108
+ return toolEvent(base, {
84
109
  phase: 'running',
85
110
  ...(edited ? { edited: { from: edited.from, to: toolCallArguments(rawInput) } } : {}),
86
111
  ...(activity ? { activity } : {}),
87
112
  });
113
+ }
114
+ export async function* dispatchToolBody(tool, input, ctx, base, beginBody) {
115
+ const claim = await beginBody?.(input);
116
+ throwIfAborted(ctx.signal);
117
+ yield toolRunningEvent(tool, input, ctx, base);
118
+ return claim;
119
+ }
120
+ export function startToolExecution(tool, rawInput, ctx) {
88
121
  throwIfAborted(ctx.signal);
89
122
  const parsed = tool.input.safeParse(rawInput);
90
123
  if (!parsed.success) {
91
- yield failureEvent(base, {
92
- code: 'invalid_input',
93
- kind: 'bad_response',
94
- message: 'Tool input validation failed', // lexicon-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
95
- details: parsed.error.flatten(),
96
- });
97
- return { ok: false };
124
+ return {
125
+ ok: false,
126
+ failure: {
127
+ code: 'invalid_input',
128
+ kind: 'bad_response',
129
+ message: labelText('tool.input_invalid', {}, ctx.profile.labels),
130
+ details: parsed.error.flatten(),
131
+ },
132
+ };
98
133
  }
99
134
  return { ok: true, data: parsed.data };
100
135
  }
@@ -1,20 +1,28 @@
1
- import { type LexiconOverrides } from '../../guardrails/lexicon.js';
1
+ import { type ToolBoundary } from '../../guardrails/boundaries.js';
2
+ import { type DetectScope } from '../../guardrails/detect-at.js';
3
+ import { type LabelOverrides } from '../../guardrails/labels.js';
2
4
  import type { SpanHandle, TraceAttributes } from '../../observability/trace-span.js';
3
5
  import { type ToolCallEnd } from '../engine/tool-trace.js';
4
- import { type InjectUnit } from '../stages.js';
6
+ import type { InjectUnit } from '../stages.js';
5
7
  import type { InteractionPart, Profile, TurnEvent } from '../types.js';
8
+ import { type AgentCaller } from './agent.js';
6
9
  import { startToolExecution, type ToolCallBase } from './events.js';
10
+ import type { ToolExecutionCoordinator, ToolOperationClaim, ToolOperationOutcome } from './operation.js';
7
11
  import type { ToolRegistry } from './registry.js';
8
12
  import { type ToolStageSupport } from './stage-run.js';
9
- import type { FunctionToolDef, ModelToolResult, ToolContext, ToolFailure, ToolGate, ToolStreamEvent, TurnToolSnapshot } from './types.js';
13
+ import type { FunctionToolDef, ModelToolResult, RegisteredAgentTool, ToolContext, ToolFailure, ToolGate, TurnToolSnapshot } from './types.js';
10
14
  export { checkPermission, isGateResumeGranted, isResumeContinuation, permissionGranted, } from './permission.js';
15
+ /**
16
+ * The boundary a call of `name` is read at before its tool gets it: none for a provider builtin,
17
+ * whose text the kernel never reads. A call no tool takes is read as a function tool's.
18
+ */
19
+ export declare function toolArgumentsBoundary(tools: ToolRegistry, name: string): ToolBoundary | undefined;
11
20
  /** Invalid entries are dropped. */
12
21
  export declare function coerceToolResultParts(raw: unknown): InteractionPart[] | undefined;
22
+ /** A tool's output without its `parts` key, which carries media the model receives separately; any other value is returned as it is. */
13
23
  export declare function leanToolResultData(output: unknown): unknown;
14
- export declare function yieldHandlerSideEvent(base: ToolCallBase, event: Exclude<ToolStreamEvent, {
15
- kind: 'complete';
16
- }>): Generator<TurnEvent>;
17
- export declare function projectForModel(tool: FunctionToolDef, output: unknown, lexicon?: LexiconOverrides): ModelToolResult;
24
+ /** What the model is told of a function tool's output: a fixed finding for a hidden tool, a finding plus the output for an awaiting-user result, otherwise the tool's own summary or finding and its data. */
25
+ export declare function projectForModel(tool: FunctionToolDef, output: unknown, labels?: LabelOverrides): ModelToolResult;
18
26
  export type ToolExecuteSettlement = {
19
27
  modelResult?: ModelToolResult;
20
28
  gated?: ToolGate;
@@ -32,33 +40,61 @@ export type ToolExecuteSettlement = {
32
40
  /** Landed after the provider tool result is recorded: the Interactions continuation must exist first. */
33
41
  pendingInject?: InjectUnit[];
34
42
  };
35
- export declare function executeFunction(tools: ToolRegistry, tool: FunctionToolDef, rawInput: unknown, ctx: ToolContext, base: ToolCallBase, snapshot?: TurnToolSnapshot, stages?: ToolStageSupport): AsyncGenerator<TurnEvent, ToolExecuteSettlement>;
43
+ export declare function executeFunction(tools: ToolRegistry, tool: FunctionToolDef, rawInput: unknown, ctx: ToolContext, base: ToolCallBase, snapshot?: TurnToolSnapshot, stages?: ToolStageSupport,
44
+ /** Set when `tool` runs an agent tool: its trust, and its handler's failures and faults. */
45
+ agent?: RegisteredAgentTool, beginBody?: (preparedInput: unknown) => Promise<ToolOperationClaim | undefined>): AsyncGenerator<TurnEvent, ToolExecuteSettlement>;
46
+ /** Names the profile's loader when it can load the tool, so the model knows which call comes first. */
36
47
  export declare function notLoadedMessage(tool: {
37
48
  name: string;
38
49
  loadTier?: string;
39
- }, lexicon?: LexiconOverrides): string;
50
+ }, profile: Profile): string;
40
51
  export declare function executeBuiltin(tool: {
41
52
  name: string;
42
53
  }, ctx: ToolContext, base: ToolCallBase, snapshot: TurnToolSnapshot): AsyncGenerator<TurnEvent, ToolExecuteSettlement>;
54
+ export declare function authorizeToolReplay(args: {
55
+ tools: ToolRegistry;
56
+ profile: Profile;
57
+ name: string;
58
+ resume: ToolContext['resume'];
59
+ snapshot?: TurnToolSnapshot;
60
+ outcome?: ToolOperationOutcome;
61
+ }): void;
43
62
  interface RegisteredToolCall {
63
+ execution?: ToolExecutionCoordinator;
64
+ invocation?: unknown;
65
+ onDispatch?: () => void;
66
+ beginBody?: (preparedInput: unknown) => Promise<ToolOperationClaim | undefined>;
44
67
  tools: ToolRegistry;
45
68
  profile: Profile;
46
69
  name: string;
47
70
  input: unknown;
48
71
  callId: string;
49
- ctx: Omit<ToolContext, 'callId' | 'profile'>;
72
+ ctx: Omit<ToolContext, 'callId' | 'profile' | 'operationId'> & {
73
+ operationId?: string;
74
+ };
50
75
  snapshot?: TurnToolSnapshot;
51
76
  stages?: ToolStageSupport;
52
77
  /** Omitted: the call is not traced. The span is handed to the tool as `ctx.traceparent`. */
53
78
  openSpan?: (name: string, attributes: TraceAttributes) => SpanHandle;
54
79
  /** Defaults to `turnReadBack`; a transport that sends something else (Live's `functionResponse`) passes its own. */
55
80
  readBack?: (settlement: ToolExecuteSettlement) => ToolCallEnd['result'];
81
+ /** Runs agent tool calls; without it an agent tool fails as a type the transport can't run. */
82
+ agents?: AgentCaller;
83
+ /** The canary and system instruction of the turn the model called from, read for in the arguments. */
84
+ scope?: DetectScope;
56
85
  }
57
86
  /**
58
87
  * A gate nobody answered: a sign-in for `expiredService` whose link expired, or any other gate
59
88
  * left behind. Both settle as `cancelled`.
60
89
  */
61
- export declare function lapsedGateFailure(toolName: string, expiredService: string | undefined, lexicon: LexiconOverrides | undefined): ToolFailure;
90
+ export declare function lapsedGateFailure(toolName: string, expiredService: string | undefined, labels: LabelOverrides | undefined): ToolFailure;
91
+ /** Runs one registered tool call as a stream of turn events and returns how it settled; when `openSpan` is given the call is recorded as a tool span that ends with the outcome. */
92
+ /**
93
+ * A call's arguments as its tool gets them, which is what the call's first
94
+ * event shows the host: a detector's placeholder where it redacts, and none
95
+ * when the call is stopped. A call no tool takes is read as a function tool's.
96
+ */
97
+ export declare function shownToolArguments(call: Pick<RegisteredToolCall, 'tools' | 'profile' | 'name' | 'input' | 'scope'>): Record<string, unknown>;
62
98
  export declare function executeRegisteredTool(args: RegisteredToolCall): AsyncGenerator<TurnEvent, ToolExecuteSettlement>;
63
99
  export type { RegisteredToolCall, ToolStageSupport };
64
100
  export { startToolExecution };