@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
@@ -1,7 +1,8 @@
1
- // A key with no entry is still a real attribute: viewers show it under its raw name.
1
+ // invariant: A key with no entry is still a real attribute: viewers show it under its raw name.
2
+ /** Labels and descriptions for each attribute group. */
2
3
  const TRACE_ATTRIBUTE_GROUPS = {
3
4
  agent: { label: 'Agent', doc: 'Which agent ran, for which conversation, and how it ended.' },
4
- request: { label: 'Request', doc: 'What THEOREM asked the provider for.' },
5
+ request: { label: 'Request', doc: 'What theorem asked the provider for.' },
5
6
  response: { label: 'Response', doc: 'What the provider said about its answer.' },
6
7
  messages: { label: 'Messages', doc: 'What was read and written, stored by hash.' },
7
8
  usage: { label: 'Usage', doc: 'Tokens and cost, as reported or estimated.' },
@@ -16,6 +17,7 @@ const TRACE_ATTRIBUTE_GROUPS = {
16
17
  },
17
18
  evaluation: { label: 'Evaluation', doc: 'How an eval graded this trace, and by which suite.' },
18
19
  };
20
+ /** Labels and descriptions for each span status. */
19
21
  const TRACE_STATUS = {
20
22
  OK: { label: 'OK', doc: 'Finished as intended.' },
21
23
  ERROR: { label: 'Error', doc: 'Failed; the error kind says why.' },
@@ -57,7 +59,7 @@ const STOP_KINDS = {
57
59
  },
58
60
  gate: {
59
61
  label: 'Waiting for approval',
60
- doc: 'A tool call needs confirmation, permission or sign-in before it runs; the host resumes it.',
62
+ doc: 'A tool call needs confirmation, permission, or sign-in before it runs; the host resumes it.',
61
63
  },
62
64
  filtered: {
63
65
  label: 'Filtered',
@@ -65,6 +67,10 @@ const STOP_KINDS = {
65
67
  },
66
68
  provider_error: { label: 'Provider error', doc: 'The provider reported an error.' },
67
69
  cancelled: { label: 'Cancelled', doc: 'The user or host stopped it.' },
70
+ step_limit: {
71
+ label: 'Ran out of steps',
72
+ doc: 'The last model call the profile allows asked for tools, so the turn ended without an answer.',
73
+ },
68
74
  stream_incomplete: {
69
75
  label: 'Stream cut off',
70
76
  doc: "The provider's stream ended before the answer was complete.",
@@ -81,7 +87,7 @@ const STOP_KINDS = {
81
87
  };
82
88
  const ERROR_KIND_OPTIONS = {
83
89
  config: { label: 'Setup', doc: 'The profile, tool, or schema is set up wrong.' },
84
- request: { label: 'Host request', doc: 'The host called THEOREM wrongly.' },
90
+ request: { label: 'Host request', doc: 'The host called theorem wrongly.' },
85
91
  input: { label: 'User input', doc: 'The user sent input the profile does not accept.' },
86
92
  action: { label: 'Not allowed', doc: 'The user asked for something the profile does not allow.' },
87
93
  auth: {
@@ -97,7 +103,7 @@ const ERROR_KIND_OPTIONS = {
97
103
  },
98
104
  network: { label: 'Network', doc: 'The request never reached the provider.' },
99
105
  timeout: { label: 'Timeout', doc: 'The model took longer than the host allowed.' },
100
- safety: { label: 'Safety', doc: 'THEOREM or the provider held the reply back.' },
106
+ safety: { label: 'Safety', doc: 'theorem or the provider held the reply back.' },
101
107
  blocked: {
102
108
  label: 'Blocked',
103
109
  doc: "A guardrail or host policy stopped one of the agent's steps.",
@@ -105,7 +111,7 @@ const ERROR_KIND_OPTIONS = {
105
111
  declined: { label: 'Declined', doc: "The user declined one of the agent's steps." },
106
112
  failed: { label: 'Failed', doc: "One of the agent's steps ran and failed." },
107
113
  cancelled: { label: 'Cancelled', doc: 'The user or host stopped the turn.' },
108
- internal: { label: 'Internal', doc: 'A THEOREM invariant broke.' },
114
+ internal: { label: 'Internal', doc: 'A theorem invariant broke.' },
109
115
  };
110
116
  /** `error.type`: an error kind, or the failing stop. An HTTP status or exception shows as is. */
111
117
  const ERROR_TYPE_OPTIONS = {
@@ -117,17 +123,17 @@ const ERROR_TYPE_OPTIONS = {
117
123
  const TOOL_OUTCOMES = {
118
124
  ok: { label: 'Succeeded', doc: 'The tool ran and returned a result.' },
119
125
  error: { label: 'Failed', doc: 'The tool ran and failed, or could not run.' },
120
- denied: { label: 'Denied', doc: 'A guardrail, a hook or the user refused the call.' },
126
+ denied: { label: 'Denied', doc: 'A guardrail, a hook, or the user refused the call.' },
121
127
  gated: {
122
128
  label: 'Waiting for approval',
123
- doc: 'The call needs confirmation, permission or sign-in; it has not run.',
129
+ doc: 'The call needs confirmation, permission, or sign-in; it has not run.',
124
130
  },
125
131
  paused: { label: 'Paused', doc: 'The call was handed back to the host to finish.' },
126
132
  cancelled: { label: 'Cancelled', doc: 'The turn was stopped before the call settled.' },
127
133
  };
128
134
  const TOOL_ORIGIN_OPTIONS = {
129
135
  local: { label: 'Host code', doc: 'TypeScript the host registered, run in-process.' },
130
- builtin: { label: 'Built-in', doc: 'A tool THEOREM ships.' },
136
+ builtin: { label: 'Built-in', doc: 'A tool theorem ships.' },
131
137
  http: { label: 'HTTP', doc: 'A remote HTTP endpoint.' },
132
138
  mcp: { label: 'MCP', doc: 'A tool on an MCP server.' },
133
139
  delegated: { label: 'Another agent', doc: 'A specialist agent the tool ran.' },
@@ -166,11 +172,12 @@ const OPERATIONS = {
166
172
  invoke_agent: { label: 'Run agent', doc: 'One turn of an agent, or one Live session.' },
167
173
  chat: { label: 'Chat', doc: 'A model call over a chat-completions API.' },
168
174
  generate_content: { label: 'Generate content', doc: 'A model call over a Gemini API.' },
169
- execute_tool: { label: 'Run tool', doc: 'A tool call THEOREM ran.' },
175
+ execute_tool: { label: 'Run tool', doc: 'A tool call theorem ran.' },
170
176
  decide: {
171
177
  label: 'Decide',
172
178
  doc: 'One model decision: typed answers to questions over JSON state.',
173
179
  },
180
+ embeddings: { label: 'Embed', doc: 'One embedding call: a vector for each input.' },
174
181
  };
175
182
  const OUTPUT_TYPES = {
176
183
  text: { label: 'Text', doc: 'The model answers in text.' },
@@ -210,6 +217,11 @@ const AFFORDANCES = {
210
217
  deny: { label: 'Denied', doc: 'Refused a tool call.' },
211
218
  confirm: { label: 'Asked to confirm', doc: 'Required confirmation before a tool call.' },
212
219
  mutate: { label: 'Changed', doc: 'Changed the tool call or its result.' },
220
+ labelFailed: {
221
+ label: 'Labelled failed',
222
+ doc: "Showed the tool's failed label for a call that completed.",
223
+ },
224
+ waitFor: { label: 'Waited', doc: 'Held a tool call until other calls in its step settled.' },
213
225
  };
214
226
  const GUARDRAIL_STAGE_OPTIONS = {
215
227
  input: { label: 'User input', doc: 'Text the user sent.' },
@@ -229,84 +241,64 @@ const GUARDRAIL_STAGE_OPTIONS = {
229
241
  /**
230
242
  * What each of Theorem's own guardrail rules caught. Keyed by every
231
243
  * {@link GuardrailRule}, so a new rule is described here before it compiles.
232
- * A host's own egress rules have no entry and show as their id.
244
+ * A host's own detectors have no entry and show as their label.
233
245
  */
234
246
  const GUARDRAIL_RULE_OPTIONS = {
235
- 'sanitize.injection': {
236
- label: 'Injection phrasing',
237
- doc: 'Text that tries to override the agent\'s instructions, such as "ignore previous instructions". Removed before the model read it.',
238
- },
239
- 'sanitize.sensitive': {
240
- label: 'Sensitive data',
241
- doc: 'A credential or personal identifier, such as an API key, card or ID number. Redacted before the model read it.',
242
- },
243
- 'egress.canary-leak': {
244
- label: 'Instructions leaked',
245
- doc: "The reply contained the turn's canary, a secret marker planted in the instructions, so the model was repeating them.",
247
+ 'detect.ids': {
248
+ label: 'IDs',
249
+ doc: 'A US SSN, ITIN, or EIN number. The decision names the boundary it was crossing and what was done with it.',
246
250
  },
247
- 'egress.prompt-echo': {
248
- label: 'Instructions repeated',
249
- doc: 'The reply repeated 12 or more words in a row of the instructions.',
250
- },
251
- 'egress.provider-tool-leak': {
252
- label: 'Instructions sent to a provider tool',
253
- doc: "A provider's built-in tool, such as search, was sent the canary or the instructions. It ran before Theorem saw it, so the data had already left.",
251
+ 'detect.financial': {
252
+ label: 'Financial',
253
+ doc: 'An IBAN or card number. The decision names the boundary it was crossing and what was done with it.',
254
254
  },
255
- 'egress.image-exfil': {
256
- label: 'Image from an unknown address',
257
- doc: 'The reply showed an image from an address the model was not given, on a host the profile does not allow. Loading it could send data out.',
255
+ 'detect.network': {
256
+ label: 'Network',
257
+ doc: 'An IPv4 or IPv6 address. The decision names the boundary it was crossing and what was done with it.',
258
258
  },
259
- 'egress.link-exfil': {
260
- label: 'Link to an unknown address',
261
- doc: 'The reply linked an address the model was not given, on a host the profile does not allow.',
259
+ 'detect.credentials': {
260
+ label: 'Credentials',
261
+ doc: 'An API key, token, password assignment, or private key. The decision names the boundary it was crossing and what was done with it.',
262
262
  },
263
- 'egress.sensitive-echo': {
264
- label: 'Sensitive data in reply',
265
- doc: 'The reply contained a credential or personal identifier.',
263
+ 'detect.injection': {
264
+ label: 'Injection',
265
+ doc: 'Text that tries to override the agent\'s instructions, such as "ignore previous instructions". The decision names the boundary it was crossing and what was done with it.',
266
266
  },
267
- 'egress.system-boundary': {
268
- label: 'Internal markers in reply',
269
- doc: 'The reply contained the markers Theorem uses to fence user data or name the canary.',
267
+ 'detect.tool_instructions': {
268
+ label: 'Tool instructions',
269
+ doc: 'A tool\'s text instructed the agent: it told it to set its instructions aside, such as "ignore your instructions", or beside an address it named a tool the model can call, gave an order such as "you must now…", or claimed to speak for the user, the system, or an admin. Each match says which in its signal. The decision names the boundary it was crossing and what was done with it.',
270
270
  },
271
- 'egress.injection-echo': {
272
- label: 'Injection phrasing in reply',
273
- doc: "The reply repeated text that tries to override the agent's instructions.",
271
+ 'detect.canary_leak': {
272
+ label: 'Canary leak',
273
+ doc: "The turn's canary, a secret marker planted in the instructions, so the model was repeating them. The decision names the boundary it was crossing and what was done with it.",
274
274
  },
275
- 'egress.unscannable': {
276
- label: 'Reply could not be checked',
277
- doc: 'Structured output could not be turned into text to check, so it was treated as unsafe.',
275
+ 'detect.prompt_leak': {
276
+ label: 'Prompt leak',
277
+ doc: '12 or more words in a row of the private instructions. The decision names the boundary it was crossing and what was done with it.',
278
278
  },
279
- 'egress.enforcer-error': {
280
- label: 'Output check failed',
281
- doc: "The host's output check threw or returned no clear verdict, so the reply was treated as blocked.",
279
+ 'detect.marker_leak': {
280
+ label: 'Marker leak',
281
+ doc: 'The markers Theorem fences user data with, or the words of the canary note. The decision names the boundary it was crossing and what was done with it.',
282
282
  },
283
- 'egress.blocked': {
284
- label: 'Stopped while streaming',
285
- doc: "The host's output check stopped the reply mid-stream without naming a rule.",
283
+ 'detect.ungiven_images': {
284
+ label: 'Ungiven images',
285
+ doc: 'An image whose address the model was not given, on a host the profile does not allow. Loading it could send data out. The decision names the boundary it was crossing and what was done with it.',
286
286
  },
287
- 'tool_result.names-callable-tool': {
288
- label: 'Named a callable tool',
289
- doc: 'Remote tool content named a tool the model can call, a common way to steer its next step.',
287
+ 'detect.ungiven_links': {
288
+ label: 'Ungiven links',
289
+ doc: 'A link to an address the model was not given, on a host the profile does not allow. The decision names the boundary it was crossing and what was done with it.',
290
290
  },
291
- 'tool_result.imperative': {
292
- label: 'Gave the agent an order',
293
- doc: 'Remote tool content addressed the agent with an instruction, such as "you must now…" or "next steps:".',
291
+ 'detect.tool_leak': {
292
+ label: 'Tool leak',
293
+ doc: "The name of one of the profile's own tools, or of a tool's parameter written as a quoted key. The decision names the boundary it was crossing and what was done with it.",
294
294
  },
295
- 'tool_result.authority-claim': {
296
- label: 'Claimed authority',
297
- doc: 'Remote tool content claimed to speak for the user, the system or an admin, such as "the user has already approved".',
298
- },
299
- 'tool_result.redacted': {
300
- label: 'Tool result redacted',
301
- doc: "Injection phrasing or sensitive data was removed from a tool's result before the model read it.",
302
- },
303
- 'tool_failure.redacted': {
304
- label: 'Tool error redacted',
305
- doc: "Injection phrasing or sensitive data was removed from a tool's error message.",
295
+ 'egress.provider-tool-leak': {
296
+ label: 'Instructions sent to a provider tool',
297
+ doc: "A provider's built-in tool, such as search, was sent the canary or the instructions. It ran before Theorem saw it, so the data had already left.",
306
298
  },
307
- 'tool_call.sensitive-argument': {
308
- label: 'Sensitive data in arguments',
309
- doc: 'The model passed a credential or personal identifier to a tool. The call still ran.',
299
+ 'egress.unscannable': {
300
+ label: 'Reply could not be checked',
301
+ doc: 'Structured output could not be turned into text to check, so it was treated as unsafe.',
310
302
  },
311
303
  'tool_call.tainted-turn': {
312
304
  label: 'Change after remote content',
@@ -316,9 +308,13 @@ const GUARDRAIL_RULE_OPTIONS = {
316
308
  label: 'Change after a remote instruction',
317
309
  doc: 'A tool that writes or deletes was called after the turn read remote content that also looked like instructions to the agent.',
318
310
  },
311
+ 'tool_call.remote-destination': {
312
+ label: 'Destination from remote content',
313
+ doc: "A tool call's argument carried an address that only a remote tool's result named.",
314
+ },
319
315
  'network.blocked': {
320
316
  label: 'Address blocked',
321
- doc: 'A tool tried to reach a private, local or disallowed address. The request was never made.',
317
+ doc: 'A tool tried to reach a private, local, or disallowed address. The request was never made.',
322
318
  },
323
319
  };
324
320
  const GUARDRAIL_CHECK_OPTIONS = {
@@ -329,6 +325,10 @@ const GUARDRAIL_CHECK_OPTIONS = {
329
325
  label: 'Remote-content gate',
330
326
  doc: 'Checked whether a tool that writes or deletes was called after the turn read remote content.',
331
327
  },
328
+ destination: {
329
+ label: 'Destination check',
330
+ doc: "Checked whether the call sends to an address that only a remote tool's result named.",
331
+ },
332
332
  tool_result: {
333
333
  label: 'Result check',
334
334
  doc: 'Checked what a tool returned before the model read it.',
@@ -350,6 +350,10 @@ const GUARDRAIL_CHECK_OPTIONS = {
350
350
  label: 'Streamed leak check',
351
351
  doc: "Checked each streamed tool call and other non-text output for the system prompt's canary.",
352
352
  },
353
+ tool_draft: {
354
+ label: 'Tool call preview check',
355
+ doc: 'Checked a tool call piece by piece as the model wrote it, before the host saw each piece.',
356
+ },
353
357
  live_input: { label: 'Live input check', doc: 'Checked text the host sent into a live session.' },
354
358
  live_output: {
355
359
  label: 'Live output check',
@@ -376,10 +380,15 @@ const SEVERITY_OPTIONS = {
376
380
  medium: { label: 'Medium', doc: 'Medium risk.' },
377
381
  high: { label: 'High', doc: 'High risk.' },
378
382
  };
383
+ const EMBEDDING_TASKS = {
384
+ query: { label: 'Query', doc: 'The input is what a search looks for.' },
385
+ document: { label: 'Document', doc: 'The input is what a search looks through.' },
386
+ };
379
387
  const GATE_KINDS = {
380
388
  confirmation: { label: 'Confirmation', doc: 'The user must confirm this call.' },
381
389
  permission: { label: 'Permission', doc: 'The user must allow this tool.' },
382
390
  auth: { label: 'Sign-in', doc: 'The tool needs a credential the user must provide.' },
391
+ page: { label: 'Page', doc: 'The call waits for the page that answers this tool.' },
383
392
  };
384
393
  const RETRY_REASONS = {
385
394
  egress: {
@@ -396,7 +405,7 @@ const COMPACTION_METER_OPTIONS = {
396
405
  history: { label: 'History', doc: 'Counts tokens across earlier turns.' },
397
406
  input: {
398
407
  label: 'Whole input',
399
- doc: "Counts the turn's whole input: instructions, history and attachments.",
408
+ doc: "Counts the turn's whole input: instructions, history, and attachments.",
400
409
  },
401
410
  };
402
411
  const COMPACTION_OUTCOME_OPTIONS = {
@@ -432,7 +441,7 @@ const SESSION_KINDS = {
432
441
  const CLOSE_INITIATORS = {
433
442
  host: { label: 'Host', doc: 'The host closed the session.' },
434
443
  provider: { label: 'Provider', doc: 'The provider closed the socket.' },
435
- theorem: { label: 'THEOREM', doc: 'THEOREM closed the socket.' },
444
+ theorem: { label: 'theorem', doc: 'theorem closed the socket.' },
436
445
  };
437
446
  const CLOCK_OPTIONS = {
438
447
  io: {
@@ -458,7 +467,7 @@ const SPAN_ATTRIBUTES = {
458
467
  'theorem.stop.kind': attr('agent', 'Stop reason', 'text', 'Why it ended. Absent when it failed before any stop.', STOP_KINDS),
459
468
  'theorem.attempts': attr('agent', 'Attempts', 'number', 'Times the turn ran its model calls, counting a retry after a guardrail or invalid JSON.'),
460
469
  'theorem.steps': attr('agent', 'Model calls', 'number', 'Model calls made (Live: responses).'),
461
- 'theorem.turn.time_to_first_text': attr('agent', 'Time to first visible text', 'seconds', 'From the start of the turn to the first reply text the host received, after every guardrail and holdback.'),
470
+ 'theorem.turn.time_to_first_text': attr('agent', 'Time to first visible text', 'seconds', 'From the start of the turn to the first reply text the host received, after every guardrail and held tail.'),
462
471
  'theorem.guardrail.stream_ms': attr('agent', 'Stream guardrail time', 'milliseconds', "Time every check on this call's streamed output took, together; each check's own time is on its `theorem.guardrail` event."),
463
472
  'theorem.step': attr('agent', 'Step', 'number', 'Which model call of the turn this is, from 1.'),
464
473
  'theorem.attempt': attr('agent', 'Attempt', 'number', 'Which attempt of the turn made this call.'),
@@ -476,7 +485,6 @@ const SPAN_ATTRIBUTES = {
476
485
  'gen_ai.request.temperature': attr('request', 'Temperature', 'number', 'As requested.'),
477
486
  'gen_ai.request.max_tokens': attr('request', 'Max output tokens', 'tokens', 'As requested.'),
478
487
  'gen_ai.request.reasoning.level': attr('request', 'Thinking level', 'text', 'As requested.'),
479
- 'gen_ai.request.previous_response.id': attr('request', 'Continues response', 'id', 'The stored response this call continues.'),
480
488
  'gen_ai.output.type': attr('request', 'Output type', 'text', 'What kind of answer was asked for.', OUTPUT_TYPES),
481
489
  'theorem.key_slot': attr('request', 'API key', 'text', 'The vault key slot that finally answered, by the name the profile gave it.'),
482
490
  'theorem.request.builtins': attr('request', 'Provider tools', 'list', 'Tools the provider runs itself (search, maps, code), as requested.'),
@@ -496,6 +504,7 @@ const SPAN_ATTRIBUTES = {
496
504
  }),
497
505
  'theorem.request.speech': fields('request', 'Speech settings', 'The audio asked for.', {
498
506
  voice: attr('request', 'Voice', 'text', 'The voice.'),
507
+ speed: attr('request', 'Speed', 'number', "The speaking rate; 1 is the voice's own pace."),
499
508
  format: attr('request', 'Format', 'text', 'The audio format.'),
500
509
  }),
501
510
  'theorem.request.live': fields('request', 'Live settings', 'The Live session setup, as sent.', {
@@ -543,7 +552,7 @@ const SPAN_ATTRIBUTES = {
543
552
  'theorem.usage.cost_usd': attr('usage', 'Cost', 'usd', "As the provider reported it, or priced from Jev's fixed price for a decision. Absent when no call reported a cost."),
544
553
  'theorem.usage.upstream_cost_usd': attr('usage', 'Upstream cost', 'usd', "The upstream provider's cost, as a gateway reported it."),
545
554
  'theorem.usage.cost_partial': attr('usage', 'Cost is partial', 'boolean', 'Only some calls reported a cost.'),
546
- 'theorem.usage.estimated': attr('usage', 'Estimated', 'list', 'Sides whose token counts THEOREM estimated rather than the provider reporting them.', USAGE_SIDES),
555
+ 'theorem.usage.estimated': attr('usage', 'Estimated', 'list', 'Sides whose token counts theorem estimated rather than the provider reporting them.', USAGE_SIDES),
547
556
  'theorem.usage.unknown_media': fields('usage', 'Uncounted media', 'Media items no counting rule covered, so their tokens are missing from the estimate.', {
548
557
  input: attr('usage', 'Input', 'number', 'Uncounted media the model read.'),
549
558
  output: attr('usage', 'Output', 'number', 'Uncounted media the model wrote.'),
@@ -567,7 +576,7 @@ const SPAN_ATTRIBUTES = {
567
576
  'url.path': attr('http', 'Path', 'id', 'The URL path. The query is never recorded.'),
568
577
  'http.response.status_code': attr('http', 'Status code', 'number', 'The HTTP status returned.'),
569
578
  'http.request.resend_count': attr('http', 'Retry number', 'number', '0 for the first try, then 1, 2, … for each retry.'),
570
- 'theorem.retry.backoff_ms': attr('http', 'Wait before retry', 'milliseconds', 'How long THEOREM waited after the previous try.'),
579
+ 'theorem.retry.backoff_ms': attr('http', 'Wait before retry', 'milliseconds', 'How long theorem waited after the previous try.'),
571
580
  'error.type': {
572
581
  ...attr('error', 'Error kind', 'text', 'Why it failed: an error kind, the failing stop, or on an HTTP try its status or exception name.', ERROR_TYPE_OPTIONS),
573
582
  open: true,
@@ -580,12 +589,15 @@ const SPAN_ATTRIBUTES = {
580
589
  'theorem.clock': attr('record', 'Clock', 'text', 'How the times in this record were taken.', CLOCK_OPTIONS),
581
590
  'theorem.source': attr('part', 'Source', 'text', 'Where this text came from, when it is not the model’s own.', TRANSCRIPT_SOURCES),
582
591
  'theorem.interim': attr('part', 'Interim', 'boolean', 'An interim transcript, not the final one.'),
583
- 'theorem.observed_end': attr('part', 'Seen at', 'time', 'When THEOREM saw this provider-run step whole.'),
592
+ 'theorem.observed_end': attr('part', 'Seen at', 'time', 'When theorem saw this provider-run step whole.'),
584
593
  'theorem.partial': attr('part', 'Incomplete', 'boolean', 'The provider sent this step incomplete.'),
594
+ 'theorem.embedding.inputs': attr('request', 'Inputs', 'number', 'How many inputs the call embedded, one vector each.'),
595
+ 'theorem.embedding.task': attr('request', 'Task', 'text', 'Whether the inputs are queries or documents, as the request said.', EMBEDDING_TASKS),
585
596
  'theorem.decision.contract': attr('decision', 'Contract', 'id', "The host's decision contract the profile names."),
586
597
  'theorem.decision.state': attr('decision', 'State', 'json', 'The JSON state the decision read.'),
587
- 'theorem.decision.questions': attr('decision', 'Questions', 'json', 'Each question by id: its kind, instructions and criteria.'),
588
- 'theorem.decision.answers': attr('decision', 'Answers', 'json', 'Each answer by question id: the choice or score, its confidence and probabilities.'),
598
+ 'theorem.decision.questions': attr('decision', 'Questions', 'json', 'Each question by id: its kind, instructions, and criteria.'),
599
+ 'theorem.decision.assets': attr('decision', 'Images', 'json', 'Each image by reference: its type and size. The image itself is never recorded.'),
600
+ 'theorem.decision.answers': attr('decision', 'Answers', 'json', 'Each answer by question id: the choice, score, number or box, its confidence, and probabilities.'),
589
601
  'gen_ai.evaluation.name': attr('evaluation', 'Grader', 'id', 'The grader that produced this result.'),
590
602
  'gen_ai.evaluation.score.value': attr('evaluation', 'Score', 'number', 'The score, 0–1 unless the grader says otherwise.'),
591
603
  'gen_ai.evaluation.score.label': attr('evaluation', 'Label', 'text', "The grader's label for this trial, one of the labels it declares."),
@@ -623,7 +635,7 @@ function traceAttributeMeta(key) {
623
635
  const header = HEADER.exec(key);
624
636
  if (header) {
625
637
  const [, direction = '', name = ''] = header;
626
- return attr('http', `${capitalize(direction)} header ${name}`, 'list', `The ${direction} header, as sent. A key, auth, cookie, secret or token header is [redacted].`);
638
+ return attr('http', `${capitalize(direction)} header ${name}`, 'list', `The ${direction} header, as sent. A key, auth, cookie, secret, or token header is [redacted].`);
627
639
  }
628
640
  return undefined;
629
641
  }
@@ -677,9 +689,19 @@ const TRACE_EVENTS = {
677
689
  reason: attr('agent', 'Reason', 'text', 'Why it retried.', RETRY_REASONS),
678
690
  },
679
691
  },
692
+ 'theorem.step.resume': {
693
+ label: 'Sent again',
694
+ doc: 'A model call failed with no reply, and the turn sent it again.',
695
+ attributes: {
696
+ step: attr('agent', 'Step', 'number', 'The step whose model call was sent again.'),
697
+ resume: attr('agent', 'Re-send', 'number', 'How many calls the turn has sent again so far.'),
698
+ stop: attr('agent', 'Stop', 'text', 'How the failed call ended.'),
699
+ error: attr('error', 'Detail', 'content', "The provider's internal reason."),
700
+ },
701
+ },
680
702
  'theorem.compaction': {
681
703
  label: 'Compaction',
682
- doc: 'THEOREM decided whether to summarize earlier messages.',
704
+ doc: 'theorem decided whether to summarize earlier messages.',
683
705
  attributes: {
684
706
  timing: attr('agent', 'Timing', 'text', 'When compaction runs.', COMPACTION_TIMING_OPTIONS),
685
707
  meter: attr('agent', 'Counts', 'text', 'What the threshold counts.', COMPACTION_METER_OPTIONS),
@@ -818,18 +840,34 @@ function traceEventMeta(name) {
818
840
  function traceEventAttributeMeta(event, key) {
819
841
  return TRACE_EVENTS[event]?.attributes[key] ?? traceAttributeMeta(key);
820
842
  }
843
+ /** Labels and descriptions for each span type. */
821
844
  const TRACE_SPAN_TYPES = {
822
845
  turn: { label: 'Turn', doc: 'One exchange: the model calls and tool calls it took to answer.' },
823
846
  session: { label: 'Live session', doc: 'A Live session, from setup to close.' },
824
847
  call: { label: 'Model call', doc: 'One request to a model and its answer.' },
825
848
  response: { label: 'Live response', doc: 'One spoken response in a Live session.' },
826
- tool: { label: 'Tool call', doc: 'One tool call THEOREM ran, from its hooks to settlement.' },
849
+ tool: { label: 'Tool call', doc: 'One tool call theorem ran, from its hooks to settlement.' },
827
850
  http: { label: 'HTTP try', doc: 'One HTTP attempt of a model call.' },
828
851
  cutout: { label: 'Cutout', doc: 'A side effect the host recorded after the turn.' },
829
852
  decision: { label: 'Decision', doc: 'One typed decision over JSON state.' },
830
853
  evaluation: { label: 'Evaluation', doc: 'An eval graded this trace, or a suite ran.' },
831
854
  host: { label: 'Host span', doc: 'A step the host recorded itself.' },
832
855
  };
856
+ /**
857
+ * Every trace field and span type, named by the record they belong to: `trace.resource`, and a
858
+ * span type by the field it fills, `trace.type.turn`.
859
+ */
860
+ function traceCatalogRows() {
861
+ const fields = Object.entries(TRACE_FIELDS).map(([key, meta]) => ({
862
+ name: `trace.${key}`,
863
+ ...meta,
864
+ }));
865
+ const spans = Object.entries(TRACE_SPAN_TYPES).map(([key, meta]) => ({
866
+ name: `trace.type.${key}`,
867
+ ...meta,
868
+ }));
869
+ return [...spans, ...fields];
870
+ }
833
871
  function stringAttribute(span, key) {
834
872
  const value = span.attributes[key];
835
873
  return typeof value === 'string' ? value : undefined;
@@ -838,6 +876,7 @@ function withSubject(type, subject) {
838
876
  const meta = { type, ...TRACE_SPAN_TYPES[type] };
839
877
  return subject ? { ...meta, subject } : meta;
840
878
  }
879
+ /** The label, subject, and description to show for a span. */
841
880
  function traceSpanMeta(span) {
842
881
  switch (stringAttribute(span, 'gen_ai.operation.name')) {
843
882
  case 'invoke_agent':
@@ -849,6 +888,8 @@ function traceSpanMeta(span) {
849
888
  return withSubject('tool', stringAttribute(span, 'gen_ai.tool.name'));
850
889
  case 'decide':
851
890
  return withSubject('decision', stringAttribute(span, 'gen_ai.agent.name'));
891
+ case 'embeddings':
892
+ return withSubject('call', stringAttribute(span, 'gen_ai.request.model'));
852
893
  default:
853
894
  break;
854
895
  }
@@ -862,4 +903,4 @@ function traceSpanMeta(span) {
862
903
  }
863
904
  return withSubject('host', span.name);
864
905
  }
865
- export { TRACE_ATTRIBUTE_GROUPS, TRACE_FIELDS, TRACE_SPAN_TYPES, TRACE_STATUS, traceAttributeMeta, traceEventAttributeMeta, traceEventMeta, traceSpanMeta, };
906
+ export { TRACE_ATTRIBUTE_GROUPS, TRACE_FIELDS, TRACE_SPAN_TYPES, TRACE_STATUS, traceAttributeMeta, traceCatalogRows, traceEventAttributeMeta, traceEventMeta, traceSpanMeta, };
@@ -1,8 +1,10 @@
1
- // Include flags drop whole attribute families or events here, in one place, so a missing field
1
+ // why: Include flags drop whole attribute families or events here, in one place, so a missing field
2
2
  // reads as "not recorded" and the root says which policy applied (`theorem.record.include`).
3
- import { redactSensitiveOnly, sanitizeText } from '../guardrails/sanitize.js';
3
+ import { storedHostSpans, storedSpans } from '../guardrails/detect-at.js';
4
+ import { SENSITIVE_GROUPS } from '../guardrails/sensitive-groups.js';
4
5
  import { sha256, sha256Base64 } from '../kernel/engine/hash.js';
5
6
  import { removeCanaries, tapeUpstream } from '../providers/shared/upstream-tape.js';
7
+ import { applySpans } from './spans.js';
6
8
  import { TRACE_VERSION } from './trace-schema.js';
7
9
  import { isTraceBytes, isTraceContent, isTraceJson, } from './trace-span.js';
8
10
  /** Pinned OpenTelemetry GenAI semantic conventions the attribute names follow. */
@@ -19,17 +21,19 @@ const EVENT_INCLUDE = {
19
21
  const RAW_ATTRIBUTE = 'raw';
20
22
  /** Guardrail hits keep the matched text only under `guardrailMatchPreview`. */
21
23
  const MATCH_ATTRIBUTE = 'match';
22
- function scrubStoredText(text, scrub) {
23
- if (scrub.sensitive && scrub.injection) {
24
- return sanitizeText(text);
25
- }
26
- if (scrub.sensitive) {
27
- return redactSensitiveOnly(text);
28
- }
29
- if (scrub.injection) {
30
- return sanitizeText(text, { sanitizeInput: true, redactSensitive: false });
31
- }
32
- return text;
24
+ /** The detectors `scrub.injection` cleans a record with. */
25
+ const INSTRUCTION_DETECTORS = ['injection', 'tool_instructions'];
26
+ /** Whether a switch cleans with one side's patterns, when it names its sides. */
27
+ function sideOn(on, side) {
28
+ return on === true || (on !== false && on[side]);
29
+ }
30
+ function scrubStoredText(text, { scrub, detect }) {
31
+ const { sensitive, injection } = scrub;
32
+ return applySpans(text, [
33
+ ...(sensitive ? storedSpans(text, SENSITIVE_GROUPS, sensitive, detect) : []),
34
+ ...(sideOn(sensitive, 'host') ? storedHostSpans(text, detect) : []),
35
+ ...(injection ? storedSpans(text, INSTRUCTION_DETECTORS, injection, detect) : []),
36
+ ]);
33
37
  }
34
38
  async function storeText(text, resolver) {
35
39
  const hash = await sha256(text);
@@ -44,13 +48,13 @@ function markerRest(value, key) {
44
48
  /** Pass 1: text and bytes. `$json` waits for pass 2, when every text is known. */
45
49
  async function resolveContent(value, resolver) {
46
50
  if (isTraceContent(value)) {
47
- const text = removeCanaries(scrubStoredText(value.$content, resolver.scrub), resolver.canaries);
51
+ const text = removeCanaries(scrubStoredText(value.$content, resolver), resolver.canaries);
48
52
  return { ...markerRest(value, '$content'), [TEXT_REF]: await storeText(text, resolver) };
49
53
  }
50
54
  if (isTraceBytes(value)) {
51
55
  const rest = markerRest(value, '$bytes');
52
56
  const digest = await sha256Base64(value.$bytes);
53
- // Not base64: hash the text as given and say so, rather than lose the record.
57
+ // why: Not base64: hash the text as given and say so, rather than lose the record.
54
58
  return digest
55
59
  ? { ...rest, content_sha256: digest.hash, bytes: digest.bytes }
56
60
  : { ...rest, invalid_base64: true, text_sha256: await sha256(value.$bytes) };
@@ -75,7 +79,7 @@ function mapStrings(value, rewrite) {
75
79
  /** Scrub a row's strings, then reference any string pass 1 already stored. */
76
80
  function internRow(row, resolver) {
77
81
  return mapStrings(row, (text) => {
78
- const scrubbed = scrubStoredText(text, resolver.scrub);
82
+ const scrubbed = scrubStoredText(text, resolver);
79
83
  const hash = resolver.known.get(scrubbed);
80
84
  return hash ? { [TEXT_REF]: hash } : scrubbed;
81
85
  });
@@ -158,7 +162,8 @@ async function buildRecord(args) {
158
162
  const { policy } = args;
159
163
  const resolver = {
160
164
  scrub: policy.scrub,
161
- canaries: policy.scrub.canary ? (args.canaries ?? []) : [],
165
+ detect: policy.detect,
166
+ canaries: sideOn(policy.scrub.canary, 'theorem') ? (args.canaries ?? []) : [],
162
167
  content: {},
163
168
  known: new Map(),
164
169
  };
@@ -4,6 +4,7 @@ export declare const TRACE_VERSION = 3;
4
4
  export type TraceAttributeValue = null | string | number | boolean | TraceAttributeValue[] | {
5
5
  [key: string]: TraceAttributeValue;
6
6
  };
7
+ /** A span's or event's attributes, by name. */
7
8
  export type TraceAttributes = Record<string, TraceAttributeValue>;
8
9
  export declare const traceAttributesSchema: z.ZodType<TraceAttributes>;
9
10
  /** OTLP span kind. THEOREM emits INTERNAL (agent, tool) and CLIENT (model call). */
@@ -19,11 +20,13 @@ export interface TraceSpanLink {
19
20
  spanId: string;
20
21
  attributes: TraceAttributes;
21
22
  }
23
+ /** A timestamped event on a span, with its attributes. */
22
24
  export interface TraceSpanEvent {
23
25
  name: string;
24
26
  timeUnixNano: string;
25
27
  attributes: TraceAttributes;
26
28
  }
29
+ /** One span of a trace: its ids, name, kind, times, attributes, events, links, and status. */
27
30
  export interface TraceSpan {
28
31
  traceId: string;
29
32
  spanId: string;
@@ -1,4 +1,4 @@
1
- // Each type is checked against its zod schema (`Equals`), so a field in one and not the other fails
1
+ // invariant: Each type is checked against its zod schema (`Equals`), so a field in one and not the other fails
2
2
  // the build. A record crosses a wire, so a reader parses it with `traceRecordSchema` first.
3
3
  import { z } from 'zod';
4
4
  export const TRACE_VERSION = 3;
@@ -6,6 +6,7 @@ export interface TraceWriteContext {
6
6
  /** Size at which a file-based destination starts a new file. */
7
7
  rotateAfterMiB: number;
8
8
  }
9
+ /** Where trace records go: `write` takes each record, and `onError` is told when building or writing one failed. */
9
10
  export interface TraceSink {
10
11
  write: (record: TraceRecord, context: TraceWriteContext) => Promise<void>;
11
12
  /** Called when `writeTrace` catches a build or write failure. Must not throw. */
@@ -1,3 +1,3 @@
1
- // Type-only so programs that never write files (browser bundles, Workers) never pull the JSONL
1
+ // why: Type-only so programs that never write files (browser bundles, Workers) never pull the JSONL
2
2
  // file sink into their module graph.
3
3
  export {};
@@ -9,15 +9,17 @@ interface TraceBytes {
9
9
  [key: string]: TraceAttributeValue;
10
10
  $bytes: string;
11
11
  }
12
- /** In-memory provider row or wire body awaiting scrub, intern and hash at record build. */
12
+ /** In-memory provider row or wire body awaiting scrub, intern, and hash at record build. */
13
13
  interface TraceJson {
14
14
  [key: string]: TraceAttributeValue;
15
15
  $json: TraceAttributeValue;
16
16
  }
17
+ /** A link from a span to another trace, by its `traceparent`. */
17
18
  interface SpanLinkInput {
18
19
  traceparent: string;
19
20
  attributes?: TraceAttributes;
20
21
  }
22
+ /** Options for starting a span: its kind, attributes, and links. */
21
23
  interface SpanOptions {
22
24
  kind?: TraceSpanKind;
23
25
  attributes?: TraceAttributes;
@@ -48,6 +50,7 @@ interface SpanHandle {
48
50
  /** Now on the trace's clock, as span timestamps are written. */
49
51
  nowUnixNano: () => string;
50
52
  }
53
+ /** A trace being built: its root span and the clock it shares. */
51
54
  interface TraceTree {
52
55
  root: SpanHandle;
53
56
  /** The trace's clock; pass it to `startTrace` so related trees share one timeline. */
@@ -55,6 +58,7 @@ interface TraceTree {
55
58
  /** Closes anything still open as `ERROR` / `unclosed`; returns root first, then start order. */
56
59
  collect: () => TraceSpan[];
57
60
  }
61
+ /** The clock a trace reads its timestamps from. */
58
62
  interface TraceClock {
59
63
  nowUnixNano: () => bigint;
60
64
  }
@@ -73,7 +77,9 @@ declare function parseTraceparent(value: string): {
73
77
  spanId: string;
74
78
  };
75
79
  declare function formatTraceparent(traceId: string, spanId: string): string;
80
+ /** Marks text as message content, which the trace stores by hash. */
76
81
  declare function traceContent(text: string): TraceContent;
82
+ /** Marks base64 data as bytes, which the trace stores by hash. */
77
83
  declare function traceBytes(base64: string): TraceBytes;
78
84
  /** `undefined` members and non-JSON values are dropped the way `JSON.stringify` drops them. */
79
85
  declare function traceJson(value: unknown): TraceJson;