@rivetkit/supabase 2.3.19 → 2.3.21
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 +1252 -976
- package/dist/mod.mjs +1255 -979
- package/package.json +4 -4
package/dist/mod.js
CHANGED
|
@@ -335,6 +335,202 @@ __export(mod_exports, {
|
|
|
335
335
|
module.exports = __toCommonJS(mod_exports);
|
|
336
336
|
var wasmBindings = __toESM(require("@rivetkit/rivetkit-wasm"));
|
|
337
337
|
|
|
338
|
+
// ../rivetkit/dist/tsup/chunk-P2OFXH4G.js
|
|
339
|
+
var INTERNAL_ERROR_CODE = "internal_error";
|
|
340
|
+
var INTERNAL_ERROR_DESCRIPTION = "An internal error occurred";
|
|
341
|
+
var USER_ERROR_CODE = "user_error";
|
|
342
|
+
var BRIDGE_RIVET_ERROR_PREFIX = "__RIVET_ERROR_JSON__:";
|
|
343
|
+
function looksLikeRivetErrorOptions(value) {
|
|
344
|
+
return typeof value === "object" && value !== null && ("public" in value || "metadata" in value || "rayId" in value || "statusCode" in value || "actor" in value || "cause" in value);
|
|
345
|
+
}
|
|
346
|
+
function isTypedErrorTag(value) {
|
|
347
|
+
return value === "ActorError" || value === "RivetError";
|
|
348
|
+
}
|
|
349
|
+
function errorMessage(error46, fallback = String(error46)) {
|
|
350
|
+
if (error46 && typeof error46 === "object" && "message" in error46 && typeof error46.message === "string") {
|
|
351
|
+
return error46.message;
|
|
352
|
+
}
|
|
353
|
+
return fallback;
|
|
354
|
+
}
|
|
355
|
+
function isRivetErrorLike(error46) {
|
|
356
|
+
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));
|
|
357
|
+
}
|
|
358
|
+
function isActorAbortedError(error46) {
|
|
359
|
+
return isRivetErrorLike(error46) && error46.group === "actor" && error46.code === "aborted";
|
|
360
|
+
}
|
|
361
|
+
function isActorSpecifier(value) {
|
|
362
|
+
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");
|
|
363
|
+
}
|
|
364
|
+
var RivetError = class extends Error {
|
|
365
|
+
__type = "RivetError";
|
|
366
|
+
public;
|
|
367
|
+
metadata;
|
|
368
|
+
rayId;
|
|
369
|
+
statusCode;
|
|
370
|
+
actor;
|
|
371
|
+
group;
|
|
372
|
+
code;
|
|
373
|
+
static isRivetError(error46) {
|
|
374
|
+
return isRivetErrorLike(error46);
|
|
375
|
+
}
|
|
376
|
+
static isActorError(error46) {
|
|
377
|
+
return isRivetErrorLike(error46);
|
|
378
|
+
}
|
|
379
|
+
constructor(group, code, message, options) {
|
|
380
|
+
const normalized = looksLikeRivetErrorOptions(options) ? options : { metadata: options };
|
|
381
|
+
super(message, { cause: normalized.cause });
|
|
382
|
+
this.name = "RivetError";
|
|
383
|
+
this.group = group;
|
|
384
|
+
this.code = code;
|
|
385
|
+
this.public = normalized.public ?? false;
|
|
386
|
+
this.metadata = normalized.metadata;
|
|
387
|
+
this.rayId = normalized.rayId ?? void 0;
|
|
388
|
+
this.statusCode = normalized.statusCode ?? (this.public ? 400 : 500);
|
|
389
|
+
this.actor = normalized.actor;
|
|
390
|
+
}
|
|
391
|
+
toString() {
|
|
392
|
+
return this.message;
|
|
393
|
+
}
|
|
394
|
+
};
|
|
395
|
+
var UserError = class extends RivetError {
|
|
396
|
+
constructor(message, options) {
|
|
397
|
+
super("user", (options == null ? void 0 : options.code) ?? USER_ERROR_CODE, message, {
|
|
398
|
+
public: true,
|
|
399
|
+
metadata: options == null ? void 0 : options.metadata,
|
|
400
|
+
cause: options == null ? void 0 : options.cause
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
};
|
|
404
|
+
function toRivetError(error46, fallback) {
|
|
405
|
+
if (typeof error46 === "string") {
|
|
406
|
+
const bridged = decodeBridgeRivetError(error46);
|
|
407
|
+
if (bridged) {
|
|
408
|
+
return bridged;
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
if (error46 instanceof Error) {
|
|
412
|
+
const bridged = decodeBridgeRivetError(error46.message);
|
|
413
|
+
if (bridged) {
|
|
414
|
+
return bridged;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
if (isRivetErrorLike(error46)) {
|
|
418
|
+
return new RivetError(error46.group, error46.code, error46.message, {
|
|
419
|
+
public: error46.public,
|
|
420
|
+
statusCode: error46.statusCode,
|
|
421
|
+
metadata: error46.metadata,
|
|
422
|
+
rayId: error46.rayId,
|
|
423
|
+
actor: error46.actor,
|
|
424
|
+
cause: error46 instanceof Error ? error46.cause : void 0
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
return new RivetError(
|
|
428
|
+
(fallback == null ? void 0 : fallback.group) ?? "actor",
|
|
429
|
+
(fallback == null ? void 0 : fallback.code) ?? INTERNAL_ERROR_CODE,
|
|
430
|
+
errorMessage(error46, (fallback == null ? void 0 : fallback.message) ?? "Unknown error"),
|
|
431
|
+
{
|
|
432
|
+
public: fallback == null ? void 0 : fallback.public,
|
|
433
|
+
statusCode: fallback == null ? void 0 : fallback.statusCode,
|
|
434
|
+
metadata: fallback == null ? void 0 : fallback.metadata,
|
|
435
|
+
rayId: fallback == null ? void 0 : fallback.rayId,
|
|
436
|
+
actor: fallback == null ? void 0 : fallback.actor,
|
|
437
|
+
cause: error46 instanceof Error ? error46 : void 0
|
|
438
|
+
}
|
|
439
|
+
);
|
|
440
|
+
}
|
|
441
|
+
function encodeBridgeRivetError(error46) {
|
|
442
|
+
return `${BRIDGE_RIVET_ERROR_PREFIX}${JSON.stringify({
|
|
443
|
+
group: error46.group,
|
|
444
|
+
code: error46.code,
|
|
445
|
+
message: error46.message,
|
|
446
|
+
metadata: error46.metadata,
|
|
447
|
+
rayId: error46.rayId,
|
|
448
|
+
public: error46.public,
|
|
449
|
+
statusCode: error46.statusCode,
|
|
450
|
+
actor: error46.actor
|
|
451
|
+
})}`;
|
|
452
|
+
}
|
|
453
|
+
function encodeErrorForBridge(error46) {
|
|
454
|
+
if (isCanonicalStructuredRivetError(error46)) {
|
|
455
|
+
return encodeBridgeRivetError(error46);
|
|
456
|
+
}
|
|
457
|
+
return String(error46);
|
|
458
|
+
}
|
|
459
|
+
function isCanonicalStructuredRivetError(error46) {
|
|
460
|
+
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";
|
|
461
|
+
}
|
|
462
|
+
function decodeBridgeRivetErrorPayload(value) {
|
|
463
|
+
if (!value.startsWith(BRIDGE_RIVET_ERROR_PREFIX)) {
|
|
464
|
+
return void 0;
|
|
465
|
+
}
|
|
466
|
+
try {
|
|
467
|
+
const raw = JSON.parse(
|
|
468
|
+
value.slice(BRIDGE_RIVET_ERROR_PREFIX.length)
|
|
469
|
+
);
|
|
470
|
+
const payload = {
|
|
471
|
+
...raw,
|
|
472
|
+
rayId: raw.rayId ?? void 0
|
|
473
|
+
};
|
|
474
|
+
if (!isRivetErrorLike(payload)) {
|
|
475
|
+
return void 0;
|
|
476
|
+
}
|
|
477
|
+
if (payload.actor !== void 0 && payload.actor !== null && !isActorSpecifier(payload.actor)) {
|
|
478
|
+
return void 0;
|
|
479
|
+
}
|
|
480
|
+
return payload;
|
|
481
|
+
} catch {
|
|
482
|
+
return void 0;
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
function decodeBridgeRivetError(value) {
|
|
486
|
+
const payload = decodeBridgeRivetErrorPayload(value);
|
|
487
|
+
if (!payload) {
|
|
488
|
+
return void 0;
|
|
489
|
+
}
|
|
490
|
+
return new RivetError(payload.group, payload.code, payload.message, {
|
|
491
|
+
metadata: payload.metadata,
|
|
492
|
+
rayId: payload.rayId,
|
|
493
|
+
public: payload.public,
|
|
494
|
+
statusCode: payload.statusCode,
|
|
495
|
+
actor: payload.actor ?? void 0
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
function invalidRequest(error46) {
|
|
499
|
+
return new RivetError(
|
|
500
|
+
"request",
|
|
501
|
+
"invalid",
|
|
502
|
+
`Invalid request: ${errorMessage(error46, String(error46))}`,
|
|
503
|
+
{
|
|
504
|
+
public: true,
|
|
505
|
+
cause: error46 instanceof Error ? error46 : void 0
|
|
506
|
+
}
|
|
507
|
+
);
|
|
508
|
+
}
|
|
509
|
+
function actorNotFound(identifier) {
|
|
510
|
+
return new RivetError(
|
|
511
|
+
"actor",
|
|
512
|
+
"not_found",
|
|
513
|
+
identifier ? `Actor not found: ${identifier} (https://www.rivet.dev/docs/clients/javascript)` : "Actor not found (https://www.rivet.dev/docs/clients/javascript)",
|
|
514
|
+
{ public: true }
|
|
515
|
+
);
|
|
516
|
+
}
|
|
517
|
+
function forbiddenError() {
|
|
518
|
+
return new RivetError("auth", "forbidden", "Forbidden", {
|
|
519
|
+
public: true,
|
|
520
|
+
statusCode: 403
|
|
521
|
+
});
|
|
522
|
+
}
|
|
523
|
+
function unsupportedFeature(feature) {
|
|
524
|
+
return new RivetError(
|
|
525
|
+
"feature",
|
|
526
|
+
"unsupported",
|
|
527
|
+
`Unsupported feature: ${feature}`
|
|
528
|
+
);
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
// ../rivetkit/dist/tsup/chunk-RGIZNZYO.js
|
|
532
|
+
var import_pino = require("pino");
|
|
533
|
+
|
|
338
534
|
// ../../../node_modules/.pnpm/zod@4.1.13/node_modules/zod/v4/classic/external.js
|
|
339
535
|
var external_exports = {};
|
|
340
536
|
__export(external_exports, {
|
|
@@ -13005,836 +13201,178 @@ var classic_default = external_exports;
|
|
|
13005
13201
|
// ../../../node_modules/.pnpm/zod@4.1.13/node_modules/zod/v4/index.js
|
|
13006
13202
|
var v4_default = classic_default;
|
|
13007
13203
|
|
|
13008
|
-
// ../rivetkit/dist/tsup/chunk-
|
|
13009
|
-
|
|
13010
|
-
|
|
13011
|
-
|
|
13012
|
-
|
|
13204
|
+
// ../rivetkit/dist/tsup/chunk-RGIZNZYO.js
|
|
13205
|
+
var cbor = __toESM(require("cbor-x"), 1);
|
|
13206
|
+
var import_invariant = __toESM(require_invariant(), 1);
|
|
13207
|
+
var getRivetEngine = () => getEnvUniversal("RIVET_ENGINE");
|
|
13208
|
+
var getRivetEndpoint = () => getEnvUniversal("RIVET_ENDPOINT");
|
|
13209
|
+
var getRivetToken = () => getEnvUniversal("RIVET_TOKEN");
|
|
13210
|
+
var getRivetNamespace = () => getEnvUniversal("RIVET_NAMESPACE");
|
|
13211
|
+
var getRivetPool = () => getEnvUniversal("RIVET_POOL");
|
|
13212
|
+
var getRivetTotalSlots = () => {
|
|
13213
|
+
const value = getEnvUniversal("RIVET_TOTAL_SLOTS");
|
|
13214
|
+
return value !== void 0 ? parseInt(value, 10) : void 0;
|
|
13215
|
+
};
|
|
13216
|
+
var getRivetRunEngine = () => getEnvUniversal("RIVET_RUN_ENGINE") === "1";
|
|
13217
|
+
var getRivetRunEngineHost = () => getEnvUniversal("RIVET_RUN_ENGINE_HOST");
|
|
13218
|
+
var getRivetRunEnginePort = () => {
|
|
13219
|
+
const value = getEnvUniversal("RIVET_RUN_ENGINE_PORT");
|
|
13220
|
+
return value !== void 0 ? parseInt(value, 10) : void 0;
|
|
13221
|
+
};
|
|
13222
|
+
var getRivetRunEngineVersion = () => getEnvUniversal("RIVET_RUN_ENGINE_VERSION");
|
|
13223
|
+
var getRivetRunServices = () => {
|
|
13224
|
+
const value = getEnvUniversal("RIVET_RUN_SERVICES");
|
|
13225
|
+
return value === void 0 ? void 0 : value === "1";
|
|
13226
|
+
};
|
|
13227
|
+
var getRivetEnvoyVersion = () => {
|
|
13228
|
+
const value = getEnvUniversal("RIVET_ENVOY_VERSION");
|
|
13229
|
+
return value !== void 0 ? parseInt(value, 10) : void 0;
|
|
13230
|
+
};
|
|
13231
|
+
var getRivetPublicEndpoint = () => getEnvUniversal("RIVET_PUBLIC_ENDPOINT");
|
|
13232
|
+
var getRivetPublicToken = () => getEnvUniversal("RIVET_PUBLIC_TOKEN");
|
|
13233
|
+
var getRivetkitRuntime = () => getEnvUniversal("RIVETKIT_RUNTIME");
|
|
13234
|
+
var getRivetkitRuntimeMode = () => {
|
|
13235
|
+
const value = getEnvUniversal("RIVETKIT_RUNTIME_MODE");
|
|
13236
|
+
if (value === void 0) return "envoy";
|
|
13237
|
+
if (value === "envoy" || value === "serverless") return value;
|
|
13238
|
+
throw new Error(
|
|
13239
|
+
`RIVETKIT_RUNTIME_MODE env var must be "envoy" or "serverless"; got "${value}"`
|
|
13240
|
+
);
|
|
13241
|
+
};
|
|
13242
|
+
var getRivetkitPublicDir = () => {
|
|
13243
|
+
const value = getEnvUniversal("RIVETKIT_PUBLIC_DIR");
|
|
13244
|
+
return value === void 0 || value === "" ? void 0 : value;
|
|
13245
|
+
};
|
|
13246
|
+
function parsePortEnv(raw) {
|
|
13247
|
+
if (raw === void 0 || raw === "") return void 0;
|
|
13248
|
+
const parsed = Number.parseInt(raw, 10);
|
|
13249
|
+
if (!Number.isFinite(parsed) || parsed < 1 || parsed > 65535 || String(parsed) !== raw.trim()) {
|
|
13250
|
+
throw new Error(
|
|
13251
|
+
`RIVET_PORT env var must be an integer between 1 and 65535; got "${raw}"`
|
|
13252
|
+
);
|
|
13013
13253
|
}
|
|
13014
|
-
return
|
|
13254
|
+
return parsed;
|
|
13015
13255
|
}
|
|
13016
|
-
|
|
13017
|
-
|
|
13018
|
-
|
|
13019
|
-
|
|
13020
|
-
|
|
13021
|
-
|
|
13022
|
-
|
|
13023
|
-
|
|
13024
|
-
|
|
13025
|
-
|
|
13026
|
-
|
|
13027
|
-
|
|
13028
|
-
|
|
13256
|
+
var getLogLevel = () => getEnvUniversal("RIVET_LOG_LEVEL") ?? getEnvUniversal("LOG_LEVEL");
|
|
13257
|
+
var getLogTarget = () => getEnvUniversal("RIVET_LOG_TARGET") === "1";
|
|
13258
|
+
var getLogTimestamp = () => getEnvUniversal("RIVET_LOG_TIMESTAMP") === "1";
|
|
13259
|
+
var getLogMessage = () => getEnvUniversal("RIVET_LOG_MESSAGE") === "1";
|
|
13260
|
+
var getLogErrorStack = () => getEnvUniversal("RIVET_LOG_ERROR_STACK") === "1";
|
|
13261
|
+
var getNodeEnv = () => getEnvUniversal("NODE_ENV");
|
|
13262
|
+
var getNextPhase = () => getEnvUniversal("NEXT_PHASE");
|
|
13263
|
+
var isDev = () => getNodeEnv() !== "production";
|
|
13264
|
+
function assertUnreachable(x) {
|
|
13265
|
+
throw new Error(`Unreachable case: ${x}`);
|
|
13266
|
+
}
|
|
13267
|
+
function deconstructError(error46, exposeInternalError = false) {
|
|
13268
|
+
let statusCode;
|
|
13269
|
+
let public_;
|
|
13270
|
+
let group;
|
|
13271
|
+
let code;
|
|
13272
|
+
let message;
|
|
13273
|
+
let metadata;
|
|
13274
|
+
let rayId;
|
|
13275
|
+
let actor2;
|
|
13276
|
+
if (isCanonicalStructuredRivetError(error46)) {
|
|
13277
|
+
statusCode = typeof error46.statusCode === "number" ? error46.statusCode : error46.public ? 400 : 500;
|
|
13278
|
+
public_ = error46.public ?? false;
|
|
13279
|
+
group = error46.group;
|
|
13280
|
+
code = error46.code;
|
|
13281
|
+
message = error46.message;
|
|
13282
|
+
metadata = error46.metadata;
|
|
13283
|
+
rayId = error46.rayId;
|
|
13284
|
+
actor2 = error46.actor;
|
|
13285
|
+
} else if (RivetError.isActorError(error46) && error46.public) {
|
|
13286
|
+
statusCode = "statusCode" in error46 && error46.statusCode ? error46.statusCode : 400;
|
|
13287
|
+
public_ = true;
|
|
13288
|
+
group = error46.group;
|
|
13289
|
+
code = error46.code;
|
|
13290
|
+
message = getErrorMessage(error46);
|
|
13291
|
+
metadata = error46.metadata;
|
|
13292
|
+
rayId = error46.rayId;
|
|
13293
|
+
actor2 = error46.actor;
|
|
13294
|
+
} else if (exposeInternalError) {
|
|
13295
|
+
if (RivetError.isActorError(error46)) {
|
|
13296
|
+
statusCode = 500;
|
|
13297
|
+
public_ = false;
|
|
13298
|
+
group = error46.group;
|
|
13299
|
+
code = error46.code;
|
|
13300
|
+
message = getErrorMessage(error46);
|
|
13301
|
+
metadata = error46.metadata;
|
|
13302
|
+
rayId = error46.rayId;
|
|
13303
|
+
actor2 = error46.actor;
|
|
13304
|
+
} else {
|
|
13305
|
+
statusCode = 500;
|
|
13306
|
+
public_ = false;
|
|
13307
|
+
group = "rivetkit";
|
|
13308
|
+
code = INTERNAL_ERROR_CODE;
|
|
13309
|
+
message = getErrorMessage(error46);
|
|
13029
13310
|
}
|
|
13030
|
-
|
|
13031
|
-
|
|
13032
|
-
|
|
13311
|
+
} else {
|
|
13312
|
+
statusCode = 500;
|
|
13313
|
+
public_ = false;
|
|
13314
|
+
group = "rivetkit";
|
|
13315
|
+
code = INTERNAL_ERROR_CODE;
|
|
13316
|
+
message = INTERNAL_ERROR_DESCRIPTION;
|
|
13317
|
+
if (RivetError.isActorError(error46)) {
|
|
13318
|
+
actor2 = error46.actor;
|
|
13033
13319
|
}
|
|
13320
|
+
metadata = {
|
|
13321
|
+
//url: `https://dashboard.rivet.dev/projects/${actorMetadata.project.slug}/environments/${actorMetadata.environment.slug}/actors?actorId=${actorMetadata.actor.id}`,
|
|
13322
|
+
};
|
|
13034
13323
|
}
|
|
13035
|
-
return
|
|
13036
|
-
|
|
13037
|
-
|
|
13038
|
-
|
|
13039
|
-
|
|
13040
|
-
|
|
13041
|
-
|
|
13324
|
+
return {
|
|
13325
|
+
__type: "ActorError",
|
|
13326
|
+
statusCode,
|
|
13327
|
+
public: public_,
|
|
13328
|
+
group,
|
|
13329
|
+
code,
|
|
13330
|
+
message,
|
|
13331
|
+
metadata,
|
|
13332
|
+
rayId,
|
|
13333
|
+
actor: actor2
|
|
13334
|
+
};
|
|
13042
13335
|
}
|
|
13043
|
-
function
|
|
13044
|
-
if (
|
|
13045
|
-
|
|
13046
|
-
|
|
13047
|
-
|
|
13048
|
-
|
|
13049
|
-
|
|
13050
|
-
|
|
13051
|
-
if (typeof child === "function") {
|
|
13052
|
-
const name = childPath.join(".");
|
|
13053
|
-
if (names.has(name)) {
|
|
13054
|
-
throw new TypeError(
|
|
13055
|
-
`Multiple action definitions flatten to \`${name}\``
|
|
13056
|
-
);
|
|
13336
|
+
function stringifyError(error46) {
|
|
13337
|
+
if (error46 instanceof Error) {
|
|
13338
|
+
if (typeof process !== "undefined" && getLogErrorStack()) {
|
|
13339
|
+
let stack;
|
|
13340
|
+
try {
|
|
13341
|
+
stack = error46.stack;
|
|
13342
|
+
} catch {
|
|
13343
|
+
stack = void 0;
|
|
13057
13344
|
}
|
|
13058
|
-
|
|
13059
|
-
|
|
13060
|
-
name,
|
|
13061
|
-
path: childPath,
|
|
13062
|
-
handler: child
|
|
13063
|
-
});
|
|
13345
|
+
return `${error46.name}: ${error46.message}${stack ? `
|
|
13346
|
+
${stack}` : ""}`;
|
|
13064
13347
|
} else {
|
|
13065
|
-
|
|
13348
|
+
return `${error46.name}: ${error46.message}`;
|
|
13066
13349
|
}
|
|
13067
|
-
}
|
|
13068
|
-
|
|
13069
|
-
|
|
13070
|
-
|
|
13071
|
-
|
|
13072
|
-
|
|
13073
|
-
return
|
|
13350
|
+
} else if (typeof error46 === "string") {
|
|
13351
|
+
return error46;
|
|
13352
|
+
} else if (typeof error46 === "object" && error46 !== null) {
|
|
13353
|
+
try {
|
|
13354
|
+
return `${JSON.stringify(error46)}`;
|
|
13355
|
+
} catch {
|
|
13356
|
+
return "[cannot stringify error]";
|
|
13074
13357
|
}
|
|
13075
|
-
|
|
13358
|
+
} else {
|
|
13359
|
+
return `Unknown error: ${getErrorMessage(error46)}`;
|
|
13076
13360
|
}
|
|
13077
|
-
return value;
|
|
13078
13361
|
}
|
|
13079
|
-
function
|
|
13080
|
-
if (typeof
|
|
13081
|
-
return
|
|
13362
|
+
function getErrorMessage(err) {
|
|
13363
|
+
if (err && typeof err === "object" && "message" in err && typeof err.message === "string") {
|
|
13364
|
+
return err.message;
|
|
13365
|
+
} else {
|
|
13366
|
+
return String(err);
|
|
13082
13367
|
}
|
|
13083
|
-
const prototype = Object.getPrototypeOf(value);
|
|
13084
|
-
return prototype === Object.prototype || prototype === null;
|
|
13085
13368
|
}
|
|
13086
|
-
function
|
|
13087
|
-
return
|
|
13088
|
-
}
|
|
13089
|
-
var DEFAULT_SLEEP_GRACE_PERIOD = 15e3;
|
|
13090
|
-
var ACTOR_CONTEXT_INTERNAL_SYMBOL = /* @__PURE__ */ Symbol(
|
|
13091
|
-
"rivetkit.actor_context_internal"
|
|
13092
|
-
);
|
|
13093
|
-
var RAW_STATE_SYMBOL = /* @__PURE__ */ Symbol("rivetkit.raw_state");
|
|
13094
|
-
var CONN_STATE_MANAGER_SYMBOL = /* @__PURE__ */ Symbol("rivetkit.conn_state_manager");
|
|
13095
|
-
var zFunction = () => external_exports.custom((val) => typeof val === "function");
|
|
13096
|
-
var zActionTree = external_exports.custom((value) => {
|
|
13097
|
-
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
13098
|
-
return false;
|
|
13099
|
-
}
|
|
13100
|
-
const prototype = Object.getPrototypeOf(value);
|
|
13101
|
-
return prototype === Object.prototype || prototype === null;
|
|
13102
|
-
}).superRefine((actions, ctx) => {
|
|
13103
|
-
try {
|
|
13104
|
-
flattenActionHandlers(actions);
|
|
13105
|
-
} catch (error46) {
|
|
13106
|
-
ctx.addIssue({
|
|
13107
|
-
code: "custom",
|
|
13108
|
-
message: error46 instanceof Error ? error46.message : "Invalid action definition"
|
|
13109
|
-
});
|
|
13110
|
-
}
|
|
13111
|
-
});
|
|
13112
|
-
var WorkflowInspectorConfigSchema = external_exports.object({
|
|
13113
|
-
getHistory: zFunction(),
|
|
13114
|
-
getState: zFunction().optional(),
|
|
13115
|
-
onHistoryUpdated: zFunction().optional(),
|
|
13116
|
-
replayFromStep: zFunction().optional()
|
|
13117
|
-
});
|
|
13118
|
-
var RunInspectorConfigSchema = external_exports.object({
|
|
13119
|
-
workflow: WorkflowInspectorConfigSchema.optional()
|
|
13120
|
-
}).optional();
|
|
13121
|
-
var BUILTIN_INSPECTOR_TAB_IDS = [
|
|
13122
|
-
"workflow",
|
|
13123
|
-
"database",
|
|
13124
|
-
"state",
|
|
13125
|
-
"queue",
|
|
13126
|
-
"schedules",
|
|
13127
|
-
"connections",
|
|
13128
|
-
"console"
|
|
13129
|
-
];
|
|
13130
|
-
var BuiltinInspectorTabIdSchema = external_exports.enum(BUILTIN_INSPECTOR_TAB_IDS);
|
|
13131
|
-
var CUSTOM_INSPECTOR_TAB_ID_RE = /^[A-Za-z0-9_-]+$/;
|
|
13132
|
-
var CustomInspectorTabEntrySchema = external_exports.object({
|
|
13133
|
-
id: external_exports.string().regex(
|
|
13134
|
-
CUSTOM_INSPECTOR_TAB_ID_RE,
|
|
13135
|
-
"inspector.tabs[].id must contain only letters, digits, underscore, or dash"
|
|
13136
|
-
),
|
|
13137
|
-
label: external_exports.string().min(1),
|
|
13138
|
-
source: external_exports.string().min(1),
|
|
13139
|
-
/**
|
|
13140
|
-
* Optional icon id. The dashboard maps strings to glyphs (see its
|
|
13141
|
-
* icon registry); unknown ids fall back to a generic icon.
|
|
13142
|
-
*/
|
|
13143
|
-
icon: external_exports.string().min(1).optional(),
|
|
13144
|
-
hidden: external_exports.literal(false).optional()
|
|
13145
|
-
}).strict();
|
|
13146
|
-
var HideInspectorTabEntrySchema = external_exports.object({
|
|
13147
|
-
id: BuiltinInspectorTabIdSchema,
|
|
13148
|
-
hidden: external_exports.literal(true)
|
|
13149
|
-
}).strict();
|
|
13150
|
-
var InspectorTabEntrySchema = external_exports.union([
|
|
13151
|
-
CustomInspectorTabEntrySchema,
|
|
13152
|
-
HideInspectorTabEntrySchema
|
|
13153
|
-
]);
|
|
13154
|
-
var ActorInspectorConfigSchema = external_exports.object({
|
|
13155
|
-
tabs: external_exports.array(InspectorTabEntrySchema).default(() => [])
|
|
13156
|
-
}).strict().refine(
|
|
13157
|
-
(data) => {
|
|
13158
|
-
const ids = data.tabs.map((t) => t.id);
|
|
13159
|
-
return new Set(ids).size === ids.length;
|
|
13160
|
-
},
|
|
13161
|
-
{ message: "Duplicate id in inspector.tabs", path: ["tabs"] }
|
|
13162
|
-
).refine(
|
|
13163
|
-
(data) => {
|
|
13164
|
-
const builtinSet = new Set(BUILTIN_INSPECTOR_TAB_IDS);
|
|
13165
|
-
return data.tabs.every(
|
|
13166
|
-
(t) => t.hidden === true || !builtinSet.has(t.id)
|
|
13167
|
-
);
|
|
13168
|
-
},
|
|
13169
|
-
{
|
|
13170
|
-
message: "Custom inspector tab id collides with a built-in (use hidden: true to hide a built-in)",
|
|
13171
|
-
path: ["tabs"]
|
|
13172
|
-
}
|
|
13173
|
-
);
|
|
13174
|
-
var RunConfigSchema = external_exports.object({
|
|
13175
|
-
/** Display name for the actor in the Inspector UI. */
|
|
13176
|
-
name: external_exports.string().optional(),
|
|
13177
|
-
/** Icon for the actor in the Inspector UI. Can be an emoji or FontAwesome icon name. */
|
|
13178
|
-
icon: external_exports.string().optional(),
|
|
13179
|
-
/** The run handler function. */
|
|
13180
|
-
run: zFunction(),
|
|
13181
|
-
/** Inspector integration for long-running run handlers. */
|
|
13182
|
-
inspector: RunInspectorConfigSchema.optional()
|
|
13183
|
-
});
|
|
13184
|
-
var RUN_FUNCTION_CONFIG_SYMBOL = /* @__PURE__ */ Symbol.for("rivetkit.run_function_config");
|
|
13185
|
-
function defineRunHandler(run, options) {
|
|
13186
|
-
if (options.inspectorKind === void 0 !== (options.createInspector === void 0)) {
|
|
13187
|
-
throw new TypeError(
|
|
13188
|
-
"defineRunHandler requires inspectorKind and createInspector together"
|
|
13189
|
-
);
|
|
13190
|
-
}
|
|
13191
|
-
Object.defineProperty(run, RUN_FUNCTION_CONFIG_SYMBOL, {
|
|
13192
|
-
configurable: false,
|
|
13193
|
-
enumerable: false,
|
|
13194
|
-
writable: false,
|
|
13195
|
-
value: {
|
|
13196
|
-
name: options.name,
|
|
13197
|
-
icon: options.icon,
|
|
13198
|
-
inspectorKind: options.inspectorKind,
|
|
13199
|
-
createInspector: options.createInspector
|
|
13200
|
-
}
|
|
13201
|
-
});
|
|
13202
|
-
return run;
|
|
13203
|
-
}
|
|
13204
|
-
function getRunInspectorKind(run) {
|
|
13205
|
-
var _a2;
|
|
13206
|
-
if (!run || typeof run !== "function") return void 0;
|
|
13207
|
-
return (_a2 = run[RUN_FUNCTION_CONFIG_SYMBOL]) == null ? void 0 : _a2.inspectorKind;
|
|
13208
|
-
}
|
|
13209
|
-
function createRunInspector(run, context2) {
|
|
13210
|
-
var _a2, _b;
|
|
13211
|
-
if (!run || typeof run !== "function") return void 0;
|
|
13212
|
-
return (_b = (_a2 = run[RUN_FUNCTION_CONFIG_SYMBOL]) == null ? void 0 : _a2.createInspector) == null ? void 0 : _b.call(_a2, context2);
|
|
13213
|
-
}
|
|
13214
|
-
var zRunHandler = external_exports.union([zFunction(), RunConfigSchema]).optional();
|
|
13215
|
-
function getRunFunction(run) {
|
|
13216
|
-
if (!run) return void 0;
|
|
13217
|
-
if (typeof run === "function") return run;
|
|
13218
|
-
return run.run;
|
|
13219
|
-
}
|
|
13220
|
-
function getRunMetadata(run) {
|
|
13221
|
-
if (!run) return {};
|
|
13222
|
-
if (typeof run === "function") {
|
|
13223
|
-
const config3 = run[RUN_FUNCTION_CONFIG_SYMBOL];
|
|
13224
|
-
if (!config3) return {};
|
|
13225
|
-
return { name: config3.name, icon: config3.icon };
|
|
13226
|
-
}
|
|
13227
|
-
return { name: run.name, icon: run.icon };
|
|
13228
|
-
}
|
|
13229
|
-
function getRunInspectorConfig(run, actor2) {
|
|
13230
|
-
if (!run) return void 0;
|
|
13231
|
-
if (typeof run === "function") {
|
|
13232
|
-
const config3 = run[RUN_FUNCTION_CONFIG_SYMBOL];
|
|
13233
|
-
return (config3 == null ? void 0 : config3.inspectorFactory) ? config3.inspectorFactory(actor2) : config3 == null ? void 0 : config3.inspector;
|
|
13234
|
-
}
|
|
13235
|
-
return run.inspector;
|
|
13236
|
-
}
|
|
13237
|
-
function hasRunInspectorConfig(run) {
|
|
13238
|
-
if (!run) return false;
|
|
13239
|
-
if (typeof run !== "function") return run.inspector !== void 0;
|
|
13240
|
-
const config3 = run[RUN_FUNCTION_CONFIG_SYMBOL];
|
|
13241
|
-
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;
|
|
13242
|
-
}
|
|
13243
|
-
function disposeRunInspector(run, actorId) {
|
|
13244
|
-
var _a2;
|
|
13245
|
-
if (!run || typeof run !== "function") {
|
|
13246
|
-
return;
|
|
13247
|
-
}
|
|
13248
|
-
const config3 = run[RUN_FUNCTION_CONFIG_SYMBOL];
|
|
13249
|
-
(_a2 = config3 == null ? void 0 : config3.disposeInspector) == null ? void 0 : _a2.call(config3, actorId);
|
|
13250
|
-
}
|
|
13251
|
-
var GlobalActorOptionsBaseSchema = external_exports.object({
|
|
13252
|
-
/** Display name for the actor in the Inspector UI. */
|
|
13253
|
-
name: external_exports.string().optional(),
|
|
13254
|
-
/** Icon for the actor in the Inspector UI. Can be an emoji or FontAwesome icon name. */
|
|
13255
|
-
icon: external_exports.string().optional(),
|
|
13256
|
-
/** Enables the experimental Actor Runtime Socket for this actor. */
|
|
13257
|
-
enableActorRuntimeSocket: external_exports.boolean().default(false),
|
|
13258
|
-
/**
|
|
13259
|
-
* Can hibernate WebSockets for onWebSocket.
|
|
13260
|
-
*
|
|
13261
|
-
* WebSockets using actions/events are hibernatable by default.
|
|
13262
|
-
*
|
|
13263
|
-
* @experimental
|
|
13264
|
-
**/
|
|
13265
|
-
canHibernateWebSocket: external_exports.union([external_exports.boolean(), zFunction()]).default(false)
|
|
13266
|
-
}).strict();
|
|
13267
|
-
var GlobalActorOptionsSchema = GlobalActorOptionsBaseSchema.prefault(
|
|
13268
|
-
() => ({})
|
|
13269
|
-
);
|
|
13270
|
-
var InstanceActorOptionsBaseSchema = external_exports.object({
|
|
13271
|
-
createVarsTimeout: external_exports.number().positive().default(5e3),
|
|
13272
|
-
createConnStateTimeout: external_exports.number().positive().default(5e3),
|
|
13273
|
-
onBeforeConnectTimeout: external_exports.number().positive().default(5e3),
|
|
13274
|
-
onConnectTimeout: external_exports.number().positive().default(5e3),
|
|
13275
|
-
onMigrateTimeout: external_exports.number().positive().default(3e4),
|
|
13276
|
-
sleepGracePeriod: external_exports.number().positive().default(DEFAULT_SLEEP_GRACE_PERIOD),
|
|
13277
|
-
/** @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. */
|
|
13278
|
-
onDestroyTimeout: external_exports.number().positive().optional(),
|
|
13279
|
-
/** @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. */
|
|
13280
|
-
waitUntilTimeout: external_exports.number().positive().optional(),
|
|
13281
|
-
stateSaveInterval: external_exports.number().positive().default(1e3),
|
|
13282
|
-
actionTimeout: external_exports.number().positive().default(6e4),
|
|
13283
|
-
connectionLivenessTimeout: external_exports.number().positive().default(2500),
|
|
13284
|
-
connectionLivenessInterval: external_exports.number().positive().default(5e3),
|
|
13285
|
-
/** @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. */
|
|
13286
|
-
noSleep: external_exports.boolean().default(false),
|
|
13287
|
-
sleepTimeout: external_exports.number().positive().default(3e4),
|
|
13288
|
-
maxQueueSize: external_exports.number().positive().default(1e3),
|
|
13289
|
-
/** Maximum pending one-shot and recurring schedules. */
|
|
13290
|
-
maxSchedules: external_exports.number().int().nonnegative().default(1e3),
|
|
13291
|
-
maxQueueMessageSize: external_exports.number().positive().default(64 * 1024),
|
|
13292
|
-
/** @deprecated Internal storage moved to SQLite and no longer uses KV preloading, so this option is ignored. Will be removed in 2.2.0. */
|
|
13293
|
-
preloadMaxWorkflowBytes: external_exports.number().nonnegative().optional(),
|
|
13294
|
-
/** @deprecated Internal storage moved to SQLite and no longer uses KV preloading, so this option is ignored. Will be removed in 2.2.0. */
|
|
13295
|
-
preloadMaxConnectionsBytes: external_exports.number().nonnegative().optional()
|
|
13296
|
-
}).strict();
|
|
13297
|
-
var InstanceActorOptionsSchema = InstanceActorOptionsBaseSchema.prefault(() => ({}));
|
|
13298
|
-
var ActorOptionsSchema = GlobalActorOptionsBaseSchema.extend(
|
|
13299
|
-
InstanceActorOptionsBaseSchema.shape
|
|
13300
|
-
).strict().prefault(() => ({}));
|
|
13301
|
-
var ActorConfigSchema = external_exports.object({
|
|
13302
|
-
onCreate: zFunction().optional(),
|
|
13303
|
-
onDestroy: zFunction().optional(),
|
|
13304
|
-
onMigrate: zFunction().optional(),
|
|
13305
|
-
onWake: zFunction().optional(),
|
|
13306
|
-
onSleep: zFunction().optional(),
|
|
13307
|
-
run: zRunHandler,
|
|
13308
|
-
onStateChange: zFunction().optional(),
|
|
13309
|
-
onBeforeConnect: zFunction().optional(),
|
|
13310
|
-
onConnect: zFunction().optional(),
|
|
13311
|
-
onDisconnect: zFunction().optional(),
|
|
13312
|
-
onBeforeActionResponse: zFunction().optional(),
|
|
13313
|
-
onRequest: zFunction().optional(),
|
|
13314
|
-
onWebSocket: zFunction().optional(),
|
|
13315
|
-
actions: zActionTree.default(() => ({})),
|
|
13316
|
-
actionInputSchemas: external_exports.record(external_exports.string(), external_exports.any()).optional(),
|
|
13317
|
-
connParamsSchema: external_exports.any().optional(),
|
|
13318
|
-
events: external_exports.record(external_exports.string(), external_exports.any()).optional(),
|
|
13319
|
-
queues: external_exports.record(external_exports.string(), external_exports.any()).optional(),
|
|
13320
|
-
state: external_exports.any().optional(),
|
|
13321
|
-
createState: zFunction().optional(),
|
|
13322
|
-
connState: external_exports.any().optional(),
|
|
13323
|
-
createConnState: zFunction().optional(),
|
|
13324
|
-
vars: external_exports.any().optional(),
|
|
13325
|
-
db: external_exports.any().optional(),
|
|
13326
|
-
createVars: zFunction().optional(),
|
|
13327
|
-
options: ActorOptionsSchema,
|
|
13328
|
-
inspector: ActorInspectorConfigSchema.optional()
|
|
13329
|
-
}).strict().refine(
|
|
13330
|
-
(data) => !(data.state !== void 0 && data.createState !== void 0),
|
|
13331
|
-
{
|
|
13332
|
-
message: "Cannot define both 'state' and 'createState'",
|
|
13333
|
-
path: ["state"]
|
|
13334
|
-
}
|
|
13335
|
-
).refine(
|
|
13336
|
-
(data) => !(data.connState !== void 0 && data.createConnState !== void 0),
|
|
13337
|
-
{
|
|
13338
|
-
message: "Cannot define both 'connState' and 'createConnState'",
|
|
13339
|
-
path: ["connState"]
|
|
13340
|
-
}
|
|
13341
|
-
).refine(
|
|
13342
|
-
(data) => !(data.vars !== void 0 && data.createVars !== void 0),
|
|
13343
|
-
{
|
|
13344
|
-
message: "Cannot define both 'vars' and 'createVars'",
|
|
13345
|
-
path: ["vars"]
|
|
13346
|
-
}
|
|
13347
|
-
);
|
|
13348
|
-
var DocActorOptionsSchema = external_exports.object({
|
|
13349
|
-
name: external_exports.string().optional().describe("Display name for the actor in the Inspector UI."),
|
|
13350
|
-
icon: external_exports.string().optional().describe(
|
|
13351
|
-
"Icon for the actor in the Inspector UI. Can be an emoji (e.g., '\u{1F680}') or FontAwesome icon name (e.g., 'rocket')."
|
|
13352
|
-
),
|
|
13353
|
-
enableActorRuntimeSocket: external_exports.boolean().optional().describe(
|
|
13354
|
-
"Enables the experimental Actor Runtime Socket for this actor. Default: false"
|
|
13355
|
-
),
|
|
13356
|
-
createVarsTimeout: external_exports.number().optional().describe("Timeout in ms for createVars handler. Default: 5000"),
|
|
13357
|
-
createConnStateTimeout: external_exports.number().optional().describe(
|
|
13358
|
-
"Timeout in ms for createConnState handler. Default: 5000"
|
|
13359
|
-
),
|
|
13360
|
-
onMigrateTimeout: external_exports.number().optional().describe("Timeout in ms for onMigrate handler. Default: 30000"),
|
|
13361
|
-
onBeforeConnectTimeout: external_exports.number().optional().describe(
|
|
13362
|
-
"Timeout in ms for onBeforeConnect handler. Default: 5000"
|
|
13363
|
-
),
|
|
13364
|
-
onConnectTimeout: external_exports.number().optional().describe("Timeout in ms for onConnect handler. Default: 5000"),
|
|
13365
|
-
sleepGracePeriod: external_exports.number().optional().describe(
|
|
13366
|
-
`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}.`
|
|
13367
|
-
),
|
|
13368
|
-
onDestroyTimeout: external_exports.number().optional().describe(
|
|
13369
|
-
"Deprecated. Folded into sleepGracePeriod, which now bounds the entire graceful shutdown window for both sleep and destroy. Will be removed in 2.2.0."
|
|
13370
|
-
),
|
|
13371
|
-
waitUntilTimeout: external_exports.number().optional().describe(
|
|
13372
|
-
"Deprecated. Folded into sleepGracePeriod, which now bounds the entire graceful shutdown window for both sleep and destroy. Will be removed in 2.2.0."
|
|
13373
|
-
),
|
|
13374
|
-
stateSaveInterval: external_exports.number().optional().describe(
|
|
13375
|
-
"Interval in ms between automatic state saves. Default: 1000"
|
|
13376
|
-
),
|
|
13377
|
-
actionTimeout: external_exports.number().optional().describe("Timeout in ms for action handlers. Default: 60000"),
|
|
13378
|
-
connectionLivenessTimeout: external_exports.number().optional().describe(
|
|
13379
|
-
"Timeout in ms for connection liveness checks. Default: 2500"
|
|
13380
|
-
),
|
|
13381
|
-
connectionLivenessInterval: external_exports.number().optional().describe(
|
|
13382
|
-
"Interval in ms between connection liveness checks. Default: 5000"
|
|
13383
|
-
),
|
|
13384
|
-
noSleep: external_exports.boolean().optional().describe(
|
|
13385
|
-
"Deprecated. If true, the actor will never sleep. Use c.keepAwake(promise) to scope keep-awake to a specific operation instead. Default: false"
|
|
13386
|
-
),
|
|
13387
|
-
sleepTimeout: external_exports.number().optional().describe(
|
|
13388
|
-
"Time in ms of inactivity before the actor sleeps. Default: 30000"
|
|
13389
|
-
),
|
|
13390
|
-
maxQueueSize: external_exports.number().optional().describe(
|
|
13391
|
-
"Maximum number of queue messages before rejecting new messages. Default: 1000"
|
|
13392
|
-
),
|
|
13393
|
-
maxSchedules: external_exports.number().int().nonnegative().optional().describe(
|
|
13394
|
-
"Maximum pending one-shot and recurring schedules before rejecting new schedules. Default: 1000"
|
|
13395
|
-
),
|
|
13396
|
-
maxQueueMessageSize: external_exports.number().optional().describe(
|
|
13397
|
-
"Maximum size of each queue message in bytes. Default: 65536"
|
|
13398
|
-
),
|
|
13399
|
-
canHibernateWebSocket: external_exports.boolean().optional().describe(
|
|
13400
|
-
"Whether WebSockets using onWebSocket can be hibernated. WebSockets using actions/events are hibernatable by default. Default: false"
|
|
13401
|
-
)
|
|
13402
|
-
}).describe("Actor options for timeouts and behavior configuration.");
|
|
13403
|
-
var DocActorConfigSchema = external_exports.object({
|
|
13404
|
-
state: external_exports.unknown().optional().describe(
|
|
13405
|
-
"Initial state value for the actor. Cannot be used with createState."
|
|
13406
|
-
),
|
|
13407
|
-
createState: external_exports.unknown().optional().describe(
|
|
13408
|
-
"Function to create initial state. Receives context and input. Cannot be used with state."
|
|
13409
|
-
),
|
|
13410
|
-
connState: external_exports.unknown().optional().describe(
|
|
13411
|
-
"Initial connection state value. Cannot be used with createConnState."
|
|
13412
|
-
),
|
|
13413
|
-
createConnState: external_exports.unknown().optional().describe(
|
|
13414
|
-
"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."
|
|
13415
|
-
),
|
|
13416
|
-
vars: external_exports.unknown().optional().describe(
|
|
13417
|
-
"Initial ephemeral variables value. Cannot be used with createVars."
|
|
13418
|
-
),
|
|
13419
|
-
createVars: external_exports.unknown().optional().describe(
|
|
13420
|
-
"Function to create ephemeral variables. Receives context and driver context. Cannot be used with vars."
|
|
13421
|
-
),
|
|
13422
|
-
db: external_exports.unknown().optional().describe("Database provider instance for the actor."),
|
|
13423
|
-
onCreate: external_exports.unknown().optional().describe(
|
|
13424
|
-
"Called when the actor is first initialized. Use to initialize state."
|
|
13425
|
-
),
|
|
13426
|
-
onDestroy: external_exports.unknown().optional().describe("Called when the actor is destroyed."),
|
|
13427
|
-
onMigrate: external_exports.unknown().optional().describe(
|
|
13428
|
-
"Called on every actor start after persisted state loads and before onWake. Use for repeatable schema migrations."
|
|
13429
|
-
),
|
|
13430
|
-
onWake: external_exports.unknown().optional().describe(
|
|
13431
|
-
"Called when the actor wakes up and is ready to receive connections and actions."
|
|
13432
|
-
),
|
|
13433
|
-
onSleep: external_exports.unknown().optional().describe(
|
|
13434
|
-
"Called when the actor is stopping or sleeping. Use to clean up resources."
|
|
13435
|
-
),
|
|
13436
|
-
run: external_exports.unknown().optional().describe(
|
|
13437
|
-
"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."
|
|
13438
|
-
),
|
|
13439
|
-
onStateChange: external_exports.unknown().optional().describe(
|
|
13440
|
-
"Called when the actor's state changes. State changes within this hook won't trigger recursion."
|
|
13441
|
-
),
|
|
13442
|
-
onBeforeConnect: external_exports.unknown().optional().describe(
|
|
13443
|
-
"Called before a client connects. Throw an error to reject the connection. The pending connection is not visible in c.conns while this runs."
|
|
13444
|
-
),
|
|
13445
|
-
onConnect: external_exports.unknown().optional().describe(
|
|
13446
|
-
"Called when a client successfully connects. The connection is visible in c.conns before this runs."
|
|
13447
|
-
),
|
|
13448
|
-
onDisconnect: external_exports.unknown().optional().describe("Called when a client disconnects."),
|
|
13449
|
-
onBeforeActionResponse: external_exports.unknown().optional().describe(
|
|
13450
|
-
"Called before sending an action response. Use to transform output."
|
|
13451
|
-
),
|
|
13452
|
-
onRequest: external_exports.unknown().optional().describe(
|
|
13453
|
-
"Called for raw HTTP requests to /actors/{name}/http/* endpoints."
|
|
13454
|
-
),
|
|
13455
|
-
onWebSocket: external_exports.unknown().optional().describe(
|
|
13456
|
-
"Called for raw WebSocket connections to /actors/{name}/websocket/* endpoints."
|
|
13457
|
-
),
|
|
13458
|
-
actions: external_exports.record(external_exports.string(), external_exports.unknown()).optional().describe(
|
|
13459
|
-
"Tree of action names or nested groups to handler functions. Nested paths use dot-separated low-level action names. Defaults to an empty object."
|
|
13460
|
-
),
|
|
13461
|
-
actionInputSchemas: external_exports.record(external_exports.string(), external_exports.unknown()).optional().describe(
|
|
13462
|
-
"Optional schemas for validating action argument tuples in native runtimes. May mirror nested action groups or use dot-separated low-level action names."
|
|
13463
|
-
),
|
|
13464
|
-
connParamsSchema: external_exports.unknown().optional().describe(
|
|
13465
|
-
"Optional schema for validating connection params in native runtimes."
|
|
13466
|
-
),
|
|
13467
|
-
events: external_exports.record(external_exports.string(), external_exports.unknown()).optional().describe("Map of event names to schemas."),
|
|
13468
|
-
queues: external_exports.record(external_exports.string(), external_exports.unknown()).optional().describe("Map of queue names to schemas."),
|
|
13469
|
-
options: DocActorOptionsSchema.optional()
|
|
13470
|
-
}).describe("Actor configuration passed to the actor() function.");
|
|
13471
|
-
|
|
13472
|
-
// ../rivetkit/dist/tsup/chunk-P2OFXH4G.js
|
|
13473
|
-
var INTERNAL_ERROR_CODE = "internal_error";
|
|
13474
|
-
var INTERNAL_ERROR_DESCRIPTION = "An internal error occurred";
|
|
13475
|
-
var USER_ERROR_CODE = "user_error";
|
|
13476
|
-
var BRIDGE_RIVET_ERROR_PREFIX = "__RIVET_ERROR_JSON__:";
|
|
13477
|
-
function looksLikeRivetErrorOptions(value) {
|
|
13478
|
-
return typeof value === "object" && value !== null && ("public" in value || "metadata" in value || "rayId" in value || "statusCode" in value || "actor" in value || "cause" in value);
|
|
13479
|
-
}
|
|
13480
|
-
function isTypedErrorTag(value) {
|
|
13481
|
-
return value === "ActorError" || value === "RivetError";
|
|
13482
|
-
}
|
|
13483
|
-
function errorMessage(error46, fallback = String(error46)) {
|
|
13484
|
-
if (error46 && typeof error46 === "object" && "message" in error46 && typeof error46.message === "string") {
|
|
13485
|
-
return error46.message;
|
|
13486
|
-
}
|
|
13487
|
-
return fallback;
|
|
13488
|
-
}
|
|
13489
|
-
function isRivetErrorLike(error46) {
|
|
13490
|
-
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));
|
|
13491
|
-
}
|
|
13492
|
-
function isActorAbortedError(error46) {
|
|
13493
|
-
return isRivetErrorLike(error46) && error46.group === "actor" && error46.code === "aborted";
|
|
13494
|
-
}
|
|
13495
|
-
function isActorSpecifier(value) {
|
|
13496
|
-
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");
|
|
13497
|
-
}
|
|
13498
|
-
var RivetError = class extends Error {
|
|
13499
|
-
__type = "RivetError";
|
|
13500
|
-
public;
|
|
13501
|
-
metadata;
|
|
13502
|
-
rayId;
|
|
13503
|
-
statusCode;
|
|
13504
|
-
actor;
|
|
13505
|
-
group;
|
|
13506
|
-
code;
|
|
13507
|
-
static isRivetError(error46) {
|
|
13508
|
-
return isRivetErrorLike(error46);
|
|
13509
|
-
}
|
|
13510
|
-
static isActorError(error46) {
|
|
13511
|
-
return isRivetErrorLike(error46);
|
|
13512
|
-
}
|
|
13513
|
-
constructor(group, code, message, options) {
|
|
13514
|
-
const normalized = looksLikeRivetErrorOptions(options) ? options : { metadata: options };
|
|
13515
|
-
super(message, { cause: normalized.cause });
|
|
13516
|
-
this.name = "RivetError";
|
|
13517
|
-
this.group = group;
|
|
13518
|
-
this.code = code;
|
|
13519
|
-
this.public = normalized.public ?? false;
|
|
13520
|
-
this.metadata = normalized.metadata;
|
|
13521
|
-
this.rayId = normalized.rayId ?? void 0;
|
|
13522
|
-
this.statusCode = normalized.statusCode ?? (this.public ? 400 : 500);
|
|
13523
|
-
this.actor = normalized.actor;
|
|
13524
|
-
}
|
|
13525
|
-
toString() {
|
|
13526
|
-
return this.message;
|
|
13527
|
-
}
|
|
13528
|
-
};
|
|
13529
|
-
var UserError = class extends RivetError {
|
|
13530
|
-
constructor(message, options) {
|
|
13531
|
-
super("user", (options == null ? void 0 : options.code) ?? USER_ERROR_CODE, message, {
|
|
13532
|
-
public: true,
|
|
13533
|
-
metadata: options == null ? void 0 : options.metadata,
|
|
13534
|
-
cause: options == null ? void 0 : options.cause
|
|
13535
|
-
});
|
|
13536
|
-
}
|
|
13537
|
-
};
|
|
13538
|
-
function toRivetError(error46, fallback) {
|
|
13539
|
-
if (typeof error46 === "string") {
|
|
13540
|
-
const bridged = decodeBridgeRivetError(error46);
|
|
13541
|
-
if (bridged) {
|
|
13542
|
-
return bridged;
|
|
13543
|
-
}
|
|
13544
|
-
}
|
|
13545
|
-
if (error46 instanceof Error) {
|
|
13546
|
-
const bridged = decodeBridgeRivetError(error46.message);
|
|
13547
|
-
if (bridged) {
|
|
13548
|
-
return bridged;
|
|
13549
|
-
}
|
|
13550
|
-
}
|
|
13551
|
-
if (isRivetErrorLike(error46)) {
|
|
13552
|
-
return new RivetError(error46.group, error46.code, error46.message, {
|
|
13553
|
-
public: error46.public,
|
|
13554
|
-
statusCode: error46.statusCode,
|
|
13555
|
-
metadata: error46.metadata,
|
|
13556
|
-
rayId: error46.rayId,
|
|
13557
|
-
actor: error46.actor,
|
|
13558
|
-
cause: error46 instanceof Error ? error46.cause : void 0
|
|
13559
|
-
});
|
|
13560
|
-
}
|
|
13561
|
-
return new RivetError(
|
|
13562
|
-
(fallback == null ? void 0 : fallback.group) ?? "actor",
|
|
13563
|
-
(fallback == null ? void 0 : fallback.code) ?? INTERNAL_ERROR_CODE,
|
|
13564
|
-
errorMessage(error46, (fallback == null ? void 0 : fallback.message) ?? "Unknown error"),
|
|
13565
|
-
{
|
|
13566
|
-
public: fallback == null ? void 0 : fallback.public,
|
|
13567
|
-
statusCode: fallback == null ? void 0 : fallback.statusCode,
|
|
13568
|
-
metadata: fallback == null ? void 0 : fallback.metadata,
|
|
13569
|
-
rayId: fallback == null ? void 0 : fallback.rayId,
|
|
13570
|
-
actor: fallback == null ? void 0 : fallback.actor,
|
|
13571
|
-
cause: error46 instanceof Error ? error46 : void 0
|
|
13572
|
-
}
|
|
13573
|
-
);
|
|
13574
|
-
}
|
|
13575
|
-
function encodeBridgeRivetError(error46) {
|
|
13576
|
-
return `${BRIDGE_RIVET_ERROR_PREFIX}${JSON.stringify({
|
|
13577
|
-
group: error46.group,
|
|
13578
|
-
code: error46.code,
|
|
13579
|
-
message: error46.message,
|
|
13580
|
-
metadata: error46.metadata,
|
|
13581
|
-
rayId: error46.rayId,
|
|
13582
|
-
public: error46.public,
|
|
13583
|
-
statusCode: error46.statusCode,
|
|
13584
|
-
actor: error46.actor
|
|
13585
|
-
})}`;
|
|
13586
|
-
}
|
|
13587
|
-
function encodeErrorForBridge(error46) {
|
|
13588
|
-
if (isCanonicalStructuredRivetError(error46)) {
|
|
13589
|
-
return encodeBridgeRivetError(error46);
|
|
13590
|
-
}
|
|
13591
|
-
return String(error46);
|
|
13592
|
-
}
|
|
13593
|
-
function isCanonicalStructuredRivetError(error46) {
|
|
13594
|
-
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";
|
|
13595
|
-
}
|
|
13596
|
-
function decodeBridgeRivetErrorPayload(value) {
|
|
13597
|
-
if (!value.startsWith(BRIDGE_RIVET_ERROR_PREFIX)) {
|
|
13598
|
-
return void 0;
|
|
13599
|
-
}
|
|
13600
|
-
try {
|
|
13601
|
-
const raw = JSON.parse(
|
|
13602
|
-
value.slice(BRIDGE_RIVET_ERROR_PREFIX.length)
|
|
13603
|
-
);
|
|
13604
|
-
const payload = {
|
|
13605
|
-
...raw,
|
|
13606
|
-
rayId: raw.rayId ?? void 0
|
|
13607
|
-
};
|
|
13608
|
-
if (!isRivetErrorLike(payload)) {
|
|
13609
|
-
return void 0;
|
|
13610
|
-
}
|
|
13611
|
-
if (payload.actor !== void 0 && payload.actor !== null && !isActorSpecifier(payload.actor)) {
|
|
13612
|
-
return void 0;
|
|
13613
|
-
}
|
|
13614
|
-
return payload;
|
|
13615
|
-
} catch {
|
|
13616
|
-
return void 0;
|
|
13617
|
-
}
|
|
13618
|
-
}
|
|
13619
|
-
function decodeBridgeRivetError(value) {
|
|
13620
|
-
const payload = decodeBridgeRivetErrorPayload(value);
|
|
13621
|
-
if (!payload) {
|
|
13622
|
-
return void 0;
|
|
13623
|
-
}
|
|
13624
|
-
return new RivetError(payload.group, payload.code, payload.message, {
|
|
13625
|
-
metadata: payload.metadata,
|
|
13626
|
-
rayId: payload.rayId,
|
|
13627
|
-
public: payload.public,
|
|
13628
|
-
statusCode: payload.statusCode,
|
|
13629
|
-
actor: payload.actor ?? void 0
|
|
13630
|
-
});
|
|
13631
|
-
}
|
|
13632
|
-
function invalidRequest(error46) {
|
|
13633
|
-
return new RivetError(
|
|
13634
|
-
"request",
|
|
13635
|
-
"invalid",
|
|
13636
|
-
`Invalid request: ${errorMessage(error46, String(error46))}`,
|
|
13637
|
-
{
|
|
13638
|
-
public: true,
|
|
13639
|
-
cause: error46 instanceof Error ? error46 : void 0
|
|
13640
|
-
}
|
|
13641
|
-
);
|
|
13642
|
-
}
|
|
13643
|
-
function actorNotFound(identifier) {
|
|
13644
|
-
return new RivetError(
|
|
13645
|
-
"actor",
|
|
13646
|
-
"not_found",
|
|
13647
|
-
identifier ? `Actor not found: ${identifier} (https://www.rivet.dev/docs/clients/javascript)` : "Actor not found (https://www.rivet.dev/docs/clients/javascript)",
|
|
13648
|
-
{ public: true }
|
|
13649
|
-
);
|
|
13650
|
-
}
|
|
13651
|
-
function forbiddenError() {
|
|
13652
|
-
return new RivetError("auth", "forbidden", "Forbidden", {
|
|
13653
|
-
public: true,
|
|
13654
|
-
statusCode: 403
|
|
13655
|
-
});
|
|
13656
|
-
}
|
|
13657
|
-
function unsupportedFeature(feature) {
|
|
13658
|
-
return new RivetError(
|
|
13659
|
-
"feature",
|
|
13660
|
-
"unsupported",
|
|
13661
|
-
`Unsupported feature: ${feature}`
|
|
13662
|
-
);
|
|
13663
|
-
}
|
|
13664
|
-
|
|
13665
|
-
// ../rivetkit/dist/tsup/chunk-DN6MD3KK.js
|
|
13666
|
-
var import_pino = require("pino");
|
|
13667
|
-
var cbor = __toESM(require("cbor-x"), 1);
|
|
13668
|
-
var import_invariant = __toESM(require_invariant(), 1);
|
|
13669
|
-
var getRivetEngine = () => getEnvUniversal("RIVET_ENGINE");
|
|
13670
|
-
var getRivetEndpoint = () => getEnvUniversal("RIVET_ENDPOINT");
|
|
13671
|
-
var getRivetToken = () => getEnvUniversal("RIVET_TOKEN");
|
|
13672
|
-
var getRivetNamespace = () => getEnvUniversal("RIVET_NAMESPACE");
|
|
13673
|
-
var getRivetPool = () => getEnvUniversal("RIVET_POOL");
|
|
13674
|
-
var getRivetTotalSlots = () => {
|
|
13675
|
-
const value = getEnvUniversal("RIVET_TOTAL_SLOTS");
|
|
13676
|
-
return value !== void 0 ? parseInt(value, 10) : void 0;
|
|
13677
|
-
};
|
|
13678
|
-
var getRivetRunEngine = () => getEnvUniversal("RIVET_RUN_ENGINE") === "1";
|
|
13679
|
-
var getRivetRunEngineHost = () => getEnvUniversal("RIVET_RUN_ENGINE_HOST");
|
|
13680
|
-
var getRivetRunEnginePort = () => {
|
|
13681
|
-
const value = getEnvUniversal("RIVET_RUN_ENGINE_PORT");
|
|
13682
|
-
return value !== void 0 ? parseInt(value, 10) : void 0;
|
|
13683
|
-
};
|
|
13684
|
-
var getRivetRunEngineVersion = () => getEnvUniversal("RIVET_RUN_ENGINE_VERSION");
|
|
13685
|
-
var getRivetRunServices = () => {
|
|
13686
|
-
const value = getEnvUniversal("RIVET_RUN_SERVICES");
|
|
13687
|
-
return value === void 0 ? void 0 : value === "1";
|
|
13688
|
-
};
|
|
13689
|
-
var getRivetEnvoyVersion = () => {
|
|
13690
|
-
const value = getEnvUniversal("RIVET_ENVOY_VERSION");
|
|
13691
|
-
return value !== void 0 ? parseInt(value, 10) : void 0;
|
|
13692
|
-
};
|
|
13693
|
-
var getRivetPublicEndpoint = () => getEnvUniversal("RIVET_PUBLIC_ENDPOINT");
|
|
13694
|
-
var getRivetPublicToken = () => getEnvUniversal("RIVET_PUBLIC_TOKEN");
|
|
13695
|
-
var getRivetkitRuntime = () => getEnvUniversal("RIVETKIT_RUNTIME");
|
|
13696
|
-
var getRivetkitRuntimeMode = () => {
|
|
13697
|
-
const value = getEnvUniversal("RIVETKIT_RUNTIME_MODE");
|
|
13698
|
-
if (value === void 0) return "envoy";
|
|
13699
|
-
if (value === "envoy" || value === "serverless") return value;
|
|
13700
|
-
throw new Error(
|
|
13701
|
-
`RIVETKIT_RUNTIME_MODE env var must be "envoy" or "serverless"; got "${value}"`
|
|
13702
|
-
);
|
|
13703
|
-
};
|
|
13704
|
-
var getRivetkitPublicDir = () => {
|
|
13705
|
-
const value = getEnvUniversal("RIVETKIT_PUBLIC_DIR");
|
|
13706
|
-
return value === void 0 || value === "" ? void 0 : value;
|
|
13707
|
-
};
|
|
13708
|
-
function parsePortEnv(raw) {
|
|
13709
|
-
if (raw === void 0 || raw === "") return void 0;
|
|
13710
|
-
const parsed = Number.parseInt(raw, 10);
|
|
13711
|
-
if (!Number.isFinite(parsed) || parsed < 1 || parsed > 65535 || String(parsed) !== raw.trim()) {
|
|
13712
|
-
throw new Error(
|
|
13713
|
-
`RIVET_PORT env var must be an integer between 1 and 65535; got "${raw}"`
|
|
13714
|
-
);
|
|
13715
|
-
}
|
|
13716
|
-
return parsed;
|
|
13717
|
-
}
|
|
13718
|
-
var getLogLevel = () => getEnvUniversal("RIVET_LOG_LEVEL") ?? getEnvUniversal("LOG_LEVEL");
|
|
13719
|
-
var getLogTarget = () => getEnvUniversal("RIVET_LOG_TARGET") === "1";
|
|
13720
|
-
var getLogTimestamp = () => getEnvUniversal("RIVET_LOG_TIMESTAMP") === "1";
|
|
13721
|
-
var getLogMessage = () => getEnvUniversal("RIVET_LOG_MESSAGE") === "1";
|
|
13722
|
-
var getLogErrorStack = () => getEnvUniversal("RIVET_LOG_ERROR_STACK") === "1";
|
|
13723
|
-
var getNodeEnv = () => getEnvUniversal("NODE_ENV");
|
|
13724
|
-
var getNextPhase = () => getEnvUniversal("NEXT_PHASE");
|
|
13725
|
-
var isDev = () => getNodeEnv() !== "production";
|
|
13726
|
-
function assertUnreachable(x) {
|
|
13727
|
-
throw new Error(`Unreachable case: ${x}`);
|
|
13728
|
-
}
|
|
13729
|
-
function deconstructError(error46, exposeInternalError = false) {
|
|
13730
|
-
let statusCode;
|
|
13731
|
-
let public_;
|
|
13732
|
-
let group;
|
|
13733
|
-
let code;
|
|
13734
|
-
let message;
|
|
13735
|
-
let metadata;
|
|
13736
|
-
let rayId;
|
|
13737
|
-
let actor2;
|
|
13738
|
-
if (isCanonicalStructuredRivetError(error46)) {
|
|
13739
|
-
statusCode = typeof error46.statusCode === "number" ? error46.statusCode : error46.public ? 400 : 500;
|
|
13740
|
-
public_ = error46.public ?? false;
|
|
13741
|
-
group = error46.group;
|
|
13742
|
-
code = error46.code;
|
|
13743
|
-
message = error46.message;
|
|
13744
|
-
metadata = error46.metadata;
|
|
13745
|
-
rayId = error46.rayId;
|
|
13746
|
-
actor2 = error46.actor;
|
|
13747
|
-
} else if (RivetError.isActorError(error46) && error46.public) {
|
|
13748
|
-
statusCode = "statusCode" in error46 && error46.statusCode ? error46.statusCode : 400;
|
|
13749
|
-
public_ = true;
|
|
13750
|
-
group = error46.group;
|
|
13751
|
-
code = error46.code;
|
|
13752
|
-
message = getErrorMessage(error46);
|
|
13753
|
-
metadata = error46.metadata;
|
|
13754
|
-
rayId = error46.rayId;
|
|
13755
|
-
actor2 = error46.actor;
|
|
13756
|
-
} else if (exposeInternalError) {
|
|
13757
|
-
if (RivetError.isActorError(error46)) {
|
|
13758
|
-
statusCode = 500;
|
|
13759
|
-
public_ = false;
|
|
13760
|
-
group = error46.group;
|
|
13761
|
-
code = error46.code;
|
|
13762
|
-
message = getErrorMessage(error46);
|
|
13763
|
-
metadata = error46.metadata;
|
|
13764
|
-
rayId = error46.rayId;
|
|
13765
|
-
actor2 = error46.actor;
|
|
13766
|
-
} else {
|
|
13767
|
-
statusCode = 500;
|
|
13768
|
-
public_ = false;
|
|
13769
|
-
group = "rivetkit";
|
|
13770
|
-
code = INTERNAL_ERROR_CODE;
|
|
13771
|
-
message = getErrorMessage(error46);
|
|
13772
|
-
}
|
|
13773
|
-
} else {
|
|
13774
|
-
statusCode = 500;
|
|
13775
|
-
public_ = false;
|
|
13776
|
-
group = "rivetkit";
|
|
13777
|
-
code = INTERNAL_ERROR_CODE;
|
|
13778
|
-
message = INTERNAL_ERROR_DESCRIPTION;
|
|
13779
|
-
if (RivetError.isActorError(error46)) {
|
|
13780
|
-
actor2 = error46.actor;
|
|
13781
|
-
}
|
|
13782
|
-
metadata = {
|
|
13783
|
-
//url: `https://dashboard.rivet.dev/projects/${actorMetadata.project.slug}/environments/${actorMetadata.environment.slug}/actors?actorId=${actorMetadata.actor.id}`,
|
|
13784
|
-
};
|
|
13785
|
-
}
|
|
13786
|
-
return {
|
|
13787
|
-
__type: "ActorError",
|
|
13788
|
-
statusCode,
|
|
13789
|
-
public: public_,
|
|
13790
|
-
group,
|
|
13791
|
-
code,
|
|
13792
|
-
message,
|
|
13793
|
-
metadata,
|
|
13794
|
-
rayId,
|
|
13795
|
-
actor: actor2
|
|
13796
|
-
};
|
|
13797
|
-
}
|
|
13798
|
-
function stringifyError(error46) {
|
|
13799
|
-
if (error46 instanceof Error) {
|
|
13800
|
-
if (typeof process !== "undefined" && getLogErrorStack()) {
|
|
13801
|
-
let stack;
|
|
13802
|
-
try {
|
|
13803
|
-
stack = error46.stack;
|
|
13804
|
-
} catch {
|
|
13805
|
-
stack = void 0;
|
|
13806
|
-
}
|
|
13807
|
-
return `${error46.name}: ${error46.message}${stack ? `
|
|
13808
|
-
${stack}` : ""}`;
|
|
13809
|
-
} else {
|
|
13810
|
-
return `${error46.name}: ${error46.message}`;
|
|
13811
|
-
}
|
|
13812
|
-
} else if (typeof error46 === "string") {
|
|
13813
|
-
return error46;
|
|
13814
|
-
} else if (typeof error46 === "object" && error46 !== null) {
|
|
13815
|
-
try {
|
|
13816
|
-
return `${JSON.stringify(error46)}`;
|
|
13817
|
-
} catch {
|
|
13818
|
-
return "[cannot stringify error]";
|
|
13819
|
-
}
|
|
13820
|
-
} else {
|
|
13821
|
-
return `Unknown error: ${getErrorMessage(error46)}`;
|
|
13822
|
-
}
|
|
13823
|
-
}
|
|
13824
|
-
function getErrorMessage(err) {
|
|
13825
|
-
if (err && typeof err === "object" && "message" in err && typeof err.message === "string") {
|
|
13826
|
-
return err.message;
|
|
13827
|
-
} else {
|
|
13828
|
-
return String(err);
|
|
13829
|
-
}
|
|
13830
|
-
}
|
|
13831
|
-
function noopNext() {
|
|
13832
|
-
return async () => {
|
|
13833
|
-
};
|
|
13369
|
+
function noopNext() {
|
|
13370
|
+
return async () => {
|
|
13371
|
+
};
|
|
13834
13372
|
}
|
|
13835
13373
|
var package_default = {
|
|
13836
13374
|
name: "rivetkit",
|
|
13837
|
-
version: "2.3.
|
|
13375
|
+
version: "2.3.21",
|
|
13838
13376
|
description: "Lightweight libraries for building stateful actors on edge platforms",
|
|
13839
13377
|
license: "Apache-2.0",
|
|
13840
13378
|
keywords: [
|
|
@@ -14047,6 +13585,7 @@ var package_default = {
|
|
|
14047
13585
|
"@rivet-dev/agent-os-core": "^0.1.1",
|
|
14048
13586
|
"@rivet-dev/services": "^0.1.5",
|
|
14049
13587
|
"@rivetkit/bare-ts": "^0.6.2",
|
|
13588
|
+
"@rivetkit/engine-api-full": "workspace:*",
|
|
14050
13589
|
"@rivetkit/engine-cli": "workspace:*",
|
|
14051
13590
|
"@rivetkit/engine-envoy-protocol": "workspace:*",
|
|
14052
13591
|
"@rivetkit/on-change": "6.0.1",
|
|
@@ -15140,7 +14679,7 @@ function Config({ initialBufferLength = 1024, maxBufferLength = 1024 * 1024 * 32
|
|
|
15140
14679
|
};
|
|
15141
14680
|
}
|
|
15142
14681
|
|
|
15143
|
-
// ../rivetkit/dist/tsup/chunk-
|
|
14682
|
+
// ../rivetkit/dist/tsup/chunk-CJXBGTVT.js
|
|
15144
14683
|
var config2 = /* @__PURE__ */ Config({});
|
|
15145
14684
|
function readWorkflowCbor(bc) {
|
|
15146
14685
|
return readData(bc);
|
|
@@ -15361,82 +14900,577 @@ function readWorkflowEntryKind(bc) {
|
|
|
15361
14900
|
}
|
|
15362
14901
|
}
|
|
15363
14902
|
}
|
|
15364
|
-
function readWorkflowEntry(bc) {
|
|
15365
|
-
return {
|
|
15366
|
-
id: readString(bc),
|
|
15367
|
-
location: readWorkflowLocation(bc),
|
|
15368
|
-
kind: readWorkflowEntryKind(bc)
|
|
15369
|
-
};
|
|
15370
|
-
}
|
|
15371
|
-
function read3(bc) {
|
|
15372
|
-
return readBool(bc) ? readU64(bc) : null;
|
|
14903
|
+
function readWorkflowEntry(bc) {
|
|
14904
|
+
return {
|
|
14905
|
+
id: readString(bc),
|
|
14906
|
+
location: readWorkflowLocation(bc),
|
|
14907
|
+
kind: readWorkflowEntryKind(bc)
|
|
14908
|
+
};
|
|
14909
|
+
}
|
|
14910
|
+
function read3(bc) {
|
|
14911
|
+
return readBool(bc) ? readU64(bc) : null;
|
|
14912
|
+
}
|
|
14913
|
+
function readWorkflowEntryMetadata(bc) {
|
|
14914
|
+
return {
|
|
14915
|
+
status: readWorkflowEntryStatus(bc),
|
|
14916
|
+
error: read1(bc),
|
|
14917
|
+
attempts: readU32(bc),
|
|
14918
|
+
lastAttemptAt: readU64(bc),
|
|
14919
|
+
createdAt: readU64(bc),
|
|
14920
|
+
completedAt: read3(bc),
|
|
14921
|
+
rollbackCompletedAt: read3(bc),
|
|
14922
|
+
rollbackError: read1(bc)
|
|
14923
|
+
};
|
|
14924
|
+
}
|
|
14925
|
+
function read4(bc) {
|
|
14926
|
+
const len = readUintSafe(bc);
|
|
14927
|
+
if (len === 0) {
|
|
14928
|
+
return [];
|
|
14929
|
+
}
|
|
14930
|
+
const result = [readString(bc)];
|
|
14931
|
+
for (let i = 1; i < len; i++) {
|
|
14932
|
+
result[i] = readString(bc);
|
|
14933
|
+
}
|
|
14934
|
+
return result;
|
|
14935
|
+
}
|
|
14936
|
+
function read5(bc) {
|
|
14937
|
+
const len = readUintSafe(bc);
|
|
14938
|
+
if (len === 0) {
|
|
14939
|
+
return [];
|
|
14940
|
+
}
|
|
14941
|
+
const result = [readWorkflowEntry(bc)];
|
|
14942
|
+
for (let i = 1; i < len; i++) {
|
|
14943
|
+
result[i] = readWorkflowEntry(bc);
|
|
14944
|
+
}
|
|
14945
|
+
return result;
|
|
14946
|
+
}
|
|
14947
|
+
function read6(bc) {
|
|
14948
|
+
const len = readUintSafe(bc);
|
|
14949
|
+
const result = /* @__PURE__ */ new Map();
|
|
14950
|
+
for (let i = 0; i < len; i++) {
|
|
14951
|
+
const offset = bc.offset;
|
|
14952
|
+
const key = readString(bc);
|
|
14953
|
+
if (result.has(key)) {
|
|
14954
|
+
bc.offset = offset;
|
|
14955
|
+
throw new BareError(offset, "duplicated key");
|
|
14956
|
+
}
|
|
14957
|
+
result.set(key, readWorkflowEntryMetadata(bc));
|
|
14958
|
+
}
|
|
14959
|
+
return result;
|
|
14960
|
+
}
|
|
14961
|
+
function readWorkflowHistory(bc) {
|
|
14962
|
+
return {
|
|
14963
|
+
nameRegistry: read4(bc),
|
|
14964
|
+
entries: read5(bc),
|
|
14965
|
+
entryMetadata: read6(bc)
|
|
14966
|
+
};
|
|
14967
|
+
}
|
|
14968
|
+
function decodeWorkflowHistory(bytes) {
|
|
14969
|
+
const bc = new ByteCursor(bytes, config2);
|
|
14970
|
+
const result = readWorkflowHistory(bc);
|
|
14971
|
+
if (bc.offset < bc.view.byteLength) {
|
|
14972
|
+
throw new BareError(bc.offset, "remaining bytes");
|
|
14973
|
+
}
|
|
14974
|
+
return result;
|
|
14975
|
+
}
|
|
14976
|
+
function decodeWorkflowHistoryTransport(data) {
|
|
14977
|
+
return decodeWorkflowHistory(toUint8Array(data));
|
|
14978
|
+
}
|
|
14979
|
+
|
|
14980
|
+
// ../rivetkit/dist/tsup/chunk-CSOHAAZK.js
|
|
14981
|
+
function flattenActionHandlers(actions) {
|
|
14982
|
+
const flattened = /* @__PURE__ */ Object.create(null);
|
|
14983
|
+
for (const { name, handler } of collectActionEntries(actions)) {
|
|
14984
|
+
flattened[name] = handler;
|
|
14985
|
+
}
|
|
14986
|
+
return flattened;
|
|
14987
|
+
}
|
|
14988
|
+
function flattenActionInputSchemas(actions, schemas) {
|
|
14989
|
+
if (schemas === void 0) return void 0;
|
|
14990
|
+
if (!isRecord(schemas)) {
|
|
14991
|
+
throw new TypeError("actionInputSchemas must be an object");
|
|
14992
|
+
}
|
|
14993
|
+
const flattened = /* @__PURE__ */ Object.create(null);
|
|
14994
|
+
for (const { name, path: path2 } of collectActionEntries(actions)) {
|
|
14995
|
+
const nestedSchema = lookupNestedSchema(schemas, path2);
|
|
14996
|
+
const flatSchema = schemas[name];
|
|
14997
|
+
if (nestedSchema !== void 0 && flatSchema !== void 0 && nestedSchema !== flatSchema) {
|
|
14998
|
+
throw new TypeError(
|
|
14999
|
+
`Action input schema \`${name}\` is defined by both a nested path and a dotted key`
|
|
15000
|
+
);
|
|
15001
|
+
}
|
|
15002
|
+
const schema = nestedSchema ?? flatSchema;
|
|
15003
|
+
if (schema !== void 0) {
|
|
15004
|
+
flattened[name] = schema;
|
|
15005
|
+
}
|
|
15006
|
+
}
|
|
15007
|
+
return flattened;
|
|
15008
|
+
}
|
|
15009
|
+
function flattenActionTraceSamplers(actions, rates = {}) {
|
|
15010
|
+
const handlers = flattenActionHandlers(actions);
|
|
15011
|
+
const flattened = Object.fromEntries(flattenSampleRates(rates, []));
|
|
15012
|
+
for (const name of Object.keys(flattened)) {
|
|
15013
|
+
if (!Object.hasOwn(handlers, name)) {
|
|
15014
|
+
throw new TypeError(
|
|
15015
|
+
`tracing.actions.${name} does not name an action`
|
|
15016
|
+
);
|
|
15017
|
+
}
|
|
15018
|
+
}
|
|
15019
|
+
return flattened;
|
|
15020
|
+
}
|
|
15021
|
+
function flattenSampleRates(rates, path2) {
|
|
15022
|
+
return Object.entries(rates).flatMap(
|
|
15023
|
+
([segment, rate]) => {
|
|
15024
|
+
const childPath = [...path2, segment];
|
|
15025
|
+
return typeof rate === "number" ? [[childPath.join("."), rate]] : flattenSampleRates(rate, childPath);
|
|
15026
|
+
}
|
|
15027
|
+
);
|
|
15028
|
+
}
|
|
15029
|
+
function collectActionEntries(actions) {
|
|
15030
|
+
const entries = [];
|
|
15031
|
+
const names = /* @__PURE__ */ new Set();
|
|
15032
|
+
visitActionGroup(actions ?? {}, [], entries, names);
|
|
15033
|
+
return entries;
|
|
15034
|
+
}
|
|
15035
|
+
function visitActionGroup(value, path2, entries, names) {
|
|
15036
|
+
if (!isRecord(value)) {
|
|
15037
|
+
throw new TypeError(
|
|
15038
|
+
`${formatActionPath(path2)} must be an action handler or group`
|
|
15039
|
+
);
|
|
15040
|
+
}
|
|
15041
|
+
for (const [segment, child] of Object.entries(value)) {
|
|
15042
|
+
const childPath = [...path2, segment];
|
|
15043
|
+
if (typeof child === "function") {
|
|
15044
|
+
const name = childPath.join(".");
|
|
15045
|
+
if (names.has(name)) {
|
|
15046
|
+
throw new TypeError(
|
|
15047
|
+
`Multiple action definitions flatten to \`${name}\``
|
|
15048
|
+
);
|
|
15049
|
+
}
|
|
15050
|
+
names.add(name);
|
|
15051
|
+
entries.push({
|
|
15052
|
+
name,
|
|
15053
|
+
path: childPath,
|
|
15054
|
+
handler: child
|
|
15055
|
+
});
|
|
15056
|
+
} else {
|
|
15057
|
+
visitActionGroup(child, childPath, entries, names);
|
|
15058
|
+
}
|
|
15059
|
+
}
|
|
15060
|
+
}
|
|
15061
|
+
function lookupNestedSchema(schemas, path2) {
|
|
15062
|
+
let value = schemas;
|
|
15063
|
+
for (const segment of path2) {
|
|
15064
|
+
if (!isRecord(value) || !Object.hasOwn(value, segment)) {
|
|
15065
|
+
return void 0;
|
|
15066
|
+
}
|
|
15067
|
+
value = value[segment];
|
|
15068
|
+
}
|
|
15069
|
+
return value;
|
|
15070
|
+
}
|
|
15071
|
+
function isRecord(value) {
|
|
15072
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
15073
|
+
return false;
|
|
15074
|
+
}
|
|
15075
|
+
const prototype = Object.getPrototypeOf(value);
|
|
15076
|
+
return prototype === Object.prototype || prototype === null;
|
|
15077
|
+
}
|
|
15078
|
+
function formatActionPath(path2) {
|
|
15079
|
+
return path2.length === 0 ? "actions" : `Action \`${path2.join(".")}\``;
|
|
15080
|
+
}
|
|
15081
|
+
var DEFAULT_SLEEP_GRACE_PERIOD = 15e3;
|
|
15082
|
+
var ACTOR_CONTEXT_INTERNAL_SYMBOL = /* @__PURE__ */ Symbol(
|
|
15083
|
+
"rivetkit.actor_context_internal"
|
|
15084
|
+
);
|
|
15085
|
+
var RAW_STATE_SYMBOL = /* @__PURE__ */ Symbol("rivetkit.raw_state");
|
|
15086
|
+
var CONN_STATE_MANAGER_SYMBOL = /* @__PURE__ */ Symbol("rivetkit.conn_state_manager");
|
|
15087
|
+
var zFunction = () => external_exports.custom((val) => typeof val === "function");
|
|
15088
|
+
var zActionTree = external_exports.custom((value) => {
|
|
15089
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
15090
|
+
return false;
|
|
15091
|
+
}
|
|
15092
|
+
const prototype = Object.getPrototypeOf(value);
|
|
15093
|
+
return prototype === Object.prototype || prototype === null;
|
|
15094
|
+
}).superRefine((actions, ctx) => {
|
|
15095
|
+
try {
|
|
15096
|
+
flattenActionHandlers(actions);
|
|
15097
|
+
} catch (error46) {
|
|
15098
|
+
ctx.addIssue({
|
|
15099
|
+
code: "custom",
|
|
15100
|
+
message: error46 instanceof Error ? error46.message : "Invalid action definition"
|
|
15101
|
+
});
|
|
15102
|
+
}
|
|
15103
|
+
});
|
|
15104
|
+
var WorkflowInspectorConfigSchema = external_exports.object({
|
|
15105
|
+
getHistory: zFunction(),
|
|
15106
|
+
getState: zFunction().optional(),
|
|
15107
|
+
onHistoryUpdated: zFunction().optional(),
|
|
15108
|
+
replayFromStep: zFunction().optional()
|
|
15109
|
+
});
|
|
15110
|
+
var RunInspectorConfigSchema = external_exports.object({
|
|
15111
|
+
workflow: WorkflowInspectorConfigSchema.optional()
|
|
15112
|
+
}).optional();
|
|
15113
|
+
var BUILTIN_INSPECTOR_TAB_IDS = [
|
|
15114
|
+
"workflow",
|
|
15115
|
+
"database",
|
|
15116
|
+
"state",
|
|
15117
|
+
"queue",
|
|
15118
|
+
"schedules",
|
|
15119
|
+
"connections",
|
|
15120
|
+
"console"
|
|
15121
|
+
];
|
|
15122
|
+
var BuiltinInspectorTabIdSchema = external_exports.enum(BUILTIN_INSPECTOR_TAB_IDS);
|
|
15123
|
+
var CUSTOM_INSPECTOR_TAB_ID_RE = /^[A-Za-z0-9_-]+$/;
|
|
15124
|
+
var CustomInspectorTabEntrySchema = external_exports.object({
|
|
15125
|
+
id: external_exports.string().regex(
|
|
15126
|
+
CUSTOM_INSPECTOR_TAB_ID_RE,
|
|
15127
|
+
"inspector.tabs[].id must contain only letters, digits, underscore, or dash"
|
|
15128
|
+
),
|
|
15129
|
+
label: external_exports.string().min(1),
|
|
15130
|
+
source: external_exports.string().min(1),
|
|
15131
|
+
/**
|
|
15132
|
+
* Optional icon id. The dashboard maps strings to glyphs (see its
|
|
15133
|
+
* icon registry); unknown ids fall back to a generic icon.
|
|
15134
|
+
*/
|
|
15135
|
+
icon: external_exports.string().min(1).optional(),
|
|
15136
|
+
hidden: external_exports.literal(false).optional()
|
|
15137
|
+
}).strict();
|
|
15138
|
+
var HideInspectorTabEntrySchema = external_exports.object({
|
|
15139
|
+
id: BuiltinInspectorTabIdSchema,
|
|
15140
|
+
hidden: external_exports.literal(true)
|
|
15141
|
+
}).strict();
|
|
15142
|
+
var InspectorTabEntrySchema = external_exports.union([
|
|
15143
|
+
CustomInspectorTabEntrySchema,
|
|
15144
|
+
HideInspectorTabEntrySchema
|
|
15145
|
+
]);
|
|
15146
|
+
var ActorInspectorConfigSchema = external_exports.object({
|
|
15147
|
+
tabs: external_exports.array(InspectorTabEntrySchema).default(() => [])
|
|
15148
|
+
}).strict().refine(
|
|
15149
|
+
(data) => {
|
|
15150
|
+
const ids = data.tabs.map((t) => t.id);
|
|
15151
|
+
return new Set(ids).size === ids.length;
|
|
15152
|
+
},
|
|
15153
|
+
{ message: "Duplicate id in inspector.tabs", path: ["tabs"] }
|
|
15154
|
+
).refine(
|
|
15155
|
+
(data) => {
|
|
15156
|
+
const builtinSet = new Set(BUILTIN_INSPECTOR_TAB_IDS);
|
|
15157
|
+
return data.tabs.every(
|
|
15158
|
+
(t) => t.hidden === true || !builtinSet.has(t.id)
|
|
15159
|
+
);
|
|
15160
|
+
},
|
|
15161
|
+
{
|
|
15162
|
+
message: "Custom inspector tab id collides with a built-in (use hidden: true to hide a built-in)",
|
|
15163
|
+
path: ["tabs"]
|
|
15164
|
+
}
|
|
15165
|
+
);
|
|
15166
|
+
var RunConfigSchema = external_exports.object({
|
|
15167
|
+
/** Display name for the actor in the Inspector UI. */
|
|
15168
|
+
name: external_exports.string().optional(),
|
|
15169
|
+
/** Icon for the actor in the Inspector UI. Can be an emoji or FontAwesome icon name. */
|
|
15170
|
+
icon: external_exports.string().optional(),
|
|
15171
|
+
/** The run handler function. */
|
|
15172
|
+
run: zFunction(),
|
|
15173
|
+
/** Inspector integration for long-running run handlers. */
|
|
15174
|
+
inspector: RunInspectorConfigSchema.optional()
|
|
15175
|
+
});
|
|
15176
|
+
var RUN_FUNCTION_CONFIG_SYMBOL = /* @__PURE__ */ Symbol.for("rivetkit.run_function_config");
|
|
15177
|
+
function defineRunHandler(run, options) {
|
|
15178
|
+
if (options.inspectorKind === void 0 !== (options.createInspector === void 0)) {
|
|
15179
|
+
throw new TypeError(
|
|
15180
|
+
"defineRunHandler requires inspectorKind and createInspector together"
|
|
15181
|
+
);
|
|
15182
|
+
}
|
|
15183
|
+
Object.defineProperty(run, RUN_FUNCTION_CONFIG_SYMBOL, {
|
|
15184
|
+
configurable: false,
|
|
15185
|
+
enumerable: false,
|
|
15186
|
+
writable: false,
|
|
15187
|
+
value: {
|
|
15188
|
+
name: options.name,
|
|
15189
|
+
icon: options.icon,
|
|
15190
|
+
inspectorKind: options.inspectorKind,
|
|
15191
|
+
createInspector: options.createInspector
|
|
15192
|
+
}
|
|
15193
|
+
});
|
|
15194
|
+
return run;
|
|
15195
|
+
}
|
|
15196
|
+
function getRunInspectorKind(run) {
|
|
15197
|
+
var _a2;
|
|
15198
|
+
if (!run || typeof run !== "function") return void 0;
|
|
15199
|
+
return (_a2 = run[RUN_FUNCTION_CONFIG_SYMBOL]) == null ? void 0 : _a2.inspectorKind;
|
|
15373
15200
|
}
|
|
15374
|
-
function
|
|
15375
|
-
|
|
15376
|
-
|
|
15377
|
-
|
|
15378
|
-
attempts: readU32(bc),
|
|
15379
|
-
lastAttemptAt: readU64(bc),
|
|
15380
|
-
createdAt: readU64(bc),
|
|
15381
|
-
completedAt: read3(bc),
|
|
15382
|
-
rollbackCompletedAt: read3(bc),
|
|
15383
|
-
rollbackError: read1(bc)
|
|
15384
|
-
};
|
|
15201
|
+
function createRunInspector(run, context2) {
|
|
15202
|
+
var _a2, _b;
|
|
15203
|
+
if (!run || typeof run !== "function") return void 0;
|
|
15204
|
+
return (_b = (_a2 = run[RUN_FUNCTION_CONFIG_SYMBOL]) == null ? void 0 : _a2.createInspector) == null ? void 0 : _b.call(_a2, context2);
|
|
15385
15205
|
}
|
|
15386
|
-
|
|
15387
|
-
|
|
15388
|
-
if (
|
|
15389
|
-
|
|
15390
|
-
|
|
15391
|
-
const result = [readString(bc)];
|
|
15392
|
-
for (let i = 1; i < len; i++) {
|
|
15393
|
-
result[i] = readString(bc);
|
|
15394
|
-
}
|
|
15395
|
-
return result;
|
|
15206
|
+
var zRunHandler = external_exports.union([zFunction(), RunConfigSchema]).optional();
|
|
15207
|
+
function getRunFunction(run) {
|
|
15208
|
+
if (!run) return void 0;
|
|
15209
|
+
if (typeof run === "function") return run;
|
|
15210
|
+
return run.run;
|
|
15396
15211
|
}
|
|
15397
|
-
function
|
|
15398
|
-
|
|
15399
|
-
if (
|
|
15400
|
-
|
|
15401
|
-
|
|
15402
|
-
|
|
15403
|
-
for (let i = 1; i < len; i++) {
|
|
15404
|
-
result[i] = readWorkflowEntry(bc);
|
|
15212
|
+
function getRunMetadata(run) {
|
|
15213
|
+
if (!run) return {};
|
|
15214
|
+
if (typeof run === "function") {
|
|
15215
|
+
const config3 = run[RUN_FUNCTION_CONFIG_SYMBOL];
|
|
15216
|
+
if (!config3) return {};
|
|
15217
|
+
return { name: config3.name, icon: config3.icon };
|
|
15405
15218
|
}
|
|
15406
|
-
return
|
|
15219
|
+
return { name: run.name, icon: run.icon };
|
|
15407
15220
|
}
|
|
15408
|
-
function
|
|
15409
|
-
|
|
15410
|
-
|
|
15411
|
-
|
|
15412
|
-
|
|
15413
|
-
const key = readString(bc);
|
|
15414
|
-
if (result.has(key)) {
|
|
15415
|
-
bc.offset = offset;
|
|
15416
|
-
throw new BareError(offset, "duplicated key");
|
|
15417
|
-
}
|
|
15418
|
-
result.set(key, readWorkflowEntryMetadata(bc));
|
|
15221
|
+
function getRunInspectorConfig(run, actor2) {
|
|
15222
|
+
if (!run) return void 0;
|
|
15223
|
+
if (typeof run === "function") {
|
|
15224
|
+
const config3 = run[RUN_FUNCTION_CONFIG_SYMBOL];
|
|
15225
|
+
return (config3 == null ? void 0 : config3.inspectorFactory) ? config3.inspectorFactory(actor2) : config3 == null ? void 0 : config3.inspector;
|
|
15419
15226
|
}
|
|
15420
|
-
return
|
|
15227
|
+
return run.inspector;
|
|
15421
15228
|
}
|
|
15422
|
-
function
|
|
15423
|
-
return
|
|
15424
|
-
|
|
15425
|
-
|
|
15426
|
-
|
|
15427
|
-
};
|
|
15229
|
+
function hasRunInspectorConfig(run) {
|
|
15230
|
+
if (!run) return false;
|
|
15231
|
+
if (typeof run !== "function") return run.inspector !== void 0;
|
|
15232
|
+
const config3 = run[RUN_FUNCTION_CONFIG_SYMBOL];
|
|
15233
|
+
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;
|
|
15428
15234
|
}
|
|
15429
|
-
function
|
|
15430
|
-
|
|
15431
|
-
|
|
15432
|
-
|
|
15433
|
-
throw new BareError(bc.offset, "remaining bytes");
|
|
15235
|
+
function disposeRunInspector(run, actorId) {
|
|
15236
|
+
var _a2;
|
|
15237
|
+
if (!run || typeof run !== "function") {
|
|
15238
|
+
return;
|
|
15434
15239
|
}
|
|
15435
|
-
|
|
15436
|
-
|
|
15437
|
-
function decodeWorkflowHistoryTransport(data) {
|
|
15438
|
-
return decodeWorkflowHistory(toUint8Array(data));
|
|
15240
|
+
const config3 = run[RUN_FUNCTION_CONFIG_SYMBOL];
|
|
15241
|
+
(_a2 = config3 == null ? void 0 : config3.disposeInspector) == null ? void 0 : _a2.call(config3, actorId);
|
|
15439
15242
|
}
|
|
15243
|
+
var GlobalActorOptionsBaseSchema = external_exports.object({
|
|
15244
|
+
/** Display name for the actor in the Inspector UI. */
|
|
15245
|
+
name: external_exports.string().optional(),
|
|
15246
|
+
/** Icon for the actor in the Inspector UI. Can be an emoji or FontAwesome icon name. */
|
|
15247
|
+
icon: external_exports.string().optional(),
|
|
15248
|
+
/** Enables the experimental Actor Runtime Socket for this actor. */
|
|
15249
|
+
enableActorRuntimeSocket: external_exports.boolean().default(false),
|
|
15250
|
+
/**
|
|
15251
|
+
* Can hibernate WebSockets for onWebSocket.
|
|
15252
|
+
*
|
|
15253
|
+
* WebSockets using actions/events are hibernatable by default.
|
|
15254
|
+
*
|
|
15255
|
+
* @experimental
|
|
15256
|
+
**/
|
|
15257
|
+
canHibernateWebSocket: external_exports.union([external_exports.boolean(), zFunction()]).default(false)
|
|
15258
|
+
}).strict();
|
|
15259
|
+
var GlobalActorOptionsSchema = GlobalActorOptionsBaseSchema.prefault(
|
|
15260
|
+
() => ({})
|
|
15261
|
+
);
|
|
15262
|
+
var InstanceActorOptionsBaseSchema = external_exports.object({
|
|
15263
|
+
createVarsTimeout: external_exports.number().positive().default(5e3),
|
|
15264
|
+
createConnStateTimeout: external_exports.number().positive().default(5e3),
|
|
15265
|
+
onBeforeConnectTimeout: external_exports.number().positive().default(5e3),
|
|
15266
|
+
onConnectTimeout: external_exports.number().positive().default(5e3),
|
|
15267
|
+
onMigrateTimeout: external_exports.number().positive().default(3e4),
|
|
15268
|
+
sleepGracePeriod: external_exports.number().positive().default(DEFAULT_SLEEP_GRACE_PERIOD),
|
|
15269
|
+
/** @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. */
|
|
15270
|
+
onDestroyTimeout: external_exports.number().positive().optional(),
|
|
15271
|
+
/** @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. */
|
|
15272
|
+
waitUntilTimeout: external_exports.number().positive().optional(),
|
|
15273
|
+
stateSaveInterval: external_exports.number().positive().default(1e3),
|
|
15274
|
+
actionTimeout: external_exports.number().positive().default(6e4),
|
|
15275
|
+
connectionLivenessTimeout: external_exports.number().positive().default(2500),
|
|
15276
|
+
connectionLivenessInterval: external_exports.number().positive().default(5e3),
|
|
15277
|
+
/** @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. */
|
|
15278
|
+
noSleep: external_exports.boolean().default(false),
|
|
15279
|
+
sleepTimeout: external_exports.number().positive().default(3e4),
|
|
15280
|
+
maxQueueSize: external_exports.number().positive().default(1e3),
|
|
15281
|
+
/** Maximum pending one-shot and recurring schedules. */
|
|
15282
|
+
maxSchedules: external_exports.number().int().nonnegative().default(1e3),
|
|
15283
|
+
maxQueueMessageSize: external_exports.number().positive().default(64 * 1024),
|
|
15284
|
+
/** @deprecated Internal storage moved to SQLite and no longer uses KV preloading, so this option is ignored. Will be removed in 2.2.0. */
|
|
15285
|
+
preloadMaxWorkflowBytes: external_exports.number().nonnegative().optional(),
|
|
15286
|
+
/** @deprecated Internal storage moved to SQLite and no longer uses KV preloading, so this option is ignored. Will be removed in 2.2.0. */
|
|
15287
|
+
preloadMaxConnectionsBytes: external_exports.number().nonnegative().optional()
|
|
15288
|
+
}).strict();
|
|
15289
|
+
var InstanceActorOptionsSchema = InstanceActorOptionsBaseSchema.prefault(() => ({}));
|
|
15290
|
+
var ActorOptionsSchema = GlobalActorOptionsBaseSchema.extend(
|
|
15291
|
+
InstanceActorOptionsBaseSchema.shape
|
|
15292
|
+
).strict().prefault(() => ({}));
|
|
15293
|
+
var zSampleRate = external_exports.number().min(0).max(1);
|
|
15294
|
+
var zActionSampleRates = external_exports.lazy(
|
|
15295
|
+
() => external_exports.record(external_exports.string(), external_exports.union([zSampleRate, zActionSampleRates]))
|
|
15296
|
+
);
|
|
15297
|
+
var ActorConfigSchema = external_exports.object({
|
|
15298
|
+
onCreate: zFunction().optional(),
|
|
15299
|
+
onDestroy: zFunction().optional(),
|
|
15300
|
+
onMigrate: zFunction().optional(),
|
|
15301
|
+
onWake: zFunction().optional(),
|
|
15302
|
+
onSleep: zFunction().optional(),
|
|
15303
|
+
run: zRunHandler,
|
|
15304
|
+
onStateChange: zFunction().optional(),
|
|
15305
|
+
onBeforeConnect: zFunction().optional(),
|
|
15306
|
+
onConnect: zFunction().optional(),
|
|
15307
|
+
onDisconnect: zFunction().optional(),
|
|
15308
|
+
onBeforeActionResponse: zFunction().optional(),
|
|
15309
|
+
onRequest: zFunction().optional(),
|
|
15310
|
+
onWebSocket: zFunction().optional(),
|
|
15311
|
+
actions: zActionTree.default(() => ({})),
|
|
15312
|
+
actionInputSchemas: external_exports.record(external_exports.string(), external_exports.any()).optional(),
|
|
15313
|
+
tracing: external_exports.object({
|
|
15314
|
+
sampler: zSampleRate.optional(),
|
|
15315
|
+
actions: zActionSampleRates.optional()
|
|
15316
|
+
}).strict().optional(),
|
|
15317
|
+
connParamsSchema: external_exports.any().optional(),
|
|
15318
|
+
events: external_exports.record(external_exports.string(), external_exports.any()).optional(),
|
|
15319
|
+
queues: external_exports.record(external_exports.string(), external_exports.any()).optional(),
|
|
15320
|
+
state: external_exports.any().optional(),
|
|
15321
|
+
createState: zFunction().optional(),
|
|
15322
|
+
connState: external_exports.any().optional(),
|
|
15323
|
+
createConnState: zFunction().optional(),
|
|
15324
|
+
vars: external_exports.any().optional(),
|
|
15325
|
+
db: external_exports.any().optional(),
|
|
15326
|
+
createVars: zFunction().optional(),
|
|
15327
|
+
options: ActorOptionsSchema,
|
|
15328
|
+
inspector: ActorInspectorConfigSchema.optional()
|
|
15329
|
+
}).strict().refine(
|
|
15330
|
+
(data) => !(data.state !== void 0 && data.createState !== void 0),
|
|
15331
|
+
{
|
|
15332
|
+
message: "Cannot define both 'state' and 'createState'",
|
|
15333
|
+
path: ["state"]
|
|
15334
|
+
}
|
|
15335
|
+
).refine(
|
|
15336
|
+
(data) => !(data.connState !== void 0 && data.createConnState !== void 0),
|
|
15337
|
+
{
|
|
15338
|
+
message: "Cannot define both 'connState' and 'createConnState'",
|
|
15339
|
+
path: ["connState"]
|
|
15340
|
+
}
|
|
15341
|
+
).refine(
|
|
15342
|
+
(data) => !(data.vars !== void 0 && data.createVars !== void 0),
|
|
15343
|
+
{
|
|
15344
|
+
message: "Cannot define both 'vars' and 'createVars'",
|
|
15345
|
+
path: ["vars"]
|
|
15346
|
+
}
|
|
15347
|
+
);
|
|
15348
|
+
var DocActorOptionsSchema = external_exports.object({
|
|
15349
|
+
name: external_exports.string().optional().describe("Display name for the actor in the Inspector UI."),
|
|
15350
|
+
icon: external_exports.string().optional().describe(
|
|
15351
|
+
"Icon for the actor in the Inspector UI. Can be an emoji (e.g., '\u{1F680}') or FontAwesome icon name (e.g., 'rocket')."
|
|
15352
|
+
),
|
|
15353
|
+
enableActorRuntimeSocket: external_exports.boolean().optional().describe(
|
|
15354
|
+
"Enables the experimental Actor Runtime Socket for this actor. Default: false"
|
|
15355
|
+
),
|
|
15356
|
+
createVarsTimeout: external_exports.number().optional().describe("Timeout in ms for createVars handler. Default: 5000"),
|
|
15357
|
+
createConnStateTimeout: external_exports.number().optional().describe(
|
|
15358
|
+
"Timeout in ms for createConnState handler. Default: 5000"
|
|
15359
|
+
),
|
|
15360
|
+
onMigrateTimeout: external_exports.number().optional().describe("Timeout in ms for onMigrate handler. Default: 30000"),
|
|
15361
|
+
onBeforeConnectTimeout: external_exports.number().optional().describe(
|
|
15362
|
+
"Timeout in ms for onBeforeConnect handler. Default: 5000"
|
|
15363
|
+
),
|
|
15364
|
+
onConnectTimeout: external_exports.number().optional().describe("Timeout in ms for onConnect handler. Default: 5000"),
|
|
15365
|
+
sleepGracePeriod: external_exports.number().optional().describe(
|
|
15366
|
+
`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}.`
|
|
15367
|
+
),
|
|
15368
|
+
onDestroyTimeout: external_exports.number().optional().describe(
|
|
15369
|
+
"Deprecated. Folded into sleepGracePeriod, which now bounds the entire graceful shutdown window for both sleep and destroy. Will be removed in 2.2.0."
|
|
15370
|
+
),
|
|
15371
|
+
waitUntilTimeout: external_exports.number().optional().describe(
|
|
15372
|
+
"Deprecated. Folded into sleepGracePeriod, which now bounds the entire graceful shutdown window for both sleep and destroy. Will be removed in 2.2.0."
|
|
15373
|
+
),
|
|
15374
|
+
stateSaveInterval: external_exports.number().optional().describe(
|
|
15375
|
+
"Interval in ms between automatic state saves. Default: 1000"
|
|
15376
|
+
),
|
|
15377
|
+
actionTimeout: external_exports.number().optional().describe("Timeout in ms for action handlers. Default: 60000"),
|
|
15378
|
+
connectionLivenessTimeout: external_exports.number().optional().describe(
|
|
15379
|
+
"Timeout in ms for connection liveness checks. Default: 2500"
|
|
15380
|
+
),
|
|
15381
|
+
connectionLivenessInterval: external_exports.number().optional().describe(
|
|
15382
|
+
"Interval in ms between connection liveness checks. Default: 5000"
|
|
15383
|
+
),
|
|
15384
|
+
noSleep: external_exports.boolean().optional().describe(
|
|
15385
|
+
"Deprecated. If true, the actor will never sleep. Use c.keepAwake(promise) to scope keep-awake to a specific operation instead. Default: false"
|
|
15386
|
+
),
|
|
15387
|
+
sleepTimeout: external_exports.number().optional().describe(
|
|
15388
|
+
"Time in ms of inactivity before the actor sleeps. Default: 30000"
|
|
15389
|
+
),
|
|
15390
|
+
maxQueueSize: external_exports.number().optional().describe(
|
|
15391
|
+
"Maximum number of queue messages before rejecting new messages. Default: 1000"
|
|
15392
|
+
),
|
|
15393
|
+
maxSchedules: external_exports.number().int().nonnegative().optional().describe(
|
|
15394
|
+
"Maximum pending one-shot and recurring schedules before rejecting new schedules. Default: 1000"
|
|
15395
|
+
),
|
|
15396
|
+
maxQueueMessageSize: external_exports.number().optional().describe(
|
|
15397
|
+
"Maximum size of each queue message in bytes. Default: 65536"
|
|
15398
|
+
),
|
|
15399
|
+
canHibernateWebSocket: external_exports.boolean().optional().describe(
|
|
15400
|
+
"Whether WebSockets using onWebSocket can be hibernated. WebSockets using actions/events are hibernatable by default. Default: false"
|
|
15401
|
+
)
|
|
15402
|
+
}).describe("Actor options for timeouts and behavior configuration.");
|
|
15403
|
+
var DocActorConfigSchema = external_exports.object({
|
|
15404
|
+
state: external_exports.unknown().optional().describe(
|
|
15405
|
+
"Initial state value for the actor. Cannot be used with createState."
|
|
15406
|
+
),
|
|
15407
|
+
createState: external_exports.unknown().optional().describe(
|
|
15408
|
+
"Function to create initial state. Receives context and input. Cannot be used with state."
|
|
15409
|
+
),
|
|
15410
|
+
connState: external_exports.unknown().optional().describe(
|
|
15411
|
+
"Initial connection state value. Cannot be used with createConnState."
|
|
15412
|
+
),
|
|
15413
|
+
createConnState: external_exports.unknown().optional().describe(
|
|
15414
|
+
"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."
|
|
15415
|
+
),
|
|
15416
|
+
vars: external_exports.unknown().optional().describe(
|
|
15417
|
+
"Initial ephemeral variables value. Cannot be used with createVars."
|
|
15418
|
+
),
|
|
15419
|
+
createVars: external_exports.unknown().optional().describe(
|
|
15420
|
+
"Function to create ephemeral variables. Receives context and driver context. Cannot be used with vars."
|
|
15421
|
+
),
|
|
15422
|
+
db: external_exports.unknown().optional().describe("Database provider instance for the actor."),
|
|
15423
|
+
onCreate: external_exports.unknown().optional().describe(
|
|
15424
|
+
"Called when the actor is first initialized. Use to initialize state."
|
|
15425
|
+
),
|
|
15426
|
+
onDestroy: external_exports.unknown().optional().describe("Called when the actor is destroyed."),
|
|
15427
|
+
onMigrate: external_exports.unknown().optional().describe(
|
|
15428
|
+
"Called on every actor start after persisted state loads and before onWake. Use for repeatable schema migrations."
|
|
15429
|
+
),
|
|
15430
|
+
onWake: external_exports.unknown().optional().describe(
|
|
15431
|
+
"Called when the actor wakes up and is ready to receive connections and actions."
|
|
15432
|
+
),
|
|
15433
|
+
onSleep: external_exports.unknown().optional().describe(
|
|
15434
|
+
"Called when the actor is stopping or sleeping. Use to clean up resources."
|
|
15435
|
+
),
|
|
15436
|
+
run: external_exports.unknown().optional().describe(
|
|
15437
|
+
"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."
|
|
15438
|
+
),
|
|
15439
|
+
onStateChange: external_exports.unknown().optional().describe(
|
|
15440
|
+
"Called when the actor's state changes. State changes within this hook won't trigger recursion."
|
|
15441
|
+
),
|
|
15442
|
+
onBeforeConnect: external_exports.unknown().optional().describe(
|
|
15443
|
+
"Called before a client connects. Throw an error to reject the connection. The pending connection is not visible in c.conns while this runs."
|
|
15444
|
+
),
|
|
15445
|
+
onConnect: external_exports.unknown().optional().describe(
|
|
15446
|
+
"Called when a client successfully connects. The connection is visible in c.conns before this runs."
|
|
15447
|
+
),
|
|
15448
|
+
onDisconnect: external_exports.unknown().optional().describe("Called when a client disconnects."),
|
|
15449
|
+
onBeforeActionResponse: external_exports.unknown().optional().describe(
|
|
15450
|
+
"Called before sending an action response. Use to transform output."
|
|
15451
|
+
),
|
|
15452
|
+
onRequest: external_exports.unknown().optional().describe(
|
|
15453
|
+
"Called for raw HTTP requests to /actors/{name}/http/* endpoints."
|
|
15454
|
+
),
|
|
15455
|
+
onWebSocket: external_exports.unknown().optional().describe(
|
|
15456
|
+
"Called for raw WebSocket connections to /actors/{name}/websocket/* endpoints."
|
|
15457
|
+
),
|
|
15458
|
+
actions: external_exports.record(external_exports.string(), external_exports.unknown()).optional().describe(
|
|
15459
|
+
"Tree of action names or nested groups to handler functions. Nested paths use dot-separated low-level action names. Defaults to an empty object."
|
|
15460
|
+
),
|
|
15461
|
+
actionInputSchemas: external_exports.record(external_exports.string(), external_exports.unknown()).optional().describe(
|
|
15462
|
+
"Optional schemas for validating action argument tuples in native runtimes. May mirror nested action groups or use dot-separated low-level action names."
|
|
15463
|
+
),
|
|
15464
|
+
tracing: external_exports.unknown().optional().describe(
|
|
15465
|
+
"Trace sampling for this actor: `sampler` is the share of its invocations that are recorded, from 0 to 1, with optional per-action rates under `actions`. A rate lowers what is recorded and never raises it. Defaults to the process sampler from OTEL_TRACES_SAMPLER."
|
|
15466
|
+
),
|
|
15467
|
+
connParamsSchema: external_exports.unknown().optional().describe(
|
|
15468
|
+
"Optional schema for validating connection params in native runtimes."
|
|
15469
|
+
),
|
|
15470
|
+
events: external_exports.record(external_exports.string(), external_exports.unknown()).optional().describe("Map of event names to schemas."),
|
|
15471
|
+
queues: external_exports.record(external_exports.string(), external_exports.unknown()).optional().describe("Map of queue names to schemas."),
|
|
15472
|
+
options: DocActorOptionsSchema.optional()
|
|
15473
|
+
}).describe("Actor configuration passed to the actor() function.");
|
|
15440
15474
|
|
|
15441
15475
|
// ../rivetkit/dist/tsup/chunk-JI6GZ2C2.js
|
|
15442
15476
|
var EMPTY_KEY = "/";
|
|
@@ -15555,7 +15589,7 @@ function removePrefixFromKey(prefixedKey) {
|
|
|
15555
15589
|
return prefixedKey.slice(KEYS.KV.length);
|
|
15556
15590
|
}
|
|
15557
15591
|
|
|
15558
|
-
// ../rivetkit/dist/tsup/chunk-
|
|
15592
|
+
// ../rivetkit/dist/tsup/chunk-2CI2IEVN.js
|
|
15559
15593
|
function logger() {
|
|
15560
15594
|
return getLogger("actor-client");
|
|
15561
15595
|
}
|
|
@@ -15676,7 +15710,7 @@ var AsyncMutex = class {
|
|
|
15676
15710
|
}
|
|
15677
15711
|
};
|
|
15678
15712
|
|
|
15679
|
-
// ../rivetkit/dist/tsup/chunk-
|
|
15713
|
+
// ../rivetkit/dist/tsup/chunk-PYRI75DL.js
|
|
15680
15714
|
var import_invariant2 = __toESM(require_invariant(), 1);
|
|
15681
15715
|
|
|
15682
15716
|
// ../../../node_modules/.pnpm/p-retry@6.2.1/node_modules/p-retry/index.js
|
|
@@ -16891,7 +16925,7 @@ var TraceAPI = (
|
|
|
16891
16925
|
// ../../../node_modules/.pnpm/@opentelemetry+api@1.9.0/node_modules/@opentelemetry/api/build/esm/trace-api.js
|
|
16892
16926
|
var trace = TraceAPI.getInstance();
|
|
16893
16927
|
|
|
16894
|
-
// ../rivetkit/dist/tsup/chunk-
|
|
16928
|
+
// ../rivetkit/dist/tsup/chunk-PYRI75DL.js
|
|
16895
16929
|
var import_invariant3 = __toESM(require_invariant(), 1);
|
|
16896
16930
|
var import_invariant4 = __toESM(require_invariant(), 1);
|
|
16897
16931
|
var PATH_CONNECT = "/connect";
|
|
@@ -19365,7 +19399,8 @@ async function sendHttpRequest(opts) {
|
|
|
19365
19399
|
{
|
|
19366
19400
|
metadata: responseData.metadata,
|
|
19367
19401
|
rayId: rayId ?? void 0,
|
|
19368
|
-
actor: responseData.actor
|
|
19402
|
+
actor: responseData.actor,
|
|
19403
|
+
statusCode: response.status
|
|
19369
19404
|
}
|
|
19370
19405
|
);
|
|
19371
19406
|
} catch (error46) {
|
|
@@ -20273,6 +20308,22 @@ var ActorHandleRaw = class {
|
|
|
20273
20308
|
"dynamic actor resolution did not produce a direct actor id"
|
|
20274
20309
|
);
|
|
20275
20310
|
}
|
|
20311
|
+
/** Issue a token scoped to this actor. Defaults to actor gateway read access. */
|
|
20312
|
+
async issueToken(options = {}) {
|
|
20313
|
+
const actorId = await this.resolve();
|
|
20314
|
+
const permissions = options.permissions ?? {
|
|
20315
|
+
actor_gateway: ["read"]
|
|
20316
|
+
};
|
|
20317
|
+
const grants = Object.keys(permissions).flatMap((resource) => {
|
|
20318
|
+
const operations = permissions[resource];
|
|
20319
|
+
return operations ? [{ resource, target: { id: actorId }, operations }] : [];
|
|
20320
|
+
});
|
|
20321
|
+
return this.#driver.issueToken({
|
|
20322
|
+
subject: options.subject,
|
|
20323
|
+
expiresIn: options.expiresIn,
|
|
20324
|
+
grants
|
|
20325
|
+
});
|
|
20326
|
+
}
|
|
20276
20327
|
/**
|
|
20277
20328
|
* Returns the raw URL for routing traffic to the actor.
|
|
20278
20329
|
*/
|
|
@@ -20305,6 +20356,8 @@ var ACTOR_CONNS_SYMBOL = /* @__PURE__ */ Symbol("actorConns");
|
|
|
20305
20356
|
var CREATE_ACTOR_CONN_PROXY = /* @__PURE__ */ Symbol("createActorConnProxy");
|
|
20306
20357
|
var ClientRaw = class {
|
|
20307
20358
|
#disposed = false;
|
|
20359
|
+
/** Issue namespace-scoped tokens with an explicit grant list. */
|
|
20360
|
+
auth;
|
|
20308
20361
|
[ACTOR_CONNS_SYMBOL] = /* @__PURE__ */ new Set();
|
|
20309
20362
|
#driver;
|
|
20310
20363
|
#encodingKind;
|
|
@@ -20316,6 +20369,9 @@ var ClientRaw = class {
|
|
|
20316
20369
|
*/
|
|
20317
20370
|
constructor(driver, options = {}) {
|
|
20318
20371
|
this.#driver = driver;
|
|
20372
|
+
this.auth = {
|
|
20373
|
+
issueToken: (issueOptions) => this.#driver.issueToken(issueOptions)
|
|
20374
|
+
};
|
|
20319
20375
|
this.#encodingKind = options.encoding ?? "bare";
|
|
20320
20376
|
this.#gatewayOptions = options.gateway ?? {};
|
|
20321
20377
|
this.#currentActorInvocation = options.currentActorInvocation;
|
|
@@ -20607,6 +20663,72 @@ function createActorProxy(handle) {
|
|
|
20607
20663
|
}
|
|
20608
20664
|
});
|
|
20609
20665
|
}
|
|
20666
|
+
function isInvalidToken(group, code) {
|
|
20667
|
+
return group === "auth" && (code === "invalid_token" || code === "token_expired");
|
|
20668
|
+
}
|
|
20669
|
+
function isInvalidTokenResponse(response) {
|
|
20670
|
+
if (response.status !== 401) return false;
|
|
20671
|
+
const error46 = response.headers.get("x-rivet-error");
|
|
20672
|
+
if (!error46) return false;
|
|
20673
|
+
const separator = error46.indexOf(".");
|
|
20674
|
+
return separator > 0 && isInvalidToken(error46.slice(0, separator), error46.slice(separator + 1));
|
|
20675
|
+
}
|
|
20676
|
+
var TokenProvider = class {
|
|
20677
|
+
constructor(getToken) {
|
|
20678
|
+
this.getToken = getToken;
|
|
20679
|
+
}
|
|
20680
|
+
#cached;
|
|
20681
|
+
#pending;
|
|
20682
|
+
#pendingForce = false;
|
|
20683
|
+
async current() {
|
|
20684
|
+
if (this.#cached && (this.#cached.expiresAt === void 0 || Date.now() < this.#cached.expiresAt - 5e3)) {
|
|
20685
|
+
return this.#cached.token;
|
|
20686
|
+
}
|
|
20687
|
+
return this.#load(false);
|
|
20688
|
+
}
|
|
20689
|
+
/** A late rejection for an older token must never erase a newer credential. */
|
|
20690
|
+
async refreshIfCurrent(failedToken) {
|
|
20691
|
+
var _a2;
|
|
20692
|
+
if (this.#pending !== void 0) {
|
|
20693
|
+
const wasForced = this.#pendingForce;
|
|
20694
|
+
const refreshed = await this.#pending;
|
|
20695
|
+
if (wasForced || refreshed !== failedToken) return refreshed;
|
|
20696
|
+
}
|
|
20697
|
+
if (((_a2 = this.#cached) == null ? void 0 : _a2.token) !== failedToken) {
|
|
20698
|
+
return this.current();
|
|
20699
|
+
}
|
|
20700
|
+
return this.#load(true);
|
|
20701
|
+
}
|
|
20702
|
+
#load(forceRefresh) {
|
|
20703
|
+
if (this.#pending !== void 0) return this.#pending;
|
|
20704
|
+
const pending = Promise.resolve().then(() => this.getToken({ forceRefresh })).then((token) => {
|
|
20705
|
+
if (typeof token !== "string" || token.length === 0) {
|
|
20706
|
+
throw new Error(
|
|
20707
|
+
"getToken must resolve to a nonempty string"
|
|
20708
|
+
);
|
|
20709
|
+
}
|
|
20710
|
+
this.#cached = { token, expiresAt: jwtExpiration(token) };
|
|
20711
|
+
return token;
|
|
20712
|
+
}).finally(() => {
|
|
20713
|
+
if (this.#pending === pending) this.#pending = void 0;
|
|
20714
|
+
});
|
|
20715
|
+
this.#pending = pending;
|
|
20716
|
+
this.#pendingForce = forceRefresh;
|
|
20717
|
+
return pending;
|
|
20718
|
+
}
|
|
20719
|
+
};
|
|
20720
|
+
function jwtExpiration(token) {
|
|
20721
|
+
try {
|
|
20722
|
+
const payload = token.split(".")[1];
|
|
20723
|
+
if (!payload) return void 0;
|
|
20724
|
+
const claims = JSON.parse(
|
|
20725
|
+
atob(payload.replace(/-/g, "+").replace(/_/g, "/"))
|
|
20726
|
+
);
|
|
20727
|
+
return typeof claims.exp === "number" && Number.isSafeInteger(claims.exp) ? claims.exp * 1e3 : void 0;
|
|
20728
|
+
} catch {
|
|
20729
|
+
return void 0;
|
|
20730
|
+
}
|
|
20731
|
+
}
|
|
20610
20732
|
var CONNECT_SYMBOL = /* @__PURE__ */ Symbol("connect");
|
|
20611
20733
|
var ActorConnRaw = class {
|
|
20612
20734
|
#disposed = false;
|
|
@@ -20635,6 +20757,7 @@ var ActorConnRaw = class {
|
|
|
20635
20757
|
/** Promise used to indicate the socket has connected successfully. This will be rejected if the connection fails. */
|
|
20636
20758
|
#onOpenPromise;
|
|
20637
20759
|
#websocket;
|
|
20760
|
+
#authRetryAvailable = true;
|
|
20638
20761
|
#client;
|
|
20639
20762
|
#driver;
|
|
20640
20763
|
#currentActorInvocation;
|
|
@@ -20880,6 +21003,10 @@ var ActorConnRaw = class {
|
|
|
20880
21003
|
if (error46 instanceof ActorConnDisposed) {
|
|
20881
21004
|
return false;
|
|
20882
21005
|
}
|
|
21006
|
+
if (error46 instanceof RivetError && isInvalidToken(error46.group, error46.code) && this.#driver.refreshAuthToken && this.#authRetryAvailable) {
|
|
21007
|
+
this.#authRetryAvailable = false;
|
|
21008
|
+
return true;
|
|
21009
|
+
}
|
|
20883
21010
|
if (error46 instanceof RivetError && this.#shouldReconnectForStaleActor(error46.group, error46.code)) {
|
|
20884
21011
|
return true;
|
|
20885
21012
|
}
|
|
@@ -21004,6 +21131,7 @@ var ActorConnRaw = class {
|
|
|
21004
21131
|
messageQueueLength: this.#messageQueue.length,
|
|
21005
21132
|
connId: this.#connId
|
|
21006
21133
|
});
|
|
21134
|
+
this.#authRetryAvailable = true;
|
|
21007
21135
|
this.#setConnStatus("connected");
|
|
21008
21136
|
if (this.#onOpenPromise) {
|
|
21009
21137
|
this.#onOpenPromise.resolve(void 0);
|
|
@@ -21146,7 +21274,8 @@ var ActorConnRaw = class {
|
|
|
21146
21274
|
}
|
|
21147
21275
|
/** Called by the onclose event from drivers. */
|
|
21148
21276
|
async #handleOnClose(event2) {
|
|
21149
|
-
var _a2;
|
|
21277
|
+
var _a2, _b, _c;
|
|
21278
|
+
const failedSocket = this.#websocket;
|
|
21150
21279
|
const closeEvent = event2;
|
|
21151
21280
|
const wasClean = closeEvent.wasClean;
|
|
21152
21281
|
const wasConnected = this.#connStatus === "connected";
|
|
@@ -21168,9 +21297,24 @@ var ActorConnRaw = class {
|
|
|
21168
21297
|
const parsed = parseWebSocketCloseReason(reason);
|
|
21169
21298
|
if (parsed) {
|
|
21170
21299
|
const { group, code, rayId } = parsed;
|
|
21300
|
+
if (isInvalidToken(group, code) && closeEvent.code === 1008 && failedSocket) {
|
|
21301
|
+
try {
|
|
21302
|
+
if (!await ((_b = (_a2 = this.#driver).refreshAuthToken) == null ? void 0 : _b.call(
|
|
21303
|
+
_a2,
|
|
21304
|
+
failedSocket
|
|
21305
|
+
))) {
|
|
21306
|
+
this.#authRetryAvailable = false;
|
|
21307
|
+
}
|
|
21308
|
+
} catch {
|
|
21309
|
+
logger().warn("token renewal failed");
|
|
21310
|
+
this.#authRetryAvailable = false;
|
|
21311
|
+
}
|
|
21312
|
+
} else if (isInvalidToken(group, code)) {
|
|
21313
|
+
this.#authRetryAvailable = false;
|
|
21314
|
+
}
|
|
21171
21315
|
if (this.#shouldReconnectForStaleActor(group, code)) {
|
|
21172
21316
|
this.#clearResolvedActorIdentity();
|
|
21173
|
-
(
|
|
21317
|
+
(_c = this.#onOpenPromise) == null ? void 0 : _c.reject(
|
|
21174
21318
|
new RivetError(
|
|
21175
21319
|
group,
|
|
21176
21320
|
code,
|
|
@@ -21217,7 +21361,7 @@ var ActorConnRaw = class {
|
|
|
21217
21361
|
if (error46 instanceof RivetError) {
|
|
21218
21362
|
this.#dispatchActorError(error46);
|
|
21219
21363
|
}
|
|
21220
|
-
if (wasConnected) {
|
|
21364
|
+
if (wasConnected && this.#authRetryAvailable) {
|
|
21221
21365
|
logger().debug({
|
|
21222
21366
|
msg: "triggering reconnect",
|
|
21223
21367
|
connId: this.#connId
|
|
@@ -21686,6 +21830,23 @@ var ActorConnRaw = class {
|
|
|
21686
21830
|
);
|
|
21687
21831
|
}
|
|
21688
21832
|
};
|
|
21833
|
+
var ENGINE_HOST = "127.0.0.1";
|
|
21834
|
+
var ENGINE_PORT = 6420;
|
|
21835
|
+
var ENGINE_ENDPOINT = buildEngineEndpoint(ENGINE_HOST, ENGINE_PORT);
|
|
21836
|
+
function buildEngineEndpoint(host, port) {
|
|
21837
|
+
const urlHost = host.includes(":") && !host.startsWith("[") ? `[${host}]` : host;
|
|
21838
|
+
return `http://${urlHost}:${port}`;
|
|
21839
|
+
}
|
|
21840
|
+
function isLocalEngineEndpoint(endpoint) {
|
|
21841
|
+
let url2;
|
|
21842
|
+
try {
|
|
21843
|
+
url2 = new URL(endpoint);
|
|
21844
|
+
} catch {
|
|
21845
|
+
return false;
|
|
21846
|
+
}
|
|
21847
|
+
const hostname3 = url2.hostname.toLowerCase();
|
|
21848
|
+
return hostname3 === "localhost" || hostname3 === "0.0.0.0" || hostname3 === "::" || hostname3 === "[::]" || hostname3 === "::1" || hostname3 === "[::1]" || /^127(?:\.\d{1,3}){0,3}$/.test(hostname3);
|
|
21849
|
+
}
|
|
21689
21850
|
function tryParseEndpoint(ctx, options) {
|
|
21690
21851
|
const {
|
|
21691
21852
|
endpoint,
|
|
@@ -21780,6 +21941,8 @@ var ClientConfigSchemaBase = v4_default.object({
|
|
|
21780
21941
|
}),
|
|
21781
21942
|
/** Token to use to authenticate with the API. */
|
|
21782
21943
|
token: v4_default.string().optional().transform((val) => val ?? getRivetToken()),
|
|
21944
|
+
/** Issue and renew a client token on demand. Overrides the static token when provided. */
|
|
21945
|
+
getToken: v4_default.custom().optional(),
|
|
21783
21946
|
/** Namespace to connect to. */
|
|
21784
21947
|
namespace: v4_default.string().optional().transform((val) => val ?? getRivetNamespace()),
|
|
21785
21948
|
/** Name of the envoy pool. This is used to group together envoys in to different pools. */
|
|
@@ -21824,7 +21987,7 @@ function transformClientConfig(config3, ctx) {
|
|
|
21824
21987
|
...config3,
|
|
21825
21988
|
endpoint: parsedEndpoint == null ? void 0 : parsedEndpoint.endpoint,
|
|
21826
21989
|
namespace: (parsedEndpoint == null ? void 0 : parsedEndpoint.namespace) ?? config3.namespace ?? "default",
|
|
21827
|
-
token: (parsedEndpoint == null ? void 0 : parsedEndpoint.token) ?? config3.token
|
|
21990
|
+
token: (parsedEndpoint == null ? void 0 : parsedEndpoint.token) ?? config3.token ?? (config3.endpoint && isLocalEngineEndpoint(config3.endpoint) ? "default" : void 0)
|
|
21828
21991
|
};
|
|
21829
21992
|
}
|
|
21830
21993
|
function convertRegistryConfigToClientConfig(config3) {
|
|
@@ -21832,6 +21995,7 @@ function convertRegistryConfigToClientConfig(config3) {
|
|
|
21832
21995
|
return {
|
|
21833
21996
|
endpoint: config3.endpoint,
|
|
21834
21997
|
token: config3.token,
|
|
21998
|
+
getToken: void 0,
|
|
21835
21999
|
namespace: config3.namespace,
|
|
21836
22000
|
poolName: config3.envoy.poolName,
|
|
21837
22001
|
headers: config3.headers,
|
|
@@ -22163,7 +22327,8 @@ async function openWebSocketToGateway(runConfig, gatewayUrl, encoding, params, o
|
|
|
22163
22327
|
const ackHookToken = typeof process !== "undefined" && process.env.VITEST ? crypto.randomUUID() : void 0;
|
|
22164
22328
|
logger2().debug({
|
|
22165
22329
|
msg: "opening websocket to actor via guard",
|
|
22166
|
-
|
|
22330
|
+
// Gateway URLs can embed credentials; never include the path or query in logs.
|
|
22331
|
+
origin: new URL(gatewayUrl).origin
|
|
22167
22332
|
});
|
|
22168
22333
|
const ws = new WebSocket2(
|
|
22169
22334
|
gatewayUrl,
|
|
@@ -22253,6 +22418,14 @@ async function apiCall(config3, method2, path2, body) {
|
|
|
22253
22418
|
responseFromBare: (value) => value
|
|
22254
22419
|
});
|
|
22255
22420
|
}
|
|
22421
|
+
async function issueToken(config3, options) {
|
|
22422
|
+
return apiCall(config3, "POST", "/auth/tokens", {
|
|
22423
|
+
namespace: config3.namespace,
|
|
22424
|
+
subject: options.subject,
|
|
22425
|
+
duration: options.expiresIn,
|
|
22426
|
+
grants: options.grants
|
|
22427
|
+
});
|
|
22428
|
+
}
|
|
22256
22429
|
async function getActor(config3, _, actorId) {
|
|
22257
22430
|
return apiCall(
|
|
22258
22431
|
config3,
|
|
@@ -22494,6 +22667,8 @@ function closeWebSocketIfOpen(ws, code, reason) {
|
|
|
22494
22667
|
var RemoteEngineControlClient = class {
|
|
22495
22668
|
#config;
|
|
22496
22669
|
#metadataPromise;
|
|
22670
|
+
#tokenProvider;
|
|
22671
|
+
#webSocketTokens = /* @__PURE__ */ new WeakMap();
|
|
22497
22672
|
constructor(runConfig) {
|
|
22498
22673
|
if (getNextPhase() === "phase-production-build") {
|
|
22499
22674
|
logger2().info(
|
|
@@ -22502,6 +22677,8 @@ var RemoteEngineControlClient = class {
|
|
|
22502
22677
|
runConfig.disableMetadataLookup = true;
|
|
22503
22678
|
}
|
|
22504
22679
|
this.#config = { ...runConfig };
|
|
22680
|
+
if (runConfig.getToken)
|
|
22681
|
+
this.#tokenProvider = new TokenProvider(runConfig.getToken);
|
|
22505
22682
|
if (!runConfig.disableMetadataLookup) {
|
|
22506
22683
|
this.#metadataPromise = lookupMetadataCached(this.#config).then(
|
|
22507
22684
|
(metadataData) => {
|
|
@@ -22510,14 +22687,13 @@ var RemoteEngineControlClient = class {
|
|
|
22510
22687
|
if (metadataData.clientNamespace) {
|
|
22511
22688
|
this.#config.namespace = metadataData.clientNamespace;
|
|
22512
22689
|
}
|
|
22513
|
-
if (metadataData.clientToken) {
|
|
22690
|
+
if (metadataData.clientToken && !this.#tokenProvider) {
|
|
22514
22691
|
this.#config.token = metadataData.clientToken;
|
|
22515
22692
|
}
|
|
22516
22693
|
logger2().info({
|
|
22517
22694
|
msg: "overriding client endpoint",
|
|
22518
22695
|
endpoint: metadataData.clientEndpoint,
|
|
22519
|
-
namespace: metadataData.clientNamespace
|
|
22520
|
-
token: metadataData.clientToken
|
|
22696
|
+
namespace: metadataData.clientNamespace
|
|
22521
22697
|
});
|
|
22522
22698
|
}
|
|
22523
22699
|
logger2().info({
|
|
@@ -22530,12 +22706,47 @@ var RemoteEngineControlClient = class {
|
|
|
22530
22706
|
);
|
|
22531
22707
|
}
|
|
22532
22708
|
}
|
|
22709
|
+
async #authorizedConfig() {
|
|
22710
|
+
if (!this.#tokenProvider) return this.#config;
|
|
22711
|
+
return { ...this.#config, token: await this.#tokenProvider.current() };
|
|
22712
|
+
}
|
|
22713
|
+
async #withCredential(request, readOnly = false) {
|
|
22714
|
+
const config3 = await this.#authorizedConfig();
|
|
22715
|
+
try {
|
|
22716
|
+
return await request(config3);
|
|
22717
|
+
} catch (error46) {
|
|
22718
|
+
if (this.#tokenProvider && config3.token && error46 instanceof RivetError && error46.statusCode === 401 && isInvalidToken(error46.group, error46.code)) {
|
|
22719
|
+
if (readOnly) {
|
|
22720
|
+
const token = await this.#tokenProvider.refreshIfCurrent(
|
|
22721
|
+
config3.token
|
|
22722
|
+
);
|
|
22723
|
+
return request({ ...this.#config, token });
|
|
22724
|
+
}
|
|
22725
|
+
await this.#tokenProvider.refreshIfCurrent(config3.token);
|
|
22726
|
+
}
|
|
22727
|
+
throw error46;
|
|
22728
|
+
}
|
|
22729
|
+
}
|
|
22730
|
+
async issueToken(options) {
|
|
22731
|
+
await this.#metadataPromise;
|
|
22732
|
+
const response = await this.#withCredential(
|
|
22733
|
+
(config3) => issueToken(config3, options)
|
|
22734
|
+
);
|
|
22735
|
+
return {
|
|
22736
|
+
token: response.token,
|
|
22737
|
+
issuedAt: response.issued_ts,
|
|
22738
|
+
expiresAt: response.expires_ts
|
|
22739
|
+
};
|
|
22740
|
+
}
|
|
22533
22741
|
async getForId({
|
|
22534
22742
|
name,
|
|
22535
22743
|
actorId
|
|
22536
22744
|
}) {
|
|
22537
22745
|
await this.#metadataPromise;
|
|
22538
|
-
const response = await
|
|
22746
|
+
const response = await this.#withCredential(
|
|
22747
|
+
(config3) => getActor(config3, name, actorId),
|
|
22748
|
+
true
|
|
22749
|
+
);
|
|
22539
22750
|
const actor2 = response.actors[0];
|
|
22540
22751
|
if (!actor2) return void 0;
|
|
22541
22752
|
if (actor2.name !== name) {
|
|
@@ -22556,7 +22767,10 @@ var RemoteEngineControlClient = class {
|
|
|
22556
22767
|
await this.#metadataPromise;
|
|
22557
22768
|
logger2().debug({ msg: "getWithKey: searching for actor", name, key });
|
|
22558
22769
|
try {
|
|
22559
|
-
const response = await
|
|
22770
|
+
const response = await this.#withCredential(
|
|
22771
|
+
(config3) => getActorByKey(config3, name, key),
|
|
22772
|
+
true
|
|
22773
|
+
);
|
|
22560
22774
|
const actor2 = response.actors[0];
|
|
22561
22775
|
if (!actor2) return void 0;
|
|
22562
22776
|
logger2().debug({
|
|
@@ -22589,16 +22803,18 @@ var RemoteEngineControlClient = class {
|
|
|
22589
22803
|
key
|
|
22590
22804
|
});
|
|
22591
22805
|
try {
|
|
22592
|
-
const { actor: actor2, created } = await
|
|
22593
|
-
|
|
22594
|
-
|
|
22595
|
-
|
|
22596
|
-
|
|
22597
|
-
|
|
22598
|
-
|
|
22599
|
-
|
|
22600
|
-
|
|
22601
|
-
|
|
22806
|
+
const { actor: actor2, created } = await this.#withCredential(
|
|
22807
|
+
(config3) => getOrCreateActor(config3, {
|
|
22808
|
+
datacenter: region,
|
|
22809
|
+
name,
|
|
22810
|
+
key: serializeActorKey(key),
|
|
22811
|
+
runner_name_selector: poolName ?? this.#config.poolName,
|
|
22812
|
+
input: actorInput ? uint8ArrayToBase642(
|
|
22813
|
+
encodeCborCompat(actorInput)
|
|
22814
|
+
) : void 0,
|
|
22815
|
+
crash_policy: crashPolicy ?? "sleep"
|
|
22816
|
+
})
|
|
22817
|
+
);
|
|
22602
22818
|
logger2().info({
|
|
22603
22819
|
msg: "getOrCreateWithKey: actor ready",
|
|
22604
22820
|
actorId: actor2.actor_id,
|
|
@@ -22614,7 +22830,10 @@ var RemoteEngineControlClient = class {
|
|
|
22614
22830
|
name,
|
|
22615
22831
|
key
|
|
22616
22832
|
});
|
|
22617
|
-
const response = await
|
|
22833
|
+
const response = await this.#withCredential(
|
|
22834
|
+
(config3) => getActorByKey(config3, name, key),
|
|
22835
|
+
true
|
|
22836
|
+
);
|
|
22618
22837
|
const existing = response.actors[0];
|
|
22619
22838
|
if (!existing) throw error46;
|
|
22620
22839
|
logger2().info({
|
|
@@ -22638,14 +22857,18 @@ var RemoteEngineControlClient = class {
|
|
|
22638
22857
|
}) {
|
|
22639
22858
|
await this.#metadataPromise;
|
|
22640
22859
|
logger2().info({ msg: "creating actor via engine api", name, key });
|
|
22641
|
-
const result = await
|
|
22642
|
-
|
|
22643
|
-
|
|
22644
|
-
|
|
22645
|
-
|
|
22646
|
-
|
|
22647
|
-
|
|
22648
|
-
|
|
22860
|
+
const result = await this.#withCredential(
|
|
22861
|
+
(config3) => createActor(config3, {
|
|
22862
|
+
datacenter: region,
|
|
22863
|
+
name,
|
|
22864
|
+
runner_name_selector: poolName ?? this.#config.poolName,
|
|
22865
|
+
key: serializeActorKey(key),
|
|
22866
|
+
input: input ? uint8ArrayToBase642(
|
|
22867
|
+
encodeCborCompat(input)
|
|
22868
|
+
) : void 0,
|
|
22869
|
+
crash_policy: crashPolicy ?? "sleep"
|
|
22870
|
+
})
|
|
22871
|
+
);
|
|
22649
22872
|
logger2().info({
|
|
22650
22873
|
msg: "actor created",
|
|
22651
22874
|
actorId: result.actor.actor_id,
|
|
@@ -22657,43 +22880,61 @@ var RemoteEngineControlClient = class {
|
|
|
22657
22880
|
async listActors({ name }) {
|
|
22658
22881
|
await this.#metadataPromise;
|
|
22659
22882
|
logger2().debug({ msg: "listing actors via engine api", name });
|
|
22660
|
-
const response = await
|
|
22883
|
+
const response = await this.#withCredential(
|
|
22884
|
+
(config3) => listActorsByName(config3, name),
|
|
22885
|
+
true
|
|
22886
|
+
);
|
|
22661
22887
|
return response.actors.map(apiActorToOutput);
|
|
22662
22888
|
}
|
|
22663
22889
|
async destroyActor(actorId) {
|
|
22664
22890
|
await this.#metadataPromise;
|
|
22665
22891
|
logger2().info({ msg: "destroying actor via engine api", actorId });
|
|
22666
|
-
await destroyActor(
|
|
22892
|
+
await this.#withCredential((config3) => destroyActor(config3, actorId));
|
|
22667
22893
|
logger2().info({ msg: "actor destroyed", actorId });
|
|
22668
22894
|
}
|
|
22669
22895
|
async sendRequest(target, actorRequest, options = {}) {
|
|
22896
|
+
var _a2;
|
|
22670
22897
|
await this.#metadataPromise;
|
|
22671
|
-
const
|
|
22672
|
-
const gatewayUrl = this.#buildGatewayUrlForTarget(
|
|
22673
|
-
target,
|
|
22674
|
-
path2,
|
|
22675
|
-
options
|
|
22676
|
-
);
|
|
22898
|
+
const config3 = await this.#authorizedConfig();
|
|
22677
22899
|
const httpOptions = {
|
|
22678
22900
|
...options,
|
|
22679
22901
|
directActorId: shouldSkipReadyWait(options) ? directActorIdFromTarget(target) : void 0
|
|
22680
22902
|
};
|
|
22681
|
-
|
|
22682
|
-
|
|
22683
|
-
|
|
22903
|
+
const send = (current) => sendHttpRequestToGateway(
|
|
22904
|
+
current,
|
|
22905
|
+
this.#buildGatewayUrlForTarget(
|
|
22906
|
+
current,
|
|
22907
|
+
target,
|
|
22908
|
+
requestPath(actorRequest),
|
|
22909
|
+
options
|
|
22910
|
+
),
|
|
22684
22911
|
actorRequest,
|
|
22685
22912
|
httpOptions
|
|
22686
22913
|
);
|
|
22914
|
+
const response = await send(config3);
|
|
22915
|
+
if (!this.#tokenProvider || !config3.token || !isInvalidTokenResponse(response))
|
|
22916
|
+
return response;
|
|
22917
|
+
if ((actorRequest.method === "GET" || actorRequest.method === "HEAD") && !("getOrCreateForKey" in target)) {
|
|
22918
|
+
const token = await this.#tokenProvider.refreshIfCurrent(
|
|
22919
|
+
config3.token
|
|
22920
|
+
);
|
|
22921
|
+
await ((_a2 = response.body) == null ? void 0 : _a2.cancel());
|
|
22922
|
+
return send({ ...this.#config, token });
|
|
22923
|
+
}
|
|
22924
|
+
await this.#tokenProvider.refreshIfCurrent(config3.token);
|
|
22925
|
+
return response;
|
|
22687
22926
|
}
|
|
22688
22927
|
async openWebSocket(path2, target, encoding, params, options = {}) {
|
|
22689
22928
|
await this.#metadataPromise;
|
|
22929
|
+
const config3 = await this.#authorizedConfig();
|
|
22690
22930
|
const gatewayUrl = this.#buildGatewayUrlForTarget(
|
|
22931
|
+
config3,
|
|
22691
22932
|
target,
|
|
22692
22933
|
path2,
|
|
22693
22934
|
options
|
|
22694
22935
|
);
|
|
22695
|
-
|
|
22696
|
-
|
|
22936
|
+
const ws = await openWebSocketToGateway(
|
|
22937
|
+
config3,
|
|
22697
22938
|
gatewayUrl,
|
|
22698
22939
|
encoding,
|
|
22699
22940
|
params,
|
|
@@ -22702,25 +22943,59 @@ var RemoteEngineControlClient = class {
|
|
|
22702
22943
|
directActorId: shouldSkipReadyWait(options) ? directActorIdFromTarget(target) : void 0
|
|
22703
22944
|
}
|
|
22704
22945
|
);
|
|
22946
|
+
this.#watchWebSocketAuth(ws, config3.token);
|
|
22947
|
+
return ws;
|
|
22948
|
+
}
|
|
22949
|
+
async refreshAuthToken(ws) {
|
|
22950
|
+
const context2 = this.#webSocketTokens.get(ws);
|
|
22951
|
+
if (!(context2 == null ? void 0 : context2.refresh)) return false;
|
|
22952
|
+
await context2.refresh;
|
|
22953
|
+
return true;
|
|
22954
|
+
}
|
|
22955
|
+
#watchWebSocketAuth(ws, token) {
|
|
22956
|
+
const tokenProvider = this.#tokenProvider;
|
|
22957
|
+
if (!tokenProvider || !token) return;
|
|
22958
|
+
const context2 = {};
|
|
22959
|
+
this.#webSocketTokens.set(ws, context2);
|
|
22960
|
+
ws.addEventListener(
|
|
22961
|
+
"close",
|
|
22962
|
+
(event2) => {
|
|
22963
|
+
if (event2.code !== 1008 || !event2.reason) return;
|
|
22964
|
+
const separator = event2.reason.indexOf(".");
|
|
22965
|
+
if (separator < 0) return;
|
|
22966
|
+
const code = event2.reason.slice(separator + 1).split(/[\s:#]/, 1)[0];
|
|
22967
|
+
if (isInvalidToken(event2.reason.slice(0, separator), code)) {
|
|
22968
|
+
context2.refresh = tokenProvider.refreshIfCurrent(token).catch((error46) => {
|
|
22969
|
+
logger2().warn(
|
|
22970
|
+
"failed to renew authentication token"
|
|
22971
|
+
);
|
|
22972
|
+
throw error46;
|
|
22973
|
+
});
|
|
22974
|
+
context2.refresh.catch(() => {
|
|
22975
|
+
});
|
|
22976
|
+
}
|
|
22977
|
+
}
|
|
22978
|
+
);
|
|
22705
22979
|
}
|
|
22706
22980
|
async buildGatewayUrl(target, options = {}) {
|
|
22707
22981
|
await this.#metadataPromise;
|
|
22708
|
-
return this.#buildGatewayUrlForTarget(
|
|
22982
|
+
return this.#buildGatewayUrlForTarget(
|
|
22983
|
+
await this.#authorizedConfig(),
|
|
22984
|
+
target,
|
|
22985
|
+
"",
|
|
22986
|
+
options
|
|
22987
|
+
);
|
|
22709
22988
|
}
|
|
22710
22989
|
async proxyRequest(_c, actorRequest, actorId) {
|
|
22711
|
-
|
|
22712
|
-
const gatewayUrl = this.#buildGatewayUrlForTarget(
|
|
22713
|
-
{ directId: actorId },
|
|
22714
|
-
requestPath(actorRequest)
|
|
22715
|
-
);
|
|
22716
|
-
return sendHttpRequestToGateway(this.#config, gatewayUrl, actorRequest);
|
|
22990
|
+
return this.sendRequest({ directId: actorId }, actorRequest);
|
|
22717
22991
|
}
|
|
22718
22992
|
async proxyWebSocket(c, path2, actorId, encoding, params) {
|
|
22719
|
-
var _a2
|
|
22993
|
+
var _a2;
|
|
22720
22994
|
await this.#metadataPromise;
|
|
22721
|
-
const
|
|
22995
|
+
const config3 = await this.#authorizedConfig();
|
|
22996
|
+
const upgradeWebSocket = (_a2 = config3.getUpgradeWebSocket) == null ? void 0 : _a2.call(config3);
|
|
22722
22997
|
(0, import_invariant4.default)(upgradeWebSocket, "missing getUpgradeWebSocket");
|
|
22723
|
-
const endpoint = getEndpoint(
|
|
22998
|
+
const endpoint = getEndpoint(config3);
|
|
22724
22999
|
const guardUrl = combineUrlPath(endpoint, path2);
|
|
22725
23000
|
const wsGuardUrl = guardUrl.replace("http://", "ws://");
|
|
22726
23001
|
logger2().debug({
|
|
@@ -22730,7 +23005,7 @@ var RemoteEngineControlClient = class {
|
|
|
22730
23005
|
guardUrl
|
|
22731
23006
|
});
|
|
22732
23007
|
const protocols = buildWebSocketProtocols(
|
|
22733
|
-
|
|
23008
|
+
config3,
|
|
22734
23009
|
encoding,
|
|
22735
23010
|
params,
|
|
22736
23011
|
void 0,
|
|
@@ -22748,8 +23023,8 @@ var RemoteEngineControlClient = class {
|
|
|
22748
23023
|
setGetUpgradeWebSocket(getUpgradeWebSocket) {
|
|
22749
23024
|
this.#config.getUpgradeWebSocket = getUpgradeWebSocket;
|
|
22750
23025
|
}
|
|
22751
|
-
#buildGatewayUrlForTarget(target, path2, options = {}) {
|
|
22752
|
-
const endpoint = getEndpoint(
|
|
23026
|
+
#buildGatewayUrlForTarget(config3, target, path2, options = {}) {
|
|
23027
|
+
const endpoint = getEndpoint(config3);
|
|
22753
23028
|
if (shouldSkipReadyWait(options) && directActorIdFromTarget(target) && canUseDirectSkipReadyWaitPath(path2)) {
|
|
22754
23029
|
return combineUrlPath(endpoint, path2);
|
|
22755
23030
|
}
|
|
@@ -22757,7 +23032,7 @@ var RemoteEngineControlClient = class {
|
|
|
22757
23032
|
return buildActorGatewayUrl(
|
|
22758
23033
|
endpoint,
|
|
22759
23034
|
target.directId,
|
|
22760
|
-
|
|
23035
|
+
config3.token,
|
|
22761
23036
|
path2
|
|
22762
23037
|
);
|
|
22763
23038
|
}
|
|
@@ -22765,20 +23040,20 @@ var RemoteEngineControlClient = class {
|
|
|
22765
23040
|
return buildActorGatewayUrl(
|
|
22766
23041
|
endpoint,
|
|
22767
23042
|
target.getForId.actorId,
|
|
22768
|
-
|
|
23043
|
+
config3.token,
|
|
22769
23044
|
path2
|
|
22770
23045
|
);
|
|
22771
23046
|
}
|
|
22772
23047
|
if ("getForKey" in target || "getOrCreateForKey" in target) {
|
|
22773
23048
|
return buildActorQueryGatewayUrl(
|
|
22774
23049
|
endpoint,
|
|
22775
|
-
|
|
23050
|
+
config3.namespace,
|
|
22776
23051
|
target,
|
|
22777
|
-
|
|
23052
|
+
config3.token,
|
|
22778
23053
|
path2,
|
|
22779
|
-
|
|
23054
|
+
config3.maxInputSize,
|
|
22780
23055
|
void 0,
|
|
22781
|
-
"getOrCreateForKey" in target ? target.getOrCreateForKey.poolName ??
|
|
23056
|
+
"getOrCreateForKey" in target ? target.getOrCreateForKey.poolName ?? config3.poolName : void 0,
|
|
22782
23057
|
options
|
|
22783
23058
|
);
|
|
22784
23059
|
}
|
|
@@ -22827,7 +23102,7 @@ function apiActorToOutput(actor2) {
|
|
|
22827
23102
|
};
|
|
22828
23103
|
}
|
|
22829
23104
|
|
|
22830
|
-
// ../rivetkit/dist/tsup/chunk-
|
|
23105
|
+
// ../rivetkit/dist/tsup/chunk-5EGLHQJJ.js
|
|
22831
23106
|
var nativeStateTransactionOpeners = /* @__PURE__ */ new WeakMap();
|
|
22832
23107
|
var nativeStateTransactionClientBinders = /* @__PURE__ */ new WeakMap();
|
|
22833
23108
|
function registerNativeStateTransactionOpener(provider, opener) {
|
|
@@ -24320,12 +24595,14 @@ function isStaticActorInstance(_actor) {
|
|
|
24320
24595
|
return true;
|
|
24321
24596
|
}
|
|
24322
24597
|
function actor(input) {
|
|
24598
|
+
var _a2;
|
|
24323
24599
|
warnDeprecatedOptionKeys(
|
|
24324
24600
|
input == null ? void 0 : input.options
|
|
24325
24601
|
);
|
|
24326
24602
|
const config3 = ActorConfigSchema.parse(input);
|
|
24327
24603
|
flattenActionHandlers(config3.actions);
|
|
24328
24604
|
flattenActionInputSchemas(config3.actions, config3.actionInputSchemas);
|
|
24605
|
+
flattenActionTraceSamplers(config3.actions, (_a2 = config3.tracing) == null ? void 0 : _a2.actions);
|
|
24329
24606
|
return new ActorDefinition(config3);
|
|
24330
24607
|
}
|
|
24331
24608
|
function isStaticActorDefinition(definition) {
|
|
@@ -24567,23 +24844,6 @@ var InlineWebSocketAdapter = class {
|
|
|
24567
24844
|
}
|
|
24568
24845
|
}
|
|
24569
24846
|
};
|
|
24570
|
-
var ENGINE_HOST = "127.0.0.1";
|
|
24571
|
-
var ENGINE_PORT = 6420;
|
|
24572
|
-
var ENGINE_ENDPOINT = buildEngineEndpoint(ENGINE_HOST, ENGINE_PORT);
|
|
24573
|
-
function buildEngineEndpoint(host, port) {
|
|
24574
|
-
const urlHost = host.includes(":") && !host.startsWith("[") ? `[${host}]` : host;
|
|
24575
|
-
return `http://${urlHost}:${port}`;
|
|
24576
|
-
}
|
|
24577
|
-
function isLocalEngineEndpoint(endpoint) {
|
|
24578
|
-
let url2;
|
|
24579
|
-
try {
|
|
24580
|
-
url2 = new URL(endpoint);
|
|
24581
|
-
} catch {
|
|
24582
|
-
return false;
|
|
24583
|
-
}
|
|
24584
|
-
const hostname3 = url2.hostname.toLowerCase();
|
|
24585
|
-
return hostname3 === "localhost" || hostname3 === "0.0.0.0" || hostname3 === "::" || hostname3 === "[::]" || hostname3 === "::1" || hostname3 === "[::1]" || /^127(?:\.\d{1,3}){0,3}$/.test(hostname3);
|
|
24586
|
-
}
|
|
24587
24847
|
function logger22() {
|
|
24588
24848
|
return getLogger("registry");
|
|
24589
24849
|
}
|
|
@@ -24681,20 +24941,9 @@ async function configureServerlessPool(config3) {
|
|
|
24681
24941
|
});
|
|
24682
24942
|
throw lastError;
|
|
24683
24943
|
}
|
|
24684
|
-
var warnedMissingVersion = false;
|
|
24685
24944
|
var EnvoyConfigSchema = external_exports.object({
|
|
24686
24945
|
poolName: external_exports.string().default(() => getRivetPool() ?? "default"),
|
|
24687
|
-
version: external_exports.number().default(() =>
|
|
24688
|
-
const version2 = getRivetEnvoyVersion();
|
|
24689
|
-
if (version2 !== void 0) return version2;
|
|
24690
|
-
if (getNodeEnv() === "production" && !warnedMissingVersion) {
|
|
24691
|
-
warnedMissingVersion = true;
|
|
24692
|
-
getLogger("rivetkit").error(
|
|
24693
|
-
"RIVET_ENVOY_VERSION is not set. Actors will not be versioned, which means they won't be drained on deploy. This is only needed when self-hosting or using a custom envoy (not needed for Rivet Compute). Set this as a build arg in your Dockerfile. See https://rivet.dev/docs/actors/versions"
|
|
24694
|
-
);
|
|
24695
|
-
}
|
|
24696
|
-
return 1;
|
|
24697
|
-
}),
|
|
24946
|
+
version: external_exports.number().default(() => getRivetEnvoyVersion() ?? 1),
|
|
24698
24947
|
// Deprecated.
|
|
24699
24948
|
totalSlots: external_exports.number().default(() => getRivetTotalSlots() ?? 1e5),
|
|
24700
24949
|
envoyKey: external_exports.string().optional()
|
|
@@ -24994,7 +25243,7 @@ var RegistryConfigSchema = external_exports.object({
|
|
|
24994
25243
|
config3.startEngine || parsedEndpoint
|
|
24995
25244
|
);
|
|
24996
25245
|
const namespace = (parsedEndpoint == null ? void 0 : parsedEndpoint.namespace) ?? config3.namespace ?? "default";
|
|
24997
|
-
const token = (parsedEndpoint == null ? void 0 : parsedEndpoint.token) ?? config3.token ?? "
|
|
25246
|
+
const token = (parsedEndpoint == null ? void 0 : parsedEndpoint.token) ?? config3.token ?? (endpoint && isLocalEngineEndpoint(endpoint) ? "default" : void 0);
|
|
24998
25247
|
const parsedPublicEndpoint = config3.serverless.publicEndpoint ? tryParseEndpoint(ctx, {
|
|
24999
25248
|
endpoint: config3.serverless.publicEndpoint,
|
|
25000
25249
|
path: ["serverless", "publicEndpoint"]
|
|
@@ -30198,6 +30447,13 @@ function withConnContext(runtime, ctx, conn, clientFactory, schemas = {}, databa
|
|
|
30198
30447
|
)
|
|
30199
30448
|
});
|
|
30200
30449
|
}
|
|
30450
|
+
function buildActorTracingConfig(actions, tracing) {
|
|
30451
|
+
if (tracing === void 0) return void 0;
|
|
30452
|
+
return {
|
|
30453
|
+
sampler: tracing.sampler,
|
|
30454
|
+
actions: flattenActionTraceSamplers(actions, tracing.actions)
|
|
30455
|
+
};
|
|
30456
|
+
}
|
|
30201
30457
|
function buildActorConfig(definition, registryConfig, runtimeKind) {
|
|
30202
30458
|
var _a2;
|
|
30203
30459
|
const config3 = definition.config;
|
|
@@ -30211,6 +30467,10 @@ function buildActorConfig(definition, registryConfig, runtimeKind) {
|
|
|
30211
30467
|
hasDatabase: true,
|
|
30212
30468
|
remoteSqlite: usesRemoteSqlite,
|
|
30213
30469
|
sqliteProfiling,
|
|
30470
|
+
tracing: buildActorTracingConfig(
|
|
30471
|
+
definition.config.actions,
|
|
30472
|
+
definition.config.tracing
|
|
30473
|
+
),
|
|
30214
30474
|
enableActorRuntimeSocket: options.enableActorRuntimeSocket === true,
|
|
30215
30475
|
hasState: config3.state !== void 0 || typeof config3.createState === "function",
|
|
30216
30476
|
canHibernateWebsocket: typeof canHibernate === "boolean" ? canHibernate : void 0,
|
|
@@ -31948,7 +32208,23 @@ var Registry = class {
|
|
|
31948
32208
|
* Starts an actor envoy for standalone server deployments.
|
|
31949
32209
|
*/
|
|
31950
32210
|
#startEnvoy(config3, printWelcome) {
|
|
32211
|
+
var _a2;
|
|
31951
32212
|
if (!this.#runtimeServePromise) {
|
|
32213
|
+
const configuredEnvoyVersion = (_a2 = this.#config.envoy) == null ? void 0 : _a2.version;
|
|
32214
|
+
const envoyVersionSource = configuredEnvoyVersion !== void 0 ? "config" : getRivetEnvoyVersion() !== void 0 ? "environment" : "default";
|
|
32215
|
+
logger22().info({
|
|
32216
|
+
msg: "starting rivetkit envoy",
|
|
32217
|
+
rivetkitVersion: VERSION,
|
|
32218
|
+
envoyVersion: config3.envoy.version,
|
|
32219
|
+
envoyVersionSource
|
|
32220
|
+
});
|
|
32221
|
+
if (envoyVersionSource === "default" && getNodeEnv() === "production") {
|
|
32222
|
+
logger22().error({
|
|
32223
|
+
msg: "envoy version defaulted because neither config.envoy.version nor RIVET_ENVOY_VERSION is set; actors will not drain automatically across deploys. See https://rivet.dev/docs/actors/versions",
|
|
32224
|
+
envoyVersion: config3.envoy.version,
|
|
32225
|
+
envoyVersionSource
|
|
32226
|
+
});
|
|
32227
|
+
}
|
|
31952
32228
|
const configuredRegistryPromise = this.#buildConfiguredRegistry(config3);
|
|
31953
32229
|
this.#runtimeServeConfiguredPromise = configuredRegistryPromise;
|
|
31954
32230
|
this.#runtimeServeLifecyclePromise = configuredRegistryPromise.then(
|