rivetkit 2.3.0-rc.10 → 2.3.0-rc.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 +105 -56
- package/dist/browser/client.js +128 -87
- package/dist/browser/client.js.map +1 -1
- package/dist/browser/inspector/client.js +40 -20
- package/dist/browser/inspector/client.js.map +1 -1
- package/dist/tsup/actor/errors.cjs +2 -2
- package/dist/tsup/actor/errors.js +1 -1
- package/dist/tsup/agent-os/index.cjs +2103 -2090
- package/dist/tsup/agent-os/index.cjs.map +1 -1
- package/dist/tsup/agent-os/index.d.cts +106 -66
- package/dist/tsup/agent-os/index.d.ts +106 -66
- package/dist/tsup/agent-os/index.js +2102 -2089
- package/dist/tsup/agent-os/index.js.map +1 -1
- package/dist/tsup/{chunk-4K3MV2MW.cjs → chunk-2NXFKPRB.cjs} +10 -10
- package/dist/tsup/chunk-2NXFKPRB.cjs.map +1 -0
- package/dist/tsup/{chunk-6BI2MS3S.js → chunk-3P2JUHWJ.js} +2 -2
- package/dist/tsup/{chunk-KU6VKVEK.js → chunk-4FP4FFB5.js} +18 -6
- package/dist/tsup/chunk-4FP4FFB5.js.map +1 -0
- package/dist/tsup/{chunk-KIWH5H3K.js → chunk-BRP62GZC.js} +3 -3
- package/dist/tsup/chunk-BRP62GZC.js.map +1 -0
- package/dist/tsup/{chunk-G34LIR7S.js → chunk-GRFBV2U7.js} +22 -7
- package/dist/tsup/chunk-GRFBV2U7.js.map +1 -0
- package/dist/tsup/{chunk-PWFGP2US.cjs → chunk-GX6W4MW3.cjs} +138 -24
- package/dist/tsup/chunk-GX6W4MW3.cjs.map +1 -0
- package/dist/tsup/{chunk-3YY5S6TV.js → chunk-HXUEHHJF.js} +2 -2
- package/dist/tsup/chunk-HXUEHHJF.js.map +1 -0
- package/dist/tsup/{chunk-PCBNKI2J.js → chunk-JZ7TWV65.js} +1 -1
- package/dist/tsup/chunk-JZ7TWV65.js.map +1 -0
- package/dist/tsup/{chunk-QAZLM4WT.cjs → chunk-KORQB2IR.cjs} +3 -3
- package/dist/tsup/{chunk-QAZLM4WT.cjs.map → chunk-KORQB2IR.cjs.map} +1 -1
- package/dist/tsup/{chunk-BM3EOY7M.js → chunk-KRC4L3YB.js} +134 -20
- package/dist/tsup/chunk-KRC4L3YB.js.map +1 -0
- package/dist/tsup/{chunk-G5RULGYQ.cjs → chunk-LNP7Q6I6.cjs} +24 -9
- package/dist/tsup/chunk-LNP7Q6I6.cjs.map +1 -0
- package/dist/tsup/{chunk-Z4C3W2CQ.cjs → chunk-LW5HNCWD.cjs} +3 -3
- package/dist/tsup/{chunk-Z4C3W2CQ.cjs.map → chunk-LW5HNCWD.cjs.map} +1 -1
- package/dist/tsup/{chunk-J5P6S2LC.cjs → chunk-RDBGKI66.cjs} +25 -13
- package/dist/tsup/chunk-RDBGKI66.cjs.map +1 -0
- package/dist/tsup/{chunk-T6YVRM4K.js → chunk-T3VCJ4PV.js} +3 -1
- package/dist/tsup/chunk-T3VCJ4PV.js.map +1 -0
- package/dist/tsup/{chunk-WU2O2KIE.js → chunk-TTLUIDVH.js} +61 -77
- package/dist/tsup/chunk-TTLUIDVH.js.map +1 -0
- package/dist/tsup/{chunk-LD5YASJU.cjs → chunk-VE2X4KMG.cjs} +2 -2
- package/dist/tsup/{chunk-LD5YASJU.cjs.map → chunk-VE2X4KMG.cjs.map} +1 -1
- package/dist/tsup/{chunk-XV52XUWU.js → chunk-WXYWDLJY.js} +4 -4
- package/dist/tsup/chunk-WXYWDLJY.js.map +1 -0
- package/dist/tsup/{chunk-WQ4HNA4W.cjs → chunk-XCDCURZ4.cjs} +4 -2
- package/dist/tsup/chunk-XCDCURZ4.cjs.map +1 -0
- package/dist/tsup/{chunk-TE4VCDNY.cjs → chunk-XG25CGSW.cjs} +217 -233
- package/dist/tsup/chunk-XG25CGSW.cjs.map +1 -0
- package/dist/tsup/{chunk-3LGP4JSO.cjs → chunk-Y3JBOFBG.cjs} +8 -8
- package/dist/tsup/{chunk-3LGP4JSO.cjs.map → chunk-Y3JBOFBG.cjs.map} +1 -1
- package/dist/tsup/{chunk-CMYS77J6.js → chunk-YRQ4F5CD.js} +3 -3
- package/dist/tsup/{chunk-2NDZ7JCR.cjs → chunk-ZA7FLHKH.cjs} +1 -1
- package/dist/tsup/chunk-ZA7FLHKH.cjs.map +1 -0
- package/dist/tsup/client/mod.cjs +9 -9
- package/dist/tsup/client/mod.d.cts +4 -4
- package/dist/tsup/client/mod.d.ts +4 -4
- package/dist/tsup/client/mod.js +8 -8
- package/dist/tsup/common/log.cjs +3 -3
- package/dist/tsup/common/log.js +2 -2
- package/dist/tsup/common/websocket.cjs +4 -4
- package/dist/tsup/common/websocket.js +3 -3
- package/dist/tsup/{config-Ca8dN4cS.d.cts → config-CTwe3WwC.d.cts} +69 -19
- package/dist/tsup/{config-CxjGYf4K.d.cts → config-D49x8NpL.d.cts} +1 -2
- package/dist/tsup/{config-CxjGYf4K.d.ts → config-D49x8NpL.d.ts} +1 -2
- package/dist/tsup/{config-0Ta55UV0.d.ts → config-De5UVu0V.d.ts} +69 -19
- package/dist/tsup/{context-B_IWbWne.d.ts → context-DPHISlUi.d.ts} +8 -8
- package/dist/tsup/{context-CUrQ9MHc.d.cts → context-Dmj477Uh.d.cts} +8 -8
- package/dist/tsup/db/drizzle.cjs +3 -3
- package/dist/tsup/db/drizzle.d.cts +1 -1
- package/dist/tsup/db/drizzle.d.ts +1 -1
- package/dist/tsup/db/drizzle.js +1 -1
- package/dist/tsup/db/mod.cjs +2 -2
- package/dist/tsup/db/mod.d.cts +2 -2
- package/dist/tsup/db/mod.d.ts +2 -2
- package/dist/tsup/db/mod.js +1 -1
- package/dist/tsup/dynamic/mod.cjs +24 -0
- package/dist/tsup/dynamic/mod.cjs.map +1 -0
- package/dist/tsup/dynamic/mod.d.cts +37 -0
- package/dist/tsup/dynamic/mod.d.ts +37 -0
- package/dist/tsup/dynamic/mod.js +24 -0
- package/dist/tsup/dynamic/mod.js.map +1 -0
- package/dist/tsup/inspector/mod.cjs +6 -6
- package/dist/tsup/inspector/mod.js +5 -5
- package/dist/tsup/mod.cjs +501 -315
- package/dist/tsup/mod.cjs.map +1 -1
- package/dist/tsup/mod.d.cts +4 -4
- package/dist/tsup/mod.d.ts +4 -4
- package/dist/tsup/mod.js +405 -219
- package/dist/tsup/mod.js.map +1 -1
- package/dist/tsup/test/mod.cjs +21 -18
- package/dist/tsup/test/mod.cjs.map +1 -1
- package/dist/tsup/test/mod.d.cts +3 -3
- package/dist/tsup/test/mod.d.ts +3 -3
- package/dist/tsup/test/mod.js +18 -15
- package/dist/tsup/test/mod.js.map +1 -1
- package/dist/tsup/utils.cjs +3 -3
- package/dist/tsup/utils.d.cts +1 -1
- package/dist/tsup/utils.d.ts +1 -1
- package/dist/tsup/utils.js +2 -2
- package/dist/tsup/workflow/mod.cjs +307 -282
- package/dist/tsup/workflow/mod.cjs.map +1 -1
- package/dist/tsup/workflow/mod.d.cts +5 -5
- package/dist/tsup/workflow/mod.d.ts +5 -5
- package/dist/tsup/workflow/mod.js +501 -476
- package/dist/tsup/workflow/mod.js.map +1 -1
- package/package.json +22 -11
- package/src/actor/config.ts +48 -41
- package/src/actor/contexts/index.ts +7 -2
- package/src/actor/definition.ts +11 -14
- package/src/actor/driver.ts +3 -3
- package/src/actor/errors.ts +9 -3
- package/src/actor/instance/mod.ts +22 -30
- package/src/actor/keys.ts +1 -1
- package/src/actor/mod.ts +20 -20
- package/src/actor/schema.ts +2 -2
- package/src/agent-os/actor/index.ts +38 -18
- package/src/agent-os/actor/preview.ts +1 -2
- package/src/agent-os/actor/session.ts +2 -2
- package/src/agent-os/config.ts +1 -1
- package/src/agent-os/fs/database-vfs.ts +1 -1
- package/src/agent-os/index.ts +16 -15
- package/src/client/actor-common.ts +90 -54
- package/src/client/actor-conn.ts +8 -36
- package/src/client/actor-handle.ts +67 -50
- package/src/client/actor-query.ts +5 -5
- package/src/client/errors.ts +1 -1
- package/src/client/lifecycle-errors.ts +2 -4
- package/src/client/query.ts +1 -1
- package/src/client/queue.ts +8 -3
- package/src/client/raw-utils.ts +8 -6
- package/src/client/resolve-gateway-target.ts +1 -1
- package/src/client/utils.ts +2 -7
- package/src/common/actor-websocket.ts +3 -1
- package/src/common/bare/actor-persist/v1.ts +205 -163
- package/src/common/bare/actor-persist/v2.ts +265 -213
- package/src/common/bare/actor-persist/v3.ts +176 -172
- package/src/common/bare/actor-persist/v4.ts +254 -253
- package/src/common/bare/transport/v1.ts +659 -543
- package/src/common/client-protocol-versioned.ts +66 -64
- package/src/common/database/config.ts +2 -8
- package/src/common/database/native-database.ts +1 -1
- package/src/common/database/shared.ts +1 -0
- package/src/common/encoding.ts +250 -16
- package/src/common/eventsource.ts +1 -1
- package/src/common/inline-websocket-adapter.ts +14 -13
- package/src/common/log.ts +1 -0
- package/src/common/router.ts +13 -17
- package/src/common/utils.ts +0 -149
- package/src/common/websocket-interface.ts +1 -1
- package/src/db/mod.ts +1 -1
- package/src/drivers/engine/actor-driver.ts +63 -72
- package/src/dynamic/instance.ts +32 -0
- package/src/dynamic/internal.ts +50 -0
- package/src/dynamic/isolate-runtime.ts +66 -0
- package/src/dynamic/mod.ts +32 -0
- package/src/engine-client/actor-http-client.ts +1 -1
- package/src/engine-client/actor-websocket-client.ts +6 -5
- package/src/engine-client/api-endpoints.ts +47 -2
- package/src/engine-client/api-utils.ts +2 -2
- package/src/engine-client/driver.ts +1 -1
- package/src/engine-client/mod.ts +6 -3
- package/src/engine-client/ws-proxy.ts +4 -4
- package/src/inspector/client.browser.ts +5 -11
- package/src/inspector/mod.ts +1 -3
- package/src/registry/config/envoy.ts +1 -2
- package/src/registry/config/index.ts +7 -7
- package/src/registry/index.ts +70 -71
- package/src/registry/napi-runtime.ts +7 -2
- package/src/registry/native-validation.ts +10 -12
- package/src/registry/native.ts +179 -153
- package/src/registry/process-metrics.ts +238 -0
- package/src/registry/runtime.ts +1 -3
- package/src/registry/wasm-runtime.ts +3 -2
- package/src/registry/write-through-proxy.ts +40 -0
- package/src/serde.ts +2 -2
- package/src/serverless/configure.ts +18 -7
- package/src/test/mod.ts +11 -8
- package/src/utils/endpoint-parser.ts +1 -1
- package/src/utils/router.ts +1 -1
- package/src/utils/serve.ts +4 -5
- package/src/utils.ts +1 -2
- package/src/workflow/context.ts +61 -33
- package/src/workflow/driver.ts +4 -6
- package/src/workflow/inspector.ts +4 -3
- package/src/workflow/mod.ts +15 -17
- package/dist/tsup/chunk-2NDZ7JCR.cjs.map +0 -1
- package/dist/tsup/chunk-3YY5S6TV.js.map +0 -1
- package/dist/tsup/chunk-4K3MV2MW.cjs.map +0 -1
- package/dist/tsup/chunk-BM3EOY7M.js.map +0 -1
- package/dist/tsup/chunk-G34LIR7S.js.map +0 -1
- package/dist/tsup/chunk-G5RULGYQ.cjs.map +0 -1
- package/dist/tsup/chunk-J5P6S2LC.cjs.map +0 -1
- package/dist/tsup/chunk-KIWH5H3K.js.map +0 -1
- package/dist/tsup/chunk-KU6VKVEK.js.map +0 -1
- package/dist/tsup/chunk-PCBNKI2J.js.map +0 -1
- package/dist/tsup/chunk-PWFGP2US.cjs.map +0 -1
- package/dist/tsup/chunk-T6YVRM4K.js.map +0 -1
- package/dist/tsup/chunk-TE4VCDNY.cjs.map +0 -1
- package/dist/tsup/chunk-WQ4HNA4W.cjs.map +0 -1
- package/dist/tsup/chunk-WU2O2KIE.js.map +0 -1
- package/dist/tsup/chunk-XV52XUWU.js.map +0 -1
- /package/dist/tsup/{chunk-6BI2MS3S.js.map → chunk-3P2JUHWJ.js.map} +0 -0
- /package/dist/tsup/{chunk-CMYS77J6.js.map → chunk-YRQ4F5CD.js.map} +0 -0
package/src/common/utils.ts
CHANGED
|
@@ -36,155 +36,6 @@ export function safeStringify(obj: unknown, maxSize: number) {
|
|
|
36
36
|
return JSON.stringify(obj, replacer);
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
// TODO: Instead of doing this, use a temp var for state and attempt to write
|
|
40
|
-
// it. Roll back state if fails to serialize.
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Check if a value is CBOR serializable.
|
|
44
|
-
* Optionally pass an onInvalid callback to receive the path to invalid values.
|
|
45
|
-
*
|
|
46
|
-
* For a complete list of supported CBOR tags, see:
|
|
47
|
-
* https://github.com/kriszyp/cbor-x/blob/cc1cf9df8ba72288c7842af1dd374d73e34cdbc1/README.md#list-of-supported-tags-for-decoding
|
|
48
|
-
*/
|
|
49
|
-
export function isCborSerializable(
|
|
50
|
-
value: unknown,
|
|
51
|
-
onInvalid?: (path: string) => void,
|
|
52
|
-
currentPath = "",
|
|
53
|
-
): boolean {
|
|
54
|
-
// Handle primitive types directly
|
|
55
|
-
if (value === null || value === undefined) {
|
|
56
|
-
return true;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (typeof value === "number") {
|
|
60
|
-
if (!Number.isFinite(value)) {
|
|
61
|
-
onInvalid?.(currentPath);
|
|
62
|
-
return false;
|
|
63
|
-
}
|
|
64
|
-
return true;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (typeof value === "boolean" || typeof value === "string") {
|
|
68
|
-
return true;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// Handle BigInt (CBOR tags 2 and 3)
|
|
72
|
-
if (typeof value === "bigint") {
|
|
73
|
-
return true;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// Handle Date objects (CBOR tags 0 and 1)
|
|
77
|
-
if (value instanceof Date) {
|
|
78
|
-
return true;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// Handle typed arrays (CBOR tags 64-82)
|
|
82
|
-
if (
|
|
83
|
-
value instanceof Uint8Array ||
|
|
84
|
-
value instanceof Uint8ClampedArray ||
|
|
85
|
-
value instanceof Uint16Array ||
|
|
86
|
-
value instanceof Uint32Array ||
|
|
87
|
-
value instanceof BigUint64Array ||
|
|
88
|
-
value instanceof Int8Array ||
|
|
89
|
-
value instanceof Int16Array ||
|
|
90
|
-
value instanceof Int32Array ||
|
|
91
|
-
value instanceof BigInt64Array ||
|
|
92
|
-
value instanceof Float32Array ||
|
|
93
|
-
value instanceof Float64Array
|
|
94
|
-
) {
|
|
95
|
-
return true;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// Handle Map (CBOR tag 259)
|
|
99
|
-
if (value instanceof Map) {
|
|
100
|
-
for (const [key, val] of value.entries()) {
|
|
101
|
-
const keyPath = currentPath
|
|
102
|
-
? `${currentPath}.key(${String(key)})`
|
|
103
|
-
: `key(${String(key)})`;
|
|
104
|
-
const valPath = currentPath
|
|
105
|
-
? `${currentPath}.value(${String(key)})`
|
|
106
|
-
: `value(${String(key)})`;
|
|
107
|
-
if (
|
|
108
|
-
!isCborSerializable(key, onInvalid, keyPath) ||
|
|
109
|
-
!isCborSerializable(val, onInvalid, valPath)
|
|
110
|
-
) {
|
|
111
|
-
return false;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
return true;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// Handle Set (CBOR tag 258)
|
|
118
|
-
if (value instanceof Set) {
|
|
119
|
-
let index = 0;
|
|
120
|
-
for (const item of value.values()) {
|
|
121
|
-
const itemPath = currentPath
|
|
122
|
-
? `${currentPath}.set[${index}]`
|
|
123
|
-
: `set[${index}]`;
|
|
124
|
-
if (!isCborSerializable(item, onInvalid, itemPath)) {
|
|
125
|
-
return false;
|
|
126
|
-
}
|
|
127
|
-
index++;
|
|
128
|
-
}
|
|
129
|
-
return true;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// Handle RegExp (CBOR tag 27)
|
|
133
|
-
if (value instanceof RegExp) {
|
|
134
|
-
return true;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
// Handle Error objects (CBOR tag 27)
|
|
138
|
-
if (value instanceof Error) {
|
|
139
|
-
return true;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
// Handle arrays
|
|
143
|
-
if (Array.isArray(value)) {
|
|
144
|
-
for (let i = 0; i < value.length; i++) {
|
|
145
|
-
const itemPath = currentPath ? `${currentPath}[${i}]` : `[${i}]`;
|
|
146
|
-
if (!isCborSerializable(value[i], onInvalid, itemPath)) {
|
|
147
|
-
return false;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
return true;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// Handle plain objects and records (CBOR tags 105, 51, 57344-57599)
|
|
154
|
-
if (typeof value === "object") {
|
|
155
|
-
// Allow plain objects and objects with prototypes (for records and named objects)
|
|
156
|
-
const proto = Object.getPrototypeOf(value);
|
|
157
|
-
if (proto !== null && proto !== Object.prototype) {
|
|
158
|
-
// Check if it's a known serializable object type
|
|
159
|
-
const protoConstructor = value.constructor;
|
|
160
|
-
if (protoConstructor && typeof protoConstructor.name === "string") {
|
|
161
|
-
// Allow objects with named constructors (records, named objects)
|
|
162
|
-
// This includes user-defined classes and built-in objects
|
|
163
|
-
// that CBOR can serialize with tag 27 or record tags
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
// Check all properties recursively
|
|
168
|
-
for (const key in value) {
|
|
169
|
-
const propPath = currentPath ? `${currentPath}.${key}` : key;
|
|
170
|
-
if (
|
|
171
|
-
!isCborSerializable(
|
|
172
|
-
value[key as keyof typeof value],
|
|
173
|
-
onInvalid,
|
|
174
|
-
propPath,
|
|
175
|
-
)
|
|
176
|
-
) {
|
|
177
|
-
return false;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
return true;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
// Not serializable
|
|
184
|
-
onInvalid?.(currentPath);
|
|
185
|
-
return false;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
39
|
export interface DeconstructedError {
|
|
189
40
|
__type: "ActorError";
|
|
190
41
|
statusCode: ContentfulStatusCode;
|
package/src/db/mod.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export { db } from "@/common/database/mod";
|
|
2
1
|
export type {
|
|
3
2
|
AnyDatabaseProvider,
|
|
4
3
|
DatabaseProvider,
|
|
@@ -11,3 +10,4 @@ export type {
|
|
|
11
10
|
SqliteNativeMetrics,
|
|
12
11
|
SqliteQueryResult,
|
|
13
12
|
} from "@/common/database/config";
|
|
13
|
+
export { db } from "@/common/database/mod";
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { EnvoyConfig } from "@rivetkit/rivetkit-native/wrapper";
|
|
2
2
|
import {
|
|
3
|
-
type HibernatingWebSocketMetadata,
|
|
4
3
|
type EnvoyHandle,
|
|
4
|
+
type HibernatingWebSocketMetadata,
|
|
5
5
|
openDatabaseFromEnvoy,
|
|
6
|
-
protocol,
|
|
6
|
+
type protocol,
|
|
7
7
|
startEnvoySync,
|
|
8
8
|
} from "@rivetkit/rivetkit-native/wrapper";
|
|
9
9
|
import * as cbor from "cbor-x";
|
|
@@ -11,17 +11,19 @@ import type { Context as HonoContext } from "hono";
|
|
|
11
11
|
import { streamSSE } from "hono/streaming";
|
|
12
12
|
import { WSContext, type WSContextInit } from "hono/ws";
|
|
13
13
|
import invariant from "invariant";
|
|
14
|
-
import {
|
|
14
|
+
import { CONN_STATE_MANAGER_SYMBOL } from "@/actor/conn/mod";
|
|
15
15
|
import { isStaticActorDefinition, lookupInRegistry } from "@/actor/definition";
|
|
16
|
+
import type { ActorDriver } from "@/actor/driver";
|
|
17
|
+
import { KEYS } from "@/actor/instance/keys";
|
|
18
|
+
import type { AnyActorInstance } from "@/actor/instance/mod";
|
|
16
19
|
import {
|
|
17
|
-
isStaticActorInstance,
|
|
18
20
|
type AnyStaticActorInstance,
|
|
21
|
+
isStaticActorInstance,
|
|
19
22
|
} from "@/actor/instance/mod";
|
|
20
|
-
import { KEYS } from "@/actor/instance/keys";
|
|
21
23
|
import {
|
|
22
|
-
type PreloadMap,
|
|
23
24
|
compareBytes,
|
|
24
25
|
createPreloadMap,
|
|
26
|
+
type PreloadMap,
|
|
25
27
|
} from "@/actor/instance/preload-map";
|
|
26
28
|
import { deserializeActorKey } from "@/actor/keys";
|
|
27
29
|
import type { Encoding } from "@/actor/protocol/serde";
|
|
@@ -41,6 +43,10 @@ import {
|
|
|
41
43
|
} from "@/common/actor-router-consts";
|
|
42
44
|
import { getLogger } from "@/common/log";
|
|
43
45
|
import { deconstructError } from "@/common/utils";
|
|
46
|
+
import type {
|
|
47
|
+
RivetMessageEvent,
|
|
48
|
+
UniversalWebSocket,
|
|
49
|
+
} from "@/common/websocket-interface";
|
|
44
50
|
import {
|
|
45
51
|
buildHibernatableWebSocketAckStateTestResponse,
|
|
46
52
|
type IndexedWebSocketPayload,
|
|
@@ -49,21 +55,19 @@ import {
|
|
|
49
55
|
setHibernatableWebSocketAckTestHooks,
|
|
50
56
|
unregisterRemoteHibernatableWebSocketAckHooks,
|
|
51
57
|
} from "@/common/websocket-test-hooks";
|
|
52
|
-
import type {
|
|
53
|
-
RivetMessageEvent,
|
|
54
|
-
UniversalWebSocket,
|
|
55
|
-
} from "@/common/websocket-interface";
|
|
56
|
-
import type { ActorDriver } from "@/actor/driver";
|
|
57
|
-
import type { AnyActorInstance } from "@/actor/instance/mod";
|
|
58
58
|
import {
|
|
59
|
-
|
|
59
|
+
type JsNativeDatabaseLike,
|
|
60
|
+
wrapJsNativeDatabase,
|
|
61
|
+
} from "@/db/native-database";
|
|
62
|
+
import {
|
|
60
63
|
type EngineControlClient,
|
|
64
|
+
getInitialActorKvState,
|
|
61
65
|
} from "@/driver-helpers/mod";
|
|
62
66
|
import { DynamicActorInstance } from "@/dynamic/instance";
|
|
63
|
-
import { DynamicActorIsolateRuntime } from "@/dynamic/isolate-runtime";
|
|
64
67
|
import { isDynamicActorDefinition } from "@/dynamic/internal";
|
|
65
|
-
import {
|
|
68
|
+
import { DynamicActorIsolateRuntime } from "@/dynamic/isolate-runtime";
|
|
66
69
|
import { getEndpoint } from "@/engine-client/api-utils";
|
|
70
|
+
import { buildActorNames, type RegistryConfig } from "@/registry/config";
|
|
67
71
|
import {
|
|
68
72
|
type LongTimeoutHandle,
|
|
69
73
|
promiseWithResolvers,
|
|
@@ -71,14 +75,10 @@ import {
|
|
|
71
75
|
stringifyError,
|
|
72
76
|
VERSION,
|
|
73
77
|
} from "@/utils";
|
|
74
|
-
import {
|
|
75
|
-
wrapJsNativeDatabase,
|
|
76
|
-
type JsNativeDatabaseLike,
|
|
77
|
-
} from "@/db/native-database";
|
|
78
78
|
import { logger } from "./log";
|
|
79
79
|
|
|
80
80
|
const ENVOY_SSE_PING_INTERVAL = 1000;
|
|
81
|
-
const
|
|
81
|
+
const ENVOY_STOP_WAIT_MS = 15_000;
|
|
82
82
|
const INITIAL_SLEEP_TIMEOUT_MS = 250;
|
|
83
83
|
const REMOTE_ACK_HOOK_QUERY_PARAM = "__rivetkitAckHook";
|
|
84
84
|
|
|
@@ -88,13 +88,13 @@ const REMOTE_ACK_HOOK_QUERY_PARAM = "__rivetkitAckHook";
|
|
|
88
88
|
//
|
|
89
89
|
// See engine/packages/pegboard-gateway/src/shared_state.rs
|
|
90
90
|
// (HWS_MESSAGE_ACK_TIMEOUT)
|
|
91
|
-
const
|
|
91
|
+
const _CONN_MESSAGE_ACK_DEADLINE = 5_000;
|
|
92
92
|
|
|
93
93
|
// Force saveState when cumulative message size reaches this threshold (0.5 MB)
|
|
94
94
|
//
|
|
95
95
|
// See engine/packages/pegboard-gateway/src/shared_state.rs
|
|
96
96
|
// (HWS_MAX_PENDING_MSGS_SIZE_PER_REQ)
|
|
97
|
-
const
|
|
97
|
+
const _CONN_BUFFERED_MESSAGE_SIZE_THRESHOLD = 500_000;
|
|
98
98
|
|
|
99
99
|
interface ActorHandler {
|
|
100
100
|
actor?: AnyActorInstance;
|
|
@@ -144,7 +144,6 @@ export type DriverContext = {};
|
|
|
144
144
|
|
|
145
145
|
export class EngineActorDriver implements ActorDriver {
|
|
146
146
|
#config: RegistryConfig;
|
|
147
|
-
#engineClient: EngineControlClient;
|
|
148
147
|
#inlineClient: Client<any>;
|
|
149
148
|
#envoy: EnvoyHandle;
|
|
150
149
|
#actors: Map<string, ActorHandler> = new Map();
|
|
@@ -161,15 +160,6 @@ export class EngineActorDriver implements ActorDriver {
|
|
|
161
160
|
string,
|
|
162
161
|
HibernatableRunnerWebSocketBinding
|
|
163
162
|
>();
|
|
164
|
-
#hwsMessageIndex = new Map<
|
|
165
|
-
string,
|
|
166
|
-
{
|
|
167
|
-
serverMessageIndex: number;
|
|
168
|
-
bufferedMessageSize: number;
|
|
169
|
-
pendingAckFromMessageIndex: boolean;
|
|
170
|
-
pendingAckFromBufferSize: boolean;
|
|
171
|
-
}
|
|
172
|
-
>();
|
|
173
163
|
#actorRouter: ActorRouter;
|
|
174
164
|
|
|
175
165
|
#envoyStarted: PromiseWithResolvers<void> = promiseWithResolvers((reason) =>
|
|
@@ -284,7 +274,7 @@ export class EngineActorDriver implements ActorDriver {
|
|
|
284
274
|
logger().debug({
|
|
285
275
|
msg: "actor crash cleanup errored",
|
|
286
276
|
actorId,
|
|
287
|
-
|
|
277
|
+
error: stringifyError(err),
|
|
288
278
|
});
|
|
289
279
|
}
|
|
290
280
|
}
|
|
@@ -376,8 +366,7 @@ export class EngineActorDriver implements ActorDriver {
|
|
|
376
366
|
requestId: ArrayBuffer,
|
|
377
367
|
): void {
|
|
378
368
|
const key = this.#hibernatableWebSocketAckKey(gatewayId, requestId);
|
|
379
|
-
const binding =
|
|
380
|
-
this.#hibernatableRunnerWebSocketBindings.get(key);
|
|
369
|
+
const binding = this.#hibernatableRunnerWebSocketBindings.get(key);
|
|
381
370
|
if (!binding) {
|
|
382
371
|
return;
|
|
383
372
|
}
|
|
@@ -397,8 +386,7 @@ export class EngineActorDriver implements ActorDriver {
|
|
|
397
386
|
requestId: ArrayBuffer,
|
|
398
387
|
): void {
|
|
399
388
|
const key = this.#hibernatableWebSocketAckKey(gatewayId, requestId);
|
|
400
|
-
const binding =
|
|
401
|
-
this.#hibernatableRunnerWebSocketBindings.get(key);
|
|
389
|
+
const binding = this.#hibernatableRunnerWebSocketBindings.get(key);
|
|
402
390
|
binding?.detach?.();
|
|
403
391
|
this.#hibernatableRunnerWebSocketBindings.delete(key);
|
|
404
392
|
}
|
|
@@ -585,7 +573,7 @@ export class EngineActorDriver implements ActorDriver {
|
|
|
585
573
|
return handler;
|
|
586
574
|
}
|
|
587
575
|
|
|
588
|
-
getContext(
|
|
576
|
+
getContext(_actorId: string): DriverContext {
|
|
589
577
|
return {};
|
|
590
578
|
}
|
|
591
579
|
|
|
@@ -847,7 +835,6 @@ export class EngineActorDriver implements ActorDriver {
|
|
|
847
835
|
return;
|
|
848
836
|
}
|
|
849
837
|
this.#isShuttingDown = true;
|
|
850
|
-
const envoyStopWaitMs = this.#envoyStopWaitMs();
|
|
851
838
|
|
|
852
839
|
logger().info({ msg: "stopping engine actor driver", immediate });
|
|
853
840
|
if (!immediate) {
|
|
@@ -862,7 +849,7 @@ export class EngineActorDriver implements ActorDriver {
|
|
|
862
849
|
this.startSleep(actorId);
|
|
863
850
|
}
|
|
864
851
|
|
|
865
|
-
const actorSleepDeadline = Date.now() +
|
|
852
|
+
const actorSleepDeadline = Date.now() + ENVOY_STOP_WAIT_MS;
|
|
866
853
|
while (this.#actors.size > 0 && Date.now() < actorSleepDeadline) {
|
|
867
854
|
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
868
855
|
}
|
|
@@ -871,7 +858,7 @@ export class EngineActorDriver implements ActorDriver {
|
|
|
871
858
|
logger().warn({
|
|
872
859
|
msg: "timed out waiting for actors to stop before envoy drain",
|
|
873
860
|
remainingActors: this.#actors.size,
|
|
874
|
-
waitMs:
|
|
861
|
+
waitMs: ENVOY_STOP_WAIT_MS,
|
|
875
862
|
});
|
|
876
863
|
// Snapshot so concurrent removals from `stopActor` do not
|
|
877
864
|
// invalidate the iterator.
|
|
@@ -913,13 +900,13 @@ export class EngineActorDriver implements ActorDriver {
|
|
|
913
900
|
const stopped = await Promise.race([
|
|
914
901
|
this.#envoyStopped.promise.then(() => true),
|
|
915
902
|
new Promise<false>((resolve) =>
|
|
916
|
-
setTimeout(() => resolve(false),
|
|
903
|
+
setTimeout(() => resolve(false), ENVOY_STOP_WAIT_MS),
|
|
917
904
|
),
|
|
918
905
|
]);
|
|
919
906
|
if (!stopped) {
|
|
920
907
|
logger().warn({
|
|
921
908
|
msg: "timed out waiting for envoy shutdown",
|
|
922
|
-
waitMs:
|
|
909
|
+
waitMs: ENVOY_STOP_WAIT_MS,
|
|
923
910
|
});
|
|
924
911
|
}
|
|
925
912
|
|
|
@@ -930,16 +917,6 @@ export class EngineActorDriver implements ActorDriver {
|
|
|
930
917
|
await this.#envoy.started();
|
|
931
918
|
}
|
|
932
919
|
|
|
933
|
-
#envoyStopWaitMs(): number {
|
|
934
|
-
const actorStopThreshold = Number(
|
|
935
|
-
this.#envoy.getProtocolMetadata()?.actorStopThreshold,
|
|
936
|
-
);
|
|
937
|
-
if (Number.isFinite(actorStopThreshold) && actorStopThreshold > 0) {
|
|
938
|
-
return actorStopThreshold;
|
|
939
|
-
}
|
|
940
|
-
return FALLBACK_ENVOY_STOP_WAIT_MS;
|
|
941
|
-
}
|
|
942
|
-
|
|
943
920
|
async #bindHibernatableConnectSocket(
|
|
944
921
|
binding: HibernatableConnectBinding,
|
|
945
922
|
isRestoringHibernatable: boolean,
|
|
@@ -1140,7 +1117,10 @@ export class EngineActorDriver implements ActorDriver {
|
|
|
1140
1117
|
actorId: binding.actorId,
|
|
1141
1118
|
error: stringifyError(error),
|
|
1142
1119
|
});
|
|
1143
|
-
binding.websocket.close(
|
|
1120
|
+
binding.websocket.close(
|
|
1121
|
+
1011,
|
|
1122
|
+
"dynamic.websocket_forward_failed",
|
|
1123
|
+
);
|
|
1144
1124
|
});
|
|
1145
1125
|
};
|
|
1146
1126
|
const onClose = (event: CloseEvent) => {
|
|
@@ -1270,7 +1250,10 @@ export class EngineActorDriver implements ActorDriver {
|
|
|
1270
1250
|
msg: "dynamic runtime websocket binding is missing after restore",
|
|
1271
1251
|
actorId: binding.actorId,
|
|
1272
1252
|
});
|
|
1273
|
-
binding.websocket.close(
|
|
1253
|
+
binding.websocket.close(
|
|
1254
|
+
1011,
|
|
1255
|
+
"dynamic.websocket_forward_failed",
|
|
1256
|
+
);
|
|
1274
1257
|
return;
|
|
1275
1258
|
}
|
|
1276
1259
|
|
|
@@ -1286,7 +1269,10 @@ export class EngineActorDriver implements ActorDriver {
|
|
|
1286
1269
|
actorId: binding.actorId,
|
|
1287
1270
|
error: stringifyError(error),
|
|
1288
1271
|
});
|
|
1289
|
-
binding.websocket.close(
|
|
1272
|
+
binding.websocket.close(
|
|
1273
|
+
1011,
|
|
1274
|
+
"dynamic.websocket_forward_failed",
|
|
1275
|
+
);
|
|
1290
1276
|
});
|
|
1291
1277
|
};
|
|
1292
1278
|
const onClose = (event: CloseEvent) => {
|
|
@@ -1357,7 +1343,7 @@ export class EngineActorDriver implements ActorDriver {
|
|
|
1357
1343
|
logger().warn({
|
|
1358
1344
|
msg: "failed to rebind dynamic hibernatable runner websocket",
|
|
1359
1345
|
actorId,
|
|
1360
|
-
|
|
1346
|
+
error: stringifyError(result.reason),
|
|
1361
1347
|
});
|
|
1362
1348
|
}
|
|
1363
1349
|
}
|
|
@@ -1380,7 +1366,7 @@ export class EngineActorDriver implements ActorDriver {
|
|
|
1380
1366
|
logger().warn({
|
|
1381
1367
|
msg: "failed to rebind hibernatable connect socket",
|
|
1382
1368
|
actorId,
|
|
1383
|
-
|
|
1369
|
+
error: stringifyError(result.reason),
|
|
1384
1370
|
});
|
|
1385
1371
|
}
|
|
1386
1372
|
}
|
|
@@ -1640,7 +1626,7 @@ export class EngineActorDriver implements ActorDriver {
|
|
|
1640
1626
|
logger().warn({
|
|
1641
1627
|
msg: "failed to restore dynamic hibernating requests after actor start",
|
|
1642
1628
|
actorId,
|
|
1643
|
-
|
|
1629
|
+
error: stringifyError(error),
|
|
1644
1630
|
});
|
|
1645
1631
|
}
|
|
1646
1632
|
} else if (isStaticActorDefinition(definition)) {
|
|
@@ -1707,7 +1693,7 @@ export class EngineActorDriver implements ActorDriver {
|
|
|
1707
1693
|
logger().debug({
|
|
1708
1694
|
msg: "failed to dispose dynamic runtime after actor start failure",
|
|
1709
1695
|
actorId,
|
|
1710
|
-
|
|
1696
|
+
error: stringifyError(disposeError),
|
|
1711
1697
|
});
|
|
1712
1698
|
}
|
|
1713
1699
|
this.#dynamicRuntimes.delete(actorId);
|
|
@@ -1730,7 +1716,7 @@ export class EngineActorDriver implements ActorDriver {
|
|
|
1730
1716
|
actorId,
|
|
1731
1717
|
name,
|
|
1732
1718
|
key,
|
|
1733
|
-
|
|
1719
|
+
error: stringifyError(error),
|
|
1734
1720
|
});
|
|
1735
1721
|
|
|
1736
1722
|
try {
|
|
@@ -1739,7 +1725,7 @@ export class EngineActorDriver implements ActorDriver {
|
|
|
1739
1725
|
logger().debug({
|
|
1740
1726
|
msg: "failed to stop actor after start failure",
|
|
1741
1727
|
actorId,
|
|
1742
|
-
|
|
1728
|
+
error: stringifyError(stopError),
|
|
1743
1729
|
});
|
|
1744
1730
|
}
|
|
1745
1731
|
}
|
|
@@ -1786,7 +1772,7 @@ export class EngineActorDriver implements ActorDriver {
|
|
|
1786
1772
|
logger().debug({
|
|
1787
1773
|
msg: "actor start failed during stop, cleaning up handler",
|
|
1788
1774
|
actorId,
|
|
1789
|
-
|
|
1775
|
+
error: stringifyError(err),
|
|
1790
1776
|
});
|
|
1791
1777
|
}
|
|
1792
1778
|
}
|
|
@@ -1804,7 +1790,7 @@ export class EngineActorDriver implements ActorDriver {
|
|
|
1804
1790
|
} catch (err) {
|
|
1805
1791
|
logger().error({
|
|
1806
1792
|
msg: "error in onStop, proceeding with removing actor",
|
|
1807
|
-
|
|
1793
|
+
error: stringifyError(err),
|
|
1808
1794
|
});
|
|
1809
1795
|
}
|
|
1810
1796
|
}
|
|
@@ -1989,8 +1975,11 @@ export class EngineActorDriver implements ActorDriver {
|
|
|
1989
1975
|
isHibernatable,
|
|
1990
1976
|
isRestoringHibernatable,
|
|
1991
1977
|
);
|
|
1992
|
-
} catch (
|
|
1993
|
-
logger().error({
|
|
1978
|
+
} catch (error) {
|
|
1979
|
+
logger().error({
|
|
1980
|
+
msg: "building websocket handlers errored",
|
|
1981
|
+
error,
|
|
1982
|
+
});
|
|
1994
1983
|
websocketRaw.close(1011, "ws.route_error");
|
|
1995
1984
|
return;
|
|
1996
1985
|
}
|
|
@@ -2005,7 +1994,7 @@ export class EngineActorDriver implements ActorDriver {
|
|
|
2005
1994
|
// Get connection and actor from wsHandler (may be undefined for inspector endpoint)
|
|
2006
1995
|
const conn = wsHandler.conn;
|
|
2007
1996
|
const actor = wsHandler.actor;
|
|
2008
|
-
const
|
|
1997
|
+
const _connStateManager = conn?.[CONN_STATE_MANAGER_SYMBOL];
|
|
2009
1998
|
|
|
2010
1999
|
// Bind event listeners to Hono WebSocket handlers
|
|
2011
2000
|
//
|
|
@@ -2044,16 +2033,15 @@ export class EngineActorDriver implements ActorDriver {
|
|
|
2044
2033
|
|
|
2045
2034
|
const currentActor = this.#actors.get(actorId)?.actor;
|
|
2046
2035
|
const actorForDispatch =
|
|
2047
|
-
currentActor &&
|
|
2048
|
-
isStaticActorInstance(currentActor)
|
|
2036
|
+
currentActor && isStaticActorInstance(currentActor)
|
|
2049
2037
|
? currentActor
|
|
2050
2038
|
: actor;
|
|
2051
2039
|
const connForDispatch =
|
|
2052
2040
|
isHibernatable && actorForDispatch
|
|
2053
|
-
? actorForDispatch.connectionManager.findHibernatableConn(
|
|
2041
|
+
? (actorForDispatch.connectionManager.findHibernatableConn(
|
|
2054
2042
|
gatewayIdBuf,
|
|
2055
2043
|
requestIdBuf,
|
|
2056
|
-
) ?? conn
|
|
2044
|
+
) ?? conn)
|
|
2057
2045
|
: conn;
|
|
2058
2046
|
|
|
2059
2047
|
if (actorForDispatch?.isStopping) {
|
|
@@ -2063,7 +2051,10 @@ export class EngineActorDriver implements ActorDriver {
|
|
|
2063
2051
|
actorId: actorForDispatch?.id,
|
|
2064
2052
|
messageIndex: event.rivetMessageIndex,
|
|
2065
2053
|
});
|
|
2066
|
-
if (
|
|
2054
|
+
if (
|
|
2055
|
+
!isRawWebSocketPath &&
|
|
2056
|
+
websocket.readyState !== websocket.CLOSED
|
|
2057
|
+
) {
|
|
2067
2058
|
websocket.close(1011, "actor.stopping");
|
|
2068
2059
|
}
|
|
2069
2060
|
return;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { DynamicActorIsolateRuntime } from "./isolate-runtime";
|
|
2
|
+
|
|
3
|
+
export class DynamicActorInstance {
|
|
4
|
+
constructor(
|
|
5
|
+
public readonly id: string,
|
|
6
|
+
private readonly runtime: DynamicActorIsolateRuntime,
|
|
7
|
+
) {}
|
|
8
|
+
|
|
9
|
+
get isStopping(): boolean {
|
|
10
|
+
return this.runtime.isStopping;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async onStop(mode: "sleep" | "destroy"): Promise<void> {
|
|
14
|
+
await this.runtime.stop(mode);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async onAlarm(): Promise<void> {
|
|
18
|
+
await this.runtime.onAlarm();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async cleanupPersistedConnections(reason?: string): Promise<number> {
|
|
22
|
+
return await this.runtime.cleanupPersistedConnections(reason);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async getHibernatingWebSockets() {
|
|
26
|
+
return await this.runtime.getHibernatingWebSockets();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
getHibernatingWebSocketMetadata() {
|
|
30
|
+
return this.runtime.getHibernatingWebSocketMetadata();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AnyActorDefinition,
|
|
3
|
+
BaseActorDefinition,
|
|
4
|
+
} from "@/actor/definition";
|
|
5
|
+
|
|
6
|
+
export const DYNAMIC_ACTOR_DEFINITION_SYMBOL = Symbol.for(
|
|
7
|
+
"rivetkit.dynamic_actor_definition",
|
|
8
|
+
);
|
|
9
|
+
|
|
10
|
+
export interface DynamicActorSource {
|
|
11
|
+
source: string;
|
|
12
|
+
nodeProcess?: {
|
|
13
|
+
memoryLimit?: number;
|
|
14
|
+
cpuTimeLimitMs?: number;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface DynamicActorLoadContext {
|
|
19
|
+
key: string[];
|
|
20
|
+
client(): Promise<any>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export type DynamicActorLoader = (
|
|
24
|
+
c: DynamicActorLoadContext,
|
|
25
|
+
) => DynamicActorSource | Promise<DynamicActorSource>;
|
|
26
|
+
|
|
27
|
+
export interface DynamicActorDefinition extends AnyActorDefinition {
|
|
28
|
+
readonly [DYNAMIC_ACTOR_DEFINITION_SYMBOL]: true;
|
|
29
|
+
readonly loader: DynamicActorLoader;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function isDynamicActorDefinition(
|
|
33
|
+
definition: BaseActorDefinition<
|
|
34
|
+
any,
|
|
35
|
+
any,
|
|
36
|
+
any,
|
|
37
|
+
any,
|
|
38
|
+
any,
|
|
39
|
+
any,
|
|
40
|
+
any,
|
|
41
|
+
any,
|
|
42
|
+
any
|
|
43
|
+
>,
|
|
44
|
+
): definition is DynamicActorDefinition {
|
|
45
|
+
return (
|
|
46
|
+
(definition as Partial<DynamicActorDefinition>)[
|
|
47
|
+
DYNAMIC_ACTOR_DEFINITION_SYMBOL
|
|
48
|
+
] === true
|
|
49
|
+
);
|
|
50
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { ActorDriver } from "@/actor/driver";
|
|
2
|
+
import type { Client } from "@/client/client";
|
|
3
|
+
import type { RegistryConfig } from "@/registry/config";
|
|
4
|
+
import type { DynamicActorLoader } from "./internal";
|
|
5
|
+
|
|
6
|
+
export interface DynamicActorIsolateRuntimeConfig {
|
|
7
|
+
actorId: string;
|
|
8
|
+
actorName: string;
|
|
9
|
+
actorKey: string[];
|
|
10
|
+
input: unknown;
|
|
11
|
+
region: string;
|
|
12
|
+
loader: DynamicActorLoader;
|
|
13
|
+
actorDriver: ActorDriver;
|
|
14
|
+
inlineClient: Client<any>;
|
|
15
|
+
test: RegistryConfig["test"];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface DynamicHibernatingWebSocketMetadata {
|
|
19
|
+
gatewayId: ArrayBuffer;
|
|
20
|
+
requestId: ArrayBuffer;
|
|
21
|
+
serverMessageIndex: number;
|
|
22
|
+
clientMessageIndex: number;
|
|
23
|
+
path: string;
|
|
24
|
+
headers: Record<string, string>;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export class DynamicActorIsolateRuntime {
|
|
28
|
+
#isStopping = false;
|
|
29
|
+
|
|
30
|
+
constructor(private readonly config: DynamicActorIsolateRuntimeConfig) {}
|
|
31
|
+
|
|
32
|
+
get isStopping(): boolean {
|
|
33
|
+
return this.#isStopping;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async start(): Promise<void> {
|
|
37
|
+
await this.config.loader({
|
|
38
|
+
key: this.config.actorKey,
|
|
39
|
+
client: async () => this.config.inlineClient,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async stop(_mode: "sleep" | "destroy"): Promise<void> {
|
|
44
|
+
this.#isStopping = true;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async dispose(): Promise<void> {
|
|
48
|
+
this.#isStopping = true;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async onAlarm(): Promise<void> {}
|
|
52
|
+
|
|
53
|
+
async cleanupPersistedConnections(_reason?: string): Promise<number> {
|
|
54
|
+
return 0;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async getHibernatingWebSockets(): Promise<
|
|
58
|
+
DynamicHibernatingWebSocketMetadata[]
|
|
59
|
+
> {
|
|
60
|
+
return [];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
getHibernatingWebSocketMetadata(): DynamicHibernatingWebSocketMetadata[] {
|
|
64
|
+
return [];
|
|
65
|
+
}
|
|
66
|
+
}
|