rivetkit 0.0.0-skip-ready-wait-flatten-client-options.1cae221 → 0.0.0-sqlite-uds.ea644f1
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 +2232 -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 +2234 -2084
- package/dist/tsup/agent-os/index.js.map +1 -1
- 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-XNZR7UD2.cjs → chunk-7DDQA6KN.cjs} +90 -65
- package/dist/tsup/chunk-7DDQA6KN.cjs.map +1 -0
- package/dist/tsup/{chunk-NFC5VU36.cjs → chunk-AESHILFV.cjs} +18 -10
- package/dist/tsup/chunk-AESHILFV.cjs.map +1 -0
- package/dist/tsup/{chunk-D4TSTM6C.js → chunk-EFQCNJ23.js} +83 -58
- package/dist/tsup/chunk-EFQCNJ23.js.map +1 -0
- package/dist/tsup/{chunk-OIKOPSXQ.js → chunk-FUS4OFX5.js} +12 -4
- package/dist/tsup/chunk-FUS4OFX5.js.map +1 -0
- package/dist/tsup/{chunk-IOYKCB6Y.cjs → chunk-GUCITCR3.cjs} +44 -9
- package/dist/tsup/chunk-GUCITCR3.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-PCBNKI2J.js → chunk-JZ7TWV65.js} +1 -1
- package/dist/tsup/chunk-JZ7TWV65.js.map +1 -0
- package/dist/tsup/{chunk-KSG2COSQ.js → chunk-KYBAXJRA.js} +6 -6
- package/dist/tsup/chunk-KYBAXJRA.js.map +1 -0
- package/dist/tsup/{chunk-LNMB25HW.js → chunk-LMUEIJUM.js} +780 -183
- package/dist/tsup/chunk-LMUEIJUM.js.map +1 -0
- package/dist/tsup/{chunk-RZEJJJKU.js → chunk-LTMSYD2A.js} +42 -7
- package/dist/tsup/chunk-LTMSYD2A.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-D2TLG75Y.cjs → chunk-TIUL6FNF.cjs} +10 -10
- package/dist/tsup/chunk-TIUL6FNF.cjs.map +1 -0
- package/dist/tsup/{chunk-POTPHU3P.cjs → chunk-UYT2CIWO.cjs} +3 -3
- package/dist/tsup/{chunk-POTPHU3P.cjs.map → chunk-UYT2CIWO.cjs.map} +1 -1
- package/dist/tsup/{chunk-TPBHXFB2.cjs → chunk-VDTC257X.cjs} +138 -24
- package/dist/tsup/chunk-VDTC257X.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-22XU3BVY.cjs → chunk-VWOA7DRK.cjs} +925 -328
- package/dist/tsup/chunk-VWOA7DRK.cjs.map +1 -0
- package/dist/tsup/{chunk-4ZIWB4CQ.js → chunk-VYQASICJ.js} +2 -2
- package/dist/tsup/{chunk-W54QCENI.js → chunk-X4BXYDTG.js} +134 -20
- package/dist/tsup/chunk-X4BXYDTG.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 +164 -78
- package/dist/tsup/db/drizzle.cjs.map +1 -1
- package/dist/tsup/db/drizzle.d.cts +4 -2
- package/dist/tsup/db/drizzle.d.ts +4 -2
- package/dist/tsup/db/drizzle.js +164 -78
- package/dist/tsup/db/drizzle.js.map +1 -1
- package/dist/tsup/db/mod.cjs +93 -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 +92 -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/actor-uds-protocol/v1.ts +802 -0
- 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 +137 -16
- package/src/common/database/mod.ts +100 -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 +194 -95
- 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-VYQASICJ.js.map} +0 -0
package/src/workflow/driver.ts
CHANGED
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
|
-
import type { RunContext } from "@/actor/config";
|
|
3
|
-
import type {
|
|
4
|
-
AnyActorInstance,
|
|
5
|
-
AnyStaticActorInstance,
|
|
6
|
-
} from "@/actor/definition";
|
|
7
|
-
import { makeWorkflowKey, workflowStoragePrefix } from "@/actor/keys";
|
|
8
1
|
import type {
|
|
9
2
|
EngineDriver,
|
|
10
3
|
KVEntry,
|
|
@@ -12,9 +5,27 @@ import type {
|
|
|
12
5
|
Message,
|
|
13
6
|
WorkflowMessageDriver,
|
|
14
7
|
} from "@rivetkit/workflow-engine";
|
|
8
|
+
import type { RunContext } from "@/actor/config";
|
|
9
|
+
import type { AnyStaticActorInstance } from "@/actor/definition";
|
|
10
|
+
import { makeWorkflowKey, workflowStoragePrefix } from "@/actor/keys";
|
|
15
11
|
|
|
16
12
|
const WORKFLOW_STORAGE_PREFIX = workflowStoragePrefix();
|
|
17
13
|
|
|
14
|
+
// Mirrors the element shape returned by `queueManager.receive`. The actor
|
|
15
|
+
// instance is reached through a loose type here, so the call's result is
|
|
16
|
+
// untyped and the message must be annotated explicitly.
|
|
17
|
+
interface ReceivedQueueMessage {
|
|
18
|
+
id: bigint;
|
|
19
|
+
name: string;
|
|
20
|
+
body: unknown;
|
|
21
|
+
createdAt: number;
|
|
22
|
+
complete?: (response?: unknown) => Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// `kvListPrefix` returns key/value tuples, but the loose actor type erases that
|
|
26
|
+
// so the tuple destructures need an explicit annotation.
|
|
27
|
+
type KVEntryTuple = [Uint8Array, Uint8Array];
|
|
28
|
+
|
|
18
29
|
function stripWorkflowKey(prefixed: Uint8Array): Uint8Array {
|
|
19
30
|
return prefixed.slice(WORKFLOW_STORAGE_PREFIX.length);
|
|
20
31
|
}
|
|
@@ -64,7 +75,7 @@ class ActorWorkflowMessageDriver implements WorkflowMessageDriver {
|
|
|
64
75
|
opts.completable,
|
|
65
76
|
),
|
|
66
77
|
);
|
|
67
|
-
return messages.map((message) => ({
|
|
78
|
+
return messages.map((message: ReceivedQueueMessage) => ({
|
|
68
79
|
id: message.id.toString(),
|
|
69
80
|
name: message.name,
|
|
70
81
|
data: message.body,
|
|
@@ -158,7 +169,7 @@ export class ActorWorkflowDriver implements EngineDriver {
|
|
|
158
169
|
await this.#runCtx.internalKeepAwake(
|
|
159
170
|
this.#actor.driver.kvBatchDelete(
|
|
160
171
|
this.#actor.id,
|
|
161
|
-
entries.map(([key]) => key),
|
|
172
|
+
entries.map(([key]: KVEntryTuple) => key),
|
|
162
173
|
),
|
|
163
174
|
);
|
|
164
175
|
}
|
|
@@ -181,7 +192,7 @@ export class ActorWorkflowDriver implements EngineDriver {
|
|
|
181
192
|
makeWorkflowKey(prefix),
|
|
182
193
|
),
|
|
183
194
|
);
|
|
184
|
-
return entries.map(([key, value]) => ({
|
|
195
|
+
return entries.map(([key, value]: KVEntryTuple) => ({
|
|
185
196
|
key: stripWorkflowKey(key),
|
|
186
197
|
value,
|
|
187
198
|
}));
|
|
@@ -297,7 +308,7 @@ export class ActorWorkflowControlDriver implements EngineDriver {
|
|
|
297
308
|
}
|
|
298
309
|
await this.#actor.driver.kvBatchDelete(
|
|
299
310
|
this.#actor.id,
|
|
300
|
-
entries.map(([key]) => key),
|
|
311
|
+
entries.map(([key]: KVEntryTuple) => key),
|
|
301
312
|
);
|
|
302
313
|
}
|
|
303
314
|
|
|
@@ -314,7 +325,7 @@ export class ActorWorkflowControlDriver implements EngineDriver {
|
|
|
314
325
|
this.#actor.id,
|
|
315
326
|
makeWorkflowKey(prefix),
|
|
316
327
|
);
|
|
317
|
-
return entries.map(([key, value]) => ({
|
|
328
|
+
return entries.map(([key, value]: KVEntryTuple) => ({
|
|
318
329
|
key: stripWorkflowKey(key),
|
|
319
330
|
value,
|
|
320
331
|
}));
|
|
@@ -5,14 +5,15 @@ import type {
|
|
|
5
5
|
EntryStatus,
|
|
6
6
|
Location,
|
|
7
7
|
SleepState,
|
|
8
|
+
WorkflowEntryMetadataSnapshot,
|
|
8
9
|
WorkflowHistoryEntry,
|
|
9
10
|
WorkflowHistorySnapshot,
|
|
10
|
-
WorkflowEntryMetadataSnapshot,
|
|
11
11
|
WorkflowState,
|
|
12
12
|
} from "@rivetkit/workflow-engine";
|
|
13
|
-
import { encodeWorkflowHistoryTransport } from "@/common/inspector-transport";
|
|
14
13
|
import type * as inspectorSchema from "@/common/bare/generated/inspector/v4";
|
|
15
14
|
import * as transport from "@/common/bare/transport/v1";
|
|
15
|
+
import type { JsonCompatValue } from "@/common/encoding";
|
|
16
|
+
import { encodeWorkflowHistoryTransport } from "@/common/inspector-transport";
|
|
16
17
|
import { encodeCborCompat } from "@/serde";
|
|
17
18
|
import { assertUnreachable, bufferToArrayBuffer } from "@/utils";
|
|
18
19
|
|
|
@@ -91,7 +92,7 @@ export function createWorkflowInspectorAdapter(): {
|
|
|
91
92
|
}
|
|
92
93
|
|
|
93
94
|
function encodeCbor(value: unknown): ArrayBuffer {
|
|
94
|
-
return bufferToArrayBuffer(encodeCborCompat(value));
|
|
95
|
+
return bufferToArrayBuffer(encodeCborCompat(value as JsonCompatValue));
|
|
95
96
|
}
|
|
96
97
|
|
|
97
98
|
function encodeOptionalCbor(value: unknown): ArrayBuffer | null {
|
|
@@ -183,6 +184,14 @@ function toWorkflowEntryKind(kind: EntryKind): transport.WorkflowEntryKind {
|
|
|
183
184
|
originalName: kind.data.originalName ?? null,
|
|
184
185
|
},
|
|
185
186
|
};
|
|
187
|
+
case "version_check":
|
|
188
|
+
return {
|
|
189
|
+
tag: "WorkflowVersionCheckEntry",
|
|
190
|
+
val: {
|
|
191
|
+
resolved: kind.data.resolved,
|
|
192
|
+
latest: kind.data.latest,
|
|
193
|
+
},
|
|
194
|
+
};
|
|
186
195
|
default:
|
|
187
196
|
assertUnreachable(kind as never);
|
|
188
197
|
}
|
package/src/workflow/mod.ts
CHANGED
|
@@ -1,33 +1,32 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
|
-
import {
|
|
3
|
-
ACTOR_CONTEXT_INTERNAL_SYMBOL,
|
|
4
|
-
RUN_FUNCTION_CONFIG_SYMBOL,
|
|
5
|
-
} from "@/actor/config";
|
|
6
|
-
import type { RunContext } from "@/actor/config";
|
|
7
|
-
import type { AnyDatabaseProvider } from "@/common/database/config";
|
|
8
|
-
import type { AnyStaticActorInstance } from "@/actor/definition";
|
|
9
|
-
import { RivetError } from "@/actor/errors";
|
|
10
|
-
import type { EventSchemaConfig, QueueSchemaConfig } from "@/actor/schema";
|
|
11
|
-
import { stringifyError } from "@/utils";
|
|
12
1
|
import {
|
|
13
2
|
CriticalError,
|
|
14
3
|
EntryInProgressError,
|
|
15
4
|
HistoryDivergedError,
|
|
16
5
|
JoinError,
|
|
17
6
|
RaceError,
|
|
18
|
-
replayWorkflowFromStep,
|
|
19
7
|
RollbackCheckpointError,
|
|
20
8
|
RollbackError,
|
|
9
|
+
replayWorkflowFromStep,
|
|
10
|
+
type RunWorkflowOptions,
|
|
21
11
|
runWorkflow,
|
|
22
12
|
StepExhaustedError,
|
|
23
13
|
type WorkflowErrorEvent,
|
|
24
14
|
} from "@rivetkit/workflow-engine";
|
|
25
15
|
import invariant from "invariant";
|
|
16
|
+
import type { RunContext } from "@/actor/config";
|
|
17
|
+
import {
|
|
18
|
+
ACTOR_CONTEXT_INTERNAL_SYMBOL,
|
|
19
|
+
RUN_FUNCTION_CONFIG_SYMBOL,
|
|
20
|
+
} from "@/actor/config";
|
|
21
|
+
import type { AnyStaticActorInstance } from "@/actor/definition";
|
|
22
|
+
import { isActorAbortedError, RivetError } from "@/actor/errors";
|
|
23
|
+
import type { EventSchemaConfig, QueueSchemaConfig } from "@/actor/schema";
|
|
24
|
+
import type { AnyDatabaseProvider } from "@/common/database/config";
|
|
25
|
+
import { stringifyError } from "@/utils";
|
|
26
|
+
import { WorkflowContext } from "./context";
|
|
26
27
|
import { ActorWorkflowControlDriver, ActorWorkflowDriver } from "./driver";
|
|
27
|
-
import { ActorWorkflowContext } from "./context";
|
|
28
28
|
import { createWorkflowInspectorAdapter } from "./inspector";
|
|
29
29
|
|
|
30
|
-
export { Loop } from "@rivetkit/workflow-engine";
|
|
31
30
|
export type {
|
|
32
31
|
TryBlockCatchKind,
|
|
33
32
|
TryBlockConfig,
|
|
@@ -40,12 +39,19 @@ export type {
|
|
|
40
39
|
WorkflowError,
|
|
41
40
|
WorkflowErrorEvent,
|
|
42
41
|
} from "@rivetkit/workflow-engine";
|
|
42
|
+
export { Loop } from "@rivetkit/workflow-engine";
|
|
43
43
|
export {
|
|
44
|
-
|
|
44
|
+
type WorkflowBranchConfig,
|
|
45
45
|
type WorkflowBranchContextOf,
|
|
46
|
+
WorkflowContext,
|
|
46
47
|
type WorkflowContextOf,
|
|
48
|
+
type WorkflowLoopConfig,
|
|
47
49
|
type WorkflowLoopContextOf,
|
|
50
|
+
type WorkflowStepConfig,
|
|
51
|
+
WorkflowStepContext,
|
|
48
52
|
type WorkflowStepContextOf,
|
|
53
|
+
type WorkflowTryConfig,
|
|
54
|
+
type WorkflowTryStepConfig,
|
|
49
55
|
} from "./context";
|
|
50
56
|
|
|
51
57
|
function shouldRethrowWorkflowError(error: unknown): boolean {
|
|
@@ -126,7 +132,7 @@ export function workflow<
|
|
|
126
132
|
TQueues extends QueueSchemaConfig = Record<never, never>,
|
|
127
133
|
>(
|
|
128
134
|
fn: (
|
|
129
|
-
ctx:
|
|
135
|
+
ctx: WorkflowContext<
|
|
130
136
|
TState,
|
|
131
137
|
TConnParams,
|
|
132
138
|
TConnState,
|
|
@@ -227,12 +233,14 @@ export function workflow<
|
|
|
227
233
|
|
|
228
234
|
const handle = runWorkflow(
|
|
229
235
|
actor.id,
|
|
230
|
-
async (ctx) => await fn(new
|
|
236
|
+
async (ctx) => await fn(new WorkflowContext(ctx, runCtx)),
|
|
231
237
|
undefined,
|
|
232
238
|
driver,
|
|
233
239
|
{
|
|
234
240
|
mode: "live",
|
|
235
|
-
logger
|
|
241
|
+
// The actor logger and the engine's pino logger are runtime
|
|
242
|
+
// compatible but not structurally assignable.
|
|
243
|
+
logger: runCtx.log as RunWorkflowOptions["logger"],
|
|
236
244
|
onHistoryUpdated: workflowInspector.update,
|
|
237
245
|
onError: onError
|
|
238
246
|
? async (event) => await onError(runCtx, event)
|
|
@@ -255,7 +263,9 @@ export function workflow<
|
|
|
255
263
|
try {
|
|
256
264
|
await handle.result;
|
|
257
265
|
} catch (error) {
|
|
258
|
-
|
|
266
|
+
// `abortSignal.aborted` is delivered on a separate async hop and
|
|
267
|
+
// races the rejection, so detect the sleep abort structurally too.
|
|
268
|
+
if (runCtx.abortSignal.aborted || isActorAbortedError(error)) {
|
|
259
269
|
return;
|
|
260
270
|
}
|
|
261
271
|
|
|
@@ -280,10 +290,17 @@ export function workflow<
|
|
|
280
290
|
[RUN_FUNCTION_CONFIG_SYMBOL]?: {
|
|
281
291
|
icon?: string;
|
|
282
292
|
inspectorFactory?: (actor: unknown) => unknown;
|
|
293
|
+
disposeInspector?: (actorId: string) => void;
|
|
283
294
|
};
|
|
284
295
|
};
|
|
285
296
|
runWithConfig[RUN_FUNCTION_CONFIG_SYMBOL] = {
|
|
286
297
|
icon: "diagram-project",
|
|
298
|
+
// Drop the per-actor inspector when the actor is destroyed so this map
|
|
299
|
+
// does not retain one inspector (and its encoded history) per actor id
|
|
300
|
+
// for the process lifetime.
|
|
301
|
+
disposeInspector: (actorId) => {
|
|
302
|
+
workflowInspectors.delete(actorId);
|
|
303
|
+
},
|
|
287
304
|
inspectorFactory: (actor) => {
|
|
288
305
|
const actorId = resolveWorkflowInspectorActorId(actor);
|
|
289
306
|
return {
|
|
@@ -317,10 +334,7 @@ function resolveWorkflowInspectorActorId(actor: unknown): string | undefined {
|
|
|
317
334
|
if (typeof candidate.id === "string" && candidate.id.length > 0) {
|
|
318
335
|
return candidate.id;
|
|
319
336
|
}
|
|
320
|
-
if (
|
|
321
|
-
typeof candidate.actorId === "string" &&
|
|
322
|
-
candidate.actorId.length > 0
|
|
323
|
-
) {
|
|
337
|
+
if (typeof candidate.actorId === "string" && candidate.actorId.length > 0) {
|
|
324
338
|
return candidate.actorId;
|
|
325
339
|
}
|
|
326
340
|
|