rivetkit 2.0.3 → 2.0.5
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/README.md +11 -0
- package/dist/schemas/actor-persist/v1.ts +21 -24
- package/dist/schemas/client-protocol/v1.ts +6 -0
- package/dist/tsup/actor/errors.cjs +10 -2
- package/dist/tsup/actor/errors.cjs.map +1 -1
- package/dist/tsup/actor/errors.d.cts +17 -4
- package/dist/tsup/actor/errors.d.ts +17 -4
- package/dist/tsup/actor/errors.js +11 -3
- package/dist/tsup/{chunk-4NSUQZ2H.js → chunk-2MD57QF4.js} +119 -115
- package/dist/tsup/chunk-2MD57QF4.js.map +1 -0
- package/dist/tsup/{chunk-GIR3AFFI.cjs → chunk-5QGQK44L.cjs} +103 -44
- package/dist/tsup/chunk-5QGQK44L.cjs.map +1 -0
- package/dist/tsup/chunk-5YTI25C3.cjs +250 -0
- package/dist/tsup/chunk-5YTI25C3.cjs.map +1 -0
- package/dist/tsup/chunk-B2QGJGZQ.js +338 -0
- package/dist/tsup/chunk-B2QGJGZQ.js.map +1 -0
- package/dist/tsup/{chunk-3H7O2A7I.js → chunk-CFFKMUYH.js} +61 -22
- package/dist/tsup/chunk-CFFKMUYH.js.map +1 -0
- package/dist/tsup/{chunk-FLMTTN27.js → chunk-CKA54YQN.js} +15 -8
- package/dist/tsup/chunk-CKA54YQN.js.map +1 -0
- package/dist/tsup/chunk-D7NWUCRK.cjs +20 -0
- package/dist/tsup/chunk-D7NWUCRK.cjs.map +1 -0
- package/dist/tsup/{chunk-FCCPJNMA.cjs → chunk-FGFT4FVX.cjs} +12 -27
- package/dist/tsup/chunk-FGFT4FVX.cjs.map +1 -0
- package/dist/tsup/chunk-I5VTWPHW.js +20 -0
- package/dist/tsup/chunk-I5VTWPHW.js.map +1 -0
- package/dist/tsup/{chunk-6WKQDDUD.cjs → chunk-IRMBWX36.cjs} +146 -142
- package/dist/tsup/chunk-IRMBWX36.cjs.map +1 -0
- package/dist/tsup/chunk-L7QRXNWP.js +6562 -0
- package/dist/tsup/chunk-L7QRXNWP.js.map +1 -0
- package/dist/tsup/{chunk-R2OPSKIV.cjs → chunk-LZIBTLEY.cjs} +20 -13
- package/dist/tsup/chunk-LZIBTLEY.cjs.map +1 -0
- package/dist/tsup/chunk-MRZS2J4X.cjs +6562 -0
- package/dist/tsup/chunk-MRZS2J4X.cjs.map +1 -0
- package/dist/tsup/{chunk-PO4VLDWA.js → chunk-PG3K2LI7.js} +3 -5
- package/dist/tsup/chunk-PG3K2LI7.js.map +1 -0
- package/dist/tsup/{chunk-TZJKSBUQ.cjs → chunk-PHSQJ6QI.cjs} +3 -5
- package/dist/tsup/chunk-PHSQJ6QI.cjs.map +1 -0
- package/dist/tsup/chunk-RM2SVURR.cjs +338 -0
- package/dist/tsup/chunk-RM2SVURR.cjs.map +1 -0
- package/dist/tsup/{chunk-OGAPU3UG.cjs → chunk-WADSS5X4.cjs} +66 -27
- package/dist/tsup/chunk-WADSS5X4.cjs.map +1 -0
- package/dist/tsup/chunk-WNGOBAA7.js +250 -0
- package/dist/tsup/chunk-WNGOBAA7.js.map +1 -0
- package/dist/tsup/{chunk-INGJP237.js → chunk-YPZFLUO6.js} +103 -44
- package/dist/tsup/chunk-YPZFLUO6.js.map +1 -0
- package/dist/tsup/{chunk-6PDXBYI5.js → chunk-YW6Y6VNE.js} +8 -23
- package/dist/tsup/chunk-YW6Y6VNE.js.map +1 -0
- package/dist/tsup/client/mod.cjs +10 -10
- package/dist/tsup/client/mod.d.cts +7 -13
- package/dist/tsup/client/mod.d.ts +7 -13
- package/dist/tsup/client/mod.js +9 -9
- package/dist/tsup/common/log.cjs +12 -4
- package/dist/tsup/common/log.cjs.map +1 -1
- package/dist/tsup/common/log.d.cts +23 -17
- package/dist/tsup/common/log.d.ts +23 -17
- package/dist/tsup/common/log.js +15 -7
- package/dist/tsup/common/websocket.cjs +5 -5
- package/dist/tsup/common/websocket.js +4 -4
- package/dist/tsup/{common-CpqORuCq.d.cts → common-CXCe7s6i.d.cts} +2 -2
- package/dist/tsup/{common-CpqORuCq.d.ts → common-CXCe7s6i.d.ts} +2 -2
- package/dist/tsup/{connection-BwUMoe6n.d.ts → connection-BvE-Oq7t.d.ts} +215 -234
- package/dist/tsup/{connection-BR_Ve4ku.d.cts → connection-DTzmWwU5.d.cts} +215 -234
- package/dist/tsup/driver-helpers/mod.cjs +6 -9
- package/dist/tsup/driver-helpers/mod.cjs.map +1 -1
- package/dist/tsup/driver-helpers/mod.d.cts +5 -6
- package/dist/tsup/driver-helpers/mod.d.ts +5 -6
- package/dist/tsup/driver-helpers/mod.js +6 -9
- package/dist/tsup/driver-test-suite/mod.cjs +615 -1357
- package/dist/tsup/driver-test-suite/mod.cjs.map +1 -1
- package/dist/tsup/driver-test-suite/mod.d.cts +12 -6
- package/dist/tsup/driver-test-suite/mod.d.ts +12 -6
- package/dist/tsup/driver-test-suite/mod.js +1334 -2076
- package/dist/tsup/driver-test-suite/mod.js.map +1 -1
- package/dist/tsup/inspector/mod.cjs +6 -8
- package/dist/tsup/inspector/mod.cjs.map +1 -1
- package/dist/tsup/inspector/mod.d.cts +3 -3
- package/dist/tsup/inspector/mod.d.ts +3 -3
- package/dist/tsup/inspector/mod.js +8 -10
- package/dist/tsup/mod.cjs +9 -15
- package/dist/tsup/mod.cjs.map +1 -1
- package/dist/tsup/mod.d.cts +47 -42
- package/dist/tsup/mod.d.ts +47 -42
- package/dist/tsup/mod.js +10 -16
- package/dist/tsup/{router-endpoints-DAbqVFx2.d.ts → router-endpoints-CctffZNL.d.cts} +2 -3
- package/dist/tsup/{router-endpoints-AYkXG8Tl.d.cts → router-endpoints-DFm1BglJ.d.ts} +2 -3
- package/dist/tsup/test/mod.cjs +10 -14
- package/dist/tsup/test/mod.cjs.map +1 -1
- package/dist/tsup/test/mod.d.cts +4 -5
- package/dist/tsup/test/mod.d.ts +4 -5
- package/dist/tsup/test/mod.js +9 -13
- package/dist/tsup/{utils-CT0cv4jd.d.ts → utils-fwx3o3K9.d.cts} +1 -0
- package/dist/tsup/{utils-CT0cv4jd.d.cts → utils-fwx3o3K9.d.ts} +1 -0
- package/dist/tsup/utils.cjs +5 -3
- package/dist/tsup/utils.cjs.map +1 -1
- package/dist/tsup/utils.d.cts +19 -2
- package/dist/tsup/utils.d.ts +19 -2
- package/dist/tsup/utils.js +4 -2
- package/package.json +6 -6
- package/src/actor/action.ts +1 -5
- package/src/actor/config.ts +27 -295
- package/src/actor/connection.ts +9 -12
- package/src/actor/context.ts +1 -4
- package/src/actor/definition.ts +7 -11
- package/src/actor/errors.ts +98 -36
- package/src/actor/generic-conn-driver.ts +28 -16
- package/src/actor/instance.ts +177 -133
- package/src/actor/log.ts +4 -13
- package/src/actor/mod.ts +0 -5
- package/src/actor/protocol/old.ts +42 -26
- package/src/actor/protocol/serde.ts +1 -1
- package/src/actor/router-endpoints.ts +47 -39
- package/src/actor/router.ts +22 -19
- package/src/actor/unstable-react.ts +1 -1
- package/src/actor/utils.ts +6 -2
- package/src/client/actor-common.ts +1 -1
- package/src/client/actor-conn.ts +152 -91
- package/src/client/actor-handle.ts +85 -25
- package/src/client/actor-query.ts +65 -0
- package/src/client/client.ts +29 -98
- package/src/client/config.ts +44 -0
- package/src/client/errors.ts +1 -0
- package/src/client/log.ts +2 -4
- package/src/client/mod.ts +16 -12
- package/src/client/raw-utils.ts +82 -25
- package/src/client/utils.ts +5 -3
- package/src/common/fake-event-source.ts +10 -9
- package/src/common/inline-websocket-adapter2.ts +39 -30
- package/src/common/log.ts +176 -101
- package/src/common/logfmt.ts +21 -30
- package/src/common/router.ts +12 -19
- package/src/common/utils.ts +27 -13
- package/src/common/websocket.ts +0 -1
- package/src/driver-helpers/mod.ts +1 -1
- package/src/driver-test-suite/log.ts +1 -3
- package/src/driver-test-suite/mod.ts +87 -61
- package/src/driver-test-suite/test-inline-client-driver.ts +441 -255
- package/src/driver-test-suite/tests/actor-error-handling.ts +4 -12
- package/src/driver-test-suite/tests/actor-handle.ts +33 -0
- package/src/driver-test-suite/tests/actor-inspector.ts +2 -1
- package/src/driver-test-suite/tests/manager-driver.ts +5 -3
- package/src/driver-test-suite/tests/raw-http-direct-registry.ts +227 -226
- package/src/driver-test-suite/tests/raw-websocket-direct-registry.ts +393 -392
- package/src/driver-test-suite/tests/request-access.ts +112 -126
- package/src/driver-test-suite/utils.ts +10 -6
- package/src/drivers/default.ts +7 -4
- package/src/drivers/engine/actor-driver.ts +22 -13
- package/src/drivers/engine/config.ts +2 -10
- package/src/drivers/engine/kv.ts +1 -1
- package/src/drivers/engine/log.ts +1 -3
- package/src/drivers/engine/mod.ts +2 -3
- package/src/drivers/file-system/actor.ts +1 -1
- package/src/drivers/file-system/global-state.ts +36 -21
- package/src/drivers/file-system/log.ts +1 -3
- package/src/drivers/file-system/manager.ts +33 -15
- package/src/inspector/config.ts +9 -4
- package/src/inspector/log.ts +1 -1
- package/src/inspector/manager.ts +2 -2
- package/src/inspector/utils.ts +1 -1
- package/src/manager/driver.ts +10 -2
- package/src/manager/hono-websocket-adapter.ts +21 -12
- package/src/manager/log.ts +2 -4
- package/src/manager/mod.ts +1 -1
- package/src/manager/router.ts +378 -1390
- package/src/manager-api/routes/actors-create.ts +16 -0
- package/src/manager-api/routes/actors-delete.ts +4 -0
- package/src/manager-api/routes/actors-get-by-id.ts +7 -0
- package/src/manager-api/routes/actors-get-or-create-by-id.ts +29 -0
- package/src/manager-api/routes/actors-get.ts +7 -0
- package/src/manager-api/routes/common.ts +18 -0
- package/src/mod.ts +0 -2
- package/src/registry/config.ts +1 -1
- package/src/registry/log.ts +2 -4
- package/src/registry/mod.ts +63 -34
- package/src/registry/run-config.ts +39 -26
- package/src/registry/serve.ts +4 -5
- package/src/remote-manager-driver/actor-http-client.ts +74 -0
- package/src/remote-manager-driver/actor-websocket-client.ts +64 -0
- package/src/remote-manager-driver/api-endpoints.ts +79 -0
- package/src/remote-manager-driver/api-utils.ts +46 -0
- package/src/remote-manager-driver/log.ts +5 -0
- package/src/remote-manager-driver/mod.ts +275 -0
- package/src/{drivers/engine → remote-manager-driver}/ws-proxy.ts +24 -14
- package/src/serde.ts +8 -2
- package/src/test/log.ts +1 -3
- package/src/test/mod.ts +17 -16
- package/src/utils.ts +53 -0
- package/dist/tsup/chunk-2CRLFV6Z.cjs +0 -202
- package/dist/tsup/chunk-2CRLFV6Z.cjs.map +0 -1
- package/dist/tsup/chunk-3H7O2A7I.js.map +0 -1
- package/dist/tsup/chunk-42I3OZ3Q.js +0 -15
- package/dist/tsup/chunk-42I3OZ3Q.js.map +0 -1
- package/dist/tsup/chunk-4NSUQZ2H.js.map +0 -1
- package/dist/tsup/chunk-6PDXBYI5.js.map +0 -1
- package/dist/tsup/chunk-6WKQDDUD.cjs.map +0 -1
- package/dist/tsup/chunk-CTBOSFUH.cjs +0 -116
- package/dist/tsup/chunk-CTBOSFUH.cjs.map +0 -1
- package/dist/tsup/chunk-EGVZZFE2.js +0 -2857
- package/dist/tsup/chunk-EGVZZFE2.js.map +0 -1
- package/dist/tsup/chunk-FCCPJNMA.cjs.map +0 -1
- package/dist/tsup/chunk-FLMTTN27.js.map +0 -1
- package/dist/tsup/chunk-GIR3AFFI.cjs.map +0 -1
- package/dist/tsup/chunk-INGJP237.js.map +0 -1
- package/dist/tsup/chunk-KJCJLKRM.js +0 -116
- package/dist/tsup/chunk-KJCJLKRM.js.map +0 -1
- package/dist/tsup/chunk-KUPQZYUQ.cjs +0 -15
- package/dist/tsup/chunk-KUPQZYUQ.cjs.map +0 -1
- package/dist/tsup/chunk-O2MBYIXO.cjs +0 -2857
- package/dist/tsup/chunk-O2MBYIXO.cjs.map +0 -1
- package/dist/tsup/chunk-OGAPU3UG.cjs.map +0 -1
- package/dist/tsup/chunk-OV6AYD4S.js +0 -4406
- package/dist/tsup/chunk-OV6AYD4S.js.map +0 -1
- package/dist/tsup/chunk-PO4VLDWA.js.map +0 -1
- package/dist/tsup/chunk-R2OPSKIV.cjs.map +0 -1
- package/dist/tsup/chunk-TZJKSBUQ.cjs.map +0 -1
- package/dist/tsup/chunk-UBUC5C3G.cjs +0 -189
- package/dist/tsup/chunk-UBUC5C3G.cjs.map +0 -1
- package/dist/tsup/chunk-UIM22YJL.cjs +0 -4406
- package/dist/tsup/chunk-UIM22YJL.cjs.map +0 -1
- package/dist/tsup/chunk-URVFQMYI.cjs +0 -230
- package/dist/tsup/chunk-URVFQMYI.cjs.map +0 -1
- package/dist/tsup/chunk-UVUPOS46.js +0 -230
- package/dist/tsup/chunk-UVUPOS46.js.map +0 -1
- package/dist/tsup/chunk-VRRHBNJC.js +0 -189
- package/dist/tsup/chunk-VRRHBNJC.js.map +0 -1
- package/dist/tsup/chunk-XFSS33EQ.js +0 -202
- package/dist/tsup/chunk-XFSS33EQ.js.map +0 -1
- package/src/client/http-client-driver.ts +0 -326
- package/src/driver-test-suite/tests/actor-auth.ts +0 -591
- package/src/drivers/engine/api-endpoints.ts +0 -128
- package/src/drivers/engine/api-utils.ts +0 -70
- package/src/drivers/engine/manager-driver.ts +0 -391
- package/src/inline-client-driver/log.ts +0 -7
- package/src/inline-client-driver/mod.ts +0 -385
- package/src/manager/auth.ts +0 -121
- /package/src/{drivers/engine → actor}/keys.test.ts +0 -0
- /package/src/{drivers/engine → actor}/keys.ts +0 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as cbor from "cbor-x";
|
|
2
2
|
import type { Context as HonoContext } from "hono";
|
|
3
|
+
import invariant from "invariant";
|
|
3
4
|
import type { WebSocket } from "ws";
|
|
4
5
|
import type { Encoding } from "@/actor/protocol/serde";
|
|
5
6
|
import {
|
|
@@ -8,244 +9,110 @@ import {
|
|
|
8
9
|
HEADER_ENCODING,
|
|
9
10
|
} from "@/actor/router-endpoints";
|
|
10
11
|
import { assertUnreachable } from "@/actor/utils";
|
|
11
|
-
import type { ClientDriver } from "@/client/client";
|
|
12
12
|
import { ActorError as ClientActorError } from "@/client/errors";
|
|
13
13
|
import type { Transport } from "@/client/mod";
|
|
14
14
|
import type { UniversalEventSource } from "@/common/eventsource-interface";
|
|
15
|
+
import type { DeconstructedError } from "@/common/utils";
|
|
15
16
|
import { importWebSocket } from "@/common/websocket";
|
|
17
|
+
import {
|
|
18
|
+
type ActorOutput,
|
|
19
|
+
type CreateInput,
|
|
20
|
+
type GetForIdInput,
|
|
21
|
+
type GetOrCreateWithKeyInput,
|
|
22
|
+
type GetWithKeyInput,
|
|
23
|
+
HEADER_ACTOR_ID,
|
|
24
|
+
type ManagerDisplayInformation,
|
|
25
|
+
type ManagerDriver,
|
|
26
|
+
} from "@/driver-helpers/mod";
|
|
16
27
|
import type { ActorQuery } from "@/manager/protocol/query";
|
|
17
|
-
import type {
|
|
18
|
-
TestInlineDriverCallRequest,
|
|
19
|
-
TestInlineDriverCallResponse,
|
|
20
|
-
} from "@/manager/router";
|
|
28
|
+
import type { UniversalWebSocket } from "@/mod";
|
|
21
29
|
import type * as protocol from "@/schemas/client-protocol/mod";
|
|
22
30
|
import { logger } from "./log";
|
|
23
31
|
|
|
32
|
+
export interface TestInlineDriverCallRequest {
|
|
33
|
+
encoding: Encoding;
|
|
34
|
+
transport: Transport;
|
|
35
|
+
method: string;
|
|
36
|
+
args: unknown[];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export type TestInlineDriverCallResponse<T> =
|
|
40
|
+
| {
|
|
41
|
+
ok: T;
|
|
42
|
+
}
|
|
43
|
+
| {
|
|
44
|
+
err: DeconstructedError;
|
|
45
|
+
};
|
|
46
|
+
|
|
24
47
|
/**
|
|
25
48
|
* Creates a client driver used for testing the inline client driver. This will send a request to the HTTP server which will then internally call the internal client and return the response.
|
|
26
49
|
*/
|
|
27
50
|
export function createTestInlineClientDriver(
|
|
28
51
|
endpoint: string,
|
|
52
|
+
encoding: Encoding,
|
|
29
53
|
transport: Transport,
|
|
30
|
-
):
|
|
54
|
+
): ManagerDriver {
|
|
31
55
|
return {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
56
|
+
getForId(input: GetForIdInput): Promise<ActorOutput | undefined> {
|
|
57
|
+
return makeInlineRequest(endpoint, encoding, transport, "getForId", [
|
|
58
|
+
input,
|
|
59
|
+
]);
|
|
60
|
+
},
|
|
61
|
+
getWithKey(input: GetWithKeyInput): Promise<ActorOutput | undefined> {
|
|
62
|
+
return makeInlineRequest(endpoint, encoding, transport, "getWithKey", [
|
|
63
|
+
input,
|
|
64
|
+
]);
|
|
65
|
+
},
|
|
66
|
+
getOrCreateWithKey(input: GetOrCreateWithKeyInput): Promise<ActorOutput> {
|
|
67
|
+
return makeInlineRequest(
|
|
41
68
|
endpoint,
|
|
42
69
|
encoding,
|
|
43
70
|
transport,
|
|
44
|
-
"
|
|
45
|
-
[
|
|
71
|
+
"getOrCreateWithKey",
|
|
72
|
+
[input],
|
|
46
73
|
);
|
|
47
74
|
},
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
encodingKind: Encoding,
|
|
53
|
-
params: unknown,
|
|
54
|
-
): Promise<string> => {
|
|
55
|
-
return makeInlineRequest<string>(
|
|
56
|
-
endpoint,
|
|
57
|
-
encodingKind,
|
|
58
|
-
transport,
|
|
59
|
-
"resolveActorId",
|
|
60
|
-
[undefined, actorQuery, encodingKind, params],
|
|
61
|
-
);
|
|
75
|
+
createActor(input: CreateInput): Promise<ActorOutput> {
|
|
76
|
+
return makeInlineRequest(endpoint, encoding, transport, "createActor", [
|
|
77
|
+
input,
|
|
78
|
+
]);
|
|
62
79
|
},
|
|
63
|
-
|
|
64
|
-
connectWebSocket: async (
|
|
65
|
-
_c: HonoContext | undefined,
|
|
66
|
-
actorQuery: ActorQuery,
|
|
67
|
-
encodingKind: Encoding,
|
|
68
|
-
params: unknown,
|
|
69
|
-
): Promise<WebSocket> => {
|
|
70
|
-
const WebSocket = await importWebSocket();
|
|
71
|
-
|
|
72
|
-
logger().debug("creating websocket connection via test inline driver", {
|
|
73
|
-
actorQuery,
|
|
74
|
-
encodingKind,
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
// Create WebSocket connection to the test endpoint
|
|
78
|
-
const wsUrl = new URL(
|
|
79
|
-
`${endpoint}/registry/.test/inline-driver/connect-websocket`,
|
|
80
|
-
);
|
|
81
|
-
wsUrl.searchParams.set("actorQuery", JSON.stringify(actorQuery));
|
|
82
|
-
if (params !== undefined)
|
|
83
|
-
wsUrl.searchParams.set("params", JSON.stringify(params));
|
|
84
|
-
wsUrl.searchParams.set("encodingKind", encodingKind);
|
|
85
|
-
|
|
86
|
-
// Convert http/https to ws/wss
|
|
87
|
-
const wsProtocol = wsUrl.protocol === "https:" ? "wss:" : "ws:";
|
|
88
|
-
const finalWsUrl = `${wsProtocol}//${wsUrl.host}${wsUrl.pathname}${wsUrl.search}`;
|
|
89
|
-
|
|
90
|
-
logger().debug("connecting to websocket", { url: finalWsUrl });
|
|
91
|
-
|
|
92
|
-
// Create and return the WebSocket
|
|
93
|
-
// Node & browser WebSocket types are incompatible
|
|
94
|
-
const ws = new WebSocket(finalWsUrl, [
|
|
95
|
-
// HACK: See packages/drivers/cloudflare-workers/src/websocket.ts
|
|
96
|
-
"rivetkit",
|
|
97
|
-
]) as any;
|
|
98
|
-
|
|
99
|
-
return ws;
|
|
100
|
-
},
|
|
101
|
-
|
|
102
|
-
connectSse: async (
|
|
103
|
-
_c: HonoContext | undefined,
|
|
104
|
-
actorQuery: ActorQuery,
|
|
105
|
-
encodingKind: Encoding,
|
|
106
|
-
params: unknown,
|
|
107
|
-
): Promise<UniversalEventSource> => {
|
|
108
|
-
logger().debug("creating sse connection via test inline driver", {
|
|
109
|
-
actorQuery,
|
|
110
|
-
encodingKind,
|
|
111
|
-
params,
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
// Dynamically import EventSource if needed
|
|
115
|
-
const EventSourceImport = await import("eventsource");
|
|
116
|
-
// Handle both ES modules (default) and CommonJS export patterns
|
|
117
|
-
const EventSourceConstructor =
|
|
118
|
-
(EventSourceImport as any).default || EventSourceImport;
|
|
119
|
-
|
|
120
|
-
// Encode parameters for the URL
|
|
121
|
-
const actorQueryParam = encodeURIComponent(JSON.stringify(actorQuery));
|
|
122
|
-
const encodingParam = encodeURIComponent(encodingKind);
|
|
123
|
-
const paramsParam = params
|
|
124
|
-
? encodeURIComponent(JSON.stringify(params))
|
|
125
|
-
: null;
|
|
126
|
-
|
|
127
|
-
// Create SSE connection URL
|
|
128
|
-
const sseUrl = new URL(
|
|
129
|
-
`${endpoint}/registry/.test/inline-driver/connect-sse`,
|
|
130
|
-
);
|
|
131
|
-
sseUrl.searchParams.set("actorQueryRaw", actorQueryParam);
|
|
132
|
-
sseUrl.searchParams.set("encodingKind", encodingParam);
|
|
133
|
-
if (paramsParam) {
|
|
134
|
-
sseUrl.searchParams.set("params", paramsParam);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
logger().debug("connecting to sse", { url: sseUrl.toString() });
|
|
138
|
-
|
|
139
|
-
// Create and return the EventSource
|
|
140
|
-
const eventSource = new EventSourceConstructor(sseUrl.toString());
|
|
141
|
-
|
|
142
|
-
// Wait for the connection to be established before returning
|
|
143
|
-
await new Promise<void>((resolve, reject) => {
|
|
144
|
-
eventSource.onopen = () => {
|
|
145
|
-
logger().debug("sse connection established");
|
|
146
|
-
resolve();
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
eventSource.onerror = (event: Event) => {
|
|
150
|
-
logger().error("sse connection failed", { event });
|
|
151
|
-
reject(new Error("Failed to establish SSE connection"));
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
// Set a timeout in case the connection never establishes
|
|
155
|
-
setTimeout(() => {
|
|
156
|
-
if (eventSource.readyState !== EventSourceConstructor.OPEN) {
|
|
157
|
-
reject(new Error("SSE connection timed out"));
|
|
158
|
-
}
|
|
159
|
-
}, 10000); // 10 second timeout
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
return eventSource as UniversalEventSource;
|
|
163
|
-
},
|
|
164
|
-
|
|
165
|
-
sendHttpMessage: async (
|
|
166
|
-
_c: HonoContext | undefined,
|
|
80
|
+
async sendRequest(
|
|
167
81
|
actorId: string,
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
connectionToken: string,
|
|
171
|
-
message: protocol.ToServer,
|
|
172
|
-
): Promise<void> => {
|
|
173
|
-
logger().debug("sending http message via test inline driver", {
|
|
174
|
-
actorId,
|
|
175
|
-
encoding,
|
|
176
|
-
connectionId,
|
|
177
|
-
transport,
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
const result = await fetch(
|
|
181
|
-
`${endpoint}/registry/.test/inline-driver/call`,
|
|
182
|
-
{
|
|
183
|
-
method: "POST",
|
|
184
|
-
headers: {
|
|
185
|
-
"Content-Type": "application/json",
|
|
186
|
-
},
|
|
187
|
-
body: JSON.stringify({
|
|
188
|
-
encoding,
|
|
189
|
-
transport,
|
|
190
|
-
method: "sendHttpMessage",
|
|
191
|
-
args: [
|
|
192
|
-
undefined,
|
|
193
|
-
actorId,
|
|
194
|
-
encoding,
|
|
195
|
-
connectionId,
|
|
196
|
-
connectionToken,
|
|
197
|
-
message,
|
|
198
|
-
],
|
|
199
|
-
} satisfies TestInlineDriverCallRequest),
|
|
200
|
-
},
|
|
201
|
-
);
|
|
202
|
-
|
|
203
|
-
if (!result.ok) {
|
|
204
|
-
throw new Error(`Failed to send HTTP message: ${result.statusText}`);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
// Discard response
|
|
208
|
-
await result.body?.cancel();
|
|
209
|
-
},
|
|
210
|
-
|
|
211
|
-
rawHttpRequest: async (
|
|
212
|
-
_c: HonoContext | undefined,
|
|
213
|
-
actorQuery: ActorQuery,
|
|
214
|
-
encoding: Encoding,
|
|
215
|
-
params: unknown,
|
|
216
|
-
path: string,
|
|
217
|
-
init: RequestInit,
|
|
218
|
-
): Promise<Response> => {
|
|
82
|
+
actorRequest: Request,
|
|
83
|
+
): Promise<Response> {
|
|
219
84
|
// Normalize path to match other drivers
|
|
220
|
-
const
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
85
|
+
const oldUrl = new URL(actorRequest.url);
|
|
86
|
+
const normalizedPath = oldUrl.pathname.startsWith("/")
|
|
87
|
+
? oldUrl.pathname.slice(1)
|
|
88
|
+
: oldUrl.pathname;
|
|
89
|
+
const pathWithQuery = normalizedPath + oldUrl.search;
|
|
90
|
+
|
|
91
|
+
logger().debug({
|
|
92
|
+
msg: "sending raw http request via test inline driver",
|
|
93
|
+
actorId,
|
|
224
94
|
encoding,
|
|
225
|
-
path:
|
|
95
|
+
path: pathWithQuery,
|
|
226
96
|
});
|
|
227
97
|
|
|
228
98
|
// Use the dedicated raw HTTP endpoint
|
|
229
|
-
const url = `${endpoint}
|
|
99
|
+
const url = `${endpoint}/.test/inline-driver/send-request/${pathWithQuery}`;
|
|
230
100
|
|
|
231
|
-
logger().debug("rewriting http url",
|
|
232
|
-
from: path,
|
|
233
|
-
to: url,
|
|
234
|
-
});
|
|
101
|
+
logger().debug({ msg: "rewriting http url", from: oldUrl, to: url });
|
|
235
102
|
|
|
236
103
|
// Merge headers with our metadata
|
|
237
|
-
const headers = new Headers(
|
|
238
|
-
headers.set(
|
|
239
|
-
headers.set(HEADER_ENCODING, encoding);
|
|
240
|
-
if (params !== undefined) {
|
|
241
|
-
headers.set(HEADER_CONN_PARAMS, JSON.stringify(params));
|
|
242
|
-
}
|
|
104
|
+
const headers = new Headers(actorRequest.headers);
|
|
105
|
+
headers.set(HEADER_ACTOR_ID, actorId);
|
|
243
106
|
|
|
244
107
|
// Forward the request directly
|
|
245
|
-
const response = await fetch(
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
108
|
+
const response = await fetch(
|
|
109
|
+
new Request(url, {
|
|
110
|
+
method: actorRequest.method,
|
|
111
|
+
headers,
|
|
112
|
+
body: actorRequest.body,
|
|
113
|
+
signal: actorRequest.signal,
|
|
114
|
+
}),
|
|
115
|
+
);
|
|
249
116
|
|
|
250
117
|
// Check if it's an error response from our handler
|
|
251
118
|
if (
|
|
@@ -281,53 +148,37 @@ export function createTestInlineClientDriver(
|
|
|
281
148
|
|
|
282
149
|
return response;
|
|
283
150
|
},
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
actorQuery: ActorQuery,
|
|
151
|
+
async openWebSocket(
|
|
152
|
+
path: string,
|
|
153
|
+
actorId: string,
|
|
288
154
|
encoding: Encoding,
|
|
289
155
|
params: unknown,
|
|
290
|
-
|
|
291
|
-
protocols: string | string[] | undefined,
|
|
292
|
-
): Promise<WebSocket> => {
|
|
293
|
-
logger().debug("test inline driver rawWebSocket called");
|
|
156
|
+
): Promise<UniversalWebSocket> {
|
|
294
157
|
const WebSocket = await importWebSocket();
|
|
295
158
|
|
|
296
159
|
// Normalize path to match other drivers
|
|
297
160
|
const normalizedPath = path.startsWith("/") ? path.slice(1) : path;
|
|
298
161
|
|
|
299
|
-
logger().debug(
|
|
300
|
-
"creating
|
|
301
|
-
|
|
302
|
-
actorQuery,
|
|
303
|
-
encoding,
|
|
304
|
-
path: normalizedPath,
|
|
305
|
-
protocols,
|
|
306
|
-
},
|
|
307
|
-
);
|
|
162
|
+
logger().debug({
|
|
163
|
+
msg: "creating websocket connection via test inline driver",
|
|
164
|
+
});
|
|
308
165
|
|
|
309
166
|
// Create WebSocket connection to the test endpoint
|
|
167
|
+
// Use a placeholder path and pass the actual path as a query param to avoid mixing user query params with internal ones
|
|
310
168
|
const wsUrl = new URL(
|
|
311
|
-
`${endpoint}
|
|
169
|
+
`${endpoint}/.test/inline-driver/connect-websocket/ws`,
|
|
312
170
|
);
|
|
313
|
-
wsUrl.searchParams.set("
|
|
171
|
+
wsUrl.searchParams.set("path", normalizedPath);
|
|
172
|
+
wsUrl.searchParams.set("actorId", actorId);
|
|
314
173
|
if (params !== undefined)
|
|
315
174
|
wsUrl.searchParams.set("params", JSON.stringify(params));
|
|
316
175
|
wsUrl.searchParams.set("encodingKind", encoding);
|
|
317
|
-
wsUrl.searchParams.set("path", normalizedPath);
|
|
318
|
-
if (protocols !== undefined)
|
|
319
|
-
wsUrl.searchParams.set("protocols", JSON.stringify(protocols));
|
|
320
176
|
|
|
321
177
|
// Convert http/https to ws/wss
|
|
322
178
|
const wsProtocol = wsUrl.protocol === "https:" ? "wss:" : "ws:";
|
|
323
179
|
const finalWsUrl = `${wsProtocol}//${wsUrl.host}${wsUrl.pathname}${wsUrl.search}`;
|
|
324
180
|
|
|
325
|
-
logger().debug("connecting to
|
|
326
|
-
|
|
327
|
-
logger().debug("rewriting websocket url", {
|
|
328
|
-
from: path,
|
|
329
|
-
to: finalWsUrl,
|
|
330
|
-
});
|
|
181
|
+
logger().debug({ msg: "connecting to websocket", url: finalWsUrl });
|
|
331
182
|
|
|
332
183
|
// Create and return the WebSocket
|
|
333
184
|
// Node & browser WebSocket types are incompatible
|
|
@@ -336,14 +187,350 @@ export function createTestInlineClientDriver(
|
|
|
336
187
|
"rivetkit",
|
|
337
188
|
]) as any;
|
|
338
189
|
|
|
339
|
-
logger().debug("test inline driver created websocket", {
|
|
340
|
-
readyState: ws.readyState,
|
|
341
|
-
url: ws.url,
|
|
342
|
-
});
|
|
343
|
-
|
|
344
190
|
return ws;
|
|
345
191
|
},
|
|
346
|
-
|
|
192
|
+
async proxyRequest(
|
|
193
|
+
c: HonoContext,
|
|
194
|
+
actorRequest: Request,
|
|
195
|
+
actorId: string,
|
|
196
|
+
): Promise<Response> {
|
|
197
|
+
return await this.sendRequest(actorId, actorRequest);
|
|
198
|
+
},
|
|
199
|
+
proxyWebSocket(
|
|
200
|
+
_c: HonoContext,
|
|
201
|
+
_path: string,
|
|
202
|
+
_actorId: string,
|
|
203
|
+
_encoding: Encoding,
|
|
204
|
+
_params: unknown,
|
|
205
|
+
_authData: unknown,
|
|
206
|
+
): Promise<Response> {
|
|
207
|
+
throw "UNIMPLEMENTED";
|
|
208
|
+
// const upgradeWebSocket = this.#runConfig.getUpgradeWebSocket?.();
|
|
209
|
+
// invariant(upgradeWebSocket, "missing getUpgradeWebSocket");
|
|
210
|
+
//
|
|
211
|
+
// const wsHandler = this.openWebSocket(path, actorId, encoding, connParams);
|
|
212
|
+
// return upgradeWebSocket(() => wsHandler)(c, noopNext());
|
|
213
|
+
},
|
|
214
|
+
displayInformation(): ManagerDisplayInformation {
|
|
215
|
+
return { name: "Test Inline", properties: {} };
|
|
216
|
+
},
|
|
217
|
+
|
|
218
|
+
// action: async <Args extends Array<unknown> = unknown[], Response = unknown>(
|
|
219
|
+
// _c: HonoContext | undefined,
|
|
220
|
+
// actorQuery: ActorQuery,
|
|
221
|
+
// encoding: Encoding,
|
|
222
|
+
// params: unknown,
|
|
223
|
+
// name: string,
|
|
224
|
+
// args: Args,
|
|
225
|
+
// ): Promise<Response> => {
|
|
226
|
+
// return makeInlineRequest<Response>(
|
|
227
|
+
// endpoint,
|
|
228
|
+
// encoding,
|
|
229
|
+
// transport,
|
|
230
|
+
// "action",
|
|
231
|
+
// [undefined, actorQuery, encoding, params, name, args],
|
|
232
|
+
// );
|
|
233
|
+
// },
|
|
234
|
+
//
|
|
235
|
+
// resolveActorId: async (
|
|
236
|
+
// _c: HonoContext | undefined,
|
|
237
|
+
// actorQuery: ActorQuery,
|
|
238
|
+
// encodingKind: Encoding,
|
|
239
|
+
// params: unknown,
|
|
240
|
+
// ): Promise<string> => {
|
|
241
|
+
// return makeInlineRequest<string>(
|
|
242
|
+
// endpoint,
|
|
243
|
+
// encodingKind,
|
|
244
|
+
// transport,
|
|
245
|
+
// "resolveActorId",
|
|
246
|
+
// [undefined, actorQuery, encodingKind, params],
|
|
247
|
+
// );
|
|
248
|
+
// },
|
|
249
|
+
//
|
|
250
|
+
// connectWebSocket: async (
|
|
251
|
+
// _c: HonoContext | undefined,
|
|
252
|
+
// actorQuery: ActorQuery,
|
|
253
|
+
// encodingKind: Encoding,
|
|
254
|
+
// params: unknown,
|
|
255
|
+
// ): Promise<WebSocket> => {
|
|
256
|
+
// const WebSocket = await importWebSocket();
|
|
257
|
+
//
|
|
258
|
+
// logger().debug({
|
|
259
|
+
// msg: "creating websocket connection via test inline driver",
|
|
260
|
+
// actorQuery,
|
|
261
|
+
// encodingKind,
|
|
262
|
+
// });
|
|
263
|
+
//
|
|
264
|
+
// // Create WebSocket connection to the test endpoint
|
|
265
|
+
// const wsUrl = new URL(
|
|
266
|
+
// `${endpoint}/registry/.test/inline-driver/connect-websocket`,
|
|
267
|
+
// );
|
|
268
|
+
// wsUrl.searchParams.set("actorQuery", JSON.stringify(actorQuery));
|
|
269
|
+
// if (params !== undefined)
|
|
270
|
+
// wsUrl.searchParams.set("params", JSON.stringify(params));
|
|
271
|
+
// wsUrl.searchParams.set("encodingKind", encodingKind);
|
|
272
|
+
//
|
|
273
|
+
// // Convert http/https to ws/wss
|
|
274
|
+
// const wsProtocol = wsUrl.protocol === "https:" ? "wss:" : "ws:";
|
|
275
|
+
// const finalWsUrl = `${wsProtocol}//${wsUrl.host}${wsUrl.pathname}${wsUrl.search}`;
|
|
276
|
+
//
|
|
277
|
+
// logger().debug({ msg: "connecting to websocket", url: finalWsUrl });
|
|
278
|
+
//
|
|
279
|
+
// // Create and return the WebSocket
|
|
280
|
+
// // Node & browser WebSocket types are incompatible
|
|
281
|
+
// const ws = new WebSocket(finalWsUrl, [
|
|
282
|
+
// // HACK: See packages/drivers/cloudflare-workers/src/websocket.ts
|
|
283
|
+
// "rivetkit",
|
|
284
|
+
// ]) as any;
|
|
285
|
+
//
|
|
286
|
+
// return ws;
|
|
287
|
+
// },
|
|
288
|
+
//
|
|
289
|
+
// connectSse: async (
|
|
290
|
+
// _c: HonoContext | undefined,
|
|
291
|
+
// actorQuery: ActorQuery,
|
|
292
|
+
// encodingKind: Encoding,
|
|
293
|
+
// params: unknown,
|
|
294
|
+
// ): Promise<UniversalEventSource> => {
|
|
295
|
+
// logger().debug({
|
|
296
|
+
// msg: "creating sse connection via test inline driver",
|
|
297
|
+
// actorQuery,
|
|
298
|
+
// encodingKind,
|
|
299
|
+
// params,
|
|
300
|
+
// });
|
|
301
|
+
//
|
|
302
|
+
// // Dynamically import EventSource if needed
|
|
303
|
+
// const EventSourceImport = await import("eventsource");
|
|
304
|
+
// // Handle both ES modules (default) and CommonJS export patterns
|
|
305
|
+
// const EventSourceConstructor =
|
|
306
|
+
// (EventSourceImport as any).default || EventSourceImport;
|
|
307
|
+
//
|
|
308
|
+
// // Encode parameters for the URL
|
|
309
|
+
// const actorQueryParam = encodeURIComponent(JSON.stringify(actorQuery));
|
|
310
|
+
// const encodingParam = encodeURIComponent(encodingKind);
|
|
311
|
+
// const paramsParam = params
|
|
312
|
+
// ? encodeURIComponent(JSON.stringify(params))
|
|
313
|
+
// : null;
|
|
314
|
+
//
|
|
315
|
+
// // Create SSE connection URL
|
|
316
|
+
// const sseUrl = new URL(
|
|
317
|
+
// `${endpoint}/registry/.test/inline-driver/connect-sse`,
|
|
318
|
+
// );
|
|
319
|
+
// sseUrl.searchParams.set("actorQueryRaw", actorQueryParam);
|
|
320
|
+
// sseUrl.searchParams.set("encodingKind", encodingParam);
|
|
321
|
+
// if (paramsParam) {
|
|
322
|
+
// sseUrl.searchParams.set("params", paramsParam);
|
|
323
|
+
// }
|
|
324
|
+
//
|
|
325
|
+
// logger().debug({ msg: "connecting to sse", url: sseUrl.toString() });
|
|
326
|
+
//
|
|
327
|
+
// // Create and return the EventSource
|
|
328
|
+
// const eventSource = new EventSourceConstructor(sseUrl.toString());
|
|
329
|
+
//
|
|
330
|
+
// // Wait for the connection to be established before returning
|
|
331
|
+
// await new Promise<void>((resolve, reject) => {
|
|
332
|
+
// eventSource.onopen = () => {
|
|
333
|
+
// logger().debug({ msg: "sse connection established" });
|
|
334
|
+
// resolve();
|
|
335
|
+
// };
|
|
336
|
+
//
|
|
337
|
+
// eventSource.onerror = (event: Event) => {
|
|
338
|
+
// logger().error({ msg: "sse connection failed", event });
|
|
339
|
+
// reject(new Error("Failed to establish SSE connection"));
|
|
340
|
+
// };
|
|
341
|
+
//
|
|
342
|
+
// // Set a timeout in case the connection never establishes
|
|
343
|
+
// setTimeout(() => {
|
|
344
|
+
// if (eventSource.readyState !== EventSourceConstructor.OPEN) {
|
|
345
|
+
// reject(new Error("SSE connection timed out"));
|
|
346
|
+
// }
|
|
347
|
+
// }, 10000); // 10 second timeout
|
|
348
|
+
// });
|
|
349
|
+
//
|
|
350
|
+
// return eventSource as UniversalEventSource;
|
|
351
|
+
// },
|
|
352
|
+
//
|
|
353
|
+
// sendHttpMessage: async (
|
|
354
|
+
// _c: HonoContext | undefined,
|
|
355
|
+
// actorId: string,
|
|
356
|
+
// encoding: Encoding,
|
|
357
|
+
// connectionId: string,
|
|
358
|
+
// connectionToken: string,
|
|
359
|
+
// message: protocol.ToServer,
|
|
360
|
+
// ): Promise<void> => {
|
|
361
|
+
// logger().debug({
|
|
362
|
+
// msg: "sending http message via test inline driver",
|
|
363
|
+
// actorId,
|
|
364
|
+
// encoding,
|
|
365
|
+
// connectionId,
|
|
366
|
+
// transport,
|
|
367
|
+
// });
|
|
368
|
+
//
|
|
369
|
+
// const result = await fetch(
|
|
370
|
+
// `${endpoint}/registry/.test/inline-driver/call`,
|
|
371
|
+
// {
|
|
372
|
+
// method: "POST",
|
|
373
|
+
// headers: {
|
|
374
|
+
// "Content-Type": "application/json",
|
|
375
|
+
// },
|
|
376
|
+
// body: JSON.stringify({
|
|
377
|
+
// encoding,
|
|
378
|
+
// transport,
|
|
379
|
+
// method: "sendHttpMessage",
|
|
380
|
+
// args: [
|
|
381
|
+
// undefined,
|
|
382
|
+
// actorId,
|
|
383
|
+
// encoding,
|
|
384
|
+
// connectionId,
|
|
385
|
+
// connectionToken,
|
|
386
|
+
// message,
|
|
387
|
+
// ],
|
|
388
|
+
// } satisfies TestInlineDriverCallRequest),
|
|
389
|
+
// },
|
|
390
|
+
// );
|
|
391
|
+
//
|
|
392
|
+
// if (!result.ok) {
|
|
393
|
+
// throw new Error(`Failed to send HTTP message: ${result.statusText}`);
|
|
394
|
+
// }
|
|
395
|
+
//
|
|
396
|
+
// // Discard response
|
|
397
|
+
// await result.body?.cancel();
|
|
398
|
+
// },
|
|
399
|
+
//
|
|
400
|
+
// rawHttpRequest: async (
|
|
401
|
+
// _c: HonoContext | undefined,
|
|
402
|
+
// actorQuery: ActorQuery,
|
|
403
|
+
// encoding: Encoding,
|
|
404
|
+
// params: unknown,
|
|
405
|
+
// path: string,
|
|
406
|
+
// init: RequestInit,
|
|
407
|
+
// ): Promise<Response> => {
|
|
408
|
+
// // Normalize path to match other drivers
|
|
409
|
+
// const normalizedPath = path.startsWith("/") ? path.slice(1) : path;
|
|
410
|
+
//
|
|
411
|
+
// logger().debug({
|
|
412
|
+
// msg: "sending raw http request via test inline driver",
|
|
413
|
+
// actorQuery,
|
|
414
|
+
// encoding,
|
|
415
|
+
// path: normalizedPath,
|
|
416
|
+
// });
|
|
417
|
+
//
|
|
418
|
+
// // Use the dedicated raw HTTP endpoint
|
|
419
|
+
// const url = `${endpoint}/registry/.test/inline-driver/raw-http/${normalizedPath}`;
|
|
420
|
+
//
|
|
421
|
+
// logger().debug({ msg: "rewriting http url", from: path, to: url });
|
|
422
|
+
//
|
|
423
|
+
// // Merge headers with our metadata
|
|
424
|
+
// const headers = new Headers(init.headers);
|
|
425
|
+
// headers.set(HEADER_ACTOR_QUERY, JSON.stringify(actorQuery));
|
|
426
|
+
// headers.set(HEADER_ENCODING, encoding);
|
|
427
|
+
// if (params !== undefined) {
|
|
428
|
+
// headers.set(HEADER_CONN_PARAMS, JSON.stringify(params));
|
|
429
|
+
// }
|
|
430
|
+
//
|
|
431
|
+
// // Forward the request directly
|
|
432
|
+
// const response = await fetch(url, {
|
|
433
|
+
// ...init,
|
|
434
|
+
// headers,
|
|
435
|
+
// });
|
|
436
|
+
//
|
|
437
|
+
// // Check if it's an error response from our handler
|
|
438
|
+
// if (
|
|
439
|
+
// !response.ok &&
|
|
440
|
+
// response.headers.get("content-type")?.includes("application/json")
|
|
441
|
+
// ) {
|
|
442
|
+
// try {
|
|
443
|
+
// // Clone the response to avoid consuming the body
|
|
444
|
+
// const clonedResponse = response.clone();
|
|
445
|
+
// const errorData = (await clonedResponse.json()) as any;
|
|
446
|
+
// if (errorData.error) {
|
|
447
|
+
// // Handle both error formats:
|
|
448
|
+
// // 1. { error: { code, message, metadata } } - structured format
|
|
449
|
+
// // 2. { error: "message" } - simple string format (from custom onFetch handlers)
|
|
450
|
+
// if (typeof errorData.error === "object") {
|
|
451
|
+
// throw new ClientActorError(
|
|
452
|
+
// errorData.error.code,
|
|
453
|
+
// errorData.error.message,
|
|
454
|
+
// errorData.error.metadata,
|
|
455
|
+
// );
|
|
456
|
+
// }
|
|
457
|
+
// // For simple string errors, just return the response as-is
|
|
458
|
+
// // This allows custom onFetch handlers to return their own error formats
|
|
459
|
+
// }
|
|
460
|
+
// } catch (e) {
|
|
461
|
+
// // If it's not our error format, just return the response as-is
|
|
462
|
+
// if (!(e instanceof ClientActorError)) {
|
|
463
|
+
// return response;
|
|
464
|
+
// }
|
|
465
|
+
// throw e;
|
|
466
|
+
// }
|
|
467
|
+
// }
|
|
468
|
+
//
|
|
469
|
+
// return response;
|
|
470
|
+
// },
|
|
471
|
+
//
|
|
472
|
+
// rawWebSocket: async (
|
|
473
|
+
// _c: HonoContext | undefined,
|
|
474
|
+
// actorQuery: ActorQuery,
|
|
475
|
+
// encoding: Encoding,
|
|
476
|
+
// params: unknown,
|
|
477
|
+
// path: string,
|
|
478
|
+
// protocols: string | string[] | undefined,
|
|
479
|
+
// ): Promise<WebSocket> => {
|
|
480
|
+
// logger().debug({ msg: "test inline driver rawWebSocket called" });
|
|
481
|
+
// const WebSocket = await importWebSocket();
|
|
482
|
+
//
|
|
483
|
+
// // Normalize path to match other drivers
|
|
484
|
+
// const normalizedPath = path.startsWith("/") ? path.slice(1) : path;
|
|
485
|
+
//
|
|
486
|
+
// logger().debug({
|
|
487
|
+
// msg: "creating raw websocket connection via test inline driver",
|
|
488
|
+
// actorQuery,
|
|
489
|
+
// encoding,
|
|
490
|
+
// path: normalizedPath,
|
|
491
|
+
// protocols,
|
|
492
|
+
// });
|
|
493
|
+
//
|
|
494
|
+
// // Create WebSocket connection to the test endpoint
|
|
495
|
+
// const wsUrl = new URL(
|
|
496
|
+
// `${endpoint}/registry/.test/inline-driver/raw-websocket`,
|
|
497
|
+
// );
|
|
498
|
+
// wsUrl.searchParams.set("actorQuery", JSON.stringify(actorQuery));
|
|
499
|
+
// if (params !== undefined)
|
|
500
|
+
// wsUrl.searchParams.set("params", JSON.stringify(params));
|
|
501
|
+
// wsUrl.searchParams.set("encodingKind", encoding);
|
|
502
|
+
// wsUrl.searchParams.set("path", normalizedPath);
|
|
503
|
+
// if (protocols !== undefined)
|
|
504
|
+
// wsUrl.searchParams.set("protocols", JSON.stringify(protocols));
|
|
505
|
+
//
|
|
506
|
+
// // Convert http/https to ws/wss
|
|
507
|
+
// const wsProtocol = wsUrl.protocol === "https:" ? "wss:" : "ws:";
|
|
508
|
+
// const finalWsUrl = `${wsProtocol}//${wsUrl.host}${wsUrl.pathname}${wsUrl.search}`;
|
|
509
|
+
//
|
|
510
|
+
// logger().debug({ msg: "connecting to raw websocket", url: finalWsUrl });
|
|
511
|
+
//
|
|
512
|
+
// logger().debug({
|
|
513
|
+
// msg: "rewriting websocket url",
|
|
514
|
+
// from: path,
|
|
515
|
+
// to: finalWsUrl,
|
|
516
|
+
// });
|
|
517
|
+
//
|
|
518
|
+
// // Create and return the WebSocket
|
|
519
|
+
// // Node & browser WebSocket types are incompatible
|
|
520
|
+
// const ws = new WebSocket(finalWsUrl, [
|
|
521
|
+
// // HACK: See packages/drivers/cloudflare-workers/src/websocket.ts
|
|
522
|
+
// "rivetkit",
|
|
523
|
+
// ]) as any;
|
|
524
|
+
//
|
|
525
|
+
// logger().debug({
|
|
526
|
+
// msg: "test inline driver created websocket",
|
|
527
|
+
// readyState: ws.readyState,
|
|
528
|
+
// url: ws.url,
|
|
529
|
+
// });
|
|
530
|
+
//
|
|
531
|
+
// return ws;
|
|
532
|
+
// },
|
|
533
|
+
} satisfies ManagerDriver;
|
|
347
534
|
}
|
|
348
535
|
|
|
349
536
|
async function makeInlineRequest<T>(
|
|
@@ -353,7 +540,8 @@ async function makeInlineRequest<T>(
|
|
|
353
540
|
method: string,
|
|
354
541
|
args: unknown[],
|
|
355
542
|
): Promise<T> {
|
|
356
|
-
logger().debug(
|
|
543
|
+
logger().debug({
|
|
544
|
+
msg: "sending inline request",
|
|
357
545
|
encoding,
|
|
358
546
|
transport,
|
|
359
547
|
method,
|
|
@@ -361,21 +549,18 @@ async function makeInlineRequest<T>(
|
|
|
361
549
|
});
|
|
362
550
|
|
|
363
551
|
// Call driver
|
|
364
|
-
const response = await fetch(
|
|
365
|
-
|
|
366
|
-
{
|
|
367
|
-
|
|
368
|
-
headers: {
|
|
369
|
-
"Content-Type": "application/json",
|
|
370
|
-
},
|
|
371
|
-
body: cbor.encode({
|
|
372
|
-
encoding,
|
|
373
|
-
transport,
|
|
374
|
-
method,
|
|
375
|
-
args,
|
|
376
|
-
} satisfies TestInlineDriverCallRequest),
|
|
552
|
+
const response = await fetch(`${endpoint}/.test/inline-driver/call`, {
|
|
553
|
+
method: "POST",
|
|
554
|
+
headers: {
|
|
555
|
+
"Content-Type": "application/json",
|
|
377
556
|
},
|
|
378
|
-
|
|
557
|
+
body: cbor.encode({
|
|
558
|
+
encoding,
|
|
559
|
+
transport,
|
|
560
|
+
method,
|
|
561
|
+
args,
|
|
562
|
+
} satisfies TestInlineDriverCallRequest),
|
|
563
|
+
});
|
|
379
564
|
|
|
380
565
|
if (!response.ok) {
|
|
381
566
|
throw new Error(`Failed to call inline ${method}: ${response.statusText}`);
|
|
@@ -392,6 +577,7 @@ async function makeInlineRequest<T>(
|
|
|
392
577
|
return callResponse.ok;
|
|
393
578
|
} else if ("err" in callResponse) {
|
|
394
579
|
throw new ClientActorError(
|
|
580
|
+
callResponse.err.group,
|
|
395
581
|
callResponse.err.code,
|
|
396
582
|
callResponse.err.message,
|
|
397
583
|
callResponse.err.metadata,
|