browser-use 0.0.1 → 0.0.2
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 +21 -0
- package/README.md +761 -0
- package/dist/agent/cloud-events.d.ts +264 -0
- package/dist/agent/cloud-events.js +318 -0
- package/dist/agent/gif.d.ts +15 -0
- package/dist/agent/gif.js +215 -0
- package/dist/agent/index.d.ts +8 -0
- package/dist/agent/index.js +8 -0
- package/dist/agent/message-manager/service.d.ts +30 -0
- package/dist/agent/message-manager/service.js +208 -0
- package/dist/agent/message-manager/utils.d.ts +2 -0
- package/dist/agent/message-manager/utils.js +41 -0
- package/dist/agent/message-manager/views.d.ts +26 -0
- package/dist/agent/message-manager/views.js +73 -0
- package/dist/agent/prompts.d.ts +52 -0
- package/dist/agent/prompts.js +259 -0
- package/dist/agent/service.d.ts +290 -0
- package/dist/agent/service.js +2200 -0
- package/dist/agent/views.d.ts +741 -0
- package/dist/agent/views.js +537 -0
- package/dist/browser/browser.d.ts +7 -0
- package/dist/browser/browser.js +5 -0
- package/dist/browser/context.d.ts +8 -0
- package/dist/browser/context.js +4 -0
- package/dist/browser/dvd-screensaver.d.ts +101 -0
- package/dist/browser/dvd-screensaver.js +270 -0
- package/dist/browser/extensions.d.ts +63 -0
- package/dist/browser/extensions.js +359 -0
- package/dist/browser/index.d.ts +10 -0
- package/dist/browser/index.js +9 -0
- package/dist/browser/playwright-manager.d.ts +47 -0
- package/dist/browser/playwright-manager.js +146 -0
- package/dist/browser/profile.d.ts +196 -0
- package/dist/browser/profile.js +815 -0
- package/dist/browser/session.d.ts +505 -0
- package/dist/browser/session.js +3409 -0
- package/dist/browser/types.d.ts +1184 -0
- package/dist/browser/types.js +1 -0
- package/dist/browser/utils.d.ts +1 -0
- package/dist/browser/utils.js +19 -0
- package/dist/browser/views.d.ts +78 -0
- package/dist/browser/views.js +72 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +44 -0
- package/dist/config.d.ts +108 -0
- package/dist/config.js +430 -0
- package/dist/controller/index.d.ts +3 -0
- package/dist/controller/index.js +3 -0
- package/dist/controller/registry/index.d.ts +2 -0
- package/dist/controller/registry/index.js +2 -0
- package/dist/controller/registry/service.d.ts +45 -0
- package/dist/controller/registry/service.js +184 -0
- package/dist/controller/registry/views.d.ts +55 -0
- package/dist/controller/registry/views.js +174 -0
- package/dist/controller/service.d.ts +49 -0
- package/dist/controller/service.js +1176 -0
- package/dist/controller/views.d.ts +241 -0
- package/dist/controller/views.js +88 -0
- package/dist/dom/clickable-element-processor/service.d.ts +11 -0
- package/dist/dom/clickable-element-processor/service.js +60 -0
- package/dist/dom/dom_tree/index.js +1400 -0
- package/dist/dom/history-tree-processor/service.d.ts +14 -0
- package/dist/dom/history-tree-processor/service.js +75 -0
- package/dist/dom/history-tree-processor/view.d.ts +54 -0
- package/dist/dom/history-tree-processor/view.js +56 -0
- package/dist/dom/playground/extraction.d.ts +19 -0
- package/dist/dom/playground/extraction.js +187 -0
- package/dist/dom/playground/process-dom.d.ts +1 -0
- package/dist/dom/playground/process-dom.js +5 -0
- package/dist/dom/playground/test-accessibility.d.ts +44 -0
- package/dist/dom/playground/test-accessibility.js +111 -0
- package/dist/dom/service.d.ts +19 -0
- package/dist/dom/service.js +227 -0
- package/dist/dom/utils.d.ts +1 -0
- package/dist/dom/utils.js +6 -0
- package/dist/dom/views.d.ts +61 -0
- package/dist/dom/views.js +247 -0
- package/dist/event-bus.d.ts +11 -0
- package/dist/event-bus.js +19 -0
- package/dist/exceptions.d.ts +10 -0
- package/dist/exceptions.js +22 -0
- package/dist/filesystem/file-system.d.ts +68 -0
- package/dist/filesystem/file-system.js +412 -0
- package/dist/filesystem/index.d.ts +1 -0
- package/dist/filesystem/index.js +1 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.js +33 -0
- package/dist/integrations/gmail/actions.d.ts +12 -0
- package/dist/integrations/gmail/actions.js +113 -0
- package/dist/integrations/gmail/index.d.ts +2 -0
- package/dist/integrations/gmail/index.js +2 -0
- package/dist/integrations/gmail/service.d.ts +61 -0
- package/dist/integrations/gmail/service.js +260 -0
- package/dist/llm/anthropic/chat.d.ts +28 -0
- package/dist/llm/anthropic/chat.js +126 -0
- package/dist/llm/anthropic/index.d.ts +2 -0
- package/dist/llm/anthropic/index.js +2 -0
- package/dist/llm/anthropic/serializer.d.ts +68 -0
- package/dist/llm/anthropic/serializer.js +285 -0
- package/dist/llm/aws/chat-anthropic.d.ts +61 -0
- package/dist/llm/aws/chat-anthropic.js +176 -0
- package/dist/llm/aws/chat-bedrock.d.ts +15 -0
- package/dist/llm/aws/chat-bedrock.js +80 -0
- package/dist/llm/aws/index.d.ts +3 -0
- package/dist/llm/aws/index.js +3 -0
- package/dist/llm/aws/serializer.d.ts +5 -0
- package/dist/llm/aws/serializer.js +68 -0
- package/dist/llm/azure/chat.d.ts +15 -0
- package/dist/llm/azure/chat.js +83 -0
- package/dist/llm/azure/index.d.ts +1 -0
- package/dist/llm/azure/index.js +1 -0
- package/dist/llm/base.d.ts +16 -0
- package/dist/llm/base.js +1 -0
- package/dist/llm/deepseek/chat.d.ts +15 -0
- package/dist/llm/deepseek/chat.js +51 -0
- package/dist/llm/deepseek/index.d.ts +2 -0
- package/dist/llm/deepseek/index.js +2 -0
- package/dist/llm/deepseek/serializer.d.ts +6 -0
- package/dist/llm/deepseek/serializer.js +57 -0
- package/dist/llm/exceptions.d.ts +10 -0
- package/dist/llm/exceptions.js +18 -0
- package/dist/llm/google/chat.d.ts +20 -0
- package/dist/llm/google/chat.js +144 -0
- package/dist/llm/google/index.d.ts +2 -0
- package/dist/llm/google/index.js +2 -0
- package/dist/llm/google/serializer.d.ts +6 -0
- package/dist/llm/google/serializer.js +64 -0
- package/dist/llm/groq/chat.d.ts +15 -0
- package/dist/llm/groq/chat.js +52 -0
- package/dist/llm/groq/index.d.ts +3 -0
- package/dist/llm/groq/index.js +3 -0
- package/dist/llm/groq/parser.d.ts +32 -0
- package/dist/llm/groq/parser.js +189 -0
- package/dist/llm/groq/serializer.d.ts +6 -0
- package/dist/llm/groq/serializer.js +56 -0
- package/dist/llm/messages.d.ts +77 -0
- package/dist/llm/messages.js +157 -0
- package/dist/llm/ollama/chat.d.ts +15 -0
- package/dist/llm/ollama/chat.js +77 -0
- package/dist/llm/ollama/index.d.ts +2 -0
- package/dist/llm/ollama/index.js +2 -0
- package/dist/llm/ollama/serializer.d.ts +6 -0
- package/dist/llm/ollama/serializer.js +53 -0
- package/dist/llm/openai/chat.d.ts +38 -0
- package/dist/llm/openai/chat.js +174 -0
- package/dist/llm/openai/index.d.ts +3 -0
- package/dist/llm/openai/index.js +3 -0
- package/dist/llm/openai/like.d.ts +17 -0
- package/dist/llm/openai/like.js +19 -0
- package/dist/llm/openai/serializer.d.ts +6 -0
- package/dist/llm/openai/serializer.js +57 -0
- package/dist/llm/openrouter/chat.d.ts +15 -0
- package/dist/llm/openrouter/chat.js +74 -0
- package/dist/llm/openrouter/index.d.ts +2 -0
- package/dist/llm/openrouter/index.js +2 -0
- package/dist/llm/openrouter/serializer.d.ts +3 -0
- package/dist/llm/openrouter/serializer.js +3 -0
- package/dist/llm/schema.d.ts +6 -0
- package/dist/llm/schema.js +77 -0
- package/dist/llm/views.d.ts +15 -0
- package/dist/llm/views.js +12 -0
- package/dist/logging-config.d.ts +25 -0
- package/dist/logging-config.js +89 -0
- package/dist/mcp/client.d.ts +142 -0
- package/dist/mcp/client.js +638 -0
- package/dist/mcp/controller.d.ts +6 -0
- package/dist/mcp/controller.js +38 -0
- package/dist/mcp/index.d.ts +3 -0
- package/dist/mcp/index.js +3 -0
- package/dist/mcp/server.d.ts +134 -0
- package/dist/mcp/server.js +759 -0
- package/dist/observability-decorators.d.ts +158 -0
- package/dist/observability-decorators.js +286 -0
- package/dist/observability.d.ts +23 -0
- package/dist/observability.js +58 -0
- package/dist/screenshots/index.d.ts +1 -0
- package/dist/screenshots/index.js +1 -0
- package/dist/screenshots/service.d.ts +6 -0
- package/dist/screenshots/service.js +28 -0
- package/dist/sync/auth.d.ts +27 -0
- package/dist/sync/auth.js +205 -0
- package/dist/sync/index.d.ts +2 -0
- package/dist/sync/index.js +2 -0
- package/dist/sync/service.d.ts +21 -0
- package/dist/sync/service.js +146 -0
- package/dist/telemetry/index.d.ts +2 -0
- package/dist/telemetry/index.js +2 -0
- package/dist/telemetry/service.d.ts +12 -0
- package/dist/telemetry/service.js +85 -0
- package/dist/telemetry/views.d.ts +112 -0
- package/dist/telemetry/views.js +112 -0
- package/dist/tokens/index.d.ts +2 -0
- package/dist/tokens/index.js +2 -0
- package/dist/tokens/service.d.ts +35 -0
- package/dist/tokens/service.js +423 -0
- package/dist/tokens/views.d.ts +58 -0
- package/dist/tokens/views.js +1 -0
- package/dist/utils.d.ts +128 -0
- package/dist/utils.js +529 -0
- package/package.json +94 -5
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
interface AgentReference {
|
|
2
|
+
task_id: string;
|
|
3
|
+
session_id: string;
|
|
4
|
+
task: string;
|
|
5
|
+
llm: {
|
|
6
|
+
model?: string;
|
|
7
|
+
model_name?: string;
|
|
8
|
+
};
|
|
9
|
+
state: {
|
|
10
|
+
stopped: boolean;
|
|
11
|
+
paused: boolean;
|
|
12
|
+
n_steps: number;
|
|
13
|
+
model_dump?: () => Record<string, unknown>;
|
|
14
|
+
};
|
|
15
|
+
history: {
|
|
16
|
+
final_result(): string | null;
|
|
17
|
+
is_done(): boolean;
|
|
18
|
+
};
|
|
19
|
+
browser_session: {
|
|
20
|
+
id: string;
|
|
21
|
+
browser_profile?: {
|
|
22
|
+
viewport?: {
|
|
23
|
+
width: number;
|
|
24
|
+
height: number;
|
|
25
|
+
};
|
|
26
|
+
user_agent?: string | null;
|
|
27
|
+
headless?: boolean;
|
|
28
|
+
allowed_domains?: string[];
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
browser_profile?: {
|
|
32
|
+
viewport?: {
|
|
33
|
+
width: number;
|
|
34
|
+
height: number;
|
|
35
|
+
};
|
|
36
|
+
user_agent?: string | null;
|
|
37
|
+
headless?: boolean;
|
|
38
|
+
allowed_domains?: string[];
|
|
39
|
+
};
|
|
40
|
+
cloud_sync?: {
|
|
41
|
+
auth_client?: {
|
|
42
|
+
device_id?: string | null;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
_task_start_time?: number;
|
|
46
|
+
}
|
|
47
|
+
interface AgentWithState extends AgentReference {
|
|
48
|
+
state: AgentReference['state'] & {
|
|
49
|
+
model_dump?: () => Record<string, unknown>;
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
export declare abstract class BaseEvent {
|
|
53
|
+
readonly event_type: string;
|
|
54
|
+
id: string;
|
|
55
|
+
user_id: string;
|
|
56
|
+
device_id: string | null;
|
|
57
|
+
protected constructor(event_type: string, init?: Partial<BaseEvent>);
|
|
58
|
+
toJSON(): {
|
|
59
|
+
event_type: string;
|
|
60
|
+
id: string;
|
|
61
|
+
user_id: string;
|
|
62
|
+
device_id: string | null;
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
export declare class UpdateAgentTaskEvent extends BaseEvent {
|
|
66
|
+
stopped: boolean | null;
|
|
67
|
+
paused: boolean | null;
|
|
68
|
+
done_output: string | null;
|
|
69
|
+
finished_at: Date | null;
|
|
70
|
+
agent_state: Record<string, unknown> | null;
|
|
71
|
+
user_feedback_type: string | null;
|
|
72
|
+
user_comment: string | null;
|
|
73
|
+
gif_url: string | null;
|
|
74
|
+
constructor(init: Partial<UpdateAgentTaskEvent> & {
|
|
75
|
+
id: string;
|
|
76
|
+
});
|
|
77
|
+
static fromAgent(agent: AgentWithState): UpdateAgentTaskEvent;
|
|
78
|
+
toJSON(): {
|
|
79
|
+
stopped: boolean | null;
|
|
80
|
+
paused: boolean | null;
|
|
81
|
+
done_output: string | null;
|
|
82
|
+
finished_at: string | null;
|
|
83
|
+
agent_state: Record<string, unknown> | null;
|
|
84
|
+
user_feedback_type: string | null;
|
|
85
|
+
user_comment: string | null;
|
|
86
|
+
gif_url: string | null;
|
|
87
|
+
event_type: string;
|
|
88
|
+
id: string;
|
|
89
|
+
user_id: string;
|
|
90
|
+
device_id: string | null;
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
export declare class CreateAgentOutputFileEvent extends BaseEvent {
|
|
94
|
+
task_id: string;
|
|
95
|
+
file_name: string;
|
|
96
|
+
file_content: string | null;
|
|
97
|
+
content_type: string | null;
|
|
98
|
+
created_at: Date;
|
|
99
|
+
constructor(init: {
|
|
100
|
+
user_id?: string;
|
|
101
|
+
device_id?: string | null;
|
|
102
|
+
task_id: string;
|
|
103
|
+
id?: string;
|
|
104
|
+
file_name: string;
|
|
105
|
+
file_content?: string | null;
|
|
106
|
+
content_type?: string | null;
|
|
107
|
+
created_at?: Date;
|
|
108
|
+
});
|
|
109
|
+
static fromAgentAndFile(agent: AgentReference, outputPath: string): Promise<CreateAgentOutputFileEvent>;
|
|
110
|
+
toJSON(): {
|
|
111
|
+
task_id: string;
|
|
112
|
+
file_name: string;
|
|
113
|
+
file_content: string | null;
|
|
114
|
+
content_type: string | null;
|
|
115
|
+
created_at: string;
|
|
116
|
+
event_type: string;
|
|
117
|
+
id: string;
|
|
118
|
+
user_id: string;
|
|
119
|
+
device_id: string | null;
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
export declare class CreateAgentStepEvent extends BaseEvent {
|
|
123
|
+
created_at: Date;
|
|
124
|
+
agent_task_id: string;
|
|
125
|
+
step: number;
|
|
126
|
+
evaluation_previous_goal: string;
|
|
127
|
+
memory: string;
|
|
128
|
+
next_goal: string;
|
|
129
|
+
actions: Array<Record<string, unknown>>;
|
|
130
|
+
screenshot_url: string | null;
|
|
131
|
+
url: string;
|
|
132
|
+
constructor(init: {
|
|
133
|
+
user_id?: string;
|
|
134
|
+
device_id?: string | null;
|
|
135
|
+
agent_task_id: string;
|
|
136
|
+
id?: string;
|
|
137
|
+
step: number;
|
|
138
|
+
evaluation_previous_goal: string;
|
|
139
|
+
memory: string;
|
|
140
|
+
next_goal: string;
|
|
141
|
+
actions: Array<Record<string, unknown>>;
|
|
142
|
+
screenshot_url?: string | null;
|
|
143
|
+
url: string;
|
|
144
|
+
created_at?: Date;
|
|
145
|
+
});
|
|
146
|
+
static fromAgentStep(agent: AgentWithState, model_output: {
|
|
147
|
+
current_state: {
|
|
148
|
+
evaluation_previous_goal: string;
|
|
149
|
+
memory: string;
|
|
150
|
+
next_goal: string;
|
|
151
|
+
};
|
|
152
|
+
action: any[];
|
|
153
|
+
}, result: Array<unknown>, actions_data: Array<Record<string, unknown>>, browser_state_summary: {
|
|
154
|
+
screenshot?: string | null;
|
|
155
|
+
url: string;
|
|
156
|
+
}): CreateAgentStepEvent;
|
|
157
|
+
toJSON(): {
|
|
158
|
+
created_at: string;
|
|
159
|
+
agent_task_id: string;
|
|
160
|
+
step: number;
|
|
161
|
+
evaluation_previous_goal: string;
|
|
162
|
+
memory: string;
|
|
163
|
+
next_goal: string;
|
|
164
|
+
actions: Record<string, unknown>[];
|
|
165
|
+
screenshot_url: string | null;
|
|
166
|
+
url: string;
|
|
167
|
+
event_type: string;
|
|
168
|
+
id: string;
|
|
169
|
+
user_id: string;
|
|
170
|
+
device_id: string | null;
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
export declare class CreateAgentTaskEvent extends BaseEvent {
|
|
174
|
+
agent_session_id: string;
|
|
175
|
+
llm_model: string;
|
|
176
|
+
stopped: boolean;
|
|
177
|
+
paused: boolean;
|
|
178
|
+
task: string;
|
|
179
|
+
done_output: string | null;
|
|
180
|
+
scheduled_task_id: string | null;
|
|
181
|
+
started_at: Date;
|
|
182
|
+
finished_at: Date | null;
|
|
183
|
+
agent_state: Record<string, unknown>;
|
|
184
|
+
user_feedback_type: string | null;
|
|
185
|
+
user_comment: string | null;
|
|
186
|
+
gif_url: string | null;
|
|
187
|
+
constructor(init: {
|
|
188
|
+
user_id?: string;
|
|
189
|
+
device_id?: string | null;
|
|
190
|
+
agent_session_id: string;
|
|
191
|
+
id?: string;
|
|
192
|
+
llm_model: string;
|
|
193
|
+
task: string;
|
|
194
|
+
stopped?: boolean;
|
|
195
|
+
paused?: boolean;
|
|
196
|
+
done_output?: string | null;
|
|
197
|
+
scheduled_task_id?: string | null;
|
|
198
|
+
started_at?: Date;
|
|
199
|
+
finished_at?: Date | null;
|
|
200
|
+
agent_state?: Record<string, unknown>;
|
|
201
|
+
user_feedback_type?: string | null;
|
|
202
|
+
user_comment?: string | null;
|
|
203
|
+
gif_url?: string | null;
|
|
204
|
+
});
|
|
205
|
+
static fromAgent(agent: AgentWithState): CreateAgentTaskEvent;
|
|
206
|
+
toJSON(): {
|
|
207
|
+
agent_session_id: string;
|
|
208
|
+
llm_model: string;
|
|
209
|
+
task: string;
|
|
210
|
+
stopped: boolean;
|
|
211
|
+
paused: boolean;
|
|
212
|
+
done_output: string | null;
|
|
213
|
+
scheduled_task_id: string | null;
|
|
214
|
+
started_at: string;
|
|
215
|
+
finished_at: string | null;
|
|
216
|
+
agent_state: Record<string, unknown>;
|
|
217
|
+
user_feedback_type: string | null;
|
|
218
|
+
user_comment: string | null;
|
|
219
|
+
gif_url: string | null;
|
|
220
|
+
event_type: string;
|
|
221
|
+
id: string;
|
|
222
|
+
user_id: string;
|
|
223
|
+
device_id: string | null;
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
export declare class CreateAgentSessionEvent extends BaseEvent {
|
|
227
|
+
browser_session_id: string;
|
|
228
|
+
browser_session_live_url: string;
|
|
229
|
+
browser_session_cdp_url: string;
|
|
230
|
+
browser_session_stopped: boolean;
|
|
231
|
+
browser_session_stopped_at: Date | null;
|
|
232
|
+
is_source_api: boolean | null;
|
|
233
|
+
browser_state: Record<string, unknown>;
|
|
234
|
+
browser_session_data: Record<string, unknown> | null;
|
|
235
|
+
constructor(init: {
|
|
236
|
+
user_id?: string;
|
|
237
|
+
device_id?: string | null;
|
|
238
|
+
browser_session_id: string;
|
|
239
|
+
id?: string;
|
|
240
|
+
browser_state?: Record<string, unknown>;
|
|
241
|
+
browser_session_live_url?: string;
|
|
242
|
+
browser_session_cdp_url?: string;
|
|
243
|
+
browser_session_stopped?: boolean;
|
|
244
|
+
browser_session_stopped_at?: Date | null;
|
|
245
|
+
is_source_api?: boolean | null;
|
|
246
|
+
browser_session_data?: Record<string, unknown> | null;
|
|
247
|
+
});
|
|
248
|
+
static fromAgent(agent: AgentReference): CreateAgentSessionEvent;
|
|
249
|
+
toJSON(): {
|
|
250
|
+
browser_session_id: string;
|
|
251
|
+
browser_session_live_url: string;
|
|
252
|
+
browser_session_cdp_url: string;
|
|
253
|
+
browser_session_stopped: boolean;
|
|
254
|
+
browser_session_stopped_at: string | null;
|
|
255
|
+
is_source_api: boolean | null;
|
|
256
|
+
browser_state: Record<string, unknown>;
|
|
257
|
+
browser_session_data: Record<string, unknown> | null;
|
|
258
|
+
event_type: string;
|
|
259
|
+
id: string;
|
|
260
|
+
user_id: string;
|
|
261
|
+
device_id: string | null;
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
export {};
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { uuid7str } from '../utils.js';
|
|
4
|
+
const MAX_STRING_LENGTH = 100_000;
|
|
5
|
+
const MAX_URL_LENGTH = 100_000;
|
|
6
|
+
const MAX_TASK_LENGTH = 100_000;
|
|
7
|
+
const MAX_COMMENT_LENGTH = 2_000;
|
|
8
|
+
const MAX_FILE_CONTENT_SIZE = 50 * 1024 * 1024;
|
|
9
|
+
const getDeviceId = (agent) => agent.cloud_sync?.auth_client?.device_id ?? null;
|
|
10
|
+
const getBrowserProfile = (agent) => agent.browser_profile ?? agent.browser_session?.browser_profile ?? null;
|
|
11
|
+
const serializeAgentState = (agent) => {
|
|
12
|
+
if (typeof agent.state.model_dump === 'function') {
|
|
13
|
+
return agent.state.model_dump();
|
|
14
|
+
}
|
|
15
|
+
return {
|
|
16
|
+
stopped: agent.state.stopped,
|
|
17
|
+
paused: agent.state.paused,
|
|
18
|
+
n_steps: agent.state.n_steps,
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
const toDate = (timestamp) => {
|
|
22
|
+
if (!timestamp) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
return new Date(timestamp * 1000);
|
|
26
|
+
};
|
|
27
|
+
export class BaseEvent {
|
|
28
|
+
event_type;
|
|
29
|
+
id;
|
|
30
|
+
user_id;
|
|
31
|
+
device_id;
|
|
32
|
+
constructor(event_type, init = {}) {
|
|
33
|
+
this.event_type = event_type;
|
|
34
|
+
this.id = init.id ?? uuid7str();
|
|
35
|
+
this.user_id = init.user_id ?? '';
|
|
36
|
+
this.device_id = init.device_id ?? null;
|
|
37
|
+
}
|
|
38
|
+
toJSON() {
|
|
39
|
+
return {
|
|
40
|
+
event_type: this.event_type,
|
|
41
|
+
id: this.id,
|
|
42
|
+
user_id: this.user_id,
|
|
43
|
+
device_id: this.device_id,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
export class UpdateAgentTaskEvent extends BaseEvent {
|
|
48
|
+
stopped;
|
|
49
|
+
paused;
|
|
50
|
+
done_output;
|
|
51
|
+
finished_at;
|
|
52
|
+
agent_state;
|
|
53
|
+
user_feedback_type;
|
|
54
|
+
user_comment;
|
|
55
|
+
gif_url;
|
|
56
|
+
constructor(init) {
|
|
57
|
+
super('UpdateAgentTaskEvent', init);
|
|
58
|
+
this.stopped = init.stopped ?? null;
|
|
59
|
+
this.paused = init.paused ?? null;
|
|
60
|
+
this.done_output = init.done_output ?? null;
|
|
61
|
+
this.finished_at = init.finished_at ?? null;
|
|
62
|
+
this.agent_state = init.agent_state ?? null;
|
|
63
|
+
this.user_feedback_type = init.user_feedback_type ?? null;
|
|
64
|
+
this.user_comment = init.user_comment ?? null;
|
|
65
|
+
this.gif_url = init.gif_url ?? null;
|
|
66
|
+
}
|
|
67
|
+
static fromAgent(agent) {
|
|
68
|
+
if (agent._task_start_time == null) {
|
|
69
|
+
throw new Error('Agent must have _task_start_time attribute');
|
|
70
|
+
}
|
|
71
|
+
return new UpdateAgentTaskEvent({
|
|
72
|
+
id: String(agent.task_id),
|
|
73
|
+
device_id: getDeviceId(agent),
|
|
74
|
+
stopped: agent.state.stopped,
|
|
75
|
+
paused: agent.state.paused,
|
|
76
|
+
done_output: agent.history.final_result(),
|
|
77
|
+
finished_at: agent.history.is_done() ? new Date() : null,
|
|
78
|
+
agent_state: serializeAgentState(agent),
|
|
79
|
+
user_feedback_type: null,
|
|
80
|
+
user_comment: null,
|
|
81
|
+
gif_url: null,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
toJSON() {
|
|
85
|
+
return {
|
|
86
|
+
...super.toJSON(),
|
|
87
|
+
stopped: this.stopped,
|
|
88
|
+
paused: this.paused,
|
|
89
|
+
done_output: this.done_output,
|
|
90
|
+
finished_at: this.finished_at?.toISOString() ?? null,
|
|
91
|
+
agent_state: this.agent_state,
|
|
92
|
+
user_feedback_type: this.user_feedback_type,
|
|
93
|
+
user_comment: this.user_comment,
|
|
94
|
+
gif_url: this.gif_url,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
export class CreateAgentOutputFileEvent extends BaseEvent {
|
|
99
|
+
task_id;
|
|
100
|
+
file_name;
|
|
101
|
+
file_content;
|
|
102
|
+
content_type;
|
|
103
|
+
created_at;
|
|
104
|
+
constructor(init) {
|
|
105
|
+
super('CreateAgentOutputFileEvent', init);
|
|
106
|
+
this.task_id = init.task_id;
|
|
107
|
+
this.file_name = init.file_name;
|
|
108
|
+
this.file_content = init.file_content ?? null;
|
|
109
|
+
this.content_type = init.content_type ?? null;
|
|
110
|
+
this.created_at = init.created_at ?? new Date();
|
|
111
|
+
}
|
|
112
|
+
static async fromAgentAndFile(agent, outputPath) {
|
|
113
|
+
const resolved = path.resolve(outputPath);
|
|
114
|
+
await fs.promises.access(resolved, fs.constants.F_OK);
|
|
115
|
+
const stats = await fs.promises.stat(resolved);
|
|
116
|
+
let fileContent = null;
|
|
117
|
+
if (stats.size < MAX_FILE_CONTENT_SIZE) {
|
|
118
|
+
const data = await fs.promises.readFile(resolved);
|
|
119
|
+
fileContent = data.toString('base64');
|
|
120
|
+
}
|
|
121
|
+
return new CreateAgentOutputFileEvent({
|
|
122
|
+
task_id: String(agent.task_id),
|
|
123
|
+
device_id: getDeviceId(agent),
|
|
124
|
+
file_name: path.basename(resolved),
|
|
125
|
+
file_content: fileContent,
|
|
126
|
+
content_type: 'image/gif',
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
toJSON() {
|
|
130
|
+
return {
|
|
131
|
+
...super.toJSON(),
|
|
132
|
+
task_id: this.task_id,
|
|
133
|
+
file_name: this.file_name,
|
|
134
|
+
file_content: this.file_content,
|
|
135
|
+
content_type: this.content_type,
|
|
136
|
+
created_at: this.created_at.toISOString(),
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
export class CreateAgentStepEvent extends BaseEvent {
|
|
141
|
+
created_at;
|
|
142
|
+
agent_task_id;
|
|
143
|
+
step;
|
|
144
|
+
evaluation_previous_goal;
|
|
145
|
+
memory;
|
|
146
|
+
next_goal;
|
|
147
|
+
actions;
|
|
148
|
+
screenshot_url;
|
|
149
|
+
url;
|
|
150
|
+
constructor(init) {
|
|
151
|
+
super('CreateAgentStepEvent', init);
|
|
152
|
+
this.created_at = init.created_at ?? new Date();
|
|
153
|
+
this.agent_task_id = init.agent_task_id;
|
|
154
|
+
this.step = init.step;
|
|
155
|
+
this.evaluation_previous_goal = init.evaluation_previous_goal;
|
|
156
|
+
this.memory = init.memory;
|
|
157
|
+
this.next_goal = init.next_goal;
|
|
158
|
+
this.actions = init.actions;
|
|
159
|
+
this.screenshot_url = init.screenshot_url ?? null;
|
|
160
|
+
this.url = init.url;
|
|
161
|
+
}
|
|
162
|
+
static fromAgentStep(agent, model_output, result, actions_data, browser_state_summary) {
|
|
163
|
+
const currentState = model_output.current_state;
|
|
164
|
+
const screenshot = browser_state_summary.screenshot
|
|
165
|
+
? `data:image/png;base64,${browser_state_summary.screenshot}`
|
|
166
|
+
: null;
|
|
167
|
+
return new CreateAgentStepEvent({
|
|
168
|
+
device_id: getDeviceId(agent),
|
|
169
|
+
agent_task_id: String(agent.task_id),
|
|
170
|
+
step: agent.state.n_steps,
|
|
171
|
+
evaluation_previous_goal: currentState?.evaluation_previous_goal ?? '',
|
|
172
|
+
memory: currentState?.memory ?? '',
|
|
173
|
+
next_goal: currentState?.next_goal ?? '',
|
|
174
|
+
actions: actions_data ?? [],
|
|
175
|
+
url: browser_state_summary.url ?? '',
|
|
176
|
+
screenshot_url: screenshot,
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
toJSON() {
|
|
180
|
+
return {
|
|
181
|
+
...super.toJSON(),
|
|
182
|
+
created_at: this.created_at.toISOString(),
|
|
183
|
+
agent_task_id: this.agent_task_id,
|
|
184
|
+
step: this.step,
|
|
185
|
+
evaluation_previous_goal: this.evaluation_previous_goal,
|
|
186
|
+
memory: this.memory,
|
|
187
|
+
next_goal: this.next_goal,
|
|
188
|
+
actions: this.actions,
|
|
189
|
+
screenshot_url: this.screenshot_url,
|
|
190
|
+
url: this.url,
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
export class CreateAgentTaskEvent extends BaseEvent {
|
|
195
|
+
agent_session_id;
|
|
196
|
+
llm_model;
|
|
197
|
+
stopped;
|
|
198
|
+
paused;
|
|
199
|
+
task;
|
|
200
|
+
done_output;
|
|
201
|
+
scheduled_task_id;
|
|
202
|
+
started_at;
|
|
203
|
+
finished_at;
|
|
204
|
+
agent_state;
|
|
205
|
+
user_feedback_type;
|
|
206
|
+
user_comment;
|
|
207
|
+
gif_url;
|
|
208
|
+
constructor(init) {
|
|
209
|
+
super('CreateAgentTaskEvent', init);
|
|
210
|
+
this.agent_session_id = init.agent_session_id;
|
|
211
|
+
this.llm_model = init.llm_model;
|
|
212
|
+
this.task = init.task;
|
|
213
|
+
this.stopped = init.stopped ?? false;
|
|
214
|
+
this.paused = init.paused ?? false;
|
|
215
|
+
this.done_output = init.done_output ?? null;
|
|
216
|
+
this.scheduled_task_id = init.scheduled_task_id ?? null;
|
|
217
|
+
this.started_at = init.started_at ?? new Date();
|
|
218
|
+
this.finished_at = init.finished_at ?? null;
|
|
219
|
+
this.agent_state = init.agent_state ?? {};
|
|
220
|
+
this.user_feedback_type = init.user_feedback_type ?? null;
|
|
221
|
+
this.user_comment = init.user_comment ?? null;
|
|
222
|
+
this.gif_url = init.gif_url ?? null;
|
|
223
|
+
}
|
|
224
|
+
static fromAgent(agent) {
|
|
225
|
+
const startedAt = toDate(agent._task_start_time) ?? new Date();
|
|
226
|
+
return new CreateAgentTaskEvent({
|
|
227
|
+
id: String(agent.task_id),
|
|
228
|
+
device_id: getDeviceId(agent),
|
|
229
|
+
agent_session_id: String(agent.session_id),
|
|
230
|
+
task: agent.task.slice(0, MAX_TASK_LENGTH),
|
|
231
|
+
llm_model: agent.llm.model_name || agent.llm.model || 'unknown',
|
|
232
|
+
agent_state: serializeAgentState(agent),
|
|
233
|
+
stopped: false,
|
|
234
|
+
paused: false,
|
|
235
|
+
started_at: startedAt,
|
|
236
|
+
finished_at: null,
|
|
237
|
+
done_output: null,
|
|
238
|
+
scheduled_task_id: null,
|
|
239
|
+
user_feedback_type: null,
|
|
240
|
+
user_comment: null,
|
|
241
|
+
gif_url: null,
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
toJSON() {
|
|
245
|
+
return {
|
|
246
|
+
...super.toJSON(),
|
|
247
|
+
agent_session_id: this.agent_session_id,
|
|
248
|
+
llm_model: this.llm_model,
|
|
249
|
+
task: this.task,
|
|
250
|
+
stopped: this.stopped,
|
|
251
|
+
paused: this.paused,
|
|
252
|
+
done_output: this.done_output,
|
|
253
|
+
scheduled_task_id: this.scheduled_task_id,
|
|
254
|
+
started_at: this.started_at.toISOString(),
|
|
255
|
+
finished_at: this.finished_at?.toISOString() ?? null,
|
|
256
|
+
agent_state: this.agent_state,
|
|
257
|
+
user_feedback_type: this.user_feedback_type,
|
|
258
|
+
user_comment: this.user_comment,
|
|
259
|
+
gif_url: this.gif_url,
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
export class CreateAgentSessionEvent extends BaseEvent {
|
|
264
|
+
browser_session_id;
|
|
265
|
+
browser_session_live_url;
|
|
266
|
+
browser_session_cdp_url;
|
|
267
|
+
browser_session_stopped;
|
|
268
|
+
browser_session_stopped_at;
|
|
269
|
+
is_source_api;
|
|
270
|
+
browser_state;
|
|
271
|
+
browser_session_data;
|
|
272
|
+
constructor(init) {
|
|
273
|
+
super('CreateAgentSessionEvent', init);
|
|
274
|
+
this.browser_session_id = init.browser_session_id;
|
|
275
|
+
this.browser_session_live_url = init.browser_session_live_url ?? '';
|
|
276
|
+
this.browser_session_cdp_url = init.browser_session_cdp_url ?? '';
|
|
277
|
+
this.browser_session_stopped = init.browser_session_stopped ?? false;
|
|
278
|
+
this.browser_session_stopped_at = init.browser_session_stopped_at ?? null;
|
|
279
|
+
this.is_source_api = init.is_source_api ?? null;
|
|
280
|
+
this.browser_state = init.browser_state ?? {};
|
|
281
|
+
this.browser_session_data = init.browser_session_data ?? null;
|
|
282
|
+
}
|
|
283
|
+
static fromAgent(agent) {
|
|
284
|
+
const profile = getBrowserProfile(agent);
|
|
285
|
+
return new CreateAgentSessionEvent({
|
|
286
|
+
id: String(agent.session_id),
|
|
287
|
+
device_id: getDeviceId(agent),
|
|
288
|
+
browser_session_id: agent.browser_session.id,
|
|
289
|
+
browser_state: {
|
|
290
|
+
viewport: profile?.viewport ?? { width: 1280, height: 720 },
|
|
291
|
+
user_agent: profile?.user_agent ?? null,
|
|
292
|
+
headless: profile?.headless ?? true,
|
|
293
|
+
initial_url: null,
|
|
294
|
+
final_url: null,
|
|
295
|
+
total_pages_visited: 0,
|
|
296
|
+
session_duration_seconds: 0,
|
|
297
|
+
},
|
|
298
|
+
browser_session_data: {
|
|
299
|
+
cookies: [],
|
|
300
|
+
secrets: {},
|
|
301
|
+
allowed_domains: profile?.allowed_domains ?? [],
|
|
302
|
+
},
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
toJSON() {
|
|
306
|
+
return {
|
|
307
|
+
...super.toJSON(),
|
|
308
|
+
browser_session_id: this.browser_session_id,
|
|
309
|
+
browser_session_live_url: this.browser_session_live_url,
|
|
310
|
+
browser_session_cdp_url: this.browser_session_cdp_url,
|
|
311
|
+
browser_session_stopped: this.browser_session_stopped,
|
|
312
|
+
browser_session_stopped_at: this.browser_session_stopped_at?.toISOString() ?? null,
|
|
313
|
+
is_source_api: this.is_source_api,
|
|
314
|
+
browser_state: this.browser_state,
|
|
315
|
+
browser_session_data: this.browser_session_data,
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { AgentHistoryList } from './views.js';
|
|
2
|
+
export declare const decode_unicode_escapes_to_utf8: (text: string) => string;
|
|
3
|
+
export interface HistoryGifOptions {
|
|
4
|
+
output_path?: string;
|
|
5
|
+
duration?: number;
|
|
6
|
+
show_goals?: boolean;
|
|
7
|
+
show_task?: boolean;
|
|
8
|
+
show_logo?: boolean;
|
|
9
|
+
font_size?: number;
|
|
10
|
+
title_font_size?: number;
|
|
11
|
+
goal_font_size?: number;
|
|
12
|
+
margin?: number;
|
|
13
|
+
line_spacing?: number;
|
|
14
|
+
}
|
|
15
|
+
export declare const create_history_gif: (task: string, history: AgentHistoryList, { output_path, duration, show_goals, show_task, show_logo, font_size, title_font_size, goal_font_size, line_spacing, }?: HistoryGifOptions) => Promise<void>;
|