rivetkit 2.0.5 → 2.0.7-rc.1
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/schemas/actor-persist/v1.ts +0 -6
- package/dist/tsup/actor-router-consts-B3Lu87yJ.d.cts +28 -0
- package/dist/tsup/actor-router-consts-B3Lu87yJ.d.ts +28 -0
- package/dist/tsup/{chunk-5YTI25C3.cjs → chunk-3MBP4WNC.cjs} +7 -7
- package/dist/tsup/{chunk-5YTI25C3.cjs.map → chunk-3MBP4WNC.cjs.map} +1 -1
- package/dist/tsup/chunk-3Y45CIF4.cjs +3726 -0
- package/dist/tsup/chunk-3Y45CIF4.cjs.map +1 -0
- package/dist/tsup/chunk-4GP7BZSR.js +102 -0
- package/dist/tsup/chunk-4GP7BZSR.js.map +1 -0
- package/dist/tsup/chunk-5ZOHIKWG.cjs +4071 -0
- package/dist/tsup/chunk-5ZOHIKWG.cjs.map +1 -0
- package/dist/tsup/{chunk-WADSS5X4.cjs → chunk-6EUWRXLT.cjs} +21 -7
- package/dist/tsup/chunk-6EUWRXLT.cjs.map +1 -0
- package/dist/tsup/{chunk-D7NWUCRK.cjs → chunk-6OVKCDSH.cjs} +6 -6
- package/dist/tsup/{chunk-D7NWUCRK.cjs.map → chunk-6OVKCDSH.cjs.map} +1 -1
- package/dist/tsup/{chunk-I5VTWPHW.js → chunk-7N56ZUC7.js} +3 -3
- package/dist/tsup/{chunk-LZIBTLEY.cjs → chunk-B3TLRM4Q.cjs} +13 -25
- package/dist/tsup/chunk-B3TLRM4Q.cjs.map +1 -0
- package/dist/tsup/chunk-BW5DPM6Z.js +4071 -0
- package/dist/tsup/chunk-BW5DPM6Z.js.map +1 -0
- package/dist/tsup/chunk-DFS77KAA.cjs +1046 -0
- package/dist/tsup/chunk-DFS77KAA.cjs.map +1 -0
- package/dist/tsup/{chunk-PG3K2LI7.js → chunk-E4UVJKSV.js} +2 -2
- package/dist/tsup/chunk-G4ABMAQY.cjs +102 -0
- package/dist/tsup/chunk-G4ABMAQY.cjs.map +1 -0
- package/dist/tsup/{chunk-CKA54YQN.js → chunk-GZVBFXBI.js} +3 -15
- package/dist/tsup/chunk-GZVBFXBI.js.map +1 -0
- package/dist/tsup/chunk-HPT3I7UU.js +3726 -0
- package/dist/tsup/chunk-HPT3I7UU.js.map +1 -0
- package/dist/tsup/chunk-JD54PXWP.js +1046 -0
- package/dist/tsup/chunk-JD54PXWP.js.map +1 -0
- package/dist/tsup/{chunk-PHSQJ6QI.cjs → chunk-K4ENQCC4.cjs} +3 -3
- package/dist/tsup/{chunk-PHSQJ6QI.cjs.map → chunk-K4ENQCC4.cjs.map} +1 -1
- package/dist/tsup/{chunk-WNGOBAA7.js → chunk-PUSQNDJG.js} +2 -2
- package/dist/tsup/{chunk-CFFKMUYH.js → chunk-RVP5RUSC.js} +20 -6
- package/dist/tsup/chunk-RVP5RUSC.js.map +1 -0
- package/dist/tsup/chunk-SAZCNSVY.cjs +259 -0
- package/dist/tsup/chunk-SAZCNSVY.cjs.map +1 -0
- package/dist/tsup/{chunk-YW6Y6VNE.js → chunk-SBKRVQS2.js} +9 -5
- package/dist/tsup/chunk-SBKRVQS2.js.map +1 -0
- package/dist/tsup/{chunk-FGFT4FVX.cjs → chunk-TZGUSEIJ.cjs} +14 -10
- package/dist/tsup/chunk-TZGUSEIJ.cjs.map +1 -0
- package/dist/tsup/chunk-YQ4XQYPM.js +259 -0
- package/dist/tsup/chunk-YQ4XQYPM.js.map +1 -0
- package/dist/tsup/client/mod.cjs +9 -9
- package/dist/tsup/client/mod.d.cts +7 -8
- package/dist/tsup/client/mod.d.ts +7 -8
- package/dist/tsup/client/mod.js +8 -8
- package/dist/tsup/common/log.cjs +3 -3
- package/dist/tsup/common/log.js +2 -2
- package/dist/tsup/common/websocket.cjs +4 -4
- package/dist/tsup/common/websocket.js +3 -3
- package/dist/tsup/{connection-BvE-Oq7t.d.ts → conn-DCSQgIlw.d.ts} +1605 -1353
- package/dist/tsup/{connection-DTzmWwU5.d.cts → conn-DdzHTm2E.d.cts} +1605 -1353
- package/dist/tsup/driver-helpers/mod.cjs +31 -5
- package/dist/tsup/driver-helpers/mod.cjs.map +1 -1
- package/dist/tsup/driver-helpers/mod.d.cts +7 -8
- package/dist/tsup/driver-helpers/mod.d.ts +7 -8
- package/dist/tsup/driver-helpers/mod.js +33 -7
- package/dist/tsup/driver-test-suite/mod.cjs +319 -216
- package/dist/tsup/driver-test-suite/mod.cjs.map +1 -1
- package/dist/tsup/driver-test-suite/mod.d.cts +7 -7
- package/dist/tsup/driver-test-suite/mod.d.ts +7 -7
- package/dist/tsup/driver-test-suite/mod.js +588 -485
- package/dist/tsup/driver-test-suite/mod.js.map +1 -1
- package/dist/tsup/inspector/mod.cjs +17 -5
- package/dist/tsup/inspector/mod.cjs.map +1 -1
- package/dist/tsup/inspector/mod.d.cts +34 -7
- package/dist/tsup/inspector/mod.d.ts +34 -7
- package/dist/tsup/inspector/mod.js +20 -8
- package/dist/tsup/mod.cjs +10 -17
- package/dist/tsup/mod.cjs.map +1 -1
- package/dist/tsup/mod.d.cts +56 -9
- package/dist/tsup/mod.d.ts +56 -9
- package/dist/tsup/mod.js +17 -24
- package/dist/tsup/test/mod.cjs +11 -9
- package/dist/tsup/test/mod.cjs.map +1 -1
- package/dist/tsup/test/mod.d.cts +6 -7
- package/dist/tsup/test/mod.d.ts +6 -7
- package/dist/tsup/test/mod.js +10 -8
- package/dist/tsup/utils.cjs +4 -2
- package/dist/tsup/utils.cjs.map +1 -1
- package/dist/tsup/utils.d.cts +11 -1
- package/dist/tsup/utils.d.ts +11 -1
- package/dist/tsup/utils.js +3 -1
- package/package.json +8 -4
- package/src/actor/action.ts +1 -1
- package/src/actor/config.ts +1 -1
- package/src/actor/conn-drivers.ts +205 -0
- package/src/actor/conn-socket.ts +6 -0
- package/src/actor/{connection.ts → conn.ts} +78 -84
- package/src/actor/context.ts +1 -1
- package/src/actor/driver.ts +4 -43
- package/src/actor/instance.ts +162 -86
- package/src/actor/mod.ts +6 -14
- package/src/actor/persisted.ts +2 -5
- package/src/actor/protocol/old.ts +1 -1
- package/src/actor/router-endpoints.ts +147 -138
- package/src/actor/router.ts +89 -52
- package/src/actor/utils.ts +5 -1
- package/src/client/actor-conn.ts +163 -31
- package/src/client/actor-handle.ts +0 -1
- package/src/client/client.ts +2 -2
- package/src/client/config.ts +7 -0
- package/src/client/raw-utils.ts +1 -1
- package/src/client/utils.ts +1 -1
- package/src/common/actor-router-consts.ts +59 -0
- package/src/common/router.ts +2 -1
- package/src/common/versioned-data.ts +5 -5
- package/src/driver-helpers/mod.ts +15 -2
- package/src/driver-test-suite/mod.ts +11 -2
- package/src/driver-test-suite/test-inline-client-driver.ts +40 -22
- package/src/driver-test-suite/tests/actor-conn-state.ts +66 -22
- package/src/driver-test-suite/tests/actor-conn.ts +65 -126
- package/src/driver-test-suite/tests/actor-reconnect.ts +160 -0
- package/src/driver-test-suite/tests/actor-sleep.ts +0 -1
- package/src/driver-test-suite/tests/raw-websocket.ts +0 -35
- package/src/driver-test-suite/utils.ts +8 -3
- package/src/drivers/default.ts +8 -7
- package/src/drivers/engine/actor-driver.ts +67 -44
- package/src/drivers/engine/config.ts +4 -0
- package/src/drivers/file-system/actor.ts +0 -6
- package/src/drivers/file-system/global-state.ts +3 -14
- package/src/drivers/file-system/manager.ts +12 -8
- package/src/inspector/actor.ts +4 -3
- package/src/inspector/config.ts +10 -1
- package/src/inspector/mod.ts +1 -0
- package/src/inspector/utils.ts +23 -4
- package/src/manager/driver.ts +12 -2
- package/src/manager/gateway.ts +407 -0
- package/src/manager/protocol/query.ts +1 -1
- package/src/manager/router.ts +269 -468
- package/src/manager-api/actors.ts +61 -0
- package/src/manager-api/common.ts +4 -0
- package/src/mod.ts +1 -1
- package/src/registry/mod.ts +126 -12
- package/src/registry/serve.ts +8 -3
- package/src/remote-manager-driver/actor-http-client.ts +30 -19
- package/src/remote-manager-driver/actor-websocket-client.ts +45 -18
- package/src/remote-manager-driver/api-endpoints.ts +19 -21
- package/src/remote-manager-driver/api-utils.ts +10 -1
- package/src/remote-manager-driver/mod.ts +53 -53
- package/src/remote-manager-driver/ws-proxy.ts +2 -9
- package/src/test/mod.ts +6 -2
- package/src/utils.ts +21 -2
- package/dist/tsup/chunk-2MD57QF4.js +0 -1794
- package/dist/tsup/chunk-2MD57QF4.js.map +0 -1
- package/dist/tsup/chunk-B2QGJGZQ.js +0 -338
- package/dist/tsup/chunk-B2QGJGZQ.js.map +0 -1
- package/dist/tsup/chunk-CFFKMUYH.js.map +0 -1
- package/dist/tsup/chunk-CKA54YQN.js.map +0 -1
- package/dist/tsup/chunk-FGFT4FVX.cjs.map +0 -1
- package/dist/tsup/chunk-IRMBWX36.cjs +0 -1794
- package/dist/tsup/chunk-IRMBWX36.cjs.map +0 -1
- package/dist/tsup/chunk-L7QRXNWP.js +0 -6562
- package/dist/tsup/chunk-L7QRXNWP.js.map +0 -1
- package/dist/tsup/chunk-LZIBTLEY.cjs.map +0 -1
- package/dist/tsup/chunk-MRZS2J4X.cjs +0 -6562
- package/dist/tsup/chunk-MRZS2J4X.cjs.map +0 -1
- package/dist/tsup/chunk-RM2SVURR.cjs +0 -338
- package/dist/tsup/chunk-RM2SVURR.cjs.map +0 -1
- package/dist/tsup/chunk-WADSS5X4.cjs.map +0 -1
- package/dist/tsup/chunk-YW6Y6VNE.js.map +0 -1
- package/dist/tsup/common-CXCe7s6i.d.cts +0 -218
- package/dist/tsup/common-CXCe7s6i.d.ts +0 -218
- package/dist/tsup/router-endpoints-CctffZNL.d.cts +0 -65
- package/dist/tsup/router-endpoints-DFm1BglJ.d.ts +0 -65
- package/src/actor/generic-conn-driver.ts +0 -246
- package/src/common/fake-event-source.ts +0 -267
- package/src/manager-api/routes/actors-create.ts +0 -16
- package/src/manager-api/routes/actors-delete.ts +0 -4
- package/src/manager-api/routes/actors-get-by-id.ts +0 -7
- package/src/manager-api/routes/actors-get-or-create-by-id.ts +0 -29
- package/src/manager-api/routes/actors-get.ts +0 -7
- package/src/manager-api/routes/common.ts +0 -18
- /package/dist/tsup/{chunk-I5VTWPHW.js.map → chunk-7N56ZUC7.js.map} +0 -0
- /package/dist/tsup/{chunk-PG3K2LI7.js.map → chunk-E4UVJKSV.js.map} +0 -0
- /package/dist/tsup/{chunk-WNGOBAA7.js.map → chunk-PUSQNDJG.js.map} +0 -0
|
@@ -1,246 +0,0 @@
|
|
|
1
|
-
import type { SSEStreamingApi } from "hono/streaming";
|
|
2
|
-
import type { WSContext } from "hono/ws";
|
|
3
|
-
import type { WebSocket } from "ws";
|
|
4
|
-
import {
|
|
5
|
-
type AnyConn,
|
|
6
|
-
CONNECTION_DRIVER_HTTP,
|
|
7
|
-
CONNECTION_DRIVER_SSE,
|
|
8
|
-
CONNECTION_DRIVER_WEBSOCKET,
|
|
9
|
-
} from "@/actor/connection";
|
|
10
|
-
import {
|
|
11
|
-
type ConnDriver,
|
|
12
|
-
type ConnectionDriversMap,
|
|
13
|
-
ConnectionReadyState,
|
|
14
|
-
} from "@/actor/driver";
|
|
15
|
-
import type { AnyActorInstance } from "@/actor/instance";
|
|
16
|
-
import type { CachedSerializer, Encoding } from "@/actor/protocol/serde";
|
|
17
|
-
import { encodeDataToString } from "@/actor/protocol/serde";
|
|
18
|
-
import type * as protocol from "@/schemas/client-protocol/mod";
|
|
19
|
-
import { loggerWithoutContext } from "./log";
|
|
20
|
-
|
|
21
|
-
// This state is different than `PersistedConn` state since the connection-specific state is persisted & must be serializable. This is also part of the connection driver, not part of the core actor.
|
|
22
|
-
//
|
|
23
|
-
// This holds the actual connections, which are not serializable.
|
|
24
|
-
//
|
|
25
|
-
// This is scoped to each actor. Do not share between multiple actors.
|
|
26
|
-
export class GenericConnGlobalState {
|
|
27
|
-
websockets = new Map<string, WSContext>();
|
|
28
|
-
sseStreams = new Map<string, SSEStreamingApi>();
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Exposes connection drivers for platforms that support vanilla WebSocket, SSE, and HTTP.
|
|
33
|
-
*/
|
|
34
|
-
export function createGenericConnDrivers(
|
|
35
|
-
globalState: GenericConnGlobalState,
|
|
36
|
-
): ConnectionDriversMap {
|
|
37
|
-
return {
|
|
38
|
-
[CONNECTION_DRIVER_WEBSOCKET]: createGenericWebSocketDriver(globalState),
|
|
39
|
-
[CONNECTION_DRIVER_SSE]: createGenericSseDriver(globalState),
|
|
40
|
-
[CONNECTION_DRIVER_HTTP]: createGenericHttpDriver(),
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// MARK: WebSocket
|
|
45
|
-
export interface GenericWebSocketDriverState {
|
|
46
|
-
encoding: Encoding;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export function createGenericWebSocketDriver(
|
|
50
|
-
globalState: GenericConnGlobalState,
|
|
51
|
-
): ConnDriver<GenericWebSocketDriverState> {
|
|
52
|
-
return {
|
|
53
|
-
sendMessage: (
|
|
54
|
-
actor: AnyActorInstance,
|
|
55
|
-
conn: AnyConn,
|
|
56
|
-
state: GenericWebSocketDriverState,
|
|
57
|
-
message: CachedSerializer<protocol.ToClient>,
|
|
58
|
-
) => {
|
|
59
|
-
const ws = globalState.websockets.get(conn.id);
|
|
60
|
-
if (!ws) {
|
|
61
|
-
actor.rLog.warn({
|
|
62
|
-
msg: "missing ws for sendMessage",
|
|
63
|
-
actorId: actor.id,
|
|
64
|
-
connId: conn.id,
|
|
65
|
-
totalCount: globalState.websockets.size,
|
|
66
|
-
});
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const serialized = message.serialize(state.encoding);
|
|
71
|
-
|
|
72
|
-
actor.rLog.debug({
|
|
73
|
-
msg: "sending websocket message",
|
|
74
|
-
encoding: state.encoding,
|
|
75
|
-
dataType: typeof serialized,
|
|
76
|
-
isUint8Array: serialized instanceof Uint8Array,
|
|
77
|
-
isArrayBuffer: serialized instanceof ArrayBuffer,
|
|
78
|
-
dataLength:
|
|
79
|
-
(serialized as any).byteLength || (serialized as any).length,
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
// Convert Uint8Array to ArrayBuffer for proper transmission
|
|
83
|
-
if (serialized instanceof Uint8Array) {
|
|
84
|
-
const buffer = serialized.buffer.slice(
|
|
85
|
-
serialized.byteOffset,
|
|
86
|
-
serialized.byteOffset + serialized.byteLength,
|
|
87
|
-
);
|
|
88
|
-
// Handle SharedArrayBuffer case
|
|
89
|
-
if (buffer instanceof SharedArrayBuffer) {
|
|
90
|
-
const arrayBuffer = new ArrayBuffer(buffer.byteLength);
|
|
91
|
-
new Uint8Array(arrayBuffer).set(new Uint8Array(buffer));
|
|
92
|
-
actor.rLog.debug({
|
|
93
|
-
msg: "converted SharedArrayBuffer to ArrayBuffer",
|
|
94
|
-
byteLength: arrayBuffer.byteLength,
|
|
95
|
-
});
|
|
96
|
-
ws.send(arrayBuffer);
|
|
97
|
-
} else {
|
|
98
|
-
actor.rLog.debug({
|
|
99
|
-
msg: "sending ArrayBuffer",
|
|
100
|
-
byteLength: buffer.byteLength,
|
|
101
|
-
});
|
|
102
|
-
ws.send(buffer);
|
|
103
|
-
}
|
|
104
|
-
} else {
|
|
105
|
-
actor.rLog.debug({
|
|
106
|
-
msg: "sending string data",
|
|
107
|
-
length: (serialized as string).length,
|
|
108
|
-
});
|
|
109
|
-
ws.send(serialized);
|
|
110
|
-
}
|
|
111
|
-
},
|
|
112
|
-
|
|
113
|
-
disconnect: async (
|
|
114
|
-
actor: AnyActorInstance,
|
|
115
|
-
conn: AnyConn,
|
|
116
|
-
_state: GenericWebSocketDriverState,
|
|
117
|
-
reason?: string,
|
|
118
|
-
) => {
|
|
119
|
-
const ws = globalState.websockets.get(conn.id);
|
|
120
|
-
if (!ws) {
|
|
121
|
-
actor.rLog.warn({
|
|
122
|
-
msg: "missing ws for disconnect",
|
|
123
|
-
actorId: actor.id,
|
|
124
|
-
connId: conn.id,
|
|
125
|
-
totalCount: globalState.websockets.size,
|
|
126
|
-
});
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
const raw = ws.raw as WebSocket;
|
|
130
|
-
if (!raw) {
|
|
131
|
-
actor.rLog.warn({ msg: "ws.raw does not exist" });
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
// Create promise to wait for socket to close gracefully
|
|
136
|
-
const { promise, resolve } = Promise.withResolvers<void>();
|
|
137
|
-
raw.addEventListener("close", () => resolve());
|
|
138
|
-
|
|
139
|
-
// Close socket
|
|
140
|
-
ws.close(1000, reason);
|
|
141
|
-
|
|
142
|
-
await promise;
|
|
143
|
-
},
|
|
144
|
-
|
|
145
|
-
getConnectionReadyState: (
|
|
146
|
-
actor: AnyActorInstance,
|
|
147
|
-
conn: AnyConn,
|
|
148
|
-
): ConnectionReadyState | undefined => {
|
|
149
|
-
const ws = globalState.websockets.get(conn.id);
|
|
150
|
-
if (!ws) {
|
|
151
|
-
actor.rLog.warn({
|
|
152
|
-
msg: "missing ws for getConnectionReadyState",
|
|
153
|
-
connId: conn.id,
|
|
154
|
-
});
|
|
155
|
-
return undefined;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
const raw = ws.raw as WebSocket;
|
|
159
|
-
|
|
160
|
-
return raw.readyState as ConnectionReadyState;
|
|
161
|
-
},
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
// MARK: SSE
|
|
166
|
-
export interface GenericSseDriverState {
|
|
167
|
-
encoding: Encoding;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
export function createGenericSseDriver(
|
|
171
|
-
globalState: GenericConnGlobalState,
|
|
172
|
-
): ConnDriver<GenericSseDriverState> {
|
|
173
|
-
return {
|
|
174
|
-
sendMessage: (
|
|
175
|
-
actor: AnyActorInstance,
|
|
176
|
-
conn: AnyConn,
|
|
177
|
-
state: GenericSseDriverState,
|
|
178
|
-
message: CachedSerializer<protocol.ToClient>,
|
|
179
|
-
) => {
|
|
180
|
-
const stream = globalState.sseStreams.get(conn.id);
|
|
181
|
-
if (!stream) {
|
|
182
|
-
actor.rLog.warn({
|
|
183
|
-
msg: "missing sse stream for sendMessage",
|
|
184
|
-
connId: conn.id,
|
|
185
|
-
});
|
|
186
|
-
return;
|
|
187
|
-
}
|
|
188
|
-
stream.writeSSE({
|
|
189
|
-
data: encodeDataToString(message.serialize(state.encoding)),
|
|
190
|
-
});
|
|
191
|
-
},
|
|
192
|
-
|
|
193
|
-
disconnect: async (
|
|
194
|
-
actor: AnyActorInstance,
|
|
195
|
-
conn: AnyConn,
|
|
196
|
-
_state: GenericSseDriverState,
|
|
197
|
-
_reason?: string,
|
|
198
|
-
) => {
|
|
199
|
-
const stream = globalState.sseStreams.get(conn.id);
|
|
200
|
-
if (!stream) {
|
|
201
|
-
actor.rLog.warn({
|
|
202
|
-
msg: "missing sse stream for disconnect",
|
|
203
|
-
connId: conn.id,
|
|
204
|
-
});
|
|
205
|
-
return;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
stream.close();
|
|
209
|
-
},
|
|
210
|
-
|
|
211
|
-
getConnectionReadyState: (
|
|
212
|
-
actor: AnyActorInstance,
|
|
213
|
-
conn: AnyConn,
|
|
214
|
-
): ConnectionReadyState | undefined => {
|
|
215
|
-
const stream = globalState.sseStreams.get(conn.id);
|
|
216
|
-
if (!stream) {
|
|
217
|
-
actor.rLog.warn({
|
|
218
|
-
msg: "missing sse stream for getConnectionReadyState",
|
|
219
|
-
connId: conn.id,
|
|
220
|
-
});
|
|
221
|
-
return undefined;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
if (stream.aborted || stream.closed) {
|
|
225
|
-
return ConnectionReadyState.CLOSED;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
return ConnectionReadyState.OPEN;
|
|
229
|
-
},
|
|
230
|
-
};
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
// MARK: HTTP
|
|
234
|
-
export type GenericHttpDriverState = Record<never, never>;
|
|
235
|
-
|
|
236
|
-
export function createGenericHttpDriver(): ConnDriver<GenericHttpDriverState> {
|
|
237
|
-
return {
|
|
238
|
-
getConnectionReadyState(_actor, _conn) {
|
|
239
|
-
// TODO: This might not be the correct logic
|
|
240
|
-
return ConnectionReadyState.OPEN;
|
|
241
|
-
},
|
|
242
|
-
disconnect: async () => {
|
|
243
|
-
// Noop
|
|
244
|
-
},
|
|
245
|
-
};
|
|
246
|
-
}
|
|
@@ -1,267 +0,0 @@
|
|
|
1
|
-
import type { EventListener } from "eventsource";
|
|
2
|
-
import type { SSEStreamingApi } from "hono/streaming";
|
|
3
|
-
import { getLogger } from "@/common//log";
|
|
4
|
-
import type {
|
|
5
|
-
UniversalEvent,
|
|
6
|
-
UniversalEventSource,
|
|
7
|
-
UniversalMessageEvent,
|
|
8
|
-
} from "@/common/eventsource-interface";
|
|
9
|
-
|
|
10
|
-
export function logger() {
|
|
11
|
-
return getLogger("fake-event-source");
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* FakeEventSource provides a minimal implementation of an SSE stream
|
|
16
|
-
* that handles events for the inline client driver
|
|
17
|
-
*/
|
|
18
|
-
export class FakeEventSource implements UniversalEventSource {
|
|
19
|
-
// EventSource readyState values
|
|
20
|
-
readonly CONNECTING = 0 as const;
|
|
21
|
-
readonly OPEN = 1 as const;
|
|
22
|
-
readonly CLOSED = 2 as const;
|
|
23
|
-
|
|
24
|
-
url = "http://internal-sse-endpoint";
|
|
25
|
-
readyState: 0 | 1 | 2 = 1; // OPEN
|
|
26
|
-
withCredentials = false;
|
|
27
|
-
|
|
28
|
-
// Event handlers
|
|
29
|
-
onopen: ((event: UniversalEvent) => void) | null = null;
|
|
30
|
-
onmessage: ((event: UniversalMessageEvent) => void) | null = null;
|
|
31
|
-
onerror: ((event: UniversalEvent) => void) | null = null;
|
|
32
|
-
|
|
33
|
-
// Private event listeners
|
|
34
|
-
#listeners: Record<string, Set<EventListener>> = {
|
|
35
|
-
open: new Set(),
|
|
36
|
-
message: new Set(),
|
|
37
|
-
error: new Set(),
|
|
38
|
-
close: new Set(),
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
// Stream that will be passed to the handler
|
|
42
|
-
#stream: SSEStreamingApi;
|
|
43
|
-
#onCloseCallback: () => Promise<void>;
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Creates a new FakeEventSource
|
|
47
|
-
*/
|
|
48
|
-
constructor(onCloseCallback: () => Promise<void>) {
|
|
49
|
-
this.#onCloseCallback = onCloseCallback;
|
|
50
|
-
|
|
51
|
-
this.#stream = this.#createStreamApi();
|
|
52
|
-
|
|
53
|
-
// Trigger open event on next tick
|
|
54
|
-
setTimeout(() => {
|
|
55
|
-
if (this.readyState === 1) {
|
|
56
|
-
this.#dispatchEvent("open");
|
|
57
|
-
}
|
|
58
|
-
}, 0);
|
|
59
|
-
|
|
60
|
-
logger().debug("FakeEventSource created");
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// Creates the SSE streaming API implementation
|
|
64
|
-
#createStreamApi(): SSEStreamingApi {
|
|
65
|
-
// Create self-reference for closures
|
|
66
|
-
const self = this;
|
|
67
|
-
|
|
68
|
-
const streamApi: SSEStreamingApi = {
|
|
69
|
-
write: async (input) => {
|
|
70
|
-
const data =
|
|
71
|
-
typeof input === "string" ? input : new TextDecoder().decode(input);
|
|
72
|
-
self.#dispatchEvent("message", { data });
|
|
73
|
-
return streamApi;
|
|
74
|
-
},
|
|
75
|
-
|
|
76
|
-
writeln: async (input: string) => {
|
|
77
|
-
await streamApi.write(input + "\n");
|
|
78
|
-
return streamApi;
|
|
79
|
-
},
|
|
80
|
-
|
|
81
|
-
writeSSE: async (message: {
|
|
82
|
-
data: string | Promise<string>;
|
|
83
|
-
event?: string;
|
|
84
|
-
id?: string;
|
|
85
|
-
retry?: number;
|
|
86
|
-
}): Promise<void> => {
|
|
87
|
-
const data = await message.data;
|
|
88
|
-
|
|
89
|
-
if (message.event) {
|
|
90
|
-
self.#dispatchEvent(message.event, { data });
|
|
91
|
-
} else {
|
|
92
|
-
self.#dispatchEvent("message", { data });
|
|
93
|
-
}
|
|
94
|
-
},
|
|
95
|
-
|
|
96
|
-
sleep: async (ms: number) => {
|
|
97
|
-
await new Promise((resolve) => setTimeout(resolve, ms));
|
|
98
|
-
return streamApi;
|
|
99
|
-
},
|
|
100
|
-
|
|
101
|
-
close: async () => {
|
|
102
|
-
self.close();
|
|
103
|
-
},
|
|
104
|
-
|
|
105
|
-
pipe: async (_body: ReadableStream) => {
|
|
106
|
-
// No-op implementation
|
|
107
|
-
},
|
|
108
|
-
|
|
109
|
-
onAbort: async (cb: () => void) => {
|
|
110
|
-
self.addEventListener("error", () => {
|
|
111
|
-
cb();
|
|
112
|
-
});
|
|
113
|
-
return streamApi;
|
|
114
|
-
},
|
|
115
|
-
|
|
116
|
-
abort: async () => {
|
|
117
|
-
self.#dispatchEvent("error");
|
|
118
|
-
return streamApi;
|
|
119
|
-
},
|
|
120
|
-
|
|
121
|
-
// Additional required properties
|
|
122
|
-
get responseReadable() {
|
|
123
|
-
return null as unknown as ReadableStream;
|
|
124
|
-
},
|
|
125
|
-
|
|
126
|
-
get aborted() {
|
|
127
|
-
return self.readyState === 2; // CLOSED
|
|
128
|
-
},
|
|
129
|
-
|
|
130
|
-
get closed() {
|
|
131
|
-
return self.readyState === 2; // CLOSED
|
|
132
|
-
},
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
return streamApi;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* Closes the connection
|
|
140
|
-
*/
|
|
141
|
-
close(): void {
|
|
142
|
-
if (this.readyState === 2) {
|
|
143
|
-
// CLOSED
|
|
144
|
-
return;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
logger().debug({ msg: "closing FakeEventSource" });
|
|
148
|
-
this.readyState = 2; // CLOSED
|
|
149
|
-
|
|
150
|
-
// Call the close callback
|
|
151
|
-
this.#onCloseCallback().catch((err) => {
|
|
152
|
-
logger().error({ msg: "error in onClose callback", error: err });
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
// Dispatch close event
|
|
156
|
-
this.#dispatchEvent("close");
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* Get the stream API to pass to the handler
|
|
161
|
-
*/
|
|
162
|
-
getStream(): SSEStreamingApi {
|
|
163
|
-
return this.#stream;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
// Implementation of EventTarget-like interface
|
|
167
|
-
addEventListener(type: string, listener: EventListener): void {
|
|
168
|
-
if (!this.#listeners[type]) {
|
|
169
|
-
this.#listeners[type] = new Set();
|
|
170
|
-
}
|
|
171
|
-
this.#listeners[type].add(listener);
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
removeEventListener(type: string, listener: EventListener): void {
|
|
175
|
-
if (this.#listeners[type]) {
|
|
176
|
-
this.#listeners[type].delete(listener);
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
dispatchEvent(event: UniversalEvent): boolean {
|
|
181
|
-
this.#dispatchEvent(event.type, event);
|
|
182
|
-
return true;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
// Internal method to dispatch events
|
|
186
|
-
#dispatchEvent(type: string, detail?: Record<string, any>): void {
|
|
187
|
-
// Create appropriate event object
|
|
188
|
-
let event: any;
|
|
189
|
-
if (type === "message") {
|
|
190
|
-
event = {
|
|
191
|
-
type: "message",
|
|
192
|
-
target: this,
|
|
193
|
-
data: detail?.data || "",
|
|
194
|
-
origin: "",
|
|
195
|
-
lastEventId: "",
|
|
196
|
-
};
|
|
197
|
-
} else if (type === "close") {
|
|
198
|
-
event = {
|
|
199
|
-
type: "close",
|
|
200
|
-
target: this,
|
|
201
|
-
code: detail?.code || 1000,
|
|
202
|
-
reason: detail?.reason || "",
|
|
203
|
-
wasClean: detail?.wasClean ?? true,
|
|
204
|
-
};
|
|
205
|
-
} else if (type === "error") {
|
|
206
|
-
event = {
|
|
207
|
-
type: "error",
|
|
208
|
-
target: this,
|
|
209
|
-
error: detail?.error,
|
|
210
|
-
};
|
|
211
|
-
} else {
|
|
212
|
-
event = {
|
|
213
|
-
type: type,
|
|
214
|
-
target: this,
|
|
215
|
-
};
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
// Call all listeners first
|
|
219
|
-
if (this.#listeners[type]) {
|
|
220
|
-
for (const listener of this.#listeners[type]) {
|
|
221
|
-
try {
|
|
222
|
-
listener.call(this, event);
|
|
223
|
-
} catch (err) {
|
|
224
|
-
logger().error({
|
|
225
|
-
msg: `error in ${type} event listener`,
|
|
226
|
-
error: err,
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
// Then call specific handler
|
|
233
|
-
switch (type) {
|
|
234
|
-
case "open":
|
|
235
|
-
if (this.onopen) {
|
|
236
|
-
try {
|
|
237
|
-
this.onopen.call(this as any, event);
|
|
238
|
-
} catch (err) {
|
|
239
|
-
logger().error({ msg: "error in onopen handler", error: err });
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
break;
|
|
243
|
-
case "message":
|
|
244
|
-
if (this.onmessage) {
|
|
245
|
-
try {
|
|
246
|
-
this.onmessage.call(this as any, event);
|
|
247
|
-
} catch (err) {
|
|
248
|
-
logger().error({ msg: "error in onmessage handler", error: err });
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
break;
|
|
252
|
-
case "error":
|
|
253
|
-
if (this.onerror) {
|
|
254
|
-
try {
|
|
255
|
-
this.onerror.call(this as any, event);
|
|
256
|
-
} catch (err) {
|
|
257
|
-
logger().error({ msg: "error in onerror handler", error: err });
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
break;
|
|
261
|
-
case "close":
|
|
262
|
-
// Note: EventSource doesn't have onclose in the standard API
|
|
263
|
-
// but we handle it here for consistency
|
|
264
|
-
break;
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
import { ActorSchema } from "./common";
|
|
3
|
-
|
|
4
|
-
export const ActorsCreateRequestSchema = z.object({
|
|
5
|
-
name: z.string(),
|
|
6
|
-
runner_name_selector: z.string(),
|
|
7
|
-
crash_policy: z.string(),
|
|
8
|
-
key: z.string().nullable().optional(),
|
|
9
|
-
input: z.string().nullable().optional(),
|
|
10
|
-
});
|
|
11
|
-
export type ActorsCreateRequest = z.infer<typeof ActorsCreateRequestSchema>;
|
|
12
|
-
|
|
13
|
-
export const ActorsCreateResponseSchema = z.object({
|
|
14
|
-
actor: ActorSchema,
|
|
15
|
-
});
|
|
16
|
-
export type ActorsCreateResponse = z.infer<typeof ActorsCreateResponseSchema>;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
import { ActorSchema, RivetIdSchema } from "./common";
|
|
3
|
-
|
|
4
|
-
export const ActorsGetOrCreateResponseSchema = z.object({
|
|
5
|
-
actor: ActorSchema,
|
|
6
|
-
created: z.boolean(),
|
|
7
|
-
});
|
|
8
|
-
export type ActorsGetOrCreateResponse = z.infer<
|
|
9
|
-
typeof ActorsGetOrCreateResponseSchema
|
|
10
|
-
>;
|
|
11
|
-
|
|
12
|
-
export const ActorsGetOrCreateByIdResponseSchema = z.object({
|
|
13
|
-
actor_id: RivetIdSchema,
|
|
14
|
-
created: z.boolean(),
|
|
15
|
-
});
|
|
16
|
-
export type ActorsGetOrCreateByIdResponse = z.infer<
|
|
17
|
-
typeof ActorsGetOrCreateByIdResponseSchema
|
|
18
|
-
>;
|
|
19
|
-
|
|
20
|
-
export const ActorsGetOrCreateByIdRequestSchema = z.object({
|
|
21
|
-
name: z.string(),
|
|
22
|
-
key: z.string(),
|
|
23
|
-
runner_name_selector: z.string(),
|
|
24
|
-
crash_policy: z.string(),
|
|
25
|
-
input: z.string().nullable().optional(),
|
|
26
|
-
});
|
|
27
|
-
export type ActorsGetOrCreateByIdRequest = z.infer<
|
|
28
|
-
typeof ActorsGetOrCreateByIdRequestSchema
|
|
29
|
-
>;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
|
|
3
|
-
export const RivetIdSchema = z.string();
|
|
4
|
-
export type RivetId = z.infer<typeof RivetIdSchema>;
|
|
5
|
-
|
|
6
|
-
export const ActorSchema = z.object({
|
|
7
|
-
actor_id: RivetIdSchema,
|
|
8
|
-
name: z.string(),
|
|
9
|
-
key: z.string(),
|
|
10
|
-
namespace_id: RivetIdSchema,
|
|
11
|
-
runner_name_selector: z.string(),
|
|
12
|
-
create_ts: z.number(),
|
|
13
|
-
connectable_ts: z.number().nullable().optional(),
|
|
14
|
-
destroy_ts: z.number().nullable().optional(),
|
|
15
|
-
sleep_ts: z.number().nullable().optional(),
|
|
16
|
-
start_ts: z.number().nullable().optional(),
|
|
17
|
-
});
|
|
18
|
-
export type Actor = z.infer<typeof ActorSchema>;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|