Skip to content
This repository was archived by the owner on Oct 22, 2025. It is now read-only.

Commit d30dcda

Browse files
committed
fix(inspector): allow connection to inspector when using engine driver (#1269)
### TL;DR Added granular control over inspector enablement for actors and managers, and improved inspector access token configuration. ### What changed? - Enhanced the inspector configuration to allow enabling/disabling the inspector separately for actors and managers - Added a `configureInspectorAccessToken` utility function to centralize token management - Modified the `isInspectorEnabled` function to check if the inspector is enabled for a specific context (actor or manager) - Updated the `ManagerDriver` interface to include a `getOrCreateInspectorAccessToken` method - Implemented the new method in various driver implementations - Added skeleton implementation for `configureInspectorAccessToken` in Cloudflare Workers - Updated router implementations to use the new context-specific inspector enablement checks - Set default inspector configurations for engine and Cloudflare Workers drivers ### How to test? 1. Configure a registry with different inspector settings for actors and managers: ```typescript const registry = new Registry({ inspector: { enabled: { actor: true, manager: false } } }); ``` 2. Verify that the inspector endpoints are accessible for actors but not for managers 3. Test that inspector access tokens are properly generated and configured ### Why make this change? This change provides more flexibility in how the inspector is configured, allowing users to enable inspection capabilities selectively for actors or managers based on their needs. It also centralizes and standardizes the inspector access token management, making the codebase more maintainable and consistent across different driver implementations.
1 parent fc1af01 commit d30dcda

File tree

12 files changed

+81
-21
lines changed

12 files changed

+81
-21
lines changed

packages/cloudflare-workers/src/actor-handler-do.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { ExecutionContext } from "hono";
33
import invariant from "invariant";
44
import type { ActorKey, ActorRouter, Registry, RunConfig } from "rivetkit";
55
import { createActorRouter, createClientWithDriver } from "rivetkit";
6-
import type { ActorDriver } from "rivetkit/driver-helpers";
6+
import type { ActorDriver, ManagerDriver } from "rivetkit/driver-helpers";
77
import { serializeEmptyPersistData } from "rivetkit/driver-helpers";
88
import { promiseWithResolvers } from "rivetkit/utils";
99
import {
@@ -121,6 +121,8 @@ export function createActorDurableObject(
121121
runConfig,
122122
);
123123

124+
configureInspectorAccessToken(registry.config, managerDriver);
125+
124126
// Create inline client
125127
const inlineClient = createClientWithDriver(managerDriver);
126128

@@ -187,3 +189,9 @@ export function createActorDurableObject(
187189
}
188190
};
189191
}
192+
function configureInspectorAccessToken(
193+
config: any,
194+
managerDriver: ManagerDriver,
195+
) {
196+
throw new Error("Function not implemented.");
197+
}

packages/rivetkit/src/actor/router.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import {
3434
type ActorInspectorRouterEnv,
3535
createActorInspectorRouter,
3636
} from "@/inspector/actor";
37-
import { secureInspector } from "@/inspector/utils";
37+
import { isInspectorEnabled, secureInspector } from "@/inspector/utils";
3838
import type { RunConfig } from "@/registry/run-config";
3939
import type { ActorDriver } from "./driver";
4040
import { InternalError } from "./errors";
@@ -206,7 +206,7 @@ export function createActorRouter(
206206
}
207207
});
208208

209-
if (runConfig.inspector.enabled) {
209+
if (isInspectorEnabled(runConfig, "actor")) {
210210
router.route(
211211
"/inspect",
212212
new Hono<ActorInspectorRouterEnv & { Bindings: ActorRouterBindings }>()

packages/rivetkit/src/driver-test-suite/mod.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { bundleRequire } from "bundle-require";
44
import invariant from "invariant";
55
import { describe } from "vitest";
66
import type { Transport } from "@/client/mod";
7+
import { configureInspectorAccessToken } from "@/inspector/utils";
78
import { createManagerRouter } from "@/manager/router";
89
import type { DriverConfig, Registry, RunConfig } from "@/mod";
910
import { RunConfigSchema } from "@/registry/run-config";
@@ -193,6 +194,7 @@ export async function createTestRuntime(
193194

194195
// Create router
195196
const managerDriver = driver.manager(registry.config, config);
197+
configureInspectorAccessToken(config, managerDriver);
196198
const { router } = createManagerRouter(
197199
registry.config,
198200
config,

packages/rivetkit/src/drivers/file-system/manager.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,6 @@ export class FileSystemManagerDriver implements ManagerDriver {
5757
this.#driverConfig = driverConfig;
5858

5959
if (runConfig.inspector.enabled) {
60-
if (!this.#runConfig.inspector.token()) {
61-
this.#runConfig.inspector.token = () =>
62-
this.#state.getOrCreateInspectorAccessToken();
63-
}
6460
const startedAt = new Date().toISOString();
6561
function transformActor(actorState: schema.ActorState): Actor {
6662
return {
@@ -317,4 +313,8 @@ export class FileSystemManagerDriver implements ManagerDriver {
317313
data: this.#state.storagePath,
318314
};
319315
}
316+
317+
getOrCreateInspectorAccessToken() {
318+
return this.#state.getOrCreateInspectorAccessToken();
319+
}
320320
}

packages/rivetkit/src/inspector/config.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,16 @@ const defaultCors: CorsOptions = {
5656

5757
export const InspectorConfigSchema = z
5858
.object({
59-
enabled: z.boolean().optional().default(defaultEnabled),
59+
enabled: z
60+
.boolean()
61+
.or(
62+
z.object({
63+
actor: z.boolean().optional().default(true),
64+
manager: z.boolean().optional().default(true),
65+
}),
66+
)
67+
.optional()
68+
.default(defaultEnabled),
6069
/** CORS configuration for the router. Uses Hono's CORS middleware options. */
6170
cors: z
6271
.custom<CorsOptions>()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export * from "./protocol/common";
22
export * from "./protocol/mod";
3+
export * from "./utils";

packages/rivetkit/src/inspector/utils.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import crypto from "node:crypto";
22
import { createMiddleware } from "hono/factory";
3+
import type { ManagerDriver } from "@/driver-helpers/mod";
34
import type { RunConfig } from "@/mod";
45
import type { RunConfigInput } from "@/registry/run-config";
56
import { inspectorLogger } from "./log";
@@ -28,10 +29,6 @@ export function compareSecrets(providedSecret: string, validSecret: string) {
2829

2930
export const secureInspector = (runConfig: RunConfig) =>
3031
createMiddleware(async (c, next) => {
31-
if (!runConfig.inspector.enabled) {
32-
return c.text("Inspector is not enabled", 503);
33-
}
34-
3532
const userToken = c.req.header("Authorization")?.replace("Bearer ", "");
3633
if (!userToken) {
3734
return c.text("Unauthorized", 401);
@@ -74,3 +71,25 @@ export function getInspectorUrl(runConfig: RunConfigInput | undefined) {
7471

7572
return url.href;
7673
}
74+
75+
export const isInspectorEnabled = (
76+
runConfig: RunConfig,
77+
context: "actor" | "manager",
78+
) => {
79+
if (typeof runConfig.inspector?.enabled === "boolean") {
80+
return runConfig.inspector.enabled;
81+
} else if (typeof runConfig.inspector?.enabled === "object") {
82+
return runConfig.inspector.enabled[context];
83+
}
84+
return false;
85+
};
86+
87+
export const configureInspectorAccessToken = (
88+
runConfig: RunConfig,
89+
managerDriver: ManagerDriver,
90+
) => {
91+
if (!runConfig.inspector?.token()) {
92+
const token = managerDriver.getOrCreateInspectorAccessToken();
93+
runConfig.inspector.token = () => token;
94+
}
95+
};

packages/rivetkit/src/manager/driver.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ export interface ManagerDriver {
4545
* @internal
4646
*/
4747
readonly inspector?: ManagerInspector;
48+
49+
/**
50+
* Get or create the inspector access token.
51+
* @internal
52+
* @returns creates or returns existing inspector access token
53+
*/
54+
getOrCreateInspectorAccessToken: () => string;
4855
}
4956

5057
export interface ManagerDisplayInformation {

packages/rivetkit/src/manager/router.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import type {
2727
TestInlineDriverCallResponse,
2828
} from "@/driver-test-suite/test-inline-client-driver";
2929
import { createManagerInspectorRouter } from "@/inspector/manager";
30-
import { secureInspector } from "@/inspector/utils";
30+
import { isInspectorEnabled, secureInspector } from "@/inspector/utils";
3131
import {
3232
type ActorsCreateRequest,
3333
ActorsCreateRequestSchema,
@@ -436,7 +436,7 @@ export function createManagerRouter(
436436
router as unknown as Hono,
437437
);
438438

439-
if (runConfig.inspector?.enabled) {
439+
if (isInspectorEnabled(runConfig, "manager")) {
440440
if (!managerDriver.inspector) {
441441
throw new Unsupported("inspector");
442442
}

packages/rivetkit/src/registry/mod.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { type Client, createClientWithDriver } from "@/client/client";
22
import { configureBaseLogger, configureDefaultLogger } from "@/common/log";
33
import { chooseDefaultDriver } from "@/drivers/default";
4-
import { getInspectorUrl } from "@/inspector/utils";
4+
import {
5+
configureInspectorAccessToken,
6+
getInspectorUrl,
7+
isInspectorEnabled,
8+
} from "@/inspector/utils";
59
import { createManagerRouter } from "@/manager/router";
610
import pkg from "../../package.json" with { type: "json" };
711
import {
@@ -58,11 +62,11 @@ export class Registry<A extends RegistryActors> {
5862

5963
// TODO: Find cleaner way of disabling by default
6064
if (driver.name === "engine") {
61-
config.inspector.enabled = false;
65+
config.inspector.enabled = { manager: false, actor: true };
6266
config.disableServer = true;
6367
}
6468
if (driver.name === "cloudflare-workers") {
65-
config.inspector.enabled = false;
69+
config.inspector.enabled = { manager: false, actor: true };
6670
config.disableServer = true;
6771
config.disableActorDriver = true;
6872
config.noWelcome = true;
@@ -76,6 +80,7 @@ export class Registry<A extends RegistryActors> {
7680

7781
// Create router
7882
const managerDriver = driver.manager(this.#config, config);
83+
configureInspectorAccessToken(config, managerDriver);
7984
const { router: hono } = createManagerRouter(
8085
this.#config,
8186
config,
@@ -92,7 +97,7 @@ export class Registry<A extends RegistryActors> {
9297
definitions: Object.keys(this.#config.use).length,
9398
...driverLog,
9499
});
95-
if (config.inspector?.enabled && managerDriver.inspector) {
100+
if (isInspectorEnabled(config, "manager") && managerDriver.inspector) {
96101
logger().info({ msg: "inspector ready", url: getInspectorUrl(config) });
97102
}
98103

@@ -106,8 +111,8 @@ export class Registry<A extends RegistryActors> {
106111
const padding = " ".repeat(Math.max(0, 13 - k.length));
107112
console.log(` - ${k}:${padding}${v}`);
108113
}
109-
if (config.inspector?.enabled && managerDriver.inspector) {
110-
console.log(` - Inspector: ${getInspectorUrl(config)}`);
114+
if (isInspectorEnabled(config, "manager") && managerDriver.inspector) {
115+
console.log(` - Inspector: ${getInspectorUrl(config)}`);
111116
}
112117
console.log();
113118
}

0 commit comments

Comments
 (0)