-
Notifications
You must be signed in to change notification settings - Fork 616
chore: yo browser less context #1284
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…nd to offload whitelist
…ailable in agent mode
- Add enum-based validation for cdp_send method (11 common CDP methods) - Add detailed union schemas for each method's parameters with examples - Add normalizeCdpParams method to handle both object and JSON string inputs - Prevent method typos and provide better type safety for CDP interactions
📝 WalkthroughWalkthroughReplaces legacy browser tool modules and BrowserToolManager with a YoBrowser CDP-centered handler and definitions, updates agent routing to use Changes
Sequence Diagram(s)sequenceDiagram
participant Agent as Agent
participant ATM as AgentToolManager
participant PT as YoBrowserPresenter
participant YTH as YoBrowserToolHandler
participant BT as BrowserTab
participant CDP as CDP Session
Agent->>ATM: callTool('yo_browser_cdp_send', args)
ATM->>PT: forward to presenter.toolHandler.callTool
PT->>YTH: callTool(toolName, args)
YTH->>PT: request browser tab (getBrowserTab)
PT->>BT: fetch BrowserTab
YTH->>BT: sendCdpCommand(method, params)
BT->>CDP: ensureSession() / sendCommand(method, params)
CDP-->>BT: result
BT-->>YTH: command result
YTH->>YTH: format JSON result
YTH-->>PT: return string result
PT-->>ATM: return tool result
ATM-->>Agent: return content
Estimated Code Review Effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In `@docs/specs/yobrowser-optimization/tasks.md`:
- Line 5: Fix the duplicated word in the task title by replacing the string
"调整调整 Browser Tabs 分区显示条件" with "调整 Browser Tabs 分区显示条件" in the tasks.md
content; search for the exact duplicated-title text and update it to the single
"调整" form so the task heading reads correctly.
In `@src/main/presenter/browser/YoBrowserToolHandler.ts`:
- Around line 91-105: Ensure CDP calls don't silently run on the wrong tab by
validating that the tab returned by presenter.getBrowserTab matches the
requested tabId: in handleCdpSend, after obtaining browserTab from
presenter.getBrowserTab(tabId), if a tabId was provided and browserTab is truthy
but its identifier (e.g., browserTab.id or browserTab.tabId) does not equal the
requested tabId, throw an error like `Tab ${tabId} not found` instead of
proceeding; keep the existing fallback behavior only when tabId is undefined.
🧹 Nitpick comments (3)
src/shared/types/presenters/legacy.presenters.d.ts (1)
224-227: Consider using a stricter return type forgetToolDefinitions().The
toolHandler.getToolDefinitions()returnsany[], which loses type safety. SinceMCPToolDefinitionis already imported and used elsewhere in this file, consider using it for consistency:readonly toolHandler: { - getToolDefinitions(): any[] + getToolDefinitions(): MCPToolDefinition[] callTool(toolName: string, args: Record<string, unknown>): Promise<string> }Also note that the previous interface method was async (
Promise<MCPToolDefinition[]>), while this is now synchronous. Ensure all callers have been updated accordingly.src/main/presenter/browser/YoBrowserToolDefinitions.ts (1)
127-215: Consider extracting the repeated server metadata.The server object is identical across all 5 tool definitions. Consider extracting it to reduce duplication:
♻️ Optional refactor
+const YOBROWSER_SERVER_INFO = { + name: 'yobrowser', + icons: '🌐', + description: 'YoBrowser CDP automation' +} as const + export function getYoBrowserToolDefinitions(): MCPToolDefinition[] { return [ { type: 'function', function: { name: 'yo_browser_tab_list', // ... }, - server: { - name: 'yobrowser', - icons: '🌐', - description: 'YoBrowser CDP automation' - } + server: YOBROWSER_SERVER_INFO }, // ... same for other tools ] }src/main/presenter/agentPresenter/acp/agentToolManager.ts (1)
275-284: Minor: Comment numbering is inconsistent.The comment at Line 275 says "1. FileSystem tools" but the next numbered section jumps to "3. Skill tools" at Line 281. Section "2." appears to be missing (or was removed without updating the numbering).
♻️ Suggested fix
- // 1. FileSystem tools (agent mode only) + // FileSystem tools (agent mode only) if (isAgentMode && this.fileSystemHandler) { const fsDefs = this.getFileSystemToolDefinitions() defs.push(...fsDefs) } - // 3. Skill tools (agent mode only) + // Skill tools (agent mode only) if (isAgentMode && this.isSkillsEnabled()) {Or renumber all sections sequentially.
Summary by CodeRabbit
New Features
Refactor
Removed
Tests
✏️ Tip: You can customize this high-level summary in your review settings.