@rivetkit/supabase 2.3.30 → 2.3.32

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 +2288 -2290
  2. package/dist/mod.mjs +2290 -2292
  3. package/package.json +3 -3
package/dist/mod.js CHANGED
@@ -335,212 +335,6 @@ __export(mod_exports, {
335
335
  module.exports = __toCommonJS(mod_exports);
336
336
  var wasmBindings = __toESM(require("@rivetkit/rivetkit-wasm"));
337
337
 
338
- // ../rivetkit/dist/tsup/chunk-ZOVJDAOW.js
339
- var INTERNAL_ERROR_CODE = "internal_error";
340
- var INTERNAL_ERROR_DESCRIPTION = "An internal error occurred";
341
- var USER_ERROR_CODE = "user_error";
342
- var BRIDGE_RIVET_ERROR_PREFIX = "__RIVET_ERROR_JSON__:";
343
- function looksLikeRivetErrorOptions(value) {
344
- return typeof value === "object" && value !== null && ("public" in value || "metadata" in value || "rayId" in value || "statusCode" in value || "actor" in value || "cause" in value);
345
- }
346
- function isTypedErrorTag(value) {
347
- return value === "ActorError" || value === "RivetError";
348
- }
349
- function errorMessage(error46, fallback = String(error46)) {
350
- if (error46 && typeof error46 === "object" && "message" in error46 && typeof error46.message === "string") {
351
- return error46.message;
352
- }
353
- return fallback;
354
- }
355
- function isRivetErrorLike(error46) {
356
- return typeof error46 === "object" && error46 !== null && "group" in error46 && typeof error46.group === "string" && "code" in error46 && typeof error46.code === "string" && "message" in error46 && typeof error46.message === "string" && (!("rayId" in error46) || error46.rayId === void 0 || typeof error46.rayId === "string") && (!("__type" in error46) || isTypedErrorTag(error46.__type));
357
- }
358
- function isActorAbortedError(error46) {
359
- return isRivetErrorLike(error46) && error46.group === "actor" && error46.code === "aborted";
360
- }
361
- function isActorSpecifier(value) {
362
- return typeof value === "object" && value !== null && "actorId" in value && typeof value.actorId === "string" && "generation" in value && typeof value.generation === "number" && (!("key" in value) || value.key === void 0 || typeof value.key === "string");
363
- }
364
- var RivetError = class extends Error {
365
- __type = "RivetError";
366
- public;
367
- metadata;
368
- rayId;
369
- statusCode;
370
- actor;
371
- group;
372
- code;
373
- static isRivetError(error46) {
374
- return isRivetErrorLike(error46);
375
- }
376
- static isActorError(error46) {
377
- return isRivetErrorLike(error46);
378
- }
379
- constructor(group, code, message, options) {
380
- const normalized = looksLikeRivetErrorOptions(options) ? options : { metadata: options };
381
- super(message, { cause: normalized.cause });
382
- this.name = "RivetError";
383
- this.group = group;
384
- this.code = code;
385
- this.public = normalized.public ?? false;
386
- this.metadata = normalized.metadata;
387
- this.rayId = normalized.rayId ?? void 0;
388
- this.statusCode = normalized.statusCode ?? (this.public ? 400 : 500);
389
- this.actor = normalized.actor;
390
- }
391
- toString() {
392
- return this.message;
393
- }
394
- };
395
- var UserError = class extends RivetError {
396
- constructor(message, options) {
397
- super("user", (options == null ? void 0 : options.code) ?? USER_ERROR_CODE, message, {
398
- public: true,
399
- metadata: options == null ? void 0 : options.metadata,
400
- cause: options == null ? void 0 : options.cause
401
- });
402
- }
403
- };
404
- function toRivetError(error46, fallback) {
405
- if (typeof error46 === "string") {
406
- const bridged = decodeBridgeRivetError(error46);
407
- if (bridged) {
408
- return bridged;
409
- }
410
- }
411
- if (error46 instanceof Error) {
412
- const bridged = decodeBridgeRivetError(error46.message);
413
- if (bridged) {
414
- return bridged;
415
- }
416
- }
417
- if (isRivetErrorLike(error46)) {
418
- return new RivetError(error46.group, error46.code, error46.message, {
419
- public: error46.public,
420
- statusCode: error46.statusCode,
421
- metadata: error46.metadata,
422
- rayId: error46.rayId,
423
- actor: error46.actor,
424
- cause: error46 instanceof Error ? error46.cause : void 0
425
- });
426
- }
427
- return new RivetError(
428
- (fallback == null ? void 0 : fallback.group) ?? "actor",
429
- (fallback == null ? void 0 : fallback.code) ?? INTERNAL_ERROR_CODE,
430
- errorMessage(error46, (fallback == null ? void 0 : fallback.message) ?? "Unknown error"),
431
- {
432
- public: fallback == null ? void 0 : fallback.public,
433
- statusCode: fallback == null ? void 0 : fallback.statusCode,
434
- metadata: fallback == null ? void 0 : fallback.metadata,
435
- rayId: fallback == null ? void 0 : fallback.rayId,
436
- actor: fallback == null ? void 0 : fallback.actor,
437
- cause: error46 instanceof Error ? error46 : void 0
438
- }
439
- );
440
- }
441
- function encodeBridgeRivetError(error46) {
442
- const payload = {
443
- group: error46.group,
444
- code: error46.code,
445
- message: error46.message,
446
- metadata: error46.metadata,
447
- rayId: error46.rayId,
448
- public: error46.public,
449
- statusCode: error46.statusCode,
450
- actor: error46.actor
451
- };
452
- try {
453
- return {
454
- encoded: `${BRIDGE_RIVET_ERROR_PREFIX}${JSON.stringify(payload)}`
455
- };
456
- } catch (cause) {
457
- return {
458
- encoded: `${BRIDGE_RIVET_ERROR_PREFIX}${JSON.stringify({ ...payload, metadata: void 0 })}`,
459
- droppedMetadataCause: cause
460
- };
461
- }
462
- }
463
- function encodeErrorForBridge(error46) {
464
- if (isCanonicalStructuredRivetError(error46)) {
465
- return encodeBridgeRivetError(error46).encoded;
466
- }
467
- return String(error46);
468
- }
469
- function isCanonicalStructuredRivetError(error46) {
470
- return error46 instanceof RivetError || typeof error46 === "object" && error46 !== null && "__type" in error46 && error46.__type === "RivetError" && "group" in error46 && typeof error46.group === "string" && "code" in error46 && typeof error46.code === "string" && "message" in error46 && typeof error46.message === "string";
471
- }
472
- function decodeBridgeRivetErrorPayload(value) {
473
- if (!value.startsWith(BRIDGE_RIVET_ERROR_PREFIX)) {
474
- return void 0;
475
- }
476
- try {
477
- const raw = JSON.parse(
478
- value.slice(BRIDGE_RIVET_ERROR_PREFIX.length)
479
- );
480
- const payload = {
481
- ...raw,
482
- rayId: raw.rayId ?? void 0
483
- };
484
- if (!isRivetErrorLike(payload)) {
485
- return void 0;
486
- }
487
- if (payload.actor !== void 0 && payload.actor !== null && !isActorSpecifier(payload.actor)) {
488
- return void 0;
489
- }
490
- return payload;
491
- } catch {
492
- return void 0;
493
- }
494
- }
495
- function decodeBridgeRivetError(value) {
496
- const payload = decodeBridgeRivetErrorPayload(value);
497
- if (!payload) {
498
- return void 0;
499
- }
500
- return new RivetError(payload.group, payload.code, payload.message, {
501
- metadata: payload.metadata,
502
- rayId: payload.rayId,
503
- public: payload.public,
504
- statusCode: payload.statusCode,
505
- actor: payload.actor ?? void 0
506
- });
507
- }
508
- function invalidRequest(error46) {
509
- return new RivetError(
510
- "request",
511
- "invalid",
512
- `Invalid request: ${errorMessage(error46, String(error46))}`,
513
- {
514
- public: true,
515
- cause: error46 instanceof Error ? error46 : void 0
516
- }
517
- );
518
- }
519
- function actorNotFound(identifier) {
520
- return new RivetError(
521
- "actor",
522
- "not_found",
523
- identifier ? `Actor not found: ${identifier} (https://www.rivet.dev/docs/clients/javascript)` : "Actor not found (https://www.rivet.dev/docs/clients/javascript)",
524
- { public: true }
525
- );
526
- }
527
- function forbiddenError() {
528
- return new RivetError("auth", "forbidden", "Forbidden", {
529
- public: true,
530
- statusCode: 403
531
- });
532
- }
533
- function unsupportedFeature(feature) {
534
- return new RivetError(
535
- "feature",
536
- "unsupported",
537
- `Unsupported feature: ${feature}`
538
- );
539
- }
540
-
541
- // ../rivetkit/dist/tsup/chunk-CORYIKDC.js
542
- var import_pino = require("pino");
543
-
544
338
  // ../../../node_modules/.pnpm/zod@4.1.13/node_modules/zod/v4/classic/external.js
545
339
  var external_exports = {};
546
340
  __export(external_exports, {
@@ -13211,2273 +13005,2477 @@ var classic_default = external_exports;
13211
13005
  // ../../../node_modules/.pnpm/zod@4.1.13/node_modules/zod/v4/index.js
13212
13006
  var v4_default = classic_default;
13213
13007
 
13214
- // ../rivetkit/dist/tsup/chunk-CORYIKDC.js
13215
- var cbor = __toESM(require("cbor-x"), 1);
13216
- var import_invariant = __toESM(require_invariant(), 1);
13217
- var getRivetEngine = () => getEnvUniversal("RIVET_ENGINE");
13218
- var getRivetEndpoint = () => getEnvUniversal("RIVET_ENDPOINT");
13219
- var getRivetToken = () => getEnvUniversal("RIVET_TOKEN");
13220
- var getRivetNamespace = () => getEnvUniversal("RIVET_NAMESPACE");
13221
- var getRivetPool = () => getEnvUniversal("RIVET_POOL");
13222
- var getRivetTotalSlots = () => {
13223
- const value = getEnvUniversal("RIVET_TOTAL_SLOTS");
13224
- return value !== void 0 ? parseInt(value, 10) : void 0;
13225
- };
13226
- var getRivetRunEngine = () => getEnvUniversal("RIVET_RUN_ENGINE") === "1";
13227
- var getRivetRunEngineHost = () => getEnvUniversal("RIVET_RUN_ENGINE_HOST");
13228
- var getRivetRunEnginePort = () => {
13229
- const value = getEnvUniversal("RIVET_RUN_ENGINE_PORT");
13230
- return value !== void 0 ? parseInt(value, 10) : void 0;
13231
- };
13232
- var getRivetRunEngineVersion = () => getEnvUniversal("RIVET_RUN_ENGINE_VERSION");
13233
- var getRivetRunServices = () => {
13234
- const value = getEnvUniversal("RIVET_RUN_SERVICES");
13235
- return value === void 0 ? void 0 : value === "1";
13236
- };
13237
- var getRivetEnvoyVersion = () => {
13238
- const value = getEnvUniversal("RIVET_ENVOY_VERSION");
13239
- return value !== void 0 ? parseInt(value, 10) : void 0;
13240
- };
13241
- var getRivetPublicEndpoint = () => getEnvUniversal("RIVET_PUBLIC_ENDPOINT");
13242
- var getRivetPublicToken = () => getEnvUniversal("RIVET_PUBLIC_TOKEN");
13243
- var getRivetkitRuntime = () => getEnvUniversal("RIVETKIT_RUNTIME");
13244
- var getRivetkitRuntimeMode = () => {
13245
- const value = getEnvUniversal("RIVETKIT_RUNTIME_MODE");
13246
- if (value === void 0) return "envoy";
13247
- if (value === "envoy" || value === "serverless") return value;
13248
- throw new Error(
13249
- `RIVETKIT_RUNTIME_MODE env var must be "envoy" or "serverless"; got "${value}"`
13250
- );
13251
- };
13252
- var getRivetkitPublicDir = () => {
13253
- const value = getEnvUniversal("RIVETKIT_PUBLIC_DIR");
13254
- return value === void 0 || value === "" ? void 0 : value;
13255
- };
13256
- function parsePortEnv(raw) {
13257
- if (raw === void 0 || raw === "") return void 0;
13258
- const parsed = Number.parseInt(raw, 10);
13259
- if (!Number.isFinite(parsed) || parsed < 1 || parsed > 65535 || String(parsed) !== raw.trim()) {
13260
- throw new Error(
13261
- `RIVET_PORT env var must be an integer between 1 and 65535; got "${raw}"`
13262
- );
13263
- }
13264
- return parsed;
13265
- }
13266
- var getLogLevel = () => getEnvUniversal("RIVET_LOG_LEVEL") ?? getEnvUniversal("LOG_LEVEL");
13267
- var getLogTarget = () => getEnvUniversal("RIVET_LOG_TARGET") === "1";
13268
- var getLogTimestamp = () => getEnvUniversal("RIVET_LOG_TIMESTAMP") === "1";
13269
- var getLogMessage = () => getEnvUniversal("RIVET_LOG_MESSAGE") === "1";
13270
- var getLogErrorStack = () => getEnvUniversal("RIVET_LOG_ERROR_STACK") === "1";
13271
- var getNodeEnv = () => getEnvUniversal("NODE_ENV");
13272
- var getNextPhase = () => getEnvUniversal("NEXT_PHASE");
13273
- var isDev = () => getNodeEnv() !== "production";
13274
- function assertUnreachable(x) {
13275
- throw new Error(`Unreachable case: ${x}`);
13008
+ // ../rivetkit/dist/tsup/chunk-6FEYCVZC.js
13009
+ function flattenActionHandlers(actions) {
13010
+ const flattened = /* @__PURE__ */ Object.create(null);
13011
+ for (const { name, handler } of collectActionEntries(actions)) {
13012
+ flattened[name] = handler;
13013
+ }
13014
+ return flattened;
13276
13015
  }
13277
- function deconstructError(error46, exposeInternalError = false) {
13278
- let statusCode;
13279
- let public_;
13280
- let group;
13281
- let code;
13282
- let message;
13283
- let metadata;
13284
- let rayId;
13285
- let actor2;
13286
- if (isCanonicalStructuredRivetError(error46)) {
13287
- statusCode = typeof error46.statusCode === "number" ? error46.statusCode : error46.public ? 400 : 500;
13288
- public_ = error46.public ?? false;
13289
- group = error46.group;
13290
- code = error46.code;
13291
- message = error46.message;
13292
- metadata = error46.metadata;
13293
- rayId = error46.rayId;
13294
- actor2 = error46.actor;
13295
- } else if (RivetError.isActorError(error46) && error46.public) {
13296
- statusCode = "statusCode" in error46 && error46.statusCode ? error46.statusCode : 400;
13297
- public_ = true;
13298
- group = error46.group;
13299
- code = error46.code;
13300
- message = getErrorMessage(error46);
13301
- metadata = error46.metadata;
13302
- rayId = error46.rayId;
13303
- actor2 = error46.actor;
13304
- } else if (exposeInternalError) {
13305
- if (RivetError.isActorError(error46)) {
13306
- statusCode = 500;
13307
- public_ = false;
13308
- group = error46.group;
13309
- code = error46.code;
13310
- message = getErrorMessage(error46);
13311
- metadata = error46.metadata;
13312
- rayId = error46.rayId;
13313
- actor2 = error46.actor;
13314
- } else {
13315
- statusCode = 500;
13316
- public_ = false;
13317
- group = "rivetkit";
13318
- code = INTERNAL_ERROR_CODE;
13319
- message = getErrorMessage(error46);
13016
+ function flattenActionInputSchemas(actions, schemas) {
13017
+ if (schemas === void 0) return void 0;
13018
+ if (!isRecord(schemas)) {
13019
+ throw new TypeError("actionInputSchemas must be an object");
13020
+ }
13021
+ const flattened = /* @__PURE__ */ Object.create(null);
13022
+ for (const { name, path: path2 } of collectActionEntries(actions)) {
13023
+ const nestedSchema = lookupNestedSchema(schemas, path2);
13024
+ const flatSchema = schemas[name];
13025
+ if (nestedSchema !== void 0 && flatSchema !== void 0 && nestedSchema !== flatSchema) {
13026
+ throw new TypeError(
13027
+ `Action input schema \`${name}\` is defined by both a nested path and a dotted key`
13028
+ );
13320
13029
  }
13321
- } else {
13322
- statusCode = 500;
13323
- public_ = false;
13324
- group = "rivetkit";
13325
- code = INTERNAL_ERROR_CODE;
13326
- message = INTERNAL_ERROR_DESCRIPTION;
13327
- if (RivetError.isActorError(error46)) {
13328
- actor2 = error46.actor;
13030
+ const schema = nestedSchema ?? flatSchema;
13031
+ if (schema !== void 0) {
13032
+ flattened[name] = schema;
13329
13033
  }
13330
- metadata = {
13331
- //url: `https://dashboard.rivet.dev/projects/${actorMetadata.project.slug}/environments/${actorMetadata.environment.slug}/actors?actorId=${actorMetadata.actor.id}`,
13332
- };
13333
13034
  }
13334
- return {
13335
- __type: "ActorError",
13336
- statusCode,
13337
- public: public_,
13338
- group,
13339
- code,
13340
- message,
13341
- metadata,
13342
- rayId,
13343
- actor: actor2
13344
- };
13035
+ return flattened;
13345
13036
  }
13346
- function stringifyError(error46) {
13347
- if (error46 instanceof Error) {
13348
- if (typeof process !== "undefined" && getLogErrorStack()) {
13349
- let stack;
13350
- try {
13351
- stack = error46.stack;
13352
- } catch {
13353
- stack = void 0;
13037
+ function flattenActionTraceSamplers(actions, rates = {}) {
13038
+ const handlers = flattenActionHandlers(actions);
13039
+ const flattened = Object.fromEntries(flattenSampleRates(rates, []));
13040
+ for (const name of Object.keys(flattened)) {
13041
+ if (!Object.hasOwn(handlers, name)) {
13042
+ throw new TypeError(
13043
+ `tracing.actions.${name} does not name an action`
13044
+ );
13045
+ }
13046
+ }
13047
+ return flattened;
13048
+ }
13049
+ function flattenSampleRates(rates, path2) {
13050
+ return Object.entries(rates).flatMap(
13051
+ ([segment, rate]) => {
13052
+ const childPath = [...path2, segment];
13053
+ return typeof rate === "number" ? [[childPath.join("."), rate]] : flattenSampleRates(rate, childPath);
13054
+ }
13055
+ );
13056
+ }
13057
+ function collectActionEntries(actions) {
13058
+ const entries = [];
13059
+ const names = /* @__PURE__ */ new Set();
13060
+ visitActionGroup(actions ?? {}, [], entries, names);
13061
+ return entries;
13062
+ }
13063
+ function visitActionGroup(value, path2, entries, names) {
13064
+ if (!isRecord(value)) {
13065
+ throw new TypeError(
13066
+ `${formatActionPath(path2)} must be an action handler or group`
13067
+ );
13068
+ }
13069
+ for (const [segment, child] of Object.entries(value)) {
13070
+ const childPath = [...path2, segment];
13071
+ if (typeof child === "function") {
13072
+ const name = childPath.join(".");
13073
+ if (names.has(name)) {
13074
+ throw new TypeError(
13075
+ `Multiple action definitions flatten to \`${name}\``
13076
+ );
13354
13077
  }
13355
- return `${error46.name}: ${error46.message}${stack ? `
13356
- ${stack}` : ""}`;
13078
+ names.add(name);
13079
+ entries.push({
13080
+ name,
13081
+ path: childPath,
13082
+ handler: child
13083
+ });
13357
13084
  } else {
13358
- return `${error46.name}: ${error46.message}`;
13085
+ visitActionGroup(child, childPath, entries, names);
13359
13086
  }
13360
- } else if (typeof error46 === "string") {
13361
- return error46;
13362
- } else if (typeof error46 === "object" && error46 !== null) {
13363
- try {
13364
- return `${JSON.stringify(error46)}`;
13365
- } catch {
13366
- return "[cannot stringify error]";
13087
+ }
13088
+ }
13089
+ function lookupNestedSchema(schemas, path2) {
13090
+ let value = schemas;
13091
+ for (const segment of path2) {
13092
+ if (!isRecord(value) || !Object.hasOwn(value, segment)) {
13093
+ return void 0;
13367
13094
  }
13368
- } else {
13369
- return `Unknown error: ${getErrorMessage(error46)}`;
13095
+ value = value[segment];
13370
13096
  }
13097
+ return value;
13371
13098
  }
13372
- function getErrorMessage(err) {
13373
- if (err && typeof err === "object" && "message" in err && typeof err.message === "string") {
13374
- return err.message;
13375
- } else {
13376
- return String(err);
13099
+ function isRecord(value) {
13100
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
13101
+ return false;
13377
13102
  }
13103
+ const prototype = Object.getPrototypeOf(value);
13104
+ return prototype === Object.prototype || prototype === null;
13378
13105
  }
13379
- function noopNext() {
13380
- return async () => {
13381
- };
13106
+ function formatActionPath(path2) {
13107
+ return path2.length === 0 ? "actions" : `Action \`${path2.join(".")}\``;
13382
13108
  }
13383
- var package_default = {
13384
- name: "rivetkit",
13385
- version: "2.3.30",
13386
- description: "Lightweight libraries for building stateful actors on edge platforms",
13387
- license: "Apache-2.0",
13388
- keywords: [
13389
- "rivetkit",
13390
- "stateful",
13391
- "serverless",
13392
- "actors",
13393
- "agents",
13394
- "realtime",
13395
- "websocket",
13396
- "actors",
13397
- "framework"
13398
- ],
13399
- files: [
13400
- "dist",
13401
- "schemas",
13402
- "src",
13403
- "package.json"
13404
- ],
13405
- type: "module",
13406
- exports: {
13407
- ".": {
13408
- import: {
13409
- types: "./dist/tsup/mod.d.ts",
13410
- default: "./dist/tsup/mod.js"
13411
- },
13412
- require: {
13413
- types: "./dist/tsup/mod.d.cts",
13414
- default: "./dist/tsup/mod.cjs"
13415
- }
13416
- },
13417
- "./workflow": {
13418
- import: {
13419
- types: "./dist/tsup/workflow/mod.d.ts",
13420
- default: "./dist/tsup/workflow/mod.js"
13421
- },
13422
- require: {
13423
- types: "./dist/tsup/workflow/mod.d.cts",
13424
- default: "./dist/tsup/workflow/mod.cjs"
13425
- }
13426
- },
13427
- "./test": {
13428
- import: {
13429
- types: "./dist/tsup/test/mod.d.ts",
13430
- default: "./dist/tsup/test/mod.js"
13431
- },
13432
- require: {
13433
- types: "./dist/tsup/test/mod.d.cts",
13434
- default: "./dist/tsup/test/mod.cjs"
13435
- }
13436
- },
13437
- "./db": {
13438
- import: {
13439
- types: "./dist/tsup/db/mod.d.ts",
13440
- default: "./dist/tsup/db/mod.js"
13441
- },
13442
- require: {
13443
- types: "./dist/tsup/db/mod.d.cts",
13444
- default: "./dist/tsup/db/mod.cjs"
13445
- }
13446
- },
13447
- "./db/drizzle": {
13448
- import: {
13449
- types: "./dist/tsup/db/drizzle.d.ts",
13450
- default: "./dist/tsup/db/drizzle.js"
13451
- },
13452
- require: {
13453
- types: "./dist/tsup/db/drizzle.d.cts",
13454
- default: "./dist/tsup/db/drizzle.cjs"
13455
- }
13456
- },
13457
- "./unstable/migrations": {
13458
- import: {
13459
- types: "./dist/tsup/unstable/migrations.d.ts",
13460
- default: "./dist/tsup/unstable/migrations.js"
13461
- },
13462
- require: {
13463
- types: "./dist/tsup/unstable/migrations.d.cts",
13464
- default: "./dist/tsup/unstable/migrations.cjs"
13465
- }
13466
- },
13467
- "./dynamic": {
13468
- import: {
13469
- types: "./dist/tsup/dynamic/mod.d.ts",
13470
- default: "./dist/tsup/dynamic/mod.js"
13471
- },
13472
- require: {
13473
- types: "./dist/tsup/dynamic/mod.d.cts",
13474
- default: "./dist/tsup/dynamic/mod.cjs"
13475
- }
13476
- },
13477
- "./client": {
13478
- import: {
13479
- browser: {
13480
- types: "./dist/browser/client.d.ts",
13481
- default: "./dist/browser/client.js"
13482
- },
13483
- types: "./dist/tsup/client/mod.d.ts",
13484
- default: "./dist/tsup/client/mod.js"
13485
- },
13486
- require: {
13487
- types: "./dist/tsup/client/mod.d.cts",
13488
- default: "./dist/tsup/client/mod.cjs"
13489
- }
13490
- },
13491
- "./log": {
13492
- import: {
13493
- types: "./dist/tsup/common/log.d.ts",
13494
- default: "./dist/tsup/common/log.js"
13495
- },
13496
- require: {
13497
- types: "./dist/tsup/common/log.d.cts",
13498
- default: "./dist/tsup/common/log.cjs"
13499
- }
13500
- },
13501
- "./errors": {
13502
- import: {
13503
- types: "./dist/tsup/actor/errors.d.ts",
13504
- default: "./dist/tsup/actor/errors.js"
13505
- },
13506
- require: {
13507
- types: "./dist/tsup/actor/errors.d.cts",
13508
- default: "./dist/tsup/actor/errors.cjs"
13509
- }
13510
- },
13511
- "./inspector": {
13512
- import: {
13513
- types: "./dist/tsup/inspector/mod.d.ts",
13514
- default: "./dist/tsup/inspector/mod.js"
13515
- },
13516
- require: {
13517
- types: "./dist/tsup/inspector/mod.d.cts",
13518
- default: "./dist/tsup/inspector/mod.cjs"
13519
- }
13520
- },
13521
- "./experimental/inspector/workflow": {
13522
- import: {
13523
- types: "./dist/tsup/inspector/workflow.d.ts",
13524
- default: "./dist/tsup/inspector/workflow.js"
13525
- },
13526
- require: {
13527
- types: "./dist/tsup/inspector/workflow.d.cts",
13528
- default: "./dist/tsup/inspector/workflow.cjs"
13529
- }
13530
- },
13531
- "./inspector-tab": {
13532
- import: {
13533
- types: "./dist/tsup/inspector-tab/mod.d.ts",
13534
- default: "./dist/tsup/inspector-tab/mod.js"
13535
- },
13536
- require: {
13537
- types: "./dist/tsup/inspector-tab/mod.d.cts",
13538
- default: "./dist/tsup/inspector-tab/mod.cjs"
13539
- }
13540
- },
13541
- "./inspector/client": {
13542
- import: {
13543
- types: "./dist/browser/inspector/client.d.ts",
13544
- default: "./dist/browser/inspector/client.js"
13545
- }
13546
- },
13547
- "./utils": {
13548
- import: {
13549
- types: "./dist/tsup/utils.d.ts",
13550
- default: "./dist/tsup/utils.js"
13551
- },
13552
- require: {
13553
- types: "./dist/tsup/utils.d.cts",
13554
- default: "./dist/tsup/utils.cjs"
13555
- }
13556
- },
13557
- "./agent-os": {
13558
- import: {
13559
- types: "./dist/tsup/agent-os/index.d.ts",
13560
- default: "./dist/tsup/agent-os/index.js"
13561
- },
13562
- require: {
13563
- types: "./dist/tsup/agent-os/index.d.cts",
13564
- default: "./dist/tsup/agent-os/index.cjs"
13565
- }
13566
- }
13567
- },
13568
- engines: {
13569
- node: ">=22.0.0"
13570
- },
13571
- sideEffects: [
13572
- "./dist/tsup/chunk-*.js",
13573
- "./dist/tsup/chunk-*.cjs"
13574
- ],
13575
- scripts: {
13576
- build: "tsup src/mod.ts src/client/mod.ts src/common/log.ts src/common/websocket.ts src/actor/errors.ts src/utils.ts src/workflow/mod.ts src/test/mod.ts src/inspector/mod.ts src/inspector/workflow.ts src/inspector-tab/mod.ts src/db/mod.ts src/db/drizzle.ts src/dynamic/mod.ts src/unstable/migrations.ts && tsup src/agent-os/index.ts --no-clean --out-dir dist/tsup/agent-os && node scripts/check-built-commonjs.mjs",
13577
- "build:browser": "tsup --config tsup.browser.config.ts",
13578
- "check-types": "tsc --noEmit",
13579
- lint: "biome check . && pnpm run check:test-skips && pnpm run check:wait-for-comments",
13580
- "lint:fix": "biome check --write .",
13581
- "check:test-skips": "tsx scripts/check-annotated-skips.ts",
13582
- "check:wait-for-comments": "tsx scripts/check-wait-for-comments.ts",
13583
- format: "biome format .",
13584
- "format:write": "biome format --write .",
13585
- test: "vitest run",
13586
- "test:platforms": "pnpm run build && RIVETKIT_INCLUDE_PLATFORM_TESTS=1 vitest run tests/platforms --passWithNoTests",
13587
- "test:watch": "vitest",
13588
- "dump-asyncapi": "tsx scripts/dump-asyncapi.ts",
13589
- "registry-config-schema-gen": "tsx scripts/registry-config-schema-gen.ts",
13590
- "actor-config-schema-gen": "tsx scripts/actor-config-schema-gen.ts"
13591
- },
13592
- dependencies: {
13593
- "@hono/zod-openapi": "^1.1.5",
13594
- "@opentelemetry/api": "^1.1.0",
13595
- "@rivet-dev/services": "^0.2.3",
13596
- "@rivetkit/bare-ts": "^0.6.2",
13597
- "@rivetkit/engine-api-full": "workspace:*",
13598
- "@rivetkit/engine-cli": "workspace:*",
13599
- "@rivetkit/engine-envoy-protocol": "workspace:*",
13600
- "@rivetkit/on-change": "6.0.1",
13601
- "@rivetkit/rivetkit-napi": "workspace:*",
13602
- "@rivetkit/rivetkit-wasm": "workspace:*",
13603
- "@rivetkit/traces": "workspace:*",
13604
- "@rivetkit/virtual-websocket": "workspace:*",
13605
- "@rivetkit/workflow-engine": "workspace:*",
13606
- "cbor-x": "^1.6.0",
13607
- "drizzle-orm": "catalog:",
13608
- hono: "^4.7.0",
13609
- invariant: "^2.2.4",
13610
- "p-retry": "^6.2.1",
13611
- pino: "^9.5.0",
13612
- uuid: "^12.0.0",
13613
- vbare: "^0.0.4",
13614
- zod: "^4.1.0"
13615
- },
13616
- devDependencies: {
13617
- "@biomejs/biome": "^2.3",
13618
- "@copilotkit/llmock": "^1.6.0",
13619
- "@hono/node-server": "^1.18.2",
13620
- "@hono/node-ws": "^1.1.1",
13621
- "@opentelemetry/sdk-trace-node": "2.11.0",
13622
- "@standard-schema/spec": "^1.0.0",
13623
- "@types/invariant": "^2",
13624
- "@types/node": "^22.13.1",
13625
- eventsource: "^4.0.0",
13626
- "get-port": "^7.1.0",
13627
- tsup: "^8.4.0",
13628
- tsx: "^4.19.4",
13629
- typescript: "^5.7.3",
13630
- "vite-tsconfig-paths": "^5.1.4",
13631
- vitest: "^3.1.1",
13632
- ws: "^8.18.1"
13109
+ var DEFAULT_SLEEP_GRACE_PERIOD = 15e3;
13110
+ var ACTOR_CONTEXT_INTERNAL_SYMBOL = /* @__PURE__ */ Symbol(
13111
+ "rivetkit.actor_context_internal"
13112
+ );
13113
+ var RAW_STATE_SYMBOL = /* @__PURE__ */ Symbol("rivetkit.raw_state");
13114
+ var CONN_STATE_MANAGER_SYMBOL = /* @__PURE__ */ Symbol("rivetkit.conn_state_manager");
13115
+ var zFunction = () => external_exports.custom((val) => typeof val === "function");
13116
+ var zActionTree = external_exports.custom((value) => {
13117
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
13118
+ return false;
13119
+ }
13120
+ const prototype = Object.getPrototypeOf(value);
13121
+ return prototype === Object.prototype || prototype === null;
13122
+ }).superRefine((actions, ctx) => {
13123
+ try {
13124
+ flattenActionHandlers(actions);
13125
+ } catch (error46) {
13126
+ ctx.addIssue({
13127
+ code: "custom",
13128
+ message: error46 instanceof Error ? error46.message : "Invalid action definition"
13129
+ });
13130
+ }
13131
+ });
13132
+ var WorkflowInspectorConfigSchema = external_exports.object({
13133
+ getHistory: zFunction(),
13134
+ getState: zFunction().optional(),
13135
+ onHistoryUpdated: zFunction().optional(),
13136
+ replayFromStep: zFunction().optional()
13137
+ });
13138
+ var RunInspectorConfigSchema = external_exports.object({
13139
+ workflow: WorkflowInspectorConfigSchema.optional()
13140
+ }).optional();
13141
+ var BUILTIN_INSPECTOR_TAB_IDS = [
13142
+ "workflow",
13143
+ "database",
13144
+ "state",
13145
+ "queue",
13146
+ "schedules",
13147
+ "connections",
13148
+ "console"
13149
+ ];
13150
+ var BuiltinInspectorTabIdSchema = external_exports.enum(BUILTIN_INSPECTOR_TAB_IDS);
13151
+ var CUSTOM_INSPECTOR_TAB_ID_RE = /^[A-Za-z0-9_-]+$/;
13152
+ var CustomInspectorTabEntrySchema = external_exports.object({
13153
+ id: external_exports.string().regex(
13154
+ CUSTOM_INSPECTOR_TAB_ID_RE,
13155
+ "inspector.tabs[].id must contain only letters, digits, underscore, or dash"
13156
+ ),
13157
+ label: external_exports.string().min(1),
13158
+ source: external_exports.string().min(1),
13159
+ /**
13160
+ * Optional icon id. The dashboard maps strings to glyphs (see its
13161
+ * icon registry); unknown ids fall back to a generic icon.
13162
+ */
13163
+ icon: external_exports.string().min(1).optional(),
13164
+ hidden: external_exports.literal(false).optional()
13165
+ }).strict();
13166
+ var HideInspectorTabEntrySchema = external_exports.object({
13167
+ id: BuiltinInspectorTabIdSchema,
13168
+ hidden: external_exports.literal(true)
13169
+ }).strict();
13170
+ var InspectorTabEntrySchema = external_exports.union([
13171
+ CustomInspectorTabEntrySchema,
13172
+ HideInspectorTabEntrySchema
13173
+ ]);
13174
+ var ActorInspectorConfigSchema = external_exports.object({
13175
+ tabs: external_exports.array(InspectorTabEntrySchema).default(() => [])
13176
+ }).strict().refine(
13177
+ (data) => {
13178
+ const ids = data.tabs.map((t) => t.id);
13179
+ return new Set(ids).size === ids.length;
13633
13180
  },
13634
- peerDependencies: {
13635
- "drizzle-kit": "^0.31.2",
13636
- eventsource: "^4.0.0",
13637
- ws: "^8.0.0"
13181
+ { message: "Duplicate id in inspector.tabs", path: ["tabs"] }
13182
+ ).refine(
13183
+ (data) => {
13184
+ const builtinSet = new Set(BUILTIN_INSPECTOR_TAB_IDS);
13185
+ return data.tabs.every(
13186
+ (t) => t.hidden === true || !builtinSet.has(t.id)
13187
+ );
13638
13188
  },
13639
- peerDependenciesMeta: {
13640
- "drizzle-kit": {
13641
- optional: true
13642
- },
13643
- eventsource: {
13644
- optional: true
13645
- },
13646
- ws: {
13647
- optional: true
13189
+ {
13190
+ message: "Custom inspector tab id collides with a built-in (use hidden: true to hide a built-in)",
13191
+ path: ["tabs"]
13192
+ }
13193
+ );
13194
+ var RunConfigSchema = external_exports.object({
13195
+ /** Display name for the actor in the Inspector UI. */
13196
+ name: external_exports.string().optional(),
13197
+ /** Icon for the actor in the Inspector UI. Can be an emoji or FontAwesome icon name. */
13198
+ icon: external_exports.string().optional(),
13199
+ /** The run handler function. */
13200
+ run: zFunction(),
13201
+ /** Inspector integration for long-running run handlers. */
13202
+ inspector: RunInspectorConfigSchema.optional()
13203
+ });
13204
+ var RUN_FUNCTION_CONFIG_SYMBOL = /* @__PURE__ */ Symbol.for("rivetkit.run_function_config");
13205
+ function defineRunHandler(run, options) {
13206
+ if (options.inspectorKind === void 0 !== (options.createInspector === void 0)) {
13207
+ throw new TypeError(
13208
+ "defineRunHandler requires inspectorKind and createInspector together"
13209
+ );
13210
+ }
13211
+ Object.defineProperty(run, RUN_FUNCTION_CONFIG_SYMBOL, {
13212
+ configurable: false,
13213
+ enumerable: false,
13214
+ writable: false,
13215
+ value: {
13216
+ name: options.name,
13217
+ icon: options.icon,
13218
+ inspectorKind: options.inspectorKind,
13219
+ createInspector: options.createInspector
13648
13220
  }
13649
- },
13650
- stableVersion: "0.8.0"
13651
- };
13652
- var baseLogger;
13653
- var configuredLogLevel;
13654
- var loggerCache = /* @__PURE__ */ new Map();
13655
- var LogLevelSchema = external_exports.enum([
13656
- "trace",
13657
- "debug",
13658
- "info",
13659
- "warn",
13660
- "error",
13661
- "fatal",
13662
- "silent"
13663
- ]);
13664
- function getPinoLevel(logLevel) {
13665
- if (logLevel) {
13666
- return logLevel;
13221
+ });
13222
+ return run;
13223
+ }
13224
+ function getRunInspectorKind(run) {
13225
+ var _a2;
13226
+ if (!run || typeof run !== "function") return void 0;
13227
+ return (_a2 = run[RUN_FUNCTION_CONFIG_SYMBOL]) == null ? void 0 : _a2.inspectorKind;
13228
+ }
13229
+ function createRunInspector(run, context2) {
13230
+ var _a2, _b;
13231
+ if (!run || typeof run !== "function") return void 0;
13232
+ return (_b = (_a2 = run[RUN_FUNCTION_CONFIG_SYMBOL]) == null ? void 0 : _a2.createInspector) == null ? void 0 : _b.call(_a2, context2);
13233
+ }
13234
+ var zRunHandler = external_exports.union([zFunction(), RunConfigSchema]).optional();
13235
+ function getRunFunction(run) {
13236
+ if (!run) return void 0;
13237
+ if (typeof run === "function") return run;
13238
+ return run.run;
13239
+ }
13240
+ function getRunMetadata(run) {
13241
+ if (!run) return {};
13242
+ if (typeof run === "function") {
13243
+ const config3 = run[RUN_FUNCTION_CONFIG_SYMBOL];
13244
+ if (!config3) return {};
13245
+ return { name: config3.name, icon: config3.icon };
13246
+ }
13247
+ return { name: run.name, icon: run.icon };
13248
+ }
13249
+ function getRunInspectorConfig(run, actor2) {
13250
+ if (!run) return void 0;
13251
+ if (typeof run === "function") {
13252
+ const config3 = run[RUN_FUNCTION_CONFIG_SYMBOL];
13253
+ return (config3 == null ? void 0 : config3.inspectorFactory) ? config3.inspectorFactory(actor2) : config3 == null ? void 0 : config3.inspector;
13254
+ }
13255
+ return run.inspector;
13256
+ }
13257
+ function hasRunInspectorConfig(run) {
13258
+ if (!run) return false;
13259
+ if (typeof run !== "function") return run.inspector !== void 0;
13260
+ const config3 = run[RUN_FUNCTION_CONFIG_SYMBOL];
13261
+ return (config3 == null ? void 0 : config3.inspectorKind) !== void 0 || (config3 == null ? void 0 : config3.createInspector) !== void 0 || (config3 == null ? void 0 : config3.inspector) !== void 0 || (config3 == null ? void 0 : config3.inspectorFactory) !== void 0;
13262
+ }
13263
+ function disposeRunInspector(run, actorId) {
13264
+ var _a2;
13265
+ if (!run || typeof run !== "function") {
13266
+ return;
13267
+ }
13268
+ const config3 = run[RUN_FUNCTION_CONFIG_SYMBOL];
13269
+ (_a2 = config3 == null ? void 0 : config3.disposeInspector) == null ? void 0 : _a2.call(config3, actorId);
13270
+ }
13271
+ var GlobalActorOptionsBaseSchema = external_exports.object({
13272
+ /** Display name for the actor in the Inspector UI. */
13273
+ name: external_exports.string().optional(),
13274
+ /** Icon for the actor in the Inspector UI. Can be an emoji or FontAwesome icon name. */
13275
+ icon: external_exports.string().optional(),
13276
+ /** Enables the experimental Actor Runtime Socket for this actor. */
13277
+ enableActorRuntimeSocket: external_exports.boolean().default(false),
13278
+ /**
13279
+ * Can hibernate WebSockets, both client connections for actions and
13280
+ * events and WebSockets for onWebSocket. A WebSocket that does not
13281
+ * hibernate closes when the actor sleeps, and the client reconnects.
13282
+ *
13283
+ * @experimental
13284
+ **/
13285
+ canHibernateWebSocket: external_exports.union([external_exports.boolean(), zFunction()]).default(false)
13286
+ }).strict();
13287
+ var GlobalActorOptionsSchema = GlobalActorOptionsBaseSchema.prefault(
13288
+ () => ({})
13289
+ );
13290
+ var InstanceActorOptionsBaseSchema = external_exports.object({
13291
+ createVarsTimeout: external_exports.number().positive().default(5e3),
13292
+ createConnStateTimeout: external_exports.number().positive().default(5e3),
13293
+ onBeforeConnectTimeout: external_exports.number().positive().default(5e3),
13294
+ onConnectTimeout: external_exports.number().positive().default(5e3),
13295
+ onMigrateTimeout: external_exports.number().positive().default(3e4),
13296
+ sleepGracePeriod: external_exports.number().positive().default(DEFAULT_SLEEP_GRACE_PERIOD),
13297
+ /** @deprecated `onDestroyTimeout` is folded into `sleepGracePeriod`, which now bounds the entire graceful shutdown window for both sleep and destroy. Will be removed in 2.2.0. */
13298
+ onDestroyTimeout: external_exports.number().positive().optional(),
13299
+ /** @deprecated `waitUntilTimeout` is folded into `sleepGracePeriod`, which now bounds the entire graceful shutdown window for both sleep and destroy. Will be removed in 2.2.0. */
13300
+ waitUntilTimeout: external_exports.number().positive().optional(),
13301
+ stateSaveInterval: external_exports.number().positive().default(1e3),
13302
+ actionTimeout: external_exports.number().positive().default(6e4),
13303
+ connectionLivenessTimeout: external_exports.number().positive().default(2500),
13304
+ connectionLivenessInterval: external_exports.number().positive().default(5e3),
13305
+ /** @deprecated Use `c.keepAwake(promise)` to scope keep-awake to a specific operation, or keep `noSleep` for actors that must stay awake indefinitely. Will be removed in 2.2.0. */
13306
+ noSleep: external_exports.boolean().default(false),
13307
+ sleepTimeout: external_exports.number().positive().default(3e4),
13308
+ maxQueueSize: external_exports.number().positive().default(1e3),
13309
+ /** Maximum pending one-shot and recurring schedules. */
13310
+ maxSchedules: external_exports.number().int().nonnegative().default(1e3),
13311
+ maxQueueMessageSize: external_exports.number().positive().default(64 * 1024),
13312
+ /** @deprecated Internal storage moved to SQLite and no longer uses KV preloading, so this option is ignored. Will be removed in 2.2.0. */
13313
+ preloadMaxWorkflowBytes: external_exports.number().nonnegative().optional(),
13314
+ /** @deprecated Internal storage moved to SQLite and no longer uses KV preloading, so this option is ignored. Will be removed in 2.2.0. */
13315
+ preloadMaxConnectionsBytes: external_exports.number().nonnegative().optional()
13316
+ }).strict();
13317
+ var InstanceActorOptionsSchema = InstanceActorOptionsBaseSchema.prefault(() => ({}));
13318
+ var ActorOptionsSchema = GlobalActorOptionsBaseSchema.extend(
13319
+ InstanceActorOptionsBaseSchema.shape
13320
+ ).strict().prefault(() => ({}));
13321
+ var zSampleRate = external_exports.number().min(0).max(1);
13322
+ var zActionSampleRates = external_exports.lazy(
13323
+ () => external_exports.record(external_exports.string(), external_exports.union([zSampleRate, zActionSampleRates]))
13324
+ );
13325
+ var ActorConfigSchema = external_exports.object({
13326
+ onCreate: zFunction().optional(),
13327
+ onDestroy: zFunction().optional(),
13328
+ onMigrate: zFunction().optional(),
13329
+ onWake: zFunction().optional(),
13330
+ onSleep: zFunction().optional(),
13331
+ run: zRunHandler,
13332
+ onStateChange: zFunction().optional(),
13333
+ onBeforeConnect: zFunction().optional(),
13334
+ onConnect: zFunction().optional(),
13335
+ onDisconnect: zFunction().optional(),
13336
+ onBeforeActionResponse: zFunction().optional(),
13337
+ onRequest: zFunction().optional(),
13338
+ onWebSocket: zFunction().optional(),
13339
+ actions: zActionTree.default(() => ({})),
13340
+ actionInputSchemas: external_exports.record(external_exports.string(), external_exports.any()).optional(),
13341
+ tracing: external_exports.object({
13342
+ sampler: zSampleRate.optional(),
13343
+ actions: zActionSampleRates.optional()
13344
+ }).strict().optional(),
13345
+ connParamsSchema: external_exports.any().optional(),
13346
+ events: external_exports.record(external_exports.string(), external_exports.any()).optional(),
13347
+ queues: external_exports.record(external_exports.string(), external_exports.any()).optional(),
13348
+ state: external_exports.any().optional(),
13349
+ createState: zFunction().optional(),
13350
+ connState: external_exports.any().optional(),
13351
+ createConnState: zFunction().optional(),
13352
+ vars: external_exports.any().optional(),
13353
+ db: external_exports.any().optional(),
13354
+ createVars: zFunction().optional(),
13355
+ options: ActorOptionsSchema,
13356
+ inspector: ActorInspectorConfigSchema.optional()
13357
+ }).strict().refine(
13358
+ (data) => !(data.state !== void 0 && data.createState !== void 0),
13359
+ {
13360
+ message: "Cannot define both 'state' and 'createState'",
13361
+ path: ["state"]
13362
+ }
13363
+ ).refine(
13364
+ (data) => !(data.connState !== void 0 && data.createConnState !== void 0),
13365
+ {
13366
+ message: "Cannot define both 'connState' and 'createConnState'",
13367
+ path: ["connState"]
13667
13368
  }
13668
- if (configuredLogLevel) {
13669
- return configuredLogLevel;
13369
+ ).refine(
13370
+ (data) => !(data.vars !== void 0 && data.createVars !== void 0),
13371
+ {
13372
+ message: "Cannot define both 'vars' and 'createVars'",
13373
+ path: ["vars"]
13670
13374
  }
13671
- const raw = (getLogLevel() || "warn").toString().toLowerCase();
13672
- const parsed = LogLevelSchema.safeParse(raw);
13673
- if (parsed.success) {
13674
- return parsed.data;
13375
+ );
13376
+ var DocActorOptionsSchema = external_exports.object({
13377
+ name: external_exports.string().optional().describe("Display name for the actor in the Inspector UI."),
13378
+ icon: external_exports.string().optional().describe(
13379
+ "Icon for the actor in the Inspector UI. Can be an emoji (e.g., '\u{1F680}') or FontAwesome icon name (e.g., 'rocket')."
13380
+ ),
13381
+ enableActorRuntimeSocket: external_exports.boolean().optional().describe(
13382
+ "Enables the experimental Actor Runtime Socket for this actor. Default: false"
13383
+ ),
13384
+ createVarsTimeout: external_exports.number().optional().describe("Timeout in ms for createVars handler. Default: 5000"),
13385
+ createConnStateTimeout: external_exports.number().optional().describe(
13386
+ "Timeout in ms for createConnState handler. Default: 5000"
13387
+ ),
13388
+ onMigrateTimeout: external_exports.number().optional().describe("Timeout in ms for onMigrate handler. Default: 30000"),
13389
+ onBeforeConnectTimeout: external_exports.number().optional().describe(
13390
+ "Timeout in ms for onBeforeConnect handler. Default: 5000"
13391
+ ),
13392
+ onConnectTimeout: external_exports.number().optional().describe("Timeout in ms for onConnect handler. Default: 5000"),
13393
+ sleepGracePeriod: external_exports.number().optional().describe(
13394
+ `Max time in ms for the graceful shutdown window. Covers lifecycle hooks (onSleep, onDestroy), the run handler wait, async raw WebSocket handlers, disconnect callbacks, and final state serialization. Default: ${DEFAULT_SLEEP_GRACE_PERIOD}.`
13395
+ ),
13396
+ onDestroyTimeout: external_exports.number().optional().describe(
13397
+ "Deprecated. Folded into sleepGracePeriod, which now bounds the entire graceful shutdown window for both sleep and destroy. Will be removed in 2.2.0."
13398
+ ),
13399
+ waitUntilTimeout: external_exports.number().optional().describe(
13400
+ "Deprecated. Folded into sleepGracePeriod, which now bounds the entire graceful shutdown window for both sleep and destroy. Will be removed in 2.2.0."
13401
+ ),
13402
+ stateSaveInterval: external_exports.number().optional().describe(
13403
+ "Interval in ms between automatic state saves. Default: 1000"
13404
+ ),
13405
+ actionTimeout: external_exports.number().optional().describe("Timeout in ms for action handlers. Default: 60000"),
13406
+ connectionLivenessTimeout: external_exports.number().optional().describe(
13407
+ "Timeout in ms for connection liveness checks. Default: 2500"
13408
+ ),
13409
+ connectionLivenessInterval: external_exports.number().optional().describe(
13410
+ "Interval in ms between connection liveness checks. Default: 5000"
13411
+ ),
13412
+ noSleep: external_exports.boolean().optional().describe(
13413
+ "Deprecated. If true, the actor will never sleep. Use c.keepAwake(promise) to scope keep-awake to a specific operation instead. Default: false"
13414
+ ),
13415
+ sleepTimeout: external_exports.number().optional().describe(
13416
+ "Time in ms of inactivity before the actor sleeps. Default: 30000"
13417
+ ),
13418
+ maxQueueSize: external_exports.number().optional().describe(
13419
+ "Maximum number of queue messages before rejecting new messages. Default: 1000"
13420
+ ),
13421
+ maxSchedules: external_exports.number().int().nonnegative().optional().describe(
13422
+ "Maximum pending one-shot and recurring schedules before rejecting new schedules. Default: 1000"
13423
+ ),
13424
+ maxQueueMessageSize: external_exports.number().optional().describe(
13425
+ "Maximum size of each queue message in bytes. Default: 65536"
13426
+ ),
13427
+ canHibernateWebSocket: external_exports.boolean().optional().describe(
13428
+ "Whether WebSockets 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"
13429
+ )
13430
+ }).describe("Actor options for timeouts and behavior configuration.");
13431
+ var DocActorConfigSchema = external_exports.object({
13432
+ state: external_exports.unknown().optional().describe(
13433
+ "Initial state value for the actor. Cannot be used with createState."
13434
+ ),
13435
+ createState: external_exports.unknown().optional().describe(
13436
+ "Function to create initial state. Receives context and input. Cannot be used with state."
13437
+ ),
13438
+ connState: external_exports.unknown().optional().describe(
13439
+ "Initial connection state value. Cannot be used with createConnState."
13440
+ ),
13441
+ createConnState: external_exports.unknown().optional().describe(
13442
+ "Function to create connection state. Receives context and connection params. The pending connection is not visible in c.conns until this succeeds. Cannot be used with connState."
13443
+ ),
13444
+ vars: external_exports.unknown().optional().describe(
13445
+ "Initial ephemeral variables value. Cannot be used with createVars."
13446
+ ),
13447
+ createVars: external_exports.unknown().optional().describe(
13448
+ "Function to create ephemeral variables. Receives context and driver context. Cannot be used with vars."
13449
+ ),
13450
+ db: external_exports.unknown().optional().describe("Database provider instance for the actor."),
13451
+ onCreate: external_exports.unknown().optional().describe(
13452
+ "Called when the actor is first initialized. Use to initialize state."
13453
+ ),
13454
+ onDestroy: external_exports.unknown().optional().describe("Called when the actor is destroyed."),
13455
+ onMigrate: external_exports.unknown().optional().describe(
13456
+ "Called on every actor start after persisted state loads and before onWake. Use for repeatable schema migrations."
13457
+ ),
13458
+ onWake: external_exports.unknown().optional().describe(
13459
+ "Called when the actor wakes up and is ready to receive connections and actions."
13460
+ ),
13461
+ onSleep: external_exports.unknown().optional().describe(
13462
+ "Called when the actor is stopping or sleeping. Use to clean up resources."
13463
+ ),
13464
+ run: external_exports.unknown().optional().describe(
13465
+ "Called after actor starts. Does not block startup. Use for background tasks like queue processing or tick loops. If it exits, the actor follows the normal idle sleep timeout once idle. If it throws, the actor logs the error and then follows the normal idle sleep timeout once idle."
13466
+ ),
13467
+ onStateChange: external_exports.unknown().optional().describe(
13468
+ "Called when the actor's state changes. State changes within this hook won't trigger recursion."
13469
+ ),
13470
+ onBeforeConnect: external_exports.unknown().optional().describe(
13471
+ "Called before a client connects. Throw an error to reject the connection. The pending connection is not visible in c.conns while this runs."
13472
+ ),
13473
+ onConnect: external_exports.unknown().optional().describe(
13474
+ "Called when a client successfully connects. The connection is visible in c.conns before this runs."
13475
+ ),
13476
+ onDisconnect: external_exports.unknown().optional().describe("Called when a client disconnects."),
13477
+ onBeforeActionResponse: external_exports.unknown().optional().describe(
13478
+ "Called before sending an action response. Use to transform output."
13479
+ ),
13480
+ onRequest: external_exports.unknown().optional().describe(
13481
+ "Called for raw HTTP requests to /actors/{name}/http/* endpoints."
13482
+ ),
13483
+ onWebSocket: external_exports.unknown().optional().describe(
13484
+ "Called for raw WebSocket connections to /actors/{name}/websocket/* endpoints."
13485
+ ),
13486
+ actions: external_exports.record(external_exports.string(), external_exports.unknown()).optional().describe(
13487
+ "Tree of action names or nested groups to handler functions. Nested paths use dot-separated low-level action names. Defaults to an empty object."
13488
+ ),
13489
+ actionInputSchemas: external_exports.record(external_exports.string(), external_exports.unknown()).optional().describe(
13490
+ "Optional schemas for validating action argument tuples in native runtimes. May mirror nested action groups or use dot-separated low-level action names."
13491
+ ),
13492
+ tracing: external_exports.unknown().optional().describe(
13493
+ "Trace sampling for this actor: `sampler` is the share of its invocations that are recorded, from 0 to 1, with optional per-action rates under `actions`. A rate lowers what is recorded and never raises it. Defaults to the process sampler from OTEL_TRACES_SAMPLER."
13494
+ ),
13495
+ connParamsSchema: external_exports.unknown().optional().describe(
13496
+ "Optional schema for validating connection params in native runtimes."
13497
+ ),
13498
+ events: external_exports.record(external_exports.string(), external_exports.unknown()).optional().describe("Map of event names to schemas."),
13499
+ queues: external_exports.record(external_exports.string(), external_exports.unknown()).optional().describe("Map of queue names to schemas."),
13500
+ options: DocActorOptionsSchema.optional()
13501
+ }).describe("Actor configuration passed to the actor() function.");
13502
+
13503
+ // ../rivetkit/dist/tsup/chunk-ZOVJDAOW.js
13504
+ var INTERNAL_ERROR_CODE = "internal_error";
13505
+ var INTERNAL_ERROR_DESCRIPTION = "An internal error occurred";
13506
+ var USER_ERROR_CODE = "user_error";
13507
+ var BRIDGE_RIVET_ERROR_PREFIX = "__RIVET_ERROR_JSON__:";
13508
+ function looksLikeRivetErrorOptions(value) {
13509
+ return typeof value === "object" && value !== null && ("public" in value || "metadata" in value || "rayId" in value || "statusCode" in value || "actor" in value || "cause" in value);
13510
+ }
13511
+ function isTypedErrorTag(value) {
13512
+ return value === "ActorError" || value === "RivetError";
13513
+ }
13514
+ function errorMessage(error46, fallback = String(error46)) {
13515
+ if (error46 && typeof error46 === "object" && "message" in error46 && typeof error46.message === "string") {
13516
+ return error46.message;
13675
13517
  }
13676
- return "info";
13518
+ return fallback;
13677
13519
  }
13678
- function getIncludeTarget() {
13679
- return getLogTarget();
13520
+ function isRivetErrorLike(error46) {
13521
+ return typeof error46 === "object" && error46 !== null && "group" in error46 && typeof error46.group === "string" && "code" in error46 && typeof error46.code === "string" && "message" in error46 && typeof error46.message === "string" && (!("rayId" in error46) || error46.rayId === void 0 || typeof error46.rayId === "string") && (!("__type" in error46) || isTypedErrorTag(error46.__type));
13680
13522
  }
13681
- function configureBaseLogger(logger23) {
13682
- baseLogger = logger23;
13683
- loggerCache.clear();
13523
+ function isActorAbortedError(error46) {
13524
+ return isRivetErrorLike(error46) && error46.group === "actor" && error46.code === "aborted";
13684
13525
  }
13685
- function makeDefaultLogger(logLevel) {
13686
- return (0, import_pino.pino)(
13526
+ function isActorSpecifier(value) {
13527
+ return typeof value === "object" && value !== null && "actorId" in value && typeof value.actorId === "string" && "generation" in value && typeof value.generation === "number" && (!("key" in value) || value.key === void 0 || typeof value.key === "string");
13528
+ }
13529
+ var RivetError = class extends Error {
13530
+ __type = "RivetError";
13531
+ public;
13532
+ metadata;
13533
+ rayId;
13534
+ statusCode;
13535
+ actor;
13536
+ group;
13537
+ code;
13538
+ static isRivetError(error46) {
13539
+ return isRivetErrorLike(error46);
13540
+ }
13541
+ static isActorError(error46) {
13542
+ return isRivetErrorLike(error46);
13543
+ }
13544
+ constructor(group, code, message, options) {
13545
+ const normalized = looksLikeRivetErrorOptions(options) ? options : { metadata: options };
13546
+ super(message, { cause: normalized.cause });
13547
+ this.name = "RivetError";
13548
+ this.group = group;
13549
+ this.code = code;
13550
+ this.public = normalized.public ?? false;
13551
+ this.metadata = normalized.metadata;
13552
+ this.rayId = normalized.rayId ?? void 0;
13553
+ this.statusCode = normalized.statusCode ?? (this.public ? 400 : 500);
13554
+ this.actor = normalized.actor;
13555
+ }
13556
+ toString() {
13557
+ return this.message;
13558
+ }
13559
+ };
13560
+ var UserError = class extends RivetError {
13561
+ constructor(message, options) {
13562
+ super("user", (options == null ? void 0 : options.code) ?? USER_ERROR_CODE, message, {
13563
+ public: true,
13564
+ metadata: options == null ? void 0 : options.metadata,
13565
+ cause: options == null ? void 0 : options.cause
13566
+ });
13567
+ }
13568
+ };
13569
+ function toRivetError(error46, fallback) {
13570
+ if (typeof error46 === "string") {
13571
+ const bridged = decodeBridgeRivetError(error46);
13572
+ if (bridged) {
13573
+ return bridged;
13574
+ }
13575
+ }
13576
+ if (error46 instanceof Error) {
13577
+ const bridged = decodeBridgeRivetError(error46.message);
13578
+ if (bridged) {
13579
+ return bridged;
13580
+ }
13581
+ }
13582
+ if (isRivetErrorLike(error46)) {
13583
+ return new RivetError(error46.group, error46.code, error46.message, {
13584
+ public: error46.public,
13585
+ statusCode: error46.statusCode,
13586
+ metadata: error46.metadata,
13587
+ rayId: error46.rayId,
13588
+ actor: error46.actor,
13589
+ cause: error46 instanceof Error ? error46.cause : void 0
13590
+ });
13591
+ }
13592
+ return new RivetError(
13593
+ (fallback == null ? void 0 : fallback.group) ?? "actor",
13594
+ (fallback == null ? void 0 : fallback.code) ?? INTERNAL_ERROR_CODE,
13595
+ errorMessage(error46, (fallback == null ? void 0 : fallback.message) ?? "Unknown error"),
13687
13596
  {
13688
- level: getPinoLevel(logLevel),
13689
- messageKey: "msg",
13690
- // Do not include pid/hostname in output
13691
- base: {},
13692
- errorKey: "error",
13693
- // Keep the numeric level so the logfmt sink can match Pino's levels.
13694
- formatters: {
13695
- level(_label, number4) {
13696
- return { level: number4 };
13697
- }
13698
- },
13699
- timestamp: getLogTimestamp() ? import_pino.stdTimeFunctions.epochTime : false
13700
- },
13701
- createLogfmtDestination()
13597
+ public: fallback == null ? void 0 : fallback.public,
13598
+ statusCode: fallback == null ? void 0 : fallback.statusCode,
13599
+ metadata: fallback == null ? void 0 : fallback.metadata,
13600
+ rayId: fallback == null ? void 0 : fallback.rayId,
13601
+ actor: fallback == null ? void 0 : fallback.actor,
13602
+ cause: error46 instanceof Error ? error46 : void 0
13603
+ }
13702
13604
  );
13703
13605
  }
13704
- function configureDefaultLogger(logLevel) {
13705
- if (logLevel) {
13706
- configuredLogLevel = logLevel;
13707
- }
13708
- baseLogger = makeDefaultLogger(logLevel);
13709
- loggerCache.clear();
13710
- }
13711
- function getBaseLogger() {
13712
- if (!baseLogger) {
13713
- configureDefaultLogger();
13606
+ function encodeBridgeRivetError(error46) {
13607
+ const payload = {
13608
+ group: error46.group,
13609
+ code: error46.code,
13610
+ message: error46.message,
13611
+ metadata: error46.metadata,
13612
+ rayId: error46.rayId,
13613
+ public: error46.public,
13614
+ statusCode: error46.statusCode,
13615
+ actor: error46.actor
13616
+ };
13617
+ try {
13618
+ return {
13619
+ encoded: `${BRIDGE_RIVET_ERROR_PREFIX}${JSON.stringify(payload)}`
13620
+ };
13621
+ } catch (cause) {
13622
+ return {
13623
+ encoded: `${BRIDGE_RIVET_ERROR_PREFIX}${JSON.stringify({ ...payload, metadata: void 0 })}`,
13624
+ droppedMetadataCause: cause
13625
+ };
13714
13626
  }
13715
- return baseLogger;
13716
13627
  }
13717
- function getLogger(name = "default") {
13718
- const cached2 = loggerCache.get(name);
13719
- if (cached2) {
13720
- return cached2;
13628
+ function encodeErrorForBridge(error46) {
13629
+ if (isCanonicalStructuredRivetError(error46)) {
13630
+ return encodeBridgeRivetError(error46).encoded;
13721
13631
  }
13722
- const base = getBaseLogger();
13723
- const child = getIncludeTarget() ? base.child({ target: name }) : base;
13724
- loggerCache.set(name, child);
13725
- return child;
13632
+ return String(error46);
13726
13633
  }
13727
- var PINO_LEVEL_LABELS = {
13728
- 10: "trace",
13729
- 20: "debug",
13730
- 30: "info",
13731
- 40: "warn",
13732
- 50: "error",
13733
- 60: "fatal"
13734
- };
13735
- function createLogfmtDestination() {
13736
- return {
13737
- write(msg) {
13738
- var _a2;
13739
- const line = formatLogfmtLine(msg);
13740
- if (typeof process !== "undefined" && ((_a2 = process.stdout) == null ? void 0 : _a2.write)) {
13741
- process.stdout.write(`${line}
13742
- `);
13743
- } else {
13744
- console.log(line);
13745
- }
13746
- }
13747
- };
13634
+ function isCanonicalStructuredRivetError(error46) {
13635
+ 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";
13748
13636
  }
13749
- function formatLogfmtLine(raw) {
13750
- let data;
13751
- try {
13752
- data = JSON.parse(raw);
13753
- } catch {
13754
- return raw.trimEnd();
13755
- }
13756
- const parts = [];
13757
- appendLogfmtEntry(parts, "level", formatPinoLevel(data.level));
13758
- if (data.time !== void 0) {
13759
- appendLogfmtEntry(parts, "ts", data.time);
13637
+ function decodeBridgeRivetErrorPayload(value) {
13638
+ if (!value.startsWith(BRIDGE_RIVET_ERROR_PREFIX)) {
13639
+ return void 0;
13760
13640
  }
13761
- for (const [key, value] of Object.entries(data)) {
13762
- if (key === "level" || key === "time") {
13763
- continue;
13641
+ try {
13642
+ const raw = JSON.parse(
13643
+ value.slice(BRIDGE_RIVET_ERROR_PREFIX.length)
13644
+ );
13645
+ const payload = {
13646
+ ...raw,
13647
+ rayId: raw.rayId ?? void 0
13648
+ };
13649
+ if (!isRivetErrorLike(payload)) {
13650
+ return void 0;
13764
13651
  }
13765
- appendLogfmtEntry(parts, key, value);
13652
+ if (payload.actor !== void 0 && payload.actor !== null && !isActorSpecifier(payload.actor)) {
13653
+ return void 0;
13654
+ }
13655
+ return payload;
13656
+ } catch {
13657
+ return void 0;
13766
13658
  }
13767
- return parts.join(" ");
13768
13659
  }
13769
- function formatPinoLevel(level) {
13770
- if (typeof level === "number") {
13771
- return PINO_LEVEL_LABELS[level] ?? level.toString();
13772
- }
13773
- if (typeof level === "string") {
13774
- return level.toLowerCase();
13660
+ function decodeBridgeRivetError(value) {
13661
+ const payload = decodeBridgeRivetErrorPayload(value);
13662
+ if (!payload) {
13663
+ return void 0;
13775
13664
  }
13776
- return "info";
13665
+ return new RivetError(payload.group, payload.code, payload.message, {
13666
+ metadata: payload.metadata,
13667
+ rayId: payload.rayId,
13668
+ public: payload.public,
13669
+ statusCode: payload.statusCode,
13670
+ actor: payload.actor ?? void 0
13671
+ });
13777
13672
  }
13778
- function appendLogfmtEntry(parts, key, value) {
13779
- const safeKey = key.replace(/[\s="]/g, "");
13780
- if (safeKey.length === 0) {
13781
- return;
13782
- }
13783
- parts.push(`${safeKey}=${formatLogfmtValue(value)}`);
13673
+ function invalidRequest(error46) {
13674
+ return new RivetError(
13675
+ "request",
13676
+ "invalid",
13677
+ `Invalid request: ${errorMessage(error46, String(error46))}`,
13678
+ {
13679
+ public: true,
13680
+ cause: error46 instanceof Error ? error46 : void 0
13681
+ }
13682
+ );
13784
13683
  }
13785
- function formatLogfmtValue(value) {
13786
- if (typeof value === "number" || typeof value === "boolean") {
13787
- return String(value);
13788
- }
13789
- if (value === null || value === void 0) {
13790
- return "null";
13791
- }
13792
- if (typeof value === "string") {
13793
- return quoteLogfmtString(value);
13794
- }
13795
- return quoteLogfmtString(JSON.stringify(value));
13684
+ function actorNotFound(identifier) {
13685
+ return new RivetError(
13686
+ "actor",
13687
+ "not_found",
13688
+ identifier ? `Actor not found: ${identifier} (https://www.rivet.dev/docs/clients/javascript)` : "Actor not found (https://www.rivet.dev/docs/clients/javascript)",
13689
+ { public: true }
13690
+ );
13796
13691
  }
13797
- function quoteLogfmtString(value) {
13798
- if (!/[\s="]/.test(value)) {
13799
- return value;
13800
- }
13801
- return `"${value.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "\\n")}"`;
13692
+ function forbiddenError() {
13693
+ return new RivetError("auth", "forbidden", "Forbidden", {
13694
+ public: true,
13695
+ statusCode: 403
13696
+ });
13802
13697
  }
13803
- function uint8ArrayToBase642(uint8Array) {
13804
- if (typeof Buffer !== "undefined") {
13805
- return Buffer.from(uint8Array).toString("base64");
13806
- }
13807
- let binary = "";
13808
- const len = uint8Array.byteLength;
13809
- for (let i = 0; i < len; i++) {
13810
- binary += String.fromCharCode(uint8Array[i]);
13811
- }
13812
- return btoa(binary);
13698
+ function unsupportedFeature(feature) {
13699
+ return new RivetError(
13700
+ "feature",
13701
+ "unsupported",
13702
+ `Unsupported feature: ${feature}`
13703
+ );
13813
13704
  }
13814
- function contentTypeForEncoding(encoding) {
13815
- if (encoding === "json") {
13816
- return "application/json";
13817
- } else if (encoding === "cbor" || encoding === "bare") {
13818
- return "application/octet-stream";
13819
- } else {
13820
- assertUnreachable(encoding);
13705
+
13706
+ // ../rivetkit/dist/tsup/chunk-3LLGBENU.js
13707
+ var import_pino = require("pino");
13708
+ var cbor = __toESM(require("cbor-x"), 1);
13709
+ var import_invariant = __toESM(require_invariant(), 1);
13710
+ var getRivetEngine = () => getEnvUniversal("RIVET_ENGINE");
13711
+ var getRivetEndpoint = () => getEnvUniversal("RIVET_ENDPOINT");
13712
+ var getRivetToken = () => getEnvUniversal("RIVET_TOKEN");
13713
+ var getRivetNamespace = () => getEnvUniversal("RIVET_NAMESPACE");
13714
+ var getRivetPool = () => getEnvUniversal("RIVET_POOL");
13715
+ var getRivetTotalSlots = () => {
13716
+ const value = getEnvUniversal("RIVET_TOTAL_SLOTS");
13717
+ return value !== void 0 ? parseInt(value, 10) : void 0;
13718
+ };
13719
+ var getRivetRunEngine = () => getEnvUniversal("RIVET_RUN_ENGINE") === "1";
13720
+ var getRivetRunEngineHost = () => getEnvUniversal("RIVET_RUN_ENGINE_HOST");
13721
+ var getRivetRunEnginePort = () => {
13722
+ const value = getEnvUniversal("RIVET_RUN_ENGINE_PORT");
13723
+ return value !== void 0 ? parseInt(value, 10) : void 0;
13724
+ };
13725
+ var getRivetRunEngineVersion = () => getEnvUniversal("RIVET_RUN_ENGINE_VERSION");
13726
+ var getRivetRunServices = () => {
13727
+ const value = getEnvUniversal("RIVET_RUN_SERVICES");
13728
+ return value === void 0 ? void 0 : value === "1";
13729
+ };
13730
+ var getRivetEnvoyVersion = () => {
13731
+ const value = getEnvUniversal("RIVET_ENVOY_VERSION");
13732
+ return value !== void 0 ? parseInt(value, 10) : void 0;
13733
+ };
13734
+ var getRivetPublicEndpoint = () => getEnvUniversal("RIVET_PUBLIC_ENDPOINT");
13735
+ var getRivetPublicToken = () => getEnvUniversal("RIVET_PUBLIC_TOKEN");
13736
+ var getRivetkitRuntime = () => getEnvUniversal("RIVETKIT_RUNTIME");
13737
+ var getRivetkitRuntimeMode = () => {
13738
+ const value = getEnvUniversal("RIVETKIT_RUNTIME_MODE");
13739
+ if (value === void 0) return "envoy";
13740
+ if (value === "envoy" || value === "serverless") return value;
13741
+ throw new Error(
13742
+ `RIVETKIT_RUNTIME_MODE env var must be "envoy" or "serverless"; got "${value}"`
13743
+ );
13744
+ };
13745
+ var getRivetkitPublicDir = () => {
13746
+ const value = getEnvUniversal("RIVETKIT_PUBLIC_DIR");
13747
+ return value === void 0 || value === "" ? void 0 : value;
13748
+ };
13749
+ function parsePortEnv(raw) {
13750
+ if (raw === void 0 || raw === "") return void 0;
13751
+ const parsed = Number.parseInt(raw, 10);
13752
+ if (!Number.isFinite(parsed) || parsed < 1 || parsed > 65535 || String(parsed) !== raw.trim()) {
13753
+ throw new Error(
13754
+ `RIVET_PORT env var must be an integer between 1 and 65535; got "${raw}"`
13755
+ );
13821
13756
  }
13757
+ return parsed;
13822
13758
  }
13823
- function encodeCborCompat(value) {
13824
- return cbor.encode(encodeJsonCompatValue(value));
13825
- }
13826
- function decodeCborCompat(buffer) {
13827
- return reviveJsonCompatValue(cbor.decode(buffer));
13759
+ var getLogLevel = () => getEnvUniversal("RIVET_LOG_LEVEL") ?? getEnvUniversal("LOG_LEVEL");
13760
+ var getLogTarget = () => getEnvUniversal("RIVET_LOG_TARGET") === "1";
13761
+ var getLogTimestamp = () => getEnvUniversal("RIVET_LOG_TIMESTAMP") === "1";
13762
+ var getLogMessage = () => getEnvUniversal("RIVET_LOG_MESSAGE") === "1";
13763
+ var getLogErrorStack = () => getEnvUniversal("RIVET_LOG_ERROR_STACK") === "1";
13764
+ var getNodeEnv = () => getEnvUniversal("NODE_ENV");
13765
+ var getNextPhase = () => getEnvUniversal("NEXT_PHASE");
13766
+ var isDev = () => getNodeEnv() !== "production";
13767
+ function assertUnreachable(x) {
13768
+ throw new Error(`Unreachable case: ${x}`);
13828
13769
  }
13829
- function serializeWithEncoding(encoding, value, versionedDataHandler, version2, zodSchema, toJson, toBare) {
13830
- if (encoding === "json") {
13831
- const jsonValue = toJson(value);
13832
- const validated = zodSchema.parse(jsonValue);
13833
- return jsonStringifyCompat(validated);
13834
- } else if (encoding === "cbor") {
13835
- const jsonValue = toJson(value);
13836
- const validated = zodSchema.parse(jsonValue);
13837
- return cbor.encode(validated);
13838
- } else if (encoding === "bare") {
13839
- if (!versionedDataHandler) {
13840
- throw new Error(
13841
- "VersionedDataHandler is required for 'bare' encoding"
13842
- );
13843
- }
13844
- if (version2 === void 0) {
13845
- throw new Error("version is required for 'bare' encoding");
13770
+ function deconstructError(error46, exposeInternalError = false) {
13771
+ let statusCode;
13772
+ let public_;
13773
+ let group;
13774
+ let code;
13775
+ let message;
13776
+ let metadata;
13777
+ let rayId;
13778
+ let actor2;
13779
+ if (isCanonicalStructuredRivetError(error46)) {
13780
+ statusCode = typeof error46.statusCode === "number" ? error46.statusCode : error46.public ? 400 : 500;
13781
+ public_ = error46.public ?? false;
13782
+ group = error46.group;
13783
+ code = error46.code;
13784
+ message = error46.message;
13785
+ metadata = error46.metadata;
13786
+ rayId = error46.rayId;
13787
+ actor2 = error46.actor;
13788
+ } else if (RivetError.isActorError(error46) && error46.public) {
13789
+ statusCode = "statusCode" in error46 && error46.statusCode ? error46.statusCode : 400;
13790
+ public_ = true;
13791
+ group = error46.group;
13792
+ code = error46.code;
13793
+ message = getErrorMessage(error46);
13794
+ metadata = error46.metadata;
13795
+ rayId = error46.rayId;
13796
+ actor2 = error46.actor;
13797
+ } else if (exposeInternalError) {
13798
+ if (RivetError.isActorError(error46)) {
13799
+ statusCode = 500;
13800
+ public_ = false;
13801
+ group = error46.group;
13802
+ code = error46.code;
13803
+ message = getErrorMessage(error46);
13804
+ metadata = error46.metadata;
13805
+ rayId = error46.rayId;
13806
+ actor2 = error46.actor;
13807
+ } else {
13808
+ statusCode = 500;
13809
+ public_ = false;
13810
+ group = "rivetkit";
13811
+ code = INTERNAL_ERROR_CODE;
13812
+ message = getErrorMessage(error46);
13846
13813
  }
13847
- const bareValue = toBare(value);
13848
- return versionedDataHandler.serializeWithEmbeddedVersion(
13849
- bareValue,
13850
- version2
13851
- );
13852
13814
  } else {
13853
- assertUnreachable(encoding);
13815
+ statusCode = 500;
13816
+ public_ = false;
13817
+ group = "rivetkit";
13818
+ code = INTERNAL_ERROR_CODE;
13819
+ message = INTERNAL_ERROR_DESCRIPTION;
13820
+ if (RivetError.isActorError(error46)) {
13821
+ actor2 = error46.actor;
13822
+ }
13823
+ metadata = {
13824
+ //url: `https://dashboard.rivet.dev/projects/${actorMetadata.project.slug}/environments/${actorMetadata.environment.slug}/actors?actorId=${actorMetadata.actor.id}`,
13825
+ };
13854
13826
  }
13827
+ return {
13828
+ __type: "ActorError",
13829
+ statusCode,
13830
+ public: public_,
13831
+ group,
13832
+ code,
13833
+ message,
13834
+ metadata,
13835
+ rayId,
13836
+ actor: actor2
13837
+ };
13855
13838
  }
13856
- function deserializeWithEncoding(encoding, buffer, versionedDataHandler, zodSchema, fromJson, fromBare) {
13857
- if (encoding === "json") {
13858
- let parsed;
13859
- if (typeof buffer === "string") {
13860
- parsed = jsonParseCompat(buffer);
13839
+ function stringifyError(error46) {
13840
+ if (error46 instanceof Error) {
13841
+ if (typeof process !== "undefined" && getLogErrorStack()) {
13842
+ let stack;
13843
+ try {
13844
+ stack = error46.stack;
13845
+ } catch {
13846
+ stack = void 0;
13847
+ }
13848
+ return `${error46.name}: ${error46.message}${stack ? `
13849
+ ${stack}` : ""}`;
13861
13850
  } else {
13862
- const decoder = new TextDecoder("utf-8");
13863
- const jsonString = decoder.decode(buffer);
13864
- parsed = jsonParseCompat(jsonString);
13851
+ return `${error46.name}: ${error46.message}`;
13865
13852
  }
13866
- const validated = zodSchema.parse(parsed);
13867
- return fromJson(validated);
13868
- } else if (encoding === "cbor") {
13869
- (0, import_invariant.default)(
13870
- typeof buffer !== "string",
13871
- "buffer cannot be string for cbor encoding"
13872
- );
13873
- const decoded = decodeCborCompat(buffer);
13874
- const validated = zodSchema.parse(decoded);
13875
- return fromJson(validated);
13876
- } else if (encoding === "bare") {
13877
- (0, import_invariant.default)(
13878
- typeof buffer !== "string",
13879
- "buffer cannot be string for bare encoding"
13880
- );
13881
- if (!versionedDataHandler) {
13882
- throw new Error(
13883
- "VersionedDataHandler is required for 'bare' encoding"
13884
- );
13853
+ } else if (typeof error46 === "string") {
13854
+ return error46;
13855
+ } else if (typeof error46 === "object" && error46 !== null) {
13856
+ try {
13857
+ return `${JSON.stringify(error46)}`;
13858
+ } catch {
13859
+ return "[cannot stringify error]";
13885
13860
  }
13886
- const bareValue = versionedDataHandler.deserializeWithEmbeddedVersion(buffer);
13887
- return fromBare(bareValue);
13888
13861
  } else {
13889
- assertUnreachable(encoding);
13862
+ return `Unknown error: ${getErrorMessage(error46)}`;
13890
13863
  }
13891
13864
  }
13892
- var JSON_COMPAT_BIGINT = "$BigInt";
13893
- var JSON_COMPAT_ARRAY_BUFFER = "$ArrayBuffer";
13894
- var JSON_COMPAT_UINT8_ARRAY = "$Uint8Array";
13895
- var JSON_COMPAT_UNDEFINED = "$Undefined";
13896
- var JSON_COMPAT_SET = "$Set";
13897
- function isTypedArray(value) {
13898
- return value instanceof Uint8ClampedArray || value instanceof Uint16Array || value instanceof Uint32Array || value instanceof BigUint64Array || value instanceof Int8Array || value instanceof Int16Array || value instanceof Int32Array || value instanceof BigInt64Array || value instanceof Float32Array || value instanceof Float64Array;
13899
- }
13900
- function assertJsonCompatValue(value, path2 = "") {
13901
- var _a2;
13902
- if (value === null || value === void 0 || typeof value === "string" || typeof value === "number" || typeof value === "boolean" || typeof value === "bigint") {
13903
- return;
13904
- }
13905
- if (typeof value === "function") {
13906
- throw new TypeError(
13907
- `Value at ${path2 || "root"} is a function and is not CBOR serializable`
13908
- );
13909
- }
13910
- if (typeof value === "symbol") {
13911
- throw new TypeError(
13912
- `Value at ${path2 || "root"} is a symbol and is not CBOR serializable`
13913
- );
13914
- }
13915
- if (value instanceof Date || value instanceof RegExp || value instanceof Error || value instanceof ArrayBuffer || value instanceof Uint8Array || isTypedArray(value)) {
13916
- return;
13917
- }
13918
- if (value instanceof WeakMap) {
13919
- throw new TypeError(
13920
- `Value at ${path2 || "root"} is a WeakMap and is not CBOR serializable`
13921
- );
13922
- }
13923
- if (value instanceof WeakSet) {
13924
- throw new TypeError(
13925
- `Value at ${path2 || "root"} is a WeakSet and is not CBOR serializable`
13926
- );
13927
- }
13928
- if (value instanceof WeakRef) {
13929
- throw new TypeError(
13930
- `Value at ${path2 || "root"} is a WeakRef and is not CBOR serializable`
13931
- );
13932
- }
13933
- if (value instanceof Promise) {
13934
- throw new TypeError(
13935
- `Value at ${path2 || "root"} is a Promise and is not CBOR serializable`
13936
- );
13937
- }
13938
- if (value instanceof Map) {
13939
- for (const [k, v] of value.entries()) {
13940
- assertJsonCompatValue(k, `${path2 || "root"}.key(${String(k)})`);
13941
- assertJsonCompatValue(v, `${path2 || "root"}.value(${String(k)})`);
13942
- }
13943
- return;
13944
- }
13945
- if (value instanceof Set) {
13946
- let index = 0;
13947
- for (const item of value.values()) {
13948
- assertJsonCompatValue(item, `${path2 || "root"}.set[${index}]`);
13949
- index++;
13950
- }
13951
- return;
13865
+ function getErrorMessage(err) {
13866
+ if (err && typeof err === "object" && "message" in err && typeof err.message === "string") {
13867
+ return err.message;
13868
+ } else {
13869
+ return String(err);
13952
13870
  }
13953
- if (Array.isArray(value)) {
13954
- for (let i = 0; i < value.length; i++) {
13955
- assertJsonCompatValue(value[i], `${path2 || "root"}[${i}]`);
13871
+ }
13872
+ function noopNext() {
13873
+ return async () => {
13874
+ };
13875
+ }
13876
+ var package_default = {
13877
+ name: "rivetkit",
13878
+ version: "2.3.32",
13879
+ description: "Lightweight libraries for building stateful actors on edge platforms",
13880
+ license: "Apache-2.0",
13881
+ keywords: [
13882
+ "rivetkit",
13883
+ "stateful",
13884
+ "serverless",
13885
+ "actors",
13886
+ "agents",
13887
+ "realtime",
13888
+ "websocket",
13889
+ "actors",
13890
+ "framework"
13891
+ ],
13892
+ files: [
13893
+ "dist",
13894
+ "schemas",
13895
+ "src",
13896
+ "package.json"
13897
+ ],
13898
+ type: "module",
13899
+ exports: {
13900
+ ".": {
13901
+ import: {
13902
+ types: "./dist/tsup/mod.d.ts",
13903
+ default: "./dist/tsup/mod.js"
13904
+ },
13905
+ require: {
13906
+ types: "./dist/tsup/mod.d.cts",
13907
+ default: "./dist/tsup/mod.cjs"
13908
+ }
13909
+ },
13910
+ "./workflow": {
13911
+ import: {
13912
+ types: "./dist/tsup/workflow/mod.d.ts",
13913
+ default: "./dist/tsup/workflow/mod.js"
13914
+ },
13915
+ require: {
13916
+ types: "./dist/tsup/workflow/mod.d.cts",
13917
+ default: "./dist/tsup/workflow/mod.cjs"
13918
+ }
13919
+ },
13920
+ "./test": {
13921
+ import: {
13922
+ types: "./dist/tsup/test/mod.d.ts",
13923
+ default: "./dist/tsup/test/mod.js"
13924
+ },
13925
+ require: {
13926
+ types: "./dist/tsup/test/mod.d.cts",
13927
+ default: "./dist/tsup/test/mod.cjs"
13928
+ }
13929
+ },
13930
+ "./db": {
13931
+ import: {
13932
+ types: "./dist/tsup/db/mod.d.ts",
13933
+ default: "./dist/tsup/db/mod.js"
13934
+ },
13935
+ require: {
13936
+ types: "./dist/tsup/db/mod.d.cts",
13937
+ default: "./dist/tsup/db/mod.cjs"
13938
+ }
13939
+ },
13940
+ "./db/drizzle": {
13941
+ import: {
13942
+ types: "./dist/tsup/db/drizzle.d.ts",
13943
+ default: "./dist/tsup/db/drizzle.js"
13944
+ },
13945
+ require: {
13946
+ types: "./dist/tsup/db/drizzle.d.cts",
13947
+ default: "./dist/tsup/db/drizzle.cjs"
13948
+ }
13949
+ },
13950
+ "./unstable/migrations": {
13951
+ import: {
13952
+ types: "./dist/tsup/unstable/migrations.d.ts",
13953
+ default: "./dist/tsup/unstable/migrations.js"
13954
+ },
13955
+ require: {
13956
+ types: "./dist/tsup/unstable/migrations.d.cts",
13957
+ default: "./dist/tsup/unstable/migrations.cjs"
13958
+ }
13959
+ },
13960
+ "./dynamic": {
13961
+ import: {
13962
+ types: "./dist/tsup/dynamic/mod.d.ts",
13963
+ default: "./dist/tsup/dynamic/mod.js"
13964
+ },
13965
+ require: {
13966
+ types: "./dist/tsup/dynamic/mod.d.cts",
13967
+ default: "./dist/tsup/dynamic/mod.cjs"
13968
+ }
13969
+ },
13970
+ "./client": {
13971
+ import: {
13972
+ browser: {
13973
+ types: "./dist/browser/client.d.ts",
13974
+ default: "./dist/browser/client.js"
13975
+ },
13976
+ types: "./dist/tsup/client/mod.d.ts",
13977
+ default: "./dist/tsup/client/mod.js"
13978
+ },
13979
+ require: {
13980
+ types: "./dist/tsup/client/mod.d.cts",
13981
+ default: "./dist/tsup/client/mod.cjs"
13982
+ }
13983
+ },
13984
+ "./log": {
13985
+ import: {
13986
+ types: "./dist/tsup/common/log.d.ts",
13987
+ default: "./dist/tsup/common/log.js"
13988
+ },
13989
+ require: {
13990
+ types: "./dist/tsup/common/log.d.cts",
13991
+ default: "./dist/tsup/common/log.cjs"
13992
+ }
13993
+ },
13994
+ "./errors": {
13995
+ import: {
13996
+ types: "./dist/tsup/actor/errors.d.ts",
13997
+ default: "./dist/tsup/actor/errors.js"
13998
+ },
13999
+ require: {
14000
+ types: "./dist/tsup/actor/errors.d.cts",
14001
+ default: "./dist/tsup/actor/errors.cjs"
14002
+ }
14003
+ },
14004
+ "./inspector": {
14005
+ import: {
14006
+ types: "./dist/tsup/inspector/mod.d.ts",
14007
+ default: "./dist/tsup/inspector/mod.js"
14008
+ },
14009
+ require: {
14010
+ types: "./dist/tsup/inspector/mod.d.cts",
14011
+ default: "./dist/tsup/inspector/mod.cjs"
14012
+ }
14013
+ },
14014
+ "./experimental/inspector/workflow": {
14015
+ import: {
14016
+ types: "./dist/tsup/inspector/workflow.d.ts",
14017
+ default: "./dist/tsup/inspector/workflow.js"
14018
+ },
14019
+ require: {
14020
+ types: "./dist/tsup/inspector/workflow.d.cts",
14021
+ default: "./dist/tsup/inspector/workflow.cjs"
14022
+ }
14023
+ },
14024
+ "./inspector-tab": {
14025
+ import: {
14026
+ types: "./dist/tsup/inspector-tab/mod.d.ts",
14027
+ default: "./dist/tsup/inspector-tab/mod.js"
14028
+ },
14029
+ require: {
14030
+ types: "./dist/tsup/inspector-tab/mod.d.cts",
14031
+ default: "./dist/tsup/inspector-tab/mod.cjs"
14032
+ }
14033
+ },
14034
+ "./inspector/client": {
14035
+ import: {
14036
+ types: "./dist/browser/inspector/client.d.ts",
14037
+ default: "./dist/browser/inspector/client.js"
14038
+ }
14039
+ },
14040
+ "./utils": {
14041
+ import: {
14042
+ types: "./dist/tsup/utils.d.ts",
14043
+ default: "./dist/tsup/utils.js"
14044
+ },
14045
+ require: {
14046
+ types: "./dist/tsup/utils.d.cts",
14047
+ default: "./dist/tsup/utils.cjs"
14048
+ }
14049
+ },
14050
+ "./agent-os": {
14051
+ import: {
14052
+ types: "./dist/tsup/agent-os/index.d.ts",
14053
+ default: "./dist/tsup/agent-os/index.js"
14054
+ },
14055
+ require: {
14056
+ types: "./dist/tsup/agent-os/index.d.cts",
14057
+ default: "./dist/tsup/agent-os/index.cjs"
14058
+ }
13956
14059
  }
13957
- return;
13958
- }
13959
- if (isPlainObject2(value)) {
13960
- for (const key in value) {
13961
- assertJsonCompatValue(
13962
- value[key],
13963
- path2 ? `${path2}.${key}` : key
13964
- );
14060
+ },
14061
+ engines: {
14062
+ node: ">=22.0.0"
14063
+ },
14064
+ sideEffects: [
14065
+ "./dist/tsup/chunk-*.js",
14066
+ "./dist/tsup/chunk-*.cjs"
14067
+ ],
14068
+ scripts: {
14069
+ build: "tsup src/mod.ts src/client/mod.ts src/common/log.ts src/common/websocket.ts src/actor/errors.ts src/utils.ts src/workflow/mod.ts src/test/mod.ts src/inspector/mod.ts src/inspector/workflow.ts src/inspector-tab/mod.ts src/db/mod.ts src/db/drizzle.ts src/dynamic/mod.ts src/unstable/migrations.ts && tsup src/agent-os/index.ts --no-clean --out-dir dist/tsup/agent-os && node scripts/check-built-commonjs.mjs",
14070
+ "build:browser": "tsup --config tsup.browser.config.ts",
14071
+ "check-types": "tsc --noEmit",
14072
+ lint: "biome check . && pnpm run check:test-skips && pnpm run check:wait-for-comments",
14073
+ "lint:fix": "biome check --write .",
14074
+ "check:test-skips": "tsx scripts/check-annotated-skips.ts",
14075
+ "check:wait-for-comments": "tsx scripts/check-wait-for-comments.ts",
14076
+ format: "biome format .",
14077
+ "format:write": "biome format --write .",
14078
+ test: "vitest run",
14079
+ "test:platforms": "pnpm run build && RIVETKIT_INCLUDE_PLATFORM_TESTS=1 vitest run tests/platforms --passWithNoTests",
14080
+ "test:watch": "vitest",
14081
+ "dump-asyncapi": "tsx scripts/dump-asyncapi.ts",
14082
+ "registry-config-schema-gen": "tsx scripts/registry-config-schema-gen.ts",
14083
+ "actor-config-schema-gen": "tsx scripts/actor-config-schema-gen.ts"
14084
+ },
14085
+ dependencies: {
14086
+ "@hono/zod-openapi": "^1.1.5",
14087
+ "@opentelemetry/api": "^1.1.0",
14088
+ "@rivet-dev/services": "^0.2.3",
14089
+ "@rivetkit/bare-ts": "^0.6.2",
14090
+ "@rivetkit/engine-api-full": "workspace:*",
14091
+ "@rivetkit/engine-cli": "workspace:*",
14092
+ "@rivetkit/engine-envoy-protocol": "workspace:*",
14093
+ "@rivetkit/on-change": "6.0.1",
14094
+ "@rivetkit/rivetkit-napi": "workspace:*",
14095
+ "@rivetkit/rivetkit-wasm": "workspace:*",
14096
+ "@rivetkit/traces": "workspace:*",
14097
+ "@rivetkit/virtual-websocket": "workspace:*",
14098
+ "@rivetkit/workflow-engine": "workspace:*",
14099
+ "cbor-x": "^1.6.0",
14100
+ "drizzle-orm": "catalog:",
14101
+ hono: "^4.7.0",
14102
+ invariant: "^2.2.4",
14103
+ "p-retry": "^6.2.1",
14104
+ pino: "^9.5.0",
14105
+ uuid: "^12.0.0",
14106
+ vbare: "^0.0.4",
14107
+ zod: "^4.1.0"
14108
+ },
14109
+ devDependencies: {
14110
+ "@biomejs/biome": "^2.3",
14111
+ "@copilotkit/llmock": "^1.6.0",
14112
+ "@hono/node-server": "^1.18.2",
14113
+ "@hono/node-ws": "^1.1.1",
14114
+ "@opentelemetry/sdk-trace-node": "2.11.0",
14115
+ "@standard-schema/spec": "^1.0.0",
14116
+ "@types/invariant": "^2",
14117
+ "@types/node": "^22.13.1",
14118
+ eventsource: "^4.0.0",
14119
+ "get-port": "^7.1.0",
14120
+ tsup: "^8.4.0",
14121
+ tsx: "^4.19.4",
14122
+ typescript: "^5.7.3",
14123
+ "vite-tsconfig-paths": "^5.1.4",
14124
+ vitest: "^3.1.1",
14125
+ ws: "^8.18.1"
14126
+ },
14127
+ peerDependencies: {
14128
+ "drizzle-kit": "^0.31.2",
14129
+ eventsource: "^4.0.0",
14130
+ ws: "^8.0.0"
14131
+ },
14132
+ peerDependenciesMeta: {
14133
+ "drizzle-kit": {
14134
+ optional: true
14135
+ },
14136
+ eventsource: {
14137
+ optional: true
14138
+ },
14139
+ ws: {
14140
+ optional: true
13965
14141
  }
13966
- return;
13967
- }
13968
- const typeName = typeof value === "object" && value !== null ? ((_a2 = value.constructor) == null ? void 0 : _a2.name) ?? typeof value : typeof value;
13969
- throw new TypeError(
13970
- `Value at ${path2 || "root"} of type "${typeName}" is not CBOR serializable`
13971
- );
13972
- }
13973
- var EncodingSchema = external_exports.enum(["json", "cbor", "bare"]);
13974
- async function inputDataToBuffer(data) {
13975
- if (typeof data === "string") {
13976
- return data;
13977
- }
13978
- if (data instanceof Blob) {
13979
- return new Uint8Array(await data.arrayBuffer());
14142
+ },
14143
+ stableVersion: "0.8.0"
14144
+ };
14145
+ var baseLogger;
14146
+ var configuredLogLevel;
14147
+ var loggerCache = /* @__PURE__ */ new Map();
14148
+ var LogLevelSchema = external_exports.enum([
14149
+ "trace",
14150
+ "debug",
14151
+ "info",
14152
+ "warn",
14153
+ "error",
14154
+ "fatal",
14155
+ "silent"
14156
+ ]);
14157
+ function getPinoLevel(logLevel) {
14158
+ if (logLevel) {
14159
+ return logLevel;
13980
14160
  }
13981
- if (data instanceof Uint8Array) {
13982
- return data;
14161
+ if (configuredLogLevel) {
14162
+ return configuredLogLevel;
13983
14163
  }
13984
- if (data instanceof ArrayBuffer || data instanceof SharedArrayBuffer) {
13985
- return new Uint8Array(data);
14164
+ const raw = (getLogLevel() || "warn").toString().toLowerCase();
14165
+ const parsed = LogLevelSchema.safeParse(raw);
14166
+ if (parsed.success) {
14167
+ return parsed.data;
13986
14168
  }
13987
- throw new Error("Malformed message");
14169
+ return "info";
13988
14170
  }
13989
- function base64EncodeUint8Array(uint8Array) {
13990
- let binary = "";
13991
- for (const value of uint8Array) {
13992
- binary += String.fromCharCode(value);
13993
- }
13994
- return btoa(binary);
14171
+ function getIncludeTarget() {
14172
+ return getLogTarget();
13995
14173
  }
13996
- function base64EncodeArrayBuffer(arrayBuffer) {
13997
- return base64EncodeUint8Array(new Uint8Array(arrayBuffer));
14174
+ function configureBaseLogger(logger23) {
14175
+ baseLogger = logger23;
14176
+ loggerCache.clear();
13998
14177
  }
13999
- function isPlainObject2(value) {
14000
- if (value === null || typeof value !== "object") {
14001
- return false;
14002
- }
14003
- const proto = Object.getPrototypeOf(value);
14004
- return proto === Object.prototype || proto === null;
14178
+ function makeDefaultLogger(logLevel) {
14179
+ return (0, import_pino.pino)(
14180
+ {
14181
+ level: getPinoLevel(logLevel),
14182
+ messageKey: "msg",
14183
+ // Do not include pid/hostname in output
14184
+ base: {},
14185
+ errorKey: "error",
14186
+ // Keep the numeric level so the logfmt sink can match Pino's levels.
14187
+ formatters: {
14188
+ level(_label, number4) {
14189
+ return { level: number4 };
14190
+ }
14191
+ },
14192
+ timestamp: getLogTimestamp() ? import_pino.stdTimeFunctions.epochTime : false
14193
+ },
14194
+ createLogfmtDestination()
14195
+ );
14005
14196
  }
14006
- function encodeJsonCompatValue(input) {
14007
- var _a2;
14008
- if (input === null) {
14009
- return input;
14010
- }
14011
- if (input === void 0) {
14012
- return [JSON_COMPAT_UNDEFINED, 0];
14013
- }
14014
- if (typeof input === "string" || typeof input === "number" || typeof input === "boolean") {
14015
- return input;
14016
- }
14017
- if (typeof input === "bigint") {
14018
- return [JSON_COMPAT_BIGINT, input.toString()];
14019
- }
14020
- if (input instanceof ArrayBuffer) {
14021
- return [JSON_COMPAT_ARRAY_BUFFER, base64EncodeArrayBuffer(input)];
14022
- }
14023
- if (input instanceof Uint8Array) {
14024
- return [JSON_COMPAT_UINT8_ARRAY, base64EncodeUint8Array(input)];
14025
- }
14026
- if (isTypedArray(input)) {
14027
- return input;
14028
- }
14029
- if (input instanceof Date || input instanceof RegExp || input instanceof Error) {
14030
- return input;
14031
- }
14032
- if (input instanceof Set) {
14033
- const encoded = [...input.values()].map(
14034
- (v) => encodeJsonCompatValue(v)
14035
- );
14036
- return [JSON_COMPAT_SET, encoded];
14037
- }
14038
- if (input instanceof Map) {
14039
- const encoded = /* @__PURE__ */ new Map();
14040
- for (const [k, v] of input.entries()) {
14041
- encoded.set(
14042
- encodeJsonCompatValue(k),
14043
- encodeJsonCompatValue(v)
14044
- );
14045
- }
14046
- return encoded;
14047
- }
14048
- if (Array.isArray(input)) {
14049
- const encoded = input.map(
14050
- (value) => encodeJsonCompatValue(value)
14051
- );
14052
- if (encoded.length === 2 && typeof encoded[0] === "string" && encoded[0].startsWith("$")) {
14053
- return [`$${encoded[0]}`, encoded[1]];
14054
- }
14055
- return encoded;
14056
- }
14057
- if (isPlainObject2(input)) {
14058
- const encoded = {};
14059
- for (const [key, value] of Object.entries(input)) {
14060
- encoded[key] = encodeJsonCompatValue(value);
14061
- }
14062
- return encoded;
14197
+ function configureDefaultLogger(logLevel) {
14198
+ if (logLevel) {
14199
+ configuredLogLevel = logLevel;
14063
14200
  }
14064
- const typeName = typeof input === "object" && input !== null ? ((_a2 = input.constructor) == null ? void 0 : _a2.name) ?? typeof input : typeof input;
14065
- throw new TypeError(`Value of type "${typeName}" is not CBOR serializable`);
14201
+ baseLogger = makeDefaultLogger(logLevel);
14202
+ loggerCache.clear();
14066
14203
  }
14067
- function reviveJsonCompatValue(input, options = {}) {
14068
- if (typeof input === "bigint") {
14069
- if (options.coerceSafeIntegerBigInts && input >= BigInt(Number.MIN_SAFE_INTEGER) && input <= BigInt(Number.MAX_SAFE_INTEGER)) {
14070
- return Number(input);
14071
- }
14072
- return input;
14204
+ function getBaseLogger() {
14205
+ if (!baseLogger) {
14206
+ configureDefaultLogger();
14073
14207
  }
14074
- if (input instanceof Map) {
14075
- const revived = /* @__PURE__ */ new Map();
14076
- for (const [k, v] of input.entries()) {
14077
- revived.set(
14078
- reviveJsonCompatValue(k, options),
14079
- reviveJsonCompatValue(v, options)
14080
- );
14081
- }
14082
- return revived;
14208
+ return baseLogger;
14209
+ }
14210
+ function getLogger(name = "default") {
14211
+ const cached2 = loggerCache.get(name);
14212
+ if (cached2) {
14213
+ return cached2;
14083
14214
  }
14084
- if (Array.isArray(input)) {
14085
- if (input.length === 2 && typeof input[0] === "string" && input[0].startsWith("$")) {
14086
- if (input[0] === JSON_COMPAT_BIGINT) {
14087
- return BigInt(input[1]);
14088
- }
14089
- if (input[0] === JSON_COMPAT_ARRAY_BUFFER) {
14090
- return base64DecodeToArrayBuffer(input[1]);
14091
- }
14092
- if (input[0] === JSON_COMPAT_UINT8_ARRAY) {
14093
- return base64DecodeToUint8Array(input[1]);
14094
- }
14095
- if (input[0] === JSON_COMPAT_UNDEFINED) {
14096
- return void 0;
14097
- }
14098
- if (input[0] === JSON_COMPAT_SET) {
14099
- const items = input[1].map(
14100
- (v) => reviveJsonCompatValue(v, options)
14101
- );
14102
- return new Set(items);
14103
- }
14104
- if (input[0].startsWith("$$")) {
14105
- return [
14106
- input[0].substring(1),
14107
- reviveJsonCompatValue(input[1], options)
14108
- ];
14215
+ const base = getBaseLogger();
14216
+ const child = getIncludeTarget() ? base.child({ target: name }) : base;
14217
+ loggerCache.set(name, child);
14218
+ return child;
14219
+ }
14220
+ var PINO_LEVEL_LABELS = {
14221
+ 10: "trace",
14222
+ 20: "debug",
14223
+ 30: "info",
14224
+ 40: "warn",
14225
+ 50: "error",
14226
+ 60: "fatal"
14227
+ };
14228
+ function createLogfmtDestination() {
14229
+ return {
14230
+ write(msg) {
14231
+ var _a2;
14232
+ const line = formatLogfmtLine(msg);
14233
+ if (typeof process !== "undefined" && ((_a2 = process.stdout) == null ? void 0 : _a2.write)) {
14234
+ process.stdout.write(`${line}
14235
+ `);
14236
+ } else {
14237
+ console.log(line);
14109
14238
  }
14110
- throw new Error(
14111
- `Unknown JSON encoding type: ${input[0]}. This may indicate corrupted data or a version mismatch.`
14112
- );
14113
14239
  }
14114
- return input.map((value) => reviveJsonCompatValue(value, options));
14240
+ };
14241
+ }
14242
+ function formatLogfmtLine(raw) {
14243
+ let data;
14244
+ try {
14245
+ data = JSON.parse(raw);
14246
+ } catch {
14247
+ return raw.trimEnd();
14115
14248
  }
14116
- if (isPlainObject2(input)) {
14117
- const decoded = {};
14118
- for (const [key, value] of Object.entries(input)) {
14119
- decoded[key] = reviveJsonCompatValue(value, options);
14249
+ const parts = [];
14250
+ appendLogfmtEntry(parts, "level", formatPinoLevel(data.level));
14251
+ if (data.time !== void 0) {
14252
+ appendLogfmtEntry(parts, "ts", data.time);
14253
+ }
14254
+ for (const [key, value] of Object.entries(data)) {
14255
+ if (key === "level" || key === "time") {
14256
+ continue;
14120
14257
  }
14121
- return decoded;
14258
+ appendLogfmtEntry(parts, key, value);
14122
14259
  }
14123
- return input;
14260
+ return parts.join(" ");
14124
14261
  }
14125
- function base64DecodeToUint8Array(base643) {
14126
- if (typeof Buffer !== "undefined") {
14127
- return new Uint8Array(Buffer.from(base643, "base64"));
14262
+ function formatPinoLevel(level) {
14263
+ if (typeof level === "number") {
14264
+ return PINO_LEVEL_LABELS[level] ?? level.toString();
14128
14265
  }
14129
- const binary = atob(base643);
14130
- const bytes = new Uint8Array(binary.length);
14131
- for (let i = 0; i < binary.length; i++) {
14132
- bytes[i] = binary.charCodeAt(i);
14266
+ if (typeof level === "string") {
14267
+ return level.toLowerCase();
14133
14268
  }
14134
- return bytes;
14135
- }
14136
- function base64DecodeToArrayBuffer(base643) {
14137
- return base64DecodeToUint8Array(base643).buffer;
14138
- }
14139
- function jsonStringifyCompat(input, space) {
14140
- return JSON.stringify(
14141
- input,
14142
- (_key, value) => {
14143
- if (typeof value === "bigint") {
14144
- return [JSON_COMPAT_BIGINT, value.toString()];
14145
- }
14146
- if (value instanceof ArrayBuffer) {
14147
- return [
14148
- JSON_COMPAT_ARRAY_BUFFER,
14149
- base64EncodeArrayBuffer(value)
14150
- ];
14151
- }
14152
- if (value instanceof Uint8Array) {
14153
- return [JSON_COMPAT_UINT8_ARRAY, base64EncodeUint8Array(value)];
14154
- }
14155
- if (Array.isArray(value) && value.length === 2 && typeof value[0] === "string" && value[0].startsWith("$")) {
14156
- return [`$${value[0]}`, value[1]];
14157
- }
14158
- return value;
14159
- },
14160
- space
14161
- );
14269
+ return "info";
14162
14270
  }
14163
- function jsonParseCompat(input) {
14164
- return reviveJsonCompatValue(JSON.parse(input));
14271
+ function appendLogfmtEntry(parts, key, value) {
14272
+ const safeKey = key.replace(/[\s="]/g, "");
14273
+ if (safeKey.length === 0) {
14274
+ return;
14275
+ }
14276
+ parts.push(`${safeKey}=${formatLogfmtValue(value)}`);
14165
14277
  }
14166
- var VERSION = package_default.version;
14167
- var _userAgent;
14168
- function httpUserAgent() {
14169
- if (_userAgent !== void 0) {
14170
- return _userAgent;
14278
+ function formatLogfmtValue(value) {
14279
+ if (typeof value === "number" || typeof value === "boolean") {
14280
+ return String(value);
14171
14281
  }
14172
- let userAgent = `RivetKit/${VERSION}`;
14173
- const navigatorObj = typeof navigator !== "undefined" ? navigator : void 0;
14174
- if (navigatorObj == null ? void 0 : navigatorObj.userAgent) userAgent += ` ${navigatorObj.userAgent}`;
14175
- _userAgent = userAgent;
14176
- return userAgent;
14282
+ if (value === null || value === void 0) {
14283
+ return "null";
14284
+ }
14285
+ if (typeof value === "string") {
14286
+ return quoteLogfmtString(value);
14287
+ }
14288
+ return quoteLogfmtString(JSON.stringify(value));
14177
14289
  }
14178
- function getEnvUniversal(key) {
14179
- if (typeof Deno !== "undefined") {
14180
- return Deno.env.get(key);
14181
- } else if (typeof process !== "undefined") {
14182
- return process.env[key];
14290
+ function quoteLogfmtString(value) {
14291
+ if (!/[\s="]/.test(value)) {
14292
+ return value;
14183
14293
  }
14294
+ return `"${value.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "\\n")}"`;
14184
14295
  }
14185
- function toUint8Array(data) {
14186
- if (data instanceof Uint8Array) {
14187
- return data;
14188
- } else if (data instanceof ArrayBuffer) {
14189
- return new Uint8Array(data);
14190
- } else if (ArrayBuffer.isView(data)) {
14191
- return new Uint8Array(
14192
- data.buffer.slice(
14193
- data.byteOffset,
14194
- data.byteOffset + data.byteLength
14195
- )
14196
- );
14296
+ function uint8ArrayToBase642(uint8Array) {
14297
+ if (typeof Buffer !== "undefined") {
14298
+ return Buffer.from(uint8Array).toString("base64");
14299
+ }
14300
+ let binary = "";
14301
+ const len = uint8Array.byteLength;
14302
+ for (let i = 0; i < len; i++) {
14303
+ binary += String.fromCharCode(uint8Array[i]);
14304
+ }
14305
+ return btoa(binary);
14306
+ }
14307
+ function contentTypeForEncoding(encoding) {
14308
+ if (encoding === "json") {
14309
+ return "application/json";
14310
+ } else if (encoding === "cbor" || encoding === "bare") {
14311
+ return "application/octet-stream";
14197
14312
  } else {
14198
- throw new TypeError("Input must be ArrayBuffer or ArrayBufferView");
14313
+ assertUnreachable(encoding);
14199
14314
  }
14200
14315
  }
14201
- function promiseWithResolvers(onReject) {
14202
- let resolve;
14203
- let reject;
14204
- const promise2 = new Promise((res, rej) => {
14205
- resolve = res;
14206
- reject = rej;
14207
- });
14208
- promise2.catch(onReject);
14209
- return { promise: promise2, resolve, reject };
14316
+ function encodeCborCompat(value) {
14317
+ return cbor.encode(encodeJsonCompatValue(value));
14210
14318
  }
14211
- function bufferToArrayBuffer(buf) {
14212
- return buf.buffer.slice(
14213
- buf.byteOffset,
14214
- buf.byteOffset + buf.byteLength
14215
- );
14319
+ function decodeCborCompat(buffer) {
14320
+ return reviveJsonCompatValue(cbor.decode(buffer));
14216
14321
  }
14217
- function combineUrlPath(endpoint, path2, queryParams) {
14218
- const baseUrl = new URL(endpoint);
14219
- const pathParts = path2.split("?");
14220
- const pathOnly = pathParts[0];
14221
- const existingQuery = pathParts[1] || "";
14222
- const basePath = baseUrl.pathname.replace(/\/$/, "");
14223
- const cleanPath = pathOnly.startsWith("/") ? pathOnly : `/${pathOnly}`;
14224
- const fullPath = (basePath + cleanPath).replace(/\/\//g, "/");
14225
- const queryParts = [];
14226
- if (existingQuery) {
14227
- queryParts.push(existingQuery);
14228
- }
14229
- if (queryParams) {
14230
- for (const [key, value] of Object.entries(queryParams)) {
14231
- if (value !== void 0) {
14232
- queryParts.push(
14233
- `${encodeURIComponent(key)}=${encodeURIComponent(value)}`
14234
- );
14235
- }
14322
+ function serializeWithEncoding(encoding, value, versionedDataHandler, version2, zodSchema, toJson, toBare) {
14323
+ if (encoding === "json") {
14324
+ const jsonValue = toJson(value);
14325
+ const validated = zodSchema.parse(jsonValue);
14326
+ return jsonStringifyCompat(validated);
14327
+ } else if (encoding === "cbor") {
14328
+ const jsonValue = toJson(value);
14329
+ const validated = zodSchema.parse(jsonValue);
14330
+ return cbor.encode(validated);
14331
+ } else if (encoding === "bare") {
14332
+ if (!versionedDataHandler) {
14333
+ throw new Error(
14334
+ "VersionedDataHandler is required for 'bare' encoding"
14335
+ );
14236
14336
  }
14237
- }
14238
- const fullQuery = queryParts.length > 0 ? `?${queryParts.join("&")}` : "";
14239
- return `${baseUrl.protocol}//${baseUrl.host}${fullPath}${fullQuery}`;
14240
- }
14241
-
14242
- // ../../../node_modules/.pnpm/@rivetkit+bare-ts@0.6.2/node_modules/@rivetkit/bare-ts/imports/dev.node.js
14243
- var DEV = process.env.NODE_ENV === "development";
14244
-
14245
- // ../../../node_modules/.pnpm/@rivetkit+bare-ts@0.6.2/node_modules/@rivetkit/bare-ts/dist/util/assert.js
14246
- var V8Error = Error;
14247
- function assert2(test, message = "") {
14248
- if (!test) {
14249
- const e = new AssertionError(message);
14250
- V8Error.captureStackTrace?.(e, assert2);
14251
- throw e;
14337
+ if (version2 === void 0) {
14338
+ throw new Error("version is required for 'bare' encoding");
14339
+ }
14340
+ const bareValue = toBare(value);
14341
+ return versionedDataHandler.serializeWithEmbeddedVersion(
14342
+ bareValue,
14343
+ version2
14344
+ );
14345
+ } else {
14346
+ assertUnreachable(encoding);
14252
14347
  }
14253
14348
  }
14254
- var AssertionError = class extends Error {
14255
- constructor() {
14256
- super(...arguments);
14257
- this.name = "AssertionError";
14349
+ function deserializeWithEncoding(encoding, buffer, versionedDataHandler, zodSchema, fromJson, fromBare) {
14350
+ if (encoding === "json") {
14351
+ let parsed;
14352
+ if (typeof buffer === "string") {
14353
+ parsed = jsonParseCompat(buffer);
14354
+ } else {
14355
+ const decoder = new TextDecoder("utf-8");
14356
+ const jsonString = decoder.decode(buffer);
14357
+ parsed = jsonParseCompat(jsonString);
14358
+ }
14359
+ const validated = zodSchema.parse(parsed);
14360
+ return fromJson(validated);
14361
+ } else if (encoding === "cbor") {
14362
+ (0, import_invariant.default)(
14363
+ typeof buffer !== "string",
14364
+ "buffer cannot be string for cbor encoding"
14365
+ );
14366
+ const decoded = decodeCborCompat(buffer);
14367
+ const validated = zodSchema.parse(decoded);
14368
+ return fromJson(validated);
14369
+ } else if (encoding === "bare") {
14370
+ (0, import_invariant.default)(
14371
+ typeof buffer !== "string",
14372
+ "buffer cannot be string for bare encoding"
14373
+ );
14374
+ if (!versionedDataHandler) {
14375
+ throw new Error(
14376
+ "VersionedDataHandler is required for 'bare' encoding"
14377
+ );
14378
+ }
14379
+ const bareValue = versionedDataHandler.deserializeWithEmbeddedVersion(buffer);
14380
+ return fromBare(bareValue);
14381
+ } else {
14382
+ assertUnreachable(encoding);
14258
14383
  }
14259
- };
14260
-
14261
- // ../../../node_modules/.pnpm/@rivetkit+bare-ts@0.6.2/node_modules/@rivetkit/bare-ts/dist/util/validator.js
14262
- function isU8(val) {
14263
- return val === (val & 255);
14264
- }
14265
- function isU32(val) {
14266
- return val === val >>> 0;
14267
14384
  }
14268
- function isU64(val) {
14269
- return val === BigInt.asUintN(64, val);
14385
+ var JSON_COMPAT_BIGINT = "$BigInt";
14386
+ var JSON_COMPAT_ARRAY_BUFFER = "$ArrayBuffer";
14387
+ var JSON_COMPAT_UINT8_ARRAY = "$Uint8Array";
14388
+ var JSON_COMPAT_UNDEFINED = "$Undefined";
14389
+ var JSON_COMPAT_SET = "$Set";
14390
+ function isTypedArray(value) {
14391
+ return value instanceof Uint8ClampedArray || value instanceof Uint16Array || value instanceof Uint32Array || value instanceof BigUint64Array || value instanceof Int8Array || value instanceof Int16Array || value instanceof Int32Array || value instanceof BigInt64Array || value instanceof Float32Array || value instanceof Float64Array;
14270
14392
  }
14271
-
14272
- // ../../../node_modules/.pnpm/@rivetkit+bare-ts@0.6.2/node_modules/@rivetkit/bare-ts/dist/util/constants.js
14273
- var TEXT_DECODER_THRESHOLD = 256;
14274
- var TEXT_ENCODER_THRESHOLD = 256;
14275
- var INT_SAFE_MAX_BYTE_COUNT = 8;
14276
- var UINT_MAX_BYTE_COUNT = 10;
14277
- var UINT_SAFE32_MAX_BYTE_COUNT = 5;
14278
- var INVALID_UTF8_STRING = "invalid UTF-8 string";
14279
- var NON_CANONICAL_REPRESENTATION = "must be canonical";
14280
- var TOO_LARGE_BUFFER = "too large buffer";
14281
- var TOO_LARGE_NUMBER = "too large number";
14282
-
14283
- // ../../../node_modules/.pnpm/@rivetkit+bare-ts@0.6.2/node_modules/@rivetkit/bare-ts/dist/core/bare-error.js
14284
- var BareError = class extends Error {
14285
- constructor(offset, issue2, opts) {
14286
- super(`(byte:${offset}) ${issue2}`);
14287
- this.name = "BareError";
14288
- this.issue = issue2;
14289
- this.offset = offset;
14290
- this.cause = opts?.cause;
14393
+ function assertJsonCompatValue(value, path2 = "") {
14394
+ var _a2;
14395
+ if (value === null || value === void 0 || typeof value === "string" || typeof value === "number" || typeof value === "boolean" || typeof value === "bigint") {
14396
+ return;
14397
+ }
14398
+ if (typeof value === "function") {
14399
+ throw new TypeError(
14400
+ `Value at ${path2 || "root"} is a function and is not CBOR serializable`
14401
+ );
14402
+ }
14403
+ if (typeof value === "symbol") {
14404
+ throw new TypeError(
14405
+ `Value at ${path2 || "root"} is a symbol and is not CBOR serializable`
14406
+ );
14407
+ }
14408
+ if (value instanceof Date || value instanceof RegExp || value instanceof Error || value instanceof ArrayBuffer || value instanceof Uint8Array || isTypedArray(value)) {
14409
+ return;
14410
+ }
14411
+ if (value instanceof WeakMap) {
14412
+ throw new TypeError(
14413
+ `Value at ${path2 || "root"} is a WeakMap and is not CBOR serializable`
14414
+ );
14415
+ }
14416
+ if (value instanceof WeakSet) {
14417
+ throw new TypeError(
14418
+ `Value at ${path2 || "root"} is a WeakSet and is not CBOR serializable`
14419
+ );
14420
+ }
14421
+ if (value instanceof WeakRef) {
14422
+ throw new TypeError(
14423
+ `Value at ${path2 || "root"} is a WeakRef and is not CBOR serializable`
14424
+ );
14425
+ }
14426
+ if (value instanceof Promise) {
14427
+ throw new TypeError(
14428
+ `Value at ${path2 || "root"} is a Promise and is not CBOR serializable`
14429
+ );
14430
+ }
14431
+ if (value instanceof Map) {
14432
+ for (const [k, v] of value.entries()) {
14433
+ assertJsonCompatValue(k, `${path2 || "root"}.key(${String(k)})`);
14434
+ assertJsonCompatValue(v, `${path2 || "root"}.value(${String(k)})`);
14435
+ }
14436
+ return;
14291
14437
  }
14292
- };
14293
-
14294
- // ../../../node_modules/.pnpm/@rivetkit+bare-ts@0.6.2/node_modules/@rivetkit/bare-ts/dist/core/byte-cursor.js
14295
- var ByteCursor = class {
14296
- /**
14297
- * @throws {BareError} Buffer exceeds `config.maxBufferLength`
14298
- */
14299
- constructor(bytes, config3) {
14300
- this.offset = 0;
14301
- if (bytes.length > config3.maxBufferLength) {
14302
- throw new BareError(0, TOO_LARGE_BUFFER);
14438
+ if (value instanceof Set) {
14439
+ let index = 0;
14440
+ for (const item of value.values()) {
14441
+ assertJsonCompatValue(item, `${path2 || "root"}.set[${index}]`);
14442
+ index++;
14303
14443
  }
14304
- this.bytes = bytes;
14305
- this.config = config3;
14306
- this.view = new DataView(bytes.buffer, bytes.byteOffset, bytes.length);
14444
+ return;
14307
14445
  }
14308
- };
14309
- function check2(bc, min) {
14310
- if (DEV) {
14311
- assert2(isU32(min));
14446
+ if (Array.isArray(value)) {
14447
+ for (let i = 0; i < value.length; i++) {
14448
+ assertJsonCompatValue(value[i], `${path2 || "root"}[${i}]`);
14449
+ }
14450
+ return;
14312
14451
  }
14313
- if (bc.offset + min > bc.bytes.length) {
14314
- throw new BareError(bc.offset, "missing bytes");
14452
+ if (isPlainObject2(value)) {
14453
+ for (const key in value) {
14454
+ assertJsonCompatValue(
14455
+ value[key],
14456
+ path2 ? `${path2}.${key}` : key
14457
+ );
14458
+ }
14459
+ return;
14315
14460
  }
14461
+ const typeName = typeof value === "object" && value !== null ? ((_a2 = value.constructor) == null ? void 0 : _a2.name) ?? typeof value : typeof value;
14462
+ throw new TypeError(
14463
+ `Value at ${path2 || "root"} of type "${typeName}" is not CBOR serializable`
14464
+ );
14316
14465
  }
14317
- function reserve(bc, min) {
14318
- if (DEV) {
14319
- assert2(isU32(min));
14466
+ var EncodingSchema = external_exports.enum(["json", "cbor", "bare"]);
14467
+ async function inputDataToBuffer(data) {
14468
+ if (typeof data === "string") {
14469
+ return data;
14320
14470
  }
14321
- const minLen = bc.offset + min | 0;
14322
- if (minLen > bc.bytes.length) {
14323
- grow(bc, minLen);
14471
+ if (data instanceof Blob) {
14472
+ return new Uint8Array(await data.arrayBuffer());
14324
14473
  }
14325
- }
14326
- function grow(bc, minLen) {
14327
- if (minLen > bc.config.maxBufferLength) {
14328
- throw new BareError(0, TOO_LARGE_BUFFER);
14474
+ if (data instanceof Uint8Array) {
14475
+ return data;
14329
14476
  }
14330
- const buffer = bc.bytes.buffer;
14331
- let newBytes;
14332
- if (isEs2024ArrayBufferLike(buffer) && // Make sure that the view covers the end of the buffer.
14333
- // If it is not the case, this indicates that the user don't want
14334
- // to override the trailing bytes.
14335
- bc.bytes.byteOffset + bc.bytes.byteLength === buffer.byteLength && bc.bytes.byteLength + minLen <= buffer.maxByteLength) {
14336
- const newLen = Math.min(minLen << 1, bc.config.maxBufferLength, buffer.maxByteLength);
14337
- if (buffer instanceof ArrayBuffer) {
14338
- buffer.resize(newLen);
14339
- } else {
14340
- buffer.grow(newLen);
14341
- }
14342
- newBytes = new Uint8Array(buffer, bc.bytes.byteOffset, newLen);
14343
- } else {
14344
- const newLen = Math.min(minLen << 1, bc.config.maxBufferLength);
14345
- newBytes = new Uint8Array(newLen);
14346
- newBytes.set(bc.bytes);
14477
+ if (data instanceof ArrayBuffer || data instanceof SharedArrayBuffer) {
14478
+ return new Uint8Array(data);
14347
14479
  }
14348
- bc.bytes = newBytes;
14349
- bc.view = new DataView(newBytes.buffer);
14350
- }
14351
- function isEs2024ArrayBufferLike(buffer) {
14352
- return "maxByteLength" in buffer;
14480
+ throw new Error("Malformed message");
14353
14481
  }
14354
-
14355
- // ../../../node_modules/.pnpm/@rivetkit+bare-ts@0.6.2/node_modules/@rivetkit/bare-ts/dist/codec/fixed-primitive.js
14356
- function readBool(bc) {
14357
- const val = readU8(bc);
14358
- if (val > 1) {
14359
- bc.offset--;
14360
- throw new BareError(bc.offset, "a bool must be equal to 0 or 1");
14482
+ function base64EncodeUint8Array(uint8Array) {
14483
+ let binary = "";
14484
+ for (const value of uint8Array) {
14485
+ binary += String.fromCharCode(value);
14361
14486
  }
14362
- return val > 0;
14363
- }
14364
- function writeBool(bc, x) {
14365
- writeU8(bc, x ? 1 : 0);
14487
+ return btoa(binary);
14366
14488
  }
14367
- function readU8(bc) {
14368
- check2(bc, 1);
14369
- return bc.bytes[bc.offset++];
14489
+ function base64EncodeArrayBuffer(arrayBuffer) {
14490
+ return base64EncodeUint8Array(new Uint8Array(arrayBuffer));
14370
14491
  }
14371
- function writeU8(bc, x) {
14372
- if (DEV) {
14373
- assert2(isU8(x), TOO_LARGE_NUMBER);
14492
+ function isPlainObject2(value) {
14493
+ if (value === null || typeof value !== "object") {
14494
+ return false;
14374
14495
  }
14375
- reserve(bc, 1);
14376
- bc.bytes[bc.offset++] = x;
14377
- }
14378
- function readU32(bc) {
14379
- check2(bc, 4);
14380
- const result = bc.view.getUint32(bc.offset, true);
14381
- bc.offset += 4;
14382
- return result;
14383
- }
14384
- function readU64(bc) {
14385
- check2(bc, 8);
14386
- const result = bc.view.getBigUint64(bc.offset, true);
14387
- bc.offset += 8;
14388
- return result;
14496
+ const proto = Object.getPrototypeOf(value);
14497
+ return proto === Object.prototype || proto === null;
14389
14498
  }
14390
- function writeU64(bc, x) {
14391
- if (DEV) {
14392
- assert2(isU64(x), TOO_LARGE_NUMBER);
14499
+ function encodeJsonCompatValue(input) {
14500
+ var _a2;
14501
+ if (input === null) {
14502
+ return input;
14393
14503
  }
14394
- reserve(bc, 8);
14395
- bc.view.setBigUint64(bc.offset, x, true);
14396
- bc.offset += 8;
14397
- }
14398
-
14399
- // ../../../node_modules/.pnpm/@rivetkit+bare-ts@0.6.2/node_modules/@rivetkit/bare-ts/dist/codec/uint.js
14400
- function readUint(bc) {
14401
- let low = readU8(bc);
14402
- if (low >= 128) {
14403
- low &= 127;
14404
- let shiftMul = 128;
14405
- let byteCount = 1;
14406
- let byte;
14407
- do {
14408
- byte = readU8(bc);
14409
- low += (byte & 127) * shiftMul;
14410
- shiftMul *= /* 2**7 */
14411
- 128;
14412
- byteCount++;
14413
- } while (byte >= 128 && byteCount < 7);
14414
- let height = 0;
14415
- shiftMul = 1;
14416
- while (byte >= 128 && byteCount < UINT_MAX_BYTE_COUNT) {
14417
- byte = readU8(bc);
14418
- height += (byte & 127) * shiftMul;
14419
- shiftMul *= /* 2**7 */
14420
- 128;
14421
- byteCount++;
14422
- }
14423
- if (byte === 0 || byteCount === UINT_MAX_BYTE_COUNT && byte > 1) {
14424
- bc.offset -= byteCount;
14425
- throw new BareError(bc.offset, NON_CANONICAL_REPRESENTATION);
14426
- }
14427
- return BigInt(low) + (BigInt(height) << BigInt(7 * 7));
14504
+ if (input === void 0) {
14505
+ return [JSON_COMPAT_UNDEFINED, 0];
14428
14506
  }
14429
- return BigInt(low);
14430
- }
14431
- function writeUint(bc, x) {
14432
- const truncated = BigInt.asUintN(64, x);
14433
- if (DEV) {
14434
- assert2(truncated === x, TOO_LARGE_NUMBER);
14507
+ if (typeof input === "string" || typeof input === "number" || typeof input === "boolean") {
14508
+ return input;
14435
14509
  }
14436
- writeUintTruncated(bc, truncated);
14437
- }
14438
- function writeUintTruncated(bc, x) {
14439
- let tmp = Number(BigInt.asUintN(7 * 7, x));
14440
- let rest = Number(x >> BigInt(7 * 7));
14441
- let byteCount = 0;
14442
- while (tmp >= 128 || rest > 0) {
14443
- writeU8(bc, 128 | tmp & 127);
14444
- tmp = Math.floor(tmp / /* 2**7 */
14445
- 128);
14446
- byteCount++;
14447
- if (byteCount === 7) {
14448
- tmp = rest;
14449
- rest = 0;
14450
- }
14510
+ if (typeof input === "bigint") {
14511
+ return [JSON_COMPAT_BIGINT, input.toString()];
14451
14512
  }
14452
- writeU8(bc, tmp);
14453
- }
14454
- function readUintSafe32(bc) {
14455
- let result = readU8(bc);
14456
- if (result >= 128) {
14457
- result &= 127;
14458
- let shift = 7;
14459
- let byteCount = 1;
14460
- let byte;
14461
- do {
14462
- byte = readU8(bc);
14463
- result += (byte & 127) << shift >>> 0;
14464
- shift += 7;
14465
- byteCount++;
14466
- } while (byte >= 128 && byteCount < UINT_SAFE32_MAX_BYTE_COUNT);
14467
- if (byte === 0) {
14468
- bc.offset -= byteCount - 1;
14469
- throw new BareError(bc.offset - byteCount + 1, NON_CANONICAL_REPRESENTATION);
14513
+ if (input instanceof ArrayBuffer) {
14514
+ return [JSON_COMPAT_ARRAY_BUFFER, base64EncodeArrayBuffer(input)];
14515
+ }
14516
+ if (input instanceof Uint8Array) {
14517
+ return [JSON_COMPAT_UINT8_ARRAY, base64EncodeUint8Array(input)];
14518
+ }
14519
+ if (isTypedArray(input)) {
14520
+ return input;
14521
+ }
14522
+ if (input instanceof Date || input instanceof RegExp || input instanceof Error) {
14523
+ return input;
14524
+ }
14525
+ if (input instanceof Set) {
14526
+ const encoded = [...input.values()].map(
14527
+ (v) => encodeJsonCompatValue(v)
14528
+ );
14529
+ return [JSON_COMPAT_SET, encoded];
14530
+ }
14531
+ if (input instanceof Map) {
14532
+ const encoded = /* @__PURE__ */ new Map();
14533
+ for (const [k, v] of input.entries()) {
14534
+ encoded.set(
14535
+ encodeJsonCompatValue(k),
14536
+ encodeJsonCompatValue(v)
14537
+ );
14470
14538
  }
14471
- if (byteCount === UINT_SAFE32_MAX_BYTE_COUNT && byte > 15) {
14472
- bc.offset -= byteCount - 1;
14473
- throw new BareError(bc.offset, TOO_LARGE_NUMBER);
14539
+ return encoded;
14540
+ }
14541
+ if (Array.isArray(input)) {
14542
+ const encoded = input.map(
14543
+ (value) => encodeJsonCompatValue(value)
14544
+ );
14545
+ if (encoded.length === 2 && typeof encoded[0] === "string" && encoded[0].startsWith("$")) {
14546
+ return [`$${encoded[0]}`, encoded[1]];
14474
14547
  }
14548
+ return encoded;
14475
14549
  }
14476
- return result;
14550
+ if (isPlainObject2(input)) {
14551
+ const encoded = {};
14552
+ for (const [key, value] of Object.entries(input)) {
14553
+ encoded[key] = encodeJsonCompatValue(value);
14554
+ }
14555
+ return encoded;
14556
+ }
14557
+ const typeName = typeof input === "object" && input !== null ? ((_a2 = input.constructor) == null ? void 0 : _a2.name) ?? typeof input : typeof input;
14558
+ throw new TypeError(`Value of type "${typeName}" is not CBOR serializable`);
14477
14559
  }
14478
- function writeUintSafe32(bc, x) {
14479
- if (DEV) {
14480
- assert2(isU32(x), TOO_LARGE_NUMBER);
14560
+ function reviveJsonCompatValue(input, options = {}) {
14561
+ if (typeof input === "bigint") {
14562
+ if (options.coerceSafeIntegerBigInts && input >= BigInt(Number.MIN_SAFE_INTEGER) && input <= BigInt(Number.MAX_SAFE_INTEGER)) {
14563
+ return Number(input);
14564
+ }
14565
+ return input;
14481
14566
  }
14482
- let zigZag = x >>> 0;
14483
- while (zigZag >= 128) {
14484
- writeU8(bc, 128 | zigZag & 127);
14485
- zigZag >>>= 7;
14567
+ if (input instanceof Map) {
14568
+ const revived = /* @__PURE__ */ new Map();
14569
+ for (const [k, v] of input.entries()) {
14570
+ revived.set(
14571
+ reviveJsonCompatValue(k, options),
14572
+ reviveJsonCompatValue(v, options)
14573
+ );
14574
+ }
14575
+ return revived;
14486
14576
  }
14487
- writeU8(bc, zigZag);
14488
- }
14489
- function readUintSafe(bc) {
14490
- let result = readU8(bc);
14491
- if (result >= 128) {
14492
- result &= 127;
14493
- let shiftMul = (
14494
- /* 2**7 */
14495
- 128
14496
- );
14497
- let byteCount = 1;
14498
- let byte;
14499
- do {
14500
- byte = readU8(bc);
14501
- result += (byte & 127) * shiftMul;
14502
- shiftMul *= /* 2**7 */
14503
- 128;
14504
- byteCount++;
14505
- } while (byte >= 128 && byteCount < INT_SAFE_MAX_BYTE_COUNT);
14506
- if (byte === 0) {
14507
- bc.offset -= byteCount - 1;
14508
- throw new BareError(bc.offset - byteCount + 1, NON_CANONICAL_REPRESENTATION);
14577
+ if (Array.isArray(input)) {
14578
+ if (input.length === 2 && typeof input[0] === "string" && input[0].startsWith("$")) {
14579
+ if (input[0] === JSON_COMPAT_BIGINT) {
14580
+ return BigInt(input[1]);
14581
+ }
14582
+ if (input[0] === JSON_COMPAT_ARRAY_BUFFER) {
14583
+ return base64DecodeToArrayBuffer(input[1]);
14584
+ }
14585
+ if (input[0] === JSON_COMPAT_UINT8_ARRAY) {
14586
+ return base64DecodeToUint8Array(input[1]);
14587
+ }
14588
+ if (input[0] === JSON_COMPAT_UNDEFINED) {
14589
+ return void 0;
14590
+ }
14591
+ if (input[0] === JSON_COMPAT_SET) {
14592
+ const items = input[1].map(
14593
+ (v) => reviveJsonCompatValue(v, options)
14594
+ );
14595
+ return new Set(items);
14596
+ }
14597
+ if (input[0].startsWith("$$")) {
14598
+ return [
14599
+ input[0].substring(1),
14600
+ reviveJsonCompatValue(input[1], options)
14601
+ ];
14602
+ }
14603
+ throw new Error(
14604
+ `Unknown JSON encoding type: ${input[0]}. This may indicate corrupted data or a version mismatch.`
14605
+ );
14509
14606
  }
14510
- if (byteCount === INT_SAFE_MAX_BYTE_COUNT && byte > 15) {
14511
- bc.offset -= byteCount - 1;
14512
- throw new BareError(bc.offset, TOO_LARGE_NUMBER);
14607
+ return input.map((value) => reviveJsonCompatValue(value, options));
14608
+ }
14609
+ if (isPlainObject2(input)) {
14610
+ const decoded = {};
14611
+ for (const [key, value] of Object.entries(input)) {
14612
+ decoded[key] = reviveJsonCompatValue(value, options);
14513
14613
  }
14614
+ return decoded;
14514
14615
  }
14515
- return result;
14516
- }
14517
-
14518
- // ../../../node_modules/.pnpm/@rivetkit+bare-ts@0.6.2/node_modules/@rivetkit/bare-ts/dist/codec/u8-array.js
14519
- function readU8Array(bc) {
14520
- return readU8FixedArray(bc, readUintSafe32(bc));
14521
- }
14522
- function writeU8Array(bc, x) {
14523
- writeUintSafe32(bc, x.length);
14524
- writeU8FixedArray(bc, x);
14525
- }
14526
- function readU8FixedArray(bc, len) {
14527
- return readUnsafeU8FixedArray(bc, len).slice();
14616
+ return input;
14528
14617
  }
14529
- function writeU8FixedArray(bc, x) {
14530
- const len = x.length;
14531
- if (len > 0) {
14532
- reserve(bc, len);
14533
- bc.bytes.set(x, bc.offset);
14534
- bc.offset += len;
14618
+ function base64DecodeToUint8Array(base643) {
14619
+ if (typeof Buffer !== "undefined") {
14620
+ return new Uint8Array(Buffer.from(base643, "base64"));
14535
14621
  }
14536
- }
14537
- function readUnsafeU8FixedArray(bc, len) {
14538
- if (DEV) {
14539
- assert2(isU32(len));
14622
+ const binary = atob(base643);
14623
+ const bytes = new Uint8Array(binary.length);
14624
+ for (let i = 0; i < binary.length; i++) {
14625
+ bytes[i] = binary.charCodeAt(i);
14540
14626
  }
14541
- check2(bc, len);
14542
- const offset = bc.offset;
14543
- bc.offset += len;
14544
- return bc.bytes.subarray(offset, offset + len);
14627
+ return bytes;
14545
14628
  }
14546
-
14547
- // ../../../node_modules/.pnpm/@rivetkit+bare-ts@0.6.2/node_modules/@rivetkit/bare-ts/dist/codec/data.js
14548
- function readData(bc) {
14549
- return readU8Array(bc).buffer;
14629
+ function base64DecodeToArrayBuffer(base643) {
14630
+ return base64DecodeToUint8Array(base643).buffer;
14550
14631
  }
14551
- function writeData(bc, x) {
14552
- writeU8Array(bc, new Uint8Array(x));
14632
+ function jsonStringifyCompat(input, space) {
14633
+ return JSON.stringify(
14634
+ input,
14635
+ (_key, value) => {
14636
+ if (typeof value === "bigint") {
14637
+ return [JSON_COMPAT_BIGINT, value.toString()];
14638
+ }
14639
+ if (value instanceof ArrayBuffer) {
14640
+ return [
14641
+ JSON_COMPAT_ARRAY_BUFFER,
14642
+ base64EncodeArrayBuffer(value)
14643
+ ];
14644
+ }
14645
+ if (value instanceof Uint8Array) {
14646
+ return [JSON_COMPAT_UINT8_ARRAY, base64EncodeUint8Array(value)];
14647
+ }
14648
+ if (Array.isArray(value) && value.length === 2 && typeof value[0] === "string" && value[0].startsWith("$")) {
14649
+ return [`$${value[0]}`, value[1]];
14650
+ }
14651
+ return value;
14652
+ },
14653
+ space
14654
+ );
14553
14655
  }
14554
-
14555
- // ../../../node_modules/.pnpm/@rivetkit+bare-ts@0.6.2/node_modules/@rivetkit/bare-ts/dist/codec/string.js
14556
- function readString(bc) {
14557
- return readFixedString(bc, readUintSafe32(bc));
14656
+ function jsonParseCompat(input) {
14657
+ return reviveJsonCompatValue(JSON.parse(input));
14558
14658
  }
14559
- function writeString(bc, x) {
14560
- if (x.length < TEXT_ENCODER_THRESHOLD) {
14561
- const byteLen = utf8ByteLength(x);
14562
- writeUintSafe32(bc, byteLen);
14563
- reserve(bc, byteLen);
14564
- writeUtf8Js(bc, x);
14565
- } else {
14566
- const strBytes = UTF8_ENCODER.encode(x);
14567
- writeUintSafe32(bc, strBytes.length);
14568
- writeU8FixedArray(bc, strBytes);
14659
+ var VERSION = package_default.version;
14660
+ var _userAgent;
14661
+ function httpUserAgent() {
14662
+ if (_userAgent !== void 0) {
14663
+ return _userAgent;
14569
14664
  }
14665
+ let userAgent = `RivetKit/${VERSION}`;
14666
+ const navigatorObj = typeof navigator !== "undefined" ? navigator : void 0;
14667
+ if (navigatorObj == null ? void 0 : navigatorObj.userAgent) userAgent += ` ${navigatorObj.userAgent}`;
14668
+ _userAgent = userAgent;
14669
+ return userAgent;
14570
14670
  }
14571
- function readFixedString(bc, byteLen) {
14572
- if (DEV) {
14573
- assert2(isU32(byteLen));
14574
- }
14575
- if (byteLen < TEXT_DECODER_THRESHOLD) {
14576
- return readUtf8Js(bc, byteLen);
14577
- }
14578
- try {
14579
- return UTF8_DECODER.decode(readUnsafeU8FixedArray(bc, byteLen));
14580
- } catch (_cause) {
14581
- throw new BareError(bc.offset, INVALID_UTF8_STRING);
14671
+ function getEnvUniversal(key) {
14672
+ if (typeof Deno !== "undefined") {
14673
+ return Deno.env.get(key);
14674
+ } else if (typeof process !== "undefined") {
14675
+ return process.env[key];
14582
14676
  }
14583
14677
  }
14584
- function readUtf8Js(bc, byteLen) {
14585
- check2(bc, byteLen);
14586
- let result = "";
14587
- const bytes = bc.bytes;
14588
- let offset = bc.offset;
14589
- const upperOffset = offset + byteLen;
14590
- while (offset < upperOffset) {
14591
- let codePoint = bytes[offset++];
14592
- if (codePoint > 127) {
14593
- let malformed = true;
14594
- const byte1 = codePoint;
14595
- if (offset < upperOffset && codePoint < 224) {
14596
- const byte2 = bytes[offset++];
14597
- codePoint = (byte1 & 31) << 6 | byte2 & 63;
14598
- malformed = codePoint >> 7 === 0 || // non-canonical char
14599
- byte1 >> 5 !== 6 || // invalid tag
14600
- byte2 >> 6 !== 2;
14601
- } else if (offset + 1 < upperOffset && codePoint < 240) {
14602
- const byte2 = bytes[offset++];
14603
- const byte3 = bytes[offset++];
14604
- codePoint = (byte1 & 15) << 12 | (byte2 & 63) << 6 | byte3 & 63;
14605
- malformed = codePoint >> 11 === 0 || // non-canonical char or missing data
14606
- codePoint >> 11 === 27 || // surrogate char (0xD800 <= codePoint <= 0xDFFF)
14607
- byte1 >> 4 !== 14 || // invalid tag
14608
- byte2 >> 6 !== 2 || // invalid tag
14609
- byte3 >> 6 !== 2;
14610
- } else if (offset + 2 < upperOffset) {
14611
- const byte2 = bytes[offset++];
14612
- const byte3 = bytes[offset++];
14613
- const byte4 = bytes[offset++];
14614
- codePoint = (byte1 & 7) << 18 | (byte2 & 63) << 12 | (byte3 & 63) << 6 | byte4 & 63;
14615
- malformed = codePoint >> 16 === 0 || // non-canonical char or missing data
14616
- codePoint > 1114111 || // too large code point
14617
- byte1 >> 3 !== 30 || // invalid tag
14618
- byte2 >> 6 !== 2 || // invalid tag
14619
- byte3 >> 6 !== 2 || // invalid tag
14620
- byte4 >> 6 !== 2;
14621
- }
14622
- if (malformed) {
14623
- throw new BareError(bc.offset, INVALID_UTF8_STRING);
14624
- }
14625
- }
14626
- result += String.fromCodePoint(codePoint);
14678
+ function toUint8Array(data) {
14679
+ if (data instanceof Uint8Array) {
14680
+ return data;
14681
+ } else if (data instanceof ArrayBuffer) {
14682
+ return new Uint8Array(data);
14683
+ } else if (ArrayBuffer.isView(data)) {
14684
+ return new Uint8Array(
14685
+ data.buffer.slice(
14686
+ data.byteOffset,
14687
+ data.byteOffset + data.byteLength
14688
+ )
14689
+ );
14690
+ } else {
14691
+ throw new TypeError("Input must be ArrayBuffer or ArrayBufferView");
14627
14692
  }
14628
- bc.offset = offset;
14629
- return result;
14630
14693
  }
14631
- function writeUtf8Js(bc, s) {
14632
- const bytes = bc.bytes;
14633
- let offset = bc.offset;
14634
- let i = 0;
14635
- while (i < s.length) {
14636
- const codePoint = s.codePointAt(i++);
14637
- if (codePoint < 128) {
14638
- bytes[offset++] = codePoint;
14639
- } else {
14640
- if (codePoint < 2048) {
14641
- bytes[offset++] = 192 | codePoint >> 6;
14642
- } else {
14643
- if (codePoint < 65536) {
14644
- bytes[offset++] = 224 | codePoint >> 12;
14645
- } else {
14646
- bytes[offset++] = 240 | codePoint >> 18;
14647
- bytes[offset++] = 128 | codePoint >> 12 & 63;
14648
- i++;
14649
- }
14650
- bytes[offset++] = 128 | codePoint >> 6 & 63;
14651
- }
14652
- bytes[offset++] = 128 | codePoint & 63;
14653
- }
14654
- }
14655
- bc.offset = offset;
14694
+ function promiseWithResolvers(onReject) {
14695
+ let resolve;
14696
+ let reject;
14697
+ const promise2 = new Promise((res, rej) => {
14698
+ resolve = res;
14699
+ reject = rej;
14700
+ });
14701
+ promise2.catch(onReject);
14702
+ return { promise: promise2, resolve, reject };
14656
14703
  }
14657
- function utf8ByteLength(s) {
14658
- let result = s.length;
14659
- for (let i = 0; i < s.length; i++) {
14660
- const codePoint = s.codePointAt(i);
14661
- if (codePoint > 127) {
14662
- result++;
14663
- if (codePoint > 2047) {
14664
- result++;
14665
- if (codePoint > 65535) {
14666
- i++;
14667
- }
14704
+ function bufferToArrayBuffer(buf) {
14705
+ return buf.buffer.slice(
14706
+ buf.byteOffset,
14707
+ buf.byteOffset + buf.byteLength
14708
+ );
14709
+ }
14710
+ function combineUrlPath(endpoint, path2, queryParams) {
14711
+ const baseUrl = new URL(endpoint);
14712
+ const pathParts = path2.split("?");
14713
+ const pathOnly = pathParts[0];
14714
+ const existingQuery = pathParts[1] || "";
14715
+ const basePath = baseUrl.pathname.replace(/\/$/, "");
14716
+ const cleanPath = pathOnly.startsWith("/") ? pathOnly : `/${pathOnly}`;
14717
+ const fullPath = (basePath + cleanPath).replace(/\/\//g, "/");
14718
+ const queryParts = [];
14719
+ if (existingQuery) {
14720
+ queryParts.push(existingQuery);
14721
+ }
14722
+ if (queryParams) {
14723
+ for (const [key, value] of Object.entries(queryParams)) {
14724
+ if (value !== void 0) {
14725
+ queryParts.push(
14726
+ `${encodeURIComponent(key)}=${encodeURIComponent(value)}`
14727
+ );
14668
14728
  }
14669
14729
  }
14670
14730
  }
14671
- return result;
14731
+ const fullQuery = queryParts.length > 0 ? `?${queryParts.join("&")}` : "";
14732
+ return `${baseUrl.protocol}//${baseUrl.host}${fullPath}${fullQuery}`;
14672
14733
  }
14673
- var UTF8_DECODER = /* @__PURE__ */ new TextDecoder("utf-8", { fatal: true });
14674
- var UTF8_ENCODER = /* @__PURE__ */ new TextEncoder();
14675
14734
 
14676
- // ../../../node_modules/.pnpm/@rivetkit+bare-ts@0.6.2/node_modules/@rivetkit/bare-ts/dist/core/config.js
14677
- function Config({ initialBufferLength = 1024, maxBufferLength = 1024 * 1024 * 32 }) {
14678
- if (DEV) {
14679
- assert2(isU32(initialBufferLength), TOO_LARGE_NUMBER);
14680
- assert2(isU32(maxBufferLength), TOO_LARGE_NUMBER);
14681
- assert2(initialBufferLength <= maxBufferLength, "initialBufferLength must be lower than or equal to maxBufferLength");
14735
+ // ../../../node_modules/.pnpm/@rivetkit+bare-ts@0.6.2/node_modules/@rivetkit/bare-ts/imports/dev.node.js
14736
+ var DEV = process.env.NODE_ENV === "development";
14737
+
14738
+ // ../../../node_modules/.pnpm/@rivetkit+bare-ts@0.6.2/node_modules/@rivetkit/bare-ts/dist/util/assert.js
14739
+ var V8Error = Error;
14740
+ function assert2(test, message = "") {
14741
+ if (!test) {
14742
+ const e = new AssertionError(message);
14743
+ V8Error.captureStackTrace?.(e, assert2);
14744
+ throw e;
14682
14745
  }
14683
- return {
14684
- initialBufferLength,
14685
- maxBufferLength
14686
- };
14687
14746
  }
14747
+ var AssertionError = class extends Error {
14748
+ constructor() {
14749
+ super(...arguments);
14750
+ this.name = "AssertionError";
14751
+ }
14752
+ };
14688
14753
 
14689
- // ../rivetkit/dist/tsup/chunk-4SNS3PYZ.js
14690
- var config2 = /* @__PURE__ */ Config({});
14691
- function readWorkflowCbor(bc) {
14692
- return readData(bc);
14754
+ // ../../../node_modules/.pnpm/@rivetkit+bare-ts@0.6.2/node_modules/@rivetkit/bare-ts/dist/util/validator.js
14755
+ function isU8(val) {
14756
+ return val === (val & 255);
14693
14757
  }
14694
- function readWorkflowNameIndex(bc) {
14695
- return readU32(bc);
14758
+ function isU32(val) {
14759
+ return val === val >>> 0;
14696
14760
  }
14697
- function readWorkflowLoopIterationMarker(bc) {
14698
- return {
14699
- loop: readWorkflowNameIndex(bc),
14700
- iteration: readU32(bc)
14701
- };
14761
+ function isU64(val) {
14762
+ return val === BigInt.asUintN(64, val);
14702
14763
  }
14703
- function readWorkflowPathSegment(bc) {
14704
- const offset = bc.offset;
14705
- const tag = readU8(bc);
14706
- switch (tag) {
14707
- case 0:
14708
- return { tag: "WorkflowNameIndex", val: readWorkflowNameIndex(bc) };
14709
- case 1:
14710
- return {
14711
- tag: "WorkflowLoopIterationMarker",
14712
- val: readWorkflowLoopIterationMarker(bc)
14713
- };
14714
- default: {
14715
- bc.offset = offset;
14716
- throw new BareError(offset, "invalid tag");
14764
+
14765
+ // ../../../node_modules/.pnpm/@rivetkit+bare-ts@0.6.2/node_modules/@rivetkit/bare-ts/dist/util/constants.js
14766
+ var TEXT_DECODER_THRESHOLD = 256;
14767
+ var TEXT_ENCODER_THRESHOLD = 256;
14768
+ var INT_SAFE_MAX_BYTE_COUNT = 8;
14769
+ var UINT_MAX_BYTE_COUNT = 10;
14770
+ var UINT_SAFE32_MAX_BYTE_COUNT = 5;
14771
+ var INVALID_UTF8_STRING = "invalid UTF-8 string";
14772
+ var NON_CANONICAL_REPRESENTATION = "must be canonical";
14773
+ var TOO_LARGE_BUFFER = "too large buffer";
14774
+ var TOO_LARGE_NUMBER = "too large number";
14775
+
14776
+ // ../../../node_modules/.pnpm/@rivetkit+bare-ts@0.6.2/node_modules/@rivetkit/bare-ts/dist/core/bare-error.js
14777
+ var BareError = class extends Error {
14778
+ constructor(offset, issue2, opts) {
14779
+ super(`(byte:${offset}) ${issue2}`);
14780
+ this.name = "BareError";
14781
+ this.issue = issue2;
14782
+ this.offset = offset;
14783
+ this.cause = opts?.cause;
14784
+ }
14785
+ };
14786
+
14787
+ // ../../../node_modules/.pnpm/@rivetkit+bare-ts@0.6.2/node_modules/@rivetkit/bare-ts/dist/core/byte-cursor.js
14788
+ var ByteCursor = class {
14789
+ /**
14790
+ * @throws {BareError} Buffer exceeds `config.maxBufferLength`
14791
+ */
14792
+ constructor(bytes, config3) {
14793
+ this.offset = 0;
14794
+ if (bytes.length > config3.maxBufferLength) {
14795
+ throw new BareError(0, TOO_LARGE_BUFFER);
14717
14796
  }
14797
+ this.bytes = bytes;
14798
+ this.config = config3;
14799
+ this.view = new DataView(bytes.buffer, bytes.byteOffset, bytes.length);
14718
14800
  }
14719
- }
14720
- function readWorkflowLocation(bc) {
14721
- const len = readUintSafe(bc);
14722
- if (len === 0) {
14723
- return [];
14801
+ };
14802
+ function check2(bc, min) {
14803
+ if (DEV) {
14804
+ assert2(isU32(min));
14724
14805
  }
14725
- const result = [readWorkflowPathSegment(bc)];
14726
- for (let i = 1; i < len; i++) {
14727
- result[i] = readWorkflowPathSegment(bc);
14806
+ if (bc.offset + min > bc.bytes.length) {
14807
+ throw new BareError(bc.offset, "missing bytes");
14728
14808
  }
14729
- return result;
14730
14809
  }
14731
- function readWorkflowEntryStatus(bc) {
14732
- const offset = bc.offset;
14733
- const tag = readU8(bc);
14734
- switch (tag) {
14735
- case 0:
14736
- return "PENDING";
14737
- case 1:
14738
- return "RUNNING";
14739
- case 2:
14740
- return "COMPLETED";
14741
- case 3:
14742
- return "FAILED";
14743
- case 4:
14744
- return "EXHAUSTED";
14745
- default: {
14746
- bc.offset = offset;
14747
- throw new BareError(offset, "invalid tag");
14748
- }
14810
+ function reserve(bc, min) {
14811
+ if (DEV) {
14812
+ assert2(isU32(min));
14749
14813
  }
14750
- }
14751
- function readWorkflowSleepState(bc) {
14752
- const offset = bc.offset;
14753
- const tag = readU8(bc);
14754
- switch (tag) {
14755
- case 0:
14756
- return "PENDING";
14757
- case 1:
14758
- return "COMPLETED";
14759
- case 2:
14760
- return "INTERRUPTED";
14761
- default: {
14762
- bc.offset = offset;
14763
- throw new BareError(offset, "invalid tag");
14764
- }
14814
+ const minLen = bc.offset + min | 0;
14815
+ if (minLen > bc.bytes.length) {
14816
+ grow(bc, minLen);
14765
14817
  }
14766
14818
  }
14767
- function readWorkflowBranchStatusType(bc) {
14768
- const offset = bc.offset;
14769
- const tag = readU8(bc);
14770
- switch (tag) {
14771
- case 0:
14772
- return "PENDING";
14773
- case 1:
14774
- return "RUNNING";
14775
- case 2:
14776
- return "COMPLETED";
14777
- case 3:
14778
- return "FAILED";
14779
- case 4:
14780
- return "CANCELLED";
14781
- default: {
14782
- bc.offset = offset;
14783
- throw new BareError(offset, "invalid tag");
14819
+ function grow(bc, minLen) {
14820
+ if (minLen > bc.config.maxBufferLength) {
14821
+ throw new BareError(0, TOO_LARGE_BUFFER);
14822
+ }
14823
+ const buffer = bc.bytes.buffer;
14824
+ let newBytes;
14825
+ if (isEs2024ArrayBufferLike(buffer) && // Make sure that the view covers the end of the buffer.
14826
+ // If it is not the case, this indicates that the user don't want
14827
+ // to override the trailing bytes.
14828
+ bc.bytes.byteOffset + bc.bytes.byteLength === buffer.byteLength && bc.bytes.byteLength + minLen <= buffer.maxByteLength) {
14829
+ const newLen = Math.min(minLen << 1, bc.config.maxBufferLength, buffer.maxByteLength);
14830
+ if (buffer instanceof ArrayBuffer) {
14831
+ buffer.resize(newLen);
14832
+ } else {
14833
+ buffer.grow(newLen);
14784
14834
  }
14835
+ newBytes = new Uint8Array(buffer, bc.bytes.byteOffset, newLen);
14836
+ } else {
14837
+ const newLen = Math.min(minLen << 1, bc.config.maxBufferLength);
14838
+ newBytes = new Uint8Array(newLen);
14839
+ newBytes.set(bc.bytes);
14785
14840
  }
14841
+ bc.bytes = newBytes;
14842
+ bc.view = new DataView(newBytes.buffer);
14786
14843
  }
14787
- function read0(bc) {
14788
- return readBool(bc) ? readWorkflowCbor(bc) : null;
14844
+ function isEs2024ArrayBufferLike(buffer) {
14845
+ return "maxByteLength" in buffer;
14789
14846
  }
14790
- function read1(bc) {
14791
- return readBool(bc) ? readString(bc) : null;
14847
+
14848
+ // ../../../node_modules/.pnpm/@rivetkit+bare-ts@0.6.2/node_modules/@rivetkit/bare-ts/dist/codec/fixed-primitive.js
14849
+ function readBool(bc) {
14850
+ const val = readU8(bc);
14851
+ if (val > 1) {
14852
+ bc.offset--;
14853
+ throw new BareError(bc.offset, "a bool must be equal to 0 or 1");
14854
+ }
14855
+ return val > 0;
14792
14856
  }
14793
- function readWorkflowStepEntry(bc) {
14794
- return {
14795
- output: read0(bc),
14796
- error: read1(bc)
14797
- };
14857
+ function writeBool(bc, x) {
14858
+ writeU8(bc, x ? 1 : 0);
14798
14859
  }
14799
- function readWorkflowLoopEntry(bc) {
14800
- return {
14801
- state: readWorkflowCbor(bc),
14802
- iteration: readU32(bc),
14803
- output: read0(bc)
14804
- };
14860
+ function readU8(bc) {
14861
+ check2(bc, 1);
14862
+ return bc.bytes[bc.offset++];
14805
14863
  }
14806
- function readWorkflowSleepEntry(bc) {
14807
- return {
14808
- deadline: readU64(bc),
14809
- state: readWorkflowSleepState(bc)
14810
- };
14864
+ function writeU8(bc, x) {
14865
+ if (DEV) {
14866
+ assert2(isU8(x), TOO_LARGE_NUMBER);
14867
+ }
14868
+ reserve(bc, 1);
14869
+ bc.bytes[bc.offset++] = x;
14811
14870
  }
14812
- function readWorkflowMessageEntry(bc) {
14813
- return {
14814
- name: readString(bc),
14815
- messageData: readWorkflowCbor(bc)
14816
- };
14871
+ function readU32(bc) {
14872
+ check2(bc, 4);
14873
+ const result = bc.view.getUint32(bc.offset, true);
14874
+ bc.offset += 4;
14875
+ return result;
14817
14876
  }
14818
- function readWorkflowRollbackCheckpointEntry(bc) {
14819
- return {
14820
- name: readString(bc)
14821
- };
14877
+ function readU64(bc) {
14878
+ check2(bc, 8);
14879
+ const result = bc.view.getBigUint64(bc.offset, true);
14880
+ bc.offset += 8;
14881
+ return result;
14822
14882
  }
14823
- function readWorkflowBranchStatus(bc) {
14824
- return {
14825
- status: readWorkflowBranchStatusType(bc),
14826
- output: read0(bc),
14827
- error: read1(bc)
14828
- };
14883
+ function writeU64(bc, x) {
14884
+ if (DEV) {
14885
+ assert2(isU64(x), TOO_LARGE_NUMBER);
14886
+ }
14887
+ reserve(bc, 8);
14888
+ bc.view.setBigUint64(bc.offset, x, true);
14889
+ bc.offset += 8;
14829
14890
  }
14830
- function read2(bc) {
14831
- const len = readUintSafe(bc);
14832
- const result = /* @__PURE__ */ new Map();
14833
- for (let i = 0; i < len; i++) {
14834
- const offset = bc.offset;
14835
- const key = readString(bc);
14836
- if (result.has(key)) {
14837
- bc.offset = offset;
14838
- throw new BareError(offset, "duplicated key");
14891
+
14892
+ // ../../../node_modules/.pnpm/@rivetkit+bare-ts@0.6.2/node_modules/@rivetkit/bare-ts/dist/codec/uint.js
14893
+ function readUint(bc) {
14894
+ let low = readU8(bc);
14895
+ if (low >= 128) {
14896
+ low &= 127;
14897
+ let shiftMul = 128;
14898
+ let byteCount = 1;
14899
+ let byte;
14900
+ do {
14901
+ byte = readU8(bc);
14902
+ low += (byte & 127) * shiftMul;
14903
+ shiftMul *= /* 2**7 */
14904
+ 128;
14905
+ byteCount++;
14906
+ } while (byte >= 128 && byteCount < 7);
14907
+ let height = 0;
14908
+ shiftMul = 1;
14909
+ while (byte >= 128 && byteCount < UINT_MAX_BYTE_COUNT) {
14910
+ byte = readU8(bc);
14911
+ height += (byte & 127) * shiftMul;
14912
+ shiftMul *= /* 2**7 */
14913
+ 128;
14914
+ byteCount++;
14839
14915
  }
14840
- result.set(key, readWorkflowBranchStatus(bc));
14916
+ if (byte === 0 || byteCount === UINT_MAX_BYTE_COUNT && byte > 1) {
14917
+ bc.offset -= byteCount;
14918
+ throw new BareError(bc.offset, NON_CANONICAL_REPRESENTATION);
14919
+ }
14920
+ return BigInt(low) + (BigInt(height) << BigInt(7 * 7));
14841
14921
  }
14842
- return result;
14922
+ return BigInt(low);
14843
14923
  }
14844
- function readWorkflowJoinEntry(bc) {
14845
- return {
14846
- branches: read2(bc)
14847
- };
14924
+ function writeUint(bc, x) {
14925
+ const truncated = BigInt.asUintN(64, x);
14926
+ if (DEV) {
14927
+ assert2(truncated === x, TOO_LARGE_NUMBER);
14928
+ }
14929
+ writeUintTruncated(bc, truncated);
14848
14930
  }
14849
- function readWorkflowRaceEntry(bc) {
14850
- return {
14851
- winner: read1(bc),
14852
- branches: read2(bc)
14853
- };
14931
+ function writeUintTruncated(bc, x) {
14932
+ let tmp = Number(BigInt.asUintN(7 * 7, x));
14933
+ let rest = Number(x >> BigInt(7 * 7));
14934
+ let byteCount = 0;
14935
+ while (tmp >= 128 || rest > 0) {
14936
+ writeU8(bc, 128 | tmp & 127);
14937
+ tmp = Math.floor(tmp / /* 2**7 */
14938
+ 128);
14939
+ byteCount++;
14940
+ if (byteCount === 7) {
14941
+ tmp = rest;
14942
+ rest = 0;
14943
+ }
14944
+ }
14945
+ writeU8(bc, tmp);
14854
14946
  }
14855
- function readWorkflowRemovedEntry(bc) {
14856
- return {
14857
- originalType: readString(bc),
14858
- originalName: read1(bc)
14859
- };
14947
+ function readUintSafe32(bc) {
14948
+ let result = readU8(bc);
14949
+ if (result >= 128) {
14950
+ result &= 127;
14951
+ let shift = 7;
14952
+ let byteCount = 1;
14953
+ let byte;
14954
+ do {
14955
+ byte = readU8(bc);
14956
+ result += (byte & 127) << shift >>> 0;
14957
+ shift += 7;
14958
+ byteCount++;
14959
+ } while (byte >= 128 && byteCount < UINT_SAFE32_MAX_BYTE_COUNT);
14960
+ if (byte === 0) {
14961
+ bc.offset -= byteCount - 1;
14962
+ throw new BareError(bc.offset - byteCount + 1, NON_CANONICAL_REPRESENTATION);
14963
+ }
14964
+ if (byteCount === UINT_SAFE32_MAX_BYTE_COUNT && byte > 15) {
14965
+ bc.offset -= byteCount - 1;
14966
+ throw new BareError(bc.offset, TOO_LARGE_NUMBER);
14967
+ }
14968
+ }
14969
+ return result;
14860
14970
  }
14861
- function readWorkflowVersionCheckEntry(bc) {
14862
- return {
14863
- resolved: readU32(bc),
14864
- latest: readU32(bc)
14865
- };
14971
+ function writeUintSafe32(bc, x) {
14972
+ if (DEV) {
14973
+ assert2(isU32(x), TOO_LARGE_NUMBER);
14974
+ }
14975
+ let zigZag = x >>> 0;
14976
+ while (zigZag >= 128) {
14977
+ writeU8(bc, 128 | zigZag & 127);
14978
+ zigZag >>>= 7;
14979
+ }
14980
+ writeU8(bc, zigZag);
14866
14981
  }
14867
- function readWorkflowEntryKind(bc) {
14868
- const offset = bc.offset;
14869
- const tag = readU8(bc);
14870
- switch (tag) {
14871
- case 0:
14872
- return { tag: "WorkflowStepEntry", val: readWorkflowStepEntry(bc) };
14873
- case 1:
14874
- return { tag: "WorkflowLoopEntry", val: readWorkflowLoopEntry(bc) };
14875
- case 2:
14876
- return {
14877
- tag: "WorkflowSleepEntry",
14878
- val: readWorkflowSleepEntry(bc)
14879
- };
14880
- case 3:
14881
- return {
14882
- tag: "WorkflowMessageEntry",
14883
- val: readWorkflowMessageEntry(bc)
14884
- };
14885
- case 4:
14886
- return {
14887
- tag: "WorkflowRollbackCheckpointEntry",
14888
- val: readWorkflowRollbackCheckpointEntry(bc)
14889
- };
14890
- case 5:
14891
- return { tag: "WorkflowJoinEntry", val: readWorkflowJoinEntry(bc) };
14892
- case 6:
14893
- return { tag: "WorkflowRaceEntry", val: readWorkflowRaceEntry(bc) };
14894
- case 7:
14895
- return {
14896
- tag: "WorkflowRemovedEntry",
14897
- val: readWorkflowRemovedEntry(bc)
14898
- };
14899
- case 8:
14900
- return {
14901
- tag: "WorkflowVersionCheckEntry",
14902
- val: readWorkflowVersionCheckEntry(bc)
14903
- };
14904
- default: {
14905
- bc.offset = offset;
14906
- throw new BareError(offset, "invalid tag");
14982
+ function readUintSafe(bc) {
14983
+ let result = readU8(bc);
14984
+ if (result >= 128) {
14985
+ result &= 127;
14986
+ let shiftMul = (
14987
+ /* 2**7 */
14988
+ 128
14989
+ );
14990
+ let byteCount = 1;
14991
+ let byte;
14992
+ do {
14993
+ byte = readU8(bc);
14994
+ result += (byte & 127) * shiftMul;
14995
+ shiftMul *= /* 2**7 */
14996
+ 128;
14997
+ byteCount++;
14998
+ } while (byte >= 128 && byteCount < INT_SAFE_MAX_BYTE_COUNT);
14999
+ if (byte === 0) {
15000
+ bc.offset -= byteCount - 1;
15001
+ throw new BareError(bc.offset - byteCount + 1, NON_CANONICAL_REPRESENTATION);
15002
+ }
15003
+ if (byteCount === INT_SAFE_MAX_BYTE_COUNT && byte > 15) {
15004
+ bc.offset -= byteCount - 1;
15005
+ throw new BareError(bc.offset, TOO_LARGE_NUMBER);
14907
15006
  }
14908
15007
  }
15008
+ return result;
14909
15009
  }
14910
- function readWorkflowEntry(bc) {
14911
- return {
14912
- id: readString(bc),
14913
- location: readWorkflowLocation(bc),
14914
- kind: readWorkflowEntryKind(bc)
14915
- };
15010
+
15011
+ // ../../../node_modules/.pnpm/@rivetkit+bare-ts@0.6.2/node_modules/@rivetkit/bare-ts/dist/codec/u8-array.js
15012
+ function readU8Array(bc) {
15013
+ return readU8FixedArray(bc, readUintSafe32(bc));
14916
15014
  }
14917
- function read3(bc) {
14918
- return readBool(bc) ? readU64(bc) : null;
15015
+ function writeU8Array(bc, x) {
15016
+ writeUintSafe32(bc, x.length);
15017
+ writeU8FixedArray(bc, x);
14919
15018
  }
14920
- function readWorkflowEntryMetadata(bc) {
14921
- return {
14922
- status: readWorkflowEntryStatus(bc),
14923
- error: read1(bc),
14924
- attempts: readU32(bc),
14925
- lastAttemptAt: readU64(bc),
14926
- createdAt: readU64(bc),
14927
- completedAt: read3(bc),
14928
- rollbackCompletedAt: read3(bc),
14929
- rollbackError: read1(bc)
14930
- };
15019
+ function readU8FixedArray(bc, len) {
15020
+ return readUnsafeU8FixedArray(bc, len).slice();
14931
15021
  }
14932
- function read4(bc) {
14933
- const len = readUintSafe(bc);
14934
- if (len === 0) {
14935
- return [];
15022
+ function writeU8FixedArray(bc, x) {
15023
+ const len = x.length;
15024
+ if (len > 0) {
15025
+ reserve(bc, len);
15026
+ bc.bytes.set(x, bc.offset);
15027
+ bc.offset += len;
14936
15028
  }
14937
- const result = [readString(bc)];
14938
- for (let i = 1; i < len; i++) {
14939
- result[i] = readString(bc);
15029
+ }
15030
+ function readUnsafeU8FixedArray(bc, len) {
15031
+ if (DEV) {
15032
+ assert2(isU32(len));
14940
15033
  }
14941
- return result;
15034
+ check2(bc, len);
15035
+ const offset = bc.offset;
15036
+ bc.offset += len;
15037
+ return bc.bytes.subarray(offset, offset + len);
14942
15038
  }
14943
- function read5(bc) {
14944
- const len = readUintSafe(bc);
14945
- if (len === 0) {
14946
- return [];
15039
+
15040
+ // ../../../node_modules/.pnpm/@rivetkit+bare-ts@0.6.2/node_modules/@rivetkit/bare-ts/dist/codec/data.js
15041
+ function readData(bc) {
15042
+ return readU8Array(bc).buffer;
15043
+ }
15044
+ function writeData(bc, x) {
15045
+ writeU8Array(bc, new Uint8Array(x));
15046
+ }
15047
+
15048
+ // ../../../node_modules/.pnpm/@rivetkit+bare-ts@0.6.2/node_modules/@rivetkit/bare-ts/dist/codec/string.js
15049
+ function readString(bc) {
15050
+ return readFixedString(bc, readUintSafe32(bc));
15051
+ }
15052
+ function writeString(bc, x) {
15053
+ if (x.length < TEXT_ENCODER_THRESHOLD) {
15054
+ const byteLen = utf8ByteLength(x);
15055
+ writeUintSafe32(bc, byteLen);
15056
+ reserve(bc, byteLen);
15057
+ writeUtf8Js(bc, x);
15058
+ } else {
15059
+ const strBytes = UTF8_ENCODER.encode(x);
15060
+ writeUintSafe32(bc, strBytes.length);
15061
+ writeU8FixedArray(bc, strBytes);
14947
15062
  }
14948
- const result = [readWorkflowEntry(bc)];
14949
- for (let i = 1; i < len; i++) {
14950
- result[i] = readWorkflowEntry(bc);
15063
+ }
15064
+ function readFixedString(bc, byteLen) {
15065
+ if (DEV) {
15066
+ assert2(isU32(byteLen));
15067
+ }
15068
+ if (byteLen < TEXT_DECODER_THRESHOLD) {
15069
+ return readUtf8Js(bc, byteLen);
15070
+ }
15071
+ try {
15072
+ return UTF8_DECODER.decode(readUnsafeU8FixedArray(bc, byteLen));
15073
+ } catch (_cause) {
15074
+ throw new BareError(bc.offset, INVALID_UTF8_STRING);
14951
15075
  }
14952
- return result;
14953
15076
  }
14954
- function read6(bc) {
14955
- const len = readUintSafe(bc);
14956
- const result = /* @__PURE__ */ new Map();
14957
- for (let i = 0; i < len; i++) {
14958
- const offset = bc.offset;
14959
- const key = readString(bc);
14960
- if (result.has(key)) {
14961
- bc.offset = offset;
14962
- throw new BareError(offset, "duplicated key");
15077
+ function readUtf8Js(bc, byteLen) {
15078
+ check2(bc, byteLen);
15079
+ let result = "";
15080
+ const bytes = bc.bytes;
15081
+ let offset = bc.offset;
15082
+ const upperOffset = offset + byteLen;
15083
+ while (offset < upperOffset) {
15084
+ let codePoint = bytes[offset++];
15085
+ if (codePoint > 127) {
15086
+ let malformed = true;
15087
+ const byte1 = codePoint;
15088
+ if (offset < upperOffset && codePoint < 224) {
15089
+ const byte2 = bytes[offset++];
15090
+ codePoint = (byte1 & 31) << 6 | byte2 & 63;
15091
+ malformed = codePoint >> 7 === 0 || // non-canonical char
15092
+ byte1 >> 5 !== 6 || // invalid tag
15093
+ byte2 >> 6 !== 2;
15094
+ } else if (offset + 1 < upperOffset && codePoint < 240) {
15095
+ const byte2 = bytes[offset++];
15096
+ const byte3 = bytes[offset++];
15097
+ codePoint = (byte1 & 15) << 12 | (byte2 & 63) << 6 | byte3 & 63;
15098
+ malformed = codePoint >> 11 === 0 || // non-canonical char or missing data
15099
+ codePoint >> 11 === 27 || // surrogate char (0xD800 <= codePoint <= 0xDFFF)
15100
+ byte1 >> 4 !== 14 || // invalid tag
15101
+ byte2 >> 6 !== 2 || // invalid tag
15102
+ byte3 >> 6 !== 2;
15103
+ } else if (offset + 2 < upperOffset) {
15104
+ const byte2 = bytes[offset++];
15105
+ const byte3 = bytes[offset++];
15106
+ const byte4 = bytes[offset++];
15107
+ codePoint = (byte1 & 7) << 18 | (byte2 & 63) << 12 | (byte3 & 63) << 6 | byte4 & 63;
15108
+ malformed = codePoint >> 16 === 0 || // non-canonical char or missing data
15109
+ codePoint > 1114111 || // too large code point
15110
+ byte1 >> 3 !== 30 || // invalid tag
15111
+ byte2 >> 6 !== 2 || // invalid tag
15112
+ byte3 >> 6 !== 2 || // invalid tag
15113
+ byte4 >> 6 !== 2;
15114
+ }
15115
+ if (malformed) {
15116
+ throw new BareError(bc.offset, INVALID_UTF8_STRING);
15117
+ }
14963
15118
  }
14964
- result.set(key, readWorkflowEntryMetadata(bc));
15119
+ result += String.fromCodePoint(codePoint);
14965
15120
  }
15121
+ bc.offset = offset;
14966
15122
  return result;
14967
15123
  }
14968
- function readWorkflowHistory(bc) {
14969
- return {
14970
- nameRegistry: read4(bc),
14971
- entries: read5(bc),
14972
- entryMetadata: read6(bc)
14973
- };
15124
+ function writeUtf8Js(bc, s) {
15125
+ const bytes = bc.bytes;
15126
+ let offset = bc.offset;
15127
+ let i = 0;
15128
+ while (i < s.length) {
15129
+ const codePoint = s.codePointAt(i++);
15130
+ if (codePoint < 128) {
15131
+ bytes[offset++] = codePoint;
15132
+ } else {
15133
+ if (codePoint < 2048) {
15134
+ bytes[offset++] = 192 | codePoint >> 6;
15135
+ } else {
15136
+ if (codePoint < 65536) {
15137
+ bytes[offset++] = 224 | codePoint >> 12;
15138
+ } else {
15139
+ bytes[offset++] = 240 | codePoint >> 18;
15140
+ bytes[offset++] = 128 | codePoint >> 12 & 63;
15141
+ i++;
15142
+ }
15143
+ bytes[offset++] = 128 | codePoint >> 6 & 63;
15144
+ }
15145
+ bytes[offset++] = 128 | codePoint & 63;
15146
+ }
15147
+ }
15148
+ bc.offset = offset;
14974
15149
  }
14975
- function decodeWorkflowHistory(bytes) {
14976
- const bc = new ByteCursor(bytes, config2);
14977
- const result = readWorkflowHistory(bc);
14978
- if (bc.offset < bc.view.byteLength) {
14979
- throw new BareError(bc.offset, "remaining bytes");
15150
+ function utf8ByteLength(s) {
15151
+ let result = s.length;
15152
+ for (let i = 0; i < s.length; i++) {
15153
+ const codePoint = s.codePointAt(i);
15154
+ if (codePoint > 127) {
15155
+ result++;
15156
+ if (codePoint > 2047) {
15157
+ result++;
15158
+ if (codePoint > 65535) {
15159
+ i++;
15160
+ }
15161
+ }
15162
+ }
14980
15163
  }
14981
15164
  return result;
14982
15165
  }
14983
- function decodeWorkflowHistoryTransport(data) {
14984
- return decodeWorkflowHistory(toUint8Array(data));
14985
- }
15166
+ var UTF8_DECODER = /* @__PURE__ */ new TextDecoder("utf-8", { fatal: true });
15167
+ var UTF8_ENCODER = /* @__PURE__ */ new TextEncoder();
14986
15168
 
14987
- // ../rivetkit/dist/tsup/chunk-6FEYCVZC.js
14988
- function flattenActionHandlers(actions) {
14989
- const flattened = /* @__PURE__ */ Object.create(null);
14990
- for (const { name, handler } of collectActionEntries(actions)) {
14991
- flattened[name] = handler;
15169
+ // ../../../node_modules/.pnpm/@rivetkit+bare-ts@0.6.2/node_modules/@rivetkit/bare-ts/dist/core/config.js
15170
+ function Config({ initialBufferLength = 1024, maxBufferLength = 1024 * 1024 * 32 }) {
15171
+ if (DEV) {
15172
+ assert2(isU32(initialBufferLength), TOO_LARGE_NUMBER);
15173
+ assert2(isU32(maxBufferLength), TOO_LARGE_NUMBER);
15174
+ assert2(initialBufferLength <= maxBufferLength, "initialBufferLength must be lower than or equal to maxBufferLength");
14992
15175
  }
14993
- return flattened;
15176
+ return {
15177
+ initialBufferLength,
15178
+ maxBufferLength
15179
+ };
14994
15180
  }
14995
- function flattenActionInputSchemas(actions, schemas) {
14996
- if (schemas === void 0) return void 0;
14997
- if (!isRecord(schemas)) {
14998
- throw new TypeError("actionInputSchemas must be an object");
14999
- }
15000
- const flattened = /* @__PURE__ */ Object.create(null);
15001
- for (const { name, path: path2 } of collectActionEntries(actions)) {
15002
- const nestedSchema = lookupNestedSchema(schemas, path2);
15003
- const flatSchema = schemas[name];
15004
- if (nestedSchema !== void 0 && flatSchema !== void 0 && nestedSchema !== flatSchema) {
15005
- throw new TypeError(
15006
- `Action input schema \`${name}\` is defined by both a nested path and a dotted key`
15007
- );
15008
- }
15009
- const schema = nestedSchema ?? flatSchema;
15010
- if (schema !== void 0) {
15011
- flattened[name] = schema;
15181
+
15182
+ // ../rivetkit/dist/tsup/chunk-IVX7KBSQ.js
15183
+ var config2 = /* @__PURE__ */ Config({});
15184
+ function readWorkflowCbor(bc) {
15185
+ return readData(bc);
15186
+ }
15187
+ function readWorkflowNameIndex(bc) {
15188
+ return readU32(bc);
15189
+ }
15190
+ function readWorkflowLoopIterationMarker(bc) {
15191
+ return {
15192
+ loop: readWorkflowNameIndex(bc),
15193
+ iteration: readU32(bc)
15194
+ };
15195
+ }
15196
+ function readWorkflowPathSegment(bc) {
15197
+ const offset = bc.offset;
15198
+ const tag = readU8(bc);
15199
+ switch (tag) {
15200
+ case 0:
15201
+ return { tag: "WorkflowNameIndex", val: readWorkflowNameIndex(bc) };
15202
+ case 1:
15203
+ return {
15204
+ tag: "WorkflowLoopIterationMarker",
15205
+ val: readWorkflowLoopIterationMarker(bc)
15206
+ };
15207
+ default: {
15208
+ bc.offset = offset;
15209
+ throw new BareError(offset, "invalid tag");
15012
15210
  }
15013
15211
  }
15014
- return flattened;
15015
15212
  }
15016
- function flattenActionTraceSamplers(actions, rates = {}) {
15017
- const handlers = flattenActionHandlers(actions);
15018
- const flattened = Object.fromEntries(flattenSampleRates(rates, []));
15019
- for (const name of Object.keys(flattened)) {
15020
- if (!Object.hasOwn(handlers, name)) {
15021
- throw new TypeError(
15022
- `tracing.actions.${name} does not name an action`
15023
- );
15024
- }
15213
+ function readWorkflowLocation(bc) {
15214
+ const len = readUintSafe(bc);
15215
+ if (len === 0) {
15216
+ return [];
15025
15217
  }
15026
- return flattened;
15218
+ const result = [readWorkflowPathSegment(bc)];
15219
+ for (let i = 1; i < len; i++) {
15220
+ result[i] = readWorkflowPathSegment(bc);
15221
+ }
15222
+ return result;
15027
15223
  }
15028
- function flattenSampleRates(rates, path2) {
15029
- return Object.entries(rates).flatMap(
15030
- ([segment, rate]) => {
15031
- const childPath = [...path2, segment];
15032
- return typeof rate === "number" ? [[childPath.join("."), rate]] : flattenSampleRates(rate, childPath);
15224
+ function readWorkflowEntryStatus(bc) {
15225
+ const offset = bc.offset;
15226
+ const tag = readU8(bc);
15227
+ switch (tag) {
15228
+ case 0:
15229
+ return "PENDING";
15230
+ case 1:
15231
+ return "RUNNING";
15232
+ case 2:
15233
+ return "COMPLETED";
15234
+ case 3:
15235
+ return "FAILED";
15236
+ case 4:
15237
+ return "EXHAUSTED";
15238
+ default: {
15239
+ bc.offset = offset;
15240
+ throw new BareError(offset, "invalid tag");
15033
15241
  }
15034
- );
15035
- }
15036
- function collectActionEntries(actions) {
15037
- const entries = [];
15038
- const names = /* @__PURE__ */ new Set();
15039
- visitActionGroup(actions ?? {}, [], entries, names);
15040
- return entries;
15041
- }
15042
- function visitActionGroup(value, path2, entries, names) {
15043
- if (!isRecord(value)) {
15044
- throw new TypeError(
15045
- `${formatActionPath(path2)} must be an action handler or group`
15046
- );
15047
15242
  }
15048
- for (const [segment, child] of Object.entries(value)) {
15049
- const childPath = [...path2, segment];
15050
- if (typeof child === "function") {
15051
- const name = childPath.join(".");
15052
- if (names.has(name)) {
15053
- throw new TypeError(
15054
- `Multiple action definitions flatten to \`${name}\``
15055
- );
15056
- }
15057
- names.add(name);
15058
- entries.push({
15059
- name,
15060
- path: childPath,
15061
- handler: child
15062
- });
15063
- } else {
15064
- visitActionGroup(child, childPath, entries, names);
15243
+ }
15244
+ function readWorkflowSleepState(bc) {
15245
+ const offset = bc.offset;
15246
+ const tag = readU8(bc);
15247
+ switch (tag) {
15248
+ case 0:
15249
+ return "PENDING";
15250
+ case 1:
15251
+ return "COMPLETED";
15252
+ case 2:
15253
+ return "INTERRUPTED";
15254
+ default: {
15255
+ bc.offset = offset;
15256
+ throw new BareError(offset, "invalid tag");
15065
15257
  }
15066
15258
  }
15067
15259
  }
15068
- function lookupNestedSchema(schemas, path2) {
15069
- let value = schemas;
15070
- for (const segment of path2) {
15071
- if (!isRecord(value) || !Object.hasOwn(value, segment)) {
15072
- return void 0;
15260
+ function readWorkflowBranchStatusType(bc) {
15261
+ const offset = bc.offset;
15262
+ const tag = readU8(bc);
15263
+ switch (tag) {
15264
+ case 0:
15265
+ return "PENDING";
15266
+ case 1:
15267
+ return "RUNNING";
15268
+ case 2:
15269
+ return "COMPLETED";
15270
+ case 3:
15271
+ return "FAILED";
15272
+ case 4:
15273
+ return "CANCELLED";
15274
+ default: {
15275
+ bc.offset = offset;
15276
+ throw new BareError(offset, "invalid tag");
15073
15277
  }
15074
- value = value[segment];
15075
15278
  }
15076
- return value;
15077
15279
  }
15078
- function isRecord(value) {
15079
- if (typeof value !== "object" || value === null || Array.isArray(value)) {
15080
- return false;
15081
- }
15082
- const prototype = Object.getPrototypeOf(value);
15083
- return prototype === Object.prototype || prototype === null;
15280
+ function read0(bc) {
15281
+ return readBool(bc) ? readWorkflowCbor(bc) : null;
15084
15282
  }
15085
- function formatActionPath(path2) {
15086
- return path2.length === 0 ? "actions" : `Action \`${path2.join(".")}\``;
15283
+ function read1(bc) {
15284
+ return readBool(bc) ? readString(bc) : null;
15087
15285
  }
15088
- var DEFAULT_SLEEP_GRACE_PERIOD = 15e3;
15089
- var ACTOR_CONTEXT_INTERNAL_SYMBOL = /* @__PURE__ */ Symbol(
15090
- "rivetkit.actor_context_internal"
15091
- );
15092
- var RAW_STATE_SYMBOL = /* @__PURE__ */ Symbol("rivetkit.raw_state");
15093
- var CONN_STATE_MANAGER_SYMBOL = /* @__PURE__ */ Symbol("rivetkit.conn_state_manager");
15094
- var zFunction = () => external_exports.custom((val) => typeof val === "function");
15095
- var zActionTree = external_exports.custom((value) => {
15096
- if (typeof value !== "object" || value === null || Array.isArray(value)) {
15097
- return false;
15098
- }
15099
- const prototype = Object.getPrototypeOf(value);
15100
- return prototype === Object.prototype || prototype === null;
15101
- }).superRefine((actions, ctx) => {
15102
- try {
15103
- flattenActionHandlers(actions);
15104
- } catch (error46) {
15105
- ctx.addIssue({
15106
- code: "custom",
15107
- message: error46 instanceof Error ? error46.message : "Invalid action definition"
15108
- });
15109
- }
15110
- });
15111
- var WorkflowInspectorConfigSchema = external_exports.object({
15112
- getHistory: zFunction(),
15113
- getState: zFunction().optional(),
15114
- onHistoryUpdated: zFunction().optional(),
15115
- replayFromStep: zFunction().optional()
15116
- });
15117
- var RunInspectorConfigSchema = external_exports.object({
15118
- workflow: WorkflowInspectorConfigSchema.optional()
15119
- }).optional();
15120
- var BUILTIN_INSPECTOR_TAB_IDS = [
15121
- "workflow",
15122
- "database",
15123
- "state",
15124
- "queue",
15125
- "schedules",
15126
- "connections",
15127
- "console"
15128
- ];
15129
- var BuiltinInspectorTabIdSchema = external_exports.enum(BUILTIN_INSPECTOR_TAB_IDS);
15130
- var CUSTOM_INSPECTOR_TAB_ID_RE = /^[A-Za-z0-9_-]+$/;
15131
- var CustomInspectorTabEntrySchema = external_exports.object({
15132
- id: external_exports.string().regex(
15133
- CUSTOM_INSPECTOR_TAB_ID_RE,
15134
- "inspector.tabs[].id must contain only letters, digits, underscore, or dash"
15135
- ),
15136
- label: external_exports.string().min(1),
15137
- source: external_exports.string().min(1),
15138
- /**
15139
- * Optional icon id. The dashboard maps strings to glyphs (see its
15140
- * icon registry); unknown ids fall back to a generic icon.
15141
- */
15142
- icon: external_exports.string().min(1).optional(),
15143
- hidden: external_exports.literal(false).optional()
15144
- }).strict();
15145
- var HideInspectorTabEntrySchema = external_exports.object({
15146
- id: BuiltinInspectorTabIdSchema,
15147
- hidden: external_exports.literal(true)
15148
- }).strict();
15149
- var InspectorTabEntrySchema = external_exports.union([
15150
- CustomInspectorTabEntrySchema,
15151
- HideInspectorTabEntrySchema
15152
- ]);
15153
- var ActorInspectorConfigSchema = external_exports.object({
15154
- tabs: external_exports.array(InspectorTabEntrySchema).default(() => [])
15155
- }).strict().refine(
15156
- (data) => {
15157
- const ids = data.tabs.map((t) => t.id);
15158
- return new Set(ids).size === ids.length;
15159
- },
15160
- { message: "Duplicate id in inspector.tabs", path: ["tabs"] }
15161
- ).refine(
15162
- (data) => {
15163
- const builtinSet = new Set(BUILTIN_INSPECTOR_TAB_IDS);
15164
- return data.tabs.every(
15165
- (t) => t.hidden === true || !builtinSet.has(t.id)
15166
- );
15167
- },
15168
- {
15169
- message: "Custom inspector tab id collides with a built-in (use hidden: true to hide a built-in)",
15170
- path: ["tabs"]
15171
- }
15172
- );
15173
- var RunConfigSchema = external_exports.object({
15174
- /** Display name for the actor in the Inspector UI. */
15175
- name: external_exports.string().optional(),
15176
- /** Icon for the actor in the Inspector UI. Can be an emoji or FontAwesome icon name. */
15177
- icon: external_exports.string().optional(),
15178
- /** The run handler function. */
15179
- run: zFunction(),
15180
- /** Inspector integration for long-running run handlers. */
15181
- inspector: RunInspectorConfigSchema.optional()
15182
- });
15183
- var RUN_FUNCTION_CONFIG_SYMBOL = /* @__PURE__ */ Symbol.for("rivetkit.run_function_config");
15184
- function defineRunHandler(run, options) {
15185
- if (options.inspectorKind === void 0 !== (options.createInspector === void 0)) {
15186
- throw new TypeError(
15187
- "defineRunHandler requires inspectorKind and createInspector together"
15188
- );
15189
- }
15190
- Object.defineProperty(run, RUN_FUNCTION_CONFIG_SYMBOL, {
15191
- configurable: false,
15192
- enumerable: false,
15193
- writable: false,
15194
- value: {
15195
- name: options.name,
15196
- icon: options.icon,
15197
- inspectorKind: options.inspectorKind,
15198
- createInspector: options.createInspector
15199
- }
15200
- });
15201
- return run;
15286
+ function readWorkflowStepEntry(bc) {
15287
+ return {
15288
+ output: read0(bc),
15289
+ error: read1(bc)
15290
+ };
15291
+ }
15292
+ function readWorkflowLoopEntry(bc) {
15293
+ return {
15294
+ state: readWorkflowCbor(bc),
15295
+ iteration: readU32(bc),
15296
+ output: read0(bc)
15297
+ };
15202
15298
  }
15203
- function getRunInspectorKind(run) {
15204
- var _a2;
15205
- if (!run || typeof run !== "function") return void 0;
15206
- return (_a2 = run[RUN_FUNCTION_CONFIG_SYMBOL]) == null ? void 0 : _a2.inspectorKind;
15299
+ function readWorkflowSleepEntry(bc) {
15300
+ return {
15301
+ deadline: readU64(bc),
15302
+ state: readWorkflowSleepState(bc)
15303
+ };
15207
15304
  }
15208
- function createRunInspector(run, context2) {
15209
- var _a2, _b;
15210
- if (!run || typeof run !== "function") return void 0;
15211
- return (_b = (_a2 = run[RUN_FUNCTION_CONFIG_SYMBOL]) == null ? void 0 : _a2.createInspector) == null ? void 0 : _b.call(_a2, context2);
15305
+ function readWorkflowMessageEntry(bc) {
15306
+ return {
15307
+ name: readString(bc),
15308
+ messageData: readWorkflowCbor(bc)
15309
+ };
15212
15310
  }
15213
- var zRunHandler = external_exports.union([zFunction(), RunConfigSchema]).optional();
15214
- function getRunFunction(run) {
15215
- if (!run) return void 0;
15216
- if (typeof run === "function") return run;
15217
- return run.run;
15311
+ function readWorkflowRollbackCheckpointEntry(bc) {
15312
+ return {
15313
+ name: readString(bc)
15314
+ };
15218
15315
  }
15219
- function getRunMetadata(run) {
15220
- if (!run) return {};
15221
- if (typeof run === "function") {
15222
- const config3 = run[RUN_FUNCTION_CONFIG_SYMBOL];
15223
- if (!config3) return {};
15224
- return { name: config3.name, icon: config3.icon };
15225
- }
15226
- return { name: run.name, icon: run.icon };
15316
+ function readWorkflowBranchStatus(bc) {
15317
+ return {
15318
+ status: readWorkflowBranchStatusType(bc),
15319
+ output: read0(bc),
15320
+ error: read1(bc)
15321
+ };
15227
15322
  }
15228
- function getRunInspectorConfig(run, actor2) {
15229
- if (!run) return void 0;
15230
- if (typeof run === "function") {
15231
- const config3 = run[RUN_FUNCTION_CONFIG_SYMBOL];
15232
- return (config3 == null ? void 0 : config3.inspectorFactory) ? config3.inspectorFactory(actor2) : config3 == null ? void 0 : config3.inspector;
15323
+ function read2(bc) {
15324
+ const len = readUintSafe(bc);
15325
+ const result = /* @__PURE__ */ new Map();
15326
+ for (let i = 0; i < len; i++) {
15327
+ const offset = bc.offset;
15328
+ const key = readString(bc);
15329
+ if (result.has(key)) {
15330
+ bc.offset = offset;
15331
+ throw new BareError(offset, "duplicated key");
15332
+ }
15333
+ result.set(key, readWorkflowBranchStatus(bc));
15233
15334
  }
15234
- return run.inspector;
15335
+ return result;
15235
15336
  }
15236
- function hasRunInspectorConfig(run) {
15237
- if (!run) return false;
15238
- if (typeof run !== "function") return run.inspector !== void 0;
15239
- const config3 = run[RUN_FUNCTION_CONFIG_SYMBOL];
15240
- 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;
15337
+ function readWorkflowJoinEntry(bc) {
15338
+ return {
15339
+ branches: read2(bc)
15340
+ };
15241
15341
  }
15242
- function disposeRunInspector(run, actorId) {
15243
- var _a2;
15244
- if (!run || typeof run !== "function") {
15245
- return;
15342
+ function readWorkflowRaceEntry(bc) {
15343
+ return {
15344
+ winner: read1(bc),
15345
+ branches: read2(bc)
15346
+ };
15347
+ }
15348
+ function readWorkflowRemovedEntry(bc) {
15349
+ return {
15350
+ originalType: readString(bc),
15351
+ originalName: read1(bc)
15352
+ };
15353
+ }
15354
+ function readWorkflowVersionCheckEntry(bc) {
15355
+ return {
15356
+ resolved: readU32(bc),
15357
+ latest: readU32(bc)
15358
+ };
15359
+ }
15360
+ function readWorkflowEntryKind(bc) {
15361
+ const offset = bc.offset;
15362
+ const tag = readU8(bc);
15363
+ switch (tag) {
15364
+ case 0:
15365
+ return { tag: "WorkflowStepEntry", val: readWorkflowStepEntry(bc) };
15366
+ case 1:
15367
+ return { tag: "WorkflowLoopEntry", val: readWorkflowLoopEntry(bc) };
15368
+ case 2:
15369
+ return {
15370
+ tag: "WorkflowSleepEntry",
15371
+ val: readWorkflowSleepEntry(bc)
15372
+ };
15373
+ case 3:
15374
+ return {
15375
+ tag: "WorkflowMessageEntry",
15376
+ val: readWorkflowMessageEntry(bc)
15377
+ };
15378
+ case 4:
15379
+ return {
15380
+ tag: "WorkflowRollbackCheckpointEntry",
15381
+ val: readWorkflowRollbackCheckpointEntry(bc)
15382
+ };
15383
+ case 5:
15384
+ return { tag: "WorkflowJoinEntry", val: readWorkflowJoinEntry(bc) };
15385
+ case 6:
15386
+ return { tag: "WorkflowRaceEntry", val: readWorkflowRaceEntry(bc) };
15387
+ case 7:
15388
+ return {
15389
+ tag: "WorkflowRemovedEntry",
15390
+ val: readWorkflowRemovedEntry(bc)
15391
+ };
15392
+ case 8:
15393
+ return {
15394
+ tag: "WorkflowVersionCheckEntry",
15395
+ val: readWorkflowVersionCheckEntry(bc)
15396
+ };
15397
+ default: {
15398
+ bc.offset = offset;
15399
+ throw new BareError(offset, "invalid tag");
15400
+ }
15246
15401
  }
15247
- const config3 = run[RUN_FUNCTION_CONFIG_SYMBOL];
15248
- (_a2 = config3 == null ? void 0 : config3.disposeInspector) == null ? void 0 : _a2.call(config3, actorId);
15249
15402
  }
15250
- var GlobalActorOptionsBaseSchema = external_exports.object({
15251
- /** Display name for the actor in the Inspector UI. */
15252
- name: external_exports.string().optional(),
15253
- /** Icon for the actor in the Inspector UI. Can be an emoji or FontAwesome icon name. */
15254
- icon: external_exports.string().optional(),
15255
- /** Enables the experimental Actor Runtime Socket for this actor. */
15256
- enableActorRuntimeSocket: external_exports.boolean().default(false),
15257
- /**
15258
- * Can hibernate WebSockets, both client connections for actions and
15259
- * events and WebSockets for onWebSocket. A WebSocket that does not
15260
- * hibernate closes when the actor sleeps, and the client reconnects.
15261
- *
15262
- * @experimental
15263
- **/
15264
- canHibernateWebSocket: external_exports.union([external_exports.boolean(), zFunction()]).default(false)
15265
- }).strict();
15266
- var GlobalActorOptionsSchema = GlobalActorOptionsBaseSchema.prefault(
15267
- () => ({})
15268
- );
15269
- var InstanceActorOptionsBaseSchema = external_exports.object({
15270
- createVarsTimeout: external_exports.number().positive().default(5e3),
15271
- createConnStateTimeout: external_exports.number().positive().default(5e3),
15272
- onBeforeConnectTimeout: external_exports.number().positive().default(5e3),
15273
- onConnectTimeout: external_exports.number().positive().default(5e3),
15274
- onMigrateTimeout: external_exports.number().positive().default(3e4),
15275
- sleepGracePeriod: external_exports.number().positive().default(DEFAULT_SLEEP_GRACE_PERIOD),
15276
- /** @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. */
15277
- onDestroyTimeout: external_exports.number().positive().optional(),
15278
- /** @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. */
15279
- waitUntilTimeout: external_exports.number().positive().optional(),
15280
- stateSaveInterval: external_exports.number().positive().default(1e3),
15281
- actionTimeout: external_exports.number().positive().default(6e4),
15282
- connectionLivenessTimeout: external_exports.number().positive().default(2500),
15283
- connectionLivenessInterval: external_exports.number().positive().default(5e3),
15284
- /** @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. */
15285
- noSleep: external_exports.boolean().default(false),
15286
- sleepTimeout: external_exports.number().positive().default(3e4),
15287
- maxQueueSize: external_exports.number().positive().default(1e3),
15288
- /** Maximum pending one-shot and recurring schedules. */
15289
- maxSchedules: external_exports.number().int().nonnegative().default(1e3),
15290
- maxQueueMessageSize: external_exports.number().positive().default(64 * 1024),
15291
- /** @deprecated Internal storage moved to SQLite and no longer uses KV preloading, so this option is ignored. Will be removed in 2.2.0. */
15292
- preloadMaxWorkflowBytes: external_exports.number().nonnegative().optional(),
15293
- /** @deprecated Internal storage moved to SQLite and no longer uses KV preloading, so this option is ignored. Will be removed in 2.2.0. */
15294
- preloadMaxConnectionsBytes: external_exports.number().nonnegative().optional()
15295
- }).strict();
15296
- var InstanceActorOptionsSchema = InstanceActorOptionsBaseSchema.prefault(() => ({}));
15297
- var ActorOptionsSchema = GlobalActorOptionsBaseSchema.extend(
15298
- InstanceActorOptionsBaseSchema.shape
15299
- ).strict().prefault(() => ({}));
15300
- var zSampleRate = external_exports.number().min(0).max(1);
15301
- var zActionSampleRates = external_exports.lazy(
15302
- () => external_exports.record(external_exports.string(), external_exports.union([zSampleRate, zActionSampleRates]))
15303
- );
15304
- var ActorConfigSchema = external_exports.object({
15305
- onCreate: zFunction().optional(),
15306
- onDestroy: zFunction().optional(),
15307
- onMigrate: zFunction().optional(),
15308
- onWake: zFunction().optional(),
15309
- onSleep: zFunction().optional(),
15310
- run: zRunHandler,
15311
- onStateChange: zFunction().optional(),
15312
- onBeforeConnect: zFunction().optional(),
15313
- onConnect: zFunction().optional(),
15314
- onDisconnect: zFunction().optional(),
15315
- onBeforeActionResponse: zFunction().optional(),
15316
- onRequest: zFunction().optional(),
15317
- onWebSocket: zFunction().optional(),
15318
- actions: zActionTree.default(() => ({})),
15319
- actionInputSchemas: external_exports.record(external_exports.string(), external_exports.any()).optional(),
15320
- tracing: external_exports.object({
15321
- sampler: zSampleRate.optional(),
15322
- actions: zActionSampleRates.optional()
15323
- }).strict().optional(),
15324
- connParamsSchema: external_exports.any().optional(),
15325
- events: external_exports.record(external_exports.string(), external_exports.any()).optional(),
15326
- queues: external_exports.record(external_exports.string(), external_exports.any()).optional(),
15327
- state: external_exports.any().optional(),
15328
- createState: zFunction().optional(),
15329
- connState: external_exports.any().optional(),
15330
- createConnState: zFunction().optional(),
15331
- vars: external_exports.any().optional(),
15332
- db: external_exports.any().optional(),
15333
- createVars: zFunction().optional(),
15334
- options: ActorOptionsSchema,
15335
- inspector: ActorInspectorConfigSchema.optional()
15336
- }).strict().refine(
15337
- (data) => !(data.state !== void 0 && data.createState !== void 0),
15338
- {
15339
- message: "Cannot define both 'state' and 'createState'",
15340
- path: ["state"]
15403
+ function readWorkflowEntry(bc) {
15404
+ return {
15405
+ id: readString(bc),
15406
+ location: readWorkflowLocation(bc),
15407
+ kind: readWorkflowEntryKind(bc)
15408
+ };
15409
+ }
15410
+ function read3(bc) {
15411
+ return readBool(bc) ? readU64(bc) : null;
15412
+ }
15413
+ function readWorkflowEntryMetadata(bc) {
15414
+ return {
15415
+ status: readWorkflowEntryStatus(bc),
15416
+ error: read1(bc),
15417
+ attempts: readU32(bc),
15418
+ lastAttemptAt: readU64(bc),
15419
+ createdAt: readU64(bc),
15420
+ completedAt: read3(bc),
15421
+ rollbackCompletedAt: read3(bc),
15422
+ rollbackError: read1(bc)
15423
+ };
15424
+ }
15425
+ function read4(bc) {
15426
+ const len = readUintSafe(bc);
15427
+ if (len === 0) {
15428
+ return [];
15429
+ }
15430
+ const result = [readString(bc)];
15431
+ for (let i = 1; i < len; i++) {
15432
+ result[i] = readString(bc);
15341
15433
  }
15342
- ).refine(
15343
- (data) => !(data.connState !== void 0 && data.createConnState !== void 0),
15344
- {
15345
- message: "Cannot define both 'connState' and 'createConnState'",
15346
- path: ["connState"]
15434
+ return result;
15435
+ }
15436
+ function read5(bc) {
15437
+ const len = readUintSafe(bc);
15438
+ if (len === 0) {
15439
+ return [];
15347
15440
  }
15348
- ).refine(
15349
- (data) => !(data.vars !== void 0 && data.createVars !== void 0),
15350
- {
15351
- message: "Cannot define both 'vars' and 'createVars'",
15352
- path: ["vars"]
15441
+ const result = [readWorkflowEntry(bc)];
15442
+ for (let i = 1; i < len; i++) {
15443
+ result[i] = readWorkflowEntry(bc);
15353
15444
  }
15354
- );
15355
- var DocActorOptionsSchema = external_exports.object({
15356
- name: external_exports.string().optional().describe("Display name for the actor in the Inspector UI."),
15357
- icon: external_exports.string().optional().describe(
15358
- "Icon for the actor in the Inspector UI. Can be an emoji (e.g., '\u{1F680}') or FontAwesome icon name (e.g., 'rocket')."
15359
- ),
15360
- enableActorRuntimeSocket: external_exports.boolean().optional().describe(
15361
- "Enables the experimental Actor Runtime Socket for this actor. Default: false"
15362
- ),
15363
- createVarsTimeout: external_exports.number().optional().describe("Timeout in ms for createVars handler. Default: 5000"),
15364
- createConnStateTimeout: external_exports.number().optional().describe(
15365
- "Timeout in ms for createConnState handler. Default: 5000"
15366
- ),
15367
- onMigrateTimeout: external_exports.number().optional().describe("Timeout in ms for onMigrate handler. Default: 30000"),
15368
- onBeforeConnectTimeout: external_exports.number().optional().describe(
15369
- "Timeout in ms for onBeforeConnect handler. Default: 5000"
15370
- ),
15371
- onConnectTimeout: external_exports.number().optional().describe("Timeout in ms for onConnect handler. Default: 5000"),
15372
- sleepGracePeriod: external_exports.number().optional().describe(
15373
- `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}.`
15374
- ),
15375
- onDestroyTimeout: external_exports.number().optional().describe(
15376
- "Deprecated. Folded into sleepGracePeriod, which now bounds the entire graceful shutdown window for both sleep and destroy. Will be removed in 2.2.0."
15377
- ),
15378
- waitUntilTimeout: external_exports.number().optional().describe(
15379
- "Deprecated. Folded into sleepGracePeriod, which now bounds the entire graceful shutdown window for both sleep and destroy. Will be removed in 2.2.0."
15380
- ),
15381
- stateSaveInterval: external_exports.number().optional().describe(
15382
- "Interval in ms between automatic state saves. Default: 1000"
15383
- ),
15384
- actionTimeout: external_exports.number().optional().describe("Timeout in ms for action handlers. Default: 60000"),
15385
- connectionLivenessTimeout: external_exports.number().optional().describe(
15386
- "Timeout in ms for connection liveness checks. Default: 2500"
15387
- ),
15388
- connectionLivenessInterval: external_exports.number().optional().describe(
15389
- "Interval in ms between connection liveness checks. Default: 5000"
15390
- ),
15391
- noSleep: external_exports.boolean().optional().describe(
15392
- "Deprecated. If true, the actor will never sleep. Use c.keepAwake(promise) to scope keep-awake to a specific operation instead. Default: false"
15393
- ),
15394
- sleepTimeout: external_exports.number().optional().describe(
15395
- "Time in ms of inactivity before the actor sleeps. Default: 30000"
15396
- ),
15397
- maxQueueSize: external_exports.number().optional().describe(
15398
- "Maximum number of queue messages before rejecting new messages. Default: 1000"
15399
- ),
15400
- maxSchedules: external_exports.number().int().nonnegative().optional().describe(
15401
- "Maximum pending one-shot and recurring schedules before rejecting new schedules. Default: 1000"
15402
- ),
15403
- maxQueueMessageSize: external_exports.number().optional().describe(
15404
- "Maximum size of each queue message in bytes. Default: 65536"
15405
- ),
15406
- canHibernateWebSocket: external_exports.boolean().optional().describe(
15407
- "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"
15408
- )
15409
- }).describe("Actor options for timeouts and behavior configuration.");
15410
- var DocActorConfigSchema = external_exports.object({
15411
- state: external_exports.unknown().optional().describe(
15412
- "Initial state value for the actor. Cannot be used with createState."
15413
- ),
15414
- createState: external_exports.unknown().optional().describe(
15415
- "Function to create initial state. Receives context and input. Cannot be used with state."
15416
- ),
15417
- connState: external_exports.unknown().optional().describe(
15418
- "Initial connection state value. Cannot be used with createConnState."
15419
- ),
15420
- createConnState: external_exports.unknown().optional().describe(
15421
- "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."
15422
- ),
15423
- vars: external_exports.unknown().optional().describe(
15424
- "Initial ephemeral variables value. Cannot be used with createVars."
15425
- ),
15426
- createVars: external_exports.unknown().optional().describe(
15427
- "Function to create ephemeral variables. Receives context and driver context. Cannot be used with vars."
15428
- ),
15429
- db: external_exports.unknown().optional().describe("Database provider instance for the actor."),
15430
- onCreate: external_exports.unknown().optional().describe(
15431
- "Called when the actor is first initialized. Use to initialize state."
15432
- ),
15433
- onDestroy: external_exports.unknown().optional().describe("Called when the actor is destroyed."),
15434
- onMigrate: external_exports.unknown().optional().describe(
15435
- "Called on every actor start after persisted state loads and before onWake. Use for repeatable schema migrations."
15436
- ),
15437
- onWake: external_exports.unknown().optional().describe(
15438
- "Called when the actor wakes up and is ready to receive connections and actions."
15439
- ),
15440
- onSleep: external_exports.unknown().optional().describe(
15441
- "Called when the actor is stopping or sleeping. Use to clean up resources."
15442
- ),
15443
- run: external_exports.unknown().optional().describe(
15444
- "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."
15445
- ),
15446
- onStateChange: external_exports.unknown().optional().describe(
15447
- "Called when the actor's state changes. State changes within this hook won't trigger recursion."
15448
- ),
15449
- onBeforeConnect: external_exports.unknown().optional().describe(
15450
- "Called before a client connects. Throw an error to reject the connection. The pending connection is not visible in c.conns while this runs."
15451
- ),
15452
- onConnect: external_exports.unknown().optional().describe(
15453
- "Called when a client successfully connects. The connection is visible in c.conns before this runs."
15454
- ),
15455
- onDisconnect: external_exports.unknown().optional().describe("Called when a client disconnects."),
15456
- onBeforeActionResponse: external_exports.unknown().optional().describe(
15457
- "Called before sending an action response. Use to transform output."
15458
- ),
15459
- onRequest: external_exports.unknown().optional().describe(
15460
- "Called for raw HTTP requests to /actors/{name}/http/* endpoints."
15461
- ),
15462
- onWebSocket: external_exports.unknown().optional().describe(
15463
- "Called for raw WebSocket connections to /actors/{name}/websocket/* endpoints."
15464
- ),
15465
- actions: external_exports.record(external_exports.string(), external_exports.unknown()).optional().describe(
15466
- "Tree of action names or nested groups to handler functions. Nested paths use dot-separated low-level action names. Defaults to an empty object."
15467
- ),
15468
- actionInputSchemas: external_exports.record(external_exports.string(), external_exports.unknown()).optional().describe(
15469
- "Optional schemas for validating action argument tuples in native runtimes. May mirror nested action groups or use dot-separated low-level action names."
15470
- ),
15471
- tracing: external_exports.unknown().optional().describe(
15472
- "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."
15473
- ),
15474
- connParamsSchema: external_exports.unknown().optional().describe(
15475
- "Optional schema for validating connection params in native runtimes."
15476
- ),
15477
- events: external_exports.record(external_exports.string(), external_exports.unknown()).optional().describe("Map of event names to schemas."),
15478
- queues: external_exports.record(external_exports.string(), external_exports.unknown()).optional().describe("Map of queue names to schemas."),
15479
- options: DocActorOptionsSchema.optional()
15480
- }).describe("Actor configuration passed to the actor() function.");
15445
+ return result;
15446
+ }
15447
+ function read6(bc) {
15448
+ const len = readUintSafe(bc);
15449
+ const result = /* @__PURE__ */ new Map();
15450
+ for (let i = 0; i < len; i++) {
15451
+ const offset = bc.offset;
15452
+ const key = readString(bc);
15453
+ if (result.has(key)) {
15454
+ bc.offset = offset;
15455
+ throw new BareError(offset, "duplicated key");
15456
+ }
15457
+ result.set(key, readWorkflowEntryMetadata(bc));
15458
+ }
15459
+ return result;
15460
+ }
15461
+ function readWorkflowHistory(bc) {
15462
+ return {
15463
+ nameRegistry: read4(bc),
15464
+ entries: read5(bc),
15465
+ entryMetadata: read6(bc)
15466
+ };
15467
+ }
15468
+ function decodeWorkflowHistory(bytes) {
15469
+ const bc = new ByteCursor(bytes, config2);
15470
+ const result = readWorkflowHistory(bc);
15471
+ if (bc.offset < bc.view.byteLength) {
15472
+ throw new BareError(bc.offset, "remaining bytes");
15473
+ }
15474
+ return result;
15475
+ }
15476
+ function decodeWorkflowHistoryTransport(data) {
15477
+ return decodeWorkflowHistory(toUint8Array(data));
15478
+ }
15481
15479
 
15482
15480
  // ../rivetkit/dist/tsup/chunk-JI6GZ2C2.js
15483
15481
  var EMPTY_KEY = "/";
@@ -15596,6 +15594,44 @@ function removePrefixFromKey(prefixedKey) {
15596
15594
  return prefixedKey.slice(KEYS.KV.length);
15597
15595
  }
15598
15596
 
15597
+ // ../rivetkit/dist/tsup/chunk-EOYS5GVX.js
15598
+ function logger() {
15599
+ return getLogger("actor-client");
15600
+ }
15601
+ var webSocketPromise = null;
15602
+ async function importWebSocket() {
15603
+ if (webSocketPromise !== null) {
15604
+ return webSocketPromise;
15605
+ }
15606
+ webSocketPromise = (async () => {
15607
+ let _WebSocket;
15608
+ if (typeof WebSocket !== "undefined") {
15609
+ _WebSocket = WebSocket;
15610
+ } else {
15611
+ try {
15612
+ const moduleName = "ws";
15613
+ const ws = await import(
15614
+ /* webpackIgnore: true */
15615
+ moduleName
15616
+ );
15617
+ _WebSocket = ws.default;
15618
+ logger().debug("using websocket from npm");
15619
+ } catch {
15620
+ _WebSocket = class MockWebSocket {
15621
+ constructor() {
15622
+ throw new Error(
15623
+ 'WebSocket support requires installing the "ws" peer dependency.'
15624
+ );
15625
+ }
15626
+ };
15627
+ logger().debug("using mock websocket");
15628
+ }
15629
+ }
15630
+ return _WebSocket;
15631
+ })();
15632
+ return webSocketPromise;
15633
+ }
15634
+
15599
15635
  // ../rivetkit/dist/tsup/chunk-JTHHCZCZ.js
15600
15636
  var MIGRATION_TRANSACTION_TIMEOUT_MS = 5 * 6e4;
15601
15637
  function isManualTransactionControl(query) {
@@ -15679,45 +15715,7 @@ var AsyncMutex = class {
15679
15715
  }
15680
15716
  };
15681
15717
 
15682
- // ../rivetkit/dist/tsup/chunk-H3SGQEHZ.js
15683
- function logger() {
15684
- return getLogger("actor-client");
15685
- }
15686
- var webSocketPromise = null;
15687
- async function importWebSocket() {
15688
- if (webSocketPromise !== null) {
15689
- return webSocketPromise;
15690
- }
15691
- webSocketPromise = (async () => {
15692
- let _WebSocket;
15693
- if (typeof WebSocket !== "undefined") {
15694
- _WebSocket = WebSocket;
15695
- } else {
15696
- try {
15697
- const moduleName = "ws";
15698
- const ws = await import(
15699
- /* webpackIgnore: true */
15700
- moduleName
15701
- );
15702
- _WebSocket = ws.default;
15703
- logger().debug("using websocket from npm");
15704
- } catch {
15705
- _WebSocket = class MockWebSocket {
15706
- constructor() {
15707
- throw new Error(
15708
- 'WebSocket support requires installing the "ws" peer dependency.'
15709
- );
15710
- }
15711
- };
15712
- logger().debug("using mock websocket");
15713
- }
15714
- }
15715
- return _WebSocket;
15716
- })();
15717
- return webSocketPromise;
15718
- }
15719
-
15720
- // ../rivetkit/dist/tsup/chunk-I472KTIC.js
15718
+ // ../rivetkit/dist/tsup/chunk-7VIY7WIH.js
15721
15719
  var import_invariant2 = __toESM(require_invariant(), 1);
15722
15720
 
15723
15721
  // ../../../node_modules/.pnpm/p-retry@6.2.1/node_modules/p-retry/index.js
@@ -16932,7 +16930,7 @@ var TraceAPI = (
16932
16930
  // ../../../node_modules/.pnpm/@opentelemetry+api@1.9.0/node_modules/@opentelemetry/api/build/esm/trace-api.js
16933
16931
  var trace = TraceAPI.getInstance();
16934
16932
 
16935
- // ../rivetkit/dist/tsup/chunk-I472KTIC.js
16933
+ // ../rivetkit/dist/tsup/chunk-7VIY7WIH.js
16936
16934
  var import_invariant3 = __toESM(require_invariant(), 1);
16937
16935
  var import_invariant4 = __toESM(require_invariant(), 1);
16938
16936
  var PATH_CONNECT = "/connect";
@@ -23128,7 +23126,7 @@ function apiActorToOutput(actor2) {
23128
23126
  };
23129
23127
  }
23130
23128
 
23131
- // ../rivetkit/dist/tsup/chunk-OUB7SGSA.js
23129
+ // ../rivetkit/dist/tsup/chunk-XWEGENG4.js
23132
23130
  var nativeStateTransactionOpeners = /* @__PURE__ */ new WeakMap();
23133
23131
  var nativeStateTransactionClientBinders = /* @__PURE__ */ new WeakMap();
23134
23132
  function registerNativeStateTransactionOpener(provider, opener) {