rivetkit 0.0.0-sqlite-profiling-compat.87d61c0 → 0.0.0-sqlite-sync-3x-release.a00b07f
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 +1317 -765
- package/dist/browser/client.js +1457 -737
- package/dist/browser/client.js.map +1 -1
- package/dist/browser/inspector/client.d.ts +252 -129
- package/dist/browser/inspector/client.js +2042 -228
- 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 -1
- package/dist/tsup/actor/errors.d.ts +1 -1
- package/dist/tsup/actor/errors.js +5 -1
- package/dist/tsup/agent-os/index.cjs +3 -2367
- package/dist/tsup/agent-os/index.cjs.map +1 -1
- package/dist/tsup/agent-os/index.d.cts +1 -2277
- package/dist/tsup/agent-os/index.d.ts +1 -2277
- package/dist/tsup/agent-os/index.js +3 -2367
- package/dist/tsup/agent-os/index.js.map +1 -1
- package/dist/tsup/{chunk-E4LNLI3W.cjs → chunk-2MOLY6AM.cjs} +444 -29
- package/dist/tsup/chunk-2MOLY6AM.cjs.map +1 -0
- package/dist/tsup/{chunk-OAUFXOG7.js → chunk-3DONDAMG.js} +2 -2
- package/dist/tsup/{chunk-XIX5DOZN.js → chunk-6FEYCVZC.js} +196 -20
- package/dist/tsup/chunk-6FEYCVZC.js.map +1 -0
- package/dist/tsup/chunk-6KXVLIXL.cjs +14 -0
- package/dist/tsup/chunk-6KXVLIXL.cjs.map +1 -0
- package/dist/tsup/chunk-73RNTXHB.cjs +243 -0
- package/dist/tsup/chunk-73RNTXHB.cjs.map +1 -0
- package/dist/tsup/{chunk-HXUEHHJF.js → chunk-A2CF6PFH.js} +19 -11
- package/dist/tsup/chunk-A2CF6PFH.js.map +1 -0
- package/dist/tsup/{chunk-EFU4JW3T.js → chunk-BRH4PQS5.js} +436 -21
- package/dist/tsup/chunk-BRH4PQS5.js.map +1 -0
- package/dist/tsup/{chunk-GM45LG7L.cjs → chunk-BTSDFFDC.cjs} +18 -11
- package/dist/tsup/chunk-BTSDFFDC.cjs.map +1 -0
- package/dist/tsup/{chunk-B3GLD4IN.js → chunk-D5WUPE47.js} +50 -3
- package/dist/tsup/chunk-D5WUPE47.js.map +1 -0
- package/dist/tsup/{chunk-O3ZUMAN7.js → chunk-DJUBJQEQ.js} +3 -3
- package/dist/tsup/chunk-DJUBJQEQ.js.map +1 -0
- package/dist/tsup/{chunk-3MHDOUD7.cjs → chunk-HDVZ6YZG.cjs} +197 -21
- package/dist/tsup/chunk-HDVZ6YZG.cjs.map +1 -0
- package/dist/tsup/{chunk-JZ7TWV65.js → chunk-JTHHCZCZ.js} +24 -1
- package/dist/tsup/chunk-JTHHCZCZ.js.map +1 -0
- package/dist/tsup/{chunk-D363DMNH.cjs → chunk-JUHXV3HF.cjs} +3 -3
- package/dist/tsup/chunk-JUHXV3HF.cjs.map +1 -0
- package/dist/tsup/chunk-JUWMP5O3.js +14 -0
- package/dist/tsup/chunk-JUWMP5O3.js.map +1 -0
- package/dist/tsup/{chunk-ZA7FLHKH.cjs → chunk-KVFIONKQ.cjs} +25 -2
- package/dist/tsup/chunk-KVFIONKQ.cjs.map +1 -0
- package/dist/tsup/{chunk-4FC7TVS6.cjs → chunk-MGI2VVF6.cjs} +39 -7
- package/dist/tsup/chunk-MGI2VVF6.cjs.map +1 -0
- package/dist/tsup/{chunk-BWERJMV6.cjs → chunk-OTVJYZ2L.cjs} +1139 -470
- package/dist/tsup/chunk-OTVJYZ2L.cjs.map +1 -0
- package/dist/tsup/{chunk-VE2X4KMG.cjs → chunk-RTWH3AX3.cjs} +18 -10
- package/dist/tsup/chunk-RTWH3AX3.cjs.map +1 -0
- package/dist/tsup/{chunk-DTRDGPHU.cjs → chunk-TM76Z7XT.cjs} +7 -7
- package/dist/tsup/chunk-TM76Z7XT.cjs.map +1 -0
- package/dist/tsup/{chunk-3GVMLSND.js → chunk-TRUHDXOU.js} +1023 -354
- package/dist/tsup/chunk-TRUHDXOU.js.map +1 -0
- package/dist/tsup/{chunk-PT7AC5PC.js → chunk-TSQTI6H6.js} +16 -9
- package/dist/tsup/chunk-TSQTI6H6.js.map +1 -0
- package/dist/tsup/{chunk-FNAXD5BQ.cjs → chunk-Z7E2G3JZ.cjs} +52 -5
- package/dist/tsup/chunk-Z7E2G3JZ.cjs.map +1 -0
- package/dist/tsup/{chunk-ZZ3WBRPD.js → chunk-ZOVJDAOW.js} +38 -6
- package/dist/tsup/chunk-ZOVJDAOW.js.map +1 -0
- package/dist/tsup/chunk-ZYK4B5WV.js +243 -0
- package/dist/tsup/chunk-ZYK4B5WV.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 +32 -6
- package/dist/tsup/client/mod.d.ts +32 -6
- 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.cjs.map +1 -1
- package/dist/tsup/common/websocket.js +3 -3
- package/dist/tsup/{config-BR1Nn0QQ.d.ts → config-B4erdavw.d.ts} +571 -65
- package/dist/tsup/{config-B0LNDrLY.d.cts → config-BfG1qpYz.d.cts} +80 -14
- package/dist/tsup/{config-B0LNDrLY.d.ts → config-BfG1qpYz.d.ts} +80 -14
- package/dist/tsup/{config-tCvkwzyN.d.cts → config-DK144OAw.d.cts} +571 -65
- package/dist/tsup/{context-D4WDwf9m.d.cts → context-Cvnf3BRe.d.cts} +3 -2
- package/dist/tsup/{context-oc9zhA3x.d.ts → context-Oxi6YWcG.d.ts} +3 -2
- 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 -126
- package/dist/tsup/db/mod.cjs.map +1 -1
- package/dist/tsup/db/mod.d.cts +8 -4
- package/dist/tsup/db/mod.d.ts +8 -4
- package/dist/tsup/db/mod.js +5 -125
- package/dist/tsup/db/mod.js.map +1 -1
- package/dist/tsup/dynamic/mod.cjs +2 -2
- package/dist/tsup/dynamic/mod.cjs.map +1 -1
- package/dist/tsup/dynamic/mod.d.cts +6 -4
- package/dist/tsup/dynamic/mod.d.ts +6 -4
- package/dist/tsup/dynamic/mod.js +1 -1
- 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 +2 -13
- package/dist/tsup/inspector-tab/mod.cjs.map +1 -1
- package/dist/tsup/inspector-tab/mod.d.cts +9 -17
- package/dist/tsup/inspector-tab/mod.d.ts +9 -17
- package/dist/tsup/inspector-tab/mod.js +1 -12
- package/dist/tsup/inspector-tab/mod.js.map +1 -1
- package/dist/tsup/mod.cjs +2724 -611
- package/dist/tsup/mod.cjs.map +1 -1
- package/dist/tsup/mod.d.cts +9 -7
- package/dist/tsup/mod.d.ts +9 -7
- package/dist/tsup/mod.js +2641 -528
- package/dist/tsup/mod.js.map +1 -1
- package/dist/tsup/test/mod.cjs +19 -17
- package/dist/tsup/test/mod.cjs.map +1 -1
- package/dist/tsup/test/mod.d.cts +6 -4
- package/dist/tsup/test/mod.d.ts +6 -4
- package/dist/tsup/test/mod.js +18 -16
- 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-CqDnC_PS.d.cts → utils-3rsE0JvI.d.cts} +25 -2
- package/dist/tsup/{utils-CqDnC_PS.d.ts → utils-3rsE0JvI.d.ts} +25 -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 +260 -200
- package/dist/tsup/workflow/mod.cjs.map +1 -1
- package/dist/tsup/workflow/mod.d.cts +8 -6
- package/dist/tsup/workflow/mod.d.ts +8 -6
- package/dist/tsup/workflow/mod.js +249 -189
- package/dist/tsup/workflow/mod.js.map +1 -1
- package/package.json +34 -14
- package/src/actor/actions.ts +155 -0
- package/src/actor/config.ts +403 -43
- package/src/actor/definition.ts +26 -7
- package/src/actor/errors.ts +87 -5
- package/src/actor/keys.ts +86 -0
- package/src/actor/mod.ts +15 -1
- package/src/actor/tracing.ts +28 -0
- package/src/agent-os/index.ts +5 -65
- package/src/client/actor-common.ts +8 -15
- package/src/client/actor-conn.ts +135 -8
- package/src/client/actor-handle.ts +180 -42
- package/src/client/actor-query.ts +8 -1
- package/src/client/auth.ts +37 -0
- package/src/client/client.ts +89 -21
- package/src/client/config.ts +27 -2
- package/src/client/errors.ts +2 -1
- package/src/client/lifecycle-errors.ts +16 -1
- package/src/client/mod.ts +9 -0
- package/src/client/outbound-telemetry.ts +66 -0
- package/src/client/query.ts +2 -0
- package/src/client/queue.ts +3 -0
- package/src/client/raw-utils.ts +37 -8
- package/src/client/resolve-gateway-target.ts +2 -0
- package/src/client/retry-budget.ts +78 -0
- package/src/client/token-provider.ts +93 -0
- package/src/client/utils.ts +16 -2
- package/src/common/actor-router-consts.ts +5 -0
- package/src/common/actor-telemetry-context.ts +19 -0
- package/src/common/bare/generated/actor-runtime-socket-protocol/v1.ts +848 -0
- 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 +36 -0
- package/src/common/database/config.ts +108 -15
- package/src/common/database/mod.ts +247 -76
- package/src/common/database/native-database.ts +433 -23
- package/src/common/database/shared.ts +24 -0
- package/src/common/encoding.ts +31 -21
- package/src/common/fetch-like.ts +63 -0
- package/src/common/inspector-transport.ts +12 -2
- package/src/common/log.ts +14 -8
- package/src/common/otel-context.ts +99 -0
- package/src/common/router.ts +1 -1
- package/src/common/utils.ts +7 -19
- package/src/db/drizzle.ts +182 -80
- package/src/db/mod.ts +2 -0
- package/src/dynamic/isolate-runtime.ts +0 -2
- package/src/engine-api/actors.ts +3 -3
- package/src/engine-client/actor-http-client.ts +29 -20
- package/src/engine-client/actor-websocket-client.ts +6 -3
- package/src/engine-client/api-endpoints.ts +72 -14
- package/src/engine-client/driver.ts +8 -15
- package/src/engine-client/mod.ts +248 -112
- package/src/inspector/client.browser.ts +134 -16
- package/src/inspector/mod.ts +1 -1
- package/src/inspector/workflow.ts +61 -0
- package/src/inspector-tab/mod.ts +1 -15
- package/src/registry/config/envoy.ts +2 -18
- package/src/registry/config/index.ts +53 -61
- package/src/registry/index.ts +311 -21
- package/src/registry/napi-runtime.ts +583 -39
- package/src/registry/native-http.ts +225 -0
- package/src/registry/native.ts +1365 -414
- package/src/registry/run-handler-coordinator.ts +219 -0
- package/src/registry/runtime.ts +372 -7
- package/src/registry/wasm-runtime.ts +490 -21
- package/src/registry/write-through-proxy.ts +101 -0
- package/src/test/mod.ts +1 -19
- package/src/test/ready.ts +22 -0
- package/src/unstable/migrations.ts +141 -0
- package/src/utils/env-vars.ts +15 -6
- package/src/utils/node.ts +44 -28
- package/src/utils.ts +3 -0
- package/src/workflow/context.ts +9 -27
- package/src/workflow/driver.ts +253 -116
- package/src/workflow/inspector.ts +23 -24
- package/src/workflow/mod.ts +50 -72
- package/dist/tsup/chunk-3GVMLSND.js.map +0 -1
- package/dist/tsup/chunk-3MHDOUD7.cjs.map +0 -1
- package/dist/tsup/chunk-4FC7TVS6.cjs.map +0 -1
- package/dist/tsup/chunk-B3GLD4IN.js.map +0 -1
- package/dist/tsup/chunk-BWERJMV6.cjs.map +0 -1
- package/dist/tsup/chunk-D363DMNH.cjs.map +0 -1
- package/dist/tsup/chunk-DTRDGPHU.cjs.map +0 -1
- package/dist/tsup/chunk-E4LNLI3W.cjs.map +0 -1
- package/dist/tsup/chunk-EFU4JW3T.js.map +0 -1
- package/dist/tsup/chunk-FNAXD5BQ.cjs.map +0 -1
- package/dist/tsup/chunk-GM45LG7L.cjs.map +0 -1
- package/dist/tsup/chunk-HXUEHHJF.js.map +0 -1
- package/dist/tsup/chunk-JZ7TWV65.js.map +0 -1
- package/dist/tsup/chunk-O3ZUMAN7.js.map +0 -1
- package/dist/tsup/chunk-P6F5MEWX.cjs +0 -382
- package/dist/tsup/chunk-P6F5MEWX.cjs.map +0 -1
- package/dist/tsup/chunk-PT7AC5PC.js.map +0 -1
- package/dist/tsup/chunk-UV7INX3N.js +0 -382
- package/dist/tsup/chunk-UV7INX3N.js.map +0 -1
- package/dist/tsup/chunk-VE2X4KMG.cjs.map +0 -1
- package/dist/tsup/chunk-XIX5DOZN.js.map +0 -1
- package/dist/tsup/chunk-ZA7FLHKH.cjs.map +0 -1
- package/dist/tsup/chunk-ZZ3WBRPD.js.map +0 -1
- package/src/actor/driver.ts +0 -141
- package/src/actor/instance/mod.ts +0 -2484
- 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 -285
- package/src/agent-os/actor/network.ts +0 -58
- package/src/agent-os/actor/preview.ts +0 -190
- 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 -2473
- package/src/registry/process-metrics.ts +0 -250
- package/src/registry/runtime.test.ts +0 -50
- package/src/utils/endpoint-parser.test.ts +0 -206
- package/src/utils.test.ts +0 -34
- /package/dist/tsup/{chunk-OAUFXOG7.js.map → chunk-3DONDAMG.js.map} +0 -0
package/src/workflow/driver.ts
CHANGED
|
@@ -4,12 +4,19 @@ import type {
|
|
|
4
4
|
KVWrite,
|
|
5
5
|
Message,
|
|
6
6
|
WorkflowMessageDriver,
|
|
7
|
+
WorkflowTelemetryDriver,
|
|
7
8
|
} from "@rivetkit/workflow-engine";
|
|
8
9
|
import type { RunContext } from "@/actor/config";
|
|
9
10
|
import type { AnyStaticActorInstance } from "@/actor/definition";
|
|
10
11
|
import { makeWorkflowKey, workflowStoragePrefix } from "@/actor/keys";
|
|
12
|
+
import type { RawAccess } from "@/common/database/config";
|
|
11
13
|
|
|
12
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;
|
|
13
20
|
|
|
14
21
|
// Mirrors the element shape returned by `queueManager.receive`. The actor
|
|
15
22
|
// instance is reached through a loose type here, so the call's result is
|
|
@@ -22,8 +29,6 @@ interface ReceivedQueueMessage {
|
|
|
22
29
|
complete?: (response?: unknown) => Promise<void>;
|
|
23
30
|
}
|
|
24
31
|
|
|
25
|
-
// `kvListPrefix` returns key/value tuples, but the loose actor type erases that
|
|
26
|
-
// so the tuple destructures need an explicit annotation.
|
|
27
32
|
type KVEntryTuple = [Uint8Array, Uint8Array];
|
|
28
33
|
|
|
29
34
|
function stripWorkflowKey(prefixed: Uint8Array): Uint8Array {
|
|
@@ -41,6 +46,209 @@ function computeUpperBound(prefix: Uint8Array): Uint8Array | null {
|
|
|
41
46
|
return null;
|
|
42
47
|
}
|
|
43
48
|
|
|
49
|
+
function normalizeSqlBlob(value: unknown): Uint8Array {
|
|
50
|
+
if (value instanceof Uint8Array) {
|
|
51
|
+
return value;
|
|
52
|
+
}
|
|
53
|
+
if (value instanceof ArrayBuffer) {
|
|
54
|
+
return new Uint8Array(value);
|
|
55
|
+
}
|
|
56
|
+
if (ArrayBuffer.isView(value)) {
|
|
57
|
+
return new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
|
|
58
|
+
}
|
|
59
|
+
if (Array.isArray(value)) {
|
|
60
|
+
const bytes = new Uint8Array(value.length);
|
|
61
|
+
for (const [i, item] of value.entries()) {
|
|
62
|
+
if (!Number.isInteger(item) || item < 0 || item > 255) {
|
|
63
|
+
throw new Error("workflow sqlite value was not a byte array");
|
|
64
|
+
}
|
|
65
|
+
bytes[i] = item;
|
|
66
|
+
}
|
|
67
|
+
return bytes;
|
|
68
|
+
}
|
|
69
|
+
throw new Error("workflow sqlite value was not a blob");
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function runtimeDbFromContext(
|
|
73
|
+
runCtx?: RunContext<any, any, any, any, any, any, any, any>,
|
|
74
|
+
): RawAccess | undefined {
|
|
75
|
+
const db = (runCtx as unknown as { db?: unknown } | undefined)?.db;
|
|
76
|
+
if (
|
|
77
|
+
db &&
|
|
78
|
+
typeof db === "object" &&
|
|
79
|
+
"execute" in db &&
|
|
80
|
+
"transaction" in db
|
|
81
|
+
) {
|
|
82
|
+
return db as RawAccess;
|
|
83
|
+
}
|
|
84
|
+
return undefined;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
class WorkflowStorage {
|
|
88
|
+
#db: RawAccess;
|
|
89
|
+
|
|
90
|
+
constructor(db?: RawAccess) {
|
|
91
|
+
if (!db) {
|
|
92
|
+
throw new Error(
|
|
93
|
+
"workflow storage requires embedded SQLite; actor KV workflow storage is no longer supported",
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
this.#db = db;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async get(key: Uint8Array): Promise<Uint8Array | null> {
|
|
100
|
+
const prefixed = makeWorkflowKey(key);
|
|
101
|
+
const rows = await this.#db.execute<{ value: unknown }>(
|
|
102
|
+
"SELECT value FROM _rivet_wf_kv WHERE key = ?",
|
|
103
|
+
prefixed,
|
|
104
|
+
);
|
|
105
|
+
return rows[0]?.value == null ? null : normalizeSqlBlob(rows[0].value);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async set(key: Uint8Array, value: Uint8Array): Promise<void> {
|
|
109
|
+
await this.batch([{ key, value }]);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
async delete(key: Uint8Array): Promise<void> {
|
|
113
|
+
const prefixed = makeWorkflowKey(key);
|
|
114
|
+
await this.#db.execute(
|
|
115
|
+
"DELETE FROM _rivet_wf_kv WHERE key = ?",
|
|
116
|
+
prefixed,
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
async batchDelete(keys: Uint8Array[]): Promise<void> {
|
|
121
|
+
if (keys.length === 0) return;
|
|
122
|
+
await this.deleteRawKeys(keys.map((key) => makeWorkflowKey(key)));
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
async deletePrefix(prefix: Uint8Array): Promise<void> {
|
|
126
|
+
const start = makeWorkflowKey(prefix);
|
|
127
|
+
const end = computeUpperBound(start);
|
|
128
|
+
if (end) {
|
|
129
|
+
await this.#db.execute(
|
|
130
|
+
"DELETE FROM _rivet_wf_kv WHERE key >= ? AND key < ?",
|
|
131
|
+
start,
|
|
132
|
+
end,
|
|
133
|
+
);
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
const entries = await this.listRaw(start);
|
|
137
|
+
await this.deleteRawKeys(
|
|
138
|
+
entries
|
|
139
|
+
.filter(([key]) => keyStartsWith(key, start))
|
|
140
|
+
.map(([key]) => key),
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
async deleteRange(start: Uint8Array, end: Uint8Array): Promise<void> {
|
|
145
|
+
const prefixedStart = makeWorkflowKey(start);
|
|
146
|
+
const prefixedEnd = makeWorkflowKey(end);
|
|
147
|
+
await this.#db.execute(
|
|
148
|
+
"DELETE FROM _rivet_wf_kv WHERE key >= ? AND key < ?",
|
|
149
|
+
prefixedStart,
|
|
150
|
+
prefixedEnd,
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
async list(prefix: Uint8Array): Promise<KVEntry[]> {
|
|
155
|
+
const prefixed = makeWorkflowKey(prefix);
|
|
156
|
+
const entries = await this.listRaw(prefixed);
|
|
157
|
+
return entries
|
|
158
|
+
.filter(([key]) => keyStartsWith(key, prefixed))
|
|
159
|
+
.map(([key, value]: KVEntryTuple) => ({
|
|
160
|
+
key: stripWorkflowKey(key),
|
|
161
|
+
value,
|
|
162
|
+
}));
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
async batch(writes: KVWrite[]): Promise<void> {
|
|
166
|
+
if (writes.length === 0) return;
|
|
167
|
+
for (const chunk of chunkWorkflowWrites(writes)) {
|
|
168
|
+
await this.#db.transaction(async (tx) => {
|
|
169
|
+
for (const { key, value } of chunk) {
|
|
170
|
+
await tx.execute(
|
|
171
|
+
"INSERT INTO _rivet_wf_kv (key, value) VALUES (?, ?) ON CONFLICT(key) DO UPDATE SET value = excluded.value",
|
|
172
|
+
makeWorkflowKey(key),
|
|
173
|
+
value,
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
async listRaw(prefix: Uint8Array): Promise<KVEntryTuple[]> {
|
|
181
|
+
const end = computeUpperBound(prefix);
|
|
182
|
+
const rows = end
|
|
183
|
+
? await this.#db.execute<{ key: unknown; value: unknown }>(
|
|
184
|
+
"SELECT key, value FROM _rivet_wf_kv WHERE key >= ? AND key < ? ORDER BY key ASC",
|
|
185
|
+
prefix,
|
|
186
|
+
end,
|
|
187
|
+
)
|
|
188
|
+
: await this.#db.execute<{ key: unknown; value: unknown }>(
|
|
189
|
+
"SELECT key, value FROM _rivet_wf_kv WHERE key >= ? ORDER BY key ASC",
|
|
190
|
+
prefix,
|
|
191
|
+
);
|
|
192
|
+
return rows.map((row) => [
|
|
193
|
+
normalizeSqlBlob(row.key),
|
|
194
|
+
normalizeSqlBlob(row.value),
|
|
195
|
+
]);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
async deleteRawKeys(keys: Uint8Array[]): Promise<void> {
|
|
199
|
+
for (
|
|
200
|
+
let start = 0;
|
|
201
|
+
start < keys.length;
|
|
202
|
+
start += WORKFLOW_SQLITE_MAX_BATCH_ROWS
|
|
203
|
+
) {
|
|
204
|
+
await this.#db.transaction(async (tx) => {
|
|
205
|
+
for (const key of keys.slice(
|
|
206
|
+
start,
|
|
207
|
+
start + WORKFLOW_SQLITE_MAX_BATCH_ROWS,
|
|
208
|
+
)) {
|
|
209
|
+
await tx.execute(
|
|
210
|
+
"DELETE FROM _rivet_wf_kv WHERE key = ?",
|
|
211
|
+
key,
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export function chunkWorkflowWrites(writes: KVWrite[]): KVWrite[][] {
|
|
220
|
+
const chunks: KVWrite[][] = [];
|
|
221
|
+
let chunk: KVWrite[] = [];
|
|
222
|
+
let chunkBytes = 0;
|
|
223
|
+
for (const write of writes) {
|
|
224
|
+
const writeBytes =
|
|
225
|
+
WORKFLOW_STORAGE_PREFIX.length +
|
|
226
|
+
write.key.length +
|
|
227
|
+
write.value.length;
|
|
228
|
+
if (
|
|
229
|
+
chunk.length > 0 &&
|
|
230
|
+
(chunk.length >= WORKFLOW_SQLITE_MAX_BATCH_ROWS ||
|
|
231
|
+
chunkBytes + writeBytes > WORKFLOW_SQLITE_MAX_BATCH_BYTES)
|
|
232
|
+
) {
|
|
233
|
+
chunks.push(chunk);
|
|
234
|
+
chunk = [];
|
|
235
|
+
chunkBytes = 0;
|
|
236
|
+
}
|
|
237
|
+
chunk.push(write);
|
|
238
|
+
chunkBytes += writeBytes;
|
|
239
|
+
}
|
|
240
|
+
if (chunk.length > 0) chunks.push(chunk);
|
|
241
|
+
return chunks;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
function keyStartsWith(key: Uint8Array, prefix: Uint8Array): boolean {
|
|
245
|
+
if (key.length < prefix.length) return false;
|
|
246
|
+
for (let i = 0; i < prefix.length; i++) {
|
|
247
|
+
if (key[i] !== prefix[i]) return false;
|
|
248
|
+
}
|
|
249
|
+
return true;
|
|
250
|
+
}
|
|
251
|
+
|
|
44
252
|
class ActorWorkflowMessageDriver implements WorkflowMessageDriver {
|
|
45
253
|
#actor: AnyStaticActorInstance;
|
|
46
254
|
#runCtx: RunContext<any, any, any, any, any, any, any, any>;
|
|
@@ -113,10 +321,13 @@ class ActorWorkflowMessageDriver implements WorkflowMessageDriver {
|
|
|
113
321
|
}
|
|
114
322
|
|
|
115
323
|
export class ActorWorkflowDriver implements EngineDriver {
|
|
324
|
+
readonly atomicBatch = true;
|
|
116
325
|
readonly workerPollInterval = 100;
|
|
117
326
|
readonly messageDriver: WorkflowMessageDriver;
|
|
327
|
+
readonly telemetry: WorkflowTelemetryDriver;
|
|
118
328
|
#actor: AnyStaticActorInstance;
|
|
119
329
|
#runCtx: RunContext<any, any, any, any, any, any, any, any>;
|
|
330
|
+
#storage: WorkflowStorage;
|
|
120
331
|
|
|
121
332
|
constructor(
|
|
122
333
|
actor: AnyStaticActorInstance,
|
|
@@ -125,97 +336,52 @@ export class ActorWorkflowDriver implements EngineDriver {
|
|
|
125
336
|
this.#actor = actor;
|
|
126
337
|
this.#runCtx = runCtx;
|
|
127
338
|
this.messageDriver = new ActorWorkflowMessageDriver(actor, runCtx);
|
|
339
|
+
this.telemetry = {
|
|
340
|
+
startSpan: () => runCtx.run.startWorkflowSpan(),
|
|
341
|
+
};
|
|
342
|
+
this.#storage = new WorkflowStorage(runtimeDbFromContext(runCtx));
|
|
128
343
|
}
|
|
129
344
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
]),
|
|
345
|
+
/** Keeps the engine's history storage out of the workflow run's trace. */
|
|
346
|
+
#untraced<T>(run: () => Promise<T>): Promise<T> {
|
|
347
|
+
return this.#runCtx.internalKeepAwake(
|
|
348
|
+
this.#runCtx.run.runOutsideWorkflowSpan(run),
|
|
135
349
|
);
|
|
136
|
-
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
async get(key: Uint8Array): Promise<Uint8Array | null> {
|
|
353
|
+
return await this.#untraced(() => this.#storage.get(key));
|
|
137
354
|
}
|
|
138
355
|
|
|
139
356
|
async set(key: Uint8Array, value: Uint8Array): Promise<void> {
|
|
140
|
-
await this.#
|
|
141
|
-
this.#actor.driver.kvBatchPut(this.#actor.id, [
|
|
142
|
-
[makeWorkflowKey(key), value],
|
|
143
|
-
]),
|
|
144
|
-
);
|
|
357
|
+
await this.#untraced(() => this.#storage.set(key, value));
|
|
145
358
|
}
|
|
146
359
|
|
|
147
360
|
async delete(key: Uint8Array): Promise<void> {
|
|
148
|
-
await this.#
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
);
|
|
361
|
+
await this.#untraced(() => this.#storage.delete(key));
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
async batchDelete(keys: Uint8Array[]): Promise<void> {
|
|
365
|
+
await this.#untraced(() => this.#storage.batchDelete(keys));
|
|
153
366
|
}
|
|
154
367
|
|
|
155
368
|
async deletePrefix(prefix: Uint8Array): Promise<void> {
|
|
156
|
-
|
|
157
|
-
const end = computeUpperBound(start);
|
|
158
|
-
if (end) {
|
|
159
|
-
await this.#runCtx.internalKeepAwake(
|
|
160
|
-
this.#actor.driver.kvDeleteRange(this.#actor.id, start, end),
|
|
161
|
-
);
|
|
162
|
-
} else {
|
|
163
|
-
const entries = await this.#runCtx.internalKeepAwake(
|
|
164
|
-
this.#actor.driver.kvListPrefix(this.#actor.id, start),
|
|
165
|
-
);
|
|
166
|
-
if (entries.length === 0) {
|
|
167
|
-
return;
|
|
168
|
-
}
|
|
169
|
-
await this.#runCtx.internalKeepAwake(
|
|
170
|
-
this.#actor.driver.kvBatchDelete(
|
|
171
|
-
this.#actor.id,
|
|
172
|
-
entries.map(([key]: KVEntryTuple) => key),
|
|
173
|
-
),
|
|
174
|
-
);
|
|
175
|
-
}
|
|
369
|
+
await this.#untraced(() => this.#storage.deletePrefix(prefix));
|
|
176
370
|
}
|
|
177
371
|
|
|
178
372
|
async deleteRange(start: Uint8Array, end: Uint8Array): Promise<void> {
|
|
179
|
-
await this.#
|
|
180
|
-
this.#actor.driver.kvDeleteRange(
|
|
181
|
-
this.#actor.id,
|
|
182
|
-
makeWorkflowKey(start),
|
|
183
|
-
makeWorkflowKey(end),
|
|
184
|
-
),
|
|
185
|
-
);
|
|
373
|
+
await this.#untraced(() => this.#storage.deleteRange(start, end));
|
|
186
374
|
}
|
|
187
375
|
|
|
188
376
|
async list(prefix: Uint8Array): Promise<KVEntry[]> {
|
|
189
|
-
|
|
190
|
-
this.#actor.driver.kvListPrefix(
|
|
191
|
-
this.#actor.id,
|
|
192
|
-
makeWorkflowKey(prefix),
|
|
193
|
-
),
|
|
194
|
-
);
|
|
195
|
-
return entries.map(([key, value]: KVEntryTuple) => ({
|
|
196
|
-
key: stripWorkflowKey(key),
|
|
197
|
-
value,
|
|
198
|
-
}));
|
|
377
|
+
return await this.#untraced(() => this.#storage.list(prefix));
|
|
199
378
|
}
|
|
200
379
|
|
|
201
380
|
async batch(writes: KVWrite[]): Promise<void> {
|
|
202
381
|
if (writes.length === 0) return;
|
|
203
382
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
await this.#runCtx.internalKeepAwake(
|
|
207
|
-
Promise.all([
|
|
208
|
-
this.#actor.driver.kvBatchPut(
|
|
209
|
-
this.#actor.id,
|
|
210
|
-
writes.map(({ key, value }) => [
|
|
211
|
-
makeWorkflowKey(key),
|
|
212
|
-
value,
|
|
213
|
-
]),
|
|
214
|
-
),
|
|
215
|
-
this.#actor.stateManager.saveState({
|
|
216
|
-
immediate: true,
|
|
217
|
-
}),
|
|
218
|
-
]),
|
|
383
|
+
await this.#untraced(() =>
|
|
384
|
+
this.#actor.stateManager.saveStateAndWorkflowBatch(writes),
|
|
219
385
|
);
|
|
220
386
|
}
|
|
221
387
|
|
|
@@ -267,68 +433,42 @@ export class ActorWorkflowControlDriver implements EngineDriver {
|
|
|
267
433
|
readonly messageDriver: WorkflowMessageDriver =
|
|
268
434
|
new NoopWorkflowMessageDriver();
|
|
269
435
|
#actor: AnyStaticActorInstance;
|
|
436
|
+
#storage: WorkflowStorage;
|
|
270
437
|
|
|
271
|
-
constructor(
|
|
438
|
+
constructor(
|
|
439
|
+
actor: AnyStaticActorInstance,
|
|
440
|
+
runCtx?: RunContext<any, any, any, any, any, any, any, any>,
|
|
441
|
+
) {
|
|
272
442
|
this.#actor = actor;
|
|
443
|
+
this.#storage = new WorkflowStorage(runtimeDbFromContext(runCtx));
|
|
273
444
|
}
|
|
274
445
|
|
|
275
446
|
async get(key: Uint8Array): Promise<Uint8Array | null> {
|
|
276
|
-
|
|
277
|
-
makeWorkflowKey(key),
|
|
278
|
-
]);
|
|
279
|
-
return value ?? null;
|
|
447
|
+
return await this.#storage.get(key);
|
|
280
448
|
}
|
|
281
449
|
|
|
282
450
|
async set(key: Uint8Array, value: Uint8Array): Promise<void> {
|
|
283
|
-
await this.#
|
|
284
|
-
[makeWorkflowKey(key), value],
|
|
285
|
-
]);
|
|
451
|
+
await this.#storage.set(key, value);
|
|
286
452
|
}
|
|
287
453
|
|
|
288
454
|
async delete(key: Uint8Array): Promise<void> {
|
|
289
|
-
await this.#
|
|
290
|
-
makeWorkflowKey(key),
|
|
291
|
-
]);
|
|
455
|
+
await this.#storage.delete(key);
|
|
292
456
|
}
|
|
293
457
|
|
|
294
|
-
async
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
if (end) {
|
|
298
|
-
await this.#actor.driver.kvDeleteRange(this.#actor.id, start, end);
|
|
299
|
-
return;
|
|
300
|
-
}
|
|
458
|
+
async batchDelete(keys: Uint8Array[]): Promise<void> {
|
|
459
|
+
await this.#storage.batchDelete(keys);
|
|
460
|
+
}
|
|
301
461
|
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
start,
|
|
305
|
-
);
|
|
306
|
-
if (entries.length === 0) {
|
|
307
|
-
return;
|
|
308
|
-
}
|
|
309
|
-
await this.#actor.driver.kvBatchDelete(
|
|
310
|
-
this.#actor.id,
|
|
311
|
-
entries.map(([key]: KVEntryTuple) => key),
|
|
312
|
-
);
|
|
462
|
+
async deletePrefix(prefix: Uint8Array): Promise<void> {
|
|
463
|
+
await this.#storage.deletePrefix(prefix);
|
|
313
464
|
}
|
|
314
465
|
|
|
315
466
|
async deleteRange(start: Uint8Array, end: Uint8Array): Promise<void> {
|
|
316
|
-
await this.#
|
|
317
|
-
this.#actor.id,
|
|
318
|
-
makeWorkflowKey(start),
|
|
319
|
-
makeWorkflowKey(end),
|
|
320
|
-
);
|
|
467
|
+
await this.#storage.deleteRange(start, end);
|
|
321
468
|
}
|
|
322
469
|
|
|
323
470
|
async list(prefix: Uint8Array): Promise<KVEntry[]> {
|
|
324
|
-
|
|
325
|
-
this.#actor.id,
|
|
326
|
-
makeWorkflowKey(prefix),
|
|
327
|
-
);
|
|
328
|
-
return entries.map(([key, value]: KVEntryTuple) => ({
|
|
329
|
-
key: stripWorkflowKey(key),
|
|
330
|
-
value,
|
|
331
|
-
}));
|
|
471
|
+
return await this.#storage.list(prefix);
|
|
332
472
|
}
|
|
333
473
|
|
|
334
474
|
async batch(writes: KVWrite[]): Promise<void> {
|
|
@@ -336,10 +476,7 @@ export class ActorWorkflowControlDriver implements EngineDriver {
|
|
|
336
476
|
return;
|
|
337
477
|
}
|
|
338
478
|
|
|
339
|
-
await this.#
|
|
340
|
-
this.#actor.id,
|
|
341
|
-
writes.map(({ key, value }) => [makeWorkflowKey(key), value]),
|
|
342
|
-
);
|
|
479
|
+
await this.#storage.batch(writes);
|
|
343
480
|
}
|
|
344
481
|
|
|
345
482
|
async setAlarm(_workflowId: string, wakeAt: number): Promise<void> {
|
|
@@ -10,14 +10,16 @@ import type {
|
|
|
10
10
|
WorkflowHistorySnapshot,
|
|
11
11
|
WorkflowState,
|
|
12
12
|
} from "@rivetkit/workflow-engine";
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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";
|
|
19
21
|
|
|
20
|
-
type HistoryListener = (history:
|
|
22
|
+
type HistoryListener = (history: WorkflowHistoryBytes) => void;
|
|
21
23
|
|
|
22
24
|
function createHistoryEmitter() {
|
|
23
25
|
const listeners = new Set<HistoryListener>();
|
|
@@ -27,7 +29,7 @@ function createHistoryEmitter() {
|
|
|
27
29
|
listeners.add(listener);
|
|
28
30
|
return () => listeners.delete(listener);
|
|
29
31
|
},
|
|
30
|
-
emit: (history:
|
|
32
|
+
emit: (history: WorkflowHistoryBytes) => {
|
|
31
33
|
for (const listener of listeners) {
|
|
32
34
|
listener(history);
|
|
33
35
|
}
|
|
@@ -35,33 +37,22 @@ function createHistoryEmitter() {
|
|
|
35
37
|
};
|
|
36
38
|
}
|
|
37
39
|
|
|
38
|
-
export
|
|
39
|
-
getHistory: () => inspectorSchema.WorkflowHistory | null;
|
|
40
|
-
getState: () => Promise<WorkflowState | null>;
|
|
41
|
-
onHistoryUpdated: (
|
|
42
|
-
listener: (history: inspectorSchema.WorkflowHistory) => void,
|
|
43
|
-
) => () => void;
|
|
44
|
-
replayFromStep: (
|
|
45
|
-
entryId?: string,
|
|
46
|
-
) => Promise<inspectorSchema.WorkflowHistory | null>;
|
|
47
|
-
}
|
|
40
|
+
export type WorkflowInspectorAdapter = PublicWorkflowInspectorAdapter;
|
|
48
41
|
|
|
49
42
|
export function createWorkflowInspectorAdapter(): {
|
|
50
43
|
adapter: WorkflowInspectorAdapter;
|
|
51
44
|
update: (snapshot: WorkflowHistorySnapshot) => void;
|
|
52
45
|
setGetState: (fn: () => Promise<WorkflowState | null>) => void;
|
|
53
46
|
setReplayFromStep: (
|
|
54
|
-
fn: (
|
|
55
|
-
entryId?: string,
|
|
56
|
-
) => Promise<inspectorSchema.WorkflowHistory | null>,
|
|
47
|
+
fn: (entryId?: string) => Promise<WorkflowHistoryBytes | null>,
|
|
57
48
|
) => void;
|
|
58
49
|
} {
|
|
59
50
|
const emitter = createHistoryEmitter();
|
|
60
|
-
let history:
|
|
51
|
+
let history: WorkflowHistoryBytes | null = null;
|
|
61
52
|
let getState: () => Promise<WorkflowState | null> = async () => null;
|
|
62
53
|
let replayFromStep: (
|
|
63
54
|
entryId?: string,
|
|
64
|
-
) => Promise<
|
|
55
|
+
) => Promise<WorkflowHistoryBytes | null> = async () => {
|
|
65
56
|
throw new Error("Workflow replay controls are not initialized");
|
|
66
57
|
};
|
|
67
58
|
|
|
@@ -92,7 +83,7 @@ export function createWorkflowInspectorAdapter(): {
|
|
|
92
83
|
}
|
|
93
84
|
|
|
94
85
|
function encodeCbor(value: unknown): ArrayBuffer {
|
|
95
|
-
return
|
|
86
|
+
return encodeWorkflowInspectorValue(value);
|
|
96
87
|
}
|
|
97
88
|
|
|
98
89
|
function encodeOptionalCbor(value: unknown): ArrayBuffer | null {
|
|
@@ -184,6 +175,14 @@ function toWorkflowEntryKind(kind: EntryKind): transport.WorkflowEntryKind {
|
|
|
184
175
|
originalName: kind.data.originalName ?? null,
|
|
185
176
|
},
|
|
186
177
|
};
|
|
178
|
+
case "version_check":
|
|
179
|
+
return {
|
|
180
|
+
tag: "WorkflowVersionCheckEntry",
|
|
181
|
+
val: {
|
|
182
|
+
resolved: kind.data.resolved,
|
|
183
|
+
latest: kind.data.latest,
|
|
184
|
+
},
|
|
185
|
+
};
|
|
187
186
|
default:
|
|
188
187
|
assertUnreachable(kind as never);
|
|
189
188
|
}
|