yiyan-browser-agent 1.6.0 → 1.6.1
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/package.json +1 -1
- package/src/server.js +23 -9
package/package.json
CHANGED
package/src/server.js
CHANGED
|
@@ -6,6 +6,7 @@ const http = require('http');
|
|
|
6
6
|
const fs = require('fs');
|
|
7
7
|
const path = require('path');
|
|
8
8
|
const os = require('os');
|
|
9
|
+
const config = require('./config');
|
|
9
10
|
const TaskQueue = require('./task-queue');
|
|
10
11
|
|
|
11
12
|
const DEFAULT_PORT = 9527;
|
|
@@ -202,18 +203,31 @@ class AgentServer {
|
|
|
202
203
|
|
|
203
204
|
logger.info(`[Remote Task] ${taskText}`);
|
|
204
205
|
|
|
206
|
+
// 使用 crashHandler.wrap 包装整个执行流程(包括 newChat)
|
|
207
|
+
const crashHandler = this.agent.browser.crashHandler;
|
|
208
|
+
|
|
205
209
|
try {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
210
|
+
if (crashHandler) {
|
|
211
|
+
const result = await crashHandler.wrap(
|
|
212
|
+
async () => {
|
|
213
|
+
if (newChat) {
|
|
214
|
+
await this.agent.browser.newChat();
|
|
215
|
+
}
|
|
216
|
+
return await this.agent.run(taskText);
|
|
217
|
+
},
|
|
218
|
+
'executeTask',
|
|
219
|
+
config.RESPONSE_TIMEOUT * 2 // 给恢复留出时间
|
|
220
|
+
);
|
|
221
|
+
this.taskQueue.completeCurrentTask(result);
|
|
222
|
+
} else {
|
|
223
|
+
// 降级:无 crashHandler
|
|
224
|
+
if (newChat) {
|
|
225
|
+
await this.agent.browser.newChat();
|
|
226
|
+
}
|
|
227
|
+
const result = await this.agent.run(taskText);
|
|
228
|
+
this.taskQueue.completeCurrentTask(result);
|
|
209
229
|
}
|
|
210
230
|
|
|
211
|
-
// 执行任务
|
|
212
|
-
const result = await this.agent.run(taskText);
|
|
213
|
-
|
|
214
|
-
// 完成任务(通知队列,触发 resolve)
|
|
215
|
-
this.taskQueue.completeCurrentTask(result);
|
|
216
|
-
|
|
217
231
|
} catch (err) {
|
|
218
232
|
logger.error(`[Remote Task Error] ${err.message}`);
|
|
219
233
|
this.taskQueue.errorCurrentTask(err);
|