rivetkit 2.1.4 → 2.1.6-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/client.d.ts +593 -588
- package/dist/browser/client.js +215 -35
- package/dist/browser/client.js.map +1 -1
- package/dist/browser/inspector/client.js +109 -10
- package/dist/browser/inspector/client.js.map +1 -1
- package/dist/inspector.tar.gz +0 -0
- package/dist/tsup/actor/errors.cjs +2 -2
- package/dist/tsup/actor/errors.js +1 -1
- package/dist/tsup/{actor-router-consts-D29T1Z-K.d.cts → actor-router-consts-DU-1IdQj.d.cts} +1 -1
- package/dist/tsup/{actor-router-consts-D29T1Z-K.d.ts → actor-router-consts-DU-1IdQj.d.ts} +1 -1
- package/dist/tsup/chunk-2ELYUO6C.cjs +112 -0
- package/dist/tsup/chunk-2ELYUO6C.cjs.map +1 -0
- package/dist/tsup/chunk-2LY7RW3Y.cjs +2316 -0
- package/dist/tsup/chunk-2LY7RW3Y.cjs.map +1 -0
- package/dist/tsup/{chunk-L47L3ZWJ.cjs → chunk-6G7ZNM27.cjs} +11 -6
- package/dist/tsup/chunk-6G7ZNM27.cjs.map +1 -0
- package/dist/tsup/{chunk-LK36OGGO.cjs → chunk-A4KEUCB6.cjs} +84 -34
- package/dist/tsup/chunk-A4KEUCB6.cjs.map +1 -0
- package/dist/tsup/{chunk-7HTNH26M.js → chunk-AKUJ5OTO.js} +11 -6
- package/dist/tsup/chunk-AKUJ5OTO.js.map +1 -0
- package/dist/tsup/{chunk-ANKZ2FS6.js → chunk-C22JYHVT.js} +77 -27
- package/dist/tsup/chunk-C22JYHVT.js.map +1 -0
- package/dist/tsup/chunk-C4EB42ET.js +1459 -0
- package/dist/tsup/chunk-C4EB42ET.js.map +1 -0
- package/dist/tsup/chunk-CGGGBIDP.cjs +1459 -0
- package/dist/tsup/chunk-CGGGBIDP.cjs.map +1 -0
- package/dist/tsup/chunk-CMQPDBBR.cjs +1486 -0
- package/dist/tsup/chunk-CMQPDBBR.cjs.map +1 -0
- package/dist/tsup/{chunk-AQD4CBZ2.cjs → chunk-DH6UINWA.cjs} +4 -4
- package/dist/tsup/{chunk-AQD4CBZ2.cjs.map → chunk-DH6UINWA.cjs.map} +1 -1
- package/dist/tsup/chunk-DK46YYCJ.js +1486 -0
- package/dist/tsup/chunk-DK46YYCJ.js.map +1 -0
- package/dist/tsup/chunk-EGWXXBZV.js +2316 -0
- package/dist/tsup/chunk-EGWXXBZV.js.map +1 -0
- package/dist/tsup/{chunk-HBYEYBIC.js → chunk-EONWXYMN.js} +2 -2
- package/dist/tsup/{chunk-N4KRDJ56.js → chunk-GFGRBYO2.js} +35 -6
- package/dist/tsup/chunk-GFGRBYO2.js.map +1 -0
- package/dist/tsup/{chunk-TEUL4UYN.cjs → chunk-GUHXWPGB.cjs} +1515 -1479
- package/dist/tsup/chunk-GUHXWPGB.cjs.map +1 -0
- package/dist/tsup/{chunk-3B6PCYJB.cjs → chunk-HNE2AK6C.cjs} +2375 -3713
- package/dist/tsup/chunk-HNE2AK6C.cjs.map +1 -0
- package/dist/tsup/{chunk-5UEFNG7P.js → chunk-I5I6OALK.js} +2 -2
- package/dist/tsup/chunk-IHQAF2HV.cjs +23 -0
- package/dist/tsup/chunk-IHQAF2HV.cjs.map +1 -0
- package/dist/tsup/{chunk-UWAGLDT6.cjs → chunk-JJNZQDUN.cjs} +667 -2517
- package/dist/tsup/chunk-JJNZQDUN.cjs.map +1 -0
- package/dist/tsup/{chunk-M6H4XIF4.js → chunk-JJSPHLJN.js} +219 -287
- package/dist/tsup/chunk-JJSPHLJN.js.map +1 -0
- package/dist/tsup/chunk-JRKPV5NJ.js +481 -0
- package/dist/tsup/chunk-JRKPV5NJ.js.map +1 -0
- package/dist/tsup/{chunk-VKVNIQRQ.js → chunk-K7MVU5SI.js} +36 -41
- package/dist/tsup/chunk-K7MVU5SI.js.map +1 -0
- package/dist/tsup/{chunk-KJSYAUOM.js → chunk-MLK3GY6P.js} +43 -27
- package/dist/tsup/chunk-MLK3GY6P.js.map +1 -0
- package/dist/tsup/{chunk-4KSHPFXF.cjs → chunk-MPLMTJY5.cjs} +123 -23
- package/dist/tsup/chunk-MPLMTJY5.cjs.map +1 -0
- package/dist/tsup/{chunk-UDMRZR6A.js → chunk-PQWI44WD.js} +1755 -3093
- package/dist/tsup/chunk-PQWI44WD.js.map +1 -0
- package/dist/tsup/{chunk-SR3KQE7Q.cjs → chunk-SQFCIDCG.cjs} +35 -6
- package/dist/tsup/chunk-SQFCIDCG.cjs.map +1 -0
- package/dist/tsup/{chunk-3GTO6H3E.js → chunk-SVHJSM2E.js} +110 -24
- package/dist/tsup/chunk-SVHJSM2E.js.map +1 -0
- package/dist/tsup/chunk-T5KYKM6R.js +49 -0
- package/dist/tsup/chunk-T5KYKM6R.js.map +1 -0
- package/dist/tsup/{chunk-GXRVSSVD.cjs → chunk-TJ7DKW6F.cjs} +123 -37
- package/dist/tsup/chunk-TJ7DKW6F.cjs.map +1 -0
- package/dist/tsup/chunk-UQZRMTM3.js +23 -0
- package/dist/tsup/chunk-UQZRMTM3.js.map +1 -0
- package/dist/tsup/{chunk-QPADHLDU.cjs → chunk-V3JSZR5P.cjs} +3 -3
- package/dist/tsup/{chunk-QPADHLDU.cjs.map → chunk-V3JSZR5P.cjs.map} +1 -1
- package/dist/tsup/{chunk-HKOSZKKZ.cjs → chunk-VBR35EQF.cjs} +271 -339
- package/dist/tsup/chunk-VBR35EQF.cjs.map +1 -0
- package/dist/tsup/{chunk-DZXDUGLL.js → chunk-VWYO36X4.js} +117 -17
- package/dist/tsup/chunk-VWYO36X4.js.map +1 -0
- package/dist/tsup/{chunk-I6PL6QIY.js → chunk-WW27B6DM.js} +1452 -1416
- package/dist/tsup/chunk-WW27B6DM.js.map +1 -0
- package/dist/tsup/chunk-YAE3MEJM.cjs +49 -0
- package/dist/tsup/chunk-YAE3MEJM.cjs.map +1 -0
- package/dist/tsup/{chunk-KTWY3K6Z.js → chunk-YGYGANCA.js} +473 -2323
- package/dist/tsup/chunk-YGYGANCA.js.map +1 -0
- package/dist/tsup/chunk-YZJWZBY5.cjs +481 -0
- package/dist/tsup/chunk-YZJWZBY5.cjs.map +1 -0
- package/dist/tsup/{chunk-ZFY5J2EP.cjs → chunk-ZZLJ5TSM.cjs} +39 -44
- package/dist/tsup/chunk-ZZLJ5TSM.cjs.map +1 -0
- package/dist/tsup/client/mod.cjs +10 -7
- package/dist/tsup/client/mod.cjs.map +1 -1
- package/dist/tsup/client/mod.d.cts +6 -6
- package/dist/tsup/client/mod.d.ts +6 -6
- package/dist/tsup/client/mod.js +11 -8
- package/dist/tsup/common/log.cjs +3 -3
- package/dist/tsup/common/log.js +2 -2
- package/dist/tsup/common/websocket.cjs +4 -4
- package/dist/tsup/common/websocket.js +3 -3
- package/dist/tsup/{config-Qj-zLJPc.d.ts → config-C2Wwnc69.d.ts} +142 -208
- package/dist/tsup/{config-BiNoIHRs.d.ts → config-DROwzBLT.d.cts} +82 -6
- package/dist/tsup/{config-BiNoIHRs.d.cts → config-DROwzBLT.d.ts} +82 -6
- package/dist/tsup/{config-iPj5l1bL.d.cts → config-ehT-_3BB.d.cts} +142 -208
- package/dist/tsup/{context-DzvH1PBK.d.cts → context-DGMJuAyc.d.ts} +16 -3
- package/dist/tsup/{context-CQCMuHND.d.ts → context-Dpp2RJbW.d.cts} +16 -3
- package/dist/tsup/db/drizzle/mod.cjs +3 -3
- package/dist/tsup/db/drizzle/mod.d.cts +1 -1
- package/dist/tsup/db/drizzle/mod.d.ts +1 -1
- package/dist/tsup/db/drizzle/mod.js +2 -2
- package/dist/tsup/db/mod.cjs +3 -3
- package/dist/tsup/db/mod.d.cts +1 -1
- package/dist/tsup/db/mod.d.ts +1 -1
- package/dist/tsup/db/mod.js +2 -2
- package/dist/tsup/{driver-Jo8v-kbU.d.ts → driver-CYZP9QYo.d.ts} +1 -1
- package/dist/tsup/{driver-iV8J-WMv.d.cts → driver-CoTFpipv.d.cts} +1 -1
- package/dist/tsup/driver-helpers/mod.cjs +7 -5
- package/dist/tsup/driver-helpers/mod.cjs.map +1 -1
- package/dist/tsup/driver-helpers/mod.d.cts +17 -18
- package/dist/tsup/driver-helpers/mod.d.ts +17 -18
- package/dist/tsup/driver-helpers/mod.js +11 -9
- package/dist/tsup/driver-test-suite/mod.cjs +1275 -228
- package/dist/tsup/driver-test-suite/mod.cjs.map +1 -1
- package/dist/tsup/driver-test-suite/mod.d.cts +6 -5
- package/dist/tsup/driver-test-suite/mod.d.ts +6 -5
- package/dist/tsup/driver-test-suite/mod.js +1581 -534
- package/dist/tsup/driver-test-suite/mod.js.map +1 -1
- package/dist/tsup/inspector/mod.cjs +4 -4
- package/dist/tsup/inspector/mod.js +3 -3
- package/dist/tsup/mod.cjs +15 -9
- package/dist/tsup/mod.cjs.map +1 -1
- package/dist/tsup/mod.d.cts +9 -9
- package/dist/tsup/mod.d.ts +9 -9
- package/dist/tsup/mod.js +19 -13
- package/dist/tsup/sandbox/client.cjs +28 -0
- package/dist/tsup/sandbox/client.cjs.map +1 -0
- package/dist/tsup/sandbox/client.d.cts +88 -0
- package/dist/tsup/sandbox/client.d.ts +88 -0
- package/dist/tsup/sandbox/client.js +28 -0
- package/dist/tsup/sandbox/client.js.map +1 -0
- package/dist/tsup/sandbox/index.cjs +761 -0
- package/dist/tsup/sandbox/index.cjs.map +1 -0
- package/dist/tsup/sandbox/index.d.cts +120 -0
- package/dist/tsup/sandbox/index.d.ts +120 -0
- package/dist/tsup/sandbox/index.js +761 -0
- package/dist/tsup/sandbox/index.js.map +1 -0
- package/dist/tsup/sandbox/providers/computesdk.cjs +3 -0
- package/dist/tsup/sandbox/providers/computesdk.cjs.map +1 -0
- package/dist/tsup/sandbox/providers/computesdk.d.cts +7 -0
- package/dist/tsup/sandbox/providers/computesdk.d.ts +7 -0
- package/dist/tsup/sandbox/providers/computesdk.js +3 -0
- package/dist/tsup/sandbox/providers/computesdk.js.map +1 -0
- package/dist/tsup/sandbox/providers/daytona.cjs +3 -0
- package/dist/tsup/sandbox/providers/daytona.cjs.map +1 -0
- package/dist/tsup/sandbox/providers/daytona.d.cts +1 -0
- package/dist/tsup/sandbox/providers/daytona.d.ts +1 -0
- package/dist/tsup/sandbox/providers/daytona.js +3 -0
- package/dist/tsup/sandbox/providers/daytona.js.map +1 -0
- package/dist/tsup/sandbox/providers/docker.cjs +3 -0
- package/dist/tsup/sandbox/providers/docker.cjs.map +1 -0
- package/dist/tsup/sandbox/providers/docker.d.cts +1 -0
- package/dist/tsup/sandbox/providers/docker.d.ts +1 -0
- package/dist/tsup/sandbox/providers/docker.js +3 -0
- package/dist/tsup/sandbox/providers/docker.js.map +1 -0
- package/dist/tsup/sandbox/providers/e2b.cjs +3 -0
- package/dist/tsup/sandbox/providers/e2b.cjs.map +1 -0
- package/dist/tsup/sandbox/providers/e2b.d.cts +1 -0
- package/dist/tsup/sandbox/providers/e2b.d.ts +1 -0
- package/dist/tsup/sandbox/providers/e2b.js +3 -0
- package/dist/tsup/sandbox/providers/e2b.js.map +1 -0
- package/dist/tsup/sandbox/providers/local.cjs +3 -0
- package/dist/tsup/sandbox/providers/local.cjs.map +1 -0
- package/dist/tsup/sandbox/providers/local.d.cts +1 -0
- package/dist/tsup/sandbox/providers/local.d.ts +1 -0
- package/dist/tsup/sandbox/providers/local.js +3 -0
- package/dist/tsup/sandbox/providers/local.js.map +1 -0
- package/dist/tsup/sandbox/providers/modal.cjs +3 -0
- package/dist/tsup/sandbox/providers/modal.cjs.map +1 -0
- package/dist/tsup/sandbox/providers/modal.d.cts +1 -0
- package/dist/tsup/sandbox/providers/modal.d.ts +1 -0
- package/dist/tsup/sandbox/providers/modal.js +3 -0
- package/dist/tsup/sandbox/providers/modal.js.map +1 -0
- package/dist/tsup/sandbox/providers/vercel.cjs +3 -0
- package/dist/tsup/sandbox/providers/vercel.cjs.map +1 -0
- package/dist/tsup/sandbox/providers/vercel.d.cts +1 -0
- package/dist/tsup/sandbox/providers/vercel.d.ts +1 -0
- package/dist/tsup/sandbox/providers/vercel.js +3 -0
- package/dist/tsup/sandbox/providers/vercel.js.map +1 -0
- package/dist/tsup/serve-test-suite/mod.cjs +451 -327
- package/dist/tsup/serve-test-suite/mod.cjs.map +1 -1
- package/dist/tsup/serve-test-suite/mod.js +362 -238
- package/dist/tsup/serve-test-suite/mod.js.map +1 -1
- package/dist/tsup/test/mod.cjs +17 -14
- package/dist/tsup/test/mod.cjs.map +1 -1
- package/dist/tsup/test/mod.d.cts +4 -4
- package/dist/tsup/test/mod.d.ts +4 -4
- package/dist/tsup/test/mod.js +14 -11
- package/dist/tsup/test/mod.js.map +1 -1
- package/dist/tsup/utils.cjs +3 -3
- package/dist/tsup/utils.js +2 -2
- package/dist/tsup/workflow/mod.cjs +6 -6
- package/dist/tsup/workflow/mod.d.cts +13 -9
- package/dist/tsup/workflow/mod.d.ts +13 -9
- package/dist/tsup/workflow/mod.js +5 -5
- package/package.json +113 -14
- package/src/actor/config.ts +94 -88
- package/src/actor/conn/drivers/websocket.ts +2 -1
- package/src/actor/contexts/base/actor.ts +27 -4
- package/src/actor/database.ts +6 -1
- package/src/actor/driver.ts +27 -8
- package/src/actor/errors.ts +10 -5
- package/src/actor/instance/connection-manager.ts +4 -3
- package/src/actor/instance/kv.ts +52 -9
- package/src/actor/instance/mod.ts +135 -84
- package/src/actor/instance/queue-manager.ts +2 -5
- package/src/actor/instance/queue.ts +31 -29
- package/src/actor/instance/state-manager.ts +7 -1
- package/src/actor/instance/traces-driver.ts +34 -36
- package/src/actor/metrics.ts +137 -0
- package/src/actor/protocol/old.ts +9 -12
- package/src/actor/router-websocket-endpoints.ts +12 -6
- package/src/actor/router.ts +46 -9
- package/src/actor/schema.ts +14 -22
- package/src/client/actor-common.ts +65 -0
- package/src/client/actor-conn.ts +71 -9
- package/src/client/actor-handle.ts +22 -5
- package/src/client/client.ts +32 -6
- package/src/client/config.ts +18 -21
- package/src/client/mod.ts +1 -0
- package/src/client/queue.ts +8 -6
- package/src/common/inline-websocket-adapter.ts +8 -2
- package/src/common/router.ts +1 -4
- package/src/common/utils.ts +2 -5
- package/src/db/config.ts +10 -5
- package/src/db/drizzle/mod.ts +51 -41
- package/src/db/mod.ts +54 -29
- package/src/db/shared.ts +42 -8
- package/src/driver-helpers/mod.ts +2 -1
- package/src/driver-helpers/sqlite-pool.ts +42 -0
- package/src/driver-helpers/utils.ts +0 -20
- package/src/driver-test-suite/mod.ts +11 -1
- package/src/driver-test-suite/tests/access-control.ts +19 -12
- package/src/driver-test-suite/tests/action-features.ts +20 -8
- package/src/driver-test-suite/tests/actor-conn.ts +94 -8
- package/src/driver-test-suite/tests/actor-db-kv-stats.ts +282 -0
- package/src/driver-test-suite/tests/actor-db-raw.ts +6 -2
- package/src/driver-test-suite/tests/actor-db.ts +101 -31
- package/src/driver-test-suite/tests/actor-inspector.ts +174 -32
- package/src/driver-test-suite/tests/actor-kv.ts +79 -33
- package/src/driver-test-suite/tests/actor-lifecycle.ts +4 -12
- package/src/driver-test-suite/tests/actor-queue.ts +125 -17
- package/src/driver-test-suite/tests/actor-run.ts +59 -55
- package/src/driver-test-suite/tests/actor-sandbox.ts +78 -0
- package/src/driver-test-suite/tests/actor-schedule.ts +1 -4
- package/src/driver-test-suite/tests/actor-sleep.ts +111 -0
- package/src/driver-test-suite/tests/actor-workflow.ts +387 -3
- package/src/driver-test-suite/tests/conn-error-serialization.ts +3 -1
- package/src/driver-test-suite/tests/raw-websocket.ts +5 -1
- package/src/drivers/default.ts +1 -3
- package/src/drivers/engine/actor-driver.ts +94 -21
- package/src/drivers/engine/config.ts +4 -12
- package/src/drivers/engine/mod.ts +1 -5
- package/src/drivers/file-system/actor.ts +43 -8
- package/src/drivers/file-system/global-state.ts +180 -64
- package/src/drivers/file-system/kv-limits.ts +1 -1
- package/src/drivers/file-system/sqlite-runtime.ts +13 -4
- package/src/engine-process/mod.ts +5 -1
- package/src/inspector/actor-inspector.ts +47 -21
- package/src/inspector/config.ts +1 -4
- package/src/inspector/mod.browser.ts +2 -2
- package/src/inspector/mod.ts +4 -1
- package/src/inspector/serve-ui.ts +0 -1
- package/src/inspector/workflow-history-json.ts +309 -0
- package/src/manager/gateway.ts +6 -2
- package/src/manager/router.ts +3 -3
- package/src/registry/config/index.ts +65 -12
- package/src/registry/config/runner.ts +19 -4
- package/src/registry/index.ts +42 -89
- package/src/sandbox/actor/db.ts +36 -0
- package/src/sandbox/actor/index.ts +476 -0
- package/src/sandbox/actor/session.ts +350 -0
- package/src/sandbox/actor.test.ts +36 -0
- package/src/sandbox/client.test.ts +484 -0
- package/src/sandbox/client.ts +707 -0
- package/src/sandbox/config.ts +151 -0
- package/src/sandbox/index.ts +41 -0
- package/src/sandbox/providers/computesdk.ts +1 -0
- package/src/sandbox/providers/daytona.ts +1 -0
- package/src/sandbox/providers/docker.ts +1 -0
- package/src/sandbox/providers/e2b.ts +1 -0
- package/src/sandbox/providers/local.ts +1 -0
- package/src/sandbox/providers/modal.ts +1 -0
- package/src/sandbox/providers/vercel.ts +1 -0
- package/src/sandbox/session-persist-driver.ts +180 -0
- package/src/sandbox/types.ts +138 -0
- package/src/serverless/configure.ts +5 -3
- package/src/serverless/router.test.ts +17 -9
- package/src/serverless/router.ts +20 -13
- package/src/test/mod.ts +3 -4
- package/src/utils/endpoint-parser.test.ts +6 -2
- package/src/utils/endpoint-parser.ts +6 -2
- package/src/utils/env-vars.ts +0 -2
- package/src/utils/node.ts +1 -1
- package/src/utils/serve.ts +10 -5
- package/src/utils.ts +6 -1
- package/src/workflow/constants.ts +1 -2
- package/src/workflow/context.ts +42 -9
- package/src/workflow/driver.ts +57 -23
- package/src/workflow/inspector.ts +7 -13
- package/src/workflow/mod.ts +91 -4
- package/dist/tsup/chunk-3B6PCYJB.cjs.map +0 -1
- package/dist/tsup/chunk-3GTO6H3E.js.map +0 -1
- package/dist/tsup/chunk-4KSHPFXF.cjs.map +0 -1
- package/dist/tsup/chunk-6LJAZ5R4.cjs +0 -96
- package/dist/tsup/chunk-6LJAZ5R4.cjs.map +0 -1
- package/dist/tsup/chunk-7HTNH26M.js.map +0 -1
- package/dist/tsup/chunk-ANKZ2FS6.js.map +0 -1
- package/dist/tsup/chunk-DZXDUGLL.js.map +0 -1
- package/dist/tsup/chunk-GXRVSSVD.cjs.map +0 -1
- package/dist/tsup/chunk-H5TSEPN4.cjs +0 -645
- package/dist/tsup/chunk-H5TSEPN4.cjs.map +0 -1
- package/dist/tsup/chunk-HKOSZKKZ.cjs.map +0 -1
- package/dist/tsup/chunk-I6PL6QIY.js.map +0 -1
- package/dist/tsup/chunk-KJSYAUOM.js.map +0 -1
- package/dist/tsup/chunk-KTWY3K6Z.js.map +0 -1
- package/dist/tsup/chunk-L47L3ZWJ.cjs.map +0 -1
- package/dist/tsup/chunk-LK36OGGO.cjs.map +0 -1
- package/dist/tsup/chunk-M6H4XIF4.js.map +0 -1
- package/dist/tsup/chunk-N4KRDJ56.js.map +0 -1
- package/dist/tsup/chunk-SR3KQE7Q.cjs.map +0 -1
- package/dist/tsup/chunk-TEFYRRAK.js +0 -645
- package/dist/tsup/chunk-TEFYRRAK.js.map +0 -1
- package/dist/tsup/chunk-TEUL4UYN.cjs.map +0 -1
- package/dist/tsup/chunk-UDMRZR6A.js.map +0 -1
- package/dist/tsup/chunk-UWAGLDT6.cjs.map +0 -1
- package/dist/tsup/chunk-VKVNIQRQ.js.map +0 -1
- package/dist/tsup/chunk-ZFY5J2EP.cjs.map +0 -1
- package/src/db/sqlite-vfs.ts +0 -12
- /package/dist/tsup/{chunk-HBYEYBIC.js.map → chunk-EONWXYMN.js.map} +0 -0
- /package/dist/tsup/{chunk-5UEFNG7P.js.map → chunk-I5I6OALK.js.map} +0 -0
|
@@ -87,7 +87,9 @@ describe("tryParseEndpoint", () => {
|
|
|
87
87
|
});
|
|
88
88
|
expect(result).toBeUndefined();
|
|
89
89
|
expect(issues).toHaveLength(1);
|
|
90
|
-
expect(issues[0]?.message).toBe(
|
|
90
|
+
expect(issues[0]?.message).toBe(
|
|
91
|
+
"endpoint cannot contain a query string",
|
|
92
|
+
);
|
|
91
93
|
});
|
|
92
94
|
|
|
93
95
|
test("adds issue for fragment", () => {
|
|
@@ -97,7 +99,9 @@ describe("tryParseEndpoint", () => {
|
|
|
97
99
|
});
|
|
98
100
|
expect(result).toBeUndefined();
|
|
99
101
|
expect(issues).toHaveLength(1);
|
|
100
|
-
expect(issues[0]?.message).toBe(
|
|
102
|
+
expect(issues[0]?.message).toBe(
|
|
103
|
+
"endpoint cannot contain a fragment",
|
|
104
|
+
);
|
|
101
105
|
});
|
|
102
106
|
|
|
103
107
|
test("adds issue for token without namespace", () => {
|
|
@@ -39,7 +39,12 @@ export function tryParseEndpoint(
|
|
|
39
39
|
ctx: z.RefinementCtx,
|
|
40
40
|
options: TryParseEndpointOptions,
|
|
41
41
|
): ParsedEndpoint | undefined {
|
|
42
|
-
const {
|
|
42
|
+
const {
|
|
43
|
+
endpoint,
|
|
44
|
+
path = ["endpoint"],
|
|
45
|
+
namespace: configNamespace,
|
|
46
|
+
token: configToken,
|
|
47
|
+
} = options;
|
|
43
48
|
// Parse the URL
|
|
44
49
|
let url: URL;
|
|
45
50
|
try {
|
|
@@ -121,4 +126,3 @@ export function tryParseEndpoint(
|
|
|
121
126
|
token,
|
|
122
127
|
};
|
|
123
128
|
}
|
|
124
|
-
|
package/src/utils/env-vars.ts
CHANGED
|
@@ -20,8 +20,6 @@ export const getRivetTotalSlots = (): number | undefined => {
|
|
|
20
20
|
const value = getEnvUniversal("RIVET_TOTAL_SLOTS");
|
|
21
21
|
return value !== undefined ? parseInt(value, 10) : undefined;
|
|
22
22
|
};
|
|
23
|
-
export const getRivetRunnerKey = (): string | undefined =>
|
|
24
|
-
getEnvUniversal("RIVET_RUNNER_KEY");
|
|
25
23
|
export const getRivetRunEngine = (): boolean =>
|
|
26
24
|
getEnvUniversal("RIVET_RUN_ENGINE") === "1";
|
|
27
25
|
export const getRivetRunEngineVersion = (): string | undefined =>
|
package/src/utils/node.ts
CHANGED
package/src/utils/serve.ts
CHANGED
|
@@ -9,8 +9,9 @@ import getPort from "get-port";
|
|
|
9
9
|
const DEFAULT_PORT = 6420;
|
|
10
10
|
export type ServeStatic =
|
|
11
11
|
typeof import("@hono/node-server/serve-static").serveStatic;
|
|
12
|
-
const serveStaticLoaderPromises: Partial<
|
|
13
|
-
|
|
12
|
+
const serveStaticLoaderPromises: Partial<
|
|
13
|
+
Record<Runtime, Promise<ServeStatic>>
|
|
14
|
+
> = {};
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
17
|
* Finds a free port starting from the given port.
|
|
@@ -39,7 +40,7 @@ export async function crossPlatformServe(
|
|
|
39
40
|
managerPort: number,
|
|
40
41
|
app: Hono<any>,
|
|
41
42
|
runtime: Runtime = detectRuntime(),
|
|
42
|
-
): Promise<{ upgradeWebSocket: any }> {
|
|
43
|
+
): Promise<{ upgradeWebSocket: any; closeServer?: () => void }> {
|
|
43
44
|
logger().debug({ msg: "detected runtime for serve", runtime });
|
|
44
45
|
|
|
45
46
|
switch (runtime) {
|
|
@@ -88,7 +89,7 @@ async function serveNode(
|
|
|
88
89
|
config: RegistryConfig,
|
|
89
90
|
managerPort: number,
|
|
90
91
|
app: Hono<any>,
|
|
91
|
-
): Promise<{ upgradeWebSocket: any }> {
|
|
92
|
+
): Promise<{ upgradeWebSocket: any; closeServer: () => void }> {
|
|
92
93
|
// Import @hono/node-server using string variable to prevent static analysis
|
|
93
94
|
const nodeServerModule = "@hono/node-server";
|
|
94
95
|
let serve: any;
|
|
@@ -136,7 +137,11 @@ async function serveNode(
|
|
|
136
137
|
);
|
|
137
138
|
injectWebSocket(server);
|
|
138
139
|
|
|
139
|
-
|
|
140
|
+
const closeServer = () => {
|
|
141
|
+
server.close();
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
return { upgradeWebSocket, closeServer };
|
|
140
145
|
}
|
|
141
146
|
|
|
142
147
|
async function serveDeno(
|
package/src/utils.ts
CHANGED
|
@@ -272,7 +272,12 @@ export class SinglePromiseQueue {
|
|
|
272
272
|
|
|
273
273
|
// Ensure a shared resolver exists for all callers in this cycle
|
|
274
274
|
if (!this.#pending) {
|
|
275
|
-
this.#pending = promiseWithResolvers<void>((reason) =>
|
|
275
|
+
this.#pending = promiseWithResolvers<void>((reason) =>
|
|
276
|
+
logger().warn({
|
|
277
|
+
msg: "unhandled single promise queue rejection",
|
|
278
|
+
reason,
|
|
279
|
+
}),
|
|
280
|
+
);
|
|
276
281
|
}
|
|
277
282
|
|
|
278
283
|
const waitForThisCycle = this.#pending.promise;
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export const WORKFLOW_GUARD_KV_KEY =
|
|
2
|
-
"__rivet_actor_workflow_guard_triggered";
|
|
1
|
+
export const WORKFLOW_GUARD_KV_KEY = "__rivet_actor_workflow_guard_triggered";
|
package/src/workflow/context.ts
CHANGED
|
@@ -2,7 +2,10 @@ import type { RunContext } from "@/actor/contexts/run";
|
|
|
2
2
|
import type { Client } from "@/client/client";
|
|
3
3
|
import type { Registry } from "@/registry";
|
|
4
4
|
import type { ActorDefinition, AnyActorDefinition } from "@/actor/definition";
|
|
5
|
-
import type {
|
|
5
|
+
import type {
|
|
6
|
+
AnyDatabaseProvider,
|
|
7
|
+
InferDatabaseClient,
|
|
8
|
+
} from "@/actor/database";
|
|
6
9
|
import type {
|
|
7
10
|
QueueFilterName,
|
|
8
11
|
QueueNextBatchOptions,
|
|
@@ -42,9 +45,8 @@ type WorkflowActorQueueNextBatchOptions<
|
|
|
42
45
|
TCompletable extends boolean,
|
|
43
46
|
> = Omit<QueueNextBatchOptions<TName, TCompletable>, "signal">;
|
|
44
47
|
|
|
45
|
-
type WorkflowActorQueueNextBatchOptionsFallback<
|
|
46
|
-
TCompletable
|
|
47
|
-
> = Omit<QueueNextBatchOptions<string, TCompletable>, "signal">;
|
|
48
|
+
type WorkflowActorQueueNextBatchOptionsFallback<TCompletable extends boolean> =
|
|
49
|
+
Omit<QueueNextBatchOptions<string, TCompletable>, "signal">;
|
|
48
50
|
|
|
49
51
|
type ActorWorkflowLoopConfig<
|
|
50
52
|
S,
|
|
@@ -182,7 +184,9 @@ export class ActorWorkflowContext<
|
|
|
182
184
|
>(
|
|
183
185
|
name: string,
|
|
184
186
|
opts?: WorkflowActorQueueNextBatchOptions<TName, TCompletable>,
|
|
185
|
-
): Promise<
|
|
187
|
+
): Promise<
|
|
188
|
+
Array<QueueResultMessageForName<TQueues, TName, TCompletable>>
|
|
189
|
+
>;
|
|
186
190
|
function nextBatch<const TCompletable extends boolean = false>(
|
|
187
191
|
name: string,
|
|
188
192
|
opts?: WorkflowActorQueueNextBatchOptionsFallback<TCompletable>,
|
|
@@ -200,7 +204,9 @@ export class ActorWorkflowContext<
|
|
|
200
204
|
opts?: WorkflowActorQueueNextBatchOptions<string, boolean>,
|
|
201
205
|
): Promise<Array<WorkflowQueueMessage<unknown>>> {
|
|
202
206
|
const messages = await self.#inner.queue.nextBatch(name, opts);
|
|
203
|
-
return messages.map((message) =>
|
|
207
|
+
return messages.map((message) =>
|
|
208
|
+
self.#toActorQueueMessage(message),
|
|
209
|
+
);
|
|
204
210
|
}
|
|
205
211
|
|
|
206
212
|
function send<K extends keyof TQueues & string>(
|
|
@@ -232,7 +238,9 @@ export class ActorWorkflowContext<
|
|
|
232
238
|
throw new Error("Step run function missing");
|
|
233
239
|
}
|
|
234
240
|
return await this.#wrapActive(() =>
|
|
235
|
-
this.#inner.step(nameOrConfig, () =>
|
|
241
|
+
this.#inner.step(nameOrConfig, () =>
|
|
242
|
+
this.#withActorAccess(run),
|
|
243
|
+
),
|
|
236
244
|
);
|
|
237
245
|
}
|
|
238
246
|
const stepConfig = nameOrConfig as StepConfig<T>;
|
|
@@ -334,6 +342,11 @@ export class ActorWorkflowContext<
|
|
|
334
342
|
return this.#inner.sleepUntil(name, timestampMs);
|
|
335
343
|
}
|
|
336
344
|
|
|
345
|
+
destroy(): void {
|
|
346
|
+
this.#ensureActorAccess("destroy");
|
|
347
|
+
this.#runCtx.destroy();
|
|
348
|
+
}
|
|
349
|
+
|
|
337
350
|
async rollbackCheckpoint(name: string): Promise<void> {
|
|
338
351
|
await this.#wrapActive(() => this.#inner.rollbackCheckpoint(name));
|
|
339
352
|
}
|
|
@@ -429,7 +442,7 @@ export class ActorWorkflowContext<
|
|
|
429
442
|
return this.#runCtx.vars as TVars extends never ? never : TVars;
|
|
430
443
|
}
|
|
431
444
|
|
|
432
|
-
client<R extends Registry<any>>(): Client<R> {
|
|
445
|
+
client<R extends Registry<any> = Registry<any>>(): Client<R> {
|
|
433
446
|
this.#ensureActorAccess("client");
|
|
434
447
|
return this.#runCtx.client<R>();
|
|
435
448
|
}
|
|
@@ -445,11 +458,31 @@ export class ActorWorkflowContext<
|
|
|
445
458
|
return this.#runCtx.log;
|
|
446
459
|
}
|
|
447
460
|
|
|
461
|
+
setPreventSleep(prevent: boolean): void {
|
|
462
|
+
this.#ensureActorAccess("setPreventSleep");
|
|
463
|
+
this.#runCtx.setPreventSleep(prevent);
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
get preventSleep(): boolean {
|
|
467
|
+
this.#ensureActorAccess("preventSleep");
|
|
468
|
+
return this.#runCtx.preventSleep;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
/**
|
|
472
|
+
* @deprecated Use `c.setPreventSleep(true)` while work is active, or move
|
|
473
|
+
* shutdown and flush work to `onSleep` if it can wait until the actor is
|
|
474
|
+
* sleeping.
|
|
475
|
+
*/
|
|
448
476
|
keepAwake<T>(promise: Promise<T>): Promise<T> {
|
|
449
477
|
this.#ensureActorAccess("keepAwake");
|
|
450
478
|
return this.#runCtx.keepAwake(promise);
|
|
451
479
|
}
|
|
452
480
|
|
|
481
|
+
/**
|
|
482
|
+
* @deprecated Use `onSleep` for shutdown or flush work, or
|
|
483
|
+
* `c.setPreventSleep(true)` while work is active if the actor must stay
|
|
484
|
+
* awake until it finishes.
|
|
485
|
+
*/
|
|
453
486
|
waitUntil(promise: Promise<void>): void {
|
|
454
487
|
this.#ensureActorAccess("waitUntil");
|
|
455
488
|
this.#runCtx.waitUntil(promise);
|
|
@@ -471,7 +504,7 @@ export class ActorWorkflowContext<
|
|
|
471
504
|
this.#ensureActorAccess("broadcast");
|
|
472
505
|
this.#runCtx.broadcast(
|
|
473
506
|
name as never,
|
|
474
|
-
...(
|
|
507
|
+
...(args as unknown[] as never[]),
|
|
475
508
|
);
|
|
476
509
|
}
|
|
477
510
|
|
package/src/workflow/driver.ts
CHANGED
|
@@ -15,6 +15,17 @@ function stripWorkflowKey(prefixed: Uint8Array): Uint8Array {
|
|
|
15
15
|
return prefixed.slice(WORKFLOW_STORAGE_PREFIX.length);
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
function computeUpperBound(prefix: Uint8Array): Uint8Array | null {
|
|
19
|
+
const upperBound = prefix.slice();
|
|
20
|
+
for (let i = upperBound.length - 1; i >= 0; i--) {
|
|
21
|
+
if (upperBound[i] !== 0xff) {
|
|
22
|
+
upperBound[i]++;
|
|
23
|
+
return upperBound.slice(0, i + 1);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
|
|
18
29
|
class ActorWorkflowMessageDriver implements WorkflowMessageDriver {
|
|
19
30
|
#actor: AnyActorInstance;
|
|
20
31
|
#runCtx: RunContext<any, any, any, any, any, any, any, any>;
|
|
@@ -40,7 +51,9 @@ class ActorWorkflowMessageDriver implements WorkflowMessageDriver {
|
|
|
40
51
|
}): Promise<Message[]> {
|
|
41
52
|
const messages = await this.#runCtx.keepAwake(
|
|
42
53
|
this.#actor.queueManager.receive(
|
|
43
|
-
opts.names && opts.names.length > 0
|
|
54
|
+
opts.names && opts.names.length > 0
|
|
55
|
+
? [...opts.names]
|
|
56
|
+
: undefined,
|
|
44
57
|
opts.count,
|
|
45
58
|
0,
|
|
46
59
|
undefined,
|
|
@@ -54,20 +67,23 @@ class ActorWorkflowMessageDriver implements WorkflowMessageDriver {
|
|
|
54
67
|
sentAt: message.createdAt,
|
|
55
68
|
...(opts.completable
|
|
56
69
|
? {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
70
|
+
complete: async (response?: unknown) => {
|
|
71
|
+
await this.#runCtx.keepAwake(
|
|
72
|
+
this.#actor.queueManager.completeMessage(
|
|
73
|
+
message,
|
|
74
|
+
response,
|
|
75
|
+
),
|
|
76
|
+
);
|
|
77
|
+
},
|
|
78
|
+
}
|
|
66
79
|
: {}),
|
|
67
80
|
}));
|
|
68
81
|
}
|
|
69
82
|
|
|
70
|
-
async completeMessage(
|
|
83
|
+
async completeMessage(
|
|
84
|
+
messageId: string,
|
|
85
|
+
response?: unknown,
|
|
86
|
+
): Promise<void> {
|
|
71
87
|
let parsedId: bigint;
|
|
72
88
|
try {
|
|
73
89
|
parsedId = BigInt(messageId);
|
|
@@ -122,19 +138,34 @@ export class ActorWorkflowDriver implements EngineDriver {
|
|
|
122
138
|
}
|
|
123
139
|
|
|
124
140
|
async deletePrefix(prefix: Uint8Array): Promise<void> {
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
141
|
+
const start = makeWorkflowKey(prefix);
|
|
142
|
+
const end = computeUpperBound(start);
|
|
143
|
+
if (end) {
|
|
144
|
+
await this.#runCtx.keepAwake(
|
|
145
|
+
this.#actor.driver.kvDeleteRange(this.#actor.id, start, end),
|
|
146
|
+
);
|
|
147
|
+
} else {
|
|
148
|
+
const entries = await this.#runCtx.keepAwake(
|
|
149
|
+
this.#actor.driver.kvListPrefix(this.#actor.id, start),
|
|
150
|
+
);
|
|
151
|
+
if (entries.length === 0) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
await this.#runCtx.keepAwake(
|
|
155
|
+
this.#actor.driver.kvBatchDelete(
|
|
156
|
+
this.#actor.id,
|
|
157
|
+
entries.map(([key]) => key),
|
|
158
|
+
),
|
|
159
|
+
);
|
|
133
160
|
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
async deleteRange(start: Uint8Array, end: Uint8Array): Promise<void> {
|
|
134
164
|
await this.#runCtx.keepAwake(
|
|
135
|
-
this.#actor.driver.
|
|
165
|
+
this.#actor.driver.kvDeleteRange(
|
|
136
166
|
this.#actor.id,
|
|
137
|
-
|
|
167
|
+
makeWorkflowKey(start),
|
|
168
|
+
makeWorkflowKey(end),
|
|
138
169
|
),
|
|
139
170
|
);
|
|
140
171
|
}
|
|
@@ -161,7 +192,10 @@ export class ActorWorkflowDriver implements EngineDriver {
|
|
|
161
192
|
Promise.all([
|
|
162
193
|
this.#actor.driver.kvBatchPut(
|
|
163
194
|
this.#actor.id,
|
|
164
|
-
writes.map(({ key, value }) => [
|
|
195
|
+
writes.map(({ key, value }) => [
|
|
196
|
+
makeWorkflowKey(key),
|
|
197
|
+
value,
|
|
198
|
+
]),
|
|
165
199
|
),
|
|
166
200
|
this.#actor.stateManager.saveState({
|
|
167
201
|
immediate: true,
|
|
@@ -191,4 +225,4 @@ export class ActorWorkflowDriver implements EngineDriver {
|
|
|
191
225
|
abortSignal,
|
|
192
226
|
);
|
|
193
227
|
}
|
|
194
|
-
}
|
|
228
|
+
}
|
|
@@ -62,9 +62,7 @@ function toU64(value: number): bigint {
|
|
|
62
62
|
return BigInt(Math.max(0, Math.floor(value)));
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
function toWorkflowLocation(
|
|
66
|
-
location: Location,
|
|
67
|
-
): transport.WorkflowLocation {
|
|
65
|
+
function toWorkflowLocation(location: Location): transport.WorkflowLocation {
|
|
68
66
|
return location.map((segment) => {
|
|
69
67
|
if (typeof segment === "number") {
|
|
70
68
|
return { tag: "WorkflowNameIndex", val: segment };
|
|
@@ -79,9 +77,7 @@ function toWorkflowLocation(
|
|
|
79
77
|
});
|
|
80
78
|
}
|
|
81
79
|
|
|
82
|
-
function toWorkflowEntryKind(
|
|
83
|
-
kind: EntryKind,
|
|
84
|
-
): transport.WorkflowEntryKind {
|
|
80
|
+
function toWorkflowEntryKind(kind: EntryKind): transport.WorkflowEntryKind {
|
|
85
81
|
switch (kind.type) {
|
|
86
82
|
case "step":
|
|
87
83
|
return {
|
|
@@ -124,7 +120,9 @@ function toWorkflowEntryKind(
|
|
|
124
120
|
case "join":
|
|
125
121
|
return {
|
|
126
122
|
tag: "WorkflowJoinEntry",
|
|
127
|
-
val: {
|
|
123
|
+
val: {
|
|
124
|
+
branches: toWorkflowBranchStatusMap(kind.data.branches),
|
|
125
|
+
},
|
|
128
126
|
};
|
|
129
127
|
case "race":
|
|
130
128
|
return {
|
|
@@ -147,9 +145,7 @@ function toWorkflowEntryKind(
|
|
|
147
145
|
}
|
|
148
146
|
}
|
|
149
147
|
|
|
150
|
-
function toWorkflowEntry(
|
|
151
|
-
entry: WorkflowHistoryEntry,
|
|
152
|
-
): transport.WorkflowEntry {
|
|
148
|
+
function toWorkflowEntry(entry: WorkflowHistoryEntry): transport.WorkflowEntry {
|
|
153
149
|
return {
|
|
154
150
|
id: entry.id,
|
|
155
151
|
location: toWorkflowLocation(entry.location),
|
|
@@ -176,9 +172,7 @@ function toWorkflowEntryStatus(
|
|
|
176
172
|
}
|
|
177
173
|
}
|
|
178
174
|
|
|
179
|
-
function toWorkflowSleepState(
|
|
180
|
-
state: SleepState,
|
|
181
|
-
): transport.WorkflowSleepState {
|
|
175
|
+
function toWorkflowSleepState(state: SleepState): transport.WorkflowSleepState {
|
|
182
176
|
switch (state) {
|
|
183
177
|
case "pending":
|
|
184
178
|
return transport.WorkflowSleepState.PENDING;
|
package/src/workflow/mod.ts
CHANGED
|
@@ -5,13 +5,28 @@ import type { AnyActorInstance } from "@/actor/instance/mod";
|
|
|
5
5
|
import type { EventSchemaConfig, QueueSchemaConfig } from "@/actor/schema";
|
|
6
6
|
import { RUN_FUNCTION_CONFIG_SYMBOL } from "@/actor/config";
|
|
7
7
|
import { stringifyError } from "@/utils";
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
CriticalError,
|
|
10
|
+
EntryInProgressError,
|
|
11
|
+
HistoryDivergedError,
|
|
12
|
+
JoinError,
|
|
13
|
+
RaceError,
|
|
14
|
+
RollbackCheckpointError,
|
|
15
|
+
RollbackError,
|
|
16
|
+
runWorkflow,
|
|
17
|
+
StepExhaustedError,
|
|
18
|
+
type WorkflowErrorEvent,
|
|
19
|
+
} from "@rivetkit/workflow-engine";
|
|
9
20
|
import invariant from "invariant";
|
|
10
21
|
import { ActorWorkflowContext } from "./context";
|
|
11
22
|
import { ActorWorkflowDriver } from "./driver";
|
|
12
23
|
import { createWorkflowInspectorAdapter } from "./inspector";
|
|
13
24
|
|
|
14
25
|
export { Loop } from "@rivetkit/workflow-engine";
|
|
26
|
+
export type {
|
|
27
|
+
WorkflowError,
|
|
28
|
+
WorkflowErrorEvent,
|
|
29
|
+
} from "@rivetkit/workflow-engine";
|
|
15
30
|
export {
|
|
16
31
|
ActorWorkflowContext,
|
|
17
32
|
type WorkflowBranchContextOf,
|
|
@@ -20,6 +35,53 @@ export {
|
|
|
20
35
|
type WorkflowStepContextOf,
|
|
21
36
|
} from "./context";
|
|
22
37
|
|
|
38
|
+
function shouldRethrowWorkflowError(error: unknown): boolean {
|
|
39
|
+
if (
|
|
40
|
+
error instanceof CriticalError ||
|
|
41
|
+
error instanceof JoinError ||
|
|
42
|
+
error instanceof RaceError ||
|
|
43
|
+
error instanceof RollbackError ||
|
|
44
|
+
error instanceof StepExhaustedError
|
|
45
|
+
) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (
|
|
50
|
+
error instanceof EntryInProgressError ||
|
|
51
|
+
error instanceof HistoryDivergedError ||
|
|
52
|
+
error instanceof RollbackCheckpointError
|
|
53
|
+
) {
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface WorkflowOptions<
|
|
61
|
+
TState,
|
|
62
|
+
TConnParams,
|
|
63
|
+
TConnState,
|
|
64
|
+
TVars,
|
|
65
|
+
TInput,
|
|
66
|
+
TDatabase extends AnyDatabaseProvider,
|
|
67
|
+
TEvents extends EventSchemaConfig = Record<never, never>,
|
|
68
|
+
TQueues extends QueueSchemaConfig = Record<never, never>,
|
|
69
|
+
> {
|
|
70
|
+
onError?: (
|
|
71
|
+
ctx: RunContext<
|
|
72
|
+
TState,
|
|
73
|
+
TConnParams,
|
|
74
|
+
TConnState,
|
|
75
|
+
TVars,
|
|
76
|
+
TInput,
|
|
77
|
+
TDatabase,
|
|
78
|
+
TEvents,
|
|
79
|
+
TQueues
|
|
80
|
+
>,
|
|
81
|
+
event: WorkflowErrorEvent,
|
|
82
|
+
) => void | Promise<void>;
|
|
83
|
+
}
|
|
84
|
+
|
|
23
85
|
export function workflow<
|
|
24
86
|
TState,
|
|
25
87
|
TConnParams,
|
|
@@ -42,6 +104,16 @@ export function workflow<
|
|
|
42
104
|
TQueues
|
|
43
105
|
>,
|
|
44
106
|
) => Promise<unknown>,
|
|
107
|
+
options: WorkflowOptions<
|
|
108
|
+
TState,
|
|
109
|
+
TConnParams,
|
|
110
|
+
TConnState,
|
|
111
|
+
TVars,
|
|
112
|
+
TInput,
|
|
113
|
+
TDatabase,
|
|
114
|
+
TEvents,
|
|
115
|
+
TQueues
|
|
116
|
+
> = {},
|
|
45
117
|
): (
|
|
46
118
|
c: RunContext<
|
|
47
119
|
TState,
|
|
@@ -55,6 +127,7 @@ export function workflow<
|
|
|
55
127
|
>,
|
|
56
128
|
) => Promise<void> {
|
|
57
129
|
const workflowInspector = createWorkflowInspectorAdapter();
|
|
130
|
+
const onError = options.onError;
|
|
58
131
|
|
|
59
132
|
async function run(
|
|
60
133
|
runCtx: RunContext<
|
|
@@ -86,6 +159,9 @@ export function workflow<
|
|
|
86
159
|
mode: "live",
|
|
87
160
|
logger: runCtx.log,
|
|
88
161
|
onHistoryUpdated: workflowInspector.update,
|
|
162
|
+
onError: onError
|
|
163
|
+
? async (event) => await onError(runCtx, event)
|
|
164
|
+
: undefined,
|
|
89
165
|
},
|
|
90
166
|
);
|
|
91
167
|
|
|
@@ -103,11 +179,22 @@ export function workflow<
|
|
|
103
179
|
try {
|
|
104
180
|
await handle.result;
|
|
105
181
|
} catch (error) {
|
|
106
|
-
runCtx.
|
|
107
|
-
|
|
182
|
+
if (runCtx.abortSignal.aborted) {
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (shouldRethrowWorkflowError(error)) {
|
|
187
|
+
runCtx.log.error({
|
|
188
|
+
msg: "workflow run failed",
|
|
189
|
+
error: stringifyError(error),
|
|
190
|
+
});
|
|
191
|
+
throw error;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
runCtx.log.warn({
|
|
195
|
+
msg: "workflow failed and will sleep until woken",
|
|
108
196
|
error: stringifyError(error),
|
|
109
197
|
});
|
|
110
|
-
throw error;
|
|
111
198
|
} finally {
|
|
112
199
|
runCtx.abortSignal.removeEventListener("abort", onAbort);
|
|
113
200
|
}
|