rivetkit 0.0.0-active-actors-fix-active-count.253e406 → 0.0.0-bisect-sync-sqlite-1.910d1c7
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 +1286 -89
- package/dist/browser/client.js +1699 -704
- package/dist/browser/client.js.map +1 -1
- package/dist/browser/inspector/client.d.ts +252 -129
- package/dist/browser/inspector/client.js +2083 -236
- package/dist/browser/inspector/client.js.map +1 -1
- package/dist/tsup/actor/errors.cjs +8 -2
- package/dist/tsup/actor/errors.cjs.map +1 -1
- package/dist/tsup/actor/errors.d.cts +1 -1
- package/dist/tsup/actor/errors.d.ts +1 -1
- package/dist/tsup/actor/errors.js +7 -1
- package/dist/tsup/agent-os/index.cjs +3 -2289
- package/dist/tsup/agent-os/index.cjs.map +1 -1
- package/dist/tsup/agent-os/index.d.cts +1 -1813
- package/dist/tsup/agent-os/index.d.ts +1 -1813
- package/dist/tsup/agent-os/index.js +3 -2289
- package/dist/tsup/agent-os/index.js.map +1 -1
- package/dist/tsup/chunk-2JJU7IQ7.cjs +14 -0
- package/dist/tsup/chunk-2JJU7IQ7.cjs.map +1 -0
- package/dist/tsup/{chunk-DZJZLZ4R.js → chunk-2MXBZGUP.js} +2 -2
- package/dist/tsup/{chunk-L4FVS7GY.js → chunk-47IS5ZFI.js} +6 -6
- package/dist/tsup/chunk-47IS5ZFI.js.map +1 -0
- package/dist/tsup/{chunk-DXWOGCZY.js → chunk-5XWY5CBA.js} +70 -8
- package/dist/tsup/chunk-5XWY5CBA.js.map +1 -0
- package/dist/tsup/{chunk-OQEEZDIK.cjs → chunk-6XVNZKKP.cjs} +506 -31
- package/dist/tsup/chunk-6XVNZKKP.cjs.map +1 -0
- package/dist/tsup/{chunk-3YY5S6TV.js → chunk-A2CF6PFH.js} +20 -12
- package/dist/tsup/chunk-A2CF6PFH.js.map +1 -0
- package/dist/tsup/{chunk-WQ4HNA4W.cjs → chunk-AQJFKHBK.cjs} +276 -27
- package/dist/tsup/chunk-AQJFKHBK.cjs.map +1 -0
- package/dist/tsup/chunk-DPWLASMC.cjs +244 -0
- package/dist/tsup/chunk-DPWLASMC.cjs.map +1 -0
- package/dist/tsup/{chunk-VUF2YEF4.cjs → chunk-DYJOU3MF.cjs} +10 -10
- package/dist/tsup/chunk-DYJOU3MF.cjs.map +1 -0
- package/dist/tsup/{chunk-7WXCRV25.cjs → chunk-ELZ6MT3V.cjs} +18 -11
- package/dist/tsup/chunk-ELZ6MT3V.cjs.map +1 -0
- package/dist/tsup/chunk-HYIVSH5X.js +244 -0
- package/dist/tsup/chunk-HYIVSH5X.js.map +1 -0
- package/dist/tsup/{chunk-T6YVRM4K.js → chunk-IHEO5OT3.js} +275 -26
- package/dist/tsup/chunk-IHEO5OT3.js.map +1 -0
- package/dist/tsup/chunk-IWACVNN5.js +14 -0
- package/dist/tsup/chunk-IWACVNN5.js.map +1 -0
- package/dist/tsup/{chunk-PCBNKI2J.js → chunk-JTHHCZCZ.js} +24 -1
- package/dist/tsup/chunk-JTHHCZCZ.js.map +1 -0
- package/dist/tsup/{chunk-V4JUWAT6.js → chunk-K3AJOPSF.js} +498 -23
- package/dist/tsup/chunk-K3AJOPSF.js.map +1 -0
- package/dist/tsup/{chunk-2NDZ7JCR.cjs → chunk-KVFIONKQ.cjs} +25 -2
- package/dist/tsup/chunk-KVFIONKQ.cjs.map +1 -0
- package/dist/tsup/{chunk-QAZLM4WT.cjs → chunk-MGI2VVF6.cjs} +45 -9
- package/dist/tsup/chunk-MGI2VVF6.cjs.map +1 -0
- package/dist/tsup/{chunk-QNLGOTQP.js → chunk-NPHTIUUJ.js} +1291 -420
- package/dist/tsup/chunk-NPHTIUUJ.js.map +1 -0
- package/dist/tsup/{chunk-7GKQJFSB.cjs → chunk-POCSZXPQ.cjs} +72 -10
- package/dist/tsup/chunk-POCSZXPQ.cjs.map +1 -0
- package/dist/tsup/{chunk-LD5YASJU.cjs → chunk-RTWH3AX3.cjs} +19 -11
- package/dist/tsup/chunk-RTWH3AX3.cjs.map +1 -0
- package/dist/tsup/{chunk-ARRBQTAR.cjs → chunk-X76BM5JS.cjs} +1420 -549
- package/dist/tsup/chunk-X76BM5JS.cjs.map +1 -0
- package/dist/tsup/{chunk-AGBP757I.js → chunk-X7SYKFPM.js} +16 -9
- package/dist/tsup/chunk-X7SYKFPM.js.map +1 -0
- package/dist/tsup/{chunk-GKAMEBTZ.cjs → chunk-XLDJSZ3B.cjs} +3 -3
- package/dist/tsup/{chunk-GKAMEBTZ.cjs.map → chunk-XLDJSZ3B.cjs.map} +1 -1
- package/dist/tsup/{chunk-KIWH5H3K.js → chunk-ZOVJDAOW.js} +44 -8
- package/dist/tsup/chunk-ZOVJDAOW.js.map +1 -0
- package/dist/tsup/client/mod.cjs +8 -9
- package/dist/tsup/client/mod.cjs.map +1 -1
- package/dist/tsup/client/mod.d.cts +33 -7
- package/dist/tsup/client/mod.d.ts +33 -7
- package/dist/tsup/client/mod.js +7 -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-nlTlOKaE.d.cts → config-BMGUEKMZ.d.cts} +1252 -75
- package/dist/tsup/config-CBTr4IhE.d.cts +224 -0
- package/dist/tsup/config-CBTr4IhE.d.ts +224 -0
- package/dist/tsup/{config-D7ykAntK.d.ts → config-iBpXyITj.d.ts} +1252 -75
- package/dist/tsup/context-hyVakgnU.d.ts +136 -0
- package/dist/tsup/context-qfvLuF0P.d.cts +136 -0
- package/dist/tsup/db/drizzle.cjs +127 -67
- package/dist/tsup/db/drizzle.cjs.map +1 -1
- package/dist/tsup/db/drizzle.d.cts +8 -4
- package/dist/tsup/db/drizzle.d.ts +8 -4
- package/dist/tsup/db/drizzle.js +127 -67
- package/dist/tsup/db/drizzle.js.map +1 -1
- package/dist/tsup/db/mod.cjs +6 -124
- package/dist/tsup/db/mod.cjs.map +1 -1
- package/dist/tsup/db/mod.d.cts +12 -4
- package/dist/tsup/db/mod.d.ts +12 -4
- package/dist/tsup/db/mod.js +5 -123
- 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 +39 -0
- package/dist/tsup/dynamic/mod.d.ts +39 -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 +26 -136
- package/dist/tsup/inspector/mod.d.ts +26 -136
- package/dist/tsup/inspector/mod.js +46 -11
- package/dist/tsup/inspector/mod.js.map +1 -1
- package/dist/tsup/inspector/workflow.cjs +21 -0
- package/dist/tsup/inspector/workflow.cjs.map +1 -0
- package/dist/tsup/inspector/workflow.d.cts +144 -0
- package/dist/tsup/inspector/workflow.d.ts +144 -0
- package/dist/tsup/inspector/workflow.js +21 -0
- package/dist/tsup/inspector/workflow.js.map +1 -0
- 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 +242 -0
- package/dist/tsup/inspector-tab/mod.d.ts +242 -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 +3527 -753
- package/dist/tsup/mod.cjs.map +1 -1
- package/dist/tsup/mod.d.cts +11 -7
- package/dist/tsup/mod.d.ts +11 -7
- package/dist/tsup/mod.js +3468 -694
- package/dist/tsup/mod.js.map +1 -1
- package/dist/tsup/test/mod.cjs +26 -21
- package/dist/tsup/test/mod.cjs.map +1 -1
- package/dist/tsup/test/mod.d.cts +7 -5
- package/dist/tsup/test/mod.d.ts +7 -5
- package/dist/tsup/test/mod.js +25 -20
- package/dist/tsup/test/mod.js.map +1 -1
- package/dist/tsup/unstable/migrations.cjs +101 -0
- package/dist/tsup/unstable/migrations.cjs.map +1 -0
- package/dist/tsup/unstable/migrations.d.cts +29 -0
- package/dist/tsup/unstable/migrations.d.ts +29 -0
- package/dist/tsup/unstable/migrations.js +101 -0
- package/dist/tsup/unstable/migrations.js.map +1 -0
- package/dist/tsup/{utils-DVekpm4I.d.ts → utils-3rsE0JvI.d.cts} +26 -2
- package/dist/tsup/{utils-DVekpm4I.d.cts → utils-3rsE0JvI.d.ts} +26 -2
- package/dist/tsup/utils-C1O-SklO.d.ts +162 -0
- package/dist/tsup/utils-C6b0aYUM.d.cts +162 -0
- package/dist/tsup/utils.cjs +7 -3
- package/dist/tsup/utils.cjs.map +1 -1
- package/dist/tsup/utils.d.cts +4 -147
- package/dist/tsup/utils.d.ts +4 -147
- package/dist/tsup/utils.js +6 -2
- package/dist/tsup/workflow/mod.cjs +557 -410
- package/dist/tsup/workflow/mod.cjs.map +1 -1
- package/dist/tsup/workflow/mod.d.cts +11 -9
- package/dist/tsup/workflow/mod.d.ts +11 -9
- package/dist/tsup/workflow/mod.js +551 -404
- package/dist/tsup/workflow/mod.js.map +1 -1
- package/package.json +67 -18
- package/src/actor/actions.ts +155 -0
- package/src/actor/config.ts +679 -101
- package/src/actor/contexts/index.ts +9 -2
- package/src/actor/definition.ts +75 -26
- package/src/actor/errors.ts +107 -8
- package/src/actor/keys.ts +87 -1
- package/src/actor/mod.ts +36 -20
- package/src/actor/schema.ts +6 -2
- package/src/actor/tracing.ts +28 -0
- package/src/agent-os/index.ts +5 -64
- package/src/client/actor-common.ts +84 -54
- package/src/client/actor-conn.ts +231 -68
- package/src/client/actor-handle.ts +283 -89
- package/src/client/actor-query.ts +13 -6
- package/src/client/auth.ts +37 -0
- package/src/client/client.ts +182 -21
- package/src/client/config.ts +28 -3
- package/src/client/errors.ts +15 -2
- package/src/client/lifecycle-errors.ts +63 -5
- package/src/client/mod.ts +10 -0
- package/src/client/outbound-telemetry.ts +66 -0
- package/src/client/query.ts +3 -1
- package/src/client/queue.ts +13 -3
- package/src/client/raw-utils.ts +59 -14
- package/src/client/resolve-gateway-target.ts +3 -1
- package/src/client/retry-budget.ts +81 -0
- package/src/client/token-provider.ts +93 -0
- package/src/client/utils.ts +22 -9
- package/src/common/actor-router-consts.ts +6 -0
- package/src/common/actor-telemetry-context.ts +19 -0
- 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/inspector/v5.ts +1016 -0
- package/src/common/bare/generated/inspector/v6.ts +1367 -0
- package/src/common/bare/transport/v1.ts +694 -542
- package/src/common/client-protocol-versioned.ts +66 -64
- package/src/common/database/config.ts +175 -9
- package/src/common/database/mod.ts +262 -77
- package/src/common/database/native-database.ts +442 -20
- package/src/common/database/shared.ts +25 -0
- package/src/common/encoding.ts +278 -34
- package/src/common/engine.ts +28 -1
- package/src/common/eventsource.ts +1 -1
- package/src/common/fetch-like.ts +63 -0
- package/src/common/inline-websocket-adapter.ts +14 -13
- package/src/common/inspector-transport.ts +12 -2
- package/src/common/log.ts +15 -8
- package/src/common/otel-context.ts +99 -0
- package/src/common/router.ts +14 -18
- package/src/common/utils.ts +8 -169
- package/src/common/websocket-interface.ts +1 -1
- package/src/db/drizzle.ts +182 -80
- package/src/db/mod.ts +5 -1
- package/src/devtools-loader/index.ts +4 -7
- package/src/devtools-loader/serve-devtools.ts +26 -0
- package/src/dynamic/instance.ts +32 -0
- package/src/dynamic/internal.ts +50 -0
- package/src/dynamic/isolate-runtime.ts +64 -0
- package/src/dynamic/mod.ts +32 -0
- package/src/engine-api/actors.ts +15 -3
- package/src/engine-client/actor-http-client.ts +37 -22
- package/src/engine-client/actor-websocket-client.ts +37 -9
- package/src/engine-client/api-endpoints.ts +128 -5
- package/src/engine-client/api-utils.ts +2 -2
- package/src/engine-client/driver.ts +21 -16
- package/src/engine-client/mod.ts +280 -111
- package/src/engine-client/ws-proxy.ts +9 -4
- package/src/inspector/client.browser.ts +127 -15
- package/src/inspector/mod.ts +2 -4
- package/src/inspector/workflow.ts +61 -0
- package/src/inspector-tab/mod.ts +301 -0
- package/src/registry/config/envoy.ts +3 -20
- package/src/registry/config/index.ts +91 -74
- package/src/registry/index.ts +702 -80
- package/src/registry/napi-runtime.ts +643 -42
- package/src/registry/native-http.ts +225 -0
- package/src/registry/native-validation.ts +10 -12
- package/src/registry/native.ts +1881 -582
- package/src/registry/run-handler-coordinator.ts +219 -0
- package/src/registry/runtime.ts +441 -7
- package/src/registry/wasm-runtime.ts +516 -23
- package/src/registry/write-through-proxy.ts +141 -0
- package/src/serde.ts +2 -2
- package/src/serverless/configure.ts +18 -7
- package/src/test/mod.ts +2 -17
- package/src/test/ready.ts +22 -0
- package/src/unstable/migrations.ts +141 -0
- package/src/utils/endpoint-parser.ts +1 -1
- package/src/utils/env-vars.ts +50 -2
- package/src/utils/node.ts +44 -28
- package/src/utils/router.ts +1 -1
- package/src/utils.ts +4 -2
- package/src/workflow/context.ts +703 -242
- package/src/workflow/driver.ts +284 -125
- package/src/workflow/inspector.ts +24 -24
- package/src/workflow/mod.ts +76 -84
- package/dist/tsup/chunk-2NDZ7JCR.cjs.map +0 -1
- package/dist/tsup/chunk-3YY5S6TV.js.map +0 -1
- package/dist/tsup/chunk-6NT2LIFN.cjs +0 -268
- package/dist/tsup/chunk-6NT2LIFN.cjs.map +0 -1
- package/dist/tsup/chunk-7GKQJFSB.cjs.map +0 -1
- package/dist/tsup/chunk-7WXCRV25.cjs.map +0 -1
- package/dist/tsup/chunk-AGBP757I.js.map +0 -1
- package/dist/tsup/chunk-ARRBQTAR.cjs.map +0 -1
- package/dist/tsup/chunk-DXWOGCZY.js.map +0 -1
- package/dist/tsup/chunk-JGIPV3QU.js +0 -268
- package/dist/tsup/chunk-JGIPV3QU.js.map +0 -1
- package/dist/tsup/chunk-KIWH5H3K.js.map +0 -1
- package/dist/tsup/chunk-L4FVS7GY.js.map +0 -1
- package/dist/tsup/chunk-LD5YASJU.cjs.map +0 -1
- package/dist/tsup/chunk-OQEEZDIK.cjs.map +0 -1
- package/dist/tsup/chunk-PCBNKI2J.js.map +0 -1
- package/dist/tsup/chunk-QAZLM4WT.cjs.map +0 -1
- package/dist/tsup/chunk-QNLGOTQP.js.map +0 -1
- package/dist/tsup/chunk-T6YVRM4K.js.map +0 -1
- package/dist/tsup/chunk-V4JUWAT6.js.map +0 -1
- package/dist/tsup/chunk-VUF2YEF4.cjs.map +0 -1
- package/dist/tsup/chunk-WQ4HNA4W.cjs.map +0 -1
- package/dist/tsup/config-CxjGYf4K.d.cts +0 -121
- package/dist/tsup/config-CxjGYf4K.d.ts +0 -121
- package/dist/tsup/context-88opQsfZ.d.cts +0 -92
- package/dist/tsup/context-CVEG5zfg.d.ts +0 -92
- package/src/actor/driver.ts +0 -141
- package/src/actor/instance/mod.ts +0 -2492
- package/src/actor/keys.test.ts +0 -275
- package/src/actor/utils.test.ts +0 -48
- package/src/agent-os/actor/cron.ts +0 -84
- package/src/agent-os/actor/db.ts +0 -54
- package/src/agent-os/actor/filesystem.ts +0 -131
- package/src/agent-os/actor/index.ts +0 -265
- package/src/agent-os/actor/network.ts +0 -58
- package/src/agent-os/actor/preview.ts +0 -191
- package/src/agent-os/actor/process.ts +0 -177
- package/src/agent-os/actor/session.ts +0 -518
- package/src/agent-os/actor/shell.ts +0 -60
- package/src/agent-os/config.ts +0 -79
- package/src/agent-os/fs/database-vfs.ts +0 -624
- package/src/agent-os/types.ts +0 -148
- package/src/client/test.ts +0 -44
- package/src/common/database/mod.test.ts +0 -137
- package/src/common/database/native-database.test.ts +0 -211
- package/src/common/inline-websocket-adapter.test.ts +0 -51
- package/src/drivers/engine/actor-driver.ts +0 -2460
- package/src/registry/runtime.test.ts +0 -50
- package/src/utils/endpoint-parser.test.ts +0 -206
- package/src/utils/serve.ts +0 -217
- package/src/utils.test.ts +0 -34
- /package/dist/tsup/{chunk-DZJZLZ4R.js.map → chunk-2MXBZGUP.js.map} +0 -0
package/src/workflow/driver.ts
CHANGED
|
@@ -1,19 +1,38 @@
|
|
|
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,
|
|
11
4
|
KVWrite,
|
|
12
5
|
Message,
|
|
13
6
|
WorkflowMessageDriver,
|
|
7
|
+
WorkflowTelemetryDriver,
|
|
14
8
|
} from "@rivetkit/workflow-engine";
|
|
9
|
+
import type { RunContext } from "@/actor/config";
|
|
10
|
+
import type { AnyStaticActorInstance } from "@/actor/definition";
|
|
11
|
+
import { makeWorkflowKey, workflowStoragePrefix } from "@/actor/keys";
|
|
12
|
+
import type { RawAccess } from "@/common/database/config";
|
|
15
13
|
|
|
16
14
|
const WORKFLOW_STORAGE_PREFIX = workflowStoragePrefix();
|
|
15
|
+
// Keep workflow flushes below depot's 320-dirty-page commit ceiling. The
|
|
16
|
+
// former actor-KV transport allowed 976 KiB batches; SQLite also dirties table
|
|
17
|
+
// and index pages, so it needs the same conservative budget as core imports.
|
|
18
|
+
const WORKFLOW_SQLITE_MAX_BATCH_ROWS = 128;
|
|
19
|
+
const WORKFLOW_SQLITE_MAX_BATCH_BYTES = 512 * 1024;
|
|
20
|
+
// Static names group each kind of workflow storage transaction in SQLite profiles.
|
|
21
|
+
const WORKFLOW_BATCH_TRANSACTION_NAME = "rivetkit-workflow-batch";
|
|
22
|
+
const WORKFLOW_DELETE_TRANSACTION_NAME = "rivetkit-workflow-delete";
|
|
23
|
+
|
|
24
|
+
// Mirrors the element shape returned by `queueManager.receive`. The actor
|
|
25
|
+
// instance is reached through a loose type here, so the call's result is
|
|
26
|
+
// untyped and the message must be annotated explicitly.
|
|
27
|
+
interface ReceivedQueueMessage {
|
|
28
|
+
id: bigint;
|
|
29
|
+
name: string;
|
|
30
|
+
body: unknown;
|
|
31
|
+
createdAt: number;
|
|
32
|
+
complete?: (response?: unknown) => Promise<void>;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
type KVEntryTuple = [Uint8Array, Uint8Array];
|
|
17
36
|
|
|
18
37
|
function stripWorkflowKey(prefixed: Uint8Array): Uint8Array {
|
|
19
38
|
return prefixed.slice(WORKFLOW_STORAGE_PREFIX.length);
|
|
@@ -30,6 +49,215 @@ function computeUpperBound(prefix: Uint8Array): Uint8Array | null {
|
|
|
30
49
|
return null;
|
|
31
50
|
}
|
|
32
51
|
|
|
52
|
+
function normalizeSqlBlob(value: unknown): Uint8Array {
|
|
53
|
+
if (value instanceof Uint8Array) {
|
|
54
|
+
return value;
|
|
55
|
+
}
|
|
56
|
+
if (value instanceof ArrayBuffer) {
|
|
57
|
+
return new Uint8Array(value);
|
|
58
|
+
}
|
|
59
|
+
if (ArrayBuffer.isView(value)) {
|
|
60
|
+
return new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
|
|
61
|
+
}
|
|
62
|
+
if (Array.isArray(value)) {
|
|
63
|
+
const bytes = new Uint8Array(value.length);
|
|
64
|
+
for (const [i, item] of value.entries()) {
|
|
65
|
+
if (!Number.isInteger(item) || item < 0 || item > 255) {
|
|
66
|
+
throw new Error("workflow sqlite value was not a byte array");
|
|
67
|
+
}
|
|
68
|
+
bytes[i] = item;
|
|
69
|
+
}
|
|
70
|
+
return bytes;
|
|
71
|
+
}
|
|
72
|
+
throw new Error("workflow sqlite value was not a blob");
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function runtimeDbFromContext(
|
|
76
|
+
runCtx?: RunContext<any, any, any, any, any, any, any, any>,
|
|
77
|
+
): RawAccess | undefined {
|
|
78
|
+
const db = (runCtx as unknown as { db?: unknown } | undefined)?.db;
|
|
79
|
+
if (
|
|
80
|
+
db &&
|
|
81
|
+
typeof db === "object" &&
|
|
82
|
+
"execute" in db &&
|
|
83
|
+
"transaction" in db
|
|
84
|
+
) {
|
|
85
|
+
return db as RawAccess;
|
|
86
|
+
}
|
|
87
|
+
return undefined;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
class WorkflowStorage {
|
|
91
|
+
#db: RawAccess;
|
|
92
|
+
|
|
93
|
+
constructor(db?: RawAccess) {
|
|
94
|
+
if (!db) {
|
|
95
|
+
throw new Error(
|
|
96
|
+
"workflow storage requires embedded SQLite; actor KV workflow storage is no longer supported",
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
this.#db = db;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
async get(key: Uint8Array): Promise<Uint8Array | null> {
|
|
103
|
+
const prefixed = makeWorkflowKey(key);
|
|
104
|
+
const rows = await this.#db.execute<{ value: unknown }>(
|
|
105
|
+
"SELECT value FROM _rivet_wf_kv WHERE key = ?",
|
|
106
|
+
prefixed,
|
|
107
|
+
);
|
|
108
|
+
return rows[0]?.value == null ? null : normalizeSqlBlob(rows[0].value);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
async set(key: Uint8Array, value: Uint8Array): Promise<void> {
|
|
112
|
+
await this.batch([{ key, value }]);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
async delete(key: Uint8Array): Promise<void> {
|
|
116
|
+
const prefixed = makeWorkflowKey(key);
|
|
117
|
+
await this.#db.execute(
|
|
118
|
+
"DELETE FROM _rivet_wf_kv WHERE key = ?",
|
|
119
|
+
prefixed,
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
async batchDelete(keys: Uint8Array[]): Promise<void> {
|
|
124
|
+
if (keys.length === 0) return;
|
|
125
|
+
await this.deleteRawKeys(keys.map((key) => makeWorkflowKey(key)));
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
async deletePrefix(prefix: Uint8Array): Promise<void> {
|
|
129
|
+
const start = makeWorkflowKey(prefix);
|
|
130
|
+
const end = computeUpperBound(start);
|
|
131
|
+
if (end) {
|
|
132
|
+
await this.#db.execute(
|
|
133
|
+
"DELETE FROM _rivet_wf_kv WHERE key >= ? AND key < ?",
|
|
134
|
+
start,
|
|
135
|
+
end,
|
|
136
|
+
);
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
const entries = await this.listRaw(start);
|
|
140
|
+
await this.deleteRawKeys(
|
|
141
|
+
entries
|
|
142
|
+
.filter(([key]) => keyStartsWith(key, start))
|
|
143
|
+
.map(([key]) => key),
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
async deleteRange(start: Uint8Array, end: Uint8Array): Promise<void> {
|
|
148
|
+
const prefixedStart = makeWorkflowKey(start);
|
|
149
|
+
const prefixedEnd = makeWorkflowKey(end);
|
|
150
|
+
await this.#db.execute(
|
|
151
|
+
"DELETE FROM _rivet_wf_kv WHERE key >= ? AND key < ?",
|
|
152
|
+
prefixedStart,
|
|
153
|
+
prefixedEnd,
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
async list(prefix: Uint8Array): Promise<KVEntry[]> {
|
|
158
|
+
const prefixed = makeWorkflowKey(prefix);
|
|
159
|
+
const entries = await this.listRaw(prefixed);
|
|
160
|
+
return entries
|
|
161
|
+
.filter(([key]) => keyStartsWith(key, prefixed))
|
|
162
|
+
.map(([key, value]: KVEntryTuple) => ({
|
|
163
|
+
key: stripWorkflowKey(key),
|
|
164
|
+
value,
|
|
165
|
+
}));
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
async batch(writes: KVWrite[]): Promise<void> {
|
|
169
|
+
if (writes.length === 0) return;
|
|
170
|
+
for (const chunk of chunkWorkflowWrites(writes)) {
|
|
171
|
+
await this.#db.transaction(
|
|
172
|
+
async (tx) => {
|
|
173
|
+
for (const { key, value } of chunk) {
|
|
174
|
+
await tx.execute(
|
|
175
|
+
"INSERT INTO _rivet_wf_kv (key, value) VALUES (?, ?) ON CONFLICT(key) DO UPDATE SET value = excluded.value",
|
|
176
|
+
makeWorkflowKey(key),
|
|
177
|
+
value,
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
{ name: WORKFLOW_BATCH_TRANSACTION_NAME },
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
async listRaw(prefix: Uint8Array): Promise<KVEntryTuple[]> {
|
|
187
|
+
const end = computeUpperBound(prefix);
|
|
188
|
+
const rows = end
|
|
189
|
+
? await this.#db.execute<{ key: unknown; value: unknown }>(
|
|
190
|
+
"SELECT key, value FROM _rivet_wf_kv WHERE key >= ? AND key < ? ORDER BY key ASC",
|
|
191
|
+
prefix,
|
|
192
|
+
end,
|
|
193
|
+
)
|
|
194
|
+
: await this.#db.execute<{ key: unknown; value: unknown }>(
|
|
195
|
+
"SELECT key, value FROM _rivet_wf_kv WHERE key >= ? ORDER BY key ASC",
|
|
196
|
+
prefix,
|
|
197
|
+
);
|
|
198
|
+
return rows.map((row) => [
|
|
199
|
+
normalizeSqlBlob(row.key),
|
|
200
|
+
normalizeSqlBlob(row.value),
|
|
201
|
+
]);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
async deleteRawKeys(keys: Uint8Array[]): Promise<void> {
|
|
205
|
+
for (
|
|
206
|
+
let start = 0;
|
|
207
|
+
start < keys.length;
|
|
208
|
+
start += WORKFLOW_SQLITE_MAX_BATCH_ROWS
|
|
209
|
+
) {
|
|
210
|
+
await this.#db.transaction(
|
|
211
|
+
async (tx) => {
|
|
212
|
+
for (const key of keys.slice(
|
|
213
|
+
start,
|
|
214
|
+
start + WORKFLOW_SQLITE_MAX_BATCH_ROWS,
|
|
215
|
+
)) {
|
|
216
|
+
await tx.execute(
|
|
217
|
+
"DELETE FROM _rivet_wf_kv WHERE key = ?",
|
|
218
|
+
key,
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
},
|
|
222
|
+
{ name: WORKFLOW_DELETE_TRANSACTION_NAME },
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
export function chunkWorkflowWrites(writes: KVWrite[]): KVWrite[][] {
|
|
229
|
+
const chunks: KVWrite[][] = [];
|
|
230
|
+
let chunk: KVWrite[] = [];
|
|
231
|
+
let chunkBytes = 0;
|
|
232
|
+
for (const write of writes) {
|
|
233
|
+
const writeBytes =
|
|
234
|
+
WORKFLOW_STORAGE_PREFIX.length +
|
|
235
|
+
write.key.length +
|
|
236
|
+
write.value.length;
|
|
237
|
+
if (
|
|
238
|
+
chunk.length > 0 &&
|
|
239
|
+
(chunk.length >= WORKFLOW_SQLITE_MAX_BATCH_ROWS ||
|
|
240
|
+
chunkBytes + writeBytes > WORKFLOW_SQLITE_MAX_BATCH_BYTES)
|
|
241
|
+
) {
|
|
242
|
+
chunks.push(chunk);
|
|
243
|
+
chunk = [];
|
|
244
|
+
chunkBytes = 0;
|
|
245
|
+
}
|
|
246
|
+
chunk.push(write);
|
|
247
|
+
chunkBytes += writeBytes;
|
|
248
|
+
}
|
|
249
|
+
if (chunk.length > 0) chunks.push(chunk);
|
|
250
|
+
return chunks;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
function keyStartsWith(key: Uint8Array, prefix: Uint8Array): boolean {
|
|
254
|
+
if (key.length < prefix.length) return false;
|
|
255
|
+
for (let i = 0; i < prefix.length; i++) {
|
|
256
|
+
if (key[i] !== prefix[i]) return false;
|
|
257
|
+
}
|
|
258
|
+
return true;
|
|
259
|
+
}
|
|
260
|
+
|
|
33
261
|
class ActorWorkflowMessageDriver implements WorkflowMessageDriver {
|
|
34
262
|
#actor: AnyStaticActorInstance;
|
|
35
263
|
#runCtx: RunContext<any, any, any, any, any, any, any, any>;
|
|
@@ -64,7 +292,7 @@ class ActorWorkflowMessageDriver implements WorkflowMessageDriver {
|
|
|
64
292
|
opts.completable,
|
|
65
293
|
),
|
|
66
294
|
);
|
|
67
|
-
return messages.map((message) => ({
|
|
295
|
+
return messages.map((message: ReceivedQueueMessage) => ({
|
|
68
296
|
id: message.id.toString(),
|
|
69
297
|
name: message.name,
|
|
70
298
|
data: message.body,
|
|
@@ -102,10 +330,13 @@ class ActorWorkflowMessageDriver implements WorkflowMessageDriver {
|
|
|
102
330
|
}
|
|
103
331
|
|
|
104
332
|
export class ActorWorkflowDriver implements EngineDriver {
|
|
333
|
+
readonly atomicBatch = true;
|
|
105
334
|
readonly workerPollInterval = 100;
|
|
106
335
|
readonly messageDriver: WorkflowMessageDriver;
|
|
336
|
+
readonly telemetry: WorkflowTelemetryDriver;
|
|
107
337
|
#actor: AnyStaticActorInstance;
|
|
108
338
|
#runCtx: RunContext<any, any, any, any, any, any, any, any>;
|
|
339
|
+
#storage: WorkflowStorage;
|
|
109
340
|
|
|
110
341
|
constructor(
|
|
111
342
|
actor: AnyStaticActorInstance,
|
|
@@ -114,109 +345,66 @@ export class ActorWorkflowDriver implements EngineDriver {
|
|
|
114
345
|
this.#actor = actor;
|
|
115
346
|
this.#runCtx = runCtx;
|
|
116
347
|
this.messageDriver = new ActorWorkflowMessageDriver(actor, runCtx);
|
|
348
|
+
this.telemetry = {
|
|
349
|
+
startSpan: () => runCtx.run.startWorkflowSpan(),
|
|
350
|
+
};
|
|
351
|
+
this.#storage = new WorkflowStorage(runtimeDbFromContext(runCtx));
|
|
117
352
|
}
|
|
118
353
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
]),
|
|
354
|
+
/** Keeps the engine's history storage out of the workflow run's trace. */
|
|
355
|
+
#untraced<T>(run: () => Promise<T>): Promise<T> {
|
|
356
|
+
return this.#runCtx.internalKeepAwake(
|
|
357
|
+
this.#runCtx.run.runOutsideWorkflowSpan(run),
|
|
124
358
|
);
|
|
125
|
-
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
async get(key: Uint8Array): Promise<Uint8Array | null> {
|
|
362
|
+
return await this.#untraced(() => this.#storage.get(key));
|
|
126
363
|
}
|
|
127
364
|
|
|
128
365
|
async set(key: Uint8Array, value: Uint8Array): Promise<void> {
|
|
129
|
-
await this.#
|
|
130
|
-
this.#actor.driver.kvBatchPut(this.#actor.id, [
|
|
131
|
-
[makeWorkflowKey(key), value],
|
|
132
|
-
]),
|
|
133
|
-
);
|
|
366
|
+
await this.#untraced(() => this.#storage.set(key, value));
|
|
134
367
|
}
|
|
135
368
|
|
|
136
369
|
async delete(key: Uint8Array): Promise<void> {
|
|
137
|
-
await this.#
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
);
|
|
370
|
+
await this.#untraced(() => this.#storage.delete(key));
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
async batchDelete(keys: Uint8Array[]): Promise<void> {
|
|
374
|
+
await this.#untraced(() => this.#storage.batchDelete(keys));
|
|
142
375
|
}
|
|
143
376
|
|
|
144
377
|
async deletePrefix(prefix: Uint8Array): Promise<void> {
|
|
145
|
-
|
|
146
|
-
const end = computeUpperBound(start);
|
|
147
|
-
if (end) {
|
|
148
|
-
await this.#runCtx.internalKeepAwake(
|
|
149
|
-
this.#actor.driver.kvDeleteRange(this.#actor.id, start, end),
|
|
150
|
-
);
|
|
151
|
-
} else {
|
|
152
|
-
const entries = await this.#runCtx.internalKeepAwake(
|
|
153
|
-
this.#actor.driver.kvListPrefix(this.#actor.id, start),
|
|
154
|
-
);
|
|
155
|
-
if (entries.length === 0) {
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
await this.#runCtx.internalKeepAwake(
|
|
159
|
-
this.#actor.driver.kvBatchDelete(
|
|
160
|
-
this.#actor.id,
|
|
161
|
-
entries.map(([key]) => key),
|
|
162
|
-
),
|
|
163
|
-
);
|
|
164
|
-
}
|
|
378
|
+
await this.#untraced(() => this.#storage.deletePrefix(prefix));
|
|
165
379
|
}
|
|
166
380
|
|
|
167
381
|
async deleteRange(start: Uint8Array, end: Uint8Array): Promise<void> {
|
|
168
|
-
await this.#
|
|
169
|
-
this.#actor.driver.kvDeleteRange(
|
|
170
|
-
this.#actor.id,
|
|
171
|
-
makeWorkflowKey(start),
|
|
172
|
-
makeWorkflowKey(end),
|
|
173
|
-
),
|
|
174
|
-
);
|
|
382
|
+
await this.#untraced(() => this.#storage.deleteRange(start, end));
|
|
175
383
|
}
|
|
176
384
|
|
|
177
385
|
async list(prefix: Uint8Array): Promise<KVEntry[]> {
|
|
178
|
-
|
|
179
|
-
this.#actor.driver.kvListPrefix(
|
|
180
|
-
this.#actor.id,
|
|
181
|
-
makeWorkflowKey(prefix),
|
|
182
|
-
),
|
|
183
|
-
);
|
|
184
|
-
return entries.map(([key, value]) => ({
|
|
185
|
-
key: stripWorkflowKey(key),
|
|
186
|
-
value,
|
|
187
|
-
}));
|
|
386
|
+
return await this.#untraced(() => this.#storage.list(prefix));
|
|
188
387
|
}
|
|
189
388
|
|
|
190
389
|
async batch(writes: KVWrite[]): Promise<void> {
|
|
191
390
|
if (writes.length === 0) return;
|
|
192
391
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
await this.#runCtx.internalKeepAwake(
|
|
196
|
-
Promise.all([
|
|
197
|
-
this.#actor.driver.kvBatchPut(
|
|
198
|
-
this.#actor.id,
|
|
199
|
-
writes.map(({ key, value }) => [
|
|
200
|
-
makeWorkflowKey(key),
|
|
201
|
-
value,
|
|
202
|
-
]),
|
|
203
|
-
),
|
|
204
|
-
this.#actor.stateManager.saveState({
|
|
205
|
-
immediate: true,
|
|
206
|
-
}),
|
|
207
|
-
]),
|
|
392
|
+
await this.#untraced(() =>
|
|
393
|
+
this.#actor.stateManager.saveStateAndWorkflowBatch(writes),
|
|
208
394
|
);
|
|
209
395
|
}
|
|
210
396
|
|
|
397
|
+
// The run wake-at shares the actor's one engine alarm with scheduled
|
|
398
|
+
// events, so schedule changes keep the workflow deadline armed. Round up
|
|
399
|
+
// because a fractional retry backoff gives a fractional deadline.
|
|
211
400
|
async setAlarm(_workflowId: string, wakeAt: number): Promise<void> {
|
|
212
401
|
await this.#runCtx.internalKeepAwake(
|
|
213
|
-
this.#
|
|
402
|
+
this.#runCtx.run.setWakeAt(Math.ceil(wakeAt)),
|
|
214
403
|
);
|
|
215
404
|
}
|
|
216
405
|
|
|
217
406
|
async clearAlarm(_workflowId: string): Promise<void> {
|
|
218
|
-
|
|
219
|
-
return;
|
|
407
|
+
await this.#runCtx.internalKeepAwake(this.#runCtx.run.setWakeAt(null));
|
|
220
408
|
}
|
|
221
409
|
|
|
222
410
|
waitForMessages(
|
|
@@ -256,68 +444,42 @@ export class ActorWorkflowControlDriver implements EngineDriver {
|
|
|
256
444
|
readonly messageDriver: WorkflowMessageDriver =
|
|
257
445
|
new NoopWorkflowMessageDriver();
|
|
258
446
|
#actor: AnyStaticActorInstance;
|
|
447
|
+
#storage: WorkflowStorage;
|
|
259
448
|
|
|
260
|
-
constructor(
|
|
449
|
+
constructor(
|
|
450
|
+
actor: AnyStaticActorInstance,
|
|
451
|
+
runCtx?: RunContext<any, any, any, any, any, any, any, any>,
|
|
452
|
+
) {
|
|
261
453
|
this.#actor = actor;
|
|
454
|
+
this.#storage = new WorkflowStorage(runtimeDbFromContext(runCtx));
|
|
262
455
|
}
|
|
263
456
|
|
|
264
457
|
async get(key: Uint8Array): Promise<Uint8Array | null> {
|
|
265
|
-
|
|
266
|
-
makeWorkflowKey(key),
|
|
267
|
-
]);
|
|
268
|
-
return value ?? null;
|
|
458
|
+
return await this.#storage.get(key);
|
|
269
459
|
}
|
|
270
460
|
|
|
271
461
|
async set(key: Uint8Array, value: Uint8Array): Promise<void> {
|
|
272
|
-
await this.#
|
|
273
|
-
[makeWorkflowKey(key), value],
|
|
274
|
-
]);
|
|
462
|
+
await this.#storage.set(key, value);
|
|
275
463
|
}
|
|
276
464
|
|
|
277
465
|
async delete(key: Uint8Array): Promise<void> {
|
|
278
|
-
await this.#
|
|
279
|
-
makeWorkflowKey(key),
|
|
280
|
-
]);
|
|
466
|
+
await this.#storage.delete(key);
|
|
281
467
|
}
|
|
282
468
|
|
|
283
|
-
async
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
if (end) {
|
|
287
|
-
await this.#actor.driver.kvDeleteRange(this.#actor.id, start, end);
|
|
288
|
-
return;
|
|
289
|
-
}
|
|
469
|
+
async batchDelete(keys: Uint8Array[]): Promise<void> {
|
|
470
|
+
await this.#storage.batchDelete(keys);
|
|
471
|
+
}
|
|
290
472
|
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
start,
|
|
294
|
-
);
|
|
295
|
-
if (entries.length === 0) {
|
|
296
|
-
return;
|
|
297
|
-
}
|
|
298
|
-
await this.#actor.driver.kvBatchDelete(
|
|
299
|
-
this.#actor.id,
|
|
300
|
-
entries.map(([key]) => key),
|
|
301
|
-
);
|
|
473
|
+
async deletePrefix(prefix: Uint8Array): Promise<void> {
|
|
474
|
+
await this.#storage.deletePrefix(prefix);
|
|
302
475
|
}
|
|
303
476
|
|
|
304
477
|
async deleteRange(start: Uint8Array, end: Uint8Array): Promise<void> {
|
|
305
|
-
await this.#
|
|
306
|
-
this.#actor.id,
|
|
307
|
-
makeWorkflowKey(start),
|
|
308
|
-
makeWorkflowKey(end),
|
|
309
|
-
);
|
|
478
|
+
await this.#storage.deleteRange(start, end);
|
|
310
479
|
}
|
|
311
480
|
|
|
312
481
|
async list(prefix: Uint8Array): Promise<KVEntry[]> {
|
|
313
|
-
|
|
314
|
-
this.#actor.id,
|
|
315
|
-
makeWorkflowKey(prefix),
|
|
316
|
-
);
|
|
317
|
-
return entries.map(([key, value]) => ({
|
|
318
|
-
key: stripWorkflowKey(key),
|
|
319
|
-
value,
|
|
320
|
-
}));
|
|
482
|
+
return await this.#storage.list(prefix);
|
|
321
483
|
}
|
|
322
484
|
|
|
323
485
|
async batch(writes: KVWrite[]): Promise<void> {
|
|
@@ -325,10 +487,7 @@ export class ActorWorkflowControlDriver implements EngineDriver {
|
|
|
325
487
|
return;
|
|
326
488
|
}
|
|
327
489
|
|
|
328
|
-
await this.#
|
|
329
|
-
this.#actor.id,
|
|
330
|
-
writes.map(({ key, value }) => [makeWorkflowKey(key), value]),
|
|
331
|
-
);
|
|
490
|
+
await this.#storage.batch(writes);
|
|
332
491
|
}
|
|
333
492
|
|
|
334
493
|
async setAlarm(_workflowId: string, wakeAt: number): Promise<void> {
|
|
@@ -5,18 +5,21 @@ 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
|
|
14
|
-
import
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
import * as transport from "@/inspector/workflow";
|
|
14
|
+
import {
|
|
15
|
+
encodeWorkflowHistoryTransport,
|
|
16
|
+
encodeWorkflowInspectorValue,
|
|
17
|
+
type WorkflowInspectorAdapter as PublicWorkflowInspectorAdapter,
|
|
18
|
+
type WorkflowHistoryBytes,
|
|
19
|
+
} from "@/inspector/workflow";
|
|
20
|
+
import { assertUnreachable } from "@/utils";
|
|
18
21
|
|
|
19
|
-
type HistoryListener = (history:
|
|
22
|
+
type HistoryListener = (history: WorkflowHistoryBytes) => void;
|
|
20
23
|
|
|
21
24
|
function createHistoryEmitter() {
|
|
22
25
|
const listeners = new Set<HistoryListener>();
|
|
@@ -26,7 +29,7 @@ function createHistoryEmitter() {
|
|
|
26
29
|
listeners.add(listener);
|
|
27
30
|
return () => listeners.delete(listener);
|
|
28
31
|
},
|
|
29
|
-
emit: (history:
|
|
32
|
+
emit: (history: WorkflowHistoryBytes) => {
|
|
30
33
|
for (const listener of listeners) {
|
|
31
34
|
listener(history);
|
|
32
35
|
}
|
|
@@ -34,33 +37,22 @@ function createHistoryEmitter() {
|
|
|
34
37
|
};
|
|
35
38
|
}
|
|
36
39
|
|
|
37
|
-
export
|
|
38
|
-
getHistory: () => inspectorSchema.WorkflowHistory | null;
|
|
39
|
-
getState: () => Promise<WorkflowState | null>;
|
|
40
|
-
onHistoryUpdated: (
|
|
41
|
-
listener: (history: inspectorSchema.WorkflowHistory) => void,
|
|
42
|
-
) => () => void;
|
|
43
|
-
replayFromStep: (
|
|
44
|
-
entryId?: string,
|
|
45
|
-
) => Promise<inspectorSchema.WorkflowHistory | null>;
|
|
46
|
-
}
|
|
40
|
+
export type WorkflowInspectorAdapter = PublicWorkflowInspectorAdapter;
|
|
47
41
|
|
|
48
42
|
export function createWorkflowInspectorAdapter(): {
|
|
49
43
|
adapter: WorkflowInspectorAdapter;
|
|
50
44
|
update: (snapshot: WorkflowHistorySnapshot) => void;
|
|
51
45
|
setGetState: (fn: () => Promise<WorkflowState | null>) => void;
|
|
52
46
|
setReplayFromStep: (
|
|
53
|
-
fn: (
|
|
54
|
-
entryId?: string,
|
|
55
|
-
) => Promise<inspectorSchema.WorkflowHistory | null>,
|
|
47
|
+
fn: (entryId?: string) => Promise<WorkflowHistoryBytes | null>,
|
|
56
48
|
) => void;
|
|
57
49
|
} {
|
|
58
50
|
const emitter = createHistoryEmitter();
|
|
59
|
-
let history:
|
|
51
|
+
let history: WorkflowHistoryBytes | null = null;
|
|
60
52
|
let getState: () => Promise<WorkflowState | null> = async () => null;
|
|
61
53
|
let replayFromStep: (
|
|
62
54
|
entryId?: string,
|
|
63
|
-
) => Promise<
|
|
55
|
+
) => Promise<WorkflowHistoryBytes | null> = async () => {
|
|
64
56
|
throw new Error("Workflow replay controls are not initialized");
|
|
65
57
|
};
|
|
66
58
|
|
|
@@ -91,7 +83,7 @@ export function createWorkflowInspectorAdapter(): {
|
|
|
91
83
|
}
|
|
92
84
|
|
|
93
85
|
function encodeCbor(value: unknown): ArrayBuffer {
|
|
94
|
-
return
|
|
86
|
+
return encodeWorkflowInspectorValue(value);
|
|
95
87
|
}
|
|
96
88
|
|
|
97
89
|
function encodeOptionalCbor(value: unknown): ArrayBuffer | null {
|
|
@@ -183,6 +175,14 @@ function toWorkflowEntryKind(kind: EntryKind): transport.WorkflowEntryKind {
|
|
|
183
175
|
originalName: kind.data.originalName ?? null,
|
|
184
176
|
},
|
|
185
177
|
};
|
|
178
|
+
case "version_check":
|
|
179
|
+
return {
|
|
180
|
+
tag: "WorkflowVersionCheckEntry",
|
|
181
|
+
val: {
|
|
182
|
+
resolved: kind.data.resolved,
|
|
183
|
+
latest: kind.data.latest,
|
|
184
|
+
},
|
|
185
|
+
};
|
|
186
186
|
default:
|
|
187
187
|
assertUnreachable(kind as never);
|
|
188
188
|
}
|