@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
@@ -61,19 +61,23 @@ export function historyToolArguments(raw) {
61
61
  export function toolCallEvents(call, rawArguments) {
62
62
  const name = call.name.trim();
63
63
  const base = { name, callId: call.id ?? newCallId(name) };
64
+ const request = {
65
+ stepId: call.stepId,
66
+ stepCallCount: call.stepCallCount,
67
+ };
64
68
  if (!name) {
65
- return malformedToolCall(base, 'function call is missing a name', rawArguments, call.thoughtSignature);
69
+ return malformedToolCall(base, 'function call is missing a name', rawArguments, request);
66
70
  }
67
71
  const parsed = parseToolArgumentsObject(rawArguments);
68
72
  if (!parsed.ok) {
69
- return malformedToolCall(base, parsed.error, parsed.raw, call.thoughtSignature);
73
+ return malformedToolCall(base, parsed.error, parsed.raw, request);
70
74
  }
71
- return [toolCallRequestEvent(base, parsed.value, { thoughtSignature: call.thoughtSignature })];
75
+ return [toolCallRequestEvent(base, parsed.value, request)];
72
76
  }
73
- /** Keeps the thought signature: the model still reads the failed call's result back. */
74
- export function malformedToolCall(base, message, raw, thoughtSignature) {
77
+ /** The model still reads the failed call's result back. */
78
+ export function malformedToolCall(base, message, raw, request = {}) {
75
79
  return [
76
- toolCallRequestEvent(base, {}, { thoughtSignature }),
80
+ toolCallRequestEvent(base, {}, request),
77
81
  failureEvent(base, {
78
82
  code: 'malformed_arguments',
79
83
  kind: 'bad_response',
@@ -0,0 +1,16 @@
1
+ import type { ModelEvent } from '../../kernel/types.js';
2
+ /** A tool call a provider is streaming: its id and name as far as they have come, and its arguments' text. */
3
+ export interface StreamingToolCall {
4
+ id?: string;
5
+ name: string;
6
+ args: string;
7
+ /** How much of `args` has gone out as `tool_draft` events. */
8
+ drafted?: number;
9
+ }
10
+ /**
11
+ * The `tool_draft` event for what `call.args` has gained since it last drafted, and advances
12
+ * `call.drafted`. Nothing until the call has an id and a name: the call is emitted under that id,
13
+ * and its draft is joined to it by that id alone. Whatever came before then goes out in the first
14
+ * draft.
15
+ */
16
+ export declare function toolDraftEvents(call: StreamingToolCall): ModelEvent[];
@@ -0,0 +1,14 @@
1
+ /**
2
+ * The `tool_draft` event for what `call.args` has gained since it last drafted, and advances
3
+ * `call.drafted`. Nothing until the call has an id and a name: the call is emitted under that id,
4
+ * and its draft is joined to it by that id alone. Whatever came before then goes out in the first
5
+ * draft.
6
+ */
7
+ export function toolDraftEvents(call) {
8
+ const name = call.name.trim();
9
+ const from = call.drafted ?? 0;
10
+ if (!(call.id && name) || call.args.length <= from)
11
+ return [];
12
+ call.drafted = call.args.length;
13
+ return [{ type: 'tool_draft', callId: call.id, name, text: call.args.slice(from) }];
14
+ }
@@ -1,8 +1,8 @@
1
- import type { KeySlot, ProviderCompleteRequest } from '../../kernel/types.js';
1
+ import type { KeySlot, ModelRequest } from '../../kernel/types.js';
2
2
  export declare function tapeHeaderValue(key: string, value: string): string;
3
3
  export declare function tapeHeaders(headers?: HeadersInit): Record<string, string>;
4
4
  export declare function throwRow(err: unknown): Record<string, unknown>;
5
- export declare function tapFetch(tap: ProviderCompleteRequest['tapUpstream'], send?: typeof fetch, keySlot?: KeySlot): typeof fetch;
5
+ export declare function tapFetch(tap: ModelRequest['tapUpstream'], send?: typeof fetch, keySlot?: KeySlot): typeof fetch;
6
6
  /** fetch rejects only when no response came back, so any non-abort, non-timeout rejection is `network`. */
7
7
  export declare function networkError(err: unknown): unknown;
8
8
  export declare function networkFetch(send?: typeof fetch): typeof fetch;
@@ -1,7 +1,7 @@
1
1
  import { redactCanaryText } from '../../guardrails/canary.js';
2
2
  import { sha256, sha256Base64 } from '../../kernel/engine/hash.js';
3
3
  import { mapStrings } from '../../kernel/engine/tree.js';
4
- /*
4
+ /*invariant:
5
5
  * Inline bytes on a taped row are stored as their sha256, never as bytes.
6
6
  * The shapes are the ones every taped transport sends (probes 23/09/2026):
7
7
  *
@@ -0,0 +1,8 @@
1
+ import { type Protocol } from '../../kernel/protocols/mod.js';
2
+ /** What a System One binding may set. Both are TypeSafe's opt-in "danger zone" headers. */
3
+ export interface SystemOneOptions {
4
+ images?: boolean;
5
+ longContext?: boolean;
6
+ }
7
+ /** TypeSafe's decision API: questions about a state, answered in one call. */
8
+ export declare const systemOne: Protocol<SystemOneOptions>;
@@ -0,0 +1,93 @@
1
+ import { z } from 'zod';
2
+ import { TheoremError } from '../../guardrails/error.js';
3
+ import { labelText } from '../../guardrails/labels.js';
4
+ import { jsonObjectSchema } from '../../kernel/json.js';
5
+ import { defineProtocol } from '../../kernel/protocols/mod.js';
6
+ const count = z.number().int().nonnegative();
7
+ const reply = z.object({
8
+ model: z.string().min(1),
9
+ answers: z.record(z.string(), z.unknown()),
10
+ usage: z
11
+ .object({
12
+ input_tokens: count,
13
+ output_tokens: count,
14
+ cost: z.number().nonnegative().optional(),
15
+ })
16
+ .optional()
17
+ .catch(undefined),
18
+ });
19
+ const options = z.strictObject({
20
+ images: z.boolean().optional().describe(
21
+ // labels-exempt: builder field description, read by the studio and docs
22
+ 'Let a decision hold images and box questions. TypeSafe calls this experimental, and a request that uses either is refused without it.'),
23
+ longContext: z.boolean().optional().describe(
24
+ // labels-exempt: builder field description, read by the studio and docs
25
+ 'Raise the context window from 64k tokens to 262k. TypeSafe calls this slower and less accurate.'),
26
+ });
27
+ const IMAGES_HEADER = 'TypeSafe-Danger-Zone-Images';
28
+ const LONG_CONTEXT_HEADER = 'TypeSafe-Danger-Zone-Long-Context';
29
+ /** TypeSafe's decision API: questions about a state, answered in one call. */
30
+ export const systemOne = defineProtocol({
31
+ id: 'systemOne',
32
+ name: 'System One',
33
+ description: "TypeSafe's decision API: questions about a state, answered in one call.", // labels-exempt: builder field description, read by the studio and docs
34
+ endpoints: { decision: '/systemone' },
35
+ options,
36
+ create(context) {
37
+ return {
38
+ async decide(request) {
39
+ const asksBox = Object.values(request.questions).some(({ type }) => type === 'box');
40
+ const holdsImages = asksBox || (request.assets && Object.keys(request.assets).length > 0);
41
+ if (holdsImages && !context.options.images)
42
+ throw new TheoremError('unsupported', labelText('provider.decision_images_off'));
43
+ // why: Only a pinned 1.13 is known to refuse a box; aliases such as `jev-latest` move, so they pass.
44
+ if (asksBox && /^jev-1\.13(\.|$)/.test(context.apiId))
45
+ throw new TheoremError('unsupported', labelText('provider.decision_box_model', { apiId: context.apiId }));
46
+ const headers = {};
47
+ if (holdsImages)
48
+ headers[IMAGES_HEADER] = 'true';
49
+ if (context.options.longContext)
50
+ headers[LONG_CONTEXT_HEADER] = 'true';
51
+ const body = jsonObjectSchema.parse({
52
+ model: context.apiId,
53
+ state: request.state,
54
+ questions: request.questions,
55
+ ...(request.assets && Object.keys(request.assets).length
56
+ ? { assets: assetsOnWire(request.assets) }
57
+ : {}),
58
+ });
59
+ for await (const row of context.send(body, { stream: false, headers })) {
60
+ const parsed = reply.safeParse(row);
61
+ if (!parsed.success)
62
+ throw new TheoremError('bad_response', labelText('protocol.reply_shape', {
63
+ protocol: 'systemOne',
64
+ issues: z.prettifyError(parsed.error),
65
+ }));
66
+ const { model, answers, usage } = parsed.data;
67
+ // invariant: The kernel validates every answer against its question before exposing it.
68
+ return {
69
+ model,
70
+ answers: answers,
71
+ ...(usage
72
+ ? {
73
+ usage: {
74
+ inputTokens: usage.input_tokens,
75
+ outputTokens: usage.output_tokens,
76
+ ...(usage.cost === undefined ? {} : { costUsd: usage.cost }),
77
+ },
78
+ }
79
+ : {}),
80
+ };
81
+ }
82
+ throw new TheoremError('bad_response', labelText('provider.decision_failed'));
83
+ },
84
+ };
85
+ },
86
+ });
87
+ const FORMATS = { 'image/png': 'png', 'image/jpeg': 'jpeg' };
88
+ function assetsOnWire(assets) {
89
+ return Object.fromEntries(Object.entries(assets).map(([reference, { mimeType, data }]) => [
90
+ reference,
91
+ { type: 'image', format: FORMATS[mimeType], data_base64: data },
92
+ ]));
93
+ }
@@ -1,19 +1,51 @@
1
- import type { KeyVault } from '../kernel/types.js';
2
- export interface OpenAiGatewayConfig {
3
- baseUrl?: string;
4
- siteUrl?: string;
5
- siteName?: string;
6
- fetch?: typeof fetch;
1
+ import type { TheoremError } from '../guardrails/error.js';
2
+ import type { InteractionPart, ModelEvent } from '../kernel/types.js';
3
+ /** Where a live model is in its reply when a frame arrives. */
4
+ export type LiveTurnPhase = 'streaming' | 'complete' | 'abort';
5
+ /** Tape row: the first key was refused for quota, so the call starts again on the fallback slot. */
6
+ export declare const KEY_FALLBACK_ROW = "key_fallback";
7
+ /** The provider's warning before it closed a live socket. */
8
+ export interface LiveGoAway {
9
+ timeLeftMs?: number;
10
+ /** Milliseconds from the last warning to the close. */
11
+ closedAfterMs: number;
7
12
  }
8
- export interface LocalProviderConfig {
9
- /** e.g. `http://127.0.0.1:11434` for Ollama. */
10
- baseUrl: string;
11
- fetch?: typeof globalThis.fetch;
13
+ /** One thing a live socket received. `row` is the parsed frame, so the kernel records it beside the events it produced. */
14
+ export type LiveQueueItem = {
15
+ type: 'batch';
16
+ events: ModelEvent[];
17
+ turnPhase: LiveTurnPhase;
18
+ row: Record<string, unknown>;
19
+ } | {
20
+ type: 'row';
21
+ row: Record<string, unknown>;
22
+ } | {
23
+ type: 'error';
24
+ error: Error;
25
+ row?: Record<string, unknown>;
12
26
  }
13
- /** What `createProvider` hands an adapter: the host's settings for it plus the one vault. */
14
- export type OpenAiGatewayTransport = OpenAiGatewayConfig & {
15
- vault?: KeyVault;
16
- };
17
- export type LocalTransport = LocalProviderConfig & {
18
- vault?: KeyVault;
27
+ /** `error` is set when the close was not normal; `goAway` when the provider warned first. */
28
+ | {
29
+ type: 'closed';
30
+ code: number;
31
+ reason: string;
32
+ error?: TheoremError;
33
+ goAway?: LiveGoAway;
19
34
  };
35
+ /**
36
+ * An open live socket, in the kernel's terms: the setup the session was opened with, what the
37
+ * session sends the model, `batches` for what it receives, and `close`. A send on a socket that is
38
+ * no longer open is dropped.
39
+ */
40
+ export interface LiveConnection {
41
+ readonly setup: Record<string, unknown>;
42
+ flush?(): Promise<void>;
43
+ /** Text the model reads without it ending the user's turn. */
44
+ sendContext(text: string): void;
45
+ /** Text, audio, or video from the user, as it arrives. */
46
+ sendInput(input: InteractionPart): void;
47
+ /** The result of a tool call the model made. */
48
+ sendToolResponse(callId: string, name: string, output: unknown, parts?: InteractionPart[]): void;
49
+ batches(): AsyncGenerator<LiveQueueItem>;
50
+ close(code?: number, reason?: string): void;
51
+ }
@@ -1 +1,2 @@
1
- export {};
1
+ /** Tape row: the first key was refused for quota, so the call starts again on the fallback slot. */
2
+ export const KEY_FALLBACK_ROW = 'key_fallback';
@@ -0,0 +1,7 @@
1
+ import { type Provider } from '../../kernel/protocols/provider.js';
2
+ /** What registering `typesafeProvider` takes as `connection`. */
3
+ export interface TypesafeConnection {
4
+ baseUrl?: string;
5
+ }
6
+ /** TypeSafe: System One decisions, at TypeSafe's own API. */
7
+ export declare const typesafeProvider: Provider<TypesafeConnection, string>;
@@ -0,0 +1,24 @@
1
+ import { z } from 'zod';
2
+ import { bearer, defineProvider, endpointUrlSchema, } from '../../kernel/protocols/provider.js';
3
+ import { systemOne } from '../system-one/protocol.js';
4
+ /** TypeSafe: System One decisions, at TypeSafe's own API. */
5
+ export const typesafeProvider = defineProvider({
6
+ id: 'typesafe',
7
+ name: 'TypeSafe',
8
+ description: "System One decisions, at TypeSafe's own API.", // labels-exempt: builder field description, read by the studio and docs
9
+ connection: z
10
+ .strictObject({
11
+ baseUrl: endpointUrlSchema
12
+ .optional()
13
+ .describe('The API, by default https://api.typesafe.ai/v1.'), // labels-exempt: builder field description, read by the studio and docs
14
+ })
15
+ .default({}),
16
+ key: z.string().trim().min(1),
17
+ authorize: bearer(),
18
+ // why: docs.typesafe.ai/models, read 2026-10-19, prices Jev 1.13 and 1.14 alike at $0.042 per million input tokens, output free. The API reports no cost.
19
+ prices: {
20
+ checked: '2026-10-19',
21
+ models: { 'jev-*': { input: 0.042, output: 0 } },
22
+ },
23
+ serves: (at) => [{ protocol: systemOne, baseUrl: at.baseUrl ?? 'https://api.typesafe.ai/v1' }],
24
+ });
@@ -1,3 +1,5 @@
1
+ /** What stands in for a credential's value wherever one is shown. */
2
+ export declare const MASK = "\u2022\u2022\u2022\u2022";
1
3
  /** What an agent sees of a secret. */
2
4
  export interface SecretCard {
3
5
  secret: true;
@@ -9,12 +11,28 @@ export interface SecretCard {
9
11
  sameAs: string[];
10
12
  usedBy: string[];
11
13
  }
14
+ /** What an agent sees of a secret instead of its value: whether it is set, what kind it looks like, the mistakes it shows, and the other secrets with the same value and the places that use it. */
12
15
  export declare function secretCard(value: unknown, extra?: {
13
16
  sameAs?: readonly string[];
14
17
  usedBy?: readonly string[];
15
18
  }): SecretCard;
16
- /** A URL with its credential query parameters and `user:pass@` masked. */
19
+ /** Whether a header or query parameter's name says it carries a credential: what `maskHeaders` masks. */
20
+ export declare function isCredentialName(name: string): boolean;
21
+ /**
22
+ * A URL with its credential query parameters and `user:pass@` masked. The rest stays as written:
23
+ * a `{param}` in a tool's path is not encoded.
24
+ */
17
25
  export declare function maskUrl(raw: string): string;
26
+ /**
27
+ * A masked URL with each masked credential filled in from `held`, the URL it was masked from.
28
+ * A mask `held` has no value for stays a mask.
29
+ */
30
+ export declare function unmaskUrl(shown: string, held: string): string;
31
+ /**
32
+ * Masked headers with each masked value filled in from `held`, the headers they were masked from.
33
+ * A mask `held` has no header for stays a mask.
34
+ */
35
+ export declare function unmaskHeaders(shown: Record<string, string>, held: Record<string, string> | undefined): Record<string, string>;
18
36
  /**
19
37
  * Headers as JSON, credential-named values masked. Text that is not a JSON object is
20
38
  * told only by its length: a parse error would quote it.
@@ -1,6 +1,7 @@
1
- import { sensitiveSpans } from '../guardrails/sensitive.js';
2
- import { applySpans } from '../observability/spans.js';
3
- const MASK = '••••';
1
+ import { redactDetectors } from '../guardrails/detect-at.js';
2
+ import { SENSITIVE_GROUPS } from '../guardrails/sensitive-groups.js';
3
+ /** What stands in for a credential's value wherever one is shown. */
4
+ export const MASK = '••••';
4
5
  /** Names that carry a credential, in a URL's query or a header. */
5
6
  const CREDENTIAL_NAME = /auth|key|token|secret|passw|pwd|cookie|session|signature|^sig$|credential|^code$|appid/i;
6
7
  /** Names a query parameter carries a credential under, in a URL too malformed to parse. */
@@ -23,6 +24,7 @@ const SHORT = 16;
23
24
  const SCRUB_MIN = 6;
24
25
  const TEXT_CAP = 2000;
25
26
  const BYTES_CAP = 200;
27
+ /** What an agent sees of a secret instead of its value: whether it is set, what kind it looks like, the mistakes it shows, and the other secrets with the same value and the places that use it. */
26
28
  export function secretCard(value, extra = {}) {
27
29
  const text = typeof value === 'string' ? value : '';
28
30
  const core = text.trim();
@@ -52,31 +54,71 @@ export function secretCard(value, extra = {}) {
52
54
  usedBy: [...(extra.usedBy ?? [])],
53
55
  };
54
56
  }
55
- /** A URL with its credential query parameters and `user:pass@` masked. */
56
- export function maskUrl(raw) {
57
- let url;
57
+ /** A URL's `user:pass@`, after its scheme. */
58
+ const USERINFO = /^([a-z][a-z0-9+.-]*:\/\/)([^/?#@]*)@/i;
59
+ /** One `name=value` of a URL, with the separator before it. */
60
+ const PAIR = /([?&;])([^=?&;#\s]*)=([^&;#\s]*)/g;
61
+ /** A `user:pass`, as its two parts. A password keeps its own colons. */
62
+ function userinfo(text) {
63
+ const at = text.indexOf(':');
64
+ return at < 0 ? [text, undefined] : [text.slice(0, at), text.slice(at + 1)];
65
+ }
66
+ function decoded(name) {
58
67
  try {
59
- url = new URL(raw);
68
+ return decodeURIComponent(name);
60
69
  }
61
70
  catch {
62
- return raw.replace(/[?&;][^?&;#\s]*/g, (pair) => {
63
- const at = pair.indexOf('=');
64
- const name = pair.slice(1, at);
65
- return at > 1 && at < pair.length - 1 && QUERY_CREDENTIAL.test(name)
66
- ? `${pair.slice(0, at + 1)}${MASK}`
67
- : pair;
68
- });
71
+ return name;
69
72
  }
70
- const credentials = [...new Set(url.searchParams.keys())].filter((name) => CREDENTIAL_NAME.test(name));
71
- if (!url.username && !url.password && credentials.length === 0)
72
- return raw;
73
- if (url.username)
74
- url.username = MASK;
75
- if (url.password)
76
- url.password = MASK;
77
- for (const name of credentials)
78
- url.searchParams.set(name, MASK);
79
- return url.href.replaceAll(encodeURIComponent(MASK), MASK);
73
+ }
74
+ /** Whether a header or query parameter's name says it carries a credential: what `maskHeaders` masks. */
75
+ export function isCredentialName(name) {
76
+ return CREDENTIAL_NAME.test(name);
77
+ }
78
+ /**
79
+ * A URL with its credential query parameters and `user:pass@` masked. The rest stays as written:
80
+ * a `{param}` in a tool's path is not encoded.
81
+ */
82
+ export function maskUrl(raw) {
83
+ const names = URL.canParse(raw) ? CREDENTIAL_NAME : QUERY_CREDENTIAL;
84
+ return raw
85
+ .replace(USERINFO, (_whole, scheme, info) => {
86
+ const [user, password] = userinfo(info);
87
+ return `${scheme}${user && MASK}${password === undefined ? '' : `:${password && MASK}`}@`;
88
+ })
89
+ .replace(PAIR, (pair, separator, name, value) => value && names.test(decoded(name)) ? `${separator}${name}=${MASK}` : pair);
90
+ }
91
+ /**
92
+ * A masked URL with each masked credential filled in from `held`, the URL it was masked from.
93
+ * A mask `held` has no value for stays a mask.
94
+ */
95
+ export function unmaskUrl(shown, held) {
96
+ const [user, password] = userinfo(USERINFO.exec(held)?.[2] ?? '');
97
+ const values = new Map();
98
+ for (const [, , name = '', value = ''] of held.matchAll(PAIR)) {
99
+ values.set(name, [...(values.get(name) ?? []), value]);
100
+ }
101
+ return shown
102
+ .replace(USERINFO, (_whole, scheme, info) => {
103
+ const [shownUser, shownPassword] = userinfo(info);
104
+ const name = shownUser === MASK && user ? user : shownUser;
105
+ const pass = shownPassword === MASK && password ? password : shownPassword;
106
+ return `${scheme}${name}${pass === undefined ? '' : `:${pass}`}@`;
107
+ })
108
+ .replace(PAIR, (pair, separator, name, value) => {
109
+ const real = value === MASK ? values.get(name)?.shift() : undefined;
110
+ return real ? `${separator}${name}=${real}` : pair;
111
+ });
112
+ }
113
+ /**
114
+ * Masked headers with each masked value filled in from `held`, the headers they were masked from.
115
+ * A mask `held` has no header for stays a mask.
116
+ */
117
+ export function unmaskHeaders(shown, held) {
118
+ return Object.fromEntries(Object.entries(shown).map(([name, value]) => [
119
+ name,
120
+ value === MASK ? (held?.[name] ?? value) : value,
121
+ ]));
80
122
  }
81
123
  /**
82
124
  * Headers as JSON, credential-named values masked. Text that is not a JSON object is
@@ -97,10 +139,7 @@ export function maskHeaders(raw) {
97
139
  if (typeof headers !== 'object' || headers === null || Array.isArray(headers)) {
98
140
  return '(not a JSON object)';
99
141
  }
100
- const masked = Object.fromEntries(Object.entries(headers).map(([name, value]) => [
101
- name,
102
- CREDENTIAL_NAME.test(name) ? MASK : value,
103
- ]));
142
+ const masked = Object.fromEntries(Object.entries(headers).map(([name, value]) => [name, isCredentialName(name) ? MASK : value]));
104
143
  return typeof raw === 'string' ? JSON.stringify(masked) : masked;
105
144
  }
106
145
  /** Scrubs text: each known secret value by name, then the kernel's sensitive patterns. */
@@ -110,7 +149,7 @@ export function scrubText(text, known) {
110
149
  if (value.length >= SCRUB_MIN)
111
150
  out = out.replaceAll(value, `[secret ${name}]`);
112
151
  }
113
- return applySpans(out, sensitiveSpans(out));
152
+ return redactDetectors(out, SENSITIVE_GROUPS);
114
153
  }
115
154
  /** Known secret values worth scrubbing: trimmed, long enough, longest first. */
116
155
  export function knownSecrets(secrets) {
@@ -2,13 +2,15 @@
2
2
  * Surfaces: one protocol for an agent to see and work in a client's screen. A page mounts a
3
3
  * surface (nodes with fields and actions); the agent uses two tools, `look` and `act`, and the
4
4
  * runtime projects every answer so secrets reach it only as cards.
5
+ *
6
+ * @module
5
7
  */
6
8
  import "../../_dnt.polyfills.js";
7
9
  export type { SecretCard } from './formats.js';
8
- export { knownSecrets, maskHeaders, maskUrl, scrubDeep, scrubText, secretCard } from './formats.js';
10
+ export { isCredentialName, knownSecrets, MASK, maskHeaders, maskUrl, scrubDeep, scrubText, secretCard, unmaskHeaders, unmaskUrl, } from './formats.js';
9
11
  export type { SurfaceLedgerEntry, SurfaceRuntime, SurfaceRuntimeOptions, } from './runtime.js';
10
12
  export { createSurfaceRuntime, SURFACE_TOOL_NAMES } from './runtime.js';
11
13
  export type { SurfaceToolsOptions } from './tools.js';
12
- export { clientAnsweredHandler, SURFACE_PROMPT, surfaceTools } from './tools.js';
14
+ export { SURFACE_PROMPT, surfaceTools } from './tools.js';
13
15
  export type { Surface, SurfaceAction, SurfaceActionContext, SurfaceActionOutcome, SurfaceAuthor, SurfaceChange, SurfaceEffect, SurfaceField, SurfaceFieldFormat, SurfaceIssue, SurfaceNode, SurfaceRejection, } from './types.js';
14
16
  export { defineAction } from './types.js';
@@ -2,9 +2,11 @@
2
2
  * Surfaces: one protocol for an agent to see and work in a client's screen. A page mounts a
3
3
  * surface (nodes with fields and actions); the agent uses two tools, `look` and `act`, and the
4
4
  * runtime projects every answer so secrets reach it only as cards.
5
+ *
6
+ * @module
5
7
  */
6
8
  import "../../_dnt.polyfills.js";
7
- export { knownSecrets, maskHeaders, maskUrl, scrubDeep, scrubText, secretCard } from './formats.js';
9
+ export { isCredentialName, knownSecrets, MASK, maskHeaders, maskUrl, scrubDeep, scrubText, secretCard, unmaskHeaders, unmaskUrl, } from './formats.js';
8
10
  export { createSurfaceRuntime, SURFACE_TOOL_NAMES } from './runtime.js';
9
- export { clientAnsweredHandler, SURFACE_PROMPT, surfaceTools } from './tools.js';
11
+ export { SURFACE_PROMPT, surfaceTools } from './tools.js';
10
12
  export { defineAction } from './types.js';
@@ -10,6 +10,7 @@ export interface SurfaceLedgerEntry {
10
10
  result: unknown;
11
11
  time: number;
12
12
  }
13
+ /** Options for a surface runtime: the clock, how to open a declared surface, where notes go and where the ledger is kept. */
13
14
  export interface SurfaceRuntimeOptions {
14
15
  now?: () => number;
15
16
  /** Opens a declared surface that isn't mounted (goes to its page). */
@@ -23,6 +24,7 @@ export interface SurfaceRuntimeOptions {
23
24
  save(entries: readonly SurfaceLedgerEntry[]): void;
24
25
  };
25
26
  }
27
+ /** What the host holds to mount surfaces and answer the agent's `look` and `act` calls. */
26
28
  export interface SurfaceRuntime {
27
29
  /** Mounts a surface until the returned function is called. */
28
30
  mount(surface: Surface): () => void;
@@ -36,5 +38,7 @@ export interface SurfaceRuntime {
36
38
  /** Where every mounted surface stands and what the agent last did; `null` when there is nothing. */
37
39
  stateLine(): string | null;
38
40
  }
41
+ /** The tools the runtime answers: `look` and `act`. */
39
42
  export declare const SURFACE_TOOL_NAMES: readonly ["look", "act"];
43
+ /** Creates a runtime that mounts surfaces and answers the agent's `look` and `act` calls. */
40
44
  export declare function createSurfaceRuntime(options?: SurfaceRuntimeOptions): SurfaceRuntime;
@@ -6,6 +6,7 @@ const INTENT_WINDOW_MS = 60_000;
6
6
  const MOUNT_WAIT_MS = 5000;
7
7
  const NODE_LIST_CAP = 80;
8
8
  const RECENT_IN_STATE = 5;
9
+ /** The tools the runtime answers: `look` and `act`. */
9
10
  export const SURFACE_TOOL_NAMES = ['look', 'act'];
10
11
  const lookArgs = z.object({ at: z.string().optional() });
11
12
  const actArgs = z.object({
@@ -47,6 +48,7 @@ function rejectionsFrom(error) {
47
48
  function errorText(err) {
48
49
  return err instanceof Error ? err.message : String(err);
49
50
  }
51
+ /** Creates a runtime that mounts surfaces and answers the agent's `look` and `act` calls. */
50
52
  export function createSurfaceRuntime(options = {}) {
51
53
  const now = options.now ?? Date.now;
52
54
  const mounted = new Map();
@@ -1,11 +1,5 @@
1
- import type { ToolContext, ToolDefinitionInput } from '../kernel/tools/types.js';
2
- /**
3
- * The handler for a function tool the client answers: it returns what the client sent back for
4
- * the call, which the relay bridge hands over as `ctx.host.clientOutput`. With no output the call
5
- * fails to the model, naming the tool; so does a call the bridge settled because the client never
6
- * answered (`host.clientTimedOut`).
7
- */
8
- export declare function clientAnsweredHandler(name: string): (input: unknown, ctx: ToolContext) => unknown;
1
+ import type { ToolDefinitionInput } from '../kernel/tools/types.js';
2
+ /** Options for `surfaceTools`: the category the tools are registered under, `surface` by default. */
9
3
  export interface SurfaceToolsOptions {
10
4
  category?: string;
11
5
  }
@@ -1,27 +1,10 @@
1
1
  import { z } from 'zod';
2
- /**
3
- * The handler for a function tool the client answers: it returns what the client sent back for
4
- * the call, which the relay bridge hands over as `ctx.host.clientOutput`. With no output the call
5
- * fails to the model, naming the tool; so does a call the bridge settled because the client never
6
- * answered (`host.clientTimedOut`).
7
- */
8
- export function clientAnsweredHandler(name) {
9
- return (_input, ctx) => {
10
- const host = ctx.host;
11
- if (host && 'clientOutput' in host)
12
- return host.clientOutput;
13
- if (host?.clientTimedOut) {
14
- throw new Error("The page didn't answer. Look before trying again.");
15
- }
16
- throw new Error(`${name} runs in the client, and the client sent no result.`);
17
- };
18
- }
19
2
  const answer = z.record(z.string(), z.unknown());
20
3
  const lookInput = z.object({
21
4
  at: z
22
5
  .string()
23
6
  .optional()
24
- .describe('A surface ("playground") or a node in one ("playground/identity"); leave out to see every surface'),
7
+ .describe('A surface ("studio") or a node in one ("studio/identity"); leave out to see every surface'),
25
8
  });
26
9
  const actInput = z.object({
27
10
  at: z.string().describe('The node to act on, as look names it'),
@@ -49,23 +32,22 @@ export function surfaceTools(options = {}) {
49
32
  loadTier: 'T0',
50
33
  permission: 'auto',
51
34
  output: answer,
35
+ answeredBy: 'page',
52
36
  };
53
37
  return [
54
38
  {
55
39
  ...base,
56
40
  name: 'look',
57
- description: "See what is on the person's screen. With no `at`: every surface, its revision, summary, nodes and issue counts. With `at`: that node's fields (secrets only as cards: set, what it looks like, problems), what each means, its issues, its actions with their input schemas, and its children.",
41
+ description: "See what is on the person's screen. With no `at`: every surface, its revision, summary, nodes, and issue counts. With `at`: that node's fields (secrets only as cards: set, what it looks like, problems), what each means, its issues, its actions with their input schemas, and its children.",
58
42
  access: 'read-only',
59
43
  input: lookInput,
60
- handler: clientAnsweredHandler('look'),
61
44
  },
62
45
  {
63
46
  ...base,
64
47
  name: 'act',
65
- description: "Do one of a node's actions: `set` fields, `point` the person at something, or the node's own (test, send, launch…). Comes back applied, unchanged, done, stale (the page changed: look again), refused or failed, with what was rejected and why.",
48
+ description: "Do one of a node's actions: `set` fields, `point` the person at something, or the node's own (test, send, launch…). Comes back applied, unchanged, done, stale (the page changed: look again), refused, or failed, with what was rejected and why.",
66
49
  access: 'read-write',
67
50
  input: actInput,
68
- handler: clientAnsweredHandler('act'),
69
51
  },
70
52
  ];
71
53
  }