Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/next-js/src/app/api/registry/[...all]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ const server = registry.createServer({
// It should match the path in your Next.js API route
// For example, if your API route is at /api/registry/[...all], this should be "/api/registry"
basePath: "/api/registry",
studio: {
// Tell RivetKit Studio where to find RivetKit Registry
inspector: {
// Tell RivetKit Inspector where to find RivetKit Registry
defaultEndpoint: "http://localhost:3000/api/registry",
},
});
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@
"on-change": "^5.0.1",
"p-retry": "^6.2.1",
"zod": "^3.25.76",
"@rivetkit/engine-runner": "https://pkg.pr.new/rivet-gg/engine/@rivetkit/engine-runner@4b0f765"
"@rivetkit/engine-runner": "https://pkg.pr.new/rivet-gg/engine/@rivetkit/engine-runner@21dd4b4"
},
"devDependencies": {
"@hono/node-server": "^1.18.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/actor/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ export function createActorRouter(
}
});

if (runConfig.studio.enabled) {
if (runConfig.inspector.enabled) {
router.route(
"/inspect",
new Hono<ActorInspectorRouterEnv & { Bindings: ActorRouterBindings }>()
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/driver-test-suite/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export async function createTestRuntime(
const config: RunConfig = RunConfigSchema.parse({
driver,
getUpgradeWebSocket: () => upgradeWebSocket!,
studio: {
inspector: {
enabled: true,
token: () => "token",
},
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/drivers/engine/actor-driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,11 @@ export class EngineActorDriver implements ActorDriver {
endpoint: config.endpoint,
pegboardEndpoint: config.pegboardEndpoint,
namespace: config.namespace,
addresses: config.addresses,
totalSlots: config.totalSlots,
runnerName: config.runnerName,
runnerKey: config.runnerKey,
metadata: {
inspectorToken: this.#runConfig.studio.token(),
inspectorToken: this.#runConfig.inspector.token(),
},
prepopulateActorNames: Object.fromEntries(
Object.keys(this.#registryConfig.use).map((name) => [
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/drivers/engine/manager-driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ export class EngineManagerDriver implements ManagerDriver {
constructor(config: Config, runConfig: RunConfig) {
this.#config = config;
this.#runConfig = runConfig;
if (!this.#runConfig.studio.token()) {
if (!this.#runConfig.inspector.token()) {
const token = generateRandomString();
this.#runConfig.studio.token = () => token;
this.#runConfig.inspector.token = () => token;
}
this.#importWebSocketPromise = importWebSocket();
}
Expand Down Expand Up @@ -365,7 +365,7 @@ function buildGuardHeadersForHttp(
// Add guard-specific headers
headers.set("x-rivet-target", "actor");
headers.set("x-rivet-actor", actorId);
headers.set("x-rivet-addr", "main");
headers.set("x-rivet-port", "main");
return headers;
}

Expand All @@ -378,7 +378,7 @@ function buildGuardHeadersForWebSocket(
const headers: Record<string, string> = {};
headers["x-rivet-target"] = "actor";
headers["x-rivet-actor"] = actorId;
headers["x-rivet-addr"] = "main";
headers["x-rivet-port"] = "main";
headers[HEADER_EXPOSE_INTERNAL_ERROR] = "true";
headers[HEADER_ENCODING] = encoding;
if (params) {
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/drivers/file-system/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ export class FileSystemManagerDriver implements ManagerDriver {
this.#state = state;
this.#driverConfig = driverConfig;

if (runConfig.studio.enabled) {
if (!this.#runConfig.studio.token()) {
this.#runConfig.studio.token = () =>
if (runConfig.inspector.enabled) {
if (!this.#runConfig.inspector.token()) {
this.#runConfig.inspector.token = () =>
this.#state.getOrCreateInspectorAccessToken();
}
const startedAt = new Date().toISOString();
Expand Down
14 changes: 7 additions & 7 deletions packages/core/src/inspector/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { getEnvUniversal } from "@/utils";
type CorsOptions = NonNullable<Parameters<typeof cors>[0]>;

const defaultTokenFn = () => {
const envToken = getEnvUniversal("RIVETKIT_STUDIO_TOKEN");
const envToken = getEnvUniversal("RIVETKIT_INSPECTOR_TOKEN");

if (envToken) {
return envToken;
Expand All @@ -18,19 +18,19 @@ const defaultTokenFn = () => {
const defaultEnabled = () => {
return (
getEnvUniversal("NODE_ENV") !== "production" ||
!getEnvUniversal("RIVETKIT_STUDIO_DISABLE")
!getEnvUniversal("RIVETKIT_INSPECTOR_DISABLE")
);
};

const defaultStudioOrigins = [
const defaultInspectorOrigins = [
"http://localhost:43708",
"https://studio.rivet.gg",
];

const defaultCors: CorsOptions = {
origin: (origin) => {
if (
defaultStudioOrigins.includes(origin) ||
defaultInspectorOrigins.includes(origin) ||
(origin.startsWith("https://") && origin.endsWith("rivet-gg.vercel.app"))
) {
return origin;
Expand Down Expand Up @@ -59,7 +59,7 @@ export const InspectorConfigSchema = z
.default(() => defaultCors),

/**
* Token used to access the Studio.
* Token used to access the Inspector.
*/
token: z
.function()
Expand All @@ -68,9 +68,9 @@ export const InspectorConfigSchema = z
.default(() => defaultTokenFn),

/**
* Default RivetKit server endpoint for Rivet Studio to connect to. This should be the same endpoint as what you use for your Rivet client to connect to RivetKit.
* Default RivetKit server endpoint for Rivet Inspector to connect to. This should be the same endpoint as what you use for your Rivet client to connect to RivetKit.
*
* This is a convenience property just for printing out the studio URL.
* This is a convenience property just for printing out the inspector URL.
*/
defaultEndpoint: z.string().optional(),
})
Expand Down
16 changes: 8 additions & 8 deletions packages/core/src/inspector/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function compareSecrets(providedSecret: string, validSecret: string) {

export const secureInspector = (runConfig: RunConfig) =>
createMiddleware(async (c, next) => {
if (!runConfig.studio.enabled) {
if (!runConfig.inspector.enabled) {
return c.text("Inspector is not enabled", 503);
}

Expand All @@ -37,7 +37,7 @@ export const secureInspector = (runConfig: RunConfig) =>
return c.text("Unauthorized", 401);
}

const inspectorToken = runConfig.studio.token?.();
const inspectorToken = runConfig.inspector.token?.();
if (!inspectorToken) {
return c.text("Unauthorized", 401);
}
Expand All @@ -50,16 +50,16 @@ export const secureInspector = (runConfig: RunConfig) =>
await next();
});

export function getStudioUrl(runConfig: RunConfigInput | undefined) {
if (!runConfig?.studio?.enabled) {
export function getInspectorUrl(runConfig: RunConfigInput | undefined) {
if (!runConfig?.inspector?.enabled) {
return "disabled";
}

const accessToken = runConfig?.studio?.token?.();
const accessToken = runConfig?.inspector?.token?.();

if (!accessToken) {
inspectorLogger().warn(
"Studio Token is not set, but Studio is enabled. Please set it in the run configuration `inspector.token` or via `RIVETKIT_STUDIO_TOKEN` environment variable. Studio will not be accessible.",
"Inspector Token is not set, but Inspector is enabled. Please set it in the run configuration `inspector.token` or via `RIVETKIT_INSPECTOR_TOKEN` environment variable. Inspector will not be accessible.",
);
return "disabled";
}
Expand All @@ -68,8 +68,8 @@ export function getStudioUrl(runConfig: RunConfigInput | undefined) {

url.searchParams.set("t", accessToken);

if (runConfig?.studio?.defaultEndpoint) {
url.searchParams.set("u", runConfig.studio.defaultEndpoint);
if (runConfig?.inspector?.defaultEndpoint) {
url.searchParams.set("u", runConfig.inspector.defaultEndpoint);
}

return url.href;
Expand Down
38 changes: 19 additions & 19 deletions packages/core/src/manager/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export function createManagerRouter(

router.use("*", loggerMiddleware(logger()));

if (runConfig.cors || runConfig.studio?.cors) {
if (runConfig.cors || runConfig.inspector?.cors) {
router.use("*", async (c, next) => {
// Don't apply to WebSocket routes
// HACK: This could be insecure if we had a varargs path. We have to check the path suffix for WS since we don't know the path that this router was mounted.
Expand All @@ -179,19 +179,19 @@ export function createManagerRouter(

return cors({
...(runConfig.cors ?? {}),
...(runConfig.studio?.cors ?? {}),
...(runConfig.inspector?.cors ?? {}),
origin: (origin, c) => {
const studioOrigin = runConfig.studio?.cors?.origin;
const inspectorOrigin = runConfig.inspector?.cors?.origin;

if (studioOrigin !== undefined) {
if (typeof studioOrigin === "function") {
const allowed = studioOrigin(origin, c);
if (inspectorOrigin !== undefined) {
if (typeof inspectorOrigin === "function") {
const allowed = inspectorOrigin(origin, c);
if (allowed) return allowed;
// Proceed to next CORS config if none provided
} else if (Array.isArray(studioOrigin)) {
return studioOrigin.includes(origin) ? origin : undefined;
} else if (Array.isArray(inspectorOrigin)) {
return inspectorOrigin.includes(origin) ? origin : undefined;
} else {
return studioOrigin;
return inspectorOrigin;
}
}

Expand All @@ -207,12 +207,12 @@ export function createManagerRouter(
return null;
},
allowMethods: (origin, c) => {
const studioMethods = runConfig.studio?.cors?.allowMethods;
if (studioMethods) {
if (typeof studioMethods === "function") {
return studioMethods(origin, c);
const inspectorMethods = runConfig.inspector?.cors?.allowMethods;
if (inspectorMethods) {
if (typeof inspectorMethods === "function") {
return inspectorMethods(origin, c);
}
return studioMethods;
return inspectorMethods;
}

if (runConfig.cors?.allowMethods) {
Expand All @@ -226,14 +226,14 @@ export function createManagerRouter(
},
allowHeaders: [
...(runConfig.cors?.allowHeaders ?? []),
...(runConfig.studio?.cors?.allowHeaders ?? []),
...(runConfig.inspector?.cors?.allowHeaders ?? []),
...ALLOWED_PUBLIC_HEADERS,
"Content-Type",
"User-Agent",
],
credentials:
runConfig.cors?.credentials ??
runConfig.studio?.cors?.credentials ??
runConfig.inspector?.cors?.credentials ??
true,
})(c, next);
});
Expand Down Expand Up @@ -562,12 +562,12 @@ export function createManagerRouter(
});
}

if (runConfig.studio?.enabled) {
if (runConfig.inspector?.enabled) {
router.route(
"/actors/inspect",
new Hono()
.use(
cors(runConfig.studio.cors),
cors(runConfig.inspector.cors),
secureInspector(runConfig),
universalActorProxy({
registryConfig,
Expand All @@ -584,7 +584,7 @@ export function createManagerRouter(
"/inspect",
new Hono()
.use(
cors(runConfig.studio.cors),
cors(runConfig.inspector.cors),
secureInspector(runConfig),
async (c, next) => {
const inspector = managerDriver.inspector;
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/registry/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { createActorRouter } from "@/actor/router";
import { type Client, createClientWithDriver } from "@/client/client";
import { chooseDefaultDriver } from "@/drivers/default";
import { createInlineClientDriver } from "@/inline-client-driver/mod";
import { getStudioUrl } from "@/inspector/utils";
import { getInspectorUrl } from "@/inspector/utils";
import { createManagerRouter } from "@/manager/router";
import {
type RegistryActors,
Expand Down Expand Up @@ -73,9 +73,9 @@ export class Registry<A extends RegistryActors> {
definitions: Object.keys(this.#config.use).length,
...driverLog,
});
if (config.studio?.enabled) {
logger().info("studio ready", {
url: getStudioUrl(config),
if (config.inspector?.enabled) {
logger().info("inspector ready", {
url: getInspectorUrl(config),
});
}

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/registry/run-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const RunConfigSchema = z

maxIncomingMessageSize: z.number().optional().default(65_536),

studio: InspectorConfigSchema,
inspector: InspectorConfigSchema,

/**
* Base path for the router. This is used to prefix all routes.
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/test/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { type Client, createClient } from "@/client/mod";
import { chooseDefaultDriver } from "@/drivers/default";
import { createFileSystemOrMemoryDriver } from "@/drivers/file-system/mod";
import { createInlineClientDriver } from "@/inline-client-driver/mod";
import { getStudioUrl } from "@/inspector/utils";
import { getInspectorUrl } from "@/inspector/utils";
import { createManagerRouter } from "@/manager/router";
import type { Registry } from "@/registry/mod";
import { RunConfigSchema } from "@/registry/run-config";
Expand Down
29 changes: 18 additions & 11 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading