@rivetkit/supabase 2.3.13 → 2.3.14

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