@rivetkit/supabase 2.3.20 → 2.3.22
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 +1260 -996
- package/dist/mod.mjs +1263 -999
- package/package.json +4 -4
package/dist/mod.js
CHANGED
|
@@ -335,6 +335,212 @@ __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-ZOVJDAOW.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
|
+
const payload = {
|
|
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
|
+
try {
|
|
453
|
+
return {
|
|
454
|
+
encoded: `${BRIDGE_RIVET_ERROR_PREFIX}${JSON.stringify(payload)}`
|
|
455
|
+
};
|
|
456
|
+
} catch (cause) {
|
|
457
|
+
return {
|
|
458
|
+
encoded: `${BRIDGE_RIVET_ERROR_PREFIX}${JSON.stringify({ ...payload, metadata: void 0 })}`,
|
|
459
|
+
droppedMetadataCause: cause
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
function encodeErrorForBridge(error46) {
|
|
464
|
+
if (isCanonicalStructuredRivetError(error46)) {
|
|
465
|
+
return encodeBridgeRivetError(error46).encoded;
|
|
466
|
+
}
|
|
467
|
+
return String(error46);
|
|
468
|
+
}
|
|
469
|
+
function isCanonicalStructuredRivetError(error46) {
|
|
470
|
+
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";
|
|
471
|
+
}
|
|
472
|
+
function decodeBridgeRivetErrorPayload(value) {
|
|
473
|
+
if (!value.startsWith(BRIDGE_RIVET_ERROR_PREFIX)) {
|
|
474
|
+
return void 0;
|
|
475
|
+
}
|
|
476
|
+
try {
|
|
477
|
+
const raw = JSON.parse(
|
|
478
|
+
value.slice(BRIDGE_RIVET_ERROR_PREFIX.length)
|
|
479
|
+
);
|
|
480
|
+
const payload = {
|
|
481
|
+
...raw,
|
|
482
|
+
rayId: raw.rayId ?? void 0
|
|
483
|
+
};
|
|
484
|
+
if (!isRivetErrorLike(payload)) {
|
|
485
|
+
return void 0;
|
|
486
|
+
}
|
|
487
|
+
if (payload.actor !== void 0 && payload.actor !== null && !isActorSpecifier(payload.actor)) {
|
|
488
|
+
return void 0;
|
|
489
|
+
}
|
|
490
|
+
return payload;
|
|
491
|
+
} catch {
|
|
492
|
+
return void 0;
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
function decodeBridgeRivetError(value) {
|
|
496
|
+
const payload = decodeBridgeRivetErrorPayload(value);
|
|
497
|
+
if (!payload) {
|
|
498
|
+
return void 0;
|
|
499
|
+
}
|
|
500
|
+
return new RivetError(payload.group, payload.code, payload.message, {
|
|
501
|
+
metadata: payload.metadata,
|
|
502
|
+
rayId: payload.rayId,
|
|
503
|
+
public: payload.public,
|
|
504
|
+
statusCode: payload.statusCode,
|
|
505
|
+
actor: payload.actor ?? void 0
|
|
506
|
+
});
|
|
507
|
+
}
|
|
508
|
+
function invalidRequest(error46) {
|
|
509
|
+
return new RivetError(
|
|
510
|
+
"request",
|
|
511
|
+
"invalid",
|
|
512
|
+
`Invalid request: ${errorMessage(error46, String(error46))}`,
|
|
513
|
+
{
|
|
514
|
+
public: true,
|
|
515
|
+
cause: error46 instanceof Error ? error46 : void 0
|
|
516
|
+
}
|
|
517
|
+
);
|
|
518
|
+
}
|
|
519
|
+
function actorNotFound(identifier) {
|
|
520
|
+
return new RivetError(
|
|
521
|
+
"actor",
|
|
522
|
+
"not_found",
|
|
523
|
+
identifier ? `Actor not found: ${identifier} (https://www.rivet.dev/docs/clients/javascript)` : "Actor not found (https://www.rivet.dev/docs/clients/javascript)",
|
|
524
|
+
{ public: true }
|
|
525
|
+
);
|
|
526
|
+
}
|
|
527
|
+
function forbiddenError() {
|
|
528
|
+
return new RivetError("auth", "forbidden", "Forbidden", {
|
|
529
|
+
public: true,
|
|
530
|
+
statusCode: 403
|
|
531
|
+
});
|
|
532
|
+
}
|
|
533
|
+
function unsupportedFeature(feature) {
|
|
534
|
+
return new RivetError(
|
|
535
|
+
"feature",
|
|
536
|
+
"unsupported",
|
|
537
|
+
`Unsupported feature: ${feature}`
|
|
538
|
+
);
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
// ../rivetkit/dist/tsup/chunk-DE2IFYJK.js
|
|
542
|
+
var import_pino = require("pino");
|
|
543
|
+
|
|
338
544
|
// ../../../node_modules/.pnpm/zod@4.1.13/node_modules/zod/v4/classic/external.js
|
|
339
545
|
var external_exports = {};
|
|
340
546
|
__export(external_exports, {
|
|
@@ -13005,867 +13211,178 @@ var classic_default = external_exports;
|
|
|
13005
13211
|
// ../../../node_modules/.pnpm/zod@4.1.13/node_modules/zod/v4/index.js
|
|
13006
13212
|
var v4_default = classic_default;
|
|
13007
13213
|
|
|
13008
|
-
// ../rivetkit/dist/tsup/chunk-
|
|
13009
|
-
|
|
13010
|
-
|
|
13011
|
-
|
|
13012
|
-
|
|
13214
|
+
// ../rivetkit/dist/tsup/chunk-DE2IFYJK.js
|
|
13215
|
+
var cbor = __toESM(require("cbor-x"), 1);
|
|
13216
|
+
var import_invariant = __toESM(require_invariant(), 1);
|
|
13217
|
+
var getRivetEngine = () => getEnvUniversal("RIVET_ENGINE");
|
|
13218
|
+
var getRivetEndpoint = () => getEnvUniversal("RIVET_ENDPOINT");
|
|
13219
|
+
var getRivetToken = () => getEnvUniversal("RIVET_TOKEN");
|
|
13220
|
+
var getRivetNamespace = () => getEnvUniversal("RIVET_NAMESPACE");
|
|
13221
|
+
var getRivetPool = () => getEnvUniversal("RIVET_POOL");
|
|
13222
|
+
var getRivetTotalSlots = () => {
|
|
13223
|
+
const value = getEnvUniversal("RIVET_TOTAL_SLOTS");
|
|
13224
|
+
return value !== void 0 ? parseInt(value, 10) : void 0;
|
|
13225
|
+
};
|
|
13226
|
+
var getRivetRunEngine = () => getEnvUniversal("RIVET_RUN_ENGINE") === "1";
|
|
13227
|
+
var getRivetRunEngineHost = () => getEnvUniversal("RIVET_RUN_ENGINE_HOST");
|
|
13228
|
+
var getRivetRunEnginePort = () => {
|
|
13229
|
+
const value = getEnvUniversal("RIVET_RUN_ENGINE_PORT");
|
|
13230
|
+
return value !== void 0 ? parseInt(value, 10) : void 0;
|
|
13231
|
+
};
|
|
13232
|
+
var getRivetRunEngineVersion = () => getEnvUniversal("RIVET_RUN_ENGINE_VERSION");
|
|
13233
|
+
var getRivetRunServices = () => {
|
|
13234
|
+
const value = getEnvUniversal("RIVET_RUN_SERVICES");
|
|
13235
|
+
return value === void 0 ? void 0 : value === "1";
|
|
13236
|
+
};
|
|
13237
|
+
var getRivetEnvoyVersion = () => {
|
|
13238
|
+
const value = getEnvUniversal("RIVET_ENVOY_VERSION");
|
|
13239
|
+
return value !== void 0 ? parseInt(value, 10) : void 0;
|
|
13240
|
+
};
|
|
13241
|
+
var getRivetPublicEndpoint = () => getEnvUniversal("RIVET_PUBLIC_ENDPOINT");
|
|
13242
|
+
var getRivetPublicToken = () => getEnvUniversal("RIVET_PUBLIC_TOKEN");
|
|
13243
|
+
var getRivetkitRuntime = () => getEnvUniversal("RIVETKIT_RUNTIME");
|
|
13244
|
+
var getRivetkitRuntimeMode = () => {
|
|
13245
|
+
const value = getEnvUniversal("RIVETKIT_RUNTIME_MODE");
|
|
13246
|
+
if (value === void 0) return "envoy";
|
|
13247
|
+
if (value === "envoy" || value === "serverless") return value;
|
|
13248
|
+
throw new Error(
|
|
13249
|
+
`RIVETKIT_RUNTIME_MODE env var must be "envoy" or "serverless"; got "${value}"`
|
|
13250
|
+
);
|
|
13251
|
+
};
|
|
13252
|
+
var getRivetkitPublicDir = () => {
|
|
13253
|
+
const value = getEnvUniversal("RIVETKIT_PUBLIC_DIR");
|
|
13254
|
+
return value === void 0 || value === "" ? void 0 : value;
|
|
13255
|
+
};
|
|
13256
|
+
function parsePortEnv(raw) {
|
|
13257
|
+
if (raw === void 0 || raw === "") return void 0;
|
|
13258
|
+
const parsed = Number.parseInt(raw, 10);
|
|
13259
|
+
if (!Number.isFinite(parsed) || parsed < 1 || parsed > 65535 || String(parsed) !== raw.trim()) {
|
|
13260
|
+
throw new Error(
|
|
13261
|
+
`RIVET_PORT env var must be an integer between 1 and 65535; got "${raw}"`
|
|
13262
|
+
);
|
|
13013
13263
|
}
|
|
13014
|
-
return
|
|
13264
|
+
return parsed;
|
|
13015
13265
|
}
|
|
13016
|
-
|
|
13017
|
-
|
|
13018
|
-
|
|
13019
|
-
|
|
13020
|
-
|
|
13021
|
-
|
|
13022
|
-
|
|
13023
|
-
|
|
13024
|
-
|
|
13025
|
-
|
|
13026
|
-
throw new TypeError(
|
|
13027
|
-
`Action input schema \`${name}\` is defined by both a nested path and a dotted key`
|
|
13028
|
-
);
|
|
13029
|
-
}
|
|
13030
|
-
const schema = nestedSchema ?? flatSchema;
|
|
13031
|
-
if (schema !== void 0) {
|
|
13032
|
-
flattened[name] = schema;
|
|
13033
|
-
}
|
|
13034
|
-
}
|
|
13035
|
-
return flattened;
|
|
13266
|
+
var getLogLevel = () => getEnvUniversal("RIVET_LOG_LEVEL") ?? getEnvUniversal("LOG_LEVEL");
|
|
13267
|
+
var getLogTarget = () => getEnvUniversal("RIVET_LOG_TARGET") === "1";
|
|
13268
|
+
var getLogTimestamp = () => getEnvUniversal("RIVET_LOG_TIMESTAMP") === "1";
|
|
13269
|
+
var getLogMessage = () => getEnvUniversal("RIVET_LOG_MESSAGE") === "1";
|
|
13270
|
+
var getLogErrorStack = () => getEnvUniversal("RIVET_LOG_ERROR_STACK") === "1";
|
|
13271
|
+
var getNodeEnv = () => getEnvUniversal("NODE_ENV");
|
|
13272
|
+
var getNextPhase = () => getEnvUniversal("NEXT_PHASE");
|
|
13273
|
+
var isDev = () => getNodeEnv() !== "production";
|
|
13274
|
+
function assertUnreachable(x) {
|
|
13275
|
+
throw new Error(`Unreachable case: ${x}`);
|
|
13036
13276
|
}
|
|
13037
|
-
function
|
|
13038
|
-
|
|
13039
|
-
|
|
13040
|
-
|
|
13041
|
-
|
|
13042
|
-
|
|
13043
|
-
|
|
13044
|
-
|
|
13277
|
+
function deconstructError(error46, exposeInternalError = false) {
|
|
13278
|
+
let statusCode;
|
|
13279
|
+
let public_;
|
|
13280
|
+
let group;
|
|
13281
|
+
let code;
|
|
13282
|
+
let message;
|
|
13283
|
+
let metadata;
|
|
13284
|
+
let rayId;
|
|
13285
|
+
let actor2;
|
|
13286
|
+
if (isCanonicalStructuredRivetError(error46)) {
|
|
13287
|
+
statusCode = typeof error46.statusCode === "number" ? error46.statusCode : error46.public ? 400 : 500;
|
|
13288
|
+
public_ = error46.public ?? false;
|
|
13289
|
+
group = error46.group;
|
|
13290
|
+
code = error46.code;
|
|
13291
|
+
message = error46.message;
|
|
13292
|
+
metadata = error46.metadata;
|
|
13293
|
+
rayId = error46.rayId;
|
|
13294
|
+
actor2 = error46.actor;
|
|
13295
|
+
} else if (RivetError.isActorError(error46) && error46.public) {
|
|
13296
|
+
statusCode = "statusCode" in error46 && error46.statusCode ? error46.statusCode : 400;
|
|
13297
|
+
public_ = true;
|
|
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 if (exposeInternalError) {
|
|
13305
|
+
if (RivetError.isActorError(error46)) {
|
|
13306
|
+
statusCode = 500;
|
|
13307
|
+
public_ = false;
|
|
13308
|
+
group = error46.group;
|
|
13309
|
+
code = error46.code;
|
|
13310
|
+
message = getErrorMessage(error46);
|
|
13311
|
+
metadata = error46.metadata;
|
|
13312
|
+
rayId = error46.rayId;
|
|
13313
|
+
actor2 = error46.actor;
|
|
13314
|
+
} else {
|
|
13315
|
+
statusCode = 500;
|
|
13316
|
+
public_ = false;
|
|
13317
|
+
group = "rivetkit";
|
|
13318
|
+
code = INTERNAL_ERROR_CODE;
|
|
13319
|
+
message = getErrorMessage(error46);
|
|
13045
13320
|
}
|
|
13046
|
-
}
|
|
13047
|
-
|
|
13048
|
-
|
|
13049
|
-
|
|
13050
|
-
|
|
13051
|
-
|
|
13052
|
-
|
|
13053
|
-
|
|
13321
|
+
} else {
|
|
13322
|
+
statusCode = 500;
|
|
13323
|
+
public_ = false;
|
|
13324
|
+
group = "rivetkit";
|
|
13325
|
+
code = INTERNAL_ERROR_CODE;
|
|
13326
|
+
message = INTERNAL_ERROR_DESCRIPTION;
|
|
13327
|
+
if (RivetError.isActorError(error46)) {
|
|
13328
|
+
actor2 = error46.actor;
|
|
13054
13329
|
}
|
|
13055
|
-
|
|
13056
|
-
}
|
|
13057
|
-
|
|
13058
|
-
const entries = [];
|
|
13059
|
-
const names = /* @__PURE__ */ new Set();
|
|
13060
|
-
visitActionGroup(actions ?? {}, [], entries, names);
|
|
13061
|
-
return entries;
|
|
13062
|
-
}
|
|
13063
|
-
function visitActionGroup(value, path2, entries, names) {
|
|
13064
|
-
if (!isRecord(value)) {
|
|
13065
|
-
throw new TypeError(
|
|
13066
|
-
`${formatActionPath(path2)} must be an action handler or group`
|
|
13067
|
-
);
|
|
13330
|
+
metadata = {
|
|
13331
|
+
//url: `https://dashboard.rivet.dev/projects/${actorMetadata.project.slug}/environments/${actorMetadata.environment.slug}/actors?actorId=${actorMetadata.actor.id}`,
|
|
13332
|
+
};
|
|
13068
13333
|
}
|
|
13069
|
-
|
|
13070
|
-
|
|
13071
|
-
|
|
13072
|
-
|
|
13073
|
-
|
|
13074
|
-
|
|
13075
|
-
|
|
13076
|
-
|
|
13334
|
+
return {
|
|
13335
|
+
__type: "ActorError",
|
|
13336
|
+
statusCode,
|
|
13337
|
+
public: public_,
|
|
13338
|
+
group,
|
|
13339
|
+
code,
|
|
13340
|
+
message,
|
|
13341
|
+
metadata,
|
|
13342
|
+
rayId,
|
|
13343
|
+
actor: actor2
|
|
13344
|
+
};
|
|
13345
|
+
}
|
|
13346
|
+
function stringifyError(error46) {
|
|
13347
|
+
if (error46 instanceof Error) {
|
|
13348
|
+
if (typeof process !== "undefined" && getLogErrorStack()) {
|
|
13349
|
+
let stack;
|
|
13350
|
+
try {
|
|
13351
|
+
stack = error46.stack;
|
|
13352
|
+
} catch {
|
|
13353
|
+
stack = void 0;
|
|
13077
13354
|
}
|
|
13078
|
-
|
|
13079
|
-
|
|
13080
|
-
name,
|
|
13081
|
-
path: childPath,
|
|
13082
|
-
handler: child
|
|
13083
|
-
});
|
|
13355
|
+
return `${error46.name}: ${error46.message}${stack ? `
|
|
13356
|
+
${stack}` : ""}`;
|
|
13084
13357
|
} else {
|
|
13085
|
-
|
|
13358
|
+
return `${error46.name}: ${error46.message}`;
|
|
13086
13359
|
}
|
|
13087
|
-
}
|
|
13088
|
-
|
|
13089
|
-
|
|
13090
|
-
|
|
13091
|
-
|
|
13092
|
-
|
|
13093
|
-
return
|
|
13360
|
+
} else if (typeof error46 === "string") {
|
|
13361
|
+
return error46;
|
|
13362
|
+
} else if (typeof error46 === "object" && error46 !== null) {
|
|
13363
|
+
try {
|
|
13364
|
+
return `${JSON.stringify(error46)}`;
|
|
13365
|
+
} catch {
|
|
13366
|
+
return "[cannot stringify error]";
|
|
13094
13367
|
}
|
|
13095
|
-
|
|
13368
|
+
} else {
|
|
13369
|
+
return `Unknown error: ${getErrorMessage(error46)}`;
|
|
13096
13370
|
}
|
|
13097
|
-
return value;
|
|
13098
13371
|
}
|
|
13099
|
-
function
|
|
13100
|
-
if (typeof
|
|
13101
|
-
return
|
|
13372
|
+
function getErrorMessage(err) {
|
|
13373
|
+
if (err && typeof err === "object" && "message" in err && typeof err.message === "string") {
|
|
13374
|
+
return err.message;
|
|
13375
|
+
} else {
|
|
13376
|
+
return String(err);
|
|
13102
13377
|
}
|
|
13103
|
-
const prototype = Object.getPrototypeOf(value);
|
|
13104
|
-
return prototype === Object.prototype || prototype === null;
|
|
13105
13378
|
}
|
|
13106
|
-
function
|
|
13107
|
-
return
|
|
13108
|
-
}
|
|
13109
|
-
var DEFAULT_SLEEP_GRACE_PERIOD = 15e3;
|
|
13110
|
-
var ACTOR_CONTEXT_INTERNAL_SYMBOL = /* @__PURE__ */ Symbol(
|
|
13111
|
-
"rivetkit.actor_context_internal"
|
|
13112
|
-
);
|
|
13113
|
-
var RAW_STATE_SYMBOL = /* @__PURE__ */ Symbol("rivetkit.raw_state");
|
|
13114
|
-
var CONN_STATE_MANAGER_SYMBOL = /* @__PURE__ */ Symbol("rivetkit.conn_state_manager");
|
|
13115
|
-
var zFunction = () => external_exports.custom((val) => typeof val === "function");
|
|
13116
|
-
var zActionTree = external_exports.custom((value) => {
|
|
13117
|
-
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
13118
|
-
return false;
|
|
13119
|
-
}
|
|
13120
|
-
const prototype = Object.getPrototypeOf(value);
|
|
13121
|
-
return prototype === Object.prototype || prototype === null;
|
|
13122
|
-
}).superRefine((actions, ctx) => {
|
|
13123
|
-
try {
|
|
13124
|
-
flattenActionHandlers(actions);
|
|
13125
|
-
} catch (error46) {
|
|
13126
|
-
ctx.addIssue({
|
|
13127
|
-
code: "custom",
|
|
13128
|
-
message: error46 instanceof Error ? error46.message : "Invalid action definition"
|
|
13129
|
-
});
|
|
13130
|
-
}
|
|
13131
|
-
});
|
|
13132
|
-
var WorkflowInspectorConfigSchema = external_exports.object({
|
|
13133
|
-
getHistory: zFunction(),
|
|
13134
|
-
getState: zFunction().optional(),
|
|
13135
|
-
onHistoryUpdated: zFunction().optional(),
|
|
13136
|
-
replayFromStep: zFunction().optional()
|
|
13137
|
-
});
|
|
13138
|
-
var RunInspectorConfigSchema = external_exports.object({
|
|
13139
|
-
workflow: WorkflowInspectorConfigSchema.optional()
|
|
13140
|
-
}).optional();
|
|
13141
|
-
var BUILTIN_INSPECTOR_TAB_IDS = [
|
|
13142
|
-
"workflow",
|
|
13143
|
-
"database",
|
|
13144
|
-
"state",
|
|
13145
|
-
"queue",
|
|
13146
|
-
"schedules",
|
|
13147
|
-
"connections",
|
|
13148
|
-
"console"
|
|
13149
|
-
];
|
|
13150
|
-
var BuiltinInspectorTabIdSchema = external_exports.enum(BUILTIN_INSPECTOR_TAB_IDS);
|
|
13151
|
-
var CUSTOM_INSPECTOR_TAB_ID_RE = /^[A-Za-z0-9_-]+$/;
|
|
13152
|
-
var CustomInspectorTabEntrySchema = external_exports.object({
|
|
13153
|
-
id: external_exports.string().regex(
|
|
13154
|
-
CUSTOM_INSPECTOR_TAB_ID_RE,
|
|
13155
|
-
"inspector.tabs[].id must contain only letters, digits, underscore, or dash"
|
|
13156
|
-
),
|
|
13157
|
-
label: external_exports.string().min(1),
|
|
13158
|
-
source: external_exports.string().min(1),
|
|
13159
|
-
/**
|
|
13160
|
-
* Optional icon id. The dashboard maps strings to glyphs (see its
|
|
13161
|
-
* icon registry); unknown ids fall back to a generic icon.
|
|
13162
|
-
*/
|
|
13163
|
-
icon: external_exports.string().min(1).optional(),
|
|
13164
|
-
hidden: external_exports.literal(false).optional()
|
|
13165
|
-
}).strict();
|
|
13166
|
-
var HideInspectorTabEntrySchema = external_exports.object({
|
|
13167
|
-
id: BuiltinInspectorTabIdSchema,
|
|
13168
|
-
hidden: external_exports.literal(true)
|
|
13169
|
-
}).strict();
|
|
13170
|
-
var InspectorTabEntrySchema = external_exports.union([
|
|
13171
|
-
CustomInspectorTabEntrySchema,
|
|
13172
|
-
HideInspectorTabEntrySchema
|
|
13173
|
-
]);
|
|
13174
|
-
var ActorInspectorConfigSchema = external_exports.object({
|
|
13175
|
-
tabs: external_exports.array(InspectorTabEntrySchema).default(() => [])
|
|
13176
|
-
}).strict().refine(
|
|
13177
|
-
(data) => {
|
|
13178
|
-
const ids = data.tabs.map((t) => t.id);
|
|
13179
|
-
return new Set(ids).size === ids.length;
|
|
13180
|
-
},
|
|
13181
|
-
{ message: "Duplicate id in inspector.tabs", path: ["tabs"] }
|
|
13182
|
-
).refine(
|
|
13183
|
-
(data) => {
|
|
13184
|
-
const builtinSet = new Set(BUILTIN_INSPECTOR_TAB_IDS);
|
|
13185
|
-
return data.tabs.every(
|
|
13186
|
-
(t) => t.hidden === true || !builtinSet.has(t.id)
|
|
13187
|
-
);
|
|
13188
|
-
},
|
|
13189
|
-
{
|
|
13190
|
-
message: "Custom inspector tab id collides with a built-in (use hidden: true to hide a built-in)",
|
|
13191
|
-
path: ["tabs"]
|
|
13192
|
-
}
|
|
13193
|
-
);
|
|
13194
|
-
var RunConfigSchema = external_exports.object({
|
|
13195
|
-
/** Display name for the actor in the Inspector UI. */
|
|
13196
|
-
name: external_exports.string().optional(),
|
|
13197
|
-
/** Icon for the actor in the Inspector UI. Can be an emoji or FontAwesome icon name. */
|
|
13198
|
-
icon: external_exports.string().optional(),
|
|
13199
|
-
/** The run handler function. */
|
|
13200
|
-
run: zFunction(),
|
|
13201
|
-
/** Inspector integration for long-running run handlers. */
|
|
13202
|
-
inspector: RunInspectorConfigSchema.optional()
|
|
13203
|
-
});
|
|
13204
|
-
var RUN_FUNCTION_CONFIG_SYMBOL = /* @__PURE__ */ Symbol.for("rivetkit.run_function_config");
|
|
13205
|
-
function defineRunHandler(run, options) {
|
|
13206
|
-
if (options.inspectorKind === void 0 !== (options.createInspector === void 0)) {
|
|
13207
|
-
throw new TypeError(
|
|
13208
|
-
"defineRunHandler requires inspectorKind and createInspector together"
|
|
13209
|
-
);
|
|
13210
|
-
}
|
|
13211
|
-
Object.defineProperty(run, RUN_FUNCTION_CONFIG_SYMBOL, {
|
|
13212
|
-
configurable: false,
|
|
13213
|
-
enumerable: false,
|
|
13214
|
-
writable: false,
|
|
13215
|
-
value: {
|
|
13216
|
-
name: options.name,
|
|
13217
|
-
icon: options.icon,
|
|
13218
|
-
inspectorKind: options.inspectorKind,
|
|
13219
|
-
createInspector: options.createInspector
|
|
13220
|
-
}
|
|
13221
|
-
});
|
|
13222
|
-
return run;
|
|
13223
|
-
}
|
|
13224
|
-
function getRunInspectorKind(run) {
|
|
13225
|
-
var _a2;
|
|
13226
|
-
if (!run || typeof run !== "function") return void 0;
|
|
13227
|
-
return (_a2 = run[RUN_FUNCTION_CONFIG_SYMBOL]) == null ? void 0 : _a2.inspectorKind;
|
|
13228
|
-
}
|
|
13229
|
-
function createRunInspector(run, context2) {
|
|
13230
|
-
var _a2, _b;
|
|
13231
|
-
if (!run || typeof run !== "function") return void 0;
|
|
13232
|
-
return (_b = (_a2 = run[RUN_FUNCTION_CONFIG_SYMBOL]) == null ? void 0 : _a2.createInspector) == null ? void 0 : _b.call(_a2, context2);
|
|
13233
|
-
}
|
|
13234
|
-
var zRunHandler = external_exports.union([zFunction(), RunConfigSchema]).optional();
|
|
13235
|
-
function getRunFunction(run) {
|
|
13236
|
-
if (!run) return void 0;
|
|
13237
|
-
if (typeof run === "function") return run;
|
|
13238
|
-
return run.run;
|
|
13239
|
-
}
|
|
13240
|
-
function getRunMetadata(run) {
|
|
13241
|
-
if (!run) return {};
|
|
13242
|
-
if (typeof run === "function") {
|
|
13243
|
-
const config3 = run[RUN_FUNCTION_CONFIG_SYMBOL];
|
|
13244
|
-
if (!config3) return {};
|
|
13245
|
-
return { name: config3.name, icon: config3.icon };
|
|
13246
|
-
}
|
|
13247
|
-
return { name: run.name, icon: run.icon };
|
|
13248
|
-
}
|
|
13249
|
-
function getRunInspectorConfig(run, actor2) {
|
|
13250
|
-
if (!run) return void 0;
|
|
13251
|
-
if (typeof run === "function") {
|
|
13252
|
-
const config3 = run[RUN_FUNCTION_CONFIG_SYMBOL];
|
|
13253
|
-
return (config3 == null ? void 0 : config3.inspectorFactory) ? config3.inspectorFactory(actor2) : config3 == null ? void 0 : config3.inspector;
|
|
13254
|
-
}
|
|
13255
|
-
return run.inspector;
|
|
13256
|
-
}
|
|
13257
|
-
function hasRunInspectorConfig(run) {
|
|
13258
|
-
if (!run) return false;
|
|
13259
|
-
if (typeof run !== "function") return run.inspector !== void 0;
|
|
13260
|
-
const config3 = run[RUN_FUNCTION_CONFIG_SYMBOL];
|
|
13261
|
-
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;
|
|
13262
|
-
}
|
|
13263
|
-
function disposeRunInspector(run, actorId) {
|
|
13264
|
-
var _a2;
|
|
13265
|
-
if (!run || typeof run !== "function") {
|
|
13266
|
-
return;
|
|
13267
|
-
}
|
|
13268
|
-
const config3 = run[RUN_FUNCTION_CONFIG_SYMBOL];
|
|
13269
|
-
(_a2 = config3 == null ? void 0 : config3.disposeInspector) == null ? void 0 : _a2.call(config3, actorId);
|
|
13270
|
-
}
|
|
13271
|
-
var GlobalActorOptionsBaseSchema = external_exports.object({
|
|
13272
|
-
/** Display name for the actor in the Inspector UI. */
|
|
13273
|
-
name: external_exports.string().optional(),
|
|
13274
|
-
/** Icon for the actor in the Inspector UI. Can be an emoji or FontAwesome icon name. */
|
|
13275
|
-
icon: external_exports.string().optional(),
|
|
13276
|
-
/** Enables the experimental Actor Runtime Socket for this actor. */
|
|
13277
|
-
enableActorRuntimeSocket: external_exports.boolean().default(false),
|
|
13278
|
-
/**
|
|
13279
|
-
* Can hibernate WebSockets for onWebSocket.
|
|
13280
|
-
*
|
|
13281
|
-
* WebSockets using actions/events are hibernatable by default.
|
|
13282
|
-
*
|
|
13283
|
-
* @experimental
|
|
13284
|
-
**/
|
|
13285
|
-
canHibernateWebSocket: external_exports.union([external_exports.boolean(), zFunction()]).default(false)
|
|
13286
|
-
}).strict();
|
|
13287
|
-
var GlobalActorOptionsSchema = GlobalActorOptionsBaseSchema.prefault(
|
|
13288
|
-
() => ({})
|
|
13289
|
-
);
|
|
13290
|
-
var InstanceActorOptionsBaseSchema = external_exports.object({
|
|
13291
|
-
createVarsTimeout: external_exports.number().positive().default(5e3),
|
|
13292
|
-
createConnStateTimeout: external_exports.number().positive().default(5e3),
|
|
13293
|
-
onBeforeConnectTimeout: external_exports.number().positive().default(5e3),
|
|
13294
|
-
onConnectTimeout: external_exports.number().positive().default(5e3),
|
|
13295
|
-
onMigrateTimeout: external_exports.number().positive().default(3e4),
|
|
13296
|
-
sleepGracePeriod: external_exports.number().positive().default(DEFAULT_SLEEP_GRACE_PERIOD),
|
|
13297
|
-
/** @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. */
|
|
13298
|
-
onDestroyTimeout: external_exports.number().positive().optional(),
|
|
13299
|
-
/** @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. */
|
|
13300
|
-
waitUntilTimeout: external_exports.number().positive().optional(),
|
|
13301
|
-
stateSaveInterval: external_exports.number().positive().default(1e3),
|
|
13302
|
-
actionTimeout: external_exports.number().positive().default(6e4),
|
|
13303
|
-
connectionLivenessTimeout: external_exports.number().positive().default(2500),
|
|
13304
|
-
connectionLivenessInterval: external_exports.number().positive().default(5e3),
|
|
13305
|
-
/** @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. */
|
|
13306
|
-
noSleep: external_exports.boolean().default(false),
|
|
13307
|
-
sleepTimeout: external_exports.number().positive().default(3e4),
|
|
13308
|
-
maxQueueSize: external_exports.number().positive().default(1e3),
|
|
13309
|
-
/** Maximum pending one-shot and recurring schedules. */
|
|
13310
|
-
maxSchedules: external_exports.number().int().nonnegative().default(1e3),
|
|
13311
|
-
maxQueueMessageSize: external_exports.number().positive().default(64 * 1024),
|
|
13312
|
-
/** @deprecated Internal storage moved to SQLite and no longer uses KV preloading, so this option is ignored. Will be removed in 2.2.0. */
|
|
13313
|
-
preloadMaxWorkflowBytes: external_exports.number().nonnegative().optional(),
|
|
13314
|
-
/** @deprecated Internal storage moved to SQLite and no longer uses KV preloading, so this option is ignored. Will be removed in 2.2.0. */
|
|
13315
|
-
preloadMaxConnectionsBytes: external_exports.number().nonnegative().optional()
|
|
13316
|
-
}).strict();
|
|
13317
|
-
var InstanceActorOptionsSchema = InstanceActorOptionsBaseSchema.prefault(() => ({}));
|
|
13318
|
-
var ActorOptionsSchema = GlobalActorOptionsBaseSchema.extend(
|
|
13319
|
-
InstanceActorOptionsBaseSchema.shape
|
|
13320
|
-
).strict().prefault(() => ({}));
|
|
13321
|
-
var zSampleRate = external_exports.number().min(0).max(1);
|
|
13322
|
-
var zActionSampleRates = external_exports.lazy(
|
|
13323
|
-
() => external_exports.record(external_exports.string(), external_exports.union([zSampleRate, zActionSampleRates]))
|
|
13324
|
-
);
|
|
13325
|
-
var ActorConfigSchema = external_exports.object({
|
|
13326
|
-
onCreate: zFunction().optional(),
|
|
13327
|
-
onDestroy: zFunction().optional(),
|
|
13328
|
-
onMigrate: zFunction().optional(),
|
|
13329
|
-
onWake: zFunction().optional(),
|
|
13330
|
-
onSleep: zFunction().optional(),
|
|
13331
|
-
run: zRunHandler,
|
|
13332
|
-
onStateChange: zFunction().optional(),
|
|
13333
|
-
onBeforeConnect: zFunction().optional(),
|
|
13334
|
-
onConnect: zFunction().optional(),
|
|
13335
|
-
onDisconnect: zFunction().optional(),
|
|
13336
|
-
onBeforeActionResponse: zFunction().optional(),
|
|
13337
|
-
onRequest: zFunction().optional(),
|
|
13338
|
-
onWebSocket: zFunction().optional(),
|
|
13339
|
-
actions: zActionTree.default(() => ({})),
|
|
13340
|
-
actionInputSchemas: external_exports.record(external_exports.string(), external_exports.any()).optional(),
|
|
13341
|
-
tracing: external_exports.object({
|
|
13342
|
-
sampler: zSampleRate.optional(),
|
|
13343
|
-
actions: zActionSampleRates.optional()
|
|
13344
|
-
}).strict().optional(),
|
|
13345
|
-
connParamsSchema: external_exports.any().optional(),
|
|
13346
|
-
events: external_exports.record(external_exports.string(), external_exports.any()).optional(),
|
|
13347
|
-
queues: external_exports.record(external_exports.string(), external_exports.any()).optional(),
|
|
13348
|
-
state: external_exports.any().optional(),
|
|
13349
|
-
createState: zFunction().optional(),
|
|
13350
|
-
connState: external_exports.any().optional(),
|
|
13351
|
-
createConnState: zFunction().optional(),
|
|
13352
|
-
vars: external_exports.any().optional(),
|
|
13353
|
-
db: external_exports.any().optional(),
|
|
13354
|
-
createVars: zFunction().optional(),
|
|
13355
|
-
options: ActorOptionsSchema,
|
|
13356
|
-
inspector: ActorInspectorConfigSchema.optional()
|
|
13357
|
-
}).strict().refine(
|
|
13358
|
-
(data) => !(data.state !== void 0 && data.createState !== void 0),
|
|
13359
|
-
{
|
|
13360
|
-
message: "Cannot define both 'state' and 'createState'",
|
|
13361
|
-
path: ["state"]
|
|
13362
|
-
}
|
|
13363
|
-
).refine(
|
|
13364
|
-
(data) => !(data.connState !== void 0 && data.createConnState !== void 0),
|
|
13365
|
-
{
|
|
13366
|
-
message: "Cannot define both 'connState' and 'createConnState'",
|
|
13367
|
-
path: ["connState"]
|
|
13368
|
-
}
|
|
13369
|
-
).refine(
|
|
13370
|
-
(data) => !(data.vars !== void 0 && data.createVars !== void 0),
|
|
13371
|
-
{
|
|
13372
|
-
message: "Cannot define both 'vars' and 'createVars'",
|
|
13373
|
-
path: ["vars"]
|
|
13374
|
-
}
|
|
13375
|
-
);
|
|
13376
|
-
var DocActorOptionsSchema = external_exports.object({
|
|
13377
|
-
name: external_exports.string().optional().describe("Display name for the actor in the Inspector UI."),
|
|
13378
|
-
icon: external_exports.string().optional().describe(
|
|
13379
|
-
"Icon for the actor in the Inspector UI. Can be an emoji (e.g., '\u{1F680}') or FontAwesome icon name (e.g., 'rocket')."
|
|
13380
|
-
),
|
|
13381
|
-
enableActorRuntimeSocket: external_exports.boolean().optional().describe(
|
|
13382
|
-
"Enables the experimental Actor Runtime Socket for this actor. Default: false"
|
|
13383
|
-
),
|
|
13384
|
-
createVarsTimeout: external_exports.number().optional().describe("Timeout in ms for createVars handler. Default: 5000"),
|
|
13385
|
-
createConnStateTimeout: external_exports.number().optional().describe(
|
|
13386
|
-
"Timeout in ms for createConnState handler. Default: 5000"
|
|
13387
|
-
),
|
|
13388
|
-
onMigrateTimeout: external_exports.number().optional().describe("Timeout in ms for onMigrate handler. Default: 30000"),
|
|
13389
|
-
onBeforeConnectTimeout: external_exports.number().optional().describe(
|
|
13390
|
-
"Timeout in ms for onBeforeConnect handler. Default: 5000"
|
|
13391
|
-
),
|
|
13392
|
-
onConnectTimeout: external_exports.number().optional().describe("Timeout in ms for onConnect handler. Default: 5000"),
|
|
13393
|
-
sleepGracePeriod: external_exports.number().optional().describe(
|
|
13394
|
-
`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}.`
|
|
13395
|
-
),
|
|
13396
|
-
onDestroyTimeout: external_exports.number().optional().describe(
|
|
13397
|
-
"Deprecated. Folded into sleepGracePeriod, which now bounds the entire graceful shutdown window for both sleep and destroy. Will be removed in 2.2.0."
|
|
13398
|
-
),
|
|
13399
|
-
waitUntilTimeout: external_exports.number().optional().describe(
|
|
13400
|
-
"Deprecated. Folded into sleepGracePeriod, which now bounds the entire graceful shutdown window for both sleep and destroy. Will be removed in 2.2.0."
|
|
13401
|
-
),
|
|
13402
|
-
stateSaveInterval: external_exports.number().optional().describe(
|
|
13403
|
-
"Interval in ms between automatic state saves. Default: 1000"
|
|
13404
|
-
),
|
|
13405
|
-
actionTimeout: external_exports.number().optional().describe("Timeout in ms for action handlers. Default: 60000"),
|
|
13406
|
-
connectionLivenessTimeout: external_exports.number().optional().describe(
|
|
13407
|
-
"Timeout in ms for connection liveness checks. Default: 2500"
|
|
13408
|
-
),
|
|
13409
|
-
connectionLivenessInterval: external_exports.number().optional().describe(
|
|
13410
|
-
"Interval in ms between connection liveness checks. Default: 5000"
|
|
13411
|
-
),
|
|
13412
|
-
noSleep: external_exports.boolean().optional().describe(
|
|
13413
|
-
"Deprecated. If true, the actor will never sleep. Use c.keepAwake(promise) to scope keep-awake to a specific operation instead. Default: false"
|
|
13414
|
-
),
|
|
13415
|
-
sleepTimeout: external_exports.number().optional().describe(
|
|
13416
|
-
"Time in ms of inactivity before the actor sleeps. Default: 30000"
|
|
13417
|
-
),
|
|
13418
|
-
maxQueueSize: external_exports.number().optional().describe(
|
|
13419
|
-
"Maximum number of queue messages before rejecting new messages. Default: 1000"
|
|
13420
|
-
),
|
|
13421
|
-
maxSchedules: external_exports.number().int().nonnegative().optional().describe(
|
|
13422
|
-
"Maximum pending one-shot and recurring schedules before rejecting new schedules. Default: 1000"
|
|
13423
|
-
),
|
|
13424
|
-
maxQueueMessageSize: external_exports.number().optional().describe(
|
|
13425
|
-
"Maximum size of each queue message in bytes. Default: 65536"
|
|
13426
|
-
),
|
|
13427
|
-
canHibernateWebSocket: external_exports.boolean().optional().describe(
|
|
13428
|
-
"Whether WebSockets using onWebSocket can be hibernated. WebSockets using actions/events are hibernatable by default. Default: false"
|
|
13429
|
-
)
|
|
13430
|
-
}).describe("Actor options for timeouts and behavior configuration.");
|
|
13431
|
-
var DocActorConfigSchema = external_exports.object({
|
|
13432
|
-
state: external_exports.unknown().optional().describe(
|
|
13433
|
-
"Initial state value for the actor. Cannot be used with createState."
|
|
13434
|
-
),
|
|
13435
|
-
createState: external_exports.unknown().optional().describe(
|
|
13436
|
-
"Function to create initial state. Receives context and input. Cannot be used with state."
|
|
13437
|
-
),
|
|
13438
|
-
connState: external_exports.unknown().optional().describe(
|
|
13439
|
-
"Initial connection state value. Cannot be used with createConnState."
|
|
13440
|
-
),
|
|
13441
|
-
createConnState: external_exports.unknown().optional().describe(
|
|
13442
|
-
"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."
|
|
13443
|
-
),
|
|
13444
|
-
vars: external_exports.unknown().optional().describe(
|
|
13445
|
-
"Initial ephemeral variables value. Cannot be used with createVars."
|
|
13446
|
-
),
|
|
13447
|
-
createVars: external_exports.unknown().optional().describe(
|
|
13448
|
-
"Function to create ephemeral variables. Receives context and driver context. Cannot be used with vars."
|
|
13449
|
-
),
|
|
13450
|
-
db: external_exports.unknown().optional().describe("Database provider instance for the actor."),
|
|
13451
|
-
onCreate: external_exports.unknown().optional().describe(
|
|
13452
|
-
"Called when the actor is first initialized. Use to initialize state."
|
|
13453
|
-
),
|
|
13454
|
-
onDestroy: external_exports.unknown().optional().describe("Called when the actor is destroyed."),
|
|
13455
|
-
onMigrate: external_exports.unknown().optional().describe(
|
|
13456
|
-
"Called on every actor start after persisted state loads and before onWake. Use for repeatable schema migrations."
|
|
13457
|
-
),
|
|
13458
|
-
onWake: external_exports.unknown().optional().describe(
|
|
13459
|
-
"Called when the actor wakes up and is ready to receive connections and actions."
|
|
13460
|
-
),
|
|
13461
|
-
onSleep: external_exports.unknown().optional().describe(
|
|
13462
|
-
"Called when the actor is stopping or sleeping. Use to clean up resources."
|
|
13463
|
-
),
|
|
13464
|
-
run: external_exports.unknown().optional().describe(
|
|
13465
|
-
"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."
|
|
13466
|
-
),
|
|
13467
|
-
onStateChange: external_exports.unknown().optional().describe(
|
|
13468
|
-
"Called when the actor's state changes. State changes within this hook won't trigger recursion."
|
|
13469
|
-
),
|
|
13470
|
-
onBeforeConnect: external_exports.unknown().optional().describe(
|
|
13471
|
-
"Called before a client connects. Throw an error to reject the connection. The pending connection is not visible in c.conns while this runs."
|
|
13472
|
-
),
|
|
13473
|
-
onConnect: external_exports.unknown().optional().describe(
|
|
13474
|
-
"Called when a client successfully connects. The connection is visible in c.conns before this runs."
|
|
13475
|
-
),
|
|
13476
|
-
onDisconnect: external_exports.unknown().optional().describe("Called when a client disconnects."),
|
|
13477
|
-
onBeforeActionResponse: external_exports.unknown().optional().describe(
|
|
13478
|
-
"Called before sending an action response. Use to transform output."
|
|
13479
|
-
),
|
|
13480
|
-
onRequest: external_exports.unknown().optional().describe(
|
|
13481
|
-
"Called for raw HTTP requests to /actors/{name}/http/* endpoints."
|
|
13482
|
-
),
|
|
13483
|
-
onWebSocket: external_exports.unknown().optional().describe(
|
|
13484
|
-
"Called for raw WebSocket connections to /actors/{name}/websocket/* endpoints."
|
|
13485
|
-
),
|
|
13486
|
-
actions: external_exports.record(external_exports.string(), external_exports.unknown()).optional().describe(
|
|
13487
|
-
"Tree of action names or nested groups to handler functions. Nested paths use dot-separated low-level action names. Defaults to an empty object."
|
|
13488
|
-
),
|
|
13489
|
-
actionInputSchemas: external_exports.record(external_exports.string(), external_exports.unknown()).optional().describe(
|
|
13490
|
-
"Optional schemas for validating action argument tuples in native runtimes. May mirror nested action groups or use dot-separated low-level action names."
|
|
13491
|
-
),
|
|
13492
|
-
tracing: external_exports.unknown().optional().describe(
|
|
13493
|
-
"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."
|
|
13494
|
-
),
|
|
13495
|
-
connParamsSchema: external_exports.unknown().optional().describe(
|
|
13496
|
-
"Optional schema for validating connection params in native runtimes."
|
|
13497
|
-
),
|
|
13498
|
-
events: external_exports.record(external_exports.string(), external_exports.unknown()).optional().describe("Map of event names to schemas."),
|
|
13499
|
-
queues: external_exports.record(external_exports.string(), external_exports.unknown()).optional().describe("Map of queue names to schemas."),
|
|
13500
|
-
options: DocActorOptionsSchema.optional()
|
|
13501
|
-
}).describe("Actor configuration passed to the actor() function.");
|
|
13502
|
-
|
|
13503
|
-
// ../rivetkit/dist/tsup/chunk-P2OFXH4G.js
|
|
13504
|
-
var INTERNAL_ERROR_CODE = "internal_error";
|
|
13505
|
-
var INTERNAL_ERROR_DESCRIPTION = "An internal error occurred";
|
|
13506
|
-
var USER_ERROR_CODE = "user_error";
|
|
13507
|
-
var BRIDGE_RIVET_ERROR_PREFIX = "__RIVET_ERROR_JSON__:";
|
|
13508
|
-
function looksLikeRivetErrorOptions(value) {
|
|
13509
|
-
return typeof value === "object" && value !== null && ("public" in value || "metadata" in value || "rayId" in value || "statusCode" in value || "actor" in value || "cause" in value);
|
|
13510
|
-
}
|
|
13511
|
-
function isTypedErrorTag(value) {
|
|
13512
|
-
return value === "ActorError" || value === "RivetError";
|
|
13513
|
-
}
|
|
13514
|
-
function errorMessage(error46, fallback = String(error46)) {
|
|
13515
|
-
if (error46 && typeof error46 === "object" && "message" in error46 && typeof error46.message === "string") {
|
|
13516
|
-
return error46.message;
|
|
13517
|
-
}
|
|
13518
|
-
return fallback;
|
|
13519
|
-
}
|
|
13520
|
-
function isRivetErrorLike(error46) {
|
|
13521
|
-
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));
|
|
13522
|
-
}
|
|
13523
|
-
function isActorAbortedError(error46) {
|
|
13524
|
-
return isRivetErrorLike(error46) && error46.group === "actor" && error46.code === "aborted";
|
|
13525
|
-
}
|
|
13526
|
-
function isActorSpecifier(value) {
|
|
13527
|
-
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");
|
|
13528
|
-
}
|
|
13529
|
-
var RivetError = class extends Error {
|
|
13530
|
-
__type = "RivetError";
|
|
13531
|
-
public;
|
|
13532
|
-
metadata;
|
|
13533
|
-
rayId;
|
|
13534
|
-
statusCode;
|
|
13535
|
-
actor;
|
|
13536
|
-
group;
|
|
13537
|
-
code;
|
|
13538
|
-
static isRivetError(error46) {
|
|
13539
|
-
return isRivetErrorLike(error46);
|
|
13540
|
-
}
|
|
13541
|
-
static isActorError(error46) {
|
|
13542
|
-
return isRivetErrorLike(error46);
|
|
13543
|
-
}
|
|
13544
|
-
constructor(group, code, message, options) {
|
|
13545
|
-
const normalized = looksLikeRivetErrorOptions(options) ? options : { metadata: options };
|
|
13546
|
-
super(message, { cause: normalized.cause });
|
|
13547
|
-
this.name = "RivetError";
|
|
13548
|
-
this.group = group;
|
|
13549
|
-
this.code = code;
|
|
13550
|
-
this.public = normalized.public ?? false;
|
|
13551
|
-
this.metadata = normalized.metadata;
|
|
13552
|
-
this.rayId = normalized.rayId ?? void 0;
|
|
13553
|
-
this.statusCode = normalized.statusCode ?? (this.public ? 400 : 500);
|
|
13554
|
-
this.actor = normalized.actor;
|
|
13555
|
-
}
|
|
13556
|
-
toString() {
|
|
13557
|
-
return this.message;
|
|
13558
|
-
}
|
|
13559
|
-
};
|
|
13560
|
-
var UserError = class extends RivetError {
|
|
13561
|
-
constructor(message, options) {
|
|
13562
|
-
super("user", (options == null ? void 0 : options.code) ?? USER_ERROR_CODE, message, {
|
|
13563
|
-
public: true,
|
|
13564
|
-
metadata: options == null ? void 0 : options.metadata,
|
|
13565
|
-
cause: options == null ? void 0 : options.cause
|
|
13566
|
-
});
|
|
13567
|
-
}
|
|
13568
|
-
};
|
|
13569
|
-
function toRivetError(error46, fallback) {
|
|
13570
|
-
if (typeof error46 === "string") {
|
|
13571
|
-
const bridged = decodeBridgeRivetError(error46);
|
|
13572
|
-
if (bridged) {
|
|
13573
|
-
return bridged;
|
|
13574
|
-
}
|
|
13575
|
-
}
|
|
13576
|
-
if (error46 instanceof Error) {
|
|
13577
|
-
const bridged = decodeBridgeRivetError(error46.message);
|
|
13578
|
-
if (bridged) {
|
|
13579
|
-
return bridged;
|
|
13580
|
-
}
|
|
13581
|
-
}
|
|
13582
|
-
if (isRivetErrorLike(error46)) {
|
|
13583
|
-
return new RivetError(error46.group, error46.code, error46.message, {
|
|
13584
|
-
public: error46.public,
|
|
13585
|
-
statusCode: error46.statusCode,
|
|
13586
|
-
metadata: error46.metadata,
|
|
13587
|
-
rayId: error46.rayId,
|
|
13588
|
-
actor: error46.actor,
|
|
13589
|
-
cause: error46 instanceof Error ? error46.cause : void 0
|
|
13590
|
-
});
|
|
13591
|
-
}
|
|
13592
|
-
return new RivetError(
|
|
13593
|
-
(fallback == null ? void 0 : fallback.group) ?? "actor",
|
|
13594
|
-
(fallback == null ? void 0 : fallback.code) ?? INTERNAL_ERROR_CODE,
|
|
13595
|
-
errorMessage(error46, (fallback == null ? void 0 : fallback.message) ?? "Unknown error"),
|
|
13596
|
-
{
|
|
13597
|
-
public: fallback == null ? void 0 : fallback.public,
|
|
13598
|
-
statusCode: fallback == null ? void 0 : fallback.statusCode,
|
|
13599
|
-
metadata: fallback == null ? void 0 : fallback.metadata,
|
|
13600
|
-
rayId: fallback == null ? void 0 : fallback.rayId,
|
|
13601
|
-
actor: fallback == null ? void 0 : fallback.actor,
|
|
13602
|
-
cause: error46 instanceof Error ? error46 : void 0
|
|
13603
|
-
}
|
|
13604
|
-
);
|
|
13605
|
-
}
|
|
13606
|
-
function encodeBridgeRivetError(error46) {
|
|
13607
|
-
return `${BRIDGE_RIVET_ERROR_PREFIX}${JSON.stringify({
|
|
13608
|
-
group: error46.group,
|
|
13609
|
-
code: error46.code,
|
|
13610
|
-
message: error46.message,
|
|
13611
|
-
metadata: error46.metadata,
|
|
13612
|
-
rayId: error46.rayId,
|
|
13613
|
-
public: error46.public,
|
|
13614
|
-
statusCode: error46.statusCode,
|
|
13615
|
-
actor: error46.actor
|
|
13616
|
-
})}`;
|
|
13617
|
-
}
|
|
13618
|
-
function encodeErrorForBridge(error46) {
|
|
13619
|
-
if (isCanonicalStructuredRivetError(error46)) {
|
|
13620
|
-
return encodeBridgeRivetError(error46);
|
|
13621
|
-
}
|
|
13622
|
-
return String(error46);
|
|
13623
|
-
}
|
|
13624
|
-
function isCanonicalStructuredRivetError(error46) {
|
|
13625
|
-
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";
|
|
13626
|
-
}
|
|
13627
|
-
function decodeBridgeRivetErrorPayload(value) {
|
|
13628
|
-
if (!value.startsWith(BRIDGE_RIVET_ERROR_PREFIX)) {
|
|
13629
|
-
return void 0;
|
|
13630
|
-
}
|
|
13631
|
-
try {
|
|
13632
|
-
const raw = JSON.parse(
|
|
13633
|
-
value.slice(BRIDGE_RIVET_ERROR_PREFIX.length)
|
|
13634
|
-
);
|
|
13635
|
-
const payload = {
|
|
13636
|
-
...raw,
|
|
13637
|
-
rayId: raw.rayId ?? void 0
|
|
13638
|
-
};
|
|
13639
|
-
if (!isRivetErrorLike(payload)) {
|
|
13640
|
-
return void 0;
|
|
13641
|
-
}
|
|
13642
|
-
if (payload.actor !== void 0 && payload.actor !== null && !isActorSpecifier(payload.actor)) {
|
|
13643
|
-
return void 0;
|
|
13644
|
-
}
|
|
13645
|
-
return payload;
|
|
13646
|
-
} catch {
|
|
13647
|
-
return void 0;
|
|
13648
|
-
}
|
|
13649
|
-
}
|
|
13650
|
-
function decodeBridgeRivetError(value) {
|
|
13651
|
-
const payload = decodeBridgeRivetErrorPayload(value);
|
|
13652
|
-
if (!payload) {
|
|
13653
|
-
return void 0;
|
|
13654
|
-
}
|
|
13655
|
-
return new RivetError(payload.group, payload.code, payload.message, {
|
|
13656
|
-
metadata: payload.metadata,
|
|
13657
|
-
rayId: payload.rayId,
|
|
13658
|
-
public: payload.public,
|
|
13659
|
-
statusCode: payload.statusCode,
|
|
13660
|
-
actor: payload.actor ?? void 0
|
|
13661
|
-
});
|
|
13662
|
-
}
|
|
13663
|
-
function invalidRequest(error46) {
|
|
13664
|
-
return new RivetError(
|
|
13665
|
-
"request",
|
|
13666
|
-
"invalid",
|
|
13667
|
-
`Invalid request: ${errorMessage(error46, String(error46))}`,
|
|
13668
|
-
{
|
|
13669
|
-
public: true,
|
|
13670
|
-
cause: error46 instanceof Error ? error46 : void 0
|
|
13671
|
-
}
|
|
13672
|
-
);
|
|
13673
|
-
}
|
|
13674
|
-
function actorNotFound(identifier) {
|
|
13675
|
-
return new RivetError(
|
|
13676
|
-
"actor",
|
|
13677
|
-
"not_found",
|
|
13678
|
-
identifier ? `Actor not found: ${identifier} (https://www.rivet.dev/docs/clients/javascript)` : "Actor not found (https://www.rivet.dev/docs/clients/javascript)",
|
|
13679
|
-
{ public: true }
|
|
13680
|
-
);
|
|
13681
|
-
}
|
|
13682
|
-
function forbiddenError() {
|
|
13683
|
-
return new RivetError("auth", "forbidden", "Forbidden", {
|
|
13684
|
-
public: true,
|
|
13685
|
-
statusCode: 403
|
|
13686
|
-
});
|
|
13687
|
-
}
|
|
13688
|
-
function unsupportedFeature(feature) {
|
|
13689
|
-
return new RivetError(
|
|
13690
|
-
"feature",
|
|
13691
|
-
"unsupported",
|
|
13692
|
-
`Unsupported feature: ${feature}`
|
|
13693
|
-
);
|
|
13694
|
-
}
|
|
13695
|
-
|
|
13696
|
-
// ../rivetkit/dist/tsup/chunk-DHWZTUKA.js
|
|
13697
|
-
var import_pino = require("pino");
|
|
13698
|
-
var cbor = __toESM(require("cbor-x"), 1);
|
|
13699
|
-
var import_invariant = __toESM(require_invariant(), 1);
|
|
13700
|
-
var getRivetEngine = () => getEnvUniversal("RIVET_ENGINE");
|
|
13701
|
-
var getRivetEndpoint = () => getEnvUniversal("RIVET_ENDPOINT");
|
|
13702
|
-
var getRivetToken = () => getEnvUniversal("RIVET_TOKEN");
|
|
13703
|
-
var getRivetNamespace = () => getEnvUniversal("RIVET_NAMESPACE");
|
|
13704
|
-
var getRivetPool = () => getEnvUniversal("RIVET_POOL");
|
|
13705
|
-
var getRivetTotalSlots = () => {
|
|
13706
|
-
const value = getEnvUniversal("RIVET_TOTAL_SLOTS");
|
|
13707
|
-
return value !== void 0 ? parseInt(value, 10) : void 0;
|
|
13708
|
-
};
|
|
13709
|
-
var getRivetRunEngine = () => getEnvUniversal("RIVET_RUN_ENGINE") === "1";
|
|
13710
|
-
var getRivetRunEngineHost = () => getEnvUniversal("RIVET_RUN_ENGINE_HOST");
|
|
13711
|
-
var getRivetRunEnginePort = () => {
|
|
13712
|
-
const value = getEnvUniversal("RIVET_RUN_ENGINE_PORT");
|
|
13713
|
-
return value !== void 0 ? parseInt(value, 10) : void 0;
|
|
13714
|
-
};
|
|
13715
|
-
var getRivetRunEngineVersion = () => getEnvUniversal("RIVET_RUN_ENGINE_VERSION");
|
|
13716
|
-
var getRivetRunServices = () => {
|
|
13717
|
-
const value = getEnvUniversal("RIVET_RUN_SERVICES");
|
|
13718
|
-
return value === void 0 ? void 0 : value === "1";
|
|
13719
|
-
};
|
|
13720
|
-
var getRivetEnvoyVersion = () => {
|
|
13721
|
-
const value = getEnvUniversal("RIVET_ENVOY_VERSION");
|
|
13722
|
-
return value !== void 0 ? parseInt(value, 10) : void 0;
|
|
13723
|
-
};
|
|
13724
|
-
var getRivetPublicEndpoint = () => getEnvUniversal("RIVET_PUBLIC_ENDPOINT");
|
|
13725
|
-
var getRivetPublicToken = () => getEnvUniversal("RIVET_PUBLIC_TOKEN");
|
|
13726
|
-
var getRivetkitRuntime = () => getEnvUniversal("RIVETKIT_RUNTIME");
|
|
13727
|
-
var getRivetkitRuntimeMode = () => {
|
|
13728
|
-
const value = getEnvUniversal("RIVETKIT_RUNTIME_MODE");
|
|
13729
|
-
if (value === void 0) return "envoy";
|
|
13730
|
-
if (value === "envoy" || value === "serverless") return value;
|
|
13731
|
-
throw new Error(
|
|
13732
|
-
`RIVETKIT_RUNTIME_MODE env var must be "envoy" or "serverless"; got "${value}"`
|
|
13733
|
-
);
|
|
13734
|
-
};
|
|
13735
|
-
var getRivetkitPublicDir = () => {
|
|
13736
|
-
const value = getEnvUniversal("RIVETKIT_PUBLIC_DIR");
|
|
13737
|
-
return value === void 0 || value === "" ? void 0 : value;
|
|
13738
|
-
};
|
|
13739
|
-
function parsePortEnv(raw) {
|
|
13740
|
-
if (raw === void 0 || raw === "") return void 0;
|
|
13741
|
-
const parsed = Number.parseInt(raw, 10);
|
|
13742
|
-
if (!Number.isFinite(parsed) || parsed < 1 || parsed > 65535 || String(parsed) !== raw.trim()) {
|
|
13743
|
-
throw new Error(
|
|
13744
|
-
`RIVET_PORT env var must be an integer between 1 and 65535; got "${raw}"`
|
|
13745
|
-
);
|
|
13746
|
-
}
|
|
13747
|
-
return parsed;
|
|
13748
|
-
}
|
|
13749
|
-
var getLogLevel = () => getEnvUniversal("RIVET_LOG_LEVEL") ?? getEnvUniversal("LOG_LEVEL");
|
|
13750
|
-
var getLogTarget = () => getEnvUniversal("RIVET_LOG_TARGET") === "1";
|
|
13751
|
-
var getLogTimestamp = () => getEnvUniversal("RIVET_LOG_TIMESTAMP") === "1";
|
|
13752
|
-
var getLogMessage = () => getEnvUniversal("RIVET_LOG_MESSAGE") === "1";
|
|
13753
|
-
var getLogErrorStack = () => getEnvUniversal("RIVET_LOG_ERROR_STACK") === "1";
|
|
13754
|
-
var getNodeEnv = () => getEnvUniversal("NODE_ENV");
|
|
13755
|
-
var getNextPhase = () => getEnvUniversal("NEXT_PHASE");
|
|
13756
|
-
var isDev = () => getNodeEnv() !== "production";
|
|
13757
|
-
function assertUnreachable(x) {
|
|
13758
|
-
throw new Error(`Unreachable case: ${x}`);
|
|
13759
|
-
}
|
|
13760
|
-
function deconstructError(error46, exposeInternalError = false) {
|
|
13761
|
-
let statusCode;
|
|
13762
|
-
let public_;
|
|
13763
|
-
let group;
|
|
13764
|
-
let code;
|
|
13765
|
-
let message;
|
|
13766
|
-
let metadata;
|
|
13767
|
-
let rayId;
|
|
13768
|
-
let actor2;
|
|
13769
|
-
if (isCanonicalStructuredRivetError(error46)) {
|
|
13770
|
-
statusCode = typeof error46.statusCode === "number" ? error46.statusCode : error46.public ? 400 : 500;
|
|
13771
|
-
public_ = error46.public ?? false;
|
|
13772
|
-
group = error46.group;
|
|
13773
|
-
code = error46.code;
|
|
13774
|
-
message = error46.message;
|
|
13775
|
-
metadata = error46.metadata;
|
|
13776
|
-
rayId = error46.rayId;
|
|
13777
|
-
actor2 = error46.actor;
|
|
13778
|
-
} else if (RivetError.isActorError(error46) && error46.public) {
|
|
13779
|
-
statusCode = "statusCode" in error46 && error46.statusCode ? error46.statusCode : 400;
|
|
13780
|
-
public_ = true;
|
|
13781
|
-
group = error46.group;
|
|
13782
|
-
code = error46.code;
|
|
13783
|
-
message = getErrorMessage(error46);
|
|
13784
|
-
metadata = error46.metadata;
|
|
13785
|
-
rayId = error46.rayId;
|
|
13786
|
-
actor2 = error46.actor;
|
|
13787
|
-
} else if (exposeInternalError) {
|
|
13788
|
-
if (RivetError.isActorError(error46)) {
|
|
13789
|
-
statusCode = 500;
|
|
13790
|
-
public_ = false;
|
|
13791
|
-
group = error46.group;
|
|
13792
|
-
code = error46.code;
|
|
13793
|
-
message = getErrorMessage(error46);
|
|
13794
|
-
metadata = error46.metadata;
|
|
13795
|
-
rayId = error46.rayId;
|
|
13796
|
-
actor2 = error46.actor;
|
|
13797
|
-
} else {
|
|
13798
|
-
statusCode = 500;
|
|
13799
|
-
public_ = false;
|
|
13800
|
-
group = "rivetkit";
|
|
13801
|
-
code = INTERNAL_ERROR_CODE;
|
|
13802
|
-
message = getErrorMessage(error46);
|
|
13803
|
-
}
|
|
13804
|
-
} else {
|
|
13805
|
-
statusCode = 500;
|
|
13806
|
-
public_ = false;
|
|
13807
|
-
group = "rivetkit";
|
|
13808
|
-
code = INTERNAL_ERROR_CODE;
|
|
13809
|
-
message = INTERNAL_ERROR_DESCRIPTION;
|
|
13810
|
-
if (RivetError.isActorError(error46)) {
|
|
13811
|
-
actor2 = error46.actor;
|
|
13812
|
-
}
|
|
13813
|
-
metadata = {
|
|
13814
|
-
//url: `https://dashboard.rivet.dev/projects/${actorMetadata.project.slug}/environments/${actorMetadata.environment.slug}/actors?actorId=${actorMetadata.actor.id}`,
|
|
13815
|
-
};
|
|
13816
|
-
}
|
|
13817
|
-
return {
|
|
13818
|
-
__type: "ActorError",
|
|
13819
|
-
statusCode,
|
|
13820
|
-
public: public_,
|
|
13821
|
-
group,
|
|
13822
|
-
code,
|
|
13823
|
-
message,
|
|
13824
|
-
metadata,
|
|
13825
|
-
rayId,
|
|
13826
|
-
actor: actor2
|
|
13827
|
-
};
|
|
13828
|
-
}
|
|
13829
|
-
function stringifyError(error46) {
|
|
13830
|
-
if (error46 instanceof Error) {
|
|
13831
|
-
if (typeof process !== "undefined" && getLogErrorStack()) {
|
|
13832
|
-
let stack;
|
|
13833
|
-
try {
|
|
13834
|
-
stack = error46.stack;
|
|
13835
|
-
} catch {
|
|
13836
|
-
stack = void 0;
|
|
13837
|
-
}
|
|
13838
|
-
return `${error46.name}: ${error46.message}${stack ? `
|
|
13839
|
-
${stack}` : ""}`;
|
|
13840
|
-
} else {
|
|
13841
|
-
return `${error46.name}: ${error46.message}`;
|
|
13842
|
-
}
|
|
13843
|
-
} else if (typeof error46 === "string") {
|
|
13844
|
-
return error46;
|
|
13845
|
-
} else if (typeof error46 === "object" && error46 !== null) {
|
|
13846
|
-
try {
|
|
13847
|
-
return `${JSON.stringify(error46)}`;
|
|
13848
|
-
} catch {
|
|
13849
|
-
return "[cannot stringify error]";
|
|
13850
|
-
}
|
|
13851
|
-
} else {
|
|
13852
|
-
return `Unknown error: ${getErrorMessage(error46)}`;
|
|
13853
|
-
}
|
|
13854
|
-
}
|
|
13855
|
-
function getErrorMessage(err) {
|
|
13856
|
-
if (err && typeof err === "object" && "message" in err && typeof err.message === "string") {
|
|
13857
|
-
return err.message;
|
|
13858
|
-
} else {
|
|
13859
|
-
return String(err);
|
|
13860
|
-
}
|
|
13861
|
-
}
|
|
13862
|
-
function noopNext() {
|
|
13863
|
-
return async () => {
|
|
13864
|
-
};
|
|
13379
|
+
function noopNext() {
|
|
13380
|
+
return async () => {
|
|
13381
|
+
};
|
|
13865
13382
|
}
|
|
13866
13383
|
var package_default = {
|
|
13867
13384
|
name: "rivetkit",
|
|
13868
|
-
version: "2.3.
|
|
13385
|
+
version: "2.3.22",
|
|
13869
13386
|
description: "Lightweight libraries for building stateful actors on edge platforms",
|
|
13870
13387
|
license: "Apache-2.0",
|
|
13871
13388
|
keywords: [
|
|
@@ -14078,6 +13595,7 @@ var package_default = {
|
|
|
14078
13595
|
"@rivet-dev/agent-os-core": "^0.1.1",
|
|
14079
13596
|
"@rivet-dev/services": "^0.1.5",
|
|
14080
13597
|
"@rivetkit/bare-ts": "^0.6.2",
|
|
13598
|
+
"@rivetkit/engine-api-full": "workspace:*",
|
|
14081
13599
|
"@rivetkit/engine-cli": "workspace:*",
|
|
14082
13600
|
"@rivetkit/engine-envoy-protocol": "workspace:*",
|
|
14083
13601
|
"@rivetkit/on-change": "6.0.1",
|
|
@@ -15171,7 +14689,7 @@ function Config({ initialBufferLength = 1024, maxBufferLength = 1024 * 1024 * 32
|
|
|
15171
14689
|
};
|
|
15172
14690
|
}
|
|
15173
14691
|
|
|
15174
|
-
// ../rivetkit/dist/tsup/chunk-
|
|
14692
|
+
// ../rivetkit/dist/tsup/chunk-XZBDVEQN.js
|
|
15175
14693
|
var config2 = /* @__PURE__ */ Config({});
|
|
15176
14694
|
function readWorkflowCbor(bc) {
|
|
15177
14695
|
return readData(bc);
|
|
@@ -15450,24 +14968,519 @@ function read6(bc) {
|
|
|
15450
14968
|
}
|
|
15451
14969
|
return result;
|
|
15452
14970
|
}
|
|
15453
|
-
function readWorkflowHistory(bc) {
|
|
15454
|
-
return {
|
|
15455
|
-
nameRegistry: read4(bc),
|
|
15456
|
-
entries: read5(bc),
|
|
15457
|
-
entryMetadata: read6(bc)
|
|
15458
|
-
};
|
|
14971
|
+
function readWorkflowHistory(bc) {
|
|
14972
|
+
return {
|
|
14973
|
+
nameRegistry: read4(bc),
|
|
14974
|
+
entries: read5(bc),
|
|
14975
|
+
entryMetadata: read6(bc)
|
|
14976
|
+
};
|
|
14977
|
+
}
|
|
14978
|
+
function decodeWorkflowHistory(bytes) {
|
|
14979
|
+
const bc = new ByteCursor(bytes, config2);
|
|
14980
|
+
const result = readWorkflowHistory(bc);
|
|
14981
|
+
if (bc.offset < bc.view.byteLength) {
|
|
14982
|
+
throw new BareError(bc.offset, "remaining bytes");
|
|
14983
|
+
}
|
|
14984
|
+
return result;
|
|
14985
|
+
}
|
|
14986
|
+
function decodeWorkflowHistoryTransport(data) {
|
|
14987
|
+
return decodeWorkflowHistory(toUint8Array(data));
|
|
14988
|
+
}
|
|
14989
|
+
|
|
14990
|
+
// ../rivetkit/dist/tsup/chunk-CSOHAAZK.js
|
|
14991
|
+
function flattenActionHandlers(actions) {
|
|
14992
|
+
const flattened = /* @__PURE__ */ Object.create(null);
|
|
14993
|
+
for (const { name, handler } of collectActionEntries(actions)) {
|
|
14994
|
+
flattened[name] = handler;
|
|
14995
|
+
}
|
|
14996
|
+
return flattened;
|
|
14997
|
+
}
|
|
14998
|
+
function flattenActionInputSchemas(actions, schemas) {
|
|
14999
|
+
if (schemas === void 0) return void 0;
|
|
15000
|
+
if (!isRecord(schemas)) {
|
|
15001
|
+
throw new TypeError("actionInputSchemas must be an object");
|
|
15002
|
+
}
|
|
15003
|
+
const flattened = /* @__PURE__ */ Object.create(null);
|
|
15004
|
+
for (const { name, path: path2 } of collectActionEntries(actions)) {
|
|
15005
|
+
const nestedSchema = lookupNestedSchema(schemas, path2);
|
|
15006
|
+
const flatSchema = schemas[name];
|
|
15007
|
+
if (nestedSchema !== void 0 && flatSchema !== void 0 && nestedSchema !== flatSchema) {
|
|
15008
|
+
throw new TypeError(
|
|
15009
|
+
`Action input schema \`${name}\` is defined by both a nested path and a dotted key`
|
|
15010
|
+
);
|
|
15011
|
+
}
|
|
15012
|
+
const schema = nestedSchema ?? flatSchema;
|
|
15013
|
+
if (schema !== void 0) {
|
|
15014
|
+
flattened[name] = schema;
|
|
15015
|
+
}
|
|
15016
|
+
}
|
|
15017
|
+
return flattened;
|
|
15018
|
+
}
|
|
15019
|
+
function flattenActionTraceSamplers(actions, rates = {}) {
|
|
15020
|
+
const handlers = flattenActionHandlers(actions);
|
|
15021
|
+
const flattened = Object.fromEntries(flattenSampleRates(rates, []));
|
|
15022
|
+
for (const name of Object.keys(flattened)) {
|
|
15023
|
+
if (!Object.hasOwn(handlers, name)) {
|
|
15024
|
+
throw new TypeError(
|
|
15025
|
+
`tracing.actions.${name} does not name an action`
|
|
15026
|
+
);
|
|
15027
|
+
}
|
|
15028
|
+
}
|
|
15029
|
+
return flattened;
|
|
15030
|
+
}
|
|
15031
|
+
function flattenSampleRates(rates, path2) {
|
|
15032
|
+
return Object.entries(rates).flatMap(
|
|
15033
|
+
([segment, rate]) => {
|
|
15034
|
+
const childPath = [...path2, segment];
|
|
15035
|
+
return typeof rate === "number" ? [[childPath.join("."), rate]] : flattenSampleRates(rate, childPath);
|
|
15036
|
+
}
|
|
15037
|
+
);
|
|
15038
|
+
}
|
|
15039
|
+
function collectActionEntries(actions) {
|
|
15040
|
+
const entries = [];
|
|
15041
|
+
const names = /* @__PURE__ */ new Set();
|
|
15042
|
+
visitActionGroup(actions ?? {}, [], entries, names);
|
|
15043
|
+
return entries;
|
|
15044
|
+
}
|
|
15045
|
+
function visitActionGroup(value, path2, entries, names) {
|
|
15046
|
+
if (!isRecord(value)) {
|
|
15047
|
+
throw new TypeError(
|
|
15048
|
+
`${formatActionPath(path2)} must be an action handler or group`
|
|
15049
|
+
);
|
|
15050
|
+
}
|
|
15051
|
+
for (const [segment, child] of Object.entries(value)) {
|
|
15052
|
+
const childPath = [...path2, segment];
|
|
15053
|
+
if (typeof child === "function") {
|
|
15054
|
+
const name = childPath.join(".");
|
|
15055
|
+
if (names.has(name)) {
|
|
15056
|
+
throw new TypeError(
|
|
15057
|
+
`Multiple action definitions flatten to \`${name}\``
|
|
15058
|
+
);
|
|
15059
|
+
}
|
|
15060
|
+
names.add(name);
|
|
15061
|
+
entries.push({
|
|
15062
|
+
name,
|
|
15063
|
+
path: childPath,
|
|
15064
|
+
handler: child
|
|
15065
|
+
});
|
|
15066
|
+
} else {
|
|
15067
|
+
visitActionGroup(child, childPath, entries, names);
|
|
15068
|
+
}
|
|
15069
|
+
}
|
|
15070
|
+
}
|
|
15071
|
+
function lookupNestedSchema(schemas, path2) {
|
|
15072
|
+
let value = schemas;
|
|
15073
|
+
for (const segment of path2) {
|
|
15074
|
+
if (!isRecord(value) || !Object.hasOwn(value, segment)) {
|
|
15075
|
+
return void 0;
|
|
15076
|
+
}
|
|
15077
|
+
value = value[segment];
|
|
15078
|
+
}
|
|
15079
|
+
return value;
|
|
15080
|
+
}
|
|
15081
|
+
function isRecord(value) {
|
|
15082
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
15083
|
+
return false;
|
|
15084
|
+
}
|
|
15085
|
+
const prototype = Object.getPrototypeOf(value);
|
|
15086
|
+
return prototype === Object.prototype || prototype === null;
|
|
15087
|
+
}
|
|
15088
|
+
function formatActionPath(path2) {
|
|
15089
|
+
return path2.length === 0 ? "actions" : `Action \`${path2.join(".")}\``;
|
|
15090
|
+
}
|
|
15091
|
+
var DEFAULT_SLEEP_GRACE_PERIOD = 15e3;
|
|
15092
|
+
var ACTOR_CONTEXT_INTERNAL_SYMBOL = /* @__PURE__ */ Symbol(
|
|
15093
|
+
"rivetkit.actor_context_internal"
|
|
15094
|
+
);
|
|
15095
|
+
var RAW_STATE_SYMBOL = /* @__PURE__ */ Symbol("rivetkit.raw_state");
|
|
15096
|
+
var CONN_STATE_MANAGER_SYMBOL = /* @__PURE__ */ Symbol("rivetkit.conn_state_manager");
|
|
15097
|
+
var zFunction = () => external_exports.custom((val) => typeof val === "function");
|
|
15098
|
+
var zActionTree = external_exports.custom((value) => {
|
|
15099
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
15100
|
+
return false;
|
|
15101
|
+
}
|
|
15102
|
+
const prototype = Object.getPrototypeOf(value);
|
|
15103
|
+
return prototype === Object.prototype || prototype === null;
|
|
15104
|
+
}).superRefine((actions, ctx) => {
|
|
15105
|
+
try {
|
|
15106
|
+
flattenActionHandlers(actions);
|
|
15107
|
+
} catch (error46) {
|
|
15108
|
+
ctx.addIssue({
|
|
15109
|
+
code: "custom",
|
|
15110
|
+
message: error46 instanceof Error ? error46.message : "Invalid action definition"
|
|
15111
|
+
});
|
|
15112
|
+
}
|
|
15113
|
+
});
|
|
15114
|
+
var WorkflowInspectorConfigSchema = external_exports.object({
|
|
15115
|
+
getHistory: zFunction(),
|
|
15116
|
+
getState: zFunction().optional(),
|
|
15117
|
+
onHistoryUpdated: zFunction().optional(),
|
|
15118
|
+
replayFromStep: zFunction().optional()
|
|
15119
|
+
});
|
|
15120
|
+
var RunInspectorConfigSchema = external_exports.object({
|
|
15121
|
+
workflow: WorkflowInspectorConfigSchema.optional()
|
|
15122
|
+
}).optional();
|
|
15123
|
+
var BUILTIN_INSPECTOR_TAB_IDS = [
|
|
15124
|
+
"workflow",
|
|
15125
|
+
"database",
|
|
15126
|
+
"state",
|
|
15127
|
+
"queue",
|
|
15128
|
+
"schedules",
|
|
15129
|
+
"connections",
|
|
15130
|
+
"console"
|
|
15131
|
+
];
|
|
15132
|
+
var BuiltinInspectorTabIdSchema = external_exports.enum(BUILTIN_INSPECTOR_TAB_IDS);
|
|
15133
|
+
var CUSTOM_INSPECTOR_TAB_ID_RE = /^[A-Za-z0-9_-]+$/;
|
|
15134
|
+
var CustomInspectorTabEntrySchema = external_exports.object({
|
|
15135
|
+
id: external_exports.string().regex(
|
|
15136
|
+
CUSTOM_INSPECTOR_TAB_ID_RE,
|
|
15137
|
+
"inspector.tabs[].id must contain only letters, digits, underscore, or dash"
|
|
15138
|
+
),
|
|
15139
|
+
label: external_exports.string().min(1),
|
|
15140
|
+
source: external_exports.string().min(1),
|
|
15141
|
+
/**
|
|
15142
|
+
* Optional icon id. The dashboard maps strings to glyphs (see its
|
|
15143
|
+
* icon registry); unknown ids fall back to a generic icon.
|
|
15144
|
+
*/
|
|
15145
|
+
icon: external_exports.string().min(1).optional(),
|
|
15146
|
+
hidden: external_exports.literal(false).optional()
|
|
15147
|
+
}).strict();
|
|
15148
|
+
var HideInspectorTabEntrySchema = external_exports.object({
|
|
15149
|
+
id: BuiltinInspectorTabIdSchema,
|
|
15150
|
+
hidden: external_exports.literal(true)
|
|
15151
|
+
}).strict();
|
|
15152
|
+
var InspectorTabEntrySchema = external_exports.union([
|
|
15153
|
+
CustomInspectorTabEntrySchema,
|
|
15154
|
+
HideInspectorTabEntrySchema
|
|
15155
|
+
]);
|
|
15156
|
+
var ActorInspectorConfigSchema = external_exports.object({
|
|
15157
|
+
tabs: external_exports.array(InspectorTabEntrySchema).default(() => [])
|
|
15158
|
+
}).strict().refine(
|
|
15159
|
+
(data) => {
|
|
15160
|
+
const ids = data.tabs.map((t) => t.id);
|
|
15161
|
+
return new Set(ids).size === ids.length;
|
|
15162
|
+
},
|
|
15163
|
+
{ message: "Duplicate id in inspector.tabs", path: ["tabs"] }
|
|
15164
|
+
).refine(
|
|
15165
|
+
(data) => {
|
|
15166
|
+
const builtinSet = new Set(BUILTIN_INSPECTOR_TAB_IDS);
|
|
15167
|
+
return data.tabs.every(
|
|
15168
|
+
(t) => t.hidden === true || !builtinSet.has(t.id)
|
|
15169
|
+
);
|
|
15170
|
+
},
|
|
15171
|
+
{
|
|
15172
|
+
message: "Custom inspector tab id collides with a built-in (use hidden: true to hide a built-in)",
|
|
15173
|
+
path: ["tabs"]
|
|
15174
|
+
}
|
|
15175
|
+
);
|
|
15176
|
+
var RunConfigSchema = external_exports.object({
|
|
15177
|
+
/** Display name for the actor in the Inspector UI. */
|
|
15178
|
+
name: external_exports.string().optional(),
|
|
15179
|
+
/** Icon for the actor in the Inspector UI. Can be an emoji or FontAwesome icon name. */
|
|
15180
|
+
icon: external_exports.string().optional(),
|
|
15181
|
+
/** The run handler function. */
|
|
15182
|
+
run: zFunction(),
|
|
15183
|
+
/** Inspector integration for long-running run handlers. */
|
|
15184
|
+
inspector: RunInspectorConfigSchema.optional()
|
|
15185
|
+
});
|
|
15186
|
+
var RUN_FUNCTION_CONFIG_SYMBOL = /* @__PURE__ */ Symbol.for("rivetkit.run_function_config");
|
|
15187
|
+
function defineRunHandler(run, options) {
|
|
15188
|
+
if (options.inspectorKind === void 0 !== (options.createInspector === void 0)) {
|
|
15189
|
+
throw new TypeError(
|
|
15190
|
+
"defineRunHandler requires inspectorKind and createInspector together"
|
|
15191
|
+
);
|
|
15192
|
+
}
|
|
15193
|
+
Object.defineProperty(run, RUN_FUNCTION_CONFIG_SYMBOL, {
|
|
15194
|
+
configurable: false,
|
|
15195
|
+
enumerable: false,
|
|
15196
|
+
writable: false,
|
|
15197
|
+
value: {
|
|
15198
|
+
name: options.name,
|
|
15199
|
+
icon: options.icon,
|
|
15200
|
+
inspectorKind: options.inspectorKind,
|
|
15201
|
+
createInspector: options.createInspector
|
|
15202
|
+
}
|
|
15203
|
+
});
|
|
15204
|
+
return run;
|
|
15205
|
+
}
|
|
15206
|
+
function getRunInspectorKind(run) {
|
|
15207
|
+
var _a2;
|
|
15208
|
+
if (!run || typeof run !== "function") return void 0;
|
|
15209
|
+
return (_a2 = run[RUN_FUNCTION_CONFIG_SYMBOL]) == null ? void 0 : _a2.inspectorKind;
|
|
15210
|
+
}
|
|
15211
|
+
function createRunInspector(run, context2) {
|
|
15212
|
+
var _a2, _b;
|
|
15213
|
+
if (!run || typeof run !== "function") return void 0;
|
|
15214
|
+
return (_b = (_a2 = run[RUN_FUNCTION_CONFIG_SYMBOL]) == null ? void 0 : _a2.createInspector) == null ? void 0 : _b.call(_a2, context2);
|
|
15215
|
+
}
|
|
15216
|
+
var zRunHandler = external_exports.union([zFunction(), RunConfigSchema]).optional();
|
|
15217
|
+
function getRunFunction(run) {
|
|
15218
|
+
if (!run) return void 0;
|
|
15219
|
+
if (typeof run === "function") return run;
|
|
15220
|
+
return run.run;
|
|
15221
|
+
}
|
|
15222
|
+
function getRunMetadata(run) {
|
|
15223
|
+
if (!run) return {};
|
|
15224
|
+
if (typeof run === "function") {
|
|
15225
|
+
const config3 = run[RUN_FUNCTION_CONFIG_SYMBOL];
|
|
15226
|
+
if (!config3) return {};
|
|
15227
|
+
return { name: config3.name, icon: config3.icon };
|
|
15228
|
+
}
|
|
15229
|
+
return { name: run.name, icon: run.icon };
|
|
15459
15230
|
}
|
|
15460
|
-
function
|
|
15461
|
-
|
|
15462
|
-
|
|
15463
|
-
|
|
15464
|
-
|
|
15231
|
+
function getRunInspectorConfig(run, actor2) {
|
|
15232
|
+
if (!run) return void 0;
|
|
15233
|
+
if (typeof run === "function") {
|
|
15234
|
+
const config3 = run[RUN_FUNCTION_CONFIG_SYMBOL];
|
|
15235
|
+
return (config3 == null ? void 0 : config3.inspectorFactory) ? config3.inspectorFactory(actor2) : config3 == null ? void 0 : config3.inspector;
|
|
15465
15236
|
}
|
|
15466
|
-
return
|
|
15237
|
+
return run.inspector;
|
|
15467
15238
|
}
|
|
15468
|
-
function
|
|
15469
|
-
|
|
15239
|
+
function hasRunInspectorConfig(run) {
|
|
15240
|
+
if (!run) return false;
|
|
15241
|
+
if (typeof run !== "function") return run.inspector !== void 0;
|
|
15242
|
+
const config3 = run[RUN_FUNCTION_CONFIG_SYMBOL];
|
|
15243
|
+
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;
|
|
15244
|
+
}
|
|
15245
|
+
function disposeRunInspector(run, actorId) {
|
|
15246
|
+
var _a2;
|
|
15247
|
+
if (!run || typeof run !== "function") {
|
|
15248
|
+
return;
|
|
15249
|
+
}
|
|
15250
|
+
const config3 = run[RUN_FUNCTION_CONFIG_SYMBOL];
|
|
15251
|
+
(_a2 = config3 == null ? void 0 : config3.disposeInspector) == null ? void 0 : _a2.call(config3, actorId);
|
|
15470
15252
|
}
|
|
15253
|
+
var GlobalActorOptionsBaseSchema = external_exports.object({
|
|
15254
|
+
/** Display name for the actor in the Inspector UI. */
|
|
15255
|
+
name: external_exports.string().optional(),
|
|
15256
|
+
/** Icon for the actor in the Inspector UI. Can be an emoji or FontAwesome icon name. */
|
|
15257
|
+
icon: external_exports.string().optional(),
|
|
15258
|
+
/** Enables the experimental Actor Runtime Socket for this actor. */
|
|
15259
|
+
enableActorRuntimeSocket: external_exports.boolean().default(false),
|
|
15260
|
+
/**
|
|
15261
|
+
* Can hibernate WebSockets for onWebSocket.
|
|
15262
|
+
*
|
|
15263
|
+
* WebSockets using actions/events are hibernatable by default.
|
|
15264
|
+
*
|
|
15265
|
+
* @experimental
|
|
15266
|
+
**/
|
|
15267
|
+
canHibernateWebSocket: external_exports.union([external_exports.boolean(), zFunction()]).default(false)
|
|
15268
|
+
}).strict();
|
|
15269
|
+
var GlobalActorOptionsSchema = GlobalActorOptionsBaseSchema.prefault(
|
|
15270
|
+
() => ({})
|
|
15271
|
+
);
|
|
15272
|
+
var InstanceActorOptionsBaseSchema = external_exports.object({
|
|
15273
|
+
createVarsTimeout: external_exports.number().positive().default(5e3),
|
|
15274
|
+
createConnStateTimeout: external_exports.number().positive().default(5e3),
|
|
15275
|
+
onBeforeConnectTimeout: external_exports.number().positive().default(5e3),
|
|
15276
|
+
onConnectTimeout: external_exports.number().positive().default(5e3),
|
|
15277
|
+
onMigrateTimeout: external_exports.number().positive().default(3e4),
|
|
15278
|
+
sleepGracePeriod: external_exports.number().positive().default(DEFAULT_SLEEP_GRACE_PERIOD),
|
|
15279
|
+
/** @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. */
|
|
15280
|
+
onDestroyTimeout: external_exports.number().positive().optional(),
|
|
15281
|
+
/** @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. */
|
|
15282
|
+
waitUntilTimeout: external_exports.number().positive().optional(),
|
|
15283
|
+
stateSaveInterval: external_exports.number().positive().default(1e3),
|
|
15284
|
+
actionTimeout: external_exports.number().positive().default(6e4),
|
|
15285
|
+
connectionLivenessTimeout: external_exports.number().positive().default(2500),
|
|
15286
|
+
connectionLivenessInterval: external_exports.number().positive().default(5e3),
|
|
15287
|
+
/** @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. */
|
|
15288
|
+
noSleep: external_exports.boolean().default(false),
|
|
15289
|
+
sleepTimeout: external_exports.number().positive().default(3e4),
|
|
15290
|
+
maxQueueSize: external_exports.number().positive().default(1e3),
|
|
15291
|
+
/** Maximum pending one-shot and recurring schedules. */
|
|
15292
|
+
maxSchedules: external_exports.number().int().nonnegative().default(1e3),
|
|
15293
|
+
maxQueueMessageSize: external_exports.number().positive().default(64 * 1024),
|
|
15294
|
+
/** @deprecated Internal storage moved to SQLite and no longer uses KV preloading, so this option is ignored. Will be removed in 2.2.0. */
|
|
15295
|
+
preloadMaxWorkflowBytes: external_exports.number().nonnegative().optional(),
|
|
15296
|
+
/** @deprecated Internal storage moved to SQLite and no longer uses KV preloading, so this option is ignored. Will be removed in 2.2.0. */
|
|
15297
|
+
preloadMaxConnectionsBytes: external_exports.number().nonnegative().optional()
|
|
15298
|
+
}).strict();
|
|
15299
|
+
var InstanceActorOptionsSchema = InstanceActorOptionsBaseSchema.prefault(() => ({}));
|
|
15300
|
+
var ActorOptionsSchema = GlobalActorOptionsBaseSchema.extend(
|
|
15301
|
+
InstanceActorOptionsBaseSchema.shape
|
|
15302
|
+
).strict().prefault(() => ({}));
|
|
15303
|
+
var zSampleRate = external_exports.number().min(0).max(1);
|
|
15304
|
+
var zActionSampleRates = external_exports.lazy(
|
|
15305
|
+
() => external_exports.record(external_exports.string(), external_exports.union([zSampleRate, zActionSampleRates]))
|
|
15306
|
+
);
|
|
15307
|
+
var ActorConfigSchema = external_exports.object({
|
|
15308
|
+
onCreate: zFunction().optional(),
|
|
15309
|
+
onDestroy: zFunction().optional(),
|
|
15310
|
+
onMigrate: zFunction().optional(),
|
|
15311
|
+
onWake: zFunction().optional(),
|
|
15312
|
+
onSleep: zFunction().optional(),
|
|
15313
|
+
run: zRunHandler,
|
|
15314
|
+
onStateChange: zFunction().optional(),
|
|
15315
|
+
onBeforeConnect: zFunction().optional(),
|
|
15316
|
+
onConnect: zFunction().optional(),
|
|
15317
|
+
onDisconnect: zFunction().optional(),
|
|
15318
|
+
onBeforeActionResponse: zFunction().optional(),
|
|
15319
|
+
onRequest: zFunction().optional(),
|
|
15320
|
+
onWebSocket: zFunction().optional(),
|
|
15321
|
+
actions: zActionTree.default(() => ({})),
|
|
15322
|
+
actionInputSchemas: external_exports.record(external_exports.string(), external_exports.any()).optional(),
|
|
15323
|
+
tracing: external_exports.object({
|
|
15324
|
+
sampler: zSampleRate.optional(),
|
|
15325
|
+
actions: zActionSampleRates.optional()
|
|
15326
|
+
}).strict().optional(),
|
|
15327
|
+
connParamsSchema: external_exports.any().optional(),
|
|
15328
|
+
events: external_exports.record(external_exports.string(), external_exports.any()).optional(),
|
|
15329
|
+
queues: external_exports.record(external_exports.string(), external_exports.any()).optional(),
|
|
15330
|
+
state: external_exports.any().optional(),
|
|
15331
|
+
createState: zFunction().optional(),
|
|
15332
|
+
connState: external_exports.any().optional(),
|
|
15333
|
+
createConnState: zFunction().optional(),
|
|
15334
|
+
vars: external_exports.any().optional(),
|
|
15335
|
+
db: external_exports.any().optional(),
|
|
15336
|
+
createVars: zFunction().optional(),
|
|
15337
|
+
options: ActorOptionsSchema,
|
|
15338
|
+
inspector: ActorInspectorConfigSchema.optional()
|
|
15339
|
+
}).strict().refine(
|
|
15340
|
+
(data) => !(data.state !== void 0 && data.createState !== void 0),
|
|
15341
|
+
{
|
|
15342
|
+
message: "Cannot define both 'state' and 'createState'",
|
|
15343
|
+
path: ["state"]
|
|
15344
|
+
}
|
|
15345
|
+
).refine(
|
|
15346
|
+
(data) => !(data.connState !== void 0 && data.createConnState !== void 0),
|
|
15347
|
+
{
|
|
15348
|
+
message: "Cannot define both 'connState' and 'createConnState'",
|
|
15349
|
+
path: ["connState"]
|
|
15350
|
+
}
|
|
15351
|
+
).refine(
|
|
15352
|
+
(data) => !(data.vars !== void 0 && data.createVars !== void 0),
|
|
15353
|
+
{
|
|
15354
|
+
message: "Cannot define both 'vars' and 'createVars'",
|
|
15355
|
+
path: ["vars"]
|
|
15356
|
+
}
|
|
15357
|
+
);
|
|
15358
|
+
var DocActorOptionsSchema = external_exports.object({
|
|
15359
|
+
name: external_exports.string().optional().describe("Display name for the actor in the Inspector UI."),
|
|
15360
|
+
icon: external_exports.string().optional().describe(
|
|
15361
|
+
"Icon for the actor in the Inspector UI. Can be an emoji (e.g., '\u{1F680}') or FontAwesome icon name (e.g., 'rocket')."
|
|
15362
|
+
),
|
|
15363
|
+
enableActorRuntimeSocket: external_exports.boolean().optional().describe(
|
|
15364
|
+
"Enables the experimental Actor Runtime Socket for this actor. Default: false"
|
|
15365
|
+
),
|
|
15366
|
+
createVarsTimeout: external_exports.number().optional().describe("Timeout in ms for createVars handler. Default: 5000"),
|
|
15367
|
+
createConnStateTimeout: external_exports.number().optional().describe(
|
|
15368
|
+
"Timeout in ms for createConnState handler. Default: 5000"
|
|
15369
|
+
),
|
|
15370
|
+
onMigrateTimeout: external_exports.number().optional().describe("Timeout in ms for onMigrate handler. Default: 30000"),
|
|
15371
|
+
onBeforeConnectTimeout: external_exports.number().optional().describe(
|
|
15372
|
+
"Timeout in ms for onBeforeConnect handler. Default: 5000"
|
|
15373
|
+
),
|
|
15374
|
+
onConnectTimeout: external_exports.number().optional().describe("Timeout in ms for onConnect handler. Default: 5000"),
|
|
15375
|
+
sleepGracePeriod: external_exports.number().optional().describe(
|
|
15376
|
+
`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}.`
|
|
15377
|
+
),
|
|
15378
|
+
onDestroyTimeout: external_exports.number().optional().describe(
|
|
15379
|
+
"Deprecated. Folded into sleepGracePeriod, which now bounds the entire graceful shutdown window for both sleep and destroy. Will be removed in 2.2.0."
|
|
15380
|
+
),
|
|
15381
|
+
waitUntilTimeout: external_exports.number().optional().describe(
|
|
15382
|
+
"Deprecated. Folded into sleepGracePeriod, which now bounds the entire graceful shutdown window for both sleep and destroy. Will be removed in 2.2.0."
|
|
15383
|
+
),
|
|
15384
|
+
stateSaveInterval: external_exports.number().optional().describe(
|
|
15385
|
+
"Interval in ms between automatic state saves. Default: 1000"
|
|
15386
|
+
),
|
|
15387
|
+
actionTimeout: external_exports.number().optional().describe("Timeout in ms for action handlers. Default: 60000"),
|
|
15388
|
+
connectionLivenessTimeout: external_exports.number().optional().describe(
|
|
15389
|
+
"Timeout in ms for connection liveness checks. Default: 2500"
|
|
15390
|
+
),
|
|
15391
|
+
connectionLivenessInterval: external_exports.number().optional().describe(
|
|
15392
|
+
"Interval in ms between connection liveness checks. Default: 5000"
|
|
15393
|
+
),
|
|
15394
|
+
noSleep: external_exports.boolean().optional().describe(
|
|
15395
|
+
"Deprecated. If true, the actor will never sleep. Use c.keepAwake(promise) to scope keep-awake to a specific operation instead. Default: false"
|
|
15396
|
+
),
|
|
15397
|
+
sleepTimeout: external_exports.number().optional().describe(
|
|
15398
|
+
"Time in ms of inactivity before the actor sleeps. Default: 30000"
|
|
15399
|
+
),
|
|
15400
|
+
maxQueueSize: external_exports.number().optional().describe(
|
|
15401
|
+
"Maximum number of queue messages before rejecting new messages. Default: 1000"
|
|
15402
|
+
),
|
|
15403
|
+
maxSchedules: external_exports.number().int().nonnegative().optional().describe(
|
|
15404
|
+
"Maximum pending one-shot and recurring schedules before rejecting new schedules. Default: 1000"
|
|
15405
|
+
),
|
|
15406
|
+
maxQueueMessageSize: external_exports.number().optional().describe(
|
|
15407
|
+
"Maximum size of each queue message in bytes. Default: 65536"
|
|
15408
|
+
),
|
|
15409
|
+
canHibernateWebSocket: external_exports.boolean().optional().describe(
|
|
15410
|
+
"Whether WebSockets using onWebSocket can be hibernated. WebSockets using actions/events are hibernatable by default. Default: false"
|
|
15411
|
+
)
|
|
15412
|
+
}).describe("Actor options for timeouts and behavior configuration.");
|
|
15413
|
+
var DocActorConfigSchema = external_exports.object({
|
|
15414
|
+
state: external_exports.unknown().optional().describe(
|
|
15415
|
+
"Initial state value for the actor. Cannot be used with createState."
|
|
15416
|
+
),
|
|
15417
|
+
createState: external_exports.unknown().optional().describe(
|
|
15418
|
+
"Function to create initial state. Receives context and input. Cannot be used with state."
|
|
15419
|
+
),
|
|
15420
|
+
connState: external_exports.unknown().optional().describe(
|
|
15421
|
+
"Initial connection state value. Cannot be used with createConnState."
|
|
15422
|
+
),
|
|
15423
|
+
createConnState: external_exports.unknown().optional().describe(
|
|
15424
|
+
"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."
|
|
15425
|
+
),
|
|
15426
|
+
vars: external_exports.unknown().optional().describe(
|
|
15427
|
+
"Initial ephemeral variables value. Cannot be used with createVars."
|
|
15428
|
+
),
|
|
15429
|
+
createVars: external_exports.unknown().optional().describe(
|
|
15430
|
+
"Function to create ephemeral variables. Receives context and driver context. Cannot be used with vars."
|
|
15431
|
+
),
|
|
15432
|
+
db: external_exports.unknown().optional().describe("Database provider instance for the actor."),
|
|
15433
|
+
onCreate: external_exports.unknown().optional().describe(
|
|
15434
|
+
"Called when the actor is first initialized. Use to initialize state."
|
|
15435
|
+
),
|
|
15436
|
+
onDestroy: external_exports.unknown().optional().describe("Called when the actor is destroyed."),
|
|
15437
|
+
onMigrate: external_exports.unknown().optional().describe(
|
|
15438
|
+
"Called on every actor start after persisted state loads and before onWake. Use for repeatable schema migrations."
|
|
15439
|
+
),
|
|
15440
|
+
onWake: external_exports.unknown().optional().describe(
|
|
15441
|
+
"Called when the actor wakes up and is ready to receive connections and actions."
|
|
15442
|
+
),
|
|
15443
|
+
onSleep: external_exports.unknown().optional().describe(
|
|
15444
|
+
"Called when the actor is stopping or sleeping. Use to clean up resources."
|
|
15445
|
+
),
|
|
15446
|
+
run: external_exports.unknown().optional().describe(
|
|
15447
|
+
"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."
|
|
15448
|
+
),
|
|
15449
|
+
onStateChange: external_exports.unknown().optional().describe(
|
|
15450
|
+
"Called when the actor's state changes. State changes within this hook won't trigger recursion."
|
|
15451
|
+
),
|
|
15452
|
+
onBeforeConnect: external_exports.unknown().optional().describe(
|
|
15453
|
+
"Called before a client connects. Throw an error to reject the connection. The pending connection is not visible in c.conns while this runs."
|
|
15454
|
+
),
|
|
15455
|
+
onConnect: external_exports.unknown().optional().describe(
|
|
15456
|
+
"Called when a client successfully connects. The connection is visible in c.conns before this runs."
|
|
15457
|
+
),
|
|
15458
|
+
onDisconnect: external_exports.unknown().optional().describe("Called when a client disconnects."),
|
|
15459
|
+
onBeforeActionResponse: external_exports.unknown().optional().describe(
|
|
15460
|
+
"Called before sending an action response. Use to transform output."
|
|
15461
|
+
),
|
|
15462
|
+
onRequest: external_exports.unknown().optional().describe(
|
|
15463
|
+
"Called for raw HTTP requests to /actors/{name}/http/* endpoints."
|
|
15464
|
+
),
|
|
15465
|
+
onWebSocket: external_exports.unknown().optional().describe(
|
|
15466
|
+
"Called for raw WebSocket connections to /actors/{name}/websocket/* endpoints."
|
|
15467
|
+
),
|
|
15468
|
+
actions: external_exports.record(external_exports.string(), external_exports.unknown()).optional().describe(
|
|
15469
|
+
"Tree of action names or nested groups to handler functions. Nested paths use dot-separated low-level action names. Defaults to an empty object."
|
|
15470
|
+
),
|
|
15471
|
+
actionInputSchemas: external_exports.record(external_exports.string(), external_exports.unknown()).optional().describe(
|
|
15472
|
+
"Optional schemas for validating action argument tuples in native runtimes. May mirror nested action groups or use dot-separated low-level action names."
|
|
15473
|
+
),
|
|
15474
|
+
tracing: external_exports.unknown().optional().describe(
|
|
15475
|
+
"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."
|
|
15476
|
+
),
|
|
15477
|
+
connParamsSchema: external_exports.unknown().optional().describe(
|
|
15478
|
+
"Optional schema for validating connection params in native runtimes."
|
|
15479
|
+
),
|
|
15480
|
+
events: external_exports.record(external_exports.string(), external_exports.unknown()).optional().describe("Map of event names to schemas."),
|
|
15481
|
+
queues: external_exports.record(external_exports.string(), external_exports.unknown()).optional().describe("Map of queue names to schemas."),
|
|
15482
|
+
options: DocActorOptionsSchema.optional()
|
|
15483
|
+
}).describe("Actor configuration passed to the actor() function.");
|
|
15471
15484
|
|
|
15472
15485
|
// ../rivetkit/dist/tsup/chunk-JI6GZ2C2.js
|
|
15473
15486
|
var EMPTY_KEY = "/";
|
|
@@ -15586,44 +15599,6 @@ function removePrefixFromKey(prefixedKey) {
|
|
|
15586
15599
|
return prefixedKey.slice(KEYS.KV.length);
|
|
15587
15600
|
}
|
|
15588
15601
|
|
|
15589
|
-
// ../rivetkit/dist/tsup/chunk-553CIQJY.js
|
|
15590
|
-
function logger() {
|
|
15591
|
-
return getLogger("actor-client");
|
|
15592
|
-
}
|
|
15593
|
-
var webSocketPromise = null;
|
|
15594
|
-
async function importWebSocket() {
|
|
15595
|
-
if (webSocketPromise !== null) {
|
|
15596
|
-
return webSocketPromise;
|
|
15597
|
-
}
|
|
15598
|
-
webSocketPromise = (async () => {
|
|
15599
|
-
let _WebSocket;
|
|
15600
|
-
if (typeof WebSocket !== "undefined") {
|
|
15601
|
-
_WebSocket = WebSocket;
|
|
15602
|
-
} else {
|
|
15603
|
-
try {
|
|
15604
|
-
const moduleName = "ws";
|
|
15605
|
-
const ws = await import(
|
|
15606
|
-
/* webpackIgnore: true */
|
|
15607
|
-
moduleName
|
|
15608
|
-
);
|
|
15609
|
-
_WebSocket = ws.default;
|
|
15610
|
-
logger().debug("using websocket from npm");
|
|
15611
|
-
} catch {
|
|
15612
|
-
_WebSocket = class MockWebSocket {
|
|
15613
|
-
constructor() {
|
|
15614
|
-
throw new Error(
|
|
15615
|
-
'WebSocket support requires installing the "ws" peer dependency.'
|
|
15616
|
-
);
|
|
15617
|
-
}
|
|
15618
|
-
};
|
|
15619
|
-
logger().debug("using mock websocket");
|
|
15620
|
-
}
|
|
15621
|
-
}
|
|
15622
|
-
return _WebSocket;
|
|
15623
|
-
})();
|
|
15624
|
-
return webSocketPromise;
|
|
15625
|
-
}
|
|
15626
|
-
|
|
15627
15602
|
// ../rivetkit/dist/tsup/chunk-JTHHCZCZ.js
|
|
15628
15603
|
var MIGRATION_TRANSACTION_TIMEOUT_MS = 5 * 6e4;
|
|
15629
15604
|
function isManualTransactionControl(query) {
|
|
@@ -15707,7 +15682,45 @@ var AsyncMutex = class {
|
|
|
15707
15682
|
}
|
|
15708
15683
|
};
|
|
15709
15684
|
|
|
15710
|
-
// ../rivetkit/dist/tsup/chunk-
|
|
15685
|
+
// ../rivetkit/dist/tsup/chunk-47FSGXYN.js
|
|
15686
|
+
function logger() {
|
|
15687
|
+
return getLogger("actor-client");
|
|
15688
|
+
}
|
|
15689
|
+
var webSocketPromise = null;
|
|
15690
|
+
async function importWebSocket() {
|
|
15691
|
+
if (webSocketPromise !== null) {
|
|
15692
|
+
return webSocketPromise;
|
|
15693
|
+
}
|
|
15694
|
+
webSocketPromise = (async () => {
|
|
15695
|
+
let _WebSocket;
|
|
15696
|
+
if (typeof WebSocket !== "undefined") {
|
|
15697
|
+
_WebSocket = WebSocket;
|
|
15698
|
+
} else {
|
|
15699
|
+
try {
|
|
15700
|
+
const moduleName = "ws";
|
|
15701
|
+
const ws = await import(
|
|
15702
|
+
/* webpackIgnore: true */
|
|
15703
|
+
moduleName
|
|
15704
|
+
);
|
|
15705
|
+
_WebSocket = ws.default;
|
|
15706
|
+
logger().debug("using websocket from npm");
|
|
15707
|
+
} catch {
|
|
15708
|
+
_WebSocket = class MockWebSocket {
|
|
15709
|
+
constructor() {
|
|
15710
|
+
throw new Error(
|
|
15711
|
+
'WebSocket support requires installing the "ws" peer dependency.'
|
|
15712
|
+
);
|
|
15713
|
+
}
|
|
15714
|
+
};
|
|
15715
|
+
logger().debug("using mock websocket");
|
|
15716
|
+
}
|
|
15717
|
+
}
|
|
15718
|
+
return _WebSocket;
|
|
15719
|
+
})();
|
|
15720
|
+
return webSocketPromise;
|
|
15721
|
+
}
|
|
15722
|
+
|
|
15723
|
+
// ../rivetkit/dist/tsup/chunk-VD47X7KQ.js
|
|
15711
15724
|
var import_invariant2 = __toESM(require_invariant(), 1);
|
|
15712
15725
|
|
|
15713
15726
|
// ../../../node_modules/.pnpm/p-retry@6.2.1/node_modules/p-retry/index.js
|
|
@@ -16922,7 +16935,7 @@ var TraceAPI = (
|
|
|
16922
16935
|
// ../../../node_modules/.pnpm/@opentelemetry+api@1.9.0/node_modules/@opentelemetry/api/build/esm/trace-api.js
|
|
16923
16936
|
var trace = TraceAPI.getInstance();
|
|
16924
16937
|
|
|
16925
|
-
// ../rivetkit/dist/tsup/chunk-
|
|
16938
|
+
// ../rivetkit/dist/tsup/chunk-VD47X7KQ.js
|
|
16926
16939
|
var import_invariant3 = __toESM(require_invariant(), 1);
|
|
16927
16940
|
var import_invariant4 = __toESM(require_invariant(), 1);
|
|
16928
16941
|
var PATH_CONNECT = "/connect";
|
|
@@ -19396,7 +19409,8 @@ async function sendHttpRequest(opts) {
|
|
|
19396
19409
|
{
|
|
19397
19410
|
metadata: responseData.metadata,
|
|
19398
19411
|
rayId: rayId ?? void 0,
|
|
19399
|
-
actor: responseData.actor
|
|
19412
|
+
actor: responseData.actor,
|
|
19413
|
+
statusCode: response.status
|
|
19400
19414
|
}
|
|
19401
19415
|
);
|
|
19402
19416
|
} catch (error46) {
|
|
@@ -20304,6 +20318,22 @@ var ActorHandleRaw = class {
|
|
|
20304
20318
|
"dynamic actor resolution did not produce a direct actor id"
|
|
20305
20319
|
);
|
|
20306
20320
|
}
|
|
20321
|
+
/** Issue a token scoped to this actor. Defaults to actor gateway read access. */
|
|
20322
|
+
async issueToken(options = {}) {
|
|
20323
|
+
const actorId = await this.resolve();
|
|
20324
|
+
const permissions = options.permissions ?? {
|
|
20325
|
+
actor_gateway: ["read"]
|
|
20326
|
+
};
|
|
20327
|
+
const grants = Object.keys(permissions).flatMap((resource) => {
|
|
20328
|
+
const operations = permissions[resource];
|
|
20329
|
+
return operations ? [{ resource, target: { id: actorId }, operations }] : [];
|
|
20330
|
+
});
|
|
20331
|
+
return this.#driver.issueToken({
|
|
20332
|
+
subject: options.subject,
|
|
20333
|
+
expiresIn: options.expiresIn,
|
|
20334
|
+
grants
|
|
20335
|
+
});
|
|
20336
|
+
}
|
|
20307
20337
|
/**
|
|
20308
20338
|
* Returns the raw URL for routing traffic to the actor.
|
|
20309
20339
|
*/
|
|
@@ -20336,6 +20366,8 @@ var ACTOR_CONNS_SYMBOL = /* @__PURE__ */ Symbol("actorConns");
|
|
|
20336
20366
|
var CREATE_ACTOR_CONN_PROXY = /* @__PURE__ */ Symbol("createActorConnProxy");
|
|
20337
20367
|
var ClientRaw = class {
|
|
20338
20368
|
#disposed = false;
|
|
20369
|
+
/** Issue namespace-scoped tokens with an explicit grant list. */
|
|
20370
|
+
auth;
|
|
20339
20371
|
[ACTOR_CONNS_SYMBOL] = /* @__PURE__ */ new Set();
|
|
20340
20372
|
#driver;
|
|
20341
20373
|
#encodingKind;
|
|
@@ -20347,6 +20379,9 @@ var ClientRaw = class {
|
|
|
20347
20379
|
*/
|
|
20348
20380
|
constructor(driver, options = {}) {
|
|
20349
20381
|
this.#driver = driver;
|
|
20382
|
+
this.auth = {
|
|
20383
|
+
issueToken: (issueOptions) => this.#driver.issueToken(issueOptions)
|
|
20384
|
+
};
|
|
20350
20385
|
this.#encodingKind = options.encoding ?? "bare";
|
|
20351
20386
|
this.#gatewayOptions = options.gateway ?? {};
|
|
20352
20387
|
this.#currentActorInvocation = options.currentActorInvocation;
|
|
@@ -20638,6 +20673,72 @@ function createActorProxy(handle) {
|
|
|
20638
20673
|
}
|
|
20639
20674
|
});
|
|
20640
20675
|
}
|
|
20676
|
+
function isInvalidToken(group, code) {
|
|
20677
|
+
return group === "auth" && (code === "invalid_token" || code === "token_expired");
|
|
20678
|
+
}
|
|
20679
|
+
function isInvalidTokenResponse(response) {
|
|
20680
|
+
if (response.status !== 401) return false;
|
|
20681
|
+
const error46 = response.headers.get("x-rivet-error");
|
|
20682
|
+
if (!error46) return false;
|
|
20683
|
+
const separator = error46.indexOf(".");
|
|
20684
|
+
return separator > 0 && isInvalidToken(error46.slice(0, separator), error46.slice(separator + 1));
|
|
20685
|
+
}
|
|
20686
|
+
var TokenProvider = class {
|
|
20687
|
+
constructor(getToken) {
|
|
20688
|
+
this.getToken = getToken;
|
|
20689
|
+
}
|
|
20690
|
+
#cached;
|
|
20691
|
+
#pending;
|
|
20692
|
+
#pendingForce = false;
|
|
20693
|
+
async current() {
|
|
20694
|
+
if (this.#cached && (this.#cached.expiresAt === void 0 || Date.now() < this.#cached.expiresAt - 5e3)) {
|
|
20695
|
+
return this.#cached.token;
|
|
20696
|
+
}
|
|
20697
|
+
return this.#load(false);
|
|
20698
|
+
}
|
|
20699
|
+
/** A late rejection for an older token must never erase a newer credential. */
|
|
20700
|
+
async refreshIfCurrent(failedToken) {
|
|
20701
|
+
var _a2;
|
|
20702
|
+
if (this.#pending !== void 0) {
|
|
20703
|
+
const wasForced = this.#pendingForce;
|
|
20704
|
+
const refreshed = await this.#pending;
|
|
20705
|
+
if (wasForced || refreshed !== failedToken) return refreshed;
|
|
20706
|
+
}
|
|
20707
|
+
if (((_a2 = this.#cached) == null ? void 0 : _a2.token) !== failedToken) {
|
|
20708
|
+
return this.current();
|
|
20709
|
+
}
|
|
20710
|
+
return this.#load(true);
|
|
20711
|
+
}
|
|
20712
|
+
#load(forceRefresh) {
|
|
20713
|
+
if (this.#pending !== void 0) return this.#pending;
|
|
20714
|
+
const pending = Promise.resolve().then(() => this.getToken({ forceRefresh })).then((token) => {
|
|
20715
|
+
if (typeof token !== "string" || token.length === 0) {
|
|
20716
|
+
throw new Error(
|
|
20717
|
+
"getToken must resolve to a nonempty string"
|
|
20718
|
+
);
|
|
20719
|
+
}
|
|
20720
|
+
this.#cached = { token, expiresAt: jwtExpiration(token) };
|
|
20721
|
+
return token;
|
|
20722
|
+
}).finally(() => {
|
|
20723
|
+
if (this.#pending === pending) this.#pending = void 0;
|
|
20724
|
+
});
|
|
20725
|
+
this.#pending = pending;
|
|
20726
|
+
this.#pendingForce = forceRefresh;
|
|
20727
|
+
return pending;
|
|
20728
|
+
}
|
|
20729
|
+
};
|
|
20730
|
+
function jwtExpiration(token) {
|
|
20731
|
+
try {
|
|
20732
|
+
const payload = token.split(".")[1];
|
|
20733
|
+
if (!payload) return void 0;
|
|
20734
|
+
const claims = JSON.parse(
|
|
20735
|
+
atob(payload.replace(/-/g, "+").replace(/_/g, "/"))
|
|
20736
|
+
);
|
|
20737
|
+
return typeof claims.exp === "number" && Number.isSafeInteger(claims.exp) ? claims.exp * 1e3 : void 0;
|
|
20738
|
+
} catch {
|
|
20739
|
+
return void 0;
|
|
20740
|
+
}
|
|
20741
|
+
}
|
|
20641
20742
|
var CONNECT_SYMBOL = /* @__PURE__ */ Symbol("connect");
|
|
20642
20743
|
var ActorConnRaw = class {
|
|
20643
20744
|
#disposed = false;
|
|
@@ -20666,6 +20767,7 @@ var ActorConnRaw = class {
|
|
|
20666
20767
|
/** Promise used to indicate the socket has connected successfully. This will be rejected if the connection fails. */
|
|
20667
20768
|
#onOpenPromise;
|
|
20668
20769
|
#websocket;
|
|
20770
|
+
#authRetryAvailable = true;
|
|
20669
20771
|
#client;
|
|
20670
20772
|
#driver;
|
|
20671
20773
|
#currentActorInvocation;
|
|
@@ -20911,6 +21013,10 @@ var ActorConnRaw = class {
|
|
|
20911
21013
|
if (error46 instanceof ActorConnDisposed) {
|
|
20912
21014
|
return false;
|
|
20913
21015
|
}
|
|
21016
|
+
if (error46 instanceof RivetError && isInvalidToken(error46.group, error46.code) && this.#driver.refreshAuthToken && this.#authRetryAvailable) {
|
|
21017
|
+
this.#authRetryAvailable = false;
|
|
21018
|
+
return true;
|
|
21019
|
+
}
|
|
20914
21020
|
if (error46 instanceof RivetError && this.#shouldReconnectForStaleActor(error46.group, error46.code)) {
|
|
20915
21021
|
return true;
|
|
20916
21022
|
}
|
|
@@ -21035,6 +21141,7 @@ var ActorConnRaw = class {
|
|
|
21035
21141
|
messageQueueLength: this.#messageQueue.length,
|
|
21036
21142
|
connId: this.#connId
|
|
21037
21143
|
});
|
|
21144
|
+
this.#authRetryAvailable = true;
|
|
21038
21145
|
this.#setConnStatus("connected");
|
|
21039
21146
|
if (this.#onOpenPromise) {
|
|
21040
21147
|
this.#onOpenPromise.resolve(void 0);
|
|
@@ -21177,7 +21284,8 @@ var ActorConnRaw = class {
|
|
|
21177
21284
|
}
|
|
21178
21285
|
/** Called by the onclose event from drivers. */
|
|
21179
21286
|
async #handleOnClose(event2) {
|
|
21180
|
-
var _a2;
|
|
21287
|
+
var _a2, _b, _c;
|
|
21288
|
+
const failedSocket = this.#websocket;
|
|
21181
21289
|
const closeEvent = event2;
|
|
21182
21290
|
const wasClean = closeEvent.wasClean;
|
|
21183
21291
|
const wasConnected = this.#connStatus === "connected";
|
|
@@ -21199,9 +21307,24 @@ var ActorConnRaw = class {
|
|
|
21199
21307
|
const parsed = parseWebSocketCloseReason(reason);
|
|
21200
21308
|
if (parsed) {
|
|
21201
21309
|
const { group, code, rayId } = parsed;
|
|
21310
|
+
if (isInvalidToken(group, code) && closeEvent.code === 1008 && failedSocket) {
|
|
21311
|
+
try {
|
|
21312
|
+
if (!await ((_b = (_a2 = this.#driver).refreshAuthToken) == null ? void 0 : _b.call(
|
|
21313
|
+
_a2,
|
|
21314
|
+
failedSocket
|
|
21315
|
+
))) {
|
|
21316
|
+
this.#authRetryAvailable = false;
|
|
21317
|
+
}
|
|
21318
|
+
} catch {
|
|
21319
|
+
logger().warn("token renewal failed");
|
|
21320
|
+
this.#authRetryAvailable = false;
|
|
21321
|
+
}
|
|
21322
|
+
} else if (isInvalidToken(group, code)) {
|
|
21323
|
+
this.#authRetryAvailable = false;
|
|
21324
|
+
}
|
|
21202
21325
|
if (this.#shouldReconnectForStaleActor(group, code)) {
|
|
21203
21326
|
this.#clearResolvedActorIdentity();
|
|
21204
|
-
(
|
|
21327
|
+
(_c = this.#onOpenPromise) == null ? void 0 : _c.reject(
|
|
21205
21328
|
new RivetError(
|
|
21206
21329
|
group,
|
|
21207
21330
|
code,
|
|
@@ -21248,7 +21371,7 @@ var ActorConnRaw = class {
|
|
|
21248
21371
|
if (error46 instanceof RivetError) {
|
|
21249
21372
|
this.#dispatchActorError(error46);
|
|
21250
21373
|
}
|
|
21251
|
-
if (wasConnected) {
|
|
21374
|
+
if (wasConnected && this.#authRetryAvailable) {
|
|
21252
21375
|
logger().debug({
|
|
21253
21376
|
msg: "triggering reconnect",
|
|
21254
21377
|
connId: this.#connId
|
|
@@ -21717,6 +21840,23 @@ var ActorConnRaw = class {
|
|
|
21717
21840
|
);
|
|
21718
21841
|
}
|
|
21719
21842
|
};
|
|
21843
|
+
var ENGINE_HOST = "127.0.0.1";
|
|
21844
|
+
var ENGINE_PORT = 6420;
|
|
21845
|
+
var ENGINE_ENDPOINT = buildEngineEndpoint(ENGINE_HOST, ENGINE_PORT);
|
|
21846
|
+
function buildEngineEndpoint(host, port) {
|
|
21847
|
+
const urlHost = host.includes(":") && !host.startsWith("[") ? `[${host}]` : host;
|
|
21848
|
+
return `http://${urlHost}:${port}`;
|
|
21849
|
+
}
|
|
21850
|
+
function isLocalEngineEndpoint(endpoint) {
|
|
21851
|
+
let url2;
|
|
21852
|
+
try {
|
|
21853
|
+
url2 = new URL(endpoint);
|
|
21854
|
+
} catch {
|
|
21855
|
+
return false;
|
|
21856
|
+
}
|
|
21857
|
+
const hostname3 = url2.hostname.toLowerCase();
|
|
21858
|
+
return hostname3 === "localhost" || hostname3 === "0.0.0.0" || hostname3 === "::" || hostname3 === "[::]" || hostname3 === "::1" || hostname3 === "[::1]" || /^127(?:\.\d{1,3}){0,3}$/.test(hostname3);
|
|
21859
|
+
}
|
|
21720
21860
|
function tryParseEndpoint(ctx, options) {
|
|
21721
21861
|
const {
|
|
21722
21862
|
endpoint,
|
|
@@ -21811,6 +21951,8 @@ var ClientConfigSchemaBase = v4_default.object({
|
|
|
21811
21951
|
}),
|
|
21812
21952
|
/** Token to use to authenticate with the API. */
|
|
21813
21953
|
token: v4_default.string().optional().transform((val) => val ?? getRivetToken()),
|
|
21954
|
+
/** Issue and renew a client token on demand. Overrides the static token when provided. */
|
|
21955
|
+
getToken: v4_default.custom().optional(),
|
|
21814
21956
|
/** Namespace to connect to. */
|
|
21815
21957
|
namespace: v4_default.string().optional().transform((val) => val ?? getRivetNamespace()),
|
|
21816
21958
|
/** Name of the envoy pool. This is used to group together envoys in to different pools. */
|
|
@@ -21855,7 +21997,7 @@ function transformClientConfig(config3, ctx) {
|
|
|
21855
21997
|
...config3,
|
|
21856
21998
|
endpoint: parsedEndpoint == null ? void 0 : parsedEndpoint.endpoint,
|
|
21857
21999
|
namespace: (parsedEndpoint == null ? void 0 : parsedEndpoint.namespace) ?? config3.namespace ?? "default",
|
|
21858
|
-
token: (parsedEndpoint == null ? void 0 : parsedEndpoint.token) ?? config3.token
|
|
22000
|
+
token: (parsedEndpoint == null ? void 0 : parsedEndpoint.token) ?? config3.token ?? (config3.endpoint && isLocalEngineEndpoint(config3.endpoint) ? "default" : void 0)
|
|
21859
22001
|
};
|
|
21860
22002
|
}
|
|
21861
22003
|
function convertRegistryConfigToClientConfig(config3) {
|
|
@@ -21863,6 +22005,7 @@ function convertRegistryConfigToClientConfig(config3) {
|
|
|
21863
22005
|
return {
|
|
21864
22006
|
endpoint: config3.endpoint,
|
|
21865
22007
|
token: config3.token,
|
|
22008
|
+
getToken: void 0,
|
|
21866
22009
|
namespace: config3.namespace,
|
|
21867
22010
|
poolName: config3.envoy.poolName,
|
|
21868
22011
|
headers: config3.headers,
|
|
@@ -22194,7 +22337,8 @@ async function openWebSocketToGateway(runConfig, gatewayUrl, encoding, params, o
|
|
|
22194
22337
|
const ackHookToken = typeof process !== "undefined" && process.env.VITEST ? crypto.randomUUID() : void 0;
|
|
22195
22338
|
logger2().debug({
|
|
22196
22339
|
msg: "opening websocket to actor via guard",
|
|
22197
|
-
|
|
22340
|
+
// Gateway URLs can embed credentials; never include the path or query in logs.
|
|
22341
|
+
origin: new URL(gatewayUrl).origin
|
|
22198
22342
|
});
|
|
22199
22343
|
const ws = new WebSocket2(
|
|
22200
22344
|
gatewayUrl,
|
|
@@ -22284,6 +22428,14 @@ async function apiCall(config3, method2, path2, body) {
|
|
|
22284
22428
|
responseFromBare: (value) => value
|
|
22285
22429
|
});
|
|
22286
22430
|
}
|
|
22431
|
+
async function issueToken(config3, options) {
|
|
22432
|
+
return apiCall(config3, "POST", "/auth/tokens", {
|
|
22433
|
+
namespace: config3.namespace,
|
|
22434
|
+
subject: options.subject,
|
|
22435
|
+
duration: options.expiresIn,
|
|
22436
|
+
grants: options.grants
|
|
22437
|
+
});
|
|
22438
|
+
}
|
|
22287
22439
|
async function getActor(config3, _, actorId) {
|
|
22288
22440
|
return apiCall(
|
|
22289
22441
|
config3,
|
|
@@ -22525,6 +22677,8 @@ function closeWebSocketIfOpen(ws, code, reason) {
|
|
|
22525
22677
|
var RemoteEngineControlClient = class {
|
|
22526
22678
|
#config;
|
|
22527
22679
|
#metadataPromise;
|
|
22680
|
+
#tokenProvider;
|
|
22681
|
+
#webSocketTokens = /* @__PURE__ */ new WeakMap();
|
|
22528
22682
|
constructor(runConfig) {
|
|
22529
22683
|
if (getNextPhase() === "phase-production-build") {
|
|
22530
22684
|
logger2().info(
|
|
@@ -22533,6 +22687,8 @@ var RemoteEngineControlClient = class {
|
|
|
22533
22687
|
runConfig.disableMetadataLookup = true;
|
|
22534
22688
|
}
|
|
22535
22689
|
this.#config = { ...runConfig };
|
|
22690
|
+
if (runConfig.getToken)
|
|
22691
|
+
this.#tokenProvider = new TokenProvider(runConfig.getToken);
|
|
22536
22692
|
if (!runConfig.disableMetadataLookup) {
|
|
22537
22693
|
this.#metadataPromise = lookupMetadataCached(this.#config).then(
|
|
22538
22694
|
(metadataData) => {
|
|
@@ -22541,14 +22697,13 @@ var RemoteEngineControlClient = class {
|
|
|
22541
22697
|
if (metadataData.clientNamespace) {
|
|
22542
22698
|
this.#config.namespace = metadataData.clientNamespace;
|
|
22543
22699
|
}
|
|
22544
|
-
if (metadataData.clientToken) {
|
|
22700
|
+
if (metadataData.clientToken && !this.#tokenProvider) {
|
|
22545
22701
|
this.#config.token = metadataData.clientToken;
|
|
22546
22702
|
}
|
|
22547
22703
|
logger2().info({
|
|
22548
22704
|
msg: "overriding client endpoint",
|
|
22549
22705
|
endpoint: metadataData.clientEndpoint,
|
|
22550
|
-
namespace: metadataData.clientNamespace
|
|
22551
|
-
token: metadataData.clientToken
|
|
22706
|
+
namespace: metadataData.clientNamespace
|
|
22552
22707
|
});
|
|
22553
22708
|
}
|
|
22554
22709
|
logger2().info({
|
|
@@ -22561,12 +22716,47 @@ var RemoteEngineControlClient = class {
|
|
|
22561
22716
|
);
|
|
22562
22717
|
}
|
|
22563
22718
|
}
|
|
22719
|
+
async #authorizedConfig() {
|
|
22720
|
+
if (!this.#tokenProvider) return this.#config;
|
|
22721
|
+
return { ...this.#config, token: await this.#tokenProvider.current() };
|
|
22722
|
+
}
|
|
22723
|
+
async #withCredential(request, readOnly = false) {
|
|
22724
|
+
const config3 = await this.#authorizedConfig();
|
|
22725
|
+
try {
|
|
22726
|
+
return await request(config3);
|
|
22727
|
+
} catch (error46) {
|
|
22728
|
+
if (this.#tokenProvider && config3.token && error46 instanceof RivetError && error46.statusCode === 401 && isInvalidToken(error46.group, error46.code)) {
|
|
22729
|
+
if (readOnly) {
|
|
22730
|
+
const token = await this.#tokenProvider.refreshIfCurrent(
|
|
22731
|
+
config3.token
|
|
22732
|
+
);
|
|
22733
|
+
return request({ ...this.#config, token });
|
|
22734
|
+
}
|
|
22735
|
+
await this.#tokenProvider.refreshIfCurrent(config3.token);
|
|
22736
|
+
}
|
|
22737
|
+
throw error46;
|
|
22738
|
+
}
|
|
22739
|
+
}
|
|
22740
|
+
async issueToken(options) {
|
|
22741
|
+
await this.#metadataPromise;
|
|
22742
|
+
const response = await this.#withCredential(
|
|
22743
|
+
(config3) => issueToken(config3, options)
|
|
22744
|
+
);
|
|
22745
|
+
return {
|
|
22746
|
+
token: response.token,
|
|
22747
|
+
issuedAt: response.issued_ts,
|
|
22748
|
+
expiresAt: response.expires_ts
|
|
22749
|
+
};
|
|
22750
|
+
}
|
|
22564
22751
|
async getForId({
|
|
22565
22752
|
name,
|
|
22566
22753
|
actorId
|
|
22567
22754
|
}) {
|
|
22568
22755
|
await this.#metadataPromise;
|
|
22569
|
-
const response = await
|
|
22756
|
+
const response = await this.#withCredential(
|
|
22757
|
+
(config3) => getActor(config3, name, actorId),
|
|
22758
|
+
true
|
|
22759
|
+
);
|
|
22570
22760
|
const actor2 = response.actors[0];
|
|
22571
22761
|
if (!actor2) return void 0;
|
|
22572
22762
|
if (actor2.name !== name) {
|
|
@@ -22587,7 +22777,10 @@ var RemoteEngineControlClient = class {
|
|
|
22587
22777
|
await this.#metadataPromise;
|
|
22588
22778
|
logger2().debug({ msg: "getWithKey: searching for actor", name, key });
|
|
22589
22779
|
try {
|
|
22590
|
-
const response = await
|
|
22780
|
+
const response = await this.#withCredential(
|
|
22781
|
+
(config3) => getActorByKey(config3, name, key),
|
|
22782
|
+
true
|
|
22783
|
+
);
|
|
22591
22784
|
const actor2 = response.actors[0];
|
|
22592
22785
|
if (!actor2) return void 0;
|
|
22593
22786
|
logger2().debug({
|
|
@@ -22620,16 +22813,18 @@ var RemoteEngineControlClient = class {
|
|
|
22620
22813
|
key
|
|
22621
22814
|
});
|
|
22622
22815
|
try {
|
|
22623
|
-
const { actor: actor2, created } = await
|
|
22624
|
-
|
|
22625
|
-
|
|
22626
|
-
|
|
22627
|
-
|
|
22628
|
-
|
|
22629
|
-
|
|
22630
|
-
|
|
22631
|
-
|
|
22632
|
-
|
|
22816
|
+
const { actor: actor2, created } = await this.#withCredential(
|
|
22817
|
+
(config3) => getOrCreateActor(config3, {
|
|
22818
|
+
datacenter: region,
|
|
22819
|
+
name,
|
|
22820
|
+
key: serializeActorKey(key),
|
|
22821
|
+
runner_name_selector: poolName ?? this.#config.poolName,
|
|
22822
|
+
input: actorInput ? uint8ArrayToBase642(
|
|
22823
|
+
encodeCborCompat(actorInput)
|
|
22824
|
+
) : void 0,
|
|
22825
|
+
crash_policy: crashPolicy ?? "sleep"
|
|
22826
|
+
})
|
|
22827
|
+
);
|
|
22633
22828
|
logger2().info({
|
|
22634
22829
|
msg: "getOrCreateWithKey: actor ready",
|
|
22635
22830
|
actorId: actor2.actor_id,
|
|
@@ -22645,7 +22840,10 @@ var RemoteEngineControlClient = class {
|
|
|
22645
22840
|
name,
|
|
22646
22841
|
key
|
|
22647
22842
|
});
|
|
22648
|
-
const response = await
|
|
22843
|
+
const response = await this.#withCredential(
|
|
22844
|
+
(config3) => getActorByKey(config3, name, key),
|
|
22845
|
+
true
|
|
22846
|
+
);
|
|
22649
22847
|
const existing = response.actors[0];
|
|
22650
22848
|
if (!existing) throw error46;
|
|
22651
22849
|
logger2().info({
|
|
@@ -22669,14 +22867,18 @@ var RemoteEngineControlClient = class {
|
|
|
22669
22867
|
}) {
|
|
22670
22868
|
await this.#metadataPromise;
|
|
22671
22869
|
logger2().info({ msg: "creating actor via engine api", name, key });
|
|
22672
|
-
const result = await
|
|
22673
|
-
|
|
22674
|
-
|
|
22675
|
-
|
|
22676
|
-
|
|
22677
|
-
|
|
22678
|
-
|
|
22679
|
-
|
|
22870
|
+
const result = await this.#withCredential(
|
|
22871
|
+
(config3) => createActor(config3, {
|
|
22872
|
+
datacenter: region,
|
|
22873
|
+
name,
|
|
22874
|
+
runner_name_selector: poolName ?? this.#config.poolName,
|
|
22875
|
+
key: serializeActorKey(key),
|
|
22876
|
+
input: input ? uint8ArrayToBase642(
|
|
22877
|
+
encodeCborCompat(input)
|
|
22878
|
+
) : void 0,
|
|
22879
|
+
crash_policy: crashPolicy ?? "sleep"
|
|
22880
|
+
})
|
|
22881
|
+
);
|
|
22680
22882
|
logger2().info({
|
|
22681
22883
|
msg: "actor created",
|
|
22682
22884
|
actorId: result.actor.actor_id,
|
|
@@ -22688,43 +22890,61 @@ var RemoteEngineControlClient = class {
|
|
|
22688
22890
|
async listActors({ name }) {
|
|
22689
22891
|
await this.#metadataPromise;
|
|
22690
22892
|
logger2().debug({ msg: "listing actors via engine api", name });
|
|
22691
|
-
const response = await
|
|
22893
|
+
const response = await this.#withCredential(
|
|
22894
|
+
(config3) => listActorsByName(config3, name),
|
|
22895
|
+
true
|
|
22896
|
+
);
|
|
22692
22897
|
return response.actors.map(apiActorToOutput);
|
|
22693
22898
|
}
|
|
22694
22899
|
async destroyActor(actorId) {
|
|
22695
22900
|
await this.#metadataPromise;
|
|
22696
22901
|
logger2().info({ msg: "destroying actor via engine api", actorId });
|
|
22697
|
-
await destroyActor(
|
|
22902
|
+
await this.#withCredential((config3) => destroyActor(config3, actorId));
|
|
22698
22903
|
logger2().info({ msg: "actor destroyed", actorId });
|
|
22699
22904
|
}
|
|
22700
22905
|
async sendRequest(target, actorRequest, options = {}) {
|
|
22906
|
+
var _a2;
|
|
22701
22907
|
await this.#metadataPromise;
|
|
22702
|
-
const
|
|
22703
|
-
const gatewayUrl = this.#buildGatewayUrlForTarget(
|
|
22704
|
-
target,
|
|
22705
|
-
path2,
|
|
22706
|
-
options
|
|
22707
|
-
);
|
|
22908
|
+
const config3 = await this.#authorizedConfig();
|
|
22708
22909
|
const httpOptions = {
|
|
22709
22910
|
...options,
|
|
22710
22911
|
directActorId: shouldSkipReadyWait(options) ? directActorIdFromTarget(target) : void 0
|
|
22711
22912
|
};
|
|
22712
|
-
|
|
22713
|
-
|
|
22714
|
-
|
|
22913
|
+
const send = (current) => sendHttpRequestToGateway(
|
|
22914
|
+
current,
|
|
22915
|
+
this.#buildGatewayUrlForTarget(
|
|
22916
|
+
current,
|
|
22917
|
+
target,
|
|
22918
|
+
requestPath(actorRequest),
|
|
22919
|
+
options
|
|
22920
|
+
),
|
|
22715
22921
|
actorRequest,
|
|
22716
22922
|
httpOptions
|
|
22717
22923
|
);
|
|
22924
|
+
const response = await send(config3);
|
|
22925
|
+
if (!this.#tokenProvider || !config3.token || !isInvalidTokenResponse(response))
|
|
22926
|
+
return response;
|
|
22927
|
+
if ((actorRequest.method === "GET" || actorRequest.method === "HEAD") && !("getOrCreateForKey" in target)) {
|
|
22928
|
+
const token = await this.#tokenProvider.refreshIfCurrent(
|
|
22929
|
+
config3.token
|
|
22930
|
+
);
|
|
22931
|
+
await ((_a2 = response.body) == null ? void 0 : _a2.cancel());
|
|
22932
|
+
return send({ ...this.#config, token });
|
|
22933
|
+
}
|
|
22934
|
+
await this.#tokenProvider.refreshIfCurrent(config3.token);
|
|
22935
|
+
return response;
|
|
22718
22936
|
}
|
|
22719
22937
|
async openWebSocket(path2, target, encoding, params, options = {}) {
|
|
22720
22938
|
await this.#metadataPromise;
|
|
22939
|
+
const config3 = await this.#authorizedConfig();
|
|
22721
22940
|
const gatewayUrl = this.#buildGatewayUrlForTarget(
|
|
22941
|
+
config3,
|
|
22722
22942
|
target,
|
|
22723
22943
|
path2,
|
|
22724
22944
|
options
|
|
22725
22945
|
);
|
|
22726
|
-
|
|
22727
|
-
|
|
22946
|
+
const ws = await openWebSocketToGateway(
|
|
22947
|
+
config3,
|
|
22728
22948
|
gatewayUrl,
|
|
22729
22949
|
encoding,
|
|
22730
22950
|
params,
|
|
@@ -22733,25 +22953,59 @@ var RemoteEngineControlClient = class {
|
|
|
22733
22953
|
directActorId: shouldSkipReadyWait(options) ? directActorIdFromTarget(target) : void 0
|
|
22734
22954
|
}
|
|
22735
22955
|
);
|
|
22956
|
+
this.#watchWebSocketAuth(ws, config3.token);
|
|
22957
|
+
return ws;
|
|
22958
|
+
}
|
|
22959
|
+
async refreshAuthToken(ws) {
|
|
22960
|
+
const context2 = this.#webSocketTokens.get(ws);
|
|
22961
|
+
if (!(context2 == null ? void 0 : context2.refresh)) return false;
|
|
22962
|
+
await context2.refresh;
|
|
22963
|
+
return true;
|
|
22964
|
+
}
|
|
22965
|
+
#watchWebSocketAuth(ws, token) {
|
|
22966
|
+
const tokenProvider = this.#tokenProvider;
|
|
22967
|
+
if (!tokenProvider || !token) return;
|
|
22968
|
+
const context2 = {};
|
|
22969
|
+
this.#webSocketTokens.set(ws, context2);
|
|
22970
|
+
ws.addEventListener(
|
|
22971
|
+
"close",
|
|
22972
|
+
(event2) => {
|
|
22973
|
+
if (event2.code !== 1008 || !event2.reason) return;
|
|
22974
|
+
const separator = event2.reason.indexOf(".");
|
|
22975
|
+
if (separator < 0) return;
|
|
22976
|
+
const code = event2.reason.slice(separator + 1).split(/[\s:#]/, 1)[0];
|
|
22977
|
+
if (isInvalidToken(event2.reason.slice(0, separator), code)) {
|
|
22978
|
+
context2.refresh = tokenProvider.refreshIfCurrent(token).catch((error46) => {
|
|
22979
|
+
logger2().warn(
|
|
22980
|
+
"failed to renew authentication token"
|
|
22981
|
+
);
|
|
22982
|
+
throw error46;
|
|
22983
|
+
});
|
|
22984
|
+
context2.refresh.catch(() => {
|
|
22985
|
+
});
|
|
22986
|
+
}
|
|
22987
|
+
}
|
|
22988
|
+
);
|
|
22736
22989
|
}
|
|
22737
22990
|
async buildGatewayUrl(target, options = {}) {
|
|
22738
22991
|
await this.#metadataPromise;
|
|
22739
|
-
return this.#buildGatewayUrlForTarget(
|
|
22992
|
+
return this.#buildGatewayUrlForTarget(
|
|
22993
|
+
await this.#authorizedConfig(),
|
|
22994
|
+
target,
|
|
22995
|
+
"",
|
|
22996
|
+
options
|
|
22997
|
+
);
|
|
22740
22998
|
}
|
|
22741
22999
|
async proxyRequest(_c, actorRequest, actorId) {
|
|
22742
|
-
|
|
22743
|
-
const gatewayUrl = this.#buildGatewayUrlForTarget(
|
|
22744
|
-
{ directId: actorId },
|
|
22745
|
-
requestPath(actorRequest)
|
|
22746
|
-
);
|
|
22747
|
-
return sendHttpRequestToGateway(this.#config, gatewayUrl, actorRequest);
|
|
23000
|
+
return this.sendRequest({ directId: actorId }, actorRequest);
|
|
22748
23001
|
}
|
|
22749
23002
|
async proxyWebSocket(c, path2, actorId, encoding, params) {
|
|
22750
|
-
var _a2
|
|
23003
|
+
var _a2;
|
|
22751
23004
|
await this.#metadataPromise;
|
|
22752
|
-
const
|
|
23005
|
+
const config3 = await this.#authorizedConfig();
|
|
23006
|
+
const upgradeWebSocket = (_a2 = config3.getUpgradeWebSocket) == null ? void 0 : _a2.call(config3);
|
|
22753
23007
|
(0, import_invariant4.default)(upgradeWebSocket, "missing getUpgradeWebSocket");
|
|
22754
|
-
const endpoint = getEndpoint(
|
|
23008
|
+
const endpoint = getEndpoint(config3);
|
|
22755
23009
|
const guardUrl = combineUrlPath(endpoint, path2);
|
|
22756
23010
|
const wsGuardUrl = guardUrl.replace("http://", "ws://");
|
|
22757
23011
|
logger2().debug({
|
|
@@ -22761,7 +23015,7 @@ var RemoteEngineControlClient = class {
|
|
|
22761
23015
|
guardUrl
|
|
22762
23016
|
});
|
|
22763
23017
|
const protocols = buildWebSocketProtocols(
|
|
22764
|
-
|
|
23018
|
+
config3,
|
|
22765
23019
|
encoding,
|
|
22766
23020
|
params,
|
|
22767
23021
|
void 0,
|
|
@@ -22779,8 +23033,8 @@ var RemoteEngineControlClient = class {
|
|
|
22779
23033
|
setGetUpgradeWebSocket(getUpgradeWebSocket) {
|
|
22780
23034
|
this.#config.getUpgradeWebSocket = getUpgradeWebSocket;
|
|
22781
23035
|
}
|
|
22782
|
-
#buildGatewayUrlForTarget(target, path2, options = {}) {
|
|
22783
|
-
const endpoint = getEndpoint(
|
|
23036
|
+
#buildGatewayUrlForTarget(config3, target, path2, options = {}) {
|
|
23037
|
+
const endpoint = getEndpoint(config3);
|
|
22784
23038
|
if (shouldSkipReadyWait(options) && directActorIdFromTarget(target) && canUseDirectSkipReadyWaitPath(path2)) {
|
|
22785
23039
|
return combineUrlPath(endpoint, path2);
|
|
22786
23040
|
}
|
|
@@ -22788,7 +23042,7 @@ var RemoteEngineControlClient = class {
|
|
|
22788
23042
|
return buildActorGatewayUrl(
|
|
22789
23043
|
endpoint,
|
|
22790
23044
|
target.directId,
|
|
22791
|
-
|
|
23045
|
+
config3.token,
|
|
22792
23046
|
path2
|
|
22793
23047
|
);
|
|
22794
23048
|
}
|
|
@@ -22796,20 +23050,20 @@ var RemoteEngineControlClient = class {
|
|
|
22796
23050
|
return buildActorGatewayUrl(
|
|
22797
23051
|
endpoint,
|
|
22798
23052
|
target.getForId.actorId,
|
|
22799
|
-
|
|
23053
|
+
config3.token,
|
|
22800
23054
|
path2
|
|
22801
23055
|
);
|
|
22802
23056
|
}
|
|
22803
23057
|
if ("getForKey" in target || "getOrCreateForKey" in target) {
|
|
22804
23058
|
return buildActorQueryGatewayUrl(
|
|
22805
23059
|
endpoint,
|
|
22806
|
-
|
|
23060
|
+
config3.namespace,
|
|
22807
23061
|
target,
|
|
22808
|
-
|
|
23062
|
+
config3.token,
|
|
22809
23063
|
path2,
|
|
22810
|
-
|
|
23064
|
+
config3.maxInputSize,
|
|
22811
23065
|
void 0,
|
|
22812
|
-
"getOrCreateForKey" in target ? target.getOrCreateForKey.poolName ??
|
|
23066
|
+
"getOrCreateForKey" in target ? target.getOrCreateForKey.poolName ?? config3.poolName : void 0,
|
|
22813
23067
|
options
|
|
22814
23068
|
);
|
|
22815
23069
|
}
|
|
@@ -22858,7 +23112,7 @@ function apiActorToOutput(actor2) {
|
|
|
22858
23112
|
};
|
|
22859
23113
|
}
|
|
22860
23114
|
|
|
22861
|
-
// ../rivetkit/dist/tsup/chunk-
|
|
23115
|
+
// ../rivetkit/dist/tsup/chunk-RIPVNPR6.js
|
|
22862
23116
|
var nativeStateTransactionOpeners = /* @__PURE__ */ new WeakMap();
|
|
22863
23117
|
var nativeStateTransactionClientBinders = /* @__PURE__ */ new WeakMap();
|
|
22864
23118
|
function registerNativeStateTransactionOpener(provider, opener) {
|
|
@@ -24600,23 +24854,6 @@ var InlineWebSocketAdapter = class {
|
|
|
24600
24854
|
}
|
|
24601
24855
|
}
|
|
24602
24856
|
};
|
|
24603
|
-
var ENGINE_HOST = "127.0.0.1";
|
|
24604
|
-
var ENGINE_PORT = 6420;
|
|
24605
|
-
var ENGINE_ENDPOINT = buildEngineEndpoint(ENGINE_HOST, ENGINE_PORT);
|
|
24606
|
-
function buildEngineEndpoint(host, port) {
|
|
24607
|
-
const urlHost = host.includes(":") && !host.startsWith("[") ? `[${host}]` : host;
|
|
24608
|
-
return `http://${urlHost}:${port}`;
|
|
24609
|
-
}
|
|
24610
|
-
function isLocalEngineEndpoint(endpoint) {
|
|
24611
|
-
let url2;
|
|
24612
|
-
try {
|
|
24613
|
-
url2 = new URL(endpoint);
|
|
24614
|
-
} catch {
|
|
24615
|
-
return false;
|
|
24616
|
-
}
|
|
24617
|
-
const hostname3 = url2.hostname.toLowerCase();
|
|
24618
|
-
return hostname3 === "localhost" || hostname3 === "0.0.0.0" || hostname3 === "::" || hostname3 === "[::]" || hostname3 === "::1" || hostname3 === "[::1]" || /^127(?:\.\d{1,3}){0,3}$/.test(hostname3);
|
|
24619
|
-
}
|
|
24620
24857
|
function logger22() {
|
|
24621
24858
|
return getLogger("registry");
|
|
24622
24859
|
}
|
|
@@ -24714,20 +24951,9 @@ async function configureServerlessPool(config3) {
|
|
|
24714
24951
|
});
|
|
24715
24952
|
throw lastError;
|
|
24716
24953
|
}
|
|
24717
|
-
var warnedMissingVersion = false;
|
|
24718
24954
|
var EnvoyConfigSchema = external_exports.object({
|
|
24719
24955
|
poolName: external_exports.string().default(() => getRivetPool() ?? "default"),
|
|
24720
|
-
version: external_exports.number().default(() =>
|
|
24721
|
-
const version2 = getRivetEnvoyVersion();
|
|
24722
|
-
if (version2 !== void 0) return version2;
|
|
24723
|
-
if (getNodeEnv() === "production" && !warnedMissingVersion) {
|
|
24724
|
-
warnedMissingVersion = true;
|
|
24725
|
-
getLogger("rivetkit").error(
|
|
24726
|
-
"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"
|
|
24727
|
-
);
|
|
24728
|
-
}
|
|
24729
|
-
return 1;
|
|
24730
|
-
}),
|
|
24956
|
+
version: external_exports.number().default(() => getRivetEnvoyVersion() ?? 1),
|
|
24731
24957
|
// Deprecated.
|
|
24732
24958
|
totalSlots: external_exports.number().default(() => getRivetTotalSlots() ?? 1e5),
|
|
24733
24959
|
envoyKey: external_exports.string().optional()
|
|
@@ -25027,7 +25253,7 @@ var RegistryConfigSchema = external_exports.object({
|
|
|
25027
25253
|
config3.startEngine || parsedEndpoint
|
|
25028
25254
|
);
|
|
25029
25255
|
const namespace = (parsedEndpoint == null ? void 0 : parsedEndpoint.namespace) ?? config3.namespace ?? "default";
|
|
25030
|
-
const token = (parsedEndpoint == null ? void 0 : parsedEndpoint.token) ?? config3.token ?? "
|
|
25256
|
+
const token = (parsedEndpoint == null ? void 0 : parsedEndpoint.token) ?? config3.token ?? (endpoint && isLocalEngineEndpoint(endpoint) ? "default" : void 0);
|
|
25031
25257
|
const parsedPublicEndpoint = config3.serverless.publicEndpoint ? tryParseEndpoint(ctx, {
|
|
25032
25258
|
endpoint: config3.serverless.publicEndpoint,
|
|
25033
25259
|
path: ["serverless", "publicEndpoint"]
|
|
@@ -28039,7 +28265,18 @@ function isStructuredBridgeError(error46) {
|
|
|
28039
28265
|
}
|
|
28040
28266
|
function encodeNativeCallbackError(error46) {
|
|
28041
28267
|
const structuredError = isStructuredBridgeError(error46) ? error46 : deconstructError(error46, true);
|
|
28042
|
-
const
|
|
28268
|
+
const { encoded, droppedMetadataCause } = encodeBridgeRivetError(structuredError);
|
|
28269
|
+
if (droppedMetadataCause !== void 0) {
|
|
28270
|
+
logger22().warn(
|
|
28271
|
+
{
|
|
28272
|
+
group: structuredError.group,
|
|
28273
|
+
code: structuredError.code,
|
|
28274
|
+
error: String(droppedMetadataCause)
|
|
28275
|
+
},
|
|
28276
|
+
"dropped error metadata that JSON cannot encode"
|
|
28277
|
+
);
|
|
28278
|
+
}
|
|
28279
|
+
const bridgeError = new Error(encoded, {
|
|
28043
28280
|
cause: error46 instanceof Error ? error46 : void 0
|
|
28044
28281
|
});
|
|
28045
28282
|
return Object.assign(bridgeError, {
|
|
@@ -29376,7 +29613,10 @@ var ActorContextHandleAdapter = class {
|
|
|
29376
29613
|
}
|
|
29377
29614
|
this.#request = request;
|
|
29378
29615
|
this[ACTOR_CONTEXT_INTERNAL_SYMBOL] = new NativeWorkflowRuntimeAdapter(
|
|
29379
|
-
this
|
|
29616
|
+
this,
|
|
29617
|
+
() => this.#logByInvocationScope.delete(
|
|
29618
|
+
this.#runtime.currentInvocationScope() ?? NO_INVOCATION_SCOPE
|
|
29619
|
+
)
|
|
29380
29620
|
);
|
|
29381
29621
|
}
|
|
29382
29622
|
get kv() {
|
|
@@ -29548,7 +29788,10 @@ var ActorContextHandleAdapter = class {
|
|
|
29548
29788
|
() => this.#runtime.actorInvocationTraceContext(this.#ctx)
|
|
29549
29789
|
);
|
|
29550
29790
|
}
|
|
29551
|
-
/**
|
|
29791
|
+
/**
|
|
29792
|
+
* Cached per invocation, because the `run` context outlives workflow runs and steps.
|
|
29793
|
+
* A workflow queue receive clears the entry, because the run's ray becomes the message's ray.
|
|
29794
|
+
*/
|
|
29552
29795
|
get log() {
|
|
29553
29796
|
const scope = this.#runtime.currentInvocationScope() ?? NO_INVOCATION_SCOPE;
|
|
29554
29797
|
const cached2 = this.#logByInvocationScope.get(scope);
|
|
@@ -30095,13 +30338,15 @@ var ActorContextHandleAdapter = class {
|
|
|
30095
30338
|
};
|
|
30096
30339
|
var NativeWorkflowRuntimeAdapter = class {
|
|
30097
30340
|
#ctx;
|
|
30341
|
+
#onMessagesReceived;
|
|
30098
30342
|
#completions = /* @__PURE__ */ new Map();
|
|
30099
30343
|
id;
|
|
30100
30344
|
driver;
|
|
30101
30345
|
queueManager;
|
|
30102
30346
|
stateManager;
|
|
30103
|
-
constructor(ctx) {
|
|
30347
|
+
constructor(ctx, onMessagesReceived) {
|
|
30104
30348
|
this.#ctx = ctx;
|
|
30349
|
+
this.#onMessagesReceived = onMessagesReceived;
|
|
30105
30350
|
this.id = ctx.actorId;
|
|
30106
30351
|
this.driver = {
|
|
30107
30352
|
kvBatchGet: async (actorId, keys) => {
|
|
@@ -30141,6 +30386,9 @@ var NativeWorkflowRuntimeAdapter = class {
|
|
|
30141
30386
|
timeout: timeout ?? 0,
|
|
30142
30387
|
completable
|
|
30143
30388
|
});
|
|
30389
|
+
if (messages.length > 0) {
|
|
30390
|
+
this.#onMessagesReceived();
|
|
30391
|
+
}
|
|
30144
30392
|
return messages.map(
|
|
30145
30393
|
(message) => this.#wrapQueueMessage(message)
|
|
30146
30394
|
);
|
|
@@ -31992,7 +32240,23 @@ var Registry = class {
|
|
|
31992
32240
|
* Starts an actor envoy for standalone server deployments.
|
|
31993
32241
|
*/
|
|
31994
32242
|
#startEnvoy(config3, printWelcome) {
|
|
32243
|
+
var _a2;
|
|
31995
32244
|
if (!this.#runtimeServePromise) {
|
|
32245
|
+
const configuredEnvoyVersion = (_a2 = this.#config.envoy) == null ? void 0 : _a2.version;
|
|
32246
|
+
const envoyVersionSource = configuredEnvoyVersion !== void 0 ? "config" : getRivetEnvoyVersion() !== void 0 ? "environment" : "default";
|
|
32247
|
+
logger22().info({
|
|
32248
|
+
msg: "starting rivetkit envoy",
|
|
32249
|
+
rivetkitVersion: VERSION,
|
|
32250
|
+
envoyVersion: config3.envoy.version,
|
|
32251
|
+
envoyVersionSource
|
|
32252
|
+
});
|
|
32253
|
+
if (envoyVersionSource === "default" && getNodeEnv() === "production") {
|
|
32254
|
+
logger22().error({
|
|
32255
|
+
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",
|
|
32256
|
+
envoyVersion: config3.envoy.version,
|
|
32257
|
+
envoyVersionSource
|
|
32258
|
+
});
|
|
32259
|
+
}
|
|
31996
32260
|
const configuredRegistryPromise = this.#buildConfiguredRegistry(config3);
|
|
31997
32261
|
this.#runtimeServeConfiguredPromise = configuredRegistryPromise;
|
|
31998
32262
|
this.#runtimeServeLifecyclePromise = configuredRegistryPromise.then(
|