rivetkit 0.0.0-main.41efcce → 0.0.0-main.49693dc

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 (299) hide show
  1. package/dist/browser/client.d.ts +939 -104
  2. package/dist/browser/client.js +1867 -900
  3. package/dist/browser/client.js.map +1 -1
  4. package/dist/browser/inspector/client.d.ts +252 -129
  5. package/dist/browser/inspector/client.js +2079 -233
  6. package/dist/browser/inspector/client.js.map +1 -1
  7. package/dist/tsup/actor/errors.cjs +6 -2
  8. package/dist/tsup/actor/errors.cjs.map +1 -1
  9. package/dist/tsup/actor/errors.d.cts +1 -74
  10. package/dist/tsup/actor/errors.d.ts +1 -74
  11. package/dist/tsup/actor/errors.js +5 -1
  12. package/dist/tsup/agent-os/index.cjs +2408 -2029
  13. package/dist/tsup/agent-os/index.cjs.map +1 -1
  14. package/dist/tsup/agent-os/index.d.cts +932 -114
  15. package/dist/tsup/agent-os/index.d.ts +932 -114
  16. package/dist/tsup/agent-os/index.js +2412 -2033
  17. package/dist/tsup/agent-os/index.js.map +1 -1
  18. package/dist/tsup/{chunk-J27CEW6F.js → chunk-2OBVQZX6.js} +6 -6
  19. package/dist/tsup/chunk-2OBVQZX6.js.map +1 -0
  20. package/dist/tsup/chunk-3ZWHWMFJ.js +14 -0
  21. package/dist/tsup/chunk-3ZWHWMFJ.js.map +1 -0
  22. package/dist/tsup/{chunk-AK57AL7S.cjs → chunk-4KGXFC6M.cjs} +238 -22
  23. package/dist/tsup/chunk-4KGXFC6M.cjs.map +1 -0
  24. package/dist/tsup/{chunk-CVHUXINE.js → chunk-5IU3MI7X.js} +594 -72
  25. package/dist/tsup/chunk-5IU3MI7X.js.map +1 -0
  26. package/dist/tsup/{chunk-VD7AZIBR.js → chunk-6CXQMHZR.js} +1161 -361
  27. package/dist/tsup/chunk-6CXQMHZR.js.map +1 -0
  28. package/dist/tsup/{chunk-SBEFJ4IQ.js → chunk-6W2UIH3X.js} +70 -8
  29. package/dist/tsup/chunk-6W2UIH3X.js.map +1 -0
  30. package/dist/tsup/{chunk-7MRGNVSR.js → chunk-6W5VGLFT.js} +237 -21
  31. package/dist/tsup/chunk-6W5VGLFT.js.map +1 -0
  32. package/dist/tsup/{chunk-RF3MEJV6.cjs → chunk-B73TBMMG.cjs} +18 -11
  33. package/dist/tsup/chunk-B73TBMMG.cjs.map +1 -0
  34. package/dist/tsup/chunk-D6TORRA4.js +243 -0
  35. package/dist/tsup/chunk-D6TORRA4.js.map +1 -0
  36. package/dist/tsup/{chunk-PXLJOMJD.js → chunk-FXT3HN32.js} +2 -2
  37. package/dist/tsup/{chunk-ZGWSH7YV.js → chunk-IXBD7BXC.js} +48 -72
  38. package/dist/tsup/chunk-IXBD7BXC.js.map +1 -0
  39. package/dist/tsup/{chunk-3BFYSYRU.js → chunk-JI6GZ2C2.js} +4 -12
  40. package/dist/tsup/chunk-JI6GZ2C2.js.map +1 -0
  41. package/dist/tsup/{chunk-PCBNKI2J.js → chunk-JTHHCZCZ.js} +24 -1
  42. package/dist/tsup/chunk-JTHHCZCZ.js.map +1 -0
  43. package/dist/tsup/{chunk-2NDZ7JCR.cjs → chunk-KVFIONKQ.cjs} +25 -2
  44. package/dist/tsup/chunk-KVFIONKQ.cjs.map +1 -0
  45. package/dist/tsup/{chunk-SPMMF6TR.cjs → chunk-LGOWPZJ5.cjs} +3 -3
  46. package/dist/tsup/chunk-LGOWPZJ5.cjs.map +1 -0
  47. package/dist/tsup/chunk-LYNWTX6R.cjs +14 -0
  48. package/dist/tsup/chunk-LYNWTX6R.cjs.map +1 -0
  49. package/dist/tsup/{chunk-LLD2D5LO.cjs → chunk-MYWZCDML.cjs} +4 -12
  50. package/dist/tsup/chunk-MYWZCDML.cjs.map +1 -0
  51. package/dist/tsup/{chunk-XSC2WWXD.js → chunk-NYDZLWHZ.js} +16 -9
  52. package/dist/tsup/chunk-NYDZLWHZ.js.map +1 -0
  53. package/dist/tsup/{chunk-AV54CVAG.cjs → chunk-RB7WUDX6.cjs} +1290 -490
  54. package/dist/tsup/chunk-RB7WUDX6.cjs.map +1 -0
  55. package/dist/tsup/{chunk-JTL6Y2UN.cjs → chunk-SPJORZMM.cjs} +49 -73
  56. package/dist/tsup/chunk-SPJORZMM.cjs.map +1 -0
  57. package/dist/tsup/chunk-SSMKIYEX.cjs +243 -0
  58. package/dist/tsup/chunk-SSMKIYEX.cjs.map +1 -0
  59. package/dist/tsup/{chunk-TQSL4NJ3.cjs → chunk-TQ4HSX2U.cjs} +72 -10
  60. package/dist/tsup/chunk-TQ4HSX2U.cjs.map +1 -0
  61. package/dist/tsup/{chunk-EVADNK6Z.cjs → chunk-U6ZQELGJ.cjs} +10 -10
  62. package/dist/tsup/chunk-U6ZQELGJ.cjs.map +1 -0
  63. package/dist/tsup/chunk-XLBMKZD3.cjs +1257 -0
  64. package/dist/tsup/chunk-XLBMKZD3.cjs.map +1 -0
  65. package/dist/tsup/client/mod.cjs +8 -9
  66. package/dist/tsup/client/mod.cjs.map +1 -1
  67. package/dist/tsup/client/mod.d.cts +18 -7
  68. package/dist/tsup/client/mod.d.ts +18 -7
  69. package/dist/tsup/client/mod.js +7 -8
  70. package/dist/tsup/common/log.cjs +5 -3
  71. package/dist/tsup/common/log.cjs.map +1 -1
  72. package/dist/tsup/common/log.d.cts +5 -1
  73. package/dist/tsup/common/log.d.ts +5 -1
  74. package/dist/tsup/common/log.js +6 -4
  75. package/dist/tsup/common/websocket.cjs +4 -4
  76. package/dist/tsup/common/websocket.cjs.map +1 -1
  77. package/dist/tsup/common/websocket.js +3 -3
  78. package/dist/tsup/{config-B3RIidaJ.d.ts → config-BXSV17G7.d.cts} +987 -72
  79. package/dist/tsup/{config-D6WxBYjV.d.cts → config-Bi1r6gI7.d.ts} +987 -72
  80. package/dist/tsup/{config-B9qUIHX4.d.ts → config-ey2I2zz5.d.cts} +82 -15
  81. package/dist/tsup/{config-B9qUIHX4.d.cts → config-ey2I2zz5.d.ts} +82 -15
  82. package/dist/tsup/context-4fJemY0D.d.cts +129 -0
  83. package/dist/tsup/context-D4sNYboo.d.ts +129 -0
  84. package/dist/tsup/db/drizzle.cjs +168 -103
  85. package/dist/tsup/db/drizzle.cjs.map +1 -1
  86. package/dist/tsup/db/drizzle.d.cts +8 -4
  87. package/dist/tsup/db/drizzle.d.ts +8 -4
  88. package/dist/tsup/db/drizzle.js +170 -105
  89. package/dist/tsup/db/drizzle.js.map +1 -1
  90. package/dist/tsup/db/mod.cjs +6 -163
  91. package/dist/tsup/db/mod.cjs.map +1 -1
  92. package/dist/tsup/db/mod.d.cts +12 -4
  93. package/dist/tsup/db/mod.d.ts +12 -4
  94. package/dist/tsup/db/mod.js +5 -162
  95. package/dist/tsup/db/mod.js.map +1 -1
  96. package/dist/tsup/dynamic/mod.cjs +24 -0
  97. package/dist/tsup/dynamic/mod.cjs.map +1 -0
  98. package/dist/tsup/dynamic/mod.d.cts +38 -0
  99. package/dist/tsup/dynamic/mod.d.ts +38 -0
  100. package/dist/tsup/dynamic/mod.js +24 -0
  101. package/dist/tsup/dynamic/mod.js.map +1 -0
  102. package/dist/tsup/inspector/mod.cjs +47 -12
  103. package/dist/tsup/inspector/mod.cjs.map +1 -1
  104. package/dist/tsup/inspector/mod.d.cts +26 -136
  105. package/dist/tsup/inspector/mod.d.ts +26 -136
  106. package/dist/tsup/inspector/mod.js +46 -11
  107. package/dist/tsup/inspector/mod.js.map +1 -1
  108. package/dist/tsup/inspector/workflow.cjs +21 -0
  109. package/dist/tsup/inspector/workflow.cjs.map +1 -0
  110. package/dist/tsup/inspector/workflow.d.cts +144 -0
  111. package/dist/tsup/inspector/workflow.d.ts +144 -0
  112. package/dist/tsup/inspector/workflow.js +21 -0
  113. package/dist/tsup/inspector/workflow.js.map +1 -0
  114. package/dist/tsup/inspector-tab/mod.cjs +162 -0
  115. package/dist/tsup/inspector-tab/mod.cjs.map +1 -0
  116. package/dist/tsup/inspector-tab/mod.d.cts +241 -0
  117. package/dist/tsup/inspector-tab/mod.d.ts +241 -0
  118. package/dist/tsup/inspector-tab/mod.js +162 -0
  119. package/dist/tsup/inspector-tab/mod.js.map +1 -0
  120. package/dist/tsup/mod.cjs +4268 -944
  121. package/dist/tsup/mod.cjs.map +1 -1
  122. package/dist/tsup/mod.d.cts +9 -8
  123. package/dist/tsup/mod.d.ts +9 -8
  124. package/dist/tsup/mod.js +4229 -905
  125. package/dist/tsup/mod.js.map +1 -1
  126. package/dist/tsup/test/mod.cjs +26 -21
  127. package/dist/tsup/test/mod.cjs.map +1 -1
  128. package/dist/tsup/test/mod.d.cts +7 -6
  129. package/dist/tsup/test/mod.d.ts +7 -6
  130. package/dist/tsup/test/mod.js +25 -20
  131. package/dist/tsup/test/mod.js.map +1 -1
  132. package/dist/tsup/unstable/migrations.cjs +101 -0
  133. package/dist/tsup/unstable/migrations.cjs.map +1 -0
  134. package/dist/tsup/unstable/migrations.d.cts +29 -0
  135. package/dist/tsup/unstable/migrations.d.ts +29 -0
  136. package/dist/tsup/unstable/migrations.js +101 -0
  137. package/dist/tsup/unstable/migrations.js.map +1 -0
  138. package/dist/tsup/utils-Bbz-3411.d.cts +162 -0
  139. package/dist/tsup/utils-BqdWVlzm.d.ts +162 -0
  140. package/dist/tsup/utils-vvJQyygr.d.cts +109 -0
  141. package/dist/tsup/utils-vvJQyygr.d.ts +109 -0
  142. package/dist/tsup/utils.cjs +7 -3
  143. package/dist/tsup/utils.cjs.map +1 -1
  144. package/dist/tsup/utils.d.cts +4 -147
  145. package/dist/tsup/utils.d.ts +4 -147
  146. package/dist/tsup/utils.js +6 -2
  147. package/dist/tsup/workflow/mod.cjs +517 -412
  148. package/dist/tsup/workflow/mod.cjs.map +1 -1
  149. package/dist/tsup/workflow/mod.d.cts +11 -10
  150. package/dist/tsup/workflow/mod.d.ts +11 -10
  151. package/dist/tsup/workflow/mod.js +511 -406
  152. package/dist/tsup/workflow/mod.js.map +1 -1
  153. package/package.json +62 -14
  154. package/src/actor/actions.ts +119 -0
  155. package/src/actor/config.test.ts +78 -0
  156. package/src/actor/config.ts +518 -96
  157. package/src/actor/contexts/index.ts +7 -2
  158. package/src/actor/definition.ts +38 -26
  159. package/src/actor/errors.ts +101 -89
  160. package/src/actor/keys.ts +2 -1
  161. package/src/actor/mod.ts +32 -21
  162. package/src/actor/schema.ts +2 -2
  163. package/src/agent-os/actor/cron.ts +37 -2
  164. package/src/agent-os/actor/index.ts +39 -19
  165. package/src/agent-os/actor/preview.ts +1 -2
  166. package/src/agent-os/actor/session.ts +2 -2
  167. package/src/agent-os/config.ts +1 -1
  168. package/src/agent-os/fs/database-vfs.ts +1 -1
  169. package/src/agent-os/index.ts +16 -15
  170. package/src/agent-os/types.ts +11 -0
  171. package/src/client/actor-common.ts +106 -53
  172. package/src/client/actor-conn.ts +94 -45
  173. package/src/client/actor-handle.ts +198 -79
  174. package/src/client/actor-query.ts +13 -6
  175. package/src/client/client.ts +43 -15
  176. package/src/client/config.ts +8 -0
  177. package/src/client/errors.ts +4 -2
  178. package/src/client/lifecycle-errors.ts +28 -4
  179. package/src/client/mod.ts +9 -4
  180. package/src/client/query.ts +3 -1
  181. package/src/client/queue.ts +8 -3
  182. package/src/client/raw-utils.ts +24 -16
  183. package/src/client/resolve-gateway-target.ts +3 -1
  184. package/src/client/utils.ts +36 -10
  185. package/src/common/actor-router-consts.ts +7 -0
  186. package/src/common/actor-websocket.ts +3 -1
  187. package/src/common/bare/actor-persist/v1.ts +205 -163
  188. package/src/common/bare/actor-persist/v2.ts +265 -213
  189. package/src/common/bare/actor-persist/v3.ts +176 -172
  190. package/src/common/bare/actor-persist/v4.ts +254 -253
  191. package/src/common/bare/generated/actor-runtime-socket-protocol/v1.ts +848 -0
  192. package/src/common/bare/generated/client-protocol/v4.ts +599 -0
  193. package/src/common/bare/generated/inspector/v5.ts +1016 -0
  194. package/src/common/bare/generated/inspector/v6.ts +1367 -0
  195. package/src/common/bare/transport/v1.ts +694 -542
  196. package/src/common/client-protocol-versioned.ts +176 -67
  197. package/src/common/client-protocol-zod.ts +7 -0
  198. package/src/common/client-protocol.ts +1 -1
  199. package/src/common/database/config.ts +103 -10
  200. package/src/common/database/mod.test.ts +364 -0
  201. package/src/common/database/mod.ts +278 -149
  202. package/src/common/database/native-database.test.ts +220 -0
  203. package/src/common/database/native-database.ts +394 -58
  204. package/src/common/database/shared.ts +25 -0
  205. package/src/common/encoding.ts +302 -38
  206. package/src/common/engine.ts +28 -1
  207. package/src/common/eventsource.ts +1 -1
  208. package/src/common/fetch-like.ts +49 -0
  209. package/src/common/inline-websocket-adapter.ts +14 -13
  210. package/src/common/inspector-transport.ts +12 -2
  211. package/src/common/log.ts +117 -14
  212. package/src/common/router.ts +49 -23
  213. package/src/common/utils.ts +23 -203
  214. package/src/common/websocket-interface.ts +1 -1
  215. package/src/db/drizzle.test.ts +164 -0
  216. package/src/db/drizzle.ts +207 -121
  217. package/src/db/mod.ts +6 -1
  218. package/src/devtools-loader/index.ts +4 -7
  219. package/src/devtools-loader/serve-devtools.ts +26 -0
  220. package/src/dynamic/instance.ts +32 -0
  221. package/src/dynamic/internal.ts +50 -0
  222. package/src/dynamic/isolate-runtime.ts +64 -0
  223. package/src/dynamic/mod.ts +32 -0
  224. package/src/engine-client/actor-http-client.ts +23 -4
  225. package/src/engine-client/actor-websocket-client.ts +32 -5
  226. package/src/engine-client/api-endpoints.ts +52 -2
  227. package/src/engine-client/api-utils.ts +2 -2
  228. package/src/engine-client/driver.ts +21 -17
  229. package/src/engine-client/mod.ts +116 -64
  230. package/src/engine-client/ws-proxy.ts +9 -4
  231. package/src/globals.d.ts +4 -0
  232. package/src/inspector/client.browser.ts +127 -15
  233. package/src/inspector/mod.ts +2 -4
  234. package/src/inspector/workflow.ts +61 -0
  235. package/src/inspector-tab/mod.ts +301 -0
  236. package/src/registry/config/envoy.ts +1 -2
  237. package/src/registry/config/index.ts +160 -53
  238. package/src/registry/config/serverless.ts +7 -1
  239. package/src/registry/index.ts +659 -96
  240. package/src/registry/napi-runtime.ts +1154 -0
  241. package/src/registry/native-validation.ts +10 -12
  242. package/src/registry/native.ts +2005 -955
  243. package/src/registry/process-metrics.ts +250 -0
  244. package/src/registry/run-handler-coordinator.test.ts +252 -0
  245. package/src/registry/run-handler-coordinator.ts +219 -0
  246. package/src/registry/runtime.test.ts +50 -0
  247. package/src/registry/runtime.ts +839 -0
  248. package/src/registry/wasm-runtime.ts +1283 -0
  249. package/src/registry/write-through-proxy.ts +141 -0
  250. package/src/serde.ts +8 -2
  251. package/src/serverless/configure.ts +102 -49
  252. package/src/test/mod.ts +2 -17
  253. package/src/test/ready.ts +22 -0
  254. package/src/unstable/migrations.test.ts +170 -0
  255. package/src/unstable/migrations.ts +141 -0
  256. package/src/utils/crypto.ts +14 -0
  257. package/src/utils/endpoint-parser.ts +1 -1
  258. package/src/utils/env-vars.ts +39 -0
  259. package/src/utils/node.ts +44 -28
  260. package/src/utils/router.ts +1 -1
  261. package/src/utils.ts +4 -2
  262. package/src/workflow/context.ts +683 -242
  263. package/src/workflow/driver.test.ts +62 -0
  264. package/src/workflow/driver.ts +246 -119
  265. package/src/workflow/inspector.ts +24 -24
  266. package/src/workflow/mod.ts +76 -84
  267. package/dist/tsup/chunk-2NDZ7JCR.cjs.map +0 -1
  268. package/dist/tsup/chunk-3BFYSYRU.js.map +0 -1
  269. package/dist/tsup/chunk-6AVUJ52Q.cjs +0 -253
  270. package/dist/tsup/chunk-6AVUJ52Q.cjs.map +0 -1
  271. package/dist/tsup/chunk-7MRGNVSR.js.map +0 -1
  272. package/dist/tsup/chunk-7X7RVTFF.cjs +0 -735
  273. package/dist/tsup/chunk-7X7RVTFF.cjs.map +0 -1
  274. package/dist/tsup/chunk-AK57AL7S.cjs.map +0 -1
  275. package/dist/tsup/chunk-AV54CVAG.cjs.map +0 -1
  276. package/dist/tsup/chunk-CVHUXINE.js.map +0 -1
  277. package/dist/tsup/chunk-EVADNK6Z.cjs.map +0 -1
  278. package/dist/tsup/chunk-J27CEW6F.js.map +0 -1
  279. package/dist/tsup/chunk-JTL6Y2UN.cjs.map +0 -1
  280. package/dist/tsup/chunk-LLD2D5LO.cjs.map +0 -1
  281. package/dist/tsup/chunk-PCBNKI2J.js.map +0 -1
  282. package/dist/tsup/chunk-RF3MEJV6.cjs.map +0 -1
  283. package/dist/tsup/chunk-SB4MXRN2.js +0 -253
  284. package/dist/tsup/chunk-SB4MXRN2.js.map +0 -1
  285. package/dist/tsup/chunk-SBEFJ4IQ.js.map +0 -1
  286. package/dist/tsup/chunk-SPMMF6TR.cjs.map +0 -1
  287. package/dist/tsup/chunk-TQSL4NJ3.cjs.map +0 -1
  288. package/dist/tsup/chunk-VD7AZIBR.js.map +0 -1
  289. package/dist/tsup/chunk-XSC2WWXD.js.map +0 -1
  290. package/dist/tsup/chunk-ZGWSH7YV.js.map +0 -1
  291. package/dist/tsup/context-BxvHh9wi.d.cts +0 -92
  292. package/dist/tsup/context-CNIZBIKl.d.ts +0 -92
  293. package/dist/tsup/utils-fwx3o3K9.d.cts +0 -18
  294. package/dist/tsup/utils-fwx3o3K9.d.ts +0 -18
  295. package/src/actor/driver.ts +0 -141
  296. package/src/actor/instance/mod.ts +0 -2501
  297. package/src/drivers/engine/actor-driver.ts +0 -2470
  298. package/src/utils/serve.ts +0 -217
  299. /package/dist/tsup/{chunk-PXLJOMJD.js.map → chunk-FXT3HN32.js.map} +0 -0
@@ -1,9 +1,16 @@
1
+ // src/common/log.ts
2
+ import {
3
+ pino,
4
+ stdTimeFunctions
5
+ } from "pino";
6
+ import { z as z2 } from "zod/v4";
7
+
1
8
  // src/actor/errors.ts
2
9
  var INTERNAL_ERROR_CODE = "internal_error";
3
10
  var INTERNAL_ERROR_DESCRIPTION = "An internal error occurred";
4
11
  var USER_ERROR_CODE = "user_error";
5
12
  function looksLikeRivetErrorOptions(value) {
6
- return typeof value === "object" && value !== null && ("public" in value || "metadata" in value || "statusCode" in value || "cause" in value);
13
+ return typeof value === "object" && value !== null && ("public" in value || "metadata" in value || "rayId" in value || "statusCode" in value || "actor" in value || "cause" in value);
7
14
  }
8
15
  function isTypedErrorTag(value) {
9
16
  return value === "ActorError" || value === "RivetError";
@@ -15,13 +22,15 @@ function errorMessage(error, fallback = String(error)) {
15
22
  return fallback;
16
23
  }
17
24
  function isRivetErrorLike(error) {
18
- return typeof error === "object" && error !== null && "group" in error && typeof error.group === "string" && "code" in error && typeof error.code === "string" && "message" in error && typeof error.message === "string" && (!("__type" in error) || isTypedErrorTag(error.__type));
25
+ return typeof error === "object" && error !== null && "group" in error && typeof error.group === "string" && "code" in error && typeof error.code === "string" && "message" in error && typeof error.message === "string" && (!("rayId" in error) || error.rayId === void 0 || typeof error.rayId === "string") && (!("__type" in error) || isTypedErrorTag(error.__type));
19
26
  }
20
27
  var RivetError = class extends Error {
21
28
  __type = "RivetError";
22
29
  public;
23
30
  metadata;
31
+ rayId;
24
32
  statusCode;
33
+ actor;
25
34
  group;
26
35
  code;
27
36
  static isRivetError(error) {
@@ -38,7 +47,9 @@ var RivetError = class extends Error {
38
47
  this.code = code;
39
48
  this.public = normalized.public ?? false;
40
49
  this.metadata = normalized.metadata;
50
+ this.rayId = normalized.rayId ?? void 0;
41
51
  this.statusCode = normalized.statusCode ?? (this.public ? 400 : 500);
52
+ this.actor = normalized.actor;
42
53
  }
43
54
  toString() {
44
55
  return this.message;
@@ -73,19 +84,6 @@ function actorNotFound(identifier) {
73
84
  );
74
85
  }
75
86
 
76
- // src/utils/env-vars.ts
77
- var getRivetEngine = () => getEnvUniversal("RIVET_ENGINE");
78
- var getRivetEndpoint = () => getEnvUniversal("RIVET_ENDPOINT");
79
- var getRivetToken = () => getEnvUniversal("RIVET_TOKEN");
80
- var getRivetNamespace = () => getEnvUniversal("RIVET_NAMESPACE");
81
- var getRivetPool = () => getEnvUniversal("RIVET_POOL");
82
- var getLogLevel = () => getEnvUniversal("RIVET_LOG_LEVEL") ?? getEnvUniversal("LOG_LEVEL");
83
- var getLogTarget = () => getEnvUniversal("RIVET_LOG_TARGET") === "1";
84
- var getLogTimestamp = () => getEnvUniversal("RIVET_LOG_TIMESTAMP") === "1";
85
- var getLogMessage = () => getEnvUniversal("RIVET_LOG_MESSAGE") === "1";
86
- var getLogErrorStack = () => getEnvUniversal("RIVET_LOG_ERROR_STACK") === "1";
87
- var getNextPhase = () => getEnvUniversal("NEXT_PHASE");
88
-
89
87
  // src/common/utils.ts
90
88
  function assertUnreachable(x) {
91
89
  throw new Error(`Unreachable case: ${x}`);
@@ -93,13 +91,15 @@ function assertUnreachable(x) {
93
91
  function isCanonicalStructuredRivetError(error) {
94
92
  return error instanceof RivetError || typeof error === "object" && error !== null && "__type" in error && error.__type === "RivetError" && "group" in error && typeof error.group === "string" && "code" in error && typeof error.code === "string" && "message" in error && typeof error.message === "string";
95
93
  }
96
- function deconstructError(error, logger4, extraLog, exposeInternalError = false) {
94
+ function deconstructError(error, exposeInternalError = false) {
97
95
  let statusCode;
98
96
  let public_;
99
97
  let group;
100
98
  let code;
101
99
  let message;
102
100
  let metadata;
101
+ let rayId;
102
+ let actor;
103
103
  if (isCanonicalStructuredRivetError(error)) {
104
104
  statusCode = typeof error.statusCode === "number" ? error.statusCode : error.public ? 400 : 500;
105
105
  public_ = error.public ?? false;
@@ -107,14 +107,8 @@ function deconstructError(error, logger4, extraLog, exposeInternalError = false)
107
107
  code = error.code;
108
108
  message = error.message;
109
109
  metadata = error.metadata;
110
- logger4.info({
111
- msg: "structured error passthrough",
112
- group,
113
- code,
114
- message,
115
- ...EXTRA_ERROR_LOG,
116
- ...extraLog
117
- });
110
+ rayId = error.rayId;
111
+ actor = error.actor;
118
112
  } else if (RivetError.isActorError(error) && error.public) {
119
113
  statusCode = "statusCode" in error && error.statusCode ? error.statusCode : 400;
120
114
  public_ = true;
@@ -122,14 +116,8 @@ function deconstructError(error, logger4, extraLog, exposeInternalError = false)
122
116
  code = error.code;
123
117
  message = getErrorMessage(error);
124
118
  metadata = error.metadata;
125
- logger4.info({
126
- msg: "public error",
127
- group,
128
- code,
129
- message,
130
- ...EXTRA_ERROR_LOG,
131
- ...extraLog
132
- });
119
+ rayId = error.rayId;
120
+ actor = error.actor;
133
121
  } else if (exposeInternalError) {
134
122
  if (RivetError.isActorError(error)) {
135
123
  statusCode = 500;
@@ -138,30 +126,14 @@ function deconstructError(error, logger4, extraLog, exposeInternalError = false)
138
126
  code = error.code;
139
127
  message = getErrorMessage(error);
140
128
  metadata = error.metadata;
141
- logger4.info({
142
- msg: "internal error",
143
- group,
144
- code,
145
- message,
146
- stack: error?.stack,
147
- ...EXTRA_ERROR_LOG,
148
- ...extraLog
149
- });
129
+ rayId = error.rayId;
130
+ actor = error.actor;
150
131
  } else {
151
132
  statusCode = 500;
152
133
  public_ = false;
153
134
  group = "rivetkit";
154
135
  code = INTERNAL_ERROR_CODE;
155
136
  message = getErrorMessage(error);
156
- logger4.info({
157
- msg: "internal error",
158
- group,
159
- code,
160
- message,
161
- stack: error?.stack,
162
- ...EXTRA_ERROR_LOG,
163
- ...extraLog
164
- });
165
137
  }
166
138
  } else {
167
139
  statusCode = 500;
@@ -169,16 +141,12 @@ function deconstructError(error, logger4, extraLog, exposeInternalError = false)
169
141
  group = "rivetkit";
170
142
  code = INTERNAL_ERROR_CODE;
171
143
  message = INTERNAL_ERROR_DESCRIPTION;
144
+ if (RivetError.isActorError(error)) {
145
+ actor = error.actor;
146
+ }
172
147
  metadata = {
173
- //url: `https://hub.rivet.dev/projects/${actorMetadata.project.slug}/environments/${actorMetadata.environment.slug}/actors?actorId=${actorMetadata.actor.id}`,
148
+ //url: `https://dashboard.rivet.dev/projects/${actorMetadata.project.slug}/environments/${actorMetadata.environment.slug}/actors?actorId=${actorMetadata.actor.id}`,
174
149
  };
175
- logger4.warn({
176
- msg: "internal error",
177
- error: getErrorMessage(error),
178
- stack: error?.stack,
179
- ...EXTRA_ERROR_LOG,
180
- ...extraLog
181
- });
182
150
  }
183
151
  return {
184
152
  __type: "ActorError",
@@ -187,14 +155,22 @@ function deconstructError(error, logger4, extraLog, exposeInternalError = false)
187
155
  group,
188
156
  code,
189
157
  message,
190
- metadata
158
+ metadata,
159
+ rayId,
160
+ actor
191
161
  };
192
162
  }
193
163
  function stringifyError(error) {
194
164
  if (error instanceof Error) {
195
165
  if (typeof process !== "undefined" && getLogErrorStack()) {
196
- return `${error.name}: ${error.message}${error.stack ? `
197
- ${error.stack}` : ""}`;
166
+ let stack;
167
+ try {
168
+ stack = error.stack;
169
+ } catch {
170
+ stack = void 0;
171
+ }
172
+ return `${error.name}: ${error.message}${stack ? `
173
+ ${stack}` : ""}`;
198
174
  } else {
199
175
  return `${error.name}: ${error.message}`;
200
176
  }
@@ -225,7 +201,7 @@ function noopNext() {
225
201
  // package.json
226
202
  var package_default = {
227
203
  name: "rivetkit",
228
- version: "0.0.0-main.41efcce",
204
+ version: "0.0.0-main.49693dc",
229
205
  description: "Lightweight libraries for building stateful actors on edge platforms",
230
206
  license: "Apache-2.0",
231
207
  keywords: [
@@ -297,6 +273,26 @@ var package_default = {
297
273
  default: "./dist/tsup/db/drizzle.cjs"
298
274
  }
299
275
  },
276
+ "./unstable/migrations": {
277
+ import: {
278
+ types: "./dist/tsup/unstable/migrations.d.ts",
279
+ default: "./dist/tsup/unstable/migrations.js"
280
+ },
281
+ require: {
282
+ types: "./dist/tsup/unstable/migrations.d.cts",
283
+ default: "./dist/tsup/unstable/migrations.cjs"
284
+ }
285
+ },
286
+ "./dynamic": {
287
+ import: {
288
+ types: "./dist/tsup/dynamic/mod.d.ts",
289
+ default: "./dist/tsup/dynamic/mod.js"
290
+ },
291
+ require: {
292
+ types: "./dist/tsup/dynamic/mod.d.cts",
293
+ default: "./dist/tsup/dynamic/mod.cjs"
294
+ }
295
+ },
300
296
  "./client": {
301
297
  import: {
302
298
  browser: {
@@ -341,6 +337,26 @@ var package_default = {
341
337
  default: "./dist/tsup/inspector/mod.cjs"
342
338
  }
343
339
  },
340
+ "./experimental/inspector/workflow": {
341
+ import: {
342
+ types: "./dist/tsup/inspector/workflow.d.ts",
343
+ default: "./dist/tsup/inspector/workflow.js"
344
+ },
345
+ require: {
346
+ types: "./dist/tsup/inspector/workflow.d.cts",
347
+ default: "./dist/tsup/inspector/workflow.cjs"
348
+ }
349
+ },
350
+ "./inspector-tab": {
351
+ import: {
352
+ types: "./dist/tsup/inspector-tab/mod.d.ts",
353
+ default: "./dist/tsup/inspector-tab/mod.js"
354
+ },
355
+ require: {
356
+ types: "./dist/tsup/inspector-tab/mod.d.cts",
357
+ default: "./dist/tsup/inspector-tab/mod.cjs"
358
+ }
359
+ },
344
360
  "./inspector/client": {
345
361
  import: {
346
362
  types: "./dist/browser/inspector/client.d.ts",
@@ -376,7 +392,7 @@ var package_default = {
376
392
  "./dist/tsup/chunk-*.cjs"
377
393
  ],
378
394
  scripts: {
379
- build: "tsup src/mod.ts src/client/mod.ts src/common/log.ts src/common/websocket.ts src/actor/errors.ts src/utils.ts src/workflow/mod.ts src/test/mod.ts src/inspector/mod.ts src/db/mod.ts src/db/drizzle.ts && tsup src/agent-os/index.ts --no-clean --out-dir dist/tsup/agent-os",
395
+ build: "tsup src/mod.ts src/client/mod.ts src/common/log.ts src/common/websocket.ts src/actor/errors.ts src/utils.ts src/workflow/mod.ts src/test/mod.ts src/inspector/mod.ts src/inspector/workflow.ts src/inspector-tab/mod.ts src/db/mod.ts src/db/drizzle.ts src/dynamic/mod.ts src/unstable/migrations.ts && tsup src/agent-os/index.ts --no-clean --out-dir dist/tsup/agent-os && node scripts/check-built-commonjs.mjs",
380
396
  "build:browser": "tsup --config tsup.browser.config.ts",
381
397
  "check-types": "tsc --noEmit",
382
398
  lint: "biome check . && pnpm run check:test-skips && pnpm run check:wait-for-comments",
@@ -386,26 +402,26 @@ var package_default = {
386
402
  format: "biome format .",
387
403
  "format:write": "biome format --write .",
388
404
  test: "vitest run",
405
+ "test:platforms": "pnpm run build && RIVETKIT_INCLUDE_PLATFORM_TESTS=1 vitest run tests/platforms --passWithNoTests",
389
406
  "test:watch": "vitest",
390
407
  "dump-asyncapi": "tsx scripts/dump-asyncapi.ts",
391
408
  "registry-config-schema-gen": "tsx scripts/registry-config-schema-gen.ts",
392
409
  "actor-config-schema-gen": "tsx scripts/actor-config-schema-gen.ts"
393
410
  },
394
411
  dependencies: {
395
- "@rivet-dev/agent-os-core": "^0.1.1",
396
- "@hono/node-server": "^1.18.2",
397
- "@hono/node-ws": "^1.1.1",
398
412
  "@hono/zod-openapi": "^1.1.5",
413
+ "@rivet-dev/agent-os-core": "^0.1.1",
399
414
  "@rivetkit/bare-ts": "^0.6.2",
400
415
  "@rivetkit/engine-cli": "workspace:*",
401
416
  "@rivetkit/engine-envoy-protocol": "workspace:*",
417
+ "@rivetkit/on-change": "6.0.1",
402
418
  "@rivetkit/rivetkit-napi": "workspace:*",
419
+ "@rivetkit/rivetkit-wasm": "workspace:*",
403
420
  "@rivetkit/traces": "workspace:*",
404
421
  "@rivetkit/virtual-websocket": "workspace:*",
405
422
  "@rivetkit/workflow-engine": "workspace:*",
406
423
  "cbor-x": "^1.6.0",
407
424
  "drizzle-orm": "^0.44.2",
408
- "get-port": "^7.1.0",
409
425
  hono: "^4.7.0",
410
426
  invariant: "^2.2.4",
411
427
  "p-retry": "^6.2.1",
@@ -415,14 +431,17 @@ var package_default = {
415
431
  zod: "^4.1.0"
416
432
  },
417
433
  devDependencies: {
434
+ "@biomejs/biome": "^2.3",
418
435
  "@copilotkit/llmock": "^1.6.0",
436
+ "@hono/node-server": "^1.18.2",
437
+ "@hono/node-ws": "^1.1.1",
419
438
  "@rivet-dev/agent-os-common": "*",
420
439
  "@rivet-dev/agent-os-pi": "^0.1.1",
421
- "@biomejs/biome": "^2.3",
422
440
  "@standard-schema/spec": "^1.0.0",
423
441
  "@types/invariant": "^2",
424
442
  "@types/node": "^22.13.1",
425
443
  eventsource: "^4.0.0",
444
+ "get-port": "^7.1.0",
426
445
  tsup: "^8.4.0",
427
446
  tsx: "^4.19.4",
428
447
  typescript: "^5.7.3",
@@ -449,114 +468,341 @@ var package_default = {
449
468
  stableVersion: "0.8.0"
450
469
  };
451
470
 
452
- // src/common/log.ts
453
- import {
454
- pino,
455
- stdTimeFunctions
456
- } from "pino";
471
+ // src/common/encoding.ts
457
472
  import { z } from "zod/v4";
458
- var baseLogger;
459
- var configuredLogLevel;
460
- var loggerCache = /* @__PURE__ */ new Map();
461
- var LogLevelSchema = z.enum([
462
- "trace",
463
- "debug",
464
- "info",
465
- "warn",
466
- "error",
467
- "fatal",
468
- "silent"
469
- ]);
470
- function getPinoLevel(logLevel) {
471
- if (logLevel) {
472
- return logLevel;
473
+
474
+ // src/serde.ts
475
+ import * as cbor from "cbor-x";
476
+ import invariant from "invariant";
477
+ function uint8ArrayToBase64(uint8Array) {
478
+ if (typeof Buffer !== "undefined") {
479
+ return Buffer.from(uint8Array).toString("base64");
473
480
  }
474
- if (configuredLogLevel) {
475
- return configuredLogLevel;
481
+ let binary = "";
482
+ const len = uint8Array.byteLength;
483
+ for (let i = 0; i < len; i++) {
484
+ binary += String.fromCharCode(uint8Array[i]);
476
485
  }
477
- const raw = (getLogLevel() || "warn").toString().toLowerCase();
478
- const parsed = LogLevelSchema.safeParse(raw);
479
- if (parsed.success) {
480
- return parsed.data;
486
+ return btoa(binary);
487
+ }
488
+ function contentTypeForEncoding(encoding) {
489
+ if (encoding === "json") {
490
+ return "application/json";
491
+ } else if (encoding === "cbor" || encoding === "bare") {
492
+ return "application/octet-stream";
493
+ } else {
494
+ assertUnreachable(encoding);
481
495
  }
482
- return "info";
483
496
  }
484
- function getIncludeTarget() {
485
- return getLogTarget();
497
+ function encodeCborCompat(value) {
498
+ return cbor.encode(encodeJsonCompatValue(value));
486
499
  }
487
- function configureDefaultLogger(logLevel) {
488
- if (logLevel) {
489
- configuredLogLevel = logLevel;
490
- }
491
- baseLogger = pino({
492
- level: getPinoLevel(logLevel),
493
- messageKey: "msg",
494
- // Do not include pid/hostname in output
495
- base: {},
496
- // Keep a string level in the output
497
- formatters: {
498
- level(_label, number) {
499
- return { level: number };
500
- }
501
- },
502
- timestamp: getLogTimestamp() ? stdTimeFunctions.epochTime : false
503
- });
504
- loggerCache.clear();
500
+ function decodeCborCompat(buffer) {
501
+ return reviveJsonCompatValue(cbor.decode(buffer));
505
502
  }
506
- function getBaseLogger() {
507
- if (!baseLogger) {
508
- configureDefaultLogger();
503
+ function serializeWithEncoding(encoding, value, versionedDataHandler, version, zodSchema, toJson, toBare) {
504
+ if (encoding === "json") {
505
+ const jsonValue = toJson(value);
506
+ const validated = zodSchema.parse(jsonValue);
507
+ return jsonStringifyCompat(validated);
508
+ } else if (encoding === "cbor") {
509
+ const jsonValue = toJson(value);
510
+ const validated = zodSchema.parse(jsonValue);
511
+ return cbor.encode(validated);
512
+ } else if (encoding === "bare") {
513
+ if (!versionedDataHandler) {
514
+ throw new Error(
515
+ "VersionedDataHandler is required for 'bare' encoding"
516
+ );
517
+ }
518
+ if (version === void 0) {
519
+ throw new Error("version is required for 'bare' encoding");
520
+ }
521
+ const bareValue = toBare(value);
522
+ return versionedDataHandler.serializeWithEmbeddedVersion(
523
+ bareValue,
524
+ version
525
+ );
526
+ } else {
527
+ assertUnreachable(encoding);
509
528
  }
510
- return baseLogger;
511
529
  }
512
- function getLogger(name = "default") {
513
- const cached = loggerCache.get(name);
514
- if (cached) {
515
- return cached;
530
+ function deserializeWithEncoding(encoding, buffer, versionedDataHandler, zodSchema, fromJson, fromBare) {
531
+ if (encoding === "json") {
532
+ let parsed;
533
+ if (typeof buffer === "string") {
534
+ parsed = jsonParseCompat(buffer);
535
+ } else {
536
+ const decoder = new TextDecoder("utf-8");
537
+ const jsonString = decoder.decode(buffer);
538
+ parsed = jsonParseCompat(jsonString);
539
+ }
540
+ const validated = zodSchema.parse(parsed);
541
+ return fromJson(validated);
542
+ } else if (encoding === "cbor") {
543
+ invariant(
544
+ typeof buffer !== "string",
545
+ "buffer cannot be string for cbor encoding"
546
+ );
547
+ const decoded = decodeCborCompat(buffer);
548
+ const validated = zodSchema.parse(decoded);
549
+ return fromJson(validated);
550
+ } else if (encoding === "bare") {
551
+ invariant(
552
+ typeof buffer !== "string",
553
+ "buffer cannot be string for bare encoding"
554
+ );
555
+ if (!versionedDataHandler) {
556
+ throw new Error(
557
+ "VersionedDataHandler is required for 'bare' encoding"
558
+ );
559
+ }
560
+ const bareValue = versionedDataHandler.deserializeWithEmbeddedVersion(buffer);
561
+ return fromBare(bareValue);
562
+ } else {
563
+ assertUnreachable(encoding);
516
564
  }
517
- const base = getBaseLogger();
518
- const child = getIncludeTarget() ? base.child({ target: name }) : base;
519
- loggerCache.set(name, child);
520
- return child;
521
565
  }
522
566
 
523
- // src/utils.ts
524
- var VERSION2 = package_default.version;
525
- var _userAgent;
526
- function httpUserAgent() {
527
- if (_userAgent !== void 0) {
528
- return _userAgent;
529
- }
530
- let userAgent = `RivetKit/${VERSION2}`;
531
- const navigatorObj = typeof navigator !== "undefined" ? navigator : void 0;
532
- if (navigatorObj?.userAgent) userAgent += ` ${navigatorObj.userAgent}`;
533
- _userAgent = userAgent;
534
- return userAgent;
567
+ // src/common/encoding.ts
568
+ var JSON_COMPAT_BIGINT = "$BigInt";
569
+ var JSON_COMPAT_ARRAY_BUFFER = "$ArrayBuffer";
570
+ var JSON_COMPAT_UINT8_ARRAY = "$Uint8Array";
571
+ var JSON_COMPAT_UNDEFINED = "$Undefined";
572
+ var JSON_COMPAT_SET = "$Set";
573
+ function isTypedArray(value) {
574
+ return value instanceof Uint8ClampedArray || value instanceof Uint16Array || value instanceof Uint32Array || value instanceof BigUint64Array || value instanceof Int8Array || value instanceof Int16Array || value instanceof Int32Array || value instanceof BigInt64Array || value instanceof Float32Array || value instanceof Float64Array;
535
575
  }
536
- function getEnvUniversal(key) {
537
- if (typeof Deno !== "undefined") {
538
- return Deno.env.get(key);
539
- } else if (typeof process !== "undefined") {
540
- return process.env[key];
576
+ var EncodingSchema = z.enum(["json", "cbor", "bare"]);
577
+ async function inputDataToBuffer(data) {
578
+ if (typeof data === "string") {
579
+ return data;
580
+ }
581
+ if (data instanceof Blob) {
582
+ return new Uint8Array(await data.arrayBuffer());
583
+ }
584
+ if (data instanceof Uint8Array) {
585
+ return data;
586
+ }
587
+ if (data instanceof ArrayBuffer || data instanceof SharedArrayBuffer) {
588
+ return new Uint8Array(data);
541
589
  }
590
+ throw new Error("Malformed message");
542
591
  }
543
- function promiseWithResolvers(onReject) {
544
- let resolve;
545
- let reject;
546
- const promise = new Promise((res, rej) => {
547
- resolve = res;
548
- reject = rej;
549
- });
550
- promise.catch(onReject);
551
- return { promise, resolve, reject };
592
+ function base64EncodeUint8Array(uint8Array) {
593
+ let binary = "";
594
+ for (const value of uint8Array) {
595
+ binary += String.fromCharCode(value);
596
+ }
597
+ return btoa(binary);
552
598
  }
553
- function bufferToArrayBuffer(buf) {
554
- return buf.buffer.slice(
555
- buf.byteOffset,
556
- buf.byteOffset + buf.byteLength
557
- );
599
+ function base64EncodeArrayBuffer(arrayBuffer) {
600
+ return base64EncodeUint8Array(new Uint8Array(arrayBuffer));
558
601
  }
559
- function combineUrlPath(endpoint, path, queryParams) {
602
+ function isPlainObject(value) {
603
+ if (value === null || typeof value !== "object") {
604
+ return false;
605
+ }
606
+ const proto = Object.getPrototypeOf(value);
607
+ return proto === Object.prototype || proto === null;
608
+ }
609
+ function encodeJsonCompatValue(input) {
610
+ if (input === null) {
611
+ return input;
612
+ }
613
+ if (input === void 0) {
614
+ return [JSON_COMPAT_UNDEFINED, 0];
615
+ }
616
+ if (typeof input === "string" || typeof input === "number" || typeof input === "boolean") {
617
+ return input;
618
+ }
619
+ if (typeof input === "bigint") {
620
+ return [JSON_COMPAT_BIGINT, input.toString()];
621
+ }
622
+ if (input instanceof ArrayBuffer) {
623
+ return [JSON_COMPAT_ARRAY_BUFFER, base64EncodeArrayBuffer(input)];
624
+ }
625
+ if (input instanceof Uint8Array) {
626
+ return [JSON_COMPAT_UINT8_ARRAY, base64EncodeUint8Array(input)];
627
+ }
628
+ if (isTypedArray(input)) {
629
+ return input;
630
+ }
631
+ if (input instanceof Date || input instanceof RegExp || input instanceof Error) {
632
+ return input;
633
+ }
634
+ if (input instanceof Set) {
635
+ const encoded = [...input.values()].map(
636
+ (v) => encodeJsonCompatValue(v)
637
+ );
638
+ return [JSON_COMPAT_SET, encoded];
639
+ }
640
+ if (input instanceof Map) {
641
+ const encoded = /* @__PURE__ */ new Map();
642
+ for (const [k, v] of input.entries()) {
643
+ encoded.set(
644
+ encodeJsonCompatValue(k),
645
+ encodeJsonCompatValue(v)
646
+ );
647
+ }
648
+ return encoded;
649
+ }
650
+ if (Array.isArray(input)) {
651
+ const encoded = input.map(
652
+ (value) => encodeJsonCompatValue(value)
653
+ );
654
+ if (encoded.length === 2 && typeof encoded[0] === "string" && encoded[0].startsWith("$")) {
655
+ return [`$${encoded[0]}`, encoded[1]];
656
+ }
657
+ return encoded;
658
+ }
659
+ if (isPlainObject(input)) {
660
+ const encoded = {};
661
+ for (const [key, value] of Object.entries(input)) {
662
+ encoded[key] = encodeJsonCompatValue(value);
663
+ }
664
+ return encoded;
665
+ }
666
+ const typeName = typeof input === "object" && input !== null ? input.constructor?.name ?? typeof input : typeof input;
667
+ throw new TypeError(`Value of type "${typeName}" is not CBOR serializable`);
668
+ }
669
+ function reviveJsonCompatValue(input, options = {}) {
670
+ if (typeof input === "bigint") {
671
+ if (options.coerceSafeIntegerBigInts && input >= BigInt(Number.MIN_SAFE_INTEGER) && input <= BigInt(Number.MAX_SAFE_INTEGER)) {
672
+ return Number(input);
673
+ }
674
+ return input;
675
+ }
676
+ if (input instanceof Map) {
677
+ const revived = /* @__PURE__ */ new Map();
678
+ for (const [k, v] of input.entries()) {
679
+ revived.set(
680
+ reviveJsonCompatValue(k, options),
681
+ reviveJsonCompatValue(v, options)
682
+ );
683
+ }
684
+ return revived;
685
+ }
686
+ if (Array.isArray(input)) {
687
+ if (input.length === 2 && typeof input[0] === "string" && input[0].startsWith("$")) {
688
+ if (input[0] === JSON_COMPAT_BIGINT) {
689
+ return BigInt(input[1]);
690
+ }
691
+ if (input[0] === JSON_COMPAT_ARRAY_BUFFER) {
692
+ return base64DecodeToArrayBuffer(input[1]);
693
+ }
694
+ if (input[0] === JSON_COMPAT_UINT8_ARRAY) {
695
+ return base64DecodeToUint8Array(input[1]);
696
+ }
697
+ if (input[0] === JSON_COMPAT_UNDEFINED) {
698
+ return void 0;
699
+ }
700
+ if (input[0] === JSON_COMPAT_SET) {
701
+ const items = input[1].map(
702
+ (v) => reviveJsonCompatValue(v, options)
703
+ );
704
+ return new Set(items);
705
+ }
706
+ if (input[0].startsWith("$$")) {
707
+ return [
708
+ input[0].substring(1),
709
+ reviveJsonCompatValue(input[1], options)
710
+ ];
711
+ }
712
+ throw new Error(
713
+ `Unknown JSON encoding type: ${input[0]}. This may indicate corrupted data or a version mismatch.`
714
+ );
715
+ }
716
+ return input.map((value) => reviveJsonCompatValue(value, options));
717
+ }
718
+ if (isPlainObject(input)) {
719
+ const decoded = {};
720
+ for (const [key, value] of Object.entries(input)) {
721
+ decoded[key] = reviveJsonCompatValue(value, options);
722
+ }
723
+ return decoded;
724
+ }
725
+ return input;
726
+ }
727
+ function base64DecodeToUint8Array(base64) {
728
+ if (typeof Buffer !== "undefined") {
729
+ return new Uint8Array(Buffer.from(base64, "base64"));
730
+ }
731
+ const binary = atob(base64);
732
+ const bytes = new Uint8Array(binary.length);
733
+ for (let i = 0; i < binary.length; i++) {
734
+ bytes[i] = binary.charCodeAt(i);
735
+ }
736
+ return bytes;
737
+ }
738
+ function base64DecodeToArrayBuffer(base64) {
739
+ return base64DecodeToUint8Array(base64).buffer;
740
+ }
741
+ function jsonStringifyCompat(input, space) {
742
+ return JSON.stringify(
743
+ input,
744
+ (_key, value) => {
745
+ if (typeof value === "bigint") {
746
+ return [JSON_COMPAT_BIGINT, value.toString()];
747
+ }
748
+ if (value instanceof ArrayBuffer) {
749
+ return [
750
+ JSON_COMPAT_ARRAY_BUFFER,
751
+ base64EncodeArrayBuffer(value)
752
+ ];
753
+ }
754
+ if (value instanceof Uint8Array) {
755
+ return [JSON_COMPAT_UINT8_ARRAY, base64EncodeUint8Array(value)];
756
+ }
757
+ if (Array.isArray(value) && value.length === 2 && typeof value[0] === "string" && value[0].startsWith("$")) {
758
+ return [`$${value[0]}`, value[1]];
759
+ }
760
+ return value;
761
+ },
762
+ space
763
+ );
764
+ }
765
+ function jsonParseCompat(input) {
766
+ return reviveJsonCompatValue(JSON.parse(input));
767
+ }
768
+
769
+ // src/utils.ts
770
+ var VERSION = package_default.version;
771
+ var _userAgent;
772
+ function httpUserAgent() {
773
+ if (_userAgent !== void 0) {
774
+ return _userAgent;
775
+ }
776
+ let userAgent = `RivetKit/${VERSION}`;
777
+ const navigatorObj = typeof navigator !== "undefined" ? navigator : void 0;
778
+ if (navigatorObj?.userAgent) userAgent += ` ${navigatorObj.userAgent}`;
779
+ _userAgent = userAgent;
780
+ return userAgent;
781
+ }
782
+ function getEnvUniversal(key) {
783
+ if (typeof Deno !== "undefined") {
784
+ return Deno.env.get(key);
785
+ } else if (typeof process !== "undefined") {
786
+ return process.env[key];
787
+ }
788
+ }
789
+ function promiseWithResolvers(onReject) {
790
+ let resolve;
791
+ let reject;
792
+ const promise = new Promise((res, rej) => {
793
+ resolve = res;
794
+ reject = rej;
795
+ });
796
+ promise.catch(onReject);
797
+ return { promise, resolve, reject };
798
+ }
799
+ function bufferToArrayBuffer(buf) {
800
+ return buf.buffer.slice(
801
+ buf.byteOffset,
802
+ buf.byteOffset + buf.byteLength
803
+ );
804
+ }
805
+ function combineUrlPath(endpoint, path, queryParams) {
560
806
  const baseUrl = new URL(endpoint);
561
807
  const pathParts = path.split("?");
562
808
  const pathOnly = pathParts[0];
@@ -580,11 +826,167 @@ function combineUrlPath(endpoint, path, queryParams) {
580
826
  const fullQuery = queryParts.length > 0 ? `?${queryParts.join("&")}` : "";
581
827
  return `${baseUrl.protocol}//${baseUrl.host}${fullPath}${fullQuery}`;
582
828
  }
583
- var EXTRA_ERROR_LOG = {
584
- issues: "https://github.com/rivet-dev/rivet/issues",
585
- support: "https://rivet.dev/discord",
586
- version: VERSION2
829
+
830
+ // src/utils/env-vars.ts
831
+ var getRivetEngine = () => getEnvUniversal("RIVET_ENGINE");
832
+ var getRivetEndpoint = () => getEnvUniversal("RIVET_ENDPOINT");
833
+ var getRivetToken = () => getEnvUniversal("RIVET_TOKEN");
834
+ var getRivetNamespace = () => getEnvUniversal("RIVET_NAMESPACE");
835
+ var getRivetPool = () => getEnvUniversal("RIVET_POOL");
836
+ var getLogLevel = () => getEnvUniversal("RIVET_LOG_LEVEL") ?? getEnvUniversal("LOG_LEVEL");
837
+ var getLogTarget = () => getEnvUniversal("RIVET_LOG_TARGET") === "1";
838
+ var getLogTimestamp = () => getEnvUniversal("RIVET_LOG_TIMESTAMP") === "1";
839
+ var getLogMessage = () => getEnvUniversal("RIVET_LOG_MESSAGE") === "1";
840
+ var getLogErrorStack = () => getEnvUniversal("RIVET_LOG_ERROR_STACK") === "1";
841
+ var getNextPhase = () => getEnvUniversal("NEXT_PHASE");
842
+
843
+ // src/common/log.ts
844
+ var baseLogger;
845
+ var configuredLogLevel;
846
+ var loggerCache = /* @__PURE__ */ new Map();
847
+ var LogLevelSchema = z2.enum([
848
+ "trace",
849
+ "debug",
850
+ "info",
851
+ "warn",
852
+ "error",
853
+ "fatal",
854
+ "silent"
855
+ ]);
856
+ function getPinoLevel(logLevel) {
857
+ if (logLevel) {
858
+ return logLevel;
859
+ }
860
+ if (configuredLogLevel) {
861
+ return configuredLogLevel;
862
+ }
863
+ const raw = (getLogLevel() || "warn").toString().toLowerCase();
864
+ const parsed = LogLevelSchema.safeParse(raw);
865
+ if (parsed.success) {
866
+ return parsed.data;
867
+ }
868
+ return "info";
869
+ }
870
+ function getIncludeTarget() {
871
+ return getLogTarget();
872
+ }
873
+ function makeDefaultLogger(logLevel) {
874
+ return pino(
875
+ {
876
+ level: getPinoLevel(logLevel),
877
+ messageKey: "msg",
878
+ // Do not include pid/hostname in output
879
+ base: {},
880
+ errorKey: "error",
881
+ // Keep the numeric level so the logfmt sink can match Pino's levels.
882
+ formatters: {
883
+ level(_label, number) {
884
+ return { level: number };
885
+ }
886
+ },
887
+ timestamp: getLogTimestamp() ? stdTimeFunctions.epochTime : false
888
+ },
889
+ createLogfmtDestination()
890
+ );
891
+ }
892
+ function configureDefaultLogger(logLevel) {
893
+ if (logLevel) {
894
+ configuredLogLevel = logLevel;
895
+ }
896
+ baseLogger = makeDefaultLogger(logLevel);
897
+ loggerCache.clear();
898
+ }
899
+ function getBaseLogger() {
900
+ if (!baseLogger) {
901
+ configureDefaultLogger();
902
+ }
903
+ return baseLogger;
904
+ }
905
+ function getLogger(name = "default") {
906
+ const cached = loggerCache.get(name);
907
+ if (cached) {
908
+ return cached;
909
+ }
910
+ const base = getBaseLogger();
911
+ const child = getIncludeTarget() ? base.child({ target: name }) : base;
912
+ loggerCache.set(name, child);
913
+ return child;
914
+ }
915
+ var PINO_LEVEL_LABELS = {
916
+ 10: "trace",
917
+ 20: "debug",
918
+ 30: "info",
919
+ 40: "warn",
920
+ 50: "error",
921
+ 60: "fatal"
587
922
  };
923
+ function createLogfmtDestination() {
924
+ return {
925
+ write(msg) {
926
+ const line = formatLogfmtLine(msg);
927
+ if (typeof process !== "undefined" && process.stdout?.write) {
928
+ process.stdout.write(`${line}
929
+ `);
930
+ } else {
931
+ console.log(line);
932
+ }
933
+ }
934
+ };
935
+ }
936
+ function formatLogfmtLine(raw) {
937
+ let data;
938
+ try {
939
+ data = JSON.parse(raw);
940
+ } catch {
941
+ return raw.trimEnd();
942
+ }
943
+ const parts = [];
944
+ appendLogfmtEntry(parts, "level", formatPinoLevel(data.level));
945
+ if (data.time !== void 0) {
946
+ appendLogfmtEntry(parts, "ts", data.time);
947
+ }
948
+ for (const [key, value] of Object.entries(data)) {
949
+ if (key === "level" || key === "time") {
950
+ continue;
951
+ }
952
+ appendLogfmtEntry(parts, key, value);
953
+ }
954
+ return parts.join(" ");
955
+ }
956
+ function formatPinoLevel(level) {
957
+ if (typeof level === "number") {
958
+ return PINO_LEVEL_LABELS[level] ?? level.toString();
959
+ }
960
+ if (typeof level === "string") {
961
+ return level.toLowerCase();
962
+ }
963
+ return "info";
964
+ }
965
+ function appendLogfmtEntry(parts, key, value) {
966
+ const safeKey = key.replace(/[\s="]/g, "");
967
+ if (safeKey.length === 0) {
968
+ return;
969
+ }
970
+ parts.push(`${safeKey}=${formatLogfmtValue(value)}`);
971
+ }
972
+ function formatLogfmtValue(value) {
973
+ if (typeof value === "number" || typeof value === "boolean") {
974
+ return String(value);
975
+ }
976
+ if (value === null || value === void 0) {
977
+ return "null";
978
+ }
979
+ if (typeof value === "string") {
980
+ return quoteLogfmtString(value);
981
+ }
982
+ return quoteLogfmtString(JSON.stringify(value));
983
+ }
984
+ function quoteLogfmtString(value) {
985
+ if (!/[\s="]/.test(value)) {
986
+ return value;
987
+ }
988
+ return `"${value.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "\\n")}"`;
989
+ }
588
990
 
589
991
  // src/devtools-loader/log.ts
590
992
  function logger() {
@@ -592,7 +994,6 @@ function logger() {
592
994
  }
593
995
 
594
996
  // src/devtools-loader/index.ts
595
- var DEFAULT_DEVTOOLS_URL = (version = VERSION2) => `https://releases.rivet.dev/rivet/latest/devtools/mod.js?v=${version}`;
596
997
  var scriptId = "rivetkit-devtools-script";
597
998
  function injectDevtools(config) {
598
999
  if (!window) {
@@ -600,9 +1001,10 @@ function injectDevtools(config) {
600
1001
  return;
601
1002
  }
602
1003
  if (!document.getElementById(scriptId)) {
1004
+ const src = `${config.endpoint?.replace(/\/$/, "")}/devtools/mod.js`;
603
1005
  const script = document.createElement("script");
604
1006
  script.id = scriptId;
605
- script.src = DEFAULT_DEVTOOLS_URL();
1007
+ script.src = src;
606
1008
  script.async = true;
607
1009
  document.head.appendChild(script);
608
1010
  }
@@ -622,6 +1024,7 @@ var KEYS = {
622
1024
  INSPECTOR_TOKEN: Uint8Array.from([3]),
623
1025
  KV: Uint8Array.from([4]),
624
1026
  QUEUE_PREFIX: Uint8Array.from([5]),
1027
+ LAST_PUSHED_ALARM: Uint8Array.from([6]),
625
1028
  WORKFLOW_PREFIX: Uint8Array.from([6]),
626
1029
  TRACES_PREFIX: Uint8Array.from([7])
627
1030
  };
@@ -711,7 +1114,7 @@ function deserializeActorKey(keyString) {
711
1114
  }
712
1115
  }
713
1116
  if (escaping) {
714
- parts.push(currentPart + "\\");
1117
+ parts.push(`${currentPart}\\`);
715
1118
  } else if (isEmptyStringMarker) {
716
1119
  parts.push("");
717
1120
  } else if (currentPart !== "" || parts.length > 0) {
@@ -720,260 +1123,34 @@ function deserializeActorKey(keyString) {
720
1123
  return parts;
721
1124
  }
722
1125
 
723
- // src/serde.ts
724
- import * as cbor from "cbor-x";
725
- import invariant from "invariant";
1126
+ // src/common/actor-router-consts.ts
1127
+ var PATH_CONNECT = "/connect";
1128
+ var PATH_WEBSOCKET_BASE = "/websocket";
1129
+ var PATH_WEBSOCKET_PREFIX = "/websocket/";
1130
+ var HEADER_ENCODING = "x-rivet-encoding";
1131
+ var HEADER_CONN_PARAMS = "x-rivet-conn-params";
1132
+ var HEADER_RIVET_TOKEN = "x-rivet-token";
1133
+ var HEADER_RIVET_TARGET = "x-rivet-target";
1134
+ var HEADER_RIVET_ACTOR = "x-rivet-actor";
1135
+ var HEADER_RIVET_SKIP_READY_WAIT = "x-rivet-skip-ready-wait";
1136
+ var WS_PROTOCOL_STANDARD = "rivet";
1137
+ var WS_PROTOCOL_TARGET = "rivet_target.";
1138
+ var WS_PROTOCOL_ACTOR = "rivet_actor.";
1139
+ var WS_PROTOCOL_ENCODING = "rivet_encoding.";
1140
+ var WS_PROTOCOL_CONN_PARAMS = "rivet_conn_params.";
1141
+ var WS_PROTOCOL_TOKEN = "rivet_token.";
1142
+ var WS_PROTOCOL_SKIP_READY_WAIT = "rivet_skip_ready_wait";
1143
+ var WS_PROTOCOL_TEST_ACK_HOOK = "rivet_test_ack_hook.";
726
1144
 
727
- // src/common/encoding.ts
728
- import { z as z2 } from "zod/v4";
729
- var JSON_COMPAT_BIGINT = "$BigInt";
730
- var JSON_COMPAT_ARRAY_BUFFER = "$ArrayBuffer";
731
- var JSON_COMPAT_UINT8_ARRAY = "$Uint8Array";
732
- var JSON_COMPAT_UNDEFINED = "$Undefined";
733
- var EncodingSchema = z2.enum(["json", "cbor", "bare"]);
734
- async function inputDataToBuffer(data) {
735
- if (typeof data === "string") {
736
- return data;
737
- }
738
- if (data instanceof Blob) {
739
- return new Uint8Array(await data.arrayBuffer());
740
- }
741
- if (data instanceof Uint8Array) {
742
- return data;
743
- }
744
- if (data instanceof ArrayBuffer || data instanceof SharedArrayBuffer) {
745
- return new Uint8Array(data);
746
- }
747
- throw new Error("Malformed message");
748
- }
749
- function base64EncodeUint8Array(uint8Array) {
750
- let binary = "";
751
- for (const value of uint8Array) {
752
- binary += String.fromCharCode(value);
753
- }
754
- return btoa(binary);
755
- }
756
- function base64EncodeArrayBuffer(arrayBuffer) {
757
- return base64EncodeUint8Array(new Uint8Array(arrayBuffer));
758
- }
759
- function isPlainObject(value) {
760
- if (value === null || typeof value !== "object") {
761
- return false;
762
- }
763
- const proto = Object.getPrototypeOf(value);
764
- return proto === Object.prototype || proto === null;
765
- }
766
- function encodeJsonCompatValue(input) {
767
- if (input === void 0) {
768
- return [JSON_COMPAT_UNDEFINED, 0];
769
- }
770
- if (typeof input === "bigint") {
771
- return [JSON_COMPAT_BIGINT, input.toString()];
772
- }
773
- if (input instanceof ArrayBuffer) {
774
- return [JSON_COMPAT_ARRAY_BUFFER, base64EncodeArrayBuffer(input)];
775
- }
776
- if (input instanceof Uint8Array) {
777
- return [JSON_COMPAT_UINT8_ARRAY, base64EncodeUint8Array(input)];
778
- }
779
- if (Array.isArray(input)) {
780
- const encoded = input.map((value) => encodeJsonCompatValue(value));
781
- if (encoded.length === 2 && typeof encoded[0] === "string" && encoded[0].startsWith("$")) {
782
- return ["$" + encoded[0], encoded[1]];
783
- }
784
- return encoded;
785
- }
786
- if (isPlainObject(input)) {
787
- const encoded = {};
788
- for (const [key, value] of Object.entries(input)) {
789
- encoded[key] = encodeJsonCompatValue(value);
790
- }
791
- return encoded;
792
- }
793
- return input;
794
- }
795
- function reviveJsonCompatValue(input) {
796
- if (Array.isArray(input)) {
797
- if (input.length === 2 && typeof input[0] === "string" && input[0].startsWith("$")) {
798
- if (input[0] === JSON_COMPAT_BIGINT) {
799
- return BigInt(input[1]);
800
- }
801
- if (input[0] === JSON_COMPAT_ARRAY_BUFFER) {
802
- return base64DecodeToArrayBuffer(input[1]);
803
- }
804
- if (input[0] === JSON_COMPAT_UINT8_ARRAY) {
805
- return base64DecodeToUint8Array(input[1]);
806
- }
807
- if (input[0] === JSON_COMPAT_UNDEFINED) {
808
- return void 0;
809
- }
810
- if (input[0].startsWith("$$")) {
811
- return [input[0].substring(1), reviveJsonCompatValue(input[1])];
812
- }
813
- throw new Error(
814
- `Unknown JSON encoding type: ${input[0]}. This may indicate corrupted data or a version mismatch.`
815
- );
816
- }
817
- return input.map((value) => reviveJsonCompatValue(value));
818
- }
819
- if (isPlainObject(input)) {
820
- const decoded = {};
821
- for (const [key, value] of Object.entries(input)) {
822
- decoded[key] = reviveJsonCompatValue(value);
823
- }
824
- return decoded;
825
- }
826
- return input;
827
- }
828
- function base64DecodeToUint8Array(base64) {
829
- if (typeof Buffer !== "undefined") {
830
- return new Uint8Array(Buffer.from(base64, "base64"));
831
- }
832
- const binary = atob(base64);
833
- const bytes = new Uint8Array(binary.length);
834
- for (let i = 0; i < binary.length; i++) {
835
- bytes[i] = binary.charCodeAt(i);
836
- }
837
- return bytes;
838
- }
839
- function base64DecodeToArrayBuffer(base64) {
840
- return base64DecodeToUint8Array(base64).buffer;
841
- }
842
- function jsonStringifyCompat(input) {
843
- return JSON.stringify(input, (_key, value) => {
844
- if (typeof value === "bigint") {
845
- return [JSON_COMPAT_BIGINT, value.toString()];
846
- }
847
- if (value instanceof ArrayBuffer) {
848
- return [
849
- JSON_COMPAT_ARRAY_BUFFER,
850
- base64EncodeArrayBuffer(value)
851
- ];
852
- }
853
- if (value instanceof Uint8Array) {
854
- return [
855
- JSON_COMPAT_UINT8_ARRAY,
856
- base64EncodeUint8Array(value)
857
- ];
858
- }
859
- if (Array.isArray(value) && value.length === 2 && typeof value[0] === "string" && value[0].startsWith("$")) {
860
- return ["$" + value[0], value[1]];
861
- }
862
- return value;
863
- });
864
- }
865
- function jsonParseCompat(input) {
866
- return reviveJsonCompatValue(JSON.parse(input));
867
- }
868
-
869
- // src/serde.ts
870
- function uint8ArrayToBase64(uint8Array) {
871
- if (typeof Buffer !== "undefined") {
872
- return Buffer.from(uint8Array).toString("base64");
873
- }
874
- let binary = "";
875
- const len = uint8Array.byteLength;
876
- for (let i = 0; i < len; i++) {
877
- binary += String.fromCharCode(uint8Array[i]);
878
- }
879
- return btoa(binary);
880
- }
881
- function contentTypeForEncoding(encoding) {
882
- if (encoding === "json") {
883
- return "application/json";
884
- } else if (encoding === "cbor" || encoding === "bare") {
885
- return "application/octet-stream";
886
- } else {
887
- assertUnreachable(encoding);
888
- }
889
- }
890
- function encodeCborCompat(value) {
891
- return cbor.encode(encodeJsonCompatValue(value));
892
- }
893
- function decodeCborCompat(buffer) {
894
- return reviveJsonCompatValue(cbor.decode(buffer));
895
- }
896
- function serializeWithEncoding(encoding, value, versionedDataHandler, version, zodSchema, toJson, toBare) {
897
- if (encoding === "json") {
898
- const jsonValue = toJson(value);
899
- const validated = zodSchema.parse(jsonValue);
900
- return jsonStringifyCompat(validated);
901
- } else if (encoding === "cbor") {
902
- const jsonValue = toJson(value);
903
- const validated = zodSchema.parse(jsonValue);
904
- return cbor.encode(validated);
905
- } else if (encoding === "bare") {
906
- if (!versionedDataHandler) {
907
- throw new Error(
908
- "VersionedDataHandler is required for 'bare' encoding"
909
- );
910
- }
911
- if (version === void 0) {
912
- throw new Error("version is required for 'bare' encoding");
913
- }
914
- const bareValue = toBare(value);
915
- return versionedDataHandler.serializeWithEmbeddedVersion(
916
- bareValue,
917
- version
918
- );
919
- } else {
920
- assertUnreachable(encoding);
921
- }
922
- }
923
- function deserializeWithEncoding(encoding, buffer, versionedDataHandler, zodSchema, fromJson, fromBare) {
924
- if (encoding === "json") {
925
- let parsed;
926
- if (typeof buffer === "string") {
927
- parsed = jsonParseCompat(buffer);
928
- } else {
929
- const decoder = new TextDecoder("utf-8");
930
- const jsonString = decoder.decode(buffer);
931
- parsed = jsonParseCompat(jsonString);
932
- }
933
- const validated = zodSchema.parse(parsed);
934
- return fromJson(validated);
935
- } else if (encoding === "cbor") {
936
- invariant(
937
- typeof buffer !== "string",
938
- "buffer cannot be string for cbor encoding"
939
- );
940
- const decoded = decodeCborCompat(buffer);
941
- const validated = zodSchema.parse(decoded);
942
- return fromJson(validated);
943
- } else if (encoding === "bare") {
944
- invariant(
945
- typeof buffer !== "string",
946
- "buffer cannot be string for bare encoding"
947
- );
948
- if (!versionedDataHandler) {
949
- throw new Error(
950
- "VersionedDataHandler is required for 'bare' encoding"
951
- );
952
- }
953
- const bareValue = versionedDataHandler.deserializeWithEmbeddedVersion(buffer);
954
- return fromBare(bareValue);
955
- } else {
956
- assertUnreachable(encoding);
957
- }
1145
+ // src/engine-client/driver.ts
1146
+ function shouldSkipReadyWait(options = {}) {
1147
+ return options.skipReadyWait === true;
958
1148
  }
959
1149
 
960
- // src/common/actor-router-consts.ts
961
- var PATH_CONNECT = "/connect";
962
- var PATH_WEBSOCKET_PREFIX = "/websocket/";
963
- var HEADER_ENCODING = "x-rivet-encoding";
964
- var HEADER_CONN_PARAMS = "x-rivet-conn-params";
965
- var HEADER_RIVET_TOKEN = "x-rivet-token";
966
- var WS_PROTOCOL_STANDARD = "rivet";
967
- var WS_PROTOCOL_TARGET = "rivet_target.";
968
- var WS_PROTOCOL_ACTOR = "rivet_actor.";
969
- var WS_PROTOCOL_ENCODING = "rivet_encoding.";
970
- var WS_PROTOCOL_CONN_PARAMS = "rivet_conn_params.";
971
- var WS_PROTOCOL_TEST_ACK_HOOK = "rivet_test_ack_hook.";
972
-
973
1150
  // src/engine-client/actor-http-client.ts
974
- async function sendHttpRequestToGateway(runConfig, gatewayUrl, actorRequest) {
1151
+ async function sendHttpRequestToGateway(runConfig, gatewayUrl, actorRequest, options = {}) {
975
1152
  let bodyToSend = null;
976
- const guardHeaders = buildGuardHeaders(runConfig, actorRequest);
1153
+ const guardHeaders = buildGuardHeaders(runConfig, actorRequest, options);
977
1154
  if (actorRequest.method !== "GET" && actorRequest.method !== "HEAD") {
978
1155
  if (actorRequest.bodyUsed) {
979
1156
  throw new Error("Request body has already been consumed");
@@ -982,7 +1159,7 @@ async function sendHttpRequestToGateway(runConfig, gatewayUrl, actorRequest) {
982
1159
  if (reqBody.byteLength !== 0) {
983
1160
  bodyToSend = reqBody;
984
1161
  guardHeaders.delete("transfer-encoding");
985
- guardHeaders.set("content-length", String(bodyToSend.byteLength));
1162
+ guardHeaders.delete("content-length");
986
1163
  }
987
1164
  }
988
1165
  const guardRequest = new Request(gatewayUrl, {
@@ -996,7 +1173,7 @@ async function sendHttpRequestToGateway(runConfig, gatewayUrl, actorRequest) {
996
1173
  function mutableResponse(fetchRes) {
997
1174
  return new Response(fetchRes.body, fetchRes);
998
1175
  }
999
- function buildGuardHeaders(runConfig, actorRequest) {
1176
+ function buildGuardHeaders(runConfig, actorRequest, options) {
1000
1177
  const headers = new Headers();
1001
1178
  actorRequest.headers.forEach((value, key) => {
1002
1179
  headers.set(key, value);
@@ -1007,6 +1184,13 @@ function buildGuardHeaders(runConfig, actorRequest) {
1007
1184
  if (runConfig.token) {
1008
1185
  headers.set(HEADER_RIVET_TOKEN, runConfig.token);
1009
1186
  }
1187
+ if (options.directActorId !== void 0) {
1188
+ headers.set(HEADER_RIVET_TARGET, "actor");
1189
+ headers.set(HEADER_RIVET_ACTOR, options.directActorId);
1190
+ }
1191
+ if (shouldSkipReadyWait(options)) {
1192
+ headers.set(HEADER_RIVET_SKIP_READY_WAIT, "1");
1193
+ }
1010
1194
  return headers;
1011
1195
  }
1012
1196
 
@@ -1116,6 +1300,9 @@ var ClientConfigSchemaBase = z3.object({
1116
1300
  poolName: z3.string().default(() => getRivetPool() ?? "default"),
1117
1301
  encoding: EncodingSchema.default("bare"),
1118
1302
  headers: z3.record(z3.string(), z3.string()).optional().default(() => ({})),
1303
+ gateway: z3.object({
1304
+ skipReadyWait: z3.boolean().optional().default(false)
1305
+ }).optional().default(() => ({ skipReadyWait: false })),
1119
1306
  // See RunConfig.getUpgradeWebSocket
1120
1307
  //
1121
1308
  // This is required in the client config in order to support
@@ -1368,7 +1555,7 @@ function buildActorGatewayUrl(endpoint, actorId, token, path = "") {
1368
1555
  const gatewayPath = `/gateway/${encodeURIComponent(actorId)}${tokenSegment}${path}`;
1369
1556
  return combineUrlPath(endpoint, gatewayPath);
1370
1557
  }
1371
- function buildActorQueryGatewayUrl(endpoint, namespace, query, token, path = "", maxInputSize = DEFAULT_MAX_QUERY_INPUT_SIZE, crashPolicy = void 0, runnerName) {
1558
+ function buildActorQueryGatewayUrl(endpoint, namespace, query, token, path = "", maxInputSize = DEFAULT_MAX_QUERY_INPUT_SIZE, crashPolicy = void 0, runnerName, options = {}) {
1372
1559
  if (namespace.length === 0) {
1373
1560
  throw new Error("actor query namespace must not be empty");
1374
1561
  }
@@ -1419,6 +1606,9 @@ function buildActorQueryGatewayUrl(endpoint, namespace, query, token, path = "",
1419
1606
  if (token !== void 0) {
1420
1607
  params.append("rvt-token", token);
1421
1608
  }
1609
+ if (shouldSkipReadyWait(options)) {
1610
+ params.append("rvt-skip-ready-wait", "true");
1611
+ }
1422
1612
  const queryString = params.toString();
1423
1613
  let separator;
1424
1614
  if (path.endsWith("?") || path.endsWith("&")) {
@@ -1451,7 +1641,7 @@ function pushInputQueryParam(params, input, maxInputSize) {
1451
1641
  function uint8ArrayToBase64Url(value) {
1452
1642
  return uint8ArrayToBase64(value).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/g, "");
1453
1643
  }
1454
- async function openWebSocketToGateway(runConfig, gatewayUrl, encoding, params) {
1644
+ async function openWebSocketToGateway(runConfig, gatewayUrl, encoding, params, options = {}) {
1455
1645
  const WebSocket2 = await importWebSocket();
1456
1646
  const ackHookToken = typeof process !== "undefined" && process.env.VITEST ? crypto.randomUUID() : void 0;
1457
1647
  logger3().debug({
@@ -1460,7 +1650,17 @@ async function openWebSocketToGateway(runConfig, gatewayUrl, encoding, params) {
1460
1650
  });
1461
1651
  const ws = new WebSocket2(
1462
1652
  gatewayUrl,
1463
- buildWebSocketProtocols(runConfig, encoding, params, ackHookToken)
1653
+ buildWebSocketProtocols(
1654
+ runConfig,
1655
+ encoding,
1656
+ params,
1657
+ ackHookToken,
1658
+ options.directActorId ? {
1659
+ target: "actor",
1660
+ actorId: options.directActorId
1661
+ } : void 0,
1662
+ options
1663
+ )
1464
1664
  );
1465
1665
  ws.binaryType = "arraybuffer";
1466
1666
  const bufferedWs = new BufferedRemoteWebSocket(
@@ -1475,13 +1675,19 @@ async function openWebSocketToGateway(runConfig, gatewayUrl, encoding, params) {
1475
1675
  }
1476
1676
  return bufferedWs;
1477
1677
  }
1478
- function buildWebSocketProtocols(_runConfig, encoding, params, ackHookToken, target) {
1678
+ function buildWebSocketProtocols(runConfig, encoding, params, ackHookToken, target, options = {}) {
1479
1679
  const protocols = [];
1480
1680
  protocols.push(WS_PROTOCOL_STANDARD);
1481
1681
  protocols.push(`${WS_PROTOCOL_ENCODING}${encoding}`);
1482
1682
  if (target) {
1483
1683
  protocols.push(`${WS_PROTOCOL_TARGET}${target.target}`);
1484
1684
  protocols.push(`${WS_PROTOCOL_ACTOR}${target.actorId}`);
1685
+ if (runConfig.token) {
1686
+ protocols.push(`${WS_PROTOCOL_TOKEN}${runConfig.token}`);
1687
+ }
1688
+ }
1689
+ if (shouldSkipReadyWait(options)) {
1690
+ protocols.push(WS_PROTOCOL_SKIP_READY_WAIT);
1485
1691
  }
1486
1692
  if (params) {
1487
1693
  protocols.push(
@@ -2071,495 +2277,927 @@ function decodeHttpActionRequest2(bytes) {
2071
2277
  }
2072
2278
  function readHttpActionResponse2(bc) {
2073
2279
  return {
2074
- output: readCbor2(bc)
2280
+ output: readCbor2(bc)
2281
+ };
2282
+ }
2283
+ function writeHttpActionResponse2(bc, x) {
2284
+ writeCbor2(bc, x.output);
2285
+ }
2286
+ function encodeHttpActionResponse2(x, config) {
2287
+ const fullConfig = config != null ? bare2.Config(config) : DEFAULT_CONFIG2;
2288
+ const bc = new bare2.ByteCursor(
2289
+ new Uint8Array(fullConfig.initialBufferLength),
2290
+ fullConfig
2291
+ );
2292
+ writeHttpActionResponse2(bc, x);
2293
+ return new Uint8Array(bc.view.buffer, bc.view.byteOffset, bc.offset);
2294
+ }
2295
+ function decodeHttpActionResponse2(bytes) {
2296
+ const bc = new bare2.ByteCursor(bytes, DEFAULT_CONFIG2);
2297
+ const result = readHttpActionResponse2(bc);
2298
+ if (bc.offset < bc.view.byteLength) {
2299
+ throw new bare2.BareError(bc.offset, "remaining bytes");
2300
+ }
2301
+ return result;
2302
+ }
2303
+ function readHttpResponseError2(bc) {
2304
+ return {
2305
+ group: bare2.readString(bc),
2306
+ code: bare2.readString(bc),
2307
+ message: bare2.readString(bc),
2308
+ metadata: read02(bc)
2309
+ };
2310
+ }
2311
+ function writeHttpResponseError2(bc, x) {
2312
+ bare2.writeString(bc, x.group);
2313
+ bare2.writeString(bc, x.code);
2314
+ bare2.writeString(bc, x.message);
2315
+ write02(bc, x.metadata);
2316
+ }
2317
+ function encodeHttpResponseError2(x, config) {
2318
+ const fullConfig = config != null ? bare2.Config(config) : DEFAULT_CONFIG2;
2319
+ const bc = new bare2.ByteCursor(
2320
+ new Uint8Array(fullConfig.initialBufferLength),
2321
+ fullConfig
2322
+ );
2323
+ writeHttpResponseError2(bc, x);
2324
+ return new Uint8Array(bc.view.buffer, bc.view.byteOffset, bc.offset);
2325
+ }
2326
+ function decodeHttpResponseError2(bytes) {
2327
+ const bc = new bare2.ByteCursor(bytes, DEFAULT_CONFIG2);
2328
+ const result = readHttpResponseError2(bc);
2329
+ if (bc.offset < bc.view.byteLength) {
2330
+ throw new bare2.BareError(bc.offset, "remaining bytes");
2331
+ }
2332
+ return result;
2333
+ }
2334
+ function readHttpResolveResponse2(bc) {
2335
+ return {
2336
+ actorId: bare2.readString(bc)
2337
+ };
2338
+ }
2339
+ function writeHttpResolveResponse2(bc, x) {
2340
+ bare2.writeString(bc, x.actorId);
2341
+ }
2342
+ function encodeHttpResolveResponse2(x, config) {
2343
+ const fullConfig = config != null ? bare2.Config(config) : DEFAULT_CONFIG2;
2344
+ const bc = new bare2.ByteCursor(
2345
+ new Uint8Array(fullConfig.initialBufferLength),
2346
+ fullConfig
2347
+ );
2348
+ writeHttpResolveResponse2(bc, x);
2349
+ return new Uint8Array(bc.view.buffer, bc.view.byteOffset, bc.offset);
2350
+ }
2351
+ function decodeHttpResolveResponse2(bytes) {
2352
+ const bc = new bare2.ByteCursor(bytes, DEFAULT_CONFIG2);
2353
+ const result = readHttpResolveResponse2(bc);
2354
+ if (bc.offset < bc.view.byteLength) {
2355
+ throw new bare2.BareError(bc.offset, "remaining bytes");
2356
+ }
2357
+ return result;
2358
+ }
2359
+
2360
+ // src/common/bare/generated/client-protocol/v3.ts
2361
+ import * as bare3 from "@rivetkit/bare-ts";
2362
+ var DEFAULT_CONFIG3 = /* @__PURE__ */ bare3.Config({});
2363
+ function readCbor3(bc) {
2364
+ return bare3.readData(bc);
2365
+ }
2366
+ function writeCbor3(bc, x) {
2367
+ bare3.writeData(bc, x);
2368
+ }
2369
+ function readInit3(bc) {
2370
+ return {
2371
+ actorId: bare3.readString(bc),
2372
+ connectionId: bare3.readString(bc)
2373
+ };
2374
+ }
2375
+ function writeInit3(bc, x) {
2376
+ bare3.writeString(bc, x.actorId);
2377
+ bare3.writeString(bc, x.connectionId);
2378
+ }
2379
+ function read03(bc) {
2380
+ return bare3.readBool(bc) ? readCbor3(bc) : null;
2381
+ }
2382
+ function write03(bc, x) {
2383
+ bare3.writeBool(bc, x != null);
2384
+ if (x != null) {
2385
+ writeCbor3(bc, x);
2386
+ }
2387
+ }
2388
+ function read13(bc) {
2389
+ return bare3.readBool(bc) ? bare3.readUint(bc) : null;
2390
+ }
2391
+ function write13(bc, x) {
2392
+ bare3.writeBool(bc, x != null);
2393
+ if (x != null) {
2394
+ bare3.writeUint(bc, x);
2395
+ }
2396
+ }
2397
+ function readError3(bc) {
2398
+ return {
2399
+ group: bare3.readString(bc),
2400
+ code: bare3.readString(bc),
2401
+ message: bare3.readString(bc),
2402
+ metadata: read03(bc),
2403
+ actionId: read13(bc)
2404
+ };
2405
+ }
2406
+ function writeError3(bc, x) {
2407
+ bare3.writeString(bc, x.group);
2408
+ bare3.writeString(bc, x.code);
2409
+ bare3.writeString(bc, x.message);
2410
+ write03(bc, x.metadata);
2411
+ write13(bc, x.actionId);
2412
+ }
2413
+ function readActionResponse3(bc) {
2414
+ return {
2415
+ id: bare3.readUint(bc),
2416
+ output: readCbor3(bc)
2417
+ };
2418
+ }
2419
+ function writeActionResponse3(bc, x) {
2420
+ bare3.writeUint(bc, x.id);
2421
+ writeCbor3(bc, x.output);
2422
+ }
2423
+ function readEvent3(bc) {
2424
+ return {
2425
+ name: bare3.readString(bc),
2426
+ args: readCbor3(bc)
2427
+ };
2428
+ }
2429
+ function writeEvent3(bc, x) {
2430
+ bare3.writeString(bc, x.name);
2431
+ writeCbor3(bc, x.args);
2432
+ }
2433
+ function readToClientBody3(bc) {
2434
+ const offset = bc.offset;
2435
+ const tag = bare3.readU8(bc);
2436
+ switch (tag) {
2437
+ case 0:
2438
+ return { tag: "Init", val: readInit3(bc) };
2439
+ case 1:
2440
+ return { tag: "Error", val: readError3(bc) };
2441
+ case 2:
2442
+ return { tag: "ActionResponse", val: readActionResponse3(bc) };
2443
+ case 3:
2444
+ return { tag: "Event", val: readEvent3(bc) };
2445
+ default: {
2446
+ bc.offset = offset;
2447
+ throw new bare3.BareError(offset, "invalid tag");
2448
+ }
2449
+ }
2450
+ }
2451
+ function writeToClientBody3(bc, x) {
2452
+ switch (x.tag) {
2453
+ case "Init": {
2454
+ bare3.writeU8(bc, 0);
2455
+ writeInit3(bc, x.val);
2456
+ break;
2457
+ }
2458
+ case "Error": {
2459
+ bare3.writeU8(bc, 1);
2460
+ writeError3(bc, x.val);
2461
+ break;
2462
+ }
2463
+ case "ActionResponse": {
2464
+ bare3.writeU8(bc, 2);
2465
+ writeActionResponse3(bc, x.val);
2466
+ break;
2467
+ }
2468
+ case "Event": {
2469
+ bare3.writeU8(bc, 3);
2470
+ writeEvent3(bc, x.val);
2471
+ break;
2472
+ }
2473
+ }
2474
+ }
2475
+ function readToClient3(bc) {
2476
+ return {
2477
+ body: readToClientBody3(bc)
2478
+ };
2479
+ }
2480
+ function writeToClient3(bc, x) {
2481
+ writeToClientBody3(bc, x.body);
2482
+ }
2483
+ function encodeToClient3(x, config) {
2484
+ const fullConfig = config != null ? bare3.Config(config) : DEFAULT_CONFIG3;
2485
+ const bc = new bare3.ByteCursor(
2486
+ new Uint8Array(fullConfig.initialBufferLength),
2487
+ fullConfig
2488
+ );
2489
+ writeToClient3(bc, x);
2490
+ return new Uint8Array(bc.view.buffer, bc.view.byteOffset, bc.offset);
2491
+ }
2492
+ function decodeToClient3(bytes) {
2493
+ const bc = new bare3.ByteCursor(bytes, DEFAULT_CONFIG3);
2494
+ const result = readToClient3(bc);
2495
+ if (bc.offset < bc.view.byteLength) {
2496
+ throw new bare3.BareError(bc.offset, "remaining bytes");
2497
+ }
2498
+ return result;
2499
+ }
2500
+ function readActionRequest3(bc) {
2501
+ return {
2502
+ id: bare3.readUint(bc),
2503
+ name: bare3.readString(bc),
2504
+ args: readCbor3(bc)
2505
+ };
2506
+ }
2507
+ function writeActionRequest3(bc, x) {
2508
+ bare3.writeUint(bc, x.id);
2509
+ bare3.writeString(bc, x.name);
2510
+ writeCbor3(bc, x.args);
2511
+ }
2512
+ function readSubscriptionRequest3(bc) {
2513
+ return {
2514
+ eventName: bare3.readString(bc),
2515
+ subscribe: bare3.readBool(bc)
2516
+ };
2517
+ }
2518
+ function writeSubscriptionRequest3(bc, x) {
2519
+ bare3.writeString(bc, x.eventName);
2520
+ bare3.writeBool(bc, x.subscribe);
2521
+ }
2522
+ function readToServerBody3(bc) {
2523
+ const offset = bc.offset;
2524
+ const tag = bare3.readU8(bc);
2525
+ switch (tag) {
2526
+ case 0:
2527
+ return { tag: "ActionRequest", val: readActionRequest3(bc) };
2528
+ case 1:
2529
+ return { tag: "SubscriptionRequest", val: readSubscriptionRequest3(bc) };
2530
+ default: {
2531
+ bc.offset = offset;
2532
+ throw new bare3.BareError(offset, "invalid tag");
2533
+ }
2534
+ }
2535
+ }
2536
+ function writeToServerBody3(bc, x) {
2537
+ switch (x.tag) {
2538
+ case "ActionRequest": {
2539
+ bare3.writeU8(bc, 0);
2540
+ writeActionRequest3(bc, x.val);
2541
+ break;
2542
+ }
2543
+ case "SubscriptionRequest": {
2544
+ bare3.writeU8(bc, 1);
2545
+ writeSubscriptionRequest3(bc, x.val);
2546
+ break;
2547
+ }
2548
+ }
2549
+ }
2550
+ function readToServer3(bc) {
2551
+ return {
2552
+ body: readToServerBody3(bc)
2553
+ };
2554
+ }
2555
+ function writeToServer3(bc, x) {
2556
+ writeToServerBody3(bc, x.body);
2557
+ }
2558
+ function encodeToServer3(x, config) {
2559
+ const fullConfig = config != null ? bare3.Config(config) : DEFAULT_CONFIG3;
2560
+ const bc = new bare3.ByteCursor(
2561
+ new Uint8Array(fullConfig.initialBufferLength),
2562
+ fullConfig
2563
+ );
2564
+ writeToServer3(bc, x);
2565
+ return new Uint8Array(bc.view.buffer, bc.view.byteOffset, bc.offset);
2566
+ }
2567
+ function decodeToServer3(bytes) {
2568
+ const bc = new bare3.ByteCursor(bytes, DEFAULT_CONFIG3);
2569
+ const result = readToServer3(bc);
2570
+ if (bc.offset < bc.view.byteLength) {
2571
+ throw new bare3.BareError(bc.offset, "remaining bytes");
2572
+ }
2573
+ return result;
2574
+ }
2575
+ function readHttpActionRequest3(bc) {
2576
+ return {
2577
+ args: readCbor3(bc)
2578
+ };
2579
+ }
2580
+ function writeHttpActionRequest3(bc, x) {
2581
+ writeCbor3(bc, x.args);
2582
+ }
2583
+ function encodeHttpActionRequest3(x, config) {
2584
+ const fullConfig = config != null ? bare3.Config(config) : DEFAULT_CONFIG3;
2585
+ const bc = new bare3.ByteCursor(
2586
+ new Uint8Array(fullConfig.initialBufferLength),
2587
+ fullConfig
2588
+ );
2589
+ writeHttpActionRequest3(bc, x);
2590
+ return new Uint8Array(bc.view.buffer, bc.view.byteOffset, bc.offset);
2591
+ }
2592
+ function decodeHttpActionRequest3(bytes) {
2593
+ const bc = new bare3.ByteCursor(bytes, DEFAULT_CONFIG3);
2594
+ const result = readHttpActionRequest3(bc);
2595
+ if (bc.offset < bc.view.byteLength) {
2596
+ throw new bare3.BareError(bc.offset, "remaining bytes");
2597
+ }
2598
+ return result;
2599
+ }
2600
+ function readHttpActionResponse3(bc) {
2601
+ return {
2602
+ output: readCbor3(bc)
2603
+ };
2604
+ }
2605
+ function writeHttpActionResponse3(bc, x) {
2606
+ writeCbor3(bc, x.output);
2607
+ }
2608
+ function encodeHttpActionResponse3(x, config) {
2609
+ const fullConfig = config != null ? bare3.Config(config) : DEFAULT_CONFIG3;
2610
+ const bc = new bare3.ByteCursor(
2611
+ new Uint8Array(fullConfig.initialBufferLength),
2612
+ fullConfig
2613
+ );
2614
+ writeHttpActionResponse3(bc, x);
2615
+ return new Uint8Array(bc.view.buffer, bc.view.byteOffset, bc.offset);
2616
+ }
2617
+ function decodeHttpActionResponse3(bytes) {
2618
+ const bc = new bare3.ByteCursor(bytes, DEFAULT_CONFIG3);
2619
+ const result = readHttpActionResponse3(bc);
2620
+ if (bc.offset < bc.view.byteLength) {
2621
+ throw new bare3.BareError(bc.offset, "remaining bytes");
2622
+ }
2623
+ return result;
2624
+ }
2625
+ function read2(bc) {
2626
+ return bare3.readBool(bc) ? bare3.readString(bc) : null;
2627
+ }
2628
+ function write2(bc, x) {
2629
+ bare3.writeBool(bc, x != null);
2630
+ if (x != null) {
2631
+ bare3.writeString(bc, x);
2632
+ }
2633
+ }
2634
+ function read3(bc) {
2635
+ return bare3.readBool(bc) ? bare3.readBool(bc) : null;
2636
+ }
2637
+ function write3(bc, x) {
2638
+ bare3.writeBool(bc, x != null);
2639
+ if (x != null) {
2640
+ bare3.writeBool(bc, x);
2641
+ }
2642
+ }
2643
+ function read4(bc) {
2644
+ return bare3.readBool(bc) ? bare3.readU64(bc) : null;
2645
+ }
2646
+ function write4(bc, x) {
2647
+ bare3.writeBool(bc, x != null);
2648
+ if (x != null) {
2649
+ bare3.writeU64(bc, x);
2650
+ }
2651
+ }
2652
+ function readHttpQueueSendRequest(bc) {
2653
+ return {
2654
+ body: readCbor3(bc),
2655
+ name: read2(bc),
2656
+ wait: read3(bc),
2657
+ timeout: read4(bc)
2658
+ };
2659
+ }
2660
+ function writeHttpQueueSendRequest(bc, x) {
2661
+ writeCbor3(bc, x.body);
2662
+ write2(bc, x.name);
2663
+ write3(bc, x.wait);
2664
+ write4(bc, x.timeout);
2665
+ }
2666
+ function encodeHttpQueueSendRequest(x, config) {
2667
+ const fullConfig = config != null ? bare3.Config(config) : DEFAULT_CONFIG3;
2668
+ const bc = new bare3.ByteCursor(
2669
+ new Uint8Array(fullConfig.initialBufferLength),
2670
+ fullConfig
2671
+ );
2672
+ writeHttpQueueSendRequest(bc, x);
2673
+ return new Uint8Array(bc.view.buffer, bc.view.byteOffset, bc.offset);
2674
+ }
2675
+ function decodeHttpQueueSendRequest(bytes) {
2676
+ const bc = new bare3.ByteCursor(bytes, DEFAULT_CONFIG3);
2677
+ const result = readHttpQueueSendRequest(bc);
2678
+ if (bc.offset < bc.view.byteLength) {
2679
+ throw new bare3.BareError(bc.offset, "remaining bytes");
2680
+ }
2681
+ return result;
2682
+ }
2683
+ function readHttpQueueSendResponse(bc) {
2684
+ return {
2685
+ status: bare3.readString(bc),
2686
+ response: read03(bc)
2075
2687
  };
2076
2688
  }
2077
- function writeHttpActionResponse2(bc, x) {
2078
- writeCbor2(bc, x.output);
2689
+ function writeHttpQueueSendResponse(bc, x) {
2690
+ bare3.writeString(bc, x.status);
2691
+ write03(bc, x.response);
2079
2692
  }
2080
- function encodeHttpActionResponse2(x, config) {
2081
- const fullConfig = config != null ? bare2.Config(config) : DEFAULT_CONFIG2;
2082
- const bc = new bare2.ByteCursor(
2693
+ function encodeHttpQueueSendResponse(x, config) {
2694
+ const fullConfig = config != null ? bare3.Config(config) : DEFAULT_CONFIG3;
2695
+ const bc = new bare3.ByteCursor(
2083
2696
  new Uint8Array(fullConfig.initialBufferLength),
2084
2697
  fullConfig
2085
2698
  );
2086
- writeHttpActionResponse2(bc, x);
2699
+ writeHttpQueueSendResponse(bc, x);
2087
2700
  return new Uint8Array(bc.view.buffer, bc.view.byteOffset, bc.offset);
2088
2701
  }
2089
- function decodeHttpActionResponse2(bytes) {
2090
- const bc = new bare2.ByteCursor(bytes, DEFAULT_CONFIG2);
2091
- const result = readHttpActionResponse2(bc);
2702
+ function decodeHttpQueueSendResponse(bytes) {
2703
+ const bc = new bare3.ByteCursor(bytes, DEFAULT_CONFIG3);
2704
+ const result = readHttpQueueSendResponse(bc);
2092
2705
  if (bc.offset < bc.view.byteLength) {
2093
- throw new bare2.BareError(bc.offset, "remaining bytes");
2706
+ throw new bare3.BareError(bc.offset, "remaining bytes");
2094
2707
  }
2095
2708
  return result;
2096
2709
  }
2097
- function readHttpResponseError2(bc) {
2710
+ function readHttpResponseError3(bc) {
2098
2711
  return {
2099
- group: bare2.readString(bc),
2100
- code: bare2.readString(bc),
2101
- message: bare2.readString(bc),
2102
- metadata: read02(bc)
2712
+ group: bare3.readString(bc),
2713
+ code: bare3.readString(bc),
2714
+ message: bare3.readString(bc),
2715
+ metadata: read03(bc)
2103
2716
  };
2104
2717
  }
2105
- function writeHttpResponseError2(bc, x) {
2106
- bare2.writeString(bc, x.group);
2107
- bare2.writeString(bc, x.code);
2108
- bare2.writeString(bc, x.message);
2109
- write02(bc, x.metadata);
2718
+ function writeHttpResponseError3(bc, x) {
2719
+ bare3.writeString(bc, x.group);
2720
+ bare3.writeString(bc, x.code);
2721
+ bare3.writeString(bc, x.message);
2722
+ write03(bc, x.metadata);
2110
2723
  }
2111
- function encodeHttpResponseError2(x, config) {
2112
- const fullConfig = config != null ? bare2.Config(config) : DEFAULT_CONFIG2;
2113
- const bc = new bare2.ByteCursor(
2724
+ function encodeHttpResponseError3(x, config) {
2725
+ const fullConfig = config != null ? bare3.Config(config) : DEFAULT_CONFIG3;
2726
+ const bc = new bare3.ByteCursor(
2114
2727
  new Uint8Array(fullConfig.initialBufferLength),
2115
2728
  fullConfig
2116
2729
  );
2117
- writeHttpResponseError2(bc, x);
2730
+ writeHttpResponseError3(bc, x);
2118
2731
  return new Uint8Array(bc.view.buffer, bc.view.byteOffset, bc.offset);
2119
2732
  }
2120
- function decodeHttpResponseError2(bytes) {
2121
- const bc = new bare2.ByteCursor(bytes, DEFAULT_CONFIG2);
2122
- const result = readHttpResponseError2(bc);
2733
+ function decodeHttpResponseError3(bytes) {
2734
+ const bc = new bare3.ByteCursor(bytes, DEFAULT_CONFIG3);
2735
+ const result = readHttpResponseError3(bc);
2123
2736
  if (bc.offset < bc.view.byteLength) {
2124
- throw new bare2.BareError(bc.offset, "remaining bytes");
2737
+ throw new bare3.BareError(bc.offset, "remaining bytes");
2125
2738
  }
2126
2739
  return result;
2127
2740
  }
2128
- function readHttpResolveResponse2(bc) {
2741
+ function readHttpResolveResponse3(bc) {
2129
2742
  return {
2130
- actorId: bare2.readString(bc)
2743
+ actorId: bare3.readString(bc)
2131
2744
  };
2132
2745
  }
2133
- function writeHttpResolveResponse2(bc, x) {
2134
- bare2.writeString(bc, x.actorId);
2746
+ function writeHttpResolveResponse3(bc, x) {
2747
+ bare3.writeString(bc, x.actorId);
2135
2748
  }
2136
- function encodeHttpResolveResponse2(x, config) {
2137
- const fullConfig = config != null ? bare2.Config(config) : DEFAULT_CONFIG2;
2138
- const bc = new bare2.ByteCursor(
2749
+ function encodeHttpResolveResponse3(x, config) {
2750
+ const fullConfig = config != null ? bare3.Config(config) : DEFAULT_CONFIG3;
2751
+ const bc = new bare3.ByteCursor(
2139
2752
  new Uint8Array(fullConfig.initialBufferLength),
2140
2753
  fullConfig
2141
2754
  );
2142
- writeHttpResolveResponse2(bc, x);
2755
+ writeHttpResolveResponse3(bc, x);
2143
2756
  return new Uint8Array(bc.view.buffer, bc.view.byteOffset, bc.offset);
2144
2757
  }
2145
- function decodeHttpResolveResponse2(bytes) {
2146
- const bc = new bare2.ByteCursor(bytes, DEFAULT_CONFIG2);
2147
- const result = readHttpResolveResponse2(bc);
2758
+ function decodeHttpResolveResponse3(bytes) {
2759
+ const bc = new bare3.ByteCursor(bytes, DEFAULT_CONFIG3);
2760
+ const result = readHttpResolveResponse3(bc);
2148
2761
  if (bc.offset < bc.view.byteLength) {
2149
- throw new bare2.BareError(bc.offset, "remaining bytes");
2762
+ throw new bare3.BareError(bc.offset, "remaining bytes");
2150
2763
  }
2151
2764
  return result;
2152
2765
  }
2153
2766
 
2154
- // src/common/bare/generated/client-protocol/v3.ts
2155
- import * as bare3 from "@rivetkit/bare-ts";
2156
- var DEFAULT_CONFIG3 = /* @__PURE__ */ bare3.Config({});
2157
- function readCbor3(bc) {
2158
- return bare3.readData(bc);
2767
+ // src/common/bare/generated/client-protocol/v4.ts
2768
+ import * as bare4 from "@rivetkit/bare-ts";
2769
+ var DEFAULT_CONFIG4 = /* @__PURE__ */ bare4.Config({});
2770
+ function readCbor4(bc) {
2771
+ return bare4.readData(bc);
2159
2772
  }
2160
- function writeCbor3(bc, x) {
2161
- bare3.writeData(bc, x);
2773
+ function writeCbor4(bc, x) {
2774
+ bare4.writeData(bc, x);
2162
2775
  }
2163
- function readInit3(bc) {
2776
+ function read04(bc) {
2777
+ return bare4.readBool(bc) ? bare4.readString(bc) : null;
2778
+ }
2779
+ function write04(bc, x) {
2780
+ bare4.writeBool(bc, x != null);
2781
+ if (x != null) {
2782
+ bare4.writeString(bc, x);
2783
+ }
2784
+ }
2785
+ function readActorSpecifier(bc) {
2164
2786
  return {
2165
- actorId: bare3.readString(bc),
2166
- connectionId: bare3.readString(bc)
2787
+ actorId: bare4.readString(bc),
2788
+ generation: bare4.readUint(bc),
2789
+ key: read04(bc)
2167
2790
  };
2168
2791
  }
2169
- function writeInit3(bc, x) {
2170
- bare3.writeString(bc, x.actorId);
2171
- bare3.writeString(bc, x.connectionId);
2792
+ function writeActorSpecifier(bc, x) {
2793
+ bare4.writeString(bc, x.actorId);
2794
+ bare4.writeUint(bc, x.generation);
2795
+ write04(bc, x.key);
2172
2796
  }
2173
- function read03(bc) {
2174
- return bare3.readBool(bc) ? readCbor3(bc) : null;
2797
+ function readInit4(bc) {
2798
+ return {
2799
+ actorId: bare4.readString(bc),
2800
+ connectionId: bare4.readString(bc)
2801
+ };
2175
2802
  }
2176
- function write03(bc, x) {
2177
- bare3.writeBool(bc, x != null);
2803
+ function writeInit4(bc, x) {
2804
+ bare4.writeString(bc, x.actorId);
2805
+ bare4.writeString(bc, x.connectionId);
2806
+ }
2807
+ function read14(bc) {
2808
+ return bare4.readBool(bc) ? readCbor4(bc) : null;
2809
+ }
2810
+ function write14(bc, x) {
2811
+ bare4.writeBool(bc, x != null);
2178
2812
  if (x != null) {
2179
- writeCbor3(bc, x);
2813
+ writeCbor4(bc, x);
2180
2814
  }
2181
2815
  }
2182
- function read13(bc) {
2183
- return bare3.readBool(bc) ? bare3.readUint(bc) : null;
2816
+ function read22(bc) {
2817
+ return bare4.readBool(bc) ? bare4.readUint(bc) : null;
2184
2818
  }
2185
- function write13(bc, x) {
2186
- bare3.writeBool(bc, x != null);
2819
+ function write22(bc, x) {
2820
+ bare4.writeBool(bc, x != null);
2187
2821
  if (x != null) {
2188
- bare3.writeUint(bc, x);
2822
+ bare4.writeUint(bc, x);
2189
2823
  }
2190
2824
  }
2191
- function readError3(bc) {
2825
+ function read32(bc) {
2826
+ return bare4.readBool(bc) ? readActorSpecifier(bc) : null;
2827
+ }
2828
+ function write32(bc, x) {
2829
+ bare4.writeBool(bc, x != null);
2830
+ if (x != null) {
2831
+ writeActorSpecifier(bc, x);
2832
+ }
2833
+ }
2834
+ function readError4(bc) {
2192
2835
  return {
2193
- group: bare3.readString(bc),
2194
- code: bare3.readString(bc),
2195
- message: bare3.readString(bc),
2196
- metadata: read03(bc),
2197
- actionId: read13(bc)
2836
+ group: bare4.readString(bc),
2837
+ code: bare4.readString(bc),
2838
+ message: bare4.readString(bc),
2839
+ metadata: read14(bc),
2840
+ actionId: read22(bc),
2841
+ actor: read32(bc)
2198
2842
  };
2199
2843
  }
2200
- function writeError3(bc, x) {
2201
- bare3.writeString(bc, x.group);
2202
- bare3.writeString(bc, x.code);
2203
- bare3.writeString(bc, x.message);
2204
- write03(bc, x.metadata);
2205
- write13(bc, x.actionId);
2844
+ function writeError4(bc, x) {
2845
+ bare4.writeString(bc, x.group);
2846
+ bare4.writeString(bc, x.code);
2847
+ bare4.writeString(bc, x.message);
2848
+ write14(bc, x.metadata);
2849
+ write22(bc, x.actionId);
2850
+ write32(bc, x.actor);
2206
2851
  }
2207
- function readActionResponse3(bc) {
2852
+ function readActionResponse4(bc) {
2208
2853
  return {
2209
- id: bare3.readUint(bc),
2210
- output: readCbor3(bc)
2854
+ id: bare4.readUint(bc),
2855
+ output: readCbor4(bc)
2211
2856
  };
2212
2857
  }
2213
- function writeActionResponse3(bc, x) {
2214
- bare3.writeUint(bc, x.id);
2215
- writeCbor3(bc, x.output);
2858
+ function writeActionResponse4(bc, x) {
2859
+ bare4.writeUint(bc, x.id);
2860
+ writeCbor4(bc, x.output);
2216
2861
  }
2217
- function readEvent3(bc) {
2862
+ function readEvent4(bc) {
2218
2863
  return {
2219
- name: bare3.readString(bc),
2220
- args: readCbor3(bc)
2864
+ name: bare4.readString(bc),
2865
+ args: readCbor4(bc)
2221
2866
  };
2222
2867
  }
2223
- function writeEvent3(bc, x) {
2224
- bare3.writeString(bc, x.name);
2225
- writeCbor3(bc, x.args);
2868
+ function writeEvent4(bc, x) {
2869
+ bare4.writeString(bc, x.name);
2870
+ writeCbor4(bc, x.args);
2226
2871
  }
2227
- function readToClientBody3(bc) {
2872
+ function readToClientBody4(bc) {
2228
2873
  const offset = bc.offset;
2229
- const tag = bare3.readU8(bc);
2874
+ const tag = bare4.readU8(bc);
2230
2875
  switch (tag) {
2231
2876
  case 0:
2232
- return { tag: "Init", val: readInit3(bc) };
2877
+ return { tag: "Init", val: readInit4(bc) };
2233
2878
  case 1:
2234
- return { tag: "Error", val: readError3(bc) };
2879
+ return { tag: "Error", val: readError4(bc) };
2235
2880
  case 2:
2236
- return { tag: "ActionResponse", val: readActionResponse3(bc) };
2881
+ return { tag: "ActionResponse", val: readActionResponse4(bc) };
2237
2882
  case 3:
2238
- return { tag: "Event", val: readEvent3(bc) };
2883
+ return { tag: "Event", val: readEvent4(bc) };
2239
2884
  default: {
2240
2885
  bc.offset = offset;
2241
- throw new bare3.BareError(offset, "invalid tag");
2886
+ throw new bare4.BareError(offset, "invalid tag");
2242
2887
  }
2243
2888
  }
2244
2889
  }
2245
- function writeToClientBody3(bc, x) {
2890
+ function writeToClientBody4(bc, x) {
2246
2891
  switch (x.tag) {
2247
2892
  case "Init": {
2248
- bare3.writeU8(bc, 0);
2249
- writeInit3(bc, x.val);
2893
+ bare4.writeU8(bc, 0);
2894
+ writeInit4(bc, x.val);
2250
2895
  break;
2251
2896
  }
2252
2897
  case "Error": {
2253
- bare3.writeU8(bc, 1);
2254
- writeError3(bc, x.val);
2898
+ bare4.writeU8(bc, 1);
2899
+ writeError4(bc, x.val);
2255
2900
  break;
2256
2901
  }
2257
2902
  case "ActionResponse": {
2258
- bare3.writeU8(bc, 2);
2259
- writeActionResponse3(bc, x.val);
2903
+ bare4.writeU8(bc, 2);
2904
+ writeActionResponse4(bc, x.val);
2260
2905
  break;
2261
2906
  }
2262
2907
  case "Event": {
2263
- bare3.writeU8(bc, 3);
2264
- writeEvent3(bc, x.val);
2908
+ bare4.writeU8(bc, 3);
2909
+ writeEvent4(bc, x.val);
2265
2910
  break;
2266
2911
  }
2267
2912
  }
2268
2913
  }
2269
- function readToClient3(bc) {
2914
+ function readToClient4(bc) {
2270
2915
  return {
2271
- body: readToClientBody3(bc)
2916
+ body: readToClientBody4(bc)
2272
2917
  };
2273
2918
  }
2274
- function writeToClient3(bc, x) {
2275
- writeToClientBody3(bc, x.body);
2919
+ function writeToClient4(bc, x) {
2920
+ writeToClientBody4(bc, x.body);
2276
2921
  }
2277
- function encodeToClient3(x, config) {
2278
- const fullConfig = config != null ? bare3.Config(config) : DEFAULT_CONFIG3;
2279
- const bc = new bare3.ByteCursor(
2922
+ function encodeToClient4(x, config) {
2923
+ const fullConfig = config != null ? bare4.Config(config) : DEFAULT_CONFIG4;
2924
+ const bc = new bare4.ByteCursor(
2280
2925
  new Uint8Array(fullConfig.initialBufferLength),
2281
2926
  fullConfig
2282
2927
  );
2283
- writeToClient3(bc, x);
2928
+ writeToClient4(bc, x);
2284
2929
  return new Uint8Array(bc.view.buffer, bc.view.byteOffset, bc.offset);
2285
2930
  }
2286
- function decodeToClient3(bytes) {
2287
- const bc = new bare3.ByteCursor(bytes, DEFAULT_CONFIG3);
2288
- const result = readToClient3(bc);
2931
+ function decodeToClient4(bytes) {
2932
+ const bc = new bare4.ByteCursor(bytes, DEFAULT_CONFIG4);
2933
+ const result = readToClient4(bc);
2289
2934
  if (bc.offset < bc.view.byteLength) {
2290
- throw new bare3.BareError(bc.offset, "remaining bytes");
2935
+ throw new bare4.BareError(bc.offset, "remaining bytes");
2291
2936
  }
2292
2937
  return result;
2293
2938
  }
2294
- function readActionRequest3(bc) {
2939
+ function readActionRequest4(bc) {
2295
2940
  return {
2296
- id: bare3.readUint(bc),
2297
- name: bare3.readString(bc),
2298
- args: readCbor3(bc)
2941
+ id: bare4.readUint(bc),
2942
+ name: bare4.readString(bc),
2943
+ args: readCbor4(bc)
2299
2944
  };
2300
2945
  }
2301
- function writeActionRequest3(bc, x) {
2302
- bare3.writeUint(bc, x.id);
2303
- bare3.writeString(bc, x.name);
2304
- writeCbor3(bc, x.args);
2946
+ function writeActionRequest4(bc, x) {
2947
+ bare4.writeUint(bc, x.id);
2948
+ bare4.writeString(bc, x.name);
2949
+ writeCbor4(bc, x.args);
2305
2950
  }
2306
- function readSubscriptionRequest3(bc) {
2951
+ function readSubscriptionRequest4(bc) {
2307
2952
  return {
2308
- eventName: bare3.readString(bc),
2309
- subscribe: bare3.readBool(bc)
2953
+ eventName: bare4.readString(bc),
2954
+ subscribe: bare4.readBool(bc)
2310
2955
  };
2311
2956
  }
2312
- function writeSubscriptionRequest3(bc, x) {
2313
- bare3.writeString(bc, x.eventName);
2314
- bare3.writeBool(bc, x.subscribe);
2957
+ function writeSubscriptionRequest4(bc, x) {
2958
+ bare4.writeString(bc, x.eventName);
2959
+ bare4.writeBool(bc, x.subscribe);
2315
2960
  }
2316
- function readToServerBody3(bc) {
2961
+ function readToServerBody4(bc) {
2317
2962
  const offset = bc.offset;
2318
- const tag = bare3.readU8(bc);
2963
+ const tag = bare4.readU8(bc);
2319
2964
  switch (tag) {
2320
2965
  case 0:
2321
- return { tag: "ActionRequest", val: readActionRequest3(bc) };
2966
+ return { tag: "ActionRequest", val: readActionRequest4(bc) };
2322
2967
  case 1:
2323
- return { tag: "SubscriptionRequest", val: readSubscriptionRequest3(bc) };
2968
+ return { tag: "SubscriptionRequest", val: readSubscriptionRequest4(bc) };
2324
2969
  default: {
2325
2970
  bc.offset = offset;
2326
- throw new bare3.BareError(offset, "invalid tag");
2971
+ throw new bare4.BareError(offset, "invalid tag");
2327
2972
  }
2328
2973
  }
2329
2974
  }
2330
- function writeToServerBody3(bc, x) {
2975
+ function writeToServerBody4(bc, x) {
2331
2976
  switch (x.tag) {
2332
2977
  case "ActionRequest": {
2333
- bare3.writeU8(bc, 0);
2334
- writeActionRequest3(bc, x.val);
2978
+ bare4.writeU8(bc, 0);
2979
+ writeActionRequest4(bc, x.val);
2335
2980
  break;
2336
2981
  }
2337
2982
  case "SubscriptionRequest": {
2338
- bare3.writeU8(bc, 1);
2339
- writeSubscriptionRequest3(bc, x.val);
2983
+ bare4.writeU8(bc, 1);
2984
+ writeSubscriptionRequest4(bc, x.val);
2340
2985
  break;
2341
2986
  }
2342
2987
  }
2343
2988
  }
2344
- function readToServer3(bc) {
2989
+ function readToServer4(bc) {
2345
2990
  return {
2346
- body: readToServerBody3(bc)
2991
+ body: readToServerBody4(bc)
2347
2992
  };
2348
2993
  }
2349
- function writeToServer3(bc, x) {
2350
- writeToServerBody3(bc, x.body);
2994
+ function writeToServer4(bc, x) {
2995
+ writeToServerBody4(bc, x.body);
2351
2996
  }
2352
- function encodeToServer3(x, config) {
2353
- const fullConfig = config != null ? bare3.Config(config) : DEFAULT_CONFIG3;
2354
- const bc = new bare3.ByteCursor(
2997
+ function encodeToServer4(x, config) {
2998
+ const fullConfig = config != null ? bare4.Config(config) : DEFAULT_CONFIG4;
2999
+ const bc = new bare4.ByteCursor(
2355
3000
  new Uint8Array(fullConfig.initialBufferLength),
2356
3001
  fullConfig
2357
3002
  );
2358
- writeToServer3(bc, x);
3003
+ writeToServer4(bc, x);
2359
3004
  return new Uint8Array(bc.view.buffer, bc.view.byteOffset, bc.offset);
2360
3005
  }
2361
- function decodeToServer3(bytes) {
2362
- const bc = new bare3.ByteCursor(bytes, DEFAULT_CONFIG3);
2363
- const result = readToServer3(bc);
3006
+ function decodeToServer4(bytes) {
3007
+ const bc = new bare4.ByteCursor(bytes, DEFAULT_CONFIG4);
3008
+ const result = readToServer4(bc);
2364
3009
  if (bc.offset < bc.view.byteLength) {
2365
- throw new bare3.BareError(bc.offset, "remaining bytes");
3010
+ throw new bare4.BareError(bc.offset, "remaining bytes");
2366
3011
  }
2367
3012
  return result;
2368
3013
  }
2369
- function readHttpActionRequest3(bc) {
3014
+ function readHttpActionRequest4(bc) {
2370
3015
  return {
2371
- args: readCbor3(bc)
3016
+ args: readCbor4(bc)
2372
3017
  };
2373
3018
  }
2374
- function writeHttpActionRequest3(bc, x) {
2375
- writeCbor3(bc, x.args);
3019
+ function writeHttpActionRequest4(bc, x) {
3020
+ writeCbor4(bc, x.args);
2376
3021
  }
2377
- function encodeHttpActionRequest3(x, config) {
2378
- const fullConfig = config != null ? bare3.Config(config) : DEFAULT_CONFIG3;
2379
- const bc = new bare3.ByteCursor(
3022
+ function encodeHttpActionRequest4(x, config) {
3023
+ const fullConfig = config != null ? bare4.Config(config) : DEFAULT_CONFIG4;
3024
+ const bc = new bare4.ByteCursor(
2380
3025
  new Uint8Array(fullConfig.initialBufferLength),
2381
3026
  fullConfig
2382
3027
  );
2383
- writeHttpActionRequest3(bc, x);
3028
+ writeHttpActionRequest4(bc, x);
2384
3029
  return new Uint8Array(bc.view.buffer, bc.view.byteOffset, bc.offset);
2385
3030
  }
2386
- function decodeHttpActionRequest3(bytes) {
2387
- const bc = new bare3.ByteCursor(bytes, DEFAULT_CONFIG3);
2388
- const result = readHttpActionRequest3(bc);
3031
+ function decodeHttpActionRequest4(bytes) {
3032
+ const bc = new bare4.ByteCursor(bytes, DEFAULT_CONFIG4);
3033
+ const result = readHttpActionRequest4(bc);
2389
3034
  if (bc.offset < bc.view.byteLength) {
2390
- throw new bare3.BareError(bc.offset, "remaining bytes");
3035
+ throw new bare4.BareError(bc.offset, "remaining bytes");
2391
3036
  }
2392
3037
  return result;
2393
3038
  }
2394
- function readHttpActionResponse3(bc) {
3039
+ function readHttpActionResponse4(bc) {
2395
3040
  return {
2396
- output: readCbor3(bc)
3041
+ output: readCbor4(bc)
2397
3042
  };
2398
3043
  }
2399
- function writeHttpActionResponse3(bc, x) {
2400
- writeCbor3(bc, x.output);
3044
+ function writeHttpActionResponse4(bc, x) {
3045
+ writeCbor4(bc, x.output);
2401
3046
  }
2402
- function encodeHttpActionResponse3(x, config) {
2403
- const fullConfig = config != null ? bare3.Config(config) : DEFAULT_CONFIG3;
2404
- const bc = new bare3.ByteCursor(
3047
+ function encodeHttpActionResponse4(x, config) {
3048
+ const fullConfig = config != null ? bare4.Config(config) : DEFAULT_CONFIG4;
3049
+ const bc = new bare4.ByteCursor(
2405
3050
  new Uint8Array(fullConfig.initialBufferLength),
2406
3051
  fullConfig
2407
3052
  );
2408
- writeHttpActionResponse3(bc, x);
3053
+ writeHttpActionResponse4(bc, x);
2409
3054
  return new Uint8Array(bc.view.buffer, bc.view.byteOffset, bc.offset);
2410
3055
  }
2411
- function decodeHttpActionResponse3(bytes) {
2412
- const bc = new bare3.ByteCursor(bytes, DEFAULT_CONFIG3);
2413
- const result = readHttpActionResponse3(bc);
3056
+ function decodeHttpActionResponse4(bytes) {
3057
+ const bc = new bare4.ByteCursor(bytes, DEFAULT_CONFIG4);
3058
+ const result = readHttpActionResponse4(bc);
2414
3059
  if (bc.offset < bc.view.byteLength) {
2415
- throw new bare3.BareError(bc.offset, "remaining bytes");
3060
+ throw new bare4.BareError(bc.offset, "remaining bytes");
2416
3061
  }
2417
3062
  return result;
2418
3063
  }
2419
- function read2(bc) {
2420
- return bare3.readBool(bc) ? bare3.readString(bc) : null;
2421
- }
2422
- function write2(bc, x) {
2423
- bare3.writeBool(bc, x != null);
2424
- if (x != null) {
2425
- bare3.writeString(bc, x);
2426
- }
2427
- }
2428
- function read3(bc) {
2429
- return bare3.readBool(bc) ? bare3.readBool(bc) : null;
3064
+ function read42(bc) {
3065
+ return bare4.readBool(bc) ? bare4.readBool(bc) : null;
2430
3066
  }
2431
- function write3(bc, x) {
2432
- bare3.writeBool(bc, x != null);
3067
+ function write42(bc, x) {
3068
+ bare4.writeBool(bc, x != null);
2433
3069
  if (x != null) {
2434
- bare3.writeBool(bc, x);
3070
+ bare4.writeBool(bc, x);
2435
3071
  }
2436
3072
  }
2437
- function read4(bc) {
2438
- return bare3.readBool(bc) ? bare3.readU64(bc) : null;
3073
+ function read5(bc) {
3074
+ return bare4.readBool(bc) ? bare4.readU64(bc) : null;
2439
3075
  }
2440
- function write4(bc, x) {
2441
- bare3.writeBool(bc, x != null);
3076
+ function write5(bc, x) {
3077
+ bare4.writeBool(bc, x != null);
2442
3078
  if (x != null) {
2443
- bare3.writeU64(bc, x);
3079
+ bare4.writeU64(bc, x);
2444
3080
  }
2445
3081
  }
2446
- function readHttpQueueSendRequest(bc) {
2447
- return {
2448
- body: readCbor3(bc),
2449
- name: read2(bc),
2450
- wait: read3(bc),
2451
- timeout: read4(bc)
3082
+ function readHttpQueueSendRequest2(bc) {
3083
+ return {
3084
+ body: readCbor4(bc),
3085
+ name: read04(bc),
3086
+ wait: read42(bc),
3087
+ timeout: read5(bc)
2452
3088
  };
2453
3089
  }
2454
- function writeHttpQueueSendRequest(bc, x) {
2455
- writeCbor3(bc, x.body);
2456
- write2(bc, x.name);
2457
- write3(bc, x.wait);
2458
- write4(bc, x.timeout);
3090
+ function writeHttpQueueSendRequest2(bc, x) {
3091
+ writeCbor4(bc, x.body);
3092
+ write04(bc, x.name);
3093
+ write42(bc, x.wait);
3094
+ write5(bc, x.timeout);
2459
3095
  }
2460
- function encodeHttpQueueSendRequest(x, config) {
2461
- const fullConfig = config != null ? bare3.Config(config) : DEFAULT_CONFIG3;
2462
- const bc = new bare3.ByteCursor(
3096
+ function encodeHttpQueueSendRequest2(x, config) {
3097
+ const fullConfig = config != null ? bare4.Config(config) : DEFAULT_CONFIG4;
3098
+ const bc = new bare4.ByteCursor(
2463
3099
  new Uint8Array(fullConfig.initialBufferLength),
2464
3100
  fullConfig
2465
3101
  );
2466
- writeHttpQueueSendRequest(bc, x);
3102
+ writeHttpQueueSendRequest2(bc, x);
2467
3103
  return new Uint8Array(bc.view.buffer, bc.view.byteOffset, bc.offset);
2468
3104
  }
2469
- function decodeHttpQueueSendRequest(bytes) {
2470
- const bc = new bare3.ByteCursor(bytes, DEFAULT_CONFIG3);
2471
- const result = readHttpQueueSendRequest(bc);
3105
+ function decodeHttpQueueSendRequest2(bytes) {
3106
+ const bc = new bare4.ByteCursor(bytes, DEFAULT_CONFIG4);
3107
+ const result = readHttpQueueSendRequest2(bc);
2472
3108
  if (bc.offset < bc.view.byteLength) {
2473
- throw new bare3.BareError(bc.offset, "remaining bytes");
3109
+ throw new bare4.BareError(bc.offset, "remaining bytes");
2474
3110
  }
2475
3111
  return result;
2476
3112
  }
2477
- function readHttpQueueSendResponse(bc) {
3113
+ function readHttpQueueSendResponse2(bc) {
2478
3114
  return {
2479
- status: bare3.readString(bc),
2480
- response: read03(bc)
3115
+ status: bare4.readString(bc),
3116
+ response: read14(bc)
2481
3117
  };
2482
3118
  }
2483
- function writeHttpQueueSendResponse(bc, x) {
2484
- bare3.writeString(bc, x.status);
2485
- write03(bc, x.response);
3119
+ function writeHttpQueueSendResponse2(bc, x) {
3120
+ bare4.writeString(bc, x.status);
3121
+ write14(bc, x.response);
2486
3122
  }
2487
- function encodeHttpQueueSendResponse(x, config) {
2488
- const fullConfig = config != null ? bare3.Config(config) : DEFAULT_CONFIG3;
2489
- const bc = new bare3.ByteCursor(
3123
+ function encodeHttpQueueSendResponse2(x, config) {
3124
+ const fullConfig = config != null ? bare4.Config(config) : DEFAULT_CONFIG4;
3125
+ const bc = new bare4.ByteCursor(
2490
3126
  new Uint8Array(fullConfig.initialBufferLength),
2491
3127
  fullConfig
2492
3128
  );
2493
- writeHttpQueueSendResponse(bc, x);
3129
+ writeHttpQueueSendResponse2(bc, x);
2494
3130
  return new Uint8Array(bc.view.buffer, bc.view.byteOffset, bc.offset);
2495
3131
  }
2496
- function decodeHttpQueueSendResponse(bytes) {
2497
- const bc = new bare3.ByteCursor(bytes, DEFAULT_CONFIG3);
2498
- const result = readHttpQueueSendResponse(bc);
3132
+ function decodeHttpQueueSendResponse2(bytes) {
3133
+ const bc = new bare4.ByteCursor(bytes, DEFAULT_CONFIG4);
3134
+ const result = readHttpQueueSendResponse2(bc);
2499
3135
  if (bc.offset < bc.view.byteLength) {
2500
- throw new bare3.BareError(bc.offset, "remaining bytes");
3136
+ throw new bare4.BareError(bc.offset, "remaining bytes");
2501
3137
  }
2502
3138
  return result;
2503
3139
  }
2504
- function readHttpResponseError3(bc) {
3140
+ function readHttpResponseError4(bc) {
2505
3141
  return {
2506
- group: bare3.readString(bc),
2507
- code: bare3.readString(bc),
2508
- message: bare3.readString(bc),
2509
- metadata: read03(bc)
3142
+ group: bare4.readString(bc),
3143
+ code: bare4.readString(bc),
3144
+ message: bare4.readString(bc),
3145
+ metadata: read14(bc),
3146
+ actor: read32(bc)
2510
3147
  };
2511
3148
  }
2512
- function writeHttpResponseError3(bc, x) {
2513
- bare3.writeString(bc, x.group);
2514
- bare3.writeString(bc, x.code);
2515
- bare3.writeString(bc, x.message);
2516
- write03(bc, x.metadata);
3149
+ function writeHttpResponseError4(bc, x) {
3150
+ bare4.writeString(bc, x.group);
3151
+ bare4.writeString(bc, x.code);
3152
+ bare4.writeString(bc, x.message);
3153
+ write14(bc, x.metadata);
3154
+ write32(bc, x.actor);
2517
3155
  }
2518
- function encodeHttpResponseError3(x, config) {
2519
- const fullConfig = config != null ? bare3.Config(config) : DEFAULT_CONFIG3;
2520
- const bc = new bare3.ByteCursor(
3156
+ function encodeHttpResponseError4(x, config) {
3157
+ const fullConfig = config != null ? bare4.Config(config) : DEFAULT_CONFIG4;
3158
+ const bc = new bare4.ByteCursor(
2521
3159
  new Uint8Array(fullConfig.initialBufferLength),
2522
3160
  fullConfig
2523
3161
  );
2524
- writeHttpResponseError3(bc, x);
3162
+ writeHttpResponseError4(bc, x);
2525
3163
  return new Uint8Array(bc.view.buffer, bc.view.byteOffset, bc.offset);
2526
3164
  }
2527
- function decodeHttpResponseError3(bytes) {
2528
- const bc = new bare3.ByteCursor(bytes, DEFAULT_CONFIG3);
2529
- const result = readHttpResponseError3(bc);
3165
+ function decodeHttpResponseError4(bytes) {
3166
+ const bc = new bare4.ByteCursor(bytes, DEFAULT_CONFIG4);
3167
+ const result = readHttpResponseError4(bc);
2530
3168
  if (bc.offset < bc.view.byteLength) {
2531
- throw new bare3.BareError(bc.offset, "remaining bytes");
3169
+ throw new bare4.BareError(bc.offset, "remaining bytes");
2532
3170
  }
2533
3171
  return result;
2534
3172
  }
2535
- function readHttpResolveResponse3(bc) {
3173
+ function readHttpResolveResponse4(bc) {
2536
3174
  return {
2537
- actorId: bare3.readString(bc)
3175
+ actorId: bare4.readString(bc)
2538
3176
  };
2539
3177
  }
2540
- function writeHttpResolveResponse3(bc, x) {
2541
- bare3.writeString(bc, x.actorId);
3178
+ function writeHttpResolveResponse4(bc, x) {
3179
+ bare4.writeString(bc, x.actorId);
2542
3180
  }
2543
- function encodeHttpResolveResponse3(x, config) {
2544
- const fullConfig = config != null ? bare3.Config(config) : DEFAULT_CONFIG3;
2545
- const bc = new bare3.ByteCursor(
3181
+ function encodeHttpResolveResponse4(x, config) {
3182
+ const fullConfig = config != null ? bare4.Config(config) : DEFAULT_CONFIG4;
3183
+ const bc = new bare4.ByteCursor(
2546
3184
  new Uint8Array(fullConfig.initialBufferLength),
2547
3185
  fullConfig
2548
3186
  );
2549
- writeHttpResolveResponse3(bc, x);
3187
+ writeHttpResolveResponse4(bc, x);
2550
3188
  return new Uint8Array(bc.view.buffer, bc.view.byteOffset, bc.offset);
2551
3189
  }
2552
- function decodeHttpResolveResponse3(bytes) {
2553
- const bc = new bare3.ByteCursor(bytes, DEFAULT_CONFIG3);
2554
- const result = readHttpResolveResponse3(bc);
3190
+ function decodeHttpResolveResponse4(bytes) {
3191
+ const bc = new bare4.ByteCursor(bytes, DEFAULT_CONFIG4);
3192
+ const result = readHttpResolveResponse4(bc);
2555
3193
  if (bc.offset < bc.view.byteLength) {
2556
- throw new bare3.BareError(bc.offset, "remaining bytes");
3194
+ throw new bare4.BareError(bc.offset, "remaining bytes");
2557
3195
  }
2558
3196
  return result;
2559
3197
  }
2560
3198
 
2561
3199
  // src/common/client-protocol-versioned.ts
2562
- var CURRENT_VERSION = 3;
3200
+ var CURRENT_VERSION = 4;
2563
3201
  var v1ToV2 = (v1Data) => {
2564
3202
  if (v1Data.body.tag === "Init") {
2565
3203
  const { actorId, connectionId } = v1Data.body.val;
@@ -2595,6 +3233,32 @@ var v2ToV1 = (v2Data) => {
2595
3233
  var v2ToV3 = (v2Data) => {
2596
3234
  return v2Data;
2597
3235
  };
3236
+ var v3ToV4 = (v3Data) => {
3237
+ if (v3Data.body.tag === "Error") {
3238
+ return {
3239
+ body: {
3240
+ tag: "Error",
3241
+ val: {
3242
+ ...v3Data.body.val,
3243
+ actor: null
3244
+ }
3245
+ }
3246
+ };
3247
+ }
3248
+ return v3Data;
3249
+ };
3250
+ var v4ToV3 = (v4Data) => {
3251
+ if (v4Data.body.tag === "Error") {
3252
+ const { actor: _, ...val } = v4Data.body.val;
3253
+ return {
3254
+ body: {
3255
+ tag: "Error",
3256
+ val
3257
+ }
3258
+ };
3259
+ }
3260
+ return v4Data;
3261
+ };
2598
3262
  var v3ToV2 = (v3Data) => {
2599
3263
  return v3Data;
2600
3264
  };
@@ -2604,12 +3268,26 @@ var v1ToServerV2 = (v1Data) => {
2604
3268
  var v2ToServerV3 = (v2Data) => {
2605
3269
  return v2Data;
2606
3270
  };
3271
+ var v3ToServerV4 = (v3Data) => {
3272
+ return v3Data;
3273
+ };
3274
+ var v4ToServerV3 = (v4Data) => {
3275
+ return v4Data;
3276
+ };
2607
3277
  var v3ToServerV2 = (v3Data) => {
2608
3278
  return v3Data;
2609
3279
  };
2610
3280
  var v2ToServerV1 = (v2Data) => {
2611
3281
  return v2Data;
2612
3282
  };
3283
+ var v3HttpResponseErrorToV4 = (v3Data) => ({
3284
+ ...v3Data,
3285
+ actor: null
3286
+ });
3287
+ var v4HttpResponseErrorToV3 = (v4Data) => {
3288
+ const { actor: _, ...rest } = v4Data;
3289
+ return rest;
3290
+ };
2613
3291
  var CLIENT_PROTOCOL_TO_SERVER = createVersionedDataHandler({
2614
3292
  deserializeVersion: (bytes, version) => {
2615
3293
  switch (version) {
@@ -2619,6 +3297,8 @@ var CLIENT_PROTOCOL_TO_SERVER = createVersionedDataHandler({
2619
3297
  return decodeToServer2(bytes);
2620
3298
  case 3:
2621
3299
  return decodeToServer3(bytes);
3300
+ case 4:
3301
+ return decodeToServer4(bytes);
2622
3302
  default:
2623
3303
  throw new Error(`Unknown version ${version}`);
2624
3304
  }
@@ -2631,12 +3311,14 @@ var CLIENT_PROTOCOL_TO_SERVER = createVersionedDataHandler({
2631
3311
  return encodeToServer2(data);
2632
3312
  case 3:
2633
3313
  return encodeToServer3(data);
3314
+ case 4:
3315
+ return encodeToServer4(data);
2634
3316
  default:
2635
3317
  throw new Error(`Unknown version ${version}`);
2636
3318
  }
2637
3319
  },
2638
- deserializeConverters: () => [v1ToServerV2, v2ToServerV3],
2639
- serializeConverters: () => [v3ToServerV2, v2ToServerV1]
3320
+ deserializeConverters: () => [v1ToServerV2, v2ToServerV3, v3ToServerV4],
3321
+ serializeConverters: () => [v4ToServerV3, v3ToServerV2, v2ToServerV1]
2640
3322
  });
2641
3323
  var CLIENT_PROTOCOL_TO_CLIENT = createVersionedDataHandler({
2642
3324
  deserializeVersion: (bytes, version) => {
@@ -2647,6 +3329,8 @@ var CLIENT_PROTOCOL_TO_CLIENT = createVersionedDataHandler({
2647
3329
  return decodeToClient2(bytes);
2648
3330
  case 3:
2649
3331
  return decodeToClient3(bytes);
3332
+ case 4:
3333
+ return decodeToClient4(bytes);
2650
3334
  default:
2651
3335
  throw new Error(`Unknown version ${version}`);
2652
3336
  }
@@ -2659,12 +3343,14 @@ var CLIENT_PROTOCOL_TO_CLIENT = createVersionedDataHandler({
2659
3343
  return encodeToClient2(data);
2660
3344
  case 3:
2661
3345
  return encodeToClient3(data);
3346
+ case 4:
3347
+ return encodeToClient4(data);
2662
3348
  default:
2663
3349
  throw new Error(`Unknown version ${version}`);
2664
3350
  }
2665
3351
  },
2666
- deserializeConverters: () => [v1ToV2, v2ToV3],
2667
- serializeConverters: () => [v3ToV2, v2ToV1]
3352
+ deserializeConverters: () => [v1ToV2, v2ToV3, v3ToV4],
3353
+ serializeConverters: () => [v4ToV3, v3ToV2, v2ToV1]
2668
3354
  });
2669
3355
  var HTTP_ACTION_REQUEST_VERSIONED = createVersionedDataHandler({
2670
3356
  deserializeVersion: (bytes, version) => {
@@ -2675,6 +3361,8 @@ var HTTP_ACTION_REQUEST_VERSIONED = createVersionedDataHandler({
2675
3361
  return decodeHttpActionRequest2(bytes);
2676
3362
  case 3:
2677
3363
  return decodeHttpActionRequest3(bytes);
3364
+ case 4:
3365
+ return decodeHttpActionRequest4(bytes);
2678
3366
  default:
2679
3367
  throw new Error(`Unknown version ${version}`);
2680
3368
  }
@@ -2693,6 +3381,10 @@ var HTTP_ACTION_REQUEST_VERSIONED = createVersionedDataHandler({
2693
3381
  return encodeHttpActionRequest3(
2694
3382
  data
2695
3383
  );
3384
+ case 4:
3385
+ return encodeHttpActionRequest4(
3386
+ data
3387
+ );
2696
3388
  default:
2697
3389
  throw new Error(`Unknown version ${version}`);
2698
3390
  }
@@ -2709,6 +3401,8 @@ var HTTP_ACTION_RESPONSE_VERSIONED = createVersionedDataHandler({
2709
3401
  return decodeHttpActionResponse2(bytes);
2710
3402
  case 3:
2711
3403
  return decodeHttpActionResponse3(bytes);
3404
+ case 4:
3405
+ return decodeHttpActionResponse4(bytes);
2712
3406
  default:
2713
3407
  throw new Error(`Unknown version ${version}`);
2714
3408
  }
@@ -2727,6 +3421,10 @@ var HTTP_ACTION_RESPONSE_VERSIONED = createVersionedDataHandler({
2727
3421
  return encodeHttpActionResponse3(
2728
3422
  data
2729
3423
  );
3424
+ case 4:
3425
+ return encodeHttpActionResponse4(
3426
+ data
3427
+ );
2730
3428
  default:
2731
3429
  throw new Error(`Unknown version ${version}`);
2732
3430
  }
@@ -2739,6 +3437,8 @@ var HTTP_QUEUE_SEND_REQUEST_VERSIONED = createVersionedDataHandler({
2739
3437
  switch (version) {
2740
3438
  case 3:
2741
3439
  return decodeHttpQueueSendRequest(bytes);
3440
+ case 4:
3441
+ return decodeHttpQueueSendRequest2(bytes);
2742
3442
  default:
2743
3443
  throw new Error(
2744
3444
  `HttpQueueSendRequest only exists in version 3+, got version ${version}`
@@ -2751,6 +3451,10 @@ var HTTP_QUEUE_SEND_REQUEST_VERSIONED = createVersionedDataHandler({
2751
3451
  return encodeHttpQueueSendRequest(
2752
3452
  data
2753
3453
  );
3454
+ case 4:
3455
+ return encodeHttpQueueSendRequest2(
3456
+ data
3457
+ );
2754
3458
  default:
2755
3459
  throw new Error(
2756
3460
  `HttpQueueSendRequest only exists in version 3+, got version ${version}`
@@ -2765,6 +3469,8 @@ var HTTP_QUEUE_SEND_RESPONSE_VERSIONED = createVersionedDataHandler({
2765
3469
  switch (version) {
2766
3470
  case 3:
2767
3471
  return decodeHttpQueueSendResponse(bytes);
3472
+ case 4:
3473
+ return decodeHttpQueueSendResponse2(bytes);
2768
3474
  default:
2769
3475
  throw new Error(
2770
3476
  `HttpQueueSendResponse only exists in version 3+, got version ${version}`
@@ -2777,6 +3483,10 @@ var HTTP_QUEUE_SEND_RESPONSE_VERSIONED = createVersionedDataHandler({
2777
3483
  return encodeHttpQueueSendResponse(
2778
3484
  data
2779
3485
  );
3486
+ case 4:
3487
+ return encodeHttpQueueSendResponse2(
3488
+ data
3489
+ );
2780
3490
  default:
2781
3491
  throw new Error(
2782
3492
  `HttpQueueSendResponse only exists in version 3+, got version ${version}`
@@ -2795,6 +3505,8 @@ var HTTP_RESPONSE_ERROR_VERSIONED = createVersionedDataHandler({
2795
3505
  return decodeHttpResponseError2(bytes);
2796
3506
  case 3:
2797
3507
  return decodeHttpResponseError3(bytes);
3508
+ case 4:
3509
+ return decodeHttpResponseError4(bytes);
2798
3510
  default:
2799
3511
  throw new Error(`Unknown version ${version}`);
2800
3512
  }
@@ -2813,12 +3525,24 @@ var HTTP_RESPONSE_ERROR_VERSIONED = createVersionedDataHandler({
2813
3525
  return encodeHttpResponseError3(
2814
3526
  data
2815
3527
  );
3528
+ case 4:
3529
+ return encodeHttpResponseError4(
3530
+ data
3531
+ );
2816
3532
  default:
2817
3533
  throw new Error(`Unknown version ${version}`);
2818
3534
  }
2819
3535
  },
2820
- deserializeConverters: () => [],
2821
- serializeConverters: () => []
3536
+ deserializeConverters: () => [
3537
+ (data) => data,
3538
+ (data) => data,
3539
+ v3HttpResponseErrorToV4
3540
+ ],
3541
+ serializeConverters: () => [
3542
+ v4HttpResponseErrorToV3,
3543
+ (data) => data,
3544
+ (data) => data
3545
+ ]
2822
3546
  });
2823
3547
  var HTTP_RESOLVE_RESPONSE_VERSIONED = createVersionedDataHandler({
2824
3548
  deserializeVersion: (bytes, version) => {
@@ -2829,6 +3553,8 @@ var HTTP_RESOLVE_RESPONSE_VERSIONED = createVersionedDataHandler({
2829
3553
  return decodeHttpResolveResponse2(bytes);
2830
3554
  case 3:
2831
3555
  return decodeHttpResolveResponse3(bytes);
3556
+ case 4:
3557
+ return decodeHttpResolveResponse4(bytes);
2832
3558
  default:
2833
3559
  throw new Error(`Unknown version ${version}`);
2834
3560
  }
@@ -2847,6 +3573,10 @@ var HTTP_RESOLVE_RESPONSE_VERSIONED = createVersionedDataHandler({
2847
3573
  return encodeHttpResolveResponse3(
2848
3574
  data
2849
3575
  );
3576
+ case 4:
3577
+ return encodeHttpResolveResponse4(
3578
+ data
3579
+ );
2850
3580
  default:
2851
3581
  throw new Error(`Unknown version ${version}`);
2852
3582
  }
@@ -2859,6 +3589,11 @@ var HTTP_RESOLVE_RESPONSE_VERSIONED = createVersionedDataHandler({
2859
3589
  import { z as z4 } from "zod/v4";
2860
3590
  var UintSchema = z4.bigint();
2861
3591
  var OptionalUintSchema = UintSchema.nullable();
3592
+ var ActorSpecifierSchema = z4.object({
3593
+ actorId: z4.string(),
3594
+ generation: z4.union([z4.number(), z4.bigint()]),
3595
+ key: z4.string().optional()
3596
+ });
2862
3597
  var InitSchema = z4.object({
2863
3598
  actorId: z4.string(),
2864
3599
  connectionId: z4.string()
@@ -2868,7 +3603,8 @@ var ErrorSchema = z4.object({
2868
3603
  code: z4.string(),
2869
3604
  message: z4.string(),
2870
3605
  metadata: z4.unknown().optional(),
2871
- actionId: OptionalUintSchema
3606
+ actionId: OptionalUintSchema,
3607
+ actor: ActorSpecifierSchema.optional()
2872
3608
  });
2873
3609
  var ActionResponseSchema = z4.object({
2874
3610
  id: UintSchema,
@@ -2926,7 +3662,8 @@ var HttpResponseErrorSchema = z4.object({
2926
3662
  group: z4.string(),
2927
3663
  code: z4.string(),
2928
3664
  message: z4.string(),
2929
- metadata: z4.unknown().optional()
3665
+ metadata: z4.unknown().optional(),
3666
+ actor: ActorSpecifierSchema.optional()
2930
3667
  });
2931
3668
  var HttpResolveRequestSchema = z4.null();
2932
3669
  var HttpResolveResponseSchema = z4.object({
@@ -2959,12 +3696,12 @@ var ActorConnDisposed = class extends ActorClientError {
2959
3696
  function isSchedulingError(group, code) {
2960
3697
  return group === "guard" && (code === "actor_ready_timeout" || code === "actor_runner_failed");
2961
3698
  }
2962
- function actorSchedulingError(group, code, actorId, details) {
3699
+ function actorSchedulingError(group, code, actorId, details, rayId) {
2963
3700
  return new RivetError(
2964
3701
  group,
2965
3702
  code,
2966
3703
  `Actor failed to start (${actorId}): ${JSON.stringify(details)}`,
2967
- { metadata: { actorId, details } }
3704
+ { metadata: { actorId, details }, rayId }
2968
3705
  );
2969
3706
  }
2970
3707
  function internalClientError(message, opts) {
@@ -3056,21 +3793,47 @@ async function sendHttpRequest(opts) {
3056
3793
  new Uint8Array(bufferResponse),
3057
3794
  HTTP_RESPONSE_ERROR_VERSIONED,
3058
3795
  HttpResponseErrorSchema,
3059
- // JSON: metadata is already unknown
3060
- (json) => json,
3796
+ // JSON/CBOR: normalize actor generation to the public number shape.
3797
+ (json) => ({
3798
+ ...json,
3799
+ actor: json.actor ? {
3800
+ ...json.actor,
3801
+ generation: Number(json.actor.generation)
3802
+ } : void 0
3803
+ }),
3061
3804
  // BARE: decode ArrayBuffer metadata to unknown
3062
- (bare4) => ({
3063
- group: bare4.group,
3064
- code: bare4.code,
3065
- message: bare4.message,
3066
- metadata: bare4.metadata ? decodeCborCompat(new Uint8Array(bare4.metadata)) : void 0
3805
+ (bare5) => ({
3806
+ group: bare5.group,
3807
+ code: bare5.code,
3808
+ message: bare5.message,
3809
+ metadata: bare5.metadata ? decodeCborCompat(new Uint8Array(bare5.metadata)) : void 0,
3810
+ actor: bare5.actor ? {
3811
+ actorId: bare5.actor.actorId,
3812
+ generation: Number(bare5.actor.generation),
3813
+ key: bare5.actor.key ?? void 0
3814
+ } : void 0
3067
3815
  })
3068
3816
  );
3817
+ logger2().warn({
3818
+ msg: "http error response",
3819
+ group: responseData.group,
3820
+ code: responseData.code,
3821
+ message: responseData.message,
3822
+ metadata: responseData.metadata,
3823
+ rayId,
3824
+ actorId: responseData.actor?.actorId,
3825
+ generation: responseData.actor?.generation,
3826
+ actorKey: responseData.actor?.key
3827
+ });
3069
3828
  throw new RivetError(
3070
3829
  responseData.group,
3071
3830
  responseData.code,
3072
3831
  responseData.message,
3073
- responseData.metadata
3832
+ {
3833
+ metadata: responseData.metadata,
3834
+ rayId: rayId ?? void 0,
3835
+ actor: responseData.actor
3836
+ }
3074
3837
  );
3075
3838
  } catch (error) {
3076
3839
  if (error instanceof RivetError) {
@@ -3198,13 +3961,6 @@ async function destroyActor(config, actorId) {
3198
3961
  async function getMetadata(config) {
3199
3962
  return apiCall(config, "GET", `/metadata`);
3200
3963
  }
3201
- async function kvGet(config, actorId, key) {
3202
- return apiCall(
3203
- config,
3204
- "GET",
3205
- `/actors/${encodeURIComponent(actorId)}/kv/keys/${encodeURIComponent(key)}`
3206
- );
3207
- }
3208
3964
 
3209
3965
  // src/engine-client/metadata.ts
3210
3966
  import pRetry from "p-retry";
@@ -3250,11 +4006,11 @@ async function lookupMetadataCached(config) {
3250
4006
  }
3251
4007
 
3252
4008
  // src/engine-client/ws-proxy.ts
3253
- async function createWebSocketProxy(c, targetUrl, protocols) {
4009
+ async function createWebSocketProxy(_c, targetUrl, protocols) {
3254
4010
  const WebSocket2 = await importWebSocket();
3255
4011
  const state = {};
3256
4012
  return {
3257
- onOpen: async (event, clientWs) => {
4013
+ onOpen: async (_event, clientWs) => {
3258
4014
  logger3().debug({ msg: "client websocket connected", targetUrl });
3259
4015
  if (clientWs.readyState !== 1) {
3260
4016
  logger3().warn({
@@ -3292,23 +4048,25 @@ async function createWebSocketProxy(c, targetUrl, protocols) {
3292
4048
  reject(error);
3293
4049
  });
3294
4050
  });
3295
- state.targetWs.addEventListener("message", (event2) => {
3296
- if (typeof event2.data === "string" || event2.data instanceof ArrayBuffer) {
3297
- clientWs.send(event2.data);
3298
- } else if (event2.data instanceof Blob) {
3299
- event2.data.arrayBuffer().then((buffer) => {
4051
+ state.connectPromise.catch(() => {
4052
+ });
4053
+ state.targetWs.addEventListener("message", (event) => {
4054
+ if (typeof event.data === "string" || event.data instanceof ArrayBuffer) {
4055
+ clientWs.send(event.data);
4056
+ } else if (event.data instanceof Blob) {
4057
+ event.data.arrayBuffer().then((buffer) => {
3300
4058
  clientWs.send(buffer);
3301
4059
  });
3302
4060
  }
3303
4061
  });
3304
- state.targetWs.addEventListener("close", (event2) => {
4062
+ state.targetWs.addEventListener("close", (event) => {
3305
4063
  logger3().debug({
3306
4064
  msg: "target websocket closed",
3307
4065
  targetUrl,
3308
- code: event2.code,
3309
- reason: event2.reason
4066
+ code: event.code,
4067
+ reason: event.reason
3310
4068
  });
3311
- closeWebSocketIfOpen(clientWs, event2.code, event2.reason);
4069
+ closeWebSocketIfOpen(clientWs, event.code, event.reason);
3312
4070
  });
3313
4071
  state.targetWs.addEventListener("error", (error) => {
3314
4072
  logger3().error({
@@ -3351,7 +4109,7 @@ async function createWebSocketProxy(c, targetUrl, protocols) {
3351
4109
  );
3352
4110
  }
3353
4111
  },
3354
- onClose: (event, clientWs) => {
4112
+ onClose: (event, _clientWs) => {
3355
4113
  logger3().debug({
3356
4114
  msg: "client websocket closed",
3357
4115
  targetUrl,
@@ -3368,7 +4126,7 @@ async function createWebSocketProxy(c, targetUrl, protocols) {
3368
4126
  }
3369
4127
  }
3370
4128
  },
3371
- onError: (event, clientWs) => {
4129
+ onError: (event, _clientWs) => {
3372
4130
  logger3().error({ msg: "client websocket error", targetUrl, event });
3373
4131
  if (state.targetWs) {
3374
4132
  if (state.targetWs.readyState === WebSocket2.OPEN) {
@@ -3473,7 +4231,14 @@ var RemoteEngineControlClient = class {
3473
4231
  }
3474
4232
  async getOrCreateWithKey(input) {
3475
4233
  await this.#metadataPromise;
3476
- const { name, key, input: actorInput, region, crashPolicy } = input;
4234
+ const {
4235
+ name,
4236
+ key,
4237
+ input: actorInput,
4238
+ region,
4239
+ crashPolicy,
4240
+ poolName
4241
+ } = input;
3477
4242
  logger3().info({
3478
4243
  msg: "getOrCreateWithKey: getting or creating actor via engine api",
3479
4244
  name,
@@ -3483,8 +4248,10 @@ var RemoteEngineControlClient = class {
3483
4248
  datacenter: region,
3484
4249
  name,
3485
4250
  key: serializeActorKey(key),
3486
- runner_name_selector: this.#config.poolName,
3487
- input: actorInput ? uint8ArrayToBase64(encodeCborCompat(actorInput)) : void 0,
4251
+ runner_name_selector: poolName ?? this.#config.poolName,
4252
+ input: actorInput ? uint8ArrayToBase64(
4253
+ encodeCborCompat(actorInput)
4254
+ ) : void 0,
3488
4255
  crash_policy: crashPolicy ?? "sleep"
3489
4256
  });
3490
4257
  logger3().info({
@@ -3501,14 +4268,15 @@ var RemoteEngineControlClient = class {
3501
4268
  key,
3502
4269
  input,
3503
4270
  region,
3504
- crashPolicy
4271
+ crashPolicy,
4272
+ poolName
3505
4273
  }) {
3506
4274
  await this.#metadataPromise;
3507
4275
  logger3().info({ msg: "creating actor via engine api", name, key });
3508
4276
  const result = await createActor(this.#config, {
3509
4277
  datacenter: region,
3510
4278
  name,
3511
- runner_name_selector: this.#config.poolName,
4279
+ runner_name_selector: poolName ?? this.#config.poolName,
3512
4280
  key: serializeActorKey(key),
3513
4281
  input: input ? uint8ArrayToBase64(encodeCborCompat(input)) : void 0,
3514
4282
  crash_policy: crashPolicy ?? "sleep"
@@ -3533,27 +4301,46 @@ var RemoteEngineControlClient = class {
3533
4301
  await destroyActor(this.#config, actorId);
3534
4302
  logger3().info({ msg: "actor destroyed", actorId });
3535
4303
  }
3536
- async sendRequest(target, actorRequest) {
4304
+ async sendRequest(target, actorRequest, options = {}) {
3537
4305
  await this.#metadataPromise;
4306
+ const path = requestPath(actorRequest);
3538
4307
  const gatewayUrl = this.#buildGatewayUrlForTarget(
3539
4308
  target,
3540
- requestPath(actorRequest)
4309
+ path,
4310
+ options
4311
+ );
4312
+ const httpOptions = {
4313
+ ...options,
4314
+ directActorId: shouldSkipReadyWait(options) ? directActorIdFromTarget(target) : void 0
4315
+ };
4316
+ return sendHttpRequestToGateway(
4317
+ this.#config,
4318
+ gatewayUrl,
4319
+ actorRequest,
4320
+ httpOptions
3541
4321
  );
3542
- return sendHttpRequestToGateway(this.#config, gatewayUrl, actorRequest);
3543
4322
  }
3544
- async openWebSocket(path, target, encoding, params) {
4323
+ async openWebSocket(path, target, encoding, params, options = {}) {
3545
4324
  await this.#metadataPromise;
3546
- const gatewayUrl = this.#buildGatewayUrlForTarget(target, path);
4325
+ const gatewayUrl = this.#buildGatewayUrlForTarget(
4326
+ target,
4327
+ path,
4328
+ options
4329
+ );
3547
4330
  return openWebSocketToGateway(
3548
4331
  this.#config,
3549
4332
  gatewayUrl,
3550
4333
  encoding,
3551
- params
4334
+ params,
4335
+ {
4336
+ ...options,
4337
+ directActorId: shouldSkipReadyWait(options) ? directActorIdFromTarget(target) : void 0
4338
+ }
3552
4339
  );
3553
4340
  }
3554
- async buildGatewayUrl(target) {
4341
+ async buildGatewayUrl(target, options = {}) {
3555
4342
  await this.#metadataPromise;
3556
- return this.#buildGatewayUrlForTarget(target, "");
4343
+ return this.#buildGatewayUrlForTarget(target, "", options);
3557
4344
  }
3558
4345
  async proxyRequest(_c, actorRequest, actorId) {
3559
4346
  await this.#metadataPromise;
@@ -3589,36 +4376,17 @@ var RemoteEngineControlClient = class {
3589
4376
  const args = await createWebSocketProxy(c, wsGuardUrl, protocols);
3590
4377
  return await upgradeWebSocket(() => args)(c, noopNext());
3591
4378
  }
3592
- async kvGet(actorId, key) {
3593
- await this.#metadataPromise;
3594
- logger3().debug({ msg: "getting kv value via engine api", key });
3595
- const response = await kvGet(
3596
- this.#config,
3597
- actorId,
3598
- new TextDecoder("utf8").decode(key)
3599
- );
3600
- return response.value;
3601
- }
3602
- async kvBatchGet(_actorId, _keys) {
3603
- throw new Error("kvBatchGet not supported on remote engine client");
3604
- }
3605
- async kvBatchPut(_actorId, _entries) {
3606
- throw new Error("kvBatchPut not supported on remote engine client");
3607
- }
3608
- async kvBatchDelete(_actorId, _keys) {
3609
- throw new Error("kvBatchDelete not supported on remote engine client");
3610
- }
3611
- async kvDeleteRange(_actorId, _start, _end) {
3612
- throw new Error("kvDeleteRange not supported on remote engine client");
3613
- }
3614
4379
  displayInformation() {
3615
4380
  return { properties: {} };
3616
4381
  }
3617
4382
  setGetUpgradeWebSocket(getUpgradeWebSocket) {
3618
4383
  this.#config.getUpgradeWebSocket = getUpgradeWebSocket;
3619
4384
  }
3620
- #buildGatewayUrlForTarget(target, path) {
4385
+ #buildGatewayUrlForTarget(target, path, options = {}) {
3621
4386
  const endpoint = getEndpoint(this.#config);
4387
+ if (shouldSkipReadyWait(options) && directActorIdFromTarget(target) && canUseDirectSkipReadyWaitPath(path)) {
4388
+ return combineUrlPath(endpoint, path);
4389
+ }
3622
4390
  if ("directId" in target) {
3623
4391
  return buildActorGatewayUrl(
3624
4392
  endpoint,
@@ -3644,7 +4412,8 @@ var RemoteEngineControlClient = class {
3644
4412
  path,
3645
4413
  this.#config.maxInputSize,
3646
4414
  void 0,
3647
- "getOrCreateForKey" in target ? this.#config.poolName : void 0
4415
+ "getOrCreateForKey" in target ? target.getOrCreateForKey.poolName ?? this.#config.poolName : void 0,
4416
+ options
3648
4417
  );
3649
4418
  }
3650
4419
  if ("create" in target) {
@@ -3655,6 +4424,25 @@ var RemoteEngineControlClient = class {
3655
4424
  throw new Error("unreachable: unknown gateway target type");
3656
4425
  }
3657
4426
  };
4427
+ function canUseDirectSkipReadyWaitPath(path) {
4428
+ return isActorHttpRequestPath(path) || isPathOrQuery(path, PATH_CONNECT) || isPathOrQuery(path, PATH_WEBSOCKET_BASE) || path.startsWith(PATH_WEBSOCKET_PREFIX);
4429
+ }
4430
+ function isPathOrQuery(path, basePath) {
4431
+ return path === basePath || path.startsWith(`${basePath}?`);
4432
+ }
4433
+ function isActorHttpRequestPath(path) {
4434
+ const stripped = path.slice("/request".length);
4435
+ return path.startsWith("/request") && (stripped.length === 0 || stripped.startsWith("/") || stripped.startsWith("?"));
4436
+ }
4437
+ function directActorIdFromTarget(target) {
4438
+ if ("directId" in target) {
4439
+ return target.directId;
4440
+ }
4441
+ if ("getForId" in target) {
4442
+ return target.getForId.actorId;
4443
+ }
4444
+ return void 0;
4445
+ }
3658
4446
  function requestPath(req) {
3659
4447
  const url = new URL(req.url);
3660
4448
  return `${url.pathname}${url.search}`;
@@ -3677,6 +4465,14 @@ function apiActorToOutput(actor) {
3677
4465
  import invariant4 from "invariant";
3678
4466
  import pRetry2, { AbortError } from "p-retry";
3679
4467
 
4468
+ // src/client/actor-common.ts
4469
+ function resolveActorGatewayOptions(defaults = {}, overrides) {
4470
+ const skipReadyWait = overrides?.skipReadyWait ?? defaults.skipReadyWait ?? false;
4471
+ return {
4472
+ skipReadyWait
4473
+ };
4474
+ }
4475
+
3680
4476
  // src/client/actor-query.ts
3681
4477
  function getActorNameFromQuery(query) {
3682
4478
  if ("getForId" in query) return query.getForId.name;
@@ -3702,7 +4498,7 @@ function getGatewayTarget(state) {
3702
4498
  function isStaleResolvedActorError(group, code) {
3703
4499
  return group === "actor" && (code === "not_found" || code === "starting" || code === "stopping" || code === "not_configured" || code === "dropped_reply" || code.startsWith("destroyed_"));
3704
4500
  }
3705
- async function checkForSchedulingError(group, code, actorId, query, driver) {
4501
+ async function checkForSchedulingError(group, code, actorId, query, driver, rayId) {
3706
4502
  const name = getActorNameFromQuery(query);
3707
4503
  try {
3708
4504
  const actor = await driver.getForId({ name, actorId });
@@ -3712,7 +4508,13 @@ async function checkForSchedulingError(group, code, actorId, query, driver) {
3712
4508
  actorId,
3713
4509
  error: actor.error
3714
4510
  });
3715
- return actorSchedulingError(group, code, actorId, actor.error);
4511
+ return actorSchedulingError(
4512
+ group,
4513
+ code,
4514
+ actorId,
4515
+ actor.error,
4516
+ rayId
4517
+ );
3716
4518
  }
3717
4519
  } catch (err) {
3718
4520
  logger2().warn({
@@ -3763,6 +4565,17 @@ function classifyActorError(error) {
3763
4565
  }
3764
4566
  );
3765
4567
  }
4568
+ if (error.group === "guard" && isRetryableGuardGatewayHttpError(error.code)) {
4569
+ return buildLifecycleBoundaryInfo(
4570
+ "request_retry",
4571
+ "actor_error",
4572
+ error.message,
4573
+ {
4574
+ group: error.group,
4575
+ code: error.code
4576
+ }
4577
+ );
4578
+ }
3766
4579
  if (error.group === "actor" && error.code === "internal_error" && error.message === "Actor is stopping") {
3767
4580
  return buildLifecycleBoundaryInfo(
3768
4581
  "request_retry",
@@ -3813,6 +4626,9 @@ function classifyActorError(error) {
3813
4626
  }
3814
4627
  return void 0;
3815
4628
  }
4629
+ function isRetryableGuardGatewayHttpError(code) {
4630
+ return code === "service_unavailable" || code === "actor_wake_retries_exceeded" || code === "actor_stopped_while_waiting" || code === "tunnel_request_aborted" || code === "tunnel_message_timeout" || code === "tunnel_response_closed" || code === "gateway_response_start_timeout";
4631
+ }
3816
4632
  function classifyTransportError(error) {
3817
4633
  if (error.message.includes("database accessed after actor stopped")) {
3818
4634
  return void 0;
@@ -3900,10 +4716,7 @@ async function retryOnLifecycleBoundary(run, opts) {
3900
4716
  if (attempt === maxAttempts - 1) {
3901
4717
  break;
3902
4718
  }
3903
- const delayMs = Math.min(
3904
- initialDelayMs * 2 ** attempt,
3905
- maxDelayMs
3906
- );
4719
+ const delayMs = Math.min(initialDelayMs * 2 ** attempt, maxDelayMs);
3907
4720
  await waitWithSignal(delayMs, opts?.signal);
3908
4721
  }
3909
4722
  }
@@ -3942,7 +4755,9 @@ function createQueueSender(senderOptions) {
3942
4755
  }),
3943
4756
  requestToBare: (value) => ({
3944
4757
  name: value.name ?? name,
3945
- body: bufferToArrayBuffer(encodeCborCompat(value.body)),
4758
+ body: bufferToArrayBuffer(
4759
+ encodeCborCompat(value.body)
4760
+ ),
3946
4761
  wait: value.wait ?? false,
3947
4762
  timeout: value.timeout !== void 0 ? BigInt(value.timeout) : null
3948
4763
  }),
@@ -3955,13 +4770,13 @@ function createQueueSender(senderOptions) {
3955
4770
  response: json.response
3956
4771
  };
3957
4772
  },
3958
- responseFromBare: (bare4) => {
3959
- if (bare4.response === null || bare4.response === void 0) {
3960
- return { status: bare4.status };
4773
+ responseFromBare: (bare5) => {
4774
+ if (bare5.response === null || bare5.response === void 0) {
4775
+ return { status: bare5.status };
3961
4776
  }
3962
4777
  return {
3963
- status: bare4.status,
3964
- response: decodeCborCompat(new Uint8Array(bare4.response))
4778
+ status: bare5.status,
4779
+ response: decodeCborCompat(new Uint8Array(bare5.response))
3965
4780
  };
3966
4781
  }
3967
4782
  });
@@ -3976,7 +4791,6 @@ function createQueueSender(senderOptions) {
3976
4791
  }
3977
4792
 
3978
4793
  // src/client/actor-conn.ts
3979
- var DEFAULT_MAX_INCOMING_MESSAGE_SIZE = 65536;
3980
4794
  var CONNECT_SYMBOL = /* @__PURE__ */ Symbol("connect");
3981
4795
  var ActorConnRaw = class {
3982
4796
  #disposed = false;
@@ -3995,6 +4809,7 @@ var ActorConnRaw = class {
3995
4809
  #statusChangeHandlers = /* @__PURE__ */ new Set();
3996
4810
  #actionIdCounter = 0;
3997
4811
  #queueSender;
4812
+ #readyPromise;
3998
4813
  /**
3999
4814
  * Interval that keeps the NodeJS process alive if this is the only thing running.
4000
4815
  *
@@ -4010,6 +4825,7 @@ var ActorConnRaw = class {
4010
4825
  #getParams;
4011
4826
  #encoding;
4012
4827
  #actorResolutionState;
4828
+ #gatewayOptions;
4013
4829
  // TODO: ws message queue
4014
4830
  /**
4015
4831
  * Do not call this directly.
@@ -4018,24 +4834,36 @@ var ActorConnRaw = class {
4018
4834
  *
4019
4835
  * @protected
4020
4836
  */
4021
- constructor(client, driver, params, getParams, encoding, actorResolutionState) {
4837
+ constructor(client, driver, params, getParams, encoding, actorResolutionState, gatewayOptions = {}) {
4022
4838
  this.#client = client;
4023
4839
  this.#driver = driver;
4024
4840
  this.#params = params;
4025
4841
  this.#getParams = getParams;
4026
4842
  this.#encoding = encoding;
4027
4843
  this.#actorResolutionState = actorResolutionState;
4844
+ this.#gatewayOptions = resolveActorGatewayOptions(gatewayOptions);
4845
+ if ("getForId" in actorResolutionState) {
4846
+ this.#actorId = actorResolutionState.getForId.actorId;
4847
+ }
4848
+ this.#readyPromise = promiseWithResolvers(
4849
+ (reason) => logger2().warn({
4850
+ msg: "unhandled ready promise rejection",
4851
+ reason
4852
+ })
4853
+ );
4028
4854
  this.#queueSender = createQueueSender({
4029
4855
  encoding: this.#encoding,
4030
4856
  params: this.#params,
4031
4857
  customFetch: async (request) => {
4032
4858
  return await this.#driver.sendRequest(
4033
4859
  getGatewayTarget(this.#actorResolutionState),
4034
- request
4860
+ request,
4861
+ this.#gatewayOptions
4035
4862
  );
4036
4863
  }
4037
4864
  });
4038
- this.#keepNodeAliveInterval = setInterval(() => 6e4);
4865
+ this.#keepNodeAliveInterval = setInterval(() => {
4866
+ }, 6e4);
4039
4867
  }
4040
4868
  #clearResolvedActorIdentity() {
4041
4869
  this.#actorId = void 0;
@@ -4142,6 +4970,7 @@ var ActorConnRaw = class {
4142
4970
  }
4143
4971
  }
4144
4972
  if (status === "connected") {
4973
+ this.#readyPromise.resolve(void 0);
4145
4974
  for (const handler of [...this.#openHandlers]) {
4146
4975
  try {
4147
4976
  handler();
@@ -4232,6 +5061,9 @@ var ActorConnRaw = class {
4232
5061
  if (error instanceof RivetError && this.#shouldReconnectForStaleActor(error.group, error.code)) {
4233
5062
  return true;
4234
5063
  }
5064
+ if (error instanceof RivetError && error.group === "client" && error.code === "get_params_failed") {
5065
+ return true;
5066
+ }
4235
5067
  return isRetryableLifecycleReconnectSignal(error);
4236
5068
  }
4237
5069
  #clearQueuedMessages() {
@@ -4269,7 +5101,8 @@ var ActorConnRaw = class {
4269
5101
  PATH_CONNECT,
4270
5102
  target,
4271
5103
  this.#encoding,
4272
- params
5104
+ params,
5105
+ this.#gatewayOptions
4273
5106
  );
4274
5107
  invariant4(ws, "websocket should have been created");
4275
5108
  logger2().debug({
@@ -4394,7 +5227,7 @@ var ActorConnRaw = class {
4394
5227
  });
4395
5228
  this.#handleOnOpen();
4396
5229
  } else if (response.body.tag === "Error") {
4397
- const { group, code, message, metadata, actionId } = response.body.val;
5230
+ const { group, code, message, metadata, actionId, actor } = response.body.val;
4398
5231
  if (actionId !== null) {
4399
5232
  const inFlight = this.#takeActionInFlight(Number(actionId));
4400
5233
  this.#invalidateActorIfStale(group, code);
@@ -4405,10 +5238,16 @@ var ActorConnRaw = class {
4405
5238
  group,
4406
5239
  code,
4407
5240
  message,
4408
- metadata
5241
+ metadata,
5242
+ actorId: actor?.actorId,
5243
+ generation: actor?.generation,
5244
+ actorKey: actor?.key
4409
5245
  });
4410
5246
  inFlight.reject(
4411
- new RivetError(group, code, message, metadata)
5247
+ new RivetError(group, code, message, {
5248
+ metadata,
5249
+ actor
5250
+ })
4412
5251
  );
4413
5252
  } else {
4414
5253
  logger2().warn({
@@ -4416,21 +5255,25 @@ var ActorConnRaw = class {
4416
5255
  group,
4417
5256
  code,
4418
5257
  message,
4419
- metadata
5258
+ metadata,
5259
+ actorId: actor?.actorId,
5260
+ generation: actor?.generation,
5261
+ actorKey: actor?.key
4420
5262
  });
4421
5263
  if (this.#shouldReconnectForStaleActor(group, code)) {
4422
5264
  this.#clearResolvedActorIdentity();
4423
5265
  this.#onOpenPromise?.reject(
4424
- new RivetError(group, code, message, metadata)
5266
+ new RivetError(group, code, message, {
5267
+ metadata,
5268
+ actor
5269
+ })
4425
5270
  );
4426
5271
  return;
4427
5272
  }
4428
- let errorToThrow = new RivetError(
4429
- group,
4430
- code,
4431
- message,
4432
- metadata
4433
- );
5273
+ let errorToThrow = new RivetError(group, code, message, {
5274
+ metadata,
5275
+ actor
5276
+ });
4434
5277
  if (isSchedulingError(group, code) && this.#actorId) {
4435
5278
  const schedulingError = await checkForSchedulingError(
4436
5279
  group,
@@ -4500,7 +5343,7 @@ var ActorConnRaw = class {
4500
5343
  const reason = closeEvent.reason || "";
4501
5344
  const parsed = parseWebSocketCloseReason(reason);
4502
5345
  if (parsed) {
4503
- const { group, code } = parsed;
5346
+ const { group, code, rayId } = parsed;
4504
5347
  if (this.#shouldReconnectForStaleActor(group, code)) {
4505
5348
  this.#clearResolvedActorIdentity();
4506
5349
  this.#onOpenPromise?.reject(
@@ -4508,7 +5351,7 @@ var ActorConnRaw = class {
4508
5351
  group,
4509
5352
  code,
4510
5353
  `Connection closed: ${reason}`,
4511
- void 0
5354
+ { rayId }
4512
5355
  )
4513
5356
  );
4514
5357
  return;
@@ -4519,7 +5362,8 @@ var ActorConnRaw = class {
4519
5362
  code,
4520
5363
  this.#actorId,
4521
5364
  this.#actorResolutionState,
4522
- this.#driver
5365
+ this.#driver,
5366
+ rayId
4523
5367
  );
4524
5368
  if (schedulingError) {
4525
5369
  error = schedulingError;
@@ -4528,7 +5372,7 @@ var ActorConnRaw = class {
4528
5372
  group,
4529
5373
  code,
4530
5374
  `Connection closed: ${reason}`,
4531
- void 0
5375
+ { rayId }
4532
5376
  );
4533
5377
  }
4534
5378
  } else {
@@ -4536,7 +5380,7 @@ var ActorConnRaw = class {
4536
5380
  group,
4537
5381
  code,
4538
5382
  `Connection closed: ${reason}`,
4539
- void 0
5383
+ { rayId }
4540
5384
  );
4541
5385
  }
4542
5386
  this.#invalidateActorIfStale(group, code);
@@ -4704,6 +5548,12 @@ var ActorConnRaw = class {
4704
5548
  get isConnected() {
4705
5549
  return this.#connStatus === "connected";
4706
5550
  }
5551
+ /**
5552
+ * Resolves when this connection first reaches the connected state.
5553
+ */
5554
+ get ready() {
5555
+ return this.#readyPromise.promise;
5556
+ }
4707
5557
  /**
4708
5558
  * Subscribes to connection open events.
4709
5559
  *
@@ -4820,31 +5670,8 @@ var ActorConnRaw = class {
4820
5670
  }
4821
5671
  }
4822
5672
  );
4823
- const serializedLength = messageLength(messageSerialized);
4824
- if (serializedLength > DEFAULT_MAX_INCOMING_MESSAGE_SIZE && message.body.tag === "ActionRequest") {
4825
- const actionId = Number(message.body.val.id);
4826
- const inFlight = this.#takeActionInFlight(actionId);
4827
- const error = new RivetError(
4828
- "message",
4829
- "incoming_too_long",
4830
- "Incoming message too long",
4831
- {
4832
- maxSize: DEFAULT_MAX_INCOMING_MESSAGE_SIZE,
4833
- actualSize: serializedLength
4834
- }
4835
- );
4836
- logger2().warn({
4837
- msg: "rejecting oversized connection action request",
4838
- actionId,
4839
- actionName: inFlight.name,
4840
- actualSize: serializedLength,
4841
- maxSize: DEFAULT_MAX_INCOMING_MESSAGE_SIZE
4842
- });
4843
- inFlight.reject(error);
4844
- this.#dispatchActorError(error);
4845
- return;
4846
- }
4847
5673
  this.#websocket.send(messageSerialized);
5674
+ const serializedLength = messageLength(messageSerialized);
4848
5675
  logger2().trace({
4849
5676
  msg: "sent websocket message",
4850
5677
  len: serializedLength
@@ -4887,8 +5714,26 @@ var ActorConnRaw = class {
4887
5714
  buffer,
4888
5715
  CLIENT_PROTOCOL_TO_CLIENT,
4889
5716
  ToClientSchema,
4890
- // JSON: values are already the correct type
4891
- (msg) => msg,
5717
+ // JSON/CBOR: normalize actor generation to the public number shape.
5718
+ (msg) => {
5719
+ if (msg.body.tag !== "Error" || !msg.body.val.actor) {
5720
+ return msg;
5721
+ }
5722
+ return {
5723
+ body: {
5724
+ tag: "Error",
5725
+ val: {
5726
+ ...msg.body.val,
5727
+ actor: {
5728
+ ...msg.body.val.actor,
5729
+ generation: Number(
5730
+ msg.body.val.actor.generation
5731
+ )
5732
+ }
5733
+ }
5734
+ }
5735
+ };
5736
+ },
4892
5737
  // BARE: need to decode ArrayBuffer fields back to unknown
4893
5738
  (msg) => {
4894
5739
  if (msg.body.tag === "Error") {
@@ -4904,7 +5749,14 @@ var ActorConnRaw = class {
4904
5749
  msg.body.val.metadata
4905
5750
  )
4906
5751
  ) : null,
4907
- actionId: msg.body.val.actionId
5752
+ actionId: msg.body.val.actionId,
5753
+ actor: msg.body.val.actor ? {
5754
+ actorId: msg.body.val.actor.actorId,
5755
+ generation: Number(
5756
+ msg.body.val.actor.generation
5757
+ ),
5758
+ key: msg.body.val.actor.key ?? void 0
5759
+ } : void 0
4908
5760
  }
4909
5761
  }
4910
5762
  };
@@ -5011,6 +5863,7 @@ var ActorConnRaw = class {
5011
5863
  };
5012
5864
 
5013
5865
  // src/common/database/shared.ts
5866
+ var MIGRATION_TRANSACTION_TIMEOUT_MS = 5 * 6e4;
5014
5867
  var AsyncMutex = class {
5015
5868
  #locked = false;
5016
5869
  #waiting = [];
@@ -5037,15 +5890,26 @@ var AsyncMutex = class {
5037
5890
  }
5038
5891
  };
5039
5892
 
5893
+ // src/common/fetch-like.ts
5894
+ function isUrlLike(value) {
5895
+ return typeof value === "object" && value !== null && typeof value.href === "string" && typeof value.pathname === "string" && typeof value.search === "string";
5896
+ }
5897
+ function isRequestLike(value) {
5898
+ return typeof value === "object" && value !== null && typeof value.url === "string" && typeof value.method === "string" && isHeadersLike(value.headers);
5899
+ }
5900
+ function isHeadersLike(value) {
5901
+ return typeof value === "object" && value !== null && typeof value.entries === "function";
5902
+ }
5903
+
5040
5904
  // src/client/raw-utils.ts
5041
- async function rawHttpFetch(driver, target, params, input, init) {
5905
+ async function rawHttpFetch(driver, target, params, input, init, options = {}) {
5042
5906
  let path;
5043
5907
  let mergedInit = init || {};
5044
5908
  if (typeof input === "string") {
5045
5909
  path = input;
5046
- } else if (input instanceof URL) {
5910
+ } else if (isUrlLike(input)) {
5047
5911
  path = input.pathname + input.search;
5048
- } else if (input instanceof Request) {
5912
+ } else if (isRequestLike(input)) {
5049
5913
  const url = new URL(input.url);
5050
5914
  path = url.pathname + url.search;
5051
5915
  const requestHeaders = new Headers(input.headers);
@@ -5096,18 +5960,13 @@ async function rawHttpFetch(driver, target, params, input, init) {
5096
5960
  ...mergedInit,
5097
5961
  headers: proxyRequestHeaders
5098
5962
  });
5099
- return driver.sendRequest(target, proxyRequest);
5963
+ return driver.sendRequest(target, proxyRequest, options);
5100
5964
  } catch (err) {
5101
- const { group, code, message, metadata } = deconstructError(
5102
- err,
5103
- logger2(),
5104
- {},
5105
- true
5106
- );
5107
- throw new RivetError(group, code, message, metadata);
5965
+ const { group, code, message, metadata, rayId, actor } = deconstructError(err, true);
5966
+ throw new RivetError(group, code, message, { metadata, rayId, actor });
5108
5967
  }
5109
5968
  }
5110
- async function rawWebSocket(driver, target, params, path, _protocols) {
5969
+ async function rawWebSocket(driver, target, params, path, _protocols, options = {}) {
5111
5970
  const encoding = "bare";
5112
5971
  let pathPortion = "";
5113
5972
  let queryPortion = "";
@@ -5130,7 +5989,13 @@ async function rawWebSocket(driver, target, params, path, _protocols) {
5130
5989
  encoding,
5131
5990
  path: fullPath
5132
5991
  });
5133
- const ws = await driver.openWebSocket(fullPath, target, encoding, params);
5992
+ const ws = await driver.openWebSocket(
5993
+ fullPath,
5994
+ target,
5995
+ encoding,
5996
+ params,
5997
+ options
5998
+ );
5134
5999
  return ws;
5135
6000
  }
5136
6001
 
@@ -5159,7 +6024,8 @@ async function resolveGatewayTarget(driver, target) {
5159
6024
  name: target.getOrCreateForKey.name,
5160
6025
  key: target.getOrCreateForKey.key,
5161
6026
  input: target.getOrCreateForKey.input,
5162
- region: target.getOrCreateForKey.region
6027
+ region: target.getOrCreateForKey.region,
6028
+ poolName: target.getOrCreateForKey.poolName
5163
6029
  });
5164
6030
  return output.actorId;
5165
6031
  }
@@ -5168,7 +6034,8 @@ async function resolveGatewayTarget(driver, target) {
5168
6034
  name: target.create.name,
5169
6035
  key: target.create.key,
5170
6036
  input: target.create.input,
5171
- region: target.create.region
6037
+ region: target.create.region,
6038
+ poolName: target.create.poolName
5172
6039
  });
5173
6040
  return output.actorId;
5174
6041
  }
@@ -5181,6 +6048,7 @@ var ActorHandleRaw = class {
5181
6048
  #driver;
5182
6049
  #encoding;
5183
6050
  #actorResolutionState;
6051
+ #gatewayOptions;
5184
6052
  #params;
5185
6053
  #getParams;
5186
6054
  #resolvedActorId;
@@ -5193,11 +6061,12 @@ var ActorHandleRaw = class {
5193
6061
  *
5194
6062
  * @protected
5195
6063
  */
5196
- constructor(client, driver, params, getParams, encoding, actorResolutionState) {
6064
+ constructor(client, driver, params, getParams, encoding, actorResolutionState, gatewayOptions = {}) {
5197
6065
  this.#client = client;
5198
6066
  this.#driver = driver;
5199
6067
  this.#encoding = encoding;
5200
6068
  this.#actorResolutionState = actorResolutionState;
6069
+ this.#gatewayOptions = gatewayOptions;
5201
6070
  this.#params = params;
5202
6071
  this.#getParams = getParams;
5203
6072
  }
@@ -5217,22 +6086,27 @@ var ActorHandleRaw = class {
5217
6086
  for (let attempt = 0; attempt < maxAttempts; attempt++) {
5218
6087
  let actorId;
5219
6088
  try {
5220
- const target = await this.#resolveActionTarget(useQueryTarget);
6089
+ const gatewayOptions = resolveActorGatewayOptions(
6090
+ this.#gatewayOptions
6091
+ );
6092
+ const target = await this.#resolveGatewayRequestTarget(
6093
+ useQueryTarget,
6094
+ gatewayOptions
6095
+ );
5221
6096
  actorId = "directId" in target ? target.directId : void 0;
5222
6097
  return await createQueueSender({
5223
6098
  encoding: this.#encoding,
5224
6099
  params: this.#params,
5225
6100
  customFetch: async (request) => {
5226
- return await this.#driver.sendRequest(target, request);
6101
+ return await this.#driver.sendRequest(
6102
+ target,
6103
+ request,
6104
+ gatewayOptions
6105
+ );
5227
6106
  }
5228
6107
  }).send(name, body, options);
5229
6108
  } catch (err) {
5230
- const { group, code, message, metadata } = deconstructError(
5231
- err,
5232
- logger2(),
5233
- {},
5234
- true
5235
- );
6109
+ const { group, code, message, metadata, rayId, actor } = deconstructError(err, true);
5236
6110
  if (this.#shouldRetryQueueDispatchOverload(
5237
6111
  group,
5238
6112
  code,
@@ -5248,7 +6122,8 @@ var ActorHandleRaw = class {
5248
6122
  code,
5249
6123
  actorId,
5250
6124
  attempt,
5251
- maxAttempts
6125
+ maxAttempts,
6126
+ rayId
5252
6127
  )) {
5253
6128
  useQueryTarget = true;
5254
6129
  await this.#waitForRetryWindow();
@@ -5265,7 +6140,10 @@ var ActorHandleRaw = class {
5265
6140
  await this.#waitForRetryWindow();
5266
6141
  continue;
5267
6142
  }
5268
- const invalidated = this.#invalidateResolvedActorId(group, code);
6143
+ const invalidated = this.#invalidateResolvedActorId(
6144
+ group,
6145
+ code
6146
+ );
5269
6147
  if (invalidated && attempt < maxAttempts - 1) {
5270
6148
  useQueryTarget = code === "starting" || code === "stopping" || code.startsWith("destroyed_");
5271
6149
  if (useQueryTarget) {
@@ -5273,7 +6151,11 @@ var ActorHandleRaw = class {
5273
6151
  }
5274
6152
  continue;
5275
6153
  }
5276
- throw new RivetError(group, code, message, metadata);
6154
+ throw new RivetError(group, code, message, {
6155
+ metadata,
6156
+ rayId,
6157
+ actor
6158
+ });
5277
6159
  }
5278
6160
  }
5279
6161
  throw new Error("unreachable queue retry state");
@@ -5301,10 +6183,17 @@ var ActorHandleRaw = class {
5301
6183
  async #sendActionNow(opts) {
5302
6184
  const maxAttempts = this.#getDynamicQueryMaxAttempts();
5303
6185
  let useQueryTarget = false;
6186
+ const gatewayOptions = resolveActorGatewayOptions(
6187
+ this.#gatewayOptions,
6188
+ opts
6189
+ );
5304
6190
  for (let attempt = 0; attempt < maxAttempts; attempt++) {
5305
6191
  let actorId;
5306
6192
  try {
5307
- const target = await this.#resolveActionTarget(useQueryTarget);
6193
+ const target = await this.#resolveGatewayRequestTarget(
6194
+ useQueryTarget,
6195
+ gatewayOptions
6196
+ );
5308
6197
  actorId = "directId" in target ? target.directId : void 0;
5309
6198
  logger2().debug(
5310
6199
  actorId ? { msg: "using direct actor gateway target", actorId } : {
@@ -5330,9 +6219,10 @@ var ActorHandleRaw = class {
5330
6219
  },
5331
6220
  body: opts.args,
5332
6221
  encoding: this.#encoding,
5333
- customFetch: this.#driver.sendRequest.bind(
5334
- this.#driver,
5335
- target
6222
+ customFetch: async (request) => await this.#driver.sendRequest(
6223
+ target,
6224
+ request,
6225
+ gatewayOptions
5336
6226
  ),
5337
6227
  signal: opts?.signal,
5338
6228
  requestVersion: CURRENT_VERSION,
@@ -5345,28 +6235,26 @@ var ActorHandleRaw = class {
5345
6235
  args
5346
6236
  }),
5347
6237
  requestToBare: (args) => ({
5348
- args: bufferToArrayBuffer(encodeCborCompat(args))
6238
+ args: bufferToArrayBuffer(
6239
+ encodeCborCompat(args)
6240
+ )
5349
6241
  }),
5350
6242
  responseFromJson: (json) => json.output,
5351
- responseFromBare: (bare4) => decodeCborCompat(new Uint8Array(bare4.output))
6243
+ responseFromBare: (bare5) => decodeCborCompat(new Uint8Array(bare5.output))
5352
6244
  });
5353
6245
  if (opts.name === "destroy" && actorId) {
5354
6246
  await this.#waitForDestroyActionToSettle(actorId);
5355
6247
  }
5356
6248
  return output;
5357
6249
  } catch (err) {
5358
- const { group, code, message, metadata } = deconstructError(
5359
- err,
5360
- logger2(),
5361
- {},
5362
- true
5363
- );
6250
+ const { group, code, message, metadata, rayId, actor } = deconstructError(err, true);
5364
6251
  if (await this.#shouldRetrySchedulingError(
5365
6252
  group,
5366
6253
  code,
5367
6254
  actorId,
5368
6255
  attempt,
5369
- maxAttempts
6256
+ maxAttempts,
6257
+ rayId
5370
6258
  )) {
5371
6259
  useQueryTarget = true;
5372
6260
  await this.#waitForRetryWindow();
@@ -5388,18 +6276,27 @@ var ActorHandleRaw = class {
5388
6276
  "actor",
5389
6277
  "not_found",
5390
6278
  "The actor does not exist or was destroyed.",
5391
- metadata
6279
+ { metadata, rayId, actor }
5392
6280
  );
5393
6281
  }
5394
- const invalidated = this.#invalidateResolvedActorId(group, code);
6282
+ const invalidated = this.#invalidateResolvedActorId(
6283
+ group,
6284
+ code
6285
+ );
5395
6286
  if (invalidated && attempt < maxAttempts - 1) {
5396
6287
  if (group === "actor" && (code === "starting" || code === "stopping")) {
5397
6288
  useQueryTarget = true;
5398
- await new Promise((resolve) => setTimeout(resolve, 100));
6289
+ await new Promise(
6290
+ (resolve) => setTimeout(resolve, 100)
6291
+ );
5399
6292
  }
5400
6293
  continue;
5401
6294
  }
5402
- throw new RivetError(group, code, message, metadata);
6295
+ throw new RivetError(group, code, message, {
6296
+ metadata,
6297
+ rayId,
6298
+ actor
6299
+ });
5403
6300
  }
5404
6301
  }
5405
6302
  throw new Error("unreachable action retry state");
@@ -5441,7 +6338,7 @@ var ActorHandleRaw = class {
5441
6338
  this.#resolvedActorId = void 0;
5442
6339
  this.#resolvingActorId = void 0;
5443
6340
  }
5444
- async #shouldRetrySchedulingError(group, code, actorId, attempt, maxAttempts) {
6341
+ async #shouldRetrySchedulingError(group, code, actorId, attempt, maxAttempts, rayId) {
5445
6342
  if (!isDynamicActorQuery(this.#actorResolutionState) || !isSchedulingError(group, code) || attempt >= maxAttempts - 1) {
5446
6343
  return false;
5447
6344
  }
@@ -5451,7 +6348,8 @@ var ActorHandleRaw = class {
5451
6348
  code,
5452
6349
  actorId,
5453
6350
  this.#actorResolutionState,
5454
- this.#driver
6351
+ this.#driver,
6352
+ rayId
5455
6353
  );
5456
6354
  if (schedulingError) {
5457
6355
  throw schedulingError;
@@ -5492,13 +6390,19 @@ var ActorHandleRaw = class {
5492
6390
  this.#resolvingActorId = void 0;
5493
6391
  }
5494
6392
  }
6393
+ async #resolveGatewayRequestTarget(useQueryTarget, gatewayOptions) {
6394
+ if (gatewayOptions.skipReadyWait) {
6395
+ return getGatewayTarget(this.#actorResolutionState);
6396
+ }
6397
+ return await this.#resolveActionTarget(useQueryTarget);
6398
+ }
5495
6399
  /**
5496
6400
  * Establishes a persistent connection to the actor.
5497
6401
  *
5498
6402
  * @template AD The actor class that this connection is for.
5499
6403
  * @returns {ActorConn<AD>} A connection to the actor.
5500
6404
  */
5501
- connect(params) {
6405
+ connect(params, options = {}) {
5502
6406
  logger2().debug({
5503
6407
  msg: "establishing connection from handle",
5504
6408
  query: this.#actorResolutionState
@@ -5511,7 +6415,8 @@ var ActorHandleRaw = class {
5511
6415
  connParams,
5512
6416
  getParams,
5513
6417
  this.#encoding,
5514
- this.#actorResolutionState
6418
+ this.#actorResolutionState,
6419
+ resolveActorGatewayOptions(this.#gatewayOptions, options)
5515
6420
  );
5516
6421
  return this.#client[CREATE_ACTOR_CONN_PROXY](
5517
6422
  conn
@@ -5527,17 +6432,28 @@ var ActorHandleRaw = class {
5527
6432
  async #fetchWithResolvedActor(input, init) {
5528
6433
  const maxAttempts = this.#getDynamicQueryMaxAttempts();
5529
6434
  let useQueryTarget = false;
6435
+ const { skipReadyWait, ...requestInit } = init ?? {};
6436
+ const gatewayOptions = resolveActorGatewayOptions(
6437
+ this.#gatewayOptions,
6438
+ {
6439
+ skipReadyWait
6440
+ }
6441
+ );
5530
6442
  for (let attempt = 0; attempt < maxAttempts; attempt++) {
5531
6443
  let actorId;
5532
6444
  try {
5533
- const target = await this.#resolveActionTarget(useQueryTarget);
6445
+ const target = await this.#resolveGatewayRequestTarget(
6446
+ useQueryTarget,
6447
+ gatewayOptions
6448
+ );
5534
6449
  actorId = "directId" in target ? target.directId : void 0;
5535
6450
  const response = await rawHttpFetch(
5536
6451
  this.#driver,
5537
6452
  target,
5538
6453
  this.#params,
5539
6454
  input,
5540
- init
6455
+ requestInit,
6456
+ gatewayOptions
5541
6457
  );
5542
6458
  const retry = await this.#shouldRetryRawFetchResponse(
5543
6459
  response,
@@ -5554,18 +6470,14 @@ var ActorHandleRaw = class {
5554
6470
  }
5555
6471
  return response;
5556
6472
  } catch (err) {
5557
- const { group, code, message, metadata } = deconstructError(
5558
- err,
5559
- logger2(),
5560
- {},
5561
- true
5562
- );
6473
+ const { group, code, message, metadata, rayId, actor } = deconstructError(err, true);
5563
6474
  if (await this.#shouldRetrySchedulingError(
5564
6475
  group,
5565
6476
  code,
5566
6477
  actorId,
5567
6478
  attempt,
5568
- maxAttempts
6479
+ maxAttempts,
6480
+ rayId
5569
6481
  )) {
5570
6482
  useQueryTarget = true;
5571
6483
  await this.#waitForRetryWindow();
@@ -5582,7 +6494,10 @@ var ActorHandleRaw = class {
5582
6494
  await this.#waitForRetryWindow();
5583
6495
  continue;
5584
6496
  }
5585
- const invalidated = this.#invalidateResolvedActorId(group, code);
6497
+ const invalidated = this.#invalidateResolvedActorId(
6498
+ group,
6499
+ code
6500
+ );
5586
6501
  if (invalidated && attempt < maxAttempts - 1) {
5587
6502
  useQueryTarget = code === "starting" || code === "stopping" || code.startsWith("destroyed_");
5588
6503
  if (useQueryTarget) {
@@ -5590,7 +6505,11 @@ var ActorHandleRaw = class {
5590
6505
  }
5591
6506
  continue;
5592
6507
  }
5593
- throw new RivetError(group, code, message, metadata);
6508
+ throw new RivetError(group, code, message, {
6509
+ metadata,
6510
+ rayId,
6511
+ actor
6512
+ });
5594
6513
  }
5595
6514
  }
5596
6515
  throw new Error("unreachable fetch retry state");
@@ -5603,13 +6522,14 @@ var ActorHandleRaw = class {
5603
6522
  if (!error) {
5604
6523
  return null;
5605
6524
  }
5606
- const { group, code } = error;
6525
+ const { group, code, rayId } = error;
5607
6526
  if (await this.#shouldRetrySchedulingError(
5608
6527
  group,
5609
6528
  code,
5610
6529
  actorId,
5611
6530
  attempt,
5612
- maxAttempts
6531
+ maxAttempts,
6532
+ rayId
5613
6533
  )) {
5614
6534
  return {
5615
6535
  useQueryTarget: true,
@@ -5645,19 +6565,34 @@ var ActorHandleRaw = class {
5645
6565
  const contentType = response.headers.get("content-type");
5646
6566
  const encoding = contentType?.includes("application/json") ? "json" : this.#encoding;
5647
6567
  try {
5648
- return deserializeWithEncoding(
6568
+ const error = deserializeWithEncoding(
5649
6569
  encoding,
5650
6570
  new Uint8Array(await response.clone().arrayBuffer()),
5651
6571
  HTTP_RESPONSE_ERROR_VERSIONED,
5652
6572
  HttpResponseErrorSchema,
5653
- (json) => json,
5654
- (bare4) => ({
5655
- group: bare4.group,
5656
- code: bare4.code,
5657
- message: bare4.message,
5658
- metadata: bare4.metadata ? decodeCborCompat(new Uint8Array(bare4.metadata)) : void 0
6573
+ (json) => ({
6574
+ ...json,
6575
+ actor: json.actor ? {
6576
+ ...json.actor,
6577
+ generation: Number(json.actor.generation)
6578
+ } : void 0
6579
+ }),
6580
+ (bare5) => ({
6581
+ group: bare5.group,
6582
+ code: bare5.code,
6583
+ message: bare5.message,
6584
+ metadata: bare5.metadata ? decodeCborCompat(new Uint8Array(bare5.metadata)) : void 0,
6585
+ actor: bare5.actor ? {
6586
+ actorId: bare5.actor.actorId,
6587
+ generation: Number(bare5.actor.generation),
6588
+ key: bare5.actor.key ?? void 0
6589
+ } : void 0
5659
6590
  })
5660
6591
  );
6592
+ return {
6593
+ ...error,
6594
+ rayId: response.headers.get("x-rivet-ray-id") ?? void 0
6595
+ };
5661
6596
  } catch {
5662
6597
  return null;
5663
6598
  }
@@ -5665,14 +6600,24 @@ var ActorHandleRaw = class {
5665
6600
  /**
5666
6601
  * Opens a raw WebSocket connection to this actor.
5667
6602
  */
5668
- async webSocket(path, protocols) {
6603
+ async webSocket(path, protocols, options = {}) {
5669
6604
  const params = await this.#resolveConnectionParams();
6605
+ const gatewayOptions = resolveActorGatewayOptions(
6606
+ this.#gatewayOptions,
6607
+ options
6608
+ );
6609
+ const useQueryTarget = isDynamicActorQuery(this.#actorResolutionState);
6610
+ const target = await this.#resolveGatewayRequestTarget(
6611
+ useQueryTarget,
6612
+ gatewayOptions
6613
+ );
5670
6614
  return await rawWebSocket(
5671
6615
  this.#driver,
5672
- getGatewayTarget(this.#actorResolutionState),
6616
+ target,
5673
6617
  params,
5674
6618
  path,
5675
- protocols
6619
+ protocols,
6620
+ gatewayOptions
5676
6621
  );
5677
6622
  }
5678
6623
  /**
@@ -5686,14 +6631,17 @@ var ActorHandleRaw = class {
5686
6631
  if ("directId" in target) {
5687
6632
  return target.directId;
5688
6633
  }
5689
- throw new Error("dynamic actor resolution did not produce a direct actor id");
6634
+ throw new Error(
6635
+ "dynamic actor resolution did not produce a direct actor id"
6636
+ );
5690
6637
  }
5691
6638
  /**
5692
6639
  * Returns the raw URL for routing traffic to the actor.
5693
6640
  */
5694
6641
  async getGatewayUrl() {
5695
6642
  return await this.#driver.buildGatewayUrl(
5696
- getGatewayTarget(this.#actorResolutionState)
6643
+ getGatewayTarget(this.#actorResolutionState),
6644
+ this.#gatewayOptions
5697
6645
  );
5698
6646
  }
5699
6647
  async reload() {
@@ -5708,7 +6656,9 @@ var ActorHandleRaw = class {
5708
6656
  "actor",
5709
6657
  "reload_failed",
5710
6658
  `reload failed with status ${response.status}: ${body}`,
5711
- {}
6659
+ {
6660
+ rayId: response.headers.get("x-rivet-ray-id") ?? void 0
6661
+ }
5712
6662
  );
5713
6663
  }
5714
6664
  }
@@ -5722,12 +6672,14 @@ var ClientRaw = class {
5722
6672
  [ACTOR_CONNS_SYMBOL] = /* @__PURE__ */ new Set();
5723
6673
  #driver;
5724
6674
  #encodingKind;
6675
+ #gatewayOptions;
5725
6676
  /**
5726
6677
  * Creates an instance of Client.
5727
6678
  */
5728
- constructor(driver, encoding) {
6679
+ constructor(driver, encoding, gatewayOptions = {}) {
5729
6680
  this.#driver = driver;
5730
6681
  this.#encodingKind = encoding ?? "bare";
6682
+ this.#gatewayOptions = gatewayOptions;
5731
6683
  }
5732
6684
  /**
5733
6685
  * Gets a stateless handle to a actor by its ID.
@@ -5811,7 +6763,8 @@ var ClientRaw = class {
5811
6763
  name,
5812
6764
  key: keyArray,
5813
6765
  input: opts?.createWithInput,
5814
- region: opts?.createInRegion
6766
+ region: opts?.createInRegion,
6767
+ poolName: opts?.poolName
5815
6768
  }
5816
6769
  };
5817
6770
  const handle = this.#createHandle(
@@ -5876,7 +6829,8 @@ var ClientRaw = class {
5876
6829
  params,
5877
6830
  getParams,
5878
6831
  this.#encodingKind,
5879
- actorQuery
6832
+ actorQuery,
6833
+ this.#gatewayOptions
5880
6834
  );
5881
6835
  }
5882
6836
  [CREATE_ACTOR_CONN_PROXY](conn) {
@@ -5904,7 +6858,7 @@ var ClientRaw = class {
5904
6858
  }
5905
6859
  };
5906
6860
  function createClientWithDriver(driver, config = {}) {
5907
- const client = new ClientRaw(driver, config.encoding);
6861
+ const client = new ClientRaw(driver, config.encoding, config.gateway);
5908
6862
  return new Proxy(client, {
5909
6863
  get: (target, prop, receiver) => {
5910
6864
  if (typeof prop === "symbol" || prop in target) {
@@ -5937,6 +6891,23 @@ function createClientWithDriver(driver, config = {}) {
5937
6891
  }
5938
6892
  function createActorProxy(handle) {
5939
6893
  const methodCache = /* @__PURE__ */ new Map();
6894
+ const actionPath = (name) => {
6895
+ let method = methodCache.get(name);
6896
+ if (method) return method;
6897
+ method = new Proxy(
6898
+ (...args) => handle.action({ name, args }),
6899
+ {
6900
+ get(target, prop) {
6901
+ if (typeof prop === "symbol")
6902
+ return Reflect.get(target, prop);
6903
+ if (prop === "then") return void 0;
6904
+ return actionPath(`${name}.${prop}`);
6905
+ }
6906
+ }
6907
+ );
6908
+ methodCache.set(name, method);
6909
+ return method;
6910
+ };
5940
6911
  return new Proxy(handle, {
5941
6912
  get(target, prop, receiver) {
5942
6913
  if (typeof prop === "symbol") {
@@ -5951,12 +6922,7 @@ function createActorProxy(handle) {
5951
6922
  }
5952
6923
  if (typeof prop === "string") {
5953
6924
  if (prop === "then") return void 0;
5954
- let method = methodCache.get(prop);
5955
- if (!method) {
5956
- method = (...args) => target.action({ name: prop, args });
5957
- methodCache.set(prop, method);
5958
- }
5959
- return method;
6925
+ return actionPath(prop);
5960
6926
  }
5961
6927
  },
5962
6928
  // Support for 'in' operator
@@ -5974,6 +6940,7 @@ function createActorProxy(handle) {
5974
6940
  },
5975
6941
  // Support proper property descriptors
5976
6942
  getOwnPropertyDescriptor(target, prop) {
6943
+ if (prop === "then") return void 0;
5977
6944
  const targetDescriptor = Reflect.getOwnPropertyDescriptor(
5978
6945
  target,
5979
6946
  prop
@@ -5986,7 +6953,7 @@ function createActorProxy(handle) {
5986
6953
  configurable: true,
5987
6954
  enumerable: false,
5988
6955
  writable: false,
5989
- value: (...args) => target.action({ name: prop, args })
6956
+ value: actionPath(prop)
5990
6957
  };
5991
6958
  }
5992
6959
  return void 0;