Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(model-default): 保留 Auto 跟随中的来源身份
fmfsaisaie36f18ae8d6b
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/cindyAutoRouteFollow.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/cindyAutoRouteFollow.test.tsindex b8087a23c5..5ef20fc8a0 100644--- a/apps/desktop/src/main/maker-ipc/__tests__/cindyAutoRouteFollow.test.ts+++ b/apps/desktop/src/main/maker-ipc/__tests__/cindyAutoRouteFollow.test.ts@@ -368,20 +368,24 @@ describe('已登记的 Auto 换来源,在 Auto 又挪动后撤销或改写', (fastMode: false,};- function follow(providers: ProviderView[], intent: typeof stagedToPlatform | undefined) {+ function follow(+ providers: ProviderView[],+ intent: typeof stagedToPlatform | undefined,+ currentRoute = current,+ ) {const stage = vi.fn(async () => {});const cancelStagedSwitch = vi.fn(async () => {});- const readStagedSwitch = async () => stagedCindyAutoSwitch(intent, current);+ const readStagedSwitch = async () => stagedCindyAutoSwitch(intent, currentRoute);return {stage,cancelStagedSwitch,run: () =>followMovedCindyAutoRoutes({- listCandidates: async () => [{ sessionId: TASK, ...current }],+ listCandidates: async () => [{ sessionId: TASK, ...currentRoute }],listProviders: async () => providers,withSessionLock: async (_sessionId, run) => run(),// 已有登记时加锁重读一律不给路由(与真实 readRoute 一致)。- readRoute: async () => (intent ? null : current),+ readRoute: async () => (intent ? null : currentRoute),readStagedSwitch,cancelStagedSwitch,stage,@@ -435,6 +439,32 @@ describe('已登记的 Auto 换来源,在 Auto 又挪动后撤销或改写', (expect(stage).not.toHaveBeenCalled();});+ // PR #6355 Codex P1:配置登记也可能切向用户来源;现有撤销/改登记只覆盖 Cindy 两端。+ // unit:走实际跟随入口,不能撤销或覆盖待生效的凭证/计费来源。+ it.each([+ { from: POOL, target: 'custom', availableAt: OTHER_POOL },+ { from: POOL, target: 'custom', availableAt: POOL },+ { from: 'custom', target: 'xd', availableAt: 'custom' },+ ])(+ '保留非 Cindy 两端的配置登记:$from → $target(Auto 在 $availableAt)',+ async ({ from, target, availableAt }) => {+ const providers = [+ provider('xd', 'builtin', availableAt === 'xd' ? [REAL_AUTO] : ['auto']),+ provider(POOL, 'organization', availableAt === POOL ? [REAL_AUTO] : []),+ provider(OTHER_POOL, 'organization', availableAt === OTHER_POOL ? [REAL_AUTO] : []),+ provider('custom', 'user', availableAt === 'custom' ? [REAL_AUTO] : []),+ ];+ const { stage, cancelStagedSwitch, run } = follow(+ providers,+ { ...stagedToPlatform, providerId: target },+ { ...current, providerId: from },+ );+ expect(await run()).toBe(0);+ expect(stage).not.toHaveBeenCalled();+ expect(cancelStagedSwitch).not.toHaveBeenCalled();+ },+ );+it('负向:只认系统登记、同引擎、同一个 Auto、只换来源的登记', () => {expect(stagedCindyAutoSwitch(stagedToPlatform, current)).toEqual({current,diff --git a/apps/desktop/src/main/maker-ipc/cindyAutoRouteFollow.ts b/apps/desktop/src/main/maker-ipc/cindyAutoRouteFollow.tsindex 8a88673e1f..aec5973970 100644--- a/apps/desktop/src/main/maker-ipc/cindyAutoRouteFollow.ts+++ b/apps/desktop/src/main/maker-ipc/cindyAutoRouteFollow.ts@@ -1,6 +1,7 @@import {effectiveSourceIdForModel,isCindyAutoModelId,+ isCindyDistributedProvider,movedCindyAutoSourceId,type AgentKind,type ProviderView,@@ -169,6 +170,16 @@ async function recheckStagedSwitch(// 其它引擎的默认来源不一定是 Cindy AI,判断不了就不动。if (!from) return false;const target = cindySourceId(current.agentKind, targetProviderId);+ // configStaged 也用于伙伴/IM 的配置切换;只有两端都是 Cindy 来源才重核 Auto 登记。+ const fromProvider = providers.find((provider) => provider.id === from);+ const targetProvider = providers.find((provider) => provider.id === target);+ if (+ !fromProvider ||+ !isCindyDistributedProvider(fromProvider) ||+ !targetProvider ||+ !isCindyDistributedProvider(targetProvider)+ )+ return false;const now = effectiveSourceIdForModel([...providers], from, current.model, current.agentKind);if (now === target) return false;if (!now || now === from) {diff --git a/apps/mobile/src/__tests__/newSession.test.ts b/apps/mobile/src/__tests__/newSession.test.tsindex 624c58d4ae..1b1901c09f 100644--- a/apps/mobile/src/__tests__/newSession.test.ts+++ b/apps/mobile/src/__tests__/newSession.test.ts@@ -946,6 +946,17 @@ describe('pickAgentDefaultRuntime', () => {expect(resolveRecentModelAndProvider(toPool, { model: auto, providerId: 'xd' }, 'pi', true),).toEqual({ model: auto, providerId: 'org-pool' });+ // PR #6355 Greptile P1:身份取完整目录,但隐藏的 Cindy AI 同名模型不能挤掉可见号池。+ // unit:旧号池无行,平台组 Auto 无行,自定义来源排在前面;仍选可见的新号池。+ const visible = [toPool[0], toPool[2]];+ const fullCatalog = [+ ...visible.map((row) => row.provider),+ autoRow('old-pool', 'organization', [], 'unused').provider,+ autoRow('xd', 'builtin', [auto], auto).provider,+ ];+ expect(+ resolveRecentModelAndProvider(visible, { model: auto, providerId: 'old-pool' }, 'pi', true, undefined, fullCatalog),+ ).toEqual({ model: auto, providerId: 'org-pool' });// 负向:用户自己接的供应商仍提供同名 auto/... 时原样保留,不被拉去 Cindy 来源。expect(resolveRecentModelAndProvider(toPlatform, { model: auto, providerId: 'custom' }, 'pi', true),diff --git a/apps/mobile/src/__tests__/newSessionHostDefaults.test.tsx b/apps/mobile/src/__tests__/newSessionHostDefaults.test.tsxindex b2f48b541c..1e9ed59aba 100644--- a/apps/mobile/src/__tests__/newSessionHostDefaults.test.tsx+++ b/apps/mobile/src/__tests__/newSessionHostDefaults.test.tsx@@ -3,7 +3,8 @@ import { useNewSessionHostDefaults } from '@/session/useNewSessionHostDefaults';import { useNewSessionDefaultSelection } from '@/session/useNewSessionDefaultSelection';import { DEFAULT_NEW_SESSION_DRAFT, isNewSessionRuntimePending, type NewSessionAgentKind, type NewSessionStoredPreferences } from '@/session/newSession';import type { MobileNewMakerDefaults } from '@/device-link/mobileMakerTransport';-import { buildMobileModelSections } from '@/session/providerModelSections';+import type { ProviderView } from '@cindy/model-providers';+import { flattenProviderSections, buildMobileModelSections } from '@/session/providerModelSections';import { act, createElement, useRef, useState } from 'react';import { createRoot, type Root } from 'react-dom/client';import { afterEach, beforeEach, expect, it, vi } from 'vitest';@@ -16,6 +17,7 @@ vi.mock('@/session/fullAccessConfirmation', () => ({ confirmFullAccessChange: vivi.mock('@/debug/mobileDebugLog', () => ({ mobileDebugLog: vi.fn() }));function usePageDefaults(bindings: Parameters<typeof useNewSessionHostDefaults>[0] & {preferences: NewSessionStoredPreferences | null;+ providers?: ProviderView[];}) {const [draft, setDraft] = useState(bindings.draft);const [settledDeviceId, setSettledDeviceId] = useState<string | null>(null);@@ -23,7 +25,8 @@ function usePageDefaults(bindings: Parameters<typeof useNewSessionHostDefaults>[const defaults = useNewSessionHostDefaults({ ...bindings, draft });const selectedDeviceRef = useRef(bindings.selectedDeviceId);selectedDeviceRef.current = bindings.selectedDeviceId;- const deviceProviders = useRef({ providers: [], ready: false, loading: true, unsupported: false, error: null }).current;+ const deviceProviders = useRef({ providers: bindings.providers ?? [], ready: !!bindings.providers, loading: !bindings.providers, unsupported: false, error: null }).current;+ const modelSections = buildMobileModelSections({ providers: deviceProviders.providers, agentKind: draft.agentKind });useNewSessionDefaultSelection({...defaults, draft, setDraft, userTouchedRuntimeRef,selectedDeviceId: bindings.selectedDeviceId, selectedDeviceRef,@@ -32,8 +35,8 @@ function usePageDefaults(bindings: Parameters<typeof useNewSessionHostDefaults>[autoDefaultDeviceRef: useRef(null),appliedPermissionMemoryRef: useRef(true),runtimeActionSeqRef: useRef(0), deviceProviders, deviceProvidersRef: useRef(deviceProviders),- catalogReadyRef: useRef(false), capabilities: null, modelRows: [],- modelSections: buildMobileModelSections({ providers: [], agentKind: draft.agentKind }),+ catalogReadyRef: useRef(deviceProviders.ready), capabilities: null, modelRows: flattenProviderSections(modelSections.sections),+ modelSections,flatModelsForUnsupportedHost: () => undefined, targetAgentHasFast: () => false,draftMemory: { getFast: () => false, getEffort: () => undefined, setFast: () => {}, setEffort: () => {} },settleRuntime: (_source, deviceId) => setSettledDeviceId(deviceId),@@ -69,12 +72,12 @@ function deferred<T>() {const promise = new Promise<T>((yes, no) => { resolve = yes; reject = no; });return { promise, resolve, reject };}-function mount(deviceId = 'desktop', agentKind: NewSessionAgentKind = 'codex', failedAgent?: string, storedAgent: NewSessionAgentKind | null = null, pendingAgents: NewSessionAgentKind[] = []) {+function mount(deviceId = 'desktop', agentKind: NewSessionAgentKind = 'codex', failedAgent?: string, storedAgent: NewSessionAgentKind | null = null, pendingAgents: NewSessionAgentKind[] = [], providers?: ProviderView[]) {if (root) act(() => root!.unmount());const read = deferred<MobileNewMakerDefaults>();const pendingReads = new Map(pendingAgents.map((agent) => [agent, deferred<MobileNewMakerDefaults>()]));const bindings = {- selectedDeviceId: deviceId, deviceLinkStatus: 'online', selectedDeviceRef: { current: deviceId },+ providers, selectedDeviceId: deviceId, deviceLinkStatus: 'online', selectedDeviceRef: { current: deviceId },outboxOwner: getMobileAuthOwner(), remoteAgentChoice: null,draft: { ...DEFAULT_NEW_SESSION_DRAFT, agentKind, model: 'chosen', providerId: 'provider', effort: 'high', fastMode: false },maker: { getNewMakerDefaults: vi.fn((agent?: string) => agent === failedAgent ? Promise.reject(new Error('read failed')) : pendingReads.get(agent as NewSessionAgentKind)?.promise ?? read.promise), applyNewMakerDraftPref: vi.fn(async () => {}) },@@ -232,3 +235,21 @@ it('caches a confirmed empty default but retries an unready host without discardexpect(mount().state.settled).toBe(true);await act(async () => {});});++// PR #6355 Greptile P1:旧号池无模型行时仍须保留目录身份,不能误选同名自定义模型。+// unit:真实页面 hooks + 列表构建 + 默认选择,覆盖初次默认和恢复已记住的引擎两条入口。+it.each([null, 'pi'] as const)('旧号池没有模型行时按完整目录跟随 Auto(保存的引擎:%s)', async (storedAgent) => {+ const auto = 'auto/group-1';+ const provider = (id: string, source: ProviderView['source'], modelIds: string[]): ProviderView => ({+ id, name: id, source, agents: ['pi'], connected: true,+ auth: { method: source === 'user' ? 'apiKey' : 'managed' },+ access: { kind: source === 'user' ? 'api' : 'managed' },+ routing: { pi: { upstream: 'https://example.test', authStrategy: 'api-key-header' } },+ models: { pi: modelIds.map(id => ({ id, name: id, contextWindow: 200_000, efforts: [], defaultEffort: null })) },+ });+ const providers = [provider('custom', 'user', [auto]), provider('pool-old', 'organization', []), provider('pool-new', 'organization', [auto])];+ const page = mount('auto-desktop', 'pi', undefined, storedAgent, [], providers);+ await act(async () => page.read.resolve({ worktreeEnabled: false, model: auto, providerId: 'pool-old', effort: '' }));+ expect(page.state.draft.model).toBe(auto);+ expect(page.state.draft.providerId).toBe('pool-new');+});diff --git a/apps/mobile/src/session/newSession.ts b/apps/mobile/src/session/newSession.tsindex 22fbeb904a..cba44ad8c1 100644--- a/apps/mobile/src/session/newSession.ts+++ b/apps/mobile/src/session/newSession.ts@@ -15,7 +15,7 @@ import type {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 { effectiveSourceIdForModel, type ProviderView } from '@cindy/model-providers/registry';import { reconcileEffortForModel, type ProviderModelRow } from './providerModelSections';import type { RemoteSession } from './types';@@ -477,6 +477,7 @@ export function resolveRecentModelAndProvider(agentKind: NewSessionAgentKind,catalogReady: boolean,visibilityOverrides?: Record<string, boolean> | null,+ providers?: readonly ProviderView[],): { model: string; providerId: string | null } {if (!catalogReady || modelNeedsReselection(visibilityOverrides, agentKind, recent.model, recent.providerId)) {return { model: recent.model, providerId: recent.providerId };@@ -512,8 +513,12 @@ export function resolveRecentModelAndProvider(// 挪到企业号池(或反过来)后,记住的来源不再提供它 —— 改用当前提供它的那一家 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);+ // 旧来源可能已经没有模型行;身份从完整目录取,候选目标仍须有可见行。+ const catalog = providers ?? [...new Map(modelRows.map((row) => [row.provider.id, row.provider])).values()];+ const relocationProviders = catalog.filter((provider) =>+ provider.id === recent.providerId || validateModelProviderId(modelRows, provider.id, recent.model, true),+ );+ const relocated = effectiveSourceIdForModel(relocationProviders, recent.providerId, recent.model, agentKind);if (relocated && validateModelProviderId(modelRows, relocated, recent.model, true)) {return { model: recent.model, providerId: relocated };}@@ -793,6 +798,8 @@ export function pickAgentDefaultRuntime(args: {/** 被控电脑该 agent 的新建任务默认(hostDraftRuntimeFromDefaults);null = 无 / 旧被控端。 */hostRuntime: NewSessionRuntime | null;modelRows: readonly ProviderModelRow[];+ /** 完整目录用于识别没有可见模型行的旧来源。 */+ providers?: readonly ProviderView[];currentEffort: string;/** 供应商目录是否已就绪(加载完成);未就绪时来源校验信任被控电脑默认(见 validateModelProviderId)。 */catalogReady: boolean;@@ -815,6 +822,7 @@ export function pickAgentDefaultRuntime(args: {agentKind,catalogReady,args.visibilityOverrides,+ args.providers,));} else if (catalogReady && modelRows[0]) {// 首项分支只在目录就绪时取——切到未缓存设备瞬间旧设备目录会短暂残留@@ -961,6 +969,8 @@ export function resolveNewSessionAutoDefault(input: {/** 被控电脑 rowsAgentKind 的新建任务默认(hostDraftRuntimeFromDefaults);null = 无。 */hostRuntime: NewSessionRuntime | null;modelRows: readonly ProviderModelRow[];+ /** 完整目录用于识别没有可见模型行的旧来源。 */+ providers?: readonly ProviderView[];/** modelRows 是按哪个 agent 的目录构建的;被控电脑默认只在同一 agent 时采用。 */rowsAgentKind: NewSessionAgentKind;/** 供应商目录是否已就绪;未就绪时来源校验信任被控电脑默认(见 validateModelProviderId)。 */@@ -998,6 +1008,7 @@ export function resolveNewSessionAutoDefault(input: {rowsAgentKind,catalogReady,input.visibilityOverrides,+ input.providers,);const sectionModel = findSectionModelRow(modelRows, model, providerId)?.model;return {diff --git a/apps/mobile/src/session/useNewSessionDefaultSelection.ts b/apps/mobile/src/session/useNewSessionDefaultSelection.tsindex 6959a6c798..fbbbb8e875 100644--- a/apps/mobile/src/session/useNewSessionDefaultSelection.ts+++ b/apps/mobile/src/session/useNewSessionDefaultSelection.ts@@ -103,6 +103,7 @@ export function useNewSessionDefaultSelection({agentKind: storedAgentKind,hostRuntime: hostRuntimeFor(storedAgentKind),modelRows: rowsNow,+ providers: deviceProvidersRef.current.providers,currentEffort,catalogReady: catalogReadyRef.current,visibilityOverrides: deviceProvidersRef.current.modelVisibilityOverrides,@@ -229,6 +230,7 @@ export function useNewSessionDefaultSelection({hostDefaultsSettled,hostRuntime: hostRuntimeFor(draft.agentKind),modelRows,+ providers: deviceProviders.providers,rowsAgentKind: draft.agentKind,catalogReady: deviceProviders.ready,visibilityOverrides: deviceProviders.modelVisibilityOverrides,@@ -293,6 +295,6 @@ export function useNewSessionDefaultSelection({autoDefaultSnapshotRef.current = previousAutoDefaultSnapshot;}};- }, [capabilities?.availableModels, deviceProviders.loading, draft.effort, draft.permissionMode, draft.agentKind, modelRows, deviceProviders.ready, deviceProviders.modelVisibilityOverrides, deviceProviders.unsupported, modelSections.connected.length, newSessionPreferences, newSessionPreferencesLoaded, selectedDeviceId, hostDefaultsSettled, hostDraftDefaults, hostRuntimeFor]);+ }, [capabilities?.availableModels, deviceProviders.providers, deviceProviders.loading, draft.effort, draft.permissionMode, draft.agentKind, modelRows, deviceProviders.ready, deviceProviders.modelVisibilityOverrides, deviceProviders.unsupported, modelSections.connected.length, newSessionPreferences, newSessionPreferencesLoaded, selectedDeviceId, hostDefaultsSettled, hostDraftDefaults, hostRuntimeFor]);}diff --git a/docs/dev-rules/model-catalog-maintenance.md b/docs/dev-rules/model-catalog-maintenance.mdindex 284b2623f7..981db42303 100644--- a/docs/dev-rules/model-catalog-maintenance.md+++ b/docs/dev-rules/model-catalog-maintenance.md@@ -152,13 +152,17 @@ Auto 只按模型 ID 认(`isCindyAutoModelId`):服务端可以把同一个之间挪动。记住的来源是这两类之一且已不再提供它时,`effectiveSourceIdForModel` 改用当前提供它的那一家(同样限于这两类),新建任务提交与手机端 `resolveRecentModelAndProvider` 复用同一规则;记住的来源仍列着它(只是断连或停用)、或是用户自己接的供应商时不改道。+手机端新建任务和恢复已记住引擎时,即使旧来源已没有可见模型行,仍用完整供应商目录识别其身份;+改道目标必须存在于当前可见模型行中,不能选中隐藏的目标或误用同名自定义模型。+目录刷新后,仍记着旧来源的进行中任务登记一次「下一条消息前切换」:引擎与模型 ID 不变,只换供应商与 Key(`apps/desktop/src/main/maker-ipc/cindyAutoRouteFollow.ts`)。用户点选、跨引擎或跨电脑的切换,以及等待生效的换凭证、运行时选择都不覆盖;运行时覆盖本身不算改道——目录刷新按原路由重新加载进行中任务时也会写上它,这时它就是当前路由,照常跟随——只有故障切换中(`fallbackHop > 0`)的任务不跟随。系统登记的 Auto 换来源(configStaged、同引擎、同一个 Auto、只换来源)在 Auto 再次挪动时按-当前位置重新核对:目标仍提供就不动;当前位置又能用、或哪里都没有了就撤销登记;去了别的来源就改登记-到那里。远程主机与另一台电脑上运行的任务不在本机改道。Auto 没有推理档位(任务里 effort+当前位置重新核对。重核前必须确认当前来源和登记目标都属于 Cindy 分发来源;伙伴或 IM 配置登记的+用户自定义来源切换不能被撤销或改登记。两端均属 Cindy 时:目标仍提供就不动;当前位置又能用、+或哪里都没有了就撤销登记;去了别的来源就改登记到那里。远程主机与另一台电脑上运行的任务不在本机改道。Auto 没有推理档位(任务里 effort为空串)时按 null 登记。Cindy AI 列表或企业号池目录任一边刷新后 Auto ID 有增减,会顺带刷新另一边(`cindyAutoModelIdsChanged`),跟随在两边都更新后才看到一致的位置;只刷新一边会把旧位置当成仍有效。请求被拒后刷新目录重试不在客户端处理。