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(hook): 远端只换 Agent 也清配对来源;null-team 兜底来源不因单个 team 改路由被清

Dash60a93cb49fad
diff --git a/apps/desktop/src/main/hook-control/__tests__/workspaceProviderSourceStore.test.ts b/apps/desktop/src/main/hook-control/__tests__/workspaceProviderSourceStore.test.ts
index fefc217766..66aeb5ad50 100644
--- a/apps/desktop/src/main/hook-control/__tests__/workspaceProviderSourceStore.test.ts
+++ b/apps/desktop/src/main/hook-control/__tests__/workspaceProviderSourceStore.test.ts
@@ -80,11 +80,12 @@ describe('workspaceProviderSourceStore', () => {
});
describe('远端快照改模型时清理同键来源(issue #5912)', () => {
- const row = (workspace: string, model: string | null, teamId: string | null = null) => ({
- workspace,
- model,
- teamId,
- });
+ const row = (
+ workspace: string,
+ model: string | null,
+ teamId: string | null = null,
+ agentKind: string | null = model === null ? null : 'codex',
+ ) => ({ workspace, model, teamId, agentKind });
it('模型被清空 / 整行消失 / 改成别的: 同键来源清除, 其它键与其它渠道不动', () => {
setWorkspaceProviderSource('x', null, 'chat', 'openai');
@@ -122,6 +123,27 @@ describe('workspaceProviderSourceStore', () => {
expect(listWorkspaceProviderSources()).toHaveLength(2);
});
+ it('只换 Agent、模型 id 不变也算路由变化, 来源清除', () => {
+ setWorkspaceProviderSource('x', null, 'chat', 'openai');
+ const next = clearWorkspaceProviderSourcesForRemoteModelChanges(
+ 'x',
+ [row('chat', 'shared-model', null, 'codex')],
+ [row('chat', 'shared-model', null, 'claude-code')],
+ );
+ expect(next).toEqual([]);
+ });
+
+ it('某 team 改路由不清共用的 null-team 兜底来源(避免其它 team 静默换账号)', () => {
+ setWorkspaceProviderSource('slack', null, 'repo', 'openai');
+ const next = clearWorkspaceProviderSourcesForRemoteModelChanges(
+ 'slack',
+ [row('repo', 'gpt-test', 'T1'), row('repo', 'gpt-test', 'T2')],
+ [row('repo', 'claude-test', 'T1'), row('repo', 'gpt-test', 'T2')],
+ );
+ expect(next).toBeNull();
+ expect(getWorkspaceProviderSource('slack', 'T2', 'repo')).toBe('openai');
+ });
+
it('按 teamId 精确键判定, 不误清其它 team 的来源', () => {
setWorkspaceProviderSource('slack', 'T1', 'repo', 'openai');
setWorkspaceProviderSource('slack', 'T2', 'repo', 'openai');
diff --git a/apps/desktop/src/main/hook-control/workspaceProviderSourceStore.ts b/apps/desktop/src/main/hook-control/workspaceProviderSourceStore.ts
index 417589f7dc..1f92ca6537 100644
--- a/apps/desktop/src/main/hook-control/workspaceProviderSourceStore.ts
+++ b/apps/desktop/src/main/hook-control/workspaceProviderSourceStore.ts
@@ -120,33 +120,40 @@ export function setWorkspaceProviderSource(
return next;
}
-/** 只需要偏好行的定位键与模型(HookWorkspacePrefs 的子集)。 */
-interface WorkspaceModelRow {
+/** 只需要偏好行的定位键与路由字段(HookWorkspacePrefs 的子集)。 */
+interface WorkspaceRouteRow {
workspace: string;
teamId?: string | null;
+ agentKind: string | null;
model: string | null;
}
/**
- * server 快照改动了某目录的模型(改成另一个 / 清空 / 整行消失)后, 清掉同键的来源偏好;
- * 有清除时返回更新后的全量条目, 否则返回 null。
+ * server 快照改动了某目录的路由(agentKind 或 model 改成别的 / 清空 / 整行消失)后,
+ * 清掉同键的来源偏好;有清除时返回更新后的全量条目, 否则返回 null。
*
- * 来源只在本机模型面板里和模型一起选, 远端(/model 卡、服务端快照)改模型时没有来源
- * 通道 —— 留着旧来源就会拼出「新模型 + 旧来源」的不可执行路由(issue #5912)。本机
- * 尚未镜像的写入在快照合并时优先, 模型不会被改动, 也就不会误清刚选的来源。
+ * 来源只在本机模型面板里和 (Agent, 模型) 一起选, 远端(/model 卡、服务端快照)改路由时
+ * 没有来源通道 —— 留着旧来源就会拼出「新路由 + 旧来源」的不可执行组合(issue #5912)。
+ * 本机尚未镜像的写入在快照合并时优先, 路由不会被改动, 也就不会误清刚选的来源。
+ *
+ * 只按来源条目自身的键比较。null-team 来源被多个 team 当兜底共用, 某个 team 远端改了
+ * 自己的路由时不清它: 清掉会让仍在用它的其它 team 静默改走默认来源(换账号)。这种
+ * 组合派发时按「显式来源失效」拒绝并提示重新选择。
*/
export function clearWorkspaceProviderSourcesForRemoteModelChanges(
channel: HookProviderChannel,
- before: readonly WorkspaceModelRow[],
- after: readonly WorkspaceModelRow[],
+ before: readonly WorkspaceRouteRow[],
+ after: readonly WorkspaceRouteRow[],
): WorkspaceProviderSourceEntry[] | null {
- const keyOf = (row: WorkspaceModelRow): string => `${row.teamId ?? ''}::${row.workspace}`;
- const modelBefore = new Map(before.map((row) => [keyOf(row), row.model] as const));
- const modelAfter = new Map(after.map((row) => [keyOf(row), row.model] as const));
- const changed = (e: WorkspaceProviderSourceEntry): boolean => {
- const key = `${e.teamId ?? ''}::${e.workspace}`;
- return (modelBefore.get(key) ?? null) !== (modelAfter.get(key) ?? null);
- };
+ const keyOf = (row: { teamId?: string | null; workspace: string }): string =>
+ `${row.teamId ?? ''}::${row.workspace}`;
+ const routeOf = (row: WorkspaceRouteRow): string =>
+ JSON.stringify([row.agentKind ?? null, row.model ?? null]);
+ const routeBefore = new Map(before.map((row) => [keyOf(row), routeOf(row)] as const));
+ const routeAfter = new Map(after.map((row) => [keyOf(row), routeOf(row)] as const));
+ const empty = JSON.stringify([null, null]);
+ const changed = (e: WorkspaceProviderSourceEntry): boolean =>
+ (routeBefore.get(keyOf(e)) ?? empty) !== (routeAfter.get(keyOf(e)) ?? empty);
const fp = filePath();
const entries = readFileEntries(fp);
const next = entries.filter((e) => e.channel !== channel || !changed(e));