@theokit/sdk 4.63.3 → 5.0.0-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (788) hide show
  1. package/CHANGELOG.md +729 -0
  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-2E7DI47Y.cjs +67 -0
  13. package/dist/{agent-PVINJTUR.cjs.map → agent-2E7DI47Y.cjs.map} +1 -1
  14. package/dist/{agent-BFno7Sfn.d.ts → agent-CdYJfKr6.d.ts} +205 -36
  15. package/dist/{agent-X0DKA943.d.cts → agent-CgNzshyV.d.cts} +205 -36
  16. package/dist/agent-XMKRP27S.js +58 -0
  17. package/dist/{agent-3JK7VXNN.js.map → agent-XMKRP27S.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-UBDMVMBZ.js → chunk-55GB6JYQ.js} +33 -22
  62. package/dist/chunk-55GB6JYQ.js.map +1 -0
  63. package/dist/{chunk-U6IFHFWK.js → chunk-5WKQDIGO.js} +8 -17
  64. package/dist/chunk-5WKQDIGO.js.map +1 -0
  65. package/dist/{chunk-GPKAF7SG.js → chunk-6HIACV34.js} +91 -92
  66. package/dist/chunk-6HIACV34.js.map +1 -0
  67. package/dist/{chunk-XL7Q7HB2.cjs → chunk-6LHQPOMI.cjs} +39 -6
  68. package/dist/chunk-6LHQPOMI.cjs.map +1 -0
  69. package/dist/{chunk-A4JVILQU.js → chunk-6M2OIS4Y.js} +7 -7
  70. package/dist/chunk-6M2OIS4Y.js.map +1 -0
  71. package/dist/{chunk-LWGSI6M3.js → chunk-6PWOWXMC.js} +4 -4
  72. package/dist/{chunk-LWGSI6M3.js.map → chunk-6PWOWXMC.js.map} +1 -1
  73. package/dist/{chunk-RNB4APBZ.js → chunk-6WAKKTBO.js} +9 -5
  74. package/dist/chunk-6WAKKTBO.js.map +1 -0
  75. package/dist/{chunk-V2BOS4WF.cjs → chunk-7A6535RA.cjs} +11 -11
  76. package/dist/chunk-7A6535RA.cjs.map +1 -0
  77. package/dist/{chunk-ZLQSWSJ2.cjs → chunk-7FDKWDA2.cjs} +11 -11
  78. package/dist/{chunk-ZLQSWSJ2.cjs.map → chunk-7FDKWDA2.cjs.map} +1 -1
  79. package/dist/{chunk-4VPXM6UU.js → chunk-7I5Z3UBJ.js} +3 -3
  80. package/dist/{chunk-4VPXM6UU.js.map → chunk-7I5Z3UBJ.js.map} +1 -1
  81. package/dist/{chunk-B4EOJWOY.cjs → chunk-7JJ3A6AT.cjs} +13 -7
  82. package/dist/chunk-7JJ3A6AT.cjs.map +1 -0
  83. package/dist/{chunk-ZWRG4NWT.cjs → chunk-7ZK4DJD7.cjs} +108 -109
  84. package/dist/chunk-7ZK4DJD7.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-CEILSTWB.cjs +109 -0
  102. package/dist/chunk-CEILSTWB.cjs.map +1 -0
  103. package/dist/{chunk-D4CUGAKZ.js → chunk-CZJ6Q7CW.js} +36 -6
  104. package/dist/chunk-CZJ6Q7CW.js.map +1 -0
  105. package/dist/{chunk-KQ7TS7WW.cjs → chunk-D6POWE7E.cjs} +37 -26
  106. package/dist/chunk-D6POWE7E.cjs.map +1 -0
  107. package/dist/{chunk-AWO27VRZ.js → chunk-DMRT67Y6.js} +6 -5
  108. package/dist/chunk-DMRT67Y6.js.map +1 -0
  109. package/dist/{chunk-5VB22SYX.cjs → chunk-DQZU7JK6.cjs} +7 -7
  110. package/dist/{chunk-5VB22SYX.cjs.map → chunk-DQZU7JK6.cjs.map} +1 -1
  111. package/dist/{chunk-3NSS2OIZ.cjs → chunk-DRL7URI4.cjs} +6 -6
  112. package/dist/{chunk-3NSS2OIZ.cjs.map → chunk-DRL7URI4.cjs.map} +1 -1
  113. package/dist/{chunk-RFXWMRFC.js → chunk-EFMFILPG.js} +14 -6
  114. package/dist/chunk-EFMFILPG.js.map +1 -0
  115. package/dist/{chunk-HS7AVXTF.js → chunk-EH6XD3FY.js} +4 -4
  116. package/dist/chunk-EH6XD3FY.js.map +1 -0
  117. package/dist/{chunk-KQRW2GPZ.js → chunk-EIQFAOFD.js} +6 -6
  118. package/dist/chunk-EIQFAOFD.js.map +1 -0
  119. package/dist/{chunk-XJCXEKMD.cjs → chunk-EXTRW7GW.cjs} +4 -4
  120. package/dist/chunk-EXTRW7GW.cjs.map +1 -0
  121. package/dist/{chunk-U54XCYG3.js → chunk-FJWQP6EE.js} +12 -6
  122. package/dist/chunk-FJWQP6EE.js.map +1 -0
  123. package/dist/{chunk-O7DK5PBJ.cjs → chunk-FUSDYC2B.cjs} +26 -42
  124. package/dist/chunk-FUSDYC2B.cjs.map +1 -0
  125. package/dist/{chunk-CQBXOJ6U.cjs → chunk-G4ZGYKJG.cjs} +21 -21
  126. package/dist/chunk-G4ZGYKJG.cjs.map +1 -0
  127. package/dist/{chunk-4QZSA2HJ.js → chunk-G7BLGBRN.js} +4 -4
  128. package/dist/chunk-G7BLGBRN.js.map +1 -0
  129. package/dist/{chunk-BZRFXJHA.js → chunk-GBCVPKHE.js} +55 -26
  130. package/dist/chunk-GBCVPKHE.js.map +1 -0
  131. package/dist/{chunk-5HEG4CQH.cjs → chunk-GZV6AVRL.cjs} +8 -8
  132. package/dist/{chunk-5HEG4CQH.cjs.map → chunk-GZV6AVRL.cjs.map} +1 -1
  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-ZCIRZE37.cjs → chunk-HWSALKOR.cjs} +26 -17
  142. package/dist/chunk-HWSALKOR.cjs.map +1 -0
  143. package/dist/{chunk-ZSWPZ23K.cjs → chunk-I2PWY7VM.cjs} +5 -5
  144. package/dist/chunk-I2PWY7VM.cjs.map +1 -0
  145. package/dist/{chunk-VJ26EKGJ.cjs → chunk-IJ7M6GOG.cjs} +3 -3
  146. package/dist/chunk-IJ7M6GOG.cjs.map +1 -0
  147. package/dist/{chunk-K5OJUYSZ.js → chunk-IJM7UGS5.js} +19 -10
  148. package/dist/chunk-IJM7UGS5.js.map +1 -0
  149. package/dist/{chunk-SAVIWMZB.js → chunk-ILGZ2ZZV.js} +3 -3
  150. package/dist/chunk-ILGZ2ZZV.js.map +1 -0
  151. package/dist/{chunk-4ZHTIJNE.cjs → chunk-J7J7J2GN.cjs} +87 -63
  152. package/dist/chunk-J7J7J2GN.cjs.map +1 -0
  153. package/dist/{chunk-UALX2J2Q.cjs → chunk-JLRLCBJ4.cjs} +38 -11
  154. package/dist/chunk-JLRLCBJ4.cjs.map +1 -0
  155. package/dist/{chunk-2QDYBS2A.js → chunk-JMDDYA22.js} +4 -4
  156. package/dist/chunk-JMDDYA22.js.map +1 -0
  157. package/dist/{chunk-LXQ6HKPS.js → chunk-JNAA4G4H.js} +3 -3
  158. package/dist/{chunk-LXQ6HKPS.js.map → chunk-JNAA4G4H.js.map} +1 -1
  159. package/dist/{chunk-UMP6OJIM.js → chunk-JOFVLOFY.js} +4 -4
  160. package/dist/{chunk-UMP6OJIM.js.map → chunk-JOFVLOFY.js.map} +1 -1
  161. package/dist/chunk-JTZ74HFD.js +100 -0
  162. package/dist/chunk-JTZ74HFD.js.map +1 -0
  163. package/dist/{chunk-A46SWMIF.js → chunk-K2VMFZQ5.js} +7 -7
  164. package/dist/chunk-K2VMFZQ5.js.map +1 -0
  165. package/dist/{chunk-DN2PACRI.js → chunk-K3NH62DG.js} +461 -282
  166. package/dist/chunk-K3NH62DG.js.map +1 -0
  167. package/dist/{chunk-XWTLIGO3.cjs → chunk-KTTHHYEW.cjs} +5 -5
  168. package/dist/chunk-KTTHHYEW.cjs.map +1 -0
  169. package/dist/{chunk-3FFAEAUJ.cjs → chunk-KVSAY6NZ.cjs} +18 -18
  170. package/dist/chunk-KVSAY6NZ.cjs.map +1 -0
  171. package/dist/{chunk-IAHZCGBE.cjs → chunk-LHSWHYF3.cjs} +120 -146
  172. package/dist/chunk-LHSWHYF3.cjs.map +1 -0
  173. package/dist/{chunk-25BD2R5G.js → chunk-NCGWJ3HS.js} +1991 -1854
  174. package/dist/chunk-NCGWJ3HS.js.map +1 -0
  175. package/dist/{chunk-3OR54XG4.js → chunk-NJWYQWDL.js} +12 -8
  176. package/dist/chunk-NJWYQWDL.js.map +1 -0
  177. package/dist/chunk-NVXXWAU7.cjs +13 -0
  178. package/dist/chunk-NVXXWAU7.cjs.map +1 -0
  179. package/dist/{chunk-2D34UTDC.js → chunk-O6USDERH.js} +31 -11
  180. package/dist/chunk-O6USDERH.js.map +1 -0
  181. package/dist/{chunk-XO4SOZN6.js → chunk-OR6XIWLB.js} +4 -4
  182. package/dist/{chunk-XO4SOZN6.js.map → chunk-OR6XIWLB.js.map} +1 -1
  183. package/dist/{chunk-4PYZ5AX3.cjs → chunk-PRZ3BES7.cjs} +16 -8
  184. package/dist/chunk-PRZ3BES7.cjs.map +1 -0
  185. package/dist/{chunk-HCZD23VS.cjs → chunk-QC55H6RJ.cjs} +65 -39
  186. package/dist/chunk-QC55H6RJ.cjs.map +1 -0
  187. package/dist/{chunk-4O5TGQBW.cjs → chunk-QME6FDFG.cjs} +9 -5
  188. package/dist/chunk-QME6FDFG.cjs.map +1 -0
  189. package/dist/chunk-QOGNZMHD.cjs +34 -0
  190. package/dist/chunk-QOGNZMHD.cjs.map +1 -0
  191. package/dist/{chunk-B2J4ZMZL.cjs → chunk-QWD3CZWE.cjs} +6 -5
  192. package/dist/chunk-QWD3CZWE.cjs.map +1 -0
  193. package/dist/{chunk-SZVR77EJ.cjs → chunk-QWD4RDZ3.cjs} +15 -24
  194. package/dist/chunk-QWD4RDZ3.cjs.map +1 -0
  195. package/dist/{chunk-7BG5UH3T.cjs → chunk-RHZ6HP23.cjs} +4 -4
  196. package/dist/chunk-RHZ6HP23.cjs.map +1 -0
  197. package/dist/{chunk-2HVF2WJY.cjs → chunk-RQMCOFAI.cjs} +8 -8
  198. package/dist/{chunk-2HVF2WJY.cjs.map → chunk-RQMCOFAI.cjs.map} +1 -1
  199. package/dist/{chunk-VKJ7V7EB.cjs → chunk-SA6K24NB.cjs} +3 -3
  200. package/dist/chunk-SA6K24NB.cjs.map +1 -0
  201. package/dist/{chunk-7AD3ZTZL.js → chunk-SAGRF4IB.js} +3 -3
  202. package/dist/chunk-SAGRF4IB.js.map +1 -0
  203. package/dist/{chunk-PUAEFLYK.js → chunk-SVQIW5RJ.js} +4 -4
  204. package/dist/{chunk-PUAEFLYK.js.map → chunk-SVQIW5RJ.js.map} +1 -1
  205. package/dist/{chunk-3O42QOMJ.js → chunk-TA3K7SBK.js} +7 -6
  206. package/dist/chunk-TA3K7SBK.js.map +1 -0
  207. package/dist/{chunk-LYRDF5TQ.cjs → chunk-TFG5IBZS.cjs} +14 -23
  208. package/dist/chunk-TFG5IBZS.cjs.map +1 -0
  209. package/dist/{chunk-GKEFRLU7.cjs → chunk-TMKTSYDS.cjs} +6 -6
  210. package/dist/{chunk-GKEFRLU7.cjs.map → chunk-TMKTSYDS.cjs.map} +1 -1
  211. package/dist/{chunk-J24VJOH3.cjs → chunk-UADQJBHR.cjs} +31 -11
  212. package/dist/chunk-UADQJBHR.cjs.map +1 -0
  213. package/dist/{chunk-TAZVKYWJ.js → chunk-UBR5PWD7.js} +26 -40
  214. package/dist/chunk-UBR5PWD7.js.map +1 -0
  215. package/dist/{chunk-IPYYKCRC.js → chunk-UFPUHJWS.js} +5 -5
  216. package/dist/{chunk-IPYYKCRC.js.map → chunk-UFPUHJWS.js.map} +1 -1
  217. package/dist/{chunk-OHLDPWTA.cjs → chunk-UGRS7ZA7.cjs} +15 -15
  218. package/dist/{chunk-OHLDPWTA.cjs.map → chunk-UGRS7ZA7.cjs.map} +1 -1
  219. package/dist/{chunk-RIAM53CP.js → chunk-UKMBRMGT.js} +3 -3
  220. package/dist/chunk-UKMBRMGT.js.map +1 -0
  221. package/dist/{chunk-L4BDVXIM.js → chunk-UNK4HNJH.js} +97 -123
  222. package/dist/chunk-UNK4HNJH.js.map +1 -0
  223. package/dist/{chunk-C3NT3PVE.js → chunk-V22DZIXO.js} +3 -3
  224. package/dist/chunk-V22DZIXO.js.map +1 -0
  225. package/dist/{chunk-OFRFZRQ4.cjs → chunk-V6ZY4AX6.cjs} +24 -14
  226. package/dist/chunk-V6ZY4AX6.cjs.map +1 -0
  227. package/dist/{chunk-B3IMEBOA.js → chunk-VE6DFSKU.js} +3 -3
  228. package/dist/{chunk-B3IMEBOA.js.map → chunk-VE6DFSKU.js.map} +1 -1
  229. package/dist/{chunk-WLQNMXQE.js → chunk-VWUXIVEI.js} +53 -26
  230. package/dist/chunk-VWUXIVEI.js.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-JJ3OVRUM.cjs → chunk-WMH2MSOP.cjs} +2250 -2113
  234. package/dist/chunk-WMH2MSOP.cjs.map +1 -0
  235. package/dist/{chunk-7YGCPMGB.js → chunk-XB4GI5RZ.js} +27 -12
  236. package/dist/chunk-XB4GI5RZ.js.map +1 -0
  237. package/dist/{chunk-LXI4XZEC.js → chunk-XCCGNU3D.js} +13 -13
  238. package/dist/chunk-XCCGNU3D.js.map +1 -0
  239. package/dist/{chunk-O73J46PV.js → chunk-XDANGA2C.js} +5 -5
  240. package/dist/{chunk-O73J46PV.js.map → chunk-XDANGA2C.js.map} +1 -1
  241. package/dist/{chunk-UTSRIDKZ.js → chunk-XYFGKVZ7.js} +3 -3
  242. package/dist/chunk-XYFGKVZ7.js.map +1 -0
  243. package/dist/{chunk-RMWTPV3M.cjs → chunk-Y2KYR2ED.cjs} +27 -27
  244. package/dist/chunk-Y2KYR2ED.cjs.map +1 -0
  245. package/dist/{chunk-O7LZFG6O.cjs → chunk-YIFFF23U.cjs} +5 -5
  246. package/dist/chunk-YIFFF23U.cjs.map +1 -0
  247. package/dist/{chunk-4OTIXDMU.cjs → chunk-YJNYDJ2T.cjs} +12 -4
  248. package/dist/chunk-YJNYDJ2T.cjs.map +1 -0
  249. package/dist/{chunk-6JSIEDKL.cjs → chunk-YSTXFWQE.cjs} +13 -7
  250. package/dist/chunk-YSTXFWQE.cjs.map +1 -0
  251. package/dist/{chunk-I6HGWHPU.cjs → chunk-Z3NTRKIC.cjs} +4 -4
  252. package/dist/{chunk-I6HGWHPU.cjs.map → chunk-Z3NTRKIC.cjs.map} +1 -1
  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-74SBFD27.cjs +23 -0
  270. package/dist/{context-AGQ3DIZU.cjs.map → context-74SBFD27.cjs.map} +1 -1
  271. package/dist/context-NZ2AC6S7.js +6 -0
  272. package/dist/{context-GQRFBCLP.js.map → context-NZ2AC6S7.js.map} +1 -1
  273. package/dist/create-skill.d.ts +4 -1
  274. package/dist/{cron-BuiRPrvt.d.cts → cron-Bw6mSgD4.d.cts} +8 -2
  275. package/dist/{cron-C2SIi31n.d.ts → cron-DJv9oXSZ.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/replay-messages.d.ts +41 -0
  341. package/dist/internal/agent-loop/tool-dispatch.d.ts +2 -2
  342. package/dist/internal/agent-loop/usage-and-cost.d.ts +1 -1
  343. package/dist/internal/auth/credential-availability.d.ts +61 -0
  344. package/dist/internal/auth/credential-store.d.ts +1 -1
  345. package/dist/internal/auth/oauth-device.d.ts +1 -1
  346. package/dist/internal/auth/oauth-engine.d.ts +1 -1
  347. package/dist/internal/auth/resolve-credential.d.ts +1 -1
  348. package/dist/internal/base-url.d.ts +14 -0
  349. package/dist/internal/cloud-agent/cloud-config-serializer.d.ts +1 -1
  350. package/dist/internal/{runtime/concurrency → concurrency}/subagent-credentials.d.ts +2 -2
  351. package/dist/internal/emit-run-event.d.ts +16 -0
  352. package/dist/internal/error-mappers/shared.d.ts +14 -1
  353. package/dist/internal/eval/assert.d.ts +2 -1
  354. package/dist/internal/eval/single-flight.d.ts +2 -1
  355. package/dist/internal/global-singleton.d.ts +6 -3
  356. package/dist/internal/llm/responses.d.ts +10 -0
  357. package/dist/internal/local-agent/local-agent-bootstrap.d.ts +5 -3
  358. package/dist/internal/local-agent/local-agent-capabilities.d.ts +38 -0
  359. package/dist/internal/local-agent/local-agent-dispatch.d.ts +2 -2
  360. package/dist/internal/local-agent/local-agent-memory-provider.d.ts +1 -1
  361. package/dist/internal/local-agent/local-agent-personality-extensions.d.ts +25 -1
  362. package/dist/internal/local-agent/local-agent-send.d.ts +42 -1
  363. package/dist/internal/local-agent/local-option-keys.d.ts +2 -0
  364. package/dist/internal/local-agent/real-local-run-mcp.d.ts +26 -0
  365. package/dist/internal/local-agent/real-local-run-options.d.ts +26 -0
  366. package/dist/internal/local-agent/real-local-run-tools.d.ts +21 -4
  367. package/dist/internal/local-agent/real-local-run.d.ts +2 -2
  368. package/dist/internal/mcp/handshake-timeout.d.ts +53 -0
  369. package/dist/internal/memory/active-memory.d.ts +1 -1
  370. package/dist/internal/memory/adapters/index.cjs +10 -10
  371. package/dist/internal/memory/adapters/index.js +9 -9
  372. package/dist/internal/memory/adapters/openai-embedding.d.cts +10 -0
  373. package/dist/internal/memory/adapters/openai-embedding.d.ts +10 -0
  374. package/dist/internal/memory/corpus-sync.d.ts +23 -0
  375. package/dist/internal/memory/index-db.d.ts +15 -1
  376. package/dist/internal/memory/index-manager-contract.d.ts +12 -0
  377. package/dist/internal/memory/index-manager.d.ts +4 -10
  378. package/dist/internal/memory/index-repository.d.ts +58 -0
  379. package/dist/internal/memory/lance-memory-adapter.d.ts +16 -14
  380. package/dist/internal/memory/memory-index.d.ts +15 -0
  381. package/dist/internal/memory/sdk-memory-peer-loader.d.ts +54 -1
  382. package/dist/internal/memory/storage/index.cjs +39 -40
  383. package/dist/internal/memory/storage/index.js +10 -11
  384. package/dist/internal/memory/storage/memory-root.d.cts +2 -3
  385. package/dist/internal/memory/storage/memory-root.d.ts +2 -3
  386. package/dist/internal/persistence/atomic-write.d.cts +4 -4
  387. package/dist/internal/persistence/atomic-write.d.ts +4 -4
  388. package/dist/internal/persistence/index.cjs +24 -25
  389. package/dist/internal/persistence/index.cjs.map +1 -1
  390. package/dist/internal/persistence/index.js +7 -8
  391. package/dist/internal/persistence/index.js.map +1 -1
  392. package/dist/internal/persistence/jsonl.d.cts +3 -1
  393. package/dist/internal/persistence/jsonl.d.ts +3 -1
  394. package/dist/internal/persistence/paths.d.cts +2 -2
  395. package/dist/internal/persistence/paths.d.ts +2 -2
  396. package/dist/internal/persistence/transcript-ops.d.cts +11 -2
  397. package/dist/internal/persistence/transcript-ops.d.ts +11 -2
  398. package/dist/internal/plugins/context.d.cts +0 -10
  399. package/dist/internal/plugins/context.d.ts +0 -10
  400. package/dist/internal/plugins/types.d.cts +1 -1
  401. package/dist/internal/plugins/types.d.ts +1 -1
  402. package/dist/internal/providers/catalog-schema.d.ts +94 -0
  403. package/dist/internal/providers/catalog-source-models-dev.d.ts +11 -0
  404. package/dist/internal/runtime/compat/foreign-config-sources.d.ts +86 -0
  405. package/dist/internal/runtime/compression/compression-model-registry.d.ts +1 -1
  406. package/dist/internal/runtime/compression/compression-summarizer.d.ts +5 -1
  407. package/dist/internal/runtime/fixtures/fixture-events.d.ts +1 -1
  408. package/dist/internal/runtime/fixtures/fixture-mode.d.ts +8 -14
  409. package/dist/internal/runtime/fixtures/fixture-run-base.d.ts +1 -1
  410. package/dist/internal/runtime/fixtures/fixture-scripts.d.ts +2 -2
  411. package/dist/internal/runtime/hooks/hooks-executor.d.ts +14 -1
  412. package/dist/internal/runtime/hooks/hooks-source.d.ts +9 -0
  413. package/dist/internal/runtime/lifecycle/wrap-completion-check-run.d.ts +1 -1
  414. package/dist/internal/runtime/{memory → memory-glue}/memory-provider.d.ts +1 -1
  415. package/dist/internal/runtime/{plugins → plugin-loader}/plugin-bundles.d.ts +3 -1
  416. package/dist/internal/runtime/processors/wrap-output-run.d.ts +1 -1
  417. package/dist/internal/runtime/registry/live-agent-registry.d.ts +9 -1
  418. package/dist/internal/runtime/system-prompt/local-assembly.d.ts +2 -1
  419. package/dist/internal/scorers/llm-judge.d.ts +12 -0
  420. package/dist/internal/security/index.cjs +14 -15
  421. package/dist/internal/security/index.d.cts +6 -1
  422. package/dist/internal/security/index.d.ts +6 -1
  423. package/dist/internal/security/index.js +4 -5
  424. package/dist/internal/security/path-containment.d.ts +24 -0
  425. package/dist/internal/session/agent-session-store.d.ts +1 -1
  426. package/dist/internal/session/agent-session.d.ts +1 -1
  427. package/dist/internal/session/index.d.ts +1 -1
  428. package/dist/internal/session/session-cache.d.ts +9 -3
  429. package/dist/internal/task/registry.d.ts +1 -1
  430. package/dist/internal/task/store.d.ts +1 -1
  431. package/dist/internal/task/subscribe.d.ts +1 -1
  432. package/dist/internal/task/task-id.d.ts +22 -0
  433. package/dist/internal/telemetry/adapter-registry.d.ts +12 -2
  434. package/dist/internal/telemetry/adapters/braintrust.d.ts +6 -1
  435. package/dist/internal/telemetry/adapters/langsmith.d.ts +6 -1
  436. package/dist/internal/workflow/executor.d.ts +2 -1
  437. package/dist/internal/workflow/snapshot-store.d.ts +1 -1
  438. package/dist/internal/workflow/step-branch.d.ts +2 -2
  439. package/dist/internal/workflow/step-dowhile.d.ts +2 -2
  440. package/dist/internal/workflow/step-execution.d.ts +25 -0
  441. package/dist/internal/workflow/step-foreach.d.ts +2 -2
  442. package/dist/internal/workflow/step-parallel.d.ts +2 -2
  443. package/dist/judge-call-6MVARKU2.js +5 -0
  444. package/dist/{judge-call-LVXABPS3.js.map → judge-call-6MVARKU2.js.map} +1 -1
  445. package/dist/judge-call-I3P4D5QR.cjs +22 -0
  446. package/dist/{judge-call-LAHMBJ57.cjs.map → judge-call-I3P4D5QR.cjs.map} +1 -1
  447. package/dist/mcp-auth.cjs +14 -15
  448. package/dist/mcp-auth.cjs.map +1 -1
  449. package/dist/mcp-auth.d.cts +2 -0
  450. package/dist/mcp-auth.d.ts +2 -0
  451. package/dist/mcp-auth.js +4 -5
  452. package/dist/mcp-auth.js.map +1 -1
  453. package/dist/models.cjs +52 -42
  454. package/dist/models.cjs.map +1 -1
  455. package/dist/models.js +39 -29
  456. package/dist/models.js.map +1 -1
  457. package/dist/oauth-transaction-store-5RIR6D5C.js +5 -0
  458. package/dist/{oauth-transaction-store-W52KVHQ4.js.map → oauth-transaction-store-5RIR6D5C.js.map} +1 -1
  459. package/dist/oauth-transaction-store-SXIE57OD.cjs +38 -0
  460. package/dist/{oauth-transaction-store-BT4GLTLK.cjs.map → oauth-transaction-store-SXIE57OD.cjs.map} +1 -1
  461. package/dist/path-safety.cjs +11 -12
  462. package/dist/path-safety.d.cts +2 -0
  463. package/dist/path-safety.d.ts +2 -0
  464. package/dist/path-safety.js +4 -5
  465. package/dist/permission-engine.d.ts +10 -17
  466. package/dist/persistence.cjs +31 -31
  467. package/dist/persistence.cjs.map +1 -1
  468. package/dist/persistence.d.cts +9 -1
  469. package/dist/persistence.d.ts +9 -1
  470. package/dist/persistence.js +12 -13
  471. package/dist/persistence.js.map +1 -1
  472. package/dist/project.cjs +5 -6
  473. package/dist/project.cjs.map +1 -1
  474. package/dist/project.js +3 -4
  475. package/dist/project.js.map +1 -1
  476. package/dist/providers.cjs +10 -10
  477. package/dist/providers.d.cts +2 -0
  478. package/dist/providers.d.ts +2 -0
  479. package/dist/providers.js +8 -8
  480. package/dist/registry-BZQFYRTL.cjs +46 -0
  481. package/dist/{registry-V7BDQ6QB.cjs.map → registry-BZQFYRTL.cjs.map} +1 -1
  482. package/dist/registry-DMWCJKRF.js +9 -0
  483. package/dist/{registry-75W33OGL.js.map → registry-DMWCJKRF.js.map} +1 -1
  484. package/dist/retry.cjs +4 -5
  485. package/dist/retry.d.cts +20 -5
  486. package/dist/retry.d.ts +20 -5
  487. package/dist/retry.js +3 -4
  488. package/dist/{run-BYSHf58D.d.cts → run-CTAdRU3U.d.cts} +120 -152
  489. package/dist/{run-BYSHf58D.d.ts → run-CTAdRU3U.d.ts} +120 -152
  490. package/dist/{run-until-HEQOUVU6.js → run-until-6D6TQ4JN.js} +27 -59
  491. package/dist/run-until-6D6TQ4JN.js.map +1 -0
  492. package/dist/{run-until-U2B5FJJI.cjs → run-until-DG2KXWB2.cjs} +27 -59
  493. package/dist/run-until-DG2KXWB2.cjs.map +1 -0
  494. package/dist/sandbox/bwrap.d.cts +11 -1
  495. package/dist/sandbox/bwrap.d.ts +11 -1
  496. package/dist/sandbox/index.cjs +26 -30
  497. package/dist/sandbox/index.cjs.map +1 -1
  498. package/dist/sandbox/index.d.cts +8 -1
  499. package/dist/sandbox/index.d.ts +8 -1
  500. package/dist/sandbox/index.js +10 -14
  501. package/dist/sandbox/index.js.map +1 -1
  502. package/dist/sandbox/linux-sandbox.d.cts +20 -4
  503. package/dist/sandbox/linux-sandbox.d.ts +20 -4
  504. package/dist/sandbox/types.d.cts +18 -2
  505. package/dist/sandbox/types.d.ts +18 -2
  506. package/dist/sanitize/index.cjs +2 -2
  507. package/dist/sanitize/index.js +1 -1
  508. package/dist/sanitize/types.d.cts +15 -2
  509. package/dist/sanitize/types.d.ts +15 -2
  510. package/dist/{sdk-agent-D8qJVkuV.d.ts → sdk-agent-Dxjb0IfM.d.cts} +169 -116
  511. package/dist/{sdk-agent-DEoKhA8a.d.cts → sdk-agent-ldzpyAaF.d.ts} +169 -116
  512. package/dist/server/auth/errors.d.cts +4 -3
  513. package/dist/server/auth/errors.d.ts +4 -3
  514. package/dist/server/auth/index.cjs +28 -28
  515. package/dist/server/auth/index.cjs.map +1 -1
  516. package/dist/server/auth/index.d.cts +28 -5
  517. package/dist/server/auth/index.d.ts +28 -5
  518. package/dist/server/auth/index.js +13 -13
  519. package/dist/server/auth/index.js.map +1 -1
  520. package/dist/server/auth/oauth-transaction-store.d.cts +2 -1
  521. package/dist/server/auth/oauth-transaction-store.d.ts +2 -1
  522. package/dist/server/auth/orchestrator.d.cts +4 -1
  523. package/dist/server/auth/orchestrator.d.ts +4 -1
  524. package/dist/server/auth/types.d.cts +18 -0
  525. package/dist/server/auth/types.d.ts +18 -0
  526. package/dist/server/errors-envelope.cjs +14 -15
  527. package/dist/server/errors-envelope.cjs.map +1 -1
  528. package/dist/server/errors-envelope.d.cts +3 -3
  529. package/dist/server/errors-envelope.d.ts +3 -3
  530. package/dist/server/errors-envelope.js +3 -4
  531. package/dist/server/errors-envelope.js.map +1 -1
  532. package/dist/session-transcript-LGHSNVY5.cjs +62 -0
  533. package/dist/{session-transcript-6WNITKRE.cjs.map → session-transcript-LGHSNVY5.cjs.map} +1 -1
  534. package/dist/session-transcript-VTBTCGQX.js +5 -0
  535. package/dist/{session-transcript-XAEKW6P7.js.map → session-transcript-VTBTCGQX.js.map} +1 -1
  536. package/dist/skills.cjs +8 -9
  537. package/dist/skills.js +6 -7
  538. package/dist/stream-object-HBFMIZLD.js +7 -0
  539. package/dist/{stream-object-UF4QRQRU.js.map → stream-object-HBFMIZLD.js.map} +1 -1
  540. package/dist/stream-object-QSKHISDJ.cjs +20 -0
  541. package/dist/{stream-object-ZJTQNKY3.cjs.map → stream-object-QSKHISDJ.cjs.map} +1 -1
  542. package/dist/stream-object.d.ts +2 -4
  543. package/dist/subagents-loader-LSKM2UIK.js +7 -0
  544. package/dist/{subagents-loader-CRT5LLL3.js.map → subagents-loader-LSKM2UIK.js.map} +1 -1
  545. package/dist/subagents-loader-YWFE7KYE.cjs +16 -0
  546. package/dist/{subagents-loader-YEUFFPAL.cjs.map → subagents-loader-YWFE7KYE.cjs.map} +1 -1
  547. package/dist/subagents-loader.cjs +7 -8
  548. package/dist/subagents-loader.cjs.map +1 -1
  549. package/dist/subagents-loader.d.cts +5 -3
  550. package/dist/subagents-loader.d.ts +5 -3
  551. package/dist/subagents-loader.js +5 -6
  552. package/dist/subagents-loader.js.map +1 -1
  553. package/dist/subagents.cjs +2 -2
  554. package/dist/subagents.cjs.map +1 -1
  555. package/dist/subagents.js +1 -1
  556. package/dist/subagents.js.map +1 -1
  557. package/dist/subscription/define-subscription.d.cts +4 -1
  558. package/dist/subscription/define-subscription.d.ts +4 -1
  559. package/dist/subscription/index.cjs +4 -5
  560. package/dist/subscription/index.cjs.map +1 -1
  561. package/dist/subscription/index.d.cts +2 -0
  562. package/dist/subscription/index.d.ts +2 -0
  563. package/dist/subscription/index.js +3 -4
  564. package/dist/subscription/index.js.map +1 -1
  565. package/dist/subscription/internal/server-integration.d.cts +5 -0
  566. package/dist/subscription/internal/server-integration.d.ts +5 -0
  567. package/dist/subscription/internal/subscription-runtime.d.cts +13 -1
  568. package/dist/subscription/internal/subscription-runtime.d.ts +13 -1
  569. package/dist/task-errors.d.ts +58 -0
  570. package/dist/task-store.cjs +7 -8
  571. package/dist/task-store.d.cts +2 -0
  572. package/dist/task-store.d.ts +2 -0
  573. package/dist/task-store.js +4 -5
  574. package/dist/types/agent-prims.d.ts +21 -0
  575. package/dist/types/agent.d.ts +63 -15
  576. package/dist/types/batch.d.ts +3 -0
  577. package/dist/types/budget-tracker.d.ts +3 -0
  578. package/dist/types/budget.d.ts +12 -3
  579. package/dist/types/content-blocks.d.ts +3 -0
  580. package/dist/types/context.d.ts +3 -0
  581. package/dist/types/conversation.d.ts +5 -0
  582. package/dist/types/cron.d.ts +5 -0
  583. package/dist/types/env-policy.d.ts +3 -0
  584. package/dist/types/eval.d.ts +3 -0
  585. package/dist/types/fork.d.ts +3 -0
  586. package/dist/types/goal-events.d.ts +3 -0
  587. package/dist/types/mcp.d.ts +5 -0
  588. package/dist/types/memory-adapter.d.ts +3 -0
  589. package/dist/types/memory-provider.d.ts +44 -5
  590. package/dist/types/messages-base.d.ts +4 -0
  591. package/dist/types/messages.d.ts +5 -0
  592. package/dist/types/plugin.d.ts +32 -4
  593. package/dist/types/processors.d.ts +3 -0
  594. package/dist/types/provider-profile.d.ts +3 -0
  595. package/dist/types/providers.d.ts +3 -0
  596. package/dist/types/run-events.d.ts +36 -9
  597. package/dist/types/run.d.ts +29 -2
  598. package/dist/types/sdk-agent.d.ts +43 -0
  599. package/dist/types/session-message.d.ts +3 -0
  600. package/dist/types/session-record.d.ts +3 -0
  601. package/dist/types/session-store.d.ts +45 -0
  602. package/dist/types/task.d.ts +3 -11
  603. package/dist/types/theokit.d.ts +3 -0
  604. package/dist/types/trajectory.d.ts +3 -0
  605. package/dist/types/updates.d.ts +5 -0
  606. package/dist/types/usage.d.ts +4 -1
  607. package/dist/types/workflow.d.ts +13 -135
  608. package/dist/workflow-as-tool.d.ts +66 -0
  609. package/dist/workflow-errors.d.ts +164 -0
  610. package/dist/workflow.cjs +29 -30
  611. package/dist/workflow.d.cts +135 -74
  612. package/dist/workflow.d.ts +135 -74
  613. package/dist/workflow.js +8 -9
  614. package/docs/adr/README.md +2604 -0
  615. package/docs/error-codes.md +137 -103
  616. package/docs/harness-capability-map.md +30 -20
  617. package/docs/memory-decisions.md +1 -1
  618. package/package.json +3 -7
  619. package/bin/theokit-migrate-config.mjs +0 -278
  620. package/bin/theokit-migrate-memory.mjs +0 -116
  621. package/dist/agent-3JK7VXNN.js +0 -57
  622. package/dist/agent-PVINJTUR.cjs +0 -66
  623. package/dist/agent-session-store-6EL5NPA4.cjs +0 -24
  624. package/dist/agent-session-store-OPGRB4XM.js +0 -7
  625. package/dist/batch-BXYTW2DP.cjs.map +0 -1
  626. package/dist/batch-L4ZXS46M.js.map +0 -1
  627. package/dist/chunk-25BD2R5G.js.map +0 -1
  628. package/dist/chunk-2D34UTDC.js.map +0 -1
  629. package/dist/chunk-2GUYQR5P.js.map +0 -1
  630. package/dist/chunk-2QDYBS2A.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-4FFBAUFS.js.map +0 -1
  635. package/dist/chunk-4O5TGQBW.cjs.map +0 -1
  636. package/dist/chunk-4OTIXDMU.cjs.map +0 -1
  637. package/dist/chunk-4PYZ5AX3.cjs.map +0 -1
  638. package/dist/chunk-4QZSA2HJ.js.map +0 -1
  639. package/dist/chunk-4ZHTIJNE.cjs.map +0 -1
  640. package/dist/chunk-52NKC5HT.cjs.map +0 -1
  641. package/dist/chunk-6HKGLTJI.cjs.map +0 -1
  642. package/dist/chunk-6JSIEDKL.cjs.map +0 -1
  643. package/dist/chunk-7AD3ZTZL.js.map +0 -1
  644. package/dist/chunk-7BG5UH3T.cjs.map +0 -1
  645. package/dist/chunk-7YGCPMGB.js.map +0 -1
  646. package/dist/chunk-A46SWMIF.js.map +0 -1
  647. package/dist/chunk-A4JVILQU.js.map +0 -1
  648. package/dist/chunk-ACDLHN3W.js.map +0 -1
  649. package/dist/chunk-AQO3NSRG.cjs +0 -41
  650. package/dist/chunk-AQO3NSRG.cjs.map +0 -1
  651. package/dist/chunk-AWO27VRZ.js.map +0 -1
  652. package/dist/chunk-B2J4ZMZL.cjs.map +0 -1
  653. package/dist/chunk-B4EOJWOY.cjs.map +0 -1
  654. package/dist/chunk-BU4KFWXF.js.map +0 -1
  655. package/dist/chunk-BZRFXJHA.js.map +0 -1
  656. package/dist/chunk-C3NT3PVE.js.map +0 -1
  657. package/dist/chunk-C72AZW7J.js.map +0 -1
  658. package/dist/chunk-CQBXOJ6U.cjs.map +0 -1
  659. package/dist/chunk-D4CUGAKZ.js.map +0 -1
  660. package/dist/chunk-DN2PACRI.js.map +0 -1
  661. package/dist/chunk-DXGZ2NUG.cjs.map +0 -1
  662. package/dist/chunk-EG4QM7ZJ.cjs +0 -39
  663. package/dist/chunk-EG4QM7ZJ.cjs.map +0 -1
  664. package/dist/chunk-GPKAF7SG.js.map +0 -1
  665. package/dist/chunk-HCZD23VS.cjs.map +0 -1
  666. package/dist/chunk-HS7AVXTF.js.map +0 -1
  667. package/dist/chunk-IAHZCGBE.cjs.map +0 -1
  668. package/dist/chunk-J24VJOH3.cjs.map +0 -1
  669. package/dist/chunk-JJ3OVRUM.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-K5OJUYSZ.js.map +0 -1
  673. package/dist/chunk-KQ7TS7WW.cjs.map +0 -1
  674. package/dist/chunk-KQRW2GPZ.js.map +0 -1
  675. package/dist/chunk-KYAJINUI.cjs.map +0 -1
  676. package/dist/chunk-L3MTL4NA.js.map +0 -1
  677. package/dist/chunk-L4BDVXIM.js.map +0 -1
  678. package/dist/chunk-LXI4XZEC.js.map +0 -1
  679. package/dist/chunk-LYRDF5TQ.cjs.map +0 -1
  680. package/dist/chunk-N2U4AZGB.js.map +0 -1
  681. package/dist/chunk-O7DK5PBJ.cjs.map +0 -1
  682. package/dist/chunk-O7LZFG6O.cjs.map +0 -1
  683. package/dist/chunk-OFRFZRQ4.cjs.map +0 -1
  684. package/dist/chunk-OSEG74VJ.js.map +0 -1
  685. package/dist/chunk-RFMBZPOW.cjs.map +0 -1
  686. package/dist/chunk-RFXWMRFC.js.map +0 -1
  687. package/dist/chunk-RIAM53CP.js.map +0 -1
  688. package/dist/chunk-RMWTPV3M.cjs.map +0 -1
  689. package/dist/chunk-RNB4APBZ.js.map +0 -1
  690. package/dist/chunk-SAVIWMZB.js.map +0 -1
  691. package/dist/chunk-SZVR77EJ.cjs.map +0 -1
  692. package/dist/chunk-TAZVKYWJ.js.map +0 -1
  693. package/dist/chunk-U54XCYG3.js.map +0 -1
  694. package/dist/chunk-U6IFHFWK.js.map +0 -1
  695. package/dist/chunk-UALX2J2Q.cjs.map +0 -1
  696. package/dist/chunk-UBDMVMBZ.js.map +0 -1
  697. package/dist/chunk-UFLD2HEV.js +0 -35
  698. package/dist/chunk-UFLD2HEV.js.map +0 -1
  699. package/dist/chunk-UGT7GK7I.cjs.map +0 -1
  700. package/dist/chunk-UNYXQ4M5.js.map +0 -1
  701. package/dist/chunk-UTSRIDKZ.js.map +0 -1
  702. package/dist/chunk-UU36SHFY.cjs.map +0 -1
  703. package/dist/chunk-V2BOS4WF.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-ZCIRZE37.cjs.map +0 -1
  718. package/dist/chunk-ZSWPZ23K.cjs.map +0 -1
  719. package/dist/chunk-ZWRG4NWT.cjs.map +0 -1
  720. package/dist/chunk-ZZMZWBR6.js.map +0 -1
  721. package/dist/compact-session-QV57KR66.cjs +0 -59
  722. package/dist/compact-session-RIGOWC4Y.js +0 -22
  723. package/dist/context-AGQ3DIZU.cjs +0 -24
  724. package/dist/context-GQRFBCLP.js +0 -7
  725. package/dist/executor-6CYCA7MI.cjs.map +0 -1
  726. package/dist/executor-QSEC3MRH.js.map +0 -1
  727. package/dist/fork-agent-RSV4E3EA.js.map +0 -1
  728. package/dist/fork-agent-Y2IK2RYU.cjs.map +0 -1
  729. package/dist/fs-session-store-4PIHT5UX.cjs +0 -20
  730. package/dist/fs-session-store-NM6YSTE2.js +0 -11
  731. package/dist/generate-object-GUNAUVBX.js +0 -8
  732. package/dist/generate-object-R7HTMW7F.cjs +0 -21
  733. package/dist/index-manager-2SRX45WJ.cjs +0 -27
  734. package/dist/index-manager-SP4ISSDX.js +0 -18
  735. package/dist/inject-session-WQKMC3GR.cjs +0 -29
  736. package/dist/internal/persistence/credential-pool-store.d.cts +0 -32
  737. package/dist/internal/persistence/credential-pool-store.d.ts +0 -32
  738. package/dist/internal/runtime/memory/memory-path-selector.d.ts +0 -73
  739. package/dist/judge-call-LAHMBJ57.cjs +0 -23
  740. package/dist/judge-call-LVXABPS3.js +0 -6
  741. package/dist/oauth-transaction-store-BT4GLTLK.cjs +0 -36
  742. package/dist/oauth-transaction-store-W52KVHQ4.js +0 -3
  743. package/dist/registry-75W33OGL.js +0 -10
  744. package/dist/registry-V7BDQ6QB.cjs +0 -47
  745. package/dist/run-until-HEQOUVU6.js.map +0 -1
  746. package/dist/run-until-U2B5FJJI.cjs.map +0 -1
  747. package/dist/server/adapter/express.d.cts +0 -9
  748. package/dist/server/adapter/express.d.ts +0 -9
  749. package/dist/server/adapter/fastify.d.cts +0 -9
  750. package/dist/server/adapter/fastify.d.ts +0 -9
  751. package/dist/server/adapter/hono.d.cts +0 -9
  752. package/dist/server/adapter/hono.d.ts +0 -9
  753. package/dist/server/adapter/shared-handler.d.cts +0 -9
  754. package/dist/server/adapter/shared-handler.d.ts +0 -9
  755. package/dist/server/adapter/types.d.cts +0 -33
  756. package/dist/server/adapter/types.d.ts +0 -33
  757. package/dist/session-transcript-6WNITKRE.cjs +0 -63
  758. package/dist/session-transcript-XAEKW6P7.js +0 -6
  759. package/dist/stream-object-UF4QRQRU.js +0 -8
  760. package/dist/stream-object-ZJTQNKY3.cjs +0 -21
  761. package/dist/subagents-loader-CRT5LLL3.js +0 -8
  762. package/dist/subagents-loader-YEUFFPAL.cjs +0 -17
  763. /package/dist/{batch.d.ts → internal/agent/batch.d.ts} +0 -0
  764. /package/dist/{agent-helpers.d.ts → internal/agent/helpers.d.ts} +0 -0
  765. /package/dist/internal/agent-loop/{loop-types.d.ts → types.d.ts} +0 -0
  766. /package/dist/internal/auth/{auth-types.d.ts → types.d.ts} +0 -0
  767. /package/dist/internal/cloud-agent/{cloud-payload-types.d.ts → types.d.ts} +0 -0
  768. /package/dist/internal/{runtime/concurrency → concurrency}/abort-utils.d.ts +0 -0
  769. /package/dist/internal/{runtime/concurrency → concurrency}/async-local-storage.d.ts +0 -0
  770. /package/dist/internal/{runtime/concurrency → concurrency}/async-semaphore.d.ts +0 -0
  771. /package/dist/internal/{runtime/concurrency → concurrency}/delegation-depth.d.ts +0 -0
  772. /package/dist/internal/{runtime/concurrency → concurrency}/map-with-concurrency.d.ts +0 -0
  773. /package/dist/internal/{runtime/retry → error-mappers}/default-retriable.d.ts +0 -0
  774. /package/dist/internal/{runtime/fixtures/fixture-types.d.ts → memory/storage/list-markdown.d.cts} +0 -0
  775. /package/dist/internal/{runtime/plugins/plugins-manager.d.ts → memory/storage/list-markdown.d.ts} +0 -0
  776. /package/dist/internal/{resilience → retry}/circuit-breaker.d.ts +0 -0
  777. /package/dist/internal/{runtime/retry → retry}/with-retry.d.ts +0 -0
  778. /package/dist/internal/{security/secret-redactor.d.cts → runtime/fixtures/types.d.ts} +0 -0
  779. /package/dist/internal/runtime/{memory → memory-glue}/memory-store.d.ts +0 -0
  780. /package/dist/internal/runtime/{memory → memory-glue}/select-facts.d.ts +0 -0
  781. /package/dist/internal/runtime/{plugins → plugin-loader}/plugin-frontmatter.d.ts +0 -0
  782. /package/dist/internal/{security/secret-redactor.d.ts → runtime/plugin-loader/plugins-manager.d.ts} +0 -0
  783. /package/dist/internal/runtime/{reasoning → system-prompt}/native-reasoning.d.ts +0 -0
  784. /package/dist/internal/{runtime/context/path-containment.d.ts → security/path-containment.d.cts} +0 -0
  785. /package/dist/internal/session/{session-types.d.ts → types.d.ts} +0 -0
  786. /package/dist/internal/{zod/to-json-schema.d.ts → zod-to-json-schema.d.ts} +0 -0
  787. /package/dist/subscription/internal/{adapter-types.d.cts → types.d.cts} +0 -0
  788. /package/dist/subscription/internal/{adapter-types.d.ts → types.d.ts} +0 -0
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/subscription/define-subscription.ts","../../src/subscription/internal/sse-parser.ts","../../src/subscription/types.ts","../../src/subscription/theokit-subscribe.ts"],"names":[],"mappings":";;;;;AAoEO,SAAS,mBACd,IAAA,EACyC;AACzC,EAAA,IAAI,IAAA,KAAS,IAAA,IAAQ,OAAO,IAAA,KAAS,QAAA,EAAU;AAC7C,IAAA,MAAM,IAAI,UAAU,gDAAgD,CAAA;AAAA,EACtE;AACA,EAAA,IAAI,KAAK,KAAA,KAAU,MAAA,IAAa,OAAO,IAAA,CAAK,KAAA,CAAM,cAAc,UAAA,EAAY;AAC1E,IAAA,MAAM,IAAI,UAAU,kEAAkE,CAAA;AA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AM,MAAM,CAAA;AAAA,EAC3D,CAAC,CAAA;AACH","file":"index.js","sourcesContent":["/**\n * `defineSubscription` DSL (G8 public API) — `@theokit/sdk`.\n *\n * Per ADR D426 (AsyncGenerator handler + Zod input/output schemas).\n *\n * @public\n */\n\nimport type { SubscriptionCtx, SubscriptionDescriptor, TrackedEnvelope, ZodLike } from \"./types.js\";\n\n/**\n * Options accepted by {@link defineSubscription}.\n *\n * @public\n */\nexport interface DefineSubscriptionOptions<TInput, TOutput> {\n /** Optional explicit name. Falls back to filename derivation by the scanner. */\n name?: string;\n /** Zod schema validating subscription input. Required (typed RPC contract). */\n input: ZodLike<TInput>;\n /** Zod schema describing each output frame. Informational; not enforced per-frame. */\n output: ZodLike<TOutput>;\n /**\n * Handler that produces the subscription stream.\n *\n * Receives the validated input + {@link SubscriptionCtx}. Yielding a value\n * emits a plain output frame. Yielding a `tracked(id, payload)` envelope\n * additionally advertises a resume token to the client so reconnects can\n * resume from that point.\n */\n handler: (\n input: TInput,\n ctx: SubscriptionCtx,\n ) => AsyncGenerator<TOutput | TrackedEnvelope<TOutput>, void, void>;\n}\n\n/**\n * Define a typed subscription. Pair with `Theokit.subscribe(name, input)`\n * on the client side.\n *\n * Per ADR D426 — handler is `AsyncGenerator<TOutput | TrackedEnvelope<TOutput>>`.\n * The runtime validates input via `opts.input.safeParse` BEFORE invoking the\n * handler; failure throws {@link import('./types.js').SubscriptionInputError}.\n *\n * @example\n * ```ts\n * import { Subscription } from \"@theokit/sdk/subscription\";\n * import { z } from \"zod\";\n *\n * export default Subscription.create({\n * input: z.object({ topic: z.string() }),\n * output: z.object({ message: z.string(), ts: z.number() }),\n * async *handler(input, ctx) {\n * let cursor = ctx.lastEventId ?? \"0\";\n * while (!ctx.signal.aborted) {\n * const msgs = await fetchMessagesSince(input.topic, cursor);\n * for (const m of msgs) {\n * cursor = m.id;\n * yield ctx.tracked(m.id, { message: m.body, ts: m.ts });\n * }\n * await sleep(1000);\n * }\n * },\n * });\n * ```\n *\n * @public\n */\nexport function defineSubscription<TInput, TOutput>(\n opts: DefineSubscriptionOptions<TInput, TOutput>,\n): SubscriptionDescriptor<TInput, TOutput> {\n if (opts === null || typeof opts !== \"object\") {\n throw new TypeError(\"defineSubscription: options object is required\");\n }\n if (opts.input === undefined || typeof opts.input.safeParse !== \"function\") {\n throw new TypeError(\"defineSubscription: opts.input must be a Zod schema (or ZodLike)\");\n }\n if (opts.output === undefined || typeof opts.output.safeParse !== \"function\") {\n throw new TypeError(\"defineSubscription: opts.output must be a Zod schema (or ZodLike)\");\n }\n if (typeof opts.handler !== \"function\") {\n throw new TypeError(\"defineSubscription: opts.handler must be an async generator function\");\n }\n return {\n ...(opts.name !== undefined ? { name: opts.name } : {}),\n input: opts.input,\n output: opts.output,\n handler: opts.handler,\n };\n}\n\n/** SE36 — `Subscription.create` replaces `defineSubscription` (ADR 0015). @public */\nexport class Subscription {\n private constructor() {}\n static create<TInput, TOutput>(\n opts: DefineSubscriptionOptions<TInput, TOutput>,\n ): SubscriptionDescriptor<TInput, TOutput> {\n return defineSubscription(opts);\n }\n}\n","/**\n * W3C SSE parser (G8 internal) — `@theokit/sdk`.\n *\n * Per ADR D428. Reads from `ReadableStream<Uint8Array>` or async iterable of\n * UTF-8 chunks; yields parsed {@link SSEvent} objects per W3C SSE spec.\n *\n * Independent of `internal/llm/sse.ts:parseSseStream` (LLM-specific a peer vendor AI\n * Data Stream v1; locked by D38). This parser handles the `id:` field needed\n * for tracked envelopes (G8 resume mechanism), which the LLM parser ignores.\n *\n * Reference: https://html.spec.whatwg.org/multipage/server-sent-events.html\n *\n * @internal\n */\n\nimport type { SSEvent } from \"./sse-encoder.js\";\n\nconst decoder = new TextDecoder(\"utf-8\");\n\n/**\n * Parse an async iterable of UTF-8 byte chunks into a stream of SSE events.\n *\n * Implements the W3C event stream parser:\n * - Lines are split by `\\n`, `\\r\\n`, or `\\r`\n * - Events are dispatched on blank line (no `:` and no field name)\n * - Fields: `event`, `data` (multi-line concat with `\\n`), `id`, `retry`\n * - Lines starting with `:` are comments (ignored, except dispatched as `comment`)\n * - Unknown fields silently ignored per spec\n *\n * Empty events (no fields) are NOT dispatched per spec.\n *\n * @internal\n */\nexport async function* parseSseW3C(\n source: AsyncIterable<Uint8Array>,\n): AsyncGenerator<SSEvent, void, void> {\n let buffer = \"\";\n let eventName: string | undefined;\n let dataLines: string[] = [];\n let id: string | undefined;\n let retry: number | undefined;\n let commentLines: string[] = [];\n let hasField = false;\n\n // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: dispatch builds SSEvent from per-field state per W3C spec — refactor candidate\n const dispatch = (): SSEvent | null => {\n if (!hasField) {\n // Blank line with no preceding fields → reset state, no dispatch (per spec § 9.2.6)\n eventName = undefined;\n dataLines = [];\n id = undefined;\n retry = undefined;\n commentLines = [];\n return null;\n }\n const chunk: SSEvent = {};\n if (eventName !== undefined) (chunk as { event?: string }).event = eventName;\n if (dataLines.length > 0) (chunk as { data?: string }).data = dataLines.join(\"\\n\");\n if (id !== undefined) (chunk as { id?: string }).id = id;\n if (retry !== undefined) (chunk as { retry?: number }).retry = retry;\n if (commentLines.length > 0) (chunk as { comment?: string }).comment = commentLines.join(\"\\n\");\n eventName = undefined;\n dataLines = [];\n id = undefined;\n retry = undefined;\n commentLines = [];\n hasField = false;\n return chunk;\n };\n\n // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: handleLine dispatches across all SSE field kinds per W3C spec — refactor candidate\n const handleLine = (line: string): SSEvent | null => {\n if (line === \"\") {\n return dispatch();\n }\n if (line.startsWith(\":\")) {\n // Comment line — per spec ignored, but we surface it for keepalive visibility.\n commentLines.push(line.slice(1).replace(/^ /, \"\"));\n hasField = true;\n return null;\n }\n const colonIdx = line.indexOf(\":\");\n let field: string;\n let value: string;\n if (colonIdx === -1) {\n field = line;\n value = \"\";\n } else {\n field = line.slice(0, colonIdx);\n value = line.slice(colonIdx + 1);\n // Strip ONE leading space if present (per spec § 9.2.6)\n if (value.startsWith(\" \")) value = value.slice(1);\n }\n switch (field) {\n case \"event\":\n eventName = value;\n hasField = true;\n break;\n case \"data\":\n dataLines.push(value);\n hasField = true;\n break;\n case \"id\":\n // Per spec: id with NULL is ignored\n if (!value.includes(\"\\0\")) {\n id = value;\n hasField = true;\n }\n break;\n case \"retry\":\n if (/^\\d+$/.test(value)) {\n retry = Number.parseInt(value, 10);\n hasField = true;\n }\n break;\n default:\n // Unknown field — ignored per spec\n break;\n }\n return null;\n };\n\n for await (const bytes of source) {\n // Normalize CRLF / CR to LF then split\n buffer += decoder.decode(bytes, { stream: true }).replace(/\\r\\n|\\r/g, \"\\n\");\n let idx: number;\n // biome-ignore lint/suspicious/noAssignInExpressions: idiomatic while-assignment loop for buffered line parsing\n while ((idx = buffer.indexOf(\"\\n\")) !== -1) {\n const line = buffer.slice(0, idx);\n buffer = buffer.slice(idx + 1);\n const event = handleLine(line);\n if (event !== null) yield event;\n }\n }\n // Flush remaining buffer as a final line (no trailing newline case)\n buffer += decoder.decode();\n if (buffer.length > 0) {\n const event = handleLine(buffer);\n if (event !== null) yield event;\n }\n // Final dispatch in case last event lacked terminating blank line\n const tail = dispatch();\n if (tail !== null) yield tail;\n}\n","/**\n * Subscription type contract (G8 v1.7.0) — `@theokit/sdk`.\n *\n * Per ADRs D423 (resume token opaque), D424 (transport selection),\n * D426 (defineSubscription DSL shape).\n *\n * @public\n */\n\nimport { TheokitAgentError } from \"../errors.js\";\n\n/**\n * Transport selection for subscriptions.\n *\n * - `'ws'`: WebSocket (bidirectional). Required for inbound client→server frames.\n * v1.7 ships Node-canonical `ws` adapter; CF/Bun/Deno deferred to v1.8.x per ADR D425.\n * - `'sse'`: W3C Server-Sent Events (server→client only). Browser-native EventSource.\n * - `'auto'`: Prefer WS, fall back SSE on upgrade failure. Default.\n *\n * @public\n */\nexport type SubscriptionTransport = \"ws\" | \"sse\" | \"auto\";\n\n/**\n * Context passed to a subscription `handler` on each invocation.\n *\n * @public\n */\nexport interface SubscriptionCtx {\n /**\n * Opaque resume token forwarded by the client when reconnecting.\n * Handler defines its own semantics (monotonic int, ULID, timestamp,\n * encrypted cursor). SDK passes through unchanged. Per ADR D423.\n */\n readonly lastEventId?: string;\n\n /**\n * AbortSignal that fires when the subscription is cancelled\n * (client disconnect, consumer abort, server shutdown).\n * Handler MUST honor `signal.aborted` in long-running loops.\n */\n readonly signal: AbortSignal;\n\n /**\n * Stable identifier for the underlying transport connection.\n * Different from the subscription name — one connection may host\n * many subscriptions. Useful for logging / per-connection state.\n */\n readonly connectionId: string;\n\n /**\n * Force-close the underlying transport with optional WS close code + reason.\n * Used by consumer code (e.g., auth middleware revoking a session) to\n * terminate a subscription that should not continue.\n */\n disconnect(code?: number, reason?: string): void;\n\n /**\n * Helper to mint a tracked envelope `[id, payload]`.\n * Yielding tracked envelopes lets the client advance `lastEventId`\n * so reconnects can resume from that point.\n */\n tracked<TPayload>(id: string, payload: TPayload): TrackedEnvelope<TPayload>;\n}\n\n/**\n * Tracked envelope: `[id, payload]` tuple yielded by subscription handlers\n * to advertise the resume token associated with the payload.\n *\n * The encoder writes the `id` as an SSE `id:` field or WS payload metadata\n * so the client can echo it back on reconnect (`input.lastEventId`).\n *\n * Per ADR D423.\n *\n * @public\n */\nexport type TrackedEnvelope<T> = readonly [id: string, payload: T];\n\n/**\n * Type guard for {@link TrackedEnvelope}.\n *\n * @public\n */\nexport function isTrackedEnvelope(value: unknown): value is TrackedEnvelope<unknown> {\n return Array.isArray(value) && value.length === 2 && typeof value[0] === \"string\";\n}\n\n/**\n * Mint a tracked envelope. Equivalent to `[id, payload] as const`,\n * exported as a function so consumers don't repeat the tuple cast.\n *\n * @public\n */\nexport function tracked<T>(id: string, payload: T): TrackedEnvelope<T> {\n if (typeof id !== \"string\" || id.length === 0) {\n throw new TypeError(\"tracked(): id must be a non-empty string\");\n }\n return [id, payload] as const;\n}\n\n/**\n * Base error for the subscription subsystem. Extends {@link TheokitAgentError}\n * so existing `instanceof TheokitAgentError` branches keep working.\n *\n * @public\n */\nexport class SubscriptionError extends TheokitAgentError {\n override readonly name: string = \"SubscriptionError\";\n\n constructor(message: string, options: { code?: string; cause?: unknown } = {}) {\n super(message, { ...options, isRetryable: false });\n }\n}\n\n/**\n * Thrown when subscription input fails Zod schema validation.\n *\n * @public\n */\nexport class SubscriptionInputError extends SubscriptionError {\n override readonly name: string = \"SubscriptionInputError\";\n\n readonly issues: unknown;\n\n constructor(message: string, options: { issues: unknown; cause?: unknown }) {\n super(message, { code: \"subscription_input_invalid\", cause: options.cause });\n this.issues = options.issues;\n }\n}\n\n/**\n * Thrown when a subscription transport disconnects unexpectedly\n * AND the client did not opt out of reconnect.\n *\n * @public\n */\nexport class SubscriptionDisconnectError extends SubscriptionError {\n override readonly name: string = \"SubscriptionDisconnectError\";\n\n readonly closeCode?: number;\n readonly closeReason?: string;\n\n constructor(\n message: string,\n options: { closeCode?: number; closeReason?: string; cause?: unknown } = {},\n ) {\n super(message, { code: \"subscription_disconnected\", cause: options.cause });\n if (options.closeCode !== undefined) this.closeCode = options.closeCode;\n if (options.closeReason !== undefined) this.closeReason = options.closeReason;\n }\n}\n\n/**\n * Descriptor returned by {@link Subscription.create}. Carries the typed\n * input/output Zod schemas + handler factory.\n *\n * @public\n */\nexport interface SubscriptionDescriptor<TInput = unknown, TOutput = unknown> {\n /** Optional explicit name; the runtime may also derive name from file path. */\n readonly name?: string;\n /** Zod schema for the subscription input. Validated at dispatch boundary. */\n readonly input: ZodLike<TInput>;\n /** Zod schema for each output frame (informational; not enforced per-frame). */\n readonly output: ZodLike<TOutput>;\n /** Async handler that yields output frames (or tracked envelopes). */\n readonly handler: (\n input: TInput,\n ctx: SubscriptionCtx,\n ) => AsyncGenerator<TOutput | TrackedEnvelope<TOutput>, void, void>;\n}\n\n/**\n * Minimal structural Zod type used to avoid hard peer-dep import.\n * Mirrors the surface used by other SDK modules (e.g., `define-tool.ts`).\n *\n * Emitted rather than erased: it appears in the signature of `defineSubscription`, which\n * `@theokit/sdk/subscription` publishes, so a consumer's type-aware lint has to be able to\n * resolve it.\n */\nexport interface ZodLike<T> {\n safeParse(value: unknown): { success: true; data: T } | { success: false; error: unknown };\n parse(value: unknown): T;\n}\n","/**\n * `Theokit.subscribe` client (G8 public API) — `@theokit/sdk`.\n *\n * Per ADR D427 (Theokit.subscribe namespace) + D424 (transport selection)\n * + D423 (lastEventId opaque propagation).\n *\n * Returns an AsyncGenerator that yields server-sent values. Transparent\n * reconnect with exponential backoff. Propagates `lastEventId` from the last\n * received tracked envelope on each reconnect attempt.\n *\n * @public\n */\n\nimport { parseSseW3C } from \"./internal/sse-parser.js\";\nimport type { WireFrame } from \"./internal/subscription-runtime.js\";\nimport {\n SubscriptionDisconnectError,\n SubscriptionError,\n type SubscriptionTransport,\n} from \"./types.js\";\n\n/**\n * Options accepted by `Theokit.subscribe(name, input, opts?)`.\n *\n * @public\n */\nexport interface SubscribeOptions {\n /** Base URL of the server (e.g., `\"http://localhost:3000\"`). Required. */\n baseUrl: string;\n /** Preferred transport. Default `\"auto\"` (WS preferred, SSE fallback). */\n transport?: SubscriptionTransport;\n /** Max reconnect attempts (default 10). 0 disables reconnect. */\n maxReconnectAttempts?: number;\n /** Backoff strategy. Default exponential `min(30_000, 1000 * 2^attempt)` ms. */\n retryDelayMs?: (attempt: number) => number;\n /** Caller-supplied abort signal. Cancels the subscription entirely. */\n signal?: AbortSignal;\n /** Additional fetch-style headers (e.g., `Authorization`). */\n headers?: Record<string, string>;\n /**\n * Override the SSE transport's `fetch`. Defaults to `globalThis.fetch`.\n * Lets a consumer supply a proxying agent or instrumented fetch without\n * mutating the runtime global.\n */\n fetch?: typeof globalThis.fetch;\n /**\n * Override the WS transport's `WebSocket` constructor. Defaults to\n * `globalThis.WebSocket`. Lets a consumer polyfill WS on a runtime that\n * lacks it, or supply an instrumented implementation, without mutating\n * the runtime global.\n */\n WebSocket?: typeof WebSocket;\n}\n\nconst defaultRetry = (attempt: number) => Math.min(30_000, 1000 * 2 ** attempt);\n\n/**\n * Subscribe to a typed subscription. Yields values produced by the server\n * handler. On disconnect with reconnect enabled, transparently re-establishes\n * the connection and forwards `lastEventId` from the last received tracked\n * envelope so the server handler can resume.\n *\n * @public\n */\n// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: G8 subscribe orchestrates reconnect + transport switch + resume — refactor candidate tracked in subscription/theokit-subscribe.ts:52 followup\nexport async function* subscribe<TInput, TOutput>(\n name: string,\n input: TInput,\n opts: SubscribeOptions,\n): AsyncGenerator<TOutput, void, void> {\n if (typeof name !== \"string\" || name.length === 0) {\n throw new SubscriptionError(\"Theokit.subscribe: name must be a non-empty string\", {\n code: \"subscribe_name_invalid\",\n });\n }\n if (opts === null || typeof opts !== \"object\" || typeof opts.baseUrl !== \"string\") {\n throw new SubscriptionError(\"Theokit.subscribe: opts.baseUrl is required\", {\n code: \"subscribe_baseUrl_missing\",\n });\n }\n const transport = opts.transport ?? \"auto\";\n const maxReconnects = opts.maxReconnectAttempts ?? 10;\n const retry = opts.retryDelayMs ?? defaultRetry;\n\n let lastEventId: string | undefined;\n let attempt = 0;\n\n while (true) {\n if (opts.signal?.aborted) return;\n try {\n const inputWithCursor = mergeLastEventId(input, lastEventId);\n const chosen = await selectTransport(transport, name, opts);\n if (chosen === \"ws\") {\n for await (const out of openWs<TOutput>(name, inputWithCursor, opts)) {\n if (out.lastEventId !== undefined) lastEventId = out.lastEventId;\n attempt = 0; // reset backoff on successful frame\n yield out.value;\n }\n } else {\n for await (const out of openSse<TOutput>(name, inputWithCursor, opts)) {\n if (out.lastEventId !== undefined) lastEventId = out.lastEventId;\n attempt = 0;\n yield out.value;\n }\n }\n // Clean end-of-stream — no reconnect.\n return;\n } catch (cause) {\n if (opts.signal?.aborted) return;\n if (maxReconnects === 0 || attempt >= maxReconnects) {\n if (cause instanceof SubscriptionError) throw cause;\n throw new SubscriptionDisconnectError(\n `subscription \"${name}\" disconnected; reconnect exhausted`,\n { cause },\n );\n }\n const delay = retry(attempt);\n attempt++;\n await sleep(delay, opts.signal);\n }\n }\n}\n\ninterface FrameOut<T> {\n readonly value: T;\n readonly lastEventId?: string;\n}\n\n// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: openSse parses framed SSE stream with abort/error/retry branches — refactor candidate\nasync function* openSse<T>(\n name: string,\n input: unknown,\n opts: SubscribeOptions,\n): AsyncIterable<FrameOut<T>> {\n const url = `${stripTrailingSlash(opts.baseUrl)}/api/subscriptions/${encodeURIComponent(name)}?input=${encodeURIComponent(JSON.stringify(input))}`;\n const fetchFn = opts.fetch ?? globalThis.fetch;\n const res = await fetchFn(url, {\n method: \"GET\",\n headers: {\n accept: \"text/event-stream\",\n ...(opts.headers ?? {}),\n },\n ...(opts.signal !== undefined ? { signal: opts.signal } : {}),\n });\n if (!res.ok || res.body === null) {\n throw new SubscriptionError(`SSE subscribe failed: HTTP ${res.status} ${res.statusText}`, {\n code: \"sse_http_error\",\n });\n }\n const events = parseSseW3C(streamToAsyncIterable(res.body));\n for await (const ev of events) {\n if (ev.event === \"end\") return;\n if (ev.event === \"error\") {\n throw new SubscriptionError(`SSE server emitted error: ${ev.data ?? \"(no body)\"}`, {\n code: \"sse_server_error\",\n });\n }\n if (ev.event === \"connected\") continue;\n if (ev.data === undefined) continue;\n const parsedValue = safeJsonParse<T>(ev.data);\n if (parsedValue === undefined) continue;\n yield {\n value: parsedValue,\n ...(ev.id !== undefined ? { lastEventId: ev.id } : {}),\n };\n }\n}\n\n// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: openWs orchestrates WS lifecycle + envelope decode + cleanup — refactor candidate\nasync function* openWs<T>(\n name: string,\n input: unknown,\n opts: SubscribeOptions,\n): AsyncIterable<FrameOut<T>> {\n const baseUrl = stripTrailingSlash(opts.baseUrl);\n const wsUrl = baseUrl\n .replace(/^http:/, \"ws:\")\n .replace(/^https:/, \"wss:\")\n .concat(\"/api/ws\");\n\n const WS = opts.WebSocket ?? (globalThis as { WebSocket?: typeof WebSocket }).WebSocket;\n if (WS === undefined) {\n throw new SubscriptionError(\n \"Theokit.subscribe(transport='ws'): no global WebSocket available. Use Node >=22 or install 'ws' as a runtime dep + assign to globalThis.WebSocket, or pass opts.WebSocket.\",\n { code: \"ws_global_missing\" },\n );\n }\n const ws = new WS(wsUrl);\n\n // Set up async iterator-like state.\n const incoming: WireFrame[] = [];\n // biome-ignore lint/suspicious/noConfusingVoidType: idiomatic event-callback signature; refactoring to undefined would mask the no-value semantics\n let waiter: ((value: void) => void) | null = null;\n let closed = false;\n let closeError: Error | undefined;\n\n ws.addEventListener(\"message\", (ev: MessageEvent) => {\n const data = typeof ev.data === \"string\" ? ev.data : \"\";\n const frame = safeJsonParse<WireFrame>(data);\n if (frame !== undefined) {\n incoming.push(frame);\n if (waiter !== null) {\n waiter();\n waiter = null;\n }\n }\n });\n ws.addEventListener(\"close\", () => {\n closed = true;\n if (waiter !== null) {\n waiter();\n waiter = null;\n }\n });\n ws.addEventListener(\"error\", () => {\n closed = true;\n closeError = new Error(\"WebSocket error\");\n if (waiter !== null) {\n waiter();\n waiter = null;\n }\n });\n\n await new Promise<void>((resolve, reject) => {\n ws.addEventListener(\"open\", () => resolve(), { once: true });\n ws.addEventListener(\"error\", () => reject(new Error(\"WS connect failed\")), { once: true });\n });\n\n // Send subscribe request after handshake.\n ws.send(JSON.stringify({ kind: \"subscribe\", name, input }));\n\n if (opts.signal !== undefined) {\n opts.signal.addEventListener(\"abort\", () => ws.close(), { once: true });\n }\n\n try {\n while (true) {\n if (incoming.length === 0) {\n if (closed) {\n if (closeError !== undefined) throw closeError;\n return;\n }\n await new Promise<void>((resolve) => {\n waiter = resolve;\n });\n continue;\n }\n const frame = incoming.shift() as WireFrame;\n if (frame.type === \"end\") return;\n if (frame.type === \"error\") {\n throw new SubscriptionError(\n `WS server emitted error: ${frame.error?.message ?? \"(unknown)\"}`,\n { code: \"ws_server_error\" },\n );\n }\n const value = frame.data as T;\n yield {\n value,\n ...(frame.id !== undefined ? { lastEventId: frame.id } : {}),\n };\n }\n } finally {\n try {\n ws.close();\n } catch {\n /* ignore */\n }\n }\n}\n\nasync function selectTransport(\n pref: SubscriptionTransport,\n _name: string,\n opts: SubscribeOptions,\n): Promise<\"ws\" | \"sse\"> {\n if (pref === \"ws\") return \"ws\";\n if (pref === \"sse\") return \"sse\";\n // auto — prefer WS if available (injected or global), else SSE.\n const WS = opts.WebSocket ?? (globalThis as { WebSocket?: unknown }).WebSocket;\n if (typeof WS === \"function\") {\n return \"ws\";\n }\n return \"sse\";\n}\n\nfunction mergeLastEventId(input: unknown, lastEventId: string | undefined): unknown {\n if (lastEventId === undefined) return input;\n if (input === null || typeof input !== \"object\" || Array.isArray(input)) {\n // Cannot merge into primitive — return as-is.\n return input;\n }\n return { ...(input as object), lastEventId };\n}\n\nfunction stripTrailingSlash(s: string): string {\n return s.endsWith(\"/\") ? s.slice(0, -1) : s;\n}\n\nfunction safeJsonParse<T>(s: string): T | undefined {\n try {\n return JSON.parse(s) as T;\n } catch {\n return undefined;\n }\n}\n\nasync function* streamToAsyncIterable(\n stream: ReadableStream<Uint8Array>,\n): AsyncIterable<Uint8Array> {\n const reader = stream.getReader();\n let finishedNaturally = false;\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) {\n finishedNaturally = true;\n return;\n }\n if (value !== undefined) yield value;\n }\n } finally {\n // B-131: `releaseLock()` alone detaches the reader WITHOUT canceling the stream (WHATWG\n // Streams spec) — the underlying `fetch` response body, and its socket, stays open until\n // something else cancels it or reads it to completion. A consumer that breaks out of the\n // subscription mid-stream (the ordinary shape: `for await ... break`) used to leave that\n // connection dangling. `cancel()` is a no-op once the stream is already closed, so it is safe\n // to call unconditionally on the early-exit path; skip it on natural completion, where the\n // stream is already done and canceling only risks surfacing a spurious rejection.\n if (!finishedNaturally) {\n try {\n await reader.cancel();\n } catch {\n /* best-effort cleanup — the caller's own error (if any) already takes precedence */\n }\n }\n reader.releaseLock();\n }\n}\n\nfunction sleep(ms: number, signal?: AbortSignal): Promise<void> {\n return new Promise((resolve, reject) => {\n if (signal?.aborted) {\n reject(new Error(\"aborted\"));\n return;\n }\n const t = setTimeout(() => {\n signal?.removeEventListener(\"abort\", onAbort);\n resolve();\n }, ms);\n const onAbort = () => {\n clearTimeout(t);\n reject(new Error(\"aborted\"));\n };\n signal?.addEventListener(\"abort\", onAbort, { once: true });\n });\n}\n"]}
1
+ {"version":3,"sources":["../../src/subscription/define-subscription.ts","../../src/subscription/internal/sse-parser.ts","../../src/subscription/types.ts","../../src/subscription/theokit-subscribe.ts"],"names":[],"mappings":";;;;AAoEO,SAAS,mBACd,IAAA,EACyC;AACzC,EAAA,IAAI,IAAA,KAAS,IAAA,IAAQ,OAAO,IAAA,KAAS,QAAA,EAAU;AAC7C,IAAA,MAAM,IAAI,UAAU,gDAAgD,CAAA;AAAA,EACtE;AACA,EAAA,IAAI,KAAK,KAAA,KAAU,MAAA,IAAa,OAAO,IAAA,CAAK,KAAA,CAAM,cAAc,UAAA,EAAY;AAC1E,IAAA,MAAM,IAAI,UAAU,kEAAkE,CAAA;AAAA,EACxF;AACA,EAAA,IAAI,KAAK,MAAA,KAAW,MAAA,IAAa,OAAO,IAAA,CAAK,MAAA,CAAO,cAAc,UAAA,EAAY;AAC5E,IAAA,MAAM,IAAI,UAAU,mEAAmE,CAAA;AAAA,EACzF;AACA,EAAA,IAAI,OAAO,IAAA,CAAK,OAAA,KAAY,UAAA,EAAY;AACtC,IAAA,MAAM,IAAI,UAAU,sEAAsE,CAAA;AAAA,EAC5F;AACA,EAAA,OAAO;AAAA,IACL,GAAI,KAAK,IAAA,KAAS,MAAA,GAAY,EAAE,IAAA,EAAM,IAAA,CAAK,IAAA,EAAK,GAAI,EAAC;AAAA,IACrD,OAAO,IAAA,CAAK,KAAA;AAAA,IACZ,QAAQ,IAAA,CAAK,MAAA;AAAA,IACb,SAAS,IAAA,CAAK;AAAA,GAChB;AACF;AAMO,IAAM,eAAN,MAAmB;AAAA,EAChB,WAAA,GAAc;AAAA,EAAC;AAAA,EACvB,OAAO,OACL,IAAA,EACyC;AACzC,IA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IAAA,MAAA,CAAO,WAAA,EAAY;AAAA,EACrB;AACF;AAEA,SAAS,KAAA,CAAM,IAAY,MAAA,EAAqC;AAC9D,EAAA,OAAO,IAAI,OAAA,CAAQ,CAAC,OAAA,EAAS,MAAA,KAAW;AACtC,IAAA,IAAI,QAAQ,OAAA,EAAS;AACnB,MAAA,MAAA,CAAO,IAAI,KAAA,CAAM,SAAS,CAAC,CAAA;AAC3B,MAAA;AAAA,IACF;AACA,IAAA,MAAM,CAAA,GAAI,WAAW,MAAM;AACzB,MAAA,MAAA,EAAQ,mBAAA,CAAoB,SAAS,OAAO,CAAA;AAC5C,MAAA,OAAA,EAAQ;AAAA,IACV,GAAG,EAAE,CAAA;AACL,IAAA,MAAM,UAAU,MAAM;AACpB,MAAA,YAAA,CAAa,CAAC,CAAA;AACd,MAAA,MAAA,CAAO,IAAI,KAAA,CAAM,SAAS,CAAC,CAAA;AAAA,IAC7B,CAAA;AACA,IAAA,MAAA,EAAQ,iBAAiB,OAAA,EAAS,OAAA,EAAS,EAAE,IAAA,EAAM,MAAM,CAAA;AAAA,EAC3D,CAAC,CAAA;AACH","file":"index.js","sourcesContent":["/**\n * `defineSubscription` DSL (G8 public API) — `@theokit/sdk`.\n *\n * Per ADR D426 (AsyncGenerator handler + Zod input/output schemas).\n *\n * @public\n */\n\nimport type { SubscriptionCtx, SubscriptionDescriptor, TrackedEnvelope, ZodLike } from \"./types.js\";\n\n/**\n * Options accepted by {@link defineSubscription}.\n *\n * @public\n */\nexport interface DefineSubscriptionOptions<TInput, TOutput> {\n /** Optional explicit name. Falls back to filename derivation by the scanner. */\n name?: string;\n /** Zod schema validating subscription input. Required (typed RPC contract). */\n input: ZodLike<TInput>;\n /** Zod schema describing each output frame. Informational; not enforced per-frame. */\n output: ZodLike<TOutput>;\n /**\n * Handler that produces the subscription stream.\n *\n * Receives the validated input + {@link SubscriptionCtx}. Yielding a value\n * emits a plain output frame. Yielding a `tracked(id, payload)` envelope\n * additionally advertises a resume token to the client so reconnects can\n * resume from that point.\n */\n handler: (\n input: TInput,\n ctx: SubscriptionCtx,\n ) => AsyncGenerator<TOutput | TrackedEnvelope<TOutput>, void, void>;\n}\n\n/**\n * Define a typed subscription. Pair with `Theokit.subscribe(name, input)`\n * on the client side.\n *\n * Per ADR D426 — handler is `AsyncGenerator<TOutput | TrackedEnvelope<TOutput>>`.\n * The runtime validates input via `opts.input.safeParse` BEFORE invoking the\n * handler; failure throws {@link import('./types.js').SubscriptionInputError}.\n *\n * @example\n * ```ts\n * import { Subscription } from \"@theokit/sdk/subscription\";\n * import { z } from \"zod\";\n *\n * export default Subscription.create({\n * input: z.object({ topic: z.string() }),\n * output: z.object({ message: z.string(), ts: z.number() }),\n * async *handler(input, ctx) {\n * let cursor = ctx.lastEventId ?? \"0\";\n * while (!ctx.signal.aborted) {\n * const msgs = await fetchMessagesSince(input.topic, cursor);\n * for (const m of msgs) {\n * cursor = m.id;\n * yield ctx.tracked(m.id, { message: m.body, ts: m.ts });\n * }\n * await sleep(1000);\n * }\n * },\n * });\n * ```\n *\n * @public\n */\nexport function defineSubscription<TInput, TOutput>(\n opts: DefineSubscriptionOptions<TInput, TOutput>,\n): SubscriptionDescriptor<TInput, TOutput> {\n if (opts === null || typeof opts !== \"object\") {\n throw new TypeError(\"defineSubscription: options object is required\");\n }\n if (opts.input === undefined || typeof opts.input.safeParse !== \"function\") {\n throw new TypeError(\"defineSubscription: opts.input must be a Zod schema (or ZodLike)\");\n }\n if (opts.output === undefined || typeof opts.output.safeParse !== \"function\") {\n throw new TypeError(\"defineSubscription: opts.output must be a Zod schema (or ZodLike)\");\n }\n if (typeof opts.handler !== \"function\") {\n throw new TypeError(\"defineSubscription: opts.handler must be an async generator function\");\n }\n return {\n ...(opts.name !== undefined ? { name: opts.name } : {}),\n input: opts.input,\n output: opts.output,\n handler: opts.handler,\n };\n}\n\n/** SE36 — `Subscription.create` replaces `defineSubscription` (ADR 0015). @public *\n * `Subscription.create` returns a **`SubscriptionDescriptor<TInput, TOutput>`**, not a\n * `Subscription`. The class is the namespace; the descriptor is the product.\n */\nexport class Subscription {\n private constructor() {}\n static create<TInput, TOutput>(\n opts: DefineSubscriptionOptions<TInput, TOutput>,\n ): SubscriptionDescriptor<TInput, TOutput> {\n return defineSubscription(opts);\n }\n}\n","/**\n * W3C SSE parser (G8 internal) — `@theokit/sdk`.\n *\n * Per ADR D428. Reads from `ReadableStream<Uint8Array>` or async iterable of\n * UTF-8 chunks; yields parsed {@link SSEvent} objects per W3C SSE spec.\n *\n * Independent of `internal/llm/sse.ts:parseSseStream` (LLM-specific a peer vendor AI\n * Data Stream v1; locked by D38). This parser handles the `id:` field needed\n * for tracked envelopes (G8 resume mechanism), which the LLM parser ignores.\n *\n * Reference: https://html.spec.whatwg.org/multipage/server-sent-events.html\n *\n * @internal\n */\n\nimport type { SSEvent } from \"./sse-encoder.js\";\n\nconst decoder = new TextDecoder(\"utf-8\");\n\n/**\n * Parse an async iterable of UTF-8 byte chunks into a stream of SSE events.\n *\n * Implements the W3C event stream parser:\n * - Lines are split by `\\n`, `\\r\\n`, or `\\r`\n * - Events are dispatched on blank line (no `:` and no field name)\n * - Fields: `event`, `data` (multi-line concat with `\\n`), `id`, `retry`\n * - Lines starting with `:` are comments (ignored, except dispatched as `comment`)\n * - Unknown fields silently ignored per spec\n *\n * Empty events (no fields) are NOT dispatched per spec.\n *\n * @internal\n */\nexport async function* parseSseW3C(\n source: AsyncIterable<Uint8Array>,\n): AsyncGenerator<SSEvent, void, void> {\n let buffer = \"\";\n let eventName: string | undefined;\n let dataLines: string[] = [];\n let id: string | undefined;\n let retry: number | undefined;\n let commentLines: string[] = [];\n let hasField = false;\n\n // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: dispatch builds SSEvent from per-field state per W3C spec — refactor candidate\n const dispatch = (): SSEvent | null => {\n if (!hasField) {\n // Blank line with no preceding fields → reset state, no dispatch (per spec § 9.2.6)\n eventName = undefined;\n dataLines = [];\n id = undefined;\n retry = undefined;\n commentLines = [];\n return null;\n }\n const chunk: SSEvent = {};\n if (eventName !== undefined) (chunk as { event?: string }).event = eventName;\n if (dataLines.length > 0) (chunk as { data?: string }).data = dataLines.join(\"\\n\");\n if (id !== undefined) (chunk as { id?: string }).id = id;\n if (retry !== undefined) (chunk as { retry?: number }).retry = retry;\n if (commentLines.length > 0) (chunk as { comment?: string }).comment = commentLines.join(\"\\n\");\n eventName = undefined;\n dataLines = [];\n id = undefined;\n retry = undefined;\n commentLines = [];\n hasField = false;\n return chunk;\n };\n\n // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: handleLine dispatches across all SSE field kinds per W3C spec — refactor candidate\n const handleLine = (line: string): SSEvent | null => {\n if (line === \"\") {\n return dispatch();\n }\n if (line.startsWith(\":\")) {\n // Comment line — per spec ignored, but we surface it for keepalive visibility.\n commentLines.push(line.slice(1).replace(/^ /, \"\"));\n hasField = true;\n return null;\n }\n const colonIdx = line.indexOf(\":\");\n let field: string;\n let value: string;\n if (colonIdx === -1) {\n field = line;\n value = \"\";\n } else {\n field = line.slice(0, colonIdx);\n value = line.slice(colonIdx + 1);\n // Strip ONE leading space if present (per spec § 9.2.6)\n if (value.startsWith(\" \")) value = value.slice(1);\n }\n switch (field) {\n case \"event\":\n eventName = value;\n hasField = true;\n break;\n case \"data\":\n dataLines.push(value);\n hasField = true;\n break;\n case \"id\":\n // Per spec: id with NULL is ignored\n if (!value.includes(\"\\0\")) {\n id = value;\n hasField = true;\n }\n break;\n case \"retry\":\n if (/^\\d+$/.test(value)) {\n retry = Number.parseInt(value, 10);\n hasField = true;\n }\n break;\n default:\n // Unknown field — ignored per spec\n break;\n }\n return null;\n };\n\n for await (const bytes of source) {\n // Normalize CRLF / CR to LF then split\n buffer += decoder.decode(bytes, { stream: true }).replace(/\\r\\n|\\r/g, \"\\n\");\n let idx: number;\n // biome-ignore lint/suspicious/noAssignInExpressions: idiomatic while-assignment loop for buffered line parsing\n while ((idx = buffer.indexOf(\"\\n\")) !== -1) {\n const line = buffer.slice(0, idx);\n buffer = buffer.slice(idx + 1);\n const event = handleLine(line);\n if (event !== null) yield event;\n }\n }\n // Flush remaining buffer as a final line (no trailing newline case)\n buffer += decoder.decode();\n if (buffer.length > 0) {\n const event = handleLine(buffer);\n if (event !== null) yield event;\n }\n // Final dispatch in case last event lacked terminating blank line\n const tail = dispatch();\n if (tail !== null) yield tail;\n}\n","/**\n * Subscription type contract (G8 v1.7.0) — `@theokit/sdk`.\n *\n * Per ADRs D423 (resume token opaque), D424 (transport selection),\n * D426 (defineSubscription DSL shape).\n *\n * @public\n */\n\nimport { TheokitAgentError } from \"../errors.js\";\n\n/**\n * Transport selection for subscriptions.\n *\n * - `'ws'`: WebSocket (bidirectional). Required for inbound client→server frames.\n * v1.7 ships Node-canonical `ws` adapter; CF/Bun/Deno deferred to v1.8.x per ADR D425.\n * - `'sse'`: W3C Server-Sent Events (server→client only). Browser-native EventSource.\n * - `'auto'`: Prefer WS, fall back SSE on upgrade failure. Default.\n *\n * @public\n */\nexport type SubscriptionTransport = \"ws\" | \"sse\" | \"auto\";\n\n/**\n * Context passed to a subscription `handler` on each invocation.\n *\n * @public\n */\nexport interface SubscriptionCtx {\n /**\n * Opaque resume token forwarded by the client when reconnecting.\n * Handler defines its own semantics (monotonic int, ULID, timestamp,\n * encrypted cursor). SDK passes through unchanged. Per ADR D423.\n */\n readonly lastEventId?: string;\n\n /**\n * AbortSignal that fires when the subscription is cancelled\n * (client disconnect, consumer abort, server shutdown).\n * Handler MUST honor `signal.aborted` in long-running loops.\n */\n readonly signal: AbortSignal;\n\n /**\n * Stable identifier for the underlying transport connection.\n * Different from the subscription name — one connection may host\n * many subscriptions. Useful for logging / per-connection state.\n */\n readonly connectionId: string;\n\n /**\n * Force-close the underlying transport with optional WS close code + reason.\n * Used by consumer code (e.g., auth middleware revoking a session) to\n * terminate a subscription that should not continue.\n */\n disconnect(code?: number, reason?: string): void;\n\n /**\n * Helper to mint a tracked envelope `[id, payload]`.\n * Yielding tracked envelopes lets the client advance `lastEventId`\n * so reconnects can resume from that point.\n */\n tracked<TPayload>(id: string, payload: TPayload): TrackedEnvelope<TPayload>;\n}\n\n/**\n * Tracked envelope: `[id, payload]` tuple yielded by subscription handlers\n * to advertise the resume token associated with the payload.\n *\n * The encoder writes the `id` as an SSE `id:` field or WS payload metadata\n * so the client can echo it back on reconnect (`input.lastEventId`).\n *\n * Per ADR D423.\n *\n * @public\n */\nexport type TrackedEnvelope<T> = readonly [id: string, payload: T];\n\n/**\n * Type guard for {@link TrackedEnvelope}.\n *\n * @public\n */\nexport function isTrackedEnvelope(value: unknown): value is TrackedEnvelope<unknown> {\n return Array.isArray(value) && value.length === 2 && typeof value[0] === \"string\";\n}\n\n/**\n * Mint a tracked envelope. Equivalent to `[id, payload] as const`,\n * exported as a function so consumers don't repeat the tuple cast.\n *\n * @public\n */\nexport function tracked<T>(id: string, payload: T): TrackedEnvelope<T> {\n if (typeof id !== \"string\" || id.length === 0) {\n throw new TypeError(\"tracked(): id must be a non-empty string\");\n }\n return [id, payload] as const;\n}\n\n/**\n * Base error for the subscription subsystem. Extends {@link TheokitAgentError}\n * so existing `instanceof TheokitAgentError` branches keep working.\n *\n * @public\n */\nexport class SubscriptionError extends TheokitAgentError {\n override readonly name: string = \"SubscriptionError\";\n\n constructor(message: string, options: { code?: string; cause?: unknown } = {}) {\n super(message, { ...options, isRetryable: false });\n }\n}\n\n/**\n * Thrown when subscription input fails Zod schema validation.\n *\n * @public\n */\nexport class SubscriptionInputError extends SubscriptionError {\n override readonly name: string = \"SubscriptionInputError\";\n\n readonly issues: unknown;\n\n constructor(message: string, options: { issues: unknown; cause?: unknown }) {\n super(message, { code: \"subscription_input_invalid\", cause: options.cause });\n this.issues = options.issues;\n }\n}\n\n/**\n * Thrown when a subscription transport disconnects unexpectedly\n * AND the client did not opt out of reconnect.\n *\n * @public\n */\nexport class SubscriptionDisconnectError extends SubscriptionError {\n override readonly name: string = \"SubscriptionDisconnectError\";\n\n readonly closeCode?: number;\n readonly closeReason?: string;\n\n constructor(\n message: string,\n options: { closeCode?: number; closeReason?: string; cause?: unknown } = {},\n ) {\n super(message, { code: \"subscription_disconnected\", cause: options.cause });\n if (options.closeCode !== undefined) this.closeCode = options.closeCode;\n if (options.closeReason !== undefined) this.closeReason = options.closeReason;\n }\n}\n\n/**\n * Descriptor returned by {@link Subscription.create}. Carries the typed\n * input/output Zod schemas + handler factory.\n *\n * @public\n */\nexport interface SubscriptionDescriptor<TInput = unknown, TOutput = unknown> {\n /** Optional explicit name; the runtime may also derive name from file path. */\n readonly name?: string;\n /** Zod schema for the subscription input. Validated at dispatch boundary. */\n readonly input: ZodLike<TInput>;\n /** Zod schema for each output frame (informational; not enforced per-frame). */\n readonly output: ZodLike<TOutput>;\n /** Async handler that yields output frames (or tracked envelopes). */\n readonly handler: (\n input: TInput,\n ctx: SubscriptionCtx,\n ) => AsyncGenerator<TOutput | TrackedEnvelope<TOutput>, void, void>;\n}\n\n/**\n * Minimal structural Zod type used to avoid hard peer-dep import.\n * Mirrors the surface used by other SDK modules (e.g., `define-tool.ts`).\n *\n * Emitted rather than erased: it appears in the signature of `defineSubscription`, which\n * `@theokit/sdk/subscription` publishes, so a consumer's type-aware lint has to be able to\n * resolve it.\n */\nexport interface ZodLike<T> {\n safeParse(value: unknown): { success: true; data: T } | { success: false; error: unknown };\n parse(value: unknown): T;\n}\n","/**\n * `Theokit.subscribe` client (G8 public API) — `@theokit/sdk`.\n *\n * Per ADR D427 (Theokit.subscribe namespace) + D424 (transport selection)\n * + D423 (lastEventId opaque propagation).\n *\n * Returns an AsyncGenerator that yields server-sent values. Transparent\n * reconnect with exponential backoff. Propagates `lastEventId` from the last\n * received tracked envelope on each reconnect attempt.\n *\n * @public\n */\n\nimport { parseSseW3C } from \"./internal/sse-parser.js\";\nimport type { WireFrame } from \"./internal/subscription-runtime.js\";\nimport {\n SubscriptionDisconnectError,\n SubscriptionError,\n type SubscriptionTransport,\n} from \"./types.js\";\n\n/**\n * Options accepted by `Theokit.subscribe(name, input, opts?)`.\n *\n * @public\n */\nexport interface SubscribeOptions {\n /** Base URL of the server (e.g., `\"http://localhost:3000\"`). Required. */\n baseUrl: string;\n /** Preferred transport. Default `\"auto\"` (WS preferred, SSE fallback). */\n transport?: SubscriptionTransport;\n /** Max reconnect attempts (default 10). 0 disables reconnect. */\n maxReconnectAttempts?: number;\n /** Backoff strategy. Default exponential `min(30_000, 1000 * 2^attempt)` ms. */\n retryDelayMs?: (attempt: number) => number;\n /** Caller-supplied abort signal. Cancels the subscription entirely. */\n signal?: AbortSignal;\n /** Additional fetch-style headers (e.g., `Authorization`). */\n headers?: Record<string, string>;\n /**\n * Override the SSE transport's `fetch`. Defaults to `globalThis.fetch`.\n * Lets a consumer supply a proxying agent or instrumented fetch without\n * mutating the runtime global.\n */\n fetch?: typeof globalThis.fetch;\n /**\n * Override the WS transport's `WebSocket` constructor. Defaults to\n * `globalThis.WebSocket`. Lets a consumer polyfill WS on a runtime that\n * lacks it, or supply an instrumented implementation, without mutating\n * the runtime global.\n */\n WebSocket?: typeof WebSocket;\n}\n\nconst defaultRetry = (attempt: number) => Math.min(30_000, 1000 * 2 ** attempt);\n\n/**\n * Subscribe to a typed subscription. Yields values produced by the server\n * handler. On disconnect with reconnect enabled, transparently re-establishes\n * the connection and forwards `lastEventId` from the last received tracked\n * envelope so the server handler can resume.\n *\n * @public\n */\n// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: subscribe orchestrates reconnect + transport switch + resume, and the interleaving is the contract. THE DEBT IS UNOWNED — this used to claim it was \"tracked in subscription/theokit-subscribe.ts:52 followup\", which is a line in an unrelated JSDoc block in this same file, and grepping the file for followup/todo/fixme/#NNN returns only this comment. The citation was its own only evidence. Saying the debt is unowned is worse news and true; a maintainer who checks the tracking before touching the module's @public entry point now learns that in one grep instead of three.\nexport async function* subscribe<TInput, TOutput>(\n name: string,\n input: TInput,\n opts: SubscribeOptions,\n): AsyncGenerator<TOutput, void, void> {\n if (typeof name !== \"string\" || name.length === 0) {\n throw new SubscriptionError(\"Theokit.subscribe: name must be a non-empty string\", {\n code: \"subscribe_name_invalid\",\n });\n }\n if (opts === null || typeof opts !== \"object\" || typeof opts.baseUrl !== \"string\") {\n throw new SubscriptionError(\"Theokit.subscribe: opts.baseUrl is required\", {\n code: \"subscribe_baseUrl_missing\",\n });\n }\n const transport = opts.transport ?? \"auto\";\n const maxReconnects = opts.maxReconnectAttempts ?? 10;\n const retry = opts.retryDelayMs ?? defaultRetry;\n\n let lastEventId: string | undefined;\n let attempt = 0;\n\n while (true) {\n if (opts.signal?.aborted) return;\n try {\n const inputWithCursor = mergeLastEventId(input, lastEventId);\n const chosen = await selectTransport(transport, name, opts);\n if (chosen === \"ws\") {\n for await (const out of openWs<TOutput>(name, inputWithCursor, opts)) {\n if (out.lastEventId !== undefined) lastEventId = out.lastEventId;\n attempt = 0; // reset backoff on successful frame\n yield out.value;\n }\n } else {\n for await (const out of openSse<TOutput>(name, inputWithCursor, opts)) {\n if (out.lastEventId !== undefined) lastEventId = out.lastEventId;\n attempt = 0;\n yield out.value;\n }\n }\n // Clean end-of-stream — no reconnect.\n return;\n } catch (cause) {\n if (opts.signal?.aborted) return;\n if (maxReconnects === 0 || attempt >= maxReconnects) {\n if (cause instanceof SubscriptionError) throw cause;\n throw new SubscriptionDisconnectError(\n `subscription \"${name}\" disconnected; reconnect exhausted`,\n { cause },\n );\n }\n const delay = retry(attempt);\n attempt++;\n await sleep(delay, opts.signal);\n }\n }\n}\n\ninterface FrameOut<T> {\n readonly value: T;\n readonly lastEventId?: string;\n}\n\n// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: openSse parses framed SSE stream with abort/error/retry branches — refactor candidate\nasync function* openSse<T>(\n name: string,\n input: unknown,\n opts: SubscribeOptions,\n): AsyncIterable<FrameOut<T>> {\n const url = `${stripTrailingSlash(opts.baseUrl)}/api/subscriptions/${encodeURIComponent(name)}?input=${encodeURIComponent(JSON.stringify(input))}`;\n const fetchFn = opts.fetch ?? globalThis.fetch;\n const res = await fetchFn(url, {\n method: \"GET\",\n headers: {\n accept: \"text/event-stream\",\n ...(opts.headers ?? {}),\n },\n ...(opts.signal !== undefined ? { signal: opts.signal } : {}),\n });\n if (!res.ok || res.body === null) {\n throw new SubscriptionError(`SSE subscribe failed: HTTP ${res.status} ${res.statusText}`, {\n code: \"sse_http_error\",\n });\n }\n const events = parseSseW3C(streamToAsyncIterable(res.body));\n for await (const ev of events) {\n if (ev.event === \"end\") return;\n if (ev.event === \"error\") {\n throw new SubscriptionError(`SSE server emitted error: ${ev.data ?? \"(no body)\"}`, {\n code: \"sse_server_error\",\n });\n }\n if (ev.event === \"connected\") continue;\n if (ev.data === undefined) continue;\n const parsedValue = safeJsonParse<T>(ev.data);\n if (parsedValue === undefined) continue;\n yield {\n value: parsedValue,\n ...(ev.id !== undefined ? { lastEventId: ev.id } : {}),\n };\n }\n}\n\n// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: openWs orchestrates WS lifecycle + envelope decode + cleanup — refactor candidate\nasync function* openWs<T>(\n name: string,\n input: unknown,\n opts: SubscribeOptions,\n): AsyncIterable<FrameOut<T>> {\n const baseUrl = stripTrailingSlash(opts.baseUrl);\n const wsUrl = baseUrl\n .replace(/^http:/, \"ws:\")\n .replace(/^https:/, \"wss:\")\n .concat(\"/api/ws\");\n\n const WS = opts.WebSocket ?? (globalThis as { WebSocket?: typeof WebSocket }).WebSocket;\n if (WS === undefined) {\n throw new SubscriptionError(\n \"Theokit.subscribe(transport='ws'): no global WebSocket available. Use Node >=22 or install 'ws' as a runtime dep + assign to globalThis.WebSocket, or pass opts.WebSocket.\",\n { code: \"ws_global_missing\" },\n );\n }\n const ws = new WS(wsUrl);\n\n // Set up async iterator-like state.\n const incoming: WireFrame[] = [];\n // biome-ignore lint/suspicious/noConfusingVoidType: idiomatic event-callback signature; refactoring to undefined would mask the no-value semantics\n let waiter: ((value: void) => void) | null = null;\n let closed = false;\n let closeError: Error | undefined;\n\n ws.addEventListener(\"message\", (ev: MessageEvent) => {\n const data = typeof ev.data === \"string\" ? ev.data : \"\";\n const frame = safeJsonParse<WireFrame>(data);\n if (frame !== undefined) {\n incoming.push(frame);\n if (waiter !== null) {\n waiter();\n waiter = null;\n }\n }\n });\n ws.addEventListener(\"close\", () => {\n closed = true;\n if (waiter !== null) {\n waiter();\n waiter = null;\n }\n });\n ws.addEventListener(\"error\", () => {\n closed = true;\n closeError = new Error(\"WebSocket error\");\n if (waiter !== null) {\n waiter();\n waiter = null;\n }\n });\n\n await new Promise<void>((resolve, reject) => {\n ws.addEventListener(\"open\", () => resolve(), { once: true });\n ws.addEventListener(\"error\", () => reject(new Error(\"WS connect failed\")), { once: true });\n });\n\n // Send subscribe request after handshake.\n ws.send(JSON.stringify({ kind: \"subscribe\", name, input }));\n\n if (opts.signal !== undefined) {\n opts.signal.addEventListener(\"abort\", () => ws.close(), { once: true });\n }\n\n try {\n while (true) {\n if (incoming.length === 0) {\n if (closed) {\n if (closeError !== undefined) throw closeError;\n return;\n }\n await new Promise<void>((resolve) => {\n waiter = resolve;\n });\n continue;\n }\n const frame = incoming.shift() as WireFrame;\n if (frame.type === \"end\") return;\n if (frame.type === \"error\") {\n // The server's own code wins. `ws_server_error` is the fallback for a frame that carries\n // none — it used to be the code for EVERY server-side failure, so a caller could not tell an\n // invalid input from a disconnect without reading English out of the message.\n throw new SubscriptionError(\n `WS server emitted error: ${frame.error?.message ?? \"(unknown)\"}`,\n { code: frame.error?.code ?? \"ws_server_error\" },\n );\n }\n const value = frame.data as T;\n yield {\n value,\n ...(frame.id !== undefined ? { lastEventId: frame.id } : {}),\n };\n }\n } finally {\n try {\n ws.close();\n } catch {\n /* ignore */\n }\n }\n}\n\nasync function selectTransport(\n pref: SubscriptionTransport,\n _name: string,\n opts: SubscribeOptions,\n): Promise<\"ws\" | \"sse\"> {\n if (pref === \"ws\") return \"ws\";\n if (pref === \"sse\") return \"sse\";\n // auto — prefer WS if available (injected or global), else SSE.\n const WS = opts.WebSocket ?? (globalThis as { WebSocket?: unknown }).WebSocket;\n if (typeof WS === \"function\") {\n return \"ws\";\n }\n return \"sse\";\n}\n\nfunction mergeLastEventId(input: unknown, lastEventId: string | undefined): unknown {\n if (lastEventId === undefined) return input;\n if (input === null || typeof input !== \"object\" || Array.isArray(input)) {\n // Cannot merge into primitive — return as-is.\n return input;\n }\n return { ...(input as object), lastEventId };\n}\n\nfunction stripTrailingSlash(s: string): string {\n return s.endsWith(\"/\") ? s.slice(0, -1) : s;\n}\n\nfunction safeJsonParse<T>(s: string): T | undefined {\n try {\n return JSON.parse(s) as T;\n } catch {\n return undefined;\n }\n}\n\nasync function* streamToAsyncIterable(\n stream: ReadableStream<Uint8Array>,\n): AsyncIterable<Uint8Array> {\n const reader = stream.getReader();\n let finishedNaturally = false;\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) {\n finishedNaturally = true;\n return;\n }\n if (value !== undefined) yield value;\n }\n } finally {\n // B-131: `releaseLock()` alone detaches the reader WITHOUT canceling the stream (WHATWG\n // Streams spec) — the underlying `fetch` response body, and its socket, stays open until\n // something else cancels it or reads it to completion. A consumer that breaks out of the\n // subscription mid-stream (the ordinary shape: `for await ... break`) used to leave that\n // connection dangling. `cancel()` is a no-op once the stream is already closed, so it is safe\n // to call unconditionally on the early-exit path; skip it on natural completion, where the\n // stream is already done and canceling only risks surfacing a spurious rejection.\n if (!finishedNaturally) {\n try {\n await reader.cancel();\n } catch {\n /* best-effort cleanup — the caller's own error (if any) already takes precedence */\n }\n }\n reader.releaseLock();\n }\n}\n\nfunction sleep(ms: number, signal?: AbortSignal): Promise<void> {\n return new Promise((resolve, reject) => {\n if (signal?.aborted) {\n reject(new Error(\"aborted\"));\n return;\n }\n const t = setTimeout(() => {\n signal?.removeEventListener(\"abort\", onAbort);\n resolve();\n }, ms);\n const onAbort = () => {\n clearTimeout(t);\n reject(new Error(\"aborted\"));\n };\n signal?.addEventListener(\"abort\", onAbort, { once: true });\n });\n}\n"]}
@@ -12,6 +12,11 @@
12
12
  * server wiring lands in a sibling theokit task (cross-repo follow-up
13
13
  * documented in EC-7 of the plan).
14
14
  *
15
+ * Claim written 2026-06-04 (f8df6284) and NOT re-verified since: whether the sibling task has
16
+ * landed is a fact about another repository, and nobody checked it from here. Re-read EC-7 before
17
+ * trusting this paragraph — a cross-repo "lands soon" is the shape most likely to outlive its own
18
+ * truth, because the person who lands it is not the person reading this.
19
+ *
15
20
  * @internal
16
21
  */
17
22
  export {};
@@ -12,6 +12,11 @@
12
12
  * server wiring lands in a sibling theokit task (cross-repo follow-up
13
13
  * documented in EC-7 of the plan).
14
14
  *
15
+ * Claim written 2026-06-04 (f8df6284) and NOT re-verified since: whether the sibling task has
16
+ * landed is a fact about another repository, and nobody checked it from here. Re-read EC-7 before
17
+ * trusting this paragraph — a cross-repo "lands soon" is the shape most likely to outlive its own
18
+ * truth, because the person who lands it is not the person reading this.
19
+ *
15
20
  * @internal
16
21
  */
17
22
  export {};
@@ -6,4 +6,16 @@
6
6
  *
7
7
  * @internal
8
8
  */
9
- export {};
9
+ /**
10
+ * Build an error frame that carries the cause's CODE, not only its sentence.
11
+ *
12
+ * `WireFrame.error.code` was declared here and written by nobody: all three producers sent
13
+ * `{ message }`, and the WS client turned every inbound error into one `ws_server_error`. So a
14
+ * subsystem that defines coded errors on purpose — `subscription_input_invalid`,
15
+ * `subscription_disconnected` — collapsed all of them to a single code at the wire, and the real
16
+ * reason survived only as interpolated English inside a message.
17
+ *
18
+ * A shared builder rather than three literals, because a declared-and-never-written field is exactly
19
+ * what happens when each site decides for itself.
20
+ */
21
+ export declare function errorFrame(cause: unknown): WireFrame;
@@ -6,4 +6,16 @@
6
6
  *
7
7
  * @internal
8
8
  */
9
- export {};
9
+ /**
10
+ * Build an error frame that carries the cause's CODE, not only its sentence.
11
+ *
12
+ * `WireFrame.error.code` was declared here and written by nobody: all three producers sent
13
+ * `{ message }`, and the WS client turned every inbound error into one `ws_server_error`. So a
14
+ * subsystem that defines coded errors on purpose — `subscription_input_invalid`,
15
+ * `subscription_disconnected` — collapsed all of them to a single code at the wire, and the real
16
+ * reason survived only as interpolated English inside a message.
17
+ *
18
+ * A shared builder rather than three literals, because a declared-and-never-written field is exactly
19
+ * what happens when each site decides for itself.
20
+ */
21
+ export declare function errorFrame(cause: unknown): WireFrame;
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Errors raised by the Task API (`src/task.ts`).
3
+ *
4
+ * One actor, one module: these three are about task identity and task lifecycle, and they change
5
+ * when the Task surface changes rather than when the agent-run surface does. They extend
6
+ * `TheokitAgentError` like every other error in this package — the hierarchy is the contract, and
7
+ * `tests/lint/every-error-is-in-the-hierarchy.test.ts` enforces it wherever the class lives.
8
+ *
9
+ * Re-exported from `errors.ts`, so `@theokit/sdk/errors` still names every error in one place.
10
+ *
11
+ * NOTE ON THE MODULE TAG: this header deliberately carries no internal-visibility tag, and does not
12
+ * even name one — TypeScript attaches a file-leading docblock to the FIRST declaration below it, and
13
+ * `stripInternal: true` (tsconfig.base) then deletes that declaration from the emitted `.d.ts`.
14
+ * `tsc --noEmit` stays clean and the declaration rollup fails with `"X" is not exported by "..."`.
15
+ * Measured twice on this file on 2026-09-01: once with the tag, and again when the comment
16
+ * EXPLAINING the trap quoted the tag verbatim and re-armed it.
17
+ */
18
+ import { TheokitAgentError } from "./errors-base.js";
19
+ /**
20
+ * Thrown when a user-supplied task ID violates the grammar
21
+ * `^[a-z0-9][a-z0-9_-]*$` (D368) OR starts with a reserved adapter
22
+ * prefix (`wf-` / `b-` / `cron-`, EC-5).
23
+ *
24
+ * @public
25
+ */
26
+ export declare class InvalidTaskIdError extends TheokitAgentError {
27
+ readonly name: string;
28
+ readonly taskId: string;
29
+ constructor(message: string, taskId: string, options?: {
30
+ cause?: unknown;
31
+ });
32
+ }
33
+ /**
34
+ * Thrown when `Task.subscribe(id)` is called for a task that has been
35
+ * evicted, never submitted, or evicted after retention (D373).
36
+ *
37
+ * @public
38
+ */
39
+ export declare class TaskNotFoundError extends TheokitAgentError {
40
+ readonly name: string;
41
+ readonly taskId: string;
42
+ constructor(taskId: string, options?: {
43
+ cause?: unknown;
44
+ });
45
+ }
46
+ /**
47
+ * Thrown when `CloudAgent` is asked to wrap a task (D370). Cloud
48
+ * task observability is deferred until Theo PaaS GA.
49
+ *
50
+ * @public
51
+ */
52
+ export declare class UnsupportedTaskOperationError extends TheokitAgentError {
53
+ readonly name: string;
54
+ readonly operation: string;
55
+ constructor(operation: string, options?: {
56
+ cause?: unknown;
57
+ });
58
+ }
@@ -1,24 +1,23 @@
1
1
  'use strict';
2
2
 
3
- var chunkRFMBZPOW_cjs = require('./chunk-RFMBZPOW.cjs');
4
- require('./chunk-UALX2J2Q.cjs');
5
- require('./chunk-4ZHTIJNE.cjs');
6
- require('./chunk-XL7Q7HB2.cjs');
7
- require('./chunk-EG4QM7ZJ.cjs');
3
+ var chunkHCT4HPCL_cjs = require('./chunk-HCT4HPCL.cjs');
4
+ require('./chunk-JLRLCBJ4.cjs');
5
+ require('./chunk-J7J7J2GN.cjs');
6
+ require('./chunk-6LHQPOMI.cjs');
8
7
 
9
8
 
10
9
 
11
10
  Object.defineProperty(exports, "InMemoryTaskStore", {
12
11
  enumerable: true,
13
- get: function () { return chunkRFMBZPOW_cjs.InMemoryTaskStore; }
12
+ get: function () { return chunkHCT4HPCL_cjs.InMemoryTaskStore; }
14
13
  });
15
14
  Object.defineProperty(exports, "JsonFileTaskStore", {
16
15
  enumerable: true,
17
- get: function () { return chunkRFMBZPOW_cjs.JsonFileTaskStore; }
16
+ get: function () { return chunkHCT4HPCL_cjs.JsonFileTaskStore; }
18
17
  });
19
18
  Object.defineProperty(exports, "getTaskStoreFor", {
20
19
  enumerable: true,
21
- get: function () { return chunkRFMBZPOW_cjs.getTaskStoreFor; }
20
+ get: function () { return chunkHCT4HPCL_cjs.getTaskStoreFor; }
22
21
  });
23
22
  //# sourceMappingURL=task-store.cjs.map
24
23
  //# sourceMappingURL=task-store.cjs.map
@@ -1,4 +1,6 @@
1
1
  /**
2
+ * Published as `@theokit/sdk/task-store`.
3
+ *
2
4
  * Public sub-export for the Task store interface + JSON-backed
3
5
  * implementation. Used by `@theokit/cli` to read the registry
4
6
  * cross-process from disk (ADR D364 + EC-7 best-effort cancel).
@@ -1,4 +1,6 @@
1
1
  /**
2
+ * Published as `@theokit/sdk/task-store`.
3
+ *
2
4
  * Public sub-export for the Task store interface + JSON-backed
3
5
  * implementation. Used by `@theokit/cli` to read the registry
4
6
  * cross-process from disk (ADR D364 + EC-7 best-effort cancel).
@@ -1,7 +1,6 @@
1
- export { InMemoryTaskStore, JsonFileTaskStore, getTaskStoreFor } from './chunk-KQRW2GPZ.js';
2
- import './chunk-2GUYQR5P.js';
3
- import './chunk-ZZMZWBR6.js';
4
- import './chunk-D4CUGAKZ.js';
5
- import './chunk-XEQ3TM66.js';
1
+ export { InMemoryTaskStore, JsonFileTaskStore, getTaskStoreFor } from './chunk-EIQFAOFD.js';
2
+ import './chunk-3JHIFQ4I.js';
3
+ import './chunk-ALUN2B4W.js';
4
+ import './chunk-CZJ6Q7CW.js';
6
5
  //# sourceMappingURL=task-store.js.map
7
6
  //# sourceMappingURL=task-store.js.map
@@ -1,4 +1,7 @@
1
1
  /**
2
+ * Owner: `internal/agent-loop/` (3 of 11 importers). Derived from the import graph, not
3
+ * declared — `tests/lint/types-name-their-owner.test.ts` re-derives it.
4
+ *
2
5
  * Type-leaf — primitives shared between `agent.ts`, `run.ts`, and
3
6
  * `messages.ts`. Extracted to break LOW type-only cycles #5 and #7
4
7
  * (audit `architecture-output/final_report.md`) per plan
@@ -114,3 +117,21 @@ export interface CustomTool {
114
117
  threadId?: string;
115
118
  }) => string | import("./content-blocks.js").ToolResultContentBlock[] | Promise<string | import("./content-blocks.js").ToolResultContentBlock[]>;
116
119
  }
120
+ /**
121
+ * How the permission engine treats the UNMATCHED verdict.
122
+ *
123
+ * - `default` — ask.
124
+ * - `plan` — read-only.
125
+ * - `acceptEdits` — auto-approve the unmatched verdict, but still honour an explicit `ask` rule.
126
+ * - `bypass` (alias `bypassPermissions`, the Anthropic-exact name) — everything allowed EXCEPT an
127
+ * explicit `deny`. Never asks.
128
+ *
129
+ * G7 / DIP — defined in this type leaf rather than in `permission-engine.ts`, which is a RUNTIME
130
+ * module. `types/agent.ts`, `types/run.ts` and `types/plugin.ts` all need the union, and each one
131
+ * used to reach into the engine for it: three of the nine violations the `types-dont-import-runtime`
132
+ * rule reported the moment it was able to see type-only edges at all. The engine re-exports it, so
133
+ * `import type { PermissionMode } from "@theokit/sdk"` is unchanged.
134
+ *
135
+ * @public
136
+ */
137
+ export type PermissionMode = "default" | "plan" | "acceptEdits" | "bypass" | "bypassPermissions";
@@ -1,13 +1,18 @@
1
+ /**
2
+ * Owner: `src/` (13 of 65 importers). Derived from the import graph, not
3
+ * declared — `tests/lint/types-name-their-owner.test.ts` re-derives it.
4
+ *
5
+ */
1
6
  import type { BudgetTracker } from "./budget-tracker.js";
2
7
  import type { ContextSettings } from "./context.js";
3
8
  import type { McpServerConfig } from "./mcp.js";
4
9
  import type { MemoryProvider } from "./memory-provider.js";
5
10
  import type { PluginsSettings, ProviderRoutingSettings } from "./providers.js";
6
11
  export type { CustomTool, ModelParameterValue, ModelSelection, ToolContextMessage, } from "./agent-prims.js";
7
- import type { CustomTool, ModelSelection } from "./agent-prims.js";
12
+ import type { CustomTool, ModelSelection, PermissionMode } from "./agent-prims.js";
8
13
  import type { Plugin } from "./plugin.js";
9
14
  import type { InvalidateCacheOptions, PersonalityPreset, SDKAgent, SystemPromptSkillRef } from "./sdk-agent.js";
10
- export type { SDKAgentPlugins, SDKAgentSkillDetail, SDKAgentSkills, SDKArtifact, SDKPluginMetadata, } from "./sdk-agent.js";
15
+ export type { AgentOperation, SDKAgentPlugins, SDKAgentSkillDetail, SDKAgentSkills, SDKArtifact, SDKPluginMetadata, } from "./sdk-agent.js";
11
16
  export type { InvalidateCacheOptions, PersonalityPreset, SDKAgent, SystemPromptSkillRef };
12
17
  /**
13
18
  * Which on-disk settings layers a local agent loads.
@@ -15,6 +20,17 @@ export type { InvalidateCacheOptions, PersonalityPreset, SDKAgent, SystemPromptS
15
20
  * @public
16
21
  */
17
22
  export type SettingSource = "project" | "user" | "team" | "mdm" | "plugins" | "all";
23
+ /**
24
+ * A foreign configuration dialect this SDK can read.
25
+ *
26
+ * A DIFFERENT axis from {@link SettingSource}, and collapsing the two would be wrong: that one is
27
+ * about SCOPE (user vs project, and the trust posture behind it), this one about which product's
28
+ * format a project wants imported. A project can legitimately want project scope with `.theokit/`
29
+ * only — which is now the default.
30
+ *
31
+ * @public
32
+ */
33
+ export type CompatSource = "claude-code";
18
34
  /**
19
35
  * A tool the SDK declares to the model on its own initiative — not one the consumer passed in
20
36
  * {@link AgentOptions.tools}, and not one an MCP server exposed.
@@ -59,6 +75,27 @@ export interface LocalOptions {
59
75
  */
60
76
  cwd?: string | string[];
61
77
  settingSources?: SettingSource[];
78
+ /**
79
+ * Foreign configuration dialects to import. Default: none — `.theokit/` only.
80
+ *
81
+ * `.claude/` used to be read unconditionally across hooks, plugins, skills and subagents, so a
82
+ * repository that merely had Claude Code set up had its hooks executed, its skills folded into
83
+ * the system prompt and its subagents registered, having configured nothing for this SDK
84
+ * (usetheokit/theokit-sdk#524). One consequence was every turn being denied, because those hook
85
+ * commands are written against a runtime that defines `$CLAUDE_PROJECT_DIR` and this one did not
86
+ * (#522).
87
+ *
88
+ * A trust gate answers "do I trust the code in this directory?". That is a different question
89
+ * from "do I want another product's configuration imported into this one?", and they come apart
90
+ * in the ordinary case: a repository you trust completely is exactly where `.claude/` is
91
+ * populated — for a different tool, by a different contract, often by a teammate who never heard
92
+ * of this SDK.
93
+ *
94
+ * Listing a dialect is all-or-nothing for that dialect, and restores exactly the previous
95
+ * behaviour. On a name collision `.theokit/` wins: the native definition is the one the project
96
+ * wrote for this runtime.
97
+ */
98
+ compatSources?: CompatSource[];
62
99
  sandboxOptions?: {
63
100
  enabled: boolean;
64
101
  };
@@ -436,7 +473,7 @@ export interface AgentOptions {
436
473
  * `SendOptions.permissionMode` overrides it. Absent ⇒ the plugin's own
437
474
  * construction-time mode applies. Local runtime.
438
475
  */
439
- permissionMode?: import("../permission-engine.js").PermissionMode;
476
+ permissionMode?: PermissionMode;
440
477
  /**
441
478
  * Skills configuration. Either a static {@link SkillsSettings} object or —
442
479
  * SE22 — a {@link SkillsResolver} evaluated per `send()` to pick skills from
@@ -634,12 +671,18 @@ export interface AgentOptions {
634
671
  * inversion). When provided, the agent loop calls `tracker.track(...)`
635
672
  * after each LLM completion and `tracker.check()` before each iteration.
636
673
  *
637
- * **Status (Phase 2 incremental):** the option is wired to the type
638
- * surface only. Agent-loop runtime wiring is additive and lands in a
639
- * subsequent iteration — for now, the kernel still uses the legacy
640
- * `UsageAccumulator` + `IterationBudget` from `internal/budget/`.
641
- * Consumers passing a custom tracker today get the type guarantee but
642
- * NOT runtime enforcement.
674
+ * **Runtime enforcement is live.** Verified against the call graph on
675
+ * 2026-09-01: `internal/agent-loop/loop.ts:78-81` reads the tracker and
676
+ * gates the iteration through `evaluateBudgetGate`, `:110` calls
677
+ * `nextIteration()`, and `:390`/`:397` call `track(...)` per completion;
678
+ * the option reaches the loop from `AgentOptions` at
679
+ * `internal/local-agent/real-local-run.ts:342`.
680
+ *
681
+ * This paragraph previously said the opposite — "wired to the type surface
682
+ * only ... NOT runtime enforcement" — and it was wrong in the expensive stale-claim-ok: verbatim quote of the corrected text
683
+ * direction: a consumer reading the published `.d.ts` was told the SDK would
684
+ * not enforce their cost ceiling, so the rational response was to build a
685
+ * second control outside it, or to stop trusting the option.
643
686
  *
644
687
  * Default impls available today via `@theokit/sdk`:
645
688
  * - `createCounterBudgetTracker({ maxTokens, maxIterations })`
@@ -658,12 +701,17 @@ export interface AgentOptions {
658
701
  * pre-LLM to inject recalled facts, and `provider.dispose(...)` on
659
702
  * Agent shutdown.
660
703
  *
661
- * **Status (Phase 1 incremental):** the option is wired to the type
662
- * surface only. Agent-loop runtime wiring is additive and lands in
663
- * subsequent iterations (T1.4 plumbing, T1.5 runtime hooks). For now,
664
- * the kernel still uses the legacy `Memory` class + `internal/memory/*`
665
- * runtime files. Consumers passing a custom provider today get the type
666
- * guarantee but NOT runtime enforcement.
704
+ * **Runtime enforcement is live.** Verified against the call graph on
705
+ * 2026-09-01: `internal/agent-loop/loop-context-init.ts:95` calls
706
+ * `provider.init(...)`, `:129` surfaces `provider.buildTools(...)` to the
707
+ * model, `:166` runs `provider.runActivePass(...)`, and
708
+ * `internal/agent-loop/loop.ts:176`/`:204` call `sync` and `dispose`.
709
+ *
710
+ * This paragraph previously said the opposite — "wired to the type surface
711
+ * only ... NOT runtime enforcement". A stale "not implemented yet" note on a stale-claim-ok: verbatim quote of the corrected text
712
+ * `@public` symbol is worse than no note: it is believed, it survives the
713
+ * work it describes, and nothing in this repo compares such a claim against
714
+ * the call graph.
667
715
  *
668
716
  * Default impls available today via `@theokit/sdk`:
669
717
  * - `createNoopMemoryProvider()` — degenerate fallback / worked example
@@ -1,4 +1,7 @@
1
1
  /**
2
+ * Owner: `src/` (2 of 5 importers). Derived from the import graph, not declared —
3
+ * `tests/lint/types-name-their-owner.test.ts` re-derives it.
4
+ *
2
5
  * Public types for `Agent.batch` (ADRs D134-D140).
3
6
  *
4
7
  * Run N prompts in parallel with bounded concurrency. Each prompt gets
@@ -1,4 +1,7 @@
1
1
  /**
2
+ * Owner: `internal/budget/tracker/` (1 of 1 importers). Derived from the import graph, not
3
+ * declared — `tests/lint/types-name-their-owner.test.ts` re-derives it.
4
+ *
2
5
  * `BudgetTracker` — runtime contract for budget/usage tracking in the
3
6
  * agent loop (SDK 2.0 Phase 2 / T2.1 — ADR D1 interface inversion).
4
7
  *
@@ -1,13 +1,22 @@
1
1
  /**
2
+ * Owner: `internal/budget/` (4 of 6 importers). Derived from the import graph, not declared —
3
+ * `tests/lint/types-name-their-owner.test.ts` re-derives it.
4
+ *
2
5
  * Public type contract for the Budget enforcement primitive
3
6
  * (ADRs D375, D382-D387). The runtime facade lives in `budget.ts`.
4
7
  *
5
8
  * @public
6
9
  */
7
10
  /**
8
- * Scope of a budget — where the charge is attributed. v1 supports
9
- * `process` (shared global) only; `agent` and `call` reserved for
10
- * v0.2 multi-tenant scenarios.
11
+ * Accounting scope for a budget.
12
+ *
13
+ * ONLY `"process"` is implemented, and `Budget.create` now REFUSES the other two with
14
+ * `unimplemented_budget_scope`. It used to accept them: nothing outside the registry read `scope`, so
15
+ * a caller asking for per-agent accounting silently got process-wide accounting — a cost control
16
+ * reporting the wrong number, which is worse than the missing feature.
17
+ *
18
+ * The union is not narrowed to `"process"` here because that is a breaking change to a published
19
+ * type and belongs to a major. Widening it back when the scopes are built is non-breaking.
11
20
  */
12
21
  export type BudgetScope = "agent" | "call" | "process";
13
22
  /**
@@ -1,4 +1,7 @@
1
1
  /**
2
+ * Owner: `src/` (2 of 7 importers). Derived from the import graph, not declared —
3
+ * `tests/lint/types-name-their-owner.test.ts` re-derives it.
4
+ *
2
5
  * Leaf module for content-block types shared by `messages.ts` (assistant/user
3
6
  * content) and `agent-prims.ts` (`CustomTool` handler results). Kept
4
7
  * import-free so both can depend on it WITHOUT the `agent-prims ↔ messages`
@@ -1,4 +1,7 @@
1
1
  /**
2
+ * Owner: `src/` (1 of 2 importers). Derived from the import graph, not declared —
3
+ * `tests/lint/types-name-their-owner.test.ts` re-derives it.
4
+ *
2
5
  * Context manager backend.
3
6
  *
4
7
  * - `"file"` — Read `.theokit/context.json` from the workspace (local) or the
@@ -1,3 +1,8 @@
1
+ /**
2
+ * Owner: `internal/agent-loop/` (4 of 8 importers). Derived from the import graph, not
3
+ * declared — `tests/lint/types-name-their-owner.test.ts` re-derives it.
4
+ *
5
+ */
1
6
  import type { ToolCall } from "./updates.js";
2
7
  export type { UserMessage } from "./messages-base.js";
3
8
  import type { UserMessage } from "./messages-base.js";
@@ -1,3 +1,8 @@
1
+ /**
2
+ * Owner: `internal/cron/` (4 of 5 importers). Derived from the import graph, not declared —
3
+ * `tests/lint/types-name-their-owner.test.ts` re-derives it.
4
+ *
5
+ */
1
6
  import type { Workflow } from "../workflow.js";
2
7
  import type { AgentOptions } from "./agent.js";
3
8
  import type { SDKUserMessage } from "./run.js";