Skip to content
This repository was archived by the owner on Oct 22, 2025. It is now read-only.
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/counter-serverless/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import { registry } from "./registry";

registry.start({
runnerKind: "serverless",
runEngine: true,
autoConfigureServerless: true,
autoConfigureServerless: { url: "http://localhost:8080" },
endpoint: "http://localhost:6420",
});
5 changes: 5 additions & 0 deletions packages/next-js/src/log.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { getLogger } from "rivetkit/log";

export function logger() {
return getLogger("driver-next-js");
}
9 changes: 9 additions & 0 deletions packages/next-js/src/mod.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Registry, RunConfigInput } from "rivetkit";
import { logger } from "./log";

export const toNextHandler = (
registry: Registry<any>,
Expand All @@ -12,6 +13,10 @@ export const toNextHandler = (

// Auto-configure serverless runner if not in prod
if (process.env.NODE_ENV !== "production") {
logger().debug(
"detected development environment, auto-starting engine and auto-configuring serverless",
);

const publicUrl =
process.env.NEXT_PUBLIC_SITE_URL ??
process.env.NEXT_PUBLIC_VERCEL_URL ??
Expand All @@ -21,6 +26,10 @@ export const toNextHandler = (
inputConfig.autoConfigureServerless = {
url: `${publicUrl}/api/rivet/start`,
};
} else {
logger().debug(
"detected production environment, will not auto-start engine and auto-configure serverless",
);
}

// Next logs this on every request
Expand Down
9 changes: 8 additions & 1 deletion packages/rivetkit/src/common/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
getRequestEncoding,
getRequestExposeInternalError,
} from "@/actor/router-endpoints";
import { buildActorNames, type RegistryConfig } from "@/registry/config";
import type { RunnerConfig } from "@/registry/run-config";
import { getEndpoint } from "@/remote-manager-driver/api-utils";
import { HttpResponseError } from "@/schemas/client-protocol/mod";
Expand Down Expand Up @@ -93,6 +94,7 @@ export interface MetadataResponse {
| { serverless: Record<never, never> }
| { normal: Record<never, never> };
};
actorNames: ReturnType<typeof buildActorNames>;
/**
* Endpoint that the client should connect to to access this runner.
*
Expand All @@ -105,7 +107,11 @@ export interface MetadataResponse {
clientEndpoint?: string;
}

export function handleMetadataRequest(c: HonoContext, runConfig: RunnerConfig) {
export function handleMetadataRequest(
c: HonoContext,
registryConfig: RegistryConfig,
runConfig: RunnerConfig,
) {
const response: MetadataResponse = {
runtime: "rivetkit",
version: VERSION,
Expand All @@ -115,6 +121,7 @@ export function handleMetadataRequest(c: HonoContext, runConfig: RunnerConfig) {
? { serverless: {} }
: { normal: {} },
},
actorNames: buildActorNames(registryConfig),
// Do not return client endpoint if default server disabled
clientEndpoint:
runConfig.overrideServerAddress ??
Expand Down
6 changes: 5 additions & 1 deletion packages/rivetkit/src/drivers/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ export function chooseDefaultDriver(runConfig: RunnerConfig): DriverConfig {
return runConfig.driver;
}

if (runConfig.endpoint || runConfig.token) {
if (
runConfig.endpoint ||
runConfig.token ||
runConfig.runnerKind === "serverless"
) {
loggerWithoutContext().debug({
msg: "using rivet engine driver",
endpoint: runConfig.endpoint,
Expand Down
9 changes: 2 additions & 7 deletions packages/rivetkit/src/drivers/engine/actor-driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
type ManagerDriver,
serializeEmptyPersistData,
} from "@/driver-helpers/mod";
import type { RegistryConfig } from "@/registry/config";
import { buildActorNames, type RegistryConfig } from "@/registry/config";
import type { RunnerConfig } from "@/registry/run-config";
import { getEndpoint } from "@/remote-manager-driver/api-utils";
import {
Expand Down Expand Up @@ -103,12 +103,7 @@ export class EngineActorDriver implements ActorDriver {
metadata: {
inspectorToken: this.#runConfig.inspector.token(),
},
prepopulateActorNames: Object.fromEntries(
Object.keys(this.#registryConfig.use).map((name) => [
name,
{ metadata: {} },
]),
),
prepopulateActorNames: buildActorNames(registryConfig),
onConnected: () => {
if (hasDisconnected) {
logger().info({
Expand Down
8 changes: 6 additions & 2 deletions packages/rivetkit/src/manager/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,9 @@ function addServerlessRoutes(

router.get("/health", (c) => handleHealthRequest(c));

router.get("/metadata", (c) => handleMetadataRequest(c, runConfig));
router.get("/metadata", (c) =>
handleMetadataRequest(c, registryConfig, runConfig),
);
}

function addManagerRoutes(
Expand Down Expand Up @@ -643,7 +645,9 @@ function addManagerRoutes(

router.get("/health", (c) => handleHealthRequest(c));

router.get("/metadata", (c) => handleMetadataRequest(c, runConfig));
router.get("/metadata", (c) =>
handleMetadataRequest(c, registryConfig, runConfig),
);

managerDriver.modifyManagerRouter?.(
registryConfig,
Expand Down
8 changes: 8 additions & 0 deletions packages/rivetkit/src/registry/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,11 @@ export type RegistryConfigInput<A extends RegistryActors> = Omit<
z.input<typeof RegistryConfigSchema>,
"use"
> & { use: A };

export function buildActorNames(
registryConfig: RegistryConfig,
): Record<string, { metadata: Record<string, any> }> {
return Object.fromEntries(
Object.keys(registryConfig.use).map((name) => [name, { metadata: {} }]),
);
}
Loading