π OpenHands: AI-Driven Development
fix: preselect router classifier model so it is created when no profiles exist (#17835)
Juan Pedro Michelini Jorge953c944eee62
diff --git a/__tests__/components/settings/meta-llm-profiles/meta-llm-settings-view.test.tsx b/__tests__/components/settings/meta-llm-profiles/meta-llm-settings-view.test.tsxindex 1fcc72cb9e..2be93b087a 100644--- a/__tests__/components/settings/meta-llm-profiles/meta-llm-settings-view.test.tsx+++ b/__tests__/components/settings/meta-llm-profiles/meta-llm-settings-view.test.tsx@@ -291,6 +291,46 @@ describe("MetaLlmSettingsView", () => {await waitFor(() => expect(saveMutateAsync).toHaveBeenCalled());});+ it("creates the classifier model when no LLM profiles exist yet", async () => {+ const user = userEvent.setup();+ saveMutateAsync.mockResolvedValue({ name: "openhands-router-pro" });+ // No saved LLM profiles and no active meta-profile (fresh install).+ vi.mocked(useLlmProfilesHook.useLlmProfiles).mockReturnValue({+ data: { profiles: [], active_profile: null },+ isLoading: false,+ error: null,+ } as unknown as ReturnType<typeof useLlmProfilesHook.useLlmProfiles>);+ vi.mocked(useMetaProfilesHook.useMetaProfiles).mockReturnValue({+ data: { meta_profiles: [], active_meta_profile: null },+ isLoading: false,+ error: null,+ } as unknown as ReturnType<typeof useMetaProfilesHook.useMetaProfiles>);++ renderWithProviders(<MetaLlmSettingsView />);++ await openRouterProTemplate(user);+ await user.click(screen.getByTestId("meta-profile-save"));++ // The classifier model must be created just like the routed models.+ await waitFor(() =>+ expect(ProfilesService.saveProfile).toHaveBeenCalledWith("minimax-m3", {+ llm: {+ model: "openhands/minimax-m3",+ usage_id: "minimax-m3",+ provider_connection_id: "conn-openhands",+ },+ include_secrets: true,+ }),+ );+ // ...and every required model (table + classifier) is created.+ const expectedNames = collectRequiredRouterModelNames(+ DEFAULT_ROUTER_PRO_META_PROFILE_DEFAULT,+ );+ expect(ProfilesService.saveProfile).toHaveBeenCalledTimes(+ expectedNames.length,+ );+ });+it("activates the first meta-profile after creating it", async () => {const user = userEvent.setup();vi.mocked(useMetaProfilesHook.useMetaProfiles).mockReturnValue({diff --git a/__tests__/components/settings/meta-llm-profiles/meta-profile-editor.test.tsx b/__tests__/components/settings/meta-llm-profiles/meta-profile-editor.test.tsxindex 02ddf02b8e..1d6c9114f5 100644--- a/__tests__/components/settings/meta-llm-profiles/meta-profile-editor.test.tsx+++ b/__tests__/components/settings/meta-llm-profiles/meta-profile-editor.test.tsx@@ -265,4 +265,37 @@ describe("MetaProfileEditor", () => {await user.click(screen.getByTestId("meta-profile-cancel"));expect(onCancel).toHaveBeenCalled();});++ it("preselects the template classifier when no LLM profiles exist yet", async () => {+ const user = userEvent.setup();+ const onSave = vi.fn();+ renderWithProviders(+ <MetaProfileEditor+ mode="create"+ providerConnections={CONNECTIONS}+ selectRouterConnectionByDefault+ availableProfiles={[]}+ isSaving={false}+ onSave={onSave}+ onCancel={vi.fn()}+ />,+ );++ // The classifier named by the template must be shown even before any LLM+ // profile exists, so it survives into the saved config and gets created.+ expect(screen.getByTestId("meta-profile-classifier-input")).toHaveValue(+ DEFAULT_ROUTER_PRO_META_PROFILE_DEFAULT.classifier_model,+ );+ expect(screen.getByTestId("meta-profile-save")).toBeEnabled();++ await user.click(screen.getByTestId("meta-profile-save"));+ expect(onSave).toHaveBeenCalledWith(+ DEFAULT_ROUTER_PRO_META_PROFILE_NAME,+ expect.objectContaining({+ classifier_model:+ DEFAULT_ROUTER_PRO_META_PROFILE_DEFAULT.classifier_model,+ }),+ "conn-openhands",+ );+ });});diff --git a/src/components/features/settings/meta-llm-profiles/meta-profile-editor.tsx b/src/components/features/settings/meta-llm-profiles/meta-profile-editor.tsxindex 2a491d2a60..d281b72247 100644--- a/src/components/features/settings/meta-llm-profiles/meta-profile-editor.tsx+++ b/src/components/features/settings/meta-llm-profiles/meta-profile-editor.tsx@@ -135,10 +135,26 @@ export function MetaProfileEditor({showRouterConnectionPicker,]);- const profileItems = useMemo(- () => availableProfiles.map((p) => ({ key: p, label: p })),- [availableProfiles],- );+ // The classifier dropdown is driven by saved LLM profile names, but a router+ // template can name a classifier (e.g. ``minimax-m3``) before any profiles+ // exist. Without the value in the list, the Autocomplete's+ // ``defaultSelectedKey`` finds no match and renders an empty input β which+ // ``allowsCustomValue`` then syncs back as ``""``, dropping the classifier+ // from the saved config (so it never gets created). Surface the chosen+ // classifier as an item so it is genuinely preselected.+ const profileItems = useMemo(() => {+ const items = availableProfiles.map((p) => ({ key: p, label: p }));+ const classifier = config.classifier_model.trim();+ if (+ classifier &&+ !availableProfiles.some(+ (p) => p.toLowerCase() === classifier.toLowerCase(),+ )+ ) {+ items.push({ key: classifier, label: classifier });+ }+ return items;+ }, [availableProfiles, config.classifier_model]);const routerConnectionItems = useMemo(() => [{@@ -222,7 +238,7 @@ export function MetaProfileEditor({name="classifier_model"label={t(I18nKey.SETTINGS$META_PROFILE_CLASSIFIER)}items={profileItems}- defaultSelectedKey={startingConfig.classifier_model || undefined}+ selectedKey={config.classifier_model || undefined}allowsCustomValueisDisabled={isSaving}onInputChange={(value) =>