diff --git a/web/app/api/cli/config/route.ts b/web/app/api/cli/config/route.ts index e75a508b3e52..ebea361b61cb 100644 --- a/web/app/api/cli/config/route.ts +++ b/web/app/api/cli/config/route.ts @@ -1,3 +1,8 @@ +import { + defaultHostedSubrouterURL, + hostedSubrouterBaseURL, +} from "@/services/subrouter/constants"; + export const runtime = "nodejs"; export const dynamic = "force-dynamic"; @@ -10,6 +15,15 @@ export function GET(request: Request): Response { if (!projectId || !publishableClientKey) { return unavailableResponse(); } + let subrouterUrl: string; + try { + subrouterUrl = hostedSubrouterBaseURL( + process.env.SUBROUTER_HOSTED_URL?.trim() || + defaultHostedSubrouterURL(), + ); + } catch { + return unavailableResponse(); + } return Response.json( { @@ -29,6 +43,15 @@ export function GET(request: Request): Response { accountsUrl: new URL("/api/coderouter/accounts", request.url).toString(), openaiBaseUrl: new URL("/v1", request.url).toString(), }, + // Keep the hosted Subrouter fields for released sr clients while cmux + // migrates its CodeRouter data plane to Vercel. + subrouter: { + url: subrouterUrl, + exchangeUrl: new URL( + "/api/subrouter/tenant-exchange", + request.url, + ).toString(), + }, }, { headers: { diff --git a/web/tests/cli-config-route.test.ts b/web/tests/cli-config-route.test.ts index 85ad69868669..e73167c4eb27 100644 --- a/web/tests/cli-config-route.test.ts +++ b/web/tests/cli-config-route.test.ts @@ -5,12 +5,14 @@ type CliConfigEnvKey = | "NEXT_PUBLIC_STACK_API_URL" | "NEXT_PUBLIC_STACK_PROJECT_ID" | "NEXT_PUBLIC_STACK_PUBLISHABLE_CLIENT_KEY" + | "SUBROUTER_HOSTED_URL" | "VERCEL_ENV"; const testEnvironment = { NEXT_PUBLIC_STACK_API_URL: "https://stack.example.test/api/v1", NEXT_PUBLIC_STACK_PROJECT_ID: "test-stack-project-id", NEXT_PUBLIC_STACK_PUBLISHABLE_CLIENT_KEY: "test-stack-publishable-key", + SUBROUTER_HOSTED_URL: "https://subrouter.example.test", VERCEL_ENV: "preview", } satisfies Record; @@ -46,7 +48,7 @@ async function withCliConfigEnvironment( } describe("CLI config route", () => { - test("publishes native Stack Auth and the Vercel CodeRouter data plane", async () => { + test("publishes CodeRouter and the hosted Subrouter POST contract", async () => { await withCliConfigEnvironment(testEnvironment, async () => { const response = GET(new Request("https://cmux.com/api/cli/config")); expect(response.status).toBe(200); @@ -65,6 +67,10 @@ describe("CLI config route", () => { accountsUrl: "https://cmux.com/api/coderouter/accounts", openaiBaseUrl: "https://cmux.com/v1", }, + subrouter: { + url: testEnvironment.SUBROUTER_HOSTED_URL, + exchangeUrl: "https://cmux.com/api/subrouter/tenant-exchange", + }, }); }); });