rivetkit 2.0.42 → 2.1.0-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/{tsup/config-CLnylLYY.d.ts → browser/client.d.ts} +2127 -1910
- package/dist/browser/client.js +5182 -0
- package/dist/browser/client.js.map +1 -0
- package/dist/browser/inspector/client.d.ts +130 -0
- package/dist/browser/inspector/client.js +2854 -0
- package/dist/browser/inspector/client.js.map +1 -0
- package/dist/browser/v3-DnYObHH3.d.ts +279 -0
- package/dist/schemas/actor-inspector/v2.ts +796 -0
- package/dist/schemas/actor-inspector/v3.ts +899 -0
- package/dist/schemas/actor-persist/v4.ts +406 -0
- package/dist/schemas/client-protocol/v3.ts +554 -0
- package/dist/schemas/persist/v1.ts +781 -0
- package/dist/schemas/transport/v1.ts +697 -0
- package/dist/tsup/actor/errors.cjs +27 -3
- package/dist/tsup/actor/errors.cjs.map +1 -1
- package/dist/tsup/actor/errors.d.cts +37 -1
- package/dist/tsup/actor/errors.d.ts +37 -1
- package/dist/tsup/actor/errors.js +26 -1
- package/dist/tsup/{actor-router-consts-DzI2szci.d.cts → actor-router-consts-D29T1Z-K.d.cts} +1 -1
- package/dist/tsup/{actor-router-consts-DzI2szci.d.ts → actor-router-consts-D29T1Z-K.d.ts} +1 -1
- package/dist/tsup/chunk-424PT5DM.js +23 -0
- package/dist/tsup/chunk-424PT5DM.js.map +1 -0
- package/dist/tsup/{chunk-JDAD2YFA.js → chunk-5ESWDTHJ.js} +148 -273
- package/dist/tsup/chunk-5ESWDTHJ.js.map +1 -0
- package/dist/tsup/{chunk-FJ3KTN4V.js → chunk-6LIBPELE.js} +119 -11
- package/dist/tsup/chunk-6LIBPELE.js.map +1 -0
- package/dist/tsup/chunk-6LJAZ5R4.cjs +96 -0
- package/dist/tsup/chunk-6LJAZ5R4.cjs.map +1 -0
- package/dist/tsup/{chunk-LFVF5SCU.js → chunk-7HTNH26M.js} +126 -1
- package/dist/tsup/chunk-7HTNH26M.js.map +1 -0
- package/dist/tsup/chunk-7K4CYDGD.js +630 -0
- package/dist/tsup/chunk-7K4CYDGD.js.map +1 -0
- package/dist/tsup/{chunk-XXGJCOL6.js → chunk-A6YIZWTK.js} +2 -2
- package/dist/tsup/chunk-AIYEYMX5.cjs +630 -0
- package/dist/tsup/chunk-AIYEYMX5.cjs.map +1 -0
- package/dist/tsup/{chunk-Q6W7RJJP.js → chunk-DIGBC2VI.js} +211 -2316
- package/dist/tsup/chunk-DIGBC2VI.js.map +1 -0
- package/dist/tsup/{chunk-RZW2DNND.cjs → chunk-F6JYU5IK.cjs} +1957 -1039
- package/dist/tsup/chunk-F6JYU5IK.cjs.map +1 -0
- package/dist/tsup/chunk-HAZL2EPK.cjs +534 -0
- package/dist/tsup/chunk-HAZL2EPK.cjs.map +1 -0
- package/dist/tsup/chunk-HDQ2JUQT.cjs +23 -0
- package/dist/tsup/chunk-HDQ2JUQT.cjs.map +1 -0
- package/dist/tsup/chunk-HIDX4C5Y.cjs +1036 -0
- package/dist/tsup/chunk-HIDX4C5Y.cjs.map +1 -0
- package/dist/tsup/chunk-IVG73YCW.js +534 -0
- package/dist/tsup/chunk-IVG73YCW.js.map +1 -0
- package/dist/tsup/chunk-KJSYAUOM.js +96 -0
- package/dist/tsup/chunk-KJSYAUOM.js.map +1 -0
- package/dist/tsup/{chunk-2XQS746M.cjs → chunk-L47L3ZWJ.cjs} +127 -2
- package/dist/tsup/chunk-L47L3ZWJ.cjs.map +1 -0
- package/dist/tsup/{chunk-H4TB4X25.cjs → chunk-LW6KLR7A.cjs} +126 -18
- package/dist/tsup/chunk-LW6KLR7A.cjs.map +1 -0
- package/dist/tsup/chunk-LXUQ667X.js +2006 -0
- package/dist/tsup/chunk-LXUQ667X.js.map +1 -0
- package/dist/tsup/{chunk-GMAVRZSF.js → chunk-M2T62AZQ.js} +1790 -872
- package/dist/tsup/chunk-M2T62AZQ.js.map +1 -0
- package/dist/tsup/chunk-MZ37VV3P.js +5974 -0
- package/dist/tsup/chunk-MZ37VV3P.js.map +1 -0
- package/dist/tsup/chunk-N4KRDJ56.js +72 -0
- package/dist/tsup/chunk-N4KRDJ56.js.map +1 -0
- package/dist/tsup/chunk-NIYZDWMW.cjs +2006 -0
- package/dist/tsup/chunk-NIYZDWMW.cjs.map +1 -0
- package/dist/tsup/chunk-OMEPCQK2.js +649 -0
- package/dist/tsup/chunk-OMEPCQK2.js.map +1 -0
- package/dist/tsup/chunk-SR3KQE7Q.cjs +72 -0
- package/dist/tsup/chunk-SR3KQE7Q.cjs.map +1 -0
- package/dist/tsup/chunk-SSEP6DHP.cjs +2657 -0
- package/dist/tsup/chunk-SSEP6DHP.cjs.map +1 -0
- package/dist/tsup/chunk-T5YCUGVS.js +1036 -0
- package/dist/tsup/chunk-T5YCUGVS.js.map +1 -0
- package/dist/tsup/{chunk-EJVBH5VF.cjs → chunk-TPGXWFQT.cjs} +3 -3
- package/dist/tsup/{chunk-EJVBH5VF.cjs.map → chunk-TPGXWFQT.cjs.map} +1 -1
- package/dist/tsup/{chunk-X35U3YNX.cjs → chunk-TYLXNCA5.cjs} +214 -339
- package/dist/tsup/chunk-TYLXNCA5.cjs.map +1 -0
- package/dist/tsup/chunk-VKVNIQRQ.js +257 -0
- package/dist/tsup/chunk-VKVNIQRQ.js.map +1 -0
- package/dist/tsup/chunk-XWBAQO5H.cjs +649 -0
- package/dist/tsup/chunk-XWBAQO5H.cjs.map +1 -0
- package/dist/tsup/chunk-YQ4LDVD6.cjs +5974 -0
- package/dist/tsup/chunk-YQ4LDVD6.cjs.map +1 -0
- package/dist/tsup/chunk-ZFY5J2EP.cjs +257 -0
- package/dist/tsup/chunk-ZFY5J2EP.cjs.map +1 -0
- package/dist/tsup/client/mod.cjs +9 -10
- package/dist/tsup/client/mod.cjs.map +1 -1
- package/dist/tsup/client/mod.d.cts +11 -5
- package/dist/tsup/client/mod.d.ts +11 -5
- package/dist/tsup/client/mod.js +8 -8
- package/dist/tsup/common/log.cjs +4 -4
- package/dist/tsup/common/log.d.cts +2 -2
- package/dist/tsup/common/log.d.ts +2 -2
- package/dist/tsup/common/log.js +3 -2
- package/dist/tsup/common/websocket.cjs +5 -5
- package/dist/tsup/common/websocket.js +4 -3
- package/dist/tsup/config-BFqid9Gr.d.ts +2574 -0
- package/dist/tsup/config-BiNoIHRs.d.cts +80 -0
- package/dist/tsup/config-BiNoIHRs.d.ts +80 -0
- package/dist/tsup/{config-CZB2-W8x.d.cts → config-CAZphOS1.d.cts} +681 -355
- package/dist/tsup/db/drizzle/mod.cjs +49 -0
- package/dist/tsup/db/drizzle/mod.cjs.map +1 -0
- package/dist/tsup/db/drizzle/mod.d.cts +17 -0
- package/dist/tsup/db/drizzle/mod.d.ts +17 -0
- package/dist/tsup/db/drizzle/mod.js +49 -0
- package/dist/tsup/db/drizzle/mod.js.map +1 -0
- package/dist/tsup/db/mod.cjs +9 -0
- package/dist/tsup/db/mod.cjs.map +1 -0
- package/dist/tsup/db/mod.d.cts +9 -0
- package/dist/tsup/db/mod.d.ts +9 -0
- package/dist/tsup/db/mod.js +9 -0
- package/dist/tsup/db/mod.js.map +1 -0
- package/dist/tsup/{driver-D0QX9M11.d.ts → driver-Bxv62E2p.d.ts} +2 -2
- package/dist/tsup/{driver-q-zqG7fc.d.cts → driver-DYXwJR5D.d.cts} +2 -2
- package/dist/tsup/driver-helpers/mod.cjs +12 -6
- package/dist/tsup/driver-helpers/mod.cjs.map +1 -1
- package/dist/tsup/driver-helpers/mod.d.cts +12 -5
- package/dist/tsup/driver-helpers/mod.d.ts +12 -5
- package/dist/tsup/driver-helpers/mod.js +12 -5
- package/dist/tsup/driver-test-suite/mod.cjs +1370 -116
- package/dist/tsup/driver-test-suite/mod.cjs.map +1 -1
- package/dist/tsup/driver-test-suite/mod.d.cts +10 -4
- package/dist/tsup/driver-test-suite/mod.d.ts +10 -4
- package/dist/tsup/driver-test-suite/mod.js +2093 -838
- package/dist/tsup/driver-test-suite/mod.js.map +1 -1
- package/dist/tsup/inspector/mod.cjs +29 -3
- package/dist/tsup/inspector/mod.cjs.map +1 -1
- package/dist/tsup/inspector/mod.d.cts +124 -3
- package/dist/tsup/inspector/mod.d.ts +124 -3
- package/dist/tsup/inspector/mod.js +72 -45
- package/dist/tsup/keys-CydblqMh.d.cts +13 -0
- package/dist/tsup/keys-CydblqMh.d.ts +13 -0
- package/dist/tsup/mod.cjs +16 -10
- package/dist/tsup/mod.cjs.map +1 -1
- package/dist/tsup/mod.d.cts +26 -14
- package/dist/tsup/mod.d.ts +26 -14
- package/dist/tsup/mod.js +20 -13
- package/dist/tsup/serve-test-suite/mod.cjs +1165 -83
- package/dist/tsup/serve-test-suite/mod.cjs.map +1 -1
- package/dist/tsup/serve-test-suite/mod.js +1114 -29
- package/dist/tsup/serve-test-suite/mod.js.map +1 -1
- package/dist/tsup/test/mod.cjs +84 -11
- package/dist/tsup/test/mod.cjs.map +1 -1
- package/dist/tsup/test/mod.d.cts +10 -5
- package/dist/tsup/test/mod.d.ts +10 -5
- package/dist/tsup/test/mod.js +85 -11
- package/dist/tsup/test/mod.js.map +1 -1
- package/dist/tsup/utils.cjs +10 -4
- package/dist/tsup/utils.cjs.map +1 -1
- package/dist/tsup/utils.d.cts +72 -2
- package/dist/tsup/utils.d.ts +72 -2
- package/dist/tsup/utils.js +9 -2
- package/dist/tsup/v3-DnYObHH3.d.cts +279 -0
- package/dist/tsup/v3-DnYObHH3.d.ts +279 -0
- package/dist/tsup/workflow/mod.cjs +16 -0
- package/dist/tsup/workflow/mod.cjs.map +1 -0
- package/dist/tsup/workflow/mod.d.cts +83 -0
- package/dist/tsup/workflow/mod.d.ts +83 -0
- package/dist/tsup/workflow/mod.js +16 -0
- package/dist/tsup/workflow/mod.js.map +1 -0
- package/package.json +62 -5
- package/src/actor/config.ts +478 -68
- package/src/actor/conn/mod.ts +68 -16
- package/src/actor/conn/state-manager.ts +2 -2
- package/src/actor/contexts/action.ts +20 -12
- package/src/actor/contexts/base/actor.ts +137 -7
- package/src/actor/contexts/base/conn-init.ts +27 -7
- package/src/actor/contexts/base/conn.ts +27 -18
- package/src/actor/contexts/before-action-response.ts +9 -2
- package/src/actor/contexts/before-connect.ts +7 -2
- package/src/actor/contexts/connect.ts +9 -2
- package/src/actor/contexts/create-conn-state.ts +7 -2
- package/src/actor/contexts/create-vars.ts +16 -3
- package/src/actor/contexts/create.ts +16 -3
- package/src/actor/contexts/destroy.ts +9 -3
- package/src/actor/contexts/disconnect.ts +10 -4
- package/src/actor/contexts/index.ts +4 -3
- package/src/actor/contexts/request.ts +23 -6
- package/src/actor/contexts/run.ts +47 -0
- package/src/actor/contexts/sleep.ts +9 -3
- package/src/actor/contexts/state-change.ts +9 -3
- package/src/actor/contexts/wake.ts +9 -3
- package/src/actor/contexts/websocket.ts +23 -6
- package/src/actor/database.ts +8 -18
- package/src/actor/definition.ts +20 -6
- package/src/actor/driver.ts +32 -3
- package/src/actor/errors.ts +127 -0
- package/src/actor/instance/connection-manager.ts +183 -80
- package/src/actor/instance/event-manager.ts +26 -15
- package/src/actor/instance/keys.ts +117 -0
- package/src/actor/instance/mod.ts +784 -174
- package/src/actor/instance/queue-manager.ts +603 -0
- package/src/actor/instance/queue.ts +287 -0
- package/src/actor/instance/schedule-manager.ts +49 -7
- package/src/actor/instance/state-manager.ts +35 -11
- package/src/actor/instance/traces-driver.ts +128 -0
- package/src/actor/mod.ts +26 -2
- package/src/actor/protocol/old.ts +28 -13
- package/src/actor/protocol/serde.ts +1 -1
- package/src/actor/router-endpoints.ts +177 -21
- package/src/actor/router-websocket-endpoints.ts +18 -29
- package/src/actor/router.ts +177 -0
- package/src/actor/schema.ts +291 -0
- package/src/actor/utils.ts +40 -0
- package/src/client/actor-common.ts +1 -1
- package/src/client/actor-conn.ts +100 -33
- package/src/client/actor-handle.ts +61 -33
- package/src/client/client.ts +2 -4
- package/src/client/config.ts +1 -1
- package/src/client/mod.browser.ts +2 -0
- package/src/client/mod.ts +1 -4
- package/src/client/queue.ts +146 -0
- package/src/client/utils.ts +1 -1
- package/src/common/log.ts +1 -1
- package/src/common/utils.ts +3 -3
- package/src/db/config.ts +100 -0
- package/src/db/drizzle/mod.ts +226 -0
- package/src/db/drizzle/sqlite-core.ts +22 -0
- package/src/db/mod.ts +125 -0
- package/src/db/shared.ts +92 -0
- package/src/db/sqlite-vfs.ts +12 -0
- package/src/driver-helpers/mod.ts +1 -0
- package/src/driver-test-suite/mod.ts +69 -43
- package/src/driver-test-suite/tests/access-control.ts +218 -0
- package/src/driver-test-suite/tests/actor-db-raw.ts +73 -0
- package/src/driver-test-suite/tests/actor-db.ts +394 -0
- package/src/driver-test-suite/tests/actor-inspector.ts +259 -358
- package/src/driver-test-suite/tests/actor-kv.ts +41 -20
- package/src/driver-test-suite/tests/actor-queue.ts +324 -0
- package/src/driver-test-suite/tests/actor-run.ts +181 -0
- package/src/driver-test-suite/tests/actor-schedule.ts +5 -2
- package/src/driver-test-suite/tests/actor-sleep.ts +3 -3
- package/src/driver-test-suite/tests/actor-stateless.ts +70 -0
- package/src/driver-test-suite/tests/actor-workflow.ts +108 -0
- package/src/driver-test-suite/tests/manager-driver.ts +11 -0
- package/src/driver-test-suite/tests/raw-http-request-properties.ts +1 -1
- package/src/driver-test-suite/tests/raw-websocket.ts +12 -12
- package/src/drivers/default.ts +7 -2
- package/src/drivers/engine/actor-driver.ts +45 -37
- package/src/drivers/engine/config.ts +1 -1
- package/src/drivers/file-system/actor.ts +20 -2
- package/src/drivers/file-system/global-state.ts +569 -258
- package/src/drivers/file-system/kv-limits.ts +70 -0
- package/src/drivers/file-system/manager.ts +22 -6
- package/src/drivers/file-system/mod.ts +39 -16
- package/src/drivers/file-system/sqlite-runtime.ts +210 -0
- package/src/inspector/actor-inspector.ts +224 -102
- package/src/inspector/config.ts +1 -1
- package/src/inspector/handler.ts +102 -20
- package/src/inspector/mod.browser.ts +8 -0
- package/src/inspector/mod.ts +2 -0
- package/src/inspector/serve-ui.ts +40 -0
- package/src/inspector/transport.ts +18 -0
- package/src/inspector/utils.ts +5 -39
- package/src/manager/gateway.ts +1 -1
- package/src/manager/protocol/mod.ts +1 -1
- package/src/manager/protocol/query.ts +1 -1
- package/src/manager/router-schema.ts +1 -1
- package/src/manager/router.ts +38 -12
- package/src/manager-api/actors.ts +1 -1
- package/src/manager-api/common.ts +1 -1
- package/src/registry/config/driver.ts +1 -1
- package/src/registry/config/index.ts +212 -43
- package/src/registry/config/legacy-runner.ts +1 -1
- package/src/registry/config/runner.ts +1 -1
- package/src/registry/config/serverless.ts +1 -1
- package/src/registry/index.ts +7 -5
- package/src/remote-manager-driver/api-utils.ts +1 -1
- package/src/schemas/actor-inspector/mod.ts +1 -1
- package/src/schemas/actor-inspector/versioned.ts +195 -8
- package/src/schemas/actor-persist/versioned.ts +87 -7
- package/src/schemas/client-protocol/mod.ts +1 -1
- package/src/schemas/client-protocol/versioned.ts +127 -11
- package/src/schemas/client-protocol-zod/mod.ts +16 -1
- package/src/schemas/persist/mod.ts +1 -0
- package/src/schemas/transport/mod.ts +1 -0
- package/src/serde.ts +1 -1
- package/src/serve-test-suite/mod.ts +10 -9
- package/src/test/mod.ts +15 -56
- package/src/utils/endpoint-parser.test.ts +1 -1
- package/src/utils/endpoint-parser.ts +1 -1
- package/src/utils/env-vars.ts +12 -1
- package/src/utils/node.ts +15 -2
- package/src/utils.test.ts +34 -0
- package/src/utils.ts +140 -6
- package/src/workflow/constants.ts +2 -0
- package/src/workflow/context.ts +532 -0
- package/src/workflow/driver.ts +191 -0
- package/src/workflow/inspector.ts +268 -0
- package/src/workflow/mod.ts +122 -0
- package/dist/tsup/chunk-2IJTYN6K.cjs +0 -278
- package/dist/tsup/chunk-2IJTYN6K.cjs.map +0 -1
- package/dist/tsup/chunk-2XQS746M.cjs.map +0 -1
- package/dist/tsup/chunk-3VP5CSHV.cjs +0 -114
- package/dist/tsup/chunk-3VP5CSHV.cjs.map +0 -1
- package/dist/tsup/chunk-AQFSQMBG.js +0 -114
- package/dist/tsup/chunk-AQFSQMBG.js.map +0 -1
- package/dist/tsup/chunk-E6ZE2YEA.js +0 -664
- package/dist/tsup/chunk-E6ZE2YEA.js.map +0 -1
- package/dist/tsup/chunk-FJ3KTN4V.js.map +0 -1
- package/dist/tsup/chunk-GBENOENJ.cjs +0 -8
- package/dist/tsup/chunk-GBENOENJ.cjs.map +0 -1
- package/dist/tsup/chunk-GD7UXGOE.cjs +0 -4762
- package/dist/tsup/chunk-GD7UXGOE.cjs.map +0 -1
- package/dist/tsup/chunk-GMAVRZSF.js.map +0 -1
- package/dist/tsup/chunk-H4TB4X25.cjs.map +0 -1
- package/dist/tsup/chunk-JDAD2YFA.js.map +0 -1
- package/dist/tsup/chunk-KCOVZOPS.js +0 -1946
- package/dist/tsup/chunk-KCOVZOPS.js.map +0 -1
- package/dist/tsup/chunk-KDFWJKMJ.cjs +0 -664
- package/dist/tsup/chunk-KDFWJKMJ.cjs.map +0 -1
- package/dist/tsup/chunk-LFVF5SCU.js.map +0 -1
- package/dist/tsup/chunk-Q6W7RJJP.js.map +0 -1
- package/dist/tsup/chunk-RUW5CZ5Z.cjs +0 -1949
- package/dist/tsup/chunk-RUW5CZ5Z.cjs.map +0 -1
- package/dist/tsup/chunk-RZW2DNND.cjs.map +0 -1
- package/dist/tsup/chunk-TCOEBUUE.js +0 -278
- package/dist/tsup/chunk-TCOEBUUE.js.map +0 -1
- package/dist/tsup/chunk-X35U3YNX.cjs.map +0 -1
- package/dist/tsup/keys-Chhy4ylv.d.cts +0 -8
- package/dist/tsup/keys-Chhy4ylv.d.ts +0 -8
- package/dist/tsup/v1-Gq4avTK3.d.cts +0 -240
- package/dist/tsup/v1-Gq4avTK3.d.ts +0 -240
- /package/dist/tsup/{chunk-XXGJCOL6.js.map → chunk-A6YIZWTK.js.map} +0 -0
|
@@ -0,0 +1,630 @@
|
|
|
1
|
+
import {
|
|
2
|
+
encodeWorkflowHistoryTransport
|
|
3
|
+
} from "./chunk-IVG73YCW.js";
|
|
4
|
+
import {
|
|
5
|
+
ACTOR_CONTEXT_INTERNAL_SYMBOL,
|
|
6
|
+
RUN_FUNCTION_CONFIG_SYMBOL,
|
|
7
|
+
makeWorkflowKey,
|
|
8
|
+
workflowStoragePrefix
|
|
9
|
+
} from "./chunk-T5YCUGVS.js";
|
|
10
|
+
import {
|
|
11
|
+
assertUnreachable,
|
|
12
|
+
bufferToArrayBuffer,
|
|
13
|
+
stringifyError
|
|
14
|
+
} from "./chunk-6LIBPELE.js";
|
|
15
|
+
|
|
16
|
+
// src/workflow/mod.ts
|
|
17
|
+
import { runWorkflow } from "@rivetkit/workflow-engine";
|
|
18
|
+
import invariant from "invariant";
|
|
19
|
+
|
|
20
|
+
// src/workflow/constants.ts
|
|
21
|
+
var WORKFLOW_GUARD_KV_KEY = "__rivet_actor_workflow_guard_triggered";
|
|
22
|
+
|
|
23
|
+
// src/workflow/context.ts
|
|
24
|
+
var ActorWorkflowContext = class _ActorWorkflowContext {
|
|
25
|
+
#inner;
|
|
26
|
+
#runCtx;
|
|
27
|
+
#actorAccessDepth = 0;
|
|
28
|
+
#allowActorAccess = false;
|
|
29
|
+
#guardViolation = false;
|
|
30
|
+
constructor(inner, runCtx) {
|
|
31
|
+
this.#inner = inner;
|
|
32
|
+
this.#runCtx = runCtx;
|
|
33
|
+
}
|
|
34
|
+
get workflowId() {
|
|
35
|
+
return this.#inner.workflowId;
|
|
36
|
+
}
|
|
37
|
+
get abortSignal() {
|
|
38
|
+
return this.#inner.abortSignal;
|
|
39
|
+
}
|
|
40
|
+
get queue() {
|
|
41
|
+
const self = this;
|
|
42
|
+
async function next(name, opts) {
|
|
43
|
+
const messages = await self.#inner.queue.next(name, opts);
|
|
44
|
+
return messages.map((message) => self.#toActorQueueMessage(message));
|
|
45
|
+
}
|
|
46
|
+
async function send(name, body) {
|
|
47
|
+
await self.#runCtx.queue.send(name, body);
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
next,
|
|
51
|
+
send
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
async step(nameOrConfig, run) {
|
|
55
|
+
if (typeof nameOrConfig === "string") {
|
|
56
|
+
if (!run) {
|
|
57
|
+
throw new Error("Step run function missing");
|
|
58
|
+
}
|
|
59
|
+
return await this.#wrapActive(
|
|
60
|
+
() => this.#inner.step(nameOrConfig, () => this.#withActorAccess(run))
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
const stepConfig = nameOrConfig;
|
|
64
|
+
const config = {
|
|
65
|
+
...stepConfig,
|
|
66
|
+
run: () => this.#withActorAccess(stepConfig.run)
|
|
67
|
+
};
|
|
68
|
+
return await this.#wrapActive(() => this.#inner.step(config));
|
|
69
|
+
}
|
|
70
|
+
async loop(nameOrConfig, run) {
|
|
71
|
+
if (typeof nameOrConfig === "string") {
|
|
72
|
+
if (!run) {
|
|
73
|
+
throw new Error("Loop run function missing");
|
|
74
|
+
}
|
|
75
|
+
return await this.#wrapActive(
|
|
76
|
+
() => this.#inner.loop(
|
|
77
|
+
nameOrConfig,
|
|
78
|
+
async (ctx) => run(this.#createChildContext(ctx))
|
|
79
|
+
)
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
const wrapped = {
|
|
83
|
+
...nameOrConfig,
|
|
84
|
+
run: async (ctx, state) => nameOrConfig.run(this.#createChildContext(ctx), state)
|
|
85
|
+
};
|
|
86
|
+
return await this.#wrapActive(() => this.#inner.loop(wrapped));
|
|
87
|
+
}
|
|
88
|
+
sleep(name, durationMs) {
|
|
89
|
+
return this.#inner.sleep(name, durationMs);
|
|
90
|
+
}
|
|
91
|
+
sleepUntil(name, timestampMs) {
|
|
92
|
+
return this.#inner.sleepUntil(name, timestampMs);
|
|
93
|
+
}
|
|
94
|
+
async rollbackCheckpoint(name) {
|
|
95
|
+
await this.#wrapActive(() => this.#inner.rollbackCheckpoint(name));
|
|
96
|
+
}
|
|
97
|
+
async join(name, branches) {
|
|
98
|
+
const wrappedBranches = Object.fromEntries(
|
|
99
|
+
Object.entries(branches).map(([key, branch]) => [
|
|
100
|
+
key,
|
|
101
|
+
{
|
|
102
|
+
run: async (ctx) => branch.run(this.#createChildContext(ctx))
|
|
103
|
+
}
|
|
104
|
+
])
|
|
105
|
+
);
|
|
106
|
+
return await this.#wrapActive(
|
|
107
|
+
() => this.#inner.join(name, wrappedBranches)
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
async race(name, branches) {
|
|
111
|
+
const wrappedBranches = branches.map((branch) => ({
|
|
112
|
+
name: branch.name,
|
|
113
|
+
run: (ctx) => branch.run(this.#createChildContext(ctx))
|
|
114
|
+
}));
|
|
115
|
+
return await this.#wrapActive(
|
|
116
|
+
() => this.#inner.race(name, wrappedBranches)
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
async removed(name, originalType) {
|
|
120
|
+
await this.#wrapActive(() => this.#inner.removed(name, originalType));
|
|
121
|
+
}
|
|
122
|
+
isEvicted() {
|
|
123
|
+
return this.#inner.isEvicted();
|
|
124
|
+
}
|
|
125
|
+
get state() {
|
|
126
|
+
this.#ensureActorAccess("state");
|
|
127
|
+
return this.#runCtx.state;
|
|
128
|
+
}
|
|
129
|
+
get vars() {
|
|
130
|
+
this.#ensureActorAccess("vars");
|
|
131
|
+
return this.#runCtx.vars;
|
|
132
|
+
}
|
|
133
|
+
client() {
|
|
134
|
+
this.#ensureActorAccess("client");
|
|
135
|
+
return this.#runCtx.client();
|
|
136
|
+
}
|
|
137
|
+
get db() {
|
|
138
|
+
this.#ensureActorAccess("db");
|
|
139
|
+
return this.#runCtx.db;
|
|
140
|
+
}
|
|
141
|
+
get log() {
|
|
142
|
+
return this.#runCtx.log;
|
|
143
|
+
}
|
|
144
|
+
keepAwake(promise) {
|
|
145
|
+
return this.#runCtx.keepAwake(promise);
|
|
146
|
+
}
|
|
147
|
+
waitUntil(promise) {
|
|
148
|
+
this.#runCtx.waitUntil(promise);
|
|
149
|
+
}
|
|
150
|
+
get actorId() {
|
|
151
|
+
return this.#runCtx.actorId;
|
|
152
|
+
}
|
|
153
|
+
broadcast(name, ...args) {
|
|
154
|
+
this.#runCtx.broadcast(
|
|
155
|
+
name,
|
|
156
|
+
...args
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
#toActorQueueMessage(message) {
|
|
160
|
+
let id;
|
|
161
|
+
try {
|
|
162
|
+
id = BigInt(message.id);
|
|
163
|
+
} catch {
|
|
164
|
+
throw new Error(`Invalid queue message id "${message.id}"`);
|
|
165
|
+
}
|
|
166
|
+
return {
|
|
167
|
+
id,
|
|
168
|
+
name: message.name,
|
|
169
|
+
body: message.body,
|
|
170
|
+
createdAt: message.createdAt,
|
|
171
|
+
...message.complete ? { complete: message.complete } : {}
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
async #wrapActive(run) {
|
|
175
|
+
return await this.#runCtx.keepAwake(run());
|
|
176
|
+
}
|
|
177
|
+
async #withActorAccess(run) {
|
|
178
|
+
this.#actorAccessDepth++;
|
|
179
|
+
if (this.#actorAccessDepth === 1) {
|
|
180
|
+
this.#allowActorAccess = true;
|
|
181
|
+
}
|
|
182
|
+
try {
|
|
183
|
+
return await run();
|
|
184
|
+
} finally {
|
|
185
|
+
this.#actorAccessDepth--;
|
|
186
|
+
if (this.#actorAccessDepth === 0) {
|
|
187
|
+
this.#allowActorAccess = false;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
#ensureActorAccess(feature) {
|
|
192
|
+
if (!this.#allowActorAccess) {
|
|
193
|
+
this.#guardViolation = true;
|
|
194
|
+
this.#markGuardTriggered();
|
|
195
|
+
throw new Error(
|
|
196
|
+
`${feature} is only available inside workflow steps`
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
consumeGuardViolation() {
|
|
201
|
+
const violated = this.#guardViolation;
|
|
202
|
+
this.#guardViolation = false;
|
|
203
|
+
return violated;
|
|
204
|
+
}
|
|
205
|
+
#markGuardTriggered() {
|
|
206
|
+
try {
|
|
207
|
+
const state = this.#runCtx.state;
|
|
208
|
+
if (state && typeof state === "object" && "guardTriggered" in state) {
|
|
209
|
+
state.guardTriggered = true;
|
|
210
|
+
}
|
|
211
|
+
} catch {
|
|
212
|
+
}
|
|
213
|
+
this.#runCtx.waitUntil(
|
|
214
|
+
(async () => {
|
|
215
|
+
try {
|
|
216
|
+
await this.#runCtx.kv.put(WORKFLOW_GUARD_KV_KEY, "true");
|
|
217
|
+
} catch (error) {
|
|
218
|
+
this.#runCtx.log.error({
|
|
219
|
+
msg: "failed to persist workflow guard flag",
|
|
220
|
+
error
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
})()
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
#createChildContext(ctx) {
|
|
227
|
+
return new _ActorWorkflowContext(ctx, this.#runCtx);
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
// src/workflow/driver.ts
|
|
232
|
+
var WORKFLOW_STORAGE_PREFIX = workflowStoragePrefix();
|
|
233
|
+
function stripWorkflowKey(prefixed) {
|
|
234
|
+
return prefixed.slice(WORKFLOW_STORAGE_PREFIX.length);
|
|
235
|
+
}
|
|
236
|
+
var ActorWorkflowMessageDriver = class {
|
|
237
|
+
#actor;
|
|
238
|
+
#runCtx;
|
|
239
|
+
constructor(actor, runCtx) {
|
|
240
|
+
this.#actor = actor;
|
|
241
|
+
this.#runCtx = runCtx;
|
|
242
|
+
}
|
|
243
|
+
async addMessage(message) {
|
|
244
|
+
await this.#runCtx.keepAwake(
|
|
245
|
+
this.#actor.queueManager.enqueue(message.name, message.data)
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
async receiveMessages(opts) {
|
|
249
|
+
const messages = await this.#runCtx.keepAwake(
|
|
250
|
+
this.#actor.queueManager.receive(
|
|
251
|
+
opts.names && opts.names.length > 0 ? [...opts.names] : void 0,
|
|
252
|
+
opts.count,
|
|
253
|
+
0,
|
|
254
|
+
void 0,
|
|
255
|
+
opts.completable
|
|
256
|
+
)
|
|
257
|
+
);
|
|
258
|
+
return messages.map((message) => ({
|
|
259
|
+
id: message.id.toString(),
|
|
260
|
+
name: message.name,
|
|
261
|
+
data: message.body,
|
|
262
|
+
sentAt: message.createdAt,
|
|
263
|
+
...opts.completable ? {
|
|
264
|
+
complete: async (response) => {
|
|
265
|
+
await this.#runCtx.keepAwake(
|
|
266
|
+
this.#actor.queueManager.completeMessage(
|
|
267
|
+
message,
|
|
268
|
+
response
|
|
269
|
+
)
|
|
270
|
+
);
|
|
271
|
+
}
|
|
272
|
+
} : {}
|
|
273
|
+
}));
|
|
274
|
+
}
|
|
275
|
+
async completeMessage(messageId, response) {
|
|
276
|
+
let parsedId;
|
|
277
|
+
try {
|
|
278
|
+
parsedId = BigInt(messageId);
|
|
279
|
+
} catch {
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
await this.#runCtx.keepAwake(
|
|
283
|
+
this.#actor.queueManager.completeMessageById(parsedId, response)
|
|
284
|
+
);
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
var ActorWorkflowDriver = class {
|
|
288
|
+
workerPollInterval = 100;
|
|
289
|
+
messageDriver;
|
|
290
|
+
#actor;
|
|
291
|
+
#runCtx;
|
|
292
|
+
constructor(actor, runCtx) {
|
|
293
|
+
this.#actor = actor;
|
|
294
|
+
this.#runCtx = runCtx;
|
|
295
|
+
this.messageDriver = new ActorWorkflowMessageDriver(actor, runCtx);
|
|
296
|
+
}
|
|
297
|
+
async get(key) {
|
|
298
|
+
const [value] = await this.#runCtx.keepAwake(
|
|
299
|
+
this.#actor.driver.kvBatchGet(this.#actor.id, [
|
|
300
|
+
makeWorkflowKey(key)
|
|
301
|
+
])
|
|
302
|
+
);
|
|
303
|
+
return value ?? null;
|
|
304
|
+
}
|
|
305
|
+
async set(key, value) {
|
|
306
|
+
await this.#runCtx.keepAwake(
|
|
307
|
+
this.#actor.driver.kvBatchPut(this.#actor.id, [
|
|
308
|
+
[makeWorkflowKey(key), value]
|
|
309
|
+
])
|
|
310
|
+
);
|
|
311
|
+
}
|
|
312
|
+
async delete(key) {
|
|
313
|
+
await this.#runCtx.keepAwake(
|
|
314
|
+
this.#actor.driver.kvBatchDelete(this.#actor.id, [
|
|
315
|
+
makeWorkflowKey(key)
|
|
316
|
+
])
|
|
317
|
+
);
|
|
318
|
+
}
|
|
319
|
+
async deletePrefix(prefix) {
|
|
320
|
+
const entries = await this.#runCtx.keepAwake(
|
|
321
|
+
this.#actor.driver.kvListPrefix(
|
|
322
|
+
this.#actor.id,
|
|
323
|
+
makeWorkflowKey(prefix)
|
|
324
|
+
)
|
|
325
|
+
);
|
|
326
|
+
if (entries.length === 0) {
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
await this.#runCtx.keepAwake(
|
|
330
|
+
this.#actor.driver.kvBatchDelete(
|
|
331
|
+
this.#actor.id,
|
|
332
|
+
entries.map(([key]) => key)
|
|
333
|
+
)
|
|
334
|
+
);
|
|
335
|
+
}
|
|
336
|
+
async list(prefix) {
|
|
337
|
+
const entries = await this.#runCtx.keepAwake(
|
|
338
|
+
this.#actor.driver.kvListPrefix(
|
|
339
|
+
this.#actor.id,
|
|
340
|
+
makeWorkflowKey(prefix)
|
|
341
|
+
)
|
|
342
|
+
);
|
|
343
|
+
return entries.map(([key, value]) => ({
|
|
344
|
+
key: stripWorkflowKey(key),
|
|
345
|
+
value
|
|
346
|
+
}));
|
|
347
|
+
}
|
|
348
|
+
async batch(writes) {
|
|
349
|
+
if (writes.length === 0) return;
|
|
350
|
+
await this.#runCtx.keepAwake(
|
|
351
|
+
Promise.all([
|
|
352
|
+
this.#actor.driver.kvBatchPut(
|
|
353
|
+
this.#actor.id,
|
|
354
|
+
writes.map(({ key, value }) => [makeWorkflowKey(key), value])
|
|
355
|
+
),
|
|
356
|
+
this.#actor.stateManager.saveState({ immediate: true })
|
|
357
|
+
])
|
|
358
|
+
);
|
|
359
|
+
}
|
|
360
|
+
async setAlarm(_workflowId, wakeAt) {
|
|
361
|
+
await this.#runCtx.keepAwake(
|
|
362
|
+
this.#actor.driver.setAlarm(this.#actor, wakeAt)
|
|
363
|
+
);
|
|
364
|
+
}
|
|
365
|
+
async clearAlarm(_workflowId) {
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
waitForMessages(messageNames, abortSignal) {
|
|
369
|
+
return this.#actor.queueManager.waitForNames(
|
|
370
|
+
messageNames.length > 0 ? messageNames : void 0,
|
|
371
|
+
abortSignal
|
|
372
|
+
);
|
|
373
|
+
}
|
|
374
|
+
};
|
|
375
|
+
|
|
376
|
+
// src/workflow/inspector.ts
|
|
377
|
+
import * as cbor from "cbor-x";
|
|
378
|
+
import { createNanoEvents } from "nanoevents";
|
|
379
|
+
function createWorkflowInspectorAdapter() {
|
|
380
|
+
const emitter = createNanoEvents();
|
|
381
|
+
let history = null;
|
|
382
|
+
const adapter = {
|
|
383
|
+
getHistory: () => history,
|
|
384
|
+
onHistoryUpdated: (listener) => emitter.on("updated", listener)
|
|
385
|
+
};
|
|
386
|
+
const update = (snapshot) => {
|
|
387
|
+
const transportHistory = toWorkflowHistory(snapshot);
|
|
388
|
+
const next = encodeWorkflowHistoryTransport(transportHistory);
|
|
389
|
+
history = next;
|
|
390
|
+
emitter.emit("updated", next);
|
|
391
|
+
};
|
|
392
|
+
return { adapter, update };
|
|
393
|
+
}
|
|
394
|
+
function encodeCbor(value) {
|
|
395
|
+
return bufferToArrayBuffer(cbor.encode(value));
|
|
396
|
+
}
|
|
397
|
+
function encodeOptionalCbor(value) {
|
|
398
|
+
if (value === void 0) {
|
|
399
|
+
return null;
|
|
400
|
+
}
|
|
401
|
+
return encodeCbor(value);
|
|
402
|
+
}
|
|
403
|
+
function toU64(value) {
|
|
404
|
+
return BigInt(Math.max(0, Math.floor(value)));
|
|
405
|
+
}
|
|
406
|
+
function toWorkflowLocation(location) {
|
|
407
|
+
return location.map((segment) => {
|
|
408
|
+
if (typeof segment === "number") {
|
|
409
|
+
return { tag: "WorkflowNameIndex", val: segment };
|
|
410
|
+
}
|
|
411
|
+
return {
|
|
412
|
+
tag: "WorkflowLoopIterationMarker",
|
|
413
|
+
val: {
|
|
414
|
+
loop: segment.loop,
|
|
415
|
+
iteration: segment.iteration
|
|
416
|
+
}
|
|
417
|
+
};
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
function toWorkflowEntryKind(kind) {
|
|
421
|
+
switch (kind.type) {
|
|
422
|
+
case "step":
|
|
423
|
+
return {
|
|
424
|
+
tag: "WorkflowStepEntry",
|
|
425
|
+
val: {
|
|
426
|
+
output: encodeOptionalCbor(kind.data.output),
|
|
427
|
+
error: kind.data.error ?? null
|
|
428
|
+
}
|
|
429
|
+
};
|
|
430
|
+
case "loop":
|
|
431
|
+
return {
|
|
432
|
+
tag: "WorkflowLoopEntry",
|
|
433
|
+
val: {
|
|
434
|
+
state: encodeCbor(kind.data.state),
|
|
435
|
+
iteration: kind.data.iteration,
|
|
436
|
+
output: encodeOptionalCbor(kind.data.output)
|
|
437
|
+
}
|
|
438
|
+
};
|
|
439
|
+
case "sleep":
|
|
440
|
+
return {
|
|
441
|
+
tag: "WorkflowSleepEntry",
|
|
442
|
+
val: {
|
|
443
|
+
deadline: toU64(kind.data.deadline),
|
|
444
|
+
state: toWorkflowSleepState(kind.data.state)
|
|
445
|
+
}
|
|
446
|
+
};
|
|
447
|
+
case "message":
|
|
448
|
+
return {
|
|
449
|
+
tag: "WorkflowMessageEntry",
|
|
450
|
+
val: {
|
|
451
|
+
name: kind.data.name,
|
|
452
|
+
messageData: encodeCbor(kind.data.data)
|
|
453
|
+
}
|
|
454
|
+
};
|
|
455
|
+
case "rollback_checkpoint":
|
|
456
|
+
return {
|
|
457
|
+
tag: "WorkflowRollbackCheckpointEntry",
|
|
458
|
+
val: { name: kind.data.name }
|
|
459
|
+
};
|
|
460
|
+
case "join":
|
|
461
|
+
return {
|
|
462
|
+
tag: "WorkflowJoinEntry",
|
|
463
|
+
val: { branches: toWorkflowBranchStatusMap(kind.data.branches) }
|
|
464
|
+
};
|
|
465
|
+
case "race":
|
|
466
|
+
return {
|
|
467
|
+
tag: "WorkflowRaceEntry",
|
|
468
|
+
val: {
|
|
469
|
+
winner: kind.data.winner ?? null,
|
|
470
|
+
branches: toWorkflowBranchStatusMap(kind.data.branches)
|
|
471
|
+
}
|
|
472
|
+
};
|
|
473
|
+
case "removed":
|
|
474
|
+
return {
|
|
475
|
+
tag: "WorkflowRemovedEntry",
|
|
476
|
+
val: {
|
|
477
|
+
originalType: kind.data.originalType,
|
|
478
|
+
originalName: kind.data.originalName ?? null
|
|
479
|
+
}
|
|
480
|
+
};
|
|
481
|
+
default:
|
|
482
|
+
assertUnreachable(kind);
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
function toWorkflowEntry(entry) {
|
|
486
|
+
return {
|
|
487
|
+
id: entry.id,
|
|
488
|
+
location: toWorkflowLocation(entry.location),
|
|
489
|
+
kind: toWorkflowEntryKind(entry.kind)
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
function toWorkflowEntryStatus(status) {
|
|
493
|
+
switch (status) {
|
|
494
|
+
case "pending":
|
|
495
|
+
return "PENDING" /* PENDING */;
|
|
496
|
+
case "running":
|
|
497
|
+
return "RUNNING" /* RUNNING */;
|
|
498
|
+
case "completed":
|
|
499
|
+
return "COMPLETED" /* COMPLETED */;
|
|
500
|
+
case "failed":
|
|
501
|
+
return "FAILED" /* FAILED */;
|
|
502
|
+
case "exhausted":
|
|
503
|
+
return "EXHAUSTED" /* EXHAUSTED */;
|
|
504
|
+
default:
|
|
505
|
+
assertUnreachable(status);
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
function toWorkflowSleepState(state) {
|
|
509
|
+
switch (state) {
|
|
510
|
+
case "pending":
|
|
511
|
+
return "PENDING" /* PENDING */;
|
|
512
|
+
case "completed":
|
|
513
|
+
return "COMPLETED" /* COMPLETED */;
|
|
514
|
+
case "interrupted":
|
|
515
|
+
return "INTERRUPTED" /* INTERRUPTED */;
|
|
516
|
+
default:
|
|
517
|
+
assertUnreachable(state);
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
function toWorkflowBranchStatusType(status) {
|
|
521
|
+
switch (status) {
|
|
522
|
+
case "pending":
|
|
523
|
+
return "PENDING" /* PENDING */;
|
|
524
|
+
case "running":
|
|
525
|
+
return "RUNNING" /* RUNNING */;
|
|
526
|
+
case "completed":
|
|
527
|
+
return "COMPLETED" /* COMPLETED */;
|
|
528
|
+
case "failed":
|
|
529
|
+
return "FAILED" /* FAILED */;
|
|
530
|
+
case "cancelled":
|
|
531
|
+
return "CANCELLED" /* CANCELLED */;
|
|
532
|
+
default:
|
|
533
|
+
assertUnreachable(status);
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
function toWorkflowBranchStatus(status) {
|
|
537
|
+
return {
|
|
538
|
+
status: toWorkflowBranchStatusType(status.status),
|
|
539
|
+
output: encodeOptionalCbor(status.output),
|
|
540
|
+
error: status.error ?? null
|
|
541
|
+
};
|
|
542
|
+
}
|
|
543
|
+
function toWorkflowBranchStatusMap(branches) {
|
|
544
|
+
return new Map(
|
|
545
|
+
Object.entries(branches).map(([name, status]) => [
|
|
546
|
+
name,
|
|
547
|
+
toWorkflowBranchStatus(status)
|
|
548
|
+
])
|
|
549
|
+
);
|
|
550
|
+
}
|
|
551
|
+
function toWorkflowEntryMetadata(metadata) {
|
|
552
|
+
return {
|
|
553
|
+
status: toWorkflowEntryStatus(metadata.status),
|
|
554
|
+
error: metadata.error ?? null,
|
|
555
|
+
attempts: metadata.attempts,
|
|
556
|
+
lastAttemptAt: toU64(metadata.lastAttemptAt),
|
|
557
|
+
createdAt: toU64(metadata.createdAt),
|
|
558
|
+
completedAt: metadata.completedAt === void 0 ? null : toU64(metadata.completedAt),
|
|
559
|
+
rollbackCompletedAt: metadata.rollbackCompletedAt === void 0 ? null : toU64(metadata.rollbackCompletedAt),
|
|
560
|
+
rollbackError: metadata.rollbackError ?? null
|
|
561
|
+
};
|
|
562
|
+
}
|
|
563
|
+
function toWorkflowHistory(snapshot) {
|
|
564
|
+
const entryMetadata = /* @__PURE__ */ new Map();
|
|
565
|
+
for (const [id, metadata] of snapshot.entryMetadata) {
|
|
566
|
+
entryMetadata.set(id, toWorkflowEntryMetadata(metadata));
|
|
567
|
+
}
|
|
568
|
+
return {
|
|
569
|
+
nameRegistry: snapshot.nameRegistry,
|
|
570
|
+
entries: snapshot.entries.map((entry) => toWorkflowEntry(entry)),
|
|
571
|
+
entryMetadata
|
|
572
|
+
};
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
// src/workflow/mod.ts
|
|
576
|
+
import { Loop } from "@rivetkit/workflow-engine";
|
|
577
|
+
function workflow(fn) {
|
|
578
|
+
const workflowInspector = createWorkflowInspectorAdapter();
|
|
579
|
+
async function run(runCtx) {
|
|
580
|
+
const actor = runCtx[ACTOR_CONTEXT_INTERNAL_SYMBOL];
|
|
581
|
+
invariant(actor, "workflow() requires an actor instance");
|
|
582
|
+
const driver = new ActorWorkflowDriver(actor, runCtx);
|
|
583
|
+
const handle = runWorkflow(
|
|
584
|
+
actor.id,
|
|
585
|
+
async (ctx) => await fn(new ActorWorkflowContext(ctx, runCtx)),
|
|
586
|
+
void 0,
|
|
587
|
+
driver,
|
|
588
|
+
{
|
|
589
|
+
mode: "live",
|
|
590
|
+
logger: runCtx.log,
|
|
591
|
+
onHistoryUpdated: workflowInspector.update
|
|
592
|
+
}
|
|
593
|
+
);
|
|
594
|
+
const onAbort = () => {
|
|
595
|
+
handle.evict();
|
|
596
|
+
};
|
|
597
|
+
if (runCtx.abortSignal.aborted) {
|
|
598
|
+
onAbort();
|
|
599
|
+
} else {
|
|
600
|
+
runCtx.abortSignal.addEventListener("abort", onAbort, {
|
|
601
|
+
once: true
|
|
602
|
+
});
|
|
603
|
+
}
|
|
604
|
+
try {
|
|
605
|
+
await handle.result;
|
|
606
|
+
} catch (error) {
|
|
607
|
+
runCtx.log.error({
|
|
608
|
+
msg: "workflow run failed",
|
|
609
|
+
error: stringifyError(error)
|
|
610
|
+
});
|
|
611
|
+
throw error;
|
|
612
|
+
} finally {
|
|
613
|
+
runCtx.abortSignal.removeEventListener("abort", onAbort);
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
const runWithConfig = run;
|
|
617
|
+
runWithConfig[RUN_FUNCTION_CONFIG_SYMBOL] = {
|
|
618
|
+
icon: "diagram-project",
|
|
619
|
+
inspector: { workflow: workflowInspector.adapter }
|
|
620
|
+
};
|
|
621
|
+
return runWithConfig;
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
export {
|
|
625
|
+
WORKFLOW_GUARD_KV_KEY,
|
|
626
|
+
ActorWorkflowContext,
|
|
627
|
+
workflow,
|
|
628
|
+
Loop
|
|
629
|
+
};
|
|
630
|
+
//# sourceMappingURL=chunk-7K4CYDGD.js.map
|