@theokit/sdk 0.0.0-compat-580-20260905204608
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 +7923 -0
- package/LICENSE +201 -0
- package/README.md +114 -0
- package/dist/a2a/agent-mailbox.d.cts +54 -0
- package/dist/a2a/agent-mailbox.d.ts +54 -0
- package/dist/a2a/index.cjs +138 -0
- package/dist/a2a/index.cjs.map +1 -0
- package/dist/a2a/index.d.cts +10 -0
- package/dist/a2a/index.d.ts +10 -0
- package/dist/a2a/index.js +125 -0
- package/dist/a2a/index.js.map +1 -0
- package/dist/a2a/message-bus.d.cts +118 -0
- package/dist/a2a/message-bus.d.ts +118 -0
- package/dist/a2a/subagent.d.cts +231 -0
- package/dist/a2a/subagent.d.ts +231 -0
- package/dist/a2a/types.d.cts +45 -0
- package/dist/a2a/types.d.ts +45 -0
- package/dist/agent-ARLOD4JX.cjs +67 -0
- package/dist/agent-ARLOD4JX.cjs.map +1 -0
- package/dist/agent-C3KO5LKm.d.cts +1871 -0
- package/dist/agent-CvmTR9uf.d.ts +1871 -0
- package/dist/agent-N6WJ54ML.js +58 -0
- package/dist/agent-N6WJ54ML.js.map +1 -0
- package/dist/agent-builder.d.ts +72 -0
- package/dist/agent-factory-registry-UU46BUMU.cjs +16 -0
- package/dist/agent-factory-registry-UU46BUMU.cjs.map +1 -0
- package/dist/agent-factory-registry-ZVTABLEY.js +3 -0
- package/dist/agent-factory-registry-ZVTABLEY.js.map +1 -0
- package/dist/agent-factory.d.ts +24 -0
- package/dist/agent-generate.d.ts +12 -0
- package/dist/agent-session-store-AFML3AXC.js +6 -0
- package/dist/agent-session-store-AFML3AXC.js.map +1 -0
- package/dist/agent-session-store-MTSIY3MH.cjs +23 -0
- package/dist/agent-session-store-MTSIY3MH.cjs.map +1 -0
- package/dist/agent.d.ts +276 -0
- package/dist/auth/index.cjs +306 -0
- package/dist/auth/index.cjs.map +1 -0
- package/dist/auth/index.d.cts +34 -0
- package/dist/auth/index.d.ts +34 -0
- package/dist/auth/index.js +247 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/batch-I6T6MXZO.cjs +263 -0
- package/dist/batch-I6T6MXZO.cjs.map +1 -0
- package/dist/batch-US4F6WPK.js +260 -0
- 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-24SYBZPL.cjs +121 -0
- package/dist/chunk-24SYBZPL.cjs.map +1 -0
- package/dist/chunk-2HPNT6HH.cjs +3373 -0
- package/dist/chunk-2HPNT6HH.cjs.map +1 -0
- package/dist/chunk-2SFBB54R.js +23 -0
- package/dist/chunk-2SFBB54R.js.map +1 -0
- package/dist/chunk-2WXHA33T.js +105 -0
- 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-2XRAWOZZ.js +172 -0
- package/dist/chunk-2XRAWOZZ.js.map +1 -0
- package/dist/chunk-2ZPEDVLM.cjs +59 -0
- package/dist/chunk-2ZPEDVLM.cjs.map +1 -0
- package/dist/chunk-3EE6LVWT.cjs +29 -0
- package/dist/chunk-3EE6LVWT.cjs.map +1 -0
- package/dist/chunk-3JHIFQ4I.js +102 -0
- package/dist/chunk-3JHIFQ4I.js.map +1 -0
- package/dist/chunk-44I6UYVH.js +133 -0
- package/dist/chunk-44I6UYVH.js.map +1 -0
- package/dist/chunk-47TF32NQ.js +79 -0
- package/dist/chunk-47TF32NQ.js.map +1 -0
- package/dist/chunk-4A3SKJ53.cjs +297 -0
- package/dist/chunk-4A3SKJ53.cjs.map +1 -0
- package/dist/chunk-4HS6FFGL.cjs +433 -0
- package/dist/chunk-4HS6FFGL.cjs.map +1 -0
- package/dist/chunk-4MMWFSCD.js +25 -0
- package/dist/chunk-4MMWFSCD.js.map +1 -0
- package/dist/chunk-4NLCWGH7.cjs +177 -0
- package/dist/chunk-4NLCWGH7.cjs.map +1 -0
- package/dist/chunk-55GB6JYQ.js +208 -0
- package/dist/chunk-55GB6JYQ.js.map +1 -0
- package/dist/chunk-5WKQDIGO.js +136 -0
- package/dist/chunk-5WKQDIGO.js.map +1 -0
- package/dist/chunk-67SBTGMA.cjs +457 -0
- package/dist/chunk-67SBTGMA.cjs.map +1 -0
- package/dist/chunk-6LHQPOMI.cjs +193 -0
- package/dist/chunk-6LHQPOMI.cjs.map +1 -0
- package/dist/chunk-6M2OIS4Y.js +158 -0
- package/dist/chunk-6M2OIS4Y.js.map +1 -0
- package/dist/chunk-6PWOWXMC.js +121 -0
- package/dist/chunk-6PWOWXMC.js.map +1 -0
- package/dist/chunk-6X6ID4MO.js +20 -0
- package/dist/chunk-6X6ID4MO.js.map +1 -0
- package/dist/chunk-7A6535RA.cjs +231 -0
- package/dist/chunk-7A6535RA.cjs.map +1 -0
- package/dist/chunk-7FDKWDA2.cjs +135 -0
- package/dist/chunk-7FDKWDA2.cjs.map +1 -0
- package/dist/chunk-7I5Z3UBJ.js +10 -0
- package/dist/chunk-7I5Z3UBJ.js.map +1 -0
- package/dist/chunk-7JJ3A6AT.cjs +88 -0
- package/dist/chunk-7JJ3A6AT.cjs.map +1 -0
- package/dist/chunk-7SZAV6QG.js +593 -0
- package/dist/chunk-7SZAV6QG.js.map +1 -0
- package/dist/chunk-A4RAL2ER.cjs +51 -0
- package/dist/chunk-A4RAL2ER.cjs.map +1 -0
- package/dist/chunk-AA27GEYS.cjs +12 -0
- package/dist/chunk-AA27GEYS.cjs.map +1 -0
- package/dist/chunk-AAEZSPTC.js +133 -0
- package/dist/chunk-AAEZSPTC.js.map +1 -0
- package/dist/chunk-AGACYRJ2.js +11 -0
- package/dist/chunk-AGACYRJ2.js.map +1 -0
- package/dist/chunk-ALUN2B4W.js +356 -0
- 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-ATT276RD.cjs +173 -0
- package/dist/chunk-ATT276RD.cjs.map +1 -0
- package/dist/chunk-AW6F6HZR.js +166 -0
- package/dist/chunk-AW6F6HZR.js.map +1 -0
- package/dist/chunk-AWINL3ZC.js +109 -0
- package/dist/chunk-AWINL3ZC.js.map +1 -0
- package/dist/chunk-BJUJT5ED.cjs +186 -0
- package/dist/chunk-BJUJT5ED.cjs.map +1 -0
- package/dist/chunk-BUUUWQMB.cjs +34 -0
- package/dist/chunk-BUUUWQMB.cjs.map +1 -0
- package/dist/chunk-BV2MWEMV.cjs +26 -0
- package/dist/chunk-BV2MWEMV.cjs.map +1 -0
- package/dist/chunk-CFE6QF2Q.js +221 -0
- package/dist/chunk-CFE6QF2Q.js.map +1 -0
- package/dist/chunk-CZJ6Q7CW.js +183 -0
- package/dist/chunk-CZJ6Q7CW.js.map +1 -0
- package/dist/chunk-D3CCY3A2.cjs +10995 -0
- package/dist/chunk-D3CCY3A2.cjs.map +1 -0
- package/dist/chunk-D6POWE7E.cjs +210 -0
- package/dist/chunk-D6POWE7E.cjs.map +1 -0
- package/dist/chunk-DMRT67Y6.js +100 -0
- package/dist/chunk-DMRT67Y6.js.map +1 -0
- package/dist/chunk-DQZU7JK6.cjs +125 -0
- package/dist/chunk-DQZU7JK6.cjs.map +1 -0
- package/dist/chunk-EFMFILPG.js +77 -0
- package/dist/chunk-EFMFILPG.js.map +1 -0
- package/dist/chunk-EH6XD3FY.js +222 -0
- package/dist/chunk-EH6XD3FY.js.map +1 -0
- package/dist/chunk-EIQFAOFD.js +229 -0
- package/dist/chunk-EIQFAOFD.js.map +1 -0
- package/dist/chunk-EPSICJLZ.js +79 -0
- package/dist/chunk-EPSICJLZ.js.map +1 -0
- package/dist/chunk-EXTRW7GW.cjs +155 -0
- package/dist/chunk-EXTRW7GW.cjs.map +1 -0
- package/dist/chunk-FD2UT76F.js +3 -0
- package/dist/chunk-FD2UT76F.js.map +1 -0
- package/dist/chunk-FJWQP6EE.js +122 -0
- package/dist/chunk-FJWQP6EE.js.map +1 -0
- package/dist/chunk-FRITRLZQ.cjs +24 -0
- package/dist/chunk-FRITRLZQ.cjs.map +1 -0
- package/dist/chunk-FUSDYC2B.cjs +280 -0
- package/dist/chunk-FUSDYC2B.cjs.map +1 -0
- package/dist/chunk-G7BLGBRN.js +43 -0
- package/dist/chunk-G7BLGBRN.js.map +1 -0
- package/dist/chunk-GBCVPKHE.js +282 -0
- package/dist/chunk-GBCVPKHE.js.map +1 -0
- package/dist/chunk-GHX4P3V2.cjs +34 -0
- package/dist/chunk-GHX4P3V2.cjs.map +1 -0
- package/dist/chunk-GZV6AVRL.cjs +282 -0
- package/dist/chunk-GZV6AVRL.cjs.map +1 -0
- package/dist/chunk-H73MEMQB.js +31 -0
- package/dist/chunk-H73MEMQB.js.map +1 -0
- package/dist/chunk-HCT4HPCL.cjs +235 -0
- package/dist/chunk-HCT4HPCL.cjs.map +1 -0
- package/dist/chunk-HFEJE7AC.js +424 -0
- package/dist/chunk-HFEJE7AC.js.map +1 -0
- package/dist/chunk-HKCKOAIO.js +57 -0
- package/dist/chunk-HKCKOAIO.js.map +1 -0
- package/dist/chunk-HUFSABUZ.cjs +48 -0
- package/dist/chunk-HUFSABUZ.cjs.map +1 -0
- package/dist/chunk-HW7SEELD.cjs +46 -0
- package/dist/chunk-HW7SEELD.cjs.map +1 -0
- package/dist/chunk-HY66GLM6.js +13 -0
- package/dist/chunk-HY66GLM6.js.map +1 -0
- package/dist/chunk-I2PWY7VM.cjs +27 -0
- package/dist/chunk-I2PWY7VM.cjs.map +1 -0
- package/dist/chunk-IJ7M6GOG.cjs +28 -0
- package/dist/chunk-IJ7M6GOG.cjs.map +1 -0
- package/dist/chunk-IU5N5224.cjs +288 -0
- package/dist/chunk-IU5N5224.cjs.map +1 -0
- package/dist/chunk-IUMAQURF.js +130 -0
- package/dist/chunk-IUMAQURF.js.map +1 -0
- package/dist/chunk-J7J7J2GN.cjs +377 -0
- package/dist/chunk-J7J7J2GN.cjs.map +1 -0
- package/dist/chunk-JLRLCBJ4.cjs +108 -0
- package/dist/chunk-JLRLCBJ4.cjs.map +1 -0
- package/dist/chunk-JMDDYA22.js +171 -0
- package/dist/chunk-JMDDYA22.js.map +1 -0
- package/dist/chunk-JNAA4G4H.js +43 -0
- package/dist/chunk-JNAA4G4H.js.map +1 -0
- package/dist/chunk-JOFVLOFY.js +268 -0
- package/dist/chunk-JOFVLOFY.js.map +1 -0
- package/dist/chunk-K2BQQ445.js +30 -0
- package/dist/chunk-K2BQQ445.js.map +1 -0
- package/dist/chunk-K2VMFZQ5.js +487 -0
- package/dist/chunk-K2VMFZQ5.js.map +1 -0
- package/dist/chunk-K3NH62DG.js +3343 -0
- package/dist/chunk-K3NH62DG.js.map +1 -0
- package/dist/chunk-KGANQYP7.cjs +172 -0
- package/dist/chunk-KGANQYP7.cjs.map +1 -0
- package/dist/chunk-KRD3GQAA.cjs +71 -0
- package/dist/chunk-KRD3GQAA.cjs.map +1 -0
- package/dist/chunk-KTTHHYEW.cjs +45 -0
- package/dist/chunk-KTTHHYEW.cjs.map +1 -0
- package/dist/chunk-KVNWIAO4.js +68 -0
- package/dist/chunk-KVNWIAO4.js.map +1 -0
- package/dist/chunk-KVSAY6NZ.cjs +497 -0
- package/dist/chunk-KVSAY6NZ.cjs.map +1 -0
- package/dist/chunk-LOHMT36V.cjs +178 -0
- package/dist/chunk-LOHMT36V.cjs.map +1 -0
- package/dist/chunk-LX7SEXOQ.js +152 -0
- package/dist/chunk-LX7SEXOQ.js.map +1 -0
- package/dist/chunk-MUUQ2WFJ.cjs +4 -0
- package/dist/chunk-MUUQ2WFJ.cjs.map +1 -0
- package/dist/chunk-N6OOOYFZ.js +281 -0
- package/dist/chunk-N6OOOYFZ.js.map +1 -0
- package/dist/chunk-NAF4L3T6.js +22 -0
- package/dist/chunk-NAF4L3T6.js.map +1 -0
- package/dist/chunk-NINIJCHU.cjs +23 -0
- package/dist/chunk-NINIJCHU.cjs.map +1 -0
- package/dist/chunk-NJWYQWDL.js +43 -0
- package/dist/chunk-NJWYQWDL.js.map +1 -0
- package/dist/chunk-NQTD6QOW.cjs +226 -0
- package/dist/chunk-NQTD6QOW.cjs.map +1 -0
- package/dist/chunk-NQTNSHSB.cjs +843 -0
- package/dist/chunk-NQTNSHSB.cjs.map +1 -0
- package/dist/chunk-NVXXWAU7.cjs +13 -0
- package/dist/chunk-NVXXWAU7.cjs.map +1 -0
- package/dist/chunk-NYQ3IS7K.cjs +130 -0
- package/dist/chunk-NYQ3IS7K.cjs.map +1 -0
- package/dist/chunk-O6USDERH.js +165 -0
- package/dist/chunk-O6USDERH.js.map +1 -0
- package/dist/chunk-OBA6YK2R.cjs +8 -0
- package/dist/chunk-OBA6YK2R.cjs.map +1 -0
- package/dist/chunk-OQRGVTQF.js +169 -0
- package/dist/chunk-OQRGVTQF.js.map +1 -0
- package/dist/chunk-OR6XIWLB.js +19 -0
- package/dist/chunk-OR6XIWLB.js.map +1 -0
- package/dist/chunk-OYD3U3LY.js +10981 -0
- package/dist/chunk-OYD3U3LY.js.map +1 -0
- package/dist/chunk-PRZ3BES7.cjs +79 -0
- package/dist/chunk-PRZ3BES7.cjs.map +1 -0
- package/dist/chunk-PY2RQOA7.js +6 -0
- package/dist/chunk-PY2RQOA7.js.map +1 -0
- package/dist/chunk-Q5EWJPRY.js +18 -0
- package/dist/chunk-Q5EWJPRY.js.map +1 -0
- package/dist/chunk-QATRS7JD.cjs +158 -0
- package/dist/chunk-QATRS7JD.cjs.map +1 -0
- package/dist/chunk-QC55H6RJ.cjs +601 -0
- package/dist/chunk-QC55H6RJ.cjs.map +1 -0
- package/dist/chunk-QDM3OHUT.cjs +134 -0
- package/dist/chunk-QDM3OHUT.cjs.map +1 -0
- package/dist/chunk-QKLOP4VC.cjs +90 -0
- package/dist/chunk-QKLOP4VC.cjs.map +1 -0
- package/dist/chunk-QOGNZMHD.cjs +34 -0
- package/dist/chunk-QOGNZMHD.cjs.map +1 -0
- package/dist/chunk-QWD3CZWE.cjs +108 -0
- package/dist/chunk-QWD3CZWE.cjs.map +1 -0
- package/dist/chunk-QWD4RDZ3.cjs +136 -0
- package/dist/chunk-QWD4RDZ3.cjs.map +1 -0
- package/dist/chunk-QYLZQ43D.cjs +172 -0
- package/dist/chunk-QYLZQ43D.cjs.map +1 -0
- package/dist/chunk-R7WIIPUR.js +27 -0
- package/dist/chunk-R7WIIPUR.js.map +1 -0
- package/dist/chunk-RQMCOFAI.cjs +85 -0
- package/dist/chunk-RQMCOFAI.cjs.map +1 -0
- package/dist/chunk-SA6K24NB.cjs +25 -0
- package/dist/chunk-SA6K24NB.cjs.map +1 -0
- package/dist/chunk-SADXXGWU.js +809 -0
- package/dist/chunk-SADXXGWU.js.map +1 -0
- package/dist/chunk-SAGRF4IB.js +25 -0
- package/dist/chunk-SAGRF4IB.js.map +1 -0
- package/dist/chunk-SVQIW5RJ.js +81 -0
- package/dist/chunk-SVQIW5RJ.js.map +1 -0
- package/dist/chunk-TA3K7SBK.js +180 -0
- package/dist/chunk-TA3K7SBK.js.map +1 -0
- package/dist/chunk-TFG5IBZS.cjs +139 -0
- package/dist/chunk-TFG5IBZS.cjs.map +1 -0
- package/dist/chunk-TMKTSYDS.cjs +21 -0
- package/dist/chunk-TMKTSYDS.cjs.map +1 -0
- package/dist/chunk-UADQJBHR.cjs +172 -0
- package/dist/chunk-UADQJBHR.cjs.map +1 -0
- package/dist/chunk-UBR5PWD7.js +275 -0
- package/dist/chunk-UBR5PWD7.js.map +1 -0
- package/dist/chunk-UKMBRMGT.js +22 -0
- package/dist/chunk-UKMBRMGT.js.map +1 -0
- package/dist/chunk-V22DZIXO.js +147 -0
- package/dist/chunk-V22DZIXO.js.map +1 -0
- package/dist/chunk-VE6DFSKU.js +107 -0
- package/dist/chunk-VE6DFSKU.js.map +1 -0
- package/dist/chunk-VPK6PHIE.cjs +211 -0
- package/dist/chunk-VPK6PHIE.cjs.map +1 -0
- package/dist/chunk-VTYY7XL5.cjs +15 -0
- package/dist/chunk-VTYY7XL5.cjs.map +1 -0
- package/dist/chunk-VWUXIVEI.js +583 -0
- package/dist/chunk-VWUXIVEI.js.map +1 -0
- package/dist/chunk-WE22OXQA.js +48 -0
- package/dist/chunk-WE22OXQA.js.map +1 -0
- package/dist/chunk-WMWEI3NS.js +120 -0
- package/dist/chunk-WMWEI3NS.js.map +1 -0
- package/dist/chunk-WS5ULCL4.js +204 -0
- package/dist/chunk-WS5ULCL4.js.map +1 -0
- package/dist/chunk-XB4GI5RZ.js +115 -0
- package/dist/chunk-XB4GI5RZ.js.map +1 -0
- package/dist/chunk-XU6MLSC6.js +455 -0
- package/dist/chunk-XU6MLSC6.js.map +1 -0
- package/dist/chunk-XYFGKVZ7.js +15 -0
- package/dist/chunk-XYFGKVZ7.js.map +1 -0
- package/dist/chunk-Y2KYR2ED.cjs +118 -0
- package/dist/chunk-Y2KYR2ED.cjs.map +1 -0
- package/dist/chunk-YIFFF23U.cjs +109 -0
- package/dist/chunk-YIFFF23U.cjs.map +1 -0
- package/dist/chunk-YJNYDJ2T.cjs +27 -0
- package/dist/chunk-YJNYDJ2T.cjs.map +1 -0
- package/dist/chunk-YSTXFWQE.cjs +127 -0
- package/dist/chunk-YSTXFWQE.cjs.map +1 -0
- package/dist/chunk-Z2JFX372.cjs +595 -0
- package/dist/chunk-Z2JFX372.cjs.map +1 -0
- package/dist/chunk-Z3NTRKIC.cjs +111 -0
- package/dist/chunk-Z3NTRKIC.cjs.map +1 -0
- package/dist/chunk-ZF2LDKQQ.cjs +20 -0
- package/dist/chunk-ZF2LDKQQ.cjs.map +1 -0
- package/dist/client/index.cjs +73 -0
- package/dist/client/index.cjs.map +1 -0
- package/dist/client/index.d.cts +12 -0
- package/dist/client/index.d.ts +12 -0
- package/dist/client/index.js +71 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/theokit-client.d.cts +60 -0
- package/dist/client/theokit-client.d.ts +60 -0
- package/dist/client/types.d.cts +51 -0
- package/dist/client/types.d.ts +51 -0
- package/dist/compact-session-BHTPCIHA.cjs +61 -0
- package/dist/compact-session-BHTPCIHA.cjs.map +1 -0
- package/dist/compact-session-W4WLJTHA.js +24 -0
- package/dist/compact-session-W4WLJTHA.js.map +1 -0
- package/dist/compaction.cjs +66 -0
- package/dist/compaction.cjs.map +1 -0
- package/dist/compaction.d.cts +240 -0
- package/dist/compaction.d.ts +240 -0
- package/dist/compaction.js +5 -0
- package/dist/compaction.js.map +1 -0
- package/dist/concurrency.cjs +23 -0
- package/dist/concurrency.cjs.map +1 -0
- package/dist/concurrency.d.cts +22 -0
- package/dist/concurrency.d.ts +22 -0
- package/dist/concurrency.js +17 -0
- package/dist/concurrency.js.map +1 -0
- package/dist/context/index.cjs +37 -0
- package/dist/context/index.cjs.map +1 -0
- package/dist/context/index.d.cts +78 -0
- package/dist/context/index.d.ts +78 -0
- package/dist/context/index.js +20 -0
- package/dist/context/index.js.map +1 -0
- package/dist/context-4QOEWRDF.cjs +23 -0
- package/dist/context-4QOEWRDF.cjs.map +1 -0
- package/dist/context-Z3CFTT3H.js +6 -0
- package/dist/context-Z3CFTT3H.js.map +1 -0
- package/dist/create-skill.d.ts +40 -0
- package/dist/cron-C3PhZED0.d.cts +246 -0
- package/dist/cron-crfMMdAw.d.ts +246 -0
- package/dist/cron.cjs +68 -0
- package/dist/cron.cjs.map +1 -0
- package/dist/cron.d.cts +7 -0
- package/dist/cron.d.ts +7 -0
- package/dist/cron.js +59 -0
- package/dist/cron.js.map +1 -0
- package/dist/define-tool.d.ts +86 -0
- package/dist/errors-CLOAyuiv.d.ts +569 -0
- package/dist/errors-DrDEgyz1.d.cts +569 -0
- 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 +89 -0
- package/dist/errors.cjs.map +1 -0
- package/dist/errors.d.cts +4 -0
- package/dist/errors.d.ts +4 -0
- package/dist/errors.js +4 -0
- package/dist/errors.js.map +1 -0
- package/dist/eval.cjs +1056 -0
- package/dist/eval.cjs.map +1 -0
- package/dist/eval.d.cts +77 -0
- package/dist/eval.d.ts +77 -0
- package/dist/eval.js +1042 -0
- package/dist/eval.js.map +1 -0
- package/dist/event-bus.d.ts +42 -0
- package/dist/executor-XQAOQOHD.cjs +993 -0
- package/dist/executor-XQAOQOHD.cjs.map +1 -0
- package/dist/executor-ZNDQDX6Q.js +989 -0
- package/dist/executor-ZNDQDX6Q.js.map +1 -0
- package/dist/filesystem/index.cjs +204 -0
- package/dist/filesystem/index.cjs.map +1 -0
- package/dist/filesystem/index.d.cts +12 -0
- package/dist/filesystem/index.d.ts +12 -0
- package/dist/filesystem/index.js +195 -0
- package/dist/filesystem/index.js.map +1 -0
- package/dist/filesystem/local-filesystem.d.cts +54 -0
- package/dist/filesystem/local-filesystem.d.ts +54 -0
- package/dist/filesystem/types.d.cts +136 -0
- package/dist/filesystem/types.d.ts +136 -0
- package/dist/fork-agent-S2EPIML7.js +61 -0
- package/dist/fork-agent-S2EPIML7.js.map +1 -0
- package/dist/fork-agent-WAEQI2DL.cjs +64 -0
- package/dist/fork-agent-WAEQI2DL.cjs.map +1 -0
- package/dist/fs-session-store-77JU46UZ.js +10 -0
- package/dist/fs-session-store-77JU46UZ.js.map +1 -0
- package/dist/fs-session-store-E4U3P56L.cjs +19 -0
- package/dist/fs-session-store-E4U3P56L.cjs.map +1 -0
- package/dist/generate-object-BXV7BZRP.js +7 -0
- package/dist/generate-object-BXV7BZRP.js.map +1 -0
- package/dist/generate-object-YBI2TDJ3.cjs +20 -0
- package/dist/generate-object-YBI2TDJ3.cjs.map +1 -0
- package/dist/generate-object.d.ts +111 -0
- package/dist/index-manager-3UNPYH34.cjs +26 -0
- package/dist/index-manager-3UNPYH34.cjs.map +1 -0
- package/dist/index-manager-W7FDMGEG.js +17 -0
- package/dist/index-manager-W7FDMGEG.js.map +1 -0
- package/dist/index.cjs +2487 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +4166 -0
- package/dist/index.d.ts +4166 -0
- package/dist/index.js +2289 -0
- package/dist/index.js.map +1 -0
- package/dist/inject-session-SUM6TDJF.js +27 -0
- package/dist/inject-session-SUM6TDJF.js.map +1 -0
- package/dist/inject-session-W6A46J3E.cjs +29 -0
- package/dist/inject-session-W6A46J3E.cjs.map +1 -0
- package/dist/interactive/index.cjs +35 -0
- package/dist/interactive/index.cjs.map +1 -0
- package/dist/interactive/index.d.cts +12 -0
- package/dist/interactive/index.d.ts +12 -0
- package/dist/interactive/index.js +30 -0
- package/dist/interactive/index.js.map +1 -0
- package/dist/interactive/types.d.cts +95 -0
- package/dist/interactive/types.d.ts +95 -0
- package/dist/internal/agent/batch.d.ts +11 -0
- package/dist/internal/agent/helpers.d.ts +1 -0
- package/dist/internal/agent-loop/budget-gate.d.ts +1 -0
- package/dist/internal/agent-loop/doom-loop-tracker.d.ts +22 -0
- package/dist/internal/agent-loop/live-events.d.ts +46 -0
- package/dist/internal/agent-loop/loop-context-init.d.ts +2 -0
- package/dist/internal/agent-loop/loop-finalize.d.ts +25 -0
- package/dist/internal/agent-loop/loop-llm-stream.d.ts +1 -0
- package/dist/internal/agent-loop/loop-thinking-steps.d.ts +28 -0
- package/dist/internal/agent-loop/loop.d.ts +7 -0
- package/dist/internal/agent-loop/message-builders.d.ts +21 -0
- package/dist/internal/agent-loop/replay-messages.d.ts +41 -0
- package/dist/internal/agent-loop/tool-dispatch.d.ts +27 -0
- package/dist/internal/agent-loop/tool-executors.d.ts +1 -0
- package/dist/internal/agent-loop/tool-result-guard.d.ts +20 -0
- package/dist/internal/agent-loop/tool-timeout.d.ts +23 -0
- package/dist/internal/agent-loop/types.d.ts +43 -0
- package/dist/internal/agent-loop/usage-and-cost.d.ts +25 -0
- package/dist/internal/auth/api-key-prefix.d.ts +23 -0
- package/dist/internal/auth/api-key-validator.d.ts +46 -0
- package/dist/internal/auth/credential-availability.d.ts +61 -0
- package/dist/internal/auth/credential-store.d.ts +77 -0
- package/dist/internal/auth/oauth-device.d.ts +54 -0
- package/dist/internal/auth/oauth-engine.d.ts +21 -0
- package/dist/internal/auth/resolve-credential.d.ts +56 -0
- package/dist/internal/auth/types.d.ts +175 -0
- package/dist/internal/base-url.d.ts +14 -0
- package/dist/internal/budget/compute-cost.d.ts +28 -0
- package/dist/internal/budget/pricing-registry.d.ts +36 -0
- package/dist/internal/budget/tracker/budget-tracker.d.ts +11 -0
- package/dist/internal/budget/tracker/budget.d.ts +34 -0
- package/dist/internal/budget/usage-accumulator.d.ts +46 -0
- package/dist/internal/cloud-agent/cloud-agent.d.ts +1 -0
- package/dist/internal/cloud-agent/cloud-config-serializer.d.ts +3 -0
- package/dist/internal/cloud-agent/cloud-run.d.ts +1 -0
- package/dist/internal/cloud-agent/cloud-tool-parity.d.ts +1 -0
- package/dist/internal/cloud-agent/index.d.ts +7 -0
- package/dist/internal/cloud-agent/real-cloud-run.d.ts +2 -0
- package/dist/internal/cloud-agent/types.d.ts +56 -0
- package/dist/internal/concurrency/abort-utils.d.ts +21 -0
- package/dist/internal/concurrency/async-local-storage.d.ts +20 -0
- package/dist/internal/concurrency/async-semaphore.d.ts +24 -0
- package/dist/internal/concurrency/delegation-depth.d.ts +27 -0
- package/dist/internal/concurrency/map-with-concurrency.d.ts +28 -0
- package/dist/internal/concurrency/subagent-credentials.d.ts +112 -0
- package/dist/internal/diagnostics.d.ts +69 -0
- package/dist/internal/emit-run-event.d.ts +16 -0
- package/dist/internal/env.d.ts +1 -0
- package/dist/internal/error-mappers/anthropic.d.ts +30 -0
- package/dist/internal/error-mappers/bedrock.d.ts +16 -0
- package/dist/internal/error-mappers/default-retriable.d.ts +1 -0
- package/dist/internal/error-mappers/ollama.d.ts +41 -0
- package/dist/internal/error-mappers/openai-compatible.d.ts +25 -0
- package/dist/internal/error-mappers/shared.d.ts +23 -0
- package/dist/internal/error-mappers/vertex.d.ts +15 -0
- package/dist/internal/eval/aggregate.d.ts +9 -0
- package/dist/internal/eval/assert.d.ts +27 -0
- package/dist/internal/eval/code-runner.d.ts +28 -0
- package/dist/internal/eval/dataset-iter.d.ts +9 -0
- package/dist/internal/eval/runner.d.ts +9 -0
- package/dist/internal/eval/single-flight.d.ts +17 -0
- package/dist/internal/eval/telemetry.d.ts +23 -0
- package/dist/internal/eval/trials.d.ts +19 -0
- package/dist/internal/global-singleton.d.ts +16 -0
- package/dist/internal/http.d.ts +1 -0
- package/dist/internal/ids.d.ts +1 -0
- package/dist/internal/judge/judge-call.d.ts +48 -0
- package/dist/internal/judge/parse-verdict.d.ts +11 -0
- package/dist/internal/llm/abort-error.d.ts +1 -0
- package/dist/internal/llm/anthropic-shared.d.ts +100 -0
- package/dist/internal/llm/anthropic.d.ts +9 -0
- package/dist/internal/llm/bedrock-anthropic.d.ts +36 -0
- package/dist/internal/llm/bedrock-token-cache.d.ts +18 -0
- package/dist/internal/llm/credential-pool-context.d.ts +11 -0
- package/dist/internal/llm/credential-pool-types.d.ts +22 -0
- package/dist/internal/llm/credential-pool.d.ts +18 -0
- package/dist/internal/llm/fallback-client.d.ts +1 -0
- package/dist/internal/llm/fault-injection.d.ts +50 -0
- package/dist/internal/llm/finish.d.ts +1 -0
- package/dist/internal/llm/hermes-tool-extract.d.ts +11 -0
- package/dist/internal/llm/model-capabilities.d.ts +40 -0
- package/dist/internal/llm/model-identifier.d.ts +58 -0
- package/dist/internal/llm/model-option.d.ts +38 -0
- package/dist/internal/llm/ollama-native.d.ts +27 -0
- package/dist/internal/llm/openai-messages.d.ts +2 -0
- package/dist/internal/llm/openai.d.ts +146 -0
- package/dist/internal/llm/pool-aware-client.d.ts +16 -0
- package/dist/internal/llm/prompt-cache-key.d.ts +1 -0
- package/dist/internal/llm/responses.d.ts +97 -0
- package/dist/internal/llm/retry.d.ts +22 -0
- package/dist/internal/llm/retrying-client.d.ts +53 -0
- package/dist/internal/llm/router.d.ts +40 -0
- package/dist/internal/llm/sse.d.ts +21 -0
- package/dist/internal/llm/stream-relay.d.ts +17 -0
- package/dist/internal/llm/tool-result-content.d.ts +40 -0
- package/dist/internal/llm/transport-error.d.ts +9 -0
- package/dist/internal/llm/types.d.ts +226 -0
- package/dist/internal/llm/vertex-anthropic.d.ts +40 -0
- package/dist/internal/llm/vertex-auth.d.ts +30 -0
- package/dist/internal/llm/vertex-gemini.d.ts +28 -0
- package/dist/internal/llm/vertex-router.d.ts +21 -0
- package/dist/internal/local-agent/index.d.ts +6 -0
- package/dist/internal/local-agent/local-agent-bootstrap.d.ts +37 -0
- package/dist/internal/local-agent/local-agent-capabilities.d.ts +38 -0
- package/dist/internal/local-agent/local-agent-dispatch.d.ts +57 -0
- package/dist/internal/local-agent/local-agent-invalidate.d.ts +1 -0
- package/dist/internal/local-agent/local-agent-lifecycle.d.ts +13 -0
- package/dist/internal/local-agent/local-agent-memory-direct.d.ts +12 -0
- package/dist/internal/local-agent/local-agent-memory-hooks.d.ts +41 -0
- package/dist/internal/local-agent/local-agent-memory-provider.d.ts +57 -0
- package/dist/internal/local-agent/local-agent-memory.d.ts +1 -0
- package/dist/internal/local-agent/local-agent-personality-extensions.d.ts +43 -0
- package/dist/internal/local-agent/local-agent-runtime-extensions.d.ts +13 -0
- package/dist/internal/local-agent/local-agent-send.d.ts +42 -0
- package/dist/internal/local-agent/local-agent-task-wrap.d.ts +11 -0
- package/dist/internal/local-agent/local-agent.d.ts +1 -0
- package/dist/internal/local-agent/local-option-keys.d.ts +2 -0
- package/dist/internal/local-agent/local-run.d.ts +1 -0
- package/dist/internal/local-agent/mcp-pool.d.ts +43 -0
- 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-provider.d.ts +13 -0
- package/dist/internal/local-agent/real-local-run-tools.d.ts +55 -0
- package/dist/internal/local-agent/real-local-run.d.ts +4 -0
- package/dist/internal/mcp/client.d.ts +16 -0
- package/dist/internal/mcp/handshake-timeout.d.ts +53 -0
- package/dist/internal/mcp/oauth.d.ts +19 -0
- package/dist/internal/mcp/token-storage.d.ts +52 -0
- package/dist/internal/memory/active-memory-cache.d.ts +10 -0
- package/dist/internal/memory/active-memory-types.d.ts +8 -0
- package/dist/internal/memory/active-memory.d.ts +56 -0
- package/dist/internal/memory/adapters/azure-openai-embedding.d.cts +2 -0
- package/dist/internal/memory/adapters/azure-openai-embedding.d.ts +2 -0
- package/dist/internal/memory/adapters/catalog.d.cts +1 -0
- package/dist/internal/memory/adapters/catalog.d.ts +1 -0
- package/dist/internal/memory/adapters/cohere-embedding.d.cts +2 -0
- package/dist/internal/memory/adapters/cohere-embedding.d.ts +2 -0
- package/dist/internal/memory/adapters/deepinfra-embedding.d.cts +2 -0
- package/dist/internal/memory/adapters/deepinfra-embedding.d.ts +2 -0
- package/dist/internal/memory/adapters/gemini-embedding.d.cts +2 -0
- package/dist/internal/memory/adapters/gemini-embedding.d.ts +2 -0
- package/dist/internal/memory/adapters/index.cjs +30 -0
- package/dist/internal/memory/adapters/index.cjs.map +1 -0
- package/dist/internal/memory/adapters/index.d.cts +18 -0
- package/dist/internal/memory/adapters/index.d.ts +18 -0
- package/dist/internal/memory/adapters/index.js +13 -0
- package/dist/internal/memory/adapters/index.js.map +1 -0
- package/dist/internal/memory/adapters/jina-embedding.d.cts +2 -0
- package/dist/internal/memory/adapters/jina-embedding.d.ts +2 -0
- package/dist/internal/memory/adapters/mistral-embedding.d.cts +2 -0
- package/dist/internal/memory/adapters/mistral-embedding.d.ts +2 -0
- package/dist/internal/memory/adapters/ollama-embedding.d.cts +34 -0
- package/dist/internal/memory/adapters/ollama-embedding.d.ts +34 -0
- package/dist/internal/memory/adapters/openai-compatible.d.cts +96 -0
- package/dist/internal/memory/adapters/openai-compatible.d.ts +96 -0
- package/dist/internal/memory/adapters/openai-embedding.d.cts +12 -0
- package/dist/internal/memory/adapters/openai-embedding.d.ts +12 -0
- package/dist/internal/memory/adapters/openrouter-embedding.d.cts +2 -0
- package/dist/internal/memory/adapters/openrouter-embedding.d.ts +2 -0
- package/dist/internal/memory/adapters/voyage-embedding.d.cts +2 -0
- package/dist/internal/memory/adapters/voyage-embedding.d.ts +2 -0
- package/dist/internal/memory/corpus-sync.d.ts +23 -0
- package/dist/internal/memory/dreaming/diary.d.ts +41 -0
- package/dist/internal/memory/dreaming/phases.d.ts +35 -0
- package/dist/internal/memory/dreaming/run.d.ts +10 -0
- package/dist/internal/memory/embedding-adapter.d.ts +42 -0
- package/dist/internal/memory/embedding-cache.d.ts +42 -0
- package/dist/internal/memory/escape-like-pattern.d.ts +22 -0
- package/dist/internal/memory/index-db.d.ts +67 -0
- package/dist/internal/memory/index-manager-contract.d.ts +48 -0
- package/dist/internal/memory/index-manager-dispatch.d.ts +23 -0
- package/dist/internal/memory/index-manager-helpers.d.ts +20 -0
- package/dist/internal/memory/index-manager.d.ts +44 -0
- package/dist/internal/memory/index-repository.d.ts +58 -0
- package/dist/internal/memory/index-schema.d.ts +21 -0
- package/dist/internal/memory/lance-index.d.ts +46 -0
- package/dist/internal/memory/lance-memory-adapter.d.ts +45 -0
- package/dist/internal/memory/memory-index.d.ts +67 -0
- package/dist/internal/memory/migrate-sqlite-to-lance.d.ts +58 -0
- package/dist/internal/memory/migration.d.ts +9 -0
- package/dist/internal/memory/sdk-memory-peer-loader.d.ts +74 -0
- package/dist/internal/memory/sqlite-vec-loader.d.ts +1 -0
- package/dist/internal/memory/storage/chunk-markdown.d.cts +2 -0
- package/dist/internal/memory/storage/chunk-markdown.d.ts +2 -0
- package/dist/internal/memory/storage/index.cjs +141 -0
- package/dist/internal/memory/storage/index.cjs.map +1 -0
- package/dist/internal/memory/storage/index.d.cts +28 -0
- package/dist/internal/memory/storage/index.d.ts +28 -0
- package/dist/internal/memory/storage/index.js +16 -0
- package/dist/internal/memory/storage/index.js.map +1 -0
- package/dist/internal/memory/storage/list-markdown.d.cts +1 -0
- package/dist/internal/memory/storage/list-markdown.d.ts +1 -0
- package/dist/internal/memory/storage/markdown-store.d.cts +48 -0
- package/dist/internal/memory/storage/markdown-store.d.ts +48 -0
- package/dist/internal/memory/storage/memory-file.d.cts +90 -0
- package/dist/internal/memory/storage/memory-file.d.ts +90 -0
- package/dist/internal/memory/storage/memory-root.d.cts +119 -0
- package/dist/internal/memory/storage/memory-root.d.ts +119 -0
- package/dist/internal/memory/storage/reader.d.cts +8 -0
- package/dist/internal/memory/storage/reader.d.ts +8 -0
- package/dist/internal/memory/storage/session-loader.d.cts +35 -0
- package/dist/internal/memory/storage/session-loader.d.ts +35 -0
- package/dist/internal/memory/storage/session-summary-writer.d.cts +50 -0
- package/dist/internal/memory/storage/session-summary-writer.d.ts +50 -0
- package/dist/internal/memory/storage/threat-scan.d.cts +62 -0
- package/dist/internal/memory/storage/threat-scan.d.ts +62 -0
- package/dist/internal/memory/storage/transcript-store.d.cts +38 -0
- package/dist/internal/memory/storage/transcript-store.d.ts +38 -0
- package/dist/internal/memory/storage/wiki-loader.d.cts +27 -0
- package/dist/internal/memory/storage/wiki-loader.d.ts +27 -0
- package/dist/internal/memory/tools.d.ts +21 -0
- package/dist/internal/memory/types.d.ts +78 -0
- package/dist/internal/memory/vec-index.d.ts +28 -0
- package/dist/internal/persistence/atomic-write.d.cts +107 -0
- package/dist/internal/persistence/atomic-write.d.ts +107 -0
- package/dist/internal/persistence/cwd-mutex.d.cts +35 -0
- package/dist/internal/persistence/cwd-mutex.d.ts +35 -0
- package/dist/internal/persistence/exclusive-create.d.cts +53 -0
- package/dist/internal/persistence/exclusive-create.d.ts +53 -0
- package/dist/internal/persistence/file-lock.d.cts +54 -0
- package/dist/internal/persistence/file-lock.d.ts +54 -0
- package/dist/internal/persistence/fs-session-store.d.cts +68 -0
- package/dist/internal/persistence/fs-session-store.d.ts +68 -0
- package/dist/internal/persistence/fts5-sanitize.d.cts +44 -0
- package/dist/internal/persistence/fts5-sanitize.d.ts +44 -0
- package/dist/internal/persistence/index.cjs +127 -0
- package/dist/internal/persistence/index.cjs.map +1 -0
- package/dist/internal/persistence/index.d.cts +33 -0
- package/dist/internal/persistence/index.d.ts +33 -0
- package/dist/internal/persistence/index.js +40 -0
- package/dist/internal/persistence/index.js.map +1 -0
- package/dist/internal/persistence/jsonl.d.cts +43 -0
- package/dist/internal/persistence/jsonl.d.ts +43 -0
- package/dist/internal/persistence/markdown-config-loader.d.cts +35 -0
- package/dist/internal/persistence/markdown-config-loader.d.ts +35 -0
- package/dist/internal/persistence/pagination.d.cts +21 -0
- package/dist/internal/persistence/pagination.d.ts +21 -0
- package/dist/internal/persistence/paths.d.cts +137 -0
- package/dist/internal/persistence/paths.d.ts +137 -0
- package/dist/internal/persistence/persistence-schema.d.cts +29 -0
- package/dist/internal/persistence/persistence-schema.d.ts +29 -0
- package/dist/internal/persistence/schema-version.d.cts +227 -0
- package/dist/internal/persistence/schema-version.d.ts +227 -0
- package/dist/internal/persistence/session-artifacts.d.cts +27 -0
- package/dist/internal/persistence/session-artifacts.d.ts +27 -0
- package/dist/internal/persistence/session-dir.d.cts +1 -0
- package/dist/internal/persistence/session-dir.d.ts +1 -0
- package/dist/internal/persistence/session-transcript.d.cts +128 -0
- package/dist/internal/persistence/session-transcript.d.ts +128 -0
- package/dist/internal/persistence/session-writer.d.cts +104 -0
- package/dist/internal/persistence/session-writer.d.ts +104 -0
- package/dist/internal/persistence/sqlite-cas.d.cts +61 -0
- package/dist/internal/persistence/sqlite-cas.d.ts +61 -0
- package/dist/internal/persistence/sqlite-open.d.cts +61 -0
- package/dist/internal/persistence/sqlite-open.d.ts +61 -0
- package/dist/internal/persistence/sqlite-wal.d.cts +54 -0
- package/dist/internal/persistence/sqlite-wal.d.ts +54 -0
- package/dist/internal/persistence/transcript-ops.d.cts +99 -0
- package/dist/internal/persistence/transcript-ops.d.ts +99 -0
- package/dist/internal/personality/context.d.ts +17 -0
- package/dist/internal/personality/registry.d.ts +17 -0
- package/dist/internal/personality/store.d.ts +27 -0
- package/dist/internal/personality/switch.d.ts +36 -0
- package/dist/internal/personality/types.d.ts +18 -0
- package/dist/internal/plugins/context.d.cts +21 -0
- package/dist/internal/plugins/context.d.ts +21 -0
- package/dist/internal/plugins/enabled-names.d.cts +1 -0
- package/dist/internal/plugins/enabled-names.d.ts +1 -0
- package/dist/internal/plugins/index.d.cts +9 -0
- package/dist/internal/plugins/index.d.ts +9 -0
- package/dist/internal/plugins/lifecycle.d.cts +15 -0
- package/dist/internal/plugins/lifecycle.d.ts +15 -0
- package/dist/internal/plugins/manager.d.cts +57 -0
- package/dist/internal/plugins/manager.d.ts +57 -0
- package/dist/internal/plugins/plugin-guards.d.cts +13 -0
- package/dist/internal/plugins/plugin-guards.d.ts +13 -0
- package/dist/internal/plugins/types.d.cts +26 -0
- package/dist/internal/plugins/types.d.ts +26 -0
- package/dist/internal/providers/builtin/anthropic.d.ts +2 -0
- package/dist/internal/providers/builtin/bedrock.d.ts +25 -0
- package/dist/internal/providers/builtin/cerebras.d.ts +5 -0
- package/dist/internal/providers/builtin/cohere.d.ts +8 -0
- package/dist/internal/providers/builtin/deepinfra.d.ts +2 -0
- package/dist/internal/providers/builtin/gemini.d.ts +10 -0
- package/dist/internal/providers/builtin/google.d.ts +6 -0
- package/dist/internal/providers/builtin/groq.d.ts +2 -0
- package/dist/internal/providers/builtin/index.d.ts +20 -0
- package/dist/internal/providers/builtin/llamacpp.d.ts +1 -0
- package/dist/internal/providers/builtin/lmstudio.d.ts +1 -0
- package/dist/internal/providers/builtin/mistral.d.ts +2 -0
- package/dist/internal/providers/builtin/ollama.d.ts +17 -0
- package/dist/internal/providers/builtin/openai-chatgpt.d.ts +14 -0
- package/dist/internal/providers/builtin/openai-compatible.d.ts +1 -0
- package/dist/internal/providers/builtin/openai.d.ts +2 -0
- package/dist/internal/providers/builtin/openrouter.d.ts +2 -0
- package/dist/internal/providers/builtin/perplexity.d.ts +5 -0
- package/dist/internal/providers/builtin/together.d.ts +2 -0
- package/dist/internal/providers/builtin/vertex.d.ts +27 -0
- package/dist/internal/providers/builtin/xai.d.ts +2 -0
- package/dist/internal/providers/catalog-loader.d.ts +55 -0
- package/dist/internal/providers/catalog-schema.d.ts +202 -0
- package/dist/internal/providers/catalog-source-models-dev.d.ts +80 -0
- package/dist/internal/providers/discovery.d.ts +14 -0
- package/dist/internal/providers/index.d.ts +8 -0
- package/dist/internal/providers/register-plugin-providers.d.ts +22 -0
- package/dist/internal/providers/registry.d.ts +13 -0
- package/dist/internal/providers/types.d.ts +11 -0
- package/dist/internal/retry/circuit-breaker.d.ts +26 -0
- package/dist/internal/retry/with-retry.d.ts +40 -0
- package/dist/internal/runtime/compat/compat-config-file.d.ts +31 -0
- package/dist/internal/runtime/compat/foreign-config-sources.d.ts +139 -0
- package/dist/internal/runtime/compression/compression-attempt.d.ts +24 -0
- package/dist/internal/runtime/compression/compression-config.d.ts +33 -0
- package/dist/internal/runtime/compression/compression-decision.d.ts +10 -0
- package/dist/internal/runtime/compression/compression-helpers.d.ts +18 -0
- package/dist/internal/runtime/compression/compression-model-registry.d.ts +41 -0
- package/dist/internal/runtime/compression/compression-summarizer.d.ts +34 -0
- package/dist/internal/runtime/config/default-model.d.ts +1 -0
- package/dist/internal/runtime/config/providers-manager.d.ts +1 -0
- package/dist/internal/runtime/config/workspace-dir.d.ts +9 -0
- package/dist/internal/runtime/context/context-aggregator.d.ts +26 -0
- package/dist/internal/runtime/context/context-discovery-runner.d.ts +80 -0
- package/dist/internal/runtime/context/context-discovery.d.ts +79 -0
- package/dist/internal/runtime/context/context-frontmatter.d.ts +16 -0
- package/dist/internal/runtime/context/context-glob.d.ts +1 -0
- package/dist/internal/runtime/context/context-import-resolver.d.ts +41 -0
- package/dist/internal/runtime/context/context-loaders.d.ts +42 -0
- package/dist/internal/runtime/context/context-manager.d.ts +28 -0
- package/dist/internal/runtime/context/context-mdc-parser.d.ts +25 -0
- package/dist/internal/runtime/context/context-rules-frontmatter.d.ts +99 -0
- package/dist/internal/runtime/context/context-yaml-lite.d.ts +26 -0
- package/dist/internal/runtime/context/project-instructions.d.ts +66 -0
- package/dist/internal/runtime/context/yaml-frontmatter.d.ts +20 -0
- package/dist/internal/runtime/fixtures/fixture-events.d.ts +12 -0
- package/dist/internal/runtime/fixtures/fixture-mode.d.ts +24 -0
- package/dist/internal/runtime/fixtures/fixture-responder.d.ts +1 -0
- package/dist/internal/runtime/fixtures/fixture-run-base.d.ts +96 -0
- package/dist/internal/runtime/fixtures/fixture-scripts.d.ts +21 -0
- package/dist/internal/runtime/fixtures/types.d.ts +1 -0
- package/dist/internal/runtime/hooks/hooks-executor.d.ts +49 -0
- package/dist/internal/runtime/hooks/hooks-source.d.ts +35 -0
- package/dist/internal/runtime/lifecycle/context-budget-event.d.ts +25 -0
- package/dist/internal/runtime/lifecycle/env-policy.d.ts +29 -0
- package/dist/internal/runtime/lifecycle/fork-agent.d.ts +15 -0
- package/dist/internal/runtime/lifecycle/goal-marker.d.ts +13 -0
- package/dist/internal/runtime/lifecycle/post-run-lifecycle.d.ts +16 -0
- package/dist/internal/runtime/lifecycle/run-to-completion.d.ts +22 -0
- package/dist/internal/runtime/lifecycle/run-until.d.ts +21 -0
- package/dist/internal/runtime/lifecycle/spawn-collect.d.ts +8 -0
- package/dist/internal/runtime/lifecycle/stream-to-completion.d.ts +31 -0
- package/dist/internal/runtime/lifecycle/wrap-completion-check-run.d.ts +30 -0
- package/dist/internal/runtime/memory-glue/memory-provider.d.ts +11 -0
- package/dist/internal/runtime/memory-glue/memory-store.d.ts +4 -0
- package/dist/internal/runtime/memory-glue/select-facts.d.ts +63 -0
- package/dist/internal/runtime/model-selection.d.ts +14 -0
- package/dist/internal/runtime/plugin-loader/plugin-bundles.d.ts +22 -0
- package/dist/internal/runtime/plugin-loader/plugin-frontmatter.d.ts +17 -0
- package/dist/internal/runtime/plugin-loader/plugins-manager.d.ts +1 -0
- package/dist/internal/runtime/processors/run-processors.d.ts +10 -0
- package/dist/internal/runtime/processors/tripwire-run.d.ts +16 -0
- package/dist/internal/runtime/processors/wrap-output-run.d.ts +18 -0
- package/dist/internal/runtime/registry/agent-factory-registry.d.ts +19 -0
- package/dist/internal/runtime/registry/agent-registry-contract.d.ts +31 -0
- package/dist/internal/runtime/registry/agent-registry-store.d.ts +75 -0
- package/dist/internal/runtime/registry/agent-registry.d.ts +6 -0
- package/dist/internal/runtime/registry/live-agent-registry.d.ts +132 -0
- package/dist/internal/runtime/registry/run-registry.d.ts +4 -0
- package/dist/internal/runtime/skills/discover-skills.d.ts +103 -0
- package/dist/internal/runtime/skills/skill-frontmatter.d.ts +6 -0
- package/dist/internal/runtime/skills/skills-block.d.ts +18 -0
- package/dist/internal/runtime/skills/skills-manager.d.ts +1 -0
- package/dist/internal/runtime/skills/subagent-tool-scope.d.ts +25 -0
- package/dist/internal/runtime/skills/subagents-loader.d.ts +1 -0
- package/dist/internal/runtime/system-prompt/escape.d.ts +1 -0
- package/dist/internal/runtime/system-prompt/local-assembly.d.ts +2 -0
- package/dist/internal/runtime/system-prompt/native-reasoning.d.ts +25 -0
- package/dist/internal/runtime/system-prompt/pipeline.d.ts +1 -0
- package/dist/internal/runtime/system-prompt/safe-call.d.ts +1 -0
- package/dist/internal/runtime/system-prompt/sources/active-memory-provider.d.ts +1 -0
- package/dist/internal/runtime/system-prompt/sources/base-provider.d.ts +1 -0
- package/dist/internal/runtime/system-prompt/sources/context-provider.d.ts +1 -0
- package/dist/internal/runtime/system-prompt/sources/memory-provider.d.ts +6 -0
- package/dist/internal/runtime/system-prompt/sources/reasoning-provider.d.ts +1 -0
- package/dist/internal/runtime/system-prompt/sources/skills-provider.d.ts +1 -0
- package/dist/internal/runtime/system-prompt/system-prompt.d.ts +1 -0
- package/dist/internal/runtime/system-prompt/types.d.ts +5 -0
- package/dist/internal/runtime/tools/shell-tool.d.ts +7 -0
- package/dist/internal/runtime/validation/validate-agent-options.d.ts +1 -0
- package/dist/internal/runtime/validation/validate-response.d.ts +18 -0
- package/dist/internal/scorers/levenshtein.d.ts +11 -0
- package/dist/internal/scorers/llm-judge.d.ts +41 -0
- package/dist/internal/security/index.cjs +52 -0
- package/dist/internal/security/index.cjs.map +1 -0
- package/dist/internal/security/index.d.cts +19 -0
- package/dist/internal/security/index.d.ts +19 -0
- package/dist/internal/security/index.js +7 -0
- package/dist/internal/security/index.js.map +1 -0
- package/dist/internal/security/path-containment.d.cts +24 -0
- package/dist/internal/security/path-containment.d.ts +24 -0
- package/dist/internal/security/path-guard.d.cts +166 -0
- package/dist/internal/security/path-guard.d.ts +166 -0
- package/dist/internal/security/redact.d.cts +74 -0
- package/dist/internal/security/redact.d.ts +74 -0
- package/dist/internal/security/test-reset.d.cts +10 -0
- package/dist/internal/security/test-reset.d.ts +10 -0
- package/dist/internal/session/agent-session-store.d.ts +65 -0
- package/dist/internal/session/agent-session.d.ts +48 -0
- package/dist/internal/session/compact-session.d.ts +97 -0
- package/dist/internal/session/index.d.ts +7 -0
- package/dist/internal/session/inject-session.d.ts +15 -0
- package/dist/internal/session/session-cache.d.ts +31 -0
- package/dist/internal/session/types.d.ts +46 -0
- package/dist/internal/structured-output-helpers.d.ts +54 -0
- package/dist/internal/task/registry.d.ts +60 -0
- package/dist/internal/task/ring-buffer.d.ts +10 -0
- package/dist/internal/task/store.d.ts +145 -0
- package/dist/internal/task/subscribe.d.ts +15 -0
- package/dist/internal/task/task-id.d.ts +22 -0
- package/dist/internal/task/task-run-event-bridge.d.ts +10 -0
- package/dist/internal/task/telemetry.d.ts +27 -0
- package/dist/internal/telemetry/adapter-registry.d.ts +12 -0
- package/dist/internal/telemetry/adapters/arize.d.ts +2 -0
- package/dist/internal/telemetry/adapters/braintrust.d.ts +7 -0
- package/dist/internal/telemetry/adapters/datadog.d.ts +2 -0
- package/dist/internal/telemetry/adapters/langfuse.d.ts +2 -0
- package/dist/internal/telemetry/adapters/langsmith.d.ts +7 -0
- package/dist/internal/telemetry/adapters/posthog.d.ts +2 -0
- package/dist/internal/telemetry/adapters/sentry.d.ts +2 -0
- package/dist/internal/telemetry/safe-require.d.ts +1 -0
- package/dist/internal/telemetry/span-names.d.ts +10 -0
- package/dist/internal/telemetry/tracer-loader.d.ts +20 -0
- package/dist/internal/telemetry/tracer.d.ts +57 -0
- package/dist/internal/tool-dispatch/repair-middleware.d.ts +34 -0
- package/dist/internal/tool-dispatch/strip-think.d.ts +22 -0
- package/dist/internal/tool-registry/personality-filter.d.ts +37 -0
- package/dist/internal/workflow/ctx.d.ts +24 -0
- package/dist/internal/workflow/error-shape.d.ts +7 -0
- package/dist/internal/workflow/event-stream.d.ts +13 -0
- package/dist/internal/workflow/evented-executor.d.ts +42 -0
- package/dist/internal/workflow/executor-helpers.d.ts +30 -0
- package/dist/internal/workflow/executor.d.ts +16 -0
- package/dist/internal/workflow/retry-policy.d.ts +14 -0
- package/dist/internal/workflow/run-id.d.ts +9 -0
- package/dist/internal/workflow/scheduler.d.ts +23 -0
- package/dist/internal/workflow/single-flight.d.ts +18 -0
- package/dist/internal/workflow/snapshot-store.d.ts +23 -0
- package/dist/internal/workflow/step-agent.d.ts +12 -0
- package/dist/internal/workflow/step-branch.d.ts +10 -0
- package/dist/internal/workflow/step-dowhile.d.ts +8 -0
- package/dist/internal/workflow/step-execution.d.ts +25 -0
- package/dist/internal/workflow/step-fn.d.ts +10 -0
- package/dist/internal/workflow/step-foreach.d.ts +11 -0
- package/dist/internal/workflow/step-parallel.d.ts +17 -0
- package/dist/internal/workflow/step-sleep.d.ts +7 -0
- package/dist/internal/workflow/telemetry.d.ts +21 -0
- package/dist/internal/zod-to-json-schema.d.ts +11 -0
- package/dist/job-queue.d.ts +68 -0
- package/dist/judge-call-46M2E5FA.cjs +22 -0
- package/dist/judge-call-46M2E5FA.cjs.map +1 -0
- package/dist/judge-call-FGUNNWEI.js +5 -0
- package/dist/judge-call-FGUNNWEI.js.map +1 -0
- package/dist/mcp-auth.cjs +314 -0
- package/dist/mcp-auth.cjs.map +1 -0
- package/dist/mcp-auth.d.cts +19 -0
- package/dist/mcp-auth.d.ts +19 -0
- package/dist/mcp-auth.js +307 -0
- package/dist/mcp-auth.js.map +1 -0
- package/dist/messages.cjs +24 -0
- package/dist/messages.cjs.map +1 -0
- package/dist/messages.d.cts +33 -0
- package/dist/messages.d.ts +33 -0
- package/dist/messages.js +20 -0
- package/dist/messages.js.map +1 -0
- package/dist/models.cjs +295 -0
- package/dist/models.cjs.map +1 -0
- package/dist/models.d.cts +18 -0
- package/dist/models.d.ts +18 -0
- package/dist/models.js +286 -0
- package/dist/models.js.map +1 -0
- package/dist/oauth-transaction-store-5RIR6D5C.js +5 -0
- package/dist/oauth-transaction-store-5RIR6D5C.js.map +1 -0
- package/dist/oauth-transaction-store-SXIE57OD.cjs +38 -0
- package/dist/oauth-transaction-store-SXIE57OD.cjs.map +1 -0
- package/dist/path-safety.cjs +39 -0
- package/dist/path-safety.cjs.map +1 -0
- package/dist/path-safety.d.cts +16 -0
- package/dist/path-safety.d.ts +16 -0
- package/dist/path-safety.js +6 -0
- package/dist/path-safety.js.map +1 -0
- package/dist/permission-engine.d.ts +134 -0
- package/dist/persistence.cjs +197 -0
- package/dist/persistence.cjs.map +1 -0
- package/dist/persistence.d.cts +40 -0
- package/dist/persistence.d.ts +40 -0
- package/dist/persistence.js +100 -0
- package/dist/persistence.js.map +1 -0
- package/dist/project.cjs +45 -0
- package/dist/project.cjs.map +1 -0
- package/dist/project.d.cts +14 -0
- package/dist/project.d.ts +14 -0
- package/dist/project.js +42 -0
- package/dist/project.js.map +1 -0
- package/dist/provider-catalog.json +1295 -0
- package/dist/providers.cjs +23 -0
- package/dist/providers.cjs.map +1 -0
- package/dist/providers.d.cts +31 -0
- package/dist/providers.d.ts +31 -0
- package/dist/providers.js +10 -0
- package/dist/providers.js.map +1 -0
- package/dist/registry-BZQFYRTL.cjs +46 -0
- package/dist/registry-BZQFYRTL.cjs.map +1 -0
- package/dist/registry-DMWCJKRF.js +9 -0
- package/dist/registry-DMWCJKRF.js.map +1 -0
- package/dist/retry.cjs +14 -0
- package/dist/retry.cjs.map +1 -0
- package/dist/retry.d.cts +35 -0
- package/dist/retry.d.ts +35 -0
- package/dist/retry.js +5 -0
- package/dist/retry.js.map +1 -0
- package/dist/run-CTAdRU3U.d.cts +1813 -0
- package/dist/run-CTAdRU3U.d.ts +1813 -0
- package/dist/run-to-completion-DRO77625.js +3 -0
- package/dist/run-to-completion-DRO77625.js.map +1 -0
- package/dist/run-to-completion-X4OWM673.cjs +48 -0
- package/dist/run-to-completion-X4OWM673.cjs.map +1 -0
- package/dist/run-until-6D6TQ4JN.js +146 -0
- package/dist/run-until-6D6TQ4JN.js.map +1 -0
- package/dist/run-until-DG2KXWB2.cjs +149 -0
- package/dist/run-until-DG2KXWB2.cjs.map +1 -0
- package/dist/sandbox/bwrap.d.cts +112 -0
- package/dist/sandbox/bwrap.d.ts +112 -0
- package/dist/sandbox/index.cjs +495 -0
- package/dist/sandbox/index.cjs.map +1 -0
- package/dist/sandbox/index.d.cts +13 -0
- package/dist/sandbox/index.d.ts +13 -0
- package/dist/sandbox/index.js +451 -0
- package/dist/sandbox/index.js.map +1 -0
- package/dist/sandbox/linux-sandbox.d.cts +218 -0
- package/dist/sandbox/linux-sandbox.d.ts +218 -0
- package/dist/sandbox/local-sandbox.d.cts +66 -0
- package/dist/sandbox/local-sandbox.d.ts +66 -0
- package/dist/sandbox/provision.d.cts +60 -0
- package/dist/sandbox/provision.d.ts +60 -0
- package/dist/sandbox/seccomp.d.cts +16 -0
- package/dist/sandbox/seccomp.d.ts +16 -0
- package/dist/sandbox/shell-escape.d.cts +8 -0
- package/dist/sandbox/shell-escape.d.ts +8 -0
- package/dist/sandbox/types.d.cts +143 -0
- package/dist/sandbox/types.d.ts +143 -0
- package/dist/sanitize/coerce.d.cts +1 -0
- package/dist/sanitize/coerce.d.ts +1 -0
- package/dist/sanitize/index.cjs +12 -0
- package/dist/sanitize/index.cjs.map +1 -0
- package/dist/sanitize/index.d.cts +9 -0
- package/dist/sanitize/index.d.ts +9 -0
- package/dist/sanitize/index.js +3 -0
- package/dist/sanitize/index.js.map +1 -0
- package/dist/sanitize/sanitize-tool-input.d.cts +11 -0
- package/dist/sanitize/sanitize-tool-input.d.ts +11 -0
- package/dist/sanitize/types.d.cts +52 -0
- package/dist/sanitize/types.d.ts +52 -0
- package/dist/scorers.d.ts +181 -0
- package/dist/sdk-agent-BOiKqOgL.d.cts +940 -0
- package/dist/sdk-agent-D4a_BR_6.d.ts +940 -0
- package/dist/server/auth/errors.d.cts +54 -0
- package/dist/server/auth/errors.d.ts +54 -0
- package/dist/server/auth/index.cjs +210 -0
- package/dist/server/auth/index.cjs.map +1 -0
- package/dist/server/auth/index.d.cts +244 -0
- package/dist/server/auth/index.d.ts +244 -0
- package/dist/server/auth/index.js +189 -0
- package/dist/server/auth/index.js.map +1 -0
- package/dist/server/auth/oauth-transaction-store.d.cts +52 -0
- package/dist/server/auth/oauth-transaction-store.d.ts +52 -0
- package/dist/server/auth/orchestrator.d.cts +15 -0
- package/dist/server/auth/orchestrator.d.ts +15 -0
- package/dist/server/auth/types.d.cts +109 -0
- package/dist/server/auth/types.d.ts +109 -0
- package/dist/server/auth/validate-return-to.d.cts +27 -0
- package/dist/server/auth/validate-return-to.d.ts +27 -0
- package/dist/server/errors-envelope.cjs +101 -0
- package/dist/server/errors-envelope.cjs.map +1 -0
- package/dist/server/errors-envelope.d.cts +67 -0
- package/dist/server/errors-envelope.d.ts +67 -0
- package/dist/server/errors-envelope.js +95 -0
- package/dist/server/errors-envelope.js.map +1 -0
- package/dist/session-transcript-LGHSNVY5.cjs +62 -0
- package/dist/session-transcript-LGHSNVY5.cjs.map +1 -0
- package/dist/session-transcript-VTBTCGQX.js +5 -0
- package/dist/session-transcript-VTBTCGQX.js.map +1 -0
- package/dist/skills.cjs +25 -0
- package/dist/skills.cjs.map +1 -0
- package/dist/skills.d.cts +19 -0
- package/dist/skills.d.ts +19 -0
- package/dist/skills.js +8 -0
- package/dist/skills.js.map +1 -0
- package/dist/stream-object-HBFMIZLD.js +7 -0
- package/dist/stream-object-HBFMIZLD.js.map +1 -0
- package/dist/stream-object-QSKHISDJ.cjs +20 -0
- package/dist/stream-object-QSKHISDJ.cjs.map +1 -0
- package/dist/stream-object.d.ts +73 -0
- package/dist/stream-to-completion-QV5HCL3J.js +30 -0
- package/dist/stream-to-completion-QV5HCL3J.js.map +1 -0
- package/dist/stream-to-completion-SRISU5AB.cjs +32 -0
- package/dist/stream-to-completion-SRISU5AB.cjs.map +1 -0
- package/dist/subagents-loader-DOBTTICM.js +7 -0
- package/dist/subagents-loader-DOBTTICM.js.map +1 -0
- package/dist/subagents-loader-GEHYCMEX.cjs +16 -0
- package/dist/subagents-loader-GEHYCMEX.cjs.map +1 -0
- package/dist/subagents-loader.cjs +35 -0
- package/dist/subagents-loader.cjs.map +1 -0
- package/dist/subagents-loader.d.cts +90 -0
- package/dist/subagents-loader.d.ts +90 -0
- package/dist/subagents-loader.js +32 -0
- package/dist/subagents-loader.js.map +1 -0
- package/dist/subagents.cjs +18 -0
- package/dist/subagents.cjs.map +1 -0
- package/dist/subagents.d.cts +14 -0
- package/dist/subagents.d.ts +14 -0
- package/dist/subagents.js +15 -0
- package/dist/subagents.js.map +1 -0
- package/dist/subscription/define-subscription.d.cts +71 -0
- package/dist/subscription/define-subscription.d.ts +71 -0
- package/dist/subscription/index.cjs +408 -0
- package/dist/subscription/index.cjs.map +1 -0
- package/dist/subscription/index.d.cts +20 -0
- package/dist/subscription/index.d.ts +20 -0
- package/dist/subscription/index.js +400 -0
- package/dist/subscription/index.js.map +1 -0
- package/dist/subscription/internal/backpressure.d.cts +24 -0
- package/dist/subscription/internal/backpressure.d.ts +24 -0
- package/dist/subscription/internal/server-integration.d.cts +22 -0
- package/dist/subscription/internal/server-integration.d.ts +22 -0
- package/dist/subscription/internal/sse-encoder.d.cts +13 -0
- package/dist/subscription/internal/sse-encoder.d.ts +13 -0
- package/dist/subscription/internal/sse-parser.d.cts +15 -0
- package/dist/subscription/internal/sse-parser.d.ts +15 -0
- package/dist/subscription/internal/subscription-runtime.d.cts +21 -0
- package/dist/subscription/internal/subscription-runtime.d.ts +21 -0
- package/dist/subscription/internal/types.d.cts +11 -0
- package/dist/subscription/internal/types.d.ts +11 -0
- package/dist/subscription/internal/ws-adapter-node.d.cts +10 -0
- package/dist/subscription/internal/ws-adapter-node.d.ts +10 -0
- package/dist/subscription/theokit-subscribe.d.cts +54 -0
- package/dist/subscription/theokit-subscribe.d.ts +54 -0
- package/dist/subscription/types.d.cts +158 -0
- package/dist/subscription/types.d.ts +158 -0
- package/dist/task-errors.d.ts +58 -0
- package/dist/task-store.cjs +23 -0
- package/dist/task-store.cjs.map +1 -0
- package/dist/task-store.d.cts +10 -0
- package/dist/task-store.d.ts +10 -0
- package/dist/task-store.js +6 -0
- package/dist/task-store.js.map +1 -0
- package/dist/tool-error.d.ts +30 -0
- package/dist/types/agent-prims.d.ts +137 -0
- package/dist/types/agent.d.ts +947 -0
- package/dist/types/batch.d.ts +121 -0
- package/dist/types/budget-tracker.d.ts +80 -0
- package/dist/types/budget.d.ts +97 -0
- package/dist/types/content-blocks.d.ts +50 -0
- package/dist/types/context.d.ts +96 -0
- package/dist/types/conversation.d.ts +127 -0
- package/dist/types/cron.d.ts +172 -0
- package/dist/types/env-policy.d.ts +21 -0
- package/dist/types/eval.d.ts +255 -0
- package/dist/types/fork.d.ts +52 -0
- package/dist/types/goal-events.d.ts +144 -0
- package/dist/types/index.d.ts +19 -0
- package/dist/types/mcp.d.ts +90 -0
- package/dist/types/memory-adapter.d.ts +189 -0
- package/dist/types/memory-provider.d.ts +206 -0
- package/dist/types/messages-base.d.ts +24 -0
- package/dist/types/messages.d.ts +161 -0
- package/dist/types/plugin.d.ts +308 -0
- package/dist/types/processors.d.ts +87 -0
- package/dist/types/provider-profile.d.ts +116 -0
- package/dist/types/providers.d.ts +116 -0
- package/dist/types/run-events.d.ts +197 -0
- package/dist/types/run.d.ts +671 -0
- package/dist/types/sdk-agent.d.ts +342 -0
- package/dist/types/session-message.d.ts +62 -0
- package/dist/types/session-record.d.ts +103 -0
- package/dist/types/session-store.d.ts +104 -0
- package/dist/types/task.d.ts +146 -0
- package/dist/types/theokit.d.ts +73 -0
- package/dist/types/trajectory.d.ts +52 -0
- package/dist/types/updates.d.ts +184 -0
- package/dist/types/usage.d.ts +64 -0
- package/dist/types/workflow.d.ts +426 -0
- package/dist/workflow-as-tool.d.ts +66 -0
- package/dist/workflow-errors.d.ts +164 -0
- package/dist/workflow.cjs +100 -0
- package/dist/workflow.cjs.map +1 -0
- package/dist/workflow.d.cts +911 -0
- package/dist/workflow.d.ts +911 -0
- package/dist/workflow.js +11 -0
- package/dist/workflow.js.map +1 -0
- package/docs/adr/README.md +2604 -0
- package/docs/error-codes.md +253 -0
- package/docs/harness-capability-map.md +1435 -0
- package/docs/memory-decisions.md +265 -0
- package/package.json +455 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,4166 @@
|
|
|
1
|
+
import { T as TheokitAgentError, E as ErrorMetadata } from './errors-base-B5g01neU.cjs';
|
|
2
|
+
export { a as ErrorCode } from './errors-base-B5g01neU.cjs';
|
|
3
|
+
import { F as RunEvent, j as CostBreakdown, at as TokenUsage, R as RunResult, M as ModelSelection, C as CustomTool, a as McpServerConfig, T as ToolResultContentBlock, b as Run, P as Processor, c as PermissionMode, d as RunEventSink$1, S as SDKMessage } from './run-CTAdRU3U.cjs';
|
|
4
|
+
export { A as AgentConversationTurn, e as AssistantMessage, f as CompletionCheck, g as CompletionCheckResult, h as ConversationStep, i as ConversationTurn, j as CostBreakdown, k as CostSource, l as CostStatus, D as DoomLoopThresholds, G as GenerateOptions, m as GenerateRunResult, I as ImageBlock, n as InputProcessorContext, o as InteractionUpdate, p as McpAuthConfig, q as McpHttpServerConfig, r as McpOAuthConfig, s as McpStdioServerConfig, t as MessageOrigin, u as ModelParameterValue, O as OutputProcessorContext, v as PartialToolCallUpdate, w as ProcessorControls, x as ProcessorTripwire, y as ProcessorViolation, z as RunCompactBoundaryEvent, B as RunCompletionCheckEvent, E as RunErrorDetail, F as RunEvent, H as RunGitInfo, J as RunMemoryDegradedEvent, K as RunOperation, L as RunPermissionDeniedEvent, N as RunRateLimitEvent, Q as RunStatus, U as RunTaskCompletedEvent, V as RunTaskStartedEvent, W as RunTaskUpdatedEvent, X as RunTimelineEvent, Y as RunToCompletionOptions, Z as RunToCompletionResult, _ as RunToolProgressEvent, $ as RunTripwireEvent, a0 as SDKAssistantMessage, a1 as SDKImage, a2 as SDKImageDimension, a3 as SDKObjectDelta, a4 as SDKRequestMessage, a5 as SDKStatusMessage, a6 as SDKSystemMessage, a7 as SDKTaskMessage, a8 as SDKThinkingMessage, a9 as SDKToolUseMessage, aa as SDKUserMessage, ab as SDKUserMessageEvent, ac as SendOptions, ad as ShellCommand, ae as ShellConversationTurn, af as ShellOutput, ag as ShellOutputDeltaUpdate, ah as StepCompletedUpdate, ai as StepStartedUpdate, aj as StreamToCompletionResult, ak as SummaryCompletedUpdate, al as SummaryStartedUpdate, am as SummaryUpdate, an as TextBlock, ao as TextDeltaUpdate, ap as ThinkingCompletedUpdate, aq as ThinkingDeltaUpdate, ar as ThinkingMessage, as as TokenDeltaUpdate, at as TokenUsage, au as ToolCall, av as ToolCallCompletedUpdate, aw as ToolCallStartedUpdate, ax as ToolContextMessage, ay as ToolResult, az as ToolResultGuardOptions, aA as ToolUseBlock, aB as TurnEndedUpdate, aC as UserMessage, aD as UserMessageAppendedUpdate } from './run-CTAdRU3U.cjs';
|
|
5
|
+
import { A as AgentOptions, L as LocalOptions, S as SystemPromptResolver, C as CloudOptions, M as MemorySettings, a as AgentDefinition, b as SkillsSettings, c as ListAgentsOptions, d as ListResult, e as SDKAgentInfo, G as GetAgentOptions, f as ListRunsOptions, g as GetRunOptions, h as AgentOperationOptions, i as AgentDescription, P as Plugin$1, j as ProviderProfile, I as InlineSkill, B as BudgetTracker, k as MemoryProvider, l as PreToolCallDecision } from './agent-C3KO5LKm.cjs';
|
|
6
|
+
export { m as ActiveMemoryPassArgs, n as ActiveMemoryPassResult, o as AgentSubagentDescription, p as AgentToolDescription, q as BudgetCheck, r as BudgetTotal, s as BudgetUsageEvent, t as BuiltinToolName, u as CloudEnv, v as CloudRepo, w as CompatSource, x as CompatSourceAdapter, y as CompatSurface, z as CreateSkillSpec, H as HookName, D as MemoryProviderAgentRef, E as MemoryProviderFactory, F as MemoryProviderHandle, J as MemoryProviderInitOptions, K as PluginContext, N as PluginHookDisposer, O as PostAssistantReplyContext, Q as PostToolCallContext, R as PreToolCallContext, T as PreUserSendContext, U as PreUserSendResult, V as ProviderTransform, W as ProviderTransformContext, X as RecordSessionSummaryArgs, Y as SessionLifecycleContext, Z as SessionRecord, _ as SessionStore, $ as SettingSource, a0 as Skill, a1 as SkillsResolver, a2 as SkillsResolverContext, a3 as SystemPromptContext, a4 as SystemPromptMemoryFact, a5 as TelemetrySettings, a6 as ToolCallSummary, a7 as ToolResultTransformContext, a8 as TransformContext } from './agent-C3KO5LKm.cjs';
|
|
7
|
+
import * as zod from 'zod';
|
|
8
|
+
import { ZodType, z } from 'zod';
|
|
9
|
+
import { S as StructuredOutputError, B as BudgetOptions, a as BudgetHandle, b as BudgetSnapshot } from './errors-DrDEgyz1.cjs';
|
|
10
|
+
export { A as AgentDisposedError, c as AgentRunError, d as AgentRunErrorCode, e as AuthenticationError, f as BudgetExceedEvent, g as BudgetExceededError, h as BudgetLimit, i as BudgetMode, j as BudgetScope, k as BudgetThresholdEvent, l as BudgetWindow, C as ConfigurationError, I as IntegrationNotConnectedError, m as InvalidTaskIdError, M as MemoryAdapterError, n as MemoryAdapterErrorCode, N as NetworkError, R as RateLimitError, T as TaskNotFoundError, U as UnknownAgentError, o as UnsupportedBudgetOperationError, p as UnsupportedRunOperationError, q as UnsupportedTaskOperationError, r as isTransientError } from './errors-DrDEgyz1.cjs';
|
|
11
|
+
import { P as ProviderRoutingSettings, S as SDKAgent, C as ContextSettings, a as PluginsSettings, J as JudgeResult, G as GoalOptions, b as GoalEvent, c as GoalResult, M as MemoryId, d as SDKProvider } from './sdk-agent-BOiKqOgL.cjs';
|
|
12
|
+
export { A as AgentMemory, e as AgentOperation, f as ContextBudget, g as ContextManagerKind, h as ContextSnapshot, i as ContextSource, j as ContextSourceStatus, I as InvalidateCacheOptions, k as MemoryAdapter, l as MemoryAdapterCapabilities, m as MemoryContext, n as MemoryFact, o as MemoryRevision, p as MemoryToolSchema, q as MemoryTurnMessage, r as PersonalityPreset, s as ProviderCapability, t as ProviderRoute, R as ResolvedProviderRoute, u as RunUntilIterator, v as SDKAgentPlugins, w as SDKAgentSkillDetail, x as SDKAgentSkills, y as SDKArtifact, z as SDKContextManager, B as SDKPluginMetadata, D as SDKProvidersManager, E as SystemPromptSkillRef, V as Verdict } from './sdk-agent-BOiKqOgL.cjs';
|
|
13
|
+
export { C as Cron, a as CronCreateOptions, b as CronGetOptions, c as CronJob, d as CronJobStatus, e as CronListOptions, f as CronOperationOptions, g as CronRunOptions, h as CronRuntime, i as CronSchedulerStatus, j as CronStartOptions } from './cron-C3PhZED0.cjs';
|
|
14
|
+
import { StepResult } from './workflow.cjs';
|
|
15
|
+
export { Workflow, agentStep, fn } from './workflow.cjs';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Public compaction / context-management helpers (M2-1, extended V3-3).
|
|
19
|
+
*
|
|
20
|
+
* Promotes the SDK's compaction capability to a public surface so consumers can
|
|
21
|
+
* compact a transcript, mark/filter conversation checkpoints, and detect
|
|
22
|
+
* context-overflow — without reaching into `internal/`.
|
|
23
|
+
*
|
|
24
|
+
* Two recent-window modes (V3-3):
|
|
25
|
+
* - `keepRecent` (turn-count, default) — keeps the last N turns verbatim and
|
|
26
|
+
* always preserves leading system PROMPTS; reuses the internal
|
|
27
|
+
* `selectCompressionWindow` (no second algorithm).
|
|
28
|
+
* - `keepTokens` (token-budget) — keeps the trailing turns whose accumulated
|
|
29
|
+
* `estimateTokens` fits the budget (theocode `splitTranscript` semantics). In
|
|
30
|
+
* this mode leading system prompts are NOT special-cased (D6).
|
|
31
|
+
*
|
|
32
|
+
* Summarization is delegated to a caller-supplied callback (which receives the
|
|
33
|
+
* older window + the summary template). With `failSafe`, a thrown summarizer
|
|
34
|
+
* returns the ORIGINAL transcript + a structured warn (compaction is an
|
|
35
|
+
* optimization, never a cause of data loss); without it, the error propagates.
|
|
36
|
+
*
|
|
37
|
+
* Public from the `@theokit/sdk/compaction` sub-path.
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Minimal message shape for compaction/compression input. THE canonical public origin (leaf type —
|
|
42
|
+
* rollup-plugin-dts cannot re-export types from internal modules into entry bundles; M42 lesson).
|
|
43
|
+
*
|
|
44
|
+
* @public
|
|
45
|
+
*/
|
|
46
|
+
interface CompressibleMessage {
|
|
47
|
+
role: "user" | "assistant" | "system";
|
|
48
|
+
content: string;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Tokenizer-free token estimate via the conventional ~4-chars-per-token
|
|
52
|
+
* heuristic: `ceil(text.length / CHARS_PER_TOKEN)`. `""` → 0; any non-empty text → ≥ 1.
|
|
53
|
+
* A cheap PRE-CALL gate for {@link shouldCompact} — NOT exact tokenization
|
|
54
|
+
* (a consumer needing exactness supplies their own tokenizer). Uses UTF-16
|
|
55
|
+
* `.length` (code units), so multibyte text is approximate.
|
|
56
|
+
*
|
|
57
|
+
* `built-in-processors.ts` re-exports this under the same name, so both entry points keep working
|
|
58
|
+
* and there is one implementation behind them.
|
|
59
|
+
*/
|
|
60
|
+
declare function estimateTokens(text: string): number;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* M50 (agent-builder) — session-transcript compaction.
|
|
64
|
+
*
|
|
65
|
+
* The mechanism:
|
|
66
|
+
* - the replacement history = recent USER messages verbatim (newest→oldest under a token budget;
|
|
67
|
+
* prior summaries filtered by marker) + ONE summary message with a textual marker prefix,
|
|
68
|
+
* injected as `role:"user"` (`build_compacted_history`, compact.rs:589-663);
|
|
69
|
+
* - persistence is APPEND-ONLY: a `compact_boundary` record becomes the new DAG root and the
|
|
70
|
+
* replacement messages are chained onto it — resume replays boundary→replacement→suffix
|
|
71
|
+
* (equivalent of `CompactedItem.replacement_history`, rollout is never truncated);
|
|
72
|
+
* - a failing summarizer leaves the transcript UNTOUCHED (typed error; no partial state).
|
|
73
|
+
*
|
|
74
|
+
* The summarizer is dependency-injected: tests pass a deterministic fake; the public
|
|
75
|
+
* `Agent.compact` wires the ADR-D440 compression summarizer (its first real caller).
|
|
76
|
+
*/
|
|
77
|
+
|
|
78
|
+
interface CompactResult {
|
|
79
|
+
preTokens: number;
|
|
80
|
+
postTokens: number;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Owner: `src/` (2 of 5 importers). Derived from the import graph, not declared —
|
|
85
|
+
* `tests/lint/types-name-their-owner.test.ts` re-derives it.
|
|
86
|
+
*
|
|
87
|
+
* Public types for `Agent.batch` (ADRs D134-D140).
|
|
88
|
+
*
|
|
89
|
+
* Run N prompts in parallel with bounded concurrency. Each prompt gets
|
|
90
|
+
* a fresh agent (create → send → wait → dispose). Failures isolated
|
|
91
|
+
* per-prompt; the batch never aborts on a single failure.
|
|
92
|
+
*
|
|
93
|
+
* @public
|
|
94
|
+
*/
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Single prompt in a batch. Plain string is shorthand for `{ prompt }`.
|
|
98
|
+
*
|
|
99
|
+
* @public
|
|
100
|
+
*/
|
|
101
|
+
interface BatchItem {
|
|
102
|
+
/** Prompt text sent to the agent. */
|
|
103
|
+
prompt: string;
|
|
104
|
+
/** Per-prompt system prompt override (wins over `BatchOptions.systemPrompt`). */
|
|
105
|
+
systemPrompt?: string;
|
|
106
|
+
/**
|
|
107
|
+
* Caller-supplied metadata, round-tripped to `BatchResult.metadata`.
|
|
108
|
+
* Passed by reference — do NOT mutate while the batch is in-flight (EC-I).
|
|
109
|
+
*/
|
|
110
|
+
metadata?: Record<string, unknown>;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Options accepted by `Agent.batch`. Extends `AgentOptions` — every
|
|
114
|
+
* prompt gets an agent created with these options (ADR D138 isolation),
|
|
115
|
+
* plus the batch-specific knobs below.
|
|
116
|
+
*
|
|
117
|
+
* @public
|
|
118
|
+
*/
|
|
119
|
+
interface BatchOptions extends AgentOptions {
|
|
120
|
+
/**
|
|
121
|
+
* Maximum parallel agents. Default 4 (ADR D136). Must be a positive
|
|
122
|
+
* integer. Capped to `prompts.length` to avoid spinning idle workers.
|
|
123
|
+
*
|
|
124
|
+
* Bounds the WHOLE per-item lifecycle, including `onResult`: a prompt's
|
|
125
|
+
* concurrency slot is not released until its `onResult` callback (if any)
|
|
126
|
+
* has finished (B-110). A caller doing anything stateful in `onResult` —
|
|
127
|
+
* writing a file, appending to a shared buffer, rate-limiting an API — can
|
|
128
|
+
* rely on at most `concurrency` such callbacks running at once.
|
|
129
|
+
*/
|
|
130
|
+
concurrency?: number;
|
|
131
|
+
/** Optional filter applied post-collection. Return `false` to discard. */
|
|
132
|
+
filter?: (result: BatchResult) => boolean;
|
|
133
|
+
/**
|
|
134
|
+
* Streaming callback fired once per completed prompt (success OR failure).
|
|
135
|
+
* Caller exceptions are caught + logged to stderr without poisoning
|
|
136
|
+
* the batch (EC-5). Bounded by `concurrency` — see its doc.
|
|
137
|
+
*/
|
|
138
|
+
onResult?: (result: BatchResult) => void | Promise<void>;
|
|
139
|
+
/** Progress callback fired after each result. */
|
|
140
|
+
onProgress?: (progress: BatchProgress) => void;
|
|
141
|
+
/**
|
|
142
|
+
* Cancel pending prompts (ADR D140). In-flight prompts continue to
|
|
143
|
+
* completion (Node `AbortSignal` semantics). When `signal.reason` is
|
|
144
|
+
* an Error, it propagates to `BatchResult.error`; otherwise a generic
|
|
145
|
+
* "aborted" error is used.
|
|
146
|
+
*/
|
|
147
|
+
signal?: AbortSignal;
|
|
148
|
+
/**
|
|
149
|
+
* Opt-in Task wrapping (ADRs D363, D374). When set, the batch is
|
|
150
|
+
* registered as a `Task` (kind="batch") in the SDK's observable
|
|
151
|
+
* registry. The parent task transitions `finished` when every
|
|
152
|
+
* prompt is resolved (success OR failure).
|
|
153
|
+
*
|
|
154
|
+
* Use cases: surfacing a long-running batch in the `theokit tasks
|
|
155
|
+
* list` CLI, programmatic `Task.cancel(id)` aborting the batch, or
|
|
156
|
+
* binding a user-facing job dashboard. v1 does NOT yet emit one
|
|
157
|
+
* task PER prompt (single parent only); per-prompt tasks land in
|
|
158
|
+
* v0.2.
|
|
159
|
+
*
|
|
160
|
+
* Auto-generated id uses the `b-` reserved prefix (D368, EC-5).
|
|
161
|
+
*
|
|
162
|
+
* @public
|
|
163
|
+
*/
|
|
164
|
+
task?: true | {
|
|
165
|
+
id?: string;
|
|
166
|
+
meta?: Record<string, unknown>;
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Per-prompt outcome. Discriminated union — check `ok` before reading
|
|
171
|
+
* `result` or `error`.
|
|
172
|
+
*
|
|
173
|
+
* @public
|
|
174
|
+
*/
|
|
175
|
+
type BatchResult = {
|
|
176
|
+
ok: true;
|
|
177
|
+
index: number;
|
|
178
|
+
prompt: string;
|
|
179
|
+
result: RunResult;
|
|
180
|
+
metadata?: Record<string, unknown>;
|
|
181
|
+
durationMs: number;
|
|
182
|
+
} | {
|
|
183
|
+
ok: false;
|
|
184
|
+
index: number;
|
|
185
|
+
prompt: string;
|
|
186
|
+
error: TheokitAgentError;
|
|
187
|
+
metadata?: Record<string, unknown>;
|
|
188
|
+
durationMs: number;
|
|
189
|
+
};
|
|
190
|
+
/**
|
|
191
|
+
* Live progress snapshot delivered to `onProgress`.
|
|
192
|
+
*
|
|
193
|
+
* @public
|
|
194
|
+
*/
|
|
195
|
+
interface BatchProgress {
|
|
196
|
+
total: number;
|
|
197
|
+
completed: number;
|
|
198
|
+
failed: number;
|
|
199
|
+
pending: number;
|
|
200
|
+
inFlight: number;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Options accepted by {@link Agent.streamObject}. Same shape as
|
|
205
|
+
* `Agent.generateObject` with the addition that the result is an
|
|
206
|
+
* `AsyncIterator<StreamObjectEvent<T>>` rather than a single Promise. See ADR D39.
|
|
207
|
+
*
|
|
208
|
+
* @public
|
|
209
|
+
*/
|
|
210
|
+
interface StreamObjectOptions<T extends ZodType> {
|
|
211
|
+
schema: T;
|
|
212
|
+
prompt: string;
|
|
213
|
+
systemPrompt?: string;
|
|
214
|
+
/** SE8 — accepts a bare-string id shorthand or a {@link ModelSelection}. */
|
|
215
|
+
model: string | ModelSelection;
|
|
216
|
+
apiKey?: string;
|
|
217
|
+
local: LocalOptions;
|
|
218
|
+
maxRetries?: number;
|
|
219
|
+
/**
|
|
220
|
+
* Optional provider routing forwarded to the transient agent. Required when
|
|
221
|
+
* `model.id` uses a prefix (e.g. `openai/gpt-4o-mini`) but the credential is
|
|
222
|
+
* for a unified gateway (e.g. OpenRouter). Without this, the SDK infers
|
|
223
|
+
* provider from the prefix and may fail with `provider_unresolved` even
|
|
224
|
+
* when the right env key is set under a different provider name.
|
|
225
|
+
*/
|
|
226
|
+
providers?: ProviderRoutingSettings;
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Recursive partial — `T` where every nested field becomes optional.
|
|
230
|
+
*
|
|
231
|
+
* @public
|
|
232
|
+
*/
|
|
233
|
+
type DeepPartial<T> = T extends (infer U)[] ? Array<DeepPartial<U>> : T extends object ? {
|
|
234
|
+
[K in keyof T]?: DeepPartial<T[K]>;
|
|
235
|
+
} : T;
|
|
236
|
+
/**
|
|
237
|
+
* Event emitted by {@link Agent.streamObject}. Discriminate on `type`.
|
|
238
|
+
*
|
|
239
|
+
* - `partial` events fire zero or more times with monotonically increasing
|
|
240
|
+
* `attempt`, carrying best-effort schema-parsed snapshots of the model's
|
|
241
|
+
* accumulating output.
|
|
242
|
+
* - `complete` fires exactly once at the end, carrying the fully Zod-parsed
|
|
243
|
+
* object alongside usage and finishReason — semantically identical to a
|
|
244
|
+
* successful `Agent.generateObject()` return.
|
|
245
|
+
*
|
|
246
|
+
* @public
|
|
247
|
+
*/
|
|
248
|
+
type StreamObjectEvent<T> = {
|
|
249
|
+
type: "partial";
|
|
250
|
+
partial: DeepPartial<T>;
|
|
251
|
+
attempt: number;
|
|
252
|
+
} | {
|
|
253
|
+
type: "complete";
|
|
254
|
+
object: T;
|
|
255
|
+
raw: unknown;
|
|
256
|
+
usage: {
|
|
257
|
+
inputTokens: number;
|
|
258
|
+
outputTokens: number;
|
|
259
|
+
};
|
|
260
|
+
finishReason: "tool_use" | "error";
|
|
261
|
+
};
|
|
262
|
+
/**
|
|
263
|
+
* Error thrown by {@link Agent.streamObject} when the model refuses to call
|
|
264
|
+
* the synthetic `output` tool or when all retries fail to produce a
|
|
265
|
+
* schema-valid object. Same code taxonomy as `GenerateObjectError`.
|
|
266
|
+
*
|
|
267
|
+
* @public
|
|
268
|
+
*/
|
|
269
|
+
declare class StreamObjectError extends StructuredOutputError {
|
|
270
|
+
readonly name = "StreamObjectError";
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Options accepted by {@link Agent.generateObject}. Returns a typed object
|
|
275
|
+
* matching the supplied Zod schema. See ADR D33.
|
|
276
|
+
*
|
|
277
|
+
* @public
|
|
278
|
+
*/
|
|
279
|
+
interface GenerateObjectOptions<T extends ZodType> {
|
|
280
|
+
/** Zod schema describing the expected object shape. */
|
|
281
|
+
schema: T;
|
|
282
|
+
/** User prompt — the model is asked to fill the schema given this prompt. */
|
|
283
|
+
prompt: string;
|
|
284
|
+
/** Optional system prompt steering the model. */
|
|
285
|
+
systemPrompt?: string;
|
|
286
|
+
/** Model selection. Required (transient agents need a model). SE8 — accepts a
|
|
287
|
+
* bare-string id shorthand (`"openai/gpt-4o-mini"`) or a {@link ModelSelection}. */
|
|
288
|
+
model: string | ModelSelection;
|
|
289
|
+
/**
|
|
290
|
+
* M21 — optional separate model for the STRUCTURING step. When set, `model` first produces a
|
|
291
|
+
* free-text reasoned answer to the prompt (phase 1), then `structuringModel` extracts the
|
|
292
|
+
* schema-matched object by calling the `output` tool over that answer (phase 2). Lets a large
|
|
293
|
+
* model reason while a cheap fast model does the extraction. Absent ⇒ today's single-model flow.
|
|
294
|
+
*/
|
|
295
|
+
structuringModel?: string | ModelSelection;
|
|
296
|
+
/** API key. Falls back to env (THEOKIT_API_KEY etc). */
|
|
297
|
+
apiKey?: string;
|
|
298
|
+
/** Local runtime config (cwd, sandbox). Required to keep the transient agent local-only. */
|
|
299
|
+
local: LocalOptions;
|
|
300
|
+
/**
|
|
301
|
+
* Retry budget on parse failures. Default 1 (initial attempt + 1 retry).
|
|
302
|
+
* The transient agent is REUSED across retries so the registry sees a
|
|
303
|
+
* single entry (EC-3).
|
|
304
|
+
*/
|
|
305
|
+
maxRetries?: number;
|
|
306
|
+
/**
|
|
307
|
+
* Optional provider routing forwarded to the transient agent. Required when
|
|
308
|
+
* `model.id` uses a prefix (e.g. `openai/gpt-4o-mini`) but the credential is
|
|
309
|
+
* for a unified gateway (e.g. OpenRouter). Without this, the SDK infers
|
|
310
|
+
* provider from the prefix and may fail with `provider_unresolved` even
|
|
311
|
+
* when the right env key is set under a different provider name.
|
|
312
|
+
*/
|
|
313
|
+
providers?: ProviderRoutingSettings;
|
|
314
|
+
/**
|
|
315
|
+
* What to do when the model's output fails schema validation after all
|
|
316
|
+
* retries are exhausted (M14):
|
|
317
|
+
* - `'throw'` (default) — throw {@link GenerateObjectError} `parse_failed`.
|
|
318
|
+
* - `'return-raw'` — resolve with the raw, UNVALIDATED input the model sent
|
|
319
|
+
* (`object` may not match the schema; inspect `raw` too).
|
|
320
|
+
* - `'return-partial'` — for object schemas, resolve with only the fields that
|
|
321
|
+
* individually validate (best-effort salvage); non-object schemas fall back
|
|
322
|
+
* to raw.
|
|
323
|
+
*/
|
|
324
|
+
errorStrategy?: "throw" | "return-partial" | "return-raw";
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Successful return from {@link Agent.generateObject}.
|
|
328
|
+
*
|
|
329
|
+
* @public
|
|
330
|
+
*/
|
|
331
|
+
interface GenerateObjectResult<T> {
|
|
332
|
+
/** Typed object parsed via the Zod schema. */
|
|
333
|
+
object: T;
|
|
334
|
+
/** Raw input the model passed to the synthetic tool, before Zod parse. */
|
|
335
|
+
raw: unknown;
|
|
336
|
+
/** Token usage of the LLM call(s) that produced the result. */
|
|
337
|
+
usage: {
|
|
338
|
+
inputTokens: number;
|
|
339
|
+
outputTokens: number;
|
|
340
|
+
};
|
|
341
|
+
/** Stop reason of the underlying agent run. */
|
|
342
|
+
finishReason: "tool_use" | "error";
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Typed error thrown by {@link Agent.generateObject} when the model refuses
|
|
346
|
+
* to call the synthetic `output` tool or when retries are exhausted.
|
|
347
|
+
*
|
|
348
|
+
* @public
|
|
349
|
+
*/
|
|
350
|
+
declare class GenerateObjectError extends StructuredOutputError {
|
|
351
|
+
readonly name = "GenerateObjectError";
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* Terminal-method callbacks injected by `Agent.builder()` so that
|
|
356
|
+
* `agent-builder.ts` does NOT need a static import of `Agent` — keeps the
|
|
357
|
+
* dependency graph acyclic (G6).
|
|
358
|
+
*
|
|
359
|
+
* Exported, and NOT carrying the internal-visibility JSDoc tag, because
|
|
360
|
+
* `AgentBuilder` is `@public` and so is its constructor: `new AgentBuilder(deps)`
|
|
361
|
+
* is callable by anyone, which makes this parameter's type part of the published
|
|
362
|
+
* contract whether or not we intended it. Hiding it did not make it private — it
|
|
363
|
+
* made the emitted `.d.ts` say `constructor(deps?: AgentBuilderDeps)` with no such
|
|
364
|
+
* type in the file (#335). Prefer `Agent.builder()`, which injects these for you;
|
|
365
|
+
* this is the seam it uses, not an argument callers are expected to construct.
|
|
366
|
+
*
|
|
367
|
+
* @public
|
|
368
|
+
*/
|
|
369
|
+
interface AgentBuilderDeps {
|
|
370
|
+
create: (options: AgentOptions) => Promise<SDKAgent>;
|
|
371
|
+
getOrCreate: (agentId: string, options: AgentOptions) => Promise<SDKAgent>;
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Fluent builder for {@link AgentOptions}. Chainable setters mutate internal
|
|
375
|
+
* state and return `this`. Three terminals:
|
|
376
|
+
*
|
|
377
|
+
* - `.build()` — synchronous snapshot (shallow clone) of accumulated options.
|
|
378
|
+
* - `.create()` — calls the injected `create` (Agent.create).
|
|
379
|
+
* - `.getOrCreate(agentId)` — calls the injected `getOrCreate` (Agent.getOrCreate).
|
|
380
|
+
*
|
|
381
|
+
* Validation runs inside the terminals via `validateAgentOptions`. See ADR D25.
|
|
382
|
+
*
|
|
383
|
+
* @public
|
|
384
|
+
*/
|
|
385
|
+
declare class AgentBuilder {
|
|
386
|
+
private opts;
|
|
387
|
+
private readonly deps;
|
|
388
|
+
constructor(deps?: AgentBuilderDeps);
|
|
389
|
+
/** SE8 — accepts a bare-string id shorthand (`"openai/gpt-4o-mini"`) or a {@link ModelSelection}. */
|
|
390
|
+
model(m: string | ModelSelection): this;
|
|
391
|
+
apiKey(k: string): this;
|
|
392
|
+
name(n: string): this;
|
|
393
|
+
systemPrompt(p: string | SystemPromptResolver): this;
|
|
394
|
+
local(l: LocalOptions): this;
|
|
395
|
+
cloud(c: CloudOptions): this;
|
|
396
|
+
memory(m: MemorySettings): this;
|
|
397
|
+
tools(t: CustomTool[]): this;
|
|
398
|
+
mcpServers(s: Record<string, McpServerConfig>): this;
|
|
399
|
+
agents(a: Record<string, AgentDefinition>): this;
|
|
400
|
+
context(c: ContextSettings): this;
|
|
401
|
+
providers(p: ProviderRoutingSettings): this;
|
|
402
|
+
plugins(p: PluginsSettings): this;
|
|
403
|
+
skills(s: SkillsSettings): this;
|
|
404
|
+
agentId(id: string): this;
|
|
405
|
+
/**
|
|
406
|
+
* Synchronous snapshot of the accumulated options. Returns a SHALLOW CLONE
|
|
407
|
+
* so external mutation of the result doesn't pollute the builder state (EC-2).
|
|
408
|
+
*/
|
|
409
|
+
build(): AgentOptions;
|
|
410
|
+
/**
|
|
411
|
+
* Validate + create a fresh agent. Delegates to `Agent.create` via the
|
|
412
|
+
* injected `deps.create`. Throws if the builder was instantiated without
|
|
413
|
+
* deps (i.e., direct `new AgentBuilder()` instead of `Agent.builder()`).
|
|
414
|
+
*/
|
|
415
|
+
create(): Promise<SDKAgent>;
|
|
416
|
+
/**
|
|
417
|
+
* Resume an existing agent or create one if the ID is unknown. Delegates to
|
|
418
|
+
* `Agent.getOrCreate` via the injected `deps.getOrCreate` (ADR D22).
|
|
419
|
+
*/
|
|
420
|
+
getOrCreate(agentId: string): Promise<SDKAgent>;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
/**
|
|
424
|
+
* Live-agent cache for production deploys (Production-Readiness #2, ADRs D307-D310).
|
|
425
|
+
*
|
|
426
|
+
* Caches `SDKAgent` instances by id with LRU eviction (when `size > maxAgents`)
|
|
427
|
+
* and an idle-timeout sweep (configurable interval, default 60s). Solves the
|
|
428
|
+
* "OOM at some point" failure mode of long-running Node servers that keep
|
|
429
|
+
* spawning fresh agents per conversation.
|
|
430
|
+
*
|
|
431
|
+
* **Distinct from `agent-registry.ts`** (the metadata registry that persists
|
|
432
|
+
* `RegisteredAgent` to `registry.json` per cwd). That module is the "address
|
|
433
|
+
* book"; this module is the "live cache". Conflating them violates SRP — see
|
|
434
|
+
* ADR D307.
|
|
435
|
+
*
|
|
436
|
+
* Defaults (ADR D308): `maxAgents: 100`, `idleTimeoutMs: 30 min`, sweep `60s`.
|
|
437
|
+
* Calibrated for indie/small-team Node deploys; high-traffic SaaS should
|
|
438
|
+
* `configure({ maxAgents: 1000 })`.
|
|
439
|
+
*
|
|
440
|
+
* @public (singleton exposed via `Agent.registry`)
|
|
441
|
+
*/
|
|
442
|
+
|
|
443
|
+
type EvictReason = "lru" | "idle" | "explicit";
|
|
444
|
+
/**
|
|
445
|
+
* Knobs for {@link LiveAgentRegistry.configure}.
|
|
446
|
+
*
|
|
447
|
+
* The three numeric fields are a partial reconfigure — one left out keeps its current value.
|
|
448
|
+
* `onEvict` is NOT: it is assigned on every call, so `configure({ maxAgents: 200 })` clears a
|
|
449
|
+
* listener registered earlier. Re-pass the listener whenever you reconfigure.
|
|
450
|
+
*
|
|
451
|
+
* Two values are load-bearing zeroes. `maxAgents: 0` disables caching entirely, so every lookup
|
|
452
|
+
* misses and every agent is rebuilt; `idleTimeoutMs: 0` keeps the cache but leaves LRU as the only
|
|
453
|
+
* eviction, because the sweep is not started at all below that threshold. Negative numbers are
|
|
454
|
+
* clamped rather than rejected — up to 1000ms for `sweepIntervalMs`, up to 0 for the other two.
|
|
455
|
+
*
|
|
456
|
+
* @public
|
|
457
|
+
*/
|
|
458
|
+
interface AgentRegistryOptions {
|
|
459
|
+
/**
|
|
460
|
+
* Maximum number of agents kept alive simultaneously. LRU eviction when
|
|
461
|
+
* exceeded. Default: 100.
|
|
462
|
+
*
|
|
463
|
+
* Setting `0` disables the cache entirely — every `Agent.getOrCreate`
|
|
464
|
+
* re-initializes (high cost, but predictable memory).
|
|
465
|
+
*/
|
|
466
|
+
maxAgents?: number;
|
|
467
|
+
/**
|
|
468
|
+
* Idle timeout in milliseconds. Agents not used for this duration are
|
|
469
|
+
* evicted on the next sweep tick. Default: 1_800_000 (30 minutes).
|
|
470
|
+
* Set `0` to disable idle eviction.
|
|
471
|
+
*/
|
|
472
|
+
idleTimeoutMs?: number;
|
|
473
|
+
/**
|
|
474
|
+
* Sweep interval in milliseconds. Default: 60_000 (60s).
|
|
475
|
+
* Lower = more responsive eviction but more CPU. Higher = staler entries.
|
|
476
|
+
*/
|
|
477
|
+
sweepIntervalMs?: number;
|
|
478
|
+
/**
|
|
479
|
+
* Called whenever an agent is evicted. Listener errors are swallowed
|
|
480
|
+
* with a one-shot stderr warn (do not crash the eviction loop).
|
|
481
|
+
*/
|
|
482
|
+
onEvict?: (id: string, reason: EvictReason) => void;
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* An LRU-plus-idle cache of live `SDKAgent` instances, reached through `Agent.registry`.
|
|
486
|
+
*
|
|
487
|
+
* It exists for long-running servers that would otherwise build a fresh agent per conversation and
|
|
488
|
+
* never release one. Do not confuse it with the metadata registry in `agent-registry.ts`, which
|
|
489
|
+
* persists `RegisteredAgent` records to disk: that one is the address book, this one is the live
|
|
490
|
+
* cache, and they share nothing.
|
|
491
|
+
*
|
|
492
|
+
* The lifecycle rule that matters to callers: eviction — by LRU, by idle timeout, or by an explicit
|
|
493
|
+
* `evict` — calls `dispose()` on the agent. A reference you held onto before eviction is a disposed
|
|
494
|
+
* agent, not a detached one. `get` counts as a use and refreshes the entry's timestamp, so polling
|
|
495
|
+
* for an agent keeps it alive indefinitely.
|
|
496
|
+
*
|
|
497
|
+
* Idle eviction depends on a background sweep that only `configure` starts. A registry nobody
|
|
498
|
+
* configured caches with the documented defaults but evicts by LRU alone, so entries can sit past
|
|
499
|
+
* `idleTimeoutMs` indefinitely; call `configure` — even with no changes — to arm the sweep.
|
|
500
|
+
*
|
|
501
|
+
* Failures on the eviction path are swallowed and reported to the diagnostics channel — a throwing
|
|
502
|
+
* `dispose()` or a throwing `onEvict` listener must not stop the sweep. Configuration is
|
|
503
|
+
* process-wide and last-call-wins.
|
|
504
|
+
*
|
|
505
|
+
* @public
|
|
506
|
+
*/
|
|
507
|
+
declare class LiveAgentRegistry {
|
|
508
|
+
#private;
|
|
509
|
+
/**
|
|
510
|
+
* Reconfigure registry behavior. Process-wide singleton (D310) — last
|
|
511
|
+
* configure call wins for all subsequent operations.
|
|
512
|
+
*/
|
|
513
|
+
configure(opts: AgentRegistryOptions): void;
|
|
514
|
+
/**
|
|
515
|
+
* Lookup a cached agent. `get` is a use — refreshes `lastUsedAt` so the
|
|
516
|
+
* entry survives LRU eviction.
|
|
517
|
+
*/
|
|
518
|
+
get(id: string): SDKAgent | undefined;
|
|
519
|
+
/**
|
|
520
|
+
* Insert or overwrite an agent in the cache. Triggers fire-and-forget LRU
|
|
521
|
+
* eviction when `size > maxAgents`.
|
|
522
|
+
*
|
|
523
|
+
* EC-4: when `id` already maps to a DIFFERENT agent instance, dispose the
|
|
524
|
+
* old one before overwriting (race protection against two `getOrCreate`
|
|
525
|
+
* calls creating two agents but only the second being cached — the first
|
|
526
|
+
* would leak file handles + lifecycle controllers).
|
|
527
|
+
*/
|
|
528
|
+
set(id: string, agent: SDKAgent): void;
|
|
529
|
+
/**
|
|
530
|
+
* Explicitly evict an agent by id. Returns `true` when the entry was
|
|
531
|
+
* present (false = already gone). Calls `agent.dispose()` + `onEvict`
|
|
532
|
+
* with reason `"explicit"`.
|
|
533
|
+
*/
|
|
534
|
+
evict(id: string): Promise<boolean>;
|
|
535
|
+
/**
|
|
536
|
+
* Evict every cached agent. Used by graceful shutdown (`process.on('SIGTERM')`)
|
|
537
|
+
* or end-of-test cleanup.
|
|
538
|
+
*/
|
|
539
|
+
evictAll(): Promise<void>;
|
|
540
|
+
/** Number of currently cached agents. */
|
|
541
|
+
size(): number;
|
|
542
|
+
/** Ids of cached agents, newest first (by lastUsedAt). */
|
|
543
|
+
ids(): readonly string[];
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
/**
|
|
547
|
+
* Owner: `src/` (1 of 2 importers). Derived from the import graph, not
|
|
548
|
+
* declared — `tests/lint/types-name-their-owner.test.ts` re-derives it.
|
|
549
|
+
*
|
|
550
|
+
* The shape of a persisted session turn, as a HOST reads it.
|
|
551
|
+
*
|
|
552
|
+
* Lives in `types/` because it is public contract — `Agent.transcript()` returns it (theokit#146).
|
|
553
|
+
* `internal/session/session-types.ts` re-exports it so the runtime and the store keep importing
|
|
554
|
+
* from the leaf they always did.
|
|
555
|
+
*
|
|
556
|
+
* @public
|
|
557
|
+
*/
|
|
558
|
+
|
|
559
|
+
/**
|
|
560
|
+
* One turn of a session.
|
|
561
|
+
*
|
|
562
|
+
* Two projections of the same turn, and they answer different questions:
|
|
563
|
+
*
|
|
564
|
+
* - `text` is the flat rendering the model replay uses. A tool call folds to `[tool call] NAME` and
|
|
565
|
+
* a result to `[tool result] <body>`.
|
|
566
|
+
* - `parts` is the same turn unflattened, for a host that draws tool CARDS: the call id, the tool
|
|
567
|
+
* name, the arguments, and the `toolUseId` that ties a result back to its call — none of which
|
|
568
|
+
* survive the flat form.
|
|
569
|
+
*
|
|
570
|
+
* `parts` was added in theokit#146 and is additive: `text` is byte-identical to what it always was,
|
|
571
|
+
* so every existing reader is untouched.
|
|
572
|
+
*
|
|
573
|
+
* @public
|
|
574
|
+
*/
|
|
575
|
+
interface SessionMessage {
|
|
576
|
+
role: "user" | "assistant";
|
|
577
|
+
text: string;
|
|
578
|
+
/**
|
|
579
|
+
* The structured view. Optional because a `SessionMessage` can also be built in memory during a
|
|
580
|
+
* live turn, where only the text projection exists. Absent means "this projection carries no
|
|
581
|
+
* structure", never "this turn had none".
|
|
582
|
+
*/
|
|
583
|
+
parts?: readonly SessionMessagePart[];
|
|
584
|
+
}
|
|
585
|
+
/**
|
|
586
|
+
* One structured element of a {@link SessionMessage}.
|
|
587
|
+
*
|
|
588
|
+
* Deliberately a session-DISPLAY shape rather than a re-export of the internal LLM part union: the
|
|
589
|
+
* two answer different questions (what to send a provider vs. what to draw), and coupling them
|
|
590
|
+
* would make every provider-wire change a change to what hosts render.
|
|
591
|
+
*
|
|
592
|
+
* @public
|
|
593
|
+
*/
|
|
594
|
+
type SessionMessagePart = {
|
|
595
|
+
readonly type: "text";
|
|
596
|
+
readonly text: string;
|
|
597
|
+
} | {
|
|
598
|
+
readonly type: "tool_use";
|
|
599
|
+
readonly id: string;
|
|
600
|
+
readonly name: string;
|
|
601
|
+
readonly input: Record<string, unknown>;
|
|
602
|
+
} | {
|
|
603
|
+
readonly type: "tool_result";
|
|
604
|
+
readonly toolUseId: string;
|
|
605
|
+
readonly content: string | ReadonlyArray<ToolResultContentBlock>;
|
|
606
|
+
readonly isError?: boolean;
|
|
607
|
+
};
|
|
608
|
+
|
|
609
|
+
/**
|
|
610
|
+
* Result of a one-shot {@link Agent.prompt} call.
|
|
611
|
+
*
|
|
612
|
+
* @public
|
|
613
|
+
*/
|
|
614
|
+
type AgentPromptResult = RunResult;
|
|
615
|
+
/**
|
|
616
|
+
* Static façade for creating and managing Theo agents.
|
|
617
|
+
*
|
|
618
|
+
* @public
|
|
619
|
+
*/
|
|
620
|
+
declare class Agent {
|
|
621
|
+
private constructor();
|
|
622
|
+
/**
|
|
623
|
+
* Live-agent cache for production deploys (Production-Readiness #2, ADRs D307-D310).
|
|
624
|
+
*
|
|
625
|
+
* Caches `SDKAgent` instances by id with LRU eviction (when `size > maxAgents`)
|
|
626
|
+
* and an idle-timeout sweep. Solves the OOM failure mode for long-running
|
|
627
|
+
* Node servers spawning fresh agents per conversation.
|
|
628
|
+
*
|
|
629
|
+
* Defaults: `maxAgents: 100`, `idleTimeoutMs: 30 min`, sweep `60s`.
|
|
630
|
+
* Configure for high-traffic SaaS:
|
|
631
|
+
*
|
|
632
|
+
* ```ts
|
|
633
|
+
* Agent.registry.configure({ maxAgents: 1000, idleTimeoutMs: 15 * 60_000 });
|
|
634
|
+
* process.on("SIGTERM", () => Agent.registry.evictAll());
|
|
635
|
+
* ```
|
|
636
|
+
*
|
|
637
|
+
* Cache hits are automatic in `Agent.getOrCreate` (T2.6). Disable the cache
|
|
638
|
+
* entirely via `configure({ maxAgents: 0 })` — every getOrCreate then
|
|
639
|
+
* re-initializes.
|
|
640
|
+
*
|
|
641
|
+
* @public
|
|
642
|
+
*/
|
|
643
|
+
static readonly registry: LiveAgentRegistry;
|
|
644
|
+
/**
|
|
645
|
+
* Create a new agent. Pass either `local` or `cloud` to pick a runtime.
|
|
646
|
+
*
|
|
647
|
+
* @public
|
|
648
|
+
*/
|
|
649
|
+
static create(options: AgentOptions): Promise<SDKAgent>;
|
|
650
|
+
/**
|
|
651
|
+
* One-shot prompt: create an agent, send a single message, wait, **dispose**.
|
|
652
|
+
*
|
|
653
|
+
* `Agent.prompt` is STATIC and owns the agent's whole lifecycle. To send to an
|
|
654
|
+
* agent you already hold, use the instance method — `agent.send(message)` —
|
|
655
|
+
* which keeps the conversation and does not dispose anything:
|
|
656
|
+
*
|
|
657
|
+
* ```ts
|
|
658
|
+
* const agent = await Agent.create({ ... });
|
|
659
|
+
* const run = await agent.send("first"); // NOT agent.prompt(...)
|
|
660
|
+
* const run2 = await agent.send("follow-up"); // full context retained
|
|
661
|
+
* ```
|
|
662
|
+
*
|
|
663
|
+
* There is no `agent.prompt()` (#302). The natural sentence for the second
|
|
664
|
+
* operation is "prompt the agent", so it is the method people reach for; the
|
|
665
|
+
* two differ in whether the agent survives the call, which is why they do not
|
|
666
|
+
* share a name.
|
|
667
|
+
*
|
|
668
|
+
* When `options.throwOnError === true`, rejects with `AgentRunError` if
|
|
669
|
+
* the run terminates with `status: 'error'` (instead of resolving with the
|
|
670
|
+
* error wrapped in the RunResult). Cancelled runs still resolve normally.
|
|
671
|
+
*
|
|
672
|
+
* @public
|
|
673
|
+
*/
|
|
674
|
+
static prompt(message: string, options: AgentOptions): Promise<AgentPromptResult>;
|
|
675
|
+
/**
|
|
676
|
+
* Reattach to an existing agent by ID.
|
|
677
|
+
*
|
|
678
|
+
* @public
|
|
679
|
+
*/
|
|
680
|
+
static resume(agentId: string, options?: Partial<AgentOptions>): Promise<SDKAgent>;
|
|
681
|
+
/**
|
|
682
|
+
* Start building an {@link AgentOptions} via fluent chain. See ADR D25.
|
|
683
|
+
* Terminals: `.build()`, `.create()`, `.getOrCreate(id)`.
|
|
684
|
+
*
|
|
685
|
+
* The builder receives `create` + `getOrCreate` as injected callbacks so
|
|
686
|
+
* that `agent-builder.ts` doesn't need a static import of `Agent` — keeps
|
|
687
|
+
* the module graph acyclic (G6).
|
|
688
|
+
*
|
|
689
|
+
* @public
|
|
690
|
+
*/
|
|
691
|
+
static builder(): AgentBuilder;
|
|
692
|
+
/**
|
|
693
|
+
* Generate a typed object matching a Zod schema via a synthetic forced
|
|
694
|
+
* tool call (ADR D33). One-shot: create transient agent → send prompt →
|
|
695
|
+
* model calls `output` tool → parse args via Zod → return typed.
|
|
696
|
+
*
|
|
697
|
+
* @public
|
|
698
|
+
*/
|
|
699
|
+
static generateObject<T extends zod.ZodType>(options: GenerateObjectOptions<T>): Promise<GenerateObjectResult<zod.z.infer<T>>>;
|
|
700
|
+
/**
|
|
701
|
+
* Stream a structured output object alongside intermediate `partial`
|
|
702
|
+
* deltas as the model accumulates its response (ADR D39). Returns an
|
|
703
|
+
* `AsyncIterator<StreamObjectEvent<T>>` that yields zero or more
|
|
704
|
+
* `partial` events and exactly one `complete` event at the end.
|
|
705
|
+
*
|
|
706
|
+
* The `complete` event carries the same `object: z.infer<T>` you would get
|
|
707
|
+
* from `Agent.generateObject` — same prompt + schema + model produces
|
|
708
|
+
* the same final object.
|
|
709
|
+
*
|
|
710
|
+
* @public
|
|
711
|
+
*/
|
|
712
|
+
static streamObject<T extends zod.ZodType>(options: StreamObjectOptions<T>): AsyncGenerator<StreamObjectEvent<zod.z.infer<T>>, void, void>;
|
|
713
|
+
/**
|
|
714
|
+
* Run N prompts in parallel with bounded concurrency (ADRs D134-D140).
|
|
715
|
+
*
|
|
716
|
+
* Each prompt gets a fresh agent (create → send → wait → dispose). Failures
|
|
717
|
+
* are isolated per-prompt; the batch never throws on a single failure —
|
|
718
|
+
* inspect `result.ok` to discriminate success vs error. Default
|
|
719
|
+
* concurrency is 4. When `options.providers.apiKeys` has ≥2 keys per
|
|
720
|
+
* provider, all in-flight agents share a single credential pool via
|
|
721
|
+
* `AsyncLocalStorage` (EC-A) so rate-limit cooldowns are observed once
|
|
722
|
+
* instead of duplicated per agent.
|
|
723
|
+
*
|
|
724
|
+
* Streaming progress is opt-in via `onResult` / `onProgress`. `AbortSignal`
|
|
725
|
+
* cancels pending prompts; in-flight ones continue to completion (Node
|
|
726
|
+
* AbortSignal semantics). `signal.reason` propagates to `error` when set.
|
|
727
|
+
*
|
|
728
|
+
* @public
|
|
729
|
+
*/
|
|
730
|
+
static batch(prompts: ReadonlyArray<string | BatchItem>, options: BatchOptions): Promise<BatchResult[]>;
|
|
731
|
+
/**
|
|
732
|
+
* Get an existing agent by ID, or create one with the supplied options if
|
|
733
|
+
* the ID is not yet registered. Eliminates the resume-vs-create boilerplate
|
|
734
|
+
* common to chat bots and other long-running agent consumers. See ADR D22.
|
|
735
|
+
*
|
|
736
|
+
* Resolution:
|
|
737
|
+
* 1. Try `Agent.resume(agentId, options)`. Return on success.
|
|
738
|
+
* 2. On `UnknownAgentError`, fall through to `Agent.create({ ...options, agentId })`.
|
|
739
|
+
* 3. On same-process race (`ConfigurationError(code: "agent_id_already_exists")`
|
|
740
|
+
* during step 2), retry `Agent.resume` once and return the winner's handle.
|
|
741
|
+
* 4. Any other error propagates verbatim.
|
|
742
|
+
*
|
|
743
|
+
* Caveats:
|
|
744
|
+
* - The function-level `agentId` always wins over `options.agentId`.
|
|
745
|
+
* - Options differ between calls? Last-call-wins for this handle (matches `Agent.resume`).
|
|
746
|
+
* - A DISPOSED agent is replaced automatically. `dispose()` evicts the id from the
|
|
747
|
+
* live cache (`liveAgentRegistry.forget`), so the next `getOrCreate(id)` builds a
|
|
748
|
+
* fresh handle — no `Agent.delete(agentId)` needed.
|
|
749
|
+
*
|
|
750
|
+
* This bullet used to say the opposite ("Disposed agents are NOT auto-deleted...
|
|
751
|
+
* call `Agent.delete(agentId)` first"). It was measured false in M91:
|
|
752
|
+
* `tests/agent-getorcreate-after-dispose.test.ts` builds an agent, disposes it, and
|
|
753
|
+
* gets a different instance back. The claim was about the PERSISTENT registry and
|
|
754
|
+
* read as being about the live cache — and consumers built around the wrong half.
|
|
755
|
+
* The agent-builder's M85 interrupt rotates the session id to work around a
|
|
756
|
+
* constraint that does not exist.
|
|
757
|
+
*
|
|
758
|
+
* - `close()` marks the handle disposed WITHOUT evicting the cache entry. It is
|
|
759
|
+
* internal and unused today; if it becomes reachable, this bullet stops being true
|
|
760
|
+
* for that path.
|
|
761
|
+
*
|
|
762
|
+
* @public
|
|
763
|
+
*/
|
|
764
|
+
static getOrCreate(agentId: string, options: AgentOptions): Promise<SDKAgent>;
|
|
765
|
+
/**
|
|
766
|
+
* List agents (local or cloud). M107 — `cwd` is READ, not ignored. B-115 (2026-08-19) —
|
|
767
|
+
* `includeArchived` and `limit`/`cursor` are READ too now; see `ListAgentsOptions`'s doc for the
|
|
768
|
+
* pagination contract and why the unlimited (no `limit`) case is unaffected.
|
|
769
|
+
*
|
|
770
|
+
* @public
|
|
771
|
+
*/
|
|
772
|
+
static list(options?: ListAgentsOptions): Promise<ListResult<SDKAgentInfo>>;
|
|
773
|
+
/**
|
|
774
|
+
* Get metadata for a single agent. B-115 (2026-08-19) — `cwd` is READ now (see
|
|
775
|
+
* `GetAgentOptions`'s doc); it used to be accepted and silently ignored.
|
|
776
|
+
*
|
|
777
|
+
* @public
|
|
778
|
+
*/
|
|
779
|
+
static get(agentId: string, options?: GetAgentOptions): Promise<SDKAgentInfo>;
|
|
780
|
+
/**
|
|
781
|
+
* List runs for an agent. B-115 (2026-08-19) — `cwd` and `limit`/`cursor` are READ now (see
|
|
782
|
+
* `ListRunsOptions`'s doc); they used to be accepted and silently ignored.
|
|
783
|
+
*
|
|
784
|
+
* @public
|
|
785
|
+
*/
|
|
786
|
+
static listRuns(agentId: string, options?: ListRunsOptions): Promise<ListResult<Run>>;
|
|
787
|
+
/**
|
|
788
|
+
* Get a single run.
|
|
789
|
+
*
|
|
790
|
+
* @public
|
|
791
|
+
*/
|
|
792
|
+
static getRun(runId: string, options?: GetRunOptions): Promise<Run>;
|
|
793
|
+
/**
|
|
794
|
+
* Archive a cloud agent.
|
|
795
|
+
*
|
|
796
|
+
* @public
|
|
797
|
+
*/
|
|
798
|
+
static archive(agentId: string, _options?: AgentOperationOptions): Promise<void>;
|
|
799
|
+
/**
|
|
800
|
+
* Restore an archived cloud agent.
|
|
801
|
+
*
|
|
802
|
+
* @public
|
|
803
|
+
*/
|
|
804
|
+
static unarchive(agentId: string, _options?: AgentOperationOptions): Promise<void>;
|
|
805
|
+
/**
|
|
806
|
+
* Set the human-facing `name` of a registered agent (the label `Agent.list()` returns). The registry
|
|
807
|
+
* already carries a `name` field; this is the missing public mutator for it. Runtime-agnostic (mutates
|
|
808
|
+
* the local per-cwd registry for local agents; the cloud registry for cloud agents).
|
|
809
|
+
*
|
|
810
|
+
* @public
|
|
811
|
+
*/
|
|
812
|
+
static rename(agentId: string, name: string, _options?: AgentOperationOptions): Promise<void>;
|
|
813
|
+
/**
|
|
814
|
+
* M50 — compact a LOCAL agent's persisted session transcript (Codex `/compact` parity): the
|
|
815
|
+
* history is summarized (recent user messages preserved verbatim + one marker'd summary) and an
|
|
816
|
+
* append-only `compact_boundary` + replacement chain is written — resume replays only the
|
|
817
|
+
* replacement + later turns. The summarizer defaults to the compression subsystem's aux-LLM
|
|
818
|
+
* (its first real caller); tests/consumers may inject their own.
|
|
819
|
+
*
|
|
820
|
+
* @public
|
|
821
|
+
*/
|
|
822
|
+
static compact(agentId: string, options?: {
|
|
823
|
+
trigger?: "manual" | "auto";
|
|
824
|
+
summarize?: (messages: readonly CompressibleMessage[]) => Promise<string>;
|
|
825
|
+
}): Promise<CompactResult>;
|
|
826
|
+
/**
|
|
827
|
+
* M51 — inject a SYNTHETIC user+assistant pair into a LOCAL session's persisted transcript WITHOUT
|
|
828
|
+
* running an LLM turn (the Codex review-exit mechanism: the parent thread "learns" a result — e.g.
|
|
829
|
+
* review findings — so follow-ups work). Appends onto the DAG leaf and invalidates the in-memory
|
|
830
|
+
* cache; serialized on the per-agent write chain.
|
|
831
|
+
*
|
|
832
|
+
* @public
|
|
833
|
+
*/
|
|
834
|
+
static injectSessionTurn(agentId: string, turn: {
|
|
835
|
+
userText: string;
|
|
836
|
+
assistantText: string;
|
|
837
|
+
}): Promise<void>;
|
|
838
|
+
/**
|
|
839
|
+
* theokit#146 — read a LOCAL agent's persisted transcript as STRUCTURE, for rendering.
|
|
840
|
+
*
|
|
841
|
+
* A resumed session already replays correctly to the model, but a host had no way to draw it:
|
|
842
|
+
* the only projection available folded a tool call to the string `[tool call] NAME`, dropping the
|
|
843
|
+
* call id and every argument. A card UI got prose, so cross-restart resume was worth less than
|
|
844
|
+
* starting fresh — which is what at least one consumer did.
|
|
845
|
+
*
|
|
846
|
+
* Each returned message carries both projections: `text` (unchanged, what the model replay uses)
|
|
847
|
+
* and `parts` (`text` / `tool_use` / `tool_result` with ids, names, arguments and the
|
|
848
|
+
* `toolUseId` that correlates a result back to its call).
|
|
849
|
+
*
|
|
850
|
+
* Read-only and local-only: it opens the agent's session store and walks the transcript, exactly
|
|
851
|
+
* as {@link Agent.compact} and {@link Agent.injectSessionTurn} do. It appends nothing.
|
|
852
|
+
*
|
|
853
|
+
* @throws UnknownAgentError when `agentId` names no local agent.
|
|
854
|
+
* @public
|
|
855
|
+
*/
|
|
856
|
+
static transcript(agentId: string): Promise<readonly SessionMessage[]>;
|
|
857
|
+
/**
|
|
858
|
+
* theokit#123 — read-only introspection of a registered agent's tools and subagents.
|
|
859
|
+
*
|
|
860
|
+
* `Agent.list()` / `Agent.get()` enumerate agents and `agent.skills.list()` covers skills, but
|
|
861
|
+
* tools and subagents lived only on `RegisteredAgent.options` — an internal contract. A
|
|
862
|
+
* reflection endpoint (theokit-studio's `theokit dev`) therefore had to report empty lists for
|
|
863
|
+
* both, and say so with an `unavailable_reason`.
|
|
864
|
+
*
|
|
865
|
+
* A PROJECTION, not the options object. Tool handlers and subagent prompts are stripped: a
|
|
866
|
+
* handler is an executable that cannot cross a process boundary, and a prompt is the agent's
|
|
867
|
+
* instructions rather than its signature — a reflection endpoint serializes what it is handed.
|
|
868
|
+
*
|
|
869
|
+
* @throws UnknownAgentError when `agentId` names no registered agent.
|
|
870
|
+
* @public
|
|
871
|
+
*/
|
|
872
|
+
static describe(agentId: string): Promise<AgentDescription>;
|
|
873
|
+
/**
|
|
874
|
+
* Permanently delete a cloud agent.
|
|
875
|
+
*
|
|
876
|
+
* @public
|
|
877
|
+
*/
|
|
878
|
+
static delete(agentId: string, _options?: AgentOperationOptions): Promise<void>;
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
/**
|
|
882
|
+
* Handle returned by {@link createAgentFactory}. See ADR D23 for merge
|
|
883
|
+
* semantics.
|
|
884
|
+
*
|
|
885
|
+
* @public
|
|
886
|
+
*/
|
|
887
|
+
interface AgentFactory {
|
|
888
|
+
/**
|
|
889
|
+
* Create a fresh agent for this session. Equivalent to `Agent.create(merged)`
|
|
890
|
+
* where `merged` is `common` ⊕ `overrides` ⊕ `{ agentId }`.
|
|
891
|
+
*/
|
|
892
|
+
forSession(agentId: string, overrides?: Partial<AgentOptions>): Promise<SDKAgent>;
|
|
893
|
+
/**
|
|
894
|
+
* Resume an existing agent for this session, or create one if the ID is
|
|
895
|
+
* unknown. Equivalent to `Agent.getOrCreate(agentId, merged)`.
|
|
896
|
+
*/
|
|
897
|
+
getOrCreate(agentId: string, overrides?: Partial<AgentOptions>): Promise<SDKAgent>;
|
|
898
|
+
}
|
|
899
|
+
/** SE36 — `AgentFactory.create` replaces `createAgentFactory` (ADR 0015). Merges with the `AgentFactory` interface. @public */
|
|
900
|
+
declare class AgentFactory {
|
|
901
|
+
private constructor();
|
|
902
|
+
static create(common: Partial<AgentOptions>): AgentFactory;
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
/**
|
|
906
|
+
* Decide whether a tool call proceeds, and say WHY — as a typed signal rather than a tool result.
|
|
907
|
+
*
|
|
908
|
+
* When a veto is delivered as an ordinary tool result, the MODEL reads it as output: it sees a
|
|
909
|
+
* string, concludes the tool failed for some reason, and retries or works around it. A denial, an
|
|
910
|
+
* error, and a tool that legitimately returned the word "denied" become indistinguishable to
|
|
911
|
+
* everything downstream — including the surface that should be telling the user what happened.
|
|
912
|
+
*
|
|
913
|
+
* ## What is generic, and what is not
|
|
914
|
+
*
|
|
915
|
+
* The RULE is a precedence: an explicit per-tool decision outranks the mode, a convenience mode does
|
|
916
|
+
* not overturn an explicit refusal, and anything undecided falls to the mode. The VOCABULARY is not
|
|
917
|
+
* — which tools exist belongs to the product and arrives as data. Nothing here names one.
|
|
918
|
+
*
|
|
919
|
+
* Deliberately separate from the blast-radius policy: that one answers "what does this action
|
|
920
|
+
* reach", this one answers "who said yes". Keeping them apart is what lets a product gate on reach
|
|
921
|
+
* without re-implementing the mode ladder, and compose both where it needs to.
|
|
922
|
+
*
|
|
923
|
+
* @public
|
|
924
|
+
*/
|
|
925
|
+
/** What the operator chose for everything not decided per tool. @public */
|
|
926
|
+
type ApprovalMode = "ask" | "never-ask" | "refuse-all";
|
|
927
|
+
/**
|
|
928
|
+
* The three answers a policy can give: proceed, put the call in front of a human, or stop it.
|
|
929
|
+
*
|
|
930
|
+
* `ask` is not a softer `deny`. A surface with no way to reach a human must treat it as a refusal,
|
|
931
|
+
* because treating it as permission is how an unattended run approves everything it was meant to
|
|
932
|
+
* pause on.
|
|
933
|
+
*
|
|
934
|
+
* @public
|
|
935
|
+
*/
|
|
936
|
+
type ApprovalOutcome = "allow" | "ask" | "deny";
|
|
937
|
+
/**
|
|
938
|
+
* Which rule produced the outcome.
|
|
939
|
+
*
|
|
940
|
+
* The `explicitly-` pair means a per-tool list decided it; the `mode-` triple means no list named
|
|
941
|
+
* the tool and the operator's mode decided instead. Worth rendering alongside the outcome: "you
|
|
942
|
+
* denied this tool" and "your mode refuses everything" send the operator to different settings.
|
|
943
|
+
*
|
|
944
|
+
* @public
|
|
945
|
+
*/
|
|
946
|
+
type ApprovalReason = "explicitly-allowed" | "explicitly-denied" | "mode-ask" | "mode-never-ask" | "mode-refuse-all";
|
|
947
|
+
/**
|
|
948
|
+
* One tool call to decide on, plus the operator's configuration.
|
|
949
|
+
*
|
|
950
|
+
* `tool` is matched against `denied` and `allowed` by exact string equality — there is no pattern
|
|
951
|
+
* or prefix rule. Both lists default to empty, so with neither supplied every call is decided by
|
|
952
|
+
* `mode` alone.
|
|
953
|
+
*
|
|
954
|
+
* @public
|
|
955
|
+
*/
|
|
956
|
+
interface ApprovalInput {
|
|
957
|
+
readonly tool: string;
|
|
958
|
+
readonly mode: ApprovalMode;
|
|
959
|
+
/** Tools the operator allowed once and for all. */
|
|
960
|
+
readonly allowed?: readonly string[];
|
|
961
|
+
/** Tools the operator refused. Outranks `allowed` and every mode. */
|
|
962
|
+
readonly denied?: readonly string[];
|
|
963
|
+
}
|
|
964
|
+
/**
|
|
965
|
+
* The answer, the rule that produced it, and the tool it was about.
|
|
966
|
+
*
|
|
967
|
+
* @public
|
|
968
|
+
*/
|
|
969
|
+
interface ApprovalDecision {
|
|
970
|
+
readonly outcome: ApprovalOutcome;
|
|
971
|
+
readonly reason: ApprovalReason;
|
|
972
|
+
/** The tool the decision was about, so a surface names it without re-deriving it. */
|
|
973
|
+
readonly tool: string;
|
|
974
|
+
}
|
|
975
|
+
/**
|
|
976
|
+
* Decide one tool call against the operator's lists and mode.
|
|
977
|
+
*
|
|
978
|
+
* The precedence is fixed and each step short-circuits: `denied` is consulted first, then
|
|
979
|
+
* `allowed`, then `mode`. A tool named in BOTH lists is therefore denied — a contradictory config
|
|
980
|
+
* is read restrictively, because the usual cause is an allow-entry that outlived the denial meant
|
|
981
|
+
* to replace it.
|
|
982
|
+
*
|
|
983
|
+
* This answers only who said yes. What the call REACHES is a separate question with a separate
|
|
984
|
+
* policy — `evaluateBlastRadius` — and neither consults the other, so a product that wants both
|
|
985
|
+
* gates calls both and combines the outcomes itself.
|
|
986
|
+
*
|
|
987
|
+
* @returns the outcome, why it was reached, and the tool it was about.
|
|
988
|
+
* @public
|
|
989
|
+
*/
|
|
990
|
+
declare function decideApproval(input: ApprovalInput): ApprovalDecision;
|
|
991
|
+
|
|
992
|
+
/**
|
|
993
|
+
* Decide an action by what it REACHES and whether it can be undone — not by its name.
|
|
994
|
+
*
|
|
995
|
+
* A sandbox answers "which files may this process touch", and that is a different question from the
|
|
996
|
+
* one that decides whether an action is safe. A tool that drops a production database touches no
|
|
997
|
+
* file the sandbox cares about; a tool that lists pods reaches an entire cluster while writing
|
|
998
|
+
* nothing. Confinement covers the disk, not the reach.
|
|
999
|
+
*
|
|
1000
|
+
* With nothing better available, every product gates on the tool's NAME: an allowlist of strings
|
|
1001
|
+
* that says nothing about what the tool does, drifts the moment one is renamed, and cannot be
|
|
1002
|
+
* reasoned about by anyone who did not write it. A guard each product re-implements is a guard some
|
|
1003
|
+
* product forgets.
|
|
1004
|
+
*
|
|
1005
|
+
* ## What is generic here, and what is not
|
|
1006
|
+
*
|
|
1007
|
+
* The RULE is: an action declares the scope it reaches and whether it is reversible, and a policy
|
|
1008
|
+
* decides from those two facts plus what the operator granted. The VOCABULARY is not — which scopes
|
|
1009
|
+
* exist ("cluster:prod", "billing-account", "the laptop") belongs to the product and arrives as
|
|
1010
|
+
* data. Nothing in this module names a scope, the same way the security floor names no sandbox mode
|
|
1011
|
+
* and the trust posture names no capability.
|
|
1012
|
+
*
|
|
1013
|
+
* ## Why the reason is part of the answer
|
|
1014
|
+
*
|
|
1015
|
+
* "The sandbox stopped this" and "you never granted reach to that scope" are different facts with
|
|
1016
|
+
* different fixes, and an operator told the wrong one widens the wrong thing. So a decision carries
|
|
1017
|
+
* WHY — the same reason a trust posture reports its `source` and a wiring record distinguishes
|
|
1018
|
+
* withheld-by-trust from never-configured.
|
|
1019
|
+
*
|
|
1020
|
+
* @public
|
|
1021
|
+
*/
|
|
1022
|
+
/** What an action reaches, and whether it can be taken back. @public */
|
|
1023
|
+
interface DeclaredAction {
|
|
1024
|
+
/**
|
|
1025
|
+
* The product's name for what this action reaches. An empty string is treated as UNDECLARED and
|
|
1026
|
+
* refused: a tool that forgot to declare is not a tool that reaches nothing.
|
|
1027
|
+
*/
|
|
1028
|
+
readonly scope: string;
|
|
1029
|
+
/**
|
|
1030
|
+
* Whether the action can be undone. Reversible actions inside a granted scope proceed;
|
|
1031
|
+
* irreversible ones ask, because granting reach is not granting destruction.
|
|
1032
|
+
*/
|
|
1033
|
+
readonly reversible: boolean;
|
|
1034
|
+
}
|
|
1035
|
+
/**
|
|
1036
|
+
* The action to decide on, plus what the operator granted.
|
|
1037
|
+
*
|
|
1038
|
+
* `granted` is matched against `action.scope` by exact string equality: there is no prefix or
|
|
1039
|
+
* wildcard rule, so granting `cluster:prod` does not grant `cluster:prod:kube-system`. A product
|
|
1040
|
+
* that wants hierarchical scopes expands them itself before calling.
|
|
1041
|
+
*
|
|
1042
|
+
* `irreversibleAllowed` defaults to empty, so an irreversible action inside a granted scope asks
|
|
1043
|
+
* for approval unless its scope was pre-approved for destruction as well.
|
|
1044
|
+
*
|
|
1045
|
+
* @public
|
|
1046
|
+
*/
|
|
1047
|
+
interface BlastRadiusInput {
|
|
1048
|
+
readonly action: DeclaredAction;
|
|
1049
|
+
/** Scopes the operator granted reach to. Empty grants nothing — never everything. */
|
|
1050
|
+
readonly granted: readonly string[];
|
|
1051
|
+
/** Scopes where the operator pre-approved irreversible actions, so an unattended run can work. */
|
|
1052
|
+
readonly irreversibleAllowed?: readonly string[];
|
|
1053
|
+
}
|
|
1054
|
+
/**
|
|
1055
|
+
* What the policy decided.
|
|
1056
|
+
*
|
|
1057
|
+
* `require-approval` means a human has to say yes before the action runs; a caller with no way to
|
|
1058
|
+
* ask must treat it as a refusal. `refuse` is not appealable through this policy at all — the
|
|
1059
|
+
* operator has to grant the scope first, which is deliberately a configuration change rather than
|
|
1060
|
+
* a prompt.
|
|
1061
|
+
*
|
|
1062
|
+
* @public
|
|
1063
|
+
*/
|
|
1064
|
+
type BlastRadiusOutcome = "allow" | "require-approval" | "refuse";
|
|
1065
|
+
/** Why the decision came out that way. Rendered to the operator and read by an audit. @public */
|
|
1066
|
+
type BlastRadiusReason = "within-granted-scope" | "irreversible" | "scope-not-granted" | "scope-undeclared";
|
|
1067
|
+
/**
|
|
1068
|
+
* The outcome, the rule that produced it, and the scope it was decided about.
|
|
1069
|
+
*
|
|
1070
|
+
* `scope` echoes what the action declared, so it is the empty string when the reason is
|
|
1071
|
+
* `scope-undeclared` — the decision names what it saw rather than substituting a placeholder.
|
|
1072
|
+
*
|
|
1073
|
+
* @public
|
|
1074
|
+
*/
|
|
1075
|
+
interface BlastRadiusDecision {
|
|
1076
|
+
readonly outcome: BlastRadiusOutcome;
|
|
1077
|
+
readonly reason: BlastRadiusReason;
|
|
1078
|
+
/** The scope the decision was made about, so a surface can name it without re-deriving it. */
|
|
1079
|
+
readonly scope: string;
|
|
1080
|
+
}
|
|
1081
|
+
/**
|
|
1082
|
+
* Decide one declared action against the scopes the operator granted.
|
|
1083
|
+
*
|
|
1084
|
+
* Four checks, in this order, each short-circuiting: an empty `scope` is refused as undeclared
|
|
1085
|
+
* before any comparison happens; a scope absent from `granted` is refused; an irreversible action
|
|
1086
|
+
* whose scope is not in `irreversibleAllowed` escalates to approval; anything left is allowed.
|
|
1087
|
+
*
|
|
1088
|
+
* Refusal outranking escalation is a decision, not an accident. Asking a human to approve a scope
|
|
1089
|
+
* the operator never granted trains them to approve by reflex, which is how an approval prompt
|
|
1090
|
+
* stops being a control.
|
|
1091
|
+
*
|
|
1092
|
+
* This decides reach only. Whether the operator permitted the tool at all is `decideApproval`, and
|
|
1093
|
+
* the two are independent.
|
|
1094
|
+
*
|
|
1095
|
+
* @returns the outcome with the reason and the scope it was decided on.
|
|
1096
|
+
* @public
|
|
1097
|
+
*/
|
|
1098
|
+
declare function evaluateBlastRadius(input: BlastRadiusInput): BlastRadiusDecision;
|
|
1099
|
+
|
|
1100
|
+
/**
|
|
1101
|
+
* computeCost — apply pricing entries to a TokenUsage and produce a
|
|
1102
|
+
* CostBreakdown (ADRs D377, D378).
|
|
1103
|
+
*
|
|
1104
|
+
* Edge cases absorbed:
|
|
1105
|
+
* - EC-13: negative pricing → status="unknown" + note.
|
|
1106
|
+
* - EC-14: reasoning tokens fall back to outputCostPerMillion when
|
|
1107
|
+
* dedicated reasoning rate is undefined.
|
|
1108
|
+
* - EC-12: money precision via microcent normalization (× 1e6).
|
|
1109
|
+
* - "subscription_included" routes (Codex CLI, future Claude Pro) →
|
|
1110
|
+
* return $0 with status="included".
|
|
1111
|
+
* - Provider unknown / pricing missing → status="unknown" with
|
|
1112
|
+
* undefined amountUsd (does NOT return a false 0).
|
|
1113
|
+
*
|
|
1114
|
+
* @internal
|
|
1115
|
+
*/
|
|
1116
|
+
interface ComputeArgs {
|
|
1117
|
+
readonly usage: TokenUsage;
|
|
1118
|
+
readonly provider: string;
|
|
1119
|
+
readonly model: string;
|
|
1120
|
+
readonly baseUrl?: string;
|
|
1121
|
+
}
|
|
1122
|
+
/**
|
|
1123
|
+
* Returns CostBreakdown with `status="estimated"`, `"unknown"`, or
|
|
1124
|
+
* `"included"`. Never throws; never returns 0 when pricing is missing.
|
|
1125
|
+
*/
|
|
1126
|
+
declare function computeCost(args: ComputeArgs): CostBreakdown;
|
|
1127
|
+
|
|
1128
|
+
/**
|
|
1129
|
+
* Budget enforcement (ADRs D383, D386, EC-7/8/9).
|
|
1130
|
+
*
|
|
1131
|
+
* - `preflightCheck(name, estimatedUsd)` — in `block` mode, throw
|
|
1132
|
+
* `BudgetExceededError` before the LLM call if any limit would be
|
|
1133
|
+
* exceeded (EC-9 — the caller invokes it inside the mutex section).
|
|
1134
|
+
* - `chargeAndCheckThresholds(name, actualUsd)` — apply the charge to the
|
|
1135
|
+
* ledger + invoke onThreshold/onExceed callbacks isolated in
|
|
1136
|
+
* try/catch (EC-8).
|
|
1137
|
+
*
|
|
1138
|
+
* @internal
|
|
1139
|
+
*/
|
|
1140
|
+
/**
|
|
1141
|
+
* Throws BudgetExceededError if `mode === "block"` and any limit
|
|
1142
|
+
* would be exceeded. No-op for audit/warn modes (post-charge checks
|
|
1143
|
+
* handle those).
|
|
1144
|
+
*
|
|
1145
|
+
* Caller invokes this BEFORE the LLM call.
|
|
1146
|
+
*/
|
|
1147
|
+
declare function preflightCheck(name: string, estimatedUsd: number): void;
|
|
1148
|
+
/**
|
|
1149
|
+
* Charge the budget + dispatch threshold/exceed callbacks (EC-8 isolated).
|
|
1150
|
+
*
|
|
1151
|
+
* - In `audit` mode: charge only, no callbacks.
|
|
1152
|
+
* - In `warn` mode: charge + onThreshold (80/95) + onExceed (100). No throw.
|
|
1153
|
+
* - In `block` mode: charge + onThreshold + onExceed. No throw post-call
|
|
1154
|
+
* (preflightCheck already prevented exceed for the upcoming call;
|
|
1155
|
+
* this protects against simultaneous-call races where multiple sends
|
|
1156
|
+
* each pass preflight independently — last one to charge may still
|
|
1157
|
+
* tip a limit. We document the case rather than retroactively throw).
|
|
1158
|
+
*/
|
|
1159
|
+
declare function chargeAndCheckThresholds(name: string, actualUsd: number): Promise<void>;
|
|
1160
|
+
|
|
1161
|
+
/**
|
|
1162
|
+
* normalizeUsage — convert provider-shaped raw `usage` object to
|
|
1163
|
+
* canonical `TokenUsage`. Ports Hermes Agent's `normalize_usage`
|
|
1164
|
+
* (reference/peer-agent/agent/usage_pricing.py:672-742).
|
|
1165
|
+
*
|
|
1166
|
+
* Handles 3 API shapes:
|
|
1167
|
+
* - Anthropic Messages: 4 explicit buckets (input/output/cache_read/cache_creation).
|
|
1168
|
+
* - OpenAI Chat Completions: prompt_tokens INCLUDES cache; subtract cached_tokens.
|
|
1169
|
+
* - OpenAI Responses (Codex): input_tokens INCLUDES cache; same subtraction.
|
|
1170
|
+
*
|
|
1171
|
+
* Edge cases:
|
|
1172
|
+
* - a peer#10266 — OpenAI-compat proxies (OpenRouter, a peer vendor AI Gateway,
|
|
1173
|
+
* a peer) routing Claude expose Anthropic-style top-level fields
|
|
1174
|
+
* (cache_read_input_tokens / cache_creation_input_tokens). Both
|
|
1175
|
+
* locations are checked with top-level fallback.
|
|
1176
|
+
* - Null/undefined fields → 0 via `int()` coerce.
|
|
1177
|
+
* - String token counts → parsed via int.
|
|
1178
|
+
* - Negative values → clamped to 0 (defensive against proxy bugs).
|
|
1179
|
+
*
|
|
1180
|
+
* @internal
|
|
1181
|
+
*/
|
|
1182
|
+
type ApiMode = "anthropic_messages" | "openai_chat_completions" | "openai_responses";
|
|
1183
|
+
/**
|
|
1184
|
+
* Guess which usage shape a provider reports, from its name alone.
|
|
1185
|
+
*
|
|
1186
|
+
* Matching is case-insensitive and exact — `"anthropic"`, `"claude"` and `"bedrock_anthropic"`
|
|
1187
|
+
* give `"anthropic_messages"`; `"openai-codex"` and `"codex"` give `"openai_responses"`. Every
|
|
1188
|
+
* other name, including ones this SDK has never seen, falls through to
|
|
1189
|
+
* `"openai_chat_completions"`. There is no unknown result, so a wrong guess is silent: it is
|
|
1190
|
+
* read as a Chat Completions payload, whose fields are absent, and the tokens come back as 0.
|
|
1191
|
+
*
|
|
1192
|
+
* The default is right for the OpenAI-compatible majority (openai, openrouter, deepseek, and the
|
|
1193
|
+
* compat endpoints of google, ollama and lmstudio). When it is not, pass `apiMode` to
|
|
1194
|
+
* `normalizeUsage` explicitly instead of relying on the name.
|
|
1195
|
+
*/
|
|
1196
|
+
declare function inferApiMode(provider: string): ApiMode;
|
|
1197
|
+
/**
|
|
1198
|
+
* Convert a provider's raw `usage` object into the SDK's canonical `TokenUsage`.
|
|
1199
|
+
*
|
|
1200
|
+
* Never throws and never reports failure. `null`, `undefined` and any non-object argument return
|
|
1201
|
+
* all-zero usage, which is indistinguishable from a real response that used no tokens — so this
|
|
1202
|
+
* is not the place to detect a malformed payload.
|
|
1203
|
+
*
|
|
1204
|
+
* `opts.apiMode` selects the reader; when omitted it is derived from `opts.provider` via
|
|
1205
|
+
* `inferApiMode`, whose fallback is Chat Completions. Pass it explicitly for any provider whose
|
|
1206
|
+
* name does not identify its wire shape.
|
|
1207
|
+
*
|
|
1208
|
+
* The shapes differ in one way that matters: Anthropic reports cache tokens in buckets separate
|
|
1209
|
+
* from `input_tokens`, while both OpenAI shapes report a prompt total that already includes
|
|
1210
|
+
* them. For the OpenAI readers the cache buckets are subtracted, so `inputTokens` is always the
|
|
1211
|
+
* uncached portion and `inputTokens + cacheReadTokens + cacheWriteTokens` reconstructs the
|
|
1212
|
+
* provider's prompt total. The subtraction is floored at 0, so a payload whose cache counts
|
|
1213
|
+
* exceed its prompt total yields 0 rather than a negative.
|
|
1214
|
+
*
|
|
1215
|
+
* Every field is coerced: numbers are truncated toward zero, numeric strings are parsed, negative
|
|
1216
|
+
* and non-finite values become 0, and anything else becomes 0.
|
|
1217
|
+
*
|
|
1218
|
+
* `totalTokens` is computed here as input + output + both cache buckets; a `total_tokens` the
|
|
1219
|
+
* provider sent is ignored. Reasoning tokens are reported separately but are NOT added again —
|
|
1220
|
+
* providers already count them inside output. `cacheReadTokens`, `cacheWriteTokens` and
|
|
1221
|
+
* `reasoningTokens` are omitted from the result when they are 0, so absent means zero, not
|
|
1222
|
+
* unknown.
|
|
1223
|
+
*
|
|
1224
|
+
* Chat Completions also accepts Anthropic-style top-level `cache_read_input_tokens` /
|
|
1225
|
+
* `cache_creation_input_tokens`, which OpenAI-compatible proxies emit when they route Claude.
|
|
1226
|
+
* The nested `prompt_tokens_details` values win; the top-level fields are consulted only when
|
|
1227
|
+
* those are 0 or missing.
|
|
1228
|
+
*/
|
|
1229
|
+
declare function normalizeUsage(rawUsage: unknown, opts: {
|
|
1230
|
+
provider: string;
|
|
1231
|
+
apiMode?: ApiMode;
|
|
1232
|
+
}): TokenUsage;
|
|
1233
|
+
|
|
1234
|
+
/**
|
|
1235
|
+
* Pricing registry — bundled snapshot of LiteLLM JSON (ADR D379) with
|
|
1236
|
+
* lazy load + alias normalization (EC-2).
|
|
1237
|
+
*
|
|
1238
|
+
* Snapshot lives in `pricing-data.json` (hand-curated 2026-05; refresh
|
|
1239
|
+
* via `scripts/refresh-pricing.mjs`). All rates in USD per 1_000_000
|
|
1240
|
+
* tokens (D378).
|
|
1241
|
+
*
|
|
1242
|
+
* Lookup precedence (EC-2):
|
|
1243
|
+
* 1. Direct `provider/model` key
|
|
1244
|
+
* 2. Strip date suffix (-YYYYMMDD or -YYYY-MM-DD)
|
|
1245
|
+
* 3. Anthropic dot-to-dash normalization (claude-opus-4.7 → claude-opus-4-7)
|
|
1246
|
+
* 4. Strip `openrouter/` prefix
|
|
1247
|
+
*
|
|
1248
|
+
* @internal
|
|
1249
|
+
*/
|
|
1250
|
+
interface PricingEntry {
|
|
1251
|
+
readonly provider: string;
|
|
1252
|
+
readonly model: string;
|
|
1253
|
+
readonly inputCostPerMillion: number;
|
|
1254
|
+
readonly outputCostPerMillion: number;
|
|
1255
|
+
readonly cacheReadCostPerMillion?: number;
|
|
1256
|
+
readonly cacheWriteCostPerMillion?: number;
|
|
1257
|
+
readonly reasoningCostPerMillion?: number;
|
|
1258
|
+
readonly pricingVersion: string;
|
|
1259
|
+
}
|
|
1260
|
+
/**
|
|
1261
|
+
* Returns the pricing entry for a given `{provider, model}` route.
|
|
1262
|
+
* Tries direct lookup, then 3 alias normalizations (EC-2).
|
|
1263
|
+
*/
|
|
1264
|
+
declare function getPricingEntry(opts: {
|
|
1265
|
+
provider: string;
|
|
1266
|
+
model: string;
|
|
1267
|
+
baseUrl?: string;
|
|
1268
|
+
}): PricingEntry | undefined;
|
|
1269
|
+
|
|
1270
|
+
/**
|
|
1271
|
+
* UsageAccumulator — aggregate multi-step `LlmFinish` token counts
|
|
1272
|
+
* into a canonical `TokenUsage` (ADR D376, mirror a peer SDK
|
|
1273
|
+
* `Usage.add`).
|
|
1274
|
+
*
|
|
1275
|
+
* Each `add(step)` merges in a per-step finish; `toTokenUsage()`
|
|
1276
|
+
* produces the aggregated public shape with `requests[]` populated
|
|
1277
|
+
* when there were ≥2 steps.
|
|
1278
|
+
*
|
|
1279
|
+
* @internal
|
|
1280
|
+
*/
|
|
1281
|
+
interface StepUsage {
|
|
1282
|
+
inputTokens?: number;
|
|
1283
|
+
outputTokens?: number;
|
|
1284
|
+
cacheReadTokens?: number;
|
|
1285
|
+
cacheWriteTokens?: number;
|
|
1286
|
+
reasoningTokens?: number;
|
|
1287
|
+
}
|
|
1288
|
+
/**
|
|
1289
|
+
* Sums the per-step token counts of a multi-step run into one `TokenUsage`.
|
|
1290
|
+
*
|
|
1291
|
+
* Call `add` once per LLM finish, in any order, then `toTokenUsage` to read the total. The instance
|
|
1292
|
+
* is a running sum, not a snapshot: `toTokenUsage` may be called repeatedly and reflects everything
|
|
1293
|
+
* added so far, and there is no reset — start a new accumulator per run.
|
|
1294
|
+
*
|
|
1295
|
+
* Two shaping rules to expect in the output. The optional counters (cache read, cache write,
|
|
1296
|
+
* reasoning) are omitted entirely when they sum to zero rather than reported as `0`. And the
|
|
1297
|
+
* per-step `requests` array appears only when at least TWO steps were added, so a single-step run
|
|
1298
|
+
* carries totals alone.
|
|
1299
|
+
*
|
|
1300
|
+
* `totalTokens` is input plus output only — cache and reasoning counts are reported separately and
|
|
1301
|
+
* are not folded into it.
|
|
1302
|
+
*/
|
|
1303
|
+
declare class UsageAccumulator {
|
|
1304
|
+
private input;
|
|
1305
|
+
private output;
|
|
1306
|
+
private cacheRead;
|
|
1307
|
+
private cacheWrite;
|
|
1308
|
+
private reasoning;
|
|
1309
|
+
private readonly requests;
|
|
1310
|
+
add(step: StepUsage): void;
|
|
1311
|
+
/** Did we observe any usage at all? */
|
|
1312
|
+
hasAny(): boolean;
|
|
1313
|
+
toTokenUsage(): TokenUsage;
|
|
1314
|
+
}
|
|
1315
|
+
|
|
1316
|
+
/**
|
|
1317
|
+
* `Budget` — token cost enforcement primitive (Adoption Roadmap #1
|
|
1318
|
+
* post-Tasks, ADRs D375-D388).
|
|
1319
|
+
*
|
|
1320
|
+
* Static facade delegating to the in-process registry + ledger.
|
|
1321
|
+
* 3 modes: `audit` (log-only), `warn` (callbacks + log), `block`
|
|
1322
|
+
* (preflight throw before LLM call).
|
|
1323
|
+
*
|
|
1324
|
+
* @public
|
|
1325
|
+
*
|
|
1326
|
+
* @deprecated since SDK 2.0 (iter 18+) — import this facade from
|
|
1327
|
+
* `@theokit/sdk-budget` instead. The sources backing this facade have
|
|
1328
|
+
* been physically extracted to `@theokit/sdk-budget/internal/` per
|
|
1329
|
+
* ADR-008. The sdk-core copies are retained for the v1.x sync API
|
|
1330
|
+
* contract; consumers MUST migrate before sdk-core v3.0.
|
|
1331
|
+
*
|
|
1332
|
+
* Migration:
|
|
1333
|
+
*
|
|
1334
|
+
* ```ts
|
|
1335
|
+
* // Before (sdk-core, deprecated):
|
|
1336
|
+
* import { Budget, computeCost } from "@theokit/sdk";
|
|
1337
|
+
*
|
|
1338
|
+
* // After (sdk-budget, authoritative):
|
|
1339
|
+
* import {
|
|
1340
|
+
* chargeAndCheckThresholds,
|
|
1341
|
+
* createBudget,
|
|
1342
|
+
* computeUsdCost, // replaces computeCost
|
|
1343
|
+
* createUsdBudgetTracker,
|
|
1344
|
+
* } from "@theokit/sdk-budget";
|
|
1345
|
+
* ```
|
|
1346
|
+
*/
|
|
1347
|
+
|
|
1348
|
+
declare class Budget {
|
|
1349
|
+
private constructor();
|
|
1350
|
+
/**
|
|
1351
|
+
* Create a budget. `name` must match `^[a-z0-9][a-z0-9_-]*$` (EC-7).
|
|
1352
|
+
* Throws `ConfigurationError` if name is invalid OR already exists
|
|
1353
|
+
* (EC-16: duplicate surface caller bug).
|
|
1354
|
+
*
|
|
1355
|
+
* `limits` is stacked (D384) — ANY exceeded triggers enforcement.
|
|
1356
|
+
* Empty `limits[]` is valid: pure tracking, no thresholds/exceed
|
|
1357
|
+
* callbacks fire (EC-19).
|
|
1358
|
+
*
|
|
1359
|
+
* Default `mode` is `"warn"` (D383). For emergency stop, use
|
|
1360
|
+
* `mode: "block", limits: [{ window: "1d", limitUsd: 0 }]` (EC-18).
|
|
1361
|
+
*/
|
|
1362
|
+
static create(options: BudgetOptions): BudgetHandle;
|
|
1363
|
+
/** Returns the handle for an active budget, or `undefined`. */
|
|
1364
|
+
static get(name: string): BudgetHandle | undefined;
|
|
1365
|
+
/** Returns all active budgets. */
|
|
1366
|
+
static list(): readonly BudgetHandle[];
|
|
1367
|
+
/**
|
|
1368
|
+
* Deletes a budget from the registry. Returns `true` if it existed.
|
|
1369
|
+
* In-flight `agent.send` calls referencing the name treat the
|
|
1370
|
+
* subsequent charge as a silent no-op + stderr warn (EC-20).
|
|
1371
|
+
*/
|
|
1372
|
+
static delete(name: string): boolean;
|
|
1373
|
+
/**
|
|
1374
|
+
* Returns per-window spend snapshot for all active budgets. Each
|
|
1375
|
+
* entry has `{ name, window, spentUsd, limitUsd, ratio }`.
|
|
1376
|
+
*/
|
|
1377
|
+
static snapshot(): readonly BudgetSnapshot[];
|
|
1378
|
+
}
|
|
1379
|
+
|
|
1380
|
+
/**
|
|
1381
|
+
* SE25 — deterministic, no-LLM guardrail processors built on the SE24
|
|
1382
|
+
* {@link Processor} seam. Cheap and churn-free (no provider/model deltas), so
|
|
1383
|
+
* they are safe to own in-core — unlike the LLM-classifier processors, which are
|
|
1384
|
+
* delegated (see the guardrails ADR). All are OPT-IN: add them to
|
|
1385
|
+
* `AgentOptions.inputProcessors` / `outputProcessors`.
|
|
1386
|
+
*
|
|
1387
|
+
* @public
|
|
1388
|
+
*/
|
|
1389
|
+
/**
|
|
1390
|
+
* Approximate token count from string length. This is an ESTIMATE
|
|
1391
|
+
* (≈ UTF-16-code-units / 4, NOT Unicode code points, NOT an exact per-model
|
|
1392
|
+
* tokenizer count) — good enough for a coarse cap, and dependency-free.
|
|
1393
|
+
*
|
|
1394
|
+
* Re-exported rather than reimplemented: the ratio lives in `compaction.ts`, which is where the
|
|
1395
|
+
* heuristic is load-bearing. The name and the behaviour here are unchanged.
|
|
1396
|
+
*/
|
|
1397
|
+
|
|
1398
|
+
/** Options for {@link createUnicodeNormalizer}. @public */
|
|
1399
|
+
interface UnicodeNormalizerOptions {
|
|
1400
|
+
/** Remove C0 + C1 control chars + DEL (keeps tab / newline / carriage-return). Default `false`. */
|
|
1401
|
+
stripControlChars?: boolean;
|
|
1402
|
+
/** Collapse runs of intra-line whitespace to one space, 3+ blank lines to one, and trim. Default `false`. Uses legacy `\s`; Unicode-only whitespace (U+00A0 NBSP, U+FEFF BOM, U+2000–U+200A) is NOT collapsed. */
|
|
1403
|
+
collapseWhitespace?: boolean;
|
|
1404
|
+
}
|
|
1405
|
+
/** Options for {@link createTokenLimiter}. @public */
|
|
1406
|
+
interface TokenLimiterOptions {
|
|
1407
|
+
/** Positive integer token budget (estimate — see {@link estimateTokens}). */
|
|
1408
|
+
limit: number;
|
|
1409
|
+
/** Over the limit: `"truncate"` (default, cut to fit) or `"block"` (abort with a tripwire). */
|
|
1410
|
+
strategy?: "truncate" | "block";
|
|
1411
|
+
}
|
|
1412
|
+
/** SE36 — `TokenLimiter.create` replaces `createTokenLimiter` (ADR 0015). @public *
|
|
1413
|
+
* `TokenLimiter.create` returns a **`Processor`**, not a `TokenLimiter`. The class is
|
|
1414
|
+
* the namespace; the processor is the product.
|
|
1415
|
+
*/
|
|
1416
|
+
declare class TokenLimiter {
|
|
1417
|
+
private constructor();
|
|
1418
|
+
static create(opts: TokenLimiterOptions): Processor;
|
|
1419
|
+
}
|
|
1420
|
+
/** SE36 — `UnicodeNormalizer.create` replaces `createUnicodeNormalizer` (ADR 0015). @public *
|
|
1421
|
+
* `UnicodeNormalizer.create` returns a **`Processor`**, not a `UnicodeNormalizer`. The
|
|
1422
|
+
* class is the namespace; the processor is the product.
|
|
1423
|
+
*/
|
|
1424
|
+
declare class UnicodeNormalizer {
|
|
1425
|
+
private constructor();
|
|
1426
|
+
static create(opts?: UnicodeNormalizerOptions): Processor;
|
|
1427
|
+
}
|
|
1428
|
+
|
|
1429
|
+
/**
|
|
1430
|
+
* Report whether a credential resolved — never what it is.
|
|
1431
|
+
*
|
|
1432
|
+
* Every agent product grows a "why can't I use this model?" surface: a doctor command, a status
|
|
1433
|
+
* panel, a startup diagnostic. Each needs to know whether a credential resolved, and each is one
|
|
1434
|
+
* careless line from printing it. The line is careless precisely because it is convenient — the
|
|
1435
|
+
* value is right there, and whoever is debugging a routing problem wants to see it.
|
|
1436
|
+
*
|
|
1437
|
+
* So presence-only is the DEFAULT here rather than each consumer's discipline. Discipline is what
|
|
1438
|
+
* every product has until the day it does not, and a leaked key is not a defect anyone can withdraw.
|
|
1439
|
+
*
|
|
1440
|
+
* ## Why a fingerprint and not a prefix
|
|
1441
|
+
*
|
|
1442
|
+
* A report has to be actionable: two people asking "is it the same key?" need something to compare.
|
|
1443
|
+
* The convenient answer — the first eight characters — is still the secret, and it is enough to
|
|
1444
|
+
* identify a key in a breach corpus. A hash is not.
|
|
1445
|
+
*
|
|
1446
|
+
* @public
|
|
1447
|
+
*/
|
|
1448
|
+
/**
|
|
1449
|
+
* One provider's credential lookup, as the product resolved it.
|
|
1450
|
+
*
|
|
1451
|
+
* `value` is the secret itself. It is hashed and dropped inside `describeCredential` — it never
|
|
1452
|
+
* reaches the report, and nothing here stores it.
|
|
1453
|
+
*
|
|
1454
|
+
* @public
|
|
1455
|
+
*/
|
|
1456
|
+
interface CredentialInput {
|
|
1457
|
+
/** The product's name for the provider. This module never knows one of its own. */
|
|
1458
|
+
readonly provider: string;
|
|
1459
|
+
/** The resolved secret, or `undefined`/empty when nothing resolved. */
|
|
1460
|
+
readonly value: string | undefined;
|
|
1461
|
+
/** Where it came from, in the product's vocabulary — `env`, `file`, `keychain`, `oauth`. */
|
|
1462
|
+
readonly source: string;
|
|
1463
|
+
}
|
|
1464
|
+
/**
|
|
1465
|
+
* A presence-only view of one credential, safe to print, log, or attach to a support bundle.
|
|
1466
|
+
*
|
|
1467
|
+
* `fingerprint` is the first eight hex characters of the SHA-256 of the trimmed secret: enough for
|
|
1468
|
+
* two people to agree they are holding the same key, and not a substring of it. It is absent
|
|
1469
|
+
* whenever `present` is false.
|
|
1470
|
+
*
|
|
1471
|
+
* @public
|
|
1472
|
+
*/
|
|
1473
|
+
interface CredentialReport {
|
|
1474
|
+
readonly provider: string;
|
|
1475
|
+
readonly present: boolean;
|
|
1476
|
+
readonly source: string;
|
|
1477
|
+
/** Eight hex characters of a hash. Absent when no credential resolved. Never a prefix. */
|
|
1478
|
+
readonly fingerprint?: string;
|
|
1479
|
+
}
|
|
1480
|
+
/**
|
|
1481
|
+
* Turn a resolved credential into something you can show a user.
|
|
1482
|
+
*
|
|
1483
|
+
* The value is trimmed before the emptiness test, so `undefined`, `""` and whitespace all report
|
|
1484
|
+
* `present: false` with no fingerprint. That matters because an environment variable that expanded
|
|
1485
|
+
* to nothing arrives as an empty string, and calling that "present" sends whoever is debugging to
|
|
1486
|
+
* hunt for a routing bug instead of a missing secret.
|
|
1487
|
+
*
|
|
1488
|
+
* @returns a report safe to log, render and attach to a support bundle.
|
|
1489
|
+
* @public
|
|
1490
|
+
*/
|
|
1491
|
+
declare function describeCredential(input: CredentialInput): CredentialReport;
|
|
1492
|
+
|
|
1493
|
+
/**
|
|
1494
|
+
* Plugin contract — RUNTIME value + type re-exports (T1.1, ADRs D97-D101).
|
|
1495
|
+
*
|
|
1496
|
+
* SE45/SE46 — the pure `Plugin` *type* and its type companions now live in
|
|
1497
|
+
* `types/plugin.ts` (above the DIP boundary, because `Plugin` is public
|
|
1498
|
+
* contract). This module keeps the RUNTIME value (`definePlugin` /
|
|
1499
|
+
* `Plugin.create`) and re-exports the types so every existing
|
|
1500
|
+
* `../plugins/types.js` importer (and the `index.ts` barrel) resolves the same
|
|
1501
|
+
* names unchanged.
|
|
1502
|
+
*
|
|
1503
|
+
* @public
|
|
1504
|
+
*/
|
|
1505
|
+
|
|
1506
|
+
/**
|
|
1507
|
+
* Identity helper for plugin authors. TS-only convenience — preserves
|
|
1508
|
+
* inferred type without forcing manual `Plugin` annotation.
|
|
1509
|
+
*
|
|
1510
|
+
* @public
|
|
1511
|
+
*/
|
|
1512
|
+
declare function definePlugin<P extends Plugin>(p: P): P;
|
|
1513
|
+
type Plugin = Plugin$1;
|
|
1514
|
+
/** SE36 — `Plugin.create` replaces `definePlugin` (ADR 0015). Const-companion (the `Plugin` type alias blocks a class of the same name); `create` is the generic `definePlugin`. @public */
|
|
1515
|
+
declare const Plugin: {
|
|
1516
|
+
create: typeof definePlugin;
|
|
1517
|
+
};
|
|
1518
|
+
|
|
1519
|
+
/**
|
|
1520
|
+
* Options for {@link defineProvider}.
|
|
1521
|
+
*
|
|
1522
|
+
* @public
|
|
1523
|
+
*/
|
|
1524
|
+
interface DefineProviderOptions {
|
|
1525
|
+
/** Plugin version surfaced in diagnostics. Default `"1.0.0"`. */
|
|
1526
|
+
version?: string;
|
|
1527
|
+
}
|
|
1528
|
+
/** SE36 — uniform namespace API. `Provider.create` replaces `defineProvider` (ADR 0015). @public */
|
|
1529
|
+
declare class Provider {
|
|
1530
|
+
private constructor();
|
|
1531
|
+
static create(profile: ProviderProfile, opts?: DefineProviderOptions): Plugin;
|
|
1532
|
+
/**
|
|
1533
|
+
* Every first-party builtin provider (anthropic, openai, openrouter, gemini, ollama, the ChatGPT/Codex
|
|
1534
|
+
* `openai-chatgpt`, …) as model-provider plugins, ready to hand to `Agent.create({ plugins })` or any
|
|
1535
|
+
* runtime that consumes model-provider plugins (e.g. the `theokit` agent server / `@theokit/agents`, whose
|
|
1536
|
+
* own model resolution does NOT share this registry). Enables a consumer to route to ANY SDK builtin —
|
|
1537
|
+
* including one added later in a single SDK file — with ZERO provider-specific code: just
|
|
1538
|
+
* `.plugins(Provider.builtins())` once, then pick a `provider/model` id. @public
|
|
1539
|
+
*/
|
|
1540
|
+
static builtins(): Plugin[];
|
|
1541
|
+
/**
|
|
1542
|
+
* The builtin serving `modelId`, or `undefined` when none does.
|
|
1543
|
+
*
|
|
1544
|
+
* The grammar of a model id — `provider/model` — now has **one** owner. M94: the consumer
|
|
1545
|
+
* redid it by hand with `modelId.slice(0, modelId.indexOf('/'))`, which on an id **without a slash** returns the
|
|
1546
|
+
* id minus its last character (`claude-opus-5` -> `claude-opus-`): it matches no provider and the
|
|
1547
|
+
* caller fell through to the default, without distinguishing that from a hit. A non-routable model was
|
|
1548
|
+
* indistinguishable from the happy path.
|
|
1549
|
+
*
|
|
1550
|
+
* Returns `undefined` instead of throwing: the caller decides whether absence is an error, and only they
|
|
1551
|
+
* know whether the model came from an explicit `--model` (an error) or from the default (normal).
|
|
1552
|
+
*
|
|
1553
|
+
* @public
|
|
1554
|
+
*/
|
|
1555
|
+
static forModel(modelId: string): Plugin | undefined;
|
|
1556
|
+
}
|
|
1557
|
+
|
|
1558
|
+
/**
|
|
1559
|
+
* SE23 — `defineSkillReadTool`: an OPT-IN factory that gives the MODEL on-demand
|
|
1560
|
+
* access to a skill's full body + references via a `skill_read` tool.
|
|
1561
|
+
*
|
|
1562
|
+
* TheoKit discloses skills eagerly through the `<skills>` system-prompt block
|
|
1563
|
+
* (name + description only). This factory is the LAZY read path: the consumer
|
|
1564
|
+
* explicitly adds the returned {@link CustomTool} to `tools`, and when the model
|
|
1565
|
+
* calls it with a skill name, it gets that skill's `instructions` (+ SE21
|
|
1566
|
+
* `references`). The SDK NEVER auto-injects it — bring-your-own-tools stays
|
|
1567
|
+
* intact (sibling of `defineSubAgent` / `workflowAsTool`). See ADR 0007.
|
|
1568
|
+
*
|
|
1569
|
+
* import { Agent, createSkill, defineSkillReadTool } from "@theokit/sdk";
|
|
1570
|
+
*
|
|
1571
|
+
* const skills = [createSkill({ name: "release", description: "…", instructions: "…" })];
|
|
1572
|
+
* const agent = await Agent.create({
|
|
1573
|
+
* model: { id: "openai/gpt-4o-mini" },
|
|
1574
|
+
* skills: { inline: skills },
|
|
1575
|
+
* tools: [defineSkillReadTool(skills)],
|
|
1576
|
+
* });
|
|
1577
|
+
*
|
|
1578
|
+
* @public
|
|
1579
|
+
*/
|
|
1580
|
+
|
|
1581
|
+
/** SE36 — `SkillReadTool.create` replaces `defineSkillReadTool` (ADR 0015). @public *
|
|
1582
|
+
* `SkillReadTool.create` returns a **`CustomTool`** — a skill-reading tool, not a
|
|
1583
|
+
* `SkillReadTool` instance.
|
|
1584
|
+
*/
|
|
1585
|
+
declare class SkillReadTool {
|
|
1586
|
+
private constructor();
|
|
1587
|
+
static create(skills: ReadonlyArray<InlineSkill>): CustomTool;
|
|
1588
|
+
}
|
|
1589
|
+
|
|
1590
|
+
/**
|
|
1591
|
+
* Options for {@link sanitizeToolInput}. Trim is the only default-on rung — coercion and JSON
|
|
1592
|
+
* repair change a value's representation, so they are opt-in (the SDK's "values are strings; Zod
|
|
1593
|
+
* coerces" boundary; see `define-tool.ts` doc-comment).
|
|
1594
|
+
*
|
|
1595
|
+
* @public
|
|
1596
|
+
*/
|
|
1597
|
+
interface SanitizeOptions {
|
|
1598
|
+
/** Trim leading/trailing whitespace from string values. Default `true`. */
|
|
1599
|
+
trim?: boolean;
|
|
1600
|
+
/** Coerce string values to typed values (`"5"`→`5`, `"true"`→`true`, `"null"`→`null`, JSON). Default `false`. */
|
|
1601
|
+
coerce?: boolean;
|
|
1602
|
+
/** Repair-then-parse malformed JSON-looking string values (via `jsonrepair`). Default `false`. */
|
|
1603
|
+
repairJson?: boolean;
|
|
1604
|
+
/**
|
|
1605
|
+
* Optional Zod schema. When it is a `z.object(...)`, coercion is schema-aware: each TOP-LEVEL
|
|
1606
|
+
* field is coerced only toward a candidate its field-schema accepts (so a `z.string()` field
|
|
1607
|
+
* keeps `"5"` as a string). Non-object schemas (union/record) fall back to heuristic coercion.
|
|
1608
|
+
* Note: with `deep: true`, nested fields always use heuristic coercion (the schema is not
|
|
1609
|
+
* descended into).
|
|
1610
|
+
*/
|
|
1611
|
+
schema?: ZodType;
|
|
1612
|
+
/**
|
|
1613
|
+
* Recurse into nested plain objects. Default `false` (shallow).
|
|
1614
|
+
*
|
|
1615
|
+
* ARRAYS ARE NOT GATED BY THIS. Their string elements are sanitized by whichever rungs are on —
|
|
1616
|
+
* `trim` is on by default — because a value does not stop being a string by sitting in a list, and
|
|
1617
|
+
* a caller who saw `{ tag: " a " }` trimmed has no reason to expect `{ tags: [" a "] }` left
|
|
1618
|
+
* alone. What `deep` gates is descending into OBJECTS, wherever they are: at the top level, nested,
|
|
1619
|
+
* or inside an array.
|
|
1620
|
+
*/
|
|
1621
|
+
deep?: boolean;
|
|
1622
|
+
/**
|
|
1623
|
+
* Max recursion depth. Default `8`.
|
|
1624
|
+
*
|
|
1625
|
+
* Counts every hop, array or object, so a deeply nested structure cannot recurse without bound even
|
|
1626
|
+
* when `deep` is off — array descent is not gated by `deep`, and this is what bounds it.
|
|
1627
|
+
*/
|
|
1628
|
+
maxDepth?: number;
|
|
1629
|
+
}
|
|
1630
|
+
|
|
1631
|
+
/**
|
|
1632
|
+
* SE16 — the handler's return type. With no `outputSchema` the tool returns a
|
|
1633
|
+
* plain `string` (pre-SE16 shape). With an `outputSchema` the handler returns the
|
|
1634
|
+
* STRUCTURED output inferred from it (validated + serialized to the tool result).
|
|
1635
|
+
* The `[O]` tuple wrap prevents distribution so `never` maps cleanly to `string`.
|
|
1636
|
+
*/
|
|
1637
|
+
type ToolHandlerReturn<O extends ZodType> = [O] extends [never] ? string : z.infer<O>;
|
|
1638
|
+
/**
|
|
1639
|
+
* Spec accepted by {@link Tool.create}. `inputSchema` is a Zod schema; the `handler` argument type
|
|
1640
|
+
* is inferred via `z.infer<T>` — no `as` casts.
|
|
1641
|
+
*
|
|
1642
|
+
* The two optional output fields do different jobs and compose. `outputSchema` changes what the
|
|
1643
|
+
* handler must RETURN (a structured value instead of a string) and validates it; `toModelOutput`
|
|
1644
|
+
* changes only what the MODEL sees in the tool result, while observability still receives the full
|
|
1645
|
+
* handler output. Set neither and the handler returns a plain string that goes to both.
|
|
1646
|
+
*
|
|
1647
|
+
* `zod` is referenced as a type only, so a consumer that never calls `Tool.create` does not need it
|
|
1648
|
+
* installed.
|
|
1649
|
+
*
|
|
1650
|
+
* @public
|
|
1651
|
+
*/
|
|
1652
|
+
interface DefineToolSpec<T extends ZodType, O extends ZodType = never> {
|
|
1653
|
+
/** Tool name surfaced to the LLM. Same constraints as {@link CustomTool.name}. */
|
|
1654
|
+
name: string;
|
|
1655
|
+
/** Description surfaced to the LLM. */
|
|
1656
|
+
description: string;
|
|
1657
|
+
/** Zod schema describing the input. Must be `z.object(...)` at the root for the LLM tool contract. */
|
|
1658
|
+
inputSchema: T;
|
|
1659
|
+
/**
|
|
1660
|
+
* SE16 — optional Zod schema describing the OUTPUT. When set, the handler
|
|
1661
|
+
* returns the structured value inferred from it; the value is validated against
|
|
1662
|
+
* this schema and serialized to the tool result (a string stays as-is, an object
|
|
1663
|
+
* is JSON-stringified). A validation failure raises `ZodError`, converted to a
|
|
1664
|
+
* `tool_result(isError)`. Absent ⇒ the handler returns a plain string (unchanged).
|
|
1665
|
+
*/
|
|
1666
|
+
outputSchema?: O;
|
|
1667
|
+
/**
|
|
1668
|
+
* Handler invoked with the parsed input. Type is inferred via `z.infer<T>`; the
|
|
1669
|
+
* return type is `z.infer<O>` when `outputSchema` is set, else `string`.
|
|
1670
|
+
* #65 — an optional 2nd `ToolContext` argument carries the run's `AbortSignal`,
|
|
1671
|
+
* so a cooperative handler can stop early when the run is cancelled. Existing
|
|
1672
|
+
* single-argument handlers are unaffected.
|
|
1673
|
+
*/
|
|
1674
|
+
handler: (input: z.infer<T>, ctx?: {
|
|
1675
|
+
signal?: AbortSignal;
|
|
1676
|
+
context?: unknown;
|
|
1677
|
+
threadId?: string;
|
|
1678
|
+
}) => ToolHandlerReturn<O> | Promise<ToolHandlerReturn<O>>;
|
|
1679
|
+
/**
|
|
1680
|
+
* SE17 — map the handler's (validated) output to the compact / multimodal
|
|
1681
|
+
* representation the MODEL sees in the tool_result. The handler keeps returning
|
|
1682
|
+
* the FULL result (validated by `outputSchema`); `toModelOutput` shapes only what
|
|
1683
|
+
* reaches the model, so app-facing detail is not forced into model context.
|
|
1684
|
+
* Returns a string OR SE7 `ToolResultContentBlock[]` (text + image). Absent ⇒
|
|
1685
|
+
* the tool_result is the serialized handler output (SE16 / pre-SE17 behavior).
|
|
1686
|
+
* The split is REAL: the model's `tool_result` carries this compact value, while
|
|
1687
|
+
* observability (`onToolEnd.result`) receives the FULL raw handler output
|
|
1688
|
+
* (serialized) — so the app keeps the complete result. ONE handler execution
|
|
1689
|
+
* feeds both channels.
|
|
1690
|
+
*/
|
|
1691
|
+
toModelOutput?: (output: ToolHandlerReturn<O>) => string | ToolResultContentBlock[];
|
|
1692
|
+
/**
|
|
1693
|
+
* Sanitize the raw model-emitted args BEFORE schema validation (`@theokit/sdk/sanitize`).
|
|
1694
|
+
* `true` trims whitespace; an object opts into coercion / JSON-repair. Coercion is schema-aware
|
|
1695
|
+
* against this tool's `inputSchema`. Absent ⇒ args reach validation untouched. Sanitize is
|
|
1696
|
+
* hygiene, not a validity bypass — a genuinely invalid arg still raises `ZodError`.
|
|
1697
|
+
*/
|
|
1698
|
+
sanitize?: boolean | SanitizeOptions;
|
|
1699
|
+
}
|
|
1700
|
+
/**
|
|
1701
|
+
* SE36 — the uniform `X.create()` namespace API. `Tool.create(spec)` is the sole public
|
|
1702
|
+
* constructor for a {@link CustomTool}; it wraps the internal builder so behavior is identical
|
|
1703
|
+
* (ADR 0015). A `private constructor` makes `Tool` a namespace, not an instantiable value —
|
|
1704
|
+
* `new Tool()` is a compile error. Mirrors `Agent.create` / `Cron.create`.
|
|
1705
|
+
*
|
|
1706
|
+
* @public
|
|
1707
|
+
*/
|
|
1708
|
+
declare class Tool {
|
|
1709
|
+
private constructor();
|
|
1710
|
+
static create<T extends ZodType, O extends ZodType = never>(spec: DefineToolSpec<T, O>): CustomTool;
|
|
1711
|
+
}
|
|
1712
|
+
|
|
1713
|
+
/**
|
|
1714
|
+
* Audit whether every configuration key can be set from the environment, or says why not.
|
|
1715
|
+
*
|
|
1716
|
+
* A key settable only by editing a file cannot be set in CI, in a container, or for a single
|
|
1717
|
+
* invocation. That is usually an oversight rather than a decision, and it is invisible — nothing
|
|
1718
|
+
* fails, the key simply has no environment path, and nobody notices until someone needs one.
|
|
1719
|
+
*
|
|
1720
|
+
* The opposite failure rots more quietly. An opt-out written for a key that has since gained an
|
|
1721
|
+
* environment path, or for a key that no longer exists, still reads as a considered decision while
|
|
1722
|
+
* exempting nothing. Both questions are answered by one call so a consumer cannot check the gap and
|
|
1723
|
+
* forget the rot: they fail for opposite reasons, and a suite that asks only one looks complete.
|
|
1724
|
+
*
|
|
1725
|
+
* ## Why the framework owns the rule and not the keys
|
|
1726
|
+
*
|
|
1727
|
+
* A framework cannot enumerate a consumer's configuration keys, and should not try. Which keys exist
|
|
1728
|
+
* is that product's vocabulary — the same reason the security floor takes its permissiveness order
|
|
1729
|
+
* as data and the trust posture takes its capability list. So the consumer ranges over its own keys
|
|
1730
|
+
* with this, rather than registering them here.
|
|
1731
|
+
*
|
|
1732
|
+
* That is a narrower claim than "reachability is checked in the framework", and it is the honest
|
|
1733
|
+
* one: the failure still surfaces in the consumer's own suite. What the consumer no longer writes is
|
|
1734
|
+
* the detector, which is where the subtlety lives — the stale-opt-out half is the part everyone
|
|
1735
|
+
* forgets.
|
|
1736
|
+
*
|
|
1737
|
+
* @public
|
|
1738
|
+
*/
|
|
1739
|
+
/** A key deliberately left off the environment, with the reason and what would reverse it. @public */
|
|
1740
|
+
interface EnvOptOut {
|
|
1741
|
+
readonly key: string;
|
|
1742
|
+
/** Why an environment variable is the wrong shape for this key. */
|
|
1743
|
+
readonly reason: string;
|
|
1744
|
+
/** What would make this opt-out obsolete. An opt-out with no exit is a permanent excuse. */
|
|
1745
|
+
readonly exitCriterion: string;
|
|
1746
|
+
}
|
|
1747
|
+
/**
|
|
1748
|
+
* The three lists the audit compares: every key the product declares, the subset an environment
|
|
1749
|
+
* variable can set, and the documented exemptions.
|
|
1750
|
+
*
|
|
1751
|
+
* All three are matched by exact string equality, and `reachable` and `optOuts` are read as subsets
|
|
1752
|
+
* of `keys` — an entry in either that is not in `keys` is what makes an opt-out stale, and an entry
|
|
1753
|
+
* in `reachable` that is not in `keys` is simply ignored.
|
|
1754
|
+
*
|
|
1755
|
+
* @public
|
|
1756
|
+
*/
|
|
1757
|
+
interface EnvReachabilityInput {
|
|
1758
|
+
/** Every configuration key the product declares. */
|
|
1759
|
+
readonly keys: readonly string[];
|
|
1760
|
+
/** The subset that an environment variable can set. */
|
|
1761
|
+
readonly reachable: readonly string[];
|
|
1762
|
+
/** Documented exemptions for keys that deliberately have no environment path. */
|
|
1763
|
+
readonly optOuts: readonly EnvOptOut[];
|
|
1764
|
+
}
|
|
1765
|
+
/**
|
|
1766
|
+
* The two failures, reported separately because they have opposite fixes.
|
|
1767
|
+
*
|
|
1768
|
+
* A key in `unreachable` needs either an environment path or a documented opt-out. A key in
|
|
1769
|
+
* `staleOptOuts` needs its opt-out DELETED — it exempts nothing, either because the key gained an
|
|
1770
|
+
* environment path or because the key no longer exists. Both lists empty is the passing state.
|
|
1771
|
+
*
|
|
1772
|
+
* @public
|
|
1773
|
+
*/
|
|
1774
|
+
interface EnvReachabilityAudit {
|
|
1775
|
+
/** Keys with neither an environment path nor a documented opt-out. */
|
|
1776
|
+
readonly unreachable: readonly string[];
|
|
1777
|
+
/** Opt-outs that exempt nothing: the key gained an environment path, or no longer exists. */
|
|
1778
|
+
readonly staleOptOuts: readonly string[];
|
|
1779
|
+
}
|
|
1780
|
+
/**
|
|
1781
|
+
* Answer both halves of the reachability question in one call.
|
|
1782
|
+
*
|
|
1783
|
+
* A key counts as covered when it is in `reachable` OR carries an opt-out, so an opt-out silences
|
|
1784
|
+
* the gap it was written for and nothing else. Assert on both returned lists: a suite that checks
|
|
1785
|
+
* only `unreachable` still passes while the opt-outs rot, which is the half everyone forgets.
|
|
1786
|
+
*
|
|
1787
|
+
* This performs no I/O and reads no environment. The caller supplies its own key vocabulary,
|
|
1788
|
+
* because a framework cannot enumerate a consumer's configuration keys.
|
|
1789
|
+
*
|
|
1790
|
+
* @returns both axes, in the order the caller declared them — a stable order so a failure message
|
|
1791
|
+
* does not change between runs for reasons unrelated to the code.
|
|
1792
|
+
* @public
|
|
1793
|
+
*/
|
|
1794
|
+
declare function auditEnvReachability(input: EnvReachabilityInput): EnvReachabilityAudit;
|
|
1795
|
+
|
|
1796
|
+
/**
|
|
1797
|
+
* `EventBus` — typed EventEmitter wrapper.
|
|
1798
|
+
*
|
|
1799
|
+
* Provides type-safe publish/subscribe with automatic unsubscribe cleanup.
|
|
1800
|
+
* Each handler is try-caught (EC-2) so one failing handler cannot break others.
|
|
1801
|
+
*/
|
|
1802
|
+
type EventHandler<T> = (payload: T) => void;
|
|
1803
|
+
/**
|
|
1804
|
+
* A typed publish/subscribe bus, parameterised by a map of event name to payload type.
|
|
1805
|
+
*
|
|
1806
|
+
* `publish` is SYNCHRONOUS: handlers run in subscription order before it returns, so a slow handler
|
|
1807
|
+
* blocks the publisher. Each handler is invoked inside its own try/catch, so one that throws cannot
|
|
1808
|
+
* stop the others — the error is written to the diagnostics channel and counted on
|
|
1809
|
+
* `handlerErrorCount`. Assert on that counter in tests; a subscriber failing on every event is
|
|
1810
|
+
* otherwise invisible.
|
|
1811
|
+
*
|
|
1812
|
+
* `subscribe` returns the unsubscribe function, which is the only way to detach a handler — there
|
|
1813
|
+
* is no `off` taking the handler back. Handlers are held in a `Set` per event, so subscribing the
|
|
1814
|
+
* same function reference twice registers it once.
|
|
1815
|
+
*
|
|
1816
|
+
* Payload objects are passed by reference to every handler; nothing here copies them, so a handler
|
|
1817
|
+
* that mutates a payload mutates it for the handlers after it.
|
|
1818
|
+
*/
|
|
1819
|
+
declare class EventBus<Events extends Record<string, unknown>> {
|
|
1820
|
+
#private;
|
|
1821
|
+
private handlers;
|
|
1822
|
+
/** M3 #64 — number of handler invocations that threw (and were logged). */
|
|
1823
|
+
get handlerErrorCount(): number;
|
|
1824
|
+
/**
|
|
1825
|
+
* Subscribe to an event. Returns an unsubscribe function.
|
|
1826
|
+
*/
|
|
1827
|
+
subscribe<K extends keyof Events>(event: K, handler: EventHandler<Events[K]>): () => void;
|
|
1828
|
+
/**
|
|
1829
|
+
* Publish an event to all subscribers. EC-2: try-catch per handler.
|
|
1830
|
+
*/
|
|
1831
|
+
publish<K extends keyof Events>(event: K, payload: Events[K]): void;
|
|
1832
|
+
/**
|
|
1833
|
+
* Subscribe to an event for a single firing. Returns an unsubscribe function.
|
|
1834
|
+
*/
|
|
1835
|
+
once<K extends keyof Events>(event: K, handler: EventHandler<Events[K]>): () => void;
|
|
1836
|
+
}
|
|
1837
|
+
|
|
1838
|
+
/** Inputs to the judge — pure data. */
|
|
1839
|
+
interface JudgeContext {
|
|
1840
|
+
goal: string;
|
|
1841
|
+
lastResponse: string;
|
|
1842
|
+
subgoals?: string[];
|
|
1843
|
+
}
|
|
1844
|
+
/** Caller-supplied tuning knobs for the judge call. */
|
|
1845
|
+
interface JudgeOptions {
|
|
1846
|
+
/**
|
|
1847
|
+
* Judge model identifier. When absent, it DERIVES from {@link agentModel} — and only falls back to the literal
|
|
1848
|
+
* `"openai/gpt-4o-mini"` when neither is provided.
|
|
1849
|
+
*
|
|
1850
|
+
* M80 — the fixed default was provider-blind: it only resolves on OpenRouter. With an Anthropic key it gives
|
|
1851
|
+
* 404, with an OAuth bearer it gives 401, and in both the goal burned 3 whole turns before failing with
|
|
1852
|
+
* a misleading reason. The agent-builder already worked around this by deriving on its own; the knowledge
|
|
1853
|
+
* belongs here.
|
|
1854
|
+
*/
|
|
1855
|
+
judgeModel?: string;
|
|
1856
|
+
/**
|
|
1857
|
+
* M80 — the DRIVEN agent's model. It is the basis of the derivation: a judge running on the same model as the
|
|
1858
|
+
* chat works wherever chat works.
|
|
1859
|
+
*/
|
|
1860
|
+
agentModel?: string;
|
|
1861
|
+
/** Override env. Default `process.env.OPENROUTER_API_KEY` (EC-A). */
|
|
1862
|
+
apiKey?: string;
|
|
1863
|
+
}
|
|
1864
|
+
/**
|
|
1865
|
+
* M80 — the judge's credential or model does not work: 401/404.
|
|
1866
|
+
*
|
|
1867
|
+
* Fails FAST by design. `rules/error-handling.md` § 2 separates recoverable from unrecoverable, and a
|
|
1868
|
+
* nonexistent model does not start existing on retry — folding that into `{parseFailed: true}` made the loop
|
|
1869
|
+
* try three times and report "failed" on a consecutive-failure limit, hiding that the cause was the
|
|
1870
|
+
* credential. A slow, opaque failure traded for a fast, clear one.
|
|
1871
|
+
*
|
|
1872
|
+
* PARSE failures and network errors stay folded: they are recoverable, and the loop already decides on
|
|
1873
|
+
* in a row.
|
|
1874
|
+
*/
|
|
1875
|
+
declare class JudgeCredentialError extends TheokitAgentError {
|
|
1876
|
+
readonly httpStatus: number;
|
|
1877
|
+
readonly judgeModel: string;
|
|
1878
|
+
readonly name = "JudgeCredentialError";
|
|
1879
|
+
constructor(httpStatus: number, judgeModel: string, cause: unknown);
|
|
1880
|
+
}
|
|
1881
|
+
|
|
1882
|
+
/**
|
|
1883
|
+
* Goal-driven Ralph loop (T3.2, ADRs D115-D121).
|
|
1884
|
+
*
|
|
1885
|
+
* `runUntilImpl` is an `AsyncGenerator<GoalEvent, GoalResult, void>`:
|
|
1886
|
+
* yields events as the loop progresses, returns the final result when
|
|
1887
|
+
* the goal completes, fails, or is paused. The auxiliary judge model is
|
|
1888
|
+
* injected via `deps.judge` so the generator stays free of the `Agent`
|
|
1889
|
+
* façade import.
|
|
1890
|
+
*
|
|
1891
|
+
* EC-C fix: pre-aborted signals emit only `[paused]`, not `[active, paused]`.
|
|
1892
|
+
* EC-D: `maxTurns: 0` is supported (vacuous yield active → failed).
|
|
1893
|
+
*
|
|
1894
|
+
* @internal
|
|
1895
|
+
*/
|
|
1896
|
+
|
|
1897
|
+
/** DI contract: the judge is the only external touchpoint. */
|
|
1898
|
+
interface RunUntilDeps {
|
|
1899
|
+
judge: (ctx: JudgeContext, opts?: JudgeOptions) => Promise<JudgeResult>;
|
|
1900
|
+
}
|
|
1901
|
+
|
|
1902
|
+
/**
|
|
1903
|
+
* The goal-loop's continuation marker — in a LEAF module, on purpose.
|
|
1904
|
+
*
|
|
1905
|
+
* It lived in `goal-loop.ts` and was imported by `run-until.ts`, which `goal-loop` in turn
|
|
1906
|
+
* imports back. The cycle was broken at runtime (the return edge is `import type` + a dynamic
|
|
1907
|
+
* `await import()`), but the cycle detector counts the dynamic edge — and counting a dynamic import as a cycle
|
|
1908
|
+
* makes the gate impossible to satisfy without abandoning the canonical cycle-breaking technique.
|
|
1909
|
+
*
|
|
1910
|
+
* A constant shared by two modules that know each other is the textbook case for extraction into a
|
|
1911
|
+
* leaf: neither needs to import the other to know it. The cycle disappears under ANY detector, with no
|
|
1912
|
+
* tool policy and without changing a line of behavior.
|
|
1913
|
+
*/
|
|
1914
|
+
declare const GOAL_CONTINUATION_MARKER = "[[theokit:goal-continuation]]";
|
|
1915
|
+
|
|
1916
|
+
/**
|
|
1917
|
+
* M56 (agent-builder goal transparency) — PUBLIC goal-loop driver for CUSTOM agent surfaces.
|
|
1918
|
+
*
|
|
1919
|
+
* `LocalAgent.runUntil` binds the goal loop to a registered local agent. Surfaces that route turns
|
|
1920
|
+
* through their OWN transport (e.g. a TUI store facade, so every goal turn renders in the same
|
|
1921
|
+
* timeline as a manual turn) need the SAME loop over a minimal `send → wait` shape. This export
|
|
1922
|
+
* gives them exactly that: the canonical `runUntilImpl` (judge + continuation + token budget +
|
|
1923
|
+
* Codex states) with the default judge wired from the DI registry.
|
|
1924
|
+
*
|
|
1925
|
+
* @public
|
|
1926
|
+
*/
|
|
1927
|
+
|
|
1928
|
+
/** The minimal surface the goal loop drives — anything that can send a prompt and wait for it. */
|
|
1929
|
+
interface GoalLoopAgent {
|
|
1930
|
+
send(prompt: string): Promise<{
|
|
1931
|
+
wait(): Promise<{
|
|
1932
|
+
result?: string;
|
|
1933
|
+
usage?: {
|
|
1934
|
+
totalTokens?: number;
|
|
1935
|
+
};
|
|
1936
|
+
}>;
|
|
1937
|
+
}>;
|
|
1938
|
+
}
|
|
1939
|
+
/**
|
|
1940
|
+
* Run the goal-driven loop (`send → judge → continuation`) over ANY `send → wait` surface.
|
|
1941
|
+
* Identical semantics to `Agent.runUntil` (ADRs D115-D121 + M55 token budget / states).
|
|
1942
|
+
* `depsOverride` is a test seam for injecting a fake judge.
|
|
1943
|
+
*/
|
|
1944
|
+
declare function runGoalLoop(agent: GoalLoopAgent, goal: string, options?: GoalOptions, depsOverride?: RunUntilDeps): AsyncGenerator<GoalEvent, GoalResult, void>;
|
|
1945
|
+
|
|
1946
|
+
/**
|
|
1947
|
+
* Reference `BudgetTracker` impl — pure token + iteration counter
|
|
1948
|
+
* (SDK 2.0 Phase 2 / T2.1 — ADR D1 reference implementation).
|
|
1949
|
+
*
|
|
1950
|
+
* Counts tokens per type (input/output) + iteration count. Enforces
|
|
1951
|
+
* optional `maxTokens` / `maxIterations` ceilings via `check()`.
|
|
1952
|
+
*
|
|
1953
|
+
* Does NOT compute USD cost — leaves that to richer impls in
|
|
1954
|
+
* `@theokit/sdk-budget` (post-Phase-2). This file is intentionally
|
|
1955
|
+
* minimal so consumers can:
|
|
1956
|
+
* - use it as-is for simple guard-rails;
|
|
1957
|
+
* - read it as a worked example before authoring a custom tracker;
|
|
1958
|
+
* - rely on it as a fallback before sdk-budget ships.
|
|
1959
|
+
*
|
|
1960
|
+
* @public — surface-level reference impl.
|
|
1961
|
+
*/
|
|
1962
|
+
|
|
1963
|
+
/** Options for `createCounterBudgetTracker`. */
|
|
1964
|
+
interface CounterBudgetTrackerOptions {
|
|
1965
|
+
/** Hard ceiling on total tokens (input + output). When reached, `check()` returns `allowed: false`. */
|
|
1966
|
+
readonly maxTokens?: number;
|
|
1967
|
+
/** Hard ceiling on iterations counted by `nextIteration()`. */
|
|
1968
|
+
readonly maxIterations?: number;
|
|
1969
|
+
}
|
|
1970
|
+
/**
|
|
1971
|
+
* Build a fresh tracker. The returned object is independent — call
|
|
1972
|
+
* `createCounterBudgetTracker()` per Agent instance.
|
|
1973
|
+
*
|
|
1974
|
+
* The tracker exposes the `BudgetTracker` contract PLUS a `nextIteration()`
|
|
1975
|
+
* helper for impls that want explicit iteration counting (the agent loop
|
|
1976
|
+
* calls it once per turn). Without `nextIteration()` calls, the iteration
|
|
1977
|
+
* cap is never reached.
|
|
1978
|
+
*/
|
|
1979
|
+
declare function createCounterBudgetTracker(options?: CounterBudgetTrackerOptions): BudgetTracker & {
|
|
1980
|
+
nextIteration(): void;
|
|
1981
|
+
};
|
|
1982
|
+
|
|
1983
|
+
/**
|
|
1984
|
+
* The library's single diagnostics channel — silent by default (#147).
|
|
1985
|
+
*
|
|
1986
|
+
* ## The problem
|
|
1987
|
+
*
|
|
1988
|
+
* The SDK wrote diagnostics straight to `process.stderr` from hot paths — 92 sites across 51
|
|
1989
|
+
* files under `internal/`. In a TUI host (Ink, alternate screen), those writes interleave with the
|
|
1990
|
+
* render and **corrupt the frame**. And the host had no way to intercept them: there was no
|
|
1991
|
+
* injectable logger. One consumer went as far as installing `proper-lockfile` just to silence ONE
|
|
1992
|
+
* of them.
|
|
1993
|
+
*
|
|
1994
|
+
* A library cannot assume `stdout`/`stderr` are free sinks. The application owns the terminal, not
|
|
1995
|
+
* the dependency.
|
|
1996
|
+
*
|
|
1997
|
+
* ## The contract
|
|
1998
|
+
*
|
|
1999
|
+
* - **`setDiagnosticsSink(fn)`** hands the messages to the application, which decides where to put
|
|
2000
|
+
* them (a status line, a file, a panel). It is what was missing for a TUI to coexist with the SDK.
|
|
2001
|
+
* - **With no sink, nothing is emitted.** A library does not own the host's terminal.
|
|
2002
|
+
*
|
|
2003
|
+
* ## Silent by default, and how 36 suites survived the flip
|
|
2004
|
+
*
|
|
2005
|
+
* The default WAS `stderr`, and 36 test files spy on `process.stderr.write` to assert a given
|
|
2006
|
+
* warning is emitted. That contract is real and had to survive; migrating all 36 by hand, across
|
|
2007
|
+
* four different spy styles, is how you weaken 36 suites in one commit.
|
|
2008
|
+
*
|
|
2009
|
+
* So the flip happened at the default, and `vitest.setup.ts` installs a sink that FORWARDS to
|
|
2010
|
+
* `stderr` for the duration of every test. Those assertions still test what they always tested —
|
|
2011
|
+
* "this condition emits a diagnostic" — through the channel a host would use, while production
|
|
2012
|
+
* emits nothing unless asked.
|
|
2013
|
+
*
|
|
2014
|
+
* The cost is stated rather than hidden: no test observes the production default by accident, so
|
|
2015
|
+
* `tests/diagnostics-public-entry.test.ts` pins it explicitly by clearing the sink first.
|
|
2016
|
+
*
|
|
2017
|
+
* ## Coverage is the whole guarantee
|
|
2018
|
+
*
|
|
2019
|
+
* The first sweep migrated the 92 sites under `internal/` and left `src/`'s own modules —
|
|
2020
|
+
* `event-bus.ts`, `batch.ts`, `compaction.ts`, `internal/workflow/step-branch.ts`. A host could
|
|
2021
|
+
* therefore install a sink and still have its frame corrupted by a batch run, which is the reported
|
|
2022
|
+
* defect with a smaller blast radius. Those are routed here too, and
|
|
2023
|
+
* `tests/lint/no-direct-terminal-write.test.ts` is what keeps the next hot path from
|
|
2024
|
+
* reintroducing one. "Mostly interceptable" is not interceptable.
|
|
2025
|
+
*
|
|
2026
|
+
* The remaining direct writers are allowlisted there with a reason, and every one of them is a seam
|
|
2027
|
+
* whose destination the CALLER already chooses (`opts.warn`, `opts.logger`, the Workflow logger).
|
|
2028
|
+
*
|
|
2029
|
+
* ## What this is NOT
|
|
2030
|
+
*
|
|
2031
|
+
* It is not a logger with levels, formatting or multiple destinations. It is the minimum that
|
|
2032
|
+
* resolves the reported blocker; a full logger here would be inventing a requirement nobody asked
|
|
2033
|
+
* for.
|
|
2034
|
+
*/
|
|
2035
|
+
/** Receives each diagnostic message already formatted, with the trailing `\n`. */
|
|
2036
|
+
type DiagnosticsSink = (message: string) => void;
|
|
2037
|
+
/**
|
|
2038
|
+
* Installs (or removes, by passing `undefined`) the diagnostics destination.
|
|
2039
|
+
*
|
|
2040
|
+
* When a sink is present it is the ONLY destination — `stderr` gets no copy. Duplicating
|
|
2041
|
+
* destinations would hand the problem back to the TUI that installed the sink precisely to get the
|
|
2042
|
+
* messages out of the terminal.
|
|
2043
|
+
*/
|
|
2044
|
+
declare function setDiagnosticsSink(next: DiagnosticsSink | undefined): void;
|
|
2045
|
+
|
|
2046
|
+
/**
|
|
2047
|
+
* The fail-safe emitter for the `RunEvent` stream — runtime, deliberately NOT in `types/`.
|
|
2048
|
+
*
|
|
2049
|
+
* Eleven modules across `agent-loop/`, `runtime/`, `task/` and `local-agent/` call it; the type it
|
|
2050
|
+
* carries stays in `types/run-events.ts`, which is what `types/` is for. Sibling of
|
|
2051
|
+
* `internal/diagnostics.ts`, which swallows sink failures on the same principle and for the same
|
|
2052
|
+
* reason: observability degrades what you can SEE, never what the agent DOES.
|
|
2053
|
+
*
|
|
2054
|
+
* @internal
|
|
2055
|
+
*/
|
|
2056
|
+
/**
|
|
2057
|
+
* SE2 — emit a {@link RunEvent} to an optional sink, swallowing any sink error so
|
|
2058
|
+
* observability can never break the run (fail-safe, mirrors the EventBus EC-2
|
|
2059
|
+
* contract). No-op when the sink is absent.
|
|
2060
|
+
*/
|
|
2061
|
+
declare function emitRunEvent(sink: RunEventSink$1 | undefined, event: RunEvent): void;
|
|
2062
|
+
|
|
2063
|
+
/**
|
|
2064
|
+
* Run `fn` after every earlier `withCwdMutex` call for the same `key` has settled, and return
|
|
2065
|
+
* what `fn` returns.
|
|
2066
|
+
*
|
|
2067
|
+
* Calls with the same key run strictly in the order they were made — FIFO, never concurrent.
|
|
2068
|
+
* Calls with different keys never wait on each other. The key is an opaque string: two callers
|
|
2069
|
+
* serialize against each other exactly when they pass equal keys, so a shared key IS the
|
|
2070
|
+
* contract, and a mismatched one silently buys no protection at all.
|
|
2071
|
+
*
|
|
2072
|
+
* A rejection does not poison the queue. The next waiter runs whether the previous `fn` fulfilled
|
|
2073
|
+
* or rejected, and the rejection is delivered only to the caller whose `fn` threw. This function
|
|
2074
|
+
* neither retries nor swallows: the returned promise rejects with whatever `fn` rejected with.
|
|
2075
|
+
*
|
|
2076
|
+
* There is no timeout and no cancellation. An `fn` that never settles blocks that key for the
|
|
2077
|
+
* lifetime of the process.
|
|
2078
|
+
*
|
|
2079
|
+
* **Scope — this is an in-process lock only.** State is a module-scoped Map, so it serializes
|
|
2080
|
+
* callers that share one module instance and nothing else. Two processes, two worker threads, or
|
|
2081
|
+
* two copies of the SDK resolved into the same tree do not see each other's queue. When the
|
|
2082
|
+
* resource is a file that other processes can also write, use `withFileLock` from
|
|
2083
|
+
* `./file-lock.ts` instead — it takes an OS-level lock and layers this mutex underneath, so it
|
|
2084
|
+
* gives both guarantees. Reach for `withCwdMutex` directly when the shared state is in memory, or
|
|
2085
|
+
* when the file is one only this process touches.
|
|
2086
|
+
*
|
|
2087
|
+
* Extracted packages (`@theokit/sdk-budget`, `@theokit/sdk-memory`) import this from
|
|
2088
|
+
* `@theokit/sdk` rather than reimplementing it, precisely so the Map is the same one: a per-package
|
|
2089
|
+
* copy would give each package its own queue and let their writes race.
|
|
2090
|
+
*
|
|
2091
|
+
* The Map is module-scoped, so nothing survives a process restart or a fresh module instance, and
|
|
2092
|
+
* its entries are never removed — pass keys from a bounded set rather than from arbitrary input.
|
|
2093
|
+
* Signature and semantics will not change before sdk-core v3.0.
|
|
2094
|
+
*
|
|
2095
|
+
* @public
|
|
2096
|
+
*/
|
|
2097
|
+
declare function withCwdMutex<T>(key: string, fn: () => Promise<T>): Promise<T>;
|
|
2098
|
+
|
|
2099
|
+
/**
|
|
2100
|
+
* Reference `MemoryProvider` impl — no-op fallback (SDK 2.0 Phase 1 /
|
|
2101
|
+
* T1.2 reference implementation, mirrors `createCounterBudgetTracker`).
|
|
2102
|
+
*
|
|
2103
|
+
* Every method is a degenerate identity:
|
|
2104
|
+
* - `init()` returns a handle wrapping a no-op `MemoryAdapter`.
|
|
2105
|
+
* - `buildTools()` returns `[]` (no memory tools surfaced to the LLM).
|
|
2106
|
+
* - `runActivePass()` returns `{ facts: [] }` (no recall fires).
|
|
2107
|
+
* - `dispose()` is a no-op.
|
|
2108
|
+
*
|
|
2109
|
+
* Why ship this:
|
|
2110
|
+
* - Default safety net before `@theokit/sdk-memory` is installed.
|
|
2111
|
+
* - Worked reference for authors of custom providers.
|
|
2112
|
+
* - Enables `Agent.create({ memoryProvider: createNoopMemoryProvider() })`
|
|
2113
|
+
* unit tests without pulling memory infrastructure.
|
|
2114
|
+
*
|
|
2115
|
+
* NOT a substitute for the existing `Memory` class — the legacy class
|
|
2116
|
+
* stays authoritative until the subsystem fully ports to providers
|
|
2117
|
+
* (Phase 1 / T1.6).
|
|
2118
|
+
*
|
|
2119
|
+
* @public — surface-level reference impl.
|
|
2120
|
+
*/
|
|
2121
|
+
|
|
2122
|
+
/** SE36 — `NoopMemoryProvider.create` replaces `createNoopMemoryProvider` (ADR 0015). @public */
|
|
2123
|
+
declare class NoopMemoryProvider {
|
|
2124
|
+
private constructor();
|
|
2125
|
+
static create(): MemoryProvider;
|
|
2126
|
+
}
|
|
2127
|
+
|
|
2128
|
+
/**
|
|
2129
|
+
* Task-id grammar (D368) — runtime, deliberately NOT in `types/`.
|
|
2130
|
+
*
|
|
2131
|
+
* It lived in `types/task.ts`, which `types/index.ts` re-exports with `export type *`. That star
|
|
2132
|
+
* cannot carry a value, so the only reason `isValidTaskId` ever reached a consumer is that the DTS
|
|
2133
|
+
* rollup hoists the declaration while the runtime bundle emits nothing — exactly the shape of #279,
|
|
2134
|
+
* where the import typechecked and was `undefined` at the call site. `src/index.ts` re-exports both
|
|
2135
|
+
* names from here, so the public API is unchanged.
|
|
2136
|
+
*
|
|
2137
|
+
* @internal
|
|
2138
|
+
*/
|
|
2139
|
+
/**
|
|
2140
|
+
* Validates a task ID against the public grammar + reserved prefixes.
|
|
2141
|
+
* Throws `InvalidTaskIdError` from `../errors.js` on rejection.
|
|
2142
|
+
*
|
|
2143
|
+
* Adapter callers (workflow/batch/cron) MUST set `allowReserved: true`
|
|
2144
|
+
* to register their own IDs; user-facing surfaces (`Task.submit`,
|
|
2145
|
+
* `agent.send({ task: { id } })`) leave it false.
|
|
2146
|
+
*/
|
|
2147
|
+
declare function isValidTaskId(id: string, allowReserved: boolean): boolean;
|
|
2148
|
+
/** Re-exported for adapter implementations + tests. */
|
|
2149
|
+
declare const TASK_RESERVED_PREFIXES: readonly string[];
|
|
2150
|
+
|
|
2151
|
+
/**
|
|
2152
|
+
* The subset of the OpenTelemetry `Span` API this SDK calls.
|
|
2153
|
+
*
|
|
2154
|
+
* Structural, not nominal: a real `@opentelemetry/api` span satisfies it, and so does a test double
|
|
2155
|
+
* or a no-op. That is why it is exported — `@theokit/sdk-memory` previously kept a hand-written
|
|
2156
|
+
* mirror of this shape, and the two had already drifted (the mirror rejected `undefined` attribute
|
|
2157
|
+
* values this one accepts, and declared `end()` without its `endTime` parameter). Import this
|
|
2158
|
+
* instead of re-declaring it.
|
|
2159
|
+
*
|
|
2160
|
+
* Erased at build time, so importing it adds nothing to a bundle and does not require
|
|
2161
|
+
* `@opentelemetry/api` to be installed.
|
|
2162
|
+
*
|
|
2163
|
+
* @public
|
|
2164
|
+
*/
|
|
2165
|
+
interface OTelSpan {
|
|
2166
|
+
setAttribute(key: string, value: string | number | boolean): void;
|
|
2167
|
+
setAttributes(attrs: Record<string, string | number | boolean | undefined>): void;
|
|
2168
|
+
addEvent(name: string, attrs?: Record<string, string | number | boolean>): void;
|
|
2169
|
+
setStatus(status: {
|
|
2170
|
+
code: number;
|
|
2171
|
+
message?: string;
|
|
2172
|
+
}): void;
|
|
2173
|
+
recordException(err: unknown): void;
|
|
2174
|
+
end(endTime?: number): void;
|
|
2175
|
+
spanContext(): {
|
|
2176
|
+
traceId: string;
|
|
2177
|
+
spanId: string;
|
|
2178
|
+
};
|
|
2179
|
+
isRecording(): boolean;
|
|
2180
|
+
}
|
|
2181
|
+
/**
|
|
2182
|
+
* Telemetry handle returned by {@link createTelemetry}. Callers use this to
|
|
2183
|
+
* start spans, add events, etc. When telemetry is disabled OR OTel is not
|
|
2184
|
+
* installed, every method is a safe no-op.
|
|
2185
|
+
*
|
|
2186
|
+
*/
|
|
2187
|
+
interface TelemetryHandle {
|
|
2188
|
+
readonly enabled: boolean;
|
|
2189
|
+
readonly includeContent: boolean;
|
|
2190
|
+
/** Start a span. Returns a no-op span if telemetry is disabled. */
|
|
2191
|
+
startSpan(name: string, attrs?: Record<string, string | number | boolean>): OTelSpan;
|
|
2192
|
+
/** Start a child span nested under `parent` (M3 #64). `undefined` parent →
|
|
2193
|
+
* a root span (parentless callers, or telemetry with no run span). */
|
|
2194
|
+
startChildSpan(parent: OTelSpan | undefined, name: string, attrs?: Record<string, string | number | boolean>): OTelSpan;
|
|
2195
|
+
/**
|
|
2196
|
+
* Record a histogram observation. T0.1 ships
|
|
2197
|
+
* `theokit_memory_recall_duration_ms`; downstream tasks add more.
|
|
2198
|
+
* No-op when telemetry is disabled or when `@opentelemetry/api`'s metrics
|
|
2199
|
+
* namespace is unavailable. ADR D34 — exporter errors are swallowed by `safe()`.
|
|
2200
|
+
*/
|
|
2201
|
+
recordHistogram(name: string, valueMs: number, attrs?: Record<string, string | number | boolean>): void;
|
|
2202
|
+
/** End all open spans on this handle (best-effort, used by Agent.dispose). */
|
|
2203
|
+
endAll(): void;
|
|
2204
|
+
}
|
|
2205
|
+
|
|
2206
|
+
/**
|
|
2207
|
+
* `JobQueue` — background job queue with status tracking, cancellation, and an
|
|
2208
|
+
* optional concurrency bound.
|
|
2209
|
+
*
|
|
2210
|
+
* EC-1: all enqueued functions are wrapped in Promise.resolve().then() so
|
|
2211
|
+
* synchronous throws become rejections.
|
|
2212
|
+
*
|
|
2213
|
+
* #58: each job runs under an `AbortController` whose signal is passed to the
|
|
2214
|
+
* job fn, so `cancel()` actually interrupts a running job (not just a status
|
|
2215
|
+
* flip); an optional `maxConcurrency` bounds how many jobs run at once.
|
|
2216
|
+
*/
|
|
2217
|
+
type JobStatus = "pending" | "running" | "completed" | "failed" | "cancelled";
|
|
2218
|
+
interface Job<T> {
|
|
2219
|
+
id: string;
|
|
2220
|
+
status: JobStatus;
|
|
2221
|
+
result?: T;
|
|
2222
|
+
error?: string;
|
|
2223
|
+
}
|
|
2224
|
+
/** #58 — construction options. */
|
|
2225
|
+
interface JobQueueOptions {
|
|
2226
|
+
/**
|
|
2227
|
+
* Max jobs running concurrently. Omit for unbounded (previous behavior).
|
|
2228
|
+
* Values < 1 are clamped to 1 (an invalid bound must not deadlock).
|
|
2229
|
+
*/
|
|
2230
|
+
maxConcurrency?: number;
|
|
2231
|
+
}
|
|
2232
|
+
/**
|
|
2233
|
+
* An in-process queue of background jobs with status tracking, cancellation, and an optional
|
|
2234
|
+
* concurrency bound.
|
|
2235
|
+
*
|
|
2236
|
+
* `enqueue` returns a job id immediately and never throws for the job's own failure: a synchronous
|
|
2237
|
+
* throw inside the function becomes a rejection, and a rejection becomes `status: "failed"` with
|
|
2238
|
+
* the message on `job.error`. Poll `getJob(id)` or `list()` for outcomes — there is no completion
|
|
2239
|
+
* event and no promise to await.
|
|
2240
|
+
*
|
|
2241
|
+
* Cancellation is COOPERATIVE. `cancel` aborts the `AbortSignal` handed to the job function and
|
|
2242
|
+
* flips the status, but a function that ignores the signal keeps running to completion; its result
|
|
2243
|
+
* is then discarded, because a cancelled job never leaves the cancelled state. The concurrency slot
|
|
2244
|
+
* of a running job is freed at cancel time rather than when it eventually settles, so a job that
|
|
2245
|
+
* never settles cannot deadlock a bounded queue.
|
|
2246
|
+
*
|
|
2247
|
+
* State lives entirely in memory and grows without bound — nothing evicts finished jobs. This is a
|
|
2248
|
+
* queue for one process, not a durable one.
|
|
2249
|
+
*/
|
|
2250
|
+
declare class JobQueue {
|
|
2251
|
+
#private;
|
|
2252
|
+
private jobs;
|
|
2253
|
+
private controllers;
|
|
2254
|
+
private readonly maxConcurrency;
|
|
2255
|
+
private running;
|
|
2256
|
+
private readonly waiting;
|
|
2257
|
+
constructor(options?: JobQueueOptions);
|
|
2258
|
+
/**
|
|
2259
|
+
* Enqueue a background function. Returns the job ID immediately. The function
|
|
2260
|
+
* receives an `AbortSignal` that fires when the job is cancelled (#58) — a
|
|
2261
|
+
* cooperative job should observe it to stop early. Existing `() => Promise<T>`
|
|
2262
|
+
* callers are unaffected (the signal argument is simply ignored).
|
|
2263
|
+
*/
|
|
2264
|
+
enqueue<T>(fn: (signal: AbortSignal) => Promise<T>): string;
|
|
2265
|
+
getJob(id: string): Job<unknown> | undefined;
|
|
2266
|
+
list(): Job<unknown>[];
|
|
2267
|
+
/**
|
|
2268
|
+
* Cancel a pending or running job. Returns true if cancelled. #58 — aborts the
|
|
2269
|
+
* job's `AbortSignal` so a cooperative running job is actually interrupted.
|
|
2270
|
+
*/
|
|
2271
|
+
cancel(id: string): boolean;
|
|
2272
|
+
}
|
|
2273
|
+
|
|
2274
|
+
/**
|
|
2275
|
+
* Fold configuration layers in a declared order — later layers win, named keys accumulate.
|
|
2276
|
+
*
|
|
2277
|
+
* Every product that reads configuration from more than one place rebuilds these two rules, and the
|
|
2278
|
+
* second one is not a nicety. With plain last-wins, a project file DISPLACES the user's entries for
|
|
2279
|
+
* a list-valued key rather than adding to them — and for a key like `hooks`, which carries arbitrary
|
|
2280
|
+
* command execution, that is the difference between a repository adding a hook and a repository
|
|
2281
|
+
* removing yours.
|
|
2282
|
+
*
|
|
2283
|
+
* The layer NAMES are the caller's, supplied as data. One product's chain is
|
|
2284
|
+
* defaults/user/project/profile/env/cli; `profile` is that product's idea and does not belong here.
|
|
2285
|
+
* That is the same test the security floor passed: a vocabulary expressible as data generalises, an
|
|
2286
|
+
* open-ended interface shaped by one product does not.
|
|
2287
|
+
*
|
|
2288
|
+
* @public
|
|
2289
|
+
*/
|
|
2290
|
+
|
|
2291
|
+
/** Raised when a declared layer chain is not strictly ascending. @public */
|
|
2292
|
+
declare class LayerOrderError extends TheokitAgentError {
|
|
2293
|
+
readonly name = "LayerOrderError";
|
|
2294
|
+
}
|
|
2295
|
+
/**
|
|
2296
|
+
* One named layer in a precedence chain.
|
|
2297
|
+
*
|
|
2298
|
+
* `precedence` is optional and the two usages do not mix well: omit it everywhere to say "this
|
|
2299
|
+
* array is already in order", or supply it everywhere you want `verifyLayerOrdering` to check.
|
|
2300
|
+
* Entries without it are SKIPPED by that check rather than treated as zero, so a chain where only
|
|
2301
|
+
* some entries declare a number is verified only between those.
|
|
2302
|
+
*
|
|
2303
|
+
* @public
|
|
2304
|
+
*/
|
|
2305
|
+
interface DeclaredLayer {
|
|
2306
|
+
readonly layer: string;
|
|
2307
|
+
/** Higher wins. Optional — omit it to mean "this array is already the order". */
|
|
2308
|
+
readonly precedence?: number;
|
|
2309
|
+
}
|
|
2310
|
+
/**
|
|
2311
|
+
* A declared layer together with the values it supplies.
|
|
2312
|
+
*
|
|
2313
|
+
* `foldLayers` consumes these in array order, so a later entry wins for the keys it mentions. A key
|
|
2314
|
+
* a layer does not mention — or mentions with `undefined` — leaves the earlier value standing;
|
|
2315
|
+
* there is no way for a layer to erase a key another layer set.
|
|
2316
|
+
*
|
|
2317
|
+
* @public
|
|
2318
|
+
*/
|
|
2319
|
+
interface LayerValues extends DeclaredLayer {
|
|
2320
|
+
readonly values: Readonly<Record<string, unknown>>;
|
|
2321
|
+
}
|
|
2322
|
+
/**
|
|
2323
|
+
* Assert that each layer strictly outranks the one before it.
|
|
2324
|
+
*
|
|
2325
|
+
* Entries without a `precedence` are skipped rather than treated as zero: omitting it means the
|
|
2326
|
+
* caller is expressing order by position, and inventing a number for them would manufacture a
|
|
2327
|
+
* conflict out of a legitimate usage.
|
|
2328
|
+
*
|
|
2329
|
+
* @throws LayerOrderError naming both layers and both precedences — a refusal that only says "out
|
|
2330
|
+
* of order" sends the reader to compare the whole list by hand.
|
|
2331
|
+
* @public
|
|
2332
|
+
*/
|
|
2333
|
+
declare function verifyLayerOrdering(layers: readonly DeclaredLayer[]): void;
|
|
2334
|
+
/**
|
|
2335
|
+
* Combine `entries` into one record.
|
|
2336
|
+
*
|
|
2337
|
+
* Later entries win. A value of `undefined` never overwrites — a layer that does not mention a key
|
|
2338
|
+
* must not erase it, because "said nothing" is overwhelmingly more common than "said nothing on
|
|
2339
|
+
* purpose".
|
|
2340
|
+
*
|
|
2341
|
+
* Keys in `accumulatingKeys` whose value is an array are CONCATENATED across layers instead of
|
|
2342
|
+
* replaced. A non-array value for such a key replaces, deliberately: a malformed config must not
|
|
2343
|
+
* corrupt the accumulator into a mixed list, and leaving the raw value visible lets the consumer's
|
|
2344
|
+
* own validation reject it with its own message.
|
|
2345
|
+
*
|
|
2346
|
+
* The accumulator is per-call and the inputs are never mutated, so folding twice yields the same
|
|
2347
|
+
* answer — which a consumer that folds once to display and once to apply depends on.
|
|
2348
|
+
*
|
|
2349
|
+
* @public
|
|
2350
|
+
*/
|
|
2351
|
+
declare function foldLayers(entries: readonly LayerValues[], accumulatingKeys?: readonly string[]): Record<string, unknown>;
|
|
2352
|
+
|
|
2353
|
+
/**
|
|
2354
|
+
* Public handle to an open memory index. Mirrors the internal `MemoryIndex`
|
|
2355
|
+
* contract structurally; defined here (NOT re-exported from internal/) so
|
|
2356
|
+
* the public DTS surface does not pull the internal/runtime cycle that
|
|
2357
|
+
* trips rollup-plugin-dts.
|
|
2358
|
+
*
|
|
2359
|
+
* @public
|
|
2360
|
+
*/
|
|
2361
|
+
interface MemoryIndexHandle {
|
|
2362
|
+
sync(): Promise<{
|
|
2363
|
+
filesScanned: number;
|
|
2364
|
+
filesUpdated: number;
|
|
2365
|
+
chunksWritten: number;
|
|
2366
|
+
chunksEmbedded: number;
|
|
2367
|
+
/**
|
|
2368
|
+
* Whether this backend actually walked a corpus. `false` on the Lance backend, which is a
|
|
2369
|
+
* vector store fed by explicit writes and has no corpus — its zero counts mean "not applicable",
|
|
2370
|
+
* not "nothing to reindex". Read this before treating the counts as a measurement.
|
|
2371
|
+
*/
|
|
2372
|
+
supported: boolean;
|
|
2373
|
+
}>;
|
|
2374
|
+
search(query: string, options?: {
|
|
2375
|
+
maxResults?: number;
|
|
2376
|
+
minScore?: number;
|
|
2377
|
+
sources?: ReadonlyArray<"memory" | "sessions" | "wiki">;
|
|
2378
|
+
}): Promise<ReadonlyArray<{
|
|
2379
|
+
path: string;
|
|
2380
|
+
startLine: number;
|
|
2381
|
+
endLine: number;
|
|
2382
|
+
score: number;
|
|
2383
|
+
textScore: number;
|
|
2384
|
+
vectorScore?: number;
|
|
2385
|
+
snippet: string;
|
|
2386
|
+
source: "memory" | "sessions" | "wiki";
|
|
2387
|
+
citation: string;
|
|
2388
|
+
}>>;
|
|
2389
|
+
status(): {
|
|
2390
|
+
backend: "fts-only" | "hybrid";
|
|
2391
|
+
filesIndexed: number;
|
|
2392
|
+
chunksIndexed: number;
|
|
2393
|
+
lastSyncMs?: number;
|
|
2394
|
+
/**
|
|
2395
|
+
* Whether `filesIndexed` / `chunksIndexed` were measured. `false` on the Lance backend, whose
|
|
2396
|
+
* store is async while `status()` is not — the zeros there are placeholders, so
|
|
2397
|
+
* `chunksIndexed > 0` is not a valid test for "is the index populated".
|
|
2398
|
+
*/
|
|
2399
|
+
countsExact: boolean;
|
|
2400
|
+
};
|
|
2401
|
+
close(): Promise<void> | void;
|
|
2402
|
+
}
|
|
2403
|
+
/**
|
|
2404
|
+
* Inputs for {@link Memory.runDreamingSweep}.
|
|
2405
|
+
*
|
|
2406
|
+
* `embedding` is required and has no default: the sweep scores cosine similarity between facts, so
|
|
2407
|
+
* without real embeddings there is nothing to dedup or cluster on. Both thresholds are cosine
|
|
2408
|
+
* similarity in [0, 1] and default to `0.95` for dedup and `0.75` for clustering — dedup is the
|
|
2409
|
+
* stricter of the two because merging two facts that were merely related is a data loss, while
|
|
2410
|
+
* failing to cluster them only costs a note.
|
|
2411
|
+
*
|
|
2412
|
+
* @public
|
|
2413
|
+
*/
|
|
2414
|
+
interface DreamingSweepOptions {
|
|
2415
|
+
/** Workspace cwd holding `.theokit/memory/`. */
|
|
2416
|
+
cwd: string;
|
|
2417
|
+
/**
|
|
2418
|
+
* Absolute path (or `~/`-prefixed) of the memory root to sweep, when the agent that wrote it set
|
|
2419
|
+
* `memory.directory`. Defaults to `<cwd>/.theokit/memory`.
|
|
2420
|
+
*/
|
|
2421
|
+
directory?: string;
|
|
2422
|
+
/**
|
|
2423
|
+
* Embedding provider for semantic dedup + clustering. Required — dreaming
|
|
2424
|
+
* relies on real embeddings to score cosine similarity. Supported providers:
|
|
2425
|
+
* `"openai"`, `"mistral"`, `"openrouter"`, `"voyage"`, `"deepinfra"`,
|
|
2426
|
+
* `"ollama"` (local, ADR D183).
|
|
2427
|
+
*/
|
|
2428
|
+
embedding: {
|
|
2429
|
+
provider: "openai" | "mistral" | "openrouter" | "voyage" | "deepinfra" | "ollama";
|
|
2430
|
+
model?: string;
|
|
2431
|
+
};
|
|
2432
|
+
/** Cosine-similarity threshold for the dedup phase. Default `0.95`. */
|
|
2433
|
+
dedupThreshold?: number;
|
|
2434
|
+
/** Cosine-similarity threshold for the clustering phase. Default `0.75`. */
|
|
2435
|
+
clusterThreshold?: number;
|
|
2436
|
+
}
|
|
2437
|
+
/**
|
|
2438
|
+
* What one dreaming sweep did.
|
|
2439
|
+
*
|
|
2440
|
+
* `status` is `"skipped"` when the workspace held no facts to work on and `"error"` when the sweep
|
|
2441
|
+
* failed; both come back with every counter at zero, so check `status` before reading a zero as
|
|
2442
|
+
* "there was nothing to consolidate". A failure is reported through this field rather than as a
|
|
2443
|
+
* rejection, which means a caller that only awaits the promise never learns the sweep did nothing.
|
|
2444
|
+
* `factsBefore` and `factsAfter` bracket the run, which is the pair to compare when you want to
|
|
2445
|
+
* know whether the sweep was worth running rather than how many operations it performed.
|
|
2446
|
+
*
|
|
2447
|
+
* @public
|
|
2448
|
+
*/
|
|
2449
|
+
interface DreamingSweepResult {
|
|
2450
|
+
status: "ok" | "skipped" | "error";
|
|
2451
|
+
factsBefore: number;
|
|
2452
|
+
factsAfter: number;
|
|
2453
|
+
duplicatesRemoved: number;
|
|
2454
|
+
clustersCreated: number;
|
|
2455
|
+
notesWritten: number;
|
|
2456
|
+
}
|
|
2457
|
+
/**
|
|
2458
|
+
* Options for `Memory.openIndex`. Mirrors the internal `OpenIndexOptions`
|
|
2459
|
+
* but using only public types from the SDK surface.
|
|
2460
|
+
*
|
|
2461
|
+
* @public
|
|
2462
|
+
*/
|
|
2463
|
+
interface OpenMemoryIndexOptions {
|
|
2464
|
+
/** Workspace cwd holding `.theokit/memory/`. */
|
|
2465
|
+
cwd: string;
|
|
2466
|
+
/** Override storage file path (SQLite) OR storage directory (Lance). */
|
|
2467
|
+
filePath?: string;
|
|
2468
|
+
/**
|
|
2469
|
+
* Embedding runtime — REQUIRED for `backend: "lance"`, optional for
|
|
2470
|
+
* `"sqlite-vec"` (when omitted, SQLite runs FTS-only without vector
|
|
2471
|
+
* recall).
|
|
2472
|
+
*/
|
|
2473
|
+
embedding?: {
|
|
2474
|
+
provider: "openai" | "mistral" | "openrouter" | "voyage" | "deepinfra" | "ollama";
|
|
2475
|
+
model?: string;
|
|
2476
|
+
};
|
|
2477
|
+
/** Default `"sqlite-vec"`. Set to `"lance"` to opt into LanceDB (peer dep). */
|
|
2478
|
+
backend?: "sqlite-vec" | "lance";
|
|
2479
|
+
}
|
|
2480
|
+
/**
|
|
2481
|
+
* Memory operations that run OUTSIDE an agent turn.
|
|
2482
|
+
*
|
|
2483
|
+
* Everything here is reachable without `Agent.create({ memory: ... })`, which is the point: opening
|
|
2484
|
+
* an index directly is how a CLI or a maintenance job inspects or rebuilds what the agent will
|
|
2485
|
+
* later read, and the dreaming sweep is maintenance that no `send()` triggers.
|
|
2486
|
+
*
|
|
2487
|
+
* Both operations route through the `@theokit/sdk-memory` peer package when it is installed and
|
|
2488
|
+
* fall back to the in-tree implementation when it is not. The fallback is not a degraded mode —
|
|
2489
|
+
* behaviour and thrown errors match — so consumers do not branch on which path ran.
|
|
2490
|
+
*
|
|
2491
|
+
* @public
|
|
2492
|
+
*/
|
|
2493
|
+
declare const Memory: {
|
|
2494
|
+
/**
|
|
2495
|
+
* Open a memory index. Dispatches to SQLite-vec (default, zero deps) or
|
|
2496
|
+
* LanceDB (opt-in via `backend: "lance"`, requires `@lancedb/lancedb`
|
|
2497
|
+
* peer dep + an embedding runtime).
|
|
2498
|
+
*
|
|
2499
|
+
* Returns a `MemoryIndex` with `sync()`, `search(query, opts?)`,
|
|
2500
|
+
* `status()`, and `close()`. Use this when you want a direct index
|
|
2501
|
+
* handle outside of `Agent.create({ memory: ... })`.
|
|
2502
|
+
*
|
|
2503
|
+
* @throws ConfigurationError({code:"invalid_memory_backend"}) for typos
|
|
2504
|
+
* like `"lancedb"`.
|
|
2505
|
+
* @throws ConfigurationError({code:"lance_requires_embedding"}) when
|
|
2506
|
+
* `backend: "lance"` is requested without `embedding`.
|
|
2507
|
+
* @throws ConfigurationError({code:"lance_backend_unavailable"}) when
|
|
2508
|
+
* `backend: "lance"` is requested but the peer dep is absent.
|
|
2509
|
+
*
|
|
2510
|
+
* @public
|
|
2511
|
+
*/
|
|
2512
|
+
openIndex(opts: OpenMemoryIndexOptions): Promise<MemoryIndexHandle>;
|
|
2513
|
+
/**
|
|
2514
|
+
* Run a dreaming sweep: dedup near-duplicate facts, cluster thematically
|
|
2515
|
+
* related ones, and write a consolidated note + diary entry.
|
|
2516
|
+
*
|
|
2517
|
+
* @public
|
|
2518
|
+
*/
|
|
2519
|
+
runDreamingSweep(opts: DreamingSweepOptions): Promise<DreamingSweepResult>;
|
|
2520
|
+
};
|
|
2521
|
+
|
|
2522
|
+
/**
|
|
2523
|
+
* Runtime helpers for `MemoryAdapter` (T1.1, ADR D141).
|
|
2524
|
+
*
|
|
2525
|
+
* Kept separate from `types/memory-adapter.ts` so the types module
|
|
2526
|
+
* stays import-free of runtime code (dep-cruise rule
|
|
2527
|
+
* `types-dont-import-runtime`). Adapter authors call `mkMemoryId` to
|
|
2528
|
+
* construct a branded id and `extractRawId` to unwrap with cross-adapter
|
|
2529
|
+
* safety (EC-B).
|
|
2530
|
+
*
|
|
2531
|
+
* @public
|
|
2532
|
+
*/
|
|
2533
|
+
|
|
2534
|
+
/**
|
|
2535
|
+
* Construct a branded `MemoryId` for an adapter. Embeds the adapter
|
|
2536
|
+
* identifier so `extractRawId` can reject ids minted by other adapters.
|
|
2537
|
+
*
|
|
2538
|
+
* @public
|
|
2539
|
+
*/
|
|
2540
|
+
declare function mkMemoryId(adapterId: string, rawId: string): MemoryId;
|
|
2541
|
+
/**
|
|
2542
|
+
* Extract the raw provider id from a `MemoryId`, enforcing that the
|
|
2543
|
+
* prefix matches `expectedAdapterId`. Throws `MemoryAdapterError(code:
|
|
2544
|
+
* "invalid_input")` on mismatch — prevents `mem0.delete(supermemoryId)`
|
|
2545
|
+
* from accidentally deleting unrelated data (EC-B).
|
|
2546
|
+
*
|
|
2547
|
+
* @public
|
|
2548
|
+
*/
|
|
2549
|
+
declare function extractRawId(id: MemoryId, expectedAdapterId: string): string;
|
|
2550
|
+
|
|
2551
|
+
/**
|
|
2552
|
+
* Options for {@link migrateSqliteToLance}.
|
|
2553
|
+
*
|
|
2554
|
+
* @public
|
|
2555
|
+
*/
|
|
2556
|
+
interface MigrateOptions {
|
|
2557
|
+
cwd: string;
|
|
2558
|
+
dryRun?: boolean;
|
|
2559
|
+
batchSize?: number;
|
|
2560
|
+
logger?: (msg: string) => void;
|
|
2561
|
+
}
|
|
2562
|
+
/**
|
|
2563
|
+
* Outcome of {@link migrateSqliteToLance}.
|
|
2564
|
+
*
|
|
2565
|
+
* @public
|
|
2566
|
+
*/
|
|
2567
|
+
interface MigrateResult {
|
|
2568
|
+
countSqlite: number;
|
|
2569
|
+
countLance: number;
|
|
2570
|
+
validated: boolean;
|
|
2571
|
+
sampleComparisons: ReadonlyArray<{
|
|
2572
|
+
id: string;
|
|
2573
|
+
match: boolean;
|
|
2574
|
+
}>;
|
|
2575
|
+
lancePath: string;
|
|
2576
|
+
committed: boolean;
|
|
2577
|
+
}
|
|
2578
|
+
/**
|
|
2579
|
+
* Migrate the Memory index from SQLite to LanceDB. ADR D44.
|
|
2580
|
+
*
|
|
2581
|
+
* @public
|
|
2582
|
+
*/
|
|
2583
|
+
declare function migrateSqliteToLance(options: MigrateOptions): Promise<MigrateResult>;
|
|
2584
|
+
|
|
2585
|
+
/**
|
|
2586
|
+
* `PermissionEngine` — first-match permission rules for tool invocations.
|
|
2587
|
+
*
|
|
2588
|
+
* Evaluates a tool name (and optional arguments, #55) against an ordered list
|
|
2589
|
+
* of rules. First matching rule wins; when no rule matches the `defaultAction`
|
|
2590
|
+
* is returned. #55 — the default is now `"ask"` (FAIL-CLOSED): a permission
|
|
2591
|
+
* engine that cannot positively allow must not silently allow. Opt back into
|
|
2592
|
+
* the previous fail-open behavior with `{ defaultAction: "allow" }`.
|
|
2593
|
+
*/
|
|
2594
|
+
type PermissionAction = "allow" | "deny" | "ask";
|
|
2595
|
+
|
|
2596
|
+
/**
|
|
2597
|
+
* SE1 — apply a {@link PermissionMode} to a rule-engine verdict. Pure.
|
|
2598
|
+
*
|
|
2599
|
+
* `explicit` is `true` when the verdict came from a rule that matched by name (and
|
|
2600
|
+
* args), `false` when it is the fail-closed default for an unmatched call. The flag
|
|
2601
|
+
* is load-bearing for `acceptEdits`, which auto-approves the unmatched default but
|
|
2602
|
+
* keeps honoring an explicit `ask` rule (unlike `bypass`, which allows even that).
|
|
2603
|
+
*
|
|
2604
|
+
* INVARIANT (both a peer project + Codex): an explicit `deny` is immune to EVERY
|
|
2605
|
+
* auto-approve mode — `bypass`/`acceptEdits` never un-deny.
|
|
2606
|
+
*/
|
|
2607
|
+
declare function applyMode(verdict: PermissionAction, mode: PermissionMode, explicit: boolean): PermissionAction;
|
|
2608
|
+
/**
|
|
2609
|
+
* #55 — an argument matcher. A rule with `args` gates on the tool's argument
|
|
2610
|
+
* VALUES, not just its name: an exact string, a RegExp (tested against the
|
|
2611
|
+
* stringified value), or a predicate. Every declared arg must match for the
|
|
2612
|
+
* rule to apply — so `{ tool: "shell", args: { command: /rm\s+-rf/ } }` denies
|
|
2613
|
+
* a destructive shell call while leaving `ls` to fall through.
|
|
2614
|
+
*/
|
|
2615
|
+
type ArgMatcher = string | RegExp | ((value: unknown) => boolean);
|
|
2616
|
+
/**
|
|
2617
|
+
* One entry in a {@link PermissionEngine}'s ordered rule list.
|
|
2618
|
+
*
|
|
2619
|
+
* Order is the semantics. The engine walks the list and the first rule whose `tool` matches — and
|
|
2620
|
+
* whose `args` matchers all pass, when it declares any — decides; nothing after it is consulted. Put
|
|
2621
|
+
* the narrow rules first: a catch-all `tool` RegExp placed above a specific deny makes that deny
|
|
2622
|
+
* unreachable, and nothing warns you.
|
|
2623
|
+
*
|
|
2624
|
+
* `args` is what lets one tool name resolve differently depending on what it is asked to do —
|
|
2625
|
+
* `{ tool: "shell", args: { command: /rm\s+-rf/ }, action: "deny" }` blocks the destructive call and
|
|
2626
|
+
* leaves `ls` to fall through to a later rule. Every declared matcher must pass.
|
|
2627
|
+
*
|
|
2628
|
+
* **A rule that declares an argument the call did not supply does not match**, whatever form the
|
|
2629
|
+
* matcher takes — string, RegExp or predicate. The predicate is not invoked with `undefined`; the
|
|
2630
|
+
* guard runs first, for every matcher form. Evaluation continues to the next rule.
|
|
2631
|
+
*
|
|
2632
|
+
* That was not always true, and the fix is the reason this paragraph is explicit (#367). A predicate
|
|
2633
|
+
* used to be called anyway, so `(v) => v !== "prod"` returned true for a missing argument and an
|
|
2634
|
+
* ALLOW rule authorized a call that supplied nothing, while `(v) => v.includes("rm")` threw a
|
|
2635
|
+
* TypeError out of the permission gate. This docblock told consumers to guard every predicate by
|
|
2636
|
+
* hand for months after `argMatches` stopped needing it — you do not have to.
|
|
2637
|
+
*
|
|
2638
|
+
* A rule that matches yields an EXPLICIT verdict, and that is what makes it survive a permissive
|
|
2639
|
+
* `PermissionMode`: `acceptEdits` auto-approves the unmatched default but still honours an explicit
|
|
2640
|
+
* `ask` rule, and an explicit `deny` is immune to every mode, `bypass` included.
|
|
2641
|
+
*/
|
|
2642
|
+
interface PermissionRule {
|
|
2643
|
+
/** Tool name (exact string) or pattern (RegExp). */
|
|
2644
|
+
tool: string | RegExp;
|
|
2645
|
+
/**
|
|
2646
|
+
* #55 — optional per-argument matchers. When present, the rule matches only
|
|
2647
|
+
* if the tool name matches AND every declared arg predicate matches the
|
|
2648
|
+
* corresponding call argument. A missing/undefined arg fails its predicate
|
|
2649
|
+
* (the rule does not match) — never throws.
|
|
2650
|
+
*/
|
|
2651
|
+
args?: Record<string, ArgMatcher>;
|
|
2652
|
+
/** Action to take when rule matches. */
|
|
2653
|
+
action: PermissionAction;
|
|
2654
|
+
}
|
|
2655
|
+
/** Options for {@link PermissionEngine}. */
|
|
2656
|
+
interface PermissionEngineOptions {
|
|
2657
|
+
/**
|
|
2658
|
+
* Action when no rule matches. #55 — default is now `"ask"` (fail-closed): a
|
|
2659
|
+
* permission engine that cannot positively allow must not silently allow.
|
|
2660
|
+
* Pass `"allow"` to restore the previous fail-open behavior.
|
|
2661
|
+
*/
|
|
2662
|
+
readonly defaultAction?: PermissionAction;
|
|
2663
|
+
}
|
|
2664
|
+
/**
|
|
2665
|
+
* Ordered first-match permission rules for tool invocations — the policy object you hand to
|
|
2666
|
+
* `PermissionPlugin.create()` to have it enforced.
|
|
2667
|
+
*
|
|
2668
|
+
* On its own it enforces nothing. `evaluate(toolName, args, mode)` is a pure function returning
|
|
2669
|
+
* `"allow" | "deny" | "ask"`, and no part of the SDK calls it until the engine is wrapped in a plugin
|
|
2670
|
+
* and that plugin is registered on an agent. The plugin is where a verdict becomes behaviour: `deny`
|
|
2671
|
+
* blocks the tool call, `allow` passes it through, and `ask` is routed to the host's `canUseTool`
|
|
2672
|
+
* gate — with no gate configured, `ask` blocks. So constructing an engine and never registering it
|
|
2673
|
+
* is a policy that does nothing, which is the mistake worth knowing about first.
|
|
2674
|
+
*
|
|
2675
|
+
* It is fail-closed by default: a call no rule matches resolves to `"ask"`, not `"allow"`, so a tool
|
|
2676
|
+
* the rules never mention needs a human — or an explicit `{ defaultAction: "allow" }` — before it
|
|
2677
|
+
* runs. Keep that default if you intend to use `PermissionMode: "plan"` for read-only behaviour,
|
|
2678
|
+
* because `plan` gates on the RESOLVED verdict: an engine built with `defaultAction: "allow"` still
|
|
2679
|
+
* allows every unmatched call under `plan`.
|
|
2680
|
+
*
|
|
2681
|
+
* The rules array is stored by reference and walked afresh on every `evaluate` call. Mutating the
|
|
2682
|
+
* array you passed in therefore changes the policy of a live engine; build a new engine when you
|
|
2683
|
+
* want a policy change to be a deliberate, visible event.
|
|
2684
|
+
*/
|
|
2685
|
+
declare class PermissionEngine {
|
|
2686
|
+
#private;
|
|
2687
|
+
private readonly rules;
|
|
2688
|
+
private readonly defaultAction;
|
|
2689
|
+
constructor(rules: PermissionRule[], options?: PermissionEngineOptions);
|
|
2690
|
+
/**
|
|
2691
|
+
* Evaluate a tool name (and optional arguments) against the rules. First
|
|
2692
|
+
* match wins; falls back to the configured `defaultAction` (default `"ask"`,
|
|
2693
|
+
* fail-closed) when no rule matches. #55 — a rule with `args` gates on the
|
|
2694
|
+
* argument values, so the same tool name can resolve to different actions
|
|
2695
|
+
* depending on what it is asked to do.
|
|
2696
|
+
*/
|
|
2697
|
+
evaluate(toolName: string, args?: Record<string, unknown>, mode?: PermissionMode): PermissionAction;
|
|
2698
|
+
}
|
|
2699
|
+
|
|
2700
|
+
/**
|
|
2701
|
+
* M7-5 — `createPermissionPlugin`: wire a {@link PermissionEngine} into the
|
|
2702
|
+
* `definePlugin` `pre_tool_call` veto seam. This is the canonical exemplar that
|
|
2703
|
+
* gives `PermissionEngine` a real caller (it was previously exported-but-unwired):
|
|
2704
|
+
* on each tool call the engine's verdict maps to the veto contract —
|
|
2705
|
+
* `"deny"` -> block, `"ask"` -> the caller's `onAsk` resolver (or block, fail-closed),
|
|
2706
|
+
* `"allow"` -> pass.
|
|
2707
|
+
*
|
|
2708
|
+
* @public
|
|
2709
|
+
*/
|
|
2710
|
+
|
|
2711
|
+
/**
|
|
2712
|
+
* SE1 — context passed to the {@link PermissionGate}. Intentionally minimal for
|
|
2713
|
+
* SE1; `agentId`/`runId` (for audit logging) are a documented follow-up — they are
|
|
2714
|
+
* available on the raw `pre_tool_call` context and can be threaded in a later slice.
|
|
2715
|
+
*/
|
|
2716
|
+
interface PermissionGateContext {
|
|
2717
|
+
/** The tool being gated. */
|
|
2718
|
+
readonly toolName: string;
|
|
2719
|
+
/** The active permission mode for this run. */
|
|
2720
|
+
readonly mode: PermissionMode;
|
|
2721
|
+
}
|
|
2722
|
+
/**
|
|
2723
|
+
* SE1 — the resolution of an `"ask"` verdict by the host gate. Fail-closed: an
|
|
2724
|
+
* absent gate, a throwing gate, and a `"deny"` decision all block. Arg rewrite
|
|
2725
|
+
* (`updatedInput`) is intentionally NOT supported yet — the `pre_tool_call` seam
|
|
2726
|
+
* is veto-only (`{ block, message }`); a future enhancement can extend it.
|
|
2727
|
+
*/
|
|
2728
|
+
type PermissionGateDecision = {
|
|
2729
|
+
readonly behavior: "allow";
|
|
2730
|
+
} | {
|
|
2731
|
+
readonly behavior: "deny";
|
|
2732
|
+
readonly message?: string;
|
|
2733
|
+
};
|
|
2734
|
+
/**
|
|
2735
|
+
* SE1 — the enriched `canUseTool` gate (the Anthropic-parity shape). Invoked ONLY
|
|
2736
|
+
* on an `"ask"` verdict, it receives the tool name, its input args, and the run
|
|
2737
|
+
* {@link PermissionGateContext}, and resolves to allow/deny. May be async (a real
|
|
2738
|
+
* gate can prompt a human — the `pre_tool_call` seam awaits it).
|
|
2739
|
+
*/
|
|
2740
|
+
type PermissionGate = (toolName: string, input: Record<string, unknown>, ctx: PermissionGateContext) => PermissionGateDecision | Promise<PermissionGateDecision>;
|
|
2741
|
+
/** Options for {@link createPermissionPlugin}. */
|
|
2742
|
+
interface PermissionPluginOptions {
|
|
2743
|
+
/** Plugin name (default `"permission-engine"`). */
|
|
2744
|
+
readonly name?: string;
|
|
2745
|
+
/**
|
|
2746
|
+
* SE1 — the per-run {@link PermissionMode}. Threaded into `engine.evaluate`, so
|
|
2747
|
+
* `bypass` auto-allows the ask verdict (gate never consulted), `plan` blocks
|
|
2748
|
+
* mutations, etc. An explicit `deny` rule is immune to every mode. Default
|
|
2749
|
+
* `"default"` (rules decide; unmatched ⇒ fail-closed ask).
|
|
2750
|
+
*/
|
|
2751
|
+
readonly mode?: PermissionMode;
|
|
2752
|
+
/**
|
|
2753
|
+
* SE1 — the enriched gate for the `"ask"` verdict. Preferred over {@link onAsk}.
|
|
2754
|
+
* Absent gate on an `ask` verdict ⇒ fail-closed block.
|
|
2755
|
+
*/
|
|
2756
|
+
readonly canUseTool?: PermissionGate;
|
|
2757
|
+
/**
|
|
2758
|
+
* @deprecated since SE1 — use {@link canUseTool}, which receives `(toolName,
|
|
2759
|
+
* input, ctx)` and returns a typed decision. Honored only when `canUseTool` is
|
|
2760
|
+
* absent. Returns a veto (`{block,message}`) to deny or `undefined` to allow.
|
|
2761
|
+
*/
|
|
2762
|
+
readonly onAsk?: (toolName: string) => PreToolCallDecision | undefined;
|
|
2763
|
+
}
|
|
2764
|
+
/** SE36 — `PermissionPlugin.create` replaces `createPermissionPlugin` (ADR 0015). @public */
|
|
2765
|
+
declare class PermissionPlugin {
|
|
2766
|
+
private constructor();
|
|
2767
|
+
static create(engine: PermissionEngine, opts?: PermissionPluginOptions): Plugin;
|
|
2768
|
+
}
|
|
2769
|
+
|
|
2770
|
+
/**
|
|
2771
|
+
* Load a project's `.env` without letting it move the credential store or switch off a trust
|
|
2772
|
+
* decision.
|
|
2773
|
+
*
|
|
2774
|
+
* `process.loadEnvFile()` reads the PROJECT's `.env` into `process.env`. For a provider key that is
|
|
2775
|
+
* exactly right and is the documented way to configure a scaffolded product. For the handful of
|
|
2776
|
+
* variables that decide WHERE credentials live and WHAT is trusted it is a hole: a cloned
|
|
2777
|
+
* repository is untrusted input, and a `.env` inside it is untrusted input the runtime is about to
|
|
2778
|
+
* treat as configuration.
|
|
2779
|
+
*
|
|
2780
|
+
* Concretely, without this guard a repository shipping
|
|
2781
|
+
*
|
|
2782
|
+
* ```
|
|
2783
|
+
* THEOKIT_AUTH_HOME=/tmp/attacker-store
|
|
2784
|
+
* ```
|
|
2785
|
+
*
|
|
2786
|
+
* redirects the credential store the moment the product starts in that directory — before any
|
|
2787
|
+
* trust prompt, because locating the store is what happens first.
|
|
2788
|
+
*
|
|
2789
|
+
* ## Why it lives here
|
|
2790
|
+
*
|
|
2791
|
+
* The scaffolding template (`create-theokit`, TUI surface) calls `process.loadEnvFile()` with no
|
|
2792
|
+
* guard, so every product generated from it starts exposed. One consumer found this and fixed it in
|
|
2793
|
+
* ~30 lines of its own. A defence each consumer has to rediscover is a defence most will not have,
|
|
2794
|
+
* and this one is invisible when missing: nothing fails, the store simply moves.
|
|
2795
|
+
*
|
|
2796
|
+
* ## Why the set is named
|
|
2797
|
+
*
|
|
2798
|
+
* A convention — "anything ending in `_HOME`", "anything with TRUST in it" — silently changes
|
|
2799
|
+
* meaning as variables are added, in the direction of accidentally sovereign or accidentally not.
|
|
2800
|
+
* The list is explicit so that making a variable sovereign is a deliberate act, and so a reader can
|
|
2801
|
+
* see the security boundary without grepping for it.
|
|
2802
|
+
*
|
|
2803
|
+
* @public
|
|
2804
|
+
*/
|
|
2805
|
+
/**
|
|
2806
|
+
* Variables a project-scoped source may never set. Each either locates the credential store, names
|
|
2807
|
+
* the config directory that is read as configuration, or carries a trust decision.
|
|
2808
|
+
*
|
|
2809
|
+
* `THEOKIT_API_KEY` is deliberately ABSENT. A project supplying its own provider key through `.env`
|
|
2810
|
+
* is the documented, intended path — treating it as sovereign would break every scaffolded product
|
|
2811
|
+
* to defend nothing, since a key the project supplies is a key the project already has.
|
|
2812
|
+
*
|
|
2813
|
+
* @public
|
|
2814
|
+
*/
|
|
2815
|
+
declare const SOVEREIGN_ENV_KEYS: readonly ["THEOKIT_HOME", "THEOKIT_AUTH_HOME", "THEOKIT_TRUSTED_PROVIDERS", "THEOKIT_REDACT_SECRETS", "THEOKIT_OAUTH_TX_SALT"];
|
|
2816
|
+
/**
|
|
2817
|
+
* The union of {@link SOVEREIGN_ENV_KEYS} entries — the variables a project-scoped `.env` may never
|
|
2818
|
+
* set.
|
|
2819
|
+
*
|
|
2820
|
+
* Derived from the array rather than written out, so adding a key in one place cannot leave the
|
|
2821
|
+
* type behind. Use it where a caller must name one of the protected variables and a plain `string`
|
|
2822
|
+
* would let a typo through silently.
|
|
2823
|
+
*
|
|
2824
|
+
* @public
|
|
2825
|
+
*/
|
|
2826
|
+
type SovereignEnvKey = (typeof SOVEREIGN_ENV_KEYS)[number];
|
|
2827
|
+
/** The mutable shape of `process.env`, narrowed so a caller can pass a plain object in tests. */
|
|
2828
|
+
type MutableEnv = Record<string, string | undefined>;
|
|
2829
|
+
/**
|
|
2830
|
+
* Read the project's `.env` into `env`, then restore every {@link SOVEREIGN_ENV_KEYS} entry to the
|
|
2831
|
+
* value it had BEFORE the load — including restoring it to absent.
|
|
2832
|
+
*
|
|
2833
|
+
* Capture-then-restore rather than filtering the file: `process.loadEnvFile` offers no hook between
|
|
2834
|
+
* parsing and assignment, and reimplementing dotenv parsing to filter it would be a second parser
|
|
2835
|
+
* to keep in step with Node's. Restoring afterwards needs no parser and cannot disagree with one.
|
|
2836
|
+
*
|
|
2837
|
+
* @param env the environment to mutate. Defaults to `process.env`.
|
|
2838
|
+
* @param load performs the load. Defaults to `process.loadEnvFile` when the runtime has it, and to
|
|
2839
|
+
* `undefined` when it does not — in which case this is a no-op rather than a startup crash.
|
|
2840
|
+
* @public
|
|
2841
|
+
*/
|
|
2842
|
+
declare function loadProjectEnv(env?: MutableEnv, load?: (() => void) | undefined): void;
|
|
2843
|
+
|
|
2844
|
+
/**
|
|
2845
|
+
* Decide which session artifacts may be deleted — and never delete them.
|
|
2846
|
+
*
|
|
2847
|
+
* This package creates session artifacts (transcripts, locks, temp files) and cleans up only what is
|
|
2848
|
+
* in flight in the operation doing the cleaning: a lock it just released, a `.tmp` from a failed
|
|
2849
|
+
* atomic write. Nothing collects the rest, so every consumer either writes its own collector or lets
|
|
2850
|
+
* the directory grow without bound — and a hand-rolled collector on the path that deletes a user's
|
|
2851
|
+
* transcript is the worst place for each product to learn the same lessons separately.
|
|
2852
|
+
*
|
|
2853
|
+
* ## Planning is not deleting, deliberately
|
|
2854
|
+
*
|
|
2855
|
+
* A function that decided AND deleted could not be tested without a filesystem, and the case that
|
|
2856
|
+
* matters most — "we could not establish whether this session is live" — would have to be simulated
|
|
2857
|
+
* rather than asserted. Here the decision is pure: the plan IS the dry run, and executing it is a
|
|
2858
|
+
* separate act on a value someone can read first. That separation is the dry-run guarantee, rather
|
|
2859
|
+
* than a flag that has to be remembered.
|
|
2860
|
+
*
|
|
2861
|
+
* ## The tri-state
|
|
2862
|
+
*
|
|
2863
|
+
* `keep`, `reap`, `undetermined`. An artifact whose liveness could not be established is never
|
|
2864
|
+
* reaped and never quietly counted as dead. Collapsing "could not determine" into "not there" is how
|
|
2865
|
+
* a collector deletes a session running on another machine, or behind a mount that answered slowly.
|
|
2866
|
+
* The third bucket costs a branch and buys the only guarantee worth having on this path.
|
|
2867
|
+
*
|
|
2868
|
+
* @public
|
|
2869
|
+
*/
|
|
2870
|
+
|
|
2871
|
+
/** Raised when a retention policy cannot be honoured as written. @public */
|
|
2872
|
+
declare class RetentionPolicyError extends TheokitAgentError {
|
|
2873
|
+
readonly name = "RetentionPolicyError";
|
|
2874
|
+
}
|
|
2875
|
+
/**
|
|
2876
|
+
* One artifact the caller is considering deleting, described well enough to decide about.
|
|
2877
|
+
*
|
|
2878
|
+
* `id` is only ever compared for equality, so any stable identity works — a path, a session id, an
|
|
2879
|
+
* inode. `live` is the tri-state that carries the whole safety property: `"unknown"` means the
|
|
2880
|
+
* caller could not establish liveness, and it is honoured as a third answer rather than folded into
|
|
2881
|
+
* `false`.
|
|
2882
|
+
*
|
|
2883
|
+
* @public
|
|
2884
|
+
*/
|
|
2885
|
+
interface ReapableArtifact {
|
|
2886
|
+
readonly id: string;
|
|
2887
|
+
/** Epoch milliseconds. Compared against an injected `nowMs`, never against a read clock. */
|
|
2888
|
+
readonly lastModifiedMs: number;
|
|
2889
|
+
/**
|
|
2890
|
+
* Whether a writer still holds this artifact. `"unknown"` when the caller could not establish it —
|
|
2891
|
+
* a stale lock behind a slow mount, a PID on another host — and it is honoured as a third answer
|
|
2892
|
+
* rather than folded into `false`.
|
|
2893
|
+
*/
|
|
2894
|
+
readonly live: boolean | "unknown";
|
|
2895
|
+
}
|
|
2896
|
+
/**
|
|
2897
|
+
* How long artifacts are kept and how many always survive.
|
|
2898
|
+
*
|
|
2899
|
+
* The two interact as a window plus a FLOOR, not as two independent allowances: `keepLast` rescues
|
|
2900
|
+
* artifacts only when the window and liveness together spared fewer than that many, and rescues
|
|
2901
|
+
* exactly enough to reach the count. Both are refused by `planReaping` rather than clamped when
|
|
2902
|
+
* they are not expressible — see its `@throws`.
|
|
2903
|
+
*
|
|
2904
|
+
* @public
|
|
2905
|
+
*/
|
|
2906
|
+
interface RetentionPolicy {
|
|
2907
|
+
/** Artifacts strictly older than this are candidates. The boundary itself is kept. */
|
|
2908
|
+
readonly maxAgeMs: number;
|
|
2909
|
+
/**
|
|
2910
|
+
* A FLOOR on how many artifacts survive: "you will always have your last N sessions". When
|
|
2911
|
+
* liveness and the retention window already spare N or more, this changes nothing; when they
|
|
2912
|
+
* spare fewer, the newest of the remainder are spared until the count reaches N.
|
|
2913
|
+
*
|
|
2914
|
+
* Undetermined artifacts do NOT count toward the floor. Their liveness was never established, so
|
|
2915
|
+
* counting them would let a transient mount failure satisfy the floor with artifacts nobody
|
|
2916
|
+
* confirmed exist as sessions — and quietly delete the ones that do.
|
|
2917
|
+
*/
|
|
2918
|
+
readonly keepLast: number;
|
|
2919
|
+
}
|
|
2920
|
+
/** Why an artifact survived. @public */
|
|
2921
|
+
type KeepReason = "live" | "within-retention" | "keep-last";
|
|
2922
|
+
/**
|
|
2923
|
+
* An artifact that survived, carrying the reason it did.
|
|
2924
|
+
*
|
|
2925
|
+
* The reason is the one that spared it FIRST, in the order liveness, then the retention window,
|
|
2926
|
+
* then the floor — so a live artifact inside the window reports `"live"`, and `"keep-last"` only
|
|
2927
|
+
* appears on artifacts that had no reason of their own.
|
|
2928
|
+
*
|
|
2929
|
+
* @public
|
|
2930
|
+
*/
|
|
2931
|
+
interface KeptArtifact extends ReapableArtifact {
|
|
2932
|
+
readonly reason: KeepReason;
|
|
2933
|
+
}
|
|
2934
|
+
/**
|
|
2935
|
+
* The decision, as three disjoint buckets whose union is exactly the input.
|
|
2936
|
+
*
|
|
2937
|
+
* Nothing is deleted by producing one of these — the plan IS the dry run, and executing it is a
|
|
2938
|
+
* separate act on a value you can read first. Delete only what is in `reap`; `undetermined` is not
|
|
2939
|
+
* a smaller `reap`, it is the set nobody could decide about.
|
|
2940
|
+
*
|
|
2941
|
+
* @public
|
|
2942
|
+
*/
|
|
2943
|
+
interface ReapPlan {
|
|
2944
|
+
/** Safe to delete. Everything here was decided, not defaulted. */
|
|
2945
|
+
readonly reap: readonly ReapableArtifact[];
|
|
2946
|
+
readonly keep: readonly KeptArtifact[];
|
|
2947
|
+
/** Liveness could not be established. Never deleted, never counted as kept. */
|
|
2948
|
+
readonly undetermined: readonly ReapableArtifact[];
|
|
2949
|
+
}
|
|
2950
|
+
/**
|
|
2951
|
+
* Everything `planReaping` needs: the candidates, the policy, and the current time.
|
|
2952
|
+
*
|
|
2953
|
+
* `nowMs` is a parameter rather than a clock read so the same input always produces the same plan —
|
|
2954
|
+
* which is what lets a caller compute a plan, show it, and execute it later against the same
|
|
2955
|
+
* decision instead of a freshly re-derived one.
|
|
2956
|
+
*
|
|
2957
|
+
* @public
|
|
2958
|
+
*/
|
|
2959
|
+
interface ReapPlanInput {
|
|
2960
|
+
readonly artifacts: readonly ReapableArtifact[];
|
|
2961
|
+
readonly retention: RetentionPolicy;
|
|
2962
|
+
/** Injected so the plan is reproducible and testable; this module never reads a clock. */
|
|
2963
|
+
readonly nowMs: number;
|
|
2964
|
+
}
|
|
2965
|
+
/**
|
|
2966
|
+
* Sort artifacts into keep, reap, and undetermined — and delete nothing.
|
|
2967
|
+
*
|
|
2968
|
+
* The order of decision is liveness, then the retention window, then the floor. An artifact whose
|
|
2969
|
+
* `live` is `"unknown"` leaves at the first step and is never considered again: it is not counted
|
|
2970
|
+
* toward `keepLast`, so a transient mount failure cannot satisfy "keep my last two" with artifacts
|
|
2971
|
+
* nobody confirmed while the confirmed ones are deleted.
|
|
2972
|
+
*
|
|
2973
|
+
* The window boundary belongs to the safe side. An artifact exactly `maxAgeMs` old is kept, so a
|
|
2974
|
+
* 30-day retention never means 29 depending on clock granularity.
|
|
2975
|
+
*
|
|
2976
|
+
* @returns the three buckets. Their union is exactly the input, each artifact counted once — the
|
|
2977
|
+
* invariant an operator reads the totals against.
|
|
2978
|
+
* @throws RetentionPolicyError when `maxAgeMs` is negative or not finite, or `keepLast` is negative
|
|
2979
|
+
* or not an integer. Nonsense is refused rather than clamped, because a clamped window on this
|
|
2980
|
+
* path deletes data the operator meant to keep.
|
|
2981
|
+
* @public
|
|
2982
|
+
*/
|
|
2983
|
+
declare function planReaping(input: ReapPlanInput): ReapPlan;
|
|
2984
|
+
|
|
2985
|
+
/** The internal JSON-Schema shape the synthetic `output` tool consumes. */
|
|
2986
|
+
type NormalizedJsonSchema = Record<string, unknown>;
|
|
2987
|
+
/**
|
|
2988
|
+
* Normalize any supported schema to the internal JSON Schema. Async because the Valibot path
|
|
2989
|
+
* dynamically imports its optional converter. Throws a clear, typed-message error for an unsupported
|
|
2990
|
+
* schema or a missing Valibot peer (error-handling.md).
|
|
2991
|
+
*/
|
|
2992
|
+
declare function normalizeSchema(schema: unknown): Promise<NormalizedJsonSchema>;
|
|
2993
|
+
|
|
2994
|
+
/**
|
|
2995
|
+
* Public security namespace (T2.1, ADR D68).
|
|
2996
|
+
*
|
|
2997
|
+
* Two entry points:
|
|
2998
|
+
*
|
|
2999
|
+
* - `Security.redact(text, opts?)` — apply the canonical redactor to
|
|
3000
|
+
* arbitrary text. Useful when a consumer app (or example) writes its
|
|
3001
|
+
* own logs / metrics / paste-share artifacts that the SDK's wired
|
|
3002
|
+
* sinks (error metadata, telemetry, transcript, migration) don't
|
|
3003
|
+
* cover.
|
|
3004
|
+
* - `Security.addPattern(re)` — register a custom credential pattern
|
|
3005
|
+
* on top of the 12 builtins (OpenAI, Anthropic, GitHub PAT classic +
|
|
3006
|
+
* fine, GitLab, AWS, Google, Slack, Sentry, Stripe live + restricted)
|
|
3007
|
+
* plus the parametric `key=value` + `Bearer <token>` matchers.
|
|
3008
|
+
*
|
|
3009
|
+
* Redaction is ON by default. Disable with `THEOKIT_REDACT_SECRETS=false`
|
|
3010
|
+
* (a warning is emitted on stderr so the operator knows the SDK process
|
|
3011
|
+
* is vulnerable). The env var is snapshotted at module init — runtime
|
|
3012
|
+
* mutation cannot disable it, defending against prompt injection that
|
|
3013
|
+
* tries to flip the flag mid-run.
|
|
3014
|
+
*/
|
|
3015
|
+
declare class Security {
|
|
3016
|
+
private constructor();
|
|
3017
|
+
/**
|
|
3018
|
+
* Redact known credential patterns from `text` and return the masked
|
|
3019
|
+
* string. Use this at any consumer output boundary the SDK does not
|
|
3020
|
+
* directly own (custom stdout loggers, app-level metrics, debug-share
|
|
3021
|
+
* artifacts, etc.).
|
|
3022
|
+
*
|
|
3023
|
+
* Coerces non-strings (objects via JSON.stringify, null/undefined → "").
|
|
3024
|
+
* Two-bucket masking: tokens shorter than 18 chars → `***`; longer
|
|
3025
|
+
* tokens preserve `prefix...suffix` for debuggability without revealing
|
|
3026
|
+
* the secret middle.
|
|
3027
|
+
*
|
|
3028
|
+
* @param text - The value to redact. Strings, objects, primitives all OK.
|
|
3029
|
+
* @param opts.codeFile - When `true`, skips the parametric `key=value`
|
|
3030
|
+
* matcher so file content like `.env.example` placeholders is left
|
|
3031
|
+
* intact. Built-in pattern matches still apply.
|
|
3032
|
+
*
|
|
3033
|
+
* @example
|
|
3034
|
+
* console.log(`[bot] received: ${Security.redact(userText)}`);
|
|
3035
|
+
* // → "[bot] received: please remember sk-abc...xyz1"
|
|
3036
|
+
*/
|
|
3037
|
+
static redact(text: unknown, opts?: {
|
|
3038
|
+
codeFile?: boolean;
|
|
3039
|
+
}): string;
|
|
3040
|
+
/**
|
|
3041
|
+
* Register a custom redaction pattern. Additive — built-in patterns
|
|
3042
|
+
* (OpenAI, Anthropic, GitHub PAT, AWS, etc.) cannot be removed.
|
|
3043
|
+
*
|
|
3044
|
+
* @param re - RegExp with `/g` flag. Throws if `/g` is missing
|
|
3045
|
+
* (without /g, only first match is replaced and the rest
|
|
3046
|
+
* leaks).
|
|
3047
|
+
*
|
|
3048
|
+
* Process-global mutable state. The SDK is designed for single-tenant
|
|
3049
|
+
* processes (Theo PaaS user runtime, local CLI). Multi-tenant
|
|
3050
|
+
* deployments running multiple SDK consumers in the same Node process
|
|
3051
|
+
* share this list — patterns added by tenant A apply to tenant B's
|
|
3052
|
+
* redactions. Acceptable for v1; future isolate-aware refactor would
|
|
3053
|
+
* thread patterns through a context if needed.
|
|
3054
|
+
*
|
|
3055
|
+
* @example
|
|
3056
|
+
* Security.addPattern(/MYORG-[A-Z0-9]{32}/g);
|
|
3057
|
+
* // → text containing "MYORG-AAAA...AAAA" now masks like a builtin.
|
|
3058
|
+
*/
|
|
3059
|
+
static addPattern(re: RegExp): void;
|
|
3060
|
+
}
|
|
3061
|
+
|
|
3062
|
+
/**
|
|
3063
|
+
* Resolve a security-relevant setting across configuration layers, where a lower-trust layer may
|
|
3064
|
+
* TIGHTEN it and never loosen it.
|
|
3065
|
+
*
|
|
3066
|
+
* Layered configuration usually resolves last-wins, and for the keys that decide confinement — a
|
|
3067
|
+
* sandbox mode, an approval policy — last-wins is a hole. With plain precedence a project layer
|
|
3068
|
+
* outranks the user's own file, so a cloned repository can hand itself the most permissive setting
|
|
3069
|
+
* and the operator's global choice loses silently, at the moment the directory is opened. Nothing
|
|
3070
|
+
* fails; the confinement is simply gone.
|
|
3071
|
+
*
|
|
3072
|
+
* ## What is generic here, and what is not
|
|
3073
|
+
*
|
|
3074
|
+
* The RULE is generic: named layers may only move the value in the confining direction, while one
|
|
3075
|
+
* designated layer — the operator's explicit flag — wins in both. The VOCABULARY is not: which
|
|
3076
|
+
* values count as more permissive, what the layers are called, and which one is the operator's are
|
|
3077
|
+
* all the consumer's, and are parameters.
|
|
3078
|
+
*
|
|
3079
|
+
* That distinction is what makes this extractable when a keypress router was not. Here the
|
|
3080
|
+
* vocabulary is DATA — two lists and a name — so a second product supplies its own without
|
|
3081
|
+
* inheriting the first's words. An interface shaped by one product's states would have given the
|
|
3082
|
+
* second consumer something to route around.
|
|
3083
|
+
*
|
|
3084
|
+
* ## Why the override is not validated
|
|
3085
|
+
*
|
|
3086
|
+
* `override` is returned verbatim, even when it is outside `permissiveness`. Validating the
|
|
3087
|
+
* operator's flag is the consumer's job: it owns the vocabulary, the error message and the exit
|
|
3088
|
+
* code. Silently dropping an unrecognised flag would be worse than passing it through — the
|
|
3089
|
+
* operator would see their explicit instruction ignored with no explanation.
|
|
3090
|
+
*
|
|
3091
|
+
* A value outside the vocabulary in a RESTRICTED layer is different and IS ignored: a typo in a
|
|
3092
|
+
* repository's config must neither become the effective setting nor be treated as maximally
|
|
3093
|
+
* permissive.
|
|
3094
|
+
*
|
|
3095
|
+
* @public
|
|
3096
|
+
*/
|
|
3097
|
+
/**
|
|
3098
|
+
* The vocabulary, the layer names, and the values to resolve.
|
|
3099
|
+
*
|
|
3100
|
+
* Two orders matter and they are not the same one. The UNRESTRICTED layers — every key of `layers`
|
|
3101
|
+
* that is neither `override` nor listed in `restricted` — are resolved last-wins in the enumeration
|
|
3102
|
+
* order of the `layers` object. The RESTRICTED layers are applied in the order of the `restricted`
|
|
3103
|
+
* array, regardless of where they sit in `layers`. Put a layer in `restricted` and its position in
|
|
3104
|
+
* that array is what decides when it gets to tighten.
|
|
3105
|
+
*
|
|
3106
|
+
* A layer named in `restricted` but absent from `layers`, or present with `undefined`, is skipped.
|
|
3107
|
+
*
|
|
3108
|
+
* @public
|
|
3109
|
+
*/
|
|
3110
|
+
interface SecurityFloorInput {
|
|
3111
|
+
/**
|
|
3112
|
+
* The vocabulary, ordered from most confined to least. Index is permissiveness, so
|
|
3113
|
+
* `["read-only", "workspace-write", "danger-full-access"]` says read-only confines the most.
|
|
3114
|
+
*/
|
|
3115
|
+
readonly permissiveness: readonly string[];
|
|
3116
|
+
/** Layers that may only tighten — typically anything a repository or environment can supply. */
|
|
3117
|
+
readonly restricted: readonly string[];
|
|
3118
|
+
/** The layer that wins outright in both directions — the operator's explicit flag. */
|
|
3119
|
+
readonly override: string;
|
|
3120
|
+
/**
|
|
3121
|
+
* Values per layer. Layers absent from `restricted` are unconstrained, which is how a `user`
|
|
3122
|
+
* layer loosens its own `defaults`.
|
|
3123
|
+
*/
|
|
3124
|
+
readonly layers: Readonly<Record<string, string | undefined>>;
|
|
3125
|
+
}
|
|
3126
|
+
/**
|
|
3127
|
+
* Resolve a security-relevant setting so that a lower-trust layer can only tighten it.
|
|
3128
|
+
*
|
|
3129
|
+
* Two paths. When `layers[override]` holds a value, that value is returned VERBATIM and nothing
|
|
3130
|
+
* else is consulted — it is not checked against `permissiveness`, because validating the operator's
|
|
3131
|
+
* own flag belongs to the consumer that owns the vocabulary and the error message. Otherwise a
|
|
3132
|
+
* baseline is taken from the unrestricted layers, and each restricted layer in turn may lower it
|
|
3133
|
+
* and never raise it.
|
|
3134
|
+
*
|
|
3135
|
+
* Two consequences worth knowing before wiring this up. A value in a restricted layer that is not
|
|
3136
|
+
* in `permissiveness` is IGNORED rather than trusted, so a typo in a repository's config leaves the
|
|
3137
|
+
* baseline standing instead of becoming the effective setting. And the ceiling only ever descends:
|
|
3138
|
+
* once one restricted layer tightens, a later one cannot return to the baseline, even though it
|
|
3139
|
+
* could have chosen that value had it come first.
|
|
3140
|
+
*
|
|
3141
|
+
* When no layer supplied a value at all, the answer is `undefined` — the absence is reported rather
|
|
3142
|
+
* than filled in with the most confined member of the vocabulary.
|
|
3143
|
+
*
|
|
3144
|
+
* @returns the resolved value, or `undefined` when no layer supplied one.
|
|
3145
|
+
* @public
|
|
3146
|
+
*/
|
|
3147
|
+
declare function applySecurityFloor(input: SecurityFloorInput): string | undefined;
|
|
3148
|
+
|
|
3149
|
+
/**
|
|
3150
|
+
* Refuse to destroy a session another process is still writing.
|
|
3151
|
+
*
|
|
3152
|
+
* Every agent product that lets a user delete or overwrite a session needs this, and the failure is
|
|
3153
|
+
* unrecoverable in the worst way: a transcript removed underneath a running session takes with it
|
|
3154
|
+
* everything that session had not flushed, and nothing errors. The user sees a successful delete.
|
|
3155
|
+
*
|
|
3156
|
+
* ## The ordering is the point
|
|
3157
|
+
*
|
|
3158
|
+
* The check runs BEFORE anything is mutated. Removing a registry entry and then refusing leaves a
|
|
3159
|
+
* session that can be neither opened nor deleted — worse than either outcome on its own. So this is
|
|
3160
|
+
* a function the caller passes through rather than a flag it may consult afterwards: the throw is
|
|
3161
|
+
* what stops the mutation, and there is no way to read the answer and forget to act on it.
|
|
3162
|
+
*
|
|
3163
|
+
* ## What is generic, and what is not
|
|
3164
|
+
*
|
|
3165
|
+
* The RULE is: a session declared live is not destroyable, and refusing says which one and why. The
|
|
3166
|
+
* VOCABULARY is not — how a product decides liveness (a pointer file, the newest transcript, a
|
|
3167
|
+
* lease, an active registry entry) is its own. Nothing here touches a filesystem.
|
|
3168
|
+
*
|
|
3169
|
+
* @public
|
|
3170
|
+
*/
|
|
3171
|
+
|
|
3172
|
+
/** Why the destruction was refused. @public */
|
|
3173
|
+
type LiveSessionReason = "session-is-live" | "liveness-undetermined";
|
|
3174
|
+
/**
|
|
3175
|
+
* Raised by `guardSessionDestruction` instead of letting a session be destroyed.
|
|
3176
|
+
*
|
|
3177
|
+
* Read `reason` rather than the message when deciding what to do: `"session-is-live"` is fixed by
|
|
3178
|
+
* closing the other session, `"liveness-undetermined"` is fixed by making the liveness check work
|
|
3179
|
+
* again, and telling a user to close a session when nothing could be read sends them to close
|
|
3180
|
+
* nothing. `sessionId` carries the session the refusal was about.
|
|
3181
|
+
*
|
|
3182
|
+
* @public
|
|
3183
|
+
*/
|
|
3184
|
+
declare class LiveSessionError extends TheokitAgentError {
|
|
3185
|
+
readonly name = "LiveSessionError";
|
|
3186
|
+
readonly sessionId: string;
|
|
3187
|
+
readonly reason: LiveSessionReason;
|
|
3188
|
+
constructor(sessionId: string, reason: LiveSessionReason);
|
|
3189
|
+
}
|
|
3190
|
+
/**
|
|
3191
|
+
* Throw unless `sessionId` is safe to destroy.
|
|
3192
|
+
*
|
|
3193
|
+
* @param live - the sessions the product declares live, or `undefined` when it could not tell.
|
|
3194
|
+
* The distinction is load-bearing: an EMPTY set is a legitimate answer (nothing is open), while
|
|
3195
|
+
* `undefined` refuses. A product that swallowed a read error and returned `[]` would hand this
|
|
3196
|
+
* guard the one input that disables it entirely, on exactly the path that destroys data.
|
|
3197
|
+
* @throws LiveSessionError naming the session and the reason — "close that session" and "the guard
|
|
3198
|
+
* could not read" have different fixes, and conflating them sends the user to close nothing.
|
|
3199
|
+
* @public
|
|
3200
|
+
*/
|
|
3201
|
+
declare function guardSessionDestruction(sessionId: string, live: readonly string[] | undefined): void;
|
|
3202
|
+
|
|
3203
|
+
/** Which session to read, in the terms a host already has. */
|
|
3204
|
+
interface ReadSessionMessagesOptions {
|
|
3205
|
+
/** The session's agent id — the same id `Agent` was created or resumed with. */
|
|
3206
|
+
sessionId: string;
|
|
3207
|
+
/**
|
|
3208
|
+
* The working directory the session belongs to. Sessions are per-cwd, so the same
|
|
3209
|
+
* id under a different cwd is a different session. Defaults to `process.cwd()`.
|
|
3210
|
+
*/
|
|
3211
|
+
cwd?: string;
|
|
3212
|
+
/**
|
|
3213
|
+
* Where transcripts live. Only needed when the agent was created with
|
|
3214
|
+
* `local.sessionDir`; otherwise the SDK's default location is used.
|
|
3215
|
+
*/
|
|
3216
|
+
sessionDir?: string;
|
|
3217
|
+
}
|
|
3218
|
+
/**
|
|
3219
|
+
* Read the messages a session already contains, for a surface that needs to re-render it.
|
|
3220
|
+
*
|
|
3221
|
+
* #546 — the SDK read these records to give the model its context on resume, and a host had
|
|
3222
|
+
* no way to read the same thing: a resumed session showed an empty screen while the model
|
|
3223
|
+
* demonstrably remembered. The alternative was for the host to parse
|
|
3224
|
+
* `<sessionDir>/projects/<encoded-cwd>/<id>.jsonl` itself, which is a private contract —
|
|
3225
|
+
* both the record shape and the directory encoding are the SDK's to change.
|
|
3226
|
+
*
|
|
3227
|
+
* This is deliberately narrower than the internal reader it wraps. That one takes a
|
|
3228
|
+
* {@link SessionStore}, and exporting it would put that interface, its record shape and its
|
|
3229
|
+
* lease semantics into the public surface to serve a caller that only wants to render what
|
|
3230
|
+
* is already there. A host that HAS a custom store can already read from it directly.
|
|
3231
|
+
*
|
|
3232
|
+
* Parsing stays tolerant, as it is on the resume path: a malformed line costs one message,
|
|
3233
|
+
* not the screen. A session that was never written resolves to `[]` rather than throwing —
|
|
3234
|
+
* a fresh session has no history, which is not an error.
|
|
3235
|
+
*
|
|
3236
|
+
* @example
|
|
3237
|
+
* ```ts
|
|
3238
|
+
* const history = await readSessionMessages({ sessionId, cwd: projectDir });
|
|
3239
|
+
* for (const m of history) render(m.role, m.text);
|
|
3240
|
+
* ```
|
|
3241
|
+
*/
|
|
3242
|
+
declare function readSessionMessages(options: ReadSessionMessagesOptions): Promise<SessionMessage[]>;
|
|
3243
|
+
|
|
3244
|
+
/**
|
|
3245
|
+
* M3 #62 — scoped session state.
|
|
3246
|
+
*
|
|
3247
|
+
* A conversation id can be namespaced by SCOPE so a consumer keeps app-durable,
|
|
3248
|
+
* user-durable, and ephemeral (temp) session data separated in the same store:
|
|
3249
|
+
*
|
|
3250
|
+
* - `app:` — durable state shared across users (app-level memory).
|
|
3251
|
+
* - `user:` — durable state for one user.
|
|
3252
|
+
* - `temp:` — ephemeral state a consumer prunes on logout / session end.
|
|
3253
|
+
*
|
|
3254
|
+
* The scope is a prefix on the conversation id (`"<scope>__<id>"`). The `__`
|
|
3255
|
+
* separator is path-safe (unlike `:`, which the identifier guard rejects), so a
|
|
3256
|
+
* host can partition sessions by scope over the native transcript store.
|
|
3257
|
+
*
|
|
3258
|
+
* @public
|
|
3259
|
+
*/
|
|
3260
|
+
/** M3 #62 — session state scope. */
|
|
3261
|
+
type SessionScope = "app" | "user" | "temp";
|
|
3262
|
+
/** M3 #62 — build a scope-namespaced conversation id (`"<scope>__<id>"`). */
|
|
3263
|
+
declare function scopedConversationId(scope: SessionScope, id: string): string;
|
|
3264
|
+
/** M3 #62 — the id prefix (`"<scope>__"`) used to match a scope's conversations. */
|
|
3265
|
+
declare function sessionScopePrefix(scope: SessionScope): string;
|
|
3266
|
+
|
|
3267
|
+
/**
|
|
3268
|
+
* `createSquad` — a sequential team of agents.
|
|
3269
|
+
*
|
|
3270
|
+
* A Squad is a thin convenience that COMPOSES `Workflow` + `agentStep` — it
|
|
3271
|
+
* adds NO new orchestration logic. Agents run in array order; each agent's
|
|
3272
|
+
* output is threaded into the next agent's prompt. For branching/parallel/
|
|
3273
|
+
* foreach teams use `Workflow` directly; for manager→worker delegation use
|
|
3274
|
+
* subagents or `@theokit/sdk-handoff`.
|
|
3275
|
+
*
|
|
3276
|
+
* Mirrors the `createAgentFactory` composition-LEGO precedent (a factory over
|
|
3277
|
+
* existing primitives, not a new subsystem).
|
|
3278
|
+
*
|
|
3279
|
+
* @public
|
|
3280
|
+
*/
|
|
3281
|
+
|
|
3282
|
+
/**
|
|
3283
|
+
* Options for {@link createSquad}.
|
|
3284
|
+
*
|
|
3285
|
+
* @public
|
|
3286
|
+
*/
|
|
3287
|
+
interface SquadOptions {
|
|
3288
|
+
/**
|
|
3289
|
+
* Agents run in array order (sequential pipeline). Must be non-empty.
|
|
3290
|
+
*
|
|
3291
|
+
* M81 — accepts an `AgentDefinition` (plain data) as well as a constructed `SDKAgent`. Building a
|
|
3292
|
+
* team used to force the caller to materialize every member by hand first: resolve the credential,
|
|
3293
|
+
* assemble the options, call `Agent.create`, await. That is precisely the work this milestone moves
|
|
3294
|
+
* into the framework elsewhere, so leaving it here would be inconsistent — and with
|
|
3295
|
+
* `discoverSubagents` now public (`@theokit/sdk/subagents-loader`), the data that describes an
|
|
3296
|
+
* agent is reachable, which closes the loop: discover → build a team, with no manual step between.
|
|
3297
|
+
*
|
|
3298
|
+
* Mixing both forms in one list is supported on purpose: a real team usually has members from
|
|
3299
|
+
* different origins.
|
|
3300
|
+
*/
|
|
3301
|
+
agents: ReadonlyArray<SDKAgent | AgentDefinition>;
|
|
3302
|
+
/**
|
|
3303
|
+
* Orchestration process. Only `"sequential"` is supported (the default).
|
|
3304
|
+
* `"hierarchical"` is accepted by the type but rejected at runtime with
|
|
3305
|
+
* guidance — use subagents or `@theokit/sdk-handoff` for manager→worker
|
|
3306
|
+
* delegation (those already cover it).
|
|
3307
|
+
*/
|
|
3308
|
+
process?: "sequential" | "hierarchical";
|
|
3309
|
+
/** Optional squad name (surfaced on the underlying workflow). Default `"squad"`. */
|
|
3310
|
+
name?: string;
|
|
3311
|
+
}
|
|
3312
|
+
/**
|
|
3313
|
+
* Result of a {@link Squad.run}. `result` is the final (last agent's) output;
|
|
3314
|
+
* `steps` is the per-agent trace from the underlying workflow run.
|
|
3315
|
+
*
|
|
3316
|
+
* @public
|
|
3317
|
+
*/
|
|
3318
|
+
interface SquadRun {
|
|
3319
|
+
readonly result: unknown;
|
|
3320
|
+
readonly status: "running" | "completed" | "failed" | "suspended" | "cancelled";
|
|
3321
|
+
readonly steps: ReadonlyArray<StepResult>;
|
|
3322
|
+
}
|
|
3323
|
+
/**
|
|
3324
|
+
* A sequential agent team produced by {@link createSquad}.
|
|
3325
|
+
*
|
|
3326
|
+
* @public
|
|
3327
|
+
*/
|
|
3328
|
+
interface Squad {
|
|
3329
|
+
/** Run the team over `input`, threading each agent's output to the next. */
|
|
3330
|
+
run(input: unknown): Promise<SquadRun>;
|
|
3331
|
+
}
|
|
3332
|
+
/** SE36 — `Squad.create` replaces `createSquad` (ADR 0015). Merges with the `Squad` interface. @public */
|
|
3333
|
+
declare class Squad {
|
|
3334
|
+
private constructor();
|
|
3335
|
+
static create(options: SquadOptions): Squad;
|
|
3336
|
+
}
|
|
3337
|
+
|
|
3338
|
+
/**
|
|
3339
|
+
* Owner: `internal/task/` (4 of 5 importers). Derived from the import graph, not declared —
|
|
3340
|
+
* `tests/lint/types-name-their-owner.test.ts` re-derives it.
|
|
3341
|
+
*
|
|
3342
|
+
* Public type contract for the Task observability registry (ADRs D361-D374).
|
|
3343
|
+
*
|
|
3344
|
+
* Tasks are an opt-in observability layer over async work in the SDK
|
|
3345
|
+
* (`Agent.send`, `Agent.batch`, `Workflow.run`, `Cron` fires). They have
|
|
3346
|
+
* a closed 5-state lifecycle (D362), discriminated events (D366), and a
|
|
3347
|
+
* pluggable store (D364). The `Task` facade in `task.ts` is the public
|
|
3348
|
+
* surface; consumers import these types from `@theokit/sdk`.
|
|
3349
|
+
*
|
|
3350
|
+
* @public
|
|
3351
|
+
*/
|
|
3352
|
+
/**
|
|
3353
|
+
* Closed enum of the 5 lifecycle states (D362).
|
|
3354
|
+
*
|
|
3355
|
+
* Transitions are acyclic:
|
|
3356
|
+
* queued → running → (finished | error | cancelled)
|
|
3357
|
+
* queued → cancelled (direct, no run started)
|
|
3358
|
+
*/
|
|
3359
|
+
type TaskState = "queued" | "running" | "finished" | "error" | "cancelled";
|
|
3360
|
+
/** Discriminator of the runtime that produced a task (D374). */
|
|
3361
|
+
type TaskKind = "run" | "batch" | "workflow" | "cron" | "custom";
|
|
3362
|
+
/** Discriminated union of task lifecycle events (D366). */
|
|
3363
|
+
type TaskEvent = {
|
|
3364
|
+
readonly type: "submitted";
|
|
3365
|
+
readonly taskId: string;
|
|
3366
|
+
readonly kind: TaskKind;
|
|
3367
|
+
readonly submittedAt: number;
|
|
3368
|
+
readonly meta?: Record<string, unknown>;
|
|
3369
|
+
/** D372 — flag set on the first yielded event when the ring buffer was at cap. */
|
|
3370
|
+
readonly truncated?: boolean;
|
|
3371
|
+
} | {
|
|
3372
|
+
readonly type: "started";
|
|
3373
|
+
readonly taskId: string;
|
|
3374
|
+
readonly startedAt: number;
|
|
3375
|
+
} | {
|
|
3376
|
+
readonly type: "progress";
|
|
3377
|
+
readonly taskId: string;
|
|
3378
|
+
readonly at: number;
|
|
3379
|
+
readonly payload: unknown;
|
|
3380
|
+
} | {
|
|
3381
|
+
readonly type: "finished";
|
|
3382
|
+
readonly taskId: string;
|
|
3383
|
+
readonly finishedAt: number;
|
|
3384
|
+
readonly result: unknown;
|
|
3385
|
+
} | {
|
|
3386
|
+
readonly type: "errored";
|
|
3387
|
+
readonly taskId: string;
|
|
3388
|
+
readonly erroredAt: number;
|
|
3389
|
+
readonly error: {
|
|
3390
|
+
readonly code: string;
|
|
3391
|
+
readonly message: string;
|
|
3392
|
+
};
|
|
3393
|
+
} | {
|
|
3394
|
+
readonly type: "cancelled";
|
|
3395
|
+
readonly taskId: string;
|
|
3396
|
+
readonly cancelledAt: number;
|
|
3397
|
+
readonly reason?: string;
|
|
3398
|
+
};
|
|
3399
|
+
/** Public read-only view of a task entry in the registry. */
|
|
3400
|
+
interface TaskHandle {
|
|
3401
|
+
readonly id: string;
|
|
3402
|
+
readonly kind: TaskKind;
|
|
3403
|
+
readonly state: TaskState;
|
|
3404
|
+
readonly submittedAt: number;
|
|
3405
|
+
readonly startedAt?: number;
|
|
3406
|
+
readonly finishedAt?: number;
|
|
3407
|
+
readonly cancelledAt?: number;
|
|
3408
|
+
readonly erroredAt?: number;
|
|
3409
|
+
readonly result?: unknown;
|
|
3410
|
+
readonly error?: {
|
|
3411
|
+
readonly code: string;
|
|
3412
|
+
readonly message: string;
|
|
3413
|
+
};
|
|
3414
|
+
readonly meta?: Record<string, unknown>;
|
|
3415
|
+
/**
|
|
3416
|
+
* EC-7 — cross-process best-effort cancel flag. Set by CLI
|
|
3417
|
+
* `theokit tasks cancel` via JsonFileTaskStore. The owning process
|
|
3418
|
+
* polls at checkpoints and honors via AbortController. Always
|
|
3419
|
+
* `undefined` for in-process cancel paths (which go directly through
|
|
3420
|
+
* AbortController).
|
|
3421
|
+
*/
|
|
3422
|
+
readonly cancelRequested?: boolean;
|
|
3423
|
+
/**
|
|
3424
|
+
* Why the task was cancelled, when whoever cancelled it said. Free text, written alongside
|
|
3425
|
+
* `cancelledAt` for a `queued` task and alongside `cancelRequested` for a `running` one.
|
|
3426
|
+
*
|
|
3427
|
+
* Absent when no reason was given — an empty string is not a reason, and a default like
|
|
3428
|
+
* "cancelled" would put words in the operator's mouth. `theokit tasks cancel --reason` is what
|
|
3429
|
+
* writes it (#351); nothing in the runtime reads it, because it exists for the human reading the
|
|
3430
|
+
* registry later.
|
|
3431
|
+
*/
|
|
3432
|
+
readonly cancelReason?: string;
|
|
3433
|
+
}
|
|
3434
|
+
/** Query filter for `Task.list`. */
|
|
3435
|
+
interface TaskFilter {
|
|
3436
|
+
readonly state?: TaskState | readonly TaskState[];
|
|
3437
|
+
readonly kind?: TaskKind | readonly TaskKind[];
|
|
3438
|
+
readonly submittedAfter?: number;
|
|
3439
|
+
readonly submittedBefore?: number;
|
|
3440
|
+
/**
|
|
3441
|
+
* Defaults to 100. `JsonFileTaskStore` returns the newest matching tasks first and reads its
|
|
3442
|
+
* whole directory to find them (256 files at a time); page past this limit with
|
|
3443
|
+
* `submittedBefore` (#362).
|
|
3444
|
+
*/
|
|
3445
|
+
readonly limit?: number;
|
|
3446
|
+
}
|
|
3447
|
+
/** Options for `Task.submit`. */
|
|
3448
|
+
interface TaskSubmitOptions {
|
|
3449
|
+
/**
|
|
3450
|
+
* Optional user-supplied ID. Must match grammar `^[a-z0-9][a-z0-9_-]*$`
|
|
3451
|
+
* and MUST NOT start with the reserved prefixes `wf-` / `b-` / `cron-`
|
|
3452
|
+
* (D368, EC-5). When omitted, `crypto.randomUUID()` is used.
|
|
3453
|
+
*/
|
|
3454
|
+
readonly id?: string;
|
|
3455
|
+
readonly meta?: Record<string, unknown>;
|
|
3456
|
+
/**
|
|
3457
|
+
* Optional caller-provided AbortSignal. If already aborted at submit
|
|
3458
|
+
* time, the registry short-circuits to `cancelled` without acquiring
|
|
3459
|
+
* a semaphore slot (EC-4).
|
|
3460
|
+
*/
|
|
3461
|
+
readonly signal?: AbortSignal;
|
|
3462
|
+
/**
|
|
3463
|
+
* SE2 — an opt-in {@link import("./run-events.js").RunEventSink}. The task's
|
|
3464
|
+
* lifecycle is forwarded to it as typed `task_started` / `task_updated` /
|
|
3465
|
+
* `task_completed` RunEvents, so a caller that spawned the task can observe it
|
|
3466
|
+
* through the same `onRunEvent` channel as the rest of the run. Best-effort (a
|
|
3467
|
+
* throwing sink never breaks the task). The dedicated `Task.subscribe(id)`
|
|
3468
|
+
* channel is unaffected.
|
|
3469
|
+
*/
|
|
3470
|
+
readonly onRunEvent?: RunEventSink$1;
|
|
3471
|
+
}
|
|
3472
|
+
/** Options shape for `TaskStore` factory (D364). */
|
|
3473
|
+
type TaskStoreOptions = {
|
|
3474
|
+
readonly backend: "memory";
|
|
3475
|
+
} | {
|
|
3476
|
+
readonly backend: "json";
|
|
3477
|
+
readonly dir: string;
|
|
3478
|
+
};
|
|
3479
|
+
/** Result of `Task.cancel` (D365 — idempotent). */
|
|
3480
|
+
interface TaskCancelResult {
|
|
3481
|
+
readonly cancelled: boolean;
|
|
3482
|
+
readonly alreadyTerminal: boolean;
|
|
3483
|
+
}
|
|
3484
|
+
|
|
3485
|
+
/**
|
|
3486
|
+
* `Task` — observable async work registry (Adoption Roadmap gap #2,
|
|
3487
|
+
* ADRs D361-D374).
|
|
3488
|
+
*
|
|
3489
|
+
* Static facade delegating to the in-process `TaskRegistry` singleton.
|
|
3490
|
+
* The lifecycle of any task is the 5-state machine `queued | running |
|
|
3491
|
+
* finished | error | cancelled` (D362). Wrapping `Agent.send` /
|
|
3492
|
+
* `Agent.batch` / `Workflow.run` / `Cron` fires is opt-in via the
|
|
3493
|
+
* `{ task: true }` option on each (D363).
|
|
3494
|
+
*
|
|
3495
|
+
* @public
|
|
3496
|
+
*/
|
|
3497
|
+
|
|
3498
|
+
interface TaskWorkContext {
|
|
3499
|
+
readonly signal: AbortSignal;
|
|
3500
|
+
emit(payload: unknown): void;
|
|
3501
|
+
}
|
|
3502
|
+
/**
|
|
3503
|
+
* The unit of work handed to {@link Task.submit}.
|
|
3504
|
+
*
|
|
3505
|
+
* It receives the context rather than raw arguments: `ctx.signal` aborts on cancel and should be
|
|
3506
|
+
* observed by anything long-running, and `ctx.emit(payload)` produces a `progress` event for
|
|
3507
|
+
* subscribers. May be synchronous — the return type allows a plain value as well as a promise.
|
|
3508
|
+
*
|
|
3509
|
+
* @public
|
|
3510
|
+
*/
|
|
3511
|
+
type TaskWorkFn<T> = (ctx: TaskWorkContext) => Promise<T> | T;
|
|
3512
|
+
/**
|
|
3513
|
+
* Registry-level configuration. May only be applied BEFORE the first
|
|
3514
|
+
* `Task.submit` of the process — see EC-13. Subsequent calls emit a
|
|
3515
|
+
* single stderr line and become no-ops.
|
|
3516
|
+
*/
|
|
3517
|
+
interface TaskConfigureOptions {
|
|
3518
|
+
readonly store?: TaskStoreOptions;
|
|
3519
|
+
readonly maxConcurrent?: number;
|
|
3520
|
+
readonly retentionMs?: number;
|
|
3521
|
+
}
|
|
3522
|
+
/**
|
|
3523
|
+
* Static facade over the process-wide task registry — the observability layer for asynchronous
|
|
3524
|
+
* work.
|
|
3525
|
+
*
|
|
3526
|
+
* Not instantiable: the constructor throws, and every operation is a static that delegates to one
|
|
3527
|
+
* in-process singleton. Tasks are an OPT-IN wrapper. `Agent.send`, `Agent.batch`, `Workflow.run`
|
|
3528
|
+
* and `Cron` fires only appear here when submitted with `{ task: true }`; work you submit yourself
|
|
3529
|
+
* goes through `Task.submit`.
|
|
3530
|
+
*
|
|
3531
|
+
* Two ordering constraints bite in practice. `Task.configure` must run before the first `submit` of
|
|
3532
|
+
* the process — a later call logs one line and is otherwise a no-op. And `Task.get` returning
|
|
3533
|
+
* `undefined` does not mean the id never existed: retention evicts terminal tasks, so an id can go
|
|
3534
|
+
* from known to unknown over time.
|
|
3535
|
+
*
|
|
3536
|
+
* @public
|
|
3537
|
+
*/
|
|
3538
|
+
declare class Task {
|
|
3539
|
+
private constructor();
|
|
3540
|
+
/**
|
|
3541
|
+
* Configure the registry. **Must be called before the first `submit`**
|
|
3542
|
+
* (EC-13). Available knobs: pluggable store (D364), concurrency cap
|
|
3543
|
+
* (D369), and retention (D373).
|
|
3544
|
+
*/
|
|
3545
|
+
static configure(opts: TaskConfigureOptions): void;
|
|
3546
|
+
/**
|
|
3547
|
+
* Submit a unit of asynchronous work to the registry.
|
|
3548
|
+
*
|
|
3549
|
+
* The `work` function receives `{ signal, emit }` — `signal` is the
|
|
3550
|
+
* AbortSignal honored on cancel; `emit(payload)` produces a
|
|
3551
|
+
* `progress` event observable via `Task.subscribe`.
|
|
3552
|
+
*
|
|
3553
|
+
* Returns a `TaskHandle` in `state: "queued"`. Subsequent state
|
|
3554
|
+
* transitions are observable via `Task.subscribe(handle.id)` OR
|
|
3555
|
+
* polled via `Task.get(handle.id)`.
|
|
3556
|
+
*
|
|
3557
|
+
* **Idempotency (D367):** submitting twice with the same `id` returns
|
|
3558
|
+
* the existing handle without re-invoking work.
|
|
3559
|
+
*
|
|
3560
|
+
* **Grammar (D368):** user-supplied ids must match
|
|
3561
|
+
* `^[a-z0-9][a-z0-9_-]*$` and must not start with reserved prefixes
|
|
3562
|
+
* `wf-` / `b-` / `cron-`. Otherwise `InvalidTaskIdError` is thrown.
|
|
3563
|
+
*
|
|
3564
|
+
* **Pre-aborted signal (EC-4):** if `options.signal` is already
|
|
3565
|
+
* aborted, the task short-circuits to `cancelled` without acquiring
|
|
3566
|
+
* a semaphore slot and without invoking `work`.
|
|
3567
|
+
*/
|
|
3568
|
+
static submit<T>(kind: TaskKind, work: TaskWorkFn<T>, options?: TaskSubmitOptions): Promise<TaskHandle>;
|
|
3569
|
+
/** Returns matching handles, capped at `filter.limit ?? 100`. */
|
|
3570
|
+
static list(filter?: TaskFilter): Promise<TaskHandle[]>;
|
|
3571
|
+
/** Returns a single handle by id, or `undefined` if unknown / evicted. */
|
|
3572
|
+
static get(id: string): Promise<TaskHandle | undefined>;
|
|
3573
|
+
/**
|
|
3574
|
+
* Idempotent cancel (D365). Returns:
|
|
3575
|
+
* - `{ cancelled: true, alreadyTerminal: false }` — transitioned
|
|
3576
|
+
* queued/running task to `cancelled`.
|
|
3577
|
+
* - `{ cancelled: false, alreadyTerminal: true }` — task already
|
|
3578
|
+
* terminal.
|
|
3579
|
+
* - `{ cancelled: false, alreadyTerminal: false }` — task unknown.
|
|
3580
|
+
*
|
|
3581
|
+
* Never throws.
|
|
3582
|
+
*/
|
|
3583
|
+
static cancel(id: string, reason?: string): Promise<TaskCancelResult>;
|
|
3584
|
+
/**
|
|
3585
|
+
* Subscribe to a task's event stream. The returned `AsyncIterable<TaskEvent>`
|
|
3586
|
+
* starts by replaying buffered events (ring buffer cap 64, D372) and
|
|
3587
|
+
* then yields live events until a terminal event (finished / errored
|
|
3588
|
+
* / cancelled) is emitted, at which point it closes automatically.
|
|
3589
|
+
*
|
|
3590
|
+
* Calling `.return()` on the iterator (or `break` in a `for await`)
|
|
3591
|
+
* cleans up the subscriber callback (EC-10).
|
|
3592
|
+
*
|
|
3593
|
+
* Throws `TaskNotFoundError` if the id is unknown or has been evicted.
|
|
3594
|
+
*/
|
|
3595
|
+
static subscribe(id: string): AsyncIterable<TaskEvent>;
|
|
3596
|
+
}
|
|
3597
|
+
|
|
3598
|
+
/**
|
|
3599
|
+
* Dynamic provider catalog loader (T10.1, ADR D447).
|
|
3600
|
+
*
|
|
3601
|
+
* Loads provider metadata from `provider-catalog.json` at runtime.
|
|
3602
|
+
* Malformed entries are skipped with WARN (EC-1) — never crash.
|
|
3603
|
+
*
|
|
3604
|
+
* @internal
|
|
3605
|
+
*/
|
|
3606
|
+
|
|
3607
|
+
interface ProviderCapabilities {
|
|
3608
|
+
supportsToolUse: boolean;
|
|
3609
|
+
supportsVision: boolean;
|
|
3610
|
+
supportsStructuredOutput: boolean;
|
|
3611
|
+
supportsStreaming: boolean;
|
|
3612
|
+
supportsCacheControl: boolean;
|
|
3613
|
+
maxContextTokens?: number;
|
|
3614
|
+
maxOutputTokens?: number;
|
|
3615
|
+
}
|
|
3616
|
+
|
|
3617
|
+
/**
|
|
3618
|
+
* Owner: `internal/catalog/` (2 of 3 importers). Derived from the import graph, not declared —
|
|
3619
|
+
* `tests/lint/types-name-their-owner.test.ts` re-derives it.
|
|
3620
|
+
*
|
|
3621
|
+
* Account-level user info returned by `Theokit.me()`.
|
|
3622
|
+
*
|
|
3623
|
+
* @public
|
|
3624
|
+
*/
|
|
3625
|
+
interface SDKUser {
|
|
3626
|
+
apiKeyName: string;
|
|
3627
|
+
userEmail?: string;
|
|
3628
|
+
createdAt: string;
|
|
3629
|
+
}
|
|
3630
|
+
/**
|
|
3631
|
+
* Per-model parameter definition discovered from `Theokit.models.list()`.
|
|
3632
|
+
*
|
|
3633
|
+
* @public
|
|
3634
|
+
*/
|
|
3635
|
+
interface ModelParameterDefinition {
|
|
3636
|
+
id: string;
|
|
3637
|
+
displayName?: string;
|
|
3638
|
+
values: Array<{
|
|
3639
|
+
value: string;
|
|
3640
|
+
displayName?: string;
|
|
3641
|
+
}>;
|
|
3642
|
+
}
|
|
3643
|
+
/**
|
|
3644
|
+
* Preset variant for a model — pre-filled parameter combinations.
|
|
3645
|
+
*
|
|
3646
|
+
* @public
|
|
3647
|
+
*/
|
|
3648
|
+
interface ModelVariant {
|
|
3649
|
+
params: Array<{
|
|
3650
|
+
id: string;
|
|
3651
|
+
value: string;
|
|
3652
|
+
}>;
|
|
3653
|
+
displayName: string;
|
|
3654
|
+
description?: string;
|
|
3655
|
+
isDefault?: boolean;
|
|
3656
|
+
}
|
|
3657
|
+
/**
|
|
3658
|
+
* Single model entry in the catalog.
|
|
3659
|
+
*
|
|
3660
|
+
* @public
|
|
3661
|
+
*/
|
|
3662
|
+
interface ModelListItem {
|
|
3663
|
+
id: string;
|
|
3664
|
+
/** Short, plain-text model name. Mirrors `displayName` for typical SDKs. */
|
|
3665
|
+
name?: string;
|
|
3666
|
+
displayName: string;
|
|
3667
|
+
description?: string;
|
|
3668
|
+
parameters?: ModelParameterDefinition[];
|
|
3669
|
+
variants?: ModelVariant[];
|
|
3670
|
+
}
|
|
3671
|
+
/**
|
|
3672
|
+
* Alias of {@link ModelListItem}, used where a model comes back from the Theokit platform rather
|
|
3673
|
+
* than from a catalog listing.
|
|
3674
|
+
*
|
|
3675
|
+
* It is the SAME type, not a narrowed one — the alias exists so platform-facing signatures read in
|
|
3676
|
+
* platform vocabulary alongside `SDKRepository` and `SDKUser`, and a value of either name is
|
|
3677
|
+
* assignable to the other.
|
|
3678
|
+
*
|
|
3679
|
+
* @public
|
|
3680
|
+
*/
|
|
3681
|
+
type SDKModel = ModelListItem;
|
|
3682
|
+
/**
|
|
3683
|
+
* GitHub repository connected to the team. Cloud-only.
|
|
3684
|
+
*
|
|
3685
|
+
* @public
|
|
3686
|
+
*/
|
|
3687
|
+
interface SDKRepository {
|
|
3688
|
+
url: string;
|
|
3689
|
+
}
|
|
3690
|
+
|
|
3691
|
+
/**
|
|
3692
|
+
* Options shared by every `Theokit.*` request.
|
|
3693
|
+
*
|
|
3694
|
+
* @public
|
|
3695
|
+
*/
|
|
3696
|
+
interface TheokitRequestOptions {
|
|
3697
|
+
/** Override the `THEOKIT_API_KEY` env var for this call. */
|
|
3698
|
+
apiKey?: string;
|
|
3699
|
+
/**
|
|
3700
|
+
* Target a specific provider for catalog reads. When set to a provider
|
|
3701
|
+
* with `authType: "none"` (e.g. `"ollama"`, `"lmstudio"`, `"llamacpp"`),
|
|
3702
|
+
* `Theokit.models.list({ provider })` reads from the provider's local
|
|
3703
|
+
* `/v1/models` endpoint instead of the TheoCloud catalog. ADR D184.
|
|
3704
|
+
*
|
|
3705
|
+
* @public
|
|
3706
|
+
*/
|
|
3707
|
+
provider?: string;
|
|
3708
|
+
}
|
|
3709
|
+
/**
|
|
3710
|
+
* Account-level and catalog reads. All methods accept an optional `apiKey`
|
|
3711
|
+
* and otherwise fall back to the `THEOKIT_API_KEY` environment variable.
|
|
3712
|
+
*
|
|
3713
|
+
* @public
|
|
3714
|
+
*/
|
|
3715
|
+
declare class Theokit {
|
|
3716
|
+
private constructor();
|
|
3717
|
+
/**
|
|
3718
|
+
* Return the user behind the current API key.
|
|
3719
|
+
*
|
|
3720
|
+
* @public
|
|
3721
|
+
*/
|
|
3722
|
+
static me(options?: TheokitRequestOptions): Promise<SDKUser>;
|
|
3723
|
+
/**
|
|
3724
|
+
* Model catalog reads.
|
|
3725
|
+
*
|
|
3726
|
+
* @public
|
|
3727
|
+
*/
|
|
3728
|
+
static readonly models: {
|
|
3729
|
+
list: (options?: TheokitRequestOptions) => Promise<SDKModel[]>;
|
|
3730
|
+
capabilities: (providerOrModelId: string) => ProviderCapabilities | undefined;
|
|
3731
|
+
};
|
|
3732
|
+
/**
|
|
3733
|
+
* Connected GitHub repositories for the calling user's team. Cloud only.
|
|
3734
|
+
*
|
|
3735
|
+
* @public
|
|
3736
|
+
*/
|
|
3737
|
+
static readonly repositories: {
|
|
3738
|
+
list: (options?: TheokitRequestOptions) => Promise<SDKRepository[]>;
|
|
3739
|
+
};
|
|
3740
|
+
/**
|
|
3741
|
+
* Provider catalog. Lists every provider known to the platform, including
|
|
3742
|
+
* plugin-registered ones, with capability and availability metadata.
|
|
3743
|
+
*
|
|
3744
|
+
* @public
|
|
3745
|
+
*/
|
|
3746
|
+
static readonly providers: {
|
|
3747
|
+
list: (options?: TheokitRequestOptions) => Promise<SDKProvider[]>;
|
|
3748
|
+
};
|
|
3749
|
+
/**
|
|
3750
|
+
* Local introspection of bundled SDK assets (ADR D201). Unlike the
|
|
3751
|
+
* cloud-catalog `providers.list()` (which hits the TheoCloud HTTP API),
|
|
3752
|
+
* `inspect.*` reads the SDK's own bundled registries — useful for
|
|
3753
|
+
* tooling (e.g. `@theokit/cli`'s `theokit inspect`) that needs to know
|
|
3754
|
+
* what's available WITHOUT a network round-trip.
|
|
3755
|
+
*
|
|
3756
|
+
* @public
|
|
3757
|
+
*/
|
|
3758
|
+
static readonly inspect: {
|
|
3759
|
+
builtinProviders: () => Array<{
|
|
3760
|
+
readonly name: string;
|
|
3761
|
+
readonly apiMode: string;
|
|
3762
|
+
readonly authType: string;
|
|
3763
|
+
readonly baseUrl: string;
|
|
3764
|
+
readonly aliases?: ReadonlyArray<string>;
|
|
3765
|
+
readonly envVars: ReadonlyArray<string>;
|
|
3766
|
+
}>;
|
|
3767
|
+
embeddingAdapters: () => Array<{
|
|
3768
|
+
readonly id: string;
|
|
3769
|
+
readonly transport: string;
|
|
3770
|
+
readonly defaultModel: string;
|
|
3771
|
+
}>;
|
|
3772
|
+
};
|
|
3773
|
+
}
|
|
3774
|
+
|
|
3775
|
+
/**
|
|
3776
|
+
* Attach a blast-radius declaration to a tool, so the approval layer gates on what the tool DOES.
|
|
3777
|
+
*
|
|
3778
|
+
* Without this the only key available to a policy is the tool's NAME, which says nothing about the
|
|
3779
|
+
* action, drifts the moment a tool is renamed, and cannot be reviewed by anyone who did not write
|
|
3780
|
+
* it. `delete_namespace` and `list_pods` differ by a word.
|
|
3781
|
+
*
|
|
3782
|
+
* ## Why a wrapper rather than a field on the input schema
|
|
3783
|
+
*
|
|
3784
|
+
* `inputSchema` is what the MODEL sees. Blast radius is not for the model — it is for the approval
|
|
3785
|
+
* layer — and putting it there would leak policy into the prompt and let a model-authored argument
|
|
3786
|
+
* influence its own gate. The declaration rides alongside the tool instead, under a symbol so it
|
|
3787
|
+
* cannot collide with a tool's own properties or be serialised into a prompt by accident.
|
|
3788
|
+
*
|
|
3789
|
+
* @public
|
|
3790
|
+
*/
|
|
3791
|
+
|
|
3792
|
+
/**
|
|
3793
|
+
* Symbol-keyed on purpose. THAT is what keeps the declaration out of a prompt: `Object.keys` and
|
|
3794
|
+
* `JSON.stringify` both ignore symbol keys, so a tool serialised on its way to the model carries
|
|
3795
|
+
* none of it. A string key would also risk colliding with a property the tool already has.
|
|
3796
|
+
*
|
|
3797
|
+
* Exported because the `@public` `WithBlastRadius<T>` below uses it as a COMPUTED
|
|
3798
|
+
* KEY. A computed key is part of the type it keys, so the emitted declaration
|
|
3799
|
+
* names this const — and a name the declaration file does not carry is a broken
|
|
3800
|
+
* reference (#335). `Symbol.for` keeps it a registry symbol, so an exported
|
|
3801
|
+
* binding does not weaken the property-hiding this comment describes: the value
|
|
3802
|
+
* was always retrievable by any code that knows the string.
|
|
3803
|
+
*
|
|
3804
|
+
* @public
|
|
3805
|
+
*/
|
|
3806
|
+
declare const DECLARED: unique symbol;
|
|
3807
|
+
/**
|
|
3808
|
+
* A tool that may carry a blast-radius declaration under {@link DECLARED}.
|
|
3809
|
+
*
|
|
3810
|
+
* The property is OPTIONAL in the type, so a plain tool is assignable to it and the type alone
|
|
3811
|
+
* never proves a declaration was made. `describeAction` is what tells the two apart at runtime.
|
|
3812
|
+
*
|
|
3813
|
+
* @public
|
|
3814
|
+
*/
|
|
3815
|
+
type WithBlastRadius<T> = T & {
|
|
3816
|
+
readonly [DECLARED]?: DeclaredAction;
|
|
3817
|
+
};
|
|
3818
|
+
/**
|
|
3819
|
+
* Declare what a tool reaches, for the approval layer rather than for the model.
|
|
3820
|
+
*
|
|
3821
|
+
* This MUTATES `tool` — it defines a symbol-keyed property on the object it was given and hands
|
|
3822
|
+
* the same reference back, so every existing reference to that tool sees the declaration too.
|
|
3823
|
+
* Calling it again on the same tool replaces the previous declaration; the property is
|
|
3824
|
+
* `configurable`, so re-declaring never throws.
|
|
3825
|
+
*
|
|
3826
|
+
* The declaration is invisible to `Object.keys` and `JSON.stringify` because the key is a symbol,
|
|
3827
|
+
* which is what keeps it out of anything serialised into a prompt.
|
|
3828
|
+
*
|
|
3829
|
+
* @returns the same tool, with its action declared. The tool is not otherwise altered — the model
|
|
3830
|
+
* must see exactly what it saw before.
|
|
3831
|
+
* @public
|
|
3832
|
+
*/
|
|
3833
|
+
declare function withBlastRadius<T extends object>(tool: T, action: DeclaredAction): WithBlastRadius<T>;
|
|
3834
|
+
/**
|
|
3835
|
+
* Read back the action a tool declared, if any.
|
|
3836
|
+
*
|
|
3837
|
+
* This is how an approval layer obtains the `action` for `evaluateBlastRadius`. An `undefined`
|
|
3838
|
+
* result means nobody has reviewed this tool's reach, which is a different fact from a tool that
|
|
3839
|
+
* declared a narrow scope — decide what to do with the unreviewed case explicitly rather than
|
|
3840
|
+
* treating it as harmless.
|
|
3841
|
+
*
|
|
3842
|
+
* @returns the declared action, or `undefined` when the tool never declared one — NOT an empty
|
|
3843
|
+
* action. "Never declared" and "declared as reaching nothing" are different facts, and collapsing
|
|
3844
|
+
* them is how an unreviewed tool passes as harmless.
|
|
3845
|
+
* @public
|
|
3846
|
+
*/
|
|
3847
|
+
declare function describeAction(tool: object): DeclaredAction | undefined;
|
|
3848
|
+
|
|
3849
|
+
/**
|
|
3850
|
+
* SE7 — `ToolError`: thrown FROM a tool `handler` to report a failure back to
|
|
3851
|
+
* the model with structured content (text and/or an image), not just a string.
|
|
3852
|
+
* Kept in its own module (not `errors.ts`) so the error taxonomy file stays
|
|
3853
|
+
* under the G8 LoC budget and this tool-shaped error lives next to the tool
|
|
3854
|
+
* surface it serves.
|
|
3855
|
+
*
|
|
3856
|
+
* @public
|
|
3857
|
+
*/
|
|
3858
|
+
|
|
3859
|
+
/**
|
|
3860
|
+
* Thrown from a tool `handler` to surface a failure to the model. The SDK turns
|
|
3861
|
+
* it into a `tool_result` with `isError: true` carrying the content. A plain
|
|
3862
|
+
* `Error` thrown from a handler still works (its message becomes text);
|
|
3863
|
+
* `ToolError` is the opt-in for a clean message or a multimodal error (e.g. an
|
|
3864
|
+
* error screenshot).
|
|
3865
|
+
*
|
|
3866
|
+
* @public
|
|
3867
|
+
*/
|
|
3868
|
+
declare class ToolError extends TheokitAgentError {
|
|
3869
|
+
readonly name: string;
|
|
3870
|
+
/** The error content surfaced to the model: a string, or text/image blocks. */
|
|
3871
|
+
readonly content: string | ToolResultContentBlock[];
|
|
3872
|
+
constructor(content: string | ToolResultContentBlock[], options?: {
|
|
3873
|
+
code?: string;
|
|
3874
|
+
cause?: unknown;
|
|
3875
|
+
metadata?: ErrorMetadata;
|
|
3876
|
+
});
|
|
3877
|
+
}
|
|
3878
|
+
|
|
3879
|
+
/**
|
|
3880
|
+
* Owner: `src/` (1 of 1 importers). Derived from the import graph, not declared —
|
|
3881
|
+
* `tests/lint/types-name-their-owner.test.ts` re-derives it.
|
|
3882
|
+
*
|
|
3883
|
+
* Public types for ShareGPT trajectory export (ADR D139).
|
|
3884
|
+
*
|
|
3885
|
+
* Output format for fine-tuning datasets — consumed by HuggingFace, Axolotl,
|
|
3886
|
+
* LLaMA-Factory, and most modern fine-tuning toolchains. Pure data shape;
|
|
3887
|
+
* no runtime dependency.
|
|
3888
|
+
*
|
|
3889
|
+
* @public
|
|
3890
|
+
*/
|
|
3891
|
+
/**
|
|
3892
|
+
* One ShareGPT message in a conversation. `from` identifies the role and
|
|
3893
|
+
* `value` carries the textual content. Tool calls live in `tool_calls`
|
|
3894
|
+
* (assistant-only) and tool results re-enter as `from: "tool"` entries.
|
|
3895
|
+
*
|
|
3896
|
+
* @public
|
|
3897
|
+
*/
|
|
3898
|
+
interface ShareGptMessage {
|
|
3899
|
+
/** "human" for user, "gpt" for assistant, "tool" for tool result, "system" for system. */
|
|
3900
|
+
from: "human" | "gpt" | "tool" | "system";
|
|
3901
|
+
/** The message text. Empty string is valid (preserves turn boundary). */
|
|
3902
|
+
value: string;
|
|
3903
|
+
/** Optional tool calls — only emitted when `from === "gpt"`. */
|
|
3904
|
+
tool_calls?: Array<{
|
|
3905
|
+
name: string;
|
|
3906
|
+
arguments: Record<string, unknown>;
|
|
3907
|
+
}>;
|
|
3908
|
+
}
|
|
3909
|
+
/**
|
|
3910
|
+
* One full ShareGPT-format trajectory — a single conversation plus
|
|
3911
|
+
* metadata. JSONL-friendly (one trajectory per line when serialized).
|
|
3912
|
+
*
|
|
3913
|
+
* @public
|
|
3914
|
+
*/
|
|
3915
|
+
interface ShareGptTrajectory {
|
|
3916
|
+
conversations: ShareGptMessage[];
|
|
3917
|
+
metadata?: {
|
|
3918
|
+
model?: string;
|
|
3919
|
+
timestamp: string;
|
|
3920
|
+
durationMs: number;
|
|
3921
|
+
promptIndex: number;
|
|
3922
|
+
};
|
|
3923
|
+
/** `true` when the source `BatchResult.ok === true`. Always `true` in current shape. */
|
|
3924
|
+
completed: boolean;
|
|
3925
|
+
/** Token usage when surfaced by the underlying RunResult (provider-specific). */
|
|
3926
|
+
usage?: {
|
|
3927
|
+
inputTokens: number;
|
|
3928
|
+
outputTokens: number;
|
|
3929
|
+
};
|
|
3930
|
+
}
|
|
3931
|
+
|
|
3932
|
+
/**
|
|
3933
|
+
* `toShareGptTrajectory` — opt-in BatchResult → ShareGPT converter (ADR D139).
|
|
3934
|
+
*
|
|
3935
|
+
* Pure transformation. Returns `null` for failed results so callers can
|
|
3936
|
+
* filter via `.map(toShareGptTrajectory).filter(Boolean)`. Tool calls and
|
|
3937
|
+
* tool results are preserved when an SDKMessage trace is provided; otherwise
|
|
3938
|
+
* a minimal `human → gpt` trajectory is emitted from the final text.
|
|
3939
|
+
*
|
|
3940
|
+
* @public
|
|
3941
|
+
*/
|
|
3942
|
+
|
|
3943
|
+
/**
|
|
3944
|
+
* Convert a successful `BatchResult` to ShareGPT-format trajectory.
|
|
3945
|
+
*
|
|
3946
|
+
* Behavior:
|
|
3947
|
+
* - `result.ok === false` → returns `null` (EC-11).
|
|
3948
|
+
* - First entry is always `{from: "human", value: result.prompt}`.
|
|
3949
|
+
* - When `options.messages` is supplied, each SDKMessage maps to one or
|
|
3950
|
+
* more ShareGPT entries (assistant text → gpt, tool_use → gpt + tool).
|
|
3951
|
+
* - Without `options.messages`, fall back to a single `{from: "gpt"}`
|
|
3952
|
+
* entry carrying `result.result.result` (the final text) when present.
|
|
3953
|
+
* - Malformed message entries are silently skipped (EC-F / EC-14).
|
|
3954
|
+
*
|
|
3955
|
+
* @public
|
|
3956
|
+
*/
|
|
3957
|
+
declare function toShareGptTrajectory(result: BatchResult, options?: {
|
|
3958
|
+
messages?: SDKMessage[];
|
|
3959
|
+
model?: string;
|
|
3960
|
+
}): ShareGptTrajectory | null;
|
|
3961
|
+
|
|
3962
|
+
/**
|
|
3963
|
+
* Decide what a project directory is allowed to switch on.
|
|
3964
|
+
*
|
|
3965
|
+
* A product that reads a repository has to answer this before it builds anything: are that
|
|
3966
|
+
* repository's hooks honoured, are its MCP servers started, do its instructions enter the persona?
|
|
3967
|
+
* The stakes are not configuration-shaped. A hook is arbitrary command execution on every tool
|
|
3968
|
+
* call, and an MCP server is an external process SPAWNED while the agent is built — before any
|
|
3969
|
+
* per-tool approval exists to refuse it. A product that gets this wrong grants local execution on
|
|
3970
|
+
* first build, in a directory the user only meant to open.
|
|
3971
|
+
*
|
|
3972
|
+
* ## What this is, and what it deliberately is not
|
|
3973
|
+
*
|
|
3974
|
+
* The arithmetic is small: pick a level, derive one boolean per capability. The value is the
|
|
3975
|
+
* INVARIANT — untrusted means EVERY declared capability is off, and `allows` is built FROM the
|
|
3976
|
+
* declared list, so a product that adds a ninth capability cannot forget to gate it. That failure
|
|
3977
|
+
* is invisible when it happens: the new capability simply works in a directory where it should not,
|
|
3978
|
+
* and nothing reports anything.
|
|
3979
|
+
*
|
|
3980
|
+
* It does NOT decide what "trusted" means. Where the record lives, what the environment variable is
|
|
3981
|
+
* called, whether a legacy alias is still honoured — all of that is the consumer's, because all of
|
|
3982
|
+
* it is that product's vocabulary. The framework owns the shape of the answer and the guarantee
|
|
3983
|
+
* that the answer covers everything declared.
|
|
3984
|
+
*
|
|
3985
|
+
* ## Why `source` is reported
|
|
3986
|
+
*
|
|
3987
|
+
* "Trusted because the operator recorded this directory" and "trusted because a blanket environment
|
|
3988
|
+
* switch is on" are different facts. A surface that only shows `trusted` cannot warn about the
|
|
3989
|
+
* second, which is the one that stays on across every directory the process ever opens.
|
|
3990
|
+
*
|
|
3991
|
+
* @public
|
|
3992
|
+
*/
|
|
3993
|
+
/**
|
|
3994
|
+
* Whether a project directory may switch anything on.
|
|
3995
|
+
*
|
|
3996
|
+
* There is no middle level on purpose: `untrusted` means every declared capability is off, not
|
|
3997
|
+
* "some are off". A product that wants a partial grant expresses it by declaring fewer capabilities
|
|
3998
|
+
* for that call, not by inventing a third level here.
|
|
3999
|
+
*
|
|
4000
|
+
* @public
|
|
4001
|
+
*/
|
|
4002
|
+
type TrustLevel = "trusted" | "untrusted";
|
|
4003
|
+
/** Where the decision came from. @public */
|
|
4004
|
+
type TrustSource = "env" | "store" | "default";
|
|
4005
|
+
/**
|
|
4006
|
+
* What the decision is made from: the capability vocabulary, a way to read the operator's record,
|
|
4007
|
+
* and an optional blanket override.
|
|
4008
|
+
*
|
|
4009
|
+
* `capabilities` is load-bearing rather than descriptive — the returned `allows` is built from
|
|
4010
|
+
* exactly this list, so a capability missing from it is a capability nothing gates.
|
|
4011
|
+
*
|
|
4012
|
+
* @public
|
|
4013
|
+
*/
|
|
4014
|
+
interface TrustPostureInput<K extends string> {
|
|
4015
|
+
/**
|
|
4016
|
+
* Every capability a repository could switch on. `allows` is built from exactly this list — the
|
|
4017
|
+
* guarantee that nothing is left ungated.
|
|
4018
|
+
*/
|
|
4019
|
+
readonly capabilities: readonly K[];
|
|
4020
|
+
/**
|
|
4021
|
+
* Whether the operator has recorded this directory as trusted. Called at most once, and not at
|
|
4022
|
+
* all when `envOverride` already granted trust — it may touch the filesystem.
|
|
4023
|
+
*/
|
|
4024
|
+
readonly isTrusted: () => boolean;
|
|
4025
|
+
/**
|
|
4026
|
+
* A blanket override from the consumer's own environment vocabulary. `true` grants trust;
|
|
4027
|
+
* `false` and `undefined` both mean "the operator did not switch it on" — NOT "switched it off",
|
|
4028
|
+
* because an unset variable must not override a trusted store.
|
|
4029
|
+
*/
|
|
4030
|
+
readonly envOverride?: boolean;
|
|
4031
|
+
}
|
|
4032
|
+
/**
|
|
4033
|
+
* The decision: the level, where it came from, and one boolean per declared capability.
|
|
4034
|
+
*
|
|
4035
|
+
* `allows` has exactly the keys of the `capabilities` list it was built from, so reading a
|
|
4036
|
+
* capability the caller never declared is a type error rather than a silent `undefined` that a
|
|
4037
|
+
* consumer would read as "not allowed".
|
|
4038
|
+
*
|
|
4039
|
+
* @public
|
|
4040
|
+
*/
|
|
4041
|
+
interface TrustPosture<K extends string> {
|
|
4042
|
+
readonly level: TrustLevel;
|
|
4043
|
+
readonly source: TrustSource;
|
|
4044
|
+
/** One entry per declared capability. Every value is `false` when the level is untrusted. */
|
|
4045
|
+
readonly allows: Readonly<Record<K, boolean>>;
|
|
4046
|
+
}
|
|
4047
|
+
/**
|
|
4048
|
+
* Decide what a project directory is allowed to switch on.
|
|
4049
|
+
*
|
|
4050
|
+
* Precedence: `envOverride === true` grants trust and SHORT-CIRCUITS — `isTrusted` is not called at
|
|
4051
|
+
* all, which matters because it may touch the filesystem. Otherwise `isTrusted()` is called exactly
|
|
4052
|
+
* once and its answer decides. `envOverride === false` is not a denial: it falls through to the
|
|
4053
|
+
* store like `undefined` does, so an unset or explicitly-off environment switch can never revoke a
|
|
4054
|
+
* directory the operator recorded as trusted.
|
|
4055
|
+
*
|
|
4056
|
+
* Every entry of `allows` is `false` whenever the level is untrusted, and the entries are generated
|
|
4057
|
+
* from `capabilities` rather than supplied per capability — that is what makes "nothing was left
|
|
4058
|
+
* ungated" a property of the call instead of a habit of the caller.
|
|
4059
|
+
*
|
|
4060
|
+
* @public
|
|
4061
|
+
*/
|
|
4062
|
+
declare function resolveTrustPosture<K extends string>(input: TrustPostureInput<K>): TrustPosture<K>;
|
|
4063
|
+
|
|
4064
|
+
/**
|
|
4065
|
+
* Record what a build actually wired, as opposed to what configuration asked for.
|
|
4066
|
+
*
|
|
4067
|
+
* A product that reads a project directory decides, while building, which of that directory's
|
|
4068
|
+
* entities it will honour: MCP servers, skills, hook events, commands. When a trust posture withholds
|
|
4069
|
+
* them, the build simply proceeds with fewer — and every surface that later asks "what is loaded?"
|
|
4070
|
+
* sees an empty list. Empty because nothing was configured and empty because everything was withheld
|
|
4071
|
+
* are the same emptiness to the reader, and only one of them is something they can act on.
|
|
4072
|
+
*
|
|
4073
|
+
* ## Why this is not a re-read
|
|
4074
|
+
*
|
|
4075
|
+
* The obvious implementation of any "what is loaded?" listing is to read the configuration again.
|
|
4076
|
+
* That is the defect this exists to prevent: a re-read cannot detect a disagreement between what
|
|
4077
|
+
* config asked for and what the build did, because it IS the config. The two disagree exactly when
|
|
4078
|
+
* something suppressed an entity, which is the case worth reporting.
|
|
4079
|
+
*
|
|
4080
|
+
* So this function is pure and parameterized. It performs no I/O, which is what makes "no second
|
|
4081
|
+
* read" checkable rather than promised — the caller passes the values it handed to the builder, at
|
|
4082
|
+
* the moment it handed them over, and what comes back is an observation of that moment.
|
|
4083
|
+
*
|
|
4084
|
+
* ## What is generic here, and what is not
|
|
4085
|
+
*
|
|
4086
|
+
* The RULE is generic: for each capability, active is the request when allowed and empty when not,
|
|
4087
|
+
* and suppression is only claimed when something was actually removed. The VOCABULARY is not —
|
|
4088
|
+
* which capabilities exist and what the entities are called belong to the product, and arrive as
|
|
4089
|
+
* data.
|
|
4090
|
+
*
|
|
4091
|
+
* @public
|
|
4092
|
+
*/
|
|
4093
|
+
|
|
4094
|
+
/** Raised when a recorded capability has no entry in the gate. @public */
|
|
4095
|
+
declare class UngatedCapabilityError extends TheokitAgentError {
|
|
4096
|
+
readonly name = "UngatedCapabilityError";
|
|
4097
|
+
}
|
|
4098
|
+
/** What one capability asked for, and what it got. @public */
|
|
4099
|
+
interface WiredEntity {
|
|
4100
|
+
/** The names actually handed to the builder. Empty when the capability was withheld. */
|
|
4101
|
+
readonly active: readonly string[];
|
|
4102
|
+
/**
|
|
4103
|
+
* The names configuration ASKED for. Equal to `active` when nothing was withheld; the difference
|
|
4104
|
+
* is exactly what the reader cannot otherwise see.
|
|
4105
|
+
*/
|
|
4106
|
+
readonly requested: readonly string[];
|
|
4107
|
+
/**
|
|
4108
|
+
* True only when the gate is what emptied `active`.
|
|
4109
|
+
*
|
|
4110
|
+
* Deliberately false for a withheld capability that requested nothing: an untrusted directory with
|
|
4111
|
+
* no skills and a trusted one with no skills are the same emptiness, and a flag that fires when
|
|
4112
|
+
* nothing happened teaches the reader to ignore it.
|
|
4113
|
+
*/
|
|
4114
|
+
readonly suppressedByTrust: boolean;
|
|
4115
|
+
}
|
|
4116
|
+
/**
|
|
4117
|
+
* The two halves of the observation: the gate that was applied, and what was handed to the builder.
|
|
4118
|
+
*
|
|
4119
|
+
* `requested` drives the shape of the record — the result has exactly its keys — while `posture`
|
|
4120
|
+
* only has to contain a gate for each of them. A posture that gates MORE than `requested` covers is
|
|
4121
|
+
* fine and normal; a posture that gates FEWER is refused, see `recordWiring`.
|
|
4122
|
+
*
|
|
4123
|
+
* Pass the values at the moment they go to the builder. Re-deriving them from configuration
|
|
4124
|
+
* afterwards would defeat the point: config is what was asked for, and the disagreement with what
|
|
4125
|
+
* was wired is the only thing this records.
|
|
4126
|
+
*
|
|
4127
|
+
* @public
|
|
4128
|
+
*/
|
|
4129
|
+
interface WiringRecordInput<K extends string> {
|
|
4130
|
+
/**
|
|
4131
|
+
* The gate. Typically the output of `resolveTrustPosture`, which is what makes the name
|
|
4132
|
+
* `suppressedByTrust` accurate rather than decorative — a posture is the only thing in this
|
|
4133
|
+
* package that withholds a capability.
|
|
4134
|
+
*
|
|
4135
|
+
* It may gate MORE than `requested` covers: a posture also gates things that are not lists of
|
|
4136
|
+
* names, like durable memory. Those are not entities and do not appear in the record.
|
|
4137
|
+
*/
|
|
4138
|
+
readonly posture: {
|
|
4139
|
+
readonly allows: Readonly<Record<string, boolean>>;
|
|
4140
|
+
};
|
|
4141
|
+
/** Per capability, the entity names the build was given. Drives which keys the record has. */
|
|
4142
|
+
readonly requested: Readonly<Record<K, readonly string[]>>;
|
|
4143
|
+
}
|
|
4144
|
+
/**
|
|
4145
|
+
* Record what a build actually wired, per capability.
|
|
4146
|
+
*
|
|
4147
|
+
* For each key of `requested`: `active` is a copy of the requested names when the posture allows
|
|
4148
|
+
* that capability and an empty array when it does not, `requested` is always a copy of what was
|
|
4149
|
+
* asked for, and `suppressedByTrust` is true only when the gate emptied a NON-EMPTY request. A
|
|
4150
|
+
* withheld capability that requested nothing reports `false`, because a flag that fires when
|
|
4151
|
+
* nothing happened is a flag readers learn to ignore.
|
|
4152
|
+
*
|
|
4153
|
+
* Pure and synchronous — it performs no I/O, which is what makes "this is not a second read of the
|
|
4154
|
+
* configuration" checkable rather than promised.
|
|
4155
|
+
*
|
|
4156
|
+
* @returns one entry per key of `requested`, each a snapshot rather than a view of the caller's
|
|
4157
|
+
* arrays — the record is read long after the build, and aliasing would make it answer with what
|
|
4158
|
+
* the process holds now instead of with what was wired.
|
|
4159
|
+
* @throws UngatedCapabilityError when a key of `requested` has no entry in `posture.allows`. Absent
|
|
4160
|
+
* is not read as denied: reporting a capability nobody gates as suppressed would send the reader
|
|
4161
|
+
* looking for a trust setting that does not exist.
|
|
4162
|
+
* @public
|
|
4163
|
+
*/
|
|
4164
|
+
declare function recordWiring<K extends string>(input: WiringRecordInput<K>): Readonly<Record<K, WiredEntity>>;
|
|
4165
|
+
|
|
4166
|
+
export { Agent, AgentBuilder, AgentDefinition, type AgentDescription, AgentFactory, AgentOperationOptions, AgentOptions, type AgentPromptResult, type AgentRegistryOptions, type ApprovalDecision, type ApprovalInput, type ApprovalMode, type ApprovalOutcome, type ApprovalReason, type BatchItem, type BatchOptions, type BatchProgress, type BatchResult, type BlastRadiusDecision, type BlastRadiusInput, type BlastRadiusOutcome, type BlastRadiusReason, Budget, BudgetHandle, BudgetOptions, BudgetSnapshot, type BudgetTracker, CloudOptions, ContextSettings, type CounterBudgetTrackerOptions, type CredentialInput, type CredentialReport, type CustomTool, type DeclaredAction, type DeclaredLayer, type DeepPartial, type DefineProviderOptions, type DefineToolSpec, type DiagnosticsSink, type DreamingSweepOptions, type DreamingSweepResult, type EnvOptOut, type EnvReachabilityAudit, type EnvReachabilityInput, ErrorMetadata, EventBus, type EvictReason, GOAL_CONTINUATION_MARKER, GenerateObjectError, type GenerateObjectOptions, type GenerateObjectResult, GetAgentOptions, GetRunOptions, GoalEvent, type GoalLoopAgent, GoalOptions, GoalResult, InlineSkill, JobQueue, type JobQueueOptions, JudgeCredentialError, type JudgeResult, type KeepReason, type KeptArtifact, LayerOrderError, type LayerValues, ListAgentsOptions, ListResult, ListRunsOptions, type LiveAgentRegistry, LiveSessionError, type LiveSessionReason, LocalOptions, McpServerConfig, Memory, MemoryId, type MemoryProvider, MemorySettings, type MigrateOptions, type MigrateResult, type ModelListItem, type ModelParameterDefinition, ModelSelection, type ModelVariant, NoopMemoryProvider, type NormalizedJsonSchema, type OTelSpan, type PermissionAction, PermissionEngine, type PermissionEngineOptions, type PermissionGate, type PermissionGateContext, type PermissionGateDecision, PermissionMode, PermissionPlugin, type PermissionPluginOptions, type PermissionRule, Plugin, PluginsSettings, PreToolCallDecision, type Processor, Provider, type ProviderProfile, ProviderRoutingSettings, type ReadSessionMessagesOptions, type ReapPlan, type ReapPlanInput, type ReapableArtifact, type RetentionPolicy, RetentionPolicyError, Run, RunEventSink$1 as RunEventSink, RunResult, type SDKAgent, SDKAgentInfo, SDKMessage, type SDKModel, SDKProvider, type SDKRepository, type SDKUser, SOVEREIGN_ENV_KEYS, Security, type SecurityFloorInput, type SessionMessage, type SessionMessagePart, type SessionScope, type ShareGptMessage, type ShareGptTrajectory, SkillReadTool, SkillsSettings, type SovereignEnvKey, Squad, type SquadOptions, type SquadRun, StreamObjectError, type StreamObjectEvent, type StreamObjectOptions, SystemPromptResolver, TASK_RESERVED_PREFIXES, Task, type TaskCancelResult, type TaskConfigureOptions, type TaskEvent, type TaskFilter, type TaskHandle, type TaskKind, type TaskState, type TaskStoreOptions, type TaskSubmitOptions, type TaskWorkContext, type TaskWorkFn, type TelemetryHandle, Theokit, TheokitAgentError, type TheokitRequestOptions, TokenLimiter, type TokenLimiterOptions, Tool, ToolError, type ToolResultContentBlock, type TrustLevel, type TrustPosture, type TrustPostureInput, type TrustSource, UngatedCapabilityError, UnicodeNormalizer, type UnicodeNormalizerOptions, UsageAccumulator, type WiredEntity, type WiringRecordInput, type WithBlastRadius, applyMode, applySecurityFloor, auditEnvReachability, chargeAndCheckThresholds, computeCost, createCounterBudgetTracker, decideApproval, describeAction, describeCredential, emitRunEvent, estimateTokens, evaluateBlastRadius, extractRawId, foldLayers, getPricingEntry, guardSessionDestruction, inferApiMode, isValidTaskId, loadProjectEnv, migrateSqliteToLance, mkMemoryId, normalizeSchema, normalizeUsage, planReaping, preflightCheck, readSessionMessages, recordWiring, resolveTrustPosture, runGoalLoop, scopedConversationId, sessionScopePrefix, setDiagnosticsSink, toShareGptTrajectory, verifyLayerOrdering, withBlastRadius, withCwdMutex };
|