@rivetkit/supabase 2.3.11-rc.5 → 2.3.11-rc.7

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 +1681 -1683
  2. package/dist/mod.mjs +1681 -1683
  3. package/package.json +9 -4
package/dist/mod.mjs CHANGED
@@ -297,186 +297,6 @@ var require_retry2 = __commonJS({
297
297
  // src/mod.ts
298
298
  import * as wasmBindings from "@rivetkit/rivetkit-wasm";
299
299
 
300
- // ../rivetkit/dist/tsup/chunk-ZZ3WBRPD.js
301
- var INTERNAL_ERROR_CODE = "internal_error";
302
- var INTERNAL_ERROR_DESCRIPTION = "An internal error occurred";
303
- var USER_ERROR_CODE = "user_error";
304
- var BRIDGE_RIVET_ERROR_PREFIX = "__RIVET_ERROR_JSON__:";
305
- function looksLikeRivetErrorOptions(value) {
306
- return typeof value === "object" && value !== null && ("public" in value || "metadata" in value || "statusCode" in value || "actor" in value || "cause" in value);
307
- }
308
- function isTypedErrorTag(value) {
309
- return value === "ActorError" || value === "RivetError";
310
- }
311
- function errorMessage(error46, fallback = String(error46)) {
312
- if (error46 && typeof error46 === "object" && "message" in error46 && typeof error46.message === "string") {
313
- return error46.message;
314
- }
315
- return fallback;
316
- }
317
- function isRivetErrorLike(error46) {
318
- return typeof error46 === "object" && error46 !== null && "group" in error46 && typeof error46.group === "string" && "code" in error46 && typeof error46.code === "string" && "message" in error46 && typeof error46.message === "string" && (!("__type" in error46) || isTypedErrorTag(error46.__type));
319
- }
320
- function isActorAbortedError(error46) {
321
- return isRivetErrorLike(error46) && error46.group === "actor" && error46.code === "aborted";
322
- }
323
- function isActorSpecifier(value) {
324
- return typeof value === "object" && value !== null && "actorId" in value && typeof value.actorId === "string" && "generation" in value && typeof value.generation === "number" && (!("key" in value) || value.key === void 0 || typeof value.key === "string");
325
- }
326
- var RivetError = class extends Error {
327
- __type = "RivetError";
328
- public;
329
- metadata;
330
- statusCode;
331
- actor;
332
- group;
333
- code;
334
- static isRivetError(error46) {
335
- return isRivetErrorLike(error46);
336
- }
337
- static isActorError(error46) {
338
- return isRivetErrorLike(error46);
339
- }
340
- constructor(group, code, message, options) {
341
- const normalized = looksLikeRivetErrorOptions(options) ? options : { metadata: options };
342
- super(message, { cause: normalized.cause });
343
- this.name = "RivetError";
344
- this.group = group;
345
- this.code = code;
346
- this.public = normalized.public ?? false;
347
- this.metadata = normalized.metadata;
348
- this.statusCode = normalized.statusCode ?? (this.public ? 400 : 500);
349
- this.actor = normalized.actor;
350
- }
351
- toString() {
352
- return this.message;
353
- }
354
- };
355
- var UserError = class extends RivetError {
356
- constructor(message, options) {
357
- super("user", (options == null ? void 0 : options.code) ?? USER_ERROR_CODE, message, {
358
- public: true,
359
- metadata: options == null ? void 0 : options.metadata,
360
- cause: options == null ? void 0 : options.cause
361
- });
362
- }
363
- };
364
- function toRivetError(error46, fallback) {
365
- if (typeof error46 === "string") {
366
- const bridged = decodeBridgeRivetError(error46);
367
- if (bridged) {
368
- return bridged;
369
- }
370
- }
371
- if (error46 instanceof Error) {
372
- const bridged = decodeBridgeRivetError(error46.message);
373
- if (bridged) {
374
- return bridged;
375
- }
376
- }
377
- if (isRivetErrorLike(error46)) {
378
- return new RivetError(error46.group, error46.code, error46.message, {
379
- public: error46.public,
380
- statusCode: error46.statusCode,
381
- metadata: error46.metadata,
382
- actor: error46.actor,
383
- cause: error46 instanceof Error ? error46.cause : void 0
384
- });
385
- }
386
- return new RivetError(
387
- (fallback == null ? void 0 : fallback.group) ?? "actor",
388
- (fallback == null ? void 0 : fallback.code) ?? INTERNAL_ERROR_CODE,
389
- errorMessage(error46, (fallback == null ? void 0 : fallback.message) ?? "Unknown error"),
390
- {
391
- public: fallback == null ? void 0 : fallback.public,
392
- statusCode: fallback == null ? void 0 : fallback.statusCode,
393
- metadata: fallback == null ? void 0 : fallback.metadata,
394
- actor: fallback == null ? void 0 : fallback.actor,
395
- cause: error46 instanceof Error ? error46 : void 0
396
- }
397
- );
398
- }
399
- function encodeBridgeRivetError(error46) {
400
- return `${BRIDGE_RIVET_ERROR_PREFIX}${JSON.stringify({
401
- group: error46.group,
402
- code: error46.code,
403
- message: error46.message,
404
- metadata: error46.metadata,
405
- public: error46.public,
406
- statusCode: error46.statusCode,
407
- actor: error46.actor
408
- })}`;
409
- }
410
- function decodeBridgeRivetErrorPayload(value) {
411
- if (!value.startsWith(BRIDGE_RIVET_ERROR_PREFIX)) {
412
- return void 0;
413
- }
414
- try {
415
- const payload = JSON.parse(
416
- value.slice(BRIDGE_RIVET_ERROR_PREFIX.length)
417
- );
418
- if (!isRivetErrorLike(payload)) {
419
- return void 0;
420
- }
421
- if (payload.actor !== void 0 && payload.actor !== null && !isActorSpecifier(payload.actor)) {
422
- return void 0;
423
- }
424
- return payload;
425
- } catch {
426
- return void 0;
427
- }
428
- }
429
- function decodeBridgeRivetError(value) {
430
- const payload = decodeBridgeRivetErrorPayload(value);
431
- if (!payload) {
432
- return void 0;
433
- }
434
- return new RivetError(payload.group, payload.code, payload.message, {
435
- metadata: payload.metadata,
436
- public: payload.public,
437
- statusCode: payload.statusCode,
438
- actor: payload.actor ?? void 0
439
- });
440
- }
441
- function invalidRequest(error46) {
442
- return new RivetError(
443
- "request",
444
- "invalid",
445
- `Invalid request: ${errorMessage(error46, String(error46))}`,
446
- {
447
- public: true,
448
- cause: error46 instanceof Error ? error46 : void 0
449
- }
450
- );
451
- }
452
- function actorNotFound(identifier) {
453
- return new RivetError(
454
- "actor",
455
- "not_found",
456
- identifier ? `Actor not found: ${identifier} (https://www.rivet.dev/docs/clients/javascript)` : "Actor not found (https://www.rivet.dev/docs/clients/javascript)",
457
- { public: true }
458
- );
459
- }
460
- function forbiddenError() {
461
- return new RivetError("auth", "forbidden", "Forbidden", {
462
- public: true,
463
- statusCode: 403
464
- });
465
- }
466
- function unsupportedFeature(feature) {
467
- return new RivetError(
468
- "feature",
469
- "unsupported",
470
- `Unsupported feature: ${feature}`
471
- );
472
- }
473
-
474
- // ../rivetkit/dist/tsup/chunk-6QL27Q5R.js
475
- import {
476
- pino,
477
- stdTimeFunctions
478
- } from "pino";
479
-
480
300
  // ../../../node_modules/.pnpm/zod@4.1.13/node_modules/zod/v4/classic/external.js
481
301
  var external_exports = {};
482
302
  __export(external_exports, {
@@ -13147,290 +12967,898 @@ var classic_default = external_exports;
13147
12967
  // ../../../node_modules/.pnpm/zod@4.1.13/node_modules/zod/v4/index.js
13148
12968
  var v4_default = classic_default;
13149
12969
 
13150
- // ../rivetkit/dist/tsup/chunk-6QL27Q5R.js
13151
- var import_invariant = __toESM(require_invariant(), 1);
13152
- import * as cbor from "cbor-x";
13153
- var getRivetEngine = () => getEnvUniversal("RIVET_ENGINE");
13154
- var getRivetEndpoint = () => getEnvUniversal("RIVET_ENDPOINT");
13155
- var getRivetToken = () => getEnvUniversal("RIVET_TOKEN");
13156
- var getRivetNamespace = () => getEnvUniversal("RIVET_NAMESPACE");
13157
- var getRivetPool = () => getEnvUniversal("RIVET_POOL");
13158
- var getRivetTotalSlots = () => {
13159
- const value = getEnvUniversal("RIVET_TOTAL_SLOTS");
13160
- return value !== void 0 ? parseInt(value, 10) : void 0;
13161
- };
13162
- var getRivetRunEngine = () => getEnvUniversal("RIVET_RUN_ENGINE") === "1";
13163
- var getRivetRunEngineHost = () => getEnvUniversal("RIVET_RUN_ENGINE_HOST");
13164
- var getRivetRunEnginePort = () => {
13165
- const value = getEnvUniversal("RIVET_RUN_ENGINE_PORT");
13166
- return value !== void 0 ? parseInt(value, 10) : void 0;
13167
- };
13168
- var getRivetRunEngineVersion = () => getEnvUniversal("RIVET_RUN_ENGINE_VERSION");
13169
- var getRivetEnvoyVersion = () => {
13170
- const value = getEnvUniversal("RIVET_ENVOY_VERSION");
13171
- return value !== void 0 ? parseInt(value, 10) : void 0;
13172
- };
13173
- var getRivetPublicEndpoint = () => getEnvUniversal("RIVET_PUBLIC_ENDPOINT");
13174
- var getRivetPublicToken = () => getEnvUniversal("RIVET_PUBLIC_TOKEN");
13175
- var getRivetkitRuntime = () => getEnvUniversal("RIVETKIT_RUNTIME");
13176
- var getRivetkitRuntimeMode = () => {
13177
- const value = getEnvUniversal("RIVETKIT_RUNTIME_MODE");
13178
- if (value === void 0) return "envoy";
13179
- if (value === "envoy" || value === "serverless") return value;
13180
- throw new Error(
13181
- `RIVETKIT_RUNTIME_MODE env var must be "envoy" or "serverless"; got "${value}"`
13182
- );
13183
- };
13184
- var getRivetkitPublicDir = () => {
13185
- const value = getEnvUniversal("RIVETKIT_PUBLIC_DIR");
13186
- return value === void 0 || value === "" ? void 0 : value;
13187
- };
13188
- function parsePortEnv(raw) {
13189
- if (raw === void 0 || raw === "") return void 0;
13190
- const parsed = Number.parseInt(raw, 10);
13191
- if (!Number.isFinite(parsed) || parsed < 1 || parsed > 65535 || String(parsed) !== raw.trim()) {
13192
- throw new Error(
13193
- `RIVET_PORT env var must be an integer between 1 and 65535; got "${raw}"`
13194
- );
12970
+ // ../rivetkit/dist/tsup/chunk-QWLJCP3X.js
12971
+ function flattenActionHandlers(actions) {
12972
+ const flattened = /* @__PURE__ */ Object.create(null);
12973
+ for (const { name, handler } of collectActionEntries(actions)) {
12974
+ flattened[name] = handler;
13195
12975
  }
13196
- return parsed;
13197
- }
13198
- var getLogLevel = () => getEnvUniversal("RIVET_LOG_LEVEL") ?? getEnvUniversal("LOG_LEVEL");
13199
- var getLogTarget = () => getEnvUniversal("RIVET_LOG_TARGET") === "1";
13200
- var getLogTimestamp = () => getEnvUniversal("RIVET_LOG_TIMESTAMP") === "1";
13201
- var getLogMessage = () => getEnvUniversal("RIVET_LOG_MESSAGE") === "1";
13202
- var getLogErrorStack = () => getEnvUniversal("RIVET_LOG_ERROR_STACK") === "1";
13203
- var getNodeEnv = () => getEnvUniversal("NODE_ENV");
13204
- var getNextPhase = () => getEnvUniversal("NEXT_PHASE");
13205
- var isDev = () => getNodeEnv() !== "production";
13206
- function assertUnreachable(x) {
13207
- throw new Error(`Unreachable case: ${x}`);
13208
- }
13209
- function isCanonicalStructuredRivetError(error46) {
13210
- 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";
12976
+ return flattened;
13211
12977
  }
13212
- function deconstructError(error46, exposeInternalError = false) {
13213
- let statusCode;
13214
- let public_;
13215
- let group;
13216
- let code;
13217
- let message;
13218
- let metadata;
13219
- let actor2;
13220
- if (isCanonicalStructuredRivetError(error46)) {
13221
- statusCode = typeof error46.statusCode === "number" ? error46.statusCode : error46.public ? 400 : 500;
13222
- public_ = error46.public ?? false;
13223
- group = error46.group;
13224
- code = error46.code;
13225
- message = error46.message;
13226
- metadata = error46.metadata;
13227
- actor2 = error46.actor;
13228
- } else if (RivetError.isActorError(error46) && error46.public) {
13229
- statusCode = "statusCode" in error46 && error46.statusCode ? error46.statusCode : 400;
13230
- public_ = true;
13231
- group = error46.group;
13232
- code = error46.code;
13233
- message = getErrorMessage(error46);
13234
- metadata = error46.metadata;
13235
- actor2 = error46.actor;
13236
- } else if (exposeInternalError) {
13237
- if (RivetError.isActorError(error46)) {
13238
- statusCode = 500;
13239
- public_ = false;
13240
- group = error46.group;
13241
- code = error46.code;
13242
- message = getErrorMessage(error46);
13243
- metadata = error46.metadata;
13244
- actor2 = error46.actor;
13245
- } else {
13246
- statusCode = 500;
13247
- public_ = false;
13248
- group = "rivetkit";
13249
- code = INTERNAL_ERROR_CODE;
13250
- message = getErrorMessage(error46);
12978
+ function flattenActionInputSchemas(actions, schemas) {
12979
+ if (schemas === void 0) return void 0;
12980
+ if (!isRecord(schemas)) {
12981
+ throw new TypeError("actionInputSchemas must be an object");
12982
+ }
12983
+ const flattened = /* @__PURE__ */ Object.create(null);
12984
+ for (const { name, path: path2 } of collectActionEntries(actions)) {
12985
+ const nestedSchema = lookupNestedSchema(schemas, path2);
12986
+ const flatSchema = schemas[name];
12987
+ if (nestedSchema !== void 0 && flatSchema !== void 0 && nestedSchema !== flatSchema) {
12988
+ throw new TypeError(
12989
+ `Action input schema \`${name}\` is defined by both a nested path and a dotted key`
12990
+ );
13251
12991
  }
13252
- } else {
13253
- statusCode = 500;
13254
- public_ = false;
13255
- group = "rivetkit";
13256
- code = INTERNAL_ERROR_CODE;
13257
- message = INTERNAL_ERROR_DESCRIPTION;
13258
- if (RivetError.isActorError(error46)) {
13259
- actor2 = error46.actor;
12992
+ const schema = nestedSchema ?? flatSchema;
12993
+ if (schema !== void 0) {
12994
+ flattened[name] = schema;
13260
12995
  }
13261
- metadata = {
13262
- //url: `https://dashboard.rivet.dev/projects/${actorMetadata.project.slug}/environments/${actorMetadata.environment.slug}/actors?actorId=${actorMetadata.actor.id}`,
13263
- };
13264
12996
  }
13265
- return {
13266
- __type: "ActorError",
13267
- statusCode,
13268
- public: public_,
13269
- group,
13270
- code,
13271
- message,
13272
- metadata,
13273
- actor: actor2
13274
- };
12997
+ return flattened;
13275
12998
  }
13276
- function stringifyError(error46) {
13277
- if (error46 instanceof Error) {
13278
- if (typeof process !== "undefined" && getLogErrorStack()) {
13279
- let stack;
13280
- try {
13281
- stack = error46.stack;
13282
- } catch {
13283
- stack = void 0;
12999
+ function collectActionEntries(actions) {
13000
+ const entries = [];
13001
+ const names = /* @__PURE__ */ new Set();
13002
+ visitActionGroup(actions ?? {}, [], entries, names);
13003
+ return entries;
13004
+ }
13005
+ function visitActionGroup(value, path2, entries, names) {
13006
+ if (!isRecord(value)) {
13007
+ throw new TypeError(
13008
+ `${formatActionPath(path2)} must be an action handler or group`
13009
+ );
13010
+ }
13011
+ for (const [segment, child] of Object.entries(value)) {
13012
+ const childPath = [...path2, segment];
13013
+ if (typeof child === "function") {
13014
+ const name = childPath.join(".");
13015
+ if (names.has(name)) {
13016
+ throw new TypeError(
13017
+ `Multiple action definitions flatten to \`${name}\``
13018
+ );
13284
13019
  }
13285
- return `${error46.name}: ${error46.message}${stack ? `
13286
- ${stack}` : ""}`;
13020
+ names.add(name);
13021
+ entries.push({
13022
+ name,
13023
+ path: childPath,
13024
+ handler: child
13025
+ });
13287
13026
  } else {
13288
- return `${error46.name}: ${error46.message}`;
13027
+ visitActionGroup(child, childPath, entries, names);
13289
13028
  }
13290
- } else if (typeof error46 === "string") {
13291
- return error46;
13292
- } else if (typeof error46 === "object" && error46 !== null) {
13293
- try {
13294
- return `${JSON.stringify(error46)}`;
13295
- } catch {
13296
- return "[cannot stringify error]";
13029
+ }
13030
+ }
13031
+ function lookupNestedSchema(schemas, path2) {
13032
+ let value = schemas;
13033
+ for (const segment of path2) {
13034
+ if (!isRecord(value) || !Object.hasOwn(value, segment)) {
13035
+ return void 0;
13297
13036
  }
13298
- } else {
13299
- return `Unknown error: ${getErrorMessage(error46)}`;
13037
+ value = value[segment];
13300
13038
  }
13039
+ return value;
13301
13040
  }
13302
- function getErrorMessage(err) {
13303
- if (err && typeof err === "object" && "message" in err && typeof err.message === "string") {
13304
- return err.message;
13305
- } else {
13306
- return String(err);
13041
+ function isRecord(value) {
13042
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
13043
+ return false;
13307
13044
  }
13045
+ const prototype = Object.getPrototypeOf(value);
13046
+ return prototype === Object.prototype || prototype === null;
13308
13047
  }
13309
- function noopNext() {
13310
- return async () => {
13311
- };
13048
+ function formatActionPath(path2) {
13049
+ return path2.length === 0 ? "actions" : `Action \`${path2.join(".")}\``;
13312
13050
  }
13313
- var package_default = {
13314
- name: "rivetkit",
13315
- version: "2.3.11-rc.5",
13316
- description: "Lightweight libraries for building stateful actors on edge platforms",
13317
- license: "Apache-2.0",
13318
- keywords: [
13319
- "rivetkit",
13320
- "stateful",
13321
- "serverless",
13322
- "actors",
13323
- "agents",
13324
- "realtime",
13325
- "websocket",
13326
- "actors",
13327
- "framework"
13328
- ],
13329
- files: [
13330
- "dist",
13331
- "schemas",
13332
- "src",
13333
- "package.json"
13334
- ],
13335
- type: "module",
13336
- exports: {
13337
- ".": {
13338
- import: {
13339
- types: "./dist/tsup/mod.d.ts",
13340
- default: "./dist/tsup/mod.js"
13341
- },
13342
- require: {
13343
- types: "./dist/tsup/mod.d.cts",
13344
- default: "./dist/tsup/mod.cjs"
13345
- }
13346
- },
13347
- "./workflow": {
13348
- import: {
13349
- types: "./dist/tsup/workflow/mod.d.ts",
13350
- default: "./dist/tsup/workflow/mod.js"
13351
- },
13352
- require: {
13353
- types: "./dist/tsup/workflow/mod.d.cts",
13354
- default: "./dist/tsup/workflow/mod.cjs"
13355
- }
13356
- },
13357
- "./test": {
13358
- import: {
13359
- types: "./dist/tsup/test/mod.d.ts",
13360
- default: "./dist/tsup/test/mod.js"
13361
- },
13362
- require: {
13363
- types: "./dist/tsup/test/mod.d.cts",
13364
- default: "./dist/tsup/test/mod.cjs"
13365
- }
13366
- },
13367
- "./db": {
13368
- import: {
13369
- types: "./dist/tsup/db/mod.d.ts",
13370
- default: "./dist/tsup/db/mod.js"
13371
- },
13372
- require: {
13373
- types: "./dist/tsup/db/mod.d.cts",
13374
- default: "./dist/tsup/db/mod.cjs"
13375
- }
13376
- },
13377
- "./db/drizzle": {
13378
- import: {
13379
- types: "./dist/tsup/db/drizzle.d.ts",
13380
- default: "./dist/tsup/db/drizzle.js"
13381
- },
13382
- require: {
13383
- types: "./dist/tsup/db/drizzle.d.cts",
13384
- default: "./dist/tsup/db/drizzle.cjs"
13385
- }
13386
- },
13387
- "./unstable/migrations": {
13388
- import: {
13389
- types: "./dist/tsup/unstable/migrations.d.ts",
13390
- default: "./dist/tsup/unstable/migrations.js"
13391
- },
13392
- require: {
13393
- types: "./dist/tsup/unstable/migrations.d.cts",
13394
- default: "./dist/tsup/unstable/migrations.cjs"
13395
- }
13396
- },
13397
- "./dynamic": {
13398
- import: {
13399
- types: "./dist/tsup/dynamic/mod.d.ts",
13400
- default: "./dist/tsup/dynamic/mod.js"
13401
- },
13402
- require: {
13403
- types: "./dist/tsup/dynamic/mod.d.cts",
13404
- default: "./dist/tsup/dynamic/mod.cjs"
13405
- }
13406
- },
13407
- "./client": {
13408
- import: {
13409
- browser: {
13410
- types: "./dist/browser/client.d.ts",
13411
- default: "./dist/browser/client.js"
13412
- },
13413
- types: "./dist/tsup/client/mod.d.ts",
13414
- default: "./dist/tsup/client/mod.js"
13415
- },
13416
- require: {
13417
- types: "./dist/tsup/client/mod.d.cts",
13418
- default: "./dist/tsup/client/mod.cjs"
13419
- }
13420
- },
13421
- "./log": {
13422
- import: {
13423
- types: "./dist/tsup/common/log.d.ts",
13424
- default: "./dist/tsup/common/log.js"
13425
- },
13426
- require: {
13427
- types: "./dist/tsup/common/log.d.cts",
13428
- default: "./dist/tsup/common/log.cjs"
13429
- }
13430
- },
13431
- "./errors": {
13432
- import: {
13433
- types: "./dist/tsup/actor/errors.d.ts",
13051
+ var DEFAULT_SLEEP_GRACE_PERIOD = 15e3;
13052
+ var ACTOR_CONTEXT_INTERNAL_SYMBOL = /* @__PURE__ */ Symbol(
13053
+ "rivetkit.actor_context_internal"
13054
+ );
13055
+ var RAW_STATE_SYMBOL = /* @__PURE__ */ Symbol("rivetkit.raw_state");
13056
+ var CONN_STATE_MANAGER_SYMBOL = /* @__PURE__ */ Symbol("rivetkit.conn_state_manager");
13057
+ var zFunction = () => external_exports.custom((val) => typeof val === "function");
13058
+ var zActionTree = external_exports.custom((value) => {
13059
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
13060
+ return false;
13061
+ }
13062
+ const prototype = Object.getPrototypeOf(value);
13063
+ return prototype === Object.prototype || prototype === null;
13064
+ }).superRefine((actions, ctx) => {
13065
+ try {
13066
+ flattenActionHandlers(actions);
13067
+ } catch (error46) {
13068
+ ctx.addIssue({
13069
+ code: "custom",
13070
+ message: error46 instanceof Error ? error46.message : "Invalid action definition"
13071
+ });
13072
+ }
13073
+ });
13074
+ var WorkflowInspectorConfigSchema = external_exports.object({
13075
+ getHistory: zFunction(),
13076
+ onHistoryUpdated: zFunction().optional(),
13077
+ replayFromStep: zFunction().optional()
13078
+ });
13079
+ var RunInspectorConfigSchema = external_exports.object({
13080
+ workflow: WorkflowInspectorConfigSchema.optional()
13081
+ }).optional();
13082
+ var BUILTIN_INSPECTOR_TAB_IDS = [
13083
+ "workflow",
13084
+ "database",
13085
+ "state",
13086
+ "queue",
13087
+ "schedules",
13088
+ "connections",
13089
+ "console"
13090
+ ];
13091
+ var BuiltinInspectorTabIdSchema = external_exports.enum(BUILTIN_INSPECTOR_TAB_IDS);
13092
+ var CUSTOM_INSPECTOR_TAB_ID_RE = /^[A-Za-z0-9_-]+$/;
13093
+ var CustomInspectorTabEntrySchema = external_exports.object({
13094
+ id: external_exports.string().regex(
13095
+ CUSTOM_INSPECTOR_TAB_ID_RE,
13096
+ "inspector.tabs[].id must contain only letters, digits, underscore, or dash"
13097
+ ),
13098
+ label: external_exports.string().min(1),
13099
+ source: external_exports.string().min(1),
13100
+ /**
13101
+ * Optional icon id. The dashboard maps strings to glyphs (see its
13102
+ * icon registry); unknown ids fall back to a generic icon.
13103
+ */
13104
+ icon: external_exports.string().min(1).optional(),
13105
+ hidden: external_exports.literal(false).optional()
13106
+ }).strict();
13107
+ var HideInspectorTabEntrySchema = external_exports.object({
13108
+ id: BuiltinInspectorTabIdSchema,
13109
+ hidden: external_exports.literal(true)
13110
+ }).strict();
13111
+ var InspectorTabEntrySchema = external_exports.union([
13112
+ CustomInspectorTabEntrySchema,
13113
+ HideInspectorTabEntrySchema
13114
+ ]);
13115
+ var ActorInspectorConfigSchema = external_exports.object({
13116
+ tabs: external_exports.array(InspectorTabEntrySchema).default(() => [])
13117
+ }).strict().refine(
13118
+ (data) => {
13119
+ const ids = data.tabs.map((t) => t.id);
13120
+ return new Set(ids).size === ids.length;
13121
+ },
13122
+ { message: "Duplicate id in inspector.tabs", path: ["tabs"] }
13123
+ ).refine(
13124
+ (data) => {
13125
+ const builtinSet = new Set(BUILTIN_INSPECTOR_TAB_IDS);
13126
+ return data.tabs.every(
13127
+ (t) => t.hidden === true || !builtinSet.has(t.id)
13128
+ );
13129
+ },
13130
+ {
13131
+ message: "Custom inspector tab id collides with a built-in (use hidden: true to hide a built-in)",
13132
+ path: ["tabs"]
13133
+ }
13134
+ );
13135
+ var RunConfigSchema = external_exports.object({
13136
+ /** Display name for the actor in the Inspector UI. */
13137
+ name: external_exports.string().optional(),
13138
+ /** Icon for the actor in the Inspector UI. Can be an emoji or FontAwesome icon name. */
13139
+ icon: external_exports.string().optional(),
13140
+ /** The run handler function. */
13141
+ run: zFunction(),
13142
+ /** Inspector integration for long-running run handlers. */
13143
+ inspector: RunInspectorConfigSchema.optional()
13144
+ });
13145
+ var RUN_FUNCTION_CONFIG_SYMBOL = /* @__PURE__ */ Symbol.for(
13146
+ "rivetkit.run_function_config"
13147
+ );
13148
+ var zRunHandler = external_exports.union([zFunction(), RunConfigSchema]).optional();
13149
+ function getRunFunction(run) {
13150
+ if (!run) return void 0;
13151
+ if (typeof run === "function") return run;
13152
+ return run.run;
13153
+ }
13154
+ function getRunMetadata(run) {
13155
+ if (!run) return {};
13156
+ if (typeof run === "function") {
13157
+ const config3 = run[RUN_FUNCTION_CONFIG_SYMBOL];
13158
+ if (!config3) return {};
13159
+ return { name: config3.name, icon: config3.icon };
13160
+ }
13161
+ return { name: run.name, icon: run.icon };
13162
+ }
13163
+ function getRunInspectorConfig(run, actor2) {
13164
+ if (!run) return void 0;
13165
+ if (typeof run === "function") {
13166
+ const config3 = run[RUN_FUNCTION_CONFIG_SYMBOL];
13167
+ return (config3 == null ? void 0 : config3.inspectorFactory) ? config3.inspectorFactory(actor2) : config3 == null ? void 0 : config3.inspector;
13168
+ }
13169
+ return run.inspector;
13170
+ }
13171
+ function disposeRunInspector(run, actorId) {
13172
+ var _a2;
13173
+ if (!run || typeof run !== "function") {
13174
+ return;
13175
+ }
13176
+ const config3 = run[RUN_FUNCTION_CONFIG_SYMBOL];
13177
+ (_a2 = config3 == null ? void 0 : config3.disposeInspector) == null ? void 0 : _a2.call(config3, actorId);
13178
+ }
13179
+ var GlobalActorOptionsBaseSchema = external_exports.object({
13180
+ /** Display name for the actor in the Inspector UI. */
13181
+ name: external_exports.string().optional(),
13182
+ /** Icon for the actor in the Inspector UI. Can be an emoji or FontAwesome icon name. */
13183
+ icon: external_exports.string().optional(),
13184
+ /** Enables the experimental Actor Runtime Socket for this actor. */
13185
+ enableActorRuntimeSocket: external_exports.boolean().default(false),
13186
+ /**
13187
+ * Can hibernate WebSockets for onWebSocket.
13188
+ *
13189
+ * WebSockets using actions/events are hibernatable by default.
13190
+ *
13191
+ * @experimental
13192
+ **/
13193
+ canHibernateWebSocket: external_exports.union([external_exports.boolean(), zFunction()]).default(false)
13194
+ }).strict();
13195
+ var GlobalActorOptionsSchema = GlobalActorOptionsBaseSchema.prefault(
13196
+ () => ({})
13197
+ );
13198
+ var InstanceActorOptionsBaseSchema = external_exports.object({
13199
+ createVarsTimeout: external_exports.number().positive().default(5e3),
13200
+ createConnStateTimeout: external_exports.number().positive().default(5e3),
13201
+ onBeforeConnectTimeout: external_exports.number().positive().default(5e3),
13202
+ onConnectTimeout: external_exports.number().positive().default(5e3),
13203
+ onMigrateTimeout: external_exports.number().positive().default(3e4),
13204
+ sleepGracePeriod: external_exports.number().positive().default(DEFAULT_SLEEP_GRACE_PERIOD),
13205
+ /** @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. */
13206
+ onDestroyTimeout: external_exports.number().positive().optional(),
13207
+ /** @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. */
13208
+ waitUntilTimeout: external_exports.number().positive().optional(),
13209
+ stateSaveInterval: external_exports.number().positive().default(1e3),
13210
+ actionTimeout: external_exports.number().positive().default(6e4),
13211
+ connectionLivenessTimeout: external_exports.number().positive().default(2500),
13212
+ connectionLivenessInterval: external_exports.number().positive().default(5e3),
13213
+ /** @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. */
13214
+ noSleep: external_exports.boolean().default(false),
13215
+ sleepTimeout: external_exports.number().positive().default(3e4),
13216
+ maxQueueSize: external_exports.number().positive().default(1e3),
13217
+ /** Maximum pending one-shot and recurring schedules. */
13218
+ maxSchedules: external_exports.number().int().nonnegative().default(1e3),
13219
+ maxQueueMessageSize: external_exports.number().positive().default(64 * 1024),
13220
+ /** @deprecated Internal storage moved to SQLite and no longer uses KV preloading, so this option is ignored. Will be removed in 2.2.0. */
13221
+ preloadMaxWorkflowBytes: external_exports.number().nonnegative().optional(),
13222
+ /** @deprecated Internal storage moved to SQLite and no longer uses KV preloading, so this option is ignored. Will be removed in 2.2.0. */
13223
+ preloadMaxConnectionsBytes: external_exports.number().nonnegative().optional()
13224
+ }).strict();
13225
+ var InstanceActorOptionsSchema = InstanceActorOptionsBaseSchema.prefault(() => ({}));
13226
+ var ActorOptionsSchema = GlobalActorOptionsBaseSchema.extend(
13227
+ InstanceActorOptionsBaseSchema.shape
13228
+ ).strict().prefault(() => ({}));
13229
+ var ActorConfigSchema = external_exports.object({
13230
+ onCreate: zFunction().optional(),
13231
+ onDestroy: zFunction().optional(),
13232
+ onMigrate: zFunction().optional(),
13233
+ onWake: zFunction().optional(),
13234
+ onSleep: zFunction().optional(),
13235
+ run: zRunHandler,
13236
+ onStateChange: zFunction().optional(),
13237
+ onBeforeConnect: zFunction().optional(),
13238
+ onConnect: zFunction().optional(),
13239
+ onDisconnect: zFunction().optional(),
13240
+ onBeforeActionResponse: zFunction().optional(),
13241
+ onRequest: zFunction().optional(),
13242
+ onWebSocket: zFunction().optional(),
13243
+ actions: zActionTree.default(() => ({})),
13244
+ actionInputSchemas: external_exports.record(external_exports.string(), external_exports.any()).optional(),
13245
+ connParamsSchema: external_exports.any().optional(),
13246
+ events: external_exports.record(external_exports.string(), external_exports.any()).optional(),
13247
+ queues: external_exports.record(external_exports.string(), external_exports.any()).optional(),
13248
+ state: external_exports.any().optional(),
13249
+ createState: zFunction().optional(),
13250
+ connState: external_exports.any().optional(),
13251
+ createConnState: zFunction().optional(),
13252
+ vars: external_exports.any().optional(),
13253
+ db: external_exports.any().optional(),
13254
+ createVars: zFunction().optional(),
13255
+ options: ActorOptionsSchema,
13256
+ inspector: ActorInspectorConfigSchema.optional()
13257
+ }).strict().refine(
13258
+ (data) => !(data.state !== void 0 && data.createState !== void 0),
13259
+ {
13260
+ message: "Cannot define both 'state' and 'createState'",
13261
+ path: ["state"]
13262
+ }
13263
+ ).refine(
13264
+ (data) => !(data.connState !== void 0 && data.createConnState !== void 0),
13265
+ {
13266
+ message: "Cannot define both 'connState' and 'createConnState'",
13267
+ path: ["connState"]
13268
+ }
13269
+ ).refine(
13270
+ (data) => !(data.vars !== void 0 && data.createVars !== void 0),
13271
+ {
13272
+ message: "Cannot define both 'vars' and 'createVars'",
13273
+ path: ["vars"]
13274
+ }
13275
+ );
13276
+ var DocActorOptionsSchema = external_exports.object({
13277
+ name: external_exports.string().optional().describe("Display name for the actor in the Inspector UI."),
13278
+ icon: external_exports.string().optional().describe(
13279
+ "Icon for the actor in the Inspector UI. Can be an emoji (e.g., '\u{1F680}') or FontAwesome icon name (e.g., 'rocket')."
13280
+ ),
13281
+ enableActorRuntimeSocket: external_exports.boolean().optional().describe(
13282
+ "Enables the experimental Actor Runtime Socket for this actor. Default: false"
13283
+ ),
13284
+ createVarsTimeout: external_exports.number().optional().describe("Timeout in ms for createVars handler. Default: 5000"),
13285
+ createConnStateTimeout: external_exports.number().optional().describe(
13286
+ "Timeout in ms for createConnState handler. Default: 5000"
13287
+ ),
13288
+ onMigrateTimeout: external_exports.number().optional().describe("Timeout in ms for onMigrate handler. Default: 30000"),
13289
+ onBeforeConnectTimeout: external_exports.number().optional().describe(
13290
+ "Timeout in ms for onBeforeConnect handler. Default: 5000"
13291
+ ),
13292
+ onConnectTimeout: external_exports.number().optional().describe("Timeout in ms for onConnect handler. Default: 5000"),
13293
+ sleepGracePeriod: external_exports.number().optional().describe(
13294
+ `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}.`
13295
+ ),
13296
+ onDestroyTimeout: external_exports.number().optional().describe(
13297
+ "Deprecated. Folded into sleepGracePeriod, which now bounds the entire graceful shutdown window for both sleep and destroy. Will be removed in 2.2.0."
13298
+ ),
13299
+ waitUntilTimeout: external_exports.number().optional().describe(
13300
+ "Deprecated. Folded into sleepGracePeriod, which now bounds the entire graceful shutdown window for both sleep and destroy. Will be removed in 2.2.0."
13301
+ ),
13302
+ stateSaveInterval: external_exports.number().optional().describe(
13303
+ "Interval in ms between automatic state saves. Default: 1000"
13304
+ ),
13305
+ actionTimeout: external_exports.number().optional().describe("Timeout in ms for action handlers. Default: 60000"),
13306
+ connectionLivenessTimeout: external_exports.number().optional().describe(
13307
+ "Timeout in ms for connection liveness checks. Default: 2500"
13308
+ ),
13309
+ connectionLivenessInterval: external_exports.number().optional().describe(
13310
+ "Interval in ms between connection liveness checks. Default: 5000"
13311
+ ),
13312
+ noSleep: external_exports.boolean().optional().describe(
13313
+ "Deprecated. If true, the actor will never sleep. Use c.keepAwake(promise) to scope keep-awake to a specific operation instead. Default: false"
13314
+ ),
13315
+ sleepTimeout: external_exports.number().optional().describe(
13316
+ "Time in ms of inactivity before the actor sleeps. Default: 30000"
13317
+ ),
13318
+ maxQueueSize: external_exports.number().optional().describe(
13319
+ "Maximum number of queue messages before rejecting new messages. Default: 1000"
13320
+ ),
13321
+ maxSchedules: external_exports.number().int().nonnegative().optional().describe(
13322
+ "Maximum pending one-shot and recurring schedules before rejecting new schedules. Default: 1000"
13323
+ ),
13324
+ maxQueueMessageSize: external_exports.number().optional().describe(
13325
+ "Maximum size of each queue message in bytes. Default: 65536"
13326
+ ),
13327
+ canHibernateWebSocket: external_exports.boolean().optional().describe(
13328
+ "Whether WebSockets using onWebSocket can be hibernated. WebSockets using actions/events are hibernatable by default. Default: false"
13329
+ )
13330
+ }).describe("Actor options for timeouts and behavior configuration.");
13331
+ var DocActorConfigSchema = external_exports.object({
13332
+ state: external_exports.unknown().optional().describe(
13333
+ "Initial state value for the actor. Cannot be used with createState."
13334
+ ),
13335
+ createState: external_exports.unknown().optional().describe(
13336
+ "Function to create initial state. Receives context and input. Cannot be used with state."
13337
+ ),
13338
+ connState: external_exports.unknown().optional().describe(
13339
+ "Initial connection state value. Cannot be used with createConnState."
13340
+ ),
13341
+ createConnState: external_exports.unknown().optional().describe(
13342
+ "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."
13343
+ ),
13344
+ vars: external_exports.unknown().optional().describe(
13345
+ "Initial ephemeral variables value. Cannot be used with createVars."
13346
+ ),
13347
+ createVars: external_exports.unknown().optional().describe(
13348
+ "Function to create ephemeral variables. Receives context and driver context. Cannot be used with vars."
13349
+ ),
13350
+ db: external_exports.unknown().optional().describe("Database provider instance for the actor."),
13351
+ onCreate: external_exports.unknown().optional().describe(
13352
+ "Called when the actor is first initialized. Use to initialize state."
13353
+ ),
13354
+ onDestroy: external_exports.unknown().optional().describe("Called when the actor is destroyed."),
13355
+ onMigrate: external_exports.unknown().optional().describe(
13356
+ "Called on every actor start after persisted state loads and before onWake. Use for repeatable schema migrations."
13357
+ ),
13358
+ onWake: external_exports.unknown().optional().describe(
13359
+ "Called when the actor wakes up and is ready to receive connections and actions."
13360
+ ),
13361
+ onSleep: external_exports.unknown().optional().describe(
13362
+ "Called when the actor is stopping or sleeping. Use to clean up resources."
13363
+ ),
13364
+ run: external_exports.unknown().optional().describe(
13365
+ "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."
13366
+ ),
13367
+ onStateChange: external_exports.unknown().optional().describe(
13368
+ "Called when the actor's state changes. State changes within this hook won't trigger recursion."
13369
+ ),
13370
+ onBeforeConnect: external_exports.unknown().optional().describe(
13371
+ "Called before a client connects. Throw an error to reject the connection. The pending connection is not visible in c.conns while this runs."
13372
+ ),
13373
+ onConnect: external_exports.unknown().optional().describe(
13374
+ "Called when a client successfully connects. The connection is visible in c.conns before this runs."
13375
+ ),
13376
+ onDisconnect: external_exports.unknown().optional().describe("Called when a client disconnects."),
13377
+ onBeforeActionResponse: external_exports.unknown().optional().describe(
13378
+ "Called before sending an action response. Use to transform output."
13379
+ ),
13380
+ onRequest: external_exports.unknown().optional().describe(
13381
+ "Called for raw HTTP requests to /actors/{name}/http/* endpoints."
13382
+ ),
13383
+ onWebSocket: external_exports.unknown().optional().describe(
13384
+ "Called for raw WebSocket connections to /actors/{name}/websocket/* endpoints."
13385
+ ),
13386
+ actions: external_exports.record(external_exports.string(), external_exports.unknown()).optional().describe(
13387
+ "Tree of action names or nested groups to handler functions. Nested paths use dot-separated low-level action names. Defaults to an empty object."
13388
+ ),
13389
+ actionInputSchemas: external_exports.record(external_exports.string(), external_exports.unknown()).optional().describe(
13390
+ "Optional schemas for validating action argument tuples in native runtimes. May mirror nested action groups or use dot-separated low-level action names."
13391
+ ),
13392
+ connParamsSchema: external_exports.unknown().optional().describe(
13393
+ "Optional schema for validating connection params in native runtimes."
13394
+ ),
13395
+ events: external_exports.record(external_exports.string(), external_exports.unknown()).optional().describe("Map of event names to schemas."),
13396
+ queues: external_exports.record(external_exports.string(), external_exports.unknown()).optional().describe("Map of queue names to schemas."),
13397
+ options: DocActorOptionsSchema.optional()
13398
+ }).describe("Actor configuration passed to the actor() function.");
13399
+
13400
+ // ../rivetkit/dist/tsup/chunk-ZZ3WBRPD.js
13401
+ var INTERNAL_ERROR_CODE = "internal_error";
13402
+ var INTERNAL_ERROR_DESCRIPTION = "An internal error occurred";
13403
+ var USER_ERROR_CODE = "user_error";
13404
+ var BRIDGE_RIVET_ERROR_PREFIX = "__RIVET_ERROR_JSON__:";
13405
+ function looksLikeRivetErrorOptions(value) {
13406
+ return typeof value === "object" && value !== null && ("public" in value || "metadata" in value || "statusCode" in value || "actor" in value || "cause" in value);
13407
+ }
13408
+ function isTypedErrorTag(value) {
13409
+ return value === "ActorError" || value === "RivetError";
13410
+ }
13411
+ function errorMessage(error46, fallback = String(error46)) {
13412
+ if (error46 && typeof error46 === "object" && "message" in error46 && typeof error46.message === "string") {
13413
+ return error46.message;
13414
+ }
13415
+ return fallback;
13416
+ }
13417
+ function isRivetErrorLike(error46) {
13418
+ 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" && (!("__type" in error46) || isTypedErrorTag(error46.__type));
13419
+ }
13420
+ function isActorAbortedError(error46) {
13421
+ return isRivetErrorLike(error46) && error46.group === "actor" && error46.code === "aborted";
13422
+ }
13423
+ function isActorSpecifier(value) {
13424
+ 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");
13425
+ }
13426
+ var RivetError = class extends Error {
13427
+ __type = "RivetError";
13428
+ public;
13429
+ metadata;
13430
+ statusCode;
13431
+ actor;
13432
+ group;
13433
+ code;
13434
+ static isRivetError(error46) {
13435
+ return isRivetErrorLike(error46);
13436
+ }
13437
+ static isActorError(error46) {
13438
+ return isRivetErrorLike(error46);
13439
+ }
13440
+ constructor(group, code, message, options) {
13441
+ const normalized = looksLikeRivetErrorOptions(options) ? options : { metadata: options };
13442
+ super(message, { cause: normalized.cause });
13443
+ this.name = "RivetError";
13444
+ this.group = group;
13445
+ this.code = code;
13446
+ this.public = normalized.public ?? false;
13447
+ this.metadata = normalized.metadata;
13448
+ this.statusCode = normalized.statusCode ?? (this.public ? 400 : 500);
13449
+ this.actor = normalized.actor;
13450
+ }
13451
+ toString() {
13452
+ return this.message;
13453
+ }
13454
+ };
13455
+ var UserError = class extends RivetError {
13456
+ constructor(message, options) {
13457
+ super("user", (options == null ? void 0 : options.code) ?? USER_ERROR_CODE, message, {
13458
+ public: true,
13459
+ metadata: options == null ? void 0 : options.metadata,
13460
+ cause: options == null ? void 0 : options.cause
13461
+ });
13462
+ }
13463
+ };
13464
+ function toRivetError(error46, fallback) {
13465
+ if (typeof error46 === "string") {
13466
+ const bridged = decodeBridgeRivetError(error46);
13467
+ if (bridged) {
13468
+ return bridged;
13469
+ }
13470
+ }
13471
+ if (error46 instanceof Error) {
13472
+ const bridged = decodeBridgeRivetError(error46.message);
13473
+ if (bridged) {
13474
+ return bridged;
13475
+ }
13476
+ }
13477
+ if (isRivetErrorLike(error46)) {
13478
+ return new RivetError(error46.group, error46.code, error46.message, {
13479
+ public: error46.public,
13480
+ statusCode: error46.statusCode,
13481
+ metadata: error46.metadata,
13482
+ actor: error46.actor,
13483
+ cause: error46 instanceof Error ? error46.cause : void 0
13484
+ });
13485
+ }
13486
+ return new RivetError(
13487
+ (fallback == null ? void 0 : fallback.group) ?? "actor",
13488
+ (fallback == null ? void 0 : fallback.code) ?? INTERNAL_ERROR_CODE,
13489
+ errorMessage(error46, (fallback == null ? void 0 : fallback.message) ?? "Unknown error"),
13490
+ {
13491
+ public: fallback == null ? void 0 : fallback.public,
13492
+ statusCode: fallback == null ? void 0 : fallback.statusCode,
13493
+ metadata: fallback == null ? void 0 : fallback.metadata,
13494
+ actor: fallback == null ? void 0 : fallback.actor,
13495
+ cause: error46 instanceof Error ? error46 : void 0
13496
+ }
13497
+ );
13498
+ }
13499
+ function encodeBridgeRivetError(error46) {
13500
+ return `${BRIDGE_RIVET_ERROR_PREFIX}${JSON.stringify({
13501
+ group: error46.group,
13502
+ code: error46.code,
13503
+ message: error46.message,
13504
+ metadata: error46.metadata,
13505
+ public: error46.public,
13506
+ statusCode: error46.statusCode,
13507
+ actor: error46.actor
13508
+ })}`;
13509
+ }
13510
+ function decodeBridgeRivetErrorPayload(value) {
13511
+ if (!value.startsWith(BRIDGE_RIVET_ERROR_PREFIX)) {
13512
+ return void 0;
13513
+ }
13514
+ try {
13515
+ const payload = JSON.parse(
13516
+ value.slice(BRIDGE_RIVET_ERROR_PREFIX.length)
13517
+ );
13518
+ if (!isRivetErrorLike(payload)) {
13519
+ return void 0;
13520
+ }
13521
+ if (payload.actor !== void 0 && payload.actor !== null && !isActorSpecifier(payload.actor)) {
13522
+ return void 0;
13523
+ }
13524
+ return payload;
13525
+ } catch {
13526
+ return void 0;
13527
+ }
13528
+ }
13529
+ function decodeBridgeRivetError(value) {
13530
+ const payload = decodeBridgeRivetErrorPayload(value);
13531
+ if (!payload) {
13532
+ return void 0;
13533
+ }
13534
+ return new RivetError(payload.group, payload.code, payload.message, {
13535
+ metadata: payload.metadata,
13536
+ public: payload.public,
13537
+ statusCode: payload.statusCode,
13538
+ actor: payload.actor ?? void 0
13539
+ });
13540
+ }
13541
+ function invalidRequest(error46) {
13542
+ return new RivetError(
13543
+ "request",
13544
+ "invalid",
13545
+ `Invalid request: ${errorMessage(error46, String(error46))}`,
13546
+ {
13547
+ public: true,
13548
+ cause: error46 instanceof Error ? error46 : void 0
13549
+ }
13550
+ );
13551
+ }
13552
+ function actorNotFound(identifier) {
13553
+ return new RivetError(
13554
+ "actor",
13555
+ "not_found",
13556
+ identifier ? `Actor not found: ${identifier} (https://www.rivet.dev/docs/clients/javascript)` : "Actor not found (https://www.rivet.dev/docs/clients/javascript)",
13557
+ { public: true }
13558
+ );
13559
+ }
13560
+ function forbiddenError() {
13561
+ return new RivetError("auth", "forbidden", "Forbidden", {
13562
+ public: true,
13563
+ statusCode: 403
13564
+ });
13565
+ }
13566
+ function unsupportedFeature(feature) {
13567
+ return new RivetError(
13568
+ "feature",
13569
+ "unsupported",
13570
+ `Unsupported feature: ${feature}`
13571
+ );
13572
+ }
13573
+
13574
+ // ../rivetkit/dist/tsup/chunk-XAGDGH4O.js
13575
+ import {
13576
+ pino,
13577
+ stdTimeFunctions
13578
+ } from "pino";
13579
+ var import_invariant = __toESM(require_invariant(), 1);
13580
+ import * as cbor from "cbor-x";
13581
+ var getRivetEngine = () => getEnvUniversal("RIVET_ENGINE");
13582
+ var getRivetEndpoint = () => getEnvUniversal("RIVET_ENDPOINT");
13583
+ var getRivetToken = () => getEnvUniversal("RIVET_TOKEN");
13584
+ var getRivetNamespace = () => getEnvUniversal("RIVET_NAMESPACE");
13585
+ var getRivetPool = () => getEnvUniversal("RIVET_POOL");
13586
+ var getRivetTotalSlots = () => {
13587
+ const value = getEnvUniversal("RIVET_TOTAL_SLOTS");
13588
+ return value !== void 0 ? parseInt(value, 10) : void 0;
13589
+ };
13590
+ var getRivetRunEngine = () => getEnvUniversal("RIVET_RUN_ENGINE") === "1";
13591
+ var getRivetRunEngineHost = () => getEnvUniversal("RIVET_RUN_ENGINE_HOST");
13592
+ var getRivetRunEnginePort = () => {
13593
+ const value = getEnvUniversal("RIVET_RUN_ENGINE_PORT");
13594
+ return value !== void 0 ? parseInt(value, 10) : void 0;
13595
+ };
13596
+ var getRivetRunEngineVersion = () => getEnvUniversal("RIVET_RUN_ENGINE_VERSION");
13597
+ var getRivetEnvoyVersion = () => {
13598
+ const value = getEnvUniversal("RIVET_ENVOY_VERSION");
13599
+ return value !== void 0 ? parseInt(value, 10) : void 0;
13600
+ };
13601
+ var getRivetPublicEndpoint = () => getEnvUniversal("RIVET_PUBLIC_ENDPOINT");
13602
+ var getRivetPublicToken = () => getEnvUniversal("RIVET_PUBLIC_TOKEN");
13603
+ var getRivetkitRuntime = () => getEnvUniversal("RIVETKIT_RUNTIME");
13604
+ var getRivetkitRuntimeMode = () => {
13605
+ const value = getEnvUniversal("RIVETKIT_RUNTIME_MODE");
13606
+ if (value === void 0) return "envoy";
13607
+ if (value === "envoy" || value === "serverless") return value;
13608
+ throw new Error(
13609
+ `RIVETKIT_RUNTIME_MODE env var must be "envoy" or "serverless"; got "${value}"`
13610
+ );
13611
+ };
13612
+ var getRivetkitPublicDir = () => {
13613
+ const value = getEnvUniversal("RIVETKIT_PUBLIC_DIR");
13614
+ return value === void 0 || value === "" ? void 0 : value;
13615
+ };
13616
+ function parsePortEnv(raw) {
13617
+ if (raw === void 0 || raw === "") return void 0;
13618
+ const parsed = Number.parseInt(raw, 10);
13619
+ if (!Number.isFinite(parsed) || parsed < 1 || parsed > 65535 || String(parsed) !== raw.trim()) {
13620
+ throw new Error(
13621
+ `RIVET_PORT env var must be an integer between 1 and 65535; got "${raw}"`
13622
+ );
13623
+ }
13624
+ return parsed;
13625
+ }
13626
+ var getLogLevel = () => getEnvUniversal("RIVET_LOG_LEVEL") ?? getEnvUniversal("LOG_LEVEL");
13627
+ var getLogTarget = () => getEnvUniversal("RIVET_LOG_TARGET") === "1";
13628
+ var getLogTimestamp = () => getEnvUniversal("RIVET_LOG_TIMESTAMP") === "1";
13629
+ var getLogMessage = () => getEnvUniversal("RIVET_LOG_MESSAGE") === "1";
13630
+ var getLogErrorStack = () => getEnvUniversal("RIVET_LOG_ERROR_STACK") === "1";
13631
+ var getNodeEnv = () => getEnvUniversal("NODE_ENV");
13632
+ var getNextPhase = () => getEnvUniversal("NEXT_PHASE");
13633
+ var isDev = () => getNodeEnv() !== "production";
13634
+ function assertUnreachable(x) {
13635
+ throw new Error(`Unreachable case: ${x}`);
13636
+ }
13637
+ function isCanonicalStructuredRivetError(error46) {
13638
+ 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";
13639
+ }
13640
+ function deconstructError(error46, exposeInternalError = false) {
13641
+ let statusCode;
13642
+ let public_;
13643
+ let group;
13644
+ let code;
13645
+ let message;
13646
+ let metadata;
13647
+ let actor2;
13648
+ if (isCanonicalStructuredRivetError(error46)) {
13649
+ statusCode = typeof error46.statusCode === "number" ? error46.statusCode : error46.public ? 400 : 500;
13650
+ public_ = error46.public ?? false;
13651
+ group = error46.group;
13652
+ code = error46.code;
13653
+ message = error46.message;
13654
+ metadata = error46.metadata;
13655
+ actor2 = error46.actor;
13656
+ } else if (RivetError.isActorError(error46) && error46.public) {
13657
+ statusCode = "statusCode" in error46 && error46.statusCode ? error46.statusCode : 400;
13658
+ public_ = true;
13659
+ group = error46.group;
13660
+ code = error46.code;
13661
+ message = getErrorMessage(error46);
13662
+ metadata = error46.metadata;
13663
+ actor2 = error46.actor;
13664
+ } else if (exposeInternalError) {
13665
+ if (RivetError.isActorError(error46)) {
13666
+ statusCode = 500;
13667
+ public_ = false;
13668
+ group = error46.group;
13669
+ code = error46.code;
13670
+ message = getErrorMessage(error46);
13671
+ metadata = error46.metadata;
13672
+ actor2 = error46.actor;
13673
+ } else {
13674
+ statusCode = 500;
13675
+ public_ = false;
13676
+ group = "rivetkit";
13677
+ code = INTERNAL_ERROR_CODE;
13678
+ message = getErrorMessage(error46);
13679
+ }
13680
+ } else {
13681
+ statusCode = 500;
13682
+ public_ = false;
13683
+ group = "rivetkit";
13684
+ code = INTERNAL_ERROR_CODE;
13685
+ message = INTERNAL_ERROR_DESCRIPTION;
13686
+ if (RivetError.isActorError(error46)) {
13687
+ actor2 = error46.actor;
13688
+ }
13689
+ metadata = {
13690
+ //url: `https://dashboard.rivet.dev/projects/${actorMetadata.project.slug}/environments/${actorMetadata.environment.slug}/actors?actorId=${actorMetadata.actor.id}`,
13691
+ };
13692
+ }
13693
+ return {
13694
+ __type: "ActorError",
13695
+ statusCode,
13696
+ public: public_,
13697
+ group,
13698
+ code,
13699
+ message,
13700
+ metadata,
13701
+ actor: actor2
13702
+ };
13703
+ }
13704
+ function stringifyError(error46) {
13705
+ if (error46 instanceof Error) {
13706
+ if (typeof process !== "undefined" && getLogErrorStack()) {
13707
+ let stack;
13708
+ try {
13709
+ stack = error46.stack;
13710
+ } catch {
13711
+ stack = void 0;
13712
+ }
13713
+ return `${error46.name}: ${error46.message}${stack ? `
13714
+ ${stack}` : ""}`;
13715
+ } else {
13716
+ return `${error46.name}: ${error46.message}`;
13717
+ }
13718
+ } else if (typeof error46 === "string") {
13719
+ return error46;
13720
+ } else if (typeof error46 === "object" && error46 !== null) {
13721
+ try {
13722
+ return `${JSON.stringify(error46)}`;
13723
+ } catch {
13724
+ return "[cannot stringify error]";
13725
+ }
13726
+ } else {
13727
+ return `Unknown error: ${getErrorMessage(error46)}`;
13728
+ }
13729
+ }
13730
+ function getErrorMessage(err) {
13731
+ if (err && typeof err === "object" && "message" in err && typeof err.message === "string") {
13732
+ return err.message;
13733
+ } else {
13734
+ return String(err);
13735
+ }
13736
+ }
13737
+ function noopNext() {
13738
+ return async () => {
13739
+ };
13740
+ }
13741
+ var package_default = {
13742
+ name: "rivetkit",
13743
+ version: "2.3.11-rc.7",
13744
+ description: "Lightweight libraries for building stateful actors on edge platforms",
13745
+ license: "Apache-2.0",
13746
+ keywords: [
13747
+ "rivetkit",
13748
+ "stateful",
13749
+ "serverless",
13750
+ "actors",
13751
+ "agents",
13752
+ "realtime",
13753
+ "websocket",
13754
+ "actors",
13755
+ "framework"
13756
+ ],
13757
+ files: [
13758
+ "dist",
13759
+ "schemas",
13760
+ "src",
13761
+ "package.json"
13762
+ ],
13763
+ type: "module",
13764
+ exports: {
13765
+ ".": {
13766
+ import: {
13767
+ types: "./dist/tsup/mod.d.ts",
13768
+ default: "./dist/tsup/mod.js"
13769
+ },
13770
+ require: {
13771
+ types: "./dist/tsup/mod.d.cts",
13772
+ default: "./dist/tsup/mod.cjs"
13773
+ }
13774
+ },
13775
+ "./workflow": {
13776
+ import: {
13777
+ types: "./dist/tsup/workflow/mod.d.ts",
13778
+ default: "./dist/tsup/workflow/mod.js"
13779
+ },
13780
+ require: {
13781
+ types: "./dist/tsup/workflow/mod.d.cts",
13782
+ default: "./dist/tsup/workflow/mod.cjs"
13783
+ }
13784
+ },
13785
+ "./test": {
13786
+ import: {
13787
+ types: "./dist/tsup/test/mod.d.ts",
13788
+ default: "./dist/tsup/test/mod.js"
13789
+ },
13790
+ require: {
13791
+ types: "./dist/tsup/test/mod.d.cts",
13792
+ default: "./dist/tsup/test/mod.cjs"
13793
+ }
13794
+ },
13795
+ "./db": {
13796
+ import: {
13797
+ types: "./dist/tsup/db/mod.d.ts",
13798
+ default: "./dist/tsup/db/mod.js"
13799
+ },
13800
+ require: {
13801
+ types: "./dist/tsup/db/mod.d.cts",
13802
+ default: "./dist/tsup/db/mod.cjs"
13803
+ }
13804
+ },
13805
+ "./db/drizzle": {
13806
+ import: {
13807
+ types: "./dist/tsup/db/drizzle.d.ts",
13808
+ default: "./dist/tsup/db/drizzle.js"
13809
+ },
13810
+ require: {
13811
+ types: "./dist/tsup/db/drizzle.d.cts",
13812
+ default: "./dist/tsup/db/drizzle.cjs"
13813
+ }
13814
+ },
13815
+ "./unstable/migrations": {
13816
+ import: {
13817
+ types: "./dist/tsup/unstable/migrations.d.ts",
13818
+ default: "./dist/tsup/unstable/migrations.js"
13819
+ },
13820
+ require: {
13821
+ types: "./dist/tsup/unstable/migrations.d.cts",
13822
+ default: "./dist/tsup/unstable/migrations.cjs"
13823
+ }
13824
+ },
13825
+ "./dynamic": {
13826
+ import: {
13827
+ types: "./dist/tsup/dynamic/mod.d.ts",
13828
+ default: "./dist/tsup/dynamic/mod.js"
13829
+ },
13830
+ require: {
13831
+ types: "./dist/tsup/dynamic/mod.d.cts",
13832
+ default: "./dist/tsup/dynamic/mod.cjs"
13833
+ }
13834
+ },
13835
+ "./client": {
13836
+ import: {
13837
+ browser: {
13838
+ types: "./dist/browser/client.d.ts",
13839
+ default: "./dist/browser/client.js"
13840
+ },
13841
+ types: "./dist/tsup/client/mod.d.ts",
13842
+ default: "./dist/tsup/client/mod.js"
13843
+ },
13844
+ require: {
13845
+ types: "./dist/tsup/client/mod.d.cts",
13846
+ default: "./dist/tsup/client/mod.cjs"
13847
+ }
13848
+ },
13849
+ "./log": {
13850
+ import: {
13851
+ types: "./dist/tsup/common/log.d.ts",
13852
+ default: "./dist/tsup/common/log.js"
13853
+ },
13854
+ require: {
13855
+ types: "./dist/tsup/common/log.d.cts",
13856
+ default: "./dist/tsup/common/log.cjs"
13857
+ }
13858
+ },
13859
+ "./errors": {
13860
+ import: {
13861
+ types: "./dist/tsup/actor/errors.d.ts",
13434
13862
  default: "./dist/tsup/actor/errors.js"
13435
13863
  },
13436
13864
  require: {
@@ -14023,1315 +14451,885 @@ function reviveJsonCompatValue(input, options = {}) {
14023
14451
  if (input[0].startsWith("$$")) {
14024
14452
  return [
14025
14453
  input[0].substring(1),
14026
- reviveJsonCompatValue(input[1], options)
14027
- ];
14028
- }
14029
- throw new Error(
14030
- `Unknown JSON encoding type: ${input[0]}. This may indicate corrupted data or a version mismatch.`
14031
- );
14032
- }
14033
- return input.map((value) => reviveJsonCompatValue(value, options));
14034
- }
14035
- if (isPlainObject2(input)) {
14036
- const decoded = {};
14037
- for (const [key, value] of Object.entries(input)) {
14038
- decoded[key] = reviveJsonCompatValue(value, options);
14039
- }
14040
- return decoded;
14041
- }
14042
- return input;
14043
- }
14044
- function base64DecodeToUint8Array(base643) {
14045
- if (typeof Buffer !== "undefined") {
14046
- return new Uint8Array(Buffer.from(base643, "base64"));
14047
- }
14048
- const binary = atob(base643);
14049
- const bytes = new Uint8Array(binary.length);
14050
- for (let i = 0; i < binary.length; i++) {
14051
- bytes[i] = binary.charCodeAt(i);
14052
- }
14053
- return bytes;
14054
- }
14055
- function base64DecodeToArrayBuffer(base643) {
14056
- return base64DecodeToUint8Array(base643).buffer;
14057
- }
14058
- function jsonStringifyCompat(input, space) {
14059
- return JSON.stringify(
14060
- input,
14061
- (_key, value) => {
14062
- if (typeof value === "bigint") {
14063
- return [JSON_COMPAT_BIGINT, value.toString()];
14064
- }
14065
- if (value instanceof ArrayBuffer) {
14066
- return [
14067
- JSON_COMPAT_ARRAY_BUFFER,
14068
- base64EncodeArrayBuffer(value)
14069
- ];
14070
- }
14071
- if (value instanceof Uint8Array) {
14072
- return [JSON_COMPAT_UINT8_ARRAY, base64EncodeUint8Array(value)];
14073
- }
14074
- if (Array.isArray(value) && value.length === 2 && typeof value[0] === "string" && value[0].startsWith("$")) {
14075
- return [`$${value[0]}`, value[1]];
14076
- }
14077
- return value;
14078
- },
14079
- space
14080
- );
14081
- }
14082
- function jsonParseCompat(input) {
14083
- return reviveJsonCompatValue(JSON.parse(input));
14084
- }
14085
- var VERSION = package_default.version;
14086
- var _userAgent;
14087
- function httpUserAgent() {
14088
- if (_userAgent !== void 0) {
14089
- return _userAgent;
14090
- }
14091
- let userAgent = `RivetKit/${VERSION}`;
14092
- const navigatorObj = typeof navigator !== "undefined" ? navigator : void 0;
14093
- if (navigatorObj == null ? void 0 : navigatorObj.userAgent) userAgent += ` ${navigatorObj.userAgent}`;
14094
- _userAgent = userAgent;
14095
- return userAgent;
14096
- }
14097
- function getEnvUniversal(key) {
14098
- if (typeof Deno !== "undefined") {
14099
- return Deno.env.get(key);
14100
- } else if (typeof process !== "undefined") {
14101
- return process.env[key];
14102
- }
14103
- }
14104
- function toUint8Array(data) {
14105
- if (data instanceof Uint8Array) {
14106
- return data;
14107
- } else if (data instanceof ArrayBuffer) {
14108
- return new Uint8Array(data);
14109
- } else if (ArrayBuffer.isView(data)) {
14110
- return new Uint8Array(
14111
- data.buffer.slice(
14112
- data.byteOffset,
14113
- data.byteOffset + data.byteLength
14114
- )
14115
- );
14116
- } else {
14117
- throw new TypeError("Input must be ArrayBuffer or ArrayBufferView");
14118
- }
14119
- }
14120
- function promiseWithResolvers(onReject) {
14121
- let resolve;
14122
- let reject;
14123
- const promise2 = new Promise((res, rej) => {
14124
- resolve = res;
14125
- reject = rej;
14126
- });
14127
- promise2.catch(onReject);
14128
- return { promise: promise2, resolve, reject };
14129
- }
14130
- function bufferToArrayBuffer(buf) {
14131
- return buf.buffer.slice(
14132
- buf.byteOffset,
14133
- buf.byteOffset + buf.byteLength
14134
- );
14135
- }
14136
- function combineUrlPath(endpoint, path2, queryParams) {
14137
- const baseUrl = new URL(endpoint);
14138
- const pathParts = path2.split("?");
14139
- const pathOnly = pathParts[0];
14140
- const existingQuery = pathParts[1] || "";
14141
- const basePath = baseUrl.pathname.replace(/\/$/, "");
14142
- const cleanPath = pathOnly.startsWith("/") ? pathOnly : `/${pathOnly}`;
14143
- const fullPath = (basePath + cleanPath).replace(/\/\//g, "/");
14144
- const queryParts = [];
14145
- if (existingQuery) {
14146
- queryParts.push(existingQuery);
14147
- }
14148
- if (queryParams) {
14149
- for (const [key, value] of Object.entries(queryParams)) {
14150
- if (value !== void 0) {
14151
- queryParts.push(
14152
- `${encodeURIComponent(key)}=${encodeURIComponent(value)}`
14153
- );
14154
- }
14155
- }
14156
- }
14157
- const fullQuery = queryParts.length > 0 ? `?${queryParts.join("&")}` : "";
14158
- return `${baseUrl.protocol}//${baseUrl.host}${fullPath}${fullQuery}`;
14159
- }
14160
-
14161
- // ../../../node_modules/.pnpm/@rivetkit+bare-ts@0.6.2/node_modules/@rivetkit/bare-ts/imports/dev.node.js
14162
- var DEV = process.env.NODE_ENV === "development";
14163
-
14164
- // ../../../node_modules/.pnpm/@rivetkit+bare-ts@0.6.2/node_modules/@rivetkit/bare-ts/dist/util/assert.js
14165
- var V8Error = Error;
14166
- function assert2(test, message = "") {
14167
- if (!test) {
14168
- const e = new AssertionError(message);
14169
- V8Error.captureStackTrace?.(e, assert2);
14170
- throw e;
14171
- }
14172
- }
14173
- var AssertionError = class extends Error {
14174
- constructor() {
14175
- super(...arguments);
14176
- this.name = "AssertionError";
14177
- }
14178
- };
14179
-
14180
- // ../../../node_modules/.pnpm/@rivetkit+bare-ts@0.6.2/node_modules/@rivetkit/bare-ts/dist/util/validator.js
14181
- function isU8(val) {
14182
- return val === (val & 255);
14183
- }
14184
- function isU32(val) {
14185
- return val === val >>> 0;
14186
- }
14187
- function isU64(val) {
14188
- return val === BigInt.asUintN(64, val);
14189
- }
14190
-
14191
- // ../../../node_modules/.pnpm/@rivetkit+bare-ts@0.6.2/node_modules/@rivetkit/bare-ts/dist/util/constants.js
14192
- var TEXT_DECODER_THRESHOLD = 256;
14193
- var TEXT_ENCODER_THRESHOLD = 256;
14194
- var INT_SAFE_MAX_BYTE_COUNT = 8;
14195
- var UINT_MAX_BYTE_COUNT = 10;
14196
- var UINT_SAFE32_MAX_BYTE_COUNT = 5;
14197
- var INVALID_UTF8_STRING = "invalid UTF-8 string";
14198
- var NON_CANONICAL_REPRESENTATION = "must be canonical";
14199
- var TOO_LARGE_BUFFER = "too large buffer";
14200
- var TOO_LARGE_NUMBER = "too large number";
14201
-
14202
- // ../../../node_modules/.pnpm/@rivetkit+bare-ts@0.6.2/node_modules/@rivetkit/bare-ts/dist/core/bare-error.js
14203
- var BareError = class extends Error {
14204
- constructor(offset, issue2, opts) {
14205
- super(`(byte:${offset}) ${issue2}`);
14206
- this.name = "BareError";
14207
- this.issue = issue2;
14208
- this.offset = offset;
14209
- this.cause = opts?.cause;
14210
- }
14211
- };
14212
-
14213
- // ../../../node_modules/.pnpm/@rivetkit+bare-ts@0.6.2/node_modules/@rivetkit/bare-ts/dist/core/byte-cursor.js
14214
- var ByteCursor = class {
14215
- /**
14216
- * @throws {BareError} Buffer exceeds `config.maxBufferLength`
14217
- */
14218
- constructor(bytes, config3) {
14219
- this.offset = 0;
14220
- if (bytes.length > config3.maxBufferLength) {
14221
- throw new BareError(0, TOO_LARGE_BUFFER);
14222
- }
14223
- this.bytes = bytes;
14224
- this.config = config3;
14225
- this.view = new DataView(bytes.buffer, bytes.byteOffset, bytes.length);
14226
- }
14227
- };
14228
- function check2(bc, min) {
14229
- if (DEV) {
14230
- assert2(isU32(min));
14231
- }
14232
- if (bc.offset + min > bc.bytes.length) {
14233
- throw new BareError(bc.offset, "missing bytes");
14234
- }
14235
- }
14236
- function reserve(bc, min) {
14237
- if (DEV) {
14238
- assert2(isU32(min));
14239
- }
14240
- const minLen = bc.offset + min | 0;
14241
- if (minLen > bc.bytes.length) {
14242
- grow(bc, minLen);
14243
- }
14244
- }
14245
- function grow(bc, minLen) {
14246
- if (minLen > bc.config.maxBufferLength) {
14247
- throw new BareError(0, TOO_LARGE_BUFFER);
14248
- }
14249
- const buffer = bc.bytes.buffer;
14250
- let newBytes;
14251
- if (isEs2024ArrayBufferLike(buffer) && // Make sure that the view covers the end of the buffer.
14252
- // If it is not the case, this indicates that the user don't want
14253
- // to override the trailing bytes.
14254
- bc.bytes.byteOffset + bc.bytes.byteLength === buffer.byteLength && bc.bytes.byteLength + minLen <= buffer.maxByteLength) {
14255
- const newLen = Math.min(minLen << 1, bc.config.maxBufferLength, buffer.maxByteLength);
14256
- if (buffer instanceof ArrayBuffer) {
14257
- buffer.resize(newLen);
14258
- } else {
14259
- buffer.grow(newLen);
14454
+ reviveJsonCompatValue(input[1], options)
14455
+ ];
14456
+ }
14457
+ throw new Error(
14458
+ `Unknown JSON encoding type: ${input[0]}. This may indicate corrupted data or a version mismatch.`
14459
+ );
14260
14460
  }
14261
- newBytes = new Uint8Array(buffer, bc.bytes.byteOffset, newLen);
14262
- } else {
14263
- const newLen = Math.min(minLen << 1, bc.config.maxBufferLength);
14264
- newBytes = new Uint8Array(newLen);
14265
- newBytes.set(bc.bytes);
14461
+ return input.map((value) => reviveJsonCompatValue(value, options));
14266
14462
  }
14267
- bc.bytes = newBytes;
14268
- bc.view = new DataView(newBytes.buffer);
14269
- }
14270
- function isEs2024ArrayBufferLike(buffer) {
14271
- return "maxByteLength" in buffer;
14272
- }
14273
-
14274
- // ../../../node_modules/.pnpm/@rivetkit+bare-ts@0.6.2/node_modules/@rivetkit/bare-ts/dist/codec/fixed-primitive.js
14275
- function readBool(bc) {
14276
- const val = readU8(bc);
14277
- if (val > 1) {
14278
- bc.offset--;
14279
- throw new BareError(bc.offset, "a bool must be equal to 0 or 1");
14463
+ if (isPlainObject2(input)) {
14464
+ const decoded = {};
14465
+ for (const [key, value] of Object.entries(input)) {
14466
+ decoded[key] = reviveJsonCompatValue(value, options);
14467
+ }
14468
+ return decoded;
14280
14469
  }
14281
- return val > 0;
14282
- }
14283
- function writeBool(bc, x) {
14284
- writeU8(bc, x ? 1 : 0);
14285
- }
14286
- function readU8(bc) {
14287
- check2(bc, 1);
14288
- return bc.bytes[bc.offset++];
14470
+ return input;
14289
14471
  }
14290
- function writeU8(bc, x) {
14291
- if (DEV) {
14292
- assert2(isU8(x), TOO_LARGE_NUMBER);
14472
+ function base64DecodeToUint8Array(base643) {
14473
+ if (typeof Buffer !== "undefined") {
14474
+ return new Uint8Array(Buffer.from(base643, "base64"));
14293
14475
  }
14294
- reserve(bc, 1);
14295
- bc.bytes[bc.offset++] = x;
14476
+ const binary = atob(base643);
14477
+ const bytes = new Uint8Array(binary.length);
14478
+ for (let i = 0; i < binary.length; i++) {
14479
+ bytes[i] = binary.charCodeAt(i);
14480
+ }
14481
+ return bytes;
14296
14482
  }
14297
- function readU32(bc) {
14298
- check2(bc, 4);
14299
- const result = bc.view.getUint32(bc.offset, true);
14300
- bc.offset += 4;
14301
- return result;
14483
+ function base64DecodeToArrayBuffer(base643) {
14484
+ return base64DecodeToUint8Array(base643).buffer;
14302
14485
  }
14303
- function readU64(bc) {
14304
- check2(bc, 8);
14305
- const result = bc.view.getBigUint64(bc.offset, true);
14306
- bc.offset += 8;
14307
- return result;
14486
+ function jsonStringifyCompat(input, space) {
14487
+ return JSON.stringify(
14488
+ input,
14489
+ (_key, value) => {
14490
+ if (typeof value === "bigint") {
14491
+ return [JSON_COMPAT_BIGINT, value.toString()];
14492
+ }
14493
+ if (value instanceof ArrayBuffer) {
14494
+ return [
14495
+ JSON_COMPAT_ARRAY_BUFFER,
14496
+ base64EncodeArrayBuffer(value)
14497
+ ];
14498
+ }
14499
+ if (value instanceof Uint8Array) {
14500
+ return [JSON_COMPAT_UINT8_ARRAY, base64EncodeUint8Array(value)];
14501
+ }
14502
+ if (Array.isArray(value) && value.length === 2 && typeof value[0] === "string" && value[0].startsWith("$")) {
14503
+ return [`$${value[0]}`, value[1]];
14504
+ }
14505
+ return value;
14506
+ },
14507
+ space
14508
+ );
14308
14509
  }
14309
- function writeU64(bc, x) {
14310
- if (DEV) {
14311
- assert2(isU64(x), TOO_LARGE_NUMBER);
14312
- }
14313
- reserve(bc, 8);
14314
- bc.view.setBigUint64(bc.offset, x, true);
14315
- bc.offset += 8;
14510
+ function jsonParseCompat(input) {
14511
+ return reviveJsonCompatValue(JSON.parse(input));
14316
14512
  }
14317
-
14318
- // ../../../node_modules/.pnpm/@rivetkit+bare-ts@0.6.2/node_modules/@rivetkit/bare-ts/dist/codec/uint.js
14319
- function readUint(bc) {
14320
- let low = readU8(bc);
14321
- if (low >= 128) {
14322
- low &= 127;
14323
- let shiftMul = 128;
14324
- let byteCount = 1;
14325
- let byte;
14326
- do {
14327
- byte = readU8(bc);
14328
- low += (byte & 127) * shiftMul;
14329
- shiftMul *= /* 2**7 */
14330
- 128;
14331
- byteCount++;
14332
- } while (byte >= 128 && byteCount < 7);
14333
- let height = 0;
14334
- shiftMul = 1;
14335
- while (byte >= 128 && byteCount < UINT_MAX_BYTE_COUNT) {
14336
- byte = readU8(bc);
14337
- height += (byte & 127) * shiftMul;
14338
- shiftMul *= /* 2**7 */
14339
- 128;
14340
- byteCount++;
14341
- }
14342
- if (byte === 0 || byteCount === UINT_MAX_BYTE_COUNT && byte > 1) {
14343
- bc.offset -= byteCount;
14344
- throw new BareError(bc.offset, NON_CANONICAL_REPRESENTATION);
14345
- }
14346
- return BigInt(low) + (BigInt(height) << BigInt(7 * 7));
14513
+ var VERSION = package_default.version;
14514
+ var _userAgent;
14515
+ function httpUserAgent() {
14516
+ if (_userAgent !== void 0) {
14517
+ return _userAgent;
14347
14518
  }
14348
- return BigInt(low);
14519
+ let userAgent = `RivetKit/${VERSION}`;
14520
+ const navigatorObj = typeof navigator !== "undefined" ? navigator : void 0;
14521
+ if (navigatorObj == null ? void 0 : navigatorObj.userAgent) userAgent += ` ${navigatorObj.userAgent}`;
14522
+ _userAgent = userAgent;
14523
+ return userAgent;
14349
14524
  }
14350
- function writeUint(bc, x) {
14351
- const truncated = BigInt.asUintN(64, x);
14352
- if (DEV) {
14353
- assert2(truncated === x, TOO_LARGE_NUMBER);
14525
+ function getEnvUniversal(key) {
14526
+ if (typeof Deno !== "undefined") {
14527
+ return Deno.env.get(key);
14528
+ } else if (typeof process !== "undefined") {
14529
+ return process.env[key];
14354
14530
  }
14355
- writeUintTruncated(bc, truncated);
14356
14531
  }
14357
- function writeUintTruncated(bc, x) {
14358
- let tmp = Number(BigInt.asUintN(7 * 7, x));
14359
- let rest = Number(x >> BigInt(7 * 7));
14360
- let byteCount = 0;
14361
- while (tmp >= 128 || rest > 0) {
14362
- writeU8(bc, 128 | tmp & 127);
14363
- tmp = Math.floor(tmp / /* 2**7 */
14364
- 128);
14365
- byteCount++;
14366
- if (byteCount === 7) {
14367
- tmp = rest;
14368
- rest = 0;
14369
- }
14532
+ function toUint8Array(data) {
14533
+ if (data instanceof Uint8Array) {
14534
+ return data;
14535
+ } else if (data instanceof ArrayBuffer) {
14536
+ return new Uint8Array(data);
14537
+ } else if (ArrayBuffer.isView(data)) {
14538
+ return new Uint8Array(
14539
+ data.buffer.slice(
14540
+ data.byteOffset,
14541
+ data.byteOffset + data.byteLength
14542
+ )
14543
+ );
14544
+ } else {
14545
+ throw new TypeError("Input must be ArrayBuffer or ArrayBufferView");
14370
14546
  }
14371
- writeU8(bc, tmp);
14372
14547
  }
14373
- function readUintSafe32(bc) {
14374
- let result = readU8(bc);
14375
- if (result >= 128) {
14376
- result &= 127;
14377
- let shift = 7;
14378
- let byteCount = 1;
14379
- let byte;
14380
- do {
14381
- byte = readU8(bc);
14382
- result += (byte & 127) << shift >>> 0;
14383
- shift += 7;
14384
- byteCount++;
14385
- } while (byte >= 128 && byteCount < UINT_SAFE32_MAX_BYTE_COUNT);
14386
- if (byte === 0) {
14387
- bc.offset -= byteCount - 1;
14388
- throw new BareError(bc.offset - byteCount + 1, NON_CANONICAL_REPRESENTATION);
14389
- }
14390
- if (byteCount === UINT_SAFE32_MAX_BYTE_COUNT && byte > 15) {
14391
- bc.offset -= byteCount - 1;
14392
- throw new BareError(bc.offset, TOO_LARGE_NUMBER);
14393
- }
14394
- }
14395
- return result;
14548
+ function promiseWithResolvers(onReject) {
14549
+ let resolve;
14550
+ let reject;
14551
+ const promise2 = new Promise((res, rej) => {
14552
+ resolve = res;
14553
+ reject = rej;
14554
+ });
14555
+ promise2.catch(onReject);
14556
+ return { promise: promise2, resolve, reject };
14396
14557
  }
14397
- function writeUintSafe32(bc, x) {
14398
- if (DEV) {
14399
- assert2(isU32(x), TOO_LARGE_NUMBER);
14400
- }
14401
- let zigZag = x >>> 0;
14402
- while (zigZag >= 128) {
14403
- writeU8(bc, 128 | zigZag & 127);
14404
- zigZag >>>= 7;
14405
- }
14406
- writeU8(bc, zigZag);
14558
+ function bufferToArrayBuffer(buf) {
14559
+ return buf.buffer.slice(
14560
+ buf.byteOffset,
14561
+ buf.byteOffset + buf.byteLength
14562
+ );
14407
14563
  }
14408
- function readUintSafe(bc) {
14409
- let result = readU8(bc);
14410
- if (result >= 128) {
14411
- result &= 127;
14412
- let shiftMul = (
14413
- /* 2**7 */
14414
- 128
14415
- );
14416
- let byteCount = 1;
14417
- let byte;
14418
- do {
14419
- byte = readU8(bc);
14420
- result += (byte & 127) * shiftMul;
14421
- shiftMul *= /* 2**7 */
14422
- 128;
14423
- byteCount++;
14424
- } while (byte >= 128 && byteCount < INT_SAFE_MAX_BYTE_COUNT);
14425
- if (byte === 0) {
14426
- bc.offset -= byteCount - 1;
14427
- throw new BareError(bc.offset - byteCount + 1, NON_CANONICAL_REPRESENTATION);
14428
- }
14429
- if (byteCount === INT_SAFE_MAX_BYTE_COUNT && byte > 15) {
14430
- bc.offset -= byteCount - 1;
14431
- throw new BareError(bc.offset, TOO_LARGE_NUMBER);
14564
+ function combineUrlPath(endpoint, path2, queryParams) {
14565
+ const baseUrl = new URL(endpoint);
14566
+ const pathParts = path2.split("?");
14567
+ const pathOnly = pathParts[0];
14568
+ const existingQuery = pathParts[1] || "";
14569
+ const basePath = baseUrl.pathname.replace(/\/$/, "");
14570
+ const cleanPath = pathOnly.startsWith("/") ? pathOnly : `/${pathOnly}`;
14571
+ const fullPath = (basePath + cleanPath).replace(/\/\//g, "/");
14572
+ const queryParts = [];
14573
+ if (existingQuery) {
14574
+ queryParts.push(existingQuery);
14575
+ }
14576
+ if (queryParams) {
14577
+ for (const [key, value] of Object.entries(queryParams)) {
14578
+ if (value !== void 0) {
14579
+ queryParts.push(
14580
+ `${encodeURIComponent(key)}=${encodeURIComponent(value)}`
14581
+ );
14582
+ }
14432
14583
  }
14433
14584
  }
14434
- return result;
14585
+ const fullQuery = queryParts.length > 0 ? `?${queryParts.join("&")}` : "";
14586
+ return `${baseUrl.protocol}//${baseUrl.host}${fullPath}${fullQuery}`;
14435
14587
  }
14436
14588
 
14437
- // ../../../node_modules/.pnpm/@rivetkit+bare-ts@0.6.2/node_modules/@rivetkit/bare-ts/dist/codec/u8-array.js
14438
- function readU8Array(bc) {
14439
- return readU8FixedArray(bc, readUintSafe32(bc));
14440
- }
14441
- function writeU8Array(bc, x) {
14442
- writeUintSafe32(bc, x.length);
14443
- writeU8FixedArray(bc, x);
14444
- }
14445
- function readU8FixedArray(bc, len) {
14446
- return readUnsafeU8FixedArray(bc, len).slice();
14447
- }
14448
- function writeU8FixedArray(bc, x) {
14449
- const len = x.length;
14450
- if (len > 0) {
14451
- reserve(bc, len);
14452
- bc.bytes.set(x, bc.offset);
14453
- bc.offset += len;
14589
+ // ../../../node_modules/.pnpm/@rivetkit+bare-ts@0.6.2/node_modules/@rivetkit/bare-ts/imports/dev.node.js
14590
+ var DEV = process.env.NODE_ENV === "development";
14591
+
14592
+ // ../../../node_modules/.pnpm/@rivetkit+bare-ts@0.6.2/node_modules/@rivetkit/bare-ts/dist/util/assert.js
14593
+ var V8Error = Error;
14594
+ function assert2(test, message = "") {
14595
+ if (!test) {
14596
+ const e = new AssertionError(message);
14597
+ V8Error.captureStackTrace?.(e, assert2);
14598
+ throw e;
14454
14599
  }
14455
14600
  }
14456
- function readUnsafeU8FixedArray(bc, len) {
14457
- if (DEV) {
14458
- assert2(isU32(len));
14601
+ var AssertionError = class extends Error {
14602
+ constructor() {
14603
+ super(...arguments);
14604
+ this.name = "AssertionError";
14459
14605
  }
14460
- check2(bc, len);
14461
- const offset = bc.offset;
14462
- bc.offset += len;
14463
- return bc.bytes.subarray(offset, offset + len);
14464
- }
14606
+ };
14465
14607
 
14466
- // ../../../node_modules/.pnpm/@rivetkit+bare-ts@0.6.2/node_modules/@rivetkit/bare-ts/dist/codec/data.js
14467
- function readData(bc) {
14468
- return readU8Array(bc).buffer;
14608
+ // ../../../node_modules/.pnpm/@rivetkit+bare-ts@0.6.2/node_modules/@rivetkit/bare-ts/dist/util/validator.js
14609
+ function isU8(val) {
14610
+ return val === (val & 255);
14469
14611
  }
14470
- function writeData(bc, x) {
14471
- writeU8Array(bc, new Uint8Array(x));
14612
+ function isU32(val) {
14613
+ return val === val >>> 0;
14472
14614
  }
14473
-
14474
- // ../../../node_modules/.pnpm/@rivetkit+bare-ts@0.6.2/node_modules/@rivetkit/bare-ts/dist/codec/string.js
14475
- function readString(bc) {
14476
- return readFixedString(bc, readUintSafe32(bc));
14615
+ function isU64(val) {
14616
+ return val === BigInt.asUintN(64, val);
14477
14617
  }
14478
- function writeString(bc, x) {
14479
- if (x.length < TEXT_ENCODER_THRESHOLD) {
14480
- const byteLen = utf8ByteLength(x);
14481
- writeUintSafe32(bc, byteLen);
14482
- reserve(bc, byteLen);
14483
- writeUtf8Js(bc, x);
14484
- } else {
14485
- const strBytes = UTF8_ENCODER.encode(x);
14486
- writeUintSafe32(bc, strBytes.length);
14487
- writeU8FixedArray(bc, strBytes);
14618
+
14619
+ // ../../../node_modules/.pnpm/@rivetkit+bare-ts@0.6.2/node_modules/@rivetkit/bare-ts/dist/util/constants.js
14620
+ var TEXT_DECODER_THRESHOLD = 256;
14621
+ var TEXT_ENCODER_THRESHOLD = 256;
14622
+ var INT_SAFE_MAX_BYTE_COUNT = 8;
14623
+ var UINT_MAX_BYTE_COUNT = 10;
14624
+ var UINT_SAFE32_MAX_BYTE_COUNT = 5;
14625
+ var INVALID_UTF8_STRING = "invalid UTF-8 string";
14626
+ var NON_CANONICAL_REPRESENTATION = "must be canonical";
14627
+ var TOO_LARGE_BUFFER = "too large buffer";
14628
+ var TOO_LARGE_NUMBER = "too large number";
14629
+
14630
+ // ../../../node_modules/.pnpm/@rivetkit+bare-ts@0.6.2/node_modules/@rivetkit/bare-ts/dist/core/bare-error.js
14631
+ var BareError = class extends Error {
14632
+ constructor(offset, issue2, opts) {
14633
+ super(`(byte:${offset}) ${issue2}`);
14634
+ this.name = "BareError";
14635
+ this.issue = issue2;
14636
+ this.offset = offset;
14637
+ this.cause = opts?.cause;
14488
14638
  }
14489
- }
14490
- function readFixedString(bc, byteLen) {
14491
- if (DEV) {
14492
- assert2(isU32(byteLen));
14639
+ };
14640
+
14641
+ // ../../../node_modules/.pnpm/@rivetkit+bare-ts@0.6.2/node_modules/@rivetkit/bare-ts/dist/core/byte-cursor.js
14642
+ var ByteCursor = class {
14643
+ /**
14644
+ * @throws {BareError} Buffer exceeds `config.maxBufferLength`
14645
+ */
14646
+ constructor(bytes, config3) {
14647
+ this.offset = 0;
14648
+ if (bytes.length > config3.maxBufferLength) {
14649
+ throw new BareError(0, TOO_LARGE_BUFFER);
14650
+ }
14651
+ this.bytes = bytes;
14652
+ this.config = config3;
14653
+ this.view = new DataView(bytes.buffer, bytes.byteOffset, bytes.length);
14493
14654
  }
14494
- if (byteLen < TEXT_DECODER_THRESHOLD) {
14495
- return readUtf8Js(bc, byteLen);
14655
+ };
14656
+ function check2(bc, min) {
14657
+ if (DEV) {
14658
+ assert2(isU32(min));
14496
14659
  }
14497
- try {
14498
- return UTF8_DECODER.decode(readUnsafeU8FixedArray(bc, byteLen));
14499
- } catch (_cause) {
14500
- throw new BareError(bc.offset, INVALID_UTF8_STRING);
14660
+ if (bc.offset + min > bc.bytes.length) {
14661
+ throw new BareError(bc.offset, "missing bytes");
14501
14662
  }
14502
14663
  }
14503
- function readUtf8Js(bc, byteLen) {
14504
- check2(bc, byteLen);
14505
- let result = "";
14506
- const bytes = bc.bytes;
14507
- let offset = bc.offset;
14508
- const upperOffset = offset + byteLen;
14509
- while (offset < upperOffset) {
14510
- let codePoint = bytes[offset++];
14511
- if (codePoint > 127) {
14512
- let malformed = true;
14513
- const byte1 = codePoint;
14514
- if (offset < upperOffset && codePoint < 224) {
14515
- const byte2 = bytes[offset++];
14516
- codePoint = (byte1 & 31) << 6 | byte2 & 63;
14517
- malformed = codePoint >> 7 === 0 || // non-canonical char
14518
- byte1 >> 5 !== 6 || // invalid tag
14519
- byte2 >> 6 !== 2;
14520
- } else if (offset + 1 < upperOffset && codePoint < 240) {
14521
- const byte2 = bytes[offset++];
14522
- const byte3 = bytes[offset++];
14523
- codePoint = (byte1 & 15) << 12 | (byte2 & 63) << 6 | byte3 & 63;
14524
- malformed = codePoint >> 11 === 0 || // non-canonical char or missing data
14525
- codePoint >> 11 === 27 || // surrogate char (0xD800 <= codePoint <= 0xDFFF)
14526
- byte1 >> 4 !== 14 || // invalid tag
14527
- byte2 >> 6 !== 2 || // invalid tag
14528
- byte3 >> 6 !== 2;
14529
- } else if (offset + 2 < upperOffset) {
14530
- const byte2 = bytes[offset++];
14531
- const byte3 = bytes[offset++];
14532
- const byte4 = bytes[offset++];
14533
- codePoint = (byte1 & 7) << 18 | (byte2 & 63) << 12 | (byte3 & 63) << 6 | byte4 & 63;
14534
- malformed = codePoint >> 16 === 0 || // non-canonical char or missing data
14535
- codePoint > 1114111 || // too large code point
14536
- byte1 >> 3 !== 30 || // invalid tag
14537
- byte2 >> 6 !== 2 || // invalid tag
14538
- byte3 >> 6 !== 2 || // invalid tag
14539
- byte4 >> 6 !== 2;
14540
- }
14541
- if (malformed) {
14542
- throw new BareError(bc.offset, INVALID_UTF8_STRING);
14543
- }
14544
- }
14545
- result += String.fromCodePoint(codePoint);
14664
+ function reserve(bc, min) {
14665
+ if (DEV) {
14666
+ assert2(isU32(min));
14667
+ }
14668
+ const minLen = bc.offset + min | 0;
14669
+ if (minLen > bc.bytes.length) {
14670
+ grow(bc, minLen);
14546
14671
  }
14547
- bc.offset = offset;
14548
- return result;
14549
14672
  }
14550
- function writeUtf8Js(bc, s) {
14551
- const bytes = bc.bytes;
14552
- let offset = bc.offset;
14553
- let i = 0;
14554
- while (i < s.length) {
14555
- const codePoint = s.codePointAt(i++);
14556
- if (codePoint < 128) {
14557
- bytes[offset++] = codePoint;
14673
+ function grow(bc, minLen) {
14674
+ if (minLen > bc.config.maxBufferLength) {
14675
+ throw new BareError(0, TOO_LARGE_BUFFER);
14676
+ }
14677
+ const buffer = bc.bytes.buffer;
14678
+ let newBytes;
14679
+ if (isEs2024ArrayBufferLike(buffer) && // Make sure that the view covers the end of the buffer.
14680
+ // If it is not the case, this indicates that the user don't want
14681
+ // to override the trailing bytes.
14682
+ bc.bytes.byteOffset + bc.bytes.byteLength === buffer.byteLength && bc.bytes.byteLength + minLen <= buffer.maxByteLength) {
14683
+ const newLen = Math.min(minLen << 1, bc.config.maxBufferLength, buffer.maxByteLength);
14684
+ if (buffer instanceof ArrayBuffer) {
14685
+ buffer.resize(newLen);
14558
14686
  } else {
14559
- if (codePoint < 2048) {
14560
- bytes[offset++] = 192 | codePoint >> 6;
14561
- } else {
14562
- if (codePoint < 65536) {
14563
- bytes[offset++] = 224 | codePoint >> 12;
14564
- } else {
14565
- bytes[offset++] = 240 | codePoint >> 18;
14566
- bytes[offset++] = 128 | codePoint >> 12 & 63;
14567
- i++;
14568
- }
14569
- bytes[offset++] = 128 | codePoint >> 6 & 63;
14570
- }
14571
- bytes[offset++] = 128 | codePoint & 63;
14687
+ buffer.grow(newLen);
14572
14688
  }
14689
+ newBytes = new Uint8Array(buffer, bc.bytes.byteOffset, newLen);
14690
+ } else {
14691
+ const newLen = Math.min(minLen << 1, bc.config.maxBufferLength);
14692
+ newBytes = new Uint8Array(newLen);
14693
+ newBytes.set(bc.bytes);
14573
14694
  }
14574
- bc.offset = offset;
14695
+ bc.bytes = newBytes;
14696
+ bc.view = new DataView(newBytes.buffer);
14575
14697
  }
14576
- function utf8ByteLength(s) {
14577
- let result = s.length;
14578
- for (let i = 0; i < s.length; i++) {
14579
- const codePoint = s.codePointAt(i);
14580
- if (codePoint > 127) {
14581
- result++;
14582
- if (codePoint > 2047) {
14583
- result++;
14584
- if (codePoint > 65535) {
14585
- i++;
14586
- }
14587
- }
14588
- }
14698
+ function isEs2024ArrayBufferLike(buffer) {
14699
+ return "maxByteLength" in buffer;
14700
+ }
14701
+
14702
+ // ../../../node_modules/.pnpm/@rivetkit+bare-ts@0.6.2/node_modules/@rivetkit/bare-ts/dist/codec/fixed-primitive.js
14703
+ function readBool(bc) {
14704
+ const val = readU8(bc);
14705
+ if (val > 1) {
14706
+ bc.offset--;
14707
+ throw new BareError(bc.offset, "a bool must be equal to 0 or 1");
14589
14708
  }
14590
- return result;
14709
+ return val > 0;
14710
+ }
14711
+ function writeBool(bc, x) {
14712
+ writeU8(bc, x ? 1 : 0);
14713
+ }
14714
+ function readU8(bc) {
14715
+ check2(bc, 1);
14716
+ return bc.bytes[bc.offset++];
14591
14717
  }
14592
- var UTF8_DECODER = /* @__PURE__ */ new TextDecoder("utf-8", { fatal: true });
14593
- var UTF8_ENCODER = /* @__PURE__ */ new TextEncoder();
14594
-
14595
- // ../../../node_modules/.pnpm/@rivetkit+bare-ts@0.6.2/node_modules/@rivetkit/bare-ts/dist/core/config.js
14596
- function Config({ initialBufferLength = 1024, maxBufferLength = 1024 * 1024 * 32 }) {
14718
+ function writeU8(bc, x) {
14597
14719
  if (DEV) {
14598
- assert2(isU32(initialBufferLength), TOO_LARGE_NUMBER);
14599
- assert2(isU32(maxBufferLength), TOO_LARGE_NUMBER);
14600
- assert2(initialBufferLength <= maxBufferLength, "initialBufferLength must be lower than or equal to maxBufferLength");
14720
+ assert2(isU8(x), TOO_LARGE_NUMBER);
14601
14721
  }
14602
- return {
14603
- initialBufferLength,
14604
- maxBufferLength
14605
- };
14722
+ reserve(bc, 1);
14723
+ bc.bytes[bc.offset++] = x;
14606
14724
  }
14607
-
14608
- // ../rivetkit/dist/tsup/chunk-Z23GEV4Y.js
14609
- var config2 = /* @__PURE__ */ Config({});
14610
- function readWorkflowCbor(bc) {
14611
- return readData(bc);
14725
+ function readU32(bc) {
14726
+ check2(bc, 4);
14727
+ const result = bc.view.getUint32(bc.offset, true);
14728
+ bc.offset += 4;
14729
+ return result;
14612
14730
  }
14613
- function readWorkflowNameIndex(bc) {
14614
- return readU32(bc);
14731
+ function readU64(bc) {
14732
+ check2(bc, 8);
14733
+ const result = bc.view.getBigUint64(bc.offset, true);
14734
+ bc.offset += 8;
14735
+ return result;
14615
14736
  }
14616
- function readWorkflowLoopIterationMarker(bc) {
14617
- return {
14618
- loop: readWorkflowNameIndex(bc),
14619
- iteration: readU32(bc)
14620
- };
14737
+ function writeU64(bc, x) {
14738
+ if (DEV) {
14739
+ assert2(isU64(x), TOO_LARGE_NUMBER);
14740
+ }
14741
+ reserve(bc, 8);
14742
+ bc.view.setBigUint64(bc.offset, x, true);
14743
+ bc.offset += 8;
14621
14744
  }
14622
- function readWorkflowPathSegment(bc) {
14623
- const offset = bc.offset;
14624
- const tag = readU8(bc);
14625
- switch (tag) {
14626
- case 0:
14627
- return { tag: "WorkflowNameIndex", val: readWorkflowNameIndex(bc) };
14628
- case 1:
14629
- return {
14630
- tag: "WorkflowLoopIterationMarker",
14631
- val: readWorkflowLoopIterationMarker(bc)
14632
- };
14633
- default: {
14634
- bc.offset = offset;
14635
- throw new BareError(offset, "invalid tag");
14745
+
14746
+ // ../../../node_modules/.pnpm/@rivetkit+bare-ts@0.6.2/node_modules/@rivetkit/bare-ts/dist/codec/uint.js
14747
+ function readUint(bc) {
14748
+ let low = readU8(bc);
14749
+ if (low >= 128) {
14750
+ low &= 127;
14751
+ let shiftMul = 128;
14752
+ let byteCount = 1;
14753
+ let byte;
14754
+ do {
14755
+ byte = readU8(bc);
14756
+ low += (byte & 127) * shiftMul;
14757
+ shiftMul *= /* 2**7 */
14758
+ 128;
14759
+ byteCount++;
14760
+ } while (byte >= 128 && byteCount < 7);
14761
+ let height = 0;
14762
+ shiftMul = 1;
14763
+ while (byte >= 128 && byteCount < UINT_MAX_BYTE_COUNT) {
14764
+ byte = readU8(bc);
14765
+ height += (byte & 127) * shiftMul;
14766
+ shiftMul *= /* 2**7 */
14767
+ 128;
14768
+ byteCount++;
14769
+ }
14770
+ if (byte === 0 || byteCount === UINT_MAX_BYTE_COUNT && byte > 1) {
14771
+ bc.offset -= byteCount;
14772
+ throw new BareError(bc.offset, NON_CANONICAL_REPRESENTATION);
14636
14773
  }
14774
+ return BigInt(low) + (BigInt(height) << BigInt(7 * 7));
14637
14775
  }
14776
+ return BigInt(low);
14638
14777
  }
14639
- function readWorkflowLocation(bc) {
14640
- const len = readUintSafe(bc);
14641
- if (len === 0) {
14642
- return [];
14643
- }
14644
- const result = [readWorkflowPathSegment(bc)];
14645
- for (let i = 1; i < len; i++) {
14646
- result[i] = readWorkflowPathSegment(bc);
14778
+ function writeUint(bc, x) {
14779
+ const truncated = BigInt.asUintN(64, x);
14780
+ if (DEV) {
14781
+ assert2(truncated === x, TOO_LARGE_NUMBER);
14647
14782
  }
14648
- return result;
14783
+ writeUintTruncated(bc, truncated);
14649
14784
  }
14650
- function readWorkflowEntryStatus(bc) {
14651
- const offset = bc.offset;
14652
- const tag = readU8(bc);
14653
- switch (tag) {
14654
- case 0:
14655
- return "PENDING";
14656
- case 1:
14657
- return "RUNNING";
14658
- case 2:
14659
- return "COMPLETED";
14660
- case 3:
14661
- return "FAILED";
14662
- case 4:
14663
- return "EXHAUSTED";
14664
- default: {
14665
- bc.offset = offset;
14666
- throw new BareError(offset, "invalid tag");
14785
+ function writeUintTruncated(bc, x) {
14786
+ let tmp = Number(BigInt.asUintN(7 * 7, x));
14787
+ let rest = Number(x >> BigInt(7 * 7));
14788
+ let byteCount = 0;
14789
+ while (tmp >= 128 || rest > 0) {
14790
+ writeU8(bc, 128 | tmp & 127);
14791
+ tmp = Math.floor(tmp / /* 2**7 */
14792
+ 128);
14793
+ byteCount++;
14794
+ if (byteCount === 7) {
14795
+ tmp = rest;
14796
+ rest = 0;
14667
14797
  }
14668
14798
  }
14799
+ writeU8(bc, tmp);
14669
14800
  }
14670
- function readWorkflowSleepState(bc) {
14671
- const offset = bc.offset;
14672
- const tag = readU8(bc);
14673
- switch (tag) {
14674
- case 0:
14675
- return "PENDING";
14676
- case 1:
14677
- return "COMPLETED";
14678
- case 2:
14679
- return "INTERRUPTED";
14680
- default: {
14681
- bc.offset = offset;
14682
- throw new BareError(offset, "invalid tag");
14801
+ function readUintSafe32(bc) {
14802
+ let result = readU8(bc);
14803
+ if (result >= 128) {
14804
+ result &= 127;
14805
+ let shift = 7;
14806
+ let byteCount = 1;
14807
+ let byte;
14808
+ do {
14809
+ byte = readU8(bc);
14810
+ result += (byte & 127) << shift >>> 0;
14811
+ shift += 7;
14812
+ byteCount++;
14813
+ } while (byte >= 128 && byteCount < UINT_SAFE32_MAX_BYTE_COUNT);
14814
+ if (byte === 0) {
14815
+ bc.offset -= byteCount - 1;
14816
+ throw new BareError(bc.offset - byteCount + 1, NON_CANONICAL_REPRESENTATION);
14683
14817
  }
14684
- }
14685
- }
14686
- function readWorkflowBranchStatusType(bc) {
14687
- const offset = bc.offset;
14688
- const tag = readU8(bc);
14689
- switch (tag) {
14690
- case 0:
14691
- return "PENDING";
14692
- case 1:
14693
- return "RUNNING";
14694
- case 2:
14695
- return "COMPLETED";
14696
- case 3:
14697
- return "FAILED";
14698
- case 4:
14699
- return "CANCELLED";
14700
- default: {
14701
- bc.offset = offset;
14702
- throw new BareError(offset, "invalid tag");
14818
+ if (byteCount === UINT_SAFE32_MAX_BYTE_COUNT && byte > 15) {
14819
+ bc.offset -= byteCount - 1;
14820
+ throw new BareError(bc.offset, TOO_LARGE_NUMBER);
14703
14821
  }
14704
14822
  }
14823
+ return result;
14705
14824
  }
14706
- function read0(bc) {
14707
- return readBool(bc) ? readWorkflowCbor(bc) : null;
14708
- }
14709
- function read1(bc) {
14710
- return readBool(bc) ? readString(bc) : null;
14711
- }
14712
- function readWorkflowStepEntry(bc) {
14713
- return {
14714
- output: read0(bc),
14715
- error: read1(bc)
14716
- };
14717
- }
14718
- function readWorkflowLoopEntry(bc) {
14719
- return {
14720
- state: readWorkflowCbor(bc),
14721
- iteration: readU32(bc),
14722
- output: read0(bc)
14723
- };
14724
- }
14725
- function readWorkflowSleepEntry(bc) {
14726
- return {
14727
- deadline: readU64(bc),
14728
- state: readWorkflowSleepState(bc)
14729
- };
14730
- }
14731
- function readWorkflowMessageEntry(bc) {
14732
- return {
14733
- name: readString(bc),
14734
- messageData: readWorkflowCbor(bc)
14735
- };
14736
- }
14737
- function readWorkflowRollbackCheckpointEntry(bc) {
14738
- return {
14739
- name: readString(bc)
14740
- };
14741
- }
14742
- function readWorkflowBranchStatus(bc) {
14743
- return {
14744
- status: readWorkflowBranchStatusType(bc),
14745
- output: read0(bc),
14746
- error: read1(bc)
14747
- };
14825
+ function writeUintSafe32(bc, x) {
14826
+ if (DEV) {
14827
+ assert2(isU32(x), TOO_LARGE_NUMBER);
14828
+ }
14829
+ let zigZag = x >>> 0;
14830
+ while (zigZag >= 128) {
14831
+ writeU8(bc, 128 | zigZag & 127);
14832
+ zigZag >>>= 7;
14833
+ }
14834
+ writeU8(bc, zigZag);
14748
14835
  }
14749
- function read2(bc) {
14750
- const len = readUintSafe(bc);
14751
- const result = /* @__PURE__ */ new Map();
14752
- for (let i = 0; i < len; i++) {
14753
- const offset = bc.offset;
14754
- const key = readString(bc);
14755
- if (result.has(key)) {
14756
- bc.offset = offset;
14757
- throw new BareError(offset, "duplicated key");
14836
+ function readUintSafe(bc) {
14837
+ let result = readU8(bc);
14838
+ if (result >= 128) {
14839
+ result &= 127;
14840
+ let shiftMul = (
14841
+ /* 2**7 */
14842
+ 128
14843
+ );
14844
+ let byteCount = 1;
14845
+ let byte;
14846
+ do {
14847
+ byte = readU8(bc);
14848
+ result += (byte & 127) * shiftMul;
14849
+ shiftMul *= /* 2**7 */
14850
+ 128;
14851
+ byteCount++;
14852
+ } while (byte >= 128 && byteCount < INT_SAFE_MAX_BYTE_COUNT);
14853
+ if (byte === 0) {
14854
+ bc.offset -= byteCount - 1;
14855
+ throw new BareError(bc.offset - byteCount + 1, NON_CANONICAL_REPRESENTATION);
14856
+ }
14857
+ if (byteCount === INT_SAFE_MAX_BYTE_COUNT && byte > 15) {
14858
+ bc.offset -= byteCount - 1;
14859
+ throw new BareError(bc.offset, TOO_LARGE_NUMBER);
14758
14860
  }
14759
- result.set(key, readWorkflowBranchStatus(bc));
14760
14861
  }
14761
14862
  return result;
14762
14863
  }
14763
- function readWorkflowJoinEntry(bc) {
14764
- return {
14765
- branches: read2(bc)
14766
- };
14864
+
14865
+ // ../../../node_modules/.pnpm/@rivetkit+bare-ts@0.6.2/node_modules/@rivetkit/bare-ts/dist/codec/u8-array.js
14866
+ function readU8Array(bc) {
14867
+ return readU8FixedArray(bc, readUintSafe32(bc));
14767
14868
  }
14768
- function readWorkflowRaceEntry(bc) {
14769
- return {
14770
- winner: read1(bc),
14771
- branches: read2(bc)
14772
- };
14869
+ function writeU8Array(bc, x) {
14870
+ writeUintSafe32(bc, x.length);
14871
+ writeU8FixedArray(bc, x);
14773
14872
  }
14774
- function readWorkflowRemovedEntry(bc) {
14775
- return {
14776
- originalType: readString(bc),
14777
- originalName: read1(bc)
14778
- };
14873
+ function readU8FixedArray(bc, len) {
14874
+ return readUnsafeU8FixedArray(bc, len).slice();
14779
14875
  }
14780
- function readWorkflowVersionCheckEntry(bc) {
14781
- return {
14782
- resolved: readU32(bc),
14783
- latest: readU32(bc)
14784
- };
14876
+ function writeU8FixedArray(bc, x) {
14877
+ const len = x.length;
14878
+ if (len > 0) {
14879
+ reserve(bc, len);
14880
+ bc.bytes.set(x, bc.offset);
14881
+ bc.offset += len;
14882
+ }
14785
14883
  }
14786
- function readWorkflowEntryKind(bc) {
14787
- const offset = bc.offset;
14788
- const tag = readU8(bc);
14789
- switch (tag) {
14790
- case 0:
14791
- return { tag: "WorkflowStepEntry", val: readWorkflowStepEntry(bc) };
14792
- case 1:
14793
- return { tag: "WorkflowLoopEntry", val: readWorkflowLoopEntry(bc) };
14794
- case 2:
14795
- return {
14796
- tag: "WorkflowSleepEntry",
14797
- val: readWorkflowSleepEntry(bc)
14798
- };
14799
- case 3:
14800
- return {
14801
- tag: "WorkflowMessageEntry",
14802
- val: readWorkflowMessageEntry(bc)
14803
- };
14804
- case 4:
14805
- return {
14806
- tag: "WorkflowRollbackCheckpointEntry",
14807
- val: readWorkflowRollbackCheckpointEntry(bc)
14808
- };
14809
- case 5:
14810
- return { tag: "WorkflowJoinEntry", val: readWorkflowJoinEntry(bc) };
14811
- case 6:
14812
- return { tag: "WorkflowRaceEntry", val: readWorkflowRaceEntry(bc) };
14813
- case 7:
14814
- return {
14815
- tag: "WorkflowRemovedEntry",
14816
- val: readWorkflowRemovedEntry(bc)
14817
- };
14818
- case 8:
14819
- return {
14820
- tag: "WorkflowVersionCheckEntry",
14821
- val: readWorkflowVersionCheckEntry(bc)
14822
- };
14823
- default: {
14824
- bc.offset = offset;
14825
- throw new BareError(offset, "invalid tag");
14826
- }
14884
+ function readUnsafeU8FixedArray(bc, len) {
14885
+ if (DEV) {
14886
+ assert2(isU32(len));
14827
14887
  }
14888
+ check2(bc, len);
14889
+ const offset = bc.offset;
14890
+ bc.offset += len;
14891
+ return bc.bytes.subarray(offset, offset + len);
14828
14892
  }
14829
- function readWorkflowEntry(bc) {
14830
- return {
14831
- id: readString(bc),
14832
- location: readWorkflowLocation(bc),
14833
- kind: readWorkflowEntryKind(bc)
14834
- };
14893
+
14894
+ // ../../../node_modules/.pnpm/@rivetkit+bare-ts@0.6.2/node_modules/@rivetkit/bare-ts/dist/codec/data.js
14895
+ function readData(bc) {
14896
+ return readU8Array(bc).buffer;
14835
14897
  }
14836
- function read3(bc) {
14837
- return readBool(bc) ? readU64(bc) : null;
14898
+ function writeData(bc, x) {
14899
+ writeU8Array(bc, new Uint8Array(x));
14838
14900
  }
14839
- function readWorkflowEntryMetadata(bc) {
14840
- return {
14841
- status: readWorkflowEntryStatus(bc),
14842
- error: read1(bc),
14843
- attempts: readU32(bc),
14844
- lastAttemptAt: readU64(bc),
14845
- createdAt: readU64(bc),
14846
- completedAt: read3(bc),
14847
- rollbackCompletedAt: read3(bc),
14848
- rollbackError: read1(bc)
14849
- };
14901
+
14902
+ // ../../../node_modules/.pnpm/@rivetkit+bare-ts@0.6.2/node_modules/@rivetkit/bare-ts/dist/codec/string.js
14903
+ function readString(bc) {
14904
+ return readFixedString(bc, readUintSafe32(bc));
14850
14905
  }
14851
- function read4(bc) {
14852
- const len = readUintSafe(bc);
14853
- if (len === 0) {
14854
- return [];
14855
- }
14856
- const result = [readString(bc)];
14857
- for (let i = 1; i < len; i++) {
14858
- result[i] = readString(bc);
14906
+ function writeString(bc, x) {
14907
+ if (x.length < TEXT_ENCODER_THRESHOLD) {
14908
+ const byteLen = utf8ByteLength(x);
14909
+ writeUintSafe32(bc, byteLen);
14910
+ reserve(bc, byteLen);
14911
+ writeUtf8Js(bc, x);
14912
+ } else {
14913
+ const strBytes = UTF8_ENCODER.encode(x);
14914
+ writeUintSafe32(bc, strBytes.length);
14915
+ writeU8FixedArray(bc, strBytes);
14859
14916
  }
14860
- return result;
14861
14917
  }
14862
- function read5(bc) {
14863
- const len = readUintSafe(bc);
14864
- if (len === 0) {
14865
- return [];
14918
+ function readFixedString(bc, byteLen) {
14919
+ if (DEV) {
14920
+ assert2(isU32(byteLen));
14866
14921
  }
14867
- const result = [readWorkflowEntry(bc)];
14868
- for (let i = 1; i < len; i++) {
14869
- result[i] = readWorkflowEntry(bc);
14922
+ if (byteLen < TEXT_DECODER_THRESHOLD) {
14923
+ return readUtf8Js(bc, byteLen);
14924
+ }
14925
+ try {
14926
+ return UTF8_DECODER.decode(readUnsafeU8FixedArray(bc, byteLen));
14927
+ } catch (_cause) {
14928
+ throw new BareError(bc.offset, INVALID_UTF8_STRING);
14929
+ }
14930
+ }
14931
+ function readUtf8Js(bc, byteLen) {
14932
+ check2(bc, byteLen);
14933
+ let result = "";
14934
+ const bytes = bc.bytes;
14935
+ let offset = bc.offset;
14936
+ const upperOffset = offset + byteLen;
14937
+ while (offset < upperOffset) {
14938
+ let codePoint = bytes[offset++];
14939
+ if (codePoint > 127) {
14940
+ let malformed = true;
14941
+ const byte1 = codePoint;
14942
+ if (offset < upperOffset && codePoint < 224) {
14943
+ const byte2 = bytes[offset++];
14944
+ codePoint = (byte1 & 31) << 6 | byte2 & 63;
14945
+ malformed = codePoint >> 7 === 0 || // non-canonical char
14946
+ byte1 >> 5 !== 6 || // invalid tag
14947
+ byte2 >> 6 !== 2;
14948
+ } else if (offset + 1 < upperOffset && codePoint < 240) {
14949
+ const byte2 = bytes[offset++];
14950
+ const byte3 = bytes[offset++];
14951
+ codePoint = (byte1 & 15) << 12 | (byte2 & 63) << 6 | byte3 & 63;
14952
+ malformed = codePoint >> 11 === 0 || // non-canonical char or missing data
14953
+ codePoint >> 11 === 27 || // surrogate char (0xD800 <= codePoint <= 0xDFFF)
14954
+ byte1 >> 4 !== 14 || // invalid tag
14955
+ byte2 >> 6 !== 2 || // invalid tag
14956
+ byte3 >> 6 !== 2;
14957
+ } else if (offset + 2 < upperOffset) {
14958
+ const byte2 = bytes[offset++];
14959
+ const byte3 = bytes[offset++];
14960
+ const byte4 = bytes[offset++];
14961
+ codePoint = (byte1 & 7) << 18 | (byte2 & 63) << 12 | (byte3 & 63) << 6 | byte4 & 63;
14962
+ malformed = codePoint >> 16 === 0 || // non-canonical char or missing data
14963
+ codePoint > 1114111 || // too large code point
14964
+ byte1 >> 3 !== 30 || // invalid tag
14965
+ byte2 >> 6 !== 2 || // invalid tag
14966
+ byte3 >> 6 !== 2 || // invalid tag
14967
+ byte4 >> 6 !== 2;
14968
+ }
14969
+ if (malformed) {
14970
+ throw new BareError(bc.offset, INVALID_UTF8_STRING);
14971
+ }
14972
+ }
14973
+ result += String.fromCodePoint(codePoint);
14870
14974
  }
14975
+ bc.offset = offset;
14871
14976
  return result;
14872
14977
  }
14873
- function read6(bc) {
14874
- const len = readUintSafe(bc);
14875
- const result = /* @__PURE__ */ new Map();
14876
- for (let i = 0; i < len; i++) {
14877
- const offset = bc.offset;
14878
- const key = readString(bc);
14879
- if (result.has(key)) {
14880
- bc.offset = offset;
14881
- throw new BareError(offset, "duplicated key");
14978
+ function writeUtf8Js(bc, s) {
14979
+ const bytes = bc.bytes;
14980
+ let offset = bc.offset;
14981
+ let i = 0;
14982
+ while (i < s.length) {
14983
+ const codePoint = s.codePointAt(i++);
14984
+ if (codePoint < 128) {
14985
+ bytes[offset++] = codePoint;
14986
+ } else {
14987
+ if (codePoint < 2048) {
14988
+ bytes[offset++] = 192 | codePoint >> 6;
14989
+ } else {
14990
+ if (codePoint < 65536) {
14991
+ bytes[offset++] = 224 | codePoint >> 12;
14992
+ } else {
14993
+ bytes[offset++] = 240 | codePoint >> 18;
14994
+ bytes[offset++] = 128 | codePoint >> 12 & 63;
14995
+ i++;
14996
+ }
14997
+ bytes[offset++] = 128 | codePoint >> 6 & 63;
14998
+ }
14999
+ bytes[offset++] = 128 | codePoint & 63;
15000
+ }
15001
+ }
15002
+ bc.offset = offset;
15003
+ }
15004
+ function utf8ByteLength(s) {
15005
+ let result = s.length;
15006
+ for (let i = 0; i < s.length; i++) {
15007
+ const codePoint = s.codePointAt(i);
15008
+ if (codePoint > 127) {
15009
+ result++;
15010
+ if (codePoint > 2047) {
15011
+ result++;
15012
+ if (codePoint > 65535) {
15013
+ i++;
15014
+ }
15015
+ }
14882
15016
  }
14883
- result.set(key, readWorkflowEntryMetadata(bc));
14884
15017
  }
14885
15018
  return result;
14886
15019
  }
14887
- function readWorkflowHistory(bc) {
15020
+ var UTF8_DECODER = /* @__PURE__ */ new TextDecoder("utf-8", { fatal: true });
15021
+ var UTF8_ENCODER = /* @__PURE__ */ new TextEncoder();
15022
+
15023
+ // ../../../node_modules/.pnpm/@rivetkit+bare-ts@0.6.2/node_modules/@rivetkit/bare-ts/dist/core/config.js
15024
+ function Config({ initialBufferLength = 1024, maxBufferLength = 1024 * 1024 * 32 }) {
15025
+ if (DEV) {
15026
+ assert2(isU32(initialBufferLength), TOO_LARGE_NUMBER);
15027
+ assert2(isU32(maxBufferLength), TOO_LARGE_NUMBER);
15028
+ assert2(initialBufferLength <= maxBufferLength, "initialBufferLength must be lower than or equal to maxBufferLength");
15029
+ }
14888
15030
  return {
14889
- nameRegistry: read4(bc),
14890
- entries: read5(bc),
14891
- entryMetadata: read6(bc)
15031
+ initialBufferLength,
15032
+ maxBufferLength
14892
15033
  };
14893
15034
  }
14894
- function decodeWorkflowHistory(bytes) {
14895
- const bc = new ByteCursor(bytes, config2);
14896
- const result = readWorkflowHistory(bc);
14897
- if (bc.offset < bc.view.byteLength) {
14898
- throw new BareError(bc.offset, "remaining bytes");
14899
- }
14900
- return result;
15035
+
15036
+ // ../rivetkit/dist/tsup/chunk-RZFEJKIS.js
15037
+ var config2 = /* @__PURE__ */ Config({});
15038
+ function readWorkflowCbor(bc) {
15039
+ return readData(bc);
14901
15040
  }
14902
- function decodeWorkflowHistoryTransport(data) {
14903
- return decodeWorkflowHistory(toUint8Array(data));
15041
+ function readWorkflowNameIndex(bc) {
15042
+ return readU32(bc);
14904
15043
  }
14905
-
14906
- // ../rivetkit/dist/tsup/chunk-QWLJCP3X.js
14907
- function flattenActionHandlers(actions) {
14908
- const flattened = /* @__PURE__ */ Object.create(null);
14909
- for (const { name, handler } of collectActionEntries(actions)) {
14910
- flattened[name] = handler;
14911
- }
14912
- return flattened;
15044
+ function readWorkflowLoopIterationMarker(bc) {
15045
+ return {
15046
+ loop: readWorkflowNameIndex(bc),
15047
+ iteration: readU32(bc)
15048
+ };
14913
15049
  }
14914
- function flattenActionInputSchemas(actions, schemas) {
14915
- if (schemas === void 0) return void 0;
14916
- if (!isRecord(schemas)) {
14917
- throw new TypeError("actionInputSchemas must be an object");
14918
- }
14919
- const flattened = /* @__PURE__ */ Object.create(null);
14920
- for (const { name, path: path2 } of collectActionEntries(actions)) {
14921
- const nestedSchema = lookupNestedSchema(schemas, path2);
14922
- const flatSchema = schemas[name];
14923
- if (nestedSchema !== void 0 && flatSchema !== void 0 && nestedSchema !== flatSchema) {
14924
- throw new TypeError(
14925
- `Action input schema \`${name}\` is defined by both a nested path and a dotted key`
14926
- );
14927
- }
14928
- const schema = nestedSchema ?? flatSchema;
14929
- if (schema !== void 0) {
14930
- flattened[name] = schema;
15050
+ function readWorkflowPathSegment(bc) {
15051
+ const offset = bc.offset;
15052
+ const tag = readU8(bc);
15053
+ switch (tag) {
15054
+ case 0:
15055
+ return { tag: "WorkflowNameIndex", val: readWorkflowNameIndex(bc) };
15056
+ case 1:
15057
+ return {
15058
+ tag: "WorkflowLoopIterationMarker",
15059
+ val: readWorkflowLoopIterationMarker(bc)
15060
+ };
15061
+ default: {
15062
+ bc.offset = offset;
15063
+ throw new BareError(offset, "invalid tag");
14931
15064
  }
14932
15065
  }
14933
- return flattened;
14934
- }
14935
- function collectActionEntries(actions) {
14936
- const entries = [];
14937
- const names = /* @__PURE__ */ new Set();
14938
- visitActionGroup(actions ?? {}, [], entries, names);
14939
- return entries;
14940
15066
  }
14941
- function visitActionGroup(value, path2, entries, names) {
14942
- if (!isRecord(value)) {
14943
- throw new TypeError(
14944
- `${formatActionPath(path2)} must be an action handler or group`
14945
- );
15067
+ function readWorkflowLocation(bc) {
15068
+ const len = readUintSafe(bc);
15069
+ if (len === 0) {
15070
+ return [];
14946
15071
  }
14947
- for (const [segment, child] of Object.entries(value)) {
14948
- const childPath = [...path2, segment];
14949
- if (typeof child === "function") {
14950
- const name = childPath.join(".");
14951
- if (names.has(name)) {
14952
- throw new TypeError(
14953
- `Multiple action definitions flatten to \`${name}\``
14954
- );
14955
- }
14956
- names.add(name);
14957
- entries.push({
14958
- name,
14959
- path: childPath,
14960
- handler: child
14961
- });
14962
- } else {
14963
- visitActionGroup(child, childPath, entries, names);
14964
- }
15072
+ const result = [readWorkflowPathSegment(bc)];
15073
+ for (let i = 1; i < len; i++) {
15074
+ result[i] = readWorkflowPathSegment(bc);
14965
15075
  }
15076
+ return result;
14966
15077
  }
14967
- function lookupNestedSchema(schemas, path2) {
14968
- let value = schemas;
14969
- for (const segment of path2) {
14970
- if (!isRecord(value) || !Object.hasOwn(value, segment)) {
14971
- return void 0;
15078
+ function readWorkflowEntryStatus(bc) {
15079
+ const offset = bc.offset;
15080
+ const tag = readU8(bc);
15081
+ switch (tag) {
15082
+ case 0:
15083
+ return "PENDING";
15084
+ case 1:
15085
+ return "RUNNING";
15086
+ case 2:
15087
+ return "COMPLETED";
15088
+ case 3:
15089
+ return "FAILED";
15090
+ case 4:
15091
+ return "EXHAUSTED";
15092
+ default: {
15093
+ bc.offset = offset;
15094
+ throw new BareError(offset, "invalid tag");
14972
15095
  }
14973
- value = value[segment];
14974
- }
14975
- return value;
14976
- }
14977
- function isRecord(value) {
14978
- if (typeof value !== "object" || value === null || Array.isArray(value)) {
14979
- return false;
14980
15096
  }
14981
- const prototype = Object.getPrototypeOf(value);
14982
- return prototype === Object.prototype || prototype === null;
14983
- }
14984
- function formatActionPath(path2) {
14985
- return path2.length === 0 ? "actions" : `Action \`${path2.join(".")}\``;
14986
15097
  }
14987
- var DEFAULT_SLEEP_GRACE_PERIOD = 15e3;
14988
- var ACTOR_CONTEXT_INTERNAL_SYMBOL = /* @__PURE__ */ Symbol(
14989
- "rivetkit.actor_context_internal"
14990
- );
14991
- var RAW_STATE_SYMBOL = /* @__PURE__ */ Symbol("rivetkit.raw_state");
14992
- var CONN_STATE_MANAGER_SYMBOL = /* @__PURE__ */ Symbol("rivetkit.conn_state_manager");
14993
- var zFunction = () => external_exports.custom((val) => typeof val === "function");
14994
- var zActionTree = external_exports.custom((value) => {
14995
- if (typeof value !== "object" || value === null || Array.isArray(value)) {
14996
- return false;
14997
- }
14998
- const prototype = Object.getPrototypeOf(value);
14999
- return prototype === Object.prototype || prototype === null;
15000
- }).superRefine((actions, ctx) => {
15001
- try {
15002
- flattenActionHandlers(actions);
15003
- } catch (error46) {
15004
- ctx.addIssue({
15005
- code: "custom",
15006
- message: error46 instanceof Error ? error46.message : "Invalid action definition"
15007
- });
15008
- }
15009
- });
15010
- var WorkflowInspectorConfigSchema = external_exports.object({
15011
- getHistory: zFunction(),
15012
- onHistoryUpdated: zFunction().optional(),
15013
- replayFromStep: zFunction().optional()
15014
- });
15015
- var RunInspectorConfigSchema = external_exports.object({
15016
- workflow: WorkflowInspectorConfigSchema.optional()
15017
- }).optional();
15018
- var BUILTIN_INSPECTOR_TAB_IDS = [
15019
- "workflow",
15020
- "database",
15021
- "state",
15022
- "queue",
15023
- "schedules",
15024
- "connections",
15025
- "console"
15026
- ];
15027
- var BuiltinInspectorTabIdSchema = external_exports.enum(BUILTIN_INSPECTOR_TAB_IDS);
15028
- var CUSTOM_INSPECTOR_TAB_ID_RE = /^[A-Za-z0-9_-]+$/;
15029
- var CustomInspectorTabEntrySchema = external_exports.object({
15030
- id: external_exports.string().regex(
15031
- CUSTOM_INSPECTOR_TAB_ID_RE,
15032
- "inspector.tabs[].id must contain only letters, digits, underscore, or dash"
15033
- ),
15034
- label: external_exports.string().min(1),
15035
- source: external_exports.string().min(1),
15036
- /**
15037
- * Optional icon id. The dashboard maps strings to glyphs (see its
15038
- * icon registry); unknown ids fall back to a generic icon.
15039
- */
15040
- icon: external_exports.string().min(1).optional(),
15041
- hidden: external_exports.literal(false).optional()
15042
- }).strict();
15043
- var HideInspectorTabEntrySchema = external_exports.object({
15044
- id: BuiltinInspectorTabIdSchema,
15045
- hidden: external_exports.literal(true)
15046
- }).strict();
15047
- var InspectorTabEntrySchema = external_exports.union([
15048
- CustomInspectorTabEntrySchema,
15049
- HideInspectorTabEntrySchema
15050
- ]);
15051
- var ActorInspectorConfigSchema = external_exports.object({
15052
- tabs: external_exports.array(InspectorTabEntrySchema).default(() => [])
15053
- }).strict().refine(
15054
- (data) => {
15055
- const ids = data.tabs.map((t) => t.id);
15056
- return new Set(ids).size === ids.length;
15057
- },
15058
- { message: "Duplicate id in inspector.tabs", path: ["tabs"] }
15059
- ).refine(
15060
- (data) => {
15061
- const builtinSet = new Set(BUILTIN_INSPECTOR_TAB_IDS);
15062
- return data.tabs.every(
15063
- (t) => t.hidden === true || !builtinSet.has(t.id)
15064
- );
15065
- },
15066
- {
15067
- message: "Custom inspector tab id collides with a built-in (use hidden: true to hide a built-in)",
15068
- path: ["tabs"]
15069
- }
15070
- );
15071
- var RunConfigSchema = external_exports.object({
15072
- /** Display name for the actor in the Inspector UI. */
15073
- name: external_exports.string().optional(),
15074
- /** Icon for the actor in the Inspector UI. Can be an emoji or FontAwesome icon name. */
15075
- icon: external_exports.string().optional(),
15076
- /** The run handler function. */
15077
- run: zFunction(),
15078
- /** Inspector integration for long-running run handlers. */
15079
- inspector: RunInspectorConfigSchema.optional()
15080
- });
15081
- var RUN_FUNCTION_CONFIG_SYMBOL = /* @__PURE__ */ Symbol.for(
15082
- "rivetkit.run_function_config"
15083
- );
15084
- var zRunHandler = external_exports.union([zFunction(), RunConfigSchema]).optional();
15085
- function getRunFunction(run) {
15086
- if (!run) return void 0;
15087
- if (typeof run === "function") return run;
15088
- return run.run;
15098
+ function readWorkflowSleepState(bc) {
15099
+ const offset = bc.offset;
15100
+ const tag = readU8(bc);
15101
+ switch (tag) {
15102
+ case 0:
15103
+ return "PENDING";
15104
+ case 1:
15105
+ return "COMPLETED";
15106
+ case 2:
15107
+ return "INTERRUPTED";
15108
+ default: {
15109
+ bc.offset = offset;
15110
+ throw new BareError(offset, "invalid tag");
15111
+ }
15112
+ }
15089
15113
  }
15090
- function getRunMetadata(run) {
15091
- if (!run) return {};
15092
- if (typeof run === "function") {
15093
- const config3 = run[RUN_FUNCTION_CONFIG_SYMBOL];
15094
- if (!config3) return {};
15095
- return { name: config3.name, icon: config3.icon };
15114
+ function readWorkflowBranchStatusType(bc) {
15115
+ const offset = bc.offset;
15116
+ const tag = readU8(bc);
15117
+ switch (tag) {
15118
+ case 0:
15119
+ return "PENDING";
15120
+ case 1:
15121
+ return "RUNNING";
15122
+ case 2:
15123
+ return "COMPLETED";
15124
+ case 3:
15125
+ return "FAILED";
15126
+ case 4:
15127
+ return "CANCELLED";
15128
+ default: {
15129
+ bc.offset = offset;
15130
+ throw new BareError(offset, "invalid tag");
15131
+ }
15096
15132
  }
15097
- return { name: run.name, icon: run.icon };
15098
15133
  }
15099
- function getRunInspectorConfig(run, actor2) {
15100
- if (!run) return void 0;
15101
- if (typeof run === "function") {
15102
- const config3 = run[RUN_FUNCTION_CONFIG_SYMBOL];
15103
- return (config3 == null ? void 0 : config3.inspectorFactory) ? config3.inspectorFactory(actor2) : config3 == null ? void 0 : config3.inspector;
15134
+ function read0(bc) {
15135
+ return readBool(bc) ? readWorkflowCbor(bc) : null;
15136
+ }
15137
+ function read1(bc) {
15138
+ return readBool(bc) ? readString(bc) : null;
15139
+ }
15140
+ function readWorkflowStepEntry(bc) {
15141
+ return {
15142
+ output: read0(bc),
15143
+ error: read1(bc)
15144
+ };
15145
+ }
15146
+ function readWorkflowLoopEntry(bc) {
15147
+ return {
15148
+ state: readWorkflowCbor(bc),
15149
+ iteration: readU32(bc),
15150
+ output: read0(bc)
15151
+ };
15152
+ }
15153
+ function readWorkflowSleepEntry(bc) {
15154
+ return {
15155
+ deadline: readU64(bc),
15156
+ state: readWorkflowSleepState(bc)
15157
+ };
15158
+ }
15159
+ function readWorkflowMessageEntry(bc) {
15160
+ return {
15161
+ name: readString(bc),
15162
+ messageData: readWorkflowCbor(bc)
15163
+ };
15164
+ }
15165
+ function readWorkflowRollbackCheckpointEntry(bc) {
15166
+ return {
15167
+ name: readString(bc)
15168
+ };
15169
+ }
15170
+ function readWorkflowBranchStatus(bc) {
15171
+ return {
15172
+ status: readWorkflowBranchStatusType(bc),
15173
+ output: read0(bc),
15174
+ error: read1(bc)
15175
+ };
15176
+ }
15177
+ function read2(bc) {
15178
+ const len = readUintSafe(bc);
15179
+ const result = /* @__PURE__ */ new Map();
15180
+ for (let i = 0; i < len; i++) {
15181
+ const offset = bc.offset;
15182
+ const key = readString(bc);
15183
+ if (result.has(key)) {
15184
+ bc.offset = offset;
15185
+ throw new BareError(offset, "duplicated key");
15186
+ }
15187
+ result.set(key, readWorkflowBranchStatus(bc));
15104
15188
  }
15105
- return run.inspector;
15189
+ return result;
15106
15190
  }
15107
- function disposeRunInspector(run, actorId) {
15108
- var _a2;
15109
- if (!run || typeof run !== "function") {
15110
- return;
15191
+ function readWorkflowJoinEntry(bc) {
15192
+ return {
15193
+ branches: read2(bc)
15194
+ };
15195
+ }
15196
+ function readWorkflowRaceEntry(bc) {
15197
+ return {
15198
+ winner: read1(bc),
15199
+ branches: read2(bc)
15200
+ };
15201
+ }
15202
+ function readWorkflowRemovedEntry(bc) {
15203
+ return {
15204
+ originalType: readString(bc),
15205
+ originalName: read1(bc)
15206
+ };
15207
+ }
15208
+ function readWorkflowVersionCheckEntry(bc) {
15209
+ return {
15210
+ resolved: readU32(bc),
15211
+ latest: readU32(bc)
15212
+ };
15213
+ }
15214
+ function readWorkflowEntryKind(bc) {
15215
+ const offset = bc.offset;
15216
+ const tag = readU8(bc);
15217
+ switch (tag) {
15218
+ case 0:
15219
+ return { tag: "WorkflowStepEntry", val: readWorkflowStepEntry(bc) };
15220
+ case 1:
15221
+ return { tag: "WorkflowLoopEntry", val: readWorkflowLoopEntry(bc) };
15222
+ case 2:
15223
+ return {
15224
+ tag: "WorkflowSleepEntry",
15225
+ val: readWorkflowSleepEntry(bc)
15226
+ };
15227
+ case 3:
15228
+ return {
15229
+ tag: "WorkflowMessageEntry",
15230
+ val: readWorkflowMessageEntry(bc)
15231
+ };
15232
+ case 4:
15233
+ return {
15234
+ tag: "WorkflowRollbackCheckpointEntry",
15235
+ val: readWorkflowRollbackCheckpointEntry(bc)
15236
+ };
15237
+ case 5:
15238
+ return { tag: "WorkflowJoinEntry", val: readWorkflowJoinEntry(bc) };
15239
+ case 6:
15240
+ return { tag: "WorkflowRaceEntry", val: readWorkflowRaceEntry(bc) };
15241
+ case 7:
15242
+ return {
15243
+ tag: "WorkflowRemovedEntry",
15244
+ val: readWorkflowRemovedEntry(bc)
15245
+ };
15246
+ case 8:
15247
+ return {
15248
+ tag: "WorkflowVersionCheckEntry",
15249
+ val: readWorkflowVersionCheckEntry(bc)
15250
+ };
15251
+ default: {
15252
+ bc.offset = offset;
15253
+ throw new BareError(offset, "invalid tag");
15254
+ }
15111
15255
  }
15112
- const config3 = run[RUN_FUNCTION_CONFIG_SYMBOL];
15113
- (_a2 = config3 == null ? void 0 : config3.disposeInspector) == null ? void 0 : _a2.call(config3, actorId);
15114
15256
  }
15115
- var GlobalActorOptionsBaseSchema = external_exports.object({
15116
- /** Display name for the actor in the Inspector UI. */
15117
- name: external_exports.string().optional(),
15118
- /** Icon for the actor in the Inspector UI. Can be an emoji or FontAwesome icon name. */
15119
- icon: external_exports.string().optional(),
15120
- /** Enables the experimental Actor Runtime Socket for this actor. */
15121
- enableActorRuntimeSocket: external_exports.boolean().default(false),
15122
- /**
15123
- * Can hibernate WebSockets for onWebSocket.
15124
- *
15125
- * WebSockets using actions/events are hibernatable by default.
15126
- *
15127
- * @experimental
15128
- **/
15129
- canHibernateWebSocket: external_exports.union([external_exports.boolean(), zFunction()]).default(false)
15130
- }).strict();
15131
- var GlobalActorOptionsSchema = GlobalActorOptionsBaseSchema.prefault(
15132
- () => ({})
15133
- );
15134
- var InstanceActorOptionsBaseSchema = external_exports.object({
15135
- createVarsTimeout: external_exports.number().positive().default(5e3),
15136
- createConnStateTimeout: external_exports.number().positive().default(5e3),
15137
- onBeforeConnectTimeout: external_exports.number().positive().default(5e3),
15138
- onConnectTimeout: external_exports.number().positive().default(5e3),
15139
- onMigrateTimeout: external_exports.number().positive().default(3e4),
15140
- sleepGracePeriod: external_exports.number().positive().default(DEFAULT_SLEEP_GRACE_PERIOD),
15141
- /** @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. */
15142
- onDestroyTimeout: external_exports.number().positive().optional(),
15143
- /** @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. */
15144
- waitUntilTimeout: external_exports.number().positive().optional(),
15145
- stateSaveInterval: external_exports.number().positive().default(1e3),
15146
- actionTimeout: external_exports.number().positive().default(6e4),
15147
- connectionLivenessTimeout: external_exports.number().positive().default(2500),
15148
- connectionLivenessInterval: external_exports.number().positive().default(5e3),
15149
- /** @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. */
15150
- noSleep: external_exports.boolean().default(false),
15151
- sleepTimeout: external_exports.number().positive().default(3e4),
15152
- maxQueueSize: external_exports.number().positive().default(1e3),
15153
- /** Maximum pending one-shot and recurring schedules. */
15154
- maxSchedules: external_exports.number().int().nonnegative().default(1e3),
15155
- maxQueueMessageSize: external_exports.number().positive().default(64 * 1024),
15156
- /** @deprecated Internal storage moved to SQLite and no longer uses KV preloading, so this option is ignored. Will be removed in 2.2.0. */
15157
- preloadMaxWorkflowBytes: external_exports.number().nonnegative().optional(),
15158
- /** @deprecated Internal storage moved to SQLite and no longer uses KV preloading, so this option is ignored. Will be removed in 2.2.0. */
15159
- preloadMaxConnectionsBytes: external_exports.number().nonnegative().optional()
15160
- }).strict();
15161
- var InstanceActorOptionsSchema = InstanceActorOptionsBaseSchema.prefault(() => ({}));
15162
- var ActorOptionsSchema = GlobalActorOptionsBaseSchema.extend(
15163
- InstanceActorOptionsBaseSchema.shape
15164
- ).strict().prefault(() => ({}));
15165
- var ActorConfigSchema = external_exports.object({
15166
- onCreate: zFunction().optional(),
15167
- onDestroy: zFunction().optional(),
15168
- onMigrate: zFunction().optional(),
15169
- onWake: zFunction().optional(),
15170
- onSleep: zFunction().optional(),
15171
- run: zRunHandler,
15172
- onStateChange: zFunction().optional(),
15173
- onBeforeConnect: zFunction().optional(),
15174
- onConnect: zFunction().optional(),
15175
- onDisconnect: zFunction().optional(),
15176
- onBeforeActionResponse: zFunction().optional(),
15177
- onRequest: zFunction().optional(),
15178
- onWebSocket: zFunction().optional(),
15179
- actions: zActionTree.default(() => ({})),
15180
- actionInputSchemas: external_exports.record(external_exports.string(), external_exports.any()).optional(),
15181
- connParamsSchema: external_exports.any().optional(),
15182
- events: external_exports.record(external_exports.string(), external_exports.any()).optional(),
15183
- queues: external_exports.record(external_exports.string(), external_exports.any()).optional(),
15184
- state: external_exports.any().optional(),
15185
- createState: zFunction().optional(),
15186
- connState: external_exports.any().optional(),
15187
- createConnState: zFunction().optional(),
15188
- vars: external_exports.any().optional(),
15189
- db: external_exports.any().optional(),
15190
- createVars: zFunction().optional(),
15191
- options: ActorOptionsSchema,
15192
- inspector: ActorInspectorConfigSchema.optional()
15193
- }).strict().refine(
15194
- (data) => !(data.state !== void 0 && data.createState !== void 0),
15195
- {
15196
- message: "Cannot define both 'state' and 'createState'",
15197
- path: ["state"]
15257
+ function readWorkflowEntry(bc) {
15258
+ return {
15259
+ id: readString(bc),
15260
+ location: readWorkflowLocation(bc),
15261
+ kind: readWorkflowEntryKind(bc)
15262
+ };
15263
+ }
15264
+ function read3(bc) {
15265
+ return readBool(bc) ? readU64(bc) : null;
15266
+ }
15267
+ function readWorkflowEntryMetadata(bc) {
15268
+ return {
15269
+ status: readWorkflowEntryStatus(bc),
15270
+ error: read1(bc),
15271
+ attempts: readU32(bc),
15272
+ lastAttemptAt: readU64(bc),
15273
+ createdAt: readU64(bc),
15274
+ completedAt: read3(bc),
15275
+ rollbackCompletedAt: read3(bc),
15276
+ rollbackError: read1(bc)
15277
+ };
15278
+ }
15279
+ function read4(bc) {
15280
+ const len = readUintSafe(bc);
15281
+ if (len === 0) {
15282
+ return [];
15198
15283
  }
15199
- ).refine(
15200
- (data) => !(data.connState !== void 0 && data.createConnState !== void 0),
15201
- {
15202
- message: "Cannot define both 'connState' and 'createConnState'",
15203
- path: ["connState"]
15284
+ const result = [readString(bc)];
15285
+ for (let i = 1; i < len; i++) {
15286
+ result[i] = readString(bc);
15204
15287
  }
15205
- ).refine(
15206
- (data) => !(data.vars !== void 0 && data.createVars !== void 0),
15207
- {
15208
- message: "Cannot define both 'vars' and 'createVars'",
15209
- path: ["vars"]
15288
+ return result;
15289
+ }
15290
+ function read5(bc) {
15291
+ const len = readUintSafe(bc);
15292
+ if (len === 0) {
15293
+ return [];
15210
15294
  }
15211
- );
15212
- var DocActorOptionsSchema = external_exports.object({
15213
- name: external_exports.string().optional().describe("Display name for the actor in the Inspector UI."),
15214
- icon: external_exports.string().optional().describe(
15215
- "Icon for the actor in the Inspector UI. Can be an emoji (e.g., '\u{1F680}') or FontAwesome icon name (e.g., 'rocket')."
15216
- ),
15217
- enableActorRuntimeSocket: external_exports.boolean().optional().describe(
15218
- "Enables the experimental Actor Runtime Socket for this actor. Default: false"
15219
- ),
15220
- createVarsTimeout: external_exports.number().optional().describe("Timeout in ms for createVars handler. Default: 5000"),
15221
- createConnStateTimeout: external_exports.number().optional().describe(
15222
- "Timeout in ms for createConnState handler. Default: 5000"
15223
- ),
15224
- onMigrateTimeout: external_exports.number().optional().describe("Timeout in ms for onMigrate handler. Default: 30000"),
15225
- onBeforeConnectTimeout: external_exports.number().optional().describe(
15226
- "Timeout in ms for onBeforeConnect handler. Default: 5000"
15227
- ),
15228
- onConnectTimeout: external_exports.number().optional().describe("Timeout in ms for onConnect handler. Default: 5000"),
15229
- sleepGracePeriod: external_exports.number().optional().describe(
15230
- `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}.`
15231
- ),
15232
- onDestroyTimeout: external_exports.number().optional().describe(
15233
- "Deprecated. Folded into sleepGracePeriod, which now bounds the entire graceful shutdown window for both sleep and destroy. Will be removed in 2.2.0."
15234
- ),
15235
- waitUntilTimeout: external_exports.number().optional().describe(
15236
- "Deprecated. Folded into sleepGracePeriod, which now bounds the entire graceful shutdown window for both sleep and destroy. Will be removed in 2.2.0."
15237
- ),
15238
- stateSaveInterval: external_exports.number().optional().describe(
15239
- "Interval in ms between automatic state saves. Default: 1000"
15240
- ),
15241
- actionTimeout: external_exports.number().optional().describe("Timeout in ms for action handlers. Default: 60000"),
15242
- connectionLivenessTimeout: external_exports.number().optional().describe(
15243
- "Timeout in ms for connection liveness checks. Default: 2500"
15244
- ),
15245
- connectionLivenessInterval: external_exports.number().optional().describe(
15246
- "Interval in ms between connection liveness checks. Default: 5000"
15247
- ),
15248
- noSleep: external_exports.boolean().optional().describe(
15249
- "Deprecated. If true, the actor will never sleep. Use c.keepAwake(promise) to scope keep-awake to a specific operation instead. Default: false"
15250
- ),
15251
- sleepTimeout: external_exports.number().optional().describe(
15252
- "Time in ms of inactivity before the actor sleeps. Default: 30000"
15253
- ),
15254
- maxQueueSize: external_exports.number().optional().describe(
15255
- "Maximum number of queue messages before rejecting new messages. Default: 1000"
15256
- ),
15257
- maxSchedules: external_exports.number().int().nonnegative().optional().describe(
15258
- "Maximum pending one-shot and recurring schedules before rejecting new schedules. Default: 1000"
15259
- ),
15260
- maxQueueMessageSize: external_exports.number().optional().describe(
15261
- "Maximum size of each queue message in bytes. Default: 65536"
15262
- ),
15263
- canHibernateWebSocket: external_exports.boolean().optional().describe(
15264
- "Whether WebSockets using onWebSocket can be hibernated. WebSockets using actions/events are hibernatable by default. Default: false"
15265
- )
15266
- }).describe("Actor options for timeouts and behavior configuration.");
15267
- var DocActorConfigSchema = external_exports.object({
15268
- state: external_exports.unknown().optional().describe(
15269
- "Initial state value for the actor. Cannot be used with createState."
15270
- ),
15271
- createState: external_exports.unknown().optional().describe(
15272
- "Function to create initial state. Receives context and input. Cannot be used with state."
15273
- ),
15274
- connState: external_exports.unknown().optional().describe(
15275
- "Initial connection state value. Cannot be used with createConnState."
15276
- ),
15277
- createConnState: external_exports.unknown().optional().describe(
15278
- "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."
15279
- ),
15280
- vars: external_exports.unknown().optional().describe(
15281
- "Initial ephemeral variables value. Cannot be used with createVars."
15282
- ),
15283
- createVars: external_exports.unknown().optional().describe(
15284
- "Function to create ephemeral variables. Receives context and driver context. Cannot be used with vars."
15285
- ),
15286
- db: external_exports.unknown().optional().describe("Database provider instance for the actor."),
15287
- onCreate: external_exports.unknown().optional().describe(
15288
- "Called when the actor is first initialized. Use to initialize state."
15289
- ),
15290
- onDestroy: external_exports.unknown().optional().describe("Called when the actor is destroyed."),
15291
- onMigrate: external_exports.unknown().optional().describe(
15292
- "Called on every actor start after persisted state loads and before onWake. Use for repeatable schema migrations."
15293
- ),
15294
- onWake: external_exports.unknown().optional().describe(
15295
- "Called when the actor wakes up and is ready to receive connections and actions."
15296
- ),
15297
- onSleep: external_exports.unknown().optional().describe(
15298
- "Called when the actor is stopping or sleeping. Use to clean up resources."
15299
- ),
15300
- run: external_exports.unknown().optional().describe(
15301
- "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."
15302
- ),
15303
- onStateChange: external_exports.unknown().optional().describe(
15304
- "Called when the actor's state changes. State changes within this hook won't trigger recursion."
15305
- ),
15306
- onBeforeConnect: external_exports.unknown().optional().describe(
15307
- "Called before a client connects. Throw an error to reject the connection. The pending connection is not visible in c.conns while this runs."
15308
- ),
15309
- onConnect: external_exports.unknown().optional().describe(
15310
- "Called when a client successfully connects. The connection is visible in c.conns before this runs."
15311
- ),
15312
- onDisconnect: external_exports.unknown().optional().describe("Called when a client disconnects."),
15313
- onBeforeActionResponse: external_exports.unknown().optional().describe(
15314
- "Called before sending an action response. Use to transform output."
15315
- ),
15316
- onRequest: external_exports.unknown().optional().describe(
15317
- "Called for raw HTTP requests to /actors/{name}/http/* endpoints."
15318
- ),
15319
- onWebSocket: external_exports.unknown().optional().describe(
15320
- "Called for raw WebSocket connections to /actors/{name}/websocket/* endpoints."
15321
- ),
15322
- actions: external_exports.record(external_exports.string(), external_exports.unknown()).optional().describe(
15323
- "Tree of action names or nested groups to handler functions. Nested paths use dot-separated low-level action names. Defaults to an empty object."
15324
- ),
15325
- actionInputSchemas: external_exports.record(external_exports.string(), external_exports.unknown()).optional().describe(
15326
- "Optional schemas for validating action argument tuples in native runtimes. May mirror nested action groups or use dot-separated low-level action names."
15327
- ),
15328
- connParamsSchema: external_exports.unknown().optional().describe(
15329
- "Optional schema for validating connection params in native runtimes."
15330
- ),
15331
- events: external_exports.record(external_exports.string(), external_exports.unknown()).optional().describe("Map of event names to schemas."),
15332
- queues: external_exports.record(external_exports.string(), external_exports.unknown()).optional().describe("Map of queue names to schemas."),
15333
- options: DocActorOptionsSchema.optional()
15334
- }).describe("Actor configuration passed to the actor() function.");
15295
+ const result = [readWorkflowEntry(bc)];
15296
+ for (let i = 1; i < len; i++) {
15297
+ result[i] = readWorkflowEntry(bc);
15298
+ }
15299
+ return result;
15300
+ }
15301
+ function read6(bc) {
15302
+ const len = readUintSafe(bc);
15303
+ const result = /* @__PURE__ */ new Map();
15304
+ for (let i = 0; i < len; i++) {
15305
+ const offset = bc.offset;
15306
+ const key = readString(bc);
15307
+ if (result.has(key)) {
15308
+ bc.offset = offset;
15309
+ throw new BareError(offset, "duplicated key");
15310
+ }
15311
+ result.set(key, readWorkflowEntryMetadata(bc));
15312
+ }
15313
+ return result;
15314
+ }
15315
+ function readWorkflowHistory(bc) {
15316
+ return {
15317
+ nameRegistry: read4(bc),
15318
+ entries: read5(bc),
15319
+ entryMetadata: read6(bc)
15320
+ };
15321
+ }
15322
+ function decodeWorkflowHistory(bytes) {
15323
+ const bc = new ByteCursor(bytes, config2);
15324
+ const result = readWorkflowHistory(bc);
15325
+ if (bc.offset < bc.view.byteLength) {
15326
+ throw new BareError(bc.offset, "remaining bytes");
15327
+ }
15328
+ return result;
15329
+ }
15330
+ function decodeWorkflowHistoryTransport(data) {
15331
+ return decodeWorkflowHistory(toUint8Array(data));
15332
+ }
15335
15333
 
15336
15334
  // ../rivetkit/dist/tsup/chunk-JI6GZ2C2.js
15337
15335
  var EMPTY_KEY = "/";
@@ -15450,35 +15448,7 @@ function removePrefixFromKey(prefixedKey) {
15450
15448
  return prefixedKey.slice(KEYS.KV.length);
15451
15449
  }
15452
15450
 
15453
- // ../rivetkit/dist/tsup/chunk-7AFZMFPQ.js
15454
- var MIGRATION_TRANSACTION_TIMEOUT_MS = 5 * 6e4;
15455
- var AsyncMutex = class {
15456
- #locked = false;
15457
- #waiting = [];
15458
- async acquire() {
15459
- while (this.#locked) {
15460
- await new Promise((resolve) => this.#waiting.push(resolve));
15461
- }
15462
- this.#locked = true;
15463
- }
15464
- release() {
15465
- this.#locked = false;
15466
- const next = this.#waiting.shift();
15467
- if (next) {
15468
- next();
15469
- }
15470
- }
15471
- async run(fn) {
15472
- await this.acquire();
15473
- try {
15474
- return await fn();
15475
- } finally {
15476
- this.release();
15477
- }
15478
- }
15479
- };
15480
-
15481
- // ../rivetkit/dist/tsup/chunk-7PVR3YAW.js
15451
+ // ../rivetkit/dist/tsup/chunk-B7N2TMLF.js
15482
15452
  function logger() {
15483
15453
  return getLogger("actor-client");
15484
15454
  }
@@ -15516,7 +15486,35 @@ async function importWebSocket() {
15516
15486
  return webSocketPromise;
15517
15487
  }
15518
15488
 
15519
- // ../rivetkit/dist/tsup/chunk-JZ4SICLQ.js
15489
+ // ../rivetkit/dist/tsup/chunk-7AFZMFPQ.js
15490
+ var MIGRATION_TRANSACTION_TIMEOUT_MS = 5 * 6e4;
15491
+ var AsyncMutex = class {
15492
+ #locked = false;
15493
+ #waiting = [];
15494
+ async acquire() {
15495
+ while (this.#locked) {
15496
+ await new Promise((resolve) => this.#waiting.push(resolve));
15497
+ }
15498
+ this.#locked = true;
15499
+ }
15500
+ release() {
15501
+ this.#locked = false;
15502
+ const next = this.#waiting.shift();
15503
+ if (next) {
15504
+ next();
15505
+ }
15506
+ }
15507
+ async run(fn) {
15508
+ await this.acquire();
15509
+ try {
15510
+ return await fn();
15511
+ } finally {
15512
+ this.release();
15513
+ }
15514
+ }
15515
+ };
15516
+
15517
+ // ../rivetkit/dist/tsup/chunk-OISWZDAF.js
15520
15518
  var import_invariant2 = __toESM(require_invariant(), 1);
15521
15519
 
15522
15520
  // ../../../node_modules/.pnpm/p-retry@6.2.1/node_modules/p-retry/index.js
@@ -15694,7 +15692,7 @@ function createVersionedDataHandler(config3) {
15694
15692
  return new VersionedDataHandler(config3);
15695
15693
  }
15696
15694
 
15697
- // ../rivetkit/dist/tsup/chunk-JZ4SICLQ.js
15695
+ // ../rivetkit/dist/tsup/chunk-OISWZDAF.js
15698
15696
  var import_invariant3 = __toESM(require_invariant(), 1);
15699
15697
  var import_invariant4 = __toESM(require_invariant(), 1);
15700
15698
  var PATH_CONNECT = "/connect";
@@ -28665,7 +28663,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
28665
28663
  var _a22;
28666
28664
  const { ctx } = unwrapTsfnPayload(error46, payload);
28667
28665
  const history = (_a22 = getNativeWorkflowInspector(ctx)) == null ? void 0 : _a22.getHistory();
28668
- return history == null ? void 0 : encodeValue(history);
28666
+ return history == null ? void 0 : toUint8Array(history);
28669
28667
  }
28670
28668
  ) : void 0,
28671
28669
  replayWorkflow: getRunInspectorConfig(config3.run) !== void 0 ? wrapNativeCallback(
@@ -28681,7 +28679,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
28681
28679
  const history = await workflowInspector.replayFromStep(
28682
28680
  entryId
28683
28681
  ) ?? null;
28684
- return history == null ? void 0 : encodeValue(history);
28682
+ return history == null ? void 0 : toUint8Array(history);
28685
28683
  }
28686
28684
  ) : void 0,
28687
28685
  actions: Object.fromEntries(