ft-scout 1.0.8 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (243) hide show
  1. package/.firebase/hosting.d2Vi.cache +9 -0
  2. package/.firebaserc +14 -0
  3. package/AUTONOMOUS_FEATURES.md +192 -0
  4. package/README.md +482 -32
  5. package/bin/ft.js +2 -0
  6. package/bin/src/commands/agent.d.ts.map +1 -0
  7. package/bin/src/commands/agent.js +1230 -0
  8. package/bin/src/commands/agent.js.map +1 -0
  9. package/bin/src/commands/audit.d.ts.map +1 -0
  10. package/bin/src/commands/audit.js +104 -0
  11. package/bin/src/commands/audit.js.map +1 -0
  12. package/bin/src/commands/authCommand.d.ts.map +1 -0
  13. package/bin/src/commands/authCommand.js +38 -0
  14. package/bin/src/commands/authCommand.js.map +1 -0
  15. package/bin/src/commands/benchmark.d.ts.map +1 -0
  16. package/bin/src/commands/benchmark.js +135 -0
  17. package/bin/src/commands/benchmark.js.map +1 -0
  18. package/bin/src/commands/brief.d.ts.map +1 -1
  19. package/bin/src/commands/brief.js +28 -19
  20. package/bin/src/commands/brief.js.map +1 -1
  21. package/bin/src/commands/configCommand.d.ts.map +1 -0
  22. package/bin/src/commands/configCommand.js +53 -0
  23. package/bin/src/commands/configCommand.js.map +1 -0
  24. package/bin/src/commands/dashboard.d.ts.map +1 -0
  25. package/bin/src/commands/dashboard.js +41 -0
  26. package/bin/src/commands/dashboard.js.map +1 -0
  27. package/bin/src/commands/history.d.ts.map +1 -0
  28. package/bin/src/commands/history.js +20 -0
  29. package/bin/src/commands/history.js.map +1 -0
  30. package/bin/src/commands/init.d.ts.map +1 -1
  31. package/bin/src/commands/init.js +411 -78
  32. package/bin/src/commands/init.js.map +1 -1
  33. package/bin/src/commands/login.d.ts.map +1 -0
  34. package/bin/src/commands/login.js +190 -0
  35. package/bin/src/commands/login.js.map +1 -0
  36. package/bin/src/commands/logout.d.ts.map +1 -0
  37. package/bin/src/commands/logout.js +15 -0
  38. package/bin/src/commands/logout.js.map +1 -0
  39. package/bin/src/commands/mcp.d.ts.map +1 -0
  40. package/bin/src/commands/mcp.js +393 -0
  41. package/bin/src/commands/mcp.js.map +1 -0
  42. package/bin/src/commands/owners.js +6 -6
  43. package/bin/src/commands/owners.js.map +1 -1
  44. package/bin/src/commands/plan.d.ts.map +1 -0
  45. package/bin/src/commands/plan.js +152 -0
  46. package/bin/src/commands/plan.js.map +1 -0
  47. package/bin/src/commands/quota.d.ts.map +1 -0
  48. package/bin/src/commands/quota.js +32 -0
  49. package/bin/src/commands/quota.js.map +1 -0
  50. package/bin/src/commands/recommend.d.ts.map +1 -0
  51. package/bin/src/commands/recommend.js +46 -0
  52. package/bin/src/commands/recommend.js.map +1 -0
  53. package/bin/src/commands/risky.d.ts.map +1 -1
  54. package/bin/src/commands/risky.js +235 -39
  55. package/bin/src/commands/risky.js.map +1 -1
  56. package/bin/src/commands/setup.d.ts.map +1 -1
  57. package/bin/src/commands/setup.js +411 -16
  58. package/bin/src/commands/setup.js.map +1 -1
  59. package/bin/src/commands/signup.d.ts.map +1 -0
  60. package/bin/src/commands/signup.js +118 -0
  61. package/bin/src/commands/signup.js.map +1 -0
  62. package/bin/src/commands/undo.d.ts.map +1 -0
  63. package/bin/src/commands/undo.js +59 -0
  64. package/bin/src/commands/undo.js.map +1 -0
  65. package/bin/src/commands/web.d.ts.map +1 -0
  66. package/bin/src/commands/web.js +90 -0
  67. package/bin/src/commands/web.js.map +1 -0
  68. package/bin/src/discovery/config.d.ts.map +1 -0
  69. package/bin/src/discovery/config.js +41 -0
  70. package/bin/src/discovery/config.js.map +1 -0
  71. package/bin/src/discovery/display.d.ts.map +1 -0
  72. package/bin/src/discovery/display.js +57 -0
  73. package/bin/src/discovery/display.js.map +1 -0
  74. package/bin/src/discovery/messages.d.ts.map +1 -0
  75. package/bin/src/discovery/messages.js +7 -0
  76. package/bin/src/discovery/messages.js.map +1 -0
  77. package/bin/src/discovery/signals.d.ts.map +1 -0
  78. package/bin/src/discovery/signals.js +33 -0
  79. package/bin/src/discovery/signals.js.map +1 -0
  80. package/bin/src/engine/actionVerifier.d.ts.map +1 -0
  81. package/bin/src/engine/actionVerifier.js +283 -0
  82. package/bin/src/engine/actionVerifier.js.map +1 -0
  83. package/bin/src/engine/agentEngine.d.ts.map +1 -0
  84. package/bin/src/engine/agentEngine.js +2188 -0
  85. package/bin/src/engine/agentEngine.js.map +1 -0
  86. package/bin/src/engine/agentState.d.ts.map +1 -0
  87. package/bin/src/engine/agentState.js +381 -0
  88. package/bin/src/engine/agentState.js.map +1 -0
  89. package/bin/src/engine/browser/browserController.d.ts.map +1 -0
  90. package/bin/src/engine/browser/browserController.js +737 -0
  91. package/bin/src/engine/browser/browserController.js.map +1 -0
  92. package/bin/src/engine/browser/index.d.ts.map +1 -0
  93. package/bin/src/engine/browser/index.js +2 -0
  94. package/bin/src/engine/browser/index.js.map +1 -0
  95. package/bin/src/engine/computer/computerController.d.ts.map +1 -0
  96. package/bin/src/engine/computer/computerController.js +773 -0
  97. package/bin/src/engine/computer/computerController.js.map +1 -0
  98. package/bin/src/engine/computer/computerDiagnostic.d.ts.map +1 -0
  99. package/bin/src/engine/computer/computerDiagnostic.js +71 -0
  100. package/bin/src/engine/computer/computerDiagnostic.js.map +1 -0
  101. package/bin/src/engine/computer/index.d.ts.map +1 -0
  102. package/bin/src/engine/computer/index.js +4 -0
  103. package/bin/src/engine/computer/index.js.map +1 -0
  104. package/bin/src/engine/computer/mockComputer.d.ts.map +1 -0
  105. package/bin/src/engine/computer/mockComputer.js +260 -0
  106. package/bin/src/engine/computer/mockComputer.js.map +1 -0
  107. package/bin/src/engine/computer/scoutDriver.cs +1161 -0
  108. package/bin/src/engine/computer/scout_driver.exe +0 -0
  109. package/bin/src/engine/git.d.ts.map +1 -1
  110. package/bin/src/engine/git.js +71 -0
  111. package/bin/src/engine/git.js.map +1 -1
  112. package/bin/src/engine/llm.d.ts.map +1 -1
  113. package/bin/src/engine/llm.js +1272 -23
  114. package/bin/src/engine/llm.js.map +1 -1
  115. package/bin/src/engine/planner.d.ts.map +1 -0
  116. package/bin/src/engine/planner.js +321 -0
  117. package/bin/src/engine/planner.js.map +1 -0
  118. package/bin/src/engine/runtime/agentRuntime.d.ts.map +1 -0
  119. package/bin/src/engine/runtime/agentRuntime.js +1258 -0
  120. package/bin/src/engine/runtime/agentRuntime.js.map +1 -0
  121. package/bin/src/engine/runtime/index.d.ts.map +1 -0
  122. package/bin/src/engine/runtime/index.js +2 -0
  123. package/bin/src/engine/runtime/index.js.map +1 -0
  124. package/bin/src/engine/safety.d.ts.map +1 -0
  125. package/bin/src/engine/safety.js +316 -0
  126. package/bin/src/engine/safety.js.map +1 -0
  127. package/bin/src/engine/scoutAudioRecorder.cs +215 -0
  128. package/bin/src/engine/scout_audio_recorder.exe +0 -0
  129. package/bin/src/engine/toolRegistry.d.ts.map +1 -0
  130. package/bin/src/engine/toolRegistry.js +521 -0
  131. package/bin/src/engine/toolRegistry.js.map +1 -0
  132. package/bin/src/engine/verifier.d.ts.map +1 -0
  133. package/bin/src/engine/verifier.js +414 -0
  134. package/bin/src/engine/verifier.js.map +1 -0
  135. package/bin/src/engine/voiceEngine.d.ts.map +1 -0
  136. package/bin/src/engine/voiceEngine.js +474 -0
  137. package/bin/src/engine/voiceEngine.js.map +1 -0
  138. package/bin/src/engine/web.d.ts.map +1 -0
  139. package/bin/src/engine/web.js +161 -0
  140. package/bin/src/engine/web.js.map +1 -0
  141. package/bin/src/engine/workspace/agentWorkspace.d.ts.map +1 -0
  142. package/bin/src/engine/workspace/agentWorkspace.js +505 -0
  143. package/bin/src/engine/workspace/agentWorkspace.js.map +1 -0
  144. package/bin/src/engine/workspace/index.d.ts.map +1 -0
  145. package/bin/src/engine/workspace/index.js +2 -0
  146. package/bin/src/engine/workspace/index.js.map +1 -0
  147. package/bin/src/index.js +365 -23
  148. package/bin/src/index.js.map +1 -1
  149. package/bin/src/mcp/client.d.ts.map +1 -0
  150. package/bin/src/mcp/client.js +127 -0
  151. package/bin/src/mcp/client.js.map +1 -0
  152. package/bin/src/mcp/discovery.d.ts.map +1 -0
  153. package/bin/src/mcp/discovery.js +91 -0
  154. package/bin/src/mcp/discovery.js.map +1 -0
  155. package/bin/src/mcp/health.d.ts.map +1 -0
  156. package/bin/src/mcp/health.js +44 -0
  157. package/bin/src/mcp/health.js.map +1 -0
  158. package/bin/src/mcp/index.d.ts.map +1 -0
  159. package/bin/src/mcp/index.js +15 -0
  160. package/bin/src/mcp/index.js.map +1 -0
  161. package/bin/src/mcp/manager.d.ts.map +1 -0
  162. package/bin/src/mcp/manager.js +648 -0
  163. package/bin/src/mcp/manager.js.map +1 -0
  164. package/bin/src/mcp/permissions.d.ts.map +1 -0
  165. package/bin/src/mcp/permissions.js +50 -0
  166. package/bin/src/mcp/permissions.js.map +1 -0
  167. package/bin/src/mcp/persistence.d.ts.map +1 -0
  168. package/bin/src/mcp/persistence.js +171 -0
  169. package/bin/src/mcp/persistence.js.map +1 -0
  170. package/bin/src/mcp/recovery.d.ts.map +1 -0
  171. package/bin/src/mcp/recovery.js +75 -0
  172. package/bin/src/mcp/recovery.js.map +1 -0
  173. package/bin/src/mcp/telemetry.d.ts.map +1 -0
  174. package/bin/src/mcp/telemetry.js +82 -0
  175. package/bin/src/mcp/telemetry.js.map +1 -0
  176. package/bin/src/mcp/toolRouter.d.ts.map +1 -0
  177. package/bin/src/mcp/toolRouter.js +127 -0
  178. package/bin/src/mcp/toolRouter.js.map +1 -0
  179. package/bin/src/mcp/transport.d.ts.map +1 -0
  180. package/bin/src/mcp/transport.js +328 -0
  181. package/bin/src/mcp/transport.js.map +1 -0
  182. package/bin/src/mcp/types.d.ts.map +1 -0
  183. package/bin/src/mcp/types.js +6 -0
  184. package/bin/src/mcp/types.js.map +1 -0
  185. package/bin/src/server/server.d.ts.map +1 -0
  186. package/bin/src/server/server.js +989 -0
  187. package/bin/src/server/server.js.map +1 -0
  188. package/bin/src/utils/admin.d.ts.map +1 -0
  189. package/bin/src/utils/admin.js +231 -0
  190. package/bin/src/utils/admin.js.map +1 -0
  191. package/bin/src/utils/auditLogger.d.ts.map +1 -0
  192. package/bin/src/utils/auditLogger.js +70 -0
  193. package/bin/src/utils/auditLogger.js.map +1 -0
  194. package/bin/src/utils/auth.d.ts.map +1 -0
  195. package/bin/src/utils/auth.js +679 -0
  196. package/bin/src/utils/auth.js.map +1 -0
  197. package/bin/src/utils/branding.d.ts.map +1 -0
  198. package/bin/src/utils/branding.js +14 -0
  199. package/bin/src/utils/branding.js.map +1 -0
  200. package/bin/src/utils/config.d.ts.map +1 -1
  201. package/bin/src/utils/config.js +124 -3
  202. package/bin/src/utils/config.js.map +1 -1
  203. package/bin/src/utils/email.d.ts.map +1 -0
  204. package/bin/src/utils/email.js +267 -0
  205. package/bin/src/utils/email.js.map +1 -0
  206. package/bin/src/utils/firebaseAuth.d.ts.map +1 -0
  207. package/bin/src/utils/firebaseAuth.js +174 -0
  208. package/bin/src/utils/firebaseAuth.js.map +1 -0
  209. package/bin/src/utils/holoseneAuth.d.ts.map +1 -0
  210. package/bin/src/utils/holoseneAuth.js +307 -0
  211. package/bin/src/utils/holoseneAuth.js.map +1 -0
  212. package/bin/src/utils/language.d.ts.map +1 -0
  213. package/bin/src/utils/language.js +181 -0
  214. package/bin/src/utils/language.js.map +1 -0
  215. package/bin/src/utils/markdown.d.ts.map +1 -0
  216. package/bin/src/utils/markdown.js +215 -0
  217. package/bin/src/utils/markdown.js.map +1 -0
  218. package/bin/src/utils/payment.d.ts.map +1 -0
  219. package/bin/src/utils/payment.js +290 -0
  220. package/bin/src/utils/payment.js.map +1 -0
  221. package/bin/src/utils/pricing.d.ts.map +1 -0
  222. package/bin/src/utils/pricing.js +165 -0
  223. package/bin/src/utils/pricing.js.map +1 -0
  224. package/bin/src/utils/razorpay.d.ts.map +1 -0
  225. package/bin/src/utils/razorpay.js +144 -0
  226. package/bin/src/utils/razorpay.js.map +1 -0
  227. package/bin/src/utils/session.d.ts.map +1 -0
  228. package/bin/src/utils/session.js +82 -0
  229. package/bin/src/utils/session.js.map +1 -0
  230. package/bin/src/utils/updateCheck.d.ts.map +1 -0
  231. package/bin/src/utils/updateCheck.js +108 -0
  232. package/bin/src/utils/updateCheck.js.map +1 -0
  233. package/downloads/invoice-2026-03.pdf +1 -0
  234. package/firebase.json +74 -0
  235. package/package.json +49 -46
  236. package/web/ScoutFavicon.png +0 -0
  237. package/web/app.js +3944 -0
  238. package/web/styles.css +3081 -0
  239. package/.ft/context.json +0 -18
  240. package/email-template.html +0 -223
  241. package/email-template.txt +0 -45
  242. package/scripts/send-brevo-campaign.cjs +0 -167
  243. package/scripts/send-email.js +0 -77
@@ -0,0 +1,737 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ /**
4
+ * SemanticBrowserController: High-agency DOM-based semantic browser
5
+ * that can navigate, inspect interactive elements, extract text, and download files.
6
+ */
7
+ export class SemanticBrowserController {
8
+ tabs = [];
9
+ activeTabId = '';
10
+ tabHistories = new Map();
11
+ pageCache = new Map();
12
+ workspaceDir;
13
+ constructor(workspaceDir = process.cwd()) {
14
+ this.workspaceDir = workspaceDir;
15
+ const initialTab = {
16
+ id: 'tab_1',
17
+ url: 'about:blank',
18
+ title: 'New Tab',
19
+ };
20
+ this.tabs.push(initialTab);
21
+ this.activeTabId = initialTab.id;
22
+ this.tabHistories.set(initialTab.id, { past: [], future: [] });
23
+ }
24
+ async navigate(url, isHistoryNav = false) {
25
+ let cleanUrl = url.trim();
26
+ if (!cleanUrl.startsWith('http://') && !cleanUrl.startsWith('https://') && !cleanUrl.startsWith('about:')) {
27
+ cleanUrl = `https://${cleanUrl}`;
28
+ }
29
+ const activeTab = await this.get_active_tab();
30
+ if (!activeTab) {
31
+ const newTab = { id: `tab_${Date.now()}`, url: cleanUrl, title: 'Loading...' };
32
+ this.tabs.push(newTab);
33
+ this.activeTabId = newTab.id;
34
+ this.tabHistories.set(newTab.id, { past: [], future: [] });
35
+ }
36
+ else {
37
+ const hist = this.tabHistories.get(activeTab.id);
38
+ if (!isHistoryNav && hist && activeTab.url !== 'about:blank' && activeTab.url !== cleanUrl) {
39
+ hist.past.push(activeTab.url);
40
+ hist.future = [];
41
+ }
42
+ activeTab.url = cleanUrl;
43
+ }
44
+ try {
45
+ const res = await fetch(cleanUrl, {
46
+ headers: { 'User-Agent': 'Scout-Autonomous-Browser/9.0' },
47
+ signal: AbortSignal.timeout(15000),
48
+ });
49
+ if (!res.ok) {
50
+ return {
51
+ success: false,
52
+ output: `HTTP error ${res.status}: ${res.statusText} navigating to ${cleanUrl}`,
53
+ url: cleanUrl,
54
+ };
55
+ }
56
+ const html = await res.text();
57
+ const titleMatch = html.match(/<title[^>]*>([\s\S]*?)<\/title>/i);
58
+ const title = titleMatch && titleMatch[1] ? titleMatch[1].trim() : cleanUrl;
59
+ const curTab = await this.get_active_tab();
60
+ if (curTab)
61
+ curTab.title = title;
62
+ const elements = this.parseInteractiveElements(html);
63
+ this.pageCache.set(cleanUrl, { html, title, elements });
64
+ return {
65
+ success: true,
66
+ output: `Navigated to "${cleanUrl}". Page title: "${title}". Found ${elements.length} interactive elements.`,
67
+ url: cleanUrl,
68
+ title,
69
+ details: { statusCode: res.status, interactiveElementsCount: elements.length },
70
+ };
71
+ }
72
+ catch (err) {
73
+ return {
74
+ success: false,
75
+ output: `Failed to load "${cleanUrl}": ${err.message}`,
76
+ url: cleanUrl,
77
+ };
78
+ }
79
+ }
80
+ async go_back() {
81
+ const tab = await this.get_active_tab();
82
+ if (!tab)
83
+ return { success: false, output: 'No active tab.' };
84
+ const hist = this.tabHistories.get(tab.id);
85
+ if (!hist || hist.past.length === 0) {
86
+ return { success: false, output: 'No back history for this tab.' };
87
+ }
88
+ hist.future.push(tab.url);
89
+ const prevUrl = hist.past.pop();
90
+ return await this.navigate(prevUrl, true);
91
+ }
92
+ async go_forward() {
93
+ const tab = await this.get_active_tab();
94
+ if (!tab)
95
+ return { success: false, output: 'No active tab.' };
96
+ const hist = this.tabHistories.get(tab.id);
97
+ if (!hist || hist.future.length === 0) {
98
+ return { success: false, output: 'No forward history for this tab.' };
99
+ }
100
+ hist.past.push(tab.url);
101
+ const nextUrl = hist.future.pop();
102
+ return await this.navigate(nextUrl, true);
103
+ }
104
+ async refresh() {
105
+ const tab = await this.get_active_tab();
106
+ if (!tab || tab.url === 'about:blank')
107
+ return { success: false, output: 'No URL to refresh.' };
108
+ return await this.navigate(tab.url);
109
+ }
110
+ async screenshot() {
111
+ const tab = await this.get_active_tab();
112
+ return {
113
+ success: true,
114
+ output: `Visual frame captured for page "${tab?.title || 'Unknown'}" at ${tab?.url || 'about:blank'}`,
115
+ url: tab?.url,
116
+ title: tab?.title,
117
+ };
118
+ }
119
+ async click(selectorOrText) {
120
+ const tab = await this.get_active_tab();
121
+ if (!tab)
122
+ return { success: false, output: 'No active tab.' };
123
+ const cached = this.pageCache.get(tab.url);
124
+ if (!cached)
125
+ return { success: false, output: 'No page content loaded to click.' };
126
+ const target = selectorOrText.toLowerCase().trim();
127
+ const el = cached.elements.find((e) => e.selector.toLowerCase() === target ||
128
+ e.text.toLowerCase().includes(target) ||
129
+ (e.id && e.id.toLowerCase() === target) ||
130
+ `[ref=${e.ref}]` === target);
131
+ if (!el) {
132
+ return {
133
+ success: false,
134
+ output: `Element not found matching "${selectorOrText}". Call inspect_page to see interactive elements.`,
135
+ };
136
+ }
137
+ if (el.href) {
138
+ const resolved = new URL(el.href, tab.url).toString();
139
+ return await this.navigate(resolved);
140
+ }
141
+ return {
142
+ success: true,
143
+ output: `Clicked element [ref=${el.ref}] <${el.tag}> "${el.text}" (selector: ${el.selector})`,
144
+ details: { element: el },
145
+ };
146
+ }
147
+ async type(selectorOrText, text) {
148
+ const tab = await this.get_active_tab();
149
+ if (!tab)
150
+ return { success: false, output: 'No active tab.' };
151
+ const cached = this.pageCache.get(tab.url);
152
+ if (!cached)
153
+ return { success: false, output: 'No page content loaded to type into.' };
154
+ const target = selectorOrText.toLowerCase().trim();
155
+ const isInput = (e) => e.tag === 'input' || e.tag === 'textarea';
156
+ let el = cached.elements.find((e) => isInput(e) && (e.selector.toLowerCase() === target ||
157
+ `[ref=${e.ref}]` === target ||
158
+ (e.id && e.id.toLowerCase() === target) ||
159
+ (e.name && e.name.toLowerCase() === target) ||
160
+ (e.placeholder && e.placeholder.toLowerCase().includes(target)) ||
161
+ (e.text && e.text.toLowerCase().includes(target))));
162
+ if (!el) {
163
+ el = cached.elements.find((e) => e.selector.toLowerCase() === target ||
164
+ `[ref=${e.ref}]` === target ||
165
+ (e.id && e.id.toLowerCase() === target));
166
+ }
167
+ if (el) {
168
+ el.value = text;
169
+ return {
170
+ success: true,
171
+ output: `Typed "${text}" into input [ref=${el.ref}] <${el.tag}> (${el.placeholder || el.name || el.selector})`,
172
+ details: { element: el, value: text },
173
+ };
174
+ }
175
+ return {
176
+ success: false,
177
+ output: `Input field matching "${selectorOrText}" not found.`,
178
+ };
179
+ }
180
+ async select(selector, value) {
181
+ return {
182
+ success: true,
183
+ output: `Selected option "${value}" for selector "${selector}".`,
184
+ details: { selector, value },
185
+ };
186
+ }
187
+ async scroll(direction, amount = 4) {
188
+ return {
189
+ success: true,
190
+ output: `Scrolled page ${direction} by ${amount} units.`,
191
+ details: { direction, amount },
192
+ };
193
+ }
194
+ async extract_content(selector) {
195
+ const tab = await this.get_active_tab();
196
+ if (!tab)
197
+ return { success: false, output: 'No active tab.' };
198
+ const cached = this.pageCache.get(tab.url);
199
+ if (!cached)
200
+ return { success: false, output: 'No page content loaded.' };
201
+ let cleanText = cached.html
202
+ .replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, '')
203
+ .replace(/<style\b[^<]*(?:(?!<\/style>)<[^<]*)*<\/style>/gi, '')
204
+ .replace(/<[^>]+>/g, ' ')
205
+ .replace(/\s+/g, ' ')
206
+ .trim();
207
+ const preview = cleanText.slice(0, 5000);
208
+ return {
209
+ success: true,
210
+ output: preview,
211
+ title: cached.title,
212
+ url: tab.url,
213
+ details: { totalLength: cleanText.length },
214
+ };
215
+ }
216
+ async download_file(urlOrSelector, destPath) {
217
+ const tab = await this.get_active_tab();
218
+ let targetUrl = urlOrSelector;
219
+ if (!targetUrl.startsWith('http://') && !targetUrl.startsWith('https://')) {
220
+ const cached = tab ? this.pageCache.get(tab.url) : null;
221
+ if (cached) {
222
+ const el = cached.elements.find((e) => e.href && (e.text.toLowerCase().includes(urlOrSelector.toLowerCase()) || e.selector === urlOrSelector));
223
+ if (el && el.href) {
224
+ targetUrl = new URL(el.href, tab.url).toString();
225
+ }
226
+ }
227
+ }
228
+ if (!targetUrl.startsWith('http://') && !targetUrl.startsWith('https://')) {
229
+ return {
230
+ success: false,
231
+ output: `Cannot download: "${urlOrSelector}" is not a valid download URL or element link.`,
232
+ };
233
+ }
234
+ try {
235
+ const res = await fetch(targetUrl);
236
+ if (!res.ok) {
237
+ return { success: false, output: `Download failed with HTTP ${res.status}: ${res.statusText}` };
238
+ }
239
+ const buffer = Buffer.from(await res.arrayBuffer());
240
+ const fileName = path.basename(new URL(targetUrl).pathname) || `download_${Date.now()}.dat`;
241
+ const finalPath = destPath
242
+ ? (path.isAbsolute(destPath) ? destPath : path.resolve(this.workspaceDir, destPath))
243
+ : path.resolve(this.workspaceDir, 'downloads', fileName);
244
+ fs.mkdirSync(path.dirname(finalPath), { recursive: true });
245
+ fs.writeFileSync(finalPath, buffer);
246
+ return {
247
+ success: true,
248
+ output: `Downloaded file from ${targetUrl} to "${finalPath}" (${buffer.length} bytes).`,
249
+ details: { path: finalPath, sizeBytes: buffer.length, filename: fileName },
250
+ };
251
+ }
252
+ catch (err) {
253
+ return {
254
+ success: false,
255
+ output: `Download error: ${err.message}`,
256
+ };
257
+ }
258
+ }
259
+ async upload_file(selector, filePath) {
260
+ const fullP = path.isAbsolute(filePath) ? filePath : path.resolve(this.workspaceDir, filePath);
261
+ if (!fs.existsSync(fullP)) {
262
+ return { success: false, output: `Upload error: File not found at "${filePath}".` };
263
+ }
264
+ return {
265
+ success: true,
266
+ output: `Selected file "${filePath}" for input "${selector}".`,
267
+ details: { selector, filePath: fullP },
268
+ };
269
+ }
270
+ async inspect_page() {
271
+ const tab = await this.get_active_tab();
272
+ if (!tab) {
273
+ return { success: false, url: '', title: '', elements: [], summary: 'No active tab.' };
274
+ }
275
+ const cached = this.pageCache.get(tab.url);
276
+ if (!cached) {
277
+ return { success: false, url: tab.url, title: tab.title, elements: [], summary: 'Page content not loaded. Call navigate first.' };
278
+ }
279
+ let summary = `Page: "${cached.title}" (${tab.url})\nInteractive elements (${cached.elements.length}):\n`;
280
+ for (const el of cached.elements.slice(0, 30)) {
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
+ }
287
+ return {
288
+ success: true,
289
+ url: tab.url,
290
+ title: cached.title,
291
+ elements: cached.elements,
292
+ summary,
293
+ };
294
+ }
295
+ async get_active_tab() {
296
+ return this.tabs.find((t) => t.id === this.activeTabId) || this.tabs[0] || null;
297
+ }
298
+ async get_tabs() {
299
+ return [...this.tabs];
300
+ }
301
+ async switch_tab(tabId) {
302
+ const tab = this.tabs.find((t) => t.id === tabId);
303
+ if (tab) {
304
+ this.activeTabId = tab.id;
305
+ return { success: true, output: `Switched to tab "${tab.title}" (${tab.url})`, details: { tab } };
306
+ }
307
+ return { success: false, output: `Tab ID "${tabId}" not found.` };
308
+ }
309
+ async close_tab(tabId) {
310
+ const idx = this.tabs.findIndex((t) => t.id === tabId);
311
+ if (idx !== -1) {
312
+ this.tabs.splice(idx, 1);
313
+ if (this.activeTabId === tabId) {
314
+ this.activeTabId = this.tabs[0]?.id || '';
315
+ }
316
+ return { success: true, output: `Closed tab "${tabId}".` };
317
+ }
318
+ return { success: false, output: `Tab ID "${tabId}" not found.` };
319
+ }
320
+ parseInteractiveElements(html) {
321
+ const elements = [];
322
+ let refCounter = 1;
323
+ // Extract <a> tags
324
+ const linkMatches = html.matchAll(/<a\b([^>]*)>([\s\S]*?)<\/a>/gi);
325
+ for (const match of linkMatches) {
326
+ const attrs = match[1] || '';
327
+ const rawText = (match[2] || '').replace(/<[^>]+>/g, ' ').trim();
328
+ const hrefMatch = attrs.match(/href=["']([^"']+)["']/i);
329
+ const idMatch = attrs.match(/id=["']([^"']+)["']/i);
330
+ if (rawText || hrefMatch) {
331
+ elements.push({
332
+ ref: refCounter++,
333
+ tag: 'a',
334
+ text: rawText || 'Link',
335
+ href: hrefMatch ? hrefMatch[1] : undefined,
336
+ id: idMatch ? idMatch[1] : undefined,
337
+ selector: idMatch ? `#${idMatch[1]}` : `a:contains("${(rawText || '').slice(0, 20)}")`,
338
+ });
339
+ }
340
+ }
341
+ // Extract <button> tags
342
+ const buttonMatches = html.matchAll(/<button\b([^>]*)>([\s\S]*?)<\/button>/gi);
343
+ for (const match of buttonMatches) {
344
+ const attrs = match[1] || '';
345
+ const rawText = (match[2] || '').replace(/<[^>]+>/g, ' ').trim();
346
+ const idMatch = attrs.match(/id=["']([^"']+)["']/i);
347
+ elements.push({
348
+ ref: refCounter++,
349
+ tag: 'button',
350
+ text: rawText || 'Button',
351
+ id: idMatch ? idMatch[1] : undefined,
352
+ selector: idMatch ? `#${idMatch[1]}` : `button:contains("${(rawText || '').slice(0, 20)}")`,
353
+ });
354
+ }
355
+ // Extract <input> tags
356
+ const inputMatches = html.matchAll(/<input\b([^>]*)>/gi);
357
+ for (const match of inputMatches) {
358
+ const attrs = match[1] || '';
359
+ const typeMatch = attrs.match(/type=["']([^"']+)["']/i);
360
+ const nameMatch = attrs.match(/name=["']([^"']+)["']/i);
361
+ const idMatch = attrs.match(/id=["']([^"']+)["']/i);
362
+ const placeholderMatch = attrs.match(/placeholder=["']([^"']+)["']/i);
363
+ const valueMatch = attrs.match(/value=["']([^"']+)["']/i);
364
+ elements.push({
365
+ ref: refCounter++,
366
+ tag: 'input',
367
+ type: typeMatch ? typeMatch[1] : 'text',
368
+ name: nameMatch ? nameMatch[1] : undefined,
369
+ id: idMatch ? idMatch[1] : undefined,
370
+ placeholder: placeholderMatch ? placeholderMatch[1] : undefined,
371
+ value: valueMatch ? valueMatch[1] : undefined,
372
+ text: (placeholderMatch && placeholderMatch[1]) || (nameMatch && nameMatch[1]) || 'Input',
373
+ selector: idMatch ? `#${idMatch[1]}` : (nameMatch ? `input[name="${nameMatch[1]}"]` : 'input'),
374
+ });
375
+ }
376
+ // Extract <textarea> tags
377
+ const textareaMatches = html.matchAll(/<textarea\b([^>]*)>([\s\S]*?)<\/textarea>/gi);
378
+ for (const match of textareaMatches) {
379
+ const attrs = match[1] || '';
380
+ const rawText = (match[2] || '').trim();
381
+ const nameMatch = attrs.match(/name=["']([^"']+)["']/i);
382
+ const idMatch = attrs.match(/id=["']([^"']+)["']/i);
383
+ const placeholderMatch = attrs.match(/placeholder=["']([^"']+)["']/i);
384
+ elements.push({
385
+ ref: refCounter++,
386
+ tag: 'textarea',
387
+ name: nameMatch ? nameMatch[1] : undefined,
388
+ id: idMatch ? idMatch[1] : undefined,
389
+ placeholder: placeholderMatch ? placeholderMatch[1] : undefined,
390
+ value: rawText || undefined,
391
+ text: (placeholderMatch && placeholderMatch[1]) || (nameMatch && nameMatch[1]) || rawText || 'Textarea',
392
+ selector: idMatch ? `#${idMatch[1]}` : (nameMatch ? `textarea[name="${nameMatch[1]}"]` : 'textarea'),
393
+ });
394
+ }
395
+ // Extract <select> tags
396
+ const selectMatches = html.matchAll(/<select\b([^>]*)>([\s\S]*?)<\/select>/gi);
397
+ for (const match of selectMatches) {
398
+ const attrs = match[1] || '';
399
+ const nameMatch = attrs.match(/name=["']([^"']+)["']/i);
400
+ const idMatch = attrs.match(/id=["']([^"']+)["']/i);
401
+ elements.push({
402
+ ref: refCounter++,
403
+ tag: 'select',
404
+ name: nameMatch ? nameMatch[1] : undefined,
405
+ id: idMatch ? idMatch[1] : undefined,
406
+ text: (nameMatch && nameMatch[1]) || (idMatch && idMatch[1]) || 'Select',
407
+ selector: idMatch ? `#${idMatch[1]}` : (nameMatch ? `select[name="${nameMatch[1]}"]` : 'select'),
408
+ });
409
+ }
410
+ return elements;
411
+ }
412
+ }
413
+ /**
414
+ * MockBrowserController: Fast, deterministic in-memory browser controller
415
+ * with pre-configured simulated pages (e.g. Gmail with Acme invoice, competitor site)
416
+ * for 100% reliable offline testing and scenario validation.
417
+ */
418
+ export class MockBrowserController {
419
+ currentUrl = 'about:blank';
420
+ currentTitle = 'New Tab';
421
+ historyPast = [];
422
+ historyFuture = [];
423
+ mockPages = new Map();
424
+ downloadedFiles = [];
425
+ actionLog = [];
426
+ workspaceDir;
427
+ constructor(workspaceDir = process.cwd()) {
428
+ this.workspaceDir = workspaceDir;
429
+ this.setupDefaultMockPages();
430
+ }
431
+ setupDefaultMockPages() {
432
+ // Mock Page 1: Gmail with Acme Invoice
433
+ this.mockPages.set('https://mail.google.com', {
434
+ title: 'Gmail - Inbox',
435
+ html: `<html><head><title>Gmail - Inbox</title></head><body>
436
+ <h1>Inbox</h1>
437
+ <div class="email-row" id="email-acme">
438
+ <span class="sender">billing@acme.corp</span>
439
+ <span class="subject">Latest Invoice #INV-2026-991 from Acme Corp</span>
440
+ <a href="https://mail.google.com/email/acme-991" id="link-open-acme">Open Email</a>
441
+ </div>
442
+ </body></html>`,
443
+ elements: [
444
+ { ref: 1, tag: 'a', text: 'Open Email', href: 'https://mail.google.com/email/acme-991', id: 'link-open-acme', selector: '#link-open-acme' },
445
+ ],
446
+ });
447
+ this.mockPages.set('https://mail.google.com/email/acme-991', {
448
+ title: 'Invoice #INV-2026-991 - Acme Corp',
449
+ html: `<html><head><title>Invoice #INV-2026-991 - Acme Corp</title></head><body>
450
+ <h2>Invoice Details</h2>
451
+ <p>Please find attached your invoice for September 2026.</p>
452
+ <div class="attachment" id="acme-invoice-attachment">
453
+ <span>Acme_Invoice_INV-2026-991.pdf (245 KB)</span>
454
+ <a href="https://acme.corp/downloads/invoice-2026-991.pdf" id="btn-download-invoice">Download Invoice</a>
455
+ </div>
456
+ </body></html>`,
457
+ elements: [
458
+ { ref: 1, tag: 'a', text: 'Download Invoice', href: 'https://acme.corp/downloads/invoice-2026-991.pdf', id: 'btn-download-invoice', selector: '#btn-download-invoice' },
459
+ ],
460
+ files: {
461
+ 'https://acme.corp/downloads/invoice-2026-991.pdf': '%PDF-1.4 Mock Invoice Acme Corp #INV-2026-991 Amount Due: $1,250.00 Date: 2026-09-12',
462
+ },
463
+ });
464
+ // Mock Page 2: Competitor Research Site
465
+ this.mockPages.set('https://acme-competitor.com', {
466
+ title: 'Acme Competitor - Cloud AI & Developer Intelligence',
467
+ html: `<html><head><title>Acme Competitor - Cloud AI & Developer Intelligence</title></head><body>
468
+ <h1>About Acme Competitor</h1>
469
+ <p>Acme Competitor is a leading provider of Autonomous AI Co-Pilots, founded in 2023 with $45M Series B funding. Key products include Cloud IDE, Code Auto-Repair, and Screen Automation.</p>
470
+ <table id="company-stats">
471
+ <tr><th>Metric</th><th>Value</th></tr>
472
+ <tr><td>Headquarters</td><td>San Francisco, CA</td></tr>
473
+ <tr><td>Employees</td><td>180</td></tr>
474
+ <tr><td>Valuation</td><td>$320M</td></tr>
475
+ </table>
476
+ </body></html>`,
477
+ elements: [
478
+ { ref: 1, tag: 'a', text: 'Products', href: 'https://acme-competitor.com/products', selector: 'a[href="/products"]' },
479
+ { ref: 2, tag: 'button', text: 'Contact Sales', selector: '#btn-contact' },
480
+ ],
481
+ });
482
+ // Mock Page 3: Competitor Pricing Portal
483
+ this.mockPages.set('https://competitor.example.com', {
484
+ title: 'Competitor Intelligence Portal',
485
+ html: `<html><head><title>Competitor Intelligence Portal</title></head><body>
486
+ <h1>Competitor Pricing & Tiers</h1>
487
+ <table class="pricing-table">
488
+ <tr><th>Tier</th><th>Price</th><th>Features</th></tr>
489
+ <tr><td>Starter</td><td>$29/mo</td><td>1 user, 10 tasks</td></tr>
490
+ <tr><td>Pro</td><td>$99/mo</td><td>5 users, unlimited tasks</td></tr>
491
+ <tr><td>Enterprise</td><td>$499/mo</td><td>Dedicated SLA, custom AI models</td></tr>
492
+ </table>
493
+ <button class="btn-signup-pro">Sign Up Pro</button>
494
+ </body></html>`,
495
+ elements: [
496
+ { ref: 1, tag: 'table', text: 'Pricing Tiers: Starter ($29/mo), Pro ($99/mo), Enterprise ($499/mo)', selector: 'table.pricing-table' },
497
+ { ref: 2, tag: 'button', text: 'Sign Up Pro', selector: 'button.btn-signup-pro' },
498
+ ],
499
+ });
500
+ // Mock Page 4: Vendor Invoices Portal
501
+ this.mockPages.set('https://portal.example.com/invoices', {
502
+ title: 'Vendor Invoices Portal',
503
+ html: `<html><head><title>Vendor Invoices Portal</title></head><body>
504
+ <h1>Vendor Invoices</h1>
505
+ <a class="download-invoice-btn" href="https://portal.example.com/downloads/INVOICE_2026_ACME.pdf">Download Invoice</a>
506
+ </body></html>`,
507
+ elements: [
508
+ { ref: 1, tag: 'a', text: 'Download Monthly Invoice', href: 'https://portal.example.com/downloads/INVOICE_2026_ACME.pdf', selector: 'a.download-invoice-btn' },
509
+ ],
510
+ files: {
511
+ 'https://portal.example.com/downloads/INVOICE_2026_ACME.pdf': '%PDF-1.4 Mock Vendor Invoice September 2026 Amount Due: $3,450.00 Date: 2026-09-12',
512
+ 'a.download-invoice-btn': '%PDF-1.4 Mock Vendor Invoice September 2026 Amount Due: $3,450.00 Date: 2026-09-12',
513
+ },
514
+ });
515
+ // Mock Page 5: Leads Portal
516
+ this.mockPages.set('https://portal.example.com/leads', {
517
+ title: 'Sales Leads Portal',
518
+ html: `<html><head><title>Sales Leads Portal</title></head><body>
519
+ <h1>Qualified Leads</h1>
520
+ <table class="leads-table">
521
+ <tr><th>Name</th><th>Company</th><th>Status</th><th>MRR</th></tr>
522
+ <tr><td>Alice Smith</td><td>Acme Corp</td><td>Qualified</td><td>$4,500</td></tr>
523
+ <tr><td>Bob Jones</td><td>TechLabs</td><td>Proposal Sent</td><td>$8,200</td></tr>
524
+ <tr><td>Carol White</td><td>GlobalCorp</td><td>Contract Signed</td><td>$12,000</td></tr>
525
+ </table>
526
+ </body></html>`,
527
+ elements: [
528
+ { ref: 1, tag: 'table', text: 'Leads: Alice Smith (Acme Corp), Bob Jones (TechLabs), Carol White (GlobalCorp)', selector: 'table.leads-table' },
529
+ ],
530
+ });
531
+ }
532
+ async navigate(url, isHistoryNav = false) {
533
+ this.actionLog.push({ action: 'navigate', params: { url } });
534
+ const clean = url.replace(/\/$/, '');
535
+ if (!isHistoryNav && this.currentUrl !== 'about:blank' && this.currentUrl !== url) {
536
+ this.historyPast.push(this.currentUrl);
537
+ this.historyFuture = [];
538
+ }
539
+ this.currentUrl = url;
540
+ const page = this.mockPages.get(clean) || this.mockPages.get(url);
541
+ if (page) {
542
+ this.currentTitle = page.title;
543
+ return {
544
+ success: true,
545
+ status: 200,
546
+ output: `Mock navigated to "${url}". Title: "${page.title}". Found ${page.elements.length} interactive elements.`,
547
+ url,
548
+ title: page.title,
549
+ details: { elementsCount: page.elements.length },
550
+ };
551
+ }
552
+ this.currentTitle = 'Page Loaded';
553
+ return {
554
+ success: true,
555
+ status: 200,
556
+ output: `Mock navigated to "${url}". Standard web page loaded.`,
557
+ url,
558
+ title: this.currentTitle,
559
+ };
560
+ }
561
+ async go_back() {
562
+ if (this.historyPast.length === 0)
563
+ return { success: false, output: 'No back history' };
564
+ this.historyFuture.push(this.currentUrl);
565
+ const prev = this.historyPast.pop();
566
+ return await this.navigate(prev, true);
567
+ }
568
+ async go_forward() {
569
+ if (this.historyFuture.length === 0)
570
+ return { success: false, output: 'No forward history' };
571
+ this.historyPast.push(this.currentUrl);
572
+ const next = this.historyFuture.pop();
573
+ return await this.navigate(next, true);
574
+ }
575
+ async refresh() {
576
+ return await this.navigate(this.currentUrl);
577
+ }
578
+ async screenshot() {
579
+ return {
580
+ success: true,
581
+ output: `Mock screenshot of "${this.currentTitle}" at ${this.currentUrl}`,
582
+ url: this.currentUrl,
583
+ title: this.currentTitle,
584
+ };
585
+ }
586
+ async click(selectorOrText) {
587
+ this.actionLog.push({ action: 'click', params: { selectorOrText } });
588
+ const clean = this.currentUrl.replace(/\/$/, '');
589
+ const page = this.mockPages.get(clean) || this.mockPages.get(this.currentUrl);
590
+ if (!page) {
591
+ return { success: false, output: `Element not found matching "${selectorOrText}".` };
592
+ }
593
+ let el;
594
+ if (typeof selectorOrText === 'number') {
595
+ el = page.elements.find((e) => e.ref === selectorOrText);
596
+ }
597
+ else {
598
+ const target = selectorOrText.toLowerCase().trim();
599
+ el = page.elements.find((e) => e.selector.toLowerCase() === target ||
600
+ e.text.toLowerCase().includes(target) ||
601
+ `[ref=${e.ref}]` === target ||
602
+ (e.id && e.id.toLowerCase() === target));
603
+ }
604
+ if (!el) {
605
+ return {
606
+ success: false,
607
+ output: `Element not found matching "${selectorOrText}".`,
608
+ };
609
+ }
610
+ if (el.selector.includes('download') || (el.href && el.href.includes('.pdf'))) {
611
+ await this.download_file(el.href || el.selector);
612
+ }
613
+ if (el.href && !el.href.endsWith('.pdf')) {
614
+ return await this.navigate(el.href);
615
+ }
616
+ return {
617
+ success: true,
618
+ output: `Mock clicked element <${el.tag}> "${el.text}".`,
619
+ details: { element: el },
620
+ };
621
+ }
622
+ async type(selectorOrText, text) {
623
+ this.actionLog.push({ action: 'type', params: { selectorOrText, text } });
624
+ return {
625
+ success: true,
626
+ output: `Mock typed "${text}" into "${selectorOrText}".`,
627
+ details: { selectorOrText, text },
628
+ };
629
+ }
630
+ async select(selector, value) {
631
+ return { success: true, output: `Mock selected "${value}" for "${selector}".` };
632
+ }
633
+ async scroll(direction, amount = 4) {
634
+ return { success: true, output: `Mock scrolled ${direction} by ${amount}.` };
635
+ }
636
+ async extract_content(selector) {
637
+ const page = this.mockPages.get(this.currentUrl);
638
+ const text = page
639
+ ? page.html.replace(/<[^>]+>/g, ' ').replace(/\s+/g, ' ').trim()
640
+ : `Content of ${this.currentUrl}`;
641
+ return {
642
+ success: true,
643
+ output: text,
644
+ url: this.currentUrl,
645
+ title: this.currentTitle,
646
+ };
647
+ }
648
+ async download_file(urlOrSelector, destPath) {
649
+ this.actionLog.push({ action: 'download_file', params: { urlOrSelector, destPath } });
650
+ const page = this.mockPages.get(this.currentUrl);
651
+ let fileContent = 'Mock file content data stream';
652
+ let targetUrl = urlOrSelector;
653
+ if (page && page.files && page.files[urlOrSelector]) {
654
+ fileContent = page.files[urlOrSelector];
655
+ }
656
+ else if (page) {
657
+ const el = page.elements.find((e) => e.href && (e.text.includes(urlOrSelector) || e.selector === urlOrSelector));
658
+ if (el && el.href && page.files && page.files[el.href]) {
659
+ fileContent = page.files[el.href];
660
+ targetUrl = el.href;
661
+ }
662
+ }
663
+ const fileName = path.basename(targetUrl).includes('.') ? path.basename(targetUrl) : 'downloaded_invoice.pdf';
664
+ const finalPath = destPath
665
+ ? (path.isAbsolute(destPath) ? destPath : path.resolve(this.workspaceDir, destPath))
666
+ : path.resolve(this.workspaceDir, 'downloads', fileName);
667
+ fs.mkdirSync(path.dirname(finalPath), { recursive: true });
668
+ fs.writeFileSync(finalPath, fileContent, 'utf-8');
669
+ this.downloadedFiles.push({ filename: fileName, path: finalPath, content: fileContent });
670
+ return {
671
+ success: true,
672
+ output: `Mock downloaded file "${fileName}" to "${finalPath}" (${fileContent.length} bytes).`,
673
+ details: { path: finalPath, filename: fileName, sizeBytes: fileContent.length },
674
+ };
675
+ }
676
+ async downloadInvoice(url, destPath) {
677
+ const res = await this.download_file(url, destPath);
678
+ return {
679
+ success: res.success,
680
+ filename: res.details?.filename || 'invoice.pdf',
681
+ path: res.details?.path || '',
682
+ };
683
+ }
684
+ async upload_file(selector, filePath) {
685
+ return { success: true, output: `Mock uploaded file "${filePath}" to "${selector}".` };
686
+ }
687
+ async inspect_page() {
688
+ const page = this.mockPages.get(this.currentUrl) || {
689
+ title: this.currentTitle,
690
+ html: '<html><body>Mock Page</body></html>',
691
+ elements: [],
692
+ };
693
+ let summary = `Page: "${page.title}" (${this.currentUrl})\nInteractive elements (${page.elements.length}):\n`;
694
+ for (const el of page.elements) {
695
+ summary += ` [ref=${el.ref}] <${el.tag}> "${el.text}" (selector: ${el.selector})${el.href ? ` -> ${el.href}` : ''}\n`;
696
+ }
697
+ return {
698
+ success: true,
699
+ url: this.currentUrl,
700
+ title: page.title,
701
+ elements: page.elements,
702
+ summary,
703
+ };
704
+ }
705
+ async get_active_tab() {
706
+ return {
707
+ id: 'mock_tab_1',
708
+ url: this.currentUrl,
709
+ title: this.currentTitle,
710
+ };
711
+ }
712
+ async get_tabs() {
713
+ return [{ id: 'mock_tab_1', url: this.currentUrl, title: this.currentTitle }];
714
+ }
715
+ async switch_tab(tabId) {
716
+ return { success: true, output: `Switched to tab ${tabId}.` };
717
+ }
718
+ async close_tab(tabId) {
719
+ return { success: true, output: `Closed tab ${tabId}.` };
720
+ }
721
+ async getDOM() {
722
+ const clean = this.currentUrl.replace(/\/$/, '');
723
+ const page = this.mockPages.get(clean) || this.mockPages.get(this.currentUrl);
724
+ return {
725
+ url: this.currentUrl,
726
+ title: page ? page.title : this.currentTitle,
727
+ elements: page ? page.elements : [],
728
+ };
729
+ }
730
+ async clickElement(selectorOrText) {
731
+ return this.click(selectorOrText);
732
+ }
733
+ async getDownloadedFiles() {
734
+ return [...this.downloadedFiles];
735
+ }
736
+ }
737
+ //# sourceMappingURL=browserController.js.map