rivetkit 2.0.3 → 2.0.4
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-6PDXBYI5.js → chunk-3F2YSRJL.js} +8 -23
- package/dist/tsup/chunk-3F2YSRJL.js.map +1 -0
- package/dist/tsup/chunk-4CXBCT26.cjs +250 -0
- package/dist/tsup/chunk-4CXBCT26.cjs.map +1 -0
- package/dist/tsup/chunk-4R73YDN3.cjs +20 -0
- package/dist/tsup/chunk-4R73YDN3.cjs.map +1 -0
- package/dist/tsup/{chunk-OGAPU3UG.cjs → chunk-6LJT3QRL.cjs} +39 -25
- package/dist/tsup/chunk-6LJT3QRL.cjs.map +1 -0
- package/dist/tsup/{chunk-6WKQDDUD.cjs → chunk-GICQ3YCU.cjs} +143 -141
- package/dist/tsup/chunk-GICQ3YCU.cjs.map +1 -0
- package/dist/tsup/{chunk-FLMTTN27.js → chunk-H26RP6GD.js} +15 -8
- package/dist/tsup/chunk-H26RP6GD.js.map +1 -0
- package/dist/tsup/chunk-HI3HWJRC.js +20 -0
- package/dist/tsup/chunk-HI3HWJRC.js.map +1 -0
- package/dist/tsup/{chunk-4NSUQZ2H.js → chunk-HLLF4B4Q.js} +116 -114
- package/dist/tsup/chunk-HLLF4B4Q.js.map +1 -0
- package/dist/tsup/{chunk-FCCPJNMA.cjs → chunk-IH6CKNDW.cjs} +12 -27
- package/dist/tsup/chunk-IH6CKNDW.cjs.map +1 -0
- package/dist/tsup/chunk-LV2S3OU3.js +250 -0
- package/dist/tsup/chunk-LV2S3OU3.js.map +1 -0
- package/dist/tsup/{chunk-R2OPSKIV.cjs → chunk-LWNKVZG5.cjs} +20 -13
- package/dist/tsup/chunk-LWNKVZG5.cjs.map +1 -0
- package/dist/tsup/{chunk-INGJP237.js → chunk-NFU2BBT5.js} +102 -43
- package/dist/tsup/chunk-NFU2BBT5.js.map +1 -0
- package/dist/tsup/{chunk-3H7O2A7I.js → chunk-PQY7KKTL.js} +33 -19
- package/dist/tsup/chunk-PQY7KKTL.js.map +1 -0
- package/dist/tsup/{chunk-PO4VLDWA.js → chunk-QK72M5JB.js} +3 -5
- package/dist/tsup/chunk-QK72M5JB.js.map +1 -0
- package/dist/tsup/{chunk-TZJKSBUQ.cjs → chunk-QNNXFOQV.cjs} +3 -5
- package/dist/tsup/chunk-QNNXFOQV.cjs.map +1 -0
- package/dist/tsup/{chunk-GIR3AFFI.cjs → chunk-SBHHJ6QS.cjs} +102 -43
- package/dist/tsup/chunk-SBHHJ6QS.cjs.map +1 -0
- package/dist/tsup/chunk-TQ62L3X7.js +325 -0
- package/dist/tsup/chunk-TQ62L3X7.js.map +1 -0
- package/dist/tsup/chunk-VO7ZRVVD.cjs +6293 -0
- package/dist/tsup/chunk-VO7ZRVVD.cjs.map +1 -0
- package/dist/tsup/chunk-WHBPJNGW.cjs +325 -0
- package/dist/tsup/chunk-WHBPJNGW.cjs.map +1 -0
- package/dist/tsup/chunk-XJQHKJ4P.js +6293 -0
- package/dist/tsup/chunk-XJQHKJ4P.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-BI-6UIBJ.d.ts} +196 -226
- package/dist/tsup/{connection-BR_Ve4ku.d.cts → connection-Dyd4NLGW.d.cts} +196 -226
- 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 +155 -1363
- package/dist/tsup/driver-test-suite/mod.cjs.map +1 -1
- package/dist/tsup/driver-test-suite/mod.d.cts +11 -5
- package/dist/tsup/driver-test-suite/mod.d.ts +11 -5
- package/dist/tsup/driver-test-suite/mod.js +876 -2084
- 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-BTe_Rsdn.d.cts} +2 -3
- package/dist/tsup/{router-endpoints-AYkXG8Tl.d.cts → router-endpoints-CBSrKHmo.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 +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/package.json +4 -4
- 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 +97 -35
- 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 +41 -38
- package/src/actor/router.ts +20 -18
- 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 +86 -60
- package/src/driver-test-suite/tests/actor-handle.ts +33 -0
- 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 +13 -10
- 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 +33 -20
- package/src/drivers/file-system/log.ts +1 -3
- package/src/drivers/file-system/manager.ts +31 -8
- 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 +277 -1657
- 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 +57 -24
- package/src/registry/run-config.ts +31 -33
- package/src/registry/serve.ts +4 -5
- package/src/remote-manager-driver/actor-http-client.ts +72 -0
- package/src/remote-manager-driver/actor-websocket-client.ts +63 -0
- package/src/remote-manager-driver/api-endpoints.ts +79 -0
- package/src/remote-manager-driver/api-utils.ts +43 -0
- package/src/remote-manager-driver/log.ts +5 -0
- package/src/remote-manager-driver/mod.ts +274 -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/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/test-inline-client-driver.ts +0 -402
- 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,326 +0,0 @@
|
|
|
1
|
-
import * as cbor from "cbor-x";
|
|
2
|
-
import type { Context as HonoContext } from "hono";
|
|
3
|
-
import type { WebSocket } from "ws";
|
|
4
|
-
import type { Encoding } from "@/actor/protocol/serde";
|
|
5
|
-
import {
|
|
6
|
-
HEADER_ACTOR_ID,
|
|
7
|
-
HEADER_ACTOR_QUERY,
|
|
8
|
-
HEADER_CONN_ID,
|
|
9
|
-
HEADER_CONN_PARAMS,
|
|
10
|
-
HEADER_CONN_TOKEN,
|
|
11
|
-
HEADER_ENCODING,
|
|
12
|
-
} from "@/actor/router-endpoints";
|
|
13
|
-
import { importEventSource } from "@/common/eventsource";
|
|
14
|
-
import type { UniversalEventSource } from "@/common/eventsource-interface";
|
|
15
|
-
import { importWebSocket } from "@/common/websocket";
|
|
16
|
-
import type { ActorQuery } from "@/manager/protocol/query";
|
|
17
|
-
import type * as protocol from "@/schemas/client-protocol/mod";
|
|
18
|
-
import {
|
|
19
|
-
HTTP_ACTION_REQUEST_VERSIONED,
|
|
20
|
-
HTTP_ACTION_RESPONSE_VERSIONED,
|
|
21
|
-
HTTP_RESOLVE_REQUEST_VERSIONED,
|
|
22
|
-
HTTP_RESOLVE_RESPONSE_VERSIONED,
|
|
23
|
-
TO_SERVER_VERSIONED,
|
|
24
|
-
} from "@/schemas/client-protocol/versioned";
|
|
25
|
-
import { serializeWithEncoding, wsBinaryTypeForEncoding } from "@/serde";
|
|
26
|
-
import { assertUnreachable, bufferToArrayBuffer, httpUserAgent } from "@/utils";
|
|
27
|
-
import type { ClientDriver } from "./client";
|
|
28
|
-
import * as errors from "./errors";
|
|
29
|
-
import { logger } from "./log";
|
|
30
|
-
import { sendHttpRequest } from "./utils";
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Client driver that communicates with the manager via HTTP.
|
|
34
|
-
*/
|
|
35
|
-
export function createHttpClientDriver(managerEndpoint: string): ClientDriver {
|
|
36
|
-
// Lazily import the dynamic imports so we don't have to turn `createClient` in to an async fn
|
|
37
|
-
const dynamicImports = (async () => {
|
|
38
|
-
// Import dynamic dependencies
|
|
39
|
-
const [WebSocket, EventSource] = await Promise.all([
|
|
40
|
-
importWebSocket(),
|
|
41
|
-
importEventSource(),
|
|
42
|
-
]);
|
|
43
|
-
return {
|
|
44
|
-
WebSocket,
|
|
45
|
-
EventSource,
|
|
46
|
-
};
|
|
47
|
-
})();
|
|
48
|
-
|
|
49
|
-
const driver: ClientDriver = {
|
|
50
|
-
action: async <Args extends Array<unknown> = unknown[], Response = unknown>(
|
|
51
|
-
_c: HonoContext | undefined,
|
|
52
|
-
actorQuery: ActorQuery,
|
|
53
|
-
encoding: Encoding,
|
|
54
|
-
params: unknown,
|
|
55
|
-
name: string,
|
|
56
|
-
args: Args,
|
|
57
|
-
opts: { signal?: AbortSignal } | undefined,
|
|
58
|
-
): Promise<Response> => {
|
|
59
|
-
logger().debug("actor handle action", {
|
|
60
|
-
name,
|
|
61
|
-
args,
|
|
62
|
-
query: actorQuery,
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
const responseData = await sendHttpRequest<
|
|
66
|
-
protocol.HttpActionRequest,
|
|
67
|
-
protocol.HttpActionResponse
|
|
68
|
-
>({
|
|
69
|
-
url: `${managerEndpoint}/registry/actors/actions/${encodeURIComponent(name)}`,
|
|
70
|
-
method: "POST",
|
|
71
|
-
headers: {
|
|
72
|
-
[HEADER_ENCODING]: encoding,
|
|
73
|
-
[HEADER_ACTOR_QUERY]: JSON.stringify(actorQuery),
|
|
74
|
-
...(params !== undefined
|
|
75
|
-
? { [HEADER_CONN_PARAMS]: JSON.stringify(params) }
|
|
76
|
-
: {}),
|
|
77
|
-
},
|
|
78
|
-
body: {
|
|
79
|
-
args: bufferToArrayBuffer(cbor.encode(args)),
|
|
80
|
-
} satisfies protocol.HttpActionRequest,
|
|
81
|
-
encoding: encoding,
|
|
82
|
-
signal: opts?.signal,
|
|
83
|
-
requestVersionedDataHandler: HTTP_ACTION_REQUEST_VERSIONED,
|
|
84
|
-
responseVersionedDataHandler: HTTP_ACTION_RESPONSE_VERSIONED,
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
return cbor.decode(new Uint8Array(responseData.output));
|
|
88
|
-
},
|
|
89
|
-
|
|
90
|
-
resolveActorId: async (
|
|
91
|
-
_c: HonoContext | undefined,
|
|
92
|
-
actorQuery: ActorQuery,
|
|
93
|
-
encodingKind: Encoding,
|
|
94
|
-
params: unknown,
|
|
95
|
-
): Promise<string> => {
|
|
96
|
-
logger().debug("resolving actor ID", { query: actorQuery });
|
|
97
|
-
|
|
98
|
-
try {
|
|
99
|
-
const result = await sendHttpRequest<
|
|
100
|
-
null,
|
|
101
|
-
protocol.HttpResolveResponse
|
|
102
|
-
>({
|
|
103
|
-
url: `${managerEndpoint}/registry/actors/resolve`,
|
|
104
|
-
method: "POST",
|
|
105
|
-
headers: {
|
|
106
|
-
[HEADER_ENCODING]: encodingKind,
|
|
107
|
-
[HEADER_ACTOR_QUERY]: JSON.stringify(actorQuery),
|
|
108
|
-
...(params !== undefined
|
|
109
|
-
? { [HEADER_CONN_PARAMS]: JSON.stringify(params) }
|
|
110
|
-
: {}),
|
|
111
|
-
},
|
|
112
|
-
body: null,
|
|
113
|
-
encoding: encodingKind,
|
|
114
|
-
requestVersionedDataHandler: HTTP_RESOLVE_REQUEST_VERSIONED,
|
|
115
|
-
responseVersionedDataHandler: HTTP_RESOLVE_RESPONSE_VERSIONED,
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
logger().debug("resolved actor ID", { actorId: result.actorId });
|
|
119
|
-
return result.actorId;
|
|
120
|
-
} catch (error) {
|
|
121
|
-
logger().error("failed to resolve actor ID", { error });
|
|
122
|
-
if (error instanceof errors.ActorError) {
|
|
123
|
-
throw error;
|
|
124
|
-
} else {
|
|
125
|
-
throw new errors.InternalError(
|
|
126
|
-
`Failed to resolve actor ID: ${String(error)}`,
|
|
127
|
-
);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
},
|
|
131
|
-
|
|
132
|
-
connectWebSocket: async (
|
|
133
|
-
_c: HonoContext | undefined,
|
|
134
|
-
actorQuery: ActorQuery,
|
|
135
|
-
encodingKind: Encoding,
|
|
136
|
-
params: unknown,
|
|
137
|
-
): Promise<WebSocket> => {
|
|
138
|
-
const { WebSocket } = await dynamicImports;
|
|
139
|
-
|
|
140
|
-
const endpoint = managerEndpoint
|
|
141
|
-
.replace(/^http:/, "ws:")
|
|
142
|
-
.replace(/^https:/, "wss:");
|
|
143
|
-
const url = `${endpoint}/registry/actors/connect/websocket`;
|
|
144
|
-
|
|
145
|
-
// Pass sensitive data via protocol
|
|
146
|
-
const protocol = [
|
|
147
|
-
`query.${encodeURIComponent(JSON.stringify(actorQuery))}`,
|
|
148
|
-
`encoding.${encodingKind}`,
|
|
149
|
-
];
|
|
150
|
-
if (params)
|
|
151
|
-
protocol.push(
|
|
152
|
-
`conn_params.${encodeURIComponent(JSON.stringify(params))}`,
|
|
153
|
-
);
|
|
154
|
-
|
|
155
|
-
// HACK: See packages/drivers/cloudflare-workers/src/websocket.ts
|
|
156
|
-
protocol.push("rivetkit");
|
|
157
|
-
|
|
158
|
-
logger().debug("connecting to websocket", { url });
|
|
159
|
-
const ws = new WebSocket(url, protocol);
|
|
160
|
-
// HACK: Bun bug prevents changing binary type, so we ignore the error https://github.com/oven-sh/bun/issues/17005
|
|
161
|
-
try {
|
|
162
|
-
ws.binaryType = wsBinaryTypeForEncoding(encodingKind);
|
|
163
|
-
} catch (error) {}
|
|
164
|
-
|
|
165
|
-
// Node & web WebSocket types not compatible
|
|
166
|
-
return ws as any;
|
|
167
|
-
},
|
|
168
|
-
|
|
169
|
-
connectSse: async (
|
|
170
|
-
_c: HonoContext | undefined,
|
|
171
|
-
actorQuery: ActorQuery,
|
|
172
|
-
encodingKind: Encoding,
|
|
173
|
-
params: unknown,
|
|
174
|
-
): Promise<UniversalEventSource> => {
|
|
175
|
-
const { EventSource } = await dynamicImports;
|
|
176
|
-
|
|
177
|
-
const url = `${managerEndpoint}/registry/actors/connect/sse`;
|
|
178
|
-
|
|
179
|
-
logger().debug("connecting to sse", { url });
|
|
180
|
-
const eventSource = new EventSource(url, {
|
|
181
|
-
fetch: (input, init) => {
|
|
182
|
-
return fetch(input, {
|
|
183
|
-
...init,
|
|
184
|
-
headers: {
|
|
185
|
-
...init?.headers,
|
|
186
|
-
"User-Agent": httpUserAgent(),
|
|
187
|
-
[HEADER_ENCODING]: encodingKind,
|
|
188
|
-
[HEADER_ACTOR_QUERY]: JSON.stringify(actorQuery),
|
|
189
|
-
...(params !== undefined
|
|
190
|
-
? { [HEADER_CONN_PARAMS]: JSON.stringify(params) }
|
|
191
|
-
: {}),
|
|
192
|
-
},
|
|
193
|
-
credentials: "include",
|
|
194
|
-
});
|
|
195
|
-
},
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
return eventSource as UniversalEventSource;
|
|
199
|
-
},
|
|
200
|
-
|
|
201
|
-
sendHttpMessage: async (
|
|
202
|
-
_c: HonoContext | undefined,
|
|
203
|
-
actorId: string,
|
|
204
|
-
encoding: Encoding,
|
|
205
|
-
connectionId: string,
|
|
206
|
-
connectionToken: string,
|
|
207
|
-
message: protocol.ToServer,
|
|
208
|
-
): Promise<void> => {
|
|
209
|
-
// TODO: Implement ordered messages, this is not guaranteed order. Needs to use an index in order to ensure we can pipeline requests efficiently.
|
|
210
|
-
// TODO: Validate that we're using HTTP/3 whenever possible for pipelining requests
|
|
211
|
-
const messageSerialized = serializeWithEncoding(
|
|
212
|
-
encoding,
|
|
213
|
-
message,
|
|
214
|
-
TO_SERVER_VERSIONED,
|
|
215
|
-
);
|
|
216
|
-
const res = await fetch(`${managerEndpoint}/registry/actors/message`, {
|
|
217
|
-
method: "POST",
|
|
218
|
-
headers: {
|
|
219
|
-
"User-Agent": httpUserAgent(),
|
|
220
|
-
[HEADER_ENCODING]: encoding,
|
|
221
|
-
[HEADER_ACTOR_ID]: actorId,
|
|
222
|
-
[HEADER_CONN_ID]: connectionId,
|
|
223
|
-
[HEADER_CONN_TOKEN]: connectionToken,
|
|
224
|
-
},
|
|
225
|
-
body: messageSerialized,
|
|
226
|
-
credentials: "include",
|
|
227
|
-
});
|
|
228
|
-
if (!res.ok) {
|
|
229
|
-
throw new errors.InternalError(
|
|
230
|
-
`Publish message over HTTP error (${res.statusText}):\n${await res.text()}`,
|
|
231
|
-
);
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
// Discard response
|
|
235
|
-
await res.body?.cancel();
|
|
236
|
-
},
|
|
237
|
-
|
|
238
|
-
rawHttpRequest: async (
|
|
239
|
-
_c: HonoContext | undefined,
|
|
240
|
-
actorQuery: ActorQuery,
|
|
241
|
-
encoding: Encoding,
|
|
242
|
-
params: unknown,
|
|
243
|
-
path: string,
|
|
244
|
-
init: RequestInit,
|
|
245
|
-
): Promise<Response> => {
|
|
246
|
-
// Build the full URL
|
|
247
|
-
// Remove leading slash from path to avoid double slashes
|
|
248
|
-
const normalizedPath = path.startsWith("/") ? path.slice(1) : path;
|
|
249
|
-
const url = `${managerEndpoint}/registry/actors/raw/http/${normalizedPath}`;
|
|
250
|
-
|
|
251
|
-
logger().debug("rewriting http url", {
|
|
252
|
-
from: path,
|
|
253
|
-
to: url,
|
|
254
|
-
});
|
|
255
|
-
|
|
256
|
-
// Merge headers properly
|
|
257
|
-
const headers = new Headers(init.headers);
|
|
258
|
-
headers.set("User-Agent", httpUserAgent());
|
|
259
|
-
headers.set(HEADER_ACTOR_QUERY, JSON.stringify(actorQuery));
|
|
260
|
-
headers.set(HEADER_ENCODING, encoding);
|
|
261
|
-
if (params !== undefined) {
|
|
262
|
-
headers.set(HEADER_CONN_PARAMS, JSON.stringify(params));
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
// Forward the request with query in headers
|
|
266
|
-
return await fetch(url, {
|
|
267
|
-
...init,
|
|
268
|
-
headers,
|
|
269
|
-
});
|
|
270
|
-
},
|
|
271
|
-
|
|
272
|
-
rawWebSocket: async (
|
|
273
|
-
_c: HonoContext | undefined,
|
|
274
|
-
actorQuery: ActorQuery,
|
|
275
|
-
encoding: Encoding,
|
|
276
|
-
params: unknown,
|
|
277
|
-
path: string,
|
|
278
|
-
protocols: string | string[] | undefined,
|
|
279
|
-
): Promise<WebSocket> => {
|
|
280
|
-
const { WebSocket } = await dynamicImports;
|
|
281
|
-
|
|
282
|
-
// Build the WebSocket URL with normalized path
|
|
283
|
-
const wsEndpoint = managerEndpoint
|
|
284
|
-
.replace(/^http:/, "ws:")
|
|
285
|
-
.replace(/^https:/, "wss:");
|
|
286
|
-
// Normalize path to match raw HTTP behavior
|
|
287
|
-
const normalizedPath = path.startsWith("/") ? path.slice(1) : path;
|
|
288
|
-
const url = `${wsEndpoint}/registry/actors/raw/websocket/${normalizedPath}`;
|
|
289
|
-
|
|
290
|
-
logger().debug("rewriting websocket url", {
|
|
291
|
-
from: path,
|
|
292
|
-
to: url,
|
|
293
|
-
});
|
|
294
|
-
|
|
295
|
-
// Pass data via WebSocket protocol subprotocols
|
|
296
|
-
const protocolList: string[] = [];
|
|
297
|
-
protocolList.push(
|
|
298
|
-
`query.${encodeURIComponent(JSON.stringify(actorQuery))}`,
|
|
299
|
-
);
|
|
300
|
-
protocolList.push(`encoding.${encoding}`);
|
|
301
|
-
if (params) {
|
|
302
|
-
protocolList.push(
|
|
303
|
-
`conn_params.${encodeURIComponent(JSON.stringify(params))}`,
|
|
304
|
-
);
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
// HACK: See packages/drivers/cloudflare-workers/src/websocket.ts
|
|
308
|
-
protocolList.push("rivetkit");
|
|
309
|
-
|
|
310
|
-
// Add user protocols
|
|
311
|
-
if (protocols) {
|
|
312
|
-
if (Array.isArray(protocols)) {
|
|
313
|
-
protocolList.push(...protocols);
|
|
314
|
-
} else {
|
|
315
|
-
protocolList.push(protocols);
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
// Create WebSocket connection
|
|
320
|
-
logger().debug("opening raw websocket", { url });
|
|
321
|
-
return new WebSocket(url, protocolList) as any;
|
|
322
|
-
},
|
|
323
|
-
};
|
|
324
|
-
|
|
325
|
-
return driver;
|
|
326
|
-
}
|