rivetkit 0.0.0-sqlite-profiling-compat.4a9a623 → 0.0.0-sqlite-sync-3-0-0-release.14341d0

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 +1433 -692
  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-AGDY6TKH.js → chunk-2EQ2WCO7.js} +1054 -364
  19. package/dist/tsup/chunk-2EQ2WCO7.js.map +1 -0
  20. package/dist/tsup/{chunk-7QKCGUTJ.cjs → chunk-4H2LT2WB.cjs} +444 -29
  21. package/dist/tsup/chunk-4H2LT2WB.cjs.map +1 -0
  22. package/dist/tsup/{chunk-XIX5DOZN.js → chunk-6FEYCVZC.js} +196 -20
  23. package/dist/tsup/chunk-6FEYCVZC.js.map +1 -0
  24. package/dist/tsup/{chunk-QAVN4QNO.cjs → chunk-6WYQ3NJI.cjs} +7 -7
  25. package/dist/tsup/chunk-6WYQ3NJI.cjs.map +1 -0
  26. package/dist/tsup/{chunk-75UE45DE.js → chunk-6ZJX3KXW.js} +436 -21
  27. package/dist/tsup/chunk-6ZJX3KXW.js.map +1 -0
  28. package/dist/tsup/{chunk-HXUEHHJF.js → chunk-A2CF6PFH.js} +19 -11
  29. package/dist/tsup/chunk-A2CF6PFH.js.map +1 -0
  30. package/dist/tsup/{chunk-RIT7N3TX.js → chunk-AIGW2SKA.js} +50 -3
  31. package/dist/tsup/chunk-AIGW2SKA.js.map +1 -0
  32. package/dist/tsup/{chunk-3MHDOUD7.cjs → chunk-HDVZ6YZG.cjs} +197 -21
  33. package/dist/tsup/chunk-HDVZ6YZG.cjs.map +1 -0
  34. package/dist/tsup/{chunk-2CICCOBL.cjs → chunk-HU4F7H3F.cjs} +52 -5
  35. package/dist/tsup/chunk-HU4F7H3F.cjs.map +1 -0
  36. package/dist/tsup/{chunk-4PX3ZKJR.js → chunk-JNJEWQZL.js} +3 -3
  37. package/dist/tsup/chunk-JNJEWQZL.js.map +1 -0
  38. package/dist/tsup/{chunk-JZ7TWV65.js → chunk-JTHHCZCZ.js} +24 -1
  39. package/dist/tsup/chunk-JTHHCZCZ.js.map +1 -0
  40. package/dist/tsup/{chunk-ZA7FLHKH.cjs → chunk-KVFIONKQ.cjs} +25 -2
  41. package/dist/tsup/chunk-KVFIONKQ.cjs.map +1 -0
  42. package/dist/tsup/{chunk-4FC7TVS6.cjs → chunk-MGI2VVF6.cjs} +39 -7
  43. package/dist/tsup/chunk-MGI2VVF6.cjs.map +1 -0
  44. package/dist/tsup/{chunk-NHUTYWKU.cjs → chunk-NE5CUQRN.cjs} +1173 -483
  45. package/dist/tsup/chunk-NE5CUQRN.cjs.map +1 -0
  46. package/dist/tsup/{chunk-IICIOTML.js → chunk-OX5MX7TO.js} +2 -2
  47. package/dist/tsup/{chunk-ND567FR5.cjs → chunk-PSIBTOAR.cjs} +3 -3
  48. package/dist/tsup/chunk-PSIBTOAR.cjs.map +1 -0
  49. package/dist/tsup/chunk-PW6FYEIV.cjs +14 -0
  50. package/dist/tsup/chunk-PW6FYEIV.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-SLICBKAU.js +14 -0
  54. package/dist/tsup/chunk-SLICBKAU.js.map +1 -0
  55. package/dist/tsup/{chunk-XFYEVYHG.js → chunk-WCVYMFWJ.js} +16 -9
  56. package/dist/tsup/chunk-WCVYMFWJ.js.map +1 -0
  57. package/dist/tsup/chunk-WX3JS4XU.cjs +243 -0
  58. package/dist/tsup/chunk-WX3JS4XU.cjs.map +1 -0
  59. package/dist/tsup/chunk-X32L7FDD.js +243 -0
  60. package/dist/tsup/chunk-X32L7FDD.js.map +1 -0
  61. package/dist/tsup/{chunk-2WMYYG4R.cjs → chunk-XAY2HIZN.cjs} +18 -11
  62. package/dist/tsup/chunk-XAY2HIZN.cjs.map +1 -0
  63. package/dist/tsup/{chunk-ZZ3WBRPD.js → chunk-ZOVJDAOW.js} +38 -6
  64. package/dist/tsup/chunk-ZOVJDAOW.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.ts → config-BfG1qpYz.d.cts} +80 -14
  80. package/dist/tsup/{config-B0LNDrLY.d.cts → 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-oc9zhA3x.d.ts → context-Cvnf3BRe.d.cts} +3 -2
  83. package/dist/tsup/{context-D4WDwf9m.d.cts → 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 +2728 -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 +2645 -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 +178 -25
  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 +29 -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 +54 -61
  211. package/src/registry/index.ts +324 -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-2CICCOBL.cjs.map +0 -1
  230. package/dist/tsup/chunk-2WMYYG4R.cjs.map +0 -1
  231. package/dist/tsup/chunk-3MHDOUD7.cjs.map +0 -1
  232. package/dist/tsup/chunk-4FC7TVS6.cjs.map +0 -1
  233. package/dist/tsup/chunk-4PX3ZKJR.js.map +0 -1
  234. package/dist/tsup/chunk-75UE45DE.js.map +0 -1
  235. package/dist/tsup/chunk-7QKCGUTJ.cjs.map +0 -1
  236. package/dist/tsup/chunk-AGDY6TKH.js.map +0 -1
  237. package/dist/tsup/chunk-HXUEHHJF.js.map +0 -1
  238. package/dist/tsup/chunk-JZ7TWV65.js.map +0 -1
  239. package/dist/tsup/chunk-ND567FR5.cjs.map +0 -1
  240. package/dist/tsup/chunk-NHUTYWKU.cjs.map +0 -1
  241. package/dist/tsup/chunk-QAVN4QNO.cjs.map +0 -1
  242. package/dist/tsup/chunk-RIT7N3TX.js.map +0 -1
  243. package/dist/tsup/chunk-RV5MAFDT.cjs +0 -382
  244. package/dist/tsup/chunk-RV5MAFDT.cjs.map +0 -1
  245. package/dist/tsup/chunk-VE2X4KMG.cjs.map +0 -1
  246. package/dist/tsup/chunk-XFYEVYHG.js.map +0 -1
  247. package/dist/tsup/chunk-XHGDS3DZ.js +0 -382
  248. package/dist/tsup/chunk-XHGDS3DZ.js.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-IICIOTML.js.map → chunk-OX5MX7TO.js.map} +0 -0
@@ -5,10 +5,20 @@ import {
5
5
  } from "@/common/bare/transport/v1";
6
6
  import { bufferToArrayBuffer, toUint8Array } from "@/utils";
7
7
 
8
+ declare const workflowHistoryBare: unique symbol;
9
+
10
+ // Branded so these bytes cannot be handed to the CBOR compat encoder, which
11
+ // would rewrite the buffer as `["$ArrayBuffer", "<base64>"]`.
12
+ export type WorkflowHistoryBytes = ArrayBuffer & {
13
+ readonly [workflowHistoryBare]: true;
14
+ };
15
+
8
16
  export function encodeWorkflowHistoryTransport(
9
17
  history: WorkflowHistory,
10
- ): ArrayBuffer {
11
- return bufferToArrayBuffer(encodeWorkflowHistory(history));
18
+ ): WorkflowHistoryBytes {
19
+ return bufferToArrayBuffer(
20
+ encodeWorkflowHistory(history),
21
+ ) as WorkflowHistoryBytes;
12
22
  }
13
23
 
14
24
  export function decodeWorkflowHistoryTransport(
package/src/common/log.ts CHANGED
@@ -62,15 +62,10 @@ export function configureBaseLogger(logger: Logger): void {
62
62
  }
63
63
 
64
64
  /**
65
- * Configure the default logger with optional log level.
65
+ * Create the default logger with optional log level.
66
66
  */
67
- export function configureDefaultLogger(logLevel?: LogLevel) {
68
- // Store the configured log level
69
- if (logLevel) {
70
- configuredLogLevel = logLevel;
71
- }
72
-
73
- baseLogger = pino(
67
+ export function makeDefaultLogger(logLevel?: LogLevel): Logger {
68
+ return pino(
74
69
  {
75
70
  level: getPinoLevel(logLevel),
76
71
  messageKey: "msg",
@@ -87,7 +82,18 @@ export function configureDefaultLogger(logLevel?: LogLevel) {
87
82
  },
88
83
  createLogfmtDestination(),
89
84
  );
85
+ }
86
+
87
+ /**
88
+ * Configure the default logger with optional log level.
89
+ */
90
+ export function configureDefaultLogger(logLevel?: LogLevel) {
91
+ // Store the configured log level
92
+ if (logLevel) {
93
+ configuredLogLevel = logLevel;
94
+ }
90
95
 
96
+ baseLogger = makeDefaultLogger(logLevel);
91
97
  loggerCache.clear();
92
98
  }
93
99
 
@@ -0,0 +1,99 @@
1
+ import {
2
+ type Context,
3
+ context,
4
+ createTraceState,
5
+ isSpanContextValid,
6
+ propagation,
7
+ type SpanContext,
8
+ trace,
9
+ } from "@opentelemetry/api";
10
+ import type { ActorInvocationSpanContext } from "./actor-telemetry-context";
11
+
12
+ /** W3C headers derived from the active JavaScript OTel context. */
13
+ export interface ActiveTraceHeaders {
14
+ /** W3C Trace Context identifying the active trace and span. */
15
+ readonly traceparent: string;
16
+ /** Optional vendor trace state associated with the active span. */
17
+ readonly tracestate?: string;
18
+ }
19
+
20
+ /** Returns the active W3C trace context, when an OTel provider has installed one. */
21
+ export function readActiveTraceHeaders(): ActiveTraceHeaders | undefined {
22
+ return traceHeaders(trace.getSpanContext(context.active()));
23
+ }
24
+
25
+ /** W3C Baggage key that carries a ray ID through application code. */
26
+ export const RAY_BAGGAGE_KEY = "rivet.ray.id";
27
+
28
+ /**
29
+ * Returns the ray ID carried in the active OpenTelemetry baggage, so a request
30
+ * handler that received a ray ID can pass it to the actors it calls. The bound
31
+ * is the one Core applies on receipt, so an invalid value is never sent.
32
+ */
33
+ export function readActiveRayId(): string | undefined {
34
+ const value = propagation
35
+ .getBaggage(context.active())
36
+ ?.getEntry(RAY_BAGGAGE_KEY)?.value;
37
+ if (value && value.length <= 30 && /^[A-Za-z0-9_-]+$/.test(value)) {
38
+ return value;
39
+ }
40
+ return undefined;
41
+ }
42
+
43
+ /** W3C headers for the Core invocation span, or nothing when it is absent or invalid. */
44
+ export function actorInvocationTraceHeaders(
45
+ invocation: ActorInvocationSpanContext | undefined,
46
+ ): ActiveTraceHeaders | undefined {
47
+ const spanContext = invocationSpanContext(invocation);
48
+ if (!spanContext) return undefined;
49
+ return traceHeaders(spanContext);
50
+ }
51
+
52
+ function traceHeaders(
53
+ spanContext: SpanContext | undefined,
54
+ ): ActiveTraceHeaders | undefined {
55
+ if (!spanContext || !isSpanContextValid(spanContext)) return undefined;
56
+ const tracestate = spanContext.traceState?.serialize();
57
+ return {
58
+ traceparent: `00-${spanContext.traceId}-${spanContext.spanId}-${spanContext.traceFlags.toString(16).padStart(2, "0")}`,
59
+ ...(tracestate ? { tracestate } : {}),
60
+ };
61
+ }
62
+
63
+ /**
64
+ * Runs `run` with the Core invocation span as the active OpenTelemetry span,
65
+ * so application spans started inside an actor callback nest under it. With
66
+ * no span, or an invalid one, `run` executes unchanged.
67
+ */
68
+ export function runWithActorInvocationSpan<T>(
69
+ invocation: ActorInvocationSpanContext | undefined,
70
+ run: () => T,
71
+ ): T {
72
+ if (!invocation) return run();
73
+
74
+ const spanContext = invocationSpanContext(invocation);
75
+ if (!spanContext) return run();
76
+ const parent: Context = trace.setSpanContext(context.active(), spanContext);
77
+
78
+ return context.with(parent, run);
79
+ }
80
+
81
+ function invocationSpanContext(
82
+ invocation: ActorInvocationSpanContext | undefined,
83
+ ): SpanContext | undefined {
84
+ if (!invocation) return undefined;
85
+ try {
86
+ const spanContext: SpanContext = {
87
+ traceId: invocation.traceId,
88
+ spanId: invocation.spanId,
89
+ traceFlags: invocation.traceFlags,
90
+ traceState: invocation.tracestate
91
+ ? createTraceState(invocation.tracestate)
92
+ : undefined,
93
+ isRemote: false,
94
+ };
95
+ return isSpanContextValid(spanContext) ? spanContext : undefined;
96
+ } catch {
97
+ return undefined;
98
+ }
99
+ }
@@ -182,7 +182,7 @@ export function handleMetadataRequest(
182
182
  version: VERSION,
183
183
  envoy: {
184
184
  kind: envoyKind,
185
- version: config.envoy.version,
185
+ version: config.node.version,
186
186
  },
187
187
  envoyProtocolVersion: envoyProtocol.VERSION,
188
188
  actorNames: buildActorNames(config),
@@ -44,27 +44,10 @@ export interface DeconstructedError {
44
44
  code: string;
45
45
  message: string;
46
46
  metadata?: unknown;
47
+ rayId?: string;
47
48
  actor?: errors.ActorSpecifier;
48
49
  }
49
50
 
50
- function isCanonicalStructuredRivetError(
51
- error: unknown,
52
- ): error is errors.RivetErrorLike {
53
- return (
54
- error instanceof errors.RivetError ||
55
- (typeof error === "object" &&
56
- error !== null &&
57
- "__type" in error &&
58
- error.__type === "RivetError" &&
59
- "group" in error &&
60
- typeof error.group === "string" &&
61
- "code" in error &&
62
- typeof error.code === "string" &&
63
- "message" in error &&
64
- typeof error.message === "string")
65
- );
66
- }
67
-
68
51
  /**
69
52
  * Deconstructs errors into response fields. Bridge callback errors that cross
70
53
  * into rivetkit-core are sanitized there; this only classifies JS-local errors.
@@ -80,10 +63,11 @@ export function deconstructError(
80
63
  let code: string;
81
64
  let message: string;
82
65
  let metadata: unknown;
66
+ let rayId: string | undefined;
83
67
  let actor: errors.ActorSpecifier | undefined;
84
68
  // Structured errors from core or from pre-built `RivetError` instances are canonical.
85
69
  // Only unstructured errors go through the classifier below.
86
- if (isCanonicalStructuredRivetError(error)) {
70
+ if (errors.isCanonicalStructuredRivetError(error)) {
87
71
  statusCode = (
88
72
  typeof error.statusCode === "number"
89
73
  ? error.statusCode
@@ -96,6 +80,7 @@ export function deconstructError(
96
80
  code = error.code;
97
81
  message = error.message;
98
82
  metadata = error.metadata;
83
+ rayId = error.rayId;
99
84
  actor = error.actor;
100
85
  } else if (errors.ActorError.isActorError(error) && error.public) {
101
86
  // Check if error has statusCode (could be ActorError instance or DeconstructedError)
@@ -107,6 +92,7 @@ export function deconstructError(
107
92
  code = error.code;
108
93
  message = getErrorMessage(error);
109
94
  metadata = error.metadata;
95
+ rayId = error.rayId;
110
96
  actor = error.actor;
111
97
  } else if (exposeInternalError) {
112
98
  if (errors.ActorError.isActorError(error)) {
@@ -116,6 +102,7 @@ export function deconstructError(
116
102
  code = error.code;
117
103
  message = getErrorMessage(error);
118
104
  metadata = error.metadata;
105
+ rayId = error.rayId;
119
106
  actor = error.actor;
120
107
  } else {
121
108
  statusCode = 500;
@@ -146,6 +133,7 @@ export function deconstructError(
146
133
  code,
147
134
  message,
148
135
  metadata,
136
+ rayId,
149
137
  actor,
150
138
  };
151
139
  }
package/src/db/drizzle.ts CHANGED
@@ -7,9 +7,19 @@ import type {
7
7
  DatabaseProvider,
8
8
  DatabaseProviderContext,
9
9
  RawAccess,
10
+ SqliteProfilingOptions,
11
+ SqliteTransactionOptions,
10
12
  SqliteDatabase,
13
+ SqliteTransactionDatabase,
11
14
  } from "@/common/database/config";
12
- import { toSqliteBindings } from "@/common/database/shared";
15
+ import { getLogger } from "@/common/log";
16
+ import {
17
+ isManualTransactionControl,
18
+ MIGRATION_TRANSACTION_TIMEOUT_MS,
19
+ toSqliteBindings,
20
+ validateTransactionName,
21
+ validateTransactionTimeout,
22
+ } from "@/common/database/shared";
13
23
  import { sha256Hex } from "@/utils/crypto";
14
24
 
15
25
  export type { SQLiteTable } from "drizzle-orm/sqlite-core";
@@ -28,8 +38,16 @@ export {
28
38
  } from "drizzle-orm/sqlite-core";
29
39
 
30
40
  type DrizzleSchema = Record<string, unknown>;
31
- type DrizzleDatabase<TSchema extends DrizzleSchema> =
32
- SqliteRemoteDatabase<TSchema> & RawAccess;
41
+ type DrizzleDatabase<TSchema extends DrizzleSchema> = Omit<
42
+ SqliteRemoteDatabase<TSchema>,
43
+ "transaction"
44
+ > &
45
+ Omit<RawAccess, "transaction"> & {
46
+ transaction: <T>(
47
+ callback: (tx: DrizzleDatabase<TSchema>) => Promise<T> | T,
48
+ options?: SqliteTransactionOptions,
49
+ ) => Promise<T>;
50
+ };
33
51
 
34
52
  interface DrizzleMigrationJournalEntry {
35
53
  idx: number;
@@ -43,10 +61,12 @@ interface DrizzleMigrations {
43
61
  migrations: Record<string, string>;
44
62
  }
45
63
 
46
- interface DrizzleDatabaseFactoryConfig<TSchema extends DrizzleSchema> {
64
+ export interface DrizzleDatabaseFactoryConfig<TSchema extends DrizzleSchema> {
47
65
  schema?: TSchema;
48
66
  migrations?: DrizzleMigrations;
49
67
  onMigrate?: (db: DrizzleDatabase<TSchema>) => Promise<void> | void;
68
+ warnOnManualTransactions?: boolean;
69
+ profiling?: SqliteProfilingOptions;
50
70
  }
51
71
 
52
72
  interface DrizzleKitConfig {
@@ -69,10 +89,13 @@ export function db<TSchema extends DrizzleSchema = Record<string, never>>({
69
89
  schema,
70
90
  migrations,
71
91
  onMigrate,
92
+ warnOnManualTransactions = true,
93
+ profiling,
72
94
  }: DrizzleDatabaseFactoryConfig<TSchema> = {}): DatabaseProvider<
73
95
  DrizzleDatabase<TSchema>
74
96
  > {
75
97
  return {
98
+ sqliteProfiling: profiling,
76
99
  createClient: async (ctx) => {
77
100
  const override = ctx.overrideDrizzleDatabaseClient
78
101
  ? await ctx.overrideDrizzleDatabaseClient()
@@ -90,6 +113,7 @@ export function db<TSchema extends DrizzleSchema = Record<string, never>>({
90
113
 
91
114
  const nativeDb = await nativeDatabaseProvider.open(ctx.actorId);
92
115
  let closed = false;
116
+ let manualTransactionWarned = false;
93
117
  const ensureOpen = () => {
94
118
  if (closed) {
95
119
  throw new Error(
@@ -98,107 +122,183 @@ export function db<TSchema extends DrizzleSchema = Record<string, never>>({
98
122
  }
99
123
  };
100
124
 
101
- const runSql = async (
102
- query: string,
103
- params: unknown[],
104
- method: "run" | "all" | "values" | "get",
105
- ) => {
106
- ensureOpen();
125
+ const createDrizzleClient = (
126
+ target: SqliteDatabase | SqliteTransactionDatabase,
127
+ transactionScoped = false,
128
+ ): DrizzleDatabase<TSchema> => {
129
+ const runSql = async (
130
+ query: string,
131
+ params: unknown[],
132
+ method: "run" | "all" | "values" | "get",
133
+ ) => {
134
+ ensureOpen();
135
+ warnForManualTransaction(query, transactionScoped);
107
136
 
108
- const start = performance.now();
109
- const kvReadsBefore = ctx.metrics?.totalKvReads ?? 0;
110
- const kvWritesBefore = ctx.metrics?.totalKvWrites ?? 0;
111
- try {
112
- const { rows } = await nativeDb.execute(
137
+ const start = performance.now();
138
+ const kvReadsBefore = ctx.metrics?.totalKvReads ?? 0;
139
+ const kvWritesBefore = ctx.metrics?.totalKvWrites ?? 0;
140
+ try {
141
+ const { rows } = await target.execute(
142
+ query,
143
+ toSqliteBindings(params),
144
+ );
145
+ if (method === "run") {
146
+ return { rows: [] };
147
+ }
148
+ if (method === "get") {
149
+ return { rows: rows[0] };
150
+ }
151
+ return { rows };
152
+ } finally {
153
+ const durationMs = performance.now() - start;
154
+ ctx.metrics?.trackSql(query, durationMs);
155
+ if (ctx.metrics) {
156
+ ctx.log?.debug({
157
+ msg: "sql query",
158
+ query: query.slice(0, 120),
159
+ durationMs,
160
+ kvReads:
161
+ ctx.metrics.totalKvReads - kvReadsBefore,
162
+ kvWrites:
163
+ ctx.metrics.totalKvWrites - kvWritesBefore,
164
+ });
165
+ }
166
+ }
167
+ };
168
+
169
+ const callback: RemoteCallback = async (
170
+ query,
171
+ params,
172
+ method,
173
+ ) => {
174
+ return await runSql(query, params, method);
175
+ };
176
+
177
+ const drizzleDb = drizzle(callback, {
178
+ schema,
179
+ }) as unknown as DrizzleDatabase<TSchema>;
180
+ drizzleDb.execute = async <
181
+ TRow extends Record<string, unknown> = Record<
182
+ string,
183
+ unknown
184
+ >,
185
+ >(
186
+ query: string,
187
+ ...args: unknown[]
188
+ ): Promise<TRow[]> => {
189
+ return await executeRaw<TRow>(
190
+ target,
191
+ ctx,
192
+ ensureOpen,
113
193
  query,
114
- toSqliteBindings(params),
194
+ args,
195
+ () =>
196
+ warnForManualTransaction(query, transactionScoped),
115
197
  );
116
- if (method === "run") {
117
- return { rows: [] };
118
- }
119
- if (method === "get") {
120
- return { rows: rows[0] };
198
+ };
199
+ drizzleDb.transaction = async <T>(
200
+ transactionCallback: (
201
+ tx: DrizzleDatabase<TSchema>,
202
+ ) => Promise<T> | T,
203
+ options?: SqliteTransactionOptions,
204
+ ): Promise<T> => {
205
+ validateTransactionTimeout(options?.timeout);
206
+ validateTransactionName(options?.name);
207
+ const transaction = await nativeDb.beginTransaction(
208
+ options?.timeout,
209
+ options?.name,
210
+ );
211
+ const tx = createDrizzleClient(transaction, true);
212
+ try {
213
+ const result = await transactionCallback(tx);
214
+ await transaction.commit();
215
+ return result;
216
+ } catch (error) {
217
+ try {
218
+ await transaction.rollback();
219
+ } catch {
220
+ // Preserve the callback or commit error after expiry cleanup.
221
+ }
222
+ throw error;
121
223
  }
122
- return { rows };
123
- } finally {
124
- const durationMs = performance.now() - start;
125
- ctx.metrics?.trackSql(query, durationMs);
126
- if (ctx.metrics) {
127
- ctx.log?.debug({
128
- msg: "sql query",
129
- query: query.slice(0, 120),
130
- durationMs,
131
- kvReads: ctx.metrics.totalKvReads - kvReadsBefore,
132
- kvWrites:
133
- ctx.metrics.totalKvWrites - kvWritesBefore,
134
- });
224
+ };
225
+ drizzleDb.close = async () => {
226
+ if (!closed) {
227
+ closed = true;
228
+ await nativeDb.close();
135
229
  }
136
- }
137
- };
230
+ };
138
231
 
139
- const callback: RemoteCallback = async (query, params, method) => {
140
- return await runSql(query, params, method);
232
+ return drizzleDb;
141
233
  };
142
234
 
143
- const drizzleDb = drizzle(callback, {
144
- schema,
145
- }) as DrizzleDatabase<TSchema>;
146
- drizzleDb.execute = async <
147
- TRow extends Record<string, unknown> = Record<string, unknown>,
148
- >(
235
+ const warnForManualTransaction = (
149
236
  query: string,
150
- ...args: unknown[]
151
- ): Promise<TRow[]> => {
152
- return await executeRaw<TRow>(
153
- nativeDb,
154
- ctx,
155
- ensureOpen,
156
- query,
157
- args,
158
- );
159
- };
160
- drizzleDb.close = async () => {
161
- if (!closed) {
162
- closed = true;
163
- await nativeDb.close();
237
+ transactionScoped: boolean,
238
+ ) => {
239
+ if (
240
+ transactionScoped ||
241
+ !warnOnManualTransactions ||
242
+ manualTransactionWarned ||
243
+ hasMultipleStatements(query) ||
244
+ !isManualTransactionControl(query)
245
+ ) {
246
+ return;
164
247
  }
248
+ manualTransactionWarned = true;
249
+ getLogger("database").warn(
250
+ { actorId: ctx.actorId },
251
+ "Manual cross-call SQLite transactions can interleave with other actor work. Use db.transaction() for coordinated transactions. Set warnOnManualTransactions: false in your db(...) configuration to disable this warning.",
252
+ );
165
253
  };
166
254
 
167
- return drizzleDb;
255
+ return createDrizzleClient(nativeDb);
168
256
  },
169
257
  onMigrate: async (client) => {
170
258
  if (!migrations && !onMigrate) {
171
259
  return;
172
260
  }
173
- await withMigrationSavepoint(client, async () => {
261
+ await withMigrationSavepoint(client, async (leased) => {
174
262
  if (migrations) {
175
- await runMigrations(client, migrations);
263
+ await runMigrations(leased, migrations);
176
264
  }
177
265
  if (onMigrate) {
178
- await onMigrate(client);
266
+ await onMigrate(leased);
179
267
  }
180
268
  });
181
269
  },
182
270
  };
183
271
  }
184
272
 
185
- async function withMigrationSavepoint<T>(
186
- client: RawAccess,
187
- callback: () => Promise<T> | T,
273
+ async function withMigrationSavepoint<TSchema extends DrizzleSchema, T>(
274
+ client: DrizzleDatabase<TSchema>,
275
+ callback: (leased: DrizzleDatabase<TSchema>) => Promise<T> | T,
188
276
  ): Promise<T> {
189
- await client.execute("SAVEPOINT __rivet_on_migrate");
190
- try {
191
- const result = await callback();
192
- await client.execute("RELEASE SAVEPOINT __rivet_on_migrate");
193
- return result;
194
- } catch (error) {
195
- try {
196
- await client.execute("ROLLBACK TO SAVEPOINT __rivet_on_migrate");
197
- } finally {
198
- await client.execute("RELEASE SAVEPOINT __rivet_on_migrate");
199
- }
200
- throw error;
201
- }
277
+ return await client.transaction(
278
+ async (leased) => {
279
+ await leased.execute("SAVEPOINT __rivet_on_migrate");
280
+ try {
281
+ const result = await callback(leased);
282
+ await leased.execute("RELEASE SAVEPOINT __rivet_on_migrate");
283
+ return result;
284
+ } catch (error) {
285
+ try {
286
+ await leased.execute(
287
+ "ROLLBACK TO SAVEPOINT __rivet_on_migrate",
288
+ );
289
+ } finally {
290
+ await leased.execute(
291
+ "RELEASE SAVEPOINT __rivet_on_migrate",
292
+ );
293
+ }
294
+ throw error;
295
+ }
296
+ },
297
+ {
298
+ name: "rivetkit-drizzle-migration",
299
+ timeout: MIGRATION_TRANSACTION_TIMEOUT_MS,
300
+ },
301
+ );
202
302
  }
203
303
 
204
304
  async function runMigrations<TSchema extends DrizzleSchema>(
@@ -281,13 +381,15 @@ function rowToObject<TRow extends Record<string, unknown>>(
281
381
  }
282
382
 
283
383
  async function executeRaw<TRow extends Record<string, unknown>>(
284
- db: SqliteDatabase,
384
+ db: SqliteDatabase | SqliteTransactionDatabase,
285
385
  ctx: DatabaseProviderContext,
286
386
  ensureOpen: () => void,
287
387
  query: string,
288
388
  args: unknown[],
389
+ warnForManualTransaction: () => void,
289
390
  ): Promise<TRow[]> {
290
391
  ensureOpen();
392
+ warnForManualTransaction();
291
393
 
292
394
  const start = performance.now();
293
395
  const kvReadsBefore = ctx.metrics?.totalKvReads ?? 0;
@@ -302,7 +404,7 @@ async function executeRaw<TRow extends Record<string, unknown>>(
302
404
  }
303
405
 
304
406
  if (!hasMultipleStatements(query)) {
305
- const { rows, columns } = await db.execute(query);
407
+ const { rows, columns } = await db.execute(query, undefined);
306
408
  return rows.map((row) => rowToObject<TRow>(row, columns));
307
409
  }
308
410
 
package/src/db/mod.ts CHANGED
@@ -2,6 +2,7 @@ export type {
2
2
  AnyDatabaseProvider,
3
3
  DatabaseProvider,
4
4
  DatabaseProviderContext,
5
+ InferDatabaseClient,
5
6
  NativeDatabaseProvider,
6
7
  RawAccess,
7
8
  RawDatabaseClient,
@@ -10,5 +11,6 @@ export type {
10
11
  SqliteNativeMetrics,
11
12
  SqliteProfilingOptions,
12
13
  SqliteQueryResult,
14
+ SqliteTransactionOptions,
13
15
  } from "@/common/database/config";
14
16
  export { db } from "@/common/database/mod";
@@ -1,4 +1,3 @@
1
- import type { ActorDriver } from "@/actor/driver";
2
1
  import type { Client } from "@/client/client";
3
2
  import type { RegistryConfig } from "@/registry/config";
4
3
  import type { DynamicActorLoader } from "./internal";
@@ -10,7 +9,6 @@ export interface DynamicActorIsolateRuntimeConfig {
10
9
  input: unknown;
11
10
  region: string;
12
11
  loader: DynamicActorLoader;
13
- actorDriver: ActorDriver;
14
12
  inlineClient: Client<any>;
15
13
  test: RegistryConfig["test"];
16
14
  }
@@ -6,7 +6,7 @@ export const ActorSchema = z.object({
6
6
  name: z.string(),
7
7
  key: z.string(),
8
8
  namespace_id: RivetIdSchema,
9
- runner_name_selector: z.string(),
9
+ pool: z.string(),
10
10
  create_ts: z.number(),
11
11
  connectable_ts: z.number().nullable().optional(),
12
12
  destroy_ts: z.number().nullable().optional(),
@@ -31,7 +31,7 @@ export type ActorsListResponse = z.infer<typeof ActorsListResponseSchema>;
31
31
  export const ActorsCreateRequestSchema = z.object({
32
32
  datacenter: z.string().optional(),
33
33
  name: z.string(),
34
- runner_name_selector: z.string(),
34
+ pool: z.string(),
35
35
  crash_policy: z.string(),
36
36
  key: z.string().nullable().optional(),
37
37
  input: z.string().nullable().optional(),
@@ -48,7 +48,7 @@ export const ActorsGetOrCreateRequestSchema = z.object({
48
48
  datacenter: z.string().optional(),
49
49
  name: z.string(),
50
50
  key: z.string(),
51
- runner_name_selector: z.string(),
51
+ pool: z.string(),
52
52
  crash_policy: z.string(),
53
53
  input: z.string().nullable().optional(),
54
54
  });