yiyan-browser-agent 1.6.6 → 1.6.8
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 +50 -15
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,20 +296,47 @@ 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
|
+
// 条件1: dialogCardBottom 出现
|
|
301
|
+
// 条件2: 内容稳定 + _isGenerating() 确认
|
|
302
|
+
let lastText = '';
|
|
303
|
+
let stableStart = null;
|
|
304
|
+
let stableCount = 0;
|
|
305
|
+
let dotCount = 0;
|
|
306
|
+
let hasCompletionMarker = false;
|
|
301
307
|
|
|
302
308
|
while (Date.now() - start < timeout) {
|
|
303
309
|
const text = await this._extractLastMessage();
|
|
304
|
-
lastLength = text.length;
|
|
305
310
|
|
|
306
|
-
//
|
|
307
|
-
|
|
308
|
-
|
|
311
|
+
// ── 稳定性检测 ──
|
|
312
|
+
if (text !== lastText) {
|
|
313
|
+
lastText = text;
|
|
314
|
+
stableStart = null;
|
|
315
|
+
stableCount = 0;
|
|
316
|
+
} else if (text.length > 50) {
|
|
317
|
+
if (!stableStart) stableStart = Date.now();
|
|
318
|
+
else if (Date.now() - stableStart >= stableDelay) {
|
|
319
|
+
stableCount++;
|
|
320
|
+
|
|
321
|
+
if (stableCount >= 2) {
|
|
322
|
+
if (!await this._isGenerating()) {
|
|
323
|
+
// 稳定性检测通过,检查是否同时有完成标记
|
|
324
|
+
if (hasCompletionMarker) {
|
|
325
|
+
logger.clearLine();
|
|
326
|
+
logger.dim('Completion confirmed (stable + marker)');
|
|
327
|
+
break;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
stableCount = 0;
|
|
331
|
+
stableStart = null;
|
|
332
|
+
} else {
|
|
333
|
+
stableStart = null;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
}
|
|
309
337
|
|
|
310
|
-
//
|
|
311
|
-
const
|
|
338
|
+
// ── 完成标记检测 ──
|
|
339
|
+
const detected = await this.page.evaluate(() => {
|
|
312
340
|
const selectors = [
|
|
313
341
|
'.dialogCardBottom__qoXjps3z',
|
|
314
342
|
'[class*="dialogCardBottom"]',
|
|
@@ -325,14 +353,21 @@ class YiyanBrowser {
|
|
|
325
353
|
return false;
|
|
326
354
|
});
|
|
327
355
|
|
|
328
|
-
if (
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
356
|
+
if (detected) {
|
|
357
|
+
hasCompletionMarker = true;
|
|
358
|
+
// 有标记,检查稳定性是否也通过
|
|
359
|
+
if (stableCount >= 2 && lastText.length > 50) {
|
|
360
|
+
await this.page.waitForTimeout(500);
|
|
361
|
+
logger.clearLine();
|
|
362
|
+
logger.dim('Completion confirmed (marker + stable)');
|
|
363
|
+
break;
|
|
364
|
+
}
|
|
334
365
|
}
|
|
335
366
|
|
|
367
|
+
// Progress indicator
|
|
368
|
+
dotCount = (dotCount + 1) % 4;
|
|
369
|
+
logger.thinking(`Receiving response${'.'.repeat(dotCount)} (${text.length} chars)`);
|
|
370
|
+
|
|
336
371
|
// 等待 200ms 给 DOM 时间更新
|
|
337
372
|
await this.page.waitForTimeout(200);
|
|
338
373
|
}
|