@rivetkit/supabase 0.0.0-main.49693dc → 0.0.0-main.78336a1
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/mod.js +1534 -1220
- package/dist/mod.mjs +1534 -1220
- package/package.json +3 -3
package/dist/mod.mjs
CHANGED
|
@@ -297,196 +297,6 @@ var require_retry2 = __commonJS({
|
|
|
297
297
|
// src/mod.ts
|
|
298
298
|
import * as wasmBindings from "@rivetkit/rivetkit-wasm";
|
|
299
299
|
|
|
300
|
-
// ../rivetkit/dist/tsup/chunk-IXBD7BXC.js
|
|
301
|
-
var INTERNAL_ERROR_CODE = "internal_error";
|
|
302
|
-
var INTERNAL_ERROR_DESCRIPTION = "An internal error occurred";
|
|
303
|
-
var USER_ERROR_CODE = "user_error";
|
|
304
|
-
var BRIDGE_RIVET_ERROR_PREFIX = "__RIVET_ERROR_JSON__:";
|
|
305
|
-
function looksLikeRivetErrorOptions(value) {
|
|
306
|
-
return typeof value === "object" && value !== null && ("public" in value || "metadata" in value || "rayId" in value || "statusCode" in value || "actor" in value || "cause" in value);
|
|
307
|
-
}
|
|
308
|
-
function isTypedErrorTag(value) {
|
|
309
|
-
return value === "ActorError" || value === "RivetError";
|
|
310
|
-
}
|
|
311
|
-
function errorMessage(error46, fallback = String(error46)) {
|
|
312
|
-
if (error46 && typeof error46 === "object" && "message" in error46 && typeof error46.message === "string") {
|
|
313
|
-
return error46.message;
|
|
314
|
-
}
|
|
315
|
-
return fallback;
|
|
316
|
-
}
|
|
317
|
-
function isRivetErrorLike(error46) {
|
|
318
|
-
return typeof error46 === "object" && error46 !== null && "group" in error46 && typeof error46.group === "string" && "code" in error46 && typeof error46.code === "string" && "message" in error46 && typeof error46.message === "string" && (!("rayId" in error46) || error46.rayId === void 0 || typeof error46.rayId === "string") && (!("__type" in error46) || isTypedErrorTag(error46.__type));
|
|
319
|
-
}
|
|
320
|
-
function isActorAbortedError(error46) {
|
|
321
|
-
return isRivetErrorLike(error46) && error46.group === "actor" && error46.code === "aborted";
|
|
322
|
-
}
|
|
323
|
-
function isActorSpecifier(value) {
|
|
324
|
-
return typeof value === "object" && value !== null && "actorId" in value && typeof value.actorId === "string" && "generation" in value && typeof value.generation === "number" && (!("key" in value) || value.key === void 0 || typeof value.key === "string");
|
|
325
|
-
}
|
|
326
|
-
var RivetError = class extends Error {
|
|
327
|
-
__type = "RivetError";
|
|
328
|
-
public;
|
|
329
|
-
metadata;
|
|
330
|
-
rayId;
|
|
331
|
-
statusCode;
|
|
332
|
-
actor;
|
|
333
|
-
group;
|
|
334
|
-
code;
|
|
335
|
-
static isRivetError(error46) {
|
|
336
|
-
return isRivetErrorLike(error46);
|
|
337
|
-
}
|
|
338
|
-
static isActorError(error46) {
|
|
339
|
-
return isRivetErrorLike(error46);
|
|
340
|
-
}
|
|
341
|
-
constructor(group, code, message, options) {
|
|
342
|
-
const normalized = looksLikeRivetErrorOptions(options) ? options : { metadata: options };
|
|
343
|
-
super(message, { cause: normalized.cause });
|
|
344
|
-
this.name = "RivetError";
|
|
345
|
-
this.group = group;
|
|
346
|
-
this.code = code;
|
|
347
|
-
this.public = normalized.public ?? false;
|
|
348
|
-
this.metadata = normalized.metadata;
|
|
349
|
-
this.rayId = normalized.rayId ?? void 0;
|
|
350
|
-
this.statusCode = normalized.statusCode ?? (this.public ? 400 : 500);
|
|
351
|
-
this.actor = normalized.actor;
|
|
352
|
-
}
|
|
353
|
-
toString() {
|
|
354
|
-
return this.message;
|
|
355
|
-
}
|
|
356
|
-
};
|
|
357
|
-
var UserError = class extends RivetError {
|
|
358
|
-
constructor(message, options) {
|
|
359
|
-
super("user", (options == null ? void 0 : options.code) ?? USER_ERROR_CODE, message, {
|
|
360
|
-
public: true,
|
|
361
|
-
metadata: options == null ? void 0 : options.metadata,
|
|
362
|
-
cause: options == null ? void 0 : options.cause
|
|
363
|
-
});
|
|
364
|
-
}
|
|
365
|
-
};
|
|
366
|
-
function toRivetError(error46, fallback) {
|
|
367
|
-
if (typeof error46 === "string") {
|
|
368
|
-
const bridged = decodeBridgeRivetError(error46);
|
|
369
|
-
if (bridged) {
|
|
370
|
-
return bridged;
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
if (error46 instanceof Error) {
|
|
374
|
-
const bridged = decodeBridgeRivetError(error46.message);
|
|
375
|
-
if (bridged) {
|
|
376
|
-
return bridged;
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
if (isRivetErrorLike(error46)) {
|
|
380
|
-
return new RivetError(error46.group, error46.code, error46.message, {
|
|
381
|
-
public: error46.public,
|
|
382
|
-
statusCode: error46.statusCode,
|
|
383
|
-
metadata: error46.metadata,
|
|
384
|
-
rayId: error46.rayId,
|
|
385
|
-
actor: error46.actor,
|
|
386
|
-
cause: error46 instanceof Error ? error46.cause : void 0
|
|
387
|
-
});
|
|
388
|
-
}
|
|
389
|
-
return new RivetError(
|
|
390
|
-
(fallback == null ? void 0 : fallback.group) ?? "actor",
|
|
391
|
-
(fallback == null ? void 0 : fallback.code) ?? INTERNAL_ERROR_CODE,
|
|
392
|
-
errorMessage(error46, (fallback == null ? void 0 : fallback.message) ?? "Unknown error"),
|
|
393
|
-
{
|
|
394
|
-
public: fallback == null ? void 0 : fallback.public,
|
|
395
|
-
statusCode: fallback == null ? void 0 : fallback.statusCode,
|
|
396
|
-
metadata: fallback == null ? void 0 : fallback.metadata,
|
|
397
|
-
rayId: fallback == null ? void 0 : fallback.rayId,
|
|
398
|
-
actor: fallback == null ? void 0 : fallback.actor,
|
|
399
|
-
cause: error46 instanceof Error ? error46 : void 0
|
|
400
|
-
}
|
|
401
|
-
);
|
|
402
|
-
}
|
|
403
|
-
function encodeBridgeRivetError(error46) {
|
|
404
|
-
return `${BRIDGE_RIVET_ERROR_PREFIX}${JSON.stringify({
|
|
405
|
-
group: error46.group,
|
|
406
|
-
code: error46.code,
|
|
407
|
-
message: error46.message,
|
|
408
|
-
metadata: error46.metadata,
|
|
409
|
-
rayId: error46.rayId,
|
|
410
|
-
public: error46.public,
|
|
411
|
-
statusCode: error46.statusCode,
|
|
412
|
-
actor: error46.actor
|
|
413
|
-
})}`;
|
|
414
|
-
}
|
|
415
|
-
function decodeBridgeRivetErrorPayload(value) {
|
|
416
|
-
if (!value.startsWith(BRIDGE_RIVET_ERROR_PREFIX)) {
|
|
417
|
-
return void 0;
|
|
418
|
-
}
|
|
419
|
-
try {
|
|
420
|
-
const raw = JSON.parse(
|
|
421
|
-
value.slice(BRIDGE_RIVET_ERROR_PREFIX.length)
|
|
422
|
-
);
|
|
423
|
-
const payload = {
|
|
424
|
-
...raw,
|
|
425
|
-
rayId: raw.rayId ?? void 0
|
|
426
|
-
};
|
|
427
|
-
if (!isRivetErrorLike(payload)) {
|
|
428
|
-
return void 0;
|
|
429
|
-
}
|
|
430
|
-
if (payload.actor !== void 0 && payload.actor !== null && !isActorSpecifier(payload.actor)) {
|
|
431
|
-
return void 0;
|
|
432
|
-
}
|
|
433
|
-
return payload;
|
|
434
|
-
} catch {
|
|
435
|
-
return void 0;
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
function decodeBridgeRivetError(value) {
|
|
439
|
-
const payload = decodeBridgeRivetErrorPayload(value);
|
|
440
|
-
if (!payload) {
|
|
441
|
-
return void 0;
|
|
442
|
-
}
|
|
443
|
-
return new RivetError(payload.group, payload.code, payload.message, {
|
|
444
|
-
metadata: payload.metadata,
|
|
445
|
-
rayId: payload.rayId,
|
|
446
|
-
public: payload.public,
|
|
447
|
-
statusCode: payload.statusCode,
|
|
448
|
-
actor: payload.actor ?? void 0
|
|
449
|
-
});
|
|
450
|
-
}
|
|
451
|
-
function invalidRequest(error46) {
|
|
452
|
-
return new RivetError(
|
|
453
|
-
"request",
|
|
454
|
-
"invalid",
|
|
455
|
-
`Invalid request: ${errorMessage(error46, String(error46))}`,
|
|
456
|
-
{
|
|
457
|
-
public: true,
|
|
458
|
-
cause: error46 instanceof Error ? error46 : void 0
|
|
459
|
-
}
|
|
460
|
-
);
|
|
461
|
-
}
|
|
462
|
-
function actorNotFound(identifier) {
|
|
463
|
-
return new RivetError(
|
|
464
|
-
"actor",
|
|
465
|
-
"not_found",
|
|
466
|
-
identifier ? `Actor not found: ${identifier} (https://www.rivet.dev/docs/clients/javascript)` : "Actor not found (https://www.rivet.dev/docs/clients/javascript)",
|
|
467
|
-
{ public: true }
|
|
468
|
-
);
|
|
469
|
-
}
|
|
470
|
-
function forbiddenError() {
|
|
471
|
-
return new RivetError("auth", "forbidden", "Forbidden", {
|
|
472
|
-
public: true,
|
|
473
|
-
statusCode: 403
|
|
474
|
-
});
|
|
475
|
-
}
|
|
476
|
-
function unsupportedFeature(feature) {
|
|
477
|
-
return new RivetError(
|
|
478
|
-
"feature",
|
|
479
|
-
"unsupported",
|
|
480
|
-
`Unsupported feature: ${feature}`
|
|
481
|
-
);
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
// ../rivetkit/dist/tsup/chunk-5IU3MI7X.js
|
|
485
|
-
import {
|
|
486
|
-
pino,
|
|
487
|
-
stdTimeFunctions
|
|
488
|
-
} from "pino";
|
|
489
|
-
|
|
490
300
|
// ../../../node_modules/.pnpm/zod@4.1.13/node_modules/zod/v4/classic/external.js
|
|
491
301
|
var external_exports = {};
|
|
492
302
|
__export(external_exports, {
|
|
@@ -13157,281 +12967,937 @@ var classic_default = external_exports;
|
|
|
13157
12967
|
// ../../../node_modules/.pnpm/zod@4.1.13/node_modules/zod/v4/index.js
|
|
13158
12968
|
var v4_default = classic_default;
|
|
13159
12969
|
|
|
13160
|
-
// ../rivetkit/dist/tsup/chunk-
|
|
13161
|
-
|
|
13162
|
-
|
|
13163
|
-
|
|
13164
|
-
|
|
13165
|
-
var getRivetToken = () => getEnvUniversal("RIVET_TOKEN");
|
|
13166
|
-
var getRivetNamespace = () => getEnvUniversal("RIVET_NAMESPACE");
|
|
13167
|
-
var getRivetPool = () => getEnvUniversal("RIVET_POOL");
|
|
13168
|
-
var getRivetTotalSlots = () => {
|
|
13169
|
-
const value = getEnvUniversal("RIVET_TOTAL_SLOTS");
|
|
13170
|
-
return value !== void 0 ? parseInt(value, 10) : void 0;
|
|
13171
|
-
};
|
|
13172
|
-
var getRivetRunEngine = () => getEnvUniversal("RIVET_RUN_ENGINE") === "1";
|
|
13173
|
-
var getRivetRunEngineHost = () => getEnvUniversal("RIVET_RUN_ENGINE_HOST");
|
|
13174
|
-
var getRivetRunEnginePort = () => {
|
|
13175
|
-
const value = getEnvUniversal("RIVET_RUN_ENGINE_PORT");
|
|
13176
|
-
return value !== void 0 ? parseInt(value, 10) : void 0;
|
|
13177
|
-
};
|
|
13178
|
-
var getRivetRunEngineVersion = () => getEnvUniversal("RIVET_RUN_ENGINE_VERSION");
|
|
13179
|
-
var getRivetEnvoyVersion = () => {
|
|
13180
|
-
const value = getEnvUniversal("RIVET_ENVOY_VERSION");
|
|
13181
|
-
return value !== void 0 ? parseInt(value, 10) : void 0;
|
|
13182
|
-
};
|
|
13183
|
-
var getRivetPublicEndpoint = () => getEnvUniversal("RIVET_PUBLIC_ENDPOINT");
|
|
13184
|
-
var getRivetPublicToken = () => getEnvUniversal("RIVET_PUBLIC_TOKEN");
|
|
13185
|
-
var getRivetkitRuntime = () => getEnvUniversal("RIVETKIT_RUNTIME");
|
|
13186
|
-
var getRivetkitRuntimeMode = () => {
|
|
13187
|
-
const value = getEnvUniversal("RIVETKIT_RUNTIME_MODE");
|
|
13188
|
-
if (value === void 0) return "envoy";
|
|
13189
|
-
if (value === "envoy" || value === "serverless") return value;
|
|
13190
|
-
throw new Error(
|
|
13191
|
-
`RIVETKIT_RUNTIME_MODE env var must be "envoy" or "serverless"; got "${value}"`
|
|
13192
|
-
);
|
|
13193
|
-
};
|
|
13194
|
-
var getRivetkitPublicDir = () => {
|
|
13195
|
-
const value = getEnvUniversal("RIVETKIT_PUBLIC_DIR");
|
|
13196
|
-
return value === void 0 || value === "" ? void 0 : value;
|
|
13197
|
-
};
|
|
13198
|
-
function parsePortEnv(raw) {
|
|
13199
|
-
if (raw === void 0 || raw === "") return void 0;
|
|
13200
|
-
const parsed = Number.parseInt(raw, 10);
|
|
13201
|
-
if (!Number.isFinite(parsed) || parsed < 1 || parsed > 65535 || String(parsed) !== raw.trim()) {
|
|
13202
|
-
throw new Error(
|
|
13203
|
-
`RIVET_PORT env var must be an integer between 1 and 65535; got "${raw}"`
|
|
13204
|
-
);
|
|
12970
|
+
// ../rivetkit/dist/tsup/chunk-6W5VGLFT.js
|
|
12971
|
+
function flattenActionHandlers(actions) {
|
|
12972
|
+
const flattened = /* @__PURE__ */ Object.create(null);
|
|
12973
|
+
for (const { name, handler } of collectActionEntries(actions)) {
|
|
12974
|
+
flattened[name] = handler;
|
|
13205
12975
|
}
|
|
13206
|
-
return
|
|
13207
|
-
}
|
|
13208
|
-
var getLogLevel = () => getEnvUniversal("RIVET_LOG_LEVEL") ?? getEnvUniversal("LOG_LEVEL");
|
|
13209
|
-
var getLogTarget = () => getEnvUniversal("RIVET_LOG_TARGET") === "1";
|
|
13210
|
-
var getLogTimestamp = () => getEnvUniversal("RIVET_LOG_TIMESTAMP") === "1";
|
|
13211
|
-
var getLogMessage = () => getEnvUniversal("RIVET_LOG_MESSAGE") === "1";
|
|
13212
|
-
var getLogErrorStack = () => getEnvUniversal("RIVET_LOG_ERROR_STACK") === "1";
|
|
13213
|
-
var getNodeEnv = () => getEnvUniversal("NODE_ENV");
|
|
13214
|
-
var getNextPhase = () => getEnvUniversal("NEXT_PHASE");
|
|
13215
|
-
var isDev = () => getNodeEnv() !== "production";
|
|
13216
|
-
function assertUnreachable(x) {
|
|
13217
|
-
throw new Error(`Unreachable case: ${x}`);
|
|
13218
|
-
}
|
|
13219
|
-
function isCanonicalStructuredRivetError(error46) {
|
|
13220
|
-
return error46 instanceof RivetError || typeof error46 === "object" && error46 !== null && "__type" in error46 && error46.__type === "RivetError" && "group" in error46 && typeof error46.group === "string" && "code" in error46 && typeof error46.code === "string" && "message" in error46 && typeof error46.message === "string";
|
|
12976
|
+
return flattened;
|
|
13221
12977
|
}
|
|
13222
|
-
function
|
|
13223
|
-
|
|
13224
|
-
|
|
13225
|
-
|
|
13226
|
-
|
|
13227
|
-
|
|
13228
|
-
|
|
13229
|
-
|
|
13230
|
-
|
|
13231
|
-
|
|
13232
|
-
|
|
13233
|
-
|
|
13234
|
-
|
|
13235
|
-
code = error46.code;
|
|
13236
|
-
message = error46.message;
|
|
13237
|
-
metadata = error46.metadata;
|
|
13238
|
-
rayId = error46.rayId;
|
|
13239
|
-
actor2 = error46.actor;
|
|
13240
|
-
} else if (RivetError.isActorError(error46) && error46.public) {
|
|
13241
|
-
statusCode = "statusCode" in error46 && error46.statusCode ? error46.statusCode : 400;
|
|
13242
|
-
public_ = true;
|
|
13243
|
-
group = error46.group;
|
|
13244
|
-
code = error46.code;
|
|
13245
|
-
message = getErrorMessage(error46);
|
|
13246
|
-
metadata = error46.metadata;
|
|
13247
|
-
rayId = error46.rayId;
|
|
13248
|
-
actor2 = error46.actor;
|
|
13249
|
-
} else if (exposeInternalError) {
|
|
13250
|
-
if (RivetError.isActorError(error46)) {
|
|
13251
|
-
statusCode = 500;
|
|
13252
|
-
public_ = false;
|
|
13253
|
-
group = error46.group;
|
|
13254
|
-
code = error46.code;
|
|
13255
|
-
message = getErrorMessage(error46);
|
|
13256
|
-
metadata = error46.metadata;
|
|
13257
|
-
rayId = error46.rayId;
|
|
13258
|
-
actor2 = error46.actor;
|
|
13259
|
-
} else {
|
|
13260
|
-
statusCode = 500;
|
|
13261
|
-
public_ = false;
|
|
13262
|
-
group = "rivetkit";
|
|
13263
|
-
code = INTERNAL_ERROR_CODE;
|
|
13264
|
-
message = getErrorMessage(error46);
|
|
12978
|
+
function flattenActionInputSchemas(actions, schemas) {
|
|
12979
|
+
if (schemas === void 0) return void 0;
|
|
12980
|
+
if (!isRecord(schemas)) {
|
|
12981
|
+
throw new TypeError("actionInputSchemas must be an object");
|
|
12982
|
+
}
|
|
12983
|
+
const flattened = /* @__PURE__ */ Object.create(null);
|
|
12984
|
+
for (const { name, path: path2 } of collectActionEntries(actions)) {
|
|
12985
|
+
const nestedSchema = lookupNestedSchema(schemas, path2);
|
|
12986
|
+
const flatSchema = schemas[name];
|
|
12987
|
+
if (nestedSchema !== void 0 && flatSchema !== void 0 && nestedSchema !== flatSchema) {
|
|
12988
|
+
throw new TypeError(
|
|
12989
|
+
`Action input schema \`${name}\` is defined by both a nested path and a dotted key`
|
|
12990
|
+
);
|
|
13265
12991
|
}
|
|
13266
|
-
|
|
13267
|
-
|
|
13268
|
-
|
|
13269
|
-
group = "rivetkit";
|
|
13270
|
-
code = INTERNAL_ERROR_CODE;
|
|
13271
|
-
message = INTERNAL_ERROR_DESCRIPTION;
|
|
13272
|
-
if (RivetError.isActorError(error46)) {
|
|
13273
|
-
actor2 = error46.actor;
|
|
12992
|
+
const schema = nestedSchema ?? flatSchema;
|
|
12993
|
+
if (schema !== void 0) {
|
|
12994
|
+
flattened[name] = schema;
|
|
13274
12995
|
}
|
|
13275
|
-
metadata = {
|
|
13276
|
-
//url: `https://dashboard.rivet.dev/projects/${actorMetadata.project.slug}/environments/${actorMetadata.environment.slug}/actors?actorId=${actorMetadata.actor.id}`,
|
|
13277
|
-
};
|
|
13278
12996
|
}
|
|
13279
|
-
return
|
|
13280
|
-
__type: "ActorError",
|
|
13281
|
-
statusCode,
|
|
13282
|
-
public: public_,
|
|
13283
|
-
group,
|
|
13284
|
-
code,
|
|
13285
|
-
message,
|
|
13286
|
-
metadata,
|
|
13287
|
-
rayId,
|
|
13288
|
-
actor: actor2
|
|
13289
|
-
};
|
|
12997
|
+
return flattened;
|
|
13290
12998
|
}
|
|
13291
|
-
function
|
|
13292
|
-
|
|
13293
|
-
|
|
13294
|
-
|
|
13295
|
-
|
|
13296
|
-
|
|
13297
|
-
|
|
13298
|
-
|
|
12999
|
+
function collectActionEntries(actions) {
|
|
13000
|
+
const entries = [];
|
|
13001
|
+
const names = /* @__PURE__ */ new Set();
|
|
13002
|
+
visitActionGroup(actions ?? {}, [], entries, names);
|
|
13003
|
+
return entries;
|
|
13004
|
+
}
|
|
13005
|
+
function visitActionGroup(value, path2, entries, names) {
|
|
13006
|
+
if (!isRecord(value)) {
|
|
13007
|
+
throw new TypeError(
|
|
13008
|
+
`${formatActionPath(path2)} must be an action handler or group`
|
|
13009
|
+
);
|
|
13010
|
+
}
|
|
13011
|
+
for (const [segment, child] of Object.entries(value)) {
|
|
13012
|
+
const childPath = [...path2, segment];
|
|
13013
|
+
if (typeof child === "function") {
|
|
13014
|
+
const name = childPath.join(".");
|
|
13015
|
+
if (names.has(name)) {
|
|
13016
|
+
throw new TypeError(
|
|
13017
|
+
`Multiple action definitions flatten to \`${name}\``
|
|
13018
|
+
);
|
|
13299
13019
|
}
|
|
13300
|
-
|
|
13301
|
-
|
|
13020
|
+
names.add(name);
|
|
13021
|
+
entries.push({
|
|
13022
|
+
name,
|
|
13023
|
+
path: childPath,
|
|
13024
|
+
handler: child
|
|
13025
|
+
});
|
|
13302
13026
|
} else {
|
|
13303
|
-
|
|
13027
|
+
visitActionGroup(child, childPath, entries, names);
|
|
13304
13028
|
}
|
|
13305
|
-
}
|
|
13306
|
-
|
|
13307
|
-
|
|
13308
|
-
|
|
13309
|
-
|
|
13310
|
-
|
|
13311
|
-
return
|
|
13029
|
+
}
|
|
13030
|
+
}
|
|
13031
|
+
function lookupNestedSchema(schemas, path2) {
|
|
13032
|
+
let value = schemas;
|
|
13033
|
+
for (const segment of path2) {
|
|
13034
|
+
if (!isRecord(value) || !Object.hasOwn(value, segment)) {
|
|
13035
|
+
return void 0;
|
|
13312
13036
|
}
|
|
13313
|
-
|
|
13314
|
-
return `Unknown error: ${getErrorMessage(error46)}`;
|
|
13037
|
+
value = value[segment];
|
|
13315
13038
|
}
|
|
13039
|
+
return value;
|
|
13316
13040
|
}
|
|
13317
|
-
function
|
|
13318
|
-
if (
|
|
13319
|
-
return
|
|
13320
|
-
} else {
|
|
13321
|
-
return String(err);
|
|
13041
|
+
function isRecord(value) {
|
|
13042
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
13043
|
+
return false;
|
|
13322
13044
|
}
|
|
13045
|
+
const prototype = Object.getPrototypeOf(value);
|
|
13046
|
+
return prototype === Object.prototype || prototype === null;
|
|
13323
13047
|
}
|
|
13324
|
-
function
|
|
13325
|
-
return
|
|
13326
|
-
};
|
|
13048
|
+
function formatActionPath(path2) {
|
|
13049
|
+
return path2.length === 0 ? "actions" : `Action \`${path2.join(".")}\``;
|
|
13327
13050
|
}
|
|
13328
|
-
var
|
|
13329
|
-
|
|
13330
|
-
|
|
13331
|
-
|
|
13332
|
-
|
|
13333
|
-
|
|
13334
|
-
|
|
13335
|
-
|
|
13336
|
-
|
|
13337
|
-
|
|
13338
|
-
|
|
13339
|
-
|
|
13340
|
-
|
|
13341
|
-
|
|
13342
|
-
|
|
13343
|
-
|
|
13344
|
-
|
|
13345
|
-
|
|
13346
|
-
|
|
13347
|
-
|
|
13348
|
-
|
|
13349
|
-
|
|
13350
|
-
|
|
13351
|
-
|
|
13352
|
-
|
|
13353
|
-
|
|
13354
|
-
|
|
13355
|
-
|
|
13356
|
-
|
|
13357
|
-
|
|
13358
|
-
|
|
13359
|
-
|
|
13360
|
-
|
|
13361
|
-
|
|
13362
|
-
|
|
13363
|
-
|
|
13364
|
-
|
|
13365
|
-
|
|
13366
|
-
|
|
13367
|
-
|
|
13368
|
-
|
|
13369
|
-
|
|
13370
|
-
|
|
13371
|
-
|
|
13372
|
-
|
|
13373
|
-
|
|
13374
|
-
|
|
13375
|
-
|
|
13376
|
-
|
|
13377
|
-
|
|
13378
|
-
|
|
13379
|
-
|
|
13380
|
-
|
|
13381
|
-
|
|
13382
|
-
|
|
13383
|
-
|
|
13384
|
-
|
|
13385
|
-
|
|
13386
|
-
|
|
13387
|
-
|
|
13388
|
-
|
|
13389
|
-
|
|
13390
|
-
|
|
13391
|
-
|
|
13392
|
-
|
|
13393
|
-
|
|
13394
|
-
|
|
13395
|
-
|
|
13396
|
-
|
|
13397
|
-
|
|
13398
|
-
|
|
13399
|
-
|
|
13400
|
-
|
|
13401
|
-
|
|
13402
|
-
|
|
13403
|
-
|
|
13404
|
-
|
|
13405
|
-
|
|
13406
|
-
|
|
13407
|
-
|
|
13408
|
-
|
|
13409
|
-
|
|
13410
|
-
|
|
13411
|
-
|
|
13412
|
-
|
|
13413
|
-
|
|
13414
|
-
|
|
13415
|
-
|
|
13416
|
-
|
|
13417
|
-
|
|
13418
|
-
|
|
13419
|
-
|
|
13420
|
-
|
|
13421
|
-
|
|
13422
|
-
|
|
13423
|
-
|
|
13424
|
-
|
|
13425
|
-
|
|
13426
|
-
|
|
13427
|
-
|
|
13428
|
-
|
|
13429
|
-
|
|
13430
|
-
|
|
13431
|
-
|
|
13432
|
-
|
|
13433
|
-
|
|
13434
|
-
|
|
13051
|
+
var DEFAULT_SLEEP_GRACE_PERIOD = 15e3;
|
|
13052
|
+
var ACTOR_CONTEXT_INTERNAL_SYMBOL = /* @__PURE__ */ Symbol(
|
|
13053
|
+
"rivetkit.actor_context_internal"
|
|
13054
|
+
);
|
|
13055
|
+
var RAW_STATE_SYMBOL = /* @__PURE__ */ Symbol("rivetkit.raw_state");
|
|
13056
|
+
var CONN_STATE_MANAGER_SYMBOL = /* @__PURE__ */ Symbol("rivetkit.conn_state_manager");
|
|
13057
|
+
var zFunction = () => external_exports.custom((val) => typeof val === "function");
|
|
13058
|
+
var zActionTree = external_exports.custom((value) => {
|
|
13059
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
13060
|
+
return false;
|
|
13061
|
+
}
|
|
13062
|
+
const prototype = Object.getPrototypeOf(value);
|
|
13063
|
+
return prototype === Object.prototype || prototype === null;
|
|
13064
|
+
}).superRefine((actions, ctx) => {
|
|
13065
|
+
try {
|
|
13066
|
+
flattenActionHandlers(actions);
|
|
13067
|
+
} catch (error46) {
|
|
13068
|
+
ctx.addIssue({
|
|
13069
|
+
code: "custom",
|
|
13070
|
+
message: error46 instanceof Error ? error46.message : "Invalid action definition"
|
|
13071
|
+
});
|
|
13072
|
+
}
|
|
13073
|
+
});
|
|
13074
|
+
var WorkflowInspectorConfigSchema = external_exports.object({
|
|
13075
|
+
getHistory: zFunction(),
|
|
13076
|
+
getState: zFunction().optional(),
|
|
13077
|
+
onHistoryUpdated: zFunction().optional(),
|
|
13078
|
+
replayFromStep: zFunction().optional()
|
|
13079
|
+
});
|
|
13080
|
+
var RunInspectorConfigSchema = external_exports.object({
|
|
13081
|
+
workflow: WorkflowInspectorConfigSchema.optional()
|
|
13082
|
+
}).optional();
|
|
13083
|
+
var BUILTIN_INSPECTOR_TAB_IDS = [
|
|
13084
|
+
"workflow",
|
|
13085
|
+
"database",
|
|
13086
|
+
"state",
|
|
13087
|
+
"queue",
|
|
13088
|
+
"schedules",
|
|
13089
|
+
"connections",
|
|
13090
|
+
"console"
|
|
13091
|
+
];
|
|
13092
|
+
var BuiltinInspectorTabIdSchema = external_exports.enum(BUILTIN_INSPECTOR_TAB_IDS);
|
|
13093
|
+
var CUSTOM_INSPECTOR_TAB_ID_RE = /^[A-Za-z0-9_-]+$/;
|
|
13094
|
+
var CustomInspectorTabEntrySchema = external_exports.object({
|
|
13095
|
+
id: external_exports.string().regex(
|
|
13096
|
+
CUSTOM_INSPECTOR_TAB_ID_RE,
|
|
13097
|
+
"inspector.tabs[].id must contain only letters, digits, underscore, or dash"
|
|
13098
|
+
),
|
|
13099
|
+
label: external_exports.string().min(1),
|
|
13100
|
+
source: external_exports.string().min(1),
|
|
13101
|
+
/**
|
|
13102
|
+
* Optional icon id. The dashboard maps strings to glyphs (see its
|
|
13103
|
+
* icon registry); unknown ids fall back to a generic icon.
|
|
13104
|
+
*/
|
|
13105
|
+
icon: external_exports.string().min(1).optional(),
|
|
13106
|
+
hidden: external_exports.literal(false).optional()
|
|
13107
|
+
}).strict();
|
|
13108
|
+
var HideInspectorTabEntrySchema = external_exports.object({
|
|
13109
|
+
id: BuiltinInspectorTabIdSchema,
|
|
13110
|
+
hidden: external_exports.literal(true)
|
|
13111
|
+
}).strict();
|
|
13112
|
+
var InspectorTabEntrySchema = external_exports.union([
|
|
13113
|
+
CustomInspectorTabEntrySchema,
|
|
13114
|
+
HideInspectorTabEntrySchema
|
|
13115
|
+
]);
|
|
13116
|
+
var ActorInspectorConfigSchema = external_exports.object({
|
|
13117
|
+
tabs: external_exports.array(InspectorTabEntrySchema).default(() => [])
|
|
13118
|
+
}).strict().refine(
|
|
13119
|
+
(data) => {
|
|
13120
|
+
const ids = data.tabs.map((t) => t.id);
|
|
13121
|
+
return new Set(ids).size === ids.length;
|
|
13122
|
+
},
|
|
13123
|
+
{ message: "Duplicate id in inspector.tabs", path: ["tabs"] }
|
|
13124
|
+
).refine(
|
|
13125
|
+
(data) => {
|
|
13126
|
+
const builtinSet = new Set(BUILTIN_INSPECTOR_TAB_IDS);
|
|
13127
|
+
return data.tabs.every(
|
|
13128
|
+
(t) => t.hidden === true || !builtinSet.has(t.id)
|
|
13129
|
+
);
|
|
13130
|
+
},
|
|
13131
|
+
{
|
|
13132
|
+
message: "Custom inspector tab id collides with a built-in (use hidden: true to hide a built-in)",
|
|
13133
|
+
path: ["tabs"]
|
|
13134
|
+
}
|
|
13135
|
+
);
|
|
13136
|
+
var RunConfigSchema = external_exports.object({
|
|
13137
|
+
/** Display name for the actor in the Inspector UI. */
|
|
13138
|
+
name: external_exports.string().optional(),
|
|
13139
|
+
/** Icon for the actor in the Inspector UI. Can be an emoji or FontAwesome icon name. */
|
|
13140
|
+
icon: external_exports.string().optional(),
|
|
13141
|
+
/** The run handler function. */
|
|
13142
|
+
run: zFunction(),
|
|
13143
|
+
/** Inspector integration for long-running run handlers. */
|
|
13144
|
+
inspector: RunInspectorConfigSchema.optional()
|
|
13145
|
+
});
|
|
13146
|
+
var RUN_FUNCTION_CONFIG_SYMBOL = /* @__PURE__ */ Symbol.for("rivetkit.run_function_config");
|
|
13147
|
+
function defineRunHandler(run, options) {
|
|
13148
|
+
if (options.inspectorKind === void 0 !== (options.createInspector === void 0)) {
|
|
13149
|
+
throw new TypeError(
|
|
13150
|
+
"defineRunHandler requires inspectorKind and createInspector together"
|
|
13151
|
+
);
|
|
13152
|
+
}
|
|
13153
|
+
Object.defineProperty(run, RUN_FUNCTION_CONFIG_SYMBOL, {
|
|
13154
|
+
configurable: false,
|
|
13155
|
+
enumerable: false,
|
|
13156
|
+
writable: false,
|
|
13157
|
+
value: {
|
|
13158
|
+
name: options.name,
|
|
13159
|
+
icon: options.icon,
|
|
13160
|
+
inspectorKind: options.inspectorKind,
|
|
13161
|
+
createInspector: options.createInspector
|
|
13162
|
+
}
|
|
13163
|
+
});
|
|
13164
|
+
return run;
|
|
13165
|
+
}
|
|
13166
|
+
function getRunInspectorKind(run) {
|
|
13167
|
+
var _a2;
|
|
13168
|
+
if (!run || typeof run !== "function") return void 0;
|
|
13169
|
+
return (_a2 = run[RUN_FUNCTION_CONFIG_SYMBOL]) == null ? void 0 : _a2.inspectorKind;
|
|
13170
|
+
}
|
|
13171
|
+
function createRunInspector(run, context) {
|
|
13172
|
+
var _a2, _b;
|
|
13173
|
+
if (!run || typeof run !== "function") return void 0;
|
|
13174
|
+
return (_b = (_a2 = run[RUN_FUNCTION_CONFIG_SYMBOL]) == null ? void 0 : _a2.createInspector) == null ? void 0 : _b.call(_a2, context);
|
|
13175
|
+
}
|
|
13176
|
+
var zRunHandler = external_exports.union([zFunction(), RunConfigSchema]).optional();
|
|
13177
|
+
function getRunFunction(run) {
|
|
13178
|
+
if (!run) return void 0;
|
|
13179
|
+
if (typeof run === "function") return run;
|
|
13180
|
+
return run.run;
|
|
13181
|
+
}
|
|
13182
|
+
function getRunMetadata(run) {
|
|
13183
|
+
if (!run) return {};
|
|
13184
|
+
if (typeof run === "function") {
|
|
13185
|
+
const config3 = run[RUN_FUNCTION_CONFIG_SYMBOL];
|
|
13186
|
+
if (!config3) return {};
|
|
13187
|
+
return { name: config3.name, icon: config3.icon };
|
|
13188
|
+
}
|
|
13189
|
+
return { name: run.name, icon: run.icon };
|
|
13190
|
+
}
|
|
13191
|
+
function getRunInspectorConfig(run, actor2) {
|
|
13192
|
+
if (!run) return void 0;
|
|
13193
|
+
if (typeof run === "function") {
|
|
13194
|
+
const config3 = run[RUN_FUNCTION_CONFIG_SYMBOL];
|
|
13195
|
+
return (config3 == null ? void 0 : config3.inspectorFactory) ? config3.inspectorFactory(actor2) : config3 == null ? void 0 : config3.inspector;
|
|
13196
|
+
}
|
|
13197
|
+
return run.inspector;
|
|
13198
|
+
}
|
|
13199
|
+
function hasRunInspectorConfig(run) {
|
|
13200
|
+
if (!run) return false;
|
|
13201
|
+
if (typeof run !== "function") return run.inspector !== void 0;
|
|
13202
|
+
const config3 = run[RUN_FUNCTION_CONFIG_SYMBOL];
|
|
13203
|
+
return (config3 == null ? void 0 : config3.inspectorKind) !== void 0 || (config3 == null ? void 0 : config3.createInspector) !== void 0 || (config3 == null ? void 0 : config3.inspector) !== void 0 || (config3 == null ? void 0 : config3.inspectorFactory) !== void 0;
|
|
13204
|
+
}
|
|
13205
|
+
function disposeRunInspector(run, actorId) {
|
|
13206
|
+
var _a2;
|
|
13207
|
+
if (!run || typeof run !== "function") {
|
|
13208
|
+
return;
|
|
13209
|
+
}
|
|
13210
|
+
const config3 = run[RUN_FUNCTION_CONFIG_SYMBOL];
|
|
13211
|
+
(_a2 = config3 == null ? void 0 : config3.disposeInspector) == null ? void 0 : _a2.call(config3, actorId);
|
|
13212
|
+
}
|
|
13213
|
+
var GlobalActorOptionsBaseSchema = external_exports.object({
|
|
13214
|
+
/** Display name for the actor in the Inspector UI. */
|
|
13215
|
+
name: external_exports.string().optional(),
|
|
13216
|
+
/** Icon for the actor in the Inspector UI. Can be an emoji or FontAwesome icon name. */
|
|
13217
|
+
icon: external_exports.string().optional(),
|
|
13218
|
+
/** Enables the experimental Actor Runtime Socket for this actor. */
|
|
13219
|
+
enableActorRuntimeSocket: external_exports.boolean().default(false),
|
|
13220
|
+
/**
|
|
13221
|
+
* Can hibernate WebSockets for onWebSocket.
|
|
13222
|
+
*
|
|
13223
|
+
* WebSockets using actions/events are hibernatable by default.
|
|
13224
|
+
*
|
|
13225
|
+
* @experimental
|
|
13226
|
+
**/
|
|
13227
|
+
canHibernateWebSocket: external_exports.union([external_exports.boolean(), zFunction()]).default(false)
|
|
13228
|
+
}).strict();
|
|
13229
|
+
var GlobalActorOptionsSchema = GlobalActorOptionsBaseSchema.prefault(
|
|
13230
|
+
() => ({})
|
|
13231
|
+
);
|
|
13232
|
+
var InstanceActorOptionsBaseSchema = external_exports.object({
|
|
13233
|
+
createVarsTimeout: external_exports.number().positive().default(5e3),
|
|
13234
|
+
createConnStateTimeout: external_exports.number().positive().default(5e3),
|
|
13235
|
+
onBeforeConnectTimeout: external_exports.number().positive().default(5e3),
|
|
13236
|
+
onConnectTimeout: external_exports.number().positive().default(5e3),
|
|
13237
|
+
onMigrateTimeout: external_exports.number().positive().default(3e4),
|
|
13238
|
+
sleepGracePeriod: external_exports.number().positive().default(DEFAULT_SLEEP_GRACE_PERIOD),
|
|
13239
|
+
/** @deprecated `onDestroyTimeout` is folded into `sleepGracePeriod`, which now bounds the entire graceful shutdown window for both sleep and destroy. Will be removed in 2.2.0. */
|
|
13240
|
+
onDestroyTimeout: external_exports.number().positive().optional(),
|
|
13241
|
+
/** @deprecated `waitUntilTimeout` is folded into `sleepGracePeriod`, which now bounds the entire graceful shutdown window for both sleep and destroy. Will be removed in 2.2.0. */
|
|
13242
|
+
waitUntilTimeout: external_exports.number().positive().optional(),
|
|
13243
|
+
stateSaveInterval: external_exports.number().positive().default(1e3),
|
|
13244
|
+
actionTimeout: external_exports.number().positive().default(6e4),
|
|
13245
|
+
connectionLivenessTimeout: external_exports.number().positive().default(2500),
|
|
13246
|
+
connectionLivenessInterval: external_exports.number().positive().default(5e3),
|
|
13247
|
+
/** @deprecated Use `c.keepAwake(promise)` to scope keep-awake to a specific operation, or keep `noSleep` for actors that must stay awake indefinitely. Will be removed in 2.2.0. */
|
|
13248
|
+
noSleep: external_exports.boolean().default(false),
|
|
13249
|
+
sleepTimeout: external_exports.number().positive().default(3e4),
|
|
13250
|
+
maxQueueSize: external_exports.number().positive().default(1e3),
|
|
13251
|
+
/** Maximum pending one-shot and recurring schedules. */
|
|
13252
|
+
maxSchedules: external_exports.number().int().nonnegative().default(1e3),
|
|
13253
|
+
maxQueueMessageSize: external_exports.number().positive().default(64 * 1024),
|
|
13254
|
+
/** @deprecated Internal storage moved to SQLite and no longer uses KV preloading, so this option is ignored. Will be removed in 2.2.0. */
|
|
13255
|
+
preloadMaxWorkflowBytes: external_exports.number().nonnegative().optional(),
|
|
13256
|
+
/** @deprecated Internal storage moved to SQLite and no longer uses KV preloading, so this option is ignored. Will be removed in 2.2.0. */
|
|
13257
|
+
preloadMaxConnectionsBytes: external_exports.number().nonnegative().optional()
|
|
13258
|
+
}).strict();
|
|
13259
|
+
var InstanceActorOptionsSchema = InstanceActorOptionsBaseSchema.prefault(() => ({}));
|
|
13260
|
+
var ActorOptionsSchema = GlobalActorOptionsBaseSchema.extend(
|
|
13261
|
+
InstanceActorOptionsBaseSchema.shape
|
|
13262
|
+
).strict().prefault(() => ({}));
|
|
13263
|
+
var ActorConfigSchema = external_exports.object({
|
|
13264
|
+
onCreate: zFunction().optional(),
|
|
13265
|
+
onDestroy: zFunction().optional(),
|
|
13266
|
+
onMigrate: zFunction().optional(),
|
|
13267
|
+
onWake: zFunction().optional(),
|
|
13268
|
+
onSleep: zFunction().optional(),
|
|
13269
|
+
run: zRunHandler,
|
|
13270
|
+
onStateChange: zFunction().optional(),
|
|
13271
|
+
onBeforeConnect: zFunction().optional(),
|
|
13272
|
+
onConnect: zFunction().optional(),
|
|
13273
|
+
onDisconnect: zFunction().optional(),
|
|
13274
|
+
onBeforeActionResponse: zFunction().optional(),
|
|
13275
|
+
onRequest: zFunction().optional(),
|
|
13276
|
+
onWebSocket: zFunction().optional(),
|
|
13277
|
+
actions: zActionTree.default(() => ({})),
|
|
13278
|
+
actionInputSchemas: external_exports.record(external_exports.string(), external_exports.any()).optional(),
|
|
13279
|
+
connParamsSchema: external_exports.any().optional(),
|
|
13280
|
+
events: external_exports.record(external_exports.string(), external_exports.any()).optional(),
|
|
13281
|
+
queues: external_exports.record(external_exports.string(), external_exports.any()).optional(),
|
|
13282
|
+
state: external_exports.any().optional(),
|
|
13283
|
+
createState: zFunction().optional(),
|
|
13284
|
+
connState: external_exports.any().optional(),
|
|
13285
|
+
createConnState: zFunction().optional(),
|
|
13286
|
+
vars: external_exports.any().optional(),
|
|
13287
|
+
db: external_exports.any().optional(),
|
|
13288
|
+
createVars: zFunction().optional(),
|
|
13289
|
+
options: ActorOptionsSchema,
|
|
13290
|
+
inspector: ActorInspectorConfigSchema.optional()
|
|
13291
|
+
}).strict().refine(
|
|
13292
|
+
(data) => !(data.state !== void 0 && data.createState !== void 0),
|
|
13293
|
+
{
|
|
13294
|
+
message: "Cannot define both 'state' and 'createState'",
|
|
13295
|
+
path: ["state"]
|
|
13296
|
+
}
|
|
13297
|
+
).refine(
|
|
13298
|
+
(data) => !(data.connState !== void 0 && data.createConnState !== void 0),
|
|
13299
|
+
{
|
|
13300
|
+
message: "Cannot define both 'connState' and 'createConnState'",
|
|
13301
|
+
path: ["connState"]
|
|
13302
|
+
}
|
|
13303
|
+
).refine(
|
|
13304
|
+
(data) => !(data.vars !== void 0 && data.createVars !== void 0),
|
|
13305
|
+
{
|
|
13306
|
+
message: "Cannot define both 'vars' and 'createVars'",
|
|
13307
|
+
path: ["vars"]
|
|
13308
|
+
}
|
|
13309
|
+
);
|
|
13310
|
+
var DocActorOptionsSchema = external_exports.object({
|
|
13311
|
+
name: external_exports.string().optional().describe("Display name for the actor in the Inspector UI."),
|
|
13312
|
+
icon: external_exports.string().optional().describe(
|
|
13313
|
+
"Icon for the actor in the Inspector UI. Can be an emoji (e.g., '\u{1F680}') or FontAwesome icon name (e.g., 'rocket')."
|
|
13314
|
+
),
|
|
13315
|
+
enableActorRuntimeSocket: external_exports.boolean().optional().describe(
|
|
13316
|
+
"Enables the experimental Actor Runtime Socket for this actor. Default: false"
|
|
13317
|
+
),
|
|
13318
|
+
createVarsTimeout: external_exports.number().optional().describe("Timeout in ms for createVars handler. Default: 5000"),
|
|
13319
|
+
createConnStateTimeout: external_exports.number().optional().describe(
|
|
13320
|
+
"Timeout in ms for createConnState handler. Default: 5000"
|
|
13321
|
+
),
|
|
13322
|
+
onMigrateTimeout: external_exports.number().optional().describe("Timeout in ms for onMigrate handler. Default: 30000"),
|
|
13323
|
+
onBeforeConnectTimeout: external_exports.number().optional().describe(
|
|
13324
|
+
"Timeout in ms for onBeforeConnect handler. Default: 5000"
|
|
13325
|
+
),
|
|
13326
|
+
onConnectTimeout: external_exports.number().optional().describe("Timeout in ms for onConnect handler. Default: 5000"),
|
|
13327
|
+
sleepGracePeriod: external_exports.number().optional().describe(
|
|
13328
|
+
`Max time in ms for the graceful shutdown window. Covers lifecycle hooks (onSleep, onDestroy), the run handler wait, async raw WebSocket handlers, disconnect callbacks, and final state serialization. Default: ${DEFAULT_SLEEP_GRACE_PERIOD}.`
|
|
13329
|
+
),
|
|
13330
|
+
onDestroyTimeout: external_exports.number().optional().describe(
|
|
13331
|
+
"Deprecated. Folded into sleepGracePeriod, which now bounds the entire graceful shutdown window for both sleep and destroy. Will be removed in 2.2.0."
|
|
13332
|
+
),
|
|
13333
|
+
waitUntilTimeout: external_exports.number().optional().describe(
|
|
13334
|
+
"Deprecated. Folded into sleepGracePeriod, which now bounds the entire graceful shutdown window for both sleep and destroy. Will be removed in 2.2.0."
|
|
13335
|
+
),
|
|
13336
|
+
stateSaveInterval: external_exports.number().optional().describe(
|
|
13337
|
+
"Interval in ms between automatic state saves. Default: 1000"
|
|
13338
|
+
),
|
|
13339
|
+
actionTimeout: external_exports.number().optional().describe("Timeout in ms for action handlers. Default: 60000"),
|
|
13340
|
+
connectionLivenessTimeout: external_exports.number().optional().describe(
|
|
13341
|
+
"Timeout in ms for connection liveness checks. Default: 2500"
|
|
13342
|
+
),
|
|
13343
|
+
connectionLivenessInterval: external_exports.number().optional().describe(
|
|
13344
|
+
"Interval in ms between connection liveness checks. Default: 5000"
|
|
13345
|
+
),
|
|
13346
|
+
noSleep: external_exports.boolean().optional().describe(
|
|
13347
|
+
"Deprecated. If true, the actor will never sleep. Use c.keepAwake(promise) to scope keep-awake to a specific operation instead. Default: false"
|
|
13348
|
+
),
|
|
13349
|
+
sleepTimeout: external_exports.number().optional().describe(
|
|
13350
|
+
"Time in ms of inactivity before the actor sleeps. Default: 30000"
|
|
13351
|
+
),
|
|
13352
|
+
maxQueueSize: external_exports.number().optional().describe(
|
|
13353
|
+
"Maximum number of queue messages before rejecting new messages. Default: 1000"
|
|
13354
|
+
),
|
|
13355
|
+
maxSchedules: external_exports.number().int().nonnegative().optional().describe(
|
|
13356
|
+
"Maximum pending one-shot and recurring schedules before rejecting new schedules. Default: 1000"
|
|
13357
|
+
),
|
|
13358
|
+
maxQueueMessageSize: external_exports.number().optional().describe(
|
|
13359
|
+
"Maximum size of each queue message in bytes. Default: 65536"
|
|
13360
|
+
),
|
|
13361
|
+
canHibernateWebSocket: external_exports.boolean().optional().describe(
|
|
13362
|
+
"Whether WebSockets using onWebSocket can be hibernated. WebSockets using actions/events are hibernatable by default. Default: false"
|
|
13363
|
+
)
|
|
13364
|
+
}).describe("Actor options for timeouts and behavior configuration.");
|
|
13365
|
+
var DocActorConfigSchema = external_exports.object({
|
|
13366
|
+
state: external_exports.unknown().optional().describe(
|
|
13367
|
+
"Initial state value for the actor. Cannot be used with createState."
|
|
13368
|
+
),
|
|
13369
|
+
createState: external_exports.unknown().optional().describe(
|
|
13370
|
+
"Function to create initial state. Receives context and input. Cannot be used with state."
|
|
13371
|
+
),
|
|
13372
|
+
connState: external_exports.unknown().optional().describe(
|
|
13373
|
+
"Initial connection state value. Cannot be used with createConnState."
|
|
13374
|
+
),
|
|
13375
|
+
createConnState: external_exports.unknown().optional().describe(
|
|
13376
|
+
"Function to create connection state. Receives context and connection params. The pending connection is not visible in c.conns until this succeeds. Cannot be used with connState."
|
|
13377
|
+
),
|
|
13378
|
+
vars: external_exports.unknown().optional().describe(
|
|
13379
|
+
"Initial ephemeral variables value. Cannot be used with createVars."
|
|
13380
|
+
),
|
|
13381
|
+
createVars: external_exports.unknown().optional().describe(
|
|
13382
|
+
"Function to create ephemeral variables. Receives context and driver context. Cannot be used with vars."
|
|
13383
|
+
),
|
|
13384
|
+
db: external_exports.unknown().optional().describe("Database provider instance for the actor."),
|
|
13385
|
+
onCreate: external_exports.unknown().optional().describe(
|
|
13386
|
+
"Called when the actor is first initialized. Use to initialize state."
|
|
13387
|
+
),
|
|
13388
|
+
onDestroy: external_exports.unknown().optional().describe("Called when the actor is destroyed."),
|
|
13389
|
+
onMigrate: external_exports.unknown().optional().describe(
|
|
13390
|
+
"Called on every actor start after persisted state loads and before onWake. Use for repeatable schema migrations."
|
|
13391
|
+
),
|
|
13392
|
+
onWake: external_exports.unknown().optional().describe(
|
|
13393
|
+
"Called when the actor wakes up and is ready to receive connections and actions."
|
|
13394
|
+
),
|
|
13395
|
+
onSleep: external_exports.unknown().optional().describe(
|
|
13396
|
+
"Called when the actor is stopping or sleeping. Use to clean up resources."
|
|
13397
|
+
),
|
|
13398
|
+
run: external_exports.unknown().optional().describe(
|
|
13399
|
+
"Called after actor starts. Does not block startup. Use for background tasks like queue processing or tick loops. If it exits, the actor follows the normal idle sleep timeout once idle. If it throws, the actor logs the error and then follows the normal idle sleep timeout once idle."
|
|
13400
|
+
),
|
|
13401
|
+
onStateChange: external_exports.unknown().optional().describe(
|
|
13402
|
+
"Called when the actor's state changes. State changes within this hook won't trigger recursion."
|
|
13403
|
+
),
|
|
13404
|
+
onBeforeConnect: external_exports.unknown().optional().describe(
|
|
13405
|
+
"Called before a client connects. Throw an error to reject the connection. The pending connection is not visible in c.conns while this runs."
|
|
13406
|
+
),
|
|
13407
|
+
onConnect: external_exports.unknown().optional().describe(
|
|
13408
|
+
"Called when a client successfully connects. The connection is visible in c.conns before this runs."
|
|
13409
|
+
),
|
|
13410
|
+
onDisconnect: external_exports.unknown().optional().describe("Called when a client disconnects."),
|
|
13411
|
+
onBeforeActionResponse: external_exports.unknown().optional().describe(
|
|
13412
|
+
"Called before sending an action response. Use to transform output."
|
|
13413
|
+
),
|
|
13414
|
+
onRequest: external_exports.unknown().optional().describe(
|
|
13415
|
+
"Called for raw HTTP requests to /actors/{name}/http/* endpoints."
|
|
13416
|
+
),
|
|
13417
|
+
onWebSocket: external_exports.unknown().optional().describe(
|
|
13418
|
+
"Called for raw WebSocket connections to /actors/{name}/websocket/* endpoints."
|
|
13419
|
+
),
|
|
13420
|
+
actions: external_exports.record(external_exports.string(), external_exports.unknown()).optional().describe(
|
|
13421
|
+
"Tree of action names or nested groups to handler functions. Nested paths use dot-separated low-level action names. Defaults to an empty object."
|
|
13422
|
+
),
|
|
13423
|
+
actionInputSchemas: external_exports.record(external_exports.string(), external_exports.unknown()).optional().describe(
|
|
13424
|
+
"Optional schemas for validating action argument tuples in native runtimes. May mirror nested action groups or use dot-separated low-level action names."
|
|
13425
|
+
),
|
|
13426
|
+
connParamsSchema: external_exports.unknown().optional().describe(
|
|
13427
|
+
"Optional schema for validating connection params in native runtimes."
|
|
13428
|
+
),
|
|
13429
|
+
events: external_exports.record(external_exports.string(), external_exports.unknown()).optional().describe("Map of event names to schemas."),
|
|
13430
|
+
queues: external_exports.record(external_exports.string(), external_exports.unknown()).optional().describe("Map of queue names to schemas."),
|
|
13431
|
+
options: DocActorOptionsSchema.optional()
|
|
13432
|
+
}).describe("Actor configuration passed to the actor() function.");
|
|
13433
|
+
|
|
13434
|
+
// ../rivetkit/dist/tsup/chunk-OUQUIBVW.js
|
|
13435
|
+
var INTERNAL_ERROR_CODE = "internal_error";
|
|
13436
|
+
var INTERNAL_ERROR_DESCRIPTION = "An internal error occurred";
|
|
13437
|
+
var USER_ERROR_CODE = "user_error";
|
|
13438
|
+
var BRIDGE_RIVET_ERROR_PREFIX = "__RIVET_ERROR_JSON__:";
|
|
13439
|
+
function looksLikeRivetErrorOptions(value) {
|
|
13440
|
+
return typeof value === "object" && value !== null && ("public" in value || "metadata" in value || "rayId" in value || "statusCode" in value || "actor" in value || "cause" in value);
|
|
13441
|
+
}
|
|
13442
|
+
function isTypedErrorTag(value) {
|
|
13443
|
+
return value === "ActorError" || value === "RivetError";
|
|
13444
|
+
}
|
|
13445
|
+
function errorMessage(error46, fallback = String(error46)) {
|
|
13446
|
+
if (error46 && typeof error46 === "object" && "message" in error46 && typeof error46.message === "string") {
|
|
13447
|
+
return error46.message;
|
|
13448
|
+
}
|
|
13449
|
+
return fallback;
|
|
13450
|
+
}
|
|
13451
|
+
function isRivetErrorLike(error46) {
|
|
13452
|
+
return typeof error46 === "object" && error46 !== null && "group" in error46 && typeof error46.group === "string" && "code" in error46 && typeof error46.code === "string" && "message" in error46 && typeof error46.message === "string" && (!("rayId" in error46) || error46.rayId === void 0 || typeof error46.rayId === "string") && (!("__type" in error46) || isTypedErrorTag(error46.__type));
|
|
13453
|
+
}
|
|
13454
|
+
function isActorAbortedError(error46) {
|
|
13455
|
+
return isRivetErrorLike(error46) && error46.group === "actor" && error46.code === "aborted";
|
|
13456
|
+
}
|
|
13457
|
+
function isActorSpecifier(value) {
|
|
13458
|
+
return typeof value === "object" && value !== null && "actorId" in value && typeof value.actorId === "string" && "generation" in value && typeof value.generation === "number" && (!("key" in value) || value.key === void 0 || typeof value.key === "string");
|
|
13459
|
+
}
|
|
13460
|
+
var RivetError = class extends Error {
|
|
13461
|
+
__type = "RivetError";
|
|
13462
|
+
public;
|
|
13463
|
+
metadata;
|
|
13464
|
+
rayId;
|
|
13465
|
+
statusCode;
|
|
13466
|
+
actor;
|
|
13467
|
+
group;
|
|
13468
|
+
code;
|
|
13469
|
+
static isRivetError(error46) {
|
|
13470
|
+
return isRivetErrorLike(error46);
|
|
13471
|
+
}
|
|
13472
|
+
static isActorError(error46) {
|
|
13473
|
+
return isRivetErrorLike(error46);
|
|
13474
|
+
}
|
|
13475
|
+
constructor(group, code, message, options) {
|
|
13476
|
+
const normalized = looksLikeRivetErrorOptions(options) ? options : { metadata: options };
|
|
13477
|
+
super(message, { cause: normalized.cause });
|
|
13478
|
+
this.name = "RivetError";
|
|
13479
|
+
this.group = group;
|
|
13480
|
+
this.code = code;
|
|
13481
|
+
this.public = normalized.public ?? false;
|
|
13482
|
+
this.metadata = normalized.metadata;
|
|
13483
|
+
this.rayId = normalized.rayId ?? void 0;
|
|
13484
|
+
this.statusCode = normalized.statusCode ?? (this.public ? 400 : 500);
|
|
13485
|
+
this.actor = normalized.actor;
|
|
13486
|
+
}
|
|
13487
|
+
toString() {
|
|
13488
|
+
return this.message;
|
|
13489
|
+
}
|
|
13490
|
+
};
|
|
13491
|
+
var UserError = class extends RivetError {
|
|
13492
|
+
constructor(message, options) {
|
|
13493
|
+
super("user", (options == null ? void 0 : options.code) ?? USER_ERROR_CODE, message, {
|
|
13494
|
+
public: true,
|
|
13495
|
+
metadata: options == null ? void 0 : options.metadata,
|
|
13496
|
+
cause: options == null ? void 0 : options.cause
|
|
13497
|
+
});
|
|
13498
|
+
}
|
|
13499
|
+
};
|
|
13500
|
+
function toRivetError(error46, fallback) {
|
|
13501
|
+
if (typeof error46 === "string") {
|
|
13502
|
+
const bridged = decodeBridgeRivetError(error46);
|
|
13503
|
+
if (bridged) {
|
|
13504
|
+
return bridged;
|
|
13505
|
+
}
|
|
13506
|
+
}
|
|
13507
|
+
if (error46 instanceof Error) {
|
|
13508
|
+
const bridged = decodeBridgeRivetError(error46.message);
|
|
13509
|
+
if (bridged) {
|
|
13510
|
+
return bridged;
|
|
13511
|
+
}
|
|
13512
|
+
}
|
|
13513
|
+
if (isRivetErrorLike(error46)) {
|
|
13514
|
+
return new RivetError(error46.group, error46.code, error46.message, {
|
|
13515
|
+
public: error46.public,
|
|
13516
|
+
statusCode: error46.statusCode,
|
|
13517
|
+
metadata: error46.metadata,
|
|
13518
|
+
rayId: error46.rayId,
|
|
13519
|
+
actor: error46.actor,
|
|
13520
|
+
cause: error46 instanceof Error ? error46.cause : void 0
|
|
13521
|
+
});
|
|
13522
|
+
}
|
|
13523
|
+
return new RivetError(
|
|
13524
|
+
(fallback == null ? void 0 : fallback.group) ?? "actor",
|
|
13525
|
+
(fallback == null ? void 0 : fallback.code) ?? INTERNAL_ERROR_CODE,
|
|
13526
|
+
errorMessage(error46, (fallback == null ? void 0 : fallback.message) ?? "Unknown error"),
|
|
13527
|
+
{
|
|
13528
|
+
public: fallback == null ? void 0 : fallback.public,
|
|
13529
|
+
statusCode: fallback == null ? void 0 : fallback.statusCode,
|
|
13530
|
+
metadata: fallback == null ? void 0 : fallback.metadata,
|
|
13531
|
+
rayId: fallback == null ? void 0 : fallback.rayId,
|
|
13532
|
+
actor: fallback == null ? void 0 : fallback.actor,
|
|
13533
|
+
cause: error46 instanceof Error ? error46 : void 0
|
|
13534
|
+
}
|
|
13535
|
+
);
|
|
13536
|
+
}
|
|
13537
|
+
function encodeBridgeRivetError(error46) {
|
|
13538
|
+
return `${BRIDGE_RIVET_ERROR_PREFIX}${JSON.stringify({
|
|
13539
|
+
group: error46.group,
|
|
13540
|
+
code: error46.code,
|
|
13541
|
+
message: error46.message,
|
|
13542
|
+
metadata: error46.metadata,
|
|
13543
|
+
rayId: error46.rayId,
|
|
13544
|
+
public: error46.public,
|
|
13545
|
+
statusCode: error46.statusCode,
|
|
13546
|
+
actor: error46.actor
|
|
13547
|
+
})}`;
|
|
13548
|
+
}
|
|
13549
|
+
function decodeBridgeRivetErrorPayload(value) {
|
|
13550
|
+
if (!value.startsWith(BRIDGE_RIVET_ERROR_PREFIX)) {
|
|
13551
|
+
return void 0;
|
|
13552
|
+
}
|
|
13553
|
+
try {
|
|
13554
|
+
const raw = JSON.parse(
|
|
13555
|
+
value.slice(BRIDGE_RIVET_ERROR_PREFIX.length)
|
|
13556
|
+
);
|
|
13557
|
+
const payload = {
|
|
13558
|
+
...raw,
|
|
13559
|
+
rayId: raw.rayId ?? void 0
|
|
13560
|
+
};
|
|
13561
|
+
if (!isRivetErrorLike(payload)) {
|
|
13562
|
+
return void 0;
|
|
13563
|
+
}
|
|
13564
|
+
if (payload.actor !== void 0 && payload.actor !== null && !isActorSpecifier(payload.actor)) {
|
|
13565
|
+
return void 0;
|
|
13566
|
+
}
|
|
13567
|
+
return payload;
|
|
13568
|
+
} catch {
|
|
13569
|
+
return void 0;
|
|
13570
|
+
}
|
|
13571
|
+
}
|
|
13572
|
+
function decodeBridgeRivetError(value) {
|
|
13573
|
+
const payload = decodeBridgeRivetErrorPayload(value);
|
|
13574
|
+
if (!payload) {
|
|
13575
|
+
return void 0;
|
|
13576
|
+
}
|
|
13577
|
+
return new RivetError(payload.group, payload.code, payload.message, {
|
|
13578
|
+
metadata: payload.metadata,
|
|
13579
|
+
rayId: payload.rayId,
|
|
13580
|
+
public: payload.public,
|
|
13581
|
+
statusCode: payload.statusCode,
|
|
13582
|
+
actor: payload.actor ?? void 0
|
|
13583
|
+
});
|
|
13584
|
+
}
|
|
13585
|
+
function invalidRequest(error46) {
|
|
13586
|
+
return new RivetError(
|
|
13587
|
+
"request",
|
|
13588
|
+
"invalid",
|
|
13589
|
+
`Invalid request: ${errorMessage(error46, String(error46))}`,
|
|
13590
|
+
{
|
|
13591
|
+
public: true,
|
|
13592
|
+
cause: error46 instanceof Error ? error46 : void 0
|
|
13593
|
+
}
|
|
13594
|
+
);
|
|
13595
|
+
}
|
|
13596
|
+
function actorNotFound(identifier) {
|
|
13597
|
+
return new RivetError(
|
|
13598
|
+
"actor",
|
|
13599
|
+
"not_found",
|
|
13600
|
+
identifier ? `Actor not found: ${identifier} (https://www.rivet.dev/docs/clients/javascript)` : "Actor not found (https://www.rivet.dev/docs/clients/javascript)",
|
|
13601
|
+
{ public: true }
|
|
13602
|
+
);
|
|
13603
|
+
}
|
|
13604
|
+
function forbiddenError() {
|
|
13605
|
+
return new RivetError("auth", "forbidden", "Forbidden", {
|
|
13606
|
+
public: true,
|
|
13607
|
+
statusCode: 403
|
|
13608
|
+
});
|
|
13609
|
+
}
|
|
13610
|
+
function unsupportedFeature(feature) {
|
|
13611
|
+
return new RivetError(
|
|
13612
|
+
"feature",
|
|
13613
|
+
"unsupported",
|
|
13614
|
+
`Unsupported feature: ${feature}`
|
|
13615
|
+
);
|
|
13616
|
+
}
|
|
13617
|
+
|
|
13618
|
+
// ../rivetkit/dist/tsup/chunk-5NBLGMI2.js
|
|
13619
|
+
import {
|
|
13620
|
+
pino,
|
|
13621
|
+
stdTimeFunctions
|
|
13622
|
+
} from "pino";
|
|
13623
|
+
var import_invariant = __toESM(require_invariant(), 1);
|
|
13624
|
+
import * as cbor from "cbor-x";
|
|
13625
|
+
var getRivetEngine = () => getEnvUniversal("RIVET_ENGINE");
|
|
13626
|
+
var getRivetEndpoint = () => getEnvUniversal("RIVET_ENDPOINT");
|
|
13627
|
+
var getRivetToken = () => getEnvUniversal("RIVET_TOKEN");
|
|
13628
|
+
var getRivetNamespace = () => getEnvUniversal("RIVET_NAMESPACE");
|
|
13629
|
+
var getRivetPool = () => getEnvUniversal("RIVET_POOL");
|
|
13630
|
+
var getRivetTotalSlots = () => {
|
|
13631
|
+
const value = getEnvUniversal("RIVET_TOTAL_SLOTS");
|
|
13632
|
+
return value !== void 0 ? parseInt(value, 10) : void 0;
|
|
13633
|
+
};
|
|
13634
|
+
var getRivetRunEngine = () => getEnvUniversal("RIVET_RUN_ENGINE") === "1";
|
|
13635
|
+
var getRivetRunEngineHost = () => getEnvUniversal("RIVET_RUN_ENGINE_HOST");
|
|
13636
|
+
var getRivetRunEnginePort = () => {
|
|
13637
|
+
const value = getEnvUniversal("RIVET_RUN_ENGINE_PORT");
|
|
13638
|
+
return value !== void 0 ? parseInt(value, 10) : void 0;
|
|
13639
|
+
};
|
|
13640
|
+
var getRivetRunEngineVersion = () => getEnvUniversal("RIVET_RUN_ENGINE_VERSION");
|
|
13641
|
+
var getRivetRunServices = () => {
|
|
13642
|
+
const value = getEnvUniversal("RIVET_RUN_SERVICES");
|
|
13643
|
+
return value === void 0 ? void 0 : value === "1";
|
|
13644
|
+
};
|
|
13645
|
+
var getRivetEnvoyVersion = () => {
|
|
13646
|
+
const value = getEnvUniversal("RIVET_ENVOY_VERSION");
|
|
13647
|
+
return value !== void 0 ? parseInt(value, 10) : void 0;
|
|
13648
|
+
};
|
|
13649
|
+
var getRivetPublicEndpoint = () => getEnvUniversal("RIVET_PUBLIC_ENDPOINT");
|
|
13650
|
+
var getRivetPublicToken = () => getEnvUniversal("RIVET_PUBLIC_TOKEN");
|
|
13651
|
+
var getRivetkitRuntime = () => getEnvUniversal("RIVETKIT_RUNTIME");
|
|
13652
|
+
var getRivetkitRuntimeMode = () => {
|
|
13653
|
+
const value = getEnvUniversal("RIVETKIT_RUNTIME_MODE");
|
|
13654
|
+
if (value === void 0) return "envoy";
|
|
13655
|
+
if (value === "envoy" || value === "serverless") return value;
|
|
13656
|
+
throw new Error(
|
|
13657
|
+
`RIVETKIT_RUNTIME_MODE env var must be "envoy" or "serverless"; got "${value}"`
|
|
13658
|
+
);
|
|
13659
|
+
};
|
|
13660
|
+
var getRivetkitPublicDir = () => {
|
|
13661
|
+
const value = getEnvUniversal("RIVETKIT_PUBLIC_DIR");
|
|
13662
|
+
return value === void 0 || value === "" ? void 0 : value;
|
|
13663
|
+
};
|
|
13664
|
+
function parsePortEnv(raw) {
|
|
13665
|
+
if (raw === void 0 || raw === "") return void 0;
|
|
13666
|
+
const parsed = Number.parseInt(raw, 10);
|
|
13667
|
+
if (!Number.isFinite(parsed) || parsed < 1 || parsed > 65535 || String(parsed) !== raw.trim()) {
|
|
13668
|
+
throw new Error(
|
|
13669
|
+
`RIVET_PORT env var must be an integer between 1 and 65535; got "${raw}"`
|
|
13670
|
+
);
|
|
13671
|
+
}
|
|
13672
|
+
return parsed;
|
|
13673
|
+
}
|
|
13674
|
+
var getLogLevel = () => getEnvUniversal("RIVET_LOG_LEVEL") ?? getEnvUniversal("LOG_LEVEL");
|
|
13675
|
+
var getLogTarget = () => getEnvUniversal("RIVET_LOG_TARGET") === "1";
|
|
13676
|
+
var getLogTimestamp = () => getEnvUniversal("RIVET_LOG_TIMESTAMP") === "1";
|
|
13677
|
+
var getLogMessage = () => getEnvUniversal("RIVET_LOG_MESSAGE") === "1";
|
|
13678
|
+
var getLogErrorStack = () => getEnvUniversal("RIVET_LOG_ERROR_STACK") === "1";
|
|
13679
|
+
var getNodeEnv = () => getEnvUniversal("NODE_ENV");
|
|
13680
|
+
var getNextPhase = () => getEnvUniversal("NEXT_PHASE");
|
|
13681
|
+
var isDev = () => getNodeEnv() !== "production";
|
|
13682
|
+
function assertUnreachable(x) {
|
|
13683
|
+
throw new Error(`Unreachable case: ${x}`);
|
|
13684
|
+
}
|
|
13685
|
+
function isCanonicalStructuredRivetError(error46) {
|
|
13686
|
+
return error46 instanceof RivetError || typeof error46 === "object" && error46 !== null && "__type" in error46 && error46.__type === "RivetError" && "group" in error46 && typeof error46.group === "string" && "code" in error46 && typeof error46.code === "string" && "message" in error46 && typeof error46.message === "string";
|
|
13687
|
+
}
|
|
13688
|
+
function deconstructError(error46, exposeInternalError = false) {
|
|
13689
|
+
let statusCode;
|
|
13690
|
+
let public_;
|
|
13691
|
+
let group;
|
|
13692
|
+
let code;
|
|
13693
|
+
let message;
|
|
13694
|
+
let metadata;
|
|
13695
|
+
let rayId;
|
|
13696
|
+
let actor2;
|
|
13697
|
+
if (isCanonicalStructuredRivetError(error46)) {
|
|
13698
|
+
statusCode = typeof error46.statusCode === "number" ? error46.statusCode : error46.public ? 400 : 500;
|
|
13699
|
+
public_ = error46.public ?? false;
|
|
13700
|
+
group = error46.group;
|
|
13701
|
+
code = error46.code;
|
|
13702
|
+
message = error46.message;
|
|
13703
|
+
metadata = error46.metadata;
|
|
13704
|
+
rayId = error46.rayId;
|
|
13705
|
+
actor2 = error46.actor;
|
|
13706
|
+
} else if (RivetError.isActorError(error46) && error46.public) {
|
|
13707
|
+
statusCode = "statusCode" in error46 && error46.statusCode ? error46.statusCode : 400;
|
|
13708
|
+
public_ = true;
|
|
13709
|
+
group = error46.group;
|
|
13710
|
+
code = error46.code;
|
|
13711
|
+
message = getErrorMessage(error46);
|
|
13712
|
+
metadata = error46.metadata;
|
|
13713
|
+
rayId = error46.rayId;
|
|
13714
|
+
actor2 = error46.actor;
|
|
13715
|
+
} else if (exposeInternalError) {
|
|
13716
|
+
if (RivetError.isActorError(error46)) {
|
|
13717
|
+
statusCode = 500;
|
|
13718
|
+
public_ = false;
|
|
13719
|
+
group = error46.group;
|
|
13720
|
+
code = error46.code;
|
|
13721
|
+
message = getErrorMessage(error46);
|
|
13722
|
+
metadata = error46.metadata;
|
|
13723
|
+
rayId = error46.rayId;
|
|
13724
|
+
actor2 = error46.actor;
|
|
13725
|
+
} else {
|
|
13726
|
+
statusCode = 500;
|
|
13727
|
+
public_ = false;
|
|
13728
|
+
group = "rivetkit";
|
|
13729
|
+
code = INTERNAL_ERROR_CODE;
|
|
13730
|
+
message = getErrorMessage(error46);
|
|
13731
|
+
}
|
|
13732
|
+
} else {
|
|
13733
|
+
statusCode = 500;
|
|
13734
|
+
public_ = false;
|
|
13735
|
+
group = "rivetkit";
|
|
13736
|
+
code = INTERNAL_ERROR_CODE;
|
|
13737
|
+
message = INTERNAL_ERROR_DESCRIPTION;
|
|
13738
|
+
if (RivetError.isActorError(error46)) {
|
|
13739
|
+
actor2 = error46.actor;
|
|
13740
|
+
}
|
|
13741
|
+
metadata = {
|
|
13742
|
+
//url: `https://dashboard.rivet.dev/projects/${actorMetadata.project.slug}/environments/${actorMetadata.environment.slug}/actors?actorId=${actorMetadata.actor.id}`,
|
|
13743
|
+
};
|
|
13744
|
+
}
|
|
13745
|
+
return {
|
|
13746
|
+
__type: "ActorError",
|
|
13747
|
+
statusCode,
|
|
13748
|
+
public: public_,
|
|
13749
|
+
group,
|
|
13750
|
+
code,
|
|
13751
|
+
message,
|
|
13752
|
+
metadata,
|
|
13753
|
+
rayId,
|
|
13754
|
+
actor: actor2
|
|
13755
|
+
};
|
|
13756
|
+
}
|
|
13757
|
+
function stringifyError(error46) {
|
|
13758
|
+
if (error46 instanceof Error) {
|
|
13759
|
+
if (typeof process !== "undefined" && getLogErrorStack()) {
|
|
13760
|
+
let stack;
|
|
13761
|
+
try {
|
|
13762
|
+
stack = error46.stack;
|
|
13763
|
+
} catch {
|
|
13764
|
+
stack = void 0;
|
|
13765
|
+
}
|
|
13766
|
+
return `${error46.name}: ${error46.message}${stack ? `
|
|
13767
|
+
${stack}` : ""}`;
|
|
13768
|
+
} else {
|
|
13769
|
+
return `${error46.name}: ${error46.message}`;
|
|
13770
|
+
}
|
|
13771
|
+
} else if (typeof error46 === "string") {
|
|
13772
|
+
return error46;
|
|
13773
|
+
} else if (typeof error46 === "object" && error46 !== null) {
|
|
13774
|
+
try {
|
|
13775
|
+
return `${JSON.stringify(error46)}`;
|
|
13776
|
+
} catch {
|
|
13777
|
+
return "[cannot stringify error]";
|
|
13778
|
+
}
|
|
13779
|
+
} else {
|
|
13780
|
+
return `Unknown error: ${getErrorMessage(error46)}`;
|
|
13781
|
+
}
|
|
13782
|
+
}
|
|
13783
|
+
function getErrorMessage(err) {
|
|
13784
|
+
if (err && typeof err === "object" && "message" in err && typeof err.message === "string") {
|
|
13785
|
+
return err.message;
|
|
13786
|
+
} else {
|
|
13787
|
+
return String(err);
|
|
13788
|
+
}
|
|
13789
|
+
}
|
|
13790
|
+
function noopNext() {
|
|
13791
|
+
return async () => {
|
|
13792
|
+
};
|
|
13793
|
+
}
|
|
13794
|
+
var package_default = {
|
|
13795
|
+
name: "rivetkit",
|
|
13796
|
+
version: "0.0.0-main.78336a1",
|
|
13797
|
+
description: "Lightweight libraries for building stateful actors on edge platforms",
|
|
13798
|
+
license: "Apache-2.0",
|
|
13799
|
+
keywords: [
|
|
13800
|
+
"rivetkit",
|
|
13801
|
+
"stateful",
|
|
13802
|
+
"serverless",
|
|
13803
|
+
"actors",
|
|
13804
|
+
"agents",
|
|
13805
|
+
"realtime",
|
|
13806
|
+
"websocket",
|
|
13807
|
+
"actors",
|
|
13808
|
+
"framework"
|
|
13809
|
+
],
|
|
13810
|
+
files: [
|
|
13811
|
+
"dist",
|
|
13812
|
+
"schemas",
|
|
13813
|
+
"src",
|
|
13814
|
+
"package.json"
|
|
13815
|
+
],
|
|
13816
|
+
type: "module",
|
|
13817
|
+
exports: {
|
|
13818
|
+
".": {
|
|
13819
|
+
import: {
|
|
13820
|
+
types: "./dist/tsup/mod.d.ts",
|
|
13821
|
+
default: "./dist/tsup/mod.js"
|
|
13822
|
+
},
|
|
13823
|
+
require: {
|
|
13824
|
+
types: "./dist/tsup/mod.d.cts",
|
|
13825
|
+
default: "./dist/tsup/mod.cjs"
|
|
13826
|
+
}
|
|
13827
|
+
},
|
|
13828
|
+
"./workflow": {
|
|
13829
|
+
import: {
|
|
13830
|
+
types: "./dist/tsup/workflow/mod.d.ts",
|
|
13831
|
+
default: "./dist/tsup/workflow/mod.js"
|
|
13832
|
+
},
|
|
13833
|
+
require: {
|
|
13834
|
+
types: "./dist/tsup/workflow/mod.d.cts",
|
|
13835
|
+
default: "./dist/tsup/workflow/mod.cjs"
|
|
13836
|
+
}
|
|
13837
|
+
},
|
|
13838
|
+
"./test": {
|
|
13839
|
+
import: {
|
|
13840
|
+
types: "./dist/tsup/test/mod.d.ts",
|
|
13841
|
+
default: "./dist/tsup/test/mod.js"
|
|
13842
|
+
},
|
|
13843
|
+
require: {
|
|
13844
|
+
types: "./dist/tsup/test/mod.d.cts",
|
|
13845
|
+
default: "./dist/tsup/test/mod.cjs"
|
|
13846
|
+
}
|
|
13847
|
+
},
|
|
13848
|
+
"./db": {
|
|
13849
|
+
import: {
|
|
13850
|
+
types: "./dist/tsup/db/mod.d.ts",
|
|
13851
|
+
default: "./dist/tsup/db/mod.js"
|
|
13852
|
+
},
|
|
13853
|
+
require: {
|
|
13854
|
+
types: "./dist/tsup/db/mod.d.cts",
|
|
13855
|
+
default: "./dist/tsup/db/mod.cjs"
|
|
13856
|
+
}
|
|
13857
|
+
},
|
|
13858
|
+
"./db/drizzle": {
|
|
13859
|
+
import: {
|
|
13860
|
+
types: "./dist/tsup/db/drizzle.d.ts",
|
|
13861
|
+
default: "./dist/tsup/db/drizzle.js"
|
|
13862
|
+
},
|
|
13863
|
+
require: {
|
|
13864
|
+
types: "./dist/tsup/db/drizzle.d.cts",
|
|
13865
|
+
default: "./dist/tsup/db/drizzle.cjs"
|
|
13866
|
+
}
|
|
13867
|
+
},
|
|
13868
|
+
"./unstable/migrations": {
|
|
13869
|
+
import: {
|
|
13870
|
+
types: "./dist/tsup/unstable/migrations.d.ts",
|
|
13871
|
+
default: "./dist/tsup/unstable/migrations.js"
|
|
13872
|
+
},
|
|
13873
|
+
require: {
|
|
13874
|
+
types: "./dist/tsup/unstable/migrations.d.cts",
|
|
13875
|
+
default: "./dist/tsup/unstable/migrations.cjs"
|
|
13876
|
+
}
|
|
13877
|
+
},
|
|
13878
|
+
"./dynamic": {
|
|
13879
|
+
import: {
|
|
13880
|
+
types: "./dist/tsup/dynamic/mod.d.ts",
|
|
13881
|
+
default: "./dist/tsup/dynamic/mod.js"
|
|
13882
|
+
},
|
|
13883
|
+
require: {
|
|
13884
|
+
types: "./dist/tsup/dynamic/mod.d.cts",
|
|
13885
|
+
default: "./dist/tsup/dynamic/mod.cjs"
|
|
13886
|
+
}
|
|
13887
|
+
},
|
|
13888
|
+
"./client": {
|
|
13889
|
+
import: {
|
|
13890
|
+
browser: {
|
|
13891
|
+
types: "./dist/browser/client.d.ts",
|
|
13892
|
+
default: "./dist/browser/client.js"
|
|
13893
|
+
},
|
|
13894
|
+
types: "./dist/tsup/client/mod.d.ts",
|
|
13895
|
+
default: "./dist/tsup/client/mod.js"
|
|
13896
|
+
},
|
|
13897
|
+
require: {
|
|
13898
|
+
types: "./dist/tsup/client/mod.d.cts",
|
|
13899
|
+
default: "./dist/tsup/client/mod.cjs"
|
|
13900
|
+
}
|
|
13435
13901
|
},
|
|
13436
13902
|
"./log": {
|
|
13437
13903
|
import: {
|
|
@@ -13537,6 +14003,7 @@ var package_default = {
|
|
|
13537
14003
|
dependencies: {
|
|
13538
14004
|
"@hono/zod-openapi": "^1.1.5",
|
|
13539
14005
|
"@rivet-dev/agent-os-core": "^0.1.1",
|
|
14006
|
+
"@rivet-dev/services": "^0.1.5",
|
|
13540
14007
|
"@rivetkit/bare-ts": "^0.6.2",
|
|
13541
14008
|
"@rivetkit/engine-cli": "workspace:*",
|
|
13542
14009
|
"@rivetkit/engine-envoy-protocol": "workspace:*",
|
|
@@ -13547,7 +14014,7 @@ var package_default = {
|
|
|
13547
14014
|
"@rivetkit/virtual-websocket": "workspace:*",
|
|
13548
14015
|
"@rivetkit/workflow-engine": "workspace:*",
|
|
13549
14016
|
"cbor-x": "^1.6.0",
|
|
13550
|
-
"drizzle-orm": "
|
|
14017
|
+
"drizzle-orm": "catalog:",
|
|
13551
14018
|
hono: "^4.7.0",
|
|
13552
14019
|
invariant: "^2.2.4",
|
|
13553
14020
|
"p-retry": "^6.2.1",
|
|
@@ -14630,7 +15097,7 @@ function Config({ initialBufferLength = 1024, maxBufferLength = 1024 * 1024 * 32
|
|
|
14630
15097
|
};
|
|
14631
15098
|
}
|
|
14632
15099
|
|
|
14633
|
-
// ../rivetkit/dist/tsup/chunk-
|
|
15100
|
+
// ../rivetkit/dist/tsup/chunk-XCSZTG4H.js
|
|
14634
15101
|
var config2 = /* @__PURE__ */ Config({});
|
|
14635
15102
|
function readWorkflowCbor(bc) {
|
|
14636
15103
|
return readData(bc);
|
|
@@ -14742,655 +15209,191 @@ function readWorkflowStepEntry(bc) {
|
|
|
14742
15209
|
}
|
|
14743
15210
|
function readWorkflowLoopEntry(bc) {
|
|
14744
15211
|
return {
|
|
14745
|
-
state: readWorkflowCbor(bc),
|
|
14746
|
-
iteration: readU32(bc),
|
|
14747
|
-
output: read0(bc)
|
|
14748
|
-
};
|
|
14749
|
-
}
|
|
14750
|
-
function readWorkflowSleepEntry(bc) {
|
|
14751
|
-
return {
|
|
14752
|
-
deadline: readU64(bc),
|
|
14753
|
-
state: readWorkflowSleepState(bc)
|
|
14754
|
-
};
|
|
14755
|
-
}
|
|
14756
|
-
function readWorkflowMessageEntry(bc) {
|
|
14757
|
-
return {
|
|
14758
|
-
name: readString(bc),
|
|
14759
|
-
messageData: readWorkflowCbor(bc)
|
|
14760
|
-
};
|
|
14761
|
-
}
|
|
14762
|
-
function readWorkflowRollbackCheckpointEntry(bc) {
|
|
14763
|
-
return {
|
|
14764
|
-
name: readString(bc)
|
|
14765
|
-
};
|
|
14766
|
-
}
|
|
14767
|
-
function readWorkflowBranchStatus(bc) {
|
|
14768
|
-
return {
|
|
14769
|
-
status: readWorkflowBranchStatusType(bc),
|
|
14770
|
-
output: read0(bc),
|
|
14771
|
-
error: read1(bc)
|
|
14772
|
-
};
|
|
14773
|
-
}
|
|
14774
|
-
function read2(bc) {
|
|
14775
|
-
const len = readUintSafe(bc);
|
|
14776
|
-
const result = /* @__PURE__ */ new Map();
|
|
14777
|
-
for (let i = 0; i < len; i++) {
|
|
14778
|
-
const offset = bc.offset;
|
|
14779
|
-
const key = readString(bc);
|
|
14780
|
-
if (result.has(key)) {
|
|
14781
|
-
bc.offset = offset;
|
|
14782
|
-
throw new BareError(offset, "duplicated key");
|
|
14783
|
-
}
|
|
14784
|
-
result.set(key, readWorkflowBranchStatus(bc));
|
|
14785
|
-
}
|
|
14786
|
-
return result;
|
|
14787
|
-
}
|
|
14788
|
-
function readWorkflowJoinEntry(bc) {
|
|
14789
|
-
return {
|
|
14790
|
-
branches: read2(bc)
|
|
14791
|
-
};
|
|
14792
|
-
}
|
|
14793
|
-
function readWorkflowRaceEntry(bc) {
|
|
14794
|
-
return {
|
|
14795
|
-
winner: read1(bc),
|
|
14796
|
-
branches: read2(bc)
|
|
14797
|
-
};
|
|
14798
|
-
}
|
|
14799
|
-
function readWorkflowRemovedEntry(bc) {
|
|
14800
|
-
return {
|
|
14801
|
-
originalType: readString(bc),
|
|
14802
|
-
originalName: read1(bc)
|
|
14803
|
-
};
|
|
14804
|
-
}
|
|
14805
|
-
function readWorkflowVersionCheckEntry(bc) {
|
|
14806
|
-
return {
|
|
14807
|
-
resolved: readU32(bc),
|
|
14808
|
-
latest: readU32(bc)
|
|
14809
|
-
};
|
|
14810
|
-
}
|
|
14811
|
-
function readWorkflowEntryKind(bc) {
|
|
14812
|
-
const offset = bc.offset;
|
|
14813
|
-
const tag = readU8(bc);
|
|
14814
|
-
switch (tag) {
|
|
14815
|
-
case 0:
|
|
14816
|
-
return { tag: "WorkflowStepEntry", val: readWorkflowStepEntry(bc) };
|
|
14817
|
-
case 1:
|
|
14818
|
-
return { tag: "WorkflowLoopEntry", val: readWorkflowLoopEntry(bc) };
|
|
14819
|
-
case 2:
|
|
14820
|
-
return {
|
|
14821
|
-
tag: "WorkflowSleepEntry",
|
|
14822
|
-
val: readWorkflowSleepEntry(bc)
|
|
14823
|
-
};
|
|
14824
|
-
case 3:
|
|
14825
|
-
return {
|
|
14826
|
-
tag: "WorkflowMessageEntry",
|
|
14827
|
-
val: readWorkflowMessageEntry(bc)
|
|
14828
|
-
};
|
|
14829
|
-
case 4:
|
|
14830
|
-
return {
|
|
14831
|
-
tag: "WorkflowRollbackCheckpointEntry",
|
|
14832
|
-
val: readWorkflowRollbackCheckpointEntry(bc)
|
|
14833
|
-
};
|
|
14834
|
-
case 5:
|
|
14835
|
-
return { tag: "WorkflowJoinEntry", val: readWorkflowJoinEntry(bc) };
|
|
14836
|
-
case 6:
|
|
14837
|
-
return { tag: "WorkflowRaceEntry", val: readWorkflowRaceEntry(bc) };
|
|
14838
|
-
case 7:
|
|
14839
|
-
return {
|
|
14840
|
-
tag: "WorkflowRemovedEntry",
|
|
14841
|
-
val: readWorkflowRemovedEntry(bc)
|
|
14842
|
-
};
|
|
14843
|
-
case 8:
|
|
14844
|
-
return {
|
|
14845
|
-
tag: "WorkflowVersionCheckEntry",
|
|
14846
|
-
val: readWorkflowVersionCheckEntry(bc)
|
|
14847
|
-
};
|
|
14848
|
-
default: {
|
|
14849
|
-
bc.offset = offset;
|
|
14850
|
-
throw new BareError(offset, "invalid tag");
|
|
14851
|
-
}
|
|
14852
|
-
}
|
|
14853
|
-
}
|
|
14854
|
-
function readWorkflowEntry(bc) {
|
|
14855
|
-
return {
|
|
14856
|
-
id: readString(bc),
|
|
14857
|
-
location: readWorkflowLocation(bc),
|
|
14858
|
-
kind: readWorkflowEntryKind(bc)
|
|
14859
|
-
};
|
|
14860
|
-
}
|
|
14861
|
-
function read3(bc) {
|
|
14862
|
-
return readBool(bc) ? readU64(bc) : null;
|
|
14863
|
-
}
|
|
14864
|
-
function readWorkflowEntryMetadata(bc) {
|
|
14865
|
-
return {
|
|
14866
|
-
status: readWorkflowEntryStatus(bc),
|
|
14867
|
-
error: read1(bc),
|
|
14868
|
-
attempts: readU32(bc),
|
|
14869
|
-
lastAttemptAt: readU64(bc),
|
|
14870
|
-
createdAt: readU64(bc),
|
|
14871
|
-
completedAt: read3(bc),
|
|
14872
|
-
rollbackCompletedAt: read3(bc),
|
|
14873
|
-
rollbackError: read1(bc)
|
|
14874
|
-
};
|
|
14875
|
-
}
|
|
14876
|
-
function read4(bc) {
|
|
14877
|
-
const len = readUintSafe(bc);
|
|
14878
|
-
if (len === 0) {
|
|
14879
|
-
return [];
|
|
14880
|
-
}
|
|
14881
|
-
const result = [readString(bc)];
|
|
14882
|
-
for (let i = 1; i < len; i++) {
|
|
14883
|
-
result[i] = readString(bc);
|
|
14884
|
-
}
|
|
14885
|
-
return result;
|
|
14886
|
-
}
|
|
14887
|
-
function read5(bc) {
|
|
14888
|
-
const len = readUintSafe(bc);
|
|
14889
|
-
if (len === 0) {
|
|
14890
|
-
return [];
|
|
14891
|
-
}
|
|
14892
|
-
const result = [readWorkflowEntry(bc)];
|
|
14893
|
-
for (let i = 1; i < len; i++) {
|
|
14894
|
-
result[i] = readWorkflowEntry(bc);
|
|
14895
|
-
}
|
|
14896
|
-
return result;
|
|
14897
|
-
}
|
|
14898
|
-
function read6(bc) {
|
|
14899
|
-
const len = readUintSafe(bc);
|
|
14900
|
-
const result = /* @__PURE__ */ new Map();
|
|
14901
|
-
for (let i = 0; i < len; i++) {
|
|
14902
|
-
const offset = bc.offset;
|
|
14903
|
-
const key = readString(bc);
|
|
14904
|
-
if (result.has(key)) {
|
|
14905
|
-
bc.offset = offset;
|
|
14906
|
-
throw new BareError(offset, "duplicated key");
|
|
14907
|
-
}
|
|
14908
|
-
result.set(key, readWorkflowEntryMetadata(bc));
|
|
14909
|
-
}
|
|
14910
|
-
return result;
|
|
14911
|
-
}
|
|
14912
|
-
function readWorkflowHistory(bc) {
|
|
14913
|
-
return {
|
|
14914
|
-
nameRegistry: read4(bc),
|
|
14915
|
-
entries: read5(bc),
|
|
14916
|
-
entryMetadata: read6(bc)
|
|
14917
|
-
};
|
|
14918
|
-
}
|
|
14919
|
-
function decodeWorkflowHistory(bytes) {
|
|
14920
|
-
const bc = new ByteCursor(bytes, config2);
|
|
14921
|
-
const result = readWorkflowHistory(bc);
|
|
14922
|
-
if (bc.offset < bc.view.byteLength) {
|
|
14923
|
-
throw new BareError(bc.offset, "remaining bytes");
|
|
14924
|
-
}
|
|
14925
|
-
return result;
|
|
14926
|
-
}
|
|
14927
|
-
function decodeWorkflowHistoryTransport(data) {
|
|
14928
|
-
return decodeWorkflowHistory(toUint8Array(data));
|
|
14929
|
-
}
|
|
14930
|
-
|
|
14931
|
-
// ../rivetkit/dist/tsup/chunk-6W5VGLFT.js
|
|
14932
|
-
function flattenActionHandlers(actions) {
|
|
14933
|
-
const flattened = /* @__PURE__ */ Object.create(null);
|
|
14934
|
-
for (const { name, handler } of collectActionEntries(actions)) {
|
|
14935
|
-
flattened[name] = handler;
|
|
14936
|
-
}
|
|
14937
|
-
return flattened;
|
|
14938
|
-
}
|
|
14939
|
-
function flattenActionInputSchemas(actions, schemas) {
|
|
14940
|
-
if (schemas === void 0) return void 0;
|
|
14941
|
-
if (!isRecord(schemas)) {
|
|
14942
|
-
throw new TypeError("actionInputSchemas must be an object");
|
|
14943
|
-
}
|
|
14944
|
-
const flattened = /* @__PURE__ */ Object.create(null);
|
|
14945
|
-
for (const { name, path: path2 } of collectActionEntries(actions)) {
|
|
14946
|
-
const nestedSchema = lookupNestedSchema(schemas, path2);
|
|
14947
|
-
const flatSchema = schemas[name];
|
|
14948
|
-
if (nestedSchema !== void 0 && flatSchema !== void 0 && nestedSchema !== flatSchema) {
|
|
14949
|
-
throw new TypeError(
|
|
14950
|
-
`Action input schema \`${name}\` is defined by both a nested path and a dotted key`
|
|
14951
|
-
);
|
|
14952
|
-
}
|
|
14953
|
-
const schema = nestedSchema ?? flatSchema;
|
|
14954
|
-
if (schema !== void 0) {
|
|
14955
|
-
flattened[name] = schema;
|
|
14956
|
-
}
|
|
14957
|
-
}
|
|
14958
|
-
return flattened;
|
|
14959
|
-
}
|
|
14960
|
-
function collectActionEntries(actions) {
|
|
14961
|
-
const entries = [];
|
|
14962
|
-
const names = /* @__PURE__ */ new Set();
|
|
14963
|
-
visitActionGroup(actions ?? {}, [], entries, names);
|
|
14964
|
-
return entries;
|
|
14965
|
-
}
|
|
14966
|
-
function visitActionGroup(value, path2, entries, names) {
|
|
14967
|
-
if (!isRecord(value)) {
|
|
14968
|
-
throw new TypeError(
|
|
14969
|
-
`${formatActionPath(path2)} must be an action handler or group`
|
|
14970
|
-
);
|
|
14971
|
-
}
|
|
14972
|
-
for (const [segment, child] of Object.entries(value)) {
|
|
14973
|
-
const childPath = [...path2, segment];
|
|
14974
|
-
if (typeof child === "function") {
|
|
14975
|
-
const name = childPath.join(".");
|
|
14976
|
-
if (names.has(name)) {
|
|
14977
|
-
throw new TypeError(
|
|
14978
|
-
`Multiple action definitions flatten to \`${name}\``
|
|
14979
|
-
);
|
|
14980
|
-
}
|
|
14981
|
-
names.add(name);
|
|
14982
|
-
entries.push({
|
|
14983
|
-
name,
|
|
14984
|
-
path: childPath,
|
|
14985
|
-
handler: child
|
|
14986
|
-
});
|
|
14987
|
-
} else {
|
|
14988
|
-
visitActionGroup(child, childPath, entries, names);
|
|
14989
|
-
}
|
|
14990
|
-
}
|
|
15212
|
+
state: readWorkflowCbor(bc),
|
|
15213
|
+
iteration: readU32(bc),
|
|
15214
|
+
output: read0(bc)
|
|
15215
|
+
};
|
|
14991
15216
|
}
|
|
14992
|
-
function
|
|
14993
|
-
|
|
14994
|
-
|
|
14995
|
-
|
|
14996
|
-
|
|
14997
|
-
}
|
|
14998
|
-
value = value[segment];
|
|
14999
|
-
}
|
|
15000
|
-
return value;
|
|
15217
|
+
function readWorkflowSleepEntry(bc) {
|
|
15218
|
+
return {
|
|
15219
|
+
deadline: readU64(bc),
|
|
15220
|
+
state: readWorkflowSleepState(bc)
|
|
15221
|
+
};
|
|
15001
15222
|
}
|
|
15002
|
-
function
|
|
15003
|
-
|
|
15004
|
-
|
|
15005
|
-
|
|
15006
|
-
|
|
15007
|
-
return prototype === Object.prototype || prototype === null;
|
|
15223
|
+
function readWorkflowMessageEntry(bc) {
|
|
15224
|
+
return {
|
|
15225
|
+
name: readString(bc),
|
|
15226
|
+
messageData: readWorkflowCbor(bc)
|
|
15227
|
+
};
|
|
15008
15228
|
}
|
|
15009
|
-
function
|
|
15010
|
-
return
|
|
15229
|
+
function readWorkflowRollbackCheckpointEntry(bc) {
|
|
15230
|
+
return {
|
|
15231
|
+
name: readString(bc)
|
|
15232
|
+
};
|
|
15011
15233
|
}
|
|
15012
|
-
|
|
15013
|
-
|
|
15014
|
-
|
|
15015
|
-
)
|
|
15016
|
-
|
|
15017
|
-
|
|
15018
|
-
|
|
15019
|
-
|
|
15020
|
-
|
|
15021
|
-
|
|
15022
|
-
|
|
15023
|
-
|
|
15024
|
-
|
|
15025
|
-
|
|
15026
|
-
|
|
15027
|
-
|
|
15028
|
-
} catch (error46) {
|
|
15029
|
-
ctx.addIssue({
|
|
15030
|
-
code: "custom",
|
|
15031
|
-
message: error46 instanceof Error ? error46.message : "Invalid action definition"
|
|
15032
|
-
});
|
|
15033
|
-
}
|
|
15034
|
-
});
|
|
15035
|
-
var WorkflowInspectorConfigSchema = external_exports.object({
|
|
15036
|
-
getHistory: zFunction(),
|
|
15037
|
-
getState: zFunction().optional(),
|
|
15038
|
-
onHistoryUpdated: zFunction().optional(),
|
|
15039
|
-
replayFromStep: zFunction().optional()
|
|
15040
|
-
});
|
|
15041
|
-
var RunInspectorConfigSchema = external_exports.object({
|
|
15042
|
-
workflow: WorkflowInspectorConfigSchema.optional()
|
|
15043
|
-
}).optional();
|
|
15044
|
-
var BUILTIN_INSPECTOR_TAB_IDS = [
|
|
15045
|
-
"workflow",
|
|
15046
|
-
"database",
|
|
15047
|
-
"state",
|
|
15048
|
-
"queue",
|
|
15049
|
-
"schedules",
|
|
15050
|
-
"connections",
|
|
15051
|
-
"console"
|
|
15052
|
-
];
|
|
15053
|
-
var BuiltinInspectorTabIdSchema = external_exports.enum(BUILTIN_INSPECTOR_TAB_IDS);
|
|
15054
|
-
var CUSTOM_INSPECTOR_TAB_ID_RE = /^[A-Za-z0-9_-]+$/;
|
|
15055
|
-
var CustomInspectorTabEntrySchema = external_exports.object({
|
|
15056
|
-
id: external_exports.string().regex(
|
|
15057
|
-
CUSTOM_INSPECTOR_TAB_ID_RE,
|
|
15058
|
-
"inspector.tabs[].id must contain only letters, digits, underscore, or dash"
|
|
15059
|
-
),
|
|
15060
|
-
label: external_exports.string().min(1),
|
|
15061
|
-
source: external_exports.string().min(1),
|
|
15062
|
-
/**
|
|
15063
|
-
* Optional icon id. The dashboard maps strings to glyphs (see its
|
|
15064
|
-
* icon registry); unknown ids fall back to a generic icon.
|
|
15065
|
-
*/
|
|
15066
|
-
icon: external_exports.string().min(1).optional(),
|
|
15067
|
-
hidden: external_exports.literal(false).optional()
|
|
15068
|
-
}).strict();
|
|
15069
|
-
var HideInspectorTabEntrySchema = external_exports.object({
|
|
15070
|
-
id: BuiltinInspectorTabIdSchema,
|
|
15071
|
-
hidden: external_exports.literal(true)
|
|
15072
|
-
}).strict();
|
|
15073
|
-
var InspectorTabEntrySchema = external_exports.union([
|
|
15074
|
-
CustomInspectorTabEntrySchema,
|
|
15075
|
-
HideInspectorTabEntrySchema
|
|
15076
|
-
]);
|
|
15077
|
-
var ActorInspectorConfigSchema = external_exports.object({
|
|
15078
|
-
tabs: external_exports.array(InspectorTabEntrySchema).default(() => [])
|
|
15079
|
-
}).strict().refine(
|
|
15080
|
-
(data) => {
|
|
15081
|
-
const ids = data.tabs.map((t) => t.id);
|
|
15082
|
-
return new Set(ids).size === ids.length;
|
|
15083
|
-
},
|
|
15084
|
-
{ message: "Duplicate id in inspector.tabs", path: ["tabs"] }
|
|
15085
|
-
).refine(
|
|
15086
|
-
(data) => {
|
|
15087
|
-
const builtinSet = new Set(BUILTIN_INSPECTOR_TAB_IDS);
|
|
15088
|
-
return data.tabs.every(
|
|
15089
|
-
(t) => t.hidden === true || !builtinSet.has(t.id)
|
|
15090
|
-
);
|
|
15091
|
-
},
|
|
15092
|
-
{
|
|
15093
|
-
message: "Custom inspector tab id collides with a built-in (use hidden: true to hide a built-in)",
|
|
15094
|
-
path: ["tabs"]
|
|
15095
|
-
}
|
|
15096
|
-
);
|
|
15097
|
-
var RunConfigSchema = external_exports.object({
|
|
15098
|
-
/** Display name for the actor in the Inspector UI. */
|
|
15099
|
-
name: external_exports.string().optional(),
|
|
15100
|
-
/** Icon for the actor in the Inspector UI. Can be an emoji or FontAwesome icon name. */
|
|
15101
|
-
icon: external_exports.string().optional(),
|
|
15102
|
-
/** The run handler function. */
|
|
15103
|
-
run: zFunction(),
|
|
15104
|
-
/** Inspector integration for long-running run handlers. */
|
|
15105
|
-
inspector: RunInspectorConfigSchema.optional()
|
|
15106
|
-
});
|
|
15107
|
-
var RUN_FUNCTION_CONFIG_SYMBOL = /* @__PURE__ */ Symbol.for("rivetkit.run_function_config");
|
|
15108
|
-
function defineRunHandler(run, options) {
|
|
15109
|
-
if (options.inspectorKind === void 0 !== (options.createInspector === void 0)) {
|
|
15110
|
-
throw new TypeError(
|
|
15111
|
-
"defineRunHandler requires inspectorKind and createInspector together"
|
|
15112
|
-
);
|
|
15113
|
-
}
|
|
15114
|
-
Object.defineProperty(run, RUN_FUNCTION_CONFIG_SYMBOL, {
|
|
15115
|
-
configurable: false,
|
|
15116
|
-
enumerable: false,
|
|
15117
|
-
writable: false,
|
|
15118
|
-
value: {
|
|
15119
|
-
name: options.name,
|
|
15120
|
-
icon: options.icon,
|
|
15121
|
-
inspectorKind: options.inspectorKind,
|
|
15122
|
-
createInspector: options.createInspector
|
|
15234
|
+
function readWorkflowBranchStatus(bc) {
|
|
15235
|
+
return {
|
|
15236
|
+
status: readWorkflowBranchStatusType(bc),
|
|
15237
|
+
output: read0(bc),
|
|
15238
|
+
error: read1(bc)
|
|
15239
|
+
};
|
|
15240
|
+
}
|
|
15241
|
+
function read2(bc) {
|
|
15242
|
+
const len = readUintSafe(bc);
|
|
15243
|
+
const result = /* @__PURE__ */ new Map();
|
|
15244
|
+
for (let i = 0; i < len; i++) {
|
|
15245
|
+
const offset = bc.offset;
|
|
15246
|
+
const key = readString(bc);
|
|
15247
|
+
if (result.has(key)) {
|
|
15248
|
+
bc.offset = offset;
|
|
15249
|
+
throw new BareError(offset, "duplicated key");
|
|
15123
15250
|
}
|
|
15124
|
-
|
|
15125
|
-
|
|
15251
|
+
result.set(key, readWorkflowBranchStatus(bc));
|
|
15252
|
+
}
|
|
15253
|
+
return result;
|
|
15126
15254
|
}
|
|
15127
|
-
function
|
|
15128
|
-
|
|
15129
|
-
|
|
15130
|
-
|
|
15255
|
+
function readWorkflowJoinEntry(bc) {
|
|
15256
|
+
return {
|
|
15257
|
+
branches: read2(bc)
|
|
15258
|
+
};
|
|
15131
15259
|
}
|
|
15132
|
-
function
|
|
15133
|
-
|
|
15134
|
-
|
|
15135
|
-
|
|
15260
|
+
function readWorkflowRaceEntry(bc) {
|
|
15261
|
+
return {
|
|
15262
|
+
winner: read1(bc),
|
|
15263
|
+
branches: read2(bc)
|
|
15264
|
+
};
|
|
15136
15265
|
}
|
|
15137
|
-
|
|
15138
|
-
|
|
15139
|
-
|
|
15140
|
-
|
|
15141
|
-
|
|
15266
|
+
function readWorkflowRemovedEntry(bc) {
|
|
15267
|
+
return {
|
|
15268
|
+
originalType: readString(bc),
|
|
15269
|
+
originalName: read1(bc)
|
|
15270
|
+
};
|
|
15142
15271
|
}
|
|
15143
|
-
function
|
|
15144
|
-
|
|
15145
|
-
|
|
15146
|
-
|
|
15147
|
-
|
|
15148
|
-
return { name: config3.name, icon: config3.icon };
|
|
15149
|
-
}
|
|
15150
|
-
return { name: run.name, icon: run.icon };
|
|
15272
|
+
function readWorkflowVersionCheckEntry(bc) {
|
|
15273
|
+
return {
|
|
15274
|
+
resolved: readU32(bc),
|
|
15275
|
+
latest: readU32(bc)
|
|
15276
|
+
};
|
|
15151
15277
|
}
|
|
15152
|
-
function
|
|
15153
|
-
|
|
15154
|
-
|
|
15155
|
-
|
|
15156
|
-
|
|
15278
|
+
function readWorkflowEntryKind(bc) {
|
|
15279
|
+
const offset = bc.offset;
|
|
15280
|
+
const tag = readU8(bc);
|
|
15281
|
+
switch (tag) {
|
|
15282
|
+
case 0:
|
|
15283
|
+
return { tag: "WorkflowStepEntry", val: readWorkflowStepEntry(bc) };
|
|
15284
|
+
case 1:
|
|
15285
|
+
return { tag: "WorkflowLoopEntry", val: readWorkflowLoopEntry(bc) };
|
|
15286
|
+
case 2:
|
|
15287
|
+
return {
|
|
15288
|
+
tag: "WorkflowSleepEntry",
|
|
15289
|
+
val: readWorkflowSleepEntry(bc)
|
|
15290
|
+
};
|
|
15291
|
+
case 3:
|
|
15292
|
+
return {
|
|
15293
|
+
tag: "WorkflowMessageEntry",
|
|
15294
|
+
val: readWorkflowMessageEntry(bc)
|
|
15295
|
+
};
|
|
15296
|
+
case 4:
|
|
15297
|
+
return {
|
|
15298
|
+
tag: "WorkflowRollbackCheckpointEntry",
|
|
15299
|
+
val: readWorkflowRollbackCheckpointEntry(bc)
|
|
15300
|
+
};
|
|
15301
|
+
case 5:
|
|
15302
|
+
return { tag: "WorkflowJoinEntry", val: readWorkflowJoinEntry(bc) };
|
|
15303
|
+
case 6:
|
|
15304
|
+
return { tag: "WorkflowRaceEntry", val: readWorkflowRaceEntry(bc) };
|
|
15305
|
+
case 7:
|
|
15306
|
+
return {
|
|
15307
|
+
tag: "WorkflowRemovedEntry",
|
|
15308
|
+
val: readWorkflowRemovedEntry(bc)
|
|
15309
|
+
};
|
|
15310
|
+
case 8:
|
|
15311
|
+
return {
|
|
15312
|
+
tag: "WorkflowVersionCheckEntry",
|
|
15313
|
+
val: readWorkflowVersionCheckEntry(bc)
|
|
15314
|
+
};
|
|
15315
|
+
default: {
|
|
15316
|
+
bc.offset = offset;
|
|
15317
|
+
throw new BareError(offset, "invalid tag");
|
|
15318
|
+
}
|
|
15157
15319
|
}
|
|
15158
|
-
return run.inspector;
|
|
15159
15320
|
}
|
|
15160
|
-
function
|
|
15161
|
-
|
|
15162
|
-
|
|
15163
|
-
|
|
15164
|
-
|
|
15321
|
+
function readWorkflowEntry(bc) {
|
|
15322
|
+
return {
|
|
15323
|
+
id: readString(bc),
|
|
15324
|
+
location: readWorkflowLocation(bc),
|
|
15325
|
+
kind: readWorkflowEntryKind(bc)
|
|
15326
|
+
};
|
|
15327
|
+
}
|
|
15328
|
+
function read3(bc) {
|
|
15329
|
+
return readBool(bc) ? readU64(bc) : null;
|
|
15165
15330
|
}
|
|
15166
|
-
function
|
|
15167
|
-
|
|
15168
|
-
|
|
15169
|
-
|
|
15170
|
-
|
|
15171
|
-
|
|
15172
|
-
|
|
15331
|
+
function readWorkflowEntryMetadata(bc) {
|
|
15332
|
+
return {
|
|
15333
|
+
status: readWorkflowEntryStatus(bc),
|
|
15334
|
+
error: read1(bc),
|
|
15335
|
+
attempts: readU32(bc),
|
|
15336
|
+
lastAttemptAt: readU64(bc),
|
|
15337
|
+
createdAt: readU64(bc),
|
|
15338
|
+
completedAt: read3(bc),
|
|
15339
|
+
rollbackCompletedAt: read3(bc),
|
|
15340
|
+
rollbackError: read1(bc)
|
|
15341
|
+
};
|
|
15173
15342
|
}
|
|
15174
|
-
|
|
15175
|
-
|
|
15176
|
-
|
|
15177
|
-
|
|
15178
|
-
icon: external_exports.string().optional(),
|
|
15179
|
-
/** Enables the experimental Actor Runtime Socket for this actor. */
|
|
15180
|
-
enableActorRuntimeSocket: external_exports.boolean().default(false),
|
|
15181
|
-
/**
|
|
15182
|
-
* Can hibernate WebSockets for onWebSocket.
|
|
15183
|
-
*
|
|
15184
|
-
* WebSockets using actions/events are hibernatable by default.
|
|
15185
|
-
*
|
|
15186
|
-
* @experimental
|
|
15187
|
-
**/
|
|
15188
|
-
canHibernateWebSocket: external_exports.union([external_exports.boolean(), zFunction()]).default(false)
|
|
15189
|
-
}).strict();
|
|
15190
|
-
var GlobalActorOptionsSchema = GlobalActorOptionsBaseSchema.prefault(
|
|
15191
|
-
() => ({})
|
|
15192
|
-
);
|
|
15193
|
-
var InstanceActorOptionsBaseSchema = external_exports.object({
|
|
15194
|
-
createVarsTimeout: external_exports.number().positive().default(5e3),
|
|
15195
|
-
createConnStateTimeout: external_exports.number().positive().default(5e3),
|
|
15196
|
-
onBeforeConnectTimeout: external_exports.number().positive().default(5e3),
|
|
15197
|
-
onConnectTimeout: external_exports.number().positive().default(5e3),
|
|
15198
|
-
onMigrateTimeout: external_exports.number().positive().default(3e4),
|
|
15199
|
-
sleepGracePeriod: external_exports.number().positive().default(DEFAULT_SLEEP_GRACE_PERIOD),
|
|
15200
|
-
/** @deprecated `onDestroyTimeout` is folded into `sleepGracePeriod`, which now bounds the entire graceful shutdown window for both sleep and destroy. Will be removed in 2.2.0. */
|
|
15201
|
-
onDestroyTimeout: external_exports.number().positive().optional(),
|
|
15202
|
-
/** @deprecated `waitUntilTimeout` is folded into `sleepGracePeriod`, which now bounds the entire graceful shutdown window for both sleep and destroy. Will be removed in 2.2.0. */
|
|
15203
|
-
waitUntilTimeout: external_exports.number().positive().optional(),
|
|
15204
|
-
stateSaveInterval: external_exports.number().positive().default(1e3),
|
|
15205
|
-
actionTimeout: external_exports.number().positive().default(6e4),
|
|
15206
|
-
connectionLivenessTimeout: external_exports.number().positive().default(2500),
|
|
15207
|
-
connectionLivenessInterval: external_exports.number().positive().default(5e3),
|
|
15208
|
-
/** @deprecated Use `c.keepAwake(promise)` to scope keep-awake to a specific operation, or keep `noSleep` for actors that must stay awake indefinitely. Will be removed in 2.2.0. */
|
|
15209
|
-
noSleep: external_exports.boolean().default(false),
|
|
15210
|
-
sleepTimeout: external_exports.number().positive().default(3e4),
|
|
15211
|
-
maxQueueSize: external_exports.number().positive().default(1e3),
|
|
15212
|
-
/** Maximum pending one-shot and recurring schedules. */
|
|
15213
|
-
maxSchedules: external_exports.number().int().nonnegative().default(1e3),
|
|
15214
|
-
maxQueueMessageSize: external_exports.number().positive().default(64 * 1024),
|
|
15215
|
-
/** @deprecated Internal storage moved to SQLite and no longer uses KV preloading, so this option is ignored. Will be removed in 2.2.0. */
|
|
15216
|
-
preloadMaxWorkflowBytes: external_exports.number().nonnegative().optional(),
|
|
15217
|
-
/** @deprecated Internal storage moved to SQLite and no longer uses KV preloading, so this option is ignored. Will be removed in 2.2.0. */
|
|
15218
|
-
preloadMaxConnectionsBytes: external_exports.number().nonnegative().optional()
|
|
15219
|
-
}).strict();
|
|
15220
|
-
var InstanceActorOptionsSchema = InstanceActorOptionsBaseSchema.prefault(() => ({}));
|
|
15221
|
-
var ActorOptionsSchema = GlobalActorOptionsBaseSchema.extend(
|
|
15222
|
-
InstanceActorOptionsBaseSchema.shape
|
|
15223
|
-
).strict().prefault(() => ({}));
|
|
15224
|
-
var ActorConfigSchema = external_exports.object({
|
|
15225
|
-
onCreate: zFunction().optional(),
|
|
15226
|
-
onDestroy: zFunction().optional(),
|
|
15227
|
-
onMigrate: zFunction().optional(),
|
|
15228
|
-
onWake: zFunction().optional(),
|
|
15229
|
-
onSleep: zFunction().optional(),
|
|
15230
|
-
run: zRunHandler,
|
|
15231
|
-
onStateChange: zFunction().optional(),
|
|
15232
|
-
onBeforeConnect: zFunction().optional(),
|
|
15233
|
-
onConnect: zFunction().optional(),
|
|
15234
|
-
onDisconnect: zFunction().optional(),
|
|
15235
|
-
onBeforeActionResponse: zFunction().optional(),
|
|
15236
|
-
onRequest: zFunction().optional(),
|
|
15237
|
-
onWebSocket: zFunction().optional(),
|
|
15238
|
-
actions: zActionTree.default(() => ({})),
|
|
15239
|
-
actionInputSchemas: external_exports.record(external_exports.string(), external_exports.any()).optional(),
|
|
15240
|
-
connParamsSchema: external_exports.any().optional(),
|
|
15241
|
-
events: external_exports.record(external_exports.string(), external_exports.any()).optional(),
|
|
15242
|
-
queues: external_exports.record(external_exports.string(), external_exports.any()).optional(),
|
|
15243
|
-
state: external_exports.any().optional(),
|
|
15244
|
-
createState: zFunction().optional(),
|
|
15245
|
-
connState: external_exports.any().optional(),
|
|
15246
|
-
createConnState: zFunction().optional(),
|
|
15247
|
-
vars: external_exports.any().optional(),
|
|
15248
|
-
db: external_exports.any().optional(),
|
|
15249
|
-
createVars: zFunction().optional(),
|
|
15250
|
-
options: ActorOptionsSchema,
|
|
15251
|
-
inspector: ActorInspectorConfigSchema.optional()
|
|
15252
|
-
}).strict().refine(
|
|
15253
|
-
(data) => !(data.state !== void 0 && data.createState !== void 0),
|
|
15254
|
-
{
|
|
15255
|
-
message: "Cannot define both 'state' and 'createState'",
|
|
15256
|
-
path: ["state"]
|
|
15257
|
-
}
|
|
15258
|
-
).refine(
|
|
15259
|
-
(data) => !(data.connState !== void 0 && data.createConnState !== void 0),
|
|
15260
|
-
{
|
|
15261
|
-
message: "Cannot define both 'connState' and 'createConnState'",
|
|
15262
|
-
path: ["connState"]
|
|
15343
|
+
function read4(bc) {
|
|
15344
|
+
const len = readUintSafe(bc);
|
|
15345
|
+
if (len === 0) {
|
|
15346
|
+
return [];
|
|
15263
15347
|
}
|
|
15264
|
-
)
|
|
15265
|
-
|
|
15266
|
-
|
|
15267
|
-
message: "Cannot define both 'vars' and 'createVars'",
|
|
15268
|
-
path: ["vars"]
|
|
15348
|
+
const result = [readString(bc)];
|
|
15349
|
+
for (let i = 1; i < len; i++) {
|
|
15350
|
+
result[i] = readString(bc);
|
|
15269
15351
|
}
|
|
15270
|
-
|
|
15271
|
-
|
|
15272
|
-
|
|
15273
|
-
|
|
15274
|
-
|
|
15275
|
-
|
|
15276
|
-
|
|
15277
|
-
|
|
15278
|
-
)
|
|
15279
|
-
|
|
15280
|
-
|
|
15281
|
-
|
|
15282
|
-
|
|
15283
|
-
|
|
15284
|
-
|
|
15285
|
-
|
|
15286
|
-
)
|
|
15287
|
-
|
|
15288
|
-
|
|
15289
|
-
|
|
15290
|
-
|
|
15291
|
-
|
|
15292
|
-
|
|
15293
|
-
|
|
15294
|
-
|
|
15295
|
-
|
|
15296
|
-
|
|
15297
|
-
|
|
15298
|
-
|
|
15299
|
-
|
|
15300
|
-
|
|
15301
|
-
|
|
15302
|
-
|
|
15303
|
-
|
|
15304
|
-
|
|
15305
|
-
|
|
15306
|
-
)
|
|
15307
|
-
|
|
15308
|
-
|
|
15309
|
-
|
|
15310
|
-
|
|
15311
|
-
|
|
15312
|
-
|
|
15313
|
-
|
|
15314
|
-
|
|
15315
|
-
),
|
|
15316
|
-
maxSchedules: external_exports.number().int().nonnegative().optional().describe(
|
|
15317
|
-
"Maximum pending one-shot and recurring schedules before rejecting new schedules. Default: 1000"
|
|
15318
|
-
),
|
|
15319
|
-
maxQueueMessageSize: external_exports.number().optional().describe(
|
|
15320
|
-
"Maximum size of each queue message in bytes. Default: 65536"
|
|
15321
|
-
),
|
|
15322
|
-
canHibernateWebSocket: external_exports.boolean().optional().describe(
|
|
15323
|
-
"Whether WebSockets using onWebSocket can be hibernated. WebSockets using actions/events are hibernatable by default. Default: false"
|
|
15324
|
-
)
|
|
15325
|
-
}).describe("Actor options for timeouts and behavior configuration.");
|
|
15326
|
-
var DocActorConfigSchema = external_exports.object({
|
|
15327
|
-
state: external_exports.unknown().optional().describe(
|
|
15328
|
-
"Initial state value for the actor. Cannot be used with createState."
|
|
15329
|
-
),
|
|
15330
|
-
createState: external_exports.unknown().optional().describe(
|
|
15331
|
-
"Function to create initial state. Receives context and input. Cannot be used with state."
|
|
15332
|
-
),
|
|
15333
|
-
connState: external_exports.unknown().optional().describe(
|
|
15334
|
-
"Initial connection state value. Cannot be used with createConnState."
|
|
15335
|
-
),
|
|
15336
|
-
createConnState: external_exports.unknown().optional().describe(
|
|
15337
|
-
"Function to create connection state. Receives context and connection params. The pending connection is not visible in c.conns until this succeeds. Cannot be used with connState."
|
|
15338
|
-
),
|
|
15339
|
-
vars: external_exports.unknown().optional().describe(
|
|
15340
|
-
"Initial ephemeral variables value. Cannot be used with createVars."
|
|
15341
|
-
),
|
|
15342
|
-
createVars: external_exports.unknown().optional().describe(
|
|
15343
|
-
"Function to create ephemeral variables. Receives context and driver context. Cannot be used with vars."
|
|
15344
|
-
),
|
|
15345
|
-
db: external_exports.unknown().optional().describe("Database provider instance for the actor."),
|
|
15346
|
-
onCreate: external_exports.unknown().optional().describe(
|
|
15347
|
-
"Called when the actor is first initialized. Use to initialize state."
|
|
15348
|
-
),
|
|
15349
|
-
onDestroy: external_exports.unknown().optional().describe("Called when the actor is destroyed."),
|
|
15350
|
-
onMigrate: external_exports.unknown().optional().describe(
|
|
15351
|
-
"Called on every actor start after persisted state loads and before onWake. Use for repeatable schema migrations."
|
|
15352
|
-
),
|
|
15353
|
-
onWake: external_exports.unknown().optional().describe(
|
|
15354
|
-
"Called when the actor wakes up and is ready to receive connections and actions."
|
|
15355
|
-
),
|
|
15356
|
-
onSleep: external_exports.unknown().optional().describe(
|
|
15357
|
-
"Called when the actor is stopping or sleeping. Use to clean up resources."
|
|
15358
|
-
),
|
|
15359
|
-
run: external_exports.unknown().optional().describe(
|
|
15360
|
-
"Called after actor starts. Does not block startup. Use for background tasks like queue processing or tick loops. If it exits, the actor follows the normal idle sleep timeout once idle. If it throws, the actor logs the error and then follows the normal idle sleep timeout once idle."
|
|
15361
|
-
),
|
|
15362
|
-
onStateChange: external_exports.unknown().optional().describe(
|
|
15363
|
-
"Called when the actor's state changes. State changes within this hook won't trigger recursion."
|
|
15364
|
-
),
|
|
15365
|
-
onBeforeConnect: external_exports.unknown().optional().describe(
|
|
15366
|
-
"Called before a client connects. Throw an error to reject the connection. The pending connection is not visible in c.conns while this runs."
|
|
15367
|
-
),
|
|
15368
|
-
onConnect: external_exports.unknown().optional().describe(
|
|
15369
|
-
"Called when a client successfully connects. The connection is visible in c.conns before this runs."
|
|
15370
|
-
),
|
|
15371
|
-
onDisconnect: external_exports.unknown().optional().describe("Called when a client disconnects."),
|
|
15372
|
-
onBeforeActionResponse: external_exports.unknown().optional().describe(
|
|
15373
|
-
"Called before sending an action response. Use to transform output."
|
|
15374
|
-
),
|
|
15375
|
-
onRequest: external_exports.unknown().optional().describe(
|
|
15376
|
-
"Called for raw HTTP requests to /actors/{name}/http/* endpoints."
|
|
15377
|
-
),
|
|
15378
|
-
onWebSocket: external_exports.unknown().optional().describe(
|
|
15379
|
-
"Called for raw WebSocket connections to /actors/{name}/websocket/* endpoints."
|
|
15380
|
-
),
|
|
15381
|
-
actions: external_exports.record(external_exports.string(), external_exports.unknown()).optional().describe(
|
|
15382
|
-
"Tree of action names or nested groups to handler functions. Nested paths use dot-separated low-level action names. Defaults to an empty object."
|
|
15383
|
-
),
|
|
15384
|
-
actionInputSchemas: external_exports.record(external_exports.string(), external_exports.unknown()).optional().describe(
|
|
15385
|
-
"Optional schemas for validating action argument tuples in native runtimes. May mirror nested action groups or use dot-separated low-level action names."
|
|
15386
|
-
),
|
|
15387
|
-
connParamsSchema: external_exports.unknown().optional().describe(
|
|
15388
|
-
"Optional schema for validating connection params in native runtimes."
|
|
15389
|
-
),
|
|
15390
|
-
events: external_exports.record(external_exports.string(), external_exports.unknown()).optional().describe("Map of event names to schemas."),
|
|
15391
|
-
queues: external_exports.record(external_exports.string(), external_exports.unknown()).optional().describe("Map of queue names to schemas."),
|
|
15392
|
-
options: DocActorOptionsSchema.optional()
|
|
15393
|
-
}).describe("Actor configuration passed to the actor() function.");
|
|
15352
|
+
return result;
|
|
15353
|
+
}
|
|
15354
|
+
function read5(bc) {
|
|
15355
|
+
const len = readUintSafe(bc);
|
|
15356
|
+
if (len === 0) {
|
|
15357
|
+
return [];
|
|
15358
|
+
}
|
|
15359
|
+
const result = [readWorkflowEntry(bc)];
|
|
15360
|
+
for (let i = 1; i < len; i++) {
|
|
15361
|
+
result[i] = readWorkflowEntry(bc);
|
|
15362
|
+
}
|
|
15363
|
+
return result;
|
|
15364
|
+
}
|
|
15365
|
+
function read6(bc) {
|
|
15366
|
+
const len = readUintSafe(bc);
|
|
15367
|
+
const result = /* @__PURE__ */ new Map();
|
|
15368
|
+
for (let i = 0; i < len; i++) {
|
|
15369
|
+
const offset = bc.offset;
|
|
15370
|
+
const key = readString(bc);
|
|
15371
|
+
if (result.has(key)) {
|
|
15372
|
+
bc.offset = offset;
|
|
15373
|
+
throw new BareError(offset, "duplicated key");
|
|
15374
|
+
}
|
|
15375
|
+
result.set(key, readWorkflowEntryMetadata(bc));
|
|
15376
|
+
}
|
|
15377
|
+
return result;
|
|
15378
|
+
}
|
|
15379
|
+
function readWorkflowHistory(bc) {
|
|
15380
|
+
return {
|
|
15381
|
+
nameRegistry: read4(bc),
|
|
15382
|
+
entries: read5(bc),
|
|
15383
|
+
entryMetadata: read6(bc)
|
|
15384
|
+
};
|
|
15385
|
+
}
|
|
15386
|
+
function decodeWorkflowHistory(bytes) {
|
|
15387
|
+
const bc = new ByteCursor(bytes, config2);
|
|
15388
|
+
const result = readWorkflowHistory(bc);
|
|
15389
|
+
if (bc.offset < bc.view.byteLength) {
|
|
15390
|
+
throw new BareError(bc.offset, "remaining bytes");
|
|
15391
|
+
}
|
|
15392
|
+
return result;
|
|
15393
|
+
}
|
|
15394
|
+
function decodeWorkflowHistoryTransport(data) {
|
|
15395
|
+
return decodeWorkflowHistory(toUint8Array(data));
|
|
15396
|
+
}
|
|
15394
15397
|
|
|
15395
15398
|
// ../rivetkit/dist/tsup/chunk-JI6GZ2C2.js
|
|
15396
15399
|
var EMPTY_KEY = "/";
|
|
@@ -15509,7 +15512,7 @@ function removePrefixFromKey(prefixedKey) {
|
|
|
15509
15512
|
return prefixedKey.slice(KEYS.KV.length);
|
|
15510
15513
|
}
|
|
15511
15514
|
|
|
15512
|
-
// ../rivetkit/dist/tsup/chunk-
|
|
15515
|
+
// ../rivetkit/dist/tsup/chunk-XKVQ3AMZ.js
|
|
15513
15516
|
function logger() {
|
|
15514
15517
|
return getLogger("actor-client");
|
|
15515
15518
|
}
|
|
@@ -15630,7 +15633,7 @@ var AsyncMutex = class {
|
|
|
15630
15633
|
}
|
|
15631
15634
|
};
|
|
15632
15635
|
|
|
15633
|
-
// ../rivetkit/dist/tsup/chunk-
|
|
15636
|
+
// ../rivetkit/dist/tsup/chunk-QU5UOJLK.js
|
|
15634
15637
|
var import_invariant2 = __toESM(require_invariant(), 1);
|
|
15635
15638
|
|
|
15636
15639
|
// ../../../node_modules/.pnpm/p-retry@6.2.1/node_modules/p-retry/index.js
|
|
@@ -15808,7 +15811,7 @@ function createVersionedDataHandler(config3) {
|
|
|
15808
15811
|
return new VersionedDataHandler(config3);
|
|
15809
15812
|
}
|
|
15810
15813
|
|
|
15811
|
-
// ../rivetkit/dist/tsup/chunk-
|
|
15814
|
+
// ../rivetkit/dist/tsup/chunk-QU5UOJLK.js
|
|
15812
15815
|
var import_invariant3 = __toESM(require_invariant(), 1);
|
|
15813
15816
|
var import_invariant4 = __toESM(require_invariant(), 1);
|
|
15814
15817
|
var PATH_CONNECT = "/connect";
|
|
@@ -15817,6 +15820,7 @@ var PATH_WEBSOCKET_PREFIX = "/websocket/";
|
|
|
15817
15820
|
var HEADER_ACTOR_QUERY = "x-rivet-query";
|
|
15818
15821
|
var HEADER_ENCODING = "x-rivet-encoding";
|
|
15819
15822
|
var HEADER_CONN_PARAMS = "x-rivet-conn-params";
|
|
15823
|
+
var HEADER_ORIGINAL_REQUEST_URL = "x-rivet-internal-original-request-url";
|
|
15820
15824
|
var HEADER_ACTOR_ID = "x-rivet-actor";
|
|
15821
15825
|
var HEADER_ACTOR_GENERATION = "x-rivet-actor-generation";
|
|
15822
15826
|
var HEADER_ACTOR_KEY = "x-rivet-actor-key";
|
|
@@ -17875,6 +17879,18 @@ async function checkForSchedulingError(group, code, actorId, query, driver, rayI
|
|
|
17875
17879
|
}
|
|
17876
17880
|
return null;
|
|
17877
17881
|
}
|
|
17882
|
+
function isUrlLike(value) {
|
|
17883
|
+
return typeof value === "object" && value !== null && typeof value.href === "string" && typeof value.pathname === "string" && typeof value.search === "string";
|
|
17884
|
+
}
|
|
17885
|
+
function isRequestLike(value) {
|
|
17886
|
+
return typeof value === "object" && value !== null && typeof value.url === "string" && typeof value.method === "string" && isHeadersLike(value.headers);
|
|
17887
|
+
}
|
|
17888
|
+
function isResponseLike(value) {
|
|
17889
|
+
return typeof value === "object" && value !== null && typeof value.status === "number" && isHeadersLike(value.headers) && typeof value.arrayBuffer === "function";
|
|
17890
|
+
}
|
|
17891
|
+
function isHeadersLike(value) {
|
|
17892
|
+
return typeof value === "object" && value !== null && typeof value.entries === "function";
|
|
17893
|
+
}
|
|
17878
17894
|
function* walkErrorChain(error46, maxDepth = 8) {
|
|
17879
17895
|
let current = error46;
|
|
17880
17896
|
let depth = 0;
|
|
@@ -18300,28 +18316,28 @@ function createQueueSender(senderOptions) {
|
|
|
18300
18316
|
send
|
|
18301
18317
|
};
|
|
18302
18318
|
}
|
|
18303
|
-
function
|
|
18304
|
-
|
|
18305
|
-
|
|
18306
|
-
|
|
18307
|
-
|
|
18308
|
-
}
|
|
18309
|
-
|
|
18310
|
-
return
|
|
18311
|
-
}
|
|
18312
|
-
function isHeadersLike(value) {
|
|
18313
|
-
return typeof value === "object" && value !== null && typeof value.entries === "function";
|
|
18319
|
+
async function prepareRetryableInit(init) {
|
|
18320
|
+
if (init.body instanceof ReadableStream) {
|
|
18321
|
+
return {
|
|
18322
|
+
...init,
|
|
18323
|
+
body: new Uint8Array(await new Response(init.body).arrayBuffer())
|
|
18324
|
+
};
|
|
18325
|
+
}
|
|
18326
|
+
return init;
|
|
18314
18327
|
}
|
|
18315
18328
|
async function rawHttpFetch(driver, target, params, input, init, options = {}) {
|
|
18316
18329
|
let path2;
|
|
18330
|
+
let originalUrl;
|
|
18317
18331
|
let mergedInit = init || {};
|
|
18318
18332
|
if (typeof input === "string") {
|
|
18319
18333
|
path2 = input;
|
|
18320
18334
|
} else if (isUrlLike(input)) {
|
|
18321
18335
|
path2 = input.pathname + input.search;
|
|
18336
|
+
originalUrl = input.toString();
|
|
18322
18337
|
} else if (isRequestLike(input)) {
|
|
18323
18338
|
const url2 = new URL(input.url);
|
|
18324
18339
|
path2 = url2.pathname + url2.search;
|
|
18340
|
+
originalUrl = url2.toString();
|
|
18325
18341
|
const requestHeaders = new Headers(input.headers);
|
|
18326
18342
|
const initHeaders = new Headers((init == null ? void 0 : init.headers) || {});
|
|
18327
18343
|
const mergedHeaders = new Headers(requestHeaders);
|
|
@@ -18363,6 +18379,10 @@ async function rawHttpFetch(driver, target, params, input, init, options = {}) {
|
|
|
18363
18379
|
const normalizedPath = path2.startsWith("/") ? path2.slice(1) : path2;
|
|
18364
18380
|
const url2 = new URL(`http://actor/request/${normalizedPath}`);
|
|
18365
18381
|
const proxyRequestHeaders = new Headers(mergedInit.headers);
|
|
18382
|
+
proxyRequestHeaders.delete(HEADER_ORIGINAL_REQUEST_URL);
|
|
18383
|
+
if (originalUrl) {
|
|
18384
|
+
proxyRequestHeaders.set(HEADER_ORIGINAL_REQUEST_URL, originalUrl);
|
|
18385
|
+
}
|
|
18366
18386
|
if (params) {
|
|
18367
18387
|
proxyRequestHeaders.set(HEADER_CONN_PARAMS, JSON.stringify(params));
|
|
18368
18388
|
}
|
|
@@ -18457,6 +18477,7 @@ var ActorHandleRaw = class {
|
|
|
18457
18477
|
#gatewayOptions;
|
|
18458
18478
|
#params;
|
|
18459
18479
|
#getParams;
|
|
18480
|
+
#signal;
|
|
18460
18481
|
#resolvedActorId;
|
|
18461
18482
|
#resolvingActorId;
|
|
18462
18483
|
#queueSendMutex = new AsyncMutex();
|
|
@@ -18467,7 +18488,7 @@ var ActorHandleRaw = class {
|
|
|
18467
18488
|
*
|
|
18468
18489
|
* @protected
|
|
18469
18490
|
*/
|
|
18470
|
-
constructor(client, driver, params, getParams, encoding, actorResolutionState, gatewayOptions = {}) {
|
|
18491
|
+
constructor(client, driver, params, getParams, encoding, actorResolutionState, gatewayOptions = {}, signal) {
|
|
18471
18492
|
this.#client = client;
|
|
18472
18493
|
this.#driver = driver;
|
|
18473
18494
|
this.#encoding = encoding;
|
|
@@ -18475,6 +18496,7 @@ var ActorHandleRaw = class {
|
|
|
18475
18496
|
this.#gatewayOptions = gatewayOptions;
|
|
18476
18497
|
this.#params = params;
|
|
18477
18498
|
this.#getParams = getParams;
|
|
18499
|
+
this.#signal = signal;
|
|
18478
18500
|
}
|
|
18479
18501
|
async #resolveConnectionParams() {
|
|
18480
18502
|
if (this.#getParams) {
|
|
@@ -18488,7 +18510,9 @@ var ActorHandleRaw = class {
|
|
|
18488
18510
|
async #sendQueueMessage(name, body, options) {
|
|
18489
18511
|
return await this.#queueSendMutex.run(async () => {
|
|
18490
18512
|
const maxAttempts = this.#getDynamicQueryMaxAttempts();
|
|
18491
|
-
let useQueryTarget =
|
|
18513
|
+
let useQueryTarget = isDynamicActorQuery(
|
|
18514
|
+
this.#actorResolutionState
|
|
18515
|
+
);
|
|
18492
18516
|
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
18493
18517
|
let actorId;
|
|
18494
18518
|
try {
|
|
@@ -18551,8 +18575,9 @@ var ActorHandleRaw = class {
|
|
|
18551
18575
|
code
|
|
18552
18576
|
);
|
|
18553
18577
|
if (invalidated && attempt < maxAttempts - 1) {
|
|
18554
|
-
|
|
18555
|
-
|
|
18578
|
+
const waitForReady = code === "starting" || code === "stopping" || code.startsWith("destroyed_");
|
|
18579
|
+
useQueryTarget = useQueryTarget || waitForReady;
|
|
18580
|
+
if (waitForReady) {
|
|
18556
18581
|
await this.#waitForRetryWindow();
|
|
18557
18582
|
}
|
|
18558
18583
|
continue;
|
|
@@ -18580,15 +18605,17 @@ var ActorHandleRaw = class {
|
|
|
18580
18605
|
`Invalid action call: expected an options object { name, args }, got ${typeof opts}. Use handle.actionName(...args) for the shorthand API.`
|
|
18581
18606
|
);
|
|
18582
18607
|
}
|
|
18583
|
-
const
|
|
18608
|
+
const signal = opts.signal ?? this.#signal;
|
|
18609
|
+
const optsWithSignal = { ...opts, signal };
|
|
18610
|
+
const run = async () => await this.#sendActionNow(optsWithSignal);
|
|
18584
18611
|
if (opts.name === "destroy") {
|
|
18585
18612
|
return await run();
|
|
18586
18613
|
}
|
|
18587
|
-
return await retryOnLifecycleBoundary(run, { signal
|
|
18614
|
+
return await retryOnLifecycleBoundary(run, { signal });
|
|
18588
18615
|
}
|
|
18589
18616
|
async #sendActionNow(opts) {
|
|
18590
18617
|
const maxAttempts = this.#getDynamicQueryMaxAttempts();
|
|
18591
|
-
let useQueryTarget =
|
|
18618
|
+
let useQueryTarget = isDynamicActorQuery(this.#actorResolutionState);
|
|
18592
18619
|
const gatewayOptions = resolveActorGatewayOptions(
|
|
18593
18620
|
this.#gatewayOptions,
|
|
18594
18621
|
opts
|
|
@@ -18836,9 +18863,11 @@ var ActorHandleRaw = class {
|
|
|
18836
18863
|
return this.#fetchWithResolvedActor(input, init);
|
|
18837
18864
|
}
|
|
18838
18865
|
async #fetchWithResolvedActor(input, init) {
|
|
18866
|
+
const { skipReadyWait, ...restInit } = init ?? {};
|
|
18839
18867
|
const maxAttempts = this.#getDynamicQueryMaxAttempts();
|
|
18840
|
-
|
|
18841
|
-
const
|
|
18868
|
+
const requestInit = maxAttempts > 1 ? await prepareRetryableInit(restInit) : restInit;
|
|
18869
|
+
const clonesInputBody = requestInit.body === void 0 && isRequestLike(input) && input.body !== null;
|
|
18870
|
+
let useQueryTarget = isDynamicActorQuery(this.#actorResolutionState);
|
|
18842
18871
|
const gatewayOptions = resolveActorGatewayOptions(
|
|
18843
18872
|
this.#gatewayOptions,
|
|
18844
18873
|
{
|
|
@@ -18857,7 +18886,9 @@ var ActorHandleRaw = class {
|
|
|
18857
18886
|
this.#driver,
|
|
18858
18887
|
target,
|
|
18859
18888
|
this.#params,
|
|
18860
|
-
|
|
18889
|
+
// Clone a body-bearing Request so retries don't reuse a consumed stream.
|
|
18890
|
+
// NOTE: This holds the body in memory until GC (unavoidable).
|
|
18891
|
+
clonesInputBody ? input.clone() : input,
|
|
18861
18892
|
requestInit,
|
|
18862
18893
|
gatewayOptions
|
|
18863
18894
|
);
|
|
@@ -18905,8 +18936,9 @@ var ActorHandleRaw = class {
|
|
|
18905
18936
|
code
|
|
18906
18937
|
);
|
|
18907
18938
|
if (invalidated && attempt < maxAttempts - 1) {
|
|
18908
|
-
|
|
18909
|
-
|
|
18939
|
+
const waitForReady = code === "starting" || code === "stopping" || code.startsWith("destroyed_");
|
|
18940
|
+
useQueryTarget = useQueryTarget || waitForReady;
|
|
18941
|
+
if (waitForReady) {
|
|
18910
18942
|
await this.#waitForRetryWindow();
|
|
18911
18943
|
}
|
|
18912
18944
|
continue;
|
|
@@ -18956,10 +18988,10 @@ var ActorHandleRaw = class {
|
|
|
18956
18988
|
}
|
|
18957
18989
|
const invalidated = this.#invalidateResolvedActorId(group, code);
|
|
18958
18990
|
if (invalidated && attempt < maxAttempts - 1) {
|
|
18959
|
-
const
|
|
18991
|
+
const waitForReady = code === "starting" || code === "stopping" || code.startsWith("destroyed_");
|
|
18960
18992
|
return {
|
|
18961
|
-
useQueryTarget,
|
|
18962
|
-
waitForRetryWindow:
|
|
18993
|
+
useQueryTarget: true,
|
|
18994
|
+
waitForRetryWindow: waitForReady
|
|
18963
18995
|
};
|
|
18964
18996
|
}
|
|
18965
18997
|
return null;
|
|
@@ -19110,7 +19142,8 @@ var ClientRaw = class {
|
|
|
19110
19142
|
const handle = this.#createHandle(
|
|
19111
19143
|
opts == null ? void 0 : opts.params,
|
|
19112
19144
|
opts == null ? void 0 : opts.getParams,
|
|
19113
|
-
actorQuery
|
|
19145
|
+
actorQuery,
|
|
19146
|
+
opts == null ? void 0 : opts.signal
|
|
19114
19147
|
);
|
|
19115
19148
|
return createActorProxy(handle);
|
|
19116
19149
|
}
|
|
@@ -19140,7 +19173,8 @@ var ClientRaw = class {
|
|
|
19140
19173
|
const handle = this.#createHandle(
|
|
19141
19174
|
opts == null ? void 0 : opts.params,
|
|
19142
19175
|
opts == null ? void 0 : opts.getParams,
|
|
19143
|
-
actorQuery
|
|
19176
|
+
actorQuery,
|
|
19177
|
+
opts == null ? void 0 : opts.signal
|
|
19144
19178
|
);
|
|
19145
19179
|
return createActorProxy(handle);
|
|
19146
19180
|
}
|
|
@@ -19174,7 +19208,8 @@ var ClientRaw = class {
|
|
|
19174
19208
|
const handle = this.#createHandle(
|
|
19175
19209
|
opts == null ? void 0 : opts.params,
|
|
19176
19210
|
opts == null ? void 0 : opts.getParams,
|
|
19177
|
-
actorQuery
|
|
19211
|
+
actorQuery,
|
|
19212
|
+
opts == null ? void 0 : opts.signal
|
|
19178
19213
|
);
|
|
19179
19214
|
return createActorProxy(handle);
|
|
19180
19215
|
}
|
|
@@ -19221,12 +19256,13 @@ var ClientRaw = class {
|
|
|
19221
19256
|
const handle = this.#createHandle(
|
|
19222
19257
|
opts == null ? void 0 : opts.params,
|
|
19223
19258
|
opts == null ? void 0 : opts.getParams,
|
|
19224
|
-
getForIdQuery
|
|
19259
|
+
getForIdQuery,
|
|
19260
|
+
opts == null ? void 0 : opts.signal
|
|
19225
19261
|
);
|
|
19226
19262
|
const proxy = createActorProxy(handle);
|
|
19227
19263
|
return proxy;
|
|
19228
19264
|
}
|
|
19229
|
-
#createHandle(params, getParams, actorQuery) {
|
|
19265
|
+
#createHandle(params, getParams, actorQuery, signal) {
|
|
19230
19266
|
return new ActorHandleRaw(
|
|
19231
19267
|
this,
|
|
19232
19268
|
this.#driver,
|
|
@@ -19234,7 +19270,8 @@ var ClientRaw = class {
|
|
|
19234
19270
|
getParams,
|
|
19235
19271
|
this.#encodingKind,
|
|
19236
19272
|
actorQuery,
|
|
19237
|
-
this.#gatewayOptions
|
|
19273
|
+
this.#gatewayOptions,
|
|
19274
|
+
signal
|
|
19238
19275
|
);
|
|
19239
19276
|
}
|
|
19240
19277
|
[CREATE_ACTOR_CONN_PROXY](conn) {
|
|
@@ -20605,23 +20642,19 @@ async function sendHttpRequestToGateway(runConfig, gatewayUrl, actorRequest, opt
|
|
|
20605
20642
|
if (actorRequest.bodyUsed) {
|
|
20606
20643
|
throw new Error("Request body has already been consumed");
|
|
20607
20644
|
}
|
|
20608
|
-
|
|
20609
|
-
|
|
20610
|
-
bodyToSend = reqBody;
|
|
20645
|
+
if (actorRequest.body) {
|
|
20646
|
+
bodyToSend = actorRequest.body;
|
|
20611
20647
|
guardHeaders.delete("transfer-encoding");
|
|
20612
20648
|
guardHeaders.delete("content-length");
|
|
20613
20649
|
}
|
|
20614
20650
|
}
|
|
20615
|
-
|
|
20651
|
+
return fetch(gatewayUrl, {
|
|
20616
20652
|
method: actorRequest.method,
|
|
20617
20653
|
headers: guardHeaders,
|
|
20618
20654
|
body: bodyToSend,
|
|
20619
|
-
signal: actorRequest.signal
|
|
20655
|
+
signal: actorRequest.signal,
|
|
20656
|
+
...bodyToSend ? { duplex: "half" } : {}
|
|
20620
20657
|
});
|
|
20621
|
-
return mutableResponse(await fetch(guardRequest));
|
|
20622
|
-
}
|
|
20623
|
-
function mutableResponse(fetchRes) {
|
|
20624
|
-
return new Response(fetchRes.body, fetchRes);
|
|
20625
20658
|
}
|
|
20626
20659
|
function buildGuardHeaders(runConfig, actorRequest, options) {
|
|
20627
20660
|
const headers = new Headers();
|
|
@@ -21332,24 +21365,45 @@ var RemoteEngineControlClient = class {
|
|
|
21332
21365
|
name,
|
|
21333
21366
|
key
|
|
21334
21367
|
});
|
|
21335
|
-
|
|
21336
|
-
|
|
21337
|
-
|
|
21338
|
-
|
|
21339
|
-
|
|
21340
|
-
|
|
21341
|
-
|
|
21342
|
-
|
|
21343
|
-
|
|
21344
|
-
|
|
21345
|
-
|
|
21346
|
-
|
|
21347
|
-
|
|
21348
|
-
|
|
21349
|
-
|
|
21350
|
-
|
|
21351
|
-
|
|
21352
|
-
|
|
21368
|
+
try {
|
|
21369
|
+
const { actor: actor2, created } = await getOrCreateActor(this.#config, {
|
|
21370
|
+
datacenter: region,
|
|
21371
|
+
name,
|
|
21372
|
+
key: serializeActorKey(key),
|
|
21373
|
+
runner_name_selector: poolName ?? this.#config.poolName,
|
|
21374
|
+
input: actorInput ? uint8ArrayToBase642(
|
|
21375
|
+
encodeCborCompat(actorInput)
|
|
21376
|
+
) : void 0,
|
|
21377
|
+
crash_policy: crashPolicy ?? "sleep"
|
|
21378
|
+
});
|
|
21379
|
+
logger2().info({
|
|
21380
|
+
msg: "getOrCreateWithKey: actor ready",
|
|
21381
|
+
actorId: actor2.actor_id,
|
|
21382
|
+
name,
|
|
21383
|
+
key,
|
|
21384
|
+
created
|
|
21385
|
+
});
|
|
21386
|
+
return apiActorToOutput(actor2);
|
|
21387
|
+
} catch (error46) {
|
|
21388
|
+
if (error46 instanceof RivetError && error46.group === "actor" && error46.code === "key_reserved_in_different_datacenter") {
|
|
21389
|
+
logger2().warn({
|
|
21390
|
+
msg: "getOrCreateWithKey: key reserved in different datacenter, retrying as get",
|
|
21391
|
+
name,
|
|
21392
|
+
key
|
|
21393
|
+
});
|
|
21394
|
+
const response = await getActorByKey(this.#config, name, key);
|
|
21395
|
+
const existing = response.actors[0];
|
|
21396
|
+
if (!existing) throw error46;
|
|
21397
|
+
logger2().info({
|
|
21398
|
+
msg: "getOrCreateWithKey: resolved existing actor via get",
|
|
21399
|
+
actorId: existing.actor_id,
|
|
21400
|
+
name,
|
|
21401
|
+
key
|
|
21402
|
+
});
|
|
21403
|
+
return apiActorToOutput(existing);
|
|
21404
|
+
}
|
|
21405
|
+
throw error46;
|
|
21406
|
+
}
|
|
21353
21407
|
}
|
|
21354
21408
|
async createActor({
|
|
21355
21409
|
name,
|
|
@@ -21550,7 +21604,7 @@ function apiActorToOutput(actor2) {
|
|
|
21550
21604
|
};
|
|
21551
21605
|
}
|
|
21552
21606
|
|
|
21553
|
-
// ../rivetkit/dist/tsup/chunk-
|
|
21607
|
+
// ../rivetkit/dist/tsup/chunk-MLT7XFEF.js
|
|
21554
21608
|
var nativeStateTransactionOpeners = /* @__PURE__ */ new WeakMap();
|
|
21555
21609
|
var nativeStateTransactionClientBinders = /* @__PURE__ */ new WeakMap();
|
|
21556
21610
|
function registerNativeStateTransactionOpener(provider, opener) {
|
|
@@ -23626,6 +23680,12 @@ var RegistryConfigSchema = external_exports.object({
|
|
|
23626
23680
|
enginePort: external_exports.number().int().min(1).max(65535).optional().default(() => getRivetRunEnginePort() ?? ENGINE_PORT),
|
|
23627
23681
|
/** @experimental */
|
|
23628
23682
|
engineVersion: external_exports.string().optional().default(() => getRivetRunEngineVersion() ?? VERSION),
|
|
23683
|
+
/**
|
|
23684
|
+
* Starts the first-party Services actor host when RivetKit manages
|
|
23685
|
+
* a local engine. Defaults to the local-engine decision. Set
|
|
23686
|
+
* RIVET_RUN_SERVICES=0 or 1 to override it.
|
|
23687
|
+
*/
|
|
23688
|
+
startServices: external_exports.boolean().optional(),
|
|
23629
23689
|
/**
|
|
23630
23690
|
* @experimental
|
|
23631
23691
|
*
|
|
@@ -23706,11 +23766,12 @@ var RegistryConfigSchema = external_exports.object({
|
|
|
23706
23766
|
config3.enginePort
|
|
23707
23767
|
);
|
|
23708
23768
|
const endpoint = config3.startEngine ? localEngineEndpoint : (parsedEndpoint == null ? void 0 : parsedEndpoint.endpoint) ?? (isDevEnv ? localEngineEndpoint : void 0);
|
|
23769
|
+
const startServices = config3.startServices ?? getRivetRunServices() ?? Boolean(endpoint && isLocalEngineEndpoint(endpoint));
|
|
23709
23770
|
const validateServerlessEndpoint = Boolean(
|
|
23710
23771
|
config3.startEngine || parsedEndpoint
|
|
23711
23772
|
);
|
|
23712
23773
|
const namespace = (parsedEndpoint == null ? void 0 : parsedEndpoint.namespace) ?? config3.namespace ?? "default";
|
|
23713
|
-
const token = (parsedEndpoint == null ? void 0 : parsedEndpoint.token) ?? config3.token;
|
|
23774
|
+
const token = (parsedEndpoint == null ? void 0 : parsedEndpoint.token) ?? config3.token ?? "dev";
|
|
23714
23775
|
const parsedPublicEndpoint = config3.serverless.publicEndpoint ? tryParseEndpoint(ctx, {
|
|
23715
23776
|
endpoint: config3.serverless.publicEndpoint,
|
|
23716
23777
|
path: ["serverless", "publicEndpoint"]
|
|
@@ -23729,6 +23790,7 @@ var RegistryConfigSchema = external_exports.object({
|
|
|
23729
23790
|
...config3,
|
|
23730
23791
|
sqlite,
|
|
23731
23792
|
endpoint,
|
|
23793
|
+
startServices,
|
|
23732
23794
|
namespace,
|
|
23733
23795
|
token,
|
|
23734
23796
|
publicEndpoint,
|
|
@@ -23842,6 +23904,9 @@ var DocRegistryConfigSchema = external_exports.object({
|
|
|
23842
23904
|
engineVersion: external_exports.string().optional().describe(
|
|
23843
23905
|
"Version of the local engine package to use. Defaults to the current RivetKit version."
|
|
23844
23906
|
),
|
|
23907
|
+
startServices: external_exports.boolean().optional().describe(
|
|
23908
|
+
"Starts Services when RivetKit manages a local Engine. Defaults to the local-Engine decision. Set RIVET_RUN_SERVICES=0 or 1 to override."
|
|
23909
|
+
),
|
|
23845
23910
|
configurePool: DocConfigurePoolSchema.describe(
|
|
23846
23911
|
"Automatically configure serverless runners in the engine."
|
|
23847
23912
|
),
|
|
@@ -24351,16 +24416,30 @@ function toNapiApplication(application) {
|
|
|
24351
24416
|
if (!request) {
|
|
24352
24417
|
throw new Error("application fetch callback received no request");
|
|
24353
24418
|
}
|
|
24354
|
-
const response = await application(
|
|
24355
|
-
|
|
24356
|
-
|
|
24357
|
-
|
|
24419
|
+
const response = await application(
|
|
24420
|
+
{
|
|
24421
|
+
...request,
|
|
24422
|
+
body: new Uint8Array(request.body),
|
|
24423
|
+
cancelToken: request.cancelToken
|
|
24424
|
+
},
|
|
24425
|
+
request.responseBodyStream ? fromNapiHttpResponseBodyStream(
|
|
24426
|
+
request.responseBodyStream
|
|
24427
|
+
) : void 0
|
|
24428
|
+
);
|
|
24358
24429
|
return {
|
|
24359
24430
|
...response,
|
|
24360
|
-
body: toNapiBuffer(response.body)
|
|
24431
|
+
body: response.body === void 0 ? void 0 : toNapiBuffer(response.body)
|
|
24361
24432
|
};
|
|
24362
24433
|
};
|
|
24363
24434
|
}
|
|
24435
|
+
function fromNapiHttpResponseBodyStream(stream) {
|
|
24436
|
+
return {
|
|
24437
|
+
cancelled: () => stream.cancelled(),
|
|
24438
|
+
write: (chunk) => stream.write(Buffer.from(chunk)),
|
|
24439
|
+
end: () => stream.end(),
|
|
24440
|
+
error: (message) => stream.error(message)
|
|
24441
|
+
};
|
|
24442
|
+
}
|
|
24364
24443
|
function toNapiHttpRequest(request) {
|
|
24365
24444
|
if (!request) {
|
|
24366
24445
|
return request;
|
|
@@ -24903,6 +24982,147 @@ async function loadNapiRuntime() {
|
|
|
24903
24982
|
runtime: new NapiCoreRuntime(bindings)
|
|
24904
24983
|
};
|
|
24905
24984
|
}
|
|
24985
|
+
var HTTP_BODY_CHUNK_SIZE = 64 * 1024;
|
|
24986
|
+
function runtimeBytesToArrayBuffer(value) {
|
|
24987
|
+
return value.buffer.slice(
|
|
24988
|
+
value.byteOffset,
|
|
24989
|
+
value.byteOffset + value.byteLength
|
|
24990
|
+
);
|
|
24991
|
+
}
|
|
24992
|
+
function buildNativeHttpRequest(init) {
|
|
24993
|
+
var _a2;
|
|
24994
|
+
const headers = new Headers(init.headers);
|
|
24995
|
+
const originalUrl = headers.get(HEADER_ORIGINAL_REQUEST_URL);
|
|
24996
|
+
headers.delete(HEADER_ORIGINAL_REQUEST_URL);
|
|
24997
|
+
const url2 = originalUrl ?? (init.uri.startsWith("http") ? init.uri : new URL(init.uri, "http://127.0.0.1").toString());
|
|
24998
|
+
const method2 = init.method.toUpperCase();
|
|
24999
|
+
const bodyForbidden = method2 === "GET" || method2 === "HEAD";
|
|
25000
|
+
const body = bodyForbidden ? void 0 : init.bodyStream ? new ReadableStream({
|
|
25001
|
+
async pull(controller) {
|
|
25002
|
+
var _a22, _b;
|
|
25003
|
+
try {
|
|
25004
|
+
if (init.body && init.body.length > 0) {
|
|
25005
|
+
controller.enqueue(new Uint8Array(init.body));
|
|
25006
|
+
init.body = void 0;
|
|
25007
|
+
return;
|
|
25008
|
+
}
|
|
25009
|
+
const chunk = await ((_a22 = init.bodyStream) == null ? void 0 : _a22.read());
|
|
25010
|
+
if (!chunk) {
|
|
25011
|
+
controller.close();
|
|
25012
|
+
} else {
|
|
25013
|
+
controller.enqueue(new Uint8Array(chunk));
|
|
25014
|
+
}
|
|
25015
|
+
} catch (error46) {
|
|
25016
|
+
(_b = init.abortController) == null ? void 0 : _b.abort(error46);
|
|
25017
|
+
controller.error(error46);
|
|
25018
|
+
}
|
|
25019
|
+
},
|
|
25020
|
+
async cancel() {
|
|
25021
|
+
var _a22;
|
|
25022
|
+
await ((_a22 = init.bodyStream) == null ? void 0 : _a22.cancel());
|
|
25023
|
+
}
|
|
25024
|
+
}) : init.body && init.body.length > 0 ? runtimeBytesToArrayBuffer(init.body) : void 0;
|
|
25025
|
+
const streamInit = init.bodyStream && !bodyForbidden ? { duplex: "half" } : {};
|
|
25026
|
+
return new Request(url2, {
|
|
25027
|
+
method: method2,
|
|
25028
|
+
headers,
|
|
25029
|
+
body,
|
|
25030
|
+
signal: ((_a2 = init.abortController) == null ? void 0 : _a2.signal) ?? init.signal,
|
|
25031
|
+
...streamInit
|
|
25032
|
+
});
|
|
25033
|
+
}
|
|
25034
|
+
async function cancelNativeHttpRequestBody(bodyStream) {
|
|
25035
|
+
await (bodyStream == null ? void 0 : bodyStream.cancel());
|
|
25036
|
+
}
|
|
25037
|
+
async function writeResponseChunk(stream, chunk) {
|
|
25038
|
+
for (let offset = 0; offset < chunk.byteLength; offset += HTTP_BODY_CHUNK_SIZE) {
|
|
25039
|
+
await stream.write(
|
|
25040
|
+
chunk.subarray(offset, offset + HTTP_BODY_CHUNK_SIZE)
|
|
25041
|
+
);
|
|
25042
|
+
}
|
|
25043
|
+
}
|
|
25044
|
+
async function pumpResponseBody(reader, stream) {
|
|
25045
|
+
var _a2;
|
|
25046
|
+
const cancelled = stream.cancelled().then(() => ({ cancelled: true }));
|
|
25047
|
+
try {
|
|
25048
|
+
for (; ; ) {
|
|
25049
|
+
const read = reader.read().then((next2) => ({ cancelled: false, next: next2 }));
|
|
25050
|
+
const result = await Promise.race([read, cancelled]);
|
|
25051
|
+
if (result.cancelled) {
|
|
25052
|
+
void reader.cancel(
|
|
25053
|
+
new Error(
|
|
25054
|
+
"native http response stream receiver dropped"
|
|
25055
|
+
)
|
|
25056
|
+
).catch((error46) => {
|
|
25057
|
+
logger22().debug({
|
|
25058
|
+
msg: "failed to cancel native http response reader",
|
|
25059
|
+
error: error46
|
|
25060
|
+
});
|
|
25061
|
+
});
|
|
25062
|
+
return;
|
|
25063
|
+
}
|
|
25064
|
+
const { next } = result;
|
|
25065
|
+
if (next.done) {
|
|
25066
|
+
await stream.end();
|
|
25067
|
+
return;
|
|
25068
|
+
}
|
|
25069
|
+
if ((_a2 = next.value) == null ? void 0 : _a2.byteLength) {
|
|
25070
|
+
await writeResponseChunk(stream, next.value);
|
|
25071
|
+
}
|
|
25072
|
+
}
|
|
25073
|
+
} catch (error46) {
|
|
25074
|
+
try {
|
|
25075
|
+
await stream.error(stringifyError(error46));
|
|
25076
|
+
} catch (streamError) {
|
|
25077
|
+
logger22().debug({
|
|
25078
|
+
msg: "failed to report native http response stream error",
|
|
25079
|
+
error: streamError
|
|
25080
|
+
});
|
|
25081
|
+
}
|
|
25082
|
+
void reader.cancel(error46).catch(() => {
|
|
25083
|
+
});
|
|
25084
|
+
} finally {
|
|
25085
|
+
try {
|
|
25086
|
+
reader.releaseLock();
|
|
25087
|
+
} catch (error46) {
|
|
25088
|
+
logger22().debug({
|
|
25089
|
+
msg: "failed to release native http response reader lock",
|
|
25090
|
+
error: error46
|
|
25091
|
+
});
|
|
25092
|
+
}
|
|
25093
|
+
}
|
|
25094
|
+
}
|
|
25095
|
+
async function convertNativeHttpResponse(response, responseBodyStream) {
|
|
25096
|
+
const headers = Object.fromEntries(response.headers.entries());
|
|
25097
|
+
if (!response.body) {
|
|
25098
|
+
return {
|
|
25099
|
+
response: {
|
|
25100
|
+
status: response.status,
|
|
25101
|
+
headers,
|
|
25102
|
+
body: new Uint8Array()
|
|
25103
|
+
}
|
|
25104
|
+
};
|
|
25105
|
+
}
|
|
25106
|
+
if (responseBodyStream) {
|
|
25107
|
+
const reader = response.body.getReader();
|
|
25108
|
+
const bodyCompletion = pumpResponseBody(reader, responseBodyStream);
|
|
25109
|
+
return {
|
|
25110
|
+
response: {
|
|
25111
|
+
status: response.status,
|
|
25112
|
+
headers,
|
|
25113
|
+
stream: true
|
|
25114
|
+
},
|
|
25115
|
+
bodyCompletion
|
|
25116
|
+
};
|
|
25117
|
+
}
|
|
25118
|
+
return {
|
|
25119
|
+
response: {
|
|
25120
|
+
status: response.status,
|
|
25121
|
+
headers,
|
|
25122
|
+
body: new Uint8Array(await response.arrayBuffer())
|
|
25123
|
+
}
|
|
25124
|
+
};
|
|
25125
|
+
}
|
|
24906
25126
|
var CONN_PARAMS_KEY = "__conn_params__";
|
|
24907
25127
|
function validateActionArgs(schemas, name, args) {
|
|
24908
25128
|
if (!(schemas == null ? void 0 : schemas[name])) {
|
|
@@ -26049,10 +26269,28 @@ async function loadAutoRuntime(config3, loaders = defaultRuntimeLoaders) {
|
|
|
26049
26269
|
if (loaders.detectHost() === "edge-like") {
|
|
26050
26270
|
return (await loaders.loadWasm(config3.wasm)).runtime;
|
|
26051
26271
|
}
|
|
26272
|
+
let nativeError;
|
|
26052
26273
|
try {
|
|
26053
26274
|
return (await loaders.loadNative()).runtime;
|
|
26054
|
-
} catch {
|
|
26275
|
+
} catch (error46) {
|
|
26276
|
+
nativeError = error46;
|
|
26277
|
+
logger22().warn({
|
|
26278
|
+
msg: "native runtime failed to load; falling back to wasm",
|
|
26279
|
+
error: stringifyError(error46)
|
|
26280
|
+
});
|
|
26281
|
+
}
|
|
26282
|
+
try {
|
|
26055
26283
|
return (await loaders.loadWasm(config3.wasm)).runtime;
|
|
26284
|
+
} catch (wasmError) {
|
|
26285
|
+
throw new RivetError(
|
|
26286
|
+
"config",
|
|
26287
|
+
"runtime_unavailable",
|
|
26288
|
+
`RivetKit could not load a core runtime. Native runtime: ${stringifyError(nativeError)} Wasm runtime: ${stringifyError(wasmError)}`,
|
|
26289
|
+
{
|
|
26290
|
+
public: true,
|
|
26291
|
+
statusCode: 500
|
|
26292
|
+
}
|
|
26293
|
+
);
|
|
26056
26294
|
}
|
|
26057
26295
|
}
|
|
26058
26296
|
async function loadConfiguredRuntime(config3, loaders = defaultRuntimeLoaders) {
|
|
@@ -26351,7 +26589,7 @@ function toRuntimeBytes(value) {
|
|
|
26351
26589
|
function arrayBufferViewToRuntimeBytes(value) {
|
|
26352
26590
|
return new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
|
|
26353
26591
|
}
|
|
26354
|
-
function
|
|
26592
|
+
function runtimeBytesToArrayBuffer2(value) {
|
|
26355
26593
|
return value.buffer.slice(
|
|
26356
26594
|
value.byteOffset,
|
|
26357
26595
|
value.byteOffset + value.byteLength
|
|
@@ -26397,6 +26635,9 @@ function decodeNativeKvValue(value, options) {
|
|
|
26397
26635
|
async function loadEngineCli() {
|
|
26398
26636
|
return import(["@rivetkit", "engine-cli"].join("/"));
|
|
26399
26637
|
}
|
|
26638
|
+
async function loadServices() {
|
|
26639
|
+
return import(["@rivet-dev", "services"].join("/"));
|
|
26640
|
+
}
|
|
26400
26641
|
function decodeValue(value) {
|
|
26401
26642
|
if (!value || value.length === 0) {
|
|
26402
26643
|
return void 0;
|
|
@@ -26682,24 +26923,6 @@ function decodeArgs(value) {
|
|
|
26682
26923
|
const decoded = decodeValue(value);
|
|
26683
26924
|
return normalizeArgs(decoded);
|
|
26684
26925
|
}
|
|
26685
|
-
function buildRequest(init) {
|
|
26686
|
-
const url2 = init.uri.startsWith("http") ? init.uri : new URL(init.uri, "http://127.0.0.1").toString();
|
|
26687
|
-
const body = init.body && init.body.length > 0 ? runtimeBytesToArrayBuffer(init.body) : void 0;
|
|
26688
|
-
return new Request(url2, {
|
|
26689
|
-
method: init.method,
|
|
26690
|
-
headers: init.headers,
|
|
26691
|
-
body
|
|
26692
|
-
});
|
|
26693
|
-
}
|
|
26694
|
-
async function toRuntimeHttpResponse(response) {
|
|
26695
|
-
const headers = Object.fromEntries(response.headers.entries());
|
|
26696
|
-
const body = new Uint8Array(await response.arrayBuffer());
|
|
26697
|
-
return {
|
|
26698
|
-
status: response.status,
|
|
26699
|
-
headers,
|
|
26700
|
-
body
|
|
26701
|
-
};
|
|
26702
|
-
}
|
|
26703
26926
|
function toActorKey(segments) {
|
|
26704
26927
|
return segments.map(
|
|
26705
26928
|
(segment) => segment.kind === "number" ? String(segment.numberValue ?? 0) : segment.stringValue ?? ""
|
|
@@ -27412,7 +27635,7 @@ var NativeWebSocketAdapter = class {
|
|
|
27412
27635
|
this.#runtime.webSocketSetEventCallback(this.#ws, (event2) => {
|
|
27413
27636
|
if (event2.kind === "message") {
|
|
27414
27637
|
this.#virtual.triggerMessage(
|
|
27415
|
-
event2.binary ?
|
|
27638
|
+
event2.binary ? runtimeBytesToArrayBuffer2(event2.data) : event2.data,
|
|
27416
27639
|
event2.messageIndex
|
|
27417
27640
|
);
|
|
27418
27641
|
return;
|
|
@@ -28795,12 +29018,14 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
28795
29018
|
cancelToken,
|
|
28796
29019
|
run !== void 0
|
|
28797
29020
|
);
|
|
28798
|
-
const maybeHandleNativeInspectorRequest = async (ctx,
|
|
29021
|
+
const maybeHandleNativeInspectorRequest = async (ctx, rawRequest) => {
|
|
28799
29022
|
var _a22, _b, _c, _d;
|
|
28800
|
-
const
|
|
29023
|
+
const rawUrl = rawRequest.uri.startsWith("http") ? rawRequest.uri : new URL(rawRequest.uri, "http://127.0.0.1").toString();
|
|
29024
|
+
const url2 = new URL(rawUrl);
|
|
28801
29025
|
if (!url2.pathname.startsWith("/inspector/")) {
|
|
28802
29026
|
return void 0;
|
|
28803
29027
|
}
|
|
29028
|
+
const jsRequest = buildNativeHttpRequest(rawRequest);
|
|
28804
29029
|
const jsonResponse = (body, init) => new Response(JSON.stringify(body), {
|
|
28805
29030
|
status: (init == null ? void 0 : init.status) ?? 200,
|
|
28806
29031
|
headers: {
|
|
@@ -29331,7 +29556,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
29331
29556
|
);
|
|
29332
29557
|
const actorCtx = makeActorCtx(
|
|
29333
29558
|
ctx,
|
|
29334
|
-
request ?
|
|
29559
|
+
request ? buildNativeHttpRequest(request) : void 0
|
|
29335
29560
|
);
|
|
29336
29561
|
try {
|
|
29337
29562
|
await config3.onBeforeConnect(
|
|
@@ -29351,7 +29576,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
29351
29576
|
const { ctx, conn, params, request } = unwrapTsfnPayload(error46, payload);
|
|
29352
29577
|
const actorCtx = makeActorCtx(
|
|
29353
29578
|
ctx,
|
|
29354
|
-
request ?
|
|
29579
|
+
request ? buildNativeHttpRequest(request) : void 0
|
|
29355
29580
|
);
|
|
29356
29581
|
const connAdapter = new NativeConnAdapter(
|
|
29357
29582
|
runtime,
|
|
@@ -29389,7 +29614,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
29389
29614
|
);
|
|
29390
29615
|
const actorCtx = makeActorCtx(
|
|
29391
29616
|
ctx,
|
|
29392
|
-
request ?
|
|
29617
|
+
request ? buildNativeHttpRequest(request) : void 0
|
|
29393
29618
|
);
|
|
29394
29619
|
const connAdapter = new NativeConnAdapter(
|
|
29395
29620
|
runtime,
|
|
@@ -29496,27 +29721,45 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
29496
29721
|
onRequest: wrapNativeCallback(
|
|
29497
29722
|
async (error46, payload) => {
|
|
29498
29723
|
try {
|
|
29499
|
-
const { ctx, request, cancelToken } = unwrapTsfnPayload(
|
|
29500
|
-
|
|
29501
|
-
payload
|
|
29502
|
-
);
|
|
29503
|
-
const jsRequest = buildRequest(request);
|
|
29504
|
-
const inspectorResponse = await maybeHandleNativeInspectorRequest(
|
|
29505
|
-
ctx,
|
|
29506
|
-
request,
|
|
29507
|
-
jsRequest
|
|
29508
|
-
);
|
|
29724
|
+
const { ctx, request, cancelToken, responseBodyStream } = unwrapTsfnPayload(error46, payload);
|
|
29725
|
+
const inspectorResponse = await maybeHandleNativeInspectorRequest(ctx, request);
|
|
29509
29726
|
if (inspectorResponse) {
|
|
29510
|
-
|
|
29727
|
+
await cancelNativeHttpRequestBody(request.bodyStream);
|
|
29728
|
+
return (await convertNativeHttpResponse(
|
|
29729
|
+
inspectorResponse,
|
|
29730
|
+
responseBodyStream
|
|
29731
|
+
)).response;
|
|
29511
29732
|
}
|
|
29512
29733
|
if (typeof config3.onRequest !== "function") {
|
|
29513
|
-
|
|
29514
|
-
|
|
29515
|
-
|
|
29734
|
+
await cancelNativeHttpRequestBody(request.bodyStream);
|
|
29735
|
+
return (await convertNativeHttpResponse(
|
|
29736
|
+
new Response(null, { status: 404 }),
|
|
29737
|
+
responseBodyStream
|
|
29738
|
+
)).response;
|
|
29516
29739
|
}
|
|
29517
|
-
const
|
|
29740
|
+
const requestAbortController = new AbortController();
|
|
29741
|
+
const handlerRequest = buildNativeHttpRequest({
|
|
29742
|
+
...request,
|
|
29743
|
+
abortController: requestAbortController
|
|
29744
|
+
});
|
|
29745
|
+
const rawConnParams = handlerRequest.headers.get(HEADER_CONN_PARAMS);
|
|
29518
29746
|
let requestCtx;
|
|
29519
29747
|
let conn;
|
|
29748
|
+
let removeRequestAbortListener;
|
|
29749
|
+
let cleanupDeferredToBody = false;
|
|
29750
|
+
let cleanedUp = false;
|
|
29751
|
+
const cleanupRequest = async () => {
|
|
29752
|
+
if (cleanedUp) return;
|
|
29753
|
+
cleanedUp = true;
|
|
29754
|
+
removeRequestAbortListener == null ? void 0 : removeRequestAbortListener();
|
|
29755
|
+
try {
|
|
29756
|
+
await (requestCtx == null ? void 0 : requestCtx.dispose());
|
|
29757
|
+
} finally {
|
|
29758
|
+
if (conn) {
|
|
29759
|
+
await runtime.connDisconnect(conn);
|
|
29760
|
+
}
|
|
29761
|
+
}
|
|
29762
|
+
};
|
|
29520
29763
|
try {
|
|
29521
29764
|
const connParams = validateConnParams(
|
|
29522
29765
|
schemaConfig.connParamsSchema,
|
|
@@ -29532,23 +29775,56 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
29532
29775
|
requestCtx = makeConnCtx(
|
|
29533
29776
|
ctx,
|
|
29534
29777
|
conn,
|
|
29535
|
-
|
|
29778
|
+
handlerRequest,
|
|
29536
29779
|
cancelToken
|
|
29537
29780
|
);
|
|
29781
|
+
const ctxAbortSignal = requestCtx.abortSignal;
|
|
29782
|
+
const abortRequest = () => requestAbortController.abort(ctxAbortSignal.reason);
|
|
29783
|
+
if (ctxAbortSignal.aborted) {
|
|
29784
|
+
abortRequest();
|
|
29785
|
+
} else {
|
|
29786
|
+
ctxAbortSignal.addEventListener(
|
|
29787
|
+
"abort",
|
|
29788
|
+
abortRequest,
|
|
29789
|
+
{ once: true }
|
|
29790
|
+
);
|
|
29791
|
+
removeRequestAbortListener = () => ctxAbortSignal.removeEventListener(
|
|
29792
|
+
"abort",
|
|
29793
|
+
abortRequest
|
|
29794
|
+
);
|
|
29795
|
+
}
|
|
29538
29796
|
const response = await config3.onRequest(
|
|
29539
29797
|
requestCtx,
|
|
29540
|
-
|
|
29798
|
+
handlerRequest
|
|
29541
29799
|
);
|
|
29542
29800
|
if (!isResponseLike(response)) {
|
|
29543
29801
|
throw new Error(
|
|
29544
29802
|
"onRequest handler must return a Response"
|
|
29545
29803
|
);
|
|
29546
29804
|
}
|
|
29547
|
-
|
|
29805
|
+
const conversion = await convertNativeHttpResponse(
|
|
29806
|
+
response,
|
|
29807
|
+
responseBodyStream
|
|
29808
|
+
);
|
|
29809
|
+
if (conversion.bodyCompletion) {
|
|
29810
|
+
cleanupDeferredToBody = true;
|
|
29811
|
+
void conversion.bodyCompletion.then(cleanupRequest).catch((cleanupError) => {
|
|
29812
|
+
logger22().error({
|
|
29813
|
+
msg: "failed to clean up native streaming http request",
|
|
29814
|
+
error: cleanupError
|
|
29815
|
+
});
|
|
29816
|
+
});
|
|
29817
|
+
}
|
|
29818
|
+
return conversion.response;
|
|
29548
29819
|
} finally {
|
|
29549
|
-
|
|
29550
|
-
|
|
29551
|
-
|
|
29820
|
+
try {
|
|
29821
|
+
await cancelNativeHttpRequestBody(
|
|
29822
|
+
request.bodyStream
|
|
29823
|
+
);
|
|
29824
|
+
} finally {
|
|
29825
|
+
if (!cleanupDeferredToBody) {
|
|
29826
|
+
await cleanupRequest();
|
|
29827
|
+
}
|
|
29552
29828
|
}
|
|
29553
29829
|
}
|
|
29554
29830
|
} catch (error210) {
|
|
@@ -29563,7 +29839,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
29563
29839
|
onWebSocket: typeof config3.onWebSocket === "function" ? wrapNativeCallback(
|
|
29564
29840
|
async (error46, payload) => {
|
|
29565
29841
|
const { ctx, conn, ws, request } = unwrapTsfnPayload(error46, payload);
|
|
29566
|
-
const jsRequest = request ?
|
|
29842
|
+
const jsRequest = request ? buildNativeHttpRequest(request) : void 0;
|
|
29567
29843
|
const actorCtx = makeConnCtx(ctx, conn, jsRequest);
|
|
29568
29844
|
try {
|
|
29569
29845
|
await config3.onWebSocket(
|
|
@@ -29669,7 +29945,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
29669
29945
|
timeoutMs,
|
|
29670
29946
|
cancelToken
|
|
29671
29947
|
} = unwrapTsfnPayload(error46, payload);
|
|
29672
|
-
const jsRequest =
|
|
29948
|
+
const jsRequest = buildNativeHttpRequest(request);
|
|
29673
29949
|
const actorCtx = withConnContext(
|
|
29674
29950
|
runtime,
|
|
29675
29951
|
ctx,
|
|
@@ -29739,7 +30015,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
29739
30015
|
buildActorConfig(definition, registryConfig, runtime.kind)
|
|
29740
30016
|
);
|
|
29741
30017
|
}
|
|
29742
|
-
async function buildServeConfig(config3) {
|
|
30018
|
+
async function buildServeConfig(config3, resolveServicesBinary = true) {
|
|
29743
30019
|
var _a2;
|
|
29744
30020
|
if (!config3.endpoint) {
|
|
29745
30021
|
throw nativeEndpointNotConfiguredError();
|
|
@@ -29750,6 +30026,7 @@ async function buildServeConfig(config3) {
|
|
|
29750
30026
|
token: config3.token,
|
|
29751
30027
|
namespace: config3.namespace,
|
|
29752
30028
|
poolName: config3.envoy.poolName,
|
|
30029
|
+
startServices: resolveServicesBinary && config3.startServices,
|
|
29753
30030
|
handleInspectorHttpInRuntime: true,
|
|
29754
30031
|
serverlessBasePath: config3.serverless.basePath,
|
|
29755
30032
|
serverlessPackageVersion: VERSION,
|
|
@@ -29768,6 +30045,17 @@ async function buildServeConfig(config3) {
|
|
|
29768
30045
|
error: stringifyError(error46)
|
|
29769
30046
|
});
|
|
29770
30047
|
}
|
|
30048
|
+
if (resolveServicesBinary && config3.startServices) {
|
|
30049
|
+
try {
|
|
30050
|
+
const { getServicesPath } = await loadServices();
|
|
30051
|
+
serveConfig.servicesBinaryPath = getServicesPath();
|
|
30052
|
+
} catch (error46) {
|
|
30053
|
+
logger22().warn({
|
|
30054
|
+
msg: "could not resolve the Services binary; a local engine will fail with services.binary_unavailable \u2014 set RIVET_RUN_SERVICES=0 to disable Services or RIVET_SERVICES_BINARY to a local rivet-services binary",
|
|
30055
|
+
error: stringifyError(error46)
|
|
30056
|
+
});
|
|
30057
|
+
}
|
|
30058
|
+
}
|
|
29771
30059
|
serveConfig.engineHost = config3.engineHost;
|
|
29772
30060
|
serveConfig.enginePort = config3.enginePort;
|
|
29773
30061
|
if ((_a2 = config3.test) == null ? void 0 : _a2.enabled) {
|
|
@@ -29794,7 +30082,7 @@ async function buildRegistryWithRuntime(config3, runtime) {
|
|
|
29794
30082
|
return {
|
|
29795
30083
|
runtime,
|
|
29796
30084
|
registry: registry2,
|
|
29797
|
-
serveConfig: await buildServeConfig(config3)
|
|
30085
|
+
serveConfig: await buildServeConfig(config3, runtime.kind === "napi")
|
|
29798
30086
|
};
|
|
29799
30087
|
}
|
|
29800
30088
|
async function buildConfiguredRegistry(config3) {
|
|
@@ -29819,15 +30107,27 @@ function finishShutdownSignal(signal) {
|
|
|
29819
30107
|
}
|
|
29820
30108
|
process.kill(process.pid, signal);
|
|
29821
30109
|
}
|
|
29822
|
-
function createApplicationFetch(application) {
|
|
29823
|
-
return async (request) => {
|
|
30110
|
+
function createApplicationFetch(application, runtime) {
|
|
30111
|
+
return async (request, responseBodyStream) => {
|
|
29824
30112
|
const method2 = request.method.toUpperCase();
|
|
29825
30113
|
const body = method2 === "GET" || method2 === "HEAD" || request.body.length === 0 ? void 0 : Uint8Array.from(request.body).buffer;
|
|
30114
|
+
const abortController = new AbortController();
|
|
30115
|
+
if (request.cancelToken) {
|
|
30116
|
+
if (runtime.cancellationTokenAborted(request.cancelToken)) {
|
|
30117
|
+
abortController.abort();
|
|
30118
|
+
} else {
|
|
30119
|
+
runtime.onCancellationTokenCancelled(
|
|
30120
|
+
request.cancelToken,
|
|
30121
|
+
() => abortController.abort()
|
|
30122
|
+
);
|
|
30123
|
+
}
|
|
30124
|
+
}
|
|
29826
30125
|
const response = await application.fetch(
|
|
29827
30126
|
new Request(request.url, {
|
|
29828
30127
|
method: method2,
|
|
29829
30128
|
headers: request.headers,
|
|
29830
|
-
body
|
|
30129
|
+
body,
|
|
30130
|
+
signal: abortController.signal
|
|
29831
30131
|
})
|
|
29832
30132
|
);
|
|
29833
30133
|
if (!isResponseLike(response)) {
|
|
@@ -29835,10 +30135,23 @@ function createApplicationFetch(application) {
|
|
|
29835
30135
|
"registry.listen() application fetch must return a Response"
|
|
29836
30136
|
);
|
|
29837
30137
|
}
|
|
30138
|
+
const conversion = await convertNativeHttpResponse(
|
|
30139
|
+
response,
|
|
30140
|
+
responseBodyStream
|
|
30141
|
+
);
|
|
30142
|
+
if (conversion.bodyCompletion) {
|
|
30143
|
+
void conversion.bodyCompletion.catch((error46) => {
|
|
30144
|
+
logger22().error({
|
|
30145
|
+
msg: "application response stream failed",
|
|
30146
|
+
error: error46
|
|
30147
|
+
});
|
|
30148
|
+
});
|
|
30149
|
+
}
|
|
29838
30150
|
return {
|
|
29839
|
-
status: response.status,
|
|
29840
|
-
headers: Object.fromEntries(response.headers.entries()),
|
|
29841
|
-
body:
|
|
30151
|
+
status: conversion.response.status ?? response.status,
|
|
30152
|
+
headers: conversion.response.headers ?? Object.fromEntries(response.headers.entries()),
|
|
30153
|
+
body: conversion.response.body,
|
|
30154
|
+
stream: conversion.response.stream
|
|
29842
30155
|
};
|
|
29843
30156
|
};
|
|
29844
30157
|
}
|
|
@@ -30096,8 +30409,7 @@ var Registry = class {
|
|
|
30096
30409
|
const port = opts.port ?? parsePortEnv(process.env.RIVET_PORT) ?? 3e3;
|
|
30097
30410
|
const publicDir = opts.publicDir ?? getRivetkitPublicDir();
|
|
30098
30411
|
const config3 = this.parseConfig();
|
|
30099
|
-
|
|
30100
|
-
if (application && getRivetkitRuntimeMode() !== "serverless") {
|
|
30412
|
+
if (opts.application && getRivetkitRuntimeMode() !== "serverless") {
|
|
30101
30413
|
if (config3.runtime === "wasm") {
|
|
30102
30414
|
throw new Error(
|
|
30103
30415
|
"registry.listen() requires the native runtime; use an application-owned HTTP server with WebAssembly"
|
|
@@ -30116,13 +30428,18 @@ var Registry = class {
|
|
|
30116
30428
|
throw new Error("registry envoy startup did not initialize");
|
|
30117
30429
|
}
|
|
30118
30430
|
const { runtime: runtime2, registry: registry22, serveConfig: serveConfig2 } = await configuredRegistryPromise2;
|
|
30431
|
+
const application2 = createApplicationFetch(
|
|
30432
|
+
opts.application,
|
|
30433
|
+
runtime2
|
|
30434
|
+
);
|
|
30435
|
+
await readyPromise;
|
|
30119
30436
|
const listenerPromise = runtime2.serveApplicationListener(
|
|
30120
30437
|
registry22,
|
|
30121
30438
|
{
|
|
30122
30439
|
port,
|
|
30123
30440
|
host: opts.host,
|
|
30124
30441
|
publicDir,
|
|
30125
|
-
application
|
|
30442
|
+
application: application2
|
|
30126
30443
|
},
|
|
30127
30444
|
serveConfig2
|
|
30128
30445
|
);
|
|
@@ -30133,14 +30450,10 @@ var Registry = class {
|
|
|
30133
30450
|
"registry envoy serve lifecycle did not initialize"
|
|
30134
30451
|
);
|
|
30135
30452
|
}
|
|
30136
|
-
await Promise.all([
|
|
30137
|
-
readyPromise,
|
|
30138
|
-
listenerPromise,
|
|
30139
|
-
serveLifecyclePromise
|
|
30140
|
-
]);
|
|
30453
|
+
await Promise.all([listenerPromise, serveLifecyclePromise]);
|
|
30141
30454
|
return;
|
|
30142
30455
|
}
|
|
30143
|
-
const configuredRegistryPromise = buildConfiguredRegistry(config3);
|
|
30456
|
+
const configuredRegistryPromise = this.#buildConfiguredRegistry(config3);
|
|
30144
30457
|
this.#runtimeServeConfiguredPromise = configuredRegistryPromise;
|
|
30145
30458
|
this.#runtimeServerlessPromise = configuredRegistryPromise;
|
|
30146
30459
|
this.#installSignalHandlers(config3);
|
|
@@ -30151,6 +30464,7 @@ var Registry = class {
|
|
|
30151
30464
|
});
|
|
30152
30465
|
this.#ensureServerlessPoolConfigured(config3);
|
|
30153
30466
|
const { runtime, registry: registry2, serveConfig } = await configuredRegistryPromise;
|
|
30467
|
+
const application = opts.application ? createApplicationFetch(opts.application, runtime) : void 0;
|
|
30154
30468
|
await runtime.serveListener(
|
|
30155
30469
|
registry2,
|
|
30156
30470
|
{
|