rivetkit 0.0.0-skip-ready-wait-flatten-client-options.1cae221 → 0.0.0-sqlite-uds.ea644f1

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 (254) hide show
  1. package/dist/browser/client.d.ts +561 -89
  2. package/dist/browser/client.js +1063 -430
  3. package/dist/browser/client.js.map +1 -1
  4. package/dist/browser/inspector/client.d.ts +22 -2
  5. package/dist/browser/inspector/client.js +1036 -232
  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 +2232 -2082
  13. package/dist/tsup/agent-os/index.cjs.map +1 -1
  14. package/dist/tsup/agent-os/index.d.cts +556 -85
  15. package/dist/tsup/agent-os/index.d.ts +556 -85
  16. package/dist/tsup/agent-os/index.js +2234 -2084
  17. package/dist/tsup/agent-os/index.js.map +1 -1
  18. package/dist/tsup/{chunk-7MRGNVSR.js → chunk-3GLNEWGY.js} +78 -6
  19. package/dist/tsup/chunk-3GLNEWGY.js.map +1 -0
  20. package/dist/tsup/{chunk-V3QNBJ7N.cjs → chunk-4FC7TVS6.cjs} +35 -10
  21. package/dist/tsup/chunk-4FC7TVS6.cjs.map +1 -0
  22. package/dist/tsup/{chunk-XNZR7UD2.cjs → chunk-7DDQA6KN.cjs} +90 -65
  23. package/dist/tsup/chunk-7DDQA6KN.cjs.map +1 -0
  24. package/dist/tsup/{chunk-NFC5VU36.cjs → chunk-AESHILFV.cjs} +18 -10
  25. package/dist/tsup/chunk-AESHILFV.cjs.map +1 -0
  26. package/dist/tsup/{chunk-D4TSTM6C.js → chunk-EFQCNJ23.js} +83 -58
  27. package/dist/tsup/chunk-EFQCNJ23.js.map +1 -0
  28. package/dist/tsup/{chunk-OIKOPSXQ.js → chunk-FUS4OFX5.js} +12 -4
  29. package/dist/tsup/chunk-FUS4OFX5.js.map +1 -0
  30. package/dist/tsup/{chunk-IOYKCB6Y.cjs → chunk-GUCITCR3.cjs} +44 -9
  31. package/dist/tsup/chunk-GUCITCR3.cjs.map +1 -0
  32. package/dist/tsup/{chunk-3BFYSYRU.js → chunk-HXUEHHJF.js} +3 -2
  33. package/dist/tsup/chunk-HXUEHHJF.js.map +1 -0
  34. package/dist/tsup/{chunk-PCBNKI2J.js → chunk-JZ7TWV65.js} +1 -1
  35. package/dist/tsup/chunk-JZ7TWV65.js.map +1 -0
  36. package/dist/tsup/{chunk-KSG2COSQ.js → chunk-KYBAXJRA.js} +6 -6
  37. package/dist/tsup/chunk-KYBAXJRA.js.map +1 -0
  38. package/dist/tsup/{chunk-LNMB25HW.js → chunk-LMUEIJUM.js} +780 -183
  39. package/dist/tsup/chunk-LMUEIJUM.js.map +1 -0
  40. package/dist/tsup/{chunk-RZEJJJKU.js → chunk-LTMSYD2A.js} +42 -7
  41. package/dist/tsup/chunk-LTMSYD2A.js.map +1 -0
  42. package/dist/tsup/{chunk-AK57AL7S.cjs → chunk-OAPVVVTX.cjs} +79 -7
  43. package/dist/tsup/chunk-OAPVVVTX.cjs.map +1 -0
  44. package/dist/tsup/{chunk-D2TLG75Y.cjs → chunk-TIUL6FNF.cjs} +10 -10
  45. package/dist/tsup/chunk-TIUL6FNF.cjs.map +1 -0
  46. package/dist/tsup/{chunk-POTPHU3P.cjs → chunk-UYT2CIWO.cjs} +3 -3
  47. package/dist/tsup/{chunk-POTPHU3P.cjs.map → chunk-UYT2CIWO.cjs.map} +1 -1
  48. package/dist/tsup/{chunk-TPBHXFB2.cjs → chunk-VDTC257X.cjs} +138 -24
  49. package/dist/tsup/chunk-VDTC257X.cjs.map +1 -0
  50. package/dist/tsup/{chunk-LLD2D5LO.cjs → chunk-VE2X4KMG.cjs} +3 -2
  51. package/dist/tsup/chunk-VE2X4KMG.cjs.map +1 -0
  52. package/dist/tsup/{chunk-22XU3BVY.cjs → chunk-VWOA7DRK.cjs} +925 -328
  53. package/dist/tsup/chunk-VWOA7DRK.cjs.map +1 -0
  54. package/dist/tsup/{chunk-4ZIWB4CQ.js → chunk-VYQASICJ.js} +2 -2
  55. package/dist/tsup/{chunk-W54QCENI.js → chunk-X4BXYDTG.js} +134 -20
  56. package/dist/tsup/chunk-X4BXYDTG.js.map +1 -0
  57. package/dist/tsup/{chunk-2NDZ7JCR.cjs → chunk-ZA7FLHKH.cjs} +1 -1
  58. package/dist/tsup/chunk-ZA7FLHKH.cjs.map +1 -0
  59. package/dist/tsup/{chunk-K34B3OVG.js → chunk-ZZ3WBRPD.js} +34 -9
  60. package/dist/tsup/chunk-ZZ3WBRPD.js.map +1 -0
  61. package/dist/tsup/client/mod.cjs +9 -9
  62. package/dist/tsup/client/mod.cjs.map +1 -1
  63. package/dist/tsup/client/mod.d.cts +8 -9
  64. package/dist/tsup/client/mod.d.ts +8 -9
  65. package/dist/tsup/client/mod.js +8 -8
  66. package/dist/tsup/common/log.cjs +5 -3
  67. package/dist/tsup/common/log.cjs.map +1 -1
  68. package/dist/tsup/common/log.d.cts +5 -1
  69. package/dist/tsup/common/log.d.ts +5 -1
  70. package/dist/tsup/common/log.js +6 -4
  71. package/dist/tsup/common/websocket.cjs +4 -4
  72. package/dist/tsup/common/websocket.js +3 -3
  73. package/dist/tsup/{config-CRdGwwbr.d.cts → config-CxG53eQo.d.cts} +577 -36
  74. package/dist/tsup/{config-kxXbtrJU.d.ts → config-DLOxy81E.d.cts} +5 -5
  75. package/dist/tsup/{config-kxXbtrJU.d.cts → config-DLOxy81E.d.ts} +5 -5
  76. package/dist/tsup/{config-DIpBWm5C.d.ts → config-Ds6DCRhV.d.ts} +577 -36
  77. package/dist/tsup/context-8KlcOYIs.d.cts +129 -0
  78. package/dist/tsup/context-Cfbm4QLr.d.ts +129 -0
  79. package/dist/tsup/db/drizzle.cjs +164 -78
  80. package/dist/tsup/db/drizzle.cjs.map +1 -1
  81. package/dist/tsup/db/drizzle.d.cts +4 -2
  82. package/dist/tsup/db/drizzle.d.ts +4 -2
  83. package/dist/tsup/db/drizzle.js +164 -78
  84. package/dist/tsup/db/drizzle.js.map +1 -1
  85. package/dist/tsup/db/mod.cjs +93 -24
  86. package/dist/tsup/db/mod.cjs.map +1 -1
  87. package/dist/tsup/db/mod.d.cts +2 -2
  88. package/dist/tsup/db/mod.d.ts +2 -2
  89. package/dist/tsup/db/mod.js +92 -23
  90. package/dist/tsup/db/mod.js.map +1 -1
  91. package/dist/tsup/dynamic/mod.cjs +24 -0
  92. package/dist/tsup/dynamic/mod.cjs.map +1 -0
  93. package/dist/tsup/dynamic/mod.d.cts +37 -0
  94. package/dist/tsup/dynamic/mod.d.ts +37 -0
  95. package/dist/tsup/dynamic/mod.js +24 -0
  96. package/dist/tsup/dynamic/mod.js.map +1 -0
  97. package/dist/tsup/inspector/mod.cjs +47 -12
  98. package/dist/tsup/inspector/mod.cjs.map +1 -1
  99. package/dist/tsup/inspector/mod.d.cts +37 -15
  100. package/dist/tsup/inspector/mod.d.ts +37 -15
  101. package/dist/tsup/inspector/mod.js +46 -11
  102. package/dist/tsup/inspector/mod.js.map +1 -1
  103. package/dist/tsup/inspector-tab/mod.cjs +162 -0
  104. package/dist/tsup/inspector-tab/mod.cjs.map +1 -0
  105. package/dist/tsup/inspector-tab/mod.d.cts +240 -0
  106. package/dist/tsup/inspector-tab/mod.d.ts +240 -0
  107. package/dist/tsup/inspector-tab/mod.js +162 -0
  108. package/dist/tsup/inspector-tab/mod.js.map +1 -0
  109. package/dist/tsup/mod.cjs +1078 -479
  110. package/dist/tsup/mod.cjs.map +1 -1
  111. package/dist/tsup/mod.d.cts +5 -6
  112. package/dist/tsup/mod.d.ts +5 -6
  113. package/dist/tsup/mod.js +996 -397
  114. package/dist/tsup/mod.js.map +1 -1
  115. package/dist/tsup/test/mod.cjs +21 -18
  116. package/dist/tsup/test/mod.cjs.map +1 -1
  117. package/dist/tsup/test/mod.d.cts +4 -5
  118. package/dist/tsup/test/mod.d.ts +4 -5
  119. package/dist/tsup/test/mod.js +18 -15
  120. package/dist/tsup/test/mod.js.map +1 -1
  121. package/dist/tsup/utils-CqDnC_PS.d.cts +104 -0
  122. package/dist/tsup/utils-CqDnC_PS.d.ts +104 -0
  123. package/dist/tsup/utils.cjs +3 -3
  124. package/dist/tsup/utils.d.cts +1 -1
  125. package/dist/tsup/utils.d.ts +1 -1
  126. package/dist/tsup/utils.js +2 -2
  127. package/dist/tsup/workflow/mod.cjs +386 -322
  128. package/dist/tsup/workflow/mod.cjs.map +1 -1
  129. package/dist/tsup/workflow/mod.d.cts +8 -9
  130. package/dist/tsup/workflow/mod.d.ts +8 -9
  131. package/dist/tsup/workflow/mod.js +363 -299
  132. package/dist/tsup/workflow/mod.js.map +1 -1
  133. package/package.json +35 -14
  134. package/src/actor/config.ts +188 -59
  135. package/src/actor/contexts/index.ts +7 -2
  136. package/src/actor/definition.ts +17 -19
  137. package/src/actor/driver.ts +3 -3
  138. package/src/actor/errors.ts +70 -7
  139. package/src/actor/instance/mod.ts +39 -56
  140. package/src/actor/keys.ts +2 -1
  141. package/src/actor/mod.ts +22 -20
  142. package/src/actor/schema.ts +2 -2
  143. package/src/agent-os/actor/index.ts +38 -18
  144. package/src/agent-os/actor/preview.ts +1 -2
  145. package/src/agent-os/actor/session.ts +2 -2
  146. package/src/agent-os/config.ts +1 -1
  147. package/src/agent-os/fs/database-vfs.ts +1 -1
  148. package/src/agent-os/index.ts +16 -15
  149. package/src/client/actor-common.ts +88 -62
  150. package/src/client/actor-conn.ts +58 -63
  151. package/src/client/actor-handle.ts +125 -71
  152. package/src/client/actor-query.ts +5 -5
  153. package/src/client/config.ts +3 -3
  154. package/src/client/errors.ts +2 -1
  155. package/src/client/lifecycle-errors.ts +2 -4
  156. package/src/client/query.ts +1 -1
  157. package/src/client/queue.ts +8 -3
  158. package/src/client/raw-utils.ts +10 -10
  159. package/src/client/resolve-gateway-target.ts +1 -1
  160. package/src/client/utils.ts +34 -10
  161. package/src/common/actor-router-consts.ts +7 -4
  162. package/src/common/actor-websocket.ts +3 -1
  163. package/src/common/bare/actor-persist/v1.ts +205 -163
  164. package/src/common/bare/actor-persist/v2.ts +265 -213
  165. package/src/common/bare/actor-persist/v3.ts +176 -172
  166. package/src/common/bare/actor-persist/v4.ts +254 -253
  167. package/src/common/bare/generated/actor-uds-protocol/v1.ts +802 -0
  168. package/src/common/bare/generated/client-protocol/v4.ts +599 -0
  169. package/src/common/bare/generated/inspector/v5.ts +1016 -0
  170. package/src/common/bare/transport/v1.ts +694 -542
  171. package/src/common/client-protocol-versioned.ts +176 -67
  172. package/src/common/client-protocol-zod.ts +7 -0
  173. package/src/common/client-protocol.ts +1 -1
  174. package/src/common/database/config.ts +16 -5
  175. package/src/common/database/mod.test.ts +137 -16
  176. package/src/common/database/mod.ts +100 -30
  177. package/src/common/database/native-database.test.ts +35 -22
  178. package/src/common/database/native-database.ts +26 -10
  179. package/src/common/database/shared.ts +1 -0
  180. package/src/common/encoding.ts +250 -16
  181. package/src/common/engine.ts +28 -1
  182. package/src/common/eventsource.ts +1 -1
  183. package/src/common/inline-websocket-adapter.ts +14 -13
  184. package/src/common/log.ts +15 -8
  185. package/src/common/router.ts +49 -23
  186. package/src/common/utils.ts +10 -202
  187. package/src/common/websocket-interface.ts +1 -1
  188. package/src/db/drizzle.ts +194 -95
  189. package/src/db/mod.ts +1 -1
  190. package/src/devtools-loader/index.ts +4 -7
  191. package/src/devtools-loader/serve-devtools.ts +26 -0
  192. package/src/drivers/engine/actor-driver.ts +76 -73
  193. package/src/dynamic/instance.ts +32 -0
  194. package/src/dynamic/internal.ts +50 -0
  195. package/src/dynamic/isolate-runtime.ts +66 -0
  196. package/src/dynamic/mod.ts +32 -0
  197. package/src/engine-client/actor-http-client.ts +6 -9
  198. package/src/engine-client/actor-websocket-client.ts +14 -13
  199. package/src/engine-client/api-endpoints.ts +51 -2
  200. package/src/engine-client/api-utils.ts +2 -2
  201. package/src/engine-client/driver.ts +3 -4
  202. package/src/engine-client/mod.ts +17 -10
  203. package/src/engine-client/ws-proxy.ts +9 -4
  204. package/src/inspector/client.browser.ts +66 -15
  205. package/src/inspector/mod.ts +2 -4
  206. package/src/inspector-tab/mod.ts +300 -0
  207. package/src/registry/config/envoy.ts +1 -2
  208. package/src/registry/config/index.ts +46 -20
  209. package/src/registry/index.ts +364 -87
  210. package/src/registry/napi-runtime.ts +97 -8
  211. package/src/registry/native-validation.ts +10 -12
  212. package/src/registry/native.ts +592 -343
  213. package/src/registry/process-metrics.ts +250 -0
  214. package/src/registry/runtime.ts +85 -6
  215. package/src/registry/wasm-runtime.ts +72 -3
  216. package/src/registry/write-through-proxy.ts +40 -0
  217. package/src/serde.ts +2 -2
  218. package/src/serverless/configure.ts +19 -8
  219. package/src/test/mod.ts +11 -8
  220. package/src/utils/crypto.ts +14 -0
  221. package/src/utils/endpoint-parser.ts +1 -1
  222. package/src/utils/env-vars.ts +37 -0
  223. package/src/utils/router.ts +1 -1
  224. package/src/utils.ts +1 -2
  225. package/src/workflow/context.ts +703 -240
  226. package/src/workflow/driver.ts +23 -12
  227. package/src/workflow/inspector.ts +12 -3
  228. package/src/workflow/mod.ts +37 -23
  229. package/dist/tsup/chunk-22XU3BVY.cjs.map +0 -1
  230. package/dist/tsup/chunk-2NDZ7JCR.cjs.map +0 -1
  231. package/dist/tsup/chunk-3BFYSYRU.js.map +0 -1
  232. package/dist/tsup/chunk-7MRGNVSR.js.map +0 -1
  233. package/dist/tsup/chunk-AK57AL7S.cjs.map +0 -1
  234. package/dist/tsup/chunk-D2TLG75Y.cjs.map +0 -1
  235. package/dist/tsup/chunk-D4TSTM6C.js.map +0 -1
  236. package/dist/tsup/chunk-IOYKCB6Y.cjs.map +0 -1
  237. package/dist/tsup/chunk-K34B3OVG.js.map +0 -1
  238. package/dist/tsup/chunk-KSG2COSQ.js.map +0 -1
  239. package/dist/tsup/chunk-LLD2D5LO.cjs.map +0 -1
  240. package/dist/tsup/chunk-LNMB25HW.js.map +0 -1
  241. package/dist/tsup/chunk-NFC5VU36.cjs.map +0 -1
  242. package/dist/tsup/chunk-OIKOPSXQ.js.map +0 -1
  243. package/dist/tsup/chunk-PCBNKI2J.js.map +0 -1
  244. package/dist/tsup/chunk-RZEJJJKU.js.map +0 -1
  245. package/dist/tsup/chunk-TPBHXFB2.cjs.map +0 -1
  246. package/dist/tsup/chunk-V3QNBJ7N.cjs.map +0 -1
  247. package/dist/tsup/chunk-W54QCENI.js.map +0 -1
  248. package/dist/tsup/chunk-XNZR7UD2.cjs.map +0 -1
  249. package/dist/tsup/context-B7G6sk7x.d.ts +0 -92
  250. package/dist/tsup/context-DzMRHkjC.d.cts +0 -92
  251. package/dist/tsup/utils-fwx3o3K9.d.cts +0 -18
  252. package/dist/tsup/utils-fwx3o3K9.d.ts +0 -18
  253. package/src/utils/serve.ts +0 -217
  254. /package/dist/tsup/{chunk-4ZIWB4CQ.js.map → chunk-VYQASICJ.js.map} +0 -0
@@ -1,9 +1,7 @@
1
1
  import type { Next } from "hono";
2
2
  import type { ContentfulStatusCode } from "hono/utils/http-status";
3
3
  import * as errors from "@/actor/errors";
4
- import { EXTRA_ERROR_LOG } from "@/utils";
5
4
  import { getLogErrorStack } from "@/utils/env-vars";
6
- import type { Logger } from "./log";
7
5
 
8
6
  export function assertUnreachable(x: never): never {
9
7
  throw new Error(`Unreachable case: ${x}`);
@@ -38,155 +36,6 @@ export function safeStringify(obj: unknown, maxSize: number) {
38
36
  return JSON.stringify(obj, replacer);
39
37
  }
40
38
 
41
- // TODO: Instead of doing this, use a temp var for state and attempt to write
42
- // it. Roll back state if fails to serialize.
43
-
44
- /**
45
- * Check if a value is CBOR serializable.
46
- * Optionally pass an onInvalid callback to receive the path to invalid values.
47
- *
48
- * For a complete list of supported CBOR tags, see:
49
- * https://github.com/kriszyp/cbor-x/blob/cc1cf9df8ba72288c7842af1dd374d73e34cdbc1/README.md#list-of-supported-tags-for-decoding
50
- */
51
- export function isCborSerializable(
52
- value: unknown,
53
- onInvalid?: (path: string) => void,
54
- currentPath = "",
55
- ): boolean {
56
- // Handle primitive types directly
57
- if (value === null || value === undefined) {
58
- return true;
59
- }
60
-
61
- if (typeof value === "number") {
62
- if (!Number.isFinite(value)) {
63
- onInvalid?.(currentPath);
64
- return false;
65
- }
66
- return true;
67
- }
68
-
69
- if (typeof value === "boolean" || typeof value === "string") {
70
- return true;
71
- }
72
-
73
- // Handle BigInt (CBOR tags 2 and 3)
74
- if (typeof value === "bigint") {
75
- return true;
76
- }
77
-
78
- // Handle Date objects (CBOR tags 0 and 1)
79
- if (value instanceof Date) {
80
- return true;
81
- }
82
-
83
- // Handle typed arrays (CBOR tags 64-82)
84
- if (
85
- value instanceof Uint8Array ||
86
- value instanceof Uint8ClampedArray ||
87
- value instanceof Uint16Array ||
88
- value instanceof Uint32Array ||
89
- value instanceof BigUint64Array ||
90
- value instanceof Int8Array ||
91
- value instanceof Int16Array ||
92
- value instanceof Int32Array ||
93
- value instanceof BigInt64Array ||
94
- value instanceof Float32Array ||
95
- value instanceof Float64Array
96
- ) {
97
- return true;
98
- }
99
-
100
- // Handle Map (CBOR tag 259)
101
- if (value instanceof Map) {
102
- for (const [key, val] of value.entries()) {
103
- const keyPath = currentPath
104
- ? `${currentPath}.key(${String(key)})`
105
- : `key(${String(key)})`;
106
- const valPath = currentPath
107
- ? `${currentPath}.value(${String(key)})`
108
- : `value(${String(key)})`;
109
- if (
110
- !isCborSerializable(key, onInvalid, keyPath) ||
111
- !isCborSerializable(val, onInvalid, valPath)
112
- ) {
113
- return false;
114
- }
115
- }
116
- return true;
117
- }
118
-
119
- // Handle Set (CBOR tag 258)
120
- if (value instanceof Set) {
121
- let index = 0;
122
- for (const item of value.values()) {
123
- const itemPath = currentPath
124
- ? `${currentPath}.set[${index}]`
125
- : `set[${index}]`;
126
- if (!isCborSerializable(item, onInvalid, itemPath)) {
127
- return false;
128
- }
129
- index++;
130
- }
131
- return true;
132
- }
133
-
134
- // Handle RegExp (CBOR tag 27)
135
- if (value instanceof RegExp) {
136
- return true;
137
- }
138
-
139
- // Handle Error objects (CBOR tag 27)
140
- if (value instanceof Error) {
141
- return true;
142
- }
143
-
144
- // Handle arrays
145
- if (Array.isArray(value)) {
146
- for (let i = 0; i < value.length; i++) {
147
- const itemPath = currentPath ? `${currentPath}[${i}]` : `[${i}]`;
148
- if (!isCborSerializable(value[i], onInvalid, itemPath)) {
149
- return false;
150
- }
151
- }
152
- return true;
153
- }
154
-
155
- // Handle plain objects and records (CBOR tags 105, 51, 57344-57599)
156
- if (typeof value === "object") {
157
- // Allow plain objects and objects with prototypes (for records and named objects)
158
- const proto = Object.getPrototypeOf(value);
159
- if (proto !== null && proto !== Object.prototype) {
160
- // Check if it's a known serializable object type
161
- const protoConstructor = value.constructor;
162
- if (protoConstructor && typeof protoConstructor.name === "string") {
163
- // Allow objects with named constructors (records, named objects)
164
- // This includes user-defined classes and built-in objects
165
- // that CBOR can serialize with tag 27 or record tags
166
- }
167
- }
168
-
169
- // Check all properties recursively
170
- for (const key in value) {
171
- const propPath = currentPath ? `${currentPath}.${key}` : key;
172
- if (
173
- !isCborSerializable(
174
- value[key as keyof typeof value],
175
- onInvalid,
176
- propPath,
177
- )
178
- ) {
179
- return false;
180
- }
181
- }
182
- return true;
183
- }
184
-
185
- // Not serializable
186
- onInvalid?.(currentPath);
187
- return false;
188
- }
189
-
190
39
  export interface DeconstructedError {
191
40
  __type: "ActorError";
192
41
  statusCode: ContentfulStatusCode;
@@ -195,6 +44,7 @@ export interface DeconstructedError {
195
44
  code: string;
196
45
  message: string;
197
46
  metadata?: unknown;
47
+ actor?: errors.ActorSpecifier;
198
48
  }
199
49
 
200
50
  function isCanonicalStructuredRivetError(
@@ -221,19 +71,16 @@ function isCanonicalStructuredRivetError(
221
71
  */
222
72
  export function deconstructError(
223
73
  error: unknown,
224
- logger: Logger,
225
- extraLog: Record<string, unknown>,
226
74
  exposeInternalError = false,
227
75
  ): DeconstructedError {
228
76
  // Build response error information. Only return errors if flagged as public in order to prevent leaking internal behavior.
229
- //
230
- // We log the error here instead of after generating the code & message because we need to log the original error, not the masked internal error.
231
77
  let statusCode: ContentfulStatusCode;
232
78
  let public_: boolean;
233
79
  let group: string;
234
80
  let code: string;
235
81
  let message: string;
236
82
  let metadata: unknown;
83
+ let actor: errors.ActorSpecifier | undefined;
237
84
  // Structured errors from core or from pre-built `RivetError` instances are canonical.
238
85
  // Only unstructured errors go through the classifier below.
239
86
  if (isCanonicalStructuredRivetError(error)) {
@@ -249,15 +96,7 @@ export function deconstructError(
249
96
  code = error.code;
250
97
  message = error.message;
251
98
  metadata = error.metadata;
252
-
253
- logger.info({
254
- msg: "structured error passthrough",
255
- group,
256
- code,
257
- message,
258
- ...EXTRA_ERROR_LOG,
259
- ...extraLog,
260
- });
99
+ actor = error.actor;
261
100
  } else if (errors.ActorError.isActorError(error) && error.public) {
262
101
  // Check if error has statusCode (could be ActorError instance or DeconstructedError)
263
102
  statusCode = (
@@ -268,15 +107,7 @@ export function deconstructError(
268
107
  code = error.code;
269
108
  message = getErrorMessage(error);
270
109
  metadata = error.metadata;
271
-
272
- logger.info({
273
- msg: "public error",
274
- group,
275
- code,
276
- message,
277
- ...EXTRA_ERROR_LOG,
278
- ...extraLog,
279
- });
110
+ actor = error.actor;
280
111
  } else if (exposeInternalError) {
281
112
  if (errors.ActorError.isActorError(error)) {
282
113
  statusCode = 500;
@@ -285,32 +116,13 @@ export function deconstructError(
285
116
  code = error.code;
286
117
  message = getErrorMessage(error);
287
118
  metadata = error.metadata;
288
-
289
- logger.info({
290
- msg: "internal error",
291
- group,
292
- code,
293
- message,
294
- stack: (error as Error)?.stack,
295
- ...EXTRA_ERROR_LOG,
296
- ...extraLog,
297
- });
119
+ actor = error.actor;
298
120
  } else {
299
121
  statusCode = 500;
300
122
  public_ = false;
301
123
  group = "rivetkit";
302
124
  code = errors.INTERNAL_ERROR_CODE;
303
125
  message = getErrorMessage(error);
304
-
305
- logger.info({
306
- msg: "internal error",
307
- group,
308
- code,
309
- message,
310
- stack: (error as Error)?.stack,
311
- ...EXTRA_ERROR_LOG,
312
- ...extraLog,
313
- });
314
126
  }
315
127
  } else {
316
128
  statusCode = 500;
@@ -318,17 +130,12 @@ export function deconstructError(
318
130
  group = "rivetkit";
319
131
  code = errors.INTERNAL_ERROR_CODE;
320
132
  message = errors.INTERNAL_ERROR_DESCRIPTION;
133
+ if (errors.ActorError.isActorError(error)) {
134
+ actor = error.actor;
135
+ }
321
136
  metadata = {
322
- //url: `https://hub.rivet.dev/projects/${actorMetadata.project.slug}/environments/${actorMetadata.environment.slug}/actors?actorId=${actorMetadata.actor.id}`,
137
+ //url: `https://dashboard.rivet.dev/projects/${actorMetadata.project.slug}/environments/${actorMetadata.environment.slug}/actors?actorId=${actorMetadata.actor.id}`,
323
138
  } satisfies errors.InternalErrorMetadata;
324
-
325
- logger.warn({
326
- msg: "internal error",
327
- error: getErrorMessage(error),
328
- stack: (error as Error)?.stack,
329
- ...EXTRA_ERROR_LOG,
330
- ...extraLog,
331
- });
332
139
  }
333
140
 
334
141
  return {
@@ -339,6 +146,7 @@ export function deconstructError(
339
146
  code,
340
147
  message,
341
148
  metadata,
149
+ actor,
342
150
  };
343
151
  }
344
152
 
@@ -1,7 +1,7 @@
1
1
  // Re-export everything from the virtual-websocket package
2
2
  export type {
3
+ RivetCloseEvent,
3
4
  RivetEvent,
4
5
  RivetMessageEvent,
5
- RivetCloseEvent,
6
6
  UniversalWebSocket,
7
7
  } from "@rivetkit/virtual-websocket";
package/src/db/drizzle.ts CHANGED
@@ -10,7 +10,7 @@ import type {
10
10
  SqliteDatabase,
11
11
  } from "@/common/database/config";
12
12
  import { toSqliteBindings } from "@/common/database/shared";
13
- import { getNodeCrypto } from "@/utils/node";
13
+ import { sha256Hex } from "@/utils/crypto";
14
14
 
15
15
  export type { SQLiteTable } from "drizzle-orm/sqlite-core";
16
16
  export {
@@ -28,8 +28,19 @@ export {
28
28
  } from "drizzle-orm/sqlite-core";
29
29
 
30
30
  type DrizzleSchema = Record<string, unknown>;
31
- type DrizzleDatabase<TSchema extends DrizzleSchema> =
32
- SqliteRemoteDatabase<TSchema> & RawAccess;
31
+ type DrizzleDatabase<TSchema extends DrizzleSchema> = Omit<
32
+ SqliteRemoteDatabase<TSchema>,
33
+ "transaction"
34
+ > &
35
+ Omit<RawAccess, "transaction"> & {
36
+ transaction: <T>(
37
+ callback: (
38
+ tx: DrizzleDatabase<TSchema>,
39
+ ) => Promise<T> | T,
40
+ ) => Promise<T>;
41
+ };
42
+
43
+ const MIGRATION_LEASE_TIMEOUT_MS = 60_000;
33
44
 
34
45
  interface DrizzleMigrationJournalEntry {
35
46
  idx: number;
@@ -90,6 +101,7 @@ export function db<TSchema extends DrizzleSchema = Record<string, never>>({
90
101
 
91
102
  const nativeDb = await nativeDatabaseProvider.open(ctx.actorId);
92
103
  let closed = false;
104
+ let transactionActive = false;
93
105
  const ensureOpen = () => {
94
106
  if (closed) {
95
107
  throw new Error(
@@ -98,108 +110,192 @@ export function db<TSchema extends DrizzleSchema = Record<string, never>>({
98
110
  }
99
111
  };
100
112
 
101
- const runSql = async (
102
- query: string,
103
- params: unknown[],
104
- method: "run" | "all" | "values" | "get",
105
- ) => {
106
- ensureOpen();
113
+ const createDrizzleClient = (lease?: {
114
+ key: string;
115
+ timeoutMs?: number;
116
+ }): DrizzleDatabase<TSchema> => {
117
+ const runSql = async (
118
+ query: string,
119
+ params: unknown[],
120
+ method: "run" | "all" | "values" | "get",
121
+ ) => {
122
+ ensureOpen();
123
+ if (!lease && transactionActive) {
124
+ throw new Error(
125
+ "Use the tx argument inside db.transaction(); the outer database client cannot run work from the transaction callback.",
126
+ );
127
+ }
107
128
 
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(
129
+ const start = performance.now();
130
+ const kvReadsBefore = ctx.metrics?.totalKvReads ?? 0;
131
+ const kvWritesBefore = ctx.metrics?.totalKvWrites ?? 0;
132
+ try {
133
+ const { rows } = await nativeDb.execute(
134
+ query,
135
+ toSqliteBindings(params),
136
+ lease,
137
+ );
138
+ if (method === "run") {
139
+ return { rows: [] };
140
+ }
141
+ if (method === "get") {
142
+ return { rows: rows[0] };
143
+ }
144
+ return { rows };
145
+ } finally {
146
+ const durationMs = performance.now() - start;
147
+ ctx.metrics?.trackSql(query, durationMs);
148
+ if (ctx.metrics) {
149
+ ctx.log?.debug({
150
+ msg: "sql query",
151
+ query: query.slice(0, 120),
152
+ durationMs,
153
+ kvReads:
154
+ ctx.metrics.totalKvReads - kvReadsBefore,
155
+ kvWrites:
156
+ ctx.metrics.totalKvWrites - kvWritesBefore,
157
+ });
158
+ }
159
+ }
160
+ };
161
+
162
+ const callback: RemoteCallback = async (
163
+ query,
164
+ params,
165
+ method,
166
+ ) => {
167
+ return await runSql(query, params, method);
168
+ };
169
+
170
+ const drizzleDb = drizzle(callback, {
171
+ schema,
172
+ }) as unknown as DrizzleDatabase<TSchema>;
173
+ drizzleDb.execute = async <
174
+ TRow extends Record<string, unknown> = Record<
175
+ string,
176
+ unknown
177
+ >,
178
+ >(
179
+ query: string,
180
+ ...args: unknown[]
181
+ ): Promise<TRow[]> => {
182
+ return await executeRaw<TRow>(
183
+ nativeDb,
184
+ ctx,
185
+ ensureOpen,
113
186
  query,
114
- toSqliteBindings(params),
187
+ args,
188
+ lease,
115
189
  );
116
- if (method === "run") {
117
- return { rows: [] };
190
+ };
191
+ drizzleDb.transaction = async <T>(
192
+ transactionCallback: (
193
+ tx: DrizzleDatabase<TSchema>,
194
+ ) => Promise<T> | T,
195
+ ): Promise<T> => {
196
+ if (lease || transactionActive) {
197
+ throw new Error(
198
+ "Nested or concurrent db.transaction() calls are not supported.",
199
+ );
118
200
  }
119
- if (method === "get") {
120
- return { rows: rows[0] };
201
+ const transactionLease = { key: crypto.randomUUID() };
202
+ const tx = createDrizzleClient(transactionLease);
203
+ await nativeDb.execute(
204
+ "BEGIN",
205
+ undefined,
206
+ transactionLease,
207
+ );
208
+ transactionActive = true;
209
+ try {
210
+ const result = await transactionCallback(tx);
211
+ await nativeDb.execute(
212
+ "COMMIT",
213
+ undefined,
214
+ transactionLease,
215
+ );
216
+ return result;
217
+ } catch (error) {
218
+ try {
219
+ await nativeDb.execute(
220
+ "ROLLBACK",
221
+ undefined,
222
+ transactionLease,
223
+ );
224
+ } catch {
225
+ // Preserve the callback or commit error after lease poisoning.
226
+ }
227
+ throw error;
228
+ } finally {
229
+ transactionActive = false;
121
230
  }
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
- });
231
+ };
232
+ drizzleDb.__withSqliteLease = async <T>(
233
+ timeoutMs: number,
234
+ leaseCallback: (leased: RawAccess) => Promise<T> | T,
235
+ ): Promise<T> => {
236
+ const internalLease = {
237
+ key: crypto.randomUUID(),
238
+ timeoutMs,
239
+ };
240
+ return await leaseCallback(
241
+ createDrizzleClient(internalLease),
242
+ );
243
+ };
244
+ drizzleDb.close = async () => {
245
+ if (!closed) {
246
+ closed = true;
247
+ await nativeDb.close();
135
248
  }
136
- }
137
- };
249
+ };
138
250
 
139
- const callback: RemoteCallback = async (query, params, method) => {
140
- return await runSql(query, params, method);
141
- };
142
-
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
- >(
149
- query: string,
150
- ...args: unknown[]
151
- ): Promise<TRow[]> => {
152
- return await executeRaw<TRow>(
153
- nativeDb,
154
- ctx,
155
- ensureOpen,
156
- query,
157
- args,
158
- );
251
+ return drizzleDb;
159
252
  };
160
- drizzleDb.close = async () => {
161
- if (!closed) {
162
- closed = true;
163
- await nativeDb.close();
164
- }
165
- };
166
- (
167
- drizzleDb as DrizzleDatabase<TSchema> & {
168
- __rivetWriteMode: <T>(
169
- callback: () => Promise<T> | T,
170
- ) => Promise<T>;
171
- }
172
- ).__rivetWriteMode = async (callback) =>
173
- await nativeDb.writeMode(async () => await callback());
174
253
 
175
- return drizzleDb;
254
+ return createDrizzleClient();
176
255
  },
177
256
  onMigrate: async (client) => {
178
- await dbWriteMode(client, async () => {
257
+ if (!migrations && !onMigrate) {
258
+ return;
259
+ }
260
+ await withMigrationSavepoint(client, async (leased) => {
179
261
  if (migrations) {
180
- await runMigrations(client, migrations);
262
+ await runMigrations(leased, migrations);
181
263
  }
182
264
  if (onMigrate) {
183
- await onMigrate(client);
265
+ await onMigrate(leased);
184
266
  }
185
267
  });
186
268
  },
187
269
  };
188
270
  }
189
271
 
190
- async function dbWriteMode<T>(
191
- client: RawAccess,
192
- callback: () => Promise<T> | T,
272
+ async function withMigrationSavepoint<TSchema extends DrizzleSchema, T>(
273
+ client: DrizzleDatabase<TSchema>,
274
+ callback: (leased: DrizzleDatabase<TSchema>) => Promise<T> | T,
193
275
  ): Promise<T> {
194
- const maybeClient = client as RawAccess & {
195
- __rivetWriteMode?: <TInner>(
196
- callback: () => Promise<TInner> | TInner,
197
- ) => Promise<TInner>;
198
- };
199
- if (maybeClient.__rivetWriteMode) {
200
- return await maybeClient.__rivetWriteMode(callback);
201
- }
202
- return await callback();
276
+ return await client.__withSqliteLease(
277
+ MIGRATION_LEASE_TIMEOUT_MS,
278
+ async (leasedAccess) => {
279
+ const leased = leasedAccess as DrizzleDatabase<TSchema>;
280
+ await leased.execute("SAVEPOINT __rivet_on_migrate");
281
+ try {
282
+ const result = await callback(leased);
283
+ await leased.execute("RELEASE SAVEPOINT __rivet_on_migrate");
284
+ return result;
285
+ } catch (error) {
286
+ try {
287
+ await leased.execute(
288
+ "ROLLBACK TO SAVEPOINT __rivet_on_migrate",
289
+ );
290
+ } finally {
291
+ await leased.execute(
292
+ "RELEASE SAVEPOINT __rivet_on_migrate",
293
+ );
294
+ }
295
+ throw error;
296
+ }
297
+ },
298
+ );
203
299
  }
204
300
 
205
301
  async function runMigrations<TSchema extends DrizzleSchema>(
@@ -244,10 +340,7 @@ async function runMigrations<TSchema extends DrizzleSchema>(
244
340
 
245
341
  await db.execute(
246
342
  "INSERT INTO __drizzle_migrations (hash, created_at) VALUES (?, ?)",
247
- getNodeCrypto()
248
- .createHash("sha256")
249
- .update(migration)
250
- .digest("hex"),
343
+ await sha256Hex(migration),
251
344
  entry.when,
252
345
  );
253
346
  }
@@ -290,6 +383,7 @@ async function executeRaw<TRow extends Record<string, unknown>>(
290
383
  ensureOpen: () => void,
291
384
  query: string,
292
385
  args: unknown[],
386
+ lease?: { key: string; timeoutMs?: number },
293
387
  ): Promise<TRow[]> {
294
388
  ensureOpen();
295
389
 
@@ -301,23 +395,28 @@ async function executeRaw<TRow extends Record<string, unknown>>(
301
395
  const { rows, columns } = await db.execute(
302
396
  query,
303
397
  toSqliteBindings(args),
398
+ lease,
304
399
  );
305
400
  return rows.map((row) => rowToObject<TRow>(row, columns));
306
401
  }
307
402
 
308
403
  if (!hasMultipleStatements(query)) {
309
- const { rows, columns } = await db.execute(query);
404
+ const { rows, columns } = await db.execute(query, undefined, lease);
310
405
  return rows.map((row) => rowToObject<TRow>(row, columns));
311
406
  }
312
407
 
313
408
  const results: Record<string, unknown>[] = [];
314
409
  let columnNames: string[] | null = null;
315
- await db.exec(query, (row, columns) => {
316
- if (!columnNames) {
317
- columnNames = columns;
318
- }
319
- results.push(rowToObject(row, columnNames));
320
- });
410
+ await db.exec(
411
+ query,
412
+ (row, columns) => {
413
+ if (!columnNames) {
414
+ columnNames = columns;
415
+ }
416
+ results.push(rowToObject(row, columnNames));
417
+ },
418
+ lease,
419
+ );
321
420
  return results as TRow[];
322
421
  } finally {
323
422
  const durationMs = performance.now() - start;
package/src/db/mod.ts CHANGED
@@ -1,4 +1,3 @@
1
- export { db } from "@/common/database/mod";
2
1
  export type {
3
2
  AnyDatabaseProvider,
4
3
  DatabaseProvider,
@@ -11,3 +10,4 @@ export type {
11
10
  SqliteNativeMetrics,
12
11
  SqliteQueryResult,
13
12
  } from "@/common/database/config";
13
+ export { db } from "@/common/database/mod";
@@ -1,16 +1,11 @@
1
1
  import type { ClientConfigInput } from "@/client/client";
2
- import { VERSION } from "@/utils";
3
2
  import { logger } from "./log";
4
3
 
5
4
  declare global {
6
5
  // Injected via tsup config
7
- // biome-ignore lint/style/noVar: required for global declaration
8
6
  var CUSTOM_RIVETKIT_DEVTOOLS_URL: string | undefined;
9
7
  }
10
8
 
11
- const DEFAULT_DEVTOOLS_URL = (version = VERSION) =>
12
- `https://releases.rivet.dev/rivet/latest/devtools/mod.js?v=${version}`;
13
-
14
9
  const scriptId = "rivetkit-devtools-script";
15
10
 
16
11
  export function injectDevtools(config: ClientConfigInput) {
@@ -20,10 +15,12 @@ export function injectDevtools(config: ClientConfigInput) {
20
15
  }
21
16
 
22
17
  if (!document.getElementById(scriptId)) {
18
+ const src =
19
+ globalThis.CUSTOM_RIVETKIT_DEVTOOLS_URL ||
20
+ `${config.endpoint?.replace(/\/$/, "")}/devtools/mod.js`;
23
21
  const script = document.createElement("script");
24
22
  script.id = scriptId;
25
- script.src =
26
- globalThis.CUSTOM_RIVETKIT_DEVTOOLS_URL || DEFAULT_DEVTOOLS_URL();
23
+ script.src = src;
27
24
  script.async = true;
28
25
  document.head.appendChild(script);
29
26
  }