rivetkit 0.0.0-sqlite-profiling-compat.87d61c0 → 0.0.0-sqlite-sync-3x-release.a00b07f

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 (277) hide show
  1. package/dist/browser/client.d.ts +1317 -765
  2. package/dist/browser/client.js +1457 -737
  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 +2042 -228
  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 -1
  10. package/dist/tsup/actor/errors.d.ts +1 -1
  11. package/dist/tsup/actor/errors.js +5 -1
  12. package/dist/tsup/agent-os/index.cjs +3 -2367
  13. package/dist/tsup/agent-os/index.cjs.map +1 -1
  14. package/dist/tsup/agent-os/index.d.cts +1 -2277
  15. package/dist/tsup/agent-os/index.d.ts +1 -2277
  16. package/dist/tsup/agent-os/index.js +3 -2367
  17. package/dist/tsup/agent-os/index.js.map +1 -1
  18. package/dist/tsup/{chunk-E4LNLI3W.cjs → chunk-2MOLY6AM.cjs} +444 -29
  19. package/dist/tsup/chunk-2MOLY6AM.cjs.map +1 -0
  20. package/dist/tsup/{chunk-OAUFXOG7.js → chunk-3DONDAMG.js} +2 -2
  21. package/dist/tsup/{chunk-XIX5DOZN.js → chunk-6FEYCVZC.js} +196 -20
  22. package/dist/tsup/chunk-6FEYCVZC.js.map +1 -0
  23. package/dist/tsup/chunk-6KXVLIXL.cjs +14 -0
  24. package/dist/tsup/chunk-6KXVLIXL.cjs.map +1 -0
  25. package/dist/tsup/chunk-73RNTXHB.cjs +243 -0
  26. package/dist/tsup/chunk-73RNTXHB.cjs.map +1 -0
  27. package/dist/tsup/{chunk-HXUEHHJF.js → chunk-A2CF6PFH.js} +19 -11
  28. package/dist/tsup/chunk-A2CF6PFH.js.map +1 -0
  29. package/dist/tsup/{chunk-EFU4JW3T.js → chunk-BRH4PQS5.js} +436 -21
  30. package/dist/tsup/chunk-BRH4PQS5.js.map +1 -0
  31. package/dist/tsup/{chunk-GM45LG7L.cjs → chunk-BTSDFFDC.cjs} +18 -11
  32. package/dist/tsup/chunk-BTSDFFDC.cjs.map +1 -0
  33. package/dist/tsup/{chunk-B3GLD4IN.js → chunk-D5WUPE47.js} +50 -3
  34. package/dist/tsup/chunk-D5WUPE47.js.map +1 -0
  35. package/dist/tsup/{chunk-O3ZUMAN7.js → chunk-DJUBJQEQ.js} +3 -3
  36. package/dist/tsup/chunk-DJUBJQEQ.js.map +1 -0
  37. package/dist/tsup/{chunk-3MHDOUD7.cjs → chunk-HDVZ6YZG.cjs} +197 -21
  38. package/dist/tsup/chunk-HDVZ6YZG.cjs.map +1 -0
  39. package/dist/tsup/{chunk-JZ7TWV65.js → chunk-JTHHCZCZ.js} +24 -1
  40. package/dist/tsup/chunk-JTHHCZCZ.js.map +1 -0
  41. package/dist/tsup/{chunk-D363DMNH.cjs → chunk-JUHXV3HF.cjs} +3 -3
  42. package/dist/tsup/chunk-JUHXV3HF.cjs.map +1 -0
  43. package/dist/tsup/chunk-JUWMP5O3.js +14 -0
  44. package/dist/tsup/chunk-JUWMP5O3.js.map +1 -0
  45. package/dist/tsup/{chunk-ZA7FLHKH.cjs → chunk-KVFIONKQ.cjs} +25 -2
  46. package/dist/tsup/chunk-KVFIONKQ.cjs.map +1 -0
  47. package/dist/tsup/{chunk-4FC7TVS6.cjs → chunk-MGI2VVF6.cjs} +39 -7
  48. package/dist/tsup/chunk-MGI2VVF6.cjs.map +1 -0
  49. package/dist/tsup/{chunk-BWERJMV6.cjs → chunk-OTVJYZ2L.cjs} +1139 -470
  50. package/dist/tsup/chunk-OTVJYZ2L.cjs.map +1 -0
  51. package/dist/tsup/{chunk-VE2X4KMG.cjs → chunk-RTWH3AX3.cjs} +18 -10
  52. package/dist/tsup/chunk-RTWH3AX3.cjs.map +1 -0
  53. package/dist/tsup/{chunk-DTRDGPHU.cjs → chunk-TM76Z7XT.cjs} +7 -7
  54. package/dist/tsup/chunk-TM76Z7XT.cjs.map +1 -0
  55. package/dist/tsup/{chunk-3GVMLSND.js → chunk-TRUHDXOU.js} +1023 -354
  56. package/dist/tsup/chunk-TRUHDXOU.js.map +1 -0
  57. package/dist/tsup/{chunk-PT7AC5PC.js → chunk-TSQTI6H6.js} +16 -9
  58. package/dist/tsup/chunk-TSQTI6H6.js.map +1 -0
  59. package/dist/tsup/{chunk-FNAXD5BQ.cjs → chunk-Z7E2G3JZ.cjs} +52 -5
  60. package/dist/tsup/chunk-Z7E2G3JZ.cjs.map +1 -0
  61. package/dist/tsup/{chunk-ZZ3WBRPD.js → chunk-ZOVJDAOW.js} +38 -6
  62. package/dist/tsup/chunk-ZOVJDAOW.js.map +1 -0
  63. package/dist/tsup/chunk-ZYK4B5WV.js +243 -0
  64. package/dist/tsup/chunk-ZYK4B5WV.js.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 +32 -6
  68. package/dist/tsup/client/mod.d.ts +32 -6
  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-BR1Nn0QQ.d.ts → config-B4erdavw.d.ts} +571 -65
  79. package/dist/tsup/{config-B0LNDrLY.d.cts → config-BfG1qpYz.d.cts} +80 -14
  80. package/dist/tsup/{config-B0LNDrLY.d.ts → config-BfG1qpYz.d.ts} +80 -14
  81. package/dist/tsup/{config-tCvkwzyN.d.cts → config-DK144OAw.d.cts} +571 -65
  82. package/dist/tsup/{context-D4WDwf9m.d.cts → context-Cvnf3BRe.d.cts} +3 -2
  83. package/dist/tsup/{context-oc9zhA3x.d.ts → context-Oxi6YWcG.d.ts} +3 -2
  84. package/dist/tsup/db/drizzle.cjs +127 -67
  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 +127 -67
  89. package/dist/tsup/db/drizzle.js.map +1 -1
  90. package/dist/tsup/db/mod.cjs +6 -126
  91. package/dist/tsup/db/mod.cjs.map +1 -1
  92. package/dist/tsup/db/mod.d.cts +8 -4
  93. package/dist/tsup/db/mod.d.ts +8 -4
  94. package/dist/tsup/db/mod.js +5 -125
  95. package/dist/tsup/db/mod.js.map +1 -1
  96. package/dist/tsup/dynamic/mod.cjs +2 -2
  97. package/dist/tsup/dynamic/mod.cjs.map +1 -1
  98. package/dist/tsup/dynamic/mod.d.cts +6 -4
  99. package/dist/tsup/dynamic/mod.d.ts +6 -4
  100. package/dist/tsup/dynamic/mod.js +1 -1
  101. package/dist/tsup/inspector/mod.cjs +47 -12
  102. package/dist/tsup/inspector/mod.cjs.map +1 -1
  103. package/dist/tsup/inspector/mod.d.cts +26 -136
  104. package/dist/tsup/inspector/mod.d.ts +26 -136
  105. package/dist/tsup/inspector/mod.js +46 -11
  106. package/dist/tsup/inspector/mod.js.map +1 -1
  107. package/dist/tsup/inspector/workflow.cjs +21 -0
  108. package/dist/tsup/inspector/workflow.cjs.map +1 -0
  109. package/dist/tsup/inspector/workflow.d.cts +144 -0
  110. package/dist/tsup/inspector/workflow.d.ts +144 -0
  111. package/dist/tsup/inspector/workflow.js +21 -0
  112. package/dist/tsup/inspector/workflow.js.map +1 -0
  113. package/dist/tsup/inspector-tab/mod.cjs +2 -13
  114. package/dist/tsup/inspector-tab/mod.cjs.map +1 -1
  115. package/dist/tsup/inspector-tab/mod.d.cts +9 -17
  116. package/dist/tsup/inspector-tab/mod.d.ts +9 -17
  117. package/dist/tsup/inspector-tab/mod.js +1 -12
  118. package/dist/tsup/inspector-tab/mod.js.map +1 -1
  119. package/dist/tsup/mod.cjs +2724 -611
  120. package/dist/tsup/mod.cjs.map +1 -1
  121. package/dist/tsup/mod.d.cts +9 -7
  122. package/dist/tsup/mod.d.ts +9 -7
  123. package/dist/tsup/mod.js +2641 -528
  124. package/dist/tsup/mod.js.map +1 -1
  125. package/dist/tsup/test/mod.cjs +19 -17
  126. package/dist/tsup/test/mod.cjs.map +1 -1
  127. package/dist/tsup/test/mod.d.cts +6 -4
  128. package/dist/tsup/test/mod.d.ts +6 -4
  129. package/dist/tsup/test/mod.js +18 -16
  130. package/dist/tsup/test/mod.js.map +1 -1
  131. package/dist/tsup/unstable/migrations.cjs +101 -0
  132. package/dist/tsup/unstable/migrations.cjs.map +1 -0
  133. package/dist/tsup/unstable/migrations.d.cts +29 -0
  134. package/dist/tsup/unstable/migrations.d.ts +29 -0
  135. package/dist/tsup/unstable/migrations.js +101 -0
  136. package/dist/tsup/unstable/migrations.js.map +1 -0
  137. package/dist/tsup/{utils-CqDnC_PS.d.cts → utils-3rsE0JvI.d.cts} +25 -2
  138. package/dist/tsup/{utils-CqDnC_PS.d.ts → utils-3rsE0JvI.d.ts} +25 -2
  139. package/dist/tsup/utils-C1O-SklO.d.ts +162 -0
  140. package/dist/tsup/utils-C6b0aYUM.d.cts +162 -0
  141. package/dist/tsup/utils.cjs +7 -3
  142. package/dist/tsup/utils.cjs.map +1 -1
  143. package/dist/tsup/utils.d.cts +4 -147
  144. package/dist/tsup/utils.d.ts +4 -147
  145. package/dist/tsup/utils.js +6 -2
  146. package/dist/tsup/workflow/mod.cjs +260 -200
  147. package/dist/tsup/workflow/mod.cjs.map +1 -1
  148. package/dist/tsup/workflow/mod.d.cts +8 -6
  149. package/dist/tsup/workflow/mod.d.ts +8 -6
  150. package/dist/tsup/workflow/mod.js +249 -189
  151. package/dist/tsup/workflow/mod.js.map +1 -1
  152. package/package.json +34 -14
  153. package/src/actor/actions.ts +155 -0
  154. package/src/actor/config.ts +403 -43
  155. package/src/actor/definition.ts +26 -7
  156. package/src/actor/errors.ts +87 -5
  157. package/src/actor/keys.ts +86 -0
  158. package/src/actor/mod.ts +15 -1
  159. package/src/actor/tracing.ts +28 -0
  160. package/src/agent-os/index.ts +5 -65
  161. package/src/client/actor-common.ts +8 -15
  162. package/src/client/actor-conn.ts +135 -8
  163. package/src/client/actor-handle.ts +180 -42
  164. package/src/client/actor-query.ts +8 -1
  165. package/src/client/auth.ts +37 -0
  166. package/src/client/client.ts +89 -21
  167. package/src/client/config.ts +27 -2
  168. package/src/client/errors.ts +2 -1
  169. package/src/client/lifecycle-errors.ts +16 -1
  170. package/src/client/mod.ts +9 -0
  171. package/src/client/outbound-telemetry.ts +66 -0
  172. package/src/client/query.ts +2 -0
  173. package/src/client/queue.ts +3 -0
  174. package/src/client/raw-utils.ts +37 -8
  175. package/src/client/resolve-gateway-target.ts +2 -0
  176. package/src/client/retry-budget.ts +78 -0
  177. package/src/client/token-provider.ts +93 -0
  178. package/src/client/utils.ts +16 -2
  179. package/src/common/actor-router-consts.ts +5 -0
  180. package/src/common/actor-telemetry-context.ts +19 -0
  181. package/src/common/bare/generated/actor-runtime-socket-protocol/v1.ts +848 -0
  182. package/src/common/bare/generated/inspector/v5.ts +1016 -0
  183. package/src/common/bare/generated/inspector/v6.ts +1367 -0
  184. package/src/common/bare/transport/v1.ts +36 -0
  185. package/src/common/database/config.ts +108 -15
  186. package/src/common/database/mod.ts +247 -76
  187. package/src/common/database/native-database.ts +433 -23
  188. package/src/common/database/shared.ts +24 -0
  189. package/src/common/encoding.ts +31 -21
  190. package/src/common/fetch-like.ts +63 -0
  191. package/src/common/inspector-transport.ts +12 -2
  192. package/src/common/log.ts +14 -8
  193. package/src/common/otel-context.ts +99 -0
  194. package/src/common/router.ts +1 -1
  195. package/src/common/utils.ts +7 -19
  196. package/src/db/drizzle.ts +182 -80
  197. package/src/db/mod.ts +2 -0
  198. package/src/dynamic/isolate-runtime.ts +0 -2
  199. package/src/engine-api/actors.ts +3 -3
  200. package/src/engine-client/actor-http-client.ts +29 -20
  201. package/src/engine-client/actor-websocket-client.ts +6 -3
  202. package/src/engine-client/api-endpoints.ts +72 -14
  203. package/src/engine-client/driver.ts +8 -15
  204. package/src/engine-client/mod.ts +248 -112
  205. package/src/inspector/client.browser.ts +134 -16
  206. package/src/inspector/mod.ts +1 -1
  207. package/src/inspector/workflow.ts +61 -0
  208. package/src/inspector-tab/mod.ts +1 -15
  209. package/src/registry/config/envoy.ts +2 -18
  210. package/src/registry/config/index.ts +53 -61
  211. package/src/registry/index.ts +311 -21
  212. package/src/registry/napi-runtime.ts +583 -39
  213. package/src/registry/native-http.ts +225 -0
  214. package/src/registry/native.ts +1365 -414
  215. package/src/registry/run-handler-coordinator.ts +219 -0
  216. package/src/registry/runtime.ts +372 -7
  217. package/src/registry/wasm-runtime.ts +490 -21
  218. package/src/registry/write-through-proxy.ts +101 -0
  219. package/src/test/mod.ts +1 -19
  220. package/src/test/ready.ts +22 -0
  221. package/src/unstable/migrations.ts +141 -0
  222. package/src/utils/env-vars.ts +15 -6
  223. package/src/utils/node.ts +44 -28
  224. package/src/utils.ts +3 -0
  225. package/src/workflow/context.ts +9 -27
  226. package/src/workflow/driver.ts +253 -116
  227. package/src/workflow/inspector.ts +23 -24
  228. package/src/workflow/mod.ts +50 -72
  229. package/dist/tsup/chunk-3GVMLSND.js.map +0 -1
  230. package/dist/tsup/chunk-3MHDOUD7.cjs.map +0 -1
  231. package/dist/tsup/chunk-4FC7TVS6.cjs.map +0 -1
  232. package/dist/tsup/chunk-B3GLD4IN.js.map +0 -1
  233. package/dist/tsup/chunk-BWERJMV6.cjs.map +0 -1
  234. package/dist/tsup/chunk-D363DMNH.cjs.map +0 -1
  235. package/dist/tsup/chunk-DTRDGPHU.cjs.map +0 -1
  236. package/dist/tsup/chunk-E4LNLI3W.cjs.map +0 -1
  237. package/dist/tsup/chunk-EFU4JW3T.js.map +0 -1
  238. package/dist/tsup/chunk-FNAXD5BQ.cjs.map +0 -1
  239. package/dist/tsup/chunk-GM45LG7L.cjs.map +0 -1
  240. package/dist/tsup/chunk-HXUEHHJF.js.map +0 -1
  241. package/dist/tsup/chunk-JZ7TWV65.js.map +0 -1
  242. package/dist/tsup/chunk-O3ZUMAN7.js.map +0 -1
  243. package/dist/tsup/chunk-P6F5MEWX.cjs +0 -382
  244. package/dist/tsup/chunk-P6F5MEWX.cjs.map +0 -1
  245. package/dist/tsup/chunk-PT7AC5PC.js.map +0 -1
  246. package/dist/tsup/chunk-UV7INX3N.js +0 -382
  247. package/dist/tsup/chunk-UV7INX3N.js.map +0 -1
  248. package/dist/tsup/chunk-VE2X4KMG.cjs.map +0 -1
  249. package/dist/tsup/chunk-XIX5DOZN.js.map +0 -1
  250. package/dist/tsup/chunk-ZA7FLHKH.cjs.map +0 -1
  251. package/dist/tsup/chunk-ZZ3WBRPD.js.map +0 -1
  252. package/src/actor/driver.ts +0 -141
  253. package/src/actor/instance/mod.ts +0 -2484
  254. package/src/actor/keys.test.ts +0 -275
  255. package/src/actor/utils.test.ts +0 -48
  256. package/src/agent-os/actor/cron.ts +0 -84
  257. package/src/agent-os/actor/db.ts +0 -54
  258. package/src/agent-os/actor/filesystem.ts +0 -131
  259. package/src/agent-os/actor/index.ts +0 -285
  260. package/src/agent-os/actor/network.ts +0 -58
  261. package/src/agent-os/actor/preview.ts +0 -190
  262. package/src/agent-os/actor/process.ts +0 -177
  263. package/src/agent-os/actor/session.ts +0 -518
  264. package/src/agent-os/actor/shell.ts +0 -60
  265. package/src/agent-os/config.ts +0 -79
  266. package/src/agent-os/fs/database-vfs.ts +0 -624
  267. package/src/agent-os/types.ts +0 -148
  268. package/src/client/test.ts +0 -44
  269. package/src/common/database/mod.test.ts +0 -137
  270. package/src/common/database/native-database.test.ts +0 -211
  271. package/src/common/inline-websocket-adapter.test.ts +0 -51
  272. package/src/drivers/engine/actor-driver.ts +0 -2473
  273. package/src/registry/process-metrics.ts +0 -250
  274. package/src/registry/runtime.test.ts +0 -50
  275. package/src/utils/endpoint-parser.test.ts +0 -206
  276. package/src/utils.test.ts +0 -34
  277. /package/dist/tsup/{chunk-OAUFXOG7.js.map → chunk-3DONDAMG.js.map} +0 -0
@@ -1,9 +1,11 @@
1
1
  import type { AnyActorDefinition } from "@/actor/definition";
2
- import type { ActorSpecifier } from "@/actor/errors";
2
+ import { type ActorSpecifier, encodeErrorForBridge } from "@/actor/errors";
3
+ import type { ActorInvocationSpanContext } from "@/common/actor-telemetry-context";
3
4
  import {
4
5
  HEADER_CONN_PARAMS,
5
6
  HEADER_ENCODING,
6
7
  } from "@/common/actor-router-consts";
8
+ import { isRequestLike } from "@/common/fetch-like";
7
9
  import type * as protocol from "@/common/client-protocol";
8
10
  import {
9
11
  CURRENT_VERSION as CLIENT_PROTOCOL_CURRENT_VERSION,
@@ -23,6 +25,14 @@ import { AsyncMutex } from "@/common/database/shared";
23
25
  import type { Encoding, JsonCompatValue } from "@/common/encoding";
24
26
  import { deconstructError } from "@/common/utils";
25
27
  import type { EngineControlClient } from "@/engine-client/driver";
28
+ import type {
29
+ ActorIssueTokenOptions,
30
+ ActorTokenPermissions,
31
+ ActorTokenResource,
32
+ IssuedToken,
33
+ TokenGrant,
34
+ } from "@/client/auth";
35
+ import type { StartCallSpan, CurrentActorInvocation } from "@/registry/runtime";
26
36
  import {
27
37
  decodeCborCompat,
28
38
  deserializeWithEncoding,
@@ -51,7 +61,9 @@ import {
51
61
  import { type ClientRaw, CREATE_ACTOR_CONN_PROXY } from "./client";
52
62
  import { ActorError, isSchedulingError } from "./errors";
53
63
  import { retryOnLifecycleBoundary } from "./lifecycle-errors";
64
+ import { RetryBudget, retryAfterMs, retryDelayMs } from "./retry-budget";
54
65
  import { logger } from "./log";
66
+ import { outboundTelemetryHeaders } from "./outbound-telemetry";
55
67
  import {
56
68
  createQueueSender,
57
69
  type QueueSendNoWaitOptions,
@@ -59,7 +71,7 @@ import {
59
71
  type QueueSendResult,
60
72
  type QueueSendWaitOptions,
61
73
  } from "./queue";
62
- import { rawHttpFetch, rawWebSocket } from "./raw-utils";
74
+ import { prepareRetryableInit, rawHttpFetch, rawWebSocket } from "./raw-utils";
63
75
  import { resolveGatewayTarget } from "./resolve-gateway-target";
64
76
  import { sendHttpRequest } from "./utils";
65
77
 
@@ -77,9 +89,13 @@ export class ActorHandleRaw {
77
89
  #gatewayOptions: ActorGatewayOptions;
78
90
  #params: unknown;
79
91
  #getParams?: () => Promise<unknown>;
92
+ #signal?: AbortSignal;
80
93
  #resolvedActorId?: string;
81
94
  #resolvingActorId?: Promise<string>;
82
95
  #queueSendMutex = new AsyncMutex();
96
+ #currentActorInvocation?: CurrentActorInvocation;
97
+ #startCallSpan?: StartCallSpan;
98
+ #retryBudget: RetryBudget;
83
99
 
84
100
  /**
85
101
  * Do not call this directly.
@@ -96,6 +112,10 @@ export class ActorHandleRaw {
96
112
  encoding: Encoding,
97
113
  actorResolutionState: ActorResolutionState,
98
114
  gatewayOptions: ActorGatewayOptions = {},
115
+ signal?: AbortSignal,
116
+ currentActorInvocation?: CurrentActorInvocation,
117
+ startCallSpan?: StartCallSpan,
118
+ retryBudget: RetryBudget = new RetryBudget(),
99
119
  ) {
100
120
  this.#client = client;
101
121
  this.#driver = driver;
@@ -104,6 +124,10 @@ export class ActorHandleRaw {
104
124
  this.#gatewayOptions = gatewayOptions;
105
125
  this.#params = params;
106
126
  this.#getParams = getParams;
127
+ this.#signal = signal;
128
+ this.#currentActorInvocation = currentActorInvocation;
129
+ this.#startCallSpan = startCallSpan;
130
+ this.#retryBudget = retryBudget;
107
131
  }
108
132
 
109
133
  async #resolveConnectionParams(): Promise<unknown> {
@@ -139,8 +163,14 @@ export class ActorHandleRaw {
139
163
  ): Promise<QueueSendResult | void> {
140
164
  return await this.#queueSendMutex.run(async () => {
141
165
  const maxAttempts = this.#getDynamicQueryMaxAttempts();
142
- let useQueryTarget = false;
166
+ // Dynamic (get/getOrCreate) handles resolve at the gateway per
167
+ // request so cross-datacenter queries forward to the reserved dc,
168
+ // rather than pre-resolving via the non-forwarding PUT /actors path.
169
+ let useQueryTarget = isDynamicActorQuery(
170
+ this.#actorResolutionState,
171
+ );
143
172
 
173
+ this.#retryBudget.deposit();
144
174
  for (let attempt = 0; attempt < maxAttempts; attempt++) {
145
175
  let actorId: string | undefined;
146
176
  try {
@@ -157,6 +187,10 @@ export class ActorHandleRaw {
157
187
  return await createQueueSender({
158
188
  encoding: this.#encoding,
159
189
  params: this.#params,
190
+ telemetryHeaders: () =>
191
+ outboundTelemetryHeaders(
192
+ this.#currentActorInvocation?.(),
193
+ ),
160
194
  customFetch: async (request: Request) => {
161
195
  return await this.#driver.sendRequest(
162
196
  target,
@@ -166,7 +200,7 @@ export class ActorHandleRaw {
166
200
  },
167
201
  }).send(name, body, options as any);
168
202
  } catch (err) {
169
- const { group, code, message, metadata, actor } =
203
+ const { group, code, message, metadata, rayId, actor } =
170
204
  deconstructError(err, true);
171
205
 
172
206
  if (
@@ -176,9 +210,19 @@ export class ActorHandleRaw {
176
210
  metadata,
177
211
  attempt,
178
212
  maxAttempts,
179
- )
213
+ ) &&
214
+ this.#retryBudget.tryWithdraw()
180
215
  ) {
181
- await this.#waitForRetryWindow();
216
+ await new Promise((resolve) =>
217
+ setTimeout(
218
+ resolve,
219
+ retryDelayMs(attempt, {
220
+ initialDelayMs: 25,
221
+ maxDelayMs: 1_000,
222
+ hintMs: retryAfterMs(err),
223
+ }),
224
+ ),
225
+ );
182
226
  continue;
183
227
  }
184
228
 
@@ -189,6 +233,7 @@ export class ActorHandleRaw {
189
233
  actorId,
190
234
  attempt,
191
235
  maxAttempts,
236
+ rayId,
192
237
  )
193
238
  ) {
194
239
  useQueryTarget = true;
@@ -215,11 +260,12 @@ export class ActorHandleRaw {
215
260
  code,
216
261
  );
217
262
  if (invalidated && attempt < maxAttempts - 1) {
218
- useQueryTarget =
263
+ const waitForReady =
219
264
  code === "starting" ||
220
265
  code === "stopping" ||
221
266
  code.startsWith("destroyed_");
222
- if (useQueryTarget) {
267
+ useQueryTarget = useQueryTarget || waitForReady;
268
+ if (waitForReady) {
223
269
  await this.#waitForRetryWindow();
224
270
  }
225
271
  continue;
@@ -227,6 +273,7 @@ export class ActorHandleRaw {
227
273
 
228
274
  throw new ActorError(group, code, message, {
229
275
  metadata,
276
+ rayId,
230
277
  actor,
231
278
  });
232
279
  }
@@ -259,22 +306,51 @@ export class ActorHandleRaw {
259
306
  `Invalid action call: expected an options object { name, args }, got ${typeof opts}. Use handle.actionName(...args) for the shorthand API.`,
260
307
  );
261
308
  }
262
- const run = async () => (await this.#sendActionNow(opts)) as Response;
263
- if (opts.name === "destroy") {
264
- return await run();
309
+ // Fall back to the handle-level signal from `get`/`getOrCreate`/etc.
310
+ // when no per-call signal is provided.
311
+ const signal = opts.signal ?? this.#signal;
312
+ const optsWithSignal = { ...opts, signal };
313
+ // Open before retries so all attempts share one span and parent context.
314
+ const call = this.#startCallSpan?.(
315
+ getActorNameFromQuery(this.#actorResolutionState),
316
+ opts.name,
317
+ );
318
+ const run = async () =>
319
+ (await this.#sendActionAttempts(
320
+ optsWithSignal,
321
+ call?.span,
322
+ )) as Response;
323
+ const send = async () => {
324
+ if (opts.name === "destroy") {
325
+ return await run();
326
+ }
327
+ return await retryOnLifecycleBoundary(run, {
328
+ signal,
329
+ budget: this.#retryBudget,
330
+ });
331
+ };
332
+ if (!call) {
333
+ return await send();
334
+ }
335
+ try {
336
+ const output = await send();
337
+ call.finish();
338
+ return output;
339
+ } catch (error) {
340
+ call.finish(encodeErrorForBridge(error));
341
+ throw error;
265
342
  }
266
-
267
- return await retryOnLifecycleBoundary(run, { signal: opts.signal });
268
343
  }
269
344
 
270
- async #sendActionNow(
345
+ async #sendActionAttempts(
271
346
  opts: {
272
347
  name: string;
273
348
  args: unknown[];
274
349
  } & ActorActionOptions,
350
+ callSpan?: ActorInvocationSpanContext,
275
351
  ): Promise<unknown> {
276
352
  const maxAttempts = this.#getDynamicQueryMaxAttempts();
277
- let useQueryTarget = false;
353
+ let useQueryTarget = isDynamicActorQuery(this.#actorResolutionState);
278
354
  const gatewayOptions = resolveActorGatewayOptions(
279
355
  this.#gatewayOptions,
280
356
  opts,
@@ -303,6 +379,16 @@ export class ActorHandleRaw {
303
379
  name: opts.name,
304
380
  encoding: this.#encoding,
305
381
  });
382
+ const headers: Record<string, string> = {
383
+ [HEADER_ENCODING]: this.#encoding,
384
+ ...outboundTelemetryHeaders(
385
+ this.#currentActorInvocation?.(),
386
+ callSpan,
387
+ ),
388
+ };
389
+ if (this.#params !== undefined) {
390
+ headers[HEADER_CONN_PARAMS] = JSON.stringify(this.#params);
391
+ }
306
392
  const output = await sendHttpRequest<
307
393
  protocol.HttpActionRequest,
308
394
  protocol.HttpActionResponse,
@@ -313,16 +399,7 @@ export class ActorHandleRaw {
313
399
  >({
314
400
  url: `http://actor/action/${encodeURIComponent(opts.name)}`,
315
401
  method: "POST",
316
- headers: {
317
- [HEADER_ENCODING]: this.#encoding,
318
- ...(this.#params !== undefined
319
- ? {
320
- [HEADER_CONN_PARAMS]: JSON.stringify(
321
- this.#params,
322
- ),
323
- }
324
- : {}),
325
- },
402
+ headers,
326
403
  body: opts.args,
327
404
  encoding: this.#encoding,
328
405
  customFetch: async (request) =>
@@ -357,7 +434,7 @@ export class ActorHandleRaw {
357
434
  }
358
435
  return output;
359
436
  } catch (err) {
360
- const { group, code, message, metadata, actor } =
437
+ const { group, code, message, metadata, rayId, actor } =
361
438
  deconstructError(err, true);
362
439
 
363
440
  if (
@@ -367,6 +444,7 @@ export class ActorHandleRaw {
367
444
  actorId,
368
445
  attempt,
369
446
  maxAttempts,
447
+ rayId,
370
448
  )
371
449
  ) {
372
450
  useQueryTarget = true;
@@ -398,7 +476,7 @@ export class ActorHandleRaw {
398
476
  "actor",
399
477
  "not_found",
400
478
  "The actor does not exist or was destroyed.",
401
- { metadata, actor },
479
+ { metadata, rayId, actor },
402
480
  );
403
481
  }
404
482
 
@@ -419,7 +497,11 @@ export class ActorHandleRaw {
419
497
  continue;
420
498
  }
421
499
 
422
- throw new ActorError(group, code, message, { metadata, actor });
500
+ throw new ActorError(group, code, message, {
501
+ metadata,
502
+ rayId,
503
+ actor,
504
+ });
423
505
  }
424
506
  }
425
507
 
@@ -514,6 +596,7 @@ export class ActorHandleRaw {
514
596
  actorId: string | undefined,
515
597
  attempt: number,
516
598
  maxAttempts: number,
599
+ rayId?: string,
517
600
  ): Promise<boolean> {
518
601
  if (
519
602
  !isDynamicActorQuery(this.#actorResolutionState) ||
@@ -530,6 +613,7 @@ export class ActorHandleRaw {
530
613
  actorId,
531
614
  this.#actorResolutionState,
532
615
  this.#driver,
616
+ rayId,
533
617
  );
534
618
  if (schedulingError) {
535
619
  throw schedulingError;
@@ -619,6 +703,7 @@ export class ActorHandleRaw {
619
703
  this.#encoding,
620
704
  this.#actorResolutionState,
621
705
  resolveActorGatewayOptions(this.#gatewayOptions, options),
706
+ this.#currentActorInvocation,
622
707
  );
623
708
 
624
709
  return this.#client[CREATE_ACTOR_CONN_PROXY](
@@ -638,15 +723,27 @@ export class ActorHandleRaw {
638
723
  input: string | URL | Request,
639
724
  init?: ActorFetchInit,
640
725
  ) {
726
+ const { skipReadyWait, ...restInit } = init ?? {};
641
727
  const maxAttempts = this.#getDynamicQueryMaxAttempts();
642
- let useQueryTarget = false;
643
- const { skipReadyWait, ...requestInit } = init ?? {};
728
+ // Buffer a streaming init body before the loop, but only when retries are possible.
729
+ const requestInit =
730
+ maxAttempts > 1 ? await prepareRetryableInit(restInit) : restInit;
731
+ // Clone the input Request only when its own body is the one being sent.
732
+ // If init replaces the body, cloning a consumed input would throw.
733
+ const clonesInputBody =
734
+ requestInit.body === undefined &&
735
+ isRequestLike(input) &&
736
+ input.body !== null;
737
+ let useQueryTarget = isDynamicActorQuery(this.#actorResolutionState);
644
738
  const gatewayOptions = resolveActorGatewayOptions(
645
739
  this.#gatewayOptions,
646
740
  {
647
741
  skipReadyWait,
648
742
  },
649
743
  );
744
+ const telemetryHeaders = outboundTelemetryHeaders(
745
+ this.#currentActorInvocation?.(),
746
+ );
650
747
 
651
748
  for (let attempt = 0; attempt < maxAttempts; attempt++) {
652
749
  let actorId: string | undefined;
@@ -660,9 +757,12 @@ export class ActorHandleRaw {
660
757
  this.#driver,
661
758
  target,
662
759
  this.#params,
663
- input,
760
+ // Clone a body-bearing Request so retries don't reuse a consumed stream.
761
+ // NOTE: This holds the body in memory until GC (unavoidable).
762
+ clonesInputBody ? input.clone() : input,
664
763
  requestInit,
665
764
  gatewayOptions,
765
+ telemetryHeaders,
666
766
  );
667
767
  const retry = await this.#shouldRetryRawFetchResponse(
668
768
  response,
@@ -679,7 +779,7 @@ export class ActorHandleRaw {
679
779
  }
680
780
  return response;
681
781
  } catch (err) {
682
- const { group, code, message, metadata, actor } =
782
+ const { group, code, message, metadata, rayId, actor } =
683
783
  deconstructError(err, true);
684
784
 
685
785
  if (
@@ -689,6 +789,7 @@ export class ActorHandleRaw {
689
789
  actorId,
690
790
  attempt,
691
791
  maxAttempts,
792
+ rayId,
692
793
  )
693
794
  ) {
694
795
  useQueryTarget = true;
@@ -715,17 +816,22 @@ export class ActorHandleRaw {
715
816
  code,
716
817
  );
717
818
  if (invalidated && attempt < maxAttempts - 1) {
718
- useQueryTarget =
819
+ const waitForReady =
719
820
  code === "starting" ||
720
821
  code === "stopping" ||
721
822
  code.startsWith("destroyed_");
722
- if (useQueryTarget) {
823
+ useQueryTarget = useQueryTarget || waitForReady;
824
+ if (waitForReady) {
723
825
  await this.#waitForRetryWindow();
724
826
  }
725
827
  continue;
726
828
  }
727
829
 
728
- throw new ActorError(group, code, message, { metadata, actor });
830
+ throw new ActorError(group, code, message, {
831
+ metadata,
832
+ rayId,
833
+ actor,
834
+ });
729
835
  }
730
836
  }
731
837
 
@@ -750,7 +856,7 @@ export class ActorHandleRaw {
750
856
  return null;
751
857
  }
752
858
 
753
- const { group, code } = error;
859
+ const { group, code, rayId } = error;
754
860
 
755
861
  if (
756
862
  await this.#shouldRetrySchedulingError(
@@ -759,6 +865,7 @@ export class ActorHandleRaw {
759
865
  actorId,
760
866
  attempt,
761
867
  maxAttempts,
868
+ rayId,
762
869
  )
763
870
  ) {
764
871
  return {
@@ -784,13 +891,13 @@ export class ActorHandleRaw {
784
891
 
785
892
  const invalidated = this.#invalidateResolvedActorId(group, code);
786
893
  if (invalidated && attempt < maxAttempts - 1) {
787
- const useQueryTarget =
894
+ const waitForReady =
788
895
  code === "starting" ||
789
896
  code === "stopping" ||
790
897
  code.startsWith("destroyed_");
791
898
  return {
792
- useQueryTarget,
793
- waitForRetryWindow: useQueryTarget,
899
+ useQueryTarget: true,
900
+ waitForRetryWindow: waitForReady,
794
901
  };
795
902
  }
796
903
 
@@ -802,6 +909,7 @@ export class ActorHandleRaw {
802
909
  code: string;
803
910
  message: string;
804
911
  metadata?: unknown;
912
+ rayId?: string;
805
913
  actor?: ActorSpecifier;
806
914
  } | null> {
807
915
  if (response.ok) {
@@ -814,7 +922,7 @@ export class ActorHandleRaw {
814
922
  : this.#encoding;
815
923
 
816
924
  try {
817
- return deserializeWithEncoding<
925
+ const error = deserializeWithEncoding<
818
926
  protocol.HttpResponseError,
819
927
  HttpResponseErrorJson,
820
928
  {
@@ -822,6 +930,7 @@ export class ActorHandleRaw {
822
930
  code: string;
823
931
  message: string;
824
932
  metadata?: unknown;
933
+ rayId?: string;
825
934
  actor?: ActorSpecifier;
826
935
  }
827
936
  >(
@@ -854,6 +963,10 @@ export class ActorHandleRaw {
854
963
  : undefined,
855
964
  }),
856
965
  );
966
+ return {
967
+ ...error,
968
+ rayId: response.headers.get("x-rivet-ray-id") ?? undefined,
969
+ };
857
970
  } catch {
858
971
  return null;
859
972
  }
@@ -905,6 +1018,29 @@ export class ActorHandleRaw {
905
1018
  );
906
1019
  }
907
1020
 
1021
+ /** Issue a token scoped to this actor. Defaults to actor gateway read access. */
1022
+ async issueToken(
1023
+ options: ActorIssueTokenOptions = {},
1024
+ ): Promise<IssuedToken> {
1025
+ const actorId = await this.resolve();
1026
+ const permissions: ActorTokenPermissions = options.permissions ?? {
1027
+ actor_gateway: ["read"],
1028
+ };
1029
+ const grants: TokenGrant[] = (
1030
+ Object.keys(permissions) as ActorTokenResource[]
1031
+ ).flatMap((resource) => {
1032
+ const operations = permissions[resource];
1033
+ return operations
1034
+ ? [{ resource, target: { id: actorId }, operations }]
1035
+ : [];
1036
+ });
1037
+ return this.#driver.issueToken({
1038
+ subject: options.subject,
1039
+ expiresIn: options.expiresIn,
1040
+ grants,
1041
+ });
1042
+ }
1043
+
908
1044
  /**
909
1045
  * Returns the raw URL for routing traffic to the actor.
910
1046
  */
@@ -927,7 +1063,9 @@ export class ActorHandleRaw {
927
1063
  "actor",
928
1064
  "reload_failed",
929
1065
  `reload failed with status ${response.status}: ${body}`,
930
- {},
1066
+ {
1067
+ rayId: response.headers.get("x-rivet-ray-id") ?? undefined,
1068
+ },
931
1069
  );
932
1070
  }
933
1071
  }
@@ -958,4 +1096,4 @@ export type ActorHandle<AD extends AnyActorDefinition> = Omit<
958
1096
  // Resolve method returns the actor ID
959
1097
  resolve(): Promise<string>;
960
1098
  } & ActorDefinitionQueueSend<AD> &
961
- ActorDefinitionActions<AD>;
1099
+ Omit<ActorDefinitionActions<AD>, keyof ActorHandleRaw>;
@@ -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({
@@ -0,0 +1,37 @@
1
+ import type { Rivet } from "@rivetkit/engine-api-full";
2
+
3
+ /** A namespace-scoped Engine grant. The caller must provide every grant explicitly. */
4
+ export type TokenGrant = Rivet.AuthTokenGrant;
5
+
6
+ /** Options for `client.auth.issueToken()`. `expiresIn` is in seconds. */
7
+ export type IssueTokenOptions = Pick<
8
+ Rivet.AuthTokenCreateRequest,
9
+ "subject" | "grants"
10
+ > & {
11
+ expiresIn?: Rivet.AuthTokenCreateRequest["duration"];
12
+ };
13
+
14
+ /** Token timestamps are Unix milliseconds. */
15
+ export interface IssuedToken {
16
+ token: Rivet.AuthTokenCreateResponse["token"];
17
+ issuedAt: Rivet.AuthTokenCreateResponse["issuedTs"];
18
+ expiresAt: Rivet.AuthTokenCreateResponse["expiresTs"];
19
+ }
20
+
21
+ /** Resources that can be scoped to a single actor ID. */
22
+ export type ActorTokenResource = Extract<
23
+ Rivet.AuthTokenGrant["resource"],
24
+ "actor_gateway" | "actor" | "actor_kv"
25
+ >;
26
+
27
+ export type ActorTokenPermissions = Partial<
28
+ Record<ActorTokenResource, Rivet.AuthTokenGrant["operations"]>
29
+ >;
30
+
31
+ /** Options for `actor.issueToken()`. Omit permissions for gateway read access only. */
32
+ export type ActorIssueTokenOptions = Pick<
33
+ IssueTokenOptions,
34
+ "subject" | "expiresIn"
35
+ > & {
36
+ permissions?: ActorTokenPermissions;
37
+ };