Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
style(model-default): 按 prettier 整理本分支新增的 desktop 代码
fmfsaisai7f523b48ce9d
diff --git a/apps/desktop/src/main/im/__tests__/defaultSessionSettings.test.ts b/apps/desktop/src/main/im/__tests__/defaultSessionSettings.test.tsindex f0310f9b36..02f88b4d19 100644--- a/apps/desktop/src/main/im/__tests__/defaultSessionSettings.test.ts+++ b/apps/desktop/src/main/im/__tests__/defaultSessionSettings.test.ts@@ -239,30 +239,50 @@ describe('resolveImSessionDefaults', () => {it.each([['号池 → Cindy AI(显式来源)', 'org-pool', 'xd', ['auto', 'auto/group-1'], ['pool-model']],- ['Cindy AI → 号池(Pi 默认来源 null 即 Cindy AI)', null, 'org-pool', ['auto'], ['pool-model', 'auto/group-1']],- ] as const)('保存的 Auto 默认在使用时跟随服务端挪动:%s', async (_name, saved, expected, xdModels, poolModels) => {- const piModel = (id: string) => ({ id, name: id, contextWindow: 200_000, efforts: [], defaultEffort: null });- const piProvider = (id: string, source: string, models: readonly string[]) => ({- id, name: id, source, connected: true, agents: ['pi'],- auth: { method: 'managed' }, access: { kind: 'managed' },- models: { pi: models.map(piModel) },- routing: { pi: { upstream: 'https://example.invalid', authStrategy: 'api-key-header' } },- });- mocks.listProviders.mockResolvedValue([- piProvider('xd', 'builtin', xdModels),- piProvider('org-pool', 'organization', poolModels),- ]);- mocks.readImDefaultSettings.mockReturnValue({- agentKind: 'pi',- agents: { pi: { providerId: saved, model: 'auto/group-1', effort: 'high' } },- });-- await expect(resolveImSessionDefaults(config)).resolves.toMatchObject({- agentKind: 'pi',- model: 'auto/group-1',- providerId: expected,- });- });+ [+ 'Cindy AI → 号池(Pi 默认来源 null 即 Cindy AI)',+ null,+ 'org-pool',+ ['auto'],+ ['pool-model', 'auto/group-1'],+ ],+ ] as const)(+ '保存的 Auto 默认在使用时跟随服务端挪动:%s',+ async (_name, saved, expected, xdModels, poolModels) => {+ const piModel = (id: string) => ({+ id,+ name: id,+ contextWindow: 200_000,+ efforts: [],+ defaultEffort: null,+ });+ const piProvider = (id: string, source: string, models: readonly string[]) => ({+ id,+ name: id,+ source,+ connected: true,+ agents: ['pi'],+ auth: { method: 'managed' },+ access: { kind: 'managed' },+ models: { pi: models.map(piModel) },+ routing: { pi: { upstream: 'https://example.invalid', authStrategy: 'api-key-header' } },+ });+ mocks.listProviders.mockResolvedValue([+ piProvider('xd', 'builtin', xdModels),+ piProvider('org-pool', 'organization', poolModels),+ ]);+ mocks.readImDefaultSettings.mockReturnValue({+ agentKind: 'pi',+ agents: { pi: { providerId: saved, model: 'auto/group-1', effort: 'high' } },+ });++ await expect(resolveImSessionDefaults(config)).resolves.toMatchObject({+ agentKind: 'pi',+ model: 'auto/group-1',+ providerId: expected,+ });+ },+ );it('reroutes an implicit default whose native-default copy is disabled', async () => {// providerId 留空(隐式路由):原生默认落点(codex → openai)的拷贝被停用而 xddiff --git a/apps/desktop/src/main/im/shared/__tests__/channelDefaultRouteSync.test.ts b/apps/desktop/src/main/im/shared/__tests__/channelDefaultRouteSync.test.tsindex 7029f970d1..06998ee355 100644--- a/apps/desktop/src/main/im/shared/__tests__/channelDefaultRouteSync.test.ts+++ b/apps/desktop/src/main/im/shared/__tests__/channelDefaultRouteSync.test.ts@@ -214,18 +214,44 @@ describe('syncUnderLock', () => {it('Auto 被服务端挪到另一家 Cindy 来源、任务已跟过去时,仍算在跟随渠道默认', async () => {const auto = 'auto/group-1';const view = (id: string, source: string, models: string[]) => ({- id, name: id, source, connected: true, agents: ['pi'],- auth: { method: 'managed' }, access: { kind: 'managed' },+ id,+ name: id,+ source,+ connected: true,+ agents: ['pi'],+ auth: { method: 'managed' },+ access: { kind: 'managed' },routing: { pi: { upstream: 'https://example.invalid', authStrategy: 'api-key-header' } },- models: { pi: models.map((model) => ({ id: model, name: model, contextWindow: 200_000, efforts: [], defaultEffort: null })) },+ models: {+ pi: models.map((model) => ({+ id: model,+ name: model,+ contextWindow: 200_000,+ efforts: [],+ defaultEffort: null,+ })),+ },});// 管理员把 Auto 从号池挪到 Cindy AI;任务已在下一条消息前跟着换到了 xd。- mocks.listProviders.mockResolvedValue([view('xd', 'builtin', [auto]), view('org-pool', 'organization', ['pool-model'])]);- const saved: ImDefaultRoute = { agentKind: 'pi', model: auto, providerId: 'org-pool', effort: 'high' };+ mocks.listProviders.mockResolvedValue([+ view('xd', 'builtin', [auto]),+ view('org-pool', 'organization', ['pool-model']),+ ]);+ const saved: ImDefaultRoute = {+ agentKind: 'pi',+ model: auto,+ providerId: 'org-pool',+ effort: 'high',+ };const moved: ImDefaultRoute = { ...saved, providerId: 'xd' };await insertTask('t1', moved, { record: buildImDefaultRouteRecord('fp-old', saved) });// 之后用户改了渠道默认的其它设置,解析出的目标仍是这个 Auto 的新位置。- mocks.resolveDefaults.mockResolvedValue({ ...moved, permissionMode: 'auto', fastMode: false, fingerprint: 'fp-new' });+ mocks.resolveDefaults.mockResolvedValue({+ ...moved,+ permissionMode: 'auto',+ fastMode: false,+ fingerprint: 'fp-new',+ });await sync().syncUnderLock('t1');expect(mocks.applyRoute).not.toHaveBeenCalled();diff --git a/apps/desktop/src/main/im/shared/channelDefaultRouteSync.ts b/apps/desktop/src/main/im/shared/channelDefaultRouteSync.tsindex c6280d0d68..2849b5e0e0 100644--- a/apps/desktop/src/main/im/shared/channelDefaultRouteSync.ts+++ b/apps/desktop/src/main/im/shared/channelDefaultRouteSync.ts@@ -8,7 +8,11 @@*/import { and, eq, inArray, isNull } from 'drizzle-orm';import type { AgentKind } from '@cindy/maker-core';-import { effectiveSourceIdForModel, movedCindyAutoSourceId, type ProviderView } from '@cindy/model-providers';+import {+ effectiveSourceIdForModel,+ movedCindyAutoSourceId,+ type ProviderView,+} from '@cindy/model-providers';import type { ImDefaultSettingsChannel } from '../../../shared/imDefaultSettings.js';import { getDbClient } from '../../localDb/client/current';@@ -141,9 +145,15 @@ function providerNormalizer(providers: ProviderView[]) {return (route: ImDefaultRoute): string | null => {if (route.agentDeviceId) return route.providerId;const agent = route.agentKind as AgentKind;- return movedCindyAutoSourceId(providers, { agent, model: route.model, providerId: route.providerId })- ?? route.providerId- ?? effectiveSourceIdForModel(providers, null, route.model, agent);+ return (+ movedCindyAutoSourceId(providers, {+ agent,+ model: route.model,+ providerId: route.providerId,+ }) ??+ route.providerId ??+ effectiveSourceIdForModel(providers, null, route.model, agent)+ );};}diff --git a/apps/desktop/src/main/maker-host/__tests__/botModelChainSettingsStore.test.ts b/apps/desktop/src/main/maker-host/__tests__/botModelChainSettingsStore.test.tsindex f79334046f..7b6c37312a 100644--- a/apps/desktop/src/main/maker-host/__tests__/botModelChainSettingsStore.test.ts+++ b/apps/desktop/src/main/maker-host/__tests__/botModelChainSettingsStore.test.ts@@ -230,22 +230,45 @@ describe('bot model chain settings store', () => {describe('模型组 Auto 被服务端挪到另一家 Cindy 来源', () => {const AUTO = 'auto/group-1';- const view = (id: string, source: ProviderView['source'], modelIds: string[]) => ({- id, name: id, source, connected: true, agents: ['pi'],- auth: { method: 'managed' }, access: { kind: 'managed' },- routing: { pi: { upstream: 'https://example.invalid', authStrategy: 'api-key-header' } },- models: { pi: modelIds.map((id) => ({ id, name: id, contextWindow: 200_000, efforts: [], defaultEffort: null })) },- }) as unknown as ProviderView;+ const view = (id: string, source: ProviderView['source'], modelIds: string[]) =>+ ({+ id,+ name: id,+ source,+ connected: true,+ agents: ['pi'],+ auth: { method: 'managed' },+ access: { kind: 'managed' },+ routing: { pi: { upstream: 'https://example.invalid', authStrategy: 'api-key-header' } },+ models: {+ pi: modelIds.map((id) => ({+ id,+ name: id,+ contextWindow: 200_000,+ efforts: [],+ defaultEffort: null,+ })),+ },+ }) as unknown as ProviderView;// 管理员把 Auto 的目标从号池模型切到平台模型。- const providers = [view('xd', 'builtin', ['auto', AUTO]), view('org-pool', 'organization', ['pool-model'])];- const route = (providerId: string | null, model = AUTO) =>- ({ harness: 'pi' as const, model, providerId, effort: '', fastMode: false });+ const providers = [+ view('xd', 'builtin', ['auto', AUTO]),+ view('org-pool', 'organization', ['pool-model']),+ ];+ const route = (providerId: string | null, model = AUTO) => ({+ harness: 'pi' as const,+ model,+ providerId,+ effort: '',+ fastMode: false,+ });it('伙伴自己存的路由在使用时改用新来源,不改写资料里的值', async () => {const rootPath = await testRoot();const config = { modelChainOverride: [route('org-pool'), route('org-pool', 'pool-model')] };expect(await readEffectiveBotModelChain(config, { rootPath, providers })).toEqual([- route('xd'), route('org-pool', 'pool-model'),+ route('xd'),+ route('org-pool', 'pool-model'),]);expect(config.modelChainOverride[0].providerId).toBe('org-pool');});@@ -253,13 +276,19 @@ describe('bot model chain settings store', () => {it('用户自定义的伙伴默认同样跟随;没挪动、预设 auto 与普通模型原样', async () => {const rootPath = await testRoot();await writeBotModelChainSettings([route('org-pool'), route('xd', 'auto')], { rootPath });- expect(await readEffectiveBotModelChain({ modelChainOverride: null }, { rootPath, providers }))- .toEqual([route('xd'), route('xd', 'auto')]);+ expect(+ await readEffectiveBotModelChain({ modelChainOverride: null }, { rootPath, providers }),+ ).toEqual([route('xd'), route('xd', 'auto')]);// 保存的设置文件仍是原值。- expect((await readBotModelChainSettingsState({ rootPath, providers: [] })).value.modelChain[0])- .toMatchObject({ providerId: 'org-pool' });- expect(await readEffectiveBotModelChain({ modelChainOverride: [route('xd')] }, { rootPath, providers }))- .toEqual([route('xd')]);+ expect(+ (await readBotModelChainSettingsState({ rootPath, providers: [] })).value.modelChain[0],+ ).toMatchObject({ providerId: 'org-pool' });+ expect(+ await readEffectiveBotModelChain(+ { modelChainOverride: [route('xd')] },+ { rootPath, providers },+ ),+ ).toEqual([route('xd')]);});});});diff --git a/apps/desktop/src/main/maker-host/bot-model-chain-settings-store.ts b/apps/desktop/src/main/maker-host/bot-model-chain-settings-store.tsindex ca21c98c07..534a2bd96d 100644--- a/apps/desktop/src/main/maker-host/bot-model-chain-settings-store.ts+++ b/apps/desktop/src/main/maker-host/bot-model-chain-settings-store.ts@@ -162,7 +162,8 @@ async function followMovedCindyAuto(providers: readonly ProviderView[] | undefined,): Promise<BotModelRoute[]> {// 预设 auto 只在 Cindy AI 上、不会被挪动;只有模型组 Auto 才值得为此读一次目录。- if (!chain.some((route) => route.model !== 'auto' && isCindyAutoModelId(route.model))) return chain;+ if (!chain.some((route) => route.model !== 'auto' && isCindyAutoModelId(route.model)))+ return chain;let views = providers;if (!views) {try {@@ -192,7 +193,10 @@ export async function readEffectiveBotModelSelection(): Promise<{ chain: BotModelRoute[]; followsCindyDefault: boolean }> {const explicit = readExplicitBotModelChain(config);if (explicit !== null) {- return { chain: await followMovedCindyAuto(explicit, options?.providers), followsCindyDefault: false };+ return {+ chain: await followMovedCindyAuto(explicit, options?.providers),+ followsCindyDefault: false,+ };}const state = await readBotModelChainSettingsState(options);// 跟随 Cindy 默认时链路由实时目录推导,已经是当前位置;只有用户自定义的设置是存下来的。diff --git a/apps/desktop/src/main/maker-ipc/__tests__/cindyAutoRouteFollow.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/cindyAutoRouteFollow.test.tsindex 2430854868..95e0036455 100644--- a/apps/desktop/src/main/maker-ipc/__tests__/cindyAutoRouteFollow.test.ts+++ b/apps/desktop/src/main/maker-ipc/__tests__/cindyAutoRouteFollow.test.ts@@ -47,31 +47,49 @@ const movedToPlatform = [describe('movedCindyAutoProviderId', () => {it('Auto 换了 Cindy 来源时给出新来源,引擎与模型不在这里改', () => {expect(movedCindyAutoProviderId(movedToPlatform, route())).toBe('xd');- const movedToPool = [provider('xd', 'builtin', ['auto']), provider('org-pool', 'organization', [AUTO])];+ const movedToPool = [+ provider('xd', 'builtin', ['auto']),+ provider('org-pool', 'organization', [AUTO]),+ ];expect(movedCindyAutoProviderId(movedToPool, route({ providerId: 'xd' }))).toBe('org-pool');});it('Pi 的默认来源(providerId=null)就是 Cindy AI,Auto 挪到号池同样跟随', () => {- const movedToPool = [provider('xd', 'builtin', ['auto']), provider('org-pool', 'organization', [AUTO])];+ const movedToPool = [+ provider('xd', 'builtin', ['auto']),+ provider('org-pool', 'organization', [AUTO]),+ ];expect(movedCindyAutoProviderId(movedToPool, route({ providerId: null }))).toBe('org-pool');// 其它引擎的默认来源不一定是 Cindy AI,不推断。- expect(movedCindyAutoProviderId(movedToPool, route({ providerId: null, agentKind: 'codex' }))).toBeNull();+ expect(+ movedCindyAutoProviderId(movedToPool, route({ providerId: null, agentKind: 'codex' })),+ ).toBeNull();});it('订阅等内置非 Cindy AI 来源上的 auto/... 不跟随', () => {- const subscription = [provider('openai', 'builtin', ['other']), provider('xd', 'builtin', [AUTO])];+ const subscription = [+ provider('openai', 'builtin', ['other']),+ provider('xd', 'builtin', [AUTO]),+ ];expect(movedCindyAutoProviderId(subscription, route({ providerId: 'openai' }))).toBeNull();});it('Auto 从两份目录都消失时不登记切换,保留原路由交给既有的来源失效提示', () => {- const gone = [provider('xd', 'builtin', ['auto']), provider('org-pool', 'organization', ['pool-model'])];+ const gone = [+ provider('xd', 'builtin', ['auto']),+ provider('org-pool', 'organization', ['pool-model']),+ ];expect(movedCindyAutoProviderId(gone, route())).toBeNull();expect(movedCindyAutoProviderId(gone, route({ providerId: null }))).toBeNull();});it('回归:预设 auto 的任务不动', () => {- expect(movedCindyAutoProviderId(movedToPlatform, route({ model: 'auto', providerId: null }))).toBeNull();- expect(movedCindyAutoProviderId(movedToPlatform, route({ model: 'auto', providerId: 'xd' }))).toBeNull();+ expect(+ movedCindyAutoProviderId(movedToPlatform, route({ model: 'auto', providerId: null })),+ ).toBeNull();+ expect(+ movedCindyAutoProviderId(movedToPlatform, route({ model: 'auto', providerId: 'xd' })),+ ).toBeNull();});it('来源没变、普通模型、用户自己接的供应商都不动', () => {@@ -95,7 +113,9 @@ describe('followMovedCindyAutoRoutes', () => {listProviders: async () => movedToPlatform,withSessionLock,readRoute: async (sessionId) =>- sessionId === 'moved' ? route({ effort: 'medium', fastMode: true }) : route({ providerId: 'xd' }),+ sessionId === 'moved'+ ? route({ effort: 'medium', fastMode: true })+ : route({ providerId: 'xd' }),stage,assertCurrent: () => {},};@@ -107,7 +127,11 @@ describe('followMovedCindyAutoRoutes', () => {await expect(followMovedCindyAutoRoutes(input)).resolves.toBe(1);expect(withSessionLock).toHaveBeenCalledTimes(1);expect(stage).toHaveBeenCalledWith('moved', {- agentKind: 'pi', model: AUTO, providerId: 'xd', effort: 'medium', fastMode: true,+ agentKind: 'pi',+ model: AUTO,+ providerId: 'xd',+ effort: 'medium',+ fastMode: true,});});@@ -166,7 +190,9 @@ describe('followMovedCindyAutoRoutes', () => {it('账号切换后整批停止,不再改动下一个账号的任务', async () => {let current = true;- const stage = vi.fn(async () => { current = false; });+ const stage = vi.fn(async () => {+ current = false;+ });const { deps: input } = deps({listCandidates: async () => [{ sessionId: 'first', ...route() },@@ -185,20 +211,24 @@ describe('followMovedCindyAutoRoutes', () => {describe('Auto 没有推理档位时的跨来源跟随', () => {// Auto 不带档位,任务库里 effort 存的是空串;登记切换只接受合法档位或 null。- const movedToPool = [provider('xd', 'builtin', ['auto']), provider('org-pool', 'organization', [AUTO])];+ const movedToPool = [+ provider('xd', 'builtin', ['auto']),+ provider('org-pool', 'organization', [AUTO]),+ ];function follow(providers: ProviderView[], current: CindyAutoRoute) {const stage = vi.fn(async () => {});return {stage,- run: () => followMovedCindyAutoRoutes({- listCandidates: async () => [{ sessionId: 'task', ...current }],- listProviders: async () => providers,- withSessionLock: async (_sessionId, run) => run(),- readRoute: async () => current,- stage,- assertCurrent: () => {},- }),+ run: () =>+ followMovedCindyAutoRoutes({+ listCandidates: async () => [{ sessionId: 'task', ...current }],+ listProviders: async () => providers,+ withSessionLock: async (_sessionId, run) => run(),+ readRoute: async () => current,+ stage,+ assertCurrent: () => {},+ }),};}@@ -206,7 +236,11 @@ describe('Auto 没有推理档位时的跨来源跟随', () => {const { stage, run } = follow(movedToPlatform, route({ providerId: 'org-pool', effort: '' }));await expect(run()).resolves.toBe(1);expect(stage).toHaveBeenCalledWith('task', {- agentKind: 'pi', model: AUTO, providerId: 'xd', effort: null, fastMode: false,+ agentKind: 'pi',+ model: AUTO,+ providerId: 'xd',+ effort: null,+ fastMode: false,});});@@ -214,7 +248,11 @@ describe('Auto 没有推理档位时的跨来源跟随', () => {const { stage, run } = follow(movedToPool, route({ providerId: 'xd', effort: '' }));await expect(run()).resolves.toBe(1);expect(stage).toHaveBeenCalledWith('task', {- agentKind: 'pi', model: AUTO, providerId: 'org-pool', effort: null, fastMode: false,+ agentKind: 'pi',+ model: AUTO,+ providerId: 'org-pool',+ effort: null,+ fastMode: false,});});diff --git a/apps/desktop/src/main/maker-ipc/cindyAutoRouteFollow.ts b/apps/desktop/src/main/maker-ipc/cindyAutoRouteFollow.tsindex b16ec1cad4..c76ba26081 100644--- a/apps/desktop/src/main/maker-ipc/cindyAutoRouteFollow.ts+++ b/apps/desktop/src/main/maker-ipc/cindyAutoRouteFollow.ts@@ -1,8 +1,4 @@-import {- movedCindyAutoSourceId,- type AgentKind,- type ProviderView,-} from '@cindy/model-providers';+import { movedCindyAutoSourceId, type AgentKind, type ProviderView } from '@cindy/model-providers';import { isSupportedRuntimeEffort } from './runtimeSelectionAxes.js';diff --git a/apps/desktop/src/main/maker-ipc/register.ts b/apps/desktop/src/main/maker-ipc/register.tsindex 6b51ffb2b8..cba13fc0a9 100644--- a/apps/desktop/src/main/maker-ipc/register.ts+++ b/apps/desktop/src/main/maker-ipc/register.ts@@ -5979,9 +5979,11 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)// 目录刷新先登记被服务端挪走的 Auto:之后的上下文刷新会跳过已登记切换的任务,// 不再按旧来源重载一个已不提供该模型的连接。if (!targets) {- await followMovedCindyAutoRoutesNow().catch((error) => log.warn('Cindy Auto provider follow failed', {- error: error instanceof Error ? error.message : String(error),- }));+ await followMovedCindyAutoRoutesNow().catch((error) =>+ log.warn('Cindy Auto provider follow failed', {+ error: error instanceof Error ? error.message : String(error),+ }),+ );}}).then(() => refreshActiveModelContextSettings({targets, inferProviderId: (model, agent) => resolveDesktopModelContextProviderId(getActiveCatalog(), agent, null, model),@@ -15024,30 +15026,39 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)await followMovedCindyAutoRoutes({isReady: () => tryGetDbClient() !== null,// 远程主机 / 另一台电脑上运行的任务,路由由那一端的目录决定,不在本机改道。- listCandidates: async () => (await getDbClient().drizzle.select({- sessionId: sessions.id,- agentKind: sessions.agentKind,- model: sessions.model,- providerId: sessions.providerId,- effort: sessions.effort,- fastMode: sessions.fastMode,- }).from(sessions).where(and(- eq(sessions.status, 'active'),- or(eq(sessions.model, 'auto'), like(sessions.model, 'auto/%')),- isNull(sessions.remoteHostId),- isNull(sessions.agentDeviceId),- ))).map((row) => ({- sessionId: row.sessionId,- agentKind: dbToMakerAgentKind(row.agentKind),- model: row.model,- providerId: row.providerId?.trim() || null,- effort: row.effort ?? null,- fastMode: row.fastMode === true,- })),- listProviders: () => getDesktopProviderService().listProviders({- allowSideEffects: false,- catalog: getActiveCatalog(),- }),+ listCandidates: async () =>+ (+ await getDbClient()+ .drizzle.select({+ sessionId: sessions.id,+ agentKind: sessions.agentKind,+ model: sessions.model,+ providerId: sessions.providerId,+ effort: sessions.effort,+ fastMode: sessions.fastMode,+ })+ .from(sessions)+ .where(+ and(+ eq(sessions.status, 'active'),+ or(eq(sessions.model, 'auto'), like(sessions.model, 'auto/%')),+ isNull(sessions.remoteHostId),+ isNull(sessions.agentDeviceId),+ ),+ )+ ).map((row) => ({+ sessionId: row.sessionId,+ agentKind: dbToMakerAgentKind(row.agentKind),+ model: row.model,+ providerId: row.providerId?.trim() || null,+ effort: row.effort ?? null,+ fastMode: row.fastMode === true,+ })),+ listProviders: () =>+ getDesktopProviderService().listProviders({+ allowSideEffects: false,+ catalog: getActiveCatalog(),+ }),withSessionLock: withSendToSessionLock,readRoute: async (sessionId) => {// 用户或系统已登记的切换、运行时改道都是更晚的决定,不覆盖。@@ -15055,7 +15066,8 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)const credentialSwitch = getPendingCredentialSwitchTarget(sessionId);if (credentialSwitch && credentialSwitch.selectionSource !== 'agent') return null;const profiles = await readSessionRuntimeProfiles(sessionId);- if (!profiles || profiles.pendingMutation || profiles.control.effectiveOverride) return null;+ if (!profiles || profiles.pendingMutation || profiles.control.effectiveOverride)+ return null;return profiles.effective;},stage: (sessionId, route) => stageSessionRouteSelection(sessionId, route, route.agentKind),diff --git a/apps/desktop/src/main/model-access/__tests__/byokRuntime.test.ts b/apps/desktop/src/main/model-access/__tests__/byokRuntime.test.tsindex e8a10d154d..7b1bba1501 100644--- a/apps/desktop/src/main/model-access/__tests__/byokRuntime.test.ts+++ b/apps/desktop/src/main/model-access/__tests__/byokRuntime.test.ts@@ -476,7 +476,11 @@ describe('Cindy Auto moving between Cindy AI and the enterprise pool', () => {function withModels(revision: string, ...ids: string[]) {const next = structuredClone(directory);next.revision = revision;- next.providers[0].models = ids.map((id) => ({ ...structuredClone(provider.models[0]), id, name: id }));+ next.providers[0].models = ids.map((id) => ({+ ...structuredClone(provider.models[0]),+ id,+ name: id,+ }));return next;}async function syncTwice(first: typeof directory, second: typeof directory) {@@ -492,18 +496,30 @@ describe('Cindy Auto moving between Cindy AI and the enterprise pool', () => {}it('platform → pool: a newly listed pool Auto asks Cindy AI to refresh too', async () => {- const notify = await syncTwice(withModels('1', 'byok/a/chat'), withModels('2', 'byok/a/chat', 'auto/group-a'));+ const notify = await syncTwice(+ withModels('1', 'byok/a/chat'),+ withModels('2', 'byok/a/chat', 'auto/group-a'),+ );expect(notify).toHaveBeenCalledTimes(1);});it('pool → platform: a pool Auto that disappeared asks Cindy AI to refresh too', async () => {- const notify = await syncTwice(withModels('1', 'byok/a/chat', 'auto/group-a'), withModels('2', 'byok/a/chat'));+ const notify = await syncTwice(+ withModels('1', 'byok/a/chat', 'auto/group-a'),+ withModels('2', 'byok/a/chat'),+ );expect(notify).toHaveBeenCalledTimes(1);});it('does not ask when only ordinary pool models change or nothing changes', async () => {- expect(await syncTwice(withModels('1', 'byok/a/chat', 'auto/group-a'), withModels('2', 'byok/a/other', 'auto/group-a')))- .not.toHaveBeenCalled();- expect(await syncTwice(withModels('1', 'auto/group-a'), withModels('1', 'auto/group-a'))).not.toHaveBeenCalled();+ expect(+ await syncTwice(+ withModels('1', 'byok/a/chat', 'auto/group-a'),+ withModels('2', 'byok/a/other', 'auto/group-a'),+ ),+ ).not.toHaveBeenCalled();+ expect(+ await syncTwice(withModels('1', 'auto/group-a'), withModels('1', 'auto/group-a')),+ ).not.toHaveBeenCalled();});});diff --git a/apps/desktop/src/main/model-access/__tests__/modelsSyncRefresh.test.ts b/apps/desktop/src/main/model-access/__tests__/modelsSyncRefresh.test.tsindex 78751e8249..8acf4b38e2 100644--- a/apps/desktop/src/main/model-access/__tests__/modelsSyncRefresh.test.ts+++ b/apps/desktop/src/main/model-access/__tests__/modelsSyncRefresh.test.ts@@ -454,8 +454,12 @@ describe('cindyAutoModelIdsChanged', () => {});it('负向:只有普通模型变化、顺序变化或形似 auto 的 ID 不算', () => {- expect(cindyAutoModelIdsChanged(ids('auto/group-a', 'p1'), ids('p2', 'auto/group-a'))).toBe(false);- expect(cindyAutoModelIdsChanged(ids('autopilot', 'vendor/auto'), ids('automation'))).toBe(false);+ expect(cindyAutoModelIdsChanged(ids('auto/group-a', 'p1'), ids('p2', 'auto/group-a'))).toBe(+ false,+ );+ expect(cindyAutoModelIdsChanged(ids('autopilot', 'vendor/auto'), ids('automation'))).toBe(+ false,+ );expect(cindyAutoModelIdsChanged([], [])).toBe(false);});});diff --git a/apps/desktop/src/renderer/__tests__/draftModelCalibration.test.ts b/apps/desktop/src/renderer/__tests__/draftModelCalibration.test.tsindex c5a0eb713e..92607e43ec 100644--- a/apps/desktop/src/renderer/__tests__/draftModelCalibration.test.ts+++ b/apps/desktop/src/renderer/__tests__/draftModelCalibration.test.ts@@ -947,8 +947,11 @@ describe('factory defaults survive send-time calibration', () => {});describe('模型组 Auto:服务端决定默认与来源', () => {- const pool = (id: string, models: CatalogModel[], source: ProviderView['source'] = 'organization') =>- ({ ...provider(id, true, { pi: models }), source }) as ProviderView;+ const pool = (+ id: string,+ models: CatalogModel[],+ source: ProviderView['source'] = 'organization',+ ) => ({ ...provider(id, true, { pi: models }), source }) as ProviderView;const groupAuto = (marked: boolean) =>model('auto/group-1', marked ? { newSessionDefault: ['pi'] } : {});@@ -957,10 +960,23 @@ describe('模型组 Auto:服务端决定默认与来源', () => {const byok = pool('org-pool', [model('pool-model'), groupAuto(true)]);const providers = [gateway, byok];const expected = { model: 'auto/group-1', providerId: 'org-pool' };- expect(calibrateDraftModel({ providers, agent: 'pi', model: 'auto', chosenByUser: false,- preferredProviderId: 'xd', providersLoading: false })).toEqual(expected);- expect(resolveNewTaskDefaultRoute({ providers, agent: 'pi',- draft: { model: 'auto', providerId: 'xd', chosenByUser: false } })).toEqual(expected);+ expect(+ calibrateDraftModel({+ providers,+ agent: 'pi',+ model: 'auto',+ chosenByUser: false,+ preferredProviderId: 'xd',+ providersLoading: false,+ }),+ ).toEqual(expected);+ expect(+ resolveNewTaskDefaultRoute({+ providers,+ agent: 'pi',+ draft: { model: 'auto', providerId: 'xd', chosenByUser: false },+ }),+ ).toEqual(expected);expect(resolveNewTaskDefaultRoute({ providers, agent: 'pi' })).toEqual(expected);});@@ -969,33 +985,69 @@ describe('模型组 Auto:服务端决定默认与来源', () => {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);+ 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);+ 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' });+ 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('用户手动选过的模型不被服务端默认覆盖', () => {const gateway = provider('xd', true, { pi: [model('auto'), groupAuto(true)] });const byok = pool('org-pool', [model('pool-model')]);const providers = [gateway, byok];- expect(calibrateDraftModel({ providers, agent: 'pi', model: 'pool-model', chosenByUser: true,- preferredProviderId: 'org-pool', providersLoading: false }))- .toEqual({ model: 'pool-model', providerId: null });- expect(resolveNewTaskDefaultRoute({ providers, agent: 'pi',- draft: { model: 'pool-model', providerId: 'org-pool', chosenByUser: true } }))- .toEqual({ model: 'pool-model', providerId: 'org-pool' });+ expect(+ calibrateDraftModel({+ providers,+ agent: 'pi',+ model: 'pool-model',+ chosenByUser: true,+ preferredProviderId: 'org-pool',+ providersLoading: false,+ }),+ ).toEqual({ model: 'pool-model', providerId: null });+ expect(+ resolveNewTaskDefaultRoute({+ providers,+ agent: 'pi',+ draft: { model: 'pool-model', providerId: 'org-pool', chosenByUser: true },+ }),+ ).toEqual({ model: 'pool-model', providerId: 'org-pool' });});it('Auto 从两份目录都消失:不崩,落到记着的来源里仍可用的模型', () => {@@ -1003,29 +1055,50 @@ describe('模型组 Auto:服务端决定默认与来源', () => {const byok = pool('org-pool', [model('pool-model')]);const providers = [gateway, byok];for (const chosenByUser of [false, true]) {- expect(resolveNewTaskDefaultRoute({ providers, agent: 'pi',- draft: { model: 'auto/group-1', providerId: 'org-pool', chosenByUser } }))- .toEqual({ model: 'pool-model', providerId: 'org-pool' });+ expect(+ resolveNewTaskDefaultRoute({+ providers,+ agent: 'pi',+ draft: { model: 'auto/group-1', providerId: 'org-pool', chosenByUser },+ }),+ ).toEqual({ model: 'pool-model', providerId: 'org-pool' });}- expect(calibrateDraftModel({ providers, agent: 'pi', model: 'auto/group-1', chosenByUser: false,- preferredProviderId: 'org-pool', providersLoading: false }))- .toEqual({ model: 'pool-model', providerId: 'org-pool' });+ expect(+ calibrateDraftModel({+ providers,+ agent: 'pi',+ model: 'auto/group-1',+ chosenByUser: false,+ preferredProviderId: 'org-pool',+ providersLoading: false,+ }),+ ).toEqual({ model: 'pool-model', providerId: 'org-pool' });});it('回归:订阅、自定义供应商、个人用户与预设 auto 的默认不变', () => {// 个人用户:目录标的是 GLM,默认仍是预设 auto,来源 Cindy AI。- const personal = provider('xd', true, { pi: [model('z-ai/glm-5.3-flash', { newSessionDefault: ['pi'] }), model('auto')] });- expect(resolveNewTaskDefaultRoute({ providers: [personal], agent: 'pi' }))- .toEqual({ model: 'auto', providerId: 'xd' });+ const personal = provider('xd', true, {+ pi: [model('z-ai/glm-5.3-flash', { newSessionDefault: ['pi'] }), model('auto')],+ });+ expect(resolveNewTaskDefaultRoute({ providers: [personal], agent: 'pi' })).toEqual({+ model: 'auto',+ providerId: 'xd',+ });// 订阅:Codex 订阅在场时 Codex 默认仍是订阅里的 Sol,不受 Pi 侧 Auto 规则影响。const openai = provider('openai', true, { codex: [model('gpt-6.1-sol')] }, 'subscription');- expect(resolveNewTaskDefaultRoute({ providers: [openai, personal], agent: 'codex' }))- .toEqual({ model: 'gpt-6.1-sol', providerId: 'openai' });+ expect(resolveNewTaskDefaultRoute({ providers: [openai, personal], agent: 'codex' })).toEqual({+ model: 'gpt-6.1-sol',+ providerId: 'openai',+ });// 自定义供应商:记着的自定义来源与模型原样保留。const custom = pool('custom-litellm', [model('custom-model')], 'user');- expect(resolveNewTaskDefaultRoute({ providers: [personal, custom], agent: 'pi',- draft: { model: 'custom-model', providerId: 'custom-litellm', chosenByUser: true } }))- .toEqual({ model: 'custom-model', providerId: 'custom-litellm' });+ expect(+ resolveNewTaskDefaultRoute({+ providers: [personal, custom],+ agent: 'pi',+ draft: { model: 'custom-model', providerId: 'custom-litellm', chosenByUser: true },+ }),+ ).toEqual({ model: 'custom-model', providerId: 'custom-litellm' });});it('新建任务提交时,Auto 已挪走的旧来源换成解析出的新来源;其它显式来源原样提交', () => {@@ -1033,11 +1106,32 @@ describe('模型组 Auto:服务端决定默认与来源', () => {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');+ 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/renderer/lib/__tests__/newMakerDefaultTuple.test.ts b/apps/desktop/src/renderer/lib/__tests__/newMakerDefaultTuple.test.tsindex 659a073f9e..398a418a0d 100644--- a/apps/desktop/src/renderer/lib/__tests__/newMakerDefaultTuple.test.ts+++ b/apps/desktop/src/renderer/lib/__tests__/newMakerDefaultTuple.test.ts@@ -339,31 +339,59 @@ describe('resolveNewMakerDefaultTuple', () => {});describe('服务端标记的 Cindy Auto(模型组 Auto)', () => {- function pool(id: string, models: CatalogModel[], source: ProviderView['source'] = 'organization') {+ function pool(+ id: string,+ models: CatalogModel[],+ source: ProviderView['source'] = 'organization',+ ) {return { ...provider({ id, access: 'managed', models: { pi: models } }), source };}const groupAuto = (newSessionDefault?: CatalogModel['newSessionDefault']) =>model('auto/group-1', 'high', newSessionDefault);it('目标是平台模型:跟随 Cindy AI 下被标记的组 Auto,不再用预设 auto', () => {- const gateway = provider({ id: 'xd', access: 'managed', models: { pi: [model('auto'), groupAuto(['pi'])] } });- expect(resolve([gateway])).toEqual({ vendor: 'pi', providerId: 'xd', model: 'auto/group-1', effort: 'high' });+ const gateway = provider({+ id: 'xd',+ access: 'managed',+ models: { pi: [model('auto'), groupAuto(['pi'])] },+ });+ expect(resolve([gateway])).toEqual({+ vendor: 'pi',+ providerId: 'xd',+ model: 'auto/group-1',+ effort: 'high',+ });});it('目标是号池模型:Auto 在企业号池供应商下,用号池来源', () => {const gateway = provider({ id: 'xd', access: 'managed', models: { pi: [model('auto')] } });const byok = pool('org-pool', [model('pool-model'), groupAuto(['pi'])]);- for (const sources of [[gateway, byok], [byok, gateway]]) {- expect(resolve(sources)).toEqual({ vendor: 'pi', providerId: 'org-pool', model: 'auto/group-1', effort: 'high' });+ for (const sources of [+ [gateway, byok],+ [byok, gateway],+ ]) {+ expect(resolve(sources)).toEqual({+ vendor: 'pi',+ providerId: 'org-pool',+ model: 'auto/group-1',+ effort: 'high',+ });}// 没有订阅也要把默认切到 Pi,这条规则不能因为模型换了来源而失效。expect(resolve([byok])).toMatchObject({ vendor: 'pi', providerId: 'org-pool' });});it('Cindy AI 与号池短暂各标一个默认时以 Cindy AI 为准,与来源列表顺序无关', () => {- const gateway = provider({ id: 'xd', access: 'managed', models: { pi: [model('auto', 'high', ['pi'])] } });+ const gateway = provider({+ id: 'xd',+ access: 'managed',+ models: { pi: [model('auto', 'high', ['pi'])] },+ });const byok = pool('org-pool', [groupAuto(['pi'])]);- for (const sources of [[gateway, byok], [byok, gateway]]) {+ for (const sources of [+ [gateway, byok],+ [byok, gateway],+ ]) {expect(resolve(sources)).toMatchObject({ providerId: 'xd', model: 'auto' });}});@@ -397,24 +425,46 @@ describe('resolveNewMakerDefaultTuple', () => {it('订阅等内置非 Cindy AI 来源里被标记的 auto/... 不当组 Auto', () => {const gateway = provider({ id: 'xd', access: 'managed', models: { pi: [model('auto')] } });// 订阅来源(内置、非 Cindy AI)里恰好有个被标记的 auto/...:不参与 Auto 规则。- const openai = provider({ id: 'openai', access: 'subscription', models: { pi: [groupAuto(['pi'])] } });- expect(resolve([openai, gateway], new Set(['pi']))).toMatchObject({ providerId: 'xd', model: 'auto' });+ const openai = provider({+ id: 'openai',+ access: 'subscription',+ models: { pi: [groupAuto(['pi'])] },+ });+ expect(resolve([openai, gateway], new Set(['pi']))).toMatchObject({+ providerId: 'xd',+ model: 'auto',+ });expect(resolve([openai], new Set(['pi']))).toBeNull();});it('Auto 从两份目录都消失:不编造默认,交给后续规则或既有空态', () => {- const gateway = provider({ id: 'xd', access: 'managed', models: { pi: [model('z-ai/glm-5.3-flash', 'high', ['pi'])] } });+ const gateway = provider({+ id: 'xd',+ access: 'managed',+ models: { pi: [model('z-ai/glm-5.3-flash', 'high', ['pi'])] },+ });const byok = pool('org-pool', [model('pool-model')]);expect(resolve([gateway, byok])).toBeNull();- const xai = provider({ id: 'xai', access: 'subscription', models: { pi: [model('grok-4.6')] } });+ const xai = provider({+ id: 'xai',+ access: 'subscription',+ models: { pi: [model('grok-4.6')] },+ });expect(resolve([gateway, byok, xai])).toMatchObject({ providerId: 'xai', model: 'grok-4.6' });});it('个人订阅仍然优先', () => {- const openai = provider({ id: 'openai', access: 'subscription', models: { codex: [model('gpt-6.1-sol')] } });+ const openai = provider({+ id: 'openai',+ access: 'subscription',+ models: { codex: [model('gpt-6.1-sol')] },+ });const byok = pool('org-pool', [groupAuto(['pi'])]);expect(resolve([byok, openai])).toMatchObject({ providerId: 'openai', vendor: 'codex' });- expect(resolve([byok, openai], new Set(['pi']))).toMatchObject({ providerId: 'org-pool', model: 'auto/group-1' });+ expect(resolve([byok, openai], new Set(['pi']))).toMatchObject({+ providerId: 'org-pool',+ model: 'auto/group-1',+ });});});diff --git a/apps/desktop/src/shared/newMakerDefaultTuple.ts b/apps/desktop/src/shared/newMakerDefaultTuple.tsindex 3ce2017710..1d62d7cda9 100644--- a/apps/desktop/src/shared/newMakerDefaultTuple.ts+++ b/apps/desktop/src/shared/newMakerDefaultTuple.ts@@ -126,11 +126,12 @@ function matchingModel(// Both renderer and unattended callers keep the same-provider fallback.// Without local visibility overrides, use the catalog's default visibility.// Cindy Auto is an upstream route identity; do not substitute a fixed model.- const candidates = pass === 'serverMarkedAuto'- ? models.filter((model) => isServerMarkedAuto(model, agent)).sort(bySortOrder)- : pass === 'preferred'- ? modelIds.map((id) => models.find((model) => model.id === id))- : models.slice().sort(bySortOrder);+ const candidates =+ pass === 'serverMarkedAuto'+ ? models.filter((model) => isServerMarkedAuto(model, agent)).sort(bySortOrder)+ : pass === 'preferred'+ ? modelIds.map((id) => models.find((model) => model.id === id))+ : models.slice().sort(bySortOrder);return candidates.find((model) =>@@ -158,7 +159,8 @@ export function resolveNewMakerDefaultTuples(args: {const tuples: NewMakerDefaultTuple[] = [];for (const policy of DEFAULT_POLICIES) {- const isPolicyProvider = (candidate: ProviderView) => providerCatalogId(candidate) === policy.providerId;+ const isPolicyProvider = (candidate: ProviderView) =>+ providerCatalogId(candidate) === policy.providerId;const matchingProviders = providers.filter((candidate) =>@@ -183,13 +185,7 @@ export function resolveNewMakerDefaultTuples(args: {for (const agent of policy.agents) {const vendor = vendorForAgent(agent);if (!availableAgents.has(vendor)) continue;- const model = matchingModel(- provider,- agent,- policy.modelIds,- pass,- args.isModelEnabled,- );+ const model = matchingModel(provider, agent, policy.modelIds, pass, args.isModelEnabled);if (!model) continue;tuples.push({vendor,