@theoremjs/agents 0.0.0-stage → 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 (588) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +545 -2
  3. package/esm/_dnt.polyfills.d.ts +66 -0
  4. package/esm/_dnt.polyfills.js +51 -0
  5. package/esm/mod.d.ts +79 -0
  6. package/esm/mod.js +49 -0
  7. package/esm/package.json +3 -0
  8. package/esm/src/cli/bin.d.ts +7 -0
  9. package/esm/src/cli/bin.js +9 -0
  10. package/esm/src/cli/commands/bench.d.ts +6 -0
  11. package/esm/src/cli/commands/bench.js +480 -0
  12. package/esm/src/cli/commands/detect-compile.d.ts +17 -0
  13. package/esm/src/cli/commands/detect-compile.js +22 -0
  14. package/esm/src/cli/commands/eval.d.ts +37 -0
  15. package/esm/src/cli/commands/eval.js +190 -0
  16. package/esm/src/cli/commands/fuzz-canary.d.ts +15 -0
  17. package/esm/src/cli/commands/fuzz-canary.js +241 -0
  18. package/esm/src/cli/commands/fuzz-guardrails.d.ts +2 -0
  19. package/esm/src/cli/commands/fuzz-guardrails.js +5 -0
  20. package/esm/src/cli/commands/profile.d.ts +2 -0
  21. package/esm/src/cli/commands/profile.js +80 -0
  22. package/esm/src/cli/commands/run.d.ts +13 -0
  23. package/esm/src/cli/commands/run.js +45 -0
  24. package/esm/src/cli/commands/test.d.ts +26 -0
  25. package/esm/src/cli/commands/test.js +143 -0
  26. package/esm/src/cli/event-log.d.ts +15 -0
  27. package/esm/src/cli/event-log.js +136 -0
  28. package/esm/src/cli/index.d.ts +10 -0
  29. package/esm/src/cli/index.js +267 -0
  30. package/esm/src/cli/matrix/fixtures.d.ts +10 -0
  31. package/esm/src/cli/matrix/fixtures.js +67 -0
  32. package/esm/src/cli/matrix/synthesizer.d.ts +18 -0
  33. package/esm/src/cli/matrix/synthesizer.js +103 -0
  34. package/esm/src/evals/attachments.d.ts +5 -0
  35. package/esm/src/evals/attachments.js +55 -0
  36. package/esm/src/evals/breakdown.d.ts +30 -0
  37. package/esm/src/evals/breakdown.js +69 -0
  38. package/esm/src/evals/graders/answer.d.ts +16 -0
  39. package/esm/src/evals/graders/answer.js +134 -0
  40. package/esm/src/evals/graders/code.d.ts +40 -0
  41. package/esm/src/evals/graders/code.js +184 -0
  42. package/esm/src/evals/graders/judge.d.ts +24 -0
  43. package/esm/src/evals/graders/judge.js +367 -0
  44. package/esm/src/evals/graders/latency.d.ts +6 -0
  45. package/esm/src/evals/graders/latency.js +82 -0
  46. package/esm/src/evals/graders/live.d.ts +14 -0
  47. package/esm/src/evals/graders/live.js +42 -0
  48. package/esm/src/evals/graders/media.d.ts +18 -0
  49. package/esm/src/evals/graders/media.js +91 -0
  50. package/esm/src/evals/graders/shared.d.ts +11 -0
  51. package/esm/src/evals/graders/shared.js +62 -0
  52. package/esm/src/evals/graders/transcript.d.ts +19 -0
  53. package/esm/src/evals/graders/transcript.js +202 -0
  54. package/esm/src/evals/mod.d.ts +34 -0
  55. package/esm/src/evals/mod.js +22 -0
  56. package/esm/src/evals/record.d.ts +41 -0
  57. package/esm/src/evals/record.js +107 -0
  58. package/esm/src/evals/rubrics/catalog.d.ts +148 -0
  59. package/esm/src/evals/rubrics/catalog.js +846 -0
  60. package/esm/src/evals/rubrics/mod.d.ts +24 -0
  61. package/esm/src/evals/rubrics/mod.js +55 -0
  62. package/esm/src/evals/rubrics/mustache.d.ts +23 -0
  63. package/esm/src/evals/rubrics/mustache.js +154 -0
  64. package/esm/src/evals/rubrics/types.d.ts +54 -0
  65. package/esm/src/evals/rubrics/types.js +74 -0
  66. package/esm/src/evals/run.d.ts +75 -0
  67. package/esm/src/evals/run.js +418 -0
  68. package/esm/src/evals/suite.d.ts +28 -0
  69. package/esm/src/evals/suite.js +97 -0
  70. package/esm/src/evals/summary.d.ts +35 -0
  71. package/esm/src/evals/summary.js +31 -0
  72. package/esm/src/evals/trial.d.ts +14 -0
  73. package/esm/src/evals/trial.js +135 -0
  74. package/esm/src/evals/types.d.ts +169 -0
  75. package/esm/src/evals/types.js +113 -0
  76. package/esm/src/evals/verdict.d.ts +23 -0
  77. package/esm/src/evals/verdict.js +48 -0
  78. package/esm/src/guardrails/boundaries.d.ts +41 -0
  79. package/esm/src/guardrails/boundaries.js +103 -0
  80. package/esm/src/guardrails/canary-gate.d.ts +22 -0
  81. package/esm/src/guardrails/canary-gate.js +40 -0
  82. package/esm/src/guardrails/canary.d.ts +146 -0
  83. package/esm/src/guardrails/canary.js +974 -0
  84. package/esm/src/guardrails/compile-egress.d.ts +12 -0
  85. package/esm/src/guardrails/compile-egress.js +12 -0
  86. package/esm/src/guardrails/corpus/canary-egress-attacks.d.ts +24 -0
  87. package/esm/src/guardrails/corpus/canary-egress-attacks.js +305 -0
  88. package/esm/src/guardrails/corpus/fuzz-inbound.d.ts +5 -0
  89. package/esm/src/guardrails/corpus/fuzz-inbound.js +199 -0
  90. package/esm/src/guardrails/corpus/inbound-payloads.d.ts +5 -0
  91. package/esm/src/guardrails/corpus/inbound-payloads.js +120 -0
  92. package/esm/src/guardrails/corpus/live-attacks.d.ts +15 -0
  93. package/esm/src/guardrails/corpus/live-attacks.js +229 -0
  94. package/esm/src/guardrails/corpus/mod.d.ts +7 -0
  95. package/esm/src/guardrails/corpus/mod.js +4 -0
  96. package/esm/src/guardrails/corpus/secrets.d.ts +12 -0
  97. package/esm/src/guardrails/corpus/secrets.js +16 -0
  98. package/esm/src/guardrails/corpus/strings.d.ts +23 -0
  99. package/esm/src/guardrails/corpus/strings.js +29 -0
  100. package/esm/src/guardrails/corpus/types.d.ts +36 -0
  101. package/esm/src/guardrails/corpus/types.js +1 -0
  102. package/esm/src/guardrails/credential-rules.d.ts +36 -0
  103. package/esm/src/guardrails/credential-rules.js +3001 -0
  104. package/esm/src/guardrails/credential-scan.d.ts +45 -0
  105. package/esm/src/guardrails/credential-scan.js +172 -0
  106. package/esm/src/guardrails/destinations.d.ts +45 -0
  107. package/esm/src/guardrails/destinations.js +234 -0
  108. package/esm/src/guardrails/detect-at.d.ts +107 -0
  109. package/esm/src/guardrails/detect-at.js +434 -0
  110. package/esm/src/guardrails/detect-reply.d.ts +61 -0
  111. package/esm/src/guardrails/detect-reply.js +95 -0
  112. package/esm/src/guardrails/detect-stream.d.ts +33 -0
  113. package/esm/src/guardrails/detect-stream.js +77 -0
  114. package/esm/src/guardrails/detectors.d.ts +216 -0
  115. package/esm/src/guardrails/detectors.js +503 -0
  116. package/esm/src/guardrails/egress-automata.d.ts +12 -0
  117. package/esm/src/guardrails/egress-automata.js +25582 -0
  118. package/esm/src/guardrails/egress-compiler.d.ts +55 -0
  119. package/esm/src/guardrails/egress-compiler.js +431 -0
  120. package/esm/src/guardrails/egress-patterns.d.ts +26 -0
  121. package/esm/src/guardrails/egress-patterns.js +36 -0
  122. package/esm/src/guardrails/egress-stream.d.ts +123 -0
  123. package/esm/src/guardrails/egress-stream.js +774 -0
  124. package/esm/src/guardrails/egress-urls.d.ts +86 -0
  125. package/esm/src/guardrails/egress-urls.js +909 -0
  126. package/esm/src/guardrails/egress.d.ts +46 -0
  127. package/esm/src/guardrails/egress.js +124 -0
  128. package/esm/src/guardrails/error.d.ts +31 -0
  129. package/esm/src/guardrails/error.js +96 -0
  130. package/esm/src/guardrails/event-schemas.d.ts +100 -0
  131. package/esm/src/guardrails/event-schemas.js +48 -0
  132. package/esm/src/guardrails/events.d.ts +13 -0
  133. package/esm/src/guardrails/events.js +45 -0
  134. package/esm/src/guardrails/hints.d.ts +14 -0
  135. package/esm/src/guardrails/hints.js +57 -0
  136. package/esm/src/guardrails/hits.d.ts +14 -0
  137. package/esm/src/guardrails/hits.js +30 -0
  138. package/esm/src/guardrails/host-patterns.d.ts +85 -0
  139. package/esm/src/guardrails/host-patterns.js +173 -0
  140. package/esm/src/guardrails/injection-patterns.d.ts +20 -0
  141. package/esm/src/guardrails/injection-patterns.js +126 -0
  142. package/esm/src/guardrails/injection-reversed.d.ts +9 -0
  143. package/esm/src/guardrails/injection-reversed.js +49 -0
  144. package/esm/src/guardrails/injection.d.ts +30 -0
  145. package/esm/src/guardrails/injection.js +460 -0
  146. package/esm/src/guardrails/labels.d.ts +40 -0
  147. package/esm/src/guardrails/labels.js +874 -0
  148. package/esm/src/guardrails/live-outbound-gate.d.ts +55 -0
  149. package/esm/src/guardrails/live-outbound-gate.js +298 -0
  150. package/esm/src/guardrails/mod.d.ts +54 -0
  151. package/esm/src/guardrails/mod.js +34 -0
  152. package/esm/src/guardrails/network.d.ts +46 -0
  153. package/esm/src/guardrails/network.js +330 -0
  154. package/esm/src/guardrails/normalize.d.ts +20 -0
  155. package/esm/src/guardrails/normalize.js +165 -0
  156. package/esm/src/guardrails/policy.d.ts +4 -0
  157. package/esm/src/guardrails/policy.js +21 -0
  158. package/esm/src/guardrails/progressive-yield.d.ts +110 -0
  159. package/esm/src/guardrails/progressive-yield.js +281 -0
  160. package/esm/src/guardrails/prompt-echo.d.ts +40 -0
  161. package/esm/src/guardrails/prompt-echo.js +306 -0
  162. package/esm/src/guardrails/quota.d.ts +21 -0
  163. package/esm/src/guardrails/quota.js +80 -0
  164. package/esm/src/guardrails/rules.d.ts +47 -0
  165. package/esm/src/guardrails/rules.js +47 -0
  166. package/esm/src/guardrails/sanitize.d.ts +40 -0
  167. package/esm/src/guardrails/sanitize.js +160 -0
  168. package/esm/src/guardrails/sensitive-groups.d.ts +21 -0
  169. package/esm/src/guardrails/sensitive-groups.js +12 -0
  170. package/esm/src/guardrails/sensitive.d.ts +22 -0
  171. package/esm/src/guardrails/sensitive.js +234 -0
  172. package/esm/src/guardrails/serialize.d.ts +15 -0
  173. package/esm/src/guardrails/serialize.js +37 -0
  174. package/esm/src/guardrails/testing.d.ts +11 -0
  175. package/esm/src/guardrails/testing.js +10 -0
  176. package/esm/src/guardrails/theorem-error.d.ts +21 -0
  177. package/esm/src/guardrails/theorem-error.js +54 -0
  178. package/esm/src/guardrails/thought-guard.d.ts +76 -0
  179. package/esm/src/guardrails/thought-guard.js +664 -0
  180. package/esm/src/guardrails/tool-directives.d.ts +38 -0
  181. package/esm/src/guardrails/tool-directives.js +195 -0
  182. package/esm/src/guardrails/tool-leak.d.ts +26 -0
  183. package/esm/src/guardrails/tool-leak.js +45 -0
  184. package/esm/src/guardrails/tool-result.d.ts +92 -0
  185. package/esm/src/guardrails/tool-result.js +272 -0
  186. package/esm/src/guardrails/types.d.ts +250 -0
  187. package/esm/src/guardrails/types.js +58 -0
  188. package/esm/src/host/client-turn.d.ts +36 -0
  189. package/esm/src/host/client-turn.js +80 -0
  190. package/esm/src/host/mint-trace.d.ts +29 -0
  191. package/esm/src/host/mint-trace.js +60 -0
  192. package/esm/src/host/mod.d.ts +13 -0
  193. package/esm/src/host/mod.js +11 -0
  194. package/esm/src/host/readStreamingJsonStringField.d.ts +2 -0
  195. package/esm/src/host/readStreamingJsonStringField.js +27 -0
  196. package/esm/src/host/reply.d.ts +13 -0
  197. package/esm/src/host/reply.js +41 -0
  198. package/esm/src/interface/blocks.d.ts +11 -0
  199. package/esm/src/interface/blocks.js +283 -0
  200. package/esm/src/interface/composer-actions.d.ts +24 -0
  201. package/esm/src/interface/composer-actions.js +33 -0
  202. package/esm/src/interface/draft.d.ts +20 -0
  203. package/esm/src/interface/draft.js +39 -0
  204. package/esm/src/interface/from-profile.d.ts +24 -0
  205. package/esm/src/interface/from-profile.js +179 -0
  206. package/esm/src/interface/history.d.ts +46 -0
  207. package/esm/src/interface/history.js +278 -0
  208. package/esm/src/interface/inputs.d.ts +11 -0
  209. package/esm/src/interface/inputs.js +67 -0
  210. package/esm/src/interface/mod.d.ts +33 -0
  211. package/esm/src/interface/mod.js +22 -0
  212. package/esm/src/interface/models.d.ts +26 -0
  213. package/esm/src/interface/models.js +50 -0
  214. package/esm/src/interface/pending.d.ts +57 -0
  215. package/esm/src/interface/pending.js +152 -0
  216. package/esm/src/interface/profile-interface.d.ts +4 -0
  217. package/esm/src/interface/profile-interface.js +237 -0
  218. package/esm/src/interface/session.d.ts +71 -0
  219. package/esm/src/interface/session.js +128 -0
  220. package/esm/src/interface/stop.d.ts +13 -0
  221. package/esm/src/interface/stop.js +28 -0
  222. package/esm/src/interface/tool-calls.d.ts +32 -0
  223. package/esm/src/interface/tool-calls.js +127 -0
  224. package/esm/src/interface/tool-invoke.d.ts +6 -0
  225. package/esm/src/interface/tool-invoke.js +22 -0
  226. package/esm/src/interface/tool-media.d.ts +11 -0
  227. package/esm/src/interface/tool-media.js +113 -0
  228. package/esm/src/interface/types.d.ts +278 -0
  229. package/esm/src/interface/types.js +5 -0
  230. package/esm/src/kernel/api-catalog.d.ts +85 -0
  231. package/esm/src/kernel/api-catalog.js +229 -0
  232. package/esm/src/kernel/auth/credential-source.d.ts +23 -0
  233. package/esm/src/kernel/auth/credential-source.js +11 -0
  234. package/esm/src/kernel/auth/crypto.d.ts +56 -0
  235. package/esm/src/kernel/auth/crypto.js +163 -0
  236. package/esm/src/kernel/auth/mod.d.ts +5 -0
  237. package/esm/src/kernel/auth/mod.js +5 -0
  238. package/esm/src/kernel/auth/oauth.d.ts +18 -0
  239. package/esm/src/kernel/auth/oauth.js +439 -0
  240. package/esm/src/kernel/auth/scope-refusal.d.ts +9 -0
  241. package/esm/src/kernel/auth/scope-refusal.js +8 -0
  242. package/esm/src/kernel/auth/typed-secret.d.ts +13 -0
  243. package/esm/src/kernel/auth/typed-secret.js +23 -0
  244. package/esm/src/kernel/auth/types.d.ts +152 -0
  245. package/esm/src/kernel/auth/types.js +1 -0
  246. package/esm/src/kernel/checkpoint.d.ts +43 -0
  247. package/esm/src/kernel/checkpoint.js +58 -0
  248. package/esm/src/kernel/default-scope.d.ts +72 -0
  249. package/esm/src/kernel/default-scope.js +121 -0
  250. package/esm/src/kernel/engine/call-trace.d.ts +19 -0
  251. package/esm/src/kernel/engine/call-trace.js +29 -0
  252. package/esm/src/kernel/engine/compaction.d.ts +71 -0
  253. package/esm/src/kernel/engine/compaction.js +203 -0
  254. package/esm/src/kernel/engine/decision.d.ts +43 -0
  255. package/esm/src/kernel/engine/decision.js +439 -0
  256. package/esm/src/kernel/engine/embedding.d.ts +8 -0
  257. package/esm/src/kernel/engine/embedding.js +118 -0
  258. package/esm/src/kernel/engine/hash.d.ts +6 -0
  259. package/esm/src/kernel/engine/hash.js +22 -0
  260. package/esm/src/kernel/engine/live-inbound.d.ts +19 -0
  261. package/esm/src/kernel/engine/live-inbound.js +44 -0
  262. package/esm/src/kernel/engine/live-ingress.d.ts +15 -0
  263. package/esm/src/kernel/engine/live-ingress.js +42 -0
  264. package/esm/src/kernel/engine/record.d.ts +3 -0
  265. package/esm/src/kernel/engine/record.js +11 -0
  266. package/esm/src/kernel/engine/repair.d.ts +7 -0
  267. package/esm/src/kernel/engine/repair.js +36 -0
  268. package/esm/src/kernel/engine/runner/gates.d.ts +5 -0
  269. package/esm/src/kernel/engine/runner/gates.js +508 -0
  270. package/esm/src/kernel/engine/runner/mod.d.ts +29 -0
  271. package/esm/src/kernel/engine/runner/mod.js +625 -0
  272. package/esm/src/kernel/engine/runner/nested.d.ts +32 -0
  273. package/esm/src/kernel/engine/runner/nested.js +134 -0
  274. package/esm/src/kernel/engine/runner/schema-validation.d.ts +35 -0
  275. package/esm/src/kernel/engine/runner/schema-validation.js +179 -0
  276. package/esm/src/kernel/engine/runner/stages.d.ts +28 -0
  277. package/esm/src/kernel/engine/runner/stages.js +41 -0
  278. package/esm/src/kernel/engine/runner/state.d.ts +97 -0
  279. package/esm/src/kernel/engine/runner/state.js +50 -0
  280. package/esm/src/kernel/engine/runner/step-order.d.ts +27 -0
  281. package/esm/src/kernel/engine/runner/step-order.js +165 -0
  282. package/esm/src/kernel/engine/runner/steps.d.ts +14 -0
  283. package/esm/src/kernel/engine/runner/steps.js +519 -0
  284. package/esm/src/kernel/engine/runner/stream.d.ts +71 -0
  285. package/esm/src/kernel/engine/runner/stream.js +376 -0
  286. package/esm/src/kernel/engine/runner/usage.d.ts +45 -0
  287. package/esm/src/kernel/engine/runner/usage.js +148 -0
  288. package/esm/src/kernel/engine/session/mod.d.ts +33 -0
  289. package/esm/src/kernel/engine/session/mod.js +1182 -0
  290. package/esm/src/kernel/engine/session/session-trace.d.ts +115 -0
  291. package/esm/src/kernel/engine/session/session-trace.js +500 -0
  292. package/esm/src/kernel/engine/token-estimate.d.ts +23 -0
  293. package/esm/src/kernel/engine/token-estimate.js +38 -0
  294. package/esm/src/kernel/engine/tool-trace.d.ts +58 -0
  295. package/esm/src/kernel/engine/tool-trace.js +132 -0
  296. package/esm/src/kernel/engine/tree.d.ts +2 -0
  297. package/esm/src/kernel/engine/tree.js +17 -0
  298. package/esm/src/kernel/engine/turn-trace.d.ts +119 -0
  299. package/esm/src/kernel/engine/turn-trace.js +855 -0
  300. package/esm/src/kernel/engine/usage.d.ts +36 -0
  301. package/esm/src/kernel/engine/usage.js +151 -0
  302. package/esm/src/kernel/interaction-parts.d.ts +13 -0
  303. package/esm/src/kernel/interaction-parts.js +40 -0
  304. package/esm/src/kernel/json.d.ts +10 -0
  305. package/esm/src/kernel/json.js +3 -0
  306. package/esm/src/kernel/mod.d.ts +74 -0
  307. package/esm/src/kernel/mod.js +45 -0
  308. package/esm/src/kernel/profile-graph.d.ts +145 -0
  309. package/esm/src/kernel/profile-graph.js +158 -0
  310. package/esm/src/kernel/profile-presence.d.ts +18 -0
  311. package/esm/src/kernel/profile-presence.js +158 -0
  312. package/esm/src/kernel/profile-scope.d.ts +40 -0
  313. package/esm/src/kernel/profile-scope.js +274 -0
  314. package/esm/src/kernel/protocols/binding.d.ts +65 -0
  315. package/esm/src/kernel/protocols/binding.js +125 -0
  316. package/esm/src/kernel/protocols/limits.d.ts +15 -0
  317. package/esm/src/kernel/protocols/limits.js +28 -0
  318. package/esm/src/kernel/protocols/mod.d.ts +5 -0
  319. package/esm/src/kernel/protocols/mod.js +5 -0
  320. package/esm/src/kernel/protocols/prices.d.ts +36 -0
  321. package/esm/src/kernel/protocols/prices.js +37 -0
  322. package/esm/src/kernel/protocols/protocol.d.ts +253 -0
  323. package/esm/src/kernel/protocols/protocol.js +253 -0
  324. package/esm/src/kernel/protocols/provider.d.ts +108 -0
  325. package/esm/src/kernel/protocols/provider.js +143 -0
  326. package/esm/src/kernel/protocols/runtime.d.ts +55 -0
  327. package/esm/src/kernel/protocols/runtime.js +534 -0
  328. package/esm/src/kernel/provider-budget.d.ts +32 -0
  329. package/esm/src/kernel/provider-budget.js +262 -0
  330. package/esm/src/kernel/provider-dispatch.d.ts +13 -0
  331. package/esm/src/kernel/provider-dispatch.js +36 -0
  332. package/esm/src/kernel/provider-live.d.ts +7 -0
  333. package/esm/src/kernel/provider-live.js +189 -0
  334. package/esm/src/kernel/provider-runtime.d.ts +57 -0
  335. package/esm/src/kernel/provider-runtime.js +524 -0
  336. package/esm/src/kernel/registry/attachments.d.ts +46 -0
  337. package/esm/src/kernel/registry/attachments.js +220 -0
  338. package/esm/src/kernel/registry/catalog.d.ts +25 -0
  339. package/esm/src/kernel/registry/catalog.js +85 -0
  340. package/esm/src/kernel/registry/embedding-rules.d.ts +28 -0
  341. package/esm/src/kernel/registry/embedding-rules.js +66 -0
  342. package/esm/src/kernel/registry/ingress.d.ts +12 -0
  343. package/esm/src/kernel/registry/ingress.js +179 -0
  344. package/esm/src/kernel/registry/kernel-registry.d.ts +15 -0
  345. package/esm/src/kernel/registry/kernel-registry.js +15 -0
  346. package/esm/src/kernel/registry/profile-outputs.d.ts +3 -0
  347. package/esm/src/kernel/registry/profile-outputs.js +10 -0
  348. package/esm/src/kernel/registry/profiles.d.ts +116 -0
  349. package/esm/src/kernel/registry/profiles.js +773 -0
  350. package/esm/src/kernel/registry/provider-request.d.ts +6 -0
  351. package/esm/src/kernel/registry/provider-request.js +34 -0
  352. package/esm/src/kernel/registry/resolve.d.ts +17 -0
  353. package/esm/src/kernel/registry/resolve.js +238 -0
  354. package/esm/src/kernel/registry/schemas.d.ts +12 -0
  355. package/esm/src/kernel/registry/schemas.js +27 -0
  356. package/esm/src/kernel/registry/slot-fill.d.ts +7 -0
  357. package/esm/src/kernel/registry/slot-fill.js +22 -0
  358. package/esm/src/kernel/registry/sole-model.d.ts +2 -0
  359. package/esm/src/kernel/registry/sole-model.js +4 -0
  360. package/esm/src/kernel/registry/system-prompt.d.ts +8 -0
  361. package/esm/src/kernel/registry/system-prompt.js +32 -0
  362. package/esm/src/kernel/registry/system-role.d.ts +3 -0
  363. package/esm/src/kernel/registry/system-role.js +9 -0
  364. package/esm/src/kernel/registry/vault.d.ts +14 -0
  365. package/esm/src/kernel/registry/vault.js +1 -0
  366. package/esm/src/kernel/schema.d.ts +226 -0
  367. package/esm/src/kernel/schema.js +895 -0
  368. package/esm/src/kernel/scope.d.ts +29 -0
  369. package/esm/src/kernel/scope.js +45 -0
  370. package/esm/src/kernel/stages.d.ts +176 -0
  371. package/esm/src/kernel/stages.js +431 -0
  372. package/esm/src/kernel/stop.d.ts +116 -0
  373. package/esm/src/kernel/stop.js +137 -0
  374. package/esm/src/kernel/system-parts.d.ts +26 -0
  375. package/esm/src/kernel/system-parts.js +98 -0
  376. package/esm/src/kernel/tools/activity-label.d.ts +22 -0
  377. package/esm/src/kernel/tools/activity-label.js +435 -0
  378. package/esm/src/kernel/tools/agent.d.ts +66 -0
  379. package/esm/src/kernel/tools/agent.js +212 -0
  380. package/esm/src/kernel/tools/coordinate.d.ts +4 -0
  381. package/esm/src/kernel/tools/coordinate.js +165 -0
  382. package/esm/src/kernel/tools/events.d.ts +66 -0
  383. package/esm/src/kernel/tools/events.js +184 -0
  384. package/esm/src/kernel/tools/execute.d.ts +100 -0
  385. package/esm/src/kernel/tools/execute.js +1173 -0
  386. package/esm/src/kernel/tools/gate-answer.d.ts +60 -0
  387. package/esm/src/kernel/tools/gate-answer.js +65 -0
  388. package/esm/src/kernel/tools/handler-events.d.ts +45 -0
  389. package/esm/src/kernel/tools/handler-events.js +106 -0
  390. package/esm/src/kernel/tools/harness.d.ts +17 -0
  391. package/esm/src/kernel/tools/harness.js +43 -0
  392. package/esm/src/kernel/tools/http-limit.d.ts +27 -0
  393. package/esm/src/kernel/tools/http-limit.js +85 -0
  394. package/esm/src/kernel/tools/invoke.d.ts +32 -0
  395. package/esm/src/kernel/tools/invoke.js +282 -0
  396. package/esm/src/kernel/tools/mcp-sessions.d.ts +23 -0
  397. package/esm/src/kernel/tools/mcp-sessions.js +69 -0
  398. package/esm/src/kernel/tools/mod.d.ts +10 -0
  399. package/esm/src/kernel/tools/mod.js +7 -0
  400. package/esm/src/kernel/tools/model-text.d.ts +16 -0
  401. package/esm/src/kernel/tools/model-text.js +31 -0
  402. package/esm/src/kernel/tools/operation.d.ts +76 -0
  403. package/esm/src/kernel/tools/operation.js +100 -0
  404. package/esm/src/kernel/tools/page-answer.d.ts +8 -0
  405. package/esm/src/kernel/tools/page-answer.js +19 -0
  406. package/esm/src/kernel/tools/permission.d.ts +15 -0
  407. package/esm/src/kernel/tools/permission.js +38 -0
  408. package/esm/src/kernel/tools/project.d.ts +11 -0
  409. package/esm/src/kernel/tools/project.js +55 -0
  410. package/esm/src/kernel/tools/registry.d.ts +27 -0
  411. package/esm/src/kernel/tools/registry.js +143 -0
  412. package/esm/src/kernel/tools/remote.d.ts +144 -0
  413. package/esm/src/kernel/tools/remote.js +1125 -0
  414. package/esm/src/kernel/tools/resolve.d.ts +31 -0
  415. package/esm/src/kernel/tools/resolve.js +267 -0
  416. package/esm/src/kernel/tools/run.d.ts +28 -0
  417. package/esm/src/kernel/tools/run.js +86 -0
  418. package/esm/src/kernel/tools/schema.d.ts +10 -0
  419. package/esm/src/kernel/tools/schema.js +95 -0
  420. package/esm/src/kernel/tools/signed-in-fetch.d.ts +19 -0
  421. package/esm/src/kernel/tools/signed-in-fetch.js +45 -0
  422. package/esm/src/kernel/tools/stage-run.d.ts +116 -0
  423. package/esm/src/kernel/tools/stage-run.js +198 -0
  424. package/esm/src/kernel/tools/types.d.ts +497 -0
  425. package/esm/src/kernel/tools/types.js +1 -0
  426. package/esm/src/kernel/tools/unchecked-output.d.ts +14 -0
  427. package/esm/src/kernel/tools/unchecked-output.js +18 -0
  428. package/esm/src/kernel/turn-events.d.ts +776 -0
  429. package/esm/src/kernel/turn-events.js +543 -0
  430. package/esm/src/kernel/types.d.ts +1025 -0
  431. package/esm/src/kernel/types.js +1 -0
  432. package/esm/src/kernel/util/base64.d.ts +4 -0
  433. package/esm/src/kernel/util/base64.js +15 -0
  434. package/esm/src/kernel/util/exact-type.d.ts +31 -0
  435. package/esm/src/kernel/util/exact-type.js +1 -0
  436. package/esm/src/kernel/util/find-last.d.ts +3 -0
  437. package/esm/src/kernel/util/find-last.js +9 -0
  438. package/esm/src/kernel/util/mime.d.ts +2 -0
  439. package/esm/src/kernel/util/mime.js +4 -0
  440. package/esm/src/kernel/util/partial-json.d.ts +23 -0
  441. package/esm/src/kernel/util/partial-json.js +128 -0
  442. package/esm/src/kernel/util/record.d.ts +2 -0
  443. package/esm/src/kernel/util/record.js +4 -0
  444. package/esm/src/observability/destinations.d.ts +14 -0
  445. package/esm/src/observability/destinations.js +43 -0
  446. package/esm/src/observability/jsonl.d.ts +18 -0
  447. package/esm/src/observability/jsonl.js +110 -0
  448. package/esm/src/observability/mod.d.ts +22 -0
  449. package/esm/src/observability/mod.js +16 -0
  450. package/esm/src/observability/openinference.d.ts +11 -0
  451. package/esm/src/observability/openinference.js +205 -0
  452. package/esm/src/observability/otlp.d.ts +71 -0
  453. package/esm/src/observability/otlp.js +98 -0
  454. package/esm/src/observability/phoenix.d.ts +30 -0
  455. package/esm/src/observability/phoenix.js +71 -0
  456. package/esm/src/observability/policy.d.ts +17 -0
  457. package/esm/src/observability/policy.js +73 -0
  458. package/esm/src/observability/resolve-policy.d.ts +8 -0
  459. package/esm/src/observability/resolve-policy.js +64 -0
  460. package/esm/src/observability/spans.d.ts +22 -0
  461. package/esm/src/observability/spans.js +72 -0
  462. package/esm/src/observability/trace-catalog.d.ts +128 -0
  463. package/esm/src/observability/trace-catalog.js +906 -0
  464. package/esm/src/observability/trace-record.d.ts +23 -0
  465. package/esm/src/observability/trace-record.js +228 -0
  466. package/esm/src/observability/trace-schema.d.ts +57 -0
  467. package/esm/src/observability/trace-schema.js +59 -0
  468. package/esm/src/observability/trace-sink.d.ts +14 -0
  469. package/esm/src/observability/trace-sink.js +3 -0
  470. package/esm/src/observability/trace-span.d.ts +98 -0
  471. package/esm/src/observability/trace-span.js +201 -0
  472. package/esm/src/observability/trace.d.ts +13 -0
  473. package/esm/src/observability/trace.js +37 -0
  474. package/esm/src/observability/types.d.ts +109 -0
  475. package/esm/src/observability/types.js +3 -0
  476. package/esm/src/presets/google/speech-voices.d.ts +9 -0
  477. package/esm/src/presets/google/speech-voices.js +38 -0
  478. package/esm/src/presets/google-limits.d.ts +13 -0
  479. package/esm/src/presets/google-limits.js +18 -0
  480. package/esm/src/presets/google.d.ts +119 -0
  481. package/esm/src/presets/google.js +197 -0
  482. package/esm/src/presets/local.d.ts +26 -0
  483. package/esm/src/presets/local.js +30 -0
  484. package/esm/src/presets/mod.d.ts +11 -0
  485. package/esm/src/presets/mod.js +9 -0
  486. package/esm/src/presets/openrouter.d.ts +26 -0
  487. package/esm/src/presets/openrouter.js +31 -0
  488. package/esm/src/providers/embedding-limits.d.ts +7 -0
  489. package/esm/src/providers/embedding-limits.js +12 -0
  490. package/esm/src/providers/gemini/embedding-protocol.d.ts +8 -0
  491. package/esm/src/providers/gemini/embedding-protocol.js +125 -0
  492. package/esm/src/providers/gemini/interactions-protocol.d.ts +8 -0
  493. package/esm/src/providers/gemini/interactions-protocol.js +105 -0
  494. package/esm/src/providers/gemini/live-protocol.d.ts +3 -0
  495. package/esm/src/providers/gemini/live-protocol.js +191 -0
  496. package/esm/src/providers/gemini/prices.d.ts +3 -0
  497. package/esm/src/providers/gemini/prices.js +63 -0
  498. package/esm/src/providers/gemini/provider.d.ts +7 -0
  499. package/esm/src/providers/gemini/provider.js +39 -0
  500. package/esm/src/providers/google/api-error.d.ts +8 -0
  501. package/esm/src/providers/google/api-error.js +123 -0
  502. package/esm/src/providers/google/builtins.d.ts +14 -0
  503. package/esm/src/providers/google/builtins.js +57 -0
  504. package/esm/src/providers/google/grounding.d.ts +5 -0
  505. package/esm/src/providers/google/grounding.js +226 -0
  506. package/esm/src/providers/google/interactions/framing.d.ts +27 -0
  507. package/esm/src/providers/google/interactions/framing.js +304 -0
  508. package/esm/src/providers/google/interactions/steps.d.ts +12 -0
  509. package/esm/src/providers/google/interactions/steps.js +200 -0
  510. package/esm/src/providers/google/interactions/stream.d.ts +23 -0
  511. package/esm/src/providers/google/interactions/stream.js +230 -0
  512. package/esm/src/providers/google/live/framing.d.ts +61 -0
  513. package/esm/src/providers/google/live/framing.js +597 -0
  514. package/esm/src/providers/google/live/stream.d.ts +13 -0
  515. package/esm/src/providers/google/live/stream.js +57 -0
  516. package/esm/src/providers/google/thinking.d.ts +3 -0
  517. package/esm/src/providers/google/thinking.js +8 -0
  518. package/esm/src/providers/google/urls.d.ts +4 -0
  519. package/esm/src/providers/google/urls.js +4 -0
  520. package/esm/src/providers/google/usage.d.ts +7 -0
  521. package/esm/src/providers/google/usage.js +49 -0
  522. package/esm/src/providers/live.d.ts +6 -0
  523. package/esm/src/providers/live.js +6 -0
  524. package/esm/src/providers/local/embedding-protocol.d.ts +7 -0
  525. package/esm/src/providers/local/embedding-protocol.js +60 -0
  526. package/esm/src/providers/local/provider.d.ts +7 -0
  527. package/esm/src/providers/local/provider.js +28 -0
  528. package/esm/src/providers/mod.d.ts +32 -0
  529. package/esm/src/providers/mod.js +23 -0
  530. package/esm/src/providers/open-ai/protocol.d.ts +3 -0
  531. package/esm/src/providers/open-ai/protocol.js +189 -0
  532. package/esm/src/providers/openrouter/embedding-protocol.d.ts +6 -0
  533. package/esm/src/providers/openrouter/embedding-protocol.js +86 -0
  534. package/esm/src/providers/openrouter/image.d.ts +15 -0
  535. package/esm/src/providers/openrouter/image.js +34 -0
  536. package/esm/src/providers/openrouter/images-protocol.d.ts +3 -0
  537. package/esm/src/providers/openrouter/images-protocol.js +82 -0
  538. package/esm/src/providers/openrouter/openai/compat.d.ts +19 -0
  539. package/esm/src/providers/openrouter/openai/compat.js +162 -0
  540. package/esm/src/providers/openrouter/openai/image-payload.d.ts +9 -0
  541. package/esm/src/providers/openrouter/openai/image-payload.js +115 -0
  542. package/esm/src/providers/openrouter/openai/reasoning-state.d.ts +2 -0
  543. package/esm/src/providers/openrouter/openai/reasoning-state.js +31 -0
  544. package/esm/src/providers/openrouter/openai/usage.d.ts +8 -0
  545. package/esm/src/providers/openrouter/openai/usage.js +56 -0
  546. package/esm/src/providers/openrouter/protocol.d.ts +8 -0
  547. package/esm/src/providers/openrouter/protocol.js +171 -0
  548. package/esm/src/providers/openrouter/provider.d.ts +10 -0
  549. package/esm/src/providers/openrouter/provider.js +50 -0
  550. package/esm/src/providers/shared/carried-tool-files.d.ts +7 -0
  551. package/esm/src/providers/shared/carried-tool-files.js +43 -0
  552. package/esm/src/providers/shared/pcm.d.ts +14 -0
  553. package/esm/src/providers/shared/pcm.js +78 -0
  554. package/esm/src/providers/shared/protocol-events.d.ts +8 -0
  555. package/esm/src/providers/shared/protocol-events.js +20 -0
  556. package/esm/src/providers/shared/response-identity.d.ts +11 -0
  557. package/esm/src/providers/shared/response-identity.js +12 -0
  558. package/esm/src/providers/shared/retry.d.ts +17 -0
  559. package/esm/src/providers/shared/retry.js +90 -0
  560. package/esm/src/providers/shared/sse.d.ts +6 -0
  561. package/esm/src/providers/shared/sse.js +93 -0
  562. package/esm/src/providers/shared/structured-output.d.ts +4 -0
  563. package/esm/src/providers/shared/structured-output.js +11 -0
  564. package/esm/src/providers/shared/tool-args.d.ts +24 -0
  565. package/esm/src/providers/shared/tool-args.js +88 -0
  566. package/esm/src/providers/shared/tool-draft.d.ts +16 -0
  567. package/esm/src/providers/shared/tool-draft.js +14 -0
  568. package/esm/src/providers/shared/upstream-tap.d.ts +8 -0
  569. package/esm/src/providers/shared/upstream-tap.js +85 -0
  570. package/esm/src/providers/shared/upstream-tape.d.ts +6 -0
  571. package/esm/src/providers/shared/upstream-tape.js +88 -0
  572. package/esm/src/providers/system-one/protocol.d.ts +8 -0
  573. package/esm/src/providers/system-one/protocol.js +93 -0
  574. package/esm/src/providers/types.d.ts +51 -0
  575. package/esm/src/providers/types.js +2 -0
  576. package/esm/src/providers/typesafe/provider.d.ts +7 -0
  577. package/esm/src/providers/typesafe/provider.js +24 -0
  578. package/esm/src/surface/formats.d.ts +46 -0
  579. package/esm/src/surface/formats.js +178 -0
  580. package/esm/src/surface/mod.d.ts +16 -0
  581. package/esm/src/surface/mod.js +12 -0
  582. package/esm/src/surface/runtime.d.ts +44 -0
  583. package/esm/src/surface/runtime.js +441 -0
  584. package/esm/src/surface/tools.d.ts +9 -0
  585. package/esm/src/surface/tools.js +62 -0
  586. package/esm/src/surface/types.d.ts +110 -0
  587. package/esm/src/surface/types.js +4 -0
  588. package/package.json +100 -4
@@ -0,0 +1,906 @@
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. */
3
+ const TRACE_ATTRIBUTE_GROUPS = {
4
+ agent: { label: 'Agent', doc: 'Which agent ran, for which conversation, and how it ended.' },
5
+ request: { label: 'Request', doc: 'What theorem asked the provider for.' },
6
+ response: { label: 'Response', doc: 'What the provider said about its answer.' },
7
+ messages: { label: 'Messages', doc: 'What was read and written, stored by hash.' },
8
+ usage: { label: 'Usage', doc: 'Tokens and cost, as reported or estimated.' },
9
+ tool: { label: 'Tool', doc: 'The tool call, its arguments, and how it settled.' },
10
+ http: { label: 'HTTP', doc: 'One HTTP try: where it went and what came back.' },
11
+ error: { label: 'Error', doc: 'Why it failed.' },
12
+ record: { label: 'Record', doc: 'What this record kept and how it was taken.' },
13
+ part: { label: 'Part', doc: 'Facts about one message part.' },
14
+ decision: {
15
+ label: 'Decision',
16
+ doc: 'The state a decision read, the questions it answered, and its answers.',
17
+ },
18
+ evaluation: { label: 'Evaluation', doc: 'How an eval graded this trace, and by which suite.' },
19
+ };
20
+ /** Labels and descriptions for each span status. */
21
+ const TRACE_STATUS = {
22
+ OK: { label: 'OK', doc: 'Finished as intended.' },
23
+ ERROR: { label: 'Error', doc: 'Failed; the error kind says why.' },
24
+ UNSET: {
25
+ label: 'Stopped',
26
+ doc: 'Stopped on purpose (cancelled, waiting for approval, paused) or ended with no verdict.',
27
+ },
28
+ };
29
+ /** A record's and a span's own fields, beside their attributes. */
30
+ const TRACE_FIELDS = {
31
+ resource: {
32
+ label: 'Host resource',
33
+ doc: 'Attributes the host set for its process (observability.resource), e.g. service.name.',
34
+ },
35
+ metadata: {
36
+ label: 'Request metadata',
37
+ doc: 'The metadata the host passed on the request, untouched.',
38
+ },
39
+ span: { label: 'Span', doc: 'One timed step of the trace.' },
40
+ type: { label: 'Type', doc: 'What the span is: a turn, a model call, a tool call, an HTTP try.' },
41
+ children: {
42
+ label: 'Spans',
43
+ doc: 'The spans inside this one, in start order: model calls, tool calls, HTTP tries.',
44
+ },
45
+ traceId: { label: 'Trace ID', doc: 'Shared by every span of one trace.' },
46
+ spanId: { label: 'Span ID', doc: "This span's id." },
47
+ status: { label: 'Status', doc: 'How the span ended.' },
48
+ start: { label: 'Started', doc: 'When the span started.' },
49
+ duration: { label: 'Duration', doc: 'From start to end, on the clock the record names.' },
50
+ events: { label: 'Events', doc: 'What happened during the span, in order.' },
51
+ links: { label: 'Links', doc: 'Earlier traces this span follows.' },
52
+ };
53
+ const STOP_KINDS = {
54
+ completed: { label: 'Completed', doc: 'The model finished its answer.' },
55
+ length: { label: 'Hit output limit', doc: 'The model stopped at its output token limit.' },
56
+ tool: {
57
+ label: 'Handed tool to host',
58
+ doc: 'Stopped to hand a tool call back to the host. Deprecated: approval now stops as “Waiting for approval”.',
59
+ },
60
+ gate: {
61
+ label: 'Waiting for approval',
62
+ doc: 'A tool call needs confirmation, permission, or sign-in before it runs; the host resumes it.',
63
+ },
64
+ filtered: {
65
+ label: 'Filtered',
66
+ doc: 'A safety filter or the output guardrail held the answer back.',
67
+ },
68
+ provider_error: { label: 'Provider error', doc: 'The provider reported an error.' },
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
+ },
74
+ stream_incomplete: {
75
+ label: 'Stream cut off',
76
+ doc: "The provider's stream ended before the answer was complete.",
77
+ },
78
+ interrupted: { label: 'Interrupted', doc: 'The user spoke over a Live response.' },
79
+ generation_complete: {
80
+ label: 'Generation complete',
81
+ doc: 'Live: the model finished generating this response; the turn may still be open.',
82
+ },
83
+ go_away: {
84
+ label: 'Closed by provider',
85
+ doc: 'Live: the provider warned the session would end, then closed it.',
86
+ },
87
+ };
88
+ const ERROR_KIND_OPTIONS = {
89
+ config: { label: 'Setup', doc: 'The profile, tool, or schema is set up wrong.' },
90
+ request: { label: 'Host request', doc: 'The host called theorem wrongly.' },
91
+ input: { label: 'User input', doc: 'The user sent input the profile does not accept.' },
92
+ action: { label: 'Not allowed', doc: 'The user asked for something the profile does not allow.' },
93
+ auth: {
94
+ label: 'Credentials',
95
+ doc: 'A missing or rejected credential, or an account that cannot be billed.',
96
+ },
97
+ rate_limit: { label: 'Rate limit', doc: 'Too many requests, or a quota used up.' },
98
+ unsupported: { label: 'Unsupported', doc: 'The model or route cannot serve this request.' },
99
+ unavailable: { label: 'Unavailable', doc: 'The provider is down or overloaded.' },
100
+ bad_response: {
101
+ label: 'Unusable response',
102
+ doc: 'The provider answered with something that cannot be used.',
103
+ },
104
+ network: { label: 'Network', doc: 'The request never reached the provider.' },
105
+ timeout: { label: 'Timeout', doc: 'The model took longer than the host allowed.' },
106
+ safety: { label: 'Safety', doc: 'theorem or the provider held the reply back.' },
107
+ blocked: {
108
+ label: 'Blocked',
109
+ doc: "A guardrail or host policy stopped one of the agent's steps.",
110
+ },
111
+ declined: { label: 'Declined', doc: "The user declined one of the agent's steps." },
112
+ failed: { label: 'Failed', doc: "One of the agent's steps ran and failed." },
113
+ cancelled: { label: 'Cancelled', doc: 'The user or host stopped the turn.' },
114
+ internal: { label: 'Internal', doc: 'A theorem invariant broke.' },
115
+ };
116
+ /** `error.type`: an error kind, or the failing stop. An HTTP status or exception shows as is. */
117
+ const ERROR_TYPE_OPTIONS = {
118
+ ...ERROR_KIND_OPTIONS,
119
+ provider_error: STOP_KINDS.provider_error,
120
+ stream_incomplete: STOP_KINDS.stream_incomplete,
121
+ grader_error: { label: 'Grader failed', doc: 'The grader threw instead of returning a result.' },
122
+ };
123
+ const TOOL_OUTCOMES = {
124
+ ok: { label: 'Succeeded', doc: 'The tool ran and returned a result.' },
125
+ error: { label: 'Failed', doc: 'The tool ran and failed, or could not run.' },
126
+ denied: { label: 'Denied', doc: 'A guardrail, a hook, or the user refused the call.' },
127
+ gated: {
128
+ label: 'Waiting for approval',
129
+ doc: 'The call needs confirmation, permission, or sign-in; it has not run.',
130
+ },
131
+ paused: { label: 'Paused', doc: 'The call was handed back to the host to finish.' },
132
+ cancelled: { label: 'Cancelled', doc: 'The turn was stopped before the call settled.' },
133
+ };
134
+ const TOOL_ORIGIN_OPTIONS = {
135
+ local: { label: 'Host code', doc: 'TypeScript the host registered, run in-process.' },
136
+ builtin: { label: 'Built-in', doc: 'A tool theorem ships.' },
137
+ http: { label: 'HTTP', doc: 'A remote HTTP endpoint.' },
138
+ mcp: { label: 'MCP', doc: 'A tool on an MCP server.' },
139
+ delegated: { label: 'Another agent', doc: 'A specialist agent the tool ran.' },
140
+ };
141
+ const TOOL_PERMISSION_OPTIONS = {
142
+ auto: { label: 'Automatic', doc: 'Runs without asking.' },
143
+ session_consent: { label: 'Ask once', doc: 'Asks once per session, then remembers the answer.' },
144
+ always_confirm: { label: 'Always ask', doc: 'Asks before every call.' },
145
+ };
146
+ const LINK_KINDS = {
147
+ resume: { label: 'Resumes', doc: 'Picks up a call that stopped for approval.' },
148
+ continue: { label: 'Continues', doc: 'Continues an answer that stopped early.' },
149
+ retry: { label: 'Retries', doc: 'Runs a failed turn again.' },
150
+ trial: { label: 'Trial', doc: 'A graded trial of this eval run.' },
151
+ };
152
+ const EVALUATION_SOURCES = {
153
+ code: { label: 'Code', doc: 'A deterministic check over the trace.' },
154
+ model: { label: 'Model', doc: 'A judge profile read the transcript.' },
155
+ };
156
+ const PASS_RULES = {
157
+ all: { label: 'Every trial', doc: 'Passes only when every trial passed (pass^k).' },
158
+ any: { label: 'Any trial', doc: 'Passes when at least one trial passed (pass@k).' },
159
+ at_least: {
160
+ label: 'At least n',
161
+ doc: 'Passes when at least the stated number of trials passed.',
162
+ },
163
+ };
164
+ const EVAL_STOPS = {
165
+ budget: { label: 'Cost ceiling', doc: 'The summed cost crossed the ceiling the host set.' },
166
+ };
167
+ const CASE_KINDS = {
168
+ capability: { label: 'Capability', doc: 'Can the agent do this at all?' },
169
+ regression: { label: 'Regression', doc: 'Does the agent still do this?' },
170
+ };
171
+ const OPERATIONS = {
172
+ invoke_agent: { label: 'Run agent', doc: 'One turn of an agent, or one Live session.' },
173
+ chat: { label: 'Chat', doc: 'A model call over a chat-completions API.' },
174
+ generate_content: { label: 'Generate content', doc: 'A model call over a Gemini API.' },
175
+ execute_tool: { label: 'Run tool', doc: 'A tool call theorem ran.' },
176
+ decide: {
177
+ label: 'Decide',
178
+ doc: 'One model decision: typed answers to questions over JSON state.',
179
+ },
180
+ embeddings: { label: 'Embed', doc: 'One embedding call: a vector for each input.' },
181
+ };
182
+ const OUTPUT_TYPES = {
183
+ text: { label: 'Text', doc: 'The model answers in text.' },
184
+ json: { label: 'JSON', doc: 'The model answers with structured JSON.' },
185
+ image: { label: 'Image', doc: 'The model answers with an image.' },
186
+ speech: { label: 'Speech', doc: 'The model answers in audio.' },
187
+ };
188
+ const PROVIDERS = {
189
+ 'gcp.gemini': { label: 'Google Gemini', doc: "Google's Gemini API." },
190
+ openrouter: { label: 'OpenRouter', doc: 'The OpenRouter gateway.' },
191
+ typesafe: { label: 'TypeSafe', doc: "TypeSafe's native decision API." },
192
+ };
193
+ const USAGE_SIDES = {
194
+ input: { label: 'Input', doc: 'Tokens the model read.' },
195
+ output: { label: 'Output', doc: 'Tokens the model wrote.' },
196
+ };
197
+ const TRANSCRIPT_SOURCES = {
198
+ input_transcription: {
199
+ label: 'What the provider heard',
200
+ doc: "The provider's transcript of the user's audio.",
201
+ },
202
+ output_transcription: {
203
+ label: 'Transcript of the reply',
204
+ doc: "The provider's transcript of the model's spoken answer.",
205
+ },
206
+ };
207
+ const TURN_STAGE_OPTIONS = {
208
+ pre_turn: { label: 'Before the turn', doc: 'Before the first model call.' },
209
+ pre_tool: { label: 'Before a tool', doc: 'Before a tool call runs.' },
210
+ post_tool: { label: 'After a tool', doc: 'After a tool call settles.' },
211
+ before_end: { label: 'Before the end', doc: 'Before the turn delivers its final answer.' },
212
+ post_turn: { label: 'After the turn', doc: 'After the turn has ended.' },
213
+ };
214
+ const AFFORDANCES = {
215
+ inject: { label: 'Injected', doc: 'Added messages to the conversation.' },
216
+ abort: { label: 'Aborted', doc: 'Stopped the turn.' },
217
+ deny: { label: 'Denied', doc: 'Refused a tool call.' },
218
+ confirm: { label: 'Asked to confirm', doc: 'Required confirmation before a tool call.' },
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.' },
225
+ };
226
+ const GUARDRAIL_STAGE_OPTIONS = {
227
+ input: { label: 'User input', doc: 'Text the user sent.' },
228
+ history: { label: 'History', doc: 'Earlier messages sent back to the model.' },
229
+ system: { label: 'System instructions', doc: "The profile's or host's instructions." },
230
+ attachment: { label: 'Attachment', doc: 'A file the user attached.' },
231
+ tool_call: { label: 'Tool call', doc: 'Arguments the model sent to a tool.' },
232
+ tool_result: { label: 'Tool result', doc: 'What a tool returned.' },
233
+ output_delta: { label: 'Streaming output', doc: 'The answer as it streamed.' },
234
+ output_final: { label: 'Final output', doc: 'The whole answer.' },
235
+ thought: { label: 'Thinking', doc: "The model's thoughts as they streamed." },
236
+ network: { label: 'Network', doc: 'A URL the agent was about to reach.' },
237
+ live_inbound: { label: 'Live inbound', doc: 'What arrived from a Live session.' },
238
+ live_outbound: { label: 'Live outbound', doc: 'What was sent into a Live session.' },
239
+ trace: { label: 'Trace', doc: 'Text being written to the trace.' },
240
+ };
241
+ /**
242
+ * What each of Theorem's own guardrail rules caught. Keyed by every
243
+ * {@link GuardrailRule}, so a new rule is described here before it compiles.
244
+ * A host's own detectors have no entry and show as their label.
245
+ */
246
+ const GUARDRAIL_RULE_OPTIONS = {
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.',
250
+ },
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
+ },
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
+ },
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
+ },
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
+ },
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
+ },
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
+ },
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
+ },
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
+ },
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
+ },
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
+ },
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
+ },
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.",
298
+ },
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.',
302
+ },
303
+ 'tool_call.tainted-turn': {
304
+ label: 'Change after remote content',
305
+ doc: 'A tool that writes or deletes was called after the turn read remote content, which could have steered it.',
306
+ },
307
+ 'tool_call.steered-turn': {
308
+ label: 'Change after a remote instruction',
309
+ doc: 'A tool that writes or deletes was called after the turn read remote content that also looked like instructions to the agent.',
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
+ },
315
+ 'network.blocked': {
316
+ label: 'Address blocked',
317
+ doc: 'A tool tried to reach a private, local, or disallowed address. The request was never made.',
318
+ },
319
+ };
320
+ const GUARDRAIL_CHECK_OPTIONS = {
321
+ input: { label: 'Input check', doc: 'Checked what the user sent before the model read it.' },
322
+ egress: { label: 'Output check', doc: 'Checked the whole answer before it was released.' },
323
+ tool_arguments: { label: 'Argument check', doc: 'Checked what the model sent to a tool.' },
324
+ taint: {
325
+ label: 'Remote-content gate',
326
+ doc: 'Checked whether a tool that writes or deletes was called after the turn read remote content.',
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
+ tool_result: {
333
+ label: 'Result check',
334
+ doc: 'Checked what a tool returned before the model read it.',
335
+ },
336
+ tool_failure: {
337
+ label: 'Error check',
338
+ doc: "Checked a tool's error message before the model read it.",
339
+ },
340
+ network: { label: 'Address check', doc: 'Checked the address a tool was about to reach.' },
341
+ network_request: {
342
+ label: 'Lookup and redirect check',
343
+ doc: "Checked, during a tool's request, where its address resolved and every redirect it followed; includes the lookup when the host resolves names.",
344
+ },
345
+ output_stream: {
346
+ label: 'Streaming check',
347
+ doc: 'Checked the answer piece by piece as it streamed, before the host saw each piece.',
348
+ },
349
+ stream_canary: {
350
+ label: 'Streamed leak check',
351
+ doc: "Checked each streamed tool call and other non-text output for the system prompt's canary.",
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
+ },
357
+ live_input: { label: 'Live input check', doc: 'Checked text the host sent into a live session.' },
358
+ live_output: {
359
+ label: 'Live output check',
360
+ doc: 'Checked what the model said in a live session, batch by batch, before the host heard it.',
361
+ },
362
+ };
363
+ const TRUST_OPTIONS = {
364
+ trusted: { label: 'Trusted', doc: "The profile's own text, written at author time." },
365
+ assembled: { label: 'Assembled', doc: 'Built by the host each turn; may carry user data.' },
366
+ untrusted: {
367
+ label: 'Untrusted',
368
+ doc: 'User input, tool results, attachments, or another agent.',
369
+ },
370
+ };
371
+ const GUARDRAIL_ACTIONS = {
372
+ allow: { label: 'Allowed', doc: 'Checked and let through unchanged.' },
373
+ redact: { label: 'Redacted', doc: 'The matched text was replaced.' },
374
+ flag: { label: 'Flagged', doc: 'Recorded; nothing was changed.' },
375
+ block: { label: 'Blocked', doc: 'The step was stopped.' },
376
+ };
377
+ const SEVERITY_OPTIONS = {
378
+ info: { label: 'Info', doc: 'Noted only.' },
379
+ low: { label: 'Low', doc: 'Low risk.' },
380
+ medium: { label: 'Medium', doc: 'Medium risk.' },
381
+ high: { label: 'High', doc: 'High risk.' },
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
+ };
387
+ const GATE_KINDS = {
388
+ confirmation: { label: 'Confirmation', doc: 'The user must confirm this call.' },
389
+ permission: { label: 'Permission', doc: 'The user must allow this tool.' },
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.' },
392
+ };
393
+ const RETRY_REASONS = {
394
+ egress: {
395
+ label: 'Output guardrail',
396
+ doc: 'The output guardrail sent the answer back to the model.',
397
+ },
398
+ validation: { label: 'Invalid JSON', doc: 'The structured output did not match its schema.' },
399
+ };
400
+ const COMPACTION_TIMING_OPTIONS = {
401
+ before: { label: 'Before the turn', doc: 'Compacts before the turn runs.' },
402
+ after: { label: 'After the turn', doc: 'Signals the host to compact after the turn.' },
403
+ };
404
+ const COMPACTION_METER_OPTIONS = {
405
+ history: { label: 'History', doc: 'Counts tokens across earlier turns.' },
406
+ input: {
407
+ label: 'Whole input',
408
+ doc: "Counts the turn's whole input: instructions, history, and attachments.",
409
+ },
410
+ };
411
+ const COMPACTION_OUTCOME_OPTIONS = {
412
+ compacted: { label: 'Compacted', doc: 'A summary replaced the earlier messages.' },
413
+ deferred: {
414
+ label: 'Kept whole',
415
+ doc: 'The compactor failed and the history still fits, so it was kept and compaction runs again next turn.',
416
+ },
417
+ dropped: {
418
+ label: 'Dropped',
419
+ doc: 'The compactor failed and the history no longer fits, so the earlier messages were dropped.',
420
+ },
421
+ };
422
+ /** `theorem.session` kinds: provider session signals (a finished response is its own record). */
423
+ const SESSION_KINDS = {
424
+ closing_soon: { label: 'Closing soon', doc: 'The provider warned the session will end.' },
425
+ ended: { label: 'Ended', doc: 'The provider ended the session after warning it would.' },
426
+ waiting_for_input: { label: 'Waiting for input', doc: 'The model is waiting for the user.' },
427
+ working: { label: 'Working', doc: 'The model is thinking or waiting on a tool.' },
428
+ idle: { label: 'Idle', doc: 'The model finished everything it was doing.' },
429
+ voice_activity: { label: 'Voice activity', doc: 'The provider heard speech start or stop.' },
430
+ session_resumption: {
431
+ label: 'Resumption update',
432
+ doc: 'The provider said whether the session can be resumed.',
433
+ },
434
+ setup_complete: { label: 'Setup complete', doc: 'The provider accepted the session setup.' },
435
+ key_fallback: {
436
+ label: 'Switched to fallback key',
437
+ doc: "The key was refused for quota at setup; the session reopened on the profile's fallback key.",
438
+ },
439
+ closed: { label: 'Socket closed', doc: 'The session socket closed.' },
440
+ };
441
+ const CLOSE_INITIATORS = {
442
+ host: { label: 'Host', doc: 'The host closed the session.' },
443
+ provider: { label: 'Provider', doc: 'The provider closed the socket.' },
444
+ theorem: { label: 'theorem', doc: 'theorem closed the socket.' },
445
+ };
446
+ const CLOCK_OPTIONS = {
447
+ io: {
448
+ label: 'Moves at I/O only',
449
+ doc: 'Recorded in a Cloudflare Worker, whose clock only moves at I/O: time spent computing reads as zero.',
450
+ },
451
+ };
452
+ function attr(group, label, format, doc, options) {
453
+ return options ? { label, doc, format, group, options } : { label, doc, format, group };
454
+ }
455
+ function fields(group, label, doc, keys) {
456
+ return { label, doc, format: 'object', group, fields: keys };
457
+ }
458
+ const BOOLEAN_SIDES = {
459
+ input: attr('request', 'Input', 'boolean', "Transcribe the user's audio."),
460
+ output: attr('request', 'Output', 'boolean', "Transcribe the model's audio."),
461
+ };
462
+ const SPAN_ATTRIBUTES = {
463
+ 'gen_ai.operation.name': attr('agent', 'Operation', 'text', 'What this span did.', OPERATIONS),
464
+ 'gen_ai.agent.name': attr('agent', 'Agent', 'id', 'The profile that ran.'),
465
+ 'gen_ai.conversation.id': attr('agent', 'Conversation', 'id', 'The conversation id the host passed; absent when it passed none.'),
466
+ 'gen_ai.conversation.compacted': attr('agent', 'History compacted', 'boolean', 'Compaction summarized earlier messages in this turn.'),
467
+ 'theorem.stop.kind': attr('agent', 'Stop reason', 'text', 'Why it ended. Absent when it failed before any stop.', STOP_KINDS),
468
+ 'theorem.attempts': attr('agent', 'Attempts', 'number', 'Times the turn ran its model calls, counting a retry after a guardrail or invalid JSON.'),
469
+ 'theorem.steps': attr('agent', 'Model calls', 'number', 'Model calls made (Live: responses).'),
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.'),
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."),
472
+ 'theorem.step': attr('agent', 'Step', 'number', 'Which model call of the turn this is, from 1.'),
473
+ 'theorem.attempt': attr('agent', 'Attempt', 'number', 'Which attempt of the turn made this call.'),
474
+ 'theorem.request.effort': attr('agent', 'Effort', 'text', 'The effort the host asked for.'),
475
+ 'theorem.request.model_select': attr('agent', 'Model asked for', 'id', 'The model the host asked for, by alias.'),
476
+ 'theorem.project.id': attr('agent', 'Project', 'id', 'The project id the host passed.'),
477
+ 'theorem.link.kind': attr('agent', 'Link', 'text', 'How this span follows an earlier trace.', LINK_KINDS),
478
+ 'gen_ai.provider.name': {
479
+ ...attr('request', 'Provider', 'id', 'Who served the call; a local server by its declared name. Absent when unknown.', PROVIDERS),
480
+ open: true,
481
+ },
482
+ 'gen_ai.request.model': attr('request', 'Model sent', 'id', 'The model id sent to the provider.'),
483
+ 'theorem.model.id': attr('request', 'Model alias', 'id', "The profile's name for the model."),
484
+ 'gen_ai.request.stream': attr('request', 'Streamed', 'boolean', 'The call streamed its answer. Absent means it did not.'),
485
+ 'gen_ai.request.temperature': attr('request', 'Temperature', 'number', 'As requested.'),
486
+ 'gen_ai.request.max_tokens': attr('request', 'Max output tokens', 'tokens', 'As requested.'),
487
+ 'gen_ai.request.reasoning.level': attr('request', 'Thinking level', 'text', 'As requested.'),
488
+ 'gen_ai.output.type': attr('request', 'Output type', 'text', 'What kind of answer was asked for.', OUTPUT_TYPES),
489
+ 'theorem.key_slot': attr('request', 'API key', 'text', 'The vault key slot that finally answered, by the name the profile gave it.'),
490
+ 'theorem.request.builtins': attr('request', 'Provider tools', 'list', 'Tools the provider runs itself (search, maps, code), as requested.'),
491
+ 'theorem.request.store': attr('request', 'Stored by provider', 'boolean', 'Asked the provider to keep the response for a later continuation.'),
492
+ 'theorem.request.summaries': attr('request', 'Thought summaries', 'text', 'Asked for summaries of the model’s thinking.'),
493
+ 'theorem.request.structured': attr('request', 'Structured output', 'object', 'The JSON schema the answer must match.'),
494
+ 'theorem.request.session_id': attr('request', 'Session', 'id', 'The provider session this call ran in.'),
495
+ 'theorem.request.cache': fields('request', 'Cache', 'The prompt cache, as requested.', {
496
+ mode: attr('request', 'Mode', 'text', 'How the prompt cache is used.'),
497
+ ttl: attr('request', 'Lifetime', 'text', 'How long a cache entry lives.'),
498
+ }),
499
+ 'theorem.request.image': fields('request', 'Image settings', 'The image asked for.', {
500
+ mime_type: attr('request', 'Format', 'text', 'The image file type.'),
501
+ aspect_ratio: attr('request', 'Aspect ratio', 'text', 'Width to height.'),
502
+ resolution: attr('request', 'Resolution', 'text', 'How detailed the image is, such as 1K, 2K or 4K.'),
503
+ include_text: attr('request', 'With text', 'boolean', 'Text may come back beside the image.'),
504
+ }),
505
+ 'theorem.request.speech': fields('request', 'Speech settings', 'The audio asked for.', {
506
+ voice: attr('request', 'Voice', 'text', 'The voice.'),
507
+ speed: attr('request', 'Speed', 'number', "The speaking rate; 1 is the voice's own pace."),
508
+ format: attr('request', 'Format', 'text', 'The audio format.'),
509
+ }),
510
+ 'theorem.request.live': fields('request', 'Live settings', 'The Live session setup, as sent.', {
511
+ voice: attr('request', 'Voice', 'text', 'The voice the model speaks in.'),
512
+ vad: fields('request', 'Voice detection', 'How the provider hears speech start and stop.', {
513
+ activity_handling: attr('request', 'On speech', 'text', 'What the model does when the user starts speaking.'),
514
+ start_sensitivity: attr('request', 'Start sensitivity', 'text', 'How readily speech counts as started.'),
515
+ end_sensitivity: attr('request', 'End sensitivity', 'text', 'How readily speech counts as ended.'),
516
+ prefix_padding_ms: attr('request', 'Lead-in', 'milliseconds', 'Speech needed before it counts as started.'),
517
+ silence_duration_ms: attr('request', 'Silence to end', 'milliseconds', 'Silence needed before speech counts as ended.'),
518
+ }),
519
+ session_resumption: attr('request', 'Resumable', 'boolean', 'Asked for handles to resume the session later.'),
520
+ context_compression: fields('request', 'Context compression', 'How the provider shrinks a long session.', {
521
+ mechanism: attr('request', 'Mechanism', 'text', 'How the context is shrunk.'),
522
+ trigger_tokens: attr('request', 'Trigger', 'tokens', 'Context size that starts compression.'),
523
+ target_tokens: attr('request', 'Keep', 'tokens', 'Context size kept after compressing.'),
524
+ }),
525
+ transcription: fields('request', 'Transcription', 'Which audio the provider transcribes.', BOOLEAN_SIDES),
526
+ resumed: attr('request', 'Resumed', 'boolean', 'The session resumed an earlier one. The resumption handle is a credential and is never recorded.'),
527
+ }),
528
+ 'theorem.input.sent_from': attr('request', 'Sent from message', 'number', 'Where in the input messages the request body starts; earlier ones the provider already held.'),
529
+ 'gen_ai.response.id': attr('response', 'Response ID', 'id', "The provider's id for its answer."),
530
+ 'gen_ai.response.model': attr('response', 'Model that answered', 'id', 'The model the provider says answered.'),
531
+ 'gen_ai.response.finish_reasons': attr('response', 'Provider finish reason', 'list', "The provider's own reason for stopping. Absent when the call was stopped."),
532
+ 'gen_ai.response.status': attr('response', 'Provider status', 'text', "The provider's own status for the answer. Absent when the call was stopped."),
533
+ 'gen_ai.response.time_to_first_chunk': attr('response', 'Time to first chunk', 'seconds', 'From the start of the successful HTTP try, or of a Live response, to its first chunk; a buffered body is its one chunk.'),
534
+ 'theorem.response.time_to_first_text': attr('response', 'Time to first text', 'seconds', 'From the start of the call to its first reply text, before guardrails; reasoning and tool calls do not count.'),
535
+ 'gen_ai.system_instructions': attr('messages', 'System instructions', 'parts', 'The instructions the model read.'),
536
+ 'gen_ai.tool.definitions': attr('messages', 'Tool definitions', 'content', 'The tools offered to the model, as sent.'),
537
+ 'gen_ai.input.messages': attr('messages', 'Input', 'messages', "On a turn: the user's new input. On a model call: everything the model read."),
538
+ 'gen_ai.output.messages': attr('messages', 'Output', 'messages', 'On a turn: what the host received. On a model call: what the model produced.'),
539
+ 'theorem.output.delivered': attr('messages', 'Delivered', 'messages', 'What the host received of this Live response.'),
540
+ 'theorem.error.public': attr('error', 'Error the user saw', 'content', 'The worded error the caller received.'),
541
+ 'gen_ai.usage.input_tokens': attr('usage', 'Input tokens', 'tokens', 'Tokens the model read.'),
542
+ 'gen_ai.usage.output_tokens': attr('usage', 'Output tokens', 'tokens', 'Tokens the model wrote.'),
543
+ 'gen_ai.usage.reasoning.output_tokens': attr('usage', 'Thinking tokens', 'tokens', 'Output tokens spent thinking.'),
544
+ 'gen_ai.usage.cache_read.input_tokens': attr('usage', 'Cached input tokens', 'tokens', 'Input tokens read from the prompt cache.'),
545
+ 'gen_ai.usage.cache_write.input_tokens': attr('usage', 'Cache write tokens', 'tokens', 'Input tokens written to the prompt cache.'),
546
+ 'theorem.usage.tool_use.input_tokens': attr('usage', 'Tool-use input tokens', 'tokens', 'Input tokens Google counts for tool use; already inside input tokens.'),
547
+ 'theorem.usage.grounding': fields('usage', 'Grounding', 'Grounding tool uses, per tool.', {
548
+ type: attr('usage', 'Tool', 'id', "The provider's name for the tool."),
549
+ count: attr('usage', 'Uses', 'number', 'Times the tool ran.'),
550
+ search_query_count: attr('usage', 'Searches', 'number', 'Search queries it ran.'),
551
+ }),
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."),
553
+ 'theorem.usage.upstream_cost_usd': attr('usage', 'Upstream cost', 'usd', "The upstream provider's cost, as a gateway reported it."),
554
+ 'theorem.usage.cost_partial': attr('usage', 'Cost is partial', 'boolean', 'Only some calls reported a cost.'),
555
+ 'theorem.usage.estimated': attr('usage', 'Estimated', 'list', 'Sides whose token counts theorem estimated rather than the provider reporting them.', USAGE_SIDES),
556
+ 'theorem.usage.unknown_media': fields('usage', 'Uncounted media', 'Media items no counting rule covered, so their tokens are missing from the estimate.', {
557
+ input: attr('usage', 'Input', 'number', 'Uncounted media the model read.'),
558
+ output: attr('usage', 'Output', 'number', 'Uncounted media the model wrote.'),
559
+ }),
560
+ 'gen_ai.tool.name': attr('tool', 'Tool', 'id', 'The tool called.'),
561
+ 'gen_ai.tool.call.id': attr('tool', 'Call ID', 'id', "The call's id."),
562
+ 'gen_ai.tool.type': attr('tool', 'Tool type', 'text', 'function for a registered tool.'),
563
+ 'gen_ai.tool.call.arguments': attr('tool', 'Arguments', 'content', 'The arguments exactly as the model sent them.'),
564
+ 'gen_ai.tool.call.result': attr('tool', 'Result', 'content', 'What the model reads back, after formatting and the tool-result guardrail.'),
565
+ 'theorem.tool.call.result.parts': attr('tool', 'Result media', 'parts', 'Media and other parts the result carried.'),
566
+ 'theorem.tool.data': attr('tool', 'Raw output', 'json', "The tool's output before formatting."),
567
+ 'theorem.tool.outcome': attr('tool', 'Outcome', 'text', 'How the call settled.', TOOL_OUTCOMES),
568
+ 'theorem.tool.origin': attr('tool', 'Origin', 'text', 'Where the tool runs, which sets how far its result is trusted.', TOOL_ORIGIN_OPTIONS),
569
+ 'theorem.tool.permission': attr('tool', 'Permission', 'text', "The tool's permission tier.", TOOL_PERMISSION_OPTIONS),
570
+ 'theorem.tool.approved': attr('tool', 'Approved', 'boolean', 'The host resumed this call with approval.'),
571
+ 'theorem.tool.failure.code': attr('error', 'Failure code', 'id', "The tool's code for the failure, e.g. malformed_arguments."),
572
+ 'theorem.cutout.input.sha256': attr('tool', 'Input hash', 'id', "The host's hash of what it sent to the cutout."),
573
+ 'theorem.cutout.output.sha256': attr('tool', 'Output hash', 'id', "The host's hash of what came back."),
574
+ 'http.request.method': attr('http', 'Method', 'text', 'The HTTP method.'),
575
+ 'server.address': attr('http', 'Host', 'id', 'The server the try went to.'),
576
+ 'url.path': attr('http', 'Path', 'id', 'The URL path. The query is never recorded.'),
577
+ 'http.response.status_code': attr('http', 'Status code', 'number', 'The HTTP status returned.'),
578
+ 'http.request.resend_count': attr('http', 'Retry number', 'number', '0 for the first try, then 1, 2, … for each retry.'),
579
+ 'theorem.retry.backoff_ms': attr('http', 'Wait before retry', 'milliseconds', 'How long theorem waited after the previous try.'),
580
+ 'error.type': {
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),
582
+ open: true,
583
+ },
584
+ 'exception.type': attr('error', 'Exception', 'id', 'The class or kind of what was thrown.'),
585
+ 'exception.message': attr('error', 'Message', 'content', 'The exception message, scrubbed.'),
586
+ 'exception.stacktrace': attr('error', 'Stack', 'content', 'Where it was thrown, scrubbed.'),
587
+ 'theorem.record.include': attr('record', 'Included', 'list', 'What this record kept. A field left out because it was off reads as not recorded, never as did not happen.'),
588
+ 'theorem.record.scrub': attr('record', 'Scrubbed', 'list', 'What was removed from stored text before it was hashed.'),
589
+ 'theorem.clock': attr('record', 'Clock', 'text', 'How the times in this record were taken.', CLOCK_OPTIONS),
590
+ 'theorem.source': attr('part', 'Source', 'text', 'Where this text came from, when it is not the model’s own.', TRANSCRIPT_SOURCES),
591
+ 'theorem.interim': attr('part', 'Interim', 'boolean', 'An interim transcript, not the final one.'),
592
+ 'theorem.observed_end': attr('part', 'Seen at', 'time', 'When theorem saw this provider-run step whole.'),
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),
596
+ 'theorem.decision.contract': attr('decision', 'Contract', 'id', "The host's decision contract the profile names."),
597
+ 'theorem.decision.state': attr('decision', 'State', 'json', 'The JSON state the decision read.'),
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.'),
601
+ 'gen_ai.evaluation.name': attr('evaluation', 'Grader', 'id', 'The grader that produced this result.'),
602
+ 'gen_ai.evaluation.score.value': attr('evaluation', 'Score', 'number', 'The score, 0–1 unless the grader says otherwise.'),
603
+ 'gen_ai.evaluation.score.label': attr('evaluation', 'Label', 'text', "The grader's label for this trial, one of the labels it declares."),
604
+ 'gen_ai.evaluation.explanation': attr('evaluation', 'Explanation', 'content', "Why, in the grader's words."),
605
+ 'theorem.evaluation.source': attr('evaluation', 'Graded by', 'text', 'Who produced this result.', EVALUATION_SOURCES),
606
+ 'theorem.evaluation.suite': attr('evaluation', 'Suite', 'id', 'The eval suite that ran.'),
607
+ 'theorem.evaluation.case': attr('evaluation', 'Case', 'id', 'The case this trial ran. Absent when a production trace was graded without one.'),
608
+ 'theorem.evaluation.trial': attr('evaluation', 'Trial', 'number', 'Which trial of the case this is, from 0.'),
609
+ 'theorem.evaluation.grader.version': attr('evaluation', 'Grader version', 'id', "The sha256 of the grader's rubric or code identity, so a reader can tell which rubric scored this."),
610
+ 'theorem.evaluation.passed': attr('evaluation', 'Passed', 'boolean', "The grader's yes or no. Absent when the result informs but does not decide."),
611
+ 'theorem.eval.repeat': attr('evaluation', 'Trials per case', 'number', 'How many times each case ran.'),
612
+ 'theorem.eval.pass_rule': attr('evaluation', 'Pass rule', 'text', 'How the trials of a case become its verdict.', PASS_RULES),
613
+ 'theorem.eval.pass_at_least': attr('evaluation', 'Trials needed', 'number', 'Trials that must pass under the at-least rule.'),
614
+ 'theorem.eval.caseless': attr('evaluation', 'Caseless', 'boolean', 'Production traces were graded with no cases: only graders that need no expectation ran.'),
615
+ 'theorem.eval.stopped': attr('evaluation', 'Stopped early', 'text', 'Why the run stopped before its end.', EVAL_STOPS),
616
+ 'vcs.ref.head.revision': attr('evaluation', 'Commit', 'id', 'The commit under test.'),
617
+ };
618
+ /** Modality token counts: `{gen_ai|theorem}.usage.<modality>.<input|output>_tokens`. */
619
+ const MODALITY_USAGE = /^(?:gen_ai|theorem)\.usage\.([a-z]+)\.(input|output)_tokens$/;
620
+ /** Recorded headers: `http.<request|response>.header.<name>`. */
621
+ const HEADER = /^http\.(request|response)\.header\.(.+)$/;
622
+ function capitalize(word) {
623
+ return word.charAt(0).toUpperCase() + word.slice(1);
624
+ }
625
+ /** What an attribute key means; `undefined` for a key THEOREM does not write. */
626
+ function traceAttributeMeta(key) {
627
+ const known = SPAN_ATTRIBUTES[key];
628
+ if (known)
629
+ return known;
630
+ const usage = MODALITY_USAGE.exec(key);
631
+ if (usage) {
632
+ const [, modality = '', side = ''] = usage;
633
+ return attr('usage', `${capitalize(modality)} ${side} tokens`, 'tokens', `${capitalize(side)} tokens that were ${modality}, as the provider reported them.`);
634
+ }
635
+ const header = HEADER.exec(key);
636
+ if (header) {
637
+ const [, direction = '', name = ''] = header;
638
+ return attr('http', `${capitalize(direction)} header ${name}`, 'list', `The ${direction} header, as sent. A key, auth, cookie, secret, or token header is [redacted].`);
639
+ }
640
+ return undefined;
641
+ }
642
+ const HITS = fields('error', 'Hits', 'Each rule that matched.', {
643
+ rule: {
644
+ ...attr('error', 'Rule', 'id', "The rule that matched: one of Theorem's own, or a host policy's, which names itself.", GUARDRAIL_RULE_OPTIONS),
645
+ open: true,
646
+ },
647
+ severity: attr('error', 'Severity', 'text', 'How serious the rule says a match is.', SEVERITY_OPTIONS),
648
+ start: attr('error', 'From', 'number', 'Where the match starts in the checked text.'),
649
+ end: attr('error', 'To', 'number', 'Where the match ends in the checked text.'),
650
+ match: attr('error', 'Match', 'text', 'The matched text, exact. Kept only when the profile records match previews.'),
651
+ label: attr('error', 'Rule name', 'text', "A host rule's own name for what it catches."),
652
+ doc: attr('error', 'Why it matters', 'text', "A host rule's own account of why a match matters."),
653
+ });
654
+ const TRACE_EVENTS = {
655
+ 'theorem.stage': {
656
+ label: 'Hook',
657
+ doc: 'A stage in the turn where host hooks could act.',
658
+ attributes: {
659
+ stage: attr('agent', 'Stage', 'text', 'Where in the turn.', TURN_STAGE_OPTIONS),
660
+ affordance: attr('agent', 'Applied', 'list', 'What the hooks did; empty when they did nothing.', AFFORDANCES),
661
+ hook_ms: attr('agent', 'Hook time', 'milliseconds', 'Time the hooks took; absent when none ran.'),
662
+ warnings: attr('error', 'Warnings', 'list', 'Warning codes the hooks raised.'),
663
+ },
664
+ },
665
+ 'theorem.guardrail': {
666
+ label: 'Guardrail',
667
+ doc: 'A guardrail checked some text: what it did, or `allow` for a timed check that let the text through.',
668
+ attributes: {
669
+ check: attr('agent', 'Check', 'id', 'Which timed check ran.', GUARDRAIL_CHECK_OPTIONS),
670
+ duration_ms: attr('agent', 'Check time', 'milliseconds', 'Time the check took; a check on streamed output, its total over the call.'),
671
+ runs: attr('agent', 'Runs', 'number', 'How many times a check on streamed output ran on the call.'),
672
+ stage: attr('agent', 'Checked', 'text', 'Which text was checked.', GUARDRAIL_STAGE_OPTIONS),
673
+ trust: attr('agent', 'Trust', 'text', 'How far that text is trusted.', TRUST_OPTIONS),
674
+ action: attr('agent', 'Action', 'text', 'What the guardrail did.', GUARDRAIL_ACTIONS),
675
+ hits: HITS,
676
+ provenance: fields('agent', 'Came from', 'Where the checked text came from.', {
677
+ origin: attr('tool', 'Origin', 'text', 'Where the tool runs, which sets how far its result is trusted.', TOOL_ORIGIN_OPTIONS),
678
+ tool: attr('tool', 'Tool', 'id', 'The tool that produced it.'),
679
+ depth: attr('tool', 'Hops', 'number', "Tool calls between the user's turn and this text: 1 for a direct call, more through another agent."),
680
+ }),
681
+ error: attr('error', 'Detail', 'content', "The guardrail's internal reason."),
682
+ },
683
+ },
684
+ 'theorem.attempt.retry': {
685
+ label: 'Retry',
686
+ doc: 'The turn ran its model calls again.',
687
+ attributes: {
688
+ attempt: attr('agent', 'Attempt', 'number', 'The attempt that starts.'),
689
+ reason: attr('agent', 'Reason', 'text', 'Why it retried.', RETRY_REASONS),
690
+ },
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
+ },
702
+ 'theorem.compaction': {
703
+ label: 'Compaction',
704
+ doc: 'theorem decided whether to summarize earlier messages.',
705
+ attributes: {
706
+ timing: attr('agent', 'Timing', 'text', 'When compaction runs.', COMPACTION_TIMING_OPTIONS),
707
+ meter: attr('agent', 'Counts', 'text', 'What the threshold counts.', COMPACTION_METER_OPTIONS),
708
+ budget: attr('usage', 'Budget', 'tokens', 'The token budget the threshold is a share of.'),
709
+ threshold: attr('usage', 'Threshold', 'number', 'The share of the budget that triggers it.'),
710
+ trigger: attr('agent', 'Trigger', 'text', 'custom when the host decides instead.'),
711
+ tokens_before: attr('usage', 'Tokens counted', 'tokens', 'What the meter read.'),
712
+ unknown_media: attr('usage', 'Uncounted media', 'number', 'Media items the count could not cover.'),
713
+ needed: attr('agent', 'Needed', 'boolean', 'The count crossed the threshold.'),
714
+ outcome: attr('agent', 'Outcome', 'text', 'What happened to the earlier messages.', COMPACTION_OUTCOME_OPTIONS),
715
+ messages_before: attr('messages', 'Messages before', 'number', 'History length before.'),
716
+ messages_after: attr('messages', 'Messages after', 'number', 'History length after.'),
717
+ dropped_media: attr('messages', 'Media left out', 'number', 'Media the compactor does not take, left out of what it read.'),
718
+ failure_stop: attr('agent', 'Compactor stop', 'text', 'How the failed compactor stopped.', STOP_KINDS),
719
+ failure_error: attr('agent', 'Compactor error', 'text', 'The error the compactor failed with.', ERROR_KIND_OPTIONS),
720
+ failure_empty: attr('agent', 'Empty summary', 'boolean', 'The compactor replied with nothing.'),
721
+ failure_unreadable: attr('agent', 'Nothing to read', 'boolean', 'Everything to compact was media the compactor does not take, so it did not run.'),
722
+ summary: attr('messages', 'Summary', 'content', 'The summary that replaced them.'),
723
+ },
724
+ },
725
+ exception: {
726
+ label: 'Exception',
727
+ doc: 'Something was thrown, or the provider reported an error.',
728
+ attributes: {},
729
+ },
730
+ 'theorem.upstream.row': {
731
+ label: 'Provider data',
732
+ doc: 'One row of data from the provider, at the time it arrived.',
733
+ attributes: {
734
+ row: attr('response', 'Row', 'json', 'The row, scrubbed, with media and known text by hash.'),
735
+ },
736
+ },
737
+ 'theorem.wire.request': {
738
+ label: 'Request body',
739
+ doc: 'The body sent to the provider.',
740
+ attributes: {
741
+ body: attr('request', 'Body', 'json', 'The body, scrubbed, with media and known text by hash.'),
742
+ body_kind: attr('request', 'Body type', 'text', 'What the body was, when it was not JSON.'),
743
+ },
744
+ },
745
+ 'theorem.grounding': {
746
+ label: 'Grounding',
747
+ doc: 'Sources and citations the answer drew on.',
748
+ attributes: {
749
+ provider: attr('response', 'Provider', 'id', 'Who supplied the evidence.'),
750
+ sources: attr('response', 'Sources', 'json', 'The sources.'),
751
+ search_html: attr('response', 'Search suggestions', 'content', "Google's search widget."),
752
+ raw: attr('response', 'Raw', 'json', "The provider's raw grounding payload."),
753
+ },
754
+ },
755
+ 'theorem.gate': {
756
+ label: 'Approval needed',
757
+ doc: 'The call stopped until the user answers.',
758
+ attributes: {
759
+ kind: attr('tool', 'Needs', 'text', 'What the user must give.', GATE_KINDS),
760
+ permission: attr('tool', 'Permission', 'text', "The tool's permission tier.", TOOL_PERMISSION_OPTIONS),
761
+ summary: attr('tool', 'Summary', 'content', 'What the user is asked to approve.'),
762
+ auth: fields('tool', 'Sign-in', 'The credential asked for. The challenge state is a secret and is never recorded.', {
763
+ slot: attr('tool', 'Credential', 'id', 'The credential slot the tool reads.'),
764
+ type: attr('tool', 'Type', 'text', 'The kind of credential.'),
765
+ service: attr('tool', 'Service', 'text', 'The service the person signs in to.'),
766
+ issuer: attr('tool', 'Issuer', 'id', 'Who issues it.'),
767
+ resource: attr('tool', 'Resource', 'id', 'What it grants access to.'),
768
+ required_scopes: attr('tool', 'Scopes', 'list', 'The scopes it must carry.'),
769
+ }),
770
+ },
771
+ },
772
+ 'theorem.auth.scope_refused': {
773
+ label: 'Access refused',
774
+ doc: 'The service asked for access outside the scopes the tool declares, so no sign-in was offered.',
775
+ attributes: {
776
+ slot: attr('tool', 'Credential', 'id', 'The credential slot the tool reads.'),
777
+ requested: attr('tool', 'Asked for', 'list', 'The scopes the service asked for.'),
778
+ declared: attr('tool', 'Declared', 'list', 'The scopes the tool declares.'),
779
+ },
780
+ },
781
+ 'theorem.tool.warning': {
782
+ label: 'Tool warning',
783
+ doc: 'Something the tool flagged while it ran; the call went on.',
784
+ attributes: {
785
+ code: attr('tool', 'Code', 'id', 'The warning, by name.'),
786
+ message: attr('tool', 'Message', 'content', 'What the tool said.'),
787
+ severity: attr('tool', 'Severity', 'text', 'How serious the tool says it is.'),
788
+ },
789
+ },
790
+ 'theorem.tool.cancel': {
791
+ label: 'Tool call cancelled',
792
+ doc: 'The provider cancelled a tool call it had made.',
793
+ attributes: {},
794
+ },
795
+ 'theorem.session': {
796
+ label: 'Session',
797
+ doc: 'Something happened to the Live session.',
798
+ attributes: {
799
+ kind: attr('agent', 'What happened', 'text', 'The session fact recorded.', SESSION_KINDS),
800
+ time_left_ms: attr('agent', 'Time left', 'milliseconds', 'How long the provider said the session had left.'),
801
+ closed_after_ms: attr('agent', 'Closed after', 'milliseconds', 'How long after the warning the socket closed.'),
802
+ cause: attr('agent', 'Cause', 'text', 'go_away when the provider had warned it would close.'),
803
+ code: attr('http', 'Close code', 'number', 'The WebSocket close code.'),
804
+ reason: attr('http', 'Close reason', 'text', 'The WebSocket close reason.'),
805
+ initiator: attr('agent', 'Closed by', 'text', 'Who closed the socket.', CLOSE_INITIATORS),
806
+ activity: attr('agent', 'Activity', 'text', "The provider's voice activity signal."),
807
+ audio_offset: attr('agent', 'Audio offset', 'text', 'Where in the audio it was heard.'),
808
+ resumable: attr('agent', 'Resumable', 'boolean', 'The session can be resumed now.'),
809
+ handle_issued: attr('agent', 'Handle issued', 'boolean', 'The provider sent a resumption handle. The handle is a credential and is never recorded.'),
810
+ key_slot: attr('request', 'From key', 'text', 'The key slot refused.'),
811
+ to_key_slot: attr('request', 'To key', 'text', "The profile's fallback key slot it reopened on."),
812
+ error: attr('error', 'Detail', 'text', "The provider's refusal."),
813
+ },
814
+ },
815
+ 'gen_ai.evaluation.result': {
816
+ label: 'Eval result',
817
+ doc: "One grader's reading of this trace. Its keys are span attributes of the evaluation group.",
818
+ attributes: {},
819
+ },
820
+ 'theorem.eval.verdict': {
821
+ label: 'Verdict',
822
+ doc: "One case's pass or fail after its trials, by the suite's pass rule. Every case is here, zeros included.",
823
+ attributes: {
824
+ case: attr('evaluation', 'Case', 'id', 'The case judged.'),
825
+ kind: attr('evaluation', 'Kind', 'text', "Anthropic's split of cases.", CASE_KINDS),
826
+ difficulty: attr('evaluation', 'Difficulty', 'number', 'The case’s 1–5 difficulty, when the suite set one.'),
827
+ passed: attr('evaluation', 'Passed', 'boolean', 'The pass rule was met.'),
828
+ trials: attr('evaluation', 'Trials', 'number', 'Trials run.'),
829
+ trials_passed: attr('evaluation', 'Passed trials', 'number', 'Trials every deciding grader passed.'),
830
+ trials_errored: attr('evaluation', 'Errored trials', 'number', 'Trials a grader could not score; they count as failed.'),
831
+ trials_ungraded: attr('evaluation', 'Ungraded trials', 'number', 'Trials no grader decided.'),
832
+ },
833
+ },
834
+ };
835
+ /** What an event records; `undefined` for an event THEOREM does not write. */
836
+ function traceEventMeta(name) {
837
+ return TRACE_EVENTS[name];
838
+ }
839
+ /** The event's own entry, else the span attribute of that key. */
840
+ function traceEventAttributeMeta(event, key) {
841
+ return TRACE_EVENTS[event]?.attributes[key] ?? traceAttributeMeta(key);
842
+ }
843
+ /** Labels and descriptions for each span type. */
844
+ const TRACE_SPAN_TYPES = {
845
+ turn: { label: 'Turn', doc: 'One exchange: the model calls and tool calls it took to answer.' },
846
+ session: { label: 'Live session', doc: 'A Live session, from setup to close.' },
847
+ call: { label: 'Model call', doc: 'One request to a model and its answer.' },
848
+ response: { label: 'Live response', doc: 'One spoken response in a Live session.' },
849
+ tool: { label: 'Tool call', doc: 'One tool call theorem ran, from its hooks to settlement.' },
850
+ http: { label: 'HTTP try', doc: 'One HTTP attempt of a model call.' },
851
+ cutout: { label: 'Cutout', doc: 'A side effect the host recorded after the turn.' },
852
+ decision: { label: 'Decision', doc: 'One typed decision over JSON state.' },
853
+ evaluation: { label: 'Evaluation', doc: 'An eval graded this trace, or a suite ran.' },
854
+ host: { label: 'Host span', doc: 'A step the host recorded itself.' },
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
+ }
871
+ function stringAttribute(span, key) {
872
+ const value = span.attributes[key];
873
+ return typeof value === 'string' ? value : undefined;
874
+ }
875
+ function withSubject(type, subject) {
876
+ const meta = { type, ...TRACE_SPAN_TYPES[type] };
877
+ return subject ? { ...meta, subject } : meta;
878
+ }
879
+ /** The label, subject, and description to show for a span. */
880
+ function traceSpanMeta(span) {
881
+ switch (stringAttribute(span, 'gen_ai.operation.name')) {
882
+ case 'invoke_agent':
883
+ return withSubject(span.events.some((event) => event.name === 'theorem.session') ? 'session' : 'turn', stringAttribute(span, 'gen_ai.agent.name'));
884
+ case 'chat':
885
+ case 'generate_content':
886
+ return withSubject('theorem.request.live' in span.attributes ? 'response' : 'call', stringAttribute(span, 'gen_ai.request.model'));
887
+ case 'execute_tool':
888
+ return withSubject('tool', stringAttribute(span, 'gen_ai.tool.name'));
889
+ case 'decide':
890
+ return withSubject('decision', stringAttribute(span, 'gen_ai.agent.name'));
891
+ case 'embeddings':
892
+ return withSubject('call', stringAttribute(span, 'gen_ai.request.model'));
893
+ default:
894
+ break;
895
+ }
896
+ if ('http.request.method' in span.attributes) {
897
+ return withSubject('http', stringAttribute(span, 'url.path'));
898
+ }
899
+ if (span.name === 'cutout')
900
+ return withSubject('cutout', stringAttribute(span, 'url.path'));
901
+ if (span.name === 'theorem.eval.trial' || span.name === 'theorem.eval.run') {
902
+ return withSubject('evaluation', stringAttribute(span, 'theorem.evaluation.suite'));
903
+ }
904
+ return withSubject('host', span.name);
905
+ }
906
+ export { TRACE_ATTRIBUTE_GROUPS, TRACE_FIELDS, TRACE_SPAN_TYPES, TRACE_STATUS, traceAttributeMeta, traceCatalogRows, traceEventAttributeMeta, traceEventMeta, traceSpanMeta, };