@amaster.ai/pi-browser-use 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,68 @@
1
+ // Extra hints appended to upstream tool descriptions.
2
+ // These steer the LLM toward correct usage (e.g. "call take_snapshot first").
3
+ const DESCRIPTION_HINTS = {
4
+ fill_form: ' Fills multiple standard HTML form fields at once. Same limitations as fill — does not work on canvas/custom widgets.',
5
+ fill: ' Fills standard HTML form fields (<input>, <textarea>, <select>) by uid. Does NOT work on custom/canvas-based widgets (e.g., Google Sheets cells, Notion blocks). If fill times out or fails, click the element first then use press_key with individual characters instead.',
6
+ click_at: ' Clicks at exact pixel coordinates (x, y). Use when you have specific coordinates for visual elements.',
7
+ click: ' Use the element uid from the accessibility tree snapshot (e.g., uid="87_4"). UIDs are invalidated after this action — call take_snapshot before using another uid.',
8
+ hover: ' Use the element uid from the accessibility tree snapshot to hover over elements.',
9
+ take_snapshot: ' Returns the accessibility tree with uid values for each element. Call this FIRST to see available elements, and AFTER every state-changing action (click, fill, press_key) before using any uid.',
10
+ navigate_page: ' Navigate to the specified URL. Call take_snapshot after to see the new page.',
11
+ new_page: ' Opens a new page/tab with the specified URL. Call take_snapshot after to see the new page.',
12
+ press_key: ' Press a SINGLE keyboard key (e.g., "Enter", "Tab", "Escape", "ArrowDown", "a", "8"). ONLY accepts one key name — do NOT pass multi-character strings like "Hello" or "A1\\nEnter". To type text, use type_text instead of calling press_key for each character.',
13
+ };
14
+ /** Append usage hints to tool descriptions based on tool name keywords. */
15
+ export function augmentToolDescription(toolName, description) {
16
+ for (const [key, hint] of Object.entries(DESCRIPTION_HINTS)) {
17
+ if (toolName.toLowerCase().includes(key)) {
18
+ return description + hint;
19
+ }
20
+ }
21
+ return description;
22
+ }
23
+ const OVERLAY_PATTERNS = [
24
+ 'not interactable',
25
+ 'obscured',
26
+ 'intercept',
27
+ 'blocked',
28
+ 'element is not visible',
29
+ 'element not found',
30
+ ];
31
+ /**
32
+ * Post-process tool output before returning to the LLM:
33
+ * - Strip embedded page snapshots (token bloat) from non-snapshot tools
34
+ * - Detect overlay/interactable issues on click actions
35
+ * - Detect stale element references
36
+ */
37
+ export function postProcessToolResult(toolName, result) {
38
+ let processed = result;
39
+ // Strip embedded snapshots to prevent token bloat (except take_snapshot)
40
+ if (toolName !== 'take_snapshot' && processed.includes('## Latest page snapshot')) {
41
+ const parts = processed.split('## Latest page snapshot');
42
+ processed = parts[0].trim();
43
+ }
44
+ // Detect overlay/interactable issues on click actions
45
+ if (toolName === 'click' || toolName.includes('click')) {
46
+ const isOverlayIssue = OVERLAY_PATTERNS.some((pattern) => processed.toLowerCase().includes(pattern));
47
+ if (isOverlayIssue) {
48
+ processed +=
49
+ '\n\nThis action may have been blocked by an overlay, popup, or tooltip. ' +
50
+ 'Look for close/dismiss buttons in the accessibility tree and click them first.';
51
+ }
52
+ }
53
+ // Detect stale element references
54
+ if (processed.toLowerCase().includes('stale') || processed.toLowerCase().includes('detached')) {
55
+ processed +=
56
+ '\n\nThe element reference is stale. Call take_snapshot to get fresh element uids.';
57
+ }
58
+ return processed;
59
+ }
60
+ export function extractTextContent(content) {
61
+ if (!content || !Array.isArray(content))
62
+ return '';
63
+ return content
64
+ .filter((c) => c.type === 'text' && c.text)
65
+ .map((c) => c.text)
66
+ .join('\n');
67
+ }
68
+ //# sourceMappingURL=tool-augment.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-augment.js","sourceRoot":"","sources":["../src/tool-augment.ts"],"names":[],"mappings":"AAAA,sDAAsD;AACtD,8EAA8E;AAC9E,MAAM,iBAAiB,GAA2B;IAChD,SAAS,EACP,uHAAuH;IACzH,IAAI,EAAE,8QAA8Q;IACpR,QAAQ,EACN,wGAAwG;IAC1G,KAAK,EACH,qKAAqK;IACvK,KAAK,EAAE,mFAAmF;IAC1F,aAAa,EACX,mMAAmM;IACrM,aAAa,EAAE,+EAA+E;IAC9F,QAAQ,EACN,6FAA6F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,IAAI,SAAS,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,SAAS,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;QAC9F,SAAS;YACP,mFAAmF,CAAC;IACxF,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,OAAgD;IACjF,IAAI,CAAC,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC;QAAE,OAAO,EAAE,CAAC;IACnD,OAAO,OAAO;SACX,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,MAAM,IAAI,CAAC,CAAC,IAAI,CAAC;SAC1C,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAK,CAAC;SACnB,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC"}
package/package.json ADDED
@@ -0,0 +1,71 @@
1
+ {
2
+ "name": "@amaster.ai/pi-browser-use",
3
+ "version": "0.1.0",
4
+ "description": "Pi extension for browser automation via chrome-devtools-mcp with browser_ prefixed tools",
5
+ "keywords": [
6
+ "pi-package",
7
+ "pi",
8
+ "extension",
9
+ "browser",
10
+ "automation",
11
+ "chrome-devtools",
12
+ "mcp"
13
+ ],
14
+ "license": "Apache-2.0",
15
+ "type": "module",
16
+ "sideEffects": false,
17
+ "main": "./dist/index.js",
18
+ "types": "./dist/index.d.ts",
19
+ "exports": {
20
+ ".": {
21
+ "types": "./dist/index.d.ts",
22
+ "default": "./dist/index.js"
23
+ },
24
+ "./package.json": {
25
+ "default": "./package.json"
26
+ }
27
+ },
28
+ "bin": {
29
+ "pi-browser-use": "./dist/cli.js"
30
+ },
31
+ "files": [
32
+ "dist",
33
+ "preview.png",
34
+ "README.md"
35
+ ],
36
+ "pi": {
37
+ "image": "https://raw.githubusercontent.com/TGYD-helige/pi/master/packages/pi-browser-use/preview.png",
38
+ "extensions": [
39
+ "./dist/index.js"
40
+ ]
41
+ },
42
+ "publishConfig": {
43
+ "access": "public"
44
+ },
45
+ "repository": {
46
+ "type": "git",
47
+ "url": "https://github.com/TGYD-helige/pi.git",
48
+ "directory": "packages/pi-browser-use"
49
+ },
50
+ "dependencies": {
51
+ "@modelcontextprotocol/sdk": "^1.29.0",
52
+ "@amaster.ai/pi-shared": "0.1.0"
53
+ },
54
+ "peerDependencies": {
55
+ "@earendil-works/pi-ai": ">=0.74.0",
56
+ "@earendil-works/pi-coding-agent": ">=0.74.0",
57
+ "typebox": "*"
58
+ },
59
+ "devDependencies": {
60
+ "@earendil-works/pi-ai": "0.74.0",
61
+ "@earendil-works/pi-coding-agent": "0.74.0",
62
+ "tsup": "^8.4.0",
63
+ "typebox": "*",
64
+ "vitest": "^4.0.0"
65
+ },
66
+ "scripts": {
67
+ "build": "tsup",
68
+ "typecheck": "tsc -b --pretty false",
69
+ "test": "vitest run src"
70
+ }
71
+ }
package/preview.png ADDED
Binary file