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