Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(providers): 辅助模型名称跟随实时目录

Dash28cc516f1fad
diff --git a/apps/desktop/src/renderer/cindy-brain/OneshotModelPinPicker.tsx b/apps/desktop/src/renderer/cindy-brain/OneshotModelPinPicker.tsx
index 6ce1eb4ec9..33c8ecd4fe 100644
--- a/apps/desktop/src/renderer/cindy-brain/OneshotModelPinPicker.tsx
+++ b/apps/desktop/src/renderer/cindy-brain/OneshotModelPinPicker.tsx
@@ -3,7 +3,7 @@ import { useMemo, type ReactNode } from 'react';
import { useTranslation } from 'react-i18next';
import type { AgentKind, ProviderView } from '@cindy/model-providers';
import { ModelSelector } from '@/components/new-chat/ModelSelector';
-import { PROVIDER_TITLE_KEY } from '@/lib/providerDisplayName';
+import { PROVIDER_TITLE_KEY, providerDisplayName } from '@/lib/providerDisplayName';
import { decodeCatalogModelPin } from '../../shared/catalogModelPin';
/** 主侧下发的目录钉条目(与 TextOneshotPinOption 同形;系统辅助模型设置使用)。 */
@@ -93,8 +93,9 @@ export function OneshotModelPinPicker({
const route = current ?? (decoded ? { ...decoded, modelId: decoded.model } : null);
const providers = useMemo(() => oneshotPickerProviders(options).map((provider) => ({
...provider,
- name: groupByProvider && PROVIDER_TITLE_KEY[provider.id]
- ? t(PROVIDER_TITLE_KEY[provider.id]!) : provider.name,
+ name: provider.id === 'xd' ? providerDisplayName(provider, t)
+ : groupByProvider && PROVIDER_TITLE_KEY[provider.id]
+ ? t(PROVIDER_TITLE_KEY[provider.id]!) : provider.name,
})), [options, groupByProvider, t]);
const currentAgent = route && knownAgent(route.agentKind) ? route.agentKind : undefined;
const vendor = currentAgent === 'claude-code' ? 'cc' : currentAgent;
diff --git a/apps/desktop/src/renderer/cindy-brain/__tests__/OneshotModelPinPicker.test.tsx b/apps/desktop/src/renderer/cindy-brain/__tests__/OneshotModelPinPicker.test.tsx
index a5a0e31d0d..2b6a618426 100644
--- a/apps/desktop/src/renderer/cindy-brain/__tests__/OneshotModelPinPicker.test.tsx
+++ b/apps/desktop/src/renderer/cindy-brain/__tests__/OneshotModelPinPicker.test.tsx
@@ -107,6 +107,16 @@ describe('OneshotModelPinPicker shared A adapter', () => {
expect(onChange).toHaveBeenCalledWith(ANTHROPIC_PIN);
});
+ // PR #7744: provider grouping must preserve the host's identity name rather than
+ // replace it with the generic translated brand before reaching ModelSelector.
+ it('preserves an updated Cindy AI identity in the real picker adapter', () => {
+ const view = mount({ options: [{ ...xdOption, group: 'Cindy AI · 个人' }], groupByProvider: true });
+ expect(picker.providersOverride?.[0].name).toBe('Cindy AI · 个人');
+ view.rerender(<OneshotModelPinPicker defaultOptionLabel="Automatic" options={[{ ...xdOption, group: 'Cindy AI · 心动' }]}
+ onChange={vi.fn()} ariaLabel="Auxiliary model" groupByProvider />);
+ expect(picker.providersOverride?.[0].name).toBe('Cindy AI · 心动');
+ });
+
it('rejects forged, unavailable, and wrong-Harness routes without saving', async () => {
const onChange = vi.fn();
mount({ options: [{ ...xdOption, available: false }, ...options], value: xdOption.id, onChange });
diff --git a/apps/desktop/src/renderer/components/settings/AuxiliaryModelSection.tsx b/apps/desktop/src/renderer/components/settings/AuxiliaryModelSection.tsx
index 01404c024c..f71ae7cca9 100644
--- a/apps/desktop/src/renderer/components/settings/AuxiliaryModelSection.tsx
+++ b/apps/desktop/src/renderer/components/settings/AuxiliaryModelSection.tsx
@@ -7,7 +7,9 @@ import { SelectParts as Select } from '@/components/ui/select';
import { OneshotModelPinPicker } from '@/cindy-brain/OneshotModelPinPicker';
import { useAuth } from '@/contexts/AuthContext';
+import { useProviders } from '@/hooks/useProviders';
import { createLogger } from '@/lib/logger';
+import { providerDisplayName } from '@/lib/providerDisplayName';
import { toast } from '@/lib/toast';
import { cn } from '@/lib/utils';
import { isModelEnabled, useModelVisibilityVersion } from '@/state/modelVisibilityPrefs';
@@ -26,6 +28,9 @@ type AuxiliaryModelMode = 'automatic' | 'custom';
export function AuxiliaryModelSection() {
const { t } = useTranslation();
const { mode: authMode } = useAuth();
+ const { providers } = useProviders();
+ const cindyAiProvider = providers.find((provider) => provider.id === 'xd');
+ const cindyAiName = cindyAiProvider ? providerDisplayName(cindyAiProvider, t) : null;
const [settings, setSettings] = useState<AuxiliaryModelSettingsState | null>(null);
const [pending, setPending] = useState(false);
const [drafting, setDrafting] = useState(false);
@@ -75,6 +80,12 @@ export function AuxiliaryModelSection() {
() =>
(settings?.options ?? []).map((option) => ({
...option,
+ // Names follow the existing live catalog, independently of saved choices
+ // or an in-flight save whose options may still carry the old locale.
+ ...(option.providerId === 'xd' && cindyAiName ? {
+ group: cindyAiName,
+ label: `${option.agentSuffix} · ${option.modelName} · ${cindyAiName}`,
+ } : {}),
available:
option.available !== false &&
isModelEnabled(option.agentKind, option.providerId, {
@@ -82,7 +93,7 @@ export function AuxiliaryModelSection() {
defaultEnabled: option.defaultEnabled,
}),
})),
- [modelVisibilityVersion, settings?.options],
+ [cindyAiName, modelVisibilityVersion, settings?.options],
);
if (!settings) return null;
diff --git a/apps/desktop/src/renderer/components/settings/__tests__/AuxiliaryModelSection.test.tsx b/apps/desktop/src/renderer/components/settings/__tests__/AuxiliaryModelSection.test.tsx
index 9e0be4722b..6c65b5a064 100644
--- a/apps/desktop/src/renderer/components/settings/__tests__/AuxiliaryModelSection.test.tsx
+++ b/apps/desktop/src/renderer/components/settings/__tests__/AuxiliaryModelSection.test.tsx
@@ -9,6 +9,7 @@ import type {
} from '../../../../shared/auxiliaryModelSettings';
import { AUTO_AUXILIARY_MODEL_CHAIN } from '../../../../shared/auxiliaryModelChain';
import * as visibility from '@/state/modelVisibilityPrefs';
+import { beginProvidersRefresh, commitProvidersSnapshot, __testing as providerSnapshots } from '@/lib/providersSnapshotStore';
const PREFERRED_PIN = 'cat:openrouter:codex:openai/gpt-5-mini';
const FALLBACK_PIN = 'cat:anthropic:claude-code:claude-haiku-4-5';
@@ -66,7 +67,7 @@ vi.mock('@/cindy-brain/OneshotModelPinPicker', () => ({
{`${Boolean(groupByProvider)}:${options.map((option) => option.group).join(',')}`}
</span>
{options.map((option) => (
- <span key={option.id} data-testid={`${ariaLabel}:option:${option.id}`} data-available={option.available} />
+ <span key={option.id} data-testid={`${ariaLabel}:option:${option.id}`} data-available={option.available} data-label={option.label} />
))}
<button
type="button"
@@ -182,6 +183,7 @@ async function selectMode(modeKey: string): Promise<void> {
describe('AuxiliaryModelSection', () => {
beforeEach(() => {
vi.clearAllMocks();
+ providerSnapshots.reset();
h.authMode = 'cloud';
Object.defineProperty(Element.prototype, 'scrollIntoView', {
configurable: true,
@@ -211,6 +213,38 @@ describe('AuxiliaryModelSection', () => {
expect(screen.queryByText('settings.auxiliaryModels.preferred.label')).toBeNull();
});
+ // PR #7744: mounted auxiliary settings must follow the shared source-name snapshot.
+ // Old tests only read the initial GET. Interleave locale/membership changes with
+ // a draft and a pending save; names must update without reloading saved choices.
+ it('uses live identity names through locale changes, drafts and a late save response', async () => {
+ const publishName = (name: string) => {
+ commitProvidersSnapshot(beginProvidersRefresh(), {
+ dataOwnerId: null, ownerGeneration: 0, providerOrder: ['xd'],
+ providers: [{ id: 'xd', name } as import('@cindy/model-providers').ProviderView],
+ });
+ };
+ publishName('Cindy AI · 个人');
+ render(<AuxiliaryModelSection />);
+ await selectMode('settings.auxiliaryModels.customize');
+ const panel = () => screen.getByTestId('settings.auxiliaryModels.preferred.ariaLabel:panel').textContent;
+ expect(panel()).toContain('Cindy AI · 个人');
+ await act(async () => publishName('Cindy AI · Personal'));
+ expect(panel()).toContain('Cindy AI · Personal');
+ expect(h.set).not.toHaveBeenCalled();
+ expect(screen.getByTestId('settings.auxiliaryModels.preferred.ariaLabel:value').textContent).toBe(AUTO_AUXILIARY_MODEL_CHAIN[0]);
+
+ let finishSave!: (next: AuxiliaryModelSettingsState) => void;
+ h.set.mockImplementationOnce(() => new Promise<AuxiliaryModelSettingsState>(resolve => { finishSave = resolve; }));
+ fireEvent.click(screen.getByRole('button', { name: 'settings.auxiliaryModels.preferred.ariaLabel:select' }));
+ await act(async () => publishName('Cindy AI · 心动'));
+ expect(panel()).toContain('Cindy AI · 心动');
+ await act(async () => finishSave(state({ models: [PREFERRED_PIN], options: OPTIONS })));
+ expect(panel()).toContain('Cindy AI · 心动');
+ expect(screen.getByTestId(`settings.auxiliaryModels.preferred.ariaLabel:option:${AUTO_AUXILIARY_MODEL_CHAIN[0]}`).getAttribute('data-label')).toContain('Cindy AI · 心动');
+ expect(screen.getByTestId('settings.auxiliaryModels.preferred.ariaLabel:value').textContent).toBe(PREFERRED_PIN);
+ expect(h.get).toHaveBeenCalledTimes(1);
+ });
+
it.each([true, false])('keeps user visibility authoritative for a Pi HTTP choice (%s)', async (visible) => {
const option: AuxiliaryModelOption = { ...SUPPLIER_OPTIONS[0], id: 'cat:go:pi:deepseek-v4.1-flash',
providerId: 'go', agentKind: 'pi', modelId: 'deepseek-v4.1-flash', defaultEnabled: true };