rivetkit 2.3.11-rc.9 → 2.3.11
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 +96 -14
- package/dist/browser/client.js +12 -2
- package/dist/browser/client.js.map +1 -1
- package/dist/browser/inspector/client.d.ts +139 -139
- package/dist/browser/inspector/client.js +12 -2
- package/dist/browser/inspector/client.js.map +1 -1
- package/dist/tsup/agent-os/index.cjs +146 -76
- package/dist/tsup/agent-os/index.cjs.map +1 -1
- package/dist/tsup/agent-os/index.d.cts +83 -9
- package/dist/tsup/agent-os/index.d.ts +83 -9
- package/dist/tsup/agent-os/index.js +146 -76
- package/dist/tsup/agent-os/index.js.map +1 -1
- package/dist/tsup/{chunk-HOZ3ZLZ2.js → chunk-3ZR542SK.js} +6 -6
- package/dist/tsup/chunk-3ZR542SK.js.map +1 -0
- package/dist/tsup/{chunk-HNHLBM3Y.cjs → chunk-4KGXFC6M.cjs} +42 -5
- package/dist/tsup/chunk-4KGXFC6M.cjs.map +1 -0
- package/dist/tsup/chunk-5UYWLCRO.js +14 -0
- package/dist/tsup/chunk-5UYWLCRO.js.map +1 -0
- package/dist/tsup/{chunk-QWLJCP3X.js → chunk-6W5VGLFT.js} +42 -5
- package/dist/tsup/chunk-6W5VGLFT.js.map +1 -0
- package/dist/tsup/chunk-6WYATRS4.js +243 -0
- package/dist/tsup/chunk-6WYATRS4.js.map +1 -0
- package/dist/tsup/chunk-B3W74FBB.cjs +14 -0
- package/dist/tsup/chunk-B3W74FBB.cjs.map +1 -0
- package/dist/tsup/{chunk-XOOESJY7.js → chunk-FWROC5LA.js} +2 -2
- package/dist/tsup/{chunk-V5CVATRU.cjs → chunk-GLIPKKEC.cjs} +7 -7
- package/dist/tsup/{chunk-V5CVATRU.cjs.map → chunk-GLIPKKEC.cjs.map} +1 -1
- package/dist/tsup/{chunk-T5XVTVQY.cjs → chunk-GN2EUMEW.cjs} +3 -3
- package/dist/tsup/{chunk-T5XVTVQY.cjs.map → chunk-GN2EUMEW.cjs.map} +1 -1
- package/dist/tsup/{chunk-T56IZ42M.cjs → chunk-GU7ML3KE.cjs} +13 -3
- package/dist/tsup/chunk-GU7ML3KE.cjs.map +1 -0
- package/dist/tsup/{chunk-IOLZ3ONU.js → chunk-JQ2AZ5FN.js} +3 -3
- package/dist/tsup/{chunk-7AFZMFPQ.js → chunk-JTHHCZCZ.js} +10 -1
- package/dist/tsup/chunk-JTHHCZCZ.js.map +1 -0
- package/dist/tsup/{chunk-UEULFXUI.cjs → chunk-KVFIONKQ.cjs} +11 -2
- package/dist/tsup/chunk-KVFIONKQ.cjs.map +1 -0
- package/dist/tsup/chunk-LWQFXGKS.cjs +243 -0
- package/dist/tsup/chunk-LWQFXGKS.cjs.map +1 -0
- package/dist/tsup/{chunk-QVCO6DTZ.js → chunk-MO2SSUOR.js} +8 -7
- package/dist/tsup/chunk-MO2SSUOR.js.map +1 -0
- package/dist/tsup/{chunk-LZ4TSBIP.js → chunk-OUENKQHB.js} +13 -3
- package/dist/tsup/chunk-OUENKQHB.js.map +1 -0
- package/dist/tsup/{chunk-6SBPWTXJ.cjs → chunk-PUZY2XCD.cjs} +10 -9
- package/dist/tsup/chunk-PUZY2XCD.cjs.map +1 -0
- package/dist/tsup/{chunk-C5TORAVP.js → chunk-QFJ24MBU.js} +27 -2
- package/dist/tsup/{chunk-C5TORAVP.js.map → chunk-QFJ24MBU.js.map} +1 -1
- package/dist/tsup/{chunk-BZWKY6WO.cjs → chunk-RXXDNJXB.cjs} +140 -140
- package/dist/tsup/{chunk-BZWKY6WO.cjs.map → chunk-RXXDNJXB.cjs.map} +1 -1
- package/dist/tsup/{chunk-IMRDHZM2.cjs → chunk-VBJQIBXI.cjs} +30 -5
- package/dist/tsup/chunk-VBJQIBXI.cjs.map +1 -0
- package/dist/tsup/client/mod.cjs +6 -6
- package/dist/tsup/client/mod.d.cts +4 -3
- package/dist/tsup/client/mod.d.ts +4 -3
- package/dist/tsup/client/mod.js +5 -5
- package/dist/tsup/common/log.cjs +2 -2
- package/dist/tsup/common/log.js +1 -1
- package/dist/tsup/common/websocket.cjs +3 -3
- package/dist/tsup/common/websocket.js +2 -2
- package/dist/tsup/{config-CZcjyT5B.d.ts → config-C4OSv0QP.d.ts} +92 -7
- package/dist/tsup/{config-rGWrumlO.d.cts → config-DTGoWdkG.d.cts} +92 -7
- package/dist/tsup/{config-BxOimoGX.d.cts → config-ey2I2zz5.d.cts} +46 -6
- package/dist/tsup/{config-BxOimoGX.d.ts → config-ey2I2zz5.d.ts} +46 -6
- package/dist/tsup/{context-B8W8E8nW.d.cts → context-C6cvDNyk.d.cts} +2 -2
- package/dist/tsup/{context-_UrDZhEh.d.ts → context-CMygeBxS.d.ts} +2 -2
- package/dist/tsup/db/drizzle.cjs +18 -10
- package/dist/tsup/db/drizzle.cjs.map +1 -1
- package/dist/tsup/db/drizzle.d.cts +5 -6
- package/dist/tsup/db/drizzle.d.ts +5 -6
- package/dist/tsup/db/drizzle.js +13 -5
- package/dist/tsup/db/drizzle.js.map +1 -1
- package/dist/tsup/db/mod.cjs +5 -175
- package/dist/tsup/db/mod.cjs.map +1 -1
- package/dist/tsup/db/mod.d.cts +11 -4
- package/dist/tsup/db/mod.d.ts +11 -4
- package/dist/tsup/db/mod.js +4 -174
- package/dist/tsup/db/mod.js.map +1 -1
- package/dist/tsup/dynamic/mod.cjs +2 -2
- package/dist/tsup/dynamic/mod.d.cts +3 -2
- package/dist/tsup/dynamic/mod.d.ts +3 -2
- package/dist/tsup/dynamic/mod.js +1 -1
- package/dist/tsup/inspector/mod.cjs +5 -4
- package/dist/tsup/inspector/mod.cjs.map +1 -1
- package/dist/tsup/inspector/mod.d.cts +12 -146
- package/dist/tsup/inspector/mod.d.ts +12 -146
- package/dist/tsup/inspector/mod.js +4 -3
- 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 -2
- package/dist/tsup/inspector-tab/mod.d.cts +4 -3
- package/dist/tsup/inspector-tab/mod.d.ts +4 -3
- package/dist/tsup/inspector-tab/mod.js +1 -1
- package/dist/tsup/mod.cjs +743 -247
- package/dist/tsup/mod.cjs.map +1 -1
- package/dist/tsup/mod.d.cts +6 -5
- package/dist/tsup/mod.d.ts +6 -5
- package/dist/tsup/mod.js +670 -174
- package/dist/tsup/mod.js.map +1 -1
- package/dist/tsup/test/mod.cjs +7 -7
- package/dist/tsup/test/mod.d.cts +3 -2
- package/dist/tsup/test/mod.d.ts +3 -2
- package/dist/tsup/test/mod.js +5 -5
- package/dist/tsup/unstable/migrations.d.cts +1 -1
- package/dist/tsup/unstable/migrations.d.ts +1 -1
- package/dist/tsup/utils.cjs +2 -2
- package/dist/tsup/utils.js +1 -1
- package/dist/tsup/workflow/mod.cjs +89 -95
- package/dist/tsup/workflow/mod.cjs.map +1 -1
- package/dist/tsup/workflow/mod.d.cts +5 -4
- package/dist/tsup/workflow/mod.d.ts +5 -4
- package/dist/tsup/workflow/mod.js +86 -92
- package/dist/tsup/workflow/mod.js.map +1 -1
- package/package.json +19 -9
- package/src/actor/config.test.ts +65 -1
- package/src/actor/config.ts +169 -5
- package/src/actor/mod.ts +10 -1
- package/src/client/actor-common.ts +5 -14
- package/src/common/database/config.ts +50 -3
- package/src/common/database/mod.test.ts +142 -4
- package/src/common/database/mod.ts +210 -98
- package/src/common/database/native-database.ts +42 -3
- package/src/common/database/shared.ts +9 -0
- package/src/db/drizzle.test.ts +8 -1
- package/src/db/drizzle.ts +15 -4
- package/src/db/mod.ts +3 -0
- package/src/inspector/workflow.ts +61 -0
- package/src/registry/napi-runtime.ts +69 -1
- package/src/registry/native.ts +474 -161
- package/src/registry/run-handler-coordinator.test.ts +252 -0
- package/src/registry/run-handler-coordinator.ts +219 -0
- package/src/registry/runtime.ts +34 -1
- package/src/registry/wasm-runtime.ts +122 -17
- package/src/utils/node.ts +44 -28
- package/src/workflow/driver.ts +56 -58
- package/src/workflow/inspector.ts +10 -15
- package/src/workflow/mod.ts +48 -70
- package/dist/tsup/chunk-6SBPWTXJ.cjs.map +0 -1
- package/dist/tsup/chunk-7AFZMFPQ.js.map +0 -1
- package/dist/tsup/chunk-HNHLBM3Y.cjs.map +0 -1
- package/dist/tsup/chunk-HOZ3ZLZ2.js.map +0 -1
- package/dist/tsup/chunk-IMRDHZM2.cjs.map +0 -1
- package/dist/tsup/chunk-LZ4TSBIP.js.map +0 -1
- package/dist/tsup/chunk-QVCO6DTZ.js.map +0 -1
- package/dist/tsup/chunk-QWLJCP3X.js.map +0 -1
- package/dist/tsup/chunk-T56IZ42M.cjs.map +0 -1
- package/dist/tsup/chunk-UEULFXUI.cjs.map +0 -1
- /package/dist/tsup/{chunk-XOOESJY7.js.map → chunk-FWROC5LA.js.map} +0 -0
- /package/dist/tsup/{chunk-IOLZ3ONU.js.map → chunk-JQ2AZ5FN.js.map} +0 -0
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
ActorContext as WasmActorContext,
|
|
3
|
-
ActorFactory as WasmActorFactory,
|
|
4
|
-
CancellationToken as WasmCancellationToken,
|
|
5
|
-
ConnHandle as WasmConnHandle,
|
|
6
|
-
CoreRegistry as WasmCoreRegistry,
|
|
7
|
-
WebSocketHandle as WasmWebSocketHandle,
|
|
8
|
-
} from "@rivetkit/rivetkit-wasm";
|
|
9
1
|
import { decodeBridgeRivetError, RivetError } from "@/actor/errors";
|
|
10
2
|
import type {
|
|
11
3
|
WasmRuntimeBindings,
|
|
@@ -15,6 +7,7 @@ import type {
|
|
|
15
7
|
import type {
|
|
16
8
|
ActorContextHandle,
|
|
17
9
|
ActorFactoryHandle,
|
|
10
|
+
ActorStateTransactionHandle,
|
|
18
11
|
CancellationTokenHandle,
|
|
19
12
|
ConnHandle,
|
|
20
13
|
CoreRuntime,
|
|
@@ -23,6 +16,8 @@ import type {
|
|
|
23
16
|
RuntimeActorKeySegment,
|
|
24
17
|
RuntimeApplicationListenerConfig,
|
|
25
18
|
RuntimeBytes,
|
|
19
|
+
RuntimeCronFire,
|
|
20
|
+
RuntimeCronJobInfo,
|
|
26
21
|
RuntimeHttpRequest,
|
|
27
22
|
RuntimeInspectorSnapshot,
|
|
28
23
|
RuntimeKvEntry,
|
|
@@ -34,12 +29,10 @@ import type {
|
|
|
34
29
|
RuntimeQueueNextBatchOptions,
|
|
35
30
|
RuntimeQueueTryNextBatchOptions,
|
|
36
31
|
RuntimeQueueWaitOptions,
|
|
37
|
-
RuntimeCronFire,
|
|
38
|
-
RuntimeCronJobInfo,
|
|
39
32
|
RuntimeRegistryRouteResponse,
|
|
40
33
|
RuntimeRequestSaveOpts,
|
|
41
|
-
RuntimeServeConfig,
|
|
42
34
|
RuntimeScheduledEventInfo,
|
|
35
|
+
RuntimeServeConfig,
|
|
43
36
|
RuntimeServerlessRequest,
|
|
44
37
|
RuntimeServerlessResponseHead,
|
|
45
38
|
RuntimeServerlessStreamCallback,
|
|
@@ -62,6 +55,35 @@ type WasmBindings = WasmRuntimeBindings;
|
|
|
62
55
|
export type WasmInitInput = WasmRuntimeInitInput;
|
|
63
56
|
type AnyFunction = (...args: unknown[]) => unknown;
|
|
64
57
|
type WasmRuntimeLoadConfig = Pick<WasmRuntimeConfig, "bindings" | "initInput">;
|
|
58
|
+
type WasmActorContext = object;
|
|
59
|
+
type WasmActorFactory = object;
|
|
60
|
+
type WasmConnHandle = object;
|
|
61
|
+
type WasmWebSocketHandle = object;
|
|
62
|
+
|
|
63
|
+
interface WasmCancellationToken {
|
|
64
|
+
aborted(): boolean;
|
|
65
|
+
cancel(): void;
|
|
66
|
+
onCancelled(callback: (...args: unknown[]) => unknown): void;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
interface WasmCoreRegistry {
|
|
70
|
+
register(name: string, factory: WasmActorFactory): void;
|
|
71
|
+
serve(config: RuntimeServeConfig): Promise<void>;
|
|
72
|
+
shutdown(): Promise<void>;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
interface WasmConstructors {
|
|
76
|
+
CoreRegistry: new () => WasmCoreRegistry;
|
|
77
|
+
ActorFactory: new (
|
|
78
|
+
callbacks: object,
|
|
79
|
+
config: RuntimeActorConfig | undefined | null,
|
|
80
|
+
) => WasmActorFactory;
|
|
81
|
+
CancellationToken: new () => WasmCancellationToken;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function asWasmConstructors(bindings: WasmBindings): WasmConstructors {
|
|
85
|
+
return bindings as unknown as WasmConstructors;
|
|
86
|
+
}
|
|
65
87
|
|
|
66
88
|
function asWasmRegistry(handle: RegistryHandle): WasmCoreRegistry {
|
|
67
89
|
return handle as unknown as WasmCoreRegistry;
|
|
@@ -235,11 +257,11 @@ function childHandle<T>(handle: unknown, name: string): T {
|
|
|
235
257
|
export class WasmCoreRuntime implements CoreRuntime {
|
|
236
258
|
readonly kind = "wasm";
|
|
237
259
|
|
|
238
|
-
#
|
|
260
|
+
#constructors: WasmConstructors;
|
|
239
261
|
#sql = new WeakMap<WasmActorContext, RuntimeSqlDatabase>();
|
|
240
262
|
|
|
241
263
|
constructor(bindings: WasmBindings) {
|
|
242
|
-
this.#
|
|
264
|
+
this.#constructors = asWasmConstructors(bindings);
|
|
243
265
|
}
|
|
244
266
|
|
|
245
267
|
#actorSql(ctx: ActorContextHandle): RuntimeSqlDatabase {
|
|
@@ -254,7 +276,7 @@ export class WasmCoreRuntime implements CoreRuntime {
|
|
|
254
276
|
|
|
255
277
|
createRegistry(): RegistryHandle {
|
|
256
278
|
return callWasmSync(() =>
|
|
257
|
-
asRegistryHandle(new this.#
|
|
279
|
+
asRegistryHandle(new this.#constructors.CoreRegistry()),
|
|
258
280
|
);
|
|
259
281
|
}
|
|
260
282
|
|
|
@@ -342,7 +364,7 @@ export class WasmCoreRuntime implements CoreRuntime {
|
|
|
342
364
|
): ActorFactoryHandle {
|
|
343
365
|
return callWasmSync(() =>
|
|
344
366
|
asActorFactoryHandle(
|
|
345
|
-
new this.#
|
|
367
|
+
new this.#constructors.ActorFactory(callbacks, config),
|
|
346
368
|
),
|
|
347
369
|
);
|
|
348
370
|
}
|
|
@@ -350,7 +372,7 @@ export class WasmCoreRuntime implements CoreRuntime {
|
|
|
350
372
|
createCancellationToken(): CancellationTokenHandle {
|
|
351
373
|
return callWasmSync(
|
|
352
374
|
() =>
|
|
353
|
-
new this.#
|
|
375
|
+
new this.#constructors.CancellationToken() as unknown as CancellationTokenHandle,
|
|
354
376
|
);
|
|
355
377
|
}
|
|
356
378
|
|
|
@@ -399,6 +421,17 @@ export class WasmCoreRuntime implements CoreRuntime {
|
|
|
399
421
|
);
|
|
400
422
|
}
|
|
401
423
|
|
|
424
|
+
async actorSetRunWakeAt(
|
|
425
|
+
ctx: ActorContextHandle,
|
|
426
|
+
timestampMs?: number | undefined | null,
|
|
427
|
+
): Promise<void> {
|
|
428
|
+
await callHandleAsync(
|
|
429
|
+
asWasmActorContext(ctx),
|
|
430
|
+
"setRunWakeAt",
|
|
431
|
+
optionalWasmNumber(timestampMs),
|
|
432
|
+
);
|
|
433
|
+
}
|
|
434
|
+
|
|
402
435
|
actorRequestSave(
|
|
403
436
|
ctx: ActorContextHandle,
|
|
404
437
|
opts?: RuntimeRequestSaveOpts | undefined | null,
|
|
@@ -748,9 +781,10 @@ export class WasmCoreRuntime implements CoreRuntime {
|
|
|
748
781
|
async actorSqlBeginTransaction(
|
|
749
782
|
ctx: ActorContextHandle,
|
|
750
783
|
timeoutMs?: number,
|
|
784
|
+
name?: string,
|
|
751
785
|
): Promise<SqliteTransactionHandle> {
|
|
752
786
|
return (await callWasm(() =>
|
|
753
|
-
this.#actorSql(ctx).beginTransaction(timeoutMs),
|
|
787
|
+
this.#actorSql(ctx).beginTransaction(timeoutMs, name),
|
|
754
788
|
)) as unknown as SqliteTransactionHandle;
|
|
755
789
|
}
|
|
756
790
|
|
|
@@ -802,6 +836,61 @@ export class WasmCoreRuntime implements CoreRuntime {
|
|
|
802
836
|
).rollback(),
|
|
803
837
|
);
|
|
804
838
|
}
|
|
839
|
+
async actorBeginStateTransaction(
|
|
840
|
+
ctx: ActorContextHandle,
|
|
841
|
+
timeoutMs?: number,
|
|
842
|
+
): Promise<ActorStateTransactionHandle> {
|
|
843
|
+
return (await callWasm(() =>
|
|
844
|
+
(
|
|
845
|
+
asWasmActorContext(ctx) as unknown as {
|
|
846
|
+
beginStateTransaction(
|
|
847
|
+
timeoutMs?: number,
|
|
848
|
+
): Promise<ActorStateTransactionHandle>;
|
|
849
|
+
}
|
|
850
|
+
).beginStateTransaction(timeoutMs),
|
|
851
|
+
)) as ActorStateTransactionHandle;
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
async actorStateTransactionExecute(
|
|
855
|
+
transaction: ActorStateTransactionHandle,
|
|
856
|
+
sql: string,
|
|
857
|
+
params?: RuntimeSqlBindParams,
|
|
858
|
+
): Promise<RuntimeSqlExecuteResult> {
|
|
859
|
+
const result = await callWasm(() =>
|
|
860
|
+
(
|
|
861
|
+
transaction as unknown as {
|
|
862
|
+
execute(
|
|
863
|
+
sql: string,
|
|
864
|
+
params?: RuntimeSqlBindParams,
|
|
865
|
+
): Promise<RuntimeSqlExecuteResult>;
|
|
866
|
+
}
|
|
867
|
+
).execute(sql, params),
|
|
868
|
+
);
|
|
869
|
+
return normalizeRuntimeSqlExecuteResult(result);
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
async actorStateTransactionCommit(
|
|
873
|
+
transaction: ActorStateTransactionHandle,
|
|
874
|
+
payload: RuntimeStateDeltaPayload,
|
|
875
|
+
): Promise<void> {
|
|
876
|
+
await callWasm(() =>
|
|
877
|
+
(
|
|
878
|
+
transaction as unknown as {
|
|
879
|
+
commit(payload: RuntimeStateDeltaPayload): Promise<void>;
|
|
880
|
+
}
|
|
881
|
+
).commit(payload),
|
|
882
|
+
);
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
async actorStateTransactionRollback(
|
|
886
|
+
transaction: ActorStateTransactionHandle,
|
|
887
|
+
): Promise<void> {
|
|
888
|
+
await callWasm(() =>
|
|
889
|
+
(
|
|
890
|
+
transaction as unknown as { rollback(): Promise<void> }
|
|
891
|
+
).rollback(),
|
|
892
|
+
);
|
|
893
|
+
}
|
|
805
894
|
|
|
806
895
|
async actorSqlQuery(
|
|
807
896
|
ctx: ActorContextHandle,
|
|
@@ -912,6 +1001,22 @@ export class WasmCoreRuntime implements CoreRuntime {
|
|
|
912
1001
|
);
|
|
913
1002
|
}
|
|
914
1003
|
|
|
1004
|
+
async actorQueueCompletePersisted(
|
|
1005
|
+
ctx: ActorContextHandle,
|
|
1006
|
+
messageId: bigint,
|
|
1007
|
+
expectedName: string,
|
|
1008
|
+
response?: RuntimeBytes | undefined | null,
|
|
1009
|
+
): Promise<boolean> {
|
|
1010
|
+
const queue = childHandle(asWasmActorContext(ctx), "queue");
|
|
1011
|
+
return await callHandleAsync(
|
|
1012
|
+
queue,
|
|
1013
|
+
"completePersisted",
|
|
1014
|
+
messageId,
|
|
1015
|
+
expectedName,
|
|
1016
|
+
response,
|
|
1017
|
+
);
|
|
1018
|
+
}
|
|
1019
|
+
|
|
915
1020
|
async actorQueueEnqueueAndWait(
|
|
916
1021
|
ctx: ActorContextHandle,
|
|
917
1022
|
name: string,
|
package/src/utils/node.ts
CHANGED
|
@@ -19,20 +19,35 @@ let nodeStream: typeof import("node:stream/promises") | undefined;
|
|
|
19
19
|
let nodeUrl: typeof import("node:url") | undefined;
|
|
20
20
|
|
|
21
21
|
let hasImportedDependencies = false;
|
|
22
|
+
type NodeBuiltin = `node:${string}`;
|
|
23
|
+
let fallbackRequire: ReturnType<typeof createRequire> | undefined;
|
|
22
24
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Loads a Node.js built-in synchronously without relying on `import.meta`,
|
|
27
|
+
* which esbuild cannot preserve in CommonJS output. Prefer Node's dedicated
|
|
28
|
+
* built-in loader and retain `createRequire` for Node 22.0-22.2 compatibility.
|
|
29
|
+
*
|
|
30
|
+
* @see https://nodejs.org/api/process.html#processgetbuiltinmoduleid
|
|
31
|
+
* @see https://github.com/evanw/esbuild/issues/1492
|
|
32
|
+
*/
|
|
33
|
+
export function loadNodeBuiltin<T>(id: NodeBuiltin): T {
|
|
34
|
+
const nodeProcess = globalThis.process;
|
|
35
|
+
const builtin = nodeProcess?.getBuiltinModule?.(id);
|
|
36
|
+
|
|
37
|
+
if (builtin !== undefined) {
|
|
38
|
+
return builtin as T;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (!nodeProcess?.execPath) {
|
|
42
|
+
throw new Error("Node.js built-ins are not available");
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Node 22.0-22.2 does not provide getBuiltinModule(). Avoid import.meta here:
|
|
46
|
+
// esbuild replaces it with an empty shim in CommonJS output, leaving
|
|
47
|
+
// import_meta.url undefined. This loader only resolves built-ins, so the
|
|
48
|
+
// fallback base does not affect package resolution.
|
|
49
|
+
fallbackRequire ??= createRequire(nodeProcess.execPath);
|
|
50
|
+
return fallbackRequire(id) as T;
|
|
36
51
|
}
|
|
37
52
|
|
|
38
53
|
/**
|
|
@@ -48,22 +63,23 @@ export function importNodeDependencies(): void {
|
|
|
48
63
|
if (hasImportedDependencies) return;
|
|
49
64
|
|
|
50
65
|
try {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
nodePath =
|
|
59
|
-
nodeOs =
|
|
60
|
-
nodeChildProcess =
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
66
|
+
nodeCrypto =
|
|
67
|
+
loadNodeBuiltin<typeof import("node:crypto")>("node:crypto");
|
|
68
|
+
nodeFsSync = loadNodeBuiltin<typeof import("node:fs")>("node:fs");
|
|
69
|
+
nodeFs =
|
|
70
|
+
loadNodeBuiltin<typeof import("node:fs/promises")>(
|
|
71
|
+
"node:fs/promises",
|
|
72
|
+
);
|
|
73
|
+
nodePath = loadNodeBuiltin<typeof import("node:path")>("node:path");
|
|
74
|
+
nodeOs = loadNodeBuiltin<typeof import("node:os")>("node:os");
|
|
75
|
+
nodeChildProcess =
|
|
76
|
+
loadNodeBuiltin<typeof import("node:child_process")>(
|
|
77
|
+
"node:child_process",
|
|
78
|
+
);
|
|
79
|
+
nodeStream = loadNodeBuiltin<typeof import("node:stream/promises")>(
|
|
80
|
+
"node:stream/promises",
|
|
65
81
|
);
|
|
66
|
-
nodeUrl =
|
|
82
|
+
nodeUrl = loadNodeBuiltin<typeof import("node:url")>("node:url");
|
|
67
83
|
hasImportedDependencies = true;
|
|
68
84
|
} catch (err) {
|
|
69
85
|
console.warn(
|
package/src/workflow/driver.ts
CHANGED
|
@@ -8,7 +8,7 @@ import type {
|
|
|
8
8
|
import type { RunContext } from "@/actor/config";
|
|
9
9
|
import type { AnyStaticActorInstance } from "@/actor/definition";
|
|
10
10
|
import { makeWorkflowKey, workflowStoragePrefix } from "@/actor/keys";
|
|
11
|
-
import type {
|
|
11
|
+
import type { RawAccess } from "@/common/database/config";
|
|
12
12
|
|
|
13
13
|
const WORKFLOW_STORAGE_PREFIX = workflowStoragePrefix();
|
|
14
14
|
// Keep workflow flushes below depot's 320-dirty-page commit ceiling. The
|
|
@@ -68,52 +68,40 @@ function normalizeSqlBlob(value: unknown): Uint8Array {
|
|
|
68
68
|
throw new Error("workflow sqlite value was not a blob");
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
function
|
|
71
|
+
function runtimeDbFromContext(
|
|
72
72
|
runCtx?: RunContext<any, any, any, any, any, any, any, any>,
|
|
73
|
-
):
|
|
74
|
-
const
|
|
73
|
+
): RawAccess | undefined {
|
|
74
|
+
const db = (runCtx as unknown as { db?: unknown } | undefined)?.db;
|
|
75
75
|
if (
|
|
76
|
-
|
|
77
|
-
typeof
|
|
78
|
-
"
|
|
79
|
-
"
|
|
80
|
-
"executeBatch" in sql &&
|
|
81
|
-
"run" in sql
|
|
76
|
+
db &&
|
|
77
|
+
typeof db === "object" &&
|
|
78
|
+
"execute" in db &&
|
|
79
|
+
"transaction" in db
|
|
82
80
|
) {
|
|
83
|
-
return
|
|
81
|
+
return db as RawAccess;
|
|
84
82
|
}
|
|
85
83
|
return undefined;
|
|
86
84
|
}
|
|
87
85
|
|
|
88
|
-
type WorkflowSqliteDatabase = SqliteDatabase &
|
|
89
|
-
Required<Pick<SqliteDatabase, "executeBatch">>;
|
|
90
|
-
|
|
91
86
|
class WorkflowStorage {
|
|
92
|
-
#
|
|
87
|
+
#db: RawAccess;
|
|
93
88
|
|
|
94
|
-
constructor(
|
|
95
|
-
if (!
|
|
89
|
+
constructor(db?: RawAccess) {
|
|
90
|
+
if (!db) {
|
|
96
91
|
throw new Error(
|
|
97
92
|
"workflow storage requires embedded SQLite; actor KV workflow storage is no longer supported",
|
|
98
93
|
);
|
|
99
94
|
}
|
|
100
|
-
|
|
101
|
-
throw new Error(
|
|
102
|
-
"workflow storage requires a SQLite database with executeBatch support",
|
|
103
|
-
);
|
|
104
|
-
}
|
|
105
|
-
this.#sql = sql as WorkflowSqliteDatabase;
|
|
95
|
+
this.#db = db;
|
|
106
96
|
}
|
|
107
97
|
|
|
108
98
|
async get(key: Uint8Array): Promise<Uint8Array | null> {
|
|
109
99
|
const prefixed = makeWorkflowKey(key);
|
|
110
|
-
const
|
|
100
|
+
const rows = await this.#db.execute<{ value: unknown }>(
|
|
111
101
|
"SELECT value FROM _rivet_wf_kv WHERE key = ?",
|
|
112
|
-
|
|
102
|
+
prefixed,
|
|
113
103
|
);
|
|
114
|
-
return
|
|
115
|
-
? null
|
|
116
|
-
: normalizeSqlBlob(result.rows[0][0]);
|
|
104
|
+
return rows[0]?.value == null ? null : normalizeSqlBlob(rows[0].value);
|
|
117
105
|
}
|
|
118
106
|
|
|
119
107
|
async set(key: Uint8Array, value: Uint8Array): Promise<void> {
|
|
@@ -122,18 +110,20 @@ class WorkflowStorage {
|
|
|
122
110
|
|
|
123
111
|
async delete(key: Uint8Array): Promise<void> {
|
|
124
112
|
const prefixed = makeWorkflowKey(key);
|
|
125
|
-
await this.#
|
|
113
|
+
await this.#db.execute(
|
|
114
|
+
"DELETE FROM _rivet_wf_kv WHERE key = ?",
|
|
126
115
|
prefixed,
|
|
127
|
-
|
|
116
|
+
);
|
|
128
117
|
}
|
|
129
118
|
|
|
130
119
|
async deletePrefix(prefix: Uint8Array): Promise<void> {
|
|
131
120
|
const start = makeWorkflowKey(prefix);
|
|
132
121
|
const end = computeUpperBound(start);
|
|
133
122
|
if (end) {
|
|
134
|
-
await this.#
|
|
123
|
+
await this.#db.execute(
|
|
135
124
|
"DELETE FROM _rivet_wf_kv WHERE key >= ? AND key < ?",
|
|
136
|
-
|
|
125
|
+
start,
|
|
126
|
+
end,
|
|
137
127
|
);
|
|
138
128
|
return;
|
|
139
129
|
}
|
|
@@ -148,9 +138,10 @@ class WorkflowStorage {
|
|
|
148
138
|
async deleteRange(start: Uint8Array, end: Uint8Array): Promise<void> {
|
|
149
139
|
const prefixedStart = makeWorkflowKey(start);
|
|
150
140
|
const prefixedEnd = makeWorkflowKey(end);
|
|
151
|
-
await this.#
|
|
141
|
+
await this.#db.execute(
|
|
152
142
|
"DELETE FROM _rivet_wf_kv WHERE key >= ? AND key < ?",
|
|
153
|
-
|
|
143
|
+
prefixedStart,
|
|
144
|
+
prefixedEnd,
|
|
154
145
|
);
|
|
155
146
|
}
|
|
156
147
|
|
|
@@ -168,29 +159,33 @@ class WorkflowStorage {
|
|
|
168
159
|
async batch(writes: KVWrite[]): Promise<void> {
|
|
169
160
|
if (writes.length === 0) return;
|
|
170
161
|
for (const chunk of chunkWorkflowWrites(writes)) {
|
|
171
|
-
await this.#
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
162
|
+
await this.#db.transaction(async (tx) => {
|
|
163
|
+
for (const { key, value } of chunk) {
|
|
164
|
+
await tx.execute(
|
|
165
|
+
"INSERT INTO _rivet_wf_kv (key, value) VALUES (?, ?) ON CONFLICT(key) DO UPDATE SET value = excluded.value",
|
|
166
|
+
makeWorkflowKey(key),
|
|
167
|
+
value,
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
});
|
|
177
171
|
}
|
|
178
172
|
}
|
|
179
173
|
|
|
180
174
|
async listRaw(prefix: Uint8Array): Promise<KVEntryTuple[]> {
|
|
181
175
|
const end = computeUpperBound(prefix);
|
|
182
|
-
const
|
|
183
|
-
? await this.#
|
|
176
|
+
const rows = end
|
|
177
|
+
? await this.#db.execute<{ key: unknown; value: unknown }>(
|
|
184
178
|
"SELECT key, value FROM _rivet_wf_kv WHERE key >= ? AND key < ? ORDER BY key ASC",
|
|
185
|
-
|
|
179
|
+
prefix,
|
|
180
|
+
end,
|
|
186
181
|
)
|
|
187
|
-
: await this.#
|
|
182
|
+
: await this.#db.execute<{ key: unknown; value: unknown }>(
|
|
188
183
|
"SELECT key, value FROM _rivet_wf_kv WHERE key >= ? ORDER BY key ASC",
|
|
189
|
-
|
|
184
|
+
prefix,
|
|
190
185
|
);
|
|
191
|
-
return
|
|
192
|
-
normalizeSqlBlob(row
|
|
193
|
-
normalizeSqlBlob(row
|
|
186
|
+
return rows.map((row) => [
|
|
187
|
+
normalizeSqlBlob(row.key),
|
|
188
|
+
normalizeSqlBlob(row.value),
|
|
194
189
|
]);
|
|
195
190
|
}
|
|
196
191
|
|
|
@@ -200,14 +195,17 @@ class WorkflowStorage {
|
|
|
200
195
|
start < keys.length;
|
|
201
196
|
start += WORKFLOW_SQLITE_MAX_BATCH_ROWS
|
|
202
197
|
) {
|
|
203
|
-
await this.#
|
|
204
|
-
keys
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
198
|
+
await this.#db.transaction(async (tx) => {
|
|
199
|
+
for (const key of keys.slice(
|
|
200
|
+
start,
|
|
201
|
+
start + WORKFLOW_SQLITE_MAX_BATCH_ROWS,
|
|
202
|
+
)) {
|
|
203
|
+
await tx.execute(
|
|
204
|
+
"DELETE FROM _rivet_wf_kv WHERE key = ?",
|
|
205
|
+
key,
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
});
|
|
211
209
|
}
|
|
212
210
|
}
|
|
213
211
|
}
|
|
@@ -331,7 +329,7 @@ export class ActorWorkflowDriver implements EngineDriver {
|
|
|
331
329
|
this.#actor = actor;
|
|
332
330
|
this.#runCtx = runCtx;
|
|
333
331
|
this.messageDriver = new ActorWorkflowMessageDriver(actor, runCtx);
|
|
334
|
-
this.#storage = new WorkflowStorage(
|
|
332
|
+
this.#storage = new WorkflowStorage(runtimeDbFromContext(runCtx));
|
|
335
333
|
}
|
|
336
334
|
|
|
337
335
|
async get(key: Uint8Array): Promise<Uint8Array | null> {
|
|
@@ -425,7 +423,7 @@ export class ActorWorkflowControlDriver implements EngineDriver {
|
|
|
425
423
|
runCtx?: RunContext<any, any, any, any, any, any, any, any>,
|
|
426
424
|
) {
|
|
427
425
|
this.#actor = actor;
|
|
428
|
-
this.#storage = new WorkflowStorage(
|
|
426
|
+
this.#storage = new WorkflowStorage(runtimeDbFromContext(runCtx));
|
|
429
427
|
}
|
|
430
428
|
|
|
431
429
|
async get(key: Uint8Array): Promise<Uint8Array | null> {
|
|
@@ -10,12 +10,14 @@ import type {
|
|
|
10
10
|
WorkflowHistorySnapshot,
|
|
11
11
|
WorkflowState,
|
|
12
12
|
} from "@rivetkit/workflow-engine";
|
|
13
|
-
import * as transport from "@/
|
|
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
22
|
type HistoryListener = (history: WorkflowHistoryBytes) => void;
|
|
21
23
|
|
|
@@ -35,14 +37,7 @@ function createHistoryEmitter() {
|
|
|
35
37
|
};
|
|
36
38
|
}
|
|
37
39
|
|
|
38
|
-
export
|
|
39
|
-
getHistory: () => WorkflowHistoryBytes | null;
|
|
40
|
-
getState: () => Promise<WorkflowState | null>;
|
|
41
|
-
onHistoryUpdated: (
|
|
42
|
-
listener: (history: WorkflowHistoryBytes) => void,
|
|
43
|
-
) => () => void;
|
|
44
|
-
replayFromStep: (entryId?: string) => Promise<WorkflowHistoryBytes | null>;
|
|
45
|
-
}
|
|
40
|
+
export type WorkflowInspectorAdapter = PublicWorkflowInspectorAdapter;
|
|
46
41
|
|
|
47
42
|
export function createWorkflowInspectorAdapter(): {
|
|
48
43
|
adapter: WorkflowInspectorAdapter;
|
|
@@ -88,7 +83,7 @@ export function createWorkflowInspectorAdapter(): {
|
|
|
88
83
|
}
|
|
89
84
|
|
|
90
85
|
function encodeCbor(value: unknown): ArrayBuffer {
|
|
91
|
-
return
|
|
86
|
+
return encodeWorkflowInspectorValue(value);
|
|
92
87
|
}
|
|
93
88
|
|
|
94
89
|
function encodeOptionalCbor(value: unknown): ArrayBuffer | null {
|