The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): reveal manual model-name input when /v1/models discovery is empty
Hermes Agente2ee9a697811
diff --git a/apps/desktop/src/components/onboarding/index.test.tsx b/apps/desktop/src/components/onboarding/index.test.tsxindex 5753c21d11a..ae2e5d698f9 100644--- a/apps/desktop/src/components/onboarding/index.test.tsx+++ b/apps/desktop/src/components/onboarding/index.test.tsx@@ -1,11 +1,11 @@-import { cleanup, fireEvent, render, screen } from '@testing-library/react'-import { afterEach, describe, expect, it } from 'vitest'+import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react'+import { afterEach, describe, expect, it, vi } from 'vitest'import { $desktopOnboarding, type DesktopOnboardingState, type OnboardingContext } from '@/store/onboarding'import { makeOAuthProvider } from '@/test/oauth-provider'import type { OAuthProvider } from '@/types/hermes'-import { Picker } from '.'+import { ApiKeyForm, Picker } from '.'function setProviders(providers: OAuthProvider[]) {$desktopOnboarding.set({@@ -100,3 +100,57 @@ describe('onboarding Picker', () => {expect(screen.queryByRole('button', { name: "I'll choose a provider later" })).toBeNull()})})++describe('ApiKeyForm manual local-model fallback', () => {+ it('reveals the model-name input only after the endpoint enumerates no models, then forwards the name', async () => {+ // First Connect: reachable endpoint, empty /v1/models — the wizard must ask+ // for a manual model name instead of dead-ending. Second Connect: the typed+ // name is forwarded as the 5th onSave argument.+ const onSave = vi+ .fn<(envKey: string, value: string, name: string, apiKey?: string, modelName?: string) => Promise<{ message?: string; needsModelInput?: boolean; ok: boolean }>>()+ .mockResolvedValueOnce({+ ok: false,+ needsModelInput: true,+ message: "Connected, but it didn't enumerate any models at /v1/models."+ })+ .mockResolvedValueOnce({ ok: true })++ render(+ <ApiKeyForm+ canGoBack={false}+ initialEnvKey="OPENAI_BASE_URL"+ onBack={() => undefined}+ onSave={onSave}+ />+ )++ fireEvent.change(screen.getByPlaceholderText('http://127.0.0.1:8000/v1'), {+ target: { value: 'https://api.cohere.ai/compatibility/v1' }+ })++ // Hidden on the happy path — discovery hasn't failed yet.+ expect(screen.queryByPlaceholderText('Model name (e.g. command-a-plus-05-2026)')).toBeNull()++ fireEvent.click(screen.getByRole('button', { name: 'Connect' }))++ await waitFor(() => {+ expect(screen.getByPlaceholderText('Model name (e.g. command-a-plus-05-2026)')).toBeTruthy()+ })++ fireEvent.change(screen.getByPlaceholderText('Model name (e.g. command-a-plus-05-2026)'), {+ target: { value: 'command-a-plus-05-2026' }+ })+ fireEvent.click(screen.getByRole('button', { name: 'Connect' }))++ await waitFor(() => {+ // apiKey is the (empty) local-key field, forwarded as-is for the local option.+ expect(onSave).toHaveBeenLastCalledWith(+ 'OPENAI_BASE_URL',+ 'https://api.cohere.ai/compatibility/v1',+ 'Local / custom endpoint',+ '',+ 'command-a-plus-05-2026'+ )+ })+ })+})diff --git a/apps/desktop/src/components/onboarding/index.tsx b/apps/desktop/src/components/onboarding/index.tsxindex b53bcd83e0c..a8905e1f3bf 100644--- a/apps/desktop/src/components/onboarding/index.tsx+++ b/apps/desktop/src/components/onboarding/index.tsx@@ -628,7 +628,9 @@ export function Picker({ ctx }: { ctx: OnboardingContext }) {canGoBack={hasOauth && !localEndpoint}initialEnvKey={localEndpoint ? 'OPENAI_BASE_URL' : apiKeyInitialEnv}onBack={() => setOnboardingMode('oauth')}- onSave={(envKey, value, name, apiKey) => saveOnboardingApiKey(envKey, value, name, ctx, apiKey)}+ onSave={(envKey, value, name, apiKey, modelName) =>+ saveOnboardingApiKey(envKey, value, name, ctx, apiKey, modelName)+ }options={apiKeyOptions}/>{manual ? null : (@@ -749,7 +751,13 @@ export function ApiKeyForm({isSet?: (envKey: string) => booleanonBack: () => voidonClear?: (envKey: string) => void- onSave: (envKey: string, value: string, name: string, apiKey?: string) => Promise<{ message?: string; ok: boolean }>+ onSave: (+ envKey: string,+ value: string,+ name: string,+ apiKey?: string,+ modelName?: string+ ) => Promise<{ message?: string; needsModelInput?: boolean; ok: boolean }>options?: ApiKeyOption[]redactedValue?: (envKey: string) => null | string | undefined}) {@@ -761,6 +769,12 @@ export function ApiKeyForm({// Optional endpoint API key, only used by the local / custom endpoint option// (whose `value` is the base URL). Cleared whenever the option changes.const [localKey, setLocalKey] = useState('')+ // Optional manual model name, only used by the local / custom endpoint+ // option when the previous probe came back with zero /v1/models entries.+ // The input is hidden until the save call asks for it (needsModelInput), so+ // the happy path (discovery finds a model) stays uncluttered.+ const [modelName, setModelName] = useState('')+ const [showModelInput, setShowModelInput] = useState(false)const [saving, setSaving] = useState(false)const [error, setError] = useState<null | string>(null)// `options` can change at runtime when callers filter the catalog (e.g. the@@ -771,6 +785,8 @@ export function ApiKeyForm({setOption(options[0])setValue('')setLocalKey('')+ setModelName('')+ setShowModelInput(false)setError(null)}}, [option.envKey, options])@@ -783,6 +799,8 @@ export function ApiKeyForm({setOption(o)setValue('')setLocalKey('')+ setModelName('')+ setShowModelInput(false)setError(null)requestAnimationFrame(() => {entryRef.current?.scrollIntoView({ behavior: 'smooth', block: 'center' })@@ -796,8 +814,10 @@ export function ApiKeyForm({// placeholder so users can eyeball that the right key is in place.const currentRedacted = alreadySet ? (redactedValue?.(option.envKey) ?? null) : null// Only require a non-empty value — no length/format validation, so a short- // or unusual key can't block the user from continuing.- const canSave = value.trim().length >= 1+ // or unusual key can't block the user from continuing. When the manual model+ // input is showing, also require it to be filled (a saved endpoint without a+ // model is still broken from the runtime's POV).+ const canSave = value.trim().length >= 1 && (!isLocal || !showModelInput || modelName.trim().length >= 1)const optionCopy = t.onboarding.apiKeyOptions[option.id]const optionDescription = optionCopy?.description ?? option.description@@ -808,13 +828,29 @@ export function ApiKeyForm({setSaving(true)setError(null)- const result = await onSave(option.envKey, value, option.name, isLocal ? localKey : undefined)+ const result = await onSave(+ option.envKey,+ value,+ option.name,+ isLocal ? localKey : undefined,+ isLocal && showModelInput ? modelName : undefined+ )if (result.ok) {setValue('')setLocalKey('')+ setModelName('')+ setShowModelInput(false)} else {setError(result.message ?? t.onboarding.couldNotSave)++ // The save handler asks the wizard to reveal a manual model-name input+ // when the endpoint didn't enumerate any models at /v1/models — the path+ // for OpenAI-compatible SaaS (Cohere, auth-gated gateways, …) that+ // doesn't serve a discovery catalog in the OpenAI shape.+ if (result.needsModelInput) {+ setShowModelInput(true)+ }}setSaving(false)@@ -880,6 +916,17 @@ export function ApiKeyForm({value={localKey}/>) : null}+ {isLocal && showModelInput ? (+ <Input+ autoComplete="off"+ autoFocus+ className="font-mono"+ onChange={e => setModelName(e.target.value)}+ onKeyDown={e => isSubmitEnter(e) && void submit()}+ placeholder={t.onboarding.localModelNamePlaceholder}+ value={modelName}+ />+ ) : null}{error ? <p className="text-xs text-destructive">{error}</p> : null}</div>diff --git a/apps/desktop/src/i18n/de.ts b/apps/desktop/src/i18n/de.tsindex f189ab00622..107184eb8d6 100644--- a/apps/desktop/src/i18n/de.ts+++ b/apps/desktop/src/i18n/de.ts@@ -4793,6 +4793,7 @@ export const deOverrides = {replaceCurrent: 'Aktuellen Wert ersetzen',pasteApiKey: 'API-Key einfügen',localApiKeyPlaceholder: 'API-Key (optional – nur falls Ihr Endpunkt einen benötigt)',+ localModelNamePlaceholder: 'Modellname (z. B. command-a-plus-05-2026)',couldNotSave: 'Anmeldedaten konnten nicht gespeichert werden.',connecting: 'Verbinden',update: 'Aktualisieren',diff --git a/apps/desktop/src/i18n/en.ts b/apps/desktop/src/i18n/en.tsindex 0496caa058f..f6d0690ab80 100644--- a/apps/desktop/src/i18n/en.ts+++ b/apps/desktop/src/i18n/en.ts@@ -4397,6 +4397,7 @@ export const en: Translations = {replaceCurrent: 'Replace current value',pasteApiKey: 'Paste API key',localApiKeyPlaceholder: 'API key (optional — only if your endpoint requires one)',+ localModelNamePlaceholder: 'Model name (e.g. command-a-plus-05-2026)',couldNotSave: 'Could not save credential.',connecting: 'Connecting',update: 'Update',diff --git a/apps/desktop/src/i18n/es.ts b/apps/desktop/src/i18n/es.tsindex 645891048d8..357af915fe3 100644--- a/apps/desktop/src/i18n/es.ts+++ b/apps/desktop/src/i18n/es.ts@@ -4783,6 +4783,7 @@ export const esOverrides = {replaceCurrent: 'Reemplazar valor actual',pasteApiKey: 'Pegar clave API',localApiKeyPlaceholder: 'Clave API (opcional; solo si tu endpoint la requiere)',+ localModelNamePlaceholder: 'Nombre del modelo (p. ej. command-a-plus-05-2026)',couldNotSave: 'No se pudo guardar la credencial.',connecting: 'Conectando',update: 'Actualizar',diff --git a/apps/desktop/src/i18n/fr.ts b/apps/desktop/src/i18n/fr.tsindex 4405c1adc29..ab75fb95edc 100644--- a/apps/desktop/src/i18n/fr.ts+++ b/apps/desktop/src/i18n/fr.ts@@ -4804,6 +4804,7 @@ export const frOverrides = {replaceCurrent: 'Remplacer la valeur actuelle',pasteApiKey: 'Collez votre clé API',localApiKeyPlaceholder: 'Clé API (facultatif — uniquement si votre point de terminaison en requiert une)',+ localModelNamePlaceholder: 'Nom du modèle (ex. command-a-plus-05-2026)',couldNotSave: "Impossible d'enregistrer l'identifiant.",connecting: 'Connexion',update: 'Mettre à jour',diff --git a/apps/desktop/src/i18n/types.ts b/apps/desktop/src/i18n/types.tsindex 9b9703682ef..85590e4ca82 100644--- a/apps/desktop/src/i18n/types.ts+++ b/apps/desktop/src/i18n/types.ts@@ -3671,6 +3671,7 @@ export interface Translations {replaceCurrent: stringpasteApiKey: stringlocalApiKeyPlaceholder: string+ localModelNamePlaceholder: stringcouldNotSave: stringconnecting: stringupdate: stringdiff --git a/apps/desktop/src/i18n/zh.ts b/apps/desktop/src/i18n/zh.tsindex 9a858f94818..1b1e3650b08 100644--- a/apps/desktop/src/i18n/zh.ts+++ b/apps/desktop/src/i18n/zh.ts@@ -4152,6 +4152,7 @@ export const zh = defineLocale({replaceCurrent: '替换当前值',pasteApiKey: '粘贴 API 密钥',localApiKeyPlaceholder: 'API 密钥(可选 — 仅当端点需要时填写)',+ localModelNamePlaceholder: '模型名称(例如 command-a-plus-05-2026)',couldNotSave: '无法保存凭据。',connecting: '连接中',update: '更新',diff --git a/apps/desktop/src/store/onboarding.test.ts b/apps/desktop/src/store/onboarding.test.tsindex 38be4b6f1d7..4b85880d89f 100644--- a/apps/desktop/src/store/onboarding.test.ts+++ b/apps/desktop/src/store/onboarding.test.ts@@ -584,7 +584,7 @@ describe('saveOnboardingLocalEndpoint', () => {}}- it('errors when the endpoint advertises no models (nothing to route to)', async () => {+ it('returns needsModelInput when the endpoint advertises no models (nothing to route to)', async () => {const calls: string[] = []installApiMock(async ({ path }: { path: string }) => {calls.push(path)@@ -601,10 +601,92 @@ describe('saveOnboardingLocalEndpoint', () => {})expect(result.ok).toBe(false)+ // The wizard reads this discriminator to reveal a manual model-name input.+ expect(result.needsModelInput).toBe(true)+ expect(result.message).toMatch(/didn't enumerate any models|advertised no models/)// Must not attempt to persist an assignment without a model.expect(calls).not.toContain('/api/model/set')})+ it('uses a manually provided model name and skips discovery when /v1/models is empty', async () => {+ const calls: { body?: unknown; path: string }[] = []++ installApiMock(async ({ body, path }: { body?: unknown; path: string }) => {+ calls.push({ body, path })++ if (path === '/api/providers/validate') {+ // Endpoint reachable but the discovery list is empty — the bug-class+ // case the wizard used to hard-fail on.+ return { ok: true, reachable: true, message: '', models: [] }+ }++ if (path === '/api/model/set') {+ return {+ ok: true,+ provider: 'custom',+ model: 'command-a-plus-05-2026',+ base_url: 'https://api.cohere.ai/compatibility/v1'+ }+ }++ throw new Error(`unexpected api path: ${path}`)+ })++ const result = await saveOnboardingLocalEndpoint(+ 'https://api.cohere.ai/compatibility/v1',+ 'sk-secret',+ { requestGateway: readyGateway() },+ 'command-a-plus-05-2026'+ )++ expect(result.ok).toBe(true)++ const assign = calls.find(c => c.path === '/api/model/set')+ // The manually provided model name is persisted verbatim — the runtime+ // honors it the same way as discover_models: false + an explicit models:.+ expect(assign?.body).toMatchObject({+ scope: 'main',+ provider: 'custom',+ model: 'command-a-plus-05-2026',+ base_url: 'https://api.cohere.ai/compatibility/v1',+ api_key: 'sk-secret'+ })+ })++ it('uses a manually provided model name even when /v1/models enumerates models', async () => {+ // The user is allowed to override the auto-discovered default by typing a+ // model name before submitting. The wizard never pre-fills the model input+ // in the happy path, but the store function must still honor modelName+ // over probe.models[0] when both are available.+ const calls: { body?: unknown; path: string }[] = []++ installApiMock(async ({ body, path }: { body?: unknown; path: string }) => {+ calls.push({ body, path })++ if (path === '/api/providers/validate') {+ return { ok: true, reachable: true, message: '', models: ['llama-3.1-8b'] }+ }++ if (path === '/api/model/set') {+ return { ok: true, provider: 'custom', model: 'llama-3.1-8b', base_url: 'http://127.0.0.1:8000/v1' }+ }++ throw new Error(`unexpected api path: ${path}`)+ })++ const result = await saveOnboardingLocalEndpoint(+ 'http://127.0.0.1:8000/v1',+ '',+ { requestGateway: readyGateway() },+ ' llama-3.3-70b '+ )++ expect(result.ok).toBe(true)++ const assign = calls.find(c => c.path === '/api/model/set')+ expect(assign?.body).toMatchObject({ model: 'llama-3.3-70b' })+ })+it('auto-discovers the model and persists provider=custom + base_url, then finishes', async () => {const calls: { body?: unknown; path: string }[] = []diff --git a/apps/desktop/src/store/onboarding.ts b/apps/desktop/src/store/onboarding.tsindex 85f82edbede..85aac808c0b 100644--- a/apps/desktop/src/store/onboarding.ts+++ b/apps/desktop/src/store/onboarding.ts@@ -1038,7 +1038,13 @@ export async function saveOnboardingApiKey(// Optional endpoint key — only meaningful for the "Local / custom endpoint"// option, whose primary `value` is the base URL. Ignored for plain API-key// providers (their key IS `value`).- endpointApiKey?: string+ endpointApiKey?: string,+ // Optional manual model name — only meaningful for the "Local / custom+ // endpoint" option when /v1/models discovery returns an empty list (e.g.+ // Cohere's OpenAI-compatible endpoint, which serves no OpenAI-shaped model+ // catalog). Mirrors the runtime's `discover_models: false` + explicit+ // `models:` config path. Ignored for plain API-key providers.+ modelName?: string) {ctx = captureContext(ctx)const generation = flowGeneration@@ -1054,7 +1060,7 @@ export async function saveOnboardingApiKey(// base_url + model + api_key), not dropped into .env — runtime resolution// ignores OPENAI_BASE_URL.if (envKey === 'OPENAI_BASE_URL') {- return saveOnboardingLocalEndpoint(trimmed, endpointApiKey?.trim() ?? '', ctx)+ return saveOnboardingLocalEndpoint(trimmed, endpointApiKey?.trim() ?? '', ctx, modelName)}// No key validation here on purpose: we previously live-probed the key and@@ -1099,16 +1105,34 @@ export async function saveOnboardingApiKey(// endpoints that gate /v1/models behind auth still enumerate models) and// persisted to model.api_key so the runtime can authenticate.//+// If discovery returns no models — common for OpenAI-compatible SaaS that+// doesn't expose a /v1/models catalog in the OpenAI shape (Cohere's+// compatibility endpoint, auth-gated gateways, etc.) — we return+// `{ ok: false, needsModelInput: true, message }` so the wizard can reveal a+// manual model-name input. The runtime already supports this case via+// `discover_models: false` + an explicit `models:` list; the wizard was the+// only layer still hard-failing. A non-empty `modelName` argument is used+// verbatim instead of the discovered list.+//// We deliberately don't route through completeWithModelConfirm: that path// re-assigns the model from /api/model/options WITHOUT a base_url, which would// wipe the base_url we just wrote. We have a concrete model already, so we// verify the runtime directly and finish.-export async function saveOnboardingLocalEndpoint(baseUrl: string, apiKey: string, ctx: OnboardingContext) {+export async function saveOnboardingLocalEndpoint(+ baseUrl: string,+ apiKey: string,+ ctx: OnboardingContext,+ // Manual model name from the wizard. When non-empty it is persisted verbatim+ // — the same semantics as `discover_models: false` + an explicit `models:`+ // list in config.yaml.+ modelName?: string+) {ctx = captureContext(ctx)const generation = flowGenerationflowScope = ctx.scopeconst url = baseUrl.trim()const key = apiKey.trim()+ const manualModel = modelName?.trim() ?? ''if (!url) {return { ok: false, message: 'Enter the endpoint URL first.' }@@ -1144,10 +1168,21 @@ export async function saveOnboardingLocalEndpoint(baseUrl: string, apiKey: strinreturn { ok: false, message: `Could not reach ${url}.` }}+ // Prefer the user-supplied model name when present; fall back to discovery.+ if (manualModel) {+ model = manualModel+ }+if (!model) {+ // Probe succeeded but the endpoint didn't enumerate any models. The+ // endpoint likely *has* models — we just can't discover them through an+ // OpenAI-shaped /v1/models response. Signal the wizard to reveal a manual+ // model-name input rather than hard-failing; `needsModelInput` is the+ // discriminator the form reads.return {ok: false,- message: `Connected to ${url}, but it advertised no models at /v1/models. Start a model on that endpoint and try again.`+ needsModelInput: true,+ message: `Connected to ${url}, but it didn't enumerate any models at /v1/models. Enter a model name below (e.g. command-a-plus-05-2026) to continue.`}}