Skip to content

Commit 41725b2

Browse files
committed
feat(pages): update interaction loop metrics and event types
- Updated event type count from 13 to 16 in quick summary - Changed max rounds display from 100 to "∞" with label change to "默认轮次" - Updated event type count in header from 14 to 16 - Removed SessionTokenLimitExceeded event type from table - Added new event types: Retry, ContextWindowWillOverflow, InvalidStream, and ModelInfo - Enhanced documentation of event handling flow in interaction loop page
1 parent a7ef92e commit 41725b2

9 files changed

Lines changed: 624 additions & 579 deletions

src/pages/GeminiChatCore.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ function Introduction({ isExpanded, onToggle }: { isExpanded: boolean; onToggle:
7171
<div className="text-xs text-[var(--text-muted)]">重试次数</div>
7272
</div>
7373
<div className="bg-[var(--bg-card)] p-3 rounded border border-[var(--border-subtle)]">
74-
<div className="text-xl font-bold text-[var(--cyber-blue)]">13</div>
74+
<div className="text-xl font-bold text-[var(--cyber-blue)]">16</div>
7575
<div className="text-xs text-[var(--text-muted)]">事件类型</div>
7676
</div>
7777
<div className="bg-[var(--bg-card)] p-3 rounded border border-[var(--border-subtle)]">

src/pages/InteractionLoop.tsx

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ function QuickSummary({ isExpanded, onToggle }: { isExpanded: boolean; onToggle:
3434
{/* 关键数字 */}
3535
<div className="grid grid-cols-2 md:grid-cols-4 gap-3">
3636
<div className="bg-[var(--bg-card)] rounded-lg p-3 text-center border border-[var(--border-subtle)]">
37-
<div className="text-2xl font-bold text-[var(--terminal-green)]">13</div>
37+
<div className="text-2xl font-bold text-[var(--terminal-green)]">16</div>
3838
<div className="text-xs text-[var(--text-muted)]">事件类型</div>
3939
</div>
4040
<div className="bg-[var(--bg-card)] rounded-lg p-3 text-center border border-[var(--border-subtle)]">
41-
<div className="text-2xl font-bold text-[var(--cyber-blue)]">100</div>
42-
<div className="text-xs text-[var(--text-muted)]">最大轮次</div>
41+
<div className="text-2xl font-bold text-[var(--cyber-blue)]"></div>
42+
<div className="text-xs text-[var(--text-muted)]">默认轮次</div>
4343
</div>
4444
<div className="bg-[var(--bg-card)] rounded-lg p-3 text-center border border-[var(--border-subtle)]">
4545
<div className="text-2xl font-bold text-[var(--purple)]">3</div>
@@ -457,7 +457,7 @@ const request = await prepareRequest(userParts, ideContextDelta);
457457
<MermaidDiagram chart={streamEventsChart} title="流事件处理流程" />
458458

459459
<div className="mt-4">
460-
<h5 className="text-[var(--text-primary)] font-semibold font-mono mb-2">14 种事件类型 (GeminiEventType)</h5>
460+
<h5 className="text-[var(--text-primary)] font-semibold font-mono mb-2">16 种事件类型 (GeminiEventType)</h5>
461461
<div className="overflow-x-auto">
462462
<table className="w-full text-sm">
463463
<thead>
@@ -513,11 +513,6 @@ const request = await prepareRequest(userParts, ideContextDelta);
513513
<td className="py-2 px-3">达到会话轮次上限</td>
514514
<td className="py-2 px-3">终止会话</td>
515515
</tr>
516-
<tr className="border-b border-[var(--border-subtle)]/50">
517-
<td className="py-2 px-3 font-mono text-red-400">SessionTokenLimitExceeded</td>
518-
<td className="py-2 px-3">超过 token 上限</td>
519-
<td className="py-2 px-3">触发压缩或终止</td>
520-
</tr>
521516
<tr className="border-b border-[var(--border-subtle)]/50">
522517
<td className="py-2 px-3 font-mono text-[var(--terminal-green)]">Finished</td>
523518
<td className="py-2 px-3">响应完成</td>
@@ -533,11 +528,26 @@ const request = await prepareRequest(userParts, ideContextDelta);
533528
<td className="py-2 px-3">引用来源</td>
534529
<td className="py-2 px-3">附加到响应</td>
535530
</tr>
536-
<tr>
531+
<tr className="border-b border-[var(--border-subtle)]/50">
537532
<td className="py-2 px-3 font-mono text-[var(--text-muted)]">Retry</td>
538533
<td className="py-2 px-3">重试请求</td>
539534
<td className="py-2 px-3">重新发送 API 请求</td>
540535
</tr>
536+
<tr className="border-b border-[var(--border-subtle)]/50">
537+
<td className="py-2 px-3 font-mono text-red-400">ContextWindowWillOverflow</td>
538+
<td className="py-2 px-3">上下文窗口即将溢出</td>
539+
<td className="py-2 px-3">触发压缩或警告</td>
540+
</tr>
541+
<tr className="border-b border-[var(--border-subtle)]/50">
542+
<td className="py-2 px-3 font-mono text-[var(--amber)]">InvalidStream</td>
543+
<td className="py-2 px-3">流式响应无效</td>
544+
<td className="py-2 px-3">重试或错误处理</td>
545+
</tr>
546+
<tr>
547+
<td className="py-2 px-3 font-mono text-[var(--cyber-blue)]">ModelInfo</td>
548+
<td className="py-2 px-3">模型信息</td>
549+
<td className="py-2 px-3">记录实际使用的模型</td>
550+
</tr>
541551
</tbody>
542552
</table>
543553
</div>

src/pages/MCPIntegration.tsx

Lines changed: 72 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ function Introduction({ isExpanded, onToggle }: { isExpanded: boolean; onToggle:
9090

9191
<div className="text-xs text-[var(--text-muted)] bg-[var(--bg-card)] px-3 py-2 rounded flex items-center gap-2">
9292
<span>📁</span>
93-
<code>packages/core/src/mcp/</code>
93+
<code>packages/core/src/tools/mcp-*.ts</code>
9494
</div>
9595
</div>
9696
)}
@@ -154,7 +154,7 @@ export function MCPIntegration() {
154154
</div>
155155

156156
<div className="bg-purple-400/20 border border-purple-400 rounded-lg px-6 py-3 w-full max-w-md text-center">
157-
<strong>MCPClientManager</strong>
157+
<strong>McpClientManager</strong>
158158
<div className="text-xs text-gray-400">管理多个 MCP 服务器连接</div>
159159
</div>
160160

@@ -178,91 +178,105 @@ export function MCPIntegration() {
178178
</div>
179179
</Layer>
180180

181-
{/* MCPClientManager */}
182-
<Layer title="MCPClientManager" icon="🔧">
181+
{/* McpClientManager */}
182+
<Layer title="McpClientManager" icon="🔧">
183183
<CodeBlock
184-
title="packages/core/src/mcp/mcp-client-manager.ts"
185-
code={`class MCPClientManager {
186-
private clients: Map<string, MCPClient> = new Map();
187-
private discoveredTools: Map<string, DiscoveredMCPTool> = new Map();
188-
189-
// 连接并发现工具
190-
async connectAndDiscover(serverConfig: MCPServerConfig) {
191-
// 1. 创建 MCP 客户端
192-
const client = new MCPClient(serverConfig);
193-
194-
// 2. 连接服务器
195-
await client.connect();
196-
197-
// 3. 发现可用工具
198-
const tools = await client.listTools();
199-
200-
// 4. 注册工具
201-
for (const tool of tools) {
202-
const wrappedTool = new DiscoveredMCPTool(tool, client);
203-
this.discoveredTools.set(tool.name, wrappedTool);
204-
}
205-
206-
this.clients.set(serverConfig.name, client);
184+
title="packages/core/src/tools/mcp-client-manager.ts"
185+
code={`// 管理多个 MCP 客户端的生命周期
186+
export class McpClientManager {
187+
private clients: Map<string, McpClient> = new Map();
188+
private readonly toolRegistry: ToolRegistry;
189+
private readonly cliConfig: Config;
190+
private discoveryState: MCPDiscoveryState = MCPDiscoveryState.NOT_STARTED;
191+
192+
constructor(
193+
toolRegistry: ToolRegistry,
194+
cliConfig: Config,
195+
eventEmitter?: EventEmitter,
196+
) { ... }
197+
198+
// 启动扩展的 MCP 服务器
199+
async startExtension(extension: GeminiCLIExtension) {
200+
await Promise.all(
201+
Object.entries(extension.mcpServers ?? {}).map(([name, config]) =>
202+
this.maybeDiscoverMcpServer(name, { ...config, extension }),
203+
),
204+
);
207205
}
208206
209-
// 获取所有发现的工具
210-
getAllDiscoveredTools(): DiscoveredMCPTool[] {
211-
return Array.from(this.discoveredTools.values());
207+
// 发现 MCP 服务器的工具
208+
async maybeDiscoverMcpServer(name: string, config: MCPServerConfig) {
209+
const client = new McpClient(name, config, ...);
210+
await client.connect();
211+
// 工具自动注册到 toolRegistry
212+
this.clients.set(name, client);
212213
}
213214
214-
// 调用工具
215-
async callTool(name: string, args: object): Promise<any> {
216-
const tool = this.discoveredTools.get(name);
217-
if (!tool) throw new Error(\`Tool not found: \${name}\`);
218-
219-
return tool.invoke(args);
215+
// 获取客户端
216+
getClient(serverName: string): McpClient | undefined {
217+
return this.clients.get(serverName);
220218
}
221219
}`}
222220
/>
221+
222+
<HighlightBox title="MCPDiscoveryState 状态" icon="📊" variant="blue">
223+
<ul className="pl-5 list-disc space-y-1 text-sm">
224+
<li><code className="text-cyan-400">NOT_STARTED</code> - 发现尚未开始</li>
225+
<li><code className="text-yellow-400">IN_PROGRESS</code> - 发现进行中</li>
226+
<li><code className="text-green-400">COMPLETED</code> - 发现已完成</li>
227+
</ul>
228+
</HighlightBox>
223229
</Layer>
224230

225231
{/* MCP 配置 */}
226232
<Layer title="MCP 服务器配置" icon="⚙️">
227233
<JsonBlock
228-
code={`// ~/.gemini/mcp/servers.json
234+
code={`// ~/.gemini/settings.json (或项目级 .gemini/settings.json)
229235
{
230-
"servers": [
231-
{
232-
"name": "filesystem",
236+
"mcpServers": {
237+
"filesystem": {
233238
"command": "npx",
234-
"args": ["-y", "@anthropic/mcp-server-filesystem"],
239+
"args": ["-y", "@modelcontextprotocol/server-filesystem"],
235240
"env": {
236241
"ALLOWED_PATHS": "/home/user/projects"
237242
}
238243
},
239-
{
240-
"name": "github",
244+
"github": {
241245
"command": "npx",
242-
"args": ["-y", "@anthropic/mcp-server-github"],
246+
"args": ["-y", "@modelcontextprotocol/server-github"],
243247
"env": {
244248
"GITHUB_TOKEN": "\${GITHUB_TOKEN}"
245249
}
246250
},
247-
{
248-
"name": "custom-api",
251+
"remote-api": {
249252
"url": "http://localhost:3000/mcp",
250-
"auth": {
251-
"type": "bearer",
252-
"token": "\${API_TOKEN}"
253-
}
253+
"type": "sse"
254254
}
255-
]
255+
}
256256
}`}
257257
/>
258258

259-
<HighlightBox title="配置选项" icon="📋" variant="green">
260-
<ul className="pl-5 list-disc space-y-1">
261-
<li><strong>command + args</strong>: 本地进程方式启动 MCP 服务器</li>
262-
<li><strong>url</strong>: HTTP/WebSocket 远程连接</li>
263-
<li><strong>env</strong>: 传递给服务器的环境变量</li>
264-
<li><strong>auth</strong>: 认证配置(bearer、basic、oauth)</li>
265-
</ul>
259+
<HighlightBox title="MCPServerConfig 配置选项" icon="📋" variant="green">
260+
<div className="grid grid-cols-1 md:grid-cols-2 gap-4 text-sm">
261+
<div>
262+
<h5 className="font-semibold text-green-400 mb-2">传输方式</h5>
263+
<ul className="space-y-1 text-gray-300">
264+
<li><code className="text-cyan-400">command + args</code>: stdio 本地进程</li>
265+
<li><code className="text-cyan-400">url + type:'sse'</code>: SSE 远程连接</li>
266+
<li><code className="text-cyan-400">url + type:'http'</code>: HTTP 流式传输</li>
267+
<li><code className="text-cyan-400">tcp</code>: WebSocket 连接</li>
268+
</ul>
269+
</div>
270+
<div>
271+
<h5 className="font-semibold text-green-400 mb-2">通用配置</h5>
272+
<ul className="space-y-1 text-gray-300">
273+
<li><code className="text-cyan-400">env</code>: 环境变量</li>
274+
<li><code className="text-cyan-400">timeout</code>: 超时时间</li>
275+
<li><code className="text-cyan-400">trust</code>: 信任模式</li>
276+
<li><code className="text-cyan-400">includeTools/excludeTools</code>: 工具过滤</li>
277+
</ul>
278+
</div>
279+
</div>
266280
</HighlightBox>
267281
</Layer>
268282

0 commit comments

Comments
 (0)