@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
@@ -3,15 +3,18 @@ import { type TraceClock, type TraceSpan } from '../observability/trace-span.js'
3
3
  import type { ResolvedObservabilityPolicy } from '../observability/types.js';
4
4
  import type { EvalResult, EvalSuite, Trial } from './types.js';
5
5
  import { type CaseVerdict } from './verdict.js';
6
+ /** A grader's result with the identity of the grader that gave it. */
6
7
  interface GradedResult {
7
8
  result: EvalResult;
8
9
  graderIdentity: string;
9
10
  }
11
+ /** What a trial's record is built from. */
10
12
  interface TrialRecordInput {
11
13
  trial: Trial;
12
14
  policy: ResolvedObservabilityPolicy;
13
15
  clock?: TraceClock;
14
16
  }
17
+ /** A trial record being built: its `traceparent` and a `finish` that writes it with the results. */
15
18
  interface OpenTrialRecord {
16
19
  traceparent: string;
17
20
  finish: (results: readonly GradedResult[]) => Promise<{
@@ -19,7 +22,9 @@ interface OpenTrialRecord {
19
22
  span: TraceSpan;
20
23
  }>;
21
24
  }
25
+ /** Opens the record of a trial. */
22
26
  declare function startTrialRecord(input: TrialRecordInput): OpenTrialRecord;
27
+ /** What a run's record is built from: the suite, the verdicts, and the trial spans. */
23
28
  interface RunRecordInput {
24
29
  suite: Pick<EvalSuite, 'id' | 'trials'>;
25
30
  verdicts: readonly CaseVerdict[];
@@ -30,6 +35,7 @@ interface RunRecordInput {
30
35
  stopped?: 'budget';
31
36
  revision?: string;
32
37
  }
38
+ /** Builds the record of a whole run. */
33
39
  declare function buildRunRecord(input: RunRecordInput): Promise<TraceRecord>;
34
40
  export type { GradedResult, OpenTrialRecord, RunRecordInput, TrialRecordInput };
35
41
  export { buildRunRecord, startTrialRecord };
@@ -34,6 +34,7 @@ async function resultAttributes(result, graderIdentity, responseId) {
34
34
  ...optional('theorem.evaluation.passed', result.passed),
35
35
  };
36
36
  }
37
+ /** Opens the record of a trial. */
37
38
  function startTrialRecord(input) {
38
39
  const { trial, policy } = input;
39
40
  const tree = startTrace(TRIAL_SPAN, {
@@ -60,7 +61,7 @@ function startTrialRecord(input) {
60
61
  });
61
62
  const [span] = record.spans;
62
63
  if (!span)
63
- throw new TheoremError('internal', 'trial record has no span'); // lexicon-exempt: invariant
64
+ throw new TheoremError('internal', 'trial record has no span'); // labels-exempt: invariant
64
65
  return { record, span };
65
66
  };
66
67
  return { traceparent: tree.root.traceparent(), finish };
@@ -77,6 +78,7 @@ function verdictAttributes(verdict) {
77
78
  trials_ungraded: verdict.trialsUngraded,
78
79
  };
79
80
  }
81
+ /** Builds the record of a whole run. */
80
82
  function buildRunRecord(input) {
81
83
  const rule = input.suite.trials.pass ?? 'all';
82
84
  const tree = startTrace(RUN_SPAN, {
@@ -98,7 +100,7 @@ function buildRunRecord(input) {
98
100
  for (const verdict of input.verdicts) {
99
101
  tree.root.event(VERDICT_EVENT, verdictAttributes(verdict));
100
102
  }
101
- // A run that reached its end is OK whatever the verdicts say; one stopped early is not finished.
103
+ // why: A run that reached its end is OK whatever the verdicts say; one stopped early is not finished.
102
104
  tree.root.end(input.stopped ? { code: 'UNSET' } : { code: 'OK' });
103
105
  return buildRecord({ spans: tree.collect(), policy: input.policy });
104
106
  }
@@ -4,7 +4,7 @@
4
4
  * Apache License 2.0), keyed in camelCase (`tool_selection` is
5
5
  * `rubrics.toolSelection`), and `rubric()` for a host's own.
6
6
  *
7
- * Each keeps Phoenix's name, labels and prompt. The labels that pass follow
7
+ * Each keeps Phoenix's name, labels, and prompt. The labels that pass follow
8
8
  * Phoenix's direction: the top-scoring labels when higher is better, the
9
9
  * bottom-scoring when lower is (`toxicity` passes `non-toxic`), none when
10
10
  * Phoenix names no direction (`refusal` informs, never decides). A decision
@@ -4,7 +4,7 @@
4
4
  * Apache License 2.0), keyed in camelCase (`tool_selection` is
5
5
  * `rubrics.toolSelection`), and `rubric()` for a host's own.
6
6
  *
7
- * Each keeps Phoenix's name, labels and prompt. The labels that pass follow
7
+ * Each keeps Phoenix's name, labels, and prompt. The labels that pass follow
8
8
  * Phoenix's direction: the top-scoring labels when higher is better, the
9
9
  * bottom-scoring when lower is (`toxicity` passes `non-toxic`), none when
10
10
  * Phoenix names no direction (`refusal` informs, never decides). A decision
@@ -13,7 +13,7 @@
13
13
  import { TheoremError } from '../../guardrails/error.js';
14
14
  const TAG = /\{\{(\{?)([^{}]*)\}?\}\}/g;
15
15
  function templateError(message) {
16
- return new TheoremError('config', `rubric template: ${message}`); // lexicon-exempt: developer contract error
16
+ return new TheoremError('config', `rubric template: ${message}`); // labels-exempt: developer contract error
17
17
  }
18
18
  /** A tag whose line holds nothing else: the whole line goes, newline included. */
19
19
  function standalone(template, start, end) {
@@ -10,7 +10,7 @@
10
10
  import { TheoremError } from '../../guardrails/error.js';
11
11
  import { renderTemplate, templateVariables } from './mustache.js';
12
12
  function configError(rubric, message) {
13
- return new TheoremError('config', `rubric ${rubric}: ${message}`); // lexicon-exempt: developer contract error
13
+ return new TheoremError('config', `rubric ${rubric}: ${message}`); // labels-exempt: developer contract error
14
14
  }
15
15
  /** Render the prompt over the view; a rubric without one, or a variable the view lacks, is a config error. */
16
16
  function fillRubric(rubric, view) {
@@ -1,118 +1,75 @@
1
- /**
2
- * `runSuite`: every case, `repeat` times, graded from the trace. Live mode
3
- * runs the profile now through `runTurn` with the host's provider and grades
4
- * what the memory sink caught; recorded mode grades records a host already
5
- * has. Both build the same trials, so the same graders give the same results.
6
- *
7
- * Every trial's results become a `theorem.eval.trial` span in the judged
8
- * trace; the run becomes one `theorem.eval.run` record. Both go to the sink
9
- * the host names, or nowhere.
10
- *
11
- * @module
12
- */
13
1
  import type { RunDecisionOptions } from '../kernel/engine/decision.js';
14
- import type { ModelProvider } from '../kernel/types.js';
2
+ import type { ProviderHostOptions } from '../kernel/protocols/runtime.js';
15
3
  import type { TraceRecord } from '../observability/trace-record.js';
16
4
  import type { TraceSink } from '../observability/trace-sink.js';
17
5
  import type { TraceClock } from '../observability/trace-span.js';
18
6
  import type { LoadedSuite } from './suite.js';
19
7
  import type { EvalCase, EvalMediaResolver, EvalPassRule, EvalResult } from './types.js';
20
8
  import { type CaseVerdict, type TrialOutcome } from './verdict.js';
21
- /** How the eval stamps a live turn so recorded mode can match its record to the case. */
9
+ /** Names a trial by suite, case, and trial number. */
22
10
  interface EvalStamp {
23
11
  suite: string;
24
12
  case: string;
25
13
  trial: number;
26
14
  }
27
- /** A turn's whole length, root span start to end, its loop (model calls and tool calls), and why it stopped. */
15
+ /** The size of a turn: its duration and the model and tool calls it made. */
28
16
  interface TurnShape {
29
17
  durationMs: number;
30
18
  modelCalls: number;
31
19
  toolCalls: number;
32
- /** `theorem.stop.kind` on the root; absent when the turn recorded none. */
33
20
  stop?: string;
34
21
  }
35
- /** One trial as the run reports it, before and after it is written. */
22
+ /** One trial's outcome, results, and records. */
36
23
  interface TrialReport {
37
24
  case?: EvalCase;
38
25
  index: number;
39
26
  outcome: TrialOutcome;
40
27
  results: EvalResult[];
41
- /** The judged trace, when the turn produced one. */
42
28
  traceId?: string;
43
29
  records: TraceRecord[];
44
- /** How long the turn took and how many times it looped, when it produced a trace. */
45
30
  turn?: TurnShape;
46
- /** The kind of the error that stopped the turn before it had a trace, if any. */
47
31
  error?: string;
48
- /** The turn's cost from its root, when it recorded one. */
49
32
  costUsd?: number;
50
- /** The judge calls' summed cost, when a model grader ran and any judge recorded one. */
51
33
  judgeCostUsd?: number;
52
- /** The turn and judge calls whose cost is unknown: none reported, or only part (`theorem.usage.cost_partial`). */
53
34
  unpriced: number;
54
- /** The turn and judge calls that reported a cost, whole or part; a reported zero counts. */
55
35
  priced: number;
56
- /** Every judge call's records, one trace per judge call. */
57
36
  judgeRecords: TraceRecord[];
58
- /** The written `theorem.eval.trial` record, when there was a trace to hold it. */
59
37
  trialRecord?: TraceRecord;
60
38
  }
39
+ /** Options for `runSuite`: the providers, the judge, and how often to repeat. */
61
40
  interface RunSuiteOptions {
62
- /** Live mode: the host's provider for the profile under test. */
63
- provider?: ModelProvider;
64
- /** The provider for text judge profiles; default the suite's `judgeProvider` export, else `provider`. */
65
- judgeProvider?: ModelProvider;
66
- /** The key for decision judge profiles (Jev); default the suite's `judgeDecision` export. */
41
+ provider?: ProviderHostOptions;
42
+ judgeProvider?: ProviderHostOptions;
67
43
  judgeDecision?: Omit<RunDecisionOptions, 'sink'>;
68
- /** Where a judge finds media the trace names only by hash; default the suite's `media` export. */
69
44
  media?: EvalMediaResolver;
70
- /** Recorded mode: the records to grade; live mode when absent. */
71
45
  recorded?: TraceRecord[];
72
- /** Where trial and run records go. Absent: they are returned only. */
73
46
  sink?: TraceSink;
74
- /**
75
- * Stop starting trials once the summed cost (agent and judge) crosses this;
76
- * the run record says `stopped: budget`. Calls with no reported cost add
77
- * nothing, so the run warns when any ran.
78
- */
79
47
  maxCostUsd?: number;
80
- /** `repeat` override from the command line. */
81
48
  repeat?: number;
82
- /** Live mode: trials in flight at once (default 1). Order of start and report is the suite's either way. */
83
49
  concurrency?: number;
84
- /** `vcs.ref.head.revision` on the run record. */
85
50
  revision?: string;
86
51
  clock?: TraceClock;
87
- /** Called after each trial is graded, for progress output. */
88
52
  onTrial?: (report: TrialReport) => void;
89
53
  signal?: AbortSignal;
90
54
  }
91
- /** What a run produced. */
55
+ /** A finished suite run: its mode and its cases' trials and verdicts. */
92
56
  interface SuiteRun {
93
57
  suite: string;
94
58
  mode: 'live' | 'recorded';
95
59
  repeat: number;
96
- /** What a case's trials must do for it to pass. */
97
60
  passRule: EvalPassRule;
98
61
  verdicts: CaseVerdict[];
99
62
  trials: TrialReport[];
100
- /** Recorded mode: trials whose records carried no matching case. */
101
63
  caseless: TrialReport[];
102
- /** Some case was decided, every decided case passed, and nothing stopped the run. */
103
64
  passed: boolean;
104
65
  stopped?: 'budget';
105
- /** The summed cost of agent turns and judge calls, over every one that recorded a cost. */
106
66
  costUsd: number;
107
- /** Agent turns and judge calls whose cost went unreported, in whole or part, so `costUsd` leaves it out. */
108
67
  unpriced: number;
109
- /** Agent turns and judge calls that reported a cost, so `costUsd` is theirs even when it is zero. */
110
68
  priced: number;
111
- /** Plain-language warnings for the host to print. */
112
69
  warnings: string[];
113
70
  run: TraceRecord;
114
71
  }
115
- /** Run a loaded suite live or over records, write its trial and run records, and report every verdict. */
72
+ /** Runs every case of a suite and returns the graded run. */
116
73
  declare function runSuite(loaded: LoadedSuite, options?: RunSuiteOptions): Promise<SuiteRun>;
117
74
  export type { EvalStamp, RunSuiteOptions, SuiteRun, TrialReport, TurnShape };
118
75
  export { runSuite };
@@ -1,15 +1,3 @@
1
- /**
2
- * `runSuite`: every case, `repeat` times, graded from the trace. Live mode
3
- * runs the profile now through `runTurn` with the host's provider and grades
4
- * what the memory sink caught; recorded mode grades records a host already
5
- * has. Both build the same trials, so the same graders give the same results.
6
- *
7
- * Every trial's results become a `theorem.eval.trial` span in the judged
8
- * trace; the run becomes one `theorem.eval.run` record. Both go to the sink
9
- * the host names, or nowhere.
10
- *
11
- * @module
12
- */
13
1
  import { errorKind, TheoremError } from '../guardrails/error.js';
14
2
  import { getProfile, runTurn } from '../kernel/default-scope.js';
15
3
  import { isModelProfile } from '../kernel/registry/resolve.js';
@@ -36,12 +24,7 @@ function stampOf(record) {
36
24
  }
37
25
  return { suite, case: caseId, trial };
38
26
  }
39
- /**
40
- * Grade one trial with every grader that applies, all at once; a grader that
41
- * throws yields `grader_error`. Judge records reach `context.traced` in grader
42
- * order once every grader is done, so a run writes the same records in the
43
- * same order whichever judge answered first.
44
- */
27
+ /** Judge records reach `context.traced` in grader order once every grader is done, so a run writes the same records in the same order whichever judge answered first. */
45
28
  async function gradeTrial(graders, trial, context) {
46
29
  const applicable = trial.case ? graders : graders.filter((grader) => !grader.needsExpect);
47
30
  const graded = await Promise.all(applicable.map(async (grader) => {
@@ -72,7 +55,6 @@ async function gradeTrial(graders, trial, context) {
72
55
  await context.traced(records);
73
56
  return graded.map(({ result, graderIdentity }) => ({ result, graderIdentity }));
74
57
  }
75
- /** Every applicable grader's result as the error that kept the turn from producing a trace. */
76
58
  function erroredResults(graders, evalCase, error) {
77
59
  const applicable = evalCase ? graders : graders.filter((grader) => !grader.needsExpect);
78
60
  return applicable.map((grader) => ({
@@ -86,7 +68,6 @@ function recordRoot(record) {
86
68
  const ids = new Set(record.spans.map((span) => span.spanId));
87
69
  return record.spans.find((span) => span.parentSpanId === undefined || !ids.has(span.parentSpanId));
88
70
  }
89
- /** A record's root cost, and whether it is whole: absent or partial, some calls went unpriced. */
90
71
  function recordCost(record) {
91
72
  const attributes = recordRoot(record)?.attributes;
92
73
  const cost = attributes?.['theorem.usage.cost_usd'];
@@ -94,12 +75,10 @@ function recordCost(record) {
94
75
  return { whole: false };
95
76
  return { usd: cost, whole: attributes?.['theorem.usage.cost_partial'] !== true };
96
77
  }
97
- /** The profile a record ran on (`gen_ai.agent.name` on its root). */
98
78
  function recordAgent(record) {
99
79
  const agent = recordRoot(record)?.attributes['gen_ai.agent.name'];
100
80
  return typeof agent === 'string' ? agent : undefined;
101
81
  }
102
- /** Build, grade and write one trial from the records of one trace. */
103
82
  async function gradeRecords(grading, evalCase, index, records) {
104
83
  const trial = buildTrial({ suite: grading.suite.suite.id, case: evalCase, index, records });
105
84
  const trialRecord = startTrialRecord({
@@ -186,9 +165,10 @@ async function turnRequest(suite, evalCase, index) {
186
165
  : {}),
187
166
  },
188
167
  metadata: { eval: stamp },
168
+ ...(suite.onStage ? { onStage: suite.onStage } : {}),
169
+ ...(suite.host === undefined ? {} : { host: suite.host }),
189
170
  };
190
171
  }
191
- /** Run one turn live; its records are what the memory sink caught. */
192
172
  async function runLiveTrial(grading, provider, evalCase, index, signal) {
193
173
  const records = [];
194
174
  let thrown;
@@ -198,14 +178,13 @@ async function runLiveTrial(grading, provider, evalCase, index, signal) {
198
178
  ...(signal ? { signal } : {}),
199
179
  };
200
180
  for await (const _event of runTurn(request, provider, memorySink(records))) {
201
- // The trace is the record of the turn; events are not graded.
181
+ // why: The trace is the record of the turn; events are not graded.
202
182
  }
203
183
  }
204
184
  catch (error) {
205
185
  thrown = error;
206
186
  }
207
187
  if (records.length > 0) {
208
- // The turn's own records go to the host's sink too: a label points at a transcript someone can read.
209
188
  if (grading.sink) {
210
189
  for (const record of records) {
211
190
  await writeTrace(grading.sink, Promise.resolve(record), grading.policy);
@@ -227,12 +206,6 @@ async function runLiveTrial(grading, provider, evalCase, index, signal) {
227
206
  error,
228
207
  };
229
208
  }
230
- /**
231
- * What the suite's model graders judge with. Each grader names its judge
232
- * profile (its own, else the suite's); a text judge needs a provider (the
233
- * option, else the suite's `judgeProvider` export, else the agent's), a
234
- * decision judge a key (the option, else the suite's `judgeDecision` export).
235
- */
236
209
  function judgingOf(loaded, options) {
237
210
  const { suite } = loaded;
238
211
  const provider = options.judgeProvider ?? loaded.judgeProvider ?? options.provider;
@@ -263,19 +236,19 @@ function checkSuite(loaded, options) {
263
236
  const { suite } = loaded;
264
237
  const profile = getProfile(suite.profile);
265
238
  if (!isModelProfile(profile)) {
266
- throw new TheoremError('config', `suite ${suite.id}: profile ${suite.profile} runs no model turn`); // lexicon-exempt: developer contract error
239
+ throw new TheoremError('config', `suite ${suite.id}: profile ${suite.profile} runs no model turn`); // labels-exempt: developer contract error
267
240
  }
268
241
  if (suite.mode === 'session') {
269
- throw new TheoremError('config', `suite ${suite.id}: session suites are not run yet`); // lexicon-exempt: developer contract error
242
+ throw new TheoremError('config', `suite ${suite.id}: session suites are not run yet`); // labels-exempt: developer contract error
270
243
  }
271
244
  if (profile.type === 'live') {
272
- throw new TheoremError('config', `suite ${suite.id}: a live profile needs mode 'session'`); // lexicon-exempt: developer contract error
245
+ throw new TheoremError('config', `suite ${suite.id}: a live profile needs mode 'session'`); // labels-exempt: developer contract error
273
246
  }
274
247
  if (!options.recorded && !options.provider) {
275
- throw new TheoremError('config', `suite ${suite.id}: live mode needs a provider`); // lexicon-exempt: developer contract error
248
+ throw new TheoremError('config', `suite ${suite.id}: live mode needs a provider`); // labels-exempt: developer contract error
276
249
  }
277
250
  if (suite.graders.length === 0) {
278
- throw new TheoremError('config', `suite ${suite.id}: no graders`); // lexicon-exempt: developer contract error
251
+ throw new TheoremError('config', `suite ${suite.id}: no graders`); // labels-exempt: developer contract error
279
252
  }
280
253
  const warnings = [];
281
254
  const repeat = options.repeat ?? suite.trials.repeat;
@@ -284,7 +257,6 @@ function checkSuite(loaded, options) {
284
257
  }
285
258
  return warnings;
286
259
  }
287
- /** A trial's whole cost: the agent's turn and its judge turns. */
288
260
  function reportCost(report) {
289
261
  return (report.costUsd ?? 0) + (report.judgeCostUsd ?? 0);
290
262
  }
@@ -294,14 +266,12 @@ function summedCost(reports) {
294
266
  function summedCalls(reports, key) {
295
267
  return reports.reduce((sum, report) => sum + report[key], 0);
296
268
  }
297
- /** Recorded mode: each trace's records become one trial, matched to a case by its eval stamp. */
298
269
  async function gradeRecorded(grading, records) {
299
270
  const byCase = new Map();
300
271
  const caseless = [];
301
272
  const cases = new Map(grading.suite.cases.map((evalCase) => [evalCase.id, evalCase]));
302
273
  const skipped = { judge: 0, other: 0 };
303
274
  for (const [, group] of groupByTrace(records)) {
304
- // A directory of eval traces holds judge calls (under their trial) and run records beside the turns; only turns are trials.
305
275
  const traceRecords = group.filter((record) => !isJudgeStamp(record));
306
276
  skipped.judge += group.length - traceRecords.length;
307
277
  if (traceRecords.length === 0)
@@ -332,11 +302,7 @@ async function gradeRecorded(grading, records) {
332
302
  skipped,
333
303
  };
334
304
  }
335
- /**
336
- * Live mode: every case, `repeat` times, started in suite order with up to
337
- * `concurrency` in flight, until the cost ceiling. The ceiling is checked
338
- * before each start, so a stop lets what is in flight finish and count.
339
- */
305
+ /** The cost ceiling is checked before each start, so a stop lets what is in flight finish and count. */
340
306
  async function runLive(grading, provider, repeat, options) {
341
307
  const jobs = grading.suite.cases.flatMap((evalCase) => Array.from({ length: repeat }, (_, index) => ({ evalCase, index })));
342
308
  const reports = new Map(grading.suite.cases.map((evalCase) => [evalCase.id, []]));
@@ -382,11 +348,11 @@ async function ranOf(grading, repeat, options) {
382
348
  return ran;
383
349
  }
384
350
  if (!options.provider) {
385
- throw new TheoremError('config', `suite ${grading.suite.suite.id}: live mode needs a provider`); // lexicon-exempt: developer contract error
351
+ throw new TheoremError('config', `suite ${grading.suite.suite.id}: live mode needs a provider`); // labels-exempt: developer contract error
386
352
  }
387
353
  return runLive(grading, options.provider, repeat, options);
388
354
  }
389
- /** Run a loaded suite live or over records, write its trial and run records, and report every verdict. */
355
+ /** Runs every case of a suite and returns the graded run. */
390
356
  async function runSuite(loaded, options = {}) {
391
357
  const warnings = checkSuite(loaded, options);
392
358
  const { suite } = loaded;
@@ -1,19 +1,28 @@
1
1
  import type { z } from 'zod';
2
2
  import type { RunDecisionOptions } from '../kernel/engine/decision.js';
3
- import type { ModelProvider } from '../kernel/types.js';
3
+ import type { ProviderHostOptions } from '../kernel/protocols/runtime.js';
4
+ import type { StageHandler } from '../kernel/stages.js';
4
5
  import { type TraceRecord } from '../observability/trace-schema.js';
5
6
  import { type EvalCase, type EvalMediaResolver, type EvalSuite } from './types.js';
7
+ /** A suite with its cases read, the providers, media resolver, and stage handler its module exports, and the module's path. */
6
8
  interface LoadedSuite {
7
9
  suite: EvalSuite;
8
10
  cases: EvalCase[];
9
- provider?: ModelProvider;
10
- judgeProvider?: ModelProvider;
11
+ provider?: ProviderHostOptions;
12
+ judgeProvider?: ProviderHostOptions;
11
13
  judgeDecision?: Omit<RunDecisionOptions, 'sink'>;
12
14
  media?: EvalMediaResolver;
15
+ /** The stage handler every live trial's turn runs with, as the host's own requests do. */
16
+ onStage?: StageHandler;
17
+ /** The application context every live trial's turn carries as `TurnRequest.host`; its tools read it as `ctx.host`. */
18
+ host?: unknown;
13
19
  path: string;
14
20
  }
21
+ /** Reads a JSON Lines file, parsing each line against the schema; throws with the file and line number on a line that is not JSON or does not match. */
15
22
  declare function readJsonl<T>(path: string, schema: z.ZodType<T>, what: string): Promise<T[]>;
23
+ /** Reads trace records from a `.jsonl` file, or from every `.jsonl` file in a directory, in name order. */
16
24
  declare function readTraceRecords(path: string): Promise<TraceRecord[]>;
25
+ /** Imports a suite module, checks its default export against `EvalSuite` and reads its cases; throws when a case id repeats. */
17
26
  declare function loadSuite(modulePath: string): Promise<LoadedSuite>;
18
27
  export type { LoadedSuite };
19
28
  export { loadSuite, readJsonl, readTraceRecords };
@@ -6,7 +6,7 @@ import { traceRecordSchema } from '../observability/trace-schema.js';
6
6
  import { pinCaseFiles } from './attachments.js';
7
7
  import { evalCaseSchema, evalSuiteSchema, } from './types.js';
8
8
  function isProvider(value) {
9
- return isRecord(value) && typeof value.complete === 'function';
9
+ return isRecord(value) && !('complete' in value);
10
10
  }
11
11
  function isDecisionKey(value) {
12
12
  return isRecord(value) && isRecord(value.vault);
@@ -18,6 +18,7 @@ function siblingOf(modulePath, relative) {
18
18
  const dir = modulePath.slice(0, modulePath.lastIndexOf('/'));
19
19
  return relative.startsWith('/') ? relative : `${dir}/${relative}`;
20
20
  }
21
+ /** Reads a JSON Lines file, parsing each line against the schema; throws with the file and line number on a line that is not JSON or does not match. */
21
22
  async function readJsonl(path, schema, what) {
22
23
  const text = await readFile(path, 'utf8');
23
24
  const out = [];
@@ -30,7 +31,7 @@ async function readJsonl(path, schema, what) {
30
31
  parsed = JSON.parse(line);
31
32
  }
32
33
  catch {
33
- throw new TheoremError('config', `${path}:${index + 1}: ${what} is not JSON`); // lexicon-exempt: developer contract error
34
+ throw new TheoremError('config', `${path}:${index + 1}: ${what} is not JSON`); // labels-exempt: developer contract error
34
35
  }
35
36
  const result = schema.safeParse(parsed);
36
37
  if (!result.success) {
@@ -42,6 +43,7 @@ async function readJsonl(path, schema, what) {
42
43
  }
43
44
  return out;
44
45
  }
46
+ /** Reads trace records from a `.jsonl` file, or from every `.jsonl` file in a directory, in name order. */
45
47
  async function readTraceRecords(path) {
46
48
  const target = absolute(path);
47
49
  const info = await stat(target);
@@ -58,11 +60,12 @@ async function readTraceRecords(path) {
58
60
  records.push(...(await readJsonl(file, traceRecordSchema, 'trace record')));
59
61
  return records;
60
62
  }
63
+ /** Imports a suite module, checks its default export against `EvalSuite` and reads its cases; throws when a case id repeats. */
61
64
  async function loadSuite(modulePath) {
62
65
  const path = absolute(modulePath);
63
66
  const module = await import(new URL(`file://${path}`).href);
64
67
  if (!isRecord(module)) {
65
- throw new TheoremError('config', `${modulePath}: not a module`); // lexicon-exempt: developer contract error
68
+ throw new TheoremError('config', `${modulePath}: not a module`); // labels-exempt: developer contract error
66
69
  }
67
70
  const parsed = evalSuiteSchema.safeParse(module.default);
68
71
  if (!parsed.success) {
@@ -75,7 +78,7 @@ async function loadSuite(modulePath) {
75
78
  const ids = new Set();
76
79
  for (const evalCase of cases) {
77
80
  if (ids.has(evalCase.id)) {
78
- throw new TheoremError('config', `${suite.cases}: case id ${evalCase.id} appears twice`); // lexicon-exempt: developer contract error
81
+ throw new TheoremError('config', `${suite.cases}: case id ${evalCase.id} appears twice`); // labels-exempt: developer contract error
79
82
  }
80
83
  ids.add(evalCase.id);
81
84
  }
@@ -87,6 +90,8 @@ async function loadSuite(modulePath) {
87
90
  ...(isProvider(module.judgeProvider) ? { judgeProvider: module.judgeProvider } : {}),
88
91
  ...(isDecisionKey(module.judgeDecision) ? { judgeDecision: module.judgeDecision } : {}),
89
92
  ...(typeof module.media === 'function' ? { media: module.media } : {}),
93
+ ...(typeof module.onStage === 'function' ? { onStage: module.onStage } : {}),
94
+ ...(module.host === undefined ? {} : { host: module.host }),
90
95
  };
91
96
  }
92
97
  export { loadSuite, readJsonl, readTraceRecords };
@@ -2,6 +2,7 @@ import { type GroupSummary } from './breakdown.js';
2
2
  import type { SuiteRun, TurnShape } from './run.js';
3
3
  import type { EvalPassRule, EvalResult } from './types.js';
4
4
  import type { CaseVerdict, TrialOutcome } from './verdict.js';
5
+ /** One trial in a run summary: its case, index, outcome, trace id, turn shape, error, and grader results. */
5
6
  interface TrialSummary {
6
7
  case?: string;
7
8
  index: number;
@@ -11,6 +12,7 @@ interface TrialSummary {
11
12
  error?: string;
12
13
  results: EvalResult[];
13
14
  }
15
+ /** A suite run reduced to what a report shows: the pass rule and verdict, cost, priced and unpriced counts, per-case verdicts, group summaries, and trials. */
14
16
  interface RunSummary {
15
17
  suite: string;
16
18
  mode: 'live' | 'recorded';
@@ -27,6 +29,7 @@ interface RunSummary {
27
29
  runTraceId?: string;
28
30
  warnings: string[];
29
31
  }
32
+ /** Reduces a suite run to a `RunSummary`. */
30
33
  declare function summarizeRun(run: SuiteRun): RunSummary;
31
34
  export type { RunSummary, TrialSummary };
32
35
  export { summarizeRun };
@@ -1,4 +1,5 @@
1
1
  import { groupSummaries } from './breakdown.js';
2
+ /** Reduces a suite run to a `RunSummary`. */
2
3
  function summarizeRun(run) {
3
4
  const trials = [...run.trials, ...run.caseless].map((report) => ({
4
5
  ...(report.case ? { case: report.case.id } : {}),
@@ -1,27 +1,14 @@
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 { type TraceRecord } from '../observability/trace-record.js';
15
2
  import type { EvalCase, Trial } from './types.js';
16
- /** Build the trial every grader receives from the records that share one trace. */
3
+ /** 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. */
17
4
  declare function buildTrial(args: {
18
5
  suite: string;
19
6
  case?: EvalCase;
20
7
  index: number;
21
8
  records: TraceRecord[];
22
9
  }): Trial;
23
- /** Group records by trace id, in first-seen order. */
10
+ /** Groups trace records by the trace id of their first span; records with no spans are dropped. */
24
11
  declare function groupByTrace(records: TraceRecord[]): Map<string, TraceRecord[]>;
25
- /** Whether these records hold a turn at all: an `invoke_agent` span. An eval run record does not. */
12
+ /** True when any record holds an `invoke_agent` span, meaning an agent turn ran. */
26
13
  declare function hasTurn(records: readonly TraceRecord[]): boolean;
27
14
  export { buildTrial, groupByTrace, hasTurn };