rivetkit 2.1.1 → 2.1.2
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.
- package/dist/browser/client.d.ts +22 -2
- package/dist/browser/client.js +1 -1
- package/dist/browser/client.js.map +1 -1
- package/dist/browser/inspector/client.js +1 -1
- package/dist/browser/inspector/client.js.map +1 -1
- package/dist/inspector.tar.gz +0 -0
- package/dist/tsup/{chunk-65RINRXE.cjs → chunk-772NPMTY.cjs} +98 -98
- package/dist/tsup/{chunk-65RINRXE.cjs.map → chunk-772NPMTY.cjs.map} +1 -1
- package/dist/tsup/{chunk-NAM3D5W5.js → chunk-BFI4LYS2.js} +5 -6
- package/dist/tsup/chunk-BFI4LYS2.js.map +1 -0
- package/dist/tsup/{chunk-OONQLPOH.js → chunk-BSIJG3LG.js} +7 -7
- package/dist/tsup/chunk-BSIJG3LG.js.map +1 -0
- package/dist/tsup/{chunk-WPDQXB7R.cjs → chunk-GVQAVU7R.cjs} +4 -4
- package/dist/tsup/{chunk-WPDQXB7R.cjs.map → chunk-GVQAVU7R.cjs.map} +1 -1
- package/dist/tsup/{chunk-AWJU3AZB.js → chunk-HB4RGGMC.js} +5 -5
- package/dist/tsup/{chunk-LNDVGTPQ.cjs → chunk-HFWRHT5T.cjs} +24 -10
- package/dist/tsup/chunk-HFWRHT5T.cjs.map +1 -0
- package/dist/tsup/{chunk-Q5CW77IT.cjs → chunk-MNS5LY6M.cjs} +81 -75
- package/dist/tsup/chunk-MNS5LY6M.cjs.map +1 -0
- package/dist/tsup/{chunk-ZR76ZGYS.cjs → chunk-NXEHFUDB.cjs} +20 -20
- package/dist/tsup/chunk-NXEHFUDB.cjs.map +1 -0
- package/dist/tsup/{chunk-XQWBEBLD.js → chunk-PSUVV4HM.js} +23 -9
- package/dist/tsup/{chunk-XQWBEBLD.js.map → chunk-PSUVV4HM.js.map} +1 -1
- package/dist/tsup/{chunk-VBU4P2IX.js → chunk-PW3YONDJ.js} +2 -2
- package/dist/tsup/{chunk-AGERRJ32.cjs → chunk-PZAV6PP2.cjs} +152 -152
- package/dist/tsup/{chunk-AGERRJ32.cjs.map → chunk-PZAV6PP2.cjs.map} +1 -1
- package/dist/tsup/{chunk-LPXB254R.cjs → chunk-QABDKI3W.cjs} +236 -237
- package/dist/tsup/chunk-QABDKI3W.cjs.map +1 -0
- package/dist/tsup/{chunk-T4PQK4WA.js → chunk-RHUII57M.js} +7 -8
- package/dist/tsup/chunk-RHUII57M.js.map +1 -0
- package/dist/tsup/{chunk-MMUXNMJF.cjs → chunk-RMJJE43B.cjs} +2 -2
- package/dist/tsup/{chunk-MMUXNMJF.cjs.map → chunk-RMJJE43B.cjs.map} +1 -1
- package/dist/tsup/{chunk-WTRB56DR.js → chunk-TDFDR7AO.js} +2 -2
- package/dist/tsup/{chunk-F5B36GL7.cjs → chunk-UZV7NXC6.cjs} +31 -32
- package/dist/tsup/chunk-UZV7NXC6.cjs.map +1 -0
- package/dist/tsup/{chunk-MICYEINX.js → chunk-VMX4I4MP.js} +10 -4
- package/dist/tsup/{chunk-MICYEINX.js.map → chunk-VMX4I4MP.js.map} +1 -1
- package/dist/tsup/{chunk-IZ4M5TJU.js → chunk-WUXR722E.js} +2 -2
- package/dist/tsup/{chunk-IZ4M5TJU.js.map → chunk-WUXR722E.js.map} +1 -1
- package/dist/tsup/{chunk-74ER4FEE.js → chunk-YQ5P6KMN.js} +4 -4
- package/dist/tsup/chunk-YQ5P6KMN.js.map +1 -0
- package/dist/tsup/{chunk-FUBHHHK5.cjs → chunk-ZHQDRRMY.cjs} +3 -3
- package/dist/tsup/{chunk-FUBHHHK5.cjs.map → chunk-ZHQDRRMY.cjs.map} +1 -1
- package/dist/tsup/client/mod.cjs +6 -6
- package/dist/tsup/client/mod.d.cts +2 -2
- package/dist/tsup/client/mod.d.ts +2 -2
- package/dist/tsup/client/mod.js +5 -5
- package/dist/tsup/common/log.cjs +2 -2
- package/dist/tsup/common/log.js +1 -1
- package/dist/tsup/common/websocket.cjs +3 -3
- package/dist/tsup/common/websocket.js +2 -2
- package/dist/tsup/{config-BFqid9Gr.d.ts → config-P3XujgRr.d.ts} +23 -3
- package/dist/tsup/{config-CAZphOS1.d.cts → config-_gfywqqI.d.cts} +23 -3
- package/dist/tsup/{context-7X-Dm6_f.d.cts → context-Bxd8Cx4H.d.cts} +5 -5
- package/dist/tsup/{context-x9zKhx5T.d.ts → context-uNA4TRn3.d.ts} +5 -5
- package/dist/tsup/{driver-DYXwJR5D.d.cts → driver-BcLvZcKl.d.cts} +1 -1
- package/dist/tsup/{driver-Bxv62E2p.d.ts → driver-CPGHKXyh.d.ts} +1 -1
- package/dist/tsup/driver-helpers/mod.cjs +6 -4
- package/dist/tsup/driver-helpers/mod.cjs.map +1 -1
- package/dist/tsup/driver-helpers/mod.d.cts +16 -4
- package/dist/tsup/driver-helpers/mod.d.ts +16 -4
- package/dist/tsup/driver-helpers/mod.js +6 -4
- package/dist/tsup/driver-test-suite/mod.cjs +64 -64
- package/dist/tsup/driver-test-suite/mod.cjs.map +1 -1
- package/dist/tsup/driver-test-suite/mod.d.cts +2 -2
- package/dist/tsup/driver-test-suite/mod.d.ts +2 -2
- package/dist/tsup/driver-test-suite/mod.js +14 -14
- package/dist/tsup/driver-test-suite/mod.js.map +1 -1
- package/dist/tsup/inspector/mod.cjs +3 -3
- package/dist/tsup/inspector/mod.js +2 -2
- package/dist/tsup/mod.cjs +8 -8
- package/dist/tsup/mod.d.cts +5 -5
- package/dist/tsup/mod.d.ts +5 -5
- package/dist/tsup/mod.js +7 -7
- package/dist/tsup/serve-test-suite/mod.cjs +126 -118
- package/dist/tsup/serve-test-suite/mod.cjs.map +1 -1
- package/dist/tsup/serve-test-suite/mod.js +37 -29
- package/dist/tsup/serve-test-suite/mod.js.map +1 -1
- package/dist/tsup/test/mod.cjs +10 -10
- package/dist/tsup/test/mod.d.cts +1 -1
- package/dist/tsup/test/mod.d.ts +1 -1
- package/dist/tsup/test/mod.js +6 -6
- package/dist/tsup/utils.cjs +2 -2
- package/dist/tsup/utils.js +1 -1
- package/dist/tsup/workflow/mod.cjs +5 -5
- package/dist/tsup/workflow/mod.d.cts +3 -3
- package/dist/tsup/workflow/mod.d.ts +3 -3
- package/dist/tsup/workflow/mod.js +4 -4
- package/package.json +5 -5
- package/src/actor/instance/queue.ts +67 -9
- package/src/driver-helpers/mod.ts +1 -1
- package/src/driver-helpers/utils.ts +18 -0
- package/src/driver-test-suite/tests/actor-queue.ts +4 -4
- package/src/drivers/file-system/actor.ts +6 -16
- package/src/engine-process/mod.ts +1 -1
- package/src/workflow/context.ts +5 -4
- package/dist/tsup/chunk-74ER4FEE.js.map +0 -1
- package/dist/tsup/chunk-F5B36GL7.cjs.map +0 -1
- package/dist/tsup/chunk-LNDVGTPQ.cjs.map +0 -1
- package/dist/tsup/chunk-LPXB254R.cjs.map +0 -1
- package/dist/tsup/chunk-NAM3D5W5.js.map +0 -1
- package/dist/tsup/chunk-OONQLPOH.js.map +0 -1
- package/dist/tsup/chunk-Q5CW77IT.cjs.map +0 -1
- package/dist/tsup/chunk-T4PQK4WA.js.map +0 -1
- package/dist/tsup/chunk-ZR76ZGYS.cjs.map +0 -1
- /package/dist/tsup/{chunk-AWJU3AZB.js.map → chunk-HB4RGGMC.js.map} +0 -0
- /package/dist/tsup/{chunk-VBU4P2IX.js.map → chunk-PW3YONDJ.js.map} +0 -0
- /package/dist/tsup/{chunk-WTRB56DR.js.map → chunk-TDFDR7AO.js.map} +0 -0
|
@@ -240,7 +240,7 @@ function noopNext() {
|
|
|
240
240
|
// package.json
|
|
241
241
|
var package_default = {
|
|
242
242
|
name: "rivetkit",
|
|
243
|
-
version: "2.1.
|
|
243
|
+
version: "2.1.2",
|
|
244
244
|
description: "Lightweight libraries for building stateful actors on edge platforms",
|
|
245
245
|
license: "Apache-2.0",
|
|
246
246
|
keywords: [
|
|
@@ -1057,4 +1057,4 @@ function detectRuntime() {
|
|
|
1057
1057
|
|
|
1058
1058
|
|
|
1059
1059
|
exports.assertUnreachable = assertUnreachable; exports.isCborSerializable = isCborSerializable; exports.deconstructError = deconstructError; exports.stringifyError = stringifyError; exports.noopNext = noopNext; exports.package_default = package_default; exports.joinSignals = joinSignals; exports.sleep = sleep; exports.interval = interval; exports.VERSION = VERSION2; exports.httpUserAgent = httpUserAgent; exports.getEnvUniversal = getEnvUniversal; exports.dbg = dbg; exports.toUint8Array = toUint8Array; exports.promiseWithResolvers = promiseWithResolvers; exports.setLongTimeout = setLongTimeout; exports.SinglePromiseQueue = SinglePromiseQueue; exports.bufferToArrayBuffer = bufferToArrayBuffer; exports.combineUrlPath = combineUrlPath; exports.arrayBuffersEqual = arrayBuffersEqual; exports.EXTRA_ERROR_LOG = EXTRA_ERROR_LOG; exports.detectRuntime = detectRuntime; exports.getRivetEngine = getRivetEngine; exports.getRivetEndpoint = getRivetEndpoint; exports.getRivetToken = getRivetToken; exports.getRivetNamespace = getRivetNamespace; exports.getRivetRunner = getRivetRunner; exports.getRivetTotalSlots = getRivetTotalSlots; exports.getRivetRunnerKey = getRivetRunnerKey; exports.getRivetRunEngine = getRivetRunEngine; exports.getRivetRunEngineVersion = getRivetRunEngineVersion; exports.getRivetRunnerKind = getRivetRunnerKind; exports.getRivetRunnerVersion = getRivetRunnerVersion; exports.getRivetPublicEndpoint = getRivetPublicEndpoint; exports.getRivetPublicToken = getRivetPublicToken; exports.getRivetkitInspectorToken = getRivetkitInspectorToken; exports.getRivetkitInspectorDisable = getRivetkitInspectorDisable; exports.getRivetkitStoragePath = getRivetkitStoragePath; exports.getLogMessage = getLogMessage; exports.getLogHeaders = getLogHeaders; exports.getNodeEnv = getNodeEnv; exports.getNextPhase = getNextPhase; exports.isDev = isDev; exports.getRivetExperimentalOtel = getRivetExperimentalOtel; exports.LogLevelSchema = LogLevelSchema; exports.getPinoLevel = getPinoLevel; exports.getIncludeTarget = getIncludeTarget; exports.configureBaseLogger = configureBaseLogger; exports.configureDefaultLogger = configureDefaultLogger; exports.getBaseLogger = getBaseLogger; exports.getLogger = getLogger;
|
|
1060
|
-
//# sourceMappingURL=chunk-
|
|
1060
|
+
//# sourceMappingURL=chunk-RMJJE43B.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/rivet/rivet/rivetkit-typescript/packages/rivetkit/dist/tsup/chunk-MMUXNMJF.cjs","../../src/utils/env-vars.ts","../../src/common/utils.ts","../../package.json","../../src/common/log.ts","../../src/common/log-levels.ts","../../src/common/logfmt.ts","../../src/utils.ts"],"names":["logger","VERSION"],"mappings":"AAAA;AACE;AACA;AACA;AACF,wDAA6B;AAC7B;AACA;ACEO,IAAM,eAAA,EAAiB,CAAA,EAAA,GAC7B,eAAA,CAAgB,cAAc,CAAA;AACxB,IAAM,iBAAA,EAAmB,CAAA,EAAA,GAC/B,eAAA,CAAgB,gBAAgB,CAAA;AAC1B,IAAM,cAAA,EAAgB,CAAA,EAAA,GAC5B,eAAA,CAAgB,aAAa,CAAA;AACvB,IAAM,kBAAA,EAAoB,CAAA,EAAA,GAChC,eAAA,CAAgB,iBAAiB,CAAA;AAC3B,IAAM,eAAA,EAAiB,CAAA,EAAA,GAC7B,eAAA,CAAgB,cAAc,CAAA;AACxB,IAAM,mBAAA,EAAqB,CAAA,EAAA,GAA0B;AAC3D,EAAA,MAAM,MAAA,EAAQ,eAAA,CAAgB,mBAAmB,CAAA;AACjD,EAAA,OAAO,MAAA,IAAU,KAAA,EAAA,EAAY,QAAA,CAAS,KAAA,EAAO,EAAE,EAAA,EAAI,KAAA,CAAA;AACpD,CAAA;AACO,IAAM,kBAAA,EAAoB,CAAA,EAAA,GAChC,eAAA,CAAgB,kBAAkB,CAAA;AAC5B,IAAM,kBAAA,EAAoB,CAAA,EAAA,GAChC,eAAA,CAAgB,kBAAkB,EAAA,IAAM,GAAA;AAClC,IAAM,yBAAA,EAA2B,CAAA,EAAA,GACvC,eAAA,CAAgB,0BAA0B,CAAA;AACpC,IAAM,mBAAA,EAAqB,CAAA,EAAA,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,IAAA;AAGG,IAAA;AACH,MAAA;AACjB,IAAA;AAE8B,IAAA;AAGF,IAAA;AACE,MAAA;AAC9B,IAAA;AAEO,IAAA;AACR,EAAA;AAAA;AAGkC,EAAA;AAC7B,IAAA;AACoB,MAAA;AAEA,QAAA;AACN,QAAA;AAGA,QAAA;AACC,QAAA;AAEb,QAAA;AACM,UAAA;AAET,UAAA;AACa,QAAA;AACE,UAAA;AACT,YAAA;AACoB,YAAA;AACzB,UAAA;AAED,UAAA;AACD,QAAA;AACD,MAAA;AACC,IAAA;AACuB,MAAA;AACzB,IAAA;AACD,EAAA;AACD;AAO2E;AACxD,EAAA;AACb,IAAA;AACiB,IAAA;AACtB,EAAA;AACD;AAuBC;AAEgC,EAAA;AAGA,EAAA;AACJ,EAAA;AACU,EAAA;AAGJ,EAAA;AACI,EAAA;AAET,EAAA;AAGC,EAAA;AACX,EAAA;AACW,IAAA;AAC9B,EAAA;AACiB,EAAA;AACkB,IAAA;AACR,MAAA;AACb,QAAA;AACoB,UAAA;AAC/B,QAAA;AACD,MAAA;AACD,IAAA;AACD,EAAA;AAEsC,EAAA;AACC,EAAA;AACxC;AAUW;AACmB,EAAA;AAEI,EAAA;AACA,EAAA;AAEM,EAAA;AACJ,IAAA;AACnC,EAAA;AACO,EAAA;AACR;AAE+B;AACtB,EAAA;AACC,EAAA;AACAC,EAAAA;AACV;AASyC;AAElB,EAAA;AACU,EAAA;AACxB,IAAA;AACR,EAAA;AAC+B,EAAA;AACvB,IAAA;AACR,EAAA;AACO,EAAA;AACR;APikByC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/rivet/rivet/rivetkit-typescript/packages/rivetkit/dist/tsup/chunk-MMUXNMJF.cjs","sourcesContent":[null,"// This file consolidates all environment variables that affect RivetKit's behavior.\n//\n// IMPORTANT: When adding or modifying environment variables here, also update the\n// documentation at: website/src/content/docs/general/environment-variables.mdx\n\nimport { getEnvUniversal } from \"@/utils\";\n\n// Rivet configuration\nexport const getRivetEngine = (): string | undefined =>\n\tgetEnvUniversal(\"RIVET_ENGINE\");\nexport const getRivetEndpoint = (): string | undefined =>\n\tgetEnvUniversal(\"RIVET_ENDPOINT\");\nexport const getRivetToken = (): string | undefined =>\n\tgetEnvUniversal(\"RIVET_TOKEN\");\nexport const getRivetNamespace = (): string | undefined =>\n\tgetEnvUniversal(\"RIVET_NAMESPACE\");\nexport const getRivetRunner = (): string | undefined =>\n\tgetEnvUniversal(\"RIVET_RUNNER\");\nexport const getRivetTotalSlots = (): number | undefined => {\n\tconst value = getEnvUniversal(\"RIVET_TOTAL_SLOTS\");\n\treturn value !== undefined ? parseInt(value, 10) : undefined;\n};\nexport const getRivetRunnerKey = (): string | undefined =>\n\tgetEnvUniversal(\"RIVET_RUNNER_KEY\");\nexport const getRivetRunEngine = (): boolean =>\n\tgetEnvUniversal(\"RIVET_RUN_ENGINE\") === \"1\";\nexport const getRivetRunEngineVersion = (): string | undefined =>\n\tgetEnvUniversal(\"RIVET_RUN_ENGINE_VERSION\");\nexport const getRivetRunnerKind = (): string | undefined =>\n\tgetEnvUniversal(\"RIVET_RUNNER_KIND\");\nexport const getRivetRunnerVersion = (): number | undefined => {\n\tconst value = getEnvUniversal(\"RIVET_RUNNER_VERSION\");\n\treturn value !== undefined ? parseInt(value, 10) : undefined;\n};\nexport const getRivetPublicEndpoint = (): string | undefined =>\n\tgetEnvUniversal(\"RIVET_PUBLIC_ENDPOINT\");\nexport const getRivetPublicToken = (): string | undefined =>\n\tgetEnvUniversal(\"RIVET_PUBLIC_TOKEN\");\n// There is no RIVET_PUBLIC_NAMESPACE because the frontend and backend cannot\n// use different namespaces\n\n// RivetKit configuration\nexport const getRivetkitInspectorToken = (): string | undefined =>\n\tgetEnvUniversal(\"RIVET_INSPECTOR_TOKEN\");\nexport const getRivetkitInspectorDisable = (): boolean =>\n\tgetEnvUniversal(\"RIVET_INSPECTOR_DISABLE\") === \"1\";\nexport const getRivetkitStoragePath = (): string | undefined =>\n\tgetEnvUniversal(\"RIVETKIT_STORAGE_PATH\");\n\n// Logging configuration\n// DEPRECATED: LOG_LEVEL will be removed in a future version\nexport const getLogLevel = (): string | undefined =>\n\tgetEnvUniversal(\"RIVET_LOG_LEVEL\") ?? getEnvUniversal(\"LOG_LEVEL\");\nexport const getLogTarget = (): boolean =>\n\tgetEnvUniversal(\"RIVET_LOG_TARGET\") === \"1\";\nexport const getLogTimestamp = (): boolean =>\n\tgetEnvUniversal(\"RIVET_LOG_TIMESTAMP\") === \"1\";\nexport const getLogMessage = (): boolean =>\n\tgetEnvUniversal(\"RIVET_LOG_MESSAGE\") === \"1\";\nexport const getLogErrorStack = (): boolean =>\n\tgetEnvUniversal(\"RIVET_LOG_ERROR_STACK\") === \"1\";\nexport const getLogHeaders = (): boolean =>\n\tgetEnvUniversal(\"RIVET_LOG_HEADERS\") === \"1\";\n\n// Environment configuration\nexport const getNodeEnv = (): string | undefined => getEnvUniversal(\"NODE_ENV\");\nexport const getNextPhase = (): string | undefined =>\n\tgetEnvUniversal(\"NEXT_PHASE\");\nexport const isDev = (): boolean => getNodeEnv() !== \"production\";\n\n// Experimental\n/**\n * Enables experimental OTel tracing for Rivet Actors.\n *\n * When disabled, actors use an in-memory no-op traces implementation.\n */\nexport const getRivetExperimentalOtel = (): boolean =>\n\tgetEnvUniversal(\"RIVET_EXPERIMENTAL_OTEL\") === \"1\";\n","import type { Next } from \"hono\";\nimport type { ContentfulStatusCode } from \"hono/utils/http-status\";\nimport * as errors from \"@/actor/errors\";\nimport { EXTRA_ERROR_LOG, VERSION } from \"@/utils\";\nimport { getLogErrorStack } from \"@/utils/env-vars\";\nimport type { Logger } from \"./log\";\n\nexport function assertUnreachable(x: never): never {\n\tthrow new Error(`Unreachable case: ${x}`);\n}\n\n/**\n * Safely stringifies an object, ensuring that the stringified object is under a certain size.\n * @param obj any object to stringify\n * @param maxSize maximum size of the stringified object in bytes\n * @returns stringified object\n */\nexport function safeStringify(obj: unknown, maxSize: number) {\n\tlet size = 0;\n\n\tfunction replacer(key: string, value: unknown) {\n\t\tif (value === null || value === undefined) return value;\n\t\tconst valueSize =\n\t\t\ttypeof value === \"string\"\n\t\t\t\t? value.length\n\t\t\t\t: JSON.stringify(value).length;\n\t\tsize += key.length + valueSize;\n\n\t\tif (size > maxSize) {\n\t\t\tthrow new Error(\n\t\t\t\t`JSON object exceeds size limit of ${maxSize} bytes.`,\n\t\t\t);\n\t\t}\n\n\t\treturn value;\n\t}\n\n\treturn JSON.stringify(obj, replacer);\n}\n\n// TODO: Instead of doing this, use a temp var for state and attempt to write\n// it. Roll back state if fails to serialize.\n\n/**\n * Check if a value is CBOR serializable.\n * Optionally pass an onInvalid callback to receive the path to invalid values.\n *\n * For a complete list of supported CBOR tags, see:\n * https://github.com/kriszyp/cbor-x/blob/cc1cf9df8ba72288c7842af1dd374d73e34cdbc1/README.md#list-of-supported-tags-for-decoding\n */\nexport function isCborSerializable(\n\tvalue: unknown,\n\tonInvalid?: (path: string) => void,\n\tcurrentPath = \"\",\n): boolean {\n\t// Handle primitive types directly\n\tif (value === null || value === undefined) {\n\t\treturn true;\n\t}\n\n\tif (typeof value === \"number\") {\n\t\tif (!Number.isFinite(value)) {\n\t\t\tonInvalid?.(currentPath);\n\t\t\treturn false;\n\t\t}\n\t\treturn true;\n\t}\n\n\tif (typeof value === \"boolean\" || typeof value === \"string\") {\n\t\treturn true;\n\t}\n\n\t// Handle BigInt (CBOR tags 2 and 3)\n\tif (typeof value === \"bigint\") {\n\t\treturn true;\n\t}\n\n\t// Handle Date objects (CBOR tags 0 and 1)\n\tif (value instanceof Date) {\n\t\treturn true;\n\t}\n\n\t// Handle typed arrays (CBOR tags 64-82)\n\tif (\n\t\tvalue instanceof Uint8Array ||\n\t\tvalue instanceof Uint8ClampedArray ||\n\t\tvalue instanceof Uint16Array ||\n\t\tvalue instanceof Uint32Array ||\n\t\tvalue instanceof BigUint64Array ||\n\t\tvalue instanceof Int8Array ||\n\t\tvalue instanceof Int16Array ||\n\t\tvalue instanceof Int32Array ||\n\t\tvalue instanceof BigInt64Array ||\n\t\tvalue instanceof Float32Array ||\n\t\tvalue instanceof Float64Array\n\t) {\n\t\treturn true;\n\t}\n\n\t// Handle Map (CBOR tag 259)\n\tif (value instanceof Map) {\n\t\tfor (const [key, val] of value.entries()) {\n\t\t\tconst keyPath = currentPath\n\t\t\t\t? `${currentPath}.key(${String(key)})`\n\t\t\t\t: `key(${String(key)})`;\n\t\t\tconst valPath = currentPath\n\t\t\t\t? `${currentPath}.value(${String(key)})`\n\t\t\t\t: `value(${String(key)})`;\n\t\t\tif (\n\t\t\t\t!isCborSerializable(key, onInvalid, keyPath) ||\n\t\t\t\t!isCborSerializable(val, onInvalid, valPath)\n\t\t\t) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n\n\t// Handle Set (CBOR tag 258)\n\tif (value instanceof Set) {\n\t\tlet index = 0;\n\t\tfor (const item of value.values()) {\n\t\t\tconst itemPath = currentPath\n\t\t\t\t? `${currentPath}.set[${index}]`\n\t\t\t\t: `set[${index}]`;\n\t\t\tif (!isCborSerializable(item, onInvalid, itemPath)) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tindex++;\n\t\t}\n\t\treturn true;\n\t}\n\n\t// Handle RegExp (CBOR tag 27)\n\tif (value instanceof RegExp) {\n\t\treturn true;\n\t}\n\n\t// Handle Error objects (CBOR tag 27)\n\tif (value instanceof Error) {\n\t\treturn true;\n\t}\n\n\t// Handle arrays\n\tif (Array.isArray(value)) {\n\t\tfor (let i = 0; i < value.length; i++) {\n\t\t\tconst itemPath = currentPath ? `${currentPath}[${i}]` : `[${i}]`;\n\t\t\tif (!isCborSerializable(value[i], onInvalid, itemPath)) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n\n\t// Handle plain objects and records (CBOR tags 105, 51, 57344-57599)\n\tif (typeof value === \"object\") {\n\t\t// Allow plain objects and objects with prototypes (for records and named objects)\n\t\tconst proto = Object.getPrototypeOf(value);\n\t\tif (proto !== null && proto !== Object.prototype) {\n\t\t\t// Check if it's a known serializable object type\n\t\t\tconst protoConstructor = value.constructor;\n\t\t\tif (protoConstructor && typeof protoConstructor.name === \"string\") {\n\t\t\t\t// Allow objects with named constructors (records, named objects)\n\t\t\t\t// This includes user-defined classes and built-in objects\n\t\t\t\t// that CBOR can serialize with tag 27 or record tags\n\t\t\t}\n\t\t}\n\n\t\t// Check all properties recursively\n\t\tfor (const key in value) {\n\t\t\tconst propPath = currentPath ? `${currentPath}.${key}` : key;\n\t\t\tif (\n\t\t\t\t!isCborSerializable(\n\t\t\t\t\tvalue[key as keyof typeof value],\n\t\t\t\t\tonInvalid,\n\t\t\t\t\tpropPath,\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n\n\t// Not serializable\n\tonInvalid?.(currentPath);\n\treturn false;\n}\n\nexport interface DeconstructedError {\n\t__type: \"ActorError\";\n\tstatusCode: ContentfulStatusCode;\n\tpublic: boolean;\n\tgroup: string;\n\tcode: string;\n\tmessage: string;\n\tmetadata?: unknown;\n}\n\n/** Deconstructs error in to components that are used to build responses. */\nexport function deconstructError(\n\terror: unknown,\n\tlogger: Logger,\n\textraLog: Record<string, unknown>,\n\texposeInternalError = false,\n): DeconstructedError {\n\t// Build response error information. Only return errors if flagged as public in order to prevent leaking internal behavior.\n\t//\n\t// We log the error here instead of after generating the code & message because we need to log the original error, not the masked internal error.\n\tlet statusCode: ContentfulStatusCode;\n\tlet public_: boolean;\n\tlet group: string;\n\tlet code: string;\n\tlet message: string;\n\tlet metadata: unknown;\n\tif (errors.ActorError.isActorError(error) && error.public) {\n\t\t// Check if error has statusCode (could be ActorError instance or DeconstructedError)\n\t\tstatusCode = (\n\t\t\t\"statusCode\" in error && error.statusCode ? error.statusCode : 400\n\t\t) as ContentfulStatusCode;\n\t\tpublic_ = true;\n\t\tgroup = error.group;\n\t\tcode = error.code;\n\t\tmessage = getErrorMessage(error);\n\t\tmetadata = error.metadata;\n\n\t\tlogger.info({\n\t\t\tmsg: \"public error\",\n\t\t\tgroup,\n\t\t\tcode,\n\t\t\tmessage,\n\t\t\t...EXTRA_ERROR_LOG,\n\t\t\t...extraLog,\n\t\t});\n\t} else if (exposeInternalError) {\n\t\tif (errors.ActorError.isActorError(error)) {\n\t\t\tstatusCode = 500;\n\t\t\tpublic_ = false;\n\t\t\tgroup = error.group;\n\t\t\tcode = error.code;\n\t\t\tmessage = getErrorMessage(error);\n\t\t\tmetadata = error.metadata;\n\n\t\t\tlogger.info({\n\t\t\t\tmsg: \"internal error\",\n\t\t\t\tgroup,\n\t\t\t\tcode,\n\t\t\t\tmessage,\n\t\t\t\tstack: (error as Error)?.stack,\n\t\t\t\t...EXTRA_ERROR_LOG,\n\t\t\t\t...extraLog,\n\t\t\t});\n\t\t} else {\n\t\t\tstatusCode = 500;\n\t\t\tpublic_ = false;\n\t\t\tgroup = \"rivetkit\";\n\t\t\tcode = errors.INTERNAL_ERROR_CODE;\n\t\t\tmessage = getErrorMessage(error);\n\n\t\t\tlogger.info({\n\t\t\t\tmsg: \"internal error\",\n\t\t\t\tgroup,\n\t\t\t\tcode,\n\t\t\t\tmessage,\n\t\t\t\tstack: (error as Error)?.stack,\n\t\t\t\t...EXTRA_ERROR_LOG,\n\t\t\t\t...extraLog,\n\t\t\t});\n\t\t}\n\t} else {\n\t\tstatusCode = 500;\n\t\tpublic_ = false;\n\t\tgroup = \"rivetkit\";\n\t\tcode = errors.INTERNAL_ERROR_CODE;\n\t\tmessage = errors.INTERNAL_ERROR_DESCRIPTION;\n\t\tmetadata = {\n\t\t\t//url: `https://hub.rivet.dev/projects/${actorMetadata.project.slug}/environments/${actorMetadata.environment.slug}/actors?actorId=${actorMetadata.actor.id}`,\n\t\t} satisfies errors.InternalErrorMetadata;\n\n\t\tlogger.warn({\n\t\t\tmsg: \"internal error\",\n\t\t\terror: getErrorMessage(error),\n\t\t\tstack: (error as Error)?.stack,\n\t\t\t...EXTRA_ERROR_LOG,\n\t\t\t...extraLog,\n\t\t});\n\t}\n\n\treturn {\n\t\t__type: \"ActorError\",\n\t\tstatusCode,\n\t\tpublic: public_,\n\t\tgroup,\n\t\tcode,\n\t\tmessage,\n\t\tmetadata,\n\t};\n}\n\nexport function stringifyError(error: unknown): string {\n\tif (error instanceof Error) {\n\t\tif (\n\t\t\ttypeof process !== \"undefined\" &&\n\t\t\tgetLogErrorStack()\n\t\t) {\n\t\t\treturn `${error.name}: ${error.message}${error.stack ? `\\n${error.stack}` : \"\"}`;\n\t\t} else {\n\t\t\treturn `${error.name}: ${error.message}`;\n\t\t}\n\t} else if (typeof error === \"string\") {\n\t\treturn error;\n\t} else if (typeof error === \"object\" && error !== null) {\n\t\ttry {\n\t\t\treturn `${JSON.stringify(error)}`;\n\t\t} catch {\n\t\t\treturn \"[cannot stringify error]\";\n\t\t}\n\t} else {\n\t\treturn `Unknown error: ${getErrorMessage(error)}`;\n\t}\n}\n\nfunction getErrorMessage(err: unknown): string {\n\tif (\n\t\terr &&\n\t\ttypeof err === \"object\" &&\n\t\t\"message\" in err &&\n\t\ttypeof err.message === \"string\"\n\t) {\n\t\treturn err.message;\n\t} else {\n\t\treturn String(err);\n\t}\n}\n\n/** Generates a `Next` handler to pass to middleware in order to be able to call arbitrary middleware. */\nexport function noopNext(): Next {\n\treturn async () => { };\n}\n","{\n\t\"name\": \"rivetkit\",\n\t\"version\": \"2.1.1\",\n\t\"description\": \"Lightweight libraries for building stateful actors on edge platforms\",\n\t\"license\": \"Apache-2.0\",\n\t\"keywords\": [\n\t\t\"rivetkit\",\n\t\t\"stateful\",\n\t\t\"serverless\",\n\t\t\"actors\",\n\t\t\"agents\",\n\t\t\"realtime\",\n\t\t\"websocket\",\n\t\t\"actors\",\n\t\t\"framework\"\n\t],\n\t\"files\": [\n\t\t\"dist\",\n\t\t\"src\",\n\t\t\"deno.json\",\n\t\t\"bun.json\",\n\t\t\"package.json\"\n\t],\n\t\"type\": \"module\",\n\t\"exports\": {\n\t\t\".\": {\n\t\t\t\"import\": {\n\t\t\t\t\"types\": \"./dist/tsup/mod.d.ts\",\n\t\t\t\t\"default\": \"./dist/tsup/mod.js\"\n\t\t\t},\n\t\t\t\"require\": {\n\t\t\t\t\"types\": \"./dist/tsup/mod.d.cts\",\n\t\t\t\t\"default\": \"./dist/tsup/mod.cjs\"\n\t\t\t}\n\t\t},\n\t\t\"./workflow\": {\n\t\t\t\"import\": {\n\t\t\t\t\"types\": \"./dist/tsup/workflow/mod.d.ts\",\n\t\t\t\t\"default\": \"./dist/tsup/workflow/mod.js\"\n\t\t\t},\n\t\t\t\"require\": {\n\t\t\t\t\"types\": \"./dist/tsup/workflow/mod.d.cts\",\n\t\t\t\t\"default\": \"./dist/tsup/workflow/mod.cjs\"\n\t\t\t}\n\t\t},\n\t\t\"./client\": {\n\t\t\t\"import\": {\n\t\t\t\t\"browser\": {\n\t\t\t\t\t\"types\": \"./dist/browser/client.d.ts\",\n\t\t\t\t\t\"default\": \"./dist/browser/client.js\"\n\t\t\t\t},\n\t\t\t\t\"types\": \"./dist/tsup/client/mod.d.ts\",\n\t\t\t\t\"default\": \"./dist/tsup/client/mod.js\"\n\t\t\t},\n\t\t\t\"require\": {\n\t\t\t\t\"types\": \"./dist/tsup/client/mod.d.cts\",\n\t\t\t\t\"default\": \"./dist/tsup/client/mod.cjs\"\n\t\t\t}\n\t\t},\n\t\t\"./log\": {\n\t\t\t\"import\": {\n\t\t\t\t\"types\": \"./dist/tsup/common/log.d.ts\",\n\t\t\t\t\"default\": \"./dist/tsup/common/log.js\"\n\t\t\t},\n\t\t\t\"require\": {\n\t\t\t\t\"types\": \"./dist/tsup/common/log.d.cts\",\n\t\t\t\t\"default\": \"./dist/tsup/common/log.cjs\"\n\t\t\t}\n\t\t},\n\t\t\"./errors\": {\n\t\t\t\"import\": {\n\t\t\t\t\"types\": \"./dist/tsup/actor/errors.d.ts\",\n\t\t\t\t\"default\": \"./dist/tsup/actor/errors.js\"\n\t\t\t},\n\t\t\t\"require\": {\n\t\t\t\t\"types\": \"./dist/tsup/actor/errors.d.cts\",\n\t\t\t\t\"default\": \"./dist/tsup/actor/errors.cjs\"\n\t\t\t}\n\t\t},\n\t\t\"./utils\": {\n\t\t\t\"import\": {\n\t\t\t\t\"types\": \"./dist/tsup/utils.d.ts\",\n\t\t\t\t\"default\": \"./dist/tsup/utils.js\"\n\t\t\t},\n\t\t\t\"require\": {\n\t\t\t\t\"types\": \"./dist/tsup/utils.d.cts\",\n\t\t\t\t\"default\": \"./dist/tsup/utils.cjs\"\n\t\t\t}\n\t\t},\n\t\t\"./driver-helpers\": {\n\t\t\t\"import\": {\n\t\t\t\t\"types\": \"./dist/tsup/driver-helpers/mod.d.ts\",\n\t\t\t\t\"default\": \"./dist/tsup/driver-helpers/mod.js\"\n\t\t\t},\n\t\t\t\"require\": {\n\t\t\t\t\"types\": \"./dist/tsup/driver-helpers/mod.d.cts\",\n\t\t\t\t\"default\": \"./dist/tsup/driver-helpers/mod.cjs\"\n\t\t\t}\n\t\t},\n\t\t\"./driver-helpers/websocket\": {\n\t\t\t\"import\": {\n\t\t\t\t\"types\": \"./dist/tsup/common/websocket.d.ts\",\n\t\t\t\t\"default\": \"./dist/tsup/common/websocket.js\"\n\t\t\t},\n\t\t\t\"require\": {\n\t\t\t\t\"types\": \"./dist/tsup/common/websocket.d.cts\",\n\t\t\t\t\"default\": \"./dist/tsup/common/websocket.cjs\"\n\t\t\t}\n\t\t},\n\t\t\"./driver-test-suite\": {\n\t\t\t\"import\": {\n\t\t\t\t\"types\": \"./dist/tsup/driver-test-suite/mod.d.ts\",\n\t\t\t\t\"default\": \"./dist/tsup/driver-test-suite/mod.js\"\n\t\t\t},\n\t\t\t\"require\": {\n\t\t\t\t\"types\": \"./dist/tsup/driver-test-suite/mod.d.cts\",\n\t\t\t\t\"default\": \"./dist/tsup/driver-test-suite/mod.cjs\"\n\t\t\t}\n\t\t},\n\t\t\"./serve-test-suite\": {\n\t\t\t\"import\": {\n\t\t\t\t\"types\": \"./dist/tsup/serve-test-suite/mod.d.ts\",\n\t\t\t\t\"default\": \"./dist/tsup/serve-test-suite/mod.js\"\n\t\t\t},\n\t\t\t\"require\": {\n\t\t\t\t\"types\": \"./dist/tsup/serve-test-suite/mod.d.cts\",\n\t\t\t\t\"default\": \"./dist/tsup/serve-test-suite/mod.cjs\"\n\t\t\t}\n\t\t},\n\t\t\"./topologies/coordinate\": {\n\t\t\t\"import\": {\n\t\t\t\t\"types\": \"./dist/tsup/topologies/coordinate/mod.d.ts\",\n\t\t\t\t\"default\": \"./dist/tsup/topologies/coordinate/mod.js\"\n\t\t\t},\n\t\t\t\"require\": {\n\t\t\t\t\"types\": \"./dist/tsup/topologies/coordinate/mod.d.cts\",\n\t\t\t\t\"default\": \"./dist/tsup/topologies/coordinate/mod.cjs\"\n\t\t\t}\n\t\t},\n\t\t\"./topologies/partition\": {\n\t\t\t\"import\": {\n\t\t\t\t\"types\": \"./dist/tsup/topologies/partition/mod.d.ts\",\n\t\t\t\t\"default\": \"./dist/tsup/topologies/partition/mod.js\"\n\t\t\t},\n\t\t\t\"require\": {\n\t\t\t\t\"types\": \"./dist/tsup/topologies/partition/mod.d.cts\",\n\t\t\t\t\"default\": \"./dist/tsup/topologies/partition/mod.cjs\"\n\t\t\t}\n\t\t},\n\t\t\"./test\": {\n\t\t\t\"import\": {\n\t\t\t\t\"types\": \"./dist/tsup/test/mod.d.ts\",\n\t\t\t\t\"default\": \"./dist/tsup/test/mod.js\"\n\t\t\t},\n\t\t\t\"require\": {\n\t\t\t\t\"types\": \"./dist/tsup/test/mod.d.cts\",\n\t\t\t\t\"default\": \"./dist/tsup/test/mod.cjs\"\n\t\t\t}\n\t\t},\n\t\t\"./inspector\": {\n\t\t\t\"import\": {\n\t\t\t\t\"types\": \"./dist/tsup/inspector/mod.d.ts\",\n\t\t\t\t\"default\": \"./dist/tsup/inspector/mod.js\"\n\t\t\t},\n\t\t\t\"require\": {\n\t\t\t\t\"types\": \"./dist/tsup/inspector/mod.d.cts\",\n\t\t\t\t\"default\": \"./dist/tsup/inspector/mod.cjs\"\n\t\t\t}\n\t\t},\n\t\t\"./inspector/client\": {\n\t\t\t\"import\": {\n\t\t\t\t\"types\": \"./dist/browser/inspector/client.d.ts\",\n\t\t\t\t\"default\": \"./dist/browser/inspector/client.js\"\n\t\t\t}\n\t\t},\n\t\t\"./db\": {\n\t\t\t\"import\": {\n\t\t\t\t\"types\": \"./dist/tsup/db/mod.d.ts\",\n\t\t\t\t\"default\": \"./dist/tsup/db/mod.js\"\n\t\t\t},\n\t\t\t\"require\": {\n\t\t\t\t\"types\": \"./dist/tsup/db/mod.d.cts\",\n\t\t\t\t\"default\": \"./dist/tsup/db/mod.cjs\"\n\t\t\t}\n\t\t},\n\t\t\"./db/drizzle\": {\n\t\t\t\"import\": {\n\t\t\t\t\"types\": \"./dist/tsup/db/drizzle/mod.d.ts\",\n\t\t\t\t\"default\": \"./dist/tsup/db/drizzle/mod.js\"\n\t\t\t},\n\t\t\t\"require\": {\n\t\t\t\t\"types\": \"./dist/tsup/db/drizzle/mod.d.cts\",\n\t\t\t\t\"default\": \"./dist/tsup/db/drizzle/mod.cjs\"\n\t\t\t}\n\t\t}\n\t},\n\t\"engines\": {\n\t\t\"node\": \">=22.0.0\"\n\t},\n\t\"sideEffects\": [\n\t\t\"./dist/tsup/chunk-*.js\",\n\t\t\"./dist/tsup/chunk-*.cjs\"\n\t],\n\t\"scripts\": {\n \t\t\"build\": \"tsup src/mod.ts src/client/mod.ts src/common/log.ts src/common/websocket.ts src/actor/errors.ts src/topologies/coordinate/mod.ts src/topologies/partition/mod.ts src/utils.ts src/driver-helpers/mod.ts src/driver-test-suite/mod.ts src/serve-test-suite/mod.ts src/test/mod.ts src/inspector/mod.ts src/workflow/mod.ts src/db/mod.ts src/db/drizzle/mod.ts\",\n\t\t\"build:browser\": \"tsup --config tsup.browser.config.ts\",\n\t\t\"build:schema\": \"./scripts/compile-bare.ts compile schemas/client-protocol/v1.bare -o dist/schemas/client-protocol/v1.ts && ./scripts/compile-bare.ts compile schemas/client-protocol/v2.bare -o dist/schemas/client-protocol/v2.ts && ./scripts/compile-bare.ts compile schemas/client-protocol/v3.bare -o dist/schemas/client-protocol/v3.ts && ./scripts/compile-bare.ts compile schemas/file-system-driver/v1.bare -o dist/schemas/file-system-driver/v1.ts && ./scripts/compile-bare.ts compile schemas/file-system-driver/v2.bare -o dist/schemas/file-system-driver/v2.ts && ./scripts/compile-bare.ts compile schemas/file-system-driver/v3.bare -o dist/schemas/file-system-driver/v3.ts && ./scripts/compile-bare.ts compile schemas/actor-persist/v1.bare -o dist/schemas/actor-persist/v1.ts && ./scripts/compile-bare.ts compile schemas/actor-persist/v2.bare -o dist/schemas/actor-persist/v2.ts && ./scripts/compile-bare.ts compile schemas/actor-persist/v3.bare -o dist/schemas/actor-persist/v3.ts && ./scripts/compile-bare.ts compile schemas/actor-persist/v4.bare -o dist/schemas/actor-persist/v4.ts && ./scripts/compile-bare.ts compile schemas/persist/v1.bare -o dist/schemas/persist/v1.ts && ./scripts/compile-bare.ts compile schemas/transport/v1.bare -o dist/schemas/transport/v1.ts && ./scripts/compile-bare.ts compile schemas/actor-inspector/v1.bare -o dist/schemas/actor-inspector/v1.ts && ./scripts/compile-bare.ts compile schemas/actor-inspector/v2.bare -o dist/schemas/actor-inspector/v2.ts && ./scripts/compile-bare.ts compile schemas/actor-inspector/v3.bare -o dist/schemas/actor-inspector/v3.ts\",\n\t\t\"check-types\": \"tsc --noEmit\",\n\t\t\"lint\": \"biome check .\",\n\t\t\"lint:fix\": \"biome check --write .\",\n\t\t\"format\": \"biome format .\",\n\t\t\"format:write\": \"biome format --write .\",\n\t\t\"test\": \"vitest run\",\n\t\t\"test:watch\": \"vitest\",\n\t\t\"manager-openapi-gen\": \"tsx scripts/manager-openapi-gen.ts\",\n\t\t\"dump-asyncapi\": \"tsx scripts/dump-asyncapi.ts\",\n\t\t\"registry-config-schema-gen\": \"tsx scripts/registry-config-schema-gen.ts\",\n\t\t\"actor-config-schema-gen\": \"tsx scripts/actor-config-schema-gen.ts\",\n\t\t\"build:pack-inspector\": \"tsx scripts/pack-inspector.ts\"\n\t},\n\t\"dependencies\": {\n\t\t\"@hono/standard-validator\": \"^0.1.3\",\n\t\t\"@hono/zod-openapi\": \"^1.1.5\",\n\t\t\"@rivetkit/bare-ts\": \"^0.6.2\",\n\t\t\"@rivetkit/engine-runner\": \"workspace:*\",\n\t\t\"@rivetkit/fast-json-patch\": \"^3.1.2\",\n\t\t\"@rivetkit/on-change\": \"^6.0.2-rc.1\",\n\t\t\"@rivetkit/sqlite-vfs\": \"workspace:*\",\n\t\t\"@rivetkit/traces\": \"workspace:*\",\n\t\t\"@rivetkit/virtual-websocket\": \"workspace:*\",\n\t\t\"@rivetkit/workflow-engine\": \"workspace:*\",\n\t\t\"cbor-x\": \"^1.6.0\",\n\t\t\"get-port\": \"^7.1.0\",\n\t\t\"hono\": \"^4.7.0\",\n\t\t\"invariant\": \"^2.2.4\",\n\t\t\"nanoevents\": \"^9.1.0\",\n\t\t\"p-retry\": \"^6.2.1\",\n\t\t\"pino\": \"^9.5.0\",\n\t\t\"tar\": \"^7.5.0\",\n\t\t\"uuid\": \"^12.0.0\",\n\t\t\"vbare\": \"^0.0.4\",\n\t\t\"@rivetkit/sqlite\": \"^0.1.1\",\n\t\t\"zod\": \"^4.1.0\"\n\t},\n\t\"devDependencies\": {\n\t\t\"@bare-ts/tools\": \"^0.13.0\",\n\t\t\"@biomejs/biome\": \"^2.3\",\n\t\t\"@hono/node-server\": \"^1.18.2\",\n\t\t\"@hono/node-ws\": \"^1.1.1\",\n\t\t\"@standard-schema/spec\": \"^1.0.0\",\n\t\t\"@types/invariant\": \"^2\",\n\t\t\"@types/node\": \"^22.13.1\",\n\t\t\"@types/ws\": \"^8\",\n\t\t\"@vitest/ui\": \"3.1.1\",\n\t\t\"cli-table3\": \"^0.6.5\",\n\t\t\"commander\": \"^12.1.0\",\n\t\t\"eventsource\": \"^4.0.0\",\n\t\t\"local-pkg\": \"^0.5.1\",\n\t\t\"tsup\": \"^8.4.0\",\n\t\t\"tsx\": \"^4.19.4\",\n\t\t\"typescript\": \"^5.7.3\",\n\t\t\"vite-tsconfig-paths\": \"^5.1.4\",\n\t\t\"vitest\": \"^3.1.1\",\n\t\t\"ws\": \"^8.18.1\",\n\t\t\"zod-to-json-schema\": \"^3.25.0\"\n\t},\n\t\"peerDependencies\": {\n\t\t\"@hono/node-server\": \"^1.14.0\",\n\t\t\"@hono/node-ws\": \"^1.1.1\",\n\t\t\"drizzle-kit\": \"^0.31.2\",\n\t\t\"drizzle-orm\": \"^0.44.2\",\n\t\t\"eventsource\": \"^4.0.0\",\n\t\t\"ws\": \"^8.0.0\"\n\t},\n\t\"peerDependenciesMeta\": {\n\t\t\"@hono/node-server\": {\n\t\t\t\"optional\": true\n\t\t},\n\t\t\"@hono/node-ws\": {\n\t\t\t\"optional\": true\n\t\t},\n\t\t\"drizzle-kit\": {\n\t\t\t\"optional\": true\n\t\t},\n\t\t\"drizzle-orm\": {\n\t\t\t\"optional\": true\n\t\t},\n\t\t\"eventsource\": {\n\t\t\t\"optional\": true\n\t\t},\n\t\t\"ws\": {\n\t\t\t\"optional\": true\n\t\t}\n\t},\n\t\"stableVersion\": \"0.8.0\"\n}\n","import {\n\ttype LevelWithSilent,\n\ttype Logger,\n\tpino,\n\tstdTimeFunctions,\n} from \"pino\";\nimport { z } from \"zod/v4\";\nimport { getLogLevel, getLogTarget, getLogTimestamp } from \"@/utils/env-vars\";\nimport {\n\tcastToLogValue,\n\tformatTimestamp,\n\tLOGGER_CONFIG,\n\tstringify,\n} from \"./logfmt\";\n\nexport type { Logger } from \"pino\";\n\nlet baseLogger: Logger | undefined;\nlet configuredLogLevel: LogLevel | undefined;\n\n/** Cache of child loggers by logger name. */\nconst loggerCache = new Map<string, Logger>();\n\nexport const LogLevelSchema = z.enum([\n\t\"trace\",\n\t\"debug\",\n\t\"info\",\n\t\"warn\",\n\t\"error\",\n\t\"fatal\",\n\t\"silent\",\n]);\n\nexport type LogLevel = z.infer<typeof LogLevelSchema>;\n\nexport function getPinoLevel(logLevel?: LogLevel): LevelWithSilent {\n\t// Priority: provided > configured > env > default\n\tif (logLevel) {\n\t\treturn logLevel;\n\t}\n\n\tif (configuredLogLevel) {\n\t\treturn configuredLogLevel;\n\t}\n\n\tconst raw = (getLogLevel() || \"warn\").toString().toLowerCase();\n\n\tconst parsed = LogLevelSchema.safeParse(raw);\n\tif (parsed.success) {\n\t\treturn parsed.data;\n\t}\n\n\t// Default to info if invalid\n\treturn \"info\";\n}\n\nexport function getIncludeTarget(): boolean {\n\treturn getLogTarget();\n}\n\n/**\n * Configure a custom base logger.\n */\nexport function configureBaseLogger(logger: Logger): void {\n\tbaseLogger = logger;\n\tloggerCache.clear();\n}\n\n// TODO: This can be simplified in logfmt.ts\nfunction customWrite(level: string, o: any) {\n\tconst entries: any = {};\n\n\t// Add timestamp if enabled\n\tif (getLogTimestamp() && o.time) {\n\t\tconst date = typeof o.time === \"number\" ? new Date(o.time) : new Date();\n\t\tentries.ts = formatTimestamp(date);\n\t}\n\n\t// Add level\n\tentries.level = level.toUpperCase();\n\n\t// Add target if present\n\tif (o.target) {\n\t\tentries.target = o.target;\n\t}\n\n\t// Add message\n\tif (o.msg) {\n\t\tentries.msg = o.msg;\n\t}\n\n\t// Add other properties\n\tfor (const [key, value] of Object.entries(o)) {\n\t\tif (\n\t\t\tkey !== \"time\" &&\n\t\t\tkey !== \"level\" &&\n\t\t\tkey !== \"target\" &&\n\t\t\tkey !== \"msg\" &&\n\t\t\tkey !== \"pid\" &&\n\t\t\tkey !== \"hostname\"\n\t\t) {\n\t\t\tentries[key] = castToLogValue(value);\n\t\t}\n\t}\n\n\tconst output = stringify(entries);\n\tconsole.log(output);\n}\n\n/**\n * Configure the default logger with optional log level.\n */\nexport function configureDefaultLogger(logLevel?: LogLevel) {\n\t// Store the configured log level\n\tif (logLevel) {\n\t\tconfiguredLogLevel = logLevel;\n\t}\n\n\tbaseLogger = pino({\n\t\tlevel: getPinoLevel(logLevel),\n\t\tmessageKey: \"msg\",\n\t\t// Do not include pid/hostname in output\n\t\tbase: {},\n\t\t// Keep a string level in the output\n\t\tformatters: {\n\t\t\tlevel(_label: string, number: number) {\n\t\t\t\treturn { level: number };\n\t\t\t},\n\t\t},\n\t\ttimestamp: getLogTimestamp() ? stdTimeFunctions.epochTime : false,\n\t\tbrowser: {\n\t\t\twrite: {\n\t\t\t\tfatal: customWrite.bind(null, \"fatal\"),\n\t\t\t\terror: customWrite.bind(null, \"error\"),\n\t\t\t\twarn: customWrite.bind(null, \"warn\"),\n\t\t\t\tinfo: customWrite.bind(null, \"info\"),\n\t\t\t\tdebug: customWrite.bind(null, \"debug\"),\n\t\t\t\ttrace: customWrite.bind(null, \"trace\"),\n\t\t\t},\n\t\t},\n\t\thooks: {\n\t\t\tlogMethod(inputArgs, method, level) {\n\t\t\t\t// TODO: This is a hack to not implement our own Pino transport target. We can get better perf if we have our own transport target.\n\n\t\t\t\tconst levelMap: Record<number, string> = {\n\t\t\t\t\t10: \"trace\",\n\t\t\t\t\t20: \"debug\",\n\t\t\t\t\t30: \"info\",\n\t\t\t\t\t40: \"warn\",\n\t\t\t\t\t50: \"error\",\n\t\t\t\t\t60: \"fatal\",\n\t\t\t\t};\n\t\t\t\tconst levelName = levelMap[level] || \"info\";\n\t\t\t\tconst time = getLogTimestamp() ? Date.now() : undefined;\n\n\t\t\t\t// Get bindings from the logger instance (child logger fields)\n\t\t\t\tconst bindings = (this as any).bindings?.() || {};\n\n\t\t\t\t// TODO: This can be simplified in logfmt.ts\n\t\t\t\tif (inputArgs.length >= 2) {\n\t\t\t\t\tconst [objOrMsg, msg] = inputArgs;\n\t\t\t\t\tif (typeof objOrMsg === \"object\" && objOrMsg !== null) {\n\t\t\t\t\t\tcustomWrite(levelName, {\n\t\t\t\t\t\t\t...bindings,\n\t\t\t\t\t\t\t...objOrMsg,\n\t\t\t\t\t\t\tmsg,\n\t\t\t\t\t\t\ttime,\n\t\t\t\t\t\t});\n\t\t\t\t\t} else {\n\t\t\t\t\t\tcustomWrite(levelName, {\n\t\t\t\t\t\t\t...bindings,\n\t\t\t\t\t\t\tmsg: String(objOrMsg),\n\t\t\t\t\t\t\ttime,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t} else if (inputArgs.length === 1) {\n\t\t\t\t\tconst [objOrMsg] = inputArgs;\n\t\t\t\t\tif (typeof objOrMsg === \"object\" && objOrMsg !== null) {\n\t\t\t\t\t\tcustomWrite(levelName, {\n\t\t\t\t\t\t\t...bindings,\n\t\t\t\t\t\t\t...objOrMsg,\n\t\t\t\t\t\t\ttime,\n\t\t\t\t\t\t});\n\t\t\t\t\t} else {\n\t\t\t\t\t\tcustomWrite(levelName, {\n\t\t\t\t\t\t\t...bindings,\n\t\t\t\t\t\t\tmsg: String(objOrMsg),\n\t\t\t\t\t\t\ttime,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t});\n\n\tloggerCache.clear();\n}\n\n/**\n * Get or initialize the base logger.\n */\nexport function getBaseLogger(): Logger {\n\tif (!baseLogger) {\n\t\tconfigureDefaultLogger();\n\t}\n\treturn baseLogger!;\n}\n\n/**\n * Returns a child logger with `target` bound for the given name.\n */\nexport function getLogger(name = \"default\"): Logger {\n\t// Check cache first\n\tconst cached = loggerCache.get(name);\n\tif (cached) {\n\t\treturn cached;\n\t}\n\n\t// Create\n\tconst base = getBaseLogger();\n\n\t// Add target to log if enabled\n\tconst child = getIncludeTarget() ? base.child({ target: name }) : base;\n\n\t// Cache the logger\n\tloggerCache.set(name, child);\n\n\treturn child;\n}\n","export type LogLevel =\n\t| \"TRACE\"\n\t| \"DEBUG\"\n\t| \"INFO\"\n\t| \"WARN\"\n\t| \"ERROR\"\n\t| \"CRITICAL\";\n\nexport const LogLevels: Record<LogLevel, LevelIndex> = {\n\tTRACE: 0,\n\tDEBUG: 1,\n\tINFO: 2,\n\tWARN: 3,\n\tERROR: 4,\n\tCRITICAL: 5,\n} as const;\n\nexport const LevelNameMap: Record<number, LogLevel> = {\n\t0: \"TRACE\",\n\t1: \"DEBUG\",\n\t2: \"INFO\",\n\t3: \"WARN\",\n\t4: \"ERROR\",\n\t5: \"CRITICAL\",\n};\n\nexport type LevelIndex = number;\n","import { type LogLevel, LogLevels } from \"./log-levels\";\n\nconst LOG_LEVEL_COLORS: Record<number, string> = {\n\t[LogLevels.CRITICAL]: \"\\x1b[31m\", // Red\n\t[LogLevels.ERROR]: \"\\x1b[31m\", // Red\n\t[LogLevels.WARN]: \"\\x1b[33m\", // Yellow\n\t[LogLevels.INFO]: \"\\x1b[32m\", // Green\n\t[LogLevels.DEBUG]: \"\\x1b[36m\", // Cyan\n\t[LogLevels.TRACE]: \"\\x1b[36m\", // Cyan\n};\n\nconst RESET_COLOR = \"\\x1b[0m\";\n\n/**\n * Serializes logfmt line from an object.\n *\n * ## Styling Methodology\n *\n * The three things you need to know for every log line is the level, the\n * message, and who called it. These properties are highlighted in different colros\n * and sorted in th eorder that you usually read them.\n *\n * Once you've found a log line you care about, then you want to find the\n * property you need to see. The property names are bolded and the default color\n * while the rest of the data is dim. This lets you scan to find the property\n * name quickly then look closer to read the data associated with the\n * property.\n */\nexport function stringify(data: any) {\n\tlet line = \"\";\n\tconst entries = Object.entries(data);\n\n\tfor (let i = 0; i < entries.length; i++) {\n\t\tconst [key, valueRaw] = entries[i];\n\n\t\tlet isNull = false;\n\t\tlet valueString: string;\n\t\tif (valueRaw == null) {\n\t\t\tisNull = true;\n\t\t\tvalueString = \"\";\n\t\t} else {\n\t\t\tvalueString = valueRaw.toString();\n\t\t}\n\n\t\t// Clip value unless specifically the error message\n\t\tif (valueString.length > 512 && key !== \"msg\" && key !== \"error\")\n\t\t\tvalueString = `${valueString.slice(0, 512)}...`;\n\n\t\tconst needsQuoting =\n\t\t\tvalueString.indexOf(\" \") > -1 || valueString.indexOf(\"=\") > -1;\n\t\tconst needsEscaping =\n\t\t\tvalueString.indexOf('\"') > -1 || valueString.indexOf(\"\\\\\") > -1;\n\n\t\tvalueString = valueString.replace(/\\n/g, \"\\\\n\");\n\t\tif (needsEscaping) valueString = valueString.replace(/[\"\\\\]/g, \"\\\\$&\");\n\t\tif (needsQuoting || needsEscaping) valueString = `\"${valueString}\"`;\n\t\tif (valueString === \"\" && !isNull) valueString = '\"\"';\n\n\t\tif (LOGGER_CONFIG.enableColor) {\n\t\t\t// With color\n\n\t\t\t// Special message colors\n\t\t\tlet color = \"\\x1b[2m\";\n\t\t\tif (key === \"level\") {\n\t\t\t\tconst level = LogLevels[valueString as LogLevel];\n\t\t\t\tconst levelColor = LOG_LEVEL_COLORS[level];\n\t\t\t\tif (levelColor) {\n\t\t\t\t\tcolor = levelColor;\n\t\t\t\t}\n\t\t\t} else if (key === \"msg\") {\n\t\t\t\tcolor = \"\\x1b[32m\";\n\t\t\t} else if (key === \"trace\") {\n\t\t\t\tcolor = \"\\x1b[34m\";\n\t\t\t}\n\n\t\t\t// Format line\n\t\t\tline += `\\x1b[0m\\x1b[1m${key}\\x1b[0m\\x1b[2m=\\x1b[0m${color}${valueString}${RESET_COLOR}`;\n\t\t} else {\n\t\t\t// No color\n\t\t\tline += `${key}=${valueString}`;\n\t\t}\n\n\t\tif (i !== entries.length - 1) {\n\t\t\tline += \" \";\n\t\t}\n\t}\n\n\treturn line;\n}\n\nexport function formatTimestamp(date: Date): string {\n\tconst year = date.getUTCFullYear();\n\tconst month = String(date.getUTCMonth() + 1).padStart(2, \"0\");\n\tconst day = String(date.getUTCDate()).padStart(2, \"0\");\n\tconst hours = String(date.getUTCHours()).padStart(2, \"0\");\n\tconst minutes = String(date.getUTCMinutes()).padStart(2, \"0\");\n\tconst seconds = String(date.getUTCSeconds()).padStart(2, \"0\");\n\tconst milliseconds = String(date.getUTCMilliseconds()).padStart(3, \"0\");\n\n\treturn `${year}-${month}-${day}T${hours}:${minutes}:${seconds}.${milliseconds}Z`;\n}\n\nexport function castToLogValue(v: unknown): any {\n\tif (\n\t\ttypeof v === \"string\" ||\n\t\ttypeof v === \"number\" ||\n\t\ttypeof v === \"bigint\" ||\n\t\ttypeof v === \"boolean\" ||\n\t\tv === null ||\n\t\tv === undefined\n\t) {\n\t\treturn v;\n\t}\n\tif (v instanceof Error) {\n\t\t//args.push(...errorToLogEntries(k, v));\n\t\treturn String(v);\n\t}\n\ttry {\n\t\treturn JSON.stringify(v);\n\t} catch {\n\t\treturn \"[cannot stringify]\";\n\t}\n}\n\n// MARK: Config\ninterface GlobalLoggerConfig {\n\tenableColor: boolean;\n\tenableSpreadObject: boolean;\n\tenableErrorStack: boolean;\n}\n\nexport const LOGGER_CONFIG: GlobalLoggerConfig = {\n\tenableColor: false,\n\tenableSpreadObject: false,\n\tenableErrorStack: false,\n};\n\n// MARK: Utils\n/**\n * Converts an object in to an easier to read KV of entries.\n */\nexport function spreadObjectToLogEntries(base: string, data: unknown): any {\n\tif (\n\t\tLOGGER_CONFIG.enableSpreadObject &&\n\t\ttypeof data === \"object\" &&\n\t\t!Array.isArray(data) &&\n\t\tdata !== null &&\n\t\tObject.keys(data).length !== 0 &&\n\t\tObject.keys(data).length < 16\n\t) {\n\t\tconst logData: any = {};\n\t\tfor (const key in data) {\n\t\t\tObject.assign(\n\t\t\t\tlogData,\n\t\t\t\tspreadObjectToLogEntries(\n\t\t\t\t\t`${base}.${key}`,\n\t\t\t\t\t// biome-ignore lint/suspicious/noExplicitAny: FIXME\n\t\t\t\t\t(data as any)[key],\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t\treturn logData;\n\t}\n\n\treturn { [base]: JSON.stringify(data) };\n}\n\nexport function errorToLogEntries(base: string, error: unknown): any {\n\tif (error instanceof Error) {\n\t\treturn {\n\t\t\t[`${base}.message`]: error.message,\n\t\t\t...(LOGGER_CONFIG.enableErrorStack && error.stack\n\t\t\t\t? { [`${base}.stack`]: formatStackTrace(error.stack) }\n\t\t\t\t: {}),\n\t\t\t...(error.cause\n\t\t\t\t? errorToLogEntries(`${base}.cause`, error.cause)\n\t\t\t\t: {}),\n\t\t};\n\t}\n\treturn { [base]: `${error}` };\n}\n\n// export function errorToLogEntries(base: string, error: unknown): LogEntry[] {\n// \tif (error instanceof RuntimeError) {\n// \t\treturn [\n// \t\t\t[`${base}.code`, error.code],\n// \t\t\t[`${base}.description`, error.errorConfig?.description],\n// \t\t\t[`${base}.module`, error.moduleName],\n// \t\t\t...(error.trace ? [[`${base}.trace`, stringifyTrace(error.trace)] as LogEntry] : []),\n// \t\t\t...(LOGGER_CONFIG.enableErrorStack && error.stack\n// \t\t\t\t? [[`${base}.stack`, formatStackTrace(error.stack)] as LogEntry]\n// \t\t\t\t: []),\n// \t\t\t...(error.meta ? [[`${base}.meta`, JSON.stringify(error.meta)] as LogEntry] : []),\n// \t\t\t...(error.cause ? errorToLogEntries(`${base}.cause`, error.cause) : []),\n// \t\t];\n// \t} else if (error instanceof Error) {\n// \t\treturn [\n// \t\t\t[`${base}.name`, error.name],\n// \t\t\t[`${base}.message`, error.message],\n// \t\t\t...(LOGGER_CONFIG.enableErrorStack && error.stack\n// \t\t\t\t? [[`${base}.stack`, formatStackTrace(error.stack)] as LogEntry]\n// \t\t\t\t: []),\n// \t\t\t...(error.cause ? errorToLogEntries(`${base}.cause`, error.cause) : []),\n// \t\t];\n// \t} else {\n// \t\treturn [\n// \t\t\t[base, `${error}`],\n// \t\t];\n// \t}\n// }\n\n/**\n * Formats a JS stack trace in to a legible one-liner.\n */\nfunction formatStackTrace(stackTrace: string): string {\n\tconst regex = /at (.+?)$/gm;\n\tconst matches = [...stackTrace.matchAll(regex)];\n\t// Reverse array since the stack goes from top level -> bottom level\n\tmatches.reverse();\n\treturn matches.map((match) => match[1].trim()).join(\" > \");\n}\n","import { stringifyError } from \"@/common/utils\";\nimport type { Context as HonoContext, Handler as HonoHandler } from \"hono\";\nimport { stringify as uuidstringify } from \"uuid\";\nimport pkgJson from \"../package.json\" with { type: \"json\" };\nimport { getLogger } from \"./common/log\";\nimport { assertUnreachable } from \"./common/utils\";\n\n/** @experimental */\nexport { stringifyError };\n\n/** @experimental */\nexport { assertUnreachable };\n\n/**\n * Joins multiple abort signals into one.\n *\n * The returned signal aborts when the first input signal aborts.\n * Uses `AbortSignal.any(...)` when available, with a runtime fallback.\n *\n * @experimental\n */\nexport function joinSignals(\n\t...signals: Array<AbortSignal | undefined | null>\n): AbortSignal {\n\tconst validSignals = signals.filter(\n\t\t(signal): signal is AbortSignal => signal != null,\n\t);\n\n\tif (validSignals.length === 0) {\n\t\treturn new AbortController().signal;\n\t}\n\n\tif (validSignals.length === 1) {\n\t\treturn validSignals[0];\n\t}\n\n\tconst signalAny = (\n\t\tAbortSignal as typeof AbortSignal & {\n\t\t\tany?: (signals: AbortSignal[]) => AbortSignal;\n\t\t}\n\t).any;\n\tif (typeof signalAny === \"function\") {\n\t\treturn signalAny(validSignals);\n\t}\n\n\tconst controller = new AbortController();\n\tconst cleanups: Array<() => void> = [];\n\n\tconst abortWithSignal = (signal: AbortSignal) => {\n\t\tif (controller.signal.aborted) {\n\t\t\treturn;\n\t\t}\n\n\t\tfor (const cleanup of cleanups) {\n\t\t\tcleanup();\n\t\t}\n\n\t\tconst reason = (signal as AbortSignal & { reason?: unknown }).reason;\n\t\tcontroller.abort(reason);\n\t};\n\n\tfor (const signal of validSignals) {\n\t\tif (signal.aborted) {\n\t\t\tabortWithSignal(signal);\n\t\t\tbreak;\n\t\t}\n\n\t\tconst onAbort = () => abortWithSignal(signal);\n\t\tsignal.addEventListener(\"abort\", onAbort, { once: true });\n\t\tcleanups.push(() => signal.removeEventListener(\"abort\", onAbort));\n\t}\n\n\treturn controller.signal;\n}\n\n/**\n * Returns a promise that resolves after the given number of milliseconds.\n *\n * @experimental\n */\nexport function sleep(ms: number): Promise<void> {\n\treturn new Promise<void>((resolve) => setTimeout(resolve, ms));\n}\n\n/**\n * Creates a fixed-rate interval tick function that can be awaited in a loop.\n *\n * @example\n * const tick = interval(100);\n * while (!c.aborted) {\n * await tick();\n * if (c.aborted) break;\n * // ... game logic\n * }\n *\n * @experimental\n */\nexport function interval(ms: number): () => Promise<void> {\n\treturn () => sleep(ms);\n}\n\nexport const VERSION = pkgJson.version;\n\nlet _userAgent: string | undefined;\n\nfunction logger() {\n\treturn getLogger(\"utils\");\n}\n\n/**\n * Builds the HTTP user agent used by this library.\n *\n * @experimental\n */\nexport function httpUserAgent(): string {\n\t// Return cached value if already initialized\n\tif (_userAgent !== undefined) {\n\t\treturn _userAgent;\n\t}\n\n\t// Library\n\tlet userAgent = `RivetKit/${VERSION}`;\n\n\t// Navigator\n\tconst navigatorObj =\n\t\ttypeof navigator !== \"undefined\" ? navigator : undefined;\n\tif (navigatorObj?.userAgent) userAgent += ` ${navigatorObj.userAgent}`;\n\n\t_userAgent = userAgent;\n\n\treturn userAgent;\n}\n\nexport type UpgradeWebSocket = (\n\tcreateEvents: (c: HonoContext) => any,\n) => HonoHandler;\n\nexport type GetUpgradeWebSocket = () => UpgradeWebSocket;\n\n/**\n * Reads an environment variable from Deno or Node runtimes.\n *\n * @experimental\n */\nexport function getEnvUniversal(key: string): string | undefined {\n\tif (typeof Deno !== \"undefined\") {\n\t\treturn Deno.env.get(key);\n\t} else if (typeof process !== \"undefined\") {\n\t\t// Do this after Deno since `process` is sometimes polyfilled\n\t\treturn process.env[key];\n\t}\n}\n\n/**\n * Traces a debug value and returns it.\n *\n * @experimental\n */\nexport function dbg<T>(x: T): T {\n\tconsole.trace(`=== DEBUG ===\\n${x}`);\n\treturn x;\n}\n\n/**\n * Converts various ArrayBuffer-like types to Uint8Array.\n * Handles ArrayBuffer, ArrayBufferView (including typed arrays), and passes through existing Uint8Array.\n *\n * @param data - The ArrayBuffer or ArrayBufferView to convert\n * @returns A Uint8Array view of the data\n *\n * @experimental\n */\nexport function toUint8Array(data: ArrayBuffer | ArrayBufferView): Uint8Array {\n\tif (data instanceof Uint8Array) {\n\t\treturn data;\n\t} else if (data instanceof ArrayBuffer) {\n\t\treturn new Uint8Array(data);\n\t} else if (ArrayBuffer.isView(data)) {\n\t\t// Handle other ArrayBufferView types (Int8Array, Uint16Array, DataView, etc.)\n\t\treturn new Uint8Array(\n\t\t\tdata.buffer.slice(\n\t\t\t\tdata.byteOffset,\n\t\t\t\tdata.byteOffset + data.byteLength,\n\t\t\t),\n\t\t);\n\t} else {\n\t\tthrow new TypeError(\"Input must be ArrayBuffer or ArrayBufferView\");\n\t}\n}\n\n// Long timeouts\n//\n// JavaScript timers use a signed 32-bit integer for delays, so values above 2^31-1 (~24.8 days)\n// are not reliable and may fire immediately or overflow.\n//\n// https://developer.mozilla.org/en-US/docs/Web/API/Window/setTimeout#maximum_delay_value\nconst TIMEOUT_MAX = 2147483647; // 2^31-1\n\nexport type LongTimeoutHandle = { abort: () => void };\n\n/**\n * Polyfill for Promise.withResolvers().\n *\n * This is specifically for Cloudflare Workers. Their implementation of Promise.withResolvers does not work correctly.\n *\n * @experimental\n */\nexport function promiseWithResolvers<T>(onReject: (reason?: any) => void): {\n\tpromise: Promise<T>;\n\tresolve: (value: T | PromiseLike<T>) => void;\n\treject: (reason?: any) => void;\n} {\n\tlet resolve!: (value: T | PromiseLike<T>) => void;\n\tlet reject!: (reason?: any) => void;\n\tconst promise = new Promise<T>((res, rej) => {\n\t\tresolve = res;\n\t\treject = rej;\n\t});\n\tpromise.catch(onReject);\n\treturn { promise, resolve, reject };\n}\n\n/**\n * Sets a timeout that supports delays larger than the JavaScript timer limit.\n *\n * @experimental\n */\nexport function setLongTimeout(\n\tlistener: () => void,\n\tafter: number,\n): LongTimeoutHandle {\n\tlet timeout: ReturnType<typeof setTimeout> | undefined;\n\n\tfunction start(remaining: number) {\n\t\tif (remaining <= TIMEOUT_MAX) {\n\t\t\ttimeout = setTimeout(listener, remaining);\n\t\t} else {\n\t\t\ttimeout = setTimeout(() => {\n\t\t\t\tstart(remaining - TIMEOUT_MAX);\n\t\t\t}, TIMEOUT_MAX);\n\t\t}\n\t}\n\n\tstart(after);\n\n\treturn {\n\t\tabort: () => {\n\t\t\tif (timeout !== undefined) clearTimeout(timeout);\n\t\t},\n\t};\n}\n\n/**\n * A tiny utility that coalesces/enqueues async operations so only the latest\n * queued task runs per cycle, while callers receive a promise that resolves\n * when the task for the cycle they joined has completed.\n */\nexport class SinglePromiseQueue {\n\t/** Next operation to execute in the queue. If attempting to enqueue another op, it will override the existing op. */\n\t#queuedOp?: () => Promise<void>;\n\n\t/** The currently running promise of #drainLoop. Do not await this, instead await `pending` to await the current cycle. */\n\trunningDrainLoop?: Promise<void>;\n\n\t/** Pending resolver fro the currently queued entry. */\n\t#pending?: ReturnType<typeof promiseWithResolvers<void>>;\n\n\t/** Queue the next operation and return a promise that resolves when it flushes. */\n\tenqueue(op: () => Promise<void>): Promise<void> {\n\t\t// Replace any previously queued operation with the latest one\n\t\tthis.#queuedOp = op;\n\n\t\t// Ensure a shared resolver exists for all callers in this cycle\n\t\tif (!this.#pending) {\n\t\t\tthis.#pending = promiseWithResolvers<void>((reason) => logger().warn({ msg: \"unhandled single promise queue rejection\", reason }));\n\t\t}\n\n\t\tconst waitForThisCycle = this.#pending.promise;\n\n\t\t// Start runner if not already running\n\t\tif (!this.runningDrainLoop) {\n\t\t\tthis.runningDrainLoop = this.#drainLoop();\n\t\t}\n\n\t\treturn waitForThisCycle;\n\t}\n\n\t/** Drain queued operations sequentially until there is nothing left. */\n\tasync #drainLoop(): Promise<void> {\n\t\ttry {\n\t\t\twhile (this.#queuedOp) {\n\t\t\t\t// Capture current cycle resolver then reset for the next cycle\n\t\t\t\tconst resolver = this.#pending;\n\t\t\t\tthis.#pending = undefined;\n\n\t\t\t\t// Capture and clear the currently queued operation\n\t\t\t\tconst op = this.#queuedOp;\n\t\t\t\tthis.#queuedOp = undefined;\n\n\t\t\t\ttry {\n\t\t\t\t\tawait op();\n\t\t\t\t\t// Notify all waiters for this cycle\n\t\t\t\t\tresolver?.resolve();\n\t\t\t\t} catch (err) {\n\t\t\t\t\tlogger().error({\n\t\t\t\t\t\tmsg: \"error in SinglePromiseQueue drain loop\",\n\t\t\t\t\t\terror: stringifyError(err),\n\t\t\t\t\t});\n\t\t\t\t\t// Reject all waiters for this cycle\n\t\t\t\t\tresolver?.reject(err);\n\t\t\t\t}\n\t\t\t}\n\t\t} finally {\n\t\t\tthis.runningDrainLoop = undefined;\n\t\t}\n\t}\n}\n\n/**\n * Converts a Buffer or Uint8Array into an ArrayBuffer view.\n *\n * @experimental\n */\nexport function bufferToArrayBuffer(buf: Buffer | Uint8Array): ArrayBuffer {\n\treturn buf.buffer.slice(\n\t\tbuf.byteOffset,\n\t\tbuf.byteOffset + buf.byteLength,\n\t) as ArrayBuffer;\n}\n\n/**\n * Properly combines a base URL endpoint with a path, preserving any base path in the endpoint.\n *\n * @example\n * combineUrlPath(\"http://localhost:8787/rivet\", \"/actors/action\")\n * // Returns: \"http://localhost:8787/rivet/actors/action\"\n *\n * @example\n * combineUrlPath(\"http://localhost:8787/rivet\", \"/actors?type=foo\", { namespace: \"test\" })\n * // Returns: \"http://localhost:8787/rivet/actors?type=foo&namespace=test\"\n *\n * @param endpoint The base URL endpoint that may contain a path component\n * @param path The path to append to the endpoint (may include query parameters)\n * @param queryParams Optional additional query parameters to append\n * @returns The properly combined URL string\n *\n * @experimental\n */\nexport function combineUrlPath(\n\tendpoint: string,\n\tpath: string,\n\tqueryParams?: Record<string, string | undefined>,\n): string {\n\tconst baseUrl = new URL(endpoint);\n\n\t// Extract path and query from the provided path\n\tconst pathParts = path.split(\"?\");\n\tconst pathOnly = pathParts[0];\n\tconst existingQuery = pathParts[1] || \"\";\n\n\t// Remove trailing slash from base path and ensure path starts with /\n\tconst basePath = baseUrl.pathname.replace(/\\/$/, \"\");\n\tconst cleanPath = pathOnly.startsWith(\"/\") ? pathOnly : `/${pathOnly}`;\n\t// Combine paths and remove any double slashes\n\tconst fullPath = (basePath + cleanPath).replace(/\\/\\//g, \"/\");\n\n\t// Build query string\n\tconst queryParts: string[] = [];\n\tif (existingQuery) {\n\t\tqueryParts.push(existingQuery);\n\t}\n\tif (queryParams) {\n\t\tfor (const [key, value] of Object.entries(queryParams)) {\n\t\t\tif (value !== undefined) {\n\t\t\t\tqueryParts.push(\n\t\t\t\t\t`${encodeURIComponent(key)}=${encodeURIComponent(value)}`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\tconst fullQuery = queryParts.length > 0 ? `?${queryParts.join(\"&\")}` : \"\";\n\treturn `${baseUrl.protocol}//${baseUrl.host}${fullPath}${fullQuery}`;\n}\n\n/**\n * Compares two ArrayBuffer values by byte content.\n *\n * @experimental\n */\nexport function arrayBuffersEqual(\n\tbuf1: ArrayBuffer,\n\tbuf2: ArrayBuffer,\n): boolean {\n\tif (buf1.byteLength !== buf2.byteLength) return false;\n\n\tconst view1 = new Uint8Array(buf1);\n\tconst view2 = new Uint8Array(buf2);\n\n\tfor (let i = 0; i < view1.length; i++) {\n\t\tif (view1[i] !== view2[i]) return false;\n\t}\n\treturn true;\n}\n\nexport const EXTRA_ERROR_LOG = {\n\tissues: \"https://github.com/rivet-dev/rivetkit/issues\",\n\tsupport: \"https://rivet.dev/discord\",\n\tversion: VERSION,\n};\n\nexport type Runtime = \"deno\" | \"bun\" | \"node\";\n\n/**\n * Detects the current JavaScript runtime from the user agent.\n *\n * @experimental\n */\nexport function detectRuntime(): Runtime {\n\tconst userAgent =\n\t\ttypeof navigator !== \"undefined\" ? navigator.userAgent : \"\";\n\tif (userAgent.includes(\"Deno\")) {\n\t\treturn \"deno\";\n\t}\n\tif (userAgent.includes(\"Bun\")) {\n\t\treturn \"bun\";\n\t}\n\treturn \"node\";\n}\n\nexport type DeepReadonly<T> = {\n\treadonly [K in keyof T]: T[K] extends object ? DeepReadonly<T[K]> : T[K];\n};\n\nexport type DeepMutable<T> = {\n\t-readonly [K in keyof T]: T[K] extends object ? DeepMutable<T[K]> : T[K];\n};\n"]}
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/rivet/rivet/rivetkit-typescript/packages/rivetkit/dist/tsup/chunk-RMJJE43B.cjs","../../src/utils/env-vars.ts","../../src/common/utils.ts","../../package.json","../../src/common/log.ts","../../src/common/log-levels.ts","../../src/common/logfmt.ts","../../src/utils.ts"],"names":["logger","VERSION"],"mappings":"AAAA;AACE;AACA;AACA;AACF,wDAA6B;AAC7B;AACA;ACEO,IAAM,eAAA,EAAiB,CAAA,EAAA,GAC7B,eAAA,CAAgB,cAAc,CAAA;AACxB,IAAM,iBAAA,EAAmB,CAAA,EAAA,GAC/B,eAAA,CAAgB,gBAAgB,CAAA;AAC1B,IAAM,cAAA,EAAgB,CAAA,EAAA,GAC5B,eAAA,CAAgB,aAAa,CAAA;AACvB,IAAM,kBAAA,EAAoB,CAAA,EAAA,GAChC,eAAA,CAAgB,iBAAiB,CAAA;AAC3B,IAAM,eAAA,EAAiB,CAAA,EAAA,GAC7B,eAAA,CAAgB,cAAc,CAAA;AACxB,IAAM,mBAAA,EAAqB,CAAA,EAAA,GAA0B;AAC3D,EAAA,MAAM,MAAA,EAAQ,eAAA,CAAgB,mBAAmB,CAAA;AACjD,EAAA,OAAO,MAAA,IAAU,KAAA,EAAA,EAAY,QAAA,CAAS,KAAA,EAAO,EAAE,EAAA,EAAI,KAAA,CAAA;AACpD,CAAA;AACO,IAAM,kBAAA,EAAoB,CAAA,EAAA,GAChC,eAAA,CAAgB,kBAAkB,CAAA;AAC5B,IAAM,kBAAA,EAAoB,CAAA,EAAA,GAChC,eAAA,CAAgB,kBAAkB,EAAA,IAAM,GAAA;AAClC,IAAM,yBAAA,EAA2B,CAAA,EAAA,GACvC,e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AA;AAAA;AAGA,EAAA;AAAA;AAGA,EAAA;AAAA;AAGgD,EAAA;AAE9B,IAAA;AAGG,IAAA;AACH,MAAA;AACjB,IAAA;AAE8B,IAAA;AAGF,IAAA;AACE,MAAA;AAC9B,IAAA;AAEO,IAAA;AACR,EAAA;AAAA;AAGkC,EAAA;AAC7B,IAAA;AACoB,MAAA;AAEA,QAAA;AACN,QAAA;AAGA,QAAA;AACC,QAAA;AAEb,QAAA;AACM,UAAA;AAET,UAAA;AACa,QAAA;AACE,UAAA;AACT,YAAA;AACoB,YAAA;AACzB,UAAA;AAED,UAAA;AACD,QAAA;AACD,MAAA;AACC,IAAA;AACuB,MAAA;AACzB,IAAA;AACD,EAAA;AACD;AAO2E;AACxD,EAAA;AACb,IAAA;AACiB,IAAA;AACtB,EAAA;AACD;AAuBC;AAEgC,EAAA;AAGA,EAAA;AACJ,EAAA;AACU,EAAA;AAGJ,EAAA;AACI,EAAA;AAET,EAAA;AAGC,EAAA;AACX,EAAA;AACW,IAAA;AAC9B,EAAA;AACiB,EAAA;AACkB,IAAA;AACR,MAAA;AACb,QAAA;AACoB,UAAA;AAC/B,QAAA;AACD,MAAA;AACD,IAAA;AACD,EAAA;AAEsC,EAAA;AACC,EAAA;AACxC;AAUW;AACmB,EAAA;AAEI,EAAA;AACA,EAAA;AAEM,EAAA;AACJ,IAAA;AACnC,EAAA;AACO,EAAA;AACR;AAE+B;AACtB,EAAA;AACC,EAAA;AACAC,EAAAA;AACV;AASyC;AAElB,EAAA;AACU,EAAA;AACxB,IAAA;AACR,EAAA;AAC+B,EAAA;AACvB,IAAA;AACR,EAAA;AACO,EAAA;AACR;APikByC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/rivet/rivet/rivetkit-typescript/packages/rivetkit/dist/tsup/chunk-RMJJE43B.cjs","sourcesContent":[null,"// This file consolidates all environment variables that affect RivetKit's behavior.\n//\n// IMPORTANT: When adding or modifying environment variables here, also update the\n// documentation at: website/src/content/docs/general/environment-variables.mdx\n\nimport { getEnvUniversal } from \"@/utils\";\n\n// Rivet configuration\nexport const getRivetEngine = (): string | undefined =>\n\tgetEnvUniversal(\"RIVET_ENGINE\");\nexport const getRivetEndpoint = (): string | undefined =>\n\tgetEnvUniversal(\"RIVET_ENDPOINT\");\nexport const getRivetToken = (): string | undefined =>\n\tgetEnvUniversal(\"RIVET_TOKEN\");\nexport const getRivetNamespace = (): string | undefined =>\n\tgetEnvUniversal(\"RIVET_NAMESPACE\");\nexport const getRivetRunner = (): string | undefined =>\n\tgetEnvUniversal(\"RIVET_RUNNER\");\nexport const getRivetTotalSlots = (): number | undefined => {\n\tconst value = getEnvUniversal(\"RIVET_TOTAL_SLOTS\");\n\treturn value !== undefined ? parseInt(value, 10) : undefined;\n};\nexport const getRivetRunnerKey = (): string | undefined =>\n\tgetEnvUniversal(\"RIVET_RUNNER_KEY\");\nexport const getRivetRunEngine = (): boolean =>\n\tgetEnvUniversal(\"RIVET_RUN_ENGINE\") === \"1\";\nexport const getRivetRunEngineVersion = (): string | undefined =>\n\tgetEnvUniversal(\"RIVET_RUN_ENGINE_VERSION\");\nexport const getRivetRunnerKind = (): string | undefined =>\n\tgetEnvUniversal(\"RIVET_RUNNER_KIND\");\nexport const getRivetRunnerVersion = (): number | undefined => {\n\tconst value = getEnvUniversal(\"RIVET_RUNNER_VERSION\");\n\treturn value !== undefined ? parseInt(value, 10) : undefined;\n};\nexport const getRivetPublicEndpoint = (): string | undefined =>\n\tgetEnvUniversal(\"RIVET_PUBLIC_ENDPOINT\");\nexport const getRivetPublicToken = (): string | undefined =>\n\tgetEnvUniversal(\"RIVET_PUBLIC_TOKEN\");\n// There is no RIVET_PUBLIC_NAMESPACE because the frontend and backend cannot\n// use different namespaces\n\n// RivetKit configuration\nexport const getRivetkitInspectorToken = (): string | undefined =>\n\tgetEnvUniversal(\"RIVET_INSPECTOR_TOKEN\");\nexport const getRivetkitInspectorDisable = (): boolean =>\n\tgetEnvUniversal(\"RIVET_INSPECTOR_DISABLE\") === \"1\";\nexport const getRivetkitStoragePath = (): string | undefined =>\n\tgetEnvUniversal(\"RIVETKIT_STORAGE_PATH\");\n\n// Logging configuration\n// DEPRECATED: LOG_LEVEL will be removed in a future version\nexport const getLogLevel = (): string | undefined =>\n\tgetEnvUniversal(\"RIVET_LOG_LEVEL\") ?? getEnvUniversal(\"LOG_LEVEL\");\nexport const getLogTarget = (): boolean =>\n\tgetEnvUniversal(\"RIVET_LOG_TARGET\") === \"1\";\nexport const getLogTimestamp = (): boolean =>\n\tgetEnvUniversal(\"RIVET_LOG_TIMESTAMP\") === \"1\";\nexport const getLogMessage = (): boolean =>\n\tgetEnvUniversal(\"RIVET_LOG_MESSAGE\") === \"1\";\nexport const getLogErrorStack = (): boolean =>\n\tgetEnvUniversal(\"RIVET_LOG_ERROR_STACK\") === \"1\";\nexport const getLogHeaders = (): boolean =>\n\tgetEnvUniversal(\"RIVET_LOG_HEADERS\") === \"1\";\n\n// Environment configuration\nexport const getNodeEnv = (): string | undefined => getEnvUniversal(\"NODE_ENV\");\nexport const getNextPhase = (): string | undefined =>\n\tgetEnvUniversal(\"NEXT_PHASE\");\nexport const isDev = (): boolean => getNodeEnv() !== \"production\";\n\n// Experimental\n/**\n * Enables experimental OTel tracing for Rivet Actors.\n *\n * When disabled, actors use an in-memory no-op traces implementation.\n */\nexport const getRivetExperimentalOtel = (): boolean =>\n\tgetEnvUniversal(\"RIVET_EXPERIMENTAL_OTEL\") === \"1\";\n","import type { Next } from \"hono\";\nimport type { ContentfulStatusCode } from \"hono/utils/http-status\";\nimport * as errors from \"@/actor/errors\";\nimport { EXTRA_ERROR_LOG, VERSION } from \"@/utils\";\nimport { getLogErrorStack } from \"@/utils/env-vars\";\nimport type { Logger } from \"./log\";\n\nexport function assertUnreachable(x: never): never {\n\tthrow new Error(`Unreachable case: ${x}`);\n}\n\n/**\n * Safely stringifies an object, ensuring that the stringified object is under a certain size.\n * @param obj any object to stringify\n * @param maxSize maximum size of the stringified object in bytes\n * @returns stringified object\n */\nexport function safeStringify(obj: unknown, maxSize: number) {\n\tlet size = 0;\n\n\tfunction replacer(key: string, value: unknown) {\n\t\tif (value === null || value === undefined) return value;\n\t\tconst valueSize =\n\t\t\ttypeof value === \"string\"\n\t\t\t\t? value.length\n\t\t\t\t: JSON.stringify(value).length;\n\t\tsize += key.length + valueSize;\n\n\t\tif (size > maxSize) {\n\t\t\tthrow new Error(\n\t\t\t\t`JSON object exceeds size limit of ${maxSize} bytes.`,\n\t\t\t);\n\t\t}\n\n\t\treturn value;\n\t}\n\n\treturn JSON.stringify(obj, replacer);\n}\n\n// TODO: Instead of doing this, use a temp var for state and attempt to write\n// it. Roll back state if fails to serialize.\n\n/**\n * Check if a value is CBOR serializable.\n * Optionally pass an onInvalid callback to receive the path to invalid values.\n *\n * For a complete list of supported CBOR tags, see:\n * https://github.com/kriszyp/cbor-x/blob/cc1cf9df8ba72288c7842af1dd374d73e34cdbc1/README.md#list-of-supported-tags-for-decoding\n */\nexport function isCborSerializable(\n\tvalue: unknown,\n\tonInvalid?: (path: string) => void,\n\tcurrentPath = \"\",\n): boolean {\n\t// Handle primitive types directly\n\tif (value === null || value === undefined) {\n\t\treturn true;\n\t}\n\n\tif (typeof value === \"number\") {\n\t\tif (!Number.isFinite(value)) {\n\t\t\tonInvalid?.(currentPath);\n\t\t\treturn false;\n\t\t}\n\t\treturn true;\n\t}\n\n\tif (typeof value === \"boolean\" || typeof value === \"string\") {\n\t\treturn true;\n\t}\n\n\t// Handle BigInt (CBOR tags 2 and 3)\n\tif (typeof value === \"bigint\") {\n\t\treturn true;\n\t}\n\n\t// Handle Date objects (CBOR tags 0 and 1)\n\tif (value instanceof Date) {\n\t\treturn true;\n\t}\n\n\t// Handle typed arrays (CBOR tags 64-82)\n\tif (\n\t\tvalue instanceof Uint8Array ||\n\t\tvalue instanceof Uint8ClampedArray ||\n\t\tvalue instanceof Uint16Array ||\n\t\tvalue instanceof Uint32Array ||\n\t\tvalue instanceof BigUint64Array ||\n\t\tvalue instanceof Int8Array ||\n\t\tvalue instanceof Int16Array ||\n\t\tvalue instanceof Int32Array ||\n\t\tvalue instanceof BigInt64Array ||\n\t\tvalue instanceof Float32Array ||\n\t\tvalue instanceof Float64Array\n\t) {\n\t\treturn true;\n\t}\n\n\t// Handle Map (CBOR tag 259)\n\tif (value instanceof Map) {\n\t\tfor (const [key, val] of value.entries()) {\n\t\t\tconst keyPath = currentPath\n\t\t\t\t? `${currentPath}.key(${String(key)})`\n\t\t\t\t: `key(${String(key)})`;\n\t\t\tconst valPath = currentPath\n\t\t\t\t? `${currentPath}.value(${String(key)})`\n\t\t\t\t: `value(${String(key)})`;\n\t\t\tif (\n\t\t\t\t!isCborSerializable(key, onInvalid, keyPath) ||\n\t\t\t\t!isCborSerializable(val, onInvalid, valPath)\n\t\t\t) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n\n\t// Handle Set (CBOR tag 258)\n\tif (value instanceof Set) {\n\t\tlet index = 0;\n\t\tfor (const item of value.values()) {\n\t\t\tconst itemPath = currentPath\n\t\t\t\t? `${currentPath}.set[${index}]`\n\t\t\t\t: `set[${index}]`;\n\t\t\tif (!isCborSerializable(item, onInvalid, itemPath)) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tindex++;\n\t\t}\n\t\treturn true;\n\t}\n\n\t// Handle RegExp (CBOR tag 27)\n\tif (value instanceof RegExp) {\n\t\treturn true;\n\t}\n\n\t// Handle Error objects (CBOR tag 27)\n\tif (value instanceof Error) {\n\t\treturn true;\n\t}\n\n\t// Handle arrays\n\tif (Array.isArray(value)) {\n\t\tfor (let i = 0; i < value.length; i++) {\n\t\t\tconst itemPath = currentPath ? `${currentPath}[${i}]` : `[${i}]`;\n\t\t\tif (!isCborSerializable(value[i], onInvalid, itemPath)) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n\n\t// Handle plain objects and records (CBOR tags 105, 51, 57344-57599)\n\tif (typeof value === \"object\") {\n\t\t// Allow plain objects and objects with prototypes (for records and named objects)\n\t\tconst proto = Object.getPrototypeOf(value);\n\t\tif (proto !== null && proto !== Object.prototype) {\n\t\t\t// Check if it's a known serializable object type\n\t\t\tconst protoConstructor = value.constructor;\n\t\t\tif (protoConstructor && typeof protoConstructor.name === \"string\") {\n\t\t\t\t// Allow objects with named constructors (records, named objects)\n\t\t\t\t// This includes user-defined classes and built-in objects\n\t\t\t\t// that CBOR can serialize with tag 27 or record tags\n\t\t\t}\n\t\t}\n\n\t\t// Check all properties recursively\n\t\tfor (const key in value) {\n\t\t\tconst propPath = currentPath ? `${currentPath}.${key}` : key;\n\t\t\tif (\n\t\t\t\t!isCborSerializable(\n\t\t\t\t\tvalue[key as keyof typeof value],\n\t\t\t\t\tonInvalid,\n\t\t\t\t\tpropPath,\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n\n\t// Not serializable\n\tonInvalid?.(currentPath);\n\treturn false;\n}\n\nexport interface DeconstructedError {\n\t__type: \"ActorError\";\n\tstatusCode: ContentfulStatusCode;\n\tpublic: boolean;\n\tgroup: string;\n\tcode: string;\n\tmessage: string;\n\tmetadata?: unknown;\n}\n\n/** Deconstructs error in to components that are used to build responses. */\nexport function deconstructError(\n\terror: unknown,\n\tlogger: Logger,\n\textraLog: Record<string, unknown>,\n\texposeInternalError = false,\n): DeconstructedError {\n\t// Build response error information. Only return errors if flagged as public in order to prevent leaking internal behavior.\n\t//\n\t// We log the error here instead of after generating the code & message because we need to log the original error, not the masked internal error.\n\tlet statusCode: ContentfulStatusCode;\n\tlet public_: boolean;\n\tlet group: string;\n\tlet code: string;\n\tlet message: string;\n\tlet metadata: unknown;\n\tif (errors.ActorError.isActorError(error) && error.public) {\n\t\t// Check if error has statusCode (could be ActorError instance or DeconstructedError)\n\t\tstatusCode = (\n\t\t\t\"statusCode\" in error && error.statusCode ? error.statusCode : 400\n\t\t) as ContentfulStatusCode;\n\t\tpublic_ = true;\n\t\tgroup = error.group;\n\t\tcode = error.code;\n\t\tmessage = getErrorMessage(error);\n\t\tmetadata = error.metadata;\n\n\t\tlogger.info({\n\t\t\tmsg: \"public error\",\n\t\t\tgroup,\n\t\t\tcode,\n\t\t\tmessage,\n\t\t\t...EXTRA_ERROR_LOG,\n\t\t\t...extraLog,\n\t\t});\n\t} else if (exposeInternalError) {\n\t\tif (errors.ActorError.isActorError(error)) {\n\t\t\tstatusCode = 500;\n\t\t\tpublic_ = false;\n\t\t\tgroup = error.group;\n\t\t\tcode = error.code;\n\t\t\tmessage = getErrorMessage(error);\n\t\t\tmetadata = error.metadata;\n\n\t\t\tlogger.info({\n\t\t\t\tmsg: \"internal error\",\n\t\t\t\tgroup,\n\t\t\t\tcode,\n\t\t\t\tmessage,\n\t\t\t\tstack: (error as Error)?.stack,\n\t\t\t\t...EXTRA_ERROR_LOG,\n\t\t\t\t...extraLog,\n\t\t\t});\n\t\t} else {\n\t\t\tstatusCode = 500;\n\t\t\tpublic_ = false;\n\t\t\tgroup = \"rivetkit\";\n\t\t\tcode = errors.INTERNAL_ERROR_CODE;\n\t\t\tmessage = getErrorMessage(error);\n\n\t\t\tlogger.info({\n\t\t\t\tmsg: \"internal error\",\n\t\t\t\tgroup,\n\t\t\t\tcode,\n\t\t\t\tmessage,\n\t\t\t\tstack: (error as Error)?.stack,\n\t\t\t\t...EXTRA_ERROR_LOG,\n\t\t\t\t...extraLog,\n\t\t\t});\n\t\t}\n\t} else {\n\t\tstatusCode = 500;\n\t\tpublic_ = false;\n\t\tgroup = \"rivetkit\";\n\t\tcode = errors.INTERNAL_ERROR_CODE;\n\t\tmessage = errors.INTERNAL_ERROR_DESCRIPTION;\n\t\tmetadata = {\n\t\t\t//url: `https://hub.rivet.dev/projects/${actorMetadata.project.slug}/environments/${actorMetadata.environment.slug}/actors?actorId=${actorMetadata.actor.id}`,\n\t\t} satisfies errors.InternalErrorMetadata;\n\n\t\tlogger.warn({\n\t\t\tmsg: \"internal error\",\n\t\t\terror: getErrorMessage(error),\n\t\t\tstack: (error as Error)?.stack,\n\t\t\t...EXTRA_ERROR_LOG,\n\t\t\t...extraLog,\n\t\t});\n\t}\n\n\treturn {\n\t\t__type: \"ActorError\",\n\t\tstatusCode,\n\t\tpublic: public_,\n\t\tgroup,\n\t\tcode,\n\t\tmessage,\n\t\tmetadata,\n\t};\n}\n\nexport function stringifyError(error: unknown): string {\n\tif (error instanceof Error) {\n\t\tif (\n\t\t\ttypeof process !== \"undefined\" &&\n\t\t\tgetLogErrorStack()\n\t\t) {\n\t\t\treturn `${error.name}: ${error.message}${error.stack ? `\\n${error.stack}` : \"\"}`;\n\t\t} else {\n\t\t\treturn `${error.name}: ${error.message}`;\n\t\t}\n\t} else if (typeof error === \"string\") {\n\t\treturn error;\n\t} else if (typeof error === \"object\" && error !== null) {\n\t\ttry {\n\t\t\treturn `${JSON.stringify(error)}`;\n\t\t} catch {\n\t\t\treturn \"[cannot stringify error]\";\n\t\t}\n\t} else {\n\t\treturn `Unknown error: ${getErrorMessage(error)}`;\n\t}\n}\n\nfunction getErrorMessage(err: unknown): string {\n\tif (\n\t\terr &&\n\t\ttypeof err === \"object\" &&\n\t\t\"message\" in err &&\n\t\ttypeof err.message === \"string\"\n\t) {\n\t\treturn err.message;\n\t} else {\n\t\treturn String(err);\n\t}\n}\n\n/** Generates a `Next` handler to pass to middleware in order to be able to call arbitrary middleware. */\nexport function noopNext(): Next {\n\treturn async () => { };\n}\n","{\n\t\"name\": \"rivetkit\",\n\t\"version\": \"2.1.2\",\n\t\"description\": \"Lightweight libraries for building stateful actors on edge platforms\",\n\t\"license\": \"Apache-2.0\",\n\t\"keywords\": [\n\t\t\"rivetkit\",\n\t\t\"stateful\",\n\t\t\"serverless\",\n\t\t\"actors\",\n\t\t\"agents\",\n\t\t\"realtime\",\n\t\t\"websocket\",\n\t\t\"actors\",\n\t\t\"framework\"\n\t],\n\t\"files\": [\n\t\t\"dist\",\n\t\t\"src\",\n\t\t\"deno.json\",\n\t\t\"bun.json\",\n\t\t\"package.json\"\n\t],\n\t\"type\": \"module\",\n\t\"exports\": {\n\t\t\".\": {\n\t\t\t\"import\": {\n\t\t\t\t\"types\": \"./dist/tsup/mod.d.ts\",\n\t\t\t\t\"default\": \"./dist/tsup/mod.js\"\n\t\t\t},\n\t\t\t\"require\": {\n\t\t\t\t\"types\": \"./dist/tsup/mod.d.cts\",\n\t\t\t\t\"default\": \"./dist/tsup/mod.cjs\"\n\t\t\t}\n\t\t},\n\t\t\"./workflow\": {\n\t\t\t\"import\": {\n\t\t\t\t\"types\": \"./dist/tsup/workflow/mod.d.ts\",\n\t\t\t\t\"default\": \"./dist/tsup/workflow/mod.js\"\n\t\t\t},\n\t\t\t\"require\": {\n\t\t\t\t\"types\": \"./dist/tsup/workflow/mod.d.cts\",\n\t\t\t\t\"default\": \"./dist/tsup/workflow/mod.cjs\"\n\t\t\t}\n\t\t},\n\t\t\"./client\": {\n\t\t\t\"import\": {\n\t\t\t\t\"browser\": {\n\t\t\t\t\t\"types\": \"./dist/browser/client.d.ts\",\n\t\t\t\t\t\"default\": \"./dist/browser/client.js\"\n\t\t\t\t},\n\t\t\t\t\"types\": \"./dist/tsup/client/mod.d.ts\",\n\t\t\t\t\"default\": \"./dist/tsup/client/mod.js\"\n\t\t\t},\n\t\t\t\"require\": {\n\t\t\t\t\"types\": \"./dist/tsup/client/mod.d.cts\",\n\t\t\t\t\"default\": \"./dist/tsup/client/mod.cjs\"\n\t\t\t}\n\t\t},\n\t\t\"./log\": {\n\t\t\t\"import\": {\n\t\t\t\t\"types\": \"./dist/tsup/common/log.d.ts\",\n\t\t\t\t\"default\": \"./dist/tsup/common/log.js\"\n\t\t\t},\n\t\t\t\"require\": {\n\t\t\t\t\"types\": \"./dist/tsup/common/log.d.cts\",\n\t\t\t\t\"default\": \"./dist/tsup/common/log.cjs\"\n\t\t\t}\n\t\t},\n\t\t\"./errors\": {\n\t\t\t\"import\": {\n\t\t\t\t\"types\": \"./dist/tsup/actor/errors.d.ts\",\n\t\t\t\t\"default\": \"./dist/tsup/actor/errors.js\"\n\t\t\t},\n\t\t\t\"require\": {\n\t\t\t\t\"types\": \"./dist/tsup/actor/errors.d.cts\",\n\t\t\t\t\"default\": \"./dist/tsup/actor/errors.cjs\"\n\t\t\t}\n\t\t},\n\t\t\"./utils\": {\n\t\t\t\"import\": {\n\t\t\t\t\"types\": \"./dist/tsup/utils.d.ts\",\n\t\t\t\t\"default\": \"./dist/tsup/utils.js\"\n\t\t\t},\n\t\t\t\"require\": {\n\t\t\t\t\"types\": \"./dist/tsup/utils.d.cts\",\n\t\t\t\t\"default\": \"./dist/tsup/utils.cjs\"\n\t\t\t}\n\t\t},\n\t\t\"./driver-helpers\": {\n\t\t\t\"import\": {\n\t\t\t\t\"types\": \"./dist/tsup/driver-helpers/mod.d.ts\",\n\t\t\t\t\"default\": \"./dist/tsup/driver-helpers/mod.js\"\n\t\t\t},\n\t\t\t\"require\": {\n\t\t\t\t\"types\": \"./dist/tsup/driver-helpers/mod.d.cts\",\n\t\t\t\t\"default\": \"./dist/tsup/driver-helpers/mod.cjs\"\n\t\t\t}\n\t\t},\n\t\t\"./driver-helpers/websocket\": {\n\t\t\t\"import\": {\n\t\t\t\t\"types\": \"./dist/tsup/common/websocket.d.ts\",\n\t\t\t\t\"default\": \"./dist/tsup/common/websocket.js\"\n\t\t\t},\n\t\t\t\"require\": {\n\t\t\t\t\"types\": \"./dist/tsup/common/websocket.d.cts\",\n\t\t\t\t\"default\": \"./dist/tsup/common/websocket.cjs\"\n\t\t\t}\n\t\t},\n\t\t\"./driver-test-suite\": {\n\t\t\t\"import\": {\n\t\t\t\t\"types\": \"./dist/tsup/driver-test-suite/mod.d.ts\",\n\t\t\t\t\"default\": \"./dist/tsup/driver-test-suite/mod.js\"\n\t\t\t},\n\t\t\t\"require\": {\n\t\t\t\t\"types\": \"./dist/tsup/driver-test-suite/mod.d.cts\",\n\t\t\t\t\"default\": \"./dist/tsup/driver-test-suite/mod.cjs\"\n\t\t\t}\n\t\t},\n\t\t\"./serve-test-suite\": {\n\t\t\t\"import\": {\n\t\t\t\t\"types\": \"./dist/tsup/serve-test-suite/mod.d.ts\",\n\t\t\t\t\"default\": \"./dist/tsup/serve-test-suite/mod.js\"\n\t\t\t},\n\t\t\t\"require\": {\n\t\t\t\t\"types\": \"./dist/tsup/serve-test-suite/mod.d.cts\",\n\t\t\t\t\"default\": \"./dist/tsup/serve-test-suite/mod.cjs\"\n\t\t\t}\n\t\t},\n\t\t\"./topologies/coordinate\": {\n\t\t\t\"import\": {\n\t\t\t\t\"types\": \"./dist/tsup/topologies/coordinate/mod.d.ts\",\n\t\t\t\t\"default\": \"./dist/tsup/topologies/coordinate/mod.js\"\n\t\t\t},\n\t\t\t\"require\": {\n\t\t\t\t\"types\": \"./dist/tsup/topologies/coordinate/mod.d.cts\",\n\t\t\t\t\"default\": \"./dist/tsup/topologies/coordinate/mod.cjs\"\n\t\t\t}\n\t\t},\n\t\t\"./topologies/partition\": {\n\t\t\t\"import\": {\n\t\t\t\t\"types\": \"./dist/tsup/topologies/partition/mod.d.ts\",\n\t\t\t\t\"default\": \"./dist/tsup/topologies/partition/mod.js\"\n\t\t\t},\n\t\t\t\"require\": {\n\t\t\t\t\"types\": \"./dist/tsup/topologies/partition/mod.d.cts\",\n\t\t\t\t\"default\": \"./dist/tsup/topologies/partition/mod.cjs\"\n\t\t\t}\n\t\t},\n\t\t\"./test\": {\n\t\t\t\"import\": {\n\t\t\t\t\"types\": \"./dist/tsup/test/mod.d.ts\",\n\t\t\t\t\"default\": \"./dist/tsup/test/mod.js\"\n\t\t\t},\n\t\t\t\"require\": {\n\t\t\t\t\"types\": \"./dist/tsup/test/mod.d.cts\",\n\t\t\t\t\"default\": \"./dist/tsup/test/mod.cjs\"\n\t\t\t}\n\t\t},\n\t\t\"./inspector\": {\n\t\t\t\"import\": {\n\t\t\t\t\"types\": \"./dist/tsup/inspector/mod.d.ts\",\n\t\t\t\t\"default\": \"./dist/tsup/inspector/mod.js\"\n\t\t\t},\n\t\t\t\"require\": {\n\t\t\t\t\"types\": \"./dist/tsup/inspector/mod.d.cts\",\n\t\t\t\t\"default\": \"./dist/tsup/inspector/mod.cjs\"\n\t\t\t}\n\t\t},\n\t\t\"./inspector/client\": {\n\t\t\t\"import\": {\n\t\t\t\t\"types\": \"./dist/browser/inspector/client.d.ts\",\n\t\t\t\t\"default\": \"./dist/browser/inspector/client.js\"\n\t\t\t}\n\t\t},\n\t\t\"./db\": {\n\t\t\t\"import\": {\n\t\t\t\t\"types\": \"./dist/tsup/db/mod.d.ts\",\n\t\t\t\t\"default\": \"./dist/tsup/db/mod.js\"\n\t\t\t},\n\t\t\t\"require\": {\n\t\t\t\t\"types\": \"./dist/tsup/db/mod.d.cts\",\n\t\t\t\t\"default\": \"./dist/tsup/db/mod.cjs\"\n\t\t\t}\n\t\t},\n\t\t\"./db/drizzle\": {\n\t\t\t\"import\": {\n\t\t\t\t\"types\": \"./dist/tsup/db/drizzle/mod.d.ts\",\n\t\t\t\t\"default\": \"./dist/tsup/db/drizzle/mod.js\"\n\t\t\t},\n\t\t\t\"require\": {\n\t\t\t\t\"types\": \"./dist/tsup/db/drizzle/mod.d.cts\",\n\t\t\t\t\"default\": \"./dist/tsup/db/drizzle/mod.cjs\"\n\t\t\t}\n\t\t}\n\t},\n\t\"engines\": {\n\t\t\"node\": \">=22.0.0\"\n\t},\n\t\"sideEffects\": [\n\t\t\"./dist/tsup/chunk-*.js\",\n\t\t\"./dist/tsup/chunk-*.cjs\"\n\t],\n\t\"scripts\": {\n \t\t\"build\": \"tsup src/mod.ts src/client/mod.ts src/common/log.ts src/common/websocket.ts src/actor/errors.ts src/topologies/coordinate/mod.ts src/topologies/partition/mod.ts src/utils.ts src/driver-helpers/mod.ts src/driver-test-suite/mod.ts src/serve-test-suite/mod.ts src/test/mod.ts src/inspector/mod.ts src/workflow/mod.ts src/db/mod.ts src/db/drizzle/mod.ts\",\n\t\t\"build:browser\": \"tsup --config tsup.browser.config.ts\",\n\t\t\"build:schema\": \"./scripts/compile-bare.ts compile schemas/client-protocol/v1.bare -o dist/schemas/client-protocol/v1.ts && ./scripts/compile-bare.ts compile schemas/client-protocol/v2.bare -o dist/schemas/client-protocol/v2.ts && ./scripts/compile-bare.ts compile schemas/client-protocol/v3.bare -o dist/schemas/client-protocol/v3.ts && ./scripts/compile-bare.ts compile schemas/file-system-driver/v1.bare -o dist/schemas/file-system-driver/v1.ts && ./scripts/compile-bare.ts compile schemas/file-system-driver/v2.bare -o dist/schemas/file-system-driver/v2.ts && ./scripts/compile-bare.ts compile schemas/file-system-driver/v3.bare -o dist/schemas/file-system-driver/v3.ts && ./scripts/compile-bare.ts compile schemas/actor-persist/v1.bare -o dist/schemas/actor-persist/v1.ts && ./scripts/compile-bare.ts compile schemas/actor-persist/v2.bare -o dist/schemas/actor-persist/v2.ts && ./scripts/compile-bare.ts compile schemas/actor-persist/v3.bare -o dist/schemas/actor-persist/v3.ts && ./scripts/compile-bare.ts compile schemas/actor-persist/v4.bare -o dist/schemas/actor-persist/v4.ts && ./scripts/compile-bare.ts compile schemas/persist/v1.bare -o dist/schemas/persist/v1.ts && ./scripts/compile-bare.ts compile schemas/transport/v1.bare -o dist/schemas/transport/v1.ts && ./scripts/compile-bare.ts compile schemas/actor-inspector/v1.bare -o dist/schemas/actor-inspector/v1.ts && ./scripts/compile-bare.ts compile schemas/actor-inspector/v2.bare -o dist/schemas/actor-inspector/v2.ts && ./scripts/compile-bare.ts compile schemas/actor-inspector/v3.bare -o dist/schemas/actor-inspector/v3.ts\",\n\t\t\"check-types\": \"tsc --noEmit\",\n\t\t\"lint\": \"biome check .\",\n\t\t\"lint:fix\": \"biome check --write .\",\n\t\t\"format\": \"biome format .\",\n\t\t\"format:write\": \"biome format --write .\",\n\t\t\"test\": \"vitest run\",\n\t\t\"test:watch\": \"vitest\",\n\t\t\"manager-openapi-gen\": \"tsx scripts/manager-openapi-gen.ts\",\n\t\t\"dump-asyncapi\": \"tsx scripts/dump-asyncapi.ts\",\n\t\t\"registry-config-schema-gen\": \"tsx scripts/registry-config-schema-gen.ts\",\n\t\t\"actor-config-schema-gen\": \"tsx scripts/actor-config-schema-gen.ts\",\n\t\t\"build:pack-inspector\": \"tsx scripts/pack-inspector.ts\"\n\t},\n\t\"dependencies\": {\n\t\t\"@hono/standard-validator\": \"^0.1.3\",\n\t\t\"@hono/zod-openapi\": \"^1.1.5\",\n\t\t\"@rivetkit/bare-ts\": \"^0.6.2\",\n\t\t\"@rivetkit/engine-runner\": \"workspace:*\",\n\t\t\"@rivetkit/fast-json-patch\": \"^3.1.2\",\n\t\t\"@rivetkit/on-change\": \"^6.0.2-rc.1\",\n\t\t\"@rivetkit/sqlite-vfs\": \"workspace:*\",\n\t\t\"@rivetkit/traces\": \"workspace:*\",\n\t\t\"@rivetkit/virtual-websocket\": \"workspace:*\",\n\t\t\"@rivetkit/workflow-engine\": \"workspace:*\",\n\t\t\"cbor-x\": \"^1.6.0\",\n\t\t\"get-port\": \"^7.1.0\",\n\t\t\"hono\": \"^4.7.0\",\n\t\t\"invariant\": \"^2.2.4\",\n\t\t\"nanoevents\": \"^9.1.0\",\n\t\t\"p-retry\": \"^6.2.1\",\n\t\t\"pino\": \"^9.5.0\",\n\t\t\"tar\": \"^7.5.0\",\n\t\t\"uuid\": \"^12.0.0\",\n\t\t\"vbare\": \"^0.0.4\",\n\t\t\"@rivetkit/sqlite\": \"^0.1.1\",\n\t\t\"zod\": \"^4.1.0\"\n\t},\n\t\"devDependencies\": {\n\t\t\"@bare-ts/tools\": \"^0.13.0\",\n\t\t\"@biomejs/biome\": \"^2.3\",\n\t\t\"@hono/node-server\": \"^1.18.2\",\n\t\t\"@hono/node-ws\": \"^1.1.1\",\n\t\t\"@standard-schema/spec\": \"^1.0.0\",\n\t\t\"@types/invariant\": \"^2\",\n\t\t\"@types/node\": \"^22.13.1\",\n\t\t\"@types/ws\": \"^8\",\n\t\t\"@vitest/ui\": \"3.1.1\",\n\t\t\"cli-table3\": \"^0.6.5\",\n\t\t\"commander\": \"^12.1.0\",\n\t\t\"eventsource\": \"^4.0.0\",\n\t\t\"local-pkg\": \"^0.5.1\",\n\t\t\"tsup\": \"^8.4.0\",\n\t\t\"tsx\": \"^4.19.4\",\n\t\t\"typescript\": \"^5.7.3\",\n\t\t\"vite-tsconfig-paths\": \"^5.1.4\",\n\t\t\"vitest\": \"^3.1.1\",\n\t\t\"ws\": \"^8.18.1\",\n\t\t\"zod-to-json-schema\": \"^3.25.0\"\n\t},\n\t\"peerDependencies\": {\n\t\t\"@hono/node-server\": \"^1.14.0\",\n\t\t\"@hono/node-ws\": \"^1.1.1\",\n\t\t\"drizzle-kit\": \"^0.31.2\",\n\t\t\"drizzle-orm\": \"^0.44.2\",\n\t\t\"eventsource\": \"^4.0.0\",\n\t\t\"ws\": \"^8.0.0\"\n\t},\n\t\"peerDependenciesMeta\": {\n\t\t\"@hono/node-server\": {\n\t\t\t\"optional\": true\n\t\t},\n\t\t\"@hono/node-ws\": {\n\t\t\t\"optional\": true\n\t\t},\n\t\t\"drizzle-kit\": {\n\t\t\t\"optional\": true\n\t\t},\n\t\t\"drizzle-orm\": {\n\t\t\t\"optional\": true\n\t\t},\n\t\t\"eventsource\": {\n\t\t\t\"optional\": true\n\t\t},\n\t\t\"ws\": {\n\t\t\t\"optional\": true\n\t\t}\n\t},\n\t\"stableVersion\": \"0.8.0\"\n}\n","import {\n\ttype LevelWithSilent,\n\ttype Logger,\n\tpino,\n\tstdTimeFunctions,\n} from \"pino\";\nimport { z } from \"zod/v4\";\nimport { getLogLevel, getLogTarget, getLogTimestamp } from \"@/utils/env-vars\";\nimport {\n\tcastToLogValue,\n\tformatTimestamp,\n\tLOGGER_CONFIG,\n\tstringify,\n} from \"./logfmt\";\n\nexport type { Logger } from \"pino\";\n\nlet baseLogger: Logger | undefined;\nlet configuredLogLevel: LogLevel | undefined;\n\n/** Cache of child loggers by logger name. */\nconst loggerCache = new Map<string, Logger>();\n\nexport const LogLevelSchema = z.enum([\n\t\"trace\",\n\t\"debug\",\n\t\"info\",\n\t\"warn\",\n\t\"error\",\n\t\"fatal\",\n\t\"silent\",\n]);\n\nexport type LogLevel = z.infer<typeof LogLevelSchema>;\n\nexport function getPinoLevel(logLevel?: LogLevel): LevelWithSilent {\n\t// Priority: provided > configured > env > default\n\tif (logLevel) {\n\t\treturn logLevel;\n\t}\n\n\tif (configuredLogLevel) {\n\t\treturn configuredLogLevel;\n\t}\n\n\tconst raw = (getLogLevel() || \"warn\").toString().toLowerCase();\n\n\tconst parsed = LogLevelSchema.safeParse(raw);\n\tif (parsed.success) {\n\t\treturn parsed.data;\n\t}\n\n\t// Default to info if invalid\n\treturn \"info\";\n}\n\nexport function getIncludeTarget(): boolean {\n\treturn getLogTarget();\n}\n\n/**\n * Configure a custom base logger.\n */\nexport function configureBaseLogger(logger: Logger): void {\n\tbaseLogger = logger;\n\tloggerCache.clear();\n}\n\n// TODO: This can be simplified in logfmt.ts\nfunction customWrite(level: string, o: any) {\n\tconst entries: any = {};\n\n\t// Add timestamp if enabled\n\tif (getLogTimestamp() && o.time) {\n\t\tconst date = typeof o.time === \"number\" ? new Date(o.time) : new Date();\n\t\tentries.ts = formatTimestamp(date);\n\t}\n\n\t// Add level\n\tentries.level = level.toUpperCase();\n\n\t// Add target if present\n\tif (o.target) {\n\t\tentries.target = o.target;\n\t}\n\n\t// Add message\n\tif (o.msg) {\n\t\tentries.msg = o.msg;\n\t}\n\n\t// Add other properties\n\tfor (const [key, value] of Object.entries(o)) {\n\t\tif (\n\t\t\tkey !== \"time\" &&\n\t\t\tkey !== \"level\" &&\n\t\t\tkey !== \"target\" &&\n\t\t\tkey !== \"msg\" &&\n\t\t\tkey !== \"pid\" &&\n\t\t\tkey !== \"hostname\"\n\t\t) {\n\t\t\tentries[key] = castToLogValue(value);\n\t\t}\n\t}\n\n\tconst output = stringify(entries);\n\tconsole.log(output);\n}\n\n/**\n * Configure the default logger with optional log level.\n */\nexport function configureDefaultLogger(logLevel?: LogLevel) {\n\t// Store the configured log level\n\tif (logLevel) {\n\t\tconfiguredLogLevel = logLevel;\n\t}\n\n\tbaseLogger = pino({\n\t\tlevel: getPinoLevel(logLevel),\n\t\tmessageKey: \"msg\",\n\t\t// Do not include pid/hostname in output\n\t\tbase: {},\n\t\t// Keep a string level in the output\n\t\tformatters: {\n\t\t\tlevel(_label: string, number: number) {\n\t\t\t\treturn { level: number };\n\t\t\t},\n\t\t},\n\t\ttimestamp: getLogTimestamp() ? stdTimeFunctions.epochTime : false,\n\t\tbrowser: {\n\t\t\twrite: {\n\t\t\t\tfatal: customWrite.bind(null, \"fatal\"),\n\t\t\t\terror: customWrite.bind(null, \"error\"),\n\t\t\t\twarn: customWrite.bind(null, \"warn\"),\n\t\t\t\tinfo: customWrite.bind(null, \"info\"),\n\t\t\t\tdebug: customWrite.bind(null, \"debug\"),\n\t\t\t\ttrace: customWrite.bind(null, \"trace\"),\n\t\t\t},\n\t\t},\n\t\thooks: {\n\t\t\tlogMethod(inputArgs, method, level) {\n\t\t\t\t// TODO: This is a hack to not implement our own Pino transport target. We can get better perf if we have our own transport target.\n\n\t\t\t\tconst levelMap: Record<number, string> = {\n\t\t\t\t\t10: \"trace\",\n\t\t\t\t\t20: \"debug\",\n\t\t\t\t\t30: \"info\",\n\t\t\t\t\t40: \"warn\",\n\t\t\t\t\t50: \"error\",\n\t\t\t\t\t60: \"fatal\",\n\t\t\t\t};\n\t\t\t\tconst levelName = levelMap[level] || \"info\";\n\t\t\t\tconst time = getLogTimestamp() ? Date.now() : undefined;\n\n\t\t\t\t// Get bindings from the logger instance (child logger fields)\n\t\t\t\tconst bindings = (this as any).bindings?.() || {};\n\n\t\t\t\t// TODO: This can be simplified in logfmt.ts\n\t\t\t\tif (inputArgs.length >= 2) {\n\t\t\t\t\tconst [objOrMsg, msg] = inputArgs;\n\t\t\t\t\tif (typeof objOrMsg === \"object\" && objOrMsg !== null) {\n\t\t\t\t\t\tcustomWrite(levelName, {\n\t\t\t\t\t\t\t...bindings,\n\t\t\t\t\t\t\t...objOrMsg,\n\t\t\t\t\t\t\tmsg,\n\t\t\t\t\t\t\ttime,\n\t\t\t\t\t\t});\n\t\t\t\t\t} else {\n\t\t\t\t\t\tcustomWrite(levelName, {\n\t\t\t\t\t\t\t...bindings,\n\t\t\t\t\t\t\tmsg: String(objOrMsg),\n\t\t\t\t\t\t\ttime,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t} else if (inputArgs.length === 1) {\n\t\t\t\t\tconst [objOrMsg] = inputArgs;\n\t\t\t\t\tif (typeof objOrMsg === \"object\" && objOrMsg !== null) {\n\t\t\t\t\t\tcustomWrite(levelName, {\n\t\t\t\t\t\t\t...bindings,\n\t\t\t\t\t\t\t...objOrMsg,\n\t\t\t\t\t\t\ttime,\n\t\t\t\t\t\t});\n\t\t\t\t\t} else {\n\t\t\t\t\t\tcustomWrite(levelName, {\n\t\t\t\t\t\t\t...bindings,\n\t\t\t\t\t\t\tmsg: String(objOrMsg),\n\t\t\t\t\t\t\ttime,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t});\n\n\tloggerCache.clear();\n}\n\n/**\n * Get or initialize the base logger.\n */\nexport function getBaseLogger(): Logger {\n\tif (!baseLogger) {\n\t\tconfigureDefaultLogger();\n\t}\n\treturn baseLogger!;\n}\n\n/**\n * Returns a child logger with `target` bound for the given name.\n */\nexport function getLogger(name = \"default\"): Logger {\n\t// Check cache first\n\tconst cached = loggerCache.get(name);\n\tif (cached) {\n\t\treturn cached;\n\t}\n\n\t// Create\n\tconst base = getBaseLogger();\n\n\t// Add target to log if enabled\n\tconst child = getIncludeTarget() ? base.child({ target: name }) : base;\n\n\t// Cache the logger\n\tloggerCache.set(name, child);\n\n\treturn child;\n}\n","export type LogLevel =\n\t| \"TRACE\"\n\t| \"DEBUG\"\n\t| \"INFO\"\n\t| \"WARN\"\n\t| \"ERROR\"\n\t| \"CRITICAL\";\n\nexport const LogLevels: Record<LogLevel, LevelIndex> = {\n\tTRACE: 0,\n\tDEBUG: 1,\n\tINFO: 2,\n\tWARN: 3,\n\tERROR: 4,\n\tCRITICAL: 5,\n} as const;\n\nexport const LevelNameMap: Record<number, LogLevel> = {\n\t0: \"TRACE\",\n\t1: \"DEBUG\",\n\t2: \"INFO\",\n\t3: \"WARN\",\n\t4: \"ERROR\",\n\t5: \"CRITICAL\",\n};\n\nexport type LevelIndex = number;\n","import { type LogLevel, LogLevels } from \"./log-levels\";\n\nconst LOG_LEVEL_COLORS: Record<number, string> = {\n\t[LogLevels.CRITICAL]: \"\\x1b[31m\", // Red\n\t[LogLevels.ERROR]: \"\\x1b[31m\", // Red\n\t[LogLevels.WARN]: \"\\x1b[33m\", // Yellow\n\t[LogLevels.INFO]: \"\\x1b[32m\", // Green\n\t[LogLevels.DEBUG]: \"\\x1b[36m\", // Cyan\n\t[LogLevels.TRACE]: \"\\x1b[36m\", // Cyan\n};\n\nconst RESET_COLOR = \"\\x1b[0m\";\n\n/**\n * Serializes logfmt line from an object.\n *\n * ## Styling Methodology\n *\n * The three things you need to know for every log line is the level, the\n * message, and who called it. These properties are highlighted in different colros\n * and sorted in th eorder that you usually read them.\n *\n * Once you've found a log line you care about, then you want to find the\n * property you need to see. The property names are bolded and the default color\n * while the rest of the data is dim. This lets you scan to find the property\n * name quickly then look closer to read the data associated with the\n * property.\n */\nexport function stringify(data: any) {\n\tlet line = \"\";\n\tconst entries = Object.entries(data);\n\n\tfor (let i = 0; i < entries.length; i++) {\n\t\tconst [key, valueRaw] = entries[i];\n\n\t\tlet isNull = false;\n\t\tlet valueString: string;\n\t\tif (valueRaw == null) {\n\t\t\tisNull = true;\n\t\t\tvalueString = \"\";\n\t\t} else {\n\t\t\tvalueString = valueRaw.toString();\n\t\t}\n\n\t\t// Clip value unless specifically the error message\n\t\tif (valueString.length > 512 && key !== \"msg\" && key !== \"error\")\n\t\t\tvalueString = `${valueString.slice(0, 512)}...`;\n\n\t\tconst needsQuoting =\n\t\t\tvalueString.indexOf(\" \") > -1 || valueString.indexOf(\"=\") > -1;\n\t\tconst needsEscaping =\n\t\t\tvalueString.indexOf('\"') > -1 || valueString.indexOf(\"\\\\\") > -1;\n\n\t\tvalueString = valueString.replace(/\\n/g, \"\\\\n\");\n\t\tif (needsEscaping) valueString = valueString.replace(/[\"\\\\]/g, \"\\\\$&\");\n\t\tif (needsQuoting || needsEscaping) valueString = `\"${valueString}\"`;\n\t\tif (valueString === \"\" && !isNull) valueString = '\"\"';\n\n\t\tif (LOGGER_CONFIG.enableColor) {\n\t\t\t// With color\n\n\t\t\t// Special message colors\n\t\t\tlet color = \"\\x1b[2m\";\n\t\t\tif (key === \"level\") {\n\t\t\t\tconst level = LogLevels[valueString as LogLevel];\n\t\t\t\tconst levelColor = LOG_LEVEL_COLORS[level];\n\t\t\t\tif (levelColor) {\n\t\t\t\t\tcolor = levelColor;\n\t\t\t\t}\n\t\t\t} else if (key === \"msg\") {\n\t\t\t\tcolor = \"\\x1b[32m\";\n\t\t\t} else if (key === \"trace\") {\n\t\t\t\tcolor = \"\\x1b[34m\";\n\t\t\t}\n\n\t\t\t// Format line\n\t\t\tline += `\\x1b[0m\\x1b[1m${key}\\x1b[0m\\x1b[2m=\\x1b[0m${color}${valueString}${RESET_COLOR}`;\n\t\t} else {\n\t\t\t// No color\n\t\t\tline += `${key}=${valueString}`;\n\t\t}\n\n\t\tif (i !== entries.length - 1) {\n\t\t\tline += \" \";\n\t\t}\n\t}\n\n\treturn line;\n}\n\nexport function formatTimestamp(date: Date): string {\n\tconst year = date.getUTCFullYear();\n\tconst month = String(date.getUTCMonth() + 1).padStart(2, \"0\");\n\tconst day = String(date.getUTCDate()).padStart(2, \"0\");\n\tconst hours = String(date.getUTCHours()).padStart(2, \"0\");\n\tconst minutes = String(date.getUTCMinutes()).padStart(2, \"0\");\n\tconst seconds = String(date.getUTCSeconds()).padStart(2, \"0\");\n\tconst milliseconds = String(date.getUTCMilliseconds()).padStart(3, \"0\");\n\n\treturn `${year}-${month}-${day}T${hours}:${minutes}:${seconds}.${milliseconds}Z`;\n}\n\nexport function castToLogValue(v: unknown): any {\n\tif (\n\t\ttypeof v === \"string\" ||\n\t\ttypeof v === \"number\" ||\n\t\ttypeof v === \"bigint\" ||\n\t\ttypeof v === \"boolean\" ||\n\t\tv === null ||\n\t\tv === undefined\n\t) {\n\t\treturn v;\n\t}\n\tif (v instanceof Error) {\n\t\t//args.push(...errorToLogEntries(k, v));\n\t\treturn String(v);\n\t}\n\ttry {\n\t\treturn JSON.stringify(v);\n\t} catch {\n\t\treturn \"[cannot stringify]\";\n\t}\n}\n\n// MARK: Config\ninterface GlobalLoggerConfig {\n\tenableColor: boolean;\n\tenableSpreadObject: boolean;\n\tenableErrorStack: boolean;\n}\n\nexport const LOGGER_CONFIG: GlobalLoggerConfig = {\n\tenableColor: false,\n\tenableSpreadObject: false,\n\tenableErrorStack: false,\n};\n\n// MARK: Utils\n/**\n * Converts an object in to an easier to read KV of entries.\n */\nexport function spreadObjectToLogEntries(base: string, data: unknown): any {\n\tif (\n\t\tLOGGER_CONFIG.enableSpreadObject &&\n\t\ttypeof data === \"object\" &&\n\t\t!Array.isArray(data) &&\n\t\tdata !== null &&\n\t\tObject.keys(data).length !== 0 &&\n\t\tObject.keys(data).length < 16\n\t) {\n\t\tconst logData: any = {};\n\t\tfor (const key in data) {\n\t\t\tObject.assign(\n\t\t\t\tlogData,\n\t\t\t\tspreadObjectToLogEntries(\n\t\t\t\t\t`${base}.${key}`,\n\t\t\t\t\t// biome-ignore lint/suspicious/noExplicitAny: FIXME\n\t\t\t\t\t(data as any)[key],\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t\treturn logData;\n\t}\n\n\treturn { [base]: JSON.stringify(data) };\n}\n\nexport function errorToLogEntries(base: string, error: unknown): any {\n\tif (error instanceof Error) {\n\t\treturn {\n\t\t\t[`${base}.message`]: error.message,\n\t\t\t...(LOGGER_CONFIG.enableErrorStack && error.stack\n\t\t\t\t? { [`${base}.stack`]: formatStackTrace(error.stack) }\n\t\t\t\t: {}),\n\t\t\t...(error.cause\n\t\t\t\t? errorToLogEntries(`${base}.cause`, error.cause)\n\t\t\t\t: {}),\n\t\t};\n\t}\n\treturn { [base]: `${error}` };\n}\n\n// export function errorToLogEntries(base: string, error: unknown): LogEntry[] {\n// \tif (error instanceof RuntimeError) {\n// \t\treturn [\n// \t\t\t[`${base}.code`, error.code],\n// \t\t\t[`${base}.description`, error.errorConfig?.description],\n// \t\t\t[`${base}.module`, error.moduleName],\n// \t\t\t...(error.trace ? [[`${base}.trace`, stringifyTrace(error.trace)] as LogEntry] : []),\n// \t\t\t...(LOGGER_CONFIG.enableErrorStack && error.stack\n// \t\t\t\t? [[`${base}.stack`, formatStackTrace(error.stack)] as LogEntry]\n// \t\t\t\t: []),\n// \t\t\t...(error.meta ? [[`${base}.meta`, JSON.stringify(error.meta)] as LogEntry] : []),\n// \t\t\t...(error.cause ? errorToLogEntries(`${base}.cause`, error.cause) : []),\n// \t\t];\n// \t} else if (error instanceof Error) {\n// \t\treturn [\n// \t\t\t[`${base}.name`, error.name],\n// \t\t\t[`${base}.message`, error.message],\n// \t\t\t...(LOGGER_CONFIG.enableErrorStack && error.stack\n// \t\t\t\t? [[`${base}.stack`, formatStackTrace(error.stack)] as LogEntry]\n// \t\t\t\t: []),\n// \t\t\t...(error.cause ? errorToLogEntries(`${base}.cause`, error.cause) : []),\n// \t\t];\n// \t} else {\n// \t\treturn [\n// \t\t\t[base, `${error}`],\n// \t\t];\n// \t}\n// }\n\n/**\n * Formats a JS stack trace in to a legible one-liner.\n */\nfunction formatStackTrace(stackTrace: string): string {\n\tconst regex = /at (.+?)$/gm;\n\tconst matches = [...stackTrace.matchAll(regex)];\n\t// Reverse array since the stack goes from top level -> bottom level\n\tmatches.reverse();\n\treturn matches.map((match) => match[1].trim()).join(\" > \");\n}\n","import { stringifyError } from \"@/common/utils\";\nimport type { Context as HonoContext, Handler as HonoHandler } from \"hono\";\nimport { stringify as uuidstringify } from \"uuid\";\nimport pkgJson from \"../package.json\" with { type: \"json\" };\nimport { getLogger } from \"./common/log\";\nimport { assertUnreachable } from \"./common/utils\";\n\n/** @experimental */\nexport { stringifyError };\n\n/** @experimental */\nexport { assertUnreachable };\n\n/**\n * Joins multiple abort signals into one.\n *\n * The returned signal aborts when the first input signal aborts.\n * Uses `AbortSignal.any(...)` when available, with a runtime fallback.\n *\n * @experimental\n */\nexport function joinSignals(\n\t...signals: Array<AbortSignal | undefined | null>\n): AbortSignal {\n\tconst validSignals = signals.filter(\n\t\t(signal): signal is AbortSignal => signal != null,\n\t);\n\n\tif (validSignals.length === 0) {\n\t\treturn new AbortController().signal;\n\t}\n\n\tif (validSignals.length === 1) {\n\t\treturn validSignals[0];\n\t}\n\n\tconst signalAny = (\n\t\tAbortSignal as typeof AbortSignal & {\n\t\t\tany?: (signals: AbortSignal[]) => AbortSignal;\n\t\t}\n\t).any;\n\tif (typeof signalAny === \"function\") {\n\t\treturn signalAny(validSignals);\n\t}\n\n\tconst controller = new AbortController();\n\tconst cleanups: Array<() => void> = [];\n\n\tconst abortWithSignal = (signal: AbortSignal) => {\n\t\tif (controller.signal.aborted) {\n\t\t\treturn;\n\t\t}\n\n\t\tfor (const cleanup of cleanups) {\n\t\t\tcleanup();\n\t\t}\n\n\t\tconst reason = (signal as AbortSignal & { reason?: unknown }).reason;\n\t\tcontroller.abort(reason);\n\t};\n\n\tfor (const signal of validSignals) {\n\t\tif (signal.aborted) {\n\t\t\tabortWithSignal(signal);\n\t\t\tbreak;\n\t\t}\n\n\t\tconst onAbort = () => abortWithSignal(signal);\n\t\tsignal.addEventListener(\"abort\", onAbort, { once: true });\n\t\tcleanups.push(() => signal.removeEventListener(\"abort\", onAbort));\n\t}\n\n\treturn controller.signal;\n}\n\n/**\n * Returns a promise that resolves after the given number of milliseconds.\n *\n * @experimental\n */\nexport function sleep(ms: number): Promise<void> {\n\treturn new Promise<void>((resolve) => setTimeout(resolve, ms));\n}\n\n/**\n * Creates a fixed-rate interval tick function that can be awaited in a loop.\n *\n * @example\n * const tick = interval(100);\n * while (!c.aborted) {\n * await tick();\n * if (c.aborted) break;\n * // ... game logic\n * }\n *\n * @experimental\n */\nexport function interval(ms: number): () => Promise<void> {\n\treturn () => sleep(ms);\n}\n\nexport const VERSION = pkgJson.version;\n\nlet _userAgent: string | undefined;\n\nfunction logger() {\n\treturn getLogger(\"utils\");\n}\n\n/**\n * Builds the HTTP user agent used by this library.\n *\n * @experimental\n */\nexport function httpUserAgent(): string {\n\t// Return cached value if already initialized\n\tif (_userAgent !== undefined) {\n\t\treturn _userAgent;\n\t}\n\n\t// Library\n\tlet userAgent = `RivetKit/${VERSION}`;\n\n\t// Navigator\n\tconst navigatorObj =\n\t\ttypeof navigator !== \"undefined\" ? navigator : undefined;\n\tif (navigatorObj?.userAgent) userAgent += ` ${navigatorObj.userAgent}`;\n\n\t_userAgent = userAgent;\n\n\treturn userAgent;\n}\n\nexport type UpgradeWebSocket = (\n\tcreateEvents: (c: HonoContext) => any,\n) => HonoHandler;\n\nexport type GetUpgradeWebSocket = () => UpgradeWebSocket;\n\n/**\n * Reads an environment variable from Deno or Node runtimes.\n *\n * @experimental\n */\nexport function getEnvUniversal(key: string): string | undefined {\n\tif (typeof Deno !== \"undefined\") {\n\t\treturn Deno.env.get(key);\n\t} else if (typeof process !== \"undefined\") {\n\t\t// Do this after Deno since `process` is sometimes polyfilled\n\t\treturn process.env[key];\n\t}\n}\n\n/**\n * Traces a debug value and returns it.\n *\n * @experimental\n */\nexport function dbg<T>(x: T): T {\n\tconsole.trace(`=== DEBUG ===\\n${x}`);\n\treturn x;\n}\n\n/**\n * Converts various ArrayBuffer-like types to Uint8Array.\n * Handles ArrayBuffer, ArrayBufferView (including typed arrays), and passes through existing Uint8Array.\n *\n * @param data - The ArrayBuffer or ArrayBufferView to convert\n * @returns A Uint8Array view of the data\n *\n * @experimental\n */\nexport function toUint8Array(data: ArrayBuffer | ArrayBufferView): Uint8Array {\n\tif (data instanceof Uint8Array) {\n\t\treturn data;\n\t} else if (data instanceof ArrayBuffer) {\n\t\treturn new Uint8Array(data);\n\t} else if (ArrayBuffer.isView(data)) {\n\t\t// Handle other ArrayBufferView types (Int8Array, Uint16Array, DataView, etc.)\n\t\treturn new Uint8Array(\n\t\t\tdata.buffer.slice(\n\t\t\t\tdata.byteOffset,\n\t\t\t\tdata.byteOffset + data.byteLength,\n\t\t\t),\n\t\t);\n\t} else {\n\t\tthrow new TypeError(\"Input must be ArrayBuffer or ArrayBufferView\");\n\t}\n}\n\n// Long timeouts\n//\n// JavaScript timers use a signed 32-bit integer for delays, so values above 2^31-1 (~24.8 days)\n// are not reliable and may fire immediately or overflow.\n//\n// https://developer.mozilla.org/en-US/docs/Web/API/Window/setTimeout#maximum_delay_value\nconst TIMEOUT_MAX = 2147483647; // 2^31-1\n\nexport type LongTimeoutHandle = { abort: () => void };\n\n/**\n * Polyfill for Promise.withResolvers().\n *\n * This is specifically for Cloudflare Workers. Their implementation of Promise.withResolvers does not work correctly.\n *\n * @experimental\n */\nexport function promiseWithResolvers<T>(onReject: (reason?: any) => void): {\n\tpromise: Promise<T>;\n\tresolve: (value: T | PromiseLike<T>) => void;\n\treject: (reason?: any) => void;\n} {\n\tlet resolve!: (value: T | PromiseLike<T>) => void;\n\tlet reject!: (reason?: any) => void;\n\tconst promise = new Promise<T>((res, rej) => {\n\t\tresolve = res;\n\t\treject = rej;\n\t});\n\tpromise.catch(onReject);\n\treturn { promise, resolve, reject };\n}\n\n/**\n * Sets a timeout that supports delays larger than the JavaScript timer limit.\n *\n * @experimental\n */\nexport function setLongTimeout(\n\tlistener: () => void,\n\tafter: number,\n): LongTimeoutHandle {\n\tlet timeout: ReturnType<typeof setTimeout> | undefined;\n\n\tfunction start(remaining: number) {\n\t\tif (remaining <= TIMEOUT_MAX) {\n\t\t\ttimeout = setTimeout(listener, remaining);\n\t\t} else {\n\t\t\ttimeout = setTimeout(() => {\n\t\t\t\tstart(remaining - TIMEOUT_MAX);\n\t\t\t}, TIMEOUT_MAX);\n\t\t}\n\t}\n\n\tstart(after);\n\n\treturn {\n\t\tabort: () => {\n\t\t\tif (timeout !== undefined) clearTimeout(timeout);\n\t\t},\n\t};\n}\n\n/**\n * A tiny utility that coalesces/enqueues async operations so only the latest\n * queued task runs per cycle, while callers receive a promise that resolves\n * when the task for the cycle they joined has completed.\n */\nexport class SinglePromiseQueue {\n\t/** Next operation to execute in the queue. If attempting to enqueue another op, it will override the existing op. */\n\t#queuedOp?: () => Promise<void>;\n\n\t/** The currently running promise of #drainLoop. Do not await this, instead await `pending` to await the current cycle. */\n\trunningDrainLoop?: Promise<void>;\n\n\t/** Pending resolver fro the currently queued entry. */\n\t#pending?: ReturnType<typeof promiseWithResolvers<void>>;\n\n\t/** Queue the next operation and return a promise that resolves when it flushes. */\n\tenqueue(op: () => Promise<void>): Promise<void> {\n\t\t// Replace any previously queued operation with the latest one\n\t\tthis.#queuedOp = op;\n\n\t\t// Ensure a shared resolver exists for all callers in this cycle\n\t\tif (!this.#pending) {\n\t\t\tthis.#pending = promiseWithResolvers<void>((reason) => logger().warn({ msg: \"unhandled single promise queue rejection\", reason }));\n\t\t}\n\n\t\tconst waitForThisCycle = this.#pending.promise;\n\n\t\t// Start runner if not already running\n\t\tif (!this.runningDrainLoop) {\n\t\t\tthis.runningDrainLoop = this.#drainLoop();\n\t\t}\n\n\t\treturn waitForThisCycle;\n\t}\n\n\t/** Drain queued operations sequentially until there is nothing left. */\n\tasync #drainLoop(): Promise<void> {\n\t\ttry {\n\t\t\twhile (this.#queuedOp) {\n\t\t\t\t// Capture current cycle resolver then reset for the next cycle\n\t\t\t\tconst resolver = this.#pending;\n\t\t\t\tthis.#pending = undefined;\n\n\t\t\t\t// Capture and clear the currently queued operation\n\t\t\t\tconst op = this.#queuedOp;\n\t\t\t\tthis.#queuedOp = undefined;\n\n\t\t\t\ttry {\n\t\t\t\t\tawait op();\n\t\t\t\t\t// Notify all waiters for this cycle\n\t\t\t\t\tresolver?.resolve();\n\t\t\t\t} catch (err) {\n\t\t\t\t\tlogger().error({\n\t\t\t\t\t\tmsg: \"error in SinglePromiseQueue drain loop\",\n\t\t\t\t\t\terror: stringifyError(err),\n\t\t\t\t\t});\n\t\t\t\t\t// Reject all waiters for this cycle\n\t\t\t\t\tresolver?.reject(err);\n\t\t\t\t}\n\t\t\t}\n\t\t} finally {\n\t\t\tthis.runningDrainLoop = undefined;\n\t\t}\n\t}\n}\n\n/**\n * Converts a Buffer or Uint8Array into an ArrayBuffer view.\n *\n * @experimental\n */\nexport function bufferToArrayBuffer(buf: Buffer | Uint8Array): ArrayBuffer {\n\treturn buf.buffer.slice(\n\t\tbuf.byteOffset,\n\t\tbuf.byteOffset + buf.byteLength,\n\t) as ArrayBuffer;\n}\n\n/**\n * Properly combines a base URL endpoint with a path, preserving any base path in the endpoint.\n *\n * @example\n * combineUrlPath(\"http://localhost:8787/rivet\", \"/actors/action\")\n * // Returns: \"http://localhost:8787/rivet/actors/action\"\n *\n * @example\n * combineUrlPath(\"http://localhost:8787/rivet\", \"/actors?type=foo\", { namespace: \"test\" })\n * // Returns: \"http://localhost:8787/rivet/actors?type=foo&namespace=test\"\n *\n * @param endpoint The base URL endpoint that may contain a path component\n * @param path The path to append to the endpoint (may include query parameters)\n * @param queryParams Optional additional query parameters to append\n * @returns The properly combined URL string\n *\n * @experimental\n */\nexport function combineUrlPath(\n\tendpoint: string,\n\tpath: string,\n\tqueryParams?: Record<string, string | undefined>,\n): string {\n\tconst baseUrl = new URL(endpoint);\n\n\t// Extract path and query from the provided path\n\tconst pathParts = path.split(\"?\");\n\tconst pathOnly = pathParts[0];\n\tconst existingQuery = pathParts[1] || \"\";\n\n\t// Remove trailing slash from base path and ensure path starts with /\n\tconst basePath = baseUrl.pathname.replace(/\\/$/, \"\");\n\tconst cleanPath = pathOnly.startsWith(\"/\") ? pathOnly : `/${pathOnly}`;\n\t// Combine paths and remove any double slashes\n\tconst fullPath = (basePath + cleanPath).replace(/\\/\\//g, \"/\");\n\n\t// Build query string\n\tconst queryParts: string[] = [];\n\tif (existingQuery) {\n\t\tqueryParts.push(existingQuery);\n\t}\n\tif (queryParams) {\n\t\tfor (const [key, value] of Object.entries(queryParams)) {\n\t\t\tif (value !== undefined) {\n\t\t\t\tqueryParts.push(\n\t\t\t\t\t`${encodeURIComponent(key)}=${encodeURIComponent(value)}`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\tconst fullQuery = queryParts.length > 0 ? `?${queryParts.join(\"&\")}` : \"\";\n\treturn `${baseUrl.protocol}//${baseUrl.host}${fullPath}${fullQuery}`;\n}\n\n/**\n * Compares two ArrayBuffer values by byte content.\n *\n * @experimental\n */\nexport function arrayBuffersEqual(\n\tbuf1: ArrayBuffer,\n\tbuf2: ArrayBuffer,\n): boolean {\n\tif (buf1.byteLength !== buf2.byteLength) return false;\n\n\tconst view1 = new Uint8Array(buf1);\n\tconst view2 = new Uint8Array(buf2);\n\n\tfor (let i = 0; i < view1.length; i++) {\n\t\tif (view1[i] !== view2[i]) return false;\n\t}\n\treturn true;\n}\n\nexport const EXTRA_ERROR_LOG = {\n\tissues: \"https://github.com/rivet-dev/rivetkit/issues\",\n\tsupport: \"https://rivet.dev/discord\",\n\tversion: VERSION,\n};\n\nexport type Runtime = \"deno\" | \"bun\" | \"node\";\n\n/**\n * Detects the current JavaScript runtime from the user agent.\n *\n * @experimental\n */\nexport function detectRuntime(): Runtime {\n\tconst userAgent =\n\t\ttypeof navigator !== \"undefined\" ? navigator.userAgent : \"\";\n\tif (userAgent.includes(\"Deno\")) {\n\t\treturn \"deno\";\n\t}\n\tif (userAgent.includes(\"Bun\")) {\n\t\treturn \"bun\";\n\t}\n\treturn \"node\";\n}\n\nexport type DeepReadonly<T> = {\n\treadonly [K in keyof T]: T[K] extends object ? DeepReadonly<T[K]> : T[K];\n};\n\nexport type DeepMutable<T> = {\n\t-readonly [K in keyof T]: T[K] extends object ? DeepMutable<T[K]> : T[K];\n};\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
bufferToArrayBuffer,
|
|
3
3
|
toUint8Array
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-WUXR722E.js";
|
|
5
5
|
|
|
6
6
|
// dist/schemas/transport/v1.ts
|
|
7
7
|
import * as bare from "@rivetkit/bare-ts";
|
|
@@ -531,4 +531,4 @@ export {
|
|
|
531
531
|
encodeWorkflowHistoryTransport,
|
|
532
532
|
decodeWorkflowHistoryTransport
|
|
533
533
|
};
|
|
534
|
-
//# sourceMappingURL=chunk-
|
|
534
|
+
//# sourceMappingURL=chunk-TDFDR7AO.js.map
|
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
var
|
|
4
|
+
var _chunkNXEHFUDBcjs = require('./chunk-NXEHFUDB.cjs');
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _chunk772NPMTYcjs = require('./chunk-772NPMTY.cjs');
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
var _chunk6LJAZ5R4cjs = require('./chunk-6LJAZ5R4.cjs');
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
|
|
15
|
-
var
|
|
15
|
+
var _chunkRMJJE43Bcjs = require('./chunk-RMJJE43B.cjs');
|
|
16
16
|
|
|
17
17
|
// src/driver-test-suite/log.ts
|
|
18
18
|
function logger() {
|
|
19
|
-
return
|
|
19
|
+
return _chunkRMJJE43Bcjs.getLogger.call(void 0, "test-suite");
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
// fixtures/driver-test-suite/hibernation.ts
|
|
23
23
|
var HIBERNATION_SLEEP_TIMEOUT = 500;
|
|
24
|
-
var hibernationActor =
|
|
24
|
+
var hibernationActor = _chunk772NPMTYcjs.actor.call(void 0, {
|
|
25
25
|
state: {
|
|
26
26
|
sleepCount: 0,
|
|
27
27
|
wakeCount: 0
|
|
@@ -89,7 +89,7 @@ var hibernationActor = _chunk65RINRXEcjs.actor.call(void 0, {
|
|
|
89
89
|
|
|
90
90
|
// fixtures/driver-test-suite/sleep.ts
|
|
91
91
|
var SLEEP_TIMEOUT = 1e3;
|
|
92
|
-
var sleep =
|
|
92
|
+
var sleep = _chunk772NPMTYcjs.actor.call(void 0, {
|
|
93
93
|
state: { startCount: 0, sleepCount: 0 },
|
|
94
94
|
onWake: (c) => {
|
|
95
95
|
c.state.startCount += 1;
|
|
@@ -118,7 +118,7 @@ var sleep = _chunk65RINRXEcjs.actor.call(void 0, {
|
|
|
118
118
|
sleepTimeout: SLEEP_TIMEOUT
|
|
119
119
|
}
|
|
120
120
|
});
|
|
121
|
-
var sleepWithLongRpc =
|
|
121
|
+
var sleepWithLongRpc = _chunk772NPMTYcjs.actor.call(void 0, {
|
|
122
122
|
state: { startCount: 0, sleepCount: 0 },
|
|
123
123
|
createVars: () => ({}),
|
|
124
124
|
onWake: (c) => {
|
|
@@ -136,7 +136,7 @@ var sleepWithLongRpc = _chunk65RINRXEcjs.actor.call(void 0, {
|
|
|
136
136
|
},
|
|
137
137
|
longRunningRpc: async (c) => {
|
|
138
138
|
c.log.info("starting long running rpc");
|
|
139
|
-
c.vars.longRunningResolve =
|
|
139
|
+
c.vars.longRunningResolve = _chunkRMJJE43Bcjs.promiseWithResolvers.call(void 0, (reason) => c.log.warn({ msg: "unhandled long running rpc rejection", reason }));
|
|
140
140
|
c.broadcast("waiting");
|
|
141
141
|
await c.vars.longRunningResolve.promise;
|
|
142
142
|
c.log.info("finished long running rpc");
|
|
@@ -150,7 +150,7 @@ var sleepWithLongRpc = _chunk65RINRXEcjs.actor.call(void 0, {
|
|
|
150
150
|
sleepTimeout: SLEEP_TIMEOUT
|
|
151
151
|
}
|
|
152
152
|
});
|
|
153
|
-
var sleepWithRawHttp =
|
|
153
|
+
var sleepWithRawHttp = _chunk772NPMTYcjs.actor.call(void 0, {
|
|
154
154
|
state: { startCount: 0, sleepCount: 0, requestCount: 0 },
|
|
155
155
|
onWake: (c) => {
|
|
156
156
|
c.state.startCount += 1;
|
|
@@ -187,7 +187,7 @@ var sleepWithRawHttp = _chunk65RINRXEcjs.actor.call(void 0, {
|
|
|
187
187
|
sleepTimeout: SLEEP_TIMEOUT
|
|
188
188
|
}
|
|
189
189
|
});
|
|
190
|
-
var sleepWithRawWebSocket =
|
|
190
|
+
var sleepWithRawWebSocket = _chunk772NPMTYcjs.actor.call(void 0, {
|
|
191
191
|
state: { startCount: 0, sleepCount: 0, connectionCount: 0 },
|
|
192
192
|
onWake: (c) => {
|
|
193
193
|
c.state.startCount += 1;
|
|
@@ -250,7 +250,7 @@ var sleepWithRawWebSocket = _chunk65RINRXEcjs.actor.call(void 0, {
|
|
|
250
250
|
sleepTimeout: SLEEP_TIMEOUT
|
|
251
251
|
}
|
|
252
252
|
});
|
|
253
|
-
var sleepWithNoSleepOption =
|
|
253
|
+
var sleepWithNoSleepOption = _chunk772NPMTYcjs.actor.call(void 0, {
|
|
254
254
|
state: { startCount: 0, sleepCount: 0 },
|
|
255
255
|
onWake: (c) => {
|
|
256
256
|
c.state.startCount += 1;
|
|
@@ -274,7 +274,7 @@ var sleepWithNoSleepOption = _chunk65RINRXEcjs.actor.call(void 0, {
|
|
|
274
274
|
|
|
275
275
|
// fixtures/driver-test-suite/run.ts
|
|
276
276
|
var RUN_SLEEP_TIMEOUT = 1e3;
|
|
277
|
-
var runWithTicks =
|
|
277
|
+
var runWithTicks = _chunk772NPMTYcjs.actor.call(void 0, {
|
|
278
278
|
state: {
|
|
279
279
|
tickCount: 0,
|
|
280
280
|
lastTickAt: 0,
|
|
@@ -316,7 +316,7 @@ var runWithTicks = _chunk65RINRXEcjs.actor.call(void 0, {
|
|
|
316
316
|
runStopTimeout: 1e3
|
|
317
317
|
}
|
|
318
318
|
});
|
|
319
|
-
var runWithQueueConsumer =
|
|
319
|
+
var runWithQueueConsumer = _chunk772NPMTYcjs.actor.call(void 0, {
|
|
320
320
|
state: {
|
|
321
321
|
messagesReceived: [],
|
|
322
322
|
runStarted: false,
|
|
@@ -329,8 +329,7 @@ var runWithQueueConsumer = _chunk65RINRXEcjs.actor.call(void 0, {
|
|
|
329
329
|
c.state.runStarted = true;
|
|
330
330
|
c.log.info("run handler started, waiting for messages");
|
|
331
331
|
while (!c.aborted) {
|
|
332
|
-
const
|
|
333
|
-
const message = messages[0];
|
|
332
|
+
const message = await c.queue.next({ names: ["messages"] });
|
|
334
333
|
if (message) {
|
|
335
334
|
c.log.info({ msg: "received message", body: message.body });
|
|
336
335
|
c.state.messagesReceived.push({
|
|
@@ -359,7 +358,7 @@ var runWithQueueConsumer = _chunk65RINRXEcjs.actor.call(void 0, {
|
|
|
359
358
|
runStopTimeout: 1e3
|
|
360
359
|
}
|
|
361
360
|
});
|
|
362
|
-
var runWithEarlyExit =
|
|
361
|
+
var runWithEarlyExit = _chunk772NPMTYcjs.actor.call(void 0, {
|
|
363
362
|
state: {
|
|
364
363
|
runStarted: false,
|
|
365
364
|
destroyCalled: false
|
|
@@ -383,7 +382,7 @@ var runWithEarlyExit = _chunk65RINRXEcjs.actor.call(void 0, {
|
|
|
383
382
|
sleepTimeout: RUN_SLEEP_TIMEOUT
|
|
384
383
|
}
|
|
385
384
|
});
|
|
386
|
-
var runWithError =
|
|
385
|
+
var runWithError = _chunk772NPMTYcjs.actor.call(void 0, {
|
|
387
386
|
state: {
|
|
388
387
|
runStarted: false,
|
|
389
388
|
destroyCalled: false
|
|
@@ -407,7 +406,7 @@ var runWithError = _chunk65RINRXEcjs.actor.call(void 0, {
|
|
|
407
406
|
sleepTimeout: RUN_SLEEP_TIMEOUT
|
|
408
407
|
}
|
|
409
408
|
});
|
|
410
|
-
var runWithoutHandler =
|
|
409
|
+
var runWithoutHandler = _chunk772NPMTYcjs.actor.call(void 0, {
|
|
411
410
|
state: {
|
|
412
411
|
wakeCount: 0
|
|
413
412
|
},
|
|
@@ -427,13 +426,13 @@ var runWithoutHandler = _chunk65RINRXEcjs.actor.call(void 0, {
|
|
|
427
426
|
// fixtures/driver-test-suite/workflow.ts
|
|
428
427
|
var _workflowengine = require('@rivetkit/workflow-engine');
|
|
429
428
|
var WORKFLOW_QUEUE_NAME = "workflow-default";
|
|
430
|
-
var workflowCounterActor =
|
|
429
|
+
var workflowCounterActor = _chunk772NPMTYcjs.actor.call(void 0, {
|
|
431
430
|
state: {
|
|
432
431
|
runCount: 0,
|
|
433
432
|
guardTriggered: false,
|
|
434
433
|
history: []
|
|
435
434
|
},
|
|
436
|
-
run:
|
|
435
|
+
run: _chunkNXEHFUDBcjs.workflow.call(void 0, async (ctx) => {
|
|
437
436
|
await ctx.loop("counter", async (loopCtx) => {
|
|
438
437
|
try {
|
|
439
438
|
loopCtx.state;
|
|
@@ -448,7 +447,7 @@ var workflowCounterActor = _chunk65RINRXEcjs.actor.call(void 0, {
|
|
|
448
447
|
}),
|
|
449
448
|
actions: {
|
|
450
449
|
getState: async (c) => {
|
|
451
|
-
const guardFlag = await c.kv.get(
|
|
450
|
+
const guardFlag = await c.kv.get(_chunkNXEHFUDBcjs.WORKFLOW_GUARD_KV_KEY);
|
|
452
451
|
if (guardFlag === "true") {
|
|
453
452
|
c.state.guardTriggered = true;
|
|
454
453
|
}
|
|
@@ -459,14 +458,14 @@ var workflowCounterActor = _chunk65RINRXEcjs.actor.call(void 0, {
|
|
|
459
458
|
sleepTimeout: 50
|
|
460
459
|
}
|
|
461
460
|
});
|
|
462
|
-
var workflowQueueActor =
|
|
461
|
+
var workflowQueueActor = _chunk772NPMTYcjs.actor.call(void 0, {
|
|
463
462
|
state: {
|
|
464
463
|
received: []
|
|
465
464
|
},
|
|
466
465
|
queues: {
|
|
467
|
-
[WORKFLOW_QUEUE_NAME]:
|
|
466
|
+
[WORKFLOW_QUEUE_NAME]: _chunk772NPMTYcjs.queue.call(void 0, )
|
|
468
467
|
},
|
|
469
|
-
run:
|
|
468
|
+
run: _chunkNXEHFUDBcjs.workflow.call(void 0, async (ctx) => {
|
|
470
469
|
await ctx.loop("queue", async (loopCtx) => {
|
|
471
470
|
const message = await loopCtx.queue.next("queue-wait", {
|
|
472
471
|
names: [WORKFLOW_QUEUE_NAME],
|
|
@@ -495,7 +494,7 @@ var workflowQueueActor = _chunk65RINRXEcjs.actor.call(void 0, {
|
|
|
495
494
|
}
|
|
496
495
|
}
|
|
497
496
|
});
|
|
498
|
-
var workflowAccessActor =
|
|
497
|
+
var workflowAccessActor = _chunk772NPMTYcjs.actor.call(void 0, {
|
|
499
498
|
db: _chunk6LJAZ5R4cjs.db.call(void 0, {
|
|
500
499
|
onMigrate: async (rawDb) => {
|
|
501
500
|
await rawDb.execute(`
|
|
@@ -512,7 +511,7 @@ var workflowAccessActor = _chunk65RINRXEcjs.actor.call(void 0, {
|
|
|
512
511
|
insideDbCount: 0,
|
|
513
512
|
insideClientAvailable: false
|
|
514
513
|
},
|
|
515
|
-
run:
|
|
514
|
+
run: _chunkNXEHFUDBcjs.workflow.call(void 0, async (ctx) => {
|
|
516
515
|
await ctx.loop("access", async (loopCtx) => {
|
|
517
516
|
let outsideDbError = null;
|
|
518
517
|
let outsideClientError = null;
|
|
@@ -541,11 +540,11 @@ var workflowAccessActor = _chunk65RINRXEcjs.actor.call(void 0, {
|
|
|
541
540
|
getState: (c) => c.state
|
|
542
541
|
}
|
|
543
542
|
});
|
|
544
|
-
var workflowSleepActor =
|
|
543
|
+
var workflowSleepActor = _chunk772NPMTYcjs.actor.call(void 0, {
|
|
545
544
|
state: {
|
|
546
545
|
ticks: 0
|
|
547
546
|
},
|
|
548
|
-
run:
|
|
547
|
+
run: _chunkNXEHFUDBcjs.workflow.call(void 0, async (ctx) => {
|
|
549
548
|
await ctx.loop("sleep", async (loopCtx) => {
|
|
550
549
|
await loopCtx.step("tick", async () => {
|
|
551
550
|
incrementWorkflowSleepTick(loopCtx);
|
|
@@ -561,13 +560,13 @@ var workflowSleepActor = _chunk65RINRXEcjs.actor.call(void 0, {
|
|
|
561
560
|
sleepTimeout: 50
|
|
562
561
|
}
|
|
563
562
|
});
|
|
564
|
-
var workflowStopTeardownActor =
|
|
563
|
+
var workflowStopTeardownActor = _chunk772NPMTYcjs.actor.call(void 0, {
|
|
565
564
|
state: {
|
|
566
565
|
wakeAts: [],
|
|
567
566
|
sleepAts: []
|
|
568
567
|
},
|
|
569
568
|
queues: {
|
|
570
|
-
never:
|
|
569
|
+
never: _chunk772NPMTYcjs.queue.call(void 0, )
|
|
571
570
|
},
|
|
572
571
|
onWake: (c) => {
|
|
573
572
|
c.state.wakeAts.push(Date.now());
|
|
@@ -575,7 +574,7 @@ var workflowStopTeardownActor = _chunk65RINRXEcjs.actor.call(void 0, {
|
|
|
575
574
|
onSleep: (c) => {
|
|
576
575
|
c.state.sleepAts.push(Date.now());
|
|
577
576
|
},
|
|
578
|
-
run:
|
|
577
|
+
run: _chunkNXEHFUDBcjs.workflow.call(void 0, async (ctx) => {
|
|
579
578
|
await ctx.loop("wait-forever", async (loopCtx) => {
|
|
580
579
|
await loopCtx.queue.next("wait-for-never", {
|
|
581
580
|
names: ["never"]
|
|
@@ -643,4 +642,4 @@ function incrementWorkflowSleepTick(ctx) {
|
|
|
643
642
|
|
|
644
643
|
|
|
645
644
|
exports.logger = logger; exports.HIBERNATION_SLEEP_TIMEOUT = HIBERNATION_SLEEP_TIMEOUT; exports.hibernationActor = hibernationActor; exports.SLEEP_TIMEOUT = SLEEP_TIMEOUT; exports.sleep = sleep; exports.sleepWithLongRpc = sleepWithLongRpc; exports.sleepWithRawHttp = sleepWithRawHttp; exports.sleepWithRawWebSocket = sleepWithRawWebSocket; exports.sleepWithNoSleepOption = sleepWithNoSleepOption; exports.RUN_SLEEP_TIMEOUT = RUN_SLEEP_TIMEOUT; exports.runWithTicks = runWithTicks; exports.runWithQueueConsumer = runWithQueueConsumer; exports.runWithEarlyExit = runWithEarlyExit; exports.runWithError = runWithError; exports.runWithoutHandler = runWithoutHandler; exports.WORKFLOW_QUEUE_NAME = WORKFLOW_QUEUE_NAME; exports.workflowCounterActor = workflowCounterActor; exports.workflowQueueActor = workflowQueueActor; exports.workflowAccessActor = workflowAccessActor; exports.workflowSleepActor = workflowSleepActor; exports.workflowStopTeardownActor = workflowStopTeardownActor;
|
|
646
|
-
//# sourceMappingURL=chunk-
|
|
645
|
+
//# sourceMappingURL=chunk-UZV7NXC6.cjs.map
|