Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
feat(model-default): Auto 只按模型 ID 认,跟随服务端在 Cindy 来源间挪动
fmfsaisai256341f03131
diff --git a/apps/desktop/src/renderer/__tests__/draftModelCalibration.test.ts b/apps/desktop/src/renderer/__tests__/draftModelCalibration.test.tsindex e5f08f851c..d794a52a2d 100644--- a/apps/desktop/src/renderer/__tests__/draftModelCalibration.test.ts+++ b/apps/desktop/src/renderer/__tests__/draftModelCalibration.test.ts@@ -963,4 +963,39 @@ describe('模型组 Auto:服务端决定默认与来源', () => {draft: { model: 'auto', providerId: 'xd', chosenByUser: false } })).toEqual(expected);expect(resolveNewTaskDefaultRoute({ providers, agent: 'pi' })).toEqual(expected);});++ it('组 Auto 从号池挪到 Cindy AI 后,按新来源继续,不退成号池里的其它模型', () => {+ const gateway = provider('xd', true, { pi: [model('auto'), groupAuto(true)] });+ const byok = pool('org-pool', [model('pool-model')]);+ const providers = [gateway, byok];+ const expected = { model: 'auto/group-1', providerId: 'xd' };+ expect(calibrateDraftModel({ providers, agent: 'pi', model: 'auto/group-1', chosenByUser: false,+ preferredProviderId: 'org-pool', providersLoading: false })).toEqual(expected);+ expect(resolveNewTaskDefaultRoute({ providers, agent: 'pi',+ draft: { model: 'auto/group-1', providerId: 'org-pool', chosenByUser: false } })).toEqual(expected);+ // 用户手动选的 Auto 同样按 ID 认:记住的号池已不提供它,改用当前提供它的 Cindy AI。+ expect(resolveNewTaskDefaultRoute({ providers, agent: 'pi',+ draft: { model: 'auto/group-1', providerId: 'org-pool', chosenByUser: true } })).toEqual(expected);+ });++ it('用户自己接的供应商不参与 Cindy 来源之间的改道', () => {+ const gateway = provider('xd', true, { pi: [model('auto'), groupAuto(true)] });+ const custom = pool('custom-litellm', [model('custom-model')], 'user');+ expect(calibrateDraftModel({ providers: [gateway, custom], agent: 'pi', model: 'custom-model',+ chosenByUser: false, preferredProviderId: 'custom-litellm', providersLoading: false }))+ .toEqual({ model: 'custom-model', providerId: 'custom-litellm' });+ });++ it('新建任务提交时,Auto 已挪走的旧来源换成解析出的新来源;其它显式来源原样提交', () => {+ const gateway = provider('xd', true, { pi: [model('auto'), groupAuto(true)] });+ const byok = pool('org-pool', [model('pool-model')]);+ const custom = pool('custom-litellm', [model('custom-model')], 'user');+ const providers = [gateway, byok, custom];+ expect(resolveDraftSessionProviderId({ providers, agent: 'pi', model: 'auto/group-1',+ explicitProviderId: 'org-pool', effectiveProviderId: 'xd' })).toBe('xd');+ expect(resolveDraftSessionProviderId({ providers, agent: 'pi', model: 'auto/group-1',+ explicitProviderId: 'org-pool', effectiveProviderId: null })).toBe('org-pool');+ expect(resolveDraftSessionProviderId({ providers, agent: 'pi', model: 'auto/group-1',+ explicitProviderId: 'custom-litellm', effectiveProviderId: 'xd' })).toBe('custom-litellm');+ });});diff --git a/apps/desktop/src/shared/draftModelCalibration.ts b/apps/desktop/src/shared/draftModelCalibration.tsindex 352201b87b..4fc0bcc4a1 100644--- a/apps/desktop/src/shared/draftModelCalibration.ts+++ b/apps/desktop/src/shared/draftModelCalibration.ts@@ -370,7 +370,16 @@ export function resolveDraftSessionProviderId({effectiveProviderId,}: DraftSessionProviderResolutionInput): string | null {if (explicitProviderId) {- return explicitProviderId;+ // 显式来源原样提交;唯一例外是服务端把 Auto 挪到了另一家 Cindy 来源,此时来源解析+ // 已改指新来源,提交旧来源只会让首条请求落到不再提供该模型的连接上。+ const explicitProvider = providers.find((provider) => provider.id === explicitProviderId);+ const effectiveProvider = providers.find((provider) => provider.id === effectiveProviderId);+ return effectiveProvider &&+ effectiveProvider.id !== explicitProviderId &&+ isCindyDistributedProvider(explicitProvider) &&+ isCindyDistributedProvider(effectiveProvider)+ ? effectiveProvider.id+ : explicitProviderId;}if (!effectiveProviderId) return null;// 预设通过「添加供应商」落地后同样属于 user provider。即使它是当前模型唯一的diff --git a/apps/mobile/src/__tests__/newSession.test.ts b/apps/mobile/src/__tests__/newSession.test.tsindex b1cbbde4f5..f149c38139 100644--- a/apps/mobile/src/__tests__/newSession.test.ts+++ b/apps/mobile/src/__tests__/newSession.test.ts@@ -901,6 +901,45 @@ describe('pickAgentDefaultRuntime', () => {),).toEqual({ model: 'gpt-5.4', providerId: null });});++ it('Auto 只按模型 ID 认:服务端把它挪到另一家 Cindy 来源后跟过去,不落到用户自己接的供应商', () => {+ const autoRow = (+ providerId: string,+ source: 'builtin' | 'organization' | 'user',+ modelIds: readonly string[],+ modelId: string,+ ): ProviderModelRow => ({+ provider: {+ id: providerId,+ name: providerId,+ source,+ agents: ['pi'],+ routing: { pi: {} },+ connected: true,+ models: { pi: modelIds.map((id) => ({ id, name: id })) },+ } as unknown as ProviderModelRow['provider'],+ model: { id: modelId, displayName: modelId, efforts: [], defaultEffort: null, contextWindow: 0 },+ });+ const auto = 'auto/group-1';+ // 号池 → Cindy AI:记住的号池还在(有别的模型),但已不再提供这个 Auto。+ const toPlatform = [+ autoRow('custom', 'user', [auto], auto),+ autoRow('org-pool', 'organization', ['pool-model'], 'pool-model'),+ autoRow('xd', 'builtin', ['auto', auto], auto),+ ];+ expect(+ resolveRecentModelAndProvider(toPlatform, { model: auto, providerId: 'org-pool' }, 'pi', true),+ ).toEqual({ model: auto, providerId: 'xd' });+ // Cindy AI → 号池:用户自己接的供应商排在前面也提供同 ID,不能被通用顶替规则选中。+ const toPool = [+ autoRow('custom', 'user', [auto], auto),+ autoRow('xd', 'builtin', ['auto'], 'auto'),+ autoRow('org-pool', 'organization', ['pool-model', auto], auto),+ ];+ expect(+ resolveRecentModelAndProvider(toPool, { model: auto, providerId: 'xd' }, 'pi', true),+ ).toEqual({ model: auto, providerId: 'org-pool' });+ });});describe('resolveNewSessionAutoDefault', () => {diff --git a/apps/mobile/src/session/newSession.ts b/apps/mobile/src/session/newSession.tsindex 43387db4df..eb5c92ef29 100644--- a/apps/mobile/src/session/newSession.ts+++ b/apps/mobile/src/session/newSession.ts@@ -14,6 +14,7 @@ import type {} from '@/device-link/mobileMakerTransport';import type { DeviceProvidersPayload } from '@/device-link/deviceProvidersCache';import type { MobileModelOption } from './agentCapabilities';+import { isCindyAutoModelId } from '@cindy/model-providers/provider-identity';import { effectiveSourceIdForModel } from '@cindy/model-providers/registry';import { reconcileEffortForModel, type ProviderModelRow } from './providerModelSections';import type { RemoteSession } from './types';@@ -501,6 +502,16 @@ export function resolveRecentModelAndProvider(}const valid = validateModelProviderId(modelRows, recent.providerId, recent.model, true);if (valid) return { model: recent.model, providerId: valid };+ // Auto 只按模型 ID 认(与桌面 effectiveSourceIdForModel 同一规则):服务端把它从 Cindy AI+ // 挪到企业号池(或反过来)后,记住的来源不再提供它 —— 改用当前提供它的那一家 Cindy 来源,+ // 不当失效处理。用户自己接的供应商不参与这条改道。+ if (isCindyAutoModelId(recent.model)) {+ const rowProviders = [...new Map(modelRows.map((row) => [row.provider.id, row.provider])).values()];+ const relocated = effectiveSourceIdForModel(rowProviders, recent.providerId, recent.model, agentKind);+ if (relocated && validateModelProviderId(modelRows, relocated, recent.model, true)) {+ return { model: recent.model, providerId: relocated };+ }+ }// 显式来源失效的替代选择:与 null 分支同口径(codex review P2:按 Agent 默认// 规则选择失效来源的替代项)——同名模型多来源时**不得取目录首行**(目录顺序// ≠ Agent 原生默认顺序,如 Codex 候选 [custom, xd] 会被首行绑定到 custom,diff --git a/docs/dev-rules/model-catalog-maintenance.md b/docs/dev-rules/model-catalog-maintenance.mdindex d76bf4bd61..f24b159623 100644--- a/docs/dev-rules/model-catalog-maintenance.md+++ b/docs/dev-rules/model-catalog-maintenance.md@@ -142,6 +142,11 @@ Claude 订阅 Opus 5.5(Claude Code)、服务端指定的 Cindy Auto(Pi)没指定模型时同样按新建任务口径解析(`apps/desktop/src/shared/draftModelCalibration.ts`的 `resolveNewTaskDefaultRoute`),不在代码里写死型号;一个可用来源都没有时明确失败或留空让用户选。+Auto 只按模型 ID 认(`isCindyAutoModelId`):服务端可以把同一个 Auto 在 Cindy AI 与企业号池+之间挪动。记住的来源是这两类之一且已不再提供它时,`effectiveSourceIdForModel` 改用当前提供它+的那一家(同样限于这两类),新建任务提交与手机端 `resolveRecentModelAndProvider` 复用同一规则;+记住的来源仍列着它(只是断连或停用)、或是用户自己接的供应商时不改道。+设置页管理列表组内与选择器同序:组内每项都带 `sortOrder` 时按它排;只要有一项缺失,退回按系列名 A–Z、同系列版本号降序,避免局部权重把新型号压到旧策展位置之后。diff --git a/packages/model-providers/src/__tests__/cindyAutoRelocation.test.ts b/packages/model-providers/src/__tests__/cindyAutoRelocation.test.tsnew file mode 100644index 0000000000..47b8aa5be7--- /dev/null+++ b/packages/model-providers/src/__tests__/cindyAutoRelocation.test.ts@@ -0,0 +1,90 @@+/**+ * 模型组 Auto 只按模型 ID 认:服务端可以把同一个 `auto/<组ID>` 在 Cindy AI 与企业号池供应商+ * 之间挪动,记住的来源不再提供它时改用当前提供它的那一家;用户自己接的供应商不受影响。+ */+import { describe, expect, it } from 'vitest';++import { isCindyAutoModelId, isCindyDistributedProvider } from '../provider-identity.js';+import { effectiveSourceIdForModel, type ProviderView } from '../registry.js';+import type { CatalogModel, ProviderSource } from '../types.js';++function model(id: string): CatalogModel {+ return { id, name: id, contextWindow: 200_000, efforts: [], defaultEffort: null };+}++function provider(id: string, source: ProviderSource, modelIds: string[], connected = true): ProviderView {+ return {+ id,+ name: id,+ source,+ agents: ['pi'],+ auth: { method: source === 'user' ? 'apiKey' : 'managed' },+ access: source === 'user' ? { kind: 'api' } : { kind: 'managed' },+ routing: { pi: { upstream: `https://${id}.test`, authStrategy: 'api-key-header' } },+ models: { pi: modelIds.map(model) },+ connected,+ };+}++const AUTO = 'auto/group-1';++describe('Cindy Auto 身份', () => {+ it('预设 auto 与 auto/<组ID> 都算,前缀相近的模型不算', () => {+ expect(isCindyAutoModelId('auto')).toBe(true);+ expect(isCindyAutoModelId(AUTO)).toBe(true);+ for (const id of ['auto/', 'autopilot', 'openrouter/auto', 'xd/auto']) {+ expect(isCindyAutoModelId(id)).toBe(false);+ }+ });++ it('只有 Cindy AI 与企业号池算 Cindy 下发的来源', () => {+ expect(isCindyDistributedProvider(provider('xd', 'builtin', []))).toBe(true);+ expect(isCindyDistributedProvider(provider('org-pool', 'organization', []))).toBe(true);+ expect(isCindyDistributedProvider(provider('xd', 'user', []))).toBe(false);+ expect(isCindyDistributedProvider(provider('anthropic', 'builtin', []))).toBe(false);+ expect(isCindyDistributedProvider(null)).toBe(false);+ });+});++describe('effectiveSourceIdForModel:Auto 跨 Cindy 来源改道', () => {+ it('号池 → Cindy AI、Cindy AI → 号池都跟着走', () => {+ const toPlatform = [provider('xd', 'builtin', ['auto', AUTO]), provider('org-pool', 'organization', ['pool-model'])];+ expect(effectiveSourceIdForModel(toPlatform, 'org-pool', AUTO, 'pi')).toBe('xd');+ const toPool = [provider('xd', 'builtin', ['auto']), provider('org-pool', 'organization', ['pool-model', AUTO])];+ expect(effectiveSourceIdForModel(toPool, 'xd', AUTO, 'pi')).toBe('org-pool');+ // 号池之间同样适用。+ const betweenPools = [+ provider('org-a', 'organization', ['pool-model']),+ provider('org-b', 'organization', [AUTO]),+ ];+ expect(effectiveSourceIdForModel(betweenPools, 'org-a', AUTO, 'pi')).toBe('org-b');+ });++ it('记住的来源仍提供它时保持不变', () => {+ const views = [provider('xd', 'builtin', [AUTO]), provider('org-pool', 'organization', [AUTO])];+ expect(effectiveSourceIdForModel(views, 'org-pool', AUTO, 'pi')).toBe('org-pool');+ });++ it('记住的来源还列着它、只是断连或停用时不改道,仍按显式来源失效处理', () => {+ const disconnected = [+ provider('xd', 'builtin', [AUTO]),+ provider('org-pool', 'organization', [AUTO], false),+ ];+ expect(effectiveSourceIdForModel(disconnected, 'org-pool', AUTO, 'pi')).toBeNull();+ const suspended = [provider('xd', 'builtin', [AUTO]), { ...provider('org-pool', 'organization', [AUTO]), suspended: true }];+ expect(effectiveSourceIdForModel(suspended, 'org-pool', AUTO, 'pi')).toBeNull();+ });++ it('用户自己接的供应商不参与:既不从它挪走,也不挪到它', () => {+ const fromUser = [provider('custom', 'user', ['other']), provider('xd', 'builtin', [AUTO])];+ expect(effectiveSourceIdForModel(fromUser, 'custom', AUTO, 'pi')).toBeNull();+ const toUser = [provider('org-pool', 'organization', ['pool-model']), provider('custom', 'user', [AUTO])];+ expect(effectiveSourceIdForModel(toUser, 'org-pool', AUTO, 'pi')).toBeNull();+ });++ it('普通模型与已不存在的来源保持原有的「显式来源失效返回 null」', () => {+ const views = [provider('xd', 'builtin', ['glm']), provider('org-pool', 'organization', ['pool-model'])];+ expect(effectiveSourceIdForModel(views, 'org-pool', 'glm', 'pi')).toBeNull();+ expect(effectiveSourceIdForModel([provider('xd', 'builtin', [AUTO])], 'gone-pool', AUTO, 'pi')).toBeNull();+ });+});diff --git a/packages/model-providers/src/registry.ts b/packages/model-providers/src/registry.tsindex 8b4c08b988..ef6e016091 100644--- a/packages/model-providers/src/registry.ts+++ b/packages/model-providers/src/registry.ts@@ -18,6 +18,7 @@ import {isModelSelectableForNewRoute,} from './classification.js';import type { ProviderLogoKind } from './providerBranding.js';+import { isCindyAutoModelId, isCindyDistributedProvider } from './provider-identity.js';import {isModelDisabled,isProviderDisabled,@@ -318,8 +319,9 @@ export function nativeDefaultSourceId(rail: ProviderView[], agent: AgentKind | n* 来源选择必须先收窄到「已连接且确实提供当前模型」的集合,再应用显式选择 / 原生默认:* 否则当 XD key 被清除、但 OpenAI 仍连接时,Claude 会话会把 OpenAI 当成 agent 级兜底,* 拼出「OpenAI 图标 + Opus」这种不可能路由。显式来源失效时返回 null,不替换账号;- * 当前模型没有任何已连接且可用于新路由的来源时返回 null。retired tombstone 与本地- * disabled 都不参与本函数;运行中会话的真实来源展示必须改用 actualSourceIdForModel。+ * 唯一例外是 Auto(见 relocatedAutoSourceId)。当前模型没有任何已连接且可用于新路由的+ * 来源时返回 null。retired tombstone 与本地 disabled 都不参与本函数;运行中会话的真实+ * 来源展示必须改用 actualSourceIdForModel。*/export function effectiveSourceIdForModel(views: ProviderView[],@@ -334,10 +336,34 @@ export function effectiveSourceIdForModel(isModelSelectableForNewRoute(model, { userProvider: provider.source === 'user' }));});- if (providerId) return sources.some((provider) => provider.id === providerId) ? providerId : null;+ if (providerId) {+ return sources.some((provider) => provider.id === providerId)+ ? providerId+ : relocatedAutoSourceId(views, providerId, modelId, agent, sources);+ }return nativeDefaultSourceId(sources, agent);}+/**+ * Auto(isCindyAutoModelId)只按模型 ID 认:服务端可以把同一个 Auto 在 Cindy AI 与+ * 企业号池供应商之间挪动(平台模型 ↔ 号池模型)。记住的来源是这两类之一、且已不再提供+ * 该 Auto 时,改用当前提供它的那一家(同样限于这两类),不判失效。记住的来源仍列着该+ * 模型(只是断连 / 停用)或是用户自己接的供应商时不改道,仍按显式来源失效处理。+ */+function relocatedAutoSourceId(+ views: readonly ProviderView[],+ providerId: string,+ modelId: string,+ agent: AgentKind,+ sources: ProviderView[],+): string | null {+ if (!isCindyAutoModelId(modelId)) return null;+ const remembered = views.find((provider) => provider.id === providerId);+ if (!remembered || !isCindyDistributedProvider(remembered)) return null;+ if (providerOffersModel(remembered, modelId, agent)) return null;+ return nativeDefaultSourceId(sources.filter(isCindyDistributedProvider), agent);+}+/*** 「实际路由口径」的来源解析:选择规则与 effectiveSourceIdForModel 相同,但**不*** 剔除停用拷贝(includeDisabled rail)。给「展示一个已在运行的会话」用:运行中的