Skip to content

feat: describe tab handling in agentic tool#46

Merged
andyMrtnzP merged 3 commits into
mainfrom
feat/agentic-tab-support
Apr 29, 2026
Merged

feat: describe tab handling in agentic tool#46
andyMrtnzP merged 3 commits into
mainfrom
feat/agentic-tab-support

Conversation

@andyMrtnzP
Copy link
Copy Markdown
Contributor

@andyMrtnzP andyMrtnzP commented Apr 29, 2026

Summary by CodeRabbit

  • New Features

    • Tab management capabilities now available: enumerate, switch, create, and close tabs.
    • Snapshots can now capture non-active tabs without changing the active tab.
  • Documentation

    • Updated tool documentation with Shadow DOM deep selector guidance.
    • Added specifications for tab behavior, error codes, and snapshot usage with tab targeting.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 29, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 767a5d00-db29-45ad-a809-8bccda2e6a94

📥 Commits

Reviewing files that changed from the base of the PR and between 47449a0 and 649ebc1.

📒 Files selected for processing (2)
  • src/lib/agent-client.ts
  • src/tools/agent.ts
✅ Files skipped from review due to trivial changes (1)
  • src/lib/agent-client.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/tools/agent.ts

Walkthrough

Added tab-management capabilities to the browsing agent: new commands to list, switch, create, and close tabs; snapshot can target a non-active tab; snapshot outputs and tool documentation were updated to include tabs/activeTargetId and formatted tab summaries.

Changes

Cohort / File(s) Summary
Agent Tool Description
src/tools/agent.ts
Updated the browser tool description (TOOL_DESCRIPTION) and internal snapshot formatting to document and display tab-management behavior, snapshot tab summaries, activation defaults, auto-switch on close, and tab-related error codes.
Tab Management Command Schemas
src/tools/schemas.ts
Added command schemas: getTabs, switchTab, createTab, closeTab; registered them in AgentCommandSchema; extended snapshot params with optional targetId to inspect non-active tabs.
Client Types for Tabs
src/lib/agent-client.ts
Added exported TabInfo type and extended SnapshotResult to optionally include tabs?: TabInfo[] and `activeTargetId?: string

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant AgentTool as Agent Tool
  participant Browser as Browser Runtime
  participant Formatter as Snapshot Formatter

  Client->>AgentTool: send command (getTabs/createTab/switchTab/closeTab/snapshot{targetId})
  AgentTool->>Browser: execute corresponding tab API call
  Browser-->>AgentTool: return result / SnapshotResult (with tabs, activeTargetId)
  AgentTool->>Formatter: formatSnapshot (include tabs summary if multiple tabs)
  Formatter-->>Client: formatted snapshot / command response
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • browserless/enterprise#1520: Implements overlapping agent tab-management methods and snapshot targetId behavior referenced by these schema and type changes.
  • feat: agentic browsing #16: Introduced the agentic browsing tool foundation that these tab-management updates extend.

Suggested reviewers

  • ashwinsingh2007

Poem

🐰
Tabs hop open, close, and gleam,
I nudge them softly—what a dream!
Snapshots peek where I request,
Quiet rabbit, tidy nest. 🥕

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding tab handling documentation and API to the agentic tool.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Warning

Review ran into problems

🔥 Problems

These MCP integrations need to be re-authenticated in the Integrations settings: Linear


Review rate limit: 3/5 reviews remaining, refill in 15 minutes and 21 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a 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

🧹 Nitpick comments (1)
src/tools/schemas.ts (1)

204-210: Tighten targetId validation to reject empty values early.

At Line 204, Line 224, and Line 258, z.string() allows "", which will pass schema validation and fail later at runtime. Enforcing non-empty strings improves error locality.

Suggested schema hardening
 targetId: z
-  .string()
+  .string()
+  .min(1, 'targetId cannot be empty')
   .optional()
 targetId: z
-  .string()
+  .string()
+  .min(1, 'targetId cannot be empty')
   .describe('The targetId of the tab to make active (from getTabs).'),
- targetId: z.string().describe('The targetId of the tab to close.'),
+ targetId: z
+   .string()
+   .min(1, 'targetId cannot be empty')
+   .describe('The targetId of the tab to close.'),

Also applies to: 224-226, 258-258

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/tools/schemas.ts` around lines 204 - 210, Replace permissive z.string()
for the targetId fields with a non-empty string validator so empty "" values
fail validation early; e.g., change instances like
z.string().optional().describe(...) to
z.string().nonempty().optional().describe(...) (apply this to the targetId
schemas in this file, including the other two occurrences that currently use
z.string().optional()).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/tools/agent.ts`:
- Line 79: The deep-selector example in src/tools/agent.ts contains a duplicated
token: change the example `button button "Deny" deep-ref=< button#deny` to
remove the extra `button` so it reads `button "Deny" deep-ref=< button#deny`,
and ensure the associated selector example remains `"< button#deny"` to keep the
example consistent.
- Around line 134-137: The snapshot metadata (tabs and activeTargetId) is
documented but not included in agent output; update the snapshot renderer
(function formatSnapshot and its SnapshotResult handling) to include
snapshot.tabs and snapshot.activeTargetId in the returned formatted text (show
Active tab and a Tabs list with targetId, active flag, title and url) so agents
can choose tabs without calling getTabs every time, or alternatively change the
docs to require getTabs by removing the claims about snapshots always including
tabs—implement the former by adding checks for snapshot.tabs and
snapshot.activeTargetId inside formatSnapshot and appending the tab metadata
lines before rendering elements.

---

Nitpick comments:
In `@src/tools/schemas.ts`:
- Around line 204-210: Replace permissive z.string() for the targetId fields
with a non-empty string validator so empty "" values fail validation early;
e.g., change instances like z.string().optional().describe(...) to
z.string().nonempty().optional().describe(...) (apply this to the targetId
schemas in this file, including the other two occurrences that currently use
z.string().optional()).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 17976a97-176f-4d8b-bb6a-9c6ca966ab53

📥 Commits

Reviewing files that changed from the base of the PR and between 75cf1dd and 47449a0.

📒 Files selected for processing (2)
  • src/tools/agent.ts
  • src/tools/schemas.ts

Comment thread src/tools/agent.ts
Comment thread src/tools/agent.ts
@andyMrtnzP andyMrtnzP merged commit f5009a3 into main Apr 29, 2026
2 checks passed
@andyMrtnzP andyMrtnzP deleted the feat/agentic-tab-support branch April 29, 2026 17:52
This was referenced Apr 30, 2026
andyMrtnzP added a commit that referenced this pull request May 20, 2026
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **New Features**
* Tab management capabilities now available: enumerate, switch, create,
and close tabs.
* Snapshots can now capture non-active tabs without changing the active
tab.

* **Documentation**
  * Updated tool documentation with Shadow DOM deep selector guidance.
* Added specifications for tab behavior, error codes, and snapshot usage
with tab targeting.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
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.

1 participant