ft-scout 9.5.5 → 9.5.6

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.
Files changed (92) hide show
  1. package/README.md +1 -1
  2. package/bin/src/engine/agent/computerUseLoop.d.ts +107 -0
  3. package/bin/src/engine/agent/computerUseLoop.js +413 -0
  4. package/bin/src/engine/agent/index.d.ts +2 -0
  5. package/bin/src/engine/agent/index.js +2 -0
  6. package/bin/src/engine/agent/recovery/index.d.ts +4 -0
  7. package/bin/src/engine/agent/recovery/index.js +4 -0
  8. package/bin/src/engine/agent/recovery/loopDetector.d.ts +26 -0
  9. package/bin/src/engine/agent/recovery/loopDetector.js +126 -0
  10. package/bin/src/engine/agent/recovery/recoveryManager.d.ts +43 -0
  11. package/bin/src/engine/agent/recovery/recoveryManager.js +271 -0
  12. package/bin/src/engine/agent/recovery/types.d.ts +48 -0
  13. package/bin/src/engine/agent/recovery/types.js +4 -0
  14. package/bin/src/engine/agent/verification/index.d.ts +3 -0
  15. package/bin/src/engine/agent/verification/index.js +3 -0
  16. package/bin/src/engine/agent/verification/stateChangeVerifier.d.ts +22 -0
  17. package/bin/src/engine/agent/verification/stateChangeVerifier.js +282 -0
  18. package/bin/src/engine/agent/verification/types.d.ts +28 -0
  19. package/bin/src/engine/agent/verification/types.js +4 -0
  20. package/bin/src/engine/agentEngine.d.ts +2 -1
  21. package/bin/src/engine/agentEngine.js +2 -1
  22. package/bin/src/engine/agentState.d.ts +41 -1
  23. package/bin/src/engine/agentState.js +45 -0
  24. package/bin/src/engine/browser/actions/actionEngine.d.ts +41 -0
  25. package/bin/src/engine/browser/actions/actionEngine.js +707 -0
  26. package/bin/src/engine/browser/actions/index.d.ts +4 -0
  27. package/bin/src/engine/browser/actions/index.js +4 -0
  28. package/bin/src/engine/browser/actions/reliability.d.ts +41 -0
  29. package/bin/src/engine/browser/actions/reliability.js +170 -0
  30. package/bin/src/engine/browser/actions/types.d.ts +50 -0
  31. package/bin/src/engine/browser/actions/types.js +2 -0
  32. package/bin/src/engine/browser/browserController.d.ts +18 -0
  33. package/bin/src/engine/browser/browserController.js +44 -12
  34. package/bin/src/engine/browser/index.d.ts +2 -0
  35. package/bin/src/engine/browser/index.js +2 -0
  36. package/bin/src/engine/browser/observer/accessibilityTree.d.ts +14 -0
  37. package/bin/src/engine/browser/observer/accessibilityTree.js +214 -0
  38. package/bin/src/engine/browser/observer/browserObserver.d.ts +29 -0
  39. package/bin/src/engine/browser/observer/browserObserver.js +204 -0
  40. package/bin/src/engine/browser/observer/domExtractor.d.ts +30 -0
  41. package/bin/src/engine/browser/observer/domExtractor.js +407 -0
  42. package/bin/src/engine/browser/observer/index.d.ts +5 -0
  43. package/bin/src/engine/browser/observer/index.js +5 -0
  44. package/bin/src/engine/browser/observer/types.d.ts +163 -0
  45. package/bin/src/engine/browser/observer/types.js +8 -0
  46. package/bin/src/engine/computer/computerController.d.ts +43 -0
  47. package/bin/src/engine/computer/computerController.js +111 -0
  48. package/bin/src/engine/computer/mockComputer.d.ts +6 -1
  49. package/bin/src/engine/computer/mockComputer.js +58 -0
  50. package/bin/src/engine/models/harpProvider.d.ts +32 -0
  51. package/bin/src/engine/models/harpProvider.js +124 -0
  52. package/bin/src/engine/models/index.d.ts +6 -0
  53. package/bin/src/engine/models/index.js +6 -0
  54. package/bin/src/engine/models/localModelProvider.d.ts +11 -0
  55. package/bin/src/engine/models/localModelProvider.js +48 -0
  56. package/bin/src/engine/models/openaiProvider.d.ts +11 -0
  57. package/bin/src/engine/models/openaiProvider.js +50 -0
  58. package/bin/src/engine/models/reasoningOrchestrator.d.ts +17 -0
  59. package/bin/src/engine/models/reasoningOrchestrator.js +75 -0
  60. package/bin/src/engine/models/types.d.ts +63 -0
  61. package/bin/src/engine/models/types.js +2 -0
  62. package/bin/src/engine/production/index.d.ts +3 -0
  63. package/bin/src/engine/production/index.js +3 -0
  64. package/bin/src/engine/production/taskReplay.d.ts +37 -0
  65. package/bin/src/engine/production/taskReplay.js +81 -0
  66. package/bin/src/engine/production/telemetry.d.ts +43 -0
  67. package/bin/src/engine/production/telemetry.js +68 -0
  68. package/bin/src/engine/runtime/agentRuntime.d.ts +1 -1
  69. package/bin/src/engine/safety/index.d.ts +3 -0
  70. package/bin/src/engine/safety/index.js +3 -0
  71. package/bin/src/engine/safety/policyEngine.d.ts +40 -0
  72. package/bin/src/engine/safety/policyEngine.js +282 -0
  73. package/bin/src/engine/safety/types.d.ts +24 -0
  74. package/bin/src/engine/safety/types.js +2 -0
  75. package/bin/src/engine/safety.d.ts +1 -0
  76. package/bin/src/engine/safety.js +1 -0
  77. package/bin/src/engine/toolRegistry.d.ts +4 -0
  78. package/bin/src/engine/toolRegistry.js +9 -0
  79. package/bin/src/engine/tools/domainHandlers.d.ts +61 -0
  80. package/bin/src/engine/tools/domainHandlers.js +458 -0
  81. package/bin/src/engine/tools/index.d.ts +4 -0
  82. package/bin/src/engine/tools/index.js +4 -0
  83. package/bin/src/engine/tools/types.d.ts +56 -0
  84. package/bin/src/engine/tools/types.js +2 -0
  85. package/bin/src/engine/tools/unifiedRouter.d.ts +29 -0
  86. package/bin/src/engine/tools/unifiedRouter.js +426 -0
  87. package/bin/src/index.js +4 -4
  88. package/bin/src/mcp/client.js +1 -1
  89. package/bin/src/utils/branding.js +1 -1
  90. package/bin/src/utils/qrBridge.js +1 -1
  91. package/bin/src/utils/support.js +1 -1
  92. package/package.json +2 -2
@@ -0,0 +1,407 @@
1
+ import {} from './types.js';
2
+ import { getImplicitAriaRole, computeAccessibleName } from './accessibilityTree.js';
3
+ function parseAttributes(attrStr) {
4
+ const attrs = {};
5
+ const regex = /([a-zA-Z0-9_\-:@.]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+)))?/g;
6
+ let match;
7
+ while ((match = regex.exec(attrStr)) !== null) {
8
+ const key = match[1].toLowerCase();
9
+ const val = match[2] ?? match[3] ?? match[4] ?? '';
10
+ attrs[key] = val;
11
+ }
12
+ return attrs;
13
+ }
14
+ function cleanText(text) {
15
+ return text.replace(/<[^>]+>/g, ' ').replace(/\s+/g, ' ').trim();
16
+ }
17
+ /**
18
+ * Extracts all interactive and semantic elements from HTML string.
19
+ */
20
+ export function extractSemanticElements(html, viewport = { width: 1280, height: 800, scrollX: 0, scrollY: 0, devicePixelRatio: 1 }) {
21
+ const elements = [];
22
+ let refCounter = 1;
23
+ // Pre-pass: map IDs to innerText for accessible name resolution
24
+ const idToTextMap = new Map();
25
+ const idOpenTagRegex = /<([a-zA-Z0-9_\-]+)\b([^>]*)>/gi;
26
+ let m;
27
+ while ((m = idOpenTagRegex.exec(html)) !== null) {
28
+ const tag = m[1].toLowerCase();
29
+ const attrs = parseAttributes(m[2] || '');
30
+ if (attrs['id']) {
31
+ const afterOpen = idOpenTagRegex.lastIndex;
32
+ const closeTag = `</${tag}>`;
33
+ const closeIdx = html.indexOf(closeTag, afterOpen);
34
+ if (closeIdx !== -1 && closeIdx - afterOpen < 1000) {
35
+ idToTextMap.set(attrs['id'], cleanText(html.slice(afterOpen, closeIdx)));
36
+ }
37
+ }
38
+ }
39
+ // Open tag scanner to find all interactive tags without container nesting conflicts
40
+ const openTagRegex = /<([a-zA-Z0-9_\-]+)\b([^>]*)>/gi;
41
+ let match;
42
+ let currentOffsetY = 20;
43
+ const itemHeight = 36;
44
+ const defaultWidth = 180;
45
+ while ((match = openTagRegex.exec(html)) !== null) {
46
+ const tagName = match[1].toLowerCase();
47
+ const attrStr = match[2] || '';
48
+ const attrs = parseAttributes(attrStr);
49
+ const role = getImplicitAriaRole(tagName, attrs);
50
+ const isInteractiveTag = ['a', 'button', 'input', 'select', 'textarea', 'dialog', 'summary'].includes(tagName);
51
+ const hasClickOrRole = Boolean(attrs['role'] && !['generic', 'presentation', 'none'].includes(attrs['role']) ||
52
+ attrs['onclick'] ||
53
+ attrs['tabindex'] ||
54
+ attrs['contenteditable'] === 'true');
55
+ if (!isInteractiveTag && !hasClickOrRole) {
56
+ continue;
57
+ }
58
+ // Extract inner text up to matching closing tag or next sibling
59
+ let innerContent = '';
60
+ const afterOpenIdx = openTagRegex.lastIndex;
61
+ const closeTag = `</${tagName}>`;
62
+ const closeIdx = html.indexOf(closeTag, afterOpenIdx);
63
+ if (closeIdx !== -1 && closeIdx - afterOpenIdx < 3000) {
64
+ innerContent = html.slice(afterOpenIdx, closeIdx);
65
+ }
66
+ const isHidden = Boolean(attrs['hidden'] !== undefined ||
67
+ attrs['aria-hidden'] === 'true' ||
68
+ /display\s*:\s*none|visibility\s*:\s*hidden/i.test(attrs['style'] || ''));
69
+ const name = computeAccessibleName(tagName, attrs, cleanText(innerContent), idToTextMap);
70
+ const id = `@el/${refCounter++}`;
71
+ // Generate robust selector
72
+ let selector;
73
+ if (attrs['id']) {
74
+ selector = `#${attrs['id']}`;
75
+ }
76
+ else if (attrs['name']) {
77
+ selector = `${tagName}[name="${attrs['name']}"]`;
78
+ }
79
+ else if (attrs['aria-label']) {
80
+ selector = `${tagName}[aria-label="${attrs['aria-label']}"]`;
81
+ }
82
+ else if (attrs['data-testid']) {
83
+ selector = `[data-testid="${attrs['data-testid']}"]`;
84
+ }
85
+ else if (tagName === 'a' && attrs['href']) {
86
+ selector = `a[href="${attrs['href']}"]`;
87
+ }
88
+ else if (name) {
89
+ selector = `${tagName}:has-text("${name.slice(0, 30)}")`;
90
+ }
91
+ else {
92
+ selector = `${tagName}:nth-of-type(${refCounter})`;
93
+ }
94
+ // Synthesize bounding box geometry
95
+ const bounds = {
96
+ x: 40,
97
+ y: currentOffsetY,
98
+ width: defaultWidth,
99
+ height: itemHeight,
100
+ viewportRelative: true,
101
+ };
102
+ currentOffsetY += itemHeight + 12;
103
+ const state = {
104
+ visible: !isHidden,
105
+ focused: attrs['autofocus'] !== undefined,
106
+ disabled: attrs['disabled'] !== undefined || attrs['aria-disabled'] === 'true',
107
+ checked: attrs['aria-checked'] ? attrs['aria-checked'] === 'true' : (attrs['checked'] !== undefined ? true : undefined),
108
+ expanded: attrs['aria-expanded'] ? attrs['aria-expanded'] === 'true' : (attrs['open'] !== undefined ? true : undefined),
109
+ selected: attrs['aria-selected'] ? attrs['aria-selected'] === 'true' : (attrs['selected'] !== undefined ? true : undefined),
110
+ readOnly: attrs['readonly'] !== undefined,
111
+ required: attrs['required'] !== undefined || attrs['aria-required'] === 'true',
112
+ };
113
+ elements.push({
114
+ id,
115
+ role,
116
+ text: name,
117
+ selector,
118
+ bounds,
119
+ state,
120
+ attributes: attrs,
121
+ tagName,
122
+ });
123
+ }
124
+ return elements;
125
+ }
126
+ /**
127
+ * Extracts all form structures with field definitions and submit controls.
128
+ */
129
+ export function extractForms(html) {
130
+ const forms = [];
131
+ const formRegex = /<form\b([^>]*)>([\s\S]*?)<\/form>/gi;
132
+ let formMatch;
133
+ let formIdx = 1;
134
+ // Map labels
135
+ const labelRegex = /<label\b([^>]*)>([\s\S]*?)<\/label>/gi;
136
+ const forLabels = new Map();
137
+ let lblMatch;
138
+ while ((lblMatch = labelRegex.exec(html)) !== null) {
139
+ const attrs = parseAttributes(lblMatch[1] || '');
140
+ if (attrs['for']) {
141
+ forLabels.set(attrs['for'], cleanText(lblMatch[2] || ''));
142
+ }
143
+ }
144
+ while ((formMatch = formRegex.exec(html)) !== null) {
145
+ const formAttrs = parseAttributes(formMatch[1] || '');
146
+ const formInner = formMatch[2] || '';
147
+ const formId = formAttrs['id'] || `form-${formIdx++}`;
148
+ const fields = [];
149
+ let submitBtn;
150
+ // Extract inputs, textareas, selects
151
+ const fieldRegex = /<(input|textarea|select|button)\b([^>]*)>(?:([\s\S]*?)<\/\1>)?/gi;
152
+ let fieldMatch;
153
+ let fieldCounter = 1;
154
+ while ((fieldMatch = fieldRegex.exec(formInner)) !== null) {
155
+ const tag = fieldMatch[1].toLowerCase();
156
+ const attrs = parseAttributes(fieldMatch[2] || '');
157
+ const inner = fieldMatch[3] || '';
158
+ const type = (attrs['type'] || (tag === 'textarea' ? 'textarea' : tag === 'select' ? 'select' : 'text')).toLowerCase();
159
+ const fieldId = attrs['id'] || `${formId}-field-${fieldCounter++}`;
160
+ const label = (attrs['id'] ? forLabels.get(attrs['id']) : undefined) || attrs['aria-label'] || attrs['placeholder'];
161
+ if (tag === 'button' || ['submit', 'button', 'image'].includes(type)) {
162
+ if (type === 'submit' || tag === 'button') {
163
+ submitBtn = {
164
+ id: `@el/submit-${formId}`,
165
+ role: 'button',
166
+ text: cleanText(inner) || attrs['value'] || 'Submit',
167
+ selector: attrs['id'] ? `#${attrs['id']}` : `form#${formId} button[type="submit"], form#${formId} input[type="submit"]`,
168
+ bounds: { x: 50, y: 100, width: 120, height: 38, viewportRelative: true },
169
+ state: { visible: true, focused: false, disabled: attrs['disabled'] !== undefined },
170
+ attributes: attrs,
171
+ tagName: tag,
172
+ };
173
+ }
174
+ continue;
175
+ }
176
+ fields.push({
177
+ id: fieldId,
178
+ name: attrs['name'],
179
+ label,
180
+ type,
181
+ value: attrs['value'],
182
+ placeholder: attrs['placeholder'],
183
+ required: attrs['required'] !== undefined || attrs['aria-required'] === 'true',
184
+ disabled: attrs['disabled'] !== undefined || attrs['aria-disabled'] === 'true',
185
+ selector: attrs['id'] ? `#${attrs['id']}` : `${tag}[name="${attrs['name'] || fieldId}"]`,
186
+ });
187
+ }
188
+ forms.push({
189
+ id: formId,
190
+ name: formAttrs['name'],
191
+ action: formAttrs['action'],
192
+ method: (formAttrs['method'] || 'GET').toUpperCase(),
193
+ fields,
194
+ submitButton: submitBtn,
195
+ selector: formAttrs['id'] ? `#${formAttrs['id']}` : `form[name="${formAttrs['name'] || formId}"]`,
196
+ });
197
+ }
198
+ return forms;
199
+ }
200
+ /**
201
+ * Extracts tabular data structures including headers, rows, and cell contents.
202
+ */
203
+ export function extractTables(html) {
204
+ const tables = [];
205
+ const tableRegex = /<table\b([^>]*)>([\s\S]*?)<\/table>/gi;
206
+ let match;
207
+ let tableIndex = 1;
208
+ while ((match = tableRegex.exec(html)) !== null) {
209
+ const attrs = parseAttributes(match[1] || '');
210
+ const tableInner = match[2] || '';
211
+ const tableId = attrs['id'] || `table-${tableIndex++}`;
212
+ // Caption
213
+ const captionMatch = tableInner.match(/<caption\b[^>]*>([\s\S]*?)<\/caption>/i);
214
+ const caption = captionMatch && captionMatch[1] ? cleanText(captionMatch[1]) : undefined;
215
+ // Headers
216
+ const headers = [];
217
+ const thRegex = /<th\b[^>]*>([\s\S]*?)<\/th>/gi;
218
+ let thMatch;
219
+ while ((thMatch = thRegex.exec(tableInner)) !== null) {
220
+ headers.push(cleanText(thMatch[1] || ''));
221
+ }
222
+ // Rows
223
+ const rows = [];
224
+ const trRegex = /<tr\b[^>]*>([\s\S]*?)<\/tr>/gi;
225
+ let trMatch;
226
+ while ((trMatch = trRegex.exec(tableInner)) !== null) {
227
+ const trContent = trMatch[1] || '';
228
+ const cells = [];
229
+ const isHeaderRow = /<th\b/i.test(trContent);
230
+ const cellRegex = /<(?:td|th)\b[^>]*>([\s\S]*?)<\/(?:td|th)>/gi;
231
+ let cellMatch;
232
+ while ((cellMatch = cellRegex.exec(trContent)) !== null) {
233
+ cells.push(cleanText(cellMatch[1] || ''));
234
+ }
235
+ if (cells.length > 0) {
236
+ rows.push({ cells, isHeader: isHeaderRow });
237
+ }
238
+ }
239
+ const columnCount = Math.max(headers.length, ...rows.map(r => r.cells.length), 0);
240
+ tables.push({
241
+ id: tableId,
242
+ headers,
243
+ rows,
244
+ rowCount: rows.length,
245
+ columnCount,
246
+ caption,
247
+ selector: attrs['id'] ? `#${attrs['id']}` : `table:nth-of-type(${tableIndex - 1})`,
248
+ });
249
+ }
250
+ return tables;
251
+ }
252
+ /**
253
+ * Extracts navigation menus, menubars, and dropdowns.
254
+ */
255
+ export function extractMenus(html) {
256
+ const menus = [];
257
+ const menuRegex = /<(nav|ul|ol|div)\b([^>]*role=["'](?:menubar|menu|navigation)["'][^>]*)>([\s\S]*?)<\/\1>|<nav\b([^>]*)>([\s\S]*?)<\/nav>/gi;
258
+ let match;
259
+ let menuIndex = 1;
260
+ while ((match = menuRegex.exec(html)) !== null) {
261
+ const attrStr = match[2] || match[4] || '';
262
+ const inner = match[3] || match[5] || '';
263
+ const attrs = parseAttributes(attrStr);
264
+ const menuId = attrs['id'] || `menu-${menuIndex++}`;
265
+ const items = [];
266
+ // First match actionable buttons and links within the menu
267
+ const actionItemRegex = /<(a|button)\b([^>]*)>([\s\S]*?)<\/\1>/gi;
268
+ let itemMatch;
269
+ let itemIndex = 1;
270
+ while ((itemMatch = actionItemRegex.exec(inner)) !== null) {
271
+ const itemTag = itemMatch[1].toLowerCase();
272
+ const itemAttrs = parseAttributes(itemMatch[2] || '');
273
+ const itemText = cleanText(itemMatch[3] || '');
274
+ if (!itemText && !itemAttrs['href'])
275
+ continue;
276
+ const isExpanded = itemAttrs['aria-expanded'] !== undefined
277
+ ? itemAttrs['aria-expanded'] === 'true'
278
+ : undefined;
279
+ items.push({
280
+ id: itemAttrs['id'] || `${menuId}-item-${itemIndex++}`,
281
+ text: itemText,
282
+ role: itemAttrs['role'] || (itemTag === 'a' ? 'link' : 'button'),
283
+ href: itemAttrs['href'],
284
+ expanded: isExpanded,
285
+ });
286
+ }
287
+ // If no action buttons/links were found, extract raw <li> items
288
+ if (items.length === 0) {
289
+ const liRegex = /<li\b([^>]*)>([\s\S]*?)<\/li>/gi;
290
+ let liMatch;
291
+ while ((liMatch = liRegex.exec(inner)) !== null) {
292
+ const liAttrs = parseAttributes(liMatch[1] || '');
293
+ const liText = cleanText(liMatch[2] || '');
294
+ if (!liText)
295
+ continue;
296
+ items.push({
297
+ id: liAttrs['id'] || `${menuId}-item-${itemIndex++}`,
298
+ text: liText,
299
+ role: liAttrs['role'] || 'menuitem',
300
+ expanded: liAttrs['aria-expanded'] !== undefined ? liAttrs['aria-expanded'] === 'true' : undefined,
301
+ });
302
+ }
303
+ }
304
+ if (items.length > 0) {
305
+ menus.push({
306
+ id: menuId,
307
+ type: attrs['role'] === 'menubar' ? 'menubar' : attrs['role'] === 'menu' ? 'menu' : 'nav',
308
+ items,
309
+ selector: attrs['id'] ? `#${attrs['id']}` : `nav:nth-of-type(${menuIndex - 1})`,
310
+ });
311
+ }
312
+ }
313
+ return menus;
314
+ }
315
+ /**
316
+ * Extracts modal dialogs, alert dialogs, and popups.
317
+ */
318
+ export function extractModals(html) {
319
+ const modals = [];
320
+ const modalRegex = /<(dialog|div|section)\b([^>]*(?:role=["'](?:dialog|alertdialog)["']|class=["'][^"']*\bmodal\b[^"']*["'])[^>]*)>([\s\S]*?)<\/\1>|<dialog\b([^>]*)>([\s\S]*?)<\/dialog>/gi;
321
+ let match;
322
+ let modalIdx = 1;
323
+ while ((match = modalRegex.exec(html)) !== null) {
324
+ const attrStr = match[2] || match[4] || '';
325
+ const inner = match[3] || match[5] || '';
326
+ const attrs = parseAttributes(attrStr);
327
+ const modalId = attrs['id'] || `modal-${modalIdx++}`;
328
+ const isOpen = Boolean(attrs['open'] !== undefined ||
329
+ attrs['aria-hidden'] === 'false' ||
330
+ /\b(?:show|active|open|visible)\b/i.test(attrs['class'] || '') ||
331
+ /display\s*:\s*block/i.test(attrs['style'] || ''));
332
+ // Find modal title
333
+ const titleMatch = inner.match(/<(?:h[1-6]|header|div)\b[^>]*class=["'][^"']*(?:title|heading|header)[^"']*["'][^>]*>([\s\S]*?)<\/(?:h[1-6]|header|div)>/i);
334
+ const title = titleMatch && titleMatch[1] ? cleanText(titleMatch[1]) : (attrs['aria-label'] || attrs['title']);
335
+ // Find close button
336
+ const closeBtnMatch = inner.match(/<button\b([^>]*(?:aria-label=["']close["']|class=["'][^"']*(?:close|dismiss)[^"']*["'])[^>]*)>([\s\S]*?)<\/button>/i);
337
+ let closeBtn;
338
+ if (closeBtnMatch) {
339
+ const btnAttrs = parseAttributes(closeBtnMatch[1] || '');
340
+ closeBtn = {
341
+ id: `@el/close-${modalId}`,
342
+ role: 'button',
343
+ text: cleanText(closeBtnMatch[2] || '') || 'Close',
344
+ selector: btnAttrs['id'] ? `#${btnAttrs['id']}` : `#${modalId} button[aria-label="close"], #${modalId} .close`,
345
+ bounds: { x: 300, y: 50, width: 32, height: 32, viewportRelative: true },
346
+ state: { visible: true, focused: false, disabled: false },
347
+ attributes: btnAttrs,
348
+ tagName: 'button',
349
+ };
350
+ }
351
+ const hasBackdrop = /modal-backdrop|overlay/i.test(html);
352
+ const isAlert = attrs['role'] === 'alertdialog';
353
+ modals.push({
354
+ id: modalId,
355
+ title,
356
+ role: isAlert ? 'alertdialog' : 'dialog',
357
+ isOpen,
358
+ isModal: attrs['aria-modal'] === 'true' || match[1]?.toLowerCase() === 'dialog',
359
+ hasBackdrop,
360
+ closeButton: closeBtn,
361
+ textSummary: cleanText(inner).slice(0, 300),
362
+ selector: attrs['id'] ? `#${attrs['id']}` : `[role="dialog"]#${modalId}`,
363
+ });
364
+ }
365
+ return modals;
366
+ }
367
+ /**
368
+ * Extracts page loading state, pending spinners, and busy indicators.
369
+ */
370
+ export function extractLoadingState(html) {
371
+ const isBusy = /aria-busy=["']true["']/i.test(html);
372
+ const hasSpinners = /\b(?:spinner|loading-indicator|loader|skeleton|progress-bar)\b/i.test(html);
373
+ const progressMatch = html.match(/<progress\b[^>]*value=["'](\d+)["']/i);
374
+ const progressPercent = progressMatch && progressMatch[1] ? Number(progressMatch[1]) : undefined;
375
+ let status = 'complete';
376
+ if (isBusy || hasSpinners) {
377
+ status = 'loading';
378
+ }
379
+ else if (/<body\b/i.test(html) && /<\/html>/i.test(html)) {
380
+ status = 'networkidle';
381
+ }
382
+ return {
383
+ status,
384
+ isBusy,
385
+ hasActiveSpinners: hasSpinners,
386
+ progressPercent,
387
+ details: isBusy ? 'Page has aria-busy="true"' : (hasSpinners ? 'Active spinner or skeleton loader detected' : 'DOM ready'),
388
+ };
389
+ }
390
+ /**
391
+ * Extracts cleaned visible prose content from the HTML document.
392
+ */
393
+ export function extractVisibleText(html) {
394
+ return html
395
+ .replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, '')
396
+ .replace(/<style\b[^<]*(?:(?!<\/style>)<[^<]*)*<\/style>/gi, '')
397
+ .replace(/<head\b[\s\S]*?<\/head>/gi, '')
398
+ .replace(/<[^>]+>/g, ' ')
399
+ .replace(/&nbsp;/g, ' ')
400
+ .replace(/&amp;/g, '&')
401
+ .replace(/&lt;/g, '<')
402
+ .replace(/&gt;/g, '>')
403
+ .replace(/&quot;/g, '"')
404
+ .replace(/\s+/g, ' ')
405
+ .trim();
406
+ }
407
+ //# sourceMappingURL=domExtractor.js.map
@@ -0,0 +1,5 @@
1
+ export * from './types.js';
2
+ export * from './accessibilityTree.js';
3
+ export * from './domExtractor.js';
4
+ export * from './browserObserver.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,5 @@
1
+ export * from './types.js';
2
+ export * from './accessibilityTree.js';
3
+ export * from './domExtractor.js';
4
+ export * from './browserObserver.js';
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,163 @@
1
+ /**
2
+ * Browser Observation Layer Types & Normalized Interfaces
3
+ *
4
+ * Design Priority:
5
+ * Accessibility/DOM → Semantic Element Info → Visual Understanding → Coordinates
6
+ */
7
+ export interface ElementBounds {
8
+ x: number;
9
+ y: number;
10
+ width: number;
11
+ height: number;
12
+ viewportRelative: boolean;
13
+ }
14
+ export interface ElementState {
15
+ visible: boolean;
16
+ focused: boolean;
17
+ disabled: boolean;
18
+ checked?: boolean | undefined;
19
+ expanded?: boolean | undefined;
20
+ selected?: boolean | undefined;
21
+ readOnly?: boolean | undefined;
22
+ required?: boolean | undefined;
23
+ }
24
+ export interface SemanticElement {
25
+ id: string;
26
+ role: string;
27
+ text: string;
28
+ selector: string;
29
+ bounds: ElementBounds;
30
+ state: ElementState;
31
+ attributes: Record<string, string>;
32
+ tagName: string;
33
+ parentRole?: string | undefined;
34
+ xpath?: string | undefined;
35
+ }
36
+ export interface AccessibilityNode {
37
+ id: string;
38
+ role: string;
39
+ name: string;
40
+ value?: string | undefined;
41
+ description?: string | undefined;
42
+ disabled?: boolean | undefined;
43
+ expanded?: boolean | undefined;
44
+ selected?: boolean | undefined;
45
+ checked?: boolean | undefined;
46
+ focused?: boolean | undefined;
47
+ children?: AccessibilityNode[] | undefined;
48
+ }
49
+ export interface BrowserViewport {
50
+ width: number;
51
+ height: number;
52
+ scrollX: number;
53
+ scrollY: number;
54
+ devicePixelRatio: number;
55
+ }
56
+ export type PageLoadingStatus = 'loading' | 'domcontentloaded' | 'networkidle' | 'complete';
57
+ export interface PageLoadingState {
58
+ status: PageLoadingStatus;
59
+ isBusy: boolean;
60
+ hasActiveSpinners: boolean;
61
+ progressPercent?: number | undefined;
62
+ details?: string | undefined;
63
+ }
64
+ export interface FormFieldObservation {
65
+ id: string;
66
+ name?: string | undefined;
67
+ label?: string | undefined;
68
+ type: string;
69
+ value?: string | undefined;
70
+ placeholder?: string | undefined;
71
+ required: boolean;
72
+ disabled: boolean;
73
+ selector: string;
74
+ }
75
+ export interface FormObservation {
76
+ id: string;
77
+ name?: string | undefined;
78
+ action?: string | undefined;
79
+ method?: string | undefined;
80
+ fields: FormFieldObservation[];
81
+ submitButton?: SemanticElement | undefined;
82
+ selector: string;
83
+ }
84
+ export interface TableRowObservation {
85
+ cells: string[];
86
+ isHeader: boolean;
87
+ }
88
+ export interface TableObservation {
89
+ id: string;
90
+ headers: string[];
91
+ rows: TableRowObservation[];
92
+ rowCount: number;
93
+ columnCount: number;
94
+ caption?: string | undefined;
95
+ selector: string;
96
+ }
97
+ export interface MenuItemObservation {
98
+ id: string;
99
+ text: string;
100
+ role: string;
101
+ href?: string | undefined;
102
+ expanded?: boolean | undefined;
103
+ children?: MenuItemObservation[] | undefined;
104
+ }
105
+ export interface MenuObservation {
106
+ id: string;
107
+ type: 'nav' | 'dropdown' | 'menu' | 'menubar';
108
+ items: MenuItemObservation[];
109
+ selector: string;
110
+ }
111
+ export interface ModalObservation {
112
+ id: string;
113
+ title?: string | undefined;
114
+ role: 'dialog' | 'alertdialog' | 'modal';
115
+ isOpen: boolean;
116
+ isModal: boolean;
117
+ hasBackdrop: boolean;
118
+ primaryActionText?: string | undefined;
119
+ closeButton?: SemanticElement | undefined;
120
+ textSummary: string;
121
+ selector: string;
122
+ }
123
+ export interface BrowserState {
124
+ url: string;
125
+ title: string;
126
+ viewport: BrowserViewport;
127
+ screenshot?: string | undefined;
128
+ elements: SemanticElement[];
129
+ accessibilityTree: AccessibilityNode;
130
+ loadingState: PageLoadingState;
131
+ visibleText: string;
132
+ forms: FormObservation[];
133
+ tables: TableObservation[];
134
+ menus: MenuObservation[];
135
+ modals: ModalObservation[];
136
+ timestamp: number;
137
+ }
138
+ export interface ObservationOptions {
139
+ includeScreenshot?: boolean | undefined;
140
+ includeAccessibilityTree?: boolean | undefined;
141
+ maxElements?: number | undefined;
142
+ viewport?: Partial<BrowserViewport> | undefined;
143
+ filterVisibleOnly?: boolean | undefined;
144
+ }
145
+ export interface IBrowserObserver {
146
+ observe(source?: {
147
+ html?: string;
148
+ url?: string;
149
+ title?: string;
150
+ cdpSession?: any;
151
+ }, options?: ObservationOptions): Promise<BrowserState>;
152
+ getElement(refOrSelector: string): Promise<SemanticElement | null>;
153
+ getElementsByRole(role: string): Promise<SemanticElement[]>;
154
+ getElementsByText(text: string): Promise<SemanticElement[]>;
155
+ getForms(): Promise<FormObservation[]>;
156
+ getTables(): Promise<TableObservation[]>;
157
+ getMenus(): Promise<MenuObservation[]>;
158
+ getModals(): Promise<ModalObservation[]>;
159
+ getLoadingState(): Promise<PageLoadingState>;
160
+ takeScreenshot(fullPage?: boolean): Promise<string>;
161
+ formatObservationForAgent(state?: BrowserState): string;
162
+ }
163
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Browser Observation Layer Types & Normalized Interfaces
3
+ *
4
+ * Design Priority:
5
+ * Accessibility/DOM → Semantic Element Info → Visual Understanding → Coordinates
6
+ */
7
+ export {};
8
+ //# sourceMappingURL=types.js.map
@@ -34,6 +34,37 @@ export interface UIInspectionResult {
34
34
  windows: string[];
35
35
  focusedElement?: string;
36
36
  }
37
+ export type SupportedAppType = 'browser' | 'terminal' | 'editor' | 'file_manager' | 'other';
38
+ export interface ActiveWindowInfo {
39
+ title: string;
40
+ appName: string;
41
+ appType: SupportedAppType;
42
+ bounds?: {
43
+ x: number;
44
+ y: number;
45
+ width: number;
46
+ height: number;
47
+ } | undefined;
48
+ processId?: number | undefined;
49
+ isResponding: boolean;
50
+ }
51
+ export interface DesktopApplicationState {
52
+ appName: string;
53
+ appType: SupportedAppType;
54
+ isRunning: boolean;
55
+ isFocused: boolean;
56
+ windowTitle: string;
57
+ bounds?: {
58
+ x: number;
59
+ y: number;
60
+ width: number;
61
+ height: number;
62
+ } | undefined;
63
+ canAcceptInput: boolean;
64
+ }
65
+ export type DesktopActionRiskLevel = 0 | 1 | 2 | 3;
66
+ export declare function classifyAppType(windowTitleOrApp: string): SupportedAppType;
67
+ export declare function getDesktopActionRiskLevel(action: string): DesktopActionRiskLevel;
37
68
  export interface IComputerController {
38
69
  screenshot(): Promise<ScreenCaptureResult>;
39
70
  click(x: number, y: number, options?: {
@@ -47,15 +78,18 @@ export interface IComputerController {
47
78
  mouseUp(x?: number, y?: number, button?: 'left' | 'right' | 'middle'): Promise<ComputerActionResult>;
48
79
  type(text: string): Promise<ComputerActionResult>;
49
80
  keyPress(key: string): Promise<ComputerActionResult>;
81
+ key_press(key: string): Promise<ComputerActionResult>;
50
82
  hotkey(keys: string[]): Promise<ComputerActionResult>;
51
83
  scroll(deltaX: number, deltaY: number): Promise<ComputerActionResult>;
52
84
  mouseMove(x: number, y: number): Promise<ComputerActionResult>;
53
85
  move(x: number, y: number): Promise<ComputerActionResult>;
86
+ move_mouse(x: number, y: number): Promise<ComputerActionResult>;
54
87
  drag(fromX: number, fromY: number, toX: number, toY: number): Promise<ComputerActionResult>;
55
88
  wait(ms: number): Promise<void>;
56
89
  openApplication(appName: string, args?: string[]): Promise<ComputerActionResult>;
57
90
  closeApplication(appName: string): Promise<ComputerActionResult>;
58
91
  switchWindow(windowTitleOrApp: string): Promise<ComputerActionResult>;
92
+ switch_to_app(appType: SupportedAppType | string): Promise<ComputerActionResult>;
59
93
  getWindowBounds?(windowTitleOrApp: string): Promise<{
60
94
  x: number;
61
95
  y: number;
@@ -63,6 +97,8 @@ export interface IComputerController {
63
97
  height: number;
64
98
  } | null>;
65
99
  inspectUI(): Promise<UIInspectionResult>;
100
+ active_window(): Promise<ActiveWindowInfo>;
101
+ application_state(appName?: string): Promise<DesktopApplicationState[]>;
66
102
  getMousePosition(): Promise<{
67
103
  x: number;
68
104
  y: number;
@@ -105,6 +141,7 @@ export declare class SystemComputerController implements IComputerController {
105
141
  mouseUp(x?: number, y?: number, button?: 'left' | 'right' | 'middle'): Promise<ComputerActionResult>;
106
142
  mouseMove(x: number, y: number): Promise<ComputerActionResult>;
107
143
  move(x: number, y: number): Promise<ComputerActionResult>;
144
+ move_mouse(x: number, y: number): Promise<ComputerActionResult>;
108
145
  drag(startX: number, startY: number, endX: number, endY: number): Promise<ComputerActionResult>;
109
146
  scroll(deltaX: number, deltaY: number): Promise<ComputerActionResult>;
110
147
  getMousePosition(): Promise<{
@@ -114,6 +151,7 @@ export declare class SystemComputerController implements IComputerController {
114
151
  runDiagnostic(): Promise<ComputerActionResult>;
115
152
  type(text: string): Promise<ComputerActionResult>;
116
153
  keyPress(key: string): Promise<ComputerActionResult>;
154
+ key_press(key: string): Promise<ComputerActionResult>;
117
155
  hotkey(keys: string[]): Promise<ComputerActionResult>;
118
156
  wait(ms: number): Promise<void>;
119
157
  resolveCanonicalApp(appName: string, args?: string[]): {
@@ -132,5 +170,10 @@ export declare class SystemComputerController implements IComputerController {
132
170
  height: number;
133
171
  } | null>;
134
172
  inspectUI(): Promise<UIInspectionResult>;
173
+ active_window(): Promise<ActiveWindowInfo>;
174
+ application_state(appName?: string): Promise<DesktopApplicationState[]>;
175
+ switch_to_app(appType: SupportedAppType | string): Promise<ComputerActionResult>;
135
176
  }
177
+ export type ComputerController = IComputerController;
178
+ export declare const ComputerController: typeof SystemComputerController;
136
179
  //# sourceMappingURL=computerController.d.ts.map