rivetkit 0.0.0-main.41efcce → 0.0.0-main.49693dc

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (299) hide show
  1. package/dist/browser/client.d.ts +939 -104
  2. package/dist/browser/client.js +1867 -900
  3. package/dist/browser/client.js.map +1 -1
  4. package/dist/browser/inspector/client.d.ts +252 -129
  5. package/dist/browser/inspector/client.js +2079 -233
  6. package/dist/browser/inspector/client.js.map +1 -1
  7. package/dist/tsup/actor/errors.cjs +6 -2
  8. package/dist/tsup/actor/errors.cjs.map +1 -1
  9. package/dist/tsup/actor/errors.d.cts +1 -74
  10. package/dist/tsup/actor/errors.d.ts +1 -74
  11. package/dist/tsup/actor/errors.js +5 -1
  12. package/dist/tsup/agent-os/index.cjs +2408 -2029
  13. package/dist/tsup/agent-os/index.cjs.map +1 -1
  14. package/dist/tsup/agent-os/index.d.cts +932 -114
  15. package/dist/tsup/agent-os/index.d.ts +932 -114
  16. package/dist/tsup/agent-os/index.js +2412 -2033
  17. package/dist/tsup/agent-os/index.js.map +1 -1
  18. package/dist/tsup/{chunk-J27CEW6F.js → chunk-2OBVQZX6.js} +6 -6
  19. package/dist/tsup/chunk-2OBVQZX6.js.map +1 -0
  20. package/dist/tsup/chunk-3ZWHWMFJ.js +14 -0
  21. package/dist/tsup/chunk-3ZWHWMFJ.js.map +1 -0
  22. package/dist/tsup/{chunk-AK57AL7S.cjs → chunk-4KGXFC6M.cjs} +238 -22
  23. package/dist/tsup/chunk-4KGXFC6M.cjs.map +1 -0
  24. package/dist/tsup/{chunk-CVHUXINE.js → chunk-5IU3MI7X.js} +594 -72
  25. package/dist/tsup/chunk-5IU3MI7X.js.map +1 -0
  26. package/dist/tsup/{chunk-VD7AZIBR.js → chunk-6CXQMHZR.js} +1161 -361
  27. package/dist/tsup/chunk-6CXQMHZR.js.map +1 -0
  28. package/dist/tsup/{chunk-SBEFJ4IQ.js → chunk-6W2UIH3X.js} +70 -8
  29. package/dist/tsup/chunk-6W2UIH3X.js.map +1 -0
  30. package/dist/tsup/{chunk-7MRGNVSR.js → chunk-6W5VGLFT.js} +237 -21
  31. package/dist/tsup/chunk-6W5VGLFT.js.map +1 -0
  32. package/dist/tsup/{chunk-RF3MEJV6.cjs → chunk-B73TBMMG.cjs} +18 -11
  33. package/dist/tsup/chunk-B73TBMMG.cjs.map +1 -0
  34. package/dist/tsup/chunk-D6TORRA4.js +243 -0
  35. package/dist/tsup/chunk-D6TORRA4.js.map +1 -0
  36. package/dist/tsup/{chunk-PXLJOMJD.js → chunk-FXT3HN32.js} +2 -2
  37. package/dist/tsup/{chunk-ZGWSH7YV.js → chunk-IXBD7BXC.js} +48 -72
  38. package/dist/tsup/chunk-IXBD7BXC.js.map +1 -0
  39. package/dist/tsup/{chunk-3BFYSYRU.js → chunk-JI6GZ2C2.js} +4 -12
  40. package/dist/tsup/chunk-JI6GZ2C2.js.map +1 -0
  41. package/dist/tsup/{chunk-PCBNKI2J.js → chunk-JTHHCZCZ.js} +24 -1
  42. package/dist/tsup/chunk-JTHHCZCZ.js.map +1 -0
  43. package/dist/tsup/{chunk-2NDZ7JCR.cjs → chunk-KVFIONKQ.cjs} +25 -2
  44. package/dist/tsup/chunk-KVFIONKQ.cjs.map +1 -0
  45. package/dist/tsup/{chunk-SPMMF6TR.cjs → chunk-LGOWPZJ5.cjs} +3 -3
  46. package/dist/tsup/chunk-LGOWPZJ5.cjs.map +1 -0
  47. package/dist/tsup/chunk-LYNWTX6R.cjs +14 -0
  48. package/dist/tsup/chunk-LYNWTX6R.cjs.map +1 -0
  49. package/dist/tsup/{chunk-LLD2D5LO.cjs → chunk-MYWZCDML.cjs} +4 -12
  50. package/dist/tsup/chunk-MYWZCDML.cjs.map +1 -0
  51. package/dist/tsup/{chunk-XSC2WWXD.js → chunk-NYDZLWHZ.js} +16 -9
  52. package/dist/tsup/chunk-NYDZLWHZ.js.map +1 -0
  53. package/dist/tsup/{chunk-AV54CVAG.cjs → chunk-RB7WUDX6.cjs} +1290 -490
  54. package/dist/tsup/chunk-RB7WUDX6.cjs.map +1 -0
  55. package/dist/tsup/{chunk-JTL6Y2UN.cjs → chunk-SPJORZMM.cjs} +49 -73
  56. package/dist/tsup/chunk-SPJORZMM.cjs.map +1 -0
  57. package/dist/tsup/chunk-SSMKIYEX.cjs +243 -0
  58. package/dist/tsup/chunk-SSMKIYEX.cjs.map +1 -0
  59. package/dist/tsup/{chunk-TQSL4NJ3.cjs → chunk-TQ4HSX2U.cjs} +72 -10
  60. package/dist/tsup/chunk-TQ4HSX2U.cjs.map +1 -0
  61. package/dist/tsup/{chunk-EVADNK6Z.cjs → chunk-U6ZQELGJ.cjs} +10 -10
  62. package/dist/tsup/chunk-U6ZQELGJ.cjs.map +1 -0
  63. package/dist/tsup/chunk-XLBMKZD3.cjs +1257 -0
  64. package/dist/tsup/chunk-XLBMKZD3.cjs.map +1 -0
  65. package/dist/tsup/client/mod.cjs +8 -9
  66. package/dist/tsup/client/mod.cjs.map +1 -1
  67. package/dist/tsup/client/mod.d.cts +18 -7
  68. package/dist/tsup/client/mod.d.ts +18 -7
  69. package/dist/tsup/client/mod.js +7 -8
  70. package/dist/tsup/common/log.cjs +5 -3
  71. package/dist/tsup/common/log.cjs.map +1 -1
  72. package/dist/tsup/common/log.d.cts +5 -1
  73. package/dist/tsup/common/log.d.ts +5 -1
  74. package/dist/tsup/common/log.js +6 -4
  75. package/dist/tsup/common/websocket.cjs +4 -4
  76. package/dist/tsup/common/websocket.cjs.map +1 -1
  77. package/dist/tsup/common/websocket.js +3 -3
  78. package/dist/tsup/{config-B3RIidaJ.d.ts → config-BXSV17G7.d.cts} +987 -72
  79. package/dist/tsup/{config-D6WxBYjV.d.cts → config-Bi1r6gI7.d.ts} +987 -72
  80. package/dist/tsup/{config-B9qUIHX4.d.ts → config-ey2I2zz5.d.cts} +82 -15
  81. package/dist/tsup/{config-B9qUIHX4.d.cts → config-ey2I2zz5.d.ts} +82 -15
  82. package/dist/tsup/context-4fJemY0D.d.cts +129 -0
  83. package/dist/tsup/context-D4sNYboo.d.ts +129 -0
  84. package/dist/tsup/db/drizzle.cjs +168 -103
  85. package/dist/tsup/db/drizzle.cjs.map +1 -1
  86. package/dist/tsup/db/drizzle.d.cts +8 -4
  87. package/dist/tsup/db/drizzle.d.ts +8 -4
  88. package/dist/tsup/db/drizzle.js +170 -105
  89. package/dist/tsup/db/drizzle.js.map +1 -1
  90. package/dist/tsup/db/mod.cjs +6 -163
  91. package/dist/tsup/db/mod.cjs.map +1 -1
  92. package/dist/tsup/db/mod.d.cts +12 -4
  93. package/dist/tsup/db/mod.d.ts +12 -4
  94. package/dist/tsup/db/mod.js +5 -162
  95. package/dist/tsup/db/mod.js.map +1 -1
  96. package/dist/tsup/dynamic/mod.cjs +24 -0
  97. package/dist/tsup/dynamic/mod.cjs.map +1 -0
  98. package/dist/tsup/dynamic/mod.d.cts +38 -0
  99. package/dist/tsup/dynamic/mod.d.ts +38 -0
  100. package/dist/tsup/dynamic/mod.js +24 -0
  101. package/dist/tsup/dynamic/mod.js.map +1 -0
  102. package/dist/tsup/inspector/mod.cjs +47 -12
  103. package/dist/tsup/inspector/mod.cjs.map +1 -1
  104. package/dist/tsup/inspector/mod.d.cts +26 -136
  105. package/dist/tsup/inspector/mod.d.ts +26 -136
  106. package/dist/tsup/inspector/mod.js +46 -11
  107. package/dist/tsup/inspector/mod.js.map +1 -1
  108. package/dist/tsup/inspector/workflow.cjs +21 -0
  109. package/dist/tsup/inspector/workflow.cjs.map +1 -0
  110. package/dist/tsup/inspector/workflow.d.cts +144 -0
  111. package/dist/tsup/inspector/workflow.d.ts +144 -0
  112. package/dist/tsup/inspector/workflow.js +21 -0
  113. package/dist/tsup/inspector/workflow.js.map +1 -0
  114. package/dist/tsup/inspector-tab/mod.cjs +162 -0
  115. package/dist/tsup/inspector-tab/mod.cjs.map +1 -0
  116. package/dist/tsup/inspector-tab/mod.d.cts +241 -0
  117. package/dist/tsup/inspector-tab/mod.d.ts +241 -0
  118. package/dist/tsup/inspector-tab/mod.js +162 -0
  119. package/dist/tsup/inspector-tab/mod.js.map +1 -0
  120. package/dist/tsup/mod.cjs +4268 -944
  121. package/dist/tsup/mod.cjs.map +1 -1
  122. package/dist/tsup/mod.d.cts +9 -8
  123. package/dist/tsup/mod.d.ts +9 -8
  124. package/dist/tsup/mod.js +4229 -905
  125. package/dist/tsup/mod.js.map +1 -1
  126. package/dist/tsup/test/mod.cjs +26 -21
  127. package/dist/tsup/test/mod.cjs.map +1 -1
  128. package/dist/tsup/test/mod.d.cts +7 -6
  129. package/dist/tsup/test/mod.d.ts +7 -6
  130. package/dist/tsup/test/mod.js +25 -20
  131. package/dist/tsup/test/mod.js.map +1 -1
  132. package/dist/tsup/unstable/migrations.cjs +101 -0
  133. package/dist/tsup/unstable/migrations.cjs.map +1 -0
  134. package/dist/tsup/unstable/migrations.d.cts +29 -0
  135. package/dist/tsup/unstable/migrations.d.ts +29 -0
  136. package/dist/tsup/unstable/migrations.js +101 -0
  137. package/dist/tsup/unstable/migrations.js.map +1 -0
  138. package/dist/tsup/utils-Bbz-3411.d.cts +162 -0
  139. package/dist/tsup/utils-BqdWVlzm.d.ts +162 -0
  140. package/dist/tsup/utils-vvJQyygr.d.cts +109 -0
  141. package/dist/tsup/utils-vvJQyygr.d.ts +109 -0
  142. package/dist/tsup/utils.cjs +7 -3
  143. package/dist/tsup/utils.cjs.map +1 -1
  144. package/dist/tsup/utils.d.cts +4 -147
  145. package/dist/tsup/utils.d.ts +4 -147
  146. package/dist/tsup/utils.js +6 -2
  147. package/dist/tsup/workflow/mod.cjs +517 -412
  148. package/dist/tsup/workflow/mod.cjs.map +1 -1
  149. package/dist/tsup/workflow/mod.d.cts +11 -10
  150. package/dist/tsup/workflow/mod.d.ts +11 -10
  151. package/dist/tsup/workflow/mod.js +511 -406
  152. package/dist/tsup/workflow/mod.js.map +1 -1
  153. package/package.json +62 -14
  154. package/src/actor/actions.ts +119 -0
  155. package/src/actor/config.test.ts +78 -0
  156. package/src/actor/config.ts +518 -96
  157. package/src/actor/contexts/index.ts +7 -2
  158. package/src/actor/definition.ts +38 -26
  159. package/src/actor/errors.ts +101 -89
  160. package/src/actor/keys.ts +2 -1
  161. package/src/actor/mod.ts +32 -21
  162. package/src/actor/schema.ts +2 -2
  163. package/src/agent-os/actor/cron.ts +37 -2
  164. package/src/agent-os/actor/index.ts +39 -19
  165. package/src/agent-os/actor/preview.ts +1 -2
  166. package/src/agent-os/actor/session.ts +2 -2
  167. package/src/agent-os/config.ts +1 -1
  168. package/src/agent-os/fs/database-vfs.ts +1 -1
  169. package/src/agent-os/index.ts +16 -15
  170. package/src/agent-os/types.ts +11 -0
  171. package/src/client/actor-common.ts +106 -53
  172. package/src/client/actor-conn.ts +94 -45
  173. package/src/client/actor-handle.ts +198 -79
  174. package/src/client/actor-query.ts +13 -6
  175. package/src/client/client.ts +43 -15
  176. package/src/client/config.ts +8 -0
  177. package/src/client/errors.ts +4 -2
  178. package/src/client/lifecycle-errors.ts +28 -4
  179. package/src/client/mod.ts +9 -4
  180. package/src/client/query.ts +3 -1
  181. package/src/client/queue.ts +8 -3
  182. package/src/client/raw-utils.ts +24 -16
  183. package/src/client/resolve-gateway-target.ts +3 -1
  184. package/src/client/utils.ts +36 -10
  185. package/src/common/actor-router-consts.ts +7 -0
  186. package/src/common/actor-websocket.ts +3 -1
  187. package/src/common/bare/actor-persist/v1.ts +205 -163
  188. package/src/common/bare/actor-persist/v2.ts +265 -213
  189. package/src/common/bare/actor-persist/v3.ts +176 -172
  190. package/src/common/bare/actor-persist/v4.ts +254 -253
  191. package/src/common/bare/generated/actor-runtime-socket-protocol/v1.ts +848 -0
  192. package/src/common/bare/generated/client-protocol/v4.ts +599 -0
  193. package/src/common/bare/generated/inspector/v5.ts +1016 -0
  194. package/src/common/bare/generated/inspector/v6.ts +1367 -0
  195. package/src/common/bare/transport/v1.ts +694 -542
  196. package/src/common/client-protocol-versioned.ts +176 -67
  197. package/src/common/client-protocol-zod.ts +7 -0
  198. package/src/common/client-protocol.ts +1 -1
  199. package/src/common/database/config.ts +103 -10
  200. package/src/common/database/mod.test.ts +364 -0
  201. package/src/common/database/mod.ts +278 -149
  202. package/src/common/database/native-database.test.ts +220 -0
  203. package/src/common/database/native-database.ts +394 -58
  204. package/src/common/database/shared.ts +25 -0
  205. package/src/common/encoding.ts +302 -38
  206. package/src/common/engine.ts +28 -1
  207. package/src/common/eventsource.ts +1 -1
  208. package/src/common/fetch-like.ts +49 -0
  209. package/src/common/inline-websocket-adapter.ts +14 -13
  210. package/src/common/inspector-transport.ts +12 -2
  211. package/src/common/log.ts +117 -14
  212. package/src/common/router.ts +49 -23
  213. package/src/common/utils.ts +23 -203
  214. package/src/common/websocket-interface.ts +1 -1
  215. package/src/db/drizzle.test.ts +164 -0
  216. package/src/db/drizzle.ts +207 -121
  217. package/src/db/mod.ts +6 -1
  218. package/src/devtools-loader/index.ts +4 -7
  219. package/src/devtools-loader/serve-devtools.ts +26 -0
  220. package/src/dynamic/instance.ts +32 -0
  221. package/src/dynamic/internal.ts +50 -0
  222. package/src/dynamic/isolate-runtime.ts +64 -0
  223. package/src/dynamic/mod.ts +32 -0
  224. package/src/engine-client/actor-http-client.ts +23 -4
  225. package/src/engine-client/actor-websocket-client.ts +32 -5
  226. package/src/engine-client/api-endpoints.ts +52 -2
  227. package/src/engine-client/api-utils.ts +2 -2
  228. package/src/engine-client/driver.ts +21 -17
  229. package/src/engine-client/mod.ts +116 -64
  230. package/src/engine-client/ws-proxy.ts +9 -4
  231. package/src/globals.d.ts +4 -0
  232. package/src/inspector/client.browser.ts +127 -15
  233. package/src/inspector/mod.ts +2 -4
  234. package/src/inspector/workflow.ts +61 -0
  235. package/src/inspector-tab/mod.ts +301 -0
  236. package/src/registry/config/envoy.ts +1 -2
  237. package/src/registry/config/index.ts +160 -53
  238. package/src/registry/config/serverless.ts +7 -1
  239. package/src/registry/index.ts +659 -96
  240. package/src/registry/napi-runtime.ts +1154 -0
  241. package/src/registry/native-validation.ts +10 -12
  242. package/src/registry/native.ts +2005 -955
  243. package/src/registry/process-metrics.ts +250 -0
  244. package/src/registry/run-handler-coordinator.test.ts +252 -0
  245. package/src/registry/run-handler-coordinator.ts +219 -0
  246. package/src/registry/runtime.test.ts +50 -0
  247. package/src/registry/runtime.ts +839 -0
  248. package/src/registry/wasm-runtime.ts +1283 -0
  249. package/src/registry/write-through-proxy.ts +141 -0
  250. package/src/serde.ts +8 -2
  251. package/src/serverless/configure.ts +102 -49
  252. package/src/test/mod.ts +2 -17
  253. package/src/test/ready.ts +22 -0
  254. package/src/unstable/migrations.test.ts +170 -0
  255. package/src/unstable/migrations.ts +141 -0
  256. package/src/utils/crypto.ts +14 -0
  257. package/src/utils/endpoint-parser.ts +1 -1
  258. package/src/utils/env-vars.ts +39 -0
  259. package/src/utils/node.ts +44 -28
  260. package/src/utils/router.ts +1 -1
  261. package/src/utils.ts +4 -2
  262. package/src/workflow/context.ts +683 -242
  263. package/src/workflow/driver.test.ts +62 -0
  264. package/src/workflow/driver.ts +246 -119
  265. package/src/workflow/inspector.ts +24 -24
  266. package/src/workflow/mod.ts +76 -84
  267. package/dist/tsup/chunk-2NDZ7JCR.cjs.map +0 -1
  268. package/dist/tsup/chunk-3BFYSYRU.js.map +0 -1
  269. package/dist/tsup/chunk-6AVUJ52Q.cjs +0 -253
  270. package/dist/tsup/chunk-6AVUJ52Q.cjs.map +0 -1
  271. package/dist/tsup/chunk-7MRGNVSR.js.map +0 -1
  272. package/dist/tsup/chunk-7X7RVTFF.cjs +0 -735
  273. package/dist/tsup/chunk-7X7RVTFF.cjs.map +0 -1
  274. package/dist/tsup/chunk-AK57AL7S.cjs.map +0 -1
  275. package/dist/tsup/chunk-AV54CVAG.cjs.map +0 -1
  276. package/dist/tsup/chunk-CVHUXINE.js.map +0 -1
  277. package/dist/tsup/chunk-EVADNK6Z.cjs.map +0 -1
  278. package/dist/tsup/chunk-J27CEW6F.js.map +0 -1
  279. package/dist/tsup/chunk-JTL6Y2UN.cjs.map +0 -1
  280. package/dist/tsup/chunk-LLD2D5LO.cjs.map +0 -1
  281. package/dist/tsup/chunk-PCBNKI2J.js.map +0 -1
  282. package/dist/tsup/chunk-RF3MEJV6.cjs.map +0 -1
  283. package/dist/tsup/chunk-SB4MXRN2.js +0 -253
  284. package/dist/tsup/chunk-SB4MXRN2.js.map +0 -1
  285. package/dist/tsup/chunk-SBEFJ4IQ.js.map +0 -1
  286. package/dist/tsup/chunk-SPMMF6TR.cjs.map +0 -1
  287. package/dist/tsup/chunk-TQSL4NJ3.cjs.map +0 -1
  288. package/dist/tsup/chunk-VD7AZIBR.js.map +0 -1
  289. package/dist/tsup/chunk-XSC2WWXD.js.map +0 -1
  290. package/dist/tsup/chunk-ZGWSH7YV.js.map +0 -1
  291. package/dist/tsup/context-BxvHh9wi.d.cts +0 -92
  292. package/dist/tsup/context-CNIZBIKl.d.ts +0 -92
  293. package/dist/tsup/utils-fwx3o3K9.d.cts +0 -18
  294. package/dist/tsup/utils-fwx3o3K9.d.ts +0 -18
  295. package/src/actor/driver.ts +0 -141
  296. package/src/actor/instance/mod.ts +0 -2501
  297. package/src/drivers/engine/actor-driver.ts +0 -2470
  298. package/src/utils/serve.ts +0 -217
  299. /package/dist/tsup/{chunk-PXLJOMJD.js.map → chunk-FXT3HN32.js.map} +0 -0
package/src/common/log.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import {
2
+ type DestinationStream,
2
3
  type LevelWithSilent,
3
4
  type Logger,
4
5
  pino,
@@ -60,6 +61,29 @@ export function configureBaseLogger(logger: Logger): void {
60
61
  loggerCache.clear();
61
62
  }
62
63
 
64
+ /**
65
+ * Create the default logger with optional log level.
66
+ */
67
+ export function makeDefaultLogger(logLevel?: LogLevel): Logger {
68
+ return pino(
69
+ {
70
+ level: getPinoLevel(logLevel),
71
+ messageKey: "msg",
72
+ // Do not include pid/hostname in output
73
+ base: {},
74
+ errorKey: "error",
75
+ // Keep the numeric level so the logfmt sink can match Pino's levels.
76
+ formatters: {
77
+ level(_label: string, number: number) {
78
+ return { level: number };
79
+ },
80
+ },
81
+ timestamp: getLogTimestamp() ? stdTimeFunctions.epochTime : false,
82
+ },
83
+ createLogfmtDestination(),
84
+ );
85
+ }
86
+
63
87
  /**
64
88
  * Configure the default logger with optional log level.
65
89
  */
@@ -69,20 +93,7 @@ export function configureDefaultLogger(logLevel?: LogLevel) {
69
93
  configuredLogLevel = logLevel;
70
94
  }
71
95
 
72
- baseLogger = pino({
73
- level: getPinoLevel(logLevel),
74
- messageKey: "msg",
75
- // Do not include pid/hostname in output
76
- base: {},
77
- // Keep a string level in the output
78
- formatters: {
79
- level(_label: string, number: number) {
80
- return { level: number };
81
- },
82
- },
83
- timestamp: getLogTimestamp() ? stdTimeFunctions.epochTime : false,
84
- });
85
-
96
+ baseLogger = makeDefaultLogger(logLevel);
86
97
  loggerCache.clear();
87
98
  }
88
99
 
@@ -117,3 +128,95 @@ export function getLogger(name = "default"): Logger {
117
128
 
118
129
  return child;
119
130
  }
131
+
132
+ const PINO_LEVEL_LABELS: Record<number, string> = {
133
+ 10: "trace",
134
+ 20: "debug",
135
+ 30: "info",
136
+ 40: "warn",
137
+ 50: "error",
138
+ 60: "fatal",
139
+ };
140
+
141
+ function createLogfmtDestination(): DestinationStream {
142
+ return {
143
+ write(msg: string): void {
144
+ const line = formatLogfmtLine(msg);
145
+ if (typeof process !== "undefined" && process.stdout?.write) {
146
+ process.stdout.write(`${line}\n`);
147
+ } else {
148
+ console.log(line);
149
+ }
150
+ },
151
+ };
152
+ }
153
+
154
+ function formatLogfmtLine(raw: string): string {
155
+ let data: Record<string, unknown>;
156
+ try {
157
+ data = JSON.parse(raw);
158
+ } catch {
159
+ return raw.trimEnd();
160
+ }
161
+
162
+ const parts: string[] = [];
163
+ appendLogfmtEntry(parts, "level", formatPinoLevel(data.level));
164
+
165
+ if (data.time !== undefined) {
166
+ appendLogfmtEntry(parts, "ts", data.time);
167
+ }
168
+
169
+ for (const [key, value] of Object.entries(data)) {
170
+ if (key === "level" || key === "time") {
171
+ continue;
172
+ }
173
+ appendLogfmtEntry(parts, key, value);
174
+ }
175
+
176
+ return parts.join(" ");
177
+ }
178
+
179
+ function formatPinoLevel(level: unknown): string {
180
+ if (typeof level === "number") {
181
+ return PINO_LEVEL_LABELS[level] ?? level.toString();
182
+ }
183
+
184
+ if (typeof level === "string") {
185
+ return level.toLowerCase();
186
+ }
187
+
188
+ return "info";
189
+ }
190
+
191
+ function appendLogfmtEntry(parts: string[], key: string, value: unknown): void {
192
+ const safeKey = key.replace(/[\s="]/g, "");
193
+ if (safeKey.length === 0) {
194
+ return;
195
+ }
196
+
197
+ parts.push(`${safeKey}=${formatLogfmtValue(value)}`);
198
+ }
199
+
200
+ function formatLogfmtValue(value: unknown): string {
201
+ if (typeof value === "number" || typeof value === "boolean") {
202
+ return String(value);
203
+ }
204
+
205
+ if (value === null || value === undefined) {
206
+ return "null";
207
+ }
208
+
209
+ if (typeof value === "string") {
210
+ return quoteLogfmtString(value);
211
+ }
212
+
213
+ return quoteLogfmtString(JSON.stringify(value));
214
+ }
215
+
216
+ function quoteLogfmtString(value: string): string {
217
+ if (!/[\s="]/.test(value)) {
218
+ return value;
219
+ }
220
+
221
+ return `"${value.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "\\n")}"`;
222
+ }
@@ -1,11 +1,11 @@
1
- import type { Context as HonoContext, Next } from "hono";
2
1
  import * as envoyProtocol from "@rivetkit/engine-envoy-protocol";
3
- import type { Encoding } from "@/common/encoding";
2
+ import type { Context as HonoContext, Next } from "hono";
3
+ import type { ActorSpecifier } from "@/actor/errors";
4
4
  import {
5
- getRequestEncoding,
6
- getRequestExposeInternalError,
7
- } from "@/common/router-request";
8
- import { buildActorNames, type RegistryConfig } from "@/registry/config";
5
+ HEADER_ACTOR_GENERATION,
6
+ HEADER_ACTOR_ID,
7
+ HEADER_ACTOR_KEY,
8
+ } from "@/common/actor-router-consts";
9
9
  import type * as protocol from "@/common/client-protocol";
10
10
  import {
11
11
  CURRENT_VERSION as CLIENT_PROTOCOL_CURRENT_VERSION,
@@ -15,15 +15,17 @@ import {
15
15
  type HttpResponseError as HttpResponseErrorJson,
16
16
  HttpResponseErrorSchema,
17
17
  } from "@/common/client-protocol-zod";
18
+ import type { Encoding, JsonCompatValue } from "@/common/encoding";
18
19
  import {
19
- encodeCborCompat,
20
- encodingIsBinary,
21
- serializeWithEncoding,
22
- } from "@/serde";
20
+ getRequestEncoding,
21
+ getRequestExposeInternalError,
22
+ } from "@/common/router-request";
23
+ import { buildActorNames, type RegistryConfig } from "@/registry/config";
24
+ import { encodeCborCompat, serializeWithEncoding } from "@/serde";
23
25
  import { bufferToArrayBuffer, VERSION } from "@/utils";
24
26
  import { getLogHeaders } from "@/utils/env-vars";
25
27
  import { getLogger, type Logger } from "./log";
26
- import { deconstructError, stringifyError } from "./utils";
28
+ import { deconstructError } from "./utils";
27
29
 
28
30
  export function logger() {
29
31
  return getLogger("router");
@@ -61,15 +63,19 @@ export function handleRouteNotFound(c: HonoContext) {
61
63
  export function handleRouteError(error: unknown, c: HonoContext) {
62
64
  const exposeInternalError = getRequestExposeInternalError(c.req.raw);
63
65
 
64
- const { statusCode, group, code, message, metadata } = deconstructError(
65
- error,
66
- logger(),
67
- {
68
- method: c.req.method,
69
- path: c.req.path,
70
- },
71
- exposeInternalError,
72
- );
66
+ const { statusCode, group, code, message, metadata, actor } =
67
+ deconstructError(error, exposeInternalError);
68
+
69
+ if (actor) {
70
+ logger().warn({
71
+ msg: "actor http error response",
72
+ actorId: actor.actorId,
73
+ generation: actor.generation,
74
+ actorKey: actor.key,
75
+ group,
76
+ code,
77
+ });
78
+ }
73
79
 
74
80
  let encoding: Encoding;
75
81
  try {
@@ -78,7 +84,7 @@ export function handleRouteError(error: unknown, c: HonoContext) {
78
84
  encoding = "json";
79
85
  }
80
86
 
81
- const errorData = { group, code, message, metadata };
87
+ const errorData = { group, code, message, metadata, actor };
82
88
  const output = serializeWithEncoding(
83
89
  encoding,
84
90
  errorData,
@@ -91,6 +97,7 @@ export function handleRouteError(error: unknown, c: HonoContext) {
91
97
  code: value.code,
92
98
  message: value.message,
93
99
  metadata: value.metadata,
100
+ actor: value.actor,
94
101
  }),
95
102
  // BARE/CBOR: metadata needs to be CBOR-encoded to ArrayBuffer
96
103
  (value): protocol.HttpResponseError => ({
@@ -98,13 +105,32 @@ export function handleRouteError(error: unknown, c: HonoContext) {
98
105
  code: value.code,
99
106
  message: value.message,
100
107
  metadata: value.metadata
101
- ? bufferToArrayBuffer(encodeCborCompat(value.metadata))
108
+ ? bufferToArrayBuffer(
109
+ encodeCborCompat(value.metadata as JsonCompatValue),
110
+ )
111
+ : null,
112
+ actor: value.actor
113
+ ? {
114
+ actorId: value.actor.actorId,
115
+ generation: BigInt(value.actor.generation),
116
+ key: value.actor.key ?? null,
117
+ }
102
118
  : null,
103
119
  }),
104
120
  );
105
121
 
122
+ const headers = actor ? actorResponseHeaders(actor) : undefined;
123
+
106
124
  // TODO: Remove any
107
- return c.body(output as any, { status: statusCode });
125
+ return c.body(output as any, { status: statusCode, headers });
126
+ }
127
+
128
+ function actorResponseHeaders(actor: ActorSpecifier): Record<string, string> {
129
+ return {
130
+ [HEADER_ACTOR_ID]: actor.actorId,
131
+ [HEADER_ACTOR_GENERATION]: String(actor.generation),
132
+ ...(actor.key ? { [HEADER_ACTOR_KEY]: actor.key } : {}),
133
+ };
108
134
  }
109
135
 
110
136
  export type MetadataEnvoyKind =
@@ -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, VERSION } 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,8 @@ export interface DeconstructedError {
195
44
  code: string;
196
45
  message: string;
197
46
  metadata?: unknown;
47
+ rayId?: string;
48
+ actor?: errors.ActorSpecifier;
198
49
  }
199
50
 
200
51
  function isCanonicalStructuredRivetError(
@@ -221,19 +72,17 @@ function isCanonicalStructuredRivetError(
221
72
  */
222
73
  export function deconstructError(
223
74
  error: unknown,
224
- logger: Logger,
225
- extraLog: Record<string, unknown>,
226
75
  exposeInternalError = false,
227
76
  ): DeconstructedError {
228
77
  // 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
78
  let statusCode: ContentfulStatusCode;
232
79
  let public_: boolean;
233
80
  let group: string;
234
81
  let code: string;
235
82
  let message: string;
236
83
  let metadata: unknown;
84
+ let rayId: string | undefined;
85
+ let actor: errors.ActorSpecifier | undefined;
237
86
  // Structured errors from core or from pre-built `RivetError` instances are canonical.
238
87
  // Only unstructured errors go through the classifier below.
239
88
  if (isCanonicalStructuredRivetError(error)) {
@@ -249,15 +98,8 @@ export function deconstructError(
249
98
  code = error.code;
250
99
  message = error.message;
251
100
  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
- });
101
+ rayId = error.rayId;
102
+ actor = error.actor;
261
103
  } else if (errors.ActorError.isActorError(error) && error.public) {
262
104
  // Check if error has statusCode (could be ActorError instance or DeconstructedError)
263
105
  statusCode = (
@@ -268,15 +110,8 @@ export function deconstructError(
268
110
  code = error.code;
269
111
  message = getErrorMessage(error);
270
112
  metadata = error.metadata;
271
-
272
- logger.info({
273
- msg: "public error",
274
- group,
275
- code,
276
- message,
277
- ...EXTRA_ERROR_LOG,
278
- ...extraLog,
279
- });
113
+ rayId = error.rayId;
114
+ actor = error.actor;
280
115
  } else if (exposeInternalError) {
281
116
  if (errors.ActorError.isActorError(error)) {
282
117
  statusCode = 500;
@@ -285,32 +120,14 @@ export function deconstructError(
285
120
  code = error.code;
286
121
  message = getErrorMessage(error);
287
122
  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
- });
123
+ rayId = error.rayId;
124
+ actor = error.actor;
298
125
  } else {
299
126
  statusCode = 500;
300
127
  public_ = false;
301
128
  group = "rivetkit";
302
129
  code = errors.INTERNAL_ERROR_CODE;
303
130
  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
131
  }
315
132
  } else {
316
133
  statusCode = 500;
@@ -318,17 +135,12 @@ export function deconstructError(
318
135
  group = "rivetkit";
319
136
  code = errors.INTERNAL_ERROR_CODE;
320
137
  message = errors.INTERNAL_ERROR_DESCRIPTION;
138
+ if (errors.ActorError.isActorError(error)) {
139
+ actor = error.actor;
140
+ }
321
141
  metadata = {
322
- //url: `https://hub.rivet.dev/projects/${actorMetadata.project.slug}/environments/${actorMetadata.environment.slug}/actors?actorId=${actorMetadata.actor.id}`,
142
+ //url: `https://dashboard.rivet.dev/projects/${actorMetadata.project.slug}/environments/${actorMetadata.environment.slug}/actors?actorId=${actorMetadata.actor.id}`,
323
143
  } 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
144
  }
333
145
 
334
146
  return {
@@ -339,13 +151,21 @@ export function deconstructError(
339
151
  code,
340
152
  message,
341
153
  metadata,
154
+ rayId,
155
+ actor,
342
156
  };
343
157
  }
344
158
 
345
159
  export function stringifyError(error: unknown): string {
346
160
  if (error instanceof Error) {
347
161
  if (typeof process !== "undefined" && getLogErrorStack()) {
348
- return `${error.name}: ${error.message}${error.stack ? `\n${error.stack}` : ""}`;
162
+ let stack: string | undefined;
163
+ try {
164
+ stack = error.stack;
165
+ } catch {
166
+ stack = undefined;
167
+ }
168
+ return `${error.name}: ${error.message}${stack ? `\n${stack}` : ""}`;
349
169
  } else {
350
170
  return `${error.name}: ${error.message}`;
351
171
  }
@@ -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";