yiyan-browser-agent 1.6.8 → 1.7.0
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 +26 -33
package/package.json
CHANGED
package/src/browser.js
CHANGED
|
@@ -296,43 +296,30 @@ class YiyanBrowser {
|
|
|
296
296
|
|
|
297
297
|
if (!appeared) logger.warn('Response may have been delayed — continuing to wait...');
|
|
298
298
|
|
|
299
|
-
// Phase 2: wait for completion
|
|
300
|
-
//
|
|
301
|
-
|
|
302
|
-
let
|
|
303
|
-
let
|
|
304
|
-
let
|
|
305
|
-
let dotCount = 0;
|
|
299
|
+
// Phase 2: wait for completion
|
|
300
|
+
// 条件: dialogCardBottom 出现 + 连续两次内容稳定
|
|
301
|
+
let lastText = '';
|
|
302
|
+
let stableCount = 0;
|
|
303
|
+
let lastCheckTime = Date.now();
|
|
304
|
+
let dotCount = 0;
|
|
306
305
|
let hasCompletionMarker = false;
|
|
307
306
|
|
|
308
307
|
while (Date.now() - start < timeout) {
|
|
309
308
|
const text = await this._extractLastMessage();
|
|
310
309
|
|
|
311
|
-
// ──
|
|
312
|
-
if (text
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
stableCount = 0;
|
|
316
|
-
} else if (text.length > 50) {
|
|
317
|
-
if (!stableStart) stableStart = Date.now();
|
|
318
|
-
else if (Date.now() - stableStart >= stableDelay) {
|
|
310
|
+
// ── 稳定性检测:内容不变则计数 ──
|
|
311
|
+
if (text === lastText && text.length > 50) {
|
|
312
|
+
// 内容没变化,检查是否达到稳定时间
|
|
313
|
+
if (Date.now() - lastCheckTime >= stableDelay) {
|
|
319
314
|
stableCount++;
|
|
320
|
-
|
|
321
|
-
|
|
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
|
-
}
|
|
315
|
+
lastCheckTime = Date.now();
|
|
316
|
+
logger.dim(`Stable count: ${stableCount}/2 (${text.length} chars)`);
|
|
335
317
|
}
|
|
318
|
+
} else {
|
|
319
|
+
// 内容变化,重置
|
|
320
|
+
lastText = text;
|
|
321
|
+
stableCount = 0;
|
|
322
|
+
lastCheckTime = Date.now();
|
|
336
323
|
}
|
|
337
324
|
|
|
338
325
|
// ── 完成标记检测 ──
|
|
@@ -355,13 +342,19 @@ class YiyanBrowser {
|
|
|
355
342
|
|
|
356
343
|
if (detected) {
|
|
357
344
|
hasCompletionMarker = true;
|
|
358
|
-
|
|
359
|
-
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
// ── 完成判断:标记出现 + 连续两次稳定 + _isGenerating 确认 ──
|
|
348
|
+
if (hasCompletionMarker && stableCount >= 2) {
|
|
349
|
+
if (!await this._isGenerating()) {
|
|
360
350
|
await this.page.waitForTimeout(500);
|
|
361
351
|
logger.clearLine();
|
|
362
|
-
logger.
|
|
352
|
+
logger.success('Response complete');
|
|
363
353
|
break;
|
|
364
354
|
}
|
|
355
|
+
// _isGenerating 说还在生成,重置计数继续等待
|
|
356
|
+
stableCount = 0;
|
|
357
|
+
lastCheckTime = Date.now();
|
|
365
358
|
}
|
|
366
359
|
|
|
367
360
|
// Progress indicator
|