@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.mjs
CHANGED
|
@@ -297,6 +297,215 @@ var require_retry2 = __commonJS({
|
|
|
297
297
|
// src/mod.ts
|
|
298
298
|
import * as wasmBindings from "@rivetkit/rivetkit-wasm";
|
|
299
299
|
|
|
300
|
+
// ../rivetkit/dist/tsup/chunk-ZOVJDAOW.js
|
|
301
|
+
var INTERNAL_ERROR_CODE = "internal_error";
|
|
302
|
+
var INTERNAL_ERROR_DESCRIPTION = "An internal error occurred";
|
|
303
|
+
var USER_ERROR_CODE = "user_error";
|
|
304
|
+
var BRIDGE_RIVET_ERROR_PREFIX = "__RIVET_ERROR_JSON__:";
|
|
305
|
+
function looksLikeRivetErrorOptions(value) {
|
|
306
|
+
return typeof value === "object" && value !== null && ("public" in value || "metadata" in value || "rayId" in value || "statusCode" in value || "actor" in value || "cause" in value);
|
|
307
|
+
}
|
|
308
|
+
function isTypedErrorTag(value) {
|
|
309
|
+
return value === "ActorError" || value === "RivetError";
|
|
310
|
+
}
|
|
311
|
+
function errorMessage(error46, fallback = String(error46)) {
|
|
312
|
+
if (error46 && typeof error46 === "object" && "message" in error46 && typeof error46.message === "string") {
|
|
313
|
+
return error46.message;
|
|
314
|
+
}
|
|
315
|
+
return fallback;
|
|
316
|
+
}
|
|
317
|
+
function isRivetErrorLike(error46) {
|
|
318
|
+
return typeof error46 === "object" && error46 !== null && "group" in error46 && typeof error46.group === "string" && "code" in error46 && typeof error46.code === "string" && "message" in error46 && typeof error46.message === "string" && (!("rayId" in error46) || error46.rayId === void 0 || typeof error46.rayId === "string") && (!("__type" in error46) || isTypedErrorTag(error46.__type));
|
|
319
|
+
}
|
|
320
|
+
function isActorAbortedError(error46) {
|
|
321
|
+
return isRivetErrorLike(error46) && error46.group === "actor" && error46.code === "aborted";
|
|
322
|
+
}
|
|
323
|
+
function isActorSpecifier(value) {
|
|
324
|
+
return typeof value === "object" && value !== null && "actorId" in value && typeof value.actorId === "string" && "generation" in value && typeof value.generation === "number" && (!("key" in value) || value.key === void 0 || typeof value.key === "string");
|
|
325
|
+
}
|
|
326
|
+
var RivetError = class extends Error {
|
|
327
|
+
__type = "RivetError";
|
|
328
|
+
public;
|
|
329
|
+
metadata;
|
|
330
|
+
rayId;
|
|
331
|
+
statusCode;
|
|
332
|
+
actor;
|
|
333
|
+
group;
|
|
334
|
+
code;
|
|
335
|
+
static isRivetError(error46) {
|
|
336
|
+
return isRivetErrorLike(error46);
|
|
337
|
+
}
|
|
338
|
+
static isActorError(error46) {
|
|
339
|
+
return isRivetErrorLike(error46);
|
|
340
|
+
}
|
|
341
|
+
constructor(group, code, message, options) {
|
|
342
|
+
const normalized = looksLikeRivetErrorOptions(options) ? options : { metadata: options };
|
|
343
|
+
super(message, { cause: normalized.cause });
|
|
344
|
+
this.name = "RivetError";
|
|
345
|
+
this.group = group;
|
|
346
|
+
this.code = code;
|
|
347
|
+
this.public = normalized.public ?? false;
|
|
348
|
+
this.metadata = normalized.metadata;
|
|
349
|
+
this.rayId = normalized.rayId ?? void 0;
|
|
350
|
+
this.statusCode = normalized.statusCode ?? (this.public ? 400 : 500);
|
|
351
|
+
this.actor = normalized.actor;
|
|
352
|
+
}
|
|
353
|
+
toString() {
|
|
354
|
+
return this.message;
|
|
355
|
+
}
|
|
356
|
+
};
|
|
357
|
+
var UserError = class extends RivetError {
|
|
358
|
+
constructor(message, options) {
|
|
359
|
+
super("user", (options == null ? void 0 : options.code) ?? USER_ERROR_CODE, message, {
|
|
360
|
+
public: true,
|
|
361
|
+
metadata: options == null ? void 0 : options.metadata,
|
|
362
|
+
cause: options == null ? void 0 : options.cause
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
};
|
|
366
|
+
function toRivetError(error46, fallback) {
|
|
367
|
+
if (typeof error46 === "string") {
|
|
368
|
+
const bridged = decodeBridgeRivetError(error46);
|
|
369
|
+
if (bridged) {
|
|
370
|
+
return bridged;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
if (error46 instanceof Error) {
|
|
374
|
+
const bridged = decodeBridgeRivetError(error46.message);
|
|
375
|
+
if (bridged) {
|
|
376
|
+
return bridged;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
if (isRivetErrorLike(error46)) {
|
|
380
|
+
return new RivetError(error46.group, error46.code, error46.message, {
|
|
381
|
+
public: error46.public,
|
|
382
|
+
statusCode: error46.statusCode,
|
|
383
|
+
metadata: error46.metadata,
|
|
384
|
+
rayId: error46.rayId,
|
|
385
|
+
actor: error46.actor,
|
|
386
|
+
cause: error46 instanceof Error ? error46.cause : void 0
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
return new RivetError(
|
|
390
|
+
(fallback == null ? void 0 : fallback.group) ?? "actor",
|
|
391
|
+
(fallback == null ? void 0 : fallback.code) ?? INTERNAL_ERROR_CODE,
|
|
392
|
+
errorMessage(error46, (fallback == null ? void 0 : fallback.message) ?? "Unknown error"),
|
|
393
|
+
{
|
|
394
|
+
public: fallback == null ? void 0 : fallback.public,
|
|
395
|
+
statusCode: fallback == null ? void 0 : fallback.statusCode,
|
|
396
|
+
metadata: fallback == null ? void 0 : fallback.metadata,
|
|
397
|
+
rayId: fallback == null ? void 0 : fallback.rayId,
|
|
398
|
+
actor: fallback == null ? void 0 : fallback.actor,
|
|
399
|
+
cause: error46 instanceof Error ? error46 : void 0
|
|
400
|
+
}
|
|
401
|
+
);
|
|
402
|
+
}
|
|
403
|
+
function encodeBridgeRivetError(error46) {
|
|
404
|
+
const payload = {
|
|
405
|
+
group: error46.group,
|
|
406
|
+
code: error46.code,
|
|
407
|
+
message: error46.message,
|
|
408
|
+
metadata: error46.metadata,
|
|
409
|
+
rayId: error46.rayId,
|
|
410
|
+
public: error46.public,
|
|
411
|
+
statusCode: error46.statusCode,
|
|
412
|
+
actor: error46.actor
|
|
413
|
+
};
|
|
414
|
+
try {
|
|
415
|
+
return {
|
|
416
|
+
encoded: `${BRIDGE_RIVET_ERROR_PREFIX}${JSON.stringify(payload)}`
|
|
417
|
+
};
|
|
418
|
+
} catch (cause) {
|
|
419
|
+
return {
|
|
420
|
+
encoded: `${BRIDGE_RIVET_ERROR_PREFIX}${JSON.stringify({ ...payload, metadata: void 0 })}`,
|
|
421
|
+
droppedMetadataCause: cause
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
function encodeErrorForBridge(error46) {
|
|
426
|
+
if (isCanonicalStructuredRivetError(error46)) {
|
|
427
|
+
return encodeBridgeRivetError(error46).encoded;
|
|
428
|
+
}
|
|
429
|
+
return String(error46);
|
|
430
|
+
}
|
|
431
|
+
function isCanonicalStructuredRivetError(error46) {
|
|
432
|
+
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";
|
|
433
|
+
}
|
|
434
|
+
function decodeBridgeRivetErrorPayload(value) {
|
|
435
|
+
if (!value.startsWith(BRIDGE_RIVET_ERROR_PREFIX)) {
|
|
436
|
+
return void 0;
|
|
437
|
+
}
|
|
438
|
+
try {
|
|
439
|
+
const raw = JSON.parse(
|
|
440
|
+
value.slice(BRIDGE_RIVET_ERROR_PREFIX.length)
|
|
441
|
+
);
|
|
442
|
+
const payload = {
|
|
443
|
+
...raw,
|
|
444
|
+
rayId: raw.rayId ?? void 0
|
|
445
|
+
};
|
|
446
|
+
if (!isRivetErrorLike(payload)) {
|
|
447
|
+
return void 0;
|
|
448
|
+
}
|
|
449
|
+
if (payload.actor !== void 0 && payload.actor !== null && !isActorSpecifier(payload.actor)) {
|
|
450
|
+
return void 0;
|
|
451
|
+
}
|
|
452
|
+
return payload;
|
|
453
|
+
} catch {
|
|
454
|
+
return void 0;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
function decodeBridgeRivetError(value) {
|
|
458
|
+
const payload = decodeBridgeRivetErrorPayload(value);
|
|
459
|
+
if (!payload) {
|
|
460
|
+
return void 0;
|
|
461
|
+
}
|
|
462
|
+
return new RivetError(payload.group, payload.code, payload.message, {
|
|
463
|
+
metadata: payload.metadata,
|
|
464
|
+
rayId: payload.rayId,
|
|
465
|
+
public: payload.public,
|
|
466
|
+
statusCode: payload.statusCode,
|
|
467
|
+
actor: payload.actor ?? void 0
|
|
468
|
+
});
|
|
469
|
+
}
|
|
470
|
+
function invalidRequest(error46) {
|
|
471
|
+
return new RivetError(
|
|
472
|
+
"request",
|
|
473
|
+
"invalid",
|
|
474
|
+
`Invalid request: ${errorMessage(error46, String(error46))}`,
|
|
475
|
+
{
|
|
476
|
+
public: true,
|
|
477
|
+
cause: error46 instanceof Error ? error46 : void 0
|
|
478
|
+
}
|
|
479
|
+
);
|
|
480
|
+
}
|
|
481
|
+
function actorNotFound(identifier) {
|
|
482
|
+
return new RivetError(
|
|
483
|
+
"actor",
|
|
484
|
+
"not_found",
|
|
485
|
+
identifier ? `Actor not found: ${identifier} (https://www.rivet.dev/docs/clients/javascript)` : "Actor not found (https://www.rivet.dev/docs/clients/javascript)",
|
|
486
|
+
{ public: true }
|
|
487
|
+
);
|
|
488
|
+
}
|
|
489
|
+
function forbiddenError() {
|
|
490
|
+
return new RivetError("auth", "forbidden", "Forbidden", {
|
|
491
|
+
public: true,
|
|
492
|
+
statusCode: 403
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
function unsupportedFeature(feature) {
|
|
496
|
+
return new RivetError(
|
|
497
|
+
"feature",
|
|
498
|
+
"unsupported",
|
|
499
|
+
`Unsupported feature: ${feature}`
|
|
500
|
+
);
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
// ../rivetkit/dist/tsup/chunk-DE2IFYJK.js
|
|
504
|
+
import {
|
|
505
|
+
pino,
|
|
506
|
+
stdTimeFunctions
|
|
507
|
+
} from "pino";
|
|
508
|
+
|
|
300
509
|
// ../../../node_modules/.pnpm/zod@4.1.13/node_modules/zod/v4/classic/external.js
|
|
301
510
|
var external_exports = {};
|
|
302
511
|
__export(external_exports, {
|
|
@@ -12967,870 +13176,178 @@ var classic_default = external_exports;
|
|
|
12967
13176
|
// ../../../node_modules/.pnpm/zod@4.1.13/node_modules/zod/v4/index.js
|
|
12968
13177
|
var v4_default = classic_default;
|
|
12969
13178
|
|
|
12970
|
-
// ../rivetkit/dist/tsup/chunk-
|
|
12971
|
-
|
|
12972
|
-
|
|
12973
|
-
|
|
12974
|
-
|
|
13179
|
+
// ../rivetkit/dist/tsup/chunk-DE2IFYJK.js
|
|
13180
|
+
var import_invariant = __toESM(require_invariant(), 1);
|
|
13181
|
+
import * as cbor from "cbor-x";
|
|
13182
|
+
var getRivetEngine = () => getEnvUniversal("RIVET_ENGINE");
|
|
13183
|
+
var getRivetEndpoint = () => getEnvUniversal("RIVET_ENDPOINT");
|
|
13184
|
+
var getRivetToken = () => getEnvUniversal("RIVET_TOKEN");
|
|
13185
|
+
var getRivetNamespace = () => getEnvUniversal("RIVET_NAMESPACE");
|
|
13186
|
+
var getRivetPool = () => getEnvUniversal("RIVET_POOL");
|
|
13187
|
+
var getRivetTotalSlots = () => {
|
|
13188
|
+
const value = getEnvUniversal("RIVET_TOTAL_SLOTS");
|
|
13189
|
+
return value !== void 0 ? parseInt(value, 10) : void 0;
|
|
13190
|
+
};
|
|
13191
|
+
var getRivetRunEngine = () => getEnvUniversal("RIVET_RUN_ENGINE") === "1";
|
|
13192
|
+
var getRivetRunEngineHost = () => getEnvUniversal("RIVET_RUN_ENGINE_HOST");
|
|
13193
|
+
var getRivetRunEnginePort = () => {
|
|
13194
|
+
const value = getEnvUniversal("RIVET_RUN_ENGINE_PORT");
|
|
13195
|
+
return value !== void 0 ? parseInt(value, 10) : void 0;
|
|
13196
|
+
};
|
|
13197
|
+
var getRivetRunEngineVersion = () => getEnvUniversal("RIVET_RUN_ENGINE_VERSION");
|
|
13198
|
+
var getRivetRunServices = () => {
|
|
13199
|
+
const value = getEnvUniversal("RIVET_RUN_SERVICES");
|
|
13200
|
+
return value === void 0 ? void 0 : value === "1";
|
|
13201
|
+
};
|
|
13202
|
+
var getRivetEnvoyVersion = () => {
|
|
13203
|
+
const value = getEnvUniversal("RIVET_ENVOY_VERSION");
|
|
13204
|
+
return value !== void 0 ? parseInt(value, 10) : void 0;
|
|
13205
|
+
};
|
|
13206
|
+
var getRivetPublicEndpoint = () => getEnvUniversal("RIVET_PUBLIC_ENDPOINT");
|
|
13207
|
+
var getRivetPublicToken = () => getEnvUniversal("RIVET_PUBLIC_TOKEN");
|
|
13208
|
+
var getRivetkitRuntime = () => getEnvUniversal("RIVETKIT_RUNTIME");
|
|
13209
|
+
var getRivetkitRuntimeMode = () => {
|
|
13210
|
+
const value = getEnvUniversal("RIVETKIT_RUNTIME_MODE");
|
|
13211
|
+
if (value === void 0) return "envoy";
|
|
13212
|
+
if (value === "envoy" || value === "serverless") return value;
|
|
13213
|
+
throw new Error(
|
|
13214
|
+
`RIVETKIT_RUNTIME_MODE env var must be "envoy" or "serverless"; got "${value}"`
|
|
13215
|
+
);
|
|
13216
|
+
};
|
|
13217
|
+
var getRivetkitPublicDir = () => {
|
|
13218
|
+
const value = getEnvUniversal("RIVETKIT_PUBLIC_DIR");
|
|
13219
|
+
return value === void 0 || value === "" ? void 0 : value;
|
|
13220
|
+
};
|
|
13221
|
+
function parsePortEnv(raw) {
|
|
13222
|
+
if (raw === void 0 || raw === "") return void 0;
|
|
13223
|
+
const parsed = Number.parseInt(raw, 10);
|
|
13224
|
+
if (!Number.isFinite(parsed) || parsed < 1 || parsed > 65535 || String(parsed) !== raw.trim()) {
|
|
13225
|
+
throw new Error(
|
|
13226
|
+
`RIVET_PORT env var must be an integer between 1 and 65535; got "${raw}"`
|
|
13227
|
+
);
|
|
12975
13228
|
}
|
|
12976
|
-
return
|
|
13229
|
+
return parsed;
|
|
12977
13230
|
}
|
|
12978
|
-
|
|
12979
|
-
|
|
12980
|
-
|
|
12981
|
-
|
|
12982
|
-
|
|
12983
|
-
|
|
12984
|
-
|
|
12985
|
-
|
|
12986
|
-
|
|
12987
|
-
|
|
12988
|
-
throw new TypeError(
|
|
12989
|
-
`Action input schema \`${name}\` is defined by both a nested path and a dotted key`
|
|
12990
|
-
);
|
|
12991
|
-
}
|
|
12992
|
-
const schema = nestedSchema ?? flatSchema;
|
|
12993
|
-
if (schema !== void 0) {
|
|
12994
|
-
flattened[name] = schema;
|
|
12995
|
-
}
|
|
12996
|
-
}
|
|
12997
|
-
return flattened;
|
|
13231
|
+
var getLogLevel = () => getEnvUniversal("RIVET_LOG_LEVEL") ?? getEnvUniversal("LOG_LEVEL");
|
|
13232
|
+
var getLogTarget = () => getEnvUniversal("RIVET_LOG_TARGET") === "1";
|
|
13233
|
+
var getLogTimestamp = () => getEnvUniversal("RIVET_LOG_TIMESTAMP") === "1";
|
|
13234
|
+
var getLogMessage = () => getEnvUniversal("RIVET_LOG_MESSAGE") === "1";
|
|
13235
|
+
var getLogErrorStack = () => getEnvUniversal("RIVET_LOG_ERROR_STACK") === "1";
|
|
13236
|
+
var getNodeEnv = () => getEnvUniversal("NODE_ENV");
|
|
13237
|
+
var getNextPhase = () => getEnvUniversal("NEXT_PHASE");
|
|
13238
|
+
var isDev = () => getNodeEnv() !== "production";
|
|
13239
|
+
function assertUnreachable(x) {
|
|
13240
|
+
throw new Error(`Unreachable case: ${x}`);
|
|
12998
13241
|
}
|
|
12999
|
-
function
|
|
13000
|
-
|
|
13001
|
-
|
|
13002
|
-
|
|
13003
|
-
|
|
13004
|
-
|
|
13005
|
-
|
|
13006
|
-
|
|
13242
|
+
function deconstructError(error46, exposeInternalError = false) {
|
|
13243
|
+
let statusCode;
|
|
13244
|
+
let public_;
|
|
13245
|
+
let group;
|
|
13246
|
+
let code;
|
|
13247
|
+
let message;
|
|
13248
|
+
let metadata;
|
|
13249
|
+
let rayId;
|
|
13250
|
+
let actor2;
|
|
13251
|
+
if (isCanonicalStructuredRivetError(error46)) {
|
|
13252
|
+
statusCode = typeof error46.statusCode === "number" ? error46.statusCode : error46.public ? 400 : 500;
|
|
13253
|
+
public_ = error46.public ?? false;
|
|
13254
|
+
group = error46.group;
|
|
13255
|
+
code = error46.code;
|
|
13256
|
+
message = error46.message;
|
|
13257
|
+
metadata = error46.metadata;
|
|
13258
|
+
rayId = error46.rayId;
|
|
13259
|
+
actor2 = error46.actor;
|
|
13260
|
+
} else if (RivetError.isActorError(error46) && error46.public) {
|
|
13261
|
+
statusCode = "statusCode" in error46 && error46.statusCode ? error46.statusCode : 400;
|
|
13262
|
+
public_ = true;
|
|
13263
|
+
group = error46.group;
|
|
13264
|
+
code = error46.code;
|
|
13265
|
+
message = getErrorMessage(error46);
|
|
13266
|
+
metadata = error46.metadata;
|
|
13267
|
+
rayId = error46.rayId;
|
|
13268
|
+
actor2 = error46.actor;
|
|
13269
|
+
} else if (exposeInternalError) {
|
|
13270
|
+
if (RivetError.isActorError(error46)) {
|
|
13271
|
+
statusCode = 500;
|
|
13272
|
+
public_ = false;
|
|
13273
|
+
group = error46.group;
|
|
13274
|
+
code = error46.code;
|
|
13275
|
+
message = getErrorMessage(error46);
|
|
13276
|
+
metadata = error46.metadata;
|
|
13277
|
+
rayId = error46.rayId;
|
|
13278
|
+
actor2 = error46.actor;
|
|
13279
|
+
} else {
|
|
13280
|
+
statusCode = 500;
|
|
13281
|
+
public_ = false;
|
|
13282
|
+
group = "rivetkit";
|
|
13283
|
+
code = INTERNAL_ERROR_CODE;
|
|
13284
|
+
message = getErrorMessage(error46);
|
|
13007
13285
|
}
|
|
13008
|
-
}
|
|
13009
|
-
|
|
13010
|
-
|
|
13011
|
-
|
|
13012
|
-
|
|
13013
|
-
|
|
13014
|
-
|
|
13015
|
-
|
|
13286
|
+
} else {
|
|
13287
|
+
statusCode = 500;
|
|
13288
|
+
public_ = false;
|
|
13289
|
+
group = "rivetkit";
|
|
13290
|
+
code = INTERNAL_ERROR_CODE;
|
|
13291
|
+
message = INTERNAL_ERROR_DESCRIPTION;
|
|
13292
|
+
if (RivetError.isActorError(error46)) {
|
|
13293
|
+
actor2 = error46.actor;
|
|
13016
13294
|
}
|
|
13017
|
-
|
|
13018
|
-
}
|
|
13019
|
-
|
|
13020
|
-
const entries = [];
|
|
13021
|
-
const names = /* @__PURE__ */ new Set();
|
|
13022
|
-
visitActionGroup(actions ?? {}, [], entries, names);
|
|
13023
|
-
return entries;
|
|
13024
|
-
}
|
|
13025
|
-
function visitActionGroup(value, path2, entries, names) {
|
|
13026
|
-
if (!isRecord(value)) {
|
|
13027
|
-
throw new TypeError(
|
|
13028
|
-
`${formatActionPath(path2)} must be an action handler or group`
|
|
13029
|
-
);
|
|
13295
|
+
metadata = {
|
|
13296
|
+
//url: `https://dashboard.rivet.dev/projects/${actorMetadata.project.slug}/environments/${actorMetadata.environment.slug}/actors?actorId=${actorMetadata.actor.id}`,
|
|
13297
|
+
};
|
|
13030
13298
|
}
|
|
13031
|
-
|
|
13032
|
-
|
|
13033
|
-
|
|
13034
|
-
|
|
13035
|
-
|
|
13036
|
-
|
|
13037
|
-
|
|
13038
|
-
|
|
13299
|
+
return {
|
|
13300
|
+
__type: "ActorError",
|
|
13301
|
+
statusCode,
|
|
13302
|
+
public: public_,
|
|
13303
|
+
group,
|
|
13304
|
+
code,
|
|
13305
|
+
message,
|
|
13306
|
+
metadata,
|
|
13307
|
+
rayId,
|
|
13308
|
+
actor: actor2
|
|
13309
|
+
};
|
|
13310
|
+
}
|
|
13311
|
+
function stringifyError(error46) {
|
|
13312
|
+
if (error46 instanceof Error) {
|
|
13313
|
+
if (typeof process !== "undefined" && getLogErrorStack()) {
|
|
13314
|
+
let stack;
|
|
13315
|
+
try {
|
|
13316
|
+
stack = error46.stack;
|
|
13317
|
+
} catch {
|
|
13318
|
+
stack = void 0;
|
|
13039
13319
|
}
|
|
13040
|
-
|
|
13041
|
-
|
|
13042
|
-
name,
|
|
13043
|
-
path: childPath,
|
|
13044
|
-
handler: child
|
|
13045
|
-
});
|
|
13320
|
+
return `${error46.name}: ${error46.message}${stack ? `
|
|
13321
|
+
${stack}` : ""}`;
|
|
13046
13322
|
} else {
|
|
13047
|
-
|
|
13323
|
+
return `${error46.name}: ${error46.message}`;
|
|
13048
13324
|
}
|
|
13049
|
-
}
|
|
13050
|
-
|
|
13051
|
-
|
|
13052
|
-
|
|
13053
|
-
|
|
13054
|
-
|
|
13055
|
-
return
|
|
13325
|
+
} else if (typeof error46 === "string") {
|
|
13326
|
+
return error46;
|
|
13327
|
+
} else if (typeof error46 === "object" && error46 !== null) {
|
|
13328
|
+
try {
|
|
13329
|
+
return `${JSON.stringify(error46)}`;
|
|
13330
|
+
} catch {
|
|
13331
|
+
return "[cannot stringify error]";
|
|
13056
13332
|
}
|
|
13057
|
-
|
|
13333
|
+
} else {
|
|
13334
|
+
return `Unknown error: ${getErrorMessage(error46)}`;
|
|
13058
13335
|
}
|
|
13059
|
-
return value;
|
|
13060
13336
|
}
|
|
13061
|
-
function
|
|
13062
|
-
if (typeof
|
|
13063
|
-
return
|
|
13337
|
+
function getErrorMessage(err) {
|
|
13338
|
+
if (err && typeof err === "object" && "message" in err && typeof err.message === "string") {
|
|
13339
|
+
return err.message;
|
|
13340
|
+
} else {
|
|
13341
|
+
return String(err);
|
|
13064
13342
|
}
|
|
13065
|
-
const prototype = Object.getPrototypeOf(value);
|
|
13066
|
-
return prototype === Object.prototype || prototype === null;
|
|
13067
13343
|
}
|
|
13068
|
-
function
|
|
13069
|
-
return
|
|
13070
|
-
}
|
|
13071
|
-
var DEFAULT_SLEEP_GRACE_PERIOD = 15e3;
|
|
13072
|
-
var ACTOR_CONTEXT_INTERNAL_SYMBOL = /* @__PURE__ */ Symbol(
|
|
13073
|
-
"rivetkit.actor_context_internal"
|
|
13074
|
-
);
|
|
13075
|
-
var RAW_STATE_SYMBOL = /* @__PURE__ */ Symbol("rivetkit.raw_state");
|
|
13076
|
-
var CONN_STATE_MANAGER_SYMBOL = /* @__PURE__ */ Symbol("rivetkit.conn_state_manager");
|
|
13077
|
-
var zFunction = () => external_exports.custom((val) => typeof val === "function");
|
|
13078
|
-
var zActionTree = external_exports.custom((value) => {
|
|
13079
|
-
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
13080
|
-
return false;
|
|
13081
|
-
}
|
|
13082
|
-
const prototype = Object.getPrototypeOf(value);
|
|
13083
|
-
return prototype === Object.prototype || prototype === null;
|
|
13084
|
-
}).superRefine((actions, ctx) => {
|
|
13085
|
-
try {
|
|
13086
|
-
flattenActionHandlers(actions);
|
|
13087
|
-
} catch (error46) {
|
|
13088
|
-
ctx.addIssue({
|
|
13089
|
-
code: "custom",
|
|
13090
|
-
message: error46 instanceof Error ? error46.message : "Invalid action definition"
|
|
13091
|
-
});
|
|
13092
|
-
}
|
|
13093
|
-
});
|
|
13094
|
-
var WorkflowInspectorConfigSchema = external_exports.object({
|
|
13095
|
-
getHistory: zFunction(),
|
|
13096
|
-
getState: zFunction().optional(),
|
|
13097
|
-
onHistoryUpdated: zFunction().optional(),
|
|
13098
|
-
replayFromStep: zFunction().optional()
|
|
13099
|
-
});
|
|
13100
|
-
var RunInspectorConfigSchema = external_exports.object({
|
|
13101
|
-
workflow: WorkflowInspectorConfigSchema.optional()
|
|
13102
|
-
}).optional();
|
|
13103
|
-
var BUILTIN_INSPECTOR_TAB_IDS = [
|
|
13104
|
-
"workflow",
|
|
13105
|
-
"database",
|
|
13106
|
-
"state",
|
|
13107
|
-
"queue",
|
|
13108
|
-
"schedules",
|
|
13109
|
-
"connections",
|
|
13110
|
-
"console"
|
|
13111
|
-
];
|
|
13112
|
-
var BuiltinInspectorTabIdSchema = external_exports.enum(BUILTIN_INSPECTOR_TAB_IDS);
|
|
13113
|
-
var CUSTOM_INSPECTOR_TAB_ID_RE = /^[A-Za-z0-9_-]+$/;
|
|
13114
|
-
var CustomInspectorTabEntrySchema = external_exports.object({
|
|
13115
|
-
id: external_exports.string().regex(
|
|
13116
|
-
CUSTOM_INSPECTOR_TAB_ID_RE,
|
|
13117
|
-
"inspector.tabs[].id must contain only letters, digits, underscore, or dash"
|
|
13118
|
-
),
|
|
13119
|
-
label: external_exports.string().min(1),
|
|
13120
|
-
source: external_exports.string().min(1),
|
|
13121
|
-
/**
|
|
13122
|
-
* Optional icon id. The dashboard maps strings to glyphs (see its
|
|
13123
|
-
* icon registry); unknown ids fall back to a generic icon.
|
|
13124
|
-
*/
|
|
13125
|
-
icon: external_exports.string().min(1).optional(),
|
|
13126
|
-
hidden: external_exports.literal(false).optional()
|
|
13127
|
-
}).strict();
|
|
13128
|
-
var HideInspectorTabEntrySchema = external_exports.object({
|
|
13129
|
-
id: BuiltinInspectorTabIdSchema,
|
|
13130
|
-
hidden: external_exports.literal(true)
|
|
13131
|
-
}).strict();
|
|
13132
|
-
var InspectorTabEntrySchema = external_exports.union([
|
|
13133
|
-
CustomInspectorTabEntrySchema,
|
|
13134
|
-
HideInspectorTabEntrySchema
|
|
13135
|
-
]);
|
|
13136
|
-
var ActorInspectorConfigSchema = external_exports.object({
|
|
13137
|
-
tabs: external_exports.array(InspectorTabEntrySchema).default(() => [])
|
|
13138
|
-
}).strict().refine(
|
|
13139
|
-
(data) => {
|
|
13140
|
-
const ids = data.tabs.map((t) => t.id);
|
|
13141
|
-
return new Set(ids).size === ids.length;
|
|
13142
|
-
},
|
|
13143
|
-
{ message: "Duplicate id in inspector.tabs", path: ["tabs"] }
|
|
13144
|
-
).refine(
|
|
13145
|
-
(data) => {
|
|
13146
|
-
const builtinSet = new Set(BUILTIN_INSPECTOR_TAB_IDS);
|
|
13147
|
-
return data.tabs.every(
|
|
13148
|
-
(t) => t.hidden === true || !builtinSet.has(t.id)
|
|
13149
|
-
);
|
|
13150
|
-
},
|
|
13151
|
-
{
|
|
13152
|
-
message: "Custom inspector tab id collides with a built-in (use hidden: true to hide a built-in)",
|
|
13153
|
-
path: ["tabs"]
|
|
13154
|
-
}
|
|
13155
|
-
);
|
|
13156
|
-
var RunConfigSchema = external_exports.object({
|
|
13157
|
-
/** Display name for the actor in the Inspector UI. */
|
|
13158
|
-
name: external_exports.string().optional(),
|
|
13159
|
-
/** Icon for the actor in the Inspector UI. Can be an emoji or FontAwesome icon name. */
|
|
13160
|
-
icon: external_exports.string().optional(),
|
|
13161
|
-
/** The run handler function. */
|
|
13162
|
-
run: zFunction(),
|
|
13163
|
-
/** Inspector integration for long-running run handlers. */
|
|
13164
|
-
inspector: RunInspectorConfigSchema.optional()
|
|
13165
|
-
});
|
|
13166
|
-
var RUN_FUNCTION_CONFIG_SYMBOL = /* @__PURE__ */ Symbol.for("rivetkit.run_function_config");
|
|
13167
|
-
function defineRunHandler(run, options) {
|
|
13168
|
-
if (options.inspectorKind === void 0 !== (options.createInspector === void 0)) {
|
|
13169
|
-
throw new TypeError(
|
|
13170
|
-
"defineRunHandler requires inspectorKind and createInspector together"
|
|
13171
|
-
);
|
|
13172
|
-
}
|
|
13173
|
-
Object.defineProperty(run, RUN_FUNCTION_CONFIG_SYMBOL, {
|
|
13174
|
-
configurable: false,
|
|
13175
|
-
enumerable: false,
|
|
13176
|
-
writable: false,
|
|
13177
|
-
value: {
|
|
13178
|
-
name: options.name,
|
|
13179
|
-
icon: options.icon,
|
|
13180
|
-
inspectorKind: options.inspectorKind,
|
|
13181
|
-
createInspector: options.createInspector
|
|
13182
|
-
}
|
|
13183
|
-
});
|
|
13184
|
-
return run;
|
|
13185
|
-
}
|
|
13186
|
-
function getRunInspectorKind(run) {
|
|
13187
|
-
var _a2;
|
|
13188
|
-
if (!run || typeof run !== "function") return void 0;
|
|
13189
|
-
return (_a2 = run[RUN_FUNCTION_CONFIG_SYMBOL]) == null ? void 0 : _a2.inspectorKind;
|
|
13190
|
-
}
|
|
13191
|
-
function createRunInspector(run, context2) {
|
|
13192
|
-
var _a2, _b;
|
|
13193
|
-
if (!run || typeof run !== "function") return void 0;
|
|
13194
|
-
return (_b = (_a2 = run[RUN_FUNCTION_CONFIG_SYMBOL]) == null ? void 0 : _a2.createInspector) == null ? void 0 : _b.call(_a2, context2);
|
|
13195
|
-
}
|
|
13196
|
-
var zRunHandler = external_exports.union([zFunction(), RunConfigSchema]).optional();
|
|
13197
|
-
function getRunFunction(run) {
|
|
13198
|
-
if (!run) return void 0;
|
|
13199
|
-
if (typeof run === "function") return run;
|
|
13200
|
-
return run.run;
|
|
13201
|
-
}
|
|
13202
|
-
function getRunMetadata(run) {
|
|
13203
|
-
if (!run) return {};
|
|
13204
|
-
if (typeof run === "function") {
|
|
13205
|
-
const config3 = run[RUN_FUNCTION_CONFIG_SYMBOL];
|
|
13206
|
-
if (!config3) return {};
|
|
13207
|
-
return { name: config3.name, icon: config3.icon };
|
|
13208
|
-
}
|
|
13209
|
-
return { name: run.name, icon: run.icon };
|
|
13210
|
-
}
|
|
13211
|
-
function getRunInspectorConfig(run, actor2) {
|
|
13212
|
-
if (!run) return void 0;
|
|
13213
|
-
if (typeof run === "function") {
|
|
13214
|
-
const config3 = run[RUN_FUNCTION_CONFIG_SYMBOL];
|
|
13215
|
-
return (config3 == null ? void 0 : config3.inspectorFactory) ? config3.inspectorFactory(actor2) : config3 == null ? void 0 : config3.inspector;
|
|
13216
|
-
}
|
|
13217
|
-
return run.inspector;
|
|
13218
|
-
}
|
|
13219
|
-
function hasRunInspectorConfig(run) {
|
|
13220
|
-
if (!run) return false;
|
|
13221
|
-
if (typeof run !== "function") return run.inspector !== void 0;
|
|
13222
|
-
const config3 = run[RUN_FUNCTION_CONFIG_SYMBOL];
|
|
13223
|
-
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;
|
|
13224
|
-
}
|
|
13225
|
-
function disposeRunInspector(run, actorId) {
|
|
13226
|
-
var _a2;
|
|
13227
|
-
if (!run || typeof run !== "function") {
|
|
13228
|
-
return;
|
|
13229
|
-
}
|
|
13230
|
-
const config3 = run[RUN_FUNCTION_CONFIG_SYMBOL];
|
|
13231
|
-
(_a2 = config3 == null ? void 0 : config3.disposeInspector) == null ? void 0 : _a2.call(config3, actorId);
|
|
13232
|
-
}
|
|
13233
|
-
var GlobalActorOptionsBaseSchema = external_exports.object({
|
|
13234
|
-
/** Display name for the actor in the Inspector UI. */
|
|
13235
|
-
name: external_exports.string().optional(),
|
|
13236
|
-
/** Icon for the actor in the Inspector UI. Can be an emoji or FontAwesome icon name. */
|
|
13237
|
-
icon: external_exports.string().optional(),
|
|
13238
|
-
/** Enables the experimental Actor Runtime Socket for this actor. */
|
|
13239
|
-
enableActorRuntimeSocket: external_exports.boolean().default(false),
|
|
13240
|
-
/**
|
|
13241
|
-
* Can hibernate WebSockets for onWebSocket.
|
|
13242
|
-
*
|
|
13243
|
-
* WebSockets using actions/events are hibernatable by default.
|
|
13244
|
-
*
|
|
13245
|
-
* @experimental
|
|
13246
|
-
**/
|
|
13247
|
-
canHibernateWebSocket: external_exports.union([external_exports.boolean(), zFunction()]).default(false)
|
|
13248
|
-
}).strict();
|
|
13249
|
-
var GlobalActorOptionsSchema = GlobalActorOptionsBaseSchema.prefault(
|
|
13250
|
-
() => ({})
|
|
13251
|
-
);
|
|
13252
|
-
var InstanceActorOptionsBaseSchema = external_exports.object({
|
|
13253
|
-
createVarsTimeout: external_exports.number().positive().default(5e3),
|
|
13254
|
-
createConnStateTimeout: external_exports.number().positive().default(5e3),
|
|
13255
|
-
onBeforeConnectTimeout: external_exports.number().positive().default(5e3),
|
|
13256
|
-
onConnectTimeout: external_exports.number().positive().default(5e3),
|
|
13257
|
-
onMigrateTimeout: external_exports.number().positive().default(3e4),
|
|
13258
|
-
sleepGracePeriod: external_exports.number().positive().default(DEFAULT_SLEEP_GRACE_PERIOD),
|
|
13259
|
-
/** @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. */
|
|
13260
|
-
onDestroyTimeout: external_exports.number().positive().optional(),
|
|
13261
|
-
/** @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. */
|
|
13262
|
-
waitUntilTimeout: external_exports.number().positive().optional(),
|
|
13263
|
-
stateSaveInterval: external_exports.number().positive().default(1e3),
|
|
13264
|
-
actionTimeout: external_exports.number().positive().default(6e4),
|
|
13265
|
-
connectionLivenessTimeout: external_exports.number().positive().default(2500),
|
|
13266
|
-
connectionLivenessInterval: external_exports.number().positive().default(5e3),
|
|
13267
|
-
/** @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. */
|
|
13268
|
-
noSleep: external_exports.boolean().default(false),
|
|
13269
|
-
sleepTimeout: external_exports.number().positive().default(3e4),
|
|
13270
|
-
maxQueueSize: external_exports.number().positive().default(1e3),
|
|
13271
|
-
/** Maximum pending one-shot and recurring schedules. */
|
|
13272
|
-
maxSchedules: external_exports.number().int().nonnegative().default(1e3),
|
|
13273
|
-
maxQueueMessageSize: external_exports.number().positive().default(64 * 1024),
|
|
13274
|
-
/** @deprecated Internal storage moved to SQLite and no longer uses KV preloading, so this option is ignored. Will be removed in 2.2.0. */
|
|
13275
|
-
preloadMaxWorkflowBytes: external_exports.number().nonnegative().optional(),
|
|
13276
|
-
/** @deprecated Internal storage moved to SQLite and no longer uses KV preloading, so this option is ignored. Will be removed in 2.2.0. */
|
|
13277
|
-
preloadMaxConnectionsBytes: external_exports.number().nonnegative().optional()
|
|
13278
|
-
}).strict();
|
|
13279
|
-
var InstanceActorOptionsSchema = InstanceActorOptionsBaseSchema.prefault(() => ({}));
|
|
13280
|
-
var ActorOptionsSchema = GlobalActorOptionsBaseSchema.extend(
|
|
13281
|
-
InstanceActorOptionsBaseSchema.shape
|
|
13282
|
-
).strict().prefault(() => ({}));
|
|
13283
|
-
var zSampleRate = external_exports.number().min(0).max(1);
|
|
13284
|
-
var zActionSampleRates = external_exports.lazy(
|
|
13285
|
-
() => external_exports.record(external_exports.string(), external_exports.union([zSampleRate, zActionSampleRates]))
|
|
13286
|
-
);
|
|
13287
|
-
var ActorConfigSchema = external_exports.object({
|
|
13288
|
-
onCreate: zFunction().optional(),
|
|
13289
|
-
onDestroy: zFunction().optional(),
|
|
13290
|
-
onMigrate: zFunction().optional(),
|
|
13291
|
-
onWake: zFunction().optional(),
|
|
13292
|
-
onSleep: zFunction().optional(),
|
|
13293
|
-
run: zRunHandler,
|
|
13294
|
-
onStateChange: zFunction().optional(),
|
|
13295
|
-
onBeforeConnect: zFunction().optional(),
|
|
13296
|
-
onConnect: zFunction().optional(),
|
|
13297
|
-
onDisconnect: zFunction().optional(),
|
|
13298
|
-
onBeforeActionResponse: zFunction().optional(),
|
|
13299
|
-
onRequest: zFunction().optional(),
|
|
13300
|
-
onWebSocket: zFunction().optional(),
|
|
13301
|
-
actions: zActionTree.default(() => ({})),
|
|
13302
|
-
actionInputSchemas: external_exports.record(external_exports.string(), external_exports.any()).optional(),
|
|
13303
|
-
tracing: external_exports.object({
|
|
13304
|
-
sampler: zSampleRate.optional(),
|
|
13305
|
-
actions: zActionSampleRates.optional()
|
|
13306
|
-
}).strict().optional(),
|
|
13307
|
-
connParamsSchema: external_exports.any().optional(),
|
|
13308
|
-
events: external_exports.record(external_exports.string(), external_exports.any()).optional(),
|
|
13309
|
-
queues: external_exports.record(external_exports.string(), external_exports.any()).optional(),
|
|
13310
|
-
state: external_exports.any().optional(),
|
|
13311
|
-
createState: zFunction().optional(),
|
|
13312
|
-
connState: external_exports.any().optional(),
|
|
13313
|
-
createConnState: zFunction().optional(),
|
|
13314
|
-
vars: external_exports.any().optional(),
|
|
13315
|
-
db: external_exports.any().optional(),
|
|
13316
|
-
createVars: zFunction().optional(),
|
|
13317
|
-
options: ActorOptionsSchema,
|
|
13318
|
-
inspector: ActorInspectorConfigSchema.optional()
|
|
13319
|
-
}).strict().refine(
|
|
13320
|
-
(data) => !(data.state !== void 0 && data.createState !== void 0),
|
|
13321
|
-
{
|
|
13322
|
-
message: "Cannot define both 'state' and 'createState'",
|
|
13323
|
-
path: ["state"]
|
|
13324
|
-
}
|
|
13325
|
-
).refine(
|
|
13326
|
-
(data) => !(data.connState !== void 0 && data.createConnState !== void 0),
|
|
13327
|
-
{
|
|
13328
|
-
message: "Cannot define both 'connState' and 'createConnState'",
|
|
13329
|
-
path: ["connState"]
|
|
13330
|
-
}
|
|
13331
|
-
).refine(
|
|
13332
|
-
(data) => !(data.vars !== void 0 && data.createVars !== void 0),
|
|
13333
|
-
{
|
|
13334
|
-
message: "Cannot define both 'vars' and 'createVars'",
|
|
13335
|
-
path: ["vars"]
|
|
13336
|
-
}
|
|
13337
|
-
);
|
|
13338
|
-
var DocActorOptionsSchema = external_exports.object({
|
|
13339
|
-
name: external_exports.string().optional().describe("Display name for the actor in the Inspector UI."),
|
|
13340
|
-
icon: external_exports.string().optional().describe(
|
|
13341
|
-
"Icon for the actor in the Inspector UI. Can be an emoji (e.g., '\u{1F680}') or FontAwesome icon name (e.g., 'rocket')."
|
|
13342
|
-
),
|
|
13343
|
-
enableActorRuntimeSocket: external_exports.boolean().optional().describe(
|
|
13344
|
-
"Enables the experimental Actor Runtime Socket for this actor. Default: false"
|
|
13345
|
-
),
|
|
13346
|
-
createVarsTimeout: external_exports.number().optional().describe("Timeout in ms for createVars handler. Default: 5000"),
|
|
13347
|
-
createConnStateTimeout: external_exports.number().optional().describe(
|
|
13348
|
-
"Timeout in ms for createConnState handler. Default: 5000"
|
|
13349
|
-
),
|
|
13350
|
-
onMigrateTimeout: external_exports.number().optional().describe("Timeout in ms for onMigrate handler. Default: 30000"),
|
|
13351
|
-
onBeforeConnectTimeout: external_exports.number().optional().describe(
|
|
13352
|
-
"Timeout in ms for onBeforeConnect handler. Default: 5000"
|
|
13353
|
-
),
|
|
13354
|
-
onConnectTimeout: external_exports.number().optional().describe("Timeout in ms for onConnect handler. Default: 5000"),
|
|
13355
|
-
sleepGracePeriod: external_exports.number().optional().describe(
|
|
13356
|
-
`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}.`
|
|
13357
|
-
),
|
|
13358
|
-
onDestroyTimeout: external_exports.number().optional().describe(
|
|
13359
|
-
"Deprecated. Folded into sleepGracePeriod, which now bounds the entire graceful shutdown window for both sleep and destroy. Will be removed in 2.2.0."
|
|
13360
|
-
),
|
|
13361
|
-
waitUntilTimeout: external_exports.number().optional().describe(
|
|
13362
|
-
"Deprecated. Folded into sleepGracePeriod, which now bounds the entire graceful shutdown window for both sleep and destroy. Will be removed in 2.2.0."
|
|
13363
|
-
),
|
|
13364
|
-
stateSaveInterval: external_exports.number().optional().describe(
|
|
13365
|
-
"Interval in ms between automatic state saves. Default: 1000"
|
|
13366
|
-
),
|
|
13367
|
-
actionTimeout: external_exports.number().optional().describe("Timeout in ms for action handlers. Default: 60000"),
|
|
13368
|
-
connectionLivenessTimeout: external_exports.number().optional().describe(
|
|
13369
|
-
"Timeout in ms for connection liveness checks. Default: 2500"
|
|
13370
|
-
),
|
|
13371
|
-
connectionLivenessInterval: external_exports.number().optional().describe(
|
|
13372
|
-
"Interval in ms between connection liveness checks. Default: 5000"
|
|
13373
|
-
),
|
|
13374
|
-
noSleep: external_exports.boolean().optional().describe(
|
|
13375
|
-
"Deprecated. If true, the actor will never sleep. Use c.keepAwake(promise) to scope keep-awake to a specific operation instead. Default: false"
|
|
13376
|
-
),
|
|
13377
|
-
sleepTimeout: external_exports.number().optional().describe(
|
|
13378
|
-
"Time in ms of inactivity before the actor sleeps. Default: 30000"
|
|
13379
|
-
),
|
|
13380
|
-
maxQueueSize: external_exports.number().optional().describe(
|
|
13381
|
-
"Maximum number of queue messages before rejecting new messages. Default: 1000"
|
|
13382
|
-
),
|
|
13383
|
-
maxSchedules: external_exports.number().int().nonnegative().optional().describe(
|
|
13384
|
-
"Maximum pending one-shot and recurring schedules before rejecting new schedules. Default: 1000"
|
|
13385
|
-
),
|
|
13386
|
-
maxQueueMessageSize: external_exports.number().optional().describe(
|
|
13387
|
-
"Maximum size of each queue message in bytes. Default: 65536"
|
|
13388
|
-
),
|
|
13389
|
-
canHibernateWebSocket: external_exports.boolean().optional().describe(
|
|
13390
|
-
"Whether WebSockets using onWebSocket can be hibernated. WebSockets using actions/events are hibernatable by default. Default: false"
|
|
13391
|
-
)
|
|
13392
|
-
}).describe("Actor options for timeouts and behavior configuration.");
|
|
13393
|
-
var DocActorConfigSchema = external_exports.object({
|
|
13394
|
-
state: external_exports.unknown().optional().describe(
|
|
13395
|
-
"Initial state value for the actor. Cannot be used with createState."
|
|
13396
|
-
),
|
|
13397
|
-
createState: external_exports.unknown().optional().describe(
|
|
13398
|
-
"Function to create initial state. Receives context and input. Cannot be used with state."
|
|
13399
|
-
),
|
|
13400
|
-
connState: external_exports.unknown().optional().describe(
|
|
13401
|
-
"Initial connection state value. Cannot be used with createConnState."
|
|
13402
|
-
),
|
|
13403
|
-
createConnState: external_exports.unknown().optional().describe(
|
|
13404
|
-
"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."
|
|
13405
|
-
),
|
|
13406
|
-
vars: external_exports.unknown().optional().describe(
|
|
13407
|
-
"Initial ephemeral variables value. Cannot be used with createVars."
|
|
13408
|
-
),
|
|
13409
|
-
createVars: external_exports.unknown().optional().describe(
|
|
13410
|
-
"Function to create ephemeral variables. Receives context and driver context. Cannot be used with vars."
|
|
13411
|
-
),
|
|
13412
|
-
db: external_exports.unknown().optional().describe("Database provider instance for the actor."),
|
|
13413
|
-
onCreate: external_exports.unknown().optional().describe(
|
|
13414
|
-
"Called when the actor is first initialized. Use to initialize state."
|
|
13415
|
-
),
|
|
13416
|
-
onDestroy: external_exports.unknown().optional().describe("Called when the actor is destroyed."),
|
|
13417
|
-
onMigrate: external_exports.unknown().optional().describe(
|
|
13418
|
-
"Called on every actor start after persisted state loads and before onWake. Use for repeatable schema migrations."
|
|
13419
|
-
),
|
|
13420
|
-
onWake: external_exports.unknown().optional().describe(
|
|
13421
|
-
"Called when the actor wakes up and is ready to receive connections and actions."
|
|
13422
|
-
),
|
|
13423
|
-
onSleep: external_exports.unknown().optional().describe(
|
|
13424
|
-
"Called when the actor is stopping or sleeping. Use to clean up resources."
|
|
13425
|
-
),
|
|
13426
|
-
run: external_exports.unknown().optional().describe(
|
|
13427
|
-
"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."
|
|
13428
|
-
),
|
|
13429
|
-
onStateChange: external_exports.unknown().optional().describe(
|
|
13430
|
-
"Called when the actor's state changes. State changes within this hook won't trigger recursion."
|
|
13431
|
-
),
|
|
13432
|
-
onBeforeConnect: external_exports.unknown().optional().describe(
|
|
13433
|
-
"Called before a client connects. Throw an error to reject the connection. The pending connection is not visible in c.conns while this runs."
|
|
13434
|
-
),
|
|
13435
|
-
onConnect: external_exports.unknown().optional().describe(
|
|
13436
|
-
"Called when a client successfully connects. The connection is visible in c.conns before this runs."
|
|
13437
|
-
),
|
|
13438
|
-
onDisconnect: external_exports.unknown().optional().describe("Called when a client disconnects."),
|
|
13439
|
-
onBeforeActionResponse: external_exports.unknown().optional().describe(
|
|
13440
|
-
"Called before sending an action response. Use to transform output."
|
|
13441
|
-
),
|
|
13442
|
-
onRequest: external_exports.unknown().optional().describe(
|
|
13443
|
-
"Called for raw HTTP requests to /actors/{name}/http/* endpoints."
|
|
13444
|
-
),
|
|
13445
|
-
onWebSocket: external_exports.unknown().optional().describe(
|
|
13446
|
-
"Called for raw WebSocket connections to /actors/{name}/websocket/* endpoints."
|
|
13447
|
-
),
|
|
13448
|
-
actions: external_exports.record(external_exports.string(), external_exports.unknown()).optional().describe(
|
|
13449
|
-
"Tree of action names or nested groups to handler functions. Nested paths use dot-separated low-level action names. Defaults to an empty object."
|
|
13450
|
-
),
|
|
13451
|
-
actionInputSchemas: external_exports.record(external_exports.string(), external_exports.unknown()).optional().describe(
|
|
13452
|
-
"Optional schemas for validating action argument tuples in native runtimes. May mirror nested action groups or use dot-separated low-level action names."
|
|
13453
|
-
),
|
|
13454
|
-
tracing: external_exports.unknown().optional().describe(
|
|
13455
|
-
"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."
|
|
13456
|
-
),
|
|
13457
|
-
connParamsSchema: external_exports.unknown().optional().describe(
|
|
13458
|
-
"Optional schema for validating connection params in native runtimes."
|
|
13459
|
-
),
|
|
13460
|
-
events: external_exports.record(external_exports.string(), external_exports.unknown()).optional().describe("Map of event names to schemas."),
|
|
13461
|
-
queues: external_exports.record(external_exports.string(), external_exports.unknown()).optional().describe("Map of queue names to schemas."),
|
|
13462
|
-
options: DocActorOptionsSchema.optional()
|
|
13463
|
-
}).describe("Actor configuration passed to the actor() function.");
|
|
13464
|
-
|
|
13465
|
-
// ../rivetkit/dist/tsup/chunk-P2OFXH4G.js
|
|
13466
|
-
var INTERNAL_ERROR_CODE = "internal_error";
|
|
13467
|
-
var INTERNAL_ERROR_DESCRIPTION = "An internal error occurred";
|
|
13468
|
-
var USER_ERROR_CODE = "user_error";
|
|
13469
|
-
var BRIDGE_RIVET_ERROR_PREFIX = "__RIVET_ERROR_JSON__:";
|
|
13470
|
-
function looksLikeRivetErrorOptions(value) {
|
|
13471
|
-
return typeof value === "object" && value !== null && ("public" in value || "metadata" in value || "rayId" in value || "statusCode" in value || "actor" in value || "cause" in value);
|
|
13472
|
-
}
|
|
13473
|
-
function isTypedErrorTag(value) {
|
|
13474
|
-
return value === "ActorError" || value === "RivetError";
|
|
13475
|
-
}
|
|
13476
|
-
function errorMessage(error46, fallback = String(error46)) {
|
|
13477
|
-
if (error46 && typeof error46 === "object" && "message" in error46 && typeof error46.message === "string") {
|
|
13478
|
-
return error46.message;
|
|
13479
|
-
}
|
|
13480
|
-
return fallback;
|
|
13481
|
-
}
|
|
13482
|
-
function isRivetErrorLike(error46) {
|
|
13483
|
-
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));
|
|
13484
|
-
}
|
|
13485
|
-
function isActorAbortedError(error46) {
|
|
13486
|
-
return isRivetErrorLike(error46) && error46.group === "actor" && error46.code === "aborted";
|
|
13487
|
-
}
|
|
13488
|
-
function isActorSpecifier(value) {
|
|
13489
|
-
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");
|
|
13490
|
-
}
|
|
13491
|
-
var RivetError = class extends Error {
|
|
13492
|
-
__type = "RivetError";
|
|
13493
|
-
public;
|
|
13494
|
-
metadata;
|
|
13495
|
-
rayId;
|
|
13496
|
-
statusCode;
|
|
13497
|
-
actor;
|
|
13498
|
-
group;
|
|
13499
|
-
code;
|
|
13500
|
-
static isRivetError(error46) {
|
|
13501
|
-
return isRivetErrorLike(error46);
|
|
13502
|
-
}
|
|
13503
|
-
static isActorError(error46) {
|
|
13504
|
-
return isRivetErrorLike(error46);
|
|
13505
|
-
}
|
|
13506
|
-
constructor(group, code, message, options) {
|
|
13507
|
-
const normalized = looksLikeRivetErrorOptions(options) ? options : { metadata: options };
|
|
13508
|
-
super(message, { cause: normalized.cause });
|
|
13509
|
-
this.name = "RivetError";
|
|
13510
|
-
this.group = group;
|
|
13511
|
-
this.code = code;
|
|
13512
|
-
this.public = normalized.public ?? false;
|
|
13513
|
-
this.metadata = normalized.metadata;
|
|
13514
|
-
this.rayId = normalized.rayId ?? void 0;
|
|
13515
|
-
this.statusCode = normalized.statusCode ?? (this.public ? 400 : 500);
|
|
13516
|
-
this.actor = normalized.actor;
|
|
13517
|
-
}
|
|
13518
|
-
toString() {
|
|
13519
|
-
return this.message;
|
|
13520
|
-
}
|
|
13521
|
-
};
|
|
13522
|
-
var UserError = class extends RivetError {
|
|
13523
|
-
constructor(message, options) {
|
|
13524
|
-
super("user", (options == null ? void 0 : options.code) ?? USER_ERROR_CODE, message, {
|
|
13525
|
-
public: true,
|
|
13526
|
-
metadata: options == null ? void 0 : options.metadata,
|
|
13527
|
-
cause: options == null ? void 0 : options.cause
|
|
13528
|
-
});
|
|
13529
|
-
}
|
|
13530
|
-
};
|
|
13531
|
-
function toRivetError(error46, fallback) {
|
|
13532
|
-
if (typeof error46 === "string") {
|
|
13533
|
-
const bridged = decodeBridgeRivetError(error46);
|
|
13534
|
-
if (bridged) {
|
|
13535
|
-
return bridged;
|
|
13536
|
-
}
|
|
13537
|
-
}
|
|
13538
|
-
if (error46 instanceof Error) {
|
|
13539
|
-
const bridged = decodeBridgeRivetError(error46.message);
|
|
13540
|
-
if (bridged) {
|
|
13541
|
-
return bridged;
|
|
13542
|
-
}
|
|
13543
|
-
}
|
|
13544
|
-
if (isRivetErrorLike(error46)) {
|
|
13545
|
-
return new RivetError(error46.group, error46.code, error46.message, {
|
|
13546
|
-
public: error46.public,
|
|
13547
|
-
statusCode: error46.statusCode,
|
|
13548
|
-
metadata: error46.metadata,
|
|
13549
|
-
rayId: error46.rayId,
|
|
13550
|
-
actor: error46.actor,
|
|
13551
|
-
cause: error46 instanceof Error ? error46.cause : void 0
|
|
13552
|
-
});
|
|
13553
|
-
}
|
|
13554
|
-
return new RivetError(
|
|
13555
|
-
(fallback == null ? void 0 : fallback.group) ?? "actor",
|
|
13556
|
-
(fallback == null ? void 0 : fallback.code) ?? INTERNAL_ERROR_CODE,
|
|
13557
|
-
errorMessage(error46, (fallback == null ? void 0 : fallback.message) ?? "Unknown error"),
|
|
13558
|
-
{
|
|
13559
|
-
public: fallback == null ? void 0 : fallback.public,
|
|
13560
|
-
statusCode: fallback == null ? void 0 : fallback.statusCode,
|
|
13561
|
-
metadata: fallback == null ? void 0 : fallback.metadata,
|
|
13562
|
-
rayId: fallback == null ? void 0 : fallback.rayId,
|
|
13563
|
-
actor: fallback == null ? void 0 : fallback.actor,
|
|
13564
|
-
cause: error46 instanceof Error ? error46 : void 0
|
|
13565
|
-
}
|
|
13566
|
-
);
|
|
13567
|
-
}
|
|
13568
|
-
function encodeBridgeRivetError(error46) {
|
|
13569
|
-
return `${BRIDGE_RIVET_ERROR_PREFIX}${JSON.stringify({
|
|
13570
|
-
group: error46.group,
|
|
13571
|
-
code: error46.code,
|
|
13572
|
-
message: error46.message,
|
|
13573
|
-
metadata: error46.metadata,
|
|
13574
|
-
rayId: error46.rayId,
|
|
13575
|
-
public: error46.public,
|
|
13576
|
-
statusCode: error46.statusCode,
|
|
13577
|
-
actor: error46.actor
|
|
13578
|
-
})}`;
|
|
13579
|
-
}
|
|
13580
|
-
function encodeErrorForBridge(error46) {
|
|
13581
|
-
if (isCanonicalStructuredRivetError(error46)) {
|
|
13582
|
-
return encodeBridgeRivetError(error46);
|
|
13583
|
-
}
|
|
13584
|
-
return String(error46);
|
|
13585
|
-
}
|
|
13586
|
-
function isCanonicalStructuredRivetError(error46) {
|
|
13587
|
-
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";
|
|
13588
|
-
}
|
|
13589
|
-
function decodeBridgeRivetErrorPayload(value) {
|
|
13590
|
-
if (!value.startsWith(BRIDGE_RIVET_ERROR_PREFIX)) {
|
|
13591
|
-
return void 0;
|
|
13592
|
-
}
|
|
13593
|
-
try {
|
|
13594
|
-
const raw = JSON.parse(
|
|
13595
|
-
value.slice(BRIDGE_RIVET_ERROR_PREFIX.length)
|
|
13596
|
-
);
|
|
13597
|
-
const payload = {
|
|
13598
|
-
...raw,
|
|
13599
|
-
rayId: raw.rayId ?? void 0
|
|
13600
|
-
};
|
|
13601
|
-
if (!isRivetErrorLike(payload)) {
|
|
13602
|
-
return void 0;
|
|
13603
|
-
}
|
|
13604
|
-
if (payload.actor !== void 0 && payload.actor !== null && !isActorSpecifier(payload.actor)) {
|
|
13605
|
-
return void 0;
|
|
13606
|
-
}
|
|
13607
|
-
return payload;
|
|
13608
|
-
} catch {
|
|
13609
|
-
return void 0;
|
|
13610
|
-
}
|
|
13611
|
-
}
|
|
13612
|
-
function decodeBridgeRivetError(value) {
|
|
13613
|
-
const payload = decodeBridgeRivetErrorPayload(value);
|
|
13614
|
-
if (!payload) {
|
|
13615
|
-
return void 0;
|
|
13616
|
-
}
|
|
13617
|
-
return new RivetError(payload.group, payload.code, payload.message, {
|
|
13618
|
-
metadata: payload.metadata,
|
|
13619
|
-
rayId: payload.rayId,
|
|
13620
|
-
public: payload.public,
|
|
13621
|
-
statusCode: payload.statusCode,
|
|
13622
|
-
actor: payload.actor ?? void 0
|
|
13623
|
-
});
|
|
13624
|
-
}
|
|
13625
|
-
function invalidRequest(error46) {
|
|
13626
|
-
return new RivetError(
|
|
13627
|
-
"request",
|
|
13628
|
-
"invalid",
|
|
13629
|
-
`Invalid request: ${errorMessage(error46, String(error46))}`,
|
|
13630
|
-
{
|
|
13631
|
-
public: true,
|
|
13632
|
-
cause: error46 instanceof Error ? error46 : void 0
|
|
13633
|
-
}
|
|
13634
|
-
);
|
|
13635
|
-
}
|
|
13636
|
-
function actorNotFound(identifier) {
|
|
13637
|
-
return new RivetError(
|
|
13638
|
-
"actor",
|
|
13639
|
-
"not_found",
|
|
13640
|
-
identifier ? `Actor not found: ${identifier} (https://www.rivet.dev/docs/clients/javascript)` : "Actor not found (https://www.rivet.dev/docs/clients/javascript)",
|
|
13641
|
-
{ public: true }
|
|
13642
|
-
);
|
|
13643
|
-
}
|
|
13644
|
-
function forbiddenError() {
|
|
13645
|
-
return new RivetError("auth", "forbidden", "Forbidden", {
|
|
13646
|
-
public: true,
|
|
13647
|
-
statusCode: 403
|
|
13648
|
-
});
|
|
13649
|
-
}
|
|
13650
|
-
function unsupportedFeature(feature) {
|
|
13651
|
-
return new RivetError(
|
|
13652
|
-
"feature",
|
|
13653
|
-
"unsupported",
|
|
13654
|
-
`Unsupported feature: ${feature}`
|
|
13655
|
-
);
|
|
13656
|
-
}
|
|
13657
|
-
|
|
13658
|
-
// ../rivetkit/dist/tsup/chunk-DHWZTUKA.js
|
|
13659
|
-
import {
|
|
13660
|
-
pino,
|
|
13661
|
-
stdTimeFunctions
|
|
13662
|
-
} from "pino";
|
|
13663
|
-
var import_invariant = __toESM(require_invariant(), 1);
|
|
13664
|
-
import * as cbor from "cbor-x";
|
|
13665
|
-
var getRivetEngine = () => getEnvUniversal("RIVET_ENGINE");
|
|
13666
|
-
var getRivetEndpoint = () => getEnvUniversal("RIVET_ENDPOINT");
|
|
13667
|
-
var getRivetToken = () => getEnvUniversal("RIVET_TOKEN");
|
|
13668
|
-
var getRivetNamespace = () => getEnvUniversal("RIVET_NAMESPACE");
|
|
13669
|
-
var getRivetPool = () => getEnvUniversal("RIVET_POOL");
|
|
13670
|
-
var getRivetTotalSlots = () => {
|
|
13671
|
-
const value = getEnvUniversal("RIVET_TOTAL_SLOTS");
|
|
13672
|
-
return value !== void 0 ? parseInt(value, 10) : void 0;
|
|
13673
|
-
};
|
|
13674
|
-
var getRivetRunEngine = () => getEnvUniversal("RIVET_RUN_ENGINE") === "1";
|
|
13675
|
-
var getRivetRunEngineHost = () => getEnvUniversal("RIVET_RUN_ENGINE_HOST");
|
|
13676
|
-
var getRivetRunEnginePort = () => {
|
|
13677
|
-
const value = getEnvUniversal("RIVET_RUN_ENGINE_PORT");
|
|
13678
|
-
return value !== void 0 ? parseInt(value, 10) : void 0;
|
|
13679
|
-
};
|
|
13680
|
-
var getRivetRunEngineVersion = () => getEnvUniversal("RIVET_RUN_ENGINE_VERSION");
|
|
13681
|
-
var getRivetRunServices = () => {
|
|
13682
|
-
const value = getEnvUniversal("RIVET_RUN_SERVICES");
|
|
13683
|
-
return value === void 0 ? void 0 : value === "1";
|
|
13684
|
-
};
|
|
13685
|
-
var getRivetEnvoyVersion = () => {
|
|
13686
|
-
const value = getEnvUniversal("RIVET_ENVOY_VERSION");
|
|
13687
|
-
return value !== void 0 ? parseInt(value, 10) : void 0;
|
|
13688
|
-
};
|
|
13689
|
-
var getRivetPublicEndpoint = () => getEnvUniversal("RIVET_PUBLIC_ENDPOINT");
|
|
13690
|
-
var getRivetPublicToken = () => getEnvUniversal("RIVET_PUBLIC_TOKEN");
|
|
13691
|
-
var getRivetkitRuntime = () => getEnvUniversal("RIVETKIT_RUNTIME");
|
|
13692
|
-
var getRivetkitRuntimeMode = () => {
|
|
13693
|
-
const value = getEnvUniversal("RIVETKIT_RUNTIME_MODE");
|
|
13694
|
-
if (value === void 0) return "envoy";
|
|
13695
|
-
if (value === "envoy" || value === "serverless") return value;
|
|
13696
|
-
throw new Error(
|
|
13697
|
-
`RIVETKIT_RUNTIME_MODE env var must be "envoy" or "serverless"; got "${value}"`
|
|
13698
|
-
);
|
|
13699
|
-
};
|
|
13700
|
-
var getRivetkitPublicDir = () => {
|
|
13701
|
-
const value = getEnvUniversal("RIVETKIT_PUBLIC_DIR");
|
|
13702
|
-
return value === void 0 || value === "" ? void 0 : value;
|
|
13703
|
-
};
|
|
13704
|
-
function parsePortEnv(raw) {
|
|
13705
|
-
if (raw === void 0 || raw === "") return void 0;
|
|
13706
|
-
const parsed = Number.parseInt(raw, 10);
|
|
13707
|
-
if (!Number.isFinite(parsed) || parsed < 1 || parsed > 65535 || String(parsed) !== raw.trim()) {
|
|
13708
|
-
throw new Error(
|
|
13709
|
-
`RIVET_PORT env var must be an integer between 1 and 65535; got "${raw}"`
|
|
13710
|
-
);
|
|
13711
|
-
}
|
|
13712
|
-
return parsed;
|
|
13713
|
-
}
|
|
13714
|
-
var getLogLevel = () => getEnvUniversal("RIVET_LOG_LEVEL") ?? getEnvUniversal("LOG_LEVEL");
|
|
13715
|
-
var getLogTarget = () => getEnvUniversal("RIVET_LOG_TARGET") === "1";
|
|
13716
|
-
var getLogTimestamp = () => getEnvUniversal("RIVET_LOG_TIMESTAMP") === "1";
|
|
13717
|
-
var getLogMessage = () => getEnvUniversal("RIVET_LOG_MESSAGE") === "1";
|
|
13718
|
-
var getLogErrorStack = () => getEnvUniversal("RIVET_LOG_ERROR_STACK") === "1";
|
|
13719
|
-
var getNodeEnv = () => getEnvUniversal("NODE_ENV");
|
|
13720
|
-
var getNextPhase = () => getEnvUniversal("NEXT_PHASE");
|
|
13721
|
-
var isDev = () => getNodeEnv() !== "production";
|
|
13722
|
-
function assertUnreachable(x) {
|
|
13723
|
-
throw new Error(`Unreachable case: ${x}`);
|
|
13724
|
-
}
|
|
13725
|
-
function deconstructError(error46, exposeInternalError = false) {
|
|
13726
|
-
let statusCode;
|
|
13727
|
-
let public_;
|
|
13728
|
-
let group;
|
|
13729
|
-
let code;
|
|
13730
|
-
let message;
|
|
13731
|
-
let metadata;
|
|
13732
|
-
let rayId;
|
|
13733
|
-
let actor2;
|
|
13734
|
-
if (isCanonicalStructuredRivetError(error46)) {
|
|
13735
|
-
statusCode = typeof error46.statusCode === "number" ? error46.statusCode : error46.public ? 400 : 500;
|
|
13736
|
-
public_ = error46.public ?? false;
|
|
13737
|
-
group = error46.group;
|
|
13738
|
-
code = error46.code;
|
|
13739
|
-
message = error46.message;
|
|
13740
|
-
metadata = error46.metadata;
|
|
13741
|
-
rayId = error46.rayId;
|
|
13742
|
-
actor2 = error46.actor;
|
|
13743
|
-
} else if (RivetError.isActorError(error46) && error46.public) {
|
|
13744
|
-
statusCode = "statusCode" in error46 && error46.statusCode ? error46.statusCode : 400;
|
|
13745
|
-
public_ = true;
|
|
13746
|
-
group = error46.group;
|
|
13747
|
-
code = error46.code;
|
|
13748
|
-
message = getErrorMessage(error46);
|
|
13749
|
-
metadata = error46.metadata;
|
|
13750
|
-
rayId = error46.rayId;
|
|
13751
|
-
actor2 = error46.actor;
|
|
13752
|
-
} else if (exposeInternalError) {
|
|
13753
|
-
if (RivetError.isActorError(error46)) {
|
|
13754
|
-
statusCode = 500;
|
|
13755
|
-
public_ = false;
|
|
13756
|
-
group = error46.group;
|
|
13757
|
-
code = error46.code;
|
|
13758
|
-
message = getErrorMessage(error46);
|
|
13759
|
-
metadata = error46.metadata;
|
|
13760
|
-
rayId = error46.rayId;
|
|
13761
|
-
actor2 = error46.actor;
|
|
13762
|
-
} else {
|
|
13763
|
-
statusCode = 500;
|
|
13764
|
-
public_ = false;
|
|
13765
|
-
group = "rivetkit";
|
|
13766
|
-
code = INTERNAL_ERROR_CODE;
|
|
13767
|
-
message = getErrorMessage(error46);
|
|
13768
|
-
}
|
|
13769
|
-
} else {
|
|
13770
|
-
statusCode = 500;
|
|
13771
|
-
public_ = false;
|
|
13772
|
-
group = "rivetkit";
|
|
13773
|
-
code = INTERNAL_ERROR_CODE;
|
|
13774
|
-
message = INTERNAL_ERROR_DESCRIPTION;
|
|
13775
|
-
if (RivetError.isActorError(error46)) {
|
|
13776
|
-
actor2 = error46.actor;
|
|
13777
|
-
}
|
|
13778
|
-
metadata = {
|
|
13779
|
-
//url: `https://dashboard.rivet.dev/projects/${actorMetadata.project.slug}/environments/${actorMetadata.environment.slug}/actors?actorId=${actorMetadata.actor.id}`,
|
|
13780
|
-
};
|
|
13781
|
-
}
|
|
13782
|
-
return {
|
|
13783
|
-
__type: "ActorError",
|
|
13784
|
-
statusCode,
|
|
13785
|
-
public: public_,
|
|
13786
|
-
group,
|
|
13787
|
-
code,
|
|
13788
|
-
message,
|
|
13789
|
-
metadata,
|
|
13790
|
-
rayId,
|
|
13791
|
-
actor: actor2
|
|
13792
|
-
};
|
|
13793
|
-
}
|
|
13794
|
-
function stringifyError(error46) {
|
|
13795
|
-
if (error46 instanceof Error) {
|
|
13796
|
-
if (typeof process !== "undefined" && getLogErrorStack()) {
|
|
13797
|
-
let stack;
|
|
13798
|
-
try {
|
|
13799
|
-
stack = error46.stack;
|
|
13800
|
-
} catch {
|
|
13801
|
-
stack = void 0;
|
|
13802
|
-
}
|
|
13803
|
-
return `${error46.name}: ${error46.message}${stack ? `
|
|
13804
|
-
${stack}` : ""}`;
|
|
13805
|
-
} else {
|
|
13806
|
-
return `${error46.name}: ${error46.message}`;
|
|
13807
|
-
}
|
|
13808
|
-
} else if (typeof error46 === "string") {
|
|
13809
|
-
return error46;
|
|
13810
|
-
} else if (typeof error46 === "object" && error46 !== null) {
|
|
13811
|
-
try {
|
|
13812
|
-
return `${JSON.stringify(error46)}`;
|
|
13813
|
-
} catch {
|
|
13814
|
-
return "[cannot stringify error]";
|
|
13815
|
-
}
|
|
13816
|
-
} else {
|
|
13817
|
-
return `Unknown error: ${getErrorMessage(error46)}`;
|
|
13818
|
-
}
|
|
13819
|
-
}
|
|
13820
|
-
function getErrorMessage(err) {
|
|
13821
|
-
if (err && typeof err === "object" && "message" in err && typeof err.message === "string") {
|
|
13822
|
-
return err.message;
|
|
13823
|
-
} else {
|
|
13824
|
-
return String(err);
|
|
13825
|
-
}
|
|
13826
|
-
}
|
|
13827
|
-
function noopNext() {
|
|
13828
|
-
return async () => {
|
|
13829
|
-
};
|
|
13344
|
+
function noopNext() {
|
|
13345
|
+
return async () => {
|
|
13346
|
+
};
|
|
13830
13347
|
}
|
|
13831
13348
|
var package_default = {
|
|
13832
13349
|
name: "rivetkit",
|
|
13833
|
-
version: "2.3.
|
|
13350
|
+
version: "2.3.22",
|
|
13834
13351
|
description: "Lightweight libraries for building stateful actors on edge platforms",
|
|
13835
13352
|
license: "Apache-2.0",
|
|
13836
13353
|
keywords: [
|
|
@@ -14043,6 +13560,7 @@ var package_default = {
|
|
|
14043
13560
|
"@rivet-dev/agent-os-core": "^0.1.1",
|
|
14044
13561
|
"@rivet-dev/services": "^0.1.5",
|
|
14045
13562
|
"@rivetkit/bare-ts": "^0.6.2",
|
|
13563
|
+
"@rivetkit/engine-api-full": "workspace:*",
|
|
14046
13564
|
"@rivetkit/engine-cli": "workspace:*",
|
|
14047
13565
|
"@rivetkit/engine-envoy-protocol": "workspace:*",
|
|
14048
13566
|
"@rivetkit/on-change": "6.0.1",
|
|
@@ -15136,7 +14654,7 @@ function Config({ initialBufferLength = 1024, maxBufferLength = 1024 * 1024 * 32
|
|
|
15136
14654
|
};
|
|
15137
14655
|
}
|
|
15138
14656
|
|
|
15139
|
-
// ../rivetkit/dist/tsup/chunk-
|
|
14657
|
+
// ../rivetkit/dist/tsup/chunk-XZBDVEQN.js
|
|
15140
14658
|
var config2 = /* @__PURE__ */ Config({});
|
|
15141
14659
|
function readWorkflowCbor(bc) {
|
|
15142
14660
|
return readData(bc);
|
|
@@ -15415,24 +14933,519 @@ function read6(bc) {
|
|
|
15415
14933
|
}
|
|
15416
14934
|
return result;
|
|
15417
14935
|
}
|
|
15418
|
-
function readWorkflowHistory(bc) {
|
|
15419
|
-
return {
|
|
15420
|
-
nameRegistry: read4(bc),
|
|
15421
|
-
entries: read5(bc),
|
|
15422
|
-
entryMetadata: read6(bc)
|
|
15423
|
-
};
|
|
14936
|
+
function readWorkflowHistory(bc) {
|
|
14937
|
+
return {
|
|
14938
|
+
nameRegistry: read4(bc),
|
|
14939
|
+
entries: read5(bc),
|
|
14940
|
+
entryMetadata: read6(bc)
|
|
14941
|
+
};
|
|
14942
|
+
}
|
|
14943
|
+
function decodeWorkflowHistory(bytes) {
|
|
14944
|
+
const bc = new ByteCursor(bytes, config2);
|
|
14945
|
+
const result = readWorkflowHistory(bc);
|
|
14946
|
+
if (bc.offset < bc.view.byteLength) {
|
|
14947
|
+
throw new BareError(bc.offset, "remaining bytes");
|
|
14948
|
+
}
|
|
14949
|
+
return result;
|
|
14950
|
+
}
|
|
14951
|
+
function decodeWorkflowHistoryTransport(data) {
|
|
14952
|
+
return decodeWorkflowHistory(toUint8Array(data));
|
|
14953
|
+
}
|
|
14954
|
+
|
|
14955
|
+
// ../rivetkit/dist/tsup/chunk-CSOHAAZK.js
|
|
14956
|
+
function flattenActionHandlers(actions) {
|
|
14957
|
+
const flattened = /* @__PURE__ */ Object.create(null);
|
|
14958
|
+
for (const { name, handler } of collectActionEntries(actions)) {
|
|
14959
|
+
flattened[name] = handler;
|
|
14960
|
+
}
|
|
14961
|
+
return flattened;
|
|
14962
|
+
}
|
|
14963
|
+
function flattenActionInputSchemas(actions, schemas) {
|
|
14964
|
+
if (schemas === void 0) return void 0;
|
|
14965
|
+
if (!isRecord(schemas)) {
|
|
14966
|
+
throw new TypeError("actionInputSchemas must be an object");
|
|
14967
|
+
}
|
|
14968
|
+
const flattened = /* @__PURE__ */ Object.create(null);
|
|
14969
|
+
for (const { name, path: path2 } of collectActionEntries(actions)) {
|
|
14970
|
+
const nestedSchema = lookupNestedSchema(schemas, path2);
|
|
14971
|
+
const flatSchema = schemas[name];
|
|
14972
|
+
if (nestedSchema !== void 0 && flatSchema !== void 0 && nestedSchema !== flatSchema) {
|
|
14973
|
+
throw new TypeError(
|
|
14974
|
+
`Action input schema \`${name}\` is defined by both a nested path and a dotted key`
|
|
14975
|
+
);
|
|
14976
|
+
}
|
|
14977
|
+
const schema = nestedSchema ?? flatSchema;
|
|
14978
|
+
if (schema !== void 0) {
|
|
14979
|
+
flattened[name] = schema;
|
|
14980
|
+
}
|
|
14981
|
+
}
|
|
14982
|
+
return flattened;
|
|
14983
|
+
}
|
|
14984
|
+
function flattenActionTraceSamplers(actions, rates = {}) {
|
|
14985
|
+
const handlers = flattenActionHandlers(actions);
|
|
14986
|
+
const flattened = Object.fromEntries(flattenSampleRates(rates, []));
|
|
14987
|
+
for (const name of Object.keys(flattened)) {
|
|
14988
|
+
if (!Object.hasOwn(handlers, name)) {
|
|
14989
|
+
throw new TypeError(
|
|
14990
|
+
`tracing.actions.${name} does not name an action`
|
|
14991
|
+
);
|
|
14992
|
+
}
|
|
14993
|
+
}
|
|
14994
|
+
return flattened;
|
|
14995
|
+
}
|
|
14996
|
+
function flattenSampleRates(rates, path2) {
|
|
14997
|
+
return Object.entries(rates).flatMap(
|
|
14998
|
+
([segment, rate]) => {
|
|
14999
|
+
const childPath = [...path2, segment];
|
|
15000
|
+
return typeof rate === "number" ? [[childPath.join("."), rate]] : flattenSampleRates(rate, childPath);
|
|
15001
|
+
}
|
|
15002
|
+
);
|
|
15003
|
+
}
|
|
15004
|
+
function collectActionEntries(actions) {
|
|
15005
|
+
const entries = [];
|
|
15006
|
+
const names = /* @__PURE__ */ new Set();
|
|
15007
|
+
visitActionGroup(actions ?? {}, [], entries, names);
|
|
15008
|
+
return entries;
|
|
15009
|
+
}
|
|
15010
|
+
function visitActionGroup(value, path2, entries, names) {
|
|
15011
|
+
if (!isRecord(value)) {
|
|
15012
|
+
throw new TypeError(
|
|
15013
|
+
`${formatActionPath(path2)} must be an action handler or group`
|
|
15014
|
+
);
|
|
15015
|
+
}
|
|
15016
|
+
for (const [segment, child] of Object.entries(value)) {
|
|
15017
|
+
const childPath = [...path2, segment];
|
|
15018
|
+
if (typeof child === "function") {
|
|
15019
|
+
const name = childPath.join(".");
|
|
15020
|
+
if (names.has(name)) {
|
|
15021
|
+
throw new TypeError(
|
|
15022
|
+
`Multiple action definitions flatten to \`${name}\``
|
|
15023
|
+
);
|
|
15024
|
+
}
|
|
15025
|
+
names.add(name);
|
|
15026
|
+
entries.push({
|
|
15027
|
+
name,
|
|
15028
|
+
path: childPath,
|
|
15029
|
+
handler: child
|
|
15030
|
+
});
|
|
15031
|
+
} else {
|
|
15032
|
+
visitActionGroup(child, childPath, entries, names);
|
|
15033
|
+
}
|
|
15034
|
+
}
|
|
15035
|
+
}
|
|
15036
|
+
function lookupNestedSchema(schemas, path2) {
|
|
15037
|
+
let value = schemas;
|
|
15038
|
+
for (const segment of path2) {
|
|
15039
|
+
if (!isRecord(value) || !Object.hasOwn(value, segment)) {
|
|
15040
|
+
return void 0;
|
|
15041
|
+
}
|
|
15042
|
+
value = value[segment];
|
|
15043
|
+
}
|
|
15044
|
+
return value;
|
|
15045
|
+
}
|
|
15046
|
+
function isRecord(value) {
|
|
15047
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
15048
|
+
return false;
|
|
15049
|
+
}
|
|
15050
|
+
const prototype = Object.getPrototypeOf(value);
|
|
15051
|
+
return prototype === Object.prototype || prototype === null;
|
|
15052
|
+
}
|
|
15053
|
+
function formatActionPath(path2) {
|
|
15054
|
+
return path2.length === 0 ? "actions" : `Action \`${path2.join(".")}\``;
|
|
15055
|
+
}
|
|
15056
|
+
var DEFAULT_SLEEP_GRACE_PERIOD = 15e3;
|
|
15057
|
+
var ACTOR_CONTEXT_INTERNAL_SYMBOL = /* @__PURE__ */ Symbol(
|
|
15058
|
+
"rivetkit.actor_context_internal"
|
|
15059
|
+
);
|
|
15060
|
+
var RAW_STATE_SYMBOL = /* @__PURE__ */ Symbol("rivetkit.raw_state");
|
|
15061
|
+
var CONN_STATE_MANAGER_SYMBOL = /* @__PURE__ */ Symbol("rivetkit.conn_state_manager");
|
|
15062
|
+
var zFunction = () => external_exports.custom((val) => typeof val === "function");
|
|
15063
|
+
var zActionTree = external_exports.custom((value) => {
|
|
15064
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
15065
|
+
return false;
|
|
15066
|
+
}
|
|
15067
|
+
const prototype = Object.getPrototypeOf(value);
|
|
15068
|
+
return prototype === Object.prototype || prototype === null;
|
|
15069
|
+
}).superRefine((actions, ctx) => {
|
|
15070
|
+
try {
|
|
15071
|
+
flattenActionHandlers(actions);
|
|
15072
|
+
} catch (error46) {
|
|
15073
|
+
ctx.addIssue({
|
|
15074
|
+
code: "custom",
|
|
15075
|
+
message: error46 instanceof Error ? error46.message : "Invalid action definition"
|
|
15076
|
+
});
|
|
15077
|
+
}
|
|
15078
|
+
});
|
|
15079
|
+
var WorkflowInspectorConfigSchema = external_exports.object({
|
|
15080
|
+
getHistory: zFunction(),
|
|
15081
|
+
getState: zFunction().optional(),
|
|
15082
|
+
onHistoryUpdated: zFunction().optional(),
|
|
15083
|
+
replayFromStep: zFunction().optional()
|
|
15084
|
+
});
|
|
15085
|
+
var RunInspectorConfigSchema = external_exports.object({
|
|
15086
|
+
workflow: WorkflowInspectorConfigSchema.optional()
|
|
15087
|
+
}).optional();
|
|
15088
|
+
var BUILTIN_INSPECTOR_TAB_IDS = [
|
|
15089
|
+
"workflow",
|
|
15090
|
+
"database",
|
|
15091
|
+
"state",
|
|
15092
|
+
"queue",
|
|
15093
|
+
"schedules",
|
|
15094
|
+
"connections",
|
|
15095
|
+
"console"
|
|
15096
|
+
];
|
|
15097
|
+
var BuiltinInspectorTabIdSchema = external_exports.enum(BUILTIN_INSPECTOR_TAB_IDS);
|
|
15098
|
+
var CUSTOM_INSPECTOR_TAB_ID_RE = /^[A-Za-z0-9_-]+$/;
|
|
15099
|
+
var CustomInspectorTabEntrySchema = external_exports.object({
|
|
15100
|
+
id: external_exports.string().regex(
|
|
15101
|
+
CUSTOM_INSPECTOR_TAB_ID_RE,
|
|
15102
|
+
"inspector.tabs[].id must contain only letters, digits, underscore, or dash"
|
|
15103
|
+
),
|
|
15104
|
+
label: external_exports.string().min(1),
|
|
15105
|
+
source: external_exports.string().min(1),
|
|
15106
|
+
/**
|
|
15107
|
+
* Optional icon id. The dashboard maps strings to glyphs (see its
|
|
15108
|
+
* icon registry); unknown ids fall back to a generic icon.
|
|
15109
|
+
*/
|
|
15110
|
+
icon: external_exports.string().min(1).optional(),
|
|
15111
|
+
hidden: external_exports.literal(false).optional()
|
|
15112
|
+
}).strict();
|
|
15113
|
+
var HideInspectorTabEntrySchema = external_exports.object({
|
|
15114
|
+
id: BuiltinInspectorTabIdSchema,
|
|
15115
|
+
hidden: external_exports.literal(true)
|
|
15116
|
+
}).strict();
|
|
15117
|
+
var InspectorTabEntrySchema = external_exports.union([
|
|
15118
|
+
CustomInspectorTabEntrySchema,
|
|
15119
|
+
HideInspectorTabEntrySchema
|
|
15120
|
+
]);
|
|
15121
|
+
var ActorInspectorConfigSchema = external_exports.object({
|
|
15122
|
+
tabs: external_exports.array(InspectorTabEntrySchema).default(() => [])
|
|
15123
|
+
}).strict().refine(
|
|
15124
|
+
(data) => {
|
|
15125
|
+
const ids = data.tabs.map((t) => t.id);
|
|
15126
|
+
return new Set(ids).size === ids.length;
|
|
15127
|
+
},
|
|
15128
|
+
{ message: "Duplicate id in inspector.tabs", path: ["tabs"] }
|
|
15129
|
+
).refine(
|
|
15130
|
+
(data) => {
|
|
15131
|
+
const builtinSet = new Set(BUILTIN_INSPECTOR_TAB_IDS);
|
|
15132
|
+
return data.tabs.every(
|
|
15133
|
+
(t) => t.hidden === true || !builtinSet.has(t.id)
|
|
15134
|
+
);
|
|
15135
|
+
},
|
|
15136
|
+
{
|
|
15137
|
+
message: "Custom inspector tab id collides with a built-in (use hidden: true to hide a built-in)",
|
|
15138
|
+
path: ["tabs"]
|
|
15139
|
+
}
|
|
15140
|
+
);
|
|
15141
|
+
var RunConfigSchema = external_exports.object({
|
|
15142
|
+
/** Display name for the actor in the Inspector UI. */
|
|
15143
|
+
name: external_exports.string().optional(),
|
|
15144
|
+
/** Icon for the actor in the Inspector UI. Can be an emoji or FontAwesome icon name. */
|
|
15145
|
+
icon: external_exports.string().optional(),
|
|
15146
|
+
/** The run handler function. */
|
|
15147
|
+
run: zFunction(),
|
|
15148
|
+
/** Inspector integration for long-running run handlers. */
|
|
15149
|
+
inspector: RunInspectorConfigSchema.optional()
|
|
15150
|
+
});
|
|
15151
|
+
var RUN_FUNCTION_CONFIG_SYMBOL = /* @__PURE__ */ Symbol.for("rivetkit.run_function_config");
|
|
15152
|
+
function defineRunHandler(run, options) {
|
|
15153
|
+
if (options.inspectorKind === void 0 !== (options.createInspector === void 0)) {
|
|
15154
|
+
throw new TypeError(
|
|
15155
|
+
"defineRunHandler requires inspectorKind and createInspector together"
|
|
15156
|
+
);
|
|
15157
|
+
}
|
|
15158
|
+
Object.defineProperty(run, RUN_FUNCTION_CONFIG_SYMBOL, {
|
|
15159
|
+
configurable: false,
|
|
15160
|
+
enumerable: false,
|
|
15161
|
+
writable: false,
|
|
15162
|
+
value: {
|
|
15163
|
+
name: options.name,
|
|
15164
|
+
icon: options.icon,
|
|
15165
|
+
inspectorKind: options.inspectorKind,
|
|
15166
|
+
createInspector: options.createInspector
|
|
15167
|
+
}
|
|
15168
|
+
});
|
|
15169
|
+
return run;
|
|
15170
|
+
}
|
|
15171
|
+
function getRunInspectorKind(run) {
|
|
15172
|
+
var _a2;
|
|
15173
|
+
if (!run || typeof run !== "function") return void 0;
|
|
15174
|
+
return (_a2 = run[RUN_FUNCTION_CONFIG_SYMBOL]) == null ? void 0 : _a2.inspectorKind;
|
|
15175
|
+
}
|
|
15176
|
+
function createRunInspector(run, context2) {
|
|
15177
|
+
var _a2, _b;
|
|
15178
|
+
if (!run || typeof run !== "function") return void 0;
|
|
15179
|
+
return (_b = (_a2 = run[RUN_FUNCTION_CONFIG_SYMBOL]) == null ? void 0 : _a2.createInspector) == null ? void 0 : _b.call(_a2, context2);
|
|
15180
|
+
}
|
|
15181
|
+
var zRunHandler = external_exports.union([zFunction(), RunConfigSchema]).optional();
|
|
15182
|
+
function getRunFunction(run) {
|
|
15183
|
+
if (!run) return void 0;
|
|
15184
|
+
if (typeof run === "function") return run;
|
|
15185
|
+
return run.run;
|
|
15186
|
+
}
|
|
15187
|
+
function getRunMetadata(run) {
|
|
15188
|
+
if (!run) return {};
|
|
15189
|
+
if (typeof run === "function") {
|
|
15190
|
+
const config3 = run[RUN_FUNCTION_CONFIG_SYMBOL];
|
|
15191
|
+
if (!config3) return {};
|
|
15192
|
+
return { name: config3.name, icon: config3.icon };
|
|
15193
|
+
}
|
|
15194
|
+
return { name: run.name, icon: run.icon };
|
|
15424
15195
|
}
|
|
15425
|
-
function
|
|
15426
|
-
|
|
15427
|
-
|
|
15428
|
-
|
|
15429
|
-
|
|
15196
|
+
function getRunInspectorConfig(run, actor2) {
|
|
15197
|
+
if (!run) return void 0;
|
|
15198
|
+
if (typeof run === "function") {
|
|
15199
|
+
const config3 = run[RUN_FUNCTION_CONFIG_SYMBOL];
|
|
15200
|
+
return (config3 == null ? void 0 : config3.inspectorFactory) ? config3.inspectorFactory(actor2) : config3 == null ? void 0 : config3.inspector;
|
|
15430
15201
|
}
|
|
15431
|
-
return
|
|
15202
|
+
return run.inspector;
|
|
15432
15203
|
}
|
|
15433
|
-
function
|
|
15434
|
-
|
|
15204
|
+
function hasRunInspectorConfig(run) {
|
|
15205
|
+
if (!run) return false;
|
|
15206
|
+
if (typeof run !== "function") return run.inspector !== void 0;
|
|
15207
|
+
const config3 = run[RUN_FUNCTION_CONFIG_SYMBOL];
|
|
15208
|
+
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;
|
|
15209
|
+
}
|
|
15210
|
+
function disposeRunInspector(run, actorId) {
|
|
15211
|
+
var _a2;
|
|
15212
|
+
if (!run || typeof run !== "function") {
|
|
15213
|
+
return;
|
|
15214
|
+
}
|
|
15215
|
+
const config3 = run[RUN_FUNCTION_CONFIG_SYMBOL];
|
|
15216
|
+
(_a2 = config3 == null ? void 0 : config3.disposeInspector) == null ? void 0 : _a2.call(config3, actorId);
|
|
15435
15217
|
}
|
|
15218
|
+
var GlobalActorOptionsBaseSchema = external_exports.object({
|
|
15219
|
+
/** Display name for the actor in the Inspector UI. */
|
|
15220
|
+
name: external_exports.string().optional(),
|
|
15221
|
+
/** Icon for the actor in the Inspector UI. Can be an emoji or FontAwesome icon name. */
|
|
15222
|
+
icon: external_exports.string().optional(),
|
|
15223
|
+
/** Enables the experimental Actor Runtime Socket for this actor. */
|
|
15224
|
+
enableActorRuntimeSocket: external_exports.boolean().default(false),
|
|
15225
|
+
/**
|
|
15226
|
+
* Can hibernate WebSockets for onWebSocket.
|
|
15227
|
+
*
|
|
15228
|
+
* WebSockets using actions/events are hibernatable by default.
|
|
15229
|
+
*
|
|
15230
|
+
* @experimental
|
|
15231
|
+
**/
|
|
15232
|
+
canHibernateWebSocket: external_exports.union([external_exports.boolean(), zFunction()]).default(false)
|
|
15233
|
+
}).strict();
|
|
15234
|
+
var GlobalActorOptionsSchema = GlobalActorOptionsBaseSchema.prefault(
|
|
15235
|
+
() => ({})
|
|
15236
|
+
);
|
|
15237
|
+
var InstanceActorOptionsBaseSchema = external_exports.object({
|
|
15238
|
+
createVarsTimeout: external_exports.number().positive().default(5e3),
|
|
15239
|
+
createConnStateTimeout: external_exports.number().positive().default(5e3),
|
|
15240
|
+
onBeforeConnectTimeout: external_exports.number().positive().default(5e3),
|
|
15241
|
+
onConnectTimeout: external_exports.number().positive().default(5e3),
|
|
15242
|
+
onMigrateTimeout: external_exports.number().positive().default(3e4),
|
|
15243
|
+
sleepGracePeriod: external_exports.number().positive().default(DEFAULT_SLEEP_GRACE_PERIOD),
|
|
15244
|
+
/** @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. */
|
|
15245
|
+
onDestroyTimeout: external_exports.number().positive().optional(),
|
|
15246
|
+
/** @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. */
|
|
15247
|
+
waitUntilTimeout: external_exports.number().positive().optional(),
|
|
15248
|
+
stateSaveInterval: external_exports.number().positive().default(1e3),
|
|
15249
|
+
actionTimeout: external_exports.number().positive().default(6e4),
|
|
15250
|
+
connectionLivenessTimeout: external_exports.number().positive().default(2500),
|
|
15251
|
+
connectionLivenessInterval: external_exports.number().positive().default(5e3),
|
|
15252
|
+
/** @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. */
|
|
15253
|
+
noSleep: external_exports.boolean().default(false),
|
|
15254
|
+
sleepTimeout: external_exports.number().positive().default(3e4),
|
|
15255
|
+
maxQueueSize: external_exports.number().positive().default(1e3),
|
|
15256
|
+
/** Maximum pending one-shot and recurring schedules. */
|
|
15257
|
+
maxSchedules: external_exports.number().int().nonnegative().default(1e3),
|
|
15258
|
+
maxQueueMessageSize: external_exports.number().positive().default(64 * 1024),
|
|
15259
|
+
/** @deprecated Internal storage moved to SQLite and no longer uses KV preloading, so this option is ignored. Will be removed in 2.2.0. */
|
|
15260
|
+
preloadMaxWorkflowBytes: external_exports.number().nonnegative().optional(),
|
|
15261
|
+
/** @deprecated Internal storage moved to SQLite and no longer uses KV preloading, so this option is ignored. Will be removed in 2.2.0. */
|
|
15262
|
+
preloadMaxConnectionsBytes: external_exports.number().nonnegative().optional()
|
|
15263
|
+
}).strict();
|
|
15264
|
+
var InstanceActorOptionsSchema = InstanceActorOptionsBaseSchema.prefault(() => ({}));
|
|
15265
|
+
var ActorOptionsSchema = GlobalActorOptionsBaseSchema.extend(
|
|
15266
|
+
InstanceActorOptionsBaseSchema.shape
|
|
15267
|
+
).strict().prefault(() => ({}));
|
|
15268
|
+
var zSampleRate = external_exports.number().min(0).max(1);
|
|
15269
|
+
var zActionSampleRates = external_exports.lazy(
|
|
15270
|
+
() => external_exports.record(external_exports.string(), external_exports.union([zSampleRate, zActionSampleRates]))
|
|
15271
|
+
);
|
|
15272
|
+
var ActorConfigSchema = external_exports.object({
|
|
15273
|
+
onCreate: zFunction().optional(),
|
|
15274
|
+
onDestroy: zFunction().optional(),
|
|
15275
|
+
onMigrate: zFunction().optional(),
|
|
15276
|
+
onWake: zFunction().optional(),
|
|
15277
|
+
onSleep: zFunction().optional(),
|
|
15278
|
+
run: zRunHandler,
|
|
15279
|
+
onStateChange: zFunction().optional(),
|
|
15280
|
+
onBeforeConnect: zFunction().optional(),
|
|
15281
|
+
onConnect: zFunction().optional(),
|
|
15282
|
+
onDisconnect: zFunction().optional(),
|
|
15283
|
+
onBeforeActionResponse: zFunction().optional(),
|
|
15284
|
+
onRequest: zFunction().optional(),
|
|
15285
|
+
onWebSocket: zFunction().optional(),
|
|
15286
|
+
actions: zActionTree.default(() => ({})),
|
|
15287
|
+
actionInputSchemas: external_exports.record(external_exports.string(), external_exports.any()).optional(),
|
|
15288
|
+
tracing: external_exports.object({
|
|
15289
|
+
sampler: zSampleRate.optional(),
|
|
15290
|
+
actions: zActionSampleRates.optional()
|
|
15291
|
+
}).strict().optional(),
|
|
15292
|
+
connParamsSchema: external_exports.any().optional(),
|
|
15293
|
+
events: external_exports.record(external_exports.string(), external_exports.any()).optional(),
|
|
15294
|
+
queues: external_exports.record(external_exports.string(), external_exports.any()).optional(),
|
|
15295
|
+
state: external_exports.any().optional(),
|
|
15296
|
+
createState: zFunction().optional(),
|
|
15297
|
+
connState: external_exports.any().optional(),
|
|
15298
|
+
createConnState: zFunction().optional(),
|
|
15299
|
+
vars: external_exports.any().optional(),
|
|
15300
|
+
db: external_exports.any().optional(),
|
|
15301
|
+
createVars: zFunction().optional(),
|
|
15302
|
+
options: ActorOptionsSchema,
|
|
15303
|
+
inspector: ActorInspectorConfigSchema.optional()
|
|
15304
|
+
}).strict().refine(
|
|
15305
|
+
(data) => !(data.state !== void 0 && data.createState !== void 0),
|
|
15306
|
+
{
|
|
15307
|
+
message: "Cannot define both 'state' and 'createState'",
|
|
15308
|
+
path: ["state"]
|
|
15309
|
+
}
|
|
15310
|
+
).refine(
|
|
15311
|
+
(data) => !(data.connState !== void 0 && data.createConnState !== void 0),
|
|
15312
|
+
{
|
|
15313
|
+
message: "Cannot define both 'connState' and 'createConnState'",
|
|
15314
|
+
path: ["connState"]
|
|
15315
|
+
}
|
|
15316
|
+
).refine(
|
|
15317
|
+
(data) => !(data.vars !== void 0 && data.createVars !== void 0),
|
|
15318
|
+
{
|
|
15319
|
+
message: "Cannot define both 'vars' and 'createVars'",
|
|
15320
|
+
path: ["vars"]
|
|
15321
|
+
}
|
|
15322
|
+
);
|
|
15323
|
+
var DocActorOptionsSchema = external_exports.object({
|
|
15324
|
+
name: external_exports.string().optional().describe("Display name for the actor in the Inspector UI."),
|
|
15325
|
+
icon: external_exports.string().optional().describe(
|
|
15326
|
+
"Icon for the actor in the Inspector UI. Can be an emoji (e.g., '\u{1F680}') or FontAwesome icon name (e.g., 'rocket')."
|
|
15327
|
+
),
|
|
15328
|
+
enableActorRuntimeSocket: external_exports.boolean().optional().describe(
|
|
15329
|
+
"Enables the experimental Actor Runtime Socket for this actor. Default: false"
|
|
15330
|
+
),
|
|
15331
|
+
createVarsTimeout: external_exports.number().optional().describe("Timeout in ms for createVars handler. Default: 5000"),
|
|
15332
|
+
createConnStateTimeout: external_exports.number().optional().describe(
|
|
15333
|
+
"Timeout in ms for createConnState handler. Default: 5000"
|
|
15334
|
+
),
|
|
15335
|
+
onMigrateTimeout: external_exports.number().optional().describe("Timeout in ms for onMigrate handler. Default: 30000"),
|
|
15336
|
+
onBeforeConnectTimeout: external_exports.number().optional().describe(
|
|
15337
|
+
"Timeout in ms for onBeforeConnect handler. Default: 5000"
|
|
15338
|
+
),
|
|
15339
|
+
onConnectTimeout: external_exports.number().optional().describe("Timeout in ms for onConnect handler. Default: 5000"),
|
|
15340
|
+
sleepGracePeriod: external_exports.number().optional().describe(
|
|
15341
|
+
`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}.`
|
|
15342
|
+
),
|
|
15343
|
+
onDestroyTimeout: external_exports.number().optional().describe(
|
|
15344
|
+
"Deprecated. Folded into sleepGracePeriod, which now bounds the entire graceful shutdown window for both sleep and destroy. Will be removed in 2.2.0."
|
|
15345
|
+
),
|
|
15346
|
+
waitUntilTimeout: external_exports.number().optional().describe(
|
|
15347
|
+
"Deprecated. Folded into sleepGracePeriod, which now bounds the entire graceful shutdown window for both sleep and destroy. Will be removed in 2.2.0."
|
|
15348
|
+
),
|
|
15349
|
+
stateSaveInterval: external_exports.number().optional().describe(
|
|
15350
|
+
"Interval in ms between automatic state saves. Default: 1000"
|
|
15351
|
+
),
|
|
15352
|
+
actionTimeout: external_exports.number().optional().describe("Timeout in ms for action handlers. Default: 60000"),
|
|
15353
|
+
connectionLivenessTimeout: external_exports.number().optional().describe(
|
|
15354
|
+
"Timeout in ms for connection liveness checks. Default: 2500"
|
|
15355
|
+
),
|
|
15356
|
+
connectionLivenessInterval: external_exports.number().optional().describe(
|
|
15357
|
+
"Interval in ms between connection liveness checks. Default: 5000"
|
|
15358
|
+
),
|
|
15359
|
+
noSleep: external_exports.boolean().optional().describe(
|
|
15360
|
+
"Deprecated. If true, the actor will never sleep. Use c.keepAwake(promise) to scope keep-awake to a specific operation instead. Default: false"
|
|
15361
|
+
),
|
|
15362
|
+
sleepTimeout: external_exports.number().optional().describe(
|
|
15363
|
+
"Time in ms of inactivity before the actor sleeps. Default: 30000"
|
|
15364
|
+
),
|
|
15365
|
+
maxQueueSize: external_exports.number().optional().describe(
|
|
15366
|
+
"Maximum number of queue messages before rejecting new messages. Default: 1000"
|
|
15367
|
+
),
|
|
15368
|
+
maxSchedules: external_exports.number().int().nonnegative().optional().describe(
|
|
15369
|
+
"Maximum pending one-shot and recurring schedules before rejecting new schedules. Default: 1000"
|
|
15370
|
+
),
|
|
15371
|
+
maxQueueMessageSize: external_exports.number().optional().describe(
|
|
15372
|
+
"Maximum size of each queue message in bytes. Default: 65536"
|
|
15373
|
+
),
|
|
15374
|
+
canHibernateWebSocket: external_exports.boolean().optional().describe(
|
|
15375
|
+
"Whether WebSockets using onWebSocket can be hibernated. WebSockets using actions/events are hibernatable by default. Default: false"
|
|
15376
|
+
)
|
|
15377
|
+
}).describe("Actor options for timeouts and behavior configuration.");
|
|
15378
|
+
var DocActorConfigSchema = external_exports.object({
|
|
15379
|
+
state: external_exports.unknown().optional().describe(
|
|
15380
|
+
"Initial state value for the actor. Cannot be used with createState."
|
|
15381
|
+
),
|
|
15382
|
+
createState: external_exports.unknown().optional().describe(
|
|
15383
|
+
"Function to create initial state. Receives context and input. Cannot be used with state."
|
|
15384
|
+
),
|
|
15385
|
+
connState: external_exports.unknown().optional().describe(
|
|
15386
|
+
"Initial connection state value. Cannot be used with createConnState."
|
|
15387
|
+
),
|
|
15388
|
+
createConnState: external_exports.unknown().optional().describe(
|
|
15389
|
+
"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."
|
|
15390
|
+
),
|
|
15391
|
+
vars: external_exports.unknown().optional().describe(
|
|
15392
|
+
"Initial ephemeral variables value. Cannot be used with createVars."
|
|
15393
|
+
),
|
|
15394
|
+
createVars: external_exports.unknown().optional().describe(
|
|
15395
|
+
"Function to create ephemeral variables. Receives context and driver context. Cannot be used with vars."
|
|
15396
|
+
),
|
|
15397
|
+
db: external_exports.unknown().optional().describe("Database provider instance for the actor."),
|
|
15398
|
+
onCreate: external_exports.unknown().optional().describe(
|
|
15399
|
+
"Called when the actor is first initialized. Use to initialize state."
|
|
15400
|
+
),
|
|
15401
|
+
onDestroy: external_exports.unknown().optional().describe("Called when the actor is destroyed."),
|
|
15402
|
+
onMigrate: external_exports.unknown().optional().describe(
|
|
15403
|
+
"Called on every actor start after persisted state loads and before onWake. Use for repeatable schema migrations."
|
|
15404
|
+
),
|
|
15405
|
+
onWake: external_exports.unknown().optional().describe(
|
|
15406
|
+
"Called when the actor wakes up and is ready to receive connections and actions."
|
|
15407
|
+
),
|
|
15408
|
+
onSleep: external_exports.unknown().optional().describe(
|
|
15409
|
+
"Called when the actor is stopping or sleeping. Use to clean up resources."
|
|
15410
|
+
),
|
|
15411
|
+
run: external_exports.unknown().optional().describe(
|
|
15412
|
+
"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."
|
|
15413
|
+
),
|
|
15414
|
+
onStateChange: external_exports.unknown().optional().describe(
|
|
15415
|
+
"Called when the actor's state changes. State changes within this hook won't trigger recursion."
|
|
15416
|
+
),
|
|
15417
|
+
onBeforeConnect: external_exports.unknown().optional().describe(
|
|
15418
|
+
"Called before a client connects. Throw an error to reject the connection. The pending connection is not visible in c.conns while this runs."
|
|
15419
|
+
),
|
|
15420
|
+
onConnect: external_exports.unknown().optional().describe(
|
|
15421
|
+
"Called when a client successfully connects. The connection is visible in c.conns before this runs."
|
|
15422
|
+
),
|
|
15423
|
+
onDisconnect: external_exports.unknown().optional().describe("Called when a client disconnects."),
|
|
15424
|
+
onBeforeActionResponse: external_exports.unknown().optional().describe(
|
|
15425
|
+
"Called before sending an action response. Use to transform output."
|
|
15426
|
+
),
|
|
15427
|
+
onRequest: external_exports.unknown().optional().describe(
|
|
15428
|
+
"Called for raw HTTP requests to /actors/{name}/http/* endpoints."
|
|
15429
|
+
),
|
|
15430
|
+
onWebSocket: external_exports.unknown().optional().describe(
|
|
15431
|
+
"Called for raw WebSocket connections to /actors/{name}/websocket/* endpoints."
|
|
15432
|
+
),
|
|
15433
|
+
actions: external_exports.record(external_exports.string(), external_exports.unknown()).optional().describe(
|
|
15434
|
+
"Tree of action names or nested groups to handler functions. Nested paths use dot-separated low-level action names. Defaults to an empty object."
|
|
15435
|
+
),
|
|
15436
|
+
actionInputSchemas: external_exports.record(external_exports.string(), external_exports.unknown()).optional().describe(
|
|
15437
|
+
"Optional schemas for validating action argument tuples in native runtimes. May mirror nested action groups or use dot-separated low-level action names."
|
|
15438
|
+
),
|
|
15439
|
+
tracing: external_exports.unknown().optional().describe(
|
|
15440
|
+
"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."
|
|
15441
|
+
),
|
|
15442
|
+
connParamsSchema: external_exports.unknown().optional().describe(
|
|
15443
|
+
"Optional schema for validating connection params in native runtimes."
|
|
15444
|
+
),
|
|
15445
|
+
events: external_exports.record(external_exports.string(), external_exports.unknown()).optional().describe("Map of event names to schemas."),
|
|
15446
|
+
queues: external_exports.record(external_exports.string(), external_exports.unknown()).optional().describe("Map of queue names to schemas."),
|
|
15447
|
+
options: DocActorOptionsSchema.optional()
|
|
15448
|
+
}).describe("Actor configuration passed to the actor() function.");
|
|
15436
15449
|
|
|
15437
15450
|
// ../rivetkit/dist/tsup/chunk-JI6GZ2C2.js
|
|
15438
15451
|
var EMPTY_KEY = "/";
|
|
@@ -15551,44 +15564,6 @@ function removePrefixFromKey(prefixedKey) {
|
|
|
15551
15564
|
return prefixedKey.slice(KEYS.KV.length);
|
|
15552
15565
|
}
|
|
15553
15566
|
|
|
15554
|
-
// ../rivetkit/dist/tsup/chunk-553CIQJY.js
|
|
15555
|
-
function logger() {
|
|
15556
|
-
return getLogger("actor-client");
|
|
15557
|
-
}
|
|
15558
|
-
var webSocketPromise = null;
|
|
15559
|
-
async function importWebSocket() {
|
|
15560
|
-
if (webSocketPromise !== null) {
|
|
15561
|
-
return webSocketPromise;
|
|
15562
|
-
}
|
|
15563
|
-
webSocketPromise = (async () => {
|
|
15564
|
-
let _WebSocket;
|
|
15565
|
-
if (typeof WebSocket !== "undefined") {
|
|
15566
|
-
_WebSocket = WebSocket;
|
|
15567
|
-
} else {
|
|
15568
|
-
try {
|
|
15569
|
-
const moduleName = "ws";
|
|
15570
|
-
const ws = await import(
|
|
15571
|
-
/* webpackIgnore: true */
|
|
15572
|
-
moduleName
|
|
15573
|
-
);
|
|
15574
|
-
_WebSocket = ws.default;
|
|
15575
|
-
logger().debug("using websocket from npm");
|
|
15576
|
-
} catch {
|
|
15577
|
-
_WebSocket = class MockWebSocket {
|
|
15578
|
-
constructor() {
|
|
15579
|
-
throw new Error(
|
|
15580
|
-
'WebSocket support requires installing the "ws" peer dependency.'
|
|
15581
|
-
);
|
|
15582
|
-
}
|
|
15583
|
-
};
|
|
15584
|
-
logger().debug("using mock websocket");
|
|
15585
|
-
}
|
|
15586
|
-
}
|
|
15587
|
-
return _WebSocket;
|
|
15588
|
-
})();
|
|
15589
|
-
return webSocketPromise;
|
|
15590
|
-
}
|
|
15591
|
-
|
|
15592
15567
|
// ../rivetkit/dist/tsup/chunk-JTHHCZCZ.js
|
|
15593
15568
|
var MIGRATION_TRANSACTION_TIMEOUT_MS = 5 * 6e4;
|
|
15594
15569
|
function isManualTransactionControl(query) {
|
|
@@ -15672,7 +15647,45 @@ var AsyncMutex = class {
|
|
|
15672
15647
|
}
|
|
15673
15648
|
};
|
|
15674
15649
|
|
|
15675
|
-
// ../rivetkit/dist/tsup/chunk-
|
|
15650
|
+
// ../rivetkit/dist/tsup/chunk-47FSGXYN.js
|
|
15651
|
+
function logger() {
|
|
15652
|
+
return getLogger("actor-client");
|
|
15653
|
+
}
|
|
15654
|
+
var webSocketPromise = null;
|
|
15655
|
+
async function importWebSocket() {
|
|
15656
|
+
if (webSocketPromise !== null) {
|
|
15657
|
+
return webSocketPromise;
|
|
15658
|
+
}
|
|
15659
|
+
webSocketPromise = (async () => {
|
|
15660
|
+
let _WebSocket;
|
|
15661
|
+
if (typeof WebSocket !== "undefined") {
|
|
15662
|
+
_WebSocket = WebSocket;
|
|
15663
|
+
} else {
|
|
15664
|
+
try {
|
|
15665
|
+
const moduleName = "ws";
|
|
15666
|
+
const ws = await import(
|
|
15667
|
+
/* webpackIgnore: true */
|
|
15668
|
+
moduleName
|
|
15669
|
+
);
|
|
15670
|
+
_WebSocket = ws.default;
|
|
15671
|
+
logger().debug("using websocket from npm");
|
|
15672
|
+
} catch {
|
|
15673
|
+
_WebSocket = class MockWebSocket {
|
|
15674
|
+
constructor() {
|
|
15675
|
+
throw new Error(
|
|
15676
|
+
'WebSocket support requires installing the "ws" peer dependency.'
|
|
15677
|
+
);
|
|
15678
|
+
}
|
|
15679
|
+
};
|
|
15680
|
+
logger().debug("using mock websocket");
|
|
15681
|
+
}
|
|
15682
|
+
}
|
|
15683
|
+
return _WebSocket;
|
|
15684
|
+
})();
|
|
15685
|
+
return webSocketPromise;
|
|
15686
|
+
}
|
|
15687
|
+
|
|
15688
|
+
// ../rivetkit/dist/tsup/chunk-VD47X7KQ.js
|
|
15676
15689
|
var import_invariant2 = __toESM(require_invariant(), 1);
|
|
15677
15690
|
|
|
15678
15691
|
// ../../../node_modules/.pnpm/p-retry@6.2.1/node_modules/p-retry/index.js
|
|
@@ -16887,7 +16900,7 @@ var TraceAPI = (
|
|
|
16887
16900
|
// ../../../node_modules/.pnpm/@opentelemetry+api@1.9.0/node_modules/@opentelemetry/api/build/esm/trace-api.js
|
|
16888
16901
|
var trace = TraceAPI.getInstance();
|
|
16889
16902
|
|
|
16890
|
-
// ../rivetkit/dist/tsup/chunk-
|
|
16903
|
+
// ../rivetkit/dist/tsup/chunk-VD47X7KQ.js
|
|
16891
16904
|
var import_invariant3 = __toESM(require_invariant(), 1);
|
|
16892
16905
|
var import_invariant4 = __toESM(require_invariant(), 1);
|
|
16893
16906
|
var PATH_CONNECT = "/connect";
|
|
@@ -19361,7 +19374,8 @@ async function sendHttpRequest(opts) {
|
|
|
19361
19374
|
{
|
|
19362
19375
|
metadata: responseData.metadata,
|
|
19363
19376
|
rayId: rayId ?? void 0,
|
|
19364
|
-
actor: responseData.actor
|
|
19377
|
+
actor: responseData.actor,
|
|
19378
|
+
statusCode: response.status
|
|
19365
19379
|
}
|
|
19366
19380
|
);
|
|
19367
19381
|
} catch (error46) {
|
|
@@ -20269,6 +20283,22 @@ var ActorHandleRaw = class {
|
|
|
20269
20283
|
"dynamic actor resolution did not produce a direct actor id"
|
|
20270
20284
|
);
|
|
20271
20285
|
}
|
|
20286
|
+
/** Issue a token scoped to this actor. Defaults to actor gateway read access. */
|
|
20287
|
+
async issueToken(options = {}) {
|
|
20288
|
+
const actorId = await this.resolve();
|
|
20289
|
+
const permissions = options.permissions ?? {
|
|
20290
|
+
actor_gateway: ["read"]
|
|
20291
|
+
};
|
|
20292
|
+
const grants = Object.keys(permissions).flatMap((resource) => {
|
|
20293
|
+
const operations = permissions[resource];
|
|
20294
|
+
return operations ? [{ resource, target: { id: actorId }, operations }] : [];
|
|
20295
|
+
});
|
|
20296
|
+
return this.#driver.issueToken({
|
|
20297
|
+
subject: options.subject,
|
|
20298
|
+
expiresIn: options.expiresIn,
|
|
20299
|
+
grants
|
|
20300
|
+
});
|
|
20301
|
+
}
|
|
20272
20302
|
/**
|
|
20273
20303
|
* Returns the raw URL for routing traffic to the actor.
|
|
20274
20304
|
*/
|
|
@@ -20301,6 +20331,8 @@ var ACTOR_CONNS_SYMBOL = /* @__PURE__ */ Symbol("actorConns");
|
|
|
20301
20331
|
var CREATE_ACTOR_CONN_PROXY = /* @__PURE__ */ Symbol("createActorConnProxy");
|
|
20302
20332
|
var ClientRaw = class {
|
|
20303
20333
|
#disposed = false;
|
|
20334
|
+
/** Issue namespace-scoped tokens with an explicit grant list. */
|
|
20335
|
+
auth;
|
|
20304
20336
|
[ACTOR_CONNS_SYMBOL] = /* @__PURE__ */ new Set();
|
|
20305
20337
|
#driver;
|
|
20306
20338
|
#encodingKind;
|
|
@@ -20312,6 +20344,9 @@ var ClientRaw = class {
|
|
|
20312
20344
|
*/
|
|
20313
20345
|
constructor(driver, options = {}) {
|
|
20314
20346
|
this.#driver = driver;
|
|
20347
|
+
this.auth = {
|
|
20348
|
+
issueToken: (issueOptions) => this.#driver.issueToken(issueOptions)
|
|
20349
|
+
};
|
|
20315
20350
|
this.#encodingKind = options.encoding ?? "bare";
|
|
20316
20351
|
this.#gatewayOptions = options.gateway ?? {};
|
|
20317
20352
|
this.#currentActorInvocation = options.currentActorInvocation;
|
|
@@ -20603,6 +20638,72 @@ function createActorProxy(handle) {
|
|
|
20603
20638
|
}
|
|
20604
20639
|
});
|
|
20605
20640
|
}
|
|
20641
|
+
function isInvalidToken(group, code) {
|
|
20642
|
+
return group === "auth" && (code === "invalid_token" || code === "token_expired");
|
|
20643
|
+
}
|
|
20644
|
+
function isInvalidTokenResponse(response) {
|
|
20645
|
+
if (response.status !== 401) return false;
|
|
20646
|
+
const error46 = response.headers.get("x-rivet-error");
|
|
20647
|
+
if (!error46) return false;
|
|
20648
|
+
const separator = error46.indexOf(".");
|
|
20649
|
+
return separator > 0 && isInvalidToken(error46.slice(0, separator), error46.slice(separator + 1));
|
|
20650
|
+
}
|
|
20651
|
+
var TokenProvider = class {
|
|
20652
|
+
constructor(getToken) {
|
|
20653
|
+
this.getToken = getToken;
|
|
20654
|
+
}
|
|
20655
|
+
#cached;
|
|
20656
|
+
#pending;
|
|
20657
|
+
#pendingForce = false;
|
|
20658
|
+
async current() {
|
|
20659
|
+
if (this.#cached && (this.#cached.expiresAt === void 0 || Date.now() < this.#cached.expiresAt - 5e3)) {
|
|
20660
|
+
return this.#cached.token;
|
|
20661
|
+
}
|
|
20662
|
+
return this.#load(false);
|
|
20663
|
+
}
|
|
20664
|
+
/** A late rejection for an older token must never erase a newer credential. */
|
|
20665
|
+
async refreshIfCurrent(failedToken) {
|
|
20666
|
+
var _a2;
|
|
20667
|
+
if (this.#pending !== void 0) {
|
|
20668
|
+
const wasForced = this.#pendingForce;
|
|
20669
|
+
const refreshed = await this.#pending;
|
|
20670
|
+
if (wasForced || refreshed !== failedToken) return refreshed;
|
|
20671
|
+
}
|
|
20672
|
+
if (((_a2 = this.#cached) == null ? void 0 : _a2.token) !== failedToken) {
|
|
20673
|
+
return this.current();
|
|
20674
|
+
}
|
|
20675
|
+
return this.#load(true);
|
|
20676
|
+
}
|
|
20677
|
+
#load(forceRefresh) {
|
|
20678
|
+
if (this.#pending !== void 0) return this.#pending;
|
|
20679
|
+
const pending = Promise.resolve().then(() => this.getToken({ forceRefresh })).then((token) => {
|
|
20680
|
+
if (typeof token !== "string" || token.length === 0) {
|
|
20681
|
+
throw new Error(
|
|
20682
|
+
"getToken must resolve to a nonempty string"
|
|
20683
|
+
);
|
|
20684
|
+
}
|
|
20685
|
+
this.#cached = { token, expiresAt: jwtExpiration(token) };
|
|
20686
|
+
return token;
|
|
20687
|
+
}).finally(() => {
|
|
20688
|
+
if (this.#pending === pending) this.#pending = void 0;
|
|
20689
|
+
});
|
|
20690
|
+
this.#pending = pending;
|
|
20691
|
+
this.#pendingForce = forceRefresh;
|
|
20692
|
+
return pending;
|
|
20693
|
+
}
|
|
20694
|
+
};
|
|
20695
|
+
function jwtExpiration(token) {
|
|
20696
|
+
try {
|
|
20697
|
+
const payload = token.split(".")[1];
|
|
20698
|
+
if (!payload) return void 0;
|
|
20699
|
+
const claims = JSON.parse(
|
|
20700
|
+
atob(payload.replace(/-/g, "+").replace(/_/g, "/"))
|
|
20701
|
+
);
|
|
20702
|
+
return typeof claims.exp === "number" && Number.isSafeInteger(claims.exp) ? claims.exp * 1e3 : void 0;
|
|
20703
|
+
} catch {
|
|
20704
|
+
return void 0;
|
|
20705
|
+
}
|
|
20706
|
+
}
|
|
20606
20707
|
var CONNECT_SYMBOL = /* @__PURE__ */ Symbol("connect");
|
|
20607
20708
|
var ActorConnRaw = class {
|
|
20608
20709
|
#disposed = false;
|
|
@@ -20631,6 +20732,7 @@ var ActorConnRaw = class {
|
|
|
20631
20732
|
/** Promise used to indicate the socket has connected successfully. This will be rejected if the connection fails. */
|
|
20632
20733
|
#onOpenPromise;
|
|
20633
20734
|
#websocket;
|
|
20735
|
+
#authRetryAvailable = true;
|
|
20634
20736
|
#client;
|
|
20635
20737
|
#driver;
|
|
20636
20738
|
#currentActorInvocation;
|
|
@@ -20876,6 +20978,10 @@ var ActorConnRaw = class {
|
|
|
20876
20978
|
if (error46 instanceof ActorConnDisposed) {
|
|
20877
20979
|
return false;
|
|
20878
20980
|
}
|
|
20981
|
+
if (error46 instanceof RivetError && isInvalidToken(error46.group, error46.code) && this.#driver.refreshAuthToken && this.#authRetryAvailable) {
|
|
20982
|
+
this.#authRetryAvailable = false;
|
|
20983
|
+
return true;
|
|
20984
|
+
}
|
|
20879
20985
|
if (error46 instanceof RivetError && this.#shouldReconnectForStaleActor(error46.group, error46.code)) {
|
|
20880
20986
|
return true;
|
|
20881
20987
|
}
|
|
@@ -21000,6 +21106,7 @@ var ActorConnRaw = class {
|
|
|
21000
21106
|
messageQueueLength: this.#messageQueue.length,
|
|
21001
21107
|
connId: this.#connId
|
|
21002
21108
|
});
|
|
21109
|
+
this.#authRetryAvailable = true;
|
|
21003
21110
|
this.#setConnStatus("connected");
|
|
21004
21111
|
if (this.#onOpenPromise) {
|
|
21005
21112
|
this.#onOpenPromise.resolve(void 0);
|
|
@@ -21142,7 +21249,8 @@ var ActorConnRaw = class {
|
|
|
21142
21249
|
}
|
|
21143
21250
|
/** Called by the onclose event from drivers. */
|
|
21144
21251
|
async #handleOnClose(event2) {
|
|
21145
|
-
var _a2;
|
|
21252
|
+
var _a2, _b, _c;
|
|
21253
|
+
const failedSocket = this.#websocket;
|
|
21146
21254
|
const closeEvent = event2;
|
|
21147
21255
|
const wasClean = closeEvent.wasClean;
|
|
21148
21256
|
const wasConnected = this.#connStatus === "connected";
|
|
@@ -21164,9 +21272,24 @@ var ActorConnRaw = class {
|
|
|
21164
21272
|
const parsed = parseWebSocketCloseReason(reason);
|
|
21165
21273
|
if (parsed) {
|
|
21166
21274
|
const { group, code, rayId } = parsed;
|
|
21275
|
+
if (isInvalidToken(group, code) && closeEvent.code === 1008 && failedSocket) {
|
|
21276
|
+
try {
|
|
21277
|
+
if (!await ((_b = (_a2 = this.#driver).refreshAuthToken) == null ? void 0 : _b.call(
|
|
21278
|
+
_a2,
|
|
21279
|
+
failedSocket
|
|
21280
|
+
))) {
|
|
21281
|
+
this.#authRetryAvailable = false;
|
|
21282
|
+
}
|
|
21283
|
+
} catch {
|
|
21284
|
+
logger().warn("token renewal failed");
|
|
21285
|
+
this.#authRetryAvailable = false;
|
|
21286
|
+
}
|
|
21287
|
+
} else if (isInvalidToken(group, code)) {
|
|
21288
|
+
this.#authRetryAvailable = false;
|
|
21289
|
+
}
|
|
21167
21290
|
if (this.#shouldReconnectForStaleActor(group, code)) {
|
|
21168
21291
|
this.#clearResolvedActorIdentity();
|
|
21169
|
-
(
|
|
21292
|
+
(_c = this.#onOpenPromise) == null ? void 0 : _c.reject(
|
|
21170
21293
|
new RivetError(
|
|
21171
21294
|
group,
|
|
21172
21295
|
code,
|
|
@@ -21213,7 +21336,7 @@ var ActorConnRaw = class {
|
|
|
21213
21336
|
if (error46 instanceof RivetError) {
|
|
21214
21337
|
this.#dispatchActorError(error46);
|
|
21215
21338
|
}
|
|
21216
|
-
if (wasConnected) {
|
|
21339
|
+
if (wasConnected && this.#authRetryAvailable) {
|
|
21217
21340
|
logger().debug({
|
|
21218
21341
|
msg: "triggering reconnect",
|
|
21219
21342
|
connId: this.#connId
|
|
@@ -21682,6 +21805,23 @@ var ActorConnRaw = class {
|
|
|
21682
21805
|
);
|
|
21683
21806
|
}
|
|
21684
21807
|
};
|
|
21808
|
+
var ENGINE_HOST = "127.0.0.1";
|
|
21809
|
+
var ENGINE_PORT = 6420;
|
|
21810
|
+
var ENGINE_ENDPOINT = buildEngineEndpoint(ENGINE_HOST, ENGINE_PORT);
|
|
21811
|
+
function buildEngineEndpoint(host, port) {
|
|
21812
|
+
const urlHost = host.includes(":") && !host.startsWith("[") ? `[${host}]` : host;
|
|
21813
|
+
return `http://${urlHost}:${port}`;
|
|
21814
|
+
}
|
|
21815
|
+
function isLocalEngineEndpoint(endpoint) {
|
|
21816
|
+
let url2;
|
|
21817
|
+
try {
|
|
21818
|
+
url2 = new URL(endpoint);
|
|
21819
|
+
} catch {
|
|
21820
|
+
return false;
|
|
21821
|
+
}
|
|
21822
|
+
const hostname3 = url2.hostname.toLowerCase();
|
|
21823
|
+
return hostname3 === "localhost" || hostname3 === "0.0.0.0" || hostname3 === "::" || hostname3 === "[::]" || hostname3 === "::1" || hostname3 === "[::1]" || /^127(?:\.\d{1,3}){0,3}$/.test(hostname3);
|
|
21824
|
+
}
|
|
21685
21825
|
function tryParseEndpoint(ctx, options) {
|
|
21686
21826
|
const {
|
|
21687
21827
|
endpoint,
|
|
@@ -21776,6 +21916,8 @@ var ClientConfigSchemaBase = v4_default.object({
|
|
|
21776
21916
|
}),
|
|
21777
21917
|
/** Token to use to authenticate with the API. */
|
|
21778
21918
|
token: v4_default.string().optional().transform((val) => val ?? getRivetToken()),
|
|
21919
|
+
/** Issue and renew a client token on demand. Overrides the static token when provided. */
|
|
21920
|
+
getToken: v4_default.custom().optional(),
|
|
21779
21921
|
/** Namespace to connect to. */
|
|
21780
21922
|
namespace: v4_default.string().optional().transform((val) => val ?? getRivetNamespace()),
|
|
21781
21923
|
/** Name of the envoy pool. This is used to group together envoys in to different pools. */
|
|
@@ -21820,7 +21962,7 @@ function transformClientConfig(config3, ctx) {
|
|
|
21820
21962
|
...config3,
|
|
21821
21963
|
endpoint: parsedEndpoint == null ? void 0 : parsedEndpoint.endpoint,
|
|
21822
21964
|
namespace: (parsedEndpoint == null ? void 0 : parsedEndpoint.namespace) ?? config3.namespace ?? "default",
|
|
21823
|
-
token: (parsedEndpoint == null ? void 0 : parsedEndpoint.token) ?? config3.token
|
|
21965
|
+
token: (parsedEndpoint == null ? void 0 : parsedEndpoint.token) ?? config3.token ?? (config3.endpoint && isLocalEngineEndpoint(config3.endpoint) ? "default" : void 0)
|
|
21824
21966
|
};
|
|
21825
21967
|
}
|
|
21826
21968
|
function convertRegistryConfigToClientConfig(config3) {
|
|
@@ -21828,6 +21970,7 @@ function convertRegistryConfigToClientConfig(config3) {
|
|
|
21828
21970
|
return {
|
|
21829
21971
|
endpoint: config3.endpoint,
|
|
21830
21972
|
token: config3.token,
|
|
21973
|
+
getToken: void 0,
|
|
21831
21974
|
namespace: config3.namespace,
|
|
21832
21975
|
poolName: config3.envoy.poolName,
|
|
21833
21976
|
headers: config3.headers,
|
|
@@ -22159,7 +22302,8 @@ async function openWebSocketToGateway(runConfig, gatewayUrl, encoding, params, o
|
|
|
22159
22302
|
const ackHookToken = typeof process !== "undefined" && process.env.VITEST ? crypto.randomUUID() : void 0;
|
|
22160
22303
|
logger2().debug({
|
|
22161
22304
|
msg: "opening websocket to actor via guard",
|
|
22162
|
-
|
|
22305
|
+
// Gateway URLs can embed credentials; never include the path or query in logs.
|
|
22306
|
+
origin: new URL(gatewayUrl).origin
|
|
22163
22307
|
});
|
|
22164
22308
|
const ws = new WebSocket2(
|
|
22165
22309
|
gatewayUrl,
|
|
@@ -22249,6 +22393,14 @@ async function apiCall(config3, method2, path2, body) {
|
|
|
22249
22393
|
responseFromBare: (value) => value
|
|
22250
22394
|
});
|
|
22251
22395
|
}
|
|
22396
|
+
async function issueToken(config3, options) {
|
|
22397
|
+
return apiCall(config3, "POST", "/auth/tokens", {
|
|
22398
|
+
namespace: config3.namespace,
|
|
22399
|
+
subject: options.subject,
|
|
22400
|
+
duration: options.expiresIn,
|
|
22401
|
+
grants: options.grants
|
|
22402
|
+
});
|
|
22403
|
+
}
|
|
22252
22404
|
async function getActor(config3, _, actorId) {
|
|
22253
22405
|
return apiCall(
|
|
22254
22406
|
config3,
|
|
@@ -22490,6 +22642,8 @@ function closeWebSocketIfOpen(ws, code, reason) {
|
|
|
22490
22642
|
var RemoteEngineControlClient = class {
|
|
22491
22643
|
#config;
|
|
22492
22644
|
#metadataPromise;
|
|
22645
|
+
#tokenProvider;
|
|
22646
|
+
#webSocketTokens = /* @__PURE__ */ new WeakMap();
|
|
22493
22647
|
constructor(runConfig) {
|
|
22494
22648
|
if (getNextPhase() === "phase-production-build") {
|
|
22495
22649
|
logger2().info(
|
|
@@ -22498,6 +22652,8 @@ var RemoteEngineControlClient = class {
|
|
|
22498
22652
|
runConfig.disableMetadataLookup = true;
|
|
22499
22653
|
}
|
|
22500
22654
|
this.#config = { ...runConfig };
|
|
22655
|
+
if (runConfig.getToken)
|
|
22656
|
+
this.#tokenProvider = new TokenProvider(runConfig.getToken);
|
|
22501
22657
|
if (!runConfig.disableMetadataLookup) {
|
|
22502
22658
|
this.#metadataPromise = lookupMetadataCached(this.#config).then(
|
|
22503
22659
|
(metadataData) => {
|
|
@@ -22506,14 +22662,13 @@ var RemoteEngineControlClient = class {
|
|
|
22506
22662
|
if (metadataData.clientNamespace) {
|
|
22507
22663
|
this.#config.namespace = metadataData.clientNamespace;
|
|
22508
22664
|
}
|
|
22509
|
-
if (metadataData.clientToken) {
|
|
22665
|
+
if (metadataData.clientToken && !this.#tokenProvider) {
|
|
22510
22666
|
this.#config.token = metadataData.clientToken;
|
|
22511
22667
|
}
|
|
22512
22668
|
logger2().info({
|
|
22513
22669
|
msg: "overriding client endpoint",
|
|
22514
22670
|
endpoint: metadataData.clientEndpoint,
|
|
22515
|
-
namespace: metadataData.clientNamespace
|
|
22516
|
-
token: metadataData.clientToken
|
|
22671
|
+
namespace: metadataData.clientNamespace
|
|
22517
22672
|
});
|
|
22518
22673
|
}
|
|
22519
22674
|
logger2().info({
|
|
@@ -22526,12 +22681,47 @@ var RemoteEngineControlClient = class {
|
|
|
22526
22681
|
);
|
|
22527
22682
|
}
|
|
22528
22683
|
}
|
|
22684
|
+
async #authorizedConfig() {
|
|
22685
|
+
if (!this.#tokenProvider) return this.#config;
|
|
22686
|
+
return { ...this.#config, token: await this.#tokenProvider.current() };
|
|
22687
|
+
}
|
|
22688
|
+
async #withCredential(request, readOnly = false) {
|
|
22689
|
+
const config3 = await this.#authorizedConfig();
|
|
22690
|
+
try {
|
|
22691
|
+
return await request(config3);
|
|
22692
|
+
} catch (error46) {
|
|
22693
|
+
if (this.#tokenProvider && config3.token && error46 instanceof RivetError && error46.statusCode === 401 && isInvalidToken(error46.group, error46.code)) {
|
|
22694
|
+
if (readOnly) {
|
|
22695
|
+
const token = await this.#tokenProvider.refreshIfCurrent(
|
|
22696
|
+
config3.token
|
|
22697
|
+
);
|
|
22698
|
+
return request({ ...this.#config, token });
|
|
22699
|
+
}
|
|
22700
|
+
await this.#tokenProvider.refreshIfCurrent(config3.token);
|
|
22701
|
+
}
|
|
22702
|
+
throw error46;
|
|
22703
|
+
}
|
|
22704
|
+
}
|
|
22705
|
+
async issueToken(options) {
|
|
22706
|
+
await this.#metadataPromise;
|
|
22707
|
+
const response = await this.#withCredential(
|
|
22708
|
+
(config3) => issueToken(config3, options)
|
|
22709
|
+
);
|
|
22710
|
+
return {
|
|
22711
|
+
token: response.token,
|
|
22712
|
+
issuedAt: response.issued_ts,
|
|
22713
|
+
expiresAt: response.expires_ts
|
|
22714
|
+
};
|
|
22715
|
+
}
|
|
22529
22716
|
async getForId({
|
|
22530
22717
|
name,
|
|
22531
22718
|
actorId
|
|
22532
22719
|
}) {
|
|
22533
22720
|
await this.#metadataPromise;
|
|
22534
|
-
const response = await
|
|
22721
|
+
const response = await this.#withCredential(
|
|
22722
|
+
(config3) => getActor(config3, name, actorId),
|
|
22723
|
+
true
|
|
22724
|
+
);
|
|
22535
22725
|
const actor2 = response.actors[0];
|
|
22536
22726
|
if (!actor2) return void 0;
|
|
22537
22727
|
if (actor2.name !== name) {
|
|
@@ -22552,7 +22742,10 @@ var RemoteEngineControlClient = class {
|
|
|
22552
22742
|
await this.#metadataPromise;
|
|
22553
22743
|
logger2().debug({ msg: "getWithKey: searching for actor", name, key });
|
|
22554
22744
|
try {
|
|
22555
|
-
const response = await
|
|
22745
|
+
const response = await this.#withCredential(
|
|
22746
|
+
(config3) => getActorByKey(config3, name, key),
|
|
22747
|
+
true
|
|
22748
|
+
);
|
|
22556
22749
|
const actor2 = response.actors[0];
|
|
22557
22750
|
if (!actor2) return void 0;
|
|
22558
22751
|
logger2().debug({
|
|
@@ -22585,16 +22778,18 @@ var RemoteEngineControlClient = class {
|
|
|
22585
22778
|
key
|
|
22586
22779
|
});
|
|
22587
22780
|
try {
|
|
22588
|
-
const { actor: actor2, created } = await
|
|
22589
|
-
|
|
22590
|
-
|
|
22591
|
-
|
|
22592
|
-
|
|
22593
|
-
|
|
22594
|
-
|
|
22595
|
-
|
|
22596
|
-
|
|
22597
|
-
|
|
22781
|
+
const { actor: actor2, created } = await this.#withCredential(
|
|
22782
|
+
(config3) => getOrCreateActor(config3, {
|
|
22783
|
+
datacenter: region,
|
|
22784
|
+
name,
|
|
22785
|
+
key: serializeActorKey(key),
|
|
22786
|
+
runner_name_selector: poolName ?? this.#config.poolName,
|
|
22787
|
+
input: actorInput ? uint8ArrayToBase642(
|
|
22788
|
+
encodeCborCompat(actorInput)
|
|
22789
|
+
) : void 0,
|
|
22790
|
+
crash_policy: crashPolicy ?? "sleep"
|
|
22791
|
+
})
|
|
22792
|
+
);
|
|
22598
22793
|
logger2().info({
|
|
22599
22794
|
msg: "getOrCreateWithKey: actor ready",
|
|
22600
22795
|
actorId: actor2.actor_id,
|
|
@@ -22610,7 +22805,10 @@ var RemoteEngineControlClient = class {
|
|
|
22610
22805
|
name,
|
|
22611
22806
|
key
|
|
22612
22807
|
});
|
|
22613
|
-
const response = await
|
|
22808
|
+
const response = await this.#withCredential(
|
|
22809
|
+
(config3) => getActorByKey(config3, name, key),
|
|
22810
|
+
true
|
|
22811
|
+
);
|
|
22614
22812
|
const existing = response.actors[0];
|
|
22615
22813
|
if (!existing) throw error46;
|
|
22616
22814
|
logger2().info({
|
|
@@ -22634,14 +22832,18 @@ var RemoteEngineControlClient = class {
|
|
|
22634
22832
|
}) {
|
|
22635
22833
|
await this.#metadataPromise;
|
|
22636
22834
|
logger2().info({ msg: "creating actor via engine api", name, key });
|
|
22637
|
-
const result = await
|
|
22638
|
-
|
|
22639
|
-
|
|
22640
|
-
|
|
22641
|
-
|
|
22642
|
-
|
|
22643
|
-
|
|
22644
|
-
|
|
22835
|
+
const result = await this.#withCredential(
|
|
22836
|
+
(config3) => createActor(config3, {
|
|
22837
|
+
datacenter: region,
|
|
22838
|
+
name,
|
|
22839
|
+
runner_name_selector: poolName ?? this.#config.poolName,
|
|
22840
|
+
key: serializeActorKey(key),
|
|
22841
|
+
input: input ? uint8ArrayToBase642(
|
|
22842
|
+
encodeCborCompat(input)
|
|
22843
|
+
) : void 0,
|
|
22844
|
+
crash_policy: crashPolicy ?? "sleep"
|
|
22845
|
+
})
|
|
22846
|
+
);
|
|
22645
22847
|
logger2().info({
|
|
22646
22848
|
msg: "actor created",
|
|
22647
22849
|
actorId: result.actor.actor_id,
|
|
@@ -22653,43 +22855,61 @@ var RemoteEngineControlClient = class {
|
|
|
22653
22855
|
async listActors({ name }) {
|
|
22654
22856
|
await this.#metadataPromise;
|
|
22655
22857
|
logger2().debug({ msg: "listing actors via engine api", name });
|
|
22656
|
-
const response = await
|
|
22858
|
+
const response = await this.#withCredential(
|
|
22859
|
+
(config3) => listActorsByName(config3, name),
|
|
22860
|
+
true
|
|
22861
|
+
);
|
|
22657
22862
|
return response.actors.map(apiActorToOutput);
|
|
22658
22863
|
}
|
|
22659
22864
|
async destroyActor(actorId) {
|
|
22660
22865
|
await this.#metadataPromise;
|
|
22661
22866
|
logger2().info({ msg: "destroying actor via engine api", actorId });
|
|
22662
|
-
await destroyActor(
|
|
22867
|
+
await this.#withCredential((config3) => destroyActor(config3, actorId));
|
|
22663
22868
|
logger2().info({ msg: "actor destroyed", actorId });
|
|
22664
22869
|
}
|
|
22665
22870
|
async sendRequest(target, actorRequest, options = {}) {
|
|
22871
|
+
var _a2;
|
|
22666
22872
|
await this.#metadataPromise;
|
|
22667
|
-
const
|
|
22668
|
-
const gatewayUrl = this.#buildGatewayUrlForTarget(
|
|
22669
|
-
target,
|
|
22670
|
-
path2,
|
|
22671
|
-
options
|
|
22672
|
-
);
|
|
22873
|
+
const config3 = await this.#authorizedConfig();
|
|
22673
22874
|
const httpOptions = {
|
|
22674
22875
|
...options,
|
|
22675
22876
|
directActorId: shouldSkipReadyWait(options) ? directActorIdFromTarget(target) : void 0
|
|
22676
22877
|
};
|
|
22677
|
-
|
|
22678
|
-
|
|
22679
|
-
|
|
22878
|
+
const send = (current) => sendHttpRequestToGateway(
|
|
22879
|
+
current,
|
|
22880
|
+
this.#buildGatewayUrlForTarget(
|
|
22881
|
+
current,
|
|
22882
|
+
target,
|
|
22883
|
+
requestPath(actorRequest),
|
|
22884
|
+
options
|
|
22885
|
+
),
|
|
22680
22886
|
actorRequest,
|
|
22681
22887
|
httpOptions
|
|
22682
22888
|
);
|
|
22889
|
+
const response = await send(config3);
|
|
22890
|
+
if (!this.#tokenProvider || !config3.token || !isInvalidTokenResponse(response))
|
|
22891
|
+
return response;
|
|
22892
|
+
if ((actorRequest.method === "GET" || actorRequest.method === "HEAD") && !("getOrCreateForKey" in target)) {
|
|
22893
|
+
const token = await this.#tokenProvider.refreshIfCurrent(
|
|
22894
|
+
config3.token
|
|
22895
|
+
);
|
|
22896
|
+
await ((_a2 = response.body) == null ? void 0 : _a2.cancel());
|
|
22897
|
+
return send({ ...this.#config, token });
|
|
22898
|
+
}
|
|
22899
|
+
await this.#tokenProvider.refreshIfCurrent(config3.token);
|
|
22900
|
+
return response;
|
|
22683
22901
|
}
|
|
22684
22902
|
async openWebSocket(path2, target, encoding, params, options = {}) {
|
|
22685
22903
|
await this.#metadataPromise;
|
|
22904
|
+
const config3 = await this.#authorizedConfig();
|
|
22686
22905
|
const gatewayUrl = this.#buildGatewayUrlForTarget(
|
|
22906
|
+
config3,
|
|
22687
22907
|
target,
|
|
22688
22908
|
path2,
|
|
22689
22909
|
options
|
|
22690
22910
|
);
|
|
22691
|
-
|
|
22692
|
-
|
|
22911
|
+
const ws = await openWebSocketToGateway(
|
|
22912
|
+
config3,
|
|
22693
22913
|
gatewayUrl,
|
|
22694
22914
|
encoding,
|
|
22695
22915
|
params,
|
|
@@ -22698,25 +22918,59 @@ var RemoteEngineControlClient = class {
|
|
|
22698
22918
|
directActorId: shouldSkipReadyWait(options) ? directActorIdFromTarget(target) : void 0
|
|
22699
22919
|
}
|
|
22700
22920
|
);
|
|
22921
|
+
this.#watchWebSocketAuth(ws, config3.token);
|
|
22922
|
+
return ws;
|
|
22923
|
+
}
|
|
22924
|
+
async refreshAuthToken(ws) {
|
|
22925
|
+
const context2 = this.#webSocketTokens.get(ws);
|
|
22926
|
+
if (!(context2 == null ? void 0 : context2.refresh)) return false;
|
|
22927
|
+
await context2.refresh;
|
|
22928
|
+
return true;
|
|
22929
|
+
}
|
|
22930
|
+
#watchWebSocketAuth(ws, token) {
|
|
22931
|
+
const tokenProvider = this.#tokenProvider;
|
|
22932
|
+
if (!tokenProvider || !token) return;
|
|
22933
|
+
const context2 = {};
|
|
22934
|
+
this.#webSocketTokens.set(ws, context2);
|
|
22935
|
+
ws.addEventListener(
|
|
22936
|
+
"close",
|
|
22937
|
+
(event2) => {
|
|
22938
|
+
if (event2.code !== 1008 || !event2.reason) return;
|
|
22939
|
+
const separator = event2.reason.indexOf(".");
|
|
22940
|
+
if (separator < 0) return;
|
|
22941
|
+
const code = event2.reason.slice(separator + 1).split(/[\s:#]/, 1)[0];
|
|
22942
|
+
if (isInvalidToken(event2.reason.slice(0, separator), code)) {
|
|
22943
|
+
context2.refresh = tokenProvider.refreshIfCurrent(token).catch((error46) => {
|
|
22944
|
+
logger2().warn(
|
|
22945
|
+
"failed to renew authentication token"
|
|
22946
|
+
);
|
|
22947
|
+
throw error46;
|
|
22948
|
+
});
|
|
22949
|
+
context2.refresh.catch(() => {
|
|
22950
|
+
});
|
|
22951
|
+
}
|
|
22952
|
+
}
|
|
22953
|
+
);
|
|
22701
22954
|
}
|
|
22702
22955
|
async buildGatewayUrl(target, options = {}) {
|
|
22703
22956
|
await this.#metadataPromise;
|
|
22704
|
-
return this.#buildGatewayUrlForTarget(
|
|
22957
|
+
return this.#buildGatewayUrlForTarget(
|
|
22958
|
+
await this.#authorizedConfig(),
|
|
22959
|
+
target,
|
|
22960
|
+
"",
|
|
22961
|
+
options
|
|
22962
|
+
);
|
|
22705
22963
|
}
|
|
22706
22964
|
async proxyRequest(_c, actorRequest, actorId) {
|
|
22707
|
-
|
|
22708
|
-
const gatewayUrl = this.#buildGatewayUrlForTarget(
|
|
22709
|
-
{ directId: actorId },
|
|
22710
|
-
requestPath(actorRequest)
|
|
22711
|
-
);
|
|
22712
|
-
return sendHttpRequestToGateway(this.#config, gatewayUrl, actorRequest);
|
|
22965
|
+
return this.sendRequest({ directId: actorId }, actorRequest);
|
|
22713
22966
|
}
|
|
22714
22967
|
async proxyWebSocket(c, path2, actorId, encoding, params) {
|
|
22715
|
-
var _a2
|
|
22968
|
+
var _a2;
|
|
22716
22969
|
await this.#metadataPromise;
|
|
22717
|
-
const
|
|
22970
|
+
const config3 = await this.#authorizedConfig();
|
|
22971
|
+
const upgradeWebSocket = (_a2 = config3.getUpgradeWebSocket) == null ? void 0 : _a2.call(config3);
|
|
22718
22972
|
(0, import_invariant4.default)(upgradeWebSocket, "missing getUpgradeWebSocket");
|
|
22719
|
-
const endpoint = getEndpoint(
|
|
22973
|
+
const endpoint = getEndpoint(config3);
|
|
22720
22974
|
const guardUrl = combineUrlPath(endpoint, path2);
|
|
22721
22975
|
const wsGuardUrl = guardUrl.replace("http://", "ws://");
|
|
22722
22976
|
logger2().debug({
|
|
@@ -22726,7 +22980,7 @@ var RemoteEngineControlClient = class {
|
|
|
22726
22980
|
guardUrl
|
|
22727
22981
|
});
|
|
22728
22982
|
const protocols = buildWebSocketProtocols(
|
|
22729
|
-
|
|
22983
|
+
config3,
|
|
22730
22984
|
encoding,
|
|
22731
22985
|
params,
|
|
22732
22986
|
void 0,
|
|
@@ -22744,8 +22998,8 @@ var RemoteEngineControlClient = class {
|
|
|
22744
22998
|
setGetUpgradeWebSocket(getUpgradeWebSocket) {
|
|
22745
22999
|
this.#config.getUpgradeWebSocket = getUpgradeWebSocket;
|
|
22746
23000
|
}
|
|
22747
|
-
#buildGatewayUrlForTarget(target, path2, options = {}) {
|
|
22748
|
-
const endpoint = getEndpoint(
|
|
23001
|
+
#buildGatewayUrlForTarget(config3, target, path2, options = {}) {
|
|
23002
|
+
const endpoint = getEndpoint(config3);
|
|
22749
23003
|
if (shouldSkipReadyWait(options) && directActorIdFromTarget(target) && canUseDirectSkipReadyWaitPath(path2)) {
|
|
22750
23004
|
return combineUrlPath(endpoint, path2);
|
|
22751
23005
|
}
|
|
@@ -22753,7 +23007,7 @@ var RemoteEngineControlClient = class {
|
|
|
22753
23007
|
return buildActorGatewayUrl(
|
|
22754
23008
|
endpoint,
|
|
22755
23009
|
target.directId,
|
|
22756
|
-
|
|
23010
|
+
config3.token,
|
|
22757
23011
|
path2
|
|
22758
23012
|
);
|
|
22759
23013
|
}
|
|
@@ -22761,20 +23015,20 @@ var RemoteEngineControlClient = class {
|
|
|
22761
23015
|
return buildActorGatewayUrl(
|
|
22762
23016
|
endpoint,
|
|
22763
23017
|
target.getForId.actorId,
|
|
22764
|
-
|
|
23018
|
+
config3.token,
|
|
22765
23019
|
path2
|
|
22766
23020
|
);
|
|
22767
23021
|
}
|
|
22768
23022
|
if ("getForKey" in target || "getOrCreateForKey" in target) {
|
|
22769
23023
|
return buildActorQueryGatewayUrl(
|
|
22770
23024
|
endpoint,
|
|
22771
|
-
|
|
23025
|
+
config3.namespace,
|
|
22772
23026
|
target,
|
|
22773
|
-
|
|
23027
|
+
config3.token,
|
|
22774
23028
|
path2,
|
|
22775
|
-
|
|
23029
|
+
config3.maxInputSize,
|
|
22776
23030
|
void 0,
|
|
22777
|
-
"getOrCreateForKey" in target ? target.getOrCreateForKey.poolName ??
|
|
23031
|
+
"getOrCreateForKey" in target ? target.getOrCreateForKey.poolName ?? config3.poolName : void 0,
|
|
22778
23032
|
options
|
|
22779
23033
|
);
|
|
22780
23034
|
}
|
|
@@ -22823,7 +23077,7 @@ function apiActorToOutput(actor2) {
|
|
|
22823
23077
|
};
|
|
22824
23078
|
}
|
|
22825
23079
|
|
|
22826
|
-
// ../rivetkit/dist/tsup/chunk-
|
|
23080
|
+
// ../rivetkit/dist/tsup/chunk-RIPVNPR6.js
|
|
22827
23081
|
var nativeStateTransactionOpeners = /* @__PURE__ */ new WeakMap();
|
|
22828
23082
|
var nativeStateTransactionClientBinders = /* @__PURE__ */ new WeakMap();
|
|
22829
23083
|
function registerNativeStateTransactionOpener(provider, opener) {
|
|
@@ -24565,23 +24819,6 @@ var InlineWebSocketAdapter = class {
|
|
|
24565
24819
|
}
|
|
24566
24820
|
}
|
|
24567
24821
|
};
|
|
24568
|
-
var ENGINE_HOST = "127.0.0.1";
|
|
24569
|
-
var ENGINE_PORT = 6420;
|
|
24570
|
-
var ENGINE_ENDPOINT = buildEngineEndpoint(ENGINE_HOST, ENGINE_PORT);
|
|
24571
|
-
function buildEngineEndpoint(host, port) {
|
|
24572
|
-
const urlHost = host.includes(":") && !host.startsWith("[") ? `[${host}]` : host;
|
|
24573
|
-
return `http://${urlHost}:${port}`;
|
|
24574
|
-
}
|
|
24575
|
-
function isLocalEngineEndpoint(endpoint) {
|
|
24576
|
-
let url2;
|
|
24577
|
-
try {
|
|
24578
|
-
url2 = new URL(endpoint);
|
|
24579
|
-
} catch {
|
|
24580
|
-
return false;
|
|
24581
|
-
}
|
|
24582
|
-
const hostname3 = url2.hostname.toLowerCase();
|
|
24583
|
-
return hostname3 === "localhost" || hostname3 === "0.0.0.0" || hostname3 === "::" || hostname3 === "[::]" || hostname3 === "::1" || hostname3 === "[::1]" || /^127(?:\.\d{1,3}){0,3}$/.test(hostname3);
|
|
24584
|
-
}
|
|
24585
24822
|
function logger22() {
|
|
24586
24823
|
return getLogger("registry");
|
|
24587
24824
|
}
|
|
@@ -24679,20 +24916,9 @@ async function configureServerlessPool(config3) {
|
|
|
24679
24916
|
});
|
|
24680
24917
|
throw lastError;
|
|
24681
24918
|
}
|
|
24682
|
-
var warnedMissingVersion = false;
|
|
24683
24919
|
var EnvoyConfigSchema = external_exports.object({
|
|
24684
24920
|
poolName: external_exports.string().default(() => getRivetPool() ?? "default"),
|
|
24685
|
-
version: external_exports.number().default(() =>
|
|
24686
|
-
const version2 = getRivetEnvoyVersion();
|
|
24687
|
-
if (version2 !== void 0) return version2;
|
|
24688
|
-
if (getNodeEnv() === "production" && !warnedMissingVersion) {
|
|
24689
|
-
warnedMissingVersion = true;
|
|
24690
|
-
getLogger("rivetkit").error(
|
|
24691
|
-
"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"
|
|
24692
|
-
);
|
|
24693
|
-
}
|
|
24694
|
-
return 1;
|
|
24695
|
-
}),
|
|
24921
|
+
version: external_exports.number().default(() => getRivetEnvoyVersion() ?? 1),
|
|
24696
24922
|
// Deprecated.
|
|
24697
24923
|
totalSlots: external_exports.number().default(() => getRivetTotalSlots() ?? 1e5),
|
|
24698
24924
|
envoyKey: external_exports.string().optional()
|
|
@@ -24992,7 +25218,7 @@ var RegistryConfigSchema = external_exports.object({
|
|
|
24992
25218
|
config3.startEngine || parsedEndpoint
|
|
24993
25219
|
);
|
|
24994
25220
|
const namespace = (parsedEndpoint == null ? void 0 : parsedEndpoint.namespace) ?? config3.namespace ?? "default";
|
|
24995
|
-
const token = (parsedEndpoint == null ? void 0 : parsedEndpoint.token) ?? config3.token ?? "
|
|
25221
|
+
const token = (parsedEndpoint == null ? void 0 : parsedEndpoint.token) ?? config3.token ?? (endpoint && isLocalEngineEndpoint(endpoint) ? "default" : void 0);
|
|
24996
25222
|
const parsedPublicEndpoint = config3.serverless.publicEndpoint ? tryParseEndpoint(ctx, {
|
|
24997
25223
|
endpoint: config3.serverless.publicEndpoint,
|
|
24998
25224
|
path: ["serverless", "publicEndpoint"]
|
|
@@ -28004,7 +28230,18 @@ function isStructuredBridgeError(error46) {
|
|
|
28004
28230
|
}
|
|
28005
28231
|
function encodeNativeCallbackError(error46) {
|
|
28006
28232
|
const structuredError = isStructuredBridgeError(error46) ? error46 : deconstructError(error46, true);
|
|
28007
|
-
const
|
|
28233
|
+
const { encoded, droppedMetadataCause } = encodeBridgeRivetError(structuredError);
|
|
28234
|
+
if (droppedMetadataCause !== void 0) {
|
|
28235
|
+
logger22().warn(
|
|
28236
|
+
{
|
|
28237
|
+
group: structuredError.group,
|
|
28238
|
+
code: structuredError.code,
|
|
28239
|
+
error: String(droppedMetadataCause)
|
|
28240
|
+
},
|
|
28241
|
+
"dropped error metadata that JSON cannot encode"
|
|
28242
|
+
);
|
|
28243
|
+
}
|
|
28244
|
+
const bridgeError = new Error(encoded, {
|
|
28008
28245
|
cause: error46 instanceof Error ? error46 : void 0
|
|
28009
28246
|
});
|
|
28010
28247
|
return Object.assign(bridgeError, {
|
|
@@ -29341,7 +29578,10 @@ var ActorContextHandleAdapter = class {
|
|
|
29341
29578
|
}
|
|
29342
29579
|
this.#request = request;
|
|
29343
29580
|
this[ACTOR_CONTEXT_INTERNAL_SYMBOL] = new NativeWorkflowRuntimeAdapter(
|
|
29344
|
-
this
|
|
29581
|
+
this,
|
|
29582
|
+
() => this.#logByInvocationScope.delete(
|
|
29583
|
+
this.#runtime.currentInvocationScope() ?? NO_INVOCATION_SCOPE
|
|
29584
|
+
)
|
|
29345
29585
|
);
|
|
29346
29586
|
}
|
|
29347
29587
|
get kv() {
|
|
@@ -29513,7 +29753,10 @@ var ActorContextHandleAdapter = class {
|
|
|
29513
29753
|
() => this.#runtime.actorInvocationTraceContext(this.#ctx)
|
|
29514
29754
|
);
|
|
29515
29755
|
}
|
|
29516
|
-
/**
|
|
29756
|
+
/**
|
|
29757
|
+
* Cached per invocation, because the `run` context outlives workflow runs and steps.
|
|
29758
|
+
* A workflow queue receive clears the entry, because the run's ray becomes the message's ray.
|
|
29759
|
+
*/
|
|
29517
29760
|
get log() {
|
|
29518
29761
|
const scope = this.#runtime.currentInvocationScope() ?? NO_INVOCATION_SCOPE;
|
|
29519
29762
|
const cached2 = this.#logByInvocationScope.get(scope);
|
|
@@ -30060,13 +30303,15 @@ var ActorContextHandleAdapter = class {
|
|
|
30060
30303
|
};
|
|
30061
30304
|
var NativeWorkflowRuntimeAdapter = class {
|
|
30062
30305
|
#ctx;
|
|
30306
|
+
#onMessagesReceived;
|
|
30063
30307
|
#completions = /* @__PURE__ */ new Map();
|
|
30064
30308
|
id;
|
|
30065
30309
|
driver;
|
|
30066
30310
|
queueManager;
|
|
30067
30311
|
stateManager;
|
|
30068
|
-
constructor(ctx) {
|
|
30312
|
+
constructor(ctx, onMessagesReceived) {
|
|
30069
30313
|
this.#ctx = ctx;
|
|
30314
|
+
this.#onMessagesReceived = onMessagesReceived;
|
|
30070
30315
|
this.id = ctx.actorId;
|
|
30071
30316
|
this.driver = {
|
|
30072
30317
|
kvBatchGet: async (actorId, keys) => {
|
|
@@ -30106,6 +30351,9 @@ var NativeWorkflowRuntimeAdapter = class {
|
|
|
30106
30351
|
timeout: timeout ?? 0,
|
|
30107
30352
|
completable
|
|
30108
30353
|
});
|
|
30354
|
+
if (messages.length > 0) {
|
|
30355
|
+
this.#onMessagesReceived();
|
|
30356
|
+
}
|
|
30109
30357
|
return messages.map(
|
|
30110
30358
|
(message) => this.#wrapQueueMessage(message)
|
|
30111
30359
|
);
|
|
@@ -31957,7 +32205,23 @@ var Registry = class {
|
|
|
31957
32205
|
* Starts an actor envoy for standalone server deployments.
|
|
31958
32206
|
*/
|
|
31959
32207
|
#startEnvoy(config3, printWelcome) {
|
|
32208
|
+
var _a2;
|
|
31960
32209
|
if (!this.#runtimeServePromise) {
|
|
32210
|
+
const configuredEnvoyVersion = (_a2 = this.#config.envoy) == null ? void 0 : _a2.version;
|
|
32211
|
+
const envoyVersionSource = configuredEnvoyVersion !== void 0 ? "config" : getRivetEnvoyVersion() !== void 0 ? "environment" : "default";
|
|
32212
|
+
logger22().info({
|
|
32213
|
+
msg: "starting rivetkit envoy",
|
|
32214
|
+
rivetkitVersion: VERSION,
|
|
32215
|
+
envoyVersion: config3.envoy.version,
|
|
32216
|
+
envoyVersionSource
|
|
32217
|
+
});
|
|
32218
|
+
if (envoyVersionSource === "default" && getNodeEnv() === "production") {
|
|
32219
|
+
logger22().error({
|
|
32220
|
+
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",
|
|
32221
|
+
envoyVersion: config3.envoy.version,
|
|
32222
|
+
envoyVersionSource
|
|
32223
|
+
});
|
|
32224
|
+
}
|
|
31961
32225
|
const configuredRegistryPromise = this.#buildConfiguredRegistry(config3);
|
|
31962
32226
|
this.#runtimeServeConfiguredPromise = configuredRegistryPromise;
|
|
31963
32227
|
this.#runtimeServeLifecyclePromise = configuredRegistryPromise.then(
|