Skip to content
Merged
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
9 changes: 8 additions & 1 deletion apps/server/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ export function assertApiDeploymentConfig(
);
}

/** Accept a full worker URL, or host:port from a platform that omits the scheme. */
export function browserWorkerUrl(value?: string): string | undefined {
const trimmed = value?.trim();
if (!trimmed) return undefined;
return trimmed.includes("://") ? trimmed : `http://${trimmed}`;
}

// Provider SDKs retry transient failures before the response starts, with
// exponential backoff: OpenAI and Anthropic retry HTTP 408, 409, 429, 5xx and
// connection errors and honor retry-after; Gemini retries 408, 429, 500, 502,
Expand Down Expand Up @@ -124,7 +131,7 @@ export function readConfig(): Config {
googleClientId: process.env.GOOGLE_CLIENT_ID,
googleClientSecret: process.env.GOOGLE_CLIENT_SECRET,
googleRedirectUri: `${publicUrl}/api/google/callback`,
workerUrl: process.env.BROWSER_WORKER_URL,
workerUrl: browserWorkerUrl(process.env.BROWSER_WORKER_URL),
workerToken: process.env.WORKER_TOKEN,
taskWorkerEnabled: process.env.TASK_WORKER_ENABLED !== "false",
computerEnabled: process.env.COMPUTER_ENABLED === "true",
Expand Down
9 changes: 9 additions & 0 deletions tests/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import assert from "node:assert/strict";
import { test } from "node:test";
import {
assertApiDeploymentConfig,
browserWorkerUrl,
type Config,
shadowedEnvKeys,
} from "../apps/server/src/config.ts";
Expand Down Expand Up @@ -79,6 +80,14 @@ test("Jev mode is off by default and validates explicit modes", async () => {
}
});

test("browser worker URL keeps an existing scheme and adds http to host:port", () => {
assert.equal(browserWorkerUrl(undefined), undefined);
assert.equal(browserWorkerUrl(" "), undefined);
assert.equal(browserWorkerUrl("http://127.0.0.1:8790"), "http://127.0.0.1:8790");
assert.equal(browserWorkerUrl("https://browser.internal:8790"), "https://browser.internal:8790");
assert.equal(browserWorkerUrl("openmuse-browser-h4fx:8790"), "http://openmuse-browser-h4fx:8790");
});

test("environment variables that override a different .env value are reported by name", () => {
const file = { OPENAI_API_KEY: "sk-or-file", MODEL: "openai/gpt-5", PORT: "8787", EMPTY: "" };
const env = { OPENAI_API_KEY: "sk-proj-system", MODEL: "openai/gpt-5", EMPTY: "set" };
Expand Down