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,5 +1,5 @@
1
1
  import type { AnyActorDefinition } from "@/actor/definition";
2
- import type { Encoding } from "@/common/encoding";
2
+ import type { ActorSpecifier } from "@/actor/errors";
3
3
  import {
4
4
  HEADER_CONN_PARAMS,
5
5
  HEADER_ENCODING,
@@ -11,7 +11,6 @@ import {
11
11
  HTTP_ACTION_RESPONSE_VERSIONED,
12
12
  HTTP_RESPONSE_ERROR_VERSIONED,
13
13
  } from "@/common/client-protocol-versioned";
14
- import { AsyncMutex } from "@/common/database/shared";
15
14
  import {
16
15
  type HttpActionRequest as HttpActionRequestJson,
17
16
  HttpActionRequestSchema,
@@ -20,14 +19,26 @@ import {
20
19
  type HttpResponseError as HttpResponseErrorJson,
21
20
  HttpResponseErrorSchema,
22
21
  } from "@/common/client-protocol-zod";
22
+ import { AsyncMutex } from "@/common/database/shared";
23
+ import type { Encoding, JsonCompatValue } from "@/common/encoding";
23
24
  import { deconstructError } from "@/common/utils";
24
25
  import type { EngineControlClient } from "@/engine-client/driver";
25
- import { decodeCborCompat, deserializeWithEncoding, encodeCborCompat } from "@/serde";
26
+ import {
27
+ decodeCborCompat,
28
+ deserializeWithEncoding,
29
+ encodeCborCompat,
30
+ } from "@/serde";
26
31
  import { bufferToArrayBuffer } from "@/utils";
27
32
  import type {
33
+ ActorActionOptions,
34
+ ActorConnectOptions,
28
35
  ActorDefinitionActions,
29
36
  ActorDefinitionQueueSend,
37
+ ActorFetchInit,
38
+ ActorGatewayOptions,
39
+ ActorWebSocketOptions,
30
40
  } from "./actor-common";
41
+ import { resolveActorGatewayOptions } from "./actor-common";
31
42
  import { type ActorConn, ActorConnRaw } from "./actor-conn";
32
43
  import {
33
44
  type ActorResolutionState,
@@ -63,6 +74,7 @@ export class ActorHandleRaw {
63
74
  #driver: EngineControlClient;
64
75
  #encoding: Encoding;
65
76
  #actorResolutionState: ActorResolutionState;
77
+ #gatewayOptions: ActorGatewayOptions;
66
78
  #params: unknown;
67
79
  #getParams?: () => Promise<unknown>;
68
80
  #resolvedActorId?: string;
@@ -83,11 +95,13 @@ export class ActorHandleRaw {
83
95
  getParams: (() => Promise<unknown>) | undefined,
84
96
  encoding: Encoding,
85
97
  actorResolutionState: ActorResolutionState,
98
+ gatewayOptions: ActorGatewayOptions = {},
86
99
  ) {
87
100
  this.#client = client;
88
101
  this.#driver = driver;
89
102
  this.#encoding = encoding;
90
103
  this.#actorResolutionState = actorResolutionState;
104
+ this.#gatewayOptions = gatewayOptions;
91
105
  this.#params = params;
92
106
  this.#getParams = getParams;
93
107
  }
@@ -130,23 +144,30 @@ export class ActorHandleRaw {
130
144
  for (let attempt = 0; attempt < maxAttempts; attempt++) {
131
145
  let actorId: string | undefined;
132
146
  try {
133
- const target = await this.#resolveActionTarget(useQueryTarget);
134
- actorId = "directId" in target ? target.directId : undefined;
147
+ const gatewayOptions = resolveActorGatewayOptions(
148
+ this.#gatewayOptions,
149
+ );
150
+ const target = await this.#resolveGatewayRequestTarget(
151
+ useQueryTarget,
152
+ gatewayOptions,
153
+ );
154
+ actorId =
155
+ "directId" in target ? target.directId : undefined;
135
156
 
136
157
  return await createQueueSender({
137
158
  encoding: this.#encoding,
138
159
  params: this.#params,
139
160
  customFetch: async (request: Request) => {
140
- return await this.#driver.sendRequest(target, request);
161
+ return await this.#driver.sendRequest(
162
+ target,
163
+ request,
164
+ gatewayOptions,
165
+ );
141
166
  },
142
167
  }).send(name, body, options as any);
143
168
  } catch (err) {
144
- const { group, code, message, metadata } = deconstructError(
145
- err,
146
- logger(),
147
- {},
148
- true,
149
- );
169
+ const { group, code, message, metadata, rayId, actor } =
170
+ deconstructError(err, true);
150
171
 
151
172
  if (
152
173
  this.#shouldRetryQueueDispatchOverload(
@@ -168,6 +189,7 @@ export class ActorHandleRaw {
168
189
  actorId,
169
190
  attempt,
170
191
  maxAttempts,
192
+ rayId,
171
193
  )
172
194
  ) {
173
195
  useQueryTarget = true;
@@ -189,19 +211,26 @@ export class ActorHandleRaw {
189
211
  continue;
190
212
  }
191
213
 
192
- const invalidated = this.#invalidateResolvedActorId(group, code);
214
+ const invalidated = this.#invalidateResolvedActorId(
215
+ group,
216
+ code,
217
+ );
193
218
  if (invalidated && attempt < maxAttempts - 1) {
194
219
  useQueryTarget =
195
- (code === "starting" ||
196
- code === "stopping" ||
197
- code.startsWith("destroyed_"));
220
+ code === "starting" ||
221
+ code === "stopping" ||
222
+ code.startsWith("destroyed_");
198
223
  if (useQueryTarget) {
199
224
  await this.#waitForRetryWindow();
200
225
  }
201
226
  continue;
202
227
  }
203
228
 
204
- throw new ActorError(group, code, message, metadata);
229
+ throw new ActorError(group, code, message, {
230
+ metadata,
231
+ rayId,
232
+ actor,
233
+ });
205
234
  }
206
235
  }
207
236
 
@@ -216,14 +245,12 @@ export class ActorHandleRaw {
216
245
  * @template Args - The type of arguments to pass to the action function.
217
246
  * @template Response - The type of the response returned by the action function.
218
247
  */
219
- async action<
220
- Args extends Array<unknown> = unknown[],
221
- Response = unknown,
222
- >(opts: {
223
- name: string;
224
- args: Args;
225
- signal?: AbortSignal;
226
- }): Promise<Response> {
248
+ async action<Args extends Array<unknown> = unknown[], Response = unknown>(
249
+ opts: {
250
+ name: string;
251
+ args: Args;
252
+ } & ActorActionOptions,
253
+ ): Promise<Response> {
227
254
  if (
228
255
  typeof opts === "string" ||
229
256
  typeof opts !== "object" ||
@@ -242,18 +269,26 @@ export class ActorHandleRaw {
242
269
  return await retryOnLifecycleBoundary(run, { signal: opts.signal });
243
270
  }
244
271
 
245
- async #sendActionNow(opts: {
246
- name: string;
247
- args: unknown[];
248
- signal?: AbortSignal;
249
- }): Promise<unknown> {
272
+ async #sendActionNow(
273
+ opts: {
274
+ name: string;
275
+ args: unknown[];
276
+ } & ActorActionOptions,
277
+ ): Promise<unknown> {
250
278
  const maxAttempts = this.#getDynamicQueryMaxAttempts();
251
279
  let useQueryTarget = false;
280
+ const gatewayOptions = resolveActorGatewayOptions(
281
+ this.#gatewayOptions,
282
+ opts,
283
+ );
252
284
 
253
285
  for (let attempt = 0; attempt < maxAttempts; attempt++) {
254
286
  let actorId: string | undefined;
255
287
  try {
256
- const target = await this.#resolveActionTarget(useQueryTarget);
288
+ const target = await this.#resolveGatewayRequestTarget(
289
+ useQueryTarget,
290
+ gatewayOptions,
291
+ );
257
292
  actorId = "directId" in target ? target.directId : undefined;
258
293
 
259
294
  logger().debug(
@@ -292,24 +327,30 @@ export class ActorHandleRaw {
292
327
  },
293
328
  body: opts.args,
294
329
  encoding: this.#encoding,
295
- customFetch: this.#driver.sendRequest.bind(
296
- this.#driver,
297
- target,
298
- ),
330
+ customFetch: async (request) =>
331
+ await this.#driver.sendRequest(
332
+ target,
333
+ request,
334
+ gatewayOptions,
335
+ ),
299
336
  signal: opts?.signal,
300
337
  requestVersion: CLIENT_PROTOCOL_CURRENT_VERSION,
301
338
  requestVersionedDataHandler: HTTP_ACTION_REQUEST_VERSIONED,
302
339
  responseVersion: CLIENT_PROTOCOL_CURRENT_VERSION,
303
- responseVersionedDataHandler: HTTP_ACTION_RESPONSE_VERSIONED,
340
+ responseVersionedDataHandler:
341
+ HTTP_ACTION_RESPONSE_VERSIONED,
304
342
  requestZodSchema: HttpActionRequestSchema,
305
343
  responseZodSchema: HttpActionResponseSchema,
306
344
  requestToJson: (args): HttpActionRequestJson => ({
307
345
  args,
308
346
  }),
309
347
  requestToBare: (args): protocol.HttpActionRequest => ({
310
- args: bufferToArrayBuffer(encodeCborCompat(args)),
348
+ args: bufferToArrayBuffer(
349
+ encodeCborCompat(args as JsonCompatValue),
350
+ ),
311
351
  }),
312
- responseFromJson: (json): Response => json.output as Response,
352
+ responseFromJson: (json): Response =>
353
+ json.output as Response,
313
354
  responseFromBare: (bare): Response =>
314
355
  decodeCborCompat(new Uint8Array(bare.output)),
315
356
  });
@@ -318,12 +359,8 @@ export class ActorHandleRaw {
318
359
  }
319
360
  return output;
320
361
  } catch (err) {
321
- const { group, code, message, metadata } = deconstructError(
322
- err,
323
- logger(),
324
- {},
325
- true,
326
- );
362
+ const { group, code, message, metadata, rayId, actor } =
363
+ deconstructError(err, true);
327
364
 
328
365
  if (
329
366
  await this.#shouldRetrySchedulingError(
@@ -332,6 +369,7 @@ export class ActorHandleRaw {
332
369
  actorId,
333
370
  attempt,
334
371
  maxAttempts,
372
+ rayId,
335
373
  )
336
374
  ) {
337
375
  useQueryTarget = true;
@@ -363,23 +401,32 @@ export class ActorHandleRaw {
363
401
  "actor",
364
402
  "not_found",
365
403
  "The actor does not exist or was destroyed.",
366
- metadata,
404
+ { metadata, rayId, actor },
367
405
  );
368
406
  }
369
407
 
370
- const invalidated = this.#invalidateResolvedActorId(group, code);
408
+ const invalidated = this.#invalidateResolvedActorId(
409
+ group,
410
+ code,
411
+ );
371
412
  if (invalidated && attempt < maxAttempts - 1) {
372
413
  if (
373
414
  group === "actor" &&
374
415
  (code === "starting" || code === "stopping")
375
416
  ) {
376
417
  useQueryTarget = true;
377
- await new Promise((resolve) => setTimeout(resolve, 100));
418
+ await new Promise((resolve) =>
419
+ setTimeout(resolve, 100),
420
+ );
378
421
  }
379
422
  continue;
380
423
  }
381
424
 
382
- throw new ActorError(group, code, message, metadata);
425
+ throw new ActorError(group, code, message, {
426
+ metadata,
427
+ rayId,
428
+ actor,
429
+ });
383
430
  }
384
431
  }
385
432
 
@@ -474,6 +521,7 @@ export class ActorHandleRaw {
474
521
  actorId: string | undefined,
475
522
  attempt: number,
476
523
  maxAttempts: number,
524
+ rayId?: string,
477
525
  ): Promise<boolean> {
478
526
  if (
479
527
  !isDynamicActorQuery(this.#actorResolutionState) ||
@@ -490,6 +538,7 @@ export class ActorHandleRaw {
490
538
  actorId,
491
539
  this.#actorResolutionState,
492
540
  this.#driver,
541
+ rayId,
493
542
  );
494
543
  if (schedulingError) {
495
544
  throw schedulingError;
@@ -542,13 +591,27 @@ export class ActorHandleRaw {
542
591
  }
543
592
  }
544
593
 
594
+ async #resolveGatewayRequestTarget(
595
+ useQueryTarget: boolean,
596
+ gatewayOptions: ActorGatewayOptions,
597
+ ) {
598
+ if (gatewayOptions.skipReadyWait) {
599
+ return getGatewayTarget(this.#actorResolutionState);
600
+ }
601
+
602
+ return await this.#resolveActionTarget(useQueryTarget);
603
+ }
604
+
545
605
  /**
546
606
  * Establishes a persistent connection to the actor.
547
607
  *
548
608
  * @template AD The actor class that this connection is for.
549
609
  * @returns {ActorConn<AD>} A connection to the actor.
550
610
  */
551
- connect(params?: unknown): ActorConn<AnyActorDefinition> {
611
+ connect(
612
+ params?: unknown,
613
+ options: ActorConnectOptions = {},
614
+ ): ActorConn<AnyActorDefinition> {
552
615
  logger().debug({
553
616
  msg: "establishing connection from handle",
554
617
  query: this.#actorResolutionState,
@@ -564,6 +627,7 @@ export class ActorHandleRaw {
564
627
  getParams,
565
628
  this.#encoding,
566
629
  this.#actorResolutionState,
630
+ resolveActorGatewayOptions(this.#gatewayOptions, options),
567
631
  );
568
632
 
569
633
  return this.#client[CREATE_ACTOR_CONN_PROXY](
@@ -575,28 +639,39 @@ export class ActorHandleRaw {
575
639
  * Fetches a resource from this actor via the /request endpoint. This is a
576
640
  * convenience wrapper around the raw HTTP API.
577
641
  */
578
- fetch(input: string | URL | Request, init?: RequestInit) {
642
+ fetch(input: string | URL | Request, init?: ActorFetchInit) {
579
643
  return this.#fetchWithResolvedActor(input, init);
580
644
  }
581
645
 
582
646
  async #fetchWithResolvedActor(
583
647
  input: string | URL | Request,
584
- init?: RequestInit,
648
+ init?: ActorFetchInit,
585
649
  ) {
586
650
  const maxAttempts = this.#getDynamicQueryMaxAttempts();
587
651
  let useQueryTarget = false;
652
+ const { skipReadyWait, ...requestInit } = init ?? {};
653
+ const gatewayOptions = resolveActorGatewayOptions(
654
+ this.#gatewayOptions,
655
+ {
656
+ skipReadyWait,
657
+ },
658
+ );
588
659
 
589
660
  for (let attempt = 0; attempt < maxAttempts; attempt++) {
590
661
  let actorId: string | undefined;
591
662
  try {
592
- const target = await this.#resolveActionTarget(useQueryTarget);
663
+ const target = await this.#resolveGatewayRequestTarget(
664
+ useQueryTarget,
665
+ gatewayOptions,
666
+ );
593
667
  actorId = "directId" in target ? target.directId : undefined;
594
668
  const response = await rawHttpFetch(
595
669
  this.#driver,
596
670
  target,
597
671
  this.#params,
598
672
  input,
599
- init,
673
+ requestInit,
674
+ gatewayOptions,
600
675
  );
601
676
  const retry = await this.#shouldRetryRawFetchResponse(
602
677
  response,
@@ -613,12 +688,8 @@ export class ActorHandleRaw {
613
688
  }
614
689
  return response;
615
690
  } catch (err) {
616
- const { group, code, message, metadata } = deconstructError(
617
- err,
618
- logger(),
619
- {},
620
- true,
621
- );
691
+ const { group, code, message, metadata, rayId, actor } =
692
+ deconstructError(err, true);
622
693
 
623
694
  if (
624
695
  await this.#shouldRetrySchedulingError(
@@ -627,6 +698,7 @@ export class ActorHandleRaw {
627
698
  actorId,
628
699
  attempt,
629
700
  maxAttempts,
701
+ rayId,
630
702
  )
631
703
  ) {
632
704
  useQueryTarget = true;
@@ -648,19 +720,26 @@ export class ActorHandleRaw {
648
720
  continue;
649
721
  }
650
722
 
651
- const invalidated = this.#invalidateResolvedActorId(group, code);
723
+ const invalidated = this.#invalidateResolvedActorId(
724
+ group,
725
+ code,
726
+ );
652
727
  if (invalidated && attempt < maxAttempts - 1) {
653
728
  useQueryTarget =
654
- (code === "starting" ||
655
- code === "stopping" ||
656
- code.startsWith("destroyed_"));
729
+ code === "starting" ||
730
+ code === "stopping" ||
731
+ code.startsWith("destroyed_");
657
732
  if (useQueryTarget) {
658
733
  await this.#waitForRetryWindow();
659
734
  }
660
735
  continue;
661
736
  }
662
737
 
663
- throw new ActorError(group, code, message, metadata);
738
+ throw new ActorError(group, code, message, {
739
+ metadata,
740
+ rayId,
741
+ actor,
742
+ });
664
743
  }
665
744
  }
666
745
 
@@ -672,13 +751,10 @@ export class ActorHandleRaw {
672
751
  actorId: string | undefined,
673
752
  attempt: number,
674
753
  maxAttempts: number,
675
- ): Promise<
676
- | {
677
- useQueryTarget: boolean;
678
- waitForRetryWindow: boolean;
679
- }
680
- | null
681
- > {
754
+ ): Promise<{
755
+ useQueryTarget: boolean;
756
+ waitForRetryWindow: boolean;
757
+ } | null> {
682
758
  if (response.ok || !isDynamicActorQuery(this.#actorResolutionState)) {
683
759
  return null;
684
760
  }
@@ -688,7 +764,7 @@ export class ActorHandleRaw {
688
764
  return null;
689
765
  }
690
766
 
691
- const { group, code } = error;
767
+ const { group, code, rayId } = error;
692
768
 
693
769
  if (
694
770
  await this.#shouldRetrySchedulingError(
@@ -697,6 +773,7 @@ export class ActorHandleRaw {
697
773
  actorId,
698
774
  attempt,
699
775
  maxAttempts,
776
+ rayId,
700
777
  )
701
778
  ) {
702
779
  return {
@@ -740,6 +817,8 @@ export class ActorHandleRaw {
740
817
  code: string;
741
818
  message: string;
742
819
  metadata?: unknown;
820
+ rayId?: string;
821
+ actor?: ActorSpecifier;
743
822
  } | null> {
744
823
  if (response.ok) {
745
824
  return null;
@@ -751,7 +830,7 @@ export class ActorHandleRaw {
751
830
  : this.#encoding;
752
831
 
753
832
  try {
754
- return deserializeWithEncoding<
833
+ const error = deserializeWithEncoding<
755
834
  protocol.HttpResponseError,
756
835
  HttpResponseErrorJson,
757
836
  {
@@ -759,13 +838,23 @@ export class ActorHandleRaw {
759
838
  code: string;
760
839
  message: string;
761
840
  metadata?: unknown;
841
+ rayId?: string;
842
+ actor?: ActorSpecifier;
762
843
  }
763
844
  >(
764
845
  encoding,
765
846
  new Uint8Array(await response.clone().arrayBuffer()),
766
847
  HTTP_RESPONSE_ERROR_VERSIONED,
767
848
  HttpResponseErrorSchema,
768
- (json) => json as HttpResponseErrorJson,
849
+ (json) => ({
850
+ ...json,
851
+ actor: json.actor
852
+ ? {
853
+ ...json.actor,
854
+ generation: Number(json.actor.generation),
855
+ }
856
+ : undefined,
857
+ }),
769
858
  (bare) => ({
770
859
  group: bare.group,
771
860
  code: bare.code,
@@ -773,8 +862,19 @@ export class ActorHandleRaw {
773
862
  metadata: bare.metadata
774
863
  ? decodeCborCompat(new Uint8Array(bare.metadata))
775
864
  : undefined,
865
+ actor: bare.actor
866
+ ? {
867
+ actorId: bare.actor.actorId,
868
+ generation: Number(bare.actor.generation),
869
+ key: bare.actor.key ?? undefined,
870
+ }
871
+ : undefined,
776
872
  }),
777
873
  );
874
+ return {
875
+ ...error,
876
+ rayId: response.headers.get("x-rivet-ray-id") ?? undefined,
877
+ };
778
878
  } catch {
779
879
  return null;
780
880
  }
@@ -783,14 +883,28 @@ export class ActorHandleRaw {
783
883
  /**
784
884
  * Opens a raw WebSocket connection to this actor.
785
885
  */
786
- async webSocket(path?: string, protocols?: string | string[]) {
886
+ async webSocket(
887
+ path?: string,
888
+ protocols?: string | string[],
889
+ options: ActorWebSocketOptions = {},
890
+ ) {
787
891
  const params = await this.#resolveConnectionParams();
892
+ const gatewayOptions = resolveActorGatewayOptions(
893
+ this.#gatewayOptions,
894
+ options,
895
+ );
896
+ const useQueryTarget = isDynamicActorQuery(this.#actorResolutionState);
897
+ const target = await this.#resolveGatewayRequestTarget(
898
+ useQueryTarget,
899
+ gatewayOptions,
900
+ );
788
901
  return await rawWebSocket(
789
902
  this.#driver,
790
- getGatewayTarget(this.#actorResolutionState),
903
+ target,
791
904
  params,
792
905
  path,
793
906
  protocols,
907
+ gatewayOptions,
794
908
  );
795
909
  }
796
910
 
@@ -807,7 +921,9 @@ export class ActorHandleRaw {
807
921
  return target.directId;
808
922
  }
809
923
 
810
- throw new Error("dynamic actor resolution did not produce a direct actor id");
924
+ throw new Error(
925
+ "dynamic actor resolution did not produce a direct actor id",
926
+ );
811
927
  }
812
928
 
813
929
  /**
@@ -816,6 +932,7 @@ export class ActorHandleRaw {
816
932
  async getGatewayUrl(): Promise<string> {
817
933
  return await this.#driver.buildGatewayUrl(
818
934
  getGatewayTarget(this.#actorResolutionState),
935
+ this.#gatewayOptions,
819
936
  );
820
937
  }
821
938
 
@@ -831,7 +948,9 @@ export class ActorHandleRaw {
831
948
  "actor",
832
949
  "reload_failed",
833
950
  `reload failed with status ${response.status}: ${body}`,
834
- {},
951
+ {
952
+ rayId: response.headers.get("x-rivet-ray-id") ?? undefined,
953
+ },
835
954
  );
836
955
  }
837
956
  }
@@ -858,7 +977,7 @@ export type ActorHandle<AD extends AnyActorDefinition> = Omit<
858
977
  "connect" | "send"
859
978
  > & {
860
979
  // Add typed version of ActorConn (instead of using AnyActorDefinition)
861
- connect(params?: unknown): ActorConn<AD>;
980
+ connect(params?: unknown, options?: ActorConnectOptions): ActorConn<AD>;
862
981
  // Resolve method returns the actor ID
863
982
  resolve(): Promise<string>;
864
983
  } & ActorDefinitionQueueSend<AD> &
@@ -1,11 +1,11 @@
1
1
  import * as errors from "@/actor/errors";
2
+ import type { ActorQuery } from "@/client/query";
2
3
  import { stringifyError } from "@/common/utils";
3
- import {
4
- type GatewayTarget,
5
- type EngineControlClient,
4
+ import type {
5
+ EngineControlClient,
6
+ GatewayTarget,
6
7
  } from "@/engine-client/driver";
7
- import type { ActorQuery } from "@/client/query";
8
- import { actorSchedulingError, type ActorSchedulingError } from "./errors";
8
+ import { type ActorSchedulingError, actorSchedulingError } from "./errors";
9
9
  import { logger } from "./log";
10
10
 
11
11
  /**
@@ -67,6 +67,7 @@ export async function checkForSchedulingError(
67
67
  actorId: string,
68
68
  query: ActorQuery,
69
69
  driver: EngineControlClient,
70
+ rayId?: string,
70
71
  ): Promise<ActorSchedulingError | null> {
71
72
  const name = getActorNameFromQuery(query);
72
73
 
@@ -79,7 +80,13 @@ export async function checkForSchedulingError(
79
80
  actorId,
80
81
  error: actor.error,
81
82
  });
82
- return actorSchedulingError(group, code, actorId, actor.error);
83
+ return actorSchedulingError(
84
+ group,
85
+ code,
86
+ actorId,
87
+ actor.error,
88
+ rayId,
89
+ );
83
90
  }
84
91
  } catch (err) {
85
92
  logger().warn({