Skip to content

🙌 OpenHands: AI-Driven Development

refactor(onboarding): edit the active LLM profile instead of raw LLM settings (#18218)

Engel Nyst51fc673f0753
diff --git a/.agents/skills/frontend-api-contracts/references/guide.md b/.agents/skills/frontend-api-contracts/references/guide.md
index 22676ff427..405aa911dc 100644
--- a/.agents/skills/frontend-api-contracts/references/guide.md
+++ b/.agents/skills/frontend-api-contracts/references/guide.md
@@ -129,7 +129,7 @@ return new ConversationClient(getAgentServerClientOptions()).someMethod(...);
## Backend and Contract Invariants
-- Local onboarding must create its LLM profile from the complete persisted settings after the form save succeeds. Fetch with `X-Expose-Secrets: encrypted` through `SettingsService.fetchSettingsFromApi("encrypted")` so unchanged endpoints, credentials and typed options survive the profile creation. A dirty-field settings diff is insufficient for the profile endpoint's complete LLM configuration. Cloud onboarding continues to use its settings save path.
+- Local onboarding edits an LLM profile, the way the LLM profile editor does. It fills the form from the active LLM profile, else from the one the `default` agent profile points at, read with `X-Expose-Secrets: encrypted` once the backend's health probe reports it connected; listing the agent profiles first runs the Agent Server's one-time backfill of legacy raw LLM settings into a `default` LLM profile, and that listing is best-effort for backends without agent profiles. With neither, it starts a fresh profile with the onboarding default model; an existing profile keeps its own model. A failed read shows an error with a retry, never a fresh form. On Next an unchanged existing profile is kept as is; otherwise the form's changes are merged over that profile with `buildProfileLlmConfig` (`src/components/features/settings/llm-profiles/llm-profile-form.ts`), which also resolves a subscription profile's model to a loaded subscription model, and the result is saved and activated. It never reads or PATCHes raw `agent_settings.llm`; activating the profile syncs it on the server. A form's dirty fields alone are not a complete profile, because the profile endpoint replaces the whole LLM configuration. Cloud onboarding still saves through its settings path.
- Use `@openhands/typescript-client` classes directly for agent-server-backed REST/workspace/event/VS Code calls. Centralize host/session API key/working-directory option assembly through `src/api/agent-server-client-options.ts`; the backend fallback policy itself lives in `src/api/backend-registry/active-store.ts`.
- Local verification/build gotchas:
diff --git a/.agents/skills/verify-openhands/references/feature-map/F01-first-run-and-sign-in.md b/.agents/skills/verify-openhands/references/feature-map/F01-first-run-and-sign-in.md
index db8888dd15..e403033799 100644
--- a/.agents/skills/verify-openhands/references/feature-map/F01-first-run-and-sign-in.md
+++ b/.agents/skills/verify-openhands/references/feature-map/F01-first-run-and-sign-in.md
@@ -19,8 +19,8 @@ Source: `src/root.tsx`, `src/components/features/onboarding/`, `src/components/f
- `F01.onboarding-modal`: a segmented progress bar (3 steps, or 4 with the backend step) over a sliding rail. Neither Escape nor a click on the backdrop dismisses it. "Skip for now" shows on every step except the last, and Back/Next move between steps.
- `F01.onboarding-backend-step`: when no reachable backend exists (public mode), step 0 "Add a backend" prefills the name `Local` and the page origin as host. Next stays disabled until an API key is typed. A wrong key shows "Could not connect to <host>" / "Invalid API key" inline. The right key saves the backend, and the flow collapses to 3 steps on "Choose your agent" with no Back button. The first paint must not raise an error toast.
- `F01.onboarding-choose-agent`: radio tiles for OpenHands (preselected), Claude Code, Codex and Gemini CLI. Next saves the agent kind with a "Settings saved" toast.
-- `F01.onboarding-setup-llm`: the embedded LLM form is prefilled with `openai/gpt-5.6-sol`. Typing a custom model and key then Next saves them. On a local backend it also creates and activates an LLM profile named after the model (`deepseek/deepseek-flash` → `deepseek-flash`).
-- `F01.onboarding-repeat-endpoint`: onboarding again (a new browser, the same backend) with the custom Base URL and key that are already saved creates a profile that keeps that Base URL, and the say-hello conversation reaches that endpoint. The All view prefills the saved Base URL.
+- `F01.onboarding-setup-llm`: on a first run the embedded LLM form is prefilled with `openai/gpt-5.6-sol`. Typing a custom model and key then Next saves them. On a local backend Next saves the form as an LLM profile named after the model (`deepseek/deepseek-flash` → `deepseek-flash`) and activates it, without writing the raw LLM settings.
+- `F01.onboarding-repeat-endpoint`: onboarding again (a new browser, the same backend) fills the form from the active LLM profile, or from the one the `default` agent profile points at, model included. The All view prefills its Base URL and key even when the raw LLM settings hold another Base URL. Next without changes keeps that profile and saves no copy. Changing only the model creates a profile that keeps that Base URL and key, and the say-hello conversation reaches that endpoint.
- `F01.onboarding-acp-secrets`: choosing an ACP agent swaps the LLM step for "Add your API keys" with that provider's fields. When the host CLI is already logged in, a green "already signed in" banner makes them optional. Back returns to the agent step.
- `F01.onboarding-say-hello`: the last step has a prefilled message. An empty message disables send. Enter or the send button creates a conversation, navigates to `/conversations/<id>` and completes onboarding, and the agent replies. A recommended-automations list sits under an "Or" separator, and a "Skip Getting Started checklist" box sits below the modal.
- `F01.onboarding-hello-close`: the last step has Back and Close instead of "Skip for now". Close dismisses the modal without creating a conversation, sets the `openhands-onboarded` flag and leaves the app shell on `/`.
@@ -69,7 +69,7 @@ Local run (`launch --new`):
- **Skip checklist box (`F01.onboarding-skip-checklist`).** Run `control-openhands browser goto /conversations` and `control-openhands browser count 'testid=sidebar-onboarding-checklist'` (`1`). Run `control-openhands browser goto '/?previewOnboardingStep=3'`, then `control-openhands browser click 'text=Skip Getting Started checklist'`. `control-openhands browser eval "document.querySelector('[data-testid=onboarding-skip-getting-started-checklist]').checked"` is `true`. Run `control-openhands browser goto /conversations` and `control-openhands browser reload`; the checklist count is `0`. On `/settings/app`, `control-openhands browser eval "document.querySelector('[data-testid=show-getting-started-checklist-switch]').checked"` is `false`. Restore it: go back to `/?previewOnboardingStep=3`, where the box now reads `true`, click the same text again, and the checklist count on `/conversations` is `1`.
- **Phone (`F01.onboarding-phone`).** Run `control-openhands browser viewport phone`. Then for N in 1, 2 and 3 run `control-openhands browser goto '/?previewOnboardingStep=N'`, `control-openhands browser bbox 'testid=onboarding-modal'` and `control-openhands browser screenshot --feature F01.onboarding-phone --name step-N`. The modal is 351 px wide with `insideViewport` `true` and `pageHorizontalOverflow` `false`, and Back/Next or Back/Close are visible. Return with `control-openhands browser viewport desktop`.
- **Error page (`F01.route-error-boundary`).** Run `control-openhands browser errors --clear`, `control-openhands browser goto /this-route-does-not-exist` and `control-openhands browser snapshot 'testid=not-found-screen'`. It shows `heading "Page not found"`, the paragraph `This address does not match any page. Check the URL, or go back to the home page.` and `link "Home"` (`/url: /`). `control-openhands browser count 'aside[data-collapsed]'` is `1`: the sidebar stays. `control-openhands browser screenshot --feature F01.route-error-boundary --name not-found` shows the message and the Home button centered beside the sidebar. `control-openhands browser errors --app-only` reports `pageErrors` `0` and `appErrors` `0`. Run `control-openhands browser click 'testid=not-found-home-link' --expect-url '/$'`; `control-openhands browser count 'testid=home-screen'` is `1`.
-- **Onboarding again with the saved endpoint (`F01.onboarding-repeat-endpoint`).** Two more first runs on this stack, both through the All view, which shows the Base URL field. Pass 1 saves a custom endpoint: `control-openhands browser reset`, `control-openhands browser goto /`, `control-openhands browser click 'testid=onboarding-agent-next'`, `control-openhands browser wait '[data-testid=onboarding-modal][data-current-step="1"]'`, `control-openhands browser click 'testid=onboarding-step-setup-llm >> testid=sdk-section-all-toggle'` and `control-openhands browser value 'testid=onboarding-step-setup-llm >> testid=base-url-input'` (empty). Run `control-openhands browser fill 'testid=onboarding-step-setup-llm >> testid=llm-custom-model-input' openai/deepseek-chat`, `control-openhands browser fill 'testid=onboarding-step-setup-llm >> testid=base-url-input' https://api.deepseek.com/v1`, `control-openhands browser fill 'testid=onboarding-step-setup-llm >> testid=llm-api-key-input' --value-env DEEPSEEK_API_KEY`, `control-openhands browser click 'testid=onboarding-llm-next'` and `control-openhands browser wait '[data-testid=onboarding-modal][data-current-step="2"]'`. `control-openhands llm show` lists `deepseek-chat` (`openai/deepseek-chat`, `base_url` `https://api.deepseek.com/v1`) as `active_profile`. Say hello as above (`browser fill 'testid=onboarding-hello-input' 'Reply with only the word hello. Do not run any tools.'`, `browser press Enter --selector 'testid=onboarding-hello-input'`, `browser wait-url '/conversations/[0-9a-f-]+'`), then `control-openhands conversation wait <id> --timeout 180` is `finished` and the agent `MessageEvent` is `hello`. Pass 2 types the same endpoint again: repeat the steps up to the All view. `browser value 'testid=onboarding-step-setup-llm >> testid=base-url-input'` is now `https://api.deepseek.com/v1`, the saved value. Fill the model `openai/deepseek-v4-flash` (a DeepSeek alias, so the new profile gets its own name), the same Base URL and the key, then Next and wait for step 2 (`control-openhands browser screenshot 'testid=onboarding-step-setup-llm' --feature F01.onboarding-repeat-endpoint --name second-pass-form` before Next). Expected: `control-openhands llm show` lists `deepseek-v4-flash` with `base_url` `https://api.deepseek.com/v1`, and the say-hello conversation finishes with `hello`. Known failure (reproduced 2026-10-08 at `53c8b4d`): the profile is saved with `base_url` `null`. The say-hello conversation then ends in `error`, and `control-openhands conversation events <id> --last 10` shows `ConversationErrorEvent` `LLMAuthenticationError: litellm.AuthenticationError: ... OpenAIException - Incorrect API key provided`: the DeepSeek key went to OpenAI. The chat shows `Your LLM API key appears to be invalid or has expired.` (`browser screenshot --feature F01.onboarding-repeat-endpoint --name second-pass-error`). Issue #17884, fix in #17889. Restore: run `control-openhands llm preset deepseek`. It also points the `default` agent profile back at `deepseek-flash`: its output has `repointed` from `deepseek-v4-flash` to `deepseek-flash`. Then `control-openhands api DELETE /api/profiles/deepseek-v4-flash --write` and `.../deepseek-chat --write` answer `200`. Delete the two say-hello conversations with Clean up's steps.
+- **Onboarding again with the saved endpoint (`F01.onboarding-repeat-endpoint`).** Two more first runs on this stack, both through the All view, which shows the Base URL field. Pass 1 saves a custom endpoint: `control-openhands browser reset`, `control-openhands browser goto /`, `control-openhands browser click 'testid=onboarding-agent-next'`, `control-openhands browser wait '[data-testid=onboarding-modal][data-current-step="1"]'`, `control-openhands browser click 'testid=onboarding-step-setup-llm >> testid=sdk-section-all-toggle'` and `control-openhands browser value 'testid=onboarding-step-setup-llm >> testid=base-url-input'` (empty). Run `control-openhands browser fill 'testid=onboarding-step-setup-llm >> testid=llm-custom-model-input' openai/deepseek-chat`, `control-openhands browser fill 'testid=onboarding-step-setup-llm >> testid=base-url-input' https://api.deepseek.com/v1`, `control-openhands browser fill 'testid=onboarding-step-setup-llm >> testid=llm-api-key-input' --value-env DEEPSEEK_API_KEY`, `control-openhands browser click 'testid=onboarding-llm-next'` and `control-openhands browser wait '[data-testid=onboarding-modal][data-current-step="2"]'`. `control-openhands llm show` lists `deepseek-chat` (`openai/deepseek-chat`, `base_url` `https://api.deepseek.com/v1`) as `active_profile`. Say hello as above (`browser fill 'testid=onboarding-hello-input' 'Reply with only the word hello. Do not run any tools.'`, `browser press Enter --selector 'testid=onboarding-hello-input'`, `browser wait-url '/conversations/[0-9a-f-]+'`), then `control-openhands conversation wait <id> --timeout 180` is `finished` and the agent `MessageEvent` is `hello`. Pass 2 types the same endpoint again: repeat the steps up to the All view. `browser value 'testid=onboarding-step-setup-llm >> testid=base-url-input'` is now `https://api.deepseek.com/v1`, the saved value. Fill the model `openai/deepseek-v4-flash` (a DeepSeek alias, so the new profile gets its own name), the same Base URL and the key, then Next and wait for step 2 (`control-openhands browser screenshot 'testid=onboarding-step-setup-llm' --feature F01.onboarding-repeat-endpoint --name second-pass-form` before Next). Expected: `control-openhands llm show` lists `deepseek-v4-flash` with `base_url` `https://api.deepseek.com/v1`, and the say-hello conversation finishes with `hello`. Raw LLM settings that disagree with the active profile do not reach the form. To check it, arrange them before pass 2 with `control-openhands api PATCH /api/settings --write --data '{"agent_settings_diff":{"llm":{"base_url":"http://127.0.0.1:9/stale-raw-settings"}}}'`. `browser value 'testid=onboarding-step-setup-llm >> testid=base-url-input'` still reads `https://api.deepseek.com/v1`. Fill only the model, run `browser network --clear` before Next and `browser network --filter '/api/(settings|profiles)'` after it: the rows are the profile `POST` and its `/activate`, with no `PATCH /api/settings`. `deepseek-v4-flash` keeps the DeepSeek Base URL, and the say-hello conversation finishes with `hello` (verified 2026-10-09). Restore: run `control-openhands llm preset deepseek`. It also points the `default` agent profile back at `deepseek-flash`: its output has `repointed` from `deepseek-v4-flash` to `deepseek-flash`. Then `control-openhands api DELETE /api/profiles/deepseek-v4-flash --write` and `.../deepseek-chat --write` answer `200`. Delete the two say-hello conversations with Clean up's steps.
- **Clean up.** Delete the hello conversation from its header menu: `control-openhands browser goto /conversations/<id>` (the hello conversation's `<id>` from Say hello; the Error page bullet left `/`), `control-openhands browser click 'testid=chat-pane-header >> testid=ellipsis-button'`, `control-openhands browser click 'testid=conversation-name-context-menu >> testid=delete-button'`, `control-openhands browser click 'role=button[name="Confirm Delete"]'`. `control-openhands conversation list` then shows `count` `0`.
Public run A (`launch --new --public`), backend step walked:
diff --git a/__tests__/components/onboarding/onboarding-modal.test.tsx b/__tests__/components/onboarding/onboarding-modal.test.tsx
index 74d3f9b454..00e292092e 100644
--- a/__tests__/components/onboarding/onboarding-modal.test.tsx
+++ b/__tests__/components/onboarding/onboarding-modal.test.tsx
@@ -29,7 +29,11 @@ const saveAgentProfileMock = vi.hoisted(() => vi.fn().mockResolvedValue({}));
const getAgentProfileMock = vi.hoisted(() =>
vi.fn().mockResolvedValue({ profile: { id: "default-profile-id" } }),
);
-const activateAgentProfileMock = vi.hoisted(() => vi.fn().mockResolvedValue({}));
+const activateAgentProfileMock = vi.hoisted(() =>
+ vi.fn().mockResolvedValue({}),
+);
+const saveLlmProfileMock = vi.hoisted(() => vi.fn().mockResolvedValue({}));
+const activateLlmProfileMock = vi.hoisted(() => vi.fn().mockResolvedValue({}));
let captureMock: MockInstance<typeof telemetry.trackEvent>;
// Both the backend status badge in the embedded edit form and the
@@ -48,11 +52,30 @@ vi.mock("@openhands/typescript-client/clients", () => ({
getSettings: vi.fn(() => getSettingsMock()),
};
}),
+ // The local LLM step edits the active LLM profile (none here, so a fresh
+ // one) and saves the form as a profile.
+ ProfilesClient: vi.fn(function ProfilesClientMock() {
+ return {
+ listProfiles: vi.fn(() =>
+ Promise.resolve({ profiles: [], active_profile: null }),
+ ),
+ getProfile: vi.fn(() =>
+ Promise.resolve({ name: "", config: {}, api_key_set: false }),
+ ),
+ saveProfile: vi.fn((...args) => saveLlmProfileMock(...args)),
+ activateProfile: vi.fn((...args) => activateLlmProfileMock(...args)),
+ };
+ }),
AgentProfilesClient: vi.fn(function AgentProfilesClientMock() {
return {
+ listAgentProfiles: vi.fn(() =>
+ Promise.resolve({ profiles: [], active_agent_profile_id: null }),
+ ),
saveAgentProfile: vi.fn((...args) => saveAgentProfileMock(...args)),
getAgentProfile: vi.fn((...args) => getAgentProfileMock(...args)),
- activateAgentProfile: vi.fn((...args) => activateAgentProfileMock(...args)),
+ activateAgentProfile: vi.fn((...args) =>
+ activateAgentProfileMock(...args),
+ ),
};
}),
}));
@@ -72,8 +95,25 @@ vi.mock("#/routes/llm-settings", async () => {
const React = await import("react");
return {
- LlmSettingsScreen: (props: Record<string, unknown>) => {
+ LlmSettingsScreen: (props: {
+ initialValueOverrides?: Record<string, string | boolean>;
+ onSaveSuccess?: () => void;
+ onSaveControlChange?: (control: unknown) => void;
+ }) => {
llmSettingsScreenMock(props);
+ const { onSaveControlChange } = props;
+ // Expose the save control the real form provides, with no changes.
+ React.useEffect(() => {
+ onSaveControlChange?.({
+ save: () => props.onSaveSuccess?.(),
+ isSaving: false,
+ isDirty: false,
+ values: props.initialValueOverrides ?? {},
+ view: "basic",
+ getDirtyPayload: () => ({ llm: {} }),
+ getSavePayload: () => ({}),
+ });
+ }, [onSaveControlChange]);
return React.createElement(
"div",
{ "data-testid": "llm-settings-screen-stub" },
@@ -164,6 +204,13 @@ async function waitForConfiguredBackendToBeSkipped() {
);
}
+// The LLM step's Next waits for the form's save control.
+async function clickLlmNext(user: ReturnType<typeof userEvent.setup>) {
+ const next = screen.getByTestId("onboarding-llm-next");
+ await waitFor(() => expect(next).toBeEnabled());
+ await user.click(next);
+}
+
async function completeAgentStep(user: ReturnType<typeof userEvent.setup>) {
await user.click(screen.getByTestId("onboarding-agent-next"));
await waitFor(
@@ -705,20 +752,21 @@ describe("OnboardingModal", () => {
);
});
- it("pre-fills the LLM step with the OpenHands default model", () => {
+ it("pre-fills the LLM step with the OpenHands default model", async () => {
renderModal();
- expect(llmSettingsScreenMock).toHaveBeenCalledTimes(1);
- expect(llmSettingsScreenMock).toHaveBeenCalledWith(
- expect.objectContaining({
- initialValueOverrides: {
- "llm.model": ONBOARDING_DEFAULT_LLM_MODEL,
- },
- }),
+ await waitFor(() =>
+ expect(llmSettingsScreenMock).toHaveBeenCalledWith(
+ expect.objectContaining({
+ initialValueOverrides: expect.objectContaining({
+ "llm.model": ONBOARDING_DEFAULT_LLM_MODEL,
+ }),
+ }),
+ ),
);
});
- it("pre-fills the LLM step with the DB-selected OpenHands default", () => {
+ it("pre-fills the LLM step with the DB-selected OpenHands default", async () => {
useFreeModelsStore.getState().setFlags({
freeModels: new Set(["openhands/gpt-5.2"]),
defaultModel: "openhands/gpt-5.2",
@@ -726,13 +774,14 @@ describe("OnboardingModal", () => {
renderModal();
- expect(llmSettingsScreenMock).toHaveBeenCalledTimes(1);
- expect(llmSettingsScreenMock).toHaveBeenCalledWith(
- expect.objectContaining({
- initialValueOverrides: {
- "llm.model": "openhands/gpt-5.2",
- },
- }),
+ await waitFor(() =>
+ expect(llmSettingsScreenMock).toHaveBeenCalledWith(
+ expect.objectContaining({
+ initialValueOverrides: expect.objectContaining({
+ "llm.model": "openhands/gpt-5.2",
+ }),
+ }),
+ ),
);
});
@@ -764,12 +813,22 @@ describe("OnboardingModal", () => {
"true",
);
- // Step 1 → 2
- await user.click(screen.getByTestId("onboarding-llm-next"));
- expect(screen.getByTestId("onboarding-modal")).toHaveAttribute(
- "data-current-step",
- "2",
+ // Step 1 → 2. On a local backend Next saves the form as an LLM profile
+ // and activates it before advancing.
+ await clickLlmNext(user);
+ await waitFor(() =>
+ expect(screen.getByTestId("onboarding-modal")).toHaveAttribute(
+ "data-current-step",
+ "2",
+ ),
+ );
+ expect(saveLlmProfileMock).toHaveBeenCalledWith(
+ "gpt-5.6-sol",
+ expect.objectContaining({
+ llm: expect.objectContaining({ model: ONBOARDING_DEFAULT_LLM_MODEL }),
+ }),
);
+ expect(activateLlmProfileMock).toHaveBeenCalledWith("gpt-5.6-sol");
expect(screen.getByTestId("onboarding-slide-2")).toHaveAttribute(
"data-active",
"true",
@@ -1014,7 +1073,7 @@ describe("OnboardingModal", () => {
await waitForConfiguredBackendToBeSkipped();
await completeAgentStep(user);
- await user.click(screen.getByTestId("onboarding-llm-next"));
+ await clickLlmNext(user);
const helloInput = screen.getByTestId(
"onboarding-hello-input",
@@ -1039,7 +1098,7 @@ describe("OnboardingModal", () => {
"true",
),
);
- await user.click(screen.getByTestId("onboarding-llm-next"));
+ await clickLlmNext(user);
await waitFor(() =>
expect(screen.getByTestId("onboarding-slide-2")).toHaveAttribute(
"data-active",
@@ -1053,7 +1112,7 @@ describe("OnboardingModal", () => {
);
expect(
helloInput.compareDocumentPosition(recommendations) &
- Node.DOCUMENT_POSITION_FOLLOWING,
+ Node.DOCUMENT_POSITION_FOLLOWING,
).toBeTruthy();
expect(
within(recommendations).getByTestId(
@@ -1170,7 +1229,7 @@ describe("OnboardingModal", () => {
const user = userEvent.setup();
await waitForConfiguredBackendToBeSkipped();
await completeAgentStep(user);
- await user.click(screen.getByTestId("onboarding-llm-next"));
+ await clickLlmNext(user);
await waitFor(() =>
expect(screen.getByTestId("onboarding-slide-2")).toHaveAttribute(
"data-active",
diff --git a/__tests__/components/onboarding/setup-llm-step.test.tsx b/__tests__/components/onboarding/setup-llm-step.test.tsx
index 28ea24da3e..4fb183cbd1 100644
--- a/__tests__/components/onboarding/setup-llm-step.test.tsx
+++ b/__tests__/components/onboarding/setup-llm-step.test.tsx
@@ -1,33 +1,110 @@
import { screen, waitFor } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { beforeEach, describe, expect, it, vi } from "vitest";
-import { SetupLlmStep } from "#/components/features/onboarding/steps/setup-llm-step";
+import {
+ ONBOARDING_DEFAULT_LLM_MODEL,
+ SetupLlmStep,
+} from "#/components/features/onboarding/steps/setup-llm-step";
import type { SdkSectionSaveControl } from "#/components/features/settings/sdk-settings/sdk-section-page";
+import type { SettingsFormValues } from "#/utils/sdk-settings-schema";
import { renderWithProviders } from "../../../test-utils";
const saveProfile = vi.hoisted(() => vi.fn());
const activateProfile = vi.hoisted(() => vi.fn());
+const listProfiles = vi.hoisted(() => vi.fn());
+const getProfile = vi.hoisted(() => vi.fn());
const applyAgentProfile = vi.hoisted(() => vi.fn());
-const getSavedSettings = vi.hoisted(() => vi.fn());
+const listAgentProfiles = vi.hoisted(() => vi.fn());
+const fetchSettings = vi.hoisted(() => vi.fn());
+const settingsSave = vi.hoisted(() => vi.fn());
const displayErrorToast = vi.hoisted(() => vi.fn());
-let finishSettingsSave: (() => void) | undefined;
+
+interface ScreenProps {
+ initialValueOverrides?: SettingsFormValues;
+ markInitialOverridesDirty?: boolean;
+ onSaveSuccess?: () => void;
+ onSaveControlChange: (control: SdkSectionSaveControl) => void;
+}
+
const formState = vi.hoisted(() => ({
- llm: {} as Record<string, unknown>,
- dirtyLlm: undefined as Record<string, unknown> | undefined,
backendKind: "local",
+ backendId: "local-backend",
+ /** Whether the active backend's health probe reports it connected. */
+ isConnected: true as boolean | null,
+ /** What the user changed in the form, as the coerced `llm` payload. */
+ dirtyLlm: {} as Record<string, unknown>,
+ view: "all" as "basic" | "advanced" | "all",
+ screenProps: undefined as ScreenProps | undefined,
+ subscriptionModels: undefined as string[] | undefined,
}));
+const llmField = (
+ key: string,
+ valueType: "string" | "number" = "string",
+ extra: Record<string, unknown> = {},
+) => ({
+ key,
+ label: key,
+ section: "llm",
+ section_label: "LLM",
+ value_type: valueType,
+ default: null,
+ choices: [],
+ depends_on: [],
+ prominence: "critical",
+ secret: key === "llm.api_key",
+ required: false,
+ ...extra,
+});
+
+const LLM_SCHEMA = vi.hoisted(() => ({ current: undefined as unknown }));
+LLM_SCHEMA.current = {
+ model_name: "AgentSettings",
+ sections: [
+ {
+ key: "llm",
+ label: "LLM",
+ fields: [
+ llmField("llm.model"),
+ llmField("llm.api_key"),
+ llmField("llm.base_url"),
+ llmField("llm.temperature", "number"),
+ llmField("llm.timeout", "number"),
+ llmField("llm.auth_type", "string", {
+ default: "api_key",
+ choices: [
+ { label: "API key", value: "api_key" },
+ { label: "Subscription", value: "subscription" },
+ ],
+ }),
+ ],
+ },
+ ],
+};
+
vi.mock("#/contexts/active-backend-context", () => ({
- useActiveBackend: () => ({ backend: { kind: formState.backendKind } }),
+ useActiveBackend: () => ({
+ backend: { kind: formState.backendKind, id: formState.backendId },
+ }),
+}));
+
+vi.mock("#/hooks/query/use-backends-health", () => ({
+ useBackendsHealth: (backends: { id: string }[]) =>
+ Object.fromEntries(
+ backends.map((backend) => [
+ backend.id,
+ { isConnected: formState.isConnected },
+ ]),
+ ),
}));
vi.mock("#/api/profiles-service/profiles-service.api", () => ({
- default: { saveProfile, activateProfile },
+ default: { saveProfile, activateProfile, listProfiles, getProfile },
}));
vi.mock("#/api/settings-service/settings-service.api", () => ({
default: {
- fetchSettingsFromApi: getSavedSettings,
+ fetchSettingsFromApi: fetchSettings,
invalidateCache: vi.fn(),
},
}));
@@ -35,6 +112,7 @@ vi.mock("#/api/settings-service/settings-service.api", () => ({
vi.mock("#/api/agent-profiles-service/agent-profiles-service.api", () => ({
WELL_KNOWN_DEFAULT_AGENT_PROFILE_NAME: "default",
default: {
+ listProfiles: listAgentProfiles,
saveProfile: applyAgentProfile,
getProfile: vi
.fn()
@@ -43,6 +121,18 @@ vi.mock("#/api/agent-profiles-service/agent-profiles-service.api", () => ({
},
}));
+vi.mock("#/hooks/query/use-settings", () => ({
+ useSettings: () => ({ data: undefined }),
+}));
+
+vi.mock("#/hooks/query/use-agent-settings-schema", () => ({
+ useAgentSettingsSchema: () => ({ data: LLM_SCHEMA.current, error: null }),
+}));
+
+vi.mock("#/hooks/query/use-llm-subscription-models", () => ({
+ useOpenAISubscriptionModels: () => ({ data: formState.subscriptionModels }),
+}));
+
vi.mock("#/hooks/query/use-free-models", () => ({
useDefaultModel: () => null,
useDefaultModelReady: () => true,
@@ -52,140 +142,460 @@ vi.mock("#/utils/custom-toast-handlers", () => ({
displayErrorToast,
}));
+// Stands in for the embedded LLM form: it starts from the overrides the step
+// passes, applies the user's changes from `formState.dirtyLlm` and exposes the
+// same save control as the real form.
vi.mock("#/routes/llm-settings", async () => {
const React = await import("react");
return {
- LlmSettingsScreen: ({
- onSaveControlChange,
- onSaveSuccess,
- }: {
- onSaveControlChange: (control: SdkSectionSaveControl) => void;
- onSaveSuccess: () => void;
- }) => {
- const canonicalLlm = formState.llm;
- finishSettingsSave = onSaveSuccess;
+ LlmSettingsScreen: (props: ScreenProps) => {
+ formState.screenProps = props;
+ const { onSaveControlChange } = props;
React.useEffect(() => {
- const buildControl = (isDirty: boolean): SdkSectionSaveControl => ({
- save: () => {
- onSaveControlChange(buildControl(false));
- finishSettingsSave?.();
- },
- isSaving: false,
- isDirty,
- values: Object.fromEntries(
- Object.entries(canonicalLlm).map(([key, value]) => [
+ const values: SettingsFormValues = {
+ ...(props.initialValueOverrides ?? {}),
+ ...Object.fromEntries(
+ Object.entries(formState.dirtyLlm).map(([key, value]) => [
`llm.${key}`,
String(value),
]),
),
- view: "basic",
- getDirtyPayload: () => ({ llm: formState.dirtyLlm ?? canonicalLlm }),
+ };
+ onSaveControlChange({
+ save: () => {
+ settingsSave();
+ props.onSaveSuccess?.();
+ },
+ isSaving: false,
+ isDirty:
+ props.markInitialOverridesDirty !== false ||
+ Object.keys(formState.dirtyLlm).length > 0,
+ values,
+ view: formState.view,
+ getDirtyPayload: () => ({ llm: formState.dirtyLlm }),
getSavePayload: () => ({
- agent_settings_diff: { llm: formState.dirtyLlm ?? canonicalLlm },
+ agent_settings_diff: { llm: formState.dirtyLlm },
}),
});
- onSaveControlChange(buildControl(true));
}, [onSaveControlChange]);
return <div data-testid="llm-settings-screen" />;
},
};
});
+const API_KEY_PROFILE_DEFAULTS = {
+ auth_type: "api_key",
+ subscription_vendor: null,
+ provider_connection_id: null,
+};
+
+function givenActiveProfile(name: string, config: Record<string, unknown>) {
+ listProfiles.mockResolvedValue({
+ profiles: [{ name }],
+ active_profile: name,
+ });
+ getProfile.mockResolvedValue({ name, config, api_key_set: true });
+}
+
+// Next stays disabled until the form has mounted from the profile it edits.
+async function clickNext() {
+ await screen.findByTestId("llm-settings-screen");
+ const nextButton = screen.getByTestId("onboarding-llm-next");
+ await waitFor(() => expect(nextButton).toBeEnabled());
+ await userEvent.click(nextButton);
+}
+
describe("SetupLlmStep", () => {
beforeEach(() => {
vi.clearAllMocks();
formState.backendKind = "local";
- formState.dirtyLlm = undefined;
- formState.llm = {
- model: "gpt-5.6-luna",
- auth_type: "subscription",
- subscription_vendor: "openai",
- temperature: 0.2,
- };
- finishSettingsSave = undefined;
+ formState.backendId = "local-backend";
+ formState.isConnected = true;
+ formState.dirtyLlm = {};
+ formState.view = "all";
+ formState.screenProps = undefined;
+ formState.subscriptionModels = undefined;
+ listProfiles.mockResolvedValue({ profiles: [], active_profile: null });
+ listAgentProfiles.mockResolvedValue({
+ profiles: [],
+ active_agent_profile_id: null,
+ });
+ getProfile.mockResolvedValue({ name: "", config: {}, api_key_set: false });
saveProfile.mockResolvedValue(undefined);
activateProfile.mockResolvedValue(undefined);
applyAgentProfile.mockResolvedValue(undefined);
- getSavedSettings.mockImplementation(async () => ({
- agent_settings: { llm: formState.llm },
- }));
});
- it("persists and activates the canonically serialized subscription profile", async () => {
+ it("edits the active profile and keeps its unchanged endpoint, key and options", async () => {
+ const activeConfig = {
+ model: "openai/previous-model",
+ base_url: "http://localhost:19118/v1",
+ api_key: "encrypted:test-key",
+ temperature: 0.2,
+ timeout: 30,
+ };
+ givenActiveProfile("previous", activeConfig);
+ formState.dirtyLlm = { model: "openai/mock-onboarding-model" };
const onNext = vi.fn();
renderWithProviders(<SetupLlmStep onBack={vi.fn()} onNext={onNext} />);
- await userEvent.click(await screen.findByTestId("onboarding-llm-next"));
+ await clickNext();
- await waitFor(() => {
- expect(saveProfile).toHaveBeenCalledWith("gpt-5.6-luna", {
- llm: {
- model: "gpt-5.6-luna",
- auth_type: "subscription",
- subscription_vendor: "openai",
- temperature: 0.2,
- },
- include_secrets: true,
- });
+ await waitFor(() => expect(onNext).toHaveBeenCalledTimes(1));
+ expect(getProfile).toHaveBeenCalledWith("previous", "encrypted");
+ // The form shows the active profile, its own model included.
+ expect(
+ screen.getByText("ONBOARDING$LLM_SUBTITLE_CURRENT_PROFILE"),
+ ).toBeInTheDocument();
+ expect(formState.screenProps?.markInitialOverridesDirty).toBe(false);
+ expect(formState.screenProps?.initialValueOverrides).toMatchObject({
+ "llm.model": "openai/previous-model",
+ "llm.api_key": "encrypted:test-key",
+ "llm.base_url": "http://localhost:19118/v1",
+ "llm.temperature": "0.2",
+ "llm.timeout": "30",
+ "llm.auth_type": "api_key",
});
- expect(activateProfile).toHaveBeenCalledWith("gpt-5.6-luna");
+ expect(saveProfile).toHaveBeenCalledWith("mock-onboarding-model", {
+ llm: {
+ ...activeConfig,
+ ...API_KEY_PROFILE_DEFAULTS,
+ model: "openai/mock-onboarding-model",
+ },
+ include_secrets: true,
+ });
+ expect(activateProfile).toHaveBeenCalledWith("mock-onboarding-model");
expect(applyAgentProfile).toHaveBeenCalledWith("default", {
agent_kind: "openhands",
- llm_profile_ref: "gpt-5.6-luna",
+ llm_profile_ref: "mock-onboarding-model",
});
- expect(onNext).toHaveBeenCalledTimes(1);
});
- it("preserves typed advanced options when creating the activated profile", async () => {
- formState.llm = {
+ it("neither reads nor writes the raw LLM settings on a local backend", async () => {
+ givenActiveProfile("previous", { model: "openai/previous-model" });
+ formState.dirtyLlm = { model: "openai/gpt-4o-mini", api_key: "sk-test" };
+ const onNext = vi.fn();
+ renderWithProviders(<SetupLlmStep onBack={vi.fn()} onNext={onNext} />);
+
+ await clickNext();
+
+ await waitFor(() => expect(onNext).toHaveBeenCalledTimes(1));
+ expect(fetchSettings).not.toHaveBeenCalled();
+ expect(settingsSave).not.toHaveBeenCalled();
+ });
+
+ it("starts from a fresh profile when no profile is active", async () => {
+ formState.dirtyLlm = {
model: "openai/gpt-4o-mini",
- api_key: "test-key",
- base_url: "http://localhost:19118/v1",
+ api_key: "sk-test",
timeout: 3,
- num_retries: 1,
- retry_min_wait: 0,
- retry_max_wait: 0,
- stream: true,
};
const onNext = vi.fn();
renderWithProviders(<SetupLlmStep onBack={vi.fn()} onNext={onNext} />);
- await userEvent.click(await screen.findByTestId("onboarding-llm-next"));
+ await clickNext();
+
+ await waitFor(() => expect(onNext).toHaveBeenCalledTimes(1));
+ expect(getProfile).not.toHaveBeenCalled();
+ expect(screen.getByText("ONBOARDING$LLM_SUBTITLE")).toBeInTheDocument();
+ expect(formState.screenProps?.initialValueOverrides).toMatchObject({
+ "llm.model": ONBOARDING_DEFAULT_LLM_MODEL,
+ "llm.api_key": "",
+ "llm.base_url": "",
+ "llm.auth_type": "api_key",
+ });
+ expect(saveProfile).toHaveBeenCalledWith("gpt-4o-mini", {
+ llm: {
+ ...API_KEY_PROFILE_DEFAULTS,
+ model: "openai/gpt-4o-mini",
+ api_key: "sk-test",
+ timeout: 3,
+ },
+ include_secrets: true,
+ });
+ });
+
+ it("starts from a fresh profile when the active profile no longer exists", async () => {
+ listProfiles.mockResolvedValue({
+ profiles: [{ name: "other" }],
+ active_profile: "deleted",
+ });
+ formState.dirtyLlm = { model: "openai/gpt-4o-mini" };
+ const onNext = vi.fn();
+ renderWithProviders(<SetupLlmStep onBack={vi.fn()} onNext={onNext} />);
+
+ await clickNext();
- await waitFor(() => {
- expect(saveProfile).toHaveBeenCalledWith("gpt-4o-mini", {
- llm: formState.llm,
- include_secrets: true,
- });
+ await waitFor(() => expect(onNext).toHaveBeenCalledTimes(1));
+ expect(getProfile).not.toHaveBeenCalled();
+ expect(saveProfile).toHaveBeenCalledWith("gpt-4o-mini", {
+ llm: { ...API_KEY_PROFILE_DEFAULTS, model: "openai/gpt-4o-mini" },
+ include_secrets: true,
+ });
+ });
+
+ it("waits for a backend, then fills the form from that backend's active profile", async () => {
+ // Public-mode onboarding mounts this step before the backend is added.
+ formState.backendId = "no-backend";
+ givenActiveProfile("previous", {
+ model: "openai/previous-model",
+ base_url: "http://localhost:19118/v1",
+ });
+ const { rerender } = renderWithProviders(
+ <SetupLlmStep onBack={vi.fn()} onNext={vi.fn()} />,
+ );
+
+ expect(screen.queryByTestId("llm-settings-screen")).toBeNull();
+ expect(screen.getByTestId("onboarding-llm-next")).toBeDisabled();
+ expect(listProfiles).not.toHaveBeenCalled();
+ expect(listAgentProfiles).not.toHaveBeenCalled();
+
+ formState.backendId = "local-backend";
+ rerender(<SetupLlmStep onBack={vi.fn()} onNext={vi.fn()} />);
+
+ await screen.findByTestId("llm-settings-screen");
+ expect(getProfile).toHaveBeenCalledWith("previous", "encrypted");
+ expect(formState.screenProps?.initialValueOverrides).toMatchObject({
+ "llm.base_url": "http://localhost:19118/v1",
+ });
+ });
+
+ it("waits for the backend to answer before reading its profiles", async () => {
+ // The step mounts with the rest of onboarding, often while a local Agent
+ // Server is still starting. Reading then would fail and leave an error.
+ formState.isConnected = null;
+ givenActiveProfile("previous", { model: "openai/previous-model" });
+ const { rerender } = renderWithProviders(
+ <SetupLlmStep onBack={vi.fn()} onNext={vi.fn()} />,
+ );
+
+ expect(screen.queryByTestId("llm-settings-screen")).toBeNull();
+ expect(screen.queryByTestId("onboarding-llm-load-error")).toBeNull();
+ expect(screen.getByTestId("onboarding-llm-next")).toBeDisabled();
+ expect(listProfiles).not.toHaveBeenCalled();
+ expect(listAgentProfiles).not.toHaveBeenCalled();
+
+ formState.isConnected = true;
+ rerender(<SetupLlmStep onBack={vi.fn()} onNext={vi.fn()} />);
+
+ await screen.findByTestId("llm-settings-screen");
+ expect(formState.screenProps?.initialValueOverrides).toMatchObject({
+ "llm.model": "openai/previous-model",
+ });
+ });
+
+ it("keeps an unchanged existing profile instead of saving a copy", async () => {
+ givenActiveProfile("my-deepseek", {
+ model: "deepseek/deepseek-flash",
+ base_url: "https://api.deepseek.com/v1",
+ api_key: "encrypted:test-key",
});
- expect(activateProfile).toHaveBeenCalledWith("gpt-4o-mini");
+ const onNext = vi.fn();
+ renderWithProviders(<SetupLlmStep onBack={vi.fn()} onNext={onNext} />);
+
+ await clickNext();
+
+ await waitFor(() => expect(onNext).toHaveBeenCalledTimes(1));
+ expect(saveProfile).not.toHaveBeenCalled();
+ expect(activateProfile).toHaveBeenCalledWith("my-deepseek");
expect(applyAgentProfile).toHaveBeenCalledWith("default", {
agent_kind: "openhands",
- llm_profile_ref: "gpt-4o-mini",
+ llm_profile_ref: "my-deepseek",
});
- expect(onNext).toHaveBeenCalledTimes(1);
});
- it("preserves unchanged endpoint, credentials and options outside the settings diff", async () => {
- formState.llm = {
- model: "openai/mock-onboarding-model",
- base_url: "http://localhost:19118/v1",
+ it("saves the prefilled default model for a fresh profile", async () => {
+ formState.view = "basic";
+ formState.dirtyLlm = { api_key: "sk-test" };
+ const onNext = vi.fn();
+ renderWithProviders(<SetupLlmStep onBack={vi.fn()} onNext={onNext} />);
+
+ await clickNext();
+
+ await waitFor(() => expect(onNext).toHaveBeenCalledTimes(1));
+ expect(saveProfile).toHaveBeenCalledWith("gpt-5.6-sol", {
+ llm: {
+ ...API_KEY_PROFILE_DEFAULTS,
+ model: ONBOARDING_DEFAULT_LLM_MODEL,
+ api_key: "sk-test",
+ },
+ include_secrets: true,
+ });
+ });
+
+ it("drops the hidden Base URL when the model changes in the Basic view", async () => {
+ givenActiveProfile("previous", {
+ model: "deepseek/deepseek-flash",
+ base_url: "https://api.deepseek.com/v1",
api_key: "encrypted:test-key",
+ });
+ formState.view = "basic";
+ formState.dirtyLlm = { model: "openai/gpt-4o-mini" };
+ const onNext = vi.fn();
+ renderWithProviders(<SetupLlmStep onBack={vi.fn()} onNext={onNext} />);
+
+ await clickNext();
+
+ await waitFor(() => expect(onNext).toHaveBeenCalledTimes(1));
+ expect(saveProfile).toHaveBeenCalledWith("gpt-4o-mini", {
+ llm: {
+ ...API_KEY_PROFILE_DEFAULTS,
+ model: "openai/gpt-4o-mini",
+ api_key: "encrypted:test-key",
+ },
+ include_secrets: true,
+ });
+ });
+
+ it("falls back to the profile the default agent profile points at", async () => {
+ // An older install: the Agent Server's backfill turned its raw LLM
+ // settings into the `default` LLM profile without activating it.
+ listProfiles.mockResolvedValue({
+ profiles: [{ name: "default" }],
+ active_profile: null,
+ });
+ listAgentProfiles.mockResolvedValue({
+ profiles: [{ name: "default", llm_profile_ref: "default" }],
+ active_agent_profile_id: "agent-1",
+ });
+ getProfile.mockResolvedValue({
+ name: "default",
+ config: {
+ model: "openai/legacy-model",
+ base_url: "http://legacy.example/v1",
+ api_key: "encrypted:legacy-key",
+ },
+ api_key_set: true,
+ });
+ renderWithProviders(<SetupLlmStep onBack={vi.fn()} onNext={vi.fn()} />);
+
+ await screen.findByTestId("llm-settings-screen");
+ expect(getProfile).toHaveBeenCalledWith("default", "encrypted");
+ // Listing the agent profiles is what runs the backfill, so it comes first.
+ expect(listAgentProfiles.mock.invocationCallOrder[0]).toBeLessThan(
+ listProfiles.mock.invocationCallOrder[0],
+ );
+ expect(formState.screenProps?.initialValueOverrides).toMatchObject({
+ "llm.model": "openai/legacy-model",
+ "llm.base_url": "http://legacy.example/v1",
+ "llm.api_key": "encrypted:legacy-key",
+ });
+ });
+
+ it("still edits the active profile when the agent profiles can't be listed", async () => {
+ // An older backend has no `/api/agent-profiles`.
+ listAgentProfiles.mockRejectedValue(new Error("Not Found"));
+ givenActiveProfile("previous", { model: "openai/previous-model" });
+ renderWithProviders(<SetupLlmStep onBack={vi.fn()} onNext={vi.fn()} />);
+
+ await screen.findByTestId("llm-settings-screen");
+ expect(screen.queryByTestId("onboarding-llm-load-error")).toBeNull();
+ expect(formState.screenProps?.initialValueOverrides).toMatchObject({
+ "llm.model": "openai/previous-model",
+ });
+ });
+
+ it("prefers the active LLM profile over the default agent profile's", async () => {
+ listProfiles.mockResolvedValue({
+ profiles: [{ name: "active-one" }, { name: "default" }],
+ active_profile: "active-one",
+ });
+ listAgentProfiles.mockResolvedValue({
+ profiles: [{ name: "default", llm_profile_ref: "default" }],
+ active_agent_profile_id: "agent-1",
+ });
+ renderWithProviders(<SetupLlmStep onBack={vi.fn()} onNext={vi.fn()} />);
+
+ await screen.findByTestId("llm-settings-screen");
+ expect(getProfile).toHaveBeenCalledTimes(1);
+ expect(getProfile).toHaveBeenCalledWith("active-one", "encrypted");
+ });
+
+ it("shows an error with a retry instead of a fresh form when the profiles can't be read", async () => {
+ listProfiles.mockRejectedValue(new Error("backend unavailable"));
+ renderWithProviders(<SetupLlmStep onBack={vi.fn()} onNext={vi.fn()} />);
+
+ await screen.findByTestId(
+ "onboarding-llm-load-error",
+ {},
+ { timeout: 4000 },
+ );
+ expect(screen.queryByTestId("llm-settings-screen")).toBeNull();
+ expect(screen.getByTestId("onboarding-llm-next")).toBeDisabled();
+
+ givenActiveProfile("previous", { model: "openai/previous-model" });
+ await userEvent.click(screen.getByTestId("onboarding-llm-load-retry"));
+
+ await screen.findByTestId("llm-settings-screen");
+ expect(formState.screenProps?.initialValueOverrides).toMatchObject({
+ "llm.model": "openai/previous-model",
+ });
+ });
+
+ it("saves a subscription profile without an inline key or Base URL", async () => {
+ givenActiveProfile("gpt-5.6-luna", {
+ model: "gpt-5.6-luna",
+ auth_type: "subscription",
+ subscription_vendor: "openai",
temperature: 0.2,
- timeout: 30,
- };
- formState.dirtyLlm = { model: formState.llm.model };
+ });
+ formState.dirtyLlm = { model: "gpt-5.6-luna" };
+ formState.subscriptionModels = ["gpt-5.6-luna", "gpt-5.6-sol"];
const onNext = vi.fn();
renderWithProviders(<SetupLlmStep onBack={vi.fn()} onNext={onNext} />);
- await userEvent.click(await screen.findByTestId("onboarding-llm-next"));
+ await clickNext();
await waitFor(() => expect(onNext).toHaveBeenCalledTimes(1));
- expect(getSavedSettings).toHaveBeenCalledWith("encrypted");
- expect(saveProfile).toHaveBeenCalledWith("mock-onboarding-model", {
- llm: formState.llm,
+ expect(saveProfile).toHaveBeenCalledWith("gpt-5.6-luna", {
+ llm: {
+ model: "gpt-5.6-luna",
+ auth_type: "subscription",
+ subscription_vendor: "openai",
+ provider_connection_id: null,
+ temperature: 0.2,
+ },
include_secrets: true,
});
+ expect(activateProfile).toHaveBeenCalledWith("gpt-5.6-luna");
+ });
+
+ it("saves the subscription model the picker shows when the form still holds another", async () => {
+ // Switching to subscription before its models load leaves the form's
+ // value at the default model while the picker shows the first model.
+ formState.dirtyLlm = { auth_type: "subscription" };
+ formState.subscriptionModels = ["gpt-5.6-luna", "gpt-5.6-sol-codex"];
+ const onNext = vi.fn();
+ renderWithProviders(<SetupLlmStep onBack={vi.fn()} onNext={onNext} />);
+
+ await clickNext();
+
+ await waitFor(() => expect(onNext).toHaveBeenCalledTimes(1));
+ expect(saveProfile).toHaveBeenCalledWith("gpt-5.6-luna", {
+ llm: {
+ model: "gpt-5.6-luna",
+ auth_type: "subscription",
+ subscription_vendor: "openai",
+ provider_connection_id: null,
+ },
+ include_secrets: true,
+ });
+ });
+
+ it("waits for the subscription models before saving a subscription profile", async () => {
+ formState.dirtyLlm = { auth_type: "subscription" };
+ const onNext = vi.fn();
+ renderWithProviders(<SetupLlmStep onBack={vi.fn()} onNext={onNext} />);
+
+ await clickNext();
+
+ await waitFor(() =>
+ expect(displayErrorToast).toHaveBeenCalledWith(
+ "Subscription models are not loaded yet.",
+ ),
+ );
+ expect(saveProfile).not.toHaveBeenCalled();
+ expect(onNext).not.toHaveBeenCalled();
});
it("keeps Cloud onboarding on its settings save path", async () => {
@@ -193,33 +603,43 @@ describe("SetupLlmStep", () => {
const onNext = vi.fn();
renderWithProviders(<SetupLlmStep onBack={vi.fn()} onNext={onNext} />);
- await userEvent.click(await screen.findByTestId("onboarding-llm-next"));
+ await clickNext();
await waitFor(() => expect(onNext).toHaveBeenCalledTimes(1));
- expect(getSavedSettings).not.toHaveBeenCalled();
+ expect(settingsSave).toHaveBeenCalledTimes(1);
+ expect(formState.screenProps?.initialValueOverrides).toEqual({
+ "llm.model": ONBOARDING_DEFAULT_LLM_MODEL,
+ });
+ expect(formState.screenProps?.markInitialOverridesDirty).toBe(true);
+ expect(listProfiles).not.toHaveBeenCalled();
+ expect(listAgentProfiles).not.toHaveBeenCalled();
+ expect(getProfile).not.toHaveBeenCalled();
expect(saveProfile).not.toHaveBeenCalled();
expect(activateProfile).not.toHaveBeenCalled();
expect(applyAgentProfile).not.toHaveBeenCalled();
});
it.each([
- ["saved settings read", getSavedSettings],
["profile save", saveProfile],
["profile activation", activateProfile],
- ])("does not advance when %s fails", async (_label, failingMutation) => {
- failingMutation.mockRejectedValueOnce(new Error("profile unavailable"));
+ ])("does not advance when the %s fails", async (_label, failingCall) => {
+ failingCall.mockRejectedValueOnce(new Error("profile unavailable"));
+ formState.dirtyLlm = { model: "openai/gpt-4o-mini", api_key: "sk-test" };
const onNext = vi.fn();
renderWithProviders(<SetupLlmStep onBack={vi.fn()} onNext={onNext} />);
- await userEvent.click(await screen.findByTestId("onboarding-llm-next"));
+ await clickNext();
await waitFor(() => expect(displayErrorToast).toHaveBeenCalled());
expect(onNext).not.toHaveBeenCalled();
- expect(applyAgentProfile).not.toHaveBeenCalled();
const nextButton = screen.getByTestId("onboarding-llm-next");
- expect(nextButton).toBeEnabled();
+ await waitFor(() => expect(nextButton).toBeEnabled());
await userEvent.click(nextButton);
await waitFor(() => expect(onNext).toHaveBeenCalledTimes(1));
+ expect(applyAgentProfile).toHaveBeenLastCalledWith("default", {
+ agent_kind: "openhands",
+ llm_profile_ref: "gpt-4o-mini",
+ });
});
});
diff --git a/src/components/features/onboarding/steps/setup-llm-step.tsx b/src/components/features/onboarding/steps/setup-llm-step.tsx
index 728c24934a..6f2a8ea1ba 100644
--- a/src/components/features/onboarding/steps/setup-llm-step.tsx
+++ b/src/components/features/onboarding/steps/setup-llm-step.tsx
@@ -1,9 +1,18 @@
import React from "react";
+import { useQuery } from "@tanstack/react-query";
import { useTranslation } from "react-i18next";
import { BrandButton } from "#/components/features/settings/brand-button";
import { I18nKey } from "#/i18n/declaration";
import { LlmSettingsScreen } from "#/routes/llm-settings";
import type { SdkSectionSaveControl } from "#/components/features/settings/sdk-settings/sdk-section-page";
+import {
+ buildProfileLlmConfig,
+ profileConfigToFormValues,
+} from "#/components/features/settings/llm-profiles/llm-profile-form";
+import { isNoBackend } from "#/api/backend-registry/active-store";
+import AgentProfilesService, {
+ WELL_KNOWN_DEFAULT_AGENT_PROFILE_NAME,
+} from "#/api/agent-profiles-service/agent-profiles-service.api";
import { useActiveBackend } from "#/contexts/active-backend-context";
import { useSaveLlmProfile } from "#/hooks/mutation/use-save-llm-profile";
import { useActivateLlmProfile } from "#/hooks/mutation/use-activate-llm-profile";
@@ -12,11 +21,23 @@ import {
useDefaultModel,
useDefaultModelReady,
} from "#/hooks/query/use-free-models";
+import { LLM_PROFILES_QUERY_KEYS } from "#/hooks/query/use-llm-profiles";
+import { useOpenAISubscriptionModels } from "#/hooks/query/use-llm-subscription-models";
+import { useSettings } from "#/hooks/query/use-settings";
+import { useAgentSettingsSchema } from "#/hooks/query/use-agent-settings-schema";
+import { useBackendsHealth } from "#/hooks/query/use-backends-health";
import { LlmSettingsInputsSkeleton } from "#/components/features/settings/llm-settings/llm-settings-inputs-skeleton";
import { deriveProfileNameFromModel } from "#/utils/derive-profile-name";
-import type { SaveProfileRequest } from "#/api/profiles-service/profiles-service.api";
-import SettingsService from "#/api/settings-service/settings-service.api";
+import ProfilesService, {
+ type SaveProfileRequest,
+} from "#/api/profiles-service/profiles-service.api";
import { displayErrorToast } from "#/utils/custom-toast-handlers";
+import type { SettingsFormValues } from "#/utils/sdk-settings-schema";
+import {
+ LLM_AUTH_TYPE_KEY,
+ LLM_AUTH_TYPE_SUBSCRIPTION,
+ resolveLlmAuthType,
+} from "#/constants/llm-subscription";
interface SetupLlmStepProps {
onBack: () => void;
@@ -25,22 +46,143 @@ interface SetupLlmStepProps {
/**
* Fallback when the backend has not exposed a DB-selected OpenHands default.
- * The onboarding override still marks the model dirty so Next persists the
- * suggested model immediately.
+ * A fresh profile starts with this model, and Next saves it even when the user
+ * leaves it as is. An existing profile keeps its own model.
*/
export const ONBOARDING_DEFAULT_LLM_MODEL = "openai/gpt-5.6-sol";
+interface ProfileSeed {
+ /** The existing LLM profile the form shows, or `null` for a fresh profile. */
+ profileName: string | null;
+ /** That profile's config (secrets encrypted), or `{}` for a fresh profile. */
+ baseConfig: Record<string, unknown>;
+ /** The form values that show that profile. */
+ initialValues: SettingsFormValues;
+}
+
+/**
+ * The LLM profile onboarding edits: the active LLM profile, else the one the
+ * `default` agent profile points at, else none (a fresh profile). Listing the
+ * agent profiles first also runs the Agent Server's one-time backfill, which
+ * turns an older install's raw LLM settings into an LLM profile named
+ * `default` and points the `default` agent profile at it, without activating
+ * it. The active profile comes first because a home launch runs it. The agent
+ * profiles are best-effort, as in `useApplyOnboardingAgentProfile`: an older
+ * backend without them still gets its active profile.
+ */
+async function loadOnboardingProfile(): Promise<{
+ profileName: string | null;
+ config: Record<string, unknown>;
+}> {
+ const agentProfiles = await AgentProfilesService.listProfiles().catch(
+ () => null,
+ );
+ const llmProfiles = await ProfilesService.listProfiles();
+ const existing = new Set(llmProfiles.profiles.map((profile) => profile.name));
+ const defaultAgentRef = agentProfiles?.profiles.find(
+ (profile) => profile.name === WELL_KNOWN_DEFAULT_AGENT_PROFILE_NAME,
+ )?.llm_profile_ref;
+ const profileName =
+ [llmProfiles.active_profile, defaultAgentRef].find(
+ (name): name is string => !!name && existing.has(name),
+ ) ?? null;
+ if (!profileName) return { profileName: null, config: {} };
+ const detail = await ProfilesService.getProfile(profileName, "encrypted");
+ return {
+ profileName,
+ config: (detail.config ?? {}) as Record<string, unknown>,
+ };
+}
+
+/**
+ * The profile the local LLM step edits (see `loadOnboardingProfile`). Raw LLM
+ * settings are never the source. The seed is taken once per backend, because
+ * the embedded form reads its initial values only when it mounts. Onboarding
+ * mounts this step before a public-mode user adds the backend, and often while
+ * a local Agent Server is still starting, so there is no seed until a backend
+ * exists and answers. A failed read is an error to retry, not a fresh profile:
+ * a fresh form would drop an endpoint the Basic view hides.
+ */
+function useOnboardingProfileSeed(isLocalBackend: boolean): {
+ seed: ProfileSeed | null;
+ isError: boolean;
+ retry: () => void;
+} {
+ const { backend, orgId } = useActiveBackend();
+ const hasBackend = isLocalBackend && !isNoBackend(backend);
+ const healthByBackendId = useBackendsHealth(hasBackend ? [backend] : []);
+ const enabled =
+ hasBackend && healthByBackendId[backend.id]?.isConnected === true;
+ const [seedState, setSeedState] = React.useState<{
+ backendId: string;
+ seed: ProfileSeed;
+ } | null>(null);
+ const seed = seedState?.backendId === backend.id ? seedState.seed : null;
+ const profile = useQuery({
+ queryKey: [
+ ...LLM_PROFILES_QUERY_KEYS.all,
+ "onboarding-seed",
+ backend.id,
+ orgId,
+ ],
+ queryFn: loadOnboardingProfile,
+ // Read once: the seed never changes, and saving or activating the new
+ // profile would otherwise refetch the secrets for nothing.
+ enabled: enabled && !seed,
+ // Keep the encrypted secrets out of the cache once the step unmounts.
+ gcTime: 0,
+ retry: 1,
+ meta: { disableToast: true },
+ });
+ const { data: settings } = useSettings();
+ const { data: schema, error: schemaError } = useAgentSettingsSchema(
+ settings?.agent_settings_schema,
+ );
+ const isSchemaSettled = !!schema || !!schemaError;
+
+ React.useEffect(() => {
+ if (!enabled || seed || !profile.data || !isSchemaSettled) return;
+ setSeedState({
+ backendId: backend.id,
+ seed: {
+ profileName: profile.data.profileName,
+ baseConfig: profile.data.config,
+ initialValues: profileConfigToFormValues(schema, profile.data.config),
+ },
+ });
+ }, [enabled, seed, backend.id, profile.data, isSchemaSettled, schema]);
+
+ const { refetch } = profile;
+ const retry = React.useCallback(() => {
+ void refetch();
+ }, [refetch]);
+
+ return {
+ seed,
+ isError: enabled && !seed && profile.isError && !profile.isFetching,
+ retry,
+ };
+}
+
/**
* Step 2: embed the LLM settings form. The screen runs in `embedded`
* mode (so it doesn't render its own sticky Save bar) and with
* `hideSaveButton` set, surfacing its save state via
* `onSaveControlChange`. We then render a single Next button at the
- * modal footer level matching the other onboarding steps; clicking
- * Next saves the form and `onSaveSuccess` advances to the next step.
+ * modal footer level matching the other onboarding steps.
*
- * If the form happens to be untouched (no dirty fields), Next falls
- * through to advancing without a save call, so users with already-
- * configured settings aren't blocked.
+ * On a local backend the step edits an LLM profile, like the profile editor
+ * in Settings: the form shows the profile `loadOnboardingProfile` picks, or a
+ * fresh one with the default model. If the user changes nothing, Next keeps
+ * that profile; otherwise it saves the form as a profile named after the
+ * model. Either way it activates the profile and points the `default` agent
+ * profile at it. Activation applies the profile to `agent_settings.llm` on the
+ * server, so the step never reads or writes raw LLM settings.
+ *
+ * On Cloud, Next saves the form to the settings and `onSaveSuccess` advances.
+ * The agent-profile ↔ LLM wiring is resolved server-side from those settings,
+ * and there is no client-writable cloud agent-profile ref to repoint here. If
+ * the form is untouched, Next advances without a save call.
*
* Note: returning Cloud users who already have an LLM configured are
* intercepted upstream by `OnboardingHost`, so they never reach this
@@ -57,100 +199,140 @@ export function SetupLlmStep({ onBack, onNext }: SetupLlmStepProps) {
const dbDefaultLlmModel = useDefaultModel();
const isDefaultModelReady = useDefaultModelReady();
const defaultLlmModel = dbDefaultLlmModel ?? ONBOARDING_DEFAULT_LLM_MODEL;
+ const {
+ seed: profileSeed,
+ isError: isProfileSeedError,
+ retry: retryProfileSeed,
+ } = useOnboardingProfileSeed(isLocalBackend);
const [saveControl, setSaveControl] =
React.useState<SdkSectionSaveControl | null>(null);
const [isFinalizing, setIsFinalizing] = React.useState(false);
- const [hasFinalizationError, setHasFinalizationError] = React.useState(false);
- const profileDraftRef = React.useRef<{
- name: string;
- llm: SaveProfileRequest["llm"];
- } | null>(null);
+ const isSubscriptionAuth =
+ resolveLlmAuthType(saveControl?.values[LLM_AUTH_TYPE_KEY]) ===
+ LLM_AUTH_TYPE_SUBSCRIPTION;
+ // Shares the form's query, so this reads the list its picker shows.
+ const { data: subscriptionModels } = useOpenAISubscriptionModels({
+ enabled: isLocalBackend && isSubscriptionAuth,
+ });
- // On local backends the LLM profiles list is the user-facing source of
- // truth; without this step the form save only updates agent_settings and
- // the new config never shows up in the profiles list ("ghost profile").
- // Returns the saved LLM profile name so the caller can point the active
- // AGENT profile at it (conversations launch from the agent profile, not the
- // active LLM profile).
- const persistAsProfile = React.useCallback(async (): Promise<
- string | null
- > => {
- if (!isLocalBackend) return null;
-
- let profileDraft = profileDraftRef.current;
- if (!profileDraft) {
- // A settings patch only contains changed fields. Read the complete saved
- // configuration so an unchanged endpoint, credential or option is not
- // lost when creating the profile. Keep secrets encrypted in the browser;
- // the profile endpoint decrypts them before persisting the profile.
- const settings = await SettingsService.fetchSettingsFromApi("encrypted");
- const llmConfig = settings.agent_settings.llm;
- if (!llmConfig || typeof llmConfig !== "object") {
- throw new Error("Saved LLM configuration is unavailable");
- }
- const model = (llmConfig as Record<string, unknown>).model;
- if (typeof model !== "string" || !model) {
- throw new Error("Saved LLM model is unavailable");
+ // An existing profile keeps its own model; only a fresh one gets the
+ // onboarding default, so the form never pairs the default model with
+ // another profile's key and endpoint.
+ const initialValueOverrides = React.useMemo(() => {
+ if (profileSeed?.profileName) return profileSeed.initialValues;
+ return {
+ ...(profileSeed?.initialValues ?? {}),
+ "llm.model": defaultLlmModel,
+ };
+ }, [profileSeed, defaultLlmModel]);
+
+ const activateForOnboarding = React.useCallback(
+ async (profileName: string) => {
+ await activateProfile.mutateAsync(profileName);
+ // Conversations launch from the active AGENT profile, so point it at the
+ // LLM the user just set up or kept (this also clears the "LLM not set
+ // up" banner). Otherwise it keeps its seeded llm_profile_ref, which may
+ // have no key.
+ await applyAgentProfile({
+ agent_kind: "openhands",
+ llm_profile_ref: profileName,
+ });
+ onNext();
+ },
+ [activateProfile, applyAgentProfile, onNext],
+ );
+
+ const persistProfile = React.useCallback(async () => {
+ if (!saveControl || !profileSeed) return;
+
+ // Unchanged existing profile: keep it as it is rather than saving a copy
+ // under the name derived from its model.
+ if (profileSeed.profileName && !saveControl.isDirty) {
+ setIsFinalizing(true);
+ try {
+ await activateForOnboarding(profileSeed.profileName);
+ } catch {
+ displayErrorToast(t(I18nKey.ERROR$GENERIC));
+ } finally {
+ setIsFinalizing(false);
}
- profileDraft = {
- name: deriveProfileNameFromModel(model),
- llm: llmConfig as SaveProfileRequest["llm"],
- };
- profileDraftRef.current = profileDraft;
+ return;
}
- await saveProfile.mutateAsync({
- name: profileDraft.name,
- request: { llm: profileDraft.llm, include_secrets: true },
+ let dirtyLlm: Record<string, unknown>;
+ try {
+ dirtyLlm = {
+ ...((saveControl.getDirtyPayload().llm ?? {}) as Record<
+ string,
+ unknown
+ >),
+ };
+ } catch (error) {
+ displayErrorToast(
+ error instanceof Error ? error.message : t(I18nKey.ERROR$GENERIC),
+ );
+ return;
+ }
+ // The form shows its model even when the user keeps it (a fresh profile's
+ // is the onboarding default), so the profile gets that model whether or
+ // not the field was edited.
+ if (!Object.prototype.hasOwnProperty.call(dirtyLlm, "model")) {
+ dirtyLlm.model = String(saveControl.values["llm.model"] ?? "");
+ }
+ if (isSubscriptionAuth && !subscriptionModels?.length) {
+ displayErrorToast("Subscription models are not loaded yet.");
+ return;
+ }
+ const { llmConfig } = buildProfileLlmConfig({
+ baseConfig: profileSeed.baseConfig,
+ dirtyLlm,
+ values: saveControl.values,
+ view: saveControl.view,
+ supportsConnections: true,
+ isCloud: false,
+ subscriptionModels,
});
- await activateProfile.mutateAsync(profileDraft.name);
- return profileDraft.name;
- }, [isLocalBackend, saveProfile, activateProfile]);
+ const model = typeof llmConfig.model === "string" ? llmConfig.model : "";
+ if (!model) {
+ displayErrorToast(t(I18nKey.SETTINGS$MODEL_REQUIRED));
+ return;
+ }
+ const profileName = deriveProfileNameFromModel(model);
- const handleSaveSuccess = React.useCallback(async () => {
setIsFinalizing(true);
- setHasFinalizationError(false);
try {
- const llmProfileName = await persistAsProfile();
- // Point the active AGENT profile at the LLM the user just configured so
- // the next conversation actually uses it (and the "LLM not set up"
- // banner clears). Without this the active agent profile keeps its
- // seeded llm_profile_ref, which has no key.
- //
- // Cloud intentionally skips this: `persistAsProfile` only creates/activates
- // a *local* LLM profile (it early-returns null off local backends), and on
- // cloud the agent-profile ↔ LLM wiring is resolved server-side from the
- // settings this step's form save already persisted — there is no
- // client-writable cloud agent-profile ref to repoint here. The ACP step
- // still calls applyAgentProfile because ACP agents carry no LLM ref and
- // persist their kind/model locally regardless of backend.
- if (llmProfileName) {
- await applyAgentProfile({
- agent_kind: "openhands",
- llm_profile_ref: llmProfileName,
- });
- }
- profileDraftRef.current = null;
- onNext();
+ await saveProfile.mutateAsync({
+ name: profileName,
+ request: {
+ llm: llmConfig as SaveProfileRequest["llm"],
+ include_secrets: true,
+ },
+ });
+ await activateForOnboarding(profileName);
} catch {
- setHasFinalizationError(true);
+ // Nothing advanced, so Next retries the whole save.
displayErrorToast(t(I18nKey.ERROR$GENERIC));
} finally {
setIsFinalizing(false);
}
- }, [persistAsProfile, applyAgentProfile, onNext, t]);
+ }, [
+ saveControl,
+ profileSeed,
+ isSubscriptionAuth,
+ subscriptionModels,
+ saveProfile,
+ activateForOnboarding,
+ t,
+ ]);
const handleNext = () => {
- if (saveControl?.isDirty) {
- profileDraftRef.current = null;
- setHasFinalizationError(false);
- saveControl.save();
- // `onSaveSuccess` (wired to `handleSaveSuccess` below) will advance
- // once the mutation resolves successfully.
+ if (isLocalBackend) {
+ void persistProfile();
return;
}
- if (hasFinalizationError) {
- void handleSaveSuccess();
+ if (saveControl?.isDirty) {
+ // `onSaveSuccess` advances once the settings save resolves.
+ saveControl.save();
return;
}
onNext();
@@ -166,7 +348,11 @@ export function SetupLlmStep({ onBack, onNext }: SetupLlmStepProps) {
{t(I18nKey.ONBOARDING$LLM_TITLE)}
</h2>
<p className="text-sm text-muted">
- {t(I18nKey.ONBOARDING$LLM_SUBTITLE)}
+ {t(
+ profileSeed?.profileName
+ ? I18nKey.ONBOARDING$LLM_SUBTITLE_CURRENT_PROFILE
+ : I18nKey.ONBOARDING$LLM_SUBTITLE,
+ )}
</p>
</header>
@@ -174,15 +360,34 @@ export function SetupLlmStep({ onBack, onNext }: SetupLlmStepProps) {
data-testid="onboarding-llm-settings"
className="flex min-h-0 flex-1 flex-col overflow-y-auto custom-scrollbar-always"
>
- {isDefaultModelReady ? (
+ {isProfileSeedError ? (
+ <div
+ data-testid="onboarding-llm-load-error"
+ className="flex flex-col items-start gap-3"
+ >
+ <p className="text-sm text-muted">
+ {t(I18nKey.ERROR$FAILED_TO_LOAD_PROFILE_TRY_AGAIN)}
+ </p>
+ <BrandButton
+ testId="onboarding-llm-load-retry"
+ type="button"
+ variant="secondary"
+ onClick={retryProfileSeed}
+ >
+ {t(I18nKey.AUTOMATIONS$ERROR_RETRY)}
+ </BrandButton>
+ </div>
+ ) : isDefaultModelReady && (!isLocalBackend || profileSeed) ? (
<LlmSettingsScreen
embedded
hideSaveButton
suppressSuccessToast
- initialValueOverrides={{
- "llm.model": defaultLlmModel,
- }}
- onSaveSuccess={handleSaveSuccess}
+ initialValueOverrides={initialValueOverrides}
+ // Local edits a profile, so like the profile editor only real
+ // changes are dirty. Cloud saves the model override to settings,
+ // so the override starts dirty there.
+ markInitialOverridesDirty={!isLocalBackend}
+ onSaveSuccess={isLocalBackend ? undefined : onNext}
onSaveControlChange={setSaveControl}
/>
) : (
@@ -205,6 +410,7 @@ export function SetupLlmStep({ onBack, onNext }: SetupLlmStepProps) {
variant="primary"
isDisabled={
!isDefaultModelReady ||
+ (isLocalBackend && (!profileSeed || !saveControl)) ||
(saveControl?.isSaving ?? false) ||
isFinalizing
}
diff --git a/src/components/features/settings/llm-profiles/llm-profile-form.ts b/src/components/features/settings/llm-profiles/llm-profile-form.ts
new file mode 100644
index 0000000000..9372a9cbc2
--- /dev/null
+++ b/src/components/features/settings/llm-profiles/llm-profile-form.ts
@@ -0,0 +1,181 @@
+import { LLM_PROVIDER_CONNECTION_KEY } from "#/constants/llm-provider-connection";
+import {
+ LLM_AUTH_TYPE_API_KEY,
+ LLM_AUTH_TYPE_KEY,
+ LLM_AUTH_TYPE_SUBSCRIPTION,
+ LLM_SUBSCRIPTION_VENDOR_KEY,
+ OPENAI_SUBSCRIPTION_VENDOR,
+ resolveLlmAuthType,
+} from "#/constants/llm-subscription";
+import type { SettingsSchema } from "#/types/settings";
+import { isOpenHandsProviderModel } from "#/utils/format-model-name";
+import {
+ normalizeFieldValue,
+ type SettingsFormValues,
+ type SettingsView,
+} from "#/utils/sdk-settings-schema";
+
+/**
+ * Form values for an LLM profile, so every tab of the embedded LLM form shows
+ * the profile's real values rather than the active settings. `config` is the
+ * profile's flat LLM config (`{ model, api_key, base_url, ... }`, with
+ * `api_key` encrypted); an empty config yields the schema defaults. Fields
+ * absent from the schema are not form values: pass `config` as the
+ * `baseConfig` of {@link buildProfileLlmConfig} to keep them on save.
+ */
+export function profileConfigToFormValues(
+ schema: SettingsSchema | null | undefined,
+ config: Record<string, unknown>,
+): SettingsFormValues {
+ const llmFields =
+ schema?.sections.find((section) => section.key === "llm")?.fields ?? [];
+ const values: SettingsFormValues = {};
+ for (const field of llmFields) {
+ const flatKey = field.key.startsWith("llm.")
+ ? field.key.slice("llm.".length)
+ : field.key;
+ values[field.key] = normalizeFieldValue(field, config[flatKey]);
+ }
+
+ // Safety net for the specially-rendered keys when the schema is
+ // unavailable, so the form still works without it.
+ if (llmFields.length === 0) {
+ values["llm.model"] = (config.model as string) ?? "";
+ values["llm.api_key"] = (config.api_key as string) ?? "";
+ values["llm.base_url"] = (config.base_url as string) ?? "";
+ values[LLM_AUTH_TYPE_KEY] = resolveLlmAuthType(config.auth_type);
+ values[LLM_SUBSCRIPTION_VENDOR_KEY] =
+ (config.subscription_vendor as string) ?? OPENAI_SUBSCRIPTION_VENDOR;
+ }
+
+ // Seed the provider-connection link explicitly (it is excluded from the
+ // schema-driven inputs), so an unchanged profile keeps its connection.
+ values[LLM_PROVIDER_CONNECTION_KEY] =
+ typeof config.provider_connection_id === "string"
+ ? config.provider_connection_id
+ : "";
+
+ return values;
+}
+
+export interface BuildProfileLlmConfigOptions {
+ /**
+ * The full LLM config of the profile the form was filled from, or `{}` for a
+ * new profile. Merging the form's changes over it preserves fields the user
+ * did not touch, including ones hidden in the current tab or absent from the
+ * schema; the backend replaces the whole LLM object, so a partial config
+ * would otherwise reset everything else to defaults.
+ */
+ baseConfig: Record<string, unknown>;
+ /** The form's coerced, dirty-only `llm` payload (`getDirtyPayload().llm`). */
+ dirtyLlm: Record<string, unknown>;
+ /** The form's current values (`SdkSectionSaveControl.values`). */
+ values: SettingsFormValues;
+ /** The form's current view (`SdkSectionSaveControl.view`). */
+ view: SettingsView;
+ /** Whether this backend can link a profile to a provider connection. */
+ supportsConnections: boolean;
+ isCloud: boolean;
+ /**
+ * The loaded subscription models. When given, a subscription profile whose
+ * model is not one of them gets the first, which is the model the form's
+ * subscription picker shows in that case.
+ */
+ subscriptionModels?: readonly string[];
+}
+
+/**
+ * The complete LLM config to save as a profile from an embedded LLM form, and
+ * the provider connection it links to (`""` when none). The same rules apply
+ * wherever a form edits a profile: the LLM profile editor and onboarding.
+ */
+export function buildProfileLlmConfig({
+ baseConfig,
+ dirtyLlm,
+ values,
+ view,
+ supportsConnections,
+ isCloud,
+ subscriptionModels,
+}: BuildProfileLlmConfigOptions): {
+ llmConfig: Record<string, unknown>;
+ connectionId: string;
+} {
+ const base = { ...baseConfig };
+ const didChangeModelInBasic =
+ view === "basic" &&
+ Object.prototype.hasOwnProperty.call(dirtyLlm, "model") &&
+ dirtyLlm.model !== base.model;
+ const llmConfig: Record<string, unknown> = { ...base, ...dirtyLlm };
+ const authType = resolveLlmAuthType(llmConfig.auth_type);
+
+ // A profile linked to a provider connection sources its credential from the
+ // connection, so it never carries an inline api_key / base_url. The form
+ // value is the source of truth: empty (or absent) means "not linked".
+ const connectionId = supportsConnections
+ ? String(values[LLM_PROVIDER_CONNECTION_KEY] ?? "").trim()
+ : "";
+
+ if (authType === LLM_AUTH_TYPE_SUBSCRIPTION) {
+ const model = typeof llmConfig.model === "string" ? llmConfig.model : "";
+ if (subscriptionModels?.length && !subscriptionModels.includes(model)) {
+ [llmConfig.model] = subscriptionModels;
+ }
+ llmConfig.auth_type = LLM_AUTH_TYPE_SUBSCRIPTION;
+ llmConfig.subscription_vendor = OPENAI_SUBSCRIPTION_VENDOR;
+ llmConfig.provider_connection_id = null;
+ delete llmConfig.api_key;
+ delete llmConfig.base_url;
+ } else if (connectionId) {
+ llmConfig.auth_type = LLM_AUTH_TYPE_API_KEY;
+ llmConfig.subscription_vendor = null;
+ llmConfig.provider_connection_id = connectionId;
+ delete llmConfig.api_key;
+ delete llmConfig.base_url;
+ } else {
+ llmConfig.auth_type = LLM_AUTH_TYPE_API_KEY;
+ llmConfig.subscription_vendor = null;
+ // Clear any prior link so unlinking sticks. Only relevant where provider
+ // connections exist; otherwise the field stays untouched below.
+ if (supportsConnections) llmConfig.provider_connection_id = null;
+
+ // On cloud the OpenHands provider is backed by a server-minted LLM key,
+ // so the profile must not carry an inline api_key / base_url — let the
+ // backend attach its own credential when the profile is saved.
+ const isCloudOpenHandsProvider =
+ isCloud &&
+ isOpenHandsProviderModel(
+ typeof llmConfig.model === "string" ? llmConfig.model : "",
+ );
+ if (isCloudOpenHandsProvider) {
+ delete llmConfig.api_key;
+ delete llmConfig.base_url;
+ } else {
+ // The Basic tab has no base_url field. Preserve an existing hidden value
+ // when the model did not actually change; if the user chooses a new model,
+ // drop the old base URL so provider defaults can apply to that model.
+ if (didChangeModelInBasic) {
+ delete llmConfig.base_url;
+ }
+
+ // API key handling: an empty value means "no change" (the UX doesn't
+ // support clearing a key). Preserve the existing encrypted key from the
+ // base profile, or omit api_key entirely for a new profile. A newly
+ // typed key arrives in `dirtyLlm` and wins.
+ if (
+ typeof llmConfig.api_key !== "string" ||
+ llmConfig.api_key.trim() === ""
+ ) {
+ const existingKey =
+ typeof base.api_key === "string" ? base.api_key : "";
+ if (existingKey) {
+ llmConfig.api_key = existingKey;
+ } else {
+ delete llmConfig.api_key;
+ }
+ }
+ }
+ }
+
+ return { llmConfig, connectionId };
+}
diff --git a/src/components/features/settings/llm-profiles/llm-settings-local-view.tsx b/src/components/features/settings/llm-profiles/llm-settings-local-view.tsx
index 521d43734c..1b3e12f6c4 100644
--- a/src/components/features/settings/llm-profiles/llm-settings-local-view.tsx
+++ b/src/components/features/settings/llm-profiles/llm-settings-local-view.tsx
@@ -9,10 +9,8 @@ import { useTranslation } from "react-i18next";
import { LlmProfilesManager } from "./llm-profiles-manager";
import { ProfileNameInput } from "./profile-name-input";
import { BrandButton } from "#/components/features/settings/brand-button";
-import {
- LlmSettingsScreen,
- LLM_PROVIDER_CONNECTION_KEY,
-} from "#/routes/llm-settings";
+import { LlmSettingsScreen } from "#/routes/llm-settings";
+import { LLM_PROVIDER_CONNECTION_KEY } from "#/constants/llm-provider-connection";
import { useActiveBackend } from "#/contexts/active-backend-context";
import { useSaveLlmProfile } from "#/hooks/mutation/use-save-llm-profile";
import { useActivateLlmProfile } from "#/hooks/mutation/use-activate-llm-profile";
@@ -38,20 +36,18 @@ import {
deriveProfileNameFromModel,
isProfileNameValid,
} from "#/utils/derive-profile-name";
-import { isOpenHandsProviderModel } from "#/utils/format-model-name";
import { SdkSectionSaveControl } from "../sdk-settings/sdk-section-page";
+import {
+ buildProfileLlmConfig,
+ profileConfigToFormValues,
+} from "./llm-profile-form";
import {
LLM_AUTH_TYPE_API_KEY,
LLM_AUTH_TYPE_KEY,
- LLM_AUTH_TYPE_SUBSCRIPTION,
LLM_SUBSCRIPTION_VENDOR_KEY,
OPENAI_SUBSCRIPTION_VENDOR,
- resolveLlmAuthType,
} from "#/constants/llm-subscription";
-import {
- normalizeFieldValue,
- SettingsFormValues,
-} from "#/utils/sdk-settings-schema";
+import { SettingsFormValues } from "#/utils/sdk-settings-schema";
import { BackNavButton } from "#/components/shared/buttons/back-nav-button";
import { Typography } from "#/ui/typography";
import { useSettingsSectionHeader } from "#/contexts/settings-section-header-context";
@@ -199,41 +195,10 @@ export function LlmSettingsLocalView() {
// active settings. Fields absent from the schema are still preserved
// on save via `baseConfig`. Read the schema from the ref so a schema
// that loaded during the `getProfile` await above is used.
- const schema = agentSchemaRef.current;
- const llmFields =
- schema?.sections.find((section) => section.key === "llm")?.fields ??
- [];
- const initialValues: SettingsFormValues = {};
- for (const field of llmFields) {
- const flatKey = field.key.startsWith("llm.")
- ? field.key.slice("llm.".length)
- : field.key;
- initialValues[field.key] = normalizeFieldValue(
- field,
- config[flatKey],
- );
- }
-
- // Safety net for the specially-rendered keys when the schema is
- // unavailable, so editing still works without it.
- if (llmFields.length === 0) {
- initialValues["llm.model"] = (config.model as string) ?? "";
- initialValues["llm.api_key"] = (config.api_key as string) ?? "";
- initialValues["llm.base_url"] = (config.base_url as string) ?? "";
- initialValues[LLM_AUTH_TYPE_KEY] = resolveLlmAuthType(
- config.auth_type,
- );
- initialValues[LLM_SUBSCRIPTION_VENDOR_KEY] =
- (config.subscription_vendor as string) ??
- OPENAI_SUBSCRIPTION_VENDOR;
- }
-
- // Seed the provider-connection link explicitly (it is excluded from the
- // schema-driven inputs), so an unchanged profile keeps its connection.
- initialValues[LLM_PROVIDER_CONNECTION_KEY] =
- typeof config.provider_connection_id === "string"
- ? config.provider_connection_id
- : "";
+ const initialValues = profileConfigToFormValues(
+ agentSchemaRef.current,
+ config,
+ );
setEditingProfile({ profile, initialValues, baseConfig: config });
setProfileName(profile.name);
@@ -299,80 +264,17 @@ export function LlmSettingsLocalView() {
return;
}
- const baseConfig =
- viewMode === "edit" && editingProfile?.baseConfig
- ? { ...editingProfile.baseConfig }
- : {};
- const didChangeModelInBasic =
- saveControl.view === "basic" &&
- Object.prototype.hasOwnProperty.call(dirtyLlm, "model") &&
- dirtyLlm.model !== baseConfig.model;
- const llmConfig: Record<string, unknown> = { ...baseConfig, ...dirtyLlm };
- const authType = resolveLlmAuthType(llmConfig.auth_type);
-
- // A profile linked to a provider connection sources its credential from the
- // connection, so it never carries an inline api_key / base_url. The form
- // value is the source of truth: empty (or absent) means "not linked".
- const connectionId = supportsConnections
- ? String(saveControl.values[LLM_PROVIDER_CONNECTION_KEY] ?? "").trim()
- : "";
-
- if (authType === LLM_AUTH_TYPE_SUBSCRIPTION) {
- llmConfig.auth_type = LLM_AUTH_TYPE_SUBSCRIPTION;
- llmConfig.subscription_vendor = OPENAI_SUBSCRIPTION_VENDOR;
- llmConfig.provider_connection_id = null;
- delete llmConfig.api_key;
- delete llmConfig.base_url;
- } else if (connectionId) {
- llmConfig.auth_type = LLM_AUTH_TYPE_API_KEY;
- llmConfig.subscription_vendor = null;
- llmConfig.provider_connection_id = connectionId;
- delete llmConfig.api_key;
- delete llmConfig.base_url;
- } else {
- llmConfig.auth_type = LLM_AUTH_TYPE_API_KEY;
- llmConfig.subscription_vendor = null;
- // Clear any prior link so unlinking sticks. Only relevant where provider
- // connections exist; otherwise the field stays untouched below.
- if (supportsConnections) llmConfig.provider_connection_id = null;
-
- // On cloud the OpenHands provider is backed by a server-minted LLM key,
- // so the profile must not carry an inline api_key / base_url — let the
- // backend attach its own credential when the profile is saved.
- const isCloudOpenHandsProvider =
- backend.kind === "cloud" &&
- isOpenHandsProviderModel(
- typeof llmConfig.model === "string" ? llmConfig.model : "",
- );
- if (isCloudOpenHandsProvider) {
- delete llmConfig.api_key;
- delete llmConfig.base_url;
- } else {
- // The Basic tab has no base_url field. Preserve an existing hidden value
- // when the model did not actually change; if the user chooses a new model,
- // drop the old base URL so provider defaults can apply to that model.
- if (didChangeModelInBasic) {
- delete llmConfig.base_url;
- }
-
- // API key handling: an empty value means "no change" (the UX doesn't
- // support clearing a key). In edit mode preserve the existing encrypted
- // key from the profile; in create mode omit api_key entirely. A newly
- // typed key arrives in `dirtyLlm` and wins.
- if (
- typeof llmConfig.api_key !== "string" ||
- llmConfig.api_key.trim() === ""
- ) {
- const existingKey =
- typeof baseConfig.api_key === "string" ? baseConfig.api_key : "";
- if (existingKey) {
- llmConfig.api_key = existingKey;
- } else {
- delete llmConfig.api_key;
- }
- }
- }
- }
+ const { llmConfig, connectionId } = buildProfileLlmConfig({
+ baseConfig:
+ viewMode === "edit" && editingProfile?.baseConfig
+ ? editingProfile.baseConfig
+ : {},
+ dirtyLlm,
+ values: saveControl.values,
+ view: saveControl.view,
+ supportsConnections,
+ isCloud: backend.kind === "cloud",
+ });
const model = typeof llmConfig.model === "string" ? llmConfig.model : "";
if (!model) {
diff --git a/src/constants/llm-provider-connection.ts b/src/constants/llm-provider-connection.ts
new file mode 100644
index 0000000000..ba7837680d
--- /dev/null
+++ b/src/constants/llm-provider-connection.ts
@@ -0,0 +1,2 @@
+/** Form-values key for the shared provider connection a profile links to. */
+export const LLM_PROVIDER_CONNECTION_KEY = "llm.provider_connection_id";
diff --git a/src/i18n/translation.json b/src/i18n/translation.json
index 73dc3a97ce..001d07a403 100644
--- a/src/i18n/translation.json
+++ b/src/i18n/translation.json
@@ -33268,6 +33268,23 @@
"tr": "Bir sağlayıcı ve model seçin. OpenAI GPT-5.6 Sol'i önceden seçtik.",
"uk": "Виберіть провайдера та модель. OpenAI GPT-5.6 Sol уже обрано."
},
+ "ONBOARDING$LLM_SUBTITLE_CURRENT_PROFILE": {
+ "en": "Pick a provider and model. We've filled in your current LLM profile.",
+ "ja": "プロバイダーとモデルを選択してください。現在の LLM プロファイルを入力済みです。",
+ "zh-CN": "选择提供商和模型。我们已填入你当前的 LLM 配置文件。",
+ "zh-TW": "選擇供應商與模型。我們已填入你目前的 LLM 設定檔。",
+ "ko-KR": "공급자와 모델을 선택하세요. 현재 LLM 프로필이 입력되어 있습니다.",
+ "no": "Velg en leverandør og modell. Vi har fylt inn din nåværende LLM-profil.",
+ "ar": "اختر مزوّدًا ونموذجًا. لقد عبّأنا ملف LLM الشخصي الحالي الخاص بك.",
+ "de": "Wählen Sie Anbieter und Modell. Wir haben Ihr aktuelles LLM-Profil eingetragen.",
+ "fr": "Choisissez un fournisseur et un modèle. Nous avons rempli votre profil LLM actuel.",
+ "it": "Scegli un provider e un modello. Abbiamo compilato il tuo profilo LLM attuale.",
+ "pt": "Escolha um provedor e modelo. Preenchemos o seu perfil de LLM atual.",
+ "es": "Elige un proveedor y modelo. Hemos rellenado tu perfil de LLM actual.",
+ "ca": "Trieu un proveïdor i model. Hem omplert el vostre perfil de LLM actual.",
+ "tr": "Bir sağlayıcı ve model seçin. Mevcut LLM profilinizi doldurduk.",
+ "uk": "Виберіть провайдера та модель. Ми заповнили ваш поточний профіль LLM."
+ },
"ONBOARDING$HELLO_TITLE": {
"en": "Say hello 👋",
"ja": "ハローと挨拶 👋",
diff --git a/src/routes/llm-settings.tsx b/src/routes/llm-settings.tsx
index c9990da6ea..90fa1d7306 100644
--- a/src/routes/llm-settings.tsx
+++ b/src/routes/llm-settings.tsx
@@ -40,9 +40,7 @@ import {
isOpenHandsProviderModel,
} from "#/utils/format-model-name";
import { FreeOpenHandsModelsNote } from "#/components/shared/free-models-note";
-
-/** Form-values key for the shared provider connection a profile links to. */
-export const LLM_PROVIDER_CONNECTION_KEY = "llm.provider_connection_id";
+import { LLM_PROVIDER_CONNECTION_KEY } from "#/constants/llm-provider-connection";
/** Dropdown sentinel for "no provider connection" (an inline key is used). */
const NO_PROVIDER_CONNECTION = "__none__";
diff --git a/tests/e2e/mock-llm/onboarding/mock-llm-onboarding-happy-path.spec.ts b/tests/e2e/mock-llm/onboarding/mock-llm-onboarding-happy-path.spec.ts
index 21eaf867df..41ba052f53 100644
--- a/tests/e2e/mock-llm/onboarding/mock-llm-onboarding-happy-path.spec.ts
+++ b/tests/e2e/mock-llm/onboarding/mock-llm-onboarding-happy-path.spec.ts
@@ -6,8 +6,9 @@
* Step 0 — Choose Agent: selects OpenHands and advances.
* Step 1 — Check Backend: waits for the connected banner, advances.
* Step 2 — Setup LLM: fills in the mock LLM model, base URL, and API
- * key (via "All" mode), and advances. The step persists settings
- * AND creates/activates a named profile automatically.
+ * key (via "All" mode), and advances. The step edits the active
+ * LLM profile: it saves the form as a profile named after the
+ * model and activates it, without writing raw LLM settings.
* Step 3 — Say Hello: verifies the Skip button is hidden (PR #1095),
* submits the default greeting, verifies the conversation is
* created and the browser navigates to it.
@@ -38,7 +39,6 @@ import {
BACKEND_URL,
waitForNonUserMessageText,
waitForAgentMessageContaining,
- ensureMockLLMProfileViaAPI,
} from "../utils/mock-llm-helpers";
import {
showOnboarding,
@@ -51,6 +51,10 @@ import {
const PROFILE_NAME = `mock-onboarding-${randomUUID()}`;
const MOCK_MODEL = `openai/${PROFILE_NAME}`;
+const PREVIOUS_PROFILE_NAME = `mock-before-onboarding-${randomUUID()}`;
+// Raw settings that disagree with the active profile. Onboarding edits the
+// profile, so this endpoint must never reach the form or the new profile.
+const STALE_SETTINGS_BASE_URL = "http://127.0.0.1:9/stale-raw-settings";
const REPLY_TOKEN = "ONBOARDING_HAPPY_PATH_REPLY_OK";
test.describe.configure({ mode: "serial" });
@@ -80,9 +84,36 @@ test.describe("onboarding happy path", () => {
expect(settings.ok()).toBe(true);
previousSettings = await settings.json();
- // Reproduce re-onboarding with an already-configured endpoint and key.
- // They are unchanged form values, so neither appears in the settings diff.
- await ensureMockLLMProfileViaAPI(request, "openai/mock-before-onboarding");
+ // Reproduce re-onboarding with an active profile that already has the
+ // endpoint and key. The form shows them, so the endpoint the test types
+ // again is an unchanged value that is absent from the form's changes.
+ const saved = await request.post(
+ `${BACKEND_URL}/api/profiles/${PREVIOUS_PROFILE_NAME}`,
+ {
+ headers,
+ data: {
+ llm: {
+ model: `openai/${PREVIOUS_PROFILE_NAME}`,
+ api_key: "mock-api-key-for-testing",
+ base_url: MOCK_LLM_AGENT_URL,
+ },
+ include_secrets: true,
+ },
+ },
+ );
+ expect(saved.ok(), "save the previous profile").toBe(true);
+ const activated = await request.post(
+ `${BACKEND_URL}/api/profiles/${PREVIOUS_PROFILE_NAME}/activate`,
+ { headers },
+ );
+ expect(activated.ok(), "activate the previous profile").toBe(true);
+ const staleSettings = await request.patch(`${BACKEND_URL}/api/settings`, {
+ headers,
+ data: {
+ agent_settings_diff: { llm: { base_url: STALE_SETTINGS_BASE_URL } },
+ },
+ });
+ expect(staleSettings.ok(), "write stale raw LLM settings").toBe(true);
await resetMockLLM(request);
});
@@ -118,13 +149,13 @@ test.describe("onboarding happy path", () => {
});
expect.soft(restored.ok(), "restore the previous settings").toBe(true);
}
- const deleted = await request.delete(
- `${BACKEND_URL}/api/profiles/${PROFILE_NAME}`,
- { headers },
- );
- expect
- .soft(deleted.ok(), "delete the onboarding test profile")
- .toBe(true);
+ for (const name of [PROFILE_NAME, PREVIOUS_PROFILE_NAME]) {
+ const deleted = await request.delete(
+ `${BACKEND_URL}/api/profiles/${name}`,
+ { headers },
+ );
+ expect.soft(deleted.ok(), `delete test profile ${name}`).toBe(true);
+ }
} finally {
await resetMockLLM(request);
}
@@ -197,6 +228,22 @@ test.describe("onboarding happy path", () => {
timeout: 10_000,
});
+ // The form shows the active profile's endpoint, not the raw settings.
+ await expect(page.getByTestId("base-url-input")).toHaveValue(
+ MOCK_LLM_AGENT_URL,
+ );
+
+ // The LLM step must not write raw LLM settings.
+ const settingsWrites: string[] = [];
+ page.on("request", (req) => {
+ if (
+ req.method() === "PATCH" &&
+ new URL(req.url()).pathname.endsWith("/api/settings")
+ ) {
+ settingsWrites.push(req.postData() ?? "");
+ }
+ });
+
// Fill in model
const modelInput = page.getByTestId("llm-custom-model-input");
await modelInput.click();
@@ -227,6 +274,7 @@ test.describe("onboarding happy path", () => {
model: MOCK_MODEL,
base_url: MOCK_LLM_AGENT_URL,
});
+ expect(settingsWrites, "settings PATCHes from the LLM step").toEqual([]);
});
// ── Step 3: Say Hello ───────────────────────────────────────────
diff --git a/tests/e2e/mock-llm/onboarding/mock-llm-onboarding-regressions.spec.ts b/tests/e2e/mock-llm/onboarding/mock-llm-onboarding-regressions.spec.ts
index 4ddc292ba3..c351d3b68e 100644
--- a/tests/e2e/mock-llm/onboarding/mock-llm-onboarding-regressions.spec.ts
+++ b/tests/e2e/mock-llm/onboarding/mock-llm-onboarding-regressions.spec.ts
@@ -86,6 +86,42 @@ test.describe("onboarding recent regressions", () => {
}
await route.fulfill({ response, json: body });
});
+ // The local LLM step edits the active LLM profile, else the one the
+ // `default` agent profile points at, and keeps that profile's model.
+ // Hide both, which earlier specs may have set, so the step starts a
+ // fresh profile with the default model, as on a first install.
+ await page.route("**/api/profiles", async (route, req) => {
+ if (req.method() !== "GET") {
+ await route.fallback();
+ return;
+ }
+ const response = await route.fetch();
+ const body = await response.json();
+ await route.fulfill({
+ response,
+ json: { ...body, active_profile: null },
+ });
+ });
+ await page.route("**/api/agent-profiles", async (route, req) => {
+ if (req.method() !== "GET") {
+ await route.fallback();
+ return;
+ }
+ const response = await route.fetch();
+ const body = await response.json();
+ await route.fulfill({
+ response,
+ json: {
+ ...body,
+ profiles: (body?.profiles ?? []).map(
+ (profile: { name?: string }) =>
+ profile.name === "default"
+ ? { ...profile, llm_profile_ref: null }
+ : profile,
+ ),
+ },
+ });
+ });
},
});
await advanceOnboardingToLlmStep(page);