Skip to content

fix(mcp): align image generation agent badges with dynamic registration state#1505

Merged
piorpua merged 4 commits intoiOfficeAI:mainfrom
Castor6:feat/image-generation-mcp
Mar 20, 2026
Merged

fix(mcp): align image generation agent badges with dynamic registration state#1505
piorpua merged 4 commits intoiOfficeAI:mainfrom
Castor6:feat/image-generation-mcp

Conversation

@Castor6
Copy link
Copy Markdown
Contributor

@Castor6 Castor6 commented Mar 19, 2026

Pull Request

Description

  • align image generation agent badges with dynamic registration state.
  • estore the dynamic registration status display of the Gemini badge in MCP.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

Testing

  • Tested on macOS
  • Tested on Windows
  • Tested on Linux
  • My code follows the project's code style guidelines
  • I have performed a self-review of my own code
  • My changes generate no new warnings or errors

Screenshots

截屏2026-03-20 00 08 25

@sentry
Copy link
Copy Markdown

sentry bot commented Mar 19, 2026

Codecov Report

❌ Patch coverage is 56.14035% with 25 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...s/settings/ToolsSettings/McpAgentStatusDisplay.tsx 0.00% 14 Missing ⚠️
...tings/SettingsModal/contents/ToolsModalContent.tsx 62.06% 6 Missing and 5 partials ⚠️

📢 Thoughts on this report? Let us know!

@piorpua
Copy link
Copy Markdown
Contributor

piorpua commented Mar 20, 2026

Code Review:fix(mcp): align image generation agent badges with dynamic registration state (#1505)

变更概述

本 PR 修复了图像生成区域的 agent badge 无法正确显示注册状态的问题,同时修复了 Gemini Badge 在 MCP 中的动态注册状态显示。改动涉及 McpService 的检测逻辑重构、ToolsModalContent 使用共享 hook 替代本地状态管理、以及 McpAgentStatusDisplay 新增 alwaysVisible 模式的入场动画。


方案评估

结论:✅ 方案合理

将 fork Gemini 从"跳过"改为"路由到 AionuiMcpAgent 并归并至 gemini source",根因定位准确。mergeDetectedServers 防止重复行的设计合理,skipNextImageGenerationAutoCheckRef 解决了手动 toggle 与 effect 自动触发的竞态,思路清晰。整体与项目架构一致,无过度工程化。


问题清单

🟡 MEDIUM — clearImageGenerationAgentStatus 在 state updater 内触发副作用

文件src/renderer/components/settings/SettingsModal/contents/ToolsModalContent.tsx,第 394–398 行

问题代码

setAgentInstallStatus((prev) => {
  const updated = { ...prev };
  delete updated[serverName];
  void ConfigStorage.set('mcp.agentInstallStatus', updated).catch((error) => {  // ← 副作用
    console.error('Failed to clear image generation agent install status:', error);
  });
  return updated;
});

问题说明:React 要求 state updater 函数是纯函数,不能包含副作用。在 React Strict Mode(开发环境)下,updater 函数会被执行两次以检测副作用,这会导致 ConfigStorage.set 被调用两次。即使生产环境不会出现双调用,这也违反了 React 的核心原则,使代码行为在不同模式下不一致。

修复建议

const clearImageGenerationAgentStatus = useCallback(
  (serverName: string) => {
    const updated = { ...agentInstallStatus };
    delete updated[serverName];
    setAgentInstallStatus(updated);
    void ConfigStorage.set('mcp.agentInstallStatus', updated).catch((error) => {
      console.error('Failed to clear image generation agent install status:', error);
    });
  },
  [setAgentInstallStatus, agentInstallStatus]
);

🔵 LOW — getDetectionTargetgetAgentForConfig 重复了 fork-Gemini 判断逻辑

文件src/process/services/mcpServices/McpService.ts,第 107–114 行 vs 第 151–166 行

问题代码

// getAgentForConfig (已有逻辑)
if (agent.backend === 'gemini' && !agent.cliPath) {
  return this.agents.get('aionui');
}

// getDetectionTarget (新增逻辑,结构相同)
if (agent.backend === 'gemini' && !agent.cliPath) {
  return {
    agentInstance: this.agents.get('aionui'),
    source: 'gemini',
  };
}

问题说明:两个私有方法共享相同的核心判断逻辑,未来若判断条件变化需同时修改两处。不阻塞合并,可作为后续优化。

建议

private getDetectionTarget(agent: { backend: AcpBackend; cliPath?: string }): {
  agentInstance: IMcpProtocol | undefined;
  source: McpSource;
} {
  const agentInstance = this.getAgentForConfig(agent);
  const source: McpSource = agent.backend === 'gemini' && !agent.cliPath
    ? 'gemini'
    : agent.backend as McpSource;
  return { agentInstance, source };
}

🔵 LOW — imageGenerationModelListmap 步骤使用 Object.assign 替代 spread

文件src/renderer/components/settings/SettingsModal/contents/ToolsModalContent.tsx,第 363–366 行

问题代码

return Object.assign({}, v, { model: filteredModels });

问题说明:项目其他地方统一使用 spread 语法,此处使用 Object.assign 是风格偏差,无功能差异。


汇总

# 严重级别 文件 问题
1 🟡 MEDIUM ToolsModalContent.tsx:394 clearImageGenerationAgentStatus 在 state updater 内调用 ConfigStorage.set 副作用
2 🔵 LOW McpService.ts:151 getDetectionTargetgetAgentForConfig 重复 fork-Gemini 判断逻辑
3 🔵 LOW ToolsModalContent.tsx:364 Object.assign 替代 spread,风格不一致

结论

⚠️ 有条件批准 — MEDIUM 问题(state updater 内有副作用)建议修复后合并,两个 LOW 问题不阻塞,可作为后续优化跟进。


本报告由本地 pr-review skill 生成,包含完整项目上下文,无截断限制。

@piorpua piorpua merged commit 78894a7 into iOfficeAI:main Mar 20, 2026
14 checks passed
piorpua pushed a commit that referenced this pull request Mar 20, 2026
- Fix clearImageGenerationAgentStatus calling ConfigStorage.set inside
  React state updater, causing potential double invocation in Strict Mode;
  move side effect outside the updater and pass direct value to setter
- Refactor getDetectionTarget to reuse getAgentForConfig, eliminating
  duplicated fork-Gemini detection logic

Review follow-up for #1505
IceyLiu added a commit that referenced this pull request Mar 20, 2026
…ew-followup

fix(image-generation-mcp): address review issues from PR #1505
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants