browser-use 0.5.0 → 0.6.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/dist/agent/service.js +2 -0
- package/dist/agent/system_prompt.md +269 -0
- package/dist/agent/system_prompt_anthropic_flash.md +240 -0
- package/dist/agent/system_prompt_browser_use.md +18 -0
- package/dist/agent/system_prompt_browser_use_flash.md +15 -0
- package/dist/agent/system_prompt_browser_use_no_thinking.md +17 -0
- package/dist/agent/system_prompt_flash.md +16 -0
- package/dist/agent/system_prompt_flash_anthropic.md +30 -0
- package/dist/agent/system_prompt_no_thinking.md +245 -0
- package/dist/browser/cloud/index.d.ts +1 -0
- package/dist/browser/cloud/index.js +1 -0
- package/dist/browser/cloud/management.d.ts +130 -0
- package/dist/browser/cloud/management.js +140 -0
- package/dist/browser/events.d.ts +61 -3
- package/dist/browser/events.js +66 -0
- package/dist/browser/profile.d.ts +1 -0
- package/dist/browser/profile.js +1 -0
- package/dist/browser/session.d.ts +56 -2
- package/dist/browser/session.js +596 -24
- package/dist/browser/watchdogs/base.js +34 -1
- package/dist/browser/watchdogs/captcha-watchdog.d.ts +26 -0
- package/dist/browser/watchdogs/captcha-watchdog.js +151 -0
- package/dist/browser/watchdogs/index.d.ts +1 -0
- package/dist/browser/watchdogs/index.js +1 -0
- package/dist/browser/watchdogs/screenshot-watchdog.js +4 -3
- package/dist/cli.d.ts +120 -0
- package/dist/cli.js +1816 -4
- package/dist/controller/service.js +106 -362
- package/dist/controller/views.d.ts +9 -6
- package/dist/controller/views.js +8 -5
- package/dist/filesystem/file-system.js +1 -1
- package/dist/llm/litellm/chat.d.ts +11 -0
- package/dist/llm/litellm/chat.js +16 -0
- package/dist/llm/litellm/index.d.ts +1 -0
- package/dist/llm/litellm/index.js +1 -0
- package/dist/llm/models.js +29 -3
- package/dist/llm/oci-raw/chat.d.ts +64 -0
- package/dist/llm/oci-raw/chat.js +350 -0
- package/dist/llm/oci-raw/index.d.ts +2 -0
- package/dist/llm/oci-raw/index.js +2 -0
- package/dist/llm/oci-raw/serializer.d.ts +12 -0
- package/dist/llm/oci-raw/serializer.js +128 -0
- package/dist/mcp/server.d.ts +1 -0
- package/dist/mcp/server.js +62 -13
- package/dist/skill-cli/direct.d.ts +100 -0
- package/dist/skill-cli/direct.js +984 -0
- package/dist/skill-cli/index.d.ts +2 -0
- package/dist/skill-cli/index.js +2 -0
- package/dist/skill-cli/server.d.ts +2 -0
- package/dist/skill-cli/server.js +472 -11
- package/dist/skill-cli/tunnel.d.ts +61 -0
- package/dist/skill-cli/tunnel.js +257 -0
- package/dist/sync/auth.d.ts +8 -0
- package/dist/sync/auth.js +12 -0
- package/package.json +22 -4
package/dist/mcp/server.js
CHANGED
|
@@ -363,6 +363,64 @@ export class MCPServer {
|
|
|
363
363
|
clearInterval(this.sessionCleanupInterval);
|
|
364
364
|
this.sessionCleanupInterval = null;
|
|
365
365
|
}
|
|
366
|
+
formatToolResult(toolName, result) {
|
|
367
|
+
if (toolName === 'browser_get_state' &&
|
|
368
|
+
result &&
|
|
369
|
+
typeof result === 'object' &&
|
|
370
|
+
!Array.isArray(result)) {
|
|
371
|
+
const payload = {
|
|
372
|
+
...result,
|
|
373
|
+
};
|
|
374
|
+
const screenshot = typeof payload.screenshot === 'string' && payload.screenshot.trim()
|
|
375
|
+
? payload.screenshot
|
|
376
|
+
: null;
|
|
377
|
+
delete payload.screenshot;
|
|
378
|
+
const pageInfo = payload.page_info &&
|
|
379
|
+
typeof payload.page_info === 'object' &&
|
|
380
|
+
!Array.isArray(payload.page_info)
|
|
381
|
+
? payload.page_info
|
|
382
|
+
: null;
|
|
383
|
+
const viewportWidth = typeof pageInfo?.viewport_width === 'number'
|
|
384
|
+
? pageInfo.viewport_width
|
|
385
|
+
: null;
|
|
386
|
+
const viewportHeight = typeof pageInfo?.viewport_height === 'number'
|
|
387
|
+
? pageInfo.viewport_height
|
|
388
|
+
: null;
|
|
389
|
+
if (screenshot &&
|
|
390
|
+
viewportWidth !== null &&
|
|
391
|
+
viewportHeight !== null &&
|
|
392
|
+
payload.screenshot_dimensions == null) {
|
|
393
|
+
payload.screenshot_dimensions = {
|
|
394
|
+
width: viewportWidth,
|
|
395
|
+
height: viewportHeight,
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
const content = [
|
|
399
|
+
{
|
|
400
|
+
type: 'text',
|
|
401
|
+
text: JSON.stringify(payload, null, 2),
|
|
402
|
+
},
|
|
403
|
+
];
|
|
404
|
+
if (screenshot) {
|
|
405
|
+
content.push({
|
|
406
|
+
type: 'image',
|
|
407
|
+
data: screenshot,
|
|
408
|
+
mimeType: 'image/png',
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
return { content };
|
|
412
|
+
}
|
|
413
|
+
return {
|
|
414
|
+
content: [
|
|
415
|
+
{
|
|
416
|
+
type: 'text',
|
|
417
|
+
text: typeof result === 'string'
|
|
418
|
+
? result
|
|
419
|
+
: JSON.stringify(result, null, 2),
|
|
420
|
+
},
|
|
421
|
+
],
|
|
422
|
+
};
|
|
423
|
+
}
|
|
366
424
|
setupHandlers() {
|
|
367
425
|
// List available tools
|
|
368
426
|
this.server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
@@ -386,16 +444,7 @@ export class MCPServer {
|
|
|
386
444
|
logger.debug(`Executing tool: ${request.params.name}`);
|
|
387
445
|
this.toolExecutionCount++;
|
|
388
446
|
const result = await tool.handler(request.params.arguments || {});
|
|
389
|
-
return
|
|
390
|
-
content: [
|
|
391
|
-
{
|
|
392
|
-
type: 'text',
|
|
393
|
-
text: typeof result === 'string'
|
|
394
|
-
? result
|
|
395
|
-
: JSON.stringify(result, null, 2),
|
|
396
|
-
},
|
|
397
|
-
],
|
|
398
|
-
};
|
|
447
|
+
return this.formatToolResult(request.params.name, result);
|
|
399
448
|
}
|
|
400
449
|
catch (error) {
|
|
401
450
|
this.errorCount++;
|
|
@@ -676,7 +725,7 @@ export class MCPServer {
|
|
|
676
725
|
this.registerTool('retry_with_browser_use_agent', 'Retry a complex task with the browser-use autonomous agent', z.object({
|
|
677
726
|
task: z.string(),
|
|
678
727
|
max_steps: z.number().int().optional().default(100),
|
|
679
|
-
model: z.string().optional()
|
|
728
|
+
model: z.string().optional(),
|
|
680
729
|
allowed_domains: z.array(z.string()).optional().default([]),
|
|
681
730
|
use_vision: z.boolean().optional().default(true),
|
|
682
731
|
}), async (args) => {
|
|
@@ -684,7 +733,7 @@ export class MCPServer {
|
|
|
684
733
|
if (!task) {
|
|
685
734
|
throw new Error('task is required');
|
|
686
735
|
}
|
|
687
|
-
const
|
|
736
|
+
const requestedModel = typeof args?.model === 'string' ? args.model.trim() : '';
|
|
688
737
|
const maxSteps = Number(args?.max_steps ?? 100);
|
|
689
738
|
const useVision = Boolean(args?.use_vision ?? true);
|
|
690
739
|
const allowedDomains = Array.isArray(args?.allowed_domains)
|
|
@@ -696,7 +745,7 @@ export class MCPServer {
|
|
|
696
745
|
const configuredModel = typeof llmConfig.model === 'string' && llmConfig.model.trim()
|
|
697
746
|
? llmConfig.model.trim()
|
|
698
747
|
: 'gpt-4o';
|
|
699
|
-
const llmModel =
|
|
748
|
+
const llmModel = requestedModel || configuredModel;
|
|
700
749
|
let llm;
|
|
701
750
|
try {
|
|
702
751
|
llm = this.createLlmFromModelName(llmModel, llmConfig);
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { CloudBrowserClient } from '../browser/cloud/cloud.js';
|
|
3
|
+
export interface DirectModeState {
|
|
4
|
+
mode?: 'local' | 'remote';
|
|
5
|
+
cdp_url?: string | null;
|
|
6
|
+
session_id?: string | null;
|
|
7
|
+
browser_pid?: number | null;
|
|
8
|
+
user_data_dir?: string | null;
|
|
9
|
+
owns_user_data_dir?: boolean | null;
|
|
10
|
+
active_url?: string | null;
|
|
11
|
+
}
|
|
12
|
+
export declare const DIRECT_STATE_FILE: string;
|
|
13
|
+
interface StreamLike {
|
|
14
|
+
write(chunk: string): void;
|
|
15
|
+
}
|
|
16
|
+
interface DirectSessionLike {
|
|
17
|
+
tabs?: Array<{
|
|
18
|
+
target_id?: string | null;
|
|
19
|
+
url?: string | null;
|
|
20
|
+
}>;
|
|
21
|
+
active_tab?: {
|
|
22
|
+
target_id?: string | null;
|
|
23
|
+
url?: string | null;
|
|
24
|
+
} | null;
|
|
25
|
+
event_bus?: {
|
|
26
|
+
stop?: () => Promise<void> | void;
|
|
27
|
+
} | null;
|
|
28
|
+
browser_context?: {
|
|
29
|
+
cookies?: (urls?: string[]) => Promise<any[]>;
|
|
30
|
+
addCookies?: (cookies: any[]) => Promise<unknown>;
|
|
31
|
+
clearCookies?: () => Promise<unknown>;
|
|
32
|
+
} | null;
|
|
33
|
+
detach_all_watchdogs?: () => void;
|
|
34
|
+
start: () => Promise<unknown>;
|
|
35
|
+
navigate_to?: (url: string) => Promise<unknown>;
|
|
36
|
+
get_current_page?: () => Promise<any>;
|
|
37
|
+
get_browser_state_with_recovery?: (options?: {
|
|
38
|
+
include_screenshot?: boolean;
|
|
39
|
+
}) => Promise<{
|
|
40
|
+
llm_representation: () => string;
|
|
41
|
+
url?: string;
|
|
42
|
+
title?: string;
|
|
43
|
+
tabs?: unknown[];
|
|
44
|
+
}>;
|
|
45
|
+
get_page_info?: () => Promise<any>;
|
|
46
|
+
get_dom_element_by_index?: (index: number) => Promise<any>;
|
|
47
|
+
get_locate_element?: (node: any) => Promise<any>;
|
|
48
|
+
_click_element_node?: (node: any) => Promise<unknown>;
|
|
49
|
+
click_coordinates?: (x: number, y: number, options?: {
|
|
50
|
+
button?: 'left' | 'middle' | 'right';
|
|
51
|
+
}) => Promise<unknown>;
|
|
52
|
+
send_keys?: (text: string) => Promise<unknown>;
|
|
53
|
+
_input_text_element_node?: (node: any, text: string, options?: {
|
|
54
|
+
clear?: boolean;
|
|
55
|
+
}) => Promise<unknown>;
|
|
56
|
+
take_screenshot?: (full_page?: boolean) => Promise<string | null>;
|
|
57
|
+
scroll?: (direction: 'up' | 'down' | 'left' | 'right', amount: number) => Promise<unknown>;
|
|
58
|
+
go_back?: () => Promise<unknown>;
|
|
59
|
+
go_forward?: () => Promise<unknown>;
|
|
60
|
+
get_page_html?: () => Promise<string>;
|
|
61
|
+
execute_javascript?: (script: string) => Promise<unknown>;
|
|
62
|
+
switch_to_tab?: (identifier: number | string) => Promise<unknown>;
|
|
63
|
+
close_tab?: (identifier: number | string) => Promise<unknown>;
|
|
64
|
+
select_dropdown_option?: (node: any, value: string) => Promise<unknown>;
|
|
65
|
+
wait_for_element?: (selector: string, timeout: number) => Promise<unknown>;
|
|
66
|
+
get_cookies?: () => Promise<any[]>;
|
|
67
|
+
}
|
|
68
|
+
export interface DirectCliEnvironment {
|
|
69
|
+
state_file?: string;
|
|
70
|
+
stdout?: StreamLike;
|
|
71
|
+
stderr?: StreamLike;
|
|
72
|
+
session_factory?: (init: {
|
|
73
|
+
cdp_url?: string | null;
|
|
74
|
+
}) => DirectSessionLike;
|
|
75
|
+
cloud_client_factory?: () => Pick<CloudBrowserClient, 'create_browser' | 'stop_browser'>;
|
|
76
|
+
local_launcher?: (options: {
|
|
77
|
+
state: DirectModeState;
|
|
78
|
+
}) => Promise<{
|
|
79
|
+
cdp_url: string;
|
|
80
|
+
browser_pid?: number | null;
|
|
81
|
+
user_data_dir?: string | null;
|
|
82
|
+
owns_user_data_dir?: boolean | null;
|
|
83
|
+
}>;
|
|
84
|
+
kill_process?: (pid: number) => void | Promise<void>;
|
|
85
|
+
}
|
|
86
|
+
export declare const load_direct_state: (state_file?: string) => DirectModeState;
|
|
87
|
+
export declare const save_direct_state: (state: DirectModeState, state_file?: string) => void;
|
|
88
|
+
export declare const clear_direct_state: (state_file?: string) => void;
|
|
89
|
+
export declare const defaultLocalLauncher: (options: {
|
|
90
|
+
state: DirectModeState;
|
|
91
|
+
timeout_ms?: number;
|
|
92
|
+
}) => Promise<{
|
|
93
|
+
cdp_url: string;
|
|
94
|
+
browser_pid: number | null;
|
|
95
|
+
user_data_dir: string | null | undefined;
|
|
96
|
+
owns_user_data_dir: boolean;
|
|
97
|
+
}>;
|
|
98
|
+
export declare const run_direct_command: (argv: string[], options?: DirectCliEnvironment) => Promise<0 | 1>;
|
|
99
|
+
export declare const main: (argv?: string[]) => Promise<0 | 1>;
|
|
100
|
+
export {};
|