Skip to content

🙌 OpenHands: AI-Driven Development

Add configurable agent server settings (#57)

Graham Neubigaaecc8961b08
diff --git a/AGENTS.md b/AGENTS.md
index 424a51c5d9..6b32832857 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -63,6 +63,7 @@
- A successful end-to-end live run in this environment required a real LLM config (`LLM_MODEL` + `LLM_API_KEY`). The default `litellm_proxy/...` model with no `llm_api_key` failed at runtime with a `litellm.AuthenticationError`.
- Git provider token persistence note: this direct-agent-server frontend now persists `Settings > Git` provider tokens locally in browser storage instead of posting to an app-backend secrets route. `src/api/secrets-service.ts` writes the token payload to localStorage, mirrors provider hosts into `provider_tokens_set` through `SettingsService.saveSettings()`, and `use-delete-git-providers` clears that local state.
+- Agent server connection settings now live at `Settings > Agent Server` (`/settings/agent-server`). The page reads deployment defaults from `VITE_BACKEND_BASE_URL` / `VITE_SESSION_API_KEY`, saves user overrides in the `openhands-agent-server-config` localStorage key, and must stay reachable even when the backend compatibility probe fails so users can recover from missing or wrong backend configuration.
- README expectation: keep the first section as a concrete, chronological from-scratch quickstart for running this frontend against a real `openhands-agent-server` (clone, install backend, optional `.env`, run `npm run dev`).
- Keep README user-focused and move contributor/developer-specific workflows (Cloud sandbox debugging, `dev:safe`, mock mode, detailed env vars/build-test notes) into `DEVELOPMENT.md`.
diff --git a/__tests__/api/agent-server-config.test.ts b/__tests__/api/agent-server-config.test.ts
index 3e73bbc978..471c942139 100644
--- a/__tests__/api/agent-server-config.test.ts
+++ b/__tests__/api/agent-server-config.test.ts
@@ -1,7 +1,12 @@
-import { afterEach, describe, expect, it } from "vitest";
-import { getAgentServerBaseUrl } from "#/api/agent-server-config";
+import { afterEach, describe, expect, it, vi } from "vitest";
+import {
+ AGENT_SERVER_CONFIG_STORAGE_KEY,
+ getAgentServerBaseUrl,
+ getAgentServerFormDefaults,
+ getAgentServerSessionApiKey,
+ saveAgentServerConfig,
+} from "#/api/agent-server-config";
-const STORAGE_KEY = "openhands-agent-server-config";
const ORIGINAL_LOCATION = window.location;
function mockWindowLocation(url: string) {
@@ -13,17 +18,18 @@ function mockWindowLocation(url: string) {
afterEach(() => {
window.localStorage.clear();
+ vi.unstubAllEnvs();
Object.defineProperty(window, "location", {
configurable: true,
value: ORIGINAL_LOCATION,
});
});
-describe("getAgentServerBaseUrl", () => {
+describe("agent server config", () => {
it("uses the browser origin when a remote browser is pointed at localhost backend config", () => {
mockWindowLocation("https://work-1.example.dev/settings");
window.localStorage.setItem(
- STORAGE_KEY,
+ AGENT_SERVER_CONFIG_STORAGE_KEY,
JSON.stringify({ baseUrl: "http://127.0.0.1:8000" }),
);
@@ -33,11 +39,38 @@ describe("getAgentServerBaseUrl", () => {
it("preserves a non-local backend URL from stored config", () => {
mockWindowLocation("https://work-1.example.dev/settings");
window.localStorage.setItem(
- STORAGE_KEY,
+ AGENT_SERVER_CONFIG_STORAGE_KEY,
JSON.stringify({ baseUrl: "https://agent.example.com" }),
);
expect(getAgentServerBaseUrl()).toBe("https://agent.example.com");
});
-});
+ it("prefills the settings form from environment defaults when local settings are empty", () => {
+ vi.stubEnv("VITE_BACKEND_BASE_URL", "https://env-agent.example.com/");
+ vi.stubEnv("VITE_SESSION_API_KEY", "env-session-key");
+
+ expect(getAgentServerFormDefaults()).toEqual({
+ baseUrl: "https://env-agent.example.com",
+ sessionApiKey: "env-session-key",
+ });
+ expect(getAgentServerSessionApiKey()).toBe("env-session-key");
+ });
+
+ it("lets saved interface settings override environment defaults", () => {
+ vi.stubEnv("VITE_BACKEND_BASE_URL", "https://env-agent.example.com");
+ vi.stubEnv("VITE_SESSION_API_KEY", "env-session-key");
+
+ saveAgentServerConfig({
+ baseUrl: "https://saved-agent.example.com/",
+ sessionApiKey: "saved-session-key ",
+ });
+
+ expect(getAgentServerFormDefaults()).toEqual({
+ baseUrl: "https://saved-agent.example.com",
+ sessionApiKey: "saved-session-key",
+ });
+ expect(getAgentServerBaseUrl()).toBe("https://saved-agent.example.com");
+ expect(getAgentServerSessionApiKey()).toBe("saved-session-key");
+ });
+});
diff --git a/__tests__/library-entrypoints.test.ts b/__tests__/library-entrypoints.test.ts
index 1f0f8200b4..caeaccf2f3 100644
--- a/__tests__/library-entrypoints.test.ts
+++ b/__tests__/library-entrypoints.test.ts
@@ -29,6 +29,7 @@ describe("library public entrypoints", () => {
expect(filesApi.FileExplorer).toBeTypeOf("function");
expect(settingsApi.SettingsPanel).toBeTypeOf("function");
expect(settingsApi.AppSettings).toBeTypeOf("function");
+ expect(settingsApi.AgentServerSettings).toBeTypeOf("function");
expect(settingsApi.GitSettings).toBeTypeOf("function");
expect(settingsApi.LLMSettings).toBeTypeOf("function");
expect(settingsApi.MCPSettings).toBeTypeOf("function");
diff --git a/__tests__/root.test.tsx b/__tests__/root.test.tsx
index d673537955..5d4273a697 100644
--- a/__tests__/root.test.tsx
+++ b/__tests__/root.test.tsx
@@ -16,6 +16,14 @@ const RouterStub = createRoutesStub([
Component: () => <div data-testid="app-outlet">app outlet</div>,
path: "/",
},
+ {
+ Component: () => (
+ <div data-testid="agent-server-settings-screen">
+ agent server settings
+ </div>
+ ),
+ path: "/settings/agent-server",
+ },
],
},
]);
@@ -99,4 +107,20 @@ describe("App root compatibility guard", () => {
screen.queryByTestId("agent-server-incompatibility-warning"),
).not.toBeInTheDocument();
});
+
+ it("still allows the agent server settings route when the backend is unreachable", async () => {
+ server.use(http.get("/server_info", () => HttpResponse.error()));
+
+ renderApp(["/settings/agent-server"]);
+
+ await waitFor(() => {
+ expect(
+ screen.getByTestId("agent-server-settings-screen"),
+ ).toBeInTheDocument();
+ });
+
+ expect(
+ screen.queryByTestId("agent-server-unavailable-warning"),
+ ).not.toBeInTheDocument();
+ });
});
diff --git a/__tests__/routes/agent-server-settings.test.tsx b/__tests__/routes/agent-server-settings.test.tsx
new file mode 100644
index 0000000000..867ed218c4
--- /dev/null
+++ b/__tests__/routes/agent-server-settings.test.tsx
@@ -0,0 +1,68 @@
+import { render, screen } from "@testing-library/react";
+import userEvent from "@testing-library/user-event";
+import { afterEach, describe, expect, it, vi } from "vitest";
+import AgentServerSettingsScreen from "#/routes/agent-server-settings";
+import { AGENT_SERVER_CONFIG_STORAGE_KEY } from "#/api/agent-server-config";
+
+const ORIGINAL_LOCATION = window.location;
+
+function mockWindowLocation(url: string, assign = vi.fn()) {
+ const location = new URL(url) as unknown as Location;
+ Object.assign(location, { assign });
+
+ Object.defineProperty(window, "location", {
+ configurable: true,
+ value: location,
+ });
+
+ return assign;
+}
+
+afterEach(() => {
+ window.localStorage.clear();
+ vi.unstubAllEnvs();
+ Object.defineProperty(window, "location", {
+ configurable: true,
+ value: ORIGINAL_LOCATION,
+ });
+});
+
+describe("AgentServerSettingsScreen", () => {
+ it("prefills values from environment defaults", async () => {
+ vi.stubEnv("VITE_BACKEND_BASE_URL", "https://env-agent.example.com/");
+ vi.stubEnv("VITE_SESSION_API_KEY", "env-session-key");
+
+ render(<AgentServerSettingsScreen />);
+
+ expect(await screen.findByTestId("agent-server-url-input")).toHaveValue(
+ "https://env-agent.example.com",
+ );
+ expect(screen.getByTestId("agent-server-api-key-input")).toHaveValue(
+ "env-session-key",
+ );
+ });
+
+ it("saves agent server settings locally and reconnects", async () => {
+ const assignMock = mockWindowLocation(
+ "https://gui.example.com/settings/agent-server",
+ );
+
+ render(<AgentServerSettingsScreen />);
+
+ const user = userEvent.setup();
+ const urlInput = await screen.findByTestId("agent-server-url-input");
+ const apiKeyInput = screen.getByTestId("agent-server-api-key-input");
+
+ await user.type(urlInput, "agent.example.com");
+ await user.type(apiKeyInput, "secret-key");
+ await user.click(screen.getByTestId("submit-button"));
+
+ expect(window.localStorage.getItem(AGENT_SERVER_CONFIG_STORAGE_KEY)).toBe(
+ JSON.stringify({
+ baseUrl: "https://agent.example.com",
+ sessionApiKey: "secret-key",
+ }),
+ );
+ expect(assignMock).toHaveBeenCalledWith("/");
+ });
+});
diff --git a/__tests__/routes/settings.test.tsx b/__tests__/routes/settings.test.tsx
index f433ec886f..a0ae3b0c9d 100644
--- a/__tests__/routes/settings.test.tsx
+++ b/__tests__/routes/settings.test.tsx
@@ -70,6 +70,19 @@ describe("settings route", () => {
expect(response.headers.get("Location")).toBe("/settings/mcp");
});
+ it("skips backend config loading for the agent server settings route", async () => {
+ const getConfigSpy = vi.spyOn(OptionService, "getConfig");
+
+ const result = await clientLoader({
+ request: new Request("http://localhost/settings/agent-server"),
+ params: {},
+ context: {},
+ } as never);
+
+ expect(result).toBeNull();
+ expect(getConfigSpy).not.toHaveBeenCalled();
+ });
+
it("renders the current OSS section title", () => {
const RouterStub = createRoutesStub([
{
@@ -90,7 +103,9 @@ describe("settings route", () => {
</QueryClientProvider>,
);
- expect(screen.getAllByText("SETTINGS$NAV_APPLICATION").length).toBeGreaterThan(0);
+ expect(
+ screen.getAllByText("SETTINGS$NAV_APPLICATION").length,
+ ).toBeGreaterThan(0);
expect(screen.getByTestId("app-settings-screen")).toBeInTheDocument();
});
});
diff --git a/src/api/agent-server-config.ts b/src/api/agent-server-config.ts
index 6d3b2708d5..2afc40c41d 100644
--- a/src/api/agent-server-config.ts
+++ b/src/api/agent-server-config.ts
@@ -1,4 +1,4 @@
-const STORAGE_KEY = "openhands-agent-server-config";
+export const AGENT_SERVER_CONFIG_STORAGE_KEY = "openhands-agent-server-config";
interface StoredAgentServerConfig {
baseUrl?: string | null;
@@ -6,11 +6,16 @@ interface StoredAgentServerConfig {
workingDir?: string | null;
}
+export interface AgentServerFormDefaults {
+ baseUrl: string;
+ sessionApiKey: string;
+}
+
function readStoredConfig(): StoredAgentServerConfig {
if (typeof window === "undefined") return {};
try {
- const raw = window.localStorage.getItem(STORAGE_KEY);
+ const raw = window.localStorage.getItem(AGENT_SERVER_CONFIG_STORAGE_KEY);
if (!raw) return {};
const parsed = JSON.parse(raw) as StoredAgentServerConfig;
return parsed ?? {};
@@ -19,6 +24,35 @@ function readStoredConfig(): StoredAgentServerConfig {
}
}
+function writeStoredConfig(config: StoredAgentServerConfig): void {
+ if (typeof window === "undefined") return;
+
+ const nextConfig = Object.fromEntries(
+ Object.entries(config).flatMap(([key, value]) => {
+ if (typeof value !== "string") return [];
+
+ const trimmed = value.trim();
+ if (!trimmed) return [];
+
+ return [[key, trimmed]];
+ }),
+ ) as StoredAgentServerConfig;
+
+ if (Object.keys(nextConfig).length === 0) {
+ window.localStorage.removeItem(AGENT_SERVER_CONFIG_STORAGE_KEY);
+ return;
+ }
+
+ window.localStorage.setItem(
+ AGENT_SERVER_CONFIG_STORAGE_KEY,
+ JSON.stringify(nextConfig),
+ );
+}
+
+function trimToNull(value?: string | null): string | null {
+ return value?.trim() || null;
+}
+
function normalizeBaseUrl(value?: string | null): string | null {
if (!value) return null;
@@ -36,6 +70,20 @@ function normalizeBaseUrl(value?: string | null): string | null {
return `http://${trimmed}`;
}
+function getConfiguredBaseUrl(): string | null {
+ const storedUrl = normalizeBaseUrl(readStoredConfig().baseUrl);
+ if (storedUrl) return storedUrl;
+
+ return normalizeBaseUrl(import.meta.env.VITE_BACKEND_BASE_URL);
+}
+
+function getConfiguredSessionApiKey(): string | null {
+ const storedKey = trimToNull(readStoredConfig().sessionApiKey);
+ if (storedKey) return storedKey;
+
+ return trimToNull(import.meta.env.VITE_SESSION_API_KEY);
+}
+
function shouldUseProxyOrigin(baseUrl: string): boolean {
if (typeof window === "undefined") {
return false;
@@ -47,8 +95,7 @@ function shouldUseProxyOrigin(baseUrl: string): boolean {
const browserHostname = window.location.hostname;
return (
- localHosts.has(configuredUrl.hostname) &&
- !localHosts.has(browserHostname)
+ localHosts.has(configuredUrl.hostname) && !localHosts.has(browserHostname)
);
} catch {
return false;
@@ -67,16 +114,26 @@ function resolveAgentServerBaseUrl(baseUrl: string | null): string | null {
return baseUrl;
}
-export function getAgentServerBaseUrl(): string {
- const envUrl = resolveAgentServerBaseUrl(
- normalizeBaseUrl(import.meta.env.VITE_BACKEND_BASE_URL),
- );
- if (envUrl) return envUrl;
+export function getAgentServerFormDefaults(): AgentServerFormDefaults {
+ return {
+ baseUrl: getConfiguredBaseUrl() ?? "",
+ sessionApiKey: getConfiguredSessionApiKey() ?? "",
+ };
+}
- const storedUrl = resolveAgentServerBaseUrl(
- normalizeBaseUrl(readStoredConfig().baseUrl),
- );
- if (storedUrl) return storedUrl;
+export function saveAgentServerConfig(config: AgentServerFormDefaults): void {
+ const currentConfig = readStoredConfig();
+
+ writeStoredConfig({
+ ...currentConfig,
+ baseUrl: normalizeBaseUrl(config.baseUrl),
+ sessionApiKey: trimToNull(config.sessionApiKey),
+ });
+}
+
+export function getAgentServerBaseUrl(): string {
+ const configuredUrl = resolveAgentServerBaseUrl(getConfiguredBaseUrl());
+ if (configuredUrl) return configuredUrl;
if (typeof window !== "undefined") {
return window.location.origin;
@@ -86,13 +143,7 @@ export function getAgentServerBaseUrl(): string {
}
export function getAgentServerSessionApiKey(): string | null {
- const envKey = import.meta.env.VITE_SESSION_API_KEY?.trim();
- if (envKey) return envKey;
-
- const storedKey = readStoredConfig().sessionApiKey?.trim();
- if (storedKey) return storedKey;
-
- return null;
+ return getConfiguredSessionApiKey();
}
export function getAgentServerWorkingDir(): string {
diff --git a/src/components/settings/index.ts b/src/components/settings/index.ts
index 28a4b82828..592b31e1f3 100644
--- a/src/components/settings/index.ts
+++ b/src/components/settings/index.ts
@@ -1,5 +1,6 @@
export * from "../features/settings";
export { AppSettingsScreen as AppSettings } from "../../routes/app-settings";
+export { AgentServerSettingsScreen as AgentServerSettings } from "../../routes/agent-server-settings";
export { GitSettingsScreen as GitSettings } from "../../routes/git-settings";
export { LlmSettingsScreen as LLMSettings } from "../../routes/llm-settings";
export { MCPSettingsScreen as MCPSettings } from "../../routes/mcp-settings";
diff --git a/src/constants/settings-nav.tsx b/src/constants/settings-nav.tsx
index 6047b42ac6..6f440e9e67 100644
--- a/src/constants/settings-nav.tsx
+++ b/src/constants/settings-nav.tsx
@@ -49,6 +49,11 @@ export const OSS_NAV_ITEMS: SettingsNavItem[] = [
to: "/settings/app",
text: "SETTINGS$NAV_APPLICATION",
},
+ {
+ icon: <ServerProcessIcon width={22} height={22} />,
+ to: "/settings/agent-server",
+ text: "SETTINGS$NAV_AGENT_SERVER",
+ },
{
icon: <KeyIcon width={22} height={22} />,
to: "/settings/secrets",
diff --git a/src/i18n/translation.json b/src/i18n/translation.json
index 2b12a0a4e7..fc367e5124 100644
--- a/src/i18n/translation.json
+++ b/src/i18n/translation.json
@@ -2090,6 +2090,23 @@
"uk": "Зберегти зміни",
"ca": "Desa els canvis"
},
+ "SETTINGS$SAVE_AND_RECONNECT": {
+ "en": "Save and reconnect",
+ "ja": "Save and reconnect",
+ "zh-CN": "Save and reconnect",
+ "zh-TW": "Save and reconnect",
+ "ko-KR": "Save and reconnect",
+ "no": "Save and reconnect",
+ "it": "Save and reconnect",
+ "pt": "Save and reconnect",
+ "es": "Save and reconnect",
+ "ar": "Save and reconnect",
+ "fr": "Save and reconnect",
+ "tr": "Save and reconnect",
+ "de": "Save and reconnect",
+ "uk": "Save and reconnect",
+ "ca": "Save and reconnect"
+ },
"SETTINGS$SDK_SCHEMA_UNAVAILABLE": {
"en": "SDK settings schema unavailable.",
"ja": "SDK設定スキーマを利用できません。",
@@ -4759,6 +4776,23 @@
"uk": "Додаток",
"ca": "Aplicació"
},
+ "SETTINGS$NAV_AGENT_SERVER": {
+ "en": "Agent Server",
+ "ja": "Agent Server",
+ "zh-CN": "Agent Server",
+ "zh-TW": "Agent Server",
+ "ko-KR": "Agent Server",
+ "no": "Agent Server",
+ "it": "Agent Server",
+ "pt": "Agent Server",
+ "es": "Agent Server",
+ "ar": "Agent Server",
+ "fr": "Agent Server",
+ "tr": "Agent Server",
+ "de": "Agent Server",
+ "uk": "Agent Server",
+ "ca": "Agent Server"
+ },
"SETTINGS$NAV_BILLING": {
"en": "Billing",
"ja": "請求",
@@ -5762,6 +5796,91 @@
"uk": "Налаштуйте ім'я користувача та електронну пошту, які OpenHands використовує для фіксації змін.",
"ca": "Configura el nom d'usuari i el correu electrònic que OpenHands utilitza per confirmar els canvis."
},
+ "SETTINGS$AGENT_SERVER_DESCRIPTION": {
+ "en": "Set the agent server URL and optional session API key that this GUI should use. Deployment defaults appear here automatically until you save different values.",
+ "ja": "Set the agent server URL and optional session API key that this GUI should use. Deployment defaults appear here automatically until you save different values.",
+ "zh-CN": "Set the agent server URL and optional session API key that this GUI should use. Deployment defaults appear here automatically until you save different values.",
+ "zh-TW": "Set the agent server URL and optional session API key that this GUI should use. Deployment defaults appear here automatically until you save different values.",
+ "ko-KR": "Set the agent server URL and optional session API key that this GUI should use. Deployment defaults appear here automatically until you save different values.",
+ "de": "Set the agent server URL and optional session API key that this GUI should use. Deployment defaults appear here automatically until you save different values.",
+ "no": "Set the agent server URL and optional session API key that this GUI should use. Deployment defaults appear here automatically until you save different values.",
+ "it": "Set the agent server URL and optional session API key that this GUI should use. Deployment defaults appear here automatically until you save different values.",
+ "pt": "Set the agent server URL and optional session API key that this GUI should use. Deployment defaults appear here automatically until you save different values.",
+ "es": "Set the agent server URL and optional session API key that this GUI should use. Deployment defaults appear here automatically until you save different values.",
+ "ar": "Set the agent server URL and optional session API key that this GUI should use. Deployment defaults appear here automatically until you save different values.",
+ "fr": "Set the agent server URL and optional session API key that this GUI should use. Deployment defaults appear here automatically until you save different values.",
+ "tr": "Set the agent server URL and optional session API key that this GUI should use. Deployment defaults appear here automatically until you save different values.",
+ "uk": "Set the agent server URL and optional session API key that this GUI should use. Deployment defaults appear here automatically until you save different values.",
+ "ca": "Set the agent server URL and optional session API key that this GUI should use. Deployment defaults appear here automatically until you save different values."
+ },
+ "SETTINGS$AGENT_SERVER_URL": {
+ "en": "Agent server URL",
+ "ja": "Agent server URL",
+ "zh-CN": "Agent server URL",
+ "zh-TW": "Agent server URL",
+ "ko-KR": "Agent server URL",
+ "de": "Agent server URL",
+ "no": "Agent server URL",
+ "it": "Agent server URL",
+ "pt": "Agent server URL",
+ "es": "Agent server URL",
+ "ar": "Agent server URL",
+ "fr": "Agent server URL",
+ "tr": "Agent server URL",
+ "uk": "Agent server URL",
+ "ca": "Agent server URL"
+ },
+ "SETTINGS$AGENT_SERVER_URL_PLACEHOLDER": {
+ "en": "https://agent.example.com",
+ "ja": "https://agent.example.com",
+ "zh-CN": "https://agent.example.com",
+ "zh-TW": "https://agent.example.com",
+ "ko-KR": "https://agent.example.com",
+ "de": "https://agent.example.com",
+ "no": "https://agent.example.com",
+ "it": "https://agent.example.com",
+ "pt": "https://agent.example.com",
+ "es": "https://agent.example.com",
+ "ar": "https://agent.example.com",
+ "fr": "https://agent.example.com",
+ "tr": "https://agent.example.com",
+ "uk": "https://agent.example.com",
+ "ca": "https://agent.example.com"
+ },
+ "SETTINGS$AGENT_SERVER_API_KEY": {
+ "en": "Session API key",
+ "ja": "Session API key",
+ "zh-CN": "Session API key",
+ "zh-TW": "Session API key",
+ "ko-KR": "Session API key",
+ "de": "Session API key",
+ "no": "Session API key",
+ "it": "Session API key",
+ "pt": "Session API key",
+ "es": "Session API key",
+ "ar": "Session API key",
+ "fr": "Session API key",
+ "tr": "Session API key",
+ "uk": "Session API key",
+ "ca": "Session API key"
+ },
+ "SETTINGS$AGENT_SERVER_API_KEY_PLACEHOLDER": {
+ "en": "Enter the X-Session-API-Key value",
+ "ja": "Enter the X-Session-API-Key value",
+ "zh-CN": "Enter the X-Session-API-Key value",
+ "zh-TW": "Enter the X-Session-API-Key value",
+ "ko-KR": "Enter the X-Session-API-Key value",
+ "de": "Enter the X-Session-API-Key value",
+ "no": "Enter the X-Session-API-Key value",
+ "it": "Enter the X-Session-API-Key value",
+ "pt": "Enter the X-Session-API-Key value",
+ "es": "Enter the X-Session-API-Key value",
+ "ar": "Enter the X-Session-API-Key value",
+ "fr": "Enter the X-Session-API-Key value",
+ "tr": "Enter the X-Session-API-Key value",
+ "uk": "Enter the X-Session-API-Key value",
+ "ca": "Enter the X-Session-API-Key value"
+ },
"SETTINGS$SOUND_NOTIFICATIONS": {
"en": "Sound Notifications",
"ja": "サウンド通知",
diff --git a/src/root.tsx b/src/root.tsx
index 9b9a4a47f3..f9f6d44481 100644
--- a/src/root.tsx
+++ b/src/root.tsx
@@ -1,10 +1,12 @@
import {
+ Link,
Links,
Meta,
MetaFunction,
Outlet,
Scripts,
ScrollRestoration,
+ useLocation,
} from "react-router";
import "./tailwind.css";
import "./index.css";
@@ -55,6 +57,7 @@ function AgentServerNotice({
data-testid={testId}
className="w-full max-w-2xl rounded-2xl border border-danger/30 bg-neutral-900/80 p-8 shadow-2xl"
>
+ {/* eslint-disable-next-line i18next/no-literal-string */}
<p className="text-sm font-medium uppercase tracking-[0.24em] text-danger">
Connection blocked
</p>
@@ -66,6 +69,18 @@ function AgentServerNotice({
);
}
+function ConfigureAgentServerLink() {
+ return (
+ <Link
+ to="/settings/agent-server"
+ className="mt-6 inline-flex w-fit items-center rounded-md bg-primary px-4 py-2 text-sm font-medium text-white transition-opacity hover:opacity-90"
+ >
+ {/* eslint-disable-next-line i18next/no-literal-string */}
+ Configure agent server
+ </Link>
+ );
+}
+
function UnsupportedAgentServerNotice({
error,
}: {
@@ -79,9 +94,11 @@ function UnsupportedAgentServerNotice({
>
{error.serverVersion && (
<p className="mt-4 text-sm text-neutral-400">
+ {/* eslint-disable-next-line i18next/no-literal-string */}
Detected version: <code>{error.serverVersion}</code>
</p>
)}
+ <ConfigureAgentServerLink />
</AgentServerNotice>
);
}
@@ -99,9 +116,11 @@ function MissingAgentServerNotice({
>
{error.details && (
<p className="mt-4 text-sm text-neutral-400">
+ {/* eslint-disable-next-line i18next/no-literal-string */}
Details: {error.details}
</p>
)}
+ <ConfigureAgentServerLink />
</AgentServerNotice>
);
}
@@ -112,13 +131,22 @@ export const meta: MetaFunction = () => [
];
export default function App() {
+ const location = useLocation();
const config = useConfig({ enabled: true });
+ const isAgentServerSettingsRoute =
+ location.pathname === "/settings/agent-server";
- if (isAgentServerUnavailableError(config.error)) {
+ if (
+ !isAgentServerSettingsRoute &&
+ isAgentServerUnavailableError(config.error)
+ ) {
return <MissingAgentServerNotice error={config.error} />;
}
- if (isAgentServerIncompatibilityError(config.error)) {
+ if (
+ !isAgentServerSettingsRoute &&
+ isAgentServerIncompatibilityError(config.error)
+ ) {
return <UnsupportedAgentServerNotice error={config.error} />;
}
diff --git a/src/routes.ts b/src/routes.ts
index 7945125888..903369d82b 100644
--- a/src/routes.ts
+++ b/src/routes.ts
@@ -17,6 +17,7 @@ export default [
route("skills", "routes/skills-settings.tsx"),
route("integrations", "routes/git-settings.tsx"),
route("app", "routes/app-settings.tsx"),
+ route("agent-server", "routes/agent-server-settings.tsx"),
route("secrets", "routes/secrets-settings.tsx"),
]),
route("conversations/:conversationId", "routes/conversation.tsx"),
diff --git a/src/routes/agent-server-settings.tsx b/src/routes/agent-server-settings.tsx
new file mode 100644
index 0000000000..657c1f941e
--- /dev/null
+++ b/src/routes/agent-server-settings.tsx
@@ -0,0 +1,83 @@
+import React from "react";
+import { useTranslation } from "react-i18next";
+import {
+ getAgentServerFormDefaults,
+ saveAgentServerConfig,
+} from "#/api/agent-server-config";
+import { BrandButton } from "#/components/features/settings/brand-button";
+import { SettingsInput } from "#/components/features/settings/settings-input";
+
+export const clientLoader = async () => null;
+
+export function AgentServerSettingsScreen() {
+ const { t } = useTranslation();
+ const defaults = React.useMemo(() => getAgentServerFormDefaults(), []);
+ const [baseUrl, setBaseUrl] = React.useState(defaults.baseUrl);
+ const [sessionApiKey, setSessionApiKey] = React.useState(
+ defaults.sessionApiKey,
+ );
+
+ const formIsClean =
+ baseUrl === defaults.baseUrl && sessionApiKey === defaults.sessionApiKey;
+
+ const onSubmit = (event: React.FormEvent<HTMLFormElement>) => {
+ event.preventDefault();
+
+ saveAgentServerConfig({
+ baseUrl,
+ sessionApiKey,
+ });
+
+ window.location.assign("/");
+ };
+
+ return (
+ <form
+ data-testid="agent-server-settings-screen"
+ onSubmit={onSubmit}
+ className="flex h-full flex-col justify-between"
+ >
+ <div className="flex flex-col gap-6">
+ <p className="max-w-[680px] text-sm text-gray-400">
+ {t("SETTINGS$AGENT_SERVER_DESCRIPTION")}
+ </p>
+
+ <SettingsInput
+ testId="agent-server-url-input"
+ name="agent-server-url-input"
+ type="text"
+ label={t("SETTINGS$AGENT_SERVER_URL")}
+ value={baseUrl}
+ onChange={setBaseUrl}
+ placeholder={t("SETTINGS$AGENT_SERVER_URL_PLACEHOLDER")}
+ className="w-full max-w-[680px]"
+ />
+
+ <SettingsInput
+ testId="agent-server-api-key-input"
+ name="agent-server-api-key-input"
+ type="password"
+ label={t("SETTINGS$AGENT_SERVER_API_KEY")}
+ value={sessionApiKey}
+ onChange={setSessionApiKey}
+ placeholder={t("SETTINGS$AGENT_SERVER_API_KEY_PLACEHOLDER")}
+ showOptionalTag
+ className="w-full max-w-[680px]"
+ />
+ </div>
+
+ <div className="flex justify-end gap-6 p-6">
+ <BrandButton
+ testId="submit-button"
+ variant="primary"
+ type="submit"
+ isDisabled={formIsClean}
+ >
+ {t("SETTINGS$SAVE_AND_RECONNECT")}
+ </BrandButton>
+ </div>
+ </form>
+ );
+}
+
+export default AgentServerSettingsScreen;
diff --git a/src/routes/settings.tsx b/src/routes/settings.tsx
index 0bd43aa491..b6850cc040 100644
--- a/src/routes/settings.tsx
+++ b/src/routes/settings.tsx
@@ -18,6 +18,10 @@ export const clientLoader = async ({ request }: Route.ClientLoaderArgs) => {
const url = new URL(request.url);
const { pathname } = url;
+ if (pathname === "/settings/agent-server") {
+ return null;
+ }
+
const config = await queryClient.fetchQuery<WebClientConfig>({
queryKey: QUERY_KEYS.WEB_CLIENT_CONFIG,
queryFn: OptionService.getConfig,
@@ -63,7 +67,9 @@ function SettingsScreen() {
<main data-testid="settings-screen" className="h-full">
<SettingsLayout navigationItems={navItems}>
<div className="flex flex-col gap-6 h-full">
- {!shouldHideTitle && <Typography.H2>{t(currentSectionTitle)}</Typography.H2>}
+ {!shouldHideTitle && (
+ <Typography.H2>{t(currentSectionTitle)}</Typography.H2>
+ )}
<div className="flex-1 overflow-auto custom-scrollbar-always">
<Outlet />
</div>