yiyan-browser-agent 1.6.6 → 1.6.7
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/browser.js +38 -10
package/package.json
CHANGED
package/src/browser.js
CHANGED
|
@@ -278,6 +278,7 @@ class YiyanBrowser {
|
|
|
278
278
|
*/
|
|
279
279
|
async waitForResponse() {
|
|
280
280
|
const timeout = config.RESPONSE_TIMEOUT;
|
|
281
|
+
const stableDelay = config.STABLE_DELAY;
|
|
281
282
|
const start = Date.now();
|
|
282
283
|
|
|
283
284
|
// Phase 1: wait for response container to appear
|
|
@@ -295,19 +296,43 @@ class YiyanBrowser {
|
|
|
295
296
|
|
|
296
297
|
if (!appeared) logger.warn('Response may have been delayed — continuing to wait...');
|
|
297
298
|
|
|
298
|
-
// Phase 2: wait for completion
|
|
299
|
-
|
|
300
|
-
|
|
299
|
+
// Phase 2: wait for completion
|
|
300
|
+
// 主要:dialogCardBottom 出现
|
|
301
|
+
// 备用:内容稳定 + _isGenerating() 确认
|
|
302
|
+
let lastText = '';
|
|
303
|
+
let stableStart = null;
|
|
304
|
+
let stableCount = 0;
|
|
305
|
+
let dotCount = 0;
|
|
301
306
|
|
|
302
307
|
while (Date.now() - start < timeout) {
|
|
303
308
|
const text = await this._extractLastMessage();
|
|
304
|
-
lastLength = text.length;
|
|
305
309
|
|
|
306
|
-
//
|
|
307
|
-
|
|
308
|
-
|
|
310
|
+
// ── 稳定性检测(备用退出路径)──
|
|
311
|
+
if (text !== lastText) {
|
|
312
|
+
lastText = text;
|
|
313
|
+
stableStart = null;
|
|
314
|
+
stableCount = 0;
|
|
315
|
+
} else if (text.length > 50) { // 内容足够长才进入稳定检测
|
|
316
|
+
if (!stableStart) stableStart = Date.now();
|
|
317
|
+
else if (Date.now() - stableStart >= stableDelay) {
|
|
318
|
+
stableCount++;
|
|
319
|
+
|
|
320
|
+
// 连续稳定检测 + _isGenerating 确认
|
|
321
|
+
if (stableCount >= 2) {
|
|
322
|
+
if (!await this._isGenerating()) {
|
|
323
|
+
logger.clearLine();
|
|
324
|
+
logger.dim('Stable completion detected');
|
|
325
|
+
break;
|
|
326
|
+
}
|
|
327
|
+
stableCount = 0;
|
|
328
|
+
stableStart = null;
|
|
329
|
+
} else {
|
|
330
|
+
stableStart = null;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|
|
309
334
|
|
|
310
|
-
//
|
|
335
|
+
// ── 完成标记检测(主要退出路径)──
|
|
311
336
|
const hasCompletion = await this.page.evaluate(() => {
|
|
312
337
|
const selectors = [
|
|
313
338
|
'.dialogCardBottom__qoXjps3z',
|
|
@@ -326,13 +351,16 @@ class YiyanBrowser {
|
|
|
326
351
|
});
|
|
327
352
|
|
|
328
353
|
if (hasCompletion) {
|
|
329
|
-
// 完成标记出现,等待一小段时间确保内容完整
|
|
330
354
|
await this.page.waitForTimeout(500);
|
|
331
355
|
logger.clearLine();
|
|
332
|
-
logger.dim('Completion marker detected
|
|
356
|
+
logger.dim('Completion marker detected');
|
|
333
357
|
break;
|
|
334
358
|
}
|
|
335
359
|
|
|
360
|
+
// Progress indicator
|
|
361
|
+
dotCount = (dotCount + 1) % 4;
|
|
362
|
+
logger.thinking(`Receiving response${'.'.repeat(dotCount)} (${text.length} chars)`);
|
|
363
|
+
|
|
336
364
|
// 等待 200ms 给 DOM 时间更新
|
|
337
365
|
await this.page.waitForTimeout(200);
|
|
338
366
|
}
|