aboutsummaryrefslogtreecommitdiff
path: root/src/tools.ts
diff options
context:
space:
mode:
authoramankumarsingh77 <amankumarsingh7702@gmal.com>2026-05-02 16:20:09 +0530
committeramankumarsingh77 <amankumarsingh7702@gmal.com>2026-05-02 16:20:09 +0530
commit6708da54b1805756908dea84bf65fe73ab03426a (patch)
tree95e144b83d69af9918321f2e3faf29c5a8bfad17 /src/tools.ts
parent9ead6a0577b750bc3ae3f36a7e8bfe108e979925 (diff)
feat(domains): migrate screenshot, add typed sharp shim, restore click crosshair overlay
Diffstat (limited to 'src/tools.ts')
-rw-r--r--src/tools.ts82
1 files changed, 0 insertions, 82 deletions
diff --git a/src/tools.ts b/src/tools.ts
index be74a03..3ea9179 100644
--- a/src/tools.ts
+++ b/src/tools.ts
@@ -310,88 +310,6 @@ export function registerTools(pi: ExtensionAPI, daemon: BrowserDaemon): void {
});
// ═══════════════════════════════════════════════════════════════════════════
- // browser_screenshot
- // ═══════════════════════════════════════════════════════════════════════════
- pi.registerTool({
- name: "browser_screenshot",
- label: "Browser Screenshot",
- description:
- "Capture a PNG or JPEG screenshot of the current page. Use this BEFORE interactions to find targets, and AFTER to verify results. JPEG (quality 80) is 2-5x smaller for complex pages — faster transfer and lower LLM context cost.",
- promptSnippet: "Capture a screenshot of the current page (PNG or JPEG)",
- promptGuidelines: [
- "Use browser_screenshot as your FIRST step when exploring a page — it shows you what's visible.",
- "After every browser_click, browser_type, browser_scroll, or browser_navigate, capture a screenshot to VERIFY the action worked.",
- "Screenshots are the fastest way to find click targets, notice hidden blockers, and decide next steps.",
- "Never assume an action worked. Always re-screenshot to confirm.",
- "For HiDPI/Retina screens, use maxDim (e.g. 2000) to keep images within LLM pixel limits.",
- "Use format: 'jpeg' with quality: 80 for 2-5x smaller files on complex pages — faster transfers and lower context cost.",
- ],
- parameters: Type.Object({
- fullPage: Type.Optional(Type.Boolean({ description: "Capture the full scrollable page (not just viewport). Default: false" })),
- format: Type.Optional(Type.String({ description: "Image format: 'png' or 'jpeg'. Default: 'png'" })),
- quality: Type.Optional(Type.Number({ description: "JPEG quality 1-100. Default: 80. Ignored for PNG." })),
- maxDim: Type.Optional(Type.Number({ description: "If set, auto-resize the screenshot so neither dimension exceeds this (e.g. 2000 for LLM pixel limits). Requires sharp." })),
- }),
- async execute(_id, params) {
- try {
- await daemon.ensureAlive();
- const path = nextScreenshotPath();
- const format = (params.format === "jpeg" ? "jpeg" : "png") as "png" | "jpeg";
- const quality = typeof params.quality === "number" ? params.quality : 80;
- await daemon.captureScreenshot(path, params.fullPage === true, format, quality);
-
- // Auto-resize if maxDim is specified and sharp is available
- let resizeNote = "";
- const maxDim = typeof params.maxDim === "number" ? params.maxDim : undefined;
- if (maxDim) {
- try {
- // sharp is an optional dependency — import at runtime
- const sharp: any = await new Function("return import('sharp')")()
- .then((m: any) => m.default || m)
- .catch(() => null);
- if (!sharp) { resizeNote = " (maxDim ignored: install sharp for auto-resize)"; }
- else {
- const metadata = await sharp(path).metadata();
- const w = metadata.width || 0;
- const h = metadata.height || 0;
- if (Math.max(w, h) > maxDim) {
- await sharp(path)
- .resize(maxDim, maxDim, { fit: "inside", withoutEnlargement: true })
- .toFile(path + ".resized");
- const { rename } = await import("node:fs/promises");
- await rename(path + ".resized", path);
- resizeNote = ` (resized from ${w}x${h} to fit ${maxDim}px)`;
- }
- }
- } catch {
- // sharp not installed — skip resize
- resizeNote = " (maxDim ignored: install sharp for auto-resize)";
- }
- }
-
- const fmtLabel = format === "jpeg" ? ` (JPEG q${quality})` : "";
- return {
- content: [{ type: "text" as const, text: `Screenshot saved: ${path}${params.fullPage ? " (full page)" : ""}${fmtLabel}${resizeNote}` }],
- details: { path, format, quality },
- };
- } catch (err) {
- return {
- isError: true,
- content: [{ type: "text" as const, text: `Screenshot failed: ${err instanceof Error ? err.message : String(err)}` }],
- details: undefined,
- };
- }
- },
- renderCall(_, theme) {
- return new Text(`📸 Capturing screenshot...`, 0, 0);
- },
- renderResult(result, _options, theme) {
- const path = (result.details as { path?: string })?.path;
- return new Text(path ? `📸 Screenshot: ${path}` : `📸 Screenshot captured`, 0, 0);
- },
- });
-
- // ═══════════════════════════════════════════════════════════════════════════
// browser_list_tabs
// ═══════════════════════════════════════════════════════════════════════════
pi.registerTool({