From 58dcd822837a9b97e37a17ffbfea8cd7b7adc374 Mon Sep 17 00:00:00 2001 From: wusumac <736139669@qq.com> Date: Sun, 8 Nov 2026 20:24:29 +0800 Subject: [PATCH] fix(web,shared): prefer hub custom Claude models and dedupe choices A custom endpoint can report aliases and resolved ids more than once, and the CLI catalog offers aliases the endpoint does not serve. Prefer the hub-configured custom list when present, fall back to the machine catalog, and emit one picker row per model value. via [HAPI](https://hapi.run) Co-Authored-By: HAPI Co-Authored-By: Claude Code --- shared/src/models.test.ts | 13 +++++++++++++ shared/src/models.ts | 11 ++++++++++- web/src/components/SessionChat.tsx | 10 +++++++--- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/shared/src/models.test.ts b/shared/src/models.test.ts index 84d1b3d8..5bc8b961 100644 --- a/shared/src/models.test.ts +++ b/shared/src/models.test.ts @@ -123,6 +123,19 @@ describe('getClaudeModelChoices', () => { { value: 'claude-custom', label: 'claude-custom', section: 'main' }, ]) }) + + test('lists each value once when a custom endpoint reports duplicate rows', () => { + const choices = getClaudeModelChoices([ + { value: 'deepseek-v4.1-flash[1m]', displayName: 'deepseek-v4.1-flash[1m]' }, + { value: 'deepseek-v4.1-flash', displayName: 'deepseek-v4.1-flash' }, + { value: 'deepseek-v4.1-flash[1m]', displayName: 'deepseek-v4.1-flash[1m]' }, + { value: 'deepseek-v4.1-flash[1m]' }, + ]) + expect(choices.map((choice) => choice.value)).toEqual([ + 'deepseek-v4.1-flash[1m]', + 'deepseek-v4.1-flash', + ]) + }) }) describe('getClaudeEffortLevelsForModel', () => { diff --git a/shared/src/models.ts b/shared/src/models.ts index 2aa609b3..71968f51 100644 --- a/shared/src/models.ts +++ b/shared/src/models.ts @@ -99,8 +99,17 @@ function getClaudeModelFamily(value: string): string { */ export function getClaudeModelChoices(catalog: readonly ClaudeModelSummary[]): ClaudeModelChoice[] { const families = new Set() + const seenValues = new Set() const choices: ClaudeModelChoice[] = catalog - .filter((model) => model.value !== 'default') + .filter((model) => { + // A custom endpoint can report the same id more than once (aliases + // and resolved ids overlap); each value is one row in the picker. + if (model.value === 'default' || seenValues.has(model.value)) { + return false + } + seenValues.add(model.value) + return true + }) .map((model) => { const family = getClaudeModelFamily(model.value) const section = families.has(family) ? 'other' : 'main' diff --git a/web/src/components/SessionChat.tsx b/web/src/components/SessionChat.tsx index ec971a32..4bef39d7 100644 --- a/web/src/components/SessionChat.tsx +++ b/web/src/components/SessionChat.tsx @@ -1202,9 +1202,13 @@ function SessionChatInner(props: SessionChatProps) { getClaudeEffortLevelsForModel(props.session.model ?? null, claudeModelsState.availableModels) ?.map((level) => ({ value: level })) ), [props.session.model, claudeModelsState.availableModels]) - // Machine catalog first; hub-configured custom Claude models fill in when - // the runner has no discovery catalog. - const claudeComposerModelOptions = claudeModelOptions ?? claudeCustomModelOptions + // Hub-configured custom Claude models describe what the session's endpoint + // actually serves; the CLI catalog is Anthropic's own model list and would + // offer aliases the endpoint does not have (and repeat resolved ids). + // Prefer the custom list when present; otherwise keep the machine catalog. + const claudeComposerModelOptions = (claudeCustomModelOptions?.length ?? 0) > 0 + ? claudeCustomModelOptions + : claudeModelOptions const piModelsState = usePiModels({ api: props.api, sessionId: props.session.id,