Skip to content

The agent that grows with you

fix(desktop): resync the Bot model picker's manual-entry state when the catalog resolves

Brooklyn Nicholson9fa36ea9e24b
diff --git a/apps/desktop/src/plugins/hermes-bots/model-picker.test.tsx b/apps/desktop/src/plugins/hermes-bots/model-picker.test.tsx
index aea6b7adf19..51733500780 100644
--- a/apps/desktop/src/plugins/hermes-bots/model-picker.test.tsx
+++ b/apps/desktop/src/plugins/hermes-bots/model-picker.test.tsx
@@ -20,7 +20,7 @@
import type * as HermesSdk from '@hermes/plugin-sdk'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
-import { render, waitFor } from '@testing-library/react'
+import { fireEvent, render, screen, waitFor } from '@testing-library/react'
import type { ReactNode } from 'react'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
@@ -79,6 +79,15 @@ function mount(bot: null | RosterRow) {
return render(<ModelPicker bot={bot} onChange={vi.fn()} value={{ model: '', provider: '' }} />, { wrapper })
}
+/** Mount with the selection a saved bot profile would carry into the editor. */
+function mountWithSelection(bot: null | RosterRow, value: { model: string; provider: string }) {
+ const wrapper = ({ children }: { children: ReactNode }) => (
+ <QueryClientProvider client={client}>{children}</QueryClientProvider>
+ )
+
+ return render(<ModelPicker bot={bot} onChange={vi.fn()} value={value} />, { wrapper })
+}
+
/** The fallback the picker paints when the catalog is unavailable. */
const isFreeText = (container: HTMLElement) =>
Boolean(container.querySelector('input[placeholder*="omnirouter"]')) &&
@@ -162,3 +171,43 @@ describe('the catalog read', () => {
await waitFor(() => expect(hostMock.requestProfile).toHaveBeenCalledTimes(1))
})
})
+
+describe('the manual-entry form vs the dropdowns (#121875)', () => {
+ it('shows the dropdowns on the FIRST open once the async catalog resolves', async () => {
+ // The saved provider is known to the catalog, but the read is still in
+ // flight at mount — exactly the first-open state of the Edit flow. The
+ // picker must not latch the manual-entry form from the empty inventory
+ // it paints before the data arrives.
+ let resolveCatalog!: (value: { providers: Array<{ models: string[]; name?: string; slug: string }> }) => void
+ hostMock.requestProfile.mockReturnValue(
+ new Promise(resolve => {
+ resolveCatalog = resolve
+ })
+ )
+
+ const { container } = mountWithSelection(remoteBot, { model: 'm1', provider: 'prov' })
+
+ // Still loading: spinner, no form yet.
+ expect(container.querySelector('[data-testid="spinner"]')).toBeTruthy()
+
+ resolveCatalog({ providers: [{ models: ['m1'], name: 'Prov', slug: 'prov' }] })
+
+ await waitFor(() => expect(container.querySelector('[data-testid="spinner"]')).toBeNull())
+ expect(isFreeText(container)).toBe(false)
+ })
+
+ it('keeps the manual form for a provider the catalog does not know, and Back to dropdowns still returns', async () => {
+ hostMock.requestProfile.mockResolvedValue({ providers: [{ models: ['m1'], slug: 'prov' }] })
+
+ const { container } = mountWithSelection(remoteBot, { model: 'custom-model', provider: 'my-router' })
+
+ // Unknown even to the LOADED inventory: the manual form is the only way
+ // to keep editing the hand-typed provider/model pair.
+ await waitFor(() => expect(isFreeText(container)).toBe(true))
+
+ // The explicit "Back to dropdowns" gesture still wins over the derived
+ // form — it is the user's choice, not the catalog's.
+ fireEvent.click(screen.getByRole('button'))
+ await waitFor(() => expect(isFreeText(container)).toBe(false))
+ })
+})
diff --git a/apps/desktop/src/plugins/hermes-bots/model-picker.tsx b/apps/desktop/src/plugins/hermes-bots/model-picker.tsx
index 7ee5a5d05d4..59510a6b63b 100644
--- a/apps/desktop/src/plugins/hermes-bots/model-picker.tsx
+++ b/apps/desktop/src/plugins/hermes-bots/model-picker.tsx
@@ -129,7 +129,16 @@ export function ModelPicker({ bot = null, value, onChange, placeholderModel }: M
const CUSTOM = '__custom__'
const providers = (data?.providers || []).filter(p => p && p.slug)
const isKnown = !value.provider || value.provider === NONE || providers.some(p => p.slug === value.provider)
- const [useFreeText, setUseFreeText] = useState(!isKnown)
+ // The manual-entry latch is the USER's choice only. Seeding it from
+ // `isKnown` froze whatever the catalog state was at first paint: on the
+ // first open the async read had not resolved yet, so a configured provider
+ // read as unknown and the picker latched into free text — the dropdown
+ // only appeared on the second open, from the cached catalog. `null` means
+ // "no user choice yet": derive from the LIVE catalog, so a provider the
+ // loaded inventory knows flips to the dropdowns when data arrives, while
+ // one it does not know still gets the free-text form.
+ const [manualEntry, setManualEntry] = useState<boolean | null>(null)
+ const useFreeText = manualEntry ?? !isKnown
if (isLoading) {
return (
@@ -202,7 +211,7 @@ export function ModelPicker({ bot = null, value, onChange, placeholderModel }: M
</div>
<Button
className="h-6 self-start text-xs text-(--ui-text-tertiary)"
- onClick={() => setUseFreeText(false)}
+ onClick={() => setManualEntry(false)}
size="sm"
variant="ghost"
>
@@ -230,7 +239,7 @@ export function ModelPicker({ bot = null, value, onChange, placeholderModel }: M
model: ''
})
} else if (v === CUSTOM) {
- setUseFreeText(true)
+ setManualEntry(true)
} else {
const prov = providers.find(p => p.slug === v)
const provModels = (prov?.models || []).map(m => (typeof m === 'string' ? m : m.id || m.name || ''))