aboutsummaryrefslogtreecommitdiff
path: root/src/tools.ts
diff options
context:
space:
mode:
authoramankumarsingh77 <amankumarsingh7702@gmal.com>2026-05-02 16:05:09 +0530
committeramankumarsingh77 <amankumarsingh7702@gmal.com>2026-05-02 16:05:09 +0530
commit0f962ef99b82207239e5dacb399be3cabce0ece3 (patch)
treeeb45efdf8821dc882a6c578fe6e767af24cc5266 /src/tools.ts
parent6a4bfa31a925af67c026cd68700fe7779fd7c4cb (diff)
feat(domains): migrate browser_click to defineBrowserTool — vertical slice
Implements Task 9: adds src/domains/click.ts with the new architecture, updates registry.ts to register clickTool, removes the legacy browser_click block from tools.ts, and wires BrowserClient alongside BrowserDaemon in index.ts so both systems coexist during migration. Also fixes AnyBrowserToolDefinition variance: uses never-arg renderCall in the erased type and a boundary cast in registerBrowserTool so concrete tool definitions (with specific Static<S> args) are assignable to the registry array without widening.
Diffstat (limited to 'src/tools.ts')
-rw-r--r--src/tools.ts77
1 files changed, 0 insertions, 77 deletions
diff --git a/src/tools.ts b/src/tools.ts
index 3ea0b54..134531c 100644
--- a/src/tools.ts
+++ b/src/tools.ts
@@ -319,83 +319,6 @@ export function registerTools(pi: ExtensionAPI, daemon: BrowserDaemon): void {
});
// ═══════════════════════════════════════════════════════════════════════════
- // browser_click
- // ═══════════════════════════════════════════════════════════════════════════
- pi.registerTool({
- name: "browser_click",
- label: "Browser Click",
- description:
- "Click at viewport CSS-pixel coordinates. Compositor-level click works through iframes, shadow DOM, and cross-origin content. Use browser_screenshot first to find coordinates.",
- promptSnippet: "Click at pixel coordinates (x, y) on the page",
- promptGuidelines: [
- "Use browser_click for all clicks. Coordinates are viewport CSS pixels (not device pixels).",
- "Capture a browser_screenshot BEFORE clicking to find the right coordinates.",
- "Capture another browser_screenshot AFTER clicking to verify the action worked.",
- "Compositor-level clicks pass through iframes, shadow DOM, and cross-origin content — no selector needed.",
- "If a click doesn't register, try setting BH_DEBUG_CLICKS=1 to get annotated screenshots showing exact click positions.",
- "For React/Vue components that don't respond to clicks, try browser_dispatch_key to send DOM-level events.",
- ],
- parameters: Type.Object({
- x: Type.Number({ description: "X coordinate in CSS pixels from left edge of viewport" }),
- y: Type.Number({ description: "Y coordinate in CSS pixels from top edge of viewport" }),
- button: Type.Optional(Type.String({ description: 'Mouse button: "left", "right", or "middle". Default: "left"' })),
- clicks: Type.Optional(Type.Number({ description: "Number of clicks (1 = single, 2 = double). Default: 1" })),
- }),
- async execute(_id, params) {
- try {
- await daemon.ensureAlive();
- await daemon.cdp("Input.dispatchMouseEvent", {
- type: "mousePressed",
- x: params.x,
- y: params.y,
- button: params.button || "left",
- clickCount: params.clicks || 1,
- });
- await daemon.cdp("Input.dispatchMouseEvent", {
- type: "mouseReleased",
- x: params.x,
- y: params.y,
- button: params.button || "left",
- clickCount: params.clicks || 1,
- });
-
- // Debug click overlay (when BH_DEBUG_CLICKS is set)
- if (process.env.BH_DEBUG_CLICKS) {
- try {
- const debugPath = nextScreenshotPath();
- await daemon.captureScreenshotWithDebugOverlay(
- debugPath,
- params.x,
- params.y,
- );
- return {
- content: [{
- type: "text" as const,
- text: `Clicked at (${params.x}, ${params.y})\n[DEBUG] Overlay screenshot: ${debugPath}`,
- }],
- details: { debugScreenshotPath: debugPath },
- };
- } catch {
- // Overlay failed — still report the click
- }
- }
-
- return { content: [{ type: "text" as const, text: `Clicked at (${params.x}, ${params.y})` }], details: undefined };
- } catch (err) {
- return {
- isError: true,
- content: [{ type: "text" as const, text: `Click failed: ${err instanceof Error ? err.message : String(err)}` }],
- details: undefined,
- };
- }
- },
- renderCall(args, theme) {
- const { x, y } = args as { x: number; y: number };
- return new Text(`🖱️ Click at (${x}, ${y})`, 0, 0);
- },
- });
-
- // ═══════════════════════════════════════════════════════════════════════════
// browser_type
// ═══════════════════════════════════════════════════════════════════════════
pi.registerTool({