ft-scout 9.5.5 → 9.5.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/README.md +1 -1
- package/bin/src/engine/agent/computerUseLoop.d.ts +107 -0
- package/bin/src/engine/agent/computerUseLoop.js +413 -0
- package/bin/src/engine/agent/index.d.ts +2 -0
- package/bin/src/engine/agent/index.js +2 -0
- package/bin/src/engine/agent/recovery/index.d.ts +4 -0
- package/bin/src/engine/agent/recovery/index.js +4 -0
- package/bin/src/engine/agent/recovery/loopDetector.d.ts +26 -0
- package/bin/src/engine/agent/recovery/loopDetector.js +126 -0
- package/bin/src/engine/agent/recovery/recoveryManager.d.ts +43 -0
- package/bin/src/engine/agent/recovery/recoveryManager.js +271 -0
- package/bin/src/engine/agent/recovery/types.d.ts +48 -0
- package/bin/src/engine/agent/recovery/types.js +4 -0
- package/bin/src/engine/agent/verification/index.d.ts +3 -0
- package/bin/src/engine/agent/verification/index.js +3 -0
- package/bin/src/engine/agent/verification/stateChangeVerifier.d.ts +22 -0
- package/bin/src/engine/agent/verification/stateChangeVerifier.js +282 -0
- package/bin/src/engine/agent/verification/types.d.ts +28 -0
- package/bin/src/engine/agent/verification/types.js +4 -0
- package/bin/src/engine/agentEngine.d.ts +3 -1
- package/bin/src/engine/agentEngine.js +370 -56
- package/bin/src/engine/agentState.d.ts +41 -1
- package/bin/src/engine/agentState.js +45 -0
- package/bin/src/engine/browser/actions/actionEngine.d.ts +41 -0
- package/bin/src/engine/browser/actions/actionEngine.js +707 -0
- package/bin/src/engine/browser/actions/index.d.ts +4 -0
- package/bin/src/engine/browser/actions/index.js +4 -0
- package/bin/src/engine/browser/actions/reliability.d.ts +41 -0
- package/bin/src/engine/browser/actions/reliability.js +170 -0
- package/bin/src/engine/browser/actions/types.d.ts +50 -0
- package/bin/src/engine/browser/actions/types.js +2 -0
- package/bin/src/engine/browser/browserController.d.ts +18 -0
- package/bin/src/engine/browser/browserController.js +44 -12
- package/bin/src/engine/browser/index.d.ts +2 -0
- package/bin/src/engine/browser/index.js +2 -0
- package/bin/src/engine/browser/observer/accessibilityTree.d.ts +14 -0
- package/bin/src/engine/browser/observer/accessibilityTree.js +214 -0
- package/bin/src/engine/browser/observer/browserObserver.d.ts +29 -0
- package/bin/src/engine/browser/observer/browserObserver.js +204 -0
- package/bin/src/engine/browser/observer/domExtractor.d.ts +30 -0
- package/bin/src/engine/browser/observer/domExtractor.js +407 -0
- package/bin/src/engine/browser/observer/index.d.ts +5 -0
- package/bin/src/engine/browser/observer/index.js +5 -0
- package/bin/src/engine/browser/observer/types.d.ts +163 -0
- package/bin/src/engine/browser/observer/types.js +8 -0
- package/bin/src/engine/computer/computerController.d.ts +45 -2
- package/bin/src/engine/computer/computerController.js +178 -38
- package/bin/src/engine/computer/mockComputer.d.ts +7 -2
- package/bin/src/engine/computer/mockComputer.js +59 -1
- package/bin/src/engine/computer/scoutDriver.cs +310 -63
- package/bin/src/engine/llm.js +35 -15
- package/bin/src/engine/models/harpProvider.d.ts +32 -0
- package/bin/src/engine/models/harpProvider.js +172 -0
- package/bin/src/engine/models/index.d.ts +6 -0
- package/bin/src/engine/models/index.js +6 -0
- package/bin/src/engine/models/localModelProvider.d.ts +11 -0
- package/bin/src/engine/models/localModelProvider.js +48 -0
- package/bin/src/engine/models/openaiProvider.d.ts +11 -0
- package/bin/src/engine/models/openaiProvider.js +50 -0
- package/bin/src/engine/models/reasoningOrchestrator.d.ts +17 -0
- package/bin/src/engine/models/reasoningOrchestrator.js +75 -0
- package/bin/src/engine/models/types.d.ts +63 -0
- package/bin/src/engine/models/types.js +2 -0
- package/bin/src/engine/production/index.d.ts +3 -0
- package/bin/src/engine/production/index.js +3 -0
- package/bin/src/engine/production/taskReplay.d.ts +37 -0
- package/bin/src/engine/production/taskReplay.js +81 -0
- package/bin/src/engine/production/telemetry.d.ts +43 -0
- package/bin/src/engine/production/telemetry.js +68 -0
- package/bin/src/engine/runtime/agentRuntime.d.ts +1 -1
- package/bin/src/engine/runtime/agentRuntime.js +33 -7
- package/bin/src/engine/safety/index.d.ts +3 -0
- package/bin/src/engine/safety/index.js +3 -0
- package/bin/src/engine/safety/policyEngine.d.ts +40 -0
- package/bin/src/engine/safety/policyEngine.js +282 -0
- package/bin/src/engine/safety/types.d.ts +24 -0
- package/bin/src/engine/safety/types.js +2 -0
- package/bin/src/engine/safety.d.ts +1 -0
- package/bin/src/engine/safety.js +1 -0
- package/bin/src/engine/toolRegistry.d.ts +4 -0
- package/bin/src/engine/toolRegistry.js +9 -0
- package/bin/src/engine/tools/domainHandlers.d.ts +61 -0
- package/bin/src/engine/tools/domainHandlers.js +495 -0
- package/bin/src/engine/tools/index.d.ts +4 -0
- package/bin/src/engine/tools/index.js +4 -0
- package/bin/src/engine/tools/types.d.ts +56 -0
- package/bin/src/engine/tools/types.js +2 -0
- package/bin/src/engine/tools/unifiedRouter.d.ts +29 -0
- package/bin/src/engine/tools/unifiedRouter.js +426 -0
- package/bin/src/engine/workspace/agentWorkspace.js +4 -2
- package/bin/src/index.js +4 -4
- package/bin/src/mcp/client.js +1 -1
- package/bin/src/server/server.js +57 -18
- package/bin/src/utils/branding.js +1 -1
- package/bin/src/utils/claudeUI.d.ts +10 -1
- package/bin/src/utils/claudeUI.js +136 -6
- package/bin/src/utils/qrBridge.js +1 -1
- package/bin/src/utils/support.js +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import {} from './types.js';
|
|
2
|
+
function parseAttributes(attrStr) {
|
|
3
|
+
const attrs = {};
|
|
4
|
+
const regex = /([a-zA-Z0-9_\-:@.]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+)))?/g;
|
|
5
|
+
let match;
|
|
6
|
+
while ((match = regex.exec(attrStr)) !== null) {
|
|
7
|
+
const key = match[1].toLowerCase();
|
|
8
|
+
const val = match[2] ?? match[3] ?? match[4] ?? '';
|
|
9
|
+
attrs[key] = val;
|
|
10
|
+
}
|
|
11
|
+
return attrs;
|
|
12
|
+
}
|
|
13
|
+
function cleanText(text) {
|
|
14
|
+
return text.replace(/<[^>]+>/g, ' ').replace(/\s+/g, ' ').trim();
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Maps standard HTML tag names and attributes to W3C ARIA roles.
|
|
18
|
+
*/
|
|
19
|
+
export function getImplicitAriaRole(tagName, attributes) {
|
|
20
|
+
const explicitRole = attributes['role']?.trim().toLowerCase();
|
|
21
|
+
if (explicitRole) {
|
|
22
|
+
return explicitRole;
|
|
23
|
+
}
|
|
24
|
+
const tag = tagName.toLowerCase();
|
|
25
|
+
switch (tag) {
|
|
26
|
+
case 'a':
|
|
27
|
+
case 'area':
|
|
28
|
+
return attributes['href'] ? 'link' : 'generic';
|
|
29
|
+
case 'button':
|
|
30
|
+
return 'button';
|
|
31
|
+
case 'input': {
|
|
32
|
+
const type = (attributes['type'] || 'text').toLowerCase();
|
|
33
|
+
if (['button', 'submit', 'reset', 'image'].includes(type))
|
|
34
|
+
return 'button';
|
|
35
|
+
if (type === 'checkbox')
|
|
36
|
+
return 'checkbox';
|
|
37
|
+
if (type === 'radio')
|
|
38
|
+
return 'radio';
|
|
39
|
+
if (type === 'search')
|
|
40
|
+
return 'searchbox';
|
|
41
|
+
if (['text', 'email', 'tel', 'url', 'password', 'number'].includes(type))
|
|
42
|
+
return 'textbox';
|
|
43
|
+
if (type === 'range')
|
|
44
|
+
return 'slider';
|
|
45
|
+
return 'textbox';
|
|
46
|
+
}
|
|
47
|
+
case 'textarea':
|
|
48
|
+
return 'textbox';
|
|
49
|
+
case 'select':
|
|
50
|
+
return attributes['multiple'] !== undefined ? 'listbox' : 'combobox';
|
|
51
|
+
case 'dialog':
|
|
52
|
+
return 'dialog';
|
|
53
|
+
case 'table':
|
|
54
|
+
return 'table';
|
|
55
|
+
case 'thead':
|
|
56
|
+
return 'rowgroup';
|
|
57
|
+
case 'tbody':
|
|
58
|
+
return 'rowgroup';
|
|
59
|
+
case 'tr':
|
|
60
|
+
return 'row';
|
|
61
|
+
case 'th':
|
|
62
|
+
return 'columnheader';
|
|
63
|
+
case 'td':
|
|
64
|
+
return 'cell';
|
|
65
|
+
case 'nav':
|
|
66
|
+
return 'navigation';
|
|
67
|
+
case 'header':
|
|
68
|
+
return 'banner';
|
|
69
|
+
case 'footer':
|
|
70
|
+
return 'contentinfo';
|
|
71
|
+
case 'main':
|
|
72
|
+
return 'main';
|
|
73
|
+
case 'form':
|
|
74
|
+
return 'form';
|
|
75
|
+
case 'h1':
|
|
76
|
+
case 'h2':
|
|
77
|
+
case 'h3':
|
|
78
|
+
case 'h4':
|
|
79
|
+
case 'h5':
|
|
80
|
+
case 'h6':
|
|
81
|
+
return 'heading';
|
|
82
|
+
case 'ul':
|
|
83
|
+
case 'ol':
|
|
84
|
+
return 'list';
|
|
85
|
+
case 'li':
|
|
86
|
+
return 'listitem';
|
|
87
|
+
case 'menu':
|
|
88
|
+
return 'menu';
|
|
89
|
+
case 'menuitem':
|
|
90
|
+
return 'menuitem';
|
|
91
|
+
case 'img':
|
|
92
|
+
return attributes['alt'] === '' ? 'presentation' : 'image';
|
|
93
|
+
case 'p':
|
|
94
|
+
return 'paragraph';
|
|
95
|
+
case 'section':
|
|
96
|
+
return attributes['aria-label'] || attributes['aria-labelledby'] ? 'region' : 'generic';
|
|
97
|
+
case 'article':
|
|
98
|
+
return 'article';
|
|
99
|
+
case 'aside':
|
|
100
|
+
return 'complementary';
|
|
101
|
+
default:
|
|
102
|
+
return 'generic';
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Computes accessible name for an element following W3C AccName specification.
|
|
107
|
+
*/
|
|
108
|
+
export function computeAccessibleName(tagName, attributes, innerText, idToTextMap) {
|
|
109
|
+
// 1. aria-label has highest precedence
|
|
110
|
+
if (attributes['aria-label']) {
|
|
111
|
+
return attributes['aria-label'].trim();
|
|
112
|
+
}
|
|
113
|
+
// 2. aria-labelledby
|
|
114
|
+
if (attributes['aria-labelledby']) {
|
|
115
|
+
const ids = attributes['aria-labelledby'].split(/\s+/);
|
|
116
|
+
const resolved = ids.map(id => idToTextMap.get(id) || '').filter(Boolean).join(' ').trim();
|
|
117
|
+
if (resolved)
|
|
118
|
+
return resolved;
|
|
119
|
+
}
|
|
120
|
+
// 3. Native attributes (alt, placeholder, title, value for buttons)
|
|
121
|
+
if (attributes['alt'])
|
|
122
|
+
return attributes['alt'].trim();
|
|
123
|
+
if (attributes['placeholder'] && !innerText)
|
|
124
|
+
return attributes['placeholder'].trim();
|
|
125
|
+
if (tagName.toLowerCase() === 'input') {
|
|
126
|
+
const type = (attributes['type'] || 'text').toLowerCase();
|
|
127
|
+
if (['button', 'submit', 'reset'].includes(type) && attributes['value']) {
|
|
128
|
+
return attributes['value'].trim();
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
// 4. Inner text
|
|
132
|
+
if (innerText) {
|
|
133
|
+
return innerText.trim();
|
|
134
|
+
}
|
|
135
|
+
// 5. title fallback
|
|
136
|
+
if (attributes['title']) {
|
|
137
|
+
return attributes['title'].trim();
|
|
138
|
+
}
|
|
139
|
+
return '';
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Builds a hierarchical AccessibilityNode tree from an HTML string or DOM fragments.
|
|
143
|
+
*/
|
|
144
|
+
export function buildAccessibilityTree(html) {
|
|
145
|
+
// Strip scripts and styles
|
|
146
|
+
const cleanHtml = html
|
|
147
|
+
.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, '')
|
|
148
|
+
.replace(/<style\b[^<]*(?:(?!<\/style>)<[^<]*)*<\/style>/gi, '')
|
|
149
|
+
.replace(/<!--[\s\S]*?-->/g, '');
|
|
150
|
+
// Map IDs to their text content for aria-labelledby resolution
|
|
151
|
+
const idToTextMap = new Map();
|
|
152
|
+
const idOpenTagRegex = /<([a-zA-Z0-9_\-]+)\b([^>]*)>/gi;
|
|
153
|
+
let m;
|
|
154
|
+
while ((m = idOpenTagRegex.exec(cleanHtml)) !== null) {
|
|
155
|
+
const tag = m[1].toLowerCase();
|
|
156
|
+
const attrs = parseAttributes(m[2] || '');
|
|
157
|
+
if (attrs['id']) {
|
|
158
|
+
const afterOpen = idOpenTagRegex.lastIndex;
|
|
159
|
+
const closeTag = `</${tag}>`;
|
|
160
|
+
const closeIdx = cleanHtml.indexOf(closeTag, afterOpen);
|
|
161
|
+
if (closeIdx !== -1 && closeIdx - afterOpen < 1000) {
|
|
162
|
+
idToTextMap.set(attrs['id'], cleanText(cleanHtml.slice(afterOpen, closeIdx)));
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
let nextNodeId = 1;
|
|
167
|
+
// Root accessibility node
|
|
168
|
+
const rootNode = {
|
|
169
|
+
id: 'ax-0',
|
|
170
|
+
role: 'WebArea',
|
|
171
|
+
name: 'Document Root',
|
|
172
|
+
children: [],
|
|
173
|
+
};
|
|
174
|
+
// Opening tag scanner to prevent parent containers from swallowing nested accessible children
|
|
175
|
+
const openTagRegex = /<([a-zA-Z0-9_\-]+)\b([^>]*)>/gi;
|
|
176
|
+
let elMatch;
|
|
177
|
+
while ((elMatch = openTagRegex.exec(cleanHtml)) !== null) {
|
|
178
|
+
const tagName = elMatch[1].toLowerCase();
|
|
179
|
+
const attrStr = elMatch[2] || '';
|
|
180
|
+
const attributes = parseAttributes(attrStr);
|
|
181
|
+
// Skip aria-hidden
|
|
182
|
+
if (attributes['aria-hidden'] === 'true') {
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
const role = getImplicitAriaRole(tagName, attributes);
|
|
186
|
+
if (role === 'generic' || role === 'presentation') {
|
|
187
|
+
continue; // Skip non-semantic containers in top-level AX projection
|
|
188
|
+
}
|
|
189
|
+
// Extract inner text up to matching closing tag
|
|
190
|
+
let innerText = '';
|
|
191
|
+
const afterOpenTagIdx = openTagRegex.lastIndex;
|
|
192
|
+
const closeTag = `</${tagName}>`;
|
|
193
|
+
const closeIdx = cleanHtml.indexOf(closeTag, afterOpenTagIdx);
|
|
194
|
+
if (closeIdx !== -1 && closeIdx - afterOpenTagIdx < 2000) {
|
|
195
|
+
innerText = cleanText(cleanHtml.slice(afterOpenTagIdx, closeIdx));
|
|
196
|
+
}
|
|
197
|
+
const name = computeAccessibleName(tagName, attributes, innerText, idToTextMap);
|
|
198
|
+
const node = {
|
|
199
|
+
id: `ax-${nextNodeId++}`,
|
|
200
|
+
role,
|
|
201
|
+
name,
|
|
202
|
+
value: attributes['value'] || attributes['href'] || undefined,
|
|
203
|
+
description: attributes['aria-description'] || attributes['title'] || undefined,
|
|
204
|
+
disabled: attributes['disabled'] !== undefined || attributes['aria-disabled'] === 'true',
|
|
205
|
+
expanded: attributes['aria-expanded'] ? attributes['aria-expanded'] === 'true' : undefined,
|
|
206
|
+
selected: attributes['aria-selected'] ? attributes['aria-selected'] === 'true' : undefined,
|
|
207
|
+
checked: attributes['aria-checked'] ? attributes['aria-checked'] === 'true' : (attributes['checked'] !== undefined ? true : undefined),
|
|
208
|
+
children: [],
|
|
209
|
+
};
|
|
210
|
+
rootNode.children.push(node);
|
|
211
|
+
}
|
|
212
|
+
return rootNode;
|
|
213
|
+
}
|
|
214
|
+
//# sourceMappingURL=accessibilityTree.js.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type BrowserState, type SemanticElement, type FormObservation, type TableObservation, type MenuObservation, type ModalObservation, type PageLoadingState, type ObservationOptions, type IBrowserObserver } from './types.js';
|
|
2
|
+
export declare class BrowserObserver implements IBrowserObserver {
|
|
3
|
+
private currentState;
|
|
4
|
+
private defaultViewport;
|
|
5
|
+
/**
|
|
6
|
+
* Observes the page and produces a normalized BrowserState representation.
|
|
7
|
+
*/
|
|
8
|
+
observe(source?: {
|
|
9
|
+
html?: string;
|
|
10
|
+
url?: string;
|
|
11
|
+
title?: string;
|
|
12
|
+
cdpSession?: any;
|
|
13
|
+
}, options?: ObservationOptions): Promise<BrowserState>;
|
|
14
|
+
getElement(refOrSelector: string): Promise<SemanticElement | null>;
|
|
15
|
+
getElementsByRole(role: string): Promise<SemanticElement[]>;
|
|
16
|
+
getElementsByText(text: string): Promise<SemanticElement[]>;
|
|
17
|
+
getForms(): Promise<FormObservation[]>;
|
|
18
|
+
getTables(): Promise<TableObservation[]>;
|
|
19
|
+
getMenus(): Promise<MenuObservation[]>;
|
|
20
|
+
getModals(): Promise<ModalObservation[]>;
|
|
21
|
+
getLoadingState(): Promise<PageLoadingState>;
|
|
22
|
+
takeScreenshot(fullPage?: boolean): Promise<string>;
|
|
23
|
+
/**
|
|
24
|
+
* Formats the observation using the strict priority:
|
|
25
|
+
* Accessibility/DOM → Semantic Element Information → Visual Understanding → Coordinates
|
|
26
|
+
*/
|
|
27
|
+
formatObservationForAgent(state?: BrowserState): string;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=browserObserver.d.ts.map
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import {} from './types.js';
|
|
2
|
+
import { buildAccessibilityTree } from './accessibilityTree.js';
|
|
3
|
+
import { extractSemanticElements, extractForms, extractTables, extractMenus, extractModals, extractLoadingState, extractVisibleText, } from './domExtractor.js';
|
|
4
|
+
export class BrowserObserver {
|
|
5
|
+
currentState = null;
|
|
6
|
+
defaultViewport = {
|
|
7
|
+
width: 1280,
|
|
8
|
+
height: 800,
|
|
9
|
+
scrollX: 0,
|
|
10
|
+
scrollY: 0,
|
|
11
|
+
devicePixelRatio: 1,
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Observes the page and produces a normalized BrowserState representation.
|
|
15
|
+
*/
|
|
16
|
+
async observe(source, options) {
|
|
17
|
+
let html = source?.html || '';
|
|
18
|
+
const url = source?.url || (html ? 'about:srcdoc' : 'about:blank');
|
|
19
|
+
// If no HTML provided, but a URL is given, fetch it
|
|
20
|
+
if (!html && url.startsWith('http')) {
|
|
21
|
+
try {
|
|
22
|
+
const res = await fetch(url, {
|
|
23
|
+
headers: { 'User-Agent': 'Scout-BrowserObserver/9.5.7' },
|
|
24
|
+
signal: AbortSignal.timeout(10000),
|
|
25
|
+
});
|
|
26
|
+
if (res.ok) {
|
|
27
|
+
html = await res.text();
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
html = `<html><body><p>Failed to load ${url}</p></body></html>`;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
// Extract title
|
|
35
|
+
let title = source?.title || '';
|
|
36
|
+
if (!title && html) {
|
|
37
|
+
const titleMatch = html.match(/<title\b[^>]*>([\s\S]*?)<\/title>/i);
|
|
38
|
+
title = titleMatch && titleMatch[1] ? titleMatch[1].trim() : url;
|
|
39
|
+
}
|
|
40
|
+
const viewport = {
|
|
41
|
+
...this.defaultViewport,
|
|
42
|
+
...(options?.viewport || {}),
|
|
43
|
+
};
|
|
44
|
+
const accessibilityTree = buildAccessibilityTree(html);
|
|
45
|
+
let elements = extractSemanticElements(html, viewport);
|
|
46
|
+
const forms = extractForms(html);
|
|
47
|
+
const tables = extractTables(html);
|
|
48
|
+
const menus = extractMenus(html);
|
|
49
|
+
const modals = extractModals(html);
|
|
50
|
+
const loadingState = extractLoadingState(html);
|
|
51
|
+
const visibleText = extractVisibleText(html);
|
|
52
|
+
if (options?.filterVisibleOnly) {
|
|
53
|
+
elements = elements.filter((el) => el.state.visible);
|
|
54
|
+
}
|
|
55
|
+
if (options?.maxElements && options.maxElements > 0) {
|
|
56
|
+
elements = elements.slice(0, options.maxElements);
|
|
57
|
+
}
|
|
58
|
+
const state = {
|
|
59
|
+
url,
|
|
60
|
+
title,
|
|
61
|
+
viewport,
|
|
62
|
+
screenshot: options?.includeScreenshot !== false
|
|
63
|
+
? `data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="${viewport.width}" height="${viewport.height}"><rect width="100%" height="100%" fill="%231a1a24"/><text x="40" y="60" fill="%23ffffff" font-family="sans-serif" font-size="20">${title || url}</text></svg>`
|
|
64
|
+
: undefined,
|
|
65
|
+
elements,
|
|
66
|
+
accessibilityTree,
|
|
67
|
+
loadingState,
|
|
68
|
+
visibleText,
|
|
69
|
+
forms,
|
|
70
|
+
tables,
|
|
71
|
+
menus,
|
|
72
|
+
modals,
|
|
73
|
+
timestamp: Date.now(),
|
|
74
|
+
};
|
|
75
|
+
this.currentState = state;
|
|
76
|
+
return state;
|
|
77
|
+
}
|
|
78
|
+
async getElement(refOrSelector) {
|
|
79
|
+
if (!this.currentState)
|
|
80
|
+
return null;
|
|
81
|
+
const query = refOrSelector.trim().toLowerCase();
|
|
82
|
+
return this.currentState.elements.find((el) => el.id.toLowerCase() === query ||
|
|
83
|
+
el.selector.toLowerCase() === query ||
|
|
84
|
+
el.text.toLowerCase().includes(query) ||
|
|
85
|
+
(el.attributes['id'] && `#${el.attributes['id'].toLowerCase()}` === query) ||
|
|
86
|
+
(el.attributes['name'] && el.attributes['name'].toLowerCase() === query)) || null;
|
|
87
|
+
}
|
|
88
|
+
async getElementsByRole(role) {
|
|
89
|
+
if (!this.currentState)
|
|
90
|
+
return [];
|
|
91
|
+
const target = role.toLowerCase().trim();
|
|
92
|
+
return this.currentState.elements.filter((el) => el.role.toLowerCase() === target);
|
|
93
|
+
}
|
|
94
|
+
async getElementsByText(text) {
|
|
95
|
+
if (!this.currentState)
|
|
96
|
+
return [];
|
|
97
|
+
const query = text.toLowerCase().trim();
|
|
98
|
+
return this.currentState.elements.filter((el) => el.text.toLowerCase().includes(query));
|
|
99
|
+
}
|
|
100
|
+
async getForms() {
|
|
101
|
+
return this.currentState?.forms || [];
|
|
102
|
+
}
|
|
103
|
+
async getTables() {
|
|
104
|
+
return this.currentState?.tables || [];
|
|
105
|
+
}
|
|
106
|
+
async getMenus() {
|
|
107
|
+
return this.currentState?.menus || [];
|
|
108
|
+
}
|
|
109
|
+
async getModals() {
|
|
110
|
+
return this.currentState?.modals || [];
|
|
111
|
+
}
|
|
112
|
+
async getLoadingState() {
|
|
113
|
+
return this.currentState?.loadingState || {
|
|
114
|
+
status: 'complete',
|
|
115
|
+
isBusy: false,
|
|
116
|
+
hasActiveSpinners: false,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
async takeScreenshot(fullPage = false) {
|
|
120
|
+
if (!this.currentState) {
|
|
121
|
+
return '';
|
|
122
|
+
}
|
|
123
|
+
return this.currentState.screenshot || '';
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Formats the observation using the strict priority:
|
|
127
|
+
* Accessibility/DOM → Semantic Element Information → Visual Understanding → Coordinates
|
|
128
|
+
*/
|
|
129
|
+
formatObservationForAgent(state) {
|
|
130
|
+
const s = state || this.currentState;
|
|
131
|
+
if (!s) {
|
|
132
|
+
return 'No browser state currently observed.';
|
|
133
|
+
}
|
|
134
|
+
const lines = [];
|
|
135
|
+
lines.push(`╭── 🌐 BROWSER OBSERVATION: "${s.title}" ──╮`);
|
|
136
|
+
lines.push(`│ URL: ${s.url}`);
|
|
137
|
+
lines.push(`│ Status: ${s.loadingState.status.toUpperCase()} ${s.loadingState.isBusy ? '(BUSY)' : ''}`);
|
|
138
|
+
lines.push(`│ Viewport: ${s.viewport.width}x${s.viewport.height} (DPI: ${s.viewport.devicePixelRatio})`);
|
|
139
|
+
lines.push(`├─────────────────────────────────────────────────────────────────`);
|
|
140
|
+
// 1. Accessibility Tree & Semantic Elements (Highest Priority)
|
|
141
|
+
lines.push(`│ ♿ ACCESSIBILITY & DOM STRUCTURE:`);
|
|
142
|
+
lines.push(`│ 🎯 INTERACTIVE ELEMENTS (${s.elements.length}):`);
|
|
143
|
+
for (const el of s.elements.slice(0, 25)) {
|
|
144
|
+
const roleBadge = `[${el.role}]`.padEnd(14);
|
|
145
|
+
const extra = el.attributes['href'] ? ` -> ${el.attributes['href']}` : (el.attributes['placeholder'] ? ` (placeholder: "${el.attributes['placeholder']}")` : '');
|
|
146
|
+
const coord = `(x:${el.bounds.x}, y:${el.bounds.y})`;
|
|
147
|
+
lines.push(`│ ${el.id.padEnd(8)} ${roleBadge} "${el.text || 'Element'}" (${el.selector})${extra} ${coord}`);
|
|
148
|
+
}
|
|
149
|
+
if (s.elements.length > 25) {
|
|
150
|
+
lines.push(`│ ... and ${s.elements.length - 25} more elements.`);
|
|
151
|
+
}
|
|
152
|
+
// 2. Forms & Inputs
|
|
153
|
+
if (s.forms.length > 0) {
|
|
154
|
+
lines.push(`├─────────────────────────────────────────────────────────────────`);
|
|
155
|
+
lines.push(`│ 📝 FORMS & INPUT CONTROLS (${s.forms.length}):`);
|
|
156
|
+
for (const f of s.forms) {
|
|
157
|
+
lines.push(`│ Form #${f.id} [${f.method} ${f.action || ''}]:`);
|
|
158
|
+
for (const field of f.fields) {
|
|
159
|
+
const req = field.required ? ' *required*' : '';
|
|
160
|
+
lines.push(`│ • ${field.label || field.name || field.id} (${field.type})${req} -> ${field.selector}`);
|
|
161
|
+
}
|
|
162
|
+
if (f.submitButton) {
|
|
163
|
+
lines.push(`│ ✔ Submit Button: "${f.submitButton.text}" (${f.submitButton.id})`);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
// 3. Modals & Dialogs (Critical for flow control)
|
|
168
|
+
const openModals = s.modals.filter((m) => m.isOpen);
|
|
169
|
+
if (openModals.length > 0) {
|
|
170
|
+
lines.push(`├─────────────────────────────────────────────────────────────────`);
|
|
171
|
+
lines.push(`│ 🚨 ACTIVE MODAL / DIALOG DETECTED (${openModals.length}):`);
|
|
172
|
+
for (const modal of openModals) {
|
|
173
|
+
lines.push(`│ [${modal.role.toUpperCase()}] "${modal.title || 'Dialog'}" (${modal.id}):`);
|
|
174
|
+
lines.push(`│ Summary: ${modal.textSummary.slice(0, 100)}`);
|
|
175
|
+
if (modal.closeButton) {
|
|
176
|
+
lines.push(`│ Dismiss Action: ${modal.closeButton.text} (${modal.closeButton.id})`);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
// 4. Tables
|
|
181
|
+
if (s.tables.length > 0) {
|
|
182
|
+
lines.push(`├─────────────────────────────────────────────────────────────────`);
|
|
183
|
+
lines.push(`│ 📊 TABULAR DATA (${s.tables.length} tables):`);
|
|
184
|
+
for (const tbl of s.tables) {
|
|
185
|
+
lines.push(`│ Table #${tbl.id}: ${tbl.rowCount} rows, ${tbl.columnCount} columns`);
|
|
186
|
+
if (tbl.headers.length > 0) {
|
|
187
|
+
lines.push(`│ Headers: [ ${tbl.headers.join(' | ')} ]`);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
// 5. Navigation & Menus
|
|
192
|
+
if (s.menus.length > 0) {
|
|
193
|
+
lines.push(`├─────────────────────────────────────────────────────────────────`);
|
|
194
|
+
lines.push(`│ 🧭 NAVIGATION & MENUS (${s.menus.length}):`);
|
|
195
|
+
for (const m of s.menus) {
|
|
196
|
+
const itemTexts = m.items.map((i) => i.text).filter(Boolean).slice(0, 6);
|
|
197
|
+
lines.push(`│ [${m.type}] ${m.id}: ${itemTexts.join(' • ')}`);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
lines.push(`╰─────────────────────────────────────────────────────────────────╯`);
|
|
201
|
+
return lines.join('\n');
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
//# sourceMappingURL=browserObserver.js.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type SemanticElement, type BrowserViewport, type FormObservation, type TableObservation, type MenuObservation, type ModalObservation, type PageLoadingState } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Extracts all interactive and semantic elements from HTML string.
|
|
4
|
+
*/
|
|
5
|
+
export declare function extractSemanticElements(html: string, viewport?: BrowserViewport): SemanticElement[];
|
|
6
|
+
/**
|
|
7
|
+
* Extracts all form structures with field definitions and submit controls.
|
|
8
|
+
*/
|
|
9
|
+
export declare function extractForms(html: string): FormObservation[];
|
|
10
|
+
/**
|
|
11
|
+
* Extracts tabular data structures including headers, rows, and cell contents.
|
|
12
|
+
*/
|
|
13
|
+
export declare function extractTables(html: string): TableObservation[];
|
|
14
|
+
/**
|
|
15
|
+
* Extracts navigation menus, menubars, and dropdowns.
|
|
16
|
+
*/
|
|
17
|
+
export declare function extractMenus(html: string): MenuObservation[];
|
|
18
|
+
/**
|
|
19
|
+
* Extracts modal dialogs, alert dialogs, and popups.
|
|
20
|
+
*/
|
|
21
|
+
export declare function extractModals(html: string): ModalObservation[];
|
|
22
|
+
/**
|
|
23
|
+
* Extracts page loading state, pending spinners, and busy indicators.
|
|
24
|
+
*/
|
|
25
|
+
export declare function extractLoadingState(html: string): PageLoadingState;
|
|
26
|
+
/**
|
|
27
|
+
* Extracts cleaned visible prose content from the HTML document.
|
|
28
|
+
*/
|
|
29
|
+
export declare function extractVisibleText(html: string): string;
|
|
30
|
+
//# sourceMappingURL=domExtractor.d.ts.map
|