btcp-browser-agent 0.1.6 → 0.1.7

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.
package/package.json CHANGED
@@ -1,69 +1,69 @@
1
- {
2
- "name": "btcp-browser-agent",
3
- "version": "0.1.6",
4
- "description": "Give AI agents the power to control browsers. A foundation for building agentic systems with smart DOM snapshots and stable element references.",
5
- "type": "module",
6
- "main": "dist/index.js",
7
- "types": "dist/index.d.ts",
8
- "exports": {
9
- ".": {
10
- "types": "./dist/index.d.ts",
11
- "import": "./dist/index.js",
12
- "default": "./dist/index.js"
13
- },
14
- "./core": {
15
- "types": "./packages/core/dist/index.d.ts",
16
- "import": "./packages/core/dist/index.js",
17
- "default": "./packages/core/dist/index.js"
18
- },
19
- "./extension": {
20
- "types": "./packages/extension/dist/index.d.ts",
21
- "import": "./packages/extension/dist/index.js",
22
- "default": "./packages/extension/dist/index.js"
23
- },
24
- "./extension/content": {
25
- "types": "./packages/extension/dist/content.d.ts",
26
- "import": "./packages/extension/dist/content.js",
27
- "default": "./packages/extension/dist/content.js"
28
- },
29
- "./extension/background": {
30
- "types": "./packages/extension/dist/background.d.ts",
31
- "import": "./packages/extension/dist/background.js",
32
- "default": "./packages/extension/dist/background.js"
33
- }
34
- },
35
- "scripts": {
36
- "build": "npm run build:packages && tsc -p tsconfig.build.json",
37
- "build:packages": "tsc -p packages/core/tsconfig.json && tsc -p packages/extension/tsconfig.json && tsc -p packages/cli/tsconfig.json",
38
- "clean": "rm -rf dist packages/*/dist",
39
- "prepare": "npm run build",
40
- "test": "vitest run",
41
- "test:watch": "vitest",
42
- "typecheck": "tsc --noEmit"
43
- },
44
- "workspaces": [
45
- "packages/core",
46
- "packages/extension",
47
- "packages/cli"
48
- ],
49
- "files": [
50
- "dist",
51
- "packages/core/dist",
52
- "packages/extension/dist",
53
- "!**/__tests__",
54
- "!**/*.map"
55
- ],
56
- "license": "Apache-2.0",
57
- "repository": {
58
- "type": "git",
59
- "url": "git+https://github.com/browser-tool-calling-protocol/btcp-browser-agent.git"
60
- },
61
- "dependencies": {},
62
- "devDependencies": {
63
- "@types/chrome": "^0.0.268",
64
- "@types/node": "^20.10.0",
65
- "jsdom": "^24.0.0",
66
- "typescript": "^5.3.0",
67
- "vitest": "^2.0.0"
68
- }
69
- }
1
+ {
2
+ "name": "btcp-browser-agent",
3
+ "version": "0.1.7",
4
+ "description": "Give AI agents the power to control browsers. A foundation for building agentic systems with smart DOM snapshots and stable element references.",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js",
12
+ "default": "./dist/index.js"
13
+ },
14
+ "./core": {
15
+ "types": "./packages/core/dist/index.d.ts",
16
+ "import": "./packages/core/dist/index.js",
17
+ "default": "./packages/core/dist/index.js"
18
+ },
19
+ "./extension": {
20
+ "types": "./packages/extension/dist/index.d.ts",
21
+ "import": "./packages/extension/dist/index.js",
22
+ "default": "./packages/extension/dist/index.js"
23
+ },
24
+ "./extension/content": {
25
+ "types": "./packages/extension/dist/content.d.ts",
26
+ "import": "./packages/extension/dist/content.js",
27
+ "default": "./packages/extension/dist/content.js"
28
+ },
29
+ "./extension/background": {
30
+ "types": "./packages/extension/dist/background.d.ts",
31
+ "import": "./packages/extension/dist/background.js",
32
+ "default": "./packages/extension/dist/background.js"
33
+ }
34
+ },
35
+ "scripts": {
36
+ "build": "npm run build:packages && tsc -p tsconfig.build.json",
37
+ "build:packages": "tsc -p packages/core/tsconfig.json && tsc -p packages/extension/tsconfig.json && tsc -p packages/cli/tsconfig.json",
38
+ "clean": "rm -rf dist packages/*/dist",
39
+ "prepare": "npm run build",
40
+ "test": "vitest run",
41
+ "test:watch": "vitest",
42
+ "typecheck": "tsc --noEmit"
43
+ },
44
+ "workspaces": [
45
+ "packages/core",
46
+ "packages/extension",
47
+ "packages/cli"
48
+ ],
49
+ "files": [
50
+ "dist",
51
+ "packages/core/dist",
52
+ "packages/extension/dist",
53
+ "!**/__tests__",
54
+ "!**/*.map"
55
+ ],
56
+ "license": "Apache-2.0",
57
+ "repository": {
58
+ "type": "git",
59
+ "url": "git+https://github.com/browser-tool-calling-protocol/btcp-browser-agent.git"
60
+ },
61
+ "dependencies": {},
62
+ "devDependencies": {
63
+ "@types/chrome": "^0.0.268",
64
+ "@types/node": "^20.10.0",
65
+ "jsdom": "^24.0.0",
66
+ "typescript": "^5.3.0",
67
+ "vitest": "^2.0.0"
68
+ }
69
+ }
@@ -102,11 +102,13 @@ export class DOMActions {
102
102
  selector: command.selector,
103
103
  maxDepth: command.maxDepth,
104
104
  includeHidden: command.includeHidden,
105
- interactive: command.interactive,
106
105
  compact: command.compact,
107
- all: command.all,
106
+ mode: command.mode,
108
107
  format: command.format,
109
108
  grep: command.grep,
109
+ maxLength: command.maxLength,
110
+ includeLinks: command.includeLinks,
111
+ includeImages: command.includeImages,
110
112
  });
111
113
  case 'querySelector':
112
114
  return this.querySelector(command.selector);
@@ -494,11 +496,13 @@ export class DOMActions {
494
496
  root,
495
497
  maxDepth: options.maxDepth,
496
498
  includeHidden: options.includeHidden,
497
- interactive: options.interactive,
498
499
  compact: options.compact,
499
- all: options.all,
500
+ mode: options.mode,
500
501
  format: options.format,
501
502
  grep: options.grep,
503
+ maxLength: options.maxLength,
504
+ includeLinks: options.includeLinks,
505
+ includeImages: options.includeImages,
502
506
  });
503
507
  // Store snapshot data for highlight command (preserve refs internally)
504
508
  this.lastSnapshotData = snapshotData;
@@ -761,15 +765,15 @@ export class DOMActions {
761
765
  // Create overlay container with absolute positioning covering entire document
762
766
  this.overlayContainer = this.document.createElement('div');
763
767
  this.overlayContainer.id = 'btcp-highlight-overlay';
764
- this.overlayContainer.style.cssText = `
765
- position: absolute;
766
- top: 0;
767
- left: 0;
768
- width: ${this.document.documentElement.scrollWidth}px;
769
- height: ${this.document.documentElement.scrollHeight}px;
770
- pointer-events: none;
771
- z-index: 999999;
772
- contain: layout style paint;
768
+ this.overlayContainer.style.cssText = `
769
+ position: absolute;
770
+ top: 0;
771
+ left: 0;
772
+ width: ${this.document.documentElement.scrollWidth}px;
773
+ height: ${this.document.documentElement.scrollHeight}px;
774
+ pointer-events: none;
775
+ z-index: 999999;
776
+ contain: layout style paint;
773
777
  `;
774
778
  let highlightedCount = 0;
775
779
  // Create border overlays and labels for each ref
@@ -790,17 +794,17 @@ export class DOMActions {
790
794
  const border = this.document.createElement('div');
791
795
  border.className = 'btcp-ref-border';
792
796
  border.dataset.ref = ref;
793
- border.style.cssText = `
794
- position: absolute;
795
- width: ${bbox.width}px;
796
- height: ${bbox.height}px;
797
- transform: translate3d(${bbox.left + this.window.scrollX}px, ${bbox.top + this.window.scrollY}px, 0);
798
- border: 2px solid rgba(59, 130, 246, 0.8);
799
- border-radius: 2px;
800
- box-shadow: 0 0 0 1px rgba(59, 130, 246, 0.2);
801
- pointer-events: none;
802
- will-change: transform;
803
- contain: layout style paint;
797
+ border.style.cssText = `
798
+ position: absolute;
799
+ width: ${bbox.width}px;
800
+ height: ${bbox.height}px;
801
+ transform: translate3d(${bbox.left + this.window.scrollX}px, ${bbox.top + this.window.scrollY}px, 0);
802
+ border: 2px solid rgba(59, 130, 246, 0.8);
803
+ border-radius: 2px;
804
+ box-shadow: 0 0 0 1px rgba(59, 130, 246, 0.2);
805
+ pointer-events: none;
806
+ will-change: transform;
807
+ contain: layout style paint;
804
808
  `;
805
809
  // Create label
806
810
  const label = this.document.createElement('div');
@@ -808,21 +812,21 @@ export class DOMActions {
808
812
  label.dataset.ref = ref;
809
813
  // Extract number from ref (e.g., "@ref:5" -> "5")
810
814
  label.textContent = ref.replace('@ref:', '');
811
- label.style.cssText = `
812
- position: absolute;
813
- transform: translate3d(${bbox.left + this.window.scrollX}px, ${bbox.top + this.window.scrollY}px, 0);
814
- background: rgba(59, 130, 246, 0.9);
815
- color: white;
816
- padding: 2px 6px;
817
- border-radius: 3px;
818
- font-family: monospace;
819
- font-size: 11px;
820
- font-weight: bold;
821
- box-shadow: 0 2px 4px rgba(0,0,0,0.3);
822
- pointer-events: none;
823
- white-space: nowrap;
824
- will-change: transform;
825
- contain: layout style paint;
815
+ label.style.cssText = `
816
+ position: absolute;
817
+ transform: translate3d(${bbox.left + this.window.scrollX}px, ${bbox.top + this.window.scrollY}px, 0);
818
+ background: rgba(59, 130, 246, 0.9);
819
+ color: white;
820
+ padding: 2px 6px;
821
+ border-radius: 3px;
822
+ font-family: monospace;
823
+ font-size: 11px;
824
+ font-weight: bold;
825
+ box-shadow: 0 2px 4px rgba(0,0,0,0.3);
826
+ pointer-events: none;
827
+ white-space: nowrap;
828
+ will-change: transform;
829
+ contain: layout style paint;
826
830
  `;
827
831
  this.overlayContainer.appendChild(border);
828
832
  this.overlayContainer.appendChild(label);
@@ -3,8 +3,13 @@
3
3
  *
4
4
  * Generates a flat accessibility snapshot of the DOM.
5
5
  * Produces a compact, AI-friendly list of interactive elements.
6
+ *
7
+ * Supports three modes:
8
+ * - 'interactive': Find clickable elements (default)
9
+ * - 'outline': Understand page structure with xpaths + metadata
10
+ * - 'content': Extract text content from sections
6
11
  */
7
- import type { SnapshotData, RefMap } from './types.js';
12
+ import type { SnapshotData, RefMap, SnapshotMode, SnapshotFormat } from './types.js';
8
13
  /**
9
14
  * Grep options (mirrors Unix grep flags)
10
15
  */
@@ -22,15 +27,37 @@ interface SnapshotOptions {
22
27
  root?: Element;
23
28
  maxDepth?: number;
24
29
  includeHidden?: boolean;
25
- interactive?: boolean;
26
30
  compact?: boolean;
27
- all?: boolean;
28
- format?: 'tree' | 'html';
31
+ /**
32
+ * Snapshot mode:
33
+ * - 'interactive': Find clickable elements (default)
34
+ * - 'outline': Understand page structure with xpaths + metadata
35
+ * - 'content': Extract text content from sections
36
+ */
37
+ mode?: SnapshotMode;
38
+ /**
39
+ * Output format:
40
+ * - 'tree': Flat accessibility tree (default)
41
+ * - 'html': Raw HTML
42
+ * - 'markdown': Markdown formatted content
43
+ */
44
+ format?: SnapshotFormat;
29
45
  /** Grep filter - string pattern or options object */
30
46
  grep?: string | GrepOptions;
47
+ /** Max chars per section in content mode */
48
+ maxLength?: number;
49
+ /** Include links as [text](url) in markdown format */
50
+ includeLinks?: boolean;
51
+ /** Include images as ![alt](src) in markdown format */
52
+ includeImages?: boolean;
31
53
  }
32
54
  /**
33
55
  * Generate flat snapshot of the DOM
56
+ *
57
+ * Supports three modes:
58
+ * - 'interactive' (default): Find clickable elements with @ref markers
59
+ * - 'outline': Structural overview with xpaths and metadata
60
+ * - 'content': Extract text content from sections
34
61
  */
35
62
  export declare function createSnapshot(document: Document, refMap: RefMap, options?: SnapshotOptions): SnapshotData;
36
63
  export {};