camel-ai 0.2.72a10__py3-none-any.whl → 0.2.73a0__py3-none-any.whl
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.
Potentially problematic release.
This version of camel-ai might be problematic. Click here for more details.
- camel/__init__.py +1 -1
- camel/agents/chat_agent.py +113 -338
- camel/memories/agent_memories.py +18 -17
- camel/societies/workforce/prompts.py +10 -4
- camel/societies/workforce/single_agent_worker.py +7 -5
- camel/toolkits/__init__.py +4 -1
- camel/toolkits/base.py +57 -1
- camel/toolkits/hybrid_browser_toolkit/config_loader.py +136 -413
- camel/toolkits/hybrid_browser_toolkit/hybrid_browser_toolkit.py +796 -1631
- camel/toolkits/hybrid_browser_toolkit/ts/package-lock.json +4356 -0
- camel/toolkits/hybrid_browser_toolkit/ts/package.json +33 -0
- camel/toolkits/hybrid_browser_toolkit/ts/src/browser-scripts.js +125 -0
- camel/toolkits/hybrid_browser_toolkit/ts/src/browser-session.ts +916 -0
- camel/toolkits/hybrid_browser_toolkit/ts/src/config-loader.ts +226 -0
- camel/toolkits/hybrid_browser_toolkit/ts/src/hybrid-browser-toolkit.ts +522 -0
- camel/toolkits/hybrid_browser_toolkit/ts/src/index.ts +7 -0
- camel/toolkits/hybrid_browser_toolkit/ts/src/types.ts +110 -0
- camel/toolkits/hybrid_browser_toolkit/ts/tsconfig.json +26 -0
- camel/toolkits/hybrid_browser_toolkit/ts/websocket-server.js +210 -0
- camel/toolkits/hybrid_browser_toolkit/ws_wrapper.py +533 -0
- camel/toolkits/message_integration.py +592 -0
- camel/toolkits/screenshot_toolkit.py +116 -31
- camel/toolkits/search_toolkit.py +20 -2
- camel/toolkits/terminal_toolkit.py +16 -2
- camel/toolkits/video_analysis_toolkit.py +13 -13
- camel/toolkits/video_download_toolkit.py +11 -11
- {camel_ai-0.2.72a10.dist-info → camel_ai-0.2.73a0.dist-info}/METADATA +10 -4
- {camel_ai-0.2.72a10.dist-info → camel_ai-0.2.73a0.dist-info}/RECORD +30 -24
- camel/toolkits/hybrid_browser_toolkit/actions.py +0 -417
- camel/toolkits/hybrid_browser_toolkit/agent.py +0 -311
- camel/toolkits/hybrid_browser_toolkit/browser_session.py +0 -740
- camel/toolkits/hybrid_browser_toolkit/snapshot.py +0 -227
- camel/toolkits/hybrid_browser_toolkit/stealth_script.js +0 -0
- camel/toolkits/hybrid_browser_toolkit/unified_analyzer.js +0 -1002
- {camel_ai-0.2.72a10.dist-info → camel_ai-0.2.73a0.dist-info}/WHEEL +0 -0
- {camel_ai-0.2.72a10.dist-info → camel_ai-0.2.73a0.dist-info}/licenses/LICENSE +0 -0
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
const WebSocket = require('ws');
|
|
2
|
+
const { HybridBrowserToolkit } = require('./dist/index.js');
|
|
3
|
+
|
|
4
|
+
class WebSocketBrowserServer {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.toolkit = null;
|
|
7
|
+
this.port = 0; // Let the OS assign a free port
|
|
8
|
+
this.server = null;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
async start() {
|
|
12
|
+
return new Promise((resolve, reject) => {
|
|
13
|
+
this.server = new WebSocket.Server({
|
|
14
|
+
port: this.port,
|
|
15
|
+
maxPayload: 50 * 1024 * 1024 // 50MB limit instead of default 1MB
|
|
16
|
+
}, () => {
|
|
17
|
+
this.port = this.server.address().port;
|
|
18
|
+
console.log(`WebSocket server started on port ${this.port}`);
|
|
19
|
+
resolve(this.port);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
this.server.on('connection', (ws) => {
|
|
23
|
+
console.log('Client connected');
|
|
24
|
+
|
|
25
|
+
ws.on('message', async (message) => {
|
|
26
|
+
try {
|
|
27
|
+
const data = JSON.parse(message.toString());
|
|
28
|
+
const { id, command, params } = data;
|
|
29
|
+
|
|
30
|
+
console.log(`Received command: ${command} with id: ${id}`);
|
|
31
|
+
|
|
32
|
+
const result = await this.handleCommand(command, params);
|
|
33
|
+
|
|
34
|
+
const response = {
|
|
35
|
+
id,
|
|
36
|
+
success: true,
|
|
37
|
+
result
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
ws.send(JSON.stringify(response));
|
|
41
|
+
} catch (error) {
|
|
42
|
+
console.error('Error handling command:', error);
|
|
43
|
+
|
|
44
|
+
const errorResponse = {
|
|
45
|
+
id: data?.id || 'unknown',
|
|
46
|
+
success: false,
|
|
47
|
+
error: error.message,
|
|
48
|
+
stack: error.stack
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
ws.send(JSON.stringify(errorResponse));
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
ws.on('close', (code, reason) => {
|
|
56
|
+
console.log('Client disconnected, code:', code, 'reason:', reason?.toString());
|
|
57
|
+
// Clean up resources when client disconnects
|
|
58
|
+
if (this.toolkit) {
|
|
59
|
+
this.toolkit.closeBrowser().catch(err => {
|
|
60
|
+
console.error('Error closing browser on disconnect:', err);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
ws.on('error', (error) => {
|
|
66
|
+
console.error('WebSocket error:', error);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
this.server.on('error', (error) => {
|
|
71
|
+
console.error('Server error:', error);
|
|
72
|
+
reject(error);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async handleCommand(command, params) {
|
|
78
|
+
switch (command) {
|
|
79
|
+
case 'init':
|
|
80
|
+
console.log('Initializing toolkit with params:', JSON.stringify(params, null, 2));
|
|
81
|
+
this.toolkit = new HybridBrowserToolkit(params);
|
|
82
|
+
return { message: 'Toolkit initialized' };
|
|
83
|
+
|
|
84
|
+
case 'open_browser':
|
|
85
|
+
if (!this.toolkit) throw new Error('Toolkit not initialized');
|
|
86
|
+
return await this.toolkit.openBrowser(params.startUrl);
|
|
87
|
+
|
|
88
|
+
case 'close_browser':
|
|
89
|
+
if (!this.toolkit) throw new Error('Toolkit not initialized');
|
|
90
|
+
return await this.toolkit.closeBrowser();
|
|
91
|
+
|
|
92
|
+
case 'visit_page':
|
|
93
|
+
if (!this.toolkit) throw new Error('Toolkit not initialized');
|
|
94
|
+
return await this.toolkit.visitPage(params.url);
|
|
95
|
+
|
|
96
|
+
case 'get_page_snapshot':
|
|
97
|
+
if (!this.toolkit) throw new Error('Toolkit not initialized');
|
|
98
|
+
return await this.toolkit.getPageSnapshot(params.viewport_limit);
|
|
99
|
+
|
|
100
|
+
case 'get_snapshot_for_ai':
|
|
101
|
+
if (!this.toolkit) throw new Error('Toolkit not initialized');
|
|
102
|
+
return await this.toolkit.getSnapshotForAI();
|
|
103
|
+
|
|
104
|
+
case 'get_som_screenshot': {
|
|
105
|
+
if (!this.toolkit) throw new Error('Toolkit not initialized');
|
|
106
|
+
console.log('Starting screenshot...');
|
|
107
|
+
const startTime = Date.now();
|
|
108
|
+
const result = await this.toolkit.getSomScreenshot();
|
|
109
|
+
const endTime = Date.now();
|
|
110
|
+
console.log(`Screenshot completed in ${endTime - startTime}ms`);
|
|
111
|
+
return result;
|
|
112
|
+
}
|
|
113
|
+
case 'click':
|
|
114
|
+
if (!this.toolkit) throw new Error('Toolkit not initialized');
|
|
115
|
+
return await this.toolkit.click(params.ref);
|
|
116
|
+
|
|
117
|
+
case 'type':
|
|
118
|
+
if (!this.toolkit) throw new Error('Toolkit not initialized');
|
|
119
|
+
return await this.toolkit.type(params.ref, params.text);
|
|
120
|
+
|
|
121
|
+
case 'select':
|
|
122
|
+
if (!this.toolkit) throw new Error('Toolkit not initialized');
|
|
123
|
+
return await this.toolkit.select(params.ref, params.value);
|
|
124
|
+
|
|
125
|
+
case 'scroll':
|
|
126
|
+
if (!this.toolkit) throw new Error('Toolkit not initialized');
|
|
127
|
+
return await this.toolkit.scroll(params.direction, params.amount);
|
|
128
|
+
|
|
129
|
+
case 'enter':
|
|
130
|
+
if (!this.toolkit) throw new Error('Toolkit not initialized');
|
|
131
|
+
return await this.toolkit.enter();
|
|
132
|
+
|
|
133
|
+
case 'back':
|
|
134
|
+
if (!this.toolkit) throw new Error('Toolkit not initialized');
|
|
135
|
+
return await this.toolkit.back();
|
|
136
|
+
|
|
137
|
+
case 'forward':
|
|
138
|
+
if (!this.toolkit) throw new Error('Toolkit not initialized');
|
|
139
|
+
return await this.toolkit.forward();
|
|
140
|
+
|
|
141
|
+
case 'switch_tab':
|
|
142
|
+
if (!this.toolkit) throw new Error('Toolkit not initialized');
|
|
143
|
+
return await this.toolkit.switchTab(params.tabId);
|
|
144
|
+
|
|
145
|
+
case 'close_tab':
|
|
146
|
+
if (!this.toolkit) throw new Error('Toolkit not initialized');
|
|
147
|
+
return await this.toolkit.closeTab(params.tabId);
|
|
148
|
+
|
|
149
|
+
case 'get_tab_info':
|
|
150
|
+
if (!this.toolkit) throw new Error('Toolkit not initialized');
|
|
151
|
+
return await this.toolkit.getTabInfo();
|
|
152
|
+
|
|
153
|
+
case 'wait_user':
|
|
154
|
+
if (!this.toolkit) throw new Error('Toolkit not initialized');
|
|
155
|
+
return await this.toolkit.waitUser(params.timeout);
|
|
156
|
+
|
|
157
|
+
case 'shutdown':
|
|
158
|
+
console.log('Shutting down server...');
|
|
159
|
+
if (this.toolkit) {
|
|
160
|
+
try {
|
|
161
|
+
await this.toolkit.closeBrowser();
|
|
162
|
+
} catch (error) {
|
|
163
|
+
console.error('Error closing browser:', error);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
setTimeout(() => {
|
|
167
|
+
process.exit(0);
|
|
168
|
+
}, 1000);
|
|
169
|
+
return { message: 'Server shutting down' };
|
|
170
|
+
|
|
171
|
+
default:
|
|
172
|
+
throw new Error(`Unknown command: ${command}`);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
async stop() {
|
|
177
|
+
if (this.server) {
|
|
178
|
+
this.server.close();
|
|
179
|
+
console.log('WebSocket server stopped');
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// Start server if this file is run directly
|
|
185
|
+
if (require.main === module) {
|
|
186
|
+
const server = new WebSocketBrowserServer();
|
|
187
|
+
|
|
188
|
+
server.start().then((port) => {
|
|
189
|
+
// Output the port so the Python client can connect
|
|
190
|
+
console.log(`SERVER_READY:${port}`);
|
|
191
|
+
}).catch((error) => {
|
|
192
|
+
console.error('Failed to start server:', error);
|
|
193
|
+
process.exit(1);
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
// Handle graceful shutdown
|
|
197
|
+
process.on('SIGINT', async () => {
|
|
198
|
+
console.log('Received SIGINT, shutting down gracefully...');
|
|
199
|
+
await server.stop();
|
|
200
|
+
process.exit(0);
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
process.on('SIGTERM', async () => {
|
|
204
|
+
console.log('Received SIGTERM, shutting down gracefully...');
|
|
205
|
+
await server.stop();
|
|
206
|
+
process.exit(0);
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
module.exports = WebSocketBrowserServer;
|