@tangle-network/agent-eval 0.129.0 → 0.130.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 (427) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/README.md +1 -0
  3. package/dist/active-curriculum-C4mk67HP.js +214 -0
  4. package/dist/active-curriculum-C4mk67HP.js.map +1 -0
  5. package/dist/adversarial-smnADNFS.d.ts +21 -0
  6. package/dist/adversarial-smnADNFS.d.ts.map +1 -0
  7. package/dist/analyst/index.d.ts +81 -2872
  8. package/dist/analyst/index.d.ts.map +1 -0
  9. package/dist/analyst/index.js +319 -360
  10. package/dist/analyst/index.js.map +1 -1
  11. package/dist/analyst-BkTS3C58.d.ts +89 -0
  12. package/dist/analyst-BkTS3C58.d.ts.map +1 -0
  13. package/dist/analyst-LsnNpSkm.js +152 -0
  14. package/dist/analyst-LsnNpSkm.js.map +1 -0
  15. package/dist/analyze-runs-C1CavBMk.js +1067 -0
  16. package/dist/analyze-runs-C1CavBMk.js.map +1 -0
  17. package/dist/analyze-runs-FsgYCinh.d.ts +72 -0
  18. package/dist/analyze-runs-FsgYCinh.d.ts.map +1 -0
  19. package/dist/attribute-vocabulary-DLJ6303h.d.ts +54 -0
  20. package/dist/attribute-vocabulary-DLJ6303h.d.ts.map +1 -0
  21. package/dist/authenticity/index.d.ts +81 -79
  22. package/dist/authenticity/index.d.ts.map +1 -0
  23. package/dist/authenticity/index.js +209 -193
  24. package/dist/authenticity/index.js.map +1 -1
  25. package/dist/baseline-HsBvw_dk.js +550 -0
  26. package/dist/baseline-HsBvw_dk.js.map +1 -0
  27. package/dist/baseline-hG3K85h4.d.ts +125 -0
  28. package/dist/baseline-hG3K85h4.d.ts.map +1 -0
  29. package/dist/belief-state/index.d.ts +448 -1188
  30. package/dist/belief-state/index.d.ts.map +1 -0
  31. package/dist/belief-state/index.js +1617 -1709
  32. package/dist/belief-state/index.js.map +1 -1
  33. package/dist/benchmarks/index.d.ts +2 -891
  34. package/dist/benchmarks/index.js +2 -60
  35. package/dist/benchmarks-DviOvUNr.js +754 -0
  36. package/dist/benchmarks-DviOvUNr.js.map +1 -0
  37. package/dist/builder-eval/index.d.ts +150 -662
  38. package/dist/builder-eval/index.d.ts.map +1 -0
  39. package/dist/builder-eval/index.js +356 -345
  40. package/dist/builder-eval/index.js.map +1 -1
  41. package/dist/calibration-CNWWA6K8.js +94 -0
  42. package/dist/calibration-CNWWA6K8.js.map +1 -0
  43. package/dist/campaign/index.d.ts +5 -6381
  44. package/dist/campaign/index.js +3 -213
  45. package/dist/campaign-CBKZvQ1H.js +3885 -0
  46. package/dist/campaign-CBKZvQ1H.js.map +1 -0
  47. package/dist/cli.d.ts +1 -1
  48. package/dist/cli.js +164 -175
  49. package/dist/cli.js.map +1 -1
  50. package/dist/client-C97NMzqi.d.ts +581 -0
  51. package/dist/client-C97NMzqi.d.ts.map +1 -0
  52. package/dist/client-CYzbdJOZ.js +637 -0
  53. package/dist/client-CYzbdJOZ.js.map +1 -0
  54. package/dist/code-agent-session-BjkMTQ7H.js +1390 -0
  55. package/dist/code-agent-session-BjkMTQ7H.js.map +1 -0
  56. package/dist/code-agent-session-DqqgOJaz.d.ts +143 -0
  57. package/dist/code-agent-session-DqqgOJaz.d.ts.map +1 -0
  58. package/dist/concurrency-DIxRZF_J.js +85 -0
  59. package/dist/concurrency-DIxRZF_J.js.map +1 -0
  60. package/dist/contract/index.d.ts +645 -5565
  61. package/dist/contract/index.d.ts.map +1 -0
  62. package/dist/contract/index.js +1730 -1938
  63. package/dist/contract/index.js.map +1 -1
  64. package/dist/control.d.ts +3 -1030
  65. package/dist/control.js +2 -33
  66. package/dist/cost-ledger-DIgQUFZZ.js +801 -0
  67. package/dist/cost-ledger-DIgQUFZZ.js.map +1 -0
  68. package/dist/cost-ledger-Dye6jCgg.d.ts +236 -0
  69. package/dist/cost-ledger-Dye6jCgg.d.ts.map +1 -0
  70. package/dist/dataset-BvtnC8Dc.d.ts +115 -0
  71. package/dist/dataset-BvtnC8Dc.d.ts.map +1 -0
  72. package/dist/default-registry-C-vFCSEc.js +2579 -0
  73. package/dist/default-registry-C-vFCSEc.js.map +1 -0
  74. package/dist/default-registry-CNPo-Vsb.d.ts +540 -0
  75. package/dist/default-registry-CNPo-Vsb.d.ts.map +1 -0
  76. package/dist/emitter-CPBAhxum.js +266 -0
  77. package/dist/emitter-CPBAhxum.js.map +1 -0
  78. package/dist/emitter-DGQGoLyj.d.ts +113 -0
  79. package/dist/emitter-DGQGoLyj.d.ts.map +1 -0
  80. package/dist/errors-8YnH8WlF.js +64 -0
  81. package/dist/errors-8YnH8WlF.js.map +1 -0
  82. package/dist/errors-CEk209JS.d.ts +76 -0
  83. package/dist/errors-CEk209JS.d.ts.map +1 -0
  84. package/dist/eval-campaign-DEm6c8ru.js +349 -0
  85. package/dist/eval-campaign-DEm6c8ru.js.map +1 -0
  86. package/dist/execution-tracks-CpgFPpS5.js +93 -0
  87. package/dist/execution-tracks-CpgFPpS5.js.map +1 -0
  88. package/dist/exporters-q9iL-2Jf.js +148 -0
  89. package/dist/exporters-q9iL-2Jf.js.map +1 -0
  90. package/dist/extract-usage-BrQ8mCLX.js +155 -0
  91. package/dist/extract-usage-BrQ8mCLX.js.map +1 -0
  92. package/dist/failure-cluster-CqcvCcdR.d.ts +59 -0
  93. package/dist/failure-cluster-CqcvCcdR.d.ts.map +1 -0
  94. package/dist/feedback-trajectory-CVaeREXV.d.ts +340 -0
  95. package/dist/feedback-trajectory-CVaeREXV.d.ts.map +1 -0
  96. package/dist/fuzz.d.ts +320 -646
  97. package/dist/fuzz.d.ts.map +1 -0
  98. package/dist/fuzz.js +670 -618
  99. package/dist/fuzz.js.map +1 -1
  100. package/dist/hf-dataset-DBJXXoY1.js +763 -0
  101. package/dist/hf-dataset-DBJXXoY1.js.map +1 -0
  102. package/dist/hosted/index.d.ts +11 -831
  103. package/dist/hosted/index.d.ts.map +1 -0
  104. package/dist/hosted/index.js +2 -37
  105. package/dist/index-2JJSA6-r2.d.ts +926 -0
  106. package/dist/index-2JJSA6-r2.d.ts.map +1 -0
  107. package/dist/index-6N0aYmpW.d.ts +217 -0
  108. package/dist/index-6N0aYmpW.d.ts.map +1 -0
  109. package/dist/index-BAvgST_9.d.ts +131 -0
  110. package/dist/index-BAvgST_9.d.ts.map +1 -0
  111. package/dist/index-BvnJuTGD.d.ts +68 -0
  112. package/dist/index-BvnJuTGD.d.ts.map +1 -0
  113. package/dist/index-C61Wi7yg.d.ts +547 -0
  114. package/dist/index-C61Wi7yg.d.ts.map +1 -0
  115. package/dist/index-CAPUUKaM.d.ts +335 -0
  116. package/dist/index-CAPUUKaM.d.ts.map +1 -0
  117. package/dist/index-DE5fb3EC.d.ts +2244 -0
  118. package/dist/index-DE5fb3EC.d.ts.map +1 -0
  119. package/dist/index-DSC51roc.d.ts +102 -0
  120. package/dist/index-DSC51roc.d.ts.map +1 -0
  121. package/dist/index.d.ts +3755 -15555
  122. package/dist/index.d.ts.map +1 -0
  123. package/dist/index.js +11182 -11216
  124. package/dist/index.js.map +1 -1
  125. package/dist/integrity-BzRbCHzi.js +424 -0
  126. package/dist/integrity-BzRbCHzi.js.map +1 -0
  127. package/dist/integrity-rmVhXWA7.d.ts +61 -0
  128. package/dist/integrity-rmVhXWA7.d.ts.map +1 -0
  129. package/dist/judge-calibration-DFtEMlde.d.ts +146 -0
  130. package/dist/judge-calibration-DFtEMlde.d.ts.map +1 -0
  131. package/dist/ledger-core/index.d.ts +2 -0
  132. package/dist/ledger-core/index.js +2 -0
  133. package/dist/ledger-core-DtZz1RG0.js +388 -0
  134. package/dist/ledger-core-DtZz1RG0.js.map +1 -0
  135. package/dist/llm-client--GR4JbZE.js +687 -0
  136. package/dist/llm-client--GR4JbZE.js.map +1 -0
  137. package/dist/llm-client-B_nIBlYo.d.ts +290 -0
  138. package/dist/llm-client-B_nIBlYo.d.ts.map +1 -0
  139. package/dist/matrix/index.d.ts +3 -155
  140. package/dist/matrix/index.js +2 -8
  141. package/dist/matrix-BzQnu2S6.js +270 -0
  142. package/dist/matrix-BzQnu2S6.js.map +1 -0
  143. package/dist/meta-eval/index.d.ts +4 -1027
  144. package/dist/meta-eval/index.js +393 -390
  145. package/dist/meta-eval/index.js.map +1 -1
  146. package/dist/metrics-C9YY1OcL.js +239 -0
  147. package/dist/metrics-C9YY1OcL.js.map +1 -0
  148. package/dist/mint-yN2M2eh0.js +201 -0
  149. package/dist/mint-yN2M2eh0.js.map +1 -0
  150. package/dist/multi-layer-verifier-BHY1gWAc.d.ts +138 -0
  151. package/dist/multi-layer-verifier-BHY1gWAc.d.ts.map +1 -0
  152. package/dist/multishot/index.d.ts +273 -480
  153. package/dist/multishot/index.d.ts.map +1 -0
  154. package/dist/multishot/index.js +595 -548
  155. package/dist/multishot/index.js.map +1 -1
  156. package/dist/off-policy-DvgzvtIx.js +220 -0
  157. package/dist/off-policy-DvgzvtIx.js.map +1 -0
  158. package/dist/off-policy-mskQw8Mb.d.ts +153 -0
  159. package/dist/off-policy-mskQw8Mb.d.ts.map +1 -0
  160. package/dist/openapi.json +1 -1
  161. package/dist/opencode-sqlite-BGrHeDu3.js +318 -0
  162. package/dist/opencode-sqlite-BGrHeDu3.js.map +1 -0
  163. package/dist/outcome-store-BYHIuO0e.d.ts +65 -0
  164. package/dist/outcome-store-BYHIuO0e.d.ts.map +1 -0
  165. package/dist/outcome-store-ChBKlTd_.js +75 -0
  166. package/dist/outcome-store-ChBKlTd_.js.map +1 -0
  167. package/dist/paired-arms-D9D0wXj2.js +260 -0
  168. package/dist/paired-arms-D9D0wXj2.js.map +1 -0
  169. package/dist/pipelines/index.d.ts +95 -532
  170. package/dist/pipelines/index.d.ts.map +1 -0
  171. package/dist/pipelines/index.js +497 -478
  172. package/dist/pipelines/index.js.map +1 -1
  173. package/dist/pre-registration-DakwTRXk.js +96 -0
  174. package/dist/pre-registration-DakwTRXk.js.map +1 -0
  175. package/dist/propose-review-control-LhIWGzHl.js +1458 -0
  176. package/dist/propose-review-control-LhIWGzHl.js.map +1 -0
  177. package/dist/query-CJ_DX8vl.d.ts +28 -0
  178. package/dist/query-CJ_DX8vl.d.ts.map +1 -0
  179. package/dist/query-Di7eEQ79.js +83 -0
  180. package/dist/query-Di7eEQ79.js.map +1 -0
  181. package/dist/raw-provider-sink-BQd7mzyT.js +201 -0
  182. package/dist/raw-provider-sink-BQd7mzyT.js.map +1 -0
  183. package/dist/raw-provider-sink-BU29Sh8h.d.ts +134 -0
  184. package/dist/raw-provider-sink-BU29Sh8h.d.ts.map +1 -0
  185. package/dist/redact-7Aq1ukl-.js +107 -0
  186. package/dist/redact-7Aq1ukl-.js.map +1 -0
  187. package/dist/release-report-Cz9NKH39.js +603 -0
  188. package/dist/release-report-Cz9NKH39.js.map +1 -0
  189. package/dist/release-report-mvB2G4_J.d.ts +244 -0
  190. package/dist/release-report-mvB2G4_J.d.ts.map +1 -0
  191. package/dist/replay-GnyotH0J.js +1741 -0
  192. package/dist/replay-GnyotH0J.js.map +1 -0
  193. package/dist/replay-OoidtG1E.d.ts +749 -0
  194. package/dist/replay-OoidtG1E.d.ts.map +1 -0
  195. package/dist/reporting.d.ts +6 -1312
  196. package/dist/reporting.js +6 -51
  197. package/dist/researcher-CwTdwXG1.d.ts +314 -0
  198. package/dist/researcher-CwTdwXG1.d.ts.map +1 -0
  199. package/dist/reward-hacking-eAnOsynk.d.ts +224 -0
  200. package/dist/reward-hacking-eAnOsynk.d.ts.map +1 -0
  201. package/dist/reward-hacking-qipEpKvY.js +596 -0
  202. package/dist/reward-hacking-qipEpKvY.js.map +1 -0
  203. package/dist/reward-nw2xZGZG.js +137 -0
  204. package/dist/reward-nw2xZGZG.js.map +1 -0
  205. package/dist/rl.d.ts +760 -4010
  206. package/dist/rl.d.ts.map +1 -0
  207. package/dist/rl.js +2325 -1958
  208. package/dist/rl.js.map +1 -1
  209. package/dist/rolldown-runtime-8H4AJuhK.js +14 -0
  210. package/dist/rollout/index.d.ts +3 -2087
  211. package/dist/rollout/index.js +8 -168
  212. package/dist/rollout-BOYjemfR.js +624 -0
  213. package/dist/rollout-BOYjemfR.js.map +1 -0
  214. package/dist/rubric-predictive-validity-B3xmbmS1.js +141 -0
  215. package/dist/rubric-predictive-validity-B3xmbmS1.js.map +1 -0
  216. package/dist/rubric-predictive-validity-Ku_clp_1.d.ts +74 -0
  217. package/dist/rubric-predictive-validity-Ku_clp_1.d.ts.map +1 -0
  218. package/dist/run-evidence-ClRX_8A9.d.ts +225 -0
  219. package/dist/run-evidence-ClRX_8A9.d.ts.map +1 -0
  220. package/dist/run-record-BuoE80Dq.js +467 -0
  221. package/dist/{chunk-56TAVBOK.js.map → run-record-BuoE80Dq.js.map} +1 -1
  222. package/dist/run-record-CnZu_gjl.d.ts +357 -0
  223. package/dist/run-record-CnZu_gjl.d.ts.map +1 -0
  224. package/dist/run-score-iEEAWiBY.js +41 -0
  225. package/dist/run-score-iEEAWiBY.js.map +1 -0
  226. package/dist/runtime-trajectory-1gyaTOoC.js +93 -0
  227. package/dist/runtime-trajectory-1gyaTOoC.js.map +1 -0
  228. package/dist/runtime-trajectory-BvSZcCHD.d.ts +50 -0
  229. package/dist/runtime-trajectory-BvSZcCHD.d.ts.map +1 -0
  230. package/dist/schema-BtVldJ3T.d.ts +206 -0
  231. package/dist/schema-BtVldJ3T.d.ts.map +1 -0
  232. package/dist/schema-C6DW4ZHR.js +821 -0
  233. package/dist/schema-C6DW4ZHR.js.map +1 -0
  234. package/dist/schema-CRhEY1SO.js +69 -0
  235. package/dist/schema-CRhEY1SO.js.map +1 -0
  236. package/dist/schema-Cef2cFmb.d.ts +408 -0
  237. package/dist/schema-Cef2cFmb.d.ts.map +1 -0
  238. package/dist/semantic-concept-judge-B6cWNJ2K.js +725 -0
  239. package/dist/semantic-concept-judge-B6cWNJ2K.js.map +1 -0
  240. package/dist/sequential-Br0mAPHA.js +148 -0
  241. package/dist/sequential-Br0mAPHA.js.map +1 -0
  242. package/dist/sequential-CYwq6Ff_.d.ts +141 -0
  243. package/dist/sequential-CYwq6Ff_.d.ts.map +1 -0
  244. package/dist/series-convergence-CjO2QdRW.js +43 -0
  245. package/dist/series-convergence-CjO2QdRW.js.map +1 -0
  246. package/dist/series-convergence-ofsqPWhs.d.ts +35 -0
  247. package/dist/series-convergence-ofsqPWhs.d.ts.map +1 -0
  248. package/dist/server-m5D9cvnG.js +1040 -0
  249. package/dist/server-m5D9cvnG.js.map +1 -0
  250. package/dist/skill-usage-C_pXm7lP.d.ts +534 -0
  251. package/dist/skill-usage-C_pXm7lP.d.ts.map +1 -0
  252. package/dist/skillopt-optimization-method-B7wX7XkF.d.ts +1739 -0
  253. package/dist/skillopt-optimization-method-B7wX7XkF.d.ts.map +1 -0
  254. package/dist/skillopt-optimization-method-D4ODwFVV.js +7712 -0
  255. package/dist/skillopt-optimization-method-D4ODwFVV.js.map +1 -0
  256. package/dist/statistics-Cmj6nynr.d.ts +514 -0
  257. package/dist/statistics-Cmj6nynr.d.ts.map +1 -0
  258. package/dist/statistics-CnnxdpOg.js +1437 -0
  259. package/dist/statistics-CnnxdpOg.js.map +1 -0
  260. package/dist/store-CT9YIIve.d.ts +117 -0
  261. package/dist/store-CT9YIIve.d.ts.map +1 -0
  262. package/dist/store-CxJry_cs.d.ts +229 -0
  263. package/dist/store-CxJry_cs.d.ts.map +1 -0
  264. package/dist/storyboard/index.d.ts +84 -203
  265. package/dist/storyboard/index.d.ts.map +1 -0
  266. package/dist/storyboard/index.js +609 -542
  267. package/dist/storyboard/index.js.map +1 -1
  268. package/dist/summary-report-BNs5nmXI.js +862 -0
  269. package/dist/summary-report-BNs5nmXI.js.map +1 -0
  270. package/dist/summary-report-Cj9gdw4i.d.ts +407 -0
  271. package/dist/summary-report-Cj9gdw4i.d.ts.map +1 -0
  272. package/dist/supervisor-run/index.d.ts +2 -959
  273. package/dist/supervisor-run/index.js +2 -65
  274. package/dist/supervisor-run-_lnTLM3z.js +1679 -0
  275. package/dist/supervisor-run-_lnTLM3z.js.map +1 -0
  276. package/dist/task-failure-attributes-CQZlB3et.js +311 -0
  277. package/dist/task-failure-attributes-CQZlB3et.js.map +1 -0
  278. package/dist/test-graded-scenario-BsqWLmPt.js +318 -0
  279. package/dist/test-graded-scenario-BsqWLmPt.js.map +1 -0
  280. package/dist/test-graded-scenario-D1TaI2va.d.ts +141 -0
  281. package/dist/test-graded-scenario-D1TaI2va.d.ts.map +1 -0
  282. package/dist/tools-BmuN627J.js +1085 -0
  283. package/dist/tools-BmuN627J.js.map +1 -0
  284. package/dist/trace-attributes.d.ts +2 -52
  285. package/dist/trace-attributes.js +131 -61
  286. package/dist/trace-attributes.js.map +1 -1
  287. package/dist/traces.d.ts +12 -2365
  288. package/dist/traces.js +12 -252
  289. package/dist/trajectory-D_7rLrvE.js +56 -0
  290. package/dist/trajectory-D_7rLrvE.js.map +1 -0
  291. package/dist/types-DGsxbAEd.d.ts +387 -0
  292. package/dist/types-DGsxbAEd.d.ts.map +1 -0
  293. package/dist/types-k9tZGKUg.d.ts +640 -0
  294. package/dist/types-k9tZGKUg.d.ts.map +1 -0
  295. package/dist/verdict-Dps8_okt.d.ts +37 -0
  296. package/dist/verdict-Dps8_okt.d.ts.map +1 -0
  297. package/dist/wire/index.d.ts +702 -1173
  298. package/dist/wire/index.d.ts.map +1 -0
  299. package/dist/wire/index.js +2 -81
  300. package/package.json +17 -9
  301. package/dist/benchmarks/index.js.map +0 -1
  302. package/dist/campaign/index.js.map +0 -1
  303. package/dist/chunk-2QU3YOPR.js +0 -7374
  304. package/dist/chunk-2QU3YOPR.js.map +0 -1
  305. package/dist/chunk-3OCR4R5I.js +0 -728
  306. package/dist/chunk-3OCR4R5I.js.map +0 -1
  307. package/dist/chunk-3RF76KTD.js +0 -84
  308. package/dist/chunk-3RF76KTD.js.map +0 -1
  309. package/dist/chunk-56TAVBOK.js +0 -698
  310. package/dist/chunk-5DTSBUL2.js +0 -159
  311. package/dist/chunk-5DTSBUL2.js.map +0 -1
  312. package/dist/chunk-7FO3TNPI.js +0 -232
  313. package/dist/chunk-7FO3TNPI.js.map +0 -1
  314. package/dist/chunk-7ZZMD7UK.js +0 -386
  315. package/dist/chunk-7ZZMD7UK.js.map +0 -1
  316. package/dist/chunk-BOD4O7OF.js +0 -40
  317. package/dist/chunk-BOD4O7OF.js.map +0 -1
  318. package/dist/chunk-BSO5JDQH.js +0 -2335
  319. package/dist/chunk-BSO5JDQH.js.map +0 -1
  320. package/dist/chunk-C6LXANRU.js +0 -1550
  321. package/dist/chunk-C6LXANRU.js.map +0 -1
  322. package/dist/chunk-DODXQREJ.js +0 -752
  323. package/dist/chunk-DODXQREJ.js.map +0 -1
  324. package/dist/chunk-DRYIUNWY.js +0 -622
  325. package/dist/chunk-DRYIUNWY.js.map +0 -1
  326. package/dist/chunk-E7QXT7SX.js +0 -183
  327. package/dist/chunk-E7QXT7SX.js.map +0 -1
  328. package/dist/chunk-EG66UGL4.js +0 -341
  329. package/dist/chunk-EG66UGL4.js.map +0 -1
  330. package/dist/chunk-FXTVJPYD.js +0 -576
  331. package/dist/chunk-FXTVJPYD.js.map +0 -1
  332. package/dist/chunk-G7MGMCZD.js +0 -153
  333. package/dist/chunk-G7MGMCZD.js.map +0 -1
  334. package/dist/chunk-GGE4NNQT.js +0 -65
  335. package/dist/chunk-GGE4NNQT.js.map +0 -1
  336. package/dist/chunk-H23X7XKK.js +0 -181
  337. package/dist/chunk-H23X7XKK.js.map +0 -1
  338. package/dist/chunk-HHWE3POT.js +0 -94
  339. package/dist/chunk-HHWE3POT.js.map +0 -1
  340. package/dist/chunk-HPWUNB47.js +0 -289
  341. package/dist/chunk-HPWUNB47.js.map +0 -1
  342. package/dist/chunk-IYCLP2N2.js +0 -766
  343. package/dist/chunk-IYCLP2N2.js.map +0 -1
  344. package/dist/chunk-JHCHEVET.js +0 -274
  345. package/dist/chunk-JHCHEVET.js.map +0 -1
  346. package/dist/chunk-JQSF5DQT.js +0 -701
  347. package/dist/chunk-JQSF5DQT.js.map +0 -1
  348. package/dist/chunk-K4DBDHLK.js +0 -158
  349. package/dist/chunk-K4DBDHLK.js.map +0 -1
  350. package/dist/chunk-K6N6XJJX.js +0 -306
  351. package/dist/chunk-K6N6XJJX.js.map +0 -1
  352. package/dist/chunk-M4YBQKIJ.js +0 -1040
  353. package/dist/chunk-M4YBQKIJ.js.map +0 -1
  354. package/dist/chunk-MA6HLL3S.js +0 -65
  355. package/dist/chunk-MA6HLL3S.js.map +0 -1
  356. package/dist/chunk-MAZ26DC7.js +0 -99
  357. package/dist/chunk-MAZ26DC7.js.map +0 -1
  358. package/dist/chunk-NPCTHQIO.js +0 -91
  359. package/dist/chunk-NPCTHQIO.js.map +0 -1
  360. package/dist/chunk-NY44NC4A.js +0 -1056
  361. package/dist/chunk-NY44NC4A.js.map +0 -1
  362. package/dist/chunk-OIUOT4QD.js +0 -44
  363. package/dist/chunk-OIUOT4QD.js.map +0 -1
  364. package/dist/chunk-ONWEPEDO.js +0 -57
  365. package/dist/chunk-ONWEPEDO.js.map +0 -1
  366. package/dist/chunk-OWN5NPMC.js +0 -152
  367. package/dist/chunk-OWN5NPMC.js.map +0 -1
  368. package/dist/chunk-P6FYH6K4.js +0 -1161
  369. package/dist/chunk-P6FYH6K4.js.map +0 -1
  370. package/dist/chunk-PC4UYEBM.js +0 -166
  371. package/dist/chunk-PC4UYEBM.js.map +0 -1
  372. package/dist/chunk-PC5DOSM7.js +0 -579
  373. package/dist/chunk-PC5DOSM7.js.map +0 -1
  374. package/dist/chunk-PXE2VKMX.js +0 -140
  375. package/dist/chunk-PXE2VKMX.js.map +0 -1
  376. package/dist/chunk-PZ5AY32C.js +0 -10
  377. package/dist/chunk-PZ5AY32C.js.map +0 -1
  378. package/dist/chunk-QB6BDBP2.js +0 -4464
  379. package/dist/chunk-QB6BDBP2.js.map +0 -1
  380. package/dist/chunk-RXHCETDZ.js +0 -536
  381. package/dist/chunk-RXHCETDZ.js.map +0 -1
  382. package/dist/chunk-RZTMDUO7.js +0 -49
  383. package/dist/chunk-RZTMDUO7.js.map +0 -1
  384. package/dist/chunk-SFLLL76A.js +0 -669
  385. package/dist/chunk-SFLLL76A.js.map +0 -1
  386. package/dist/chunk-SZLVEKMJ.js +0 -1446
  387. package/dist/chunk-SZLVEKMJ.js.map +0 -1
  388. package/dist/chunk-T4SQEITX.js +0 -95
  389. package/dist/chunk-T4SQEITX.js.map +0 -1
  390. package/dist/chunk-T6RLYGAD.js +0 -158
  391. package/dist/chunk-T6RLYGAD.js.map +0 -1
  392. package/dist/chunk-TJVT4QFF.js +0 -911
  393. package/dist/chunk-TJVT4QFF.js.map +0 -1
  394. package/dist/chunk-TQ7LNKZ3.js +0 -136
  395. package/dist/chunk-TQ7LNKZ3.js.map +0 -1
  396. package/dist/chunk-U4L7JRPZ.js +0 -1706
  397. package/dist/chunk-U4L7JRPZ.js.map +0 -1
  398. package/dist/chunk-U4PHLT2N.js +0 -419
  399. package/dist/chunk-U4PHLT2N.js.map +0 -1
  400. package/dist/chunk-VCZ5FQYW.js +0 -928
  401. package/dist/chunk-VCZ5FQYW.js.map +0 -1
  402. package/dist/chunk-VI2UW6B6.js +0 -162
  403. package/dist/chunk-VI2UW6B6.js.map +0 -1
  404. package/dist/chunk-VQMK5FMP.js +0 -247
  405. package/dist/chunk-VQMK5FMP.js.map +0 -1
  406. package/dist/chunk-WGXIEX7P.js +0 -116
  407. package/dist/chunk-WGXIEX7P.js.map +0 -1
  408. package/dist/chunk-WVATSFCP.js +0 -1553
  409. package/dist/chunk-WVATSFCP.js.map +0 -1
  410. package/dist/chunk-X4YIBDER.js +0 -1662
  411. package/dist/chunk-X4YIBDER.js.map +0 -1
  412. package/dist/chunk-YQN4ICPP.js +0 -355
  413. package/dist/chunk-YQN4ICPP.js.map +0 -1
  414. package/dist/chunk-ZET2UAYW.js +0 -89
  415. package/dist/chunk-ZET2UAYW.js.map +0 -1
  416. package/dist/chunk-ZHTZ4EYI.js +0 -1212
  417. package/dist/chunk-ZHTZ4EYI.js.map +0 -1
  418. package/dist/control.js.map +0 -1
  419. package/dist/hosted/index.js.map +0 -1
  420. package/dist/matrix/index.js.map +0 -1
  421. package/dist/reporting.js.map +0 -1
  422. package/dist/rollout/index.js.map +0 -1
  423. package/dist/run-campaign-OJJ7CZF4.js +0 -18
  424. package/dist/run-campaign-OJJ7CZF4.js.map +0 -1
  425. package/dist/supervisor-run/index.js.map +0 -1
  426. package/dist/traces.js.map +0 -1
  427. package/dist/wire/index.js.map +0 -1
@@ -1,928 +0,0 @@
1
- import {
2
- estimateCost,
3
- isModelPriced,
4
- resolveModelPricing
5
- } from "./chunk-VI2UW6B6.js";
6
- import {
7
- ValidationError
8
- } from "./chunk-ONWEPEDO.js";
9
-
10
- // src/cost-ledger.ts
11
- import { z } from "zod";
12
- var CostCeilingReachedError = class extends ValidationError {
13
- constructor(ceilingUsd, committedAndReservedUsd, requestedUsd, phase, actor) {
14
- super(
15
- `CostLedger: reserving ${requestedUsd} for '${actor}' during '${phase}' would exceed ceiling ${ceilingUsd} with ${committedAndReservedUsd} already committed or reserved`
16
- );
17
- }
18
- };
19
- var CostAccountingIncompleteError = class extends ValidationError {
20
- };
21
- var CostReservationExceededError = class extends ValidationError {
22
- constructor(actor, actualUsd, maximumUsd) {
23
- super(
24
- `CostLedger: '${actor}' charged ${actualUsd}, exceeding its enforced maximum ${maximumUsd}`
25
- );
26
- }
27
- };
28
- var CostCallConflictError = class extends ValidationError {
29
- callId;
30
- receipt;
31
- constructor(message, options = {}) {
32
- super(message, options.cause === void 0 ? void 0 : { cause: options.cause });
33
- this.callId = options.callId;
34
- this.receipt = options.receipt ? cloneReceipt(options.receipt) : void 0;
35
- }
36
- };
37
- var CostLedgerPersistenceError = class extends ValidationError {
38
- callId;
39
- receipt;
40
- constructor(cause, callId, receipt) {
41
- super(
42
- `CostLedger: failed to persist${callId ? ` call '${callId}'` : ""}: ${toError(cause).message}`,
43
- { cause }
44
- );
45
- this.callId = callId;
46
- this.receipt = receipt ? cloneReceipt(receipt) : void 0;
47
- }
48
- };
49
- var CostReceiptCaptureError = class extends ValidationError {
50
- callId;
51
- receipt;
52
- receiptError;
53
- constructor(callId, cause, receiptError, receipt) {
54
- super(`CostLedger: could not capture the provider receipt for call '${callId}'`, { cause });
55
- this.callId = callId;
56
- this.receipt = receipt ? cloneReceipt(receipt) : void 0;
57
- this.receiptError = toError(receiptError);
58
- }
59
- };
60
- var CostLedger = class {
61
- records = /* @__PURE__ */ new Map();
62
- activeCallIds = /* @__PURE__ */ new Set();
63
- lateCallIds = /* @__PURE__ */ new Set();
64
- idleWaiters = /* @__PURE__ */ new Set();
65
- completedTasks = 0;
66
- revision = "memory";
67
- costLimitPersisted = false;
68
- costCeilingUsd;
69
- persistence;
70
- constructor(input) {
71
- const options = typeof input === "number" ? { costCeilingUsd: input } : input ?? {};
72
- this.persistence = options.persistence;
73
- if (options.costCeilingUsd !== void 0) {
74
- assertNonNegative(options.costCeilingUsd, "costCeilingUsd");
75
- }
76
- let persistedCostCeilingUsd;
77
- if (this.persistence) {
78
- let stored;
79
- try {
80
- stored = this.persistence.read();
81
- } catch (cause) {
82
- throw new CostLedgerPersistenceError(cause);
83
- }
84
- assertString(stored.revision, "persistence revision");
85
- this.revision = stored.revision;
86
- const restored = parseEvents(stored.events);
87
- for (const record of restored.records) this.records.set(record.callId, record);
88
- this.completedTasks = restored.completedTasks;
89
- persistedCostCeilingUsd = restored.costCeilingUsd;
90
- }
91
- if (options.costCeilingUsd !== void 0 && persistedCostCeilingUsd !== void 0 && options.costCeilingUsd !== persistedCostCeilingUsd) {
92
- throw new ValidationError(
93
- `CostLedger: requested cost ceiling ${options.costCeilingUsd} does not match persisted ceiling ${persistedCostCeilingUsd}`
94
- );
95
- }
96
- this.costCeilingUsd = persistedCostCeilingUsd ?? options.costCeilingUsd;
97
- this.costLimitPersisted = !this.persistence || this.costCeilingUsd === void 0 || persistedCostCeilingUsd !== void 0;
98
- if (this.costCeilingUsd !== void 0 && [...this.records.values()].some(
99
- (record) => record.status === "pending" && record.maximumCostUsd === void 0
100
- )) {
101
- throw new ValidationError("CostLedger: capped event log contains an unbounded pending call");
102
- }
103
- if (options.receipts?.length) {
104
- const imported = options.receipts.map(
105
- (receipt, index) => parseImportedReceipt(receipt, `imported receipt ${index + 1}`)
106
- );
107
- this.ensureCostLimitPersisted();
108
- for (const receipt of imported) this.appendRecord(receipt);
109
- }
110
- }
111
- async runPaidCall(input) {
112
- let callId;
113
- let pending;
114
- try {
115
- callId = resolveCallId(input.callId);
116
- validateAttribution(input);
117
- if (input.signal?.aborted) {
118
- return { succeeded: false, callId, error: abortError(input.signal) };
119
- }
120
- if (this.records.has(callId)) {
121
- return {
122
- succeeded: false,
123
- callId,
124
- error: new CostCallConflictError(`CostLedger: callId '${callId}' already exists`)
125
- };
126
- }
127
- this.ensureCostLimitPersisted(callId);
128
- const summary = this.summary();
129
- if (summary.unresolvedCalls > 0) {
130
- return {
131
- succeeded: false,
132
- callId,
133
- error: new CostAccountingIncompleteError(
134
- `CostLedger: ${summary.unresolvedCalls} unresolved call(s) must be reconciled before new paid work`
135
- )
136
- };
137
- }
138
- const maximumCostUsd = this.resolveMaximum(input.maximumCharge);
139
- if (this.costCeilingUsd !== void 0 && this.hasIncompleteSettledCall()) {
140
- return {
141
- succeeded: false,
142
- callId,
143
- error: new CostAccountingIncompleteError(
144
- `CostLedger: accounting is incomplete; refusing paid call '${input.actor}' during '${input.phase}'`
145
- )
146
- };
147
- }
148
- if (this.costCeilingUsd !== void 0) {
149
- const committedAndReserved = summary.totalCostUsd + summary.reservedCostUsd;
150
- if (committedAndReserved + maximumCostUsd > this.costCeilingUsd) {
151
- return {
152
- succeeded: false,
153
- callId,
154
- error: new CostCeilingReachedError(
155
- this.costCeilingUsd,
156
- committedAndReserved,
157
- maximumCostUsd,
158
- input.phase,
159
- input.actor
160
- )
161
- };
162
- }
163
- }
164
- pending = {
165
- status: "pending",
166
- callId,
167
- channel: input.channel,
168
- phase: input.phase,
169
- actor: input.actor,
170
- model: pendingModel(input),
171
- ...maximumCostUsd === void 0 ? {} : { maximumCostUsd },
172
- ...input.tags ? { tags: { ...input.tags } } : {},
173
- timestamp: Date.now()
174
- };
175
- this.appendRecord(pending);
176
- this.activeCallIds.add(callId);
177
- } catch (error) {
178
- return { succeeded: false, ...callId ? { callId } : {}, error: toError(error) };
179
- }
180
- try {
181
- return await this.execute(input, pending);
182
- } catch (error) {
183
- return { succeeded: false, callId: pending.callId, error: toError(error) };
184
- } finally {
185
- if (!this.lateCallIds.has(pending.callId)) this.releaseActiveCall(pending.callId);
186
- }
187
- }
188
- /** Wait until every call started by this ledger has produced a durable outcome. */
189
- async waitForIdle(options = {}) {
190
- const hasActiveMatch = () => [...this.activeCallIds].some((callId) => {
191
- const record = this.records.get(callId);
192
- return record !== void 0 && matches(record, options.filter);
193
- });
194
- if (!hasActiveMatch()) return true;
195
- const timeoutMs = options.timeoutMs ?? 5e3;
196
- assertTimeout(timeoutMs, "waitForIdle.timeoutMs");
197
- return new Promise((resolve) => {
198
- let timer;
199
- const finish = (settled) => {
200
- this.idleWaiters.delete(onIdle);
201
- if (timer !== void 0) clearTimeout(timer);
202
- resolve(settled);
203
- };
204
- const onIdle = () => {
205
- if (!hasActiveMatch()) finish(true);
206
- };
207
- this.idleWaiters.add(onIdle);
208
- timer = setTimeout(() => finish(false), timeoutMs);
209
- onIdle();
210
- });
211
- }
212
- /** Settle a call left pending by a crashed process after reconciling with the provider. */
213
- reconcile(callId, observed, options = {}) {
214
- const pending = [...this.records.values()].find(
215
- (record) => record.callId === callId && record.status === "pending"
216
- );
217
- if (!pending) throw new CostCallConflictError(`CostLedger: no pending call '${callId}'`);
218
- if (this.activeCallIds.has(callId)) {
219
- throw new CostCallConflictError(`CostLedger: call '${callId}' is still active`);
220
- }
221
- this.ensureCostLimitPersisted(callId);
222
- return this.commitReceipt(pending, observed, options.error);
223
- }
224
- list(filter) {
225
- return [...this.records.values()].filter((record) => record.status === "settled").filter((receipt) => matches(receipt, filter)).map(cloneReceipt);
226
- }
227
- /** Read pending calls without exposing mutable ledger state. */
228
- listPending(filter) {
229
- return [...this.records.values()].filter((record) => record.status === "pending").filter((record) => matches(record, filter)).map((record) => ({
230
- ...clonePendingCall(record),
231
- state: this.lateCallIds.has(record.callId) ? "late" : this.activeCallIds.has(record.callId) ? "active" : "interrupted"
232
- }));
233
- }
234
- summary(filter) {
235
- const records = [...this.records.values()].filter((record) => matches(record, filter));
236
- const pending = records.filter(
237
- (record) => record.status === "pending"
238
- );
239
- const receipts = records.filter((record) => record.status === "settled");
240
- const byChannel = /* @__PURE__ */ new Map();
241
- const unpriced = /* @__PURE__ */ new Set();
242
- const incompleteReasons = pending.map(
243
- (record) => `call '${record.callId}' for '${record.actor}' is pending`
244
- );
245
- let inputTokens = 0;
246
- let outputTokens = 0;
247
- let reasoningTokens = 0;
248
- let cachedTokens = 0;
249
- let cacheWriteTokens = 0;
250
- let totalCostUsd = 0;
251
- for (const receipt of receipts) {
252
- inputTokens += receipt.inputTokens;
253
- outputTokens += receipt.outputTokens;
254
- reasoningTokens += receipt.reasoningTokens ?? 0;
255
- cachedTokens += receipt.cachedTokens ?? 0;
256
- cacheWriteTokens += receipt.cacheWriteTokens ?? 0;
257
- totalCostUsd += receipt.costUsd;
258
- if (receipt.costUnknown) {
259
- unpriced.add(receipt.model);
260
- incompleteReasons.push(
261
- receipt.error ?? `cost unknown for '${receipt.actor}' using '${receipt.model}'`
262
- );
263
- }
264
- if (receipt.usageUnknown) {
265
- incompleteReasons.push(
266
- `token usage unknown for '${receipt.actor}' using '${receipt.model}'`
267
- );
268
- }
269
- if (receipt.maximumCostUsd !== void 0 && receipt.costUsd > receipt.maximumCostUsd) {
270
- incompleteReasons.push(
271
- `'${receipt.actor}' charged ${receipt.costUsd}, exceeding its enforced maximum ${receipt.maximumCostUsd}`
272
- );
273
- }
274
- const rollup = byChannel.get(receipt.channel) ?? emptyRollup(receipt.channel);
275
- rollup.calls += 1;
276
- rollup.inputTokens += receipt.inputTokens;
277
- rollup.outputTokens += receipt.outputTokens;
278
- rollup.reasoningTokens = (rollup.reasoningTokens ?? 0) + (receipt.reasoningTokens ?? 0);
279
- rollup.cachedTokens += receipt.cachedTokens ?? 0;
280
- rollup.cacheWriteTokens = (rollup.cacheWriteTokens ?? 0) + (receipt.cacheWriteTokens ?? 0);
281
- rollup.costUsd += receipt.costUsd;
282
- if (receipt.costUnknown) rollup.unpricedCalls += 1;
283
- if (receipt.usageUnknown) rollup.unknownUsageCalls += 1;
284
- byChannel.set(receipt.channel, rollup);
285
- }
286
- return {
287
- totalCalls: receipts.length,
288
- pendingCalls: pending.length,
289
- unresolvedCalls: pending.filter(
290
- (record) => !this.activeCallIds.has(record.callId) || this.lateCallIds.has(record.callId)
291
- ).length,
292
- reservedCostUsd: pending.reduce((sum, record) => sum + (record.maximumCostUsd ?? 0), 0),
293
- inputTokens,
294
- outputTokens,
295
- reasoningTokens,
296
- cachedTokens,
297
- cacheWriteTokens,
298
- totalCostUsd,
299
- byChannel: [...byChannel.values()].sort((a, b) => a.channel.localeCompare(b.channel)),
300
- unpricedModels: [...unpriced].sort(),
301
- fullyPriced: unpriced.size === 0,
302
- usageComplete: pending.length === 0 && receipts.every((receipt) => !receipt.usageUnknown),
303
- accountingComplete: incompleteReasons.length === 0,
304
- incompleteReasons: [...new Set(incompleteReasons)]
305
- };
306
- }
307
- markCompleted(count = 1) {
308
- if (!Number.isInteger(count) || count < 0) {
309
- throw new ValidationError(
310
- `CostLedger.markCompleted: count must be a non-negative integer, got ${count}`
311
- );
312
- }
313
- if (count === 0) return;
314
- this.ensureCostLimitPersisted();
315
- this.appendEvent({ version: 1, completedTasks: count });
316
- this.completedTasks += count;
317
- }
318
- costPerCompletedTask() {
319
- return this.completedTasks === 0 ? null : this.summary().totalCostUsd / this.completedTasks;
320
- }
321
- async execute(input, pending) {
322
- const signal = input.signal ?? new AbortController().signal;
323
- if (signal.aborted) {
324
- return this.commitOutcome(pending, abortError(signal), {
325
- model: pending.model,
326
- inputTokens: 0,
327
- outputTokens: 0,
328
- actualCostUsd: 0
329
- });
330
- }
331
- const operation = Promise.resolve().then(() => input.execute(signal, pending.callId));
332
- const settled = await settle(operation, signal);
333
- if (settled.kind === "aborted") {
334
- this.lateCallIds.add(pending.callId);
335
- this.captureLateOutcome(input, pending, operation);
336
- return paidFailure(pending.callId, abortError(signal));
337
- }
338
- if (settled.kind === "error") {
339
- let observed;
340
- try {
341
- observed = input.receiptFromError?.(settled.error);
342
- } catch (receiptError) {
343
- return this.captureFailure(pending, settled.error, receiptError);
344
- }
345
- return this.commitOutcome(pending, settled.error, observed ?? unknownReceipt(pending.model));
346
- }
347
- try {
348
- const receipt = this.commitReceipt(pending, input.receipt(settled.value));
349
- if (receipt.maximumCostUsd !== void 0 && receipt.costUsd > receipt.maximumCostUsd) {
350
- return paidFailure(
351
- pending.callId,
352
- new CostReservationExceededError(pending.actor, receipt.costUsd, receipt.maximumCostUsd),
353
- receipt
354
- );
355
- }
356
- return { succeeded: true, callId: pending.callId, value: settled.value, receipt };
357
- } catch (receiptError) {
358
- if (receiptError instanceof CostLedgerPersistenceError || receiptError instanceof CostCallConflictError) {
359
- return paidFailure(pending.callId, receiptError);
360
- }
361
- return this.captureFailure(pending, receiptError, receiptError);
362
- }
363
- }
364
- captureLateOutcome(input, pending, operation) {
365
- void operation.then(
366
- (value) => {
367
- if (this.records.get(pending.callId)?.status !== "pending") return;
368
- try {
369
- this.commitReceipt(pending, input.receipt(value));
370
- } catch {
371
- }
372
- },
373
- (cause) => {
374
- if (this.records.get(pending.callId)?.status !== "pending") return;
375
- const error = toError(cause);
376
- try {
377
- const observed = input.receiptFromError?.(error);
378
- this.commitReceipt(pending, observed ?? unknownReceipt(pending.model), error.message);
379
- } catch (receiptError) {
380
- if (receiptError instanceof CostLedgerPersistenceError || receiptError instanceof CostCallConflictError) {
381
- return;
382
- }
383
- this.captureFailure(pending, error, receiptError);
384
- }
385
- }
386
- ).finally(() => {
387
- this.lateCallIds.delete(pending.callId);
388
- this.releaseActiveCall(pending.callId);
389
- });
390
- }
391
- releaseActiveCall(callId) {
392
- this.activeCallIds.delete(callId);
393
- for (const resolve of [...this.idleWaiters]) resolve();
394
- }
395
- commitOutcome(pending, error, observed) {
396
- try {
397
- const receipt = this.commitReceipt(pending, observed, error.message);
398
- return paidFailure(pending.callId, error, receipt);
399
- } catch (receiptError) {
400
- if (receiptError instanceof CostLedgerPersistenceError || receiptError instanceof CostCallConflictError) {
401
- return paidFailure(pending.callId, receiptError);
402
- }
403
- return this.captureFailure(pending, error, receiptError);
404
- }
405
- }
406
- captureFailure(pending, cause, receiptError) {
407
- try {
408
- const receipt = this.commitReceipt(
409
- pending,
410
- unknownReceipt(pending.model),
411
- toError(receiptError).message
412
- );
413
- return paidFailure(
414
- pending.callId,
415
- new CostReceiptCaptureError(pending.callId, cause, receiptError, receipt),
416
- receipt
417
- );
418
- } catch (error) {
419
- const typed = error instanceof Error ? error : toError(error);
420
- return paidFailure(pending.callId, typed);
421
- }
422
- }
423
- commitReceipt(pending, observed, error) {
424
- const receipt = buildReceipt(pending, observed, error);
425
- if (this.records.get(pending.callId)?.status !== "pending") {
426
- throw new CostCallConflictError(`CostLedger: call '${pending.callId}' is not pending`);
427
- }
428
- this.appendRecord(receipt);
429
- return cloneReceipt(receipt);
430
- }
431
- resolveMaximum(maximum) {
432
- if (!maximum) {
433
- if (this.costCeilingUsd !== void 0) {
434
- throw new CostAccountingIncompleteError(
435
- "CostLedger: capped paid calls require a hard maximumCharge before execution"
436
- );
437
- }
438
- return void 0;
439
- }
440
- if ("externallyEnforcedMaximumUsd" in maximum) {
441
- assertNonNegative(
442
- maximum.externallyEnforcedMaximumUsd,
443
- "maximumCharge.externallyEnforcedMaximumUsd"
444
- );
445
- return maximum.externallyEnforcedMaximumUsd;
446
- }
447
- if ("customTokenPricing" in maximum) {
448
- return costForTokenPricing(maximum.customTokenPricing, maximum);
449
- }
450
- const priced = costForUsage(maximum.model, maximum);
451
- if (priced.costUnknown) {
452
- if (this.costCeilingUsd !== void 0) {
453
- throw new CostAccountingIncompleteError(
454
- `CostLedger: cannot reserve unpriced model '${maximum.model}' in a capped run`
455
- );
456
- }
457
- return void 0;
458
- }
459
- return priced.costUsd;
460
- }
461
- hasIncompleteSettledCall() {
462
- return [...this.records.values()].some(
463
- (record) => record.status === "settled" && (record.costUnknown || record.usageUnknown || record.maximumCostUsd !== void 0 && record.costUsd > record.maximumCostUsd)
464
- );
465
- }
466
- appendRecord(record) {
467
- const callId = record.callId;
468
- const receipt = record.status === "settled" ? record : void 0;
469
- validateTransition(this.records, record);
470
- const event = record.status === "settled" ? { version: 2, record: cloneReceipt(record) } : { version: 1, record: clonePendingCall(record) };
471
- this.appendEvent(event, callId, receipt);
472
- this.records.set(callId, cloneRecord(record));
473
- }
474
- ensureCostLimitPersisted(callId) {
475
- if (this.costLimitPersisted || this.costCeilingUsd === void 0) return;
476
- this.appendEvent({ version: 1, costCeilingUsd: this.costCeilingUsd }, callId);
477
- this.costLimitPersisted = true;
478
- }
479
- appendEvent(event, callId, receipt) {
480
- try {
481
- if (this.persistence) {
482
- const nextRevision = this.persistence.append(this.revision, `${JSON.stringify(event)}
483
- `);
484
- if (nextRevision === void 0) {
485
- throw new CostCallConflictError(
486
- `CostLedger: persisted revision changed while writing call '${callId}'`,
487
- { callId, receipt }
488
- );
489
- }
490
- assertString(nextRevision, "persistence revision");
491
- this.revision = nextRevision;
492
- }
493
- } catch (cause) {
494
- if (cause instanceof CostCallConflictError) throw cause;
495
- throw new CostLedgerPersistenceError(cause, callId, receipt);
496
- }
497
- }
498
- };
499
- function modelPriceKey(model) {
500
- return isModelPriced(model) ? model : null;
501
- }
502
- function costForUsage(model, usage) {
503
- assertUsage(usage);
504
- if (!resolveModelPricing(model)) return { costUsd: 0, costUnknown: true };
505
- return {
506
- costUsd: estimateCost(
507
- usage.inputTokens + (usage.cachedTokens ?? 0) + (usage.cacheWriteTokens ?? 0),
508
- usage.outputTokens,
509
- model
510
- ),
511
- costUnknown: false
512
- };
513
- }
514
- function costForTokenPricing(pricing, usage) {
515
- assertTokenCount(usage.inputTokens, "usage.inputTokens");
516
- assertTokenCount(usage.outputTokens, "usage.outputTokens");
517
- if (usage.cachedTokens !== void 0) {
518
- assertTokenCount(usage.cachedTokens, "usage.cachedTokens");
519
- }
520
- if (usage.cacheWriteTokens !== void 0) {
521
- assertTokenCount(usage.cacheWriteTokens, "usage.cacheWriteTokens");
522
- }
523
- assertNonNegative(pricing.inputUsdPerMillion, "pricing.inputUsdPerMillion");
524
- if (pricing.cachedInputUsdPerMillion !== void 0) {
525
- assertNonNegative(pricing.cachedInputUsdPerMillion, "pricing.cachedInputUsdPerMillion");
526
- }
527
- if (pricing.cacheWriteUsdPerMillion !== void 0) {
528
- assertNonNegative(pricing.cacheWriteUsdPerMillion, "pricing.cacheWriteUsdPerMillion");
529
- }
530
- assertNonNegative(pricing.outputUsdPerMillion, "pricing.outputUsdPerMillion");
531
- const cachedInputRate = pricing.cachedInputUsdPerMillion ?? pricing.inputUsdPerMillion;
532
- const cacheWriteRate = pricing.cacheWriteUsdPerMillion ?? pricing.inputUsdPerMillion;
533
- return usage.inputTokens / 1e6 * pricing.inputUsdPerMillion + (usage.cachedTokens ?? 0) / 1e6 * cachedInputRate + (usage.cacheWriteTokens ?? 0) / 1e6 * cacheWriteRate + usage.outputTokens / 1e6 * pricing.outputUsdPerMillion;
534
- }
535
- async function settle(promise, signal) {
536
- return await new Promise((resolve) => {
537
- let done = false;
538
- const finish = (value) => {
539
- if (done) return;
540
- done = true;
541
- signal.removeEventListener("abort", onAbort);
542
- resolve(value);
543
- };
544
- const onAbort = () => finish({ kind: "aborted" });
545
- signal.addEventListener("abort", onAbort, { once: true });
546
- if (signal.aborted) onAbort();
547
- promise.then(
548
- (value) => finish({ kind: "value", value }),
549
- (error) => finish({ kind: "error", error: toError(error) })
550
- );
551
- });
552
- }
553
- function buildReceipt(pending, observed, error) {
554
- assertUsage(observed);
555
- assertString(observed.model, "receipt.model");
556
- if (observed.actualCostUsd !== void 0 && observed.customTokenPricing !== void 0) {
557
- throw new ValidationError(
558
- "CostLedger: a receipt cannot have both actualCostUsd and customTokenPricing"
559
- );
560
- }
561
- const customPricingSnapshot = observed.customTokenPricing === void 0 ? void 0 : pricingSnapshot(observed.customTokenPricing);
562
- const estimated = customPricingSnapshot ? {
563
- costUsd: costFromPricing(observed, customPricingSnapshot),
564
- costUnknown: false
565
- } : costForUsage(observed.model, observed);
566
- const hasActual = observed.actualCostUsd !== void 0;
567
- if (hasActual && observed.costUnknown === true) {
568
- throw new ValidationError(
569
- "CostLedger: a receipt cannot have both actualCostUsd and costUnknown=true"
570
- );
571
- }
572
- if (hasActual) assertNonNegative(observed.actualCostUsd, "actualCostUsd");
573
- const usageUnknown = observed.usageUnknown === true;
574
- const costUnknown = observed.costUnknown === true || !hasActual && (usageUnknown || estimated.costUnknown);
575
- const resolvedModelPricing = !customPricingSnapshot && !hasActual && !costUnknown ? resolveModelPricing(observed.model) : null;
576
- const receiptPricing = !hasActual && !costUnknown ? customPricingSnapshot ?? (resolvedModelPricing ? {
577
- inputUsdPerThousand: resolvedModelPricing.input,
578
- outputUsdPerThousand: resolvedModelPricing.output
579
- } : void 0) : void 0;
580
- return parseReceipt(
581
- {
582
- status: "settled",
583
- callId: pending.callId,
584
- channel: pending.channel,
585
- phase: pending.phase,
586
- actor: pending.actor,
587
- model: observed.model,
588
- inputTokens: observed.inputTokens,
589
- outputTokens: observed.outputTokens,
590
- ...observed.reasoningTokens === void 0 ? {} : { reasoningTokens: observed.reasoningTokens },
591
- ...observed.cachedTokens === void 0 ? {} : { cachedTokens: observed.cachedTokens },
592
- ...observed.cacheWriteTokens === void 0 ? {} : { cacheWriteTokens: observed.cacheWriteTokens },
593
- costUsd: costUnknown ? 0 : hasActual ? observed.actualCostUsd : estimated.costUsd,
594
- costUnknown,
595
- usageUnknown,
596
- ...receiptPricing ? { pricing: receiptPricing } : {},
597
- ...hasActual ? { actualCostUsd: observed.actualCostUsd } : {},
598
- ...pending.maximumCostUsd === void 0 ? {} : { maximumCostUsd: pending.maximumCostUsd },
599
- ...error ? { error } : {},
600
- ...pending.tags ? { tags: { ...pending.tags } } : {},
601
- timestamp: pending.timestamp
602
- },
603
- "provider receipt"
604
- );
605
- }
606
- var NonEmptyString = z.string().refine((value) => value.trim().length > 0, "must be non-empty");
607
- var TokenCount = z.number().int().nonnegative().finite();
608
- var NonNegative = z.number().nonnegative().finite();
609
- var Tags = z.record(NonEmptyString, z.string());
610
- var CostPricingSchema = z.strictObject({
611
- inputUsdPerThousand: NonNegative,
612
- cachedInputUsdPerThousand: NonNegative.optional(),
613
- cacheWriteUsdPerThousand: NonNegative.optional(),
614
- outputUsdPerThousand: NonNegative
615
- });
616
- var CostCallBaseShape = {
617
- callId: NonEmptyString,
618
- channel: NonEmptyString,
619
- phase: NonEmptyString,
620
- actor: NonEmptyString,
621
- model: NonEmptyString,
622
- maximumCostUsd: NonNegative.optional(),
623
- tags: Tags.optional(),
624
- timestamp: NonNegative
625
- };
626
- var PendingCostCallSchema = z.strictObject({
627
- status: z.literal("pending"),
628
- ...CostCallBaseShape
629
- });
630
- var CostReceiptBaseShape = {
631
- status: z.literal("settled"),
632
- ...CostCallBaseShape,
633
- inputTokens: TokenCount,
634
- outputTokens: TokenCount,
635
- cachedTokens: TokenCount.optional(),
636
- costUsd: NonNegative,
637
- costUnknown: z.boolean(),
638
- usageUnknown: z.boolean().default(false),
639
- pricing: CostPricingSchema.optional(),
640
- actualCostUsd: NonNegative.optional(),
641
- error: z.string().optional()
642
- };
643
- var CostReceiptSchema = z.strictObject({
644
- ...CostReceiptBaseShape,
645
- reasoningTokens: TokenCount.optional(),
646
- cacheWriteTokens: TokenCount.optional()
647
- }).superRefine((receipt, ctx) => validateCostReceipt(receipt, ctx));
648
- function validateCostReceipt(receipt, ctx) {
649
- if (receipt.reasoningTokens !== void 0 && receipt.reasoningTokens > receipt.outputTokens) {
650
- ctx.addIssue({ code: "custom", message: "reasoningTokens must not exceed outputTokens" });
651
- }
652
- if (receipt.actualCostUsd !== void 0) {
653
- if (receipt.costUnknown || receipt.costUsd !== receipt.actualCostUsd) {
654
- ctx.addIssue({ code: "custom", message: "actual cost must be known and equal costUsd" });
655
- }
656
- if (receipt.pricing !== void 0) {
657
- ctx.addIssue({ code: "custom", message: "actual cost must not include estimated pricing" });
658
- }
659
- return;
660
- }
661
- if (receipt.costUnknown) {
662
- if (receipt.costUsd !== 0) {
663
- ctx.addIssue({ code: "custom", message: "unknown cost must have costUsd 0" });
664
- }
665
- if (receipt.pricing !== void 0) {
666
- ctx.addIssue({ code: "custom", message: "unknown cost must not include estimated pricing" });
667
- }
668
- return;
669
- }
670
- if (receipt.usageUnknown) {
671
- ctx.addIssue({ code: "custom", message: "known estimated cost requires known usage" });
672
- }
673
- if (!receipt.pricing) {
674
- ctx.addIssue({ code: "custom", message: "known estimated cost requires a pricing snapshot" });
675
- return;
676
- }
677
- const expected = costFromPricing(receipt, receipt.pricing);
678
- if (receipt.costUsd !== expected) {
679
- ctx.addIssue({
680
- code: "custom",
681
- message: `estimated cost ${receipt.costUsd} does not match pricing snapshot ${expected}`
682
- });
683
- }
684
- }
685
- var CostLedgerEventSchema = z.union([
686
- z.strictObject({
687
- version: z.literal(1),
688
- record: PendingCostCallSchema
689
- }),
690
- z.strictObject({
691
- version: z.literal(2),
692
- record: CostReceiptSchema
693
- }),
694
- z.strictObject({
695
- version: z.literal(1),
696
- completedTasks: TokenCount
697
- }),
698
- z.strictObject({
699
- version: z.literal(1),
700
- costCeilingUsd: NonNegative
701
- })
702
- ]);
703
- function parseEvents(serialized) {
704
- const records = /* @__PURE__ */ new Map();
705
- let completedTasks = 0;
706
- let costCeilingUsd;
707
- let lineNumber = 0;
708
- try {
709
- for (const line of serialized.split("\n")) {
710
- if (!line.trim()) continue;
711
- lineNumber += 1;
712
- const event = CostLedgerEventSchema.parse(JSON.parse(line));
713
- if ("record" in event) {
714
- const record = event.record;
715
- validateTransition(records, record);
716
- records.set(record.callId, cloneRecord(record));
717
- } else if ("completedTasks" in event) {
718
- completedTasks += event.completedTasks;
719
- if (!Number.isSafeInteger(completedTasks)) {
720
- throw new ValidationError("CostLedger: completed task count exceeds safe integer range");
721
- }
722
- } else {
723
- if (costCeilingUsd !== void 0) {
724
- throw new ValidationError("CostLedger: duplicate persisted cost ceiling");
725
- }
726
- costCeilingUsd = event.costCeilingUsd;
727
- }
728
- }
729
- return {
730
- records: [...records.values()],
731
- completedTasks,
732
- ...costCeilingUsd === void 0 ? {} : { costCeilingUsd }
733
- };
734
- } catch (cause) {
735
- throw new ValidationError(
736
- `CostLedger: invalid persisted event ${lineNumber || 1}: ${validationMessage(cause)}`,
737
- { cause }
738
- );
739
- }
740
- }
741
- function validateTransition(records, record) {
742
- const current = records.get(record.callId);
743
- if (!current) return;
744
- if (record.status === "pending" || current.status === "settled") {
745
- throw new CostCallConflictError(`CostLedger: duplicate callId '${record.callId}'`);
746
- }
747
- if (!sameAttribution(current, record)) {
748
- throw new ValidationError(`CostLedger: receipt attribution changed for call '${record.callId}'`);
749
- }
750
- }
751
- function sameAttribution(before, after) {
752
- return before.channel === after.channel && before.phase === after.phase && before.actor === after.actor && before.maximumCostUsd === after.maximumCostUsd && before.timestamp === after.timestamp && JSON.stringify(before.tags ?? {}) === JSON.stringify(after.tags ?? {});
753
- }
754
- function parseReceipt(value, path) {
755
- try {
756
- return CostReceiptSchema.parse(value);
757
- } catch (cause) {
758
- throw new ValidationError(`CostLedger: invalid ${path}: ${validationMessage(cause)}`, { cause });
759
- }
760
- }
761
- function parseImportedReceipt(value, path) {
762
- if (typeof value !== "object" || value === null) return parseReceipt(value, path);
763
- const candidate = { ...value };
764
- if (candidate.status === "settled" && candidate.actualCostUsd === void 0 && candidate.costUnknown === false && candidate.pricing === void 0 && typeof candidate.model === "string") {
765
- const pricing = resolveModelPricing(candidate.model);
766
- if (pricing) {
767
- candidate.pricing = {
768
- inputUsdPerThousand: pricing.input,
769
- outputUsdPerThousand: pricing.output
770
- };
771
- }
772
- }
773
- return parseReceipt(candidate, path);
774
- }
775
- function validateAttribution(input) {
776
- assertString(input.channel, "channel");
777
- assertString(input.phase, "phase");
778
- assertString(input.actor, "actor");
779
- if (input.model !== void 0) assertString(input.model, "model");
780
- if (input.tags !== void 0) {
781
- const parsed = Tags.safeParse(input.tags);
782
- if (!parsed.success)
783
- throw new ValidationError(`CostLedger: invalid tags: ${parsed.error.message}`);
784
- }
785
- }
786
- function matches(record, filter) {
787
- if (!filter) return true;
788
- if (filter.channel !== void 0 && record.channel !== filter.channel) return false;
789
- if (filter.phase !== void 0 && record.phase !== filter.phase) return false;
790
- return Object.entries(filter.tags ?? {}).every(([key, value]) => record.tags?.[key] === value);
791
- }
792
- function cloneRecord(record) {
793
- if (record.status === "settled") return cloneReceipt(record);
794
- return clonePendingCall(record);
795
- }
796
- function clonePendingCall(record) {
797
- const { tags, ...rest } = record;
798
- return { ...rest, ...tags ? { tags: { ...tags } } : {} };
799
- }
800
- function cloneReceipt(receipt) {
801
- const { pricing, tags, ...rest } = receipt;
802
- return {
803
- ...rest,
804
- ...tags ? { tags: { ...tags } } : {},
805
- ...pricing ? { pricing: { ...pricing } } : {}
806
- };
807
- }
808
- function costFromPricing(usage, pricing) {
809
- const cachedInputRate = pricing.cachedInputUsdPerThousand ?? pricing.inputUsdPerThousand;
810
- const cacheWriteRate = pricing.cacheWriteUsdPerThousand ?? pricing.inputUsdPerThousand;
811
- return usage.inputTokens / 1e3 * pricing.inputUsdPerThousand + (usage.cachedTokens ?? 0) / 1e3 * cachedInputRate + (usage.cacheWriteTokens ?? 0) / 1e3 * cacheWriteRate + usage.outputTokens / 1e3 * pricing.outputUsdPerThousand;
812
- }
813
- function pricingSnapshot(pricing) {
814
- costForTokenPricing(pricing, { inputTokens: 0, outputTokens: 0 });
815
- return {
816
- inputUsdPerThousand: pricing.inputUsdPerMillion / 1e3,
817
- ...pricing.cachedInputUsdPerMillion === void 0 ? {} : { cachedInputUsdPerThousand: pricing.cachedInputUsdPerMillion / 1e3 },
818
- ...pricing.cacheWriteUsdPerMillion === void 0 ? {} : { cacheWriteUsdPerThousand: pricing.cacheWriteUsdPerMillion / 1e3 },
819
- outputUsdPerThousand: pricing.outputUsdPerMillion / 1e3
820
- };
821
- }
822
- function emptyRollup(channel) {
823
- return {
824
- channel,
825
- calls: 0,
826
- inputTokens: 0,
827
- outputTokens: 0,
828
- reasoningTokens: 0,
829
- cachedTokens: 0,
830
- cacheWriteTokens: 0,
831
- costUsd: 0,
832
- unpricedCalls: 0,
833
- unknownUsageCalls: 0
834
- };
835
- }
836
- function pendingModel(input) {
837
- if (input.model) return input.model;
838
- if (input.maximumCharge && "model" in input.maximumCharge) return input.maximumCharge.model;
839
- return "unknown";
840
- }
841
- function unknownReceipt(model) {
842
- return { model, inputTokens: 0, outputTokens: 0, costUnknown: true, usageUnknown: true };
843
- }
844
- function resolveCallId(input) {
845
- if (input !== void 0) {
846
- assertString(input, "callId");
847
- return input;
848
- }
849
- if (typeof globalThis.crypto?.randomUUID !== "function") {
850
- throw new ValidationError("CostLedger: crypto.randomUUID is required when callId is omitted");
851
- }
852
- return globalThis.crypto.randomUUID();
853
- }
854
- function abortError(signal) {
855
- const reason = signal.reason;
856
- if (reason instanceof Error) return reason;
857
- const error = new Error("CostLedger: paid call aborted");
858
- error.name = "AbortError";
859
- return error;
860
- }
861
- function toError(value) {
862
- return value instanceof Error ? value : new Error(String(value));
863
- }
864
- function paidFailure(callId, error, receipt) {
865
- return {
866
- succeeded: false,
867
- callId,
868
- error,
869
- ...receipt ? { receipt: cloneReceipt(receipt) } : {}
870
- };
871
- }
872
- function validationMessage(cause) {
873
- return cause instanceof z.ZodError ? z.prettifyError(cause) : toError(cause).message;
874
- }
875
- function assertUsage(usage) {
876
- assertTokenCount(usage.inputTokens, "inputTokens");
877
- assertTokenCount(usage.outputTokens, "outputTokens");
878
- if (usage.reasoningTokens !== void 0) {
879
- assertTokenCount(usage.reasoningTokens, "reasoningTokens");
880
- if (usage.reasoningTokens > usage.outputTokens) {
881
- throw new ValidationError("CostLedger: reasoningTokens must not exceed outputTokens");
882
- }
883
- }
884
- if (usage.cachedTokens !== void 0) assertTokenCount(usage.cachedTokens, "cachedTokens");
885
- if (usage.cacheWriteTokens !== void 0) {
886
- assertTokenCount(usage.cacheWriteTokens, "cacheWriteTokens");
887
- }
888
- }
889
- function assertTokenCount(value, name) {
890
- if (typeof value !== "number" || !Number.isInteger(value) || value < 0) {
891
- throw new ValidationError(
892
- `CostLedger: ${name} must be a non-negative integer, got ${String(value)}`
893
- );
894
- }
895
- }
896
- function assertNonNegative(value, name) {
897
- if (typeof value !== "number" || !Number.isFinite(value) || value < 0) {
898
- throw new ValidationError(
899
- `CostLedger: ${name} must be a non-negative finite number, got ${String(value)}`
900
- );
901
- }
902
- }
903
- function assertTimeout(value, name) {
904
- if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0 || value > 2147483647) {
905
- throw new ValidationError(
906
- `CostLedger: ${name} must be a non-negative safe integer no greater than 2147483647, got ${String(value)}`
907
- );
908
- }
909
- }
910
- function assertString(value, name) {
911
- if (typeof value !== "string" || value.trim().length === 0) {
912
- throw new ValidationError(`CostLedger: ${name} must be a non-empty string`);
913
- }
914
- }
915
-
916
- export {
917
- CostCeilingReachedError,
918
- CostAccountingIncompleteError,
919
- CostReservationExceededError,
920
- CostCallConflictError,
921
- CostLedgerPersistenceError,
922
- CostReceiptCaptureError,
923
- CostLedger,
924
- modelPriceKey,
925
- costForUsage,
926
- costForTokenPricing
927
- };
928
- //# sourceMappingURL=chunk-VCZ5FQYW.js.map