rivetkit 2.3.0-rc.11 → 2.3.0-rc.13

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 (123) hide show
  1. package/dist/browser/client.d.ts +407 -20
  2. package/dist/browser/client.js +101 -86
  3. package/dist/browser/client.js.map +1 -1
  4. package/dist/browser/inspector/client.js +12 -2
  5. package/dist/browser/inspector/client.js.map +1 -1
  6. package/dist/tsup/actor/errors.d.cts +1 -1
  7. package/dist/tsup/actor/errors.d.ts +1 -1
  8. package/dist/tsup/agent-os/index.cjs +66 -3
  9. package/dist/tsup/agent-os/index.cjs.map +1 -1
  10. package/dist/tsup/agent-os/index.d.cts +404 -17
  11. package/dist/tsup/agent-os/index.d.ts +404 -17
  12. package/dist/tsup/agent-os/index.js +66 -3
  13. package/dist/tsup/agent-os/index.js.map +1 -1
  14. package/dist/tsup/{chunk-WXYWDLJY.js → chunk-33YE6XCI.js} +4 -4
  15. package/dist/tsup/{chunk-2NXFKPRB.cjs → chunk-7OR3CHD5.cjs} +10 -10
  16. package/dist/tsup/{chunk-2NXFKPRB.cjs.map → chunk-7OR3CHD5.cjs.map} +1 -1
  17. package/dist/tsup/{chunk-LW5HNCWD.cjs → chunk-7XQCARVY.cjs} +3 -3
  18. package/dist/tsup/{chunk-LW5HNCWD.cjs.map → chunk-7XQCARVY.cjs.map} +1 -1
  19. package/dist/tsup/{chunk-GX6W4MW3.cjs → chunk-BSPS6NSN.cjs} +5 -5
  20. package/dist/tsup/{chunk-GX6W4MW3.cjs.map → chunk-BSPS6NSN.cjs.map} +1 -1
  21. package/dist/tsup/{chunk-T3VCJ4PV.js → chunk-DPIMKYNB.js} +61 -2
  22. package/dist/tsup/chunk-DPIMKYNB.js.map +1 -0
  23. package/dist/tsup/{chunk-XG25CGSW.cjs → chunk-E5CLYAUZ.cjs} +146 -143
  24. package/dist/tsup/chunk-E5CLYAUZ.cjs.map +1 -0
  25. package/dist/tsup/{chunk-RDBGKI66.cjs → chunk-EBWOJRCC.cjs} +22 -5
  26. package/dist/tsup/chunk-EBWOJRCC.cjs.map +1 -0
  27. package/dist/tsup/{chunk-YRQ4F5CD.js → chunk-HHNYEQD3.js} +6 -6
  28. package/dist/tsup/chunk-HHNYEQD3.js.map +1 -0
  29. package/dist/tsup/{chunk-4FP4FFB5.js → chunk-IOUSQVXI.js} +21 -4
  30. package/dist/tsup/chunk-IOUSQVXI.js.map +1 -0
  31. package/dist/tsup/{chunk-LNP7Q6I6.cjs → chunk-ISDKSSYR.cjs} +4 -4
  32. package/dist/tsup/{chunk-LNP7Q6I6.cjs.map → chunk-ISDKSSYR.cjs.map} +1 -1
  33. package/dist/tsup/{chunk-TTLUIDVH.js → chunk-J72WHUBC.js} +12 -9
  34. package/dist/tsup/chunk-J72WHUBC.js.map +1 -0
  35. package/dist/tsup/{chunk-Y3JBOFBG.cjs → chunk-KWABEUUA.cjs} +10 -10
  36. package/dist/tsup/chunk-KWABEUUA.cjs.map +1 -0
  37. package/dist/tsup/{chunk-XCDCURZ4.cjs → chunk-NIY3RSPX.cjs} +62 -3
  38. package/dist/tsup/chunk-NIY3RSPX.cjs.map +1 -0
  39. package/dist/tsup/{chunk-3P2JUHWJ.js → chunk-T44AVAGW.js} +2 -2
  40. package/dist/tsup/{chunk-GRFBV2U7.js → chunk-TCXEM6PA.js} +2 -2
  41. package/dist/tsup/{chunk-KRC4L3YB.js → chunk-ZI5CNA2Z.js} +2 -2
  42. package/dist/tsup/client/mod.cjs +7 -7
  43. package/dist/tsup/client/mod.cjs.map +1 -1
  44. package/dist/tsup/client/mod.d.cts +3 -3
  45. package/dist/tsup/client/mod.d.ts +3 -3
  46. package/dist/tsup/client/mod.js +6 -6
  47. package/dist/tsup/common/log.cjs +2 -2
  48. package/dist/tsup/common/log.js +1 -1
  49. package/dist/tsup/common/websocket.cjs +3 -3
  50. package/dist/tsup/common/websocket.js +2 -2
  51. package/dist/tsup/{config-De5UVu0V.d.ts → config-BxWAw3iH.d.ts} +476 -20
  52. package/dist/tsup/{config-CTwe3WwC.d.cts → config-CZQQ-mso.d.cts} +476 -20
  53. package/dist/tsup/{context-Dmj477Uh.d.cts → context-Bw7xq8w3.d.cts} +1 -1
  54. package/dist/tsup/{context-DPHISlUi.d.ts → context-D8QA76sV.d.ts} +1 -1
  55. package/dist/tsup/dynamic/mod.cjs +2 -2
  56. package/dist/tsup/dynamic/mod.d.cts +2 -2
  57. package/dist/tsup/dynamic/mod.d.ts +2 -2
  58. package/dist/tsup/dynamic/mod.js +1 -1
  59. package/dist/tsup/inspector/mod.cjs +5 -5
  60. package/dist/tsup/inspector/mod.js +4 -4
  61. package/dist/tsup/inspector-tab/mod.cjs +173 -0
  62. package/dist/tsup/inspector-tab/mod.cjs.map +1 -0
  63. package/dist/tsup/inspector-tab/mod.d.cts +250 -0
  64. package/dist/tsup/inspector-tab/mod.d.ts +250 -0
  65. package/dist/tsup/inspector-tab/mod.js +173 -0
  66. package/dist/tsup/inspector-tab/mod.js.map +1 -0
  67. package/dist/tsup/mod.cjs +341 -138
  68. package/dist/tsup/mod.cjs.map +1 -1
  69. package/dist/tsup/mod.d.cts +4 -4
  70. package/dist/tsup/mod.d.ts +4 -4
  71. package/dist/tsup/mod.js +277 -74
  72. package/dist/tsup/mod.js.map +1 -1
  73. package/dist/tsup/test/mod.cjs +10 -10
  74. package/dist/tsup/test/mod.d.cts +2 -2
  75. package/dist/tsup/test/mod.d.ts +2 -2
  76. package/dist/tsup/test/mod.js +6 -6
  77. package/dist/tsup/{utils-DVekpm4I.d.ts → utils-DQosb24I.d.cts} +1 -1
  78. package/dist/tsup/{utils-DVekpm4I.d.cts → utils-DQosb24I.d.ts} +1 -1
  79. package/dist/tsup/utils.cjs +2 -2
  80. package/dist/tsup/utils.d.cts +1 -1
  81. package/dist/tsup/utils.d.ts +1 -1
  82. package/dist/tsup/utils.js +1 -1
  83. package/dist/tsup/workflow/mod.cjs +11 -11
  84. package/dist/tsup/workflow/mod.cjs.map +1 -1
  85. package/dist/tsup/workflow/mod.d.cts +4 -4
  86. package/dist/tsup/workflow/mod.d.ts +4 -4
  87. package/dist/tsup/workflow/mod.js +5 -5
  88. package/package.json +19 -9
  89. package/src/actor/config.ts +111 -10
  90. package/src/actor/definition.ts +6 -5
  91. package/src/actor/instance/mod.ts +4 -4
  92. package/src/actor/mod.ts +2 -0
  93. package/src/client/actor-common.ts +24 -27
  94. package/src/client/actor-handle.ts +2 -1
  95. package/src/common/engine.ts +28 -1
  96. package/src/common/utils.ts +1 -1
  97. package/src/devtools-loader/index.ts +4 -7
  98. package/src/devtools-loader/serve-devtools.ts +26 -0
  99. package/src/drivers/engine/actor-driver.ts +16 -5
  100. package/src/engine-client/actor-http-client.ts +2 -2
  101. package/src/engine-client/api-endpoints.ts +5 -1
  102. package/src/engine-client/ws-proxy.ts +5 -0
  103. package/src/inspector-tab/mod.ts +315 -0
  104. package/src/registry/config/index.ts +40 -16
  105. package/src/registry/index.ts +143 -62
  106. package/src/registry/napi-runtime.ts +6 -0
  107. package/src/registry/native.ts +170 -27
  108. package/src/registry/process-metrics.ts +16 -4
  109. package/src/registry/runtime.ts +26 -0
  110. package/src/registry/wasm-runtime.ts +16 -1
  111. package/src/utils/env-vars.ts +6 -0
  112. package/dist/tsup/chunk-4FP4FFB5.js.map +0 -1
  113. package/dist/tsup/chunk-RDBGKI66.cjs.map +0 -1
  114. package/dist/tsup/chunk-T3VCJ4PV.js.map +0 -1
  115. package/dist/tsup/chunk-TTLUIDVH.js.map +0 -1
  116. package/dist/tsup/chunk-XCDCURZ4.cjs.map +0 -1
  117. package/dist/tsup/chunk-XG25CGSW.cjs.map +0 -1
  118. package/dist/tsup/chunk-Y3JBOFBG.cjs.map +0 -1
  119. package/dist/tsup/chunk-YRQ4F5CD.js.map +0 -1
  120. /package/dist/tsup/{chunk-WXYWDLJY.js.map → chunk-33YE6XCI.js.map} +0 -0
  121. /package/dist/tsup/{chunk-3P2JUHWJ.js.map → chunk-T44AVAGW.js.map} +0 -0
  122. /package/dist/tsup/{chunk-GRFBV2U7.js.map → chunk-TCXEM6PA.js.map} +0 -0
  123. /package/dist/tsup/{chunk-KRC4L3YB.js.map → chunk-ZI5CNA2Z.js.map} +0 -0
@@ -0,0 +1,315 @@
1
+ /**
2
+ * Type and schema declarations for custom Rivet inspector tabs.
3
+ *
4
+ * Everything here is **derived from runtime Zod schemas** that the
5
+ * dashboard and rivetkit itself use, so the published types cannot
6
+ * drift from the wire format. There are three sources of truth:
7
+ *
8
+ * 1. The `inspector.tabs[]` actor-config Zod schemas in
9
+ * `../actor/config.ts` — re-exported below. These validate the
10
+ * authoring surface (`defineActor({ inspector: { tabs: [...] } })`).
11
+ * 2. The dashboard ↔ tab postMessage envelopes defined in this file.
12
+ * The inspector-ui SPA (`frontend/apps/inspector-ui/src/bridge.ts`)
13
+ * imports the same schemas to validate messages at runtime, so any
14
+ * change here lands on both ends in lockstep.
15
+ * 3. The inspector HTTP endpoint response schemas defined in this
16
+ * file. The dashboard parses every response through them; if the
17
+ * Rust handler ever emits a different shape, the dashboard fails
18
+ * loudly at the parse step instead of silently casting `unknown`.
19
+ *
20
+ * Tab bundles import these types for autocomplete and compile-time
21
+ * safety:
22
+ *
23
+ * ```ts
24
+ * import type {
25
+ * ShellToTabMessage,
26
+ * TabToShellMessage,
27
+ * V1Init,
28
+ * InspectorStateResponse,
29
+ * } from "rivetkit/inspector-tab";
30
+ * ```
31
+ */
32
+
33
+ import { z } from "zod";
34
+
35
+ // ============================================================================
36
+ // Re-exported from `../actor/config.ts` — the authoring schema for
37
+ // `defineActor({ inspector: { tabs: [...] } })`.
38
+ // ============================================================================
39
+
40
+ export {
41
+ ActorInspectorConfigSchema,
42
+ BUILTIN_INSPECTOR_TAB_IDS,
43
+ BuiltinInspectorTabIdSchema,
44
+ CustomInspectorTabEntrySchema,
45
+ HideInspectorTabEntrySchema,
46
+ InspectorTabEntrySchema,
47
+ } from "../actor/config";
48
+ export type { ActorInspectorConfig } from "../actor/config";
49
+
50
+ import type {
51
+ CustomInspectorTabEntrySchema,
52
+ HideInspectorTabEntrySchema,
53
+ InspectorTabEntrySchema,
54
+ } from "../actor/config";
55
+
56
+ /** One entry in the actor's `inspector.tabs[]` declaration. */
57
+ export type ActorInspectorTabEntry = z.input<typeof InspectorTabEntrySchema>;
58
+ /** A custom-tab entry — adds a new tab to the dashboard strip. */
59
+ export type ActorCustomInspectorTabEntry = z.input<
60
+ typeof CustomInspectorTabEntrySchema
61
+ >;
62
+ /** A hide modifier — removes a built-in tab from the strip. */
63
+ export type ActorHideInspectorTabEntry = z.input<
64
+ typeof HideInspectorTabEntrySchema
65
+ >;
66
+ /** Union of the six built-in inspector tab ids. */
67
+ export type BuiltinInspectorTabId =
68
+ | "workflow"
69
+ | "database"
70
+ | "state"
71
+ | "queue"
72
+ | "connections"
73
+ | "console";
74
+
75
+ // ============================================================================
76
+ // Dashboard ↔ tab postMessage envelope (source of truth).
77
+ //
78
+ // These Zod schemas are imported by `frontend/apps/inspector-ui/src/bridge.ts`
79
+ // and used to validate inbound messages at runtime. Changes here flow to
80
+ // both sides in a single commit.
81
+ // ============================================================================
82
+
83
+ /** Public tab descriptor that crosses the dashboard ↔ inspector-ui bridge. */
84
+ export const InspectorTabDescriptorSchema = z.object({
85
+ id: z.string(),
86
+ label: z.string(),
87
+ icon: z.string(),
88
+ /**
89
+ * `true` for author-shipped custom tabs; absent or `false` for
90
+ * built-in tabs the SPA renders. Lets the dashboard route the
91
+ * iframe `src` to `/inspector/custom-tabs/<id>/` for custom tabs and
92
+ * `/inspector/ui/` for built-ins without the dashboard needing to
93
+ * know which ids are built-in.
94
+ */
95
+ isCustom: z.boolean().optional(),
96
+ });
97
+
98
+ /**
99
+ * Initial handshake from the dashboard. Sent on first mount and again on
100
+ * every token refresh. Tabs MUST accept late `init` messages and replace
101
+ * the cached token.
102
+ */
103
+ export const V1InitSchema = z.object({
104
+ type: z.literal("init"),
105
+ v: z.literal(1),
106
+ /** The actor this tab is mounted for. */
107
+ actorId: z.string(),
108
+ /**
109
+ * Per-actor inspector bearer token. Tabs include it as
110
+ * `Authorization: Bearer ${authToken}` on every authenticated fetch.
111
+ */
112
+ authToken: z.string(),
113
+ /**
114
+ * Outer Rivet API token. Optional; not required for inspector HTTP
115
+ * routes but available to tabs that want to call the engine REST API.
116
+ */
117
+ rivetToken: z.string().optional(),
118
+ /**
119
+ * The tab id the dashboard wants active at mount time. Multi-view
120
+ * tabs may read this to seed their initial route; most tabs ignore it.
121
+ */
122
+ activeTab: z.string().optional(),
123
+ /**
124
+ * Dashboard's currently active theme. Tabs that use the shared
125
+ * stylesheet (`/inspector/tab.css`) mirror it by toggling the `dark`
126
+ * class on `<html>`. Optional for backwards compatibility — tabs
127
+ * should default to `"dark"` if absent (the dashboard pinned dark
128
+ * mode before this field was added).
129
+ */
130
+ theme: z.enum(["light", "dark"]).optional(),
131
+ });
132
+
133
+ /**
134
+ * Dashboard tells the inspector-ui SPA which built-in tab to render. Not
135
+ * sent to custom tabs — when the user activates a custom tab the
136
+ * dashboard navigates the outer iframe to a different `src`.
137
+ */
138
+ export const V1SetActiveTabSchema = z.object({
139
+ type: z.literal("set-active-tab"),
140
+ v: z.literal(1),
141
+ tab: z.string(),
142
+ });
143
+
144
+ /**
145
+ * Tab → dashboard. Sent once after the message listener is registered.
146
+ * The dashboard hides the "Connecting to inspector…" overlay on receipt;
147
+ * if it never arrives the overlay times out after 8 s.
148
+ */
149
+ export const V1ReadySchema = z.object({
150
+ type: z.literal("ready"),
151
+ v: z.literal(1),
152
+ });
153
+
154
+ /**
155
+ * Tab → dashboard. Sent when the tab gets a 401 on an inspector data
156
+ * call. The dashboard refreshes the token and re-issues `v1Init`.
157
+ */
158
+ export const V1TokenRefreshNeededSchema = z.object({
159
+ type: z.literal("token-refresh-needed"),
160
+ v: z.literal(1),
161
+ });
162
+
163
+ /**
164
+ * Emitted by the inspector-ui SPA to tell the dashboard which tabs to
165
+ * render in the strip. Custom tab bundles do NOT emit this — only the
166
+ * SPA does.
167
+ */
168
+ export const V1TabsAvailableSchema = z.object({
169
+ type: z.literal("tabs-available"),
170
+ v: z.literal(1),
171
+ tabs: z.array(InspectorTabDescriptorSchema),
172
+ });
173
+
174
+ /** Discriminated union of messages a tab can RECEIVE from the dashboard. */
175
+ export const ShellToTabMessageSchema = z.discriminatedUnion("type", [
176
+ V1InitSchema,
177
+ V1SetActiveTabSchema,
178
+ ]);
179
+
180
+ /** Discriminated union of messages a tab can SEND to the dashboard. */
181
+ export const TabToShellMessageSchema = z.discriminatedUnion("type", [
182
+ V1ReadySchema,
183
+ V1TabsAvailableSchema,
184
+ V1TokenRefreshNeededSchema,
185
+ ]);
186
+
187
+ export type InspectorTabDescriptor = z.infer<
188
+ typeof InspectorTabDescriptorSchema
189
+ >;
190
+ export type V1Init = z.infer<typeof V1InitSchema>;
191
+ export type V1SetActiveTab = z.infer<typeof V1SetActiveTabSchema>;
192
+ export type V1Ready = z.infer<typeof V1ReadySchema>;
193
+ export type V1TokenRefreshNeeded = z.infer<typeof V1TokenRefreshNeededSchema>;
194
+ export type V1TabsAvailable = z.infer<typeof V1TabsAvailableSchema>;
195
+ export type ShellToTabMessage = z.infer<typeof ShellToTabMessageSchema>;
196
+ export type TabToShellMessage = z.infer<typeof TabToShellMessageSchema>;
197
+
198
+ /** Stable envelope protocol version. Bump only when introducing a v2 shape. */
199
+ export const POSTMESSAGE_PROTOCOL_VERSION = 1;
200
+
201
+ /** URL query parameters the dashboard sets on the tab iframe `src`. */
202
+ export const SHELL_ORIGIN_PARAM = "shellOrigin";
203
+ export const ACTOR_ID_PARAM = "actorId";
204
+
205
+ // ============================================================================
206
+ // Inspector HTTP endpoint response schemas (source of truth).
207
+ //
208
+ // The dashboard parses every authenticated inspector response through
209
+ // these schemas (`frontend/src/components/actors/actor-inspector-context.tsx`).
210
+ // If the Rust handler emits a different shape the parse fails and the
211
+ // dashboard surfaces an error — drift is loud.
212
+ // ============================================================================
213
+
214
+ /** `GET /inspector/state` response shape. */
215
+ export const InspectorStateResponseSchema = z.object({
216
+ /** Current actor state (whatever shape the actor declared). */
217
+ state: z.unknown(),
218
+ /**
219
+ * `false` when the actor did not declare any state — `state` is then
220
+ * `null` and `PATCH /inspector/state` returns an error.
221
+ */
222
+ isStateEnabled: z.boolean(),
223
+ });
224
+
225
+ /** `POST /inspector/action/<name>` request body. */
226
+ export const InspectorActionRequestSchema = z
227
+ .object({
228
+ /** Positional arguments. Mutually exclusive with `properties`. */
229
+ args: z.array(z.unknown()).optional(),
230
+ /** Keyed arguments. Mutually exclusive with `args`. */
231
+ properties: z.record(z.string(), z.unknown()).optional(),
232
+ })
233
+ .refine(
234
+ (body) => !(body.args !== undefined && body.properties !== undefined),
235
+ "Use either `args` or `properties`, not both",
236
+ );
237
+
238
+ /** `POST /inspector/action/<name>` response shape. */
239
+ export const InspectorActionResponseSchema = z.object({
240
+ output: z.unknown(),
241
+ });
242
+
243
+ /** `GET /inspector/rpcs` response shape — the list of action names. */
244
+ export const InspectorRpcsResponseSchema = z.object({
245
+ rpcs: z.array(z.string()),
246
+ });
247
+
248
+ /** One connection record in `GET /inspector/connections`. */
249
+ export const InspectorConnectionSchema = z.object({
250
+ connectionType: z.string().nullable(),
251
+ id: z.string(),
252
+ details: z.object({
253
+ connectionType: z.string().nullable(),
254
+ params: z.unknown(),
255
+ stateEnabled: z.boolean(),
256
+ state: z.unknown(),
257
+ subscriptions: z.number(),
258
+ isHibernatable: z.boolean(),
259
+ }),
260
+ });
261
+
262
+ /** `GET /inspector/connections` response shape. */
263
+ export const InspectorConnectionsResponseSchema = z.object({
264
+ connections: z.array(InspectorConnectionSchema),
265
+ });
266
+
267
+ /** One queued message in `GET /inspector/queue`. */
268
+ export const InspectorQueueMessageSchema = z.object({
269
+ id: z.string(),
270
+ name: z.string(),
271
+ createdAtMs: z.number(),
272
+ });
273
+
274
+ /** `GET /inspector/queue` response shape. */
275
+ export const InspectorQueueResponseSchema = z.object({
276
+ size: z.number(),
277
+ maxSize: z.number(),
278
+ /** `true` if `?limit=N` truncated the message list below `size`. */
279
+ truncated: z.boolean(),
280
+ messages: z.array(InspectorQueueMessageSchema),
281
+ });
282
+
283
+ /** `GET /inspector/tab-config` response shape. */
284
+ export const InspectorTabConfigResponseSchema = z.object({
285
+ tabs: z.array(
286
+ z.object({
287
+ id: z.string(),
288
+ label: z.string().optional(),
289
+ icon: z.string().nullable().optional(),
290
+ hidden: z.boolean().optional(),
291
+ }),
292
+ ),
293
+ });
294
+
295
+ export type InspectorStateResponse = z.infer<
296
+ typeof InspectorStateResponseSchema
297
+ >;
298
+ export type InspectorActionRequest = z.infer<
299
+ typeof InspectorActionRequestSchema
300
+ >;
301
+ export type InspectorActionResponse = z.infer<
302
+ typeof InspectorActionResponseSchema
303
+ >;
304
+ export type InspectorRpcsResponse = z.infer<typeof InspectorRpcsResponseSchema>;
305
+ export type InspectorConnection = z.infer<typeof InspectorConnectionSchema>;
306
+ export type InspectorConnectionsResponse = z.infer<
307
+ typeof InspectorConnectionsResponseSchema
308
+ >;
309
+ export type InspectorQueueMessage = z.infer<typeof InspectorQueueMessageSchema>;
310
+ export type InspectorQueueResponse = z.infer<
311
+ typeof InspectorQueueResponseSchema
312
+ >;
313
+ export type InspectorTabConfigResponse = z.infer<
314
+ typeof InspectorTabConfigResponseSchema
315
+ >;
@@ -10,7 +10,7 @@ import {
10
10
  queueMetadataKey,
11
11
  workflowStoragePrefix,
12
12
  } from "@/actor/keys";
13
- import { ENGINE_ENDPOINT } from "@/common/engine";
13
+ import { buildEngineEndpoint, ENGINE_HOST, ENGINE_PORT } from "@/common/engine";
14
14
  import { type Logger, LogLevelSchema } from "@/common/log";
15
15
  import { VERSION } from "@/utils";
16
16
  import { tryParseEndpoint } from "@/utils/endpoint-parser";
@@ -20,6 +20,8 @@ import {
20
20
  getRivetkitRuntime,
21
21
  getRivetNamespace,
22
22
  getRivetRunEngine,
23
+ getRivetRunEngineHost,
24
+ getRivetRunEnginePort,
23
25
  getRivetRunEngineVersion,
24
26
  getRivetToken,
25
27
  isDev,
@@ -224,6 +226,27 @@ export const RegistryConfigSchema = z
224
226
  * Starts the full Rust engine process locally.
225
227
  */
226
228
  startEngine: z.boolean().default(() => getRivetRunEngine()),
229
+ /**
230
+ * @experimental
231
+ *
232
+ * Host to bind the spawned local engine process to.
233
+ */
234
+ engineHost: z
235
+ .string()
236
+ .optional()
237
+ .default(() => getRivetRunEngineHost() ?? ENGINE_HOST),
238
+ /**
239
+ * @experimental
240
+ *
241
+ * Port to bind the spawned local engine process to.
242
+ */
243
+ enginePort: z
244
+ .number()
245
+ .int()
246
+ .min(1)
247
+ .max(65_535)
248
+ .optional()
249
+ .default(() => getRivetRunEnginePort() ?? ENGINE_PORT),
227
250
  /** @experimental */
228
251
  engineVersion: z
229
252
  .string()
@@ -262,17 +285,12 @@ export const RegistryConfigSchema = z
262
285
  .object({
263
286
  /**
264
287
  * Wait this many milliseconds for the serve promise to resolve
265
- * after calling `CoreRegistry::shutdown()`. Defaults to 30s,
266
- * matching Kubernetes `terminationGracePeriodSeconds`.
288
+ * after calling `CoreRegistry::shutdown()`. Defaults to the
289
+ * engine-provided actor stop threshold once the envoy connects.
267
290
  *
268
291
  * Must be long enough for rivetkit-core to drain the envoy.
269
292
  */
270
- gracePeriodMs: z
271
- .number()
272
- .int()
273
- .min(1_000)
274
- .optional()
275
- .default(30_000),
293
+ gracePeriodMs: z.number().int().min(1_000).optional(),
276
294
  /**
277
295
  * If true, rivetkit will not install SIGINT/SIGTERM handlers.
278
296
  * Use when the host application owns signal policy and will
@@ -282,7 +300,6 @@ export const RegistryConfigSchema = z
282
300
  })
283
301
  .optional()
284
302
  .default(() => ({
285
- gracePeriodMs: 30_000,
286
303
  disableSignalHandlers: false,
287
304
  })),
288
305
  })
@@ -318,7 +335,9 @@ export const RegistryConfigSchema = z
318
335
  })
319
336
  : undefined;
320
337
 
321
- // Can't start a local engine and connect to a remote endpoint.
338
+ // RIVET_ENDPOINT configures what RivetKit connects to. Use
339
+ // engineHost/enginePort (or RIVET_RUN_ENGINE_HOST/PORT) to control the
340
+ // spawned local engine bind address.
322
341
  if (config.startEngine && parsedEndpoint) {
323
342
  ctx.addIssue({
324
343
  code: "custom",
@@ -335,12 +354,17 @@ export const RegistryConfigSchema = z
335
354
  });
336
355
  }
337
356
 
338
- // Flatten the endpoint and apply defaults for namespace/token
339
- // If startEngine is enabled, set endpoint to the engine endpoint.
357
+ // Flatten the endpoint and apply defaults for namespace/token.
358
+ const localEngineEndpoint = buildEngineEndpoint(
359
+ config.engineHost,
360
+ config.enginePort,
361
+ );
340
362
  const endpoint = config.startEngine
341
- ? ENGINE_ENDPOINT
363
+ ? localEngineEndpoint
342
364
  : (parsedEndpoint?.endpoint ??
343
- (isDevEnv ? ENGINE_ENDPOINT : undefined));
365
+ (isDevEnv
366
+ ? buildEngineEndpoint(ENGINE_HOST, ENGINE_PORT)
367
+ : undefined));
344
368
  const validateServerlessEndpoint = Boolean(
345
369
  config.startEngine || parsedEndpoint,
346
370
  );
@@ -373,7 +397,7 @@ export const RegistryConfigSchema = z
373
397
  // In dev mode, clients connect directly to the local Rivet Engine.
374
398
  const publicEndpoint =
375
399
  parsedPublicEndpoint?.endpoint ??
376
- (isDevEnv && config.startEngine ? ENGINE_ENDPOINT : undefined);
400
+ (isDevEnv && config.startEngine ? endpoint : undefined);
377
401
  // We extract publicNamespace to validate that it matches the backend
378
402
  // namespace (see validation above), not for functional use.
379
403
  const publicNamespace = parsedPublicEndpoint?.namespace;