@theoremjs/agents 0.3.0 → 0.3.2

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 (570) hide show
  1. package/README.md +277 -995
  2. package/esm/mod.d.ts +34 -20
  3. package/esm/mod.js +19 -12
  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 +25 -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 +881 -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 +30 -22
  123. package/esm/src/guardrails/mod.js +19 -14
  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 +4 -1
  135. package/esm/src/guardrails/quota.js +7 -2
  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 +5 -2
  148. package/esm/src/guardrails/theorem-error.js +6 -3
  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 +8 -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 +174 -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 +329 -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 +130 -88
  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 +102 -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/api-error.d.ts +2 -0
  435. package/esm/src/providers/google/api-error.js +26 -18
  436. package/esm/src/providers/google/builtins.d.ts +14 -0
  437. package/esm/src/providers/google/builtins.js +57 -0
  438. package/esm/src/providers/google/grounding.d.ts +4 -4
  439. package/esm/src/providers/google/interactions/framing.d.ts +20 -8
  440. package/esm/src/providers/google/interactions/framing.js +85 -44
  441. package/esm/src/providers/google/interactions/steps.d.ts +5 -5
  442. package/esm/src/providers/google/interactions/steps.js +4 -4
  443. package/esm/src/providers/google/interactions/stream.d.ts +10 -11
  444. package/esm/src/providers/google/interactions/stream.js +33 -100
  445. package/esm/src/providers/google/live/framing.d.ts +15 -5
  446. package/esm/src/providers/google/live/framing.js +25 -25
  447. package/esm/src/providers/google/live/stream.d.ts +6 -44
  448. package/esm/src/providers/google/live/stream.js +4 -210
  449. package/esm/src/providers/google/urls.d.ts +1 -3
  450. package/esm/src/providers/google/urls.js +1 -3
  451. package/esm/src/providers/google/usage.js +2 -2
  452. package/esm/src/providers/live.d.ts +6 -0
  453. package/esm/src/providers/live.js +6 -0
  454. package/esm/src/providers/local/embedding-protocol.d.ts +7 -0
  455. package/esm/src/providers/local/embedding-protocol.js +60 -0
  456. package/esm/src/providers/local/provider.d.ts +7 -0
  457. package/esm/src/providers/local/provider.js +28 -0
  458. package/esm/src/providers/mod.d.ts +28 -7
  459. package/esm/src/providers/mod.js +19 -3
  460. package/esm/src/providers/open-ai/protocol.d.ts +3 -0
  461. package/esm/src/providers/open-ai/protocol.js +189 -0
  462. package/esm/src/providers/openrouter/embedding-protocol.d.ts +6 -0
  463. package/esm/src/providers/openrouter/embedding-protocol.js +86 -0
  464. package/esm/src/providers/openrouter/image.d.ts +0 -9
  465. package/esm/src/providers/openrouter/image.js +0 -153
  466. package/esm/src/providers/openrouter/images-protocol.d.ts +3 -0
  467. package/esm/src/providers/openrouter/images-protocol.js +82 -0
  468. package/esm/src/providers/openrouter/openai/compat.d.ts +2 -2
  469. package/esm/src/providers/openrouter/openai/compat.js +6 -6
  470. package/esm/src/providers/openrouter/openai/image-payload.d.ts +2 -2
  471. package/esm/src/providers/openrouter/openai/reasoning-state.d.ts +2 -0
  472. package/esm/src/providers/openrouter/openai/reasoning-state.js +31 -0
  473. package/esm/src/providers/openrouter/protocol.d.ts +8 -0
  474. package/esm/src/providers/openrouter/protocol.js +171 -0
  475. package/esm/src/providers/openrouter/provider.d.ts +10 -0
  476. package/esm/src/providers/openrouter/provider.js +50 -0
  477. package/esm/src/providers/shared/carried-tool-files.d.ts +7 -0
  478. package/esm/src/providers/shared/carried-tool-files.js +43 -0
  479. package/esm/src/providers/shared/pcm.js +2 -2
  480. package/esm/src/providers/shared/protocol-events.d.ts +8 -0
  481. package/esm/src/providers/shared/protocol-events.js +20 -0
  482. package/esm/src/providers/shared/response-identity.d.ts +2 -2
  483. package/esm/src/providers/shared/retry.d.ts +18 -0
  484. package/esm/src/providers/shared/retry.js +89 -0
  485. package/esm/src/providers/shared/sse.d.ts +0 -4
  486. package/esm/src/providers/shared/sse.js +50 -36
  487. package/esm/src/providers/shared/tool-args.d.ts +6 -7
  488. package/esm/src/providers/shared/tool-args.js +10 -6
  489. package/esm/src/providers/shared/tool-draft.d.ts +16 -0
  490. package/esm/src/providers/shared/tool-draft.js +14 -0
  491. package/esm/src/providers/shared/upstream-tap.d.ts +2 -2
  492. package/esm/src/providers/shared/upstream-tape.js +1 -1
  493. package/esm/src/providers/system-one/protocol.d.ts +8 -0
  494. package/esm/src/providers/system-one/protocol.js +93 -0
  495. package/esm/src/providers/types.d.ts +48 -16
  496. package/esm/src/providers/types.js +2 -1
  497. package/esm/src/providers/typesafe/provider.d.ts +7 -0
  498. package/esm/src/providers/typesafe/provider.js +24 -0
  499. package/esm/src/surface/formats.d.ts +19 -1
  500. package/esm/src/surface/formats.js +68 -29
  501. package/esm/src/surface/mod.d.ts +4 -2
  502. package/esm/src/surface/mod.js +4 -2
  503. package/esm/src/surface/runtime.d.ts +4 -0
  504. package/esm/src/surface/runtime.js +2 -0
  505. package/esm/src/surface/tools.d.ts +2 -8
  506. package/esm/src/surface/tools.js +4 -22
  507. package/esm/src/surface/types.d.ts +6 -0
  508. package/package.json +5 -13
  509. package/esm/src/cli/commands/egress-compile.d.ts +0 -17
  510. package/esm/src/cli/commands/egress-compile.js +0 -25
  511. package/esm/src/guardrails/egress-policy.d.ts +0 -27
  512. package/esm/src/guardrails/egress-policy.js +0 -76
  513. package/esm/src/guardrails/egress-rules.d.ts +0 -54
  514. package/esm/src/guardrails/egress-rules.js +0 -49
  515. package/esm/src/guardrails/lexicon.d.ts +0 -30
  516. package/esm/src/guardrails/lexicon.js +0 -478
  517. package/esm/src/kernel/engine/media-probe/audio.d.ts +0 -7
  518. package/esm/src/kernel/engine/media-probe/audio.js +0 -342
  519. package/esm/src/kernel/engine/media-probe/bytes.d.ts +0 -6
  520. package/esm/src/kernel/engine/media-probe/bytes.js +0 -26
  521. package/esm/src/kernel/engine/media-probe/image.d.ts +0 -5
  522. package/esm/src/kernel/engine/media-probe/image.js +0 -171
  523. package/esm/src/kernel/engine/media-probe/iso-bmff.d.ts +0 -19
  524. package/esm/src/kernel/engine/media-probe/iso-bmff.js +0 -48
  525. package/esm/src/kernel/engine/media-probe/matroska.d.ts +0 -35
  526. package/esm/src/kernel/engine/media-probe/matroska.js +0 -226
  527. package/esm/src/kernel/engine/media-probe/mp4.d.ts +0 -22
  528. package/esm/src/kernel/engine/media-probe/mp4.js +0 -279
  529. package/esm/src/kernel/engine/media-probe/opus.d.ts +0 -4
  530. package/esm/src/kernel/engine/media-probe/opus.js +0 -23
  531. package/esm/src/kernel/engine/media-probe/pdf.d.ts +0 -5
  532. package/esm/src/kernel/engine/media-probe/pdf.js +0 -117
  533. package/esm/src/kernel/engine/media-probe/video.d.ts +0 -15
  534. package/esm/src/kernel/engine/media-probe/video.js +0 -49
  535. package/esm/src/presets/typesafe.d.ts +0 -2
  536. package/esm/src/presets/typesafe.js +0 -2
  537. package/esm/src/providers/create-provider.d.ts +0 -21
  538. package/esm/src/providers/create-provider.js +0 -90
  539. package/esm/src/providers/decision/usage.d.ts +0 -3
  540. package/esm/src/providers/decision/usage.js +0 -25
  541. package/esm/src/providers/google/interactions/mod.d.ts +0 -2
  542. package/esm/src/providers/google/interactions/mod.js +0 -2
  543. package/esm/src/providers/google/keys.d.ts +0 -20
  544. package/esm/src/providers/google/keys.js +0 -87
  545. package/esm/src/providers/google/live/mod.d.ts +0 -7
  546. package/esm/src/providers/google/live/mod.js +0 -7
  547. package/esm/src/providers/google/live/openapi-schema.d.ts +0 -1
  548. package/esm/src/providers/google/live/openapi-schema.js +0 -42
  549. package/esm/src/providers/google/live/session.d.ts +0 -14
  550. package/esm/src/providers/google/live/session.js +0 -150
  551. package/esm/src/providers/local/local.d.ts +0 -12
  552. package/esm/src/providers/local/local.js +0 -186
  553. package/esm/src/providers/local/mod.d.ts +0 -8
  554. package/esm/src/providers/local/mod.js +0 -8
  555. package/esm/src/providers/openrouter/cache-control.d.ts +0 -5
  556. package/esm/src/providers/openrouter/cache-control.js +0 -4
  557. package/esm/src/providers/openrouter/chat.d.ts +0 -64
  558. package/esm/src/providers/openrouter/chat.js +0 -490
  559. package/esm/src/providers/openrouter/openai/sdk-messages.d.ts +0 -10
  560. package/esm/src/providers/openrouter/openai/sdk-messages.js +0 -99
  561. package/esm/src/providers/openrouter/resolve-api-key.d.ts +0 -3
  562. package/esm/src/providers/openrouter/resolve-api-key.js +0 -8
  563. package/esm/src/providers/openrouter/speech.d.ts +0 -18
  564. package/esm/src/providers/openrouter/speech.js +0 -109
  565. package/esm/src/providers/probe.d.ts +0 -5
  566. package/esm/src/providers/probe.js +0 -15
  567. package/esm/src/providers/shared/builtin-wire.d.ts +0 -4
  568. package/esm/src/providers/shared/builtin-wire.js +0 -9
  569. package/esm/src/providers/shared/vault.d.ts +0 -13
  570. 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: {
@@ -90,14 +96,15 @@ const ERROR_KIND_OPTIONS = {
90
96
  },
91
97
  rate_limit: { label: 'Rate limit', doc: 'Too many requests, or a quota used up.' },
92
98
  unsupported: { label: 'Unsupported', doc: 'The model or route cannot serve this request.' },
93
- unavailable: { label: 'Unavailable', doc: 'The provider is down or overloaded.' },
99
+ busy: { label: 'Busy', doc: 'The provider is up but too busy for the call.' },
100
+ unavailable: { label: 'Unavailable', doc: 'The provider is down.' },
94
101
  bad_response: {
95
102
  label: 'Unusable response',
96
103
  doc: 'The provider answered with something that cannot be used.',
97
104
  },
98
105
  network: { label: 'Network', doc: 'The request never reached the provider.' },
99
106
  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.' },
107
+ safety: { label: 'Safety', doc: 'theorem or the provider held the reply back.' },
101
108
  blocked: {
102
109
  label: 'Blocked',
103
110
  doc: "A guardrail or host policy stopped one of the agent's steps.",
@@ -105,7 +112,7 @@ const ERROR_KIND_OPTIONS = {
105
112
  declined: { label: 'Declined', doc: "The user declined one of the agent's steps." },
106
113
  failed: { label: 'Failed', doc: "One of the agent's steps ran and failed." },
107
114
  cancelled: { label: 'Cancelled', doc: 'The user or host stopped the turn.' },
108
- internal: { label: 'Internal', doc: 'A THEOREM invariant broke.' },
115
+ internal: { label: 'Internal', doc: 'A theorem invariant broke.' },
109
116
  };
110
117
  /** `error.type`: an error kind, or the failing stop. An HTTP status or exception shows as is. */
111
118
  const ERROR_TYPE_OPTIONS = {
@@ -117,17 +124,17 @@ const ERROR_TYPE_OPTIONS = {
117
124
  const TOOL_OUTCOMES = {
118
125
  ok: { label: 'Succeeded', doc: 'The tool ran and returned a result.' },
119
126
  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.' },
127
+ denied: { label: 'Denied', doc: 'A guardrail, a hook, or the user refused the call.' },
121
128
  gated: {
122
129
  label: 'Waiting for approval',
123
- doc: 'The call needs confirmation, permission or sign-in; it has not run.',
130
+ doc: 'The call needs confirmation, permission, or sign-in; it has not run.',
124
131
  },
125
132
  paused: { label: 'Paused', doc: 'The call was handed back to the host to finish.' },
126
133
  cancelled: { label: 'Cancelled', doc: 'The turn was stopped before the call settled.' },
127
134
  };
128
135
  const TOOL_ORIGIN_OPTIONS = {
129
136
  local: { label: 'Host code', doc: 'TypeScript the host registered, run in-process.' },
130
- builtin: { label: 'Built-in', doc: 'A tool THEOREM ships.' },
137
+ builtin: { label: 'Built-in', doc: 'A tool theorem ships.' },
131
138
  http: { label: 'HTTP', doc: 'A remote HTTP endpoint.' },
132
139
  mcp: { label: 'MCP', doc: 'A tool on an MCP server.' },
133
140
  delegated: { label: 'Another agent', doc: 'A specialist agent the tool ran.' },
@@ -166,11 +173,12 @@ const OPERATIONS = {
166
173
  invoke_agent: { label: 'Run agent', doc: 'One turn of an agent, or one Live session.' },
167
174
  chat: { label: 'Chat', doc: 'A model call over a chat-completions API.' },
168
175
  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.' },
176
+ execute_tool: { label: 'Run tool', doc: 'A tool call theorem ran.' },
170
177
  decide: {
171
178
  label: 'Decide',
172
179
  doc: 'One model decision: typed answers to questions over JSON state.',
173
180
  },
181
+ embeddings: { label: 'Embed', doc: 'One embedding call: a vector for each input.' },
174
182
  };
175
183
  const OUTPUT_TYPES = {
176
184
  text: { label: 'Text', doc: 'The model answers in text.' },
@@ -210,6 +218,11 @@ const AFFORDANCES = {
210
218
  deny: { label: 'Denied', doc: 'Refused a tool call.' },
211
219
  confirm: { label: 'Asked to confirm', doc: 'Required confirmation before a tool call.' },
212
220
  mutate: { label: 'Changed', doc: 'Changed the tool call or its result.' },
221
+ labelFailed: {
222
+ label: 'Labelled failed',
223
+ doc: "Showed the tool's failed label for a call that completed.",
224
+ },
225
+ waitFor: { label: 'Waited', doc: 'Held a tool call until other calls in its step settled.' },
213
226
  };
214
227
  const GUARDRAIL_STAGE_OPTIONS = {
215
228
  input: { label: 'User input', doc: 'Text the user sent.' },
@@ -229,84 +242,64 @@ const GUARDRAIL_STAGE_OPTIONS = {
229
242
  /**
230
243
  * What each of Theorem's own guardrail rules caught. Keyed by every
231
244
  * {@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.
245
+ * A host's own detectors have no entry and show as their label.
233
246
  */
234
247
  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.",
248
+ 'detect.ids': {
249
+ label: 'IDs',
250
+ doc: 'A US SSN, ITIN, or EIN number. The decision names the boundary it was crossing and what was done with it.',
246
251
  },
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.",
252
+ 'detect.financial': {
253
+ label: 'Financial',
254
+ doc: 'An IBAN or card number. The decision names the boundary it was crossing and what was done with it.',
254
255
  },
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.',
256
+ 'detect.network': {
257
+ label: 'Network',
258
+ doc: 'An IPv4 or IPv6 address. The decision names the boundary it was crossing and what was done with it.',
258
259
  },
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.',
260
+ 'detect.credentials': {
261
+ label: 'Credentials',
262
+ 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
263
  },
263
- 'egress.sensitive-echo': {
264
- label: 'Sensitive data in reply',
265
- doc: 'The reply contained a credential or personal identifier.',
264
+ 'detect.injection': {
265
+ label: 'Injection',
266
+ 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
267
  },
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.',
268
+ 'detect.tool_instructions': {
269
+ label: 'Tool instructions',
270
+ 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
271
  },
271
- 'egress.injection-echo': {
272
- label: 'Injection phrasing in reply',
273
- doc: "The reply repeated text that tries to override the agent's instructions.",
272
+ 'detect.canary_leak': {
273
+ label: 'Canary leak',
274
+ 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
275
  },
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.',
276
+ 'detect.prompt_leak': {
277
+ label: 'Prompt leak',
278
+ 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
279
  },
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.",
280
+ 'detect.marker_leak': {
281
+ label: 'Marker leak',
282
+ 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
283
  },
283
- 'egress.blocked': {
284
- label: 'Stopped while streaming',
285
- doc: "The host's output check stopped the reply mid-stream without naming a rule.",
284
+ 'detect.ungiven_images': {
285
+ label: 'Ungiven images',
286
+ 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
287
  },
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.',
288
+ 'detect.ungiven_links': {
289
+ label: 'Ungiven links',
290
+ 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
291
  },
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:".',
292
+ 'detect.tool_leak': {
293
+ label: 'Tool leak',
294
+ 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
295
  },
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.",
296
+ 'egress.provider-tool-leak': {
297
+ label: 'Instructions sent to a provider tool',
298
+ 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
299
  },
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.',
300
+ 'egress.unscannable': {
301
+ label: 'Reply could not be checked',
302
+ doc: 'Structured output could not be turned into text to check, so it was treated as unsafe.',
310
303
  },
311
304
  'tool_call.tainted-turn': {
312
305
  label: 'Change after remote content',
@@ -316,9 +309,13 @@ const GUARDRAIL_RULE_OPTIONS = {
316
309
  label: 'Change after a remote instruction',
317
310
  doc: 'A tool that writes or deletes was called after the turn read remote content that also looked like instructions to the agent.',
318
311
  },
312
+ 'tool_call.remote-destination': {
313
+ label: 'Destination from remote content',
314
+ doc: "A tool call's argument carried an address that only a remote tool's result named.",
315
+ },
319
316
  'network.blocked': {
320
317
  label: 'Address blocked',
321
- doc: 'A tool tried to reach a private, local or disallowed address. The request was never made.',
318
+ doc: 'A tool tried to reach a private, local, or disallowed address. The request was never made.',
322
319
  },
323
320
  };
324
321
  const GUARDRAIL_CHECK_OPTIONS = {
@@ -329,6 +326,10 @@ const GUARDRAIL_CHECK_OPTIONS = {
329
326
  label: 'Remote-content gate',
330
327
  doc: 'Checked whether a tool that writes or deletes was called after the turn read remote content.',
331
328
  },
329
+ destination: {
330
+ label: 'Destination check',
331
+ doc: "Checked whether the call sends to an address that only a remote tool's result named.",
332
+ },
332
333
  tool_result: {
333
334
  label: 'Result check',
334
335
  doc: 'Checked what a tool returned before the model read it.',
@@ -350,6 +351,10 @@ const GUARDRAIL_CHECK_OPTIONS = {
350
351
  label: 'Streamed leak check',
351
352
  doc: "Checked each streamed tool call and other non-text output for the system prompt's canary.",
352
353
  },
354
+ tool_draft: {
355
+ label: 'Tool call preview check',
356
+ doc: 'Checked a tool call piece by piece as the model wrote it, before the host saw each piece.',
357
+ },
353
358
  live_input: { label: 'Live input check', doc: 'Checked text the host sent into a live session.' },
354
359
  live_output: {
355
360
  label: 'Live output check',
@@ -376,10 +381,15 @@ const SEVERITY_OPTIONS = {
376
381
  medium: { label: 'Medium', doc: 'Medium risk.' },
377
382
  high: { label: 'High', doc: 'High risk.' },
378
383
  };
384
+ const EMBEDDING_TASKS = {
385
+ query: { label: 'Query', doc: 'The input is what a search looks for.' },
386
+ document: { label: 'Document', doc: 'The input is what a search looks through.' },
387
+ };
379
388
  const GATE_KINDS = {
380
389
  confirmation: { label: 'Confirmation', doc: 'The user must confirm this call.' },
381
390
  permission: { label: 'Permission', doc: 'The user must allow this tool.' },
382
391
  auth: { label: 'Sign-in', doc: 'The tool needs a credential the user must provide.' },
392
+ page: { label: 'Page', doc: 'The call waits for the page that answers this tool.' },
383
393
  };
384
394
  const RETRY_REASONS = {
385
395
  egress: {
@@ -396,7 +406,7 @@ const COMPACTION_METER_OPTIONS = {
396
406
  history: { label: 'History', doc: 'Counts tokens across earlier turns.' },
397
407
  input: {
398
408
  label: 'Whole input',
399
- doc: "Counts the turn's whole input: instructions, history and attachments.",
409
+ doc: "Counts the turn's whole input: instructions, history, and attachments.",
400
410
  },
401
411
  };
402
412
  const COMPACTION_OUTCOME_OPTIONS = {
@@ -432,7 +442,7 @@ const SESSION_KINDS = {
432
442
  const CLOSE_INITIATORS = {
433
443
  host: { label: 'Host', doc: 'The host closed the session.' },
434
444
  provider: { label: 'Provider', doc: 'The provider closed the socket.' },
435
- theorem: { label: 'THEOREM', doc: 'THEOREM closed the socket.' },
445
+ theorem: { label: 'theorem', doc: 'theorem closed the socket.' },
436
446
  };
437
447
  const CLOCK_OPTIONS = {
438
448
  io: {
@@ -458,7 +468,7 @@ const SPAN_ATTRIBUTES = {
458
468
  'theorem.stop.kind': attr('agent', 'Stop reason', 'text', 'Why it ended. Absent when it failed before any stop.', STOP_KINDS),
459
469
  'theorem.attempts': attr('agent', 'Attempts', 'number', 'Times the turn ran its model calls, counting a retry after a guardrail or invalid JSON.'),
460
470
  '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.'),
471
+ '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
472
  '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
473
  'theorem.step': attr('agent', 'Step', 'number', 'Which model call of the turn this is, from 1.'),
464
474
  'theorem.attempt': attr('agent', 'Attempt', 'number', 'Which attempt of the turn made this call.'),
@@ -476,7 +486,6 @@ const SPAN_ATTRIBUTES = {
476
486
  'gen_ai.request.temperature': attr('request', 'Temperature', 'number', 'As requested.'),
477
487
  'gen_ai.request.max_tokens': attr('request', 'Max output tokens', 'tokens', 'As requested.'),
478
488
  '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
489
  'gen_ai.output.type': attr('request', 'Output type', 'text', 'What kind of answer was asked for.', OUTPUT_TYPES),
481
490
  'theorem.key_slot': attr('request', 'API key', 'text', 'The vault key slot that finally answered, by the name the profile gave it.'),
482
491
  'theorem.request.builtins': attr('request', 'Provider tools', 'list', 'Tools the provider runs itself (search, maps, code), as requested.'),
@@ -496,6 +505,7 @@ const SPAN_ATTRIBUTES = {
496
505
  }),
497
506
  'theorem.request.speech': fields('request', 'Speech settings', 'The audio asked for.', {
498
507
  voice: attr('request', 'Voice', 'text', 'The voice.'),
508
+ speed: attr('request', 'Speed', 'number', "The speaking rate; 1 is the voice's own pace."),
499
509
  format: attr('request', 'Format', 'text', 'The audio format.'),
500
510
  }),
501
511
  'theorem.request.live': fields('request', 'Live settings', 'The Live session setup, as sent.', {
@@ -543,7 +553,7 @@ const SPAN_ATTRIBUTES = {
543
553
  '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
554
  'theorem.usage.upstream_cost_usd': attr('usage', 'Upstream cost', 'usd', "The upstream provider's cost, as a gateway reported it."),
545
555
  '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),
556
+ 'theorem.usage.estimated': attr('usage', 'Estimated', 'list', 'Sides whose token counts theorem estimated rather than the provider reporting them.', USAGE_SIDES),
547
557
  'theorem.usage.unknown_media': fields('usage', 'Uncounted media', 'Media items no counting rule covered, so their tokens are missing from the estimate.', {
548
558
  input: attr('usage', 'Input', 'number', 'Uncounted media the model read.'),
549
559
  output: attr('usage', 'Output', 'number', 'Uncounted media the model wrote.'),
@@ -567,7 +577,7 @@ const SPAN_ATTRIBUTES = {
567
577
  'url.path': attr('http', 'Path', 'id', 'The URL path. The query is never recorded.'),
568
578
  'http.response.status_code': attr('http', 'Status code', 'number', 'The HTTP status returned.'),
569
579
  '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.'),
580
+ 'theorem.retry.backoff_ms': attr('http', 'Wait before retry', 'milliseconds', 'How long theorem waited after the previous try.'),
571
581
  'error.type': {
572
582
  ...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
583
  open: true,
@@ -580,12 +590,15 @@ const SPAN_ATTRIBUTES = {
580
590
  'theorem.clock': attr('record', 'Clock', 'text', 'How the times in this record were taken.', CLOCK_OPTIONS),
581
591
  'theorem.source': attr('part', 'Source', 'text', 'Where this text came from, when it is not the model’s own.', TRANSCRIPT_SOURCES),
582
592
  '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.'),
593
+ 'theorem.observed_end': attr('part', 'Seen at', 'time', 'When theorem saw this provider-run step whole.'),
584
594
  'theorem.partial': attr('part', 'Incomplete', 'boolean', 'The provider sent this step incomplete.'),
595
+ 'theorem.embedding.inputs': attr('request', 'Inputs', 'number', 'How many inputs the call embedded, one vector each.'),
596
+ 'theorem.embedding.task': attr('request', 'Task', 'text', 'Whether the inputs are queries or documents, as the request said.', EMBEDDING_TASKS),
585
597
  'theorem.decision.contract': attr('decision', 'Contract', 'id', "The host's decision contract the profile names."),
586
598
  '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.'),
599
+ 'theorem.decision.questions': attr('decision', 'Questions', 'json', 'Each question by id: its kind, instructions, and criteria.'),
600
+ 'theorem.decision.assets': attr('decision', 'Images', 'json', 'Each image by reference: its type and size. The image itself is never recorded.'),
601
+ 'theorem.decision.answers': attr('decision', 'Answers', 'json', 'Each answer by question id: the choice, score, number or box, its confidence, and probabilities.'),
589
602
  'gen_ai.evaluation.name': attr('evaluation', 'Grader', 'id', 'The grader that produced this result.'),
590
603
  'gen_ai.evaluation.score.value': attr('evaluation', 'Score', 'number', 'The score, 0–1 unless the grader says otherwise.'),
591
604
  'gen_ai.evaluation.score.label': attr('evaluation', 'Label', 'text', "The grader's label for this trial, one of the labels it declares."),
@@ -623,7 +636,7 @@ function traceAttributeMeta(key) {
623
636
  const header = HEADER.exec(key);
624
637
  if (header) {
625
638
  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].`);
639
+ return attr('http', `${capitalize(direction)} header ${name}`, 'list', `The ${direction} header, as sent. A key, auth, cookie, secret, or token header is [redacted].`);
627
640
  }
628
641
  return undefined;
629
642
  }
@@ -677,9 +690,19 @@ const TRACE_EVENTS = {
677
690
  reason: attr('agent', 'Reason', 'text', 'Why it retried.', RETRY_REASONS),
678
691
  },
679
692
  },
693
+ 'theorem.step.resume': {
694
+ label: 'Sent again',
695
+ doc: 'A model call failed with no reply, and the turn sent it again.',
696
+ attributes: {
697
+ step: attr('agent', 'Step', 'number', 'The step whose model call was sent again.'),
698
+ resume: attr('agent', 'Re-send', 'number', 'How many calls the turn has sent again so far.'),
699
+ stop: attr('agent', 'Stop', 'text', 'How the failed call ended.'),
700
+ error: attr('error', 'Detail', 'content', "The provider's internal reason."),
701
+ },
702
+ },
680
703
  'theorem.compaction': {
681
704
  label: 'Compaction',
682
- doc: 'THEOREM decided whether to summarize earlier messages.',
705
+ doc: 'theorem decided whether to summarize earlier messages.',
683
706
  attributes: {
684
707
  timing: attr('agent', 'Timing', 'text', 'When compaction runs.', COMPACTION_TIMING_OPTIONS),
685
708
  meter: attr('agent', 'Counts', 'text', 'What the threshold counts.', COMPACTION_METER_OPTIONS),
@@ -818,18 +841,34 @@ function traceEventMeta(name) {
818
841
  function traceEventAttributeMeta(event, key) {
819
842
  return TRACE_EVENTS[event]?.attributes[key] ?? traceAttributeMeta(key);
820
843
  }
844
+ /** Labels and descriptions for each span type. */
821
845
  const TRACE_SPAN_TYPES = {
822
846
  turn: { label: 'Turn', doc: 'One exchange: the model calls and tool calls it took to answer.' },
823
847
  session: { label: 'Live session', doc: 'A Live session, from setup to close.' },
824
848
  call: { label: 'Model call', doc: 'One request to a model and its answer.' },
825
849
  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.' },
850
+ tool: { label: 'Tool call', doc: 'One tool call theorem ran, from its hooks to settlement.' },
827
851
  http: { label: 'HTTP try', doc: 'One HTTP attempt of a model call.' },
828
852
  cutout: { label: 'Cutout', doc: 'A side effect the host recorded after the turn.' },
829
853
  decision: { label: 'Decision', doc: 'One typed decision over JSON state.' },
830
854
  evaluation: { label: 'Evaluation', doc: 'An eval graded this trace, or a suite ran.' },
831
855
  host: { label: 'Host span', doc: 'A step the host recorded itself.' },
832
856
  };
857
+ /**
858
+ * Every trace field and span type, named by the record they belong to: `trace.resource`, and a
859
+ * span type by the field it fills, `trace.type.turn`.
860
+ */
861
+ function traceCatalogRows() {
862
+ const fields = Object.entries(TRACE_FIELDS).map(([key, meta]) => ({
863
+ name: `trace.${key}`,
864
+ ...meta,
865
+ }));
866
+ const spans = Object.entries(TRACE_SPAN_TYPES).map(([key, meta]) => ({
867
+ name: `trace.type.${key}`,
868
+ ...meta,
869
+ }));
870
+ return [...spans, ...fields];
871
+ }
833
872
  function stringAttribute(span, key) {
834
873
  const value = span.attributes[key];
835
874
  return typeof value === 'string' ? value : undefined;
@@ -838,6 +877,7 @@ function withSubject(type, subject) {
838
877
  const meta = { type, ...TRACE_SPAN_TYPES[type] };
839
878
  return subject ? { ...meta, subject } : meta;
840
879
  }
880
+ /** The label, subject, and description to show for a span. */
841
881
  function traceSpanMeta(span) {
842
882
  switch (stringAttribute(span, 'gen_ai.operation.name')) {
843
883
  case 'invoke_agent':
@@ -849,6 +889,8 @@ function traceSpanMeta(span) {
849
889
  return withSubject('tool', stringAttribute(span, 'gen_ai.tool.name'));
850
890
  case 'decide':
851
891
  return withSubject('decision', stringAttribute(span, 'gen_ai.agent.name'));
892
+ case 'embeddings':
893
+ return withSubject('call', stringAttribute(span, 'gen_ai.request.model'));
852
894
  default:
853
895
  break;
854
896
  }
@@ -862,4 +904,4 @@ function traceSpanMeta(span) {
862
904
  }
863
905
  return withSubject('host', span.name);
864
906
  }
865
- export { TRACE_ATTRIBUTE_GROUPS, TRACE_FIELDS, TRACE_SPAN_TYPES, TRACE_STATUS, traceAttributeMeta, traceEventAttributeMeta, traceEventMeta, traceSpanMeta, };
907
+ 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 {};