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(desktop): 已显式选模后档位同步不再改模型配对

Dashd867728d8f4b
diff --git a/apps/desktop/src/renderer/__tests__/deviceLinkInteractionScenarios.test.ts b/apps/desktop/src/renderer/__tests__/deviceLinkInteractionScenarios.test.ts
index b84ebb5d52..fa325a7424 100644
--- a/apps/desktop/src/renderer/__tests__/deviceLinkInteractionScenarios.test.ts
+++ b/apps/desktop/src/renderer/__tests__/deviceLinkInteractionScenarios.test.ts
@@ -961,6 +961,8 @@ describe('远程交互接线不变式', () => {
expect(syncBody).toContain('patchVendorPrefsPreservingModelChoice');
expect(syncBody).toContain('markModelChoice ? patchVendorPrefs : patchVendorPrefsPreservingModelChoice');
expect(syncBody).toContain("opts.markModelChoice === true");
+ expect(syncBody).toContain('markModelChoice');
+ expect(syncBody).toContain('{ model: modelId, providerId: activeProviderId ?? null }');
expect(syncBody).toContain(
'opts.remoteDeviceId ?? getSessionDeviceId(sessionId) ?? deviceLinkDeviceId',
);
@@ -976,6 +978,11 @@ describe('远程交互接线不变式', () => {
expect(appSrc).toContain('model: modelId');
expect(appSrc).not.toContain("markModelChoice === false ? {} : { model: modelId }");
+ const draftSrc = read('state/newMakerDraft.ts');
+ expect(draftSrc).toContain('if (!opts.markModelChoice && modelChosen[vendor] === true)');
+ expect(draftSrc).toContain('delete nextPatch.model');
+ expect(draftSrc).toContain('delete nextPatch.providerId');
+
const newMakerDraftRouteSrc = read('features/cc-agent/NewMakerDraftRoute.tsx');
const pushActiveStart = newMakerDraftRouteSrc.indexOf('const pushActiveDraftPref');
expect(pushActiveStart).toBeGreaterThan(-1);
diff --git a/apps/desktop/src/renderer/__tests__/newMakerDraft.test.ts b/apps/desktop/src/renderer/__tests__/newMakerDraft.test.ts
index 6ec8a147cc..1adfe56e74 100644
--- a/apps/desktop/src/renderer/__tests__/newMakerDraft.test.ts
+++ b/apps/desktop/src/renderer/__tests__/newMakerDraft.test.ts
@@ -396,11 +396,28 @@ describe('newMakerDraft store', () => {
m1.patchVendorPrefsPreservingModelChoice('cc', {
model: 'claude-opus-4-8',
+ providerId: 'anthropic',
effort: 'high',
});
- expect(m1.getDraft().lastByVendor.cc.model).toBe('claude-opus-4-8');
+ expect(m1.getDraft().lastByVendor.cc.model).toBe('claude-sonnet-4-6');
+ expect(m1.getDraft().lastByVendor.cc.providerId).toBeNull();
+ expect(m1.getDraft().lastByVendor.cc.effort).toBe('high');
expect(m1.getDraft().modelChosenByVendor).toEqual({ cc: true });
- expect(m1.getPersistedVendorModel('cc')).toBe('claude-opus-4-8');
+ expect(m1.getPersistedVendorModel('cc')).toBe('claude-sonnet-4-6');
+ });
+
+ it('patchVendorPrefsPreservingModelChoice:未打标时仍可写回活动模型与来源', async () => {
+ const m1 = await loadModule();
+ m1.patchVendorPrefsPreservingModelChoice('cc', {
+ model: 'claude-opus-4-8',
+ providerId: 'anthropic',
+ effort: 'high',
+ });
+ expect(m1.getDraft().lastByVendor.cc.model).toBe('claude-opus-4-8');
+ expect(m1.getDraft().lastByVendor.cc.providerId).toBe('anthropic');
+ expect(m1.getDraft().lastByVendor.cc.effort).toBe('high');
+ expect(m1.getDraft().modelChosenByVendor).toEqual({});
+ expect(m1.getPersistedVendorModel('cc')).toBe('');
});
it('已有任务换模走 patchVendorPrefs,下次新建跟随这次选择', async () => {
diff --git a/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx b/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx
index ed5c6a95e8..beb9efc29a 100644
--- a/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx
+++ b/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx
@@ -5206,9 +5206,10 @@ export function ChatInput({
: 'cc';
const persistPrefs = markModelChoice ? patchVendorPrefs : patchVendorPrefsPreservingModelChoice;
persistPrefs(vendor, {
- // 只改思考档 / Fast 不得改写下次新建用的模型;换模才带 model 并打标记。
- ...(markModelChoice ? { model: modelId } : {}),
- providerId: activeProviderId ?? null,
+ // 只改思考档 / Fast 不得改写下次新建用的模型或来源;换模才带配对并打标记。
+ ...(markModelChoice
+ ? { model: modelId, providerId: activeProviderId ?? null }
+ : {}),
...(patch.effort !== undefined ? { effort: patch.effort } : {}),
});
if (memoryProviderId) {
diff --git a/apps/desktop/src/renderer/state/newMakerDraft.ts b/apps/desktop/src/renderer/state/newMakerDraft.ts
index cc36502210..ee0c1ab01c 100644
--- a/apps/desktop/src/renderer/state/newMakerDraft.ts
+++ b/apps/desktop/src/renderer/state/newMakerDraft.ts
@@ -150,7 +150,8 @@ export interface NewMakerDraft {
* 调度任务默认模型的三级回退(getPersistedVendorModel 消费)只认这里标记过的
* vendor,否则全新 / 没用过该 vendor 的用户会被对话侧 Opus 种子默认顶掉
* 成本保守兜底。patchVendorPrefs 收到显式 model 时置 true;只改思考档 / Fast
- * 的会话回写走 patchVendorPrefsPreservingModelChoice,不得清掉已有标记。
+ * 的会话回写走 patchVendorPrefsPreservingModelChoice:不得打标、不得清标,
+ * 也不得在已打标后改写 lastByVendor.model / providerId。
*/
modelChosenByVendor: Partial<Record<MakerVendor, boolean>>;
}
@@ -739,7 +740,8 @@ function patchVendorPrefsInternal(
opts: { markModelChoice: boolean },
): void {
const modelChosen = { ...currentDraft.modelChosenByVendor };
- if (typeof patch.model === 'string' && patch.model.length > 0) {
+ const nextPatch = { ...patch };
+ if (typeof nextPatch.model === 'string' && nextPatch.model.length > 0) {
if (opts.markModelChoice) {
// 新建页 picker 或已有任务换模 → 打标记,下次新建跟随这次选择,不再回落区域默认。
modelChosen[vendor] = true;
@@ -747,12 +749,17 @@ function patchVendorPrefsInternal(
// markModelChoice=false 仍可写回当前活动模型(远程草稿 / 旧控制端 wire
// 会带 modelId),但不得打标,也不得清掉已有标记。
}
+ if (!opts.markModelChoice && modelChosen[vendor] === true) {
+ // 已显式选过时,只改思考档 / Fast / 远程档位同步不得替换那次选择的模型或来源。
+ delete nextPatch.model;
+ delete nextPatch.providerId;
+ }
currentDraft = {
...currentDraft,
modelChosenByVendor: modelChosen,
lastByVendor: {
...currentDraft.lastByVendor,
- [vendor]: { ...currentDraft.lastByVendor[vendor], ...patch },
+ [vendor]: { ...currentDraft.lastByVendor[vendor], ...nextPatch },
},
};
scheduleWrite();
@@ -765,9 +772,9 @@ export function patchVendorPrefs(vendor: MakerVendor, patch: Partial<VendorPrefs
/**
* 已创建任务把思考档、以及 wire 上的当前活动模型同步回新建草稿时使用。
- * 可以更新 lastByVendor.model,但不把 modelChosenByVendor 打成「显式选过」:
- * 只改思考档 / 远程草稿回写不能把区域默认升级成用户选择,也不得清掉已有标记。
- * 本机已有任务里换模型应走 patchVendorPrefs,让下次新建跟随这次选择。
+ * 未打标时可以更新 lastByVendor.model / providerId,方便远程草稿 / 旧控制端
+ * 把活动值写回,但不把这次当成显式选模。已打标后只接受思考档等非选模字段,
+ * 不得替换那次选择的模型或来源。本机已有任务里换模型应走 patchVendorPrefs。
*/
export function patchVendorPrefsPreservingModelChoice(
vendor: MakerVendor,