/** * Browser Intent MCP Tools — ADR-175 page-agent integration. * * Adds a natural-language INTENT layer on top of the low-level selector-based * `browser_*` tools (browser-tools.ts, driven by the `agent-browser` CLI). * `browser_act({ task })` lets a caller say "Click the login button" instead * of chaining browser_snapshot + browser_click. * * Backing library: `page-agent` (npm, MIT, https://github.com/alibaba/page-agent) * — in-page injected JS that turns the DOM into text and lets an LLM execute * natural-language intents via `agent.execute('Click login')`. * * ============================================================================ * VERIFIED API (recorded 2026-07-04 against page-agent@1.11.0 — `npm view * page-agent`, the published README, and the actual npm tarball contents). * Deviations from the original integration brief are called out inline. * ============================================================================ * * - Package layout changed since the brief was written: `page-agent` is now a * thin composition of `@page-agent/core` + `@page-agent/llms` + * `@page-agent/page-controller` + `@page-agent/ui`. The npm package is * ESM-only (`"type":"module"`) and ships two builds: * - `dist/esm/page-agent.js` — the Node/bundler ESM entry. * - `dist/iife/page-agent.demo.js` — a self-contained browser IIFE that * sets `window.PageAgent = ` (this is what we inject). * * - DEVIATION #1 (load-bearing): `await import('page-agent')` is NOT a safe * availability probe in Node. Empirically, importing the ESM entry throws * `ReferenceError: window is not defined` — even when the package IS * correctly installed — because `@page-agent/core`'s module graph touches * DOM globals at import time (it's designed to run in a browser, not Node). * This differs from the agenticow-loader.ts pattern used elsewhere in this * repo (dynamic `import()` + catch `ERR_MODULE_NOT_FOUND`), which only * works for pure-Node optional deps. Instead we detect availability via * `require.resolve('page-agent')` — path resolution only, never executes * module code — the same technique `browser-session-tools.ts` already uses * to resolve the local `ruvector` CLI bin without invoking it. * * - DEVIATION #2: the IIFE bundle unconditionally (also) auto-constructs a * DEMO `PageAgent` instance via `setTimeout`, pointed at Alibaba's public * sandbox endpoint (`model: 'qwen3.5-plus'`, a `page-ag-testing-*.run` * baseURL, `apiKey: 'NA'`) UNLESS the bundle is loaded via a real * `