rivetkit 0.0.0-main.72cbc7c → 0.0.0-main.79e97f1

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 (265) hide show
  1. package/dist/browser/client.d.ts +721 -88
  2. package/dist/browser/client.js +684 -604
  3. package/dist/browser/client.js.map +1 -1
  4. package/dist/browser/inspector/client.d.ts +121 -2
  5. package/dist/browser/inspector/client.js +2064 -232
  6. package/dist/browser/inspector/client.js.map +1 -1
  7. package/dist/tsup/actor/errors.cjs +4 -2
  8. package/dist/tsup/actor/errors.cjs.map +1 -1
  9. package/dist/tsup/actor/errors.d.cts +1 -1
  10. package/dist/tsup/actor/errors.d.ts +1 -1
  11. package/dist/tsup/actor/errors.js +3 -1
  12. package/dist/tsup/agent-os/index.cjs +2355 -2099
  13. package/dist/tsup/agent-os/index.cjs.map +1 -1
  14. package/dist/tsup/agent-os/index.d.cts +719 -87
  15. package/dist/tsup/agent-os/index.d.ts +719 -87
  16. package/dist/tsup/agent-os/index.js +2343 -2087
  17. package/dist/tsup/agent-os/index.js.map +1 -1
  18. package/dist/tsup/{chunk-OFP533QU.cjs → chunk-42QKF4NL.cjs} +3 -3
  19. package/dist/tsup/{chunk-OFP533QU.cjs.map → chunk-42QKF4NL.cjs.map} +1 -1
  20. package/dist/tsup/{chunk-QAZLM4WT.cjs → chunk-4FC7TVS6.cjs} +8 -4
  21. package/dist/tsup/chunk-4FC7TVS6.cjs.map +1 -0
  22. package/dist/tsup/{chunk-PCBNKI2J.js → chunk-7AFZMFPQ.js} +15 -1
  23. package/dist/tsup/chunk-7AFZMFPQ.js.map +1 -0
  24. package/dist/tsup/{chunk-HSTK7OBI.js → chunk-AXDEBZFM.js} +13 -7
  25. package/dist/tsup/chunk-AXDEBZFM.js.map +1 -0
  26. package/dist/tsup/{chunk-WQ4HNA4W.cjs → chunk-HNHLBM3Y.cjs} +192 -15
  27. package/dist/tsup/chunk-HNHLBM3Y.cjs.map +1 -0
  28. package/dist/tsup/{chunk-EI55QOUB.js → chunk-J2TA4HLA.js} +235 -245
  29. package/dist/tsup/chunk-J2TA4HLA.js.map +1 -0
  30. package/dist/tsup/{chunk-3YY5S6TV.js → chunk-JI6GZ2C2.js} +3 -12
  31. package/dist/tsup/chunk-JI6GZ2C2.js.map +1 -0
  32. package/dist/tsup/{chunk-4KSYSQHX.js → chunk-KUWK4UNH.js} +2 -2
  33. package/dist/tsup/{chunk-YQQ2ZDKT.cjs → chunk-L3YK4JAQ.cjs} +378 -388
  34. package/dist/tsup/chunk-L3YK4JAQ.cjs.map +1 -0
  35. package/dist/tsup/{chunk-WDO5Y6PO.cjs → chunk-LSLRMWDP.cjs} +17 -11
  36. package/dist/tsup/chunk-LSLRMWDP.cjs.map +1 -0
  37. package/dist/tsup/{chunk-LD5YASJU.cjs → chunk-MYWZCDML.cjs} +3 -12
  38. package/dist/tsup/chunk-MYWZCDML.cjs.map +1 -0
  39. package/dist/tsup/{chunk-T6YVRM4K.js → chunk-QWLJCP3X.js} +190 -13
  40. package/dist/tsup/chunk-QWLJCP3X.js.map +1 -0
  41. package/dist/tsup/{chunk-OQSBGFIB.cjs → chunk-ROANIJSQ.cjs} +10 -10
  42. package/dist/tsup/chunk-ROANIJSQ.cjs.map +1 -0
  43. package/dist/tsup/{chunk-5DGOZZKE.cjs → chunk-SHGGJE3M.cjs} +44 -9
  44. package/dist/tsup/chunk-SHGGJE3M.cjs.map +1 -0
  45. package/dist/tsup/{chunk-2NDZ7JCR.cjs → chunk-UEULFXUI.cjs} +16 -2
  46. package/dist/tsup/chunk-UEULFXUI.cjs.map +1 -0
  47. package/dist/tsup/{chunk-O25KOT5C.cjs → chunk-ULWCXOND.cjs} +475 -24
  48. package/dist/tsup/chunk-ULWCXOND.cjs.map +1 -0
  49. package/dist/tsup/{chunk-DFHHCPH7.js → chunk-ULYPJPHB.js} +42 -7
  50. package/dist/tsup/chunk-ULYPJPHB.js.map +1 -0
  51. package/dist/tsup/{chunk-GDKM56PU.js → chunk-Y5BCFECV.js} +466 -15
  52. package/dist/tsup/chunk-Y5BCFECV.js.map +1 -0
  53. package/dist/tsup/{chunk-PJSE5ZGN.js → chunk-YTE3YP7Q.js} +6 -6
  54. package/dist/tsup/chunk-YTE3YP7Q.js.map +1 -0
  55. package/dist/tsup/{chunk-KIWH5H3K.js → chunk-ZZ3WBRPD.js} +7 -3
  56. package/dist/tsup/chunk-ZZ3WBRPD.js.map +1 -0
  57. package/dist/tsup/client/mod.cjs +8 -9
  58. package/dist/tsup/client/mod.cjs.map +1 -1
  59. package/dist/tsup/client/mod.d.cts +7 -6
  60. package/dist/tsup/client/mod.d.ts +7 -6
  61. package/dist/tsup/client/mod.js +7 -8
  62. package/dist/tsup/common/log.cjs +5 -3
  63. package/dist/tsup/common/log.cjs.map +1 -1
  64. package/dist/tsup/common/log.d.cts +5 -1
  65. package/dist/tsup/common/log.d.ts +5 -1
  66. package/dist/tsup/common/log.js +6 -4
  67. package/dist/tsup/common/websocket.cjs +4 -4
  68. package/dist/tsup/common/websocket.js +3 -3
  69. package/dist/tsup/{config-CxjGYf4K.d.cts → config-BxOimoGX.d.cts} +17 -2
  70. package/dist/tsup/{config-CxjGYf4K.d.ts → config-BxOimoGX.d.ts} +17 -2
  71. package/dist/tsup/{config-CRwCN3Ok.d.ts → config-CUymbyM6.d.ts} +758 -56
  72. package/dist/tsup/{config-voObiSep.d.cts → config-CpB-e4I9.d.cts} +758 -56
  73. package/dist/tsup/context-YBUBTwTS.d.ts +129 -0
  74. package/dist/tsup/context-c-6G4mjk.d.cts +129 -0
  75. package/dist/tsup/db/drizzle.cjs +120 -68
  76. package/dist/tsup/db/drizzle.cjs.map +1 -1
  77. package/dist/tsup/db/drizzle.d.cts +8 -3
  78. package/dist/tsup/db/drizzle.d.ts +8 -3
  79. package/dist/tsup/db/drizzle.js +120 -68
  80. package/dist/tsup/db/drizzle.js.map +1 -1
  81. package/dist/tsup/db/mod.cjs +74 -22
  82. package/dist/tsup/db/mod.cjs.map +1 -1
  83. package/dist/tsup/db/mod.d.cts +4 -3
  84. package/dist/tsup/db/mod.d.ts +4 -3
  85. package/dist/tsup/db/mod.js +74 -22
  86. package/dist/tsup/db/mod.js.map +1 -1
  87. package/dist/tsup/dynamic/mod.cjs +24 -0
  88. package/dist/tsup/dynamic/mod.cjs.map +1 -0
  89. package/dist/tsup/dynamic/mod.d.cts +37 -0
  90. package/dist/tsup/dynamic/mod.d.ts +37 -0
  91. package/dist/tsup/dynamic/mod.js +24 -0
  92. package/dist/tsup/dynamic/mod.js.map +1 -0
  93. package/dist/tsup/inspector/mod.cjs +46 -12
  94. package/dist/tsup/inspector/mod.cjs.map +1 -1
  95. package/dist/tsup/inspector/mod.d.cts +37 -15
  96. package/dist/tsup/inspector/mod.d.ts +37 -15
  97. package/dist/tsup/inspector/mod.js +45 -11
  98. package/dist/tsup/inspector/mod.js.map +1 -1
  99. package/dist/tsup/inspector-tab/mod.cjs +162 -0
  100. package/dist/tsup/inspector-tab/mod.cjs.map +1 -0
  101. package/dist/tsup/inspector-tab/mod.d.cts +240 -0
  102. package/dist/tsup/inspector-tab/mod.d.ts +240 -0
  103. package/dist/tsup/inspector-tab/mod.js +162 -0
  104. package/dist/tsup/inspector-tab/mod.js.map +1 -0
  105. package/dist/tsup/mod.cjs +2031 -533
  106. package/dist/tsup/mod.cjs.map +1 -1
  107. package/dist/tsup/mod.d.cts +6 -6
  108. package/dist/tsup/mod.d.ts +6 -6
  109. package/dist/tsup/mod.js +1953 -455
  110. package/dist/tsup/mod.js.map +1 -1
  111. package/dist/tsup/test/mod.cjs +26 -21
  112. package/dist/tsup/test/mod.cjs.map +1 -1
  113. package/dist/tsup/test/mod.d.cts +5 -5
  114. package/dist/tsup/test/mod.d.ts +5 -5
  115. package/dist/tsup/test/mod.js +25 -20
  116. package/dist/tsup/test/mod.js.map +1 -1
  117. package/dist/tsup/unstable/migrations.cjs +101 -0
  118. package/dist/tsup/unstable/migrations.cjs.map +1 -0
  119. package/dist/tsup/unstable/migrations.d.cts +29 -0
  120. package/dist/tsup/unstable/migrations.d.ts +29 -0
  121. package/dist/tsup/unstable/migrations.js +101 -0
  122. package/dist/tsup/unstable/migrations.js.map +1 -0
  123. package/dist/tsup/utils-CV0akuDD.d.ts +162 -0
  124. package/dist/tsup/{utils-DVekpm4I.d.cts → utils-CqDnC_PS.d.cts} +2 -1
  125. package/dist/tsup/{utils-DVekpm4I.d.ts → utils-CqDnC_PS.d.ts} +2 -1
  126. package/dist/tsup/utils-DQDCphrl.d.cts +162 -0
  127. package/dist/tsup/utils.cjs +7 -3
  128. package/dist/tsup/utils.cjs.map +1 -1
  129. package/dist/tsup/utils.d.cts +4 -147
  130. package/dist/tsup/utils.d.ts +4 -147
  131. package/dist/tsup/utils.js +6 -2
  132. package/dist/tsup/workflow/mod.cjs +486 -375
  133. package/dist/tsup/workflow/mod.cjs.map +1 -1
  134. package/dist/tsup/workflow/mod.d.cts +9 -9
  135. package/dist/tsup/workflow/mod.d.ts +9 -9
  136. package/dist/tsup/workflow/mod.js +478 -367
  137. package/dist/tsup/workflow/mod.js.map +1 -1
  138. package/package.json +45 -14
  139. package/src/actor/actions.ts +119 -0
  140. package/src/actor/config.test.ts +14 -0
  141. package/src/actor/config.ts +338 -85
  142. package/src/actor/contexts/index.ts +7 -2
  143. package/src/actor/definition.ts +38 -26
  144. package/src/actor/errors.ts +20 -3
  145. package/src/actor/keys.ts +1 -1
  146. package/src/actor/mod.ts +22 -20
  147. package/src/actor/schema.ts +2 -2
  148. package/src/agent-os/actor/index.ts +39 -19
  149. package/src/agent-os/actor/preview.ts +1 -2
  150. package/src/agent-os/actor/session.ts +2 -2
  151. package/src/agent-os/config.ts +1 -1
  152. package/src/agent-os/fs/database-vfs.ts +1 -1
  153. package/src/agent-os/index.ts +16 -15
  154. package/src/client/actor-common.ts +89 -54
  155. package/src/client/actor-conn.ts +11 -36
  156. package/src/client/actor-handle.ts +72 -52
  157. package/src/client/actor-query.ts +5 -5
  158. package/src/client/client.ts +24 -11
  159. package/src/client/errors.ts +1 -1
  160. package/src/client/lifecycle-errors.ts +2 -4
  161. package/src/client/query.ts +1 -1
  162. package/src/client/queue.ts +8 -3
  163. package/src/client/raw-utils.ts +19 -8
  164. package/src/client/resolve-gateway-target.ts +1 -1
  165. package/src/client/utils.ts +2 -7
  166. package/src/common/actor-router-consts.ts +1 -0
  167. package/src/common/actor-websocket.ts +3 -1
  168. package/src/common/bare/actor-persist/v1.ts +205 -163
  169. package/src/common/bare/actor-persist/v2.ts +265 -213
  170. package/src/common/bare/actor-persist/v3.ts +176 -172
  171. package/src/common/bare/actor-persist/v4.ts +254 -253
  172. package/src/common/bare/generated/actor-runtime-socket-protocol/v1.ts +848 -0
  173. package/src/common/bare/generated/inspector/v5.ts +1016 -0
  174. package/src/common/bare/generated/inspector/v6.ts +1367 -0
  175. package/src/common/bare/transport/v1.ts +694 -542
  176. package/src/common/client-protocol-versioned.ts +66 -64
  177. package/src/common/database/config.ts +26 -8
  178. package/src/common/database/mod.test.ts +148 -59
  179. package/src/common/database/mod.ts +93 -23
  180. package/src/common/database/native-database.test.ts +9 -0
  181. package/src/common/database/native-database.ts +152 -1
  182. package/src/common/database/shared.ts +16 -0
  183. package/src/common/encoding.ts +278 -34
  184. package/src/common/engine.ts +28 -1
  185. package/src/common/eventsource.ts +1 -1
  186. package/src/common/fetch-like.ts +49 -0
  187. package/src/common/inline-websocket-adapter.ts +14 -13
  188. package/src/common/log.ts +15 -8
  189. package/src/common/router.ts +13 -17
  190. package/src/common/utils.ts +1 -150
  191. package/src/common/websocket-interface.ts +1 -1
  192. package/src/db/drizzle.test.ts +157 -0
  193. package/src/db/drizzle.ts +170 -79
  194. package/src/db/mod.ts +1 -1
  195. package/src/devtools-loader/index.ts +4 -7
  196. package/src/devtools-loader/serve-devtools.ts +26 -0
  197. package/src/dynamic/instance.ts +32 -0
  198. package/src/dynamic/internal.ts +50 -0
  199. package/src/dynamic/isolate-runtime.ts +64 -0
  200. package/src/dynamic/mod.ts +32 -0
  201. package/src/engine-client/actor-http-client.ts +8 -24
  202. package/src/engine-client/actor-websocket-client.ts +6 -5
  203. package/src/engine-client/api-endpoints.ts +51 -2
  204. package/src/engine-client/api-utils.ts +2 -2
  205. package/src/engine-client/driver.ts +1 -16
  206. package/src/engine-client/mod.ts +6 -44
  207. package/src/engine-client/ws-proxy.ts +9 -4
  208. package/src/inspector/client.browser.ts +127 -15
  209. package/src/inspector/mod.ts +2 -4
  210. package/src/inspector-tab/mod.ts +301 -0
  211. package/src/registry/config/envoy.ts +1 -2
  212. package/src/registry/config/index.ts +41 -55
  213. package/src/registry/index.ts +595 -92
  214. package/src/registry/napi-runtime.ts +359 -23
  215. package/src/registry/native-http.ts +208 -0
  216. package/src/registry/native-validation.ts +10 -12
  217. package/src/registry/native.ts +879 -311
  218. package/src/registry/process-metrics.ts +250 -0
  219. package/src/registry/runtime.ts +249 -8
  220. package/src/registry/wasm-runtime.ts +280 -9
  221. package/src/registry/write-through-proxy.ts +40 -0
  222. package/src/serde.ts +2 -2
  223. package/src/serverless/configure.ts +18 -7
  224. package/src/test/mod.ts +2 -17
  225. package/src/test/ready.ts +22 -0
  226. package/src/unstable/migrations.test.ts +170 -0
  227. package/src/unstable/migrations.ts +141 -0
  228. package/src/utils/endpoint-parser.ts +1 -1
  229. package/src/utils/env-vars.ts +37 -0
  230. package/src/utils/router.ts +1 -1
  231. package/src/utils.ts +4 -2
  232. package/src/workflow/context.ts +683 -242
  233. package/src/workflow/driver.test.ts +62 -0
  234. package/src/workflow/driver.ts +248 -119
  235. package/src/workflow/inspector.ts +12 -3
  236. package/src/workflow/mod.ts +39 -25
  237. package/dist/tsup/chunk-2NDZ7JCR.cjs.map +0 -1
  238. package/dist/tsup/chunk-3YY5S6TV.js.map +0 -1
  239. package/dist/tsup/chunk-5DGOZZKE.cjs.map +0 -1
  240. package/dist/tsup/chunk-DFHHCPH7.js.map +0 -1
  241. package/dist/tsup/chunk-EI55QOUB.js.map +0 -1
  242. package/dist/tsup/chunk-GDKM56PU.js.map +0 -1
  243. package/dist/tsup/chunk-HSTK7OBI.js.map +0 -1
  244. package/dist/tsup/chunk-KIWH5H3K.js.map +0 -1
  245. package/dist/tsup/chunk-LD5YASJU.cjs.map +0 -1
  246. package/dist/tsup/chunk-LI5MR5BD.js +0 -268
  247. package/dist/tsup/chunk-LI5MR5BD.js.map +0 -1
  248. package/dist/tsup/chunk-NDY6IZJ3.cjs +0 -268
  249. package/dist/tsup/chunk-NDY6IZJ3.cjs.map +0 -1
  250. package/dist/tsup/chunk-O25KOT5C.cjs.map +0 -1
  251. package/dist/tsup/chunk-OQSBGFIB.cjs.map +0 -1
  252. package/dist/tsup/chunk-PCBNKI2J.js.map +0 -1
  253. package/dist/tsup/chunk-PJSE5ZGN.js.map +0 -1
  254. package/dist/tsup/chunk-QAZLM4WT.cjs.map +0 -1
  255. package/dist/tsup/chunk-T6YVRM4K.js.map +0 -1
  256. package/dist/tsup/chunk-WDO5Y6PO.cjs.map +0 -1
  257. package/dist/tsup/chunk-WQ4HNA4W.cjs.map +0 -1
  258. package/dist/tsup/chunk-YQQ2ZDKT.cjs.map +0 -1
  259. package/dist/tsup/context-BPFYVZ5g.d.ts +0 -92
  260. package/dist/tsup/context-D0YF1MQq.d.cts +0 -92
  261. package/src/actor/driver.ts +0 -141
  262. package/src/actor/instance/mod.ts +0 -2492
  263. package/src/drivers/engine/actor-driver.ts +0 -2460
  264. package/src/utils/serve.ts +0 -217
  265. /package/dist/tsup/{chunk-4KSYSQHX.js.map → chunk-KUWK4UNH.js.map} +0 -0
@@ -1,3 +1,10 @@
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";
@@ -75,19 +82,6 @@ function actorNotFound(identifier) {
75
82
  );
76
83
  }
77
84
 
78
- // src/utils/env-vars.ts
79
- var getRivetEngine = () => getEnvUniversal("RIVET_ENGINE");
80
- var getRivetEndpoint = () => getEnvUniversal("RIVET_ENDPOINT");
81
- var getRivetToken = () => getEnvUniversal("RIVET_TOKEN");
82
- var getRivetNamespace = () => getEnvUniversal("RIVET_NAMESPACE");
83
- var getRivetPool = () => getEnvUniversal("RIVET_POOL");
84
- var getLogLevel = () => getEnvUniversal("RIVET_LOG_LEVEL") ?? getEnvUniversal("LOG_LEVEL");
85
- var getLogTarget = () => getEnvUniversal("RIVET_LOG_TARGET") === "1";
86
- var getLogTimestamp = () => getEnvUniversal("RIVET_LOG_TIMESTAMP") === "1";
87
- var getLogMessage = () => getEnvUniversal("RIVET_LOG_MESSAGE") === "1";
88
- var getLogErrorStack = () => getEnvUniversal("RIVET_LOG_ERROR_STACK") === "1";
89
- var getNextPhase = () => getEnvUniversal("NEXT_PHASE");
90
-
91
85
  // src/common/utils.ts
92
86
  function assertUnreachable(x) {
93
87
  throw new Error(`Unreachable case: ${x}`);
@@ -145,7 +139,7 @@ function deconstructError(error, exposeInternalError = false) {
145
139
  actor = error.actor;
146
140
  }
147
141
  metadata = {
148
- //url: `https://hub.rivet.dev/projects/${actorMetadata.project.slug}/environments/${actorMetadata.environment.slug}/actors?actorId=${actorMetadata.actor.id}`,
142
+ //url: `https://dashboard.rivet.dev/projects/${actorMetadata.project.slug}/environments/${actorMetadata.environment.slug}/actors?actorId=${actorMetadata.actor.id}`,
149
143
  };
150
144
  }
151
145
  return {
@@ -200,7 +194,7 @@ function noopNext() {
200
194
  // package.json
201
195
  var package_default = {
202
196
  name: "rivetkit",
203
- version: "0.0.0-main.72cbc7c",
197
+ version: "0.0.0-main.79e97f1",
204
198
  description: "Lightweight libraries for building stateful actors on edge platforms",
205
199
  license: "Apache-2.0",
206
200
  keywords: [
@@ -272,6 +266,26 @@ var package_default = {
272
266
  default: "./dist/tsup/db/drizzle.cjs"
273
267
  }
274
268
  },
269
+ "./unstable/migrations": {
270
+ import: {
271
+ types: "./dist/tsup/unstable/migrations.d.ts",
272
+ default: "./dist/tsup/unstable/migrations.js"
273
+ },
274
+ require: {
275
+ types: "./dist/tsup/unstable/migrations.d.cts",
276
+ default: "./dist/tsup/unstable/migrations.cjs"
277
+ }
278
+ },
279
+ "./dynamic": {
280
+ import: {
281
+ types: "./dist/tsup/dynamic/mod.d.ts",
282
+ default: "./dist/tsup/dynamic/mod.js"
283
+ },
284
+ require: {
285
+ types: "./dist/tsup/dynamic/mod.d.cts",
286
+ default: "./dist/tsup/dynamic/mod.cjs"
287
+ }
288
+ },
275
289
  "./client": {
276
290
  import: {
277
291
  browser: {
@@ -316,6 +330,16 @@ var package_default = {
316
330
  default: "./dist/tsup/inspector/mod.cjs"
317
331
  }
318
332
  },
333
+ "./inspector-tab": {
334
+ import: {
335
+ types: "./dist/tsup/inspector-tab/mod.d.ts",
336
+ default: "./dist/tsup/inspector-tab/mod.js"
337
+ },
338
+ require: {
339
+ types: "./dist/tsup/inspector-tab/mod.d.cts",
340
+ default: "./dist/tsup/inspector-tab/mod.cjs"
341
+ }
342
+ },
319
343
  "./inspector/client": {
320
344
  import: {
321
345
  types: "./dist/browser/inspector/client.d.ts",
@@ -351,7 +375,7 @@ var package_default = {
351
375
  "./dist/tsup/chunk-*.cjs"
352
376
  ],
353
377
  scripts: {
354
- 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",
378
+ 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-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",
355
379
  "build:browser": "tsup --config tsup.browser.config.ts",
356
380
  "check-types": "tsc --noEmit",
357
381
  lint: "biome check . && pnpm run check:test-skips && pnpm run check:wait-for-comments",
@@ -368,13 +392,12 @@ var package_default = {
368
392
  "actor-config-schema-gen": "tsx scripts/actor-config-schema-gen.ts"
369
393
  },
370
394
  dependencies: {
371
- "@rivet-dev/agent-os-core": "^0.1.1",
372
- "@hono/node-server": "^1.18.2",
373
- "@hono/node-ws": "^1.1.1",
374
395
  "@hono/zod-openapi": "^1.1.5",
396
+ "@rivet-dev/agent-os-core": "^0.1.1",
375
397
  "@rivetkit/bare-ts": "^0.6.2",
376
398
  "@rivetkit/engine-cli": "workspace:*",
377
399
  "@rivetkit/engine-envoy-protocol": "workspace:*",
400
+ "@rivetkit/on-change": "6.0.1",
378
401
  "@rivetkit/rivetkit-napi": "workspace:*",
379
402
  "@rivetkit/rivetkit-wasm": "workspace:*",
380
403
  "@rivetkit/traces": "workspace:*",
@@ -382,7 +405,6 @@ var package_default = {
382
405
  "@rivetkit/workflow-engine": "workspace:*",
383
406
  "cbor-x": "^1.6.0",
384
407
  "drizzle-orm": "^0.44.2",
385
- "get-port": "^7.1.0",
386
408
  hono: "^4.7.0",
387
409
  invariant: "^2.2.4",
388
410
  "p-retry": "^6.2.1",
@@ -392,14 +414,17 @@ var package_default = {
392
414
  zod: "^4.1.0"
393
415
  },
394
416
  devDependencies: {
417
+ "@biomejs/biome": "^2.3",
395
418
  "@copilotkit/llmock": "^1.6.0",
419
+ "@hono/node-server": "^1.18.2",
420
+ "@hono/node-ws": "^1.1.1",
396
421
  "@rivet-dev/agent-os-common": "*",
397
422
  "@rivet-dev/agent-os-pi": "^0.1.1",
398
- "@biomejs/biome": "^2.3",
399
423
  "@standard-schema/spec": "^1.0.0",
400
424
  "@types/invariant": "^2",
401
425
  "@types/node": "^22.13.1",
402
426
  eventsource: "^4.0.0",
427
+ "get-port": "^7.1.0",
403
428
  tsup: "^8.4.0",
404
429
  tsx: "^4.19.4",
405
430
  typescript: "^5.7.3",
@@ -426,153 +451,302 @@ var package_default = {
426
451
  stableVersion: "0.8.0"
427
452
  };
428
453
 
429
- // src/common/log.ts
430
- import {
431
- pino,
432
- stdTimeFunctions
433
- } from "pino";
454
+ // src/common/encoding.ts
434
455
  import { z } from "zod/v4";
435
- var baseLogger;
436
- var configuredLogLevel;
437
- var loggerCache = /* @__PURE__ */ new Map();
438
- var LogLevelSchema = z.enum([
439
- "trace",
440
- "debug",
441
- "info",
442
- "warn",
443
- "error",
444
- "fatal",
445
- "silent"
446
- ]);
447
- function getPinoLevel(logLevel) {
448
- if (logLevel) {
449
- return logLevel;
456
+
457
+ // src/serde.ts
458
+ import * as cbor from "cbor-x";
459
+ import invariant from "invariant";
460
+ function uint8ArrayToBase64(uint8Array) {
461
+ if (typeof Buffer !== "undefined") {
462
+ return Buffer.from(uint8Array).toString("base64");
450
463
  }
451
- if (configuredLogLevel) {
452
- return configuredLogLevel;
464
+ let binary = "";
465
+ const len = uint8Array.byteLength;
466
+ for (let i = 0; i < len; i++) {
467
+ binary += String.fromCharCode(uint8Array[i]);
453
468
  }
454
- const raw = (getLogLevel() || "warn").toString().toLowerCase();
455
- const parsed = LogLevelSchema.safeParse(raw);
456
- if (parsed.success) {
457
- return parsed.data;
469
+ return btoa(binary);
470
+ }
471
+ function contentTypeForEncoding(encoding) {
472
+ if (encoding === "json") {
473
+ return "application/json";
474
+ } else if (encoding === "cbor" || encoding === "bare") {
475
+ return "application/octet-stream";
476
+ } else {
477
+ assertUnreachable(encoding);
458
478
  }
459
- return "info";
460
479
  }
461
- function getIncludeTarget() {
462
- return getLogTarget();
480
+ function encodeCborCompat(value) {
481
+ return cbor.encode(encodeJsonCompatValue(value));
463
482
  }
464
- function configureDefaultLogger(logLevel) {
465
- if (logLevel) {
466
- configuredLogLevel = logLevel;
467
- }
468
- baseLogger = pino(
469
- {
470
- level: getPinoLevel(logLevel),
471
- messageKey: "msg",
472
- // Do not include pid/hostname in output
473
- base: {},
474
- // Keep the numeric level so the logfmt sink can match Pino's levels.
475
- formatters: {
476
- level(_label, number) {
477
- return { level: number };
478
- }
479
- },
480
- timestamp: getLogTimestamp() ? stdTimeFunctions.epochTime : false
481
- },
482
- createLogfmtDestination()
483
- );
484
- loggerCache.clear();
483
+ function decodeCborCompat(buffer) {
484
+ return reviveJsonCompatValue(cbor.decode(buffer));
485
485
  }
486
- function getBaseLogger() {
487
- if (!baseLogger) {
488
- configureDefaultLogger();
486
+ function serializeWithEncoding(encoding, value, versionedDataHandler, version, zodSchema, toJson, toBare) {
487
+ if (encoding === "json") {
488
+ const jsonValue = toJson(value);
489
+ const validated = zodSchema.parse(jsonValue);
490
+ return jsonStringifyCompat(validated);
491
+ } else if (encoding === "cbor") {
492
+ const jsonValue = toJson(value);
493
+ const validated = zodSchema.parse(jsonValue);
494
+ return cbor.encode(validated);
495
+ } else if (encoding === "bare") {
496
+ if (!versionedDataHandler) {
497
+ throw new Error(
498
+ "VersionedDataHandler is required for 'bare' encoding"
499
+ );
500
+ }
501
+ if (version === void 0) {
502
+ throw new Error("version is required for 'bare' encoding");
503
+ }
504
+ const bareValue = toBare(value);
505
+ return versionedDataHandler.serializeWithEmbeddedVersion(
506
+ bareValue,
507
+ version
508
+ );
509
+ } else {
510
+ assertUnreachable(encoding);
489
511
  }
490
- return baseLogger;
491
512
  }
492
- function getLogger(name = "default") {
493
- const cached = loggerCache.get(name);
494
- if (cached) {
495
- return cached;
513
+ function deserializeWithEncoding(encoding, buffer, versionedDataHandler, zodSchema, fromJson, fromBare) {
514
+ if (encoding === "json") {
515
+ let parsed;
516
+ if (typeof buffer === "string") {
517
+ parsed = jsonParseCompat(buffer);
518
+ } else {
519
+ const decoder = new TextDecoder("utf-8");
520
+ const jsonString = decoder.decode(buffer);
521
+ parsed = jsonParseCompat(jsonString);
522
+ }
523
+ const validated = zodSchema.parse(parsed);
524
+ return fromJson(validated);
525
+ } else if (encoding === "cbor") {
526
+ invariant(
527
+ typeof buffer !== "string",
528
+ "buffer cannot be string for cbor encoding"
529
+ );
530
+ const decoded = decodeCborCompat(buffer);
531
+ const validated = zodSchema.parse(decoded);
532
+ return fromJson(validated);
533
+ } else if (encoding === "bare") {
534
+ invariant(
535
+ typeof buffer !== "string",
536
+ "buffer cannot be string for bare encoding"
537
+ );
538
+ if (!versionedDataHandler) {
539
+ throw new Error(
540
+ "VersionedDataHandler is required for 'bare' encoding"
541
+ );
542
+ }
543
+ const bareValue = versionedDataHandler.deserializeWithEmbeddedVersion(buffer);
544
+ return fromBare(bareValue);
545
+ } else {
546
+ assertUnreachable(encoding);
496
547
  }
497
- const base = getBaseLogger();
498
- const child = getIncludeTarget() ? base.child({ target: name }) : base;
499
- loggerCache.set(name, child);
500
- return child;
501
548
  }
502
- var PINO_LEVEL_LABELS = {
503
- 10: "trace",
504
- 20: "debug",
505
- 30: "info",
506
- 40: "warn",
507
- 50: "error",
508
- 60: "fatal"
509
- };
510
- function createLogfmtDestination() {
511
- return {
512
- write(msg) {
513
- const line = formatLogfmtLine(msg);
514
- if (typeof process !== "undefined" && process.stdout?.write) {
515
- process.stdout.write(`${line}
516
- `);
517
- } else {
518
- console.log(line);
519
- }
520
- }
521
- };
549
+
550
+ // src/common/encoding.ts
551
+ var JSON_COMPAT_BIGINT = "$BigInt";
552
+ var JSON_COMPAT_ARRAY_BUFFER = "$ArrayBuffer";
553
+ var JSON_COMPAT_UINT8_ARRAY = "$Uint8Array";
554
+ var JSON_COMPAT_UNDEFINED = "$Undefined";
555
+ var JSON_COMPAT_SET = "$Set";
556
+ function isTypedArray(value) {
557
+ 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;
522
558
  }
523
- function formatLogfmtLine(raw) {
524
- let data;
525
- try {
526
- data = JSON.parse(raw);
527
- } catch {
528
- return raw.trimEnd();
559
+ var EncodingSchema = z.enum(["json", "cbor", "bare"]);
560
+ async function inputDataToBuffer(data) {
561
+ if (typeof data === "string") {
562
+ return data;
529
563
  }
530
- const parts = [];
531
- appendLogfmtEntry(parts, "level", formatPinoLevel(data.level));
532
- if (data.time !== void 0) {
533
- appendLogfmtEntry(parts, "ts", data.time);
564
+ if (data instanceof Blob) {
565
+ return new Uint8Array(await data.arrayBuffer());
534
566
  }
535
- for (const [key, value] of Object.entries(data)) {
536
- if (key === "level" || key === "time") {
537
- continue;
538
- }
539
- appendLogfmtEntry(parts, key, value);
567
+ if (data instanceof Uint8Array) {
568
+ return data;
540
569
  }
541
- return parts.join(" ");
542
- }
543
- function formatPinoLevel(level) {
544
- if (typeof level === "number") {
545
- return PINO_LEVEL_LABELS[level] ?? level.toString();
570
+ if (data instanceof ArrayBuffer || data instanceof SharedArrayBuffer) {
571
+ return new Uint8Array(data);
546
572
  }
547
- if (typeof level === "string") {
548
- return level.toLowerCase();
573
+ throw new Error("Malformed message");
574
+ }
575
+ function base64EncodeUint8Array(uint8Array) {
576
+ let binary = "";
577
+ for (const value of uint8Array) {
578
+ binary += String.fromCharCode(value);
549
579
  }
550
- return "info";
580
+ return btoa(binary);
551
581
  }
552
- function appendLogfmtEntry(parts, key, value) {
553
- const safeKey = key.replace(/[\s="]/g, "");
554
- if (safeKey.length === 0) {
555
- return;
582
+ function base64EncodeArrayBuffer(arrayBuffer) {
583
+ return base64EncodeUint8Array(new Uint8Array(arrayBuffer));
584
+ }
585
+ function isPlainObject(value) {
586
+ if (value === null || typeof value !== "object") {
587
+ return false;
556
588
  }
557
- parts.push(`${safeKey}=${formatLogfmtValue(value)}`);
589
+ const proto = Object.getPrototypeOf(value);
590
+ return proto === Object.prototype || proto === null;
558
591
  }
559
- function formatLogfmtValue(value) {
560
- if (typeof value === "number" || typeof value === "boolean") {
561
- return String(value);
592
+ function encodeJsonCompatValue(input) {
593
+ if (input === null) {
594
+ return input;
562
595
  }
563
- if (value === null || value === void 0) {
564
- return "null";
596
+ if (input === void 0) {
597
+ return [JSON_COMPAT_UNDEFINED, 0];
565
598
  }
566
- if (typeof value === "string") {
567
- return quoteLogfmtString(value);
599
+ if (typeof input === "string" || typeof input === "number" || typeof input === "boolean") {
600
+ return input;
568
601
  }
569
- return quoteLogfmtString(JSON.stringify(value));
602
+ if (typeof input === "bigint") {
603
+ return [JSON_COMPAT_BIGINT, input.toString()];
604
+ }
605
+ if (input instanceof ArrayBuffer) {
606
+ return [JSON_COMPAT_ARRAY_BUFFER, base64EncodeArrayBuffer(input)];
607
+ }
608
+ if (input instanceof Uint8Array) {
609
+ return [JSON_COMPAT_UINT8_ARRAY, base64EncodeUint8Array(input)];
610
+ }
611
+ if (isTypedArray(input)) {
612
+ return input;
613
+ }
614
+ if (input instanceof Date || input instanceof RegExp || input instanceof Error) {
615
+ return input;
616
+ }
617
+ if (input instanceof Set) {
618
+ const encoded = [...input.values()].map(
619
+ (v) => encodeJsonCompatValue(v)
620
+ );
621
+ return [JSON_COMPAT_SET, encoded];
622
+ }
623
+ if (input instanceof Map) {
624
+ const encoded = /* @__PURE__ */ new Map();
625
+ for (const [k, v] of input.entries()) {
626
+ encoded.set(
627
+ encodeJsonCompatValue(k),
628
+ encodeJsonCompatValue(v)
629
+ );
630
+ }
631
+ return encoded;
632
+ }
633
+ if (Array.isArray(input)) {
634
+ const encoded = input.map(
635
+ (value) => encodeJsonCompatValue(value)
636
+ );
637
+ if (encoded.length === 2 && typeof encoded[0] === "string" && encoded[0].startsWith("$")) {
638
+ return [`$${encoded[0]}`, encoded[1]];
639
+ }
640
+ return encoded;
641
+ }
642
+ if (isPlainObject(input)) {
643
+ const encoded = {};
644
+ for (const [key, value] of Object.entries(input)) {
645
+ encoded[key] = encodeJsonCompatValue(value);
646
+ }
647
+ return encoded;
648
+ }
649
+ const typeName = typeof input === "object" && input !== null ? input.constructor?.name ?? typeof input : typeof input;
650
+ throw new TypeError(`Value of type "${typeName}" is not CBOR serializable`);
570
651
  }
571
- function quoteLogfmtString(value) {
572
- if (!/[\s="]/.test(value)) {
573
- return value;
652
+ function reviveJsonCompatValue(input, options = {}) {
653
+ if (typeof input === "bigint") {
654
+ if (options.coerceSafeIntegerBigInts && input >= BigInt(Number.MIN_SAFE_INTEGER) && input <= BigInt(Number.MAX_SAFE_INTEGER)) {
655
+ return Number(input);
656
+ }
657
+ return input;
574
658
  }
575
- return `"${value.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "\\n")}"`;
659
+ if (input instanceof Map) {
660
+ const revived = /* @__PURE__ */ new Map();
661
+ for (const [k, v] of input.entries()) {
662
+ revived.set(
663
+ reviveJsonCompatValue(k, options),
664
+ reviveJsonCompatValue(v, options)
665
+ );
666
+ }
667
+ return revived;
668
+ }
669
+ if (Array.isArray(input)) {
670
+ if (input.length === 2 && typeof input[0] === "string" && input[0].startsWith("$")) {
671
+ if (input[0] === JSON_COMPAT_BIGINT) {
672
+ return BigInt(input[1]);
673
+ }
674
+ if (input[0] === JSON_COMPAT_ARRAY_BUFFER) {
675
+ return base64DecodeToArrayBuffer(input[1]);
676
+ }
677
+ if (input[0] === JSON_COMPAT_UINT8_ARRAY) {
678
+ return base64DecodeToUint8Array(input[1]);
679
+ }
680
+ if (input[0] === JSON_COMPAT_UNDEFINED) {
681
+ return void 0;
682
+ }
683
+ if (input[0] === JSON_COMPAT_SET) {
684
+ const items = input[1].map(
685
+ (v) => reviveJsonCompatValue(v, options)
686
+ );
687
+ return new Set(items);
688
+ }
689
+ if (input[0].startsWith("$$")) {
690
+ return [
691
+ input[0].substring(1),
692
+ reviveJsonCompatValue(input[1], options)
693
+ ];
694
+ }
695
+ throw new Error(
696
+ `Unknown JSON encoding type: ${input[0]}. This may indicate corrupted data or a version mismatch.`
697
+ );
698
+ }
699
+ return input.map((value) => reviveJsonCompatValue(value, options));
700
+ }
701
+ if (isPlainObject(input)) {
702
+ const decoded = {};
703
+ for (const [key, value] of Object.entries(input)) {
704
+ decoded[key] = reviveJsonCompatValue(value, options);
705
+ }
706
+ return decoded;
707
+ }
708
+ return input;
709
+ }
710
+ function base64DecodeToUint8Array(base64) {
711
+ if (typeof Buffer !== "undefined") {
712
+ return new Uint8Array(Buffer.from(base64, "base64"));
713
+ }
714
+ const binary = atob(base64);
715
+ const bytes = new Uint8Array(binary.length);
716
+ for (let i = 0; i < binary.length; i++) {
717
+ bytes[i] = binary.charCodeAt(i);
718
+ }
719
+ return bytes;
720
+ }
721
+ function base64DecodeToArrayBuffer(base64) {
722
+ return base64DecodeToUint8Array(base64).buffer;
723
+ }
724
+ function jsonStringifyCompat(input, space) {
725
+ return JSON.stringify(
726
+ input,
727
+ (_key, value) => {
728
+ if (typeof value === "bigint") {
729
+ return [JSON_COMPAT_BIGINT, value.toString()];
730
+ }
731
+ if (value instanceof ArrayBuffer) {
732
+ return [
733
+ JSON_COMPAT_ARRAY_BUFFER,
734
+ base64EncodeArrayBuffer(value)
735
+ ];
736
+ }
737
+ if (value instanceof Uint8Array) {
738
+ return [JSON_COMPAT_UINT8_ARRAY, base64EncodeUint8Array(value)];
739
+ }
740
+ if (Array.isArray(value) && value.length === 2 && typeof value[0] === "string" && value[0].startsWith("$")) {
741
+ return [`$${value[0]}`, value[1]];
742
+ }
743
+ return value;
744
+ },
745
+ space
746
+ );
747
+ }
748
+ function jsonParseCompat(input) {
749
+ return reviveJsonCompatValue(JSON.parse(input));
576
750
  }
577
751
 
578
752
  // src/utils.ts
@@ -636,13 +810,173 @@ function combineUrlPath(endpoint, path, queryParams) {
636
810
  return `${baseUrl.protocol}//${baseUrl.host}${fullPath}${fullQuery}`;
637
811
  }
638
812
 
813
+ // src/utils/env-vars.ts
814
+ var getRivetEngine = () => getEnvUniversal("RIVET_ENGINE");
815
+ var getRivetEndpoint = () => getEnvUniversal("RIVET_ENDPOINT");
816
+ var getRivetToken = () => getEnvUniversal("RIVET_TOKEN");
817
+ var getRivetNamespace = () => getEnvUniversal("RIVET_NAMESPACE");
818
+ var getRivetPool = () => getEnvUniversal("RIVET_POOL");
819
+ var getLogLevel = () => getEnvUniversal("RIVET_LOG_LEVEL") ?? getEnvUniversal("LOG_LEVEL");
820
+ var getLogTarget = () => getEnvUniversal("RIVET_LOG_TARGET") === "1";
821
+ var getLogTimestamp = () => getEnvUniversal("RIVET_LOG_TIMESTAMP") === "1";
822
+ var getLogMessage = () => getEnvUniversal("RIVET_LOG_MESSAGE") === "1";
823
+ var getLogErrorStack = () => getEnvUniversal("RIVET_LOG_ERROR_STACK") === "1";
824
+ var getNextPhase = () => getEnvUniversal("NEXT_PHASE");
825
+
826
+ // src/common/log.ts
827
+ var baseLogger;
828
+ var configuredLogLevel;
829
+ var loggerCache = /* @__PURE__ */ new Map();
830
+ var LogLevelSchema = z2.enum([
831
+ "trace",
832
+ "debug",
833
+ "info",
834
+ "warn",
835
+ "error",
836
+ "fatal",
837
+ "silent"
838
+ ]);
839
+ function getPinoLevel(logLevel) {
840
+ if (logLevel) {
841
+ return logLevel;
842
+ }
843
+ if (configuredLogLevel) {
844
+ return configuredLogLevel;
845
+ }
846
+ const raw = (getLogLevel() || "warn").toString().toLowerCase();
847
+ const parsed = LogLevelSchema.safeParse(raw);
848
+ if (parsed.success) {
849
+ return parsed.data;
850
+ }
851
+ return "info";
852
+ }
853
+ function getIncludeTarget() {
854
+ return getLogTarget();
855
+ }
856
+ function makeDefaultLogger(logLevel) {
857
+ return pino(
858
+ {
859
+ level: getPinoLevel(logLevel),
860
+ messageKey: "msg",
861
+ // Do not include pid/hostname in output
862
+ base: {},
863
+ errorKey: "error",
864
+ // Keep the numeric level so the logfmt sink can match Pino's levels.
865
+ formatters: {
866
+ level(_label, number) {
867
+ return { level: number };
868
+ }
869
+ },
870
+ timestamp: getLogTimestamp() ? stdTimeFunctions.epochTime : false
871
+ },
872
+ createLogfmtDestination()
873
+ );
874
+ }
875
+ function configureDefaultLogger(logLevel) {
876
+ if (logLevel) {
877
+ configuredLogLevel = logLevel;
878
+ }
879
+ baseLogger = makeDefaultLogger(logLevel);
880
+ loggerCache.clear();
881
+ }
882
+ function getBaseLogger() {
883
+ if (!baseLogger) {
884
+ configureDefaultLogger();
885
+ }
886
+ return baseLogger;
887
+ }
888
+ function getLogger(name = "default") {
889
+ const cached = loggerCache.get(name);
890
+ if (cached) {
891
+ return cached;
892
+ }
893
+ const base = getBaseLogger();
894
+ const child = getIncludeTarget() ? base.child({ target: name }) : base;
895
+ loggerCache.set(name, child);
896
+ return child;
897
+ }
898
+ var PINO_LEVEL_LABELS = {
899
+ 10: "trace",
900
+ 20: "debug",
901
+ 30: "info",
902
+ 40: "warn",
903
+ 50: "error",
904
+ 60: "fatal"
905
+ };
906
+ function createLogfmtDestination() {
907
+ return {
908
+ write(msg) {
909
+ const line = formatLogfmtLine(msg);
910
+ if (typeof process !== "undefined" && process.stdout?.write) {
911
+ process.stdout.write(`${line}
912
+ `);
913
+ } else {
914
+ console.log(line);
915
+ }
916
+ }
917
+ };
918
+ }
919
+ function formatLogfmtLine(raw) {
920
+ let data;
921
+ try {
922
+ data = JSON.parse(raw);
923
+ } catch {
924
+ return raw.trimEnd();
925
+ }
926
+ const parts = [];
927
+ appendLogfmtEntry(parts, "level", formatPinoLevel(data.level));
928
+ if (data.time !== void 0) {
929
+ appendLogfmtEntry(parts, "ts", data.time);
930
+ }
931
+ for (const [key, value] of Object.entries(data)) {
932
+ if (key === "level" || key === "time") {
933
+ continue;
934
+ }
935
+ appendLogfmtEntry(parts, key, value);
936
+ }
937
+ return parts.join(" ");
938
+ }
939
+ function formatPinoLevel(level) {
940
+ if (typeof level === "number") {
941
+ return PINO_LEVEL_LABELS[level] ?? level.toString();
942
+ }
943
+ if (typeof level === "string") {
944
+ return level.toLowerCase();
945
+ }
946
+ return "info";
947
+ }
948
+ function appendLogfmtEntry(parts, key, value) {
949
+ const safeKey = key.replace(/[\s="]/g, "");
950
+ if (safeKey.length === 0) {
951
+ return;
952
+ }
953
+ parts.push(`${safeKey}=${formatLogfmtValue(value)}`);
954
+ }
955
+ function formatLogfmtValue(value) {
956
+ if (typeof value === "number" || typeof value === "boolean") {
957
+ return String(value);
958
+ }
959
+ if (value === null || value === void 0) {
960
+ return "null";
961
+ }
962
+ if (typeof value === "string") {
963
+ return quoteLogfmtString(value);
964
+ }
965
+ return quoteLogfmtString(JSON.stringify(value));
966
+ }
967
+ function quoteLogfmtString(value) {
968
+ if (!/[\s="]/.test(value)) {
969
+ return value;
970
+ }
971
+ return `"${value.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "\\n")}"`;
972
+ }
973
+
639
974
  // src/devtools-loader/log.ts
640
975
  function logger() {
641
976
  return getLogger("devtools");
642
977
  }
643
978
 
644
979
  // src/devtools-loader/index.ts
645
- var DEFAULT_DEVTOOLS_URL = (version = VERSION) => `https://releases.rivet.dev/rivet/latest/devtools/mod.js?v=${version}`;
646
980
  var scriptId = "rivetkit-devtools-script";
647
981
  function injectDevtools(config) {
648
982
  if (!window) {
@@ -650,9 +984,10 @@ function injectDevtools(config) {
650
984
  return;
651
985
  }
652
986
  if (!document.getElementById(scriptId)) {
987
+ const src = `${config.endpoint?.replace(/\/$/, "")}/devtools/mod.js`;
653
988
  const script = document.createElement("script");
654
989
  script.id = scriptId;
655
- script.src = DEFAULT_DEVTOOLS_URL();
990
+ script.src = src;
656
991
  script.async = true;
657
992
  document.head.appendChild(script);
658
993
  }
@@ -691,354 +1026,109 @@ var QUEUE_NAMESPACE = {
691
1026
  MESSAGES: Uint8Array.from([2])
692
1027
  };
693
1028
  function concatPrefix(prefix, suffix) {
694
- const merged = new Uint8Array(prefix.length + suffix.length);
695
- merged.set(prefix, 0);
696
- merged.set(suffix, prefix.length);
697
- return merged;
698
- }
699
- var QUEUE_STORAGE_PREFIX = concatPrefix(
700
- KEYS.QUEUE_PREFIX,
701
- STORAGE_VERSION_BYTES.QUEUE
702
- );
703
- var QUEUE_METADATA_KEY = concatPrefix(
704
- QUEUE_STORAGE_PREFIX,
705
- QUEUE_NAMESPACE.METADATA
706
- );
707
- var QUEUE_MESSAGES_PREFIX = concatPrefix(
708
- QUEUE_STORAGE_PREFIX,
709
- QUEUE_NAMESPACE.MESSAGES
710
- );
711
- var WORKFLOW_STORAGE_PREFIX = concatPrefix(
712
- KEYS.WORKFLOW_PREFIX,
713
- STORAGE_VERSION_BYTES.WORKFLOW
714
- );
715
- var TRACES_STORAGE_PREFIX = concatPrefix(
716
- KEYS.TRACES_PREFIX,
717
- STORAGE_VERSION_BYTES.TRACES
718
- );
719
- function serializeActorKey(key) {
720
- if (key.length === 0) {
721
- return EMPTY_KEY;
722
- }
723
- const escapedParts = key.map((part) => {
724
- if (part === "") {
725
- return "\\0";
726
- }
727
- let escaped = part.replace(/\\/g, "\\\\");
728
- escaped = escaped.replace(/\//g, `\\${KEY_SEPARATOR}`);
729
- return escaped;
730
- });
731
- return escapedParts.join(KEY_SEPARATOR);
732
- }
733
- function deserializeActorKey(keyString) {
734
- if (keyString === void 0 || keyString === null || keyString === EMPTY_KEY) {
735
- return [];
736
- }
737
- const parts = [];
738
- let currentPart = "";
739
- let escaping = false;
740
- let isEmptyStringMarker = false;
741
- for (let i = 0; i < keyString.length; i++) {
742
- const char = keyString[i];
743
- if (escaping) {
744
- if (char === "0") {
745
- isEmptyStringMarker = true;
746
- } else {
747
- currentPart += char;
748
- }
749
- escaping = false;
750
- } else if (char === "\\") {
751
- escaping = true;
752
- } else if (char === KEY_SEPARATOR) {
753
- if (isEmptyStringMarker) {
754
- parts.push("");
755
- isEmptyStringMarker = false;
756
- } else {
757
- parts.push(currentPart);
758
- }
759
- currentPart = "";
760
- } else {
761
- currentPart += char;
762
- }
763
- }
764
- if (escaping) {
765
- parts.push(currentPart + "\\");
766
- } else if (isEmptyStringMarker) {
767
- parts.push("");
768
- } else if (currentPart !== "" || parts.length > 0) {
769
- parts.push(currentPart);
770
- }
771
- return parts;
772
- }
773
-
774
- // src/common/actor-router-consts.ts
775
- var PATH_CONNECT = "/connect";
776
- var PATH_WEBSOCKET_BASE = "/websocket";
777
- var PATH_WEBSOCKET_PREFIX = "/websocket/";
778
- var HEADER_ENCODING = "x-rivet-encoding";
779
- var HEADER_CONN_PARAMS = "x-rivet-conn-params";
780
- var HEADER_RIVET_TOKEN = "x-rivet-token";
781
- var HEADER_RIVET_TARGET = "x-rivet-target";
782
- var HEADER_RIVET_ACTOR = "x-rivet-actor";
783
- var HEADER_RIVET_SKIP_READY_WAIT = "x-rivet-skip-ready-wait";
784
- var WS_PROTOCOL_STANDARD = "rivet";
785
- var WS_PROTOCOL_TARGET = "rivet_target.";
786
- var WS_PROTOCOL_ACTOR = "rivet_actor.";
787
- var WS_PROTOCOL_ENCODING = "rivet_encoding.";
788
- var WS_PROTOCOL_CONN_PARAMS = "rivet_conn_params.";
789
- var WS_PROTOCOL_TOKEN = "rivet_token.";
790
- var WS_PROTOCOL_SKIP_READY_WAIT = "rivet_skip_ready_wait";
791
- var WS_PROTOCOL_TEST_ACK_HOOK = "rivet_test_ack_hook.";
792
-
793
- // src/engine-client/driver.ts
794
- function shouldSkipReadyWait(options = {}) {
795
- return options.skipReadyWait === true;
796
- }
797
-
798
- // src/serde.ts
799
- import * as cbor from "cbor-x";
800
- import invariant from "invariant";
801
-
802
- // src/common/encoding.ts
803
- import { z as z2 } from "zod/v4";
804
- var JSON_COMPAT_BIGINT = "$BigInt";
805
- var JSON_COMPAT_ARRAY_BUFFER = "$ArrayBuffer";
806
- var JSON_COMPAT_UINT8_ARRAY = "$Uint8Array";
807
- var JSON_COMPAT_UNDEFINED = "$Undefined";
808
- var EncodingSchema = z2.enum(["json", "cbor", "bare"]);
809
- async function inputDataToBuffer(data) {
810
- if (typeof data === "string") {
811
- return data;
812
- }
813
- if (data instanceof Blob) {
814
- return new Uint8Array(await data.arrayBuffer());
815
- }
816
- if (data instanceof Uint8Array) {
817
- return data;
818
- }
819
- if (data instanceof ArrayBuffer || data instanceof SharedArrayBuffer) {
820
- return new Uint8Array(data);
821
- }
822
- throw new Error("Malformed message");
823
- }
824
- function base64EncodeUint8Array(uint8Array) {
825
- let binary = "";
826
- for (const value of uint8Array) {
827
- binary += String.fromCharCode(value);
828
- }
829
- return btoa(binary);
830
- }
831
- function base64EncodeArrayBuffer(arrayBuffer) {
832
- return base64EncodeUint8Array(new Uint8Array(arrayBuffer));
833
- }
834
- function isPlainObject(value) {
835
- if (value === null || typeof value !== "object") {
836
- return false;
837
- }
838
- const proto = Object.getPrototypeOf(value);
839
- return proto === Object.prototype || proto === null;
840
- }
841
- function encodeJsonCompatValue(input) {
842
- if (input === void 0) {
843
- return [JSON_COMPAT_UNDEFINED, 0];
844
- }
845
- if (typeof input === "bigint") {
846
- return [JSON_COMPAT_BIGINT, input.toString()];
847
- }
848
- if (input instanceof ArrayBuffer) {
849
- return [JSON_COMPAT_ARRAY_BUFFER, base64EncodeArrayBuffer(input)];
850
- }
851
- if (input instanceof Uint8Array) {
852
- return [JSON_COMPAT_UINT8_ARRAY, base64EncodeUint8Array(input)];
853
- }
854
- if (Array.isArray(input)) {
855
- const encoded = input.map((value) => encodeJsonCompatValue(value));
856
- if (encoded.length === 2 && typeof encoded[0] === "string" && encoded[0].startsWith("$")) {
857
- return ["$" + encoded[0], encoded[1]];
858
- }
859
- return encoded;
860
- }
861
- if (isPlainObject(input)) {
862
- const encoded = {};
863
- for (const [key, value] of Object.entries(input)) {
864
- encoded[key] = encodeJsonCompatValue(value);
865
- }
866
- return encoded;
867
- }
868
- return input;
869
- }
870
- function reviveJsonCompatValue(input, options = {}) {
871
- if (typeof input === "bigint") {
872
- if (options.coerceSafeIntegerBigInts && input >= BigInt(Number.MIN_SAFE_INTEGER) && input <= BigInt(Number.MAX_SAFE_INTEGER)) {
873
- return Number(input);
874
- }
875
- return input;
876
- }
877
- if (Array.isArray(input)) {
878
- if (input.length === 2 && typeof input[0] === "string" && input[0].startsWith("$")) {
879
- if (input[0] === JSON_COMPAT_BIGINT) {
880
- return BigInt(input[1]);
881
- }
882
- if (input[0] === JSON_COMPAT_ARRAY_BUFFER) {
883
- return base64DecodeToArrayBuffer(input[1]);
884
- }
885
- if (input[0] === JSON_COMPAT_UINT8_ARRAY) {
886
- return base64DecodeToUint8Array(input[1]);
887
- }
888
- if (input[0] === JSON_COMPAT_UNDEFINED) {
889
- return void 0;
890
- }
891
- if (input[0].startsWith("$$")) {
892
- return [
893
- input[0].substring(1),
894
- reviveJsonCompatValue(input[1], options)
895
- ];
896
- }
897
- throw new Error(
898
- `Unknown JSON encoding type: ${input[0]}. This may indicate corrupted data or a version mismatch.`
899
- );
900
- }
901
- return input.map((value) => reviveJsonCompatValue(value, options));
902
- }
903
- if (isPlainObject(input)) {
904
- const decoded = {};
905
- for (const [key, value] of Object.entries(input)) {
906
- decoded[key] = reviveJsonCompatValue(value, options);
907
- }
908
- return decoded;
909
- }
910
- return input;
1029
+ const merged = new Uint8Array(prefix.length + suffix.length);
1030
+ merged.set(prefix, 0);
1031
+ merged.set(suffix, prefix.length);
1032
+ return merged;
911
1033
  }
912
- function base64DecodeToUint8Array(base64) {
913
- if (typeof Buffer !== "undefined") {
914
- return new Uint8Array(Buffer.from(base64, "base64"));
915
- }
916
- const binary = atob(base64);
917
- const bytes = new Uint8Array(binary.length);
918
- for (let i = 0; i < binary.length; i++) {
919
- bytes[i] = binary.charCodeAt(i);
1034
+ var QUEUE_STORAGE_PREFIX = concatPrefix(
1035
+ KEYS.QUEUE_PREFIX,
1036
+ STORAGE_VERSION_BYTES.QUEUE
1037
+ );
1038
+ var QUEUE_METADATA_KEY = concatPrefix(
1039
+ QUEUE_STORAGE_PREFIX,
1040
+ QUEUE_NAMESPACE.METADATA
1041
+ );
1042
+ var QUEUE_MESSAGES_PREFIX = concatPrefix(
1043
+ QUEUE_STORAGE_PREFIX,
1044
+ QUEUE_NAMESPACE.MESSAGES
1045
+ );
1046
+ var WORKFLOW_STORAGE_PREFIX = concatPrefix(
1047
+ KEYS.WORKFLOW_PREFIX,
1048
+ STORAGE_VERSION_BYTES.WORKFLOW
1049
+ );
1050
+ var TRACES_STORAGE_PREFIX = concatPrefix(
1051
+ KEYS.TRACES_PREFIX,
1052
+ STORAGE_VERSION_BYTES.TRACES
1053
+ );
1054
+ function serializeActorKey(key) {
1055
+ if (key.length === 0) {
1056
+ return EMPTY_KEY;
920
1057
  }
921
- return bytes;
922
- }
923
- function base64DecodeToArrayBuffer(base64) {
924
- return base64DecodeToUint8Array(base64).buffer;
925
- }
926
- function jsonStringifyCompat(input) {
927
- return JSON.stringify(input, (_key, value) => {
928
- if (typeof value === "bigint") {
929
- return [JSON_COMPAT_BIGINT, value.toString()];
930
- }
931
- if (value instanceof ArrayBuffer) {
932
- return [
933
- JSON_COMPAT_ARRAY_BUFFER,
934
- base64EncodeArrayBuffer(value)
935
- ];
936
- }
937
- if (value instanceof Uint8Array) {
938
- return [
939
- JSON_COMPAT_UINT8_ARRAY,
940
- base64EncodeUint8Array(value)
941
- ];
942
- }
943
- if (Array.isArray(value) && value.length === 2 && typeof value[0] === "string" && value[0].startsWith("$")) {
944
- return ["$" + value[0], value[1]];
1058
+ const escapedParts = key.map((part) => {
1059
+ if (part === "") {
1060
+ return "\\0";
945
1061
  }
946
- return value;
1062
+ let escaped = part.replace(/\\/g, "\\\\");
1063
+ escaped = escaped.replace(/\//g, `\\${KEY_SEPARATOR}`);
1064
+ return escaped;
947
1065
  });
1066
+ return escapedParts.join(KEY_SEPARATOR);
948
1067
  }
949
- function jsonParseCompat(input) {
950
- return reviveJsonCompatValue(JSON.parse(input));
951
- }
952
-
953
- // src/serde.ts
954
- function uint8ArrayToBase64(uint8Array) {
955
- if (typeof Buffer !== "undefined") {
956
- return Buffer.from(uint8Array).toString("base64");
957
- }
958
- let binary = "";
959
- const len = uint8Array.byteLength;
960
- for (let i = 0; i < len; i++) {
961
- binary += String.fromCharCode(uint8Array[i]);
962
- }
963
- return btoa(binary);
964
- }
965
- function contentTypeForEncoding(encoding) {
966
- if (encoding === "json") {
967
- return "application/json";
968
- } else if (encoding === "cbor" || encoding === "bare") {
969
- return "application/octet-stream";
970
- } else {
971
- assertUnreachable(encoding);
972
- }
973
- }
974
- function encodeCborCompat(value) {
975
- return cbor.encode(encodeJsonCompatValue(value));
976
- }
977
- function decodeCborCompat(buffer) {
978
- return reviveJsonCompatValue(cbor.decode(buffer));
979
- }
980
- function serializeWithEncoding(encoding, value, versionedDataHandler, version, zodSchema, toJson, toBare) {
981
- if (encoding === "json") {
982
- const jsonValue = toJson(value);
983
- const validated = zodSchema.parse(jsonValue);
984
- return jsonStringifyCompat(validated);
985
- } else if (encoding === "cbor") {
986
- const jsonValue = toJson(value);
987
- const validated = zodSchema.parse(jsonValue);
988
- return cbor.encode(validated);
989
- } else if (encoding === "bare") {
990
- if (!versionedDataHandler) {
991
- throw new Error(
992
- "VersionedDataHandler is required for 'bare' encoding"
993
- );
994
- }
995
- if (version === void 0) {
996
- throw new Error("version is required for 'bare' encoding");
997
- }
998
- const bareValue = toBare(value);
999
- return versionedDataHandler.serializeWithEmbeddedVersion(
1000
- bareValue,
1001
- version
1002
- );
1003
- } else {
1004
- assertUnreachable(encoding);
1068
+ function deserializeActorKey(keyString) {
1069
+ if (keyString === void 0 || keyString === null || keyString === EMPTY_KEY) {
1070
+ return [];
1005
1071
  }
1006
- }
1007
- function deserializeWithEncoding(encoding, buffer, versionedDataHandler, zodSchema, fromJson, fromBare) {
1008
- if (encoding === "json") {
1009
- let parsed;
1010
- if (typeof buffer === "string") {
1011
- parsed = jsonParseCompat(buffer);
1072
+ const parts = [];
1073
+ let currentPart = "";
1074
+ let escaping = false;
1075
+ let isEmptyStringMarker = false;
1076
+ for (let i = 0; i < keyString.length; i++) {
1077
+ const char = keyString[i];
1078
+ if (escaping) {
1079
+ if (char === "0") {
1080
+ isEmptyStringMarker = true;
1081
+ } else {
1082
+ currentPart += char;
1083
+ }
1084
+ escaping = false;
1085
+ } else if (char === "\\") {
1086
+ escaping = true;
1087
+ } else if (char === KEY_SEPARATOR) {
1088
+ if (isEmptyStringMarker) {
1089
+ parts.push("");
1090
+ isEmptyStringMarker = false;
1091
+ } else {
1092
+ parts.push(currentPart);
1093
+ }
1094
+ currentPart = "";
1012
1095
  } else {
1013
- const decoder = new TextDecoder("utf-8");
1014
- const jsonString = decoder.decode(buffer);
1015
- parsed = jsonParseCompat(jsonString);
1016
- }
1017
- const validated = zodSchema.parse(parsed);
1018
- return fromJson(validated);
1019
- } else if (encoding === "cbor") {
1020
- invariant(
1021
- typeof buffer !== "string",
1022
- "buffer cannot be string for cbor encoding"
1023
- );
1024
- const decoded = decodeCborCompat(buffer);
1025
- const validated = zodSchema.parse(decoded);
1026
- return fromJson(validated);
1027
- } else if (encoding === "bare") {
1028
- invariant(
1029
- typeof buffer !== "string",
1030
- "buffer cannot be string for bare encoding"
1031
- );
1032
- if (!versionedDataHandler) {
1033
- throw new Error(
1034
- "VersionedDataHandler is required for 'bare' encoding"
1035
- );
1096
+ currentPart += char;
1036
1097
  }
1037
- const bareValue = versionedDataHandler.deserializeWithEmbeddedVersion(buffer);
1038
- return fromBare(bareValue);
1039
- } else {
1040
- assertUnreachable(encoding);
1041
1098
  }
1099
+ if (escaping) {
1100
+ parts.push(`${currentPart}\\`);
1101
+ } else if (isEmptyStringMarker) {
1102
+ parts.push("");
1103
+ } else if (currentPart !== "" || parts.length > 0) {
1104
+ parts.push(currentPart);
1105
+ }
1106
+ return parts;
1107
+ }
1108
+
1109
+ // src/common/actor-router-consts.ts
1110
+ var PATH_CONNECT = "/connect";
1111
+ var PATH_WEBSOCKET_BASE = "/websocket";
1112
+ var PATH_WEBSOCKET_PREFIX = "/websocket/";
1113
+ var HEADER_ENCODING = "x-rivet-encoding";
1114
+ var HEADER_CONN_PARAMS = "x-rivet-conn-params";
1115
+ var HEADER_ORIGINAL_REQUEST_URL = "x-rivet-internal-original-request-url";
1116
+ var HEADER_RIVET_TOKEN = "x-rivet-token";
1117
+ var HEADER_RIVET_TARGET = "x-rivet-target";
1118
+ var HEADER_RIVET_ACTOR = "x-rivet-actor";
1119
+ var HEADER_RIVET_SKIP_READY_WAIT = "x-rivet-skip-ready-wait";
1120
+ var WS_PROTOCOL_STANDARD = "rivet";
1121
+ var WS_PROTOCOL_TARGET = "rivet_target.";
1122
+ var WS_PROTOCOL_ACTOR = "rivet_actor.";
1123
+ var WS_PROTOCOL_ENCODING = "rivet_encoding.";
1124
+ var WS_PROTOCOL_CONN_PARAMS = "rivet_conn_params.";
1125
+ var WS_PROTOCOL_TOKEN = "rivet_token.";
1126
+ var WS_PROTOCOL_SKIP_READY_WAIT = "rivet_skip_ready_wait";
1127
+ var WS_PROTOCOL_TEST_ACK_HOOK = "rivet_test_ack_hook.";
1128
+
1129
+ // src/engine-client/driver.ts
1130
+ function shouldSkipReadyWait(options = {}) {
1131
+ return options.skipReadyWait === true;
1042
1132
  }
1043
1133
 
1044
1134
  // src/engine-client/actor-http-client.ts
@@ -1049,23 +1139,19 @@ async function sendHttpRequestToGateway(runConfig, gatewayUrl, actorRequest, opt
1049
1139
  if (actorRequest.bodyUsed) {
1050
1140
  throw new Error("Request body has already been consumed");
1051
1141
  }
1052
- const reqBody = await actorRequest.arrayBuffer();
1053
- if (reqBody.byteLength !== 0) {
1054
- bodyToSend = reqBody;
1142
+ if (actorRequest.body) {
1143
+ bodyToSend = actorRequest.body;
1055
1144
  guardHeaders.delete("transfer-encoding");
1056
- guardHeaders.set("content-length", String(bodyToSend.byteLength));
1145
+ guardHeaders.delete("content-length");
1057
1146
  }
1058
1147
  }
1059
- const guardRequest = new Request(gatewayUrl, {
1148
+ return fetch(gatewayUrl, {
1060
1149
  method: actorRequest.method,
1061
1150
  headers: guardHeaders,
1062
1151
  body: bodyToSend,
1063
- signal: actorRequest.signal
1152
+ signal: actorRequest.signal,
1153
+ ...bodyToSend ? { duplex: "half" } : {}
1064
1154
  });
1065
- return mutableResponse(await fetch(guardRequest));
1066
- }
1067
- function mutableResponse(fetchRes) {
1068
- return new Response(fetchRes.body, fetchRes);
1069
1155
  }
1070
1156
  function buildGuardHeaders(runConfig, actorRequest, options) {
1071
1157
  const headers = new Headers();
@@ -3853,13 +3939,6 @@ async function destroyActor(config, actorId) {
3853
3939
  async function getMetadata(config) {
3854
3940
  return apiCall(config, "GET", `/metadata`);
3855
3941
  }
3856
- async function kvGet(config, actorId, key) {
3857
- return apiCall(
3858
- config,
3859
- "GET",
3860
- `/actors/${encodeURIComponent(actorId)}/kv/keys/${encodeURIComponent(key)}`
3861
- );
3862
- }
3863
3942
 
3864
3943
  // src/engine-client/metadata.ts
3865
3944
  import pRetry from "p-retry";
@@ -3905,11 +3984,11 @@ async function lookupMetadataCached(config) {
3905
3984
  }
3906
3985
 
3907
3986
  // src/engine-client/ws-proxy.ts
3908
- async function createWebSocketProxy(c, targetUrl, protocols) {
3987
+ async function createWebSocketProxy(_c, targetUrl, protocols) {
3909
3988
  const WebSocket2 = await importWebSocket();
3910
3989
  const state = {};
3911
3990
  return {
3912
- onOpen: async (event, clientWs) => {
3991
+ onOpen: async (_event, clientWs) => {
3913
3992
  logger3().debug({ msg: "client websocket connected", targetUrl });
3914
3993
  if (clientWs.readyState !== 1) {
3915
3994
  logger3().warn({
@@ -3947,23 +4026,25 @@ async function createWebSocketProxy(c, targetUrl, protocols) {
3947
4026
  reject(error);
3948
4027
  });
3949
4028
  });
3950
- state.targetWs.addEventListener("message", (event2) => {
3951
- if (typeof event2.data === "string" || event2.data instanceof ArrayBuffer) {
3952
- clientWs.send(event2.data);
3953
- } else if (event2.data instanceof Blob) {
3954
- event2.data.arrayBuffer().then((buffer) => {
4029
+ state.connectPromise.catch(() => {
4030
+ });
4031
+ state.targetWs.addEventListener("message", (event) => {
4032
+ if (typeof event.data === "string" || event.data instanceof ArrayBuffer) {
4033
+ clientWs.send(event.data);
4034
+ } else if (event.data instanceof Blob) {
4035
+ event.data.arrayBuffer().then((buffer) => {
3955
4036
  clientWs.send(buffer);
3956
4037
  });
3957
4038
  }
3958
4039
  });
3959
- state.targetWs.addEventListener("close", (event2) => {
4040
+ state.targetWs.addEventListener("close", (event) => {
3960
4041
  logger3().debug({
3961
4042
  msg: "target websocket closed",
3962
4043
  targetUrl,
3963
- code: event2.code,
3964
- reason: event2.reason
4044
+ code: event.code,
4045
+ reason: event.reason
3965
4046
  });
3966
- closeWebSocketIfOpen(clientWs, event2.code, event2.reason);
4047
+ closeWebSocketIfOpen(clientWs, event.code, event.reason);
3967
4048
  });
3968
4049
  state.targetWs.addEventListener("error", (error) => {
3969
4050
  logger3().error({
@@ -4006,7 +4087,7 @@ async function createWebSocketProxy(c, targetUrl, protocols) {
4006
4087
  );
4007
4088
  }
4008
4089
  },
4009
- onClose: (event, clientWs) => {
4090
+ onClose: (event, _clientWs) => {
4010
4091
  logger3().debug({
4011
4092
  msg: "client websocket closed",
4012
4093
  targetUrl,
@@ -4023,7 +4104,7 @@ async function createWebSocketProxy(c, targetUrl, protocols) {
4023
4104
  }
4024
4105
  }
4025
4106
  },
4026
- onError: (event, clientWs) => {
4107
+ onError: (event, _clientWs) => {
4027
4108
  logger3().error({ msg: "client websocket error", targetUrl, event });
4028
4109
  if (state.targetWs) {
4029
4110
  if (state.targetWs.readyState === WebSocket2.OPEN) {
@@ -4139,7 +4220,9 @@ var RemoteEngineControlClient = class {
4139
4220
  name,
4140
4221
  key: serializeActorKey(key),
4141
4222
  runner_name_selector: this.#config.poolName,
4142
- input: actorInput ? uint8ArrayToBase64(encodeCborCompat(actorInput)) : void 0,
4223
+ input: actorInput ? uint8ArrayToBase64(
4224
+ encodeCborCompat(actorInput)
4225
+ ) : void 0,
4143
4226
  crash_policy: crashPolicy ?? "sleep"
4144
4227
  });
4145
4228
  logger3().info({
@@ -4263,28 +4346,6 @@ var RemoteEngineControlClient = class {
4263
4346
  const args = await createWebSocketProxy(c, wsGuardUrl, protocols);
4264
4347
  return await upgradeWebSocket(() => args)(c, noopNext());
4265
4348
  }
4266
- async kvGet(actorId, key) {
4267
- await this.#metadataPromise;
4268
- logger3().debug({ msg: "getting kv value via engine api", key });
4269
- const response = await kvGet(
4270
- this.#config,
4271
- actorId,
4272
- new TextDecoder("utf8").decode(key)
4273
- );
4274
- return response.value;
4275
- }
4276
- async kvBatchGet(_actorId, _keys) {
4277
- throw new Error("kvBatchGet not supported on remote engine client");
4278
- }
4279
- async kvBatchPut(_actorId, _entries) {
4280
- throw new Error("kvBatchPut not supported on remote engine client");
4281
- }
4282
- async kvBatchDelete(_actorId, _keys) {
4283
- throw new Error("kvBatchDelete not supported on remote engine client");
4284
- }
4285
- async kvDeleteRange(_actorId, _start, _end) {
4286
- throw new Error("kvDeleteRange not supported on remote engine client");
4287
- }
4288
4349
  displayInformation() {
4289
4350
  return { properties: {} };
4290
4351
  }
@@ -4530,7 +4591,7 @@ function classifyActorError(error) {
4530
4591
  return void 0;
4531
4592
  }
4532
4593
  function isRetryableGuardGatewayHttpError(code) {
4533
- return code === "service_unavailable" || code === "actor_stopped_while_waiting" || code === "tunnel_request_aborted" || code === "tunnel_message_timeout" || code === "tunnel_response_closed" || code === "gateway_response_start_timeout";
4594
+ 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";
4534
4595
  }
4535
4596
  function classifyTransportError(error) {
4536
4597
  if (error.message.includes("database accessed after actor stopped")) {
@@ -4619,10 +4680,7 @@ async function retryOnLifecycleBoundary(run, opts) {
4619
4680
  if (attempt === maxAttempts - 1) {
4620
4681
  break;
4621
4682
  }
4622
- const delayMs = Math.min(
4623
- initialDelayMs * 2 ** attempt,
4624
- maxDelayMs
4625
- );
4683
+ const delayMs = Math.min(initialDelayMs * 2 ** attempt, maxDelayMs);
4626
4684
  await waitWithSignal(delayMs, opts?.signal);
4627
4685
  }
4628
4686
  }
@@ -4661,7 +4719,9 @@ function createQueueSender(senderOptions) {
4661
4719
  }),
4662
4720
  requestToBare: (value) => ({
4663
4721
  name: value.name ?? name,
4664
- body: bufferToArrayBuffer(encodeCborCompat(value.body)),
4722
+ body: bufferToArrayBuffer(
4723
+ encodeCborCompat(value.body)
4724
+ ),
4665
4725
  wait: value.wait ?? false,
4666
4726
  timeout: value.timeout !== void 0 ? BigInt(value.timeout) : null
4667
4727
  }),
@@ -4695,7 +4755,6 @@ function createQueueSender(senderOptions) {
4695
4755
  }
4696
4756
 
4697
4757
  // src/client/actor-conn.ts
4698
- var DEFAULT_MAX_INCOMING_MESSAGE_SIZE = 65536;
4699
4758
  var CONNECT_SYMBOL = /* @__PURE__ */ Symbol("connect");
4700
4759
  var ActorConnRaw = class {
4701
4760
  #disposed = false;
@@ -4747,6 +4806,9 @@ var ActorConnRaw = class {
4747
4806
  this.#encoding = encoding;
4748
4807
  this.#actorResolutionState = actorResolutionState;
4749
4808
  this.#gatewayOptions = resolveActorGatewayOptions(gatewayOptions);
4809
+ if ("getForId" in actorResolutionState) {
4810
+ this.#actorId = actorResolutionState.getForId.actorId;
4811
+ }
4750
4812
  this.#readyPromise = promiseWithResolvers(
4751
4813
  (reason) => logger2().warn({
4752
4814
  msg: "unhandled ready promise rejection",
@@ -5171,12 +5233,10 @@ var ActorConnRaw = class {
5171
5233
  );
5172
5234
  return;
5173
5235
  }
5174
- let errorToThrow = new RivetError(
5175
- group,
5176
- code,
5177
- message,
5178
- { metadata, actor }
5179
- );
5236
+ let errorToThrow = new RivetError(group, code, message, {
5237
+ metadata,
5238
+ actor
5239
+ });
5180
5240
  if (isSchedulingError(group, code) && this.#actorId) {
5181
5241
  const schedulingError = await checkForSchedulingError(
5182
5242
  group,
@@ -5572,31 +5632,8 @@ var ActorConnRaw = class {
5572
5632
  }
5573
5633
  }
5574
5634
  );
5575
- const serializedLength = messageLength(messageSerialized);
5576
- if (serializedLength > DEFAULT_MAX_INCOMING_MESSAGE_SIZE && message.body.tag === "ActionRequest") {
5577
- const actionId = Number(message.body.val.id);
5578
- const inFlight = this.#takeActionInFlight(actionId);
5579
- const error = new RivetError(
5580
- "message",
5581
- "incoming_too_long",
5582
- "Incoming message too long",
5583
- {
5584
- maxSize: DEFAULT_MAX_INCOMING_MESSAGE_SIZE,
5585
- actualSize: serializedLength
5586
- }
5587
- );
5588
- logger2().warn({
5589
- msg: "rejecting oversized connection action request",
5590
- actionId,
5591
- actionName: inFlight.name,
5592
- actualSize: serializedLength,
5593
- maxSize: DEFAULT_MAX_INCOMING_MESSAGE_SIZE
5594
- });
5595
- inFlight.reject(error);
5596
- this.#dispatchActorError(error);
5597
- return;
5598
- }
5599
5635
  this.#websocket.send(messageSerialized);
5636
+ const serializedLength = messageLength(messageSerialized);
5600
5637
  logger2().trace({
5601
5638
  msg: "sent websocket message",
5602
5639
  len: serializedLength
@@ -5787,7 +5824,19 @@ var ActorConnRaw = class {
5787
5824
  }
5788
5825
  };
5789
5826
 
5827
+ // src/common/fetch-like.ts
5828
+ function isUrlLike(value) {
5829
+ return typeof value === "object" && value !== null && typeof value.href === "string" && typeof value.pathname === "string" && typeof value.search === "string";
5830
+ }
5831
+ function isRequestLike(value) {
5832
+ return typeof value === "object" && value !== null && typeof value.url === "string" && typeof value.method === "string" && isHeadersLike(value.headers);
5833
+ }
5834
+ function isHeadersLike(value) {
5835
+ return typeof value === "object" && value !== null && typeof value.entries === "function";
5836
+ }
5837
+
5790
5838
  // src/common/database/shared.ts
5839
+ var MIGRATION_TRANSACTION_TIMEOUT_MS = 5 * 6e4;
5791
5840
  var AsyncMutex = class {
5792
5841
  #locked = false;
5793
5842
  #waiting = [];
@@ -5817,14 +5866,17 @@ var AsyncMutex = class {
5817
5866
  // src/client/raw-utils.ts
5818
5867
  async function rawHttpFetch(driver, target, params, input, init, options = {}) {
5819
5868
  let path;
5869
+ let originalUrl;
5820
5870
  let mergedInit = init || {};
5821
5871
  if (typeof input === "string") {
5822
5872
  path = input;
5823
- } else if (input instanceof URL) {
5873
+ } else if (isUrlLike(input)) {
5824
5874
  path = input.pathname + input.search;
5825
- } else if (input instanceof Request) {
5875
+ originalUrl = input.toString();
5876
+ } else if (isRequestLike(input)) {
5826
5877
  const url = new URL(input.url);
5827
5878
  path = url.pathname + url.search;
5879
+ originalUrl = url.toString();
5828
5880
  const requestHeaders = new Headers(input.headers);
5829
5881
  const initHeaders = new Headers(init?.headers || {});
5830
5882
  const mergedHeaders = new Headers(requestHeaders);
@@ -5866,6 +5918,10 @@ async function rawHttpFetch(driver, target, params, input, init, options = {}) {
5866
5918
  const normalizedPath = path.startsWith("/") ? path.slice(1) : path;
5867
5919
  const url = new URL(`http://actor/request/${normalizedPath}`);
5868
5920
  const proxyRequestHeaders = new Headers(mergedInit.headers);
5921
+ proxyRequestHeaders.delete(HEADER_ORIGINAL_REQUEST_URL);
5922
+ if (originalUrl) {
5923
+ proxyRequestHeaders.set(HEADER_ORIGINAL_REQUEST_URL, originalUrl);
5924
+ }
5869
5925
  if (params) {
5870
5926
  proxyRequestHeaders.set(HEADER_CONN_PARAMS, JSON.stringify(params));
5871
5927
  }
@@ -6020,10 +6076,7 @@ var ActorHandleRaw = class {
6020
6076
  }
6021
6077
  }).send(name, body, options);
6022
6078
  } catch (err) {
6023
- const { group, code, message, metadata, actor } = deconstructError(
6024
- err,
6025
- true
6026
- );
6079
+ const { group, code, message, metadata, actor } = deconstructError(err, true);
6027
6080
  if (this.#shouldRetryQueueDispatchOverload(
6028
6081
  group,
6029
6082
  code,
@@ -6056,7 +6109,10 @@ var ActorHandleRaw = class {
6056
6109
  await this.#waitForRetryWindow();
6057
6110
  continue;
6058
6111
  }
6059
- const invalidated = this.#invalidateResolvedActorId(group, code);
6112
+ const invalidated = this.#invalidateResolvedActorId(
6113
+ group,
6114
+ code
6115
+ );
6060
6116
  if (invalidated && attempt < maxAttempts - 1) {
6061
6117
  useQueryTarget = code === "starting" || code === "stopping" || code.startsWith("destroyed_");
6062
6118
  if (useQueryTarget) {
@@ -6064,7 +6120,10 @@ var ActorHandleRaw = class {
6064
6120
  }
6065
6121
  continue;
6066
6122
  }
6067
- throw new RivetError(group, code, message, { metadata, actor });
6123
+ throw new RivetError(group, code, message, {
6124
+ metadata,
6125
+ actor
6126
+ });
6068
6127
  }
6069
6128
  }
6070
6129
  throw new Error("unreachable queue retry state");
@@ -6144,7 +6203,9 @@ var ActorHandleRaw = class {
6144
6203
  args
6145
6204
  }),
6146
6205
  requestToBare: (args) => ({
6147
- args: bufferToArrayBuffer(encodeCborCompat(args))
6206
+ args: bufferToArrayBuffer(
6207
+ encodeCborCompat(args)
6208
+ )
6148
6209
  }),
6149
6210
  responseFromJson: (json) => json.output,
6150
6211
  responseFromBare: (bare5) => decodeCborCompat(new Uint8Array(bare5.output))
@@ -6154,10 +6215,7 @@ var ActorHandleRaw = class {
6154
6215
  }
6155
6216
  return output;
6156
6217
  } catch (err) {
6157
- const { group, code, message, metadata, actor } = deconstructError(
6158
- err,
6159
- true
6160
- );
6218
+ const { group, code, message, metadata, actor } = deconstructError(err, true);
6161
6219
  if (await this.#shouldRetrySchedulingError(
6162
6220
  group,
6163
6221
  code,
@@ -6188,11 +6246,16 @@ var ActorHandleRaw = class {
6188
6246
  { metadata, actor }
6189
6247
  );
6190
6248
  }
6191
- const invalidated = this.#invalidateResolvedActorId(group, code);
6249
+ const invalidated = this.#invalidateResolvedActorId(
6250
+ group,
6251
+ code
6252
+ );
6192
6253
  if (invalidated && attempt < maxAttempts - 1) {
6193
6254
  if (group === "actor" && (code === "starting" || code === "stopping")) {
6194
6255
  useQueryTarget = true;
6195
- await new Promise((resolve) => setTimeout(resolve, 100));
6256
+ await new Promise(
6257
+ (resolve) => setTimeout(resolve, 100)
6258
+ );
6196
6259
  }
6197
6260
  continue;
6198
6261
  }
@@ -6331,6 +6394,7 @@ var ActorHandleRaw = class {
6331
6394
  async #fetchWithResolvedActor(input, init) {
6332
6395
  const maxAttempts = this.#getDynamicQueryMaxAttempts();
6333
6396
  let useQueryTarget = false;
6397
+ const retryableRequest = isRequestLike(input) ? input.clone() : void 0;
6334
6398
  const { skipReadyWait, ...requestInit } = init ?? {};
6335
6399
  const gatewayOptions = resolveActorGatewayOptions(
6336
6400
  this.#gatewayOptions,
@@ -6350,7 +6414,7 @@ var ActorHandleRaw = class {
6350
6414
  this.#driver,
6351
6415
  target,
6352
6416
  this.#params,
6353
- input,
6417
+ retryableRequest ? retryableRequest.clone() : input,
6354
6418
  requestInit,
6355
6419
  gatewayOptions
6356
6420
  );
@@ -6369,10 +6433,7 @@ var ActorHandleRaw = class {
6369
6433
  }
6370
6434
  return response;
6371
6435
  } catch (err) {
6372
- const { group, code, message, metadata, actor } = deconstructError(
6373
- err,
6374
- true
6375
- );
6436
+ const { group, code, message, metadata, actor } = deconstructError(err, true);
6376
6437
  if (await this.#shouldRetrySchedulingError(
6377
6438
  group,
6378
6439
  code,
@@ -6395,7 +6456,10 @@ var ActorHandleRaw = class {
6395
6456
  await this.#waitForRetryWindow();
6396
6457
  continue;
6397
6458
  }
6398
- const invalidated = this.#invalidateResolvedActorId(group, code);
6459
+ const invalidated = this.#invalidateResolvedActorId(
6460
+ group,
6461
+ code
6462
+ );
6399
6463
  if (invalidated && attempt < maxAttempts - 1) {
6400
6464
  useQueryTarget = code === "starting" || code === "stopping" || code.startsWith("destroyed_");
6401
6465
  if (useQueryTarget) {
@@ -6495,8 +6559,9 @@ var ActorHandleRaw = class {
6495
6559
  this.#gatewayOptions,
6496
6560
  options
6497
6561
  );
6562
+ const useQueryTarget = isDynamicActorQuery(this.#actorResolutionState);
6498
6563
  const target = await this.#resolveGatewayRequestTarget(
6499
- false,
6564
+ useQueryTarget,
6500
6565
  gatewayOptions
6501
6566
  );
6502
6567
  return await rawWebSocket(
@@ -6519,7 +6584,9 @@ var ActorHandleRaw = class {
6519
6584
  if ("directId" in target) {
6520
6585
  return target.directId;
6521
6586
  }
6522
- throw new Error("dynamic actor resolution did not produce a direct actor id");
6587
+ throw new Error(
6588
+ "dynamic actor resolution did not produce a direct actor id"
6589
+ );
6523
6590
  }
6524
6591
  /**
6525
6592
  * Returns the raw URL for routing traffic to the actor.
@@ -6774,6 +6841,23 @@ function createClientWithDriver(driver, config = {}) {
6774
6841
  }
6775
6842
  function createActorProxy(handle) {
6776
6843
  const methodCache = /* @__PURE__ */ new Map();
6844
+ const actionPath = (name) => {
6845
+ let method = methodCache.get(name);
6846
+ if (method) return method;
6847
+ method = new Proxy(
6848
+ (...args) => handle.action({ name, args }),
6849
+ {
6850
+ get(target, prop) {
6851
+ if (typeof prop === "symbol")
6852
+ return Reflect.get(target, prop);
6853
+ if (prop === "then") return void 0;
6854
+ return actionPath(`${name}.${prop}`);
6855
+ }
6856
+ }
6857
+ );
6858
+ methodCache.set(name, method);
6859
+ return method;
6860
+ };
6777
6861
  return new Proxy(handle, {
6778
6862
  get(target, prop, receiver) {
6779
6863
  if (typeof prop === "symbol") {
@@ -6788,12 +6872,7 @@ function createActorProxy(handle) {
6788
6872
  }
6789
6873
  if (typeof prop === "string") {
6790
6874
  if (prop === "then") return void 0;
6791
- let method = methodCache.get(prop);
6792
- if (!method) {
6793
- method = (...args) => target.action({ name: prop, args });
6794
- methodCache.set(prop, method);
6795
- }
6796
- return method;
6875
+ return actionPath(prop);
6797
6876
  }
6798
6877
  },
6799
6878
  // Support for 'in' operator
@@ -6811,6 +6890,7 @@ function createActorProxy(handle) {
6811
6890
  },
6812
6891
  // Support proper property descriptors
6813
6892
  getOwnPropertyDescriptor(target, prop) {
6893
+ if (prop === "then") return void 0;
6814
6894
  const targetDescriptor = Reflect.getOwnPropertyDescriptor(
6815
6895
  target,
6816
6896
  prop
@@ -6823,7 +6903,7 @@ function createActorProxy(handle) {
6823
6903
  configurable: true,
6824
6904
  enumerable: false,
6825
6905
  writable: false,
6826
- value: (...args) => target.action({ name: prop, args })
6906
+ value: actionPath(prop)
6827
6907
  };
6828
6908
  }
6829
6909
  return void 0;