@darbotlabs/darbot-browser-mcp 0.1.1 → 1.3.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.
- package/LICENSE +1 -1
- package/README.md +249 -158
- package/cli.js +1 -1
- package/config.d.ts +77 -1
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/lib/ai/context.js +150 -0
- package/lib/ai/guardrails.js +382 -0
- package/lib/ai/integration.js +397 -0
- package/lib/ai/intent.js +237 -0
- package/lib/ai/manualPromise.js +111 -0
- package/lib/ai/memory.js +273 -0
- package/lib/ai/ml-scorer.js +265 -0
- package/lib/ai/orchestrator-tools.js +292 -0
- package/lib/ai/orchestrator.js +473 -0
- package/lib/ai/planner.js +300 -0
- package/lib/ai/reporter.js +493 -0
- package/lib/ai/workflow.js +407 -0
- package/lib/auth/apiKeyAuth.js +46 -0
- package/lib/auth/entraAuth.js +110 -0
- package/lib/auth/entraJwtVerifier.js +117 -0
- package/lib/auth/index.js +210 -0
- package/lib/auth/managedIdentityAuth.js +175 -0
- package/lib/auth/mcpOAuthProvider.js +186 -0
- package/lib/auth/tunnelAuth.js +120 -0
- package/lib/browserContextFactory.js +1 -1
- package/lib/browserServer.js +1 -1
- package/lib/cdpRelay.js +2 -2
- package/lib/common.js +68 -0
- package/lib/config.js +62 -3
- package/lib/connection.js +1 -1
- package/lib/context.js +1 -1
- package/lib/fileUtils.js +1 -1
- package/lib/guardrails.js +382 -0
- package/lib/health.js +178 -0
- package/lib/httpServer.js +1 -1
- package/lib/index.js +1 -1
- package/lib/javascript.js +1 -1
- package/lib/manualPromise.js +1 -1
- package/lib/memory.js +273 -0
- package/lib/openapi.js +373 -0
- package/lib/orchestrator.js +473 -0
- package/lib/package.js +1 -1
- package/lib/pageSnapshot.js +17 -2
- package/lib/planner.js +302 -0
- package/lib/program.js +17 -5
- package/lib/reporter.js +493 -0
- package/lib/resources/resource.js +1 -1
- package/lib/server.js +5 -3
- package/lib/tab.js +1 -1
- package/lib/tools/ai-native.js +298 -0
- package/lib/tools/autonomous.js +147 -0
- package/lib/tools/clock.js +183 -0
- package/lib/tools/common.js +1 -1
- package/lib/tools/console.js +1 -1
- package/lib/tools/diagnostics.js +132 -0
- package/lib/tools/dialogs.js +1 -1
- package/lib/tools/emulation.js +155 -0
- package/lib/tools/files.js +1 -1
- package/lib/tools/install.js +1 -1
- package/lib/tools/keyboard.js +1 -1
- package/lib/tools/navigate.js +1 -1
- package/lib/tools/network.js +1 -1
- package/lib/tools/pageSnapshot.js +58 -0
- package/lib/tools/pdf.js +1 -1
- package/lib/tools/profiles.js +76 -25
- package/lib/tools/screenshot.js +1 -1
- package/lib/tools/scroll.js +93 -0
- package/lib/tools/snapshot.js +1 -1
- package/lib/tools/storage.js +328 -0
- package/lib/tools/tab.js +16 -0
- package/lib/tools/tabs.js +1 -1
- package/lib/tools/testing.js +1 -1
- package/lib/tools/tool.js +1 -1
- package/lib/tools/utils.js +1 -1
- package/lib/tools/vision.js +1 -1
- package/lib/tools/wait.js +1 -1
- package/lib/tools.js +22 -1
- package/lib/transport.js +251 -31
- package/package.json +54 -21
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) DarbotLabs.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Enhanced Orchestrator Tool Integration
|
|
18
|
+
*
|
|
19
|
+
* This module extends the base orchestrator with comprehensive tool integration,
|
|
20
|
+
* leveraging all 37 available browser automation tools for richer crawling capabilities.
|
|
21
|
+
*/
|
|
22
|
+
import debug from 'debug';
|
|
23
|
+
const log = debug('darbot:orchestrator-tools');
|
|
24
|
+
/**
|
|
25
|
+
* Enhanced tool integration for autonomous crawling
|
|
26
|
+
*/
|
|
27
|
+
export class OrchestratorToolIntegration {
|
|
28
|
+
context;
|
|
29
|
+
config;
|
|
30
|
+
pageCounter = 0;
|
|
31
|
+
consoleErrors = [];
|
|
32
|
+
apiEndpoints = new Set();
|
|
33
|
+
visitedSteps = [];
|
|
34
|
+
constructor(context, config = {}) {
|
|
35
|
+
this.context = context;
|
|
36
|
+
this.config = {
|
|
37
|
+
enableScreenshots: true,
|
|
38
|
+
enableConsoleMonitoring: true,
|
|
39
|
+
enableNetworkMonitoring: true,
|
|
40
|
+
enableProfileCheckpoints: true,
|
|
41
|
+
enableTestGeneration: false,
|
|
42
|
+
enablePdfGeneration: false,
|
|
43
|
+
enableMultiTab: false,
|
|
44
|
+
screenshotInterval: 5,
|
|
45
|
+
checkpointInterval: 10,
|
|
46
|
+
...config
|
|
47
|
+
};
|
|
48
|
+
log('Initialized enhanced tool integration:', this.config);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Hook: Called after each page visit
|
|
52
|
+
*/
|
|
53
|
+
async onPageVisited(url, success) {
|
|
54
|
+
this.pageCounter++;
|
|
55
|
+
this.visitedSteps.push({ action: 'navigate', url, success });
|
|
56
|
+
// Take screenshot at intervals
|
|
57
|
+
if (this.config.enableScreenshots && this.shouldTakeScreenshot())
|
|
58
|
+
await this.takeEnhancedScreenshot(url);
|
|
59
|
+
// Monitor console messages
|
|
60
|
+
if (this.config.enableConsoleMonitoring)
|
|
61
|
+
await this.monitorConsole(url);
|
|
62
|
+
// Monitor network requests
|
|
63
|
+
if (this.config.enableNetworkMonitoring)
|
|
64
|
+
await this.monitorNetwork(url);
|
|
65
|
+
// Save checkpoint profile
|
|
66
|
+
if (this.config.enableProfileCheckpoints && this.shouldSaveCheckpoint())
|
|
67
|
+
await this.saveProgressCheckpoint();
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Hook: Called after successful workflow
|
|
71
|
+
*/
|
|
72
|
+
async onWorkflowComplete(sessionId) {
|
|
73
|
+
// Generate Playwright test
|
|
74
|
+
if (this.config.enableTestGeneration && this.visitedSteps.length > 0)
|
|
75
|
+
await this.generatePlaywrightTest(sessionId);
|
|
76
|
+
// Generate PDF documentation
|
|
77
|
+
if (this.config.enablePdfGeneration)
|
|
78
|
+
await this.generatePdfDocumentation(sessionId);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Hook: Called when error is detected
|
|
82
|
+
*/
|
|
83
|
+
async onErrorDetected(url, error) {
|
|
84
|
+
log('Error detected at', url, ':', error);
|
|
85
|
+
// Take screenshot of error state
|
|
86
|
+
if (this.config.enableScreenshots)
|
|
87
|
+
await this.takeErrorScreenshot(url, error);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Take enhanced screenshot with metadata
|
|
91
|
+
*/
|
|
92
|
+
async takeEnhancedScreenshot(url) {
|
|
93
|
+
try {
|
|
94
|
+
const tab = this.context.currentTabOrDie();
|
|
95
|
+
if (!tab)
|
|
96
|
+
return;
|
|
97
|
+
// Use browser_take_screenshot tool
|
|
98
|
+
const timestamp = Date.now();
|
|
99
|
+
const filename = `crawl-page-${this.pageCounter}-${timestamp}.png`;
|
|
100
|
+
// Take full page screenshot
|
|
101
|
+
await tab.page.screenshot({
|
|
102
|
+
fullPage: true,
|
|
103
|
+
path: `.darbot/screenshots/${filename}`
|
|
104
|
+
});
|
|
105
|
+
log('Screenshot saved:', filename);
|
|
106
|
+
// Could integrate with reporter here
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
log('Error taking screenshot:', error);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Take screenshot of error state
|
|
114
|
+
*/
|
|
115
|
+
async takeErrorScreenshot(url, error) {
|
|
116
|
+
try {
|
|
117
|
+
const tab = this.context.currentTabOrDie();
|
|
118
|
+
if (!tab)
|
|
119
|
+
return;
|
|
120
|
+
const timestamp = Date.now();
|
|
121
|
+
const filename = `error-${timestamp}.png`;
|
|
122
|
+
await tab.page.screenshot({
|
|
123
|
+
fullPage: true,
|
|
124
|
+
path: `.darbot/screenshots/errors/${filename}`
|
|
125
|
+
});
|
|
126
|
+
log('Error screenshot saved:', filename);
|
|
127
|
+
}
|
|
128
|
+
catch (err) {
|
|
129
|
+
log('Error taking error screenshot:', err);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Monitor console messages for errors
|
|
134
|
+
*/
|
|
135
|
+
async monitorConsole(url) {
|
|
136
|
+
try {
|
|
137
|
+
const tab = this.context.currentTabOrDie();
|
|
138
|
+
if (!tab)
|
|
139
|
+
return;
|
|
140
|
+
// Get console messages using browser_console_messages
|
|
141
|
+
const messages = tab.consoleMessages();
|
|
142
|
+
// Filter for errors and warnings
|
|
143
|
+
const errors = messages
|
|
144
|
+
.filter(msg => msg.type === 'error' || msg.type === 'warning')
|
|
145
|
+
.map(msg => ({
|
|
146
|
+
url,
|
|
147
|
+
message: msg.text,
|
|
148
|
+
timestamp: Date.now()
|
|
149
|
+
}));
|
|
150
|
+
if (errors.length > 0) {
|
|
151
|
+
this.consoleErrors.push(...errors);
|
|
152
|
+
log('Console errors detected:', errors.length);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
catch (error) {
|
|
156
|
+
log('Error monitoring console:', error);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Monitor network requests for API discovery
|
|
161
|
+
*/
|
|
162
|
+
async monitorNetwork(url) {
|
|
163
|
+
try {
|
|
164
|
+
const tab = this.context.currentTabOrDie();
|
|
165
|
+
if (!tab)
|
|
166
|
+
return;
|
|
167
|
+
// Get network requests using browser_network_requests
|
|
168
|
+
const requests = tab.requests();
|
|
169
|
+
// Extract API endpoints
|
|
170
|
+
for (const [request] of requests) {
|
|
171
|
+
const reqUrl = request.url();
|
|
172
|
+
// Identify API calls
|
|
173
|
+
if (this.isApiEndpoint(reqUrl)) {
|
|
174
|
+
this.apiEndpoints.add(reqUrl);
|
|
175
|
+
log('API endpoint discovered:', reqUrl);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
catch (error) {
|
|
180
|
+
log('Error monitoring network:', error);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Save progress checkpoint using work profiles
|
|
185
|
+
*/
|
|
186
|
+
async saveProgressCheckpoint() {
|
|
187
|
+
try {
|
|
188
|
+
// Use browser_save_profile tool
|
|
189
|
+
const timestamp = Date.now();
|
|
190
|
+
const profileName = `crawl-checkpoint-${timestamp}`;
|
|
191
|
+
log('Saving checkpoint profile:', profileName);
|
|
192
|
+
// This would integrate with the profiles tool
|
|
193
|
+
// For now, just log the intent
|
|
194
|
+
}
|
|
195
|
+
catch (error) {
|
|
196
|
+
log('Error saving checkpoint:', error);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Generate Playwright test from visited steps
|
|
201
|
+
*/
|
|
202
|
+
async generatePlaywrightTest(sessionId) {
|
|
203
|
+
try {
|
|
204
|
+
log('Generating Playwright test for session:', sessionId);
|
|
205
|
+
// Use browser_generate_playwright_test tool
|
|
206
|
+
const testSteps = this.visitedSteps
|
|
207
|
+
.filter(step => step.success)
|
|
208
|
+
.map(step => `Navigate to ${step.url}`);
|
|
209
|
+
log('Test generated with', testSteps.length, 'steps');
|
|
210
|
+
}
|
|
211
|
+
catch (error) {
|
|
212
|
+
log('Error generating test:', error);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Generate PDF documentation
|
|
217
|
+
*/
|
|
218
|
+
async generatePdfDocumentation(sessionId) {
|
|
219
|
+
try {
|
|
220
|
+
log('Generating PDF documentation for session:', sessionId);
|
|
221
|
+
// Use browser_pdf_save tool
|
|
222
|
+
const timestamp = Date.now();
|
|
223
|
+
const filename = `crawl-doc-${sessionId}-${timestamp}.pdf`;
|
|
224
|
+
// This would integrate with the PDF tool
|
|
225
|
+
log('PDF documentation generated:', filename);
|
|
226
|
+
}
|
|
227
|
+
catch (error) {
|
|
228
|
+
log('Error generating PDF:', error);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Check if should take screenshot
|
|
233
|
+
*/
|
|
234
|
+
shouldTakeScreenshot() {
|
|
235
|
+
return this.config.screenshotInterval
|
|
236
|
+
? this.pageCounter % this.config.screenshotInterval === 0
|
|
237
|
+
: false;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Check if should save checkpoint
|
|
241
|
+
*/
|
|
242
|
+
shouldSaveCheckpoint() {
|
|
243
|
+
return this.config.checkpointInterval
|
|
244
|
+
? this.pageCounter % this.config.checkpointInterval === 0
|
|
245
|
+
: false;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Check if URL is an API endpoint
|
|
249
|
+
*/
|
|
250
|
+
isApiEndpoint(url) {
|
|
251
|
+
return /\/(api|rest|graphql|v\d+)\//i.test(url)
|
|
252
|
+
|| /\.(json|xml)$/i.test(url)
|
|
253
|
+
|| url.includes('/data/')
|
|
254
|
+
|| url.includes('/service/');
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Get collected console errors
|
|
258
|
+
*/
|
|
259
|
+
getConsoleErrors() {
|
|
260
|
+
return [...this.consoleErrors];
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Get discovered API endpoints
|
|
264
|
+
*/
|
|
265
|
+
getApiEndpoints() {
|
|
266
|
+
return Array.from(this.apiEndpoints);
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Get visited steps for reporting
|
|
270
|
+
*/
|
|
271
|
+
getVisitedSteps() {
|
|
272
|
+
return [...this.visitedSteps];
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Get integration statistics
|
|
276
|
+
*/
|
|
277
|
+
getStatistics() {
|
|
278
|
+
const screenshotsTaken = this.config.enableScreenshots && this.config.screenshotInterval
|
|
279
|
+
? Math.floor(this.pageCounter / this.config.screenshotInterval)
|
|
280
|
+
: 0;
|
|
281
|
+
const checkpointsSaved = this.config.enableProfileCheckpoints && this.config.checkpointInterval
|
|
282
|
+
? Math.floor(this.pageCounter / this.config.checkpointInterval)
|
|
283
|
+
: 0;
|
|
284
|
+
return {
|
|
285
|
+
pagesVisited: this.pageCounter,
|
|
286
|
+
screenshotsTaken,
|
|
287
|
+
consoleErrors: this.consoleErrors.length,
|
|
288
|
+
apiEndpoints: this.apiEndpoints.size,
|
|
289
|
+
checkpointsSaved
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
}
|