@tangle-network/agent-eval 0.129.0 → 0.130.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 +21 -0
- package/README.md +2 -0
- package/dist/active-curriculum-C4mk67HP.js +214 -0
- package/dist/active-curriculum-C4mk67HP.js.map +1 -0
- package/dist/adversarial-smnADNFS.d.ts +21 -0
- package/dist/adversarial-smnADNFS.d.ts.map +1 -0
- package/dist/analyst/index.d.ts +81 -2872
- package/dist/analyst/index.d.ts.map +1 -0
- package/dist/analyst/index.js +319 -360
- package/dist/analyst/index.js.map +1 -1
- package/dist/analyst-BkTS3C58.d.ts +89 -0
- package/dist/analyst-BkTS3C58.d.ts.map +1 -0
- package/dist/analyst-LsnNpSkm.js +152 -0
- package/dist/analyst-LsnNpSkm.js.map +1 -0
- package/dist/analyze-runs-C1CavBMk.js +1067 -0
- package/dist/analyze-runs-C1CavBMk.js.map +1 -0
- package/dist/analyze-runs-FsgYCinh.d.ts +72 -0
- package/dist/analyze-runs-FsgYCinh.d.ts.map +1 -0
- package/dist/attribute-vocabulary-DLJ6303h.d.ts +54 -0
- package/dist/attribute-vocabulary-DLJ6303h.d.ts.map +1 -0
- package/dist/authenticity/index.d.ts +81 -79
- package/dist/authenticity/index.d.ts.map +1 -0
- package/dist/authenticity/index.js +209 -193
- package/dist/authenticity/index.js.map +1 -1
- package/dist/baseline-HsBvw_dk.js +550 -0
- package/dist/baseline-HsBvw_dk.js.map +1 -0
- package/dist/baseline-hG3K85h4.d.ts +125 -0
- package/dist/baseline-hG3K85h4.d.ts.map +1 -0
- package/dist/belief-state/index.d.ts +448 -1188
- package/dist/belief-state/index.d.ts.map +1 -0
- package/dist/belief-state/index.js +1617 -1709
- package/dist/belief-state/index.js.map +1 -1
- package/dist/benchmarks/index.d.ts +2 -891
- package/dist/benchmarks/index.js +2 -60
- package/dist/benchmarks-BJgDGkAD.js +754 -0
- package/dist/benchmarks-BJgDGkAD.js.map +1 -0
- package/dist/builder-eval/index.d.ts +150 -662
- package/dist/builder-eval/index.d.ts.map +1 -0
- package/dist/builder-eval/index.js +356 -345
- package/dist/builder-eval/index.js.map +1 -1
- package/dist/calibration-CNWWA6K8.js +94 -0
- package/dist/calibration-CNWWA6K8.js.map +1 -0
- package/dist/campaign/index.d.ts +5 -6381
- package/dist/campaign/index.js +3 -213
- package/dist/campaign-aKJt6emI.js +3886 -0
- package/dist/campaign-aKJt6emI.js.map +1 -0
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +164 -175
- package/dist/cli.js.map +1 -1
- package/dist/client-C97NMzqi.d.ts +581 -0
- package/dist/client-C97NMzqi.d.ts.map +1 -0
- package/dist/client-CYzbdJOZ.js +637 -0
- package/dist/client-CYzbdJOZ.js.map +1 -0
- package/dist/code-agent-session-BjkMTQ7H.js +1390 -0
- package/dist/code-agent-session-BjkMTQ7H.js.map +1 -0
- package/dist/code-agent-session-DqqgOJaz.d.ts +143 -0
- package/dist/code-agent-session-DqqgOJaz.d.ts.map +1 -0
- package/dist/concurrency-DIxRZF_J.js +85 -0
- package/dist/concurrency-DIxRZF_J.js.map +1 -0
- package/dist/contract/index.d.ts +645 -5565
- package/dist/contract/index.d.ts.map +1 -0
- package/dist/contract/index.js +1730 -1938
- package/dist/contract/index.js.map +1 -1
- package/dist/control.d.ts +3 -1030
- package/dist/control.js +2 -33
- package/dist/cost-ledger-DIgQUFZZ.js +801 -0
- package/dist/cost-ledger-DIgQUFZZ.js.map +1 -0
- package/dist/cost-ledger-Dye6jCgg.d.ts +236 -0
- package/dist/cost-ledger-Dye6jCgg.d.ts.map +1 -0
- package/dist/dataset-BvtnC8Dc.d.ts +115 -0
- package/dist/dataset-BvtnC8Dc.d.ts.map +1 -0
- package/dist/default-registry-C-vFCSEc.js +2579 -0
- package/dist/default-registry-C-vFCSEc.js.map +1 -0
- package/dist/default-registry-CNPo-Vsb.d.ts +540 -0
- package/dist/default-registry-CNPo-Vsb.d.ts.map +1 -0
- package/dist/emitter-CPBAhxum.js +266 -0
- package/dist/emitter-CPBAhxum.js.map +1 -0
- package/dist/emitter-DGQGoLyj.d.ts +113 -0
- package/dist/emitter-DGQGoLyj.d.ts.map +1 -0
- package/dist/errors-8YnH8WlF.js +64 -0
- package/dist/errors-8YnH8WlF.js.map +1 -0
- package/dist/errors-CEk209JS.d.ts +76 -0
- package/dist/errors-CEk209JS.d.ts.map +1 -0
- package/dist/eval-campaign-DEm6c8ru.js +349 -0
- package/dist/eval-campaign-DEm6c8ru.js.map +1 -0
- package/dist/execution-tracks-CpgFPpS5.js +93 -0
- package/dist/execution-tracks-CpgFPpS5.js.map +1 -0
- package/dist/exporters-q9iL-2Jf.js +148 -0
- package/dist/exporters-q9iL-2Jf.js.map +1 -0
- package/dist/extract-usage-BrQ8mCLX.js +155 -0
- package/dist/extract-usage-BrQ8mCLX.js.map +1 -0
- package/dist/failure-cluster-CqcvCcdR.d.ts +59 -0
- package/dist/failure-cluster-CqcvCcdR.d.ts.map +1 -0
- package/dist/feedback-trajectory-CVaeREXV.d.ts +340 -0
- package/dist/feedback-trajectory-CVaeREXV.d.ts.map +1 -0
- package/dist/fuzz.d.ts +320 -646
- package/dist/fuzz.d.ts.map +1 -0
- package/dist/fuzz.js +670 -618
- package/dist/fuzz.js.map +1 -1
- package/dist/hf-dataset-DBJXXoY1.js +763 -0
- package/dist/hf-dataset-DBJXXoY1.js.map +1 -0
- package/dist/hosted/index.d.ts +11 -831
- package/dist/hosted/index.d.ts.map +1 -0
- package/dist/hosted/index.js +2 -37
- package/dist/index-2JJSA6-r2.d.ts +926 -0
- package/dist/index-2JJSA6-r2.d.ts.map +1 -0
- package/dist/index-6N0aYmpW.d.ts +217 -0
- package/dist/index-6N0aYmpW.d.ts.map +1 -0
- package/dist/index-BAvgST_9.d.ts +131 -0
- package/dist/index-BAvgST_9.d.ts.map +1 -0
- package/dist/index-BvnJuTGD.d.ts +68 -0
- package/dist/index-BvnJuTGD.d.ts.map +1 -0
- package/dist/index-C61Wi7yg.d.ts +547 -0
- package/dist/index-C61Wi7yg.d.ts.map +1 -0
- package/dist/index-CD_WZ_Xr.d.ts +2250 -0
- package/dist/index-CD_WZ_Xr.d.ts.map +1 -0
- package/dist/index-DSC51roc.d.ts +102 -0
- package/dist/index-DSC51roc.d.ts.map +1 -0
- package/dist/index-Em67JBjs.d.ts +335 -0
- package/dist/index-Em67JBjs.d.ts.map +1 -0
- package/dist/index.d.ts +3755 -15555
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11182 -11216
- package/dist/index.js.map +1 -1
- package/dist/integrity-BzRbCHzi.js +424 -0
- package/dist/integrity-BzRbCHzi.js.map +1 -0
- package/dist/integrity-rmVhXWA7.d.ts +61 -0
- package/dist/integrity-rmVhXWA7.d.ts.map +1 -0
- package/dist/judge-calibration-DFtEMlde.d.ts +146 -0
- package/dist/judge-calibration-DFtEMlde.d.ts.map +1 -0
- package/dist/ledger-core/index.d.ts +2 -0
- package/dist/ledger-core/index.js +2 -0
- package/dist/ledger-core-DtZz1RG0.js +388 -0
- package/dist/ledger-core-DtZz1RG0.js.map +1 -0
- package/dist/llm-client--GR4JbZE.js +687 -0
- package/dist/llm-client--GR4JbZE.js.map +1 -0
- package/dist/llm-client-B_nIBlYo.d.ts +290 -0
- package/dist/llm-client-B_nIBlYo.d.ts.map +1 -0
- package/dist/matrix/index.d.ts +3 -155
- package/dist/matrix/index.js +2 -8
- package/dist/matrix-BzQnu2S6.js +270 -0
- package/dist/matrix-BzQnu2S6.js.map +1 -0
- package/dist/meta-eval/index.d.ts +4 -1027
- package/dist/meta-eval/index.js +393 -390
- package/dist/meta-eval/index.js.map +1 -1
- package/dist/metrics-C9YY1OcL.js +239 -0
- package/dist/metrics-C9YY1OcL.js.map +1 -0
- package/dist/mint-yN2M2eh0.js +201 -0
- package/dist/mint-yN2M2eh0.js.map +1 -0
- package/dist/multi-layer-verifier-BHY1gWAc.d.ts +138 -0
- package/dist/multi-layer-verifier-BHY1gWAc.d.ts.map +1 -0
- package/dist/multishot/index.d.ts +273 -480
- package/dist/multishot/index.d.ts.map +1 -0
- package/dist/multishot/index.js +595 -548
- package/dist/multishot/index.js.map +1 -1
- package/dist/off-policy-DvgzvtIx.js +220 -0
- package/dist/off-policy-DvgzvtIx.js.map +1 -0
- package/dist/off-policy-mskQw8Mb.d.ts +153 -0
- package/dist/off-policy-mskQw8Mb.d.ts.map +1 -0
- package/dist/openapi.json +1 -1
- package/dist/opencode-sqlite-BGrHeDu3.js +318 -0
- package/dist/opencode-sqlite-BGrHeDu3.js.map +1 -0
- package/dist/outcome-store-BYHIuO0e.d.ts +65 -0
- package/dist/outcome-store-BYHIuO0e.d.ts.map +1 -0
- package/dist/outcome-store-ChBKlTd_.js +75 -0
- package/dist/outcome-store-ChBKlTd_.js.map +1 -0
- package/dist/paired-arms-D9D0wXj2.js +260 -0
- package/dist/paired-arms-D9D0wXj2.js.map +1 -0
- package/dist/pipelines/index.d.ts +95 -532
- package/dist/pipelines/index.d.ts.map +1 -0
- package/dist/pipelines/index.js +497 -478
- package/dist/pipelines/index.js.map +1 -1
- package/dist/pre-registration-DakwTRXk.js +96 -0
- package/dist/pre-registration-DakwTRXk.js.map +1 -0
- package/dist/propose-review-control-LhIWGzHl.js +1458 -0
- package/dist/propose-review-control-LhIWGzHl.js.map +1 -0
- package/dist/query-CJ_DX8vl.d.ts +28 -0
- package/dist/query-CJ_DX8vl.d.ts.map +1 -0
- package/dist/query-Di7eEQ79.js +83 -0
- package/dist/query-Di7eEQ79.js.map +1 -0
- package/dist/raw-provider-sink-BQd7mzyT.js +201 -0
- package/dist/raw-provider-sink-BQd7mzyT.js.map +1 -0
- package/dist/raw-provider-sink-BU29Sh8h.d.ts +134 -0
- package/dist/raw-provider-sink-BU29Sh8h.d.ts.map +1 -0
- package/dist/redact-7Aq1ukl-.js +107 -0
- package/dist/redact-7Aq1ukl-.js.map +1 -0
- package/dist/release-report-Cz9NKH39.js +603 -0
- package/dist/release-report-Cz9NKH39.js.map +1 -0
- package/dist/release-report-mvB2G4_J.d.ts +244 -0
- package/dist/release-report-mvB2G4_J.d.ts.map +1 -0
- package/dist/replay-GnyotH0J.js +1741 -0
- package/dist/replay-GnyotH0J.js.map +1 -0
- package/dist/replay-OoidtG1E.d.ts +749 -0
- package/dist/replay-OoidtG1E.d.ts.map +1 -0
- package/dist/reporting.d.ts +6 -1312
- package/dist/reporting.js +6 -51
- package/dist/researcher-CwTdwXG1.d.ts +314 -0
- package/dist/researcher-CwTdwXG1.d.ts.map +1 -0
- package/dist/reward-hacking-eAnOsynk.d.ts +224 -0
- package/dist/reward-hacking-eAnOsynk.d.ts.map +1 -0
- package/dist/reward-hacking-qipEpKvY.js +596 -0
- package/dist/reward-hacking-qipEpKvY.js.map +1 -0
- package/dist/reward-nw2xZGZG.js +137 -0
- package/dist/reward-nw2xZGZG.js.map +1 -0
- package/dist/rl.d.ts +760 -4010
- package/dist/rl.d.ts.map +1 -0
- package/dist/rl.js +2325 -1958
- package/dist/rl.js.map +1 -1
- package/dist/rolldown-runtime-8H4AJuhK.js +14 -0
- package/dist/rollout/index.d.ts +3 -2087
- package/dist/rollout/index.js +8 -168
- package/dist/rollout-BOYjemfR.js +624 -0
- package/dist/rollout-BOYjemfR.js.map +1 -0
- package/dist/rubric-predictive-validity-B3xmbmS1.js +141 -0
- package/dist/rubric-predictive-validity-B3xmbmS1.js.map +1 -0
- package/dist/rubric-predictive-validity-Ku_clp_1.d.ts +74 -0
- package/dist/rubric-predictive-validity-Ku_clp_1.d.ts.map +1 -0
- package/dist/run-evidence-ClRX_8A9.d.ts +225 -0
- package/dist/run-evidence-ClRX_8A9.d.ts.map +1 -0
- package/dist/run-record-BuoE80Dq.js +467 -0
- package/dist/{chunk-56TAVBOK.js.map → run-record-BuoE80Dq.js.map} +1 -1
- package/dist/run-record-CnZu_gjl.d.ts +357 -0
- package/dist/run-record-CnZu_gjl.d.ts.map +1 -0
- package/dist/run-score-iEEAWiBY.js +41 -0
- package/dist/run-score-iEEAWiBY.js.map +1 -0
- package/dist/runtime-trajectory-1gyaTOoC.js +93 -0
- package/dist/runtime-trajectory-1gyaTOoC.js.map +1 -0
- package/dist/runtime-trajectory-BvSZcCHD.d.ts +50 -0
- package/dist/runtime-trajectory-BvSZcCHD.d.ts.map +1 -0
- package/dist/schema-BtVldJ3T.d.ts +206 -0
- package/dist/schema-BtVldJ3T.d.ts.map +1 -0
- package/dist/schema-C6DW4ZHR.js +821 -0
- package/dist/schema-C6DW4ZHR.js.map +1 -0
- package/dist/schema-CRhEY1SO.js +69 -0
- package/dist/schema-CRhEY1SO.js.map +1 -0
- package/dist/schema-Cef2cFmb.d.ts +408 -0
- package/dist/schema-Cef2cFmb.d.ts.map +1 -0
- package/dist/semantic-concept-judge-B6cWNJ2K.js +725 -0
- package/dist/semantic-concept-judge-B6cWNJ2K.js.map +1 -0
- package/dist/sequential-Br0mAPHA.js +148 -0
- package/dist/sequential-Br0mAPHA.js.map +1 -0
- package/dist/sequential-CYwq6Ff_.d.ts +141 -0
- package/dist/sequential-CYwq6Ff_.d.ts.map +1 -0
- package/dist/series-convergence-CjO2QdRW.js +43 -0
- package/dist/series-convergence-CjO2QdRW.js.map +1 -0
- package/dist/series-convergence-ofsqPWhs.d.ts +35 -0
- package/dist/series-convergence-ofsqPWhs.d.ts.map +1 -0
- package/dist/server-m5D9cvnG.js +1040 -0
- package/dist/server-m5D9cvnG.js.map +1 -0
- package/dist/skill-usage-C_pXm7lP.d.ts +534 -0
- package/dist/skill-usage-C_pXm7lP.d.ts.map +1 -0
- package/dist/skillopt-optimization-method-CUmHkGbI.js +7718 -0
- package/dist/skillopt-optimization-method-CUmHkGbI.js.map +1 -0
- package/dist/skillopt-optimization-method-CWKVTnks.d.ts +1740 -0
- package/dist/skillopt-optimization-method-CWKVTnks.d.ts.map +1 -0
- package/dist/statistics-Cmj6nynr.d.ts +514 -0
- package/dist/statistics-Cmj6nynr.d.ts.map +1 -0
- package/dist/statistics-CnnxdpOg.js +1437 -0
- package/dist/statistics-CnnxdpOg.js.map +1 -0
- package/dist/store-CT9YIIve.d.ts +117 -0
- package/dist/store-CT9YIIve.d.ts.map +1 -0
- package/dist/store-CxJry_cs.d.ts +229 -0
- package/dist/store-CxJry_cs.d.ts.map +1 -0
- package/dist/storyboard/index.d.ts +84 -203
- package/dist/storyboard/index.d.ts.map +1 -0
- package/dist/storyboard/index.js +609 -542
- package/dist/storyboard/index.js.map +1 -1
- package/dist/summary-report-BNs5nmXI.js +862 -0
- package/dist/summary-report-BNs5nmXI.js.map +1 -0
- package/dist/summary-report-Cj9gdw4i.d.ts +407 -0
- package/dist/summary-report-Cj9gdw4i.d.ts.map +1 -0
- package/dist/supervisor-run/index.d.ts +2 -959
- package/dist/supervisor-run/index.js +2 -65
- package/dist/supervisor-run-_lnTLM3z.js +1679 -0
- package/dist/supervisor-run-_lnTLM3z.js.map +1 -0
- package/dist/task-failure-attributes-CQZlB3et.js +311 -0
- package/dist/task-failure-attributes-CQZlB3et.js.map +1 -0
- package/dist/test-graded-scenario-BsqWLmPt.js +318 -0
- package/dist/test-graded-scenario-BsqWLmPt.js.map +1 -0
- package/dist/test-graded-scenario-D1TaI2va.d.ts +141 -0
- package/dist/test-graded-scenario-D1TaI2va.d.ts.map +1 -0
- package/dist/tools-BmuN627J.js +1085 -0
- package/dist/tools-BmuN627J.js.map +1 -0
- package/dist/trace-attributes.d.ts +2 -52
- package/dist/trace-attributes.js +131 -61
- package/dist/trace-attributes.js.map +1 -1
- package/dist/traces.d.ts +12 -2365
- package/dist/traces.js +12 -252
- package/dist/trajectory-D_7rLrvE.js +56 -0
- package/dist/trajectory-D_7rLrvE.js.map +1 -0
- package/dist/types-DGsxbAEd.d.ts +387 -0
- package/dist/types-DGsxbAEd.d.ts.map +1 -0
- package/dist/types-k9tZGKUg.d.ts +640 -0
- package/dist/types-k9tZGKUg.d.ts.map +1 -0
- package/dist/verdict-Dps8_okt.d.ts +37 -0
- package/dist/verdict-Dps8_okt.d.ts.map +1 -0
- package/dist/wire/index.d.ts +702 -1173
- package/dist/wire/index.d.ts.map +1 -0
- package/dist/wire/index.js +2 -81
- package/docs/campaign-proposers.md +1 -0
- package/package.json +17 -9
- package/dist/benchmarks/index.js.map +0 -1
- package/dist/campaign/index.js.map +0 -1
- package/dist/chunk-2QU3YOPR.js +0 -7374
- package/dist/chunk-2QU3YOPR.js.map +0 -1
- package/dist/chunk-3OCR4R5I.js +0 -728
- package/dist/chunk-3OCR4R5I.js.map +0 -1
- package/dist/chunk-3RF76KTD.js +0 -84
- package/dist/chunk-3RF76KTD.js.map +0 -1
- package/dist/chunk-56TAVBOK.js +0 -698
- package/dist/chunk-5DTSBUL2.js +0 -159
- package/dist/chunk-5DTSBUL2.js.map +0 -1
- package/dist/chunk-7FO3TNPI.js +0 -232
- package/dist/chunk-7FO3TNPI.js.map +0 -1
- package/dist/chunk-7ZZMD7UK.js +0 -386
- package/dist/chunk-7ZZMD7UK.js.map +0 -1
- package/dist/chunk-BOD4O7OF.js +0 -40
- package/dist/chunk-BOD4O7OF.js.map +0 -1
- package/dist/chunk-BSO5JDQH.js +0 -2335
- package/dist/chunk-BSO5JDQH.js.map +0 -1
- package/dist/chunk-C6LXANRU.js +0 -1550
- package/dist/chunk-C6LXANRU.js.map +0 -1
- package/dist/chunk-DODXQREJ.js +0 -752
- package/dist/chunk-DODXQREJ.js.map +0 -1
- package/dist/chunk-DRYIUNWY.js +0 -622
- package/dist/chunk-DRYIUNWY.js.map +0 -1
- package/dist/chunk-E7QXT7SX.js +0 -183
- package/dist/chunk-E7QXT7SX.js.map +0 -1
- package/dist/chunk-EG66UGL4.js +0 -341
- package/dist/chunk-EG66UGL4.js.map +0 -1
- package/dist/chunk-FXTVJPYD.js +0 -576
- package/dist/chunk-FXTVJPYD.js.map +0 -1
- package/dist/chunk-G7MGMCZD.js +0 -153
- package/dist/chunk-G7MGMCZD.js.map +0 -1
- package/dist/chunk-GGE4NNQT.js +0 -65
- package/dist/chunk-GGE4NNQT.js.map +0 -1
- package/dist/chunk-H23X7XKK.js +0 -181
- package/dist/chunk-H23X7XKK.js.map +0 -1
- package/dist/chunk-HHWE3POT.js +0 -94
- package/dist/chunk-HHWE3POT.js.map +0 -1
- package/dist/chunk-HPWUNB47.js +0 -289
- package/dist/chunk-HPWUNB47.js.map +0 -1
- package/dist/chunk-IYCLP2N2.js +0 -766
- package/dist/chunk-IYCLP2N2.js.map +0 -1
- package/dist/chunk-JHCHEVET.js +0 -274
- package/dist/chunk-JHCHEVET.js.map +0 -1
- package/dist/chunk-JQSF5DQT.js +0 -701
- package/dist/chunk-JQSF5DQT.js.map +0 -1
- package/dist/chunk-K4DBDHLK.js +0 -158
- package/dist/chunk-K4DBDHLK.js.map +0 -1
- package/dist/chunk-K6N6XJJX.js +0 -306
- package/dist/chunk-K6N6XJJX.js.map +0 -1
- package/dist/chunk-M4YBQKIJ.js +0 -1040
- package/dist/chunk-M4YBQKIJ.js.map +0 -1
- package/dist/chunk-MA6HLL3S.js +0 -65
- package/dist/chunk-MA6HLL3S.js.map +0 -1
- package/dist/chunk-MAZ26DC7.js +0 -99
- package/dist/chunk-MAZ26DC7.js.map +0 -1
- package/dist/chunk-NPCTHQIO.js +0 -91
- package/dist/chunk-NPCTHQIO.js.map +0 -1
- package/dist/chunk-NY44NC4A.js +0 -1056
- package/dist/chunk-NY44NC4A.js.map +0 -1
- package/dist/chunk-OIUOT4QD.js +0 -44
- package/dist/chunk-OIUOT4QD.js.map +0 -1
- package/dist/chunk-ONWEPEDO.js +0 -57
- package/dist/chunk-ONWEPEDO.js.map +0 -1
- package/dist/chunk-OWN5NPMC.js +0 -152
- package/dist/chunk-OWN5NPMC.js.map +0 -1
- package/dist/chunk-P6FYH6K4.js +0 -1161
- package/dist/chunk-P6FYH6K4.js.map +0 -1
- package/dist/chunk-PC4UYEBM.js +0 -166
- package/dist/chunk-PC4UYEBM.js.map +0 -1
- package/dist/chunk-PC5DOSM7.js +0 -579
- package/dist/chunk-PC5DOSM7.js.map +0 -1
- package/dist/chunk-PXE2VKMX.js +0 -140
- package/dist/chunk-PXE2VKMX.js.map +0 -1
- package/dist/chunk-PZ5AY32C.js +0 -10
- package/dist/chunk-PZ5AY32C.js.map +0 -1
- package/dist/chunk-QB6BDBP2.js +0 -4464
- package/dist/chunk-QB6BDBP2.js.map +0 -1
- package/dist/chunk-RXHCETDZ.js +0 -536
- package/dist/chunk-RXHCETDZ.js.map +0 -1
- package/dist/chunk-RZTMDUO7.js +0 -49
- package/dist/chunk-RZTMDUO7.js.map +0 -1
- package/dist/chunk-SFLLL76A.js +0 -669
- package/dist/chunk-SFLLL76A.js.map +0 -1
- package/dist/chunk-SZLVEKMJ.js +0 -1446
- package/dist/chunk-SZLVEKMJ.js.map +0 -1
- package/dist/chunk-T4SQEITX.js +0 -95
- package/dist/chunk-T4SQEITX.js.map +0 -1
- package/dist/chunk-T6RLYGAD.js +0 -158
- package/dist/chunk-T6RLYGAD.js.map +0 -1
- package/dist/chunk-TJVT4QFF.js +0 -911
- package/dist/chunk-TJVT4QFF.js.map +0 -1
- package/dist/chunk-TQ7LNKZ3.js +0 -136
- package/dist/chunk-TQ7LNKZ3.js.map +0 -1
- package/dist/chunk-U4L7JRPZ.js +0 -1706
- package/dist/chunk-U4L7JRPZ.js.map +0 -1
- package/dist/chunk-U4PHLT2N.js +0 -419
- package/dist/chunk-U4PHLT2N.js.map +0 -1
- package/dist/chunk-VCZ5FQYW.js +0 -928
- package/dist/chunk-VCZ5FQYW.js.map +0 -1
- package/dist/chunk-VI2UW6B6.js +0 -162
- package/dist/chunk-VI2UW6B6.js.map +0 -1
- package/dist/chunk-VQMK5FMP.js +0 -247
- package/dist/chunk-VQMK5FMP.js.map +0 -1
- package/dist/chunk-WGXIEX7P.js +0 -116
- package/dist/chunk-WGXIEX7P.js.map +0 -1
- package/dist/chunk-WVATSFCP.js +0 -1553
- package/dist/chunk-WVATSFCP.js.map +0 -1
- package/dist/chunk-X4YIBDER.js +0 -1662
- package/dist/chunk-X4YIBDER.js.map +0 -1
- package/dist/chunk-YQN4ICPP.js +0 -355
- package/dist/chunk-YQN4ICPP.js.map +0 -1
- package/dist/chunk-ZET2UAYW.js +0 -89
- package/dist/chunk-ZET2UAYW.js.map +0 -1
- package/dist/chunk-ZHTZ4EYI.js +0 -1212
- package/dist/chunk-ZHTZ4EYI.js.map +0 -1
- package/dist/control.js.map +0 -1
- package/dist/hosted/index.js.map +0 -1
- package/dist/matrix/index.js.map +0 -1
- package/dist/reporting.js.map +0 -1
- package/dist/rollout/index.js.map +0 -1
- package/dist/run-campaign-OJJ7CZF4.js +0 -18
- package/dist/run-campaign-OJJ7CZF4.js.map +0 -1
- package/dist/supervisor-run/index.js.map +0 -1
- package/dist/traces.js.map +0 -1
- package/dist/wire/index.js.map +0 -1
|
@@ -0,0 +1,687 @@
|
|
|
1
|
+
import { n as CaptureIntegrityError, t as AgentEvalError } from "./errors-8YnH8WlF.js";
|
|
2
|
+
import { c as costForTokenPricing } from "./cost-ledger-DIgQUFZZ.js";
|
|
3
|
+
import { a as providerFromBaseUrl, i as defaultProviderRedactor } from "./raw-provider-sink-BQd7mzyT.js";
|
|
4
|
+
//#region src/llm-client.ts
|
|
5
|
+
/**
|
|
6
|
+
* LLM client with graceful degrade.
|
|
7
|
+
*
|
|
8
|
+
* OpenAI-compatible `/v1/chat/completions` client with:
|
|
9
|
+
* - Exponential-backoff retry on 429 + 5xx gateway errors (502/503/504).
|
|
10
|
+
* - Retry on transient network errors (fetch failed, AbortError, ECONNRESET).
|
|
11
|
+
* - One retry at temperature 1 when a model explicitly requires it.
|
|
12
|
+
* - Graceful json_schema → json_object degrade on 400 with schema-reject body.
|
|
13
|
+
* - Fenced-JSON stripping (```json ... ```) for models that wrap structured output.
|
|
14
|
+
* - Configurable base URL + api key / bearer, works with LiteLLM proxies, OpenAI
|
|
15
|
+
* directly, cli-bridge subscriptions, and any router that speaks the spec.
|
|
16
|
+
*
|
|
17
|
+
* Usage:
|
|
18
|
+
* const { value, result } = await callLlmJson<MyType>(
|
|
19
|
+
* { model: 'gpt-4o', messages: [...], jsonSchema: { name: 'x', schema: {...} } },
|
|
20
|
+
* { baseUrl: 'https://router.tangle.tools/v1', apiKey: process.env.KEY },
|
|
21
|
+
* )
|
|
22
|
+
*
|
|
23
|
+
* `createChatClient` wraps this implementation for provider-neutral package
|
|
24
|
+
* entry points. Direct callers can use `callLlm` or `callLlmJson`.
|
|
25
|
+
*/
|
|
26
|
+
/** Conservative priced bound for the exact text request sent to a provider.
|
|
27
|
+
* Returns undefined when output or multimodal input is not bounded, causing a
|
|
28
|
+
* capped CostLedger to reject the call before execution. Pass
|
|
29
|
+
* `customTokenPricing` when package pricing does not cover the model or endpoint. */
|
|
30
|
+
function maximumChargeForLlmRequest(request, options = {}) {
|
|
31
|
+
if (request.maxTokens === void 0) return void 0;
|
|
32
|
+
if (!Number.isInteger(request.maxTokens) || request.maxTokens <= 0) throw new RangeError(`maximumChargeForLlmRequest: maxTokens must be a positive integer`);
|
|
33
|
+
if (request.messages.some((message) => Array.isArray(message.content) && message.content.some((part) => part.type === "image_url"))) return;
|
|
34
|
+
const attempts = resolveMaximumAttempts(options.maximumAttempts);
|
|
35
|
+
const forceJsonObject = options.jsonSchemaTransport === "json-object";
|
|
36
|
+
const requestBytes = new TextEncoder().encode(JSON.stringify(buildBody(request, forceJsonObject, options.thinking))).byteLength;
|
|
37
|
+
const batches = request.jsonSchema && !forceJsonObject ? 2 : 1;
|
|
38
|
+
const usage = {
|
|
39
|
+
inputTokens: requestBytes * attempts * batches,
|
|
40
|
+
outputTokens: request.maxTokens * attempts * batches
|
|
41
|
+
};
|
|
42
|
+
return options.customTokenPricing ? {
|
|
43
|
+
customTokenPricing: options.customTokenPricing,
|
|
44
|
+
...usage
|
|
45
|
+
} : {
|
|
46
|
+
model: request.model,
|
|
47
|
+
...usage
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/** Convert a provider result into the canonical paid-call receipt input. */
|
|
51
|
+
function costReceiptFromLlm(result, customTokenPricing) {
|
|
52
|
+
const cachedTokens = result.usage.cachedPromptTokens ?? 0;
|
|
53
|
+
const inputTokens = Math.max(0, result.usage.promptTokens - cachedTokens);
|
|
54
|
+
const configuredCostUsd = result.costUsd === null && customTokenPricing && result.usage.captured !== false ? costForTokenPricing(customTokenPricing, {
|
|
55
|
+
inputTokens,
|
|
56
|
+
...cachedTokens > 0 ? { cachedTokens } : {},
|
|
57
|
+
outputTokens: result.usage.completionTokens
|
|
58
|
+
}) : void 0;
|
|
59
|
+
return {
|
|
60
|
+
model: result.model,
|
|
61
|
+
inputTokens,
|
|
62
|
+
outputTokens: result.usage.completionTokens,
|
|
63
|
+
reasoningTokens: result.usage.reasoningTokens,
|
|
64
|
+
cachedTokens: cachedTokens > 0 ? cachedTokens : void 0,
|
|
65
|
+
actualCostUsd: result.costUsd ?? configuredCostUsd,
|
|
66
|
+
usageUnknown: result.usage.captured === false
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/** Structured-response failures retain their completed provider receipt. */
|
|
70
|
+
function costReceiptFromLlmError(error, customTokenPricing) {
|
|
71
|
+
return error instanceof LlmResponseError ? costReceiptFromLlm(error.result, customTokenPricing) : void 0;
|
|
72
|
+
}
|
|
73
|
+
var LlmCallError = class extends AgentEvalError {
|
|
74
|
+
status;
|
|
75
|
+
body;
|
|
76
|
+
model;
|
|
77
|
+
constructor(message, status, body, model) {
|
|
78
|
+
super("judge", message);
|
|
79
|
+
this.status = status;
|
|
80
|
+
this.body = body;
|
|
81
|
+
this.model = model;
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
/** A provider response completed and incurred measurable usage, but its content
|
|
85
|
+
* could not satisfy the caller's response contract. The response envelope is
|
|
86
|
+
* retained so accounting can commit the receipt before the error propagates. */
|
|
87
|
+
var LlmResponseError = class extends AgentEvalError {
|
|
88
|
+
result;
|
|
89
|
+
constructor(message, result, options) {
|
|
90
|
+
super("judge", message, options);
|
|
91
|
+
this.result = result;
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
const DEFAULT_BASE_URL = "https://router.tangle.tools/v1";
|
|
95
|
+
const DEFAULT_TIMEOUT_MS = Number(process.env.TANGLE_LLM_TIMEOUT_MS) || 3e5;
|
|
96
|
+
const DEFAULT_MAXIMUM_ATTEMPTS = process.env.TANGLE_LLM_MAXIMUM_ATTEMPTS === void 0 ? 3 : Number(process.env.TANGLE_LLM_MAXIMUM_ATTEMPTS);
|
|
97
|
+
function resolveMaximumAttempts(configured) {
|
|
98
|
+
const attempts = configured ?? DEFAULT_MAXIMUM_ATTEMPTS;
|
|
99
|
+
if (!Number.isInteger(attempts) || attempts <= 0) throw new RangeError("LLM maximum attempts must be a positive integer");
|
|
100
|
+
return attempts;
|
|
101
|
+
}
|
|
102
|
+
function providerTokenCount(value) {
|
|
103
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0 ? value : void 0;
|
|
104
|
+
}
|
|
105
|
+
const RETRYABLE_STATUS = /* @__PURE__ */ new Set([
|
|
106
|
+
429,
|
|
107
|
+
502,
|
|
108
|
+
503,
|
|
109
|
+
504
|
|
110
|
+
]);
|
|
111
|
+
/**
|
|
112
|
+
* Transient transport/network error signatures, matched against an error's
|
|
113
|
+
* name, message, and `code`. Covers fetch/undici network failures, aborts
|
|
114
|
+
* and timeouts, and — critically — HTTP/2 transport faults a keep-alive
|
|
115
|
+
* connection raises mid-response: `terminated`, `NGHTTP2_INTERNAL_ERROR`,
|
|
116
|
+
* `UND_ERR_*`, `other side closed`. Those last ones carry no clean HTTP
|
|
117
|
+
* status; unrecognised, they escape the retry loop and surface as an
|
|
118
|
+
* uncaught rejection.
|
|
119
|
+
*/
|
|
120
|
+
const TRANSIENT_ERROR_PATTERNS = [
|
|
121
|
+
/AbortError/i,
|
|
122
|
+
/TimeoutError/i,
|
|
123
|
+
/this operation was aborted/i,
|
|
124
|
+
/fetch failed/i,
|
|
125
|
+
/ECONNRESET/i,
|
|
126
|
+
/ETIMEDOUT/i,
|
|
127
|
+
/EAI_AGAIN/i,
|
|
128
|
+
/socket hang up/i,
|
|
129
|
+
/stream.*ended.*unexpectedly/i,
|
|
130
|
+
/terminated/i,
|
|
131
|
+
/other side closed/i,
|
|
132
|
+
/NGHTTP2/i,
|
|
133
|
+
/UND_ERR/i
|
|
134
|
+
];
|
|
135
|
+
/**
|
|
136
|
+
* True when an error is a transient transport/network fault worth retrying,
|
|
137
|
+
* as opposed to a deterministic failure (4xx schema reject, JSON parse) that
|
|
138
|
+
* a retry cannot fix. Inspects `LlmCallError.status`, then the error's
|
|
139
|
+
* name/message/code, then recurses into `error.cause` — undici nests the
|
|
140
|
+
* real socket fault one or more levels under `.cause`.
|
|
141
|
+
*
|
|
142
|
+
* This is the retry classifier for the package: `callLlm` and
|
|
143
|
+
* `withJudgeRetry` both route through it, so connection failures are treated
|
|
144
|
+
* consistently across transports.
|
|
145
|
+
*/
|
|
146
|
+
function isTransientLlmError(err) {
|
|
147
|
+
return classifyTransient(err, 0);
|
|
148
|
+
}
|
|
149
|
+
function classifyTransient(err, depth) {
|
|
150
|
+
if (err instanceof LlmCallError) return RETRYABLE_STATUS.has(err.status);
|
|
151
|
+
if (!(err instanceof Error)) return false;
|
|
152
|
+
const status = err.status;
|
|
153
|
+
if (typeof status === "number" && RETRYABLE_STATUS.has(status)) return true;
|
|
154
|
+
const code = err.code;
|
|
155
|
+
const haystack = `${err.name}\n${err.message}\n${typeof code === "string" ? code : ""}`;
|
|
156
|
+
if (TRANSIENT_ERROR_PATTERNS.some((p) => p.test(haystack))) return true;
|
|
157
|
+
const cause = err.cause;
|
|
158
|
+
if (depth < 4 && cause instanceof Error && cause !== err) return classifyTransient(cause, depth + 1);
|
|
159
|
+
return false;
|
|
160
|
+
}
|
|
161
|
+
function parseRetryAfter(headers) {
|
|
162
|
+
const h = headers.get("retry-after");
|
|
163
|
+
if (!h) return null;
|
|
164
|
+
const asNumber = Number(h);
|
|
165
|
+
if (Number.isFinite(asNumber) && asNumber > 0) return asNumber * 1e3;
|
|
166
|
+
const asDate = Date.parse(h);
|
|
167
|
+
if (Number.isFinite(asDate)) return Math.max(0, asDate - Date.now());
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
170
|
+
/** Exponential backoff: 500ms, 1s, 2s, 4s, ... capped at 16s. Attempt is 0-indexed. */
|
|
171
|
+
function backoffMs(attempt) {
|
|
172
|
+
return Math.min(500 * 2 ** attempt, 16e3);
|
|
173
|
+
}
|
|
174
|
+
function buildHeaders(opts) {
|
|
175
|
+
const headers = {
|
|
176
|
+
"Content-Type": "application/json",
|
|
177
|
+
Accept: "application/json"
|
|
178
|
+
};
|
|
179
|
+
if (opts.authHeader) headers[opts.authHeader.name] = opts.authHeader.value;
|
|
180
|
+
else if (opts.bearer || opts.apiKey) headers.Authorization = `Bearer ${opts.bearer ?? opts.apiKey}`;
|
|
181
|
+
if (opts.idempotencyKey) headers["Idempotency-Key"] = opts.idempotencyKey;
|
|
182
|
+
return headers;
|
|
183
|
+
}
|
|
184
|
+
function isSchemaRejection(status, body) {
|
|
185
|
+
if (status !== 400) return false;
|
|
186
|
+
const lower = body.toLowerCase();
|
|
187
|
+
return lower.includes("response_format") || lower.includes("json_schema") || lower.includes("is unavailable") || lower.includes("not supported");
|
|
188
|
+
}
|
|
189
|
+
function isTemperatureOneRejection(status, body) {
|
|
190
|
+
if (status !== 400 || !/temperature/i.test(body)) return false;
|
|
191
|
+
return /temperature[^.\n]{0,120}\b(?:only|must|should|required|requires?)\b[^.\n]{0,40}\b1(?:\.0+)?\b/i.test(body) || /\bonly\s+1(?:\.0+)?\s+is\s+allowed\b[^.\n]{0,120}\btemperature\b/i.test(body);
|
|
192
|
+
}
|
|
193
|
+
function buildBody(req, forceJsonObject, defaultThinking) {
|
|
194
|
+
const body = {
|
|
195
|
+
model: req.model,
|
|
196
|
+
messages: req.messages,
|
|
197
|
+
temperature: req.temperature ?? 0
|
|
198
|
+
};
|
|
199
|
+
if (req.maxTokens != null) if (usesMaxCompletionTokens(req.model)) body.max_completion_tokens = req.maxTokens;
|
|
200
|
+
else body.max_tokens = req.maxTokens;
|
|
201
|
+
const thinking = req.thinking ?? defaultThinking;
|
|
202
|
+
if (thinking !== void 0) body.thinking = { type: thinking };
|
|
203
|
+
if (req.jsonSchema && !forceJsonObject) body.response_format = {
|
|
204
|
+
type: "json_schema",
|
|
205
|
+
json_schema: {
|
|
206
|
+
name: req.jsonSchema.name,
|
|
207
|
+
schema: req.jsonSchema.schema,
|
|
208
|
+
strict: true
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
else if (req.jsonMode || req.jsonSchema) body.response_format = { type: "json_object" };
|
|
212
|
+
return body;
|
|
213
|
+
}
|
|
214
|
+
function usesMaxCompletionTokens(model) {
|
|
215
|
+
return /^gpt-5(?:[.-]|$)/i.test(model);
|
|
216
|
+
}
|
|
217
|
+
async function sleep(ms) {
|
|
218
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Combine the per-attempt timeout signal with an optional caller signal into
|
|
222
|
+
* one signal the fetch listens on. Prefers the native `AbortSignal.any`; falls
|
|
223
|
+
* back to manual wiring on runtimes that predate it. The caller signal is also
|
|
224
|
+
* propagated to the timeout controller so aborting it cancels the in-flight
|
|
225
|
+
* fetch immediately.
|
|
226
|
+
*/
|
|
227
|
+
function linkSignals(timeoutController, caller) {
|
|
228
|
+
if (!caller) return timeoutController.signal;
|
|
229
|
+
if (typeof AbortSignal.any === "function") return AbortSignal.any([timeoutController.signal, caller]);
|
|
230
|
+
if (caller.aborted) timeoutController.abort();
|
|
231
|
+
else caller.addEventListener("abort", () => timeoutController.abort(), { once: true });
|
|
232
|
+
return timeoutController.signal;
|
|
233
|
+
}
|
|
234
|
+
/** True once the cross-attempt wall-clock budget (if any) is exhausted. */
|
|
235
|
+
function deadlineExceeded(start, deadlineMs) {
|
|
236
|
+
return deadlineMs != null && Date.now() - start >= deadlineMs;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Strip a ```json / ``` code fence if the model emitted one.
|
|
240
|
+
* Idempotent for naked JSON. Some models (claude-code via router, certain
|
|
241
|
+
* deepseek models) wrap output even under json_object.
|
|
242
|
+
*/
|
|
243
|
+
function stripFencedJson(raw) {
|
|
244
|
+
const trimmed = raw.trim();
|
|
245
|
+
const m = trimmed.match(/^```(?:json)?\s*\n?([\s\S]*?)\n?```\s*$/);
|
|
246
|
+
return m ? m[1].trim() : trimmed;
|
|
247
|
+
}
|
|
248
|
+
function extractJsonPayload(raw) {
|
|
249
|
+
const stripped = stripFencedJson(raw);
|
|
250
|
+
try {
|
|
251
|
+
JSON.parse(stripped);
|
|
252
|
+
return stripped;
|
|
253
|
+
} catch {
|
|
254
|
+
if (stripped.startsWith("{") || stripped.startsWith("[")) return stripped;
|
|
255
|
+
}
|
|
256
|
+
const starts = [...stripped.matchAll(/[[{]/g)].map((match) => match.index).filter((index) => index != null);
|
|
257
|
+
for (const start of starts) {
|
|
258
|
+
const candidate = extractBalancedJson(stripped, start);
|
|
259
|
+
if (!candidate) continue;
|
|
260
|
+
try {
|
|
261
|
+
JSON.parse(candidate);
|
|
262
|
+
return candidate;
|
|
263
|
+
} catch {}
|
|
264
|
+
}
|
|
265
|
+
return stripped;
|
|
266
|
+
}
|
|
267
|
+
function extractBalancedJson(input, start) {
|
|
268
|
+
const opener = input[start];
|
|
269
|
+
const closer = opener === "{" ? "}" : opener === "[" ? "]" : null;
|
|
270
|
+
if (!closer) return null;
|
|
271
|
+
const stack = [closer];
|
|
272
|
+
let isInString = false;
|
|
273
|
+
let isEscaped = false;
|
|
274
|
+
for (let i = start + 1; i < input.length; i++) {
|
|
275
|
+
const char = input[i];
|
|
276
|
+
if (isEscaped) {
|
|
277
|
+
isEscaped = false;
|
|
278
|
+
continue;
|
|
279
|
+
}
|
|
280
|
+
if (char === "\\") {
|
|
281
|
+
isEscaped = isInString;
|
|
282
|
+
continue;
|
|
283
|
+
}
|
|
284
|
+
if (char === "\"") {
|
|
285
|
+
isInString = !isInString;
|
|
286
|
+
continue;
|
|
287
|
+
}
|
|
288
|
+
if (isInString) continue;
|
|
289
|
+
if (char === "{") stack.push("}");
|
|
290
|
+
else if (char === "[") stack.push("]");
|
|
291
|
+
else if (char === stack[stack.length - 1]) {
|
|
292
|
+
stack.pop();
|
|
293
|
+
if (stack.length === 0) return input.slice(start, i + 1);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
return null;
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Low-level call. Returns raw content + usage + cost. Retries on transient
|
|
300
|
+
* failures; does NOT degrade schema here — callers that want graceful
|
|
301
|
+
* degrade use `callLlmJson`.
|
|
302
|
+
*/
|
|
303
|
+
async function callLlm(req, opts = {}) {
|
|
304
|
+
const baseUrl = (opts.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
305
|
+
const url = `${baseUrl}/chat/completions`;
|
|
306
|
+
const endpoint = "/chat/completions";
|
|
307
|
+
const timeoutMs = req.timeoutMs ?? opts.defaultTimeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
308
|
+
const maximumAttempts = resolveMaximumAttempts(opts.maximumAttempts);
|
|
309
|
+
const fetchFn = opts.fetch ?? globalThis.fetch;
|
|
310
|
+
const headers = buildHeaders(opts);
|
|
311
|
+
const provider = opts.provider ?? providerFromBaseUrl(baseUrl);
|
|
312
|
+
const sink = opts.rawSink;
|
|
313
|
+
const redactor = opts.redactor ?? defaultProviderRedactor;
|
|
314
|
+
const traceContext = opts.traceContext;
|
|
315
|
+
const callerSignal = opts.signal;
|
|
316
|
+
const deadlineMs = opts.deadlineMs;
|
|
317
|
+
const deadlineStart = Date.now();
|
|
318
|
+
if (opts.customTokenPricing) costForTokenPricing(opts.customTokenPricing, {
|
|
319
|
+
inputTokens: 0,
|
|
320
|
+
outputTokens: 0
|
|
321
|
+
});
|
|
322
|
+
let lastErr;
|
|
323
|
+
let effectiveRequest = req;
|
|
324
|
+
for (let attempt = 0; attempt < maximumAttempts; attempt++) {
|
|
325
|
+
if (callerSignal?.aborted) throw new DOMException("callLlm aborted by caller signal", "AbortError");
|
|
326
|
+
if (attempt > 0 && deadlineExceeded(deadlineStart, deadlineMs)) throw lastErr instanceof Error ? lastErr : new Error(String(lastErr));
|
|
327
|
+
const controller = new AbortController();
|
|
328
|
+
const attemptSignal = linkSignals(controller, callerSignal);
|
|
329
|
+
const timeoutHandle = setTimeout(() => controller.abort(), timeoutMs);
|
|
330
|
+
const started = Date.now();
|
|
331
|
+
const requestBody = buildBody(effectiveRequest, opts.jsonSchemaTransport === "json-object", opts.thinking);
|
|
332
|
+
let attemptErrorRecorded = false;
|
|
333
|
+
if (sink) await recordRaw(sink, redactor, {
|
|
334
|
+
eventId: cryptoEventId(),
|
|
335
|
+
runId: traceContext?.runId,
|
|
336
|
+
spanId: traceContext?.spanId,
|
|
337
|
+
provider,
|
|
338
|
+
model: req.model,
|
|
339
|
+
endpoint,
|
|
340
|
+
baseUrl,
|
|
341
|
+
attemptIndex: attempt,
|
|
342
|
+
direction: "request",
|
|
343
|
+
timestamp: started,
|
|
344
|
+
requestHeaders: headers,
|
|
345
|
+
requestBody,
|
|
346
|
+
redactedFields: []
|
|
347
|
+
});
|
|
348
|
+
try {
|
|
349
|
+
const res = await fetchFn(url, {
|
|
350
|
+
method: "POST",
|
|
351
|
+
headers,
|
|
352
|
+
body: JSON.stringify(requestBody),
|
|
353
|
+
signal: attemptSignal
|
|
354
|
+
});
|
|
355
|
+
clearTimeout(timeoutHandle);
|
|
356
|
+
const responseHeaders = sink ? headersToObject(res.headers) : void 0;
|
|
357
|
+
if (!res.ok) {
|
|
358
|
+
const body = await res.text();
|
|
359
|
+
if (sink) {
|
|
360
|
+
await recordRaw(sink, redactor, {
|
|
361
|
+
eventId: cryptoEventId(),
|
|
362
|
+
runId: traceContext?.runId,
|
|
363
|
+
spanId: traceContext?.spanId,
|
|
364
|
+
provider,
|
|
365
|
+
model: req.model,
|
|
366
|
+
endpoint,
|
|
367
|
+
baseUrl,
|
|
368
|
+
attemptIndex: attempt,
|
|
369
|
+
direction: "error",
|
|
370
|
+
timestamp: Date.now(),
|
|
371
|
+
durationMs: Date.now() - started,
|
|
372
|
+
statusCode: res.status,
|
|
373
|
+
responseHeaders,
|
|
374
|
+
responseBody: body,
|
|
375
|
+
errorMessage: `HTTP ${res.status}`,
|
|
376
|
+
redactedFields: []
|
|
377
|
+
});
|
|
378
|
+
attemptErrorRecorded = true;
|
|
379
|
+
}
|
|
380
|
+
const err = new LlmCallError(`LLM call ${res.status}: ${body.slice(0, 300)}`, res.status, body, req.model);
|
|
381
|
+
if (isTemperatureOneRejection(res.status, body) && effectiveRequest.temperature !== 1 && attempt < maximumAttempts - 1 && !deadlineExceeded(deadlineStart, deadlineMs)) {
|
|
382
|
+
lastErr = err;
|
|
383
|
+
effectiveRequest = {
|
|
384
|
+
...effectiveRequest,
|
|
385
|
+
temperature: 1
|
|
386
|
+
};
|
|
387
|
+
continue;
|
|
388
|
+
}
|
|
389
|
+
if (RETRYABLE_STATUS.has(res.status) && attempt < maximumAttempts - 1 && !deadlineExceeded(deadlineStart, deadlineMs)) {
|
|
390
|
+
lastErr = err;
|
|
391
|
+
await sleep(parseRetryAfter(res.headers) ?? backoffMs(attempt));
|
|
392
|
+
continue;
|
|
393
|
+
}
|
|
394
|
+
throw err;
|
|
395
|
+
}
|
|
396
|
+
const text = await res.text();
|
|
397
|
+
let json;
|
|
398
|
+
try {
|
|
399
|
+
json = JSON.parse(text);
|
|
400
|
+
} catch (parseErr) {
|
|
401
|
+
if (sink) {
|
|
402
|
+
await recordRaw(sink, redactor, {
|
|
403
|
+
eventId: cryptoEventId(),
|
|
404
|
+
runId: traceContext?.runId,
|
|
405
|
+
spanId: traceContext?.spanId,
|
|
406
|
+
provider,
|
|
407
|
+
model: req.model,
|
|
408
|
+
endpoint,
|
|
409
|
+
baseUrl,
|
|
410
|
+
attemptIndex: attempt,
|
|
411
|
+
direction: "error",
|
|
412
|
+
timestamp: Date.now(),
|
|
413
|
+
durationMs: Date.now() - started,
|
|
414
|
+
statusCode: res.status,
|
|
415
|
+
responseHeaders,
|
|
416
|
+
responseBody: text,
|
|
417
|
+
errorMessage: `non-JSON response: ${parseErr instanceof Error ? parseErr.message : String(parseErr)}`,
|
|
418
|
+
redactedFields: []
|
|
419
|
+
});
|
|
420
|
+
attemptErrorRecorded = true;
|
|
421
|
+
}
|
|
422
|
+
throw parseErr;
|
|
423
|
+
}
|
|
424
|
+
if (sink) await recordRaw(sink, redactor, {
|
|
425
|
+
eventId: cryptoEventId(),
|
|
426
|
+
runId: traceContext?.runId,
|
|
427
|
+
spanId: traceContext?.spanId,
|
|
428
|
+
provider,
|
|
429
|
+
model: req.model,
|
|
430
|
+
endpoint,
|
|
431
|
+
baseUrl,
|
|
432
|
+
attemptIndex: attempt,
|
|
433
|
+
direction: "response",
|
|
434
|
+
timestamp: Date.now(),
|
|
435
|
+
durationMs: Date.now() - started,
|
|
436
|
+
statusCode: res.status,
|
|
437
|
+
responseHeaders,
|
|
438
|
+
responseBody: json,
|
|
439
|
+
redactedFields: []
|
|
440
|
+
});
|
|
441
|
+
const choice = json.choices?.[0];
|
|
442
|
+
const usageRaw = json.usage && typeof json.usage === "object" && !Array.isArray(json.usage) ? json.usage : void 0;
|
|
443
|
+
const promptTokens = providerTokenCount(usageRaw?.prompt_tokens);
|
|
444
|
+
const completionTokens = providerTokenCount(usageRaw?.completion_tokens);
|
|
445
|
+
const totalTokens = providerTokenCount(usageRaw?.total_tokens);
|
|
446
|
+
const reasoningRaw = (usageRaw?.completion_tokens_details && typeof usageRaw.completion_tokens_details === "object" && !Array.isArray(usageRaw.completion_tokens_details) ? usageRaw.completion_tokens_details : void 0)?.reasoning_tokens;
|
|
447
|
+
const reasoningTokens = reasoningRaw === void 0 ? void 0 : providerTokenCount(reasoningRaw);
|
|
448
|
+
const cachedRaw = usageRaw?.prompt_tokens_details && typeof usageRaw.prompt_tokens_details === "object" && !Array.isArray(usageRaw.prompt_tokens_details) ? usageRaw.prompt_tokens_details.cached_tokens : void 0;
|
|
449
|
+
const cachedPromptTokens = cachedRaw === void 0 ? void 0 : providerTokenCount(cachedRaw);
|
|
450
|
+
const usageCaptured = promptTokens !== void 0 && completionTokens !== void 0 && (reasoningRaw === void 0 || reasoningTokens !== void 0 && reasoningTokens <= completionTokens) && (cachedRaw === void 0 || cachedPromptTokens !== void 0 && cachedPromptTokens <= promptTokens) && (totalTokens === void 0 || totalTokens === promptTokens + completionTokens);
|
|
451
|
+
const costFromProxy = json._response_cost ?? json.cost_usd;
|
|
452
|
+
const content = choice?.message?.content ?? "";
|
|
453
|
+
const configuredCost = typeof costFromProxy !== "number" && usageCaptured && opts.customTokenPricing ? costForTokenPricing(opts.customTokenPricing, {
|
|
454
|
+
inputTokens: promptTokens - (cachedPromptTokens ?? 0),
|
|
455
|
+
...cachedPromptTokens ? { cachedTokens: cachedPromptTokens } : {},
|
|
456
|
+
outputTokens: completionTokens
|
|
457
|
+
}) : void 0;
|
|
458
|
+
return {
|
|
459
|
+
content,
|
|
460
|
+
finishReason: choice?.finish_reason ?? null,
|
|
461
|
+
contentEmpty: content.trim().length === 0,
|
|
462
|
+
usage: {
|
|
463
|
+
promptTokens: promptTokens ?? 0,
|
|
464
|
+
completionTokens: completionTokens ?? 0,
|
|
465
|
+
totalTokens: totalTokens ?? (promptTokens ?? 0) + (completionTokens ?? 0),
|
|
466
|
+
captured: usageCaptured,
|
|
467
|
+
reasoningTokens,
|
|
468
|
+
cachedPromptTokens
|
|
469
|
+
},
|
|
470
|
+
costUsd: typeof costFromProxy === "number" ? costFromProxy : configuredCost ?? null,
|
|
471
|
+
model: json.model ?? req.model,
|
|
472
|
+
durationMs: Date.now() - started,
|
|
473
|
+
raw: json
|
|
474
|
+
};
|
|
475
|
+
} catch (err) {
|
|
476
|
+
clearTimeout(timeoutHandle);
|
|
477
|
+
lastErr = err;
|
|
478
|
+
if (callerSignal?.aborted) {
|
|
479
|
+
if (sink && !attemptErrorRecorded) await recordRaw(sink, redactor, {
|
|
480
|
+
eventId: cryptoEventId(),
|
|
481
|
+
runId: traceContext?.runId,
|
|
482
|
+
spanId: traceContext?.spanId,
|
|
483
|
+
provider,
|
|
484
|
+
model: req.model,
|
|
485
|
+
endpoint,
|
|
486
|
+
baseUrl,
|
|
487
|
+
attemptIndex: attempt,
|
|
488
|
+
direction: "error",
|
|
489
|
+
timestamp: Date.now(),
|
|
490
|
+
durationMs: Date.now() - started,
|
|
491
|
+
errorMessage: err instanceof Error ? err.message : String(err),
|
|
492
|
+
redactedFields: []
|
|
493
|
+
});
|
|
494
|
+
throw err;
|
|
495
|
+
}
|
|
496
|
+
if (sink && !attemptErrorRecorded) await recordRaw(sink, redactor, {
|
|
497
|
+
eventId: cryptoEventId(),
|
|
498
|
+
runId: traceContext?.runId,
|
|
499
|
+
spanId: traceContext?.spanId,
|
|
500
|
+
provider,
|
|
501
|
+
model: req.model,
|
|
502
|
+
endpoint,
|
|
503
|
+
baseUrl,
|
|
504
|
+
attemptIndex: attempt,
|
|
505
|
+
direction: "error",
|
|
506
|
+
timestamp: Date.now(),
|
|
507
|
+
durationMs: Date.now() - started,
|
|
508
|
+
errorMessage: err instanceof Error ? err.message : String(err),
|
|
509
|
+
redactedFields: []
|
|
510
|
+
});
|
|
511
|
+
if (attempt < maximumAttempts - 1 && isTransientLlmError(err) && !deadlineExceeded(deadlineStart, deadlineMs)) {
|
|
512
|
+
await sleep(backoffMs(attempt));
|
|
513
|
+
continue;
|
|
514
|
+
}
|
|
515
|
+
throw err;
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
throw lastErr instanceof Error ? lastErr : new Error(String(lastErr));
|
|
519
|
+
}
|
|
520
|
+
async function recordRaw(sink, redactor, event) {
|
|
521
|
+
try {
|
|
522
|
+
await sink.record(redactor(event));
|
|
523
|
+
} catch {}
|
|
524
|
+
}
|
|
525
|
+
function headersToObject(h) {
|
|
526
|
+
const out = {};
|
|
527
|
+
h.forEach((value, key) => {
|
|
528
|
+
out[key] = value;
|
|
529
|
+
});
|
|
530
|
+
return out;
|
|
531
|
+
}
|
|
532
|
+
function cryptoEventId() {
|
|
533
|
+
if (typeof globalThis.crypto?.randomUUID === "function") return globalThis.crypto.randomUUID();
|
|
534
|
+
return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
|
|
535
|
+
}
|
|
536
|
+
/**
|
|
537
|
+
* Structured-output call. Returns parsed JSON plus the raw result envelope.
|
|
538
|
+
* Degrades `jsonSchema` → `jsonMode` on a 400 that names the schema param —
|
|
539
|
+
* critical for deepseek-v3/v4, kimi-k2.6, and other models that don't accept
|
|
540
|
+
* the `response_format.json_schema` shape but DO accept `json_object`.
|
|
541
|
+
*/
|
|
542
|
+
async function callLlmJson(req, opts = {}) {
|
|
543
|
+
const result = await callLlmStructured(req, opts);
|
|
544
|
+
return {
|
|
545
|
+
value: parseJsonResult(result, opts.jsonPayloadMode ?? "extract"),
|
|
546
|
+
result
|
|
547
|
+
};
|
|
548
|
+
}
|
|
549
|
+
/** Shared schema-to-JSON-mode fallback that preserves the raw result. */
|
|
550
|
+
async function callLlmStructured(req, opts = {}) {
|
|
551
|
+
try {
|
|
552
|
+
return await callLlm({
|
|
553
|
+
...req,
|
|
554
|
+
jsonMode: req.jsonMode ?? !req.jsonSchema
|
|
555
|
+
}, opts);
|
|
556
|
+
} catch (err) {
|
|
557
|
+
if (opts.jsonSchemaTransport !== "json-object" && err instanceof LlmCallError && isSchemaRejection(err.status, err.body) && req.jsonSchema) return await callLlm({
|
|
558
|
+
...req,
|
|
559
|
+
jsonMode: true,
|
|
560
|
+
jsonSchema: void 0
|
|
561
|
+
}, opts);
|
|
562
|
+
throw err;
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
function parseJsonResult(result, jsonPayloadMode) {
|
|
566
|
+
try {
|
|
567
|
+
if (result.finishReason === "length") throw new Error(`LLM returned truncated JSON content (model=${result.model}, finishReason=length)`);
|
|
568
|
+
return parseJsonSafely(result.content, result.model, jsonPayloadMode);
|
|
569
|
+
} catch (error) {
|
|
570
|
+
if (error instanceof LlmResponseError) throw error;
|
|
571
|
+
const cause = error instanceof Error ? error : new Error(String(error));
|
|
572
|
+
throw new LlmResponseError(cause.message, result, { cause });
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
function parseJsonSafely(content, model, jsonPayloadMode) {
|
|
576
|
+
const payload = jsonPayloadMode === "exact" ? content : extractJsonPayload(content);
|
|
577
|
+
try {
|
|
578
|
+
return JSON.parse(payload);
|
|
579
|
+
} catch (err) {
|
|
580
|
+
throw new Error(`LLM returned non-JSON content (model=${model}): ${err instanceof Error ? err.message : String(err)}\n--- raw content ---\n${content.slice(0, 800)}`);
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
var LlmRouteAssertionError = class extends CaptureIntegrityError {
|
|
584
|
+
reason;
|
|
585
|
+
baseUrl;
|
|
586
|
+
constructor(message, reason, baseUrl) {
|
|
587
|
+
super(message);
|
|
588
|
+
this.reason = reason;
|
|
589
|
+
this.baseUrl = baseUrl;
|
|
590
|
+
}
|
|
591
|
+
};
|
|
592
|
+
/**
|
|
593
|
+
* Fail-loud assertion that the configured LLM client points at the route
|
|
594
|
+
* the caller intends. Designed for the matrix-runner preflight: invoke
|
|
595
|
+
* once before any LLM call to catch misconfiguration before a sweep burns
|
|
596
|
+
* dollars on the wrong provider.
|
|
597
|
+
*
|
|
598
|
+
* Throws `LlmRouteAssertionError`. Pure — no I/O — so it's safe to call
|
|
599
|
+
* from constructors and CI gates.
|
|
600
|
+
*/
|
|
601
|
+
function assertLlmRoute(opts, req = {}) {
|
|
602
|
+
const baseUrlExplicit = opts.baseUrl !== void 0;
|
|
603
|
+
const baseUrl = (opts.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
604
|
+
if (req.requireExplicitBaseUrl && !baseUrlExplicit) throw new LlmRouteAssertionError(`assertLlmRoute: requireExplicitBaseUrl set but opts.baseUrl is undefined; would fall back to ${DEFAULT_BASE_URL}.`, "no_explicit_base_url", baseUrl);
|
|
605
|
+
if (req.blockedBaseUrls?.some((p) => matchUrl(baseUrl, p))) throw new LlmRouteAssertionError(`assertLlmRoute: baseUrl ${baseUrl} matches a blocked pattern.`, "base_url_blocked", baseUrl);
|
|
606
|
+
if (req.allowedBaseUrls && req.allowedBaseUrls.length > 0) {
|
|
607
|
+
if (!req.allowedBaseUrls.some((p) => matchUrl(baseUrl, p))) throw new LlmRouteAssertionError(`assertLlmRoute: baseUrl ${baseUrl} is not in the allowed list (${req.allowedBaseUrls.map(describePattern).join(", ")}).`, "base_url_not_allowed", baseUrl);
|
|
608
|
+
}
|
|
609
|
+
if (req.requireAuth && !opts.apiKey && !opts.bearer && !opts.authHeader) throw new LlmRouteAssertionError(`assertLlmRoute: requireAuth set but no apiKey, bearer, or authHeader was supplied.`, "no_auth", baseUrl);
|
|
610
|
+
if (req.expectedProvider) {
|
|
611
|
+
const actual = opts.provider ?? providerFromBaseUrl(baseUrl);
|
|
612
|
+
if (actual !== req.expectedProvider) throw new LlmRouteAssertionError(`assertLlmRoute: expected provider ${req.expectedProvider} but baseUrl ${baseUrl} resolves to ${actual}.`, "wrong_provider", baseUrl);
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
function matchUrl(url, pattern) {
|
|
616
|
+
if (pattern instanceof RegExp) return pattern.test(url);
|
|
617
|
+
return url.toLowerCase().startsWith(pattern.toLowerCase());
|
|
618
|
+
}
|
|
619
|
+
function describePattern(p) {
|
|
620
|
+
return p instanceof RegExp ? p.source : p;
|
|
621
|
+
}
|
|
622
|
+
/**
|
|
623
|
+
* Probe whether a model is reachable. Returns latency + null error on
|
|
624
|
+
* success; `ok=false` + error message on any failure (HTTP, timeout,
|
|
625
|
+
* network, parse). Designed for sweep preflights — fail loud at the
|
|
626
|
+
* boundary before burning a 30-leaf run on a misconfigured router.
|
|
627
|
+
*
|
|
628
|
+
* Sends a tiny `ping` message with `maxTokens=64`. Reasoning models
|
|
629
|
+
* (glm-5.1, deepseek-v4) can burn the entire budget on internal reasoning
|
|
630
|
+
* for short prompts, so don't tighten this further. We don't validate
|
|
631
|
+
* content; HTTP 200 means reachable.
|
|
632
|
+
*/
|
|
633
|
+
async function probeLlm(model, opts = {}) {
|
|
634
|
+
const start = Date.now();
|
|
635
|
+
try {
|
|
636
|
+
await callLlm({
|
|
637
|
+
model,
|
|
638
|
+
messages: [{
|
|
639
|
+
role: "user",
|
|
640
|
+
content: "ping"
|
|
641
|
+
}],
|
|
642
|
+
maxTokens: 64,
|
|
643
|
+
timeoutMs: opts.timeoutMs ?? 3e4
|
|
644
|
+
}, opts);
|
|
645
|
+
return {
|
|
646
|
+
ok: true,
|
|
647
|
+
latencyMs: Date.now() - start,
|
|
648
|
+
error: null
|
|
649
|
+
};
|
|
650
|
+
} catch (err) {
|
|
651
|
+
return {
|
|
652
|
+
ok: false,
|
|
653
|
+
latencyMs: Date.now() - start,
|
|
654
|
+
error: err instanceof Error ? err.message : String(err)
|
|
655
|
+
};
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
/**
|
|
659
|
+
* Stateful client — construct once with defaults, call many times.
|
|
660
|
+
* Thin wrapper around the free functions; exists for callers that want
|
|
661
|
+
* to inject a single configured instance into multiple primitives.
|
|
662
|
+
*/
|
|
663
|
+
var LlmClient = class {
|
|
664
|
+
maximumAttempts;
|
|
665
|
+
opts;
|
|
666
|
+
constructor(opts = {}) {
|
|
667
|
+
this.opts = opts;
|
|
668
|
+
this.maximumAttempts = resolveMaximumAttempts(opts.maximumAttempts);
|
|
669
|
+
}
|
|
670
|
+
call(req, per) {
|
|
671
|
+
const options = {
|
|
672
|
+
...this.opts,
|
|
673
|
+
...per
|
|
674
|
+
};
|
|
675
|
+
return req.jsonSchema ? callLlmStructured(req, options) : callLlm(req, options);
|
|
676
|
+
}
|
|
677
|
+
callJson(req, per) {
|
|
678
|
+
return callLlmJson(req, {
|
|
679
|
+
...this.opts,
|
|
680
|
+
...per
|
|
681
|
+
});
|
|
682
|
+
}
|
|
683
|
+
};
|
|
684
|
+
//#endregion
|
|
685
|
+
export { assertLlmRoute as a, callLlmJson as c, isTransientLlmError as d, maximumChargeForLlmRequest as f, LlmRouteAssertionError as i, costReceiptFromLlm as l, stripFencedJson as m, LlmClient as n, backoffMs as o, probeLlm as p, LlmResponseError as r, callLlm as s, LlmCallError as t, costReceiptFromLlmError as u };
|
|
686
|
+
|
|
687
|
+
//# sourceMappingURL=llm-client--GR4JbZE.js.map
|