@tangle-network/agent-eval 0.216.0 → 0.217.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +141 -57
- package/README.md +2 -2
- package/dist/adapters/http.d.ts +3 -3
- package/dist/{agent-profile-CIA2Atnt.d.ts → agent-profile-DTt8uGP9.d.ts} +5 -18
- package/dist/agent-profile-DTt8uGP9.d.ts.map +1 -0
- package/dist/{agent-profile-cell-BYc0bxsL.js → agent-profile-cell-B1V1gUZs.js} +4 -53
- package/dist/agent-profile-cell-B1V1gUZs.js.map +1 -0
- package/dist/{agent-profile-cell-BNp-Js9F.d.ts → agent-profile-cell-BcpFbNd5.d.ts} +2 -22
- package/dist/agent-profile-cell-BcpFbNd5.d.ts.map +1 -0
- package/dist/{agreement-irr-DsTURxdr.js → agreement-irr-BhAqjluA.js} +5 -5
- package/dist/agreement-irr-BhAqjluA.js.map +1 -0
- package/dist/analyst/index.d.ts +37 -170
- package/dist/analyst/index.d.ts.map +1 -1
- package/dist/analyst/index.js +17 -192
- package/dist/analyst/index.js.map +1 -1
- package/dist/{analyze-runs-3xpby3p2.js → analyze-runs-DqPJaJ4X.js} +763 -555
- package/dist/analyze-runs-DqPJaJ4X.js.map +1 -0
- package/dist/{analyze-runs-CSDAh8A7.d.ts → analyze-runs-DyeNcenW.d.ts} +18 -16
- package/dist/analyze-runs-DyeNcenW.d.ts.map +1 -0
- package/dist/authenticity/index.d.ts +0 -23
- package/dist/authenticity/index.d.ts.map +1 -1
- package/dist/authenticity/index.js +1 -34
- package/dist/authenticity/index.js.map +1 -1
- package/dist/{benchmark-command-CByl9dxG.js → benchmark-command-xQK8nOI6.js} +591 -109
- package/dist/benchmark-command-xQK8nOI6.js.map +1 -0
- package/dist/benchmarks/index.d.ts +5 -6
- package/dist/benchmarks/index.d.ts.map +1 -1
- package/dist/benchmarks/index.js +4 -4
- package/dist/benchmarks/index.js.map +1 -1
- package/dist/builder-eval/index.d.ts +3 -3
- package/dist/builder-eval/index.js +2 -2
- package/dist/builder-eval/index.js.map +1 -1
- package/dist/campaign/index.d.ts +8 -8
- package/dist/campaign/index.js +15 -15
- package/dist/{campaign-BQ-Jujuj.js → campaign-CJGkxAQ6.js} +256 -765
- package/dist/campaign-CJGkxAQ6.js.map +1 -0
- package/dist/{campaign-evidence-OcUciD-N.js → campaign-evidence-CQYw8_0H.js} +10 -18
- package/dist/{campaign-evidence-OcUciD-N.js.map → campaign-evidence-CQYw8_0H.js.map} +1 -1
- package/dist/{canonical-BsZVgBhW.js → canonical-Dq2hOQ8L.js} +2 -2
- package/dist/{canonical-BsZVgBhW.js.map → canonical-Dq2hOQ8L.js.map} +1 -1
- package/dist/cell-spend-DEWR3nj-.js +90 -0
- package/dist/cell-spend-DEWR3nj-.js.map +1 -0
- package/dist/{chat-client-DthPOYGd.js → chat-client-ldqxYYTN.js} +2 -2
- package/dist/{chat-client-DthPOYGd.js.map → chat-client-ldqxYYTN.js.map} +1 -1
- package/dist/{chat-json-call-BrKsyspg.js → chat-json-call-DavzexSp.js} +3 -2
- package/dist/chat-json-call-DavzexSp.js.map +1 -0
- package/dist/{claim-BXcZw-jo.js → claim-BPVuyHuy.js} +4 -4
- package/dist/claim-BPVuyHuy.js.map +1 -0
- package/dist/cli.js +113 -12
- package/dist/cli.js.map +1 -1
- package/dist/{client-BzL9niqi.d.ts → client-hwo3cJjR.d.ts} +3 -16
- package/dist/client-hwo3cJjR.d.ts.map +1 -0
- package/dist/{cluster-bootstrap-B3JywQQn.js → cluster-bootstrap-DEwwhl0C.js} +3 -3
- package/dist/{cluster-bootstrap-B3JywQQn.js.map → cluster-bootstrap-DEwwhl0C.js.map} +1 -1
- package/dist/{produced-state-ZCtDBxAE.js → completion-verifier-B_jw6C9p.js} +9 -64
- package/dist/completion-verifier-B_jw6C9p.js.map +1 -0
- package/dist/contract/index.d.ts +13 -13
- package/dist/contract/index.js +1041 -1473
- package/dist/contract/index.js.map +1 -1
- package/dist/{cost-ledger-D2FnJPBF.js → cost-ledger-D0352Z4d.js} +832 -817
- package/dist/cost-ledger-D0352Z4d.js.map +1 -0
- package/dist/{cost-ledger-CO7UyEcQ.d.ts → cost-ledger-Jk62OBfF.d.ts} +12 -47
- package/dist/cost-ledger-Jk62OBfF.d.ts.map +1 -0
- package/dist/dataset-DQqhOCPt.d.ts.map +1 -1
- package/dist/{default-registry-Cn1LQ2Ve.js → default-registry-ClYjq3QE.js} +8 -11
- package/dist/default-registry-ClYjq3QE.js.map +1 -0
- package/dist/{default-registry-BrWh62zf.d.ts → default-registry-DXgLmoDI.d.ts} +7 -50
- package/dist/default-registry-DXgLmoDI.d.ts.map +1 -0
- package/dist/{define-agent-eval-Ch3MWX6k.js → define-agent-eval-BDxNlP3D.js} +10 -10
- package/dist/define-agent-eval-BDxNlP3D.js.map +1 -0
- package/dist/{define-agent-eval-CEWkX5wZ.d.ts → define-agent-eval-BIkH_gAR.d.ts} +9 -9
- package/dist/define-agent-eval-BIkH_gAR.d.ts.map +1 -0
- package/dist/{descriptive-CnU8Yq29.js → descriptive-CVNy48rR.js} +2 -2
- package/dist/{descriptive-CnU8Yq29.js.map → descriptive-CVNy48rR.js.map} +1 -1
- package/dist/diagnosis/index.d.ts +4 -14
- package/dist/diagnosis/index.d.ts.map +1 -1
- package/dist/diagnosis/index.js +67 -28
- package/dist/diagnosis/index.js.map +1 -1
- package/dist/{dspy-rlm-engine-D-KX_e64.js → dspy-rlm-engine-DhdCr1Dc.js} +5 -10
- package/dist/dspy-rlm-engine-DhdCr1Dc.js.map +1 -0
- package/dist/{emitter-HcCmFQl_.d.ts → emitter-DABYYTcH.d.ts} +5 -5
- package/dist/emitter-DABYYTcH.d.ts.map +1 -0
- package/dist/emitter-DbMXUIVP.js.map +1 -1
- package/dist/{engine-C_zNWfM8.d.ts → engine-BvZ0R-36.d.ts} +18 -22
- package/dist/engine-BvZ0R-36.d.ts.map +1 -0
- package/dist/{equal-terms-Blx9Zk5I.js → equal-terms-DbPGcVtI.js} +2 -2
- package/dist/equal-terms-DbPGcVtI.js.map +1 -0
- package/dist/{errors-Dngq5h35.js → errors-BcOs5MKW.js} +6 -8
- package/dist/{errors-Dngq5h35.js.map → errors-BcOs5MKW.js.map} +1 -1
- package/dist/{eval-campaign-4byTtqrf.js → eval-campaign-BLEfBGbA.js} +6 -6
- package/dist/{eval-campaign-4byTtqrf.js.map → eval-campaign-BLEfBGbA.js.map} +1 -1
- package/dist/{evaluation-Cn2dRZIz.d.ts → evaluation-jTjC_QQD.d.ts} +8 -8
- package/dist/evaluation-jTjC_QQD.d.ts.map +1 -0
- package/dist/evaluation.d.ts +2 -2
- package/dist/evaluation.js +1 -1
- package/dist/evaluation.js.map +1 -1
- package/dist/{exact-types-CD0lf5Qd.d.ts → exact-types-CflbJ9f3.d.ts} +2 -2
- package/dist/{exact-types-CD0lf5Qd.d.ts.map → exact-types-CflbJ9f3.d.ts.map} +1 -1
- package/dist/{exec-ChJ6d5if.js → exec-CpbtOXVt.js} +2 -24
- package/dist/{exec-ChJ6d5if.js.map → exec-CpbtOXVt.js.map} +1 -1
- package/dist/execution-tracks-CpgFPpS5.js.map +1 -1
- package/dist/experiment/index.d.ts +331 -33
- package/dist/experiment/index.d.ts.map +1 -1
- package/dist/experiment/index.js +303 -101
- package/dist/experiment/index.js.map +1 -1
- package/dist/{exporters-X4xwla8A.js → exporters-Cl6IeNAu.js} +3 -3
- package/dist/exporters-Cl6IeNAu.js.map +1 -0
- package/dist/{exporters-ChTnR90l.d.ts → exporters-Dk3oEbK_.d.ts} +2 -4
- package/dist/{exporters-ChTnR90l.d.ts.map → exporters-Dk3oEbK_.d.ts.map} +1 -1
- package/dist/{external-optimizer-process-nnsY5D_4.js → external-optimizer-process-KVFGvYX1.js} +4 -3
- package/dist/external-optimizer-process-KVFGvYX1.js.map +1 -0
- package/dist/{external-optimizer-subprocess-DcerlZSG.js → external-optimizer-subprocess-XIHBOSKt.js} +551 -553
- package/dist/external-optimizer-subprocess-XIHBOSKt.js.map +1 -0
- package/dist/{extract-usage-BrnzRJ6H.js → extract-usage-BZLU01kR.js} +2 -23
- package/dist/{extract-usage-BrnzRJ6H.js.map → extract-usage-BZLU01kR.js.map} +1 -1
- package/dist/{failure-cluster-CbgEDcFJ.d.ts → failure-cluster-DN0t63Z0.d.ts} +4 -43
- package/dist/failure-cluster-DN0t63Z0.d.ts.map +1 -0
- package/dist/{failure-taxonomy-CjabTATj.js → failure-taxonomy-Bx5oWqaW.js} +2 -19
- package/dist/{failure-taxonomy-CjabTATj.js.map → failure-taxonomy-Bx5oWqaW.js.map} +1 -1
- package/dist/{feedback-trajectory-DkaDj0dj.d.ts → feedback-trajectory-BWmhRBGu.d.ts} +8 -13
- package/dist/feedback-trajectory-BWmhRBGu.d.ts.map +1 -0
- package/dist/{semantic-concept-judge-zQBG9hHU.js → findings-store-BMVQtEsm.js} +13 -255
- package/dist/findings-store-BMVQtEsm.js.map +1 -0
- package/dist/fuzz.d.ts +20 -63
- package/dist/fuzz.d.ts.map +1 -1
- package/dist/fuzz.js +62 -108
- package/dist/fuzz.js.map +1 -1
- package/dist/{hf-dataset-BR2yhuNn.js → hf-dataset-D9f7-oX7.js} +4 -24
- package/dist/hf-dataset-D9f7-oX7.js.map +1 -0
- package/dist/hosted/index.d.ts +2 -2
- package/dist/hosted/index.js +2 -2
- package/dist/{index-DHKEAv3s.d.ts → index-9jJ2fKSX.d.ts} +2 -64
- package/dist/index-9jJ2fKSX.d.ts.map +1 -0
- package/dist/{index-oQ4aHziK.d.ts → index-BLGqZ81N.d.ts} +11 -16
- package/dist/{index-oQ4aHziK.d.ts.map → index-BLGqZ81N.d.ts.map} +1 -1
- package/dist/{index-DlH0Y9gI.d.ts → index-BiT6RtNH.d.ts} +31 -43
- package/dist/index-BiT6RtNH.d.ts.map +1 -0
- package/dist/{index-Ch9VxCpK.d.ts → index-CX-GAUpw.d.ts} +4 -8
- package/dist/index-CX-GAUpw.d.ts.map +1 -0
- package/dist/{index-CPJJr98o.d.ts → index-CiRwLv2R.d.ts} +5 -68
- package/dist/index-CiRwLv2R.d.ts.map +1 -0
- package/dist/{index-NvGBiO8H.d.ts → index-ZuWx52WG.d.ts} +266 -495
- package/dist/index-ZuWx52WG.d.ts.map +1 -0
- package/dist/index.d.ts +2256 -2165
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +514 -1192
- package/dist/index.js.map +1 -1
- package/dist/{integrity-BV1ZDf42.js → integrity-DOd9Q86O.js} +7 -12
- package/dist/integrity-DOd9Q86O.js.map +1 -0
- package/dist/{integrity-BvnVARVl.js → integrity-W4CADcFc.js} +3 -7
- package/dist/{integrity-BvnVARVl.js.map → integrity-W4CADcFc.js.map} +1 -1
- package/dist/{integrity-CCAxGVK6.d.ts → integrity-_qgZLA5p.d.ts} +4 -6
- package/dist/{integrity-CCAxGVK6.d.ts.map → integrity-_qgZLA5p.d.ts.map} +1 -1
- package/dist/{internal-CRHwS9iz.js → internal-BTK91Bqt.js} +3 -3
- package/dist/{internal-CRHwS9iz.js.map → internal-BTK91Bqt.js.map} +1 -1
- package/dist/interval-Dq9gt7jx.js +219 -0
- package/dist/interval-Dq9gt7jx.js.map +1 -0
- package/dist/interval-ohuOJurX.d.ts +47 -0
- package/dist/interval-ohuOJurX.d.ts.map +1 -0
- package/dist/{journal-DvKCvjty.js → journal-CR4QikYp.js} +110 -110
- package/dist/journal-CR4QikYp.js.map +1 -0
- package/dist/json-BhdsJaOQ.js +111 -0
- package/dist/json-BhdsJaOQ.js.map +1 -0
- package/dist/{judge-calibration-N44V04Se.js → judge-calibration-BkXMIWA4.js} +3 -3
- package/dist/{judge-calibration-N44V04Se.js.map → judge-calibration-BkXMIWA4.js.map} +1 -1
- package/dist/{judge-gate-B1qYnkpi.js → judge-gate-Co5tuh57.js} +4 -27
- package/dist/judge-gate-Co5tuh57.js.map +1 -0
- package/dist/{judge-gate-DNcUrRFA.d.ts → judge-gate-DsL0yFcb.d.ts} +9 -10
- package/dist/judge-gate-DsL0yFcb.d.ts.map +1 -0
- package/dist/{kind-factory-CbZ-6tvu.js → kind-factory-Gy4fXixd.js} +88 -17
- package/dist/kind-factory-Gy4fXixd.js.map +1 -0
- package/dist/ledger-core/index.d.ts +2 -2
- package/dist/ledger-core/index.js +4 -4
- package/dist/{ledger-core-B2hahzrt.js → ledger-core-DrJhbms9.js} +5 -84
- package/dist/ledger-core-DrJhbms9.js.map +1 -0
- package/dist/{llm-client-DQveoxSM.js → llm-client-BshCREn6.js} +90 -219
- package/dist/llm-client-BshCREn6.js.map +1 -0
- package/dist/{llm-judge-PXV7Xljl.js → llm-judge-C8jMTNNG.js} +501 -931
- package/dist/llm-judge-C8jMTNNG.js.map +1 -0
- package/dist/matrix/index.d.ts +4 -4
- package/dist/matrix/index.js +3 -2
- package/dist/{matrix-_BV9-Lk5.js → matrix-B8l-Nsxd.js} +7 -96
- package/dist/matrix-B8l-Nsxd.js.map +1 -0
- package/dist/{matrix-CHMiebFx.d.ts → matrix-DHe-dwVJ.d.ts} +10 -19
- package/dist/matrix-DHe-dwVJ.d.ts.map +1 -0
- package/dist/{paired-tests-jbwPdSz5.js → mean-BbA_JCzW.js} +45 -5
- package/dist/mean-BbA_JCzW.js.map +1 -0
- package/dist/meta-eval/index.d.ts +6 -6
- package/dist/meta-eval/index.js +10 -10
- package/dist/meta-eval/index.js.map +1 -1
- package/dist/metrics-BKaPBtIG.js.map +1 -1
- package/dist/mint-BRZXuwRi.d.ts +81 -0
- package/dist/mint-BRZXuwRi.d.ts.map +1 -0
- package/dist/{mint-Csor1BLJ.js → mint-zszyYlpA.js} +4 -4
- package/dist/{mint-Csor1BLJ.js.map → mint-zszyYlpA.js.map} +1 -1
- package/dist/{multi-layer-verifier-BUaQ4C17.d.ts → multi-layer-verifier-DEgMUk6v.d.ts} +2 -2
- package/dist/{multi-layer-verifier-BUaQ4C17.d.ts.map → multi-layer-verifier-DEgMUk6v.d.ts.map} +1 -1
- package/dist/{multiplicity-D9cjmStq.js → multiplicity-Sg0U7h8j.js} +2 -2
- package/dist/{multiplicity-D9cjmStq.js.map → multiplicity-Sg0U7h8j.js.map} +1 -1
- package/dist/multishot/golden/index.d.ts +1 -23
- package/dist/multishot/golden/index.d.ts.map +1 -1
- package/dist/multishot/golden/index.js +5 -8
- package/dist/multishot/golden/index.js.map +1 -1
- package/dist/multishot/index.d.ts +3 -12
- package/dist/multishot/index.d.ts.map +1 -1
- package/dist/multishot/index.js +4 -3
- package/dist/multishot/index.js.map +1 -1
- package/dist/nonnegative-number-DvdMxg_f.js +9 -0
- package/dist/nonnegative-number-DvdMxg_f.js.map +1 -0
- package/dist/openapi.json +114 -10
- package/dist/{otel-spans-C8YIJWy1.js → otel-spans-CdN909k1.js} +3 -3
- package/dist/{otel-spans-C8YIJWy1.js.map → otel-spans-CdN909k1.js.map} +1 -1
- package/dist/{paired-arms-DzKn0TfY.js → paired-arms-Ct4LTKc1.js} +32 -9
- package/dist/paired-arms-Ct4LTKc1.js.map +1 -0
- package/dist/{paired-binary-Q36bhn2R.js → paired-binary-B_nejA44.js} +3 -36
- package/dist/paired-binary-B_nejA44.js.map +1 -0
- package/dist/{paired-promotion-decision-DPKz8ZnF.d.ts → paired-promotion-decision-CQMJ5xGN.d.ts} +2 -34
- package/dist/paired-promotion-decision-CQMJ5xGN.d.ts.map +1 -0
- package/dist/{paired-promotion-decision-BN6IQTiu.js → paired-promotion-decision-D0SHb-ZL.js} +3 -3
- package/dist/{paired-promotion-decision-BN6IQTiu.js.map → paired-promotion-decision-D0SHb-ZL.js.map} +1 -1
- package/dist/{search-kernel-BztlERLv.js → pareto-BzsxidFD.js} +883 -861
- package/dist/pareto-BzsxidFD.js.map +1 -0
- package/dist/pipelines/index.d.ts +16 -19
- package/dist/pipelines/index.d.ts.map +1 -1
- package/dist/pipelines/index.js +4 -68
- package/dist/pipelines/index.js.map +1 -1
- package/dist/{power-and-mde-fK5Qocwo.js → power-and-mde-N5nU4_Ly.js} +3 -3
- package/dist/{power-and-mde-fK5Qocwo.js.map → power-and-mde-N5nU4_Ly.js.map} +1 -1
- package/dist/predicate-FdKmElA_.js +38 -0
- package/dist/predicate-FdKmElA_.js.map +1 -0
- package/dist/{prime-protocol-DcAK9pC8.js → prime-protocol-BFgGrEMP.js} +3 -3
- package/dist/prime-protocol-BFgGrEMP.js.map +1 -0
- package/dist/{prime-protocol-CEE4BR9N.d.ts → prime-protocol-BWG2DQIk.d.ts} +4 -22
- package/dist/prime-protocol-BWG2DQIk.d.ts.map +1 -0
- package/dist/profile-cell.d.ts +2 -2
- package/dist/profile-cell.js +2 -2
- package/dist/{release-confidence-BK2QCB5M.d.ts → promotion-gate-DaY95yU6.d.ts} +105 -106
- package/dist/promotion-gate-DaY95yU6.d.ts.map +1 -0
- package/dist/{promotion-policy-CWW35UWq.js → promotion-policy-6A8osGr_.js} +4 -4
- package/dist/{promotion-policy-CWW35UWq.js.map → promotion-policy-6A8osGr_.js.map} +1 -1
- package/dist/{proposal-findings-BZiMTzAF.js → proposal-findings-BbWidvUk.js} +3 -3
- package/dist/proposal-findings-BbWidvUk.js.map +1 -0
- package/dist/{query-B1D1qp2Z.js → query-B_RZ36an.js} +5 -5
- package/dist/query-B_RZ36an.js.map +1 -0
- package/dist/{query-DK1nWcmp.d.ts → query-Cmv_U8vf.d.ts} +4 -24
- package/dist/{query-DK1nWcmp.d.ts.map → query-Cmv_U8vf.d.ts.map} +1 -1
- package/dist/{random-Dn5fPWkt.js → random-DDDcC7YU.js} +2 -2
- package/dist/{random-Dn5fPWkt.js.map → random-DDDcC7YU.js.map} +1 -1
- package/dist/{raw-provider-sink-rB2DYxr6.js → raw-provider-sink-75w4FWBj.js} +2 -2
- package/dist/{raw-provider-sink-rB2DYxr6.js.map → raw-provider-sink-75w4FWBj.js.map} +1 -1
- package/dist/{redact-Cveoq6fJ.d.ts → redact-DXdlFb_U.d.ts} +4 -21
- package/dist/redact-DXdlFb_U.d.ts.map +1 -0
- package/dist/{redact-Dk1ZdJEm.js → redact-mtkTiJVk.js} +92 -98
- package/dist/redact-mtkTiJVk.js.map +1 -0
- package/dist/{registry-JYfPxcVz.d.ts → registry-ssNoHzwD.d.ts} +5 -5
- package/dist/{registry-JYfPxcVz.d.ts.map → registry-ssNoHzwD.d.ts.map} +1 -1
- package/dist/{release-confidence-Dbe9AS_X.js → release-confidence-CYIFH-fp.js} +6 -11
- package/dist/release-confidence-CYIFH-fp.js.map +1 -0
- package/dist/{report-command-y8H6RSX8.js → render-C-w2EZ6p.js} +331 -554
- package/dist/render-C-w2EZ6p.js.map +1 -0
- package/dist/reporting-html-Kvlc8oMt.js +100 -0
- package/dist/reporting-html-Kvlc8oMt.js.map +1 -0
- package/dist/reporting.d.ts +6 -6
- package/dist/reporting.js +8 -8
- package/dist/{researcher-f6mZhh58.d.ts → researcher-0ABVIdGa.d.ts} +9 -9
- package/dist/{researcher-f6mZhh58.d.ts.map → researcher-0ABVIdGa.d.ts.map} +1 -1
- package/dist/reward-DrZ71vnf.d.ts +55 -0
- package/dist/reward-DrZ71vnf.d.ts.map +1 -0
- package/dist/{reward-hacking-BFcQgkux.js → reward-hacking-ByuETaIb.js} +3 -3
- package/dist/{reward-hacking-BFcQgkux.js.map → reward-hacking-ByuETaIb.js.map} +1 -1
- package/dist/{reward-hacking-DHA7c1l8.d.ts → reward-hacking-E52wq86n.d.ts} +5 -18
- package/dist/reward-hacking-E52wq86n.d.ts.map +1 -0
- package/dist/reward-nw2xZGZG.js.map +1 -1
- package/dist/rl.d.ts +117 -295
- package/dist/rl.d.ts.map +1 -1
- package/dist/rl.js +27 -747
- package/dist/rl.js.map +1 -1
- package/dist/rollout/index.d.ts +5 -4
- package/dist/rollout/index.js +7 -8
- package/dist/{rollout-D9bKKBnZ.js → rollout-D6C50mfA.js} +88 -13
- package/dist/rollout-D6C50mfA.js.map +1 -0
- package/dist/round-decimal-COrKglMh.js +10 -0
- package/dist/round-decimal-COrKglMh.js.map +1 -0
- package/dist/{rubric-predictive-validity-BsgkBfT0.js → rubric-predictive-validity-D3_oI72N.js} +3 -3
- package/dist/{rubric-predictive-validity-BsgkBfT0.js.map → rubric-predictive-validity-D3_oI72N.js.map} +1 -1
- package/dist/{rubric-predictive-validity-2SgHxoa5.d.ts → rubric-predictive-validity-DiwT8PbL.d.ts} +2 -2
- package/dist/{rubric-predictive-validity-2SgHxoa5.d.ts.map → rubric-predictive-validity-DiwT8PbL.d.ts.map} +1 -1
- package/dist/{run-record-D1Hw-Jml.d.ts → run-record-CaxbLq6Y.d.ts} +5 -11
- package/dist/run-record-CaxbLq6Y.d.ts.map +1 -0
- package/dist/{run-record-ES07wfz9.js → run-record-CysKLB93.js} +3 -5
- package/dist/run-record-CysKLB93.js.map +1 -0
- package/dist/{run-record-DlTZ_lqe.js → run-record-DhEJgoPz.js} +4 -4
- package/dist/{run-record-DlTZ_lqe.js.map → run-record-DhEJgoPz.js.map} +1 -1
- package/dist/sandbox-harness-BlSOu4LX.d.ts.map +1 -1
- package/dist/{schema-CSf6qWgZ.js → schema-Bt2vLFm3.js} +2 -14
- package/dist/schema-Bt2vLFm3.js.map +1 -0
- package/dist/schema-C-ziyJD7.d.ts.map +1 -1
- package/dist/{schema-2g7trUwH.d.ts → schema-D6EVKzTB.d.ts} +4 -5
- package/dist/schema-D6EVKzTB.d.ts.map +1 -0
- package/dist/{schema-BuiujZ-g.js → schema-DxcKTzbi.js} +2 -2
- package/dist/schema-DxcKTzbi.js.map +1 -0
- package/dist/search/index.d.ts +39 -53
- package/dist/search/index.d.ts.map +1 -1
- package/dist/search/index.js +4 -4
- package/dist/{search-kernel-CpcKH5Ih.d.ts → search-kernel-DxqjBxA-.d.ts} +18 -31
- package/dist/search-kernel-DxqjBxA-.d.ts.map +1 -0
- package/dist/{search-ledger-d7V8o9Lk.js → search-ledger-TUvB5gWH.js} +189 -199
- package/dist/search-ledger-TUvB5gWH.js.map +1 -0
- package/dist/{search-ledger-file-BqOo-bVo.js → search-ledger-file-UKCO2r8a.js} +4 -4
- package/dist/search-ledger-file-UKCO2r8a.js.map +1 -0
- package/dist/search-ledger-types-p2xKfiDJ.d.ts.map +1 -1
- package/dist/{search-shipper-er4pK5_Y.js → search-shipper-Cw2z3-td.js} +4 -4
- package/dist/search-shipper-Cw2z3-td.js.map +1 -0
- package/dist/{search-summary-CBvz3u_S.js → search-summary-DQIvJsSB.js} +5 -5
- package/dist/{search-summary-CBvz3u_S.js.map → search-summary-DQIvJsSB.js.map} +1 -1
- package/dist/{sequential-CzK5DarL.js → sequential-BVv1sjsw.js} +2 -32
- package/dist/{sequential-CzK5DarL.js.map → sequential-BVv1sjsw.js.map} +1 -1
- package/dist/{sequential-D-1PPCmM.js → sequential-CimQrbjv.js} +5 -5
- package/dist/sequential-CimQrbjv.js.map +1 -0
- package/dist/{sequential-BhsrMupG.d.ts → sequential-KwGspfeR.d.ts} +2 -9
- package/dist/{sequential-BhsrMupG.d.ts.map → sequential-KwGspfeR.d.ts.map} +1 -1
- package/dist/{sequential-eprocess-D1jKoihe.js → sequential-eprocess-DodI6RoF.js} +2 -2
- package/dist/{sequential-eprocess-D1jKoihe.js.map → sequential-eprocess-DodI6RoF.js.map} +1 -1
- package/dist/{server-DbcC7xMl.js → server-DoVbqqtJ.js} +101 -101
- package/dist/server-DoVbqqtJ.js.map +1 -0
- package/dist/{single-run-lock-fVu3MZWH.js → single-run-lock-U58yf8N6.js} +2 -2
- package/dist/{single-run-lock-fVu3MZWH.js.map → single-run-lock-U58yf8N6.js.map} +1 -1
- package/dist/{skillopt-optimization-method-CCtzralq.js → skillopt-optimization-method-kyL94-ri.js} +428 -91
- package/dist/skillopt-optimization-method-kyL94-ri.js.map +1 -0
- package/dist/{spans-D9_ehFuk.d.ts → spans-CVngGij3.d.ts} +2 -2
- package/dist/{spans-D9_ehFuk.d.ts.map → spans-CVngGij3.d.ts.map} +1 -1
- package/dist/{statistical-heldout-1Gbmex7v.js → statistical-heldout-Bksv92Th.js} +3 -3
- package/dist/statistical-heldout-Bksv92Th.js.map +1 -0
- package/dist/{statistical-heldout-BeR4bOdg.d.ts → statistical-heldout-C9AbgREN.d.ts} +8 -67
- package/dist/statistical-heldout-C9AbgREN.d.ts.map +1 -0
- package/dist/{steps-Bg5-KVx1.d.ts → steps-DlepJPwD.d.ts} +2 -56
- package/dist/steps-DlepJPwD.d.ts.map +1 -0
- package/dist/{store-C4avFjIi.d.ts → store-B3nWRy3B.d.ts} +2 -2
- package/dist/{store-C4avFjIi.d.ts.map → store-B3nWRy3B.d.ts.map} +1 -1
- package/dist/{store-otlp-DtB4Slsr.js → store-otlp-BteDAbHK.js} +135 -132
- package/dist/store-otlp-BteDAbHK.js.map +1 -0
- package/dist/{store-tool-spans-fZIigrpP.js → store-tool-spans-D5l_OfTJ.js} +9 -9
- package/dist/store-tool-spans-D5l_OfTJ.js.map +1 -0
- package/dist/{store-tool-spans-DR1SrCLK.d.ts → store-tool-spans-DZS0HWVf.d.ts} +157 -165
- package/dist/store-tool-spans-DZS0HWVf.d.ts.map +1 -0
- package/dist/storyboard/index.d.ts +4 -11
- package/dist/storyboard/index.d.ts.map +1 -1
- package/dist/storyboard/index.js +21 -19
- package/dist/storyboard/index.js.map +1 -1
- package/dist/{summary-report-DtdRucM0.js → summary-report-BsXJoYX5.js} +588 -598
- package/dist/summary-report-BsXJoYX5.js.map +1 -0
- package/dist/{summary-report-C-CtItCN.d.ts → summary-report-DM7tlml1.d.ts} +16 -20
- package/dist/summary-report-DM7tlml1.d.ts.map +1 -0
- package/dist/supervisor-run/index.d.ts +189 -153
- package/dist/supervisor-run/index.d.ts.map +1 -1
- package/dist/supervisor-run/index.js +58 -450
- package/dist/supervisor-run/index.js.map +1 -1
- package/dist/{systemone-CpTLAlqb.d.ts → systemone-Bp_Ac0p1.d.ts} +6 -6
- package/dist/{systemone-CpTLAlqb.d.ts.map → systemone-Bp_Ac0p1.d.ts.map} +1 -1
- package/dist/systemone-protocol.js +1 -1
- package/dist/{systemone-review-B_yo1xsd.d.ts → systemone-review-CwE6JGIp.d.ts} +2 -2
- package/dist/{systemone-review-B_yo1xsd.d.ts.map → systemone-review-CwE6JGIp.d.ts.map} +1 -1
- package/dist/{systemone-review-BZWfrtq1.js → systemone-review-DzdOJ8I6.js} +3 -3
- package/dist/{systemone-review-BZWfrtq1.js.map → systemone-review-DzdOJ8I6.js.map} +1 -1
- package/dist/systemone.d.ts +5 -5
- package/dist/systemone.js +5 -5
- package/dist/systemone.js.map +1 -1
- package/dist/{task-failure-attributes-DngaLdE4.js → task-failure-attributes-BMsblaDh.js} +3 -3
- package/dist/task-failure-attributes-BMsblaDh.js.map +1 -0
- package/dist/{terminal-record-BHocwFw1.js → terminal-record-78g6E4vh.js} +17 -13
- package/dist/terminal-record-78g6E4vh.js.map +1 -0
- package/dist/{tool-groups-mcxOXVlb.d.ts → tool-groups-DyNz2JZ_.d.ts} +3 -3
- package/dist/tool-groups-DyNz2JZ_.d.ts.map +1 -0
- package/dist/{tool-waste-Wi4g6Ekb.d.ts → tool-waste-CkjzWmeY.d.ts} +53 -56
- package/dist/tool-waste-CkjzWmeY.d.ts.map +1 -0
- package/dist/{tool-waste-D52PqU9Q.js → tool-waste-DLsjS_p-.js} +5 -5
- package/dist/{tool-waste-D52PqU9Q.js.map → tool-waste-DLsjS_p-.js.map} +1 -1
- package/dist/{trace-questions-DG7nqLQ7.d.ts → trace-questions-xxwgsuMi.d.ts} +5 -10
- package/dist/{trace-questions-DG7nqLQ7.d.ts.map → trace-questions-xxwgsuMi.d.ts.map} +1 -1
- package/dist/trace-repair/index.d.ts +15 -212
- package/dist/trace-repair/index.d.ts.map +1 -1
- package/dist/trace-repair/index.js +865 -987
- package/dist/trace-repair/index.js.map +1 -1
- package/dist/traces.d.ts +76 -86
- package/dist/traces.d.ts.map +1 -1
- package/dist/traces.js +13 -13
- package/dist/traces.js.map +1 -1
- package/dist/trajectory-replay/index.d.ts +3 -117
- package/dist/trajectory-replay/index.d.ts.map +1 -1
- package/dist/trajectory-replay/index.js +98 -56
- package/dist/trajectory-replay/index.js.map +1 -1
- package/dist/{tree-rXLW3M_4.js → tree-BGRglkKd.js} +2355 -2414
- package/dist/tree-BGRglkKd.js.map +1 -0
- package/dist/{types-B3jzCp0p.js → types-BXgASBCL.js} +2 -2
- package/dist/{types-B3jzCp0p.js.map → types-BXgASBCL.js.map} +1 -1
- package/dist/{types-oKRhQAde.d.ts → types-CW8ewATZ.d.ts} +5 -114
- package/dist/types-CW8ewATZ.d.ts.map +1 -0
- package/dist/{types-BqkVmHfv.d.ts → types-CmXY0PQf.d.ts} +2 -4
- package/dist/types-CmXY0PQf.d.ts.map +1 -0
- package/dist/{types-DBZ7keha.d.ts → types-D-mgRzlh.d.ts} +9 -72
- package/dist/types-D-mgRzlh.d.ts.map +1 -0
- package/dist/{types-B4C5nFw6.d.ts → types-D8GhJoHk.d.ts} +79 -75
- package/dist/types-D8GhJoHk.d.ts.map +1 -0
- package/dist/{types-IXD2HJzu.js → types-DqFMNTgK.js} +2 -4
- package/dist/types-DqFMNTgK.js.map +1 -0
- package/dist/{types-CfZMIzB_.d.ts → types-DtMbFw6U.d.ts} +3 -3
- package/dist/{types-CfZMIzB_.d.ts.map → types-DtMbFw6U.d.ts.map} +1 -1
- package/dist/{verdict-DhPoXApk.js → verdict-BGQmxQ8A.js} +3 -3
- package/dist/verdict-BGQmxQ8A.js.map +1 -0
- package/dist/{verdict-E4eRNf7-.d.ts → verdict-C24NELtN.d.ts} +2 -15
- package/dist/{verdict-E4eRNf7-.d.ts.map → verdict-C24NELtN.d.ts.map} +1 -1
- package/dist/{verdict-cache-BQEsVy9n.js → verdict-cache-CL_7tePD.js} +2 -2
- package/dist/verdict-cache-CL_7tePD.js.map +1 -0
- package/dist/wire/index.d.ts +32 -411
- package/dist/wire/index.d.ts.map +1 -1
- package/dist/wire/index.js +2 -2
- package/docs/changes/jev-evidence-review.md +1 -1
- package/docs/changes/jev-product-adoption.md +1 -1
- package/docs/changes/jev-recorded-evidence.md +1 -1
- package/docs/design/mlbenchmarks-book-review.md +1 -1
- package/docs/design/mlbenchmarks-review/probes.mts +23 -31
- package/docs/design/statistics-decisions.md +17 -17
- package/docs/design.md +1 -1
- package/docs/evaluation-integrity.md +1 -1
- package/docs/experiment.md +1 -1
- package/docs/proofs/campaign-attempt-retention-20261001/README.md +2 -2
- package/docs/public-api.md +138 -529
- package/docs/rollout.md +1 -1
- package/docs/trace-repair-admission.md +1 -1
- package/docs/wire-protocol.md +1 -1
- package/package.json +1 -1
- package/dist/active-curriculum-B_Lc9kfO.js +0 -61
- package/dist/active-curriculum-B_Lc9kfO.js.map +0 -1
- package/dist/agent-profile-CIA2Atnt.d.ts.map +0 -1
- package/dist/agent-profile-cell-BNp-Js9F.d.ts.map +0 -1
- package/dist/agent-profile-cell-BYc0bxsL.js.map +0 -1
- package/dist/agreement-irr-DsTURxdr.js.map +0 -1
- package/dist/analyze-runs-3xpby3p2.js.map +0 -1
- package/dist/analyze-runs-CSDAh8A7.d.ts.map +0 -1
- package/dist/ast-DJ6Bc7ab.js +0 -558
- package/dist/ast-DJ6Bc7ab.js.map +0 -1
- package/dist/ast-hI-vjW6J.d.ts +0 -457
- package/dist/ast-hI-vjW6J.d.ts.map +0 -1
- package/dist/baseline-Dm8966du.js +0 -259
- package/dist/baseline-Dm8966du.js.map +0 -1
- package/dist/benchmark-BywPeAUo.js +0 -562
- package/dist/benchmark-BywPeAUo.js.map +0 -1
- package/dist/benchmark-command-CByl9dxG.js.map +0 -1
- package/dist/campaign-BQ-Jujuj.js.map +0 -1
- package/dist/chat-json-call-BrKsyspg.js.map +0 -1
- package/dist/claim-BXcZw-jo.js.map +0 -1
- package/dist/claude-jsonl-dZir12m6.js +0 -86
- package/dist/claude-jsonl-dZir12m6.js.map +0 -1
- package/dist/client-BzL9niqi.d.ts.map +0 -1
- package/dist/cost-ledger-CO7UyEcQ.d.ts.map +0 -1
- package/dist/cost-ledger-D2FnJPBF.js.map +0 -1
- package/dist/counterfactual-CPaWN99-.d.ts +0 -60
- package/dist/counterfactual-CPaWN99-.d.ts.map +0 -1
- package/dist/counterfactual-DtMWvn7D.js +0 -98
- package/dist/counterfactual-DtMWvn7D.js.map +0 -1
- package/dist/default-registry-BrWh62zf.d.ts.map +0 -1
- package/dist/default-registry-Cn1LQ2Ve.js.map +0 -1
- package/dist/define-agent-eval-CEWkX5wZ.d.ts.map +0 -1
- package/dist/define-agent-eval-Ch3MWX6k.js.map +0 -1
- package/dist/dspy-rlm-engine-D-KX_e64.js.map +0 -1
- package/dist/effect-sizes-DiH8MGOH.js +0 -82
- package/dist/effect-sizes-DiH8MGOH.js.map +0 -1
- package/dist/emitter-HcCmFQl_.d.ts.map +0 -1
- package/dist/engine-C_zNWfM8.d.ts.map +0 -1
- package/dist/equal-terms-Blx9Zk5I.js.map +0 -1
- package/dist/evaluation-Cn2dRZIz.d.ts.map +0 -1
- package/dist/exporters-X4xwla8A.js.map +0 -1
- package/dist/external-optimizer-process-nnsY5D_4.js.map +0 -1
- package/dist/external-optimizer-subprocess-DcerlZSG.js.map +0 -1
- package/dist/failure-cluster-CbgEDcFJ.d.ts.map +0 -1
- package/dist/feedback-trajectory-DkaDj0dj.d.ts.map +0 -1
- package/dist/hf-dataset-BR2yhuNn.js.map +0 -1
- package/dist/index-CPJJr98o.d.ts.map +0 -1
- package/dist/index-Ch9VxCpK.d.ts.map +0 -1
- package/dist/index-DHKEAv3s.d.ts.map +0 -1
- package/dist/index-DlH0Y9gI.d.ts.map +0 -1
- package/dist/index-NvGBiO8H.d.ts.map +0 -1
- package/dist/integrity-BV1ZDf42.js.map +0 -1
- package/dist/journal-DvKCvjty.js.map +0 -1
- package/dist/judge-gate-B1qYnkpi.js.map +0 -1
- package/dist/judge-gate-DNcUrRFA.d.ts.map +0 -1
- package/dist/kind-factory-CbZ-6tvu.js.map +0 -1
- package/dist/ledger-core-B2hahzrt.js.map +0 -1
- package/dist/llm-client-DQveoxSM.js.map +0 -1
- package/dist/llm-judge-PXV7Xljl.js.map +0 -1
- package/dist/matrix-CHMiebFx.d.ts.map +0 -1
- package/dist/matrix-_BV9-Lk5.js.map +0 -1
- package/dist/mint-DCGoBYhB.d.ts +0 -155
- package/dist/mint-DCGoBYhB.d.ts.map +0 -1
- package/dist/normal-DsJZtrJc.js +0 -25
- package/dist/normal-DsJZtrJc.js.map +0 -1
- package/dist/paired-arms-DzKn0TfY.js.map +0 -1
- package/dist/paired-binary-Q36bhn2R.js.map +0 -1
- package/dist/paired-promotion-decision-DPKz8ZnF.d.ts.map +0 -1
- package/dist/paired-tests-jbwPdSz5.js.map +0 -1
- package/dist/prime-protocol-CEE4BR9N.d.ts.map +0 -1
- package/dist/prime-protocol-DcAK9pC8.js.map +0 -1
- package/dist/produced-state-ZCtDBxAE.js.map +0 -1
- package/dist/proposal-findings-BZiMTzAF.js.map +0 -1
- package/dist/query-B1D1qp2Z.js.map +0 -1
- package/dist/redact-Cveoq6fJ.d.ts.map +0 -1
- package/dist/redact-Dk1ZdJEm.js.map +0 -1
- package/dist/release-confidence-BK2QCB5M.d.ts.map +0 -1
- package/dist/release-confidence-Dbe9AS_X.js.map +0 -1
- package/dist/report-command-y8H6RSX8.js.map +0 -1
- package/dist/reward-hacking-DHA7c1l8.d.ts.map +0 -1
- package/dist/rollout-D9bKKBnZ.js.map +0 -1
- package/dist/run-record-D1Hw-Jml.d.ts.map +0 -1
- package/dist/run-record-ES07wfz9.js.map +0 -1
- package/dist/schema-2g7trUwH.d.ts.map +0 -1
- package/dist/schema-BuiujZ-g.js.map +0 -1
- package/dist/schema-CSf6qWgZ.js.map +0 -1
- package/dist/search-kernel-BztlERLv.js.map +0 -1
- package/dist/search-kernel-CpcKH5Ih.d.ts.map +0 -1
- package/dist/search-ledger-d7V8o9Lk.js.map +0 -1
- package/dist/search-ledger-file-BqOo-bVo.js.map +0 -1
- package/dist/search-shipper-er4pK5_Y.js.map +0 -1
- package/dist/semantic-concept-judge-zQBG9hHU.js.map +0 -1
- package/dist/sequential-D-1PPCmM.js.map +0 -1
- package/dist/server-DbcC7xMl.js.map +0 -1
- package/dist/skillopt-optimization-method-CCtzralq.js.map +0 -1
- package/dist/statistical-heldout-1Gbmex7v.js.map +0 -1
- package/dist/statistical-heldout-BeR4bOdg.d.ts.map +0 -1
- package/dist/steps-Bg5-KVx1.d.ts.map +0 -1
- package/dist/store-otlp-DtB4Slsr.js.map +0 -1
- package/dist/store-tool-spans-DR1SrCLK.d.ts.map +0 -1
- package/dist/store-tool-spans-fZIigrpP.js.map +0 -1
- package/dist/student-t-BQeKJx2N.js +0 -39
- package/dist/student-t-BQeKJx2N.js.map +0 -1
- package/dist/summary-report-C-CtItCN.d.ts.map +0 -1
- package/dist/summary-report-DtdRucM0.js.map +0 -1
- package/dist/task-failure-attributes-DngaLdE4.js.map +0 -1
- package/dist/terminal-record-BHocwFw1.js.map +0 -1
- package/dist/tool-groups-mcxOXVlb.d.ts.map +0 -1
- package/dist/tool-waste-Wi4g6Ekb.d.ts.map +0 -1
- package/dist/trajectory-Y1fmdlw7.d.ts +0 -24
- package/dist/trajectory-Y1fmdlw7.d.ts.map +0 -1
- package/dist/tree-rXLW3M_4.js.map +0 -1
- package/dist/types-B4C5nFw6.d.ts.map +0 -1
- package/dist/types-BqkVmHfv.d.ts.map +0 -1
- package/dist/types-DBZ7keha.d.ts.map +0 -1
- package/dist/types-IXD2HJzu.js.map +0 -1
- package/dist/types-oKRhQAde.d.ts.map +0 -1
- package/dist/usage-receipt-Cx3xNeyB.js +0 -76
- package/dist/usage-receipt-Cx3xNeyB.js.map +0 -1
- package/dist/verdict-DhPoXApk.js.map +0 -1
- package/dist/verdict-cache-BQEsVy9n.js.map +0 -1
- package/docs/design/self-improvement-evidence-audit.md +0 -263
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"chat-json-call-BrKsyspg.js","names":[],"sources":["../src/chat-json-call.ts"],"sourcesContent":["/**\n * One paid model call through a caller-owned `ChatClient`, metered by the\n * cost ledger.\n *\n * agent-eval executes no paid model: the transport is supplied by the caller\n * and the credential never enters this package. What stays here is the\n * accounting around the call — the priced maximum reserved before it runs, the\n * stable call id forwarded as the provider idempotency key, the receipt\n * settled from the response, and an honest unknown-usage receipt when the\n * transport failed.\n *\n * The judges, the wire judge endpoint, and the in-process trace-analysis\n * engine all make the same call in the same order; this is the one copy of\n * that sequence. `paidChat` is the sequence; `paidJsonChat` adds the JSON\n * answer parse that a structured caller needs.\n */\n\nimport type { ChatClient, ChatResponse } from './analyst/chat-client'\nimport type { CostChannel, CostLedgerHandle, CostReceipt, CustomTokenPricing } from './cost-ledger'\nimport {\n costReceiptFromLlm,\n costReceiptFromLlmError,\n extractJsonPayload,\n type LlmCallRequest,\n maximumChargeForLlmRequest,\n} from './llm-client'\n\nexport interface PaidChatInput {\n /** Caller-owned transport. One `chat()` call. */\n chat: ChatClient\n /** The exact canonical request, including its JSON-mode or schema fields. */\n request: LlmCallRequest\n ledger: CostLedgerHandle\n channel: CostChannel\n phase: string\n actor: string\n tags?: Record<string, string>\n signal?: AbortSignal\n /** Endpoint rates used when the transport reports no billed amount. */\n pricing?: CustomTokenPricing\n}\n\nexport type PaidJsonChatInput = PaidChatInput\n\nexport type PaidChatResult =\n | { succeeded: true; response: ChatResponse; receipt: CostReceipt }\n | { succeeded: false; error: Error; receipt?: CostReceipt }\n\nexport type PaidJsonChatResult<T> =\n | { succeeded: true; value: T; response: ChatResponse; receipt: CostReceipt }\n | { succeeded: false; error: Error; receipt?: CostReceipt }\n\n/** Parse a JSON answer out of a model response. The transport may fence it. */\nfunction parseJsonAnswer<T>(response: ChatResponse, actor: string): T {\n try {\n return JSON.parse(extractJsonPayload(response.content)) as T\n } catch (error) {\n throw new Error(\n `${actor}: model answer was not JSON — ${error instanceof Error ? error.message : String(error)}`,\n )\n }\n}\n\n/** Reserve, execute, and settle one caller-owned chat call. */\nexport async function paidChat(input: PaidChatInput): Promise<PaidChatResult> {\n const paid = await input.ledger.runPaidCall({\n channel: input.channel,\n phase: input.phase,\n actor: input.actor,\n model: input.request.model,\n ...(input.tags && Object.keys(input.tags).length > 0 ? { tags: input.tags } : {}),\n maximumCharge: maximumChargeForLlmRequest(input.request, {\n ...(input.chat.maximumAttempts === undefined\n ? {}\n : { maximumAttempts: input.chat.maximumAttempts }),\n ...(input.pricing ? { customTokenPricing: input.pricing } : {}),\n }),\n ...(input.signal ? { signal: input.signal } : {}),\n execute: (signal, callId) => input.chat.chat(input.request, { signal, idempotencyKey: callId }),\n receipt: (response) => costReceiptFromLlm(response, input.pricing),\n receiptFromError: (error) => costReceiptFromLlmError(error, input.pricing),\n })\n if (!paid.succeeded) {\n return {\n succeeded: false,\n error: paid.error,\n ...(paid.receipt ? { receipt: paid.receipt } : {}),\n }\n }\n return { succeeded: true, response: paid.value, receipt: paid.receipt }\n}\n\nexport async function paidJsonChat<T>(input: PaidJsonChatInput): Promise<PaidJsonChatResult<T>> {\n const paid = await paidChat(input)\n if (!paid.succeeded) return paid\n // The call completed and was billed. A malformed answer is a contract\n // failure AFTER the money was spent, so it keeps the settled receipt instead\n // of reporting the spend as unknown.\n try {\n return {\n succeeded: true,\n value: parseJsonAnswer<T>(paid.response, input.actor),\n response: paid.response,\n receipt: paid.receipt,\n }\n } catch (error) {\n return {\n succeeded: false,\n error: error instanceof Error ? error : new Error(String(error)),\n receipt: paid.receipt,\n }\n }\n}\n"],"mappings":";;;AAqDA,SAAS,gBAAmB,UAAwB,OAAkB;CACpE,IAAI;EACF,OAAO,KAAK,MAAM,mBAAmB,SAAS,OAAO,CAAC;CACxD,SAAS,OAAO;EACd,MAAM,IAAI,MACR,GAAG,MAAM,gCAAgC,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,GAChG;CACF;AACF;;AAGA,eAAsB,SAAS,OAA+C;CAC5E,MAAM,OAAO,MAAM,MAAM,OAAO,YAAY;EAC1C,SAAS,MAAM;EACf,OAAO,MAAM;EACb,OAAO,MAAM;EACb,OAAO,MAAM,QAAQ;EACrB,GAAI,MAAM,QAAQ,OAAO,KAAK,MAAM,IAAI,CAAC,CAAC,SAAS,IAAI,EAAE,MAAM,MAAM,KAAK,IAAI,CAAC;EAC/E,eAAe,2BAA2B,MAAM,SAAS;GACvD,GAAI,MAAM,KAAK,oBAAoB,KAAA,IAC/B,CAAC,IACD,EAAE,iBAAiB,MAAM,KAAK,gBAAgB;GAClD,GAAI,MAAM,UAAU,EAAE,oBAAoB,MAAM,QAAQ,IAAI,CAAC;EAC/D,CAAC;EACD,GAAI,MAAM,SAAS,EAAE,QAAQ,MAAM,OAAO,IAAI,CAAC;EAC/C,UAAU,QAAQ,WAAW,MAAM,KAAK,KAAK,MAAM,SAAS;GAAE;GAAQ,gBAAgB;EAAO,CAAC;EAC9F,UAAU,aAAa,mBAAmB,UAAU,MAAM,OAAO;EACjE,mBAAmB,UAAU,wBAAwB,OAAO,MAAM,OAAO;CAC3E,CAAC;CACD,IAAI,CAAC,KAAK,WACR,OAAO;EACL,WAAW;EACX,OAAO,KAAK;EACZ,GAAI,KAAK,UAAU,EAAE,SAAS,KAAK,QAAQ,IAAI,CAAC;CAClD;CAEF,OAAO;EAAE,WAAW;EAAM,UAAU,KAAK;EAAO,SAAS,KAAK;CAAQ;AACxE;AAEA,eAAsB,aAAgB,OAA0D;CAC9F,MAAM,OAAO,MAAM,SAAS,KAAK;CACjC,IAAI,CAAC,KAAK,WAAW,OAAO;CAI5B,IAAI;EACF,OAAO;GACL,WAAW;GACX,OAAO,gBAAmB,KAAK,UAAU,MAAM,KAAK;GACpD,UAAU,KAAK;GACf,SAAS,KAAK;EAChB;CACF,SAAS,OAAO;EACd,OAAO;GACL,WAAW;GACX,OAAO,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,KAAK,CAAC;GAC/D,SAAS,KAAK;EAChB;CACF;AACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"claim-BXcZw-jo.js","names":[],"sources":["../src/experiment/claim.ts"],"sourcesContent":["import { z } from 'zod'\nimport { ValidationError } from '../errors'\nimport { compareCodeUnits } from '../ledger-core/canonical'\nimport { type EvidenceRecord, readField } from './ast'\n\nconst nonEmpty = z\n .string()\n .min(1)\n .refine((value) => value.trim() === value)\n\n/** The claim's schema, shared by every record that binds a claim. */\nexport const evaluationClaimSchema = z\n .object({\n use: z.enum(['development', 'comparison', 'certification']),\n population: z.object({ id: nonEmpty, description: nonEmpty }).strict(),\n samplingFrame: nonEmpty,\n independentUnit: nonEmpty,\n generalization: z.enum(['fixed-roster', 'new-units']),\n minimumEffect: z.number().finite().positive().optional(),\n })\n .strict()\n\n/** The population and independent observations a measured result can describe. */\nexport type EvaluationClaim = z.infer<typeof evaluationClaimSchema>\n\n/** Validate a claim before binding it to a sealed experiment or final evidence. */\nexport function defineEvaluationClaim(input: EvaluationClaim): EvaluationClaim {\n const parsed = evaluationClaimSchema.safeParse(input)\n if (!parsed.success)\n throw new ValidationError(`invalid evaluation claim: ${parsed.error.message}`)\n return Object.freeze({ ...parsed.data, population: Object.freeze(parsed.data.population) })\n}\n\nexport interface EvaluationUnitSummary {\n observations: number\n independentUnits: number\n units: Array<{ id: string; observations: number }>\n}\n\n/** Repetitions retain their denominator without becoming additional independent units. */\nexport function summarizeEvaluationUnits(\n claim: EvaluationClaim,\n rows: readonly object[],\n): EvaluationUnitSummary {\n const validated = defineEvaluationClaim(claim)\n const counts = new Map<string, number>()\n for (const [index, row] of rows.entries()) {\n if (row === null || typeof row !== 'object' || Array.isArray(row)) {\n throw new ValidationError(`evaluation claim: row ${index} must be an object`)\n }\n const value = readField(row as EvidenceRecord, validated.independentUnit)\n if (typeof value !== 'string' || !value.trim() || value.trim() !== value) {\n throw new ValidationError(\n `evaluation claim: row ${index} needs a nonempty string at '${validated.independentUnit}'`,\n )\n }\n counts.set(value, (counts.get(value) ?? 0) + 1)\n }\n return {\n observations: rows.length,\n independentUnits: counts.size,\n units: [...counts]\n .sort(([left], [right]) => compareCodeUnits(left, right))\n .map(([id, observations]) => ({ id, observations })),\n }\n}\n"],"mappings":";;;;;AAKA,MAAM,WAAW,EACd,OAAO,CAAC,CACR,IAAI,CAAC,CAAC,CACN,QAA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AAM,CAAC,CACf,MAAM,CAAC,OAAO,CAAC,WAAW,iBAAiB,MAAM,KAAK,CAAC,CAAC,CACxD,KAAK,CAAC,IAAI,mBAAmB;GAAE;GAAI;EAAa,EAAE;CACvD;AACF"}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { join } from "node:path";
|
|
2
|
-
import { homedir } from "node:os";
|
|
3
|
-
import { readdir } from "node:fs/promises";
|
|
4
|
-
import { claudeCodeReader, claudeCodeRefForFile, readSessionInput, toChatMessages } from "@tangle-network/harness-sessions";
|
|
5
|
-
//#region src/rollout/readers/claude-jsonl.ts
|
|
6
|
-
/**
|
|
7
|
-
* Claude Code project transcripts (~/.claude/projects/<cwd-slug>/<sessionId>.jsonl) as canonical
|
|
8
|
-
* chat-with-tools messages plus per-session token usage.
|
|
9
|
-
*
|
|
10
|
-
* The transcript is read by @tangle-network/harness-sessions, the one reader of harness sessions
|
|
11
|
-
* shared with Discovery, agent-record, traces and the blog: one model call per API response
|
|
12
|
-
* (`message.id`, its usage counted once), the served model from the response, tool calls with
|
|
13
|
-
* their results. This module only projects that session. Sidechain lines (subagent threads in the
|
|
14
|
-
* main file) are separate invocations and are excluded unless `includeSidechain` asks for a
|
|
15
|
-
* subagent's own transcript.
|
|
16
|
-
*/
|
|
17
|
-
const DEFAULT_CLAUDE_PROJECTS_DIR = join(homedir(), ".claude", "projects");
|
|
18
|
-
/** Claude Code's project-directory slug for a working directory. */
|
|
19
|
-
function claudeProjectSlug(cwd) {
|
|
20
|
-
return cwd.replace(/[^a-zA-Z0-9-]/g, "-");
|
|
21
|
-
}
|
|
22
|
-
/** Transcript files recorded for sessions launched from `cwd`. */
|
|
23
|
-
async function findClaudeTranscripts(cwd, projectsDir = DEFAULT_CLAUDE_PROJECTS_DIR) {
|
|
24
|
-
const dir = join(projectsDir, claudeProjectSlug(cwd));
|
|
25
|
-
return (await readdir(dir).catch(() => [])).filter((n) => n.endsWith(".jsonl")).sort().map((n) => ({
|
|
26
|
-
sessionId: n.replace(/\.jsonl$/, ""),
|
|
27
|
-
path: join(dir, n)
|
|
28
|
-
}));
|
|
29
|
-
}
|
|
30
|
-
const USAGE_FIELDS = [
|
|
31
|
-
["tokensIn", "input"],
|
|
32
|
-
["tokensOut", "output"],
|
|
33
|
-
["cacheRead", "cacheRead"],
|
|
34
|
-
["cacheWrite", "cacheWrite"]
|
|
35
|
-
];
|
|
36
|
-
/**
|
|
37
|
-
* The messages+usage projection of a normalized session. A usage field is null when any answered
|
|
38
|
-
* model call did not report it, so a partial sum is never mistaken for the session's usage.
|
|
39
|
-
*/
|
|
40
|
-
function transcriptFromSession(session) {
|
|
41
|
-
const gaps = session.integrity.gaps.filter((gap) => /is not a JSON record|still being written/u.test(gap));
|
|
42
|
-
const answered = session.modelCalls.filter((call) => call.error === null);
|
|
43
|
-
const usage = {
|
|
44
|
-
tokensIn: null,
|
|
45
|
-
tokensOut: null,
|
|
46
|
-
cacheRead: null,
|
|
47
|
-
cacheWrite: null
|
|
48
|
-
};
|
|
49
|
-
if (answered.length > 0) for (const [target, field] of USAGE_FIELDS) {
|
|
50
|
-
let total = 0;
|
|
51
|
-
for (const call of answered) {
|
|
52
|
-
const value = call.usage?.[field] ?? null;
|
|
53
|
-
if (value === null) {
|
|
54
|
-
total = null;
|
|
55
|
-
gaps.push(`model call ${call.id}: ${field} usage unavailable`);
|
|
56
|
-
break;
|
|
57
|
-
}
|
|
58
|
-
total += value;
|
|
59
|
-
}
|
|
60
|
-
usage[target] = total;
|
|
61
|
-
}
|
|
62
|
-
const model = [...answered].reverse().find((call) => call.servedModel !== null)?.servedModel ?? null;
|
|
63
|
-
return {
|
|
64
|
-
messages: toChatMessages(session),
|
|
65
|
-
usage,
|
|
66
|
-
startedAt: session.startedAt,
|
|
67
|
-
endedAt: session.endedAt,
|
|
68
|
-
model,
|
|
69
|
-
gaps
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
/** Read one transcript file. */
|
|
73
|
-
async function readClaudeTranscript(path, options = {}) {
|
|
74
|
-
return transcriptFromSession(await claudeCodeReader.read(claudeCodeRefForFile(path, options.includeSidechain === true ? "parent" : null)));
|
|
75
|
-
}
|
|
76
|
-
/** Parse retained JSONL text without another file or store; source gaps remain explicit. */
|
|
77
|
-
function parseClaudeTranscript(raw, options = {}) {
|
|
78
|
-
return transcriptFromSession(readSessionInput("claude-code", { text: raw }, {
|
|
79
|
-
parentNativeSessionId: options.includeSidechain === true ? "parent" : null,
|
|
80
|
-
label: "retained transcript"
|
|
81
|
-
}));
|
|
82
|
-
}
|
|
83
|
-
//#endregion
|
|
84
|
-
export { readClaudeTranscript as a, parseClaudeTranscript as i, claudeProjectSlug as n, transcriptFromSession as o, findClaudeTranscripts as r, DEFAULT_CLAUDE_PROJECTS_DIR as t };
|
|
85
|
-
|
|
86
|
-
//# sourceMappingURL=claude-jsonl-dZir12m6.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"claude-jsonl-dZir12m6.js","names":[],"sources":["../src/rollout/readers/claude-jsonl.ts"],"sourcesContent":["/**\n * Claude Code project transcripts (~/.claude/projects/<cwd-slug>/<sessionId>.jsonl) as canonical\n * chat-with-tools messages plus per-session token usage.\n *\n * The transcript is read by @tangle-network/harness-sessions, the one reader of harness sessions\n * shared with Discovery, agent-record, traces and the blog: one model call per API response\n * (`message.id`, its usage counted once), the served model from the response, tool calls with\n * their results. This module only projects that session. Sidechain lines (subagent threads in the\n * main file) are separate invocations and are excluded unless `includeSidechain` asks for a\n * subagent's own transcript.\n */\n\nimport { readdir } from 'node:fs/promises'\nimport { homedir } from 'node:os'\nimport { join } from 'node:path'\nimport {\n claudeCodeReader,\n claudeCodeRefForFile,\n type HarnessSession,\n readSessionInput,\n toChatMessages,\n} from '@tangle-network/harness-sessions'\nimport type { ChatMessage } from '../schema'\n\nexport const DEFAULT_CLAUDE_PROJECTS_DIR = join(homedir(), '.claude', 'projects')\n\n/** Claude Code's project-directory slug for a working directory. */\nexport function claudeProjectSlug(cwd: string): string {\n return cwd.replace(/[^a-zA-Z0-9-]/g, '-')\n}\n\nexport interface ClaudeTranscriptRef {\n sessionId: string\n path: string\n}\n\n/** Transcript files recorded for sessions launched from `cwd`. */\nexport async function findClaudeTranscripts(\n cwd: string,\n projectsDir: string = DEFAULT_CLAUDE_PROJECTS_DIR,\n): Promise<ClaudeTranscriptRef[]> {\n const dir = join(projectsDir, claudeProjectSlug(cwd))\n const names = await readdir(dir).catch(() => [])\n return names\n .filter((n) => n.endsWith('.jsonl'))\n .sort()\n .map((n) => ({ sessionId: n.replace(/\\.jsonl$/, ''), path: join(dir, n) }))\n}\n\nexport interface ClaudeUsageTotals {\n tokensIn: number | null\n tokensOut: number | null\n cacheRead: number | null\n cacheWrite: number | null\n}\n\nexport interface ClaudeTranscript {\n messages: ChatMessage[]\n usage: ClaudeUsageTotals\n /** Timestamp of the first conversation record; null = empty transcript. */\n startedAt: string | null\n endedAt: string | null\n /** The model that answered the last response (never Claude Code's `<synthetic>` error turn). */\n model: string | null\n /** Every parse or usage gap retained beside this semantic projection. */\n gaps: string[]\n}\n\nexport interface ReadClaudeTranscriptOptions {\n /**\n * Read a subagent's own transcript (`<session>/subagents/agent-<id>.jsonl`), whose records are\n * sidechain end to end, instead of skipping sidechain records.\n */\n readonly includeSidechain?: boolean\n}\n\nconst USAGE_FIELDS = [\n ['tokensIn', 'input'],\n ['tokensOut', 'output'],\n ['cacheRead', 'cacheRead'],\n ['cacheWrite', 'cacheWrite'],\n] as const\n\n/**\n * The messages+usage projection of a normalized session. A usage field is null when any answered\n * model call did not report it, so a partial sum is never mistaken for the session's usage.\n */\nexport function transcriptFromSession(session: HarnessSession): ClaudeTranscript {\n const gaps = session.integrity.gaps.filter((gap) =>\n /is not a JSON record|still being written/u.test(gap),\n )\n const answered = session.modelCalls.filter((call) => call.error === null)\n const usage: ClaudeUsageTotals = {\n tokensIn: null,\n tokensOut: null,\n cacheRead: null,\n cacheWrite: null,\n }\n if (answered.length > 0) {\n for (const [target, field] of USAGE_FIELDS) {\n let total: number | null = 0\n for (const call of answered) {\n const value = call.usage?.[field] ?? null\n if (value === null) {\n total = null\n gaps.push(`model call ${call.id}: ${field} usage unavailable`)\n break\n }\n total += value\n }\n usage[target] = total\n }\n }\n const model =\n [...answered].reverse().find((call) => call.servedModel !== null)?.servedModel ?? null\n return {\n messages: toChatMessages(session),\n usage,\n startedAt: session.startedAt,\n endedAt: session.endedAt,\n model,\n gaps,\n }\n}\n\n/** Read one transcript file. */\nexport async function readClaudeTranscript(\n path: string,\n options: ReadClaudeTranscriptOptions = {},\n): Promise<ClaudeTranscript> {\n const session = await claudeCodeReader.read(\n claudeCodeRefForFile(path, options.includeSidechain === true ? 'parent' : null),\n )\n return transcriptFromSession(session)\n}\n\n/** Parse retained JSONL text without another file or store; source gaps remain explicit. */\nexport function parseClaudeTranscript(\n raw: string,\n options: ReadClaudeTranscriptOptions = {},\n): ClaudeTranscript {\n const session = readSessionInput(\n 'claude-code',\n { text: raw },\n {\n parentNativeSessionId: options.includeSidechain === true ? 'parent' : null,\n label: 'retained transcript',\n },\n )\n return transcriptFromSession(session)\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAwBA,MAAa,8BAA8B,KAAK,QAAQ,GAAG,WAAW,UAAU;;AAGhF,SAAgB,kBAAkB,KAAqB;CACrD,OAAO,IAAI,QAAQ,kBAAkB,GAAG;AAC1C;;AAQA,eAAsB,sBACpB,KACA,cAAsB,6BACU;CAChC,MAAM,MAAM,KAAK,aAAa,kBAAkB,GAAG,CAAC;CAEpD,QAAO,MADa,QAAQ,GAAG,CAAC,CAAC,YAAY,CAAC,CAAC,EAAA,CAE5C,QAAQ,MAAM,EAAE,SAAS,QAAQ,CAAC,CAAC,CACnC,KAAK,CAAC,CACN,KAAK,OAAO;EAAE,WAAW,EAAE,QAAQ,YAAY,EAAE;EAAG,MAAM,KAAK,KAAK,CAAC;CAAE,EAAE;AAC9E;AA6BA,MAAM,eAAe;CACnB,CAAC,YAAY,OAAO;CACpB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;EAClE,mBACE,SAAS,2BACT,SAAS,cACR,QAAQ;EACX,cACE,4BACA,OAAO,WAAW,cAClB,qBACA,SAAS,cACR,QAAQ;WACF,QAAQ;WACR,aAAa;;;cAIX,2BAA2B;WAC7B;WACA;EACT,YAAY,aAAa,gBAAgB;;iBAuI3B,mBAAmB,QAAQ,eAAe;;;;;;;;;;iBAqG1C,oBACd,YAAW,QAAQ;EAAkB,MAAM;IAC1C;;;iBAmBa,oBACd,YAAW,QAAQ;EAAkB,MAAM;IAC1C"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cost-ledger-CO7UyEcQ.d.ts","names":[],"sources":["../src/cost-ledger.ts"],"mappings":";;KAIY;;KAGA;EACN;EAAkB;;EAClB;EAAmB;;EACnB;EAAoB;;UAET;EACf;;EAEA;;EAEA;;EAEA;;EAEA;;UAGQ;EACR;EACA,SAAS;EACT;EACA;EACA;EACA;EACA,OAAO;EACP;;UAGe,wBAAwB;EACvC;;UAGe,4BAA4B;EAC3C;;UAGe,oBAAoB,cAAc;EACjD;EACA;EACA;EACA;;EAEA;IACE;IACA;IACA;IACA;;;EAGF;;EAEA;;;EAGA;;UAKe,yBAAyB;EACxC;;EAEA,qBAAqB;EACrB;;EAEA;EACA;EACA;;;UAIe;;EAEf;;EAEA;;EAEA;EACA;;KAGU;EACN;;EAEA,oBAAoB;IAClB,KAAK;EACN;IAAkB;UAER,iBAAiB;EAChC;EACA,SAAS;EACT;EACA;;EAEA;EACA,OAAO;EACP,SAAS;;EAET,gBAAgB;;EAEhB,QAAQ,QAAQ,aAAa,iBAAiB,QAAQ;EACtD,QAAQ,OAAO,IAAI;EACnB,kBAAkB,OAAO,QAAQ;;KAGvB,eAAe;EACrB;EAAiB;EAAgB,OAAO;EAAG,SAAS;;EACpD;EAAkB;EAAiB,OAAO;EAAO,UAAU;;UAEhD;EACf,SAAS;EACT;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;UAGe;EACf;EACA;EACA;EACA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../src/cost-ledger.ts"],"sourcesContent":["import { z } from 'zod'\nimport { ValidationError } from './errors'\nimport { estimateCost, isModelPriced, resolveModelPricing } from './metrics'\n\nexport type CostChannel = 'agent' | 'judge' | 'verifier' | 'analyst' | 'driver' | (string & {})\n\n/** How a USD amount was obtained. */\nexport type CostProvenance =\n | { kind: 'observed'; usd: number }\n | { kind: 'estimated'; usd: number }\n | { kind: 'uncaptured'; usd: null }\n\nexport interface CostUsage {\n inputTokens: number\n /** Includes reasoning tokens when the provider bills them as output. */\n outputTokens: number\n /** Reasoning-token subset of outputTokens, when reported. */\n reasoningTokens?: number\n /** Prompt tokens served from a provider cache. */\n cachedTokens?: number\n /** Prompt tokens written into a provider cache. */\n cacheWriteTokens?: number\n}\n\ninterface CostCallBase {\n callId: string\n channel: CostChannel\n phase: string\n actor: string\n model: string\n maximumCostUsd?: number\n tags?: Record<string, string>\n timestamp: number\n}\n\nexport interface PendingCostCall extends CostCallBase {\n status: 'pending'\n}\n\nexport interface PendingCostCallView extends PendingCostCall {\n state: 'active' | 'late' | 'interrupted'\n}\n\nexport interface CostReceipt extends CostCallBase, CostUsage {\n status: 'settled'\n costUsd: number\n costUnknown: boolean\n usageUnknown?: boolean\n /** Rates used to estimate cost locally. Absent when cost is provider-reported or unknown. */\n pricing?: {\n inputUsdPerThousand: number\n cachedInputUsdPerThousand?: number\n cacheWriteUsdPerThousand?: number\n outputUsdPerThousand: number\n }\n /** Cost reported by the provider, not a local token-price calculation. */\n actualCostUsd?: number\n /** Known non-provider amount supplied by an external executor. */\n estimatedCostUsd?: number\n /** Why the call failed. `'paid-call-failed'` is the ledger's own value for\n * recovery settles; a reconciling caller may record its own reason. */\n error?: string\n}\n\nexport type CostLedgerRecord = PendingCostCall | CostReceipt\n\nexport interface CostReceiptInput extends CostUsage {\n model: string\n /** Caller-supplied rates for a local estimate when the provider does not report billed cost. */\n customTokenPricing?: CustomTokenPricing\n actualCostUsd?: number\n /** A known estimate from an external executor that cannot provide token pricing. */\n estimatedCostUsd?: number\n costUnknown?: boolean\n usageUnknown?: boolean\n}\n\n/** Per-million token rates for a model or endpoint not covered by package pricing. */\nexport interface CustomTokenPricing {\n /** Non-cached input tokens. */\n inputUsdPerMillion: number\n /** Cache-read tokens. Falls back to the normal input rate when omitted. */\n cachedInputUsdPerMillion?: number\n /** Cache-creation or cache-write tokens. Falls back to the normal input rate when omitted. */\n cacheWriteUsdPerMillion?: number\n outputUsdPerMillion: number\n}\n\nexport type MaximumCharge =\n | { externallyEnforcedMaximumUsd: number }\n | ({\n customTokenPricing: CustomTokenPricing\n } & Pick<CostUsage, 'inputTokens' | 'outputTokens' | 'cachedTokens' | 'cacheWriteTokens'>)\n | ({ model: string } & CostUsage)\n\nexport interface RunPaidCallInput<T> {\n callId?: string\n channel: CostChannel\n phase: string\n actor: string\n /** Used before a provider receipt exists and on failures without one. */\n model?: string\n tags?: Record<string, string>\n signal?: AbortSignal\n /** Provider-enforced dollar maximum, or maximum token usage with known pricing. Required when capped. */\n maximumCharge?: MaximumCharge\n /** `callId` can be forwarded as the provider's idempotency key. */\n execute(signal: AbortSignal, callId: string): Promise<T>\n receipt(value: T): CostReceiptInput\n receiptFromError?(error: Error): CostReceiptInput | undefined\n}\n\nexport type PaidCallResult<T> =\n | { succeeded: true; callId: string; value: T; receipt: CostReceipt }\n | { succeeded: false; callId?: string; error: Error; receipt?: CostReceipt }\n\nexport interface ChannelRollup {\n channel: CostChannel\n calls: number\n inputTokens: number\n outputTokens: number\n reasoningTokens?: number\n cachedTokens: number\n cacheWriteTokens?: number\n costUsd: number\n unpricedCalls: number\n unknownUsageCalls: number\n}\n\nexport interface CostLedgerSummary {\n totalCalls: number\n pendingCalls: number\n unresolvedCalls: number\n reservedCostUsd: number\n inputTokens: number\n outputTokens: number\n reasoningTokens?: number\n cachedTokens: number\n cacheWriteTokens?: number\n totalCostUsd: number\n costProvenance: CostProvenance\n byChannel: ChannelRollup[]\n unpricedModels: string[]\n fullyPriced: boolean\n usageComplete: boolean\n accountingComplete: boolean\n incompleteReasons: string[]\n}\n\nexport interface CostLedgerFilter {\n channel?: CostChannel\n phase?: string\n tags?: Record<string, string>\n}\n\nexport interface CostLedgerWaitOptions {\n /** Maximum time to wait for active provider calls. Default 5 seconds. */\n timeoutMs?: number\n /** Wait only for calls matching this attribution filter. */\n filter?: CostLedgerFilter\n}\n\n/** Append-only storage. `append` must atomically reject stale revisions. */\nexport interface CostLedgerPersistence {\n read(): { revision: string; events: string }\n append(expectedRevision: string, event: string): string | undefined\n}\n\nexport interface CostLedgerOptions {\n costCeilingUsd?: number\n persistence?: CostLedgerPersistence\n /** Import already-settled receipts without admitting new paid work. */\n receipts?: readonly CostReceipt[]\n}\n\nexport class CostCeilingReachedError extends ValidationError {\n constructor(\n ceilingUsd: number,\n committedUsd: number,\n requestedUsd: number,\n phase: string,\n actor: string,\n ) {\n super(\n `CostLedger: reserving ${requestedUsd} for '${actor}' during '${phase}' would exceed ceiling ${ceilingUsd} with ${committedUsd} already committed`,\n )\n }\n}\n\nexport class CostAccountingIncompleteError extends ValidationError {}\n\nexport class CostReservationExceededError extends ValidationError {\n constructor(actor: string, actualUsd: number, maximumUsd: number) {\n super(\n `CostLedger: '${actor}' charged ${actualUsd}, exceeding its enforced maximum ${maximumUsd}`,\n )\n }\n}\n\nexport class CostCallConflictError extends ValidationError {\n readonly callId?: string\n readonly receipt?: CostReceipt\n\n constructor(\n message: string,\n options: { callId?: string; receipt?: CostReceipt; cause?: unknown } = {},\n ) {\n super(message, options.cause === undefined ? undefined : { cause: options.cause })\n this.callId = options.callId\n this.receipt = options.receipt ? cloneReceipt(options.receipt) : undefined\n }\n}\n\nexport class CostLedgerPersistenceError extends ValidationError {\n readonly callId?: string\n readonly receipt?: CostReceipt\n\n constructor(cause: unknown, callId?: string, receipt?: CostReceipt) {\n super(\n `CostLedger: failed to persist${callId ? ` call '${callId}'` : ''}: ${toError(cause).message}`,\n { cause },\n )\n this.callId = callId\n this.receipt = receipt ? cloneReceipt(receipt) : undefined\n }\n}\n\nexport class CostReceiptCaptureError extends ValidationError {\n readonly callId: string\n readonly receipt?: CostReceipt\n readonly receiptError: Error\n\n constructor(callId: string, cause: unknown, receiptError: unknown, receipt?: CostReceipt) {\n super(`CostLedger: could not capture the provider receipt for call '${callId}'`, { cause })\n this.callId = callId\n this.receipt = receipt ? cloneReceipt(receipt) : undefined\n this.receiptError = toError(receiptError)\n }\n}\n\ninterface PendingCostCallEvent {\n version: 1\n record: PendingCostCall\n}\n\ninterface SettledCostCallEvent {\n version: 2\n record: CostReceipt\n}\n\ninterface CompletedTasksEvent {\n version: 1\n completedTasks: number\n}\n\ninterface CostLimitEvent {\n version: 1\n costCeilingUsd: number\n}\n\ntype CostCallEvent = PendingCostCallEvent | SettledCostCallEvent\ntype CostLedgerEvent = CostCallEvent | CompletedTasksEvent | CostLimitEvent\n\n/** Run-wide paid-call admission, durable call state, receipts, and summaries. */\nexport class CostLedger {\n private readonly records = new Map<string, CostLedgerRecord>()\n private readonly activeCallIds = new Set<string>()\n private readonly lateCallIds = new Set<string>()\n private readonly idleWaiters = new Set<() => void>()\n private completedTasks = 0\n private revision = 'memory'\n private costLimitPersisted = false\n readonly costCeilingUsd?: number\n private readonly persistence?: CostLedgerPersistence\n\n constructor(input?: number | CostLedgerOptions) {\n const options = typeof input === 'number' ? { costCeilingUsd: input } : (input ?? {})\n this.persistence = options.persistence\n if (options.costCeilingUsd !== undefined) {\n assertNonNegative(options.costCeilingUsd, 'costCeilingUsd')\n }\n\n let persistedCostCeilingUsd: number | undefined\n if (this.persistence) {\n let stored: ReturnType<CostLedgerPersistence['read']>\n try {\n stored = this.persistence.read()\n } catch (cause) {\n throw new CostLedgerPersistenceError(cause)\n }\n assertString(stored.revision, 'persistence revision')\n this.revision = stored.revision\n const restored = parseEvents(stored.events)\n for (const record of restored.records) this.records.set(record.callId, record)\n this.completedTasks = restored.completedTasks\n persistedCostCeilingUsd = restored.costCeilingUsd\n }\n\n if (\n options.costCeilingUsd !== undefined &&\n persistedCostCeilingUsd !== undefined &&\n options.costCeilingUsd !== persistedCostCeilingUsd\n ) {\n throw new ValidationError(\n `CostLedger: requested cost ceiling ${options.costCeilingUsd} does not match persisted ceiling ${persistedCostCeilingUsd}`,\n )\n }\n this.costCeilingUsd = persistedCostCeilingUsd ?? options.costCeilingUsd\n this.costLimitPersisted =\n !this.persistence ||\n this.costCeilingUsd === undefined ||\n persistedCostCeilingUsd !== undefined\n\n if (\n this.costCeilingUsd !== undefined &&\n [...this.records.values()].some(\n (record) => record.status === 'pending' && record.maximumCostUsd === undefined,\n )\n ) {\n throw new ValidationError('CostLedger: capped event log contains an unbounded pending call')\n }\n\n if (options.receipts?.length) {\n const imported = options.receipts.map((receipt, index) =>\n parseImportedReceipt(receipt, `imported receipt ${index + 1}`),\n )\n this.ensureCostLimitPersisted()\n for (const receipt of imported) this.appendRecord(receipt)\n }\n }\n\n async runPaidCall<T>(input: RunPaidCallInput<T>): Promise<PaidCallResult<T>> {\n let callId: string | undefined\n let pending: PendingCostCall | undefined\n try {\n callId = resolveCallId(input.callId)\n validateAttribution(input)\n if (input.signal?.aborted) {\n return { succeeded: false, callId, error: abortError(input.signal) }\n }\n this.ensureCostLimitPersisted(callId)\n\n const maximumCostUsd = this.resolveMaximum(input.maximumCharge)\n const existing = this.records.get(callId)\n if (existing) {\n return {\n succeeded: false,\n callId,\n error: new CostCallConflictError(\n existing.status === 'pending'\n ? `CostLedger: callId '${callId}' is unresolved and must be reconciled before retry`\n : `CostLedger: callId '${callId}' already exists`,\n { callId },\n ),\n }\n }\n\n if (!pending) {\n while (true) {\n if (this.records.has(callId)) {\n return {\n succeeded: false,\n callId,\n error: new CostCallConflictError(`CostLedger: callId '${callId}' already exists`),\n }\n }\n const admission = this.admissionState()\n if (admission.unresolvedCalls > 0) {\n return {\n succeeded: false,\n callId,\n error: new CostAccountingIncompleteError(\n `CostLedger: ${admission.unresolvedCalls} unresolved call(s) must be reconciled before new paid work`,\n ),\n }\n }\n if (this.costCeilingUsd === undefined) break\n if (admission.budgetBreached) {\n return {\n succeeded: false,\n callId,\n error: new CostAccountingIncompleteError(\n `CostLedger: a settled call exceeded its enforced maximum; refusing paid call '${input.actor}' during '${input.phase}'`,\n ),\n }\n }\n // A settled call whose cost the provider left unknown is charged its\n // reserved maximum here, so the ceiling is enforced against a real\n // upper bound and one under-reported response cannot let later calls\n // silently exceed the budget — while still permitting them.\n const { committedCostUsd } = admission\n if (committedCostUsd + maximumCostUsd! > this.costCeilingUsd) {\n return {\n succeeded: false,\n callId,\n error: new CostCeilingReachedError(\n this.costCeilingUsd,\n committedCostUsd,\n maximumCostUsd!,\n input.phase,\n input.actor,\n ),\n }\n }\n if (\n committedCostUsd + admission.reservedCostUsd + maximumCostUsd! <=\n this.costCeilingUsd\n ) {\n break\n }\n await this.waitForReservationRelease(input.signal)\n }\n\n pending = {\n status: 'pending',\n callId,\n channel: input.channel,\n phase: input.phase,\n actor: input.actor,\n model: pendingModel(input),\n ...(maximumCostUsd === undefined ? {} : { maximumCostUsd }),\n ...(input.tags ? { tags: { ...input.tags } } : {}),\n timestamp: Date.now(),\n }\n this.appendRecord(pending)\n this.activeCallIds.add(callId)\n }\n } catch (error) {\n return { succeeded: false, ...(callId ? { callId } : {}), error: toError(error) }\n }\n\n try {\n return await this.execute(input, pending)\n } catch (error) {\n return { succeeded: false, callId: pending.callId, error: toError(error) }\n } finally {\n if (!this.lateCallIds.has(pending.callId)) this.releaseActiveCall(pending.callId)\n }\n }\n\n /** Wait until every call started by this ledger has produced a durable outcome. */\n async waitForIdle(options: CostLedgerWaitOptions = {}): Promise<boolean> {\n const hasActiveMatch = (): boolean =>\n [...this.activeCallIds].some((callId) => {\n const record = this.records.get(callId)\n return record !== undefined && matches(record, options.filter)\n })\n if (!hasActiveMatch()) return true\n const timeoutMs = options.timeoutMs ?? 5_000\n assertTimeout(timeoutMs, 'waitForIdle.timeoutMs')\n return new Promise<boolean>((resolve) => {\n let timer: ReturnType<typeof setTimeout> | undefined\n const finish = (settled: boolean): void => {\n this.idleWaiters.delete(onIdle)\n if (timer !== undefined) clearTimeout(timer)\n resolve(settled)\n }\n const onIdle = (): void => {\n if (!hasActiveMatch()) finish(true)\n }\n this.idleWaiters.add(onIdle)\n timer = setTimeout(() => finish(false), timeoutMs)\n onIdle()\n })\n }\n\n /** Settle a call left pending by a crashed process after reconciling with the provider. */\n reconcile(\n callId: string,\n observed: CostReceiptInput,\n options: { failed?: boolean; error?: string } = {},\n ): CostReceipt {\n const pending = this.records.get(callId)\n if (pending?.status !== 'pending') {\n throw new CostCallConflictError(`CostLedger: no pending call '${callId}'`)\n }\n if (this.activeCallIds.has(callId)) {\n throw new CostCallConflictError(`CostLedger: call '${callId}' is still active`)\n }\n this.ensureCostLimitPersisted(callId)\n return this.commitReceipt(\n pending,\n observed,\n options.failed === true || options.error !== undefined,\n options.error,\n )\n }\n\n list(filter?: CostLedgerFilter): CostReceipt[] {\n return [...this.records.values()]\n .filter((record): record is CostReceipt => record.status === 'settled')\n .filter((receipt) => matches(receipt, filter))\n .map(cloneReceipt)\n }\n\n /** Read pending calls without exposing mutable ledger state. */\n listPending(filter?: CostLedgerFilter): PendingCostCallView[] {\n return [...this.records.values()]\n .filter((record): record is PendingCostCall => record.status === 'pending')\n .filter((record) => matches(record, filter))\n .map((record) => ({\n ...clonePendingCall(record),\n state: this.lateCallIds.has(record.callId)\n ? 'late'\n : this.activeCallIds.has(record.callId)\n ? 'active'\n : 'interrupted',\n }))\n }\n\n summary(filter?: CostLedgerFilter): CostLedgerSummary {\n const records = [...this.records.values()].filter((record) => matches(record, filter))\n const pending = records.filter(\n (record): record is PendingCostCall => record.status === 'pending',\n )\n const receipts = records.filter((record): record is CostReceipt => record.status === 'settled')\n const byChannel = new Map<string, ChannelRollup>()\n const unpriced = new Set<string>()\n const incompleteReasons: string[] = pending.map(\n (record) => `call '${record.callId}' for '${record.actor}' is pending`,\n )\n let inputTokens = 0\n let outputTokens = 0\n let reasoningTokens = 0\n let cachedTokens = 0\n let cacheWriteTokens = 0\n let totalCostUsd = 0\n\n for (const receipt of receipts) {\n inputTokens += receipt.inputTokens\n outputTokens += receipt.outputTokens\n reasoningTokens += receipt.reasoningTokens ?? 0\n cachedTokens += receipt.cachedTokens ?? 0\n cacheWriteTokens += receipt.cacheWriteTokens ?? 0\n totalCostUsd += receipt.costUsd\n if (receipt.costUnknown) {\n unpriced.add(receipt.model)\n incompleteReasons.push(\n receipt.error ?? `cost unknown for '${receipt.actor}' using '${receipt.model}'`,\n )\n }\n if (receipt.usageUnknown) {\n incompleteReasons.push(\n `token usage unknown for '${receipt.actor}' using '${receipt.model}'`,\n )\n }\n if (receipt.maximumCostUsd !== undefined && receipt.costUsd > receipt.maximumCostUsd) {\n incompleteReasons.push(\n `'${receipt.actor}' charged ${receipt.costUsd}, exceeding its enforced maximum ${receipt.maximumCostUsd}`,\n )\n }\n const rollup = byChannel.get(receipt.channel) ?? emptyRollup(receipt.channel)\n rollup.calls += 1\n rollup.inputTokens += receipt.inputTokens\n rollup.outputTokens += receipt.outputTokens\n rollup.reasoningTokens = (rollup.reasoningTokens ?? 0) + (receipt.reasoningTokens ?? 0)\n rollup.cachedTokens += receipt.cachedTokens ?? 0\n rollup.cacheWriteTokens = (rollup.cacheWriteTokens ?? 0) + (receipt.cacheWriteTokens ?? 0)\n rollup.costUsd += receipt.costUsd\n if (receipt.costUnknown) rollup.unpricedCalls += 1\n if (receipt.usageUnknown) rollup.unknownUsageCalls += 1\n byChannel.set(receipt.channel, rollup)\n }\n\n return {\n totalCalls: receipts.length,\n pendingCalls: pending.length,\n unresolvedCalls: pending.filter(\n (record) => !this.activeCallIds.has(record.callId) || this.lateCallIds.has(record.callId),\n ).length,\n reservedCostUsd: pending.reduce((sum, record) => sum + (record.maximumCostUsd ?? 0), 0),\n inputTokens,\n outputTokens,\n reasoningTokens,\n cachedTokens,\n cacheWriteTokens,\n totalCostUsd,\n costProvenance:\n pending.length > 0 || receipts.some((receipt) => receipt.costUnknown)\n ? { kind: 'uncaptured', usd: null }\n : receipts.every((receipt) => receipt.actualCostUsd !== undefined)\n ? { kind: 'observed', usd: totalCostUsd }\n : { kind: 'estimated', usd: totalCostUsd },\n byChannel: [...byChannel.values()].sort((a, b) => a.channel.localeCompare(b.channel)),\n unpricedModels: [...unpriced].sort(),\n fullyPriced: unpriced.size === 0,\n usageComplete: pending.length === 0 && receipts.every((receipt) => !receipt.usageUnknown),\n accountingComplete: incompleteReasons.length === 0,\n incompleteReasons: [...new Set(incompleteReasons)],\n }\n }\n\n markCompleted(count = 1): void {\n if (!Number.isInteger(count) || count < 0) {\n throw new ValidationError(\n `CostLedger.markCompleted: count must be a non-negative integer, got ${count}`,\n )\n }\n if (count === 0) return\n this.ensureCostLimitPersisted()\n this.appendEvent({ version: 1, completedTasks: count })\n this.completedTasks += count\n }\n\n costPerCompletedTask(): number | null {\n return this.completedTasks === 0 ? null : this.summary().totalCostUsd / this.completedTasks\n }\n\n private async execute<T>(\n input: RunPaidCallInput<T>,\n pending: PendingCostCall,\n ): Promise<PaidCallResult<T>> {\n const signal = input.signal ?? new AbortController().signal\n if (signal.aborted) {\n return this.commitOutcome(pending, abortError(signal), {\n model: pending.model,\n inputTokens: 0,\n outputTokens: 0,\n actualCostUsd: 0,\n })\n }\n\n const operation = Promise.resolve().then(() => input.execute(signal, pending.callId))\n const settled = await settle(operation, signal)\n if (settled.kind === 'aborted') {\n this.lateCallIds.add(pending.callId)\n this.captureLateOutcome(input, pending, operation)\n return paidFailure(pending.callId, abortError(signal))\n }\n if (settled.kind === 'error') {\n let observed: CostReceiptInput | undefined\n try {\n observed = input.receiptFromError?.(settled.error)\n } catch (receiptError) {\n return this.captureFailure(pending, settled.error, receiptError)\n }\n return this.commitOutcome(pending, settled.error, observed ?? unknownReceipt(pending.model))\n }\n\n try {\n const receipt = this.commitReceipt(pending, input.receipt(settled.value))\n if (receipt.maximumCostUsd !== undefined && receipt.costUsd > receipt.maximumCostUsd) {\n return paidFailure(\n pending.callId,\n new CostReservationExceededError(pending.actor, receipt.costUsd, receipt.maximumCostUsd),\n receipt,\n )\n }\n return { succeeded: true, callId: pending.callId, value: settled.value, receipt }\n } catch (receiptError) {\n if (\n receiptError instanceof CostLedgerPersistenceError ||\n receiptError instanceof CostCallConflictError\n ) {\n return paidFailure(pending.callId, receiptError)\n }\n return this.captureFailure(pending, receiptError, receiptError)\n }\n }\n\n private captureLateOutcome<T>(\n input: RunPaidCallInput<T>,\n pending: PendingCostCall,\n operation: Promise<T>,\n ): void {\n void operation\n .then(\n (value) => {\n if (this.records.get(pending.callId)?.status !== 'pending') return\n try {\n this.commitReceipt(pending, input.receipt(value))\n } catch {\n // A failed durable settlement leaves the reservation pending and blocks new paid work.\n }\n },\n (cause) => {\n if (this.records.get(pending.callId)?.status !== 'pending') return\n const error = toError(cause)\n try {\n const observed = input.receiptFromError?.(error)\n this.commitReceipt(pending, observed ?? unknownReceipt(pending.model), true)\n } catch (receiptError) {\n if (\n receiptError instanceof CostLedgerPersistenceError ||\n receiptError instanceof CostCallConflictError\n ) {\n return\n }\n this.captureFailure(pending, error, receiptError)\n }\n },\n )\n .finally(() => {\n this.lateCallIds.delete(pending.callId)\n this.releaseActiveCall(pending.callId)\n })\n }\n\n private releaseActiveCall(callId: string): void {\n this.activeCallIds.delete(callId)\n for (const resolve of [...this.idleWaiters]) resolve()\n }\n\n private async waitForReservationRelease(signal?: AbortSignal): Promise<void> {\n if (signal?.aborted) throw abortError(signal)\n await new Promise<void>((resolve, reject) => {\n let finished = false\n const finish = (error?: Error): void => {\n if (finished) return\n finished = true\n this.idleWaiters.delete(onRelease)\n signal?.removeEventListener('abort', onAbort)\n if (error) reject(error)\n else resolve()\n }\n const onRelease = (): void => finish()\n const onAbort = (): void => finish(abortError(signal!))\n this.idleWaiters.add(onRelease)\n signal?.addEventListener('abort', onAbort, { once: true })\n if (this.activeCallIds.size === 0) onRelease()\n })\n }\n\n private commitOutcome<T>(\n pending: PendingCostCall,\n error: Error,\n observed: CostReceiptInput,\n ): PaidCallResult<T> {\n try {\n const receipt = this.commitReceipt(pending, observed, true)\n return paidFailure(pending.callId, error, receipt)\n } catch (receiptError) {\n if (\n receiptError instanceof CostLedgerPersistenceError ||\n receiptError instanceof CostCallConflictError\n ) {\n return paidFailure(pending.callId, receiptError)\n }\n return this.captureFailure(pending, error, receiptError)\n }\n }\n\n private captureFailure<T>(\n pending: PendingCostCall,\n cause: unknown,\n receiptError: unknown,\n ): PaidCallResult<T> {\n try {\n const receipt = this.commitReceipt(pending, unknownReceipt(pending.model), true)\n return paidFailure(\n pending.callId,\n new CostReceiptCaptureError(pending.callId, cause, receiptError, receipt),\n receipt,\n )\n } catch (error) {\n const typed = error instanceof Error ? error : toError(error)\n return paidFailure(pending.callId, typed)\n }\n }\n\n private commitReceipt(\n pending: PendingCostCall,\n observed: CostReceiptInput,\n failed = false,\n error?: string,\n ): CostReceipt {\n const receipt = buildReceipt(pending, observed, failed, error)\n if (this.records.get(pending.callId)?.status !== 'pending') {\n throw new CostCallConflictError(`CostLedger: call '${pending.callId}' is not pending`)\n }\n this.appendRecord(receipt)\n return cloneReceipt(receipt)\n }\n\n private resolveMaximum(maximum: MaximumCharge | undefined): number | undefined {\n if (!maximum) {\n if (this.costCeilingUsd !== undefined) {\n throw new CostAccountingIncompleteError(\n 'CostLedger: capped paid calls require a hard maximumCharge before execution',\n )\n }\n return undefined\n }\n if ('externallyEnforcedMaximumUsd' in maximum) {\n assertNonNegative(\n maximum.externallyEnforcedMaximumUsd,\n 'maximumCharge.externallyEnforcedMaximumUsd',\n )\n return maximum.externallyEnforcedMaximumUsd\n }\n if ('customTokenPricing' in maximum) {\n return costForTokenPricing(maximum.customTokenPricing, maximum)\n }\n const priced = costForUsage(maximum.model, maximum)\n if (priced.costUnknown) {\n if (this.costCeilingUsd !== undefined) {\n throw new CostAccountingIncompleteError(\n `CostLedger: cannot reserve unpriced model '${maximum.model}' in a capped run`,\n )\n }\n return undefined\n }\n return priced.costUsd\n }\n\n /** Compute admission totals in record order without building reporting rollups. */\n private admissionState() {\n let unresolvedCalls = 0\n let reservedCostUsd = 0\n let committedCostUsd = 0\n let budgetBreached = false\n for (const record of this.records.values()) {\n if (record.status === 'pending') {\n if (!this.activeCallIds.has(record.callId) || this.lateCallIds.has(record.callId)) {\n unresolvedCalls += 1\n }\n reservedCostUsd += record.maximumCostUsd ?? 0\n } else {\n if (record.maximumCostUsd !== undefined && record.costUsd > record.maximumCostUsd) {\n budgetBreached = true\n }\n // Unknown settled costs consume their reserved maximum for admission.\n committedCostUsd += record.costUnknown\n ? (record.maximumCostUsd ?? record.costUsd)\n : record.costUsd\n }\n }\n return { unresolvedCalls, reservedCostUsd, committedCostUsd, budgetBreached }\n }\n\n private appendRecord(record: CostLedgerRecord): void {\n const callId = record.callId\n const receipt = record.status === 'settled' ? record : undefined\n validateTransition(this.records, record)\n const event: CostCallEvent =\n record.status === 'settled'\n ? { version: 2, record: cloneReceipt(record) }\n : { version: 1, record: clonePendingCall(record) }\n this.appendEvent(event, callId, receipt)\n this.records.set(callId, cloneRecord(record))\n }\n\n private ensureCostLimitPersisted(callId?: string): void {\n if (this.costLimitPersisted || this.costCeilingUsd === undefined) return\n this.appendEvent({ version: 1, costCeilingUsd: this.costCeilingUsd }, callId)\n this.costLimitPersisted = true\n }\n\n private appendEvent(event: CostLedgerEvent, callId?: string, receipt?: CostReceipt): void {\n try {\n if (this.persistence) {\n const nextRevision = this.persistence.append(this.revision, `${JSON.stringify(event)}\\n`)\n if (nextRevision === undefined) {\n throw new CostCallConflictError(\n `CostLedger: persisted revision changed while writing call '${callId}'`,\n { callId, receipt },\n )\n }\n assertString(nextRevision, 'persistence revision')\n this.revision = nextRevision\n }\n } catch (cause) {\n if (cause instanceof CostCallConflictError) throw cause\n throw new CostLedgerPersistenceError(cause, callId, receipt)\n }\n }\n}\n\n/** Public callback surface for a shared cost ledger.\n *\n * Declaration bundles may expose this type through multiple package subpaths.\n * Keeping callback contracts structural lets those subpaths compose while the\n * concrete {@link CostLedger} retains its private durable state.\n */\nexport type CostLedgerHandle = Pick<\n CostLedger,\n Exclude<keyof CostLedger, 'listPending' | 'waitForIdle'>\n> &\n Partial<Pick<CostLedger, 'listPending' | 'waitForIdle'>>\n\n/** Return the canonical pricing-table key, or null when the model is unpriced. */\nexport function modelPriceKey(model: string): string | null {\n return isModelPriced(model) ? model : null\n}\n\nexport interface CostResult {\n costUsd: number\n costUnknown: boolean\n}\n\nexport function costForUsage(model: string, usage: CostUsage): CostResult {\n assertUsage(usage)\n if (!resolveModelPricing(model)) return { costUsd: 0, costUnknown: true }\n return {\n costUsd: estimateCost(\n usage.inputTokens + (usage.cachedTokens ?? 0) + (usage.cacheWriteTokens ?? 0),\n usage.outputTokens,\n model,\n ),\n costUnknown: false,\n }\n}\n\n/** Price token counts with caller-supplied per-million rates. */\nexport function costForTokenPricing(\n pricing: CustomTokenPricing,\n usage: Pick<CostUsage, 'inputTokens' | 'outputTokens' | 'cachedTokens' | 'cacheWriteTokens'>,\n): number {\n assertTokenCount(usage.inputTokens, 'usage.inputTokens')\n assertTokenCount(usage.outputTokens, 'usage.outputTokens')\n if (usage.cachedTokens !== undefined) {\n assertTokenCount(usage.cachedTokens, 'usage.cachedTokens')\n }\n if (usage.cacheWriteTokens !== undefined) {\n assertTokenCount(usage.cacheWriteTokens, 'usage.cacheWriteTokens')\n }\n assertNonNegative(pricing.inputUsdPerMillion, 'pricing.inputUsdPerMillion')\n if (pricing.cachedInputUsdPerMillion !== undefined) {\n assertNonNegative(pricing.cachedInputUsdPerMillion, 'pricing.cachedInputUsdPerMillion')\n }\n if (pricing.cacheWriteUsdPerMillion !== undefined) {\n assertNonNegative(pricing.cacheWriteUsdPerMillion, 'pricing.cacheWriteUsdPerMillion')\n }\n assertNonNegative(pricing.outputUsdPerMillion, 'pricing.outputUsdPerMillion')\n const cachedInputRate = pricing.cachedInputUsdPerMillion ?? pricing.inputUsdPerMillion\n const cacheWriteRate = pricing.cacheWriteUsdPerMillion ?? pricing.inputUsdPerMillion\n return (\n (usage.inputTokens / 1_000_000) * pricing.inputUsdPerMillion +\n ((usage.cachedTokens ?? 0) / 1_000_000) * cachedInputRate +\n ((usage.cacheWriteTokens ?? 0) / 1_000_000) * cacheWriteRate +\n (usage.outputTokens / 1_000_000) * pricing.outputUsdPerMillion\n )\n}\n\ntype Settled<T> =\n | { kind: 'value'; value: T }\n | { kind: 'error'; error: Error }\n | { kind: 'aborted' }\n\nasync function settle<T>(promise: Promise<T>, signal: AbortSignal): Promise<Settled<T>> {\n return await new Promise((resolve) => {\n let done = false\n const finish = (value: Settled<T>): void => {\n if (done) return\n done = true\n signal.removeEventListener('abort', onAbort)\n resolve(value)\n }\n const onAbort = () => finish({ kind: 'aborted' })\n signal.addEventListener('abort', onAbort, { once: true })\n if (signal.aborted) onAbort()\n promise.then(\n (value) => finish({ kind: 'value', value }),\n (error) => finish({ kind: 'error', error: toError(error) }),\n )\n })\n}\n\nfunction buildReceipt(\n pending: PendingCostCall,\n observed: CostReceiptInput,\n failed = false,\n error?: string,\n): CostReceipt {\n assertUsage(observed)\n assertString(observed.model, 'receipt.model')\n const suppliedAmounts = [\n observed.actualCostUsd,\n observed.estimatedCostUsd,\n observed.customTokenPricing,\n ].filter((value) => value !== undefined)\n if (suppliedAmounts.length > 1) {\n throw new ValidationError(\n 'CostLedger: a receipt can have only one of actualCostUsd, estimatedCostUsd, or customTokenPricing',\n )\n }\n const customPricingSnapshot =\n observed.customTokenPricing === undefined\n ? undefined\n : pricingSnapshot(observed.customTokenPricing)\n const estimated = customPricingSnapshot\n ? {\n costUsd: costFromPricing(observed, customPricingSnapshot),\n costUnknown: false,\n }\n : costForUsage(observed.model, observed)\n const hasActual = observed.actualCostUsd !== undefined\n const hasExternalEstimate = observed.estimatedCostUsd !== undefined\n if (hasActual && observed.costUnknown === true) {\n throw new ValidationError(\n 'CostLedger: a receipt cannot have both actualCostUsd and costUnknown=true',\n )\n }\n if (hasActual) assertNonNegative(observed.actualCostUsd!, 'actualCostUsd')\n if (hasExternalEstimate) assertNonNegative(observed.estimatedCostUsd!, 'estimatedCostUsd')\n if (hasExternalEstimate && observed.costUnknown === true) {\n throw new ValidationError(\n 'CostLedger: a receipt cannot have both estimatedCostUsd and costUnknown=true',\n )\n }\n const usageUnknown = observed.usageUnknown === true\n const costUnknown =\n observed.costUnknown === true ||\n (!hasActual && !hasExternalEstimate && (usageUnknown || estimated.costUnknown))\n const resolvedModelPricing =\n !customPricingSnapshot && !hasActual && !hasExternalEstimate && !costUnknown\n ? resolveModelPricing(observed.model)\n : null\n const receiptPricing =\n !hasActual && !hasExternalEstimate && !costUnknown\n ? (customPricingSnapshot ??\n (resolvedModelPricing\n ? {\n inputUsdPerThousand: resolvedModelPricing.input,\n outputUsdPerThousand: resolvedModelPricing.output,\n }\n : undefined))\n : undefined\n return parseReceipt(\n {\n status: 'settled',\n callId: pending.callId,\n channel: pending.channel,\n phase: pending.phase,\n actor: pending.actor,\n model: observed.model,\n inputTokens: observed.inputTokens,\n outputTokens: observed.outputTokens,\n ...(observed.reasoningTokens === undefined\n ? {}\n : { reasoningTokens: observed.reasoningTokens }),\n ...(observed.cachedTokens === undefined ? {} : { cachedTokens: observed.cachedTokens }),\n ...(observed.cacheWriteTokens === undefined\n ? {}\n : { cacheWriteTokens: observed.cacheWriteTokens }),\n costUsd: costUnknown\n ? 0\n : hasActual\n ? observed.actualCostUsd!\n : hasExternalEstimate\n ? observed.estimatedCostUsd!\n : estimated.costUsd,\n costUnknown,\n usageUnknown,\n ...(receiptPricing ? { pricing: receiptPricing } : {}),\n ...(hasActual ? { actualCostUsd: observed.actualCostUsd } : {}),\n ...(hasExternalEstimate ? { estimatedCostUsd: observed.estimatedCostUsd } : {}),\n ...(pending.maximumCostUsd === undefined ? {} : { maximumCostUsd: pending.maximumCostUsd }),\n ...(failed ? { error: error ?? 'paid-call-failed' } : {}),\n ...(pending.tags ? { tags: { ...pending.tags } } : {}),\n timestamp: pending.timestamp,\n },\n 'provider receipt',\n )\n}\n\nconst NonEmptyString = z.string().refine((value) => value.trim().length > 0, 'must be non-empty')\nconst TokenCount = z.number().int().nonnegative().finite()\nconst NonNegative = z.number().nonnegative().finite()\nconst Tags = z.record(NonEmptyString, z.string())\nconst CostPricingSchema = z.strictObject({\n inputUsdPerThousand: NonNegative,\n cachedInputUsdPerThousand: NonNegative.optional(),\n cacheWriteUsdPerThousand: NonNegative.optional(),\n outputUsdPerThousand: NonNegative,\n})\nconst CostCallBaseShape = {\n callId: NonEmptyString,\n channel: NonEmptyString,\n phase: NonEmptyString,\n actor: NonEmptyString,\n model: NonEmptyString,\n maximumCostUsd: NonNegative.optional(),\n tags: Tags.optional(),\n timestamp: NonNegative,\n}\nconst PendingCostCallSchema = z.strictObject({\n status: z.literal('pending'),\n ...CostCallBaseShape,\n})\nconst CostReceiptBaseShape = {\n status: z.literal('settled'),\n ...CostCallBaseShape,\n inputTokens: TokenCount,\n outputTokens: TokenCount,\n cachedTokens: TokenCount.optional(),\n costUsd: NonNegative,\n costUnknown: z.boolean(),\n usageUnknown: z.boolean().default(false),\n pricing: CostPricingSchema.optional(),\n actualCostUsd: NonNegative.optional(),\n estimatedCostUsd: NonNegative.optional(),\n error: NonEmptyString.optional(),\n}\nconst CostReceiptSchema = z\n .strictObject({\n ...CostReceiptBaseShape,\n reasoningTokens: TokenCount.optional(),\n cacheWriteTokens: TokenCount.optional(),\n })\n .superRefine((receipt, ctx) => validateCostReceipt(receipt, ctx))\n\nfunction validateCostReceipt(\n receipt: CostUsage & {\n costUsd: number\n costUnknown: boolean\n usageUnknown: boolean\n pricing?: NonNullable<CostReceipt['pricing']>\n actualCostUsd?: number\n estimatedCostUsd?: number\n },\n ctx: z.RefinementCtx,\n): void {\n if (receipt.reasoningTokens !== undefined && receipt.reasoningTokens > receipt.outputTokens) {\n ctx.addIssue({ code: 'custom', message: 'reasoningTokens must not exceed outputTokens' })\n }\n\n if (receipt.actualCostUsd !== undefined && receipt.estimatedCostUsd !== undefined) {\n ctx.addIssue({\n code: 'custom',\n message: 'actual and external estimated costs cannot both be present',\n })\n }\n\n if (receipt.actualCostUsd !== undefined) {\n if (receipt.costUnknown || receipt.costUsd !== receipt.actualCostUsd) {\n ctx.addIssue({ code: 'custom', message: 'actual cost must be known and equal costUsd' })\n }\n if (receipt.pricing !== undefined) {\n ctx.addIssue({ code: 'custom', message: 'actual cost must not include estimated pricing' })\n }\n return\n }\n\n if (receipt.estimatedCostUsd !== undefined) {\n if (receipt.costUnknown || receipt.costUsd !== receipt.estimatedCostUsd) {\n ctx.addIssue({ code: 'custom', message: 'external estimate must be known and equal costUsd' })\n }\n if (receipt.pricing !== undefined) {\n ctx.addIssue({ code: 'custom', message: 'external estimate must not include token pricing' })\n }\n return\n }\n\n if (receipt.costUnknown) {\n if (receipt.costUsd !== 0) {\n ctx.addIssue({ code: 'custom', message: 'unknown cost must have costUsd 0' })\n }\n if (receipt.pricing !== undefined) {\n ctx.addIssue({ code: 'custom', message: 'unknown cost must not include estimated pricing' })\n }\n return\n }\n\n if (receipt.usageUnknown) {\n ctx.addIssue({ code: 'custom', message: 'known estimated cost requires known usage' })\n }\n if (!receipt.pricing) {\n ctx.addIssue({ code: 'custom', message: 'known estimated cost requires a pricing snapshot' })\n return\n }\n\n const expected = costFromPricing(receipt, receipt.pricing)\n if (!costAmountsMatch(receipt.costUsd, expected)) {\n ctx.addIssue({\n code: 'custom',\n message: `estimated cost ${receipt.costUsd} does not match pricing snapshot ${expected}`,\n })\n }\n}\n\nfunction costAmountsMatch(left: number, right: number): boolean {\n const scale = Math.max(1, Math.abs(left), Math.abs(right))\n return Math.abs(left - right) <= Number.EPSILON * scale * 8\n}\n\nconst CostLedgerEventSchema = z.union([\n z.strictObject({\n version: z.literal(1),\n record: PendingCostCallSchema,\n }),\n z.strictObject({\n version: z.literal(2),\n record: CostReceiptSchema,\n }),\n z.strictObject({\n version: z.literal(1),\n completedTasks: TokenCount,\n }),\n z.strictObject({\n version: z.literal(1),\n costCeilingUsd: NonNegative,\n }),\n])\n\nfunction parseEvents(serialized: string): {\n records: CostLedgerRecord[]\n completedTasks: number\n costCeilingUsd?: number\n} {\n const records = new Map<string, CostLedgerRecord>()\n let completedTasks = 0\n let costCeilingUsd: number | undefined\n let lineNumber = 0\n try {\n for (const line of completeJournalPrefix(serialized).split('\\n')) {\n if (!line.trim()) continue\n lineNumber += 1\n const event = CostLedgerEventSchema.parse(JSON.parse(line)) as CostLedgerEvent\n if ('record' in event) {\n const record = event.record\n validateTransition(records, record)\n records.set(record.callId, cloneRecord(record))\n } else if ('completedTasks' in event) {\n completedTasks += event.completedTasks\n if (!Number.isSafeInteger(completedTasks)) {\n throw new ValidationError('CostLedger: completed task count exceeds safe integer range')\n }\n } else {\n if (costCeilingUsd !== undefined) {\n throw new ValidationError('CostLedger: duplicate persisted cost ceiling')\n }\n costCeilingUsd = event.costCeilingUsd\n }\n }\n return {\n records: [...records.values()],\n completedTasks,\n ...(costCeilingUsd === undefined ? {} : { costCeilingUsd }),\n }\n } catch (cause) {\n throw new ValidationError(\n `CostLedger: invalid persisted event ${lineNumber || 1}: ${validationMessage(cause)}`,\n { cause },\n )\n }\n}\n\nfunction completeJournalPrefix(serialized: string): string {\n if (!serialized || serialized.endsWith('\\n')) return serialized\n const finalNewline = serialized.lastIndexOf('\\n')\n const tail = serialized.slice(finalNewline + 1)\n try {\n JSON.parse(tail)\n } catch {\n return finalNewline < 0 ? '' : serialized.slice(0, finalNewline + 1)\n }\n throw new ValidationError(\n 'CostLedger: complete final persisted event is missing its newline terminator',\n )\n}\n\nfunction validateTransition(\n records: ReadonlyMap<string, CostLedgerRecord>,\n record: CostLedgerRecord,\n): void {\n const current = records.get(record.callId)\n if (!current) return\n if (record.status === 'pending' || current.status === 'settled') {\n throw new CostCallConflictError(`CostLedger: duplicate callId '${record.callId}'`)\n }\n if (!sameAttribution(current, record)) {\n throw new ValidationError(`CostLedger: receipt attribution changed for call '${record.callId}'`)\n }\n}\n\nfunction sameAttribution(before: CostCallBase, after: CostCallBase): boolean {\n return (\n before.channel === after.channel &&\n before.phase === after.phase &&\n before.actor === after.actor &&\n before.maximumCostUsd === after.maximumCostUsd &&\n before.timestamp === after.timestamp &&\n sameTags(before.tags, after.tags)\n )\n}\n\nfunction sameTags(\n left: Readonly<Record<string, string>> | undefined,\n right: Readonly<Record<string, string>> | undefined,\n): boolean {\n const leftEntries = Object.entries(left ?? {}).sort(([a], [b]) => a.localeCompare(b))\n const rightEntries = Object.entries(right ?? {}).sort(([a], [b]) => a.localeCompare(b))\n return JSON.stringify(leftEntries) === JSON.stringify(rightEntries)\n}\n\nfunction parseReceipt(value: unknown, path: string): CostReceipt {\n try {\n return CostReceiptSchema.parse(value) as CostReceipt\n } catch (cause) {\n throw new ValidationError(`CostLedger: invalid ${path}: ${validationMessage(cause)}`, { cause })\n }\n}\n\nfunction parseImportedReceipt(value: unknown, path: string): CostReceipt {\n if (typeof value !== 'object' || value === null) return parseReceipt(value, path)\n const candidate = { ...value } as Record<string, unknown>\n if (\n candidate.status === 'settled' &&\n candidate.actualCostUsd === undefined &&\n candidate.estimatedCostUsd === undefined &&\n candidate.costUnknown === false &&\n candidate.pricing === undefined &&\n typeof candidate.model === 'string'\n ) {\n const pricing = resolveModelPricing(candidate.model)\n if (pricing) {\n candidate.pricing = {\n inputUsdPerThousand: pricing.input,\n outputUsdPerThousand: pricing.output,\n }\n }\n }\n return parseReceipt(candidate, path)\n}\n\nfunction validateAttribution(\n input: Pick<RunPaidCallInput<unknown>, 'channel' | 'phase' | 'actor' | 'model' | 'tags'>,\n): void {\n assertString(input.channel, 'channel')\n assertString(input.phase, 'phase')\n assertString(input.actor, 'actor')\n if (input.model !== undefined) assertString(input.model, 'model')\n if (input.tags !== undefined) {\n const parsed = Tags.safeParse(input.tags)\n if (!parsed.success)\n throw new ValidationError(`CostLedger: invalid tags: ${parsed.error.message}`)\n }\n}\n\nfunction matches(record: CostCallBase, filter: CostLedgerFilter | undefined): boolean {\n if (!filter) return true\n if (filter.channel !== undefined && record.channel !== filter.channel) return false\n if (filter.phase !== undefined && record.phase !== filter.phase) return false\n return Object.entries(filter.tags ?? {}).every(([key, value]) => record.tags?.[key] === value)\n}\n\nfunction cloneRecord(record: CostLedgerRecord): CostLedgerRecord {\n if (record.status === 'settled') return cloneReceipt(record)\n return clonePendingCall(record)\n}\n\nfunction clonePendingCall(record: PendingCostCall): PendingCostCall {\n const { tags, ...rest } = record\n return { ...rest, ...(tags ? { tags: { ...tags } } : {}) }\n}\n\nfunction cloneReceipt(receipt: CostReceipt): CostReceipt {\n const { pricing, tags, ...rest } = receipt\n return {\n ...rest,\n ...(tags ? { tags: { ...tags } } : {}),\n ...(pricing ? { pricing: { ...pricing } } : {}),\n }\n}\n\nfunction costFromPricing(usage: CostUsage, pricing: NonNullable<CostReceipt['pricing']>): number {\n const cachedInputRate = pricing.cachedInputUsdPerThousand ?? pricing.inputUsdPerThousand\n const cacheWriteRate = pricing.cacheWriteUsdPerThousand ?? pricing.inputUsdPerThousand\n return (\n (usage.inputTokens / 1000) * pricing.inputUsdPerThousand +\n ((usage.cachedTokens ?? 0) / 1000) * cachedInputRate +\n ((usage.cacheWriteTokens ?? 0) / 1000) * cacheWriteRate +\n (usage.outputTokens / 1000) * pricing.outputUsdPerThousand\n )\n}\n\nfunction pricingSnapshot(pricing: CustomTokenPricing): NonNullable<CostReceipt['pricing']> {\n costForTokenPricing(pricing, { inputTokens: 0, outputTokens: 0 })\n return {\n inputUsdPerThousand: pricing.inputUsdPerMillion / 1000,\n ...(pricing.cachedInputUsdPerMillion === undefined\n ? {}\n : { cachedInputUsdPerThousand: pricing.cachedInputUsdPerMillion / 1000 }),\n ...(pricing.cacheWriteUsdPerMillion === undefined\n ? {}\n : { cacheWriteUsdPerThousand: pricing.cacheWriteUsdPerMillion / 1000 }),\n outputUsdPerThousand: pricing.outputUsdPerMillion / 1000,\n }\n}\n\nfunction emptyRollup(channel: CostChannel): ChannelRollup {\n return {\n channel,\n calls: 0,\n inputTokens: 0,\n outputTokens: 0,\n reasoningTokens: 0,\n cachedTokens: 0,\n cacheWriteTokens: 0,\n costUsd: 0,\n unpricedCalls: 0,\n unknownUsageCalls: 0,\n }\n}\n\nfunction pendingModel(input: RunPaidCallInput<unknown>): string {\n if (input.model) return input.model\n if (input.maximumCharge && 'model' in input.maximumCharge) return input.maximumCharge.model\n return 'unknown'\n}\n\nfunction unknownReceipt(model: string): CostReceiptInput {\n return { model, inputTokens: 0, outputTokens: 0, costUnknown: true, usageUnknown: true }\n}\n\nfunction resolveCallId(input: string | undefined): string {\n if (input !== undefined) {\n assertString(input, 'callId')\n return input\n }\n if (typeof globalThis.crypto?.randomUUID !== 'function') {\n throw new ValidationError('CostLedger: crypto.randomUUID is required when callId is omitted')\n }\n return globalThis.crypto.randomUUID()\n}\n\nfunction abortError(signal: AbortSignal): Error {\n const reason = (signal as { reason?: unknown }).reason\n if (reason instanceof Error) return reason\n const error = new Error('CostLedger: paid call aborted')\n error.name = 'AbortError'\n return error\n}\n\nfunction toError(value: unknown): Error {\n return value instanceof Error ? value : new Error(String(value))\n}\n\nfunction paidFailure<T>(callId: string, error: Error, receipt?: CostReceipt): PaidCallResult<T> {\n return {\n succeeded: false,\n callId,\n error,\n ...(receipt ? { receipt: cloneReceipt(receipt) } : {}),\n }\n}\n\nfunction validationMessage(cause: unknown): string {\n return cause instanceof z.ZodError ? z.prettifyError(cause) : toError(cause).message\n}\n\nfunction assertUsage(usage: CostUsage): void {\n assertTokenCount(usage.inputTokens, 'inputTokens')\n assertTokenCount(usage.outputTokens, 'outputTokens')\n if (usage.reasoningTokens !== undefined) {\n assertTokenCount(usage.reasoningTokens, 'reasoningTokens')\n if (usage.reasoningTokens > usage.outputTokens) {\n throw new ValidationError('CostLedger: reasoningTokens must not exceed outputTokens')\n }\n }\n if (usage.cachedTokens !== undefined) assertTokenCount(usage.cachedTokens, 'cachedTokens')\n if (usage.cacheWriteTokens !== undefined) {\n assertTokenCount(usage.cacheWriteTokens, 'cacheWriteTokens')\n }\n}\n\nfunction assertTokenCount(value: unknown, name: string): asserts value is number {\n if (typeof value !== 'number' || !Number.isInteger(value) || value < 0) {\n throw new ValidationError(\n `CostLedger: ${name} must be a non-negative integer, got ${String(value)}`,\n )\n }\n}\n\nfunction assertNonNegative(value: unknown, name: string): asserts value is number {\n if (typeof value !== 'number' || !Number.isFinite(value) || value < 0) {\n throw new ValidationError(\n `CostLedger: ${name} must be a non-negative finite number, got ${String(value)}`,\n )\n }\n}\n\nfunction assertTimeout(value: unknown, name: string): asserts value is number {\n if (\n typeof value !== 'number' ||\n !Number.isSafeInteger(value) ||\n value < 0 ||\n value > 2_147_483_647\n ) {\n throw new ValidationError(\n `CostLedger: ${name} must be a non-negative safe integer no greater than 2147483647, got ${String(value)}`,\n )\n }\n}\n\nfunction assertString(value: unknown, name: string): asserts value is string {\n if (typeof value !== 'string' || value.trim().length === 0) {\n throw new ValidationError(`CostLedger: ${name} must be a non-empty string`)\n }\n}\n"],"mappings":";;;;AA+KA,IAAa,0BAAb,cAA6C,gBAAgB;CAC3D,YACE,YACA,cACA,cACA,OACA,OACA;EACA,MACE,yBAAyB,aAAa,QAAQ,MAAM,YAAY,MAAM,yBAAyB,WAAW,QAAQ,aAAa,mBACjI;CACF;AACF;AAEA,IAAa,gCAAb,cAAmD,gBAAgB,CAAC;AAEpE,IAAa,+BAAb,cAAkD,gBAAgB;CAChE,YAAY,OAAe,WAAmB,YAAoB;EAChE,MACE,gBAAgB,MAAM,YAAY,UAAU,mCAAmC,YACjF;CACF;AACF;AAEA,IAAa,wBAAb,cAA2C,gBAAgB;CACzD;CACA;CAEA,YACE,SACA,UAAuE,CAAC,GACxE;EACA,MAAM,SAAS,QAAQ,UAAU,KAAA,IAAY,KAAA,IAAY,EAAE,OAAO,QAAQ,MAAM,CAAC;EACjF,KAAK,SAAS,QAAQ;EACtB,KAAK,UAAU,QAAQ,UAAU,aAAa,QAAQ,OAAO,IAAI,KAAA;CACnE;AACF;AAEA,IAAa,6BAAb,cAAgD,gBAAgB;CAC9D;CACA;CAEA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AAK,QAAQ,GAClE,MAAM,IAAI,gBACR,eAAe,KAAK,6CAA6C,OAAO,KAAK,GAC/E;AAEJ;AAEA,SAAS,cAAc,OAAgB,MAAuC;CAC5E,IACE,OAAO,UAAU,YACjB,CAAC,OAAO,cAAc,KAAK,KAC3B,QAAQ,KACR,QAAQ,YAER,MAAM,IAAI,gBACR,eAAe,KAAK,uEAAuE,OAAO,KAAK,GACzG;AAEJ;AAEA,SAAS,aAAa,OAAgB,MAAuC;CAC3E,IAAI,OAAO,UAAU,YAAY,MAAM,KAAK,CAAC,CAAC,WAAW,GACvD,MAAM,IAAI,gBAAgB,eAAe,KAAK,4BAA4B;AAE9E"}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { s as TraceStore } from "./store-C4avFjIi.js";
|
|
2
|
-
import { o as TraceEmitter } from "./emitter-HcCmFQl_.js";
|
|
3
|
-
import { n as TrajectoryStep, t as Trajectory } from "./trajectory-Y1fmdlw7.js";
|
|
4
|
-
//#region src/counterfactual.d.ts
|
|
5
|
-
type CounterfactualMutation = {
|
|
6
|
-
kind: 'swap-model';
|
|
7
|
-
at: number;
|
|
8
|
-
newModel: string;
|
|
9
|
-
} | {
|
|
10
|
-
kind: 'swap-tool-result';
|
|
11
|
-
at: number;
|
|
12
|
-
newResult: unknown;
|
|
13
|
-
} | {
|
|
14
|
-
kind: 'truncate-after';
|
|
15
|
-
at: number;
|
|
16
|
-
} | {
|
|
17
|
-
kind: 'inject-system-message';
|
|
18
|
-
at: number;
|
|
19
|
-
content: string;
|
|
20
|
-
} | {
|
|
21
|
-
kind: 'custom';
|
|
22
|
-
at: number;
|
|
23
|
-
describe: string;
|
|
24
|
-
apply: (step: TrajectoryStep) => TrajectoryStep;
|
|
25
|
-
};
|
|
26
|
-
interface CounterfactualContext {
|
|
27
|
-
originalRunId: string;
|
|
28
|
-
originalTrajectory: Trajectory;
|
|
29
|
-
/** Steps up to (but not including) the mutation point — the prefix the
|
|
30
|
-
* replayed agent inherits as its prior conversation/tool history. */
|
|
31
|
-
prefix: TrajectoryStep[];
|
|
32
|
-
mutation: CounterfactualMutation;
|
|
33
|
-
/** Pre-applied mutation on the step at `mutation.at`. Consumers use this
|
|
34
|
-
* as the FIRST step the replayed agent emits (they decide whether to
|
|
35
|
-
* re-emit it or continue from there). */
|
|
36
|
-
mutatedStep: TrajectoryStep;
|
|
37
|
-
}
|
|
38
|
-
interface CounterfactualResult {
|
|
39
|
-
counterfactualRunId: string;
|
|
40
|
-
originalRunId: string;
|
|
41
|
-
mutation: CounterfactualMutation;
|
|
42
|
-
/** Structured delta summary — caller can extend via scoring. */
|
|
43
|
-
delta: {
|
|
44
|
-
originalOutcomeScore: number | null;
|
|
45
|
-
counterfactualOutcomeScore: number | null;
|
|
46
|
-
deltaScore: number | null;
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
interface CounterfactualRunner {
|
|
50
|
-
/**
|
|
51
|
-
* Execute the agent from `ctx.prefix` with the mutation applied.
|
|
52
|
-
* MUST emit spans into the provided emitter so they become part of
|
|
53
|
-
* the counterfactual run. MUST call emitter.endRun() with a verdict.
|
|
54
|
-
*/
|
|
55
|
-
executeFrom: (ctx: CounterfactualContext, emitter: TraceEmitter) => Promise<void>;
|
|
56
|
-
}
|
|
57
|
-
declare function runCounterfactual(store: TraceStore, originalRunId: string, mutation: CounterfactualMutation, runner: CounterfactualRunner): Promise<CounterfactualResult>;
|
|
58
|
-
//#endregion
|
|
59
|
-
export { runCounterfactual as a, CounterfactualRunner as i, CounterfactualMutation as n, CounterfactualResult as r, CounterfactualContext as t };
|
|
60
|
-
//# sourceMappingURL=counterfactual-CPaWN99-.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"counterfactual-CPaWN99-.d.ts","names":[],"sources":["../src/counterfactual.ts"],"mappings":";;;;KAoBY;EACN;EAAoB;EAAY;;EAChC;EAA0B;EAAY;;EACtC;EAAwB;;EACxB;EAA+B;EAAY;;EAE3C;EACA;EACA;EACA,QAAQ,MAAM,mBAAmB;;UAGtB;EACf;EACA,oBAAoB;;;EAGpB,QAAQ;EACR,UAAU;;;;EAIV,aAAa;;UAGE;EACf;EACA;EACA,UAAU;;EAEV;IACE;IACA;IACA;;;UAIa;;;;;;EAMf,cAAc,KAAK,uBAAuB,SAAS,iBAAiB;;iBAGhD,kBACpB,OAAO,YACP,uBACA,UAAU,wBACV,QAAQ,uBACP,QAAQ"}
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import { o as NotFoundError, s as ValidationError } from "./errors-Dngq5h35.js";
|
|
2
|
-
import { t as TraceEmitter } from "./emitter-DbMXUIVP.js";
|
|
3
|
-
import { t as buildTrajectory } from "./trajectory-D_7rLrvE.js";
|
|
4
|
-
//#region src/counterfactual.ts
|
|
5
|
-
/**
|
|
6
|
-
* Counterfactual replay — "what would have happened if we'd changed
|
|
7
|
-
* exactly one thing at turn N?"
|
|
8
|
-
*
|
|
9
|
-
* The framework does NOT drive the agent — it sets up the replay
|
|
10
|
-
* context (prior spans, prior state, mutation spec) and records the
|
|
11
|
-
* resulting divergence. Consumers supply an `executeFrom(ctx)` callback
|
|
12
|
-
* that runs their agent starting from turn N with the mutation applied.
|
|
13
|
-
*
|
|
14
|
-
* Counterfactual runs are recorded as a new Run with `layer='meta'` and
|
|
15
|
-
* `parentRunId = originalRunId`, so downstream diff + correlation
|
|
16
|
-
* pipelines see them natively.
|
|
17
|
-
*/
|
|
18
|
-
async function runCounterfactual(store, originalRunId, mutation, runner) {
|
|
19
|
-
const originalRun = await store.getRun(originalRunId);
|
|
20
|
-
if (!originalRun) throw new NotFoundError(`counterfactual: run ${originalRunId} not found`);
|
|
21
|
-
const trajectory = await buildTrajectory(store, originalRunId);
|
|
22
|
-
if (mutation.at < 0 || mutation.at >= trajectory.steps.length) throw new ValidationError(`counterfactual: mutation.at=${mutation.at} out of range [0, ${trajectory.steps.length})`);
|
|
23
|
-
const targetStep = trajectory.steps[mutation.at];
|
|
24
|
-
const mutatedStep = applyMutation(targetStep, mutation);
|
|
25
|
-
const cfEmitter = new TraceEmitter(store);
|
|
26
|
-
await cfEmitter.startRun({
|
|
27
|
-
scenarioId: originalRun.scenarioId,
|
|
28
|
-
variantId: originalRun.variantId ? `${originalRun.variantId}+cf:${mutation.kind}@${mutation.at}` : `cf:${mutation.kind}@${mutation.at}`,
|
|
29
|
-
projectId: originalRun.projectId,
|
|
30
|
-
parentRunId: originalRunId,
|
|
31
|
-
layer: "meta",
|
|
32
|
-
tags: {
|
|
33
|
-
counterfactual: "true",
|
|
34
|
-
mutationKind: mutation.kind,
|
|
35
|
-
mutationAt: String(mutation.at)
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
await runner.executeFrom({
|
|
39
|
-
originalRunId,
|
|
40
|
-
originalTrajectory: trajectory,
|
|
41
|
-
prefix: trajectory.steps.slice(0, mutation.at),
|
|
42
|
-
mutation,
|
|
43
|
-
mutatedStep
|
|
44
|
-
}, cfEmitter);
|
|
45
|
-
const counterfactual = await store.getRun(cfEmitter.runId);
|
|
46
|
-
const delta = {
|
|
47
|
-
originalOutcomeScore: originalRun.outcome?.score ?? null,
|
|
48
|
-
counterfactualOutcomeScore: counterfactual?.outcome?.score ?? null,
|
|
49
|
-
deltaScore: originalRun.outcome?.score !== void 0 && counterfactual?.outcome?.score !== void 0 ? counterfactual.outcome.score - originalRun.outcome.score : null
|
|
50
|
-
};
|
|
51
|
-
return {
|
|
52
|
-
counterfactualRunId: cfEmitter.runId,
|
|
53
|
-
originalRunId,
|
|
54
|
-
mutation,
|
|
55
|
-
delta
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
function applyMutation(step, mutation) {
|
|
59
|
-
if (mutation.kind === "swap-model" && step.span.kind === "llm") {
|
|
60
|
-
const llm = step.span;
|
|
61
|
-
return {
|
|
62
|
-
...step,
|
|
63
|
-
span: {
|
|
64
|
-
...llm,
|
|
65
|
-
model: mutation.newModel
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
if (mutation.kind === "swap-tool-result" && step.span.kind === "tool") {
|
|
70
|
-
const tool = step.span;
|
|
71
|
-
return {
|
|
72
|
-
...step,
|
|
73
|
-
span: {
|
|
74
|
-
...tool,
|
|
75
|
-
result: mutation.newResult
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
if (mutation.kind === "inject-system-message" && step.span.kind === "llm") {
|
|
80
|
-
const llm = step.span;
|
|
81
|
-
return {
|
|
82
|
-
...step,
|
|
83
|
-
span: {
|
|
84
|
-
...llm,
|
|
85
|
-
messages: [{
|
|
86
|
-
role: "system",
|
|
87
|
-
content: mutation.content
|
|
88
|
-
}, ...llm.messages]
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
if (mutation.kind === "custom") return mutation.apply(step);
|
|
93
|
-
return step;
|
|
94
|
-
}
|
|
95
|
-
//#endregion
|
|
96
|
-
export { runCounterfactual as t };
|
|
97
|
-
|
|
98
|
-
//# sourceMappingURL=counterfactual-DtMWvn7D.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"counterfactual-DtMWvn7D.js","names":[],"sources":["../src/counterfactual.ts"],"sourcesContent":["/**\n * Counterfactual replay — \"what would have happened if we'd changed\n * exactly one thing at turn N?\"\n *\n * The framework does NOT drive the agent — it sets up the replay\n * context (prior spans, prior state, mutation spec) and records the\n * resulting divergence. Consumers supply an `executeFrom(ctx)` callback\n * that runs their agent starting from turn N with the mutation applied.\n *\n * Counterfactual runs are recorded as a new Run with `layer='meta'` and\n * `parentRunId = originalRunId`, so downstream diff + correlation\n * pipelines see them natively.\n */\n\nimport { NotFoundError, ValidationError } from './errors'\nimport { TraceEmitter } from './trace/emitter'\nimport type { LlmSpan, Span, ToolSpan } from './trace/schema'\nimport type { TraceStore } from './trace/store'\nimport { buildTrajectory, type Trajectory, type TrajectoryStep } from './trajectory'\n\nexport type CounterfactualMutation =\n | { kind: 'swap-model'; at: number; newModel: string }\n | { kind: 'swap-tool-result'; at: number; newResult: unknown }\n | { kind: 'truncate-after'; at: number }\n | { kind: 'inject-system-message'; at: number; content: string }\n | {\n kind: 'custom'\n at: number\n describe: string\n apply: (step: TrajectoryStep) => TrajectoryStep\n }\n\nexport interface CounterfactualContext {\n originalRunId: string\n originalTrajectory: Trajectory\n /** Steps up to (but not including) the mutation point — the prefix the\n * replayed agent inherits as its prior conversation/tool history. */\n prefix: TrajectoryStep[]\n mutation: CounterfactualMutation\n /** Pre-applied mutation on the step at `mutation.at`. Consumers use this\n * as the FIRST step the replayed agent emits (they decide whether to\n * re-emit it or continue from there). */\n mutatedStep: TrajectoryStep\n}\n\nexport interface CounterfactualResult {\n counterfactualRunId: string\n originalRunId: string\n mutation: CounterfactualMutation\n /** Structured delta summary — caller can extend via scoring. */\n delta: {\n originalOutcomeScore: number | null\n counterfactualOutcomeScore: number | null\n deltaScore: number | null\n }\n}\n\nexport interface CounterfactualRunner {\n /**\n * Execute the agent from `ctx.prefix` with the mutation applied.\n * MUST emit spans into the provided emitter so they become part of\n * the counterfactual run. MUST call emitter.endRun() with a verdict.\n */\n executeFrom: (ctx: CounterfactualContext, emitter: TraceEmitter) => Promise<void>\n}\n\nexport async function runCounterfactual(\n store: TraceStore,\n originalRunId: string,\n mutation: CounterfactualMutation,\n runner: CounterfactualRunner,\n): Promise<CounterfactualResult> {\n const originalRun = await store.getRun(originalRunId)\n if (!originalRun) throw new NotFoundError(`counterfactual: run ${originalRunId} not found`)\n const trajectory = await buildTrajectory(store, originalRunId)\n if (mutation.at < 0 || mutation.at >= trajectory.steps.length) {\n throw new ValidationError(\n `counterfactual: mutation.at=${mutation.at} out of range [0, ${trajectory.steps.length})`,\n )\n }\n const targetStep = trajectory.steps[mutation.at]!\n const mutatedStep = applyMutation(targetStep, mutation)\n\n const cfEmitter = new TraceEmitter(store)\n await cfEmitter.startRun({\n scenarioId: originalRun.scenarioId,\n variantId: originalRun.variantId\n ? `${originalRun.variantId}+cf:${mutation.kind}@${mutation.at}`\n : `cf:${mutation.kind}@${mutation.at}`,\n projectId: originalRun.projectId,\n parentRunId: originalRunId,\n layer: 'meta',\n tags: { counterfactual: 'true', mutationKind: mutation.kind, mutationAt: String(mutation.at) },\n })\n\n await runner.executeFrom(\n {\n originalRunId,\n originalTrajectory: trajectory,\n prefix: trajectory.steps.slice(0, mutation.at),\n mutation,\n mutatedStep,\n },\n cfEmitter,\n )\n\n const counterfactual = await store.getRun(cfEmitter.runId)\n const delta = {\n originalOutcomeScore: originalRun.outcome?.score ?? null,\n counterfactualOutcomeScore: counterfactual?.outcome?.score ?? null,\n deltaScore:\n originalRun.outcome?.score !== undefined && counterfactual?.outcome?.score !== undefined\n ? counterfactual.outcome.score - originalRun.outcome.score\n : null,\n }\n return { counterfactualRunId: cfEmitter.runId, originalRunId, mutation, delta }\n}\n\nfunction applyMutation(step: TrajectoryStep, mutation: CounterfactualMutation): TrajectoryStep {\n if (mutation.kind === 'swap-model' && step.span.kind === 'llm') {\n const llm = step.span as LlmSpan\n return { ...step, span: { ...llm, model: mutation.newModel } }\n }\n if (mutation.kind === 'swap-tool-result' && step.span.kind === 'tool') {\n const tool = step.span as ToolSpan\n return { ...step, span: { ...tool, result: mutation.newResult } }\n }\n if (mutation.kind === 'inject-system-message' && step.span.kind === 'llm') {\n const llm = step.span as LlmSpan\n return {\n ...step,\n span: {\n ...llm,\n messages: [{ role: 'system', content: mutation.content }, ...llm.messages],\n },\n }\n }\n if (mutation.kind === 'custom') return mutation.apply(step)\n // swap-tool-result on non-tool span / swap-model on non-llm / truncate-after: no step-level change.\n return step\n}\n\n// Re-export Span type for consumer ergonomics.\nexport type { Span }\n"],"mappings":";;;;;;;;;;;;;;;;;AAkEA,eAAsB,kBACpB,OACA,eACA,UACA,QAC+B;CAC/B,MAAM,cAAc,MAAM,MAAM,OAAO,aAAa;CACpD,IAAI,CAAC,aAAa,MAAM,IAAI,cAAc,uBAAuB,cAAc,WAAW;CAC1F,MAAM,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K,KAAK,SAAS,QAAQ;EACrE,MAAM,OAAO,KAAK;EAClB,OAAO;GAAE,GAAG;GAAM,MAAM;IAAE,GAAG;IAAM,QAAQ,SAAS;GAAU;EAAE;CAClE;CACA,IAAI,SAAS,SAAS,2BAA2B,KAAK,KAAK,SAAS,OAAO;EACzE,MAAM,MAAM,KAAK;EACjB,OAAO;GACL,GAAG;GACH,MAAM;IACJ,GAAG;IACH,UAAU,CAAC;KAAE,MAAM;KAAU,SAAS,SAAS;IAAQ,GAAG,GAAG,IAAI,QAAQ;GAC3E;EACF;CACF;CACA,IAAI,SAAS,SAAS,UAAU,OAAO,SAAS,MAAM,IAAI;CAE1D,OAAO;AACT"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"default-registry-BrWh62zf.d.ts","names":[],"sources":["../src/trace-analyst/behavioral-metrics.ts","../src/analyst/behavioral-analyst.ts","../src/analyst/kind-factory.ts","../src/analyst/default-registry.ts"],"mappings":";;;;;;KAoBY;UAMK;EACf,MAAM;EACN;;EAEA;;EAEA,UAAU;;UAGK;;EAEf;EACA;;EAEA,gBAAgB;;EAEhB;EACA;EACA,eAAe;EACf;EACA;;EAEA;EACA;EACA,SAAS;;UAGM;EACf;EACA;EACA,sBAAsB;EACtB,uBAAuB;;;;UC1BR;;EAEf;;EAEA;;;;;;iBA+Dc,yBACd,SAAS,mBACT;EAAQ;EAAoB;IAC3B;;iBAkCa,kBACd,UAAS,2BACR,oBAAoB;;;;UCrHN;EACf;EACA;EACA;EACA;;EAEA,sBAAsB,SAAS;;EAE/B;;EAEA,WAAW;;EAEX,kBACE,OAAO,oBACP,SAAS,wCACe;EAC1B,SAAS,QAAQ;EACjB,eAAe,KAAK,mBAAmB,SAAS,mBAAmB;EACnE;EACA;;UAGe;EACf,QAAQ;;EAER;EACA;;;iBAIoB,gBAAgB;EACpC,YAAY;EACZ,QAAQ;EACR,OAAO;EACP,SAAS;EACT;IACE,QAAQ;;iBAgHI,mBACd,YAAY,wBACZ,SAAS,4BACR,oBAAoB;iBA2RP,oBAAoB,OAAO;;;UChc1B;;;;;;EAMf,SAAS;EACT,uBAAuB;;EAEvB;EACA,aAAa;EACb,WAAW;;iBAGG,4BACd,UAAS,gCACR"}
|