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,41 @@
|
|
|
1
|
+
import { type ActionTarget, type RetryPolicy, type WaitCondition } from './types.js';
|
|
2
|
+
import { type SemanticElement, type BrowserState } from '../observer/types.js';
|
|
3
|
+
export declare const DEFAULT_RETRY_POLICY: RetryPolicy;
|
|
4
|
+
/**
|
|
5
|
+
* Normalizes an ActionTarget input from string or structured object.
|
|
6
|
+
*/
|
|
7
|
+
export declare function normalizeActionTarget(target: ActionTarget | string): ActionTarget;
|
|
8
|
+
/**
|
|
9
|
+
* Resolves a target element from the current observed element pool
|
|
10
|
+
* prioritizing Accessibility/DOM -> Semantic Element Info -> Visual -> Coordinates.
|
|
11
|
+
*/
|
|
12
|
+
export declare function resolveTargetElement(targetInput: ActionTarget | string, elements: SemanticElement[]): {
|
|
13
|
+
element: SemanticElement | null;
|
|
14
|
+
strategy: 'ref' | 'selector' | 'role_text' | 'fuzzy_text' | 'coordinates' | 'none';
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Re-locates a stale element across DOM re-renders or page state transitions.
|
|
18
|
+
*/
|
|
19
|
+
export declare function recoverStaleElement(targetInput: ActionTarget | string, staleElement: SemanticElement | null, freshElements: SemanticElement[]): SemanticElement | null;
|
|
20
|
+
/**
|
|
21
|
+
* Evaluates navigation state transitions and popup dialog detections.
|
|
22
|
+
*/
|
|
23
|
+
export declare function detectNavigationAndPopups(beforeState?: BrowserState, afterState?: BrowserState): {
|
|
24
|
+
navigationDetected: boolean;
|
|
25
|
+
popupDetected: boolean;
|
|
26
|
+
newUrl?: string | undefined;
|
|
27
|
+
popupTitle?: string | undefined;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Executes an operation with exponential backoff and retry policy.
|
|
31
|
+
*/
|
|
32
|
+
export declare function withRetry<T>(operation: (attempt: number) => Promise<T>, policy?: Partial<RetryPolicy>): Promise<{
|
|
33
|
+
result: T;
|
|
34
|
+
retries: number;
|
|
35
|
+
recovered: boolean;
|
|
36
|
+
}>;
|
|
37
|
+
/**
|
|
38
|
+
* Handles wait conditions (duration, element presence, network idle, url change).
|
|
39
|
+
*/
|
|
40
|
+
export declare function waitForCondition(condition: WaitCondition, param: any, checkFn: () => Promise<boolean>, timeoutMs?: number): Promise<boolean>;
|
|
41
|
+
//# sourceMappingURL=reliability.d.ts.map
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import {} from './types.js';
|
|
2
|
+
import {} from '../observer/types.js';
|
|
3
|
+
export const DEFAULT_RETRY_POLICY = {
|
|
4
|
+
maxRetries: 3,
|
|
5
|
+
backoffMs: 250,
|
|
6
|
+
exponential: true,
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Normalizes an ActionTarget input from string or structured object.
|
|
10
|
+
*/
|
|
11
|
+
export function normalizeActionTarget(target) {
|
|
12
|
+
if (typeof target === 'string') {
|
|
13
|
+
const trimmed = target.trim();
|
|
14
|
+
if (trimmed.startsWith('@el/')) {
|
|
15
|
+
return { selectorOrRef: trimmed };
|
|
16
|
+
}
|
|
17
|
+
if (trimmed.startsWith('#') || trimmed.startsWith('.') || trimmed.startsWith('[') || trimmed.includes(':')) {
|
|
18
|
+
return { selectorOrRef: trimmed };
|
|
19
|
+
}
|
|
20
|
+
return { text: trimmed, selectorOrRef: trimmed };
|
|
21
|
+
}
|
|
22
|
+
return target;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Resolves a target element from the current observed element pool
|
|
26
|
+
* prioritizing Accessibility/DOM -> Semantic Element Info -> Visual -> Coordinates.
|
|
27
|
+
*/
|
|
28
|
+
export function resolveTargetElement(targetInput, elements) {
|
|
29
|
+
const target = normalizeActionTarget(targetInput);
|
|
30
|
+
// 1. Direct Ref ID match (@el/1, @el/2)
|
|
31
|
+
if (target.selectorOrRef && target.selectorOrRef.startsWith('@el/')) {
|
|
32
|
+
const el = elements.find(e => e.id.toLowerCase() === target.selectorOrRef.toLowerCase());
|
|
33
|
+
if (el)
|
|
34
|
+
return { element: el, strategy: 'ref' };
|
|
35
|
+
}
|
|
36
|
+
// 2. Exact Selector match (#submit-btn, button[name="submit"])
|
|
37
|
+
if (target.selectorOrRef) {
|
|
38
|
+
const query = target.selectorOrRef.trim().toLowerCase();
|
|
39
|
+
const el = elements.find(e => e.selector.toLowerCase() === query ||
|
|
40
|
+
(e.attributes['id'] && `#${e.attributes['id'].toLowerCase()}` === query) ||
|
|
41
|
+
(e.attributes['name'] && e.attributes['name'].toLowerCase() === query) ||
|
|
42
|
+
(e.attributes['data-testid'] && `[data-testid="${e.attributes['data-testid'].toLowerCase()}"]` === query));
|
|
43
|
+
if (el)
|
|
44
|
+
return { element: el, strategy: 'selector' };
|
|
45
|
+
}
|
|
46
|
+
// 3. Accessible Role + Text Match (Highest Semantic Accuracy)
|
|
47
|
+
if (target.role && target.text) {
|
|
48
|
+
const roleQuery = target.role.toLowerCase();
|
|
49
|
+
const textQuery = target.text.toLowerCase();
|
|
50
|
+
const el = elements.find(e => e.role.toLowerCase() === roleQuery &&
|
|
51
|
+
(e.text.toLowerCase().includes(textQuery) || textQuery.includes(e.text.toLowerCase())));
|
|
52
|
+
if (el)
|
|
53
|
+
return { element: el, strategy: 'role_text' };
|
|
54
|
+
}
|
|
55
|
+
// 4. Accessible Text / Substring match
|
|
56
|
+
if (target.text) {
|
|
57
|
+
const textQuery = target.text.toLowerCase();
|
|
58
|
+
const el = elements.find(e => e.text.toLowerCase().includes(textQuery) ||
|
|
59
|
+
(e.attributes['placeholder'] && e.attributes['placeholder'].toLowerCase().includes(textQuery)) ||
|
|
60
|
+
(e.attributes['aria-label'] && e.attributes['aria-label'].toLowerCase().includes(textQuery)) ||
|
|
61
|
+
(e.attributes['value'] && e.attributes['value'].toLowerCase().includes(textQuery)));
|
|
62
|
+
if (el)
|
|
63
|
+
return { element: el, strategy: 'fuzzy_text' };
|
|
64
|
+
}
|
|
65
|
+
// 5. Visual Coordinates Grounding (Fallback when coordinates are provided)
|
|
66
|
+
if (target.coordinates) {
|
|
67
|
+
const { x, y } = target.coordinates;
|
|
68
|
+
const el = elements.find(e => x >= e.bounds.x &&
|
|
69
|
+
x <= e.bounds.x + e.bounds.width &&
|
|
70
|
+
y >= e.bounds.y &&
|
|
71
|
+
y <= e.bounds.y + e.bounds.height);
|
|
72
|
+
if (el)
|
|
73
|
+
return { element: el, strategy: 'coordinates' };
|
|
74
|
+
}
|
|
75
|
+
return { element: null, strategy: 'none' };
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Re-locates a stale element across DOM re-renders or page state transitions.
|
|
79
|
+
*/
|
|
80
|
+
export function recoverStaleElement(targetInput, staleElement, freshElements) {
|
|
81
|
+
// 1. Try resolving using targetInput first
|
|
82
|
+
const direct = resolveTargetElement(targetInput, freshElements);
|
|
83
|
+
if (direct.element)
|
|
84
|
+
return direct.element;
|
|
85
|
+
if (!staleElement)
|
|
86
|
+
return null;
|
|
87
|
+
// 2. Match by exact selector in fresh elements
|
|
88
|
+
const bySelector = freshElements.find(e => e.selector.toLowerCase() === staleElement.selector.toLowerCase());
|
|
89
|
+
if (bySelector)
|
|
90
|
+
return bySelector;
|
|
91
|
+
// 3. Match by role and accessible text
|
|
92
|
+
const byRoleText = freshElements.find(e => e.role === staleElement.role &&
|
|
93
|
+
e.text.toLowerCase() === staleElement.text.toLowerCase());
|
|
94
|
+
if (byRoleText)
|
|
95
|
+
return byRoleText;
|
|
96
|
+
// 4. Match by unique attributes
|
|
97
|
+
const byAttr = freshElements.find(e => (staleElement.attributes['name'] && e.attributes['name'] === staleElement.attributes['name']) ||
|
|
98
|
+
(staleElement.attributes['id'] && e.attributes['id'] === staleElement.attributes['id']) ||
|
|
99
|
+
(staleElement.attributes['data-testid'] && e.attributes['data-testid'] === staleElement.attributes['data-testid']));
|
|
100
|
+
if (byAttr)
|
|
101
|
+
return byAttr;
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Evaluates navigation state transitions and popup dialog detections.
|
|
106
|
+
*/
|
|
107
|
+
export function detectNavigationAndPopups(beforeState, afterState) {
|
|
108
|
+
let navigationDetected = false;
|
|
109
|
+
let popupDetected = false;
|
|
110
|
+
let newUrl;
|
|
111
|
+
let popupTitle;
|
|
112
|
+
if (beforeState && afterState) {
|
|
113
|
+
if (beforeState.url !== afterState.url) {
|
|
114
|
+
navigationDetected = true;
|
|
115
|
+
newUrl = afterState.url;
|
|
116
|
+
}
|
|
117
|
+
const beforeOpenModal = beforeState.modals?.find(m => m.isOpen);
|
|
118
|
+
const afterOpenModal = afterState.modals?.find(m => m.isOpen);
|
|
119
|
+
if (!beforeOpenModal && afterOpenModal) {
|
|
120
|
+
popupDetected = true;
|
|
121
|
+
popupTitle = afterOpenModal.title || afterOpenModal.id;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return { navigationDetected, popupDetected, newUrl, popupTitle };
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Executes an operation with exponential backoff and retry policy.
|
|
128
|
+
*/
|
|
129
|
+
export async function withRetry(operation, policy = {}) {
|
|
130
|
+
const maxRetries = policy.maxRetries ?? DEFAULT_RETRY_POLICY.maxRetries;
|
|
131
|
+
const backoffMs = policy.backoffMs ?? DEFAULT_RETRY_POLICY.backoffMs;
|
|
132
|
+
const exponential = policy.exponential ?? DEFAULT_RETRY_POLICY.exponential;
|
|
133
|
+
let lastError;
|
|
134
|
+
let retries = 0;
|
|
135
|
+
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
|
136
|
+
try {
|
|
137
|
+
const res = await operation(attempt);
|
|
138
|
+
return { result: res, retries, recovered: retries > 0 };
|
|
139
|
+
}
|
|
140
|
+
catch (err) {
|
|
141
|
+
lastError = err;
|
|
142
|
+
retries = attempt;
|
|
143
|
+
if (attempt < maxRetries) {
|
|
144
|
+
const delay = exponential ? backoffMs * Math.pow(2, attempt - 1) : backoffMs;
|
|
145
|
+
await new Promise(r => setTimeout(r, delay));
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
throw lastError;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Handles wait conditions (duration, element presence, network idle, url change).
|
|
153
|
+
*/
|
|
154
|
+
export async function waitForCondition(condition, param, checkFn, timeoutMs = 5000) {
|
|
155
|
+
if (typeof condition === 'number') {
|
|
156
|
+
const ms = Math.max(10, Math.min(condition, 30000));
|
|
157
|
+
await new Promise(r => setTimeout(r, ms));
|
|
158
|
+
return true;
|
|
159
|
+
}
|
|
160
|
+
const startTime = Date.now();
|
|
161
|
+
const interval = 50;
|
|
162
|
+
while (Date.now() - startTime < timeoutMs) {
|
|
163
|
+
const ok = await checkFn();
|
|
164
|
+
if (ok)
|
|
165
|
+
return true;
|
|
166
|
+
await new Promise(r => setTimeout(r, interval));
|
|
167
|
+
}
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
//# sourceMappingURL=reliability.js.map
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { type BrowserState } from '../observer/types.js';
|
|
2
|
+
export interface ActionTarget {
|
|
3
|
+
selectorOrRef?: string | undefined;
|
|
4
|
+
text?: string | undefined;
|
|
5
|
+
role?: string | undefined;
|
|
6
|
+
name?: string | undefined;
|
|
7
|
+
id?: string | undefined;
|
|
8
|
+
coordinates?: {
|
|
9
|
+
x: number;
|
|
10
|
+
y: number;
|
|
11
|
+
} | undefined;
|
|
12
|
+
}
|
|
13
|
+
export interface ActionResult<T = any> {
|
|
14
|
+
success: boolean;
|
|
15
|
+
action: string;
|
|
16
|
+
target?: ActionTarget | string | undefined;
|
|
17
|
+
beforeState?: Partial<BrowserState> | undefined;
|
|
18
|
+
afterState?: Partial<BrowserState> | undefined;
|
|
19
|
+
error?: string | undefined;
|
|
20
|
+
metadata?: Record<string, any> | undefined;
|
|
21
|
+
durationMs: number;
|
|
22
|
+
recovered?: boolean | undefined;
|
|
23
|
+
retries?: number | undefined;
|
|
24
|
+
data?: T | undefined;
|
|
25
|
+
}
|
|
26
|
+
export type WaitCondition = 'load' | 'domcontentloaded' | 'networkidle' | 'element' | 'element_hidden' | 'url_change' | 'title_change' | number;
|
|
27
|
+
export interface RetryPolicy {
|
|
28
|
+
maxRetries: number;
|
|
29
|
+
backoffMs: number;
|
|
30
|
+
exponential?: boolean | undefined;
|
|
31
|
+
}
|
|
32
|
+
export interface IBrowserActionEngine {
|
|
33
|
+
navigate(url: string, htmlContent?: string): Promise<ActionResult>;
|
|
34
|
+
click(target: ActionTarget | string): Promise<ActionResult>;
|
|
35
|
+
type(target: ActionTarget | string, text: string, options?: {
|
|
36
|
+
clear?: boolean;
|
|
37
|
+
delayMs?: number;
|
|
38
|
+
}): Promise<ActionResult>;
|
|
39
|
+
select(target: ActionTarget | string, value: string): Promise<ActionResult>;
|
|
40
|
+
scroll(direction: 'up' | 'down' | 'left' | 'right', amount?: number): Promise<ActionResult>;
|
|
41
|
+
hover(target: ActionTarget | string): Promise<ActionResult>;
|
|
42
|
+
press_key(key: string): Promise<ActionResult>;
|
|
43
|
+
open_tab(url?: string, htmlContent?: string): Promise<ActionResult>;
|
|
44
|
+
close_tab(tabId?: string): Promise<ActionResult>;
|
|
45
|
+
switch_tab(tabId: string): Promise<ActionResult>;
|
|
46
|
+
wait(condition: WaitCondition, param?: any): Promise<ActionResult>;
|
|
47
|
+
upload(target: ActionTarget | string, localFilePath: string): Promise<ActionResult>;
|
|
48
|
+
download(target: ActionTarget | string, destPath?: string): Promise<ActionResult>;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { BrowserObserver, type BrowserState } from './observer/index.js';
|
|
2
|
+
import { BrowserActionEngine } from './actions/index.js';
|
|
1
3
|
export interface BrowserActionResult {
|
|
2
4
|
success: boolean;
|
|
3
5
|
output: string;
|
|
@@ -42,11 +44,15 @@ export interface IBrowserController {
|
|
|
42
44
|
title: string;
|
|
43
45
|
elements: InteractiveElement[];
|
|
44
46
|
summary: string;
|
|
47
|
+
state?: BrowserState | undefined;
|
|
45
48
|
}>;
|
|
46
49
|
get_active_tab(): Promise<BrowserTab | null>;
|
|
47
50
|
get_tabs(): Promise<BrowserTab[]>;
|
|
48
51
|
switch_tab(tabId: string): Promise<BrowserActionResult>;
|
|
49
52
|
close_tab(tabId: string): Promise<BrowserActionResult>;
|
|
53
|
+
observe?(): Promise<BrowserState>;
|
|
54
|
+
getObserver?(): BrowserObserver;
|
|
55
|
+
getActionEngine?(): BrowserActionEngine;
|
|
50
56
|
}
|
|
51
57
|
/**
|
|
52
58
|
* SemanticBrowserController: High-agency DOM-based semantic browser
|
|
@@ -58,7 +64,12 @@ export declare class SemanticBrowserController implements IBrowserController {
|
|
|
58
64
|
private tabHistories;
|
|
59
65
|
private pageCache;
|
|
60
66
|
private workspaceDir;
|
|
67
|
+
private observer;
|
|
68
|
+
private actionEngine;
|
|
61
69
|
constructor(workspaceDir?: string);
|
|
70
|
+
getActionEngine(): BrowserActionEngine;
|
|
71
|
+
getObserver(): BrowserObserver;
|
|
72
|
+
observe(): Promise<BrowserState>;
|
|
62
73
|
navigate(url: string, isHistoryNav?: boolean): Promise<BrowserActionResult>;
|
|
63
74
|
go_back(): Promise<BrowserActionResult>;
|
|
64
75
|
go_forward(): Promise<BrowserActionResult>;
|
|
@@ -77,6 +88,7 @@ export declare class SemanticBrowserController implements IBrowserController {
|
|
|
77
88
|
title: string;
|
|
78
89
|
elements: InteractiveElement[];
|
|
79
90
|
summary: string;
|
|
91
|
+
state?: BrowserState | undefined;
|
|
80
92
|
}>;
|
|
81
93
|
get_active_tab(): Promise<BrowserTab | null>;
|
|
82
94
|
get_tabs(): Promise<BrowserTab[]>;
|
|
@@ -110,7 +122,12 @@ export declare class MockBrowserController implements IBrowserController {
|
|
|
110
122
|
params: any;
|
|
111
123
|
}>;
|
|
112
124
|
private workspaceDir;
|
|
125
|
+
private observer;
|
|
126
|
+
private actionEngine;
|
|
113
127
|
constructor(workspaceDir?: string);
|
|
128
|
+
getActionEngine(): BrowserActionEngine;
|
|
129
|
+
getObserver(): BrowserObserver;
|
|
130
|
+
observe(): Promise<BrowserState>;
|
|
114
131
|
private setupDefaultMockPages;
|
|
115
132
|
navigate(url: string, isHistoryNav?: boolean): Promise<BrowserActionResult>;
|
|
116
133
|
go_back(): Promise<BrowserActionResult>;
|
|
@@ -135,6 +152,7 @@ export declare class MockBrowserController implements IBrowserController {
|
|
|
135
152
|
title: string;
|
|
136
153
|
elements: InteractiveElement[];
|
|
137
154
|
summary: string;
|
|
155
|
+
state?: BrowserState | undefined;
|
|
138
156
|
}>;
|
|
139
157
|
get_active_tab(): Promise<BrowserTab | null>;
|
|
140
158
|
get_tabs(): Promise<BrowserTab[]>;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import path from 'path';
|
|
3
|
+
import { BrowserObserver } from './observer/index.js';
|
|
4
|
+
import { BrowserActionEngine } from './actions/index.js';
|
|
3
5
|
/**
|
|
4
6
|
* SemanticBrowserController: High-agency DOM-based semantic browser
|
|
5
7
|
* that can navigate, inspect interactive elements, extract text, and download files.
|
|
@@ -10,8 +12,12 @@ export class SemanticBrowserController {
|
|
|
10
12
|
tabHistories = new Map();
|
|
11
13
|
pageCache = new Map();
|
|
12
14
|
workspaceDir;
|
|
15
|
+
observer;
|
|
16
|
+
actionEngine;
|
|
13
17
|
constructor(workspaceDir = process.cwd()) {
|
|
14
18
|
this.workspaceDir = workspaceDir;
|
|
19
|
+
this.observer = new BrowserObserver();
|
|
20
|
+
this.actionEngine = new BrowserActionEngine(this.workspaceDir);
|
|
15
21
|
const initialTab = {
|
|
16
22
|
id: 'tab_1',
|
|
17
23
|
url: 'about:blank',
|
|
@@ -21,6 +27,21 @@ export class SemanticBrowserController {
|
|
|
21
27
|
this.activeTabId = initialTab.id;
|
|
22
28
|
this.tabHistories.set(initialTab.id, { past: [], future: [] });
|
|
23
29
|
}
|
|
30
|
+
getActionEngine() {
|
|
31
|
+
return this.actionEngine;
|
|
32
|
+
}
|
|
33
|
+
getObserver() {
|
|
34
|
+
return this.observer;
|
|
35
|
+
}
|
|
36
|
+
async observe() {
|
|
37
|
+
const tab = await this.get_active_tab();
|
|
38
|
+
const cached = tab ? this.pageCache.get(tab.url) : null;
|
|
39
|
+
return this.observer.observe({
|
|
40
|
+
html: cached?.html || '',
|
|
41
|
+
url: tab?.url || 'about:blank',
|
|
42
|
+
title: tab?.title || '',
|
|
43
|
+
});
|
|
44
|
+
}
|
|
24
45
|
async navigate(url, isHistoryNav = false) {
|
|
25
46
|
let cleanUrl = url.trim();
|
|
26
47
|
if (!cleanUrl.startsWith('http://') && !cleanUrl.startsWith('https://') && !cleanUrl.startsWith('about:')) {
|
|
@@ -276,20 +297,15 @@ export class SemanticBrowserController {
|
|
|
276
297
|
if (!cached) {
|
|
277
298
|
return { success: false, url: tab.url, title: tab.title, elements: [], summary: 'Page content not loaded. Call navigate first.' };
|
|
278
299
|
}
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
const extra = el.href ? ` -> ${el.href}` : (el.placeholder ? ` (placeholder: "${el.placeholder}")` : '');
|
|
282
|
-
summary += ` [ref=${el.ref}] <${el.tag}> "${el.text}"${extra}\n`;
|
|
283
|
-
}
|
|
284
|
-
if (cached.elements.length > 30) {
|
|
285
|
-
summary += ` ... and ${cached.elements.length - 30} more elements.\n`;
|
|
286
|
-
}
|
|
300
|
+
const state = await this.observe();
|
|
301
|
+
const summary = this.observer.formatObservationForAgent(state);
|
|
287
302
|
return {
|
|
288
303
|
success: true,
|
|
289
304
|
url: tab.url,
|
|
290
305
|
title: cached.title,
|
|
291
306
|
elements: cached.elements,
|
|
292
307
|
summary,
|
|
308
|
+
state,
|
|
293
309
|
};
|
|
294
310
|
}
|
|
295
311
|
async get_active_tab() {
|
|
@@ -424,10 +440,27 @@ export class MockBrowserController {
|
|
|
424
440
|
downloadedFiles = [];
|
|
425
441
|
actionLog = [];
|
|
426
442
|
workspaceDir;
|
|
443
|
+
observer = new BrowserObserver();
|
|
444
|
+
actionEngine;
|
|
427
445
|
constructor(workspaceDir = process.cwd()) {
|
|
428
446
|
this.workspaceDir = workspaceDir;
|
|
447
|
+
this.actionEngine = new BrowserActionEngine(this.workspaceDir);
|
|
429
448
|
this.setupDefaultMockPages();
|
|
430
449
|
}
|
|
450
|
+
getActionEngine() {
|
|
451
|
+
return this.actionEngine;
|
|
452
|
+
}
|
|
453
|
+
getObserver() {
|
|
454
|
+
return this.observer;
|
|
455
|
+
}
|
|
456
|
+
async observe() {
|
|
457
|
+
const page = this.mockPages.get(this.currentUrl);
|
|
458
|
+
return this.observer.observe({
|
|
459
|
+
html: page?.html || '',
|
|
460
|
+
url: this.currentUrl,
|
|
461
|
+
title: this.currentTitle,
|
|
462
|
+
});
|
|
463
|
+
}
|
|
431
464
|
setupDefaultMockPages() {
|
|
432
465
|
// Mock Page 1: Gmail with Acme Invoice
|
|
433
466
|
this.mockPages.set('https://mail.google.com', {
|
|
@@ -690,16 +723,15 @@ export class MockBrowserController {
|
|
|
690
723
|
html: '<html><body>Mock Page</body></html>',
|
|
691
724
|
elements: [],
|
|
692
725
|
};
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
summary += ` [ref=${el.ref}] <${el.tag}> "${el.text}" (selector: ${el.selector})${el.href ? ` -> ${el.href}` : ''}\n`;
|
|
696
|
-
}
|
|
726
|
+
const state = await this.observe();
|
|
727
|
+
const summary = this.observer.formatObservationForAgent(state);
|
|
697
728
|
return {
|
|
698
729
|
success: true,
|
|
699
730
|
url: this.currentUrl,
|
|
700
731
|
title: page.title,
|
|
701
732
|
elements: page.elements,
|
|
702
733
|
summary,
|
|
734
|
+
state,
|
|
703
735
|
};
|
|
704
736
|
}
|
|
705
737
|
async get_active_tab() {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type AccessibilityNode } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Maps standard HTML tag names and attributes to W3C ARIA roles.
|
|
4
|
+
*/
|
|
5
|
+
export declare function getImplicitAriaRole(tagName: string, attributes: Record<string, string>): string;
|
|
6
|
+
/**
|
|
7
|
+
* Computes accessible name for an element following W3C AccName specification.
|
|
8
|
+
*/
|
|
9
|
+
export declare function computeAccessibleName(tagName: string, attributes: Record<string, string>, innerText: string, idToTextMap: Map<string, string>): string;
|
|
10
|
+
/**
|
|
11
|
+
* Builds a hierarchical AccessibilityNode tree from an HTML string or DOM fragments.
|
|
12
|
+
*/
|
|
13
|
+
export declare function buildAccessibilityTree(html: string): AccessibilityNode;
|
|
14
|
+
//# sourceMappingURL=accessibilityTree.d.ts.map
|