niceeval 0.18.0 → 0.19.0

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 (679) hide show
  1. package/INDEX.md +4 -2
  2. package/dist/adapter-usage.cjs.map +1 -1
  3. package/dist/adapter-usage.d.cts +1 -1
  4. package/dist/adapter-usage.d.mts +1 -1
  5. package/dist/adapter-usage.d.ts +1 -1
  6. package/dist/adapter.cjs +8 -7
  7. package/dist/adapter.cjs.map +1 -1
  8. package/dist/adapter.d.cts +21 -21
  9. package/dist/adapter.d.mts +21 -21
  10. package/dist/adapter.d.ts +21 -21
  11. package/dist/agents/{effect-runtime.cjs → agent-effects.cjs} +12 -18
  12. package/dist/agents/agent-effects.cjs.map +1 -0
  13. package/dist/agents/agent-effects.d.cts +23 -0
  14. package/dist/agents/agent-effects.d.mts +23 -0
  15. package/dist/agents/agent-effects.d.ts +23 -0
  16. package/dist/agents/agent-effects.js +16 -0
  17. package/dist/agents/agent-effects.js.map +1 -0
  18. package/dist/agents/ai-sdk.cjs +1 -1
  19. package/dist/agents/ai-sdk.cjs.map +1 -1
  20. package/dist/agents/bub.cjs +31 -18
  21. package/dist/agents/bub.cjs.map +1 -1
  22. package/dist/agents/bub.d.cts +9 -12
  23. package/dist/agents/bub.d.mts +9 -12
  24. package/dist/agents/bub.d.ts +9 -12
  25. package/dist/agents/claude-code-native.cjs +2 -2
  26. package/dist/agents/claude-code-native.cjs.map +1 -1
  27. package/dist/agents/claude-code.cjs +17 -11
  28. package/dist/agents/claude-code.cjs.map +1 -1
  29. package/dist/agents/claude-code.d.cts +11 -11
  30. package/dist/agents/claude-code.d.mts +11 -11
  31. package/dist/agents/claude-code.d.ts +11 -11
  32. package/dist/agents/codex-app-server.cjs +2 -2
  33. package/dist/agents/codex-app-server.cjs.map +1 -1
  34. package/dist/agents/codex.cjs +18 -12
  35. package/dist/agents/codex.cjs.map +1 -1
  36. package/dist/agents/codex.d.cts +12 -12
  37. package/dist/agents/codex.d.mts +12 -12
  38. package/dist/agents/codex.d.ts +12 -12
  39. package/dist/agents/deepseek-harness.cjs +2 -2
  40. package/dist/agents/deepseek-harness.cjs.map +1 -1
  41. package/dist/agents/hermes.cjs +3 -3
  42. package/dist/agents/hermes.cjs.map +1 -1
  43. package/dist/agents/index.cjs +3 -3
  44. package/dist/agents/index.cjs.map +1 -1
  45. package/dist/agents/index.d.cts +3 -3
  46. package/dist/agents/index.d.mts +3 -3
  47. package/dist/agents/index.d.ts +3 -3
  48. package/dist/agents/index.js +2 -2
  49. package/dist/agents/index.mjs +2 -2
  50. package/dist/agents/mcp.cjs.map +1 -1
  51. package/dist/agents/mcp.d.cts +2 -2
  52. package/dist/agents/mcp.d.mts +2 -2
  53. package/dist/agents/mcp.d.ts +2 -2
  54. package/dist/agents/omp.cjs +2 -2
  55. package/dist/agents/omp.cjs.map +1 -1
  56. package/dist/agents/openai-compat.cjs +2 -2
  57. package/dist/agents/openai-compat.cjs.map +1 -1
  58. package/dist/agents/openclaw.cjs +3 -3
  59. package/dist/agents/openclaw.cjs.map +1 -1
  60. package/dist/agents/opencode.cjs +16 -4
  61. package/dist/agents/opencode.cjs.map +1 -1
  62. package/dist/agents/plugin-extensions.cjs +71 -0
  63. package/dist/agents/plugin-extensions.cjs.map +1 -0
  64. package/dist/agents/plugin-extensions.d.cts +26 -0
  65. package/dist/agents/plugin-extensions.d.mts +26 -0
  66. package/dist/agents/plugin-extensions.d.ts +26 -0
  67. package/dist/agents/plugin-extensions.js +8 -0
  68. package/dist/agents/plugin-extensions.js.map +1 -0
  69. package/dist/agents/post-setup.cjs +14 -3
  70. package/dist/agents/post-setup.cjs.map +1 -1
  71. package/dist/agents/post-setup.d.cts +4 -2
  72. package/dist/agents/post-setup.d.mts +4 -2
  73. package/dist/agents/post-setup.d.ts +4 -2
  74. package/dist/agents/post-setup.js +8 -6
  75. package/dist/agents/sdk-streams.cjs +3 -3
  76. package/dist/agents/sdk-streams.cjs.map +1 -1
  77. package/dist/agents/{session-slot.cjs → session-key.cjs} +4 -4
  78. package/dist/agents/session-key.cjs.map +1 -0
  79. package/dist/agents/session-key.d.cts +12 -0
  80. package/dist/agents/session-key.d.mts +12 -0
  81. package/dist/agents/session-key.d.ts +12 -0
  82. package/dist/agents/session-key.js +6 -0
  83. package/dist/agents/session-key.js.map +1 -0
  84. package/dist/agents/shared.cjs +2 -2
  85. package/dist/agents/shared.cjs.map +1 -1
  86. package/dist/agents/shared.d.cts +4 -4
  87. package/dist/agents/shared.d.mts +4 -4
  88. package/dist/agents/shared.d.ts +4 -4
  89. package/dist/agents/skills.cjs.map +1 -1
  90. package/dist/agents/skills.d.cts +3 -3
  91. package/dist/agents/skills.d.mts +3 -3
  92. package/dist/agents/skills.d.ts +3 -3
  93. package/dist/agents/types.cjs.map +1 -1
  94. package/dist/agents/types.d.cts +55 -54
  95. package/dist/agents/types.d.mts +55 -54
  96. package/dist/agents/types.d.ts +55 -54
  97. package/dist/agents/ui-message-stream.cjs +4 -4
  98. package/dist/agents/ui-message-stream.cjs.map +1 -1
  99. package/dist/agents/unrecognized-events.cjs +32 -0
  100. package/dist/agents/unrecognized-events.cjs.map +1 -0
  101. package/dist/agents/unrecognized-events.d.cts +8 -0
  102. package/dist/agents/unrecognized-events.d.mts +8 -0
  103. package/dist/agents/unrecognized-events.d.ts +8 -0
  104. package/dist/agents/unrecognized-events.js +6 -0
  105. package/dist/agents/unrecognized-events.js.map +1 -0
  106. package/dist/assertions/api.cjs.map +1 -1
  107. package/dist/assertions/api.d.cts +3 -0
  108. package/dist/assertions/api.d.mts +3 -0
  109. package/dist/assertions/api.d.ts +3 -0
  110. package/dist/assertions/collection.cjs +1 -1
  111. package/dist/assertions/collection.cjs.map +1 -1
  112. package/dist/assertions/judge.cjs +1 -1
  113. package/dist/assertions/judge.cjs.map +1 -1
  114. package/dist/assertions/match.cjs +52 -21
  115. package/dist/assertions/match.cjs.map +1 -1
  116. package/dist/assertions/match.d.cts +16 -5
  117. package/dist/assertions/match.d.mts +16 -5
  118. package/dist/assertions/match.d.ts +16 -5
  119. package/dist/assertions/match.js +96 -94
  120. package/dist/assertions/measurements.cjs +22 -6
  121. package/dist/assertions/measurements.cjs.map +1 -1
  122. package/dist/assertions/measurements.d.cts +8 -1
  123. package/dist/assertions/measurements.d.mts +8 -1
  124. package/dist/assertions/measurements.d.ts +8 -1
  125. package/dist/assertions/numeric.cjs +2 -0
  126. package/dist/assertions/numeric.cjs.map +1 -1
  127. package/dist/assertions/numeric.d.cts +1 -1
  128. package/dist/assertions/numeric.d.mts +1 -1
  129. package/dist/assertions/numeric.d.ts +1 -1
  130. package/dist/assertions/quantity.cjs +42 -0
  131. package/dist/assertions/quantity.cjs.map +1 -0
  132. package/dist/assertions/quantity.d.cts +18 -0
  133. package/dist/assertions/quantity.d.mts +18 -0
  134. package/dist/assertions/quantity.d.ts +18 -0
  135. package/dist/assertions/quantity.js +22 -0
  136. package/dist/assertions/quantity.js.map +1 -0
  137. package/dist/assertions/record/attachment.cjs +2 -0
  138. package/dist/assertions/record/attachment.cjs.map +1 -1
  139. package/dist/assertions/record/codec.cjs +5 -1
  140. package/dist/assertions/record/codec.cjs.map +1 -1
  141. package/dist/assertions/record/model.cjs.map +1 -1
  142. package/dist/assertions/record/model.d.cts +3 -1
  143. package/dist/assertions/record/model.d.mts +3 -1
  144. package/dist/assertions/record/model.d.ts +3 -1
  145. package/dist/assertions/runtime.cjs +11 -6
  146. package/dist/assertions/runtime.cjs.map +1 -1
  147. package/dist/cli/program.cjs +3 -0
  148. package/dist/cli/program.cjs.map +1 -1
  149. package/dist/context/assert-first.cjs +6 -4
  150. package/dist/context/assert-first.cjs.map +1 -1
  151. package/dist/context/assert-first.d.cts +9 -3
  152. package/dist/context/assert-first.d.mts +9 -3
  153. package/dist/context/assert-first.d.ts +9 -3
  154. package/dist/context/notes.cjs +47 -0
  155. package/dist/context/notes.cjs.map +1 -0
  156. package/dist/context/notes.d.cts +10 -0
  157. package/dist/context/notes.d.mts +10 -0
  158. package/dist/context/notes.d.ts +10 -0
  159. package/dist/context/notes.js +6 -0
  160. package/dist/context/notes.js.map +1 -0
  161. package/dist/context/send-failures.cjs +1 -7
  162. package/dist/context/send-failures.cjs.map +1 -1
  163. package/dist/context/send-failures.d.cts +2 -3
  164. package/dist/context/send-failures.d.mts +2 -3
  165. package/dist/context/send-failures.d.ts +2 -3
  166. package/dist/context/send-retry.cjs +0 -1
  167. package/dist/context/send-retry.cjs.map +1 -1
  168. package/dist/context/send-retry.d.cts +1 -2
  169. package/dist/context/send-retry.d.mts +1 -2
  170. package/dist/context/send-retry.d.ts +1 -2
  171. package/dist/context/session.cjs +10 -17
  172. package/dist/context/session.cjs.map +1 -1
  173. package/dist/context/session.d.cts +4 -10
  174. package/dist/context/session.d.mts +4 -10
  175. package/dist/context/session.d.ts +4 -10
  176. package/dist/define.cjs +88 -65
  177. package/dist/define.cjs.map +1 -1
  178. package/dist/define.d.cts +3 -3
  179. package/dist/define.d.mts +3 -3
  180. package/dist/define.d.ts +3 -3
  181. package/dist/eval/cli/contribution.cjs +1 -1
  182. package/dist/eval/cli/contribution.cjs.map +1 -1
  183. package/dist/eval/host/index.cjs +1 -1
  184. package/dist/eval/host/index.cjs.map +1 -1
  185. package/dist/eval/record/evaluation.cjs +1 -1
  186. package/dist/eval/record/evaluation.cjs.map +1 -1
  187. package/dist/eval/record/membership-provenance.d.cts +3 -3
  188. package/dist/eval/record/membership-provenance.d.mts +3 -3
  189. package/dist/eval/record/membership-provenance.d.ts +3 -3
  190. package/dist/eval/record/score.cjs +2 -2
  191. package/dist/eval/record/score.cjs.map +1 -1
  192. package/dist/eval/record/sealed-assertion.cjs +1 -1
  193. package/dist/eval/record/sealed-assertion.cjs.map +1 -1
  194. package/dist/eval/record/verdict.cjs +2 -2
  195. package/dist/eval/record/verdict.cjs.map +1 -1
  196. package/dist/expect/index.cjs +10 -1
  197. package/dist/expect/index.cjs.map +1 -1
  198. package/dist/expect/index.d.cts +3 -1
  199. package/dist/expect/index.d.mts +3 -1
  200. package/dist/expect/index.d.ts +3 -1
  201. package/dist/expect/index.js +92 -76
  202. package/dist/expect/index.mjs +92 -76
  203. package/dist/experiment/host/cli/contribution.cjs +52 -39
  204. package/dist/experiment/host/cli/contribution.cjs.map +1 -1
  205. package/dist/experiment/host/cli/contribution.d.cts +18 -4
  206. package/dist/experiment/host/cli/contribution.d.mts +18 -4
  207. package/dist/experiment/host/cli/contribution.d.ts +18 -4
  208. package/dist/experiment/host/cli/contribution.js +2 -2
  209. package/dist/experiment/host/cli/debug-protocol.cjs +2 -2
  210. package/dist/experiment/host/cli/debug-protocol.cjs.map +1 -1
  211. package/dist/experiment/host/cli/debug-protocol.d.cts +2 -2
  212. package/dist/experiment/host/cli/debug-protocol.d.mts +2 -2
  213. package/dist/experiment/host/cli/debug-protocol.d.ts +2 -2
  214. package/dist/experiment/host/cli/output-protocol.cjs +1 -1
  215. package/dist/experiment/host/cli/output-protocol.cjs.map +1 -1
  216. package/dist/experiment/host/cli/output-protocol.d.cts +2 -2
  217. package/dist/experiment/host/cli/output-protocol.d.mts +2 -2
  218. package/dist/experiment/host/cli/output-protocol.d.ts +2 -2
  219. package/dist/experiment/host/current.cjs +2 -2
  220. package/dist/experiment/host/current.cjs.map +1 -1
  221. package/dist/experiment/host/index.cjs +1 -1
  222. package/dist/experiment/host/index.cjs.map +1 -1
  223. package/dist/experiment/host/operations.cjs +21 -22
  224. package/dist/experiment/host/operations.cjs.map +1 -1
  225. package/dist/experiment/host/runtime.cjs +8 -9
  226. package/dist/experiment/host/runtime.cjs.map +1 -1
  227. package/dist/experiment/host/runtime.d.cts +3 -3
  228. package/dist/experiment/host/runtime.d.mts +3 -3
  229. package/dist/experiment/host/runtime.d.ts +3 -3
  230. package/dist/experiment/host/teardown.cjs +3 -3
  231. package/dist/experiment/host/teardown.cjs.map +1 -1
  232. package/dist/experiment/host/teardown.d.cts +3 -3
  233. package/dist/experiment/host/teardown.d.mts +3 -3
  234. package/dist/experiment/host/teardown.d.ts +3 -3
  235. package/dist/experiment/host/types.cjs.map +1 -1
  236. package/dist/experiment/host/types.d.cts +19 -19
  237. package/dist/experiment/host/types.d.mts +19 -19
  238. package/dist/experiment/host/types.d.ts +19 -19
  239. package/dist/index.cjs +3 -3
  240. package/dist/index.cjs.map +1 -1
  241. package/dist/index.d.cts +3 -3
  242. package/dist/index.d.mts +3 -3
  243. package/dist/index.d.ts +3 -3
  244. package/dist/index.js +2 -2
  245. package/dist/index.mjs +2 -2
  246. package/dist/inspection/assertions.cjs +1 -1
  247. package/dist/inspection/assertions.cjs.map +1 -1
  248. package/dist/inspection/cli/contribution.cjs +8 -7
  249. package/dist/inspection/cli/contribution.cjs.map +1 -1
  250. package/dist/inspection/facts.cjs +4 -4
  251. package/dist/inspection/facts.cjs.map +1 -1
  252. package/dist/inspection/index.cjs +1 -5
  253. package/dist/inspection/index.cjs.map +1 -1
  254. package/dist/inspection/index.d.cts +1 -2
  255. package/dist/inspection/index.d.mts +1 -2
  256. package/dist/inspection/index.d.ts +1 -2
  257. package/dist/inspection/index.js +20 -26
  258. package/dist/inspection/lifecycle.cjs +7 -0
  259. package/dist/inspection/lifecycle.cjs.map +1 -0
  260. package/dist/inspection/lifecycle.d.cts +4 -0
  261. package/dist/inspection/lifecycle.d.mts +4 -0
  262. package/dist/inspection/lifecycle.d.ts +4 -0
  263. package/dist/inspection/lifecycle.js +6 -0
  264. package/dist/inspection/lifecycle.js.map +1 -0
  265. package/dist/inspection/notes.cjs +40 -0
  266. package/dist/inspection/notes.cjs.map +1 -0
  267. package/dist/inspection/notes.d.cts +12 -0
  268. package/dist/inspection/notes.d.mts +12 -0
  269. package/dist/inspection/notes.d.ts +12 -0
  270. package/dist/inspection/notes.js +8 -0
  271. package/dist/inspection/notes.js.map +1 -0
  272. package/dist/inspection/overview.cjs +12 -15
  273. package/dist/inspection/overview.cjs.map +1 -1
  274. package/dist/inspection/overview.d.cts +8 -6
  275. package/dist/inspection/overview.d.mts +8 -6
  276. package/dist/inspection/overview.d.ts +8 -6
  277. package/dist/inspection/planned-attempt.cjs +45 -0
  278. package/dist/inspection/planned-attempt.cjs.map +1 -0
  279. package/dist/inspection/planned-attempt.d.cts +109 -0
  280. package/dist/inspection/planned-attempt.d.mts +109 -0
  281. package/dist/inspection/planned-attempt.d.ts +109 -0
  282. package/dist/inspection/planned-attempt.js +24 -0
  283. package/dist/inspection/planned-attempt.js.map +1 -0
  284. package/dist/inspection/project-result.cjs +5 -5
  285. package/dist/inspection/project-result.cjs.map +1 -1
  286. package/dist/inspection/project-result.d.cts +58 -57
  287. package/dist/inspection/project-result.d.mts +58 -57
  288. package/dist/inspection/project-result.d.ts +58 -57
  289. package/dist/inspection/project-result.js +4 -4
  290. package/dist/inspection/project.cjs +3 -3
  291. package/dist/inspection/project.cjs.map +1 -1
  292. package/dist/inspection/protocol-values.cjs +1 -1
  293. package/dist/inspection/protocol-values.cjs.map +1 -1
  294. package/dist/inspection/protocol-values.d.cts +1 -1
  295. package/dist/inspection/protocol-values.d.mts +1 -1
  296. package/dist/inspection/protocol-values.d.ts +1 -1
  297. package/dist/inspection/protocol.cjs +8 -8
  298. package/dist/inspection/protocol.cjs.map +1 -1
  299. package/dist/inspection/protocol.d.cts +237 -219
  300. package/dist/inspection/protocol.d.mts +237 -219
  301. package/dist/inspection/protocol.d.ts +237 -219
  302. package/dist/inspection/public.cjs +1 -5
  303. package/dist/inspection/public.cjs.map +1 -1
  304. package/dist/inspection/public.d.cts +1 -2
  305. package/dist/inspection/public.d.mts +1 -2
  306. package/dist/inspection/public.d.ts +1 -2
  307. package/dist/inspection/public.js +14 -20
  308. package/dist/inspection/public.mjs +166 -129
  309. package/dist/inspection/query.cjs +1 -1
  310. package/dist/inspection/query.cjs.map +1 -1
  311. package/dist/inspection/results.cjs +61 -52
  312. package/dist/inspection/results.cjs.map +1 -1
  313. package/dist/inspection/results.d.cts +157 -140
  314. package/dist/inspection/results.d.mts +157 -140
  315. package/dist/inspection/results.d.ts +157 -140
  316. package/dist/inspection/select.cjs +33 -28
  317. package/dist/inspection/select.cjs.map +1 -1
  318. package/dist/inspection/source.cjs +1 -1
  319. package/dist/inspection/source.cjs.map +1 -1
  320. package/dist/inspection/sources.cjs +2 -2
  321. package/dist/inspection/sources.cjs.map +1 -1
  322. package/dist/inspection/trace.cjs +9 -8
  323. package/dist/inspection/trace.cjs.map +1 -1
  324. package/dist/inspection/trace.d.cts +4 -4
  325. package/dist/inspection/trace.d.mts +4 -4
  326. package/dist/inspection/trace.d.ts +4 -4
  327. package/dist/loaders/index.cjs +7 -279
  328. package/dist/loaders/index.cjs.map +1 -1
  329. package/dist/loaders/index.d.cts +2 -95
  330. package/dist/loaders/index.d.mts +2 -95
  331. package/dist/loaders/index.d.ts +2 -95
  332. package/dist/loaders/index.js +10 -12
  333. package/dist/loaders/index.mjs +10 -12
  334. package/dist/loaders/runtime.cjs +283 -0
  335. package/dist/loaders/runtime.cjs.map +1 -0
  336. package/dist/loaders/runtime.d.cts +95 -0
  337. package/dist/loaders/runtime.d.mts +95 -0
  338. package/dist/loaders/runtime.d.ts +95 -0
  339. package/dist/loaders/runtime.js +16 -0
  340. package/dist/loaders/runtime.js.map +1 -0
  341. package/dist/migrations/judge-provider.md +6 -6
  342. package/dist/{model-slots.cjs → model-roles.cjs} +12 -12
  343. package/dist/{model-slots.cjs.map → model-roles.cjs.map} +1 -1
  344. package/dist/{model-slots.d.cts → model-roles.d.cts} +10 -10
  345. package/dist/{model-slots.d.mts → model-roles.d.mts} +10 -10
  346. package/dist/{model-slots.d.ts → model-roles.d.ts} +10 -10
  347. package/dist/model-roles.js +14 -0
  348. package/dist/model-roles.js.map +1 -0
  349. package/dist/o11y/adapter-usage-projection.cjs +9 -8
  350. package/dist/o11y/adapter-usage-projection.cjs.map +1 -1
  351. package/dist/o11y/adapter-usage-projection.d.cts +23 -15
  352. package/dist/o11y/adapter-usage-projection.d.mts +23 -15
  353. package/dist/o11y/adapter-usage-projection.d.ts +23 -15
  354. package/dist/o11y/cache-read.cjs +14 -14
  355. package/dist/o11y/cache-read.cjs.map +1 -1
  356. package/dist/o11y/cache-read.d.cts +5 -5
  357. package/dist/o11y/cache-read.d.mts +5 -5
  358. package/dist/o11y/cache-read.d.ts +5 -5
  359. package/dist/o11y/derive.cjs.map +1 -1
  360. package/dist/o11y/derive.d.cts +2 -2
  361. package/dist/o11y/derive.d.mts +2 -2
  362. package/dist/o11y/derive.d.ts +2 -2
  363. package/dist/o11y/eval-usage.cjs +9 -9
  364. package/dist/o11y/eval-usage.cjs.map +1 -1
  365. package/dist/o11y/eval-usage.d.cts +7 -7
  366. package/dist/o11y/eval-usage.d.mts +7 -7
  367. package/dist/o11y/eval-usage.d.ts +7 -7
  368. package/dist/o11y/parsers/bub.cjs +57 -81
  369. package/dist/o11y/parsers/bub.cjs.map +1 -1
  370. package/dist/o11y/parsers/index.cjs.map +1 -1
  371. package/dist/o11y/parsers/index.d.cts +2 -0
  372. package/dist/o11y/parsers/index.d.mts +2 -0
  373. package/dist/o11y/parsers/index.d.ts +2 -0
  374. package/dist/o11y/parsers/opencode.cjs +129 -217
  375. package/dist/o11y/parsers/opencode.cjs.map +1 -1
  376. package/dist/o11y/parsers/opencode.d.cts +2 -5
  377. package/dist/o11y/parsers/opencode.d.mts +2 -5
  378. package/dist/o11y/parsers/opencode.d.ts +2 -5
  379. package/dist/o11y/types.cjs.map +1 -1
  380. package/dist/o11y/types.d.cts +1 -1
  381. package/dist/o11y/types.d.mts +1 -1
  382. package/dist/o11y/types.d.ts +1 -1
  383. package/dist/plugin/contracts.cjs +170 -120
  384. package/dist/plugin/contracts.cjs.map +1 -1
  385. package/dist/plugin/contracts.d.cts +102 -90
  386. package/dist/plugin/contracts.d.mts +102 -90
  387. package/dist/plugin/contracts.d.ts +102 -90
  388. package/dist/plugin/contracts.js +16 -12
  389. package/dist/plugin/index.cjs.map +1 -1
  390. package/dist/plugin/index.d.cts +1 -1
  391. package/dist/plugin/index.d.mts +1 -1
  392. package/dist/plugin/index.d.ts +1 -1
  393. package/dist/plugin/link.cjs +69 -64
  394. package/dist/plugin/link.cjs.map +1 -1
  395. package/dist/plugin/link.d.cts +5 -3
  396. package/dist/plugin/link.d.mts +5 -3
  397. package/dist/plugin/link.d.ts +5 -3
  398. package/dist/plugin/link.js +12 -8
  399. package/dist/record/codec/seal-manifest.d.cts +3 -3
  400. package/dist/record/codec/seal-manifest.d.mts +3 -3
  401. package/dist/record/codec/seal-manifest.d.ts +3 -3
  402. package/dist/record/family/attempt-note/definition.cjs +12 -0
  403. package/dist/record/family/attempt-note/definition.cjs.map +1 -0
  404. package/dist/record/family/attempt-note/definition.d.cts +6 -0
  405. package/dist/record/family/attempt-note/definition.d.mts +6 -0
  406. package/dist/record/family/attempt-note/definition.d.ts +6 -0
  407. package/dist/record/family/attempt-note/definition.js +6 -0
  408. package/dist/record/family/attempt-note/definition.js.map +1 -0
  409. package/dist/record/family/attempt-note/persistence.cjs +10 -0
  410. package/dist/record/family/attempt-note/persistence.cjs.map +1 -0
  411. package/dist/record/family/attempt-note/persistence.d.cts +6 -0
  412. package/dist/record/family/attempt-note/persistence.d.mts +6 -0
  413. package/dist/record/family/attempt-note/persistence.d.ts +6 -0
  414. package/dist/record/family/attempt-note/persistence.js +6 -0
  415. package/dist/record/family/attempt-note/persistence.js.map +1 -0
  416. package/dist/record/family/attempt-note/schema.cjs +20 -0
  417. package/dist/record/family/attempt-note/schema.cjs.map +1 -0
  418. package/dist/record/family/attempt-note/schema.d.cts +21 -0
  419. package/dist/record/family/attempt-note/schema.d.mts +21 -0
  420. package/dist/record/family/attempt-note/schema.d.ts +21 -0
  421. package/dist/record/family/attempt-note/schema.js +10 -0
  422. package/dist/record/family/attempt-note/schema.js.map +1 -0
  423. package/dist/record/family/catalog.cjs +32 -29
  424. package/dist/record/family/catalog.cjs.map +1 -1
  425. package/dist/record/family/catalog.d.cts +7 -2
  426. package/dist/record/family/catalog.d.mts +7 -2
  427. package/dist/record/family/catalog.d.ts +7 -2
  428. package/dist/record/family/current.cjs +48 -45
  429. package/dist/record/family/current.cjs.map +1 -1
  430. package/dist/record/family/current.d.cts +15 -0
  431. package/dist/record/family/current.d.mts +15 -0
  432. package/dist/record/family/current.d.ts +15 -0
  433. package/dist/record/model/index.js +66 -64
  434. package/dist/record/model/run-context.cjs +9 -3
  435. package/dist/record/model/run-context.cjs.map +1 -1
  436. package/dist/record/model/run-context.d.cts +9 -2
  437. package/dist/record/model/run-context.d.mts +9 -2
  438. package/dist/record/model/run-context.d.ts +9 -2
  439. package/dist/record/model/run-context.js +8 -6
  440. package/dist/record/model/seal-manifest.d.cts +1 -1
  441. package/dist/record/model/seal-manifest.d.mts +1 -1
  442. package/dist/record/model/seal-manifest.d.ts +1 -1
  443. package/dist/run/cli/contribution.cjs +6 -32
  444. package/dist/run/cli/contribution.cjs.map +1 -1
  445. package/dist/run/host/runtime.cjs +1 -1
  446. package/dist/run/host/runtime.cjs.map +1 -1
  447. package/dist/run/storage/sqlite.cjs +7 -7
  448. package/dist/run/storage/sqlite.cjs.map +1 -1
  449. package/dist/runner/adapter-usage.cjs +5 -3
  450. package/dist/runner/adapter-usage.cjs.map +1 -1
  451. package/dist/runner/adapter-usage.d.cts +2 -2
  452. package/dist/runner/adapter-usage.d.mts +2 -2
  453. package/dist/runner/adapter-usage.d.ts +2 -2
  454. package/dist/runner/adoption.cjs +9 -12
  455. package/dist/runner/adoption.cjs.map +1 -1
  456. package/dist/runner/attempt-notes.cjs +8 -0
  457. package/dist/runner/attempt-notes.cjs.map +1 -0
  458. package/dist/runner/attempt-notes.d.cts +4 -0
  459. package/dist/runner/attempt-notes.d.mts +4 -0
  460. package/dist/runner/attempt-notes.d.ts +4 -0
  461. package/dist/runner/attempt-notes.js +8 -0
  462. package/dist/runner/attempt-notes.js.map +1 -0
  463. package/dist/runner/attempt.cjs +61 -73
  464. package/dist/runner/attempt.cjs.map +1 -1
  465. package/dist/runner/attempt.d.cts +3 -3
  466. package/dist/runner/attempt.d.mts +3 -3
  467. package/dist/runner/attempt.d.ts +3 -3
  468. package/dist/runner/command-plan.cjs +21 -26
  469. package/dist/runner/command-plan.cjs.map +1 -1
  470. package/dist/runner/command-plan.d.cts +4 -4
  471. package/dist/runner/command-plan.d.mts +4 -4
  472. package/dist/runner/command-plan.d.ts +4 -4
  473. package/dist/runner/command-plan.js +4 -4
  474. package/dist/runner/config-identity.cjs.map +1 -1
  475. package/dist/runner/config-identity.d.cts +2 -2
  476. package/dist/runner/config-identity.d.mts +2 -2
  477. package/dist/runner/config-identity.d.ts +2 -2
  478. package/dist/runner/discover.cjs +6 -6
  479. package/dist/runner/discover.cjs.map +1 -1
  480. package/dist/runner/eval-selection.cjs +2 -2
  481. package/dist/runner/eval-selection.cjs.map +1 -1
  482. package/dist/runner/eval-selection.d.cts +2 -2
  483. package/dist/runner/eval-selection.d.mts +2 -2
  484. package/dist/runner/eval-selection.d.ts +2 -2
  485. package/dist/runner/feedback/human.cjs +1 -1
  486. package/dist/runner/feedback/human.cjs.map +1 -1
  487. package/dist/runner/feedback/json.cjs +4 -2
  488. package/dist/runner/feedback/json.cjs.map +1 -1
  489. package/dist/runner/feedback/json.d.cts +1 -1
  490. package/dist/runner/feedback/json.d.mts +1 -1
  491. package/dist/runner/feedback/json.d.ts +1 -1
  492. package/dist/runner/feedback/sink.cjs +1 -1
  493. package/dist/runner/feedback/sink.cjs.map +1 -1
  494. package/dist/runner/feedback/sink.d.cts +1 -1
  495. package/dist/runner/feedback/sink.d.mts +1 -1
  496. package/dist/runner/feedback/sink.d.ts +1 -1
  497. package/dist/runner/fingerprint.cjs +1 -1
  498. package/dist/runner/fingerprint.cjs.map +1 -1
  499. package/dist/runner/project-target.cjs.map +1 -1
  500. package/dist/runner/project-target.d.cts +2 -2
  501. package/dist/runner/project-target.d.mts +2 -2
  502. package/dist/runner/project-target.d.ts +2 -2
  503. package/dist/runner/record/attachments.cjs +2 -2
  504. package/dist/runner/record/attachments.cjs.map +1 -1
  505. package/dist/runner/record/planning.cjs +8 -2
  506. package/dist/runner/record/planning.cjs.map +1 -1
  507. package/dist/runner/record.cjs +2 -0
  508. package/dist/runner/record.cjs.map +1 -1
  509. package/dist/runner/report.cjs +3 -3
  510. package/dist/runner/report.cjs.map +1 -1
  511. package/dist/runner/report.d.cts +1 -1
  512. package/dist/runner/report.d.mts +1 -1
  513. package/dist/runner/report.d.ts +1 -1
  514. package/dist/runner/reuse-plan.cjs +2 -2
  515. package/dist/runner/reuse-plan.cjs.map +1 -1
  516. package/dist/runner/run.cjs +10 -45
  517. package/dist/runner/run.cjs.map +1 -1
  518. package/dist/runner/sandbox-pool.cjs +1 -2
  519. package/dist/runner/sandbox-pool.cjs.map +1 -1
  520. package/dist/runner/setup-prefix-preparation.cjs +1 -1
  521. package/dist/runner/setup-prefix-preparation.cjs.map +1 -1
  522. package/dist/runner/teardown-registry.cjs +2 -2
  523. package/dist/runner/teardown-registry.cjs.map +1 -1
  524. package/dist/runner/teardown-registry.d.cts +1 -1
  525. package/dist/runner/teardown-registry.d.mts +1 -1
  526. package/dist/runner/teardown-registry.d.ts +1 -1
  527. package/dist/runner/types.cjs +4 -4
  528. package/dist/runner/types.cjs.map +1 -1
  529. package/dist/runner/types.d.cts +64 -93
  530. package/dist/runner/types.d.mts +64 -93
  531. package/dist/runner/types.d.ts +64 -93
  532. package/dist/runner/types.js +2 -2
  533. package/dist/sandbox/action.cjs +1 -1
  534. package/dist/sandbox/action.cjs.map +1 -1
  535. package/dist/sandbox/cli/contribution.cjs +17 -14
  536. package/dist/sandbox/cli/contribution.cjs.map +1 -1
  537. package/dist/sandbox/cli/contribution.d.cts +1 -1
  538. package/dist/sandbox/cli/contribution.d.mts +1 -1
  539. package/dist/sandbox/cli/contribution.d.ts +1 -1
  540. package/dist/sandbox/commands.cjs +1 -1
  541. package/dist/sandbox/commands.cjs.map +1 -1
  542. package/dist/sandbox/commands.d.cts +1 -1
  543. package/dist/sandbox/commands.d.mts +1 -1
  544. package/dist/sandbox/commands.d.ts +1 -1
  545. package/dist/sandbox/compose.cjs +2 -2
  546. package/dist/sandbox/compose.cjs.map +1 -1
  547. package/dist/sandbox/docker-profile/registry.cjs +5 -9
  548. package/dist/sandbox/docker-profile/registry.cjs.map +1 -1
  549. package/dist/sandbox/docker-profile/registry.d.cts +0 -3
  550. package/dist/sandbox/docker-profile/registry.d.mts +0 -3
  551. package/dist/sandbox/docker-profile/registry.d.ts +0 -3
  552. package/dist/sandbox/docker-profile/registry.js +6 -12
  553. package/dist/sandbox/docker-profile/runtime.cjs +1 -1
  554. package/dist/sandbox/docker-profile/runtime.cjs.map +1 -1
  555. package/dist/sandbox/docker-profile/schema.cjs +12 -16
  556. package/dist/sandbox/docker-profile/schema.cjs.map +1 -1
  557. package/dist/sandbox/docker-profile/schema.d.cts +2 -6
  558. package/dist/sandbox/docker-profile/schema.d.mts +2 -6
  559. package/dist/sandbox/docker-profile/schema.d.ts +2 -6
  560. package/dist/sandbox/docker-profile/schema.js +24 -32
  561. package/dist/sandbox/incus.cjs +2 -2
  562. package/dist/sandbox/incus.cjs.map +1 -1
  563. package/dist/sandbox/index.cjs +4 -35
  564. package/dist/sandbox/index.cjs.map +1 -1
  565. package/dist/sandbox/index.d.cts +4 -8
  566. package/dist/sandbox/index.d.mts +4 -8
  567. package/dist/sandbox/index.d.ts +4 -8
  568. package/dist/sandbox/index.js +116 -172
  569. package/dist/sandbox/index.mjs +116 -172
  570. package/dist/sandbox/layer.cjs +3 -3
  571. package/dist/sandbox/layer.cjs.map +1 -1
  572. package/dist/sandbox/link.cjs +5 -0
  573. package/dist/sandbox/link.cjs.map +1 -1
  574. package/dist/sandbox/link.d.cts +3 -0
  575. package/dist/sandbox/link.d.mts +3 -0
  576. package/dist/sandbox/link.d.ts +3 -0
  577. package/dist/sandbox/runtime.cjs +9 -4
  578. package/dist/sandbox/runtime.cjs.map +1 -1
  579. package/dist/shared/failure-class.cjs +5 -5
  580. package/dist/shared/failure-class.cjs.map +1 -1
  581. package/dist/shared/failure-class.d.cts +4 -10
  582. package/dist/shared/failure-class.d.mts +4 -10
  583. package/dist/shared/failure-class.d.ts +4 -10
  584. package/dist/shared/types.cjs.map +1 -1
  585. package/dist/shared/types.d.cts +1 -1
  586. package/dist/shared/types.d.mts +1 -1
  587. package/dist/shared/types.d.ts +1 -1
  588. package/dist/show/contribution.cjs +17 -2
  589. package/dist/show/contribution.cjs.map +1 -1
  590. package/dist/show/contribution.d.cts +14 -0
  591. package/dist/show/contribution.d.mts +14 -0
  592. package/dist/show/contribution.d.ts +14 -0
  593. package/dist/show/model.cjs +8 -5
  594. package/dist/show/model.cjs.map +1 -1
  595. package/dist/show/model.d.cts +11 -8
  596. package/dist/show/model.d.mts +11 -8
  597. package/dist/show/model.d.ts +11 -8
  598. package/dist/show/render.cjs +34 -22
  599. package/dist/show/render.cjs.map +1 -1
  600. package/dist/sources/projector.cjs +1 -1
  601. package/dist/sources/projector.cjs.map +1 -1
  602. package/dist/types.cjs +1 -1
  603. package/dist/types.cjs.map +1 -1
  604. package/dist/types.d.cts +1 -1
  605. package/dist/types.d.mts +1 -1
  606. package/dist/types.d.ts +1 -1
  607. package/dist/types.js +2 -2
  608. package/dist/view/app-dist/.vite/manifest.json +2 -2
  609. package/dist/view/app-dist/assets/{index-B3ijZRph.js → index-CxrOUvHC.js} +17 -17
  610. package/dist/view/app-dist/assets/{quality-cost-scatter-B--DfJ9s.js → quality-cost-scatter-B6Aiss7x.js} +1 -1
  611. package/dist/view/app-dist/index.html +1 -1
  612. package/dist/view/cli/contribution.cjs +1 -1
  613. package/dist/view/cli/contribution.cjs.map +1 -1
  614. package/dist/view/function-runtime.mjs +318 -121
  615. package/dist/view/http-protocol.d.cts +1 -1
  616. package/dist/view/http-protocol.d.mts +1 -1
  617. package/dist/view/http-protocol.d.ts +1 -1
  618. package/dist/view/inspection-host.cjs +2 -2
  619. package/dist/view/inspection-host.cjs.map +1 -1
  620. package/dist/view/inspection-host.d.cts +349 -331
  621. package/dist/view/inspection-host.d.mts +349 -331
  622. package/dist/view/inspection-host.d.ts +349 -331
  623. package/docs-site/zh/examples/integrations/ai-sdk-v7.mdx +6 -6
  624. package/docs-site/zh/examples/integrations/claude-sdk.mdx +5 -5
  625. package/docs-site/zh/examples/integrations/codex-sdk.mdx +4 -4
  626. package/docs-site/zh/examples/integrations/langgraph.mdx +4 -4
  627. package/docs-site/zh/examples/integrations/pi-sdk.mdx +5 -5
  628. package/docs-site/zh/explanation/adapter.mdx +6 -6
  629. package/docs-site/zh/explanation/assert.mdx +7 -7
  630. package/docs-site/zh/explanation/drive.mdx +4 -4
  631. package/docs-site/zh/explanation/hitl.mdx +2 -2
  632. package/docs-site/zh/explanation/judge.mdx +2 -2
  633. package/docs-site/zh/introduction.mdx +2 -2
  634. package/docs-site/zh/reference/builtin-agents.mdx +46 -49
  635. package/docs-site/zh/reference/cli.mdx +16 -14
  636. package/docs-site/zh/reference/define-agent.mdx +19 -19
  637. package/docs-site/zh/reference/define-config.mdx +7 -15
  638. package/docs-site/zh/reference/define-eval.mdx +20 -14
  639. package/docs-site/zh/reference/define-experiment.mdx +18 -39
  640. package/docs-site/zh/reference/events.mdx +1 -1
  641. package/docs-site/zh/reference/expect.mdx +21 -0
  642. package/docs-site/zh/reference/official-adapters.mdx +12 -5
  643. package/docs-site/zh/troubleshooting/debugging.mdx +2 -2
  644. package/docs-site/zh/troubleshooting/recover-after-kill.mdx +1 -1
  645. package/docs-site/zh/tutorials/agent-onboarding.mdx +2 -2
  646. package/docs-site/zh/tutorials/authoring.mdx +2 -2
  647. package/docs-site/zh/tutorials/compare-runs.mdx +1 -1
  648. package/docs-site/zh/tutorials/concurrency.mdx +8 -8
  649. package/docs-site/zh/tutorials/configuration.mdx +5 -5
  650. package/docs-site/zh/tutorials/control-run-cost.mdx +19 -19
  651. package/docs-site/zh/tutorials/eval-groups.mdx +1 -1
  652. package/docs-site/zh/tutorials/evaluation-kinds.mdx +5 -5
  653. package/docs-site/zh/tutorials/experiment-services.mdx +32 -32
  654. package/docs-site/zh/tutorials/handle-execution-failures.mdx +2 -28
  655. package/docs-site/zh/tutorials/plugins.mdx +49 -143
  656. package/docs-site/zh/tutorials/sandbox-agent.mdx +1 -1
  657. package/docs-site/zh/tutorials/sandbox-reuse.mdx +7 -7
  658. package/docs-site/zh/tutorials/upgrade-0-18.mdx +1 -1
  659. package/docs-site/zh/tutorials/upgrade-0-19.mdx +121 -0
  660. package/docs-site/zh/tutorials/upgrade-0-20.mdx +12 -0
  661. package/docs-site/zh/tutorials/verify-judge.mdx +2 -2
  662. package/docs-site/zh/tutorials/viewing-results.mdx +2 -2
  663. package/docs-site/zh/tutorials/write-experiment.mdx +1 -1
  664. package/docs-site/zh/tutorials/write-send.mdx +13 -13
  665. package/package.json +1 -1
  666. package/dist/agents/effect-runtime.cjs.map +0 -1
  667. package/dist/agents/effect-runtime.d.cts +0 -29
  668. package/dist/agents/effect-runtime.d.mts +0 -29
  669. package/dist/agents/effect-runtime.d.ts +0 -29
  670. package/dist/agents/effect-runtime.js +0 -16
  671. package/dist/agents/effect-runtime.js.map +0 -1
  672. package/dist/agents/session-slot.cjs.map +0 -1
  673. package/dist/agents/session-slot.d.cts +0 -12
  674. package/dist/agents/session-slot.d.mts +0 -12
  675. package/dist/agents/session-slot.d.ts +0 -12
  676. package/dist/agents/session-slot.js +0 -6
  677. package/dist/agents/session-slot.js.map +0 -1
  678. package/dist/model-slots.js +0 -14
  679. package/dist/model-slots.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"adapter-usage-projection.js","sourceRoot":"","sources":["adapter-usage-projection.ts"],"names":[],"mappings":";;AAiBA,kDAMC;AACD,kDAUC;AAQD,oDA4BC;AACD,kEAWC;AAED,8DAaC;AAED,4DA+DC;AAoBD,kEAGC;AACD,0DAOC;AAjMD,mDAAmD;AAEnD,0EAAiF;AAejF,SAAgB,mBAAmB,CAAC,KAAqC;IACrE,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,CAAC,KAAK,CAAC,aAAa,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC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CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACtC,CAAC","sourcesContent":["import { projectCacheRead } from \"./cache-read.ts\";\nimport 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\" }, producerCompletenessKnown = true) {\n const cacheRead = projectCacheRead(usage, models, producerCompletenessKnown, unavailable.reason === \"physical-call-identity-not-recorded\" ? \"adapter-usage-required\" : unavailable.reason);\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 cacheRead,\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 cacheRead,\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"]}
1
+ {"version":3,"file":"adapter-usage-projection.js","sourceRoot":"","sources":["adapter-usage-projection.ts"],"names":[],"mappings":";;AAmBA,kDAOC;AACD,kD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AC,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 { projectCacheRead } from \"./cache-read.ts\";\nimport 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 { ResolvedModelRoles } from \"../model-roles.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 = Omit<AdapterUsageCall, \"modelSlot\"> & {\n readonly modelRole: string | null;\n} & {\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 const { modelSlot, ...fields } = call;\n return Object.freeze({ ...fields, modelRole: modelSlot, 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: Omit<AdapterUsageCall, \"modelSlot\">): {\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: {\n readonly collection: ReadableAdapterUsageAttachment[\"collection\"];\n readonly calls: readonly Omit<AdapterUsageCall, \"modelSlot\">[];\n}, 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: {\n readonly collection: ReadableAdapterUsageAttachment[\"collection\"];\n readonly calls: readonly Omit<AdapterUsageCall, \"modelSlot\">[];\n}, 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<EffectiveUsageCall, \"modelRole\" | \"provider\" | \"model\">, right: Pick<EffectiveUsageCall, \"modelRole\" | \"provider\" | \"model\">): number {\n for (const key of [\"modelRole\", \"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: ResolvedModelRoles | 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\" }, producerCompletenessKnown = true) {\n const cacheRead = projectCacheRead(usage, models, producerCompletenessKnown, unavailable.reason === \"physical-call-identity-not-recorded\" ? \"adapter-usage-required\" : unavailable.reason);\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((modelRole) => Object.freeze({\n modelRole, ...models[modelRole]!,\n recordedCalls: usage === null ? null : counts.get(modelRole) ?? 0,\n }))),\n });\n if (usage === null)\n return Object.freeze({\n cacheRead,\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.modelRole, 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 { modelRole, provider, model } = calls[0]!;\n const groupUsage = { ...usage, calls };\n return Object.freeze({\n modelRole, 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 cacheRead,\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"]}
@@ -1,6 +1,6 @@
1
1
  import type { ReadableAdapterUsageAttachment, AdapterUsageCall, AdapterCallPriceReceipt } from "../record/family/adapter-usage/schema.cjs";
2
2
  import type { NumericMaterial } from "../assertions/match.cjs";
3
- import type { ResolvedModelSlots } from "../model-slots.cjs";
3
+ import type { ResolvedModelRoles } from "../model-roles.cjs";
4
4
  export interface EffectiveCallCost {
5
5
  readonly amount: string;
6
6
  readonly currency: string;
@@ -10,7 +10,9 @@ export interface EffectiveCallCost {
10
10
  };
11
11
  readonly state: "complete" | "partial";
12
12
  }
13
- export type EffectiveUsageCall = AdapterUsageCall & {
13
+ export type EffectiveUsageCall = Omit<AdapterUsageCall, "modelSlot"> & {
14
+ readonly modelRole: string | null;
15
+ } & {
14
16
  readonly effectiveCost: EffectiveCallCost | null;
15
17
  };
16
18
  export declare function effectiveUsageCalls(usage: ReadableAdapterUsageAttachment): readonly EffectiveUsageCall[];
@@ -29,16 +31,22 @@ export declare function effectiveCostTotals(calls: readonly {
29
31
  }>[];
30
32
  totalCalls: number;
31
33
  }>;
32
- export declare function adapterTokenMaterial(usage: ReadableAdapterUsageAttachment, metric: "inputTokens" | "inputTotalTokens" | "outputTokens" | "cacheReadTokens" | "cacheWriteTokens" | "totalTokens"): NumericMaterial;
33
- export declare function adapterInspectionTokenTotal(usage: ReadableAdapterUsageAttachment, metric: "inputTotalTokens" | "outputTokens" | "totalTokens"): Readonly<{
34
+ export declare function adapterTokenMaterial(usage: {
35
+ readonly collection: ReadableAdapterUsageAttachment["collection"];
36
+ readonly calls: readonly Omit<AdapterUsageCall, "modelSlot">[];
37
+ }, metric: "inputTokens" | "inputTotalTokens" | "outputTokens" | "cacheReadTokens" | "cacheWriteTokens" | "totalTokens"): NumericMaterial;
38
+ export declare function adapterInspectionTokenTotal(usage: {
39
+ readonly collection: ReadableAdapterUsageAttachment["collection"];
40
+ readonly calls: readonly Omit<AdapterUsageCall, "modelSlot">[];
41
+ }, metric: "inputTotalTokens" | "outputTokens" | "totalTokens"): Readonly<{
34
42
  state: "partial" | "available" | "unavailable";
35
43
  value: number | null;
36
44
  observationCount: number;
37
45
  }>;
38
46
  /** Tuple order is stable across hosts, with missing identities before strings. */
39
- export declare function compareAdapterModelGroups(left: Pick<AdapterUsageCall, "modelSlot" | "provider" | "model">, right: Pick<AdapterUsageCall, "modelSlot" | "provider" | "model">): number;
47
+ export declare function compareAdapterModelGroups(left: Pick<EffectiveUsageCall, "modelRole" | "provider" | "model">, right: Pick<EffectiveUsageCall, "modelRole" | "provider" | "model">): number;
40
48
  /** Configuration counts and grouped statistics both consume the complete sealed ledger. */
41
- export declare function projectAdapterModelUsage(usage: ReadableAdapterUsageAttachment | null, models: ResolvedModelSlots | undefined, unavailable?: {
49
+ export declare function projectAdapterModelUsage(usage: ReadableAdapterUsageAttachment | null, models: ResolvedModelRoles | undefined, unavailable?: {
42
50
  readonly basis: "recorded-calls" | "reported-sends" | "unavailable";
43
51
  readonly reason: "source-invalid" | "usage-not-recorded" | "physical-call-identity-not-recorded";
44
52
  }, producerCompletenessKnown?: boolean): Readonly<{
@@ -59,7 +67,7 @@ export declare function projectAdapterModelUsage(usage: ReadableAdapterUsageAtta
59
67
  readonly collectionComplete: boolean;
60
68
  readonly reasons: readonly ("usage-not-recorded" | "source-invalid" | "adapter-usage-required" | "collection-incomplete" | "call-status-unknown" | "no-calls" | "cache-read-missing" | "input-total-missing" | "zero-input-total" | "unsafe-token-total")[];
61
69
  };
62
- readonly modelSlots: readonly {
70
+ readonly roles: readonly {
63
71
  readonly rate: {
64
72
  readonly state: "exact";
65
73
  readonly value: number;
@@ -74,7 +82,7 @@ export declare function projectAdapterModelUsage(usage: ReadableAdapterUsageAtta
74
82
  readonly unknownStatusCalls: number;
75
83
  readonly collectionComplete: boolean;
76
84
  readonly reasons: readonly ("usage-not-recorded" | "source-invalid" | "adapter-usage-required" | "collection-incomplete" | "call-status-unknown" | "no-calls" | "cache-read-missing" | "input-total-missing" | "zero-input-total" | "unsafe-token-total")[];
77
- readonly modelSlot: string | null;
85
+ readonly modelRole: string | null;
78
86
  }[];
79
87
  readonly models: readonly {
80
88
  readonly rate: {
@@ -91,7 +99,7 @@ export declare function projectAdapterModelUsage(usage: ReadableAdapterUsageAtta
91
99
  readonly unknownStatusCalls: number;
92
100
  readonly collectionComplete: boolean;
93
101
  readonly reasons: readonly ("usage-not-recorded" | "source-invalid" | "adapter-usage-required" | "collection-incomplete" | "call-status-unknown" | "no-calls" | "cache-read-missing" | "input-total-missing" | "zero-input-total" | "unsafe-token-total")[];
94
- readonly modelSlot: string | null;
102
+ readonly modelRole: string | null;
95
103
  readonly provider: string | null;
96
104
  readonly model: string | null;
97
105
  }[];
@@ -104,7 +112,7 @@ export declare function projectAdapterModelUsage(usage: ReadableAdapterUsageAtta
104
112
  recordedCalls: number | null;
105
113
  model: string | null;
106
114
  reasoningEffort: string | null;
107
- modelSlot: string;
115
+ modelRole: string;
108
116
  }>[];
109
117
  }>;
110
118
  modelGroups: Readonly<{
@@ -134,7 +142,7 @@ export declare function projectAdapterModelUsage(usage: ReadableAdapterUsageAtta
134
142
  readonly collectionComplete: boolean;
135
143
  readonly reasons: readonly ("usage-not-recorded" | "source-invalid" | "adapter-usage-required" | "collection-incomplete" | "call-status-unknown" | "no-calls" | "cache-read-missing" | "input-total-missing" | "zero-input-total" | "unsafe-token-total")[];
136
144
  };
137
- readonly modelSlots: readonly {
145
+ readonly roles: readonly {
138
146
  readonly rate: {
139
147
  readonly state: "exact";
140
148
  readonly value: number;
@@ -149,7 +157,7 @@ export declare function projectAdapterModelUsage(usage: ReadableAdapterUsageAtta
149
157
  readonly unknownStatusCalls: number;
150
158
  readonly collectionComplete: boolean;
151
159
  readonly reasons: readonly ("usage-not-recorded" | "source-invalid" | "adapter-usage-required" | "collection-incomplete" | "call-status-unknown" | "no-calls" | "cache-read-missing" | "input-total-missing" | "zero-input-total" | "unsafe-token-total")[];
152
- readonly modelSlot: string | null;
160
+ readonly modelRole: string | null;
153
161
  }[];
154
162
  readonly models: readonly {
155
163
  readonly rate: {
@@ -166,7 +174,7 @@ export declare function projectAdapterModelUsage(usage: ReadableAdapterUsageAtta
166
174
  readonly unknownStatusCalls: number;
167
175
  readonly collectionComplete: boolean;
168
176
  readonly reasons: readonly ("usage-not-recorded" | "source-invalid" | "adapter-usage-required" | "collection-incomplete" | "call-status-unknown" | "no-calls" | "cache-read-missing" | "input-total-missing" | "zero-input-total" | "unsafe-token-total")[];
169
- readonly modelSlot: string | null;
177
+ readonly modelRole: string | null;
170
178
  readonly provider: string | null;
171
179
  readonly model: string | null;
172
180
  }[];
@@ -179,14 +187,14 @@ export declare function projectAdapterModelUsage(usage: ReadableAdapterUsageAtta
179
187
  recordedCalls: number | null;
180
188
  model: string | null;
181
189
  reasoningEffort: string | null;
182
- modelSlot: string;
190
+ modelRole: string;
183
191
  }>[];
184
192
  }>;
185
193
  modelGroups: Readonly<{
186
194
  state: "available";
187
195
  basis: "recorded-calls";
188
196
  groups: readonly Readonly<{
189
- modelSlot: string | null;
197
+ modelRole: string | null;
190
198
  provider: string | null;
191
199
  model: string | null;
192
200
  recordedCalls: number;
@@ -1,6 +1,6 @@
1
1
  import type { ReadableAdapterUsageAttachment, AdapterUsageCall, AdapterCallPriceReceipt } from "../record/family/adapter-usage/schema.mjs";
2
2
  import type { NumericMaterial } from "../assertions/match.mjs";
3
- import type { ResolvedModelSlots } from "../model-slots.mjs";
3
+ import type { ResolvedModelRoles } from "../model-roles.mjs";
4
4
  export interface EffectiveCallCost {
5
5
  readonly amount: string;
6
6
  readonly currency: string;
@@ -10,7 +10,9 @@ export interface EffectiveCallCost {
10
10
  };
11
11
  readonly state: "complete" | "partial";
12
12
  }
13
- export type EffectiveUsageCall = AdapterUsageCall & {
13
+ export type EffectiveUsageCall = Omit<AdapterUsageCall, "modelSlot"> & {
14
+ readonly modelRole: string | null;
15
+ } & {
14
16
  readonly effectiveCost: EffectiveCallCost | null;
15
17
  };
16
18
  export declare function effectiveUsageCalls(usage: ReadableAdapterUsageAttachment): readonly EffectiveUsageCall[];
@@ -29,16 +31,22 @@ export declare function effectiveCostTotals(calls: readonly {
29
31
  }>[];
30
32
  totalCalls: number;
31
33
  }>;
32
- export declare function adapterTokenMaterial(usage: ReadableAdapterUsageAttachment, metric: "inputTokens" | "inputTotalTokens" | "outputTokens" | "cacheReadTokens" | "cacheWriteTokens" | "totalTokens"): NumericMaterial;
33
- export declare function adapterInspectionTokenTotal(usage: ReadableAdapterUsageAttachment, metric: "inputTotalTokens" | "outputTokens" | "totalTokens"): Readonly<{
34
+ export declare function adapterTokenMaterial(usage: {
35
+ readonly collection: ReadableAdapterUsageAttachment["collection"];
36
+ readonly calls: readonly Omit<AdapterUsageCall, "modelSlot">[];
37
+ }, metric: "inputTokens" | "inputTotalTokens" | "outputTokens" | "cacheReadTokens" | "cacheWriteTokens" | "totalTokens"): NumericMaterial;
38
+ export declare function adapterInspectionTokenTotal(usage: {
39
+ readonly collection: ReadableAdapterUsageAttachment["collection"];
40
+ readonly calls: readonly Omit<AdapterUsageCall, "modelSlot">[];
41
+ }, metric: "inputTotalTokens" | "outputTokens" | "totalTokens"): Readonly<{
34
42
  state: "partial" | "available" | "unavailable";
35
43
  value: number | null;
36
44
  observationCount: number;
37
45
  }>;
38
46
  /** Tuple order is stable across hosts, with missing identities before strings. */
39
- export declare function compareAdapterModelGroups(left: Pick<AdapterUsageCall, "modelSlot" | "provider" | "model">, right: Pick<AdapterUsageCall, "modelSlot" | "provider" | "model">): number;
47
+ export declare function compareAdapterModelGroups(left: Pick<EffectiveUsageCall, "modelRole" | "provider" | "model">, right: Pick<EffectiveUsageCall, "modelRole" | "provider" | "model">): number;
40
48
  /** Configuration counts and grouped statistics both consume the complete sealed ledger. */
41
- export declare function projectAdapterModelUsage(usage: ReadableAdapterUsageAttachment | null, models: ResolvedModelSlots | undefined, unavailable?: {
49
+ export declare function projectAdapterModelUsage(usage: ReadableAdapterUsageAttachment | null, models: ResolvedModelRoles | undefined, unavailable?: {
42
50
  readonly basis: "recorded-calls" | "reported-sends" | "unavailable";
43
51
  readonly reason: "source-invalid" | "usage-not-recorded" | "physical-call-identity-not-recorded";
44
52
  }, producerCompletenessKnown?: boolean): Readonly<{
@@ -59,7 +67,7 @@ export declare function projectAdapterModelUsage(usage: ReadableAdapterUsageAtta
59
67
  readonly collectionComplete: boolean;
60
68
  readonly reasons: readonly ("usage-not-recorded" | "source-invalid" | "adapter-usage-required" | "collection-incomplete" | "call-status-unknown" | "no-calls" | "cache-read-missing" | "input-total-missing" | "zero-input-total" | "unsafe-token-total")[];
61
69
  };
62
- readonly modelSlots: readonly {
70
+ readonly roles: readonly {
63
71
  readonly rate: {
64
72
  readonly state: "exact";
65
73
  readonly value: number;
@@ -74,7 +82,7 @@ export declare function projectAdapterModelUsage(usage: ReadableAdapterUsageAtta
74
82
  readonly unknownStatusCalls: number;
75
83
  readonly collectionComplete: boolean;
76
84
  readonly reasons: readonly ("usage-not-recorded" | "source-invalid" | "adapter-usage-required" | "collection-incomplete" | "call-status-unknown" | "no-calls" | "cache-read-missing" | "input-total-missing" | "zero-input-total" | "unsafe-token-total")[];
77
- readonly modelSlot: string | null;
85
+ readonly modelRole: string | null;
78
86
  }[];
79
87
  readonly models: readonly {
80
88
  readonly rate: {
@@ -91,7 +99,7 @@ export declare function projectAdapterModelUsage(usage: ReadableAdapterUsageAtta
91
99
  readonly unknownStatusCalls: number;
92
100
  readonly collectionComplete: boolean;
93
101
  readonly reasons: readonly ("usage-not-recorded" | "source-invalid" | "adapter-usage-required" | "collection-incomplete" | "call-status-unknown" | "no-calls" | "cache-read-missing" | "input-total-missing" | "zero-input-total" | "unsafe-token-total")[];
94
- readonly modelSlot: string | null;
102
+ readonly modelRole: string | null;
95
103
  readonly provider: string | null;
96
104
  readonly model: string | null;
97
105
  }[];
@@ -104,7 +112,7 @@ export declare function projectAdapterModelUsage(usage: ReadableAdapterUsageAtta
104
112
  recordedCalls: number | null;
105
113
  model: string | null;
106
114
  reasoningEffort: string | null;
107
- modelSlot: string;
115
+ modelRole: string;
108
116
  }>[];
109
117
  }>;
110
118
  modelGroups: Readonly<{
@@ -134,7 +142,7 @@ export declare function projectAdapterModelUsage(usage: ReadableAdapterUsageAtta
134
142
  readonly collectionComplete: boolean;
135
143
  readonly reasons: readonly ("usage-not-recorded" | "source-invalid" | "adapter-usage-required" | "collection-incomplete" | "call-status-unknown" | "no-calls" | "cache-read-missing" | "input-total-missing" | "zero-input-total" | "unsafe-token-total")[];
136
144
  };
137
- readonly modelSlots: readonly {
145
+ readonly roles: readonly {
138
146
  readonly rate: {
139
147
  readonly state: "exact";
140
148
  readonly value: number;
@@ -149,7 +157,7 @@ export declare function projectAdapterModelUsage(usage: ReadableAdapterUsageAtta
149
157
  readonly unknownStatusCalls: number;
150
158
  readonly collectionComplete: boolean;
151
159
  readonly reasons: readonly ("usage-not-recorded" | "source-invalid" | "adapter-usage-required" | "collection-incomplete" | "call-status-unknown" | "no-calls" | "cache-read-missing" | "input-total-missing" | "zero-input-total" | "unsafe-token-total")[];
152
- readonly modelSlot: string | null;
160
+ readonly modelRole: string | null;
153
161
  }[];
154
162
  readonly models: readonly {
155
163
  readonly rate: {
@@ -166,7 +174,7 @@ export declare function projectAdapterModelUsage(usage: ReadableAdapterUsageAtta
166
174
  readonly unknownStatusCalls: number;
167
175
  readonly collectionComplete: boolean;
168
176
  readonly reasons: readonly ("usage-not-recorded" | "source-invalid" | "adapter-usage-required" | "collection-incomplete" | "call-status-unknown" | "no-calls" | "cache-read-missing" | "input-total-missing" | "zero-input-total" | "unsafe-token-total")[];
169
- readonly modelSlot: string | null;
177
+ readonly modelRole: string | null;
170
178
  readonly provider: string | null;
171
179
  readonly model: string | null;
172
180
  }[];
@@ -179,14 +187,14 @@ export declare function projectAdapterModelUsage(usage: ReadableAdapterUsageAtta
179
187
  recordedCalls: number | null;
180
188
  model: string | null;
181
189
  reasoningEffort: string | null;
182
- modelSlot: string;
190
+ modelRole: string;
183
191
  }>[];
184
192
  }>;
185
193
  modelGroups: Readonly<{
186
194
  state: "available";
187
195
  basis: "recorded-calls";
188
196
  groups: readonly Readonly<{
189
- modelSlot: string | null;
197
+ modelRole: string | null;
190
198
  provider: string | null;
191
199
  model: string | null;
192
200
  recordedCalls: number;
@@ -1,6 +1,6 @@
1
1
  import type { ReadableAdapterUsageAttachment, AdapterUsageCall, AdapterCallPriceReceipt } from "../record/family/adapter-usage/schema.js";
2
2
  import type { NumericMaterial } from "../assertions/match.js";
3
- import type { ResolvedModelSlots } from "../model-slots.js";
3
+ import type { ResolvedModelRoles } from "../model-roles.js";
4
4
  export interface EffectiveCallCost {
5
5
  readonly amount: string;
6
6
  readonly currency: string;
@@ -10,7 +10,9 @@ export interface EffectiveCallCost {
10
10
  };
11
11
  readonly state: "complete" | "partial";
12
12
  }
13
- export type EffectiveUsageCall = AdapterUsageCall & {
13
+ export type EffectiveUsageCall = Omit<AdapterUsageCall, "modelSlot"> & {
14
+ readonly modelRole: string | null;
15
+ } & {
14
16
  readonly effectiveCost: EffectiveCallCost | null;
15
17
  };
16
18
  export declare function effectiveUsageCalls(usage: ReadableAdapterUsageAttachment): readonly EffectiveUsageCall[];
@@ -29,16 +31,22 @@ export declare function effectiveCostTotals(calls: readonly {
29
31
  }>[];
30
32
  totalCalls: number;
31
33
  }>;
32
- export declare function adapterTokenMaterial(usage: ReadableAdapterUsageAttachment, metric: "inputTokens" | "inputTotalTokens" | "outputTokens" | "cacheReadTokens" | "cacheWriteTokens" | "totalTokens"): NumericMaterial;
33
- export declare function adapterInspectionTokenTotal(usage: ReadableAdapterUsageAttachment, metric: "inputTotalTokens" | "outputTokens" | "totalTokens"): Readonly<{
34
+ export declare function adapterTokenMaterial(usage: {
35
+ readonly collection: ReadableAdapterUsageAttachment["collection"];
36
+ readonly calls: readonly Omit<AdapterUsageCall, "modelSlot">[];
37
+ }, metric: "inputTokens" | "inputTotalTokens" | "outputTokens" | "cacheReadTokens" | "cacheWriteTokens" | "totalTokens"): NumericMaterial;
38
+ export declare function adapterInspectionTokenTotal(usage: {
39
+ readonly collection: ReadableAdapterUsageAttachment["collection"];
40
+ readonly calls: readonly Omit<AdapterUsageCall, "modelSlot">[];
41
+ }, metric: "inputTotalTokens" | "outputTokens" | "totalTokens"): Readonly<{
34
42
  state: "partial" | "available" | "unavailable";
35
43
  value: number | null;
36
44
  observationCount: number;
37
45
  }>;
38
46
  /** Tuple order is stable across hosts, with missing identities before strings. */
39
- export declare function compareAdapterModelGroups(left: Pick<AdapterUsageCall, "modelSlot" | "provider" | "model">, right: Pick<AdapterUsageCall, "modelSlot" | "provider" | "model">): number;
47
+ export declare function compareAdapterModelGroups(left: Pick<EffectiveUsageCall, "modelRole" | "provider" | "model">, right: Pick<EffectiveUsageCall, "modelRole" | "provider" | "model">): number;
40
48
  /** Configuration counts and grouped statistics both consume the complete sealed ledger. */
41
- export declare function projectAdapterModelUsage(usage: ReadableAdapterUsageAttachment | null, models: ResolvedModelSlots | undefined, unavailable?: {
49
+ export declare function projectAdapterModelUsage(usage: ReadableAdapterUsageAttachment | null, models: ResolvedModelRoles | undefined, unavailable?: {
42
50
  readonly basis: "recorded-calls" | "reported-sends" | "unavailable";
43
51
  readonly reason: "source-invalid" | "usage-not-recorded" | "physical-call-identity-not-recorded";
44
52
  }, producerCompletenessKnown?: boolean): Readonly<{
@@ -59,7 +67,7 @@ export declare function projectAdapterModelUsage(usage: ReadableAdapterUsageAtta
59
67
  readonly collectionComplete: boolean;
60
68
  readonly reasons: readonly ("usage-not-recorded" | "source-invalid" | "adapter-usage-required" | "collection-incomplete" | "call-status-unknown" | "no-calls" | "cache-read-missing" | "input-total-missing" | "zero-input-total" | "unsafe-token-total")[];
61
69
  };
62
- readonly modelSlots: readonly {
70
+ readonly roles: readonly {
63
71
  readonly rate: {
64
72
  readonly state: "exact";
65
73
  readonly value: number;
@@ -74,7 +82,7 @@ export declare function projectAdapterModelUsage(usage: ReadableAdapterUsageAtta
74
82
  readonly unknownStatusCalls: number;
75
83
  readonly collectionComplete: boolean;
76
84
  readonly reasons: readonly ("usage-not-recorded" | "source-invalid" | "adapter-usage-required" | "collection-incomplete" | "call-status-unknown" | "no-calls" | "cache-read-missing" | "input-total-missing" | "zero-input-total" | "unsafe-token-total")[];
77
- readonly modelSlot: string | null;
85
+ readonly modelRole: string | null;
78
86
  }[];
79
87
  readonly models: readonly {
80
88
  readonly rate: {
@@ -91,7 +99,7 @@ export declare function projectAdapterModelUsage(usage: ReadableAdapterUsageAtta
91
99
  readonly unknownStatusCalls: number;
92
100
  readonly collectionComplete: boolean;
93
101
  readonly reasons: readonly ("usage-not-recorded" | "source-invalid" | "adapter-usage-required" | "collection-incomplete" | "call-status-unknown" | "no-calls" | "cache-read-missing" | "input-total-missing" | "zero-input-total" | "unsafe-token-total")[];
94
- readonly modelSlot: string | null;
102
+ readonly modelRole: string | null;
95
103
  readonly provider: string | null;
96
104
  readonly model: string | null;
97
105
  }[];
@@ -104,7 +112,7 @@ export declare function projectAdapterModelUsage(usage: ReadableAdapterUsageAtta
104
112
  recordedCalls: number | null;
105
113
  model: string | null;
106
114
  reasoningEffort: string | null;
107
- modelSlot: string;
115
+ modelRole: string;
108
116
  }>[];
109
117
  }>;
110
118
  modelGroups: Readonly<{
@@ -134,7 +142,7 @@ export declare function projectAdapterModelUsage(usage: ReadableAdapterUsageAtta
134
142
  readonly collectionComplete: boolean;
135
143
  readonly reasons: readonly ("usage-not-recorded" | "source-invalid" | "adapter-usage-required" | "collection-incomplete" | "call-status-unknown" | "no-calls" | "cache-read-missing" | "input-total-missing" | "zero-input-total" | "unsafe-token-total")[];
136
144
  };
137
- readonly modelSlots: readonly {
145
+ readonly roles: readonly {
138
146
  readonly rate: {
139
147
  readonly state: "exact";
140
148
  readonly value: number;
@@ -149,7 +157,7 @@ export declare function projectAdapterModelUsage(usage: ReadableAdapterUsageAtta
149
157
  readonly unknownStatusCalls: number;
150
158
  readonly collectionComplete: boolean;
151
159
  readonly reasons: readonly ("usage-not-recorded" | "source-invalid" | "adapter-usage-required" | "collection-incomplete" | "call-status-unknown" | "no-calls" | "cache-read-missing" | "input-total-missing" | "zero-input-total" | "unsafe-token-total")[];
152
- readonly modelSlot: string | null;
160
+ readonly modelRole: string | null;
153
161
  }[];
154
162
  readonly models: readonly {
155
163
  readonly rate: {
@@ -166,7 +174,7 @@ export declare function projectAdapterModelUsage(usage: ReadableAdapterUsageAtta
166
174
  readonly unknownStatusCalls: number;
167
175
  readonly collectionComplete: boolean;
168
176
  readonly reasons: readonly ("usage-not-recorded" | "source-invalid" | "adapter-usage-required" | "collection-incomplete" | "call-status-unknown" | "no-calls" | "cache-read-missing" | "input-total-missing" | "zero-input-total" | "unsafe-token-total")[];
169
- readonly modelSlot: string | null;
177
+ readonly modelRole: string | null;
170
178
  readonly provider: string | null;
171
179
  readonly model: string | null;
172
180
  }[];
@@ -179,14 +187,14 @@ export declare function projectAdapterModelUsage(usage: ReadableAdapterUsageAtta
179
187
  recordedCalls: number | null;
180
188
  model: string | null;
181
189
  reasoningEffort: string | null;
182
- modelSlot: string;
190
+ modelRole: string;
183
191
  }>[];
184
192
  }>;
185
193
  modelGroups: Readonly<{
186
194
  state: "available";
187
195
  basis: "recorded-calls";
188
196
  groups: readonly Readonly<{
189
- modelSlot: string | null;
197
+ modelRole: string | null;
190
198
  provider: string | null;
191
199
  model: string | null;
192
200
  recordedCalls: number;
@@ -36,9 +36,9 @@ const SummaryShape = effect_1.Schema.Struct(fields);
36
36
  const Summary = SummaryShape.check(effect_1.Schema.makeFilter(consistent));
37
37
  exports.CacheReadReportSchema = effect_1.Schema.Struct({
38
38
  total: Summary,
39
- modelSlots: effect_1.Schema.Array(effect_1.Schema.Struct({ modelSlot: effect_1.Schema.NullOr(effect_1.Schema.String), ...fields }).check(effect_1.Schema.makeFilter(consistent))),
40
- models: effect_1.Schema.Array(effect_1.Schema.Struct({ modelSlot: effect_1.Schema.NullOr(effect_1.Schema.String), provider: effect_1.Schema.NullOr(effect_1.Schema.String), model: effect_1.Schema.NullOr(effect_1.Schema.String), ...fields }).check(effect_1.Schema.makeFilter(consistent))),
41
- }).check(effect_1.Schema.makeFilter((value) => value.modelSlots.length <= 65 && value.models.length <= 4000));
39
+ roles: effect_1.Schema.Array(effect_1.Schema.Struct({ modelRole: effect_1.Schema.NullOr(effect_1.Schema.String), ...fields }).check(effect_1.Schema.makeFilter(consistent))),
40
+ models: effect_1.Schema.Array(effect_1.Schema.Struct({ modelRole: effect_1.Schema.NullOr(effect_1.Schema.String), provider: effect_1.Schema.NullOr(effect_1.Schema.String), model: effect_1.Schema.NullOr(effect_1.Schema.String), ...fields }).check(effect_1.Schema.makeFilter(consistent))),
41
+ }).check(effect_1.Schema.makeFilter((value) => value.roles.length <= 65 && value.models.length <= 4000));
42
42
  function summary(calls, collectionComplete, absent) {
43
43
  let numerator = 0;
44
44
  let denominator = 0;
@@ -82,18 +82,18 @@ function summary(calls, collectionComplete, absent) {
82
82
  }
83
83
  const compare = (a, b) => a === b ? 0 : a === null ? -1 : b === null ? 1 : a < b ? -1 : 1;
84
84
  /** A historical collection marked complete is not proof of an explicit producer seal. */
85
- function projectCacheRead(usage, slots, producerCompletenessKnown, absent = "usage-not-recorded") {
85
+ function projectCacheRead(usage, roles, producerCompletenessKnown, absent = "usage-not-recorded") {
86
86
  if (usage === null)
87
- return Object.freeze({ total: summary([], false, absent), modelSlots: Object.freeze([]), models: Object.freeze([]) });
87
+ return Object.freeze({ total: summary([], false, absent), roles: Object.freeze([]), models: Object.freeze([]) });
88
88
  const complete = producerCompletenessKnown && usage.collection.state === "complete";
89
- const bySlot = new Map(Object.keys(slots ?? {}).map((slot) => [slot, []]));
89
+ const byRole = new Map(Object.keys(roles ?? {}).map((role) => [role, []]));
90
90
  const byModel = new Map();
91
91
  for (const call of usage.calls) {
92
- const slot = bySlot.get(call.modelSlot);
93
- if (slot === undefined)
94
- bySlot.set(call.modelSlot, [call]);
92
+ const role = byRole.get(call.modelSlot);
93
+ if (role === undefined)
94
+ byRole.set(call.modelSlot, [call]);
95
95
  else
96
- slot.push(call);
96
+ role.push(call);
97
97
  const key = JSON.stringify([call.modelSlot, call.provider, call.model]);
98
98
  const model = byModel.get(key);
99
99
  if (model === undefined)
@@ -102,11 +102,11 @@ function projectCacheRead(usage, slots, producerCompletenessKnown, absent = "usa
102
102
  model.push(call);
103
103
  }
104
104
  const models = [...byModel.values()].map((calls) => {
105
- const { modelSlot, provider, model } = calls[0];
106
- return Object.freeze({ modelSlot, provider, model, ...summary(calls, complete) });
107
- }).sort((a, b) => compare(a.modelSlot, b.modelSlot) || compare(a.provider, b.provider) || compare(a.model, b.model));
105
+ const { modelSlot: modelRole, provider, model } = calls[0];
106
+ return Object.freeze({ modelRole, provider, model, ...summary(calls, complete) });
107
+ }).sort((a, b) => compare(a.modelRole, b.modelRole) || compare(a.provider, b.provider) || compare(a.model, b.model));
108
108
  return Object.freeze({ total: summary(usage.calls, complete),
109
- modelSlots: Object.freeze([...bySlot].sort(([a], [b]) => compare(a, b)).map(([modelSlot, calls]) => Object.freeze({ modelSlot, ...summary(calls, complete) }))),
109
+ roles: Object.freeze([...byRole].sort(([a], [b]) => compare(a, b)).map(([modelRole, calls]) => Object.freeze({ modelRole, ...summary(calls, complete) }))),
110
110
  models: Object.freeze(models),
111
111
  });
112
112
  }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AAC;KAChC,CAAC,CAAC;AACP,CAAC","sourcesContent":["import { Schema } from \"effect\";\nimport type { ResolvedModelSlots } from \"../model-slots.ts\";\nimport type { AdapterUsageCall, ReadableAdapterUsageAttachment } from \"../record/family/adapter-usage/schema.ts\";\nimport { NonNegativeSafeIntegerSchema } from \"../record/family/common.ts\";\nconst Reason = Schema.Literals([\n \"usage-not-recorded\", \"source-invalid\", \"adapter-usage-required\", \"collection-incomplete\",\n \"call-status-unknown\", \"no-calls\", \"cache-read-missing\", \"input-total-missing\", \"zero-input-total\", \"unsafe-token-total\",\n]);\ntype Reason = typeof Reason.Type;\nconst Rate = Schema.Union([\n Schema.Struct({ state: Schema.Literal(\"exact\"), value: Schema.Number.check(Schema.makeFilter((value) => Number.isFinite(value) && value >= 0 && value <= 1)) }),\n Schema.Struct({ state: Schema.Literal(\"unavailable\"), reason: Reason }),\n]);\nconst fields = {\n rate: Rate,\n recordedCalls: NonNegativeSafeIntegerSchema,\n coveredCalls: NonNegativeSafeIntegerSchema,\n missingCacheReadCalls: NonNegativeSafeIntegerSchema,\n missingInputTotalCalls: NonNegativeSafeIntegerSchema,\n unknownStatusCalls: NonNegativeSafeIntegerSchema,\n collectionComplete: Schema.Boolean,\n reasons: Schema.Array(Reason),\n};\nconst consistent = (value: typeof SummaryShape.Type): boolean => {\n const count = value.recordedCalls;\n return count <= 4000 && value.coveredCalls <= count && value.unknownStatusCalls <= count &&\n value.missingCacheReadCalls <= count && value.missingInputTotalCalls <= count &&\n value.coveredCalls <= count - Math.max(value.missingCacheReadCalls, value.missingInputTotalCalls) &&\n value.coveredCalls >= count - value.missingCacheReadCalls - value.missingInputTotalCalls &&\n new Set(value.reasons).size === value.reasons.length &&\n (value.rate.state === \"exact\" ? value.reasons.length === 0 && value.collectionComplete && count > 0 &&\n value.coveredCalls === count && value.unknownStatusCalls === 0 : value.rate.reason === value.reasons[0]);\n};\nconst SummaryShape = Schema.Struct(fields);\nconst Summary = SummaryShape.check(Schema.makeFilter(consistent));\n/** Token-weighted cache reading, with explicit input coverage and collection completeness. */\nexport type CacheReadSummary = typeof Summary.Type;\nexport const CacheReadReportSchema = Schema.Struct({\n total: Summary,\n modelSlots: Schema.Array(Schema.Struct({ modelSlot: Schema.NullOr(Schema.String), ...fields }).check(Schema.makeFilter(consistent))),\n models: Schema.Array(Schema.Struct({ modelSlot: Schema.NullOr(Schema.String), provider: Schema.NullOr(Schema.String), model: Schema.NullOr(Schema.String), ...fields }).check(Schema.makeFilter(consistent))),\n}).check(Schema.makeFilter((value) => value.modelSlots.length <= 65 && value.models.length <= 4000));\n/** Complete per-Attempt report; unknown model identities remain null. */\nexport type CacheReadReport = typeof CacheReadReportSchema.Type;\nfunction summary(calls: readonly AdapterUsageCall[], collectionComplete: boolean, absent?: Reason): CacheReadSummary {\n let numerator = 0;\n let denominator = 0;\n let coveredCalls = 0;\n let missingCacheReadCalls = 0;\n let missingInputTotalCalls = 0;\n let unknownStatusCalls = 0;\n let unsafe = false;\n for (const call of calls) {\n const total = call.inputTotalTokens ?? (call.inputTokens !== null && call.cacheReadTokens !== null && call.cacheWriteTokens !== null\n ? call.inputTokens + call.cacheReadTokens + call.cacheWriteTokens : null);\n if (call.status === \"unknown\")\n unknownStatusCalls++;\n if (call.cacheReadTokens === null)\n missingCacheReadCalls++;\n else\n numerator += call.cacheReadTokens;\n if (total === null)\n missingInputTotalCalls++;\n else\n denominator += total;\n if (total !== null && call.cacheReadTokens !== null)\n coveredCalls++;\n if ((total !== null && !Number.isSafeInteger(total)) || !Number.isSafeInteger(numerator) || !Number.isSafeInteger(denominator))\n unsafe = true;\n }\n const reasons: Reason[] = absent === undefined ? [\n ...(!collectionComplete ? [\"collection-incomplete\" as const] : []),\n ...(unknownStatusCalls > 0 ? [\"call-status-unknown\" as const] : []),\n ...(calls.length === 0 ? [\"no-calls\" as const] : []),\n ...(missingCacheReadCalls > 0 ? [\"cache-read-missing\" as const] : []),\n ...(missingInputTotalCalls > 0 ? [\"input-total-missing\" as const] : []),\n ...(calls.length > 0 && missingInputTotalCalls === 0 && denominator === 0 ? [\"zero-input-total\" as const] : []),\n ...(unsafe ? [\"unsafe-token-total\" as const] : []),\n ] : [absent];\n const rate: CacheReadSummary[\"rate\"] = reasons.length === 0\n ? Object.freeze({ state: \"exact\", value: numerator / denominator })\n : Object.freeze({ state: \"unavailable\", reason: reasons[0]! });\n return Object.freeze({ rate, recordedCalls: calls.length, coveredCalls, missingCacheReadCalls, missingInputTotalCalls,\n unknownStatusCalls, collectionComplete, reasons: Object.freeze(reasons) });\n}\nconst compare = (a: string | null, b: string | null): number => a === b ? 0 : a === null ? -1 : b === null ? 1 : a < b ? -1 : 1;\n/** A historical collection marked complete is not proof of an explicit producer seal. */\nexport function projectCacheRead(usage: ReadableAdapterUsageAttachment | null, slots: ResolvedModelSlots | undefined, producerCompletenessKnown: boolean, absent: \"usage-not-recorded\" | \"source-invalid\" | \"adapter-usage-required\" = \"usage-not-recorded\"): CacheReadReport {\n if (usage === null)\n return Object.freeze({ total: summary([], false, absent), modelSlots: Object.freeze([]), models: Object.freeze([]) });\n const complete = producerCompletenessKnown && usage.collection.state === \"complete\";\n const bySlot = new Map<string | null, AdapterUsageCall[]>(Object.keys(slots ?? {}).map((slot) => [slot, []]));\n const byModel = new Map<string, AdapterUsageCall[]>();\n for (const call of usage.calls) {\n const slot = bySlot.get(call.modelSlot);\n if (slot === undefined)\n bySlot.set(call.modelSlot, [call]);\n else\n slot.push(call);\n const key = JSON.stringify([call.modelSlot, call.provider, call.model]);\n const model = byModel.get(key);\n if (model === undefined)\n byModel.set(key, [call]);\n else\n model.push(call);\n }\n const models = [...byModel.values()].map((calls) => {\n const { modelSlot, provider, model } = calls[0]!;\n return Object.freeze({ modelSlot, provider, model, ...summary(calls, complete) });\n }).sort((a, b) => compare(a.modelSlot, b.modelSlot) || compare(a.provider, b.provider) || compare(a.model, b.model));\n return Object.freeze({ total: summary(usage.calls, complete),\n modelSlots: Object.freeze([...bySlot].sort(([a], [b]) => compare(a, b)).map(([modelSlot, calls]) => Object.freeze({ modelSlot, ...summary(calls, complete) }))),\n models: Object.freeze(models),\n });\n}\n"]}
1
+ {"version":3,"file":"cache-read.js","sourceRoot":"","sources":["cache-read.ts"],"names":[],"mappings":";;;AAuFA,4CA2BC;AAlHD,mCAAgC;AAGhC,0DAA0E;AAC1E,MAAM,MAAM,GAAG,eAAM,CAAC,QAAQ,CAAC;IAC3B,oBAAoB,EAAE,gBAAgB,EAAE,wBAAwB,EAAE,uBAAuB;IACzF,qBAAqB,EAAE,UAAU,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,oBAAoB;CAC3H,CAAC,CAAC;AAEH,MAAM,IAAI,GAAG,eAAM,CAAC,KAAK,CAAC;IACtB,eAAM,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,eAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,eAAM,CAAC,MAAM,CAAC,KAAK,CAAC,eAAM,CAAC,UAAU,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;IAC/J,eAAM,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,eAAM,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;CAC1E,CAAC,CAAC;AACH,MAAM,MAAM,GAAG;IACX,IAAI,EAAE,IAAI;IACV,aAAa,EAAE,wCAA4B;IAC3C,YAAY,EAAE,wCAA4B;IAC1C,qBAAqB,EAAE,wCAA4B;IACnD,sBAAsB,EAAE,wCAA4B;IACpD,kBAAkB,EAAE,wCAA4B;IAChD,kBAAkB,EAAE,eAAM,CAAC,OAAO;IAClC,OAAO,EAAE,eAAM,CAAC,KAAK,CAAC,MAAM,CAAC;CAChC,CAAC;AACF,MAAM,UAAU,GAAG,CAAC,KAA+B,EA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,CAAC,EAAE,CAAC,CAAC,CAAC;QAC1J,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC;KAChC,CAAC,CAAC;AACP,CAAC","sourcesContent":["import { Schema } from \"effect\";\nimport type { ResolvedModelRoles } from \"../model-roles.ts\";\nimport type { AdapterUsageCall, ReadableAdapterUsageAttachment } from \"../record/family/adapter-usage/schema.ts\";\nimport { NonNegativeSafeIntegerSchema } from \"../record/family/common.ts\";\nconst Reason = Schema.Literals([\n \"usage-not-recorded\", \"source-invalid\", \"adapter-usage-required\", \"collection-incomplete\",\n \"call-status-unknown\", \"no-calls\", \"cache-read-missing\", \"input-total-missing\", \"zero-input-total\", \"unsafe-token-total\",\n]);\ntype Reason = typeof Reason.Type;\nconst Rate = Schema.Union([\n Schema.Struct({ state: Schema.Literal(\"exact\"), value: Schema.Number.check(Schema.makeFilter((value) => Number.isFinite(value) && value >= 0 && value <= 1)) }),\n Schema.Struct({ state: Schema.Literal(\"unavailable\"), reason: Reason }),\n]);\nconst fields = {\n rate: Rate,\n recordedCalls: NonNegativeSafeIntegerSchema,\n coveredCalls: NonNegativeSafeIntegerSchema,\n missingCacheReadCalls: NonNegativeSafeIntegerSchema,\n missingInputTotalCalls: NonNegativeSafeIntegerSchema,\n unknownStatusCalls: NonNegativeSafeIntegerSchema,\n collectionComplete: Schema.Boolean,\n reasons: Schema.Array(Reason),\n};\nconst consistent = (value: typeof SummaryShape.Type): boolean => {\n const count = value.recordedCalls;\n return count <= 4000 && value.coveredCalls <= count && value.unknownStatusCalls <= count &&\n value.missingCacheReadCalls <= count && value.missingInputTotalCalls <= count &&\n value.coveredCalls <= count - Math.max(value.missingCacheReadCalls, value.missingInputTotalCalls) &&\n value.coveredCalls >= count - value.missingCacheReadCalls - value.missingInputTotalCalls &&\n new Set(value.reasons).size === value.reasons.length &&\n (value.rate.state === \"exact\" ? value.reasons.length === 0 && value.collectionComplete && count > 0 &&\n value.coveredCalls === count && value.unknownStatusCalls === 0 : value.rate.reason === value.reasons[0]);\n};\nconst SummaryShape = Schema.Struct(fields);\nconst Summary = SummaryShape.check(Schema.makeFilter(consistent));\n/** Token-weighted cache reading, with explicit input coverage and collection completeness. */\nexport type CacheReadSummary = typeof Summary.Type;\nexport const CacheReadReportSchema = Schema.Struct({\n total: Summary,\n roles: Schema.Array(Schema.Struct({ modelRole: Schema.NullOr(Schema.String), ...fields }).check(Schema.makeFilter(consistent))),\n models: Schema.Array(Schema.Struct({ modelRole: Schema.NullOr(Schema.String), provider: Schema.NullOr(Schema.String), model: Schema.NullOr(Schema.String), ...fields }).check(Schema.makeFilter(consistent))),\n}).check(Schema.makeFilter((value) => value.roles.length <= 65 && value.models.length <= 4000));\n/** Complete per-Attempt report; unknown model identities remain null. */\nexport type CacheReadReport = typeof CacheReadReportSchema.Type;\nfunction summary(calls: readonly AdapterUsageCall[], collectionComplete: boolean, absent?: Reason): CacheReadSummary {\n let numerator = 0;\n let denominator = 0;\n let coveredCalls = 0;\n let missingCacheReadCalls = 0;\n let missingInputTotalCalls = 0;\n let unknownStatusCalls = 0;\n let unsafe = false;\n for (const call of calls) {\n const total = call.inputTotalTokens ?? (call.inputTokens !== null && call.cacheReadTokens !== null && call.cacheWriteTokens !== null\n ? call.inputTokens + call.cacheReadTokens + call.cacheWriteTokens : null);\n if (call.status === \"unknown\")\n unknownStatusCalls++;\n if (call.cacheReadTokens === null)\n missingCacheReadCalls++;\n else\n numerator += call.cacheReadTokens;\n if (total === null)\n missingInputTotalCalls++;\n else\n denominator += total;\n if (total !== null && call.cacheReadTokens !== null)\n coveredCalls++;\n if ((total !== null && !Number.isSafeInteger(total)) || !Number.isSafeInteger(numerator) || !Number.isSafeInteger(denominator))\n unsafe = true;\n }\n const reasons: Reason[] = absent === undefined ? [\n ...(!collectionComplete ? [\"collection-incomplete\" as const] : []),\n ...(unknownStatusCalls > 0 ? [\"call-status-unknown\" as const] : []),\n ...(calls.length === 0 ? [\"no-calls\" as const] : []),\n ...(missingCacheReadCalls > 0 ? [\"cache-read-missing\" as const] : []),\n ...(missingInputTotalCalls > 0 ? [\"input-total-missing\" as const] : []),\n ...(calls.length > 0 && missingInputTotalCalls === 0 && denominator === 0 ? [\"zero-input-total\" as const] : []),\n ...(unsafe ? [\"unsafe-token-total\" as const] : []),\n ] : [absent];\n const rate: CacheReadSummary[\"rate\"] = reasons.length === 0\n ? Object.freeze({ state: \"exact\", value: numerator / denominator })\n : Object.freeze({ state: \"unavailable\", reason: reasons[0]! });\n return Object.freeze({ rate, recordedCalls: calls.length, coveredCalls, missingCacheReadCalls, missingInputTotalCalls,\n unknownStatusCalls, collectionComplete, reasons: Object.freeze(reasons) });\n}\nconst compare = (a: string | null, b: string | null): number => a === b ? 0 : a === null ? -1 : b === null ? 1 : a < b ? -1 : 1;\n/** A historical collection marked complete is not proof of an explicit producer seal. */\nexport function projectCacheRead(usage: ReadableAdapterUsageAttachment | null, roles: ResolvedModelRoles | undefined, producerCompletenessKnown: boolean, absent: \"usage-not-recorded\" | \"source-invalid\" | \"adapter-usage-required\" = \"usage-not-recorded\"): CacheReadReport {\n if (usage === null)\n return Object.freeze({ total: summary([], false, absent), roles: Object.freeze([]), models: Object.freeze([]) });\n const complete = producerCompletenessKnown && usage.collection.state === \"complete\";\n const byRole = new Map<string | null, AdapterUsageCall[]>(Object.keys(roles ?? {}).map((role) => [role, []]));\n const byModel = new Map<string, AdapterUsageCall[]>();\n for (const call of usage.calls) {\n const role = byRole.get(call.modelSlot);\n if (role === undefined)\n byRole.set(call.modelSlot, [call]);\n else\n role.push(call);\n const key = JSON.stringify([call.modelSlot, call.provider, call.model]);\n const model = byModel.get(key);\n if (model === undefined)\n byModel.set(key, [call]);\n else\n model.push(call);\n }\n const models = [...byModel.values()].map((calls) => {\n const { modelSlot: modelRole, provider, model } = calls[0]!;\n return Object.freeze({ modelRole, provider, model, ...summary(calls, complete) });\n }).sort((a, b) => compare(a.modelRole, b.modelRole) || compare(a.provider, b.provider) || compare(a.model, b.model));\n return Object.freeze({ total: summary(usage.calls, complete),\n roles: Object.freeze([...byRole].sort(([a], [b]) => compare(a, b)).map(([modelRole, calls]) => Object.freeze({ modelRole, ...summary(calls, complete) }))),\n models: Object.freeze(models),\n });\n}\n"]}