rivetkit 0.0.0-skip-ready-wait-flatten-client-options.1cae221 → 0.0.0-sqlite-uds.4e59a38
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 +561 -89
- package/dist/browser/client.js +1063 -430
- package/dist/browser/client.js.map +1 -1
- package/dist/browser/inspector/client.d.ts +22 -2
- package/dist/browser/inspector/client.js +1036 -232
- package/dist/browser/inspector/client.js.map +1 -1
- package/dist/tsup/actor/errors.cjs +6 -2
- package/dist/tsup/actor/errors.cjs.map +1 -1
- package/dist/tsup/actor/errors.d.cts +1 -74
- package/dist/tsup/actor/errors.d.ts +1 -74
- package/dist/tsup/actor/errors.js +5 -1
- package/dist/tsup/agent-os/index.cjs +2218 -2082
- package/dist/tsup/agent-os/index.cjs.map +1 -1
- package/dist/tsup/agent-os/index.d.cts +556 -85
- package/dist/tsup/agent-os/index.d.ts +556 -85
- package/dist/tsup/agent-os/index.js +2220 -2084
- package/dist/tsup/agent-os/index.js.map +1 -1
- package/dist/tsup/{chunk-NFC5VU36.cjs → chunk-3GC3EP6D.cjs} +18 -10
- package/dist/tsup/chunk-3GC3EP6D.cjs.map +1 -0
- package/dist/tsup/{chunk-7MRGNVSR.js → chunk-3GLNEWGY.js} +78 -6
- package/dist/tsup/chunk-3GLNEWGY.js.map +1 -0
- package/dist/tsup/{chunk-V3QNBJ7N.cjs → chunk-4FC7TVS6.cjs} +35 -10
- package/dist/tsup/chunk-4FC7TVS6.cjs.map +1 -0
- package/dist/tsup/{chunk-POTPHU3P.cjs → chunk-62LSMTP2.cjs} +3 -3
- package/dist/tsup/{chunk-POTPHU3P.cjs.map → chunk-62LSMTP2.cjs.map} +1 -1
- package/dist/tsup/{chunk-OIKOPSXQ.js → chunk-7IVUT2JT.js} +12 -4
- package/dist/tsup/chunk-7IVUT2JT.js.map +1 -0
- package/dist/tsup/{chunk-22XU3BVY.cjs → chunk-GEYQLGXC.cjs} +925 -328
- package/dist/tsup/chunk-GEYQLGXC.cjs.map +1 -0
- package/dist/tsup/{chunk-D2TLG75Y.cjs → chunk-GMN45CQ6.cjs} +10 -10
- package/dist/tsup/chunk-GMN45CQ6.cjs.map +1 -0
- package/dist/tsup/{chunk-3BFYSYRU.js → chunk-HXUEHHJF.js} +3 -2
- package/dist/tsup/chunk-HXUEHHJF.js.map +1 -0
- package/dist/tsup/{chunk-IOYKCB6Y.cjs → chunk-I336PMWT.cjs} +44 -9
- package/dist/tsup/chunk-I336PMWT.cjs.map +1 -0
- package/dist/tsup/{chunk-RZEJJJKU.js → chunk-IB73AMGJ.js} +42 -7
- package/dist/tsup/chunk-IB73AMGJ.js.map +1 -0
- package/dist/tsup/{chunk-4ZIWB4CQ.js → chunk-ITWJ6Y7G.js} +2 -2
- package/dist/tsup/{chunk-PCBNKI2J.js → chunk-JZ7TWV65.js} +1 -1
- package/dist/tsup/chunk-JZ7TWV65.js.map +1 -0
- package/dist/tsup/{chunk-W54QCENI.js → chunk-KTNBYGRU.js} +134 -20
- package/dist/tsup/chunk-KTNBYGRU.js.map +1 -0
- package/dist/tsup/{chunk-AK57AL7S.cjs → chunk-OAPVVVTX.cjs} +79 -7
- package/dist/tsup/chunk-OAPVVVTX.cjs.map +1 -0
- package/dist/tsup/{chunk-TPBHXFB2.cjs → chunk-OUDV3ITX.cjs} +138 -24
- package/dist/tsup/chunk-OUDV3ITX.cjs.map +1 -0
- package/dist/tsup/{chunk-XNZR7UD2.cjs → chunk-PRXTIERO.cjs} +90 -65
- package/dist/tsup/chunk-PRXTIERO.cjs.map +1 -0
- package/dist/tsup/{chunk-LLD2D5LO.cjs → chunk-VE2X4KMG.cjs} +3 -2
- package/dist/tsup/chunk-VE2X4KMG.cjs.map +1 -0
- package/dist/tsup/{chunk-KSG2COSQ.js → chunk-WRZEVVLL.js} +6 -6
- package/dist/tsup/chunk-WRZEVVLL.js.map +1 -0
- package/dist/tsup/{chunk-LNMB25HW.js → chunk-XAIMHUPG.js} +780 -183
- package/dist/tsup/chunk-XAIMHUPG.js.map +1 -0
- package/dist/tsup/{chunk-D4TSTM6C.js → chunk-XZ62SWSC.js} +83 -58
- package/dist/tsup/chunk-XZ62SWSC.js.map +1 -0
- package/dist/tsup/{chunk-2NDZ7JCR.cjs → chunk-ZA7FLHKH.cjs} +1 -1
- package/dist/tsup/chunk-ZA7FLHKH.cjs.map +1 -0
- package/dist/tsup/{chunk-K34B3OVG.js → chunk-ZZ3WBRPD.js} +34 -9
- package/dist/tsup/chunk-ZZ3WBRPD.js.map +1 -0
- package/dist/tsup/client/mod.cjs +9 -9
- package/dist/tsup/client/mod.cjs.map +1 -1
- package/dist/tsup/client/mod.d.cts +8 -9
- package/dist/tsup/client/mod.d.ts +8 -9
- package/dist/tsup/client/mod.js +8 -8
- package/dist/tsup/common/log.cjs +5 -3
- package/dist/tsup/common/log.cjs.map +1 -1
- package/dist/tsup/common/log.d.cts +5 -1
- package/dist/tsup/common/log.d.ts +5 -1
- package/dist/tsup/common/log.js +6 -4
- package/dist/tsup/common/websocket.cjs +4 -4
- package/dist/tsup/common/websocket.js +3 -3
- package/dist/tsup/{config-CRdGwwbr.d.cts → config-CxG53eQo.d.cts} +577 -36
- package/dist/tsup/{config-kxXbtrJU.d.ts → config-DLOxy81E.d.cts} +5 -5
- package/dist/tsup/{config-kxXbtrJU.d.cts → config-DLOxy81E.d.ts} +5 -5
- package/dist/tsup/{config-DIpBWm5C.d.ts → config-Ds6DCRhV.d.ts} +577 -36
- package/dist/tsup/context-8KlcOYIs.d.cts +129 -0
- package/dist/tsup/context-Cfbm4QLr.d.ts +129 -0
- package/dist/tsup/db/drizzle.cjs +151 -79
- package/dist/tsup/db/drizzle.cjs.map +1 -1
- package/dist/tsup/db/drizzle.d.cts +2 -2
- package/dist/tsup/db/drizzle.d.ts +2 -2
- package/dist/tsup/db/drizzle.js +151 -79
- package/dist/tsup/db/drizzle.js.map +1 -1
- package/dist/tsup/db/mod.cjs +79 -24
- package/dist/tsup/db/mod.cjs.map +1 -1
- package/dist/tsup/db/mod.d.cts +2 -2
- package/dist/tsup/db/mod.d.ts +2 -2
- package/dist/tsup/db/mod.js +78 -23
- package/dist/tsup/db/mod.js.map +1 -1
- package/dist/tsup/dynamic/mod.cjs +24 -0
- package/dist/tsup/dynamic/mod.cjs.map +1 -0
- package/dist/tsup/dynamic/mod.d.cts +37 -0
- package/dist/tsup/dynamic/mod.d.ts +37 -0
- package/dist/tsup/dynamic/mod.js +24 -0
- package/dist/tsup/dynamic/mod.js.map +1 -0
- package/dist/tsup/inspector/mod.cjs +47 -12
- package/dist/tsup/inspector/mod.cjs.map +1 -1
- package/dist/tsup/inspector/mod.d.cts +37 -15
- package/dist/tsup/inspector/mod.d.ts +37 -15
- package/dist/tsup/inspector/mod.js +46 -11
- package/dist/tsup/inspector/mod.js.map +1 -1
- package/dist/tsup/inspector-tab/mod.cjs +162 -0
- package/dist/tsup/inspector-tab/mod.cjs.map +1 -0
- package/dist/tsup/inspector-tab/mod.d.cts +240 -0
- package/dist/tsup/inspector-tab/mod.d.ts +240 -0
- package/dist/tsup/inspector-tab/mod.js +162 -0
- package/dist/tsup/inspector-tab/mod.js.map +1 -0
- package/dist/tsup/mod.cjs +1078 -479
- package/dist/tsup/mod.cjs.map +1 -1
- package/dist/tsup/mod.d.cts +5 -6
- package/dist/tsup/mod.d.ts +5 -6
- package/dist/tsup/mod.js +996 -397
- package/dist/tsup/mod.js.map +1 -1
- package/dist/tsup/test/mod.cjs +21 -18
- package/dist/tsup/test/mod.cjs.map +1 -1
- package/dist/tsup/test/mod.d.cts +4 -5
- package/dist/tsup/test/mod.d.ts +4 -5
- package/dist/tsup/test/mod.js +18 -15
- package/dist/tsup/test/mod.js.map +1 -1
- package/dist/tsup/utils-CqDnC_PS.d.cts +104 -0
- package/dist/tsup/utils-CqDnC_PS.d.ts +104 -0
- package/dist/tsup/utils.cjs +3 -3
- package/dist/tsup/utils.d.cts +1 -1
- package/dist/tsup/utils.d.ts +1 -1
- package/dist/tsup/utils.js +2 -2
- package/dist/tsup/workflow/mod.cjs +386 -322
- package/dist/tsup/workflow/mod.cjs.map +1 -1
- package/dist/tsup/workflow/mod.d.cts +8 -9
- package/dist/tsup/workflow/mod.d.ts +8 -9
- package/dist/tsup/workflow/mod.js +363 -299
- package/dist/tsup/workflow/mod.js.map +1 -1
- package/package.json +35 -14
- package/src/actor/config.ts +188 -59
- package/src/actor/contexts/index.ts +7 -2
- package/src/actor/definition.ts +17 -19
- package/src/actor/driver.ts +3 -3
- package/src/actor/errors.ts +70 -7
- package/src/actor/instance/mod.ts +39 -56
- package/src/actor/keys.ts +2 -1
- package/src/actor/mod.ts +22 -20
- package/src/actor/schema.ts +2 -2
- package/src/agent-os/actor/index.ts +38 -18
- package/src/agent-os/actor/preview.ts +1 -2
- package/src/agent-os/actor/session.ts +2 -2
- package/src/agent-os/config.ts +1 -1
- package/src/agent-os/fs/database-vfs.ts +1 -1
- package/src/agent-os/index.ts +16 -15
- package/src/client/actor-common.ts +88 -62
- package/src/client/actor-conn.ts +58 -63
- package/src/client/actor-handle.ts +125 -71
- package/src/client/actor-query.ts +5 -5
- package/src/client/config.ts +3 -3
- package/src/client/errors.ts +2 -1
- package/src/client/lifecycle-errors.ts +2 -4
- package/src/client/query.ts +1 -1
- package/src/client/queue.ts +8 -3
- package/src/client/raw-utils.ts +10 -10
- package/src/client/resolve-gateway-target.ts +1 -1
- package/src/client/utils.ts +34 -10
- package/src/common/actor-router-consts.ts +7 -4
- package/src/common/actor-websocket.ts +3 -1
- package/src/common/bare/actor-persist/v1.ts +205 -163
- package/src/common/bare/actor-persist/v2.ts +265 -213
- package/src/common/bare/actor-persist/v3.ts +176 -172
- package/src/common/bare/actor-persist/v4.ts +254 -253
- package/src/common/bare/generated/client-protocol/v4.ts +599 -0
- package/src/common/bare/generated/inspector/v5.ts +1016 -0
- package/src/common/bare/transport/v1.ts +694 -542
- package/src/common/client-protocol-versioned.ts +176 -67
- package/src/common/client-protocol-zod.ts +7 -0
- package/src/common/client-protocol.ts +1 -1
- package/src/common/database/config.ts +16 -5
- package/src/common/database/mod.test.ts +83 -16
- package/src/common/database/mod.ts +86 -30
- package/src/common/database/native-database.test.ts +35 -22
- package/src/common/database/native-database.ts +26 -10
- package/src/common/database/shared.ts +1 -0
- package/src/common/encoding.ts +250 -16
- package/src/common/engine.ts +28 -1
- package/src/common/eventsource.ts +1 -1
- package/src/common/inline-websocket-adapter.ts +14 -13
- package/src/common/log.ts +15 -8
- package/src/common/router.ts +49 -23
- package/src/common/utils.ts +10 -202
- package/src/common/websocket-interface.ts +1 -1
- package/src/db/drizzle.ts +173 -96
- package/src/db/mod.ts +1 -1
- package/src/devtools-loader/index.ts +4 -7
- package/src/devtools-loader/serve-devtools.ts +26 -0
- package/src/drivers/engine/actor-driver.ts +76 -73
- package/src/dynamic/instance.ts +32 -0
- package/src/dynamic/internal.ts +50 -0
- package/src/dynamic/isolate-runtime.ts +66 -0
- package/src/dynamic/mod.ts +32 -0
- package/src/engine-client/actor-http-client.ts +6 -9
- package/src/engine-client/actor-websocket-client.ts +14 -13
- package/src/engine-client/api-endpoints.ts +51 -2
- package/src/engine-client/api-utils.ts +2 -2
- package/src/engine-client/driver.ts +3 -4
- package/src/engine-client/mod.ts +17 -10
- package/src/engine-client/ws-proxy.ts +9 -4
- package/src/inspector/client.browser.ts +66 -15
- package/src/inspector/mod.ts +2 -4
- package/src/inspector-tab/mod.ts +300 -0
- package/src/registry/config/envoy.ts +1 -2
- package/src/registry/config/index.ts +46 -20
- package/src/registry/index.ts +364 -87
- package/src/registry/napi-runtime.ts +97 -8
- package/src/registry/native-validation.ts +10 -12
- package/src/registry/native.ts +592 -343
- package/src/registry/process-metrics.ts +250 -0
- package/src/registry/runtime.ts +85 -6
- package/src/registry/wasm-runtime.ts +72 -3
- package/src/registry/write-through-proxy.ts +40 -0
- package/src/serde.ts +2 -2
- package/src/serverless/configure.ts +19 -8
- package/src/test/mod.ts +11 -8
- package/src/utils/crypto.ts +14 -0
- package/src/utils/endpoint-parser.ts +1 -1
- package/src/utils/env-vars.ts +37 -0
- package/src/utils/router.ts +1 -1
- package/src/utils.ts +1 -2
- package/src/workflow/context.ts +703 -240
- package/src/workflow/driver.ts +23 -12
- package/src/workflow/inspector.ts +12 -3
- package/src/workflow/mod.ts +37 -23
- package/dist/tsup/chunk-22XU3BVY.cjs.map +0 -1
- package/dist/tsup/chunk-2NDZ7JCR.cjs.map +0 -1
- package/dist/tsup/chunk-3BFYSYRU.js.map +0 -1
- package/dist/tsup/chunk-7MRGNVSR.js.map +0 -1
- package/dist/tsup/chunk-AK57AL7S.cjs.map +0 -1
- package/dist/tsup/chunk-D2TLG75Y.cjs.map +0 -1
- package/dist/tsup/chunk-D4TSTM6C.js.map +0 -1
- package/dist/tsup/chunk-IOYKCB6Y.cjs.map +0 -1
- package/dist/tsup/chunk-K34B3OVG.js.map +0 -1
- package/dist/tsup/chunk-KSG2COSQ.js.map +0 -1
- package/dist/tsup/chunk-LLD2D5LO.cjs.map +0 -1
- package/dist/tsup/chunk-LNMB25HW.js.map +0 -1
- package/dist/tsup/chunk-NFC5VU36.cjs.map +0 -1
- package/dist/tsup/chunk-OIKOPSXQ.js.map +0 -1
- package/dist/tsup/chunk-PCBNKI2J.js.map +0 -1
- package/dist/tsup/chunk-RZEJJJKU.js.map +0 -1
- package/dist/tsup/chunk-TPBHXFB2.cjs.map +0 -1
- package/dist/tsup/chunk-V3QNBJ7N.cjs.map +0 -1
- package/dist/tsup/chunk-W54QCENI.js.map +0 -1
- package/dist/tsup/chunk-XNZR7UD2.cjs.map +0 -1
- package/dist/tsup/context-B7G6sk7x.d.ts +0 -92
- package/dist/tsup/context-DzMRHkjC.d.cts +0 -92
- package/dist/tsup/utils-fwx3o3K9.d.cts +0 -18
- package/dist/tsup/utils-fwx3o3K9.d.ts +0 -18
- package/src/utils/serve.ts +0 -217
- /package/dist/tsup/{chunk-4ZIWB4CQ.js.map → chunk-ITWJ6Y7G.js.map} +0 -0
|
@@ -1,22 +1,24 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createWorkflowInspectorAdapter
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-7IVUT2JT.js";
|
|
4
|
+
import "../chunk-IB73AMGJ.js";
|
|
4
5
|
import {
|
|
5
6
|
ACTOR_CONTEXT_INTERNAL_SYMBOL,
|
|
7
|
+
RAW_STATE_SYMBOL,
|
|
6
8
|
RUN_FUNCTION_CONFIG_SYMBOL
|
|
7
|
-
} from "../chunk-
|
|
8
|
-
import "../chunk-RZEJJJKU.js";
|
|
9
|
+
} from "../chunk-3GLNEWGY.js";
|
|
9
10
|
import {
|
|
10
11
|
makeWorkflowKey,
|
|
11
12
|
workflowStoragePrefix
|
|
12
|
-
} from "../chunk-
|
|
13
|
-
import "../chunk-
|
|
13
|
+
} from "../chunk-HXUEHHJF.js";
|
|
14
|
+
import "../chunk-KTNBYGRU.js";
|
|
14
15
|
import {
|
|
15
16
|
stringifyError
|
|
16
|
-
} from "../chunk-
|
|
17
|
+
} from "../chunk-XZ62SWSC.js";
|
|
17
18
|
import {
|
|
18
|
-
RivetError
|
|
19
|
-
|
|
19
|
+
RivetError,
|
|
20
|
+
isActorAbortedError
|
|
21
|
+
} from "../chunk-ZZ3WBRPD.js";
|
|
20
22
|
|
|
21
23
|
// src/workflow/mod.ts
|
|
22
24
|
import {
|
|
@@ -25,14 +27,354 @@ import {
|
|
|
25
27
|
HistoryDivergedError,
|
|
26
28
|
JoinError,
|
|
27
29
|
RaceError,
|
|
28
|
-
replayWorkflowFromStep,
|
|
29
30
|
RollbackCheckpointError,
|
|
30
31
|
RollbackError,
|
|
32
|
+
replayWorkflowFromStep,
|
|
31
33
|
runWorkflow,
|
|
32
34
|
StepExhaustedError
|
|
33
35
|
} from "@rivetkit/workflow-engine";
|
|
34
36
|
import invariant from "invariant";
|
|
35
37
|
|
|
38
|
+
// src/workflow/constants.ts
|
|
39
|
+
var WORKFLOW_GUARD_KV_KEY = "__rivet_actor_workflow_guard_triggered";
|
|
40
|
+
|
|
41
|
+
// src/workflow/context.ts
|
|
42
|
+
var DEACTIVATE_STEP = /* @__PURE__ */ Symbol("workflow.step.deactivate");
|
|
43
|
+
var WorkflowStepContext = class {
|
|
44
|
+
#runCtx;
|
|
45
|
+
#active = true;
|
|
46
|
+
#onGuardViolation;
|
|
47
|
+
constructor(runCtx, onGuardViolation) {
|
|
48
|
+
this.#runCtx = runCtx;
|
|
49
|
+
this.#onGuardViolation = onGuardViolation;
|
|
50
|
+
}
|
|
51
|
+
[DEACTIVATE_STEP]() {
|
|
52
|
+
this.#active = false;
|
|
53
|
+
}
|
|
54
|
+
#ensureActive(feature) {
|
|
55
|
+
if (!this.#active) {
|
|
56
|
+
this.#onGuardViolation();
|
|
57
|
+
throw new Error(
|
|
58
|
+
`${feature} is only available inside workflow steps`
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
get actorId() {
|
|
63
|
+
return this.#runCtx.actorId;
|
|
64
|
+
}
|
|
65
|
+
get name() {
|
|
66
|
+
return this.#runCtx.name;
|
|
67
|
+
}
|
|
68
|
+
get key() {
|
|
69
|
+
return this.#runCtx.key;
|
|
70
|
+
}
|
|
71
|
+
get log() {
|
|
72
|
+
return this.#runCtx.log;
|
|
73
|
+
}
|
|
74
|
+
get abortSignal() {
|
|
75
|
+
return this.#runCtx.abortSignal;
|
|
76
|
+
}
|
|
77
|
+
get state() {
|
|
78
|
+
this.#ensureActive("state");
|
|
79
|
+
return this.#runCtx.state;
|
|
80
|
+
}
|
|
81
|
+
get vars() {
|
|
82
|
+
this.#ensureActive("vars");
|
|
83
|
+
return this.#runCtx.vars;
|
|
84
|
+
}
|
|
85
|
+
get db() {
|
|
86
|
+
this.#ensureActive("db");
|
|
87
|
+
return this.#runCtx.db;
|
|
88
|
+
}
|
|
89
|
+
client() {
|
|
90
|
+
this.#ensureActive("client");
|
|
91
|
+
return this.#runCtx.client();
|
|
92
|
+
}
|
|
93
|
+
broadcast(name, ...args) {
|
|
94
|
+
this.#ensureActive("broadcast");
|
|
95
|
+
this.#runCtx.broadcast(
|
|
96
|
+
name,
|
|
97
|
+
...args
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
get queue() {
|
|
101
|
+
const self = this;
|
|
102
|
+
async function send(name, body) {
|
|
103
|
+
self.#ensureActive("queue.send");
|
|
104
|
+
await self.#runCtx.queue.send(name, body);
|
|
105
|
+
}
|
|
106
|
+
return { send };
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Holds the actor awake for the duration of the provided promise. The actor
|
|
110
|
+
* cannot idle-sleep or finalize the sleep grace period until the promise
|
|
111
|
+
* settles.
|
|
112
|
+
*/
|
|
113
|
+
keepAwake(promise) {
|
|
114
|
+
this.#ensureActive("keepAwake");
|
|
115
|
+
return this.#runCtx.keepAwake(promise);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Registers a promise that the sleep grace period will wait on. Use this for
|
|
119
|
+
* best-effort flush/cleanup work that may complete inside the grace window.
|
|
120
|
+
*/
|
|
121
|
+
waitUntil(promise) {
|
|
122
|
+
this.#ensureActive("waitUntil");
|
|
123
|
+
this.#runCtx.waitUntil(promise);
|
|
124
|
+
}
|
|
125
|
+
destroy() {
|
|
126
|
+
this.#ensureActive("destroy");
|
|
127
|
+
this.#runCtx.destroy();
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
var WorkflowContext = class _WorkflowContext {
|
|
131
|
+
#inner;
|
|
132
|
+
#runCtx;
|
|
133
|
+
constructor(inner, runCtx) {
|
|
134
|
+
this.#inner = inner;
|
|
135
|
+
this.#runCtx = runCtx;
|
|
136
|
+
}
|
|
137
|
+
get workflowId() {
|
|
138
|
+
return this.#inner.workflowId;
|
|
139
|
+
}
|
|
140
|
+
get abortSignal() {
|
|
141
|
+
return this.#inner.abortSignal;
|
|
142
|
+
}
|
|
143
|
+
get actorId() {
|
|
144
|
+
return this.#runCtx.actorId;
|
|
145
|
+
}
|
|
146
|
+
get name() {
|
|
147
|
+
return this.#runCtx.name;
|
|
148
|
+
}
|
|
149
|
+
get key() {
|
|
150
|
+
return this.#runCtx.key;
|
|
151
|
+
}
|
|
152
|
+
get log() {
|
|
153
|
+
return this.#runCtx.log;
|
|
154
|
+
}
|
|
155
|
+
get queue() {
|
|
156
|
+
const self = this;
|
|
157
|
+
async function next(name, opts) {
|
|
158
|
+
const message = await self.#inner.queue.next(name, opts);
|
|
159
|
+
return self.#toActorQueueMessage(message);
|
|
160
|
+
}
|
|
161
|
+
async function nextBatch(name, opts) {
|
|
162
|
+
const messages = await self.#inner.queue.nextBatch(name, opts);
|
|
163
|
+
return messages.map(
|
|
164
|
+
(message) => self.#toActorQueueMessage(message)
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
return {
|
|
168
|
+
next,
|
|
169
|
+
nextBatch
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
async step(nameOrConfig, run) {
|
|
173
|
+
if (typeof nameOrConfig === "string") {
|
|
174
|
+
if (!run) {
|
|
175
|
+
throw new Error("Step run function missing");
|
|
176
|
+
}
|
|
177
|
+
const stepRun = run;
|
|
178
|
+
return await this.#wrapActive(
|
|
179
|
+
() => this.#inner.step(nameOrConfig, () => this.#runStep(stepRun))
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
const stepConfig = nameOrConfig;
|
|
183
|
+
const rollback = stepConfig.rollback;
|
|
184
|
+
const config = {
|
|
185
|
+
...stepConfig,
|
|
186
|
+
run: () => this.#runStep(stepConfig.run),
|
|
187
|
+
rollback: rollback ? (_ctx, output) => this.#runRollback(rollback, output) : void 0
|
|
188
|
+
};
|
|
189
|
+
return await this.#wrapActive(() => this.#inner.step(config));
|
|
190
|
+
}
|
|
191
|
+
async tryStep(nameOrConfig, run) {
|
|
192
|
+
if (typeof nameOrConfig === "string") {
|
|
193
|
+
if (!run) {
|
|
194
|
+
throw new Error("Step run function missing");
|
|
195
|
+
}
|
|
196
|
+
const stepRun = run;
|
|
197
|
+
return await this.#wrapActive(
|
|
198
|
+
() => this.#inner.tryStep(nameOrConfig, () => this.#runStep(stepRun))
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
const stepConfig = nameOrConfig;
|
|
202
|
+
const rollback = stepConfig.rollback;
|
|
203
|
+
const config = {
|
|
204
|
+
...stepConfig,
|
|
205
|
+
run: () => this.#runStep(stepConfig.run),
|
|
206
|
+
rollback: rollback ? (_ctx, output) => this.#runRollback(rollback, output) : void 0
|
|
207
|
+
};
|
|
208
|
+
return await this.#wrapActive(() => this.#inner.tryStep(config));
|
|
209
|
+
}
|
|
210
|
+
async try(nameOrConfig, run) {
|
|
211
|
+
if (typeof nameOrConfig === "string") {
|
|
212
|
+
if (!run) {
|
|
213
|
+
throw new Error("Try run function missing");
|
|
214
|
+
}
|
|
215
|
+
const tryRun = run;
|
|
216
|
+
return await this.#wrapActive(
|
|
217
|
+
() => this.#inner.try(
|
|
218
|
+
nameOrConfig,
|
|
219
|
+
async (ctx) => tryRun(this.#createChildContext(ctx))
|
|
220
|
+
)
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
const tryConfig = nameOrConfig;
|
|
224
|
+
const config = {
|
|
225
|
+
...tryConfig,
|
|
226
|
+
run: async (ctx) => tryConfig.run(this.#createChildContext(ctx))
|
|
227
|
+
};
|
|
228
|
+
return await this.#wrapActive(() => this.#inner.try(config));
|
|
229
|
+
}
|
|
230
|
+
async loop(nameOrConfig, run) {
|
|
231
|
+
if (typeof nameOrConfig === "string") {
|
|
232
|
+
if (!run) {
|
|
233
|
+
throw new Error("Loop run function missing");
|
|
234
|
+
}
|
|
235
|
+
const loopRun = run;
|
|
236
|
+
return await this.#wrapActive(
|
|
237
|
+
() => this.#inner.loop(
|
|
238
|
+
nameOrConfig,
|
|
239
|
+
// A void return (no explicit Loop result) is undefined at
|
|
240
|
+
// runtime, which the engine treats as continue.
|
|
241
|
+
async (ctx) => await loopRun(this.#createChildContext(ctx)) ?? void 0
|
|
242
|
+
)
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
const loopConfig = nameOrConfig;
|
|
246
|
+
const wrapped = {
|
|
247
|
+
...loopConfig,
|
|
248
|
+
run: (async (ctx, state) => await loopConfig.run(this.#createChildContext(ctx), state) ?? void 0)
|
|
249
|
+
};
|
|
250
|
+
return await this.#wrapActive(() => this.#inner.loop(wrapped));
|
|
251
|
+
}
|
|
252
|
+
sleep(name, durationMs) {
|
|
253
|
+
return this.#inner.sleep(name, durationMs);
|
|
254
|
+
}
|
|
255
|
+
sleepUntil(name, timestampMs) {
|
|
256
|
+
return this.#inner.sleepUntil(name, timestampMs);
|
|
257
|
+
}
|
|
258
|
+
async rollbackCheckpoint(name) {
|
|
259
|
+
await this.#wrapActive(() => this.#inner.rollbackCheckpoint(name));
|
|
260
|
+
}
|
|
261
|
+
async join(name, branches) {
|
|
262
|
+
const wrappedBranches = Object.fromEntries(
|
|
263
|
+
Object.entries(branches).map(([key, branch]) => [
|
|
264
|
+
key,
|
|
265
|
+
{
|
|
266
|
+
run: async (ctx) => branch.run(this.#createChildContext(ctx))
|
|
267
|
+
}
|
|
268
|
+
])
|
|
269
|
+
);
|
|
270
|
+
return await this.#wrapActive(
|
|
271
|
+
() => this.#inner.join(name, wrappedBranches)
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
async race(name, branches) {
|
|
275
|
+
const wrappedBranches = branches.map((branch) => ({
|
|
276
|
+
name: branch.name,
|
|
277
|
+
run: (ctx) => branch.run(this.#createChildContext(ctx))
|
|
278
|
+
}));
|
|
279
|
+
return await this.#wrapActive(
|
|
280
|
+
() => this.#inner.race(name, wrappedBranches)
|
|
281
|
+
);
|
|
282
|
+
}
|
|
283
|
+
async removed(name, originalType) {
|
|
284
|
+
await this.#wrapActive(() => this.#inner.removed(name, originalType));
|
|
285
|
+
}
|
|
286
|
+
getVersion(name, latest) {
|
|
287
|
+
return this.#wrapActive(() => this.#inner.getVersion(name, latest));
|
|
288
|
+
}
|
|
289
|
+
isEvicted() {
|
|
290
|
+
return this.#inner.isEvicted();
|
|
291
|
+
}
|
|
292
|
+
// Runs a user step body inside a fresh step context, snapshotting actor
|
|
293
|
+
// state/vars so a thrown step rolls back its mutations, and deactivating the
|
|
294
|
+
// step context once the body settles so it cannot be used after the step.
|
|
295
|
+
async #runStep(run) {
|
|
296
|
+
const stepCtx = new WorkflowStepContext(this.#runCtx, () => this.#markGuardTriggered());
|
|
297
|
+
let stateSnapshot = null;
|
|
298
|
+
try {
|
|
299
|
+
stateSnapshot = { state: this.#runCtx[RAW_STATE_SYMBOL]() };
|
|
300
|
+
} catch (error) {
|
|
301
|
+
this.#runCtx.log.debug({
|
|
302
|
+
msg: "failed to get state, likely due to being stateless workflow",
|
|
303
|
+
error
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
if (stateSnapshot) {
|
|
307
|
+
stateSnapshot.state = structuredClone(stateSnapshot.state);
|
|
308
|
+
}
|
|
309
|
+
const varsSnapshot = structuredClone(this.#runCtx.vars);
|
|
310
|
+
try {
|
|
311
|
+
return await run(stepCtx);
|
|
312
|
+
} catch (error) {
|
|
313
|
+
if (stateSnapshot) {
|
|
314
|
+
this.#runCtx.state = stateSnapshot.state;
|
|
315
|
+
}
|
|
316
|
+
this.#runCtx.vars = varsSnapshot;
|
|
317
|
+
throw error;
|
|
318
|
+
} finally {
|
|
319
|
+
stepCtx[DEACTIVATE_STEP]();
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
#toActorQueueMessage(message) {
|
|
323
|
+
let id;
|
|
324
|
+
try {
|
|
325
|
+
id = BigInt(message.id);
|
|
326
|
+
} catch {
|
|
327
|
+
throw new Error(`Invalid queue message id "${message.id}"`);
|
|
328
|
+
}
|
|
329
|
+
return {
|
|
330
|
+
id,
|
|
331
|
+
name: message.name,
|
|
332
|
+
body: message.body,
|
|
333
|
+
createdAt: message.createdAt,
|
|
334
|
+
...message.complete ? { complete: message.complete } : {}
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
// Runs a step rollback compensation with an active step context. Rollbacks
|
|
338
|
+
// intentionally mutate actor state, so their writes are not snapshotted.
|
|
339
|
+
async #runRollback(rollback, output) {
|
|
340
|
+
const stepCtx = new WorkflowStepContext(this.#runCtx, () => this.#markGuardTriggered());
|
|
341
|
+
try {
|
|
342
|
+
await rollback(stepCtx, output);
|
|
343
|
+
} finally {
|
|
344
|
+
stepCtx[DEACTIVATE_STEP]();
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
async #wrapActive(run) {
|
|
348
|
+
return await this.#runCtx.internalKeepAwake(run);
|
|
349
|
+
}
|
|
350
|
+
// Records that a step context was used outside its step. Mirrors the value
|
|
351
|
+
// onto actor state and a KV flag so callers can observe the violation.
|
|
352
|
+
#markGuardTriggered() {
|
|
353
|
+
try {
|
|
354
|
+
const state = this.#runCtx.state;
|
|
355
|
+
if (state && typeof state === "object" && "guardTriggered" in state) {
|
|
356
|
+
state.guardTriggered = true;
|
|
357
|
+
}
|
|
358
|
+
} catch {
|
|
359
|
+
}
|
|
360
|
+
this.#runCtx.waitUntil(
|
|
361
|
+
(async () => {
|
|
362
|
+
try {
|
|
363
|
+
await this.#runCtx.kv.put(WORKFLOW_GUARD_KV_KEY, "true");
|
|
364
|
+
} catch (error) {
|
|
365
|
+
this.#runCtx.log.error({
|
|
366
|
+
msg: "failed to persist workflow guard flag",
|
|
367
|
+
error
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
})()
|
|
371
|
+
);
|
|
372
|
+
}
|
|
373
|
+
#createChildContext(ctx) {
|
|
374
|
+
return new _WorkflowContext(ctx, this.#runCtx);
|
|
375
|
+
}
|
|
376
|
+
};
|
|
377
|
+
|
|
36
378
|
// src/workflow/driver.ts
|
|
37
379
|
var WORKFLOW_STORAGE_PREFIX = workflowStoragePrefix();
|
|
38
380
|
function stripWorkflowKey(prefixed) {
|
|
@@ -296,293 +638,6 @@ var ActorWorkflowControlDriver = class {
|
|
|
296
638
|
}
|
|
297
639
|
};
|
|
298
640
|
|
|
299
|
-
// src/workflow/constants.ts
|
|
300
|
-
var WORKFLOW_GUARD_KV_KEY = "__rivet_actor_workflow_guard_triggered";
|
|
301
|
-
|
|
302
|
-
// src/workflow/context.ts
|
|
303
|
-
var ActorWorkflowContext = class _ActorWorkflowContext {
|
|
304
|
-
#inner;
|
|
305
|
-
#runCtx;
|
|
306
|
-
#actorAccessDepth = 0;
|
|
307
|
-
#allowActorAccess = false;
|
|
308
|
-
#guardViolation = false;
|
|
309
|
-
constructor(inner, runCtx) {
|
|
310
|
-
this.#inner = inner;
|
|
311
|
-
this.#runCtx = runCtx;
|
|
312
|
-
}
|
|
313
|
-
get workflowId() {
|
|
314
|
-
return this.#inner.workflowId;
|
|
315
|
-
}
|
|
316
|
-
get abortSignal() {
|
|
317
|
-
return this.#inner.abortSignal;
|
|
318
|
-
}
|
|
319
|
-
get queue() {
|
|
320
|
-
const self = this;
|
|
321
|
-
async function next(name, opts) {
|
|
322
|
-
const message = await self.#inner.queue.next(name, opts);
|
|
323
|
-
return self.#toActorQueueMessage(message);
|
|
324
|
-
}
|
|
325
|
-
async function nextBatch(name, opts) {
|
|
326
|
-
const messages = await self.#inner.queue.nextBatch(name, opts);
|
|
327
|
-
return messages.map(
|
|
328
|
-
(message) => self.#toActorQueueMessage(message)
|
|
329
|
-
);
|
|
330
|
-
}
|
|
331
|
-
async function send(name, body) {
|
|
332
|
-
self.#ensureActorAccess("queue.send");
|
|
333
|
-
await self.#runCtx.queue.send(name, body);
|
|
334
|
-
}
|
|
335
|
-
return {
|
|
336
|
-
next,
|
|
337
|
-
nextBatch,
|
|
338
|
-
send
|
|
339
|
-
};
|
|
340
|
-
}
|
|
341
|
-
async step(nameOrConfig, run) {
|
|
342
|
-
if (typeof nameOrConfig === "string") {
|
|
343
|
-
if (!run) {
|
|
344
|
-
throw new Error("Step run function missing");
|
|
345
|
-
}
|
|
346
|
-
return await this.#wrapActive(
|
|
347
|
-
() => this.#inner.step(
|
|
348
|
-
nameOrConfig,
|
|
349
|
-
() => this.#withActorAccess(run)
|
|
350
|
-
)
|
|
351
|
-
);
|
|
352
|
-
}
|
|
353
|
-
const stepConfig = nameOrConfig;
|
|
354
|
-
const config = {
|
|
355
|
-
...stepConfig,
|
|
356
|
-
run: () => this.#withActorAccess(stepConfig.run)
|
|
357
|
-
};
|
|
358
|
-
return await this.#wrapActive(() => this.#inner.step(config));
|
|
359
|
-
}
|
|
360
|
-
async tryStep(nameOrConfig, run) {
|
|
361
|
-
if (typeof nameOrConfig === "string") {
|
|
362
|
-
if (!run) {
|
|
363
|
-
throw new Error("Step run function missing");
|
|
364
|
-
}
|
|
365
|
-
return await this.#wrapActive(
|
|
366
|
-
() => this.#inner.tryStep(
|
|
367
|
-
nameOrConfig,
|
|
368
|
-
() => this.#withActorAccess(run)
|
|
369
|
-
)
|
|
370
|
-
);
|
|
371
|
-
}
|
|
372
|
-
const stepConfig = nameOrConfig;
|
|
373
|
-
const config = {
|
|
374
|
-
...stepConfig,
|
|
375
|
-
run: () => this.#withActorAccess(stepConfig.run)
|
|
376
|
-
};
|
|
377
|
-
return await this.#wrapActive(() => this.#inner.tryStep(config));
|
|
378
|
-
}
|
|
379
|
-
async try(nameOrConfig, run) {
|
|
380
|
-
if (typeof nameOrConfig === "string") {
|
|
381
|
-
if (!run) {
|
|
382
|
-
throw new Error("Try run function missing");
|
|
383
|
-
}
|
|
384
|
-
return await this.#wrapActive(
|
|
385
|
-
() => this.#inner.try(
|
|
386
|
-
nameOrConfig,
|
|
387
|
-
async (ctx) => run(this.#createChildContext(ctx))
|
|
388
|
-
)
|
|
389
|
-
);
|
|
390
|
-
}
|
|
391
|
-
const tryConfig = nameOrConfig;
|
|
392
|
-
const config = {
|
|
393
|
-
...tryConfig,
|
|
394
|
-
run: async (ctx) => tryConfig.run(this.#createChildContext(ctx))
|
|
395
|
-
};
|
|
396
|
-
return await this.#wrapActive(() => this.#inner.try(config));
|
|
397
|
-
}
|
|
398
|
-
async loop(nameOrConfig, run) {
|
|
399
|
-
if (typeof nameOrConfig === "string") {
|
|
400
|
-
if (!run) {
|
|
401
|
-
throw new Error("Loop run function missing");
|
|
402
|
-
}
|
|
403
|
-
return await this.#wrapActive(
|
|
404
|
-
() => this.#inner.loop(
|
|
405
|
-
nameOrConfig,
|
|
406
|
-
async (ctx) => run(this.#createChildContext(ctx))
|
|
407
|
-
)
|
|
408
|
-
);
|
|
409
|
-
}
|
|
410
|
-
const wrapped = {
|
|
411
|
-
...nameOrConfig,
|
|
412
|
-
run: async (ctx, state) => nameOrConfig.run(this.#createChildContext(ctx), state)
|
|
413
|
-
};
|
|
414
|
-
return await this.#wrapActive(() => this.#inner.loop(wrapped));
|
|
415
|
-
}
|
|
416
|
-
sleep(name, durationMs) {
|
|
417
|
-
return this.#inner.sleep(name, durationMs);
|
|
418
|
-
}
|
|
419
|
-
sleepUntil(name, timestampMs) {
|
|
420
|
-
return this.#inner.sleepUntil(name, timestampMs);
|
|
421
|
-
}
|
|
422
|
-
destroy() {
|
|
423
|
-
this.#ensureActorAccess("destroy");
|
|
424
|
-
this.#runCtx.destroy();
|
|
425
|
-
}
|
|
426
|
-
async rollbackCheckpoint(name) {
|
|
427
|
-
await this.#wrapActive(() => this.#inner.rollbackCheckpoint(name));
|
|
428
|
-
}
|
|
429
|
-
async join(name, branches) {
|
|
430
|
-
const wrappedBranches = Object.fromEntries(
|
|
431
|
-
Object.entries(branches).map(([key, branch]) => [
|
|
432
|
-
key,
|
|
433
|
-
{
|
|
434
|
-
run: async (ctx) => branch.run(this.#createChildContext(ctx))
|
|
435
|
-
}
|
|
436
|
-
])
|
|
437
|
-
);
|
|
438
|
-
return await this.#wrapActive(
|
|
439
|
-
() => this.#inner.join(name, wrappedBranches)
|
|
440
|
-
);
|
|
441
|
-
}
|
|
442
|
-
async race(name, branches) {
|
|
443
|
-
const wrappedBranches = branches.map((branch) => ({
|
|
444
|
-
name: branch.name,
|
|
445
|
-
run: (ctx) => branch.run(this.#createChildContext(ctx))
|
|
446
|
-
}));
|
|
447
|
-
return await this.#wrapActive(
|
|
448
|
-
() => this.#inner.race(name, wrappedBranches)
|
|
449
|
-
);
|
|
450
|
-
}
|
|
451
|
-
async removed(name, originalType) {
|
|
452
|
-
await this.#wrapActive(() => this.#inner.removed(name, originalType));
|
|
453
|
-
}
|
|
454
|
-
isEvicted() {
|
|
455
|
-
return this.#inner.isEvicted();
|
|
456
|
-
}
|
|
457
|
-
get state() {
|
|
458
|
-
this.#ensureActorAccess("state");
|
|
459
|
-
return this.#runCtx.state;
|
|
460
|
-
}
|
|
461
|
-
get vars() {
|
|
462
|
-
this.#ensureActorAccess("vars");
|
|
463
|
-
return this.#runCtx.vars;
|
|
464
|
-
}
|
|
465
|
-
client() {
|
|
466
|
-
this.#ensureActorAccess("client");
|
|
467
|
-
return this.#runCtx.client();
|
|
468
|
-
}
|
|
469
|
-
get db() {
|
|
470
|
-
this.#ensureActorAccess("db");
|
|
471
|
-
return this.#runCtx.db;
|
|
472
|
-
}
|
|
473
|
-
get log() {
|
|
474
|
-
return this.#runCtx.log;
|
|
475
|
-
}
|
|
476
|
-
/** @deprecated No-op. Use `keepAwake(promise)` or `waitUntil(promise)` instead. */
|
|
477
|
-
setPreventSleep(_prevent) {
|
|
478
|
-
this.#ensureActorAccess("setPreventSleep");
|
|
479
|
-
}
|
|
480
|
-
/** @deprecated No-op. Always returns `false`. */
|
|
481
|
-
get preventSleep() {
|
|
482
|
-
this.#ensureActorAccess("preventSleep");
|
|
483
|
-
return false;
|
|
484
|
-
}
|
|
485
|
-
/**
|
|
486
|
-
* Holds the actor awake for the duration of the provided promise. The
|
|
487
|
-
* actor cannot idle-sleep or finalize the sleep grace period until the
|
|
488
|
-
* promise settles.
|
|
489
|
-
*/
|
|
490
|
-
keepAwake(promise) {
|
|
491
|
-
this.#ensureActorAccess("keepAwake");
|
|
492
|
-
return this.#runCtx.keepAwake(promise);
|
|
493
|
-
}
|
|
494
|
-
/**
|
|
495
|
-
* Registers a promise that the sleep grace period will wait on. Use this
|
|
496
|
-
* for best-effort flush/cleanup work that may complete inside the grace
|
|
497
|
-
* window. For work the actor must stay running through, prefer
|
|
498
|
-
* `c.keepAwake(promise)` which also blocks idle sleep.
|
|
499
|
-
*/
|
|
500
|
-
waitUntil(promise) {
|
|
501
|
-
this.#ensureActorAccess("waitUntil");
|
|
502
|
-
this.#runCtx.waitUntil(promise);
|
|
503
|
-
}
|
|
504
|
-
get actorId() {
|
|
505
|
-
return this.#runCtx.actorId;
|
|
506
|
-
}
|
|
507
|
-
broadcast(name, ...args) {
|
|
508
|
-
this.#ensureActorAccess("broadcast");
|
|
509
|
-
this.#runCtx.broadcast(
|
|
510
|
-
name,
|
|
511
|
-
...args
|
|
512
|
-
);
|
|
513
|
-
}
|
|
514
|
-
#toActorQueueMessage(message) {
|
|
515
|
-
let id;
|
|
516
|
-
try {
|
|
517
|
-
id = BigInt(message.id);
|
|
518
|
-
} catch {
|
|
519
|
-
throw new Error(`Invalid queue message id "${message.id}"`);
|
|
520
|
-
}
|
|
521
|
-
return {
|
|
522
|
-
id,
|
|
523
|
-
name: message.name,
|
|
524
|
-
body: message.body,
|
|
525
|
-
createdAt: message.createdAt,
|
|
526
|
-
...message.complete ? { complete: message.complete } : {}
|
|
527
|
-
};
|
|
528
|
-
}
|
|
529
|
-
async #wrapActive(run) {
|
|
530
|
-
return await this.#runCtx.internalKeepAwake(run);
|
|
531
|
-
}
|
|
532
|
-
async #withActorAccess(run) {
|
|
533
|
-
this.#actorAccessDepth++;
|
|
534
|
-
if (this.#actorAccessDepth === 1) {
|
|
535
|
-
this.#allowActorAccess = true;
|
|
536
|
-
}
|
|
537
|
-
try {
|
|
538
|
-
return await run();
|
|
539
|
-
} finally {
|
|
540
|
-
this.#actorAccessDepth--;
|
|
541
|
-
if (this.#actorAccessDepth === 0) {
|
|
542
|
-
this.#allowActorAccess = false;
|
|
543
|
-
}
|
|
544
|
-
}
|
|
545
|
-
}
|
|
546
|
-
#ensureActorAccess(feature) {
|
|
547
|
-
if (!this.#allowActorAccess) {
|
|
548
|
-
this.#guardViolation = true;
|
|
549
|
-
this.#markGuardTriggered();
|
|
550
|
-
throw new Error(
|
|
551
|
-
`${feature} is only available inside workflow steps`
|
|
552
|
-
);
|
|
553
|
-
}
|
|
554
|
-
}
|
|
555
|
-
consumeGuardViolation() {
|
|
556
|
-
const violated = this.#guardViolation;
|
|
557
|
-
this.#guardViolation = false;
|
|
558
|
-
return violated;
|
|
559
|
-
}
|
|
560
|
-
#markGuardTriggered() {
|
|
561
|
-
try {
|
|
562
|
-
const state = this.#runCtx.state;
|
|
563
|
-
if (state && typeof state === "object" && "guardTriggered" in state) {
|
|
564
|
-
state.guardTriggered = true;
|
|
565
|
-
}
|
|
566
|
-
} catch {
|
|
567
|
-
}
|
|
568
|
-
this.#runCtx.waitUntil(
|
|
569
|
-
(async () => {
|
|
570
|
-
try {
|
|
571
|
-
await this.#runCtx.kv.put(WORKFLOW_GUARD_KV_KEY, "true");
|
|
572
|
-
} catch (error) {
|
|
573
|
-
this.#runCtx.log.error({
|
|
574
|
-
msg: "failed to persist workflow guard flag",
|
|
575
|
-
error
|
|
576
|
-
});
|
|
577
|
-
}
|
|
578
|
-
})()
|
|
579
|
-
);
|
|
580
|
-
}
|
|
581
|
-
#createChildContext(ctx) {
|
|
582
|
-
return new _ActorWorkflowContext(ctx, this.#runCtx);
|
|
583
|
-
}
|
|
584
|
-
};
|
|
585
|
-
|
|
586
641
|
// src/workflow/mod.ts
|
|
587
642
|
import { Loop } from "@rivetkit/workflow-engine";
|
|
588
643
|
function shouldRethrowWorkflowError(error) {
|
|
@@ -650,11 +705,13 @@ function workflow(fn, options = {}) {
|
|
|
650
705
|
});
|
|
651
706
|
const handle = runWorkflow(
|
|
652
707
|
actor.id,
|
|
653
|
-
async (ctx) => await fn(new
|
|
708
|
+
async (ctx) => await fn(new WorkflowContext(ctx, runCtx)),
|
|
654
709
|
void 0,
|
|
655
710
|
driver,
|
|
656
711
|
{
|
|
657
712
|
mode: "live",
|
|
713
|
+
// The actor logger and the engine's pino logger are runtime
|
|
714
|
+
// compatible but not structurally assignable.
|
|
658
715
|
logger: runCtx.log,
|
|
659
716
|
onHistoryUpdated: workflowInspector.update,
|
|
660
717
|
onError: onError ? async (event) => await onError(runCtx, event) : void 0
|
|
@@ -674,7 +731,7 @@ function workflow(fn, options = {}) {
|
|
|
674
731
|
try {
|
|
675
732
|
await handle.result;
|
|
676
733
|
} catch (error) {
|
|
677
|
-
if (runCtx.abortSignal.aborted) {
|
|
734
|
+
if (runCtx.abortSignal.aborted || isActorAbortedError(error)) {
|
|
678
735
|
return;
|
|
679
736
|
}
|
|
680
737
|
if (shouldRethrowWorkflowError(error)) {
|
|
@@ -695,6 +752,12 @@ function workflow(fn, options = {}) {
|
|
|
695
752
|
const runWithConfig = run;
|
|
696
753
|
runWithConfig[RUN_FUNCTION_CONFIG_SYMBOL] = {
|
|
697
754
|
icon: "diagram-project",
|
|
755
|
+
// Drop the per-actor inspector when the actor is destroyed so this map
|
|
756
|
+
// does not retain one inspector (and its encoded history) per actor id
|
|
757
|
+
// for the process lifetime.
|
|
758
|
+
disposeInspector: (actorId) => {
|
|
759
|
+
workflowInspectors.delete(actorId);
|
|
760
|
+
},
|
|
698
761
|
inspectorFactory: (actor) => {
|
|
699
762
|
const actorId = resolveWorkflowInspectorActorId(actor);
|
|
700
763
|
return {
|
|
@@ -726,8 +789,9 @@ function resolveWorkflowInspectorActorId(actor) {
|
|
|
726
789
|
return void 0;
|
|
727
790
|
}
|
|
728
791
|
export {
|
|
729
|
-
ActorWorkflowContext,
|
|
730
792
|
Loop,
|
|
793
|
+
WorkflowContext,
|
|
794
|
+
WorkflowStepContext,
|
|
731
795
|
workflow
|
|
732
796
|
};
|
|
733
797
|
//# sourceMappingURL=mod.js.map
|