@rivetkit/engine-runner 2.0.26 → 2.0.27
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/.turbo/turbo-build.log +10 -10
- package/dist/mod.cjs +126 -230
- package/dist/mod.cjs.map +1 -1
- package/dist/mod.d.cts +1 -9
- package/dist/mod.d.ts +1 -9
- package/dist/mod.js +117 -221
- package/dist/mod.js.map +1 -1
- package/package.json +2 -2
- package/src/actor.ts +4 -18
- package/src/mod.ts +92 -176
- package/src/stringify.ts +26 -26
- package/src/tunnel.ts +13 -4
- package/src/utils.ts +0 -16
package/src/stringify.ts
CHANGED
|
@@ -40,6 +40,8 @@ export function stringifyToServerTunnelMessageKind(
|
|
|
40
40
|
kind: protocol.ToServerTunnelMessageKind,
|
|
41
41
|
): string {
|
|
42
42
|
switch (kind.tag) {
|
|
43
|
+
case "DeprecatedTunnelAck":
|
|
44
|
+
return "DeprecatedTunnelAck";
|
|
43
45
|
case "ToServerResponseStart": {
|
|
44
46
|
const { status, headers, body, stream } = kind.val;
|
|
45
47
|
const bodyStr = body === null ? "null" : stringifyArrayBuffer(body);
|
|
@@ -80,6 +82,8 @@ export function stringifyToClientTunnelMessageKind(
|
|
|
80
82
|
kind: protocol.ToClientTunnelMessageKind,
|
|
81
83
|
): string {
|
|
82
84
|
switch (kind.tag) {
|
|
85
|
+
case "DeprecatedTunnelAck":
|
|
86
|
+
return "DeprecatedTunnelAck";
|
|
83
87
|
case "ToClientRequestStart": {
|
|
84
88
|
const { actorId, method, path, headers, body, stream } = kind.val;
|
|
85
89
|
const bodyStr = body === null ? "null" : stringifyArrayBuffer(body);
|
|
@@ -115,7 +119,7 @@ export function stringifyToClientTunnelMessageKind(
|
|
|
115
119
|
export function stringifyCommand(command: protocol.Command): string {
|
|
116
120
|
switch (command.tag) {
|
|
117
121
|
case "CommandStartActor": {
|
|
118
|
-
const { generation, config, hibernatingRequests } =
|
|
122
|
+
const { actorId, generation, config, hibernatingRequests } =
|
|
119
123
|
command.val;
|
|
120
124
|
const keyStr = config.key === null ? "null" : `"${config.key}"`;
|
|
121
125
|
const inputStr =
|
|
@@ -126,11 +130,11 @@ export function stringifyCommand(command: protocol.Command): string {
|
|
|
126
130
|
hibernatingRequests.length > 0
|
|
127
131
|
? `[${hibernatingRequests.map((hr) => `{gatewayId: ${idToStr(hr.gatewayId)}, requestId: ${idToStr(hr.requestId)}}`).join(", ")}]`
|
|
128
132
|
: "[]";
|
|
129
|
-
return `CommandStartActor{generation: ${generation}, config: {name: "${config.name}", key: ${keyStr}, createTs: ${stringifyBigInt(config.createTs)}, input: ${inputStr}}, hibernatingRequests: ${hibernatingRequestsStr}}`;
|
|
133
|
+
return `CommandStartActor{actorId: "${actorId}", generation: ${generation}, config: {name: "${config.name}", key: ${keyStr}, createTs: ${stringifyBigInt(config.createTs)}, input: ${inputStr}}, hibernatingRequests: ${hibernatingRequestsStr}}`;
|
|
130
134
|
}
|
|
131
135
|
case "CommandStopActor": {
|
|
132
|
-
const { generation } = command.val;
|
|
133
|
-
return `CommandStopActor{generation: ${generation}}`;
|
|
136
|
+
const { actorId, generation } = command.val;
|
|
137
|
+
return `CommandStopActor{actorId: "${actorId}", generation: ${generation}}`;
|
|
134
138
|
}
|
|
135
139
|
}
|
|
136
140
|
}
|
|
@@ -142,7 +146,7 @@ export function stringifyCommand(command: protocol.Command): string {
|
|
|
142
146
|
export function stringifyCommandWrapper(
|
|
143
147
|
wrapper: protocol.CommandWrapper,
|
|
144
148
|
): string {
|
|
145
|
-
return `CommandWrapper{
|
|
149
|
+
return `CommandWrapper{index: ${stringifyBigInt(wrapper.index)}, inner: ${stringifyCommand(wrapper.inner)}}`;
|
|
146
150
|
}
|
|
147
151
|
|
|
148
152
|
/**
|
|
@@ -189,7 +193,7 @@ export function stringifyEvent(event: protocol.Event): string {
|
|
|
189
193
|
* Handles ArrayBuffers, BigInts, and Maps that can't be JSON.stringified
|
|
190
194
|
*/
|
|
191
195
|
export function stringifyEventWrapper(wrapper: protocol.EventWrapper): string {
|
|
192
|
-
return `EventWrapper{
|
|
196
|
+
return `EventWrapper{index: ${stringifyBigInt(wrapper.index)}, inner: ${stringifyEvent(wrapper.inner)}}`;
|
|
193
197
|
}
|
|
194
198
|
|
|
195
199
|
/**
|
|
@@ -203,33 +207,34 @@ export function stringifyToServer(message: protocol.ToServer): string {
|
|
|
203
207
|
name,
|
|
204
208
|
version,
|
|
205
209
|
totalSlots,
|
|
210
|
+
lastCommandIdx,
|
|
206
211
|
prepopulateActorNames,
|
|
207
212
|
metadata,
|
|
208
213
|
} = message.val;
|
|
214
|
+
const lastCommandIdxStr =
|
|
215
|
+
lastCommandIdx === null
|
|
216
|
+
? "null"
|
|
217
|
+
: stringifyBigInt(lastCommandIdx);
|
|
209
218
|
const prepopulateActorNamesStr =
|
|
210
219
|
prepopulateActorNames === null
|
|
211
220
|
? "null"
|
|
212
221
|
: `Map(${prepopulateActorNames.size})`;
|
|
213
222
|
const metadataStr = metadata === null ? "null" : `"${metadata}"`;
|
|
214
|
-
return `ToServerInit{name: "${name}", version: ${version}, totalSlots: ${totalSlots}, prepopulateActorNames: ${prepopulateActorNamesStr}, metadata: ${metadataStr}}`;
|
|
223
|
+
return `ToServerInit{name: "${name}", version: ${version}, totalSlots: ${totalSlots}, lastCommandIdx: ${lastCommandIdxStr}, prepopulateActorNames: ${prepopulateActorNamesStr}, metadata: ${metadataStr}}`;
|
|
215
224
|
}
|
|
216
225
|
case "ToServerEvents": {
|
|
217
226
|
const events = message.val;
|
|
218
227
|
return `ToServerEvents{count: ${events.length}, events: [${events.map((e) => stringifyEventWrapper(e)).join(", ")}]}`;
|
|
219
228
|
}
|
|
220
229
|
case "ToServerAckCommands": {
|
|
221
|
-
const {
|
|
222
|
-
|
|
223
|
-
lastCommandCheckpoints.length > 0
|
|
224
|
-
? `[${lastCommandCheckpoints.map((cp) => `{actorId: "${cp.actorId}", index: ${stringifyBigInt(cp.index)}}`).join(", ")}]`
|
|
225
|
-
: "[]";
|
|
226
|
-
return `ToServerAckCommands{lastCommandCheckpoints: ${checkpointsStr}}`;
|
|
230
|
+
const { lastCommandIdx } = message.val;
|
|
231
|
+
return `ToServerAckCommands{lastCommandIdx: ${stringifyBigInt(lastCommandIdx)}}`;
|
|
227
232
|
}
|
|
228
233
|
case "ToServerStopping":
|
|
229
234
|
return "ToServerStopping";
|
|
230
|
-
case "
|
|
235
|
+
case "ToServerPing": {
|
|
231
236
|
const { ts } = message.val;
|
|
232
|
-
return `
|
|
237
|
+
return `ToServerPing{ts: ${stringifyBigInt(ts)}}`;
|
|
233
238
|
}
|
|
234
239
|
case "ToServerKvRequest": {
|
|
235
240
|
const { actorId, requestId, data } = message.val;
|
|
@@ -250,24 +255,19 @@ export function stringifyToServer(message: protocol.ToServer): string {
|
|
|
250
255
|
export function stringifyToClient(message: protocol.ToClient): string {
|
|
251
256
|
switch (message.tag) {
|
|
252
257
|
case "ToClientInit": {
|
|
253
|
-
const { runnerId, metadata } = message.val;
|
|
258
|
+
const { runnerId, lastEventIdx, metadata } = message.val;
|
|
254
259
|
const metadataStr = `{runnerLostThreshold: ${stringifyBigInt(metadata.runnerLostThreshold)}}`;
|
|
255
|
-
return `ToClientInit{runnerId: "${runnerId}", metadata: ${metadataStr}}`;
|
|
260
|
+
return `ToClientInit{runnerId: "${runnerId}", lastEventIdx: ${stringifyBigInt(lastEventIdx)}, metadata: ${metadataStr}}`;
|
|
256
261
|
}
|
|
257
|
-
case "
|
|
258
|
-
|
|
259
|
-
return `ToClientPing{ts: ${stringifyBigInt(ts)}}`;
|
|
262
|
+
case "ToClientClose":
|
|
263
|
+
return "ToClientClose";
|
|
260
264
|
case "ToClientCommands": {
|
|
261
265
|
const commands = message.val;
|
|
262
266
|
return `ToClientCommands{count: ${commands.length}, commands: [${commands.map((c) => stringifyCommandWrapper(c)).join(", ")}]}`;
|
|
263
267
|
}
|
|
264
268
|
case "ToClientAckEvents": {
|
|
265
|
-
const {
|
|
266
|
-
|
|
267
|
-
lastEventCheckpoints.length > 0
|
|
268
|
-
? `[${lastEventCheckpoints.map((cp) => `{actorId: "${cp.actorId}", index: ${stringifyBigInt(cp.index)}}`).join(", ")}]`
|
|
269
|
-
: "[]";
|
|
270
|
-
return `ToClientAckEvents{lastEventCheckpoints: ${checkpointsStr}}`;
|
|
269
|
+
const { lastEventIdx } = message.val;
|
|
270
|
+
return `ToClientAckEvents{lastEventIdx: ${stringifyBigInt(lastEventIdx)}}`;
|
|
271
271
|
}
|
|
272
272
|
case "ToClientKvResponse": {
|
|
273
273
|
const { requestId, data } = message.val;
|
package/src/tunnel.ts
CHANGED
|
@@ -10,12 +10,12 @@ import {
|
|
|
10
10
|
stringify as uuidstringify,
|
|
11
11
|
v4 as uuidv4,
|
|
12
12
|
} from "uuid";
|
|
13
|
-
import {
|
|
13
|
+
import type { Runner, RunnerActor } from "./mod";
|
|
14
14
|
import {
|
|
15
15
|
stringifyToClientTunnelMessageKind,
|
|
16
16
|
stringifyToServerTunnelMessageKind,
|
|
17
17
|
} from "./stringify";
|
|
18
|
-
import { arraysEqual, idToStr,
|
|
18
|
+
import { arraysEqual, idToStr, unreachable } from "./utils";
|
|
19
19
|
import {
|
|
20
20
|
HIBERNATABLE_SYMBOL,
|
|
21
21
|
WebSocketTunnelAdapter,
|
|
@@ -41,6 +41,12 @@ export interface HibernatingWebSocketMetadata {
|
|
|
41
41
|
headers: Record<string, string>;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
class RunnerShutdownError extends Error {
|
|
45
|
+
constructor() {
|
|
46
|
+
super("Runner shut down");
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
44
50
|
export class Tunnel {
|
|
45
51
|
#runner: Runner;
|
|
46
52
|
|
|
@@ -220,7 +226,7 @@ export class Tunnel {
|
|
|
220
226
|
this.log?.error({
|
|
221
227
|
msg: "error creating websocket during restore",
|
|
222
228
|
requestId: requestIdStr,
|
|
223
|
-
|
|
229
|
+
err,
|
|
224
230
|
});
|
|
225
231
|
|
|
226
232
|
// Close the WebSocket on error
|
|
@@ -285,7 +291,7 @@ export class Tunnel {
|
|
|
285
291
|
this.log?.error({
|
|
286
292
|
msg: "error creating stale websocket during restore",
|
|
287
293
|
requestId: requestIdStr,
|
|
288
|
-
|
|
294
|
+
err,
|
|
289
295
|
});
|
|
290
296
|
});
|
|
291
297
|
|
|
@@ -665,6 +671,9 @@ export class Tunnel {
|
|
|
665
671
|
message.messageKind.val,
|
|
666
672
|
);
|
|
667
673
|
break;
|
|
674
|
+
case "DeprecatedTunnelAck":
|
|
675
|
+
// Ignore deprecated tunnel ack messages
|
|
676
|
+
break;
|
|
668
677
|
default:
|
|
669
678
|
unreachable(message.messageKind);
|
|
670
679
|
}
|
package/src/utils.ts
CHANGED
|
@@ -157,19 +157,3 @@ export function idToStr(id: ArrayBuffer): string {
|
|
|
157
157
|
.map((byte) => byte.toString(16).padStart(2, "0"))
|
|
158
158
|
.join("");
|
|
159
159
|
}
|
|
160
|
-
|
|
161
|
-
export function stringifyError(error: unknown): string {
|
|
162
|
-
if (error instanceof Error) {
|
|
163
|
-
return `${error.name}: ${error.message}${error.stack ? `\n${error.stack}` : ""}`;
|
|
164
|
-
} else if (typeof error === "string") {
|
|
165
|
-
return error;
|
|
166
|
-
} else if (typeof error === "object" && error !== null) {
|
|
167
|
-
try {
|
|
168
|
-
return `${JSON.stringify(error)}`;
|
|
169
|
-
} catch {
|
|
170
|
-
return `[object ${error.constructor?.name || "Object"}]`;
|
|
171
|
-
}
|
|
172
|
-
} else {
|
|
173
|
-
return String(error);
|
|
174
|
-
}
|
|
175
|
-
}
|