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
@@ -1,3 +1,4 @@
1
+ import type { ResolvedModelSlots } from "../model-slots.cjs";
1
2
  import type { AgentTurnsAttachment } from "../record/family/agent-turns/schema.cjs";
2
3
  import type { PersistedContentMetadata, SealedAttachmentMetadata } from "../record/sqlite/index.cjs";
3
4
  import { type InspectionJson } from "./codec.cjs";
@@ -8,7 +9,10 @@ export interface TraceAttachmentInput {
8
9
  readonly value: InspectionJson;
9
10
  }
10
11
  export interface AttemptTraceAttachments {
12
+ /** Only the sealed origin Run's configuration may validate or describe these calls. */
13
+ readonly models?: ResolvedModelSlots;
11
14
  readonly adapterUsage?: TraceAttachmentInput;
15
+ readonly judgeUsage?: TraceAttachmentInput;
12
16
  readonly agentTurns?: TraceAttachmentInput;
13
17
  readonly turnContexts?: TraceAttachmentInput;
14
18
  readonly sandboxCommands?: TraceAttachmentInput;
@@ -42,6 +46,7 @@ export declare function projectAttemptTrace(source: InspectionFactSource, attach
42
46
  readonly traceId?: string;
43
47
  readonly sourceId?: string;
44
48
  readonly actorId?: string;
49
+ readonly eventType?: string;
45
50
  readonly continuation?: string;
46
51
  }): InspectionTraceResult;
47
52
  /**
@@ -51,8 +56,8 @@ export declare function projectAttemptTrace(source: InspectionFactSource, attach
51
56
  */
52
57
  export declare function projectAttemptTraceDetail(source: InspectionFactSource, attachments: AttemptTraceAttachments, selector: AttemptTraceDetailSelector): InspectionTraceDetailResult | undefined;
53
58
  export declare function readInspectionAgentTurns(attachment?: TraceAttachmentInput): InspectionAgentTurnsRead;
54
- export declare function projectAttemptUsage(attachments: AttemptTraceAttachments): InspectionAttemptUsageResult;
55
- export declare function projectAdapterUsageTokens(attachment: TraceAttachmentInput): {
59
+ export declare function projectAttemptUsage(attachments: AttemptTraceAttachments, models?: ResolvedModelSlots | undefined): InspectionAttemptUsageResult;
60
+ export declare function projectAdapterUsageTokens(attachment: TraceAttachmentInput, models?: ResolvedModelSlots): {
56
61
  readonly value: number | null;
57
62
  readonly state: "available" | "partial" | "unavailable" | "failed";
58
63
  };
@@ -1,3 +1,4 @@
1
+ import type { ResolvedModelSlots } from "../model-slots.mjs";
1
2
  import type { AgentTurnsAttachment } from "../record/family/agent-turns/schema.mjs";
2
3
  import type { PersistedContentMetadata, SealedAttachmentMetadata } from "../record/sqlite/index.mjs";
3
4
  import { type InspectionJson } from "./codec.mjs";
@@ -8,7 +9,10 @@ export interface TraceAttachmentInput {
8
9
  readonly value: InspectionJson;
9
10
  }
10
11
  export interface AttemptTraceAttachments {
12
+ /** Only the sealed origin Run's configuration may validate or describe these calls. */
13
+ readonly models?: ResolvedModelSlots;
11
14
  readonly adapterUsage?: TraceAttachmentInput;
15
+ readonly judgeUsage?: TraceAttachmentInput;
12
16
  readonly agentTurns?: TraceAttachmentInput;
13
17
  readonly turnContexts?: TraceAttachmentInput;
14
18
  readonly sandboxCommands?: TraceAttachmentInput;
@@ -42,6 +46,7 @@ export declare function projectAttemptTrace(source: InspectionFactSource, attach
42
46
  readonly traceId?: string;
43
47
  readonly sourceId?: string;
44
48
  readonly actorId?: string;
49
+ readonly eventType?: string;
45
50
  readonly continuation?: string;
46
51
  }): InspectionTraceResult;
47
52
  /**
@@ -51,8 +56,8 @@ export declare function projectAttemptTrace(source: InspectionFactSource, attach
51
56
  */
52
57
  export declare function projectAttemptTraceDetail(source: InspectionFactSource, attachments: AttemptTraceAttachments, selector: AttemptTraceDetailSelector): InspectionTraceDetailResult | undefined;
53
58
  export declare function readInspectionAgentTurns(attachment?: TraceAttachmentInput): InspectionAgentTurnsRead;
54
- export declare function projectAttemptUsage(attachments: AttemptTraceAttachments): InspectionAttemptUsageResult;
55
- export declare function projectAdapterUsageTokens(attachment: TraceAttachmentInput): {
59
+ export declare function projectAttemptUsage(attachments: AttemptTraceAttachments, models?: ResolvedModelSlots | undefined): InspectionAttemptUsageResult;
60
+ export declare function projectAdapterUsageTokens(attachment: TraceAttachmentInput, models?: ResolvedModelSlots): {
56
61
  readonly value: number | null;
57
62
  readonly state: "available" | "partial" | "unavailable" | "failed";
58
63
  };
@@ -1,3 +1,4 @@
1
+ import type { ResolvedModelSlots } from "../model-slots.js";
1
2
  import type { AgentTurnsAttachment } from "../record/family/agent-turns/schema.js";
2
3
  import type { PersistedContentMetadata, SealedAttachmentMetadata } from "../record/sqlite/index.js";
3
4
  import { type InspectionJson } from "./codec.js";
@@ -8,7 +9,10 @@ export interface TraceAttachmentInput {
8
9
  readonly value: InspectionJson;
9
10
  }
10
11
  export interface AttemptTraceAttachments {
12
+ /** Only the sealed origin Run's configuration may validate or describe these calls. */
13
+ readonly models?: ResolvedModelSlots;
11
14
  readonly adapterUsage?: TraceAttachmentInput;
15
+ readonly judgeUsage?: TraceAttachmentInput;
12
16
  readonly agentTurns?: TraceAttachmentInput;
13
17
  readonly turnContexts?: TraceAttachmentInput;
14
18
  readonly sandboxCommands?: TraceAttachmentInput;
@@ -42,6 +46,7 @@ export declare function projectAttemptTrace(source: InspectionFactSource, attach
42
46
  readonly traceId?: string;
43
47
  readonly sourceId?: string;
44
48
  readonly actorId?: string;
49
+ readonly eventType?: string;
45
50
  readonly continuation?: string;
46
51
  }): InspectionTraceResult;
47
52
  /**
@@ -51,8 +56,8 @@ export declare function projectAttemptTrace(source: InspectionFactSource, attach
51
56
  */
52
57
  export declare function projectAttemptTraceDetail(source: InspectionFactSource, attachments: AttemptTraceAttachments, selector: AttemptTraceDetailSelector): InspectionTraceDetailResult | undefined;
53
58
  export declare function readInspectionAgentTurns(attachment?: TraceAttachmentInput): InspectionAgentTurnsRead;
54
- export declare function projectAttemptUsage(attachments: AttemptTraceAttachments): InspectionAttemptUsageResult;
55
- export declare function projectAdapterUsageTokens(attachment: TraceAttachmentInput): {
59
+ export declare function projectAttemptUsage(attachments: AttemptTraceAttachments, models?: ResolvedModelSlots | undefined): InspectionAttemptUsageResult;
60
+ export declare function projectAdapterUsageTokens(attachment: TraceAttachmentInput, models?: ResolvedModelSlots): {
56
61
  readonly value: number | null;
57
62
  readonly state: "available" | "partial" | "unavailable" | "failed";
58
63
  };
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ResolvedModelSlotsSchema = void 0;
4
+ exports.normalizeModelSlots = normalizeModelSlots;
5
+ const effect_1 = require("effect");
6
+ const modelText = effect_1.Schema.String.check(effect_1.Schema.isPattern(/\S/u));
7
+ const slotKey = effect_1.Schema.String.check(effect_1.Schema.isPattern(/^[A-Za-z][A-Za-z0-9_-]{0,63}$(?![\s\S])/u));
8
+ const selections = effect_1.Schema.Record(slotKey, effect_1.Schema.Struct({
9
+ model: modelText,
10
+ reasoningEffort: effect_1.Schema.optionalKey(modelText),
11
+ })).check(effect_1.Schema.makeFilter((value) => Object.keys(value).length > 0 && Object.keys(value).length <= 64));
12
+ exports.ResolvedModelSlotsSchema = effect_1.Schema.Record(slotKey, effect_1.Schema.Struct({
13
+ model: effect_1.Schema.NullOr(modelText),
14
+ reasoningEffort: effect_1.Schema.NullOr(modelText),
15
+ })).check(effect_1.Schema.makeFilter((value) => Object.keys(value).length <= 64));
16
+ /** Only the definition boundary interprets author syntax. Downstream owners pass this value through. */
17
+ function normalizeModelSlots(input) {
18
+ if (input.models !== undefined) {
19
+ if (input.model !== undefined || input.reasoningEffort !== undefined) {
20
+ throw new TypeError("Experiment models cannot be combined with model or reasoningEffort.");
21
+ }
22
+ const decoded = effect_1.Schema.decodeUnknownSync(selections, { onExcessProperty: "error" })(input.models);
23
+ return Object.freeze(Object.fromEntries(Object.keys(decoded).sort().map((key) => {
24
+ const value = decoded[key];
25
+ return [key, Object.freeze({ model: value.model, reasoningEffort: value.reasoningEffort ?? null })];
26
+ })));
27
+ }
28
+ if (input.model === undefined && input.reasoningEffort === undefined)
29
+ return Object.freeze({});
30
+ return Object.freeze({ default: Object.freeze({
31
+ model: input.model === undefined ? null : effect_1.Schema.decodeUnknownSync(modelText)(input.model),
32
+ reasoningEffort: input.reasoningEffort === undefined ? null : effect_1.Schema.decodeUnknownSync(modelText)(input.reasoningEffort),
33
+ }) });
34
+ }
35
+ //# sourceMappingURL=model-slots.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model-slots.js","sourceRoot":"","sources":["model-slots.ts"],"names":[],"mappings":";;;AAuBA,kDAqBC;AA5CD,mCAAgC;AAYhC,MAAM,SAAS,GAAG,eAAM,CAAC,MAAM,CAAC,KAAK,CAAC,eAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;AAC/D,MAAM,OAAO,GAAG,eAAM,CAAC,MAAM,CAAC,KAAK,CAAC,eAAM,CAAC,SAAS,CAAC,0CAA0C,CAAC,CAAC,CAAC;AAClG,MAAM,UAAU,GAAG,eAAM,CAAC,MAAM,CAAC,OAAO,EAAE,eAAM,CAAC,MAAM,CAAC;IACpD,KAAK,EAAE,SAAS;IAChB,eAAe,EAAE,eAAM,CAAC,WAAW,CAAC,SAAS,CAAC;CACjD,CAAC,CAAC,CAAC,KAAK,CAAC,eAAM,CAAC,UAAU,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,GAAG,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,CAAC;AAC7F,QAAA,wBAAwB,GAAqC,eAAM,CAAC,MAAM,CAAC,OAAO,EAAE,eAAM,CAAC,MAAM,CAAC;IAC3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O,MAAM,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC;YACtC,KAAK,EAAE,KAAK,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,eAAM,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC;YAC1F,eAAe,EAAE,KAAK,CAAC,eAAe,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,eAAM,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,eAAe,CAAC;SAC3H,CAAC,EAAE,CAAC,CAAC;AACd,CAAC","sourcesContent":["import { Schema } from \"effect\";\n/** A model selected for one application-defined purpose. */\nexport interface ModelSlotSelection {\n readonly model: string;\n readonly reasoningEffort?: string;\n}\n/** Frozen selection; null preserves an unspecified native default. */\nexport interface ResolvedModelSlot {\n readonly model: string | null;\n readonly reasoningEffort: string | null;\n}\nexport type ResolvedModelSlots = Readonly<Record<string, ResolvedModelSlot>>;\nconst modelText = Schema.String.check(Schema.isPattern(/\\S/u));\nconst slotKey = Schema.String.check(Schema.isPattern(/^[A-Za-z][A-Za-z0-9_-]{0,63}$(?![\\s\\S])/u));\nconst selections = Schema.Record(slotKey, Schema.Struct({\n model: modelText,\n reasoningEffort: Schema.optionalKey(modelText),\n})).check(Schema.makeFilter((value) => Object.keys(value).length > 0 && Object.keys(value).length <= 64));\nexport const ResolvedModelSlotsSchema: Schema.Codec<ResolvedModelSlots> = Schema.Record(slotKey, Schema.Struct({\n model: Schema.NullOr(modelText),\n reasoningEffort: Schema.NullOr(modelText),\n})).check(Schema.makeFilter((value) => Object.keys(value).length <= 64));\n/** Only the definition boundary interprets author syntax. Downstream owners pass this value through. */\nexport function normalizeModelSlots(input: {\n readonly model?: string;\n readonly reasoningEffort?: string;\n readonly models?: Readonly<Record<string, ModelSlotSelection>>;\n}): ResolvedModelSlots {\n if (input.models !== undefined) {\n if (input.model !== undefined || input.reasoningEffort !== undefined) {\n throw new TypeError(\"Experiment models cannot be combined with model or reasoningEffort.\");\n }\n const decoded = Schema.decodeUnknownSync(selections, { onExcessProperty: \"error\" })(input.models);\n return Object.freeze(Object.fromEntries(Object.keys(decoded).sort().map((key) => {\n const value = decoded[key]!;\n return [key, Object.freeze({ model: value.model, reasoningEffort: value.reasoningEffort ?? null })];\n })));\n }\n if (input.model === undefined && input.reasoningEffort === undefined)\n return Object.freeze({});\n return Object.freeze({ default: Object.freeze({\n model: input.model === undefined ? null : Schema.decodeUnknownSync(modelText)(input.model),\n reasoningEffort: input.reasoningEffort === undefined ? null : Schema.decodeUnknownSync(modelText)(input.reasoningEffort),\n }) });\n}\n"]}
@@ -0,0 +1,19 @@
1
+ import { Schema } from "effect";
2
+ /** A model selected for one application-defined purpose. */
3
+ export interface ModelSlotSelection {
4
+ readonly model: string;
5
+ readonly reasoningEffort?: string;
6
+ }
7
+ /** Frozen selection; null preserves an unspecified native default. */
8
+ export interface ResolvedModelSlot {
9
+ readonly model: string | null;
10
+ readonly reasoningEffort: string | null;
11
+ }
12
+ export type ResolvedModelSlots = Readonly<Record<string, ResolvedModelSlot>>;
13
+ export declare const ResolvedModelSlotsSchema: Schema.Codec<ResolvedModelSlots>;
14
+ /** Only the definition boundary interprets author syntax. Downstream owners pass this value through. */
15
+ export declare function normalizeModelSlots(input: {
16
+ readonly model?: string;
17
+ readonly reasoningEffort?: string;
18
+ readonly models?: Readonly<Record<string, ModelSlotSelection>>;
19
+ }): ResolvedModelSlots;
@@ -0,0 +1,19 @@
1
+ import { Schema } from "effect";
2
+ /** A model selected for one application-defined purpose. */
3
+ export interface ModelSlotSelection {
4
+ readonly model: string;
5
+ readonly reasoningEffort?: string;
6
+ }
7
+ /** Frozen selection; null preserves an unspecified native default. */
8
+ export interface ResolvedModelSlot {
9
+ readonly model: string | null;
10
+ readonly reasoningEffort: string | null;
11
+ }
12
+ export type ResolvedModelSlots = Readonly<Record<string, ResolvedModelSlot>>;
13
+ export declare const ResolvedModelSlotsSchema: Schema.Codec<ResolvedModelSlots>;
14
+ /** Only the definition boundary interprets author syntax. Downstream owners pass this value through. */
15
+ export declare function normalizeModelSlots(input: {
16
+ readonly model?: string;
17
+ readonly reasoningEffort?: string;
18
+ readonly models?: Readonly<Record<string, ModelSlotSelection>>;
19
+ }): ResolvedModelSlots;
@@ -0,0 +1,19 @@
1
+ import { Schema } from "effect";
2
+ /** A model selected for one application-defined purpose. */
3
+ export interface ModelSlotSelection {
4
+ readonly model: string;
5
+ readonly reasoningEffort?: string;
6
+ }
7
+ /** Frozen selection; null preserves an unspecified native default. */
8
+ export interface ResolvedModelSlot {
9
+ readonly model: string | null;
10
+ readonly reasoningEffort: string | null;
11
+ }
12
+ export type ResolvedModelSlots = Readonly<Record<string, ResolvedModelSlot>>;
13
+ export declare const ResolvedModelSlotsSchema: Schema.Codec<ResolvedModelSlots>;
14
+ /** Only the definition boundary interprets author syntax. Downstream owners pass this value through. */
15
+ export declare function normalizeModelSlots(input: {
16
+ readonly model?: string;
17
+ readonly reasoningEffort?: string;
18
+ readonly models?: Readonly<Record<string, ModelSlotSelection>>;
19
+ }): ResolvedModelSlots;
@@ -0,0 +1,8 @@
1
+ import { createRequire as __niceevalCreateRequire } from "node:module";
2
+ const __niceevalRequire = __niceevalCreateRequire(import.meta.url);
3
+ const __niceevalCanonical = __niceevalRequire("./model-slots.cjs");
4
+ const __niceevalExport0 = __niceevalCanonical["ResolvedModelSlotsSchema"];
5
+ export { __niceevalExport0 as ResolvedModelSlotsSchema };
6
+ const __niceevalExport1 = __niceevalCanonical["normalizeModelSlots"];
7
+ export { __niceevalExport1 as normalizeModelSlots };
8
+ //# sourceMappingURL=model-slots.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model-slots.js","sources":[],"names":[],"mappings":""}
@@ -1,5 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.configuredProfile = configuredProfile;
4
+ exports.rateFor = rateFor;
3
5
  exports.createAdapterCallPriceReceipts = createAdapterCallPriceReceipts;
4
6
  const effect_1 = require("effect");
5
7
  const schema_ts_1 = require("../record/family/adapter-usage/schema.cjs");
@@ -9,6 +11,7 @@ const core_ts_1 = require("../record/codec/core.cjs");
9
11
  * durable receipt schema before publication so type assertions cannot hide drift.
10
12
  */
11
13
  const pricing_ts_1 = require("../record/family/adapter-usage/pricing.cjs");
14
+ /** @internal Shared configured-price selection; it never consults the builtin catalog. */
12
15
  function configuredProfile(model, overrides) {
13
16
  if (overrides === undefined)
14
17
  return undefined;
@@ -57,6 +60,7 @@ function tokensFor(call, bucket) {
57
60
  case "cache-write": return call.cacheWriteTokens;
58
61
  }
59
62
  }
63
+ /** @internal Shared rates for the four mutually exclusive token buckets. */
60
64
  function rateFor(profile, bucket) {
61
65
  switch (bucket) {
62
66
  case "input": return profile.ratesPerMTok.input;
@@ -1 +1 @@
1
- {"version":3,"file":"adapter-call-price.js","sourceRoot":"","sources":["adapter-call-price.ts"],"names":[],"mappings":";;AAmJA,wEAKC;AAxJD,mCAAwC;AAExC,wEAA+I;AAC/I,qDAAkE;AAClE;;;GAGG;AACH,0EAA4M;AAmB5M,SAAS,iBAAiB,CAAC,KAAa,EAAE,SAA8D;IACpG,IAAI,SAAS,KAAK,SAAS;QACvB,OAAO,SAAS,CAAC;IACrB,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;IAC7F,MAAM,QAAQ,GAAG,SAAS,CAAC,KAAK,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK;QACnD,CAAC,CAAC,QAAQ,KAAK,SAAS,IAAI,SAAS,CAAC,QAAQ,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,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O;QACP,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC;QAC/B,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC;KAClC,CAAC,CAAC;IACH,IAAI,eAAM,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;IACvE,CAAC;IACD,OAAO,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;AAC1C,CAAC;AACD,SAAgB,8BAA8B,CAAC,KAAkC,EAAE,SAA8D;IAC7I,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QACxC,MAAM,OAAO,GAAG,UAAU,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;QAC5C,OAAO,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;IAClD,CAAC,CAAC,CAAC,CAAC;AACR,CAAC","sourcesContent":["import { Result, Schema } from \"effect\";\nimport type { PriceOverride } from \"../runner/types.ts\";\nimport { AdapterCallPriceReceiptSchema, type AdapterCallPriceReceipt, type AdapterUsageCall, } from \"../record/family/adapter-usage/schema.ts\";\nimport { RecordExactParseOptions } from \"../record/codec/core.ts\";\n/*\n * This estimator is independent of Runner maxCost. Its output is decoded by the\n * durable receipt schema before publication so type assertions cannot hide drift.\n */\nimport { AdapterCallPriceBuckets, adapterCallPricingProfileDigest, addCanonicalDecimals, canonicalDecimalFromNumber, multiplyCanonicalDecimalPerMillion, } from \"../record/family/adapter-usage/pricing.ts\";\ninterface SelectedProfile {\n readonly basis: \"catalog-reference\";\n readonly currency: \"USD\";\n readonly source: {\n readonly kind: \"configured-profile\";\n readonly id: string;\n readonly asOf: number | null;\n };\n readonly requestModel: string;\n readonly selector: string;\n readonly match: \"exact\" | \"provider-wildcard\";\n readonly ratesPerMTok: {\n readonly input: string;\n readonly output: string;\n readonly cacheRead: string | null;\n readonly cacheWrite: string | null;\n };\n}\nfunction configuredProfile(model: string, overrides: Readonly<Record<string, PriceOverride>> | undefined): SelectedProfile | undefined {\n if (overrides === undefined)\n return undefined;\n const wildcard = model.includes(\"/\") ? `${model.slice(0, model.indexOf(\"/\"))}/*` : undefined;\n const selector = overrides[model] !== undefined ? model\n : wildcard !== undefined && overrides[wildcard] !== undefined ? wildcard\n : undefined;\n if (selector === undefined)\n return undefined;\n const value = overrides[selector]!;\n if (value.basis !== undefined && value.basis !== \"catalog-reference\" ||\n value.currency !== undefined && value.currency !== \"USD\")\n return undefined;\n const sourceId = value.source?.id ?? \"niceeval.config.pricing\";\n const asOf = value.source?.asOf ?? null;\n const input = canonicalDecimalFromNumber(value.inputPerMTok);\n const output = canonicalDecimalFromNumber(value.outputPerMTok);\n if (input === undefined || output === undefined || sourceId.trim().length === 0 ||\n new TextEncoder().encode(sourceId).byteLength > 256 || /[\\u0000-\\u001f\\u007f]/u.test(sourceId) ||\n asOf !== null && (!Number.isSafeInteger(asOf) || asOf <= 0))\n return undefined;\n return Object.freeze({\n basis: \"catalog-reference\",\n currency: \"USD\",\n source: Object.freeze({ kind: \"configured-profile\", id: sourceId, asOf }),\n requestModel: model,\n selector,\n match: selector === model ? \"exact\" : \"provider-wildcard\",\n ratesPerMTok: Object.freeze({\n input,\n output,\n cacheRead: value.cacheReadPerMTok === undefined\n ? null\n : canonicalDecimalFromNumber(value.cacheReadPerMTok) ?? null,\n cacheWrite: value.cacheWritePerMTok === undefined\n ? null\n : canonicalDecimalFromNumber(value.cacheWritePerMTok) ?? null,\n }),\n });\n}\nfunction tokensFor(call: AdapterUsageCall, bucket: (typeof AdapterCallPriceBuckets)[number]): number | null {\n switch (bucket) {\n case \"input\": return call.inputTokens;\n case \"output\": return call.outputTokens;\n case \"cache-read\": return call.cacheReadTokens;\n case \"cache-write\": return call.cacheWriteTokens;\n }\n}\nfunction rateFor(profile: SelectedProfile, bucket: (typeof AdapterCallPriceBuckets)[number]): string | null {\n switch (bucket) {\n case \"input\": return profile.ratesPerMTok.input;\n case \"output\": return profile.ratesPerMTok.output;\n case \"cache-read\": return profile.ratesPerMTok.cacheRead;\n case \"cache-write\": return profile.ratesPerMTok.cacheWrite;\n }\n}\nfunction receiptFor(call: AdapterUsageCall, overrides: Readonly<Record<string, PriceOverride>> | undefined): AdapterCallPriceReceipt | undefined {\n if (call.cost !== null || call.model === null)\n return undefined;\n // The vendored builtin catalog has no independent flat-applicability proof. It is not used here.\n const selected = configuredProfile(call.model, overrides);\n if (selected === undefined)\n return undefined;\n const digestInput = {\n basis: selected.basis,\n currency: selected.currency,\n source: selected.source,\n requestModel: selected.requestModel,\n selector: selected.selector,\n match: selected.match,\n ratesPerMTok: selected.ratesPerMTok,\n };\n const pricing = Object.freeze({\n ...digestInput,\n source: Object.freeze({\n ...selected.source,\n profileDigest: adapterCallPricingProfileDigest(digestInput),\n }),\n });\n const charges: Array<Record<string, unknown>> = [];\n const missing: Array<Record<string, unknown>> = [];\n for (const bucket of AdapterCallPriceBuckets) {\n const tokens = tokensFor(call, bucket);\n const rate = rateFor(selected, bucket);\n if (tokens === null) {\n missing.push(Object.freeze({ bucket, reason: \"tokens-unknown\" }));\n }\n else if (tokens === 0) {\n charges.push(Object.freeze({ bucket, tokens, ratePerMTok: rate, amount: \"0\" }));\n }\n else if (rate === null) {\n missing.push(Object.freeze({ bucket, reason: \"rate-unknown\" }));\n }\n else {\n charges.push(Object.freeze({\n bucket,\n tokens,\n ratePerMTok: rate,\n amount: multiplyCanonicalDecimalPerMillion(rate, tokens),\n }));\n }\n }\n if (charges.length === 0)\n return undefined;\n const receipt = Schema.decodeUnknownResult(AdapterCallPriceReceiptSchema, RecordExactParseOptions)({\n kind: \"adapter-call-price-estimate\",\n callId: call.callId,\n state: missing.length === 0 ? \"complete\" : \"partial\",\n amount: addCanonicalDecimals(charges.map((charge) => String(charge.amount))),\n currency: \"USD\",\n source: Object.freeze({ kind: \"estimated\", id: selected.source.id }),\n pricing,\n charges: Object.freeze(charges),\n missing: Object.freeze(missing),\n });\n if (Result.isFailure(receipt)) {\n throw new Error(\"Generated Adapter call price receipt is invalid\");\n }\n return Object.freeze(receipt.success);\n}\nexport function createAdapterCallPriceReceipts(calls: readonly AdapterUsageCall[], overrides: Readonly<Record<string, PriceOverride>> | undefined): readonly AdapterCallPriceReceipt[] {\n return Object.freeze(calls.flatMap((call) => {\n const receipt = receiptFor(call, overrides);\n return receipt === undefined ? [] : [receipt];\n }));\n}\n"]}
1
+ {"version":3,"file":"adapter-call-price.js","sourceRoot":"","sources":["adapter-call-price.ts"],"names":[],"mappings":";;AA4BA,8CAuCC;AAUD,0BAOC;AAiED,wEAKC;AA1JD,mCAAwC;AAExC,wEAA+I;AAC/I,qDAAkE;AAClE;;;GAGG;AACH,0EAA4M;AAmB5M,0FAA0F;AAC1F,SAAgB,iBAAiB,CAAC,KAAa,EAAE,SAA8D;IAC3G,IAAI,SAAS,KAAK,SAAS;QACvB,OAAO,SAAS,CAAC;IACrB,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;IAC7F,MAAM,QAAQ,GAAG,SAAS,CAAC,KAAK,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK;QACnD,CAAC,CAAC,QAAQ,KAAK,SAAS,IAAI,SAAS,CAAC,QAAQ,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,QAAQ;YACpE,CAAC,CAAC,SAAS,CAAC;IACpB,IAAI,QAAQ,KAAK,SAAS;QACtB,OAAO,SAAS,CAAC;IACrB,MAAM,KAAK,GAAG,SAAS,CAAC,QAAQ,CAAE,CAAC;IACnC,IAAI,KAAK,CAAC,KAAK,KAAK,SAAS,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AC,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;IACvE,CAAC;IACD,OAAO,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;AAC1C,CAAC;AACD,SAAgB,8BAA8B,CAAC,KAAkC,EAAE,SAA8D;IAC7I,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QACxC,MAAM,OAAO,GAAG,UAAU,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;QAC5C,OAAO,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;IAClD,CAAC,CAAC,CAAC,CAAC;AACR,CAAC","sourcesContent":["import { Result, Schema } from \"effect\";\nimport type { PriceOverride } from \"../runner/types.ts\";\nimport { AdapterCallPriceReceiptSchema, type AdapterCallPriceReceipt, type AdapterUsageCall, } from \"../record/family/adapter-usage/schema.ts\";\nimport { RecordExactParseOptions } from \"../record/codec/core.ts\";\n/*\n * This estimator is independent of Runner maxCost. Its output is decoded by the\n * durable receipt schema before publication so type assertions cannot hide drift.\n */\nimport { AdapterCallPriceBuckets, adapterCallPricingProfileDigest, addCanonicalDecimals, canonicalDecimalFromNumber, multiplyCanonicalDecimalPerMillion, } from \"../record/family/adapter-usage/pricing.ts\";\ninterface SelectedProfile {\n readonly basis: \"catalog-reference\";\n readonly currency: \"USD\";\n readonly source: {\n readonly kind: \"configured-profile\";\n readonly id: string;\n readonly asOf: number | null;\n };\n readonly requestModel: string;\n readonly selector: string;\n readonly match: \"exact\" | \"provider-wildcard\";\n readonly ratesPerMTok: {\n readonly input: string;\n readonly output: string;\n readonly cacheRead: string | null;\n readonly cacheWrite: string | null;\n };\n}\n/** @internal Shared configured-price selection; it never consults the builtin catalog. */\nexport function configuredProfile(model: string, overrides: Readonly<Record<string, PriceOverride>> | undefined): SelectedProfile | undefined {\n if (overrides === undefined)\n return undefined;\n const wildcard = model.includes(\"/\") ? `${model.slice(0, model.indexOf(\"/\"))}/*` : undefined;\n const selector = overrides[model] !== undefined ? model\n : wildcard !== undefined && overrides[wildcard] !== undefined ? wildcard\n : undefined;\n if (selector === undefined)\n return undefined;\n const value = overrides[selector]!;\n if (value.basis !== undefined && value.basis !== \"catalog-reference\" ||\n value.currency !== undefined && value.currency !== \"USD\")\n return undefined;\n const sourceId = value.source?.id ?? \"niceeval.config.pricing\";\n const asOf = value.source?.asOf ?? null;\n const input = canonicalDecimalFromNumber(value.inputPerMTok);\n const output = canonicalDecimalFromNumber(value.outputPerMTok);\n if (input === undefined || output === undefined || sourceId.trim().length === 0 ||\n new TextEncoder().encode(sourceId).byteLength > 256 || /[\\u0000-\\u001f\\u007f]/u.test(sourceId) ||\n asOf !== null && (!Number.isSafeInteger(asOf) || asOf <= 0))\n return undefined;\n return Object.freeze({\n basis: \"catalog-reference\",\n currency: \"USD\",\n source: Object.freeze({ kind: \"configured-profile\", id: sourceId, asOf }),\n requestModel: model,\n selector,\n match: selector === model ? \"exact\" : \"provider-wildcard\",\n ratesPerMTok: Object.freeze({\n input,\n output,\n cacheRead: value.cacheReadPerMTok === undefined\n ? null\n : canonicalDecimalFromNumber(value.cacheReadPerMTok) ?? null,\n cacheWrite: value.cacheWritePerMTok === undefined\n ? null\n : canonicalDecimalFromNumber(value.cacheWritePerMTok) ?? null,\n }),\n });\n}\nfunction tokensFor(call: AdapterUsageCall, bucket: (typeof AdapterCallPriceBuckets)[number]): number | null {\n switch (bucket) {\n case \"input\": return call.inputTokens;\n case \"output\": return call.outputTokens;\n case \"cache-read\": return call.cacheReadTokens;\n case \"cache-write\": return call.cacheWriteTokens;\n }\n}\n/** @internal Shared rates for the four mutually exclusive token buckets. */\nexport function rateFor(profile: SelectedProfile, bucket: (typeof AdapterCallPriceBuckets)[number]): string | null {\n switch (bucket) {\n case \"input\": return profile.ratesPerMTok.input;\n case \"output\": return profile.ratesPerMTok.output;\n case \"cache-read\": return profile.ratesPerMTok.cacheRead;\n case \"cache-write\": return profile.ratesPerMTok.cacheWrite;\n }\n}\nfunction receiptFor(call: AdapterUsageCall, overrides: Readonly<Record<string, PriceOverride>> | undefined): AdapterCallPriceReceipt | undefined {\n if (call.cost !== null || call.model === null)\n return undefined;\n // The vendored builtin catalog has no independent flat-applicability proof. It is not used here.\n const selected = configuredProfile(call.model, overrides);\n if (selected === undefined)\n return undefined;\n const digestInput = {\n basis: selected.basis,\n currency: selected.currency,\n source: selected.source,\n requestModel: selected.requestModel,\n selector: selected.selector,\n match: selected.match,\n ratesPerMTok: selected.ratesPerMTok,\n };\n const pricing = Object.freeze({\n ...digestInput,\n source: Object.freeze({\n ...selected.source,\n profileDigest: adapterCallPricingProfileDigest(digestInput),\n }),\n });\n const charges: Array<Record<string, unknown>> = [];\n const missing: Array<Record<string, unknown>> = [];\n for (const bucket of AdapterCallPriceBuckets) {\n const tokens = tokensFor(call, bucket);\n const rate = rateFor(selected, bucket);\n if (tokens === null) {\n missing.push(Object.freeze({ bucket, reason: \"tokens-unknown\" }));\n }\n else if (tokens === 0) {\n charges.push(Object.freeze({ bucket, tokens, ratePerMTok: rate, amount: \"0\" }));\n }\n else if (rate === null) {\n missing.push(Object.freeze({ bucket, reason: \"rate-unknown\" }));\n }\n else {\n charges.push(Object.freeze({\n bucket,\n tokens,\n ratePerMTok: rate,\n amount: multiplyCanonicalDecimalPerMillion(rate, tokens),\n }));\n }\n }\n if (charges.length === 0)\n return undefined;\n const receipt = Schema.decodeUnknownResult(AdapterCallPriceReceiptSchema, RecordExactParseOptions)({\n kind: \"adapter-call-price-estimate\",\n callId: call.callId,\n state: missing.length === 0 ? \"complete\" : \"partial\",\n amount: addCanonicalDecimals(charges.map((charge) => String(charge.amount))),\n currency: \"USD\",\n source: Object.freeze({ kind: \"estimated\", id: selected.source.id }),\n pricing,\n charges: Object.freeze(charges),\n missing: Object.freeze(missing),\n });\n if (Result.isFailure(receipt)) {\n throw new Error(\"Generated Adapter call price receipt is invalid\");\n }\n return Object.freeze(receipt.success);\n}\nexport function createAdapterCallPriceReceipts(calls: readonly AdapterUsageCall[], overrides: Readonly<Record<string, PriceOverride>> | undefined): readonly AdapterCallPriceReceipt[] {\n return Object.freeze(calls.flatMap((call) => {\n const receipt = receiptFor(call, overrides);\n return receipt === undefined ? [] : [receipt];\n }));\n}\n"]}
@@ -1,3 +1,27 @@
1
1
  import type { PriceOverride } from "../runner/types.cjs";
2
2
  import { type AdapterCallPriceReceipt, type AdapterUsageCall } from "../record/family/adapter-usage/schema.cjs";
3
+ import { AdapterCallPriceBuckets } from "../record/family/adapter-usage/pricing.cjs";
4
+ interface SelectedProfile {
5
+ readonly basis: "catalog-reference";
6
+ readonly currency: "USD";
7
+ readonly source: {
8
+ readonly kind: "configured-profile";
9
+ readonly id: string;
10
+ readonly asOf: number | null;
11
+ };
12
+ readonly requestModel: string;
13
+ readonly selector: string;
14
+ readonly match: "exact" | "provider-wildcard";
15
+ readonly ratesPerMTok: {
16
+ readonly input: string;
17
+ readonly output: string;
18
+ readonly cacheRead: string | null;
19
+ readonly cacheWrite: string | null;
20
+ };
21
+ }
22
+ /** @internal Shared configured-price selection; it never consults the builtin catalog. */
23
+ export declare function configuredProfile(model: string, overrides: Readonly<Record<string, PriceOverride>> | undefined): SelectedProfile | undefined;
24
+ /** @internal Shared rates for the four mutually exclusive token buckets. */
25
+ export declare function rateFor(profile: SelectedProfile, bucket: (typeof AdapterCallPriceBuckets)[number]): string | null;
3
26
  export declare function createAdapterCallPriceReceipts(calls: readonly AdapterUsageCall[], overrides: Readonly<Record<string, PriceOverride>> | undefined): readonly AdapterCallPriceReceipt[];
27
+ export {};
@@ -1,3 +1,27 @@
1
1
  import type { PriceOverride } from "../runner/types.mjs";
2
2
  import { type AdapterCallPriceReceipt, type AdapterUsageCall } from "../record/family/adapter-usage/schema.mjs";
3
+ import { AdapterCallPriceBuckets } from "../record/family/adapter-usage/pricing.mjs";
4
+ interface SelectedProfile {
5
+ readonly basis: "catalog-reference";
6
+ readonly currency: "USD";
7
+ readonly source: {
8
+ readonly kind: "configured-profile";
9
+ readonly id: string;
10
+ readonly asOf: number | null;
11
+ };
12
+ readonly requestModel: string;
13
+ readonly selector: string;
14
+ readonly match: "exact" | "provider-wildcard";
15
+ readonly ratesPerMTok: {
16
+ readonly input: string;
17
+ readonly output: string;
18
+ readonly cacheRead: string | null;
19
+ readonly cacheWrite: string | null;
20
+ };
21
+ }
22
+ /** @internal Shared configured-price selection; it never consults the builtin catalog. */
23
+ export declare function configuredProfile(model: string, overrides: Readonly<Record<string, PriceOverride>> | undefined): SelectedProfile | undefined;
24
+ /** @internal Shared rates for the four mutually exclusive token buckets. */
25
+ export declare function rateFor(profile: SelectedProfile, bucket: (typeof AdapterCallPriceBuckets)[number]): string | null;
3
26
  export declare function createAdapterCallPriceReceipts(calls: readonly AdapterUsageCall[], overrides: Readonly<Record<string, PriceOverride>> | undefined): readonly AdapterCallPriceReceipt[];
27
+ export {};
@@ -1,3 +1,27 @@
1
1
  import type { PriceOverride } from "../runner/types.js";
2
2
  import { type AdapterCallPriceReceipt, type AdapterUsageCall } from "../record/family/adapter-usage/schema.js";
3
+ import { AdapterCallPriceBuckets } from "../record/family/adapter-usage/pricing.js";
4
+ interface SelectedProfile {
5
+ readonly basis: "catalog-reference";
6
+ readonly currency: "USD";
7
+ readonly source: {
8
+ readonly kind: "configured-profile";
9
+ readonly id: string;
10
+ readonly asOf: number | null;
11
+ };
12
+ readonly requestModel: string;
13
+ readonly selector: string;
14
+ readonly match: "exact" | "provider-wildcard";
15
+ readonly ratesPerMTok: {
16
+ readonly input: string;
17
+ readonly output: string;
18
+ readonly cacheRead: string | null;
19
+ readonly cacheWrite: string | null;
20
+ };
21
+ }
22
+ /** @internal Shared configured-price selection; it never consults the builtin catalog. */
23
+ export declare function configuredProfile(model: string, overrides: Readonly<Record<string, PriceOverride>> | undefined): SelectedProfile | undefined;
24
+ /** @internal Shared rates for the four mutually exclusive token buckets. */
25
+ export declare function rateFor(profile: SelectedProfile, bucket: (typeof AdapterCallPriceBuckets)[number]): string | null;
3
26
  export declare function createAdapterCallPriceReceipts(calls: readonly AdapterUsageCall[], overrides: Readonly<Record<string, PriceOverride>> | undefined): readonly AdapterCallPriceReceipt[];
27
+ export {};
@@ -1,6 +1,10 @@
1
1
  import { createRequire as __niceevalCreateRequire } from "node:module";
2
2
  const __niceevalRequire = __niceevalCreateRequire(import.meta.url);
3
3
  const __niceevalCanonical = __niceevalRequire("./adapter-call-price.cjs");
4
- const __niceevalExport0 = __niceevalCanonical["createAdapterCallPriceReceipts"];
5
- export { __niceevalExport0 as createAdapterCallPriceReceipts };
4
+ const __niceevalExport0 = __niceevalCanonical["configuredProfile"];
5
+ export { __niceevalExport0 as configuredProfile };
6
+ const __niceevalExport1 = __niceevalCanonical["createAdapterCallPriceReceipts"];
7
+ export { __niceevalExport1 as createAdapterCallPriceReceipts };
8
+ const __niceevalExport2 = __niceevalCanonical["rateFor"];
9
+ export { __niceevalExport2 as rateFor };
6
10
  //# sourceMappingURL=adapter-call-price.js.map
@@ -0,0 +1,158 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.effectiveUsageCalls = effectiveUsageCalls;
4
+ exports.effectiveCostTotals = effectiveCostTotals;
5
+ exports.adapterTokenMaterial = adapterTokenMaterial;
6
+ exports.adapterInspectionTokenTotal = adapterInspectionTokenTotal;
7
+ exports.compareAdapterModelGroups = compareAdapterModelGroups;
8
+ exports.projectAdapterModelUsage = projectAdapterModelUsage;
9
+ exports.projectAdapterUsageSnapshot = projectAdapterUsageSnapshot;
10
+ exports.compareCanonicalDecimal = compareCanonicalDecimal;
11
+ const pricing_ts_1 = require("../record/family/adapter-usage/pricing.cjs");
12
+ function effectiveUsageCalls(usage) {
13
+ const receipts = new Map((usage.priceReceipts ?? []).map((receipt) => [receipt.callId, receipt]));
14
+ return Object.freeze(usage.calls.map((call) => {
15
+ const receipt = receipts.get(call.callId);
16
+ return Object.freeze({ ...call, effectiveCost: call.cost !== null ? Object.freeze({ ...call.cost, state: "complete" }) : receipt === undefined ? null : Object.freeze({ amount: receipt.amount, currency: receipt.currency, source: receipt.source, state: receipt.state }) });
17
+ }));
18
+ }
19
+ function effectiveCostTotals(calls, collectionState) {
20
+ const known = calls.flatMap((call) => call.effectiveCost === null ? [] : [call.effectiveCost]);
21
+ const kind = (values) => { const sources = new Set(values.map((value) => value.source.kind)); return sources.size === 0 ? null : sources.size === 1 ? [...sources][0] : "mixed"; };
22
+ const grouped = new Map();
23
+ for (const cost of known)
24
+ grouped.set(cost.currency, [...(grouped.get(cost.currency) ?? []), cost]);
25
+ const complete = collectionState === "complete" && known.length === calls.length && known.every((cost) => cost.state === "complete");
26
+ return Object.freeze({ state: known.length === 0 ? "unavailable" : complete ? "complete" : "partial", source: kind(known), values: Object.freeze([...grouped.entries()].sort(([left], [right]) => left.localeCompare(right)).map(([currency, values]) => Object.freeze({ currency, value: (0, pricing_ts_1.addCanonicalDecimals)(values.map((value) => value.amount)), source: kind(values), coveredCalls: values.filter((value) => value.state === "complete").length, reportedCalls: values.filter((value) => value.source.kind === "reported").length, estimatedCalls: values.filter((value) => value.source.kind === "estimated").length }))), totalCalls: calls.length });
27
+ }
28
+ function inputTotal(call) {
29
+ const known = [call.inputTokens, call.cacheReadTokens, call.cacheWriteTokens].filter((value) => value !== null);
30
+ return { value: call.inputTotalTokens ?? (known.length === 0 ? null : known.reduce((sum, value) => sum + value, 0)), complete: call.inputTotalTokens !== null || known.length === 3 };
31
+ }
32
+ function adapterTokenMaterial(usage, metric) {
33
+ const provenance = Object.freeze({ source: "adapter", scope: "recorded-calls", unit: "tokens", cut: "call-time" });
34
+ let value = 0;
35
+ let observations = 0;
36
+ let complete = usage.collection.state === "complete" && usage.calls.length > 0;
37
+ for (const call of usage.calls) {
38
+ if (call.status === "unknown")
39
+ complete = false;
40
+ const input = inputTotal(call);
41
+ const buckets = metric === "totalTokens" ? [input.value, call.outputTokens] : metric === "inputTotalTokens" ? [input.value] : [call[metric]];
42
+ const observedBuckets = metric === "totalTokens" || metric === "inputTotalTokens"
43
+ ? [...(call.inputTotalTokens === null ? [call.inputTokens, call.cacheReadTokens, call.cacheWriteTokens] : [call.inputTotalTokens]), ...(metric === "totalTokens" ? [call.outputTokens] : [])]
44
+ : buckets;
45
+ if (observedBuckets.some((bucket) => bucket !== null && (!Number.isSafeInteger(bucket) || bucket < 0))) {
46
+ return Object.freeze({ state: "unavailable", reason: "usage-invalid-token-value", provenance });
47
+ }
48
+ for (const bucket of buckets) {
49
+ if (bucket === null)
50
+ complete = false;
51
+ else {
52
+ value += bucket;
53
+ observations += 1;
54
+ }
55
+ }
56
+ if ((metric === "totalTokens" || metric === "inputTotalTokens") && !input.complete)
57
+ complete = false;
58
+ }
59
+ return Object.freeze(!Number.isSafeInteger(value) ? { state: "unavailable", reason: "usage-exceeds-safe-integer", provenance } : observations === 0 ? { state: "unavailable", reason: "usage-not-recorded", provenance } : { state: complete ? "exact" : "lower-bound", value, provenance });
60
+ }
61
+ function adapterInspectionTokenTotal(usage, metric) {
62
+ const material = adapterTokenMaterial(usage, metric);
63
+ const observationCount = usage.calls.filter((call) => metric === "outputTokens"
64
+ ? call.outputTokens !== null
65
+ : inputTotal(call).value !== null || (metric === "totalTokens" && call.outputTokens !== null)).length;
66
+ return Object.freeze({
67
+ state: material.state === "exact" ? "available"
68
+ : material.state === "lower-bound" ? "partial" : "unavailable",
69
+ value: material.state === "unavailable" ? null : material.value,
70
+ observationCount,
71
+ });
72
+ }
73
+ /** Tuple order is stable across hosts, with missing identities before strings. */
74
+ function compareAdapterModelGroups(left, right) {
75
+ for (const key of ["modelSlot", "provider", "model"]) {
76
+ const a = left[key];
77
+ const b = right[key];
78
+ if (a === b)
79
+ continue;
80
+ if (a === null)
81
+ return -1;
82
+ if (b === null)
83
+ return 1;
84
+ return a < b ? -1 : 1;
85
+ }
86
+ return 0;
87
+ }
88
+ /** Configuration counts and grouped statistics both consume the complete sealed ledger. */
89
+ function projectAdapterModelUsage(usage, models, unavailable = { basis: "unavailable", reason: "usage-not-recorded" }) {
90
+ const counts = new Map();
91
+ for (const call of usage?.calls ?? []) {
92
+ if (call.modelSlot !== null)
93
+ counts.set(call.modelSlot, (counts.get(call.modelSlot) ?? 0) + 1);
94
+ }
95
+ const configuredModels = models === undefined
96
+ ? Object.freeze({ state: "not-recorded" })
97
+ : Object.freeze({
98
+ state: "available",
99
+ bindings: Object.freeze(Object.keys(models).sort().map((modelSlot) => Object.freeze({
100
+ modelSlot, ...models[modelSlot],
101
+ recordedCalls: usage === null ? null : counts.get(modelSlot) ?? 0,
102
+ }))),
103
+ });
104
+ if (usage === null)
105
+ return Object.freeze({
106
+ configuredModels,
107
+ modelGroups: Object.freeze({
108
+ state: "unavailable", ...unavailable,
109
+ groups: Object.freeze([]), totalGroupCount: null,
110
+ groupsTruncated: false, omittedGroupCount: 0,
111
+ }),
112
+ });
113
+ const grouped = new Map();
114
+ for (const call of effectiveUsageCalls(usage)) {
115
+ const identity = JSON.stringify([call.modelSlot, call.provider, call.model]);
116
+ const group = grouped.get(identity);
117
+ if (group === undefined)
118
+ grouped.set(identity, [call]);
119
+ else
120
+ group.push(call);
121
+ }
122
+ const allGroups = [...grouped.values()].sort((left, right) => compareAdapterModelGroups(left[0], right[0]));
123
+ const groups = allGroups.slice(0, 64).map((calls) => {
124
+ const { modelSlot, provider, model } = calls[0];
125
+ const groupUsage = { ...usage, calls };
126
+ return Object.freeze({
127
+ modelSlot, provider, model, recordedCalls: calls.length,
128
+ tokens: Object.freeze({
129
+ inputTotalTokens: adapterInspectionTokenTotal(groupUsage, "inputTotalTokens"),
130
+ outputTokens: adapterInspectionTokenTotal(groupUsage, "outputTokens"),
131
+ totalTokens: adapterInspectionTokenTotal(groupUsage, "totalTokens"),
132
+ }),
133
+ costs: effectiveCostTotals(calls, usage.collection.state),
134
+ });
135
+ });
136
+ return Object.freeze({
137
+ configuredModels,
138
+ modelGroups: Object.freeze({
139
+ state: "available", basis: "recorded-calls",
140
+ groups: Object.freeze(groups), totalGroupCount: allGroups.length,
141
+ groupsTruncated: allGroups.length > groups.length,
142
+ omittedGroupCount: allGroups.length - groups.length,
143
+ }),
144
+ });
145
+ }
146
+ function projectAdapterUsageSnapshot(usage) {
147
+ const calls = effectiveUsageCalls(usage);
148
+ return Object.freeze({ source: "adapter", scope: "recorded-calls", cut: "call-time", collection: usage.collection, calls, priceReceipts: usage.priceReceipts ?? [], inputTokens: adapterTokenMaterial(usage, "inputTokens"), inputTotalTokens: adapterTokenMaterial(usage, "inputTotalTokens"), outputTokens: adapterTokenMaterial(usage, "outputTokens"), cacheReadTokens: adapterTokenMaterial(usage, "cacheReadTokens"), cacheWriteTokens: adapterTokenMaterial(usage, "cacheWriteTokens"), totalTokens: adapterTokenMaterial(usage, "totalTokens"), costs: effectiveCostTotals(calls, usage.collection.state) });
149
+ }
150
+ function compareCanonicalDecimal(left, right) {
151
+ const [li, lf = ""] = left.split(".");
152
+ const [ri, rf = ""] = right.split(".");
153
+ const width = Math.max(lf.length, rf.length);
154
+ const l = BigInt(li + lf.padEnd(width, "0"));
155
+ const r = BigInt(ri + rf.padEnd(width, "0"));
156
+ return l < r ? -1 : l > r ? 1 : 0;
157
+ }
158
+ //# sourceMappingURL=adapter-usage-projection.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adapter-usage-projection.js","sourceRoot":"","sources":["adapter-usage-projection.ts"],"names":[],"mappings":";;AAgBA,kDAMC;AACD,kDAUC;AAQD,oDA4BC;AACD,kEAWC;AAED,8DAaC;AAED,4DA4DC;AAoBD,kEAGC;AACD,0DAOC;AA5LD,0EAAiF;AAejF,SAAgB,mBAAmB,CAAC,KAAqC;IACrE,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,CAAC,KAAK,CAAC,aAAa,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,MAA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K,EAAE,iBAAiB,CAAC,EAAE,gBAAgB,EAAE,oBAAoB,CAAC,KAAK,EAAE,kBAAkB,CAAC,EAAE,WAAW,EAAE,oBAAoB,CAAC,KAAK,EAAE,aAAa,CAAC,EAAE,KAAK,EAAE,mBAAmB,CAAC,KAAK,EAAE,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;AACzlB,CAAC;AACD,SAAgB,uBAAuB,CAAC,IAAY,EAAE,KAAa;IAC/D,MAAM,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACtC,MAAM,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACvC,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC;IAC7C,MAAM,CAAC,GAAG,MAAM,CAAC,EAAG,GAAG,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC;IAC9C,MAAM,CAAC,GAAG,MAAM,CAAC,EAAG,GAAG,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC;IAC9C,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACtC,CAAC","sourcesContent":["import type { ReadableAdapterUsageAttachment, AdapterUsageCall, AdapterCallPriceReceipt } from \"../record/family/adapter-usage/schema.ts\";\nimport { addCanonicalDecimals } from \"../record/family/adapter-usage/pricing.ts\";\nimport type { NumericMaterial } from \"../assertions/match.ts\";\nimport type { ResolvedModelSlots } from \"../model-slots.ts\";\nexport interface EffectiveCallCost {\n readonly amount: string;\n readonly currency: string;\n readonly source: {\n readonly kind: \"reported\" | \"estimated\";\n readonly id: string;\n };\n readonly state: \"complete\" | \"partial\";\n}\nexport type EffectiveUsageCall = AdapterUsageCall & {\n readonly effectiveCost: EffectiveCallCost | null;\n};\nexport function effectiveUsageCalls(usage: ReadableAdapterUsageAttachment): readonly EffectiveUsageCall[] {\n const receipts = new Map((usage.priceReceipts ?? []).map((receipt) => [receipt.callId, receipt]));\n return Object.freeze(usage.calls.map((call) => {\n const receipt = receipts.get(call.callId);\n return Object.freeze({ ...call, effectiveCost: call.cost !== null ? Object.freeze({ ...call.cost, state: \"complete\" as const }) : receipt === undefined ? null : Object.freeze({ amount: receipt.amount, currency: receipt.currency, source: receipt.source, state: receipt.state }) });\n }));\n}\nexport function effectiveCostTotals(calls: readonly {\n readonly effectiveCost: EffectiveCallCost | null;\n}[], collectionState: \"complete\" | \"partial\") {\n const known = calls.flatMap((call) => call.effectiveCost === null ? [] : [call.effectiveCost]);\n const kind = (values: readonly EffectiveCallCost[]) => { const sources = new Set(values.map((value) => value.source.kind)); return sources.size === 0 ? null : sources.size === 1 ? [...sources][0]! : \"mixed\" as const; };\n const grouped = new Map<string, EffectiveCallCost[]>();\n for (const cost of known)\n grouped.set(cost.currency, [...(grouped.get(cost.currency) ?? []), cost]);\n const complete = collectionState === \"complete\" && known.length === calls.length && known.every((cost) => cost.state === \"complete\");\n return Object.freeze({ state: known.length === 0 ? \"unavailable\" as const : complete ? \"complete\" as const : \"partial\" as const, source: kind(known), values: Object.freeze([...grouped.entries()].sort(([left], [right]) => left.localeCompare(right)).map(([currency, values]) => Object.freeze({ currency, value: addCanonicalDecimals(values.map((value) => value.amount)), source: kind(values)!, coveredCalls: values.filter((value) => value.state === \"complete\").length, reportedCalls: values.filter((value) => value.source.kind === \"reported\").length, estimatedCalls: values.filter((value) => value.source.kind === \"estimated\").length }))), totalCalls: calls.length });\n}\nfunction inputTotal(call: AdapterUsageCall): {\n value: number | null;\n complete: boolean;\n} {\n const known = [call.inputTokens, call.cacheReadTokens, call.cacheWriteTokens].filter((value): value is number => value !== null);\n return { value: call.inputTotalTokens ?? (known.length === 0 ? null : known.reduce((sum, value) => sum + value, 0)), complete: call.inputTotalTokens !== null || known.length === 3 };\n}\nexport function adapterTokenMaterial(usage: ReadableAdapterUsageAttachment, metric: \"inputTokens\" | \"inputTotalTokens\" | \"outputTokens\" | \"cacheReadTokens\" | \"cacheWriteTokens\" | \"totalTokens\"): NumericMaterial {\n const provenance = Object.freeze({ source: \"adapter\", scope: \"recorded-calls\", unit: \"tokens\", cut: \"call-time\" });\n let value = 0;\n let observations = 0;\n let complete = usage.collection.state === \"complete\" && usage.calls.length > 0;\n for (const call of usage.calls) {\n if (call.status === \"unknown\")\n complete = false;\n const input = inputTotal(call);\n const buckets = metric === \"totalTokens\" ? [input.value, call.outputTokens] : metric === \"inputTotalTokens\" ? [input.value] : [call[metric]];\n const observedBuckets = metric === \"totalTokens\" || metric === \"inputTotalTokens\"\n ? [...(call.inputTotalTokens === null ? [call.inputTokens, call.cacheReadTokens, call.cacheWriteTokens] : [call.inputTotalTokens]), ...(metric === \"totalTokens\" ? [call.outputTokens] : [])]\n : buckets;\n if (observedBuckets.some((bucket) => bucket !== null && (!Number.isSafeInteger(bucket) || bucket < 0))) {\n return Object.freeze({ state: \"unavailable\", reason: \"usage-invalid-token-value\", provenance });\n }\n for (const bucket of buckets) {\n if (bucket === null)\n complete = false;\n else {\n value += bucket;\n observations += 1;\n }\n }\n if ((metric === \"totalTokens\" || metric === \"inputTotalTokens\") && !input.complete)\n complete = false;\n }\n return Object.freeze(!Number.isSafeInteger(value) ? { state: \"unavailable\", reason: \"usage-exceeds-safe-integer\", provenance } : observations === 0 ? { state: \"unavailable\", reason: \"usage-not-recorded\", provenance } : { state: complete ? \"exact\" : \"lower-bound\", value, provenance });\n}\nexport function adapterInspectionTokenTotal(usage: ReadableAdapterUsageAttachment, metric: \"inputTotalTokens\" | \"outputTokens\" | \"totalTokens\") {\n const material = adapterTokenMaterial(usage, metric);\n const observationCount = usage.calls.filter((call) => metric === \"outputTokens\"\n ? call.outputTokens !== null\n : inputTotal(call).value !== null || (metric === \"totalTokens\" && call.outputTokens !== null)).length;\n return Object.freeze({\n state: material.state === \"exact\" ? \"available\" as const\n : material.state === \"lower-bound\" ? \"partial\" as const : \"unavailable\" as const,\n value: material.state === \"unavailable\" ? null : material.value,\n observationCount,\n });\n}\n/** Tuple order is stable across hosts, with missing identities before strings. */\nexport function compareAdapterModelGroups(left: Pick<AdapterUsageCall, \"modelSlot\" | \"provider\" | \"model\">, right: Pick<AdapterUsageCall, \"modelSlot\" | \"provider\" | \"model\">): number {\n for (const key of [\"modelSlot\", \"provider\", \"model\"] as const) {\n const a = left[key];\n const b = right[key];\n if (a === b)\n continue;\n if (a === null)\n return -1;\n if (b === null)\n return 1;\n return a < b ? -1 : 1;\n }\n return 0;\n}\n/** Configuration counts and grouped statistics both consume the complete sealed ledger. */\nexport function projectAdapterModelUsage(usage: ReadableAdapterUsageAttachment | null, models: ResolvedModelSlots | undefined, unavailable: {\n readonly basis: \"recorded-calls\" | \"reported-sends\" | \"unavailable\";\n readonly reason: \"source-invalid\" | \"usage-not-recorded\" | \"physical-call-identity-not-recorded\";\n} = { basis: \"unavailable\", reason: \"usage-not-recorded\" }) {\n const counts = new Map<string, number>();\n for (const call of usage?.calls ?? []) {\n if (call.modelSlot !== null)\n counts.set(call.modelSlot, (counts.get(call.modelSlot) ?? 0) + 1);\n }\n const configuredModels = models === undefined\n ? Object.freeze({ state: \"not-recorded\" as const })\n : Object.freeze({\n state: \"available\" as const,\n bindings: Object.freeze(Object.keys(models).sort().map((modelSlot) => Object.freeze({\n modelSlot, ...models[modelSlot]!,\n recordedCalls: usage === null ? null : counts.get(modelSlot) ?? 0,\n }))),\n });\n if (usage === null)\n return Object.freeze({\n configuredModels,\n modelGroups: Object.freeze({\n state: \"unavailable\" as const, ...unavailable,\n groups: Object.freeze([]) as readonly [\n ], totalGroupCount: null,\n groupsTruncated: false as const, omittedGroupCount: 0 as const,\n }),\n });\n const grouped = new Map<string, EffectiveUsageCall[]>();\n for (const call of effectiveUsageCalls(usage)) {\n const identity = JSON.stringify([call.modelSlot, call.provider, call.model]);\n const group = grouped.get(identity);\n if (group === undefined)\n grouped.set(identity, [call]);\n else\n group.push(call);\n }\n const allGroups = [...grouped.values()].sort((left, right) => compareAdapterModelGroups(left[0]!, right[0]!));\n const groups = allGroups.slice(0, 64).map((calls) => {\n const { modelSlot, provider, model } = calls[0]!;\n const groupUsage = { ...usage, calls };\n return Object.freeze({\n modelSlot, provider, model, recordedCalls: calls.length,\n tokens: Object.freeze({\n inputTotalTokens: adapterInspectionTokenTotal(groupUsage, \"inputTotalTokens\"),\n outputTokens: adapterInspectionTokenTotal(groupUsage, \"outputTokens\"),\n totalTokens: adapterInspectionTokenTotal(groupUsage, \"totalTokens\"),\n }),\n costs: effectiveCostTotals(calls, usage.collection.state),\n });\n });\n return Object.freeze({\n configuredModels,\n modelGroups: Object.freeze({\n state: \"available\" as const, basis: \"recorded-calls\" as const,\n groups: Object.freeze(groups), totalGroupCount: allGroups.length,\n groupsTruncated: allGroups.length > groups.length,\n omittedGroupCount: allGroups.length - groups.length,\n }),\n });\n}\nexport interface AdapterAttemptUsageSnapshot {\n readonly source: \"adapter\";\n readonly scope: \"recorded-calls\";\n readonly cut: \"call-time\";\n readonly collection: ReadableAdapterUsageAttachment[\"collection\"];\n readonly calls: readonly EffectiveUsageCall[];\n readonly priceReceipts: readonly AdapterCallPriceReceipt[];\n readonly inputTokens: NumericMaterial;\n readonly inputTotalTokens: NumericMaterial;\n readonly outputTokens: NumericMaterial;\n readonly cacheReadTokens: NumericMaterial;\n readonly cacheWriteTokens: NumericMaterial;\n readonly totalTokens: NumericMaterial;\n readonly costs: ReturnType<typeof effectiveCostTotals>;\n}\nexport type AttemptUsageSnapshot = AdapterAttemptUsageSnapshot | {\n readonly source: \"unavailable\";\n readonly reason: \"usage-owner-not-bound\";\n};\nexport function projectAdapterUsageSnapshot(usage: ReadableAdapterUsageAttachment): AdapterAttemptUsageSnapshot {\n const calls = effectiveUsageCalls(usage);\n return Object.freeze({ source: \"adapter\", scope: \"recorded-calls\", cut: \"call-time\", collection: usage.collection, calls, priceReceipts: usage.priceReceipts ?? [], inputTokens: adapterTokenMaterial(usage, \"inputTokens\"), inputTotalTokens: adapterTokenMaterial(usage, \"inputTotalTokens\"), outputTokens: adapterTokenMaterial(usage, \"outputTokens\"), cacheReadTokens: adapterTokenMaterial(usage, \"cacheReadTokens\"), cacheWriteTokens: adapterTokenMaterial(usage, \"cacheWriteTokens\"), totalTokens: adapterTokenMaterial(usage, \"totalTokens\"), costs: effectiveCostTotals(calls, usage.collection.state) });\n}\nexport function compareCanonicalDecimal(left: string, right: string): -1 | 0 | 1 {\n const [li, lf = \"\"] = left.split(\".\");\n const [ri, rf = \"\"] = right.split(\".\");\n const width = Math.max(lf.length, rf.length);\n const l = BigInt(li! + lf.padEnd(width, \"0\"));\n const r = BigInt(ri! + rf.padEnd(width, \"0\"));\n return l < r ? -1 : l > r ? 1 : 0;\n}\n"]}