@theokit/sdk 4.63.4 → 5.0.0-next.2
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 +847 -23
- package/dist/a2a/index.cjs +29 -13
- package/dist/a2a/index.cjs.map +1 -1
- package/dist/a2a/index.d.cts +1 -1
- package/dist/a2a/index.d.ts +1 -1
- package/dist/a2a/index.js +26 -11
- package/dist/a2a/index.js.map +1 -1
- package/dist/a2a/message-bus.d.cts +26 -3
- package/dist/a2a/message-bus.d.ts +26 -3
- package/dist/a2a/subagent.d.cts +8 -3
- package/dist/a2a/subagent.d.ts +8 -3
- package/dist/{agent-X0DKA943.d.cts → agent-C3KO5LKm.d.cts} +251 -36
- package/dist/{agent-BFno7Sfn.d.ts → agent-CvmTR9uf.d.ts} +251 -36
- package/dist/agent-GPV2JWZG.cjs +67 -0
- package/dist/{agent-UX7WFI6B.cjs.map → agent-GPV2JWZG.cjs.map} +1 -1
- package/dist/agent-Y24I5JBM.js +58 -0
- package/dist/{agent-A5XMIVNP.js.map → agent-Y24I5JBM.js.map} +1 -1
- package/dist/agent-session-store-AFML3AXC.js +6 -0
- package/dist/{agent-session-store-OPGRB4XM.js.map → agent-session-store-AFML3AXC.js.map} +1 -1
- package/dist/agent-session-store-MTSIY3MH.cjs +23 -0
- package/dist/{agent-session-store-6EL5NPA4.cjs.map → agent-session-store-MTSIY3MH.cjs.map} +1 -1
- package/dist/agent.d.ts +1 -1
- package/dist/auth/index.cjs +33 -34
- package/dist/auth/index.cjs.map +1 -1
- package/dist/auth/index.d.cts +1 -1
- package/dist/auth/index.d.ts +1 -1
- package/dist/auth/index.js +6 -7
- package/dist/auth/index.js.map +1 -1
- package/dist/{batch-BXYTW2DP.cjs → batch-I6T6MXZO.cjs} +58 -40
- package/dist/batch-I6T6MXZO.cjs.map +1 -0
- package/dist/{batch-L4ZXS46M.js → batch-US4F6WPK.js} +42 -24
- package/dist/batch-US4F6WPK.js.map +1 -0
- package/dist/chunk-24MGQDK3.js +31 -0
- package/dist/chunk-24MGQDK3.js.map +1 -0
- package/dist/{chunk-UGT7GK7I.cjs → chunk-24SYBZPL.cjs} +36 -18
- package/dist/chunk-24SYBZPL.cjs.map +1 -0
- package/dist/{chunk-KYAJINUI.cjs → chunk-2HPNT6HH.cjs} +581 -401
- package/dist/chunk-2HPNT6HH.cjs.map +1 -0
- package/dist/{chunk-VLVVJLDH.cjs → chunk-2NE7DTOK.cjs} +234 -193
- package/dist/chunk-2NE7DTOK.cjs.map +1 -0
- package/dist/{chunk-N2U4AZGB.js → chunk-2WXHA33T.js} +3 -3
- package/dist/chunk-2WXHA33T.js.map +1 -0
- package/dist/chunk-2XC6KDJM.js +22 -0
- package/dist/chunk-2XC6KDJM.js.map +1 -0
- package/dist/{chunk-L3MTL4NA.js → chunk-2ZLVT7H3.js} +223 -182
- package/dist/chunk-2ZLVT7H3.js.map +1 -0
- package/dist/{chunk-2GUYQR5P.js → chunk-3JHIFQ4I.js} +39 -13
- package/dist/chunk-3JHIFQ4I.js.map +1 -0
- package/dist/{chunk-BU4KFWXF.js → chunk-44I6UYVH.js} +8 -17
- package/dist/chunk-44I6UYVH.js.map +1 -0
- package/dist/{chunk-UNYXQ4M5.js → chunk-47TF32NQ.js} +10 -5
- package/dist/chunk-47TF32NQ.js.map +1 -0
- package/dist/{chunk-WNO3C3N2.cjs → chunk-4A3SKJ53.cjs} +56 -27
- package/dist/chunk-4A3SKJ53.cjs.map +1 -0
- package/dist/{chunk-YML4ME27.cjs → chunk-4HS6FFGL.cjs} +55 -46
- package/dist/chunk-4HS6FFGL.cjs.map +1 -0
- package/dist/{chunk-C72AZW7J.js → chunk-4MMWFSCD.js} +4 -4
- package/dist/chunk-4MMWFSCD.js.map +1 -0
- package/dist/{chunk-6HKGLTJI.cjs → chunk-4NLCWGH7.cjs} +15 -15
- package/dist/chunk-4NLCWGH7.cjs.map +1 -0
- package/dist/{chunk-LKBEROHN.js → chunk-4S5TWFIZ.js} +14 -14
- package/dist/chunk-4S5TWFIZ.js.map +1 -0
- package/dist/{chunk-UBDMVMBZ.js → chunk-55GB6JYQ.js} +33 -22
- package/dist/chunk-55GB6JYQ.js.map +1 -0
- package/dist/{chunk-U6IFHFWK.js → chunk-5WKQDIGO.js} +8 -17
- package/dist/chunk-5WKQDIGO.js.map +1 -0
- package/dist/chunk-67ADYSTW.js +120 -0
- package/dist/chunk-67ADYSTW.js.map +1 -0
- package/dist/{chunk-XL7Q7HB2.cjs → chunk-6LHQPOMI.cjs} +39 -6
- package/dist/chunk-6LHQPOMI.cjs.map +1 -0
- package/dist/{chunk-A4JVILQU.js → chunk-6M2OIS4Y.js} +7 -7
- package/dist/chunk-6M2OIS4Y.js.map +1 -0
- package/dist/{chunk-LWGSI6M3.js → chunk-6PWOWXMC.js} +4 -4
- package/dist/{chunk-LWGSI6M3.js.map → chunk-6PWOWXMC.js.map} +1 -1
- package/dist/{chunk-RNB4APBZ.js → chunk-6WAKKTBO.js} +9 -5
- package/dist/chunk-6WAKKTBO.js.map +1 -0
- package/dist/{chunk-V2BOS4WF.cjs → chunk-7A6535RA.cjs} +11 -11
- package/dist/chunk-7A6535RA.cjs.map +1 -0
- package/dist/{chunk-ZLQSWSJ2.cjs → chunk-7FDKWDA2.cjs} +11 -11
- package/dist/{chunk-ZLQSWSJ2.cjs.map → chunk-7FDKWDA2.cjs.map} +1 -1
- package/dist/{chunk-4VPXM6UU.js → chunk-7I5Z3UBJ.js} +3 -3
- package/dist/{chunk-4VPXM6UU.js.map → chunk-7I5Z3UBJ.js.map} +1 -1
- package/dist/{chunk-B4EOJWOY.cjs → chunk-7JJ3A6AT.cjs} +13 -7
- package/dist/chunk-7JJ3A6AT.cjs.map +1 -0
- package/dist/{chunk-WJVHMTKB.cjs → chunk-AA27GEYS.cjs} +3 -3
- package/dist/{chunk-WJVHMTKB.cjs.map → chunk-AA27GEYS.cjs.map} +1 -1
- package/dist/{chunk-BP46RJ5X.js → chunk-AAEZSPTC.js} +5 -5
- package/dist/{chunk-BP46RJ5X.js.map → chunk-AAEZSPTC.js.map} +1 -1
- package/dist/chunk-AGACYRJ2.js +11 -0
- package/dist/chunk-AGACYRJ2.js.map +1 -0
- package/dist/{chunk-ZZMZWBR6.js → chunk-ALUN2B4W.js} +81 -58
- package/dist/chunk-ALUN2B4W.js.map +1 -0
- package/dist/chunk-ANMJJD6D.cjs +18 -0
- package/dist/chunk-ANMJJD6D.cjs.map +1 -0
- package/dist/{chunk-DXGZ2NUG.cjs → chunk-ATT276RD.cjs} +12 -11
- package/dist/chunk-ATT276RD.cjs.map +1 -0
- package/dist/{chunk-4FFBAUFS.js → chunk-AWINL3ZC.js} +6 -6
- package/dist/chunk-AWINL3ZC.js.map +1 -0
- package/dist/{chunk-UU36SHFY.cjs → chunk-BJUJT5ED.cjs} +9 -8
- package/dist/chunk-BJUJT5ED.cjs.map +1 -0
- package/dist/{chunk-D4CUGAKZ.js → chunk-CZJ6Q7CW.js} +36 -6
- package/dist/chunk-CZJ6Q7CW.js.map +1 -0
- package/dist/{chunk-KQ7TS7WW.cjs → chunk-D6POWE7E.cjs} +37 -26
- package/dist/chunk-D6POWE7E.cjs.map +1 -0
- package/dist/{chunk-AWO27VRZ.js → chunk-DMRT67Y6.js} +6 -5
- package/dist/chunk-DMRT67Y6.js.map +1 -0
- package/dist/{chunk-5VB22SYX.cjs → chunk-DQZU7JK6.cjs} +7 -7
- package/dist/{chunk-5VB22SYX.cjs.map → chunk-DQZU7JK6.cjs.map} +1 -1
- package/dist/{chunk-3NSS2OIZ.cjs → chunk-DRL7URI4.cjs} +6 -6
- package/dist/{chunk-3NSS2OIZ.cjs.map → chunk-DRL7URI4.cjs.map} +1 -1
- package/dist/{chunk-RFXWMRFC.js → chunk-EFMFILPG.js} +14 -6
- package/dist/chunk-EFMFILPG.js.map +1 -0
- package/dist/{chunk-HS7AVXTF.js → chunk-EH6XD3FY.js} +4 -4
- package/dist/chunk-EH6XD3FY.js.map +1 -0
- package/dist/{chunk-KQRW2GPZ.js → chunk-EIQFAOFD.js} +6 -6
- package/dist/chunk-EIQFAOFD.js.map +1 -0
- package/dist/{chunk-XJCXEKMD.cjs → chunk-EXTRW7GW.cjs} +4 -4
- package/dist/chunk-EXTRW7GW.cjs.map +1 -0
- package/dist/{chunk-U54XCYG3.js → chunk-FJWQP6EE.js} +12 -6
- package/dist/chunk-FJWQP6EE.js.map +1 -0
- package/dist/{chunk-O7DK5PBJ.cjs → chunk-FUSDYC2B.cjs} +26 -42
- package/dist/chunk-FUSDYC2B.cjs.map +1 -0
- package/dist/{chunk-4QZSA2HJ.js → chunk-G7BLGBRN.js} +4 -4
- package/dist/chunk-G7BLGBRN.js.map +1 -0
- package/dist/{chunk-BZRFXJHA.js → chunk-GBCVPKHE.js} +55 -26
- package/dist/chunk-GBCVPKHE.js.map +1 -0
- package/dist/chunk-GGZ5GPE3.cjs +130 -0
- package/dist/chunk-GGZ5GPE3.cjs.map +1 -0
- package/dist/{chunk-5HEG4CQH.cjs → chunk-GZV6AVRL.cjs} +8 -8
- package/dist/{chunk-5HEG4CQH.cjs.map → chunk-GZV6AVRL.cjs.map} +1 -1
- package/dist/{chunk-VCLBZAZU.cjs → chunk-H6YM3PV6.cjs} +17 -17
- package/dist/chunk-H6YM3PV6.cjs.map +1 -0
- package/dist/{chunk-RFMBZPOW.cjs → chunk-HCT4HPCL.cjs} +10 -10
- package/dist/chunk-HCT4HPCL.cjs.map +1 -0
- package/dist/{chunk-OSEG74VJ.js → chunk-HFEJE7AC.js} +52 -43
- package/dist/chunk-HFEJE7AC.js.map +1 -0
- package/dist/{chunk-52NKC5HT.cjs → chunk-HUFSABUZ.cjs} +12 -8
- package/dist/chunk-HUFSABUZ.cjs.map +1 -0
- package/dist/{chunk-4CLOXP6H.cjs → chunk-HW7SEELD.cjs} +4 -4
- package/dist/{chunk-4CLOXP6H.cjs.map → chunk-HW7SEELD.cjs.map} +1 -1
- package/dist/{chunk-ZSWPZ23K.cjs → chunk-I2PWY7VM.cjs} +5 -5
- package/dist/chunk-I2PWY7VM.cjs.map +1 -0
- package/dist/{chunk-VJ26EKGJ.cjs → chunk-IJ7M6GOG.cjs} +3 -3
- package/dist/chunk-IJ7M6GOG.cjs.map +1 -0
- package/dist/{chunk-SAVIWMZB.js → chunk-ILGZ2ZZV.js} +3 -3
- package/dist/chunk-ILGZ2ZZV.js.map +1 -0
- package/dist/{chunk-4ZHTIJNE.cjs → chunk-J7J7J2GN.cjs} +87 -63
- package/dist/chunk-J7J7J2GN.cjs.map +1 -0
- package/dist/{chunk-UALX2J2Q.cjs → chunk-JLRLCBJ4.cjs} +38 -11
- package/dist/chunk-JLRLCBJ4.cjs.map +1 -0
- package/dist/{chunk-2QDYBS2A.js → chunk-JMDDYA22.js} +4 -4
- package/dist/chunk-JMDDYA22.js.map +1 -0
- package/dist/{chunk-LXQ6HKPS.js → chunk-JNAA4G4H.js} +3 -3
- package/dist/{chunk-LXQ6HKPS.js.map → chunk-JNAA4G4H.js.map} +1 -1
- package/dist/{chunk-UMP6OJIM.js → chunk-JOFVLOFY.js} +4 -4
- package/dist/{chunk-UMP6OJIM.js.map → chunk-JOFVLOFY.js.map} +1 -1
- package/dist/{chunk-A46SWMIF.js → chunk-K2VMFZQ5.js} +7 -7
- package/dist/chunk-K2VMFZQ5.js.map +1 -0
- package/dist/{chunk-DN2PACRI.js → chunk-K3NH62DG.js} +461 -282
- package/dist/chunk-K3NH62DG.js.map +1 -0
- package/dist/{chunk-LYTOXSRH.js → chunk-KDR53EO7.js} +1939 -1864
- package/dist/chunk-KDR53EO7.js.map +1 -0
- package/dist/{chunk-XWTLIGO3.cjs → chunk-KTTHHYEW.cjs} +5 -5
- package/dist/chunk-KTTHHYEW.cjs.map +1 -0
- package/dist/{chunk-3FFAEAUJ.cjs → chunk-KVSAY6NZ.cjs} +18 -18
- package/dist/chunk-KVSAY6NZ.cjs.map +1 -0
- package/dist/{chunk-IAHZCGBE.cjs → chunk-LHSWHYF3.cjs} +120 -146
- package/dist/chunk-LHSWHYF3.cjs.map +1 -0
- package/dist/{chunk-3OR54XG4.js → chunk-NJWYQWDL.js} +12 -8
- package/dist/chunk-NJWYQWDL.js.map +1 -0
- package/dist/chunk-NVXXWAU7.cjs +13 -0
- package/dist/chunk-NVXXWAU7.cjs.map +1 -0
- package/dist/{chunk-2D34UTDC.js → chunk-O6USDERH.js} +31 -11
- package/dist/chunk-O6USDERH.js.map +1 -0
- package/dist/{chunk-XO4SOZN6.js → chunk-OR6XIWLB.js} +4 -4
- package/dist/{chunk-XO4SOZN6.js.map → chunk-OR6XIWLB.js.map} +1 -1
- package/dist/{chunk-4PYZ5AX3.cjs → chunk-PRZ3BES7.cjs} +16 -8
- package/dist/chunk-PRZ3BES7.cjs.map +1 -0
- package/dist/{chunk-HCZD23VS.cjs → chunk-QC55H6RJ.cjs} +65 -39
- package/dist/chunk-QC55H6RJ.cjs.map +1 -0
- package/dist/{chunk-4O5TGQBW.cjs → chunk-QME6FDFG.cjs} +9 -5
- package/dist/chunk-QME6FDFG.cjs.map +1 -0
- package/dist/chunk-QOGNZMHD.cjs +34 -0
- package/dist/chunk-QOGNZMHD.cjs.map +1 -0
- package/dist/{chunk-7VT4P3Z4.cjs → chunk-QUAEOKDW.cjs} +1642 -1567
- package/dist/chunk-QUAEOKDW.cjs.map +1 -0
- package/dist/{chunk-B2J4ZMZL.cjs → chunk-QWD3CZWE.cjs} +6 -5
- package/dist/chunk-QWD3CZWE.cjs.map +1 -0
- package/dist/{chunk-SZVR77EJ.cjs → chunk-QWD4RDZ3.cjs} +15 -24
- package/dist/chunk-QWD4RDZ3.cjs.map +1 -0
- package/dist/{chunk-7BG5UH3T.cjs → chunk-RHZ6HP23.cjs} +4 -4
- package/dist/chunk-RHZ6HP23.cjs.map +1 -0
- package/dist/{chunk-2HVF2WJY.cjs → chunk-RQMCOFAI.cjs} +8 -8
- package/dist/{chunk-2HVF2WJY.cjs.map → chunk-RQMCOFAI.cjs.map} +1 -1
- package/dist/{chunk-VKJ7V7EB.cjs → chunk-SA6K24NB.cjs} +3 -3
- package/dist/chunk-SA6K24NB.cjs.map +1 -0
- package/dist/{chunk-7AD3ZTZL.js → chunk-SAGRF4IB.js} +3 -3
- package/dist/chunk-SAGRF4IB.js.map +1 -0
- package/dist/{chunk-PUAEFLYK.js → chunk-SVQIW5RJ.js} +4 -4
- package/dist/{chunk-PUAEFLYK.js.map → chunk-SVQIW5RJ.js.map} +1 -1
- package/dist/{chunk-43ZQRWAP.cjs → chunk-SYVWE64W.cjs} +22 -22
- package/dist/chunk-SYVWE64W.cjs.map +1 -0
- package/dist/{chunk-3O42QOMJ.js → chunk-TA3K7SBK.js} +7 -6
- package/dist/chunk-TA3K7SBK.js.map +1 -0
- package/dist/{chunk-LYRDF5TQ.cjs → chunk-TFG5IBZS.cjs} +14 -23
- package/dist/chunk-TFG5IBZS.cjs.map +1 -0
- package/dist/{chunk-GKEFRLU7.cjs → chunk-TMKTSYDS.cjs} +6 -6
- package/dist/{chunk-GKEFRLU7.cjs.map → chunk-TMKTSYDS.cjs.map} +1 -1
- package/dist/{chunk-J24VJOH3.cjs → chunk-UADQJBHR.cjs} +31 -11
- package/dist/chunk-UADQJBHR.cjs.map +1 -0
- package/dist/{chunk-TAZVKYWJ.js → chunk-UBR5PWD7.js} +26 -40
- package/dist/chunk-UBR5PWD7.js.map +1 -0
- package/dist/{chunk-IPYYKCRC.js → chunk-UFPUHJWS.js} +5 -5
- package/dist/{chunk-IPYYKCRC.js.map → chunk-UFPUHJWS.js.map} +1 -1
- package/dist/{chunk-OHLDPWTA.cjs → chunk-UGRS7ZA7.cjs} +15 -15
- package/dist/{chunk-OHLDPWTA.cjs.map → chunk-UGRS7ZA7.cjs.map} +1 -1
- package/dist/{chunk-RIAM53CP.js → chunk-UKMBRMGT.js} +3 -3
- package/dist/chunk-UKMBRMGT.js.map +1 -0
- package/dist/{chunk-L4BDVXIM.js → chunk-UNK4HNJH.js} +97 -123
- package/dist/chunk-UNK4HNJH.js.map +1 -0
- package/dist/{chunk-C3NT3PVE.js → chunk-V22DZIXO.js} +3 -3
- package/dist/chunk-V22DZIXO.js.map +1 -0
- package/dist/{chunk-OFRFZRQ4.cjs → chunk-V6ZY4AX6.cjs} +24 -14
- package/dist/chunk-V6ZY4AX6.cjs.map +1 -0
- package/dist/{chunk-B3IMEBOA.js → chunk-VE6DFSKU.js} +3 -3
- package/dist/{chunk-B3IMEBOA.js.map → chunk-VE6DFSKU.js.map} +1 -1
- package/dist/{chunk-WLQNMXQE.js → chunk-VWUXIVEI.js} +53 -26
- package/dist/chunk-VWUXIVEI.js.map +1 -0
- package/dist/{chunk-GMLBYDW4.cjs → chunk-VXDEKILY.cjs} +108 -109
- package/dist/chunk-VXDEKILY.cjs.map +1 -0
- package/dist/{chunk-ACDLHN3W.js → chunk-WJXOICRC.js} +16 -6
- package/dist/chunk-WJXOICRC.js.map +1 -0
- package/dist/{chunk-7YGCPMGB.js → chunk-XB4GI5RZ.js} +27 -12
- package/dist/chunk-XB4GI5RZ.js.map +1 -0
- package/dist/{chunk-O73J46PV.js → chunk-XDANGA2C.js} +5 -5
- package/dist/{chunk-O73J46PV.js.map → chunk-XDANGA2C.js.map} +1 -1
- package/dist/{chunk-NDGGJQTZ.js → chunk-XJZEBGXD.js} +10 -10
- package/dist/chunk-XJZEBGXD.js.map +1 -0
- package/dist/{chunk-UTSRIDKZ.js → chunk-XYFGKVZ7.js} +3 -3
- package/dist/chunk-XYFGKVZ7.js.map +1 -0
- package/dist/{chunk-RMWTPV3M.cjs → chunk-Y2KYR2ED.cjs} +27 -27
- package/dist/chunk-Y2KYR2ED.cjs.map +1 -0
- package/dist/{chunk-O7LZFG6O.cjs → chunk-YIFFF23U.cjs} +5 -5
- package/dist/chunk-YIFFF23U.cjs.map +1 -0
- package/dist/{chunk-4OTIXDMU.cjs → chunk-YJNYDJ2T.cjs} +12 -4
- package/dist/chunk-YJNYDJ2T.cjs.map +1 -0
- package/dist/{chunk-6JSIEDKL.cjs → chunk-YSTXFWQE.cjs} +13 -7
- package/dist/chunk-YSTXFWQE.cjs.map +1 -0
- package/dist/{chunk-I6HGWHPU.cjs → chunk-Z3NTRKIC.cjs} +4 -4
- package/dist/{chunk-I6HGWHPU.cjs.map → chunk-Z3NTRKIC.cjs.map} +1 -1
- package/dist/{chunk-32WTYBUH.js → chunk-ZH26RNQA.js} +91 -92
- package/dist/chunk-ZH26RNQA.js.map +1 -0
- package/dist/compact-session-BHTPCIHA.cjs +61 -0
- package/dist/{compact-session-QV57KR66.cjs.map → compact-session-BHTPCIHA.cjs.map} +1 -1
- package/dist/compact-session-W4WLJTHA.js +24 -0
- package/dist/{compact-session-RIGOWC4Y.js.map → compact-session-W4WLJTHA.js.map} +1 -1
- package/dist/compaction.cjs +20 -17
- package/dist/compaction.d.cts +15 -1
- package/dist/compaction.d.ts +15 -1
- package/dist/compaction.js +3 -4
- package/dist/concurrency.cjs +6 -7
- package/dist/concurrency.cjs.map +1 -1
- package/dist/concurrency.d.cts +6 -3
- package/dist/concurrency.d.ts +6 -3
- package/dist/concurrency.js +4 -5
- package/dist/concurrency.js.map +1 -1
- package/dist/context/index.cjs +6 -6
- package/dist/context/index.js +3 -3
- package/dist/context-NI33FS2R.cjs +23 -0
- package/dist/{context-WFLTTMK3.cjs.map → context-NI33FS2R.cjs.map} +1 -1
- package/dist/context-Y7B7SI5X.js +6 -0
- package/dist/{context-WI2DFG7V.js.map → context-Y7B7SI5X.js.map} +1 -1
- package/dist/create-skill.d.ts +4 -1
- package/dist/{cron-BuiRPrvt.d.cts → cron-C3PhZED0.d.cts} +8 -2
- package/dist/{cron-C2SIi31n.d.ts → cron-crfMMdAw.d.ts} +8 -2
- package/dist/cron.cjs +46 -45
- package/dist/cron.d.cts +5 -4
- package/dist/cron.d.ts +5 -4
- package/dist/cron.js +45 -44
- package/dist/{errors-BgJH9PHi.d.cts → errors-CLOAyuiv.d.ts} +133 -95
- package/dist/{errors-C5fJUqLk.d.ts → errors-DrDEgyz1.d.cts} +133 -95
- package/dist/errors-base-B5g01neU.d.cts +75 -0
- package/dist/errors-base-B5g01neU.d.ts +75 -0
- package/dist/errors-base.d.ts +73 -0
- package/dist/errors.cjs +25 -22
- package/dist/errors.d.cts +3 -2
- package/dist/errors.d.ts +3 -2
- package/dist/errors.js +2 -3
- package/dist/eval.cjs +74 -78
- package/dist/eval.cjs.map +1 -1
- package/dist/eval.js +64 -68
- package/dist/eval.js.map +1 -1
- package/dist/{executor-6CYCA7MI.cjs → executor-XQAOQOHD.cjs} +60 -54
- package/dist/executor-XQAOQOHD.cjs.map +1 -0
- package/dist/{executor-QSEC3MRH.js → executor-ZNDQDX6Q.js} +43 -37
- package/dist/executor-ZNDQDX6Q.js.map +1 -0
- package/dist/filesystem/index.cjs +24 -26
- package/dist/filesystem/index.cjs.map +1 -1
- package/dist/filesystem/index.js +20 -22
- package/dist/filesystem/index.js.map +1 -1
- package/dist/filesystem/types.d.cts +11 -5
- package/dist/filesystem/types.d.ts +11 -5
- package/dist/{fork-agent-RSV4E3EA.js → fork-agent-S2EPIML7.js} +3 -3
- package/dist/fork-agent-S2EPIML7.js.map +1 -0
- package/dist/{fork-agent-Y2IK2RYU.cjs → fork-agent-WAEQI2DL.cjs} +4 -4
- package/dist/fork-agent-WAEQI2DL.cjs.map +1 -0
- package/dist/fs-session-store-77JU46UZ.js +10 -0
- package/dist/{fs-session-store-NM6YSTE2.js.map → fs-session-store-77JU46UZ.js.map} +1 -1
- package/dist/fs-session-store-E4U3P56L.cjs +19 -0
- package/dist/{fs-session-store-4PIHT5UX.cjs.map → fs-session-store-E4U3P56L.cjs.map} +1 -1
- package/dist/generate-object-BXV7BZRP.js +7 -0
- package/dist/{generate-object-GUNAUVBX.js.map → generate-object-BXV7BZRP.js.map} +1 -1
- package/dist/generate-object-YBI2TDJ3.cjs +20 -0
- package/dist/{generate-object-R7HTMW7F.cjs.map → generate-object-YBI2TDJ3.cjs.map} +1 -1
- package/dist/generate-object.d.ts +2 -4
- package/dist/index-manager-DXR2RSFI.cjs +26 -0
- package/dist/{index-manager-2SRX45WJ.cjs.map → index-manager-DXR2RSFI.cjs.map} +1 -1
- package/dist/index-manager-QH6OXEV5.js +17 -0
- package/dist/{index-manager-SP4ISSDX.js.map → index-manager-QH6OXEV5.js.map} +1 -1
- package/dist/index.cjs +234 -194
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +243 -41
- package/dist/index.d.ts +243 -41
- package/dist/index.js +140 -102
- package/dist/index.js.map +1 -1
- package/dist/{inject-session-DAR7OUCW.js → inject-session-SUM6TDJF.js} +9 -9
- package/dist/{inject-session-DAR7OUCW.js.map → inject-session-SUM6TDJF.js.map} +1 -1
- package/dist/inject-session-W6A46J3E.cjs +29 -0
- package/dist/{inject-session-WQKMC3GR.cjs.map → inject-session-W6A46J3E.cjs.map} +1 -1
- package/dist/interactive/index.cjs +12 -6
- package/dist/interactive/index.cjs.map +1 -1
- package/dist/interactive/index.js +12 -6
- package/dist/interactive/index.js.map +1 -1
- package/dist/interactive/types.d.cts +14 -4
- package/dist/interactive/types.d.ts +14 -4
- package/dist/internal/agent-loop/loop-context-init.d.ts +1 -1
- package/dist/internal/agent-loop/loop-finalize.d.ts +25 -0
- package/dist/internal/agent-loop/loop.d.ts +1 -1
- package/dist/internal/agent-loop/message-builders.d.ts +1 -1
- package/dist/internal/agent-loop/tool-dispatch.d.ts +2 -2
- package/dist/internal/agent-loop/usage-and-cost.d.ts +1 -1
- package/dist/internal/auth/credential-availability.d.ts +61 -0
- package/dist/internal/auth/credential-store.d.ts +1 -1
- package/dist/internal/auth/oauth-device.d.ts +1 -1
- package/dist/internal/auth/oauth-engine.d.ts +1 -1
- package/dist/internal/auth/resolve-credential.d.ts +1 -1
- package/dist/internal/base-url.d.ts +14 -0
- package/dist/internal/cloud-agent/cloud-config-serializer.d.ts +1 -1
- package/dist/internal/{runtime/concurrency → concurrency}/subagent-credentials.d.ts +2 -2
- package/dist/internal/emit-run-event.d.ts +16 -0
- package/dist/internal/error-mappers/shared.d.ts +14 -1
- package/dist/internal/eval/assert.d.ts +2 -1
- package/dist/internal/eval/single-flight.d.ts +2 -1
- package/dist/internal/global-singleton.d.ts +6 -3
- package/dist/internal/llm/responses.d.ts +10 -0
- package/dist/internal/local-agent/local-agent-bootstrap.d.ts +5 -3
- package/dist/internal/local-agent/local-agent-capabilities.d.ts +38 -0
- package/dist/internal/local-agent/local-agent-dispatch.d.ts +2 -2
- package/dist/internal/local-agent/local-agent-memory-provider.d.ts +1 -1
- package/dist/internal/local-agent/local-agent-personality-extensions.d.ts +25 -1
- package/dist/internal/local-agent/local-agent-send.d.ts +42 -1
- package/dist/internal/local-agent/real-local-run-mcp.d.ts +26 -0
- package/dist/internal/local-agent/real-local-run-options.d.ts +26 -0
- package/dist/internal/local-agent/real-local-run-tools.d.ts +21 -4
- package/dist/internal/local-agent/real-local-run.d.ts +2 -2
- package/dist/internal/mcp/handshake-timeout.d.ts +53 -0
- package/dist/internal/memory/active-memory.d.ts +1 -1
- package/dist/internal/memory/adapters/index.cjs +10 -10
- package/dist/internal/memory/adapters/index.js +9 -9
- package/dist/internal/memory/adapters/openai-embedding.d.cts +10 -0
- package/dist/internal/memory/adapters/openai-embedding.d.ts +10 -0
- package/dist/internal/memory/corpus-sync.d.ts +23 -0
- package/dist/internal/memory/index-db.d.ts +15 -1
- package/dist/internal/memory/index-manager-contract.d.ts +12 -0
- package/dist/internal/memory/index-manager.d.ts +4 -10
- package/dist/internal/memory/index-repository.d.ts +58 -0
- package/dist/internal/memory/lance-memory-adapter.d.ts +16 -14
- package/dist/internal/memory/memory-index.d.ts +15 -0
- package/dist/internal/memory/sdk-memory-peer-loader.d.ts +54 -1
- package/dist/internal/memory/storage/index.cjs +39 -40
- package/dist/internal/memory/storage/index.js +10 -11
- package/dist/internal/memory/storage/memory-root.d.cts +2 -3
- package/dist/internal/memory/storage/memory-root.d.ts +2 -3
- package/dist/internal/persistence/atomic-write.d.cts +4 -4
- package/dist/internal/persistence/atomic-write.d.ts +4 -4
- package/dist/internal/persistence/index.cjs +24 -25
- package/dist/internal/persistence/index.cjs.map +1 -1
- package/dist/internal/persistence/index.js +7 -8
- package/dist/internal/persistence/index.js.map +1 -1
- package/dist/internal/persistence/jsonl.d.cts +3 -1
- package/dist/internal/persistence/jsonl.d.ts +3 -1
- package/dist/internal/persistence/paths.d.cts +25 -12
- package/dist/internal/persistence/paths.d.ts +25 -12
- package/dist/internal/persistence/transcript-ops.d.cts +11 -2
- package/dist/internal/persistence/transcript-ops.d.ts +11 -2
- package/dist/internal/plugins/context.d.cts +0 -10
- package/dist/internal/plugins/context.d.ts +0 -10
- package/dist/internal/plugins/types.d.cts +1 -1
- package/dist/internal/plugins/types.d.ts +1 -1
- package/dist/internal/providers/catalog-schema.d.ts +94 -0
- package/dist/internal/providers/catalog-source-models-dev.d.ts +11 -0
- package/dist/internal/runtime/compat/compat-config-file.d.ts +31 -0
- package/dist/internal/runtime/compat/foreign-config-sources.d.ts +58 -34
- package/dist/internal/runtime/compression/compression-model-registry.d.ts +1 -1
- package/dist/internal/runtime/compression/compression-summarizer.d.ts +5 -1
- package/dist/internal/runtime/fixtures/fixture-events.d.ts +1 -1
- package/dist/internal/runtime/fixtures/fixture-mode.d.ts +8 -14
- package/dist/internal/runtime/fixtures/fixture-run-base.d.ts +1 -1
- package/dist/internal/runtime/fixtures/fixture-scripts.d.ts +2 -2
- package/dist/internal/runtime/hooks/hooks-executor.d.ts +6 -1
- package/dist/internal/runtime/lifecycle/wrap-completion-check-run.d.ts +1 -1
- package/dist/internal/runtime/{memory → memory-glue}/memory-provider.d.ts +1 -1
- package/dist/internal/runtime/{plugins → plugin-loader}/plugin-bundles.d.ts +4 -1
- package/dist/internal/runtime/processors/wrap-output-run.d.ts +1 -1
- package/dist/internal/runtime/registry/live-agent-registry.d.ts +9 -1
- package/dist/internal/runtime/system-prompt/local-assembly.d.ts +2 -1
- package/dist/internal/scorers/llm-judge.d.ts +12 -0
- package/dist/internal/security/index.cjs +14 -15
- package/dist/internal/security/index.d.cts +6 -1
- package/dist/internal/security/index.d.ts +6 -1
- package/dist/internal/security/index.js +4 -5
- package/dist/internal/security/path-containment.d.ts +24 -0
- package/dist/internal/session/agent-session-store.d.ts +1 -1
- package/dist/internal/session/agent-session.d.ts +1 -1
- package/dist/internal/session/index.d.ts +1 -1
- package/dist/internal/session/session-cache.d.ts +9 -3
- package/dist/internal/task/registry.d.ts +1 -1
- package/dist/internal/task/store.d.ts +1 -1
- package/dist/internal/task/subscribe.d.ts +1 -1
- package/dist/internal/task/task-id.d.ts +22 -0
- package/dist/internal/telemetry/adapter-registry.d.ts +12 -2
- package/dist/internal/telemetry/adapters/braintrust.d.ts +6 -1
- package/dist/internal/telemetry/adapters/langsmith.d.ts +6 -1
- package/dist/internal/workflow/executor.d.ts +2 -1
- package/dist/internal/workflow/snapshot-store.d.ts +1 -1
- package/dist/internal/workflow/step-branch.d.ts +2 -2
- package/dist/internal/workflow/step-dowhile.d.ts +2 -2
- package/dist/internal/workflow/step-execution.d.ts +25 -0
- package/dist/internal/workflow/step-foreach.d.ts +2 -2
- package/dist/internal/workflow/step-parallel.d.ts +2 -2
- package/dist/judge-call-6MVARKU2.js +5 -0
- package/dist/{judge-call-LVXABPS3.js.map → judge-call-6MVARKU2.js.map} +1 -1
- package/dist/judge-call-I3P4D5QR.cjs +22 -0
- package/dist/{judge-call-LAHMBJ57.cjs.map → judge-call-I3P4D5QR.cjs.map} +1 -1
- package/dist/mcp-auth.cjs +14 -15
- package/dist/mcp-auth.cjs.map +1 -1
- package/dist/mcp-auth.d.cts +2 -0
- package/dist/mcp-auth.d.ts +2 -0
- package/dist/mcp-auth.js +4 -5
- package/dist/mcp-auth.js.map +1 -1
- package/dist/models.cjs +52 -42
- package/dist/models.cjs.map +1 -1
- package/dist/models.js +39 -29
- package/dist/models.js.map +1 -1
- package/dist/oauth-transaction-store-5RIR6D5C.js +5 -0
- package/dist/{oauth-transaction-store-W52KVHQ4.js.map → oauth-transaction-store-5RIR6D5C.js.map} +1 -1
- package/dist/oauth-transaction-store-SXIE57OD.cjs +38 -0
- package/dist/{oauth-transaction-store-BT4GLTLK.cjs.map → oauth-transaction-store-SXIE57OD.cjs.map} +1 -1
- package/dist/path-safety.cjs +11 -12
- package/dist/path-safety.d.cts +2 -0
- package/dist/path-safety.d.ts +2 -0
- package/dist/path-safety.js +4 -5
- package/dist/permission-engine.d.ts +10 -17
- package/dist/persistence.cjs +31 -31
- package/dist/persistence.cjs.map +1 -1
- package/dist/persistence.d.cts +9 -1
- package/dist/persistence.d.ts +9 -1
- package/dist/persistence.js +12 -13
- package/dist/persistence.js.map +1 -1
- package/dist/project.cjs +5 -6
- package/dist/project.cjs.map +1 -1
- package/dist/project.js +3 -4
- package/dist/project.js.map +1 -1
- package/dist/providers.cjs +10 -10
- package/dist/providers.d.cts +2 -0
- package/dist/providers.d.ts +2 -0
- package/dist/providers.js +8 -8
- package/dist/registry-BZQFYRTL.cjs +46 -0
- package/dist/{registry-V7BDQ6QB.cjs.map → registry-BZQFYRTL.cjs.map} +1 -1
- package/dist/registry-DMWCJKRF.js +9 -0
- package/dist/{registry-75W33OGL.js.map → registry-DMWCJKRF.js.map} +1 -1
- package/dist/retry.cjs +4 -5
- package/dist/retry.d.cts +20 -5
- package/dist/retry.d.ts +20 -5
- package/dist/retry.js +3 -4
- package/dist/{run-BYSHf58D.d.ts → run-CTAdRU3U.d.cts} +120 -152
- package/dist/{run-BYSHf58D.d.cts → run-CTAdRU3U.d.ts} +120 -152
- package/dist/{run-until-HEQOUVU6.js → run-until-6D6TQ4JN.js} +27 -59
- package/dist/run-until-6D6TQ4JN.js.map +1 -0
- package/dist/{run-until-U2B5FJJI.cjs → run-until-DG2KXWB2.cjs} +27 -59
- package/dist/run-until-DG2KXWB2.cjs.map +1 -0
- package/dist/sandbox/bwrap.d.cts +11 -1
- package/dist/sandbox/bwrap.d.ts +11 -1
- package/dist/sandbox/index.cjs +26 -30
- package/dist/sandbox/index.cjs.map +1 -1
- package/dist/sandbox/index.d.cts +8 -1
- package/dist/sandbox/index.d.ts +8 -1
- package/dist/sandbox/index.js +10 -14
- package/dist/sandbox/index.js.map +1 -1
- package/dist/sandbox/linux-sandbox.d.cts +20 -4
- package/dist/sandbox/linux-sandbox.d.ts +20 -4
- package/dist/sandbox/types.d.cts +18 -2
- package/dist/sandbox/types.d.ts +18 -2
- package/dist/sanitize/index.cjs +2 -2
- package/dist/sanitize/index.js +1 -1
- package/dist/sanitize/types.d.cts +15 -2
- package/dist/sanitize/types.d.ts +15 -2
- package/dist/{sdk-agent-D8qJVkuV.d.ts → sdk-agent-BOiKqOgL.d.cts} +197 -117
- package/dist/{sdk-agent-DEoKhA8a.d.cts → sdk-agent-D4a_BR_6.d.ts} +197 -117
- package/dist/server/auth/errors.d.cts +4 -3
- package/dist/server/auth/errors.d.ts +4 -3
- package/dist/server/auth/index.cjs +28 -28
- package/dist/server/auth/index.cjs.map +1 -1
- package/dist/server/auth/index.d.cts +28 -5
- package/dist/server/auth/index.d.ts +28 -5
- package/dist/server/auth/index.js +13 -13
- package/dist/server/auth/index.js.map +1 -1
- package/dist/server/auth/oauth-transaction-store.d.cts +2 -1
- package/dist/server/auth/oauth-transaction-store.d.ts +2 -1
- package/dist/server/auth/orchestrator.d.cts +4 -1
- package/dist/server/auth/orchestrator.d.ts +4 -1
- package/dist/server/auth/types.d.cts +18 -0
- package/dist/server/auth/types.d.ts +18 -0
- package/dist/server/errors-envelope.cjs +14 -15
- package/dist/server/errors-envelope.cjs.map +1 -1
- 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 -4
- package/dist/server/errors-envelope.js.map +1 -1
- package/dist/session-transcript-LGHSNVY5.cjs +62 -0
- package/dist/{session-transcript-6WNITKRE.cjs.map → session-transcript-LGHSNVY5.cjs.map} +1 -1
- package/dist/session-transcript-VTBTCGQX.js +5 -0
- package/dist/{session-transcript-XAEKW6P7.js.map → session-transcript-VTBTCGQX.js.map} +1 -1
- package/dist/skills.cjs +8 -9
- package/dist/skills.js +6 -7
- package/dist/stream-object-HBFMIZLD.js +7 -0
- package/dist/{stream-object-UF4QRQRU.js.map → stream-object-HBFMIZLD.js.map} +1 -1
- package/dist/stream-object-QSKHISDJ.cjs +20 -0
- package/dist/{stream-object-ZJTQNKY3.cjs.map → stream-object-QSKHISDJ.cjs.map} +1 -1
- package/dist/stream-object.d.ts +2 -4
- package/dist/subagents-loader-TPZLTXYZ.cjs +16 -0
- package/dist/{subagents-loader-UCNO7FUH.cjs.map → subagents-loader-TPZLTXYZ.cjs.map} +1 -1
- package/dist/subagents-loader-Y6JFYXAY.js +7 -0
- package/dist/{subagents-loader-XP5ERVDZ.js.map → subagents-loader-Y6JFYXAY.js.map} +1 -1
- package/dist/subagents-loader.cjs +7 -8
- package/dist/subagents-loader.cjs.map +1 -1
- package/dist/subagents-loader.d.cts +5 -3
- package/dist/subagents-loader.d.ts +5 -3
- package/dist/subagents-loader.js +5 -6
- package/dist/subagents-loader.js.map +1 -1
- package/dist/subagents.cjs +2 -2
- package/dist/subagents.cjs.map +1 -1
- package/dist/subagents.js +1 -1
- package/dist/subagents.js.map +1 -1
- package/dist/subscription/define-subscription.d.cts +4 -1
- package/dist/subscription/define-subscription.d.ts +4 -1
- package/dist/subscription/index.cjs +4 -5
- package/dist/subscription/index.cjs.map +1 -1
- package/dist/subscription/index.d.cts +2 -0
- package/dist/subscription/index.d.ts +2 -0
- package/dist/subscription/index.js +3 -4
- package/dist/subscription/index.js.map +1 -1
- package/dist/subscription/internal/server-integration.d.cts +5 -0
- package/dist/subscription/internal/server-integration.d.ts +5 -0
- package/dist/subscription/internal/subscription-runtime.d.cts +13 -1
- package/dist/subscription/internal/subscription-runtime.d.ts +13 -1
- package/dist/task-errors.d.ts +58 -0
- package/dist/task-store.cjs +7 -8
- package/dist/task-store.d.cts +2 -0
- package/dist/task-store.d.ts +2 -0
- package/dist/task-store.js +4 -5
- package/dist/types/agent-prims.d.ts +21 -0
- package/dist/types/agent.d.ts +109 -15
- package/dist/types/batch.d.ts +3 -0
- package/dist/types/budget-tracker.d.ts +3 -0
- package/dist/types/budget.d.ts +12 -3
- package/dist/types/content-blocks.d.ts +3 -0
- package/dist/types/context.d.ts +3 -0
- package/dist/types/conversation.d.ts +5 -0
- package/dist/types/cron.d.ts +5 -0
- package/dist/types/env-policy.d.ts +3 -0
- package/dist/types/eval.d.ts +3 -0
- package/dist/types/fork.d.ts +3 -0
- package/dist/types/goal-events.d.ts +3 -0
- package/dist/types/mcp.d.ts +5 -0
- package/dist/types/memory-adapter.d.ts +3 -0
- package/dist/types/memory-provider.d.ts +44 -5
- package/dist/types/messages-base.d.ts +4 -0
- package/dist/types/messages.d.ts +5 -0
- package/dist/types/plugin.d.ts +32 -4
- package/dist/types/processors.d.ts +3 -0
- package/dist/types/provider-profile.d.ts +3 -0
- package/dist/types/providers.d.ts +3 -0
- package/dist/types/run-events.d.ts +36 -9
- package/dist/types/run.d.ts +29 -2
- package/dist/types/sdk-agent.d.ts +71 -1
- package/dist/types/session-message.d.ts +3 -0
- package/dist/types/session-record.d.ts +3 -0
- package/dist/types/session-store.d.ts +45 -0
- package/dist/types/task.d.ts +3 -11
- package/dist/types/theokit.d.ts +3 -0
- package/dist/types/trajectory.d.ts +3 -0
- package/dist/types/updates.d.ts +5 -0
- package/dist/types/usage.d.ts +4 -1
- package/dist/types/workflow.d.ts +13 -135
- package/dist/workflow-as-tool.d.ts +66 -0
- package/dist/workflow-errors.d.ts +164 -0
- package/dist/workflow.cjs +29 -30
- package/dist/workflow.d.cts +135 -74
- package/dist/workflow.d.ts +135 -74
- package/dist/workflow.js +8 -9
- package/docs/adr/README.md +2604 -0
- package/docs/error-codes.md +139 -105
- package/docs/harness-capability-map.md +32 -20
- package/docs/memory-decisions.md +1 -1
- package/package.json +3 -7
- package/bin/theokit-migrate-config.mjs +0 -278
- package/bin/theokit-migrate-memory.mjs +0 -116
- package/dist/agent-A5XMIVNP.js +0 -57
- package/dist/agent-UX7WFI6B.cjs +0 -66
- package/dist/agent-session-store-6EL5NPA4.cjs +0 -24
- package/dist/agent-session-store-OPGRB4XM.js +0 -7
- package/dist/batch-BXYTW2DP.cjs.map +0 -1
- package/dist/batch-L4ZXS46M.js.map +0 -1
- package/dist/chunk-247ZTLNU.js +0 -73
- package/dist/chunk-247ZTLNU.js.map +0 -1
- package/dist/chunk-2D34UTDC.js.map +0 -1
- package/dist/chunk-2GUYQR5P.js.map +0 -1
- package/dist/chunk-2QDYBS2A.js.map +0 -1
- package/dist/chunk-32WTYBUH.js.map +0 -1
- package/dist/chunk-3FFAEAUJ.cjs.map +0 -1
- package/dist/chunk-3O42QOMJ.js.map +0 -1
- package/dist/chunk-3OR54XG4.js.map +0 -1
- package/dist/chunk-43ZQRWAP.cjs.map +0 -1
- package/dist/chunk-4FFBAUFS.js.map +0 -1
- package/dist/chunk-4O5TGQBW.cjs.map +0 -1
- package/dist/chunk-4OTIXDMU.cjs.map +0 -1
- package/dist/chunk-4PYZ5AX3.cjs.map +0 -1
- package/dist/chunk-4QZSA2HJ.js.map +0 -1
- package/dist/chunk-4ZHTIJNE.cjs.map +0 -1
- package/dist/chunk-52NKC5HT.cjs.map +0 -1
- package/dist/chunk-6HKGLTJI.cjs.map +0 -1
- package/dist/chunk-6JSIEDKL.cjs.map +0 -1
- package/dist/chunk-7AD3ZTZL.js.map +0 -1
- package/dist/chunk-7BG5UH3T.cjs.map +0 -1
- package/dist/chunk-7VT4P3Z4.cjs.map +0 -1
- package/dist/chunk-7YGCPMGB.js.map +0 -1
- package/dist/chunk-A46SWMIF.js.map +0 -1
- package/dist/chunk-A4JVILQU.js.map +0 -1
- package/dist/chunk-ACDLHN3W.js.map +0 -1
- package/dist/chunk-AKJP2STZ.cjs +0 -81
- package/dist/chunk-AKJP2STZ.cjs.map +0 -1
- package/dist/chunk-AWO27VRZ.js.map +0 -1
- package/dist/chunk-B2J4ZMZL.cjs.map +0 -1
- package/dist/chunk-B4EOJWOY.cjs.map +0 -1
- package/dist/chunk-BU4KFWXF.js.map +0 -1
- package/dist/chunk-BZRFXJHA.js.map +0 -1
- package/dist/chunk-C3NT3PVE.js.map +0 -1
- package/dist/chunk-C72AZW7J.js.map +0 -1
- package/dist/chunk-D4CUGAKZ.js.map +0 -1
- package/dist/chunk-DN2PACRI.js.map +0 -1
- package/dist/chunk-DXGZ2NUG.cjs.map +0 -1
- package/dist/chunk-EG4QM7ZJ.cjs +0 -39
- package/dist/chunk-EG4QM7ZJ.cjs.map +0 -1
- package/dist/chunk-GMLBYDW4.cjs.map +0 -1
- package/dist/chunk-HCZD23VS.cjs.map +0 -1
- package/dist/chunk-HS7AVXTF.js.map +0 -1
- package/dist/chunk-IAHZCGBE.cjs.map +0 -1
- package/dist/chunk-J24VJOH3.cjs.map +0 -1
- package/dist/chunk-JPBKYL3B.cjs +0 -18
- package/dist/chunk-JPBKYL3B.cjs.map +0 -1
- package/dist/chunk-KQ7TS7WW.cjs.map +0 -1
- package/dist/chunk-KQRW2GPZ.js.map +0 -1
- package/dist/chunk-KYAJINUI.cjs.map +0 -1
- package/dist/chunk-L3MTL4NA.js.map +0 -1
- package/dist/chunk-L4BDVXIM.js.map +0 -1
- package/dist/chunk-LKBEROHN.js.map +0 -1
- package/dist/chunk-LYRDF5TQ.cjs.map +0 -1
- package/dist/chunk-LYTOXSRH.js.map +0 -1
- package/dist/chunk-N2U4AZGB.js.map +0 -1
- package/dist/chunk-NDGGJQTZ.js.map +0 -1
- package/dist/chunk-O7DK5PBJ.cjs.map +0 -1
- package/dist/chunk-O7LZFG6O.cjs.map +0 -1
- package/dist/chunk-OFRFZRQ4.cjs.map +0 -1
- package/dist/chunk-OSEG74VJ.js.map +0 -1
- package/dist/chunk-RFMBZPOW.cjs.map +0 -1
- package/dist/chunk-RFXWMRFC.js.map +0 -1
- package/dist/chunk-RIAM53CP.js.map +0 -1
- package/dist/chunk-RMWTPV3M.cjs.map +0 -1
- package/dist/chunk-RNB4APBZ.js.map +0 -1
- package/dist/chunk-SAVIWMZB.js.map +0 -1
- package/dist/chunk-SZVR77EJ.cjs.map +0 -1
- package/dist/chunk-TAZVKYWJ.js.map +0 -1
- package/dist/chunk-U54XCYG3.js.map +0 -1
- package/dist/chunk-U6IFHFWK.js.map +0 -1
- package/dist/chunk-UALX2J2Q.cjs.map +0 -1
- package/dist/chunk-UBDMVMBZ.js.map +0 -1
- package/dist/chunk-UGT7GK7I.cjs.map +0 -1
- package/dist/chunk-UNYXQ4M5.js.map +0 -1
- package/dist/chunk-UTSRIDKZ.js.map +0 -1
- package/dist/chunk-UU36SHFY.cjs.map +0 -1
- package/dist/chunk-V2BOS4WF.cjs.map +0 -1
- package/dist/chunk-VCLBZAZU.cjs.map +0 -1
- package/dist/chunk-VJ26EKGJ.cjs.map +0 -1
- package/dist/chunk-VKJ7V7EB.cjs.map +0 -1
- package/dist/chunk-VLVVJLDH.cjs.map +0 -1
- package/dist/chunk-WLQNMXQE.js.map +0 -1
- package/dist/chunk-WNO3C3N2.cjs.map +0 -1
- package/dist/chunk-WTMU7J4U.js +0 -14
- package/dist/chunk-WTMU7J4U.js.map +0 -1
- package/dist/chunk-XEQ3TM66.js +0 -35
- package/dist/chunk-XEQ3TM66.js.map +0 -1
- package/dist/chunk-XJCXEKMD.cjs.map +0 -1
- package/dist/chunk-XL7Q7HB2.cjs.map +0 -1
- package/dist/chunk-XWTLIGO3.cjs.map +0 -1
- package/dist/chunk-YML4ME27.cjs.map +0 -1
- package/dist/chunk-ZSWPZ23K.cjs.map +0 -1
- package/dist/chunk-ZZMZWBR6.js.map +0 -1
- package/dist/compact-session-QV57KR66.cjs +0 -59
- package/dist/compact-session-RIGOWC4Y.js +0 -22
- package/dist/context-WFLTTMK3.cjs +0 -24
- package/dist/context-WI2DFG7V.js +0 -7
- package/dist/executor-6CYCA7MI.cjs.map +0 -1
- package/dist/executor-QSEC3MRH.js.map +0 -1
- package/dist/fork-agent-RSV4E3EA.js.map +0 -1
- package/dist/fork-agent-Y2IK2RYU.cjs.map +0 -1
- package/dist/fs-session-store-4PIHT5UX.cjs +0 -20
- package/dist/fs-session-store-NM6YSTE2.js +0 -11
- package/dist/generate-object-GUNAUVBX.js +0 -8
- package/dist/generate-object-R7HTMW7F.cjs +0 -21
- package/dist/index-manager-2SRX45WJ.cjs +0 -27
- package/dist/index-manager-SP4ISSDX.js +0 -18
- package/dist/inject-session-WQKMC3GR.cjs +0 -29
- package/dist/internal/persistence/credential-pool-store.d.cts +0 -32
- package/dist/internal/persistence/credential-pool-store.d.ts +0 -32
- package/dist/internal/runtime/memory/memory-path-selector.d.ts +0 -73
- package/dist/judge-call-LAHMBJ57.cjs +0 -23
- package/dist/judge-call-LVXABPS3.js +0 -6
- package/dist/oauth-transaction-store-BT4GLTLK.cjs +0 -36
- package/dist/oauth-transaction-store-W52KVHQ4.js +0 -3
- package/dist/registry-75W33OGL.js +0 -10
- package/dist/registry-V7BDQ6QB.cjs +0 -47
- package/dist/run-until-HEQOUVU6.js.map +0 -1
- package/dist/run-until-U2B5FJJI.cjs.map +0 -1
- package/dist/server/adapter/express.d.cts +0 -9
- package/dist/server/adapter/express.d.ts +0 -9
- package/dist/server/adapter/fastify.d.cts +0 -9
- package/dist/server/adapter/fastify.d.ts +0 -9
- package/dist/server/adapter/hono.d.cts +0 -9
- package/dist/server/adapter/hono.d.ts +0 -9
- package/dist/server/adapter/shared-handler.d.cts +0 -9
- package/dist/server/adapter/shared-handler.d.ts +0 -9
- package/dist/server/adapter/types.d.cts +0 -33
- package/dist/server/adapter/types.d.ts +0 -33
- package/dist/session-transcript-6WNITKRE.cjs +0 -63
- package/dist/session-transcript-XAEKW6P7.js +0 -6
- package/dist/stream-object-UF4QRQRU.js +0 -8
- package/dist/stream-object-ZJTQNKY3.cjs +0 -21
- package/dist/subagents-loader-UCNO7FUH.cjs +0 -17
- package/dist/subagents-loader-XP5ERVDZ.js +0 -8
- /package/dist/{batch.d.ts → internal/agent/batch.d.ts} +0 -0
- /package/dist/{agent-helpers.d.ts → internal/agent/helpers.d.ts} +0 -0
- /package/dist/internal/agent-loop/{loop-types.d.ts → types.d.ts} +0 -0
- /package/dist/internal/auth/{auth-types.d.ts → types.d.ts} +0 -0
- /package/dist/internal/cloud-agent/{cloud-payload-types.d.ts → types.d.ts} +0 -0
- /package/dist/internal/{runtime/concurrency → concurrency}/abort-utils.d.ts +0 -0
- /package/dist/internal/{runtime/concurrency → concurrency}/async-local-storage.d.ts +0 -0
- /package/dist/internal/{runtime/concurrency → concurrency}/async-semaphore.d.ts +0 -0
- /package/dist/internal/{runtime/concurrency → concurrency}/delegation-depth.d.ts +0 -0
- /package/dist/internal/{runtime/concurrency → concurrency}/map-with-concurrency.d.ts +0 -0
- /package/dist/internal/{runtime/retry → error-mappers}/default-retriable.d.ts +0 -0
- /package/dist/internal/{runtime/fixtures/fixture-types.d.ts → memory/storage/list-markdown.d.cts} +0 -0
- /package/dist/internal/{runtime/plugins/plugins-manager.d.ts → memory/storage/list-markdown.d.ts} +0 -0
- /package/dist/internal/{resilience → retry}/circuit-breaker.d.ts +0 -0
- /package/dist/internal/{runtime/retry → retry}/with-retry.d.ts +0 -0
- /package/dist/internal/{security/secret-redactor.d.cts → runtime/fixtures/types.d.ts} +0 -0
- /package/dist/internal/runtime/{memory → memory-glue}/memory-store.d.ts +0 -0
- /package/dist/internal/runtime/{memory → memory-glue}/select-facts.d.ts +0 -0
- /package/dist/internal/runtime/{plugins → plugin-loader}/plugin-frontmatter.d.ts +0 -0
- /package/dist/internal/{security/secret-redactor.d.ts → runtime/plugin-loader/plugins-manager.d.ts} +0 -0
- /package/dist/internal/runtime/{reasoning → system-prompt}/native-reasoning.d.ts +0 -0
- /package/dist/internal/{runtime/context/path-containment.d.ts → security/path-containment.d.cts} +0 -0
- /package/dist/internal/session/{session-types.d.ts → types.d.ts} +0 -0
- /package/dist/internal/{zod/to-json-schema.d.ts → zod-to-json-schema.d.ts} +0 -0
- /package/dist/subscription/internal/{adapter-types.d.cts → types.d.cts} +0 -0
- /package/dist/subscription/internal/{adapter-types.d.ts → types.d.ts} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/internal/runtime/plugin-loader/plugin-bundles.ts","../src/internal/runtime/skills/subagents-loader.ts"],"names":["join"],"mappings":";;;;;;;AAyBA,eAAsB,gBAAA,CACpB,GAAA,EAEA,aAAA,GAAoD,EAAC,EAClC;AACnB,EAAA,MAAM,OAAiB,EAAC;AACxB,EAAA,KAAA,MAAW,IAAA,IAAQ,iBAAA,CAAkB,GAAA,EAAK,aAAa,CAAA,EAAG;AACxD,IAAA,IAAI,OAAA;AACJ,IAAA,IAAI;AACF,MAAA,OAAA,GAAU,MAAM,OAAA,CAAQ,IAAA,EAAM,EAAE,aAAA,EAAe,MAAM,CAAA;AAAA,IACvD,CAAA,CAAA,MAAQ;AACN,MAAA;AAAA,IACF;AACA,IAAA,KAAA,MAAW,SAAS,OAAA,EAAS;AAC3B,MAAA,IAAI,KAAA,CAAM,aAAY,EAAG,IAAA,CAAK,KAAK,IAAA,CAAK,IAAA,EAAM,KAAA,CAAM,IAAI,CAAC,CAAA;AAAA,IAC3D;AAAA,EACF;AACA,EAAA,OAAO,IAAA;AACT;;;ACrBA,eAAsB,cACpB,GAAA,EACA,4BAAA,EACA,MAAA,EAEA,aAAA,GAAoD,EAAC,EACX;AAC1C,EAAA,MAAM,SAA0C,EAAC;AACjD,EAAA,IAAI,4BAAA,EAA8B;AAChC,IAAA,MAAM,aAAA,GAAgB,MAAM,oBAAA,CAAqB,GAAA,EAAK,aAAa,CAAA;AACnE,IAAA,KAAA,MAAW,CAAC,IAAA,EAAM,UAAU,KAAK,MAAA,CAAO,OAAA,CAAQ,aAAa,CAAA,EAAG;AAC9D,MAAA,MAAA,CAAO,IAAI,CAAA,GAAI,UAAA;AAAA,IACjB;AAAA,EACF;AACA,EAAA,IAAI,WAAW,MAAA,EAAW;AACxB,IAAA,KAAA,MAAW,CAAC,IAAA,EAAM,UAAU,KAAK,MAAA,CAAO,OAAA,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AAE,MAAA,CAAO,CAAC,CAAA,KAAM,CAAA,CAAE,SAAS,CAAC,CAAA;AAC9E,EAAA,IAAI,OAAO,MAAM,QAAA,EAAU;AACzB,IAAA,OAAO,EACJ,KAAA,CAAM,QAAQ,CAAA,CACd,GAAA,CAAI,CAAC,CAAA,KAAM,CAAA,CAAE,IAAA,EAAM,EACnB,MAAA,CAAO,CAAC,CAAA,KAAM,CAAA,CAAE,SAAS,CAAC,CAAA;AAAA,EAC/B;AACA,EAAA,OAAO,EAAC;AACV;AAGA,SAAS,eAAe,GAAA,EAAsB;AAC5C,EAAA,OAAO,WAAA,CAAY,KAAK,GAAG,CAAA;AAC7B;AAEA,SAAS,gBAAA,CAAiB,KAAa,QAAA,EAAyD;AAC9F,EAAA,MAAM,KAAA,GAAQ,yCAAA,CAA0C,IAAA,CAAK,GAAG,CAAA;AAChE,EAAA,IAAI,UAAU,IAAA,EAAM;AAClB,IAAA,MAAM,IAAI,kBAAA,CAAmB,CAAA,SAAA,EAAY,QAAQ,CAAA,uBAAA,CAAA,EAA2B;AAAA,MAC1E,IAAA,EAAM;AAAA,KACP,CAAA;AAAA,EACH;AACA,EAAA,OAAO,EAAE,WAAA,EAAa,KAAA,CAAM,CAAC,CAAA,IAAK,EAAA,EAAI,IAAA,EAAA,CAAO,KAAA,CAAM,CAAC,CAAA,IAAK,EAAA,EAAI,IAAA,EAAK,EAAE;AACtE;AAEA,SAAS,uBAAuB,WAAA,EAAmE;AAIjG,EAAA,OAAO,gBAAgB,WAAW,CAAA;AACpC","file":"chunk-4S5TWFIZ.js","sourcesContent":["/**\n * Locating the plugin bundles a project carries.\n *\n * Shared by the skills and subagents loaders, which both need the same answer to \"which folders in\n * this project are plugins\" and would otherwise each grow their own copy of the directory walk.\n *\n * @internal\n */\n\nimport type { Dirent } from \"node:fs\";\nimport { readdir } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport { pluginBundleRoots } from \"../../persistence/paths.js\";\nimport type { CompatSourceDeclaration } from \"../compat/foreign-config-sources.js\";\n\n/**\n * Every plugin folder under the project's plugin roots.\n *\n * Returns the FOLDERS, not their contents — what a bundle contributes (`skills/`, `agents/`) is the\n * caller's business, and a loader that also knew the layout would have to change whenever the other\n * one did.\n *\n * A missing root is not an error: most projects carry no plugins, and treating their absence as a\n * failure would make \"none installed\" indistinguishable from \"the directory could not be read\".\n */\nexport async function pluginBundleDirs(\n cwd: string,\n /** Declared foreign dialects (#524). Empty reads `.theokit/plugins` only. */\n compatSources: readonly CompatSourceDeclaration[] = [],\n): Promise<string[]> {\n const dirs: string[] = [];\n for (const root of pluginBundleRoots(cwd, compatSources)) {\n let entries: Dirent[];\n try {\n entries = await readdir(root, { withFileTypes: true });\n } catch {\n continue;\n }\n for (const entry of entries) {\n if (entry.isDirectory()) dirs.push(join(root, entry.name));\n }\n }\n return dirs;\n}\n","import { readFile } from \"node:fs/promises\";\nimport { join } from \"node:path\";\n\nimport { ConfigurationError } from \"../../../errors.js\";\nimport type { AgentDefinition } from \"../../../types/agent.js\";\nimport type { ModelSelection } from \"../../../types/agent-prims.js\";\nimport { diag } from \"../../diagnostics.js\";\nimport { projectConfigRoots } from \"../../persistence/paths.js\";\nimport type { CompatSourceDeclaration } from \"../compat/foreign-config-sources.js\";\nimport { readWorkspaceDir } from \"../config/workspace-dir.js\";\nimport { type FrontmatterValue, parseSimpleYaml } from \"../context/yaml-frontmatter.js\";\nimport { pluginBundleDirs } from \"../plugin-loader/plugin-bundles.js\";\n\n/**\n * Load file-based subagents from `.theokit/agents/*.md` and merge with\n * inline definitions. Inline overrides file-based on name conflict.\n *\n * Each markdown file has YAML frontmatter (description + optional model)\n * and a body that becomes the subagent prompt.\n *\n * @internal\n */\nexport async function loadSubagents(\n cwd: string,\n settingSourcesIncludeProject: boolean,\n inline: Record<string, AgentDefinition> | undefined,\n /** Declared foreign dialects (#524). Empty reads `.theokit/` only. */\n compatSources: readonly CompatSourceDeclaration[] = [],\n): Promise<Record<string, AgentDefinition>> {\n const result: Record<string, AgentDefinition> = {};\n if (settingSourcesIncludeProject) {\n const projectAgents = await readProjectSubagents(cwd, compatSources);\n for (const [name, definition] of Object.entries(projectAgents)) {\n result[name] = definition;\n }\n }\n if (inline !== undefined) {\n for (const [name, definition] of Object.entries(inline)) {\n result[name] = definition;\n }\n }\n return result;\n}\n\n/**\n * Read agent declarations from every project config root (`.theokit`, then `.claude`).\n *\n * FIRST occurrence of a name wins, which is what makes `projectConfigRoots`' order a contract rather\n * than a detail: a project declaring the same agent in both means the explicit namespace.\n */\nasync function readProjectSubagents(\n cwd: string,\n compatSources: readonly CompatSourceDeclaration[],\n): Promise<Record<string, AgentDefinition>> {\n const subagents: Record<string, AgentDefinition> = {};\n for (const configRoot of projectConfigRoots(cwd, compatSources, \"subagents\")) {\n await readSubagentsFrom(join(configRoot, \"agents\"), subagents);\n }\n // A Claude Code plugin is a BUNDLE, and its `agents/` is what it exists to contribute. Read after\n // the project's own, so a project can shadow an agent a plugin ships without editing the plugin.\n for (const bundle of await pluginBundleDirs(cwd, compatSources)) {\n await readSubagentsFrom(join(bundle, \"agents\"), subagents);\n }\n return subagents;\n}\n\nasync function readSubagentsFrom(\n root: string,\n subagents: Record<string, AgentDefinition>,\n): Promise<void> {\n const entries = await readWorkspaceDir(root, \"subagents_read_error\", \"subagents directory\");\n for (const entry of entries) {\n if (!entry.isFile() || !entry.name.endsWith(\".md\")) continue;\n const path = join(root, entry.name);\n const raw = await readFile(path, \"utf8\");\n // A markdown file with NO frontmatter is not an agent declaration — a directory of agents\n // written for the Claude Code CLI conventionally carries documentation beside them, and\n // `.claude/agents/README.md` exists in this repository. Throwing on it made ONE such file stop\n // every agent in the directory from loading.\n //\n // Skipped with a warn rather than in silence, and ONLY for the no-frontmatter case: a file that\n // HAS frontmatter and gets it wrong is a broken agent and still fails loudly, which is what\n // keeps a typo'd `sandbox` from returning as a silent gate through this door.\n if (!hasFrontmatter(raw)) {\n diag(`[theokit-sdk] ${entry.name} has no frontmatter — not an agent declaration, skipping`);\n continue;\n }\n const definition = parseSubagentMarkdown(raw, entry.name);\n if (subagents[definition.name] === undefined) {\n // `path` is computed above to read the file and was then dropped. Keeping it is the whole\n // visibility fix (#524): without it a listing cannot say which root an agent came from.\n subagents[definition.name] = { ...definition.definition, source: path };\n }\n }\n}\n\n// The frontmatter keys a disk subagent may declare. Any other key is a typed load\n// error rather than a silent drop — a dropped `sandbox` an operator wrote believing\n// it confines the child is exactly the silent-gate failure class this guards against.\nconst ACCEPTED_FIELDS = new Set([\n \"name\",\n \"description\",\n \"model\",\n \"tools\",\n \"reasoning_effort\",\n \"mcp\",\n \"sandbox\",\n]);\n\n// Fields the Claude Code CLI writes that carry NO behaviour for this runtime. Accepted and ignored,\n// so an agent authored for the CLI loads here unchanged — measured 2026-08-26 across the 59 agent\n// files on one machine, where `color` appeared in 38 of them and made every one of those a\n// `subagent_unknown_field` load error.\n//\n// Named explicitly instead of loosening the check above, because that check's reason is sound: a\n// dropped `sandbox` an operator wrote believing it confines the child is a silent gate. A field that\n// COULD change behaviour must still fail loudly. This set is the difference between \"we know this\n// one and it does nothing\" and \"we have never heard of this\" — two facts a bare allow-everything\n// would collapse into one.\n//\n// Anything added here needs the same justification: inert for THIS runtime, not merely unfamiliar.\nconst INERT_CLAUDE_CODE_FIELDS = new Set([\n /** The CLI's label colour for the agent. Presentation only. */\n \"color\",\n]);\n\nfunction parseSubagentMarkdown(\n raw: string,\n filename: string,\n): { name: string; definition: AgentDefinition } {\n const { frontmatter, body } = splitFrontmatter(raw, filename);\n const fields = parseFrontmatterFields(frontmatter);\n rejectUnknownFields(fields, filename);\n rejectMcp(fields, filename);\n\n const definition: AgentDefinition = {\n description: asString(fields.description) ?? \"\",\n prompt: body,\n };\n const model = resolveModel(fields, filename);\n if (model !== undefined) definition.model = model;\n const tools = toStringList(fields.tools);\n if (tools.length > 0) definition.tools = tools;\n const sandbox = resolveSandbox(fields, filename);\n if (sandbox !== undefined) definition.sandbox = sandbox;\n\n const name = asString(fields.name) ?? filename.replace(/\\.md$/, \"\");\n return { name, definition };\n}\n\nfunction rejectUnknownFields(\n fields: Record<string, FrontmatterValue | undefined>,\n filename: string,\n): void {\n for (const key of Object.keys(fields)) {\n if (INERT_CLAUDE_CODE_FIELDS.has(key)) continue;\n if (!ACCEPTED_FIELDS.has(key)) {\n throw new ConfigurationError(\n `Subagent ${filename}: unknown frontmatter field \"${key}\" (accepted: ${[...ACCEPTED_FIELDS].join(\", \")})`,\n { code: \"subagent_unknown_field\" },\n );\n }\n }\n}\n\n// mcp: a known field, but not yet honored on the LOCAL delegation path. The frontmatter YAML can only\n// express server NAMES (parseSimpleYaml has no nested-object support), while a child's `Agent.create`\n// needs `mcpServers` as a Record<name, config>; resolving names→config per-subagent in local delegation\n// is its own follow-up. Rather than silently drop it (the M26/M32 silent-gate class), it is a typed load\n// error that names the field and points at the alternative.\nfunction rejectMcp(fields: Record<string, FrontmatterValue | undefined>, filename: string): void {\n if (fields.mcp !== undefined) {\n throw new ConfigurationError(\n `Subagent ${filename}: per-subagent \"mcp\" is not yet supported on the local delegation path; declare MCP servers in .theokit/mcp.json (or the parent) instead`,\n { code: \"subagent_mcp_unsupported_local\" },\n );\n }\n}\n\n// model + reasoning_effort — effort rides inside `model.params[thinking]`, so it requires a concrete\n// model id to attach to (a child inheriting the parent's model cannot carry the parent's provider-\n// specific effort param safely).\nfunction resolveModel(\n fields: Record<string, FrontmatterValue | undefined>,\n filename: string,\n): ModelSelection | \"inherit\" | undefined {\n const modelId = asString(fields.model);\n const effort = asString(fields.reasoning_effort);\n // reasoning_effort rides in model.params[thinking], so it needs a CONCRETE model id to attach to.\n // Neither an absent model NOR `model: inherit` can carry it (the inherited id is unknown at load), so\n // both are typed errors rather than a silently-dropped effort — the silent-gate class this guards.\n if (effort !== undefined && (modelId === undefined || modelId === \"inherit\")) {\n throw new ConfigurationError(\n `Subagent ${filename}: reasoning_effort requires a concrete model (effort is a model parameter; an absent model or \"inherit\" cannot carry it)`,\n { code: \"subagent_reasoning_effort_without_model\" },\n );\n }\n if (modelId === undefined) return undefined;\n if (modelId === \"inherit\") return \"inherit\";\n return effort !== undefined\n ? { id: modelId, params: [{ id: \"thinking\", value: effort }] }\n : { id: modelId };\n}\n\n// sandbox: boolean only. A granular mode string (read-only/…) is unsupported by the SDK runtime and is\n// a typed error rather than a silent coercion to a boolean.\nfunction resolveSandbox(\n fields: Record<string, FrontmatterValue | undefined>,\n filename: string,\n): boolean | undefined {\n if (fields.sandbox === undefined) return undefined;\n if (typeof fields.sandbox !== \"boolean\") {\n throw new ConfigurationError(\n `Subagent ${filename}: sandbox must be a boolean (got \"${String(fields.sandbox)}\"); granular sandbox modes are not supported by the runtime`,\n { code: \"subagent_sandbox_not_boolean\" },\n );\n }\n return fields.sandbox;\n}\n\nfunction asString(v: FrontmatterValue | undefined): string | undefined {\n if (typeof v !== \"string\") return undefined;\n // parseSimpleYaml does not strip quotes (documented), and `model`/`reasoning_effort` are fields users\n // habitually quote (`model: \"openai/gpt-4o\"`). Strip a single matching surrounding quote pair so a\n // quoted id/effort does not slip past validation and fail only at the provider.\n const m = /^([\"'])(.*)\\1$/.exec(v);\n return m ? m[2] : v;\n}\n\n/** Accept a YAML list (`string[]`) or a comma/space-separated scalar; trim + drop empties. */\nfunction toStringList(v: FrontmatterValue | undefined): string[] {\n if (Array.isArray(v)) return v.map((t) => t.trim()).filter((t) => t.length > 0);\n if (typeof v === \"string\") {\n return v\n .split(/[\\s,]+/)\n .map((t) => t.trim())\n .filter((t) => t.length > 0);\n }\n return [];\n}\n\n/** Does this file open with a frontmatter block at all? Its ABSENCE means \"not an agent\". */\nfunction hasFrontmatter(raw: string): boolean {\n return /^---\\s*\\n/.test(raw);\n}\n\nfunction splitFrontmatter(raw: string, filename: string): { frontmatter: string; body: string } {\n const match = /^---\\s*\\n([\\s\\S]*?)\\n---\\s*\\n([\\s\\S]*)$/.exec(raw);\n if (match === null) {\n throw new ConfigurationError(`Subagent ${filename} is missing frontmatter`, {\n code: \"subagent_missing_frontmatter\",\n });\n }\n return { frontmatter: match[1] ?? \"\", body: (match[2] ?? \"\").trim() };\n}\n\nfunction parseFrontmatterFields(frontmatter: string): Record<string, FrontmatterValue | undefined> {\n // Preserve the rich YAML value types (boolean/number/string[]): `sandbox: true` and\n // `mcp: [a, b]` are meaningful here, so narrowing everything to string (as the\n // pre-M33 loader did) would drop them. Per-field validation happens in parseSubagentMarkdown.\n return parseSimpleYaml(frontmatter);\n}\n"]}
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { globalEmbeddingCache } from './chunk-H73MEMQB.js';
|
|
2
|
-
import { mapOpenAICompatibleError } from './chunk-
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { parseRetryAfter, mapOpenAICompatibleError } from './chunk-XB4GI5RZ.js';
|
|
3
|
+
import { computeBackoffMs } from './chunk-24MGQDK3.js';
|
|
4
|
+
import { mapWithConcurrency } from './chunk-4MMWFSCD.js';
|
|
5
|
+
import { AuthenticationError, ConfigurationError, NetworkError } from './chunk-ALUN2B4W.js';
|
|
5
6
|
import { createHash } from 'crypto';
|
|
6
7
|
|
|
7
8
|
var MAX_BATCH = 100;
|
|
8
9
|
var MAX_RETRIES = 2;
|
|
10
|
+
var EMBED_BACKOFF_BASE_MS = 250;
|
|
11
|
+
var EMBED_BACKOFF_CAP_MS = 4e3;
|
|
9
12
|
async function createOpenAiCompatibleRuntime(cfg, options) {
|
|
10
13
|
const model = options.model ?? cfg.defaultModel;
|
|
11
14
|
const apiKey = options.apiKey ?? process.env[cfg.apiKeyEnv];
|
|
@@ -132,23 +135,34 @@ async function embedBatch(opts) {
|
|
|
132
135
|
if (isRetryable(response.status) && attempt < MAX_RETRIES) {
|
|
133
136
|
attempt += 1;
|
|
134
137
|
opts.stats.retries += 1;
|
|
135
|
-
|
|
138
|
+
const retryAfterSec = parseRetryAfter(response.headers);
|
|
139
|
+
await sleep(
|
|
140
|
+
computeBackoffMs({
|
|
141
|
+
attempt,
|
|
142
|
+
baseMs: EMBED_BACKOFF_BASE_MS,
|
|
143
|
+
capMs: EMBED_BACKOFF_CAP_MS,
|
|
144
|
+
...retryAfterSec !== void 0 ? { retryAfterMs: retryAfterSec * 1e3 } : {}
|
|
145
|
+
})
|
|
146
|
+
);
|
|
136
147
|
continue;
|
|
137
148
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
body,
|
|
148
|
-
headers: response.headers,
|
|
149
|
-
endpoint: opts.embeddingsPath
|
|
150
|
-
});
|
|
149
|
+
throw await mappedEmbedError(opts, response);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
async function mappedEmbedError(opts, response) {
|
|
153
|
+
const text = await response.text().catch(() => "");
|
|
154
|
+
let body = text;
|
|
155
|
+
try {
|
|
156
|
+
body = JSON.parse(text);
|
|
157
|
+
} catch {
|
|
151
158
|
}
|
|
159
|
+
return mapOpenAICompatibleError({
|
|
160
|
+
providerId: opts.providerId,
|
|
161
|
+
status: response.status,
|
|
162
|
+
body,
|
|
163
|
+
headers: response.headers,
|
|
164
|
+
endpoint: opts.embeddingsPath
|
|
165
|
+
});
|
|
152
166
|
}
|
|
153
167
|
async function postEmbedRequest(opts, url) {
|
|
154
168
|
return opts.fetchImpl(url, {
|
|
@@ -185,13 +199,10 @@ function isRetryable(status) {
|
|
|
185
199
|
function hashKey(model, text) {
|
|
186
200
|
return createHash("sha256").update(`${model} ${text}`).digest("hex");
|
|
187
201
|
}
|
|
188
|
-
function linearBackoffMs(attempt) {
|
|
189
|
-
return 50 * attempt;
|
|
190
|
-
}
|
|
191
202
|
function sleep(ms) {
|
|
192
203
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
193
204
|
}
|
|
194
205
|
|
|
195
206
|
export { createOpenAiCompatibleRuntime };
|
|
196
|
-
//# sourceMappingURL=chunk-
|
|
197
|
-
//# sourceMappingURL=chunk-
|
|
207
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MAAM,QAAA,CAAS,IAAA,EAAK;AAElC,EAAA,MAAM,UAAA,GAAa,OAAA,EAAS,OAAA,GAAU,IAAI,CAAA;AAC1C,EAAA,IAAI,UAAA,KAAe,QAAW,OAAO,UAAA;AACrC,EAAA,IAAI,CAAC,KAAA,CAAM,OAAA,CAAQ,IAAA,CAAK,IAAI,CAAA,EAAG;AAC7B,IAAA,MAAM,IAAI,YAAA,CAAa,CAAA,EAAG,UAAU,CAAA,CAAA,EAAI,QAAQ,CAAA,iBAAA,CAAA,EAAqB;AAAA,MACnE,IAAA,EAAM,4BAAA;AAAA,MACN,QAAA,EAAU;AAAA,QACR,QAAA,EAAU,UAAA;AAAA,QACV,QAAA;AAAA,QACA,IAAA,EAAM,iBAAA;AAAA,QACN,GAAA,EAAK;AAAA;AACP,KACD,CAAA;AAAA,EACH;AACA,EAAA,OAAO,KAAK,IAAA,CAAK,GAAA,CAAI,CAAC,CAAA,KAAM,EAAE,SAAS,CAAA;AACzC;AAEA,SAAS,YAAY,MAAA,EAAyB;AAC5C,EAAA,OAAO,MAAA,KAAW,GAAA,IAAQ,MAAA,IAAU,GAAA,IAAO,MAAA,GAAS,GAAA;AACtD;AAEA,SAAS,OAAA,CAAQ,OAAe,IAAA,EAAsB;AACpD,EAAA,OAAO,UAAA,CAAW,QAAQ,CAAA,CAAE,MAAA,CAAO,CAAA,EAAG,KAAK,CAAA,CAAA,EAAI,IAAI,CAAA,CAAE,CAAA,CAAE,MAAA,CAAO,KAAK,CAAA;AACrE;AAWA,SAAS,MAAM,EAAA,EAA2B;AACxC,EAAA,OAAO,IAAI,OAAA,CAAQ,CAAC,YAAY,UAAA,CAAW,OAAA,EAAS,EAAE,CAAC,CAAA;AACzD","file":"chunk-55GB6JYQ.js","sourcesContent":["import { createHash } from \"node:crypto\";\n\nimport { AuthenticationError, ConfigurationError, NetworkError } from \"../../../errors.js\";\nimport { mapWithConcurrency } from \"../../concurrency/map-with-concurrency.js\";\nimport { mapOpenAICompatibleError } from \"../../error-mappers/openai-compatible.js\";\nimport { parseRetryAfter } from \"../../error-mappers/shared.js\";\nimport { computeBackoffMs } from \"../../llm/retry.js\";\nimport type {\n CreateAdapterOptions,\n EmbeddingRuntime,\n EmbeddingRuntimeStats,\n} from \"../embedding-adapter.js\";\nimport { globalEmbeddingCache } from \"../embedding-cache.js\";\n\n/**\n * Shared factory for OpenAI-compatible embedding providers (OpenAI, Mistral,\n * DeepInfra, and anything else exposing `POST /v1/embeddings` with the\n * `{ model, input }` request shape and `{ data: [{ embedding }] }` response).\n *\n * Mirrors the inner mechanics of peer-project's batch embedding runtime.\n *\n * @internal\n */\n\nconst MAX_BATCH = 100;\nconst MAX_RETRIES = 2;\n/**\n * Deliberately tighter than the transport's 500ms/32s.\n *\n * An embedding retry sits inside a memory write on the agent's critical path and cannot be\n * cancelled (see `sleep` below), so the worst case has to be small enough to wait out: 2 retries\n * capped at 4s is at most ~8s. The transport can afford 32s because a streaming turn is already\n * long-running and IS abortable.\n */\nconst EMBED_BACKOFF_BASE_MS = 250;\nconst EMBED_BACKOFF_CAP_MS = 4_000;\n\n/**\n * What one provider adapter tells {@link createOpenAiCompatibleRuntime} about\n * its wire: where to POST, which environment variables carry the key and the\n * base URL, which model to use by default, and how wide each model's vectors\n * are.\n *\n * `id` is the provider id that ends up on errors and on\n * `EmbeddingRuntime.id`, and is also the identity the SQLite vector index stores\n * — changing it invalidates the vectors already on disk.\n *\n * `apiKeyEnv` is required, `baseUrlEnv` is not: a provider that declares no\n * base-URL variable can only be redirected by passing `baseUrl` explicitly.\n * Leave `dialect` unset for anything that speaks the OpenAI embedding wire.\n */\nexport interface OpenAiCompatibleConfig {\n id: string;\n defaultBaseUrl: string;\n apiKeyEnv: string;\n baseUrlEnv?: string;\n defaultModel: string;\n /**\n * Dimension hint by model id. The chosen model MUST be in this table —\n * unknown models throw `ConfigurationError(code: \"embedding_unknown_model\")`\n * (EC-4 fix). This prevents vec0 virtual-table dimension mismatches that\n * surface as cryptic errors downstream.\n */\n dimensionByModel: Record<string, number>;\n /**\n * Path component appended to `baseUrl` for the embeddings endpoint.\n * Default `\"/v1/embeddings\"` (OpenAI canonical). REPLACES the default —\n * does NOT concatenate. Used by DeepInfra (`\"/v1/openai/embeddings\"`),\n * etc. (EC-2 fix).\n */\n embeddingsPath?: string;\n /**\n * theokit#159 — per-provider deviations from the OpenAI wire.\n *\n * The runtime was rigidly OpenAI-shaped: one auth header, one body, one response shape. Three of\n * the ten catalog providers do not speak it, so every call they made was rejected — Azure\n * authenticates with an `api-key` header and puts the deployment in the path, Cohere's `/v2/embed`\n * takes `texts` and answers `{embeddings:{float}}`. Advertising a provider that cannot work is\n * worse than not advertising it.\n *\n * Every hook is optional and its default is exactly the previous behaviour, so the seven\n * providers that DO speak OpenAI are untouched.\n */\n dialect?: EmbeddingDialect;\n}\n\n/**\n * theokit#159 — the three points where a provider may deviate from the OpenAI embedding wire.\n *\n * Deliberately three narrow hooks rather than a general \"transform the request\" seam: these are the\n * only axes on which the supported providers actually differ, and a wider seam would invite\n * per-provider logic that belongs in the adapter.\n */\nexport interface EmbeddingDialect {\n /** Replaces `authorization: Bearer <key>`. */\n authHeaders?: (apiKey: string) => Record<string, string>;\n /** Replaces the `{ model, input }` request body. */\n body?: (model: string, inputs: ReadonlyArray<string>) => Record<string, unknown>;\n /** Replaces reading vectors from `json.data[].embedding`. Return `undefined` when unparseable. */\n vectors?: (json: unknown) => number[][] | undefined;\n}\n\n/**\n * Build an {@link EmbeddingRuntime} for a provider that speaks the OpenAI\n * embedding wire — or, through `cfg.dialect`, one that deviates from it in a\n * known way. Every adapter in the memory catalog is a thin call to this.\n *\n * Resolution order for each setting is explicit option, then environment\n * variable, then the config default. Two things are checked before any request\n * is sent, so a misconfiguration fails at creation rather than at first search:\n * a missing or empty key rejects with an `AuthenticationError` carrying\n * `embedding_missing_api_key`, and a model absent from `dimensionByModel`\n * rejects with a `ConfigurationError` carrying `embedding_unknown_model`. The\n * second check exists because the vector index is created at a fixed width — an\n * unknown dimension would surface much later as a vec0 mismatch.\n *\n * `{model}` in `embeddingsPath` is replaced with the URL-encoded model, which is\n * how Azure addresses a deployment in the path. `embeddingsPath` replaces the\n * default `/v1/embeddings` rather than being appended to it.\n *\n * The returned `embed` batches at 100 texts per request and runs at most 3\n * requests concurrently, preserving input order. Whitespace-only inputs never\n * reach the network and come back as an all-zero vector. Results are cached by\n * model and text; the cache defaults to a process-wide LRU of 5000 entries, so\n * pass `options.cache` when runtimes must not share entries.\n *\n * Failed requests retry up to twice on 429 and 5xx with a 50ms-per-attempt\n * linear backoff. Anything else, and a retry budget that runs out, throws the\n * typed error the OpenAI-compatible mapper builds from the status and body. A\n * response that parses but carries no vectors throws a `NetworkError` with\n * `embedding_invalid_response`. There is no request timeout here — cancellation\n * is the caller's to impose.\n */\nexport async function createOpenAiCompatibleRuntime(\n cfg: OpenAiCompatibleConfig,\n options: CreateAdapterOptions,\n): Promise<EmbeddingRuntime> {\n const model = options.model ?? cfg.defaultModel;\n const apiKey = options.apiKey ?? process.env[cfg.apiKeyEnv];\n if (apiKey === undefined || apiKey.length === 0) {\n throw new AuthenticationError(`${cfg.apiKeyEnv} missing`, {\n code: \"embedding_missing_api_key\",\n });\n }\n const envBaseUrl = cfg.baseUrlEnv !== undefined ? process.env[cfg.baseUrlEnv] : undefined;\n const baseUrl = options.baseUrl ?? envBaseUrl ?? cfg.defaultBaseUrl;\n const fetchImpl = options.fetch ?? fetch;\n // T4.4 — default to process-wide singleton (was per-adapter instance).\n const cache = options.cache ?? globalEmbeddingCache;\n // EC-4: refuse unknown models to prevent vec0 dimension mismatches downstream.\n const dimension = cfg.dimensionByModel[model];\n if (dimension === undefined) {\n throw new ConfigurationError(\n `${cfg.id} adapter: model \"${model}\" is not in the dimension table. Use one of: ${Object.keys(cfg.dimensionByModel).join(\", \")}. To add it, update dimensionByModel in the adapter source.`,\n { code: \"embedding_unknown_model\" },\n );\n }\n // theokit#128: `{model}` is substituted, because Azure OpenAI addresses the deployment IN THE\n // PATH (`/openai/deployments/{model}/embeddings`) rather than in the body. Without this the URL\n // carried the literal placeholder and every Azure request 404'd. A path with no placeholder —\n // every other provider — is passed through untouched.\n const embeddingsPath = (cfg.embeddingsPath ?? \"/v1/embeddings\").replace(\n \"{model}\",\n encodeURIComponent(model),\n );\n\n const stats: EmbeddingRuntimeStats = {\n cacheHits: 0,\n cacheMisses: 0,\n httpCalls: 0,\n retries: 0,\n };\n\n return {\n id: cfg.id,\n model,\n dimension,\n stats: () => ({ ...stats }),\n embed: (texts) =>\n embedTexts({\n texts,\n cache,\n stats,\n model,\n dimension,\n apiKey,\n baseUrl,\n embeddingsPath,\n fetchImpl,\n providerId: cfg.id,\n dialect: cfg.dialect ?? {},\n }),\n };\n}\n\ninterface EmbedTextsInput {\n texts: ReadonlyArray<string>;\n cache: NonNullable<CreateAdapterOptions[\"cache\"]>;\n stats: EmbeddingRuntimeStats;\n model: string;\n dimension: number;\n apiKey: string;\n baseUrl: string;\n embeddingsPath: string;\n fetchImpl: typeof fetch;\n providerId: string;\n dialect: EmbeddingDialect;\n}\n\nasync function embedTexts(input: EmbedTextsInput): Promise<number[][]> {\n const { texts, cache, stats, model, dimension } = input;\n const results = new Array<number[] | undefined>(texts.length);\n const pending: Array<{ index: number; text: string; key: string }> = [];\n for (let i = 0; i < texts.length; i++) {\n classifyEntry({\n index: i,\n text: texts[i] ?? \"\",\n model,\n dimension,\n cache,\n stats,\n results,\n pending,\n });\n }\n await embedInBoundedBatches(input, pending, results);\n return results.map((v) => v ?? new Array(dimension).fill(0));\n}\n\ninterface ClassifyEntryArgs {\n index: number;\n text: string;\n model: string;\n dimension: number;\n cache: NonNullable<CreateAdapterOptions[\"cache\"]>;\n stats: EmbeddingRuntimeStats;\n results: Array<number[] | undefined>;\n pending: Array<{ index: number; text: string; key: string }>;\n}\n\nfunction classifyEntry(args: ClassifyEntryArgs): void {\n if (args.text.trim().length === 0) {\n args.results[args.index] = new Array(args.dimension).fill(0);\n return;\n }\n const key = hashKey(args.model, args.text);\n const cached = args.cache.get(key);\n if (cached !== undefined) {\n args.stats.cacheHits += 1;\n args.results[args.index] = cached;\n return;\n }\n args.stats.cacheMisses += 1;\n args.pending.push({ index: args.index, text: args.text, key });\n}\n\n// T4.3 — max concurrent embedding API requests per embed() call.\n// 3 is enough to saturate most embedding APIs without triggering\n// rate limits (each batch is already up to MAX_BATCH=100 texts).\nconst MAX_CONCURRENT_BATCHES = 3;\n\n/**\n * T4.3 — parallel embed batches (DR4 finding #3).\n *\n * Pre-T4.3 this was a serial `for` loop — each batch of 100 texts\n * awaited before the next HTTP request started. With 500 texts the\n * serial path took 5 × RTT; parallel takes max(RTT) × ceil(5/3).\n *\n * Uses bounded-concurrency `Promise.all` capped at 3 concurrent\n * HTTP requests to avoid overwhelming the embedding API.\n */\nasync function embedInBoundedBatches(\n input: EmbedTextsInput,\n pending: ReadonlyArray<{ index: number; text: string; key: string }>,\n results: Array<number[] | undefined>,\n): Promise<void> {\n const batches: Array<ReadonlyArray<{ index: number; text: string; key: string }>> = [];\n for (let offset = 0; offset < pending.length; offset += MAX_BATCH) {\n batches.push(pending.slice(offset, offset + MAX_BATCH));\n }\n // M0-2: bounded parallel via the shared ordered pool (was an inline\n // acquire/release clone — see plan m0-foundation-expose-primitives).\n await mapWithConcurrency(batches, MAX_CONCURRENT_BATCHES, (batch) =>\n processBatch(input, batch, results),\n );\n}\n\nasync function processBatch(\n input: EmbedTextsInput,\n batch: ReadonlyArray<{ index: number; text: string; key: string }>,\n results: Array<number[] | undefined>,\n): Promise<void> {\n const vectors = await embedBatch({\n apiKey: input.apiKey,\n baseUrl: input.baseUrl,\n embeddingsPath: input.embeddingsPath,\n model: input.model,\n inputs: batch.map((b) => b.text),\n fetchImpl: input.fetchImpl,\n stats: input.stats,\n providerId: input.providerId,\n dialect: input.dialect,\n });\n for (let j = 0; j < batch.length; j++) {\n const slot = batch[j];\n const vector = vectors[j];\n if (slot === undefined || vector === undefined) continue;\n results[slot.index] = vector;\n input.cache.set(slot.key, vector);\n }\n}\n\ninterface BatchOptions {\n apiKey: string;\n baseUrl: string;\n embeddingsPath: string;\n model: string;\n inputs: ReadonlyArray<string>;\n fetchImpl: typeof fetch;\n stats: EmbeddingRuntimeStats;\n providerId: string;\n dialect: EmbeddingDialect;\n}\n\nasync function embedBatch(opts: BatchOptions): Promise<number[][]> {\n // EC-2: embeddingsPath REPLACES the suffix; never concatenates.\n const url = `${opts.baseUrl.replace(/\\/$/, \"\")}${opts.embeddingsPath}`;\n let attempt = 0;\n while (true) {\n opts.stats.httpCalls += 1;\n const response = await postEmbedRequest(opts, url);\n if (response.ok)\n return await parseEmbedResponse(response, opts.providerId, opts.embeddingsPath, opts.dialect);\n if (isRetryable(response.status) && attempt < MAX_RETRIES) {\n attempt += 1;\n opts.stats.retries += 1;\n const retryAfterSec = parseRetryAfter(response.headers);\n await sleep(\n computeBackoffMs({\n attempt,\n baseMs: EMBED_BACKOFF_BASE_MS,\n capMs: EMBED_BACKOFF_CAP_MS,\n ...(retryAfterSec !== undefined ? { retryAfterMs: retryAfterSec * 1000 } : {}),\n }),\n );\n continue;\n }\n throw await mappedEmbedError(opts, response);\n }\n}\n\n/**\n * The terminal failure: read the body best-effort so the mapper sees the provider's error code, then\n * map it. Its own function because folding it back into the retry loop puts `embedBatch` at\n * cognitive complexity 11 against the repo max of 10 — and the sibling budget for those suppressions\n * is ratcheting DOWN, so adding one here to keep this loop whole would undo that.\n */\nasync function mappedEmbedError(opts: BatchOptions, response: Response): Promise<unknown> {\n const text = await response.text().catch(() => \"\");\n let body: unknown = text;\n try {\n body = JSON.parse(text);\n } catch {\n // not JSON — keep as string\n }\n return mapOpenAICompatibleError({\n providerId: opts.providerId,\n status: response.status,\n body,\n headers: response.headers,\n endpoint: opts.embeddingsPath,\n });\n}\n\nasync function postEmbedRequest(opts: BatchOptions, url: string): Promise<Response> {\n return opts.fetchImpl(url, {\n method: \"POST\",\n headers: {\n \"content-type\": \"application/json\",\n ...(opts.dialect.authHeaders?.(opts.apiKey) ?? { authorization: `Bearer ${opts.apiKey}` }),\n },\n body: JSON.stringify(\n opts.dialect.body?.(opts.model, opts.inputs) ?? { model: opts.model, input: opts.inputs },\n ),\n });\n}\n\nasync function parseEmbedResponse(\n response: Response,\n providerId: string,\n endpoint: string,\n dialect?: EmbeddingDialect,\n): Promise<number[][]> {\n const json = (await response.json()) as { data?: Array<{ embedding: number[] }> };\n // theokit#159 — a provider whose response is not OpenAI-shaped supplies its own reader.\n const viaDialect = dialect?.vectors?.(json);\n if (viaDialect !== undefined) return viaDialect;\n if (!Array.isArray(json.data)) {\n throw new NetworkError(`${providerId} ${endpoint} returned no data`, {\n code: \"embedding_invalid_response\",\n metadata: {\n provider: providerId,\n endpoint,\n code: \"invalid_request\",\n raw: json,\n },\n });\n }\n return json.data.map((d) => d.embedding);\n}\n\nfunction isRetryable(status: number): boolean {\n return status === 429 || (status >= 500 && status < 600);\n}\n\nfunction hashKey(model: string, text: string): string {\n return createHash(\"sha256\").update(`${model} ${text}`).digest(\"hex\");\n}\n\n/**\n * Not `sleepWithAbort`, and the reason is the parsimony ladder rather than an oversight.\n *\n * `EmbeddingRuntime.embed(texts)` takes no signal, and NONE of its seven callers — lance-index,\n * index-manager, vec-index, the two dreaming phases, scorers — holds one to pass. Adding the\n * parameter would add a seam nobody supplies, so cancellation is bounded instead of plumbed: at most\n * MAX_RETRIES sleeps of at most EMBED_BACKOFF_CAP_MS each. Give `embed()` a signal on the day a\n * caller has one, and this becomes `sleepWithAbort` in the same edit.\n */\nfunction sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n"]}
|
|
@@ -1,15 +1,9 @@
|
|
|
1
|
-
import { setupStructuredOutput, makeOutputTool, buildTransientAgentOptions, buildToolPrompt, extractUsage, disposeAndDeleteTransient } from './chunk-
|
|
1
|
+
import { setupStructuredOutput, makeOutputTool, buildTransientAgentOptions, buildToolPrompt, extractUsage, STRUCTURED_OUTPUT_MESSAGES, disposeAndDeleteTransient } from './chunk-47TF32NQ.js';
|
|
2
|
+
import { StructuredOutputError } from './chunk-ALUN2B4W.js';
|
|
2
3
|
|
|
3
4
|
// src/stream-object.ts
|
|
4
|
-
var StreamObjectError = class extends
|
|
5
|
+
var StreamObjectError = class extends StructuredOutputError {
|
|
5
6
|
name = "StreamObjectError";
|
|
6
|
-
code;
|
|
7
|
-
cause;
|
|
8
|
-
constructor(code, message, cause) {
|
|
9
|
-
super(message);
|
|
10
|
-
this.code = code;
|
|
11
|
-
if (cause !== void 0) this.cause = cause;
|
|
12
|
-
}
|
|
13
7
|
};
|
|
14
8
|
async function* streamObjectImpl(options, deps) {
|
|
15
9
|
const { jsonSchema, maxRetries, initialUsage } = setupStructuredOutput(
|
|
@@ -64,15 +58,12 @@ async function* streamObjectImpl(options, deps) {
|
|
|
64
58
|
if (result.status === "error" && result.error !== void 0) {
|
|
65
59
|
throw new StreamObjectError(
|
|
66
60
|
"no_tool_call",
|
|
67
|
-
|
|
61
|
+
STRUCTURED_OUTPUT_MESSAGES.runFailed(result.error.message, result.error.code),
|
|
68
62
|
result.error
|
|
69
63
|
);
|
|
70
64
|
}
|
|
71
65
|
if (attempt === maxRetries) {
|
|
72
|
-
throw new StreamObjectError(
|
|
73
|
-
"no_tool_call",
|
|
74
|
-
"The model returned text instead of calling the `output` tool."
|
|
75
|
-
);
|
|
66
|
+
throw new StreamObjectError("no_tool_call", STRUCTURED_OUTPUT_MESSAGES.noToolCall);
|
|
76
67
|
}
|
|
77
68
|
continue;
|
|
78
69
|
}
|
|
@@ -91,7 +82,7 @@ async function* streamObjectImpl(options, deps) {
|
|
|
91
82
|
}
|
|
92
83
|
throw new StreamObjectError(
|
|
93
84
|
"parse_failed",
|
|
94
|
-
|
|
85
|
+
STRUCTURED_OUTPUT_MESSAGES.parseFailed,
|
|
95
86
|
lastParseError
|
|
96
87
|
);
|
|
97
88
|
} finally {
|
|
@@ -141,5 +132,5 @@ function bestEffortPartialParse(text, schema) {
|
|
|
141
132
|
}
|
|
142
133
|
|
|
143
134
|
export { StreamObjectError, streamObjectImpl };
|
|
144
|
-
//# sourceMappingURL=chunk-
|
|
145
|
-
//# sourceMappingURL=chunk-
|
|
135
|
+
//# sourceMappingURL=chunk-5WKQDIGO.js.map
|
|
136
|
+
//# sourceMappingURL=chunk-5WKQDIGO.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/stream-object.ts"],"names":[],"mappings":";;;;AAgFO,IAAM,iBAAA,GAAN,cAAgC,qBAAA,CAAsB;AAAA,EACzC,IAAA,GAAO,mBAAA;AAC3B;AAkCA,gBAAuB,gBAAA,CACrB,SACA,IAAA,EACsE;AACtE,EAAA,MAAM,EAAE,UAAA,EAAY,UAAA,EAAY,YAAA,EAAa,GAAI,qBAAA;AAAA,IAC/C,OAAA,CAAQ,MAAA;AAAA,IACR,OAAA,CAAQ;AAAA,GACV;AACA,EAAA,IAAI,WAAA;AACJ,EAAA,IAAI,SAAA,GAAY,YAAA;AAEhB,EAAA,MAAM,UAAA,GAAa,cAAA,CAAe,UAAA,EAAY,CAAC,KAAA,KAAU;AAEvD,IAAA,IAAI,gBAAgB,MAAA,EAAW;AAC7B,MAAA,WAAA,GAAc,KAAA;AAAA,IAChB;AACA,IAAA,OAAO,IAAA,CAAK,SAAA,CAAU,EAAE,EAAA,EAAI,MAAM,CAAA;AAAA,EACpC,CAAC,CAAA;AAED,EAAA,MAAM,eAA6B,0BAAA,CAA2B;AAAA,IAC5D,OAAO,OAAA,CAAQ,KAAA;AAAA,IACf,OAAO,OAAA,CAAQ,KAAA;AAAA,IACf,UAAA;AAAA,IACA,GAAI,QAAQ,YAAA,KAAiB,MAAA,GAAY,EAAE,YAAA,EAAc,OAAA,CAAQ,YAAA,EAAa,GAAI,EAAC;AAAA,IACnF,GAAI,QAAQ,MAAA,KAAW,MAAA,GAAY,EAAE,MAAA,EAAQ,OAAA,CAAQ,MAAA,EAAO,GAAI,EAAC;AAAA,IACjE,GAAI,QAAQ,SAAA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cAAc,OAAO,YAAA,KAAiB,aAAa,YAAA,CAAa,IAAA,CAAK,MAAM,CAAA,GAAI,MAAA;AACrF,EAAA,MAAM,MAAA,GAAS,WAAA,CAAY,SAAA,CAAU,MAAM,CAAA;AAC3C,EAAA,OAAO,MAAA,CAAO,OAAA,GAAU,MAAA,CAAO,IAAA,GAAO,MAAA;AACxC","file":"chunk-5WKQDIGO.js","sourcesContent":["import type { z as ZodNamespace, ZodType } from \"zod\";\nimport { StructuredOutputError } from \"./errors.js\";\nimport {\n buildToolPrompt,\n buildTransientAgentOptions,\n disposeAndDeleteTransient,\n extractUsage,\n makeOutputTool,\n STRUCTURED_OUTPUT_MESSAGES,\n setupStructuredOutput,\n} from \"./internal/structured-output-helpers.js\";\nimport type { AgentOptions, LocalOptions, ModelSelection, SDKAgent } from \"./types/agent.js\";\nimport type { ProviderRoutingSettings } from \"./types/providers.js\";\n\n/**\n * Options accepted by {@link Agent.streamObject}. Same shape as\n * `Agent.generateObject` with the addition that the result is an\n * `AsyncIterator<StreamObjectEvent<T>>` rather than a single Promise. See ADR D39.\n *\n * @public\n */\nexport interface StreamObjectOptions<T extends ZodType> {\n schema: T;\n prompt: string;\n systemPrompt?: string;\n /** SE8 — accepts a bare-string id shorthand or a {@link ModelSelection}. */\n model: string | ModelSelection;\n apiKey?: string;\n local: LocalOptions;\n maxRetries?: number;\n /**\n * Optional provider routing forwarded to the transient agent. Required when\n * `model.id` uses a prefix (e.g. `openai/gpt-4o-mini`) but the credential is\n * for a unified gateway (e.g. OpenRouter). Without this, the SDK infers\n * provider from the prefix and may fail with `provider_unresolved` even\n * when the right env key is set under a different provider name.\n */\n providers?: ProviderRoutingSettings;\n}\n\n/**\n * Recursive partial — `T` where every nested field becomes optional.\n *\n * @public\n */\nexport type DeepPartial<T> = T extends (infer U)[]\n ? Array<DeepPartial<U>>\n : T extends object\n ? { [K in keyof T]?: DeepPartial<T[K]> }\n : T;\n\n/**\n * Event emitted by {@link Agent.streamObject}. Discriminate on `type`.\n *\n * - `partial` events fire zero or more times with monotonically increasing\n * `attempt`, carrying best-effort schema-parsed snapshots of the model's\n * accumulating output.\n * - `complete` fires exactly once at the end, carrying the fully Zod-parsed\n * object alongside usage and finishReason — semantically identical to a\n * successful `Agent.generateObject()` return.\n *\n * @public\n */\nexport type StreamObjectEvent<T> =\n | { type: \"partial\"; partial: DeepPartial<T>; attempt: number }\n | {\n type: \"complete\";\n object: T;\n raw: unknown;\n usage: { inputTokens: number; outputTokens: number };\n finishReason: \"tool_use\" | \"error\";\n };\n\n/**\n * Error thrown by {@link Agent.streamObject} when the model refuses to call\n * the synthetic `output` tool or when all retries fail to produce a\n * schema-valid object. Same code taxonomy as `GenerateObjectError`.\n *\n * @public\n */\nexport class StreamObjectError extends StructuredOutputError {\n override readonly name = \"StreamObjectError\";\n}\n\ninterface StreamObjectDeps {\n create: (options: AgentOptions) => Promise<SDKAgent>;\n delete: (agentId: string) => Promise<void>;\n}\n\n/**\n * Implementation of `Agent.streamObject` as an async generator. Mirrors the\n * synthetic-forced-tool pattern from `generate-object.ts` (ADR D33) with the\n * addition of intermediate `partial` events emitted from incremental parsing\n * of accumulating text deltas during the agent loop.\n *\n * REACHED BY DYNAMIC IMPORT — do not delete on a dead-code report (B-140).\n * `agent.ts` loads this module lazily to keep it off the eager path:\n *\n * streamObjectImport ??= import(\"./stream-object.js\");\n * const { streamObjectImpl } = await streamObjectImport;\n *\n * `knip` resolves imports statically and does not follow a destructure off a\n * dynamic-import promise, so it reports this export as unused on every run. It\n * is not: removing it breaks `Agent.streamObject`. The `@knipignore` tag below\n * silences that one false positive — a tool limitation, not a suppression of a\n * real finding, and the difference is the whole reason this comment exists.\n *\n * The tag replaced a whole-file entry in `knip.json`'s ignore list, which also\n * excluded the four other exports in this file from dead-code analysis. The tag\n * is scoped to the symbol knip actually cannot resolve, so the rest of the file\n * is examined again.\n *\n * @knipignore reached only via `await import()` in agent.ts; knip cannot follow it\n * @internal\n */\n// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: streaming loop interleaves text-delta accumulation, partial-parse attempts, retries, and final dispose — splitting harms locality of the iterator contract.\nexport async function* streamObjectImpl<T extends ZodType>(\n options: StreamObjectOptions<T>,\n deps: StreamObjectDeps,\n): AsyncGenerator<StreamObjectEvent<ZodNamespace.infer<T>>, void, void> {\n const { jsonSchema, maxRetries, initialUsage } = setupStructuredOutput(\n options.schema,\n options.maxRetries,\n );\n let capturedRaw: unknown;\n let lastUsage = initialUsage;\n\n const outputTool = makeOutputTool(jsonSchema, (input) => {\n // EC-6: first capture wins (parallel tool use in Claude 3.5+).\n if (capturedRaw === undefined) {\n capturedRaw = input;\n }\n return JSON.stringify({ ok: true });\n });\n\n const agentOptions: AgentOptions = buildTransientAgentOptions({\n model: options.model,\n local: options.local,\n outputTool,\n ...(options.systemPrompt !== undefined ? { systemPrompt: options.systemPrompt } : {}),\n ...(options.apiKey !== undefined ? { apiKey: options.apiKey } : {}),\n ...(options.providers !== undefined ? { providers: options.providers } : {}),\n });\n const agent = await deps.create(agentOptions);\n const userMessage = buildToolPrompt(options.prompt);\n\n try {\n let lastParseError: unknown;\n let attemptCounter = 0;\n\n for (let attempt = 0; attempt <= maxRetries; attempt += 1) {\n capturedRaw = undefined;\n const run = await agent.send(userMessage);\n\n // Buffer text deltas during streaming; try partial-parse on each.\n let textBuffer = \"\";\n for await (const msg of run.stream()) {\n if (msg.type === \"assistant\") {\n const newText = msg.message.content\n .filter((c): c is { type: \"text\"; text: string } => c.type === \"text\")\n .map((c) => c.text)\n .join(\"\");\n if (newText.length > 0) {\n textBuffer += newText;\n const partial = bestEffortPartialParse(textBuffer, options.schema);\n if (partial !== undefined) {\n attemptCounter += 1;\n yield {\n type: \"partial\",\n partial: partial as DeepPartial<ZodNamespace.infer<T>>,\n attempt: attemptCounter,\n };\n }\n }\n }\n }\n const result = await run.wait();\n lastUsage = extractUsage(result);\n\n if (capturedRaw === undefined) {\n // EC: when the underlying run errored (e.g. provider_unresolved),\n // surface the original cause instead of the misleading \"model\n // returned text\" message — there was no model call at all.\n if (result.status === \"error\" && result.error !== undefined) {\n throw new StreamObjectError(\n \"no_tool_call\",\n STRUCTURED_OUTPUT_MESSAGES.runFailed(result.error.message, result.error.code),\n result.error,\n );\n }\n if (attempt === maxRetries) {\n throw new StreamObjectError(\"no_tool_call\", STRUCTURED_OUTPUT_MESSAGES.noToolCall);\n }\n continue;\n }\n\n const parsed = options.schema.safeParse(capturedRaw);\n if (parsed.success) {\n yield {\n type: \"complete\",\n object: parsed.data,\n raw: capturedRaw,\n usage: lastUsage,\n finishReason: \"tool_use\",\n };\n return;\n }\n lastParseError = parsed.error;\n }\n\n throw new StreamObjectError(\n \"parse_failed\",\n STRUCTURED_OUTPUT_MESSAGES.parseFailed,\n lastParseError,\n );\n } finally {\n // EC-4: even if consumer calls iter.return() mid-stream, this finally\n // runs — transient agent is disposed AND removed from registry.\n await disposeAndDeleteTransient(agent, deps.delete);\n }\n}\n\n/**\n * Try to extract a partial JSON object from a possibly-incomplete text\n * buffer and parse it via the schema in lenient mode. Returns `undefined`\n * if nothing parseable is found yet.\n *\n * Strategy: find the first `{`, find the LAST balanced `}` (greedy), parse\n * the substring as JSON, then `safeParse` against `schema.partial()` if the\n * schema supports it, else against the original schema.\n *\n * @internal\n */\n// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: stateful JSON-balancing scanner — string/brace/escape state must be co-located for the parser to remain correct.\nfunction bestEffortPartialParse<T extends ZodType>(text: string, schema: T): unknown | undefined {\n const start = text.indexOf(\"{\");\n if (start < 0) return undefined;\n // Find the longest balanced JSON object from `start`.\n let depth = 0;\n let inString = false;\n let isEscaped = false;\n let end = -1;\n for (let i = start; i < text.length; i += 1) {\n const ch = text[i];\n if (isEscaped) {\n isEscaped = false;\n continue;\n }\n if (ch === \"\\\\\" && inString) {\n isEscaped = true;\n continue;\n }\n if (ch === '\"') {\n inString = !inString;\n continue;\n }\n if (inString) continue;\n if (ch === \"{\") depth += 1;\n else if (ch === \"}\") {\n depth -= 1;\n if (depth === 0) end = i;\n }\n }\n if (end < 0) return undefined;\n const candidate = text.slice(start, end + 1);\n let parsed: unknown;\n try {\n parsed = JSON.parse(candidate);\n } catch {\n return undefined;\n }\n // Try schema.partial() if available (Zod objects support it); else fall\n // back to the original schema (loose match).\n const maybePartial = (schema as unknown as { partial?: () => ZodType }).partial;\n const looseSchema = typeof maybePartial === \"function\" ? maybePartial.call(schema) : schema;\n const result = looseSchema.safeParse(parsed);\n return result.success ? result.data : undefined;\n}\n"]}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { diag } from './chunk-CZJ6Q7CW.js';
|
|
2
|
+
import { homedir } from 'os';
|
|
3
|
+
import { join } from 'path';
|
|
4
|
+
import { existsSync } from 'fs';
|
|
5
|
+
|
|
6
|
+
var THEOKIT_DIR_LITERAL = ".theokit";
|
|
7
|
+
var CLAUDE_DIR_NAME = ".claude";
|
|
8
|
+
var NATIVE_SOURCE = {
|
|
9
|
+
kind: "theokit",
|
|
10
|
+
dirName: THEOKIT_DIR_LITERAL,
|
|
11
|
+
runtimeEnv: () => ({})
|
|
12
|
+
};
|
|
13
|
+
var CLAUDE_CODE_SOURCE = {
|
|
14
|
+
kind: "claude-code",
|
|
15
|
+
dirName: CLAUDE_DIR_NAME,
|
|
16
|
+
runtimeEnv: (cwd) => ({ CLAUDE_PROJECT_DIR: cwd })
|
|
17
|
+
};
|
|
18
|
+
var FOREIGN_SOURCES = [CLAUDE_CODE_SOURCE];
|
|
19
|
+
var BY_DIR_NAME = new Map(
|
|
20
|
+
[NATIVE_SOURCE, ...FOREIGN_SOURCES].map((a) => [a.dirName, a])
|
|
21
|
+
);
|
|
22
|
+
function adaptersFor(kinds) {
|
|
23
|
+
const byKind = new Map(FOREIGN_SOURCES.map((a) => [a.kind, a]));
|
|
24
|
+
const out = [];
|
|
25
|
+
for (const kind of kinds) {
|
|
26
|
+
const adapter = byKind.get(kind);
|
|
27
|
+
if (adapter !== void 0 && !out.includes(adapter)) out.push(adapter);
|
|
28
|
+
}
|
|
29
|
+
return out;
|
|
30
|
+
}
|
|
31
|
+
var COMPAT_SURFACES = ["hooks", "plugins", "skills", "subagents"];
|
|
32
|
+
function adaptersForSurface(sources, surface) {
|
|
33
|
+
const admitted = [];
|
|
34
|
+
for (const source of sources) {
|
|
35
|
+
if (typeof source === "string") {
|
|
36
|
+
admitted.push(source);
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
const wanted = source.import ?? [];
|
|
40
|
+
if (wanted.some((s) => s === surface && COMPAT_SURFACES.includes(s))) {
|
|
41
|
+
admitted.push(source.kind);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return adaptersFor(admitted);
|
|
45
|
+
}
|
|
46
|
+
function adapterForConfigPath(path) {
|
|
47
|
+
for (const segment of path.split(/[\\/]/)) {
|
|
48
|
+
const adapter = BY_DIR_NAME.get(segment);
|
|
49
|
+
if (adapter !== void 0) return adapter;
|
|
50
|
+
}
|
|
51
|
+
return void 0;
|
|
52
|
+
}
|
|
53
|
+
function undefinedVariablesIn(command, supplied, env = process.env) {
|
|
54
|
+
const unquoted = command.replace(/'[^']*'/g, " ");
|
|
55
|
+
const names = /* @__PURE__ */ new Set();
|
|
56
|
+
for (const match of unquoted.matchAll(
|
|
57
|
+
/\$\{([A-Za-z_][A-Za-z0-9_]*)\}|\$([A-Za-z_][A-Za-z0-9_]*)/g
|
|
58
|
+
)) {
|
|
59
|
+
const name = match[1] ?? match[2];
|
|
60
|
+
if (name === void 0) continue;
|
|
61
|
+
if (name in supplied) continue;
|
|
62
|
+
if (env[name] !== void 0) continue;
|
|
63
|
+
names.add(name);
|
|
64
|
+
}
|
|
65
|
+
return [...names];
|
|
66
|
+
}
|
|
67
|
+
var reported = /* @__PURE__ */ new Set();
|
|
68
|
+
function reportUndeclaredSources(cwd, declared) {
|
|
69
|
+
const declaredKinds = new Set(
|
|
70
|
+
adaptersFor(declared.map((d) => typeof d === "string" ? d : d.kind)).map((a) => a.kind)
|
|
71
|
+
);
|
|
72
|
+
for (const adapter of FOREIGN_SOURCES) {
|
|
73
|
+
if (declaredKinds.has(adapter.kind)) continue;
|
|
74
|
+
const dir = join(cwd, adapter.dirName);
|
|
75
|
+
if (!existsSync(dir)) continue;
|
|
76
|
+
if (reported.has(dir)) continue;
|
|
77
|
+
reported.add(dir);
|
|
78
|
+
diag(
|
|
79
|
+
`[theokit] ${adapter.dirName}/ is present but not declared, so its hooks, skills, subagents and plugins are ignored. To read it, pass local: { compatSources: ["${adapter.kind}"] } (usetheokit/theokit-sdk#524).
|
|
80
|
+
`
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// src/internal/persistence/paths.ts
|
|
86
|
+
function getTheokitHome(cwd) {
|
|
87
|
+
const override = process.env.THEOKIT_HOME?.trim();
|
|
88
|
+
if (override !== void 0 && override.length > 0) {
|
|
89
|
+
return override;
|
|
90
|
+
}
|
|
91
|
+
return join(cwd, THEOKIT_DIR_LITERAL);
|
|
92
|
+
}
|
|
93
|
+
function theokitConfigRoot(cwd) {
|
|
94
|
+
return join(cwd, THEOKIT_DIR_LITERAL);
|
|
95
|
+
}
|
|
96
|
+
function projectConfigRoots(cwd, sources, surface) {
|
|
97
|
+
return [
|
|
98
|
+
theokitConfigRoot(cwd),
|
|
99
|
+
...adaptersForSurface(sources, surface).map((adapter) => join(cwd, adapter.dirName))
|
|
100
|
+
];
|
|
101
|
+
}
|
|
102
|
+
function pluginBundleRoots(cwd, sources) {
|
|
103
|
+
return projectConfigRoots(cwd, sources, "plugins").map((root) => join(root, "plugins"));
|
|
104
|
+
}
|
|
105
|
+
function getProfilesRoot() {
|
|
106
|
+
return join(homedir(), THEOKIT_DIR_LITERAL, "profiles");
|
|
107
|
+
}
|
|
108
|
+
function displayTheokitHome(cwd) {
|
|
109
|
+
const resolved = getTheokitHome(cwd);
|
|
110
|
+
const home = homedir();
|
|
111
|
+
if (resolved === home) return "~";
|
|
112
|
+
if (resolved.startsWith(`${home}/`)) {
|
|
113
|
+
return `~${resolved.slice(home.length)}`;
|
|
114
|
+
}
|
|
115
|
+
return resolved;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export { adapterForConfigPath, displayTheokitHome, getProfilesRoot, getTheokitHome, pluginBundleRoots, projectConfigRoots, reportUndeclaredSources, theokitConfigRoot, undefinedVariablesIn };
|
|
119
|
+
//# sourceMappingURL=chunk-67ADYSTW.js.map
|
|
120
|
+
//# sourceMappingURL=chunk-67ADYSTW.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/internal/runtime/compat/foreign-config-sources.ts","../src/internal/persistence/paths.ts"],"names":["join"],"mappings":";;;;;AAmDO,IAAM,mBAAA,GAAsB,UAAA;AAG5B,IAAM,eAAA,GAAkB,SAAA;AAkBxB,IAAM,aAAA,GAAqC;AAAA,EAChD,IAAA,EAAM,SAAA;AAAA,EACN,OAAA,EAAS,mBAAA;AAAA,EACT,UAAA,EAAY,OAAO,EAAC;AACtB,CAAA;AAWO,IAAM,kBAAA,GAA0C;AAAA,EACrD,IAAA,EAAM,aAAA;AAAA,EACN,OAAA,EAAS,eAAA;AAAA,EACT,UAAA,EAAY,CAAC,GAAA,MAAS,EAAE,oBAAoB,GAAA,EAAI;AAClD,CAAA;AAEA,IAAM,eAAA,GAAkD,CAAC,kBAAkB,CAAA;AAE3E,IAAM,cAAwD,IAAI,GAAA;AAAA,EAChE,CAAC,aAAA,EAAe,GAAG,eAAe,CAAA,CAAE,GAAA,CAAI,CAAC,CAAA,KAAM,CAAC,CAAA,CAAE,OAAA,EAAS,CAAC,CAAC;AAC/D,CAAA;AASO,SAAS,YAAY,KAAA,EAAiD;AAC3E,EAAA,MAAM,MAAA,GAAS,IAAI,GAAA,CAAI,eAAA,CAAgB,GAAA,CAAI,CAAC,CAAA,KAAM,CAAC,CAAA,CAAE,IAAA,EAAM,CAAC,CAAC,CAAC,CAAA;AAC9D,EAAA,MAAM,MAA6B,E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CAAA,EAAG,IAAI,GAAG,CAAA,EAAG;AACnC,IAAA,OAAO,CAAA,CAAA,EAAI,QAAA,CAAS,KAAA,CAAM,IAAA,CAAK,MAAM,CAAC,CAAA,CAAA;AAAA,EACxC;AACA,EAAA,OAAO,QAAA;AACT","file":"chunk-67ADYSTW.js","sourcesContent":["import { existsSync } from \"node:fs\";\nimport { join } from \"node:path\";\n\nimport { diag } from \"../../diagnostics.js\";\n\n/*\n * The foreign configuration dialects this SDK can read, and what each one PRESUMES.\n *\n * ## Why a registry and not a list of directory names\n *\n * `projectConfigRoots` returned `[\".theokit\", \".claude\"]` — two paths — and that shape is what\n * usetheokit/theokit-sdk#522 fell through. A path says WHERE a file lives. It does not say how the\n * file is parsed, and it does not say what runtime the commands inside it were written against.\n *\n * Claude Code defines `$CLAUDE_PROJECT_DIR` for the hook commands in its `settings.json`, and its\n * documentation tells authors to reach project files through it — an absolute path would break for\n * every other person on the team, so the shape that failed here is the shape upstream recommends.\n * This SDK read the file and ran the command without the variable. `sh` expands an unset variable to\n * the empty string, so\n *\n * bash \"$CLAUDE_PROJECT_DIR/.claude/hooks/guard.sh\" became bash \"/.claude/hooks/guard.sh\"\n *\n * which does not exist, which a hook runner correctly reads as a refusal. Every turn denied, in any\n * repository that also had Claude Code set up, with a message naming a file that was present and\n * executable all along.\n *\n * Importing a format means accepting the contract that format presumes. An adapter is where that\n * contract is written down, so the next dialect (`.codex/` is the obvious one) declares its own\n * instead of inheriting a hole.\n *\n * ## What an adapter deliberately does NOT do\n *\n * It does not make the foreign source trusted, and it does not make its hooks permissive: a script\n * that exits non-zero is still a refusal. It supplies the variables the format's authors were\n * entitled to assume, and nothing else — `env` here is merged over the scrubbed inherit policy by\n * `spawnAndCollect`, so it adds names rather than widening what a child can see.\n *\n * @internal\n */\n\n/**\n * The project config directory literal.\n *\n * Renamed from `THEOKIT_DIR_NAME` in #410. Sharing a name with the (now removed) sovereign env var\n * was the MECHANISM of that defect, not scenery: every grep for the variable landed on that const\n * and looked answered, so \"is it read?\" returned five hits and nobody checked what they were.\n *\n * Lives here rather than in `persistence/paths.ts` because a directory name is one third of what a\n * dialect is — the other two being how it parses and what it presumes — and splitting the three\n * across two modules is what let the third go unwritten.\n */\nexport const THEOKIT_DIR_LITERAL = \".theokit\";\n\n/** The Claude Code CLI's project configuration directory. */\nexport const CLAUDE_DIR_NAME = \".claude\";\n\n/** A configuration dialect this SDK understands. `theokit` is native; the rest are foreign. */\nexport interface ConfigSourceAdapter {\n /** Stable identifier, and what a consumer names to opt in. */\n readonly kind: string;\n /** The project-relative directory the dialect keeps its configuration in. */\n readonly dirName: string;\n /**\n * Variables the dialect's own runtime defines for commands it executes.\n *\n * Empty for the native source: a `.theokit/` hook is written against THIS runtime and inherits it\n * already. Non-empty is what makes a foreign command runnable rather than silently broken.\n */\n runtimeEnv(cwd: string): Record<string, string>;\n}\n\n/** The native source. Always read, never opted into, always first for precedence. */\nexport const NATIVE_SOURCE: ConfigSourceAdapter = {\n kind: \"theokit\",\n dirName: THEOKIT_DIR_LITERAL,\n runtimeEnv: () => ({}),\n};\n\n/**\n * Claude Code.\n *\n * `CLAUDE_PROJECT_DIR` is the documented way for a hook command in `settings.json` to reach a file\n * in the project. Only that one variable is supplied: `$CLAUDE_PLUGIN_ROOT` and the rest of that\n * runtime's surface are NOT defined here, because supplying a name whose value this SDK would have\n * to invent is worse than leaving it unset — an invented root sends a script somewhere real and\n * wrong, where an unset one fails loudly.\n */\nexport const CLAUDE_CODE_SOURCE: ConfigSourceAdapter = {\n kind: \"claude-code\",\n dirName: CLAUDE_DIR_NAME,\n runtimeEnv: (cwd) => ({ CLAUDE_PROJECT_DIR: cwd }),\n};\n\nconst FOREIGN_SOURCES: readonly ConfigSourceAdapter[] = [CLAUDE_CODE_SOURCE];\n\nconst BY_DIR_NAME: ReadonlyMap<string, ConfigSourceAdapter> = new Map(\n [NATIVE_SOURCE, ...FOREIGN_SOURCES].map((a) => [a.dirName, a]),\n);\n\n/**\n * The adapters a caller declared, in declaration order, skipping any name that names no adapter.\n *\n * An unknown name is DROPPED rather than turned into `<cwd>/<name>`: a typo must fail closed. Making\n * a directory out of an unrecognised string would import a dialect nothing knows how to parse — and\n * the whole reason this exists is that a directory name was never enough to describe a dialect.\n */\nexport function adaptersFor(kinds: readonly string[]): ConfigSourceAdapter[] {\n const byKind = new Map(FOREIGN_SOURCES.map((a) => [a.kind, a]));\n const out: ConfigSourceAdapter[] = [];\n for (const kind of kinds) {\n const adapter = byKind.get(kind);\n if (adapter !== undefined && !out.includes(adapter)) out.push(adapter);\n }\n return out;\n}\n\n/**\n * A surface a foreign source may be admitted to. The four the SDK reads a project directory for.\n *\n * They are listed separately because they carry very different risk, which is the whole reason\n * #524 asks for per-surface control: a skill is text that enters the system prompt, a hook is\n * command execution, a plugin is code loading. A consumer who wants their skills back has no\n * reason to be handed the other two along with them.\n */\nexport type CompatSurface = \"hooks\" | \"plugins\" | \"skills\" | \"subagents\";\n\nconst COMPAT_SURFACES: readonly CompatSurface[] = [\"hooks\", \"plugins\", \"skills\", \"subagents\"];\n\n/**\n * A declared foreign source: a bare kind, or a kind with the surfaces it may be read for.\n */\nexport type CompatSourceDeclaration =\n | string\n | { readonly kind: string; readonly import?: readonly string[] };\n\n/**\n * The adapters admitted to ONE surface.\n *\n * Three rules, and each one fails closed:\n *\n * - A bare string admits every surface. It is what `5.0.0-next.1` published, so narrowing it\n * silently would turn a working opt-in into a no-op — the exact defect #524 is about, one level\n * up.\n * - An object with no `import` admits nothing. The issue's own rule, and safe to apply strictly\n * because the object form is new and nobody can be depending on it.\n * - An unrecognised surface name is dropped rather than matched loosely, for the same reason an\n * unrecognised KIND is dropped in {@link adaptersFor}: a typo must not silently widen access.\n */\nexport function adaptersForSurface(\n sources: readonly CompatSourceDeclaration[],\n surface: CompatSurface,\n): ConfigSourceAdapter[] {\n const admitted: string[] = [];\n for (const source of sources) {\n if (typeof source === \"string\") {\n admitted.push(source);\n continue;\n }\n const wanted = source.import ?? [];\n if (wanted.some((s) => s === surface && COMPAT_SURFACES.includes(s as CompatSurface))) {\n admitted.push(source.kind);\n }\n }\n return adaptersFor(admitted);\n}\n\n/**\n * The adapter whose directory an absolute config path sits under, or `undefined` for a path that\n * belongs to no registered dialect.\n *\n * Matched on the path SEGMENT rather than with `includes`, so a workspace that happens to live under\n * `/home/me/.claude-backups/repo` does not read as a Claude Code source.\n */\nexport function adapterForConfigPath(path: string): ConfigSourceAdapter | undefined {\n for (const segment of path.split(/[\\\\/]/)) {\n const adapter = BY_DIR_NAME.get(segment);\n if (adapter !== undefined) return adapter;\n }\n return undefined;\n}\n\n/**\n * Variable references in a shell command that nothing will define.\n *\n * The second half of #522, and the half that cost the debugging session. `sh` expands an unset\n * variable to the empty string and says nothing, so the failure surfaces ten characters later as a\n * path: `bash: /.claude/hooks/guard.sh: No such file or directory` — which reads as \"your script is\n * missing\" while the script is present and executable. Nothing in that message contains the name of\n * the variable that was actually missing, so the reader looks in the wrong place.\n *\n * Checked against BOTH the process environment and the variables the dialect supplies, because\n * either is a legitimate source: a hook may reasonably use `$HOME`.\n *\n * ## What it deliberately does not try to be\n *\n * This is not a shell parser. It finds `$NAME` and `${NAME}` outside single quotes, which is the\n * shape a config file's hook commands take. It does NOT understand `${NAME:-default}` (a default\n * makes the variable optional, so it is not reported), assignments earlier in the same command, or\n * variables a sourced script exports. A false NEGATIVE there costs the old behaviour — the confusing\n * path error — and a false positive would deny a hook that would have worked, so the parse errs\n * toward silence and the check only ever ADDS a name to a failure that already happened.\n */\nexport function undefinedVariablesIn(\n command: string,\n supplied: Readonly<Record<string, string>>,\n env: Readonly<Record<string, string | undefined>> = process.env,\n): string[] {\n // Single-quoted spans are literal in `sh`: `echo '$FOO'` prints the dollar sign.\n const unquoted = command.replace(/'[^']*'/g, \" \");\n const names = new Set<string>();\n for (const match of unquoted.matchAll(\n /\\$\\{([A-Za-z_][A-Za-z0-9_]*)\\}|\\$([A-Za-z_][A-Za-z0-9_]*)/g,\n )) {\n const name = match[1] ?? match[2];\n if (name === undefined) continue;\n if (name in supplied) continue;\n if (env[name] !== undefined) continue;\n names.add(name);\n }\n return [...names];\n}\n\n/**\n * Workspaces already reported, so repeated agent construction in one process says it once.\n *\n * Keyed by the resolved directory rather than by dialect kind, so a long-lived host that drives\n * several workspaces still reports each of them.\n */\nconst reported = new Set<string>();\n\n/**\n * Reports a foreign configuration directory that exists in the workspace and was not declared.\n *\n * ## Why the flip needs a voice\n *\n * Before #524 a `.claude/` was read with no opt-in; after it, the same directory is ignored. From\n * inside the repository the two states are indistinguishable — the hook file is there, it is\n * executable, and it does not run. The only remaining way to learn why is a CHANGELOG entry for a\n * version the reader may not know they crossed.\n *\n * ## Why `diag` rather than `diagFailure`\n *\n * `diagFailure` falls back to stderr, and this is not a failure: ignoring an undeclared foreign\n * directory is precisely what #524 asked for. Every repository that has Claude Code set up and does\n * NOT want it imported would pay a stderr line at every agent start — on a TUI host's render\n * surface — for behaving as instructed. That is the corruption `diagnostics.ts` exists to prevent.\n *\n * So it goes on the interceptable channel, for the reader holding the question it answers.\n */\nexport function reportUndeclaredSources(\n cwd: string,\n declared: readonly CompatSourceDeclaration[],\n): void {\n // A kind named with a NARROW import list has still been declared: the consumer knows the\n // directory is there and chose which surfaces to admit. Warning them anyway would be the noise\n // that gets a warning ignored, and this one has exactly one job — telling somebody who does NOT\n // know the directory is being skipped.\n const declaredKinds = new Set(\n adaptersFor(declared.map((d) => (typeof d === \"string\" ? d : d.kind))).map((a) => a.kind),\n );\n for (const adapter of FOREIGN_SOURCES) {\n if (declaredKinds.has(adapter.kind)) continue;\n const dir = join(cwd, adapter.dirName);\n if (!existsSync(dir)) continue;\n if (reported.has(dir)) continue;\n reported.add(dir);\n diag(\n `[theokit] ${adapter.dirName}/ is present but not declared, so its hooks, skills, subagents ` +\n `and plugins are ignored. To read it, pass ` +\n `local: { compatSources: [\"${adapter.kind}\"] } (usetheokit/theokit-sdk#524).\\n`,\n );\n }\n}\n","/**\n * Path resolution for SDK state files (ADR D60).\n *\n * Theokit anchors state at `<cwd>/.theokit/` by default (per-cwd). An\n * optional `THEOKIT_HOME` environment variable overrides this, enabling\n * test isolation, profile switching, and multi-tenant deployments.\n *\n * Rules:\n * - `getTheokitHome(cwd)` is the canonical resolver **for cwd-anchored state**. Never hardcode\n * `path.join(cwd, \".theokit\")` in callers — use this function so tests\n * and overrides stay consistent.\n *\n * M94 — this comment said \"the ONLY canonical resolver\", and stopped being true: the\n * transcript gained `transcriptRoot()`, which is **home-anchored** (`~/.theokit`) with the same\n * `THEOKIT_HOME` override. The two defaults differ on purpose — unifying would move the\n * transcript of everyone who does NOT set the variable, which is a data migration and not a\n * re-export.\n *\n * A consequence worth writing down: **without `THEOKIT_HOME` the state stays split in two**\n * — registry in `<cwd>/.theokit`, transcript in `~/.theokit`. M94 unifies only for those who set\n * the variable. Unifying both defaults is another milestone's work.\n * - `getProfilesRoot()` is intentionally home-anchored (not affected by\n * `THEOKIT_HOME`) so `theokit profile list` discovers all profiles\n * regardless of which is active.\n * - `displayTheokitHome(cwd)` returns a human-readable path for logs.\n *\n * @internal\n */\n\nimport { homedir } from \"node:os\";\nimport { join } from \"node:path\";\n\nimport {\n adaptersForSurface,\n type CompatSourceDeclaration,\n type CompatSurface,\n THEOKIT_DIR_LITERAL,\n} from \"../runtime/compat/foreign-config-sources.js\";\n\n// The directory names live with the dialect registry that owns them — a name is one third of what a\n// configuration dialect is, and keeping the three together is what stops the next one shipping\n// without its runtime contract (#522).\n\n/**\n * Resolve the directory cwd-anchored SDK state lives in.\n *\n * `THEOKIT_HOME` wins when it is set and not blank after trimming; the trimmed value is used, and\n * it is used VERBATIM — it is not resolved against `cwd`, so a relative value stays relative and\n * `.theokit` is not appended to it. Otherwise the answer is `<cwd>/.theokit`.\n *\n * The environment is read on every call, so a change to the variable takes effect immediately\n * rather than being frozen at import.\n *\n * This creates nothing and checks nothing: the returned path may not exist, and the caller owns\n * the `mkdir`. Call it instead of writing `join(cwd, \".theokit\")` by hand, or the override stops\n * working for that one call site and tests silently touch the real home.\n *\n * Not the whole story about where state lives — the transcript is home-anchored via\n * `transcriptRoot()`, honoring the same variable but defaulting to `~/.theokit`. With\n * `THEOKIT_HOME` unset, state is genuinely split between two roots.\n *\n * Semver-exempt: reachable via the `@theokit/sdk/internal/persistence` sub-path, which the package\n * declares in `exports` but does NOT cover with its semver contract.\n */\nexport function getTheokitHome(cwd: string): string {\n const override = process.env.THEOKIT_HOME?.trim();\n if (override !== undefined && override.length > 0) {\n return override;\n }\n return join(cwd, THEOKIT_DIR_LITERAL);\n}\n\n/**\n * The project's own configuration root: `<cwd>/.theokit`, always — never `THEOKIT_HOME`.\n *\n * `THEOKIT_HOME` relocates cwd-anchored SDK STATE (sessions, credentials). A project's\n * CONFIGURATION belongs to the repository: hooks, MCP servers, context sources, subagents, the\n * personality a project declares, all committed to git and shared by a team. Following the\n * override for any of them would move where a project's declared capabilities come from — a\n * behaviour change wearing the costume of a refactor, which is exactly what this function exists\n * to make impossible to do by accident: every config-class reader calls this instead of writing\n * `join(cwd, \".theokit\")` by hand.\n *\n * NOT for the `.claude/`-style foreign roots {@link adaptersForSurface} adds — those are additive,\n * opt-in, and each has its own directory name.\n *\n * Semver-exempt: reachable via the `@theokit/sdk/internal/persistence` sub-path, which the package\n * declares in `exports` but does NOT cover with its semver contract.\n */\nexport function theokitConfigRoot(cwd: string): string {\n return join(cwd, THEOKIT_DIR_LITERAL);\n}\n\n/**\n * Every directory a project's configuration may be read from, in precedence order.\n *\n * `.theokit` first — via {@link theokitConfigRoot}, so it is NEVER affected by `THEOKIT_HOME` for\n * the reason documented there — then `.claude`. The order is the whole contract: a project that\n * declares a skill, agent or rule in both means the explicit namespace to win, and a caller merging\n * these roots must therefore keep the FIRST occurrence of a name rather than the last.\n *\n * `.claude` is read because the formats already agree and only the location did not. Measured\n * 2026-08-26: the SKILL.md frontmatter this SDK requires (`name` + `description`) is exactly what\n * the CLI writes, its hook config is the same JSON shape, and 59 of the CLI's agent declarations\n * parse here unchanged. A repository set up for the CLI was failing on the directory name alone.\n *\n * NOT a rename of `.theokit`, and not a migration. Both are read, so nothing that works today stops\n * working — which is why this returns a LIST and not a single resolved answer.\n *\n * Creates nothing and checks nothing; either path may not exist, and the caller owns that.\n *\n * Semver-exempt: reachable via the `@theokit/sdk/internal/persistence` sub-path, which the package\n * declares in `exports` but does NOT cover with its semver contract.\n */\nexport function projectConfigRoots(\n cwd: string,\n sources: readonly CompatSourceDeclaration[],\n surface: CompatSurface,\n): string[] {\n return [\n theokitConfigRoot(cwd),\n ...adaptersForSurface(sources, surface).map((adapter) => join(cwd, adapter.dirName)),\n ];\n}\n\n/**\n * Every directory that may hold a plugin BUNDLE contributed by the Claude Code CLI.\n *\n * A CLI plugin is not a JS entry point — it is a folder whose `skills/` and `agents/` are what it\n * exists to provide. Measured 2026-08-26 on an installed one: seven agents and three skills beside\n * a manifest in `.claude-plugin/plugin.json`. Parsing that manifest and stopping there produced a\n * plugin that loaded and did nothing.\n *\n * Project-scoped deliberately. The CLI also keeps plugins under `~/.claude/plugins/cache`, behind\n * its own installer and enable/disable state — reproducing that is an installation system, not\n * reading a project's configuration, and guessing at someone's enablement would run code they\n * turned off.\n */\nexport function pluginBundleRoots(\n cwd: string,\n sources: readonly CompatSourceDeclaration[],\n): string[] {\n // Always the `plugins` surface, including when the caller wants the SKILLS a bundle carries.\n // A bundle is code, and its skills arrive attached to it: admitting `skills` alone must not\n // reach inside a foreign plugin directory, or the narrower permission would silently grant the\n // wider one. `skills-manager` and `subagents-loader` both read bundle contents and both go\n // through here, so the rule holds in one place rather than three.\n return projectConfigRoots(cwd, sources, \"plugins\").map((root) => join(root, \"plugins\"));\n}\n\n/**\n * The directory holding every profile: always `~/.theokit/profiles`, from `os.homedir()`.\n *\n * Deliberately NOT affected by `THEOKIT_HOME`, which is the one thing to remember about it. If it\n * followed the override, a session pointed at one profile would only be able to see that profile,\n * and `theokit profile list` could never enumerate the rest. Profiles are the thing the override\n * switches between, so their index cannot live behind it.\n *\n * Takes no `cwd` for the same reason. Creates nothing; the path may not exist.\n *\n * Semver-exempt: reachable via the `@theokit/sdk/internal/persistence` sub-path, which the package\n * declares in `exports` but does NOT cover with its semver contract.\n */\nexport function getProfilesRoot(): string {\n return join(homedir(), THEOKIT_DIR_LITERAL, \"profiles\");\n}\n\n/**\n * The same path `getTheokitHome(cwd)` returns, shortened for display: the home directory prefix\n * collapses to `~`, so `/home/ada/.theokit` prints as `~/.theokit`.\n *\n * For humans only — log lines, CLI output, error messages. The result is NOT a usable path: `~`\n * is a shell convention that `fs` does not expand, so passing this to a filesystem call resolves\n * a literal directory named `~` relative to the process cwd. Use `getTheokitHome` for anything\n * that touches disk.\n *\n * Collapsing is a prefix match on the home directory followed by a literal `/`, so a sibling like\n * `/home/adalovelace` is left alone even though `/home/ada` is a string prefix of it. A path\n * outside the home directory comes back unchanged — and so does a Windows path, where the\n * separator is a backslash and the prefix test therefore never matches.\n *\n * Semver-exempt: reachable via the `@theokit/sdk/internal/persistence` sub-path, which the package\n * declares in `exports` but does NOT cover with its semver contract.\n */\nexport function displayTheokitHome(cwd: string): string {\n const resolved = getTheokitHome(cwd);\n const home = homedir();\n if (resolved === home) return \"~\";\n if (resolved.startsWith(`${home}/`)) {\n return `~${resolved.slice(home.length)}`;\n }\n return resolved;\n}\n"]}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var chunkEG4QM7ZJ_cjs = require('./chunk-EG4QM7ZJ.cjs');
|
|
4
|
-
|
|
5
3
|
// src/internal/env.ts
|
|
6
4
|
var API_KEY_ENV_VAR = "THEOKIT_API_KEY";
|
|
7
5
|
function readEnv(name) {
|
|
@@ -18,6 +16,38 @@ function resolveApiKey(explicit) {
|
|
|
18
16
|
return void 0;
|
|
19
17
|
}
|
|
20
18
|
|
|
19
|
+
// src/internal/diagnostics.ts
|
|
20
|
+
var SINK_SLOT = /* @__PURE__ */ Symbol.for("theokit.sdk.diagnostics.sink.v1");
|
|
21
|
+
function currentSink() {
|
|
22
|
+
return globalThis[SINK_SLOT];
|
|
23
|
+
}
|
|
24
|
+
function setDiagnosticsSink(next) {
|
|
25
|
+
globalThis[SINK_SLOT] = next;
|
|
26
|
+
}
|
|
27
|
+
function diag(message) {
|
|
28
|
+
const sink = currentSink();
|
|
29
|
+
if (sink === void 0) return;
|
|
30
|
+
try {
|
|
31
|
+
sink(message);
|
|
32
|
+
} catch {
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function diagFailure(message) {
|
|
36
|
+
const sink = currentSink();
|
|
37
|
+
if (sink !== void 0) {
|
|
38
|
+
try {
|
|
39
|
+
sink(message);
|
|
40
|
+
return;
|
|
41
|
+
} catch {
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
try {
|
|
45
|
+
globalThis.process?.stderr?.write(`${message}
|
|
46
|
+
`);
|
|
47
|
+
} catch {
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
21
51
|
// src/internal/security/redact.ts
|
|
22
52
|
var REDACT_ENABLED = readEnvOnce();
|
|
23
53
|
function readEnvOnce() {
|
|
@@ -27,7 +57,7 @@ function readEnvOnce() {
|
|
|
27
57
|
}
|
|
28
58
|
var warnedOptOut = false;
|
|
29
59
|
if (!REDACT_ENABLED && !warnedOptOut) {
|
|
30
|
-
|
|
60
|
+
diag(
|
|
31
61
|
"[theokit-sdk] Secret redaction is DISABLED via THEOKIT_REDACT_SECRETS. Credentials may leak into errors, telemetry, logs, transcripts.\n"
|
|
32
62
|
);
|
|
33
63
|
warnedOptOut = true;
|
|
@@ -107,7 +137,7 @@ var PARAM_PATTERN = /(\b(?:access_token|api_key|api-key|client_secret|credential
|
|
|
107
137
|
var _extraPatterns = [];
|
|
108
138
|
function addPattern(re) {
|
|
109
139
|
if (!re.global) {
|
|
110
|
-
throw new Error("
|
|
140
|
+
throw new Error("addPattern: regex must have /g flag for replace-all semantics");
|
|
111
141
|
}
|
|
112
142
|
_extraPatterns.push(re);
|
|
113
143
|
}
|
|
@@ -152,9 +182,12 @@ function redactSecrets(text, opts) {
|
|
|
152
182
|
|
|
153
183
|
exports.API_KEY_ENV_VAR = API_KEY_ENV_VAR;
|
|
154
184
|
exports.addPattern = addPattern;
|
|
185
|
+
exports.diag = diag;
|
|
186
|
+
exports.diagFailure = diagFailure;
|
|
155
187
|
exports.maskToken = maskToken;
|
|
156
188
|
exports.readEnv = readEnv;
|
|
157
189
|
exports.redactSecrets = redactSecrets;
|
|
158
190
|
exports.resolveApiKey = resolveApiKey;
|
|
159
|
-
|
|
160
|
-
//# sourceMappingURL=chunk-
|
|
191
|
+
exports.setDiagnosticsSink = setDiagnosticsSink;
|
|
192
|
+
//# sourceMappingURL=chunk-6LHQPOMI.cjs.map
|
|
193
|
+
//# sourceMappingURL=chunk-6LHQPOMI.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/internal/env.ts","../src/internal/diagnostics.ts","../src/internal/security/redact.ts"],"names":[],"mappings":";;;AAKO,IAAM,eAAA,GAAkB;AAoBxB,SAAS,QAAQ,IAAA,EAAkC;AACxD,EAAA,OAAO,UAAA,CAAW,OAAA,EAAS,GAAA,GAAM,IAAI,CAAA;AACvC;AAYO,SAAS,cAAc,QAAA,EAAuC;AACnE,EAAA,IAAI,QAAA,KAAa,MAAA,IAAa,QAAA,CAAS,MAAA,GAAS,CAAA,EAAG;AACjD,IAAA,OAAO,QAAA;AAAA,EACT;AACA,EAAA,MAAM,OAAA,GAAU,QAAQ,eAAe,CAAA;AACvC,EAAA,IAAI,OAAA,KAAY,MAAA,IAAa,OAAA,CAAQ,MAAA,GAAS,CAAA,EAAG;AAC/C,IAAA,OAAO,OAAA;AAAA,EACT;AACA,EAAA,OAAO,MAAA;AACT;;;ACoBA,IAAM,SAAA,mBAAY,MAAA,CAAO,GAAA,CAAI,iCAAiC,CAAA;AAI9D,SAAS,WAAA,GAA2C;AAClD,EAAA,OAAQ,WAAqC,SAAS,CAAA;AACxD;A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,CAAQ,aAAA,EAAe,CAAC,KAAA,EAAO,QAAgB,KAAA,KAAkB;AAOrE,MAAA,IAAI,UAAA,CAAW,IAAA,CAAK,KAAK,CAAA,EAAG,OAAO,KAAA;AACnC,MAAA,OAAO,GAAG,MAAM,CAAA,GAAA,CAAA;AAAA,IAClB,CAAC,CAAA;AAAA,EACH;AACA,EAAA,OAAO,CAAA;AACT","file":"chunk-6LHQPOMI.cjs","sourcesContent":["/**\n * Environment variable used to provide the default API key.\n *\n * @internal\n */\nexport const API_KEY_ENV_VAR = \"THEOKIT_API_KEY\";\n\n/**\n * Read an environment variable without assuming `process` exists.\n *\n * Parts of this package legitimately reach a browser: `errors.ts` is imported by the client\n * bindings that framework consumers ship to the front end, and it in turn pulls in the redaction\n * and retry modules. `process` is a Node global — a bare `process.env` in any of them throws\n * `ReferenceError: process is not defined` while the module graph is still evaluating, before a\n * single component renders. The page goes blank with one console error that names no cause.\n *\n * `globalThis.process?.env?.[name]` degrades instead: on the server it reads the variable, and in\n * a browser it yields `undefined`, which every caller here already treats as \"not set\". Bundlers\n * that inline `process.env.X` at build time keep working, because they replace the expression\n * before it ever runs.\n *\n * This is the same pattern the sibling design system uses for `NODE_ENV`, for the same reason.\n *\n * @internal\n */\nexport function readEnv(name: string): string | undefined {\n return globalThis.process?.env?.[name];\n}\n\n/**\n * Resolve the API key with the documented precedence:\n *\n * 1. Explicit `apiKey` argument.\n * 2. The `THEOKIT_API_KEY` environment variable.\n *\n * Returns `undefined` when neither is set.\n *\n * @internal\n */\nexport function resolveApiKey(explicit?: string): string | undefined {\n if (explicit !== undefined && explicit.length > 0) {\n return explicit;\n }\n const fromEnv = readEnv(API_KEY_ENV_VAR);\n if (fromEnv !== undefined && fromEnv.length > 0) {\n return fromEnv;\n }\n return undefined;\n}\n","/**\n * The library's single diagnostics channel — silent by default (#147).\n *\n * ## The problem\n *\n * The SDK wrote diagnostics straight to `process.stderr` from hot paths — 92 sites across 51\n * files under `internal/`. In a TUI host (Ink, alternate screen), those writes interleave with the\n * render and **corrupt the frame**. And the host had no way to intercept them: there was no\n * injectable logger. One consumer went as far as installing `proper-lockfile` just to silence ONE\n * of them.\n *\n * A library cannot assume `stdout`/`stderr` are free sinks. The application owns the terminal, not\n * the dependency.\n *\n * ## The contract\n *\n * - **`setDiagnosticsSink(fn)`** hands the messages to the application, which decides where to put\n * them (a status line, a file, a panel). It is what was missing for a TUI to coexist with the SDK.\n * - **With no sink, nothing is emitted.** A library does not own the host's terminal.\n *\n * ## Silent by default, and how 36 suites survived the flip\n *\n * The default WAS `stderr`, and 36 test files spy on `process.stderr.write` to assert a given\n * warning is emitted. That contract is real and had to survive; migrating all 36 by hand, across\n * four different spy styles, is how you weaken 36 suites in one commit.\n *\n * So the flip happened at the default, and `vitest.setup.ts` installs a sink that FORWARDS to\n * `stderr` for the duration of every test. Those assertions still test what they always tested —\n * \"this condition emits a diagnostic\" — through the channel a host would use, while production\n * emits nothing unless asked.\n *\n * The cost is stated rather than hidden: no test observes the production default by accident, so\n * `tests/diagnostics-public-entry.test.ts` pins it explicitly by clearing the sink first.\n *\n * ## Coverage is the whole guarantee\n *\n * The first sweep migrated the 92 sites under `internal/` and left `src/`'s own modules —\n * `event-bus.ts`, `batch.ts`, `compaction.ts`, `internal/workflow/step-branch.ts`. A host could\n * therefore install a sink and still have its frame corrupted by a batch run, which is the reported\n * defect with a smaller blast radius. Those are routed here too, and\n * `tests/lint/no-direct-terminal-write.test.ts` is what keeps the next hot path from\n * reintroducing one. \"Mostly interceptable\" is not interceptable.\n *\n * The remaining direct writers are allowlisted there with a reason, and every one of them is a seam\n * whose destination the CALLER already chooses (`opts.warn`, `opts.logger`, the Workflow logger).\n *\n * ## What this is NOT\n *\n * It is not a logger with levels, formatting or multiple destinations. It is the minimum that\n * resolves the reported blocker; a full logger here would be inventing a requirement nobody asked\n * for.\n */\n\n/** Receives each diagnostic message already formatted, with the trailing `\\n`. */\nexport type DiagnosticsSink = (message: string) => void;\n\n/**\n * The registry lives on `globalThis`, not in a module-level `let` (theokit#173).\n *\n * A module-level binding is a per-INSTANCE singleton, and a package manager will install two\n * physical copies of the same version whenever two dependents resolve different peer sets. Measured:\n * `@theokit/sdk@4.39.1` existed under two pnpm store hashes in the theokit workspace, so a sink\n * installed through `@theokit/agents` landed in a different registry than the emitter writes to.\n *\n * The failure mode is the quiet one — the re-export resolves, the function is callable, nothing\n * throws, and no diagnostic ever arrives. `Symbol.for` gives every copy in the process the same\n * slot; the `v1` suffix leaves room to change the shape without colliding with an older copy.\n */\nconst SINK_SLOT = Symbol.for(\"theokit.sdk.diagnostics.sink.v1\");\n\ntype SinkHolder = Record<symbol, DiagnosticsSink | undefined>;\n\nfunction currentSink(): DiagnosticsSink | undefined {\n return (globalThis as unknown as SinkHolder)[SINK_SLOT];\n}\n\n/**\n * Installs (or removes, by passing `undefined`) the diagnostics destination.\n *\n * When a sink is present it is the ONLY destination — `stderr` gets no copy. Duplicating\n * destinations would hand the problem back to the TUI that installed the sink precisely to get the\n * messages out of the terminal.\n */\nexport function setDiagnosticsSink(next: DiagnosticsSink | undefined): void {\n (globalThis as unknown as SinkHolder)[SINK_SLOT] = next;\n}\n\n/**\n * Emits a library diagnostic message.\n *\n * Replaces `process.stderr.write` on internal paths. Never throws: a faulty sink must not\n * must not take down the run it merely observes.\n */\nexport function diag(message: string): void {\n // Silent by default (#147): with no sink installed the message is dropped. A library must not\n // assume the host's stdout/stderr are free-form log sinks — in a TUI they are the render surface.\n const sink = currentSink();\n if (sink === undefined) return;\n try {\n sink(message);\n } catch {\n // Observability never breaks the run — same principle as `emitRunEvent`.\n }\n}\n\n/**\n * Emits a diagnostic that reports a USER-VISIBLE FAILURE, and is never silently dropped.\n *\n * `diag` is silent with no sink installed, and that is right for chatter: a library must not assume\n * the host's stderr is a free-form log, because in a TUI it is the render surface. A failure is a\n * different message. `theokit-sdk#189` is the record of the difference — an MCP server failed to\n * start, the only report went to `diag()`, the embedding UI never read it, and the user saw an\n * agent with missing tools and no reason given.\n *\n * The two failure modes are not symmetric, which is the whole decision: a corrupted frame is\n * visible and recoverable, while a silently dropped failure is neither. So this falls back to\n * stderr rather than to silence.\n *\n * A sink still takes precedence — the host installed it precisely to keep these off the terminal —\n * EXCEPT when the sink throws. A broken sink swallowing the one report of a failure is the same\n * defect one layer further in.\n *\n * @internal\n */\nexport function diagFailure(message: string): void {\n const sink = currentSink();\n if (sink !== undefined) {\n try {\n sink(message);\n return;\n } catch {\n // Fall through: the sink is broken, and this message is too important to drop with it.\n }\n }\n try {\n // `globalThis.process?.stderr` rather than a bare `process`: in a browser the bare form is a\n // ReferenceError that the catch below would swallow — working by accident, on an exception used\n // as ordinary control flow. Optional chaining states the intent: write to stderr where one\n // exists, stay silent where none does.\n globalThis.process?.stderr?.write(`${message}\\n`);\n } catch {\n // Nothing left to try. Observability never breaks the run.\n }\n}\n","import { diag } from \"../diagnostics.js\";\nimport { readEnv } from \"../env.js\";\n\n/**\n * Canonical secret redaction module (ADRs D68-D73).\n *\n * Single source of truth for credential pattern masking across the SDK.\n * Wired at output boundaries: `ErrorMetadata.raw` (mappers/shared.ts),\n * telemetry span attributes (telemetry/tracer.ts), transcript JSONL\n * appends (agent-session-store.ts), migration logger output\n * (memory/migrate-sqlite-to-lance.ts).\n *\n * - D68: central module, single source of truth (replaces 2 duplicates)\n * - D69: env snapshot at module init (prompt-injection defense)\n * - D70: ON by default, warn on opt-out\n * - D71: two-bucket masking — short fully masked, long preserves prefix+suffix\n * - D72: `codeFile` opt-out for legitimate prefix-shaped content\n * - D73: redact at OUTPUT boundaries, not at storage\n *\n * @internal\n */\n\n// D69: env snapshot captured at module load. Subsequent mutations of\n// process.env.THEOKIT_REDACT_SECRETS are ignored — defends against\n// prompt injection that tries to disable redaction mid-run.\nlet REDACT_ENABLED: boolean = readEnvOnce();\n\nfunction readEnvOnce(): boolean {\n // `readEnv` rather than `process.env`: this module reaches the browser through `errors.ts`, and\n // a bare `process` there is a ReferenceError at module scope — a blank page, not a warning.\n const raw = readEnv(\"THEOKIT_REDACT_SECRETS\");\n if (raw === undefined) return true; // D70: default ON\n return [\"1\", \"true\", \"yes\", \"on\"].includes(raw.toLowerCase());\n}\n\n// D70: warn once on opt-out so the user knows they're vulnerable.\nlet warnedOptOut = false;\nif (!REDACT_ENABLED && !warnedOptOut) {\n diag(\n \"[theokit-sdk] Secret redaction is DISABLED via THEOKIT_REDACT_SECRETS. \" +\n \"Credentials may leak into errors, telemetry, logs, transcripts.\\n\",\n );\n warnedOptOut = true;\n}\n\n/**\n * Built-in credential patterns. Order matters — more specific prefixes\n * must come before generic ones (e.g., `sk-ant-` before `sk-`). Quantifiers\n * are all bounded `{n,m}` or applied to char classes — linear time, no ReDoS.\n *\n * @internal\n */\nconst BUILTIN_PATTERNS: readonly RegExp[] = [\n // T5.4: 30+ vendor prefixes (was 12 pre-T5.4). Order matters — more\n // specific prefixes precede generic ones (e.g., sk-ant-admin01 before\n // sk-ant-, sk-proj- before sk-). PEM block deliberately first so its\n // multi-line span runs before any per-line patterns can fire.\n /-----BEGIN[ ]+(?:RSA |EC |DSA |OPENSSH |ENCRYPTED |)PRIVATE KEY-----[\\s\\S]+?-----END[ ]+(?:RSA |EC |DSA |OPENSSH |ENCRYPTED |)PRIVATE KEY-----/g,\n // JWT — exact 3-segment base64url. Dotted; the body floor of 4 chars per\n // segment matches the minimum legal payload while skipping `a.b.c` noise.\n /eyJ[A-Za-z0-9_-]{4,}\\.eyJ[A-Za-z0-9_-]{4,}\\.[A-Za-z0-9_-]{4,}/g,\n // Azure Storage SAS — match the sig= component (URL-encoded base64).\n /(?<=[?&]sig=)[A-Za-z0-9%+/]{20,}/g,\n // Anthropic\n /sk-ant-admin01-[A-Za-z0-9_-]{10,}/g, // Anthropic admin keys (must precede sk-ant-)\n /sk-ant-[A-Za-z0-9_-]{10,}/g, // Anthropic regular\n // OpenAI family + clones (sk- generic must come AFTER all sk-foo- variants)\n /sk-proj-[A-Za-z0-9_-]{10,}/g, // OpenAI project key (must precede sk- generic)\n /sk-[A-Za-z0-9_-]{10,}/g, // OpenAI / OpenRouter / DeepInfra / Together / DeepSeek\n // Provider prefixes (alphabetized for maintainability)\n /AIza[A-Za-z0-9_-]{35}/g, // Google API key\n /AKIA[A-Z0-9]{16}/g, // AWS access key\n /fw_[A-Za-z0-9]{20,}/g, // Fireworks\n /glpat-[A-Za-z0-9_-]{20}/g, // GitLab PAT\n /ghp_[A-Za-z0-9]{36}/g, // GitHub PAT classic\n /github_pat_[A-Za-z0-9_]{82}/g, // GitHub PAT fine-grained\n /gsk_[A-Za-z0-9]{20,}/g, // Groq\n /hf_[A-Za-z0-9]{20,}/g, // HuggingFace\n /\\bpa-[A-Za-z0-9_-]{20,}/g, // Voyage AI (word-boundary to skip CSS / kebab IDs)\n /pcsk_[A-Za-z0-9_-]{20,}/g, // Pinecone\n /pplx-[A-Za-z0-9_-]{20,}/g, // Perplexity\n /r8_[A-Za-z0-9_-]{20,}/g, // Replicate\n /rk_live_[A-Za-z0-9]{20,}/g, // Stripe restricted\n /sk_live_[A-Za-z0-9]{20,}/g, // Stripe secret\n /sntrys_[A-Za-z0-9]{40,}/g, // Sentry user auth\n /xai-[A-Za-z0-9_-]{20,}/g, // xAI (Grok)\n /xox[bpasr]-[A-Za-z0-9-]{10,}/g, //Slack tokens\n // Additional unique-prefix tokens with low false-positive risk\n /npm_[A-Za-z0-9]{36}/g, // npm access token\n /SG\\.[A-Za-z0-9_-]{22}\\.[A-Za-z0-9_-]{43}/g, // SendGrid\n /\\bSK[A-Za-z0-9]{32}\\b/g, // Twilio API SID (word-boundary to skip CSS class noise)\n /\\bkey-[a-f0-9]{32}\\b/g, // Mailgun (hex-only narrows false positives)\n /MT[A-Za-z0-9_-]{23}\\.[A-Za-z0-9_-]{6}\\.[A-Za-z0-9_-]{27}/g, // Discord bot\n /\\b(?:sdk|mob)-[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}\\b/g, // LaunchDarkly\n];\n\n// `Bearer <token>` matched as its own first-class pattern so PARAM_PATTERN\n// doesn't have to handle the unusual `Authorization: Bearer xxx` shape\n// (no `:` or `=` between \"Bearer\" and the value — bare whitespace).\nconst BEARER_PATTERN = /\\b(Bearer\\s+)([A-Za-z0-9_\\-.+/=]{8,})/g;\n\n// Parametric: matches `key=value` and `key: value` (with optional quote\n// between the key and the separator, to handle JSON: `\"api_key\": \"...\"`)\n// in URLs, query strings, JSON-like bodies, HTTP headers. Captures the\n// prefix so we keep it visible while masking the value.\n//\n// `authorization` deliberately excluded — BEARER_PATTERN handles the\n// common `Authorization: Bearer xxx` shape. Including it here causes\n// double-masking (\"Authorization: *** ***\") after Bearer fires.\n// T5.4: keyword set expanded from 6 → 16 to cover the OAuth / JWT / generic\n// credential vocabulary surfaced by DR6 finding #4. `authorization`,\n// `auth`, `bearer` stay excluded — BEARER_PATTERN handles the\n// `Authorization: Bearer xxx` shape and including these here would\n// re-catch the post-BUILTIN-masked form (D71 prefix-preservation\n// contract) and double-mask to `***`.\n//\n// Value class includes `.` so JWT / `.env` / dotted base64url values\n// match; the callback skips already-masked values (containing the\n// `...` D71 separator) to preserve the BUILTIN prefix-mask result.\nconst PARAM_PATTERN =\n /(\\b(?:access_token|api_key|api-key|client_secret|credential|credentials|id_token|jwt|password|private_key|refresh_token|secret|service_account|session_token|token|x-api-key)\\b[\"']?\\s*[:=]\\s*[\"']?)([A-Za-z0-9_\\-.+/]+)/gi;\n\nconst _extraPatterns: RegExp[] = [];\n\n/**\n * Register an extra pattern for `redactSecrets` to mask, on top of the built-in vendor set.\n *\n * Additive and irreversible for the life of the process: patterns accumulate in module scope,\n * builtins are never replaced or reordered, and there is no way to remove one. Registering the\n * same regex twice registers it twice.\n *\n * Throws immediately when the regex has no `/g` flag. That is not pedantry — `String.replace`\n * with a non-global regex substitutes only the FIRST match, so a pattern registered without it\n * would mask the first credential in a payload and let every later one through, which reads as\n * working.\n *\n * Extras run after the builtins and before the parametric `key=value` sweep, and each whole match\n * is replaced by `maskToken` of that match. Anchor and bound the pattern with care: a regex that\n * matches more than the secret masks more than the secret, and one that backtracks badly runs on\n * every string crossing an output boundary.\n *\n * Registering a pattern does not enable redaction. When `THEOKIT_REDACT_SECRETS` was off at\n * module load, `redactSecrets` returns its input untouched and extras never run.\n *\n * Also exposed publicly, and under semver, as `Security.addPattern` in `src/security.ts`; the\n * direct export here additionally reaches the semver-exempt `@theokit/sdk/internal/security`\n * sub-path.\n */\nexport function addPattern(re: RegExp): void {\n if (!re.global) {\n // A BARE Error here, deliberately, and this is the one place in the package where that is the\n // right answer. `errors.ts` imports `redactSecrets` from this module for the anti-leak invariant\n // on `providerError`, so this module must stay below it — importing ConfigurationError closes a\n // cycle (measured: `madge --circular` reports `errors.ts > internal/security/redact.ts`).\n //\n // The typed error lives at the surface a consumer touches: `Security.addPattern` in\n // `src/security.ts` validates first and throws ConfigurationError with a code. This throw is the\n // backstop for the semver-exempt `@theokit/sdk/internal/security` sub-path.\n throw new Error(\"addPattern: regex must have /g flag for replace-all semantics\");\n }\n _extraPatterns.push(re);\n}\n\n/**\n * Mask one string, keeping enough of it to be recognizable in a log.\n *\n * Under 18 characters the whole string becomes the literal `***`; the length is not preserved and\n * nothing of the input survives. From 18 characters up, the result is the first 6 characters, the\n * literal `...`, and the last 4 — so exactly 10 characters of the input are RETAINED IN CLEAR and\n * the middle is dropped. That is the trade the threshold encodes: short strings could be brute\n * forced from a partial, long ones cannot, and the surviving prefix is usually the vendor tag\n * (`sk-ant`, `ghp_de`) that tells an operator which credential misbehaved.\n *\n * Be clear about what this is and is not. It is a readability aid for logs, not an anonymizer and\n * not a security boundary. The retained prefix and suffix identify the credential's issuer and\n * often the credential itself to anyone who has seen it before, so a masked value still belongs in\n * a trusted log and not in a bug report or a support ticket.\n *\n * It masks whatever it is handed. There is no check that the argument is a secret, so calling it\n * on ordinary text mangles the text, and calling it on something the caller merely hopes is a\n * secret proves nothing about what leaked.\n *\n * `redactSecrets` applies it to the ENTIRE match of a pattern, not to a captured group. For a\n * match like `Bearer sk-ant-...` the first 6 characters retained are `Bearer`, not the key's\n * prefix.\n *\n * Semver-exempt: reachable via the `@theokit/sdk/internal/security` sub-path, which the package\n * declares in `exports` but does NOT cover with its semver contract.\n */\nexport function maskToken(token: string): string {\n if (token.length < 18) return \"***\";\n return `${token.slice(0, 6)}...${token.slice(-4)}`;\n}\n\n// issue #117 — the EXACT shape of a `maskToken` output (`slice(0,6)+\"...\"+slice(-4)`\n// = 6 chars, literal `...`, 4 chars). Used to detect a value PARAM_PATTERN would\n// otherwise re-mask, WITHOUT skipping a raw secret that merely contains `...`.\nconst MASK_SHAPE = /^.{6}\\.\\.\\..{4}$/s;\n\n// Coerce arbitrary input to a string for redaction. Returns `null`\n// sentinel when the value is null/undefined/non-stringifiable, so the\n// caller can short-circuit with `\"\"`. EC-7 fix: circular refs go through\n// the try/catch and produce the sentinel marker, never throwing.\nfunction coerceToString(value: unknown): string | null {\n if (typeof value === \"string\") return value;\n if (value === null || value === undefined) return null;\n if (typeof value === \"object\") {\n try {\n const s = JSON.stringify(value);\n return s === undefined ? null : s;\n } catch {\n return \"[unredactable: circular]\";\n }\n }\n return String(value);\n}\n\n/**\n * Redact known credential patterns from `text`. Default behavior masks\n * builtins + extras + parametric `key=value` sinks.\n *\n * With `{ codeFile: true }` (D72), skips PARAM_PATTERN to avoid mangling\n * `.env.example`, schema JSON, or test fixtures that legitimately contain\n * prefix-like strings.\n *\n * Returns the redacted string. Coerces non-strings via JSON.stringify;\n * EC-7 fix (edge-case review): wraps in try/catch so circular references\n * never propagate — returns sentinel `\"[unredactable: circular]\"`.\n *\n * `null` and `undefined` return `\"\"`. When redaction was switched off at module load via\n * `THEOKIT_REDACT_SECRETS`, the coerced input is returned with no masking at all — the value is\n * still stringified, but nothing is removed from it.\n *\n * Masking is best-effort against a list of known shapes. A credential in a format no pattern\n * covers passes through unchanged, so a redacted string is not a string proven free of secrets.\n */\nexport function redactSecrets(text: unknown, opts?: { codeFile?: boolean }): string {\n const coerced = coerceToString(text);\n if (coerced === null) return \"\";\n if (!REDACT_ENABLED) return coerced;\n\n let s = coerced;\n for (const re of BUILTIN_PATTERNS) {\n s = s.replace(re, (m) => maskToken(m));\n }\n for (const re of _extraPatterns) {\n s = s.replace(re, (m) => maskToken(m));\n }\n if (!opts?.codeFile) {\n // Bearer first (preserves \"Bearer \" prefix, masks the token after).\n // Must run before PARAM_PATTERN so the bare-whitespace shape doesn't\n // get mis-handled as a value.\n s = s.replace(BEARER_PATTERN, (_, prefix: string) => `${prefix}***`);\n // T5.4: skip if value already contains the D71 bucket-mask separator\n // (`...`) — BUILTIN ran first and produced a prefix-preserved mask;\n // re-masking would lose the prefix and degrade debuggability.\n s = s.replace(PARAM_PATTERN, (whole, prefix: string, value: string) => {\n // issue #117 — skip ONLY when the value is already a mask that a BUILTIN\n // pattern produced (maskToken's exact `6chars...4chars` shape), so we don't\n // re-mask and lose the prefix. The old `value.includes(\"...\")` was too broad:\n // a REAL secret that happens to contain `...` (e.g. `L_-cxw-.2UI_..._`) was\n // skipped and LEAKED. The mask shape is exact (maskToken: slice(0,6)+\"...\"+\n // slice(-4)), so a raw secret with `...` elsewhere is now masked.\n if (MASK_SHAPE.test(value)) return whole;\n return `${prefix}***`;\n });\n }\n return s;\n}\n\n/**\n * Test-only helper exported for `_test-reset.ts`. NOT included in the\n * `index.ts` barrel — vitest setup imports the dedicated module via\n * explicit path to discourage production callers.\n *\n * @internal\n */\nexport function _resetForTests(opts: { enabled?: boolean; clearExtras?: boolean }): void {\n if (opts.enabled !== undefined) REDACT_ENABLED = opts.enabled;\n if (opts.clearExtras === true) _extraPatterns.length = 0;\n}\n\n/**\n * T5.4 — Test-only count of BUILTIN_PATTERNS. Exposed so the count-floor\n * assertion can run without re-deriving the array shape in test land.\n * NOT included in the public barrel.\n *\n * @internal\n */\nexport function __TESTING__BUILTIN_PATTERN_COUNT(): number {\n return BUILTIN_PATTERNS.length;\n}\n"]}
|