@theokit/sdk 4.37.2 → 4.39.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +309 -72
- package/dist/a2a/index.cjs +3 -3
- package/dist/a2a/index.js +1 -1
- package/dist/a2a/subagent.d.cts +1 -0
- package/dist/a2a/subagent.d.ts +1 -0
- package/dist/{agent-SmxntivO.d.ts → agent-D7bRK9Kg.d.cts} +108 -41
- package/dist/agent-I3EZZR6S.cjs +55 -0
- package/dist/{agent-IE6IE4NW.cjs.map → agent-I3EZZR6S.cjs.map} +1 -1
- package/dist/agent-KKZYLY5D.js +46 -0
- package/dist/{agent-DW2J37IH.js.map → agent-KKZYLY5D.js.map} +1 -1
- package/dist/{agent-DGv1-d81.d.cts → agent-ZCZa7YQv.d.ts} +108 -41
- package/dist/agent-session-store-N4TVKHBU.cjs +23 -0
- package/dist/agent-session-store-N4TVKHBU.cjs.map +1 -0
- package/dist/agent-session-store-RHMHP5DG.js +6 -0
- package/dist/agent-session-store-RHMHP5DG.js.map +1 -0
- package/dist/agent.d.ts +38 -2
- package/dist/auth/index.cjs +15 -15
- package/dist/auth/index.js +4 -4
- package/dist/{batch-SY5GZLFD.js → batch-6KQM3EBA.js} +12 -12
- package/dist/batch-6KQM3EBA.js.map +1 -0
- package/dist/{batch-3SEPDXCU.cjs → batch-X6JKGDPK.cjs} +26 -26
- package/dist/batch-X6JKGDPK.cjs.map +1 -0
- package/dist/chunk-2RW7K6FN.cjs +34 -0
- package/dist/chunk-2RW7K6FN.cjs.map +1 -0
- package/dist/chunk-3I4B3OIX.js +105 -0
- package/dist/chunk-3I4B3OIX.js.map +1 -0
- package/dist/{chunk-2WFB5ZOX.js → chunk-42IFCKQZ.js} +5 -5
- package/dist/{chunk-2WFB5ZOX.js.map → chunk-42IFCKQZ.js.map} +1 -1
- package/dist/{chunk-DCJ5MCJ3.js → chunk-4F7JQZOX.js} +9 -36
- package/dist/chunk-4F7JQZOX.js.map +1 -0
- package/dist/{chunk-JNIWFCKI.js → chunk-4JSZYSGW.js} +3 -3
- package/dist/{chunk-JNIWFCKI.js.map → chunk-4JSZYSGW.js.map} +1 -1
- package/dist/{chunk-EEZ7CFMM.js → chunk-5KOW3GLE.js} +2 -2
- package/dist/chunk-5KOW3GLE.js.map +1 -0
- package/dist/{chunk-6VP3XGEK.js → chunk-65ONFZWM.js} +12 -11
- package/dist/chunk-65ONFZWM.js.map +1 -0
- package/dist/{chunk-CSZRJ4RE.js → chunk-6EEYRFJC.js} +5 -5
- package/dist/{chunk-CSZRJ4RE.js.map → chunk-6EEYRFJC.js.map} +1 -1
- package/dist/{chunk-FAY3QDGC.cjs → chunk-6LGQECT7.cjs} +11 -11
- package/dist/{chunk-FAY3QDGC.cjs.map → chunk-6LGQECT7.cjs.map} +1 -1
- package/dist/{chunk-PAEJPLVN.cjs → chunk-6NEHIHFU.cjs} +4 -4
- package/dist/{chunk-PAEJPLVN.cjs.map → chunk-6NEHIHFU.cjs.map} +1 -1
- package/dist/chunk-6YNYA7GD.cjs +103 -0
- package/dist/chunk-6YNYA7GD.cjs.map +1 -0
- package/dist/chunk-74D7KSBP.cjs +112 -0
- package/dist/chunk-74D7KSBP.cjs.map +1 -0
- package/dist/{chunk-FK4EJD2I.cjs → chunk-75DSEWTJ.cjs} +7 -7
- package/dist/{chunk-FK4EJD2I.cjs.map → chunk-75DSEWTJ.cjs.map} +1 -1
- package/dist/{chunk-SWIBQFPH.cjs → chunk-7OLG7VI4.cjs} +4 -4
- package/dist/{chunk-SWIBQFPH.cjs.map → chunk-7OLG7VI4.cjs.map} +1 -1
- package/dist/chunk-7U2HAAWB.cjs +199 -0
- package/dist/chunk-7U2HAAWB.cjs.map +1 -0
- package/dist/{chunk-YBFDBOUN.cjs → chunk-7YBJZS5P.cjs} +8 -8
- package/dist/{chunk-YBFDBOUN.cjs.map → chunk-7YBJZS5P.cjs.map} +1 -1
- package/dist/{chunk-GLUWH6JO.js → chunk-AECV3G5Z.js} +4 -4
- package/dist/{chunk-GLUWH6JO.js.map → chunk-AECV3G5Z.js.map} +1 -1
- package/dist/{chunk-UQPDFW4E.js → chunk-AR5MQZ3J.js} +3 -3
- package/dist/{chunk-UQPDFW4E.js.map → chunk-AR5MQZ3J.js.map} +1 -1
- package/dist/{chunk-G2F67XUR.cjs → chunk-B4YA6BRS.cjs} +13 -14
- package/dist/chunk-B4YA6BRS.cjs.map +1 -0
- package/dist/{chunk-LTCOPATU.cjs → chunk-BCQ3E2ZG.cjs} +12 -3
- package/dist/chunk-BCQ3E2ZG.cjs.map +1 -0
- package/dist/{chunk-ALU3KC4G.cjs → chunk-BPN5ONSW.cjs} +223 -277
- package/dist/chunk-BPN5ONSW.cjs.map +1 -0
- package/dist/{chunk-YHZXBDAW.js → chunk-BQDUEG4C.js} +16 -16
- package/dist/{chunk-YHZXBDAW.js.map → chunk-BQDUEG4C.js.map} +1 -1
- package/dist/{chunk-IT3PWBW4.cjs → chunk-BURYFNOM.cjs} +2 -2
- package/dist/chunk-BURYFNOM.cjs.map +1 -0
- package/dist/{chunk-BJMKQOY2.cjs → chunk-C7OP3FAK.cjs} +47 -11
- package/dist/chunk-C7OP3FAK.cjs.map +1 -0
- package/dist/{chunk-XAYVHS2B.cjs → chunk-CEIHCKTO.cjs} +4 -4
- package/dist/chunk-CEIHCKTO.cjs.map +1 -0
- package/dist/{chunk-2423XDPT.cjs → chunk-CN6UX5EV.cjs} +28 -56
- package/dist/chunk-CN6UX5EV.cjs.map +1 -0
- package/dist/{chunk-VNNK6AKU.js → chunk-D7IULBF2.js} +3 -3
- package/dist/chunk-D7IULBF2.js.map +1 -0
- package/dist/chunk-DCXRHCZJ.cjs +118 -0
- package/dist/chunk-DCXRHCZJ.cjs.map +1 -0
- package/dist/{chunk-ICYBIC6N.cjs → chunk-DGLLVCNB.cjs} +4 -4
- package/dist/chunk-DGLLVCNB.cjs.map +1 -0
- package/dist/{chunk-I35DI7ES.js → chunk-DKFGUOWL.js} +3 -3
- package/dist/{chunk-I35DI7ES.js.map → chunk-DKFGUOWL.js.map} +1 -1
- package/dist/{chunk-TQI3KRXZ.cjs → chunk-DMTZ3FII.cjs} +18 -18
- package/dist/{chunk-TQI3KRXZ.cjs.map → chunk-DMTZ3FII.cjs.map} +1 -1
- package/dist/{chunk-QFMXXUUT.js → chunk-DU7DE543.js} +3 -3
- package/dist/{chunk-QFMXXUUT.js.map → chunk-DU7DE543.js.map} +1 -1
- package/dist/{chunk-W4QN5CMG.cjs → chunk-DWY25VLP.cjs} +9 -9
- package/dist/{chunk-W4QN5CMG.cjs.map → chunk-DWY25VLP.cjs.map} +1 -1
- package/dist/chunk-E2FFG33C.js +109 -0
- package/dist/chunk-E2FFG33C.js.map +1 -0
- package/dist/{chunk-QUFSDDNU.cjs → chunk-E4IUN3JB.cjs} +15 -15
- package/dist/{chunk-QUFSDDNU.cjs.map → chunk-E4IUN3JB.cjs.map} +1 -1
- package/dist/{chunk-THEYGCYS.cjs → chunk-ECHGWE47.cjs} +4 -4
- package/dist/chunk-ECHGWE47.cjs.map +1 -0
- package/dist/{chunk-U2WLFOA3.cjs → chunk-ECW2MLEW.cjs} +4 -4
- package/dist/{chunk-U2WLFOA3.cjs.map → chunk-ECW2MLEW.cjs.map} +1 -1
- package/dist/{chunk-MXSMAGDU.js → chunk-ET6PHZRX.js} +33 -26
- package/dist/chunk-ET6PHZRX.js.map +1 -0
- package/dist/{chunk-G6AASL5T.cjs → chunk-FRUBE44B.cjs} +24 -24
- package/dist/{chunk-G6AASL5T.cjs.map → chunk-FRUBE44B.cjs.map} +1 -1
- package/dist/{chunk-3ILFUXNE.cjs → chunk-FWBSDQZ7.cjs} +5 -5
- package/dist/{chunk-3ILFUXNE.cjs.map → chunk-FWBSDQZ7.cjs.map} +1 -1
- package/dist/{chunk-7DXLNNKH.cjs → chunk-G2Q3ZC6C.cjs} +4 -4
- package/dist/{chunk-7DXLNNKH.cjs.map → chunk-G2Q3ZC6C.cjs.map} +1 -1
- package/dist/{chunk-56ZM6P7Z.cjs → chunk-G4XUXSRN.cjs} +12 -12
- package/dist/chunk-G4XUXSRN.cjs.map +1 -0
- package/dist/{chunk-VYJSHGAY.js → chunk-GIRD3RWH.js} +422 -295
- package/dist/chunk-GIRD3RWH.js.map +1 -0
- package/dist/{chunk-NQ4AC2U4.cjs → chunk-HIQFVHC6.cjs} +9 -9
- package/dist/{chunk-NQ4AC2U4.cjs.map → chunk-HIQFVHC6.cjs.map} +1 -1
- package/dist/{chunk-EXQV452X.js → chunk-HWNVAUK4.js} +3 -3
- package/dist/{chunk-EXQV452X.js.map → chunk-HWNVAUK4.js.map} +1 -1
- package/dist/{chunk-P34DHHYQ.cjs → chunk-I53ZQHU6.cjs} +34 -27
- package/dist/chunk-I53ZQHU6.cjs.map +1 -0
- package/dist/{chunk-MHCKWQR3.cjs → chunk-IHFNRNTJ.cjs} +8 -8
- package/dist/{chunk-MHCKWQR3.cjs.map → chunk-IHFNRNTJ.cjs.map} +1 -1
- package/dist/{chunk-W52DKZBR.cjs → chunk-INSFS5GT.cjs} +680 -553
- package/dist/chunk-INSFS5GT.cjs.map +1 -0
- package/dist/{chunk-TAPQWDW2.js → chunk-IVSD7L22.js} +12 -4
- package/dist/chunk-IVSD7L22.js.map +1 -0
- package/dist/{chunk-WDGCZDRG.js → chunk-J3UK2GMN.js} +3 -3
- package/dist/{chunk-WDGCZDRG.js.map → chunk-J3UK2GMN.js.map} +1 -1
- package/dist/{chunk-4YB7B3RP.cjs → chunk-J6T5LWJ4.cjs} +15 -14
- package/dist/chunk-J6T5LWJ4.cjs.map +1 -0
- package/dist/{chunk-XAEAMI5H.js → chunk-JRLXEYR4.js} +21 -5
- package/dist/chunk-JRLXEYR4.js.map +1 -0
- package/dist/{chunk-ZJN6NTHE.js → chunk-JZUPMTJY.js} +3 -3
- package/dist/{chunk-ZJN6NTHE.js.map → chunk-JZUPMTJY.js.map} +1 -1
- package/dist/{chunk-M5ZQBOIZ.js → chunk-KE6XKRLQ.js} +3 -3
- package/dist/{chunk-M5ZQBOIZ.js.map → chunk-KE6XKRLQ.js.map} +1 -1
- package/dist/chunk-KGRIHEDT.js +110 -0
- package/dist/chunk-KGRIHEDT.js.map +1 -0
- package/dist/{chunk-T4QWDOG6.js → chunk-KWUNN5J2.js} +5 -5
- package/dist/{chunk-T4QWDOG6.js.map → chunk-KWUNN5J2.js.map} +1 -1
- package/dist/{chunk-56OXYUZE.js → chunk-KX7JV5KM.js} +3 -3
- package/dist/chunk-KX7JV5KM.js.map +1 -0
- package/dist/{chunk-D4ZUJTFB.cjs → chunk-LALG2K33.cjs} +8 -8
- package/dist/{chunk-D4ZUJTFB.cjs.map → chunk-LALG2K33.cjs.map} +1 -1
- package/dist/{chunk-QGDKZDPN.js → chunk-LGILIGV3.js} +3 -3
- package/dist/{chunk-QGDKZDPN.js.map → chunk-LGILIGV3.js.map} +1 -1
- package/dist/{chunk-HEN5WXXI.js → chunk-LJX2SQV2.js} +6 -6
- package/dist/{chunk-HEN5WXXI.js.map → chunk-LJX2SQV2.js.map} +1 -1
- package/dist/{chunk-SDIBMLL5.js → chunk-MC5EINBV.js} +44 -8
- package/dist/chunk-MC5EINBV.js.map +1 -0
- package/dist/{chunk-F6Y4IEQM.js → chunk-ML5A5DOJ.js} +4 -4
- package/dist/{chunk-F6Y4IEQM.js.map → chunk-ML5A5DOJ.js.map} +1 -1
- package/dist/{chunk-6EDQBX7U.cjs → chunk-N475ETD6.cjs} +17 -17
- package/dist/{chunk-6EDQBX7U.cjs.map → chunk-N475ETD6.cjs.map} +1 -1
- package/dist/{chunk-YPQF26X7.cjs → chunk-OBA6YK2R.cjs} +2 -2
- package/dist/chunk-OBA6YK2R.cjs.map +1 -0
- package/dist/chunk-OXNYIMZZ.js +31 -0
- package/dist/chunk-OXNYIMZZ.js.map +1 -0
- package/dist/{chunk-NFCKEBHI.js → chunk-PI4RO4GR.js} +3 -3
- package/dist/{chunk-NFCKEBHI.js.map → chunk-PI4RO4GR.js.map} +1 -1
- package/dist/{chunk-2ONFGMBV.js → chunk-PY2RQOA7.js} +2 -2
- package/dist/chunk-PY2RQOA7.js.map +1 -0
- package/dist/chunk-QKE556YD.js +197 -0
- package/dist/chunk-QKE556YD.js.map +1 -0
- package/dist/{chunk-FV3YEMQ7.js → chunk-RP5HQVLD.js} +13 -14
- package/dist/chunk-RP5HQVLD.js.map +1 -0
- package/dist/chunk-SCFW5MJZ.js +100 -0
- package/dist/chunk-SCFW5MJZ.js.map +1 -0
- package/dist/{chunk-CD73YHEH.js → chunk-SG5ZWT6C.js} +3 -3
- package/dist/{chunk-CD73YHEH.js.map → chunk-SG5ZWT6C.js.map} +1 -1
- package/dist/{chunk-MRODLUGY.cjs → chunk-TIMPJL5V.cjs} +4 -4
- package/dist/{chunk-MRODLUGY.cjs.map → chunk-TIMPJL5V.cjs.map} +1 -1
- package/dist/{chunk-77WHPVXE.js → chunk-TOTP24P6.js} +4 -4
- package/dist/chunk-TOTP24P6.js.map +1 -0
- package/dist/{chunk-3O2ELBST.cjs → chunk-USZTVNUQ.cjs} +5 -5
- package/dist/{chunk-3O2ELBST.cjs.map → chunk-USZTVNUQ.cjs.map} +1 -1
- package/dist/{chunk-YDLNI7J6.js → chunk-V2RBCCN5.js} +3 -3
- package/dist/chunk-V2RBCCN5.js.map +1 -0
- package/dist/{chunk-NNSKJCBM.cjs → chunk-VJYSQXN6.cjs} +10 -10
- package/dist/{chunk-NNSKJCBM.cjs.map → chunk-VJYSQXN6.cjs.map} +1 -1
- package/dist/{chunk-GM7QDQ24.cjs → chunk-W4WKVOOQ.cjs} +11 -11
- package/dist/{chunk-GM7QDQ24.cjs.map → chunk-W4WKVOOQ.cjs.map} +1 -1
- package/dist/chunk-XYOHKCYG.cjs +109 -0
- package/dist/chunk-XYOHKCYG.cjs.map +1 -0
- package/dist/{chunk-ZW345YOI.js → chunk-YP67XZES.js} +4 -4
- package/dist/{chunk-ZW345YOI.js.map → chunk-YP67XZES.js.map} +1 -1
- package/dist/{chunk-YCXMSDSP.js → chunk-YRXY2A5L.js} +4 -4
- package/dist/{chunk-YCXMSDSP.js.map → chunk-YRXY2A5L.js.map} +1 -1
- package/dist/{chunk-IEUDKUPM.cjs → chunk-Z2CUEBXV.cjs} +25 -9
- package/dist/chunk-Z2CUEBXV.cjs.map +1 -0
- package/dist/{chunk-GL7CFBVC.js → chunk-ZYB6B7QJ.js} +112 -165
- package/dist/chunk-ZYB6B7QJ.js.map +1 -0
- package/dist/compact-session-PYEC3NZV.js +18 -0
- package/dist/{compact-session-WNKKIIDW.js.map → compact-session-PYEC3NZV.js.map} +1 -1
- package/dist/compact-session-VVT6IBJG.cjs +55 -0
- package/dist/{compact-session-H5TKLD55.cjs.map → compact-session-VVT6IBJG.cjs.map} +1 -1
- package/dist/compaction.cjs +19 -19
- package/dist/compaction.d.cts +9 -9
- package/dist/compaction.d.ts +9 -9
- package/dist/compaction.js +3 -3
- package/dist/concurrency.cjs +6 -6
- package/dist/concurrency.js +4 -4
- package/dist/context-2FZSC6VQ.cjs +22 -0
- package/dist/{context-ZV33V4DC.cjs.map → context-2FZSC6VQ.cjs.map} +1 -1
- package/dist/context-ATJJAFOS.js +5 -0
- package/dist/{context-VAYLPT4O.js.map → context-ATJJAFOS.js.map} +1 -1
- package/dist/{cron-Dx7B-3WB.d.ts → cron-Bx7tzm5R.d.ts} +54 -2
- package/dist/{cron-BiK_aNJI.d.cts → cron-D-DVjGQe.d.cts} +54 -2
- package/dist/cron.cjs +34 -30
- package/dist/cron.d.cts +3 -3
- package/dist/cron.d.ts +3 -3
- package/dist/cron.js +33 -29
- package/dist/{errors-DyVbXdR4.d.cts → errors-DMY-gLSK.d.cts} +1 -1
- package/dist/{errors-Cua4WC9H.d.ts → errors-DjBQ4Tn8.d.ts} +1 -1
- package/dist/errors.cjs +21 -21
- package/dist/errors.d.cts +2 -2
- package/dist/errors.d.ts +2 -2
- package/dist/errors.js +2 -2
- package/dist/eval.cjs +42 -37
- package/dist/eval.cjs.map +1 -1
- package/dist/eval.js +38 -33
- package/dist/eval.js.map +1 -1
- package/dist/{executor-OZSYXDKF.cjs → executor-BMRICN46.cjs} +26 -25
- package/dist/executor-BMRICN46.cjs.map +1 -0
- package/dist/{executor-PAH72CB5.js → executor-T65PPOPT.js} +10 -9
- package/dist/executor-T65PPOPT.js.map +1 -0
- package/dist/filesystem/index.cjs +7 -7
- package/dist/filesystem/index.js +3 -3
- package/dist/fs-session-store-J5MCFFUM.cjs +19 -0
- package/dist/{fs-session-store-7E7UPLF2.cjs.map → fs-session-store-J5MCFFUM.cjs.map} +1 -1
- package/dist/fs-session-store-O6FNHECD.js +10 -0
- package/dist/{fs-session-store-6MY7PNI2.js.map → fs-session-store-O6FNHECD.js.map} +1 -1
- package/dist/generate-object-UF6WIZLF.cjs +20 -0
- package/dist/{generate-object-5SCEH2EE.cjs.map → generate-object-UF6WIZLF.cjs.map} +1 -1
- package/dist/generate-object-XDCBYVK3.js +7 -0
- package/dist/{generate-object-I7UD4NWN.js.map → generate-object-XDCBYVK3.js.map} +1 -1
- package/dist/index-manager-N7RQYUKT.cjs +20 -0
- package/dist/{index-manager-R6ZJFEZF.cjs.map → index-manager-N7RQYUKT.cjs.map} +1 -1
- package/dist/index-manager-ZVZUHPP7.js +11 -0
- package/dist/{index-manager-KKAK7NT3.js.map → index-manager-ZVZUHPP7.js.map} +1 -1
- package/dist/index.cjs +154 -148
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +201 -43
- package/dist/index.d.ts +201 -43
- package/dist/index.js +62 -59
- package/dist/index.js.map +1 -1
- package/dist/{inject-session-UXNJQTZ6.js → inject-session-GQMTDZUN.js} +8 -7
- package/dist/inject-session-GQMTDZUN.js.map +1 -0
- package/dist/{inject-session-DM4SKTZO.cjs → inject-session-LFCYVSLJ.cjs} +11 -10
- package/dist/inject-session-LFCYVSLJ.cjs.map +1 -0
- package/dist/internal/agent-loop/live-events.d.ts +46 -0
- package/dist/internal/agent-loop/loop-thinking-steps.d.ts +28 -0
- package/dist/internal/agent-loop/message-builders.d.ts +12 -3
- package/dist/internal/budget/compute-cost.d.ts +1 -1
- package/dist/internal/diagnostics.d.ts +46 -31
- package/dist/internal/error-mappers/anthropic.d.ts +1 -1
- package/dist/internal/global-singleton.d.ts +7 -7
- package/dist/internal/judge/judge-call.d.ts +14 -14
- package/dist/internal/llm/anthropic-shared.d.ts +4 -4
- package/dist/internal/llm/retrying-client.d.ts +29 -29
- package/dist/internal/llm/transport-error.d.ts +2 -2
- package/dist/internal/llm/types.d.ts +49 -9
- package/dist/internal/local-agent/mcp-pool.d.ts +7 -3
- package/dist/internal/memory/adapters/azure-openai-embedding.d.cts +2 -0
- package/dist/internal/memory/adapters/catalog.d.cts +1 -0
- package/dist/internal/memory/adapters/cohere-embedding.d.cts +2 -0
- package/dist/internal/memory/adapters/deepinfra-embedding.d.cts +2 -0
- package/dist/internal/memory/adapters/gemini-embedding.d.cts +2 -0
- package/dist/internal/memory/adapters/index.cjs +28 -0
- package/dist/internal/memory/adapters/index.cjs.map +1 -0
- package/dist/internal/memory/adapters/index.d.cts +16 -0
- package/dist/internal/memory/adapters/index.d.ts +16 -0
- package/dist/internal/memory/adapters/index.js +11 -0
- package/dist/internal/memory/adapters/index.js.map +1 -0
- package/dist/internal/memory/adapters/jina-embedding.d.cts +2 -0
- package/dist/internal/memory/adapters/mistral-embedding.d.cts +2 -0
- package/dist/internal/memory/adapters/ollama-embedding.d.cts +34 -0
- package/dist/internal/memory/adapters/openai-compatible.d.cts +51 -0
- package/dist/internal/memory/adapters/openai-compatible.d.ts +28 -0
- package/dist/internal/memory/adapters/openai-embedding.d.cts +2 -0
- package/dist/internal/memory/adapters/openrouter-embedding.d.cts +2 -0
- package/dist/internal/memory/adapters/voyage-embedding.d.cts +2 -0
- package/dist/internal/memory/dreaming/diary.d.ts +4 -0
- package/dist/internal/memory/dreaming/phases.d.ts +15 -0
- package/dist/internal/memory/dreaming/run.d.ts +10 -0
- package/dist/internal/memory/migrate-sqlite-to-lance.d.ts +15 -0
- package/dist/internal/memory/sdk-memory-peer-loader.d.ts +21 -0
- package/dist/internal/persistence/exclusive-create.d.cts +2 -2
- package/dist/internal/persistence/exclusive-create.d.ts +2 -2
- package/dist/internal/persistence/fs-session-store.d.cts +18 -18
- package/dist/internal/persistence/fs-session-store.d.ts +18 -18
- package/dist/internal/persistence/index.cjs +25 -25
- package/dist/internal/persistence/index.cjs.map +1 -1
- package/dist/internal/persistence/index.js +6 -6
- package/dist/internal/persistence/index.js.map +1 -1
- package/dist/internal/persistence/paths.d.cts +7 -7
- package/dist/internal/persistence/paths.d.ts +7 -7
- package/dist/internal/persistence/session-transcript.d.cts +13 -7
- package/dist/internal/persistence/session-transcript.d.ts +13 -7
- package/dist/internal/persistence/session-writer.d.cts +30 -13
- package/dist/internal/persistence/session-writer.d.ts +30 -13
- package/dist/internal/runtime/concurrency/subagent-credentials.d.ts +35 -0
- package/dist/internal/runtime/fixtures/fixture-run-base.d.ts +45 -13
- package/dist/internal/runtime/lifecycle/goal-marker.d.ts +8 -8
- package/dist/internal/security/index.cjs +13 -13
- package/dist/internal/security/index.js +3 -3
- package/dist/internal/session/agent-session-store.d.ts +1 -0
- package/dist/internal/session/agent-session.d.ts +14 -14
- package/dist/internal/session/session-cache.d.ts +9 -9
- package/dist/internal/session/session-types.d.ts +6 -1
- package/dist/judge-call-NA2G6ZMJ.js +5 -0
- package/dist/{judge-call-TAEIXMYG.js.map → judge-call-NA2G6ZMJ.js.map} +1 -1
- package/dist/judge-call-U2D33JOW.cjs +22 -0
- package/dist/{judge-call-SP3G3X2Y.cjs.map → judge-call-U2D33JOW.cjs.map} +1 -1
- package/dist/models.cjs +20 -20
- package/dist/models.cjs.map +1 -1
- package/dist/models.js +5 -5
- package/dist/models.js.map +1 -1
- package/dist/path-safety.cjs +10 -10
- package/dist/path-safety.js +3 -3
- package/dist/persistence.cjs +43 -43
- package/dist/persistence.cjs.map +1 -1
- package/dist/persistence.d.cts +1 -1
- package/dist/persistence.d.ts +1 -1
- package/dist/persistence.js +14 -14
- package/dist/persistence.js.map +1 -1
- package/dist/project.cjs +5 -5
- package/dist/project.js +3 -3
- package/dist/registry-CAS6Y5ZY.js +9 -0
- package/dist/{registry-SOXE4RY6.js.map → registry-CAS6Y5ZY.js.map} +1 -1
- package/dist/registry-JSDI4WKA.cjs +46 -0
- package/dist/{registry-N3GTKYCI.cjs.map → registry-JSDI4WKA.cjs.map} +1 -1
- package/dist/retry.cjs +4 -4
- package/dist/retry.js +3 -3
- package/dist/{run-CwEJtLPE.d.ts → run-i2-fUohR.d.cts} +217 -174
- package/dist/{run-CwEJtLPE.d.cts → run-i2-fUohR.d.ts} +217 -174
- package/dist/{run-until-YZ2ODWOF.js → run-until-BK56WG4P.js} +3 -3
- package/dist/{run-until-YZ2ODWOF.js.map → run-until-BK56WG4P.js.map} +1 -1
- package/dist/{run-until-ZZ2JLPJM.cjs → run-until-L5KQD3PV.cjs} +4 -4
- package/dist/{run-until-ZZ2JLPJM.cjs.map → run-until-L5KQD3PV.cjs.map} +1 -1
- package/dist/sandbox/bwrap.d.cts +20 -20
- package/dist/sandbox/bwrap.d.ts +20 -20
- package/dist/sandbox/index.cjs +39 -39
- package/dist/sandbox/index.cjs.map +1 -1
- package/dist/sandbox/index.d.cts +1 -1
- package/dist/sandbox/index.d.ts +1 -1
- package/dist/sandbox/index.js +35 -35
- package/dist/sandbox/index.js.map +1 -1
- package/dist/sandbox/linux-sandbox.d.cts +26 -21
- package/dist/sandbox/linux-sandbox.d.ts +26 -21
- package/dist/server/auth/index.cjs.map +1 -1
- package/dist/server/auth/index.d.cts +6 -6
- package/dist/server/auth/index.d.ts +6 -6
- package/dist/server/auth/index.js.map +1 -1
- package/dist/server/auth/orchestrator.d.cts +2 -2
- package/dist/server/auth/orchestrator.d.ts +2 -2
- package/dist/server/auth/types.d.cts +4 -4
- package/dist/server/auth/types.d.ts +4 -4
- package/dist/server/errors-envelope.cjs +14 -14
- package/dist/server/errors-envelope.d.cts +3 -3
- package/dist/server/errors-envelope.d.ts +3 -3
- package/dist/server/errors-envelope.js +3 -3
- package/dist/session-transcript-3B52DKTG.js +5 -0
- package/dist/{session-transcript-6WKLYIN4.js.map → session-transcript-3B52DKTG.js.map} +1 -1
- package/dist/session-transcript-H7NUFXXM.cjs +50 -0
- package/dist/{session-transcript-EAKR4D2W.cjs.map → session-transcript-H7NUFXXM.cjs.map} +1 -1
- package/dist/skills.cjs +7 -7
- package/dist/skills.js +5 -5
- package/dist/stream-object-4FDU76YW.cjs +20 -0
- package/dist/{stream-object-Y7YCX3BI.cjs.map → stream-object-4FDU76YW.cjs.map} +1 -1
- package/dist/stream-object-HWDEEQN4.js +7 -0
- package/dist/{stream-object-OFM66VUT.js.map → stream-object-HWDEEQN4.js.map} +1 -1
- package/dist/subagents-loader-A4W6C3QP.cjs +15 -0
- package/dist/subagents-loader-A4W6C3QP.cjs.map +1 -0
- package/dist/subagents-loader-X33KH2SZ.js +6 -0
- package/dist/subagents-loader-X33KH2SZ.js.map +1 -0
- package/dist/subagents-loader.cjs +6 -6
- package/dist/subagents-loader.d.cts +2 -2
- package/dist/subagents-loader.d.ts +2 -2
- package/dist/subagents-loader.js +4 -4
- package/dist/subscription/index.cjs +3 -3
- package/dist/subscription/index.js +2 -2
- package/dist/task-store.cjs +7 -7
- package/dist/task-store.js +4 -4
- package/dist/types/agent-prims.d.ts +4 -4
- package/dist/types/agent.d.ts +68 -3
- package/dist/types/conversation.d.ts +7 -0
- package/dist/types/goal-events.d.ts +24 -23
- package/dist/types/messages.d.ts +9 -0
- package/dist/types/run.d.ts +27 -0
- package/dist/types/session-message.d.ts +59 -0
- package/dist/types/session-record.d.ts +14 -13
- package/dist/types/workflow.d.ts +36 -0
- package/dist/workflow.cjs +27 -27
- package/dist/workflow.d.cts +17 -1
- package/dist/workflow.d.ts +17 -1
- package/dist/workflow.js +6 -6
- package/docs/harness-capability-map.md +22 -0
- package/package.json +22 -13
- package/dist/agent-DW2J37IH.js +0 -42
- package/dist/agent-IE6IE4NW.cjs +0 -51
- package/dist/batch-3SEPDXCU.cjs.map +0 -1
- package/dist/batch-SY5GZLFD.js.map +0 -1
- package/dist/chunk-2423XDPT.cjs.map +0 -1
- package/dist/chunk-2ONFGMBV.js.map +0 -1
- package/dist/chunk-4YB7B3RP.cjs.map +0 -1
- package/dist/chunk-56OXYUZE.js.map +0 -1
- package/dist/chunk-56ZM6P7Z.cjs.map +0 -1
- package/dist/chunk-5SB4V74H.js +0 -176
- package/dist/chunk-5SB4V74H.js.map +0 -1
- package/dist/chunk-6VP3XGEK.js.map +0 -1
- package/dist/chunk-77WHPVXE.js.map +0 -1
- package/dist/chunk-ALU3KC4G.cjs.map +0 -1
- package/dist/chunk-BJMKQOY2.cjs.map +0 -1
- package/dist/chunk-DCJ5MCJ3.js.map +0 -1
- package/dist/chunk-EEZ7CFMM.js.map +0 -1
- package/dist/chunk-FV3YEMQ7.js.map +0 -1
- package/dist/chunk-G2F67XUR.cjs.map +0 -1
- package/dist/chunk-GL7CFBVC.js.map +0 -1
- package/dist/chunk-H5YVJB4K.cjs +0 -185
- package/dist/chunk-H5YVJB4K.cjs.map +0 -1
- package/dist/chunk-ICYBIC6N.cjs.map +0 -1
- package/dist/chunk-IEUDKUPM.cjs.map +0 -1
- package/dist/chunk-IT3PWBW4.cjs.map +0 -1
- package/dist/chunk-ITLS5LRF.cjs +0 -105
- package/dist/chunk-ITLS5LRF.cjs.map +0 -1
- package/dist/chunk-LTCOPATU.cjs.map +0 -1
- package/dist/chunk-MXSMAGDU.js.map +0 -1
- package/dist/chunk-P34DHHYQ.cjs.map +0 -1
- package/dist/chunk-SDIBMLL5.js.map +0 -1
- package/dist/chunk-TAPQWDW2.js.map +0 -1
- package/dist/chunk-THEYGCYS.cjs.map +0 -1
- package/dist/chunk-VNNK6AKU.js.map +0 -1
- package/dist/chunk-VYJSHGAY.js.map +0 -1
- package/dist/chunk-W52DKZBR.cjs.map +0 -1
- package/dist/chunk-XAEAMI5H.js.map +0 -1
- package/dist/chunk-XAYVHS2B.cjs.map +0 -1
- package/dist/chunk-YDLNI7J6.js.map +0 -1
- package/dist/chunk-YPQF26X7.cjs.map +0 -1
- package/dist/chunk-YVTNFKZO.js +0 -103
- package/dist/chunk-YVTNFKZO.js.map +0 -1
- package/dist/compact-session-H5TKLD55.cjs +0 -54
- package/dist/compact-session-WNKKIIDW.js +0 -17
- package/dist/context-VAYLPT4O.js +0 -5
- package/dist/context-ZV33V4DC.cjs +0 -22
- package/dist/executor-OZSYXDKF.cjs.map +0 -1
- package/dist/executor-PAH72CB5.js.map +0 -1
- package/dist/fs-session-store-6MY7PNI2.js +0 -10
- package/dist/fs-session-store-7E7UPLF2.cjs +0 -19
- package/dist/generate-object-5SCEH2EE.cjs +0 -20
- package/dist/generate-object-I7UD4NWN.js +0 -7
- package/dist/index-manager-KKAK7NT3.js +0 -10
- package/dist/index-manager-R6ZJFEZF.cjs +0 -19
- package/dist/inject-session-DM4SKTZO.cjs.map +0 -1
- package/dist/inject-session-UXNJQTZ6.js.map +0 -1
- package/dist/judge-call-SP3G3X2Y.cjs +0 -22
- package/dist/judge-call-TAEIXMYG.js +0 -5
- package/dist/registry-N3GTKYCI.cjs +0 -46
- package/dist/registry-SOXE4RY6.js +0 -9
- package/dist/session-transcript-6WKLYIN4.js +0 -5
- package/dist/session-transcript-EAKR4D2W.cjs +0 -50
- package/dist/stream-object-OFM66VUT.js +0 -7
- package/dist/stream-object-Y7YCX3BI.cjs +0 -20
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
3
|
+
var chunkECW2MLEW_cjs = require('./chunk-ECW2MLEW.cjs');
|
|
4
|
+
var chunkBURYFNOM_cjs = require('./chunk-BURYFNOM.cjs');
|
|
5
|
+
var chunk6YNYA7GD_cjs = require('./chunk-6YNYA7GD.cjs');
|
|
5
6
|
var chunk6JSIEDKL_cjs = require('./chunk-6JSIEDKL.cjs');
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var
|
|
7
|
+
var chunkZ2CUEBXV_cjs = require('./chunk-Z2CUEBXV.cjs');
|
|
8
|
+
var chunkJ6T5LWJ4_cjs = require('./chunk-J6T5LWJ4.cjs');
|
|
9
|
+
var chunkG4XUXSRN_cjs = require('./chunk-G4XUXSRN.cjs');
|
|
10
|
+
var chunkIHFNRNTJ_cjs = require('./chunk-IHFNRNTJ.cjs');
|
|
11
|
+
var chunkBCQ3E2ZG_cjs = require('./chunk-BCQ3E2ZG.cjs');
|
|
11
12
|
var fs = require('fs');
|
|
12
13
|
var promises = require('fs/promises');
|
|
13
14
|
var os = require('os');
|
|
@@ -16,7 +17,7 @@ var url = require('url');
|
|
|
16
17
|
var module$1 = require('module');
|
|
17
18
|
|
|
18
19
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
19
|
-
var discoveryState =
|
|
20
|
+
var discoveryState = chunkG4XUXSRN_cjs.globalSingleton("theokit-sdk.providers.discovered", () => ({
|
|
20
21
|
done: false
|
|
21
22
|
}));
|
|
22
23
|
function pluginsRoot() {
|
|
@@ -38,19 +39,19 @@ function loadTrustedNames() {
|
|
|
38
39
|
else discarded += 1;
|
|
39
40
|
}
|
|
40
41
|
if (discarded > 0) {
|
|
41
|
-
|
|
42
|
+
chunkBCQ3E2ZG_cjs.diag(
|
|
42
43
|
`[theokit-sdk] WARN: ${path} contains ${discarded} non-string entr${discarded === 1 ? "y" : "ies"} \u2014 discarded (entries must be plugin-name strings)
|
|
43
44
|
`
|
|
44
45
|
);
|
|
45
46
|
}
|
|
46
47
|
} else {
|
|
47
|
-
|
|
48
|
+
chunkBCQ3E2ZG_cjs.diag(
|
|
48
49
|
`[theokit-sdk] WARN: ${path} is not a JSON array \u2014 trusting NO provider plugins (fail-closed)
|
|
49
50
|
`
|
|
50
51
|
);
|
|
51
52
|
}
|
|
52
53
|
} catch {
|
|
53
|
-
|
|
54
|
+
chunkBCQ3E2ZG_cjs.diag(
|
|
54
55
|
`[theokit-sdk] WARN: ${path} is not valid JSON \u2014 trusting NO provider plugins (fail-closed)
|
|
55
56
|
`
|
|
56
57
|
);
|
|
@@ -76,7 +77,7 @@ async function discoverProviderPlugins() {
|
|
|
76
77
|
const trusted = loadTrustedNames();
|
|
77
78
|
for (const entry of entries) {
|
|
78
79
|
if (!trusted.has(entry)) {
|
|
79
|
-
|
|
80
|
+
chunkBCQ3E2ZG_cjs.diag(
|
|
80
81
|
`[theokit-sdk] WARN: provider plugin "${entry}" is present but NOT trusted \u2014 skipped. To trust it, add "${entry}" to ${trustFilePath()} (JSON array of names) or THEOKIT_TRUSTED_PROVIDERS (comma-separated), then restart the process.
|
|
81
82
|
`
|
|
82
83
|
);
|
|
@@ -95,56 +96,25 @@ async function loadOne(dir, entryName) {
|
|
|
95
96
|
if (plugin !== null && typeof plugin === "object" && plugin.kind === "model-provider") {
|
|
96
97
|
const profile = plugin.profile;
|
|
97
98
|
if (profile !== void 0 && typeof profile === "object") {
|
|
98
|
-
|
|
99
|
+
chunkG4XUXSRN_cjs.registerProvider(profile);
|
|
99
100
|
}
|
|
100
101
|
}
|
|
101
102
|
return;
|
|
102
103
|
} catch (err) {
|
|
103
104
|
const msg = err instanceof Error ? err.message : String(err);
|
|
104
|
-
|
|
105
|
+
chunkBCQ3E2ZG_cjs.diag(`[theokit-sdk] failed to load provider plugin "${entryName}": ${msg}
|
|
105
106
|
`);
|
|
106
107
|
return;
|
|
107
108
|
}
|
|
108
109
|
}
|
|
109
110
|
}
|
|
110
111
|
|
|
111
|
-
// src/internal/error-mappers/shared.ts
|
|
112
|
-
var RAW_MAX_BYTES = 2048;
|
|
113
|
-
function parseRetryAfter(headers) {
|
|
114
|
-
if (headers === void 0) return void 0;
|
|
115
|
-
const raw = headers.get("retry-after");
|
|
116
|
-
if (raw === null) return void 0;
|
|
117
|
-
const n = Number(raw);
|
|
118
|
-
if (Number.isFinite(n) && n >= 0) return Math.ceil(n);
|
|
119
|
-
const dateMs = Date.parse(raw);
|
|
120
|
-
if (Number.isFinite(dateMs)) return Math.max(0, Math.ceil((dateMs - Date.now()) / 1e3));
|
|
121
|
-
return void 0;
|
|
122
|
-
}
|
|
123
|
-
function truncateRaw(body) {
|
|
124
|
-
if (body === null || body === void 0) return void 0;
|
|
125
|
-
const s = typeof body === "string" ? body : JSON.stringify(body);
|
|
126
|
-
const truncated = s.length <= RAW_MAX_BYTES ? s : `${s.slice(0, RAW_MAX_BYTES)}\u2026`;
|
|
127
|
-
return chunkLTCOPATU_cjs.redactSecrets(truncated);
|
|
128
|
-
}
|
|
129
|
-
function buildErrorMetadata(args) {
|
|
130
|
-
const retryAfter = parseRetryAfter(args.headers);
|
|
131
|
-
const raw = truncateRaw(args.body);
|
|
132
|
-
return {
|
|
133
|
-
provider: args.provider,
|
|
134
|
-
endpoint: args.endpoint,
|
|
135
|
-
code: args.code,
|
|
136
|
-
statusCode: args.status,
|
|
137
|
-
...retryAfter !== void 0 ? { retryAfter } : {},
|
|
138
|
-
...raw !== void 0 ? { raw } : {}
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
|
|
142
112
|
// src/internal/error-mappers/anthropic.ts
|
|
143
113
|
function mapAnthropicError(args) {
|
|
144
114
|
const { status, body, headers, endpoint } = args;
|
|
145
115
|
const code = mapAnthropicStatusToCode(status, body);
|
|
146
116
|
const message = formatMessage(status, code);
|
|
147
|
-
const metadata = buildErrorMetadata({
|
|
117
|
+
const metadata = chunk6YNYA7GD_cjs.buildErrorMetadata({
|
|
148
118
|
provider: "anthropic",
|
|
149
119
|
endpoint,
|
|
150
120
|
code,
|
|
@@ -153,24 +123,24 @@ function mapAnthropicError(args) {
|
|
|
153
123
|
body
|
|
154
124
|
});
|
|
155
125
|
if (status === 401 || status === 403) {
|
|
156
|
-
return new
|
|
126
|
+
return new chunkIHFNRNTJ_cjs.AuthenticationError(message, { code: "anthropic_auth_failed", metadata });
|
|
157
127
|
}
|
|
158
128
|
if (status === 429) {
|
|
159
|
-
return new
|
|
129
|
+
return new chunkIHFNRNTJ_cjs.RateLimitError(message, { code: "anthropic_rate_limit", metadata });
|
|
160
130
|
}
|
|
161
131
|
if (status === 400) {
|
|
162
|
-
return new
|
|
132
|
+
return new chunkIHFNRNTJ_cjs.ConfigurationError(message, {
|
|
163
133
|
code: `anthropic_${code}`,
|
|
164
134
|
metadata
|
|
165
135
|
});
|
|
166
136
|
}
|
|
167
137
|
if (status === 408) {
|
|
168
|
-
return new
|
|
138
|
+
return new chunkIHFNRNTJ_cjs.NetworkError(message, { code: "anthropic_timeout", metadata });
|
|
169
139
|
}
|
|
170
140
|
if (status >= 500 && status < 600) {
|
|
171
|
-
return new
|
|
141
|
+
return new chunkIHFNRNTJ_cjs.NetworkError(message, { code: "anthropic_server_error", metadata });
|
|
172
142
|
}
|
|
173
|
-
return new
|
|
143
|
+
return new chunkIHFNRNTJ_cjs.UnknownAgentError(message, { code: "anthropic_unknown", metadata });
|
|
174
144
|
}
|
|
175
145
|
function mapAnthropicStatusToCode(status, body) {
|
|
176
146
|
if (status === 401 || status === 403) return "auth_failed";
|
|
@@ -230,6 +200,7 @@ function makeLlmFinish(state) {
|
|
|
230
200
|
if (state.cacheReadTokens !== void 0) finish.cacheReadTokens = state.cacheReadTokens;
|
|
231
201
|
if (state.cacheWriteTokens !== void 0) finish.cacheWriteTokens = state.cacheWriteTokens;
|
|
232
202
|
if (state.reasoningTokens !== void 0) finish.reasoningTokens = state.reasoningTokens;
|
|
203
|
+
if (state.thinking !== void 0) finish.thinking = state.thinking;
|
|
233
204
|
return finish;
|
|
234
205
|
}
|
|
235
206
|
|
|
@@ -240,7 +211,7 @@ function toBlockToolResultContent(content) {
|
|
|
240
211
|
function toStringToolResultContent(content, providerName) {
|
|
241
212
|
if (typeof content === "string") return content;
|
|
242
213
|
if (content.some((block) => block.type === "image")) {
|
|
243
|
-
throw new
|
|
214
|
+
throw new chunkIHFNRNTJ_cjs.ConfigurationError(
|
|
244
215
|
`provider "${providerName}" does not support image content in tool results`
|
|
245
216
|
);
|
|
246
217
|
}
|
|
@@ -284,25 +255,28 @@ function mapAnthropicStopReason(reason) {
|
|
|
284
255
|
return "end_turn";
|
|
285
256
|
}
|
|
286
257
|
}
|
|
258
|
+
function thinkingToWireBlock(part) {
|
|
259
|
+
return part.signature === void 0 ? void 0 : { type: "thinking", thinking: part.text, signature: part.signature };
|
|
260
|
+
}
|
|
261
|
+
function partToWireBlock(part) {
|
|
262
|
+
if (part.type === "text") return { type: "text", text: part.text };
|
|
263
|
+
if (part.type === "tool_use") {
|
|
264
|
+
return { type: "tool_use", id: part.id, name: part.name, input: part.input };
|
|
265
|
+
}
|
|
266
|
+
if (part.type === "image") return { type: "image", source: part.source };
|
|
267
|
+
if (part.type === "thinking") return thinkingToWireBlock(part);
|
|
268
|
+
return {
|
|
269
|
+
type: "tool_result",
|
|
270
|
+
tool_use_id: part.toolUseId,
|
|
271
|
+
// SE7 — this wire is block-capable: strings pass through, structured
|
|
272
|
+
// text/image blocks are forwarded natively.
|
|
273
|
+
content: toBlockToolResultContent(part.content),
|
|
274
|
+
...part.isError === true ? { is_error: true } : {}
|
|
275
|
+
};
|
|
276
|
+
}
|
|
287
277
|
function toAnthropicWireMessage(message) {
|
|
288
278
|
const role = message.role === "system" ? "user" : message.role;
|
|
289
|
-
const content = message.content.map((
|
|
290
|
-
if (part.type === "text") return { type: "text", text: part.text };
|
|
291
|
-
if (part.type === "tool_use") {
|
|
292
|
-
return { type: "tool_use", id: part.id, name: part.name, input: part.input };
|
|
293
|
-
}
|
|
294
|
-
if (part.type === "image") {
|
|
295
|
-
return { type: "image", source: part.source };
|
|
296
|
-
}
|
|
297
|
-
return {
|
|
298
|
-
type: "tool_result",
|
|
299
|
-
tool_use_id: part.toolUseId,
|
|
300
|
-
// SE7 — this wire is block-capable: strings pass through, structured
|
|
301
|
-
// text/image blocks are forwarded natively.
|
|
302
|
-
content: toBlockToolResultContent(part.content),
|
|
303
|
-
...part.isError === true ? { is_error: true } : {}
|
|
304
|
-
};
|
|
305
|
-
});
|
|
279
|
+
const content = message.content.map(partToWireBlock).filter((b) => b !== void 0);
|
|
306
280
|
return { role, content };
|
|
307
281
|
}
|
|
308
282
|
function postAnthropicRequest(args) {
|
|
@@ -346,11 +320,21 @@ async function parseHttpErrorBody(response) {
|
|
|
346
320
|
return text;
|
|
347
321
|
}
|
|
348
322
|
}
|
|
323
|
+
function thinkingBudgetTokens(effort) {
|
|
324
|
+
if (effort === "low" || effort === "minimal") return 1024;
|
|
325
|
+
if (effort === "high" || effort === "max") return 16384;
|
|
326
|
+
return 4096;
|
|
327
|
+
}
|
|
349
328
|
function buildAnthropicCommonBody(request) {
|
|
350
329
|
const body = {
|
|
351
330
|
max_tokens: request.maxTokens ?? 4096,
|
|
352
331
|
messages: request.messages.map(toAnthropicWireMessage)
|
|
353
332
|
};
|
|
333
|
+
if (request.reasoning?.effort !== void 0) {
|
|
334
|
+
const budget = thinkingBudgetTokens(request.reasoning.effort);
|
|
335
|
+
body.thinking = { type: "enabled", budget_tokens: budget };
|
|
336
|
+
if (body.max_tokens <= budget) body.max_tokens = budget + 4096;
|
|
337
|
+
}
|
|
354
338
|
const wireSystem = encodeAnthropicSystem(request.system);
|
|
355
339
|
if (wireSystem !== void 0) body.system = wireSystem;
|
|
356
340
|
if (request.temperature !== void 0) body.temperature = request.temperature;
|
|
@@ -406,7 +390,7 @@ function readWithIdleTimeout(reader, idleTimeoutMs) {
|
|
|
406
390
|
(resolve, reject) => {
|
|
407
391
|
const timer = setTimeout(() => {
|
|
408
392
|
reject(
|
|
409
|
-
new
|
|
393
|
+
new chunkIHFNRNTJ_cjs.NetworkError(`SSE stream idle for ${idleTimeoutMs}ms \u2014 upstream stalled`, {
|
|
410
394
|
code: "stream_idle_timeout"
|
|
411
395
|
})
|
|
412
396
|
);
|
|
@@ -483,9 +467,9 @@ function ehAbort(err) {
|
|
|
483
467
|
}
|
|
484
468
|
function wrapTransportError(err, ctx) {
|
|
485
469
|
if (ehAbort(err)) return err;
|
|
486
|
-
if (err instanceof
|
|
470
|
+
if (err instanceof chunkIHFNRNTJ_cjs.NetworkError) return err;
|
|
487
471
|
const detalhe = err instanceof Error ? err.message : String(err);
|
|
488
|
-
return new
|
|
472
|
+
return new chunkIHFNRNTJ_cjs.NetworkError(`${ctx.providerId} transport failure on ${ctx.endpoint}: ${detalhe}`, {
|
|
489
473
|
code: "transport_failure",
|
|
490
474
|
cause: err
|
|
491
475
|
});
|
|
@@ -549,7 +533,7 @@ var AnthropicClient = class {
|
|
|
549
533
|
for (const event of events) yield event;
|
|
550
534
|
}
|
|
551
535
|
if (!accumulator.finishReasonSeen) {
|
|
552
|
-
throw new
|
|
536
|
+
throw new chunkIHFNRNTJ_cjs.NetworkError("Anthropic SSE stream truncated (no stop_reason)", {
|
|
553
537
|
code: "stream_truncated"
|
|
554
538
|
});
|
|
555
539
|
}
|
|
@@ -571,9 +555,17 @@ var AnthropicStreamAccumulator = class {
|
|
|
571
555
|
cacheWriteTokens;
|
|
572
556
|
toolCalls = /* @__PURE__ */ new Map();
|
|
573
557
|
toolBuffers = /* @__PURE__ */ new Map();
|
|
558
|
+
/**
|
|
559
|
+
* theokit#122 — the turn's thinking block. Text accumulates across `thinking_delta`s; the
|
|
560
|
+
* signature arrives once, on a `signature_delta` for the same block. Undefined until the model
|
|
561
|
+
* actually opens a thinking block, so a non-thinking turn reports nothing.
|
|
562
|
+
*/
|
|
563
|
+
thinking;
|
|
574
564
|
consume(event) {
|
|
575
565
|
if (event.type === "content_block_start") {
|
|
576
|
-
|
|
566
|
+
const block = event.content_block;
|
|
567
|
+
if (block.type === "thinking") this.handleThinkingStart(event);
|
|
568
|
+
else this.handleToolStart(event);
|
|
577
569
|
return [];
|
|
578
570
|
}
|
|
579
571
|
if (event.type === "content_block_delta") {
|
|
@@ -594,12 +586,31 @@ var AnthropicStreamAccumulator = class {
|
|
|
594
586
|
});
|
|
595
587
|
this.toolBuffers.set(start.index, "");
|
|
596
588
|
}
|
|
589
|
+
handleThinkingStart(start) {
|
|
590
|
+
this.thinking = {
|
|
591
|
+
text: start.content_block.thinking ?? "",
|
|
592
|
+
...start.content_block.signature !== void 0 ? { signature: start.content_block.signature } : {}
|
|
593
|
+
};
|
|
594
|
+
}
|
|
597
595
|
handleContentDelta(delta) {
|
|
598
596
|
if (delta.delta.type === "text_delta") {
|
|
599
597
|
const text = delta.delta.text;
|
|
600
598
|
this.text += text;
|
|
601
599
|
return [{ type: "text_delta", text }];
|
|
602
600
|
}
|
|
601
|
+
if (delta.delta.type === "thinking_delta") {
|
|
602
|
+
const text = delta.delta.thinking;
|
|
603
|
+
this.thinking = {
|
|
604
|
+
...this.thinking ?? { text: "" },
|
|
605
|
+
text: (this.thinking?.text ?? "") + text
|
|
606
|
+
};
|
|
607
|
+
return [{ type: "reasoning_delta", text }];
|
|
608
|
+
}
|
|
609
|
+
if (delta.delta.type === "signature_delta") {
|
|
610
|
+
const signature = delta.delta.signature;
|
|
611
|
+
this.thinking = { text: this.thinking?.text ?? "", signature };
|
|
612
|
+
return [{ type: "reasoning_delta", text: "", signature }];
|
|
613
|
+
}
|
|
603
614
|
const idx = delta.index;
|
|
604
615
|
const existing = this.toolBuffers.get(idx) ?? "";
|
|
605
616
|
this.toolBuffers.set(idx, existing + delta.delta.partial_json);
|
|
@@ -645,7 +656,9 @@ var AnthropicStreamAccumulator = class {
|
|
|
645
656
|
// T3.8 — surface Anthropic native cache-token counters when the
|
|
646
657
|
// request used `cache_control: {type:"ephemeral"}` on system blocks.
|
|
647
658
|
cacheReadTokens: this.cacheReadTokens,
|
|
648
|
-
cacheWriteTokens: this.cacheWriteTokens
|
|
659
|
+
cacheWriteTokens: this.cacheWriteTokens,
|
|
660
|
+
// theokit#122 — carry the thinking block + its signature so the turn can be replayed.
|
|
661
|
+
...this.thinking !== void 0 ? { thinking: { type: "thinking", ...this.thinking } } : {}
|
|
649
662
|
});
|
|
650
663
|
}
|
|
651
664
|
};
|
|
@@ -673,7 +686,7 @@ function classifyBedrockError(args, awsType, message) {
|
|
|
673
686
|
return "unknown";
|
|
674
687
|
}
|
|
675
688
|
function buildBedrockMetadata(args, code) {
|
|
676
|
-
return buildErrorMetadata({
|
|
689
|
+
return chunk6YNYA7GD_cjs.buildErrorMetadata({
|
|
677
690
|
provider: "bedrock",
|
|
678
691
|
endpoint: args.endpoint,
|
|
679
692
|
code,
|
|
@@ -690,19 +703,19 @@ function mapBedrockError(args) {
|
|
|
690
703
|
const metadata = buildBedrockMetadata(args, code);
|
|
691
704
|
switch (code) {
|
|
692
705
|
case "rate_limit":
|
|
693
|
-
return new
|
|
706
|
+
return new chunkIHFNRNTJ_cjs.RateLimitError(`Bedrock throttled: ${message}`, { metadata });
|
|
694
707
|
case "auth_failed":
|
|
695
|
-
return new
|
|
708
|
+
return new chunkIHFNRNTJ_cjs.AuthenticationError(`Bedrock auth: ${message}`, { metadata });
|
|
696
709
|
case "invalid_request": {
|
|
697
710
|
const friendly = message.includes("use case details") ? `Bedrock account setup required: ${message} (AWS Console \u2192 Bedrock \u2192 Model access \u2192 Anthropic \u2192 Submit use case form, then retry in 15 min.)` : `Bedrock validation: ${message}`;
|
|
698
|
-
return new
|
|
711
|
+
return new chunkIHFNRNTJ_cjs.ConfigurationError(friendly, { metadata });
|
|
699
712
|
}
|
|
700
713
|
case "timeout":
|
|
701
|
-
return new
|
|
714
|
+
return new chunkIHFNRNTJ_cjs.NetworkError(`Bedrock timeout: ${message}`, { metadata });
|
|
702
715
|
case "server_error":
|
|
703
|
-
return new
|
|
716
|
+
return new chunkIHFNRNTJ_cjs.NetworkError(`Bedrock server error: ${message}`, { metadata });
|
|
704
717
|
default:
|
|
705
|
-
return new
|
|
718
|
+
return new chunkIHFNRNTJ_cjs.UnknownAgentError(`Bedrock unknown: ${message}`, { metadata });
|
|
706
719
|
}
|
|
707
720
|
}
|
|
708
721
|
function parseBody(body) {
|
|
@@ -726,7 +739,7 @@ async function resolveBedrockToken(region) {
|
|
|
726
739
|
return cachedToken.value;
|
|
727
740
|
}
|
|
728
741
|
try {
|
|
729
|
-
const r = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-
|
|
742
|
+
const r = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-BPN5ONSW.cjs', document.baseURI).href)));
|
|
730
743
|
const gen = r("@aws/bedrock-token-generator");
|
|
731
744
|
if (typeof gen.getToken !== "function") return void 0;
|
|
732
745
|
const providers = r("@aws-sdk/credential-providers");
|
|
@@ -754,16 +767,16 @@ var BedrockAnthropicClient = class {
|
|
|
754
767
|
if (fromOpts !== void 0 && fromOpts.length > 0) return fromOpts;
|
|
755
768
|
const fromEnv = await resolveBedrockToken(region);
|
|
756
769
|
if (fromEnv !== void 0 && fromEnv.length > 0) return fromEnv;
|
|
757
|
-
throw new
|
|
770
|
+
throw new chunkIHFNRNTJ_cjs.ConfigurationError(
|
|
758
771
|
"Bedrock requires AWS_BEARER_TOKEN_BEDROCK env var, or install `@aws/bedrock-token-generator` for auto-refresh, or pass apiKey explicitly.",
|
|
759
772
|
{ code: "auth_failed" }
|
|
760
773
|
);
|
|
761
774
|
}
|
|
762
775
|
async *stream(request, signal) {
|
|
763
|
-
const region =
|
|
776
|
+
const region = chunkG4XUXSRN_cjs.inferRegionFromModelId(request.model) ?? process.env.AWS_REGION ?? "us-east-1";
|
|
764
777
|
const token = await this.resolveTokenOrThrow(region);
|
|
765
|
-
const bareModel =
|
|
766
|
-
const baseUrl = this.options.baseUrl ??
|
|
778
|
+
const bareModel = chunkG4XUXSRN_cjs.stripBedrockPrefix(request.model);
|
|
779
|
+
const baseUrl = this.options.baseUrl ?? chunkG4XUXSRN_cjs.resolveBedrockBaseUrl(request.model);
|
|
767
780
|
const endpoint = `/model/${encodeURIComponent(bareModel)}/invoke`;
|
|
768
781
|
const url = `${baseUrl}${endpoint}`;
|
|
769
782
|
const response = await postAnthropicRequest({
|
|
@@ -789,69 +802,6 @@ function buildBedrockBody(request) {
|
|
|
789
802
|
};
|
|
790
803
|
}
|
|
791
804
|
|
|
792
|
-
// src/internal/error-mappers/openai-compatible.ts
|
|
793
|
-
function mapOpenAICompatibleError(args) {
|
|
794
|
-
const { providerId, status, body, headers, endpoint } = args;
|
|
795
|
-
const code = mapOpenAiStatusToCode(status, body);
|
|
796
|
-
const message = formatMessage2(providerId, status, code);
|
|
797
|
-
const metadata = buildErrorMetadata({
|
|
798
|
-
provider: providerId,
|
|
799
|
-
endpoint,
|
|
800
|
-
code,
|
|
801
|
-
status,
|
|
802
|
-
headers,
|
|
803
|
-
body
|
|
804
|
-
});
|
|
805
|
-
if (status === 401 || status === 403) {
|
|
806
|
-
return new chunkMHCKWQR3_cjs.AuthenticationError(message, { code: `${providerId}_auth_failed`, metadata });
|
|
807
|
-
}
|
|
808
|
-
if (status === 429) {
|
|
809
|
-
return new chunkMHCKWQR3_cjs.RateLimitError(message, { code: `${providerId}_rate_limit`, metadata });
|
|
810
|
-
}
|
|
811
|
-
if (status === 400) {
|
|
812
|
-
return new chunkMHCKWQR3_cjs.ConfigurationError(message, { code: `${providerId}_${code}`, metadata });
|
|
813
|
-
}
|
|
814
|
-
if (status === 408) {
|
|
815
|
-
return new chunkMHCKWQR3_cjs.NetworkError(message, { code: `${providerId}_timeout`, metadata });
|
|
816
|
-
}
|
|
817
|
-
if (status >= 500 && status < 600) {
|
|
818
|
-
return new chunkMHCKWQR3_cjs.NetworkError(message, { code: `${providerId}_server_error`, metadata });
|
|
819
|
-
}
|
|
820
|
-
return new chunkMHCKWQR3_cjs.UnknownAgentError(message, { code: `${providerId}_unknown`, metadata });
|
|
821
|
-
}
|
|
822
|
-
function extractOpenAiErrorCode(body) {
|
|
823
|
-
if (body === null || typeof body !== "object") return void 0;
|
|
824
|
-
const err = body.error;
|
|
825
|
-
if (err === void 0 || err === null) return void 0;
|
|
826
|
-
if (typeof err.code === "string") return err.code;
|
|
827
|
-
if (typeof err.type === "string") return err.type;
|
|
828
|
-
return void 0;
|
|
829
|
-
}
|
|
830
|
-
function mapOpenAiStatusToCode(status, body) {
|
|
831
|
-
const rawCode = extractOpenAiErrorCode(body)?.toLowerCase() ?? "";
|
|
832
|
-
if (rawCode.includes("context_length") || rawCode.includes("context_window") || rawCode.includes("too_many_tokens") || rawCode.includes("max_tokens")) {
|
|
833
|
-
return "context_too_long";
|
|
834
|
-
}
|
|
835
|
-
if (rawCode.includes("content_filter") || rawCode.includes("content_policy") || rawCode.includes("safety")) {
|
|
836
|
-
return "content_filtered";
|
|
837
|
-
}
|
|
838
|
-
if (rawCode.includes("model_not_found") || rawCode.includes("model_unavailable") || rawCode.includes("invalid_model")) {
|
|
839
|
-
return "model_unavailable";
|
|
840
|
-
}
|
|
841
|
-
if (status === 402 || rawCode.includes("insufficient_quota") || rawCode.includes("quota_exceeded")) {
|
|
842
|
-
return "quota_exceeded";
|
|
843
|
-
}
|
|
844
|
-
if (status === 401 || status === 403) return "auth_failed";
|
|
845
|
-
if (status === 429) return "rate_limit";
|
|
846
|
-
if (status === 408) return "timeout";
|
|
847
|
-
if (status === 400) return "invalid_request";
|
|
848
|
-
if (status >= 500 && status < 600) return "server_error";
|
|
849
|
-
return "unknown";
|
|
850
|
-
}
|
|
851
|
-
function formatMessage2(providerId, status, code) {
|
|
852
|
-
return `${providerId} API error: ${code} (HTTP ${status})`;
|
|
853
|
-
}
|
|
854
|
-
|
|
855
805
|
// src/internal/llm/fault-injection.ts
|
|
856
806
|
var ENV_GATE_KEY = "NODE_ENV";
|
|
857
807
|
var ENV_GATE_VALUE = "test";
|
|
@@ -881,7 +831,7 @@ var FaultInjectingLlmClient = class {
|
|
|
881
831
|
return yield* this.inner.stream(request, signal);
|
|
882
832
|
}
|
|
883
833
|
if (parsed.status >= 400) {
|
|
884
|
-
throw mapOpenAICompatibleError({
|
|
834
|
+
throw chunk6YNYA7GD_cjs.mapOpenAICompatibleError({
|
|
885
835
|
providerId: this.name,
|
|
886
836
|
status: parsed.status,
|
|
887
837
|
body: parsed.body,
|
|
@@ -891,7 +841,6 @@ var FaultInjectingLlmClient = class {
|
|
|
891
841
|
}
|
|
892
842
|
const text = extractText(parsed.body);
|
|
893
843
|
yield { type: "text_delta", text };
|
|
894
|
-
yield { type: "stop", reason: "end_turn" };
|
|
895
844
|
return {
|
|
896
845
|
stopReason: "end_turn",
|
|
897
846
|
text,
|
|
@@ -929,7 +878,7 @@ function parseOverrideOrWarnOnce() {
|
|
|
929
878
|
function warnInvalidJsonOnce(_raw) {
|
|
930
879
|
if (warnedInvalidJson) return;
|
|
931
880
|
warnedInvalidJson = true;
|
|
932
|
-
|
|
881
|
+
chunkBCQ3E2ZG_cjs.diag(
|
|
933
882
|
`[theokit-sdk] ${ENV_OVERRIDE_KEY} is set but value is not valid JSON of shape \`{"status": number, "body": object | string}\`. Falling back to real LLM call. This warning is shown once per process.
|
|
934
883
|
`
|
|
935
884
|
);
|
|
@@ -957,7 +906,7 @@ function mapOllamaTransportError(args) {
|
|
|
957
906
|
if (args.providerId !== "ollama") return void 0;
|
|
958
907
|
const causeCode = extractCauseCode(args.cause);
|
|
959
908
|
if (causeCode !== "ECONNREFUSED" && causeCode !== "ENOTFOUND") return void 0;
|
|
960
|
-
const metadata = buildErrorMetadata({
|
|
909
|
+
const metadata = chunk6YNYA7GD_cjs.buildErrorMetadata({
|
|
961
910
|
provider: "ollama",
|
|
962
911
|
endpoint: args.endpoint,
|
|
963
912
|
code: "network",
|
|
@@ -965,7 +914,7 @@ function mapOllamaTransportError(args) {
|
|
|
965
914
|
headers: void 0,
|
|
966
915
|
body: { cause: causeCode }
|
|
967
916
|
});
|
|
968
|
-
return new
|
|
917
|
+
return new chunkIHFNRNTJ_cjs.ConfigurationError(
|
|
969
918
|
"Ollama is not reachable. Run `ollama serve` to start the local runtime, or set OLLAMA_HOST to point at a remote Ollama server.",
|
|
970
919
|
{ code: "ollama_unreachable", metadata }
|
|
971
920
|
);
|
|
@@ -975,7 +924,7 @@ function mapOllamaHttpError(args) {
|
|
|
975
924
|
const errString = extractErrorString(args.body).toLowerCase();
|
|
976
925
|
if (args.status === 404 && errString.includes("not found") && errString.includes("pull")) {
|
|
977
926
|
const modelHint = extractModelName(errString);
|
|
978
|
-
const metadata = buildErrorMetadata({
|
|
927
|
+
const metadata = chunk6YNYA7GD_cjs.buildErrorMetadata({
|
|
979
928
|
provider: "ollama",
|
|
980
929
|
endpoint: args.endpoint,
|
|
981
930
|
code: "model_unavailable",
|
|
@@ -984,13 +933,13 @@ function mapOllamaHttpError(args) {
|
|
|
984
933
|
body: args.body
|
|
985
934
|
});
|
|
986
935
|
const pullCmd = modelHint !== void 0 ? `ollama pull ${modelHint}` : "ollama pull <model>";
|
|
987
|
-
return new
|
|
936
|
+
return new chunkIHFNRNTJ_cjs.ConfigurationError(
|
|
988
937
|
`Ollama model is not pulled. Run \`${pullCmd}\` to download it first.`,
|
|
989
938
|
{ code: "ollama_model_not_pulled", metadata }
|
|
990
939
|
);
|
|
991
940
|
}
|
|
992
941
|
if (args.status === 503 && errString.includes("model is loading")) {
|
|
993
|
-
const metadata = buildErrorMetadata({
|
|
942
|
+
const metadata = chunk6YNYA7GD_cjs.buildErrorMetadata({
|
|
994
943
|
provider: "ollama",
|
|
995
944
|
endpoint: args.endpoint,
|
|
996
945
|
code: "server_error",
|
|
@@ -998,7 +947,7 @@ function mapOllamaHttpError(args) {
|
|
|
998
947
|
headers: args.headers,
|
|
999
948
|
body: args.body
|
|
1000
949
|
});
|
|
1001
|
-
return new
|
|
950
|
+
return new chunkIHFNRNTJ_cjs.NetworkError(
|
|
1002
951
|
"Ollama model is loading. Retry in a few seconds \u2014 Ollama is warming up the model into memory.",
|
|
1003
952
|
{ code: "ollama_model_loading", metadata }
|
|
1004
953
|
);
|
|
@@ -1219,7 +1168,7 @@ function toOllamaMessages(message) {
|
|
|
1219
1168
|
}
|
|
1220
1169
|
if (message.role === "user") {
|
|
1221
1170
|
if (message.content.some((p) => p.type === "image")) {
|
|
1222
|
-
throw new
|
|
1171
|
+
throw new chunkIHFNRNTJ_cjs.ConfigurationError(
|
|
1223
1172
|
"image input is not supported on the ollama-native provider; use an OpenAI/OpenRouter model for multimodal turns",
|
|
1224
1173
|
{ code: "ollama_image_unsupported" }
|
|
1225
1174
|
);
|
|
@@ -1348,7 +1297,7 @@ async function safeFetch(fetchFn, url, init) {
|
|
|
1348
1297
|
try {
|
|
1349
1298
|
return await fetchFn(url, init);
|
|
1350
1299
|
} catch (cause) {
|
|
1351
|
-
throw new
|
|
1300
|
+
throw new chunkIHFNRNTJ_cjs.NetworkError("HTTP request failed", { code: "network_error", cause });
|
|
1352
1301
|
}
|
|
1353
1302
|
}
|
|
1354
1303
|
async function safeParseJsonResponse(response) {
|
|
@@ -1375,7 +1324,7 @@ function mapHttpStatusToError(status, body) {
|
|
|
1375
1324
|
cause: body
|
|
1376
1325
|
};
|
|
1377
1326
|
if (envelope.code === "integration_not_connected") {
|
|
1378
|
-
return new
|
|
1327
|
+
return new chunkIHFNRNTJ_cjs.IntegrationNotConnectedError(message, {
|
|
1379
1328
|
provider: envelope.provider ?? "unknown",
|
|
1380
1329
|
helpUrl: envelope.helpUrl ?? "",
|
|
1381
1330
|
code: envelope.code,
|
|
@@ -1383,18 +1332,18 @@ function mapHttpStatusToError(status, body) {
|
|
|
1383
1332
|
});
|
|
1384
1333
|
}
|
|
1385
1334
|
if (status === 401 || status === 403) {
|
|
1386
|
-
return new
|
|
1335
|
+
return new chunkIHFNRNTJ_cjs.AuthenticationError(message, errorOptions);
|
|
1387
1336
|
}
|
|
1388
1337
|
if (status === 429) {
|
|
1389
|
-
return new
|
|
1338
|
+
return new chunkIHFNRNTJ_cjs.RateLimitError(message, errorOptions);
|
|
1390
1339
|
}
|
|
1391
1340
|
if (status >= 400 && status < 500) {
|
|
1392
|
-
return new
|
|
1341
|
+
return new chunkIHFNRNTJ_cjs.ConfigurationError(message, errorOptions);
|
|
1393
1342
|
}
|
|
1394
1343
|
if (status >= 500) {
|
|
1395
|
-
return new
|
|
1344
|
+
return new chunkIHFNRNTJ_cjs.NetworkError(message, errorOptions);
|
|
1396
1345
|
}
|
|
1397
|
-
return new
|
|
1346
|
+
return new chunkIHFNRNTJ_cjs.UnknownAgentError(message, errorOptions);
|
|
1398
1347
|
}
|
|
1399
1348
|
function extractErrorEnvelope(body) {
|
|
1400
1349
|
if (!body || typeof body !== "object") return {};
|
|
@@ -1648,7 +1597,7 @@ var OpenAIClient = class {
|
|
|
1648
1597
|
endpoint: "/v1/chat/completions"
|
|
1649
1598
|
});
|
|
1650
1599
|
if (ollamaMapped !== void 0) throw ollamaMapped;
|
|
1651
|
-
throw mapOpenAICompatibleError({
|
|
1600
|
+
throw chunk6YNYA7GD_cjs.mapOpenAICompatibleError({
|
|
1652
1601
|
providerId,
|
|
1653
1602
|
status: response.status,
|
|
1654
1603
|
body,
|
|
@@ -1677,7 +1626,7 @@ var OpenAIClient = class {
|
|
|
1677
1626
|
}
|
|
1678
1627
|
if (chunk.error !== void 0 && chunk.error !== null) {
|
|
1679
1628
|
const status = typeof chunk.error.code === "number" ? chunk.error.code : 502;
|
|
1680
|
-
throw mapOpenAICompatibleError({
|
|
1629
|
+
throw chunk6YNYA7GD_cjs.mapOpenAICompatibleError({
|
|
1681
1630
|
providerId,
|
|
1682
1631
|
status,
|
|
1683
1632
|
body: chunk,
|
|
@@ -1689,7 +1638,7 @@ var OpenAIClient = class {
|
|
|
1689
1638
|
for (const event of events) yield event;
|
|
1690
1639
|
}
|
|
1691
1640
|
if (!sawDone && !accumulator.finishReasonSeen) {
|
|
1692
|
-
throw new
|
|
1641
|
+
throw new chunkIHFNRNTJ_cjs.NetworkError("SSE stream truncated (no finish_reason / [DONE])", {
|
|
1693
1642
|
code: "stream_truncated"
|
|
1694
1643
|
});
|
|
1695
1644
|
}
|
|
@@ -1821,13 +1770,13 @@ var OpenAIStreamAccumulator = class {
|
|
|
1821
1770
|
toolCalls.push(...recovered.toolCalls);
|
|
1822
1771
|
text = recovered.residualText;
|
|
1823
1772
|
stopReason = "tool_use";
|
|
1824
|
-
|
|
1773
|
+
chunkBCQ3E2ZG_cjs.diag(
|
|
1825
1774
|
`[theokit-sdk] recovered ${recovered.toolCalls.length} leaked tool call(s) from assistant content (provider="${this.providerName}", names=${recovered.toolCalls.map((c) => c.name).join(",")})
|
|
1826
1775
|
`
|
|
1827
1776
|
);
|
|
1828
1777
|
}
|
|
1829
1778
|
if (recovered.droppedNames.length > 0) {
|
|
1830
|
-
|
|
1779
|
+
chunkBCQ3E2ZG_cjs.diag(
|
|
1831
1780
|
`[theokit-sdk] dropped ${recovered.droppedNames.length} leaked block(s) whose name is not a tool in the request (provider="${this.providerName}", names=${recovered.droppedNames.join(",")})
|
|
1832
1781
|
`
|
|
1833
1782
|
);
|
|
@@ -1949,10 +1898,10 @@ async function tryFirstEvent(client, request, signal, logFallback = false) {
|
|
|
1949
1898
|
const firstResult = await generator.next();
|
|
1950
1899
|
return { kind: "ok", generator, firstResult };
|
|
1951
1900
|
} catch (cause) {
|
|
1952
|
-
if (cause instanceof
|
|
1901
|
+
if (cause instanceof chunkIHFNRNTJ_cjs.NetworkError || cause instanceof chunkIHFNRNTJ_cjs.RateLimitError || cause instanceof chunkIHFNRNTJ_cjs.AuthenticationError) {
|
|
1953
1902
|
if (logFallback) {
|
|
1954
1903
|
const errCode = cause.metadata?.code ?? cause.code ?? "unknown";
|
|
1955
|
-
|
|
1904
|
+
chunkBCQ3E2ZG_cjs.diag(`[theokit-sdk] provider ${client.name} failed (${errCode}): falling back
|
|
1956
1905
|
`);
|
|
1957
1906
|
}
|
|
1958
1907
|
return { kind: "handshake_error", error: cause };
|
|
@@ -1994,7 +1943,7 @@ var PoolAwareLlmClient = class {
|
|
|
1994
1943
|
// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: stream() must serialize pool-select → build client → first-event probe → classify → retry/rotate/propagate. Extracting helpers fragments the linear narrative; the comments above each branch keep it readable.
|
|
1995
1944
|
async *stream(request, signal) {
|
|
1996
1945
|
if (this.breaker.shouldSkip(this.pool.provider)) {
|
|
1997
|
-
throw new
|
|
1946
|
+
throw new chunkIHFNRNTJ_cjs.NetworkError(`${this.pool.provider} circuit open \u2014 failing fast`, {
|
|
1998
1947
|
code: "circuit_open"
|
|
1999
1948
|
});
|
|
2000
1949
|
}
|
|
@@ -2013,7 +1962,7 @@ var PoolAwareLlmClient = class {
|
|
|
2013
1962
|
}
|
|
2014
1963
|
if (entry === null) {
|
|
2015
1964
|
this.breaker.recordTimeout(this.pool.provider);
|
|
2016
|
-
throw new
|
|
1965
|
+
throw new chunkIHFNRNTJ_cjs.CredentialPoolExhaustedError(
|
|
2017
1966
|
`All ${this.pool.provider} credentials exhausted; next retry available at ${this.nextRetryHint() ?? "unknown"}`,
|
|
2018
1967
|
{ provider: this.pool.provider, nextRetryAt: this.nextRetryHint() }
|
|
2019
1968
|
);
|
|
@@ -2027,13 +1976,13 @@ var PoolAwareLlmClient = class {
|
|
|
2027
1976
|
}
|
|
2028
1977
|
const decision = classifyAndDecide(attempt.error, hasRetried429);
|
|
2029
1978
|
if (decision === "retry") {
|
|
2030
|
-
const backoffMs =
|
|
1979
|
+
const backoffMs = chunkECW2MLEW_cjs.computeBackoffMs({
|
|
2031
1980
|
attempt: 0,
|
|
2032
1981
|
...this.backoffBaseMs !== void 0 ? { baseMs: this.backoffBaseMs } : {},
|
|
2033
1982
|
...this.rng !== void 0 ? { rng: this.rng } : {}
|
|
2034
1983
|
});
|
|
2035
1984
|
this.onRateLimit?.({ attempt: 1, retryAfterMs: backoffMs });
|
|
2036
|
-
await
|
|
1985
|
+
await chunkECW2MLEW_cjs.sleepWithAbort(backoffMs, signal);
|
|
2037
1986
|
hasRetried429 = true;
|
|
2038
1987
|
continue;
|
|
2039
1988
|
}
|
|
@@ -2045,7 +1994,7 @@ var PoolAwareLlmClient = class {
|
|
|
2045
1994
|
...parseRetryAfterMs(attempt.error) !== void 0 ? { resetAtMs: parseRetryAfterMs(attempt.error) } : {}
|
|
2046
1995
|
});
|
|
2047
1996
|
} catch (persistErr) {
|
|
2048
|
-
|
|
1997
|
+
chunkBCQ3E2ZG_cjs.diag(
|
|
2049
1998
|
`[theokit-sdk] credential-pool: persist failed during rotate; continuing in-memory: ${persistErr instanceof Error ? persistErr.message : String(persistErr)}
|
|
2050
1999
|
`
|
|
2051
2000
|
);
|
|
@@ -2067,8 +2016,8 @@ var PoolAwareLlmClient = class {
|
|
|
2067
2016
|
}
|
|
2068
2017
|
};
|
|
2069
2018
|
function classifyAndDecide(error, hasRetried429) {
|
|
2070
|
-
if (error instanceof
|
|
2071
|
-
if (error instanceof
|
|
2019
|
+
if (error instanceof chunkIHFNRNTJ_cjs.NetworkError) return "propagate";
|
|
2020
|
+
if (error instanceof chunkIHFNRNTJ_cjs.AuthenticationError) return "rotate";
|
|
2072
2021
|
const status = error.metadata?.statusCode ?? 429;
|
|
2073
2022
|
if (status === 402) return "rotate";
|
|
2074
2023
|
return hasRetried429 ? "rotate" : "retry";
|
|
@@ -2081,8 +2030,8 @@ function parseRetryAfterMs(error) {
|
|
|
2081
2030
|
return void 0;
|
|
2082
2031
|
}
|
|
2083
2032
|
function inferStatusCode(error) {
|
|
2084
|
-
if (error instanceof
|
|
2085
|
-
if (error instanceof
|
|
2033
|
+
if (error instanceof chunkIHFNRNTJ_cjs.AuthenticationError) return 401;
|
|
2034
|
+
if (error instanceof chunkIHFNRNTJ_cjs.RateLimitError) return 429;
|
|
2086
2035
|
return 0;
|
|
2087
2036
|
}
|
|
2088
2037
|
function abortError(signal) {
|
|
@@ -2190,7 +2139,7 @@ var ResponsesApiClient = class {
|
|
|
2190
2139
|
body = JSON.parse(text2);
|
|
2191
2140
|
} catch {
|
|
2192
2141
|
}
|
|
2193
|
-
throw mapOpenAICompatibleError({
|
|
2142
|
+
throw chunk6YNYA7GD_cjs.mapOpenAICompatibleError({
|
|
2194
2143
|
providerId,
|
|
2195
2144
|
status: response.status,
|
|
2196
2145
|
body,
|
|
@@ -2250,7 +2199,6 @@ var ResponsesApiClient = class {
|
|
|
2250
2199
|
};
|
|
2251
2200
|
toolCalls.push(call);
|
|
2252
2201
|
delete pending[id];
|
|
2253
|
-
yield { type: "tool_use", id: call.id, name: call.name, input: call.input };
|
|
2254
2202
|
} else if (t === "response.completed" || t === "response.incomplete") {
|
|
2255
2203
|
const usage = event.response?.usage;
|
|
2256
2204
|
if (usage !== void 0) {
|
|
@@ -2262,7 +2210,7 @@ var ResponsesApiClient = class {
|
|
|
2262
2210
|
} else if (t === "response.failed" || t === "error") {
|
|
2263
2211
|
const msg = event.response?.error?.message ?? event.message ?? "responses stream failed";
|
|
2264
2212
|
yield { type: "error", message: msg };
|
|
2265
|
-
throw mapOpenAICompatibleError({
|
|
2213
|
+
throw chunk6YNYA7GD_cjs.mapOpenAICompatibleError({
|
|
2266
2214
|
providerId,
|
|
2267
2215
|
status: 502,
|
|
2268
2216
|
body: { error: { message: msg } },
|
|
@@ -2273,7 +2221,6 @@ var ResponsesApiClient = class {
|
|
|
2273
2221
|
}
|
|
2274
2222
|
}
|
|
2275
2223
|
if (toolCalls.length > 0 && stopReason === "end_turn") stopReason = "tool_use";
|
|
2276
|
-
yield { type: "stop", reason: stopReason };
|
|
2277
2224
|
return makeLlmFinish({
|
|
2278
2225
|
stopReason,
|
|
2279
2226
|
text,
|
|
@@ -2292,32 +2239,32 @@ function abortError2(signal) {
|
|
|
2292
2239
|
}
|
|
2293
2240
|
|
|
2294
2241
|
// src/internal/llm/retrying-client.ts
|
|
2295
|
-
var
|
|
2296
|
-
function
|
|
2297
|
-
if (!
|
|
2298
|
-
if (err instanceof
|
|
2299
|
-
if (err instanceof
|
|
2300
|
-
if (err instanceof
|
|
2242
|
+
var MAX_ATTEMPTS = 3;
|
|
2243
|
+
function isRetriableError(err) {
|
|
2244
|
+
if (!chunkIHFNRNTJ_cjs.isTransientError(err)) return false;
|
|
2245
|
+
if (err instanceof chunkIHFNRNTJ_cjs.CredentialPoolExhaustedError) return false;
|
|
2246
|
+
if (err instanceof chunkIHFNRNTJ_cjs.TheokitAgentError && err.code === "circuit_open") return false;
|
|
2247
|
+
if (err instanceof chunkIHFNRNTJ_cjs.RateLimitError && err.metadata?.statusCode === 402) return false;
|
|
2301
2248
|
return true;
|
|
2302
2249
|
}
|
|
2303
|
-
function
|
|
2304
|
-
if (!(err instanceof
|
|
2305
|
-
const
|
|
2306
|
-
return typeof
|
|
2250
|
+
function retryAfterHintMs(err) {
|
|
2251
|
+
if (!(err instanceof chunkIHFNRNTJ_cjs.RateLimitError)) return void 0;
|
|
2252
|
+
const seconds = err.metadata?.retryAfter;
|
|
2253
|
+
return typeof seconds === "number" && seconds > 0 ? seconds * 1e3 : void 0;
|
|
2307
2254
|
}
|
|
2308
|
-
async function*
|
|
2309
|
-
let
|
|
2310
|
-
while (
|
|
2311
|
-
|
|
2312
|
-
yield
|
|
2313
|
-
|
|
2255
|
+
async function* consume(gen, state) {
|
|
2256
|
+
let step = await gen.next();
|
|
2257
|
+
while (step.done !== true) {
|
|
2258
|
+
state.emitted = true;
|
|
2259
|
+
yield step.value;
|
|
2260
|
+
step = await gen.next();
|
|
2314
2261
|
}
|
|
2315
|
-
return
|
|
2262
|
+
return step.value;
|
|
2316
2263
|
}
|
|
2317
|
-
function
|
|
2318
|
-
if (
|
|
2319
|
-
if (
|
|
2320
|
-
return
|
|
2264
|
+
function canRetry(err, emitted, attempt) {
|
|
2265
|
+
if (emitted) return false;
|
|
2266
|
+
if (attempt === MAX_ATTEMPTS - 1) return false;
|
|
2267
|
+
return isRetriableError(err);
|
|
2321
2268
|
}
|
|
2322
2269
|
var RetryingLlmClient = class {
|
|
2323
2270
|
#inner;
|
|
@@ -2327,10 +2274,10 @@ var RetryingLlmClient = class {
|
|
|
2327
2274
|
this.#rng = opts?.rng;
|
|
2328
2275
|
}
|
|
2329
2276
|
/**
|
|
2330
|
-
*
|
|
2331
|
-
*
|
|
2332
|
-
* decorators.
|
|
2333
|
-
*
|
|
2277
|
+
* The decorated client. Public by the same convention as `FaultInjectingLlmClient.inner`: the
|
|
2278
|
+
* router's wiring tests assert `instanceof PoolAwareLlmClient` and need to see through the
|
|
2279
|
+
* decorators. Without this, adding a decorator breaks tests whose intent is still valid — which is
|
|
2280
|
+
* exactly what M93 did to 4 pre-existing tests.
|
|
2334
2281
|
*/
|
|
2335
2282
|
get inner() {
|
|
2336
2283
|
return this.#inner;
|
|
@@ -2339,35 +2286,35 @@ var RetryingLlmClient = class {
|
|
|
2339
2286
|
return this.#inner.name;
|
|
2340
2287
|
}
|
|
2341
2288
|
/**
|
|
2342
|
-
*
|
|
2289
|
+
* Waits out attempt `n`'s backoff, honoring the provider's `Retry-After` when one arrived.
|
|
2343
2290
|
*
|
|
2344
|
-
*
|
|
2345
|
-
*
|
|
2346
|
-
* `stream`
|
|
2291
|
+
* Its own method because `stream` is a generator with a nested loop, and inlining the conditional
|
|
2292
|
+
* option assembly here pushed cognitive complexity to 19 (project ceiling: 10). The body of
|
|
2293
|
+
* `stream` stays nothing but the attempt machine.
|
|
2347
2294
|
*/
|
|
2348
|
-
async #
|
|
2349
|
-
const
|
|
2350
|
-
const ms =
|
|
2351
|
-
attempt
|
|
2352
|
-
...
|
|
2295
|
+
async #waitBackoff(err, attempt, signal) {
|
|
2296
|
+
const hint = retryAfterHintMs(err);
|
|
2297
|
+
const ms = chunkECW2MLEW_cjs.computeBackoffMs({
|
|
2298
|
+
attempt,
|
|
2299
|
+
...hint !== void 0 ? { retryAfterMs: hint } : {},
|
|
2353
2300
|
...this.#rng !== void 0 ? { rng: this.#rng } : {}
|
|
2354
2301
|
});
|
|
2355
|
-
await
|
|
2302
|
+
await chunkECW2MLEW_cjs.sleepWithAbort(ms, signal);
|
|
2356
2303
|
}
|
|
2357
2304
|
async *stream(request, signal) {
|
|
2358
|
-
let
|
|
2359
|
-
for (let
|
|
2360
|
-
if (signal.aborted) throw
|
|
2361
|
-
const
|
|
2305
|
+
let lastError;
|
|
2306
|
+
for (let attempt = 0; attempt < MAX_ATTEMPTS; attempt++) {
|
|
2307
|
+
if (signal.aborted) throw lastError ?? abortError2(signal);
|
|
2308
|
+
const state = { emitted: false };
|
|
2362
2309
|
try {
|
|
2363
|
-
return yield*
|
|
2310
|
+
return yield* consume(this.#inner.stream(request, signal), state);
|
|
2364
2311
|
} catch (err) {
|
|
2365
|
-
|
|
2366
|
-
if (!
|
|
2367
|
-
await this.#
|
|
2312
|
+
lastError = err;
|
|
2313
|
+
if (!canRetry(err, state.emitted, attempt)) throw err;
|
|
2314
|
+
await this.#waitBackoff(err, attempt, signal);
|
|
2368
2315
|
}
|
|
2369
2316
|
}
|
|
2370
|
-
throw
|
|
2317
|
+
throw lastError ?? new Error("retries exhausted with no recorded error");
|
|
2371
2318
|
}
|
|
2372
2319
|
};
|
|
2373
2320
|
|
|
@@ -2390,7 +2337,7 @@ function classifyVertexError(args, errStatus) {
|
|
|
2390
2337
|
return "unknown";
|
|
2391
2338
|
}
|
|
2392
2339
|
function vertexMetadata(args, code) {
|
|
2393
|
-
return buildErrorMetadata({
|
|
2340
|
+
return chunk6YNYA7GD_cjs.buildErrorMetadata({
|
|
2394
2341
|
provider: "vertex",
|
|
2395
2342
|
endpoint: args.endpoint,
|
|
2396
2343
|
code,
|
|
@@ -2400,23 +2347,23 @@ function vertexMetadata(args, code) {
|
|
|
2400
2347
|
});
|
|
2401
2348
|
}
|
|
2402
2349
|
var VERTEX_ERROR_BUILDERS = {
|
|
2403
|
-
rate_limit: (args, msg) => new
|
|
2350
|
+
rate_limit: (args, msg) => new chunkIHFNRNTJ_cjs.RateLimitError(`Vertex quota exhausted: ${msg}`, {
|
|
2404
2351
|
metadata: vertexMetadata(args, "rate_limit")
|
|
2405
2352
|
}),
|
|
2406
|
-
auth_unauthenticated: (args, msg) => new
|
|
2353
|
+
auth_unauthenticated: (args, msg) => new chunkIHFNRNTJ_cjs.AuthenticationError(`Vertex unauthenticated: ${msg}`, {
|
|
2407
2354
|
metadata: vertexMetadata(args, "auth_failed")
|
|
2408
2355
|
}),
|
|
2409
|
-
auth_permission: (args, msg) => new
|
|
2356
|
+
auth_permission: (args, msg) => new chunkIHFNRNTJ_cjs.AuthenticationError(`Vertex permission denied: ${msg}`, {
|
|
2410
2357
|
metadata: vertexMetadata(args, "auth_failed")
|
|
2411
2358
|
}),
|
|
2412
|
-
invalid_request: (args, msg) => new
|
|
2359
|
+
invalid_request: (args, msg) => new chunkIHFNRNTJ_cjs.ConfigurationError(`Vertex validation: ${msg}`, {
|
|
2413
2360
|
metadata: vertexMetadata(args, "invalid_request")
|
|
2414
2361
|
}),
|
|
2415
|
-
timeout: (args, msg) => new
|
|
2416
|
-
server_error: (args, msg) => new
|
|
2362
|
+
timeout: (args, msg) => new chunkIHFNRNTJ_cjs.NetworkError(`Vertex timeout: ${msg}`, { metadata: vertexMetadata(args, "timeout") }),
|
|
2363
|
+
server_error: (args, msg) => new chunkIHFNRNTJ_cjs.NetworkError(`Vertex server error: ${msg}`, {
|
|
2417
2364
|
metadata: vertexMetadata(args, "server_error")
|
|
2418
2365
|
}),
|
|
2419
|
-
unknown: (args, msg) => new
|
|
2366
|
+
unknown: (args, msg) => new chunkIHFNRNTJ_cjs.UnknownAgentError(`Vertex unknown: ${msg}`, { metadata: vertexMetadata(args, "unknown") })
|
|
2420
2367
|
};
|
|
2421
2368
|
function mapVertexError(args) {
|
|
2422
2369
|
const parsed = parseBody2(args.body);
|
|
@@ -2452,12 +2399,12 @@ async function resolveVertexAccessToken() {
|
|
|
2452
2399
|
async function getAuthClientOrThrow() {
|
|
2453
2400
|
let mod;
|
|
2454
2401
|
try {
|
|
2455
|
-
const r = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-
|
|
2402
|
+
const r = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-BPN5ONSW.cjs', document.baseURI).href)));
|
|
2456
2403
|
mod = r("google-auth-library");
|
|
2457
2404
|
} catch (err) {
|
|
2458
2405
|
const isModuleMissing = err instanceof Error && (err.message.includes("Cannot find module") || err.code === "MODULE_NOT_FOUND");
|
|
2459
2406
|
if (isModuleMissing) {
|
|
2460
|
-
throw new
|
|
2407
|
+
throw new chunkIHFNRNTJ_cjs.ConfigurationError(
|
|
2461
2408
|
"Vertex provider requires `google-auth-library`. Install: `pnpm add google-auth-library`.",
|
|
2462
2409
|
{ code: "auth_failed", cause: err }
|
|
2463
2410
|
);
|
|
@@ -2468,7 +2415,7 @@ async function getAuthClientOrThrow() {
|
|
|
2468
2415
|
const auth = new mod.GoogleAuth({ scopes: [SCOPE_CLOUD_PLATFORM] });
|
|
2469
2416
|
return await auth.getClient();
|
|
2470
2417
|
} catch (err) {
|
|
2471
|
-
|
|
2418
|
+
chunkBCQ3E2ZG_cjs.diag(
|
|
2472
2419
|
`[theokit-sdk] Vertex ADC initialization failed: ${err instanceof Error ? err.message : String(err)}
|
|
2473
2420
|
`
|
|
2474
2421
|
);
|
|
@@ -2494,7 +2441,7 @@ var VertexAnthropicClient = class {
|
|
|
2494
2441
|
resolveProjectOrThrow() {
|
|
2495
2442
|
const projectId = this.options.projectId ?? resolveVertexProjectId();
|
|
2496
2443
|
if (projectId !== void 0) return projectId;
|
|
2497
|
-
throw new
|
|
2444
|
+
throw new chunkIHFNRNTJ_cjs.ConfigurationError(
|
|
2498
2445
|
"Vertex requires a project id. Set GOOGLE_CLOUD_PROJECT env var or run `gcloud config set project <id>`.",
|
|
2499
2446
|
{ code: "auth_failed" }
|
|
2500
2447
|
);
|
|
@@ -2504,7 +2451,7 @@ var VertexAnthropicClient = class {
|
|
|
2504
2451
|
if (fromOpts !== void 0 && fromOpts.length > 0) return fromOpts;
|
|
2505
2452
|
const fromAdc = await resolveVertexAccessToken();
|
|
2506
2453
|
if (fromAdc !== void 0 && fromAdc.length > 0) return fromAdc;
|
|
2507
|
-
throw new
|
|
2454
|
+
throw new chunkIHFNRNTJ_cjs.ConfigurationError(
|
|
2508
2455
|
"Vertex could not resolve an access token. Run `gcloud auth application-default login` or set GOOGLE_APPLICATION_CREDENTIALS to a service-account JSON path.",
|
|
2509
2456
|
{ code: "auth_failed" }
|
|
2510
2457
|
);
|
|
@@ -2513,8 +2460,8 @@ var VertexAnthropicClient = class {
|
|
|
2513
2460
|
const projectId = this.resolveProjectOrThrow();
|
|
2514
2461
|
const location = this.options.location ?? resolveVertexLocation();
|
|
2515
2462
|
const accessToken = await this.resolveTokenOrThrow();
|
|
2516
|
-
const baseUrl =
|
|
2517
|
-
const bareModel =
|
|
2463
|
+
const baseUrl = chunkG4XUXSRN_cjs.resolveVertexBaseUrl({ projectId, location, modelDialect: "anthropic" });
|
|
2464
|
+
const bareModel = chunkG4XUXSRN_cjs.stripVertexPrefix(request.model);
|
|
2518
2465
|
const endpoint = `/models/${encodeURIComponent(bareModel)}:rawPredict`;
|
|
2519
2466
|
const url = `${baseUrl}${endpoint}`;
|
|
2520
2467
|
const response = await postAnthropicRequest({
|
|
@@ -2550,7 +2497,7 @@ var VertexGeminiClient = class {
|
|
|
2550
2497
|
async *stream(request, signal) {
|
|
2551
2498
|
const projectId = this.options.projectId ?? resolveVertexProjectId();
|
|
2552
2499
|
if (projectId === void 0) {
|
|
2553
|
-
throw new
|
|
2500
|
+
throw new chunkIHFNRNTJ_cjs.ConfigurationError(
|
|
2554
2501
|
"Vertex requires a project id. Set GOOGLE_CLOUD_PROJECT env var or run `gcloud config set project <id>`.",
|
|
2555
2502
|
{ code: "auth_failed" }
|
|
2556
2503
|
);
|
|
@@ -2558,12 +2505,12 @@ var VertexGeminiClient = class {
|
|
|
2558
2505
|
const location = this.options.location ?? resolveVertexLocation();
|
|
2559
2506
|
const accessToken = this.options.apiKey !== void 0 && this.options.apiKey.length > 0 ? this.options.apiKey : await resolveVertexAccessToken();
|
|
2560
2507
|
if (accessToken === void 0 || accessToken.length === 0) {
|
|
2561
|
-
throw new
|
|
2508
|
+
throw new chunkIHFNRNTJ_cjs.ConfigurationError(
|
|
2562
2509
|
"Vertex could not resolve an access token. Run `gcloud auth application-default login` or set GOOGLE_APPLICATION_CREDENTIALS to a service-account JSON path.",
|
|
2563
2510
|
{ code: "auth_failed" }
|
|
2564
2511
|
);
|
|
2565
2512
|
}
|
|
2566
|
-
const baseUrl =
|
|
2513
|
+
const baseUrl = chunkG4XUXSRN_cjs.resolveVertexBaseUrl({ projectId, location, modelDialect: "gemini" });
|
|
2567
2514
|
const url = `${baseUrl}/chat/completions`;
|
|
2568
2515
|
const innerFetch = this.options.fetch ?? fetch;
|
|
2569
2516
|
const rewriteFetch = (input, init) => {
|
|
@@ -2589,7 +2536,7 @@ var VertexRouterClient = class {
|
|
|
2589
2536
|
options;
|
|
2590
2537
|
name = "vertex";
|
|
2591
2538
|
async *stream(request, signal) {
|
|
2592
|
-
const dialect =
|
|
2539
|
+
const dialect = chunkG4XUXSRN_cjs.inferModelDialect(request.model);
|
|
2593
2540
|
if (dialect === "anthropic") {
|
|
2594
2541
|
const inner2 = new VertexAnthropicClient(this.options);
|
|
2595
2542
|
return yield* inner2.stream(request, signal);
|
|
@@ -2601,7 +2548,7 @@ var VertexRouterClient = class {
|
|
|
2601
2548
|
|
|
2602
2549
|
// src/internal/llm/router.ts
|
|
2603
2550
|
function resolveProviderChain(options) {
|
|
2604
|
-
|
|
2551
|
+
chunkG4XUXSRN_cjs.registerBuiltins();
|
|
2605
2552
|
return buildChain(options);
|
|
2606
2553
|
}
|
|
2607
2554
|
function buildChain(options) {
|
|
@@ -2618,7 +2565,7 @@ function buildChain(options) {
|
|
|
2618
2565
|
addClient(options.primary);
|
|
2619
2566
|
for (const fallback of options.fallback ?? []) addClient(fallback);
|
|
2620
2567
|
if (clients.length === 0) {
|
|
2621
|
-
throw new
|
|
2568
|
+
throw new chunkIHFNRNTJ_cjs.ConfigurationError(
|
|
2622
2569
|
`No provider client could be resolved (primary=${options.primary}). Set ANTHROPIC_API_KEY or OPENAI_API_KEY / OPENROUTER_API_KEY.`,
|
|
2623
2570
|
{ code: "provider_unresolved" }
|
|
2624
2571
|
);
|
|
@@ -2626,11 +2573,11 @@ function buildChain(options) {
|
|
|
2626
2573
|
return clients;
|
|
2627
2574
|
}
|
|
2628
2575
|
function buildClient(name, routerOptions) {
|
|
2629
|
-
const baseProfile =
|
|
2576
|
+
const baseProfile = chunkG4XUXSRN_cjs.getProviderProfile(name);
|
|
2630
2577
|
if (baseProfile === void 0) return void 0;
|
|
2631
2578
|
const profile = routerOptions.extractToolCallsFromContent === true && baseProfile.extractToolCallsFromContent !== true ? { ...baseProfile, extractToolCallsFromContent: true } : baseProfile;
|
|
2632
2579
|
const resilience = routerOptions.onRateLimit !== void 0 ? { onRateLimit: routerOptions.onRateLimit } : {};
|
|
2633
|
-
const ambient =
|
|
2580
|
+
const ambient = chunkECW2MLEW_cjs.currentCredentialPool(name);
|
|
2634
2581
|
if (ambient !== void 0) {
|
|
2635
2582
|
return new RetryingLlmClient(
|
|
2636
2583
|
new PoolAwareLlmClient(
|
|
@@ -2660,9 +2607,9 @@ function buildPoolOrSingle(args) {
|
|
|
2660
2607
|
if (poolKeys !== void 0 && poolKeys.length >= 2) {
|
|
2661
2608
|
const strategy = routerOptions.credentialPoolStrategy?.[name] ?? "fill_first";
|
|
2662
2609
|
const entries = poolKeys.map(
|
|
2663
|
-
(accessToken, priority) =>
|
|
2610
|
+
(accessToken, priority) => chunkECW2MLEW_cjs.newPooledCredential({ provider: name, accessToken, priority, source: "manual" })
|
|
2664
2611
|
);
|
|
2665
|
-
const pool = new
|
|
2612
|
+
const pool = new chunkECW2MLEW_cjs.CredentialPool(name, entries, strategy);
|
|
2666
2613
|
const resilience = routerOptions.onRateLimit !== void 0 ? { onRateLimit: routerOptions.onRateLimit } : {};
|
|
2667
2614
|
return new RetryingLlmClient(
|
|
2668
2615
|
new PoolAwareLlmClient(
|
|
@@ -2697,7 +2644,7 @@ var warnedNoAuthApiKeys = /* @__PURE__ */ new Set();
|
|
|
2697
2644
|
function warnNoAuthApiKeysIgnoredOnce(provider) {
|
|
2698
2645
|
if (warnedNoAuthApiKeys.has(provider)) return;
|
|
2699
2646
|
warnedNoAuthApiKeys.add(provider);
|
|
2700
|
-
|
|
2647
|
+
chunkBCQ3E2ZG_cjs.diag(
|
|
2701
2648
|
`[theokit-sdk] provider "${provider}" has authType: "none" \u2014 apiKeys ignored (no auth required for local runtime).
|
|
2702
2649
|
`
|
|
2703
2650
|
);
|
|
@@ -2723,10 +2670,10 @@ function warnUnknownProvidersInApiKeys(apiKeys) {
|
|
|
2723
2670
|
if (apiKeys === void 0) return;
|
|
2724
2671
|
for (const name of Object.keys(apiKeys)) {
|
|
2725
2672
|
if (warnedProviders.has(name)) continue;
|
|
2726
|
-
const profile =
|
|
2673
|
+
const profile = chunkG4XUXSRN_cjs.getProviderProfile(name);
|
|
2727
2674
|
if (profile === void 0) {
|
|
2728
2675
|
warnedProviders.add(name);
|
|
2729
|
-
|
|
2676
|
+
chunkBCQ3E2ZG_cjs.diag(
|
|
2730
2677
|
`[theokit-sdk] credential-pool: unknown provider "${name}" in apiKeys (no profile registered)
|
|
2731
2678
|
`
|
|
2732
2679
|
);
|
|
@@ -2746,19 +2693,19 @@ function selectTransport(profile, apiKey) {
|
|
|
2746
2693
|
const ctx = { apiKey };
|
|
2747
2694
|
return { fetch: profile.transform.fetch?.(ctx), headers: profile.transform.headers?.(ctx) };
|
|
2748
2695
|
};
|
|
2749
|
-
const comTransform = (opts,
|
|
2696
|
+
const comTransform = (opts, construct) => {
|
|
2750
2697
|
const t = applyTransform();
|
|
2751
2698
|
assertOAuthResolved(t);
|
|
2752
2699
|
if (t.fetch !== void 0) opts.fetch = t.fetch;
|
|
2753
2700
|
const merged = profile.extraHeaders !== void 0 || t.headers !== void 0 ? { ...profile.extraHeaders, ...t.headers } : void 0;
|
|
2754
2701
|
if (merged !== void 0) opts.extraHeaders = merged;
|
|
2755
|
-
return
|
|
2702
|
+
return construct(opts);
|
|
2756
2703
|
};
|
|
2757
2704
|
const assertOAuthResolved = (t) => {
|
|
2758
2705
|
if (apiKey !== "__oauth_lazy_token__") return;
|
|
2759
2706
|
const auth = t.headers?.authorization ?? t.headers?.Authorization;
|
|
2760
2707
|
if (t.fetch === void 0 && auth === void 0) {
|
|
2761
|
-
throw new
|
|
2708
|
+
throw new chunkIHFNRNTJ_cjs.ConfigurationError(
|
|
2762
2709
|
`provider "${profile.name}" uses OAuth (authType: ${profile.authType}) but no credential was resolved. Register a ProviderProfile.transform whose fetch (or headers.authorization) supplies the bearer \u2014 typically via resolveCredential() from "@theokit/sdk/auth".`
|
|
2763
2710
|
);
|
|
2764
2711
|
}
|
|
@@ -2809,7 +2756,7 @@ function selectTransport(profile, apiKey) {
|
|
|
2809
2756
|
providerName: profile.name
|
|
2810
2757
|
});
|
|
2811
2758
|
}
|
|
2812
|
-
throw new
|
|
2759
|
+
throw new chunkIHFNRNTJ_cjs.ConfigurationError(
|
|
2813
2760
|
`Provider "${profile.name}" requires apiMode "${profile.apiMode}" but no transport is registered. Install a third-party transport plugin (@theokit-transport-${profile.apiMode}) or use a provider with apiMode "chat_completions" or "anthropic_messages".`,
|
|
2814
2761
|
{ code: "transport_unavailable" }
|
|
2815
2762
|
);
|
|
@@ -2824,7 +2771,7 @@ function inferProviderFromApiKey(apiKey) {
|
|
|
2824
2771
|
{ provider: "openai", prefix: "sk-" }
|
|
2825
2772
|
];
|
|
2826
2773
|
for (const { provider, prefix } of byPrefix) {
|
|
2827
|
-
if (apiKey.startsWith(prefix) &&
|
|
2774
|
+
if (apiKey.startsWith(prefix) && chunkG4XUXSRN_cjs.getProviderProfile(provider) !== void 0) {
|
|
2828
2775
|
return provider;
|
|
2829
2776
|
}
|
|
2830
2777
|
}
|
|
@@ -2963,7 +2910,7 @@ function plainText(content) {
|
|
|
2963
2910
|
}
|
|
2964
2911
|
async function compactSessionTranscript(opts) {
|
|
2965
2912
|
const prior = await opts.store.readRecords(opts.loc.agentId);
|
|
2966
|
-
const history =
|
|
2913
|
+
const history = chunkZ2CUEBXV_cjs.reconstructMessages(prior);
|
|
2967
2914
|
const compressible = [];
|
|
2968
2915
|
for (const m of history) {
|
|
2969
2916
|
const text = plainText(m.content);
|
|
@@ -2971,14 +2918,14 @@ async function compactSessionTranscript(opts) {
|
|
|
2971
2918
|
compressible.push({ role: m.role, content: text });
|
|
2972
2919
|
}
|
|
2973
2920
|
}
|
|
2974
|
-
const preTokens =
|
|
2921
|
+
const preTokens = chunkJ6T5LWJ4_cjs.estimateTokens(compressible.map((m) => m.content).join("\n"));
|
|
2975
2922
|
const summaryBody = await opts.summarize(compressible);
|
|
2976
2923
|
const preserved = [];
|
|
2977
2924
|
let budget = 0;
|
|
2978
2925
|
for (let i = compressible.length - 1; i >= 0; i--) {
|
|
2979
2926
|
const m = compressible[i];
|
|
2980
2927
|
if (m === void 0 || m.role !== "user" || isCompactSummary(m.content)) continue;
|
|
2981
|
-
const cost =
|
|
2928
|
+
const cost = chunkJ6T5LWJ4_cjs.estimateTokens(m.content);
|
|
2982
2929
|
if (budget + cost > COMPACT_USER_MESSAGE_MAX_TOKENS) {
|
|
2983
2930
|
const remaining = COMPACT_USER_MESSAGE_MAX_TOKENS - budget;
|
|
2984
2931
|
if (remaining > 50) {
|
|
@@ -2992,7 +2939,7 @@ async function compactSessionTranscript(opts) {
|
|
|
2992
2939
|
}
|
|
2993
2940
|
const summary = `${COMPACT_SUMMARY_MARKER}
|
|
2994
2941
|
${summaryBody}`;
|
|
2995
|
-
const transcript =
|
|
2942
|
+
const transcript = chunkZ2CUEBXV_cjs.SessionTranscript.fromRecords(prior, {
|
|
2996
2943
|
cwd: opts.loc.cwd,
|
|
2997
2944
|
sessionId: opts.sessionId,
|
|
2998
2945
|
model: opts.loc.model ?? "unknown"
|
|
@@ -3002,8 +2949,8 @@ ${summaryBody}`;
|
|
|
3002
2949
|
transcript.appendUserTurn(summary);
|
|
3003
2950
|
const delta = transcript.records().slice(prior.length);
|
|
3004
2951
|
await opts.store.appendRecords(opts.loc.agentId, delta);
|
|
3005
|
-
|
|
3006
|
-
const postTokens =
|
|
2952
|
+
chunkBURYFNOM_cjs.invalidateSessionCache(opts.loc.cwd, opts.loc.agentId);
|
|
2953
|
+
const postTokens = chunkJ6T5LWJ4_cjs.estimateTokens([...preserved, summary].join("\n"));
|
|
3007
2954
|
return { preTokens, postTokens };
|
|
3008
2955
|
}
|
|
3009
2956
|
function resolveSummarizerRoute(opts) {
|
|
@@ -3012,9 +2959,9 @@ function resolveSummarizerRoute(opts) {
|
|
|
3012
2959
|
}
|
|
3013
2960
|
function buildDefaultSummarizer(opts) {
|
|
3014
2961
|
return async (messages) => {
|
|
3015
|
-
|
|
2962
|
+
chunkG4XUXSRN_cjs.registerBuiltins();
|
|
3016
2963
|
const modelPrefix = opts.agentModel.includes("/") ? opts.agentModel.slice(0, opts.agentModel.indexOf("/")) : void 0;
|
|
3017
|
-
const prefixProfile = modelPrefix !== void 0 ?
|
|
2964
|
+
const prefixProfile = modelPrefix !== void 0 ? chunkG4XUXSRN_cjs.getProviderProfile(modelPrefix) : void 0;
|
|
3018
2965
|
const prefixUsable = prefixProfile !== void 0 && (prefixProfile.authType !== "api_key" || prefixProfile.envVars.some((v) => (process.env[v] ?? "").length > 0));
|
|
3019
2966
|
const route = resolveSummarizerRoute({
|
|
3020
2967
|
keyProvider: inferProviderFromApiKey(opts.apiKey),
|
|
@@ -3085,7 +3032,7 @@ async function autoCompactIfNeeded(opts) {
|
|
|
3085
3032
|
return true;
|
|
3086
3033
|
} catch (cause) {
|
|
3087
3034
|
const msg = cause instanceof Error ? cause.message : String(cause);
|
|
3088
|
-
|
|
3035
|
+
chunkBCQ3E2ZG_cjs.diag(`[theokit-sdk] auto-compaction failed (left transcript untouched): ${msg}
|
|
3089
3036
|
`);
|
|
3090
3037
|
return false;
|
|
3091
3038
|
}
|
|
@@ -3106,7 +3053,6 @@ exports.isCompactSummary = isCompactSummary;
|
|
|
3106
3053
|
exports.isFixtureApiKey = isFixtureApiKey;
|
|
3107
3054
|
exports.mapOllamaHttpError = mapOllamaHttpError;
|
|
3108
3055
|
exports.mapOllamaTransportError = mapOllamaTransportError;
|
|
3109
|
-
exports.mapOpenAICompatibleError = mapOpenAICompatibleError;
|
|
3110
3056
|
exports.parseSseStream = parseSseStream;
|
|
3111
3057
|
exports.readErrorResponseBody = readErrorResponseBody;
|
|
3112
3058
|
exports.relayStream = relayStream;
|
|
@@ -3117,5 +3063,5 @@ exports.shouldAutoCompact = shouldAutoCompact;
|
|
|
3117
3063
|
exports.shouldUseFixtureMode = shouldUseFixtureMode;
|
|
3118
3064
|
exports.shouldUseRealLocalRuntime = shouldUseRealLocalRuntime;
|
|
3119
3065
|
exports.tryFirstEvent = tryFirstEvent;
|
|
3120
|
-
//# sourceMappingURL=chunk-
|
|
3121
|
-
//# sourceMappingURL=chunk-
|
|
3066
|
+
//# sourceMappingURL=chunk-BPN5ONSW.cjs.map
|
|
3067
|
+
//# sourceMappingURL=chunk-BPN5ONSW.cjs.map
|