@theokit/sdk 4.23.0 → 4.25.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 (374) hide show
  1. package/dist/a2a/index.cjs +10 -171
  2. package/dist/a2a/index.cjs.map +1 -1
  3. package/dist/a2a/index.js +3 -170
  4. package/dist/a2a/index.js.map +1 -1
  5. package/dist/agent-factory-registry-UU46BUMU.cjs +16 -0
  6. package/dist/agent-factory-registry-UU46BUMU.cjs.map +1 -0
  7. package/dist/agent-factory-registry-ZVTABLEY.js +3 -0
  8. package/dist/agent-factory-registry-ZVTABLEY.js.map +1 -0
  9. package/dist/auth/index.cjs +63 -343
  10. package/dist/auth/index.cjs.map +1 -1
  11. package/dist/auth/index.js +6 -318
  12. package/dist/auth/index.js.map +1 -1
  13. package/dist/batch-2FSD2UNL.cjs +244 -0
  14. package/dist/batch-2FSD2UNL.cjs.map +1 -0
  15. package/dist/batch-MR2HKYMS.js +241 -0
  16. package/dist/batch-MR2HKYMS.js.map +1 -0
  17. package/dist/chunk-2HRYBRD7.cjs +31 -0
  18. package/dist/chunk-2HRYBRD7.cjs.map +1 -0
  19. package/dist/chunk-2MF3IE2D.cjs +2863 -0
  20. package/dist/chunk-2MF3IE2D.cjs.map +1 -0
  21. package/dist/chunk-2ONFGMBV.js +6 -0
  22. package/dist/chunk-2ONFGMBV.js.map +1 -0
  23. package/dist/chunk-2SFBB54R.js +23 -0
  24. package/dist/chunk-2SFBB54R.js.map +1 -0
  25. package/dist/chunk-2XLKLVVR.js +18 -0
  26. package/dist/chunk-2XLKLVVR.js.map +1 -0
  27. package/dist/chunk-4HKMQEPX.js +458 -0
  28. package/dist/chunk-4HKMQEPX.js.map +1 -0
  29. package/dist/chunk-4SXHEZIV.cjs +240 -0
  30. package/dist/chunk-4SXHEZIV.cjs.map +1 -0
  31. package/dist/chunk-4VPXM6UU.js +10 -0
  32. package/dist/chunk-4VPXM6UU.js.map +1 -0
  33. package/dist/chunk-4WL52CXU.cjs +148 -0
  34. package/dist/chunk-4WL52CXU.cjs.map +1 -0
  35. package/dist/chunk-5NBUH3NO.js +39 -0
  36. package/dist/chunk-5NBUH3NO.js.map +1 -0
  37. package/dist/chunk-5PZMMF4H.js +43 -0
  38. package/dist/chunk-5PZMMF4H.js.map +1 -0
  39. package/dist/chunk-6CLRANZA.js +289 -0
  40. package/dist/chunk-6CLRANZA.js.map +1 -0
  41. package/dist/chunk-6JSIEDKL.cjs +121 -0
  42. package/dist/chunk-6JSIEDKL.cjs.map +1 -0
  43. package/dist/chunk-6M4ODB2V.cjs +145 -0
  44. package/dist/chunk-6M4ODB2V.cjs.map +1 -0
  45. package/dist/chunk-6X6ID4MO.js +20 -0
  46. package/dist/chunk-6X6ID4MO.js.map +1 -0
  47. package/dist/chunk-77FOZCOT.js +165 -0
  48. package/dist/chunk-77FOZCOT.js.map +1 -0
  49. package/dist/chunk-7AD3ZTZL.js +25 -0
  50. package/dist/chunk-7AD3ZTZL.js.map +1 -0
  51. package/dist/chunk-7GFX45DD.js +57 -0
  52. package/dist/chunk-7GFX45DD.js.map +1 -0
  53. package/dist/chunk-7RMWOMDB.cjs +460 -0
  54. package/dist/chunk-7RMWOMDB.cjs.map +1 -0
  55. package/dist/chunk-7S7KKUO6.cjs +45 -0
  56. package/dist/chunk-7S7KKUO6.cjs.map +1 -0
  57. package/dist/chunk-7W7ZWMLQ.js +99 -0
  58. package/dist/chunk-7W7ZWMLQ.js.map +1 -0
  59. package/dist/chunk-A44COQJJ.cjs +353 -0
  60. package/dist/chunk-A44COQJJ.cjs.map +1 -0
  61. package/dist/chunk-AKSBP7OO.js +185 -0
  62. package/dist/chunk-AKSBP7OO.js.map +1 -0
  63. package/dist/chunk-ANIZEWTU.cjs +196 -0
  64. package/dist/chunk-ANIZEWTU.cjs.map +1 -0
  65. package/dist/chunk-BEURCLDV.cjs +139 -0
  66. package/dist/chunk-BEURCLDV.cjs.map +1 -0
  67. package/dist/chunk-BFWPZMG7.js +379 -0
  68. package/dist/chunk-BFWPZMG7.js.map +1 -0
  69. package/dist/chunk-BUUUWQMB.cjs +34 -0
  70. package/dist/chunk-BUUUWQMB.cjs.map +1 -0
  71. package/dist/chunk-BV2MWEMV.cjs +26 -0
  72. package/dist/chunk-BV2MWEMV.cjs.map +1 -0
  73. package/dist/chunk-BWT67BI4.cjs +268 -0
  74. package/dist/chunk-BWT67BI4.cjs.map +1 -0
  75. package/dist/chunk-BXV2QUIC.js +191 -0
  76. package/dist/chunk-BXV2QUIC.js.map +1 -0
  77. package/dist/chunk-C6Y6CWYD.cjs +44 -0
  78. package/dist/chunk-C6Y6CWYD.cjs.map +1 -0
  79. package/dist/chunk-C7PICHRF.cjs +68 -0
  80. package/dist/chunk-C7PICHRF.cjs.map +1 -0
  81. package/dist/chunk-CAH3G4IS.js +13 -0
  82. package/dist/chunk-CAH3G4IS.js.map +1 -0
  83. package/dist/chunk-CJ6YJ2L3.cjs +10590 -0
  84. package/dist/chunk-CJ6YJ2L3.cjs.map +1 -0
  85. package/dist/chunk-D42XHI4O.cjs +565 -0
  86. package/dist/chunk-D42XHI4O.cjs.map +1 -0
  87. package/dist/chunk-DGRZNMTU.js +104 -0
  88. package/dist/chunk-DGRZNMTU.js.map +1 -0
  89. package/dist/chunk-DUK5WMKJ.js +71 -0
  90. package/dist/chunk-DUK5WMKJ.js.map +1 -0
  91. package/dist/chunk-EEZ7CFMM.js +14 -0
  92. package/dist/chunk-EEZ7CFMM.js.map +1 -0
  93. package/dist/chunk-EPYZOCOL.cjs +82 -0
  94. package/dist/chunk-EPYZOCOL.cjs.map +1 -0
  95. package/dist/chunk-EVADEGM7.cjs +168 -0
  96. package/dist/chunk-EVADEGM7.cjs.map +1 -0
  97. package/dist/chunk-F3XVLFLM.js +10573 -0
  98. package/dist/chunk-F3XVLFLM.js.map +1 -0
  99. package/dist/chunk-FD2UT76F.js +3 -0
  100. package/dist/chunk-FD2UT76F.js.map +1 -0
  101. package/dist/chunk-FV3YEMQ7.js +179 -0
  102. package/dist/chunk-FV3YEMQ7.js.map +1 -0
  103. package/dist/chunk-G2F67XUR.cjs +184 -0
  104. package/dist/chunk-G2F67XUR.cjs.map +1 -0
  105. package/dist/chunk-G6GO6BXD.js +994 -0
  106. package/dist/chunk-G6GO6BXD.js.map +1 -0
  107. package/dist/chunk-GIW4L6HY.cjs +27 -0
  108. package/dist/chunk-GIW4L6HY.cjs.map +1 -0
  109. package/dist/chunk-GJAGKFTR.js +74 -0
  110. package/dist/chunk-GJAGKFTR.js.map +1 -0
  111. package/dist/chunk-HFPGOTVF.cjs +324 -0
  112. package/dist/chunk-HFPGOTVF.cjs.map +1 -0
  113. package/dist/chunk-HRA3CPGG.js +486 -0
  114. package/dist/chunk-HRA3CPGG.js.map +1 -0
  115. package/dist/chunk-HZQEDNF6.js +66 -0
  116. package/dist/chunk-HZQEDNF6.js.map +1 -0
  117. package/dist/chunk-IT3PWBW4.cjs +19 -0
  118. package/dist/chunk-IT3PWBW4.cjs.map +1 -0
  119. package/dist/chunk-JD74LN7R.cjs +171 -0
  120. package/dist/chunk-JD74LN7R.cjs.map +1 -0
  121. package/dist/chunk-JTFYYKDT.js +135 -0
  122. package/dist/chunk-JTFYYKDT.js.map +1 -0
  123. package/dist/chunk-K2BQQ445.js +30 -0
  124. package/dist/chunk-K2BQQ445.js.map +1 -0
  125. package/dist/chunk-KAP4GJHO.js +546 -0
  126. package/dist/chunk-KAP4GJHO.js.map +1 -0
  127. package/dist/chunk-KIO7QFIV.cjs +223 -0
  128. package/dist/chunk-KIO7QFIV.cjs.map +1 -0
  129. package/dist/chunk-KSKU6JY6.cjs +71 -0
  130. package/dist/chunk-KSKU6JY6.cjs.map +1 -0
  131. package/dist/chunk-LSLPF6OI.cjs +192 -0
  132. package/dist/chunk-LSLPF6OI.cjs.map +1 -0
  133. package/dist/chunk-LU7VALW5.js +312 -0
  134. package/dist/chunk-LU7VALW5.js.map +1 -0
  135. package/dist/chunk-LUSXDZPV.cjs +296 -0
  136. package/dist/chunk-LUSXDZPV.cjs.map +1 -0
  137. package/dist/chunk-M72RJVPC.js +69 -0
  138. package/dist/chunk-M72RJVPC.js.map +1 -0
  139. package/dist/chunk-MQLCZ4HJ.cjs +1010 -0
  140. package/dist/chunk-MQLCZ4HJ.cjs.map +1 -0
  141. package/dist/chunk-MUUQ2WFJ.cjs +4 -0
  142. package/dist/chunk-MUUQ2WFJ.cjs.map +1 -0
  143. package/dist/chunk-MZ5ZRORA.cjs +496 -0
  144. package/dist/chunk-MZ5ZRORA.cjs.map +1 -0
  145. package/dist/chunk-N24XBYNX.cjs +140 -0
  146. package/dist/chunk-N24XBYNX.cjs.map +1 -0
  147. package/dist/chunk-NINIJCHU.cjs +23 -0
  148. package/dist/chunk-NINIJCHU.cjs.map +1 -0
  149. package/dist/chunk-NRSH7RJY.js +2841 -0
  150. package/dist/chunk-NRSH7RJY.js.map +1 -0
  151. package/dist/chunk-OIYQBUW4.cjs +111 -0
  152. package/dist/chunk-OIYQBUW4.cjs.map +1 -0
  153. package/dist/chunk-PNVDQL5Y.cjs +15 -0
  154. package/dist/chunk-PNVDQL5Y.cjs.map +1 -0
  155. package/dist/chunk-POQT2OIF.js +214 -0
  156. package/dist/chunk-POQT2OIF.js.map +1 -0
  157. package/dist/chunk-QUTUJ6P6.cjs +76 -0
  158. package/dist/chunk-QUTUJ6P6.cjs.map +1 -0
  159. package/dist/chunk-S2BBRVQX.js +68 -0
  160. package/dist/chunk-S2BBRVQX.js.map +1 -0
  161. package/dist/chunk-S5RCBTSF.js +145 -0
  162. package/dist/chunk-S5RCBTSF.js.map +1 -0
  163. package/dist/chunk-S7OEXQMI.cjs +136 -0
  164. package/dist/chunk-S7OEXQMI.cjs.map +1 -0
  165. package/dist/chunk-SKWVAQAY.js +129 -0
  166. package/dist/chunk-SKWVAQAY.js.map +1 -0
  167. package/dist/chunk-SQLZ7ONU.js +152 -0
  168. package/dist/chunk-SQLZ7ONU.js.map +1 -0
  169. package/dist/chunk-TIZ4TS5V.cjs +72 -0
  170. package/dist/chunk-TIZ4TS5V.cjs.map +1 -0
  171. package/dist/chunk-TQKCU7CL.js +142 -0
  172. package/dist/chunk-TQKCU7CL.js.map +1 -0
  173. package/dist/chunk-U54XCYG3.js +116 -0
  174. package/dist/chunk-U54XCYG3.js.map +1 -0
  175. package/dist/chunk-U6QGZHPN.js +29 -0
  176. package/dist/chunk-U6QGZHPN.js.map +1 -0
  177. package/dist/chunk-UCFONJBG.js +79 -0
  178. package/dist/chunk-UCFONJBG.js.map +1 -0
  179. package/dist/chunk-UJ7IQJAG.js +141 -0
  180. package/dist/chunk-UJ7IQJAG.js.map +1 -0
  181. package/dist/chunk-UVNG67DG.js +253 -0
  182. package/dist/chunk-UVNG67DG.js.map +1 -0
  183. package/dist/chunk-V4XRLPEF.js +25 -0
  184. package/dist/chunk-V4XRLPEF.js.map +1 -0
  185. package/dist/chunk-VJ26EKGJ.cjs +28 -0
  186. package/dist/chunk-VJ26EKGJ.cjs.map +1 -0
  187. package/dist/chunk-VK7MAV65.cjs +90 -0
  188. package/dist/chunk-VK7MAV65.cjs.map +1 -0
  189. package/dist/chunk-VYCKUKPA.cjs +106 -0
  190. package/dist/chunk-VYCKUKPA.cjs.map +1 -0
  191. package/dist/chunk-VYHJZVL5.cjs +29 -0
  192. package/dist/chunk-VYHJZVL5.cjs.map +1 -0
  193. package/dist/chunk-WA3FO4R7.js +155 -0
  194. package/dist/chunk-WA3FO4R7.js.map +1 -0
  195. package/dist/chunk-WJVHMTKB.cjs +12 -0
  196. package/dist/chunk-WJVHMTKB.cjs.map +1 -0
  197. package/dist/chunk-WLKFWQSJ.js +333 -0
  198. package/dist/chunk-WLKFWQSJ.js.map +1 -0
  199. package/dist/chunk-WPZTYOUX.cjs +59 -0
  200. package/dist/chunk-WPZTYOUX.cjs.map +1 -0
  201. package/dist/chunk-X2FR4OIT.js +27 -0
  202. package/dist/chunk-X2FR4OIT.js.map +1 -0
  203. package/dist/chunk-XIG2IE3L.js +134 -0
  204. package/dist/chunk-XIG2IE3L.js.map +1 -0
  205. package/dist/chunk-YLQQX5W2.cjs +20 -0
  206. package/dist/chunk-YLQQX5W2.cjs.map +1 -0
  207. package/dist/chunk-YPEPCZHF.cjs +147 -0
  208. package/dist/chunk-YPEPCZHF.cjs.map +1 -0
  209. package/dist/chunk-YPQF26X7.cjs +8 -0
  210. package/dist/chunk-YPQF26X7.cjs.map +1 -0
  211. package/dist/chunk-YU6KON2I.cjs +160 -0
  212. package/dist/chunk-YU6KON2I.cjs.map +1 -0
  213. package/dist/chunk-Z2OC3UIW.cjs +388 -0
  214. package/dist/chunk-Z2OC3UIW.cjs.map +1 -0
  215. package/dist/chunk-ZZWTY3RX.js +230 -0
  216. package/dist/chunk-ZZWTY3RX.js.map +1 -0
  217. package/dist/compact-session-OO2GD76G.js +17 -0
  218. package/dist/compact-session-OO2GD76G.js.map +1 -0
  219. package/dist/compact-session-OO7NVWPB.cjs +54 -0
  220. package/dist/compact-session-OO7NVWPB.cjs.map +1 -0
  221. package/dist/compaction.cjs +54 -303
  222. package/dist/compaction.cjs.map +1 -1
  223. package/dist/compaction.js +3 -292
  224. package/dist/compaction.js.map +1 -1
  225. package/dist/concurrency.cjs +9 -81
  226. package/dist/concurrency.cjs.map +1 -1
  227. package/dist/concurrency.js +5 -80
  228. package/dist/concurrency.js.map +1 -1
  229. package/dist/context-GWANQLX4.js +5 -0
  230. package/dist/context-GWANQLX4.js.map +1 -0
  231. package/dist/context-KNWVTZSY.cjs +22 -0
  232. package/dist/context-KNWVTZSY.cjs.map +1 -0
  233. package/dist/cron.cjs +44 -20675
  234. package/dist/cron.cjs.map +1 -1
  235. package/dist/cron.js +38 -20675
  236. package/dist/cron.js.map +1 -1
  237. package/dist/errors.cjs +78 -470
  238. package/dist/errors.cjs.map +1 -1
  239. package/dist/errors.js +2 -455
  240. package/dist/errors.js.map +1 -1
  241. package/dist/eval.cjs +72 -20410
  242. package/dist/eval.cjs.map +1 -1
  243. package/dist/eval.js +59 -20401
  244. package/dist/eval.js.map +1 -1
  245. package/dist/executor-ORJS5GV2.js +981 -0
  246. package/dist/executor-ORJS5GV2.js.map +1 -0
  247. package/dist/executor-Y4MKPIUD.cjs +985 -0
  248. package/dist/executor-Y4MKPIUD.cjs.map +1 -0
  249. package/dist/filesystem/index.cjs +7 -112
  250. package/dist/filesystem/index.cjs.map +1 -1
  251. package/dist/filesystem/index.js +4 -109
  252. package/dist/filesystem/index.js.map +1 -1
  253. package/dist/fork-agent-RSV4E3EA.js +61 -0
  254. package/dist/fork-agent-RSV4E3EA.js.map +1 -0
  255. package/dist/fork-agent-Y2IK2RYU.cjs +64 -0
  256. package/dist/fork-agent-Y2IK2RYU.cjs.map +1 -0
  257. package/dist/fs-session-store-KAUQYSGI.cjs +17 -0
  258. package/dist/fs-session-store-KAUQYSGI.cjs.map +1 -0
  259. package/dist/fs-session-store-ZKB5NN37.js +8 -0
  260. package/dist/fs-session-store-ZKB5NN37.js.map +1 -0
  261. package/dist/generate-object-H3RNAM6S.cjs +20 -0
  262. package/dist/generate-object-H3RNAM6S.cjs.map +1 -0
  263. package/dist/generate-object-YJPDV5BS.js +7 -0
  264. package/dist/generate-object-YJPDV5BS.js.map +1 -0
  265. package/dist/index-manager-CB6I7XFQ.cjs +19 -0
  266. package/dist/index-manager-CB6I7XFQ.cjs.map +1 -0
  267. package/dist/index-manager-L27Q3QAC.js +10 -0
  268. package/dist/index-manager-L27Q3QAC.js.map +1 -0
  269. package/dist/index.cjs +371 -22887
  270. package/dist/index.cjs.map +1 -1
  271. package/dist/index.js +92 -22712
  272. package/dist/index.js.map +1 -1
  273. package/dist/inject-session-6MJUSGZP.cjs +27 -0
  274. package/dist/inject-session-6MJUSGZP.cjs.map +1 -0
  275. package/dist/inject-session-KOFHS5K3.js +25 -0
  276. package/dist/inject-session-KOFHS5K3.js.map +1 -0
  277. package/dist/internal/auth/credential-store.d.ts +20 -3
  278. package/dist/internal/persistence/index.cjs +93 -508
  279. package/dist/internal/persistence/index.cjs.map +1 -1
  280. package/dist/internal/persistence/index.js +11 -489
  281. package/dist/internal/persistence/index.js.map +1 -1
  282. package/dist/internal/security/index.cjs +44 -361
  283. package/dist/internal/security/index.cjs.map +1 -1
  284. package/dist/internal/security/index.js +4 -355
  285. package/dist/internal/security/index.js.map +1 -1
  286. package/dist/judge-call-7CF7D334.cjs +95 -0
  287. package/dist/judge-call-7CF7D334.cjs.map +1 -0
  288. package/dist/judge-call-VIMNK5TA.js +92 -0
  289. package/dist/judge-call-VIMNK5TA.js.map +1 -0
  290. package/dist/models.cjs +24 -913
  291. package/dist/models.cjs.map +1 -1
  292. package/dist/models.js +11 -901
  293. package/dist/models.js.map +1 -1
  294. package/dist/oauth-transaction-store-7CKHPQRN.cjs +32 -0
  295. package/dist/oauth-transaction-store-7CKHPQRN.cjs.map +1 -0
  296. package/dist/oauth-transaction-store-W74I6EFD.js +3 -0
  297. package/dist/oauth-transaction-store-W74I6EFD.js.map +1 -0
  298. package/dist/path-safety.cjs +31 -200
  299. package/dist/path-safety.cjs.map +1 -1
  300. package/dist/path-safety.js +3 -197
  301. package/dist/path-safety.js.map +1 -1
  302. package/dist/persistence.cjs +73 -393
  303. package/dist/persistence.cjs.map +1 -1
  304. package/dist/persistence.js +9 -381
  305. package/dist/persistence.js.map +1 -1
  306. package/dist/project.cjs +8 -112
  307. package/dist/project.cjs.map +1 -1
  308. package/dist/project.js +6 -110
  309. package/dist/project.js.map +1 -1
  310. package/dist/registry-34IWWDQQ.js +9 -0
  311. package/dist/registry-34IWWDQQ.js.map +1 -0
  312. package/dist/registry-APYDISL6.cjs +46 -0
  313. package/dist/registry-APYDISL6.cjs.map +1 -0
  314. package/dist/retry.cjs +7 -87
  315. package/dist/retry.cjs.map +1 -1
  316. package/dist/retry.js +3 -90
  317. package/dist/retry.js.map +1 -1
  318. package/dist/run-to-completion-J73I6IY4.cjs +48 -0
  319. package/dist/run-to-completion-J73I6IY4.cjs.map +1 -0
  320. package/dist/run-to-completion-JDPIUKSH.js +3 -0
  321. package/dist/run-to-completion-JDPIUKSH.js.map +1 -0
  322. package/dist/run-until-2PX4QBHZ.js +168 -0
  323. package/dist/run-until-2PX4QBHZ.js.map +1 -0
  324. package/dist/run-until-DB3LVGZS.cjs +171 -0
  325. package/dist/run-until-DB3LVGZS.cjs.map +1 -0
  326. package/dist/sandbox/index.cjs +35 -337
  327. package/dist/sandbox/index.cjs.map +1 -1
  328. package/dist/sandbox/index.js +7 -323
  329. package/dist/sandbox/index.js.map +1 -1
  330. package/dist/sanitize/index.cjs +5 -112
  331. package/dist/sanitize/index.cjs.map +1 -1
  332. package/dist/sanitize/index.js +1 -114
  333. package/dist/sanitize/index.js.map +1 -1
  334. package/dist/server/auth/index.cjs +35 -175
  335. package/dist/server/auth/index.cjs.map +1 -1
  336. package/dist/server/auth/index.js +7 -161
  337. package/dist/server/auth/index.js.map +1 -1
  338. package/dist/server/errors-envelope.cjs +17 -328
  339. package/dist/server/errors-envelope.cjs.map +1 -1
  340. package/dist/server/errors-envelope.js +4 -317
  341. package/dist/server/errors-envelope.js.map +1 -1
  342. package/dist/session-transcript-LPNZR3YS.cjs +46 -0
  343. package/dist/session-transcript-LPNZR3YS.cjs.map +1 -0
  344. package/dist/session-transcript-T7LGJUGW.js +5 -0
  345. package/dist/session-transcript-T7LGJUGW.js.map +1 -0
  346. package/dist/skills.cjs +12 -280
  347. package/dist/skills.cjs.map +1 -1
  348. package/dist/skills.js +4 -282
  349. package/dist/skills.js.map +1 -1
  350. package/dist/stream-object-QEQJJDTI.cjs +20 -0
  351. package/dist/stream-object-QEQJJDTI.cjs.map +1 -0
  352. package/dist/stream-object-WUQSSRY2.js +7 -0
  353. package/dist/stream-object-WUQSSRY2.js.map +1 -0
  354. package/dist/stream-to-completion-DFJ5T3BK.js +30 -0
  355. package/dist/stream-to-completion-DFJ5T3BK.js.map +1 -0
  356. package/dist/stream-to-completion-H2MHISSK.cjs +32 -0
  357. package/dist/stream-to-completion-H2MHISSK.cjs.map +1 -0
  358. package/dist/subagents.cjs +2 -8
  359. package/dist/subagents.cjs.map +1 -1
  360. package/dist/subagents.js +1 -7
  361. package/dist/subagents.js.map +1 -1
  362. package/dist/subscription/index.cjs +4 -17
  363. package/dist/subscription/index.cjs.map +1 -1
  364. package/dist/subscription/index.js +3 -16
  365. package/dist/subscription/index.js.map +1 -1
  366. package/dist/task-store.cjs +16 -258
  367. package/dist/task-store.cjs.map +1 -1
  368. package/dist/task-store.js +4 -259
  369. package/dist/task-store.js.map +1 -1
  370. package/dist/workflow.cjs +71 -2797
  371. package/dist/workflow.cjs.map +1 -1
  372. package/dist/workflow.js +8 -2812
  373. package/dist/workflow.js.map +1 -1
  374. package/package.json +1 -1
@@ -0,0 +1,985 @@
1
+ 'use strict';
2
+
3
+ var chunkBWT67BI4_cjs = require('./chunk-BWT67BI4.cjs');
4
+ var chunkBUUUWQMB_cjs = require('./chunk-BUUUWQMB.cjs');
5
+ var chunk7S7KKUO6_cjs = require('./chunk-7S7KKUO6.cjs');
6
+ require('./chunk-TIZ4TS5V.cjs');
7
+ var chunkA44COQJJ_cjs = require('./chunk-A44COQJJ.cjs');
8
+ var chunkBEURCLDV_cjs = require('./chunk-BEURCLDV.cjs');
9
+
10
+ // src/internal/workflow/ctx.ts
11
+ var WorkflowSuspendedSentinel = class extends Error {
12
+ constructor(payload) {
13
+ super("__workflow_suspended__");
14
+ this.payload = payload;
15
+ }
16
+ payload;
17
+ name = "WorkflowSuspendedSentinel";
18
+ };
19
+ function makeStepContext(runId, signal, state) {
20
+ return {
21
+ runId,
22
+ signal,
23
+ log: {
24
+ debug: (msg, attrs) => emit("debug", runId, msg, attrs),
25
+ info: (msg, attrs) => emit("info", runId, msg, attrs),
26
+ warn: (msg, attrs) => emit("warn", runId, msg, attrs)
27
+ },
28
+ suspend: async (payload) => {
29
+ throw new WorkflowSuspendedSentinel(payload);
30
+ },
31
+ // SE29 — read reflects the current shared state; write goes through the
32
+ // controller (which validates against `stateSchema`).
33
+ get state() {
34
+ return state.getState();
35
+ },
36
+ setState: (next) => state.setState(next)
37
+ };
38
+ }
39
+ function emit(level, runId, msg, attrs) {
40
+ const tag = `[workflow ${runId}]`;
41
+ if (attrs !== void 0) {
42
+ if (level === "warn") console.warn(tag, msg, attrs);
43
+ else console.log(tag, msg, attrs);
44
+ } else {
45
+ if (level === "warn") console.warn(tag, msg);
46
+ else console.log(tag, msg);
47
+ }
48
+ }
49
+ function combineSignals(...signals) {
50
+ const valid = signals.filter((s) => s !== void 0);
51
+ if (valid.length === 0) return new AbortController().signal;
52
+ if (valid.length === 1) return valid[0];
53
+ const ctrl = new AbortController();
54
+ for (const s of valid) {
55
+ if (s.aborted) {
56
+ ctrl.abort(s.reason);
57
+ break;
58
+ }
59
+ s.addEventListener("abort", () => ctrl.abort(s.reason), { once: true });
60
+ }
61
+ return ctrl.signal;
62
+ }
63
+
64
+ // src/internal/workflow/error-shape.ts
65
+ function errToShape(err) {
66
+ if (err instanceof Error) {
67
+ return { name: err.name, message: err.message };
68
+ }
69
+ return { name: "Error", message: String(err) };
70
+ }
71
+
72
+ // src/internal/workflow/executor-helpers.ts
73
+ function assembleRun(params) {
74
+ return {
75
+ id: params.runId,
76
+ name: params.name,
77
+ status: params.status,
78
+ startedAt: params.startedAt,
79
+ endedAt: Date.now(),
80
+ stepResults: params.stepResults,
81
+ ...params.output !== void 0 ? { output: params.output } : {},
82
+ ...params.error !== void 0 ? { error: params.error } : {}
83
+ };
84
+ }
85
+ function abortRun(name, runId, startedAt, stepResults, signal) {
86
+ return assembleRun({
87
+ runId,
88
+ name,
89
+ status: "cancelled",
90
+ stepResults,
91
+ startedAt,
92
+ error: { name: "AbortError", message: String(signal.reason ?? "Aborted") }
93
+ });
94
+ }
95
+ function validateWorkflowSchema(schema, value) {
96
+ if (schema === void 0) return void 0;
97
+ let parsed;
98
+ try {
99
+ parsed = schema.safeParse(value);
100
+ } catch {
101
+ return "schema uses async refinements, which whole-workflow validation does not support (use a synchronous Zod schema)";
102
+ }
103
+ if (parsed.success) return void 0;
104
+ return parsed.error.issues.map((issue) => `${issue.path.join(".") || "(root)"}: ${issue.message}`).join("; ");
105
+ }
106
+ function makeStateController(options, initial) {
107
+ let current = initial;
108
+ return {
109
+ getState: () => current,
110
+ setState: (next) => {
111
+ const issues = validateWorkflowSchema(options.stateSchema, next);
112
+ if (issues !== void 0) throw new chunkBWT67BI4_cjs.WorkflowStateError(options.name, issues);
113
+ current = next;
114
+ }
115
+ };
116
+ }
117
+
118
+ // src/internal/workflow/run-id.ts
119
+ function mintRunId() {
120
+ return `wfr-${globalThis.crypto.randomUUID().replace(/-/g, "").slice(0, 8)}`;
121
+ }
122
+
123
+ // src/internal/workflow/single-flight.ts
124
+ var registry = /* @__PURE__ */ new Map();
125
+ function key(workflowId, runId) {
126
+ return `${workflowId}:${runId}`;
127
+ }
128
+ function acquireSingleFlight(workflowId, runId, workflowName) {
129
+ const k = key(workflowId, runId);
130
+ if (registry.has(k)) {
131
+ throw new chunkBWT67BI4_cjs.WorkflowAlreadyRunningError(workflowName, runId);
132
+ }
133
+ const controller = new AbortController();
134
+ registry.set(k, { controller });
135
+ return {
136
+ signal: controller.signal,
137
+ release: () => {
138
+ registry.delete(k);
139
+ }
140
+ };
141
+ }
142
+
143
+ // src/internal/workflow/retry-policy.ts
144
+ var DEFAULT_NON_RETRYABLE = ["AbortError", "WorkflowSnapshotNotFoundError", "ConfigurationError"];
145
+ function backoffConfigFromPolicy(policy) {
146
+ return {
147
+ max: policy.maxAttempts,
148
+ init: policy.initialBackoffMs ?? 1e3,
149
+ coef: policy.backoffCoefficient ?? 2,
150
+ cap: policy.maximumBackoffMs ?? 3e4,
151
+ nonRetryable: new Set(policy.nonRetryableErrors ?? DEFAULT_NON_RETRYABLE)
152
+ };
153
+ }
154
+ function throwIfAborted(signal) {
155
+ if (signal.aborted) {
156
+ throw new DOMException(String(signal.reason ?? "Aborted"), "AbortError");
157
+ }
158
+ }
159
+ function shouldRethrow(err, attempt, cfg) {
160
+ const errName = err instanceof Error ? err.name : "Error";
161
+ return cfg.nonRetryable.has(errName) || attempt === cfg.max;
162
+ }
163
+ async function tryOnce(fn, attempt, cfg, signal) {
164
+ try {
165
+ const value = await fn();
166
+ return { value, attempts: attempt };
167
+ } catch (err) {
168
+ if (shouldRethrow(err, attempt, cfg)) throw err;
169
+ await abortableSleep(Math.min(cfg.init * cfg.coef ** (attempt - 1), cfg.cap), signal);
170
+ return { kind: "retry" };
171
+ }
172
+ }
173
+ async function withRetry(fn, policy, signal) {
174
+ const cfg = backoffConfigFromPolicy(policy);
175
+ for (let attempt = 1; attempt <= cfg.max; attempt += 1) {
176
+ throwIfAborted(signal);
177
+ const result = await tryOnce(fn, attempt, cfg, signal);
178
+ if ("value" in result) return result;
179
+ }
180
+ throw new Error("withRetry: exhausted attempts without throwing");
181
+ }
182
+ async function abortableSleep(ms, signal) {
183
+ if (signal.aborted) {
184
+ throw new DOMException(String(signal.reason ?? "Aborted"), "AbortError");
185
+ }
186
+ return new Promise((resolve, reject) => {
187
+ const timer = setTimeout(() => {
188
+ cleanup();
189
+ resolve();
190
+ }, ms);
191
+ const onAbort = () => {
192
+ clearTimeout(timer);
193
+ cleanup();
194
+ reject(new DOMException(String(signal.reason ?? "Aborted"), "AbortError"));
195
+ };
196
+ const cleanup = () => {
197
+ signal.removeEventListener("abort", onAbort);
198
+ };
199
+ signal.addEventListener("abort", onAbort, { once: true });
200
+ });
201
+ }
202
+
203
+ // src/internal/workflow/step-agent.ts
204
+ async function runAgentStep(step, input, ctx) {
205
+ const startedAt = Date.now();
206
+ const agentId = step.agent.agentId;
207
+ if (typeof agentId === "string" && agentId.startsWith("bc-")) {
208
+ return {
209
+ stepId: step.id,
210
+ kind: "agent",
211
+ status: "failed",
212
+ attempts: 0,
213
+ durationMs: Date.now() - startedAt,
214
+ error: errToShape(
215
+ new chunkA44COQJJ_cjs.UnsupportedRunOperationError(
216
+ `Workflow agent steps not supported on CloudAgent yet (D244). agent="${agentId}", step="${step.id}"`,
217
+ "workflow"
218
+ )
219
+ )
220
+ };
221
+ }
222
+ let prompt;
223
+ try {
224
+ prompt = typeof step.promptTemplate === "string" ? step.promptTemplate : step.promptTemplate(input);
225
+ } catch (err) {
226
+ return {
227
+ stepId: step.id,
228
+ kind: "agent",
229
+ status: "failed",
230
+ attempts: 0,
231
+ durationMs: Date.now() - startedAt,
232
+ error: errToShape(err)
233
+ };
234
+ }
235
+ if (typeof prompt !== "string" || prompt.length === 0) {
236
+ return {
237
+ stepId: step.id,
238
+ kind: "agent",
239
+ status: "failed",
240
+ attempts: 0,
241
+ durationMs: Date.now() - startedAt,
242
+ error: errToShape(
243
+ new Error(`agentStep "${step.id}": rendered prompt must be a non-empty string`)
244
+ )
245
+ };
246
+ }
247
+ const exec = async () => {
248
+ const run = await step.agent.send(
249
+ prompt,
250
+ step.origin !== void 0 ? { origin: step.origin } : void 0
251
+ );
252
+ const result = await run.wait();
253
+ if (result.status === "finished") {
254
+ return result.result ?? "";
255
+ }
256
+ if (result.status === "error") {
257
+ throw result.error ?? new Error("agent.send errored");
258
+ }
259
+ throw new Error(`Unexpected agent status: ${result.status}`);
260
+ };
261
+ try {
262
+ const { value, attempts } = step.retry !== void 0 ? await withRetry(exec, step.retry, ctx.signal) : { value: await exec(), attempts: 1 };
263
+ return {
264
+ stepId: step.id,
265
+ kind: "agent",
266
+ status: "completed",
267
+ attempts,
268
+ durationMs: Date.now() - startedAt,
269
+ output: value
270
+ };
271
+ } catch (err) {
272
+ if (err instanceof WorkflowSuspendedSentinel) throw err;
273
+ return {
274
+ stepId: step.id,
275
+ kind: "agent",
276
+ status: "failed",
277
+ attempts: 1,
278
+ durationMs: Date.now() - startedAt,
279
+ error: errToShape(err)
280
+ };
281
+ }
282
+ }
283
+
284
+ // src/internal/workflow/step-branch.ts
285
+ async function runBranchStep(step, input, ctx, options, prevStepResults, dispatch) {
286
+ const startedAt = Date.now();
287
+ for (let i = 0; i < step.predicates.length; i += 1) {
288
+ const pair = step.predicates[i];
289
+ const [predicate, branch] = pair;
290
+ let matched = false;
291
+ try {
292
+ matched = await Promise.resolve(predicate(input));
293
+ } catch (err) {
294
+ const errText = err instanceof Error ? err.message : String(err);
295
+ console.warn(
296
+ chunkBEURCLDV_cjs.redactSecrets(
297
+ `[workflow] branch "${step.id}" predicate ${i} threw, treating as no-match: ${errText}`
298
+ )
299
+ );
300
+ }
301
+ if (matched) {
302
+ const r = await runInnerSequence(branch, input, ctx, options, prevStepResults, dispatch);
303
+ return {
304
+ ...r,
305
+ stepId: step.id,
306
+ kind: "branch",
307
+ durationMs: Date.now() - startedAt
308
+ };
309
+ }
310
+ }
311
+ if (step.fallback !== void 0) {
312
+ const r = await runInnerSequence(step.fallback, input, ctx, options, prevStepResults, dispatch);
313
+ return {
314
+ ...r,
315
+ stepId: step.id,
316
+ kind: "branch",
317
+ durationMs: Date.now() - startedAt
318
+ };
319
+ }
320
+ return {
321
+ stepId: step.id,
322
+ kind: "branch",
323
+ status: "skipped",
324
+ attempts: 0,
325
+ durationMs: Date.now() - startedAt,
326
+ output: input
327
+ };
328
+ }
329
+ async function runInnerSequence(branch, input, ctx, options, prevStepResults, dispatch) {
330
+ let acc = input;
331
+ let lastAttempts = 1;
332
+ for (const inner of branch) {
333
+ const r = await dispatch(inner, acc, ctx, options, prevStepResults);
334
+ lastAttempts = r.attempts;
335
+ if (r.status === "failed") {
336
+ return {
337
+ stepId: inner.id,
338
+ kind: "branch",
339
+ status: "failed",
340
+ attempts: r.attempts,
341
+ durationMs: 0,
342
+ error: r.error ?? errToShape(new Error("branch inner step failed"))
343
+ };
344
+ }
345
+ acc = r.output;
346
+ }
347
+ return {
348
+ stepId: "__branch-completed__",
349
+ kind: "branch",
350
+ status: "completed",
351
+ attempts: lastAttempts,
352
+ durationMs: 0,
353
+ output: acc
354
+ };
355
+ }
356
+
357
+ // src/internal/workflow/step-dowhile.ts
358
+ async function runDowhileStep(step, input, ctx, options, prevStepResults, dispatch) {
359
+ const startedAt = Date.now();
360
+ const maxIter = step.maxIterations ?? 100;
361
+ let acc = input;
362
+ let i = 0;
363
+ while (true) {
364
+ if (i >= maxIter) {
365
+ return {
366
+ stepId: step.id,
367
+ kind: "dowhile",
368
+ status: "failed",
369
+ attempts: i,
370
+ durationMs: Date.now() - startedAt,
371
+ error: errToShape(new chunkBWT67BI4_cjs.WorkflowMaxIterationsExceededError(step.id, maxIter))
372
+ };
373
+ }
374
+ const r = await dispatch(step.step, acc, ctx, options, prevStepResults);
375
+ if (r.status === "failed") {
376
+ return {
377
+ stepId: step.id,
378
+ kind: "dowhile",
379
+ status: "failed",
380
+ attempts: i + 1,
381
+ durationMs: Date.now() - startedAt,
382
+ error: r.error
383
+ };
384
+ }
385
+ acc = r.output;
386
+ i += 1;
387
+ let shouldContinue = false;
388
+ try {
389
+ shouldContinue = await Promise.resolve(step.condFn(acc, i));
390
+ } catch (err) {
391
+ return {
392
+ stepId: step.id,
393
+ kind: "dowhile",
394
+ status: "failed",
395
+ attempts: i,
396
+ durationMs: Date.now() - startedAt,
397
+ error: errToShape(err)
398
+ };
399
+ }
400
+ if (!shouldContinue) break;
401
+ }
402
+ return {
403
+ stepId: step.id,
404
+ kind: "dowhile",
405
+ status: "completed",
406
+ attempts: i,
407
+ durationMs: Date.now() - startedAt,
408
+ output: acc
409
+ };
410
+ }
411
+
412
+ // src/internal/workflow/step-fn.ts
413
+ function failedFnResult(stepId, attempts, startedAt, err) {
414
+ return {
415
+ stepId,
416
+ kind: "fn",
417
+ status: "failed",
418
+ attempts,
419
+ durationMs: Date.now() - startedAt,
420
+ error: errToShape(err)
421
+ };
422
+ }
423
+ function validate(schema, value) {
424
+ if (schema === void 0) return void 0;
425
+ schema.parse(value);
426
+ return void 0;
427
+ }
428
+ async function execWithRetry(step, input, ctx) {
429
+ const exec = async () => step.fn(input, ctx);
430
+ if (step.retry !== void 0) return withRetry(exec, step.retry, ctx.signal);
431
+ return { value: await exec(), attempts: 1 };
432
+ }
433
+ async function runFnStep(step, input, ctx) {
434
+ const startedAt = Date.now();
435
+ if (step.compensate !== void 0) {
436
+ return failedFnResult(
437
+ step.id,
438
+ 0,
439
+ startedAt,
440
+ new chunkBWT67BI4_cjs.WorkflowCompensateNotImplementedError(step.id)
441
+ );
442
+ }
443
+ try {
444
+ validate(step.inputSchema, input);
445
+ } catch (err) {
446
+ return failedFnResult(step.id, 0, startedAt, err);
447
+ }
448
+ try {
449
+ const { value, attempts } = await execWithRetry(step, input, ctx);
450
+ try {
451
+ validate(step.outputSchema, value);
452
+ } catch (err) {
453
+ return failedFnResult(step.id, attempts, startedAt, err);
454
+ }
455
+ return {
456
+ stepId: step.id,
457
+ kind: "fn",
458
+ status: "completed",
459
+ attempts,
460
+ durationMs: Date.now() - startedAt,
461
+ output: value
462
+ };
463
+ } catch (err) {
464
+ if (err instanceof WorkflowSuspendedSentinel) throw err;
465
+ return failedFnResult(step.id, 1, startedAt, err);
466
+ }
467
+ }
468
+
469
+ // src/internal/workflow/step-foreach.ts
470
+ async function runForeachStep(step, _input, ctx, options, prevStepResults, dispatch) {
471
+ const startedAt = Date.now();
472
+ const sourceResult = prevStepResults.find((r) => r.stepId === step.iterableFrom);
473
+ if (sourceResult === void 0) {
474
+ return {
475
+ stepId: step.id,
476
+ kind: "foreach",
477
+ status: "failed",
478
+ attempts: 0,
479
+ durationMs: Date.now() - startedAt,
480
+ error: errToShape(
481
+ new Error(
482
+ `foreach.iterableFrom "${step.iterableFrom}" not found in top-level steps. It must reference an earlier top-level step ID \u2014 nested step IDs inside parallel/branch/foreach blocks are not visible here.`
483
+ )
484
+ )
485
+ };
486
+ }
487
+ const items = sourceResult.output;
488
+ if (!Array.isArray(items)) {
489
+ return {
490
+ stepId: step.id,
491
+ kind: "foreach",
492
+ status: "failed",
493
+ attempts: 0,
494
+ durationMs: Date.now() - startedAt,
495
+ error: errToShape(
496
+ new Error(
497
+ `foreach.iterableFrom "${step.iterableFrom}" output must be Array, got ${typeof items}.`
498
+ )
499
+ )
500
+ };
501
+ }
502
+ if (items.length === 0) {
503
+ return {
504
+ stepId: step.id,
505
+ kind: "foreach",
506
+ status: "completed",
507
+ attempts: 1,
508
+ durationMs: Date.now() - startedAt,
509
+ output: []
510
+ };
511
+ }
512
+ const concurrency = step.concurrency ?? 4;
513
+ const sem = chunk7S7KKUO6_cjs.createSemaphore(Math.max(1, Math.min(concurrency, items.length)));
514
+ const failures = [];
515
+ const outputs = new Array(items.length);
516
+ await Promise.all(
517
+ items.map(async (item, idx) => {
518
+ const release = await sem.acquire();
519
+ try {
520
+ const r = await dispatch(step.step, item, ctx, options, prevStepResults);
521
+ if (r.status === "failed") {
522
+ failures.push(new Error(`foreach item ${idx} failed: ${r.error?.message ?? "unknown"}`));
523
+ } else {
524
+ outputs[idx] = r.output;
525
+ }
526
+ } finally {
527
+ release();
528
+ }
529
+ })
530
+ );
531
+ if (failures.length > 0) {
532
+ return {
533
+ stepId: step.id,
534
+ kind: "foreach",
535
+ status: "failed",
536
+ attempts: 1,
537
+ durationMs: Date.now() - startedAt,
538
+ error: errToShape(
539
+ new AggregateError(failures, `foreach "${step.id}" had ${failures.length} failure(s)`)
540
+ )
541
+ };
542
+ }
543
+ return {
544
+ stepId: step.id,
545
+ kind: "foreach",
546
+ status: "completed",
547
+ attempts: 1,
548
+ durationMs: Date.now() - startedAt,
549
+ output: outputs
550
+ };
551
+ }
552
+
553
+ // src/internal/workflow/step-parallel.ts
554
+ async function runParallelStep(step, input, ctx, options, _prevStepResults, dispatch) {
555
+ const startedAt = Date.now();
556
+ const policy = step.errorPolicy ?? "fail-fast";
557
+ const branchCount = step.branches.length;
558
+ if (branchCount === 0) {
559
+ return {
560
+ stepId: step.id,
561
+ kind: "parallel",
562
+ status: "completed",
563
+ attempts: 1,
564
+ durationMs: Date.now() - startedAt,
565
+ output: []
566
+ };
567
+ }
568
+ const concurrency = step.concurrency ?? branchCount;
569
+ const sem = chunk7S7KKUO6_cjs.createSemaphore(Math.max(1, Math.min(concurrency, branchCount)));
570
+ const failFastCtrl = policy === "fail-fast" ? new AbortController() : void 0;
571
+ const branchSignal = policy === "fail-fast" ? mergeSignals(ctx.signal, failFastCtrl.signal) : ctx.signal;
572
+ const semBranchPromises = step.branches.map(async (branch, branchIdx) => {
573
+ const release = await sem.acquire();
574
+ try {
575
+ return await runBranch(
576
+ branch,
577
+ input,
578
+ { ...ctx, signal: branchSignal },
579
+ options,
580
+ dispatch,
581
+ branchIdx
582
+ );
583
+ } finally {
584
+ release();
585
+ }
586
+ });
587
+ if (policy === "fail-fast") {
588
+ try {
589
+ const outputs2 = await Promise.all(semBranchPromises);
590
+ return {
591
+ stepId: step.id,
592
+ kind: "parallel",
593
+ status: "completed",
594
+ attempts: 1,
595
+ durationMs: Date.now() - startedAt,
596
+ output: outputs2
597
+ };
598
+ } catch (err) {
599
+ failFastCtrl?.abort(err);
600
+ const settled2 = await Promise.allSettled(semBranchPromises);
601
+ const errors = settled2.filter((s) => s.status === "rejected").map((s) => s.reason instanceof Error ? s.reason : new Error(String(s.reason)));
602
+ return {
603
+ stepId: step.id,
604
+ kind: "parallel",
605
+ status: "failed",
606
+ attempts: 1,
607
+ durationMs: Date.now() - startedAt,
608
+ error: errToShape(new chunkBWT67BI4_cjs.WorkflowParallelError(errors, step.id)),
609
+ output: void 0
610
+ };
611
+ }
612
+ }
613
+ const settled = await Promise.allSettled(semBranchPromises);
614
+ const outputs = settled.map(
615
+ (s) => s.status === "fulfilled" ? { ok: true, value: s.value } : { ok: false, error: errToShape(s.reason) }
616
+ );
617
+ return {
618
+ stepId: step.id,
619
+ kind: "parallel",
620
+ status: "completed",
621
+ attempts: 1,
622
+ durationMs: Date.now() - startedAt,
623
+ output: outputs
624
+ };
625
+ }
626
+ async function runBranch(branch, input, ctx, options, dispatch, branchIdx) {
627
+ let acc = input;
628
+ for (const inner of branch) {
629
+ const r = await dispatch(inner, acc, ctx, options, []);
630
+ if (r.status === "failed") {
631
+ throw new Error(
632
+ `parallel branch ${branchIdx} step "${inner.id}" failed: ${r.error?.message ?? "unknown"}`
633
+ );
634
+ }
635
+ acc = r.output;
636
+ }
637
+ return acc;
638
+ }
639
+ function mergeSignals(a, b) {
640
+ if (a.aborted) return a;
641
+ if (b.aborted) return b;
642
+ const ctrl = new AbortController();
643
+ const onAbortA = () => ctrl.abort(a.reason);
644
+ const onAbortB = () => ctrl.abort(b.reason);
645
+ a.addEventListener("abort", onAbortA, { once: true });
646
+ b.addEventListener("abort", onAbortB, { once: true });
647
+ return ctrl.signal;
648
+ }
649
+
650
+ // src/internal/workflow/step-sleep.ts
651
+ async function runSleepStep(step, input, ctx) {
652
+ const startedAt = Date.now();
653
+ try {
654
+ await abortableSleep(step.durationMs, ctx.signal);
655
+ return {
656
+ stepId: step.id,
657
+ kind: "sleep",
658
+ status: "completed",
659
+ attempts: 1,
660
+ durationMs: Date.now() - startedAt,
661
+ output: input
662
+ // sleep is a pass-through
663
+ };
664
+ } catch (err) {
665
+ return {
666
+ stepId: step.id,
667
+ kind: "sleep",
668
+ status: "failed",
669
+ attempts: 1,
670
+ durationMs: Date.now() - startedAt,
671
+ error: errToShape(err)
672
+ };
673
+ }
674
+ }
675
+
676
+ // src/internal/workflow/telemetry.ts
677
+ var TRACER_NAME = "@theokit/sdk/workflow";
678
+ function startWorkflowRunSpan(info) {
679
+ const tracer = chunkBUUUWQMB_cjs.getTracer(TRACER_NAME);
680
+ if (tracer === void 0) return chunkBUUUWQMB_cjs.noopSpan;
681
+ return tracer.startSpan("workflow.run", {
682
+ attributes: {
683
+ "workflow.name": info.workflowName,
684
+ "workflow.run_id": info.runId
685
+ }
686
+ });
687
+ }
688
+ function startWorkflowStepSpan(info) {
689
+ const tracer = chunkBUUUWQMB_cjs.getTracer(TRACER_NAME);
690
+ if (tracer === void 0) return chunkBUUUWQMB_cjs.noopSpan;
691
+ return tracer.startSpan(`workflow.step.${info.stepId}`, {
692
+ attributes: {
693
+ "step.id": info.stepId,
694
+ "step.kind": info.kind,
695
+ "step.attempt": info.attempt
696
+ }
697
+ });
698
+ }
699
+
700
+ // src/internal/workflow/executor.ts
701
+ async function handleSuspend(err, ctx) {
702
+ try {
703
+ await saveSnapshot({
704
+ runId: ctx.runId,
705
+ workflowName: ctx.options.name,
706
+ currentStepId: ctx.step.id,
707
+ suspendedPayload: err.payload,
708
+ stepResults: ctx.stepResults,
709
+ accumulatedInput: ctx.acc,
710
+ state: ctx.stepCtx.state,
711
+ // SE29 — capture the shared state at suspend
712
+ options: ctx.options
713
+ });
714
+ } catch (snapErr) {
715
+ ctx.stepSpan.setAttribute("step.status", "failed");
716
+ ctx.stepSpan.end();
717
+ return {
718
+ kind: "failed",
719
+ run: assembleRun({
720
+ runId: ctx.runId,
721
+ name: ctx.name,
722
+ status: "failed",
723
+ stepResults: ctx.stepResults,
724
+ startedAt: ctx.startedAt,
725
+ error: errToShape(snapErr)
726
+ })
727
+ };
728
+ }
729
+ ctx.stepSpan.setAttribute("step.status", "suspended");
730
+ ctx.stepSpan.end();
731
+ return {
732
+ kind: "suspended",
733
+ run: assembleRun({
734
+ runId: ctx.runId,
735
+ name: ctx.name,
736
+ status: "suspended",
737
+ stepResults: [
738
+ ...ctx.stepResults,
739
+ {
740
+ stepId: ctx.step.id,
741
+ kind: ctx.step.kind,
742
+ status: "suspended",
743
+ attempts: 1,
744
+ durationMs: 0,
745
+ output: void 0
746
+ }
747
+ ],
748
+ startedAt: ctx.startedAt
749
+ })
750
+ };
751
+ }
752
+ async function runOneStep(args) {
753
+ const stepSpan = startWorkflowStepSpan({
754
+ stepId: args.step.id,
755
+ kind: args.step.kind,
756
+ attempt: 1
757
+ });
758
+ let result;
759
+ try {
760
+ result = await dispatchStep(args.step, args.acc, args.ctx, args.options, args.stepResults);
761
+ } catch (err) {
762
+ if (err instanceof WorkflowSuspendedSentinel) {
763
+ const outcome = await handleSuspend(err, { ...args, stepSpan, stepCtx: args.ctx });
764
+ return { kind: "terminal", run: outcome.run };
765
+ }
766
+ result = {
767
+ stepId: args.step.id,
768
+ kind: args.step.kind,
769
+ status: "failed",
770
+ attempts: 1,
771
+ durationMs: 0,
772
+ error: errToShape(err)
773
+ };
774
+ }
775
+ stepSpan.setAttribute("step.status", result.status);
776
+ stepSpan.setAttribute("step.attempts", result.attempts);
777
+ stepSpan.end();
778
+ return { kind: "ok", result };
779
+ }
780
+ function handleStepOutcome(outcome, step, loop, onStepEvent) {
781
+ if (outcome.kind === "terminal") {
782
+ if (outcome.run.status === "suspended") {
783
+ onStepEvent?.({ type: "workflow_suspended", stepId: step.id });
784
+ }
785
+ return { terminal: outcome.run };
786
+ }
787
+ loop.stepResults.push(outcome.result);
788
+ if (outcome.result.status === "failed") {
789
+ onStepEvent?.({
790
+ type: "step_failed",
791
+ stepId: step.id,
792
+ error: outcome.result.error ?? { name: "WorkflowStepError", message: "step failed" }
793
+ });
794
+ return {
795
+ terminal: assembleRun({
796
+ runId: loop.runId,
797
+ name: loop.name,
798
+ status: "failed",
799
+ stepResults: loop.stepResults,
800
+ startedAt: loop.startedAt,
801
+ error: outcome.result.error
802
+ })
803
+ };
804
+ }
805
+ onStepEvent?.({ type: "step_completed", stepId: step.id, output: outcome.result.output });
806
+ return { acc: outcome.result.output };
807
+ }
808
+ async function runStepsLoop(params) {
809
+ const { options, steps, ctx, runId, startedAt, signal, onStepEvent } = params;
810
+ const stepResults = [...params.initialStepResults ?? []];
811
+ const loop = { stepResults, runId, name: options.name, startedAt };
812
+ let acc = params.input;
813
+ for (const step of steps) {
814
+ if (signal.aborted) return abortRun(options.name, runId, startedAt, stepResults, signal);
815
+ onStepEvent?.({ type: "step_started", stepId: step.id });
816
+ const outcome = await runOneStep({
817
+ step,
818
+ acc,
819
+ ctx,
820
+ options,
821
+ stepResults,
822
+ runId,
823
+ name: options.name,
824
+ startedAt
825
+ });
826
+ const handled = handleStepOutcome(outcome, step, loop, onStepEvent);
827
+ if ("terminal" in handled) return handled.terminal;
828
+ acc = handled.acc;
829
+ }
830
+ const outputIssues = validateWorkflowSchema(options.outputSchema, acc);
831
+ if (outputIssues !== void 0) {
832
+ return assembleRun({
833
+ runId,
834
+ name: options.name,
835
+ status: "failed",
836
+ stepResults,
837
+ startedAt,
838
+ error: errToShape(new chunkBWT67BI4_cjs.WorkflowOutputError(options.name, outputIssues))
839
+ });
840
+ }
841
+ onStepEvent?.({ type: "workflow_completed" });
842
+ return assembleRun({
843
+ runId,
844
+ name: options.name,
845
+ status: "completed",
846
+ output: acc,
847
+ stepResults,
848
+ startedAt
849
+ });
850
+ }
851
+ async function executeWorkflow(options, steps, input, runOpts) {
852
+ const runId = runOpts?.runId ?? mintRunId();
853
+ const workflowId = options.workflowId ?? `wf-anon`;
854
+ const flight = acquireSingleFlight(workflowId, runId, options.name);
855
+ const startedAt = Date.now();
856
+ const signal = combineSignals(runOpts?.signal, flight.signal);
857
+ const runSpan = startWorkflowRunSpan({ workflowName: options.name, runId });
858
+ if (signal.aborted) {
859
+ flight.release();
860
+ runSpan.setAttribute("workflow.status", "cancelled");
861
+ runSpan.end();
862
+ return abortRun(options.name, runId, startedAt, [], signal);
863
+ }
864
+ const internal = runOpts;
865
+ const seededState = internal?.restoredState !== void 0 ? internal.restoredState : options.initialState;
866
+ const stateController = makeStateController(options, seededState);
867
+ const ctx = makeStepContext(runId, signal, stateController);
868
+ try {
869
+ const inputIssues = validateWorkflowSchema(options.inputSchema, input);
870
+ if (inputIssues !== void 0) {
871
+ return assembleRun({
872
+ runId,
873
+ name: options.name,
874
+ status: "failed",
875
+ stepResults: [],
876
+ startedAt,
877
+ error: errToShape(new chunkBWT67BI4_cjs.WorkflowInputError(options.name, inputIssues))
878
+ });
879
+ }
880
+ const stateIssues = seededState !== void 0 ? validateWorkflowSchema(options.stateSchema, seededState) : void 0;
881
+ if (stateIssues !== void 0) {
882
+ return assembleRun({
883
+ runId,
884
+ name: options.name,
885
+ status: "failed",
886
+ stepResults: [],
887
+ startedAt,
888
+ error: errToShape(new chunkBWT67BI4_cjs.WorkflowStateError(options.name, stateIssues))
889
+ });
890
+ }
891
+ return await runStepsLoop({
892
+ options,
893
+ steps,
894
+ input,
895
+ ctx,
896
+ runId,
897
+ startedAt,
898
+ signal,
899
+ ...internal?.initialStepResults !== void 0 ? { initialStepResults: internal.initialStepResults } : {},
900
+ ...internal?.onStepEvent !== void 0 ? { onStepEvent: internal.onStepEvent } : {}
901
+ });
902
+ } finally {
903
+ runSpan.end();
904
+ flight.release();
905
+ }
906
+ }
907
+ async function dispatchStep(step, input, ctx, options, prevStepResults) {
908
+ switch (step.kind) {
909
+ case "fn":
910
+ return runFnStep(step, input, ctx);
911
+ case "agent":
912
+ return runAgentStep(step, input, ctx);
913
+ case "parallel":
914
+ return runParallelStep(step, input, ctx, options, prevStepResults, dispatchStep);
915
+ case "branch":
916
+ return runBranchStep(step, input, ctx, options, prevStepResults, dispatchStep);
917
+ case "foreach":
918
+ return runForeachStep(step, input, ctx, options, prevStepResults, dispatchStep);
919
+ case "dowhile":
920
+ return runDowhileStep(step, input, ctx, options, prevStepResults, dispatchStep);
921
+ case "sleep":
922
+ return runSleepStep(step, input, ctx);
923
+ case "suspend":
924
+ throw new WorkflowSuspendedSentinel(void 0);
925
+ default: {
926
+ const _exhaustive = step;
927
+ throw new Error(`Unknown step kind: ${_exhaustive.kind}`);
928
+ }
929
+ }
930
+ }
931
+ async function saveSnapshot(p) {
932
+ const snapshot = {
933
+ _schemaVersion: 2,
934
+ // SE29 — carries `state`
935
+ runId: p.runId,
936
+ workflowName: p.workflowName,
937
+ currentStepId: p.currentStepId,
938
+ suspendedPayload: p.suspendedPayload,
939
+ stepResults: p.stepResults,
940
+ accumulatedInput: p.accumulatedInput,
941
+ ...p.state !== void 0 ? { state: p.state } : {},
942
+ suspendedAt: Date.now()
943
+ };
944
+ const store = chunkBWT67BI4_cjs.getSnapshotStoreFor(p.options);
945
+ await store.save(snapshot);
946
+ }
947
+ async function resumeWorkflow(opts) {
948
+ const wfInternal = opts.workflow;
949
+ const options = wfInternal.__options;
950
+ const steps = wfInternal.__steps;
951
+ if (options === void 0 || steps === void 0) {
952
+ throw new Error("Workflow.resume requires an instance from Workflow.create().commit()");
953
+ }
954
+ const store = chunkBWT67BI4_cjs.getSnapshotStoreFor(options);
955
+ const snapshot = await store.load(opts.runId);
956
+ if (snapshot === void 0) {
957
+ throw new chunkBWT67BI4_cjs.WorkflowSnapshotNotFoundError(opts.runId);
958
+ }
959
+ const stepIdx = steps.findIndex((s) => s.id === snapshot.currentStepId);
960
+ if (stepIdx < 0) {
961
+ throw new chunkBWT67BI4_cjs.WorkflowResumeStepNotFoundError(snapshot.currentStepId, snapshot.workflowName);
962
+ }
963
+ const suspendStep = steps[stepIdx];
964
+ if (suspendStep !== void 0 && suspendStep.kind === "suspend" && suspendStep.payloadSchema !== void 0) {
965
+ suspendStep.payloadSchema.parse(opts.payload);
966
+ }
967
+ const resumeInput = opts.payload !== void 0 ? opts.payload : snapshot.accumulatedInput;
968
+ const remainingSteps = steps.slice(stepIdx + 1);
969
+ await store.delete(opts.runId);
970
+ return executeWorkflow(options, remainingSteps, resumeInput, {
971
+ signal: opts.signal,
972
+ runId: opts.runId,
973
+ // M3 #62 — restore prior step outputs so the resumed run is not lossy (internal seam).
974
+ initialStepResults: snapshot.stepResults,
975
+ // SE29 — restore shared state (v2 snapshot). A v1 snapshot has no `state` →
976
+ // executeWorkflow falls back to `options.initialState`.
977
+ ...snapshot.state !== void 0 ? { restoredState: snapshot.state } : {}
978
+ });
979
+ }
980
+
981
+ exports.dispatchStep = dispatchStep;
982
+ exports.executeWorkflow = executeWorkflow;
983
+ exports.resumeWorkflow = resumeWorkflow;
984
+ //# sourceMappingURL=executor-Y4MKPIUD.cjs.map
985
+ //# sourceMappingURL=executor-Y4MKPIUD.cjs.map