niceeval 0.15.1-canary.76 → 0.16.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 (714) hide show
  1. package/INDEX.md +45 -40
  2. package/dist/adapter-execution-trace.cjs.map +1 -1
  3. package/dist/adapter-execution-trace.d.cts +26 -0
  4. package/dist/adapter-execution-trace.d.mts +26 -0
  5. package/dist/adapter-execution-trace.d.ts +26 -0
  6. package/dist/adapter-usage.cjs.map +1 -1
  7. package/dist/adapter-usage.d.cts +9 -0
  8. package/dist/adapter-usage.d.mts +9 -0
  9. package/dist/adapter-usage.d.ts +9 -0
  10. package/dist/adapter.cjs +19 -4
  11. package/dist/adapter.cjs.map +1 -1
  12. package/dist/adapter.d.cts +37 -12
  13. package/dist/adapter.d.mts +37 -12
  14. package/dist/adapter.d.ts +37 -12
  15. package/dist/agents/ai-sdk.cjs +3 -0
  16. package/dist/agents/ai-sdk.cjs.map +1 -1
  17. package/dist/agents/bub.cjs +3 -0
  18. package/dist/agents/bub.cjs.map +1 -1
  19. package/dist/agents/claude-code-native.cjs +28 -2
  20. package/dist/agents/claude-code-native.cjs.map +1 -1
  21. package/dist/agents/claude-code.cjs +3 -0
  22. package/dist/agents/claude-code.cjs.map +1 -1
  23. package/dist/agents/codex.cjs +3 -0
  24. package/dist/agents/codex.cjs.map +1 -1
  25. package/dist/agents/coding-cli-versions.cjs +9 -10
  26. package/dist/agents/coding-cli-versions.cjs.map +1 -1
  27. package/dist/agents/coding-cli-versions.d.cts +1 -1
  28. package/dist/agents/coding-cli-versions.d.mts +1 -1
  29. package/dist/agents/coding-cli-versions.d.ts +1 -1
  30. package/dist/agents/deepseek-harness.cjs +3 -0
  31. package/dist/agents/deepseek-harness.cjs.map +1 -1
  32. package/dist/agents/hermes.cjs +3 -0
  33. package/dist/agents/hermes.cjs.map +1 -1
  34. package/dist/agents/index.cjs.map +1 -1
  35. package/dist/agents/index.d.cts +3 -2
  36. package/dist/agents/index.d.mts +3 -2
  37. package/dist/agents/index.d.ts +3 -2
  38. package/dist/agents/omp.cjs +3 -0
  39. package/dist/agents/omp.cjs.map +1 -1
  40. package/dist/agents/openai-compat.cjs +6 -0
  41. package/dist/agents/openai-compat.cjs.map +1 -1
  42. package/dist/agents/openclaw.cjs +3 -0
  43. package/dist/agents/openclaw.cjs.map +1 -1
  44. package/dist/agents/opencode.cjs +3 -0
  45. package/dist/agents/opencode.cjs.map +1 -1
  46. package/dist/agents/sdk-streams.cjs +9 -0
  47. package/dist/agents/sdk-streams.cjs.map +1 -1
  48. package/dist/agents/ui-message-stream.cjs +3 -0
  49. package/dist/agents/ui-message-stream.cjs.map +1 -1
  50. package/dist/assertions/api.cjs.map +1 -1
  51. package/dist/assertions/api.d.cts +27 -5
  52. package/dist/assertions/api.d.mts +27 -5
  53. package/dist/assertions/api.d.ts +27 -5
  54. package/dist/assertions/collection.cjs +6 -0
  55. package/dist/assertions/collection.cjs.map +1 -1
  56. package/dist/assertions/collection.d.cts +4 -2
  57. package/dist/assertions/collection.d.mts +4 -2
  58. package/dist/assertions/collection.d.ts +4 -2
  59. package/dist/assertions/collection.js +12 -8
  60. package/dist/assertions/context-match.cjs +70 -0
  61. package/dist/assertions/context-match.cjs.map +1 -0
  62. package/dist/assertions/context-match.d.cts +107 -0
  63. package/dist/assertions/context-match.d.mts +107 -0
  64. package/dist/assertions/context-match.d.ts +107 -0
  65. package/dist/assertions/context-match.js +12 -0
  66. package/dist/assertions/context-match.js.map +1 -0
  67. package/dist/assertions/full-content.cjs +109 -0
  68. package/dist/assertions/full-content.cjs.map +1 -0
  69. package/dist/assertions/full-content.d.cts +6 -0
  70. package/dist/assertions/full-content.d.mts +6 -0
  71. package/dist/assertions/full-content.d.ts +6 -0
  72. package/dist/assertions/full-content.js +12 -0
  73. package/dist/assertions/full-content.js.map +1 -0
  74. package/dist/assertions/judge-presets.cjs +2 -34
  75. package/dist/assertions/judge-presets.cjs.map +1 -1
  76. package/dist/assertions/judge-presets.d.cts +6 -9
  77. package/dist/assertions/judge-presets.d.mts +6 -9
  78. package/dist/assertions/judge-presets.d.ts +6 -9
  79. package/dist/assertions/judge-presets.js +8 -8
  80. package/dist/assertions/judge.cjs +107 -29
  81. package/dist/assertions/judge.cjs.map +1 -1
  82. package/dist/assertions/judge.d.cts +2 -0
  83. package/dist/assertions/judge.d.mts +2 -0
  84. package/dist/assertions/judge.d.ts +2 -0
  85. package/dist/assertions/match.cjs +244 -5
  86. package/dist/assertions/match.cjs.map +1 -1
  87. package/dist/assertions/match.d.cts +43 -3
  88. package/dist/assertions/match.d.mts +43 -3
  89. package/dist/assertions/match.d.ts +43 -3
  90. package/dist/assertions/match.js +88 -78
  91. package/dist/assertions/material.cjs +520 -0
  92. package/dist/assertions/material.cjs.map +1 -0
  93. package/dist/assertions/material.d.cts +56 -0
  94. package/dist/assertions/material.d.mts +56 -0
  95. package/dist/assertions/material.d.ts +56 -0
  96. package/dist/assertions/material.js +20 -0
  97. package/dist/assertions/material.js.map +1 -0
  98. package/dist/assertions/record/attachment.cjs +5 -2
  99. package/dist/assertions/record/attachment.cjs.map +1 -1
  100. package/dist/assertions/record/codec.cjs +2 -1
  101. package/dist/assertions/record/codec.cjs.map +1 -1
  102. package/dist/assertions/record/model.cjs.map +1 -1
  103. package/dist/assertions/record/model.d.cts +6 -1
  104. package/dist/assertions/record/model.d.mts +6 -1
  105. package/dist/assertions/record/model.d.ts +6 -1
  106. package/dist/assertions/runtime.cjs +207 -14
  107. package/dist/assertions/runtime.cjs.map +1 -1
  108. package/dist/assertions/runtime.d.cts +9 -0
  109. package/dist/assertions/runtime.d.mts +9 -0
  110. package/dist/assertions/runtime.d.ts +9 -0
  111. package/dist/assertions/runtime.js +14 -8
  112. package/dist/assertions/score-match-audit.cjs +18 -8
  113. package/dist/assertions/score-match-audit.cjs.map +1 -1
  114. package/dist/assertions/score-match-gateway.cjs +83 -25
  115. package/dist/assertions/score-match-gateway.cjs.map +1 -1
  116. package/dist/assertions/score-match-gateway.d.cts +2 -0
  117. package/dist/assertions/score-match-gateway.d.mts +2 -0
  118. package/dist/assertions/score-match-gateway.d.ts +2 -0
  119. package/dist/assertions/value-composition.test-d.cjs +77 -0
  120. package/dist/assertions/value-composition.test-d.cjs.map +1 -0
  121. package/dist/assertions/value-composition.test-d.d.cts +1 -0
  122. package/dist/assertions/value-composition.test-d.d.mts +1 -0
  123. package/dist/assertions/value-composition.test-d.d.ts +1 -0
  124. package/dist/assertions/value-composition.test-d.js +4 -0
  125. package/dist/assertions/value-composition.test-d.js.map +1 -0
  126. package/dist/context/assert-first.cjs +207 -213
  127. package/dist/context/assert-first.cjs.map +1 -1
  128. package/dist/context/assert-first.d.cts +49 -23
  129. package/dist/context/assert-first.d.mts +49 -23
  130. package/dist/context/assert-first.d.ts +49 -23
  131. package/dist/context/session.cjs +111 -9
  132. package/dist/context/session.cjs.map +1 -1
  133. package/dist/context/session.d.cts +18 -0
  134. package/dist/context/session.d.mts +18 -0
  135. package/dist/context/session.d.ts +18 -0
  136. package/dist/define.cjs +17 -1
  137. package/dist/define.cjs.map +1 -1
  138. package/dist/eval/cli/contribution.cjs +2 -0
  139. package/dist/eval/cli/contribution.cjs.map +1 -1
  140. package/dist/eval/host/index.cjs +2 -0
  141. package/dist/eval/host/index.cjs.map +1 -1
  142. package/dist/eval/record/evaluation.cjs +3 -0
  143. package/dist/eval/record/evaluation.cjs.map +1 -1
  144. package/dist/eval/record/membership-provenance.d.cts +15 -15
  145. package/dist/eval/record/membership-provenance.d.mts +15 -15
  146. package/dist/eval/record/membership-provenance.d.ts +15 -15
  147. package/dist/eval/record/score.cjs +7 -0
  148. package/dist/eval/record/score.cjs.map +1 -1
  149. package/dist/eval/record/sealed-assertion.cjs +3 -0
  150. package/dist/eval/record/sealed-assertion.cjs.map +1 -1
  151. package/dist/eval/record/verdict.cjs +7 -0
  152. package/dist/eval/record/verdict.cjs.map +1 -1
  153. package/dist/expect/index.cjs +8 -2
  154. package/dist/expect/index.cjs.map +1 -1
  155. package/dist/expect/index.d.cts +9 -4
  156. package/dist/expect/index.d.mts +9 -4
  157. package/dist/expect/index.d.ts +9 -4
  158. package/dist/expect/index.js +72 -62
  159. package/dist/expect/index.mjs +72 -62
  160. package/dist/experiment/host/cli/contribution.cjs +37 -23
  161. package/dist/experiment/host/cli/contribution.cjs.map +1 -1
  162. package/dist/experiment/host/cli/contribution.d.cts +9 -1
  163. package/dist/experiment/host/cli/contribution.d.mts +9 -1
  164. package/dist/experiment/host/cli/contribution.d.ts +9 -1
  165. package/dist/experiment/host/current.cjs +74 -0
  166. package/dist/experiment/host/current.cjs.map +1 -0
  167. package/dist/experiment/host/current.d.cts +33 -0
  168. package/dist/experiment/host/current.d.mts +33 -0
  169. package/dist/experiment/host/current.d.ts +33 -0
  170. package/dist/experiment/host/current.js +10 -0
  171. package/dist/experiment/host/current.js.map +1 -0
  172. package/dist/experiment/host/index.cjs +17 -174
  173. package/dist/experiment/host/index.cjs.map +1 -1
  174. package/dist/experiment/host/index.d.cts +8 -54
  175. package/dist/experiment/host/index.d.mts +8 -54
  176. package/dist/experiment/host/index.d.ts +8 -54
  177. package/dist/experiment/host/operations.cjs +33 -10
  178. package/dist/experiment/host/operations.cjs.map +1 -1
  179. package/dist/experiment/host/operations.d.cts +29 -1
  180. package/dist/experiment/host/operations.d.mts +29 -1
  181. package/dist/experiment/host/operations.d.ts +29 -1
  182. package/dist/experiment/host/operations.js +6 -4
  183. package/dist/experiment/host/requirements.cjs +3 -0
  184. package/dist/experiment/host/requirements.cjs.map +1 -0
  185. package/dist/experiment/host/requirements.d.cts +3 -0
  186. package/dist/experiment/host/requirements.d.mts +3 -0
  187. package/dist/experiment/host/requirements.d.ts +3 -0
  188. package/dist/experiment/host/requirements.js +4 -0
  189. package/dist/experiment/host/requirements.js.map +1 -0
  190. package/dist/experiment/host/runtime.cjs +179 -0
  191. package/dist/experiment/host/runtime.cjs.map +1 -0
  192. package/dist/experiment/host/runtime.d.cts +79 -0
  193. package/dist/experiment/host/runtime.d.mts +79 -0
  194. package/dist/experiment/host/runtime.d.ts +79 -0
  195. package/dist/experiment/host/runtime.js +6 -0
  196. package/dist/experiment/host/runtime.js.map +1 -0
  197. package/dist/experiment/host/types.cjs.map +1 -1
  198. package/dist/experiment/host/types.d.cts +17 -16
  199. package/dist/experiment/host/types.d.mts +17 -16
  200. package/dist/experiment/host/types.d.ts +17 -16
  201. package/dist/fresh-import.cjs +2 -1
  202. package/dist/fresh-import.cjs.map +1 -1
  203. package/dist/index.cjs +4 -2
  204. package/dist/index.cjs.map +1 -1
  205. package/dist/index.d.cts +12 -6
  206. package/dist/index.d.mts +12 -6
  207. package/dist/index.d.ts +12 -6
  208. package/dist/index.js +32 -30
  209. package/dist/index.mjs +32 -30
  210. package/dist/inspection/artifacts.cjs +83 -54
  211. package/dist/inspection/artifacts.cjs.map +1 -1
  212. package/dist/inspection/artifacts.d.cts +8 -0
  213. package/dist/inspection/artifacts.d.mts +8 -0
  214. package/dist/inspection/artifacts.d.ts +8 -0
  215. package/dist/inspection/artifacts.js +2 -0
  216. package/dist/inspection/assertions.cjs +4 -1
  217. package/dist/inspection/assertions.cjs.map +1 -1
  218. package/dist/inspection/cli/contribution.cjs +27 -4
  219. package/dist/inspection/cli/contribution.cjs.map +1 -1
  220. package/dist/inspection/cli/contribution.d.cts +2 -1
  221. package/dist/inspection/cli/contribution.d.mts +2 -1
  222. package/dist/inspection/cli/contribution.d.ts +2 -1
  223. package/dist/inspection/execution-traces.cjs +114 -8
  224. package/dist/inspection/execution-traces.cjs.map +1 -1
  225. package/dist/inspection/execution-traces.d.cts +38 -0
  226. package/dist/inspection/execution-traces.d.mts +38 -0
  227. package/dist/inspection/execution-traces.d.ts +38 -0
  228. package/dist/inspection/facts.cjs +12 -0
  229. package/dist/inspection/facts.cjs.map +1 -1
  230. package/dist/inspection/limits.cjs +5 -1
  231. package/dist/inspection/limits.cjs.map +1 -1
  232. package/dist/inspection/limits.d.cts +4 -0
  233. package/dist/inspection/limits.d.mts +4 -0
  234. package/dist/inspection/limits.d.ts +4 -0
  235. package/dist/inspection/limits.js +6 -2
  236. package/dist/inspection/overview.cjs +74 -33
  237. package/dist/inspection/overview.cjs.map +1 -1
  238. package/dist/inspection/overview.d.cts +19 -1
  239. package/dist/inspection/overview.d.mts +19 -1
  240. package/dist/inspection/overview.d.ts +19 -1
  241. package/dist/inspection/overview.js +4 -2
  242. package/dist/inspection/project-input.cjs +9 -0
  243. package/dist/inspection/project-input.cjs.map +1 -0
  244. package/dist/inspection/project-input.d.cts +20 -0
  245. package/dist/inspection/project-input.d.mts +20 -0
  246. package/dist/inspection/project-input.d.ts +20 -0
  247. package/dist/inspection/project-input.js +8 -0
  248. package/dist/inspection/project-input.js.map +1 -0
  249. package/dist/inspection/project-result.cjs +60 -0
  250. package/dist/inspection/project-result.cjs.map +1 -0
  251. package/dist/inspection/project-result.d.cts +1264 -0
  252. package/dist/inspection/project-result.d.mts +1264 -0
  253. package/dist/inspection/project-result.d.ts +1264 -0
  254. package/dist/inspection/project-result.js +10 -0
  255. package/dist/inspection/project-result.js.map +1 -0
  256. package/dist/inspection/project-source.cjs +109 -0
  257. package/dist/inspection/project-source.cjs.map +1 -0
  258. package/dist/inspection/project-source.d.cts +10 -0
  259. package/dist/inspection/project-source.d.mts +10 -0
  260. package/dist/inspection/project-source.d.ts +10 -0
  261. package/dist/inspection/project-source.js +6 -0
  262. package/dist/inspection/project-source.js.map +1 -0
  263. package/dist/inspection/project.cjs +100 -0
  264. package/dist/inspection/project.cjs.map +1 -0
  265. package/dist/inspection/project.d.cts +3 -0
  266. package/dist/inspection/project.d.mts +3 -0
  267. package/dist/inspection/project.d.ts +3 -0
  268. package/dist/inspection/project.js +6 -0
  269. package/dist/inspection/project.js.map +1 -0
  270. package/dist/inspection/protocol.cjs +19 -9
  271. package/dist/inspection/protocol.cjs.map +1 -1
  272. package/dist/inspection/protocol.d.cts +5506 -38189
  273. package/dist/inspection/protocol.d.mts +5506 -38189
  274. package/dist/inspection/protocol.d.ts +5506 -38189
  275. package/dist/inspection/public.mjs +896 -84
  276. package/dist/inspection/query.cjs +2 -0
  277. package/dist/inspection/query.cjs.map +1 -1
  278. package/dist/inspection/results.cjs +234 -29
  279. package/dist/inspection/results.cjs.map +1 -1
  280. package/dist/inspection/results.d.cts +870 -13
  281. package/dist/inspection/results.d.mts +870 -13
  282. package/dist/inspection/results.d.ts +870 -13
  283. package/dist/inspection/results.js +36 -34
  284. package/dist/inspection/select.cjs +126 -14
  285. package/dist/inspection/select.cjs.map +1 -1
  286. package/dist/inspection/select.d.cts +1 -1
  287. package/dist/inspection/select.d.mts +1 -1
  288. package/dist/inspection/select.d.ts +1 -1
  289. package/dist/inspection/source.cjs +4 -0
  290. package/dist/inspection/source.cjs.map +1 -1
  291. package/dist/inspection/sources.cjs +5 -0
  292. package/dist/inspection/sources.cjs.map +1 -1
  293. package/dist/inspection/trace.cjs +82 -84
  294. package/dist/inspection/trace.cjs.map +1 -1
  295. package/dist/inspection/trace.d.cts +7 -2
  296. package/dist/inspection/trace.d.mts +7 -2
  297. package/dist/inspection/trace.d.ts +7 -2
  298. package/dist/model-slots.cjs +35 -0
  299. package/dist/model-slots.cjs.map +1 -0
  300. package/dist/model-slots.d.cts +19 -0
  301. package/dist/model-slots.d.mts +19 -0
  302. package/dist/model-slots.d.ts +19 -0
  303. package/dist/model-slots.js +8 -0
  304. package/dist/model-slots.js.map +1 -0
  305. package/dist/o11y/adapter-call-price.cjs +4 -0
  306. package/dist/o11y/adapter-call-price.cjs.map +1 -1
  307. package/dist/o11y/adapter-call-price.d.cts +24 -0
  308. package/dist/o11y/adapter-call-price.d.mts +24 -0
  309. package/dist/o11y/adapter-call-price.d.ts +24 -0
  310. package/dist/o11y/adapter-call-price.js +6 -2
  311. package/dist/o11y/adapter-usage-projection.cjs +158 -0
  312. package/dist/o11y/adapter-usage-projection.cjs.map +1 -0
  313. package/dist/o11y/adapter-usage-projection.d.cts +141 -0
  314. package/dist/o11y/adapter-usage-projection.d.mts +141 -0
  315. package/dist/o11y/adapter-usage-projection.d.ts +141 -0
  316. package/dist/o11y/adapter-usage-projection.js +20 -0
  317. package/dist/o11y/adapter-usage-projection.js.map +1 -0
  318. package/dist/o11y/eval-usage.cjs +149 -0
  319. package/dist/o11y/eval-usage.cjs.map +1 -0
  320. package/dist/o11y/eval-usage.d.cts +46 -0
  321. package/dist/o11y/eval-usage.d.mts +46 -0
  322. package/dist/o11y/eval-usage.d.ts +46 -0
  323. package/dist/o11y/eval-usage.js +8 -0
  324. package/dist/o11y/eval-usage.js.map +1 -0
  325. package/dist/o11y/judge-call-price.cjs +62 -0
  326. package/dist/o11y/judge-call-price.cjs.map +1 -0
  327. package/dist/o11y/judge-call-price.d.cts +3 -0
  328. package/dist/o11y/judge-call-price.d.mts +3 -0
  329. package/dist/o11y/judge-call-price.d.ts +3 -0
  330. package/dist/o11y/judge-call-price.js +6 -0
  331. package/dist/o11y/judge-call-price.js.map +1 -0
  332. package/dist/o11y/judge-usage-projection.cjs +134 -0
  333. package/dist/o11y/judge-usage-projection.cjs.map +1 -0
  334. package/dist/o11y/judge-usage-projection.d.cts +18 -0
  335. package/dist/o11y/judge-usage-projection.d.mts +18 -0
  336. package/dist/o11y/judge-usage-projection.d.ts +18 -0
  337. package/dist/o11y/judge-usage-projection.js +20 -0
  338. package/dist/o11y/judge-usage-projection.js.map +1 -0
  339. package/dist/o11y/judge-usage-receipt.cjs +135 -0
  340. package/dist/o11y/judge-usage-receipt.cjs.map +1 -0
  341. package/dist/o11y/judge-usage-receipt.d.cts +5 -0
  342. package/dist/o11y/judge-usage-receipt.d.mts +5 -0
  343. package/dist/o11y/judge-usage-receipt.d.ts +5 -0
  344. package/dist/o11y/judge-usage-receipt.js +6 -0
  345. package/dist/o11y/judge-usage-receipt.js.map +1 -0
  346. package/dist/o11y/judge-usage.cjs +171 -0
  347. package/dist/o11y/judge-usage.cjs.map +1 -0
  348. package/dist/o11y/judge-usage.d.cts +35 -0
  349. package/dist/o11y/judge-usage.d.mts +35 -0
  350. package/dist/o11y/judge-usage.d.ts +35 -0
  351. package/dist/o11y/judge-usage.js +6 -0
  352. package/dist/o11y/judge-usage.js.map +1 -0
  353. package/dist/plugin/contracts.cjs +2 -0
  354. package/dist/plugin/contracts.cjs.map +1 -1
  355. package/dist/plugin/link.cjs +7 -0
  356. package/dist/plugin/link.cjs.map +1 -1
  357. package/dist/record/attachment/protocol.cjs +8 -6
  358. package/dist/record/attachment/protocol.cjs.map +1 -1
  359. package/dist/record/attachment/protocol.d.cts +10 -0
  360. package/dist/record/attachment/protocol.d.mts +10 -0
  361. package/dist/record/attachment/protocol.d.ts +10 -0
  362. package/dist/record/attachment/protocol.js +38 -36
  363. package/dist/record/codec/seal-manifest.d.cts +3 -3
  364. package/dist/record/codec/seal-manifest.d.mts +3 -3
  365. package/dist/record/codec/seal-manifest.d.ts +3 -3
  366. package/dist/record/family/adapter-usage/definition.d.cts +1 -0
  367. package/dist/record/family/adapter-usage/definition.d.mts +1 -0
  368. package/dist/record/family/adapter-usage/definition.d.ts +1 -0
  369. package/dist/record/family/adapter-usage/persistence.cjs +1 -1
  370. package/dist/record/family/adapter-usage/persistence.cjs.map +1 -1
  371. package/dist/record/family/adapter-usage/persistence.d.cts +2 -1
  372. package/dist/record/family/adapter-usage/persistence.d.mts +2 -1
  373. package/dist/record/family/adapter-usage/persistence.d.ts +2 -1
  374. package/dist/record/family/adapter-usage/schema.cjs +21 -2
  375. package/dist/record/family/adapter-usage/schema.cjs.map +1 -1
  376. package/dist/record/family/adapter-usage/schema.d.cts +85 -0
  377. package/dist/record/family/adapter-usage/schema.d.mts +85 -0
  378. package/dist/record/family/adapter-usage/schema.d.ts +85 -0
  379. package/dist/record/family/adapter-usage/schema.js +18 -12
  380. package/dist/record/family/catalog.cjs +31 -27
  381. package/dist/record/family/catalog.cjs.map +1 -1
  382. package/dist/record/family/catalog.d.cts +94 -3
  383. package/dist/record/family/catalog.d.mts +94 -3
  384. package/dist/record/family/catalog.d.ts +94 -3
  385. package/dist/record/family/current.cjs +45 -42
  386. package/dist/record/family/current.cjs.map +1 -1
  387. package/dist/record/family/current.d.cts +240 -1
  388. package/dist/record/family/current.d.mts +240 -1
  389. package/dist/record/family/current.d.ts +240 -1
  390. package/dist/record/family/execution-traces/definition.d.cts +26 -0
  391. package/dist/record/family/execution-traces/definition.d.mts +26 -0
  392. package/dist/record/family/execution-traces/definition.d.ts +26 -0
  393. package/dist/record/family/execution-traces/definition.js +20 -14
  394. package/dist/record/family/execution-traces/schema.cjs +57 -1
  395. package/dist/record/family/execution-traces/schema.cjs.map +1 -1
  396. package/dist/record/family/execution-traces/schema.d.cts +114 -0
  397. package/dist/record/family/execution-traces/schema.d.mts +114 -0
  398. package/dist/record/family/execution-traces/schema.d.ts +114 -0
  399. package/dist/record/family/execution-traces/schema.js +18 -12
  400. package/dist/record/family/judge-usage/definition.cjs +12 -0
  401. package/dist/record/family/judge-usage/definition.cjs.map +1 -0
  402. package/dist/record/family/judge-usage/definition.d.cts +91 -0
  403. package/dist/record/family/judge-usage/definition.d.mts +91 -0
  404. package/dist/record/family/judge-usage/definition.d.ts +91 -0
  405. package/dist/record/family/judge-usage/definition.js +6 -0
  406. package/dist/record/family/judge-usage/definition.js.map +1 -0
  407. package/dist/record/family/judge-usage/persistence.cjs +10 -0
  408. package/dist/record/family/judge-usage/persistence.cjs.map +1 -0
  409. package/dist/record/family/judge-usage/persistence.d.cts +91 -0
  410. package/dist/record/family/judge-usage/persistence.d.mts +91 -0
  411. package/dist/record/family/judge-usage/persistence.d.ts +91 -0
  412. package/dist/record/family/judge-usage/persistence.js +6 -0
  413. package/dist/record/family/judge-usage/persistence.js.map +1 -0
  414. package/dist/record/family/judge-usage/schema.cjs +307 -0
  415. package/dist/record/family/judge-usage/schema.cjs.map +1 -0
  416. package/dist/record/family/judge-usage/schema.d.cts +351 -0
  417. package/dist/record/family/judge-usage/schema.d.mts +351 -0
  418. package/dist/record/family/judge-usage/schema.d.ts +351 -0
  419. package/dist/record/family/judge-usage/schema.js +18 -0
  420. package/dist/record/family/judge-usage/schema.js.map +1 -0
  421. package/dist/record/host/sqlite-host.cjs +55 -9
  422. package/dist/record/host/sqlite-host.cjs.map +1 -1
  423. package/dist/record/host/types.cjs.map +1 -1
  424. package/dist/record/host/types.d.cts +7 -0
  425. package/dist/record/host/types.d.mts +7 -0
  426. package/dist/record/host/types.d.ts +7 -0
  427. package/dist/record/model/run-context.cjs +7 -1
  428. package/dist/record/model/run-context.cjs.map +1 -1
  429. package/dist/record/model/run-context.d.cts +4 -0
  430. package/dist/record/model/run-context.d.mts +4 -0
  431. package/dist/record/model/run-context.d.ts +4 -0
  432. package/dist/record/model/seal-manifest.d.cts +1 -1
  433. package/dist/record/model/seal-manifest.d.mts +1 -1
  434. package/dist/record/model/seal-manifest.d.ts +1 -1
  435. package/dist/record/sqlite/client.cjs +18 -5
  436. package/dist/record/sqlite/client.cjs.map +1 -1
  437. package/dist/record/sqlite/client.d.cts +1 -1
  438. package/dist/record/sqlite/client.d.mts +1 -1
  439. package/dist/record/sqlite/client.d.ts +1 -1
  440. package/dist/record/sqlite/project-state-database.cjs +29 -8
  441. package/dist/record/sqlite/project-state-database.cjs.map +1 -1
  442. package/dist/run/host/runtime.cjs +4 -0
  443. package/dist/run/host/runtime.cjs.map +1 -1
  444. package/dist/run/storage/sqlite.cjs +20 -0
  445. package/dist/run/storage/sqlite.cjs.map +1 -1
  446. package/dist/runner/adapter-execution-trace.cjs +125 -2
  447. package/dist/runner/adapter-execution-trace.cjs.map +1 -1
  448. package/dist/runner/adapter-execution-trace.d.cts +1 -1
  449. package/dist/runner/adapter-execution-trace.d.mts +1 -1
  450. package/dist/runner/adapter-execution-trace.d.ts +1 -1
  451. package/dist/runner/adapter-usage.cjs +55 -7
  452. package/dist/runner/adapter-usage.cjs.map +1 -1
  453. package/dist/runner/adapter-usage.d.cts +9 -2
  454. package/dist/runner/adapter-usage.d.mts +9 -2
  455. package/dist/runner/adapter-usage.d.ts +9 -2
  456. package/dist/runner/adoption.cjs +9 -0
  457. package/dist/runner/adoption.cjs.map +1 -1
  458. package/dist/runner/attempt-cancellation.cjs +12 -0
  459. package/dist/runner/attempt-cancellation.cjs.map +1 -0
  460. package/dist/runner/attempt-cancellation.d.cts +6 -0
  461. package/dist/runner/attempt-cancellation.d.mts +6 -0
  462. package/dist/runner/attempt-cancellation.d.ts +6 -0
  463. package/dist/runner/attempt-cancellation.js +6 -0
  464. package/dist/runner/attempt-cancellation.js.map +1 -0
  465. package/dist/runner/attempt-resources.cjs +10 -4
  466. package/dist/runner/attempt-resources.cjs.map +1 -1
  467. package/dist/runner/attempt-resources.d.cts +2 -1
  468. package/dist/runner/attempt-resources.d.mts +2 -1
  469. package/dist/runner/attempt-resources.d.ts +2 -1
  470. package/dist/runner/attempt.cjs +1177 -1139
  471. package/dist/runner/attempt.cjs.map +1 -1
  472. package/dist/runner/config-identity.cjs +20 -1
  473. package/dist/runner/config-identity.cjs.map +1 -1
  474. package/dist/runner/config-identity.d.cts +5 -0
  475. package/dist/runner/config-identity.d.mts +5 -0
  476. package/dist/runner/config-identity.d.ts +5 -0
  477. package/dist/runner/discover.cjs +14 -0
  478. package/dist/runner/discover.cjs.map +1 -1
  479. package/dist/runner/discover.d.cts +3 -0
  480. package/dist/runner/discover.d.mts +3 -0
  481. package/dist/runner/discover.d.ts +3 -0
  482. package/dist/runner/feedback/human.cjs +9 -4
  483. package/dist/runner/feedback/human.cjs.map +1 -1
  484. package/dist/runner/fingerprint.cjs +1 -0
  485. package/dist/runner/fingerprint.cjs.map +1 -1
  486. package/dist/runner/judge-usage.cjs +18 -0
  487. package/dist/runner/judge-usage.cjs.map +1 -0
  488. package/dist/runner/judge-usage.d.cts +5 -0
  489. package/dist/runner/judge-usage.d.mts +5 -0
  490. package/dist/runner/judge-usage.d.ts +5 -0
  491. package/dist/runner/judge-usage.js +8 -0
  492. package/dist/runner/judge-usage.js.map +1 -0
  493. package/dist/runner/project-target.cjs.map +1 -1
  494. package/dist/runner/project-target.d.cts +2 -0
  495. package/dist/runner/project-target.d.mts +2 -0
  496. package/dist/runner/project-target.d.ts +2 -0
  497. package/dist/runner/record/planning.cjs +1 -0
  498. package/dist/runner/record/planning.cjs.map +1 -1
  499. package/dist/runner/record.cjs +4 -0
  500. package/dist/runner/record.cjs.map +1 -1
  501. package/dist/runner/reporters/braintrust.cjs +2 -0
  502. package/dist/runner/reporters/braintrust.cjs.map +1 -1
  503. package/dist/runner/reuse-diagnostics.cjs +9 -10
  504. package/dist/runner/reuse-diagnostics.cjs.map +1 -1
  505. package/dist/runner/reuse-diagnostics.d.cts +5 -6
  506. package/dist/runner/reuse-diagnostics.d.mts +5 -6
  507. package/dist/runner/reuse-diagnostics.d.ts +5 -6
  508. package/dist/runner/reuse-diagnostics.js +4 -4
  509. package/dist/runner/reuse-plan.cjs +100 -48
  510. package/dist/runner/reuse-plan.cjs.map +1 -1
  511. package/dist/runner/reuse-plan.d.cts +60 -3
  512. package/dist/runner/reuse-plan.d.mts +60 -3
  513. package/dist/runner/reuse-plan.d.ts +60 -3
  514. package/dist/runner/reuse-plan.js +14 -10
  515. package/dist/runner/run.cjs +8 -6
  516. package/dist/runner/run.cjs.map +1 -1
  517. package/dist/runner/session.cjs +1 -1
  518. package/dist/runner/session.cjs.map +1 -1
  519. package/dist/runner/session.d.cts +1 -1
  520. package/dist/runner/session.d.mts +1 -1
  521. package/dist/runner/session.d.ts +1 -1
  522. package/dist/runner/source-producer.cjs +3 -1
  523. package/dist/runner/source-producer.cjs.map +1 -1
  524. package/dist/runner/types.cjs.map +1 -1
  525. package/dist/runner/types.d.cts +26 -5
  526. package/dist/runner/types.d.mts +26 -5
  527. package/dist/runner/types.d.ts +26 -5
  528. package/dist/sandbox/action.cjs +3 -0
  529. package/dist/sandbox/action.cjs.map +1 -1
  530. package/dist/sandbox/commands.cjs +3 -0
  531. package/dist/sandbox/commands.cjs.map +1 -1
  532. package/dist/sandbox/compose.cjs +6 -0
  533. package/dist/sandbox/compose.cjs.map +1 -1
  534. package/dist/sandbox/docker-profile/registry.cjs +7 -0
  535. package/dist/sandbox/docker-profile/registry.cjs.map +1 -1
  536. package/dist/sandbox/docker-profile/runtime.cjs +3 -0
  537. package/dist/sandbox/docker-profile/runtime.cjs.map +1 -1
  538. package/dist/sandbox/docker-profile/schema.cjs +7 -0
  539. package/dist/sandbox/docker-profile/schema.cjs.map +1 -1
  540. package/dist/sandbox/incus.cjs +7 -0
  541. package/dist/sandbox/incus.cjs.map +1 -1
  542. package/dist/sandbox/layer.cjs +12 -0
  543. package/dist/sandbox/layer.cjs.map +1 -1
  544. package/dist/shared/adapter-cleanup.cjs +18 -0
  545. package/dist/shared/adapter-cleanup.cjs.map +1 -0
  546. package/dist/shared/adapter-cleanup.d.cts +4 -0
  547. package/dist/shared/adapter-cleanup.d.mts +4 -0
  548. package/dist/shared/adapter-cleanup.d.ts +4 -0
  549. package/dist/shared/adapter-cleanup.js +10 -0
  550. package/dist/shared/adapter-cleanup.js.map +1 -0
  551. package/dist/shared/attempt-lifecycle.cjs +3 -0
  552. package/dist/shared/attempt-lifecycle.cjs.map +1 -0
  553. package/dist/shared/attempt-lifecycle.d.cts +13 -0
  554. package/dist/shared/attempt-lifecycle.d.mts +13 -0
  555. package/dist/shared/attempt-lifecycle.d.ts +13 -0
  556. package/dist/shared/attempt-lifecycle.js +4 -0
  557. package/dist/shared/attempt-lifecycle.js.map +1 -0
  558. package/dist/show/contribution.cjs +52 -14
  559. package/dist/show/contribution.cjs.map +1 -1
  560. package/dist/show/contribution.d.cts +23 -1
  561. package/dist/show/contribution.d.mts +23 -1
  562. package/dist/show/contribution.d.ts +23 -1
  563. package/dist/show/model.cjs +8 -1
  564. package/dist/show/model.cjs.map +1 -1
  565. package/dist/show/model.d.cts +10 -1
  566. package/dist/show/model.d.mts +10 -1
  567. package/dist/show/model.d.ts +10 -1
  568. package/dist/show/render.cjs +287 -49
  569. package/dist/show/render.cjs.map +1 -1
  570. package/dist/show/render.d.cts +3 -0
  571. package/dist/show/render.d.mts +3 -0
  572. package/dist/show/render.d.ts +3 -0
  573. package/dist/sources/projector.cjs +3 -0
  574. package/dist/sources/projector.cjs.map +1 -1
  575. package/dist/types.cjs.map +1 -1
  576. package/dist/types.d.cts +1 -1
  577. package/dist/types.d.mts +1 -1
  578. package/dist/types.d.ts +1 -1
  579. package/dist/view/app-dist/.vite/manifest.json +2 -2
  580. package/dist/view/app-dist/assets/index-CmVoXbwG.js +63 -0
  581. package/dist/view/app-dist/assets/{quality-cost-scatter-CFB3wnkN.js → quality-cost-scatter-BuLISaH4.js} +1 -1
  582. package/dist/view/app-dist/index.html +1 -1
  583. package/dist/view/cli/contribution.cjs +54 -21
  584. package/dist/view/cli/contribution.cjs.map +1 -1
  585. package/dist/view/cli/contribution.d.cts +2 -1
  586. package/dist/view/cli/contribution.d.mts +2 -1
  587. package/dist/view/cli/contribution.d.ts +2 -1
  588. package/dist/view/function-runtime.mjs +13231 -11647
  589. package/dist/view/http-protocol.cjs +3 -0
  590. package/dist/view/http-protocol.cjs.map +1 -1
  591. package/dist/view/http-protocol.d.cts +8 -0
  592. package/dist/view/http-protocol.d.mts +8 -0
  593. package/dist/view/http-protocol.d.ts +8 -0
  594. package/dist/view/inspection-host.cjs +17 -1
  595. package/dist/view/inspection-host.cjs.map +1 -1
  596. package/dist/view/render.cjs +1 -0
  597. package/dist/view/render.cjs.map +1 -1
  598. package/dist/view/render.d.cts +2 -1
  599. package/dist/view/render.d.mts +2 -1
  600. package/dist/view/render.d.ts +2 -1
  601. package/dist/view/revision.cjs.map +1 -1
  602. package/dist/view/revision.d.cts +12 -0
  603. package/dist/view/revision.d.mts +12 -0
  604. package/dist/view/revision.d.ts +12 -0
  605. package/dist/view/server.cjs +10 -9
  606. package/dist/view/server.cjs.map +1 -1
  607. package/docs-site/zh/examples/ai-agent-application.mdx +1 -1
  608. package/docs-site/zh/explanation/adapter.mdx +2 -2
  609. package/docs-site/zh/explanation/assert.mdx +60 -24
  610. package/docs-site/zh/explanation/drive.mdx +1 -1
  611. package/docs-site/zh/explanation/evals.mdx +31 -29
  612. package/docs-site/zh/explanation/experiment.mdx +15 -15
  613. package/docs-site/zh/explanation/judge.mdx +23 -15
  614. package/docs-site/zh/explanation/overview.mdx +44 -21
  615. package/docs-site/zh/explanation/record.mdx +28 -13
  616. package/docs-site/zh/explanation/results-flow.mdx +37 -0
  617. package/docs-site/zh/explanation/runner.mdx +27 -6
  618. package/docs-site/zh/index.mdx +22 -115
  619. package/docs-site/zh/introduction.mdx +89 -61
  620. package/docs-site/zh/reference/cli.mdx +50 -26
  621. package/docs-site/zh/reference/define-agent.mdx +37 -5
  622. package/docs-site/zh/reference/define-eval.mdx +130 -29
  623. package/docs-site/zh/reference/define-experiment.mdx +251 -0
  624. package/docs-site/zh/reference/events.mdx +34 -30
  625. package/docs-site/zh/reference/expect.mdx +77 -2
  626. package/docs-site/zh/reference/official-adapters.mdx +2 -2
  627. package/docs-site/zh/troubleshooting/debug-sandbox.mdx +43 -24
  628. package/docs-site/zh/troubleshooting/debugging.mdx +65 -42
  629. package/docs-site/zh/troubleshooting/recover-after-kill.mdx +35 -28
  630. package/docs-site/zh/tutorials/accept-results.mdx +34 -24
  631. package/docs-site/zh/tutorials/agent-feedback-loop.mdx +74 -43
  632. package/docs-site/zh/tutorials/agent-onboarding.mdx +27 -20
  633. package/docs-site/zh/tutorials/authoring.mdx +138 -121
  634. package/docs-site/zh/tutorials/ci-integration.mdx +46 -22
  635. package/docs-site/zh/tutorials/compare-runs.mdx +40 -13
  636. package/docs-site/zh/tutorials/concurrency.mdx +66 -62
  637. package/docs-site/zh/tutorials/configuration.mdx +17 -17
  638. package/docs-site/zh/tutorials/connect-otel.mdx +48 -37
  639. package/docs-site/zh/tutorials/connect-your-agent.mdx +80 -173
  640. package/docs-site/zh/tutorials/control-run-cost.mdx +63 -12
  641. package/docs-site/zh/tutorials/criteria-files.mdx +28 -21
  642. package/docs-site/zh/tutorials/custom-application.mdx +75 -55
  643. package/docs-site/zh/tutorials/dataset-fanout.mdx +32 -22
  644. package/docs-site/zh/tutorials/debug-lifecycle-plan.mdx +38 -31
  645. package/docs-site/zh/tutorials/docker-in-docker.mdx +83 -89
  646. package/docs-site/zh/tutorials/eval-groups.mdx +70 -89
  647. package/docs-site/zh/tutorials/evaluation-kinds.mdx +12 -5
  648. package/docs-site/zh/tutorials/experiment-services.mdx +243 -0
  649. package/docs-site/zh/tutorials/fixtures.mdx +42 -26
  650. package/docs-site/zh/tutorials/handle-execution-failures.mdx +41 -19
  651. package/docs-site/zh/tutorials/install-custom-sandbox-agent.mdx +21 -16
  652. package/docs-site/zh/tutorials/niceeval-taste-application.mdx +394 -0
  653. package/docs-site/zh/tutorials/niceeval-taste.mdx +190 -0
  654. package/docs-site/zh/tutorials/nixos-managed-dind.mdx +51 -39
  655. package/docs-site/zh/tutorials/plugins.mdx +55 -31
  656. package/docs-site/zh/tutorials/prebuilt-sandbox.mdx +204 -0
  657. package/docs-site/zh/tutorials/quickstart.mdx +91 -47
  658. package/docs-site/zh/tutorials/reporters.mdx +45 -30
  659. package/docs-site/zh/tutorials/rerun-and-cache.mdx +39 -40
  660. package/docs-site/zh/tutorials/sandbox-agent.mdx +65 -40
  661. package/docs-site/zh/tutorials/sandbox-providers.mdx +104 -282
  662. package/docs-site/zh/tutorials/sandbox-reuse.mdx +65 -97
  663. package/docs-site/zh/tutorials/select-and-preview.mdx +25 -20
  664. package/docs-site/zh/tutorials/verify-judge.mdx +49 -26
  665. package/docs-site/zh/tutorials/viewing-results.mdx +130 -80
  666. package/docs-site/zh/tutorials/write-experiment.mdx +116 -298
  667. package/docs-site/zh/tutorials/write-send.mdx +53 -52
  668. package/node_modules/undici/docs/docs/api/Agent.md +8 -8
  669. package/node_modules/undici/docs/docs/api/DiagnosticsChannel.md +9 -6
  670. package/node_modules/undici/docs/docs/api/Errors.md +25 -0
  671. package/node_modules/undici/docs/docs/api/Interceptors.md +4 -3
  672. package/node_modules/undici/docs/docs/api/Pool.md +5 -6
  673. package/node_modules/undici/lib/api/readable.js +1 -2
  674. package/node_modules/undici/lib/core/request.js +23 -2
  675. package/node_modules/undici/lib/core/util.js +0 -39
  676. package/node_modules/undici/lib/dispatcher/client-h1.js +11 -4
  677. package/node_modules/undici/lib/dispatcher/client-h2.js +52 -8
  678. package/node_modules/undici/lib/dispatcher/client.js +1 -1
  679. package/node_modules/undici/lib/dispatcher/dispatcher1-wrapper.js +3 -2
  680. package/node_modules/undici/lib/dispatcher/env-http-proxy-agent.js +21 -6
  681. package/node_modules/undici/lib/dispatcher/pool-base.js +63 -2
  682. package/node_modules/undici/lib/dispatcher/pool.js +90 -7
  683. package/node_modules/undici/lib/dispatcher/proxy-agent.js +16 -3
  684. package/node_modules/undici/lib/handler/deduplication-handler.js +24 -11
  685. package/node_modules/undici/lib/handler/redirect-handler.js +5 -0
  686. package/node_modules/undici/lib/handler/retry-handler.js +72 -13
  687. package/node_modules/undici/lib/interceptor/cache.js +4 -1
  688. package/node_modules/undici/lib/interceptor/decompress.js +236 -69
  689. package/node_modules/undici/lib/web/cache/cache.js +17 -8
  690. package/node_modules/undici/lib/web/cache/cachestorage.js +11 -5
  691. package/node_modules/undici/lib/web/cookies/index.js +19 -7
  692. package/node_modules/undici/lib/web/cookies/util.js +3 -1
  693. package/node_modules/undici/lib/web/eventsource/eventsource.js +25 -1
  694. package/node_modules/undici/lib/web/fetch/body.js +22 -15
  695. package/node_modules/undici/lib/web/fetch/data-url.js +6 -6
  696. package/node_modules/undici/lib/web/fetch/formdata.js +30 -36
  697. package/node_modules/undici/lib/web/fetch/headers.js +34 -31
  698. package/node_modules/undici/lib/web/fetch/index.js +38 -14
  699. package/node_modules/undici/lib/web/fetch/request.js +74 -79
  700. package/node_modules/undici/lib/web/fetch/response.js +43 -44
  701. package/node_modules/undici/lib/web/fetch/util.js +7 -7
  702. package/node_modules/undici/lib/web/infra/index.js +16 -1
  703. package/node_modules/undici/lib/web/webidl/index.js +2 -14
  704. package/node_modules/undici/lib/web/websocket/events.js +43 -26
  705. package/node_modules/undici/lib/web/websocket/receiver.js +5 -0
  706. package/node_modules/undici/lib/web/websocket/stream/websocketerror.js +13 -10
  707. package/node_modules/undici/lib/web/websocket/websocket.js +44 -41
  708. package/node_modules/undici/package.json +1 -1
  709. package/node_modules/undici/types/diagnostics-channel.d.ts +2 -1
  710. package/node_modules/undici/types/interceptors.d.ts +1 -1
  711. package/node_modules/undici/types/webidl.d.ts +13 -7
  712. package/package.json +4 -4
  713. package/dist/view/app-dist/assets/index-DFzw1L97.js +0 -63
  714. package/docs-site/zh/tutorials/experiments.mdx +0 -101
@@ -0,0 +1,135 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeJudgeUsageResponse = normalizeJudgeUsageResponse;
4
+ const effect_1 = require("effect");
5
+ const core_ts_1 = require("../record/codec/core.cjs");
6
+ const digest_ts_1 = require("../record/definition/digest.cjs");
7
+ const common_ts_1 = require("../record/family/common.cjs");
8
+ const codec_ts_1 = require("../record/family/source-receipt/codec.cjs");
9
+ const pricing_ts_1 = require("../record/family/adapter-usage/pricing.cjs");
10
+ const schema_ts_1 = require("../record/family/judge-usage/schema.cjs");
11
+ const ProviderSchema = schema_ts_1.JudgeUsageModelSchema.check(effect_1.Schema.makeFilter((value) => new TextEncoder().encode(value).byteLength <= 256));
12
+ const JsonResponseSchema = effect_1.Schema.fromJsonString(effect_1.Schema.Unknown);
13
+ function unavailable(reason, responseDigest) {
14
+ return Object.freeze({
15
+ provider: null, model: null, inputTokens: null, inputTotalTokens: null, outputTokens: null,
16
+ cacheReadTokens: null, cacheWriteTokens: null, cost: null,
17
+ receipt: Object.freeze({ state: "unavailable", reason, responseDigest, fields: Object.freeze([]) }),
18
+ });
19
+ }
20
+ /** Retains only protocol facts, independently of status and QA/body interpretation. */
21
+ function normalizeJudgeUsageResponse(transportProvider, body) {
22
+ const bytes = new TextEncoder().encode(body);
23
+ if (body.length === 0)
24
+ return unavailable("response-unavailable", null);
25
+ const responseDigest = `sha256:${new digest_ts_1.RecordSha256().update(bytes).digestHex()}`;
26
+ const decoded = effect_1.Schema.decodeUnknownResult(JsonResponseSchema)(body);
27
+ if (effect_1.Result.isFailure(decoded))
28
+ return unavailable("invalid-json", responseDigest);
29
+ const root = decoded.success;
30
+ if (!effect_1.Predicate.isObject(root) || Array.isArray(root))
31
+ return unavailable("invalid-usage", responseDigest);
32
+ const fields = [];
33
+ let invalidUsage = root.usage !== undefined && (!effect_1.Predicate.isObject(root.usage) || Array.isArray(root.usage));
34
+ let modelTooLarge = false;
35
+ function read(path) {
36
+ let value = root;
37
+ for (const key of path.split(".")) {
38
+ if (!effect_1.Predicate.isObject(value) || Array.isArray(value) || !Object.hasOwn(value, key))
39
+ return undefined;
40
+ value = value[key];
41
+ }
42
+ return value;
43
+ }
44
+ function scalar(path, schema) {
45
+ const raw = read(path);
46
+ if (raw === undefined)
47
+ return null;
48
+ const value = effect_1.Schema.decodeUnknownResult(schema, core_ts_1.RecordExactParseOptions)(raw);
49
+ if (effect_1.Result.isFailure(value)) {
50
+ if (path === "model" && typeof raw === "string" && new TextEncoder().encode(raw).byteLength > schema_ts_1.JudgeUsageLimits.maximumModelBytes)
51
+ modelTooLarge = true;
52
+ else
53
+ invalidUsage = true;
54
+ return null;
55
+ }
56
+ // Schemas above accept only string/number encodings, so arbitrary JSON never enters a receipt.
57
+ if (typeof raw === "string" || typeof raw === "number")
58
+ fields.push({ path, value: raw === 0 ? 0 : raw });
59
+ return value.success;
60
+ }
61
+ const model = scalar("model", schema_ts_1.JudgeUsageModelSchema);
62
+ const provider = transportProvider === "openrouter" ? scalar("provider", ProviderSchema) : null;
63
+ const inputPath = transportProvider === "typesafe" ? "usage.input_tokens" : "usage.prompt_tokens";
64
+ const outputPath = transportProvider === "typesafe" ? "usage.output_tokens" : "usage.completion_tokens";
65
+ let inputTotalTokens = scalar(inputPath, common_ts_1.NonNegativeSafeIntegerSchema);
66
+ let outputTokens = scalar(outputPath, common_ts_1.NonNegativeSafeIntegerSchema);
67
+ const totalTokens = scalar("usage.total_tokens", common_ts_1.NonNegativeSafeIntegerSchema);
68
+ let cacheReadTokens = transportProvider === "typesafe" ? null
69
+ : scalar("usage.prompt_tokens_details.cached_tokens", common_ts_1.NonNegativeSafeIntegerSchema);
70
+ let cacheWriteTokens = transportProvider === "openrouter"
71
+ ? scalar("usage.prompt_tokens_details.cache_write_tokens", common_ts_1.NonNegativeSafeIntegerSchema) : null;
72
+ let inputTokens = null;
73
+ if (transportProvider !== "typesafe") {
74
+ const details = read("usage.prompt_tokens_details.cached_tokens");
75
+ const write = read("usage.prompt_tokens_details.cache_write_tokens");
76
+ const usage = root.usage;
77
+ const malformedDetails = effect_1.Predicate.isObject(usage) && usage.prompt_tokens_details !== undefined &&
78
+ (!effect_1.Predicate.isObject(usage.prompt_tokens_details) || Array.isArray(usage.prompt_tokens_details));
79
+ if (malformedDetails)
80
+ invalidUsage = true;
81
+ const invalidCache = malformedDetails || details !== undefined && cacheReadTokens === null ||
82
+ transportProvider === "openrouter" && write !== undefined && cacheWriteTokens === null;
83
+ const invalidZeroWrite = write !== undefined &&
84
+ (!effect_1.Schema.is(common_ts_1.NonNegativeSafeIntegerSchema)(write) || write !== 0);
85
+ const knownSum = (cacheReadTokens ?? 0) + (cacheWriteTokens ?? 0);
86
+ if (!Number.isSafeInteger(knownSum) || inputTotalTokens !== null &&
87
+ (knownSum > inputTotalTokens || inputTotalTokens === 0 && (invalidCache || invalidZeroWrite))) {
88
+ invalidUsage = true;
89
+ inputTotalTokens = cacheReadTokens = cacheWriteTokens = null;
90
+ }
91
+ else if (inputTotalTokens === 0 && !invalidCache) {
92
+ // Non-negative sub-buckets of an explicitly zero total are independently zero.
93
+ inputTokens = cacheReadTokens = cacheWriteTokens = 0;
94
+ }
95
+ else if (inputTotalTokens !== null && cacheReadTokens !== null && cacheWriteTokens !== null) {
96
+ inputTokens = inputTotalTokens - cacheReadTokens - cacheWriteTokens;
97
+ }
98
+ }
99
+ const invalidTotal = read("usage.total_tokens") !== undefined && totalTokens === null;
100
+ if (invalidTotal || totalTokens !== null &&
101
+ (inputTotalTokens !== null && inputTotalTokens > totalTokens || outputTokens !== null && outputTokens > totalTokens) ||
102
+ inputTotalTokens !== null && outputTokens !== null &&
103
+ (!Number.isSafeInteger(inputTotalTokens + outputTokens) || totalTokens !== null && totalTokens !== inputTotalTokens + outputTokens)) {
104
+ invalidUsage = true;
105
+ inputTokens = inputTotalTokens = outputTokens = cacheReadTokens = cacheWriteTokens = null;
106
+ }
107
+ let cost = null;
108
+ if (transportProvider === "openrouter") {
109
+ const raw = read("usage.cost");
110
+ if (raw !== undefined) {
111
+ const amount = typeof raw === "number" && effect_1.Schema.is(common_ts_1.FiniteNonNegativeNumberSchema)(raw)
112
+ ? (0, pricing_ts_1.canonicalDecimalFromNumber)(raw) : raw;
113
+ const parsed = effect_1.Schema.decodeUnknownResult(codec_ts_1.CanonicalDecimalSchema)(amount);
114
+ if (effect_1.Result.isFailure(parsed))
115
+ invalidUsage = true;
116
+ else {
117
+ const currency = effect_1.Schema.decodeUnknownSync(codec_ts_1.CurrencyCodeSchema)("USD");
118
+ cost = Object.freeze({ amount: parsed.success, currency, source: Object.freeze({ kind: "reported", id: "openrouter.usage.cost" }) });
119
+ if (typeof raw === "string" || typeof raw === "number")
120
+ fields.push({ path: "usage.cost", value: raw === 0 ? 0 : raw });
121
+ }
122
+ }
123
+ }
124
+ fields.sort((left, right) => left.path < right.path ? -1 : left.path > right.path ? 1 : 0);
125
+ const usageReported = fields.some((field) => field.path.startsWith("usage."));
126
+ const reason = invalidUsage ? "invalid-usage" : modelTooLarge ? "response-model-too-large" : usageReported ? null : "usage-not-reported";
127
+ return Object.freeze({
128
+ provider, model, inputTokens, inputTotalTokens, outputTokens, cacheReadTokens, cacheWriteTokens, cost,
129
+ receipt: Object.freeze({
130
+ state: fields.length > 0 ? "available" : "unavailable", reason, responseDigest,
131
+ fields: Object.freeze(fields.map((field) => Object.freeze(field))),
132
+ }),
133
+ });
134
+ }
135
+ //# sourceMappingURL=judge-usage-receipt.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"judge-usage-receipt.js","sourceRoot":"","sources":["judge-usage-receipt.ts"],"names":[],"mappings":";;AAmBA,kEAiHC;AApID,mCAAmD;AACnD,qDAAkE;AAClE,8DAA8D;AAC9D,0DAAyG;AACzG,uEAAsG;AACtG,0EAAuF;AACvF,sEAAsH;AAGtH,MAAM,cAAc,GAAG,iCAAqB,CAAC,KAAK,CAAC,eAAM,CAAC,UAAU,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,UAAU,IAAI,GAAG,CAAC,CAAC,CAAC;AACpI,MAAM,kBAAkB,GAAG,eAAM,CAAC,cAAc,CAAC,eAAM,CAAC,OAAO,CAAC,CAAC;AACjE,SAAS,WAAW,CAAC,MAA2C,EAAE,cAA6B;IAC3F,OAAO,MAAM,CAAC,MAAM,CAAC;QACjB,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,gBAAgB,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI;QAC1F,eAAe,EAAE,IAAI,EAAE,gBAAgB,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI;QACzD,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC;KACtG,CAAC,CAAC;AACP,CAAC;AACD,uFAAuF;AACvF,SAAgB,2BAA2B,CAAC,iBAAsD,EAAE,IAAY;IAC5G,MAAM,KAAK,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC7C,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;QACjB,OAAO,WAAW,CAAC,sBAAsB,EAAE,IAAI,CA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,GAAG,EAAE,CAAC,CAAC;YACxE,CAAC;QACL,CAAC;IACL,CAAC;IACD,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC3F,MAAM,aAAa,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC9E,MAAM,MAAM,GAAG,YAAY,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,0BAA0B,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,oBAAoB,CAAC;IACzI,OAAO,MAAM,CAAC,MAAM,CAAC;QACjB,QAAQ,EAAE,KAAK,EAAE,WAAW,EAAE,gBAAgB,EAAE,YAAY,EAAE,eAAe,EAAE,gBAAgB,EAAE,IAAI;QACrG,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC;YACnB,KAAK,EAAE,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,aAAa,EAAE,MAAM,EAAE,cAAc;YAC9E,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;SACrE,CAAC;KACL,CAAC,CAAC;AACP,CAAC","sourcesContent":["import { Predicate, Result, Schema } from \"effect\";\nimport { RecordExactParseOptions } from \"../record/codec/core.ts\";\nimport { RecordSha256 } from \"../record/definition/digest.ts\";\nimport { FiniteNonNegativeNumberSchema, NonNegativeSafeIntegerSchema } from \"../record/family/common.ts\";\nimport { CanonicalDecimalSchema, CurrencyCodeSchema } from \"../record/family/source-receipt/codec.ts\";\nimport { canonicalDecimalFromNumber } from \"../record/family/adapter-usage/pricing.ts\";\nimport { JudgeUsageLimits, JudgeUsageModelSchema, type JudgeUsageCall } from \"../record/family/judge-usage/schema.ts\";\ntype NormalizedResponse = Pick<JudgeUsageCall, \"provider\" | \"model\" | \"inputTokens\" | \"inputTotalTokens\" | \"outputTokens\" | \"cacheReadTokens\" | \"cacheWriteTokens\" | \"cost\" | \"receipt\">;\ntype Field = JudgeUsageCall[\"receipt\"][\"fields\"][number];\nconst ProviderSchema = JudgeUsageModelSchema.check(Schema.makeFilter((value) => new TextEncoder().encode(value).byteLength <= 256));\nconst JsonResponseSchema = Schema.fromJsonString(Schema.Unknown);\nfunction unavailable(reason: JudgeUsageCall[\"receipt\"][\"reason\"], responseDigest: string | null): NormalizedResponse {\n return Object.freeze({\n provider: null, model: null, inputTokens: null, inputTotalTokens: null, outputTokens: null,\n cacheReadTokens: null, cacheWriteTokens: null, cost: null,\n receipt: Object.freeze({ state: \"unavailable\", reason, responseDigest, fields: Object.freeze([]) }),\n });\n}\n/** Retains only protocol facts, independently of status and QA/body interpretation. */\nexport function normalizeJudgeUsageResponse(transportProvider: JudgeUsageCall[\"transportProvider\"], body: string): NormalizedResponse {\n const bytes = new TextEncoder().encode(body);\n if (body.length === 0)\n return unavailable(\"response-unavailable\", null);\n const responseDigest = `sha256:${new RecordSha256().update(bytes).digestHex()}`;\n const decoded = Schema.decodeUnknownResult(JsonResponseSchema)(body);\n if (Result.isFailure(decoded))\n return unavailable(\"invalid-json\", responseDigest);\n const root = decoded.success;\n if (!Predicate.isObject(root) || Array.isArray(root))\n return unavailable(\"invalid-usage\", responseDigest);\n const fields: Field[] = [];\n let invalidUsage = root.usage !== undefined && (!Predicate.isObject(root.usage) || Array.isArray(root.usage));\n let modelTooLarge = false;\n function read(path: Field[\"path\"]): unknown {\n let value: unknown = root;\n for (const key of path.split(\".\")) {\n if (!Predicate.isObject(value) || Array.isArray(value) || !Object.hasOwn(value, key))\n return undefined;\n value = value[key];\n }\n return value;\n }\n function scalar<A>(path: Field[\"path\"], schema: Schema.Codec<A, string | number>): A | null {\n const raw = read(path);\n if (raw === undefined)\n return null;\n const value = Schema.decodeUnknownResult(schema, RecordExactParseOptions)(raw);\n if (Result.isFailure(value)) {\n if (path === \"model\" && typeof raw === \"string\" && new TextEncoder().encode(raw).byteLength > JudgeUsageLimits.maximumModelBytes)\n modelTooLarge = true;\n else\n invalidUsage = true;\n return null;\n }\n // Schemas above accept only string/number encodings, so arbitrary JSON never enters a receipt.\n if (typeof raw === \"string\" || typeof raw === \"number\")\n fields.push({ path, value: raw === 0 ? 0 : raw });\n return value.success;\n }\n const model = scalar(\"model\", JudgeUsageModelSchema);\n const provider = transportProvider === \"openrouter\" ? scalar(\"provider\", ProviderSchema) : null;\n const inputPath = transportProvider === \"typesafe\" ? \"usage.input_tokens\" : \"usage.prompt_tokens\";\n const outputPath = transportProvider === \"typesafe\" ? \"usage.output_tokens\" : \"usage.completion_tokens\";\n let inputTotalTokens = scalar(inputPath, NonNegativeSafeIntegerSchema);\n let outputTokens = scalar(outputPath, NonNegativeSafeIntegerSchema);\n const totalTokens = scalar(\"usage.total_tokens\", NonNegativeSafeIntegerSchema);\n let cacheReadTokens = transportProvider === \"typesafe\" ? null\n : scalar(\"usage.prompt_tokens_details.cached_tokens\", NonNegativeSafeIntegerSchema);\n let cacheWriteTokens = transportProvider === \"openrouter\"\n ? scalar(\"usage.prompt_tokens_details.cache_write_tokens\", NonNegativeSafeIntegerSchema) : null;\n let inputTokens: number | null = null;\n if (transportProvider !== \"typesafe\") {\n const details = read(\"usage.prompt_tokens_details.cached_tokens\");\n const write = read(\"usage.prompt_tokens_details.cache_write_tokens\");\n const usage = root.usage;\n const malformedDetails = Predicate.isObject(usage) && usage.prompt_tokens_details !== undefined &&\n (!Predicate.isObject(usage.prompt_tokens_details) || Array.isArray(usage.prompt_tokens_details));\n if (malformedDetails)\n invalidUsage = true;\n const invalidCache = malformedDetails || details !== undefined && cacheReadTokens === null ||\n transportProvider === \"openrouter\" && write !== undefined && cacheWriteTokens === null;\n const invalidZeroWrite = write !== undefined &&\n (!Schema.is(NonNegativeSafeIntegerSchema)(write) || write !== 0);\n const knownSum = (cacheReadTokens ?? 0) + (cacheWriteTokens ?? 0);\n if (!Number.isSafeInteger(knownSum) || inputTotalTokens !== null &&\n (knownSum > inputTotalTokens || inputTotalTokens === 0 && (invalidCache || invalidZeroWrite))) {\n invalidUsage = true;\n inputTotalTokens = cacheReadTokens = cacheWriteTokens = null;\n }\n else if (inputTotalTokens === 0 && !invalidCache) {\n // Non-negative sub-buckets of an explicitly zero total are independently zero.\n inputTokens = cacheReadTokens = cacheWriteTokens = 0;\n }\n else if (inputTotalTokens !== null && cacheReadTokens !== null && cacheWriteTokens !== null) {\n inputTokens = inputTotalTokens - cacheReadTokens - cacheWriteTokens;\n }\n }\n const invalidTotal = read(\"usage.total_tokens\") !== undefined && totalTokens === null;\n if (invalidTotal || totalTokens !== null &&\n (inputTotalTokens !== null && inputTotalTokens > totalTokens || outputTokens !== null && outputTokens > totalTokens) ||\n inputTotalTokens !== null && outputTokens !== null &&\n (!Number.isSafeInteger(inputTotalTokens + outputTokens) || totalTokens !== null && totalTokens !== inputTotalTokens + outputTokens)) {\n invalidUsage = true;\n inputTokens = inputTotalTokens = outputTokens = cacheReadTokens = cacheWriteTokens = null;\n }\n let cost: JudgeUsageCall[\"cost\"] = null;\n if (transportProvider === \"openrouter\") {\n const raw = read(\"usage.cost\");\n if (raw !== undefined) {\n const amount = typeof raw === \"number\" && Schema.is(FiniteNonNegativeNumberSchema)(raw)\n ? canonicalDecimalFromNumber(raw) : raw;\n const parsed = Schema.decodeUnknownResult(CanonicalDecimalSchema)(amount);\n if (Result.isFailure(parsed))\n invalidUsage = true;\n else {\n const currency = Schema.decodeUnknownSync(CurrencyCodeSchema)(\"USD\");\n cost = Object.freeze({ amount: parsed.success, currency, source: Object.freeze({ kind: \"reported\", id: \"openrouter.usage.cost\" }) });\n if (typeof raw === \"string\" || typeof raw === \"number\")\n fields.push({ path: \"usage.cost\", value: raw === 0 ? 0 : raw });\n }\n }\n }\n fields.sort((left, right) => left.path < right.path ? -1 : left.path > right.path ? 1 : 0);\n const usageReported = fields.some((field) => field.path.startsWith(\"usage.\"));\n const reason = invalidUsage ? \"invalid-usage\" : modelTooLarge ? \"response-model-too-large\" : usageReported ? null : \"usage-not-reported\";\n return Object.freeze({\n provider, model, inputTokens, inputTotalTokens, outputTokens, cacheReadTokens, cacheWriteTokens, cost,\n receipt: Object.freeze({\n state: fields.length > 0 ? \"available\" : \"unavailable\", reason, responseDigest,\n fields: Object.freeze(fields.map((field) => Object.freeze(field))),\n }),\n });\n}\n"]}
@@ -0,0 +1,5 @@
1
+ import { type JudgeUsageCall } from "../record/family/judge-usage/schema.cjs";
2
+ type NormalizedResponse = Pick<JudgeUsageCall, "provider" | "model" | "inputTokens" | "inputTotalTokens" | "outputTokens" | "cacheReadTokens" | "cacheWriteTokens" | "cost" | "receipt">;
3
+ /** Retains only protocol facts, independently of status and QA/body interpretation. */
4
+ export declare function normalizeJudgeUsageResponse(transportProvider: JudgeUsageCall["transportProvider"], body: string): NormalizedResponse;
5
+ export {};
@@ -0,0 +1,5 @@
1
+ import { type JudgeUsageCall } from "../record/family/judge-usage/schema.mjs";
2
+ type NormalizedResponse = Pick<JudgeUsageCall, "provider" | "model" | "inputTokens" | "inputTotalTokens" | "outputTokens" | "cacheReadTokens" | "cacheWriteTokens" | "cost" | "receipt">;
3
+ /** Retains only protocol facts, independently of status and QA/body interpretation. */
4
+ export declare function normalizeJudgeUsageResponse(transportProvider: JudgeUsageCall["transportProvider"], body: string): NormalizedResponse;
5
+ export {};
@@ -0,0 +1,5 @@
1
+ import { type JudgeUsageCall } from "../record/family/judge-usage/schema.js";
2
+ type NormalizedResponse = Pick<JudgeUsageCall, "provider" | "model" | "inputTokens" | "inputTotalTokens" | "outputTokens" | "cacheReadTokens" | "cacheWriteTokens" | "cost" | "receipt">;
3
+ /** Retains only protocol facts, independently of status and QA/body interpretation. */
4
+ export declare function normalizeJudgeUsageResponse(transportProvider: JudgeUsageCall["transportProvider"], body: string): NormalizedResponse;
5
+ export {};
@@ -0,0 +1,6 @@
1
+ import { createRequire as __niceevalCreateRequire } from "node:module";
2
+ const __niceevalRequire = __niceevalCreateRequire(import.meta.url);
3
+ const __niceevalCanonical = __niceevalRequire("./judge-usage-receipt.cjs");
4
+ const __niceevalExport0 = __niceevalCanonical["normalizeJudgeUsageResponse"];
5
+ export { __niceevalExport0 as normalizeJudgeUsageResponse };
6
+ //# sourceMappingURL=judge-usage-receipt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"judge-usage-receipt.js","sources":[],"names":[],"mappings":""}
@@ -0,0 +1,171 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.JudgeUsageCollector = void 0;
4
+ const effect_1 = require("effect");
5
+ const codec_ts_1 = require("../assertions/record/codec.cjs");
6
+ const canonical_ts_1 = require("../record/definition/canonical.cjs");
7
+ const protocol_ts_1 = require("../record/attachment/protocol.cjs");
8
+ const judge_usage_receipt_ts_1 = require("./judge-usage-receipt.cjs");
9
+ const judge_call_price_ts_1 = require("./judge-call-price.cjs");
10
+ const placeholderEntryId = effect_1.Schema.decodeUnknownSync(codec_ts_1.AssertionEntryIdSchema)("ae_00000000000000000000");
11
+ const emptyReceipt = Object.freeze({
12
+ state: "unavailable", reason: "response-unavailable", responseDigest: null, fields: Object.freeze([]),
13
+ });
14
+ const completeCollection = Object.freeze({ state: "complete", limitations: Object.freeze([]) });
15
+ /** One Attempt owns admission, receipt cuts and all transport cleanup promises. */
16
+ class JudgeUsageCollector {
17
+ signal;
18
+ onCleanupIncomplete;
19
+ rows = [];
20
+ entries = new Map();
21
+ cleanups = new Set();
22
+ closed = false;
23
+ cleanupIncomplete = false;
24
+ pricing;
25
+ onAbort = () => this.close();
26
+ constructor(pricing, signal, onCleanupIncomplete) {
27
+ this.signal = signal;
28
+ this.onCleanupIncomplete = onCleanupIncomplete;
29
+ this.pricing = pricing === undefined ? undefined : freeze(structuredClone(pricing));
30
+ signal?.addEventListener("abort", this.onAbort, { once: true });
31
+ if (signal?.aborted)
32
+ this.close();
33
+ }
34
+ forEntry(entryIndex) {
35
+ const previous = this.entries.get(entryIndex);
36
+ if (!Number.isSafeInteger(entryIndex) || entryIndex < 0 || (previous !== undefined && previous.rows.length > 0)) {
37
+ throw new Error("Judge usage requires one capability per Assertion entry");
38
+ }
39
+ if (previous !== undefined)
40
+ previous.closed = true;
41
+ const entry = { closed: this.closed, rows: [] };
42
+ this.entries.set(entryIndex, entry);
43
+ return Object.freeze({
44
+ begin: (input) => {
45
+ if (this.closed || entry.closed || this.signal?.aborted || this.rows.length >= 4000)
46
+ return undefined;
47
+ const call = Object.freeze({
48
+ ...input, entryIndex, entryId: placeholderEntryId,
49
+ callId: `judge:${entryIndex}:${input.logicalOrdinal}:${input.transmissionOrdinal}`,
50
+ provider: null, model: null, status: "unknown", httpStatus: null,
51
+ inputTokens: null, inputTotalTokens: null, outputTokens: null, cacheReadTokens: null, cacheWriteTokens: null,
52
+ cost: null, receipt: emptyReceipt,
53
+ });
54
+ if (this.rows.some((row) => row.call.callId === call.callId))
55
+ throw new Error("Duplicate Judge physical call identity");
56
+ const row = { call, open: true };
57
+ if (!this.canReserve(row))
58
+ return undefined;
59
+ this.rows.push(row);
60
+ entry.rows.push(row);
61
+ const terminal = (status, reason) => {
62
+ if (!row.open)
63
+ return;
64
+ row.open = false;
65
+ row.call = Object.freeze({ ...row.call, status, receipt: Object.freeze({ ...emptyReceipt, reason }) });
66
+ };
67
+ return Object.freeze({
68
+ headers: (status) => {
69
+ if (row.open && Number.isInteger(status) && status >= 100 && status <= 599)
70
+ row.call = Object.freeze({ ...row.call, httpStatus: status });
71
+ },
72
+ body: (body) => {
73
+ if (!row.open)
74
+ return;
75
+ // No await may separate the receipt cut and its immutable contribution.
76
+ const receipt = (0, judge_usage_receipt_ts_1.normalizeJudgeUsageResponse)(input.transportProvider, body);
77
+ row.open = false;
78
+ row.call = freeze({ ...row.call, ...receipt, status: row.call.httpStatus !== null && row.call.httpStatus >= 200 && row.call.httpStatus < 300 ? "succeeded" : "failed" });
79
+ },
80
+ fail: (reason) => terminal("failed", reason),
81
+ cancel: () => terminal("cancelled", "cancelled"),
82
+ trackCleanup: (work, deadlineAt) => this.trackCleanup(work, deadlineAt),
83
+ });
84
+ },
85
+ close: () => {
86
+ entry.closed = true;
87
+ for (const row of entry.rows)
88
+ this.cancelRow(row);
89
+ },
90
+ });
91
+ }
92
+ cancelRow(row) {
93
+ if (!row.open)
94
+ return;
95
+ row.open = false;
96
+ row.call = Object.freeze({ ...row.call, status: "cancelled", receipt: Object.freeze({ ...emptyReceipt, reason: "cancelled" }) });
97
+ }
98
+ close() {
99
+ if (this.closed)
100
+ return;
101
+ this.closed = true;
102
+ this.signal?.removeEventListener("abort", this.onAbort);
103
+ for (const entry of this.entries.values())
104
+ entry.closed = true;
105
+ for (const row of this.rows)
106
+ this.cancelRow(row);
107
+ }
108
+ async closeAndDrain() {
109
+ this.close();
110
+ while (this.cleanups.size > 0)
111
+ await Promise.all([...this.cleanups]);
112
+ }
113
+ snapshot() {
114
+ if (!this.closed)
115
+ throw new Error("Judge usage must close before publication");
116
+ const calls = Object.freeze(this.rows.map((row) => row.call));
117
+ return freeze({
118
+ collection: completeCollection,
119
+ calls,
120
+ priceReceipts: (0, judge_call_price_ts_1.createJudgeCallPriceReceipts)(calls, this.pricing),
121
+ });
122
+ }
123
+ trackCleanup(work, deadlineAt) {
124
+ let timer;
125
+ const settled = work.then(() => true, () => false);
126
+ const expired = new Promise((resolve) => { timer = setTimeout(() => resolve(false), Math.max(0, Math.min(1000, deadlineAt - Date.now()))); });
127
+ const bounded = Promise.race([settled, expired]).then((ok) => {
128
+ if (timer !== undefined)
129
+ clearTimeout(timer);
130
+ if (!ok && !this.cleanupIncomplete) {
131
+ this.cleanupIncomplete = true;
132
+ this.onCleanupIncomplete?.();
133
+ }
134
+ });
135
+ this.cleanups.add(bounded);
136
+ void bounded.then(() => this.cleanups.delete(bounded));
137
+ }
138
+ canReserve(next) {
139
+ const rows = [...this.rows, next];
140
+ const terminalCalls = rows.filter((row) => !row.open).map((row) => row.call);
141
+ // Receipt padding bounds canonical bytes; scalar rows additionally bound nodes,
142
+ // keys and depth. Price padding includes both legal 8 KiB model selectors.
143
+ const calls = rows.map((row) => row.open ? {
144
+ ...row.call, entryId: "a".repeat(256), provider: '"'.repeat(256), model: '"'.repeat(8192),
145
+ cost: { amount: "1".repeat(512), currency: "A".repeat(256), source: { kind: "reported", id: '"'.repeat(256) } },
146
+ receipt: { state: "available", reason: "invalid-usage", responseDigest: "0".repeat(71),
147
+ fields: Array.from({ length: 24 }, (_, index) => ({ path: String(index).padEnd(128, "p"), value: null })),
148
+ reservedCanonicalBytes: "x".repeat(32 * 1024) },
149
+ } : row.call);
150
+ const priceReceipts = [...(0, judge_call_price_ts_1.createJudgeCallPriceReceipts)(terminalCalls, this.pricing)];
151
+ if (this.pricing !== undefined)
152
+ for (const row of rows)
153
+ if (row.open)
154
+ priceReceipts.push({
155
+ callId: row.call.callId, requestModel: row.call.requestModel,
156
+ reservedCanonicalBytes: "x".repeat(64 * 1024),
157
+ reservedNodes: Array.from({ length: 256 }, () => ({ value: null })),
158
+ });
159
+ return effect_1.Result.isSuccess((0, canonical_ts_1.canonicalizeRecordValue)({ collection: completeCollection, calls, priceReceipts }, protocol_ts_1.RecordAttachmentEncodingLimits));
160
+ }
161
+ }
162
+ exports.JudgeUsageCollector = JudgeUsageCollector;
163
+ function freeze(value) {
164
+ if (value !== null && typeof value === "object") {
165
+ for (const child of Object.values(value))
166
+ freeze(child);
167
+ Object.freeze(value);
168
+ }
169
+ return value;
170
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,KAAK,CAAC;AACjB,CAAC","sourcesContent":["import { Result, Schema } from \"effect\";\nimport { AssertionEntryIdSchema } from \"../assertions/record/codec.ts\";\nimport { canonicalizeRecordValue } from \"../record/definition/canonical.ts\";\nimport { RecordAttachmentEncodingLimits } from \"../record/attachment/protocol.ts\";\nimport type { JudgeUsageAttachment, JudgeUsageCall } from \"../record/family/judge-usage/schema.ts\";\nimport type { PriceOverride } from \"../runner/types.ts\";\nimport { normalizeJudgeUsageResponse } from \"./judge-usage-receipt.ts\";\nimport { createJudgeCallPriceReceipts } from \"./judge-call-price.ts\";\ntype TransmissionInput = Pick<JudgeUsageCall, \"logicalOrdinal\" | \"transmissionOrdinal\" | \"operation\" | \"requestModel\" | \"transportProvider\">;\nexport interface JudgeUsageTransmission {\n headers(status: number): void;\n body(body: string): void;\n fail(reason: \"response-unavailable\" | \"response-too-large\"): void;\n cancel(): void;\n trackCleanup(work: Promise<unknown>, deadlineAt: number): void;\n}\nexport interface JudgeUsageEntry {\n begin(input: TransmissionInput): JudgeUsageTransmission | undefined;\n close(): void;\n}\ninterface PendingCall {\n call: JudgeUsageCall;\n open: boolean;\n}\nconst placeholderEntryId = Schema.decodeUnknownSync(AssertionEntryIdSchema)(\"ae_00000000000000000000\");\nconst emptyReceipt: JudgeUsageCall[\"receipt\"] = Object.freeze({\n state: \"unavailable\", reason: \"response-unavailable\", responseDigest: null, fields: Object.freeze([]),\n});\nconst completeCollection = Object.freeze({ state: \"complete\" as const, limitations: Object.freeze([] as const) });\n/** One Attempt owns admission, receipt cuts and all transport cleanup promises. */\nexport class JudgeUsageCollector {\n private readonly rows: PendingCall[] = [];\n private readonly entries = new Map<number, {\n closed: boolean;\n rows: PendingCall[];\n }>();\n private readonly cleanups = new Set<Promise<void>>();\n private closed = false;\n private cleanupIncomplete = false;\n private readonly pricing: Readonly<Record<string, PriceOverride>> | undefined;\n private readonly onAbort = () => this.close();\n constructor(pricing: Readonly<Record<string, PriceOverride>> | undefined, private readonly signal?: AbortSignal, private readonly onCleanupIncomplete?: () => void) {\n this.pricing = pricing === undefined ? undefined : freeze(structuredClone(pricing));\n signal?.addEventListener(\"abort\", this.onAbort, { once: true });\n if (signal?.aborted)\n this.close();\n }\n forEntry(entryIndex: number): JudgeUsageEntry {\n const previous = this.entries.get(entryIndex);\n if (!Number.isSafeInteger(entryIndex) || entryIndex < 0 || (previous !== undefined && previous.rows.length > 0)) {\n throw new Error(\"Judge usage requires one capability per Assertion entry\");\n }\n if (previous !== undefined)\n previous.closed = true;\n const entry = { closed: this.closed, rows: [] as PendingCall[] };\n this.entries.set(entryIndex, entry);\n return Object.freeze({\n begin: (input: TransmissionInput) => {\n if (this.closed || entry.closed || this.signal?.aborted || this.rows.length >= 4000)\n return undefined;\n const call: JudgeUsageCall = Object.freeze({\n ...input, entryIndex, entryId: placeholderEntryId,\n callId: `judge:${entryIndex}:${input.logicalOrdinal}:${input.transmissionOrdinal}`,\n provider: null, model: null, status: \"unknown\", httpStatus: null,\n inputTokens: null, inputTotalTokens: null, outputTokens: null, cacheReadTokens: null, cacheWriteTokens: null,\n cost: null, receipt: emptyReceipt,\n });\n if (this.rows.some((row) => row.call.callId === call.callId))\n throw new Error(\"Duplicate Judge physical call identity\");\n const row: PendingCall = { call, open: true };\n if (!this.canReserve(row))\n return undefined;\n this.rows.push(row);\n entry.rows.push(row);\n const terminal = (status: JudgeUsageCall[\"status\"], reason: JudgeUsageCall[\"receipt\"][\"reason\"]): void => {\n if (!row.open)\n return;\n row.open = false;\n row.call = Object.freeze({ ...row.call, status, receipt: Object.freeze({ ...emptyReceipt, reason }) });\n };\n return Object.freeze({\n headers: (status: number) => {\n if (row.open && Number.isInteger(status) && status >= 100 && status <= 599)\n row.call = Object.freeze({ ...row.call, httpStatus: status });\n },\n body: (body: string) => {\n if (!row.open)\n return;\n // No await may separate the receipt cut and its immutable contribution.\n const receipt = normalizeJudgeUsageResponse(input.transportProvider, body);\n row.open = false;\n row.call = freeze({ ...row.call, ...receipt, status: row.call.httpStatus !== null && row.call.httpStatus >= 200 && row.call.httpStatus < 300 ? \"succeeded\" : \"failed\" });\n },\n fail: (reason: \"response-unavailable\" | \"response-too-large\") => terminal(\"failed\", reason),\n cancel: () => terminal(\"cancelled\", \"cancelled\"),\n trackCleanup: (work: Promise<unknown>, deadlineAt: number) => this.trackCleanup(work, deadlineAt),\n });\n },\n close: () => {\n entry.closed = true;\n for (const row of entry.rows)\n this.cancelRow(row);\n },\n });\n }\n private cancelRow(row: PendingCall): void {\n if (!row.open)\n return;\n row.open = false;\n row.call = Object.freeze({ ...row.call, status: \"cancelled\", receipt: Object.freeze({ ...emptyReceipt, reason: \"cancelled\" }) });\n }\n close(): void {\n if (this.closed)\n return;\n this.closed = true;\n this.signal?.removeEventListener(\"abort\", this.onAbort);\n for (const entry of this.entries.values())\n entry.closed = true;\n for (const row of this.rows)\n this.cancelRow(row);\n }\n async closeAndDrain(): Promise<void> {\n this.close();\n while (this.cleanups.size > 0)\n await Promise.all([...this.cleanups]);\n }\n snapshot(): JudgeUsageAttachment {\n if (!this.closed)\n throw new Error(\"Judge usage must close before publication\");\n const calls = Object.freeze(this.rows.map((row) => row.call));\n return freeze({\n collection: completeCollection,\n calls,\n priceReceipts: createJudgeCallPriceReceipts(calls, this.pricing),\n });\n }\n private trackCleanup(work: Promise<unknown>, deadlineAt: number): void {\n let timer: ReturnType<typeof setTimeout> | undefined;\n const settled = work.then(() => true, () => false);\n const expired = new Promise<false>((resolve) => { timer = setTimeout(() => resolve(false), Math.max(0, Math.min(1000, deadlineAt - Date.now()))); });\n const bounded = Promise.race([settled, expired]).then((ok) => {\n if (timer !== undefined)\n clearTimeout(timer);\n if (!ok && !this.cleanupIncomplete) {\n this.cleanupIncomplete = true;\n this.onCleanupIncomplete?.();\n }\n });\n this.cleanups.add(bounded);\n void bounded.then(() => this.cleanups.delete(bounded));\n }\n private canReserve(next: PendingCall): boolean {\n const rows = [...this.rows, next];\n const terminalCalls = rows.filter((row) => !row.open).map((row) => row.call);\n // Receipt padding bounds canonical bytes; scalar rows additionally bound nodes,\n // keys and depth. Price padding includes both legal 8 KiB model selectors.\n const calls = rows.map((row) => row.open ? {\n ...row.call, entryId: \"a\".repeat(256), provider: '\"'.repeat(256), model: '\"'.repeat(8192),\n cost: { amount: \"1\".repeat(512), currency: \"A\".repeat(256), source: { kind: \"reported\", id: '\"'.repeat(256) } },\n receipt: { state: \"available\", reason: \"invalid-usage\", responseDigest: \"0\".repeat(71),\n fields: Array.from({ length: 24 }, (_, index) => ({ path: String(index).padEnd(128, \"p\"), value: null })),\n reservedCanonicalBytes: \"x\".repeat(32 * 1024) },\n } : row.call);\n const priceReceipts: unknown[] = [...createJudgeCallPriceReceipts(terminalCalls, this.pricing)];\n if (this.pricing !== undefined)\n for (const row of rows)\n if (row.open)\n priceReceipts.push({\n callId: row.call.callId, requestModel: row.call.requestModel,\n reservedCanonicalBytes: \"x\".repeat(64 * 1024),\n reservedNodes: Array.from({ length: 256 }, () => ({ value: null })),\n });\n return Result.isSuccess(canonicalizeRecordValue({ collection: completeCollection, calls, priceReceipts }, RecordAttachmentEncodingLimits));\n }\n}\nfunction freeze<T>(value: T): T {\n if (value !== null && typeof value === \"object\") {\n for (const child of Object.values(value))\n freeze(child);\n Object.freeze(value);\n }\n return value;\n}\n"]}
@@ -0,0 +1,35 @@
1
+ import type { JudgeUsageAttachment, JudgeUsageCall } from "../record/family/judge-usage/schema.cjs";
2
+ import type { PriceOverride } from "../runner/types.cjs";
3
+ type TransmissionInput = Pick<JudgeUsageCall, "logicalOrdinal" | "transmissionOrdinal" | "operation" | "requestModel" | "transportProvider">;
4
+ export interface JudgeUsageTransmission {
5
+ headers(status: number): void;
6
+ body(body: string): void;
7
+ fail(reason: "response-unavailable" | "response-too-large"): void;
8
+ cancel(): void;
9
+ trackCleanup(work: Promise<unknown>, deadlineAt: number): void;
10
+ }
11
+ export interface JudgeUsageEntry {
12
+ begin(input: TransmissionInput): JudgeUsageTransmission | undefined;
13
+ close(): void;
14
+ }
15
+ /** One Attempt owns admission, receipt cuts and all transport cleanup promises. */
16
+ export declare class JudgeUsageCollector {
17
+ private readonly signal?;
18
+ private readonly onCleanupIncomplete?;
19
+ private readonly rows;
20
+ private readonly entries;
21
+ private readonly cleanups;
22
+ private closed;
23
+ private cleanupIncomplete;
24
+ private readonly pricing;
25
+ private readonly onAbort;
26
+ constructor(pricing: Readonly<Record<string, PriceOverride>> | undefined, signal?: AbortSignal | undefined, onCleanupIncomplete?: (() => void) | undefined);
27
+ forEntry(entryIndex: number): JudgeUsageEntry;
28
+ private cancelRow;
29
+ close(): void;
30
+ closeAndDrain(): Promise<void>;
31
+ snapshot(): JudgeUsageAttachment;
32
+ private trackCleanup;
33
+ private canReserve;
34
+ }
35
+ export {};
@@ -0,0 +1,35 @@
1
+ import type { JudgeUsageAttachment, JudgeUsageCall } from "../record/family/judge-usage/schema.mjs";
2
+ import type { PriceOverride } from "../runner/types.mjs";
3
+ type TransmissionInput = Pick<JudgeUsageCall, "logicalOrdinal" | "transmissionOrdinal" | "operation" | "requestModel" | "transportProvider">;
4
+ export interface JudgeUsageTransmission {
5
+ headers(status: number): void;
6
+ body(body: string): void;
7
+ fail(reason: "response-unavailable" | "response-too-large"): void;
8
+ cancel(): void;
9
+ trackCleanup(work: Promise<unknown>, deadlineAt: number): void;
10
+ }
11
+ export interface JudgeUsageEntry {
12
+ begin(input: TransmissionInput): JudgeUsageTransmission | undefined;
13
+ close(): void;
14
+ }
15
+ /** One Attempt owns admission, receipt cuts and all transport cleanup promises. */
16
+ export declare class JudgeUsageCollector {
17
+ private readonly signal?;
18
+ private readonly onCleanupIncomplete?;
19
+ private readonly rows;
20
+ private readonly entries;
21
+ private readonly cleanups;
22
+ private closed;
23
+ private cleanupIncomplete;
24
+ private readonly pricing;
25
+ private readonly onAbort;
26
+ constructor(pricing: Readonly<Record<string, PriceOverride>> | undefined, signal?: AbortSignal | undefined, onCleanupIncomplete?: (() => void) | undefined);
27
+ forEntry(entryIndex: number): JudgeUsageEntry;
28
+ private cancelRow;
29
+ close(): void;
30
+ closeAndDrain(): Promise<void>;
31
+ snapshot(): JudgeUsageAttachment;
32
+ private trackCleanup;
33
+ private canReserve;
34
+ }
35
+ export {};
@@ -0,0 +1,35 @@
1
+ import type { JudgeUsageAttachment, JudgeUsageCall } from "../record/family/judge-usage/schema.js";
2
+ import type { PriceOverride } from "../runner/types.js";
3
+ type TransmissionInput = Pick<JudgeUsageCall, "logicalOrdinal" | "transmissionOrdinal" | "operation" | "requestModel" | "transportProvider">;
4
+ export interface JudgeUsageTransmission {
5
+ headers(status: number): void;
6
+ body(body: string): void;
7
+ fail(reason: "response-unavailable" | "response-too-large"): void;
8
+ cancel(): void;
9
+ trackCleanup(work: Promise<unknown>, deadlineAt: number): void;
10
+ }
11
+ export interface JudgeUsageEntry {
12
+ begin(input: TransmissionInput): JudgeUsageTransmission | undefined;
13
+ close(): void;
14
+ }
15
+ /** One Attempt owns admission, receipt cuts and all transport cleanup promises. */
16
+ export declare class JudgeUsageCollector {
17
+ private readonly signal?;
18
+ private readonly onCleanupIncomplete?;
19
+ private readonly rows;
20
+ private readonly entries;
21
+ private readonly cleanups;
22
+ private closed;
23
+ private cleanupIncomplete;
24
+ private readonly pricing;
25
+ private readonly onAbort;
26
+ constructor(pricing: Readonly<Record<string, PriceOverride>> | undefined, signal?: AbortSignal | undefined, onCleanupIncomplete?: (() => void) | undefined);
27
+ forEntry(entryIndex: number): JudgeUsageEntry;
28
+ private cancelRow;
29
+ close(): void;
30
+ closeAndDrain(): Promise<void>;
31
+ snapshot(): JudgeUsageAttachment;
32
+ private trackCleanup;
33
+ private canReserve;
34
+ }
35
+ export {};
@@ -0,0 +1,6 @@
1
+ import { createRequire as __niceevalCreateRequire } from "node:module";
2
+ const __niceevalRequire = __niceevalCreateRequire(import.meta.url);
3
+ const __niceevalCanonical = __niceevalRequire("./judge-usage.cjs");
4
+ const __niceevalExport0 = __niceevalCanonical["JudgeUsageCollector"];
5
+ export { __niceevalExport0 as JudgeUsageCollector };
6
+ //# sourceMappingURL=judge-usage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"judge-usage.js","sources":[],"names":[],"mappings":""}
@@ -85,6 +85,8 @@ const SANDBOX_ONLY_HOST_FRAGMENT = Object.freeze({
85
85
  identity: Object.freeze({}),
86
86
  hostDeclared: false,
87
87
  });
88
+ // @concord-code ne-surface-define-plugin
89
+ // @concord-implements docs/feature/plugins/library.md
88
90
  function definePlugin(definition) {
89
91
  if (!isPlainRecord(definition))
90
92
  throw new TypeError("definePlugin requires an object.");