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
|
@@ -38,3 +38,104 @@ export function createWriteThroughProxy<T>(
|
|
|
38
38
|
},
|
|
39
39
|
) as T;
|
|
40
40
|
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Returns the raw target behind an `@rivetkit/on-change` proxy, following
|
|
44
|
+
* chains of proxies wrapping proxies until reaching a plain value.
|
|
45
|
+
*/
|
|
46
|
+
function unwrapProxy(value: unknown): unknown {
|
|
47
|
+
let current = value;
|
|
48
|
+
while (current !== null && typeof current === "object") {
|
|
49
|
+
const target = onChange.target(current as Record<string, any>);
|
|
50
|
+
if (target === current) {
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
current = target;
|
|
54
|
+
}
|
|
55
|
+
return current;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function isPlainObject(value: unknown): value is Record<string, unknown> {
|
|
59
|
+
const proto = Object.getPrototypeOf(value as object);
|
|
60
|
+
return proto === Object.prototype || proto === null;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function unwrapDeep(value: unknown, seen: Set<object>): unknown {
|
|
64
|
+
const unwrapped = unwrapProxy(value);
|
|
65
|
+
if (!unwrapped || typeof unwrapped !== "object") {
|
|
66
|
+
return unwrapped;
|
|
67
|
+
}
|
|
68
|
+
if (seen.has(unwrapped)) {
|
|
69
|
+
return unwrapped;
|
|
70
|
+
}
|
|
71
|
+
seen.add(unwrapped);
|
|
72
|
+
|
|
73
|
+
if (Array.isArray(unwrapped)) {
|
|
74
|
+
for (let i = 0; i < unwrapped.length; i++) {
|
|
75
|
+
const child = unwrapDeep(unwrapped[i], seen);
|
|
76
|
+
if (child !== unwrapped[i]) {
|
|
77
|
+
unwrapped[i] = child;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return unwrapped;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (unwrapped instanceof Map) {
|
|
84
|
+
const replacements: [unknown, unknown, unknown][] = [];
|
|
85
|
+
for (const [key, child] of unwrapped.entries()) {
|
|
86
|
+
const nextKey = unwrapDeep(key, seen);
|
|
87
|
+
const nextChild = unwrapDeep(child, seen);
|
|
88
|
+
if (nextKey !== key || nextChild !== child) {
|
|
89
|
+
replacements.push([key, nextKey, nextChild]);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
for (const [key, nextKey, nextChild] of replacements) {
|
|
93
|
+
if (nextKey !== key) {
|
|
94
|
+
unwrapped.delete(key);
|
|
95
|
+
}
|
|
96
|
+
unwrapped.set(nextKey, nextChild);
|
|
97
|
+
}
|
|
98
|
+
return unwrapped;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (unwrapped instanceof Set) {
|
|
102
|
+
const replacements: [unknown, unknown][] = [];
|
|
103
|
+
for (const child of unwrapped.values()) {
|
|
104
|
+
const next = unwrapDeep(child, seen);
|
|
105
|
+
if (next !== child) {
|
|
106
|
+
replacements.push([child, next]);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
for (const [child, next] of replacements) {
|
|
110
|
+
unwrapped.delete(child);
|
|
111
|
+
unwrapped.add(next);
|
|
112
|
+
}
|
|
113
|
+
return unwrapped;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (isPlainObject(unwrapped)) {
|
|
117
|
+
for (const key of Object.keys(unwrapped)) {
|
|
118
|
+
const child = unwrapDeep(unwrapped[key], seen);
|
|
119
|
+
if (child !== unwrapped[key]) {
|
|
120
|
+
unwrapped[key] = child;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return unwrapped;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Strips every `@rivetkit/on-change` proxy out of a value in place, including
|
|
130
|
+
* proxies nested inside plain objects, arrays, `Map`s, and `Set`s.
|
|
131
|
+
*
|
|
132
|
+
* A read of `c.state` or `conn.state` hands back a deep write-through proxy,
|
|
133
|
+
* so an update written as `c.state = { ...c.state, foo }` produces a plain root
|
|
134
|
+
* object whose children are still proxies. Persisting that value as-is makes
|
|
135
|
+
* the next read wrap proxies in another proxy layer, and each layer multiplies
|
|
136
|
+
* the work of traversing the state, so repeated spread updates degrade
|
|
137
|
+
* exponentially. Unwrapping before persisting keeps stored state proxy-free.
|
|
138
|
+
*/
|
|
139
|
+
export function unwrapWriteThroughProxy<T>(value: T): T {
|
|
140
|
+
return unwrapDeep(value, new Set()) as T;
|
|
141
|
+
}
|
package/src/test/mod.ts
CHANGED
|
@@ -1,31 +1,13 @@
|
|
|
1
|
-
import pRetry from "p-retry";
|
|
2
1
|
import type { TestContext } from "vitest";
|
|
3
2
|
import { convertRegistryConfigToClientConfig } from "@/client/config";
|
|
4
3
|
import { type Client, createClient } from "@/client/mod";
|
|
5
|
-
import { getMetadata } from "@/engine-client/api-endpoints";
|
|
6
4
|
import type { Registry } from "@/registry";
|
|
5
|
+
import { waitForRegistryReady } from "./ready";
|
|
7
6
|
|
|
8
7
|
export interface SetupTestResult<A extends Registry<any>> {
|
|
9
8
|
client: Client<A>;
|
|
10
9
|
}
|
|
11
10
|
|
|
12
|
-
async function waitForRegistryReady(registry: Registry<any>): Promise<void> {
|
|
13
|
-
const clientConfig = convertRegistryConfigToClientConfig(
|
|
14
|
-
registry.parseConfig(),
|
|
15
|
-
);
|
|
16
|
-
|
|
17
|
-
await pRetry(
|
|
18
|
-
async () => {
|
|
19
|
-
await getMetadata(clientConfig);
|
|
20
|
-
},
|
|
21
|
-
{
|
|
22
|
-
retries: 20,
|
|
23
|
-
minTimeout: 50,
|
|
24
|
-
maxTimeout: 250,
|
|
25
|
-
},
|
|
26
|
-
);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
11
|
export async function setupTest<A extends Registry<any>>(
|
|
30
12
|
c: TestContext,
|
|
31
13
|
registry: A,
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import pRetry from "p-retry";
|
|
2
|
+
import type { Registry } from "@/registry";
|
|
3
|
+
|
|
4
|
+
export async function waitForRegistryReady(
|
|
5
|
+
registry: Registry<any>,
|
|
6
|
+
): Promise<void> {
|
|
7
|
+
await pRetry(
|
|
8
|
+
async () => {
|
|
9
|
+
const response = await registry.routes.health();
|
|
10
|
+
if (!response.ok) {
|
|
11
|
+
throw new Error(
|
|
12
|
+
`RivetKit registry is not ready: ${response.status} ${await response.text()}`,
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
retries: 120,
|
|
18
|
+
minTimeout: 50,
|
|
19
|
+
maxTimeout: 250,
|
|
20
|
+
},
|
|
21
|
+
);
|
|
22
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import type { RawAccess } from "@/common/database/config";
|
|
2
|
+
|
|
3
|
+
export const DEFAULT_MIGRATION_TABLE_NAME = "rivetkit_schema_version";
|
|
4
|
+
|
|
5
|
+
export type MigrationDatabase = Pick<RawAccess, "execute">;
|
|
6
|
+
|
|
7
|
+
export type Migration =
|
|
8
|
+
| {
|
|
9
|
+
version: number;
|
|
10
|
+
sql: string;
|
|
11
|
+
up?: never;
|
|
12
|
+
}
|
|
13
|
+
| {
|
|
14
|
+
version: number;
|
|
15
|
+
sql?: never;
|
|
16
|
+
up: (db: MigrationDatabase) => Promise<void> | void;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export interface MigrationsOptions {
|
|
20
|
+
/** A table owned by this schema. Override this when multiple schemas share a database. */
|
|
21
|
+
tableName?: string;
|
|
22
|
+
/** Detect the version of a schema that predates its migration table. */
|
|
23
|
+
adopt?: (db: MigrationDatabase) => Promise<number> | number;
|
|
24
|
+
/** Contiguous migrations numbered from 1. */
|
|
25
|
+
migrations: readonly Migration[];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Creates an `onMigrate` callback that applies each unapplied migration in order.
|
|
30
|
+
* RivetKit runs the callback inside its migration savepoint, making the complete
|
|
31
|
+
* ladder atomic when used with `db({ onMigrate })`.
|
|
32
|
+
*/
|
|
33
|
+
export function migrations({
|
|
34
|
+
tableName = DEFAULT_MIGRATION_TABLE_NAME,
|
|
35
|
+
adopt,
|
|
36
|
+
migrations: ladder,
|
|
37
|
+
}: MigrationsOptions): (db: MigrationDatabase) => Promise<void> {
|
|
38
|
+
validateTableName(tableName);
|
|
39
|
+
validateLadder(ladder);
|
|
40
|
+
|
|
41
|
+
return async (database) => {
|
|
42
|
+
const quotedTableName = `"${tableName}"`;
|
|
43
|
+
await database.execute(`
|
|
44
|
+
CREATE TABLE IF NOT EXISTS ${quotedTableName} (
|
|
45
|
+
singleton INTEGER PRIMARY KEY CHECK (singleton = 1),
|
|
46
|
+
schema_version INTEGER NOT NULL CHECK (
|
|
47
|
+
schema_version BETWEEN 0 AND ${Number.MAX_SAFE_INTEGER}
|
|
48
|
+
)
|
|
49
|
+
) STRICT
|
|
50
|
+
`);
|
|
51
|
+
|
|
52
|
+
const rows = await database.execute<{ schema_version: unknown }>(
|
|
53
|
+
`SELECT schema_version FROM ${quotedTableName} WHERE singleton = 1`,
|
|
54
|
+
);
|
|
55
|
+
if (rows.length > 1) {
|
|
56
|
+
throw new Error(
|
|
57
|
+
`invalid migration table "${tableName}": expected at most one version row, received ${rows.length}`,
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const rawCurrent = rows[0]?.schema_version;
|
|
62
|
+
let current = rows.length === 0 ? 0 : rawCurrent;
|
|
63
|
+
if (rows.length === 0 && adopt) {
|
|
64
|
+
current = await adopt(database);
|
|
65
|
+
}
|
|
66
|
+
if (
|
|
67
|
+
typeof current !== "number" ||
|
|
68
|
+
!Number.isSafeInteger(current) ||
|
|
69
|
+
current < 0
|
|
70
|
+
) {
|
|
71
|
+
throw new Error(
|
|
72
|
+
`invalid schema version ${String(current)} in migration table "${tableName}"`,
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
if (current > ladder.length) {
|
|
76
|
+
throw new Error(
|
|
77
|
+
`migration version ${current} in "${tableName}" is newer than supported version ${ladder.length}`,
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
if (rows.length === 0 && current > 0) {
|
|
81
|
+
await writeVersion(database, quotedTableName, current);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
for (const migration of ladder.slice(current)) {
|
|
85
|
+
if (migration.sql !== undefined) {
|
|
86
|
+
await database.execute(migration.sql);
|
|
87
|
+
} else {
|
|
88
|
+
await migration.up(database);
|
|
89
|
+
}
|
|
90
|
+
await writeVersion(database, quotedTableName, migration.version);
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
async function writeVersion(
|
|
96
|
+
database: MigrationDatabase,
|
|
97
|
+
quotedTableName: string,
|
|
98
|
+
version: number,
|
|
99
|
+
): Promise<void> {
|
|
100
|
+
await database.execute(
|
|
101
|
+
`INSERT INTO ${quotedTableName} (singleton, schema_version)
|
|
102
|
+
VALUES (1, ?)
|
|
103
|
+
ON CONFLICT(singleton) DO UPDATE SET schema_version = excluded.schema_version`,
|
|
104
|
+
version,
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function validateTableName(tableName: string): void {
|
|
109
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(tableName)) {
|
|
110
|
+
throw new Error(
|
|
111
|
+
`invalid migration table name "${tableName}": expected a SQLite identifier`,
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function validateLadder(ladder: readonly Migration[]): void {
|
|
117
|
+
if (ladder.length === 0) {
|
|
118
|
+
throw new Error("migration ladder must not be empty");
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
for (const [index, migration] of ladder.entries()) {
|
|
122
|
+
const expectedVersion = index + 1;
|
|
123
|
+
if (migration.version !== expectedVersion) {
|
|
124
|
+
throw new Error(
|
|
125
|
+
`invalid migration ladder: expected version ${expectedVersion}, received ${migration.version}`,
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
const hasSql = typeof migration.sql === "string";
|
|
129
|
+
const hasUp = typeof migration.up === "function";
|
|
130
|
+
if (hasSql === hasUp) {
|
|
131
|
+
throw new Error(
|
|
132
|
+
`invalid migration ${migration.version}: expected exactly one of sql or up`,
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
if (hasSql && migration.sql.trim().length === 0) {
|
|
136
|
+
throw new Error(
|
|
137
|
+
`invalid migration ${migration.version}: SQL is empty`,
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
package/src/utils/env-vars.ts
CHANGED
|
@@ -30,10 +30,15 @@ export const getRivetRunEnginePort = (): number | undefined => {
|
|
|
30
30
|
};
|
|
31
31
|
export const getRivetRunEngineVersion = (): string | undefined =>
|
|
32
32
|
getEnvUniversal("RIVET_RUN_ENGINE_VERSION");
|
|
33
|
+
export const getRivetRunServices = (): boolean =>
|
|
34
|
+
getEnvUniversal("RIVET_RUN_SERVICES") === "1";
|
|
33
35
|
export const getRivetEnvoyKind = (): string | undefined =>
|
|
34
|
-
getEnvUniversal("RIVET_ENVOY_KIND");
|
|
36
|
+
getEnvUniversal("RIVET_NODE_KIND") ?? getEnvUniversal("RIVET_ENVOY_KIND");
|
|
35
37
|
export const getRivetEnvoyVersion = (): number | undefined => {
|
|
36
|
-
|
|
38
|
+
// The legacy platform deployment still sets the old name.
|
|
39
|
+
const value =
|
|
40
|
+
getEnvUniversal("RIVET_NODE_VERSION") ??
|
|
41
|
+
getEnvUniversal("RIVET_ENVOY_VERSION");
|
|
37
42
|
return value !== undefined ? parseInt(value, 10) : undefined;
|
|
38
43
|
};
|
|
39
44
|
export const getRivetPublicEndpoint = (): string | undefined =>
|
|
@@ -50,14 +55,18 @@ export const getRivetkitStoragePath = (): string | undefined =>
|
|
|
50
55
|
getEnvUniversal("RIVETKIT_STORAGE_PATH");
|
|
51
56
|
export const getRivetkitRuntime = (): string | undefined =>
|
|
52
57
|
getEnvUniversal("RIVETKIT_RUNTIME");
|
|
53
|
-
export type RuntimeMode = "
|
|
58
|
+
export type RuntimeMode = "node" | "serverless";
|
|
54
59
|
|
|
55
60
|
export const getRivetkitRuntimeMode = (): RuntimeMode => {
|
|
56
61
|
const value = getEnvUniversal("RIVETKIT_RUNTIME_MODE");
|
|
57
|
-
if (value === undefined) return "
|
|
58
|
-
|
|
62
|
+
if (value === undefined || value === "envoy") return "node";
|
|
63
|
+
// Serverless is disabled for v3.
|
|
64
|
+
if (value === "serverless") {
|
|
65
|
+
throw new Error("serverless is disabled in this version");
|
|
66
|
+
}
|
|
67
|
+
if (value === "node") return value;
|
|
59
68
|
throw new Error(
|
|
60
|
-
`RIVETKIT_RUNTIME_MODE env var must be "
|
|
69
|
+
`RIVETKIT_RUNTIME_MODE env var must be "node" or "serverless"; got "${value}"`,
|
|
61
70
|
);
|
|
62
71
|
};
|
|
63
72
|
|
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/utils.ts
CHANGED
package/src/workflow/context.ts
CHANGED
|
@@ -17,8 +17,8 @@ import type {
|
|
|
17
17
|
QueueNextBatchOptions,
|
|
18
18
|
QueueNextOptions,
|
|
19
19
|
QueueResultMessageForName,
|
|
20
|
+
RunContext,
|
|
20
21
|
} from "@/actor/config";
|
|
21
|
-
import { RAW_STATE_SYMBOL, type RunContext } from "@/actor/config";
|
|
22
22
|
import type {
|
|
23
23
|
AnyActorDefinition,
|
|
24
24
|
BaseActorDefinition,
|
|
@@ -469,7 +469,6 @@ export class WorkflowContext<
|
|
|
469
469
|
TEvents,
|
|
470
470
|
TQueues
|
|
471
471
|
>;
|
|
472
|
-
|
|
473
472
|
constructor(
|
|
474
473
|
inner: WorkflowContextInterface,
|
|
475
474
|
runCtx: RunContext<
|
|
@@ -960,13 +959,17 @@ export class WorkflowContext<
|
|
|
960
959
|
await this.#wrapActive(() => this.#inner.removed(name, originalType));
|
|
961
960
|
}
|
|
962
961
|
|
|
962
|
+
getVersion(name: string, latest: number): Promise<number> {
|
|
963
|
+
return this.#wrapActive(() => this.#inner.getVersion(name, latest));
|
|
964
|
+
}
|
|
965
|
+
|
|
963
966
|
isEvicted(): boolean {
|
|
964
967
|
return this.#inner.isEvicted();
|
|
965
968
|
}
|
|
966
969
|
|
|
967
|
-
// Runs a user step body inside a fresh step context
|
|
968
|
-
//
|
|
969
|
-
//
|
|
970
|
+
// Runs a user step body inside a fresh step context and deactivates the step
|
|
971
|
+
// context once the body settles. Workflows are roll-forward only, so state and
|
|
972
|
+
// vars mutations made before a failure always remain visible.
|
|
970
973
|
async #runStep<T>(
|
|
971
974
|
run: WorkflowStepRun<
|
|
972
975
|
T,
|
|
@@ -991,28 +994,8 @@ export class WorkflowContext<
|
|
|
991
994
|
TQueues
|
|
992
995
|
>(this.#runCtx, () => this.#markGuardTriggered());
|
|
993
996
|
|
|
994
|
-
let stateSnapshot: { state: TState } | null = null;
|
|
995
|
-
try {
|
|
996
|
-
stateSnapshot = { state: this.#runCtx[RAW_STATE_SYMBOL]() };
|
|
997
|
-
} catch (error) {
|
|
998
|
-
this.#runCtx.log.debug({
|
|
999
|
-
msg: "failed to get state, likely due to being stateless workflow",
|
|
1000
|
-
error,
|
|
1001
|
-
});
|
|
1002
|
-
}
|
|
1003
|
-
if (stateSnapshot) {
|
|
1004
|
-
stateSnapshot.state = structuredClone(stateSnapshot.state);
|
|
1005
|
-
}
|
|
1006
|
-
const varsSnapshot = structuredClone(this.#runCtx.vars);
|
|
1007
|
-
|
|
1008
997
|
try {
|
|
1009
998
|
return await run(stepCtx);
|
|
1010
|
-
} catch (error) {
|
|
1011
|
-
if (stateSnapshot) {
|
|
1012
|
-
this.#runCtx.state = stateSnapshot.state;
|
|
1013
|
-
}
|
|
1014
|
-
this.#runCtx.vars = varsSnapshot;
|
|
1015
|
-
throw error;
|
|
1016
999
|
} finally {
|
|
1017
1000
|
stepCtx[DEACTIVATE_STEP]();
|
|
1018
1001
|
}
|
|
@@ -1036,8 +1019,7 @@ export class WorkflowContext<
|
|
|
1036
1019
|
};
|
|
1037
1020
|
}
|
|
1038
1021
|
|
|
1039
|
-
// Runs a step rollback compensation with an active step context.
|
|
1040
|
-
// intentionally mutate actor state, so their writes are not snapshotted.
|
|
1022
|
+
// Runs a step rollback compensation with an active step context.
|
|
1041
1023
|
async #runRollback<T>(
|
|
1042
1024
|
rollback: WorkflowStepRollback<
|
|
1043
1025
|
T,
|