rivetkit 2.0.3 → 2.0.4

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 (233) hide show
  1. package/README.md +11 -0
  2. package/dist/schemas/actor-persist/v1.ts +21 -24
  3. package/dist/schemas/client-protocol/v1.ts +6 -0
  4. package/dist/tsup/actor/errors.cjs +10 -2
  5. package/dist/tsup/actor/errors.cjs.map +1 -1
  6. package/dist/tsup/actor/errors.d.cts +17 -4
  7. package/dist/tsup/actor/errors.d.ts +17 -4
  8. package/dist/tsup/actor/errors.js +11 -3
  9. package/dist/tsup/{chunk-6PDXBYI5.js → chunk-3F2YSRJL.js} +8 -23
  10. package/dist/tsup/chunk-3F2YSRJL.js.map +1 -0
  11. package/dist/tsup/chunk-4CXBCT26.cjs +250 -0
  12. package/dist/tsup/chunk-4CXBCT26.cjs.map +1 -0
  13. package/dist/tsup/chunk-4R73YDN3.cjs +20 -0
  14. package/dist/tsup/chunk-4R73YDN3.cjs.map +1 -0
  15. package/dist/tsup/{chunk-OGAPU3UG.cjs → chunk-6LJT3QRL.cjs} +39 -25
  16. package/dist/tsup/chunk-6LJT3QRL.cjs.map +1 -0
  17. package/dist/tsup/{chunk-6WKQDDUD.cjs → chunk-GICQ3YCU.cjs} +143 -141
  18. package/dist/tsup/chunk-GICQ3YCU.cjs.map +1 -0
  19. package/dist/tsup/{chunk-FLMTTN27.js → chunk-H26RP6GD.js} +15 -8
  20. package/dist/tsup/chunk-H26RP6GD.js.map +1 -0
  21. package/dist/tsup/chunk-HI3HWJRC.js +20 -0
  22. package/dist/tsup/chunk-HI3HWJRC.js.map +1 -0
  23. package/dist/tsup/{chunk-4NSUQZ2H.js → chunk-HLLF4B4Q.js} +116 -114
  24. package/dist/tsup/chunk-HLLF4B4Q.js.map +1 -0
  25. package/dist/tsup/{chunk-FCCPJNMA.cjs → chunk-IH6CKNDW.cjs} +12 -27
  26. package/dist/tsup/chunk-IH6CKNDW.cjs.map +1 -0
  27. package/dist/tsup/chunk-LV2S3OU3.js +250 -0
  28. package/dist/tsup/chunk-LV2S3OU3.js.map +1 -0
  29. package/dist/tsup/{chunk-R2OPSKIV.cjs → chunk-LWNKVZG5.cjs} +20 -13
  30. package/dist/tsup/chunk-LWNKVZG5.cjs.map +1 -0
  31. package/dist/tsup/{chunk-INGJP237.js → chunk-NFU2BBT5.js} +102 -43
  32. package/dist/tsup/chunk-NFU2BBT5.js.map +1 -0
  33. package/dist/tsup/{chunk-3H7O2A7I.js → chunk-PQY7KKTL.js} +33 -19
  34. package/dist/tsup/chunk-PQY7KKTL.js.map +1 -0
  35. package/dist/tsup/{chunk-PO4VLDWA.js → chunk-QK72M5JB.js} +3 -5
  36. package/dist/tsup/chunk-QK72M5JB.js.map +1 -0
  37. package/dist/tsup/{chunk-TZJKSBUQ.cjs → chunk-QNNXFOQV.cjs} +3 -5
  38. package/dist/tsup/chunk-QNNXFOQV.cjs.map +1 -0
  39. package/dist/tsup/{chunk-GIR3AFFI.cjs → chunk-SBHHJ6QS.cjs} +102 -43
  40. package/dist/tsup/chunk-SBHHJ6QS.cjs.map +1 -0
  41. package/dist/tsup/chunk-TQ62L3X7.js +325 -0
  42. package/dist/tsup/chunk-TQ62L3X7.js.map +1 -0
  43. package/dist/tsup/chunk-VO7ZRVVD.cjs +6293 -0
  44. package/dist/tsup/chunk-VO7ZRVVD.cjs.map +1 -0
  45. package/dist/tsup/chunk-WHBPJNGW.cjs +325 -0
  46. package/dist/tsup/chunk-WHBPJNGW.cjs.map +1 -0
  47. package/dist/tsup/chunk-XJQHKJ4P.js +6293 -0
  48. package/dist/tsup/chunk-XJQHKJ4P.js.map +1 -0
  49. package/dist/tsup/client/mod.cjs +10 -10
  50. package/dist/tsup/client/mod.d.cts +7 -13
  51. package/dist/tsup/client/mod.d.ts +7 -13
  52. package/dist/tsup/client/mod.js +9 -9
  53. package/dist/tsup/common/log.cjs +12 -4
  54. package/dist/tsup/common/log.cjs.map +1 -1
  55. package/dist/tsup/common/log.d.cts +23 -17
  56. package/dist/tsup/common/log.d.ts +23 -17
  57. package/dist/tsup/common/log.js +15 -7
  58. package/dist/tsup/common/websocket.cjs +5 -5
  59. package/dist/tsup/common/websocket.js +4 -4
  60. package/dist/tsup/{common-CpqORuCq.d.cts → common-CXCe7s6i.d.cts} +2 -2
  61. package/dist/tsup/{common-CpqORuCq.d.ts → common-CXCe7s6i.d.ts} +2 -2
  62. package/dist/tsup/{connection-BwUMoe6n.d.ts → connection-BI-6UIBJ.d.ts} +196 -226
  63. package/dist/tsup/{connection-BR_Ve4ku.d.cts → connection-Dyd4NLGW.d.cts} +196 -226
  64. package/dist/tsup/driver-helpers/mod.cjs +6 -9
  65. package/dist/tsup/driver-helpers/mod.cjs.map +1 -1
  66. package/dist/tsup/driver-helpers/mod.d.cts +5 -6
  67. package/dist/tsup/driver-helpers/mod.d.ts +5 -6
  68. package/dist/tsup/driver-helpers/mod.js +6 -9
  69. package/dist/tsup/driver-test-suite/mod.cjs +155 -1363
  70. package/dist/tsup/driver-test-suite/mod.cjs.map +1 -1
  71. package/dist/tsup/driver-test-suite/mod.d.cts +11 -5
  72. package/dist/tsup/driver-test-suite/mod.d.ts +11 -5
  73. package/dist/tsup/driver-test-suite/mod.js +876 -2084
  74. package/dist/tsup/driver-test-suite/mod.js.map +1 -1
  75. package/dist/tsup/inspector/mod.cjs +6 -8
  76. package/dist/tsup/inspector/mod.cjs.map +1 -1
  77. package/dist/tsup/inspector/mod.d.cts +3 -3
  78. package/dist/tsup/inspector/mod.d.ts +3 -3
  79. package/dist/tsup/inspector/mod.js +8 -10
  80. package/dist/tsup/mod.cjs +9 -15
  81. package/dist/tsup/mod.cjs.map +1 -1
  82. package/dist/tsup/mod.d.cts +47 -42
  83. package/dist/tsup/mod.d.ts +47 -42
  84. package/dist/tsup/mod.js +10 -16
  85. package/dist/tsup/{router-endpoints-DAbqVFx2.d.ts → router-endpoints-BTe_Rsdn.d.cts} +2 -3
  86. package/dist/tsup/{router-endpoints-AYkXG8Tl.d.cts → router-endpoints-CBSrKHmo.d.ts} +2 -3
  87. package/dist/tsup/test/mod.cjs +10 -14
  88. package/dist/tsup/test/mod.cjs.map +1 -1
  89. package/dist/tsup/test/mod.d.cts +4 -5
  90. package/dist/tsup/test/mod.d.ts +4 -5
  91. package/dist/tsup/test/mod.js +9 -13
  92. package/dist/tsup/{utils-CT0cv4jd.d.ts → utils-fwx3o3K9.d.cts} +1 -0
  93. package/dist/tsup/{utils-CT0cv4jd.d.cts → utils-fwx3o3K9.d.ts} +1 -0
  94. package/dist/tsup/utils.cjs +3 -3
  95. package/dist/tsup/utils.d.cts +1 -1
  96. package/dist/tsup/utils.d.ts +1 -1
  97. package/dist/tsup/utils.js +2 -2
  98. package/package.json +4 -4
  99. package/src/actor/action.ts +1 -5
  100. package/src/actor/config.ts +27 -295
  101. package/src/actor/connection.ts +9 -12
  102. package/src/actor/context.ts +1 -4
  103. package/src/actor/definition.ts +7 -11
  104. package/src/actor/errors.ts +97 -35
  105. package/src/actor/generic-conn-driver.ts +28 -16
  106. package/src/actor/instance.ts +177 -133
  107. package/src/actor/log.ts +4 -13
  108. package/src/actor/mod.ts +0 -5
  109. package/src/actor/protocol/old.ts +42 -26
  110. package/src/actor/protocol/serde.ts +1 -1
  111. package/src/actor/router-endpoints.ts +41 -38
  112. package/src/actor/router.ts +20 -18
  113. package/src/actor/unstable-react.ts +1 -1
  114. package/src/actor/utils.ts +6 -2
  115. package/src/client/actor-common.ts +1 -1
  116. package/src/client/actor-conn.ts +152 -91
  117. package/src/client/actor-handle.ts +85 -25
  118. package/src/client/actor-query.ts +65 -0
  119. package/src/client/client.ts +29 -98
  120. package/src/client/config.ts +44 -0
  121. package/src/client/errors.ts +1 -0
  122. package/src/client/log.ts +2 -4
  123. package/src/client/mod.ts +16 -12
  124. package/src/client/raw-utils.ts +82 -25
  125. package/src/client/utils.ts +5 -3
  126. package/src/common/fake-event-source.ts +10 -9
  127. package/src/common/inline-websocket-adapter2.ts +39 -30
  128. package/src/common/log.ts +176 -101
  129. package/src/common/logfmt.ts +21 -30
  130. package/src/common/router.ts +12 -19
  131. package/src/common/utils.ts +27 -13
  132. package/src/common/websocket.ts +0 -1
  133. package/src/driver-helpers/mod.ts +1 -1
  134. package/src/driver-test-suite/log.ts +1 -3
  135. package/src/driver-test-suite/mod.ts +86 -60
  136. package/src/driver-test-suite/tests/actor-handle.ts +33 -0
  137. package/src/driver-test-suite/tests/manager-driver.ts +5 -3
  138. package/src/driver-test-suite/tests/raw-http-direct-registry.ts +227 -226
  139. package/src/driver-test-suite/tests/raw-websocket-direct-registry.ts +393 -392
  140. package/src/driver-test-suite/tests/request-access.ts +112 -126
  141. package/src/driver-test-suite/utils.ts +13 -10
  142. package/src/drivers/default.ts +7 -4
  143. package/src/drivers/engine/actor-driver.ts +22 -13
  144. package/src/drivers/engine/config.ts +2 -10
  145. package/src/drivers/engine/kv.ts +1 -1
  146. package/src/drivers/engine/log.ts +1 -3
  147. package/src/drivers/engine/mod.ts +2 -3
  148. package/src/drivers/file-system/actor.ts +1 -1
  149. package/src/drivers/file-system/global-state.ts +33 -20
  150. package/src/drivers/file-system/log.ts +1 -3
  151. package/src/drivers/file-system/manager.ts +31 -8
  152. package/src/inspector/config.ts +9 -4
  153. package/src/inspector/log.ts +1 -1
  154. package/src/inspector/manager.ts +2 -2
  155. package/src/inspector/utils.ts +1 -1
  156. package/src/manager/driver.ts +10 -2
  157. package/src/manager/hono-websocket-adapter.ts +21 -12
  158. package/src/manager/log.ts +2 -4
  159. package/src/manager/mod.ts +1 -1
  160. package/src/manager/router.ts +277 -1657
  161. package/src/manager-api/routes/actors-create.ts +16 -0
  162. package/src/manager-api/routes/actors-delete.ts +4 -0
  163. package/src/manager-api/routes/actors-get-by-id.ts +7 -0
  164. package/src/manager-api/routes/actors-get-or-create-by-id.ts +29 -0
  165. package/src/manager-api/routes/actors-get.ts +7 -0
  166. package/src/manager-api/routes/common.ts +18 -0
  167. package/src/mod.ts +0 -2
  168. package/src/registry/config.ts +1 -1
  169. package/src/registry/log.ts +2 -4
  170. package/src/registry/mod.ts +57 -24
  171. package/src/registry/run-config.ts +31 -33
  172. package/src/registry/serve.ts +4 -5
  173. package/src/remote-manager-driver/actor-http-client.ts +72 -0
  174. package/src/remote-manager-driver/actor-websocket-client.ts +63 -0
  175. package/src/remote-manager-driver/api-endpoints.ts +79 -0
  176. package/src/remote-manager-driver/api-utils.ts +43 -0
  177. package/src/remote-manager-driver/log.ts +5 -0
  178. package/src/remote-manager-driver/mod.ts +274 -0
  179. package/src/{drivers/engine → remote-manager-driver}/ws-proxy.ts +24 -14
  180. package/src/serde.ts +8 -2
  181. package/src/test/log.ts +1 -3
  182. package/src/test/mod.ts +17 -16
  183. package/dist/tsup/chunk-2CRLFV6Z.cjs +0 -202
  184. package/dist/tsup/chunk-2CRLFV6Z.cjs.map +0 -1
  185. package/dist/tsup/chunk-3H7O2A7I.js.map +0 -1
  186. package/dist/tsup/chunk-42I3OZ3Q.js +0 -15
  187. package/dist/tsup/chunk-42I3OZ3Q.js.map +0 -1
  188. package/dist/tsup/chunk-4NSUQZ2H.js.map +0 -1
  189. package/dist/tsup/chunk-6PDXBYI5.js.map +0 -1
  190. package/dist/tsup/chunk-6WKQDDUD.cjs.map +0 -1
  191. package/dist/tsup/chunk-CTBOSFUH.cjs +0 -116
  192. package/dist/tsup/chunk-CTBOSFUH.cjs.map +0 -1
  193. package/dist/tsup/chunk-EGVZZFE2.js +0 -2857
  194. package/dist/tsup/chunk-EGVZZFE2.js.map +0 -1
  195. package/dist/tsup/chunk-FCCPJNMA.cjs.map +0 -1
  196. package/dist/tsup/chunk-FLMTTN27.js.map +0 -1
  197. package/dist/tsup/chunk-GIR3AFFI.cjs.map +0 -1
  198. package/dist/tsup/chunk-INGJP237.js.map +0 -1
  199. package/dist/tsup/chunk-KJCJLKRM.js +0 -116
  200. package/dist/tsup/chunk-KJCJLKRM.js.map +0 -1
  201. package/dist/tsup/chunk-KUPQZYUQ.cjs +0 -15
  202. package/dist/tsup/chunk-KUPQZYUQ.cjs.map +0 -1
  203. package/dist/tsup/chunk-O2MBYIXO.cjs +0 -2857
  204. package/dist/tsup/chunk-O2MBYIXO.cjs.map +0 -1
  205. package/dist/tsup/chunk-OGAPU3UG.cjs.map +0 -1
  206. package/dist/tsup/chunk-OV6AYD4S.js +0 -4406
  207. package/dist/tsup/chunk-OV6AYD4S.js.map +0 -1
  208. package/dist/tsup/chunk-PO4VLDWA.js.map +0 -1
  209. package/dist/tsup/chunk-R2OPSKIV.cjs.map +0 -1
  210. package/dist/tsup/chunk-TZJKSBUQ.cjs.map +0 -1
  211. package/dist/tsup/chunk-UBUC5C3G.cjs +0 -189
  212. package/dist/tsup/chunk-UBUC5C3G.cjs.map +0 -1
  213. package/dist/tsup/chunk-UIM22YJL.cjs +0 -4406
  214. package/dist/tsup/chunk-UIM22YJL.cjs.map +0 -1
  215. package/dist/tsup/chunk-URVFQMYI.cjs +0 -230
  216. package/dist/tsup/chunk-URVFQMYI.cjs.map +0 -1
  217. package/dist/tsup/chunk-UVUPOS46.js +0 -230
  218. package/dist/tsup/chunk-UVUPOS46.js.map +0 -1
  219. package/dist/tsup/chunk-VRRHBNJC.js +0 -189
  220. package/dist/tsup/chunk-VRRHBNJC.js.map +0 -1
  221. package/dist/tsup/chunk-XFSS33EQ.js +0 -202
  222. package/dist/tsup/chunk-XFSS33EQ.js.map +0 -1
  223. package/src/client/http-client-driver.ts +0 -326
  224. package/src/driver-test-suite/test-inline-client-driver.ts +0 -402
  225. package/src/driver-test-suite/tests/actor-auth.ts +0 -591
  226. package/src/drivers/engine/api-endpoints.ts +0 -128
  227. package/src/drivers/engine/api-utils.ts +0 -70
  228. package/src/drivers/engine/manager-driver.ts +0 -391
  229. package/src/inline-client-driver/log.ts +0 -7
  230. package/src/inline-client-driver/mod.ts +0 -385
  231. package/src/manager/auth.ts +0 -121
  232. /package/src/{drivers/engine → actor}/keys.test.ts +0 -0
  233. /package/src/{drivers/engine → actor}/keys.ts +0 -0
@@ -20,6 +20,8 @@ export class ActorError extends Error {
20
20
  public public: boolean;
21
21
  public metadata?: unknown;
22
22
  public statusCode = 500;
23
+ public readonly group: string;
24
+ public readonly code: string;
23
25
 
24
26
  public static isActorError(
25
27
  error: unknown,
@@ -31,11 +33,14 @@ export class ActorError extends Error {
31
33
  }
32
34
 
33
35
  constructor(
34
- public readonly code: string,
36
+ group: string,
37
+ code: string,
35
38
  message: string,
36
39
  opts?: ActorErrorOptions,
37
40
  ) {
38
41
  super(message, { cause: opts?.cause });
42
+ this.group = group;
43
+ this.code = code;
39
44
  this.public = opts?.public ?? false;
40
45
  this.metadata = opts?.metadata;
41
46
 
@@ -64,7 +69,7 @@ export class ActorError extends Error {
64
69
 
65
70
  export class InternalError extends ActorError {
66
71
  constructor(message: string) {
67
- super(INTERNAL_ERROR_CODE, message);
72
+ super("actor", INTERNAL_ERROR_CODE, message);
68
73
  }
69
74
  }
70
75
 
@@ -77,8 +82,9 @@ export class Unreachable extends InternalError {
77
82
  export class StateNotEnabled extends ActorError {
78
83
  constructor() {
79
84
  super(
85
+ "actor",
80
86
  "state_not_enabled",
81
- "State not enabled. Must implement `createState` or `state` to use state. (https://www.rivet.gg/docs/actors/state/#initializing-state)",
87
+ "State not enabled. Must implement `createState` or `state` to use state. (https://www.rivet.dev/docs/actors/state/#initializing-state)",
82
88
  );
83
89
  }
84
90
  }
@@ -86,8 +92,9 @@ export class StateNotEnabled extends ActorError {
86
92
  export class ConnStateNotEnabled extends ActorError {
87
93
  constructor() {
88
94
  super(
95
+ "actor",
89
96
  "conn_state_not_enabled",
90
- "Connection state not enabled. Must implement `createConnectionState` or `connectionState` to use connection state. (https://www.rivet.gg/docs/actors/connections/#connection-state)",
97
+ "Connection state not enabled. Must implement `createConnectionState` or `connectionState` to use connection state. (https://www.rivet.dev/docs/actors/connections/#connection-state)",
91
98
  );
92
99
  }
93
100
  }
@@ -95,8 +102,9 @@ export class ConnStateNotEnabled extends ActorError {
95
102
  export class VarsNotEnabled extends ActorError {
96
103
  constructor() {
97
104
  super(
105
+ "actor",
98
106
  "vars_not_enabled",
99
- "Variables not enabled. Must implement `createVars` or `vars` to use state. (https://www.rivet.gg/docs/actors/ephemeral-variables/#initializing-variables)",
107
+ "Variables not enabled. Must implement `createVars` or `vars` to use state. (https://www.rivet.dev/docs/actors/ephemeral-variables/#initializing-variables)",
100
108
  );
101
109
  }
102
110
  }
@@ -104,7 +112,8 @@ export class VarsNotEnabled extends ActorError {
104
112
  export class ActionTimedOut extends ActorError {
105
113
  constructor() {
106
114
  super(
107
- "action_timed_out",
115
+ "action",
116
+ "timed_out",
108
117
  "Action timed out. This can be increased with: `actor({ options: { action: { timeout: ... } } })`",
109
118
  { public: true },
110
119
  );
@@ -114,7 +123,8 @@ export class ActionTimedOut extends ActorError {
114
123
  export class ActionNotFound extends ActorError {
115
124
  constructor(name: string) {
116
125
  super(
117
- "action_not_found",
126
+ "action",
127
+ "not_found",
118
128
  `Action '${name}' not found. Validate the action exists on your actor.`,
119
129
  { public: true },
120
130
  );
@@ -124,8 +134,9 @@ export class ActionNotFound extends ActorError {
124
134
  export class InvalidEncoding extends ActorError {
125
135
  constructor(format?: string) {
126
136
  super(
127
- "invalid_encoding",
128
- `Invalid encoding \`${format}\`. (https://www.rivet.gg/docs/actors/clients/#actor-client)`,
137
+ "encoding",
138
+ "invalid",
139
+ `Invalid encoding \`${format}\`. (https://www.rivet.dev/docs/actors/clients/#actor-client)`,
129
140
  {
130
141
  public: true,
131
142
  },
@@ -135,7 +146,7 @@ export class InvalidEncoding extends ActorError {
135
146
 
136
147
  export class ConnNotFound extends ActorError {
137
148
  constructor(id?: string) {
138
- super("conn_not_found", `Connection not found for ID: ${id}`, {
149
+ super("connection", "not_found", `Connection not found for ID: ${id}`, {
139
150
  public: true,
140
151
  });
141
152
  }
@@ -143,7 +154,7 @@ export class ConnNotFound extends ActorError {
143
154
 
144
155
  export class IncorrectConnToken extends ActorError {
145
156
  constructor() {
146
- super("incorrect_conn_token", "Incorrect connection token.", {
157
+ super("connection", "incorrect_token", "Incorrect connection token.", {
147
158
  public: true,
148
159
  });
149
160
  }
@@ -152,7 +163,8 @@ export class IncorrectConnToken extends ActorError {
152
163
  export class MessageTooLong extends ActorError {
153
164
  constructor() {
154
165
  super(
155
- "message_too_long",
166
+ "message",
167
+ "too_long",
156
168
  "Message too long. This can be configured with: `registry.runServer({ maxIncomingMessageSize: ... })`",
157
169
  { public: true },
158
170
  );
@@ -161,7 +173,7 @@ export class MessageTooLong extends ActorError {
161
173
 
162
174
  export class MalformedMessage extends ActorError {
163
175
  constructor(cause?: unknown) {
164
- super("malformed_message", `Malformed message: ${cause}`, {
176
+ super("message", "malformed", `Malformed message: ${cause}`, {
165
177
  public: true,
166
178
  cause,
167
179
  });
@@ -181,14 +193,14 @@ export class InvalidStateType extends ActorError {
181
193
  msg += "Attempted to set invalid state.";
182
194
  }
183
195
  msg +=
184
- " Valid types include: null, undefined, boolean, string, number, BigInt, Date, RegExp, Error, typed arrays (Uint8Array, Int8Array, Float32Array, etc.), Map, Set, Array, and plain objects. (https://www.rivet.gg/docs/actors/state/#limitations)";
185
- super("invalid_state_type", msg);
196
+ " Valid types include: null, undefined, boolean, string, number, BigInt, Date, RegExp, Error, typed arrays (Uint8Array, Int8Array, Float32Array, etc.), Map, Set, Array, and plain objects. (https://www.rivet.dev/docs/actors/state/#limitations)";
197
+ super("state", "invalid_type", msg);
186
198
  }
187
199
  }
188
200
 
189
201
  export class Unsupported extends ActorError {
190
202
  constructor(feature: string) {
191
- super("unsupported", `Unsupported feature: ${feature}`);
203
+ super("feature", "unsupported", `Unsupported feature: ${feature}`);
192
204
  }
193
205
  }
194
206
 
@@ -216,7 +228,7 @@ export class UserError extends ActorError {
216
228
  * @param opts - Optional parameters for the error, including a machine-readable code and additional metadata.
217
229
  */
218
230
  constructor(message: string, opts?: UserErrorOptions) {
219
- super(opts?.code ?? USER_ERROR_CODE, message, {
231
+ super("user", opts?.code ?? USER_ERROR_CODE, message, {
220
232
  public: true,
221
233
  metadata: opts?.metadata,
222
234
  });
@@ -225,7 +237,7 @@ export class UserError extends ActorError {
225
237
 
226
238
  export class InvalidQueryJSON extends ActorError {
227
239
  constructor(error?: unknown) {
228
- super("invalid_query_json", `Invalid query JSON: ${error}`, {
240
+ super("request", "invalid_query_json", `Invalid query JSON: ${error}`, {
229
241
  public: true,
230
242
  cause: error,
231
243
  });
@@ -234,7 +246,7 @@ export class InvalidQueryJSON extends ActorError {
234
246
 
235
247
  export class InvalidRequest extends ActorError {
236
248
  constructor(error?: unknown) {
237
- super("invalid_request", `Invalid request: ${error}`, {
249
+ super("request", "invalid", `Invalid request: ${error}`, {
238
250
  public: true,
239
251
  cause: error,
240
252
  });
@@ -244,10 +256,11 @@ export class InvalidRequest extends ActorError {
244
256
  export class ActorNotFound extends ActorError {
245
257
  constructor(identifier?: string) {
246
258
  super(
247
- "actor_not_found",
259
+ "actor",
260
+ "not_found",
248
261
  identifier
249
- ? `Actor not found: ${identifier} (https://www.rivet.gg/docs/actors/clients/#actor-client)`
250
- : "Actor not found (https://www.rivet.gg/docs/actors/clients/#actor-client)",
262
+ ? `Actor not found: ${identifier} (https://www.rivet.dev/docs/actors/clients/#actor-client)`
263
+ : "Actor not found (https://www.rivet.dev/docs/actors/clients/#actor-client)",
251
264
  { public: true },
252
265
  );
253
266
  }
@@ -256,8 +269,9 @@ export class ActorNotFound extends ActorError {
256
269
  export class ActorAlreadyExists extends ActorError {
257
270
  constructor(name: string, key: string[]) {
258
271
  super(
259
- "actor_already_exists",
260
- `Actor already exists with name '${name}' and key '${JSON.stringify(key)}' (https://www.rivet.gg/docs/actors/clients/#actor-client)`,
272
+ "actor",
273
+ "already_exists",
274
+ `Actor already exists with name '${name}' and key '${JSON.stringify(key)}' (https://www.rivet.dev/docs/actors/clients/#actor-client)`,
261
275
  { public: true },
262
276
  );
263
277
  }
@@ -266,7 +280,8 @@ export class ActorAlreadyExists extends ActorError {
266
280
  export class ProxyError extends ActorError {
267
281
  constructor(operation: string, error?: unknown) {
268
282
  super(
269
- "proxy_error",
283
+ "proxy",
284
+ "error",
270
285
  `Error proxying ${operation}, this is likely an internal error: ${error}`,
271
286
  {
272
287
  public: true,
@@ -278,22 +293,23 @@ export class ProxyError extends ActorError {
278
293
 
279
294
  export class InvalidActionRequest extends ActorError {
280
295
  constructor(message: string) {
281
- super("invalid_action_request", message, { public: true });
296
+ super("action", "invalid_request", message, { public: true });
282
297
  }
283
298
  }
284
299
 
285
300
  export class InvalidParams extends ActorError {
286
301
  constructor(message: string) {
287
- super("invalid_params", message, { public: true });
302
+ super("params", "invalid", message, { public: true });
288
303
  }
289
304
  }
290
305
 
291
306
  export class Unauthorized extends ActorError {
292
307
  constructor(message?: string) {
293
308
  super(
309
+ "auth",
294
310
  "unauthorized",
295
311
  message ??
296
- "Unauthorized. Access denied. (https://www.rivet.gg/docs/actors/authentication/)",
312
+ "Unauthorized. Access denied. (https://www.rivet.dev/docs/actors/authentication/)",
297
313
  {
298
314
  public: true,
299
315
  },
@@ -305,9 +321,10 @@ export class Unauthorized extends ActorError {
305
321
  export class Forbidden extends ActorError {
306
322
  constructor(message?: string, opts?: { metadata?: unknown }) {
307
323
  super(
324
+ "auth",
308
325
  "forbidden",
309
326
  message ??
310
- "Forbidden. Access denied. (https://www.rivet.gg/docs/actors/authentication/)",
327
+ "Forbidden. Access denied. (https://www.rivet.dev/docs/actors/authentication/)",
311
328
  {
312
329
  public: true,
313
330
  metadata: opts?.metadata,
@@ -320,7 +337,8 @@ export class Forbidden extends ActorError {
320
337
  export class DatabaseNotEnabled extends ActorError {
321
338
  constructor() {
322
339
  super(
323
- "database_not_enabled",
340
+ "database",
341
+ "not_enabled",
324
342
  "Database not enabled. Must implement `database` to use database.",
325
343
  );
326
344
  }
@@ -329,8 +347,9 @@ export class DatabaseNotEnabled extends ActorError {
329
347
  export class FetchHandlerNotDefined extends ActorError {
330
348
  constructor() {
331
349
  super(
332
- "fetch_handler_not_defined",
333
- "Raw HTTP handler not defined. Actor must implement `onFetch` to handle raw HTTP requests. (https://www.rivet.gg/docs/actors/fetch-and-websocket-handler/)",
350
+ "handler",
351
+ "fetch_not_defined",
352
+ "Raw HTTP handler not defined. Actor must implement `onFetch` to handle raw HTTP requests. (https://www.rivet.dev/docs/actors/fetch-and-websocket-handler/)",
334
353
  { public: true },
335
354
  );
336
355
  this.statusCode = 404;
@@ -340,8 +359,9 @@ export class FetchHandlerNotDefined extends ActorError {
340
359
  export class WebSocketHandlerNotDefined extends ActorError {
341
360
  constructor() {
342
361
  super(
343
- "websocket_handler_not_defined",
344
- "Raw WebSocket handler not defined. Actor must implement `onWebSocket` to handle raw WebSocket connections. (https://www.rivet.gg/docs/actors/fetch-and-websocket-handler/)",
362
+ "handler",
363
+ "websocket_not_defined",
364
+ "Raw WebSocket handler not defined. Actor must implement `onWebSocket` to handle raw WebSocket connections. (https://www.rivet.dev/docs/actors/fetch-and-websocket-handler/)",
345
365
  { public: true },
346
366
  );
347
367
  this.statusCode = 404;
@@ -351,10 +371,52 @@ export class WebSocketHandlerNotDefined extends ActorError {
351
371
  export class InvalidFetchResponse extends ActorError {
352
372
  constructor() {
353
373
  super(
374
+ "handler",
354
375
  "invalid_fetch_response",
355
- "Actor's onFetch handler must return a Response object. Returning void/undefined is not allowed. (https://www.rivet.gg/docs/actors/fetch-and-websocket-handler/)",
376
+ "Actor's onFetch handler must return a Response object. Returning void/undefined is not allowed. (https://www.rivet.dev/docs/actors/fetch-and-websocket-handler/)",
356
377
  { public: true },
357
378
  );
358
379
  this.statusCode = 500;
359
380
  }
360
381
  }
382
+
383
+ // Manager-specific errors
384
+ export class MissingActorHeader extends ActorError {
385
+ constructor() {
386
+ super(
387
+ "request",
388
+ "missing_actor_header",
389
+ "Missing x-rivet-actor header when x-rivet-target=actor",
390
+ { public: true },
391
+ );
392
+ this.statusCode = 400;
393
+ }
394
+ }
395
+
396
+ export class WebSocketsNotEnabled extends ActorError {
397
+ constructor() {
398
+ super(
399
+ "driver",
400
+ "websockets_not_enabled",
401
+ "WebSockets are not enabled for this driver",
402
+ { public: true },
403
+ );
404
+ this.statusCode = 400;
405
+ }
406
+ }
407
+
408
+ export class FeatureNotImplemented extends ActorError {
409
+ constructor(feature: string) {
410
+ super("feature", "not_implemented", `${feature} is not implemented`, {
411
+ public: true,
412
+ });
413
+ this.statusCode = 501;
414
+ }
415
+ }
416
+
417
+ export class RouteNotFound extends ActorError {
418
+ constructor() {
419
+ super("route", "not_found", "Route not found", { public: true });
420
+ this.statusCode = 404;
421
+ }
422
+ }
@@ -16,7 +16,7 @@ import type { AnyActorInstance } from "@/actor/instance";
16
16
  import type { CachedSerializer, Encoding } from "@/actor/protocol/serde";
17
17
  import { encodeDataToString } from "@/actor/protocol/serde";
18
18
  import type * as protocol from "@/schemas/client-protocol/mod";
19
- import { logger } from "./log";
19
+ import { loggerWithoutContext } from "./log";
20
20
 
21
21
  // This state is different than `PersistedConn` state since the connection-specific state is persisted & must be serializable. This is also part of the connection driver, not part of the core actor.
22
22
  //
@@ -58,7 +58,8 @@ export function createGenericWebSocketDriver(
58
58
  ) => {
59
59
  const ws = globalState.websockets.get(conn.id);
60
60
  if (!ws) {
61
- logger().warn("missing ws for sendMessage", {
61
+ actor.rLog.warn({
62
+ msg: "missing ws for sendMessage",
62
63
  actorId: actor.id,
63
64
  connId: conn.id,
64
65
  totalCount: globalState.websockets.size,
@@ -68,7 +69,8 @@ export function createGenericWebSocketDriver(
68
69
 
69
70
  const serialized = message.serialize(state.encoding);
70
71
 
71
- logger().debug("sending websocket message", {
72
+ actor.rLog.debug({
73
+ msg: "sending websocket message",
72
74
  encoding: state.encoding,
73
75
  dataType: typeof serialized,
74
76
  isUint8Array: serialized instanceof Uint8Array,
@@ -87,18 +89,21 @@ export function createGenericWebSocketDriver(
87
89
  if (buffer instanceof SharedArrayBuffer) {
88
90
  const arrayBuffer = new ArrayBuffer(buffer.byteLength);
89
91
  new Uint8Array(arrayBuffer).set(new Uint8Array(buffer));
90
- logger().debug("converted SharedArrayBuffer to ArrayBuffer", {
92
+ actor.rLog.debug({
93
+ msg: "converted SharedArrayBuffer to ArrayBuffer",
91
94
  byteLength: arrayBuffer.byteLength,
92
95
  });
93
96
  ws.send(arrayBuffer);
94
97
  } else {
95
- logger().debug("sending ArrayBuffer", {
98
+ actor.rLog.debug({
99
+ msg: "sending ArrayBuffer",
96
100
  byteLength: buffer.byteLength,
97
101
  });
98
102
  ws.send(buffer);
99
103
  }
100
104
  } else {
101
- logger().debug("sending string data", {
105
+ actor.rLog.debug({
106
+ msg: "sending string data",
102
107
  length: (serialized as string).length,
103
108
  });
104
109
  ws.send(serialized);
@@ -113,7 +118,8 @@ export function createGenericWebSocketDriver(
113
118
  ) => {
114
119
  const ws = globalState.websockets.get(conn.id);
115
120
  if (!ws) {
116
- logger().warn("missing ws for disconnect", {
121
+ actor.rLog.warn({
122
+ msg: "missing ws for disconnect",
117
123
  actorId: actor.id,
118
124
  connId: conn.id,
119
125
  totalCount: globalState.websockets.size,
@@ -122,7 +128,7 @@ export function createGenericWebSocketDriver(
122
128
  }
123
129
  const raw = ws.raw as WebSocket;
124
130
  if (!raw) {
125
- logger().warn("ws.raw does not exist");
131
+ actor.rLog.warn({ msg: "ws.raw does not exist" });
126
132
  return;
127
133
  }
128
134
 
@@ -137,12 +143,13 @@ export function createGenericWebSocketDriver(
137
143
  },
138
144
 
139
145
  getConnectionReadyState: (
140
- _actor: AnyActorInstance,
146
+ actor: AnyActorInstance,
141
147
  conn: AnyConn,
142
148
  ): ConnectionReadyState | undefined => {
143
149
  const ws = globalState.websockets.get(conn.id);
144
150
  if (!ws) {
145
- logger().warn("missing ws for getConnectionReadyState", {
151
+ actor.rLog.warn({
152
+ msg: "missing ws for getConnectionReadyState",
146
153
  connId: conn.id,
147
154
  });
148
155
  return undefined;
@@ -165,14 +172,15 @@ export function createGenericSseDriver(
165
172
  ): ConnDriver<GenericSseDriverState> {
166
173
  return {
167
174
  sendMessage: (
168
- _actor: AnyActorInstance,
175
+ actor: AnyActorInstance,
169
176
  conn: AnyConn,
170
177
  state: GenericSseDriverState,
171
178
  message: CachedSerializer<protocol.ToClient>,
172
179
  ) => {
173
180
  const stream = globalState.sseStreams.get(conn.id);
174
181
  if (!stream) {
175
- logger().warn("missing sse stream for sendMessage", {
182
+ actor.rLog.warn({
183
+ msg: "missing sse stream for sendMessage",
176
184
  connId: conn.id,
177
185
  });
178
186
  return;
@@ -183,14 +191,17 @@ export function createGenericSseDriver(
183
191
  },
184
192
 
185
193
  disconnect: async (
186
- _actor: AnyActorInstance,
194
+ actor: AnyActorInstance,
187
195
  conn: AnyConn,
188
196
  _state: GenericSseDriverState,
189
197
  _reason?: string,
190
198
  ) => {
191
199
  const stream = globalState.sseStreams.get(conn.id);
192
200
  if (!stream) {
193
- logger().warn("missing sse stream for disconnect", { connId: conn.id });
201
+ actor.rLog.warn({
202
+ msg: "missing sse stream for disconnect",
203
+ connId: conn.id,
204
+ });
194
205
  return;
195
206
  }
196
207
 
@@ -198,12 +209,13 @@ export function createGenericSseDriver(
198
209
  },
199
210
 
200
211
  getConnectionReadyState: (
201
- _actor: AnyActorInstance,
212
+ actor: AnyActorInstance,
202
213
  conn: AnyConn,
203
214
  ): ConnectionReadyState | undefined => {
204
215
  const stream = globalState.sseStreams.get(conn.id);
205
216
  if (!stream) {
206
- logger().warn("missing sse stream for getConnectionReadyState", {
217
+ actor.rLog.warn({
218
+ msg: "missing sse stream for getConnectionReadyState",
207
219
  connId: conn.id,
208
220
  });
209
221
  return undefined;