From bfba73fa2f1373abd8a5a704c9c833d6fce1b44f Mon Sep 17 00:00:00 2001 From: amankumarsingh77 Date: Tue, 28 Jul 2026 00:17:13 +0530 Subject: refactor(domains): share target resolution and CDP error mapping The ref-vs-x/y branch turned out to exist in one tool, not four; it is now one helper with tests covering the half-specified-coordinate and stale-ref cases. cdpCall folds the repeated cdp_error mapping at 24 active-session call sites; target-scoped callOnTarget/callBrowser sites are left alone. Co-Authored-By: Claude Opus 5 (1M context) --- src/domains/drag.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/domains/drag.ts') diff --git a/src/domains/drag.ts b/src/domains/drag.ts index 9ad2ada..49a5a58 100644 --- a/src/domains/drag.ts +++ b/src/domains/drag.ts @@ -1,6 +1,7 @@ import { Type } from "typebox"; -import { type Result, err, ok } from "../util/result"; +import { type Result, ok } from "../util/result"; import { defineBrowserTool, type ToolErr, type ToolOk } from "../util/tool"; +import { cdpCall } from "./cdp-call"; const DragArgs = Type.Object({ startX: Type.Number(), @@ -35,7 +36,6 @@ export const dragAndDropTool = defineBrowserTool({ dragOperationsMask: 1, } : { items: [], dragOperationsMask: 1 }; - const cdp = client.session(); type InputCall = readonly ["Input.dispatchMouseEvent" | "Input.dispatchDragEvent", Record]; const calls: ReadonlyArray = [ ["Input.dispatchMouseEvent", { type: "mousePressed", x: args.startX, y: args.startY, button: "left", clickCount: 1 }], @@ -58,8 +58,8 @@ export const dragAndDropTool = defineBrowserTool({ ["Input.dispatchMouseEvent", { type: "mouseReleased", x: args.endX, y: args.endY, button: "left", clickCount: 1 }], ]; for (const [method, params] of calls) { - const r = await cdp.call(method, params); - if (!r.success) return err({ kind: "cdp_error", message: r.error.message }); + const r = await cdpCall(client, method, params); + if (!r.success) return r; } return ok({ text: `Dragged from (${args.startX},${args.startY}) to (${args.endX},${args.endY})`, -- cgit v1.2.3