@theoremjs/agents 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (568) hide show
  1. package/README.md +276 -995
  2. package/esm/mod.d.ts +33 -19
  3. package/esm/mod.js +18 -11
  4. package/esm/src/cli/commands/bench.js +36 -14
  5. package/esm/src/cli/commands/detect-compile.d.ts +17 -0
  6. package/esm/src/cli/commands/detect-compile.js +22 -0
  7. package/esm/src/cli/commands/eval.d.ts +3 -3
  8. package/esm/src/cli/commands/fuzz-canary.js +55 -16
  9. package/esm/src/cli/commands/profile.js +4 -4
  10. package/esm/src/cli/commands/run.d.ts +2 -2
  11. package/esm/src/cli/commands/run.js +1 -1
  12. package/esm/src/cli/commands/test.d.ts +4 -3
  13. package/esm/src/cli/commands/test.js +2 -2
  14. package/esm/src/cli/index.js +9 -9
  15. package/esm/src/cli/matrix/fixtures.js +25 -30
  16. package/esm/src/evals/attachments.d.ts +1 -0
  17. package/esm/src/evals/attachments.js +4 -2
  18. package/esm/src/evals/breakdown.d.ts +2 -0
  19. package/esm/src/evals/breakdown.js +1 -0
  20. package/esm/src/evals/graders/answer.d.ts +3 -0
  21. package/esm/src/evals/graders/answer.js +1 -0
  22. package/esm/src/evals/graders/code.d.ts +7 -31
  23. package/esm/src/evals/graders/code.js +4 -25
  24. package/esm/src/evals/graders/judge.d.ts +4 -0
  25. package/esm/src/evals/graders/judge.js +7 -5
  26. package/esm/src/evals/graders/latency.d.ts +1 -0
  27. package/esm/src/evals/graders/latency.js +3 -2
  28. package/esm/src/evals/graders/live.d.ts +3 -0
  29. package/esm/src/evals/graders/live.js +2 -0
  30. package/esm/src/evals/graders/media.js +1 -2
  31. package/esm/src/evals/graders/shared.js +1 -1
  32. package/esm/src/evals/graders/transcript.d.ts +2 -0
  33. package/esm/src/evals/graders/transcript.js +5 -3
  34. package/esm/src/evals/mod.d.ts +1 -9
  35. package/esm/src/evals/mod.js +1 -9
  36. package/esm/src/evals/record.d.ts +6 -0
  37. package/esm/src/evals/record.js +4 -2
  38. package/esm/src/evals/rubrics/mod.d.ts +1 -1
  39. package/esm/src/evals/rubrics/mod.js +1 -1
  40. package/esm/src/evals/rubrics/mustache.js +1 -1
  41. package/esm/src/evals/rubrics/types.js +1 -1
  42. package/esm/src/evals/run.d.ts +9 -52
  43. package/esm/src/evals/run.js +12 -46
  44. package/esm/src/evals/suite.d.ts +12 -3
  45. package/esm/src/evals/suite.js +9 -4
  46. package/esm/src/evals/summary.d.ts +3 -0
  47. package/esm/src/evals/summary.js +1 -0
  48. package/esm/src/evals/trial.d.ts +3 -16
  49. package/esm/src/evals/trial.js +7 -30
  50. package/esm/src/evals/types.d.ts +30 -121
  51. package/esm/src/evals/types.js +3 -16
  52. package/esm/src/evals/verdict.d.ts +5 -0
  53. package/esm/src/evals/verdict.js +4 -1
  54. package/esm/src/guardrails/boundaries.d.ts +41 -0
  55. package/esm/src/guardrails/boundaries.js +103 -0
  56. package/esm/src/guardrails/canary-gate.d.ts +1 -0
  57. package/esm/src/guardrails/canary.d.ts +49 -15
  58. package/esm/src/guardrails/canary.js +103 -30
  59. package/esm/src/guardrails/compile-egress.d.ts +6 -5
  60. package/esm/src/guardrails/compile-egress.js +6 -5
  61. package/esm/src/guardrails/corpus/canary-egress-attacks.d.ts +3 -1
  62. package/esm/src/guardrails/corpus/canary-egress-attacks.js +4 -2
  63. package/esm/src/guardrails/corpus/fuzz-inbound.js +14 -17
  64. package/esm/src/guardrails/corpus/inbound-payloads.d.ts +2 -0
  65. package/esm/src/guardrails/corpus/inbound-payloads.js +4 -2
  66. package/esm/src/guardrails/corpus/live-attacks.d.ts +2 -0
  67. package/esm/src/guardrails/corpus/live-attacks.js +6 -1
  68. package/esm/src/guardrails/corpus/mod.d.ts +1 -1
  69. package/esm/src/guardrails/corpus/secrets.d.ts +3 -3
  70. package/esm/src/guardrails/corpus/secrets.js +2 -2
  71. package/esm/src/guardrails/corpus/strings.d.ts +1 -1
  72. package/esm/src/guardrails/corpus/strings.js +1 -1
  73. package/esm/src/guardrails/corpus/types.d.ts +5 -1
  74. package/esm/src/guardrails/credential-rules.d.ts +36 -0
  75. package/esm/src/guardrails/credential-rules.js +3001 -0
  76. package/esm/src/guardrails/credential-scan.d.ts +45 -0
  77. package/esm/src/guardrails/credential-scan.js +172 -0
  78. package/esm/src/guardrails/destinations.d.ts +45 -0
  79. package/esm/src/guardrails/destinations.js +234 -0
  80. package/esm/src/guardrails/detect-at.d.ts +107 -0
  81. package/esm/src/guardrails/detect-at.js +434 -0
  82. package/esm/src/guardrails/detect-reply.d.ts +61 -0
  83. package/esm/src/guardrails/detect-reply.js +95 -0
  84. package/esm/src/guardrails/detect-stream.d.ts +33 -0
  85. package/esm/src/guardrails/detect-stream.js +77 -0
  86. package/esm/src/guardrails/detectors.d.ts +216 -0
  87. package/esm/src/guardrails/detectors.js +503 -0
  88. package/esm/src/guardrails/egress-automata.d.ts +4 -6
  89. package/esm/src/guardrails/egress-automata.js +24095 -4572
  90. package/esm/src/guardrails/egress-compiler.d.ts +38 -16
  91. package/esm/src/guardrails/egress-compiler.js +254 -60
  92. package/esm/src/guardrails/egress-patterns.d.ts +4 -2
  93. package/esm/src/guardrails/egress-patterns.js +6 -2
  94. package/esm/src/guardrails/egress-stream.d.ts +54 -36
  95. package/esm/src/guardrails/egress-stream.js +253 -124
  96. package/esm/src/guardrails/egress-urls.d.ts +6 -3
  97. package/esm/src/guardrails/egress-urls.js +14 -22
  98. package/esm/src/guardrails/egress.d.ts +26 -86
  99. package/esm/src/guardrails/egress.js +59 -309
  100. package/esm/src/guardrails/error.d.ts +13 -8
  101. package/esm/src/guardrails/error.js +23 -18
  102. package/esm/src/guardrails/event-schemas.d.ts +46 -3
  103. package/esm/src/guardrails/event-schemas.js +12 -5
  104. package/esm/src/guardrails/events.d.ts +5 -1
  105. package/esm/src/guardrails/events.js +4 -1
  106. package/esm/src/guardrails/hints.d.ts +14 -0
  107. package/esm/src/guardrails/hints.js +57 -0
  108. package/esm/src/guardrails/hits.d.ts +7 -1
  109. package/esm/src/guardrails/hits.js +12 -1
  110. package/esm/src/guardrails/host-patterns.d.ts +85 -0
  111. package/esm/src/guardrails/host-patterns.js +173 -0
  112. package/esm/src/guardrails/injection-patterns.d.ts +6 -1
  113. package/esm/src/guardrails/injection-patterns.js +33 -1
  114. package/esm/src/guardrails/injection-reversed.d.ts +9 -0
  115. package/esm/src/guardrails/injection-reversed.js +49 -0
  116. package/esm/src/guardrails/injection.d.ts +17 -1
  117. package/esm/src/guardrails/injection.js +259 -36
  118. package/esm/src/guardrails/labels.d.ts +40 -0
  119. package/esm/src/guardrails/labels.js +874 -0
  120. package/esm/src/guardrails/live-outbound-gate.d.ts +9 -8
  121. package/esm/src/guardrails/live-outbound-gate.js +100 -107
  122. package/esm/src/guardrails/mod.d.ts +29 -21
  123. package/esm/src/guardrails/mod.js +18 -13
  124. package/esm/src/guardrails/network.d.ts +4 -0
  125. package/esm/src/guardrails/network.js +21 -19
  126. package/esm/src/guardrails/normalize.d.ts +15 -1
  127. package/esm/src/guardrails/normalize.js +34 -1
  128. package/esm/src/guardrails/policy.d.ts +2 -17
  129. package/esm/src/guardrails/policy.js +12 -41
  130. package/esm/src/guardrails/progressive-yield.d.ts +65 -24
  131. package/esm/src/guardrails/progressive-yield.js +191 -147
  132. package/esm/src/guardrails/prompt-echo.d.ts +4 -2
  133. package/esm/src/guardrails/prompt-echo.js +87 -6
  134. package/esm/src/guardrails/quota.d.ts +1 -0
  135. package/esm/src/guardrails/quota.js +1 -1
  136. package/esm/src/guardrails/rules.d.ts +20 -29
  137. package/esm/src/guardrails/rules.js +23 -30
  138. package/esm/src/guardrails/sanitize.d.ts +32 -15
  139. package/esm/src/guardrails/sanitize.js +100 -124
  140. package/esm/src/guardrails/sensitive-groups.d.ts +21 -0
  141. package/esm/src/guardrails/sensitive-groups.js +12 -0
  142. package/esm/src/guardrails/sensitive.d.ts +16 -23
  143. package/esm/src/guardrails/sensitive.js +168 -47
  144. package/esm/src/guardrails/serialize.d.ts +1 -0
  145. package/esm/src/guardrails/testing.d.ts +4 -2
  146. package/esm/src/guardrails/testing.js +4 -2
  147. package/esm/src/guardrails/theorem-error.d.ts +4 -1
  148. package/esm/src/guardrails/theorem-error.js +3 -2
  149. package/esm/src/guardrails/thought-guard.d.ts +34 -13
  150. package/esm/src/guardrails/thought-guard.js +264 -64
  151. package/esm/src/guardrails/tool-directives.d.ts +29 -10
  152. package/esm/src/guardrails/tool-directives.js +133 -47
  153. package/esm/src/guardrails/tool-leak.d.ts +26 -0
  154. package/esm/src/guardrails/tool-leak.js +45 -0
  155. package/esm/src/guardrails/tool-result.d.ts +45 -14
  156. package/esm/src/guardrails/tool-result.js +94 -70
  157. package/esm/src/guardrails/types.d.ts +79 -71
  158. package/esm/src/guardrails/types.js +11 -7
  159. package/esm/src/host/client-turn.d.ts +29 -2
  160. package/esm/src/host/client-turn.js +46 -4
  161. package/esm/src/host/mint-trace.d.ts +1 -0
  162. package/esm/src/host/mint-trace.js +3 -2
  163. package/esm/src/host/mod.d.ts +2 -2
  164. package/esm/src/host/mod.js +1 -1
  165. package/esm/src/host/readStreamingJsonStringField.js +2 -43
  166. package/esm/src/host/reply.d.ts +6 -0
  167. package/esm/src/host/reply.js +7 -1
  168. package/esm/src/interface/blocks.d.ts +3 -0
  169. package/esm/src/interface/blocks.js +84 -14
  170. package/esm/src/interface/composer-actions.d.ts +4 -0
  171. package/esm/src/interface/composer-actions.js +5 -3
  172. package/esm/src/interface/draft.d.ts +6 -0
  173. package/esm/src/interface/draft.js +22 -11
  174. package/esm/src/interface/from-profile.d.ts +13 -1
  175. package/esm/src/interface/from-profile.js +66 -31
  176. package/esm/src/interface/history.d.ts +9 -3
  177. package/esm/src/interface/history.js +33 -24
  178. package/esm/src/interface/inputs.d.ts +1 -0
  179. package/esm/src/interface/inputs.js +3 -0
  180. package/esm/src/interface/mod.d.ts +4 -2
  181. package/esm/src/interface/mod.js +3 -2
  182. package/esm/src/interface/models.d.ts +7 -0
  183. package/esm/src/interface/models.js +5 -0
  184. package/esm/src/interface/pending.d.ts +9 -0
  185. package/esm/src/interface/pending.js +9 -3
  186. package/esm/src/interface/profile-interface.js +54 -40
  187. package/esm/src/interface/session.d.ts +12 -5
  188. package/esm/src/interface/session.js +17 -10
  189. package/esm/src/interface/stop.d.ts +13 -0
  190. package/esm/src/interface/stop.js +28 -0
  191. package/esm/src/interface/tool-calls.d.ts +14 -2
  192. package/esm/src/interface/tool-calls.js +64 -10
  193. package/esm/src/interface/tool-invoke.d.ts +2 -0
  194. package/esm/src/interface/tool-invoke.js +3 -1
  195. package/esm/src/interface/tool-media.d.ts +2 -0
  196. package/esm/src/interface/tool-media.js +2 -1
  197. package/esm/src/interface/types.d.ts +105 -40
  198. package/esm/src/interface/types.js +1 -0
  199. package/esm/src/kernel/api-catalog.d.ts +85 -0
  200. package/esm/src/kernel/api-catalog.js +229 -0
  201. package/esm/src/kernel/auth/crypto.d.ts +7 -2
  202. package/esm/src/kernel/auth/crypto.js +12 -10
  203. package/esm/src/kernel/auth/oauth.d.ts +2 -1
  204. package/esm/src/kernel/auth/oauth.js +23 -22
  205. package/esm/src/kernel/auth/typed-secret.js +2 -2
  206. package/esm/src/kernel/auth/types.d.ts +13 -0
  207. package/esm/src/kernel/checkpoint.d.ts +43 -0
  208. package/esm/src/kernel/checkpoint.js +58 -0
  209. package/esm/src/kernel/default-scope.d.ts +43 -5
  210. package/esm/src/kernel/default-scope.js +54 -5
  211. package/esm/src/kernel/engine/call-trace.d.ts +19 -0
  212. package/esm/src/kernel/engine/call-trace.js +29 -0
  213. package/esm/src/kernel/engine/compaction.d.ts +6 -5
  214. package/esm/src/kernel/engine/compaction.js +12 -11
  215. package/esm/src/kernel/engine/decision.d.ts +10 -8
  216. package/esm/src/kernel/engine/decision.js +173 -146
  217. package/esm/src/kernel/engine/embedding.d.ts +8 -0
  218. package/esm/src/kernel/engine/embedding.js +118 -0
  219. package/esm/src/kernel/engine/live-inbound.d.ts +14 -4
  220. package/esm/src/kernel/engine/live-inbound.js +36 -11
  221. package/esm/src/kernel/engine/live-ingress.d.ts +6 -0
  222. package/esm/src/kernel/engine/live-ingress.js +6 -1
  223. package/esm/src/kernel/engine/repair.js +12 -12
  224. package/esm/src/kernel/engine/runner/gates.d.ts +2 -2
  225. package/esm/src/kernel/engine/runner/gates.js +287 -101
  226. package/esm/src/kernel/engine/runner/mod.d.ts +19 -5
  227. package/esm/src/kernel/engine/runner/mod.js +107 -56
  228. package/esm/src/kernel/engine/runner/nested.d.ts +32 -0
  229. package/esm/src/kernel/engine/runner/nested.js +134 -0
  230. package/esm/src/kernel/engine/runner/schema-validation.d.ts +24 -3
  231. package/esm/src/kernel/engine/runner/schema-validation.js +78 -4
  232. package/esm/src/kernel/engine/runner/stages.d.ts +1 -1
  233. package/esm/src/kernel/engine/runner/stages.js +1 -8
  234. package/esm/src/kernel/engine/runner/state.d.ts +33 -12
  235. package/esm/src/kernel/engine/runner/state.js +11 -1
  236. package/esm/src/kernel/engine/runner/step-order.d.ts +27 -0
  237. package/esm/src/kernel/engine/runner/step-order.js +165 -0
  238. package/esm/src/kernel/engine/runner/steps.d.ts +2 -2
  239. package/esm/src/kernel/engine/runner/steps.js +328 -169
  240. package/esm/src/kernel/engine/runner/stream.d.ts +42 -11
  241. package/esm/src/kernel/engine/runner/stream.js +197 -46
  242. package/esm/src/kernel/engine/runner/usage.d.ts +5 -5
  243. package/esm/src/kernel/engine/runner/usage.js +12 -14
  244. package/esm/src/kernel/engine/session/mod.d.ts +8 -6
  245. package/esm/src/kernel/engine/session/mod.js +360 -129
  246. package/esm/src/kernel/engine/session/session-trace.d.ts +10 -10
  247. package/esm/src/kernel/engine/session/session-trace.js +41 -30
  248. package/esm/src/kernel/engine/token-estimate.d.ts +10 -64
  249. package/esm/src/kernel/engine/token-estimate.js +14 -194
  250. package/esm/src/kernel/engine/tool-trace.d.ts +3 -3
  251. package/esm/src/kernel/engine/tool-trace.js +2 -1
  252. package/esm/src/kernel/engine/turn-trace.d.ts +8 -7
  253. package/esm/src/kernel/engine/turn-trace.js +28 -36
  254. package/esm/src/kernel/engine/usage.d.ts +6 -0
  255. package/esm/src/kernel/engine/usage.js +17 -0
  256. package/esm/src/kernel/interaction-parts.d.ts +3 -0
  257. package/esm/src/kernel/interaction-parts.js +18 -0
  258. package/esm/src/kernel/json.d.ts +10 -0
  259. package/esm/src/kernel/json.js +3 -0
  260. package/esm/src/kernel/mod.d.ts +38 -11
  261. package/esm/src/kernel/mod.js +22 -7
  262. package/esm/src/kernel/profile-graph.d.ts +11 -6
  263. package/esm/src/kernel/profile-graph.js +14 -7
  264. package/esm/src/kernel/profile-presence.d.ts +10 -1
  265. package/esm/src/kernel/profile-presence.js +90 -75
  266. package/esm/src/kernel/profile-scope.d.ts +7 -3
  267. package/esm/src/kernel/profile-scope.js +67 -55
  268. package/esm/src/kernel/protocols/binding.d.ts +65 -0
  269. package/esm/src/kernel/protocols/binding.js +125 -0
  270. package/esm/src/kernel/protocols/limits.d.ts +15 -0
  271. package/esm/src/kernel/protocols/limits.js +28 -0
  272. package/esm/src/kernel/protocols/mod.d.ts +5 -0
  273. package/esm/src/kernel/protocols/mod.js +5 -0
  274. package/esm/src/kernel/protocols/prices.d.ts +36 -0
  275. package/esm/src/kernel/protocols/prices.js +37 -0
  276. package/esm/src/kernel/protocols/protocol.d.ts +253 -0
  277. package/esm/src/kernel/protocols/protocol.js +253 -0
  278. package/esm/src/kernel/protocols/provider.d.ts +108 -0
  279. package/esm/src/kernel/protocols/provider.js +143 -0
  280. package/esm/src/kernel/protocols/runtime.d.ts +55 -0
  281. package/esm/src/kernel/protocols/runtime.js +534 -0
  282. package/esm/src/kernel/provider-budget.d.ts +32 -0
  283. package/esm/src/kernel/provider-budget.js +262 -0
  284. package/esm/src/kernel/provider-dispatch.d.ts +13 -0
  285. package/esm/src/kernel/provider-dispatch.js +36 -0
  286. package/esm/src/kernel/provider-live.d.ts +7 -0
  287. package/esm/src/kernel/provider-live.js +189 -0
  288. package/esm/src/kernel/provider-runtime.d.ts +57 -0
  289. package/esm/src/kernel/provider-runtime.js +524 -0
  290. package/esm/src/kernel/registry/attachments.d.ts +15 -4
  291. package/esm/src/kernel/registry/attachments.js +31 -22
  292. package/esm/src/kernel/registry/catalog.d.ts +6 -0
  293. package/esm/src/kernel/registry/catalog.js +9 -2
  294. package/esm/src/kernel/registry/embedding-rules.d.ts +28 -0
  295. package/esm/src/kernel/registry/embedding-rules.js +66 -0
  296. package/esm/src/kernel/registry/ingress.d.ts +6 -2
  297. package/esm/src/kernel/registry/ingress.js +55 -10
  298. package/esm/src/kernel/registry/kernel-registry.d.ts +3 -0
  299. package/esm/src/kernel/registry/kernel-registry.js +9 -2
  300. package/esm/src/kernel/registry/profile-outputs.js +4 -1
  301. package/esm/src/kernel/registry/profiles.d.ts +38 -14
  302. package/esm/src/kernel/registry/profiles.js +280 -205
  303. package/esm/src/kernel/registry/provider-request.d.ts +3 -3
  304. package/esm/src/kernel/registry/provider-request.js +5 -13
  305. package/esm/src/kernel/registry/resolve.d.ts +4 -1
  306. package/esm/src/kernel/registry/resolve.js +59 -58
  307. package/esm/src/kernel/registry/schemas.d.ts +3 -0
  308. package/esm/src/kernel/registry/schemas.js +3 -1
  309. package/esm/src/kernel/registry/slot-fill.d.ts +7 -0
  310. package/esm/src/kernel/registry/slot-fill.js +22 -0
  311. package/esm/src/kernel/registry/system-prompt.js +7 -8
  312. package/esm/src/kernel/registry/vault.d.ts +14 -13
  313. package/esm/src/kernel/registry/vault.js +1 -14
  314. package/esm/src/kernel/schema.d.ts +100 -46
  315. package/esm/src/kernel/schema.js +499 -257
  316. package/esm/src/kernel/scope.d.ts +12 -5
  317. package/esm/src/kernel/scope.js +23 -3
  318. package/esm/src/kernel/stages.d.ts +38 -3
  319. package/esm/src/kernel/stages.js +82 -39
  320. package/esm/src/kernel/stop.d.ts +29 -6
  321. package/esm/src/kernel/stop.js +16 -4
  322. package/esm/src/kernel/system-parts.js +6 -6
  323. package/esm/src/kernel/tools/activity-label.d.ts +12 -6
  324. package/esm/src/kernel/tools/activity-label.js +258 -32
  325. package/esm/src/kernel/tools/agent.d.ts +66 -0
  326. package/esm/src/kernel/tools/agent.js +212 -0
  327. package/esm/src/kernel/tools/coordinate.d.ts +4 -0
  328. package/esm/src/kernel/tools/coordinate.js +165 -0
  329. package/esm/src/kernel/tools/events.d.ts +21 -6
  330. package/esm/src/kernel/tools/events.js +53 -18
  331. package/esm/src/kernel/tools/execute.d.ts +47 -11
  332. package/esm/src/kernel/tools/execute.js +508 -136
  333. package/esm/src/kernel/tools/gate-answer.d.ts +12 -2
  334. package/esm/src/kernel/tools/gate-answer.js +17 -6
  335. package/esm/src/kernel/tools/handler-events.d.ts +45 -0
  336. package/esm/src/kernel/tools/handler-events.js +106 -0
  337. package/esm/src/kernel/tools/harness.d.ts +1 -0
  338. package/esm/src/kernel/tools/harness.js +2 -1
  339. package/esm/src/kernel/tools/http-limit.d.ts +27 -0
  340. package/esm/src/kernel/tools/http-limit.js +85 -0
  341. package/esm/src/kernel/tools/invoke.d.ts +27 -5
  342. package/esm/src/kernel/tools/invoke.js +223 -70
  343. package/esm/src/kernel/tools/mcp-sessions.d.ts +4 -1
  344. package/esm/src/kernel/tools/mcp-sessions.js +13 -8
  345. package/esm/src/kernel/tools/mod.d.ts +4 -3
  346. package/esm/src/kernel/tools/mod.js +3 -2
  347. package/esm/src/kernel/tools/model-text.d.ts +10 -5
  348. package/esm/src/kernel/tools/model-text.js +18 -12
  349. package/esm/src/kernel/tools/operation.d.ts +76 -0
  350. package/esm/src/kernel/tools/operation.js +100 -0
  351. package/esm/src/kernel/tools/page-answer.d.ts +8 -0
  352. package/esm/src/kernel/tools/page-answer.js +19 -0
  353. package/esm/src/kernel/tools/permission.d.ts +11 -2
  354. package/esm/src/kernel/tools/permission.js +12 -12
  355. package/esm/src/kernel/tools/project.d.ts +4 -1
  356. package/esm/src/kernel/tools/project.js +32 -2
  357. package/esm/src/kernel/tools/registry.d.ts +9 -2
  358. package/esm/src/kernel/tools/registry.js +69 -10
  359. package/esm/src/kernel/tools/remote.d.ts +40 -6
  360. package/esm/src/kernel/tools/remote.js +219 -92
  361. package/esm/src/kernel/tools/resolve.d.ts +3 -0
  362. package/esm/src/kernel/tools/resolve.js +12 -4
  363. package/esm/src/kernel/tools/run.d.ts +28 -0
  364. package/esm/src/kernel/tools/run.js +86 -0
  365. package/esm/src/kernel/tools/schema.d.ts +3 -3
  366. package/esm/src/kernel/tools/schema.js +21 -100
  367. package/esm/src/kernel/tools/signed-in-fetch.d.ts +2 -1
  368. package/esm/src/kernel/tools/signed-in-fetch.js +3 -3
  369. package/esm/src/kernel/tools/stage-run.d.ts +27 -4
  370. package/esm/src/kernel/tools/stage-run.js +75 -17
  371. package/esm/src/kernel/tools/types.d.ts +235 -25
  372. package/esm/src/kernel/tools/unchecked-output.d.ts +14 -0
  373. package/esm/src/kernel/tools/unchecked-output.js +18 -0
  374. package/esm/src/kernel/turn-events.d.ts +208 -31
  375. package/esm/src/kernel/turn-events.js +127 -9
  376. package/esm/src/kernel/types.d.ts +302 -161
  377. package/esm/src/kernel/util/base64.d.ts +2 -0
  378. package/esm/src/kernel/util/base64.js +2 -0
  379. package/esm/src/kernel/util/partial-json.d.ts +23 -0
  380. package/esm/src/kernel/util/partial-json.js +128 -0
  381. package/esm/src/kernel/util/record.d.ts +1 -0
  382. package/esm/src/kernel/util/record.js +1 -0
  383. package/esm/src/observability/destinations.d.ts +5 -0
  384. package/esm/src/observability/destinations.js +7 -2
  385. package/esm/src/observability/jsonl.d.ts +2 -2
  386. package/esm/src/observability/jsonl.js +15 -22
  387. package/esm/src/observability/mod.d.ts +3 -3
  388. package/esm/src/observability/mod.js +2 -2
  389. package/esm/src/observability/openinference.d.ts +1 -1
  390. package/esm/src/observability/openinference.js +3 -3
  391. package/esm/src/observability/otlp.d.ts +3 -0
  392. package/esm/src/observability/otlp.js +3 -3
  393. package/esm/src/observability/phoenix.d.ts +1 -0
  394. package/esm/src/observability/policy.d.ts +3 -0
  395. package/esm/src/observability/policy.js +5 -1
  396. package/esm/src/observability/resolve-policy.js +11 -5
  397. package/esm/src/observability/spans.d.ts +8 -2
  398. package/esm/src/observability/spans.js +21 -5
  399. package/esm/src/observability/trace-catalog.d.ts +19 -2
  400. package/esm/src/observability/trace-catalog.js +128 -87
  401. package/esm/src/observability/trace-record.js +22 -17
  402. package/esm/src/observability/trace-schema.d.ts +3 -0
  403. package/esm/src/observability/trace-schema.js +1 -1
  404. package/esm/src/observability/trace-sink.d.ts +1 -0
  405. package/esm/src/observability/trace-sink.js +1 -1
  406. package/esm/src/observability/trace-span.d.ts +7 -1
  407. package/esm/src/observability/trace-span.js +3 -1
  408. package/esm/src/observability/trace.d.ts +2 -0
  409. package/esm/src/observability/trace.js +4 -2
  410. package/esm/src/observability/types.d.ts +35 -11
  411. package/esm/src/observability/types.js +1 -1
  412. package/esm/src/presets/google/speech-voices.d.ts +1 -0
  413. package/esm/src/presets/google-limits.d.ts +1 -0
  414. package/esm/src/presets/google.d.ts +27 -12
  415. package/esm/src/presets/google.js +34 -25
  416. package/esm/src/presets/local.d.ts +26 -0
  417. package/esm/src/presets/local.js +30 -0
  418. package/esm/src/presets/mod.d.ts +5 -4
  419. package/esm/src/presets/mod.js +4 -4
  420. package/esm/src/presets/openrouter.d.ts +14 -1
  421. package/esm/src/presets/openrouter.js +19 -1
  422. package/esm/src/providers/embedding-limits.d.ts +7 -0
  423. package/esm/src/providers/embedding-limits.js +12 -0
  424. package/esm/src/providers/gemini/embedding-protocol.d.ts +8 -0
  425. package/esm/src/providers/gemini/embedding-protocol.js +125 -0
  426. package/esm/src/providers/gemini/interactions-protocol.d.ts +8 -0
  427. package/esm/src/providers/gemini/interactions-protocol.js +105 -0
  428. package/esm/src/providers/gemini/live-protocol.d.ts +3 -0
  429. package/esm/src/providers/gemini/live-protocol.js +191 -0
  430. package/esm/src/providers/gemini/prices.d.ts +3 -0
  431. package/esm/src/providers/gemini/prices.js +63 -0
  432. package/esm/src/providers/gemini/provider.d.ts +7 -0
  433. package/esm/src/providers/gemini/provider.js +39 -0
  434. package/esm/src/providers/google/builtins.d.ts +14 -0
  435. package/esm/src/providers/google/builtins.js +57 -0
  436. package/esm/src/providers/google/grounding.d.ts +4 -4
  437. package/esm/src/providers/google/interactions/framing.d.ts +20 -8
  438. package/esm/src/providers/google/interactions/framing.js +85 -44
  439. package/esm/src/providers/google/interactions/steps.d.ts +5 -5
  440. package/esm/src/providers/google/interactions/steps.js +4 -4
  441. package/esm/src/providers/google/interactions/stream.d.ts +10 -11
  442. package/esm/src/providers/google/interactions/stream.js +33 -100
  443. package/esm/src/providers/google/live/framing.d.ts +15 -5
  444. package/esm/src/providers/google/live/framing.js +25 -25
  445. package/esm/src/providers/google/live/stream.d.ts +6 -44
  446. package/esm/src/providers/google/live/stream.js +3 -209
  447. package/esm/src/providers/google/urls.d.ts +1 -3
  448. package/esm/src/providers/google/urls.js +1 -3
  449. package/esm/src/providers/google/usage.js +2 -2
  450. package/esm/src/providers/live.d.ts +6 -0
  451. package/esm/src/providers/live.js +6 -0
  452. package/esm/src/providers/local/embedding-protocol.d.ts +7 -0
  453. package/esm/src/providers/local/embedding-protocol.js +60 -0
  454. package/esm/src/providers/local/provider.d.ts +7 -0
  455. package/esm/src/providers/local/provider.js +28 -0
  456. package/esm/src/providers/mod.d.ts +28 -7
  457. package/esm/src/providers/mod.js +19 -3
  458. package/esm/src/providers/open-ai/protocol.d.ts +3 -0
  459. package/esm/src/providers/open-ai/protocol.js +189 -0
  460. package/esm/src/providers/openrouter/embedding-protocol.d.ts +6 -0
  461. package/esm/src/providers/openrouter/embedding-protocol.js +86 -0
  462. package/esm/src/providers/openrouter/image.d.ts +0 -9
  463. package/esm/src/providers/openrouter/image.js +0 -153
  464. package/esm/src/providers/openrouter/images-protocol.d.ts +3 -0
  465. package/esm/src/providers/openrouter/images-protocol.js +82 -0
  466. package/esm/src/providers/openrouter/openai/compat.d.ts +2 -2
  467. package/esm/src/providers/openrouter/openai/compat.js +6 -6
  468. package/esm/src/providers/openrouter/openai/image-payload.d.ts +2 -2
  469. package/esm/src/providers/openrouter/openai/reasoning-state.d.ts +2 -0
  470. package/esm/src/providers/openrouter/openai/reasoning-state.js +31 -0
  471. package/esm/src/providers/openrouter/protocol.d.ts +8 -0
  472. package/esm/src/providers/openrouter/protocol.js +171 -0
  473. package/esm/src/providers/openrouter/provider.d.ts +10 -0
  474. package/esm/src/providers/openrouter/provider.js +50 -0
  475. package/esm/src/providers/shared/carried-tool-files.d.ts +7 -0
  476. package/esm/src/providers/shared/carried-tool-files.js +43 -0
  477. package/esm/src/providers/shared/pcm.js +2 -2
  478. package/esm/src/providers/shared/protocol-events.d.ts +8 -0
  479. package/esm/src/providers/shared/protocol-events.js +20 -0
  480. package/esm/src/providers/shared/response-identity.d.ts +2 -2
  481. package/esm/src/providers/shared/retry.d.ts +17 -0
  482. package/esm/src/providers/shared/retry.js +90 -0
  483. package/esm/src/providers/shared/sse.d.ts +0 -4
  484. package/esm/src/providers/shared/sse.js +50 -36
  485. package/esm/src/providers/shared/tool-args.d.ts +6 -7
  486. package/esm/src/providers/shared/tool-args.js +10 -6
  487. package/esm/src/providers/shared/tool-draft.d.ts +16 -0
  488. package/esm/src/providers/shared/tool-draft.js +14 -0
  489. package/esm/src/providers/shared/upstream-tap.d.ts +2 -2
  490. package/esm/src/providers/shared/upstream-tape.js +1 -1
  491. package/esm/src/providers/system-one/protocol.d.ts +8 -0
  492. package/esm/src/providers/system-one/protocol.js +93 -0
  493. package/esm/src/providers/types.d.ts +48 -16
  494. package/esm/src/providers/types.js +2 -1
  495. package/esm/src/providers/typesafe/provider.d.ts +7 -0
  496. package/esm/src/providers/typesafe/provider.js +24 -0
  497. package/esm/src/surface/formats.d.ts +19 -1
  498. package/esm/src/surface/formats.js +68 -29
  499. package/esm/src/surface/mod.d.ts +4 -2
  500. package/esm/src/surface/mod.js +4 -2
  501. package/esm/src/surface/runtime.d.ts +4 -0
  502. package/esm/src/surface/runtime.js +2 -0
  503. package/esm/src/surface/tools.d.ts +2 -8
  504. package/esm/src/surface/tools.js +4 -22
  505. package/esm/src/surface/types.d.ts +6 -0
  506. package/package.json +5 -13
  507. package/esm/src/cli/commands/egress-compile.d.ts +0 -17
  508. package/esm/src/cli/commands/egress-compile.js +0 -25
  509. package/esm/src/guardrails/egress-policy.d.ts +0 -27
  510. package/esm/src/guardrails/egress-policy.js +0 -76
  511. package/esm/src/guardrails/egress-rules.d.ts +0 -54
  512. package/esm/src/guardrails/egress-rules.js +0 -49
  513. package/esm/src/guardrails/lexicon.d.ts +0 -30
  514. package/esm/src/guardrails/lexicon.js +0 -478
  515. package/esm/src/kernel/engine/media-probe/audio.d.ts +0 -7
  516. package/esm/src/kernel/engine/media-probe/audio.js +0 -342
  517. package/esm/src/kernel/engine/media-probe/bytes.d.ts +0 -6
  518. package/esm/src/kernel/engine/media-probe/bytes.js +0 -26
  519. package/esm/src/kernel/engine/media-probe/image.d.ts +0 -5
  520. package/esm/src/kernel/engine/media-probe/image.js +0 -171
  521. package/esm/src/kernel/engine/media-probe/iso-bmff.d.ts +0 -19
  522. package/esm/src/kernel/engine/media-probe/iso-bmff.js +0 -48
  523. package/esm/src/kernel/engine/media-probe/matroska.d.ts +0 -35
  524. package/esm/src/kernel/engine/media-probe/matroska.js +0 -226
  525. package/esm/src/kernel/engine/media-probe/mp4.d.ts +0 -22
  526. package/esm/src/kernel/engine/media-probe/mp4.js +0 -279
  527. package/esm/src/kernel/engine/media-probe/opus.d.ts +0 -4
  528. package/esm/src/kernel/engine/media-probe/opus.js +0 -23
  529. package/esm/src/kernel/engine/media-probe/pdf.d.ts +0 -5
  530. package/esm/src/kernel/engine/media-probe/pdf.js +0 -117
  531. package/esm/src/kernel/engine/media-probe/video.d.ts +0 -15
  532. package/esm/src/kernel/engine/media-probe/video.js +0 -49
  533. package/esm/src/presets/typesafe.d.ts +0 -2
  534. package/esm/src/presets/typesafe.js +0 -2
  535. package/esm/src/providers/create-provider.d.ts +0 -21
  536. package/esm/src/providers/create-provider.js +0 -90
  537. package/esm/src/providers/decision/usage.d.ts +0 -3
  538. package/esm/src/providers/decision/usage.js +0 -25
  539. package/esm/src/providers/google/interactions/mod.d.ts +0 -2
  540. package/esm/src/providers/google/interactions/mod.js +0 -2
  541. package/esm/src/providers/google/keys.d.ts +0 -20
  542. package/esm/src/providers/google/keys.js +0 -87
  543. package/esm/src/providers/google/live/mod.d.ts +0 -7
  544. package/esm/src/providers/google/live/mod.js +0 -7
  545. package/esm/src/providers/google/live/openapi-schema.d.ts +0 -1
  546. package/esm/src/providers/google/live/openapi-schema.js +0 -42
  547. package/esm/src/providers/google/live/session.d.ts +0 -14
  548. package/esm/src/providers/google/live/session.js +0 -150
  549. package/esm/src/providers/local/local.d.ts +0 -12
  550. package/esm/src/providers/local/local.js +0 -186
  551. package/esm/src/providers/local/mod.d.ts +0 -8
  552. package/esm/src/providers/local/mod.js +0 -8
  553. package/esm/src/providers/openrouter/cache-control.d.ts +0 -5
  554. package/esm/src/providers/openrouter/cache-control.js +0 -4
  555. package/esm/src/providers/openrouter/chat.d.ts +0 -64
  556. package/esm/src/providers/openrouter/chat.js +0 -490
  557. package/esm/src/providers/openrouter/openai/sdk-messages.d.ts +0 -10
  558. package/esm/src/providers/openrouter/openai/sdk-messages.js +0 -99
  559. package/esm/src/providers/openrouter/resolve-api-key.d.ts +0 -3
  560. package/esm/src/providers/openrouter/resolve-api-key.js +0 -8
  561. package/esm/src/providers/openrouter/speech.d.ts +0 -18
  562. package/esm/src/providers/openrouter/speech.js +0 -109
  563. package/esm/src/providers/probe.d.ts +0 -5
  564. package/esm/src/providers/probe.js +0 -15
  565. package/esm/src/providers/shared/builtin-wire.d.ts +0 -4
  566. package/esm/src/providers/shared/builtin-wire.js +0 -9
  567. package/esm/src/providers/shared/vault.d.ts +0 -13
  568. package/esm/src/providers/shared/vault.js +0 -41
@@ -1,16 +1,3 @@
1
- /**
2
- * Records → `Trial`. A live run hands the runner what its memory sink caught;
3
- * a recorded run hands it what a file held. Both build the same trial, so the
4
- * same graders give the same results.
5
- *
6
- * The root is the `invoke_agent` span with no agent above it in the set; a host
7
- * span above it (the host's request, when the host nests the turn under its own
8
- * span) does not hide it, and the topmost span above it is the trial's `top`. It
9
- * is never assumed to be the first record: a compaction turn's record can be
10
- * written before its parent's (P9).
11
- *
12
- * @module
13
- */
14
1
  import { TheoremError } from '../guardrails/error.js';
15
2
  import { contentOf, inlineContent } from '../observability/trace-record.js';
16
3
  function byStart(a, b) {
@@ -22,11 +9,9 @@ function operationOf(span) {
22
9
  const value = span.attributes['gen_ai.operation.name'];
23
10
  return typeof value === 'string' ? value : undefined;
24
11
  }
25
- /** Every span of every record, in start order. */
26
12
  function allSpans(records) {
27
13
  return records.flatMap((record) => record.spans).sort(byStart);
28
14
  }
29
- /** The spans above `span` in the set, nearest first; a parent outside the set ends the walk. */
30
15
  function ancestorsOf(span, byId) {
31
16
  const above = [];
32
17
  const seen = new Set([span.spanId]);
@@ -38,16 +23,13 @@ function ancestorsOf(span, byId) {
38
23
  }
39
24
  return above;
40
25
  }
41
- /**
42
- * The `invoke_agent` span with no `invoke_agent` above it in the set; the
43
- * earliest when several qualify (a session root before its responses).
44
- */
26
+ /** The earliest `invoke_agent` span with no `invoke_agent` above it; never assumed to be the first record, since a compaction turn's record can be written before its parent's (P9). */
45
27
  function rootOf(spans, byId) {
46
28
  const roots = spans.filter((span) => operationOf(span) === 'invoke_agent' &&
47
29
  !ancestorsOf(span, byId).some((above) => operationOf(above) === 'invoke_agent'));
48
30
  const [root] = roots;
49
31
  if (!root) {
50
- throw new TheoremError('config', 'trial records hold no invoke_agent root span'); // lexicon-exempt: developer contract error
32
+ throw new TheoremError('config', 'trial records hold no invoke_agent root span'); // labels-exempt: developer contract error
51
33
  }
52
34
  return root;
53
35
  }
@@ -55,7 +37,7 @@ function rootOf(spans, byId) {
55
37
  function mergedRecord(records) {
56
38
  const [first] = records;
57
39
  if (!first) {
58
- throw new TheoremError('config', 'a trial needs at least one trace record'); // lexicon-exempt: developer contract error
40
+ throw new TheoremError('config', 'a trial needs at least one trace record'); // labels-exempt: developer contract error
59
41
  }
60
42
  return { ...first, content: Object.assign({}, ...records.map((record) => record.content)) };
61
43
  }
@@ -69,7 +51,6 @@ function isObject(value) {
69
51
  function isMessageList(value) {
70
52
  return Array.isArray(value) && value.every(isObject);
71
53
  }
72
- /** The root's usage attributes as `TurnTokens`; zero when the root recorded none. */
73
54
  function usageOf(root) {
74
55
  const input = numberAttribute(root, 'gen_ai.usage.input_tokens') ?? 0;
75
56
  const output = numberAttribute(root, 'gen_ai.usage.output_tokens') ?? 0;
@@ -99,11 +80,7 @@ function usageOf(root) {
99
80
  };
100
81
  return costUsd === undefined ? { tokens } : { tokens, costUsd };
101
82
  }
102
- /**
103
- * What the host received. A turn's root carries `gen_ai.output.messages`; a
104
- * Live session's root carries none, and each response span carries its own
105
- * `theorem.output.delivered`, taken in start order.
106
- */
83
+ /** A turn's root carries `gen_ai.output.messages`; a Live session's root carries none, and each response span carries its own `theorem.output.delivered`. */
107
84
  function deliveredOf(root, spans) {
108
85
  const own = root.attributes['gen_ai.output.messages'];
109
86
  if (isMessageList(own))
@@ -115,7 +92,7 @@ function deliveredOf(root, spans) {
115
92
  return isMessageList(delivered) ? delivered : [];
116
93
  });
117
94
  }
118
- /** Build the trial every grader receives from the records that share one trace. */
95
+ /** Builds the `Trial` a grader reads from one trial's trace records: its root and top spans and accessors for spans, children, content, delivered output, and usage. */
119
96
  function buildTrial(args) {
120
97
  const merged = mergedRecord(args.records);
121
98
  const spans = allSpans(args.records);
@@ -136,7 +113,7 @@ function buildTrial(args) {
136
113
  usage: () => usageOf(root),
137
114
  };
138
115
  }
139
- /** Group records by trace id, in first-seen order. */
116
+ /** Groups trace records by the trace id of their first span; records with no spans are dropped. */
140
117
  function groupByTrace(records) {
141
118
  const groups = new Map();
142
119
  for (const record of records) {
@@ -151,7 +128,7 @@ function groupByTrace(records) {
151
128
  }
152
129
  return groups;
153
130
  }
154
- /** Whether these records hold a turn at all: an `invoke_agent` span. An eval run record does not. */
131
+ /** True when any record holds an `invoke_agent` span, meaning an agent turn ran. */
155
132
  function hasTurn(records) {
156
133
  return records.some((record) => record.spans.some((span) => operationOf(span) === 'invoke_agent'));
157
134
  }
@@ -1,96 +1,66 @@
1
- /**
2
- * Eval shapes: the suite a host writes, the cases it keeps in JSONL,
3
- * and the result every grader returns. Each is a documented type and a zod
4
- * schema checked against it (`Equals`): the type is what graders read; the
5
- * schema is what the runner runs on a file.
6
- *
7
- * Vocabulary follows Anthropic's evals guide so a host can read both: a
8
- * **suite** of **cases**, each run as k **trials**; a **grader** reads a
9
- * trial's transcript (its trace) and returns a **result**; the suite's pass
10
- * rule turns k results into one **verdict**.
11
- *
12
- * @module
13
- */
14
1
  import { z } from 'zod';
15
2
  import type { RunDecisionOptions } from '../kernel/engine/decision.js';
3
+ import type { ProviderHostOptions } from '../kernel/protocols/runtime.js';
16
4
  import type { TurnTokens } from '../kernel/turn-events.js';
17
- import type { ModelProvider } from '../kernel/types.js';
18
5
  import type { TraceRecord } from '../observability/trace-record.js';
19
6
  import type { TraceAttributeValue, TraceSpan } from '../observability/trace-span.js';
20
- /** Anthropic's split: does the agent *do* the thing (capability), or *still* do it (regression)? */
7
+ /** Whether a case probes what the profile can do (`capability`) or guards what it already did (`regression`). */
21
8
  export type EvalCaseKind = 'capability' | 'regression';
22
- /** A file the case attaches to its turn, inline, as `TurnBlob` takes it. */
9
+ /** An attachment carried in the case file as base64. */
23
10
  export interface EvalInlineAttachment {
24
11
  mimeType: string;
25
12
  /** Base64 bytes. */
26
13
  data: string;
27
14
  name?: string;
28
15
  }
29
- /**
30
- * A file the case attaches to its turn, kept beside the cases file and pinned
31
- * by the hex SHA-256 of its bytes; a file whose bytes hash otherwise is refused.
32
- */
16
+ /** A file attachment is pinned by the hex SHA-256 of its bytes; a file whose bytes hash otherwise is refused. */
33
17
  export interface EvalFileAttachment {
34
18
  mimeType: string;
35
- /** Relative to the cases file, or absolute; the loaded case holds it absolute. */
36
19
  path: string;
37
20
  sha256: string;
38
21
  name?: string;
39
22
  }
40
- /** A file the case attaches to its turn: its bytes inline, or a file beside the cases. */
23
+ /** An attachment a case sends: inline bytes or a file on disk. */
41
24
  export type EvalAttachment = EvalInlineAttachment | EvalFileAttachment;
42
- /** One turn's input (`mode: 'turn'`). */
25
+ /** A single-turn case input. */
43
26
  export interface EvalTurnInput {
44
27
  text?: string;
45
28
  attachments?: EvalAttachment[];
46
29
  }
47
- /** One scripted step of a Live session: send text, wait for the boundary it names. */
30
+ /** One message of a session case, sent once the previous step's turn completes. */
48
31
  export interface EvalSessionStep {
49
32
  text: string;
50
33
  until: 'turn_complete';
51
34
  }
52
- /** A scripted Live session (`mode: 'session'`): text steps in order. Audio steps are not in this slice. */
35
+ /** A multi-step session case input. */
53
36
  export interface EvalSessionInput {
54
37
  session: {
55
38
  steps: EvalSessionStep[];
56
39
  };
57
40
  }
58
- /** What the case sends: a turn's input or a session script. */
41
+ /** A case input: one turn or a session. */
59
42
  export type EvalCaseInput = EvalTurnInput | EvalSessionInput;
60
- /**
61
- * A dataset case's right answer. Only an `accepted` name passes; a `partial`
62
- * one is close but not enough (the genus, the broader condition); a `rejected`
63
- * one is a wrong answer the dataset records for the case (a confuser, an
64
- * identification it superseded).
65
- */
43
+ /** Only an `accepted` name passes; a `partial` one is close but not enough; a `rejected` one named beside an accepted name makes the reply `partial`, not a pass. */
66
44
  export interface EvalAnswer {
67
- /** Every name that counts: scientific name, synonyms, common names. */
68
45
  accepted: string[];
69
46
  partial?: string[];
70
- /** A reply that names one beside an accepted name hedged: `partial`, not a pass. */
71
47
  rejected?: string[];
72
- /** Grounding notes for the person reading a miss; no grader reads them. */
73
48
  reference?: string;
74
49
  }
75
- /** What the transcript should contain; graders that need it are skipped when it is absent. */
50
+ /** What a case expects: tools, JSON fields, a transcription, or an answer. */
76
51
  export interface EvalExpect {
77
- /** Tools the agent should call, in order (`toolTrajectory` reads it). Empty = no tool. */
78
52
  tools?: string[];
79
- /** Fields the delivered JSON should carry, each compared whole (`delivered.json` reads it). */
80
53
  json?: Record<string, unknown>;
81
- /** What the Live reply's transcript should say (`transcription.*` read it). */
82
54
  transcription?: {
83
55
  includes?: string;
84
56
  regex?: string;
85
57
  };
86
- /** The right answer to a dataset question (`answer` reads it). */
87
58
  answer?: EvalAnswer;
88
- /** For the human reading the case; no grader reads it. */
89
59
  notes?: string;
90
60
  }
91
- /** Perplexity's 1–5 difficulty; results are reported per bucket when set. */
61
+ /** How hard a case is, from 1 to 5. */
92
62
  export type EvalDifficulty = 1 | 2 | 3 | 4 | 5;
93
- /** One line of `cases.jsonl`. */
63
+ /** One eval case: its input and what the reply is expected to be. */
94
64
  export interface EvalCase {
95
65
  id: string;
96
66
  kind: EvalCaseKind;
@@ -99,113 +69,70 @@ export interface EvalCase {
99
69
  expect?: EvalExpect;
100
70
  tags?: string[];
101
71
  }
102
- /** What the runner runs on each line of a cases file. */
72
+ /** The schema an eval case parses against. */
103
73
  export declare const evalCaseSchema: z.ZodType<EvalCase>;
104
- /** The `gen_ai.operation.name` values a trial's spans carry. */
74
+ /** The operation a trace span records. */
105
75
  export type TraceOperation = 'invoke_agent' | 'chat' | 'generate_content' | 'execute_tool';
106
76
  /** A message as the trace stores it: `{ role, parts: [...] }`, parts by hash; resolve them with `text` / `content`. */
107
77
  export type TrialMessage = Record<string, TraceAttributeValue>;
108
- /** What the root span reports the trial cost, as the kernel's `TurnTokens`. */
78
+ /** Tokens and cost a trial used. */
109
79
  export interface TrialUsage {
110
80
  tokens: TurnTokens;
111
81
  costUsd?: number;
112
82
  }
113
- /**
114
- * One run of one case, as every grader receives it: the trace records that
115
- * share the trial's trace id and nothing else. If a grader needs a fact the
116
- * trace does not hold, the trace is wrong, not the grader.
117
- */
83
+ /** A grader receives the trace records that share the trial's trace id and nothing else; if it needs a fact the trace does not hold, the trace is wrong, not the grader. */
118
84
  export interface Trial {
119
85
  suite: string;
120
- /** Absent in caseless recorded mode (a production trace with no `metadata.eval`). */
121
86
  case?: EvalCase;
122
- /** 0..k-1. */
123
87
  index: number;
124
88
  records: TraceRecord[];
125
- /** The `invoke_agent` span with no agent above it in the set; never assumed to be first. */
126
89
  root: TraceSpan;
127
- /**
128
- * The topmost span above `root` in the set: the host's own span when the host
129
- * nested the turn under it, else `root`. Its length is the trial's time.
130
- */
90
+ /** The topmost span above `root`: the host's own span when the host nested the turn under it, else `root`. Its length is the trial's time. */
131
91
  top: TraceSpan;
132
- /** Spans by operation, in start order, across every record. */
133
92
  spans: (operation: TraceOperation) => TraceSpan[];
134
- /** The spans one span parents, in start order (a model call's HTTP tries, a response's tool calls). */
135
93
  children: (span: TraceSpan) => TraceSpan[];
136
- /** A value with every `{ content_sha256 }` / `{ json_sha256 }` reference replaced by its stored content. */
137
94
  content: (value: unknown) => unknown;
138
- /** The stored text one reference names; `undefined` for any other value. */
139
95
  text: (value: unknown) => string | undefined;
140
- /** What the host received: the root's output messages, or each Live response's, as stored. */
141
96
  delivered: () => TrialMessage[];
142
- /** Tokens and cost from the root's usage attributes. */
143
97
  usage: () => TrialUsage;
144
98
  }
145
- /** Who produced a result: a code grader, or a judge model. */
99
+ /** Whether a result came from code or from a model. */
146
100
  export type EvalResultSource = 'code' | 'model';
147
- /**
148
- * One grader's reading of one trial: the semconv `gen_ai.evaluation.result`
149
- * event, before it is written. `passed` is the grader's yes/no when it has one;
150
- * absent means the result informs but does not decide the verdict.
151
- */
101
+ /** One grader's verdict on a trial: a score, a label, and why. */
152
102
  export interface EvalResult {
153
- /** The grader's name, e.g. `tool_trajectory`, `faithfulness`. */
154
103
  name: string;
155
104
  source: EvalResultSource;
156
- /** `value` is 0–1 unless the grader says otherwise; `label` is one of the grader's labels. */
157
105
  score?: {
158
106
  value?: number;
159
107
  label?: string;
160
108
  };
161
- /** Why, in the grader's words. */
162
109
  explanation?: string;
163
110
  /** Whether this result counts as a pass. Absent: informational only. */
164
111
  passed?: boolean;
165
112
  /** Why no score could be produced; the result is then a failed one. */
166
113
  errorType?: string;
167
- /** Judge turns this result was drawn from (`traceparent` each); model graders only. */
168
114
  judgeTraceparents?: string[];
169
115
  }
170
- /** A result as a reader validates it, e.g. one rebuilt from a written event. */
116
+ /** The schema an eval result parses against. */
171
117
  export declare const evalResultSchema: z.ZodType<EvalResult>;
172
- /** How k trials become one verdict: every trial (pass^k), any trial (pass@k), or at least n. */
118
+ /** How many trials of a case must pass for the case to pass. */
173
119
  export type EvalPassRule = 'all' | 'any' | {
174
120
  atLeast: number;
175
121
  };
176
- /** How many times each case runs, and what counts as passing. */
122
+ /** How often a case runs, and the rule across those runs. */
177
123
  export interface EvalTrials {
178
124
  /** Trials per case. No default: it is a cost decision, so the suite states it. `1` cannot tell noise from change. */
179
125
  repeat: number;
180
- /** Default `all`. */
181
126
  pass?: EvalPassRule;
182
127
  }
183
- /**
184
- * What the runner hands every grader beside the trial. Code graders ignore it;
185
- * a model grader runs its judge through it and reports each judge call's
186
- * records through `traced`, so the runner can count their cost and write them
187
- * to the sink.
188
- */
128
+ /** What a grader gets besides the trial: the judge model and its trace parent. */
189
129
  export interface EvalGradeContext {
190
- /** The suite's judge profile, when it names one; a grader may name its own. */
191
130
  judge?: string;
192
- /** The host's provider for text judge profiles. */
193
- judgeProvider?: ModelProvider;
194
- /** The host's vault for decision judge profiles. */
131
+ judgeProvider?: ProviderHostOptions;
195
132
  judgeDecision?: Omit<RunDecisionOptions, 'sink'>;
196
- /**
197
- * The trial span as a W3C `traceparent`: a judge call runs under it, so it
198
- * lands in the judged trace beneath the trial. Absent, each judge call
199
- * starts a trace of its own.
200
- */
133
+ /** The trial span as a W3C `traceparent`: a judge call runs under it, so it lands in the judged trace beneath the trial. Absent, each judge call starts a trace of its own. */
201
134
  traceparent?: string;
202
- /**
203
- * The host's store for media a trace names only by hash. A judge that must
204
- * see media the case did not attach asks here; absent, only the case's own
205
- * attachments can be shown.
206
- */
207
135
  media?: EvalMediaResolver;
208
- /** Every record a grader's own judge call produced. */
209
136
  traced: (records: TraceRecord[]) => void | Promise<void>;
210
137
  signal?: AbortSignal;
211
138
  }
@@ -216,45 +143,27 @@ export interface EvalMediaRef {
216
143
  }
217
144
  /** The media's bytes as base64, or `undefined` when the host does not have them. */
218
145
  export type EvalMediaResolver = (ref: EvalMediaRef) => string | undefined | Promise<string | undefined>;
219
- /** Code or model logic that reads a trial and returns a result. */
146
+ /** Grades one trial of a case, from its trace. */
220
147
  export interface EvalGrader {
221
- /** The result's `gen_ai.evaluation.name`. */
222
148
  name: string;
223
- /**
224
- * Stable text naming exactly what this grader checks (its options, its
225
- * rubric). Its sha256 is written as `theorem.evaluation.grader.version`, so
226
- * a later reader can tell which rubric produced which score.
227
- */
149
+ /** Stable text naming exactly what this grader checks; its sha256 is written as `theorem.evaluation.grader.version`, so a later reader can tell which rubric produced which score. */
228
150
  identity: string;
229
151
  source: EvalResultSource;
230
- /** Reads the case's `expect`; skipped when a trial has no case (caseless recorded mode). */
231
152
  needsExpect: boolean;
232
- /**
233
- * Model graders: every judge profile this grader may run, given the suite's
234
- * `judge.profile`: its judge first, then any it escalates to. Throws when
235
- * there is none, or a profile cannot run this grader, so a suite fails
236
- * before its first trial.
237
- */
238
153
  judgeProfiles?: (suiteJudge: string | undefined) => string[];
239
154
  grade: (trial: Trial, context: EvalGradeContext) => EvalResult | Promise<EvalResult>;
240
155
  }
241
- /** A named set of cases against one profile, with graders and a pass rule. */
156
+ /** A suite: a profile, a mode, a cases file, and the graders to run. */
242
157
  export interface EvalSuite {
243
158
  id: string;
244
- /** The profile under test; any type but `host`. */
245
159
  profile: string;
246
160
  mode: 'turn' | 'session';
247
- /** Path to `cases.jsonl`, relative to the suite module. */
248
161
  cases: string;
249
162
  trials: EvalTrials;
250
163
  graders: EvalGrader[];
251
- /**
252
- * The judge profile model graders run unless they name their own: a text
253
- * profile that answers through `evalJudgment`, or a decision profile (Jev).
254
- */
255
164
  judge?: {
256
165
  profile: string;
257
166
  };
258
167
  }
259
- /** What the runner runs on a suite module's default export. */
168
+ /** The schema an eval suite parses against. */
260
169
  export declare const evalSuiteSchema: z.ZodType<EvalSuite>;
@@ -1,16 +1,3 @@
1
- /**
2
- * Eval shapes: the suite a host writes, the cases it keeps in JSONL,
3
- * and the result every grader returns. Each is a documented type and a zod
4
- * schema checked against it (`Equals`): the type is what graders read; the
5
- * schema is what the runner runs on a file.
6
- *
7
- * Vocabulary follows Anthropic's evals guide so a host can read both: a
8
- * **suite** of **cases**, each run as k **trials**; a **grader** reads a
9
- * trial's transcript (its trace) and returns a **result**; the suite's pass
10
- * rule turns k results into one **verdict**.
11
- *
12
- * @module
13
- */
14
1
  import { z } from 'zod';
15
2
  import { isRecord } from '../kernel/util/record.js';
16
3
  const evalCaseKind = z.enum(['capability', 'regression']);
@@ -75,7 +62,7 @@ const evalCase = z.object({
75
62
  tags: z.array(z.string()).optional(),
76
63
  });
77
64
  true;
78
- /** What the runner runs on each line of a cases file. */
65
+ /** The schema an eval case parses against. */
79
66
  export const evalCaseSchema = evalCase;
80
67
  const evalResultSource = z.enum(['code', 'model']);
81
68
  true;
@@ -89,7 +76,7 @@ const evalResult = z.object({
89
76
  judgeTraceparents: z.array(z.string()).optional(),
90
77
  });
91
78
  true;
92
- /** A result as a reader validates it, e.g. one rebuilt from a written event. */
79
+ /** The schema an eval result parses against. */
93
80
  export const evalResultSchema = evalResult;
94
81
  const evalPassRule = z.union([
95
82
  z.literal('all'),
@@ -122,5 +109,5 @@ const evalSuite = z.object({
122
109
  judge: z.object({ profile: z.string().min(1) }).optional(),
123
110
  });
124
111
  true;
125
- /** What the runner runs on a suite module's default export. */
112
+ /** The schema an eval suite parses against. */
126
113
  export const evalSuiteSchema = evalSuite;
@@ -1,6 +1,9 @@
1
1
  import type { EvalCase, EvalPassRule, EvalResult } from './types.js';
2
+ /** How a trial ended: passed, failed, errored, or ungraded. */
2
3
  type TrialOutcome = 'passed' | 'failed' | 'errored' | 'ungraded';
4
+ /** The outcome of a trial from its results. */
3
5
  declare function trialOutcome(results: readonly EvalResult[]): TrialOutcome;
6
+ /** A case's verdict across its trials, under the pass rule. */
4
7
  interface CaseVerdict {
5
8
  case: string;
6
9
  kind: EvalCase['kind'];
@@ -12,7 +15,9 @@ interface CaseVerdict {
12
15
  trialsErrored: number;
13
16
  trialsUngraded: number;
14
17
  }
18
+ /** The name of a pass rule, as the trace records it. */
15
19
  declare function passRuleName(rule: EvalPassRule): 'all' | 'any' | 'at_least';
20
+ /** The verdict of a case from its trials' results. */
16
21
  declare function caseVerdict(evalCase: EvalCase, trials: readonly (readonly EvalResult[])[], rule?: EvalPassRule): CaseVerdict;
17
22
  export type { CaseVerdict, TrialOutcome };
18
23
  export { caseVerdict, passRuleName, trialOutcome };
@@ -1,3 +1,4 @@
1
+ /** The outcome of a trial from its results. */
1
2
  function trialOutcome(results) {
2
3
  if (results.some((result) => result.errorType !== undefined))
3
4
  return 'errored';
@@ -18,10 +19,12 @@ function ruleMet(rule, passed, trials) {
18
19
  function trialsNeeded(rule) {
19
20
  return typeof rule === 'object' ? rule.atLeast : 1;
20
21
  }
22
+ /** The name of a pass rule, as the trace records it. */
21
23
  function passRuleName(rule) {
22
24
  return typeof rule === 'string' ? rule : 'at_least';
23
25
  }
24
- // An errored trial is one that could not be graded (a provider error, a judge that failed), so the rule reads it as a trial that never ran: a rate limit never counts against the agent.
26
+ // why: An errored trial is one that could not be graded (a provider error, a judge that failed), so the rule reads it as a trial that never ran: a rate limit never counts against the agent.
27
+ /** The verdict of a case from its trials' results. */
25
28
  function caseVerdict(evalCase, trials, rule = 'all') {
26
29
  const outcomes = trials.map(trialOutcome);
27
30
  const count = (outcome) => outcomes.filter((o) => o === outcome).length;
@@ -0,0 +1,41 @@
1
+ /** labels-exempt-file: authoring labels and descriptions for boundaries — not runtime user or model copy (P2) */
2
+ /** A record with one entry per key, typed by the keys it was built from. */
3
+ declare function recordOf<K extends string, V>(keys: readonly K[], value: (key: K) => V): Record<K, V>;
4
+ /**
5
+ * The kinds of tool whose text the kernel reads, in the words a builder writes as a tool's
6
+ * `type`. A provider builtin has none: the provider runs it and the kernel never reads its text.
7
+ */
8
+ declare const TOOL_KINDS: readonly ["function", "http", "mcp", "agent"];
9
+ /** One of {@linkcode TOOL_KINDS}. */
10
+ type ToolKind = (typeof TOOL_KINDS)[number];
11
+ /**
12
+ * The places a tool's text crosses: what the model sends, what comes back to it, its error text,
13
+ * and what the call shows the person (its output, error, artifacts, and trace on the turn's events).
14
+ */
15
+ declare const TOOL_CROSSINGS: readonly ["tool_arguments", "tool_output", "tool_failure", "tool_shown"];
16
+ /** One of {@linkcode TOOL_CROSSINGS}. */
17
+ type ToolCrossing = (typeof TOOL_CROSSINGS)[number];
18
+ /** A tool crossing for one kind of tool, such as `tool_output_mcp`. */
19
+ type ToolBoundary = `${ToolCrossing}_${ToolKind}`;
20
+ /** The boundary where `crossing` happens for a `kind` tool. */
21
+ declare function toolBoundary<C extends ToolCrossing, K extends ToolKind>(crossing: C, kind: K): `${C}_${K}`;
22
+ /** Every tool boundary, each crossing in turn for every kind of tool. */
23
+ declare const TOOL_BOUNDARIES: readonly ToolBoundary[];
24
+ /** Where text reaches the model from the person or the host. */
25
+ declare const INBOUND_BOUNDARIES: readonly ["user", "attachment", "voice", "slots", "context", "history", "injected", "system", "repair", "live_user"];
26
+ /** Where the model's own text reaches the person. */
27
+ declare const OUTBOUND_BOUNDARIES: readonly ["reply", "reply_structured", "live_reply", "thought"];
28
+ /** Every place the kernel reads text as it crosses, in the order a turn meets them. */
29
+ declare const BOUNDARIES: readonly ["user", "attachment", "voice", "slots", "context", "history", "injected", "system", "repair", "live_user", ...("tool_arguments_function" | "tool_arguments_http" | "tool_arguments_mcp" | "tool_arguments_agent" | "tool_output_function" | "tool_output_http" | "tool_output_mcp" | "tool_output_agent" | "tool_failure_function" | "tool_failure_http" | "tool_failure_mcp" | "tool_failure_agent" | "tool_shown_function" | "tool_shown_http" | "tool_shown_mcp" | "tool_shown_agent")[], "reply", "reply_structured", "live_reply", "thought"];
30
+ /** One of {@linkcode BOUNDARIES}. */
31
+ type Boundary = (typeof BOUNDARIES)[number];
32
+ /** How a boundary is named and described to a builder. */
33
+ interface BoundaryMeta {
34
+ label: string;
35
+ /** What is read there. */
36
+ doc: string;
37
+ }
38
+ /** The label and description of every boundary. */
39
+ declare const BOUNDARY_META: Readonly<Record<Boundary, BoundaryMeta>>;
40
+ export type { Boundary, BoundaryMeta, ToolBoundary, ToolCrossing, ToolKind };
41
+ export { BOUNDARIES, BOUNDARY_META, INBOUND_BOUNDARIES, OUTBOUND_BOUNDARIES, recordOf, TOOL_BOUNDARIES, TOOL_KINDS, toolBoundary, };
@@ -0,0 +1,103 @@
1
+ // invariant: Leaf module. Imports nothing from `src/guardrails/types.ts` or `src/kernel/`, so the
2
+ // vocabulary can be read by every layer without a cycle.
3
+ /** labels-exempt-file: authoring labels and descriptions for boundaries — not runtime user or model copy (P2) */
4
+ /** A record with one entry per key, typed by the keys it was built from. */
5
+ function recordOf(keys, value) {
6
+ return Object.fromEntries(keys.map((key) => [key, value(key)]));
7
+ }
8
+ /**
9
+ * The kinds of tool whose text the kernel reads, in the words a builder writes as a tool's
10
+ * `type`. A provider builtin has none: the provider runs it and the kernel never reads its text.
11
+ */
12
+ const TOOL_KINDS = ['function', 'http', 'mcp', 'agent'];
13
+ /**
14
+ * The places a tool's text crosses: what the model sends, what comes back to it, its error text,
15
+ * and what the call shows the person (its output, error, artifacts, and trace on the turn's events).
16
+ */
17
+ const TOOL_CROSSINGS = ['tool_arguments', 'tool_output', 'tool_failure', 'tool_shown'];
18
+ /** The boundary where `crossing` happens for a `kind` tool. */
19
+ function toolBoundary(crossing, kind) {
20
+ return `${crossing}_${kind}`;
21
+ }
22
+ /** Every tool boundary, each crossing in turn for every kind of tool. */
23
+ const TOOL_BOUNDARIES = TOOL_CROSSINGS.flatMap((crossing) => TOOL_KINDS.map((kind) => toolBoundary(crossing, kind)));
24
+ /** Where text reaches the model from the person or the host. */
25
+ const INBOUND_BOUNDARIES = [
26
+ 'user',
27
+ 'attachment',
28
+ 'voice',
29
+ 'slots',
30
+ 'context',
31
+ 'history',
32
+ 'injected',
33
+ 'system',
34
+ 'repair',
35
+ 'live_user',
36
+ ];
37
+ /** Where the model's own text reaches the person. */
38
+ const OUTBOUND_BOUNDARIES = ['reply', 'reply_structured', 'live_reply', 'thought'];
39
+ /** Every place the kernel reads text as it crosses, in the order a turn meets them. */
40
+ const BOUNDARIES = [
41
+ ...INBOUND_BOUNDARIES,
42
+ ...TOOL_BOUNDARIES,
43
+ ...OUTBOUND_BOUNDARIES,
44
+ ];
45
+ const TOOL_KIND_LABELS = {
46
+ function: 'function',
47
+ http: 'HTTP',
48
+ mcp: 'MCP',
49
+ agent: 'agent',
50
+ };
51
+ const TOOL_CROSSING_META = {
52
+ tool_arguments: (kind) => ({
53
+ label: `Arguments to ${kind} tools`,
54
+ doc: `What the model sends to a tool of type ${kind}.`,
55
+ }),
56
+ tool_output: (kind) => ({
57
+ label: `Output of ${kind} tools`,
58
+ doc: `What a tool of type ${kind} returns.`,
59
+ }),
60
+ tool_failure: (kind) => ({
61
+ label: `Errors from ${kind} tools`,
62
+ doc: `The error text of a tool of type ${kind} that failed.`,
63
+ }),
64
+ tool_shown: (kind) => ({
65
+ label: `Shown from ${kind} tools`,
66
+ doc: `What a call to a tool of type ${kind} shows the person: its output, error, artifacts, and trace.`,
67
+ }),
68
+ };
69
+ function toolBoundaryMeta() {
70
+ const entries = TOOL_CROSSINGS.flatMap((crossing) => TOOL_KINDS.map((kind) => [
71
+ toolBoundary(crossing, kind),
72
+ TOOL_CROSSING_META[crossing](TOOL_KIND_LABELS[kind]),
73
+ ]));
74
+ return Object.fromEntries(entries);
75
+ }
76
+ /** The label and description of every boundary. */
77
+ const BOUNDARY_META = {
78
+ user: { label: 'User message', doc: 'The message the person typed.' },
79
+ attachment: { label: 'Attachments', doc: 'The text of a file the person attached.' },
80
+ voice: { label: 'Voice', doc: 'The transcript of what the person said.' },
81
+ slots: { label: 'Slots', doc: 'The values the host fills into the prompt.' },
82
+ context: { label: 'Context', doc: 'What the page or the host tells the model to know.' },
83
+ history: { label: 'History', doc: 'Earlier messages the host replays.' },
84
+ injected: { label: 'Stage messages', doc: 'Messages a host stage adds during the turn.' },
85
+ system: {
86
+ label: 'Turn system text',
87
+ doc: 'Text the host adds to the system instruction for one turn.',
88
+ },
89
+ repair: {
90
+ label: 'Repair',
91
+ doc: 'A stopped reply and the reason, handed back to the model to try again.',
92
+ },
93
+ live_user: { label: 'Live message', doc: 'Text the person sends in a Live session.' },
94
+ ...toolBoundaryMeta(),
95
+ reply: { label: 'Reply', doc: 'The text the model says to the person.' },
96
+ reply_structured: {
97
+ label: 'Structured reply',
98
+ doc: 'The structured output the model returns.',
99
+ },
100
+ live_reply: { label: 'Live reply', doc: 'What the model says in a Live session.' },
101
+ thought: { label: 'Thoughts', doc: "The model's reasoning, where the host shows it." },
102
+ };
103
+ export { BOUNDARIES, BOUNDARY_META, INBOUND_BOUNDARIES, OUTBOUND_BOUNDARIES, recordOf, TOOL_BOUNDARIES, TOOL_KINDS, toolBoundary, };
@@ -1,5 +1,6 @@
1
1
  import type { TurnEvent } from '../kernel/types.js';
2
2
  import { type CanaryStreamGate } from './canary.js';
3
+ /** A canary leak gate for one reply: the turn canary, the system prompt to catch echoes of, and the stream gate that holds text back. */
3
4
  export interface CanaryGateSession {
4
5
  canary: string;
5
6
  /** The system prompt as sent, when replies echoing it are leaks too. */