rivetkit 2.0.18 → 2.0.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/dist/tsup/{chunk-O7NI7QQW.cjs → chunk-2I6L3VRO.cjs} +14 -14
  2. package/dist/tsup/{chunk-O7NI7QQW.cjs.map → chunk-2I6L3VRO.cjs.map} +1 -1
  3. package/dist/tsup/{chunk-BGBEE6N2.cjs → chunk-2S7HJMMY.cjs} +240 -193
  4. package/dist/tsup/chunk-2S7HJMMY.cjs.map +1 -0
  5. package/dist/tsup/{chunk-JMSXK5ZO.js → chunk-5F6X4AFU.js} +6 -6
  6. package/dist/tsup/{chunk-2MUSMEMN.js → chunk-7ACKZS3T.js} +6 -5
  7. package/dist/tsup/chunk-7ACKZS3T.js.map +1 -0
  8. package/dist/tsup/{chunk-OPB45MKH.cjs → chunk-DUOTOMP7.cjs} +3 -3
  9. package/dist/tsup/{chunk-OPB45MKH.cjs.map → chunk-DUOTOMP7.cjs.map} +1 -1
  10. package/dist/tsup/{chunk-6JGEHV56.js → chunk-ER5OT3SQ.js} +2 -2
  11. package/dist/tsup/{chunk-4R5LOYEU.cjs → chunk-FYP3TZXD.cjs} +28 -27
  12. package/dist/tsup/chunk-FYP3TZXD.cjs.map +1 -0
  13. package/dist/tsup/{chunk-RFCYH6EC.cjs → chunk-G6JGHCG4.cjs} +6 -6
  14. package/dist/tsup/{chunk-RFCYH6EC.cjs.map → chunk-G6JGHCG4.cjs.map} +1 -1
  15. package/dist/tsup/{chunk-DZEQUURK.js → chunk-GQ5WTE64.js} +18 -10
  16. package/dist/tsup/chunk-GQ5WTE64.js.map +1 -0
  17. package/dist/tsup/{chunk-IXPZJCBE.cjs → chunk-JZD6FEOE.cjs} +219 -211
  18. package/dist/tsup/chunk-JZD6FEOE.cjs.map +1 -0
  19. package/dist/tsup/{chunk-F5VXILGA.cjs → chunk-KKRR7DSG.cjs} +8 -4
  20. package/dist/tsup/chunk-KKRR7DSG.cjs.map +1 -0
  21. package/dist/tsup/{chunk-FADDMRZP.cjs → chunk-KUZWEM23.cjs} +2 -2
  22. package/dist/tsup/{chunk-FADDMRZP.cjs.map → chunk-KUZWEM23.cjs.map} +1 -1
  23. package/dist/tsup/{chunk-S5K7CB2F.js → chunk-L3YPHXPE.js} +76 -29
  24. package/dist/tsup/{chunk-S5K7CB2F.js.map → chunk-L3YPHXPE.js.map} +1 -1
  25. package/dist/tsup/{chunk-IXPWBGXK.js → chunk-M6LIJ6BK.js} +3 -3
  26. package/dist/tsup/{chunk-2P4ENWQ6.js → chunk-MGHPBNWB.js} +7 -3
  27. package/dist/tsup/chunk-MGHPBNWB.js.map +1 -0
  28. package/dist/tsup/{chunk-SBBFWYNM.cjs → chunk-PV22ZBDE.cjs} +8 -8
  29. package/dist/tsup/{chunk-SBBFWYNM.cjs.map → chunk-PV22ZBDE.cjs.map} +1 -1
  30. package/dist/tsup/{chunk-42UD33X4.js → chunk-QMVCFQ37.js} +2 -2
  31. package/dist/tsup/{chunk-42UD33X4.js.map → chunk-QMVCFQ37.js.map} +1 -1
  32. package/dist/tsup/{chunk-YVK2XQNR.js → chunk-QRUGCDA5.js} +2 -2
  33. package/dist/tsup/{chunk-KPFRD7KN.js → chunk-RI4YHZZW.js} +2 -2
  34. package/dist/tsup/{chunk-QMF6X2E2.cjs → chunk-RJVSNJO7.cjs} +7 -7
  35. package/dist/tsup/{chunk-QMF6X2E2.cjs.map → chunk-RJVSNJO7.cjs.map} +1 -1
  36. package/dist/tsup/{chunk-AR5ZY563.js → chunk-YFFCPYHY.js} +3 -3
  37. package/dist/tsup/{chunk-ICPFPGOJ.cjs → chunk-ZODINJWN.cjs} +12 -12
  38. package/dist/tsup/{chunk-ICPFPGOJ.cjs.map → chunk-ZODINJWN.cjs.map} +1 -1
  39. package/dist/tsup/client/mod.cjs +9 -9
  40. package/dist/tsup/client/mod.d.cts +2 -2
  41. package/dist/tsup/client/mod.d.ts +2 -2
  42. package/dist/tsup/client/mod.js +8 -8
  43. package/dist/tsup/common/log.cjs +3 -3
  44. package/dist/tsup/common/log.js +2 -2
  45. package/dist/tsup/common/websocket.cjs +4 -4
  46. package/dist/tsup/common/websocket.js +3 -3
  47. package/dist/tsup/{conn-DhdZYlSX.d.ts → conn-CmPcqOCF.d.ts} +72 -67
  48. package/dist/tsup/{conn-CxCsTz2s.d.cts → conn-DU5EbfCu.d.cts} +72 -67
  49. package/dist/tsup/driver-helpers/mod.cjs +5 -5
  50. package/dist/tsup/driver-helpers/mod.d.cts +1 -1
  51. package/dist/tsup/driver-helpers/mod.d.ts +1 -1
  52. package/dist/tsup/driver-helpers/mod.js +4 -4
  53. package/dist/tsup/driver-test-suite/mod.cjs +71 -71
  54. package/dist/tsup/driver-test-suite/mod.d.cts +1 -1
  55. package/dist/tsup/driver-test-suite/mod.d.ts +1 -1
  56. package/dist/tsup/driver-test-suite/mod.js +11 -11
  57. package/dist/tsup/inspector/mod.cjs +6 -6
  58. package/dist/tsup/inspector/mod.d.cts +2 -2
  59. package/dist/tsup/inspector/mod.d.ts +2 -2
  60. package/dist/tsup/inspector/mod.js +5 -5
  61. package/dist/tsup/mod.cjs +10 -10
  62. package/dist/tsup/mod.d.cts +2 -2
  63. package/dist/tsup/mod.d.ts +2 -2
  64. package/dist/tsup/mod.js +9 -9
  65. package/dist/tsup/test/mod.cjs +11 -11
  66. package/dist/tsup/test/mod.d.cts +1 -1
  67. package/dist/tsup/test/mod.d.ts +1 -1
  68. package/dist/tsup/test/mod.js +10 -10
  69. package/dist/tsup/utils.cjs +2 -2
  70. package/dist/tsup/utils.js +1 -1
  71. package/package.json +1 -1
  72. package/src/common/eventsource.ts +7 -43
  73. package/src/common/websocket.ts +2 -1
  74. package/src/engine-process/mod.ts +66 -15
  75. package/src/registry/mod.ts +26 -2
  76. package/src/registry/run-config.ts +1 -0
  77. package/src/remote-manager-driver/mod.ts +12 -3
  78. package/dist/tsup/chunk-2MUSMEMN.js.map +0 -1
  79. package/dist/tsup/chunk-2P4ENWQ6.js.map +0 -1
  80. package/dist/tsup/chunk-4R5LOYEU.cjs.map +0 -1
  81. package/dist/tsup/chunk-BGBEE6N2.cjs.map +0 -1
  82. package/dist/tsup/chunk-DZEQUURK.js.map +0 -1
  83. package/dist/tsup/chunk-F5VXILGA.cjs.map +0 -1
  84. package/dist/tsup/chunk-IXPZJCBE.cjs.map +0 -1
  85. /package/dist/tsup/{chunk-JMSXK5ZO.js.map → chunk-5F6X4AFU.js.map} +0 -0
  86. /package/dist/tsup/{chunk-6JGEHV56.js.map → chunk-ER5OT3SQ.js.map} +0 -0
  87. /package/dist/tsup/{chunk-IXPWBGXK.js.map → chunk-M6LIJ6BK.js.map} +0 -0
  88. /package/dist/tsup/{chunk-YVK2XQNR.js.map → chunk-QRUGCDA5.js.map} +0 -0
  89. /package/dist/tsup/{chunk-KPFRD7KN.js.map → chunk-RI4YHZZW.js.map} +0 -0
  90. /package/dist/tsup/{chunk-AR5ZY563.js.map → chunk-YFFCPYHY.js.map} +0 -0
@@ -1,10 +1,10 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } }
2
2
 
3
- var _chunkQMF6X2E2cjs = require('./chunk-QMF6X2E2.cjs');
3
+ var _chunkRJVSNJO7cjs = require('./chunk-RJVSNJO7.cjs');
4
4
 
5
5
  // src/client/log.ts
6
6
  function logger() {
7
- return _chunkQMF6X2E2cjs.getLogger.call(void 0, "actor-client");
7
+ return _chunkRJVSNJO7cjs.getLogger.call(void 0, "actor-client");
8
8
  }
9
9
 
10
10
  // src/common/websocket.ts
@@ -19,7 +19,11 @@ async function importWebSocket() {
19
19
  _WebSocket = WebSocket;
20
20
  } else {
21
21
  try {
22
- const ws = await Promise.resolve().then(() => _interopRequireWildcard(require("ws")));
22
+ const moduleName = "ws";
23
+ const ws = await Promise.resolve().then(() => _interopRequireWildcard(require(
24
+ /* webpackIgnore: true */
25
+ moduleName
26
+ )));
23
27
  _WebSocket = ws.default;
24
28
  logger().debug("using websocket from npm");
25
29
  } catch (e) {
@@ -42,4 +46,4 @@ async function importWebSocket() {
42
46
 
43
47
 
44
48
  exports.logger = logger; exports.importWebSocket = importWebSocket;
45
- //# sourceMappingURL=chunk-F5VXILGA.cjs.map
49
+ //# sourceMappingURL=chunk-KKRR7DSG.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/nathan/rivetkit/packages/rivetkit/dist/tsup/chunk-KKRR7DSG.cjs","../../src/client/log.ts","../../src/common/websocket.ts"],"names":[],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACA;ACFO,SAAS,MAAA,CAAA,EAAS;AACxB,EAAA,OAAO,yCAAA,cAAwB,CAAA;AAChC;ADIA;AACA;AENA,IAAI,iBAAA,EAAqD,IAAA;AAEzD,MAAA,SAAsB,eAAA,CAAA,EAA6C;AAElE,EAAA,GAAA,CAAI,iBAAA,IAAqB,IAAA,EAAM;AAC9B,IAAA,OAAO,gBAAA;AAAA,EACR;AAGA,EAAA,iBAAA,EAAA,CAAoB,MAAA,CAAA,EAAA,GAAY;AAC/B,IAAA,IAAI,UAAA;AAEJ,IAAA,GAAA,CAAI,OAAO,UAAA,IAAc,WAAA,EAAa;AAErC,MAAA,WAAA,EAAa,SAAA;AAAA,IACd,EAAA,KAAO;AAEN,MAAA,IAAI;AACH,QAAA,MAAM,WAAA,EAAa,IAAA;AACnB,QAAA,MAAM,GAAA,EAAK,MAAM,4DAAA;AAAA;AAAA,UAAiC;AAAA,QAAA,GAAA;AAClD,QAAA,WAAA,EAAa,EAAA,CAAG,OAAA;AAChB,QAAA,MAAA,CAAO,CAAA,CAAE,KAAA,CAAM,0BAA0B,CAAA;AAAA,MAC1C,EAAA,UAAQ;AAEP,QAAA,WAAA,EAAa,MAAM,cAAc;AAAA,UAChC,WAAA,CAAA,EAAc;AACb,YAAA,MAAM,IAAI,KAAA;AAAA,cACT;AAAA,YACD,CAAA;AAAA,UACD;AAAA,QACD,CAAA;AACA,QAAA,MAAA,CAAO,CAAA,CAAE,KAAA,CAAM,sBAAsB,CAAA;AAAA,MACtC;AAAA,IACD;AAEA,IAAA,OAAO,UAAA;AAAA,EACR,CAAA,CAAA,CAAG,CAAA;AAEH,EAAA,OAAO,gBAAA;AACR;AFCA;AACA;AACE;AACA;AACF,mEAAC","file":"/Users/nathan/rivetkit/packages/rivetkit/dist/tsup/chunk-KKRR7DSG.cjs","sourcesContent":[null,"import { getLogger } from \"@/common/log\";\n\nexport function logger() {\n\treturn getLogger(\"actor-client\");\n}\n","import { logger } from \"@/client/log\";\n\n// Global singleton promise that will be reused for subsequent calls\nlet webSocketPromise: Promise<typeof WebSocket> | null = null;\n\nexport async function importWebSocket(): Promise<typeof WebSocket> {\n\t// Return existing promise if we already started loading\n\tif (webSocketPromise !== null) {\n\t\treturn webSocketPromise;\n\t}\n\n\t// Create and store the promise\n\twebSocketPromise = (async () => {\n\t\tlet _WebSocket: typeof WebSocket;\n\n\t\tif (typeof WebSocket !== \"undefined\") {\n\t\t\t// Browser environment\n\t\t\t_WebSocket = WebSocket as unknown as typeof WebSocket;\n\t\t} else {\n\t\t\t// Node.js environment\n\t\t\ttry {\n\t\t\t\tconst moduleName = \"ws\";\n\t\t\t\tconst ws = await import(/* webpackIgnore: true */ moduleName);\n\t\t\t\t_WebSocket = ws.default as unknown as typeof WebSocket;\n\t\t\t\tlogger().debug(\"using websocket from npm\");\n\t\t\t} catch {\n\t\t\t\t// WS not available\n\t\t\t\t_WebSocket = class MockWebSocket {\n\t\t\t\t\tconstructor() {\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t'WebSocket support requires installing the \"ws\" peer dependency.',\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t} as unknown as typeof WebSocket;\n\t\t\t\tlogger().debug(\"using mock websocket\");\n\t\t\t}\n\t\t}\n\n\t\treturn _WebSocket;\n\t})();\n\n\treturn webSocketPromise;\n}\n"]}
@@ -208,7 +208,7 @@ function noopNext() {
208
208
  // package.json
209
209
  var package_default = {
210
210
  name: "rivetkit",
211
- version: "2.0.18",
211
+ version: "2.0.20",
212
212
  description: "Lightweight libraries for building stateful actors on edge platforms",
213
213
  license: "Apache-2.0",
214
214
  keywords: [
@@ -574,4 +574,4 @@ function combineUrlPath(endpoint, path, queryParams) {
574
574
 
575
575
 
576
576
  exports.assertUnreachable = assertUnreachable; exports.isCborSerializable = isCborSerializable; exports.deconstructError = deconstructError; exports.stringifyError = stringifyError; exports.noopNext = noopNext; exports.package_default = package_default; exports.VERSION = VERSION; 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;
577
- //# sourceMappingURL=chunk-FADDMRZP.cjs.map
577
+ //# sourceMappingURL=chunk-KUZWEM23.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/nathan/rivetkit/packages/rivetkit/dist/tsup/chunk-FADDMRZP.cjs","../../src/common/utils.ts","../../package.json","../../src/utils.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACF,wDAA6B;AAC7B;AACA;ACAO,SAAS,iBAAA,CAAkB,CAAA,EAAiB;AAClD,EAAA,MAAM,IAAI,KAAA,CAAM,CAAA,kBAAA,EAAqB,CAAC,CAAA,CAAA;AACvC;AAuCC;AAIgC,EAAA;AACxB,IAAA;AACR,EAAA;AAE+B,EAAA;AACD,IAAA;AAC5B,MAAA;AACO,MAAA;AACR,IAAA;AACO,IAAA;AACR,EAAA;AAEkC,EAAA;AAC1B,IAAA;AACR,EAAA;A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ACE,QAAA;AACb,MAAA;AACW,MAAA;AACA,QAAA;AACE,QAAA;AACb,MAAA;AACF,IAAA;AACS,IAAA;AACG,MAAA;AACC,QAAA;AACE,QAAA;AACb,MAAA;AACW,MAAA;AACA,QAAA;AACE,QAAA;AACb,MAAA;AACF,IAAA;AACY,IAAA;AACA,MAAA;AACC,QAAA;AACE,QAAA;AACb,MAAA;AACW,MAAA;AACA,QAAA;AACE,QAAA;AACb,MAAA;AACF,IAAA;AACW,IAAA;AACC,MAAA;AACC,QAAA;AACE,QAAA;AACb,MAAA;AACW,MAAA;AACA,QAAA;AACE,QAAA;AACb,MAAA;AACF,IAAA;AACoB,IAAA;AACR,MAAA;AACC,QAAA;AACE,QAAA;AACb,MAAA;AACW,MAAA;AACA,QAAA;AACE,QAAA;AACb,MAAA;AACF,IAAA;AAC8B,IAAA;AAClB,MAAA;AACC,QAAA;AACE,QAAA;AACb,MAAA;AACW,MAAA;AACA,QAAA;AACE,QAAA;AACb,MAAA;AACF,IAAA;AACuB,IAAA;AACX,MAAA;AACC,QAAA;AACE,QAAA;AACb,MAAA;AACW,MAAA;AACA,QAAA;AACE,QAAA;AACb,MAAA;AACF,IAAA;AAC2B,IAAA;AACf,MAAA;AACC,QAAA;AACE,QAAA;AACb,MAAA;AACW,MAAA;AACA,QAAA;AACE,QAAA;AACb,MAAA;AACF,IAAA;AAC0B,IAAA;AACd,MAAA;AACC,QAAA;AACE,QAAA;AACb,MAAA;AACW,MAAA;AACA,QAAA;AACE,QAAA;AACb,MAAA;AACF,IAAA;AACU,IAAA;AACE,MAAA;AACC,QAAA;AACE,QAAA;AACb,MAAA;AACW,MAAA;AACA,QAAA;AACE,QAAA;AACb,MAAA;AACF,IAAA;AACe,IAAA;AACH,MAAA;AACC,QAAA;AACE,QAAA;AACb,MAAA;AACW,MAAA;AACA,QAAA;AACE,QAAA;AACb,MAAA;AACF,IAAA;AACF,EAAA;AACW,EAAA;AACD,IAAA;AACV,EAAA;AACe,EAAA;AACb,IAAA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,MAAA;AACzB,IAAA;AACqB,MAAA;AACG,QAAA;AAChB,MAAA;AACf,IAAA;AACD,EAAA;AAEW,EAAA;AAEJ,EAAA;AACO,IAAA;AACe,MAAA;AAC5B,IAAA;AACD,EAAA;AACD;AAOgC;AAAA;AAE/B,EAAA;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;AACF,QAAA;AAER,QAAA;AAGA,QAAA;AACD,MAAA;AACC,IAAA;AACuB,MAAA;AACzB,IAAA;AACD,EAAA;AACD;AAE2E;AACxD,EAAA;AACb,IAAA;AACiB,IAAA;AACtB,EAAA;AACD;AAqBC;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;AHwTyC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/Users/nathan/rivetkit/packages/rivetkit/dist/tsup/chunk-FADDMRZP.cjs","sourcesContent":[null,"import type { Next } from \"hono\";\nimport type { ContentfulStatusCode } from \"hono/utils/http-status\";\nimport * as errors from \"@/actor/errors\";\nimport { getEnvUniversal } from \"@/utils\";\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\" ? value.length : JSON.stringify(value).length;\n\t\tsize += key.length + valueSize;\n\n\t\tif (size > maxSize) {\n\t\t\tthrow new Error(`JSON object exceeds size limit of ${maxSize} bytes.`);\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\tissues: \"https://github.com/rivet-dev/rivetkit/issues\",\n\t\t\tsupport: \"https://rivet.dev/discord\",\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\tissues: \"https://github.com/rivet-dev/rivetkit/issues\",\n\t\t\t\tsupport: \"https://rivet.dev/discord\",\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 = \"internal\";\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\tissues: \"https://github.com/rivet-dev/rivetkit/issues\",\n\t\t\t\tsupport: \"https://rivet.dev/discord\",\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 = \"internal\";\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\tissues: \"https://github.com/rivet-dev/rivetkit/issues\",\n\t\t\tsupport: \"https://rivet.dev/discord\",\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\tgetEnvUniversal(\"_RIVETKIT_ERROR_STACK\") === \"1\"\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 \"name\": \"rivetkit\",\n \"version\": \"2.0.18\",\n \"description\": \"Lightweight libraries for building stateful actors on edge platforms\",\n \"license\": \"Apache-2.0\",\n \"keywords\": [\n \"rivetkit\",\n \"stateful\",\n \"serverless\",\n \"actors\",\n \"agents\",\n \"realtime\",\n \"websocket\",\n \"actors\",\n \"framework\"\n ],\n \"files\": [\n \"dist\",\n \"src\",\n \"deno.json\",\n \"bun.json\",\n \"package.json\"\n ],\n \"type\": \"module\",\n \"exports\": {\n \".\": {\n \"import\": {\n \"types\": \"./dist/tsup/mod.d.ts\",\n \"default\": \"./dist/tsup/mod.js\"\n },\n \"require\": {\n \"types\": \"./dist/tsup/mod.d.cts\",\n \"default\": \"./dist/tsup/mod.cjs\"\n }\n },\n \"./client\": {\n \"import\": {\n \"types\": \"./dist/tsup/client/mod.d.ts\",\n \"default\": \"./dist/tsup/client/mod.js\"\n },\n \"require\": {\n \"types\": \"./dist/tsup/client/mod.d.cts\",\n \"default\": \"./dist/tsup/client/mod.cjs\"\n }\n },\n \"./log\": {\n \"import\": {\n \"types\": \"./dist/tsup/common/log.d.ts\",\n \"default\": \"./dist/tsup/common/log.js\"\n },\n \"require\": {\n \"types\": \"./dist/tsup/common/log.d.cts\",\n \"default\": \"./dist/tsup/common/log.cjs\"\n }\n },\n \"./errors\": {\n \"import\": {\n \"types\": \"./dist/tsup/actor/errors.d.ts\",\n \"default\": \"./dist/tsup/actor/errors.js\"\n },\n \"require\": {\n \"types\": \"./dist/tsup/actor/errors.d.cts\",\n \"default\": \"./dist/tsup/actor/errors.cjs\"\n }\n },\n \"./utils\": {\n \"import\": {\n \"types\": \"./dist/tsup/utils.d.ts\",\n \"default\": \"./dist/tsup/utils.js\"\n },\n \"require\": {\n \"types\": \"./dist/tsup/utils.d.cts\",\n \"default\": \"./dist/tsup/utils.cjs\"\n }\n },\n \"./driver-helpers\": {\n \"import\": {\n \"types\": \"./dist/tsup/driver-helpers/mod.d.ts\",\n \"default\": \"./dist/tsup/driver-helpers/mod.js\"\n },\n \"require\": {\n \"types\": \"./dist/tsup/driver-helpers/mod.d.cts\",\n \"default\": \"./dist/tsup/driver-helpers/mod.cjs\"\n }\n },\n \"./driver-helpers/websocket\": {\n \"import\": {\n \"types\": \"./dist/tsup/common/websocket.d.ts\",\n \"default\": \"./dist/tsup/common/websocket.js\"\n },\n \"require\": {\n \"types\": \"./dist/tsup/common/websocket.d.cts\",\n \"default\": \"./dist/tsup/common/websocket.cjs\"\n }\n },\n \"./driver-test-suite\": {\n \"import\": {\n \"types\": \"./dist/tsup/driver-test-suite/mod.d.ts\",\n \"default\": \"./dist/tsup/driver-test-suite/mod.js\"\n },\n \"require\": {\n \"types\": \"./dist/tsup/driver-test-suite/mod.d.cts\",\n \"default\": \"./dist/tsup/driver-test-suite/mod.cjs\"\n }\n },\n \"./topologies/coordinate\": {\n \"import\": {\n \"types\": \"./dist/tsup/topologies/coordinate/mod.d.ts\",\n \"default\": \"./dist/tsup/topologies/coordinate/mod.js\"\n },\n \"require\": {\n \"types\": \"./dist/tsup/topologies/coordinate/mod.d.cts\",\n \"default\": \"./dist/tsup/topologies/coordinate/mod.cjs\"\n }\n },\n \"./topologies/partition\": {\n \"import\": {\n \"types\": \"./dist/tsup/topologies/partition/mod.d.ts\",\n \"default\": \"./dist/tsup/topologies/partition/mod.js\"\n },\n \"require\": {\n \"types\": \"./dist/tsup/topologies/partition/mod.d.cts\",\n \"default\": \"./dist/tsup/topologies/partition/mod.cjs\"\n }\n },\n \"./test\": {\n \"import\": {\n \"types\": \"./dist/tsup/test/mod.d.ts\",\n \"default\": \"./dist/tsup/test/mod.js\"\n },\n \"require\": {\n \"types\": \"./dist/tsup/test/mod.d.cts\",\n \"default\": \"./dist/tsup/test/mod.cjs\"\n }\n },\n \"./inspector\": {\n \"import\": {\n \"types\": \"./dist/tsup/inspector/mod.d.ts\",\n \"default\": \"./dist/tsup/inspector/mod.js\"\n },\n \"require\": {\n \"types\": \"./dist/tsup/inspector/mod.d.cts\",\n \"default\": \"./dist/tsup/inspector/mod.cjs\"\n }\n }\n },\n \"engines\": {\n \"node\": \">=22.0.0\"\n },\n \"sideEffects\": [\n \"./dist/tsup/chunk-*.js\",\n \"./dist/tsup/chunk-*.cjs\"\n ],\n \"scripts\": {\n \"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/test/mod.ts src/inspector/mod.ts\",\n \"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/file-system-driver/v1.bare -o dist/schemas/file-system-driver/v1.ts && ./scripts/compile-bare.ts compile schemas/actor-persist/v1.bare -o dist/schemas/actor-persist/v1.ts\",\n \"check-types\": \"tsc --noEmit\",\n \"test\": \"vitest run\",\n \"test:watch\": \"vitest\",\n \"dump-openapi\": \"tsx scripts/dump-openapi.ts\"\n },\n \"dependencies\": {\n \"@bare-ts/lib\": \"~0.3.0\",\n \"@hono/standard-validator\": \"^0.1.3\",\n \"@hono/zod-openapi\": \"^0.19.10\",\n \"@rivetkit/engine-runner\": \"https://pkg.pr.new/rivet-dev/engine/@rivetkit/engine-runner@6659217\",\n \"@rivetkit/fast-json-patch\": \"^3.1.2\",\n \"cbor-x\": \"^1.6.0\",\n \"hono\": \"^4.7.0\",\n \"invariant\": \"^2.2.4\",\n \"nanoevents\": \"^9.1.0\",\n \"on-change\": \"^5.0.1\",\n \"p-retry\": \"^6.2.1\",\n \"pino\": \"^9.5.0\",\n \"zod\": \"^3.25.76\"\n },\n \"devDependencies\": {\n \"@bare-ts/tools\": \"^0.13.0\",\n \"@hono/node-server\": \"^1.18.2\",\n \"@hono/node-ws\": \"^1.1.1\",\n \"@types/invariant\": \"^2\",\n \"@types/node\": \"^22.13.1\",\n \"@types/ws\": \"^8\",\n \"@vitest/ui\": \"3.1.1\",\n \"bundle-require\": \"^5.1.0\",\n \"eventsource\": \"^4.0.0\",\n \"tsup\": \"^8.4.0\",\n \"tsx\": \"^4.19.4\",\n \"typescript\": \"^5.7.3\",\n \"vitest\": \"^3.1.1\",\n \"ws\": \"^8.18.1\"\n },\n \"peerDependencies\": {\n \"@hono/node-server\": \"^1.14.0\",\n \"@hono/node-ws\": \"^1.1.1\",\n \"eventsource\": \"^4.0.0\",\n \"ws\": \"^8.0.0\"\n },\n \"peerDependenciesMeta\": {\n \"@hono/node-server\": {\n \"optional\": true\n },\n \"@hono/node-ws\": {\n \"optional\": true\n },\n \"eventsource\": {\n \"optional\": true\n },\n \"ws\": {\n \"optional\": true\n }\n },\n \"stableVersion\": \"0.8.0\"\n}\n","export { stringifyError } from \"@/common/utils\";\nexport { assertUnreachable } from \"./common/utils\";\n\nimport type { Context as HonoContext, Handler as HonoHandler } from \"hono\";\n\nimport pkgJson from \"../package.json\" with { type: \"json\" };\n\nexport const VERSION = pkgJson.version;\n\nlet _userAgent: string | undefined;\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 = typeof 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\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\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 */\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(data.byteOffset, data.byteOffset + data.byteLength),\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 */\nexport function promiseWithResolvers<T>(): {\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\treturn { promise, resolve, reject };\n}\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>();\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} catch {\n\t\t\t\t\t// Swallow errors: callers only await cycle completion, not success\n\t\t\t\t}\n\n\t\t\t\t// Notify all waiters for this cycle\n\t\t\t\tresolver?.resolve();\n\t\t\t}\n\t\t} finally {\n\t\t\tthis.runningDrainLoop = undefined;\n\t\t}\n\t}\n}\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 */\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"]}
1
+ {"version":3,"sources":["/Users/nathan/rivetkit/packages/rivetkit/dist/tsup/chunk-KUZWEM23.cjs","../../src/common/utils.ts","../../package.json","../../src/utils.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACF,wDAA6B;AAC7B;AACA;ACAO,SAAS,iBAAA,CAAkB,CAAA,EAAiB;AAClD,EAAA,MAAM,IAAI,KAAA,CAAM,CAAA,kBAAA,EAAqB,CAAC,CAAA,CAAA;AACvC;AAuCC;AAIgC,EAAA;AACxB,IAAA;AACR,EAAA;AAE+B,EAAA;AACD,IAAA;AAC5B,MAAA;AACO,MAAA;AACR,IAAA;AACO,IAAA;AACR,EAAA;AAEkC,EAAA;AAC1B,IAAA;AACR,EAAA;AAG+B,EAAA;AACvB,IAAA;AACR,EAAA;AAG2B,EAAA;AACnB,IAAA;AACR,EAAA;AAKC,EAAA;AAWO,IAAA;AACR,EAAA;AAG0B,EAAA;AACM,IAAA;AAExB,MAAA;AAGA,MAAA;AAGoB,MAAA;AAGlB,QAAA;AACR,MAAA;AACD,IAAA;AACO,IAAA;AACR,EAAA;AAG0B,EAAA;AACb,IAAA;AACuB,IAAA;AAE5B,MAAA;AAEwB,MAAA;AACtB,QAAA;AACR,MAAA;AACA,MAAA;AACD,IAAA;AACO,IAAA;AACR,EAAA;AAG6B,EAAA;AACrB,IAAA;AACR,EAAA;AAG4B,EAAA;AACpB,IAAA;AACR,EAAA;AAG0B,EAAA;AACS,IAAA;AACC,MAAA;AACA,MAAA;AAC1B,QAAA;AACR,MAAA;AACD,IAAA;AACO,IAAA;AACR,EAAA;AAG+B,EAAA;AAEM,IAAA;AACJ,IAAA;AAEA,MAAA;AACA,MAAA;AAI/B,MAAA;AACD,IAAA;AAGyB,IAAA;AACU,MAAA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;AACA,MAAA;AACR,IAAA;AACM,EAAA;AACmB,IAAA;AAC1B,EAAA;AACD;AAE+C;AAI7C,EAAA;AAGW,IAAA;AACL,EAAA;AACW,IAAA;AAClB,EAAA;AACD;AAGiC;AACb,EAAA;AAAC,EAAA;AACrB;ADjIyC;AACA;AE/MzC;AACU,EAAA;AACG,EAAA;AACI,EAAA;AACJ,EAAA;AACC,EAAA;AACV,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACF,EAAA;AACS,EAAA;AACP,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACF,EAAA;AACQ,EAAA;AACG,EAAA;AACJ,IAAA;AACO,MAAA;AACC,QAAA;AACE,QAAA;AACb,MAAA;AACW,MAAA;AACA,QAAA;AACE,QAAA;AACb,MAAA;AACF,IAAA;AACY,IAAA;AACA,MAAA;AACC,QAAA;AACE,QAAA;AACb,MAAA;AACW,MAAA;AACA,QAAA;AACE,QAAA;AACb,MAAA;AACF,IAAA;AACS,IAAA;AACG,MAAA;AACC,QAAA;AACE,QAAA;AACb,MAAA;AACW,MAAA;AACA,QAAA;AACE,QAAA;AACb,MAAA;AACF,IAAA;AACY,IAAA;AACA,MAAA;AACC,QAAA;AACE,QAAA;AACb,MAAA;AACW,MAAA;AACA,QAAA;AACE,QAAA;AACb,MAAA;AACF,IAAA;AACW,IAAA;AACC,MAAA;AACC,QAAA;AACE,QAAA;AACb,MAAA;AACW,MAAA;AACA,QAAA;AACE,QAAA;AACb,MAAA;AACF,IAAA;AACoB,IAAA;AACR,MAAA;AACC,QAAA;AACE,QAAA;AACb,MAAA;AACW,MAAA;AACA,QAAA;AACE,QAAA;AACb,MAAA;AACF,IAAA;AAC8B,IAAA;AAClB,MAAA;AACC,QAAA;AACE,QAAA;AACb,MAAA;AACW,MAAA;AACA,QAAA;AACE,QAAA;AACb,MAAA;AACF,IAAA;AACuB,IAAA;AACX,MAAA;AACC,QAAA;AACE,QAAA;AACb,MAAA;AACW,MAAA;AACA,QAAA;AACE,QAAA;AACb,MAAA;AACF,IAAA;AAC2B,IAAA;AACf,MAAA;AACC,QAAA;AACE,QAAA;AACb,MAAA;AACW,MAAA;AACA,QAAA;AACE,QAAA;AACb,MAAA;AACF,IAAA;AAC0B,IAAA;AACd,MAAA;AACC,QAAA;AACE,QAAA;AACb,MAAA;AACW,MAAA;AACA,QAAA;AACE,QAAA;AACb,MAAA;AACF,IAAA;AACU,IAAA;AACE,MAAA;AACC,QAAA;AACE,QAAA;AACb,MAAA;AACW,MAAA;AACA,QAAA;AACE,QAAA;AACb,MAAA;AACF,IAAA;AACe,IAAA;AACH,MAAA;AACC,QAAA;AACE,QAAA;AACb,MAAA;AACW,MAAA;AACA,QAAA;AACE,QAAA;AACb,MAAA;AACF,IAAA;AACF,EAAA;AACW,EAAA;AACD,IAAA;AACV,EAAA;AACe,EAAA;AACb,IAAA;AACA,IAAA;AACF,EAAA;AACW,EAAA;AACA,IAAA;AACO,IAAA;AACD,IAAA;AACP,IAAA;AACM,IAAA;AACE,IAAA;AAClB,EAAA;AACgB,EAAA;AACE,IAAA;AACY,IAAA;AACP,IAAA;AACM,IAAA;AACE,IAAA;AACnB,IAAA;AACF,IAAA;AACK,IAAA;AACC,IAAA;AACD,IAAA;AACF,IAAA;AACH,IAAA;AACD,IAAA;AACT,EAAA;AACmB,EAAA;AACC,IAAA;AACG,IAAA;AACJ,IAAA;AACG,IAAA;AACL,IAAA;AACF,IAAA;AACC,IAAA;AACI,IAAA;AACH,IAAA;AACP,IAAA;AACD,IAAA;AACO,IAAA;AACJ,IAAA;AACJ,IAAA;AACR,EAAA;AACoB,EAAA;AACG,IAAA;AACJ,IAAA;AACF,IAAA;AACT,IAAA;AACR,EAAA;AACwB,EAAA;AACD,IAAA;AACP,MAAA;AACd,IAAA;AACiB,IAAA;AACH,MAAA;AACd,IAAA;AACe,IAAA;AACD,MAAA;AACd,IAAA;AAC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,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;AHwTyC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/Users/nathan/rivetkit/packages/rivetkit/dist/tsup/chunk-KUZWEM23.cjs","sourcesContent":[null,"import type { Next } from \"hono\";\nimport type { ContentfulStatusCode } from \"hono/utils/http-status\";\nimport * as errors from \"@/actor/errors\";\nimport { getEnvUniversal } from \"@/utils\";\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\" ? value.length : JSON.stringify(value).length;\n\t\tsize += key.length + valueSize;\n\n\t\tif (size > maxSize) {\n\t\t\tthrow new Error(`JSON object exceeds size limit of ${maxSize} bytes.`);\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\tissues: \"https://github.com/rivet-dev/rivetkit/issues\",\n\t\t\tsupport: \"https://rivet.dev/discord\",\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\tissues: \"https://github.com/rivet-dev/rivetkit/issues\",\n\t\t\t\tsupport: \"https://rivet.dev/discord\",\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 = \"internal\";\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\tissues: \"https://github.com/rivet-dev/rivetkit/issues\",\n\t\t\t\tsupport: \"https://rivet.dev/discord\",\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 = \"internal\";\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\tissues: \"https://github.com/rivet-dev/rivetkit/issues\",\n\t\t\tsupport: \"https://rivet.dev/discord\",\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\tgetEnvUniversal(\"_RIVETKIT_ERROR_STACK\") === \"1\"\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 \"name\": \"rivetkit\",\n \"version\": \"2.0.20\",\n \"description\": \"Lightweight libraries for building stateful actors on edge platforms\",\n \"license\": \"Apache-2.0\",\n \"keywords\": [\n \"rivetkit\",\n \"stateful\",\n \"serverless\",\n \"actors\",\n \"agents\",\n \"realtime\",\n \"websocket\",\n \"actors\",\n \"framework\"\n ],\n \"files\": [\n \"dist\",\n \"src\",\n \"deno.json\",\n \"bun.json\",\n \"package.json\"\n ],\n \"type\": \"module\",\n \"exports\": {\n \".\": {\n \"import\": {\n \"types\": \"./dist/tsup/mod.d.ts\",\n \"default\": \"./dist/tsup/mod.js\"\n },\n \"require\": {\n \"types\": \"./dist/tsup/mod.d.cts\",\n \"default\": \"./dist/tsup/mod.cjs\"\n }\n },\n \"./client\": {\n \"import\": {\n \"types\": \"./dist/tsup/client/mod.d.ts\",\n \"default\": \"./dist/tsup/client/mod.js\"\n },\n \"require\": {\n \"types\": \"./dist/tsup/client/mod.d.cts\",\n \"default\": \"./dist/tsup/client/mod.cjs\"\n }\n },\n \"./log\": {\n \"import\": {\n \"types\": \"./dist/tsup/common/log.d.ts\",\n \"default\": \"./dist/tsup/common/log.js\"\n },\n \"require\": {\n \"types\": \"./dist/tsup/common/log.d.cts\",\n \"default\": \"./dist/tsup/common/log.cjs\"\n }\n },\n \"./errors\": {\n \"import\": {\n \"types\": \"./dist/tsup/actor/errors.d.ts\",\n \"default\": \"./dist/tsup/actor/errors.js\"\n },\n \"require\": {\n \"types\": \"./dist/tsup/actor/errors.d.cts\",\n \"default\": \"./dist/tsup/actor/errors.cjs\"\n }\n },\n \"./utils\": {\n \"import\": {\n \"types\": \"./dist/tsup/utils.d.ts\",\n \"default\": \"./dist/tsup/utils.js\"\n },\n \"require\": {\n \"types\": \"./dist/tsup/utils.d.cts\",\n \"default\": \"./dist/tsup/utils.cjs\"\n }\n },\n \"./driver-helpers\": {\n \"import\": {\n \"types\": \"./dist/tsup/driver-helpers/mod.d.ts\",\n \"default\": \"./dist/tsup/driver-helpers/mod.js\"\n },\n \"require\": {\n \"types\": \"./dist/tsup/driver-helpers/mod.d.cts\",\n \"default\": \"./dist/tsup/driver-helpers/mod.cjs\"\n }\n },\n \"./driver-helpers/websocket\": {\n \"import\": {\n \"types\": \"./dist/tsup/common/websocket.d.ts\",\n \"default\": \"./dist/tsup/common/websocket.js\"\n },\n \"require\": {\n \"types\": \"./dist/tsup/common/websocket.d.cts\",\n \"default\": \"./dist/tsup/common/websocket.cjs\"\n }\n },\n \"./driver-test-suite\": {\n \"import\": {\n \"types\": \"./dist/tsup/driver-test-suite/mod.d.ts\",\n \"default\": \"./dist/tsup/driver-test-suite/mod.js\"\n },\n \"require\": {\n \"types\": \"./dist/tsup/driver-test-suite/mod.d.cts\",\n \"default\": \"./dist/tsup/driver-test-suite/mod.cjs\"\n }\n },\n \"./topologies/coordinate\": {\n \"import\": {\n \"types\": \"./dist/tsup/topologies/coordinate/mod.d.ts\",\n \"default\": \"./dist/tsup/topologies/coordinate/mod.js\"\n },\n \"require\": {\n \"types\": \"./dist/tsup/topologies/coordinate/mod.d.cts\",\n \"default\": \"./dist/tsup/topologies/coordinate/mod.cjs\"\n }\n },\n \"./topologies/partition\": {\n \"import\": {\n \"types\": \"./dist/tsup/topologies/partition/mod.d.ts\",\n \"default\": \"./dist/tsup/topologies/partition/mod.js\"\n },\n \"require\": {\n \"types\": \"./dist/tsup/topologies/partition/mod.d.cts\",\n \"default\": \"./dist/tsup/topologies/partition/mod.cjs\"\n }\n },\n \"./test\": {\n \"import\": {\n \"types\": \"./dist/tsup/test/mod.d.ts\",\n \"default\": \"./dist/tsup/test/mod.js\"\n },\n \"require\": {\n \"types\": \"./dist/tsup/test/mod.d.cts\",\n \"default\": \"./dist/tsup/test/mod.cjs\"\n }\n },\n \"./inspector\": {\n \"import\": {\n \"types\": \"./dist/tsup/inspector/mod.d.ts\",\n \"default\": \"./dist/tsup/inspector/mod.js\"\n },\n \"require\": {\n \"types\": \"./dist/tsup/inspector/mod.d.cts\",\n \"default\": \"./dist/tsup/inspector/mod.cjs\"\n }\n }\n },\n \"engines\": {\n \"node\": \">=22.0.0\"\n },\n \"sideEffects\": [\n \"./dist/tsup/chunk-*.js\",\n \"./dist/tsup/chunk-*.cjs\"\n ],\n \"scripts\": {\n \"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/test/mod.ts src/inspector/mod.ts\",\n \"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/file-system-driver/v1.bare -o dist/schemas/file-system-driver/v1.ts && ./scripts/compile-bare.ts compile schemas/actor-persist/v1.bare -o dist/schemas/actor-persist/v1.ts\",\n \"check-types\": \"tsc --noEmit\",\n \"test\": \"vitest run\",\n \"test:watch\": \"vitest\",\n \"dump-openapi\": \"tsx scripts/dump-openapi.ts\"\n },\n \"dependencies\": {\n \"@bare-ts/lib\": \"~0.3.0\",\n \"@hono/standard-validator\": \"^0.1.3\",\n \"@hono/zod-openapi\": \"^0.19.10\",\n \"@rivetkit/engine-runner\": \"https://pkg.pr.new/rivet-dev/engine/@rivetkit/engine-runner@6659217\",\n \"@rivetkit/fast-json-patch\": \"^3.1.2\",\n \"cbor-x\": \"^1.6.0\",\n \"hono\": \"^4.7.0\",\n \"invariant\": \"^2.2.4\",\n \"nanoevents\": \"^9.1.0\",\n \"on-change\": \"^5.0.1\",\n \"p-retry\": \"^6.2.1\",\n \"pino\": \"^9.5.0\",\n \"zod\": \"^3.25.76\"\n },\n \"devDependencies\": {\n \"@bare-ts/tools\": \"^0.13.0\",\n \"@hono/node-server\": \"^1.18.2\",\n \"@hono/node-ws\": \"^1.1.1\",\n \"@types/invariant\": \"^2\",\n \"@types/node\": \"^22.13.1\",\n \"@types/ws\": \"^8\",\n \"@vitest/ui\": \"3.1.1\",\n \"bundle-require\": \"^5.1.0\",\n \"eventsource\": \"^4.0.0\",\n \"tsup\": \"^8.4.0\",\n \"tsx\": \"^4.19.4\",\n \"typescript\": \"^5.7.3\",\n \"vitest\": \"^3.1.1\",\n \"ws\": \"^8.18.1\"\n },\n \"peerDependencies\": {\n \"@hono/node-server\": \"^1.14.0\",\n \"@hono/node-ws\": \"^1.1.1\",\n \"eventsource\": \"^4.0.0\",\n \"ws\": \"^8.0.0\"\n },\n \"peerDependenciesMeta\": {\n \"@hono/node-server\": {\n \"optional\": true\n },\n \"@hono/node-ws\": {\n \"optional\": true\n },\n \"eventsource\": {\n \"optional\": true\n },\n \"ws\": {\n \"optional\": true\n }\n },\n \"stableVersion\": \"0.8.0\"\n}\n","export { stringifyError } from \"@/common/utils\";\nexport { assertUnreachable } from \"./common/utils\";\n\nimport type { Context as HonoContext, Handler as HonoHandler } from \"hono\";\n\nimport pkgJson from \"../package.json\" with { type: \"json\" };\n\nexport const VERSION = pkgJson.version;\n\nlet _userAgent: string | undefined;\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 = typeof 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\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\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 */\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(data.byteOffset, data.byteOffset + data.byteLength),\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 */\nexport function promiseWithResolvers<T>(): {\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\treturn { promise, resolve, reject };\n}\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>();\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} catch {\n\t\t\t\t\t// Swallow errors: callers only await cycle completion, not success\n\t\t\t\t}\n\n\t\t\t\t// Notify all waiters for this cycle\n\t\t\t\tresolver?.resolve();\n\t\t\t}\n\t\t} finally {\n\t\t\tthis.runningDrainLoop = undefined;\n\t\t}\n\t}\n}\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 */\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"]}
@@ -4,7 +4,7 @@ import {
4
4
  inspectorLogger,
5
5
  isInspectorEnabled,
6
6
  secureInspector
7
- } from "./chunk-KPFRD7KN.js";
7
+ } from "./chunk-RI4YHZZW.js";
8
8
  import {
9
9
  ActorDefinition,
10
10
  RemoteManagerDriver,
@@ -17,10 +17,10 @@ import {
17
17
  lookupInRegistry,
18
18
  serializeActorKey,
19
19
  updateRunnerConfig
20
- } from "./chunk-DZEQUURK.js";
20
+ } from "./chunk-GQ5WTE64.js";
21
21
  import {
22
22
  CreateActorSchema
23
- } from "./chunk-YVK2XQNR.js";
23
+ } from "./chunk-QRUGCDA5.js";
24
24
  import {
25
25
  ActionContext,
26
26
  ClientConfigSchema,
@@ -32,7 +32,7 @@ import {
32
32
  createVersionedDataHandler,
33
33
  parseMessage,
34
34
  serializeEmptyPersistData
35
- } from "./chunk-2MUSMEMN.js";
35
+ } from "./chunk-7ACKZS3T.js";
36
36
  import {
37
37
  EncodingSchema,
38
38
  HEADER_ACTOR_ID,
@@ -58,12 +58,12 @@ import {
58
58
  generateRandomString,
59
59
  loggerWithoutContext,
60
60
  serializeWithEncoding
61
- } from "./chunk-AR5ZY563.js";
61
+ } from "./chunk-YFFCPYHY.js";
62
62
  import {
63
63
  configureBaseLogger,
64
64
  configureDefaultLogger,
65
65
  getLogger
66
- } from "./chunk-6JGEHV56.js";
66
+ } from "./chunk-ER5OT3SQ.js";
67
67
  import {
68
68
  VERSION,
69
69
  assertUnreachable,
@@ -75,7 +75,7 @@ import {
75
75
  promiseWithResolvers,
76
76
  setLongTimeout,
77
77
  stringifyError
78
- } from "./chunk-42UD33X4.js";
78
+ } from "./chunk-QMVCFQ37.js";
79
79
  import {
80
80
  ActorAlreadyExists,
81
81
  ConnNotFound,
@@ -2439,8 +2439,8 @@ var FileSystemGlobalState = class {
2439
2439
  for (const tempFile of tempFiles) {
2440
2440
  try {
2441
2441
  const fullPath = path2.join(this.#stateDir, tempFile);
2442
- const stat = fsSync2.statSync(fullPath);
2443
- if (stat.mtimeMs < oneHourAgo) {
2442
+ const stat2 = fsSync2.statSync(fullPath);
2443
+ if (stat2.mtimeMs < oneHourAgo) {
2444
2444
  fsSync2.unlinkSync(fullPath);
2445
2445
  logger5().info({
2446
2446
  msg: "cleaned up stale temp file",
@@ -2806,6 +2806,7 @@ function chooseDefaultDriver(runConfig) {
2806
2806
 
2807
2807
  // src/engine-process/mod.ts
2808
2808
  import { spawn } from "child_process";
2809
+ import { randomUUID as randomUUID2 } from "crypto";
2809
2810
  import { createWriteStream } from "fs";
2810
2811
  import * as fs3 from "fs/promises";
2811
2812
  import * as path3 from "path";
@@ -2884,9 +2885,11 @@ async function ensureEngineProcess(options) {
2884
2885
  });
2885
2886
  child.once("exit", (code, signal) => {
2886
2887
  logger6().warn({
2887
- msg: "engine process exited",
2888
+ msg: "engine process exited, please report this error",
2888
2889
  code,
2889
- signal
2890
+ signal,
2891
+ issues: "https://github.com/rivet-dev/rivetkit/issues",
2892
+ support: "https://rivet.dev/discord"
2890
2893
  });
2891
2894
  stdoutStream.end();
2892
2895
  stderrStream.end();
@@ -2935,22 +2938,55 @@ async function downloadEngineBinaryIfNeeded(binaryPath, version, varDir) {
2935
2938
  `failed to download rivet engine binary from ${downloadUrl}: ${response.status} ${response.statusText}`
2936
2939
  );
2937
2940
  }
2938
- const tempPath = `${binaryPath}.${process.pid}.tmp`;
2939
- await pipeline(response.body, createWriteStream(tempPath));
2940
- if (process.platform !== "win32") {
2941
- await fs3.chmod(tempPath, 493);
2942
- }
2943
- await fs3.rename(tempPath, binaryPath);
2941
+ const tempPath = `${binaryPath}.${randomUUID2()}.tmp`;
2942
+ const startTime = Date.now();
2944
2943
  logger6().debug({
2945
- msg: "engine binary download complete",
2946
- version,
2947
- path: binaryPath
2948
- });
2949
- logger6().info({
2950
- msg: "engine binary downloaded",
2951
- version,
2952
- path: binaryPath
2944
+ msg: "starting binary download",
2945
+ tempPath,
2946
+ contentLength: response.headers.get("content-length")
2953
2947
  });
2948
+ const slowDownloadWarning = setTimeout(() => {
2949
+ logger6().warn({
2950
+ msg: "engine binary download is taking longer than expected, please be patient",
2951
+ version
2952
+ });
2953
+ }, 5e3);
2954
+ try {
2955
+ await pipeline(response.body, createWriteStream(tempPath));
2956
+ clearTimeout(slowDownloadWarning);
2957
+ const stats = await fs3.stat(tempPath);
2958
+ const downloadDuration = Date.now() - startTime;
2959
+ if (process.platform !== "win32") {
2960
+ await fs3.chmod(tempPath, 493);
2961
+ }
2962
+ await fs3.rename(tempPath, binaryPath);
2963
+ logger6().debug({
2964
+ msg: "engine binary download complete",
2965
+ version,
2966
+ path: binaryPath,
2967
+ size: stats.size,
2968
+ durationMs: downloadDuration
2969
+ });
2970
+ logger6().info({
2971
+ msg: "engine binary downloaded",
2972
+ version,
2973
+ path: binaryPath
2974
+ });
2975
+ } catch (error) {
2976
+ clearTimeout(slowDownloadWarning);
2977
+ logger6().warn({
2978
+ msg: "engine download failed, please report this error",
2979
+ tempPath,
2980
+ error,
2981
+ issues: "https://github.com/rivet-dev/rivetkit/issues",
2982
+ support: "https://rivet.dev/discord"
2983
+ });
2984
+ try {
2985
+ await fs3.unlink(tempPath);
2986
+ } catch (unlinkError) {
2987
+ }
2988
+ throw error;
2989
+ }
2954
2990
  }
2955
2991
  function resolveTargetTriplet() {
2956
2992
  return resolveTargetTripletFor(process.platform, process.arch);
@@ -3925,6 +3961,15 @@ var Registry = class {
3925
3961
  );
3926
3962
  }
3927
3963
  const readyPromises = [];
3964
+ if (config2.runnerKind === "serverless") {
3965
+ logger7().debug("disabling health check since using serverless");
3966
+ config2.disableHealthCheck = true;
3967
+ }
3968
+ if (process.env.NODE_ENV !== "production" && config2.runnerKind === "serverless") {
3969
+ if ((inputConfig == null ? void 0 : inputConfig.runEngine) === void 0) config2.runEngine = true;
3970
+ if ((inputConfig == null ? void 0 : inputConfig.autoConfigureServerless) === void 0)
3971
+ config2.autoConfigureServerless = true;
3972
+ }
3928
3973
  if (config2.runEngine) {
3929
3974
  logger7().debug({
3930
3975
  msg: "run engine requested",
@@ -4005,6 +4050,7 @@ var Registry = class {
4005
4050
  }
4006
4051
  if (!config2.disableActorDriver) {
4007
4052
  Promise.all(readyPromises).then(async () => {
4053
+ logger7().debug("starting actor driver");
4008
4054
  driver.actor(this.#config, config2, managerDriver, client);
4009
4055
  });
4010
4056
  }
@@ -4033,6 +4079,7 @@ var Registry = class {
4033
4079
  }
4034
4080
  };
4035
4081
  async function configureServerlessRunner(config2) {
4082
+ logger7().debug("configuring serverless runner");
4036
4083
  try {
4037
4084
  if (!config2.runnerName) {
4038
4085
  throw new Error("runnerName is required for serverless configuration");
@@ -4075,7 +4122,8 @@ async function configureServerlessRunner(config2) {
4075
4122
  request_lifespan: customConfig.requestLifespan ?? 15 * 60,
4076
4123
  runners_margin: customConfig.runnersMargin ?? 0,
4077
4124
  slots_per_runner: customConfig.slotsPerRunner ?? config2.totalSlots ?? 1e3
4078
- }
4125
+ },
4126
+ metadata: customConfig.metadata ?? {}
4079
4127
  };
4080
4128
  await updateRunnerConfig(clientConfig, config2.runnerName, {
4081
4129
  datacenters: Object.fromEntries(
@@ -4089,10 +4137,9 @@ async function configureServerlessRunner(config2) {
4089
4137
  });
4090
4138
  } catch (error) {
4091
4139
  logger7().error({
4092
- msg: "failed to configure serverless runner",
4140
+ msg: "failed to configure serverless runner, validate endpoint is configured correctly then restart this process",
4093
4141
  error
4094
4142
  });
4095
- throw error;
4096
4143
  }
4097
4144
  }
4098
4145
  function setup(input) {
@@ -4116,4 +4163,4 @@ export {
4116
4163
  setup
4117
4164
  };
4118
4165
  //! These configs configs hold anything that's not platform-specific about running actors.
4119
- //# sourceMappingURL=chunk-S5K7CB2F.js.map
4166
+ //# sourceMappingURL=chunk-L3YPHXPE.js.map