From 325e28bfa0e310fd36dd8ecb40ee8f565cc1fb66 Mon Sep 17 00:00:00 2001 From: lsdsjy <1356263+lsdsjy@users.noreply.github.com> Date: Sun, 20 Sep 2026 11:42:43 +0800 Subject: [PATCH] fix(ui-model-selection,llm-deepseek): prioritize account models and simplify provider label --- .../client/ui-model-selection/README.i18n.yaml | 4 ++-- packages/client/ui-model-selection/README.md | 2 +- .../client/ui-model-selection/README.zh.md | 2 +- .../src/client/ModelSelect.tsx | 8 +++++--- .../tests/expected/account-first.txt | 8 ++++++++ .../tests/model-select.client.spec.tsx | 18 ++++++++++++++++++ packages/llm/llm-deepseek/src/adapter.ts | 2 +- packages/llm/llm-deepseek/src/index.ts | 2 +- .../llm/llm-deepseek/tests/adapter.spec.ts | 12 ++++++------ 9 files changed, 43 insertions(+), 15 deletions(-) create mode 100644 packages/client/ui-model-selection/tests/expected/account-first.txt diff --git a/packages/client/ui-model-selection/README.i18n.yaml b/packages/client/ui-model-selection/README.i18n.yaml index 9ba09cab47..2b7317e90e 100644 --- a/packages/client/ui-model-selection/README.i18n.yaml +++ b/packages/client/ui-model-selection/README.i18n.yaml @@ -2,5 +2,5 @@ # side as of the last confirmed-consistent state. Both languages carry equal authority; # after editing either side, bring the other along and re-record with: # pnpm run verify-translation-pairing --write packages/client/ui-model-selection/README.md -README.md: 7afc8f158509e18e90236d6302ab51125fa7a891 -README.zh.md: c14ad7ab05af24c35727d42e6d843cbdaf20f332 +README.md: 9b73298b776d2f3d869a5da88db8d17e14f0f3a9 +README.zh.md: 4dbd077a30cbbaaefd9fabcbf1cc4661367a3069 diff --git a/packages/client/ui-model-selection/README.md b/packages/client/ui-model-selection/README.md index 7afc8f1585..9b73298b77 100644 --- a/packages/client/ui-model-selection/README.md +++ b/packages/client/ui-model-selection/README.md @@ -31,7 +31,7 @@ Mount this plugin alongside `ui-conversation` and the commands package; the comp ### Model and effort -Models stay grouped by provider. The composer menu shows model and effort names only. The `/model` popup shows provider names and catalog descriptions; it localizes the two built-in DeepSeek descriptions and leaves external provider descriptions verbatim. The popup applies the selected model's default effort; the composer can then choose any advertised effort. An adapter without reasoning metadata leaves the Effort row absent; there is no arbitrary effort input. +Models stay grouped by provider. The composer menu shows model and effort names only, with DeepSeek Account first; other providers retain their catalog order. The `/model` popup shows provider names and catalog descriptions; it localizes the two built-in DeepSeek descriptions and leaves external provider descriptions verbatim. The popup applies the selected model's default effort; the composer can then choose any advertised effort. An adapter without reasoning metadata leaves the Effort row absent; there is no arbitrary effort input. ### Unroutable sessions diff --git a/packages/client/ui-model-selection/README.zh.md b/packages/client/ui-model-selection/README.zh.md index c14ad7ab05..4dbd077a30 100644 --- a/packages/client/ui-model-selection/README.zh.md +++ b/packages/client/ui-model-selection/README.zh.md @@ -31,7 +31,7 @@ DeepSeek 账号和 API Key 路由显示为独立提供方分组,各自展示 ### 模型与推理强度 -模型按提供方分组。composer 菜单只显示模型与推理强度名称。`/model` 弹窗显示提供方名称与目录说明;其中两个内置 DeepSeek 模型的说明使用当前语言,外部提供方说明保持原文。弹窗应用所选模型的默认推理强度;composer 随后可以选择任一已公布的推理强度。适配器没有推理元数据时不显示 Effort 行;不存在任意推理强度输入。 +模型按提供方分组。composer 菜单只显示模型与推理强度名称,DeepSeek 账号置顶,其他提供方保持目录原有顺序。`/model` 弹窗显示提供方名称与目录说明;其中两个内置 DeepSeek 模型的说明使用当前语言,外部提供方说明保持原文。弹窗应用所选模型的默认推理强度;composer 随后可以选择任一已公布的推理强度。适配器没有推理元数据时不显示 Effort 行;不存在任意推理强度输入。 ### 不可路由的会话 diff --git a/packages/client/ui-model-selection/src/client/ModelSelect.tsx b/packages/client/ui-model-selection/src/client/ModelSelect.tsx index b9c8993563..5e33fbe526 100644 --- a/packages/client/ui-model-selection/src/client/ModelSelect.tsx +++ b/packages/client/ui-model-selection/src/client/ModelSelect.tsx @@ -75,7 +75,9 @@ export function ModelSelect( const itemRefs = useRef<(HTMLButtonElement | null)[]>([]) const id = useId() - const choices = useMemo(() => state.groups.flatMap(group => + const groups = useMemo(() => state.groups.toSorted((left, right) => + Number(right.id === 'deepseek-account') - Number(left.id === 'deepseek-account')), [state.groups]) + const choices = useMemo(() => groups.flatMap(group => group.models.map(model => ({ group, model, @@ -86,7 +88,7 @@ export function ModelSelect( ? {} : { reasoningEffort: model.reasoning.defaultEffort }, } satisfies ModelSelection, - }))), [state.groups]) + }))), [groups]) const selectedIndex = state.current === null ? -1 : choices.findIndex(c => c.selection.provider === state.current?.provider && c.selection.model === state.current.model) @@ -409,7 +411,7 @@ export function ModelSelect( ))}
- {state.groups.map((group) => { + {groups.map((group) => { const headingId = `${id}-${group.id}` return (
diff --git a/packages/client/ui-model-selection/tests/expected/account-first.txt b/packages/client/ui-model-selection/tests/expected/account-first.txt new file mode 100644 index 0000000000..304c901c9f --- /dev/null +++ b/packages/client/ui-model-selection/tests/expected/account-first.txt @@ -0,0 +1,8 @@ +deepseek-account-1 +deepseek-account-2 +custom-1 +custom-2 +deepseek-official-1 +deepseek-official-2 +another-1 +another-2 diff --git a/packages/client/ui-model-selection/tests/model-select.client.spec.tsx b/packages/client/ui-model-selection/tests/model-select.client.spec.tsx index 3ac3613aac..e71062bbdc 100644 --- a/packages/client/ui-model-selection/tests/model-select.client.spec.tsx +++ b/packages/client/ui-model-selection/tests/model-select.client.spec.tsx @@ -455,3 +455,21 @@ it('shows the unselected model control without a stale model or effort', async ( await expect(`${trigger.textContent}\n`).toMatchFileSnapshot('./expected/unselected-model.txt') expect(trigger.textContent).not.toContain('High') }) + + +it('places account models first while preserving other provider and model order', async () => { + const groups = ['custom', 'deepseek-official', 'deepseek-account', 'another'].map(id => ({ + id, name: id, models: [1, 2].map(index => ({ id: `${id}-${index}`, name: `${id}-${index}` })), + })) + const directory = createSnapshotStore(state({ current: null, groups })) + render() + fireEvent.click(screen.getByRole('button', { name: '请选择模型' })) + fireEvent.click(screen.getByRole('menuitem', { name: /模型/ })) + const names = screen.getAllByRole('menuitemradio').map(row => row.textContent) + expect(names).toEqual([ + 'deepseek-account-1', 'deepseek-account-2', 'custom-1', 'custom-2', + 'deepseek-official-1', 'deepseek-official-2', 'another-1', 'another-2', + ]) + expect(groups.map(group => group.id)).toEqual(['custom', 'deepseek-official', 'deepseek-account', 'another']) + await expect(`${names.join('\n')}\n`).toMatchFileSnapshot('./expected/account-first.txt') +}) diff --git a/packages/llm/llm-deepseek/src/adapter.ts b/packages/llm/llm-deepseek/src/adapter.ts index 568b3190e6..95add7b318 100644 --- a/packages/llm/llm-deepseek/src/adapter.ts +++ b/packages/llm/llm-deepseek/src/adapter.ts @@ -41,7 +41,7 @@ export class DeepSeekAdapter extends LlmAdapter { } } - override providerInfo(provider: string) { return { id: provider, name: provider === 'deepseek-account' ? 'DeepSeek Account' : 'DeepSeek (API Key)' } } + override providerInfo(provider: string) { return { id: provider, name: provider === 'deepseek-account' ? 'DeepSeek Account' : 'DeepSeek' } } override providerRetryPolicy(provider: string) { return this.implementation().providerRetryPolicy(provider) } override async listModels(provider: string) { try { await this.dependencies.resolveApiKey(this.dependencies.options()) } diff --git a/packages/llm/llm-deepseek/src/index.ts b/packages/llm/llm-deepseek/src/index.ts index f0c262c722..bd159998e3 100644 --- a/packages/llm/llm-deepseek/src/index.ts +++ b/packages/llm/llm-deepseek/src/index.ts @@ -133,7 +133,7 @@ export function apply(ctx: Context, config: Config): void { }, }) ctx.llm.registerConfigurableProviders([ - { provider: PROVIDER, displayName: 'DeepSeek (API Key)', settingsNs: NS, settingsPath: [] }, + { provider: PROVIDER, displayName: 'DeepSeek', settingsNs: NS, settingsPath: [] }, { provider: 'deepseek-account', displayName: 'DeepSeek Account', settingsNs: NS, settingsPath: [] }, ]) // Route effects bind to this apply fiber via the stable `ctx` reference, diff --git a/packages/llm/llm-deepseek/tests/adapter.spec.ts b/packages/llm/llm-deepseek/tests/adapter.spec.ts index 89d33d64b4..fb8c01a25a 100644 --- a/packages/llm/llm-deepseek/tests/adapter.spec.ts +++ b/packages/llm/llm-deepseek/tests/adapter.spec.ts @@ -1697,10 +1697,10 @@ describe('plugin registration and config', () => { protocol: 'chat-completions', baseURL: server.url, }) - expect(ctx.llm.listProviders()).toEqual([{ id: 'deepseek-official', name: 'DeepSeek (API Key)' }, { id: 'deepseek-account', name: 'DeepSeek Account' }]) + expect(ctx.llm.listProviders()).toEqual([{ id: 'deepseek-official', name: 'DeepSeek' }, { id: 'deepseek-account', name: 'DeepSeek Account' }]) expect(ctx.llm.listConfigurableProviders()).toEqual([{ provider: 'deepseek-official', - displayName: 'DeepSeek (API Key)', + displayName: 'DeepSeek', settingsNs: 'llm-deepseek', settingsPath: [], }, { provider: 'deepseek-account', displayName: 'DeepSeek Account', settingsNs: 'llm-deepseek', settingsPath: [] }]) @@ -1734,7 +1734,7 @@ describe('plugin registration and config', () => { const ctx = new Context() await ctx.plugin(LlmRuntime) await ctx.plugin(LlmDeepSeek, { protocol: 'chat-completions', baseURL: 'http://127.0.0.1:1' }) - expect(ctx.llm.listProviders()).toEqual([{ id: 'deepseek-official', name: 'DeepSeek (API Key)' }, { id: 'deepseek-account', name: 'DeepSeek Account' }]) + expect(ctx.llm.listProviders()).toEqual([{ id: 'deepseek-official', name: 'DeepSeek' }, { id: 'deepseek-account', name: 'DeepSeek Account' }]) await expect(ctx.llm.listModels('deepseek-official')).resolves.toEqual([ { provider: 'deepseek-official', id: 'deepseek-flash', name: 'DeepSeek-V41-Flash', inputModalities: ['text', 'image'] }, { @@ -2189,7 +2189,7 @@ describe('plugin registration and config', () => { const ctx = new Context() await ctx.plugin(LlmRuntime) await ctx.plugin(LlmDeepSeek, { protocol: 'chat-completions' }) - expect(ctx.llm.listProviders()).toEqual([{ id: 'deepseek-official', name: 'DeepSeek (API Key)' }, { id: 'deepseek-account', name: 'DeepSeek Account' }]) + expect(ctx.llm.listProviders()).toEqual([{ id: 'deepseek-official', name: 'DeepSeek' }, { id: 'deepseek-account', name: 'DeepSeek Account' }]) }) it('loads keyless, hides unavailable models, and fails the request actionably', async () => { @@ -2198,7 +2198,7 @@ describe('plugin registration and config', () => { await ctx.plugin(LlmRuntime) await ctx.plugin(LlmDeepSeek, { protocol: 'chat-completions', baseURL: 'http://127.0.0.1:1' }) // The registered provider remains configurable before its credential exists. - expect(ctx.llm.listProviders()).toEqual([{ id: 'deepseek-official', name: 'DeepSeek (API Key)' }, { id: 'deepseek-account', name: 'DeepSeek Account' }]) + expect(ctx.llm.listProviders()).toEqual([{ id: 'deepseek-official', name: 'DeepSeek' }, { id: 'deepseek-account', name: 'DeepSeek Account' }]) await expect(ctx.llm.listModels('deepseek-official')).resolves.toHaveLength(0) const first = await assemble(ctx, { model: 'deepseek-flash', messages: [] }) expect(first.finish).toMatchObject({ kind: 'error', failure: { code: 'MISSING_CREDENTIAL' } }) @@ -2279,7 +2279,7 @@ describe('plugin registration and config', () => { await ctx.plugin(LlmRuntime) // Registration succeeds; no call is made (would hit api.deepseek.com). await ctx.plugin(LlmDeepSeek, { protocol: 'chat-completions' }) - expect(ctx.llm.listProviders()).toEqual([{ id: 'deepseek-official', name: 'DeepSeek (API Key)' }, { id: 'deepseek-account', name: 'DeepSeek Account' }]) + expect(ctx.llm.listProviders()).toEqual([{ id: 'deepseek-official', name: 'DeepSeek' }, { id: 'deepseek-account', name: 'DeepSeek Account' }]) }) it('adapter is constructible directly for embedding over the shared resolver', async () => {