@rivetkit/supabase 2.3.16-rc.3 → 2.3.16

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