Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): 隐藏辅助任务不可选模型
DavidShen27500261cd1b
diff --git a/apps/desktop/src/main/utility-model/__tests__/textOneshotPinOptions.test.ts b/apps/desktop/src/main/utility-model/__tests__/textOneshotPinOptions.test.tsindex 4c4b98ac83..6759794f87 100644--- a/apps/desktop/src/main/utility-model/__tests__/textOneshotPinOptions.test.ts+++ b/apps/desktop/src/main/utility-model/__tests__/textOneshotPinOptions.test.ts@@ -128,6 +128,29 @@ describe('buildTextOneshotPinOptions', () => {expect(options.map((o) => o.id)).toEqual(['cat:xd:codex:gpt-b']);});+ it('过滤目录视图中已停用的模型并透传默认可见性', () => {+ const options = buildTextOneshotPinOptions(+ catalogOf(+ provider({+ id: 'xd',+ models: {+ codex: [+ chat('disabled', { disabled: true }),+ chat('hidden-by-default', { defaultEnabled: false }),+ ],+ },+ }),+ ),+ undefined,+ );++ expect(options).toHaveLength(1);+ expect(options[0]).toMatchObject({+ id: 'cat:xd:codex:hidden-by-default',+ defaultEnabled: false,+ });+ });+it('非聊天模型过滤:mode 非聊天能态、mode 缺省但 group 是已知非聊天分类', () => {const options = buildTextOneshotPinOptions(catalogOf(@@ -396,4 +419,11 @@ describe('resolveOneshotCatalogModel', () => {expect(resolveOneshotCatalogModel(catalog, undefined, ' ')).toBeNull();expect(resolveOneshotCatalogModel(catalog, { disabledProviders: { xd: true } }, 'gpt-a')).toBeNull();});++ it('目录视图中已停用的模型不能作为声明路由', () => {+ const catalog = catalogOf(+ provider({ id: 'xd', models: { codex: [chat('gpt-disabled', { disabled: true })] } }),+ );+ expect(resolveOneshotCatalogModel(catalog, undefined, 'gpt-disabled')).toBeNull();+ });});diff --git a/apps/desktop/src/main/utility-model/textOneshotPinOptions.ts b/apps/desktop/src/main/utility-model/textOneshotPinOptions.tsindex a42e2ddc01..f236490a9c 100644--- a/apps/desktop/src/main/utility-model/textOneshotPinOptions.ts+++ b/apps/desktop/src/main/utility-model/textOneshotPinOptions.ts@@ -97,7 +97,8 @@ function isRoutableForOneshot(provider: Provider, agentKind: AgentKind): boolean* 更宽的判据会把 mode 缺省、group='image' 的网关条目放进钉档清单,钉死* 不回落 = 恒失败)。userProvider 标记镜像模型选择器的自定义供应商放行。 */function isChatModel(model: CatalogModel, provider: Provider): boolean {- return isAgentSelectableModel(model, { userProvider: provider.source === 'user' });+ return model.disabled !== true+ && isAgentSelectableModel(model, { userProvider: provider.source === 'user' });}const AGENT_LABEL: Record<(typeof ONESHOT_ROUTE_AGENTS)[number], string> = {@@ -133,6 +134,8 @@ export interface TextOneshotPinOption {modelId: string;/** 模型展示名(CatalogModel.name)。 */modelName: string;+ /** 模型选择器的目录默认可见性;缺省 = 可见。 */+ defaultEnabled?: boolean;/** 模型展示图标 id(CatalogModel.icon;未设定时渲染层回落供应商标)。 */icon?: string;/** 折扣路由条目(classifyModel = gpt-budget)——渲染层据此亮「折扣」徽标。 */@@ -234,6 +237,7 @@ export function buildTextOneshotPinOptions(agentKind: e.agentKind,modelId: e.model.id,modelName: e.model.name,+ ...(e.model.defaultEnabled !== undefined ? { defaultEnabled: e.model.defaultEnabled } : {}),...(e.model.icon !== undefined ? { icon: e.model.icon } : {}),budget: classifyModel(e.model) === 'gpt-budget',subscription: e.provider.access?.kind === 'subscription',diff --git a/apps/desktop/src/renderer/cindy-brain/OneshotModelPinPicker.tsx b/apps/desktop/src/renderer/cindy-brain/OneshotModelPinPicker.tsxindex 60d0ee182e..387e940b4b 100644--- a/apps/desktop/src/renderer/cindy-brain/OneshotModelPinPicker.tsx+++ b/apps/desktop/src/renderer/cindy-brain/OneshotModelPinPicker.tsx@@ -24,13 +24,14 @@ export interface OneshotPinOption {agentKind: string;modelId: string;modelName: string;+ defaultEnabled?: boolean;icon?: string;budget: boolean;subscription: boolean;/** Provider['routing'](IPC 载荷;ProviderLogoMark 的厂牌图标判定用)。 */routing?: import('@cindy/model-providers').Provider['routing'];agentSuffix?: string;- /** False for a persisted route that is no longer credential/catalog ready. */+ /** False for a persisted route that is no longer offered or currently usable. */available?: boolean;}diff --git a/apps/desktop/src/renderer/components/settings/AuxiliaryModelSection.tsx b/apps/desktop/src/renderer/components/settings/AuxiliaryModelSection.tsxindex 40acbefdd5..651b9579d2 100644--- a/apps/desktop/src/renderer/components/settings/AuxiliaryModelSection.tsx+++ b/apps/desktop/src/renderer/components/settings/AuxiliaryModelSection.tsx@@ -1,11 +1,12 @@/** Settings → Personalization: global models for short auxiliary text tasks. */-import { useCallback, useEffect, useRef, useState } from 'react';+import { useCallback, useEffect, useMemo, useRef, useState } from 'react';import { useTranslation } from 'react-i18next';import { OneshotModelPinPicker, type OneshotPinOption } from '@/cindy-brain/OneshotModelPinPicker';import { createLogger } from '@/lib/logger';import { toast } from '@/lib/toast';+import { isModelEnabled, useModelVisibilityVersion } from '@/state/modelVisibilityPrefs';import type {AuxiliaryModelSettingsKey,AuxiliaryModelSettingsState,@@ -18,6 +19,7 @@ export function AuxiliaryModelSection() {const [settings, setSettings] = useState<AuxiliaryModelSettingsState | null>(null);const [pending, setPending] = useState(false);const pendingRef = useRef(false);+ const modelVisibilityVersion = useModelVisibilityVersion();useEffect(() => {let disposed = false;@@ -55,6 +57,20 @@ export function AuxiliaryModelSection() {[t],);+ const options = useMemo<readonly OneshotPinOption[]>(+ () =>+ (settings?.options ?? []).map((option) => ({+ ...option,+ available:+ option.available !== false+ && isModelEnabled(option.agentKind, option.providerId, {+ id: option.modelId,+ defaultEnabled: option.defaultEnabled,+ }),+ })),+ [modelVisibilityVersion, settings?.options],+ );+if (!settings) return null;const picker = (key: AuxiliaryModelSettingsKey, ariaLabel: string, automaticLabel: string) => (@@ -62,7 +78,7 @@ export function AuxiliaryModelSection() {value={settings[key] ?? undefined}defaultLabel=""declaredLabel={null}- options={settings.options as readonly OneshotPinOption[]}+ options={options}onChange={(pin) => {void persist(key, pin);}}diff --git a/apps/desktop/src/renderer/components/settings/__tests__/AuxiliaryModelSection.test.tsx b/apps/desktop/src/renderer/components/settings/__tests__/AuxiliaryModelSection.test.tsxindex cc112820a7..22901b16e4 100644--- a/apps/desktop/src/renderer/components/settings/__tests__/AuxiliaryModelSection.test.tsx+++ b/apps/desktop/src/renderer/components/settings/__tests__/AuxiliaryModelSection.test.tsx@@ -12,6 +12,7 @@ const h = vi.hoisted(() => ({get: vi.fn(),set: vi.fn(),toastError: vi.fn(),+ isModelEnabled: vi.fn(),}));vi.mock('react-i18next', () => ({@@ -26,23 +27,36 @@ vi.mock('@/lib/toast', () => ({toast: { error: h.toastError },}));+vi.mock('@/state/modelVisibilityPrefs', () => ({+ isModelEnabled: h.isModelEnabled,+ useModelVisibilityVersion: () => 0,+}));+vi.mock('@/cindy-brain/OneshotModelPinPicker', () => ({OneshotModelPinPicker: ({value,onChange,ariaLabel,disabled,+ options,}: {value?: string;onChange: (pin: string | null) => void;ariaLabel: string;disabled?: boolean;+ options: Array<{ id: string; available?: boolean }>;}) => {const titleRow = ariaLabel.includes('sessionTitle');const pin = titleRow ? TITLE_PIN : RECOMMENDATION_PIN;+ const displayedOptions = options.filter(+ (option) => option.available !== false || option.id === value,+ );return (<div><span>{`${ariaLabel}:${value ?? 'automatic'}`}</span>+ <span data-testid={`${ariaLabel}:options`}>+ {displayedOptions.map((option) => `${option.id}:${option.available !== false}`).join('|')}+ </span><buttontype="button"aria-label={`${ariaLabel}:select`}@@ -97,6 +111,7 @@ describe('AuxiliaryModelSection', () => {beforeEach(() => {vi.clearAllMocks();installApi();+ h.isModelEnabled.mockReturnValue(true);h.get.mockResolvedValue(state());h.set.mockImplementation(async (patch: Partial<AuxiliaryModelSettingsState>) => state(patch));});@@ -146,4 +161,90 @@ describe('AuxiliaryModelSection', () => {);await waitFor(() => expect(h.set).toHaveBeenCalledWith({ sessionTitleModel: null }));});++ it('does not offer models hidden from the regular model selector', async () => {+ const hiddenPin = 'cat:xd:codex:claude-opus-5';+ const visiblePin = 'cat:xd:codex:deepseek/deepseek-v4-flash';+ h.isModelEnabled.mockImplementation(+ (_agent: string, _providerId: string, model: { id: string }) =>+ model.id !== 'claude-opus-5',+ );+ h.get.mockResolvedValue(+ state({+ options: [+ {+ id: hiddenPin,+ label: 'Claude Opus 5 · XD Gateway',+ group: 'XD Gateway',+ providerId: 'xd',+ agentKind: 'codex',+ modelId: 'claude-opus-5',+ modelName: 'Claude Opus 5',+ budget: false,+ subscription: false,+ available: true,+ },+ {+ id: visiblePin,+ label: 'DeepSeek V4 Flash · XD Gateway',+ group: 'XD Gateway',+ providerId: 'xd',+ agentKind: 'codex',+ modelId: 'deepseek/deepseek-v4-flash',+ modelName: 'DeepSeek V4 Flash',+ budget: false,+ subscription: false,+ available: true,+ },+ ],+ }),+ );++ render(<AuxiliaryModelSection />);++ const titleOptions = await screen.findByTestId(+ 'settings.auxiliaryModels.sessionTitle.ariaLabel:options',+ );+ const recommendationOptions = screen.getByTestId(+ 'settings.auxiliaryModels.promptRecommendation.ariaLabel:options',+ );+ expect(titleOptions.textContent).toBe(`${visiblePin}:true`);+ expect(recommendationOptions.textContent).toBe(`${visiblePin}:true`);+ });++ it('keeps a selected hidden model visible only as an unavailable value', async () => {+ const hiddenPin = 'cat:xd:codex:claude-opus-5';+ h.isModelEnabled.mockReturnValue(false);+ h.get.mockResolvedValue(+ state({+ sessionTitleModel: hiddenPin,+ options: [+ {+ id: hiddenPin,+ label: 'Claude Opus 5 · XD Gateway',+ group: 'XD Gateway',+ providerId: 'xd',+ agentKind: 'codex',+ modelId: 'claude-opus-5',+ modelName: 'Claude Opus 5',+ defaultEnabled: false,+ budget: false,+ subscription: false,+ available: true,+ },+ ],+ }),+ );++ render(<AuxiliaryModelSection />);++ expect(+ (await screen.findByTestId('settings.auxiliaryModels.sessionTitle.ariaLabel:options'))+ .textContent,+ ).toBe(`${hiddenPin}:false`);+ expect(+ screen.getByTestId('settings.auxiliaryModels.promptRecommendation.ariaLabel:options')+ .textContent,+ ).toBe('');+ });});diff --git a/apps/desktop/src/shared/auxiliaryModelSettings.ts b/apps/desktop/src/shared/auxiliaryModelSettings.tsindex 7add9bf20c..3f1ef73ffe 100644--- a/apps/desktop/src/shared/auxiliaryModelSettings.ts+++ b/apps/desktop/src/shared/auxiliaryModelSettings.ts@@ -29,6 +29,8 @@ export interface AuxiliaryModelOption {agentKind: 'codex' | 'claude-code';modelId: string;modelName: string;+ /** Follow the same default visibility as the regular model selector. */+ defaultEnabled?: boolean;icon?: string;budget: boolean;subscription: boolean;