@theokit/sdk 4.63.4 → 5.0.0-next.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (786) hide show
  1. package/CHANGELOG.md +847 -23
  2. package/dist/a2a/index.cjs +29 -13
  3. package/dist/a2a/index.cjs.map +1 -1
  4. package/dist/a2a/index.d.cts +1 -1
  5. package/dist/a2a/index.d.ts +1 -1
  6. package/dist/a2a/index.js +26 -11
  7. package/dist/a2a/index.js.map +1 -1
  8. package/dist/a2a/message-bus.d.cts +26 -3
  9. package/dist/a2a/message-bus.d.ts +26 -3
  10. package/dist/a2a/subagent.d.cts +8 -3
  11. package/dist/a2a/subagent.d.ts +8 -3
  12. package/dist/{agent-X0DKA943.d.cts → agent-C3KO5LKm.d.cts} +251 -36
  13. package/dist/{agent-BFno7Sfn.d.ts → agent-CvmTR9uf.d.ts} +251 -36
  14. package/dist/agent-GPV2JWZG.cjs +67 -0
  15. package/dist/{agent-UX7WFI6B.cjs.map → agent-GPV2JWZG.cjs.map} +1 -1
  16. package/dist/agent-Y24I5JBM.js +58 -0
  17. package/dist/{agent-A5XMIVNP.js.map → agent-Y24I5JBM.js.map} +1 -1
  18. package/dist/agent-session-store-AFML3AXC.js +6 -0
  19. package/dist/{agent-session-store-OPGRB4XM.js.map → agent-session-store-AFML3AXC.js.map} +1 -1
  20. package/dist/agent-session-store-MTSIY3MH.cjs +23 -0
  21. package/dist/{agent-session-store-6EL5NPA4.cjs.map → agent-session-store-MTSIY3MH.cjs.map} +1 -1
  22. package/dist/agent.d.ts +1 -1
  23. package/dist/auth/index.cjs +33 -34
  24. package/dist/auth/index.cjs.map +1 -1
  25. package/dist/auth/index.d.cts +1 -1
  26. package/dist/auth/index.d.ts +1 -1
  27. package/dist/auth/index.js +6 -7
  28. package/dist/auth/index.js.map +1 -1
  29. package/dist/{batch-BXYTW2DP.cjs → batch-I6T6MXZO.cjs} +58 -40
  30. package/dist/batch-I6T6MXZO.cjs.map +1 -0
  31. package/dist/{batch-L4ZXS46M.js → batch-US4F6WPK.js} +42 -24
  32. package/dist/batch-US4F6WPK.js.map +1 -0
  33. package/dist/chunk-24MGQDK3.js +31 -0
  34. package/dist/chunk-24MGQDK3.js.map +1 -0
  35. package/dist/{chunk-UGT7GK7I.cjs → chunk-24SYBZPL.cjs} +36 -18
  36. package/dist/chunk-24SYBZPL.cjs.map +1 -0
  37. package/dist/{chunk-KYAJINUI.cjs → chunk-2HPNT6HH.cjs} +581 -401
  38. package/dist/chunk-2HPNT6HH.cjs.map +1 -0
  39. package/dist/{chunk-VLVVJLDH.cjs → chunk-2NE7DTOK.cjs} +234 -193
  40. package/dist/chunk-2NE7DTOK.cjs.map +1 -0
  41. package/dist/{chunk-N2U4AZGB.js → chunk-2WXHA33T.js} +3 -3
  42. package/dist/chunk-2WXHA33T.js.map +1 -0
  43. package/dist/chunk-2XC6KDJM.js +22 -0
  44. package/dist/chunk-2XC6KDJM.js.map +1 -0
  45. package/dist/{chunk-L3MTL4NA.js → chunk-2ZLVT7H3.js} +223 -182
  46. package/dist/chunk-2ZLVT7H3.js.map +1 -0
  47. package/dist/{chunk-2GUYQR5P.js → chunk-3JHIFQ4I.js} +39 -13
  48. package/dist/chunk-3JHIFQ4I.js.map +1 -0
  49. package/dist/{chunk-BU4KFWXF.js → chunk-44I6UYVH.js} +8 -17
  50. package/dist/chunk-44I6UYVH.js.map +1 -0
  51. package/dist/{chunk-UNYXQ4M5.js → chunk-47TF32NQ.js} +10 -5
  52. package/dist/chunk-47TF32NQ.js.map +1 -0
  53. package/dist/{chunk-WNO3C3N2.cjs → chunk-4A3SKJ53.cjs} +56 -27
  54. package/dist/chunk-4A3SKJ53.cjs.map +1 -0
  55. package/dist/{chunk-YML4ME27.cjs → chunk-4HS6FFGL.cjs} +55 -46
  56. package/dist/chunk-4HS6FFGL.cjs.map +1 -0
  57. package/dist/{chunk-C72AZW7J.js → chunk-4MMWFSCD.js} +4 -4
  58. package/dist/chunk-4MMWFSCD.js.map +1 -0
  59. package/dist/{chunk-6HKGLTJI.cjs → chunk-4NLCWGH7.cjs} +15 -15
  60. package/dist/chunk-4NLCWGH7.cjs.map +1 -0
  61. package/dist/{chunk-LKBEROHN.js → chunk-4S5TWFIZ.js} +14 -14
  62. package/dist/chunk-4S5TWFIZ.js.map +1 -0
  63. package/dist/{chunk-UBDMVMBZ.js → chunk-55GB6JYQ.js} +33 -22
  64. package/dist/chunk-55GB6JYQ.js.map +1 -0
  65. package/dist/{chunk-U6IFHFWK.js → chunk-5WKQDIGO.js} +8 -17
  66. package/dist/chunk-5WKQDIGO.js.map +1 -0
  67. package/dist/chunk-67ADYSTW.js +120 -0
  68. package/dist/chunk-67ADYSTW.js.map +1 -0
  69. package/dist/{chunk-XL7Q7HB2.cjs → chunk-6LHQPOMI.cjs} +39 -6
  70. package/dist/chunk-6LHQPOMI.cjs.map +1 -0
  71. package/dist/{chunk-A4JVILQU.js → chunk-6M2OIS4Y.js} +7 -7
  72. package/dist/chunk-6M2OIS4Y.js.map +1 -0
  73. package/dist/{chunk-LWGSI6M3.js → chunk-6PWOWXMC.js} +4 -4
  74. package/dist/{chunk-LWGSI6M3.js.map → chunk-6PWOWXMC.js.map} +1 -1
  75. package/dist/{chunk-RNB4APBZ.js → chunk-6WAKKTBO.js} +9 -5
  76. package/dist/chunk-6WAKKTBO.js.map +1 -0
  77. package/dist/{chunk-V2BOS4WF.cjs → chunk-7A6535RA.cjs} +11 -11
  78. package/dist/chunk-7A6535RA.cjs.map +1 -0
  79. package/dist/{chunk-ZLQSWSJ2.cjs → chunk-7FDKWDA2.cjs} +11 -11
  80. package/dist/{chunk-ZLQSWSJ2.cjs.map → chunk-7FDKWDA2.cjs.map} +1 -1
  81. package/dist/{chunk-4VPXM6UU.js → chunk-7I5Z3UBJ.js} +3 -3
  82. package/dist/{chunk-4VPXM6UU.js.map → chunk-7I5Z3UBJ.js.map} +1 -1
  83. package/dist/{chunk-B4EOJWOY.cjs → chunk-7JJ3A6AT.cjs} +13 -7
  84. package/dist/chunk-7JJ3A6AT.cjs.map +1 -0
  85. package/dist/{chunk-WJVHMTKB.cjs → chunk-AA27GEYS.cjs} +3 -3
  86. package/dist/{chunk-WJVHMTKB.cjs.map → chunk-AA27GEYS.cjs.map} +1 -1
  87. package/dist/{chunk-BP46RJ5X.js → chunk-AAEZSPTC.js} +5 -5
  88. package/dist/{chunk-BP46RJ5X.js.map → chunk-AAEZSPTC.js.map} +1 -1
  89. package/dist/chunk-AGACYRJ2.js +11 -0
  90. package/dist/chunk-AGACYRJ2.js.map +1 -0
  91. package/dist/{chunk-ZZMZWBR6.js → chunk-ALUN2B4W.js} +81 -58
  92. package/dist/chunk-ALUN2B4W.js.map +1 -0
  93. package/dist/chunk-ANMJJD6D.cjs +18 -0
  94. package/dist/chunk-ANMJJD6D.cjs.map +1 -0
  95. package/dist/{chunk-DXGZ2NUG.cjs → chunk-ATT276RD.cjs} +12 -11
  96. package/dist/chunk-ATT276RD.cjs.map +1 -0
  97. package/dist/{chunk-4FFBAUFS.js → chunk-AWINL3ZC.js} +6 -6
  98. package/dist/chunk-AWINL3ZC.js.map +1 -0
  99. package/dist/{chunk-UU36SHFY.cjs → chunk-BJUJT5ED.cjs} +9 -8
  100. package/dist/chunk-BJUJT5ED.cjs.map +1 -0
  101. package/dist/{chunk-D4CUGAKZ.js → chunk-CZJ6Q7CW.js} +36 -6
  102. package/dist/chunk-CZJ6Q7CW.js.map +1 -0
  103. package/dist/{chunk-KQ7TS7WW.cjs → chunk-D6POWE7E.cjs} +37 -26
  104. package/dist/chunk-D6POWE7E.cjs.map +1 -0
  105. package/dist/{chunk-AWO27VRZ.js → chunk-DMRT67Y6.js} +6 -5
  106. package/dist/chunk-DMRT67Y6.js.map +1 -0
  107. package/dist/{chunk-5VB22SYX.cjs → chunk-DQZU7JK6.cjs} +7 -7
  108. package/dist/{chunk-5VB22SYX.cjs.map → chunk-DQZU7JK6.cjs.map} +1 -1
  109. package/dist/{chunk-3NSS2OIZ.cjs → chunk-DRL7URI4.cjs} +6 -6
  110. package/dist/{chunk-3NSS2OIZ.cjs.map → chunk-DRL7URI4.cjs.map} +1 -1
  111. package/dist/{chunk-RFXWMRFC.js → chunk-EFMFILPG.js} +14 -6
  112. package/dist/chunk-EFMFILPG.js.map +1 -0
  113. package/dist/{chunk-HS7AVXTF.js → chunk-EH6XD3FY.js} +4 -4
  114. package/dist/chunk-EH6XD3FY.js.map +1 -0
  115. package/dist/{chunk-KQRW2GPZ.js → chunk-EIQFAOFD.js} +6 -6
  116. package/dist/chunk-EIQFAOFD.js.map +1 -0
  117. package/dist/{chunk-XJCXEKMD.cjs → chunk-EXTRW7GW.cjs} +4 -4
  118. package/dist/chunk-EXTRW7GW.cjs.map +1 -0
  119. package/dist/{chunk-U54XCYG3.js → chunk-FJWQP6EE.js} +12 -6
  120. package/dist/chunk-FJWQP6EE.js.map +1 -0
  121. package/dist/{chunk-O7DK5PBJ.cjs → chunk-FUSDYC2B.cjs} +26 -42
  122. package/dist/chunk-FUSDYC2B.cjs.map +1 -0
  123. package/dist/{chunk-4QZSA2HJ.js → chunk-G7BLGBRN.js} +4 -4
  124. package/dist/chunk-G7BLGBRN.js.map +1 -0
  125. package/dist/{chunk-BZRFXJHA.js → chunk-GBCVPKHE.js} +55 -26
  126. package/dist/chunk-GBCVPKHE.js.map +1 -0
  127. package/dist/chunk-GGZ5GPE3.cjs +130 -0
  128. package/dist/chunk-GGZ5GPE3.cjs.map +1 -0
  129. package/dist/{chunk-5HEG4CQH.cjs → chunk-GZV6AVRL.cjs} +8 -8
  130. package/dist/{chunk-5HEG4CQH.cjs.map → chunk-GZV6AVRL.cjs.map} +1 -1
  131. package/dist/{chunk-VCLBZAZU.cjs → chunk-H6YM3PV6.cjs} +17 -17
  132. package/dist/chunk-H6YM3PV6.cjs.map +1 -0
  133. package/dist/{chunk-RFMBZPOW.cjs → chunk-HCT4HPCL.cjs} +10 -10
  134. package/dist/chunk-HCT4HPCL.cjs.map +1 -0
  135. package/dist/{chunk-OSEG74VJ.js → chunk-HFEJE7AC.js} +52 -43
  136. package/dist/chunk-HFEJE7AC.js.map +1 -0
  137. package/dist/{chunk-52NKC5HT.cjs → chunk-HUFSABUZ.cjs} +12 -8
  138. package/dist/chunk-HUFSABUZ.cjs.map +1 -0
  139. package/dist/{chunk-4CLOXP6H.cjs → chunk-HW7SEELD.cjs} +4 -4
  140. package/dist/{chunk-4CLOXP6H.cjs.map → chunk-HW7SEELD.cjs.map} +1 -1
  141. package/dist/{chunk-ZSWPZ23K.cjs → chunk-I2PWY7VM.cjs} +5 -5
  142. package/dist/chunk-I2PWY7VM.cjs.map +1 -0
  143. package/dist/{chunk-VJ26EKGJ.cjs → chunk-IJ7M6GOG.cjs} +3 -3
  144. package/dist/chunk-IJ7M6GOG.cjs.map +1 -0
  145. package/dist/{chunk-SAVIWMZB.js → chunk-ILGZ2ZZV.js} +3 -3
  146. package/dist/chunk-ILGZ2ZZV.js.map +1 -0
  147. package/dist/{chunk-4ZHTIJNE.cjs → chunk-J7J7J2GN.cjs} +87 -63
  148. package/dist/chunk-J7J7J2GN.cjs.map +1 -0
  149. package/dist/{chunk-UALX2J2Q.cjs → chunk-JLRLCBJ4.cjs} +38 -11
  150. package/dist/chunk-JLRLCBJ4.cjs.map +1 -0
  151. package/dist/{chunk-2QDYBS2A.js → chunk-JMDDYA22.js} +4 -4
  152. package/dist/chunk-JMDDYA22.js.map +1 -0
  153. package/dist/{chunk-LXQ6HKPS.js → chunk-JNAA4G4H.js} +3 -3
  154. package/dist/{chunk-LXQ6HKPS.js.map → chunk-JNAA4G4H.js.map} +1 -1
  155. package/dist/{chunk-UMP6OJIM.js → chunk-JOFVLOFY.js} +4 -4
  156. package/dist/{chunk-UMP6OJIM.js.map → chunk-JOFVLOFY.js.map} +1 -1
  157. package/dist/{chunk-A46SWMIF.js → chunk-K2VMFZQ5.js} +7 -7
  158. package/dist/chunk-K2VMFZQ5.js.map +1 -0
  159. package/dist/{chunk-DN2PACRI.js → chunk-K3NH62DG.js} +461 -282
  160. package/dist/chunk-K3NH62DG.js.map +1 -0
  161. package/dist/{chunk-LYTOXSRH.js → chunk-KDR53EO7.js} +1939 -1864
  162. package/dist/chunk-KDR53EO7.js.map +1 -0
  163. package/dist/{chunk-XWTLIGO3.cjs → chunk-KTTHHYEW.cjs} +5 -5
  164. package/dist/chunk-KTTHHYEW.cjs.map +1 -0
  165. package/dist/{chunk-3FFAEAUJ.cjs → chunk-KVSAY6NZ.cjs} +18 -18
  166. package/dist/chunk-KVSAY6NZ.cjs.map +1 -0
  167. package/dist/{chunk-IAHZCGBE.cjs → chunk-LHSWHYF3.cjs} +120 -146
  168. package/dist/chunk-LHSWHYF3.cjs.map +1 -0
  169. package/dist/{chunk-3OR54XG4.js → chunk-NJWYQWDL.js} +12 -8
  170. package/dist/chunk-NJWYQWDL.js.map +1 -0
  171. package/dist/chunk-NVXXWAU7.cjs +13 -0
  172. package/dist/chunk-NVXXWAU7.cjs.map +1 -0
  173. package/dist/{chunk-2D34UTDC.js → chunk-O6USDERH.js} +31 -11
  174. package/dist/chunk-O6USDERH.js.map +1 -0
  175. package/dist/{chunk-XO4SOZN6.js → chunk-OR6XIWLB.js} +4 -4
  176. package/dist/{chunk-XO4SOZN6.js.map → chunk-OR6XIWLB.js.map} +1 -1
  177. package/dist/{chunk-4PYZ5AX3.cjs → chunk-PRZ3BES7.cjs} +16 -8
  178. package/dist/chunk-PRZ3BES7.cjs.map +1 -0
  179. package/dist/{chunk-HCZD23VS.cjs → chunk-QC55H6RJ.cjs} +65 -39
  180. package/dist/chunk-QC55H6RJ.cjs.map +1 -0
  181. package/dist/{chunk-4O5TGQBW.cjs → chunk-QME6FDFG.cjs} +9 -5
  182. package/dist/chunk-QME6FDFG.cjs.map +1 -0
  183. package/dist/chunk-QOGNZMHD.cjs +34 -0
  184. package/dist/chunk-QOGNZMHD.cjs.map +1 -0
  185. package/dist/{chunk-7VT4P3Z4.cjs → chunk-QUAEOKDW.cjs} +1642 -1567
  186. package/dist/chunk-QUAEOKDW.cjs.map +1 -0
  187. package/dist/{chunk-B2J4ZMZL.cjs → chunk-QWD3CZWE.cjs} +6 -5
  188. package/dist/chunk-QWD3CZWE.cjs.map +1 -0
  189. package/dist/{chunk-SZVR77EJ.cjs → chunk-QWD4RDZ3.cjs} +15 -24
  190. package/dist/chunk-QWD4RDZ3.cjs.map +1 -0
  191. package/dist/{chunk-7BG5UH3T.cjs → chunk-RHZ6HP23.cjs} +4 -4
  192. package/dist/chunk-RHZ6HP23.cjs.map +1 -0
  193. package/dist/{chunk-2HVF2WJY.cjs → chunk-RQMCOFAI.cjs} +8 -8
  194. package/dist/{chunk-2HVF2WJY.cjs.map → chunk-RQMCOFAI.cjs.map} +1 -1
  195. package/dist/{chunk-VKJ7V7EB.cjs → chunk-SA6K24NB.cjs} +3 -3
  196. package/dist/chunk-SA6K24NB.cjs.map +1 -0
  197. package/dist/{chunk-7AD3ZTZL.js → chunk-SAGRF4IB.js} +3 -3
  198. package/dist/chunk-SAGRF4IB.js.map +1 -0
  199. package/dist/{chunk-PUAEFLYK.js → chunk-SVQIW5RJ.js} +4 -4
  200. package/dist/{chunk-PUAEFLYK.js.map → chunk-SVQIW5RJ.js.map} +1 -1
  201. package/dist/{chunk-43ZQRWAP.cjs → chunk-SYVWE64W.cjs} +22 -22
  202. package/dist/chunk-SYVWE64W.cjs.map +1 -0
  203. package/dist/{chunk-3O42QOMJ.js → chunk-TA3K7SBK.js} +7 -6
  204. package/dist/chunk-TA3K7SBK.js.map +1 -0
  205. package/dist/{chunk-LYRDF5TQ.cjs → chunk-TFG5IBZS.cjs} +14 -23
  206. package/dist/chunk-TFG5IBZS.cjs.map +1 -0
  207. package/dist/{chunk-GKEFRLU7.cjs → chunk-TMKTSYDS.cjs} +6 -6
  208. package/dist/{chunk-GKEFRLU7.cjs.map → chunk-TMKTSYDS.cjs.map} +1 -1
  209. package/dist/{chunk-J24VJOH3.cjs → chunk-UADQJBHR.cjs} +31 -11
  210. package/dist/chunk-UADQJBHR.cjs.map +1 -0
  211. package/dist/{chunk-TAZVKYWJ.js → chunk-UBR5PWD7.js} +26 -40
  212. package/dist/chunk-UBR5PWD7.js.map +1 -0
  213. package/dist/{chunk-IPYYKCRC.js → chunk-UFPUHJWS.js} +5 -5
  214. package/dist/{chunk-IPYYKCRC.js.map → chunk-UFPUHJWS.js.map} +1 -1
  215. package/dist/{chunk-OHLDPWTA.cjs → chunk-UGRS7ZA7.cjs} +15 -15
  216. package/dist/{chunk-OHLDPWTA.cjs.map → chunk-UGRS7ZA7.cjs.map} +1 -1
  217. package/dist/{chunk-RIAM53CP.js → chunk-UKMBRMGT.js} +3 -3
  218. package/dist/chunk-UKMBRMGT.js.map +1 -0
  219. package/dist/{chunk-L4BDVXIM.js → chunk-UNK4HNJH.js} +97 -123
  220. package/dist/chunk-UNK4HNJH.js.map +1 -0
  221. package/dist/{chunk-C3NT3PVE.js → chunk-V22DZIXO.js} +3 -3
  222. package/dist/chunk-V22DZIXO.js.map +1 -0
  223. package/dist/{chunk-OFRFZRQ4.cjs → chunk-V6ZY4AX6.cjs} +24 -14
  224. package/dist/chunk-V6ZY4AX6.cjs.map +1 -0
  225. package/dist/{chunk-B3IMEBOA.js → chunk-VE6DFSKU.js} +3 -3
  226. package/dist/{chunk-B3IMEBOA.js.map → chunk-VE6DFSKU.js.map} +1 -1
  227. package/dist/{chunk-WLQNMXQE.js → chunk-VWUXIVEI.js} +53 -26
  228. package/dist/chunk-VWUXIVEI.js.map +1 -0
  229. package/dist/{chunk-GMLBYDW4.cjs → chunk-VXDEKILY.cjs} +108 -109
  230. package/dist/chunk-VXDEKILY.cjs.map +1 -0
  231. package/dist/{chunk-ACDLHN3W.js → chunk-WJXOICRC.js} +16 -6
  232. package/dist/chunk-WJXOICRC.js.map +1 -0
  233. package/dist/{chunk-7YGCPMGB.js → chunk-XB4GI5RZ.js} +27 -12
  234. package/dist/chunk-XB4GI5RZ.js.map +1 -0
  235. package/dist/{chunk-O73J46PV.js → chunk-XDANGA2C.js} +5 -5
  236. package/dist/{chunk-O73J46PV.js.map → chunk-XDANGA2C.js.map} +1 -1
  237. package/dist/{chunk-NDGGJQTZ.js → chunk-XJZEBGXD.js} +10 -10
  238. package/dist/chunk-XJZEBGXD.js.map +1 -0
  239. package/dist/{chunk-UTSRIDKZ.js → chunk-XYFGKVZ7.js} +3 -3
  240. package/dist/chunk-XYFGKVZ7.js.map +1 -0
  241. package/dist/{chunk-RMWTPV3M.cjs → chunk-Y2KYR2ED.cjs} +27 -27
  242. package/dist/chunk-Y2KYR2ED.cjs.map +1 -0
  243. package/dist/{chunk-O7LZFG6O.cjs → chunk-YIFFF23U.cjs} +5 -5
  244. package/dist/chunk-YIFFF23U.cjs.map +1 -0
  245. package/dist/{chunk-4OTIXDMU.cjs → chunk-YJNYDJ2T.cjs} +12 -4
  246. package/dist/chunk-YJNYDJ2T.cjs.map +1 -0
  247. package/dist/{chunk-6JSIEDKL.cjs → chunk-YSTXFWQE.cjs} +13 -7
  248. package/dist/chunk-YSTXFWQE.cjs.map +1 -0
  249. package/dist/{chunk-I6HGWHPU.cjs → chunk-Z3NTRKIC.cjs} +4 -4
  250. package/dist/{chunk-I6HGWHPU.cjs.map → chunk-Z3NTRKIC.cjs.map} +1 -1
  251. package/dist/{chunk-32WTYBUH.js → chunk-ZH26RNQA.js} +91 -92
  252. package/dist/chunk-ZH26RNQA.js.map +1 -0
  253. package/dist/compact-session-BHTPCIHA.cjs +61 -0
  254. package/dist/{compact-session-QV57KR66.cjs.map → compact-session-BHTPCIHA.cjs.map} +1 -1
  255. package/dist/compact-session-W4WLJTHA.js +24 -0
  256. package/dist/{compact-session-RIGOWC4Y.js.map → compact-session-W4WLJTHA.js.map} +1 -1
  257. package/dist/compaction.cjs +20 -17
  258. package/dist/compaction.d.cts +15 -1
  259. package/dist/compaction.d.ts +15 -1
  260. package/dist/compaction.js +3 -4
  261. package/dist/concurrency.cjs +6 -7
  262. package/dist/concurrency.cjs.map +1 -1
  263. package/dist/concurrency.d.cts +6 -3
  264. package/dist/concurrency.d.ts +6 -3
  265. package/dist/concurrency.js +4 -5
  266. package/dist/concurrency.js.map +1 -1
  267. package/dist/context/index.cjs +6 -6
  268. package/dist/context/index.js +3 -3
  269. package/dist/context-NI33FS2R.cjs +23 -0
  270. package/dist/{context-WFLTTMK3.cjs.map → context-NI33FS2R.cjs.map} +1 -1
  271. package/dist/context-Y7B7SI5X.js +6 -0
  272. package/dist/{context-WI2DFG7V.js.map → context-Y7B7SI5X.js.map} +1 -1
  273. package/dist/create-skill.d.ts +4 -1
  274. package/dist/{cron-BuiRPrvt.d.cts → cron-C3PhZED0.d.cts} +8 -2
  275. package/dist/{cron-C2SIi31n.d.ts → cron-crfMMdAw.d.ts} +8 -2
  276. package/dist/cron.cjs +46 -45
  277. package/dist/cron.d.cts +5 -4
  278. package/dist/cron.d.ts +5 -4
  279. package/dist/cron.js +45 -44
  280. package/dist/{errors-BgJH9PHi.d.cts → errors-CLOAyuiv.d.ts} +133 -95
  281. package/dist/{errors-C5fJUqLk.d.ts → errors-DrDEgyz1.d.cts} +133 -95
  282. package/dist/errors-base-B5g01neU.d.cts +75 -0
  283. package/dist/errors-base-B5g01neU.d.ts +75 -0
  284. package/dist/errors-base.d.ts +73 -0
  285. package/dist/errors.cjs +25 -22
  286. package/dist/errors.d.cts +3 -2
  287. package/dist/errors.d.ts +3 -2
  288. package/dist/errors.js +2 -3
  289. package/dist/eval.cjs +74 -78
  290. package/dist/eval.cjs.map +1 -1
  291. package/dist/eval.js +64 -68
  292. package/dist/eval.js.map +1 -1
  293. package/dist/{executor-6CYCA7MI.cjs → executor-XQAOQOHD.cjs} +60 -54
  294. package/dist/executor-XQAOQOHD.cjs.map +1 -0
  295. package/dist/{executor-QSEC3MRH.js → executor-ZNDQDX6Q.js} +43 -37
  296. package/dist/executor-ZNDQDX6Q.js.map +1 -0
  297. package/dist/filesystem/index.cjs +24 -26
  298. package/dist/filesystem/index.cjs.map +1 -1
  299. package/dist/filesystem/index.js +20 -22
  300. package/dist/filesystem/index.js.map +1 -1
  301. package/dist/filesystem/types.d.cts +11 -5
  302. package/dist/filesystem/types.d.ts +11 -5
  303. package/dist/{fork-agent-RSV4E3EA.js → fork-agent-S2EPIML7.js} +3 -3
  304. package/dist/fork-agent-S2EPIML7.js.map +1 -0
  305. package/dist/{fork-agent-Y2IK2RYU.cjs → fork-agent-WAEQI2DL.cjs} +4 -4
  306. package/dist/fork-agent-WAEQI2DL.cjs.map +1 -0
  307. package/dist/fs-session-store-77JU46UZ.js +10 -0
  308. package/dist/{fs-session-store-NM6YSTE2.js.map → fs-session-store-77JU46UZ.js.map} +1 -1
  309. package/dist/fs-session-store-E4U3P56L.cjs +19 -0
  310. package/dist/{fs-session-store-4PIHT5UX.cjs.map → fs-session-store-E4U3P56L.cjs.map} +1 -1
  311. package/dist/generate-object-BXV7BZRP.js +7 -0
  312. package/dist/{generate-object-GUNAUVBX.js.map → generate-object-BXV7BZRP.js.map} +1 -1
  313. package/dist/generate-object-YBI2TDJ3.cjs +20 -0
  314. package/dist/{generate-object-R7HTMW7F.cjs.map → generate-object-YBI2TDJ3.cjs.map} +1 -1
  315. package/dist/generate-object.d.ts +2 -4
  316. package/dist/index-manager-DXR2RSFI.cjs +26 -0
  317. package/dist/{index-manager-2SRX45WJ.cjs.map → index-manager-DXR2RSFI.cjs.map} +1 -1
  318. package/dist/index-manager-QH6OXEV5.js +17 -0
  319. package/dist/{index-manager-SP4ISSDX.js.map → index-manager-QH6OXEV5.js.map} +1 -1
  320. package/dist/index.cjs +234 -194
  321. package/dist/index.cjs.map +1 -1
  322. package/dist/index.d.cts +243 -41
  323. package/dist/index.d.ts +243 -41
  324. package/dist/index.js +140 -102
  325. package/dist/index.js.map +1 -1
  326. package/dist/{inject-session-DAR7OUCW.js → inject-session-SUM6TDJF.js} +9 -9
  327. package/dist/{inject-session-DAR7OUCW.js.map → inject-session-SUM6TDJF.js.map} +1 -1
  328. package/dist/inject-session-W6A46J3E.cjs +29 -0
  329. package/dist/{inject-session-WQKMC3GR.cjs.map → inject-session-W6A46J3E.cjs.map} +1 -1
  330. package/dist/interactive/index.cjs +12 -6
  331. package/dist/interactive/index.cjs.map +1 -1
  332. package/dist/interactive/index.js +12 -6
  333. package/dist/interactive/index.js.map +1 -1
  334. package/dist/interactive/types.d.cts +14 -4
  335. package/dist/interactive/types.d.ts +14 -4
  336. package/dist/internal/agent-loop/loop-context-init.d.ts +1 -1
  337. package/dist/internal/agent-loop/loop-finalize.d.ts +25 -0
  338. package/dist/internal/agent-loop/loop.d.ts +1 -1
  339. package/dist/internal/agent-loop/message-builders.d.ts +1 -1
  340. package/dist/internal/agent-loop/tool-dispatch.d.ts +2 -2
  341. package/dist/internal/agent-loop/usage-and-cost.d.ts +1 -1
  342. package/dist/internal/auth/credential-availability.d.ts +61 -0
  343. package/dist/internal/auth/credential-store.d.ts +1 -1
  344. package/dist/internal/auth/oauth-device.d.ts +1 -1
  345. package/dist/internal/auth/oauth-engine.d.ts +1 -1
  346. package/dist/internal/auth/resolve-credential.d.ts +1 -1
  347. package/dist/internal/base-url.d.ts +14 -0
  348. package/dist/internal/cloud-agent/cloud-config-serializer.d.ts +1 -1
  349. package/dist/internal/{runtime/concurrency → concurrency}/subagent-credentials.d.ts +2 -2
  350. package/dist/internal/emit-run-event.d.ts +16 -0
  351. package/dist/internal/error-mappers/shared.d.ts +14 -1
  352. package/dist/internal/eval/assert.d.ts +2 -1
  353. package/dist/internal/eval/single-flight.d.ts +2 -1
  354. package/dist/internal/global-singleton.d.ts +6 -3
  355. package/dist/internal/llm/responses.d.ts +10 -0
  356. package/dist/internal/local-agent/local-agent-bootstrap.d.ts +5 -3
  357. package/dist/internal/local-agent/local-agent-capabilities.d.ts +38 -0
  358. package/dist/internal/local-agent/local-agent-dispatch.d.ts +2 -2
  359. package/dist/internal/local-agent/local-agent-memory-provider.d.ts +1 -1
  360. package/dist/internal/local-agent/local-agent-personality-extensions.d.ts +25 -1
  361. package/dist/internal/local-agent/local-agent-send.d.ts +42 -1
  362. package/dist/internal/local-agent/real-local-run-mcp.d.ts +26 -0
  363. package/dist/internal/local-agent/real-local-run-options.d.ts +26 -0
  364. package/dist/internal/local-agent/real-local-run-tools.d.ts +21 -4
  365. package/dist/internal/local-agent/real-local-run.d.ts +2 -2
  366. package/dist/internal/mcp/handshake-timeout.d.ts +53 -0
  367. package/dist/internal/memory/active-memory.d.ts +1 -1
  368. package/dist/internal/memory/adapters/index.cjs +10 -10
  369. package/dist/internal/memory/adapters/index.js +9 -9
  370. package/dist/internal/memory/adapters/openai-embedding.d.cts +10 -0
  371. package/dist/internal/memory/adapters/openai-embedding.d.ts +10 -0
  372. package/dist/internal/memory/corpus-sync.d.ts +23 -0
  373. package/dist/internal/memory/index-db.d.ts +15 -1
  374. package/dist/internal/memory/index-manager-contract.d.ts +12 -0
  375. package/dist/internal/memory/index-manager.d.ts +4 -10
  376. package/dist/internal/memory/index-repository.d.ts +58 -0
  377. package/dist/internal/memory/lance-memory-adapter.d.ts +16 -14
  378. package/dist/internal/memory/memory-index.d.ts +15 -0
  379. package/dist/internal/memory/sdk-memory-peer-loader.d.ts +54 -1
  380. package/dist/internal/memory/storage/index.cjs +39 -40
  381. package/dist/internal/memory/storage/index.js +10 -11
  382. package/dist/internal/memory/storage/memory-root.d.cts +2 -3
  383. package/dist/internal/memory/storage/memory-root.d.ts +2 -3
  384. package/dist/internal/persistence/atomic-write.d.cts +4 -4
  385. package/dist/internal/persistence/atomic-write.d.ts +4 -4
  386. package/dist/internal/persistence/index.cjs +24 -25
  387. package/dist/internal/persistence/index.cjs.map +1 -1
  388. package/dist/internal/persistence/index.js +7 -8
  389. package/dist/internal/persistence/index.js.map +1 -1
  390. package/dist/internal/persistence/jsonl.d.cts +3 -1
  391. package/dist/internal/persistence/jsonl.d.ts +3 -1
  392. package/dist/internal/persistence/paths.d.cts +25 -12
  393. package/dist/internal/persistence/paths.d.ts +25 -12
  394. package/dist/internal/persistence/transcript-ops.d.cts +11 -2
  395. package/dist/internal/persistence/transcript-ops.d.ts +11 -2
  396. package/dist/internal/plugins/context.d.cts +0 -10
  397. package/dist/internal/plugins/context.d.ts +0 -10
  398. package/dist/internal/plugins/types.d.cts +1 -1
  399. package/dist/internal/plugins/types.d.ts +1 -1
  400. package/dist/internal/providers/catalog-schema.d.ts +94 -0
  401. package/dist/internal/providers/catalog-source-models-dev.d.ts +11 -0
  402. package/dist/internal/runtime/compat/compat-config-file.d.ts +31 -0
  403. package/dist/internal/runtime/compat/foreign-config-sources.d.ts +58 -34
  404. package/dist/internal/runtime/compression/compression-model-registry.d.ts +1 -1
  405. package/dist/internal/runtime/compression/compression-summarizer.d.ts +5 -1
  406. package/dist/internal/runtime/fixtures/fixture-events.d.ts +1 -1
  407. package/dist/internal/runtime/fixtures/fixture-mode.d.ts +8 -14
  408. package/dist/internal/runtime/fixtures/fixture-run-base.d.ts +1 -1
  409. package/dist/internal/runtime/fixtures/fixture-scripts.d.ts +2 -2
  410. package/dist/internal/runtime/hooks/hooks-executor.d.ts +6 -1
  411. package/dist/internal/runtime/lifecycle/wrap-completion-check-run.d.ts +1 -1
  412. package/dist/internal/runtime/{memory → memory-glue}/memory-provider.d.ts +1 -1
  413. package/dist/internal/runtime/{plugins → plugin-loader}/plugin-bundles.d.ts +4 -1
  414. package/dist/internal/runtime/processors/wrap-output-run.d.ts +1 -1
  415. package/dist/internal/runtime/registry/live-agent-registry.d.ts +9 -1
  416. package/dist/internal/runtime/system-prompt/local-assembly.d.ts +2 -1
  417. package/dist/internal/scorers/llm-judge.d.ts +12 -0
  418. package/dist/internal/security/index.cjs +14 -15
  419. package/dist/internal/security/index.d.cts +6 -1
  420. package/dist/internal/security/index.d.ts +6 -1
  421. package/dist/internal/security/index.js +4 -5
  422. package/dist/internal/security/path-containment.d.ts +24 -0
  423. package/dist/internal/session/agent-session-store.d.ts +1 -1
  424. package/dist/internal/session/agent-session.d.ts +1 -1
  425. package/dist/internal/session/index.d.ts +1 -1
  426. package/dist/internal/session/session-cache.d.ts +9 -3
  427. package/dist/internal/task/registry.d.ts +1 -1
  428. package/dist/internal/task/store.d.ts +1 -1
  429. package/dist/internal/task/subscribe.d.ts +1 -1
  430. package/dist/internal/task/task-id.d.ts +22 -0
  431. package/dist/internal/telemetry/adapter-registry.d.ts +12 -2
  432. package/dist/internal/telemetry/adapters/braintrust.d.ts +6 -1
  433. package/dist/internal/telemetry/adapters/langsmith.d.ts +6 -1
  434. package/dist/internal/workflow/executor.d.ts +2 -1
  435. package/dist/internal/workflow/snapshot-store.d.ts +1 -1
  436. package/dist/internal/workflow/step-branch.d.ts +2 -2
  437. package/dist/internal/workflow/step-dowhile.d.ts +2 -2
  438. package/dist/internal/workflow/step-execution.d.ts +25 -0
  439. package/dist/internal/workflow/step-foreach.d.ts +2 -2
  440. package/dist/internal/workflow/step-parallel.d.ts +2 -2
  441. package/dist/judge-call-6MVARKU2.js +5 -0
  442. package/dist/{judge-call-LVXABPS3.js.map → judge-call-6MVARKU2.js.map} +1 -1
  443. package/dist/judge-call-I3P4D5QR.cjs +22 -0
  444. package/dist/{judge-call-LAHMBJ57.cjs.map → judge-call-I3P4D5QR.cjs.map} +1 -1
  445. package/dist/mcp-auth.cjs +14 -15
  446. package/dist/mcp-auth.cjs.map +1 -1
  447. package/dist/mcp-auth.d.cts +2 -0
  448. package/dist/mcp-auth.d.ts +2 -0
  449. package/dist/mcp-auth.js +4 -5
  450. package/dist/mcp-auth.js.map +1 -1
  451. package/dist/models.cjs +52 -42
  452. package/dist/models.cjs.map +1 -1
  453. package/dist/models.js +39 -29
  454. package/dist/models.js.map +1 -1
  455. package/dist/oauth-transaction-store-5RIR6D5C.js +5 -0
  456. package/dist/{oauth-transaction-store-W52KVHQ4.js.map → oauth-transaction-store-5RIR6D5C.js.map} +1 -1
  457. package/dist/oauth-transaction-store-SXIE57OD.cjs +38 -0
  458. package/dist/{oauth-transaction-store-BT4GLTLK.cjs.map → oauth-transaction-store-SXIE57OD.cjs.map} +1 -1
  459. package/dist/path-safety.cjs +11 -12
  460. package/dist/path-safety.d.cts +2 -0
  461. package/dist/path-safety.d.ts +2 -0
  462. package/dist/path-safety.js +4 -5
  463. package/dist/permission-engine.d.ts +10 -17
  464. package/dist/persistence.cjs +31 -31
  465. package/dist/persistence.cjs.map +1 -1
  466. package/dist/persistence.d.cts +9 -1
  467. package/dist/persistence.d.ts +9 -1
  468. package/dist/persistence.js +12 -13
  469. package/dist/persistence.js.map +1 -1
  470. package/dist/project.cjs +5 -6
  471. package/dist/project.cjs.map +1 -1
  472. package/dist/project.js +3 -4
  473. package/dist/project.js.map +1 -1
  474. package/dist/providers.cjs +10 -10
  475. package/dist/providers.d.cts +2 -0
  476. package/dist/providers.d.ts +2 -0
  477. package/dist/providers.js +8 -8
  478. package/dist/registry-BZQFYRTL.cjs +46 -0
  479. package/dist/{registry-V7BDQ6QB.cjs.map → registry-BZQFYRTL.cjs.map} +1 -1
  480. package/dist/registry-DMWCJKRF.js +9 -0
  481. package/dist/{registry-75W33OGL.js.map → registry-DMWCJKRF.js.map} +1 -1
  482. package/dist/retry.cjs +4 -5
  483. package/dist/retry.d.cts +20 -5
  484. package/dist/retry.d.ts +20 -5
  485. package/dist/retry.js +3 -4
  486. package/dist/{run-BYSHf58D.d.ts → run-CTAdRU3U.d.cts} +120 -152
  487. package/dist/{run-BYSHf58D.d.cts → run-CTAdRU3U.d.ts} +120 -152
  488. package/dist/{run-until-HEQOUVU6.js → run-until-6D6TQ4JN.js} +27 -59
  489. package/dist/run-until-6D6TQ4JN.js.map +1 -0
  490. package/dist/{run-until-U2B5FJJI.cjs → run-until-DG2KXWB2.cjs} +27 -59
  491. package/dist/run-until-DG2KXWB2.cjs.map +1 -0
  492. package/dist/sandbox/bwrap.d.cts +11 -1
  493. package/dist/sandbox/bwrap.d.ts +11 -1
  494. package/dist/sandbox/index.cjs +26 -30
  495. package/dist/sandbox/index.cjs.map +1 -1
  496. package/dist/sandbox/index.d.cts +8 -1
  497. package/dist/sandbox/index.d.ts +8 -1
  498. package/dist/sandbox/index.js +10 -14
  499. package/dist/sandbox/index.js.map +1 -1
  500. package/dist/sandbox/linux-sandbox.d.cts +20 -4
  501. package/dist/sandbox/linux-sandbox.d.ts +20 -4
  502. package/dist/sandbox/types.d.cts +18 -2
  503. package/dist/sandbox/types.d.ts +18 -2
  504. package/dist/sanitize/index.cjs +2 -2
  505. package/dist/sanitize/index.js +1 -1
  506. package/dist/sanitize/types.d.cts +15 -2
  507. package/dist/sanitize/types.d.ts +15 -2
  508. package/dist/{sdk-agent-D8qJVkuV.d.ts → sdk-agent-BOiKqOgL.d.cts} +197 -117
  509. package/dist/{sdk-agent-DEoKhA8a.d.cts → sdk-agent-D4a_BR_6.d.ts} +197 -117
  510. package/dist/server/auth/errors.d.cts +4 -3
  511. package/dist/server/auth/errors.d.ts +4 -3
  512. package/dist/server/auth/index.cjs +28 -28
  513. package/dist/server/auth/index.cjs.map +1 -1
  514. package/dist/server/auth/index.d.cts +28 -5
  515. package/dist/server/auth/index.d.ts +28 -5
  516. package/dist/server/auth/index.js +13 -13
  517. package/dist/server/auth/index.js.map +1 -1
  518. package/dist/server/auth/oauth-transaction-store.d.cts +2 -1
  519. package/dist/server/auth/oauth-transaction-store.d.ts +2 -1
  520. package/dist/server/auth/orchestrator.d.cts +4 -1
  521. package/dist/server/auth/orchestrator.d.ts +4 -1
  522. package/dist/server/auth/types.d.cts +18 -0
  523. package/dist/server/auth/types.d.ts +18 -0
  524. package/dist/server/errors-envelope.cjs +14 -15
  525. package/dist/server/errors-envelope.cjs.map +1 -1
  526. package/dist/server/errors-envelope.d.cts +3 -3
  527. package/dist/server/errors-envelope.d.ts +3 -3
  528. package/dist/server/errors-envelope.js +3 -4
  529. package/dist/server/errors-envelope.js.map +1 -1
  530. package/dist/session-transcript-LGHSNVY5.cjs +62 -0
  531. package/dist/{session-transcript-6WNITKRE.cjs.map → session-transcript-LGHSNVY5.cjs.map} +1 -1
  532. package/dist/session-transcript-VTBTCGQX.js +5 -0
  533. package/dist/{session-transcript-XAEKW6P7.js.map → session-transcript-VTBTCGQX.js.map} +1 -1
  534. package/dist/skills.cjs +8 -9
  535. package/dist/skills.js +6 -7
  536. package/dist/stream-object-HBFMIZLD.js +7 -0
  537. package/dist/{stream-object-UF4QRQRU.js.map → stream-object-HBFMIZLD.js.map} +1 -1
  538. package/dist/stream-object-QSKHISDJ.cjs +20 -0
  539. package/dist/{stream-object-ZJTQNKY3.cjs.map → stream-object-QSKHISDJ.cjs.map} +1 -1
  540. package/dist/stream-object.d.ts +2 -4
  541. package/dist/subagents-loader-TPZLTXYZ.cjs +16 -0
  542. package/dist/{subagents-loader-UCNO7FUH.cjs.map → subagents-loader-TPZLTXYZ.cjs.map} +1 -1
  543. package/dist/subagents-loader-Y6JFYXAY.js +7 -0
  544. package/dist/{subagents-loader-XP5ERVDZ.js.map → subagents-loader-Y6JFYXAY.js.map} +1 -1
  545. package/dist/subagents-loader.cjs +7 -8
  546. package/dist/subagents-loader.cjs.map +1 -1
  547. package/dist/subagents-loader.d.cts +5 -3
  548. package/dist/subagents-loader.d.ts +5 -3
  549. package/dist/subagents-loader.js +5 -6
  550. package/dist/subagents-loader.js.map +1 -1
  551. package/dist/subagents.cjs +2 -2
  552. package/dist/subagents.cjs.map +1 -1
  553. package/dist/subagents.js +1 -1
  554. package/dist/subagents.js.map +1 -1
  555. package/dist/subscription/define-subscription.d.cts +4 -1
  556. package/dist/subscription/define-subscription.d.ts +4 -1
  557. package/dist/subscription/index.cjs +4 -5
  558. package/dist/subscription/index.cjs.map +1 -1
  559. package/dist/subscription/index.d.cts +2 -0
  560. package/dist/subscription/index.d.ts +2 -0
  561. package/dist/subscription/index.js +3 -4
  562. package/dist/subscription/index.js.map +1 -1
  563. package/dist/subscription/internal/server-integration.d.cts +5 -0
  564. package/dist/subscription/internal/server-integration.d.ts +5 -0
  565. package/dist/subscription/internal/subscription-runtime.d.cts +13 -1
  566. package/dist/subscription/internal/subscription-runtime.d.ts +13 -1
  567. package/dist/task-errors.d.ts +58 -0
  568. package/dist/task-store.cjs +7 -8
  569. package/dist/task-store.d.cts +2 -0
  570. package/dist/task-store.d.ts +2 -0
  571. package/dist/task-store.js +4 -5
  572. package/dist/types/agent-prims.d.ts +21 -0
  573. package/dist/types/agent.d.ts +109 -15
  574. package/dist/types/batch.d.ts +3 -0
  575. package/dist/types/budget-tracker.d.ts +3 -0
  576. package/dist/types/budget.d.ts +12 -3
  577. package/dist/types/content-blocks.d.ts +3 -0
  578. package/dist/types/context.d.ts +3 -0
  579. package/dist/types/conversation.d.ts +5 -0
  580. package/dist/types/cron.d.ts +5 -0
  581. package/dist/types/env-policy.d.ts +3 -0
  582. package/dist/types/eval.d.ts +3 -0
  583. package/dist/types/fork.d.ts +3 -0
  584. package/dist/types/goal-events.d.ts +3 -0
  585. package/dist/types/mcp.d.ts +5 -0
  586. package/dist/types/memory-adapter.d.ts +3 -0
  587. package/dist/types/memory-provider.d.ts +44 -5
  588. package/dist/types/messages-base.d.ts +4 -0
  589. package/dist/types/messages.d.ts +5 -0
  590. package/dist/types/plugin.d.ts +32 -4
  591. package/dist/types/processors.d.ts +3 -0
  592. package/dist/types/provider-profile.d.ts +3 -0
  593. package/dist/types/providers.d.ts +3 -0
  594. package/dist/types/run-events.d.ts +36 -9
  595. package/dist/types/run.d.ts +29 -2
  596. package/dist/types/sdk-agent.d.ts +71 -1
  597. package/dist/types/session-message.d.ts +3 -0
  598. package/dist/types/session-record.d.ts +3 -0
  599. package/dist/types/session-store.d.ts +45 -0
  600. package/dist/types/task.d.ts +3 -11
  601. package/dist/types/theokit.d.ts +3 -0
  602. package/dist/types/trajectory.d.ts +3 -0
  603. package/dist/types/updates.d.ts +5 -0
  604. package/dist/types/usage.d.ts +4 -1
  605. package/dist/types/workflow.d.ts +13 -135
  606. package/dist/workflow-as-tool.d.ts +66 -0
  607. package/dist/workflow-errors.d.ts +164 -0
  608. package/dist/workflow.cjs +29 -30
  609. package/dist/workflow.d.cts +135 -74
  610. package/dist/workflow.d.ts +135 -74
  611. package/dist/workflow.js +8 -9
  612. package/docs/adr/README.md +2604 -0
  613. package/docs/error-codes.md +139 -105
  614. package/docs/harness-capability-map.md +32 -20
  615. package/docs/memory-decisions.md +1 -1
  616. package/package.json +3 -7
  617. package/bin/theokit-migrate-config.mjs +0 -278
  618. package/bin/theokit-migrate-memory.mjs +0 -116
  619. package/dist/agent-A5XMIVNP.js +0 -57
  620. package/dist/agent-UX7WFI6B.cjs +0 -66
  621. package/dist/agent-session-store-6EL5NPA4.cjs +0 -24
  622. package/dist/agent-session-store-OPGRB4XM.js +0 -7
  623. package/dist/batch-BXYTW2DP.cjs.map +0 -1
  624. package/dist/batch-L4ZXS46M.js.map +0 -1
  625. package/dist/chunk-247ZTLNU.js +0 -73
  626. package/dist/chunk-247ZTLNU.js.map +0 -1
  627. package/dist/chunk-2D34UTDC.js.map +0 -1
  628. package/dist/chunk-2GUYQR5P.js.map +0 -1
  629. package/dist/chunk-2QDYBS2A.js.map +0 -1
  630. package/dist/chunk-32WTYBUH.js.map +0 -1
  631. package/dist/chunk-3FFAEAUJ.cjs.map +0 -1
  632. package/dist/chunk-3O42QOMJ.js.map +0 -1
  633. package/dist/chunk-3OR54XG4.js.map +0 -1
  634. package/dist/chunk-43ZQRWAP.cjs.map +0 -1
  635. package/dist/chunk-4FFBAUFS.js.map +0 -1
  636. package/dist/chunk-4O5TGQBW.cjs.map +0 -1
  637. package/dist/chunk-4OTIXDMU.cjs.map +0 -1
  638. package/dist/chunk-4PYZ5AX3.cjs.map +0 -1
  639. package/dist/chunk-4QZSA2HJ.js.map +0 -1
  640. package/dist/chunk-4ZHTIJNE.cjs.map +0 -1
  641. package/dist/chunk-52NKC5HT.cjs.map +0 -1
  642. package/dist/chunk-6HKGLTJI.cjs.map +0 -1
  643. package/dist/chunk-6JSIEDKL.cjs.map +0 -1
  644. package/dist/chunk-7AD3ZTZL.js.map +0 -1
  645. package/dist/chunk-7BG5UH3T.cjs.map +0 -1
  646. package/dist/chunk-7VT4P3Z4.cjs.map +0 -1
  647. package/dist/chunk-7YGCPMGB.js.map +0 -1
  648. package/dist/chunk-A46SWMIF.js.map +0 -1
  649. package/dist/chunk-A4JVILQU.js.map +0 -1
  650. package/dist/chunk-ACDLHN3W.js.map +0 -1
  651. package/dist/chunk-AKJP2STZ.cjs +0 -81
  652. package/dist/chunk-AKJP2STZ.cjs.map +0 -1
  653. package/dist/chunk-AWO27VRZ.js.map +0 -1
  654. package/dist/chunk-B2J4ZMZL.cjs.map +0 -1
  655. package/dist/chunk-B4EOJWOY.cjs.map +0 -1
  656. package/dist/chunk-BU4KFWXF.js.map +0 -1
  657. package/dist/chunk-BZRFXJHA.js.map +0 -1
  658. package/dist/chunk-C3NT3PVE.js.map +0 -1
  659. package/dist/chunk-C72AZW7J.js.map +0 -1
  660. package/dist/chunk-D4CUGAKZ.js.map +0 -1
  661. package/dist/chunk-DN2PACRI.js.map +0 -1
  662. package/dist/chunk-DXGZ2NUG.cjs.map +0 -1
  663. package/dist/chunk-EG4QM7ZJ.cjs +0 -39
  664. package/dist/chunk-EG4QM7ZJ.cjs.map +0 -1
  665. package/dist/chunk-GMLBYDW4.cjs.map +0 -1
  666. package/dist/chunk-HCZD23VS.cjs.map +0 -1
  667. package/dist/chunk-HS7AVXTF.js.map +0 -1
  668. package/dist/chunk-IAHZCGBE.cjs.map +0 -1
  669. package/dist/chunk-J24VJOH3.cjs.map +0 -1
  670. package/dist/chunk-JPBKYL3B.cjs +0 -18
  671. package/dist/chunk-JPBKYL3B.cjs.map +0 -1
  672. package/dist/chunk-KQ7TS7WW.cjs.map +0 -1
  673. package/dist/chunk-KQRW2GPZ.js.map +0 -1
  674. package/dist/chunk-KYAJINUI.cjs.map +0 -1
  675. package/dist/chunk-L3MTL4NA.js.map +0 -1
  676. package/dist/chunk-L4BDVXIM.js.map +0 -1
  677. package/dist/chunk-LKBEROHN.js.map +0 -1
  678. package/dist/chunk-LYRDF5TQ.cjs.map +0 -1
  679. package/dist/chunk-LYTOXSRH.js.map +0 -1
  680. package/dist/chunk-N2U4AZGB.js.map +0 -1
  681. package/dist/chunk-NDGGJQTZ.js.map +0 -1
  682. package/dist/chunk-O7DK5PBJ.cjs.map +0 -1
  683. package/dist/chunk-O7LZFG6O.cjs.map +0 -1
  684. package/dist/chunk-OFRFZRQ4.cjs.map +0 -1
  685. package/dist/chunk-OSEG74VJ.js.map +0 -1
  686. package/dist/chunk-RFMBZPOW.cjs.map +0 -1
  687. package/dist/chunk-RFXWMRFC.js.map +0 -1
  688. package/dist/chunk-RIAM53CP.js.map +0 -1
  689. package/dist/chunk-RMWTPV3M.cjs.map +0 -1
  690. package/dist/chunk-RNB4APBZ.js.map +0 -1
  691. package/dist/chunk-SAVIWMZB.js.map +0 -1
  692. package/dist/chunk-SZVR77EJ.cjs.map +0 -1
  693. package/dist/chunk-TAZVKYWJ.js.map +0 -1
  694. package/dist/chunk-U54XCYG3.js.map +0 -1
  695. package/dist/chunk-U6IFHFWK.js.map +0 -1
  696. package/dist/chunk-UALX2J2Q.cjs.map +0 -1
  697. package/dist/chunk-UBDMVMBZ.js.map +0 -1
  698. package/dist/chunk-UGT7GK7I.cjs.map +0 -1
  699. package/dist/chunk-UNYXQ4M5.js.map +0 -1
  700. package/dist/chunk-UTSRIDKZ.js.map +0 -1
  701. package/dist/chunk-UU36SHFY.cjs.map +0 -1
  702. package/dist/chunk-V2BOS4WF.cjs.map +0 -1
  703. package/dist/chunk-VCLBZAZU.cjs.map +0 -1
  704. package/dist/chunk-VJ26EKGJ.cjs.map +0 -1
  705. package/dist/chunk-VKJ7V7EB.cjs.map +0 -1
  706. package/dist/chunk-VLVVJLDH.cjs.map +0 -1
  707. package/dist/chunk-WLQNMXQE.js.map +0 -1
  708. package/dist/chunk-WNO3C3N2.cjs.map +0 -1
  709. package/dist/chunk-WTMU7J4U.js +0 -14
  710. package/dist/chunk-WTMU7J4U.js.map +0 -1
  711. package/dist/chunk-XEQ3TM66.js +0 -35
  712. package/dist/chunk-XEQ3TM66.js.map +0 -1
  713. package/dist/chunk-XJCXEKMD.cjs.map +0 -1
  714. package/dist/chunk-XL7Q7HB2.cjs.map +0 -1
  715. package/dist/chunk-XWTLIGO3.cjs.map +0 -1
  716. package/dist/chunk-YML4ME27.cjs.map +0 -1
  717. package/dist/chunk-ZSWPZ23K.cjs.map +0 -1
  718. package/dist/chunk-ZZMZWBR6.js.map +0 -1
  719. package/dist/compact-session-QV57KR66.cjs +0 -59
  720. package/dist/compact-session-RIGOWC4Y.js +0 -22
  721. package/dist/context-WFLTTMK3.cjs +0 -24
  722. package/dist/context-WI2DFG7V.js +0 -7
  723. package/dist/executor-6CYCA7MI.cjs.map +0 -1
  724. package/dist/executor-QSEC3MRH.js.map +0 -1
  725. package/dist/fork-agent-RSV4E3EA.js.map +0 -1
  726. package/dist/fork-agent-Y2IK2RYU.cjs.map +0 -1
  727. package/dist/fs-session-store-4PIHT5UX.cjs +0 -20
  728. package/dist/fs-session-store-NM6YSTE2.js +0 -11
  729. package/dist/generate-object-GUNAUVBX.js +0 -8
  730. package/dist/generate-object-R7HTMW7F.cjs +0 -21
  731. package/dist/index-manager-2SRX45WJ.cjs +0 -27
  732. package/dist/index-manager-SP4ISSDX.js +0 -18
  733. package/dist/inject-session-WQKMC3GR.cjs +0 -29
  734. package/dist/internal/persistence/credential-pool-store.d.cts +0 -32
  735. package/dist/internal/persistence/credential-pool-store.d.ts +0 -32
  736. package/dist/internal/runtime/memory/memory-path-selector.d.ts +0 -73
  737. package/dist/judge-call-LAHMBJ57.cjs +0 -23
  738. package/dist/judge-call-LVXABPS3.js +0 -6
  739. package/dist/oauth-transaction-store-BT4GLTLK.cjs +0 -36
  740. package/dist/oauth-transaction-store-W52KVHQ4.js +0 -3
  741. package/dist/registry-75W33OGL.js +0 -10
  742. package/dist/registry-V7BDQ6QB.cjs +0 -47
  743. package/dist/run-until-HEQOUVU6.js.map +0 -1
  744. package/dist/run-until-U2B5FJJI.cjs.map +0 -1
  745. package/dist/server/adapter/express.d.cts +0 -9
  746. package/dist/server/adapter/express.d.ts +0 -9
  747. package/dist/server/adapter/fastify.d.cts +0 -9
  748. package/dist/server/adapter/fastify.d.ts +0 -9
  749. package/dist/server/adapter/hono.d.cts +0 -9
  750. package/dist/server/adapter/hono.d.ts +0 -9
  751. package/dist/server/adapter/shared-handler.d.cts +0 -9
  752. package/dist/server/adapter/shared-handler.d.ts +0 -9
  753. package/dist/server/adapter/types.d.cts +0 -33
  754. package/dist/server/adapter/types.d.ts +0 -33
  755. package/dist/session-transcript-6WNITKRE.cjs +0 -63
  756. package/dist/session-transcript-XAEKW6P7.js +0 -6
  757. package/dist/stream-object-UF4QRQRU.js +0 -8
  758. package/dist/stream-object-ZJTQNKY3.cjs +0 -21
  759. package/dist/subagents-loader-UCNO7FUH.cjs +0 -17
  760. package/dist/subagents-loader-XP5ERVDZ.js +0 -8
  761. /package/dist/{batch.d.ts → internal/agent/batch.d.ts} +0 -0
  762. /package/dist/{agent-helpers.d.ts → internal/agent/helpers.d.ts} +0 -0
  763. /package/dist/internal/agent-loop/{loop-types.d.ts → types.d.ts} +0 -0
  764. /package/dist/internal/auth/{auth-types.d.ts → types.d.ts} +0 -0
  765. /package/dist/internal/cloud-agent/{cloud-payload-types.d.ts → types.d.ts} +0 -0
  766. /package/dist/internal/{runtime/concurrency → concurrency}/abort-utils.d.ts +0 -0
  767. /package/dist/internal/{runtime/concurrency → concurrency}/async-local-storage.d.ts +0 -0
  768. /package/dist/internal/{runtime/concurrency → concurrency}/async-semaphore.d.ts +0 -0
  769. /package/dist/internal/{runtime/concurrency → concurrency}/delegation-depth.d.ts +0 -0
  770. /package/dist/internal/{runtime/concurrency → concurrency}/map-with-concurrency.d.ts +0 -0
  771. /package/dist/internal/{runtime/retry → error-mappers}/default-retriable.d.ts +0 -0
  772. /package/dist/internal/{runtime/fixtures/fixture-types.d.ts → memory/storage/list-markdown.d.cts} +0 -0
  773. /package/dist/internal/{runtime/plugins/plugins-manager.d.ts → memory/storage/list-markdown.d.ts} +0 -0
  774. /package/dist/internal/{resilience → retry}/circuit-breaker.d.ts +0 -0
  775. /package/dist/internal/{runtime/retry → retry}/with-retry.d.ts +0 -0
  776. /package/dist/internal/{security/secret-redactor.d.cts → runtime/fixtures/types.d.ts} +0 -0
  777. /package/dist/internal/runtime/{memory → memory-glue}/memory-store.d.ts +0 -0
  778. /package/dist/internal/runtime/{memory → memory-glue}/select-facts.d.ts +0 -0
  779. /package/dist/internal/runtime/{plugins → plugin-loader}/plugin-frontmatter.d.ts +0 -0
  780. /package/dist/internal/{security/secret-redactor.d.ts → runtime/plugin-loader/plugins-manager.d.ts} +0 -0
  781. /package/dist/internal/runtime/{reasoning → system-prompt}/native-reasoning.d.ts +0 -0
  782. /package/dist/internal/{runtime/context/path-containment.d.ts → security/path-containment.d.cts} +0 -0
  783. /package/dist/internal/session/{session-types.d.ts → types.d.ts} +0 -0
  784. /package/dist/internal/{zod/to-json-schema.d.ts → zod-to-json-schema.d.ts} +0 -0
  785. /package/dist/subscription/internal/{adapter-types.d.cts → types.d.cts} +0 -0
  786. /package/dist/subscription/internal/{adapter-types.d.ts → types.d.ts} +0 -0
@@ -1,16 +1,19 @@
1
1
  'use strict';
2
2
 
3
- var chunkO7DK5PBJ_cjs = require('./chunk-O7DK5PBJ.cjs');
4
- var chunk4OTIXDMU_cjs = require('./chunk-4OTIXDMU.cjs');
5
- var chunkUGT7GK7I_cjs = require('./chunk-UGT7GK7I.cjs');
6
- var chunk6JSIEDKL_cjs = require('./chunk-6JSIEDKL.cjs');
3
+ var chunkFUSDYC2B_cjs = require('./chunk-FUSDYC2B.cjs');
4
+ var chunkYJNYDJ2T_cjs = require('./chunk-YJNYDJ2T.cjs');
5
+ var chunk24SYBZPL_cjs = require('./chunk-24SYBZPL.cjs');
6
+ var chunkQOGNZMHD_cjs = require('./chunk-QOGNZMHD.cjs');
7
+ var chunkYSTXFWQE_cjs = require('./chunk-YSTXFWQE.cjs');
7
8
  var chunkFRITRLZQ_cjs = require('./chunk-FRITRLZQ.cjs');
8
- var chunk5HEG4CQH_cjs = require('./chunk-5HEG4CQH.cjs');
9
- var chunkDXGZ2NUG_cjs = require('./chunk-DXGZ2NUG.cjs');
10
- var chunkHCZD23VS_cjs = require('./chunk-HCZD23VS.cjs');
11
- var chunkXJCXEKMD_cjs = require('./chunk-XJCXEKMD.cjs');
12
- var chunk4ZHTIJNE_cjs = require('./chunk-4ZHTIJNE.cjs');
13
- var chunkEG4QM7ZJ_cjs = require('./chunk-EG4QM7ZJ.cjs');
9
+ var chunkGZV6AVRL_cjs = require('./chunk-GZV6AVRL.cjs');
10
+ var chunkATT276RD_cjs = require('./chunk-ATT276RD.cjs');
11
+ var chunk3EE6LVWT_cjs = require('./chunk-3EE6LVWT.cjs');
12
+ var chunkQC55H6RJ_cjs = require('./chunk-QC55H6RJ.cjs');
13
+ var chunkNVXXWAU7_cjs = require('./chunk-NVXXWAU7.cjs');
14
+ var chunkEXTRW7GW_cjs = require('./chunk-EXTRW7GW.cjs');
15
+ var chunkJ7J7J2GN_cjs = require('./chunk-J7J7J2GN.cjs');
16
+ var chunk6LHQPOMI_cjs = require('./chunk-6LHQPOMI.cjs');
14
17
  var fs = require('fs');
15
18
  var promises = require('fs/promises');
16
19
  var os = require('os');
@@ -19,7 +22,7 @@ var url = require('url');
19
22
  var module$1 = require('module');
20
23
 
21
24
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
22
- var discoveryState = chunkHCZD23VS_cjs.globalSingleton("theokit-sdk.providers.discovered", () => ({
25
+ var discoveryState = chunkNVXXWAU7_cjs.globalSingleton("theokit-sdk.providers.discovered", () => ({
23
26
  done: false
24
27
  }));
25
28
  function pluginsRoot() {
@@ -41,19 +44,19 @@ function loadTrustedNames() {
41
44
  else discarded += 1;
42
45
  }
43
46
  if (discarded > 0) {
44
- chunkEG4QM7ZJ_cjs.diag(
47
+ chunk6LHQPOMI_cjs.diag(
45
48
  `[theokit-sdk] WARN: ${path} contains ${discarded} non-string entr${discarded === 1 ? "y" : "ies"} \u2014 discarded (entries must be plugin-name strings)
46
49
  `
47
50
  );
48
51
  }
49
52
  } else {
50
- chunkEG4QM7ZJ_cjs.diag(
53
+ chunk6LHQPOMI_cjs.diag(
51
54
  `[theokit-sdk] WARN: ${path} is not a JSON array \u2014 trusting NO provider plugins (fail-closed)
52
55
  `
53
56
  );
54
57
  }
55
58
  } catch {
56
- chunkEG4QM7ZJ_cjs.diag(
59
+ chunk6LHQPOMI_cjs.diag(
57
60
  `[theokit-sdk] WARN: ${path} is not valid JSON \u2014 trusting NO provider plugins (fail-closed)
58
61
  `
59
62
  );
@@ -79,7 +82,7 @@ async function discoverProviderPlugins() {
79
82
  const trusted = loadTrustedNames();
80
83
  for (const entry of entries) {
81
84
  if (!trusted.has(entry)) {
82
- chunkEG4QM7ZJ_cjs.diag(
85
+ chunk6LHQPOMI_cjs.diag(
83
86
  `[theokit-sdk] WARN: provider plugin "${entry}" is present but NOT trusted \u2014 skipped. To trust it, add "${entry}" to ${trustFilePath()} (JSON array of names) or THEOKIT_TRUSTED_PROVIDERS (comma-separated), then restart the process.
84
87
  `
85
88
  );
@@ -98,13 +101,13 @@ async function loadOne(dir, entryName) {
98
101
  if (plugin !== null && typeof plugin === "object" && plugin.kind === "model-provider") {
99
102
  const profile = plugin.profile;
100
103
  if (profile !== void 0 && typeof profile === "object") {
101
- chunkHCZD23VS_cjs.registerProvider(profile);
104
+ chunkQC55H6RJ_cjs.registerProvider(profile);
102
105
  }
103
106
  }
104
107
  return;
105
108
  } catch (err) {
106
109
  const msg = err instanceof Error ? err.message : String(err);
107
- chunkEG4QM7ZJ_cjs.diag(`[theokit-sdk] failed to load provider plugin "${entryName}": ${msg}
110
+ chunk6LHQPOMI_cjs.diag(`[theokit-sdk] failed to load provider plugin "${entryName}": ${msg}
108
111
  `);
109
112
  return;
110
113
  }
@@ -116,7 +119,7 @@ function mapAnthropicError(args) {
116
119
  const { status, body, headers, endpoint } = args;
117
120
  const code = mapAnthropicStatusToCode(status, body);
118
121
  const message = formatMessage(status, code);
119
- const metadata = chunkUGT7GK7I_cjs.buildErrorMetadata({
122
+ const metadata = chunk24SYBZPL_cjs.buildErrorMetadata({
120
123
  provider: "anthropic",
121
124
  endpoint,
122
125
  code,
@@ -125,29 +128,26 @@ function mapAnthropicError(args) {
125
128
  body
126
129
  });
127
130
  if (status === 401 || status === 403) {
128
- return new chunk4ZHTIJNE_cjs.AuthenticationError(message, { code: "anthropic_auth_failed", metadata });
131
+ return new chunkJ7J7J2GN_cjs.AuthenticationError(message, { code: "anthropic_auth_failed", metadata });
129
132
  }
130
133
  if (status === 429) {
131
- return new chunk4ZHTIJNE_cjs.RateLimitError(message, { code: "anthropic_rate_limit", metadata });
134
+ return new chunkJ7J7J2GN_cjs.RateLimitError(message, { code: "anthropic_rate_limit", metadata });
132
135
  }
133
136
  if (status === 400) {
134
- return new chunk4ZHTIJNE_cjs.ConfigurationError(message, {
137
+ return new chunkJ7J7J2GN_cjs.ConfigurationError(message, {
135
138
  code: `anthropic_${code}`,
136
139
  metadata
137
140
  });
138
141
  }
139
142
  if (status === 408) {
140
- return new chunk4ZHTIJNE_cjs.NetworkError(message, { code: "anthropic_timeout", metadata });
143
+ return new chunkJ7J7J2GN_cjs.NetworkError(message, { code: "anthropic_timeout", metadata });
141
144
  }
142
145
  if (status >= 500 && status < 600) {
143
- return new chunk4ZHTIJNE_cjs.NetworkError(message, { code: "anthropic_server_error", metadata });
146
+ return new chunkJ7J7J2GN_cjs.NetworkError(message, { code: "anthropic_server_error", metadata });
144
147
  }
145
- return new chunk4ZHTIJNE_cjs.UnknownAgentError(message, { code: "anthropic_unknown", metadata });
148
+ return new chunkJ7J7J2GN_cjs.UnknownAgentError(message, { code: "anthropic_unknown", metadata });
146
149
  }
147
150
  function mapAnthropicStatusToCode(status, body) {
148
- if (status === 401 || status === 403) return "auth_failed";
149
- if (status === 429) return "rate_limit";
150
- if (status === 408) return "timeout";
151
151
  if (status === 400) {
152
152
  const text = JSON.stringify(body ?? "").toLowerCase();
153
153
  if (text.includes("context") && (text.includes("too long") || text.includes("too_long") || text.includes("length"))) {
@@ -158,8 +158,7 @@ function mapAnthropicStatusToCode(status, body) {
158
158
  }
159
159
  return "invalid_request";
160
160
  }
161
- if (status >= 500 && status < 600) return "server_error";
162
- return "unknown";
161
+ return chunk24SYBZPL_cjs.httpStatusToErrorCode(status);
163
162
  }
164
163
  function formatMessage(status, code) {
165
164
  return `Anthropic API error: ${code} (HTTP ${status})`;
@@ -176,8 +175,8 @@ function parseToolArguments(buffered) {
176
175
  try {
177
176
  return JSON.parse(buffered);
178
177
  } catch {
179
- const repaired = chunk6JSIEDKL_cjs.tryJson(buffered, true);
180
- if (chunk6JSIEDKL_cjs.isPlainObject(repaired)) return repaired;
178
+ const repaired = chunkYSTXFWQE_cjs.tryJson(buffered, true);
179
+ if (chunkYSTXFWQE_cjs.isPlainObject(repaired)) return repaired;
181
180
  return { raw: buffered };
182
181
  }
183
182
  }
@@ -200,7 +199,7 @@ function assign(finish, key, value) {
200
199
  if (value === void 0) return;
201
200
  const count = asTokenCount(value);
202
201
  if (count === void 0) {
203
- chunkEG4QM7ZJ_cjs.diag(
202
+ chunk6LHQPOMI_cjs.diag(
204
203
  `[theokit-sdk] provider reported an unusable ${key} (${String(value)}) \u2014 dropping it. Usage and cost for this turn will be incomplete.
205
204
  `
206
205
  );
@@ -230,7 +229,7 @@ function toBlockToolResultContent(content) {
230
229
  function toStringToolResultContent(content, providerName) {
231
230
  if (typeof content === "string") return content;
232
231
  if (content.some((block) => block.type === "image")) {
233
- throw new chunk4ZHTIJNE_cjs.ConfigurationError(
232
+ throw new chunkJ7J7J2GN_cjs.ConfigurationError(
234
233
  `provider "${providerName}" does not support image content in tool results`
235
234
  );
236
235
  }
@@ -409,7 +408,7 @@ function readWithIdleTimeout(reader, idleTimeoutMs) {
409
408
  (resolve, reject) => {
410
409
  const timer = setTimeout(() => {
411
410
  reject(
412
- new chunk4ZHTIJNE_cjs.NetworkError(`SSE stream idle for ${idleTimeoutMs}ms \u2014 upstream stalled`, {
411
+ new chunkJ7J7J2GN_cjs.NetworkError(`SSE stream idle for ${idleTimeoutMs}ms \u2014 upstream stalled`, {
413
412
  code: "stream_idle_timeout"
414
413
  })
415
414
  );
@@ -479,16 +478,16 @@ function releaseReader(reader) {
479
478
  }
480
479
 
481
480
  // src/internal/llm/transport-error.ts
482
- function ehAbort(err) {
481
+ function isAbortError(err) {
483
482
  if (typeof err !== "object" || err === null) return false;
484
- const nome = err.name;
485
- return nome === "AbortError" || nome === "TimeoutError";
483
+ const name = err.name;
484
+ return name === "AbortError" || name === "TimeoutError";
486
485
  }
487
486
  function wrapTransportError(err, ctx) {
488
- if (ehAbort(err)) return err;
489
- if (err instanceof chunk4ZHTIJNE_cjs.TheokitAgentError) return err;
487
+ if (isAbortError(err)) return err;
488
+ if (err instanceof chunkJ7J7J2GN_cjs.TheokitAgentError) return err;
490
489
  const detail = err instanceof Error ? err.message : String(err);
491
- return new chunk4ZHTIJNE_cjs.NetworkError(`${ctx.providerId} transport failure on ${ctx.endpoint}: ${detail}`, {
490
+ return new chunkJ7J7J2GN_cjs.NetworkError(`${ctx.providerId} transport failure on ${ctx.endpoint}: ${detail}`, {
492
491
  code: "transport_failure",
493
492
  cause: err
494
493
  });
@@ -552,7 +551,7 @@ var AnthropicClient = class {
552
551
  for (const event of events) yield event;
553
552
  }
554
553
  if (!accumulator.finishReasonSeen) {
555
- throw new chunk4ZHTIJNE_cjs.NetworkError("Anthropic SSE stream truncated (no stop_reason)", {
554
+ throw new chunkJ7J7J2GN_cjs.NetworkError("Anthropic SSE stream truncated (no stop_reason)", {
556
555
  code: "stream_truncated"
557
556
  });
558
557
  }
@@ -691,21 +690,20 @@ function buildAnthropicBody(request) {
691
690
 
692
691
  // src/internal/error-mappers/bedrock.ts
693
692
  function classifyBedrockError(args, awsType, message) {
694
- if (args.status === 429 || awsType.includes("Throttling") || awsType.includes("TooManyRequests")) {
693
+ if (awsType.includes("Throttling") || awsType.includes("TooManyRequests")) {
695
694
  return "rate_limit";
696
695
  }
697
- if (args.status === 401 || args.status === 403 || awsType.includes("AccessDenied") || awsType.includes("UnauthorizedOperation")) {
696
+ if (awsType.includes("AccessDenied") || awsType.includes("UnauthorizedOperation")) {
698
697
  return "auth_failed";
699
698
  }
700
- if (args.status === 400 || args.status === 404 || awsType.includes("ValidationException") || awsType.includes("ResourceNotFound") || message.includes("use case details")) {
699
+ if (args.status === 404 || awsType.includes("ValidationException") || awsType.includes("ResourceNotFound") || message.includes("use case details")) {
701
700
  return "invalid_request";
702
701
  }
703
- if (args.status === 408 || awsType.includes("Timeout")) return "timeout";
704
- if (args.status >= 500) return "server_error";
705
- return "unknown";
702
+ if (awsType.includes("Timeout")) return "timeout";
703
+ return chunk24SYBZPL_cjs.httpStatusToErrorCode(args.status);
706
704
  }
707
705
  function buildBedrockMetadata(args, code) {
708
- return chunkUGT7GK7I_cjs.buildErrorMetadata({
706
+ return chunk24SYBZPL_cjs.buildErrorMetadata({
709
707
  provider: "bedrock",
710
708
  endpoint: args.endpoint,
711
709
  code,
@@ -715,39 +713,30 @@ function buildBedrockMetadata(args, code) {
715
713
  });
716
714
  }
717
715
  function mapBedrockError(args) {
718
- const parsed = parseBody(args.body);
716
+ const parsed = chunk24SYBZPL_cjs.parseErrorBody(args.body);
719
717
  const awsType = parsed.__type ?? "";
720
718
  const message = parsed.message ?? parsed.Message ?? "Bedrock request failed";
721
719
  const code = classifyBedrockError(args, awsType, message);
722
720
  const metadata = buildBedrockMetadata(args, code);
723
721
  switch (code) {
724
722
  case "rate_limit":
725
- return new chunk4ZHTIJNE_cjs.RateLimitError(`Bedrock throttled: ${message}`, { metadata });
723
+ return new chunkJ7J7J2GN_cjs.RateLimitError(`Bedrock throttled: ${message}`, { metadata });
726
724
  case "auth_failed":
727
- return new chunk4ZHTIJNE_cjs.AuthenticationError(`Bedrock auth: ${message}`, { metadata });
725
+ return new chunkJ7J7J2GN_cjs.AuthenticationError(`Bedrock auth: ${message}`, { metadata });
728
726
  case "invalid_request": {
729
727
  const friendly = message.includes("use case details") ? `Bedrock account setup required: ${message} (AWS Console \u2192 Bedrock \u2192 Model access \u2192 Anthropic \u2192 Submit use case form, then retry in 15 min.)` : `Bedrock validation: ${message}`;
730
- return new chunk4ZHTIJNE_cjs.ConfigurationError(friendly, { metadata });
728
+ return new chunkJ7J7J2GN_cjs.ConfigurationError(friendly, { metadata });
731
729
  }
730
+ case "quota_exceeded":
731
+ return new chunkJ7J7J2GN_cjs.RateLimitError(`Bedrock quota exceeded: ${message}`, { metadata });
732
732
  case "timeout":
733
- return new chunk4ZHTIJNE_cjs.NetworkError(`Bedrock timeout: ${message}`, { metadata });
733
+ return new chunkJ7J7J2GN_cjs.NetworkError(`Bedrock timeout: ${message}`, { metadata });
734
734
  case "server_error":
735
- return new chunk4ZHTIJNE_cjs.NetworkError(`Bedrock server error: ${message}`, { metadata });
735
+ return new chunkJ7J7J2GN_cjs.NetworkError(`Bedrock server error: ${message}`, { metadata });
736
736
  default:
737
- return new chunk4ZHTIJNE_cjs.UnknownAgentError(`Bedrock unknown: ${message}`, { metadata });
737
+ return new chunkJ7J7J2GN_cjs.UnknownAgentError(`Bedrock unknown: ${message}`, { metadata });
738
738
  }
739
739
  }
740
- function parseBody(body) {
741
- if (body !== null && typeof body === "object") return body;
742
- if (typeof body === "string") {
743
- try {
744
- return JSON.parse(body);
745
- } catch {
746
- return {};
747
- }
748
- }
749
- return {};
750
- }
751
740
  var cachedToken = null;
752
741
  var CACHE_TTL_MS = 90 * 60 * 1e3;
753
742
  async function resolveBedrockToken(region) {
@@ -758,7 +747,7 @@ async function resolveBedrockToken(region) {
758
747
  return cachedToken.value;
759
748
  }
760
749
  try {
761
- const r = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-KYAJINUI.cjs', document.baseURI).href)));
750
+ const r = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-2HPNT6HH.cjs', document.baseURI).href)));
762
751
  const gen = r("@aws/bedrock-token-generator");
763
752
  if (typeof gen.getToken !== "function") return void 0;
764
753
  const providers = r("@aws-sdk/credential-providers");
@@ -786,16 +775,16 @@ var BedrockAnthropicClient = class {
786
775
  if (fromOpts !== void 0 && fromOpts.length > 0) return fromOpts;
787
776
  const fromEnv = await resolveBedrockToken(region);
788
777
  if (fromEnv !== void 0 && fromEnv.length > 0) return fromEnv;
789
- throw new chunk4ZHTIJNE_cjs.ConfigurationError(
778
+ throw new chunkJ7J7J2GN_cjs.ConfigurationError(
790
779
  "Bedrock requires AWS_BEARER_TOKEN_BEDROCK env var, or install `@aws/bedrock-token-generator` for auto-refresh, or pass apiKey explicitly.",
791
780
  { code: "auth_failed" }
792
781
  );
793
782
  }
794
783
  async *stream(request, signal) {
795
- const region = chunkHCZD23VS_cjs.inferRegionFromModelId(request.model) ?? process.env.AWS_REGION ?? "us-east-1";
784
+ const region = chunkQC55H6RJ_cjs.inferRegionFromModelId(request.model) ?? process.env.AWS_REGION ?? "us-east-1";
796
785
  const token = await this.resolveTokenOrThrow(region);
797
- const bareModel = chunkHCZD23VS_cjs.stripBedrockPrefix(request.model);
798
- const baseUrl = this.options.baseUrl ?? chunkHCZD23VS_cjs.resolveBedrockBaseUrl(request.model);
786
+ const bareModel = chunkQC55H6RJ_cjs.stripBedrockPrefix(request.model);
787
+ const baseUrl = this.options.baseUrl ?? chunkQC55H6RJ_cjs.resolveBedrockBaseUrl(request.model);
799
788
  const endpoint = `/model/${encodeURIComponent(bareModel)}/invoke`;
800
789
  const url = `${baseUrl}${endpoint}`;
801
790
  const response = await postAnthropicRequest({
@@ -850,7 +839,7 @@ var FaultInjectingLlmClient = class {
850
839
  return yield* this.inner.stream(request, signal);
851
840
  }
852
841
  if (parsed.status >= 400) {
853
- throw chunkUGT7GK7I_cjs.mapOpenAICompatibleError({
842
+ throw chunk24SYBZPL_cjs.mapOpenAICompatibleError({
854
843
  providerId: this.name,
855
844
  status: parsed.status,
856
845
  body: parsed.body,
@@ -897,7 +886,7 @@ function parseOverrideOrWarnOnce() {
897
886
  function warnInvalidJsonOnce(_raw) {
898
887
  if (warnedInvalidJson) return;
899
888
  warnedInvalidJson = true;
900
- chunkEG4QM7ZJ_cjs.diag(
889
+ chunk6LHQPOMI_cjs.diag(
901
890
  `[theokit-sdk] ${ENV_OVERRIDE_KEY} is set but value is not valid JSON of shape \`{"status": number, "body": object | string}\`. Falling back to real LLM call. This warning is shown once per process.
902
891
  `
903
892
  );
@@ -925,7 +914,7 @@ function mapOllamaTransportError(args) {
925
914
  if (args.providerId !== "ollama") return void 0;
926
915
  const causeCode = extractCauseCode(args.cause);
927
916
  if (causeCode !== "ECONNREFUSED" && causeCode !== "ENOTFOUND") return void 0;
928
- const metadata = chunkUGT7GK7I_cjs.buildErrorMetadata({
917
+ const metadata = chunk24SYBZPL_cjs.buildErrorMetadata({
929
918
  provider: "ollama",
930
919
  endpoint: args.endpoint,
931
920
  code: "network",
@@ -933,7 +922,7 @@ function mapOllamaTransportError(args) {
933
922
  headers: void 0,
934
923
  body: { cause: causeCode }
935
924
  });
936
- return new chunk4ZHTIJNE_cjs.ConfigurationError(
925
+ return new chunkJ7J7J2GN_cjs.ConfigurationError(
937
926
  "Ollama is not reachable. Run `ollama serve` to start the local runtime, or set OLLAMA_HOST to point at a remote Ollama server.",
938
927
  { code: "ollama_unreachable", metadata }
939
928
  );
@@ -943,7 +932,7 @@ function mapOllamaHttpError(args) {
943
932
  const errString = extractErrorString(args.body).toLowerCase();
944
933
  if (args.status === 404 && errString.includes("not found") && errString.includes("pull")) {
945
934
  const modelHint = extractModelName(errString);
946
- const metadata = chunkUGT7GK7I_cjs.buildErrorMetadata({
935
+ const metadata = chunk24SYBZPL_cjs.buildErrorMetadata({
947
936
  provider: "ollama",
948
937
  endpoint: args.endpoint,
949
938
  code: "model_unavailable",
@@ -952,13 +941,13 @@ function mapOllamaHttpError(args) {
952
941
  body: args.body
953
942
  });
954
943
  const pullCmd = modelHint !== void 0 ? `ollama pull ${modelHint}` : "ollama pull <model>";
955
- return new chunk4ZHTIJNE_cjs.ConfigurationError(
944
+ return new chunkJ7J7J2GN_cjs.ConfigurationError(
956
945
  `Ollama model is not pulled. Run \`${pullCmd}\` to download it first.`,
957
946
  { code: "ollama_model_not_pulled", metadata }
958
947
  );
959
948
  }
960
949
  if (args.status === 503 && errString.includes("model is loading")) {
961
- const metadata = chunkUGT7GK7I_cjs.buildErrorMetadata({
950
+ const metadata = chunk24SYBZPL_cjs.buildErrorMetadata({
962
951
  provider: "ollama",
963
952
  endpoint: args.endpoint,
964
953
  code: "server_error",
@@ -966,7 +955,7 @@ function mapOllamaHttpError(args) {
966
955
  headers: args.headers,
967
956
  body: args.body
968
957
  });
969
- return new chunk4ZHTIJNE_cjs.NetworkError(
958
+ return new chunkJ7J7J2GN_cjs.NetworkError(
970
959
  "Ollama model is loading. Retry in a few seconds \u2014 Ollama is warming up the model into memory.",
971
960
  { code: "ollama_model_loading", metadata }
972
961
  );
@@ -1028,7 +1017,7 @@ var OllamaNativeClient = class {
1028
1017
  endpoint: "/api/chat"
1029
1018
  });
1030
1019
  if (mapped !== void 0) throw mapped;
1031
- throw fetchErr;
1020
+ throw wrapTransportError(fetchErr, { providerId: "ollama", endpoint: "/api/chat" });
1032
1021
  }
1033
1022
  if (!response.ok) {
1034
1023
  const text = await response.text().catch(() => "");
@@ -1045,7 +1034,13 @@ var OllamaNativeClient = class {
1045
1034
  endpoint: "/api/chat"
1046
1035
  });
1047
1036
  if (mapped !== void 0) throw mapped;
1048
- throw new Error(`Ollama /api/chat HTTP ${response.status}: ${text.slice(0, 200)}`);
1037
+ throw chunk24SYBZPL_cjs.mapOpenAICompatibleError({
1038
+ providerId: "ollama",
1039
+ status: response.status,
1040
+ body: bodyJson,
1041
+ headers: response.headers,
1042
+ endpoint: "/api/chat"
1043
+ });
1049
1044
  }
1050
1045
  const accumulator = new OllamaStreamAccumulator();
1051
1046
  if (response.body === null) {
@@ -1187,7 +1182,7 @@ function toOllamaMessages(message) {
1187
1182
  }
1188
1183
  if (message.role === "user") {
1189
1184
  if (message.content.some((p) => p.type === "image")) {
1190
- throw new chunk4ZHTIJNE_cjs.ConfigurationError(
1185
+ throw new chunkJ7J7J2GN_cjs.ConfigurationError(
1191
1186
  "image input is not supported on the ollama-native provider; use an OpenAI/OpenRouter model for multimodal turns",
1192
1187
  { code: "ollama_image_unsupported" }
1193
1188
  );
@@ -1234,83 +1229,13 @@ function toOllamaTools(tools) {
1234
1229
  }
1235
1230
  }));
1236
1231
  }
1237
- var FIXTURE_API_KEY_PREFIX = "theo_test_";
1238
- function isFixtureApiKey(apiKey) {
1239
- if (apiKey === void 0) return false;
1240
- return apiKey.startsWith(FIXTURE_API_KEY_PREFIX);
1241
- }
1232
+
1233
+ // src/internal/base-url.ts
1242
1234
  function getConfiguredBaseUrl() {
1243
1235
  const value = process.env.THEOKIT_API_BASE_URL;
1244
1236
  if (value === void 0 || value.length === 0) return void 0;
1245
1237
  return value;
1246
1238
  }
1247
- function shouldUseFixtureMode(apiKey) {
1248
- if (getConfiguredBaseUrl() !== void 0) return false;
1249
- return isFixtureApiKey(apiKey);
1250
- }
1251
- var PROVIDER_CREDENTIAL_ENV_VARS = [
1252
- "ANTHROPIC_API_KEY",
1253
- "OPENAI_API_KEY",
1254
- "OPENROUTER_API_KEY"
1255
- ];
1256
- function presentProviderCredentialEnvVars() {
1257
- return PROVIDER_CREDENTIAL_ENV_VARS.filter((name) => {
1258
- const value = process.env[name];
1259
- return typeof value === "string" && value.length > 0;
1260
- });
1261
- }
1262
- function shouldUseRealLocalRuntime(apiKey) {
1263
- if (isFixtureApiKey(apiKey)) return false;
1264
- if (isStoredOAuthAvailable()) return true;
1265
- if (apiKey === void 0 || apiKey.length === 0) return false;
1266
- return presentProviderCredentialEnvVars().length > 0 || isAwsBedrockAuthAvailable() || isGcpVertexAuthAvailable() || isLocalNoAuthProviderAvailable();
1267
- }
1268
- var AMBIENT_STORE = {
1269
- home: os.homedir(),
1270
- dirName: ".theokit",
1271
- fileName: "auth.json",
1272
- homeEnvVar: "THEOKIT_AUTH_HOME"
1273
- };
1274
- function isStoredOAuthAvailable(env = process.env) {
1275
- try {
1276
- return chunkXJCXEKMD_cjs.readStoredOAuth(AMBIENT_STORE, env) !== void 0;
1277
- } catch {
1278
- return false;
1279
- }
1280
- }
1281
- function isAwsBedrockAuthAvailable() {
1282
- if (typeof process.env.AWS_BEARER_TOKEN_BEDROCK === "string" && process.env.AWS_BEARER_TOKEN_BEDROCK.length > 0) {
1283
- return true;
1284
- }
1285
- if (typeof process.env.AWS_ACCESS_KEY_ID === "string" && process.env.AWS_ACCESS_KEY_ID.length > 0) {
1286
- return true;
1287
- }
1288
- if (typeof process.env.AWS_PROFILE === "string" && process.env.AWS_PROFILE.length > 0) {
1289
- return true;
1290
- }
1291
- return awsCredentialsFileExists();
1292
- }
1293
- function awsCredentialsFileExists() {
1294
- try {
1295
- const home = process.env.HOME ?? process.env.USERPROFILE;
1296
- if (home === void 0 || home.length === 0) return false;
1297
- return fs.existsSync(`${home}/.aws/credentials`) || fs.existsSync(`${home}/.aws/config`);
1298
- } catch {
1299
- return false;
1300
- }
1301
- }
1302
- function isGcpVertexAuthAvailable() {
1303
- if (typeof process.env.GOOGLE_APPLICATION_CREDENTIALS === "string" && process.env.GOOGLE_APPLICATION_CREDENTIALS.length > 0) {
1304
- return true;
1305
- }
1306
- if (typeof process.env.GOOGLE_CLOUD_PROJECT === "string" && process.env.GOOGLE_CLOUD_PROJECT.length > 0) {
1307
- return true;
1308
- }
1309
- return false;
1310
- }
1311
- function isLocalNoAuthProviderAvailable() {
1312
- return true;
1313
- }
1314
1239
 
1315
1240
  // src/internal/http.ts
1316
1241
  var DEFAULT_BASE_URL = "https://api.usetheo.dev";
@@ -1341,7 +1266,7 @@ async function safeFetch(fetchFn, url, init) {
1341
1266
  try {
1342
1267
  return await fetchFn(url, init);
1343
1268
  } catch (cause) {
1344
- throw new chunk4ZHTIJNE_cjs.NetworkError("HTTP request failed", { code: "network_error", cause });
1269
+ throw new chunkJ7J7J2GN_cjs.NetworkError("HTTP request failed", { code: "network_error", cause });
1345
1270
  }
1346
1271
  }
1347
1272
  async function safeParseJsonResponse(response) {
@@ -1368,26 +1293,32 @@ function mapHttpStatusToError(status, body) {
1368
1293
  cause: body
1369
1294
  };
1370
1295
  if (envelope.code === "integration_not_connected") {
1371
- return new chunk4ZHTIJNE_cjs.IntegrationNotConnectedError(message, {
1296
+ return new chunkJ7J7J2GN_cjs.IntegrationNotConnectedError(message, {
1372
1297
  provider: envelope.provider ?? "unknown",
1373
1298
  helpUrl: envelope.helpUrl ?? "",
1374
1299
  code: envelope.code,
1375
1300
  cause: body
1376
1301
  });
1377
1302
  }
1303
+ return statusToError(status, message, errorOptions);
1304
+ }
1305
+ function statusToError(status, message, errorOptions) {
1378
1306
  if (status === 401 || status === 403) {
1379
- return new chunk4ZHTIJNE_cjs.AuthenticationError(message, errorOptions);
1307
+ return new chunkJ7J7J2GN_cjs.AuthenticationError(message, errorOptions);
1380
1308
  }
1381
1309
  if (status === 429) {
1382
- return new chunk4ZHTIJNE_cjs.RateLimitError(message, errorOptions);
1310
+ return new chunkJ7J7J2GN_cjs.RateLimitError(message, errorOptions);
1311
+ }
1312
+ if (status === 408) {
1313
+ return new chunkJ7J7J2GN_cjs.NetworkError(message, { ...errorOptions, code: errorOptions.code ?? "timeout" });
1383
1314
  }
1384
1315
  if (status >= 400 && status < 500) {
1385
- return new chunk4ZHTIJNE_cjs.ConfigurationError(message, errorOptions);
1316
+ return new chunkJ7J7J2GN_cjs.ConfigurationError(message, errorOptions);
1386
1317
  }
1387
1318
  if (status >= 500) {
1388
- return new chunk4ZHTIJNE_cjs.NetworkError(message, errorOptions);
1319
+ return new chunkJ7J7J2GN_cjs.NetworkError(message, errorOptions);
1389
1320
  }
1390
- return new chunk4ZHTIJNE_cjs.UnknownAgentError(message, errorOptions);
1321
+ return new chunkJ7J7J2GN_cjs.UnknownAgentError(message, errorOptions);
1391
1322
  }
1392
1323
  function extractErrorEnvelope(body) {
1393
1324
  if (!body || typeof body !== "object") return {};
@@ -1444,7 +1375,7 @@ function parseHermesParams(inner) {
1444
1375
  if (key === void 0 || value === void 0) continue;
1445
1376
  input[key.trim()] = value;
1446
1377
  }
1447
- return chunk6JSIEDKL_cjs.sanitizeToolInput(input, { trim: true }).value;
1378
+ return chunkYSTXFWQE_cjs.sanitizeToolInput(input, { trim: true }).value;
1448
1379
  }
1449
1380
  var STREAM_MARKER = "<function=";
1450
1381
  var DEFAULT_STREAM_BUFFER_CAP = 8192;
@@ -1641,7 +1572,7 @@ var OpenAIClient = class {
1641
1572
  endpoint: "/v1/chat/completions"
1642
1573
  });
1643
1574
  if (ollamaMapped !== void 0) throw ollamaMapped;
1644
- throw chunkUGT7GK7I_cjs.mapOpenAICompatibleError({
1575
+ throw chunk24SYBZPL_cjs.mapOpenAICompatibleError({
1645
1576
  providerId,
1646
1577
  status: response.status,
1647
1578
  body,
@@ -1677,7 +1608,7 @@ var OpenAIClient = class {
1677
1608
  }
1678
1609
  if (chunk.error !== void 0 && chunk.error !== null) {
1679
1610
  const status = typeof chunk.error.code === "number" ? chunk.error.code : 502;
1680
- throw chunkUGT7GK7I_cjs.mapOpenAICompatibleError({
1611
+ throw chunk24SYBZPL_cjs.mapOpenAICompatibleError({
1681
1612
  providerId,
1682
1613
  status,
1683
1614
  body: chunk,
@@ -1689,7 +1620,7 @@ var OpenAIClient = class {
1689
1620
  for (const event of events) yield event;
1690
1621
  }
1691
1622
  if (!sawDone && !accumulator.finishReasonSeen) {
1692
- throw new chunk4ZHTIJNE_cjs.NetworkError("SSE stream truncated (no finish_reason / [DONE])", {
1623
+ throw new chunkJ7J7J2GN_cjs.NetworkError("SSE stream truncated (no finish_reason / [DONE])", {
1693
1624
  code: "stream_truncated"
1694
1625
  });
1695
1626
  }
@@ -1821,13 +1752,13 @@ var OpenAIStreamAccumulator = class {
1821
1752
  toolCalls.push(...recovered.toolCalls);
1822
1753
  text = recovered.residualText;
1823
1754
  stopReason = "tool_use";
1824
- chunkEG4QM7ZJ_cjs.diag(
1755
+ chunk6LHQPOMI_cjs.diag(
1825
1756
  `[theokit-sdk] recovered ${recovered.toolCalls.length} leaked tool call(s) from assistant content (provider="${this.providerName}", names=${recovered.toolCalls.map((c) => c.name).join(",")})
1826
1757
  `
1827
1758
  );
1828
1759
  }
1829
1760
  if (recovered.droppedNames.length > 0) {
1830
- chunkEG4QM7ZJ_cjs.diag(
1761
+ chunk6LHQPOMI_cjs.diag(
1831
1762
  `[theokit-sdk] dropped ${recovered.droppedNames.length} leaked block(s) whose name is not a tool in the request (provider="${this.providerName}", names=${recovered.droppedNames.join(",")})
1832
1763
  `
1833
1764
  );
@@ -1900,7 +1831,7 @@ function encodeOpenAIResponseFormat(rf) {
1900
1831
  };
1901
1832
  }
1902
1833
 
1903
- // src/internal/resilience/circuit-breaker.ts
1834
+ // src/internal/retry/circuit-breaker.ts
1904
1835
  var DEFAULT_MAX_TIMEOUTS = 3;
1905
1836
  var DEFAULT_COOLDOWN_MS = 6e4;
1906
1837
  var CircuitBreaker = class {
@@ -1942,6 +1873,12 @@ var CircuitBreaker = class {
1942
1873
  }
1943
1874
  };
1944
1875
 
1876
+ // src/internal/llm/abort-error.ts
1877
+ function abortError(signal) {
1878
+ if (signal.reason instanceof Error) return signal.reason;
1879
+ return new Error(signal.reason !== void 0 ? String(signal.reason) : "aborted");
1880
+ }
1881
+
1945
1882
  // src/internal/llm/stream-relay.ts
1946
1883
  async function tryFirstEvent(client, request, signal, logFallback = false) {
1947
1884
  const generator = client.stream(request, signal);
@@ -1949,10 +1886,10 @@ async function tryFirstEvent(client, request, signal, logFallback = false) {
1949
1886
  const firstResult = await generator.next();
1950
1887
  return { kind: "ok", generator, firstResult };
1951
1888
  } catch (cause) {
1952
- if (cause instanceof chunk4ZHTIJNE_cjs.NetworkError || cause instanceof chunk4ZHTIJNE_cjs.RateLimitError || cause instanceof chunk4ZHTIJNE_cjs.AuthenticationError) {
1889
+ if (cause instanceof chunkJ7J7J2GN_cjs.NetworkError || cause instanceof chunkJ7J7J2GN_cjs.RateLimitError || cause instanceof chunkJ7J7J2GN_cjs.AuthenticationError) {
1953
1890
  if (logFallback) {
1954
1891
  const errCode = cause.metadata?.code ?? cause.code ?? "unknown";
1955
- chunkEG4QM7ZJ_cjs.diag(`[theokit-sdk] provider ${client.name} failed (${errCode}): falling back
1892
+ chunk6LHQPOMI_cjs.diag(`[theokit-sdk] provider ${client.name} failed (${errCode}): falling back
1956
1893
  `);
1957
1894
  }
1958
1895
  return { kind: "handshake_error", error: cause };
@@ -1994,7 +1931,7 @@ var PoolAwareLlmClient = class {
1994
1931
  // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: stream() must serialize pool-select → build client → first-event probe → classify → retry/rotate/propagate. Extracting helpers fragments the linear narrative; the comments above each branch keep it readable.
1995
1932
  async *stream(request, signal) {
1996
1933
  if (this.breaker.shouldSkip(this.pool.provider)) {
1997
- throw new chunk4ZHTIJNE_cjs.NetworkError(`${this.pool.provider} circuit open \u2014 failing fast`, {
1934
+ throw new chunkJ7J7J2GN_cjs.NetworkError(`${this.pool.provider} circuit open \u2014 failing fast`, {
1998
1935
  code: "circuit_open"
1999
1936
  });
2000
1937
  }
@@ -2013,7 +1950,7 @@ var PoolAwareLlmClient = class {
2013
1950
  }
2014
1951
  if (entry === null) {
2015
1952
  this.breaker.recordTimeout(this.pool.provider);
2016
- throw new chunk4ZHTIJNE_cjs.CredentialPoolExhaustedError(
1953
+ throw new chunkJ7J7J2GN_cjs.CredentialPoolExhaustedError(
2017
1954
  `All ${this.pool.provider} credentials exhausted; next retry available at ${this.nextRetryHint() ?? "unknown"}`,
2018
1955
  { provider: this.pool.provider, nextRetryAt: this.nextRetryHint() }
2019
1956
  );
@@ -2027,13 +1964,13 @@ var PoolAwareLlmClient = class {
2027
1964
  }
2028
1965
  const decision = classifyAndDecide(attempt.error, hasRetried429);
2029
1966
  if (decision === "retry") {
2030
- const backoffMs = chunkO7DK5PBJ_cjs.computeBackoffMs({
1967
+ const backoffMs = chunkQOGNZMHD_cjs.computeBackoffMs({
2031
1968
  attempt: 0,
2032
1969
  ...this.backoffBaseMs !== void 0 ? { baseMs: this.backoffBaseMs } : {},
2033
1970
  ...this.rng !== void 0 ? { rng: this.rng } : {}
2034
1971
  });
2035
1972
  this.onRateLimit?.({ attempt: 1, retryAfterMs: backoffMs });
2036
- await chunkO7DK5PBJ_cjs.sleepWithAbort(backoffMs, signal);
1973
+ await chunkQOGNZMHD_cjs.sleepWithAbort(backoffMs, signal);
2037
1974
  hasRetried429 = true;
2038
1975
  continue;
2039
1976
  }
@@ -2045,7 +1982,7 @@ var PoolAwareLlmClient = class {
2045
1982
  ...parseRetryAfterMs(attempt.error) !== void 0 ? { resetAtMs: parseRetryAfterMs(attempt.error) } : {}
2046
1983
  });
2047
1984
  } catch (persistErr) {
2048
- chunkEG4QM7ZJ_cjs.diag(
1985
+ chunk6LHQPOMI_cjs.diag(
2049
1986
  `[theokit-sdk] credential-pool: persist failed during rotate; continuing in-memory: ${persistErr instanceof Error ? persistErr.message : String(persistErr)}
2050
1987
  `
2051
1988
  );
@@ -2067,8 +2004,8 @@ var PoolAwareLlmClient = class {
2067
2004
  }
2068
2005
  };
2069
2006
  function classifyAndDecide(error, hasRetried429) {
2070
- if (error instanceof chunk4ZHTIJNE_cjs.NetworkError) return "propagate";
2071
- if (error instanceof chunk4ZHTIJNE_cjs.AuthenticationError) return "rotate";
2007
+ if (error instanceof chunkJ7J7J2GN_cjs.NetworkError) return "propagate";
2008
+ if (error instanceof chunkJ7J7J2GN_cjs.AuthenticationError) return "rotate";
2072
2009
  const status = error.metadata?.statusCode ?? 429;
2073
2010
  if (status === 402) return "rotate";
2074
2011
  return hasRetried429 ? "rotate" : "retry";
@@ -2081,14 +2018,10 @@ function parseRetryAfterMs(error) {
2081
2018
  return void 0;
2082
2019
  }
2083
2020
  function inferStatusCode(error) {
2084
- if (error instanceof chunk4ZHTIJNE_cjs.AuthenticationError) return 401;
2085
- if (error instanceof chunk4ZHTIJNE_cjs.RateLimitError) return 429;
2021
+ if (error instanceof chunkJ7J7J2GN_cjs.AuthenticationError) return 401;
2022
+ if (error instanceof chunkJ7J7J2GN_cjs.RateLimitError) return 429;
2086
2023
  return 0;
2087
2024
  }
2088
- function abortError(signal) {
2089
- if (signal.reason instanceof Error) return signal.reason;
2090
- return new Error("AbortError");
2091
- }
2092
2025
 
2093
2026
  // src/internal/llm/responses.ts
2094
2027
  function messageToInputItems(message, reasoningByCallId) {
@@ -2175,6 +2108,142 @@ function applyPromptCachingFields(body, request, options) {
2175
2108
  if (carryReasoning) body.include = ["reasoning.encrypted_content"];
2176
2109
  if (request.promptCacheKey !== void 0) body.prompt_cache_key = request.promptCacheKey;
2177
2110
  }
2111
+ var ResponsesStreamAccumulator = class {
2112
+ constructor(rememberReasoning) {
2113
+ this.rememberReasoning = rememberReasoning;
2114
+ }
2115
+ rememberReasoning;
2116
+ text = "";
2117
+ toolCalls = [];
2118
+ stopReason = "end_turn";
2119
+ inputTokens;
2120
+ outputTokens;
2121
+ reasoningTokens;
2122
+ cacheReadTokens;
2123
+ cacheWriteTokens;
2124
+ /** Function-call accumulation keyed by the streamed output-item id. */
2125
+ pending = {};
2126
+ /**
2127
+ * usetheokit/theokit-sdk#383 — reasoning items seen so far in THIS response and not yet claimed
2128
+ * by a tool call. Claimed (and cleared) when the next `function_call` completes, which is what
2129
+ * binds each batch to the call it produced.
2130
+ */
2131
+ unclaimedReasoning = [];
2132
+ /** The message of a terminal failure event, or `undefined` when this is not one. */
2133
+ static failureMessage(event) {
2134
+ if (event.type !== "response.failed" && event.type !== "error") return void 0;
2135
+ return event.response?.error?.message ?? event.message ?? "responses stream failed";
2136
+ }
2137
+ consume(event) {
2138
+ return this.applyDelta(event) ?? this.applyStructural(event) ?? [];
2139
+ }
2140
+ /** The three event kinds that produce an event for the consumer. */
2141
+ applyDelta(event) {
2142
+ const t = event.type;
2143
+ if (t === "response.output_text.delta") {
2144
+ const d = event.delta ?? "";
2145
+ if (d.length === 0) return [];
2146
+ this.text += d;
2147
+ return [{ type: "text_delta", text: d }];
2148
+ }
2149
+ if (t === "response.reasoning_summary_text.delta" || t === "response.reasoning_text.delta") {
2150
+ const d = event.delta ?? "";
2151
+ return d.length > 0 ? [{ type: "reasoning_delta", text: d }] : [];
2152
+ }
2153
+ return void 0;
2154
+ }
2155
+ /** The event kinds that only move accumulator state. Routing only — each arm is its own method. */
2156
+ applyStructural(event) {
2157
+ const t = event.type;
2158
+ if (t === "response.output_item.added" || t === "response.output_item.done") {
2159
+ this.applyOutputItem(t, event);
2160
+ return [];
2161
+ }
2162
+ if (t === "response.function_call_arguments.delta") {
2163
+ this.appendArguments(event);
2164
+ return [];
2165
+ }
2166
+ if (t === "response.completed" || t === "response.incomplete") {
2167
+ this.applyTerminal(t, event);
2168
+ return [];
2169
+ }
2170
+ return void 0;
2171
+ }
2172
+ appendArguments(event) {
2173
+ const c = event.item_id !== void 0 ? this.pending[event.item_id] : void 0;
2174
+ if (c !== void 0) c.args += event.delta ?? "";
2175
+ }
2176
+ applyTerminal(t, event) {
2177
+ this.applyUsage(event.response?.usage);
2178
+ this.stopReason = t === "response.incomplete" ? "max_tokens" : "end_turn";
2179
+ }
2180
+ finish() {
2181
+ const stopReason = this.toolCalls.length > 0 && this.stopReason === "end_turn" ? "tool_use" : this.stopReason;
2182
+ return makeLlmFinish({
2183
+ stopReason,
2184
+ text: this.text,
2185
+ toolCalls: this.toolCalls,
2186
+ inputTokens: this.inputTokens,
2187
+ outputTokens: this.outputTokens,
2188
+ reasoningTokens: this.reasoningTokens,
2189
+ cacheReadTokens: this.cacheReadTokens,
2190
+ cacheWriteTokens: this.cacheWriteTokens
2191
+ });
2192
+ }
2193
+ applyOutputItem(t, event) {
2194
+ const item = event.item;
2195
+ if (item === void 0) return;
2196
+ if (t === "response.output_item.added") {
2197
+ if (item.type === "function_call") this.beginFunctionCall(item);
2198
+ return;
2199
+ }
2200
+ if (item.type === "reasoning") this.applyReasoningItem(item);
2201
+ else if (item.type === "function_call") this.applyFunctionCallDone(item);
2202
+ }
2203
+ beginFunctionCall(item) {
2204
+ const id = item.id ?? item.call_id ?? "call-0";
2205
+ this.pending[id] = {
2206
+ callId: item.call_id ?? id,
2207
+ name: item.name ?? "",
2208
+ args: item.arguments ?? ""
2209
+ };
2210
+ }
2211
+ applyReasoningItem(item) {
2212
+ const id = item.id;
2213
+ const encrypted = item.encrypted_content;
2214
+ if (id !== void 0 && encrypted !== void 0 && encrypted.length > 0) {
2215
+ this.unclaimedReasoning.push({ id, encrypted_content: encrypted });
2216
+ }
2217
+ }
2218
+ applyFunctionCallDone(item) {
2219
+ const id = item.id ?? item.call_id ?? "call-0";
2220
+ const c = this.pending[id] ?? {
2221
+ callId: item.call_id ?? id,
2222
+ name: item.name ?? "",
2223
+ args: item.arguments ?? ""
2224
+ };
2225
+ const call = {
2226
+ type: "tool_use",
2227
+ id: c.callId,
2228
+ name: c.name.length > 0 ? c.name : item.name ?? "",
2229
+ input: parseToolArguments(item.arguments ?? c.args)
2230
+ };
2231
+ this.toolCalls.push(call);
2232
+ if (this.unclaimedReasoning.length > 0) {
2233
+ this.rememberReasoning(call.id, this.unclaimedReasoning);
2234
+ this.unclaimedReasoning = [];
2235
+ }
2236
+ delete this.pending[id];
2237
+ }
2238
+ applyUsage(usage) {
2239
+ if (usage === void 0) return;
2240
+ this.inputTokens = usage.input_tokens;
2241
+ this.outputTokens = usage.output_tokens;
2242
+ this.reasoningTokens = usage.output_tokens_details?.reasoning_tokens;
2243
+ this.cacheReadTokens = usage.input_tokens_details?.cached_tokens;
2244
+ this.cacheWriteTokens = usage.input_tokens_details?.cache_write_tokens;
2245
+ }
2246
+ };
2178
2247
  var MAX_REMEMBERED_REASONING_CALLS = 256;
2179
2248
  var ResponsesApiClient = class {
2180
2249
  constructor(options) {
@@ -2207,20 +2276,17 @@ var ResponsesApiClient = class {
2207
2276
  this.reasoningByCallId.delete(oldest.value);
2208
2277
  }
2209
2278
  }
2210
- // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: the SSE dispatch (text / reasoning / tool-call add+delta+done / terminal+usage / error) is one cohesive state machine, mirroring OpenAIStreamAccumulator.consume.
2211
- async *stream(request, signal) {
2212
- const providerId = this.options.providerName ?? "openai";
2213
- const headers = {
2214
- "content-type": "application/json",
2215
- accept: "text/event-stream",
2216
- authorization: `Bearer ${this.options.apiKey}`,
2217
- ...this.options.extraHeaders ?? {}
2218
- };
2219
- const url = `${this.baseUrl}/responses`;
2220
- const response = await this.fetchImpl(url, {
2279
+ /** Issues the streaming request. Separated so `stream()` reads as fetch check consume. */
2280
+ async post(request, signal) {
2281
+ return await this.fetchImpl(`${this.baseUrl}/responses`, {
2221
2282
  method: "POST",
2222
2283
  signal,
2223
- headers,
2284
+ headers: {
2285
+ "content-type": "application/json",
2286
+ accept: "text/event-stream",
2287
+ authorization: `Bearer ${this.options.apiKey}`,
2288
+ ...this.options.extraHeaders ?? {}
2289
+ },
2224
2290
  body: JSON.stringify(
2225
2291
  // Both options ride the SAME flag on purpose: a provider that never declared support gets
2226
2292
  // the byte-identical pre-#383 body, even in the impossible case where it returned ciphertext
@@ -2231,140 +2297,78 @@ var ResponsesApiClient = class {
2231
2297
  )
2232
2298
  )
2233
2299
  });
2234
- if (!response.ok) {
2235
- const text2 = await response.text().catch(() => "");
2236
- let body = text2;
2300
+ }
2301
+ /** Maps a non-2xx response to a typed error. Returns it rather than throwing, so the caller's
2302
+ * control flow stays visible at the call site. */
2303
+ async errorFor(response, providerId) {
2304
+ const text = await response.text().catch(() => "");
2305
+ let body = text;
2306
+ try {
2307
+ body = JSON.parse(text);
2308
+ } catch {
2309
+ }
2310
+ return chunk24SYBZPL_cjs.mapOpenAICompatibleError({
2311
+ providerId,
2312
+ status: response.status,
2313
+ body,
2314
+ headers: response.headers,
2315
+ endpoint: "/responses"
2316
+ });
2317
+ }
2318
+ /**
2319
+ * SSE frames → parsed events, stopping at `[DONE]`. A frame that is not JSON is skipped rather
2320
+ * than fatal: a provider that emits a keep-alive or a comment frame must not end the response.
2321
+ */
2322
+ async *decode(body, signal) {
2323
+ for await (const record of parseSseStream(body, signal)) {
2324
+ if (record.data === "[DONE]") return;
2325
+ let event;
2237
2326
  try {
2238
- body = JSON.parse(text2);
2327
+ event = JSON.parse(record.data);
2239
2328
  } catch {
2329
+ continue;
2240
2330
  }
2241
- throw chunkUGT7GK7I_cjs.mapOpenAICompatibleError({
2242
- providerId,
2243
- status: response.status,
2244
- body,
2245
- headers: response.headers,
2246
- endpoint: "/responses"
2247
- });
2331
+ yield event;
2248
2332
  }
2249
- let text = "";
2250
- const toolCalls = [];
2251
- let stopReason = "end_turn";
2252
- let inputTokens;
2253
- let outputTokens;
2254
- let reasoningTokens;
2255
- let cacheReadTokens;
2256
- let cacheWriteTokens;
2257
- const pending = {};
2258
- let unclaimedReasoning = [];
2333
+ }
2334
+ async *stream(request, signal) {
2335
+ const providerId = this.options.providerName ?? "openai";
2336
+ const response = await this.post(request, signal);
2337
+ if (!response.ok) throw await this.errorFor(response, providerId);
2338
+ const acc = new ResponsesStreamAccumulator(
2339
+ (callId, items) => this.rememberReasoning(callId, items)
2340
+ );
2259
2341
  if (response.body !== null) {
2260
- for await (const record of parseSseStream(response.body, signal)) {
2261
- if (record.data === "[DONE]") break;
2262
- let event;
2263
- try {
2264
- event = JSON.parse(record.data);
2265
- } catch {
2266
- continue;
2267
- }
2268
- const t = event.type;
2269
- if (t === "response.output_text.delta") {
2270
- const d = event.delta ?? "";
2271
- if (d.length > 0) {
2272
- text += d;
2273
- yield { type: "text_delta", text: d };
2274
- }
2275
- } else if (t === "response.reasoning_summary_text.delta" || t === "response.reasoning_text.delta") {
2276
- const d = event.delta ?? "";
2277
- if (d.length > 0) yield { type: "reasoning_delta", text: d };
2278
- } else if (t === "response.output_item.done" && event.item?.type === "reasoning") {
2279
- const id = event.item.id;
2280
- const encrypted = event.item.encrypted_content;
2281
- if (id !== void 0 && encrypted !== void 0 && encrypted.length > 0) {
2282
- unclaimedReasoning.push({ id, encrypted_content: encrypted });
2283
- }
2284
- } else if (t === "response.output_item.added" && event.item?.type === "function_call") {
2285
- const id = event.item.id ?? event.item.call_id ?? "call-0";
2286
- pending[id] = {
2287
- callId: event.item.call_id ?? id,
2288
- name: event.item.name ?? "",
2289
- args: event.item.arguments ?? ""
2290
- };
2291
- } else if (t === "response.function_call_arguments.delta") {
2292
- const c = event.item_id !== void 0 ? pending[event.item_id] : void 0;
2293
- if (c !== void 0) c.args += event.delta ?? "";
2294
- } else if (t === "response.output_item.done" && event.item?.type === "function_call") {
2295
- const id = event.item.id ?? event.item.call_id ?? "call-0";
2296
- const c = pending[id] ?? {
2297
- callId: event.item.call_id ?? id,
2298
- name: event.item.name ?? "",
2299
- args: event.item.arguments ?? ""
2300
- };
2301
- const rawArgs = event.item.arguments ?? c.args;
2302
- const call = {
2303
- type: "tool_use",
2304
- id: c.callId,
2305
- name: c.name.length > 0 ? c.name : event.item.name ?? "",
2306
- input: parseToolArguments(rawArgs)
2307
- };
2308
- toolCalls.push(call);
2309
- if (unclaimedReasoning.length > 0) {
2310
- this.rememberReasoning(call.id, unclaimedReasoning);
2311
- unclaimedReasoning = [];
2312
- }
2313
- delete pending[id];
2314
- } else if (t === "response.completed" || t === "response.incomplete") {
2315
- const usage = event.response?.usage;
2316
- if (usage !== void 0) {
2317
- inputTokens = usage.input_tokens;
2318
- outputTokens = usage.output_tokens;
2319
- reasoningTokens = usage.output_tokens_details?.reasoning_tokens;
2320
- cacheReadTokens = usage.input_tokens_details?.cached_tokens;
2321
- cacheWriteTokens = usage.input_tokens_details?.cache_write_tokens;
2322
- }
2323
- stopReason = t === "response.incomplete" ? "max_tokens" : "end_turn";
2324
- } else if (t === "response.failed" || t === "error") {
2325
- const msg = event.response?.error?.message ?? event.message ?? "responses stream failed";
2326
- yield { type: "error", message: msg };
2327
- throw chunkUGT7GK7I_cjs.mapOpenAICompatibleError({
2342
+ for await (const event of this.decode(response.body, signal)) {
2343
+ const failure = ResponsesStreamAccumulator.failureMessage(event);
2344
+ if (failure !== void 0) {
2345
+ yield { type: "error", message: failure };
2346
+ throw chunk24SYBZPL_cjs.mapOpenAICompatibleError({
2328
2347
  providerId,
2329
2348
  status: 502,
2330
- body: { error: { message: msg } },
2349
+ body: { error: { message: failure } },
2331
2350
  headers: response.headers,
2332
2351
  endpoint: "/responses"
2333
2352
  });
2334
2353
  }
2354
+ yield* acc.consume(event);
2335
2355
  }
2336
2356
  }
2337
- if (toolCalls.length > 0 && stopReason === "end_turn") stopReason = "tool_use";
2338
- return makeLlmFinish({
2339
- stopReason,
2340
- text,
2341
- toolCalls,
2342
- inputTokens,
2343
- outputTokens,
2344
- reasoningTokens,
2345
- cacheReadTokens,
2346
- cacheWriteTokens
2347
- });
2357
+ return acc.finish();
2348
2358
  }
2349
2359
  };
2350
2360
 
2351
- // src/internal/llm/abort-error.ts
2352
- function abortError2(signal) {
2353
- if (signal.reason instanceof Error) return signal.reason;
2354
- return new Error(signal.reason !== void 0 ? String(signal.reason) : "aborted");
2355
- }
2356
-
2357
2361
  // src/internal/llm/retrying-client.ts
2358
2362
  var MAX_ATTEMPTS = 3;
2359
2363
  function isRetriableError(err) {
2360
- if (!chunk4ZHTIJNE_cjs.isTransientError(err)) return false;
2361
- if (err instanceof chunk4ZHTIJNE_cjs.CredentialPoolExhaustedError) return false;
2362
- if (err instanceof chunk4ZHTIJNE_cjs.TheokitAgentError && err.code === "circuit_open") return false;
2363
- if (err instanceof chunk4ZHTIJNE_cjs.RateLimitError && err.metadata?.statusCode === 402) return false;
2364
+ if (!chunkJ7J7J2GN_cjs.isTransientError(err)) return false;
2365
+ if (err instanceof chunkJ7J7J2GN_cjs.CredentialPoolExhaustedError) return false;
2366
+ if (err instanceof chunkJ7J7J2GN_cjs.TheokitAgentError && err.code === "circuit_open") return false;
2367
+ if (err instanceof chunkJ7J7J2GN_cjs.RateLimitError && err.metadata?.statusCode === 402) return false;
2364
2368
  return true;
2365
2369
  }
2366
2370
  function retryAfterHintMs(err) {
2367
- if (!(err instanceof chunk4ZHTIJNE_cjs.RateLimitError)) return void 0;
2371
+ if (!(err instanceof chunkJ7J7J2GN_cjs.RateLimitError)) return void 0;
2368
2372
  const seconds = err.metadata?.retryAfter;
2369
2373
  return typeof seconds === "number" && seconds > 0 ? seconds * 1e3 : void 0;
2370
2374
  }
@@ -2410,21 +2414,21 @@ var RetryingLlmClient = class {
2410
2414
  */
2411
2415
  async #waitBackoff(err, attempt, signal) {
2412
2416
  const hint = retryAfterHintMs(err);
2413
- const ms = chunkO7DK5PBJ_cjs.computeBackoffMs({
2417
+ const ms = chunkQOGNZMHD_cjs.computeBackoffMs({
2414
2418
  attempt,
2415
2419
  ...hint !== void 0 ? { retryAfterMs: hint } : {},
2416
2420
  ...this.#rng !== void 0 ? { rng: this.#rng } : {}
2417
2421
  });
2418
2422
  const cause = err instanceof Error ? err.name : typeof err;
2419
- chunkEG4QM7ZJ_cjs.diag(
2423
+ chunk6LHQPOMI_cjs.diag(
2420
2424
  `retry ${attempt + 1}/${MAX_ATTEMPTS} in ${String(ms)}ms \u2014 ${cause}` + (hint !== void 0 ? ` (Retry-After: ${String(hint)}ms)` : "")
2421
2425
  );
2422
- await chunkO7DK5PBJ_cjs.sleepWithAbort(ms, signal);
2426
+ await chunkQOGNZMHD_cjs.sleepWithAbort(ms, signal);
2423
2427
  }
2424
2428
  async *stream(request, signal) {
2425
2429
  let lastError;
2426
2430
  for (let attempt = 0; attempt < MAX_ATTEMPTS; attempt++) {
2427
- if (signal.aborted) throw lastError ?? abortError2(signal);
2431
+ if (signal.aborted) throw lastError ?? abortError(signal);
2428
2432
  const state = { emitted: false };
2429
2433
  try {
2430
2434
  return yield* consume(this.#inner.stream(request, signal), state);
@@ -2447,17 +2451,17 @@ var VERTEX_RULES = [
2447
2451
  test: (s, e) => s === 400 || e === "INVALID_ARGUMENT" || e === "FAILED_PRECONDITION" || e === "NOT_FOUND",
2448
2452
  code: "invalid_request"
2449
2453
  },
2450
- { test: (s, e) => s === 408 || e === "DEADLINE_EXCEEDED", code: "timeout" },
2451
- { test: (s) => s >= 500, code: "server_error" }
2454
+ { test: (s, e) => s === 408 || e === "DEADLINE_EXCEEDED", code: "timeout" }
2452
2455
  ];
2453
2456
  function classifyVertexError(args, errStatus) {
2454
2457
  for (const rule of VERTEX_RULES) {
2455
2458
  if (rule.test(args.status, errStatus)) return rule.code;
2456
2459
  }
2457
- return "unknown";
2460
+ const shared = chunk24SYBZPL_cjs.httpStatusToErrorCode(args.status);
2461
+ return shared === "auth_failed" ? "auth_permission" : shared;
2458
2462
  }
2459
2463
  function vertexMetadata(args, code) {
2460
- return chunkUGT7GK7I_cjs.buildErrorMetadata({
2464
+ return chunk24SYBZPL_cjs.buildErrorMetadata({
2461
2465
  provider: "vertex",
2462
2466
  endpoint: args.endpoint,
2463
2467
  code,
@@ -2467,42 +2471,34 @@ function vertexMetadata(args, code) {
2467
2471
  });
2468
2472
  }
2469
2473
  var VERTEX_ERROR_BUILDERS = {
2470
- rate_limit: (args, msg) => new chunk4ZHTIJNE_cjs.RateLimitError(`Vertex quota exhausted: ${msg}`, {
2474
+ rate_limit: (args, msg) => new chunkJ7J7J2GN_cjs.RateLimitError(`Vertex quota exhausted: ${msg}`, {
2471
2475
  metadata: vertexMetadata(args, "rate_limit")
2472
2476
  }),
2473
- auth_unauthenticated: (args, msg) => new chunk4ZHTIJNE_cjs.AuthenticationError(`Vertex unauthenticated: ${msg}`, {
2477
+ auth_unauthenticated: (args, msg) => new chunkJ7J7J2GN_cjs.AuthenticationError(`Vertex unauthenticated: ${msg}`, {
2474
2478
  metadata: vertexMetadata(args, "auth_failed")
2475
2479
  }),
2476
- auth_permission: (args, msg) => new chunk4ZHTIJNE_cjs.AuthenticationError(`Vertex permission denied: ${msg}`, {
2480
+ auth_permission: (args, msg) => new chunkJ7J7J2GN_cjs.AuthenticationError(`Vertex permission denied: ${msg}`, {
2477
2481
  metadata: vertexMetadata(args, "auth_failed")
2478
2482
  }),
2479
- invalid_request: (args, msg) => new chunk4ZHTIJNE_cjs.ConfigurationError(`Vertex validation: ${msg}`, {
2483
+ invalid_request: (args, msg) => new chunkJ7J7J2GN_cjs.ConfigurationError(`Vertex validation: ${msg}`, {
2480
2484
  metadata: vertexMetadata(args, "invalid_request")
2481
2485
  }),
2482
- timeout: (args, msg) => new chunk4ZHTIJNE_cjs.NetworkError(`Vertex timeout: ${msg}`, { metadata: vertexMetadata(args, "timeout") }),
2483
- server_error: (args, msg) => new chunk4ZHTIJNE_cjs.NetworkError(`Vertex server error: ${msg}`, {
2486
+ quota_exceeded: (args, msg) => new chunkJ7J7J2GN_cjs.RateLimitError(`Vertex quota exceeded: ${msg}`, {
2487
+ metadata: vertexMetadata(args, "quota_exceeded")
2488
+ }),
2489
+ timeout: (args, msg) => new chunkJ7J7J2GN_cjs.NetworkError(`Vertex timeout: ${msg}`, { metadata: vertexMetadata(args, "timeout") }),
2490
+ server_error: (args, msg) => new chunkJ7J7J2GN_cjs.NetworkError(`Vertex server error: ${msg}`, {
2484
2491
  metadata: vertexMetadata(args, "server_error")
2485
2492
  }),
2486
- unknown: (args, msg) => new chunk4ZHTIJNE_cjs.UnknownAgentError(`Vertex unknown: ${msg}`, { metadata: vertexMetadata(args, "unknown") })
2493
+ unknown: (args, msg) => new chunkJ7J7J2GN_cjs.UnknownAgentError(`Vertex unknown: ${msg}`, { metadata: vertexMetadata(args, "unknown") })
2487
2494
  };
2488
2495
  function mapVertexError(args) {
2489
- const parsed = parseBody2(args.body);
2496
+ const parsed = chunk24SYBZPL_cjs.parseErrorBody(args.body);
2490
2497
  const errStatus = parsed.error?.status ?? "";
2491
2498
  const message = parsed.error?.message ?? "Vertex request failed";
2492
2499
  const code = classifyVertexError(args, errStatus);
2493
2500
  return VERTEX_ERROR_BUILDERS[code](args, message);
2494
2501
  }
2495
- function parseBody2(body) {
2496
- if (body !== null && typeof body === "object") return body;
2497
- if (typeof body === "string") {
2498
- try {
2499
- return JSON.parse(body);
2500
- } catch {
2501
- return {};
2502
- }
2503
- }
2504
- return {};
2505
- }
2506
2502
  var cachedAuthClient;
2507
2503
  var SCOPE_CLOUD_PLATFORM = "https://www.googleapis.com/auth/cloud-platform";
2508
2504
  async function resolveVertexAccessToken() {
@@ -2519,12 +2515,12 @@ async function resolveVertexAccessToken() {
2519
2515
  async function getAuthClientOrThrow() {
2520
2516
  let mod;
2521
2517
  try {
2522
- const r = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-KYAJINUI.cjs', document.baseURI).href)));
2518
+ const r = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-2HPNT6HH.cjs', document.baseURI).href)));
2523
2519
  mod = r("google-auth-library");
2524
2520
  } catch (err) {
2525
2521
  const isModuleMissing = err instanceof Error && (err.message.includes("Cannot find module") || err.code === "MODULE_NOT_FOUND");
2526
2522
  if (isModuleMissing) {
2527
- throw new chunk4ZHTIJNE_cjs.ConfigurationError(
2523
+ throw new chunkJ7J7J2GN_cjs.ConfigurationError(
2528
2524
  "Vertex provider requires `google-auth-library`. Install: `pnpm add google-auth-library`.",
2529
2525
  { code: "auth_failed", cause: err }
2530
2526
  );
@@ -2535,7 +2531,7 @@ async function getAuthClientOrThrow() {
2535
2531
  const auth = new mod.GoogleAuth({ scopes: [SCOPE_CLOUD_PLATFORM] });
2536
2532
  return await auth.getClient();
2537
2533
  } catch (err) {
2538
- chunkEG4QM7ZJ_cjs.diag(
2534
+ chunk6LHQPOMI_cjs.diag(
2539
2535
  `[theokit-sdk] Vertex ADC initialization failed: ${err instanceof Error ? err.message : String(err)}
2540
2536
  `
2541
2537
  );
@@ -2561,7 +2557,7 @@ var VertexAnthropicClient = class {
2561
2557
  resolveProjectOrThrow() {
2562
2558
  const projectId = this.options.projectId ?? resolveVertexProjectId();
2563
2559
  if (projectId !== void 0) return projectId;
2564
- throw new chunk4ZHTIJNE_cjs.ConfigurationError(
2560
+ throw new chunkJ7J7J2GN_cjs.ConfigurationError(
2565
2561
  "Vertex requires a project id. Set GOOGLE_CLOUD_PROJECT env var or run `gcloud config set project <id>`.",
2566
2562
  { code: "auth_failed" }
2567
2563
  );
@@ -2571,7 +2567,7 @@ var VertexAnthropicClient = class {
2571
2567
  if (fromOpts !== void 0 && fromOpts.length > 0) return fromOpts;
2572
2568
  const fromAdc = await resolveVertexAccessToken();
2573
2569
  if (fromAdc !== void 0 && fromAdc.length > 0) return fromAdc;
2574
- throw new chunk4ZHTIJNE_cjs.ConfigurationError(
2570
+ throw new chunkJ7J7J2GN_cjs.ConfigurationError(
2575
2571
  "Vertex could not resolve an access token. Run `gcloud auth application-default login` or set GOOGLE_APPLICATION_CREDENTIALS to a service-account JSON path.",
2576
2572
  { code: "auth_failed" }
2577
2573
  );
@@ -2580,8 +2576,8 @@ var VertexAnthropicClient = class {
2580
2576
  const projectId = this.resolveProjectOrThrow();
2581
2577
  const location = this.options.location ?? resolveVertexLocation();
2582
2578
  const accessToken = await this.resolveTokenOrThrow();
2583
- const baseUrl = chunkHCZD23VS_cjs.resolveVertexBaseUrl({ projectId, location, modelDialect: "anthropic" });
2584
- const bareModel = chunkHCZD23VS_cjs.stripVertexPrefix(request.model);
2579
+ const baseUrl = chunkQC55H6RJ_cjs.resolveVertexBaseUrl({ projectId, location, modelDialect: "anthropic" });
2580
+ const bareModel = chunkQC55H6RJ_cjs.stripVertexPrefix(request.model);
2585
2581
  const endpoint = `/models/${encodeURIComponent(bareModel)}:rawPredict`;
2586
2582
  const url = `${baseUrl}${endpoint}`;
2587
2583
  const response = await postAnthropicRequest({
@@ -2617,7 +2613,7 @@ var VertexGeminiClient = class {
2617
2613
  async *stream(request, signal) {
2618
2614
  const projectId = this.options.projectId ?? resolveVertexProjectId();
2619
2615
  if (projectId === void 0) {
2620
- throw new chunk4ZHTIJNE_cjs.ConfigurationError(
2616
+ throw new chunkJ7J7J2GN_cjs.ConfigurationError(
2621
2617
  "Vertex requires a project id. Set GOOGLE_CLOUD_PROJECT env var or run `gcloud config set project <id>`.",
2622
2618
  { code: "auth_failed" }
2623
2619
  );
@@ -2625,12 +2621,12 @@ var VertexGeminiClient = class {
2625
2621
  const location = this.options.location ?? resolveVertexLocation();
2626
2622
  const accessToken = this.options.apiKey !== void 0 && this.options.apiKey.length > 0 ? this.options.apiKey : await resolveVertexAccessToken();
2627
2623
  if (accessToken === void 0 || accessToken.length === 0) {
2628
- throw new chunk4ZHTIJNE_cjs.ConfigurationError(
2624
+ throw new chunkJ7J7J2GN_cjs.ConfigurationError(
2629
2625
  "Vertex could not resolve an access token. Run `gcloud auth application-default login` or set GOOGLE_APPLICATION_CREDENTIALS to a service-account JSON path.",
2630
2626
  { code: "auth_failed" }
2631
2627
  );
2632
2628
  }
2633
- const baseUrl = chunkHCZD23VS_cjs.resolveVertexBaseUrl({ projectId, location, modelDialect: "gemini" });
2629
+ const baseUrl = chunkQC55H6RJ_cjs.resolveVertexBaseUrl({ projectId, location, modelDialect: "gemini" });
2634
2630
  const url = `${baseUrl}/chat/completions`;
2635
2631
  const innerFetch = this.options.fetch ?? fetch;
2636
2632
  const rewriteFetch = (_input, init) => innerFetch(url, init);
@@ -2652,7 +2648,7 @@ var VertexRouterClient = class {
2652
2648
  options;
2653
2649
  name = "vertex";
2654
2650
  async *stream(request, signal) {
2655
- const dialect = chunkHCZD23VS_cjs.inferModelDialect(request.model);
2651
+ const dialect = chunkQC55H6RJ_cjs.inferModelDialect(request.model);
2656
2652
  if (dialect === "anthropic") {
2657
2653
  const inner2 = new VertexAnthropicClient(this.options);
2658
2654
  return yield* inner2.stream(request, signal);
@@ -2664,7 +2660,7 @@ var VertexRouterClient = class {
2664
2660
 
2665
2661
  // src/internal/llm/router.ts
2666
2662
  function resolveProviderChain(options) {
2667
- chunkHCZD23VS_cjs.registerBuiltins();
2663
+ chunkQC55H6RJ_cjs.registerBuiltins();
2668
2664
  return buildChain(options);
2669
2665
  }
2670
2666
  function buildChain(options) {
@@ -2681,27 +2677,25 @@ function buildChain(options) {
2681
2677
  addClient(options.primary, options.baseUrl);
2682
2678
  for (const fallback of options.fallback ?? []) addClient(fallback);
2683
2679
  if (clients.length === 0) {
2684
- throw new chunk4ZHTIJNE_cjs.ConfigurationError(
2680
+ throw new chunkJ7J7J2GN_cjs.ConfigurationError(
2685
2681
  `No provider client could be resolved (primary=${options.primary}). Set ANTHROPIC_API_KEY or OPENAI_API_KEY / OPENROUTER_API_KEY.`,
2686
2682
  { code: "provider_unresolved" }
2687
2683
  );
2688
2684
  }
2689
2685
  return clients;
2690
2686
  }
2691
- function buildClient(name, routerOptions, perCallBaseUrl) {
2692
- const baseProfile = chunkHCZD23VS_cjs.getProviderProfile(name);
2687
+ function buildTransport(name, routerOptions, perCallBaseUrl) {
2688
+ const baseProfile = chunkQC55H6RJ_cjs.getProviderProfile(name);
2693
2689
  if (baseProfile === void 0) return void 0;
2694
2690
  const profile = routerOptions.extractToolCallsFromContent === true && baseProfile.extractToolCallsFromContent !== true ? { ...baseProfile, extractToolCallsFromContent: true } : baseProfile;
2695
2691
  const resilience = routerOptions.onRateLimit !== void 0 ? { onRateLimit: routerOptions.onRateLimit } : {};
2696
- const ambient = chunkO7DK5PBJ_cjs.currentCredentialPool(name);
2692
+ const ambient = chunkFUSDYC2B_cjs.currentCredentialPool(name);
2697
2693
  if (ambient !== void 0) {
2698
- return new RetryingLlmClient(
2699
- new PoolAwareLlmClient(
2700
- ambient,
2701
- (apiKey) => selectTransport(profile, apiKey, perCallBaseUrl),
2702
- void 0,
2703
- resilience
2704
- )
2694
+ return new PoolAwareLlmClient(
2695
+ ambient,
2696
+ (apiKey) => selectTransport(profile, apiKey, perCallBaseUrl),
2697
+ void 0,
2698
+ resilience
2705
2699
  );
2706
2700
  }
2707
2701
  const poolKeys = filterPoolKeys(routerOptions.apiKeys?.[name]);
@@ -2709,6 +2703,10 @@ function buildClient(name, routerOptions, perCallBaseUrl) {
2709
2703
  if (noAuthOverride !== void 0) return noAuthOverride;
2710
2704
  return buildPoolOrSingle({ name, profile, poolKeys, routerOptions, perCallBaseUrl });
2711
2705
  }
2706
+ function buildClient(name, routerOptions, perCallBaseUrl) {
2707
+ const transport = buildTransport(name, routerOptions, perCallBaseUrl);
2708
+ return transport === void 0 ? void 0 : new RetryingLlmClient(transport);
2709
+ }
2712
2710
  function maybeBuildNoAuthTransport(profile, poolKeys, baseUrl) {
2713
2711
  if (profile.authType !== "none" || poolKeys === void 0 || poolKeys.length === 0) {
2714
2712
  return void 0;
@@ -2723,22 +2721,20 @@ function buildPoolOrSingle(args) {
2723
2721
  if (poolKeys !== void 0 && poolKeys.length >= 2) {
2724
2722
  const strategy = routerOptions.credentialPoolStrategy?.[name] ?? "fill_first";
2725
2723
  const entries = poolKeys.map(
2726
- (accessToken, priority) => chunkO7DK5PBJ_cjs.newPooledCredential({ provider: name, accessToken, priority, source: "manual" })
2724
+ (accessToken, priority) => chunkFUSDYC2B_cjs.newPooledCredential({ provider: name, accessToken, priority, source: "manual" })
2727
2725
  );
2728
- const pool = new chunkO7DK5PBJ_cjs.CredentialPool(name, entries, strategy);
2726
+ const pool = new chunkFUSDYC2B_cjs.CredentialPool(name, entries, strategy);
2729
2727
  const resilience = routerOptions.onRateLimit !== void 0 ? { onRateLimit: routerOptions.onRateLimit } : {};
2730
- return new RetryingLlmClient(
2731
- new PoolAwareLlmClient(
2732
- pool,
2733
- (apiKey2) => selectTransport(profile, apiKey2, perCallBaseUrl),
2734
- void 0,
2735
- resilience
2736
- )
2728
+ return new PoolAwareLlmClient(
2729
+ pool,
2730
+ (apiKey2) => selectTransport(profile, apiKey2, perCallBaseUrl),
2731
+ void 0,
2732
+ resilience
2737
2733
  );
2738
2734
  }
2739
2735
  const apiKey = poolKeys?.[0] ?? resolveApiKey(profile.envVars) ?? sentinelForNoAuth(profile) ?? sentinelForLazyAuth(profile);
2740
2736
  if (apiKey === void 0) return void 0;
2741
- return new RetryingLlmClient(selectTransport(profile, apiKey, perCallBaseUrl));
2737
+ return selectTransport(profile, apiKey, perCallBaseUrl);
2742
2738
  }
2743
2739
  function resolveBaseUrlEnvOverride(providerName) {
2744
2740
  switch (providerName) {
@@ -2758,7 +2754,7 @@ var warnedNoAuthApiKeys = /* @__PURE__ */ new Set();
2758
2754
  function warnNoAuthApiKeysIgnoredOnce(provider) {
2759
2755
  if (warnedNoAuthApiKeys.has(provider)) return;
2760
2756
  warnedNoAuthApiKeys.add(provider);
2761
- chunkEG4QM7ZJ_cjs.diag(
2757
+ chunk6LHQPOMI_cjs.diag(
2762
2758
  `[theokit-sdk] provider "${provider}" has authType: "none" \u2014 apiKeys ignored (no auth required for local runtime).
2763
2759
  `
2764
2760
  );
@@ -2784,10 +2780,10 @@ function warnUnknownProvidersInApiKeys(apiKeys) {
2784
2780
  if (apiKeys === void 0) return;
2785
2781
  for (const name of Object.keys(apiKeys)) {
2786
2782
  if (warnedProviders.has(name)) continue;
2787
- const profile = chunkHCZD23VS_cjs.getProviderProfile(name);
2783
+ const profile = chunkQC55H6RJ_cjs.getProviderProfile(name);
2788
2784
  if (profile === void 0) {
2789
2785
  warnedProviders.add(name);
2790
- chunkEG4QM7ZJ_cjs.diag(
2786
+ chunk6LHQPOMI_cjs.diag(
2791
2787
  `[theokit-sdk] credential-pool: unknown provider "${name}" in apiKeys (no profile registered)
2792
2788
  `
2793
2789
  );
@@ -2807,7 +2803,7 @@ function selectTransport(profile, apiKey, baseUrl) {
2807
2803
  const ctx = { apiKey };
2808
2804
  return { fetch: profile.transform.fetch?.(ctx), headers: profile.transform.headers?.(ctx) };
2809
2805
  };
2810
- const comTransform = (opts, construct) => {
2806
+ const withTransform = (opts, construct) => {
2811
2807
  const t = applyTransform();
2812
2808
  assertOAuthResolved(t);
2813
2809
  if (t.fetch !== void 0) opts.fetch = t.fetch;
@@ -2819,7 +2815,7 @@ function selectTransport(profile, apiKey, baseUrl) {
2819
2815
  if (apiKey !== "__oauth_lazy_token__") return;
2820
2816
  const auth = t.headers?.authorization ?? t.headers?.Authorization;
2821
2817
  if (t.fetch === void 0 && auth === void 0) {
2822
- throw new chunk4ZHTIJNE_cjs.ConfigurationError(
2818
+ throw new chunkJ7J7J2GN_cjs.ConfigurationError(
2823
2819
  `provider "${profile.name}" uses OAuth (authType: ${profile.authType}) but no credential was resolved. Register a ProviderProfile.transform whose fetch (or headers.authorization) supplies the bearer \u2014 typically via resolveCredential() from "@theokit/sdk/auth".`
2824
2820
  );
2825
2821
  }
@@ -2844,7 +2840,7 @@ function selectTransport(profile, apiKey, baseUrl) {
2844
2840
  const envOverride = resolveBaseUrlEnvOverride(profile.name);
2845
2841
  if (envOverride !== void 0) opts.baseUrl = envOverride;
2846
2842
  if (baseUrl !== void 0) opts.baseUrl = baseUrl;
2847
- return comTransform(opts, (o) => new OpenAIClient(o));
2843
+ return withTransform(opts, (o) => new OpenAIClient(o));
2848
2844
  }
2849
2845
  if (profile.apiMode === "anthropic_messages") {
2850
2846
  if (profile.name === "vertex") {
@@ -2853,7 +2849,7 @@ function selectTransport(profile, apiKey, baseUrl) {
2853
2849
  }
2854
2850
  const opts = { apiKey };
2855
2851
  opts.baseUrl = baseUrl ?? process.env.ANTHROPIC_API_BASE_URL ?? profile.baseUrl;
2856
- return comTransform(opts, (o) => new AnthropicClient(o));
2852
+ return withTransform(opts, (o) => new AnthropicClient(o));
2857
2853
  }
2858
2854
  if (profile.apiMode === "bedrock_anthropic") {
2859
2855
  const realKey = apiKey === "__bedrock_lazy_token__" ? void 0 : apiKey;
@@ -2878,17 +2874,172 @@ function selectTransport(profile, apiKey, baseUrl) {
2878
2874
  providerName: profile.name
2879
2875
  });
2880
2876
  }
2881
- throw new chunk4ZHTIJNE_cjs.ConfigurationError(
2882
- `Provider "${profile.name}" requires apiMode "${profile.apiMode}" but no transport is registered. Install a third-party transport plugin (@theokit-transport-${profile.apiMode}) or use a provider with apiMode "chat_completions" or "anthropic_messages".`,
2877
+ throw new chunkJ7J7J2GN_cjs.ConfigurationError(
2878
+ `Provider "${profile.name}" declares apiMode "${profile.apiMode}", which this SDK has no transport for. Transports are built in and cannot be extended by a plugin; the supported modes are "chat_completions", "anthropic_messages", "bedrock_anthropic" and "responses_api". Change the provider's apiMode to one of those, or open an issue if the provider genuinely speaks a fifth protocol.`,
2883
2879
  { code: "transport_unavailable" }
2884
2880
  );
2885
2881
  }
2886
2882
 
2883
+ // src/internal/auth/api-key-validator.ts
2884
+ var FIXTURE_KEY_PREFIX = "theo_test_";
2885
+ var LOCAL_RUNTIME_MOCK_KEY = "local";
2886
+ var MIN_KEY_LENGTH = 16;
2887
+ var KNOWN_PROVIDER_PREFIXES = [
2888
+ { provider: "openai", prefix: "sk-" },
2889
+ { provider: "anthropic", prefix: "sk-ant-" },
2890
+ { provider: "openrouter", prefix: "sk-or-" }
2891
+ ];
2892
+ function validateApiKeyShape(key, options = {}) {
2893
+ const opts = typeof options === "string" ? { provider: options } : options;
2894
+ const tier1 = checkTier1(key);
2895
+ if (tier1.malformed) return tier1;
2896
+ const validKey = key;
2897
+ if (validKey.startsWith(FIXTURE_KEY_PREFIX) || validKey === LOCAL_RUNTIME_MOCK_KEY) {
2898
+ return { malformed: false };
2899
+ }
2900
+ if (opts.strict === false) return { malformed: false };
2901
+ return checkTier2(validKey, opts.provider);
2902
+ }
2903
+ function checkTier1(key) {
2904
+ if (key === void 0 || key.length === 0) {
2905
+ return { malformed: true, reason: "empty", message: "API key is empty." };
2906
+ }
2907
+ if (key.trim().length === 0) {
2908
+ return {
2909
+ malformed: true,
2910
+ reason: "whitespace_only",
2911
+ message: "API key contains only whitespace."
2912
+ };
2913
+ }
2914
+ if (key.length < 4) {
2915
+ return {
2916
+ malformed: true,
2917
+ reason: "too_short",
2918
+ message: `API key must be at least 4 chars (got ${key.length}).`
2919
+ };
2920
+ }
2921
+ return { malformed: false };
2922
+ }
2923
+ function checkTier2(key, provider) {
2924
+ if (key.length < MIN_KEY_LENGTH) {
2925
+ return {
2926
+ malformed: true,
2927
+ reason: "too_short",
2928
+ message: `API key must be at least ${MIN_KEY_LENGTH} chars (got ${key.length}).`
2929
+ };
2930
+ }
2931
+ if (/\s/.test(key)) {
2932
+ return {
2933
+ malformed: true,
2934
+ reason: "embedded_whitespace",
2935
+ message: "API key contains embedded whitespace."
2936
+ };
2937
+ }
2938
+ return checkProviderPrefix(key, provider);
2939
+ }
2940
+ function checkProviderPrefix(key, provider) {
2941
+ if (provider === void 0) return { malformed: false };
2942
+ const hint = KNOWN_PROVIDER_PREFIXES.find((p) => p.provider === provider.toLowerCase());
2943
+ if (hint === void 0) return { malformed: false };
2944
+ if (!key.startsWith(hint.prefix)) {
2945
+ return {
2946
+ malformed: true,
2947
+ reason: "missing_known_prefix",
2948
+ message: `API key for provider "${hint.provider}" expected to start with "${hint.prefix}".`
2949
+ };
2950
+ }
2951
+ return { malformed: false };
2952
+ }
2953
+
2954
+ // src/internal/providers/register-plugin-providers.ts
2955
+ function registerPluginProviderProfiles(entries) {
2956
+ let registered = 0;
2957
+ for (const entry of entries) {
2958
+ chunkQC55H6RJ_cjs.registerProvider(entry.profile);
2959
+ registered += 1;
2960
+ }
2961
+ return registered;
2962
+ }
2963
+ var PROVIDER_CREDENTIAL_ENV_VARS = [
2964
+ "ANTHROPIC_API_KEY",
2965
+ "OPENAI_API_KEY",
2966
+ "OPENROUTER_API_KEY"
2967
+ ];
2968
+ function presentProviderCredentialEnvVars() {
2969
+ return PROVIDER_CREDENTIAL_ENV_VARS.filter((name) => {
2970
+ const value = process.env[name];
2971
+ return typeof value === "string" && value.length > 0;
2972
+ });
2973
+ }
2974
+ var AMBIENT_STORE = {
2975
+ home: os.homedir(),
2976
+ dirName: ".theokit",
2977
+ fileName: "auth.json",
2978
+ homeEnvVar: "THEOKIT_AUTH_HOME"
2979
+ };
2980
+ function isStoredOAuthAvailable(env = process.env) {
2981
+ try {
2982
+ return chunkEXTRW7GW_cjs.readStoredOAuth(AMBIENT_STORE, env) !== void 0;
2983
+ } catch {
2984
+ return false;
2985
+ }
2986
+ }
2987
+ function isAwsBedrockAuthAvailable() {
2988
+ if (typeof process.env.AWS_BEARER_TOKEN_BEDROCK === "string" && process.env.AWS_BEARER_TOKEN_BEDROCK.length > 0) {
2989
+ return true;
2990
+ }
2991
+ if (typeof process.env.AWS_ACCESS_KEY_ID === "string" && process.env.AWS_ACCESS_KEY_ID.length > 0) {
2992
+ return true;
2993
+ }
2994
+ if (typeof process.env.AWS_PROFILE === "string" && process.env.AWS_PROFILE.length > 0) {
2995
+ return true;
2996
+ }
2997
+ return awsCredentialsFileExists();
2998
+ }
2999
+ function awsCredentialsFileExists() {
3000
+ try {
3001
+ const home = process.env.HOME ?? process.env.USERPROFILE;
3002
+ if (home === void 0 || home.length === 0) return false;
3003
+ return fs.existsSync(`${home}/.aws/credentials`) || fs.existsSync(`${home}/.aws/config`);
3004
+ } catch {
3005
+ return false;
3006
+ }
3007
+ }
3008
+ function isGcpVertexAuthAvailable() {
3009
+ if (typeof process.env.GOOGLE_APPLICATION_CREDENTIALS === "string" && process.env.GOOGLE_APPLICATION_CREDENTIALS.length > 0) {
3010
+ return true;
3011
+ }
3012
+ if (typeof process.env.GOOGLE_CLOUD_PROJECT === "string" && process.env.GOOGLE_CLOUD_PROJECT.length > 0) {
3013
+ return true;
3014
+ }
3015
+ return false;
3016
+ }
3017
+ function isLocalNoAuthProviderAvailable() {
3018
+ return true;
3019
+ }
3020
+
3021
+ // src/internal/runtime/fixtures/fixture-mode.ts
3022
+ var FIXTURE_API_KEY_PREFIX = "theo_test_";
3023
+ function isFixtureApiKey(apiKey) {
3024
+ if (apiKey === void 0) return false;
3025
+ return apiKey.startsWith(FIXTURE_API_KEY_PREFIX);
3026
+ }
3027
+ function shouldUseFixtureMode(apiKey) {
3028
+ if (getConfiguredBaseUrl() !== void 0) return false;
3029
+ return isFixtureApiKey(apiKey);
3030
+ }
3031
+ function shouldUseRealLocalRuntime(apiKey) {
3032
+ if (isFixtureApiKey(apiKey)) return false;
3033
+ if (isStoredOAuthAvailable()) return true;
3034
+ if (apiKey === void 0 || apiKey.length === 0) return false;
3035
+ return presentProviderCredentialEnvVars().length > 0 || isAwsBedrockAuthAvailable() || isGcpVertexAuthAvailable() || isLocalNoAuthProviderAvailable();
3036
+ }
3037
+
2887
3038
  // src/internal/local-agent/real-local-run-provider.ts
2888
3039
  function inferProviderFromApiKey(apiKey) {
2889
3040
  const provider = chunkFRITRLZQ_cjs.providerFromApiKeyPrefix(apiKey);
2890
3041
  if (provider === void 0) return void 0;
2891
- return chunkHCZD23VS_cjs.getProviderProfile(provider) === void 0 ? void 0 : provider;
3042
+ return chunkQC55H6RJ_cjs.getProviderProfile(provider) === void 0 ? void 0 : provider;
2892
3043
  }
2893
3044
  function detectPrimaryProvider() {
2894
3045
  if (process.env.ANTHROPIC_API_KEY !== void 0 && process.env.ANTHROPIC_API_KEY.length > 0) {
@@ -2908,11 +3059,37 @@ function warnProviderPrecedenceOnce(asked, used) {
2908
3059
  const key = `${asked}->${used}`;
2909
3060
  if (warnedProviderPrecedence.has(key)) return;
2910
3061
  warnedProviderPrecedence.add(key);
2911
- chunkEG4QM7ZJ_cjs.diag(
3062
+ chunk6LHQPOMI_cjs.diag(
2912
3063
  `[theokit-sdk] model id names provider "${asked}", but "${used}" was used \u2014 an explicit \`providers.routes[0]\` or the API key's own prefix outranks the model id's prefix. Pass \`providers.routes\` to choose deliberately.
2913
3064
  `
2914
3065
  );
2915
3066
  }
3067
+ var pluginProvidersAnnounced = false;
3068
+ function resolveRunProvider(options) {
3069
+ chunkQC55H6RJ_cjs.registerBuiltins();
3070
+ const profiles = options.pluginManager?.aggregated.providerProfiles ?? [];
3071
+ const registered = registerPluginProviderProfiles(profiles);
3072
+ if (registered > 0 && !pluginProvidersAnnounced) {
3073
+ pluginProvidersAnnounced = true;
3074
+ const names = profiles.map((e) => e.profile.name).join(", ");
3075
+ chunk6LHQPOMI_cjs.diag(`[theokit-sdk] registered ${registered} plugin provider profile(s): ${names}
3076
+ `);
3077
+ }
3078
+ const parsedModel = chunk3EE6LVWT_cjs.parseModelId(options.model?.id);
3079
+ const modelInferredProvider = parsedModel.provider !== void 0 && chunkQC55H6RJ_cjs.getProviderProfile(parsedModel.provider) !== void 0 ? parsedModel.provider : void 0;
3080
+ const keyInferredProvider = inferProviderFromApiKey(options.agentOptions.apiKey);
3081
+ const primary = options.agentOptions.providers?.routes?.[0]?.provider ?? keyInferredProvider ?? modelInferredProvider ?? detectPrimaryProvider();
3082
+ warnProviderPrecedenceOnce(modelInferredProvider, primary);
3083
+ const effectiveModelId = modelInferredProvider !== void 0 && modelInferredProvider === primary ? parsedModel.name : options.model?.id ?? "claude-sonnet-4-6";
3084
+ return { primary, effectiveModelId };
3085
+ }
3086
+ function mergeExplicitApiKey(pools, primary, apiKey) {
3087
+ if (apiKey === void 0 || apiKey.length === 0) return pools;
3088
+ if (isFixtureApiKey(apiKey) || apiKey === LOCAL_RUNTIME_MOCK_KEY) return pools;
3089
+ const existing = pools?.[primary];
3090
+ if (existing !== void 0 && existing.length > 0) return pools;
3091
+ return { ...pools ?? {}, [primary]: [apiKey] };
3092
+ }
2916
3093
 
2917
3094
  // src/internal/runtime/compression/compression-model-registry.ts
2918
3095
  var EXACT_REGISTRY = /* @__PURE__ */ new Map([
@@ -2949,12 +3126,13 @@ var WILDCARD_REGISTRY = [
2949
3126
  ["bedrock/anthropic.claude-3-5-sonnet*", "bedrock/anthropic.claude-3-5-haiku*"]
2950
3127
  ];
2951
3128
  var NO_AUTH_PROVIDERS = /* @__PURE__ */ new Set(["ollama", "lmstudio", "llamacpp"]);
2952
- var CompressionModelUnresolvedError = class extends Error {
3129
+ var CompressionModelUnresolvedError = class extends chunkJ7J7J2GN_cjs.TheokitAgentError {
2953
3130
  name = "CompressionModelUnresolvedError";
2954
3131
  agentModel;
2955
3132
  constructor(agentModel) {
2956
3133
  super(
2957
- `Could not resolve a same-family-cheaper-tier compression model for "${agentModel}". Provide Agent.create({compression: {model: "<your-cheaper-model>"}}) OR add "${agentModel}" to the compression-model-registry (see ADR D440).`
3134
+ `Could not resolve a same-family-cheaper-tier compression model for "${agentModel}". Provide Agent.create({compression: {model: "<your-cheaper-model>"}}) OR add "${agentModel}" to the compression-model-registry (see ADR D440).`,
3135
+ { code: "compression_model_unresolved", isRetryable: false }
2958
3136
  );
2959
3137
  this.agentModel = agentModel;
2960
3138
  }
@@ -2984,8 +3162,11 @@ function isNoAuthProvider(agentModel) {
2984
3162
  }
2985
3163
 
2986
3164
  // src/internal/runtime/compression/compression-summarizer.ts
2987
- var CompressionFailedError = class extends Error {
3165
+ var CompressionFailedError = class extends chunkJ7J7J2GN_cjs.TheokitAgentError {
2988
3166
  name = "CompressionFailedError";
3167
+ constructor(message, options = {}) {
3168
+ super(message, { ...options, code: "compression_failed", isRetryable: true });
3169
+ }
2989
3170
  };
2990
3171
  function buildCompressionPrompt(messages) {
2991
3172
  const formatted = messages.map((m) => `[${m.role}]: ${m.content}`).join("\n\n");
@@ -3034,7 +3215,7 @@ function plainText(content) {
3034
3215
  }
3035
3216
  async function compactSessionTranscript(opts) {
3036
3217
  const prior = await opts.store.readRecords(opts.loc.agentId);
3037
- const history = chunk5HEG4CQH_cjs.reconstructMessages(prior);
3218
+ const history = chunkGZV6AVRL_cjs.reconstructMessages(prior);
3038
3219
  const compressible = [];
3039
3220
  for (const m of history) {
3040
3221
  const text = plainText(m.content);
@@ -3042,14 +3223,14 @@ async function compactSessionTranscript(opts) {
3042
3223
  compressible.push({ role: m.role, content: text });
3043
3224
  }
3044
3225
  }
3045
- const preTokens = chunkDXGZ2NUG_cjs.estimateTokens(compressible.map((m) => m.content).join("\n"));
3226
+ const preTokens = chunkATT276RD_cjs.estimateTokens(compressible.map((m) => m.content).join("\n"));
3046
3227
  const summaryBody = await opts.summarize(compressible);
3047
3228
  const preserved = [];
3048
3229
  let budget = 0;
3049
3230
  for (let i = compressible.length - 1; i >= 0; i--) {
3050
3231
  const m = compressible[i];
3051
3232
  if (m === void 0 || m.role !== "user" || isCompactSummary(m.content)) continue;
3052
- const cost = chunkDXGZ2NUG_cjs.estimateTokens(m.content);
3233
+ const cost = chunkATT276RD_cjs.estimateTokens(m.content);
3053
3234
  if (budget + cost > COMPACT_USER_MESSAGE_MAX_TOKENS) {
3054
3235
  const remaining = COMPACT_USER_MESSAGE_MAX_TOKENS - budget;
3055
3236
  if (remaining > 50) {
@@ -3063,7 +3244,7 @@ async function compactSessionTranscript(opts) {
3063
3244
  }
3064
3245
  const summary = `${COMPACT_SUMMARY_MARKER}
3065
3246
  ${summaryBody}`;
3066
- const transcript = chunk5HEG4CQH_cjs.SessionTranscript.fromRecords(prior, {
3247
+ const transcript = chunkGZV6AVRL_cjs.SessionTranscript.fromRecords(prior, {
3067
3248
  cwd: opts.loc.cwd,
3068
3249
  sessionId: opts.sessionId,
3069
3250
  model: opts.loc.model ?? "unknown"
@@ -3073,8 +3254,8 @@ ${summaryBody}`;
3073
3254
  transcript.appendUserTurn(summary);
3074
3255
  const delta = transcript.records().slice(prior.length);
3075
3256
  await opts.store.appendRecords(opts.loc.agentId, delta);
3076
- chunk4OTIXDMU_cjs.invalidateSessionCache(opts.loc.cwd, opts.loc.agentId);
3077
- const postTokens = chunkDXGZ2NUG_cjs.estimateTokens([...preserved, summary].join("\n"));
3257
+ chunkYJNYDJ2T_cjs.invalidateSessionCache(opts.loc.cwd, opts.loc.agentId);
3258
+ const postTokens = chunkATT276RD_cjs.estimateTokens([...preserved, summary].join("\n"));
3078
3259
  return { preTokens, postTokens };
3079
3260
  }
3080
3261
  function resolveSummarizerRoute(opts) {
@@ -3083,9 +3264,9 @@ function resolveSummarizerRoute(opts) {
3083
3264
  }
3084
3265
  function buildDefaultSummarizer(opts) {
3085
3266
  return async (messages) => {
3086
- chunkHCZD23VS_cjs.registerBuiltins();
3267
+ chunkQC55H6RJ_cjs.registerBuiltins();
3087
3268
  const modelPrefix = opts.agentModel.includes("/") ? opts.agentModel.slice(0, opts.agentModel.indexOf("/")) : void 0;
3088
- const prefixProfile = modelPrefix !== void 0 ? chunkHCZD23VS_cjs.getProviderProfile(modelPrefix) : void 0;
3269
+ const prefixProfile = modelPrefix !== void 0 ? chunkQC55H6RJ_cjs.getProviderProfile(modelPrefix) : void 0;
3089
3270
  const prefixUsable = prefixProfile !== void 0 && (prefixProfile.authType !== "api_key" || prefixProfile.envVars.some((v) => (process.env[v] ?? "").length > 0));
3090
3271
  const route = resolveSummarizerRoute({
3091
3272
  keyProvider: inferProviderFromApiKey(opts.apiKey),
@@ -3134,12 +3315,10 @@ function shouldAutoCompact(opts) {
3134
3315
  if (opts.usageTotal <= 0 || opts.contextWindow <= 0) return false;
3135
3316
  return opts.usageTotal >= Math.floor(opts.contextWindow * 9 / 10);
3136
3317
  }
3137
- var autoCompactAttempts = (() => {
3138
- const g = globalThis;
3139
- const sym = /* @__PURE__ */ Symbol.for("theokit-sdk.session.auto-compact-attempts");
3140
- if (g[sym] === void 0) g[sym] = /* @__PURE__ */ new Map();
3141
- return g[sym];
3142
- })();
3318
+ var autoCompactAttempts = chunkNVXXWAU7_cjs.globalSingleton(
3319
+ "theokit-sdk.session.auto-compact-attempts",
3320
+ () => /* @__PURE__ */ new Map()
3321
+ );
3143
3322
  async function autoCompactIfNeeded(opts) {
3144
3323
  if (!shouldAutoCompact(opts)) return false;
3145
3324
  const key = `${opts.loc.cwd}::${opts.loc.agentId}`;
@@ -3156,7 +3335,7 @@ async function autoCompactIfNeeded(opts) {
3156
3335
  return true;
3157
3336
  } catch (cause) {
3158
3337
  const msg = cause instanceof Error ? cause.message : String(cause);
3159
- chunkEG4QM7ZJ_cjs.diag(`[theokit-sdk] auto-compaction failed (left transcript untouched): ${msg}
3338
+ chunk6LHQPOMI_cjs.diag(`[theokit-sdk] auto-compaction failed (left transcript untouched): ${msg}
3160
3339
  `);
3161
3340
  return false;
3162
3341
  }
@@ -3165,29 +3344,30 @@ async function autoCompactIfNeeded(opts) {
3165
3344
  exports.COMPACT_SUMMARY_MARKER = COMPACT_SUMMARY_MARKER;
3166
3345
  exports.COMPACT_USER_MESSAGE_MAX_TOKENS = COMPACT_USER_MESSAGE_MAX_TOKENS;
3167
3346
  exports.CircuitBreaker = CircuitBreaker;
3347
+ exports.abortError = abortError;
3168
3348
  exports.autoCompactIfNeeded = autoCompactIfNeeded;
3169
3349
  exports.buildDefaultSummarizer = buildDefaultSummarizer;
3170
3350
  exports.compactSessionTranscript = compactSessionTranscript;
3171
- exports.detectPrimaryProvider = detectPrimaryProvider;
3172
3351
  exports.discoverProviderPlugins = discoverProviderPlugins;
3173
3352
  exports.getConfiguredBaseUrl = getConfiguredBaseUrl;
3174
3353
  exports.httpRequest = httpRequest;
3175
- exports.inferProviderFromApiKey = inferProviderFromApiKey;
3176
3354
  exports.isCompactSummary = isCompactSummary;
3177
3355
  exports.isFixtureApiKey = isFixtureApiKey;
3178
3356
  exports.mapOllamaHttpError = mapOllamaHttpError;
3179
3357
  exports.mapOllamaTransportError = mapOllamaTransportError;
3358
+ exports.mergeExplicitApiKey = mergeExplicitApiKey;
3180
3359
  exports.parseSseStream = parseSseStream;
3181
3360
  exports.presentProviderCredentialEnvVars = presentProviderCredentialEnvVars;
3182
3361
  exports.readErrorResponseBody = readErrorResponseBody;
3183
3362
  exports.relayStream = relayStream;
3184
3363
  exports.renderToolResultContentText = renderToolResultContentText;
3185
3364
  exports.resolveProviderChain = resolveProviderChain;
3365
+ exports.resolveRunProvider = resolveRunProvider;
3186
3366
  exports.resolveSummarizerRoute = resolveSummarizerRoute;
3187
3367
  exports.shouldAutoCompact = shouldAutoCompact;
3188
3368
  exports.shouldUseFixtureMode = shouldUseFixtureMode;
3189
3369
  exports.shouldUseRealLocalRuntime = shouldUseRealLocalRuntime;
3190
3370
  exports.tryFirstEvent = tryFirstEvent;
3191
- exports.warnProviderPrecedenceOnce = warnProviderPrecedenceOnce;
3192
- //# sourceMappingURL=chunk-KYAJINUI.cjs.map
3193
- //# sourceMappingURL=chunk-KYAJINUI.cjs.map
3371
+ exports.validateApiKeyShape = validateApiKeyShape;
3372
+ //# sourceMappingURL=chunk-2HPNT6HH.cjs.map
3373
+ //# sourceMappingURL=chunk-2HPNT6HH.cjs.map