@theokit/sdk 4.37.2 → 4.39.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (457) hide show
  1. package/CHANGELOG.md +309 -72
  2. package/dist/a2a/index.cjs +3 -3
  3. package/dist/a2a/index.js +1 -1
  4. package/dist/a2a/subagent.d.cts +1 -0
  5. package/dist/a2a/subagent.d.ts +1 -0
  6. package/dist/{agent-SmxntivO.d.ts → agent-D7bRK9Kg.d.cts} +108 -41
  7. package/dist/agent-I3EZZR6S.cjs +55 -0
  8. package/dist/{agent-IE6IE4NW.cjs.map → agent-I3EZZR6S.cjs.map} +1 -1
  9. package/dist/agent-KKZYLY5D.js +46 -0
  10. package/dist/{agent-DW2J37IH.js.map → agent-KKZYLY5D.js.map} +1 -1
  11. package/dist/{agent-DGv1-d81.d.cts → agent-ZCZa7YQv.d.ts} +108 -41
  12. package/dist/agent-session-store-N4TVKHBU.cjs +23 -0
  13. package/dist/agent-session-store-N4TVKHBU.cjs.map +1 -0
  14. package/dist/agent-session-store-RHMHP5DG.js +6 -0
  15. package/dist/agent-session-store-RHMHP5DG.js.map +1 -0
  16. package/dist/agent.d.ts +38 -2
  17. package/dist/auth/index.cjs +15 -15
  18. package/dist/auth/index.js +4 -4
  19. package/dist/{batch-SY5GZLFD.js → batch-6KQM3EBA.js} +12 -12
  20. package/dist/batch-6KQM3EBA.js.map +1 -0
  21. package/dist/{batch-3SEPDXCU.cjs → batch-X6JKGDPK.cjs} +26 -26
  22. package/dist/batch-X6JKGDPK.cjs.map +1 -0
  23. package/dist/chunk-2RW7K6FN.cjs +34 -0
  24. package/dist/chunk-2RW7K6FN.cjs.map +1 -0
  25. package/dist/chunk-3I4B3OIX.js +105 -0
  26. package/dist/chunk-3I4B3OIX.js.map +1 -0
  27. package/dist/{chunk-2WFB5ZOX.js → chunk-42IFCKQZ.js} +5 -5
  28. package/dist/{chunk-2WFB5ZOX.js.map → chunk-42IFCKQZ.js.map} +1 -1
  29. package/dist/{chunk-DCJ5MCJ3.js → chunk-4F7JQZOX.js} +9 -36
  30. package/dist/chunk-4F7JQZOX.js.map +1 -0
  31. package/dist/{chunk-JNIWFCKI.js → chunk-4JSZYSGW.js} +3 -3
  32. package/dist/{chunk-JNIWFCKI.js.map → chunk-4JSZYSGW.js.map} +1 -1
  33. package/dist/{chunk-EEZ7CFMM.js → chunk-5KOW3GLE.js} +2 -2
  34. package/dist/chunk-5KOW3GLE.js.map +1 -0
  35. package/dist/{chunk-6VP3XGEK.js → chunk-65ONFZWM.js} +12 -11
  36. package/dist/chunk-65ONFZWM.js.map +1 -0
  37. package/dist/{chunk-CSZRJ4RE.js → chunk-6EEYRFJC.js} +5 -5
  38. package/dist/{chunk-CSZRJ4RE.js.map → chunk-6EEYRFJC.js.map} +1 -1
  39. package/dist/{chunk-FAY3QDGC.cjs → chunk-6LGQECT7.cjs} +11 -11
  40. package/dist/{chunk-FAY3QDGC.cjs.map → chunk-6LGQECT7.cjs.map} +1 -1
  41. package/dist/{chunk-PAEJPLVN.cjs → chunk-6NEHIHFU.cjs} +4 -4
  42. package/dist/{chunk-PAEJPLVN.cjs.map → chunk-6NEHIHFU.cjs.map} +1 -1
  43. package/dist/chunk-6YNYA7GD.cjs +103 -0
  44. package/dist/chunk-6YNYA7GD.cjs.map +1 -0
  45. package/dist/chunk-74D7KSBP.cjs +112 -0
  46. package/dist/chunk-74D7KSBP.cjs.map +1 -0
  47. package/dist/{chunk-FK4EJD2I.cjs → chunk-75DSEWTJ.cjs} +7 -7
  48. package/dist/{chunk-FK4EJD2I.cjs.map → chunk-75DSEWTJ.cjs.map} +1 -1
  49. package/dist/{chunk-SWIBQFPH.cjs → chunk-7OLG7VI4.cjs} +4 -4
  50. package/dist/{chunk-SWIBQFPH.cjs.map → chunk-7OLG7VI4.cjs.map} +1 -1
  51. package/dist/chunk-7U2HAAWB.cjs +199 -0
  52. package/dist/chunk-7U2HAAWB.cjs.map +1 -0
  53. package/dist/{chunk-YBFDBOUN.cjs → chunk-7YBJZS5P.cjs} +8 -8
  54. package/dist/{chunk-YBFDBOUN.cjs.map → chunk-7YBJZS5P.cjs.map} +1 -1
  55. package/dist/{chunk-GLUWH6JO.js → chunk-AECV3G5Z.js} +4 -4
  56. package/dist/{chunk-GLUWH6JO.js.map → chunk-AECV3G5Z.js.map} +1 -1
  57. package/dist/{chunk-UQPDFW4E.js → chunk-AR5MQZ3J.js} +3 -3
  58. package/dist/{chunk-UQPDFW4E.js.map → chunk-AR5MQZ3J.js.map} +1 -1
  59. package/dist/{chunk-G2F67XUR.cjs → chunk-B4YA6BRS.cjs} +13 -14
  60. package/dist/chunk-B4YA6BRS.cjs.map +1 -0
  61. package/dist/{chunk-LTCOPATU.cjs → chunk-BCQ3E2ZG.cjs} +12 -3
  62. package/dist/chunk-BCQ3E2ZG.cjs.map +1 -0
  63. package/dist/{chunk-ALU3KC4G.cjs → chunk-BPN5ONSW.cjs} +223 -277
  64. package/dist/chunk-BPN5ONSW.cjs.map +1 -0
  65. package/dist/{chunk-YHZXBDAW.js → chunk-BQDUEG4C.js} +16 -16
  66. package/dist/{chunk-YHZXBDAW.js.map → chunk-BQDUEG4C.js.map} +1 -1
  67. package/dist/{chunk-IT3PWBW4.cjs → chunk-BURYFNOM.cjs} +2 -2
  68. package/dist/chunk-BURYFNOM.cjs.map +1 -0
  69. package/dist/{chunk-BJMKQOY2.cjs → chunk-C7OP3FAK.cjs} +47 -11
  70. package/dist/chunk-C7OP3FAK.cjs.map +1 -0
  71. package/dist/{chunk-XAYVHS2B.cjs → chunk-CEIHCKTO.cjs} +4 -4
  72. package/dist/chunk-CEIHCKTO.cjs.map +1 -0
  73. package/dist/{chunk-2423XDPT.cjs → chunk-CN6UX5EV.cjs} +28 -56
  74. package/dist/chunk-CN6UX5EV.cjs.map +1 -0
  75. package/dist/{chunk-VNNK6AKU.js → chunk-D7IULBF2.js} +3 -3
  76. package/dist/chunk-D7IULBF2.js.map +1 -0
  77. package/dist/chunk-DCXRHCZJ.cjs +118 -0
  78. package/dist/chunk-DCXRHCZJ.cjs.map +1 -0
  79. package/dist/{chunk-ICYBIC6N.cjs → chunk-DGLLVCNB.cjs} +4 -4
  80. package/dist/chunk-DGLLVCNB.cjs.map +1 -0
  81. package/dist/{chunk-I35DI7ES.js → chunk-DKFGUOWL.js} +3 -3
  82. package/dist/{chunk-I35DI7ES.js.map → chunk-DKFGUOWL.js.map} +1 -1
  83. package/dist/{chunk-TQI3KRXZ.cjs → chunk-DMTZ3FII.cjs} +18 -18
  84. package/dist/{chunk-TQI3KRXZ.cjs.map → chunk-DMTZ3FII.cjs.map} +1 -1
  85. package/dist/{chunk-QFMXXUUT.js → chunk-DU7DE543.js} +3 -3
  86. package/dist/{chunk-QFMXXUUT.js.map → chunk-DU7DE543.js.map} +1 -1
  87. package/dist/{chunk-W4QN5CMG.cjs → chunk-DWY25VLP.cjs} +9 -9
  88. package/dist/{chunk-W4QN5CMG.cjs.map → chunk-DWY25VLP.cjs.map} +1 -1
  89. package/dist/chunk-E2FFG33C.js +109 -0
  90. package/dist/chunk-E2FFG33C.js.map +1 -0
  91. package/dist/{chunk-QUFSDDNU.cjs → chunk-E4IUN3JB.cjs} +15 -15
  92. package/dist/{chunk-QUFSDDNU.cjs.map → chunk-E4IUN3JB.cjs.map} +1 -1
  93. package/dist/{chunk-THEYGCYS.cjs → chunk-ECHGWE47.cjs} +4 -4
  94. package/dist/chunk-ECHGWE47.cjs.map +1 -0
  95. package/dist/{chunk-U2WLFOA3.cjs → chunk-ECW2MLEW.cjs} +4 -4
  96. package/dist/{chunk-U2WLFOA3.cjs.map → chunk-ECW2MLEW.cjs.map} +1 -1
  97. package/dist/{chunk-MXSMAGDU.js → chunk-ET6PHZRX.js} +33 -26
  98. package/dist/chunk-ET6PHZRX.js.map +1 -0
  99. package/dist/{chunk-G6AASL5T.cjs → chunk-FRUBE44B.cjs} +24 -24
  100. package/dist/{chunk-G6AASL5T.cjs.map → chunk-FRUBE44B.cjs.map} +1 -1
  101. package/dist/{chunk-3ILFUXNE.cjs → chunk-FWBSDQZ7.cjs} +5 -5
  102. package/dist/{chunk-3ILFUXNE.cjs.map → chunk-FWBSDQZ7.cjs.map} +1 -1
  103. package/dist/{chunk-7DXLNNKH.cjs → chunk-G2Q3ZC6C.cjs} +4 -4
  104. package/dist/{chunk-7DXLNNKH.cjs.map → chunk-G2Q3ZC6C.cjs.map} +1 -1
  105. package/dist/{chunk-56ZM6P7Z.cjs → chunk-G4XUXSRN.cjs} +12 -12
  106. package/dist/chunk-G4XUXSRN.cjs.map +1 -0
  107. package/dist/{chunk-VYJSHGAY.js → chunk-GIRD3RWH.js} +422 -295
  108. package/dist/chunk-GIRD3RWH.js.map +1 -0
  109. package/dist/{chunk-NQ4AC2U4.cjs → chunk-HIQFVHC6.cjs} +9 -9
  110. package/dist/{chunk-NQ4AC2U4.cjs.map → chunk-HIQFVHC6.cjs.map} +1 -1
  111. package/dist/{chunk-EXQV452X.js → chunk-HWNVAUK4.js} +3 -3
  112. package/dist/{chunk-EXQV452X.js.map → chunk-HWNVAUK4.js.map} +1 -1
  113. package/dist/{chunk-P34DHHYQ.cjs → chunk-I53ZQHU6.cjs} +34 -27
  114. package/dist/chunk-I53ZQHU6.cjs.map +1 -0
  115. package/dist/{chunk-MHCKWQR3.cjs → chunk-IHFNRNTJ.cjs} +8 -8
  116. package/dist/{chunk-MHCKWQR3.cjs.map → chunk-IHFNRNTJ.cjs.map} +1 -1
  117. package/dist/{chunk-W52DKZBR.cjs → chunk-INSFS5GT.cjs} +680 -553
  118. package/dist/chunk-INSFS5GT.cjs.map +1 -0
  119. package/dist/{chunk-TAPQWDW2.js → chunk-IVSD7L22.js} +12 -4
  120. package/dist/chunk-IVSD7L22.js.map +1 -0
  121. package/dist/{chunk-WDGCZDRG.js → chunk-J3UK2GMN.js} +3 -3
  122. package/dist/{chunk-WDGCZDRG.js.map → chunk-J3UK2GMN.js.map} +1 -1
  123. package/dist/{chunk-4YB7B3RP.cjs → chunk-J6T5LWJ4.cjs} +15 -14
  124. package/dist/chunk-J6T5LWJ4.cjs.map +1 -0
  125. package/dist/{chunk-XAEAMI5H.js → chunk-JRLXEYR4.js} +21 -5
  126. package/dist/chunk-JRLXEYR4.js.map +1 -0
  127. package/dist/{chunk-ZJN6NTHE.js → chunk-JZUPMTJY.js} +3 -3
  128. package/dist/{chunk-ZJN6NTHE.js.map → chunk-JZUPMTJY.js.map} +1 -1
  129. package/dist/{chunk-M5ZQBOIZ.js → chunk-KE6XKRLQ.js} +3 -3
  130. package/dist/{chunk-M5ZQBOIZ.js.map → chunk-KE6XKRLQ.js.map} +1 -1
  131. package/dist/chunk-KGRIHEDT.js +110 -0
  132. package/dist/chunk-KGRIHEDT.js.map +1 -0
  133. package/dist/{chunk-T4QWDOG6.js → chunk-KWUNN5J2.js} +5 -5
  134. package/dist/{chunk-T4QWDOG6.js.map → chunk-KWUNN5J2.js.map} +1 -1
  135. package/dist/{chunk-56OXYUZE.js → chunk-KX7JV5KM.js} +3 -3
  136. package/dist/chunk-KX7JV5KM.js.map +1 -0
  137. package/dist/{chunk-D4ZUJTFB.cjs → chunk-LALG2K33.cjs} +8 -8
  138. package/dist/{chunk-D4ZUJTFB.cjs.map → chunk-LALG2K33.cjs.map} +1 -1
  139. package/dist/{chunk-QGDKZDPN.js → chunk-LGILIGV3.js} +3 -3
  140. package/dist/{chunk-QGDKZDPN.js.map → chunk-LGILIGV3.js.map} +1 -1
  141. package/dist/{chunk-HEN5WXXI.js → chunk-LJX2SQV2.js} +6 -6
  142. package/dist/{chunk-HEN5WXXI.js.map → chunk-LJX2SQV2.js.map} +1 -1
  143. package/dist/{chunk-SDIBMLL5.js → chunk-MC5EINBV.js} +44 -8
  144. package/dist/chunk-MC5EINBV.js.map +1 -0
  145. package/dist/{chunk-F6Y4IEQM.js → chunk-ML5A5DOJ.js} +4 -4
  146. package/dist/{chunk-F6Y4IEQM.js.map → chunk-ML5A5DOJ.js.map} +1 -1
  147. package/dist/{chunk-6EDQBX7U.cjs → chunk-N475ETD6.cjs} +17 -17
  148. package/dist/{chunk-6EDQBX7U.cjs.map → chunk-N475ETD6.cjs.map} +1 -1
  149. package/dist/{chunk-YPQF26X7.cjs → chunk-OBA6YK2R.cjs} +2 -2
  150. package/dist/chunk-OBA6YK2R.cjs.map +1 -0
  151. package/dist/chunk-OXNYIMZZ.js +31 -0
  152. package/dist/chunk-OXNYIMZZ.js.map +1 -0
  153. package/dist/{chunk-NFCKEBHI.js → chunk-PI4RO4GR.js} +3 -3
  154. package/dist/{chunk-NFCKEBHI.js.map → chunk-PI4RO4GR.js.map} +1 -1
  155. package/dist/{chunk-2ONFGMBV.js → chunk-PY2RQOA7.js} +2 -2
  156. package/dist/chunk-PY2RQOA7.js.map +1 -0
  157. package/dist/chunk-QKE556YD.js +197 -0
  158. package/dist/chunk-QKE556YD.js.map +1 -0
  159. package/dist/{chunk-FV3YEMQ7.js → chunk-RP5HQVLD.js} +13 -14
  160. package/dist/chunk-RP5HQVLD.js.map +1 -0
  161. package/dist/chunk-SCFW5MJZ.js +100 -0
  162. package/dist/chunk-SCFW5MJZ.js.map +1 -0
  163. package/dist/{chunk-CD73YHEH.js → chunk-SG5ZWT6C.js} +3 -3
  164. package/dist/{chunk-CD73YHEH.js.map → chunk-SG5ZWT6C.js.map} +1 -1
  165. package/dist/{chunk-MRODLUGY.cjs → chunk-TIMPJL5V.cjs} +4 -4
  166. package/dist/{chunk-MRODLUGY.cjs.map → chunk-TIMPJL5V.cjs.map} +1 -1
  167. package/dist/{chunk-77WHPVXE.js → chunk-TOTP24P6.js} +4 -4
  168. package/dist/chunk-TOTP24P6.js.map +1 -0
  169. package/dist/{chunk-3O2ELBST.cjs → chunk-USZTVNUQ.cjs} +5 -5
  170. package/dist/{chunk-3O2ELBST.cjs.map → chunk-USZTVNUQ.cjs.map} +1 -1
  171. package/dist/{chunk-YDLNI7J6.js → chunk-V2RBCCN5.js} +3 -3
  172. package/dist/chunk-V2RBCCN5.js.map +1 -0
  173. package/dist/{chunk-NNSKJCBM.cjs → chunk-VJYSQXN6.cjs} +10 -10
  174. package/dist/{chunk-NNSKJCBM.cjs.map → chunk-VJYSQXN6.cjs.map} +1 -1
  175. package/dist/{chunk-GM7QDQ24.cjs → chunk-W4WKVOOQ.cjs} +11 -11
  176. package/dist/{chunk-GM7QDQ24.cjs.map → chunk-W4WKVOOQ.cjs.map} +1 -1
  177. package/dist/chunk-XYOHKCYG.cjs +109 -0
  178. package/dist/chunk-XYOHKCYG.cjs.map +1 -0
  179. package/dist/{chunk-ZW345YOI.js → chunk-YP67XZES.js} +4 -4
  180. package/dist/{chunk-ZW345YOI.js.map → chunk-YP67XZES.js.map} +1 -1
  181. package/dist/{chunk-YCXMSDSP.js → chunk-YRXY2A5L.js} +4 -4
  182. package/dist/{chunk-YCXMSDSP.js.map → chunk-YRXY2A5L.js.map} +1 -1
  183. package/dist/{chunk-IEUDKUPM.cjs → chunk-Z2CUEBXV.cjs} +25 -9
  184. package/dist/chunk-Z2CUEBXV.cjs.map +1 -0
  185. package/dist/{chunk-GL7CFBVC.js → chunk-ZYB6B7QJ.js} +112 -165
  186. package/dist/chunk-ZYB6B7QJ.js.map +1 -0
  187. package/dist/compact-session-PYEC3NZV.js +18 -0
  188. package/dist/{compact-session-WNKKIIDW.js.map → compact-session-PYEC3NZV.js.map} +1 -1
  189. package/dist/compact-session-VVT6IBJG.cjs +55 -0
  190. package/dist/{compact-session-H5TKLD55.cjs.map → compact-session-VVT6IBJG.cjs.map} +1 -1
  191. package/dist/compaction.cjs +19 -19
  192. package/dist/compaction.d.cts +9 -9
  193. package/dist/compaction.d.ts +9 -9
  194. package/dist/compaction.js +3 -3
  195. package/dist/concurrency.cjs +6 -6
  196. package/dist/concurrency.js +4 -4
  197. package/dist/context-2FZSC6VQ.cjs +22 -0
  198. package/dist/{context-ZV33V4DC.cjs.map → context-2FZSC6VQ.cjs.map} +1 -1
  199. package/dist/context-ATJJAFOS.js +5 -0
  200. package/dist/{context-VAYLPT4O.js.map → context-ATJJAFOS.js.map} +1 -1
  201. package/dist/{cron-Dx7B-3WB.d.ts → cron-Bx7tzm5R.d.ts} +54 -2
  202. package/dist/{cron-BiK_aNJI.d.cts → cron-D-DVjGQe.d.cts} +54 -2
  203. package/dist/cron.cjs +34 -30
  204. package/dist/cron.d.cts +3 -3
  205. package/dist/cron.d.ts +3 -3
  206. package/dist/cron.js +33 -29
  207. package/dist/{errors-DyVbXdR4.d.cts → errors-DMY-gLSK.d.cts} +1 -1
  208. package/dist/{errors-Cua4WC9H.d.ts → errors-DjBQ4Tn8.d.ts} +1 -1
  209. package/dist/errors.cjs +21 -21
  210. package/dist/errors.d.cts +2 -2
  211. package/dist/errors.d.ts +2 -2
  212. package/dist/errors.js +2 -2
  213. package/dist/eval.cjs +42 -37
  214. package/dist/eval.cjs.map +1 -1
  215. package/dist/eval.js +38 -33
  216. package/dist/eval.js.map +1 -1
  217. package/dist/{executor-OZSYXDKF.cjs → executor-BMRICN46.cjs} +26 -25
  218. package/dist/executor-BMRICN46.cjs.map +1 -0
  219. package/dist/{executor-PAH72CB5.js → executor-T65PPOPT.js} +10 -9
  220. package/dist/executor-T65PPOPT.js.map +1 -0
  221. package/dist/filesystem/index.cjs +7 -7
  222. package/dist/filesystem/index.js +3 -3
  223. package/dist/fs-session-store-J5MCFFUM.cjs +19 -0
  224. package/dist/{fs-session-store-7E7UPLF2.cjs.map → fs-session-store-J5MCFFUM.cjs.map} +1 -1
  225. package/dist/fs-session-store-O6FNHECD.js +10 -0
  226. package/dist/{fs-session-store-6MY7PNI2.js.map → fs-session-store-O6FNHECD.js.map} +1 -1
  227. package/dist/generate-object-UF6WIZLF.cjs +20 -0
  228. package/dist/{generate-object-5SCEH2EE.cjs.map → generate-object-UF6WIZLF.cjs.map} +1 -1
  229. package/dist/generate-object-XDCBYVK3.js +7 -0
  230. package/dist/{generate-object-I7UD4NWN.js.map → generate-object-XDCBYVK3.js.map} +1 -1
  231. package/dist/index-manager-N7RQYUKT.cjs +20 -0
  232. package/dist/{index-manager-R6ZJFEZF.cjs.map → index-manager-N7RQYUKT.cjs.map} +1 -1
  233. package/dist/index-manager-ZVZUHPP7.js +11 -0
  234. package/dist/{index-manager-KKAK7NT3.js.map → index-manager-ZVZUHPP7.js.map} +1 -1
  235. package/dist/index.cjs +154 -148
  236. package/dist/index.cjs.map +1 -1
  237. package/dist/index.d.cts +201 -43
  238. package/dist/index.d.ts +201 -43
  239. package/dist/index.js +62 -59
  240. package/dist/index.js.map +1 -1
  241. package/dist/{inject-session-UXNJQTZ6.js → inject-session-GQMTDZUN.js} +8 -7
  242. package/dist/inject-session-GQMTDZUN.js.map +1 -0
  243. package/dist/{inject-session-DM4SKTZO.cjs → inject-session-LFCYVSLJ.cjs} +11 -10
  244. package/dist/inject-session-LFCYVSLJ.cjs.map +1 -0
  245. package/dist/internal/agent-loop/live-events.d.ts +46 -0
  246. package/dist/internal/agent-loop/loop-thinking-steps.d.ts +28 -0
  247. package/dist/internal/agent-loop/message-builders.d.ts +12 -3
  248. package/dist/internal/budget/compute-cost.d.ts +1 -1
  249. package/dist/internal/diagnostics.d.ts +46 -31
  250. package/dist/internal/error-mappers/anthropic.d.ts +1 -1
  251. package/dist/internal/global-singleton.d.ts +7 -7
  252. package/dist/internal/judge/judge-call.d.ts +14 -14
  253. package/dist/internal/llm/anthropic-shared.d.ts +4 -4
  254. package/dist/internal/llm/retrying-client.d.ts +29 -29
  255. package/dist/internal/llm/transport-error.d.ts +2 -2
  256. package/dist/internal/llm/types.d.ts +49 -9
  257. package/dist/internal/local-agent/mcp-pool.d.ts +7 -3
  258. package/dist/internal/memory/adapters/azure-openai-embedding.d.cts +2 -0
  259. package/dist/internal/memory/adapters/catalog.d.cts +1 -0
  260. package/dist/internal/memory/adapters/cohere-embedding.d.cts +2 -0
  261. package/dist/internal/memory/adapters/deepinfra-embedding.d.cts +2 -0
  262. package/dist/internal/memory/adapters/gemini-embedding.d.cts +2 -0
  263. package/dist/internal/memory/adapters/index.cjs +28 -0
  264. package/dist/internal/memory/adapters/index.cjs.map +1 -0
  265. package/dist/internal/memory/adapters/index.d.cts +16 -0
  266. package/dist/internal/memory/adapters/index.d.ts +16 -0
  267. package/dist/internal/memory/adapters/index.js +11 -0
  268. package/dist/internal/memory/adapters/index.js.map +1 -0
  269. package/dist/internal/memory/adapters/jina-embedding.d.cts +2 -0
  270. package/dist/internal/memory/adapters/mistral-embedding.d.cts +2 -0
  271. package/dist/internal/memory/adapters/ollama-embedding.d.cts +34 -0
  272. package/dist/internal/memory/adapters/openai-compatible.d.cts +51 -0
  273. package/dist/internal/memory/adapters/openai-compatible.d.ts +28 -0
  274. package/dist/internal/memory/adapters/openai-embedding.d.cts +2 -0
  275. package/dist/internal/memory/adapters/openrouter-embedding.d.cts +2 -0
  276. package/dist/internal/memory/adapters/voyage-embedding.d.cts +2 -0
  277. package/dist/internal/memory/dreaming/diary.d.ts +4 -0
  278. package/dist/internal/memory/dreaming/phases.d.ts +15 -0
  279. package/dist/internal/memory/dreaming/run.d.ts +10 -0
  280. package/dist/internal/memory/migrate-sqlite-to-lance.d.ts +15 -0
  281. package/dist/internal/memory/sdk-memory-peer-loader.d.ts +21 -0
  282. package/dist/internal/persistence/exclusive-create.d.cts +2 -2
  283. package/dist/internal/persistence/exclusive-create.d.ts +2 -2
  284. package/dist/internal/persistence/fs-session-store.d.cts +18 -18
  285. package/dist/internal/persistence/fs-session-store.d.ts +18 -18
  286. package/dist/internal/persistence/index.cjs +25 -25
  287. package/dist/internal/persistence/index.cjs.map +1 -1
  288. package/dist/internal/persistence/index.js +6 -6
  289. package/dist/internal/persistence/index.js.map +1 -1
  290. package/dist/internal/persistence/paths.d.cts +7 -7
  291. package/dist/internal/persistence/paths.d.ts +7 -7
  292. package/dist/internal/persistence/session-transcript.d.cts +13 -7
  293. package/dist/internal/persistence/session-transcript.d.ts +13 -7
  294. package/dist/internal/persistence/session-writer.d.cts +30 -13
  295. package/dist/internal/persistence/session-writer.d.ts +30 -13
  296. package/dist/internal/runtime/concurrency/subagent-credentials.d.ts +35 -0
  297. package/dist/internal/runtime/fixtures/fixture-run-base.d.ts +45 -13
  298. package/dist/internal/runtime/lifecycle/goal-marker.d.ts +8 -8
  299. package/dist/internal/security/index.cjs +13 -13
  300. package/dist/internal/security/index.js +3 -3
  301. package/dist/internal/session/agent-session-store.d.ts +1 -0
  302. package/dist/internal/session/agent-session.d.ts +14 -14
  303. package/dist/internal/session/session-cache.d.ts +9 -9
  304. package/dist/internal/session/session-types.d.ts +6 -1
  305. package/dist/judge-call-NA2G6ZMJ.js +5 -0
  306. package/dist/{judge-call-TAEIXMYG.js.map → judge-call-NA2G6ZMJ.js.map} +1 -1
  307. package/dist/judge-call-U2D33JOW.cjs +22 -0
  308. package/dist/{judge-call-SP3G3X2Y.cjs.map → judge-call-U2D33JOW.cjs.map} +1 -1
  309. package/dist/models.cjs +20 -20
  310. package/dist/models.cjs.map +1 -1
  311. package/dist/models.js +5 -5
  312. package/dist/models.js.map +1 -1
  313. package/dist/path-safety.cjs +10 -10
  314. package/dist/path-safety.js +3 -3
  315. package/dist/persistence.cjs +43 -43
  316. package/dist/persistence.cjs.map +1 -1
  317. package/dist/persistence.d.cts +1 -1
  318. package/dist/persistence.d.ts +1 -1
  319. package/dist/persistence.js +14 -14
  320. package/dist/persistence.js.map +1 -1
  321. package/dist/project.cjs +5 -5
  322. package/dist/project.js +3 -3
  323. package/dist/registry-CAS6Y5ZY.js +9 -0
  324. package/dist/{registry-SOXE4RY6.js.map → registry-CAS6Y5ZY.js.map} +1 -1
  325. package/dist/registry-JSDI4WKA.cjs +46 -0
  326. package/dist/{registry-N3GTKYCI.cjs.map → registry-JSDI4WKA.cjs.map} +1 -1
  327. package/dist/retry.cjs +4 -4
  328. package/dist/retry.js +3 -3
  329. package/dist/{run-CwEJtLPE.d.ts → run-i2-fUohR.d.cts} +217 -174
  330. package/dist/{run-CwEJtLPE.d.cts → run-i2-fUohR.d.ts} +217 -174
  331. package/dist/{run-until-YZ2ODWOF.js → run-until-BK56WG4P.js} +3 -3
  332. package/dist/{run-until-YZ2ODWOF.js.map → run-until-BK56WG4P.js.map} +1 -1
  333. package/dist/{run-until-ZZ2JLPJM.cjs → run-until-L5KQD3PV.cjs} +4 -4
  334. package/dist/{run-until-ZZ2JLPJM.cjs.map → run-until-L5KQD3PV.cjs.map} +1 -1
  335. package/dist/sandbox/bwrap.d.cts +20 -20
  336. package/dist/sandbox/bwrap.d.ts +20 -20
  337. package/dist/sandbox/index.cjs +39 -39
  338. package/dist/sandbox/index.cjs.map +1 -1
  339. package/dist/sandbox/index.d.cts +1 -1
  340. package/dist/sandbox/index.d.ts +1 -1
  341. package/dist/sandbox/index.js +35 -35
  342. package/dist/sandbox/index.js.map +1 -1
  343. package/dist/sandbox/linux-sandbox.d.cts +26 -21
  344. package/dist/sandbox/linux-sandbox.d.ts +26 -21
  345. package/dist/server/auth/index.cjs.map +1 -1
  346. package/dist/server/auth/index.d.cts +6 -6
  347. package/dist/server/auth/index.d.ts +6 -6
  348. package/dist/server/auth/index.js.map +1 -1
  349. package/dist/server/auth/orchestrator.d.cts +2 -2
  350. package/dist/server/auth/orchestrator.d.ts +2 -2
  351. package/dist/server/auth/types.d.cts +4 -4
  352. package/dist/server/auth/types.d.ts +4 -4
  353. package/dist/server/errors-envelope.cjs +14 -14
  354. package/dist/server/errors-envelope.d.cts +3 -3
  355. package/dist/server/errors-envelope.d.ts +3 -3
  356. package/dist/server/errors-envelope.js +3 -3
  357. package/dist/session-transcript-3B52DKTG.js +5 -0
  358. package/dist/{session-transcript-6WKLYIN4.js.map → session-transcript-3B52DKTG.js.map} +1 -1
  359. package/dist/session-transcript-H7NUFXXM.cjs +50 -0
  360. package/dist/{session-transcript-EAKR4D2W.cjs.map → session-transcript-H7NUFXXM.cjs.map} +1 -1
  361. package/dist/skills.cjs +7 -7
  362. package/dist/skills.js +5 -5
  363. package/dist/stream-object-4FDU76YW.cjs +20 -0
  364. package/dist/{stream-object-Y7YCX3BI.cjs.map → stream-object-4FDU76YW.cjs.map} +1 -1
  365. package/dist/stream-object-HWDEEQN4.js +7 -0
  366. package/dist/{stream-object-OFM66VUT.js.map → stream-object-HWDEEQN4.js.map} +1 -1
  367. package/dist/subagents-loader-A4W6C3QP.cjs +15 -0
  368. package/dist/subagents-loader-A4W6C3QP.cjs.map +1 -0
  369. package/dist/subagents-loader-X33KH2SZ.js +6 -0
  370. package/dist/subagents-loader-X33KH2SZ.js.map +1 -0
  371. package/dist/subagents-loader.cjs +6 -6
  372. package/dist/subagents-loader.d.cts +2 -2
  373. package/dist/subagents-loader.d.ts +2 -2
  374. package/dist/subagents-loader.js +4 -4
  375. package/dist/subscription/index.cjs +3 -3
  376. package/dist/subscription/index.js +2 -2
  377. package/dist/task-store.cjs +7 -7
  378. package/dist/task-store.js +4 -4
  379. package/dist/types/agent-prims.d.ts +4 -4
  380. package/dist/types/agent.d.ts +68 -3
  381. package/dist/types/conversation.d.ts +7 -0
  382. package/dist/types/goal-events.d.ts +24 -23
  383. package/dist/types/messages.d.ts +9 -0
  384. package/dist/types/run.d.ts +27 -0
  385. package/dist/types/session-message.d.ts +59 -0
  386. package/dist/types/session-record.d.ts +14 -13
  387. package/dist/types/workflow.d.ts +36 -0
  388. package/dist/workflow.cjs +27 -27
  389. package/dist/workflow.d.cts +17 -1
  390. package/dist/workflow.d.ts +17 -1
  391. package/dist/workflow.js +6 -6
  392. package/docs/harness-capability-map.md +22 -0
  393. package/package.json +22 -13
  394. package/dist/agent-DW2J37IH.js +0 -42
  395. package/dist/agent-IE6IE4NW.cjs +0 -51
  396. package/dist/batch-3SEPDXCU.cjs.map +0 -1
  397. package/dist/batch-SY5GZLFD.js.map +0 -1
  398. package/dist/chunk-2423XDPT.cjs.map +0 -1
  399. package/dist/chunk-2ONFGMBV.js.map +0 -1
  400. package/dist/chunk-4YB7B3RP.cjs.map +0 -1
  401. package/dist/chunk-56OXYUZE.js.map +0 -1
  402. package/dist/chunk-56ZM6P7Z.cjs.map +0 -1
  403. package/dist/chunk-5SB4V74H.js +0 -176
  404. package/dist/chunk-5SB4V74H.js.map +0 -1
  405. package/dist/chunk-6VP3XGEK.js.map +0 -1
  406. package/dist/chunk-77WHPVXE.js.map +0 -1
  407. package/dist/chunk-ALU3KC4G.cjs.map +0 -1
  408. package/dist/chunk-BJMKQOY2.cjs.map +0 -1
  409. package/dist/chunk-DCJ5MCJ3.js.map +0 -1
  410. package/dist/chunk-EEZ7CFMM.js.map +0 -1
  411. package/dist/chunk-FV3YEMQ7.js.map +0 -1
  412. package/dist/chunk-G2F67XUR.cjs.map +0 -1
  413. package/dist/chunk-GL7CFBVC.js.map +0 -1
  414. package/dist/chunk-H5YVJB4K.cjs +0 -185
  415. package/dist/chunk-H5YVJB4K.cjs.map +0 -1
  416. package/dist/chunk-ICYBIC6N.cjs.map +0 -1
  417. package/dist/chunk-IEUDKUPM.cjs.map +0 -1
  418. package/dist/chunk-IT3PWBW4.cjs.map +0 -1
  419. package/dist/chunk-ITLS5LRF.cjs +0 -105
  420. package/dist/chunk-ITLS5LRF.cjs.map +0 -1
  421. package/dist/chunk-LTCOPATU.cjs.map +0 -1
  422. package/dist/chunk-MXSMAGDU.js.map +0 -1
  423. package/dist/chunk-P34DHHYQ.cjs.map +0 -1
  424. package/dist/chunk-SDIBMLL5.js.map +0 -1
  425. package/dist/chunk-TAPQWDW2.js.map +0 -1
  426. package/dist/chunk-THEYGCYS.cjs.map +0 -1
  427. package/dist/chunk-VNNK6AKU.js.map +0 -1
  428. package/dist/chunk-VYJSHGAY.js.map +0 -1
  429. package/dist/chunk-W52DKZBR.cjs.map +0 -1
  430. package/dist/chunk-XAEAMI5H.js.map +0 -1
  431. package/dist/chunk-XAYVHS2B.cjs.map +0 -1
  432. package/dist/chunk-YDLNI7J6.js.map +0 -1
  433. package/dist/chunk-YPQF26X7.cjs.map +0 -1
  434. package/dist/chunk-YVTNFKZO.js +0 -103
  435. package/dist/chunk-YVTNFKZO.js.map +0 -1
  436. package/dist/compact-session-H5TKLD55.cjs +0 -54
  437. package/dist/compact-session-WNKKIIDW.js +0 -17
  438. package/dist/context-VAYLPT4O.js +0 -5
  439. package/dist/context-ZV33V4DC.cjs +0 -22
  440. package/dist/executor-OZSYXDKF.cjs.map +0 -1
  441. package/dist/executor-PAH72CB5.js.map +0 -1
  442. package/dist/fs-session-store-6MY7PNI2.js +0 -10
  443. package/dist/fs-session-store-7E7UPLF2.cjs +0 -19
  444. package/dist/generate-object-5SCEH2EE.cjs +0 -20
  445. package/dist/generate-object-I7UD4NWN.js +0 -7
  446. package/dist/index-manager-KKAK7NT3.js +0 -10
  447. package/dist/index-manager-R6ZJFEZF.cjs +0 -19
  448. package/dist/inject-session-DM4SKTZO.cjs.map +0 -1
  449. package/dist/inject-session-UXNJQTZ6.js.map +0 -1
  450. package/dist/judge-call-SP3G3X2Y.cjs +0 -22
  451. package/dist/judge-call-TAEIXMYG.js +0 -5
  452. package/dist/registry-N3GTKYCI.cjs +0 -46
  453. package/dist/registry-SOXE4RY6.js +0 -9
  454. package/dist/session-transcript-6WKLYIN4.js +0 -5
  455. package/dist/session-transcript-EAKR4D2W.cjs +0 -50
  456. package/dist/stream-object-OFM66VUT.js +0 -7
  457. package/dist/stream-object-Y7YCX3BI.cjs +0 -20
@@ -1,4 +1,4 @@
1
- import { M as ModelSelection, ac as SDKUserMessage, ae as SendOptions, b as Run, G as GenerateOptions, n as GenerateRunResult, _ as RunToCompletionOptions, $ as RunToCompletionResult, S as SDKMessage, al as StreamToCompletionResult, C as CustomTool, c as PermissionMode, a as McpServerConfig, P as Processor } from './run-CwEJtLPE.cjs';
1
+ import { M as ModelSelection, ad as SDKUserMessage, af as SendOptions, b as Run, G as GenerateOptions, n as GenerateRunResult, $ as RunToCompletionOptions, a0 as RunToCompletionResult, S as SDKMessage, am as StreamToCompletionResult, C as CustomTool, c as PermissionMode, a as McpServerConfig, P as Processor } from './run-i2-fUohR.js';
2
2
  import * as zod from 'zod';
3
3
 
4
4
  /**
@@ -16,7 +16,7 @@ import * as zod from 'zod';
16
16
  * @public
17
17
  */
18
18
  /** One transcript record (one JSONL line). `message` absent on `system` (compact_boundary) records. */
19
- /** Um bloco de conteúdo dentro de {@link TranscriptMessage}. */
19
+ /** A content block inside {@link TranscriptMessage}. */
20
20
  type TranscriptBlock = {
21
21
  type: "text";
22
22
  text: string;
@@ -38,12 +38,13 @@ type TranscriptBlock = {
38
38
  /**
39
39
  * O corpo de mensagem de um {@link SessionRecord}.
40
40
  *
41
- * **NÃO se chama `SessionMessage`** — esse nome existe em `internal/session/session-types.ts` com
42
- * a forma `{role, text}`, incompatível com esta. Repropor um nome exportado com forma nova é
43
- * precisamente a quebra silenciosa que o M91 custou dois patches para desfazer.
41
+ * **It is NOT called `SessionMessage`** — that name already exists in
42
+ * `internal/session/session-types.ts` with the shape `{role, text}`, incompatible with this one.
43
+ * Reusing an exported name for a new shape is
44
+ * precisely the silent break M91 cost two patches to undo.
44
45
  *
45
- * O parse do disco continua **tolerante** (`readTranscript` pula linha malformada): o que muda aqui
46
- * é o **tipo**, não a leniência registros gravados por versões anteriores continuam legíveis.
46
+ * Parsing from disk stays **tolerant** (`readTranscript` skips a malformed line): what changes here
47
+ * is the **type**, not leniencyrecords written by earlier versions stay readable.
47
48
  *
48
49
  * @public
49
50
  */
@@ -51,9 +52,9 @@ interface TranscriptMessage {
51
52
  role: "user" | "assistant";
52
53
  content: TranscriptBlock[];
53
54
  /**
54
- * Os três campos abaixo aparecem **só** no registro de assistant, e vêm do escritor
55
- * (`SessionTranscript.appendAssistant`). Declarados opcionais porque o registro de user não os
56
- * temmedido no próprio escritor, não presumido.
55
+ * The three fields below appear **only** on the assistant record, and come from the writer
56
+ * (`SessionTranscript.appendAssistant`). Declared optional because the user record does not carry
57
+ * themmeasured in the writer itself, not assumed.
57
58
  */
58
59
  id?: string;
59
60
  type?: "message";
@@ -75,11 +76,11 @@ interface SessionRecord {
75
76
  trigger: string;
76
77
  };
77
78
  /**
78
- * O corpo da mensagem, na forma que o escritor de transcript de fato grava.
79
+ * The message body, in the shape the transcript writer actually writes.
79
80
  *
80
- * M94 — era `Record<string, unknown>`, e o consumidor recuperava o tipo com cast a cada leitura.
81
- * A forma **sempre foi fixa** (`SessionTranscript.appendToolResults` / `#push` a produzem); só não
82
- * estava declarada. Segue opcional porque registros de sistema não carregam mensagem.
81
+ * M94 — it was `Record<string, unknown>`, and the consumer recovered the type with a cast on every read.
82
+ * The shape **has always been fixed** (`SessionTranscript.appendToolResults` / `#push` produce
83
+ * it); it simply was not declared. It stays optional because system records carry no message.
83
84
  */
84
85
  message?: TranscriptMessage;
85
86
  }
@@ -597,24 +598,24 @@ interface ForkResult {
597
598
  }
598
599
 
599
600
  /**
600
- * M80 — os verdicts terminais que um judge pode devolver.
601
+ * M80 — the terminal verdicts a judge can return.
601
602
  *
602
- * `"blocked"` entrou aqui neste milestone. `GoalResult.status` o carregava, mas o judge não tinha
603
- * como EMITI-LO: seu vocabulário era `done | continue | skipped`, então diante de um bloqueio real
604
- * ele podia dizer `continue` — e o loop repetia o mesmo turno até estourar o orçamento,
605
- * reportando `failed` por limite em vez de `blocked` por impossibilidade. Duas causas diferentes com
606
- * o mesmo desfecho visível.
603
+ * `"blocked"` was added here in this milestone. `GoalResult.status` already carried it, but the
604
+ * judge had no way to EMIT it: its vocabulary was `done | continue | skipped`, so facing a real
605
+ * blocker it could only say `continue` — and the loop repeated the same turn until it blew the
606
+ * budget, reporting `failed` on a limit rather than `blocked` on impossibility. Two different causes
607
+ * with the same visible outcome.
607
608
  *
608
609
  * @public
609
610
  */
610
611
  type Verdict = "done" | "continue" | "skipped" | "blocked";
611
612
  /**
612
- * M80 — resultado de uma chamada ao judge, agora público.
613
+ * M80 — the result of a judge call, now public.
613
614
  *
614
- * Era `internal/`, então um consumidor que quisesse tipar o retornopara reagir a `blocked` sem
615
- * string mágica precisava redeclarar a forma. É a mesma duplicação que o M78 fechou para a
616
- * hierarquia de erro: sem superfície pública, reimplementar é a única saída legal para quem está
617
- * atrás da fronteira de camadas.
615
+ * It was `internal/`, so a consumer wanting to type the returnto react to `blocked` without a
616
+ * magic string — had to redeclare the shape. It is the same duplication M78 closed for the error
617
+ * hierarchy: without a public surface, reimplementing is the only legal way out for anyone behind
618
+ * the layer boundary.
618
619
  *
619
620
  * @public
620
621
  */
@@ -622,9 +623,9 @@ interface JudgeResult {
622
623
  verdict: Verdict;
623
624
  reason: string;
624
625
  /**
625
- * `true` quando o texto não começou com um dos prefixos canônicos. O verdict vira `"continue"`
626
- * (fail-safe) para não parar cedo demais; o chamador conta falhas consecutivas e desiste via
627
- * `maxConsecutiveJudgeFailures`.
626
+ * `true` when the text did not start with one of the canonical prefixes. The verdict becomes
627
+ * `"continue"` (fail-safe) so the loop does not stop too early; the caller counts consecutive
628
+ * failures and gives up via `maxConsecutiveJudgeFailures`.
628
629
  */
629
630
  parseFailed: boolean;
630
631
  }
@@ -670,7 +671,7 @@ type GoalEvent = {
670
671
  } | {
671
672
  type: "judge_verdict";
672
673
  turn: number;
673
- /** M80 — `"blocked"` entrou: o judge pode declarar impossibilidade, não "continue". */
674
+ /** M80 — `"blocked"` was added: the judge can declare impossibility, not just "continue". */
674
675
  verdict: "done" | "continue" | "skipped" | "blocked";
675
676
  reason: string;
676
677
  parseFailed: boolean;
@@ -692,7 +693,7 @@ type GoalEvent = {
692
693
  interface GoalResult {
693
694
  status: "completed" | "failed" | "paused" | "budget_limited" | "blocked";
694
695
  turnsUsed: number;
695
- /** M55 — tokens somados ao longo do loop (0 quando `usage` esteve ausente — fail-open). */
696
+ /** M55 — tokens summed across the loop (0 when `usage` was absent — fail-open). */
696
697
  tokensUsed: number;
697
698
  finalResponse: string | undefined;
698
699
  }
@@ -712,9 +713,9 @@ interface GoalOptions {
712
713
  /** Hard cap on iterations (safety net against runaway). Default `20`. */
713
714
  maxTurns?: number;
714
715
  /**
715
- * M55 — token budget (Codex ext/goal parity, tool.rs:454-465). Soma `run.wait().usage.totalTokens`
716
- * por turno; ao cruzar, o loop para com status `budget_limited`. Omitido ilimitado (só maxTurns).
717
- * `usage` ausente nunca estoura o budget (fail-open).
716
+ * M55 — token budget (Codex ext/goal parity, tool.rs:454-465). Sums `run.wait().usage.totalTokens`
717
+ * per turn; on crossing it, the loop stops with status `budget_limited`. Omitted => unlimited (only
718
+ * maxTurns). A missing `usage` never blows the budget (fail-open).
718
719
  */
719
720
  tokenBudget?: number;
720
721
  /** Bail after N consecutive judge parse failures. Default `3` (ADR D121). */
@@ -724,11 +725,12 @@ interface GoalOptions {
724
725
  /** Override env for the judge auxiliary agent. Default `OPENROUTER_API_KEY` (EC-A). */
725
726
  judgeApiKey?: string;
726
727
  /**
727
- * M80 — o modelo do agente CONDUZIDO, base da derivação do judge quando `judgeModel` é omitido.
728
+ * M80 — the model of the DRIVEN agent, the basis for deriving the judge when `judgeModel` is
729
+ * omitted.
728
730
  *
729
- * Existe porque o default fixo (`openai/gpt-4o-mini`) resolve em OpenRouter: com chave
730
- * Anthropic 404, com bearer OAuth 401, e o goal queimava 3 turnos antes de falhar com razão
731
- * enganosa. Um judge que roda no mesmo modelo do chat funciona onde o chat funciona.
731
+ * It exists because the fixed default (`openai/gpt-4o-mini`) only resolves on OpenRouter: an
732
+ * Anthropic key gives 404, an OAuth bearer gives 401, and the goal burned 3 turns before failing
733
+ * with a misleading reason. A judge running on the chat's own model works wherever chat works.
732
734
  */
733
735
  agentModel?: string;
734
736
  /** Optional subgoals fed to the judge prompt. */
@@ -1818,9 +1820,11 @@ interface AgentOptions {
1818
1820
  *
1819
1821
  * `'run'` (DEFAULT, and the historical behaviour) spawns a client per `send` and drops it when the
1820
1822
  * run ends. `'session'` pools clients per `(agentId, server, config)` and keeps them across turns,
1821
- * which is what the reference does — Codex holds its connection manager in `SessionServices`
1822
- * (`core/src/state/service.rs:116`). Measured cost of the per-run path: 193 / 138 / 134 ms of
1823
- * spawn + handshake on every turn.
1823
+ * which is what the reference does — Codex holds its MCP runtime in `SessionServices`
1824
+ * (`codex-rs/core/src/state/service.rs:51-58`; theokit#155 corrected the earlier
1825
+ * `core/src/state/service.rs:116`, which named a parameter of `install_mcp_runtime`, not the
1826
+ * owning field). Measured cost of the per-run path: 193 / 138 / 134 ms of spawn + handshake on
1827
+ * every turn.
1824
1828
  *
1825
1829
  * Opt-in rather than default because it changes the FAILURE model: a server that dies mid-session
1826
1830
  * becomes a reachable state. One-shot and cron runs gain nothing from pooling and would pay that
@@ -2088,6 +2092,69 @@ type SDKAgentInfo = {
2088
2092
  env?: CloudEnv;
2089
2093
  repos?: string[];
2090
2094
  });
2095
+ /**
2096
+ * theokit#123 — one tool of a registered agent, as a reflection surface sees it.
2097
+ *
2098
+ * A projection, not the `CustomTool` itself: the handler is an executable that cannot cross a
2099
+ * process boundary and has no meaning to a caller enumerating a registry.
2100
+ *
2101
+ * @public
2102
+ */
2103
+ interface AgentToolDescription {
2104
+ name: string;
2105
+ description: string;
2106
+ /** The JSON Schema sent to the model verbatim — the tool's callable signature. */
2107
+ inputSchema: Record<string, unknown>;
2108
+ }
2109
+ /**
2110
+ * theokit#123 — one subagent of a registered agent (what theokit-studio calls a workflow).
2111
+ *
2112
+ * `prompt` is deliberately absent. Enumeration asks what a subagent IS and what it may call; its
2113
+ * system prompt is instructions, not signature, and a reflection endpoint that serializes it
2114
+ * publishes the agent's behaviour to anyone who can reach the endpoint.
2115
+ *
2116
+ * @public
2117
+ */
2118
+ interface AgentSubagentDescription {
2119
+ /** The key under `AgentOptions.agents` — how the parent addresses it. */
2120
+ name: string;
2121
+ description: string;
2122
+ /** `"inherit"` (or absent) means it runs on the parent's model. */
2123
+ model?: ModelSelection | "inherit";
2124
+ /** Tool whitelist, when the subagent is scoped to a subset of the parent's tools. */
2125
+ tools?: string[];
2126
+ }
2127
+ /**
2128
+ * theokit#123 — the read-only introspection of a registered agent, returned by `Agent.describe()`.
2129
+ *
2130
+ * `Agent.list()` / `Agent.get()` enumerate agents and `agent.skills.list()` covers skills; this
2131
+ * fills the remaining gap, so a reflection endpoint can report the live registry instead of
2132
+ * degrading to empty lists.
2133
+ *
2134
+ * `tools` and `subagents` are always arrays — never `undefined` — so a caller can distinguish
2135
+ * "this agent has none" from "the SDK did not say".
2136
+ *
2137
+ * @public
2138
+ */
2139
+ interface AgentDescription {
2140
+ agentId: string;
2141
+ /** Inlined rather than imported from the registry contract: `types/` stays a leaf (theokit#146). */
2142
+ runtime: "local" | "cloud";
2143
+ model?: ModelSelection;
2144
+ /**
2145
+ * The agent's DECLARED tool catalog.
2146
+ *
2147
+ * Plugin-contributed tools and the internal `think` tool (added when `reasoning` is on) are
2148
+ * assembled per run and are not knowable from the registry, so they are absent here. Stated
2149
+ * rather than implied: a reflection endpoint should not present this as the complete runtime set.
2150
+ */
2151
+ tools: readonly AgentToolDescription[];
2152
+ /**
2153
+ * Every subagent the runtime would resolve — file-based roles from `.theokit/agents/*.md` merged
2154
+ * with the inline `agentOptions.agents`, the same set `loadSubagents` builds for a run.
2155
+ */
2156
+ subagents: readonly AgentSubagentDescription[];
2157
+ }
2091
2158
  /**
2092
2159
  * Options for `Agent.list()`.
2093
2160
  *
@@ -2163,4 +2230,4 @@ interface ListResult<T> {
2163
2230
  nextCursor?: string;
2164
2231
  }
2165
2232
 
2166
- export { type MemoryToolSchema as $, type AgentOptions as A, type BudgetTracker as B, type CloudOptions as C, type CloudEnv as D, type CloudRepo as E, type ContextBudget as F, type GetAgentOptions as G, type ContextManagerKind as H, type InlineSkill as I, type JudgeResult as J, type ContextSnapshot as K, type LocalOptions as L, type MemorySettings as M, type ContextSource as N, type ContextSourceStatus as O, type ProviderRoutingSettings as P, type CreateSkillSpec as Q, type HookName as R, type SystemPromptResolver as S, type InvalidateCacheOptions as T, type MemoryAdapter as U, type MemoryAdapterCapabilities as V, type MemoryContext as W, type MemoryFact as X, type MemoryProviderHandle as Y, type MemoryProviderInitOptions as Z, type MemoryRevision as _, type AgentDefinition as a, type MemoryTurnMessage as a0, type PersonalityPreset as a1, type PluginContext as a2, type PostAssistantReplyContext as a3, type PostToolCallContext as a4, type PreToolCallContext as a5, type PreUserSendContext as a6, type PreUserSendResult as a7, type ProviderCapability as a8, type ProviderRoute as a9, type Verdict as aA, type ProviderTransform as aa, type ProviderTransformContext as ab, type RecordSessionSummaryArgs as ac, type ResolvedProviderRoute as ad, type RunUntilIterator as ae, type SDKAgentPlugins as af, type SDKAgentSkillDetail as ag, type SDKAgentSkills as ah, type SDKArtifact as ai, type SDKContextManager as aj, type SDKPluginMetadata as ak, type SDKProvidersManager as al, type SessionLifecycleContext as am, type SessionRecord as an, type SessionStore as ao, type SettingSource as ap, Skill as aq, type SkillsResolver as ar, type SkillsResolverContext as as, type SystemPromptContext as at, type SystemPromptMemoryFact as au, type SystemPromptSkillRef as av, type TelemetrySettings as aw, type ToolCallSummary as ax, type ToolResultTransformContext as ay, type TransformContext as az, type ContextSettings as b, type PluginsSettings as c, type SkillsSettings as d, type SDKAgent as e, type ListAgentsOptions as f, type ListResult as g, type SDKAgentInfo as h, type ListRunsOptions as i, type GetRunOptions as j, type AgentOperationOptions as k, type Plugin as l, type ProviderProfile as m, type GoalOptions as n, type GoalEvent as o, type GoalResult as p, type MemoryProvider as q, type MemoryId as r, type PreToolCallDecision as s, type SDKProvider as t, type ActiveMemoryPassArgs as u, type ActiveMemoryPassResult as v, type AgentMemory as w, type BudgetCheck as x, type BudgetTotal as y, type BudgetUsageEvent as z };
2233
+ export { type MemoryProviderHandle as $, type AgentOptions as A, type BudgetTracker as B, type CloudOptions as C, type BudgetCheck as D, type BudgetTotal as E, type BudgetUsageEvent as F, type GetAgentOptions as G, type CloudEnv as H, type InlineSkill as I, type JudgeResult as J, type CloudRepo as K, type LocalOptions as L, type MemorySettings as M, type ContextBudget as N, type ContextManagerKind as O, type ProviderRoutingSettings as P, type ContextSnapshot as Q, type ContextSource as R, type SystemPromptResolver as S, type ContextSourceStatus as T, type CreateSkillSpec as U, type HookName as V, type InvalidateCacheOptions as W, type MemoryAdapter as X, type MemoryAdapterCapabilities as Y, type MemoryContext as Z, type MemoryFact as _, type AgentDefinition as a, type MemoryProviderInitOptions as a0, type MemoryRevision as a1, type MemoryToolSchema as a2, type MemoryTurnMessage as a3, type PersonalityPreset as a4, type PluginContext as a5, type PostAssistantReplyContext as a6, type PostToolCallContext as a7, type PreToolCallContext as a8, type PreUserSendContext as a9, type ToolCallSummary as aA, type ToolResultTransformContext as aB, type TransformContext as aC, type Verdict as aD, type PreUserSendResult as aa, type ProviderCapability as ab, type ProviderRoute as ac, type ProviderTransform as ad, type ProviderTransformContext as ae, type RecordSessionSummaryArgs as af, type ResolvedProviderRoute as ag, type RunUntilIterator as ah, type SDKAgentPlugins as ai, type SDKAgentSkillDetail as aj, type SDKAgentSkills as ak, type SDKArtifact as al, type SDKContextManager as am, type SDKPluginMetadata as an, type SDKProvidersManager as ao, type SessionLifecycleContext as ap, type SessionRecord as aq, type SessionStore as ar, type SettingSource as as, Skill as at, type SkillsResolver as au, type SkillsResolverContext as av, type SystemPromptContext as aw, type SystemPromptMemoryFact as ax, type SystemPromptSkillRef as ay, type TelemetrySettings as az, type ContextSettings as b, type PluginsSettings as c, type SkillsSettings as d, type SDKAgent as e, type ListAgentsOptions as f, type ListResult as g, type SDKAgentInfo as h, type ListRunsOptions as i, type GetRunOptions as j, type AgentOperationOptions as k, type AgentDescription as l, type Plugin as m, type ProviderProfile as n, type GoalOptions as o, type GoalEvent as p, type GoalResult as q, type MemoryProvider as r, type MemoryId as s, type PreToolCallDecision as t, type SDKProvider as u, type ActiveMemoryPassArgs as v, type ActiveMemoryPassResult as w, type AgentMemory as x, type AgentSubagentDescription as y, type AgentToolDescription as z };
@@ -0,0 +1,23 @@
1
+ 'use strict';
2
+
3
+ var chunkXYOHKCYG_cjs = require('./chunk-XYOHKCYG.cjs');
4
+ require('./chunk-Z2CUEBXV.cjs');
5
+ require('./chunk-DGLLVCNB.cjs');
6
+ require('./chunk-BCQ3E2ZG.cjs');
7
+
8
+
9
+
10
+ Object.defineProperty(exports, "appendCompactBoundaryRecord", {
11
+ enumerable: true,
12
+ get: function () { return chunkXYOHKCYG_cjs.appendCompactBoundaryRecord; }
13
+ });
14
+ Object.defineProperty(exports, "persistTurn", {
15
+ enumerable: true,
16
+ get: function () { return chunkXYOHKCYG_cjs.persistTurn; }
17
+ });
18
+ Object.defineProperty(exports, "readSessionMessages", {
19
+ enumerable: true,
20
+ get: function () { return chunkXYOHKCYG_cjs.readSessionMessages; }
21
+ });
22
+ //# sourceMappingURL=agent-session-store-N4TVKHBU.cjs.map
23
+ //# sourceMappingURL=agent-session-store-N4TVKHBU.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"agent-session-store-N4TVKHBU.cjs"}
@@ -0,0 +1,6 @@
1
+ export { appendCompactBoundaryRecord, persistTurn, readSessionMessages } from './chunk-3I4B3OIX.js';
2
+ import './chunk-JRLXEYR4.js';
3
+ import './chunk-KX7JV5KM.js';
4
+ import './chunk-IVSD7L22.js';
5
+ //# sourceMappingURL=agent-session-store-RHMHP5DG.js.map
6
+ //# sourceMappingURL=agent-session-store-RHMHP5DG.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"agent-session-store-RHMHP5DG.js"}
package/dist/agent.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import { AgentBuilder } from "./agent-builder.js";
2
2
  import { type LiveAgentRegistry } from "./internal/runtime/registry/live-agent-registry.js";
3
- import type { AgentOperationOptions, AgentOptions, GetAgentOptions, GetRunOptions, ListAgentsOptions, ListResult, ListRunsOptions, SDKAgent, SDKAgentInfo } from "./types/agent.js";
3
+ import type { AgentDescription, AgentOperationOptions, AgentOptions, GetAgentOptions, GetRunOptions, ListAgentsOptions, ListResult, ListRunsOptions, SDKAgent, SDKAgentInfo } from "./types/agent.js";
4
4
  import type { Run, RunResult } from "./types/run.js";
5
+ import type { SessionMessage } from "./types/session-message.js";
5
6
  /**
6
7
  * Result of a one-shot {@link Agent.prompt} call.
7
8
  *
@@ -130,7 +131,7 @@ export declare class Agent {
130
131
  *
131
132
  * This bullet used to say the opposite ("Disposed agents are NOT auto-deleted...
132
133
  * call `Agent.delete(agentId)` first"). It was measured false in M91:
133
- * `tests/m91-getorcreate-apos-dispose.test.ts` builds an agent, disposes it, and
134
+ * `tests/m91-getorcreate-after-dispose.test.ts` builds an agent, disposes it, and
134
135
  * gets a different instance back. The claim was about the PERSISTENT registry and
135
136
  * read as being about the live cache — and consumers built around the wrong half.
136
137
  * The agent-builder's M85 interrupt rotates the session id to work around a
@@ -213,6 +214,41 @@ export declare class Agent {
213
214
  userText: string;
214
215
  assistantText: string;
215
216
  }): Promise<void>;
217
+ /**
218
+ * theokit#146 — read a LOCAL agent's persisted transcript as STRUCTURE, for rendering.
219
+ *
220
+ * A resumed session already replays correctly to the model, but a host had no way to draw it:
221
+ * the only projection available folded a tool call to the string `[tool call] NAME`, dropping the
222
+ * call id and every argument. A card UI got prose, so cross-restart resume was worth less than
223
+ * starting fresh — which is what at least one consumer did.
224
+ *
225
+ * Each returned message carries both projections: `text` (unchanged, what the model replay uses)
226
+ * and `parts` (`text` / `tool_use` / `tool_result` with ids, names, arguments and the
227
+ * `toolUseId` that correlates a result back to its call).
228
+ *
229
+ * Read-only and local-only: it opens the agent's session store and walks the transcript, exactly
230
+ * as {@link Agent.compact} and {@link Agent.injectSessionTurn} do. It appends nothing.
231
+ *
232
+ * @throws UnknownAgentError when `agentId` names no local agent.
233
+ * @public
234
+ */
235
+ static transcript(agentId: string): Promise<readonly SessionMessage[]>;
236
+ /**
237
+ * theokit#123 — read-only introspection of a registered agent's tools and subagents.
238
+ *
239
+ * `Agent.list()` / `Agent.get()` enumerate agents and `agent.skills.list()` covers skills, but
240
+ * tools and subagents lived only on `RegisteredAgent.options` — an internal contract. A
241
+ * reflection endpoint (theokit-studio's `theokit dev`) therefore had to report empty lists for
242
+ * both, and say so with an `unavailable_reason`.
243
+ *
244
+ * A PROJECTION, not the options object. Tool handlers and subagent prompts are stripped: a
245
+ * handler is an executable that cannot cross a process boundary, and a prompt is the agent's
246
+ * instructions rather than its signature — a reflection endpoint serializes what it is handed.
247
+ *
248
+ * @throws UnknownAgentError when `agentId` names no registered agent.
249
+ * @public
250
+ */
251
+ static describe(agentId: string): Promise<AgentDescription>;
216
252
  /**
217
253
  * Permanently delete a cloud agent.
218
254
  *
@@ -1,9 +1,9 @@
1
1
  'use strict';
2
2
 
3
- var chunkPAEJPLVN_cjs = require('../chunk-PAEJPLVN.cjs');
3
+ var chunk6NEHIHFU_cjs = require('../chunk-6NEHIHFU.cjs');
4
4
  var chunkC6Y6CWYD_cjs = require('../chunk-C6Y6CWYD.cjs');
5
- require('../chunk-MHCKWQR3.cjs');
6
- require('../chunk-LTCOPATU.cjs');
5
+ require('../chunk-IHFNRNTJ.cjs');
6
+ require('../chunk-BCQ3E2ZG.cjs');
7
7
 
8
8
  // src/internal/auth/oauth-device.ts
9
9
  var POLLING_SAFETY_MARGIN_MS = 3e3;
@@ -183,7 +183,7 @@ async function openaiDeviceLogin(config, deps, hooks) {
183
183
  "device poll returned no authorization_code"
184
184
  );
185
185
  }
186
- const tokens = await chunkPAEJPLVN_cjs.exchangeCode(
186
+ const tokens = await chunk6NEHIHFU_cjs.exchangeCode(
187
187
  config,
188
188
  { code: data.authorization_code, verifier: data.code_verifier },
189
189
  deps
@@ -227,47 +227,47 @@ function extractAccountId(tokens) {
227
227
 
228
228
  Object.defineProperty(exports, "CredentialError", {
229
229
  enumerable: true,
230
- get: function () { return chunkPAEJPLVN_cjs.CredentialError; }
230
+ get: function () { return chunk6NEHIHFU_cjs.CredentialError; }
231
231
  });
232
232
  Object.defineProperty(exports, "authFilePath", {
233
233
  enumerable: true,
234
- get: function () { return chunkPAEJPLVN_cjs.authFilePath; }
234
+ get: function () { return chunk6NEHIHFU_cjs.authFilePath; }
235
235
  });
236
236
  Object.defineProperty(exports, "credentialHome", {
237
237
  enumerable: true,
238
- get: function () { return chunkPAEJPLVN_cjs.credentialHome; }
238
+ get: function () { return chunk6NEHIHFU_cjs.credentialHome; }
239
239
  });
240
240
  Object.defineProperty(exports, "ensureFreshCredential", {
241
241
  enumerable: true,
242
- get: function () { return chunkPAEJPLVN_cjs.ensureFreshCredential; }
242
+ get: function () { return chunk6NEHIHFU_cjs.ensureFreshCredential; }
243
243
  });
244
244
  Object.defineProperty(exports, "exchangeCode", {
245
245
  enumerable: true,
246
- get: function () { return chunkPAEJPLVN_cjs.exchangeCode; }
246
+ get: function () { return chunk6NEHIHFU_cjs.exchangeCode; }
247
247
  });
248
248
  Object.defineProperty(exports, "persistOAuthTokens", {
249
249
  enumerable: true,
250
- get: function () { return chunkPAEJPLVN_cjs.persistOAuthTokens; }
250
+ get: function () { return chunk6NEHIHFU_cjs.persistOAuthTokens; }
251
251
  });
252
252
  Object.defineProperty(exports, "readAuthFile", {
253
253
  enumerable: true,
254
- get: function () { return chunkPAEJPLVN_cjs.readAuthFile; }
254
+ get: function () { return chunk6NEHIHFU_cjs.readAuthFile; }
255
255
  });
256
256
  Object.defineProperty(exports, "readStoredOAuth", {
257
257
  enumerable: true,
258
- get: function () { return chunkPAEJPLVN_cjs.readStoredOAuth; }
258
+ get: function () { return chunk6NEHIHFU_cjs.readStoredOAuth; }
259
259
  });
260
260
  Object.defineProperty(exports, "refreshOAuthTokens", {
261
261
  enumerable: true,
262
- get: function () { return chunkPAEJPLVN_cjs.refreshOAuthTokens; }
262
+ get: function () { return chunk6NEHIHFU_cjs.refreshOAuthTokens; }
263
263
  });
264
264
  Object.defineProperty(exports, "resolveCredential", {
265
265
  enumerable: true,
266
- get: function () { return chunkPAEJPLVN_cjs.resolveCredential; }
266
+ get: function () { return chunk6NEHIHFU_cjs.resolveCredential; }
267
267
  });
268
268
  Object.defineProperty(exports, "writeCredential", {
269
269
  enumerable: true,
270
- get: function () { return chunkPAEJPLVN_cjs.writeCredential; }
270
+ get: function () { return chunk6NEHIHFU_cjs.writeCredential; }
271
271
  });
272
272
  exports.deviceLogin = deviceLogin;
273
273
  exports.extractAccountId = extractAccountId;
@@ -1,8 +1,8 @@
1
- import { exchangeCode } from '../chunk-I35DI7ES.js';
2
- export { CredentialError, authFilePath, credentialHome, ensureFreshCredential, exchangeCode, persistOAuthTokens, readAuthFile, readStoredOAuth, refreshOAuthTokens, resolveCredential, writeCredential } from '../chunk-I35DI7ES.js';
1
+ import { exchangeCode } from '../chunk-DKFGUOWL.js';
2
+ export { CredentialError, authFilePath, credentialHome, ensureFreshCredential, exchangeCode, persistOAuthTokens, readAuthFile, readStoredOAuth, refreshOAuthTokens, resolveCredential, writeCredential } from '../chunk-DKFGUOWL.js';
3
3
  import { AuthCallbackError } from '../chunk-5NBUH3NO.js';
4
- import '../chunk-CD73YHEH.js';
5
- import '../chunk-TAPQWDW2.js';
4
+ import '../chunk-SG5ZWT6C.js';
5
+ import '../chunk-IVSD7L22.js';
6
6
 
7
7
  // src/internal/auth/oauth-device.ts
8
8
  var POLLING_SAFETY_MARGIN_MS = 3e3;
@@ -1,12 +1,12 @@
1
- import { submit, get } from './chunk-HEN5WXXI.js';
1
+ import { submit, get } from './chunk-LJX2SQV2.js';
2
2
  import './chunk-K2BQQ445.js';
3
- import { newPooledCredential, CredentialPool, withCredentialPool } from './chunk-EXQV452X.js';
4
- import { createSemaphore } from './chunk-NFCKEBHI.js';
3
+ import { newPooledCredential, CredentialPool, withCredentialPool } from './chunk-HWNVAUK4.js';
4
+ import { createSemaphore } from './chunk-PI4RO4GR.js';
5
5
  import './chunk-2XLKLVVR.js';
6
- import './chunk-CSZRJ4RE.js';
7
- import './chunk-56OXYUZE.js';
8
- import { ConfigurationError, TheokitAgentError } from './chunk-CD73YHEH.js';
9
- import './chunk-TAPQWDW2.js';
6
+ import './chunk-6EEYRFJC.js';
7
+ import './chunk-KX7JV5KM.js';
8
+ import { ConfigurationError, TheokitAgentError } from './chunk-SG5ZWT6C.js';
9
+ import { diag } from './chunk-IVSD7L22.js';
10
10
  import { randomUUID } from 'crypto';
11
11
 
12
12
  function validateBatchInput(prompts, options) {
@@ -132,7 +132,7 @@ async function runOne(item, index, options, deps) {
132
132
  try {
133
133
  await agent.dispose();
134
134
  } catch (disposeErr) {
135
- process.stderr.write(
135
+ diag(
136
136
  `[theokit-sdk] batch: agent.dispose failed for prompt ${index}: ${disposeErr instanceof Error ? disposeErr.message : String(disposeErr)}
137
137
  `
138
138
  );
@@ -201,7 +201,7 @@ async function safeCallResult(cb, result) {
201
201
  try {
202
202
  await cb(result);
203
203
  } catch (err) {
204
- process.stderr.write(
204
+ diag(
205
205
  `[theokit-sdk] batch: onResult callback threw: ${err instanceof Error ? err.message : String(err)}
206
206
  `
207
207
  );
@@ -212,7 +212,7 @@ function safeCallProgress(cb, progress) {
212
212
  try {
213
213
  cb(progress);
214
214
  } catch (err) {
215
- process.stderr.write(
215
+ diag(
216
216
  `[theokit-sdk] batch: onProgress callback threw: ${err instanceof Error ? err.message : String(err)}
217
217
  `
218
218
  );
@@ -237,5 +237,5 @@ function buildPoolsFromApiKeys(apiKeys, strategy) {
237
237
  }
238
238
 
239
239
  export { batchImpl, validateBatchInput };
240
- //# sourceMappingURL=batch-SY5GZLFD.js.map
241
- //# sourceMappingURL=batch-SY5GZLFD.js.map
240
+ //# sourceMappingURL=batch-6KQM3EBA.js.map
241
+ //# sourceMappingURL=batch-6KQM3EBA.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/batch.ts"],"names":[],"mappings":";;;;;;;;;;;AAgDO,SAAS,kBAAA,CACd,SACA,OAAA,EACM;AACN,EAAA,MAAM,EAAE,aAAY,GAAI,OAAA;AACxB,EAAA,IAAI,WAAA,KAAgB,WAAc,CAAC,MAAA,CAAO,UAAU,WAAW,CAAA,IAAK,cAAc,CAAA,CAAA,EAAI;AACpF,IAAA,MAAM,IAAI,kBAAA;AAAA,MACR,2DAA2D,WAAW,CAAA,CAAA;AAAA,MACtE,EAAE,MAAM,qBAAA;AAAsB,KAChC;AAAA,EACF;AACA,EAAA,KAAA,IAAS,CAAA,GAAI,CAAA,EAAG,CAAA,G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AAI,QAAA,CAAS,SAAS,CAAA,EAAG;AACzB,IAAA,MAAM,UAAU,QAAA,CAAS,GAAA;AAAA,MAAI,CAAC,KAAA,EAAO,CAAA,KACnC,mBAAA,CAAoB,EAAE,QAAA,EAAU,WAAA,EAAa,KAAA,EAAO,QAAA,EAAU,CAAA,EAAG,MAAA,EAAQ,QAAA,EAAU;AAAA,KACrF;AACA,IAAA,KAAA,CAAM,GAAA;AAAA,MACJ,QAAA;AAAA,MACA,IAAI,cAAA,CAAe,QAAA,EAAU,SAAS,QAAA,GAAW,QAAQ,KAAK,YAAY;AAAA,KAC5E;AAAA,EACF;AACA,EAAA,OAAO,KAAA;AACT","file":"batch-6KQM3EBA.js","sourcesContent":["/**\n * `Agent.batch(prompts, options)` core (ADRs D134-D140).\n *\n * Fans out N prompts via bounded concurrency, isolates failures per-prompt,\n * preserves input order in the result array, supports streaming callbacks\n * + AbortSignal. The credential pool (D131) is shared across all\n * in-flight agents via `withCredentialPool` ALS scope (EC-A fix).\n *\n * @internal\n */\n\nimport { randomUUID } from \"node:crypto\";\nimport { ConfigurationError, TheokitAgentError } from \"./errors.js\";\nimport { diag } from \"./internal/diagnostics.js\";\nimport { CredentialPool, newPooledCredential } from \"./internal/llm/credential-pool.js\";\nimport { withCredentialPool } from \"./internal/llm/credential-pool-context.js\";\nimport type { CredentialPoolStrategy } from \"./internal/llm/credential-pool-types.js\";\nimport { createSemaphore } from \"./internal/runtime/concurrency/async-semaphore.js\";\nimport { get as taskRegistryGet, submit as taskRegistrySubmit } from \"./internal/task/registry.js\";\nimport type { AgentOptions, SDKAgent } from \"./types/agent.js\";\nimport type { BatchItem, BatchOptions, BatchProgress, BatchResult } from \"./types/batch.js\";\n\n/** DI contract — keeps batch.ts cycle-free from agent.ts. @internal */\ninterface BatchDeps {\n create: (options: AgentOptions) => Promise<SDKAgent>;\n}\n\n/**\n * Pre-flight boundary validation for `Agent.batch` (arch-review Gap 3).\n *\n * Mirrors the in-repo `validateAgentOptions` / `validateCronExpression`\n * pattern: throws `ConfigurationError` with a stable code on the first\n * violation, returns silently otherwise. Pure — no I/O.\n *\n * Rules:\n * - `concurrency`, when provided, must be a positive integer (rejects\n * 0/negative/non-integer/NaN/Infinity). Previously this was caught only\n * incidentally deep inside `createSemaphore` with a leaky \"permits\"\n * message, AND after task wrapping (dangling Task on invalid input).\n * - every prompt item must carry a non-empty string prompt. Previously\n * `normalizeItem` passed `prompt: \"\"` / non-string straight to\n * `agent.send`. (Whitespace-only strings are intentionally NOT rejected —\n * an empty string is a structural error; judging content is not this\n * validator's job, and the repo's property tests treat any length>=1\n * string as a valid prompt.)\n *\n * @internal\n */\nexport function validateBatchInput(\n prompts: ReadonlyArray<string | BatchItem>,\n options: BatchOptions,\n): void {\n const { concurrency } = options;\n if (concurrency !== undefined && (!Number.isInteger(concurrency) || concurrency < 1)) {\n throw new ConfigurationError(\n `Agent.batch concurrency must be a positive integer, got ${concurrency}`,\n { code: \"invalid_concurrency\" },\n );\n }\n for (let i = 0; i < prompts.length; i++) {\n const item = prompts[i];\n const prompt = typeof item === \"string\" ? item : item?.prompt;\n if (typeof prompt !== \"string\" || prompt.length === 0) {\n throw new ConfigurationError(`Agent.batch prompt at index ${i} must be a non-empty string`, {\n code: \"invalid_batch_item\",\n });\n }\n }\n}\n\n/**\n * Run N prompts in parallel with bounded concurrency.\n *\n * @internal\n */\nexport async function batchImpl(\n prompts: ReadonlyArray<string | BatchItem>,\n options: BatchOptions,\n deps: BatchDeps,\n): Promise<BatchResult[]> {\n // EC-1: empty array → no work, no agents created.\n if (prompts.length === 0) return [];\n\n // Pre-flight boundary validation (arch-review Gap 3). MUST run before pool\n // build AND before wrapBatchAsTask so invalid input never registers a\n // dangling Task or builds a credential pool (fail-fast, Rule 8).\n validateBatchInput(prompts, options);\n\n // EC-A fix: build credential pools ONCE and share via AsyncLocalStorage.\n // Without this each Agent.create() would build its own pool from identical\n // apiKeys → 4× rate-limit wastage per concurrency window.\n const sharedPools = buildPoolsFromApiKeys(\n options.providers?.apiKeys,\n options.providers?.credentialPoolStrategy,\n );\n const exec = (): Promise<BatchResult[]> => runBatch(prompts, options, deps);\n const withPool = (): Promise<BatchResult[]> =>\n sharedPools.size > 0 ? withCredentialPool(sharedPools, exec) : exec();\n // T3.3: opt-in Task wrapping (ADRs D363, D374). Register the whole\n // batch as a single Task (kind=\"batch\") with `b-` prefix (D368/EC-5).\n if (options.task !== undefined) {\n return wrapBatchAsTask(prompts.length, options.task, withPool);\n }\n return withPool();\n}\n\nasync function wrapBatchAsTask(\n total: number,\n taskOpt: true | { id?: string; meta?: Record<string, unknown> },\n exec: () => Promise<BatchResult[]>,\n): Promise<BatchResult[]> {\n const opts = taskOpt === true ? {} : taskOpt;\n const id = opts.id ?? `b-${randomUUID()}`;\n const meta: Record<string, unknown> = {\n total,\n ...(opts.meta ?? {}),\n };\n let results: BatchResult[] = [];\n await taskRegistrySubmit({\n kind: \"batch\",\n work: async (ctx) => {\n results = await exec();\n const succeeded = results.filter((r) => r.ok).length;\n const failed = results.length - succeeded;\n ctx.emit({ total: results.length, succeeded, failed });\n return { total: results.length, succeeded, failed };\n },\n id,\n meta,\n allowReservedPrefix: true,\n });\n // submit returns immediately with a queued handle. Wait for terminal.\n for (let i = 0; i < 5000; i++) {\n const h = await taskRegistryGet(id);\n if (h?.state === \"finished\" || h?.state === \"error\" || h?.state === \"cancelled\") break;\n await new Promise((r) => setTimeout(r, 5));\n }\n return results;\n}\n\nasync function runBatch(\n prompts: ReadonlyArray<string | BatchItem>,\n options: BatchOptions,\n deps: BatchDeps,\n): Promise<BatchResult[]> {\n const requested = options.concurrency ?? 4;\n // createSemaphore throws on invalid (EC-2).\n // EC-3: cap to prompts.length to avoid idle workers.\n const effective = Math.min(requested, prompts.length);\n const semaphore = createSemaphore(effective);\n const items = prompts.map(normalizeItem);\n const results: BatchResult[] = new Array(items.length);\n const counters = { completed: 0, failed: 0 };\n let aborted = false;\n\n const onAbort = (): void => {\n aborted = true;\n };\n options.signal?.addEventListener(\"abort\", onAbort);\n // EC-C: pre-aborted signal — treat as already-aborted before any work.\n if (options.signal?.aborted === true) aborted = true;\n\n try {\n await Promise.all(\n items.map(async (item, index) => {\n const release = await semaphore.acquire();\n try {\n if (aborted) {\n results[index] = abortResult(item, index, options.signal);\n } else {\n results[index] = await runOne(item, index, options, deps);\n }\n } finally {\n release();\n }\n if (results[index].ok) counters.completed += 1;\n else counters.failed += 1;\n await safeCallResult(options.onResult, results[index]);\n safeCallProgress(options.onProgress, {\n total: items.length,\n completed: counters.completed,\n failed: counters.failed,\n inFlight: semaphore.inFlight(),\n pending: Math.max(0, semaphore.pending() - semaphore.inFlight()),\n });\n }),\n );\n } finally {\n options.signal?.removeEventListener(\"abort\", onAbort);\n }\n\n return options.filter ? results.filter(options.filter) : results;\n}\n\nasync function runOne(\n item: BatchItem,\n index: number,\n options: BatchOptions,\n deps: BatchDeps,\n): Promise<BatchResult> {\n const t0 = Date.now();\n const agentOpts = buildAgentOptions(item, options);\n\n try {\n const agent = await deps.create(agentOpts);\n try {\n const run = await agent.send(item.prompt);\n const result = await run.wait();\n return {\n ok: true,\n index,\n prompt: item.prompt,\n result,\n ...(item.metadata !== undefined ? { metadata: item.metadata } : {}),\n durationMs: Date.now() - t0,\n };\n } finally {\n // EC-8: dispose failure → stderr warn, don't fail the result.\n try {\n await agent.dispose();\n } catch (disposeErr) {\n // theokit#147 — the interceptable channel; a batch run must not write onto a TUI's frame.\n diag(\n `[theokit-sdk] batch: agent.dispose failed for prompt ${index}: ${\n disposeErr instanceof Error ? disposeErr.message : String(disposeErr)\n }\\n`,\n );\n }\n }\n } catch (err) {\n return {\n ok: false,\n index,\n prompt: item.prompt,\n error: toTheokitError(err),\n ...(item.metadata !== undefined ? { metadata: item.metadata } : {}),\n durationMs: Date.now() - t0,\n };\n }\n}\n\nfunction buildAgentOptions(item: BatchItem, options: BatchOptions): AgentOptions {\n const {\n concurrency: _c,\n filter: _f,\n onResult: _or,\n onProgress: _op,\n signal: _s,\n task: _t,\n ...rest\n } = options;\n void _c;\n void _f;\n void _or;\n void _op;\n void _s;\n void _t;\n const agentOpts = rest as AgentOptions;\n if (item.systemPrompt !== undefined) {\n return { ...agentOpts, systemPrompt: item.systemPrompt };\n }\n return agentOpts;\n}\n\nfunction normalizeItem(promptOrItem: string | BatchItem): BatchItem {\n return typeof promptOrItem === \"string\" ? { prompt: promptOrItem } : promptOrItem;\n}\n\nfunction abortResult(item: BatchItem, index: number, signal?: AbortSignal): BatchResult {\n // EC-D: propagate signal.reason when set (preserves caller's error).\n let error: TheokitAgentError;\n if (signal?.reason instanceof TheokitAgentError) {\n error = signal.reason;\n } else if (signal?.reason instanceof Error) {\n error = new TheokitAgentError(signal.reason.message, {\n code: \"aborted\",\n cause: signal.reason,\n });\n } else {\n error = new TheokitAgentError(\"Batch aborted via AbortSignal\", { code: \"aborted\" });\n }\n return {\n ok: false,\n index,\n prompt: item.prompt,\n error,\n ...(item.metadata !== undefined ? { metadata: item.metadata } : {}),\n durationMs: 0,\n };\n}\n\nfunction toTheokitError(err: unknown): TheokitAgentError {\n if (err instanceof TheokitAgentError) return err;\n if (err instanceof Error) {\n return new TheokitAgentError(err.message, { code: \"unknown\", cause: err });\n }\n return new TheokitAgentError(String(err), { code: \"unknown\" });\n}\n\nasync function safeCallResult(cb: BatchOptions[\"onResult\"], result: BatchResult): Promise<void> {\n if (cb === undefined) return;\n try {\n await cb(result);\n } catch (err) {\n diag(\n `[theokit-sdk] batch: onResult callback threw: ${\n err instanceof Error ? err.message : String(err)\n }\\n`,\n );\n }\n}\n\nfunction safeCallProgress(cb: BatchOptions[\"onProgress\"], progress: BatchProgress): void {\n if (cb === undefined) return;\n try {\n cb(progress);\n } catch (err) {\n diag(\n `[theokit-sdk] batch: onProgress callback threw: ${\n err instanceof Error ? err.message : String(err)\n }\\n`,\n );\n }\n}\n\n/**\n * EC-A: construct shared pools from options.apiKeys. Empty/invalid → empty Map.\n *\n * @internal\n */\nfunction buildPoolsFromApiKeys(\n apiKeys: Record<string, string[]> | undefined,\n strategy: Record<string, CredentialPoolStrategy> | undefined,\n): Map<string, CredentialPool> {\n const pools = new Map<string, CredentialPool>();\n if (apiKeys === undefined) return pools;\n for (const [provider, keys] of Object.entries(apiKeys)) {\n if (!Array.isArray(keys)) continue;\n const filtered = keys.filter((k): k is string => typeof k === \"string\" && k.length > 0);\n if (filtered.length < 2) continue; // 1-key pools aren't pools\n const entries = filtered.map((token, i) =>\n newPooledCredential({ provider, accessToken: token, priority: i, source: \"manual\" }),\n );\n pools.set(\n provider,\n new CredentialPool(provider, entries, strategy?.[provider] ?? \"fill_first\"),\n );\n }\n return pools;\n}\n"]}