@rivetkit/supabase 2.3.32 → 2.3.34

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.
Files changed (3) hide show
  1. package/dist/mod.js +867 -865
  2. package/dist/mod.mjs +870 -868
  3. package/package.json +3 -3
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-MBU6CTKH.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,880 +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-6FEYCVZC.js
12971
- function flattenActionHandlers(actions) {
12972
- const flattened = /* @__PURE__ */ Object.create(null);
12973
- for (const { name, handler } of collectActionEntries(actions)) {
12974
- flattened[name] = handler;
12975
- }
12976
- return flattened;
12977
- }
12978
- function flattenActionInputSchemas(actions, schemas) {
12979
- if (schemas === void 0) return void 0;
12980
- if (!isRecord(schemas)) {
12981
- throw new TypeError("actionInputSchemas must be an object");
12982
- }
12983
- const flattened = /* @__PURE__ */ Object.create(null);
12984
- for (const { name, path: path2 } of collectActionEntries(actions)) {
12985
- const nestedSchema = lookupNestedSchema(schemas, path2);
12986
- const flatSchema = schemas[name];
12987
- if (nestedSchema !== void 0 && flatSchema !== void 0 && nestedSchema !== flatSchema) {
12988
- throw new TypeError(
12989
- `Action input schema \`${name}\` is defined by both a nested path and a dotted key`
12990
- );
12991
- }
12992
- const schema = nestedSchema ?? flatSchema;
12993
- if (schema !== void 0) {
12994
- flattened[name] = schema;
12995
- }
12996
- }
12997
- return flattened;
12998
- }
12999
- function flattenActionTraceSamplers(actions, rates = {}) {
13000
- const handlers = flattenActionHandlers(actions);
13001
- const flattened = Object.fromEntries(flattenSampleRates(rates, []));
13002
- for (const name of Object.keys(flattened)) {
13003
- if (!Object.hasOwn(handlers, name)) {
13004
- throw new TypeError(
13005
- `tracing.actions.${name} does not name an action`
13006
- );
13007
- }
13008
- }
13009
- return flattened;
13010
- }
13011
- function flattenSampleRates(rates, path2) {
13012
- return Object.entries(rates).flatMap(
13013
- ([segment, rate]) => {
13014
- const childPath = [...path2, segment];
13015
- return typeof rate === "number" ? [[childPath.join("."), rate]] : flattenSampleRates(rate, childPath);
13016
- }
13017
- );
13018
- }
13019
- function collectActionEntries(actions) {
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`
13179
+ // ../rivetkit/dist/tsup/chunk-MBU6CTKH.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}"`
13029
13227
  );
13030
13228
  }
13031
- for (const [segment, child] of Object.entries(value)) {
13032
- const childPath = [...path2, segment];
13033
- if (typeof child === "function") {
13034
- const name = childPath.join(".");
13035
- if (names.has(name)) {
13036
- throw new TypeError(
13037
- `Multiple action definitions flatten to \`${name}\``
13038
- );
13039
- }
13040
- names.add(name);
13041
- entries.push({
13042
- name,
13043
- path: childPath,
13044
- handler: child
13045
- });
13229
+ return parsed;
13230
+ }
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}`);
13241
+ }
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;
13046
13279
  } else {
13047
- visitActionGroup(child, childPath, entries, names);
13280
+ statusCode = 500;
13281
+ public_ = false;
13282
+ group = "rivetkit";
13283
+ code = INTERNAL_ERROR_CODE;
13284
+ message = getErrorMessage(error46);
13285
+ }
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;
13048
13294
  }
13295
+ metadata = {
13296
+ //url: `https://dashboard.rivet.dev/projects/${actorMetadata.project.slug}/environments/${actorMetadata.environment.slug}/actors?actorId=${actorMetadata.actor.id}`,
13297
+ };
13049
13298
  }
13299
+ return {
13300
+ __type: "ActorError",
13301
+ statusCode,
13302
+ public: public_,
13303
+ group,
13304
+ code,
13305
+ message,
13306
+ metadata,
13307
+ rayId,
13308
+ actor: actor2
13309
+ };
13050
13310
  }
13051
- function lookupNestedSchema(schemas, path2) {
13052
- let value = schemas;
13053
- for (const segment of path2) {
13054
- if (!isRecord(value) || !Object.hasOwn(value, segment)) {
13055
- return void 0;
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;
13319
+ }
13320
+ return `${error46.name}: ${error46.message}${stack ? `
13321
+ ${stack}` : ""}`;
13322
+ } else {
13323
+ return `${error46.name}: ${error46.message}`;
13056
13324
  }
13057
- value = value[segment];
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]";
13332
+ }
13333
+ } else {
13334
+ return `Unknown error: ${getErrorMessage(error46)}`;
13058
13335
  }
13059
- return value;
13060
13336
  }
13061
- function isRecord(value) {
13062
- if (typeof value !== "object" || value === null || Array.isArray(value)) {
13063
- return false;
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 formatActionPath(path2) {
13069
- return path2.length === 0 ? "actions" : `Action \`${path2.join(".")}\``;
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, both client connections for actions and
13242
- * events and WebSockets for onWebSocket. A WebSocket that does not
13243
- * hibernate closes when the actor sleeps, and the client reconnects.
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 can be hibernated, both client connections for actions and events and WebSockets using onWebSocket. A WebSocket that does not hibernate closes when the actor sleeps. 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-ZOVJDAOW.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
- const payload = {
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
- try {
13580
- return {
13581
- encoded: `${BRIDGE_RIVET_ERROR_PREFIX}${JSON.stringify(payload)}`
13582
- };
13583
- } catch (cause) {
13584
- return {
13585
- encoded: `${BRIDGE_RIVET_ERROR_PREFIX}${JSON.stringify({ ...payload, metadata: void 0 })}`,
13586
- droppedMetadataCause: cause
13587
- };
13588
- }
13589
- }
13590
- function encodeErrorForBridge(error46) {
13591
- if (isCanonicalStructuredRivetError(error46)) {
13592
- return encodeBridgeRivetError(error46).encoded;
13593
- }
13594
- return String(error46);
13595
- }
13596
- function isCanonicalStructuredRivetError(error46) {
13597
- 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";
13598
- }
13599
- function decodeBridgeRivetErrorPayload(value) {
13600
- if (!value.startsWith(BRIDGE_RIVET_ERROR_PREFIX)) {
13601
- return void 0;
13602
- }
13603
- try {
13604
- const raw = JSON.parse(
13605
- value.slice(BRIDGE_RIVET_ERROR_PREFIX.length)
13606
- );
13607
- const payload = {
13608
- ...raw,
13609
- rayId: raw.rayId ?? void 0
13610
- };
13611
- if (!isRivetErrorLike(payload)) {
13612
- return void 0;
13613
- }
13614
- if (payload.actor !== void 0 && payload.actor !== null && !isActorSpecifier(payload.actor)) {
13615
- return void 0;
13616
- }
13617
- return payload;
13618
- } catch {
13619
- return void 0;
13620
- }
13621
- }
13622
- function decodeBridgeRivetError(value) {
13623
- const payload = decodeBridgeRivetErrorPayload(value);
13624
- if (!payload) {
13625
- return void 0;
13626
- }
13627
- return new RivetError(payload.group, payload.code, payload.message, {
13628
- metadata: payload.metadata,
13629
- rayId: payload.rayId,
13630
- public: payload.public,
13631
- statusCode: payload.statusCode,
13632
- actor: payload.actor ?? void 0
13633
- });
13634
- }
13635
- function invalidRequest(error46) {
13636
- return new RivetError(
13637
- "request",
13638
- "invalid",
13639
- `Invalid request: ${errorMessage(error46, String(error46))}`,
13640
- {
13641
- public: true,
13642
- cause: error46 instanceof Error ? error46 : void 0
13643
- }
13644
- );
13645
- }
13646
- function actorNotFound(identifier) {
13647
- return new RivetError(
13648
- "actor",
13649
- "not_found",
13650
- identifier ? `Actor not found: ${identifier} (https://www.rivet.dev/docs/clients/javascript)` : "Actor not found (https://www.rivet.dev/docs/clients/javascript)",
13651
- { public: true }
13652
- );
13653
- }
13654
- function forbiddenError() {
13655
- return new RivetError("auth", "forbidden", "Forbidden", {
13656
- public: true,
13657
- statusCode: 403
13658
- });
13659
- }
13660
- function unsupportedFeature(feature) {
13661
- return new RivetError(
13662
- "feature",
13663
- "unsupported",
13664
- `Unsupported feature: ${feature}`
13665
- );
13666
- }
13667
-
13668
- // ../rivetkit/dist/tsup/chunk-3LLGBENU.js
13669
- import {
13670
- pino,
13671
- stdTimeFunctions
13672
- } from "pino";
13673
- var import_invariant = __toESM(require_invariant(), 1);
13674
- import * as cbor from "cbor-x";
13675
- var getRivetEngine = () => getEnvUniversal("RIVET_ENGINE");
13676
- var getRivetEndpoint = () => getEnvUniversal("RIVET_ENDPOINT");
13677
- var getRivetToken = () => getEnvUniversal("RIVET_TOKEN");
13678
- var getRivetNamespace = () => getEnvUniversal("RIVET_NAMESPACE");
13679
- var getRivetPool = () => getEnvUniversal("RIVET_POOL");
13680
- var getRivetTotalSlots = () => {
13681
- const value = getEnvUniversal("RIVET_TOTAL_SLOTS");
13682
- return value !== void 0 ? parseInt(value, 10) : void 0;
13683
- };
13684
- var getRivetRunEngine = () => getEnvUniversal("RIVET_RUN_ENGINE") === "1";
13685
- var getRivetRunEngineHost = () => getEnvUniversal("RIVET_RUN_ENGINE_HOST");
13686
- var getRivetRunEnginePort = () => {
13687
- const value = getEnvUniversal("RIVET_RUN_ENGINE_PORT");
13688
- return value !== void 0 ? parseInt(value, 10) : void 0;
13689
- };
13690
- var getRivetRunEngineVersion = () => getEnvUniversal("RIVET_RUN_ENGINE_VERSION");
13691
- var getRivetRunServices = () => {
13692
- const value = getEnvUniversal("RIVET_RUN_SERVICES");
13693
- return value === void 0 ? void 0 : value === "1";
13694
- };
13695
- var getRivetEnvoyVersion = () => {
13696
- const value = getEnvUniversal("RIVET_ENVOY_VERSION");
13697
- return value !== void 0 ? parseInt(value, 10) : void 0;
13698
- };
13699
- var getRivetPublicEndpoint = () => getEnvUniversal("RIVET_PUBLIC_ENDPOINT");
13700
- var getRivetPublicToken = () => getEnvUniversal("RIVET_PUBLIC_TOKEN");
13701
- var getRivetkitRuntime = () => getEnvUniversal("RIVETKIT_RUNTIME");
13702
- var getRivetkitRuntimeMode = () => {
13703
- const value = getEnvUniversal("RIVETKIT_RUNTIME_MODE");
13704
- if (value === void 0) return "envoy";
13705
- if (value === "envoy" || value === "serverless") return value;
13706
- throw new Error(
13707
- `RIVETKIT_RUNTIME_MODE env var must be "envoy" or "serverless"; got "${value}"`
13708
- );
13709
- };
13710
- var getRivetkitPublicDir = () => {
13711
- const value = getEnvUniversal("RIVETKIT_PUBLIC_DIR");
13712
- return value === void 0 || value === "" ? void 0 : value;
13713
- };
13714
- function parsePortEnv(raw) {
13715
- if (raw === void 0 || raw === "") return void 0;
13716
- const parsed = Number.parseInt(raw, 10);
13717
- if (!Number.isFinite(parsed) || parsed < 1 || parsed > 65535 || String(parsed) !== raw.trim()) {
13718
- throw new Error(
13719
- `RIVET_PORT env var must be an integer between 1 and 65535; got "${raw}"`
13720
- );
13721
- }
13722
- return parsed;
13723
- }
13724
- var getLogLevel = () => getEnvUniversal("RIVET_LOG_LEVEL") ?? getEnvUniversal("LOG_LEVEL");
13725
- var getLogTarget = () => getEnvUniversal("RIVET_LOG_TARGET") === "1";
13726
- var getLogTimestamp = () => getEnvUniversal("RIVET_LOG_TIMESTAMP") === "1";
13727
- var getLogMessage = () => getEnvUniversal("RIVET_LOG_MESSAGE") === "1";
13728
- var getLogErrorStack = () => getEnvUniversal("RIVET_LOG_ERROR_STACK") === "1";
13729
- var getNodeEnv = () => getEnvUniversal("NODE_ENV");
13730
- var getNextPhase = () => getEnvUniversal("NEXT_PHASE");
13731
- var isDev = () => getNodeEnv() !== "production";
13732
- function assertUnreachable(x) {
13733
- throw new Error(`Unreachable case: ${x}`);
13734
- }
13735
- function deconstructError(error46, exposeInternalError = false) {
13736
- let statusCode;
13737
- let public_;
13738
- let group;
13739
- let code;
13740
- let message;
13741
- let metadata;
13742
- let rayId;
13743
- let actor2;
13744
- if (isCanonicalStructuredRivetError(error46)) {
13745
- statusCode = typeof error46.statusCode === "number" ? error46.statusCode : error46.public ? 400 : 500;
13746
- public_ = error46.public ?? false;
13747
- group = error46.group;
13748
- code = error46.code;
13749
- message = error46.message;
13750
- metadata = error46.metadata;
13751
- rayId = error46.rayId;
13752
- actor2 = error46.actor;
13753
- } else if (RivetError.isActorError(error46) && error46.public) {
13754
- statusCode = "statusCode" in error46 && error46.statusCode ? error46.statusCode : 400;
13755
- public_ = true;
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 if (exposeInternalError) {
13763
- if (RivetError.isActorError(error46)) {
13764
- statusCode = 500;
13765
- public_ = false;
13766
- group = error46.group;
13767
- code = error46.code;
13768
- message = getErrorMessage(error46);
13769
- metadata = error46.metadata;
13770
- rayId = error46.rayId;
13771
- actor2 = error46.actor;
13772
- } else {
13773
- statusCode = 500;
13774
- public_ = false;
13775
- group = "rivetkit";
13776
- code = INTERNAL_ERROR_CODE;
13777
- message = getErrorMessage(error46);
13778
- }
13779
- } else {
13780
- statusCode = 500;
13781
- public_ = false;
13782
- group = "rivetkit";
13783
- code = INTERNAL_ERROR_CODE;
13784
- message = INTERNAL_ERROR_DESCRIPTION;
13785
- if (RivetError.isActorError(error46)) {
13786
- actor2 = error46.actor;
13787
- }
13788
- metadata = {
13789
- //url: `https://dashboard.rivet.dev/projects/${actorMetadata.project.slug}/environments/${actorMetadata.environment.slug}/actors?actorId=${actorMetadata.actor.id}`,
13790
- };
13791
- }
13792
- return {
13793
- __type: "ActorError",
13794
- statusCode,
13795
- public: public_,
13796
- group,
13797
- code,
13798
- message,
13799
- metadata,
13800
- rayId,
13801
- actor: actor2
13802
- };
13803
- }
13804
- function stringifyError(error46) {
13805
- if (error46 instanceof Error) {
13806
- if (typeof process !== "undefined" && getLogErrorStack()) {
13807
- let stack;
13808
- try {
13809
- stack = error46.stack;
13810
- } catch {
13811
- stack = void 0;
13812
- }
13813
- return `${error46.name}: ${error46.message}${stack ? `
13814
- ${stack}` : ""}`;
13815
- } else {
13816
- return `${error46.name}: ${error46.message}`;
13817
- }
13818
- } else if (typeof error46 === "string") {
13819
- return error46;
13820
- } else if (typeof error46 === "object" && error46 !== null) {
13821
- try {
13822
- return `${JSON.stringify(error46)}`;
13823
- } catch {
13824
- return "[cannot stringify error]";
13825
- }
13826
- } else {
13827
- return `Unknown error: ${getErrorMessage(error46)}`;
13828
- }
13829
- }
13830
- function getErrorMessage(err) {
13831
- if (err && typeof err === "object" && "message" in err && typeof err.message === "string") {
13832
- return err.message;
13833
- } else {
13834
- return String(err);
13835
- }
13836
- }
13837
- function noopNext() {
13838
- return async () => {
13839
- };
13344
+ function noopNext() {
13345
+ return async () => {
13346
+ };
13840
13347
  }
13841
13348
  var package_default = {
13842
13349
  name: "rivetkit",
13843
- version: "2.3.32",
13350
+ version: "2.3.34",
13844
13351
  description: "Lightweight libraries for building stateful actors on edge platforms",
13845
13352
  license: "Apache-2.0",
13846
13353
  keywords: [
@@ -15144,7 +14651,7 @@ function Config({ initialBufferLength = 1024, maxBufferLength = 1024 * 1024 * 32
15144
14651
  };
15145
14652
  }
15146
14653
 
15147
- // ../rivetkit/dist/tsup/chunk-IVX7KBSQ.js
14654
+ // ../rivetkit/dist/tsup/chunk-WCPWIVQ2.js
15148
14655
  var config2 = /* @__PURE__ */ Config({});
15149
14656
  function readWorkflowCbor(bc) {
15150
14657
  return readData(bc);
@@ -15436,11 +14943,506 @@ function decodeWorkflowHistory(bytes) {
15436
14943
  if (bc.offset < bc.view.byteLength) {
15437
14944
  throw new BareError(bc.offset, "remaining bytes");
15438
14945
  }
15439
- return result;
14946
+ return result;
14947
+ }
14948
+ function decodeWorkflowHistoryTransport(data) {
14949
+ return decodeWorkflowHistory(toUint8Array(data));
14950
+ }
14951
+
14952
+ // ../rivetkit/dist/tsup/chunk-6FEYCVZC.js
14953
+ function flattenActionHandlers(actions) {
14954
+ const flattened = /* @__PURE__ */ Object.create(null);
14955
+ for (const { name, handler } of collectActionEntries(actions)) {
14956
+ flattened[name] = handler;
14957
+ }
14958
+ return flattened;
14959
+ }
14960
+ function flattenActionInputSchemas(actions, schemas) {
14961
+ if (schemas === void 0) return void 0;
14962
+ if (!isRecord(schemas)) {
14963
+ throw new TypeError("actionInputSchemas must be an object");
14964
+ }
14965
+ const flattened = /* @__PURE__ */ Object.create(null);
14966
+ for (const { name, path: path2 } of collectActionEntries(actions)) {
14967
+ const nestedSchema = lookupNestedSchema(schemas, path2);
14968
+ const flatSchema = schemas[name];
14969
+ if (nestedSchema !== void 0 && flatSchema !== void 0 && nestedSchema !== flatSchema) {
14970
+ throw new TypeError(
14971
+ `Action input schema \`${name}\` is defined by both a nested path and a dotted key`
14972
+ );
14973
+ }
14974
+ const schema = nestedSchema ?? flatSchema;
14975
+ if (schema !== void 0) {
14976
+ flattened[name] = schema;
14977
+ }
14978
+ }
14979
+ return flattened;
14980
+ }
14981
+ function flattenActionTraceSamplers(actions, rates = {}) {
14982
+ const handlers = flattenActionHandlers(actions);
14983
+ const flattened = Object.fromEntries(flattenSampleRates(rates, []));
14984
+ for (const name of Object.keys(flattened)) {
14985
+ if (!Object.hasOwn(handlers, name)) {
14986
+ throw new TypeError(
14987
+ `tracing.actions.${name} does not name an action`
14988
+ );
14989
+ }
14990
+ }
14991
+ return flattened;
14992
+ }
14993
+ function flattenSampleRates(rates, path2) {
14994
+ return Object.entries(rates).flatMap(
14995
+ ([segment, rate]) => {
14996
+ const childPath = [...path2, segment];
14997
+ return typeof rate === "number" ? [[childPath.join("."), rate]] : flattenSampleRates(rate, childPath);
14998
+ }
14999
+ );
15000
+ }
15001
+ function collectActionEntries(actions) {
15002
+ const entries = [];
15003
+ const names = /* @__PURE__ */ new Set();
15004
+ visitActionGroup(actions ?? {}, [], entries, names);
15005
+ return entries;
15006
+ }
15007
+ function visitActionGroup(value, path2, entries, names) {
15008
+ if (!isRecord(value)) {
15009
+ throw new TypeError(
15010
+ `${formatActionPath(path2)} must be an action handler or group`
15011
+ );
15012
+ }
15013
+ for (const [segment, child] of Object.entries(value)) {
15014
+ const childPath = [...path2, segment];
15015
+ if (typeof child === "function") {
15016
+ const name = childPath.join(".");
15017
+ if (names.has(name)) {
15018
+ throw new TypeError(
15019
+ `Multiple action definitions flatten to \`${name}\``
15020
+ );
15021
+ }
15022
+ names.add(name);
15023
+ entries.push({
15024
+ name,
15025
+ path: childPath,
15026
+ handler: child
15027
+ });
15028
+ } else {
15029
+ visitActionGroup(child, childPath, entries, names);
15030
+ }
15031
+ }
15032
+ }
15033
+ function lookupNestedSchema(schemas, path2) {
15034
+ let value = schemas;
15035
+ for (const segment of path2) {
15036
+ if (!isRecord(value) || !Object.hasOwn(value, segment)) {
15037
+ return void 0;
15038
+ }
15039
+ value = value[segment];
15040
+ }
15041
+ return value;
15042
+ }
15043
+ function isRecord(value) {
15044
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
15045
+ return false;
15046
+ }
15047
+ const prototype = Object.getPrototypeOf(value);
15048
+ return prototype === Object.prototype || prototype === null;
15049
+ }
15050
+ function formatActionPath(path2) {
15051
+ return path2.length === 0 ? "actions" : `Action \`${path2.join(".")}\``;
15052
+ }
15053
+ var DEFAULT_SLEEP_GRACE_PERIOD = 15e3;
15054
+ var ACTOR_CONTEXT_INTERNAL_SYMBOL = /* @__PURE__ */ Symbol(
15055
+ "rivetkit.actor_context_internal"
15056
+ );
15057
+ var RAW_STATE_SYMBOL = /* @__PURE__ */ Symbol("rivetkit.raw_state");
15058
+ var CONN_STATE_MANAGER_SYMBOL = /* @__PURE__ */ Symbol("rivetkit.conn_state_manager");
15059
+ var zFunction = () => external_exports.custom((val) => typeof val === "function");
15060
+ var zActionTree = external_exports.custom((value) => {
15061
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
15062
+ return false;
15063
+ }
15064
+ const prototype = Object.getPrototypeOf(value);
15065
+ return prototype === Object.prototype || prototype === null;
15066
+ }).superRefine((actions, ctx) => {
15067
+ try {
15068
+ flattenActionHandlers(actions);
15069
+ } catch (error46) {
15070
+ ctx.addIssue({
15071
+ code: "custom",
15072
+ message: error46 instanceof Error ? error46.message : "Invalid action definition"
15073
+ });
15074
+ }
15075
+ });
15076
+ var WorkflowInspectorConfigSchema = external_exports.object({
15077
+ getHistory: zFunction(),
15078
+ getState: zFunction().optional(),
15079
+ onHistoryUpdated: zFunction().optional(),
15080
+ replayFromStep: zFunction().optional()
15081
+ });
15082
+ var RunInspectorConfigSchema = external_exports.object({
15083
+ workflow: WorkflowInspectorConfigSchema.optional()
15084
+ }).optional();
15085
+ var BUILTIN_INSPECTOR_TAB_IDS = [
15086
+ "workflow",
15087
+ "database",
15088
+ "state",
15089
+ "queue",
15090
+ "schedules",
15091
+ "connections",
15092
+ "console"
15093
+ ];
15094
+ var BuiltinInspectorTabIdSchema = external_exports.enum(BUILTIN_INSPECTOR_TAB_IDS);
15095
+ var CUSTOM_INSPECTOR_TAB_ID_RE = /^[A-Za-z0-9_-]+$/;
15096
+ var CustomInspectorTabEntrySchema = external_exports.object({
15097
+ id: external_exports.string().regex(
15098
+ CUSTOM_INSPECTOR_TAB_ID_RE,
15099
+ "inspector.tabs[].id must contain only letters, digits, underscore, or dash"
15100
+ ),
15101
+ label: external_exports.string().min(1),
15102
+ source: external_exports.string().min(1),
15103
+ /**
15104
+ * Optional icon id. The dashboard maps strings to glyphs (see its
15105
+ * icon registry); unknown ids fall back to a generic icon.
15106
+ */
15107
+ icon: external_exports.string().min(1).optional(),
15108
+ hidden: external_exports.literal(false).optional()
15109
+ }).strict();
15110
+ var HideInspectorTabEntrySchema = external_exports.object({
15111
+ id: BuiltinInspectorTabIdSchema,
15112
+ hidden: external_exports.literal(true)
15113
+ }).strict();
15114
+ var InspectorTabEntrySchema = external_exports.union([
15115
+ CustomInspectorTabEntrySchema,
15116
+ HideInspectorTabEntrySchema
15117
+ ]);
15118
+ var ActorInspectorConfigSchema = external_exports.object({
15119
+ tabs: external_exports.array(InspectorTabEntrySchema).default(() => [])
15120
+ }).strict().refine(
15121
+ (data) => {
15122
+ const ids = data.tabs.map((t) => t.id);
15123
+ return new Set(ids).size === ids.length;
15124
+ },
15125
+ { message: "Duplicate id in inspector.tabs", path: ["tabs"] }
15126
+ ).refine(
15127
+ (data) => {
15128
+ const builtinSet = new Set(BUILTIN_INSPECTOR_TAB_IDS);
15129
+ return data.tabs.every(
15130
+ (t) => t.hidden === true || !builtinSet.has(t.id)
15131
+ );
15132
+ },
15133
+ {
15134
+ message: "Custom inspector tab id collides with a built-in (use hidden: true to hide a built-in)",
15135
+ path: ["tabs"]
15136
+ }
15137
+ );
15138
+ var RunConfigSchema = external_exports.object({
15139
+ /** Display name for the actor in the Inspector UI. */
15140
+ name: external_exports.string().optional(),
15141
+ /** Icon for the actor in the Inspector UI. Can be an emoji or FontAwesome icon name. */
15142
+ icon: external_exports.string().optional(),
15143
+ /** The run handler function. */
15144
+ run: zFunction(),
15145
+ /** Inspector integration for long-running run handlers. */
15146
+ inspector: RunInspectorConfigSchema.optional()
15147
+ });
15148
+ var RUN_FUNCTION_CONFIG_SYMBOL = /* @__PURE__ */ Symbol.for("rivetkit.run_function_config");
15149
+ function defineRunHandler(run, options) {
15150
+ if (options.inspectorKind === void 0 !== (options.createInspector === void 0)) {
15151
+ throw new TypeError(
15152
+ "defineRunHandler requires inspectorKind and createInspector together"
15153
+ );
15154
+ }
15155
+ Object.defineProperty(run, RUN_FUNCTION_CONFIG_SYMBOL, {
15156
+ configurable: false,
15157
+ enumerable: false,
15158
+ writable: false,
15159
+ value: {
15160
+ name: options.name,
15161
+ icon: options.icon,
15162
+ inspectorKind: options.inspectorKind,
15163
+ createInspector: options.createInspector
15164
+ }
15165
+ });
15166
+ return run;
15167
+ }
15168
+ function getRunInspectorKind(run) {
15169
+ var _a2;
15170
+ if (!run || typeof run !== "function") return void 0;
15171
+ return (_a2 = run[RUN_FUNCTION_CONFIG_SYMBOL]) == null ? void 0 : _a2.inspectorKind;
15172
+ }
15173
+ function createRunInspector(run, context2) {
15174
+ var _a2, _b;
15175
+ if (!run || typeof run !== "function") return void 0;
15176
+ return (_b = (_a2 = run[RUN_FUNCTION_CONFIG_SYMBOL]) == null ? void 0 : _a2.createInspector) == null ? void 0 : _b.call(_a2, context2);
15177
+ }
15178
+ var zRunHandler = external_exports.union([zFunction(), RunConfigSchema]).optional();
15179
+ function getRunFunction(run) {
15180
+ if (!run) return void 0;
15181
+ if (typeof run === "function") return run;
15182
+ return run.run;
15183
+ }
15184
+ function getRunMetadata(run) {
15185
+ if (!run) return {};
15186
+ if (typeof run === "function") {
15187
+ const config3 = run[RUN_FUNCTION_CONFIG_SYMBOL];
15188
+ if (!config3) return {};
15189
+ return { name: config3.name, icon: config3.icon };
15190
+ }
15191
+ return { name: run.name, icon: run.icon };
15440
15192
  }
15441
- function decodeWorkflowHistoryTransport(data) {
15442
- return decodeWorkflowHistory(toUint8Array(data));
15193
+ function getRunInspectorConfig(run, actor2) {
15194
+ if (!run) return void 0;
15195
+ if (typeof run === "function") {
15196
+ const config3 = run[RUN_FUNCTION_CONFIG_SYMBOL];
15197
+ return (config3 == null ? void 0 : config3.inspectorFactory) ? config3.inspectorFactory(actor2) : config3 == null ? void 0 : config3.inspector;
15198
+ }
15199
+ return run.inspector;
15200
+ }
15201
+ function hasRunInspectorConfig(run) {
15202
+ if (!run) return false;
15203
+ if (typeof run !== "function") return run.inspector !== void 0;
15204
+ const config3 = run[RUN_FUNCTION_CONFIG_SYMBOL];
15205
+ 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;
15206
+ }
15207
+ function disposeRunInspector(run, actorId) {
15208
+ var _a2;
15209
+ if (!run || typeof run !== "function") {
15210
+ return;
15211
+ }
15212
+ const config3 = run[RUN_FUNCTION_CONFIG_SYMBOL];
15213
+ (_a2 = config3 == null ? void 0 : config3.disposeInspector) == null ? void 0 : _a2.call(config3, actorId);
15443
15214
  }
15215
+ var GlobalActorOptionsBaseSchema = external_exports.object({
15216
+ /** Display name for the actor in the Inspector UI. */
15217
+ name: external_exports.string().optional(),
15218
+ /** Icon for the actor in the Inspector UI. Can be an emoji or FontAwesome icon name. */
15219
+ icon: external_exports.string().optional(),
15220
+ /** Enables the experimental Actor Runtime Socket for this actor. */
15221
+ enableActorRuntimeSocket: external_exports.boolean().default(false),
15222
+ /**
15223
+ * Can hibernate WebSockets, both client connections for actions and
15224
+ * events and WebSockets for onWebSocket. A WebSocket that does not
15225
+ * hibernate closes when the actor sleeps, and the client reconnects.
15226
+ *
15227
+ * @experimental
15228
+ **/
15229
+ canHibernateWebSocket: external_exports.union([external_exports.boolean(), zFunction()]).default(false)
15230
+ }).strict();
15231
+ var GlobalActorOptionsSchema = GlobalActorOptionsBaseSchema.prefault(
15232
+ () => ({})
15233
+ );
15234
+ var InstanceActorOptionsBaseSchema = external_exports.object({
15235
+ createVarsTimeout: external_exports.number().positive().default(5e3),
15236
+ createConnStateTimeout: external_exports.number().positive().default(5e3),
15237
+ onBeforeConnectTimeout: external_exports.number().positive().default(5e3),
15238
+ onConnectTimeout: external_exports.number().positive().default(5e3),
15239
+ onMigrateTimeout: external_exports.number().positive().default(3e4),
15240
+ sleepGracePeriod: external_exports.number().positive().default(DEFAULT_SLEEP_GRACE_PERIOD),
15241
+ /** @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. */
15242
+ onDestroyTimeout: external_exports.number().positive().optional(),
15243
+ /** @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. */
15244
+ waitUntilTimeout: external_exports.number().positive().optional(),
15245
+ stateSaveInterval: external_exports.number().positive().default(1e3),
15246
+ actionTimeout: external_exports.number().positive().default(6e4),
15247
+ connectionLivenessTimeout: external_exports.number().positive().default(2500),
15248
+ connectionLivenessInterval: external_exports.number().positive().default(5e3),
15249
+ /** @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. */
15250
+ noSleep: external_exports.boolean().default(false),
15251
+ sleepTimeout: external_exports.number().positive().default(3e4),
15252
+ maxQueueSize: external_exports.number().positive().default(1e3),
15253
+ /** Maximum pending one-shot and recurring schedules. */
15254
+ maxSchedules: external_exports.number().int().nonnegative().default(1e3),
15255
+ maxQueueMessageSize: external_exports.number().positive().default(64 * 1024),
15256
+ /** @deprecated Internal storage moved to SQLite and no longer uses KV preloading, so this option is ignored. Will be removed in 2.2.0. */
15257
+ preloadMaxWorkflowBytes: external_exports.number().nonnegative().optional(),
15258
+ /** @deprecated Internal storage moved to SQLite and no longer uses KV preloading, so this option is ignored. Will be removed in 2.2.0. */
15259
+ preloadMaxConnectionsBytes: external_exports.number().nonnegative().optional()
15260
+ }).strict();
15261
+ var InstanceActorOptionsSchema = InstanceActorOptionsBaseSchema.prefault(() => ({}));
15262
+ var ActorOptionsSchema = GlobalActorOptionsBaseSchema.extend(
15263
+ InstanceActorOptionsBaseSchema.shape
15264
+ ).strict().prefault(() => ({}));
15265
+ var zSampleRate = external_exports.number().min(0).max(1);
15266
+ var zActionSampleRates = external_exports.lazy(
15267
+ () => external_exports.record(external_exports.string(), external_exports.union([zSampleRate, zActionSampleRates]))
15268
+ );
15269
+ var ActorConfigSchema = external_exports.object({
15270
+ onCreate: zFunction().optional(),
15271
+ onDestroy: zFunction().optional(),
15272
+ onMigrate: zFunction().optional(),
15273
+ onWake: zFunction().optional(),
15274
+ onSleep: zFunction().optional(),
15275
+ run: zRunHandler,
15276
+ onStateChange: zFunction().optional(),
15277
+ onBeforeConnect: zFunction().optional(),
15278
+ onConnect: zFunction().optional(),
15279
+ onDisconnect: zFunction().optional(),
15280
+ onBeforeActionResponse: zFunction().optional(),
15281
+ onRequest: zFunction().optional(),
15282
+ onWebSocket: zFunction().optional(),
15283
+ actions: zActionTree.default(() => ({})),
15284
+ actionInputSchemas: external_exports.record(external_exports.string(), external_exports.any()).optional(),
15285
+ tracing: external_exports.object({
15286
+ sampler: zSampleRate.optional(),
15287
+ actions: zActionSampleRates.optional()
15288
+ }).strict().optional(),
15289
+ connParamsSchema: external_exports.any().optional(),
15290
+ events: external_exports.record(external_exports.string(), external_exports.any()).optional(),
15291
+ queues: external_exports.record(external_exports.string(), external_exports.any()).optional(),
15292
+ state: external_exports.any().optional(),
15293
+ createState: zFunction().optional(),
15294
+ connState: external_exports.any().optional(),
15295
+ createConnState: zFunction().optional(),
15296
+ vars: external_exports.any().optional(),
15297
+ db: external_exports.any().optional(),
15298
+ createVars: zFunction().optional(),
15299
+ options: ActorOptionsSchema,
15300
+ inspector: ActorInspectorConfigSchema.optional()
15301
+ }).strict().refine(
15302
+ (data) => !(data.state !== void 0 && data.createState !== void 0),
15303
+ {
15304
+ message: "Cannot define both 'state' and 'createState'",
15305
+ path: ["state"]
15306
+ }
15307
+ ).refine(
15308
+ (data) => !(data.connState !== void 0 && data.createConnState !== void 0),
15309
+ {
15310
+ message: "Cannot define both 'connState' and 'createConnState'",
15311
+ path: ["connState"]
15312
+ }
15313
+ ).refine(
15314
+ (data) => !(data.vars !== void 0 && data.createVars !== void 0),
15315
+ {
15316
+ message: "Cannot define both 'vars' and 'createVars'",
15317
+ path: ["vars"]
15318
+ }
15319
+ );
15320
+ var DocActorOptionsSchema = external_exports.object({
15321
+ name: external_exports.string().optional().describe("Display name for the actor in the Inspector UI."),
15322
+ icon: external_exports.string().optional().describe(
15323
+ "Icon for the actor in the Inspector UI. Can be an emoji (e.g., '\u{1F680}') or FontAwesome icon name (e.g., 'rocket')."
15324
+ ),
15325
+ enableActorRuntimeSocket: external_exports.boolean().optional().describe(
15326
+ "Enables the experimental Actor Runtime Socket for this actor. Default: false"
15327
+ ),
15328
+ createVarsTimeout: external_exports.number().optional().describe("Timeout in ms for createVars handler. Default: 5000"),
15329
+ createConnStateTimeout: external_exports.number().optional().describe(
15330
+ "Timeout in ms for createConnState handler. Default: 5000"
15331
+ ),
15332
+ onMigrateTimeout: external_exports.number().optional().describe("Timeout in ms for onMigrate handler. Default: 30000"),
15333
+ onBeforeConnectTimeout: external_exports.number().optional().describe(
15334
+ "Timeout in ms for onBeforeConnect handler. Default: 5000"
15335
+ ),
15336
+ onConnectTimeout: external_exports.number().optional().describe("Timeout in ms for onConnect handler. Default: 5000"),
15337
+ sleepGracePeriod: external_exports.number().optional().describe(
15338
+ `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}.`
15339
+ ),
15340
+ onDestroyTimeout: external_exports.number().optional().describe(
15341
+ "Deprecated. Folded into sleepGracePeriod, which now bounds the entire graceful shutdown window for both sleep and destroy. Will be removed in 2.2.0."
15342
+ ),
15343
+ waitUntilTimeout: 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
+ stateSaveInterval: external_exports.number().optional().describe(
15347
+ "Interval in ms between automatic state saves. Default: 1000"
15348
+ ),
15349
+ actionTimeout: external_exports.number().optional().describe("Timeout in ms for action handlers. Default: 60000"),
15350
+ connectionLivenessTimeout: external_exports.number().optional().describe(
15351
+ "Timeout in ms for connection liveness checks. Default: 2500"
15352
+ ),
15353
+ connectionLivenessInterval: external_exports.number().optional().describe(
15354
+ "Interval in ms between connection liveness checks. Default: 5000"
15355
+ ),
15356
+ noSleep: external_exports.boolean().optional().describe(
15357
+ "Deprecated. If true, the actor will never sleep. Use c.keepAwake(promise) to scope keep-awake to a specific operation instead. Default: false"
15358
+ ),
15359
+ sleepTimeout: external_exports.number().optional().describe(
15360
+ "Time in ms of inactivity before the actor sleeps. Default: 30000"
15361
+ ),
15362
+ maxQueueSize: external_exports.number().optional().describe(
15363
+ "Maximum number of queue messages before rejecting new messages. Default: 1000"
15364
+ ),
15365
+ maxSchedules: external_exports.number().int().nonnegative().optional().describe(
15366
+ "Maximum pending one-shot and recurring schedules before rejecting new schedules. Default: 1000"
15367
+ ),
15368
+ maxQueueMessageSize: external_exports.number().optional().describe(
15369
+ "Maximum size of each queue message in bytes. Default: 65536"
15370
+ ),
15371
+ canHibernateWebSocket: external_exports.boolean().optional().describe(
15372
+ "Whether WebSockets can be hibernated, both client connections for actions and events and WebSockets using onWebSocket. A WebSocket that does not hibernate closes when the actor sleeps. Default: false"
15373
+ )
15374
+ }).describe("Actor options for timeouts and behavior configuration.");
15375
+ var DocActorConfigSchema = external_exports.object({
15376
+ state: external_exports.unknown().optional().describe(
15377
+ "Initial state value for the actor. Cannot be used with createState."
15378
+ ),
15379
+ createState: external_exports.unknown().optional().describe(
15380
+ "Function to create initial state. Receives context and input. Cannot be used with state."
15381
+ ),
15382
+ connState: external_exports.unknown().optional().describe(
15383
+ "Initial connection state value. Cannot be used with createConnState."
15384
+ ),
15385
+ createConnState: external_exports.unknown().optional().describe(
15386
+ "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."
15387
+ ),
15388
+ vars: external_exports.unknown().optional().describe(
15389
+ "Initial ephemeral variables value. Cannot be used with createVars."
15390
+ ),
15391
+ createVars: external_exports.unknown().optional().describe(
15392
+ "Function to create ephemeral variables. Receives context and driver context. Cannot be used with vars."
15393
+ ),
15394
+ db: external_exports.unknown().optional().describe("Database provider instance for the actor."),
15395
+ onCreate: external_exports.unknown().optional().describe(
15396
+ "Called when the actor is first initialized. Use to initialize state."
15397
+ ),
15398
+ onDestroy: external_exports.unknown().optional().describe("Called when the actor is destroyed."),
15399
+ onMigrate: external_exports.unknown().optional().describe(
15400
+ "Called on every actor start after persisted state loads and before onWake. Use for repeatable schema migrations."
15401
+ ),
15402
+ onWake: external_exports.unknown().optional().describe(
15403
+ "Called when the actor wakes up and is ready to receive connections and actions."
15404
+ ),
15405
+ onSleep: external_exports.unknown().optional().describe(
15406
+ "Called when the actor is stopping or sleeping. Use to clean up resources."
15407
+ ),
15408
+ run: external_exports.unknown().optional().describe(
15409
+ "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."
15410
+ ),
15411
+ onStateChange: external_exports.unknown().optional().describe(
15412
+ "Called when the actor's state changes. State changes within this hook won't trigger recursion."
15413
+ ),
15414
+ onBeforeConnect: external_exports.unknown().optional().describe(
15415
+ "Called before a client connects. Throw an error to reject the connection. The pending connection is not visible in c.conns while this runs."
15416
+ ),
15417
+ onConnect: external_exports.unknown().optional().describe(
15418
+ "Called when a client successfully connects. The connection is visible in c.conns before this runs."
15419
+ ),
15420
+ onDisconnect: external_exports.unknown().optional().describe("Called when a client disconnects."),
15421
+ onBeforeActionResponse: external_exports.unknown().optional().describe(
15422
+ "Called before sending an action response. Use to transform output."
15423
+ ),
15424
+ onRequest: external_exports.unknown().optional().describe(
15425
+ "Called for raw HTTP requests to /actors/{name}/http/* endpoints."
15426
+ ),
15427
+ onWebSocket: external_exports.unknown().optional().describe(
15428
+ "Called for raw WebSocket connections to /actors/{name}/websocket/* endpoints."
15429
+ ),
15430
+ actions: external_exports.record(external_exports.string(), external_exports.unknown()).optional().describe(
15431
+ "Tree of action names or nested groups to handler functions. Nested paths use dot-separated low-level action names. Defaults to an empty object."
15432
+ ),
15433
+ actionInputSchemas: external_exports.record(external_exports.string(), external_exports.unknown()).optional().describe(
15434
+ "Optional schemas for validating action argument tuples in native runtimes. May mirror nested action groups or use dot-separated low-level action names."
15435
+ ),
15436
+ tracing: external_exports.unknown().optional().describe(
15437
+ "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."
15438
+ ),
15439
+ connParamsSchema: external_exports.unknown().optional().describe(
15440
+ "Optional schema for validating connection params in native runtimes."
15441
+ ),
15442
+ events: external_exports.record(external_exports.string(), external_exports.unknown()).optional().describe("Map of event names to schemas."),
15443
+ queues: external_exports.record(external_exports.string(), external_exports.unknown()).optional().describe("Map of queue names to schemas."),
15444
+ options: DocActorOptionsSchema.optional()
15445
+ }).describe("Actor configuration passed to the actor() function.");
15444
15446
 
15445
15447
  // ../rivetkit/dist/tsup/chunk-JI6GZ2C2.js
15446
15448
  var EMPTY_KEY = "/";
@@ -15559,7 +15561,7 @@ function removePrefixFromKey(prefixedKey) {
15559
15561
  return prefixedKey.slice(KEYS.KV.length);
15560
15562
  }
15561
15563
 
15562
- // ../rivetkit/dist/tsup/chunk-EOYS5GVX.js
15564
+ // ../rivetkit/dist/tsup/chunk-WNPBKWLZ.js
15563
15565
  function logger() {
15564
15566
  return getLogger("actor-client");
15565
15567
  }
@@ -15680,7 +15682,7 @@ var AsyncMutex = class {
15680
15682
  }
15681
15683
  };
15682
15684
 
15683
- // ../rivetkit/dist/tsup/chunk-7VIY7WIH.js
15685
+ // ../rivetkit/dist/tsup/chunk-VLK3NAEM.js
15684
15686
  var import_invariant2 = __toESM(require_invariant(), 1);
15685
15687
 
15686
15688
  // ../../../node_modules/.pnpm/p-retry@6.2.1/node_modules/p-retry/index.js
@@ -16895,7 +16897,7 @@ var TraceAPI = (
16895
16897
  // ../../../node_modules/.pnpm/@opentelemetry+api@1.9.0/node_modules/@opentelemetry/api/build/esm/trace-api.js
16896
16898
  var trace = TraceAPI.getInstance();
16897
16899
 
16898
- // ../rivetkit/dist/tsup/chunk-7VIY7WIH.js
16900
+ // ../rivetkit/dist/tsup/chunk-VLK3NAEM.js
16899
16901
  var import_invariant3 = __toESM(require_invariant(), 1);
16900
16902
  var import_invariant4 = __toESM(require_invariant(), 1);
16901
16903
  var PATH_CONNECT = "/connect";
@@ -23091,7 +23093,7 @@ function apiActorToOutput(actor2) {
23091
23093
  };
23092
23094
  }
23093
23095
 
23094
- // ../rivetkit/dist/tsup/chunk-XWEGENG4.js
23096
+ // ../rivetkit/dist/tsup/chunk-ZVCLBO26.js
23095
23097
  var nativeStateTransactionOpeners = /* @__PURE__ */ new WeakMap();
23096
23098
  var nativeStateTransactionClientBinders = /* @__PURE__ */ new WeakMap();
23097
23099
  function registerNativeStateTransactionOpener(provider, opener) {