rivetkit 2.0.19 → 2.0.21
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/tsup/actor/errors.cjs.map +1 -1
- package/dist/tsup/{chunk-UGLCR467.js → chunk-2POQCWMA.js} +481 -100
- package/dist/tsup/chunk-2POQCWMA.js.map +1 -0
- package/dist/tsup/{chunk-GBVUP7IH.js → chunk-3UIGKLZW.js} +6 -6
- package/dist/tsup/chunk-3UIGKLZW.js.map +1 -0
- package/dist/tsup/{chunk-NCVKAD3U.js → chunk-4OINFQBR.js} +3 -3
- package/dist/tsup/{chunk-2N5T57W5.cjs → chunk-65SAIRRY.cjs} +12 -12
- package/dist/tsup/chunk-65SAIRRY.cjs.map +1 -0
- package/dist/tsup/{chunk-SO6CSZPF.js → chunk-6G76WIWL.js} +2 -2
- package/dist/tsup/{chunk-SO6CSZPF.js.map → chunk-6G76WIWL.js.map} +1 -1
- package/dist/tsup/{chunk-UBS2ARYU.js → chunk-D2LS4X6E.js} +11 -5
- package/dist/tsup/chunk-D2LS4X6E.js.map +1 -0
- package/dist/tsup/{chunk-FO4Q36GQ.js → chunk-DYA34FHW.js} +2 -2
- package/dist/tsup/{chunk-7RKGZXDH.cjs → chunk-ELDFBXDV.cjs} +8 -4
- package/dist/tsup/chunk-ELDFBXDV.cjs.map +1 -0
- package/dist/tsup/{chunk-F4PHLUIT.cjs → chunk-FDJ3AVNB.cjs} +32 -26
- package/dist/tsup/chunk-FDJ3AVNB.cjs.map +1 -0
- package/dist/tsup/{chunk-U3PO7PEY.js → chunk-FUX6U6TL.js} +2 -2
- package/dist/tsup/chunk-FUX6U6TL.js.map +1 -0
- package/dist/tsup/{chunk-AYNDGM4A.cjs → chunk-HN7UXCYQ.cjs} +7 -7
- package/dist/tsup/chunk-HN7UXCYQ.cjs.map +1 -0
- package/dist/tsup/{chunk-6MI3RWWC.js → chunk-HUGSRAGL.js} +8 -4
- package/dist/tsup/chunk-HUGSRAGL.js.map +1 -0
- package/dist/tsup/{chunk-7BTAYSZC.cjs → chunk-JKOUXDK6.cjs} +16 -10
- package/dist/tsup/chunk-JKOUXDK6.cjs.map +1 -0
- package/dist/tsup/{chunk-EXP6CQEI.cjs → chunk-JTIBPF7N.cjs} +14 -14
- package/dist/tsup/chunk-JTIBPF7N.cjs.map +1 -0
- package/dist/tsup/chunk-KSRXX3Z4.cjs.map +1 -1
- package/dist/tsup/{chunk-RIK4JNIG.cjs → chunk-LMJHBF26.cjs} +454 -288
- package/dist/tsup/chunk-LMJHBF26.cjs.map +1 -0
- package/dist/tsup/{chunk-DGXMPCNI.cjs → chunk-LWGCMELP.cjs} +3 -3
- package/dist/tsup/chunk-LWGCMELP.cjs.map +1 -0
- package/dist/tsup/{chunk-ZB3DP5IR.cjs → chunk-M5BHNJHB.cjs} +630 -249
- package/dist/tsup/chunk-M5BHNJHB.cjs.map +1 -0
- package/dist/tsup/{chunk-J5PFJTK3.cjs → chunk-O4GUKGK4.cjs} +6 -6
- package/dist/tsup/chunk-O4GUKGK4.cjs.map +1 -0
- package/dist/tsup/{chunk-LWQDW6VP.js → chunk-RZZDFDB6.js} +13 -7
- package/dist/tsup/chunk-RZZDFDB6.js.map +1 -0
- package/dist/tsup/{chunk-DAZ2YBCM.js → chunk-VLR3TDHT.js} +2 -2
- package/dist/tsup/{chunk-DAAQFFK3.js → chunk-Y2QONT7B.js} +262 -96
- package/dist/tsup/chunk-Y2QONT7B.js.map +1 -0
- package/dist/tsup/{chunk-AXQWQIUS.cjs → chunk-ZNWE3XBT.cjs} +3 -3
- package/dist/tsup/chunk-ZNWE3XBT.cjs.map +1 -0
- package/dist/tsup/client/mod.cjs +9 -9
- package/dist/tsup/client/mod.cjs.map +1 -1
- package/dist/tsup/client/mod.d.cts +2 -2
- package/dist/tsup/client/mod.d.ts +2 -2
- package/dist/tsup/client/mod.js +8 -8
- package/dist/tsup/common/log.cjs +3 -3
- package/dist/tsup/common/log.cjs.map +1 -1
- package/dist/tsup/common/log.js +2 -2
- 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/{conn-DAXlyhVg.d.ts → conn-Clu655RU.d.ts} +1 -0
- package/dist/tsup/{conn--6rFdSfD.d.cts → conn-lUvFLo_q.d.cts} +1 -0
- package/dist/tsup/driver-helpers/mod.cjs +5 -5
- package/dist/tsup/driver-helpers/mod.cjs.map +1 -1
- package/dist/tsup/driver-helpers/mod.d.cts +1 -1
- package/dist/tsup/driver-helpers/mod.d.ts +1 -1
- package/dist/tsup/driver-helpers/mod.js +4 -4
- package/dist/tsup/driver-test-suite/mod.cjs +603 -294
- package/dist/tsup/driver-test-suite/mod.cjs.map +1 -1
- package/dist/tsup/driver-test-suite/mod.d.cts +1 -1
- package/dist/tsup/driver-test-suite/mod.d.ts +1 -1
- package/dist/tsup/driver-test-suite/mod.js +574 -265
- package/dist/tsup/driver-test-suite/mod.js.map +1 -1
- package/dist/tsup/inspector/mod.cjs +6 -6
- package/dist/tsup/inspector/mod.cjs.map +1 -1
- package/dist/tsup/inspector/mod.d.cts +68 -7
- package/dist/tsup/inspector/mod.d.ts +68 -7
- package/dist/tsup/inspector/mod.js +5 -5
- package/dist/tsup/mod.cjs +10 -10
- package/dist/tsup/mod.cjs.map +1 -1
- package/dist/tsup/mod.d.cts +2 -2
- package/dist/tsup/mod.d.ts +2 -2
- package/dist/tsup/mod.js +9 -9
- package/dist/tsup/test/mod.cjs +11 -11
- package/dist/tsup/test/mod.cjs.map +1 -1
- package/dist/tsup/test/mod.d.cts +1 -1
- package/dist/tsup/test/mod.d.ts +1 -1
- package/dist/tsup/test/mod.js +10 -10
- package/dist/tsup/utils.cjs +2 -2
- package/dist/tsup/utils.cjs.map +1 -1
- package/dist/tsup/utils.js +1 -1
- package/package.json +4 -3
- package/src/actor/config.ts +108 -15
- package/src/actor/conn-drivers.ts +2 -1
- package/src/actor/instance.ts +119 -35
- package/src/actor/keys.test.ts +13 -4
- package/src/actor/protocol/old.ts +10 -3
- package/src/actor/router-endpoints.ts +26 -16
- package/src/actor/router.ts +41 -13
- package/src/actor/unstable-react.ts +1 -1
- package/src/client/actor-common.ts +3 -1
- package/src/client/actor-conn.ts +44 -12
- package/src/client/actor-handle.ts +4 -1
- package/src/client/client.ts +32 -18
- package/src/client/utils.ts +21 -8
- package/src/common/actor-router-consts.ts +2 -0
- package/src/common/inline-websocket-adapter2.ts +24 -6
- package/src/common/log.ts +6 -2
- package/src/common/logfmt.ts +3 -1
- package/src/common/router.ts +3 -1
- package/src/common/utils.ts +6 -2
- package/src/driver-helpers/utils.ts +4 -1
- package/src/driver-test-suite/mod.ts +15 -4
- package/src/driver-test-suite/test-inline-client-driver.ts +35 -13
- package/src/driver-test-suite/tests/action-features.ts +6 -2
- package/src/driver-test-suite/tests/actor-conn-state.ts +18 -8
- package/src/driver-test-suite/tests/actor-conn.ts +35 -13
- package/src/driver-test-suite/tests/actor-handle.ts +35 -15
- package/src/driver-test-suite/tests/actor-inline-client.ts +34 -23
- package/src/driver-test-suite/tests/actor-inspector.ts +241 -131
- package/src/driver-test-suite/tests/actor-reconnect.ts +14 -4
- package/src/driver-test-suite/tests/actor-schedule.ts +12 -3
- package/src/driver-test-suite/tests/actor-sleep.ts +6 -3
- package/src/driver-test-suite/tests/actor-vars.ts +6 -2
- package/src/driver-test-suite/tests/manager-driver.ts +16 -6
- package/src/driver-test-suite/tests/raw-http-request-properties.ts +64 -25
- package/src/driver-test-suite/tests/raw-http.ts +17 -5
- package/src/driver-test-suite/tests/raw-websocket.ts +36 -12
- package/src/driver-test-suite/tests/request-access.ts +18 -8
- package/src/drivers/engine/actor-driver.ts +46 -25
- package/src/drivers/engine/config.ts +2 -1
- package/src/drivers/file-system/global-state.ts +58 -16
- package/src/drivers/file-system/manager.ts +35 -12
- package/src/drivers/file-system/mod.ts +6 -1
- package/src/drivers/file-system/utils.ts +8 -2
- package/src/engine-process/mod.ts +15 -4
- package/src/inspector/actor.ts +63 -23
- package/src/inspector/config.ts +2 -1
- package/src/inspector/manager.ts +10 -3
- package/src/inspector/utils.ts +2 -1
- package/src/manager/driver.ts +4 -1
- package/src/manager/gateway.ts +278 -8
- package/src/manager/hono-websocket-adapter.ts +33 -10
- package/src/manager/router-schema.ts +4 -2
- package/src/manager/router.ts +78 -12
- package/src/manager-api/actors.ts +2 -0
- package/src/registry/mod.ts +31 -9
- package/src/registry/run-config.ts +3 -1
- package/src/remote-manager-driver/api-endpoints.ts +2 -2
- package/src/remote-manager-driver/mod.ts +22 -5
- package/src/remote-manager-driver/ws-proxy.ts +21 -5
- package/src/serde.ts +6 -2
- package/src/test/mod.ts +2 -1
- package/src/utils.ts +6 -2
- package/dist/tsup/chunk-2N5T57W5.cjs.map +0 -1
- package/dist/tsup/chunk-6MI3RWWC.js.map +0 -1
- package/dist/tsup/chunk-7BTAYSZC.cjs.map +0 -1
- package/dist/tsup/chunk-7RKGZXDH.cjs.map +0 -1
- package/dist/tsup/chunk-AXQWQIUS.cjs.map +0 -1
- package/dist/tsup/chunk-AYNDGM4A.cjs.map +0 -1
- package/dist/tsup/chunk-DAAQFFK3.js.map +0 -1
- package/dist/tsup/chunk-DGXMPCNI.cjs.map +0 -1
- package/dist/tsup/chunk-EXP6CQEI.cjs.map +0 -1
- package/dist/tsup/chunk-F4PHLUIT.cjs.map +0 -1
- package/dist/tsup/chunk-GBVUP7IH.js.map +0 -1
- package/dist/tsup/chunk-J5PFJTK3.cjs.map +0 -1
- package/dist/tsup/chunk-LWQDW6VP.js.map +0 -1
- package/dist/tsup/chunk-RIK4JNIG.cjs.map +0 -1
- package/dist/tsup/chunk-U3PO7PEY.js.map +0 -1
- package/dist/tsup/chunk-UBS2ARYU.js.map +0 -1
- package/dist/tsup/chunk-UGLCR467.js.map +0 -1
- package/dist/tsup/chunk-ZB3DP5IR.cjs.map +0 -1
- /package/dist/tsup/{chunk-NCVKAD3U.js.map → chunk-4OINFQBR.js.map} +0 -0
- /package/dist/tsup/{chunk-FO4Q36GQ.js.map → chunk-DYA34FHW.js.map} +0 -0
- /package/dist/tsup/{chunk-DAZ2YBCM.js.map → chunk-VLR3TDHT.js.map} +0 -0
package/src/actor/router.ts
CHANGED
|
@@ -71,7 +71,9 @@ export function createActorRouter(
|
|
|
71
71
|
actorDriver: ActorDriver,
|
|
72
72
|
isTest: boolean,
|
|
73
73
|
): ActorRouter {
|
|
74
|
-
const router = new Hono<{ Bindings: ActorRouterBindings }>({
|
|
74
|
+
const router = new Hono<{ Bindings: ActorRouterBindings }>({
|
|
75
|
+
strict: false,
|
|
76
|
+
});
|
|
75
77
|
|
|
76
78
|
router.use("*", loggerMiddleware(loggerWithoutContext()));
|
|
77
79
|
|
|
@@ -131,18 +133,32 @@ export function createActorRouter(
|
|
|
131
133
|
let connTokenRaw: string | undefined;
|
|
132
134
|
|
|
133
135
|
if (protocols) {
|
|
134
|
-
const protocolList = protocols
|
|
136
|
+
const protocolList = protocols
|
|
137
|
+
.split(",")
|
|
138
|
+
.map((p) => p.trim());
|
|
135
139
|
for (const protocol of protocolList) {
|
|
136
140
|
if (protocol.startsWith(WS_PROTOCOL_ENCODING)) {
|
|
137
|
-
encodingRaw = protocol.substring(
|
|
138
|
-
|
|
141
|
+
encodingRaw = protocol.substring(
|
|
142
|
+
WS_PROTOCOL_ENCODING.length,
|
|
143
|
+
);
|
|
144
|
+
} else if (
|
|
145
|
+
protocol.startsWith(WS_PROTOCOL_CONN_PARAMS)
|
|
146
|
+
) {
|
|
139
147
|
connParamsRaw = decodeURIComponent(
|
|
140
|
-
protocol.substring(
|
|
148
|
+
protocol.substring(
|
|
149
|
+
WS_PROTOCOL_CONN_PARAMS.length,
|
|
150
|
+
),
|
|
141
151
|
);
|
|
142
152
|
} else if (protocol.startsWith(WS_PROTOCOL_CONN_ID)) {
|
|
143
|
-
connIdRaw = protocol.substring(
|
|
144
|
-
|
|
145
|
-
|
|
153
|
+
connIdRaw = protocol.substring(
|
|
154
|
+
WS_PROTOCOL_CONN_ID.length,
|
|
155
|
+
);
|
|
156
|
+
} else if (
|
|
157
|
+
protocol.startsWith(WS_PROTOCOL_CONN_TOKEN)
|
|
158
|
+
) {
|
|
159
|
+
connTokenRaw = protocol.substring(
|
|
160
|
+
WS_PROTOCOL_CONN_TOKEN.length,
|
|
161
|
+
);
|
|
146
162
|
}
|
|
147
163
|
}
|
|
148
164
|
}
|
|
@@ -178,7 +194,13 @@ export function createActorRouter(
|
|
|
178
194
|
router.post("/action/:action", async (c) => {
|
|
179
195
|
const actionName = c.req.param("action");
|
|
180
196
|
|
|
181
|
-
return handleAction(
|
|
197
|
+
return handleAction(
|
|
198
|
+
c,
|
|
199
|
+
runConfig,
|
|
200
|
+
actorDriver,
|
|
201
|
+
actionName,
|
|
202
|
+
c.env.actorId,
|
|
203
|
+
);
|
|
182
204
|
});
|
|
183
205
|
|
|
184
206
|
router.post("/connections/message", async (c) => {
|
|
@@ -282,14 +304,20 @@ export function createActorRouter(
|
|
|
282
304
|
if (isInspectorEnabled(runConfig, "actor")) {
|
|
283
305
|
router.route(
|
|
284
306
|
"/inspect",
|
|
285
|
-
new Hono<
|
|
307
|
+
new Hono<
|
|
308
|
+
ActorInspectorRouterEnv & { Bindings: ActorRouterBindings }
|
|
309
|
+
>()
|
|
286
310
|
.use(
|
|
287
311
|
cors(runConfig.inspector.cors),
|
|
288
312
|
secureInspector(runConfig),
|
|
289
313
|
async (c, next) => {
|
|
290
|
-
const inspector = (
|
|
291
|
-
.
|
|
292
|
-
|
|
314
|
+
const inspector = (
|
|
315
|
+
await actorDriver.loadActor(c.env.actorId)
|
|
316
|
+
).inspector;
|
|
317
|
+
invariant(
|
|
318
|
+
inspector,
|
|
319
|
+
"inspector not supported on this platform",
|
|
320
|
+
);
|
|
293
321
|
|
|
294
322
|
c.set("inspector", inspector);
|
|
295
323
|
return next();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//// @ts-
|
|
1
|
+
//// @ts-expect-error we do not have types for this lib
|
|
2
2
|
//import { renderToPipeableStream } from "@jogit/tmp-react-server-dom-nodeless";
|
|
3
3
|
//import getStream from "get-stream";
|
|
4
4
|
//import { isValidElement } from "react";
|
|
@@ -23,7 +23,9 @@ export type ActorDefinitionActions<AD extends AnyActorDefinition> =
|
|
|
23
23
|
// biome-ignore lint/suspicious/noExplicitAny: safe to use any here
|
|
24
24
|
AD extends ActorDefinition<any, any, any, any, any, any, infer R>
|
|
25
25
|
? {
|
|
26
|
-
[K in keyof R]: R[K] extends (
|
|
26
|
+
[K in keyof R]: R[K] extends (
|
|
27
|
+
...args: infer Args
|
|
28
|
+
) => infer Return
|
|
27
29
|
? ActorActionFunction<Args, Return>
|
|
28
30
|
: never;
|
|
29
31
|
}
|
package/src/client/actor-conn.ts
CHANGED
|
@@ -183,7 +183,11 @@ export class ActorConnRaw {
|
|
|
183
183
|
|
|
184
184
|
const { promise, resolve, reject } =
|
|
185
185
|
promiseWithResolvers<protocol.ActionResponse>();
|
|
186
|
-
this.#actionsInFlight.set(actionId, {
|
|
186
|
+
this.#actionsInFlight.set(actionId, {
|
|
187
|
+
name: opts.name,
|
|
188
|
+
resolve,
|
|
189
|
+
reject,
|
|
190
|
+
});
|
|
187
191
|
|
|
188
192
|
this.#sendMessage({
|
|
189
193
|
body: {
|
|
@@ -377,12 +381,17 @@ enc
|
|
|
377
381
|
"User-Agent": httpUserAgent(),
|
|
378
382
|
[HEADER_ENCODING]: this.#encoding,
|
|
379
383
|
...(this.#params !== undefined
|
|
380
|
-
? {
|
|
384
|
+
? {
|
|
385
|
+
[HEADER_CONN_PARAMS]: JSON.stringify(
|
|
386
|
+
this.#params,
|
|
387
|
+
),
|
|
388
|
+
}
|
|
381
389
|
: {}),
|
|
382
390
|
...(isReconnection
|
|
383
391
|
? {
|
|
384
392
|
[HEADER_CONN_ID]: this.#connectionId,
|
|
385
|
-
[HEADER_CONN_TOKEN]:
|
|
393
|
+
[HEADER_CONN_TOKEN]:
|
|
394
|
+
this.#connectionToken,
|
|
386
395
|
}
|
|
387
396
|
: {}),
|
|
388
397
|
},
|
|
@@ -453,7 +462,9 @@ enc
|
|
|
453
462
|
getEnvUniversal("_RIVETKIT_LOG_MESSAGE")
|
|
454
463
|
? {
|
|
455
464
|
msg: "parsed message",
|
|
456
|
-
message:
|
|
465
|
+
message:
|
|
466
|
+
jsonStringifyCompat(response).substring(0, 100) +
|
|
467
|
+
"...",
|
|
457
468
|
}
|
|
458
469
|
: { msg: "parsed message" },
|
|
459
470
|
);
|
|
@@ -471,7 +482,8 @@ enc
|
|
|
471
482
|
this.#handleOnOpen();
|
|
472
483
|
} else if (response.body.tag === "Error") {
|
|
473
484
|
// Connection error
|
|
474
|
-
const { group, code, message, metadata, actionId } =
|
|
485
|
+
const { group, code, message, metadata, actionId } =
|
|
486
|
+
response.body.val;
|
|
475
487
|
|
|
476
488
|
if (actionId) {
|
|
477
489
|
const inFlight = this.#takeActionInFlight(Number(actionId));
|
|
@@ -486,7 +498,9 @@ enc
|
|
|
486
498
|
metadata,
|
|
487
499
|
});
|
|
488
500
|
|
|
489
|
-
inFlight.reject(
|
|
501
|
+
inFlight.reject(
|
|
502
|
+
new errors.ActorError(group, code, message, metadata),
|
|
503
|
+
);
|
|
490
504
|
} else {
|
|
491
505
|
logger().warn({
|
|
492
506
|
msg: "connection error",
|
|
@@ -534,7 +548,10 @@ enc
|
|
|
534
548
|
});
|
|
535
549
|
inFlight.resolve(response.body.val);
|
|
536
550
|
} else if (response.body.tag === "Event") {
|
|
537
|
-
logger().trace({
|
|
551
|
+
logger().trace({
|
|
552
|
+
msg: "received event",
|
|
553
|
+
name: response.body.val.name,
|
|
554
|
+
});
|
|
538
555
|
this.#dispatchEvent(response.body.val);
|
|
539
556
|
} else {
|
|
540
557
|
assertUnreachable(response.body);
|
|
@@ -821,7 +838,9 @@ enc
|
|
|
821
838
|
) {
|
|
822
839
|
try {
|
|
823
840
|
if (!this.#actorId || !this.#connectionId || !this.#connectionToken)
|
|
824
|
-
throw new errors.InternalError(
|
|
841
|
+
throw new errors.InternalError(
|
|
842
|
+
"Missing connection ID or token.",
|
|
843
|
+
);
|
|
825
844
|
|
|
826
845
|
logger().trace(
|
|
827
846
|
getEnvUniversal("_RIVETKIT_LOG_MESSAGE")
|
|
@@ -850,14 +869,20 @@ enc
|
|
|
850
869
|
body: message,
|
|
851
870
|
encoding: this.#encoding,
|
|
852
871
|
skipParseResponse: true,
|
|
853
|
-
customFetch: this.#driver.sendRequest.bind(
|
|
872
|
+
customFetch: this.#driver.sendRequest.bind(
|
|
873
|
+
this.#driver,
|
|
874
|
+
this.#actorId,
|
|
875
|
+
),
|
|
854
876
|
requestVersionedDataHandler: TO_SERVER_VERSIONED,
|
|
855
877
|
responseVersionedDataHandler: TO_CLIENT_VERSIONED,
|
|
856
878
|
});
|
|
857
879
|
} catch (error) {
|
|
858
880
|
// TODO: This will not automatically trigger a re-broadcast of HTTP events since SSE is separate from the HTTP action
|
|
859
881
|
|
|
860
|
-
logger().warn({
|
|
882
|
+
logger().warn({
|
|
883
|
+
msg: "failed to send message, added to queue",
|
|
884
|
+
error,
|
|
885
|
+
});
|
|
861
886
|
|
|
862
887
|
// Assuming the socket is disconnected and will be reconnected soon
|
|
863
888
|
//
|
|
@@ -887,7 +912,11 @@ enc
|
|
|
887
912
|
|
|
888
913
|
const buffer = await inputDataToBuffer(data);
|
|
889
914
|
|
|
890
|
-
return deserializeWithEncoding(
|
|
915
|
+
return deserializeWithEncoding(
|
|
916
|
+
this.#encoding,
|
|
917
|
+
buffer,
|
|
918
|
+
TO_CLIENT_VERSIONED,
|
|
919
|
+
);
|
|
891
920
|
}
|
|
892
921
|
|
|
893
922
|
/**
|
|
@@ -977,7 +1006,10 @@ enc
|
|
|
977
1006
|
});
|
|
978
1007
|
} catch (error) {
|
|
979
1008
|
// Ignore errors when closing - connection may already be closed
|
|
980
|
-
logger().warn({
|
|
1009
|
+
logger().warn({
|
|
1010
|
+
msg: "failed to send close request",
|
|
1011
|
+
error,
|
|
1012
|
+
});
|
|
981
1013
|
}
|
|
982
1014
|
}
|
|
983
1015
|
this.#transport.sse.close();
|
|
@@ -115,7 +115,10 @@ export class ActorHandleRaw {
|
|
|
115
115
|
args: bufferToArrayBuffer(cbor.encode(opts.args)),
|
|
116
116
|
} satisfies protocol.HttpActionRequest,
|
|
117
117
|
encoding: this.#encoding,
|
|
118
|
-
customFetch: this.#driver.sendRequest.bind(
|
|
118
|
+
customFetch: this.#driver.sendRequest.bind(
|
|
119
|
+
this.#driver,
|
|
120
|
+
actorId,
|
|
121
|
+
),
|
|
119
122
|
signal: opts?.signal,
|
|
120
123
|
requestVersionedDataHandler: HTTP_ACTION_REQUEST_VERSIONED,
|
|
121
124
|
responseVersionedDataHandler: HTTP_ACTION_RESPONSE_VERSIONED,
|
package/src/client/client.ts
CHANGED
|
@@ -317,7 +317,11 @@ export class ClientRaw {
|
|
|
317
317
|
});
|
|
318
318
|
|
|
319
319
|
// Create the actor
|
|
320
|
-
const { actorId } = await queryActor(
|
|
320
|
+
const { actorId } = await queryActor(
|
|
321
|
+
undefined,
|
|
322
|
+
createQuery,
|
|
323
|
+
this.#driver,
|
|
324
|
+
);
|
|
321
325
|
logger().debug({
|
|
322
326
|
msg: "created actor with ID",
|
|
323
327
|
name,
|
|
@@ -427,17 +431,19 @@ export function createClientWithDriver<A extends Registry<any>>(
|
|
|
427
431
|
get: (
|
|
428
432
|
key?: string | string[],
|
|
429
433
|
opts?: GetWithIdOptions,
|
|
430
|
-
): ActorHandle<
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
);
|
|
434
|
+
): ActorHandle<
|
|
435
|
+
ExtractActorsFromRegistry<A>[typeof prop]
|
|
436
|
+
> => {
|
|
437
|
+
return target.get<
|
|
438
|
+
ExtractActorsFromRegistry<A>[typeof prop]
|
|
439
|
+
>(prop, key, opts);
|
|
436
440
|
},
|
|
437
441
|
getOrCreate: (
|
|
438
442
|
key?: string | string[],
|
|
439
443
|
opts?: GetOptions,
|
|
440
|
-
): ActorHandle<
|
|
444
|
+
): ActorHandle<
|
|
445
|
+
ExtractActorsFromRegistry<A>[typeof prop]
|
|
446
|
+
> => {
|
|
441
447
|
return target.getOrCreate<
|
|
442
448
|
ExtractActorsFromRegistry<A>[typeof prop]
|
|
443
449
|
>(prop, key, opts);
|
|
@@ -445,12 +451,12 @@ export function createClientWithDriver<A extends Registry<any>>(
|
|
|
445
451
|
getForId: (
|
|
446
452
|
actorId: string,
|
|
447
453
|
opts?: GetWithIdOptions,
|
|
448
|
-
): ActorHandle<
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
);
|
|
454
|
+
): ActorHandle<
|
|
455
|
+
ExtractActorsFromRegistry<A>[typeof prop]
|
|
456
|
+
> => {
|
|
457
|
+
return target.getForId<
|
|
458
|
+
ExtractActorsFromRegistry<A>[typeof prop]
|
|
459
|
+
>(prop, actorId, opts);
|
|
454
460
|
},
|
|
455
461
|
create: async (
|
|
456
462
|
key: string | string[],
|
|
@@ -502,7 +508,8 @@ function createActorProxy<AD extends AnyActorDefinition>(
|
|
|
502
508
|
|
|
503
509
|
let method = methodCache.get(prop);
|
|
504
510
|
if (!method) {
|
|
505
|
-
method = (...args: unknown[]) =>
|
|
511
|
+
method = (...args: unknown[]) =>
|
|
512
|
+
target.action({ name: prop, args });
|
|
506
513
|
methodCache.set(prop, method);
|
|
507
514
|
}
|
|
508
515
|
return method;
|
|
@@ -530,8 +537,14 @@ function createActorProxy<AD extends AnyActorDefinition>(
|
|
|
530
537
|
},
|
|
531
538
|
|
|
532
539
|
// Support proper property descriptors
|
|
533
|
-
getOwnPropertyDescriptor(
|
|
534
|
-
|
|
540
|
+
getOwnPropertyDescriptor(
|
|
541
|
+
target: ActorHandleRaw,
|
|
542
|
+
prop: string | symbol,
|
|
543
|
+
) {
|
|
544
|
+
const targetDescriptor = Reflect.getOwnPropertyDescriptor(
|
|
545
|
+
target,
|
|
546
|
+
prop,
|
|
547
|
+
);
|
|
535
548
|
if (targetDescriptor) {
|
|
536
549
|
return targetDescriptor;
|
|
537
550
|
}
|
|
@@ -541,7 +554,8 @@ function createActorProxy<AD extends AnyActorDefinition>(
|
|
|
541
554
|
configurable: true,
|
|
542
555
|
enumerable: false,
|
|
543
556
|
writable: false,
|
|
544
|
-
value: (...args: unknown[]) =>
|
|
557
|
+
value: (...args: unknown[]) =>
|
|
558
|
+
target.action({ name: prop, args }),
|
|
545
559
|
};
|
|
546
560
|
}
|
|
547
561
|
return undefined;
|
package/src/client/utils.ts
CHANGED
|
@@ -43,7 +43,9 @@ export interface HttpRequestOpts<RequestBody, ResponseBody> {
|
|
|
43
43
|
signal?: AbortSignal;
|
|
44
44
|
customFetch?: (req: Request) => Promise<Response>;
|
|
45
45
|
requestVersionedDataHandler: VersionedDataHandler<RequestBody> | undefined;
|
|
46
|
-
responseVersionedDataHandler:
|
|
46
|
+
responseVersionedDataHandler:
|
|
47
|
+
| VersionedDataHandler<ResponseBody>
|
|
48
|
+
| undefined;
|
|
47
49
|
}
|
|
48
50
|
|
|
49
51
|
export async function sendHttpRequest<
|
|
@@ -113,18 +115,29 @@ export async function sendHttpRequest<
|
|
|
113
115
|
//});
|
|
114
116
|
|
|
115
117
|
// Error is not structured
|
|
116
|
-
const textResponse = new TextDecoder("utf-8", {
|
|
117
|
-
|
|
118
|
-
);
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
118
|
+
const textResponse = new TextDecoder("utf-8", {
|
|
119
|
+
fatal: false,
|
|
120
|
+
}).decode(bufferResponse);
|
|
121
|
+
|
|
122
|
+
const rayId = response.headers.get("x-rivet-ray-id");
|
|
123
|
+
|
|
124
|
+
if (rayId) {
|
|
125
|
+
throw new HttpRequestError(
|
|
126
|
+
`${response.statusText} (${response.status}) (Ray ID: ${rayId}):\n${textResponse}`,
|
|
127
|
+
);
|
|
128
|
+
} else {
|
|
129
|
+
throw new HttpRequestError(
|
|
130
|
+
`${response.statusText} (${response.status}):\n${textResponse}`,
|
|
131
|
+
);
|
|
132
|
+
}
|
|
122
133
|
}
|
|
123
134
|
|
|
124
135
|
// Decode metadata based on encoding - only binary encodings have CBOR-encoded metadata
|
|
125
136
|
let decodedMetadata: unknown;
|
|
126
137
|
if (responseData.metadata && encodingIsBinary(opts.encoding)) {
|
|
127
|
-
decodedMetadata = cbor.decode(
|
|
138
|
+
decodedMetadata = cbor.decode(
|
|
139
|
+
new Uint8Array(responseData.metadata),
|
|
140
|
+
);
|
|
128
141
|
}
|
|
129
142
|
|
|
130
143
|
// Throw structured error
|
|
@@ -23,6 +23,7 @@ export const HEADER_RIVET_TOKEN = "x-rivet-token";
|
|
|
23
23
|
// MARK: Manager Gateway Headers
|
|
24
24
|
export const HEADER_RIVET_TARGET = "x-rivet-target";
|
|
25
25
|
export const HEADER_RIVET_ACTOR = "x-rivet-actor";
|
|
26
|
+
export const HEADER_RIVET_NAMESPACE = "x-rivet-namespace";
|
|
26
27
|
|
|
27
28
|
// MARK: WebSocket Protocol Prefixes
|
|
28
29
|
/** Some servers (such as node-ws & Cloudflare) require explicitly match a certain WebSocket protocol. This gives us a static protocol to match against. */
|
|
@@ -55,5 +56,6 @@ export const ALLOWED_PUBLIC_HEADERS = [
|
|
|
55
56
|
HEADER_CONN_TOKEN,
|
|
56
57
|
HEADER_RIVET_TARGET,
|
|
57
58
|
HEADER_RIVET_ACTOR,
|
|
59
|
+
HEADER_RIVET_NAMESPACE,
|
|
58
60
|
HEADER_RIVET_TOKEN,
|
|
59
61
|
];
|
|
@@ -119,7 +119,10 @@ export class InlineWebSocketAdapter2 implements UniversalWebSocket {
|
|
|
119
119
|
* Closes the connection
|
|
120
120
|
*/
|
|
121
121
|
close(code = 1000, reason = ""): void {
|
|
122
|
-
if (
|
|
122
|
+
if (
|
|
123
|
+
this.readyState === this.CLOSED ||
|
|
124
|
+
this.readyState === this.CLOSING
|
|
125
|
+
) {
|
|
123
126
|
return;
|
|
124
127
|
}
|
|
125
128
|
|
|
@@ -129,7 +132,10 @@ export class InlineWebSocketAdapter2 implements UniversalWebSocket {
|
|
|
129
132
|
|
|
130
133
|
// Call the handler's onClose method
|
|
131
134
|
try {
|
|
132
|
-
this.#handler.onClose(
|
|
135
|
+
this.#handler.onClose(
|
|
136
|
+
{ code, reason, wasClean: true },
|
|
137
|
+
this.#wsContext,
|
|
138
|
+
);
|
|
133
139
|
} catch (err) {
|
|
134
140
|
logger().error({ msg: "error closing websocket", error: err });
|
|
135
141
|
} finally {
|
|
@@ -323,7 +329,10 @@ export class InlineWebSocketAdapter2 implements UniversalWebSocket {
|
|
|
323
329
|
try {
|
|
324
330
|
this.#onopen(event);
|
|
325
331
|
} catch (error) {
|
|
326
|
-
logger().error({
|
|
332
|
+
logger().error({
|
|
333
|
+
msg: "error in onopen handler",
|
|
334
|
+
error,
|
|
335
|
+
});
|
|
327
336
|
}
|
|
328
337
|
}
|
|
329
338
|
break;
|
|
@@ -332,7 +341,10 @@ export class InlineWebSocketAdapter2 implements UniversalWebSocket {
|
|
|
332
341
|
try {
|
|
333
342
|
this.#onclose(event);
|
|
334
343
|
} catch (error) {
|
|
335
|
-
logger().error({
|
|
344
|
+
logger().error({
|
|
345
|
+
msg: "error in onclose handler",
|
|
346
|
+
error,
|
|
347
|
+
});
|
|
336
348
|
}
|
|
337
349
|
}
|
|
338
350
|
break;
|
|
@@ -341,7 +353,10 @@ export class InlineWebSocketAdapter2 implements UniversalWebSocket {
|
|
|
341
353
|
try {
|
|
342
354
|
this.#onerror(event);
|
|
343
355
|
} catch (error) {
|
|
344
|
-
logger().error({
|
|
356
|
+
logger().error({
|
|
357
|
+
msg: "error in onerror handler",
|
|
358
|
+
error,
|
|
359
|
+
});
|
|
345
360
|
}
|
|
346
361
|
}
|
|
347
362
|
break;
|
|
@@ -350,7 +365,10 @@ export class InlineWebSocketAdapter2 implements UniversalWebSocket {
|
|
|
350
365
|
try {
|
|
351
366
|
this.#onmessage(event);
|
|
352
367
|
} catch (error) {
|
|
353
|
-
logger().error({
|
|
368
|
+
logger().error({
|
|
369
|
+
msg: "error in onmessage handler",
|
|
370
|
+
error,
|
|
371
|
+
});
|
|
354
372
|
}
|
|
355
373
|
}
|
|
356
374
|
break;
|
package/src/common/log.ts
CHANGED
|
@@ -43,7 +43,9 @@ export function getPinoLevel(logLevel?: LogLevel): LevelWithSilent {
|
|
|
43
43
|
return configuredLogLevel;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
const raw = (getEnvUniversal("LOG_LEVEL") || "warn")
|
|
46
|
+
const raw = (getEnvUniversal("LOG_LEVEL") || "warn")
|
|
47
|
+
.toString()
|
|
48
|
+
.toLowerCase();
|
|
47
49
|
|
|
48
50
|
const parsed = LogLevelSchema.safeParse(raw);
|
|
49
51
|
if (parsed.success) {
|
|
@@ -157,7 +159,9 @@ export async function configureDefaultLogger(
|
|
|
157
159
|
};
|
|
158
160
|
const levelName = levelMap[level] || "info";
|
|
159
161
|
const time =
|
|
160
|
-
getEnvUniversal("LOG_TIMESTAMP") === "1"
|
|
162
|
+
getEnvUniversal("LOG_TIMESTAMP") === "1"
|
|
163
|
+
? Date.now()
|
|
164
|
+
: undefined;
|
|
161
165
|
// TODO: This can be simplified in logfmt.ts
|
|
162
166
|
if (inputArgs.length >= 2) {
|
|
163
167
|
const [objOrMsg, msg] = inputArgs;
|
package/src/common/logfmt.ts
CHANGED
|
@@ -172,7 +172,9 @@ export function errorToLogEntries(base: string, error: unknown): any {
|
|
|
172
172
|
...(LOGGER_CONFIG.enableErrorStack && error.stack
|
|
173
173
|
? { [`${base}.stack`]: formatStackTrace(error.stack) }
|
|
174
174
|
: {}),
|
|
175
|
-
...(error.cause
|
|
175
|
+
...(error.cause
|
|
176
|
+
? errorToLogEntries(`${base}.cause`, error.cause)
|
|
177
|
+
: {}),
|
|
176
178
|
};
|
|
177
179
|
}
|
|
178
180
|
return { [base]: `${error}` };
|
package/src/common/router.ts
CHANGED
|
@@ -128,7 +128,9 @@ export function handleMetadataRequest(
|
|
|
128
128
|
// Do not return client endpoint if default server disabled
|
|
129
129
|
clientEndpoint:
|
|
130
130
|
runConfig.overrideServerAddress ??
|
|
131
|
-
(runConfig.disableDefaultServer
|
|
131
|
+
(runConfig.disableDefaultServer
|
|
132
|
+
? undefined
|
|
133
|
+
: getEndpoint(runConfig)),
|
|
132
134
|
};
|
|
133
135
|
|
|
134
136
|
return c.json(response);
|
package/src/common/utils.ts
CHANGED
|
@@ -20,11 +20,15 @@ export function safeStringify(obj: unknown, maxSize: number) {
|
|
|
20
20
|
function replacer(key: string, value: unknown) {
|
|
21
21
|
if (value === null || value === undefined) return value;
|
|
22
22
|
const valueSize =
|
|
23
|
-
typeof value === "string"
|
|
23
|
+
typeof value === "string"
|
|
24
|
+
? value.length
|
|
25
|
+
: JSON.stringify(value).length;
|
|
24
26
|
size += key.length + valueSize;
|
|
25
27
|
|
|
26
28
|
if (size > maxSize) {
|
|
27
|
-
throw new Error(
|
|
29
|
+
throw new Error(
|
|
30
|
+
`JSON object exceeds size limit of ${maxSize} bytes.`,
|
|
31
|
+
);
|
|
28
32
|
}
|
|
29
33
|
|
|
30
34
|
return value;
|
|
@@ -7,7 +7,10 @@ export function serializeEmptyPersistData(
|
|
|
7
7
|
input: unknown | undefined,
|
|
8
8
|
): Uint8Array {
|
|
9
9
|
const persistData: schema.PersistedActor = {
|
|
10
|
-
input:
|
|
10
|
+
input:
|
|
11
|
+
input !== undefined
|
|
12
|
+
? bufferToArrayBuffer(cbor.encode(input))
|
|
13
|
+
: null,
|
|
11
14
|
hasInitialized: false,
|
|
12
15
|
state: bufferToArrayBuffer(cbor.encode(undefined)),
|
|
13
16
|
connections: [],
|
|
@@ -119,11 +119,20 @@ export function runDriverTests(
|
|
|
119
119
|
transport,
|
|
120
120
|
});
|
|
121
121
|
|
|
122
|
-
runActorConnStateTests({
|
|
122
|
+
runActorConnStateTests({
|
|
123
|
+
...driverTestConfig,
|
|
124
|
+
transport,
|
|
125
|
+
});
|
|
123
126
|
|
|
124
|
-
runActorReconnectTests({
|
|
127
|
+
runActorReconnectTests({
|
|
128
|
+
...driverTestConfig,
|
|
129
|
+
transport,
|
|
130
|
+
});
|
|
125
131
|
|
|
126
|
-
runRequestAccessTests({
|
|
132
|
+
runRequestAccessTests({
|
|
133
|
+
...driverTestConfig,
|
|
134
|
+
transport,
|
|
135
|
+
});
|
|
127
136
|
|
|
128
137
|
runActorDriverTestsWithTransport({
|
|
129
138
|
...driverTestConfig,
|
|
@@ -267,7 +276,9 @@ export async function createTestRuntime(
|
|
|
267
276
|
// Cleanup
|
|
268
277
|
const cleanup = async () => {
|
|
269
278
|
// Stop server
|
|
270
|
-
await new Promise((resolve) =>
|
|
279
|
+
await new Promise((resolve) =>
|
|
280
|
+
server.close(() => resolve(undefined)),
|
|
281
|
+
);
|
|
271
282
|
|
|
272
283
|
// Extra cleanup
|
|
273
284
|
await driverCleanup?.();
|
|
@@ -60,16 +60,26 @@ export function createTestInlineClientDriver(
|
|
|
60
60
|
): ManagerDriver {
|
|
61
61
|
return {
|
|
62
62
|
getForId(input: GetForIdInput): Promise<ActorOutput | undefined> {
|
|
63
|
-
return makeInlineRequest(
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
return makeInlineRequest(
|
|
64
|
+
endpoint,
|
|
65
|
+
encoding,
|
|
66
|
+
transport,
|
|
67
|
+
"getForId",
|
|
68
|
+
[input],
|
|
69
|
+
);
|
|
66
70
|
},
|
|
67
71
|
getWithKey(input: GetWithKeyInput): Promise<ActorOutput | undefined> {
|
|
68
|
-
return makeInlineRequest(
|
|
69
|
-
|
|
70
|
-
|
|
72
|
+
return makeInlineRequest(
|
|
73
|
+
endpoint,
|
|
74
|
+
encoding,
|
|
75
|
+
transport,
|
|
76
|
+
"getWithKey",
|
|
77
|
+
[input],
|
|
78
|
+
);
|
|
71
79
|
},
|
|
72
|
-
getOrCreateWithKey(
|
|
80
|
+
getOrCreateWithKey(
|
|
81
|
+
input: GetOrCreateWithKeyInput,
|
|
82
|
+
): Promise<ActorOutput> {
|
|
73
83
|
return makeInlineRequest(
|
|
74
84
|
endpoint,
|
|
75
85
|
encoding,
|
|
@@ -79,9 +89,13 @@ export function createTestInlineClientDriver(
|
|
|
79
89
|
);
|
|
80
90
|
},
|
|
81
91
|
createActor(input: CreateInput): Promise<ActorOutput> {
|
|
82
|
-
return makeInlineRequest(
|
|
83
|
-
|
|
84
|
-
|
|
92
|
+
return makeInlineRequest(
|
|
93
|
+
endpoint,
|
|
94
|
+
encoding,
|
|
95
|
+
transport,
|
|
96
|
+
"createActor",
|
|
97
|
+
[input],
|
|
98
|
+
);
|
|
85
99
|
},
|
|
86
100
|
async sendRequest(
|
|
87
101
|
actorId: string,
|
|
@@ -104,7 +118,11 @@ export function createTestInlineClientDriver(
|
|
|
104
118
|
// Use the dedicated raw HTTP endpoint
|
|
105
119
|
const url = `${endpoint}/.test/inline-driver/send-request/${pathWithQuery}`;
|
|
106
120
|
|
|
107
|
-
logger().debug({
|
|
121
|
+
logger().debug({
|
|
122
|
+
msg: "rewriting http url",
|
|
123
|
+
from: oldUrl,
|
|
124
|
+
to: url,
|
|
125
|
+
});
|
|
108
126
|
|
|
109
127
|
// Merge headers with our metadata
|
|
110
128
|
const headers = new Headers(actorRequest.headers);
|
|
@@ -124,7 +142,9 @@ export function createTestInlineClientDriver(
|
|
|
124
142
|
// Check if it's an error response from our handler
|
|
125
143
|
if (
|
|
126
144
|
!response.ok &&
|
|
127
|
-
response.headers
|
|
145
|
+
response.headers
|
|
146
|
+
.get("content-type")
|
|
147
|
+
?.includes("application/json")
|
|
128
148
|
) {
|
|
129
149
|
try {
|
|
130
150
|
// Clone the response to avoid consuming the body
|
|
@@ -581,7 +601,9 @@ async function makeInlineRequest<T>(
|
|
|
581
601
|
} as RequestInit);
|
|
582
602
|
|
|
583
603
|
if (!response.ok) {
|
|
584
|
-
throw new Error(
|
|
604
|
+
throw new Error(
|
|
605
|
+
`Failed to call inline ${method}: ${response.statusText}`,
|
|
606
|
+
);
|
|
585
607
|
}
|
|
586
608
|
|
|
587
609
|
// Parse response
|