yiyan-browser-agent 1.8.0 → 1.8.2
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 +27 -47
package/package.json
CHANGED
package/src/browser.js
CHANGED
|
@@ -297,12 +297,11 @@ class YiyanBrowser {
|
|
|
297
297
|
if (!appeared) logger.warn('Response may have been delayed — continuing to wait...');
|
|
298
298
|
|
|
299
299
|
// Phase 2: wait for completion
|
|
300
|
-
// 条件:
|
|
300
|
+
// 条件: 思考区域和答案区域都稳定不变
|
|
301
301
|
let lastText = '';
|
|
302
302
|
let lastThinkingText = '';
|
|
303
303
|
let stableCount = 0;
|
|
304
|
-
let
|
|
305
|
-
let lastCheckTime = Date.now();
|
|
304
|
+
let lastStableTime = Date.now();
|
|
306
305
|
let dotCount = 0;
|
|
307
306
|
let hasCompletionMarker = false;
|
|
308
307
|
|
|
@@ -321,28 +320,24 @@ class YiyanBrowser {
|
|
|
321
320
|
return { text, exists: true };
|
|
322
321
|
});
|
|
323
322
|
|
|
324
|
-
// ──
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
logger.dim(`Thinking stable: ${thinkingStableCount}/2 (${thinkingInfo.text.length} chars)`);
|
|
329
|
-
}
|
|
330
|
-
} else if (thinkingInfo.text !== lastThinkingText) {
|
|
331
|
-
lastThinkingText = thinkingInfo.text;
|
|
332
|
-
thinkingStableCount = 0;
|
|
333
|
-
lastCheckTime = Date.now();
|
|
334
|
-
}
|
|
323
|
+
// ── 统一稳定性检测:两者都不变才算稳定 ──
|
|
324
|
+
const thinkingStable = thinkingInfo.text === lastThinkingText;
|
|
325
|
+
const answerStable = text === lastText;
|
|
326
|
+
const hasContent = thinkingInfo.text.length > 5 && text.length > 50;
|
|
335
327
|
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
if (Date.now() -
|
|
328
|
+
if (thinkingStable && answerStable && hasContent) {
|
|
329
|
+
// 两者都稳定且有内容,检查稳定时间
|
|
330
|
+
if (Date.now() - lastStableTime >= stableDelay) {
|
|
339
331
|
stableCount++;
|
|
340
|
-
|
|
332
|
+
lastStableTime = Date.now();
|
|
333
|
+
logger.dim(`Both stable: ${stableCount}/2 (thinking: ${thinkingInfo.text.length} chars, answer: ${text.length} chars)`);
|
|
341
334
|
}
|
|
342
|
-
} else
|
|
335
|
+
} else {
|
|
336
|
+
// 任一变化,重置
|
|
337
|
+
lastThinkingText = thinkingInfo.text;
|
|
343
338
|
lastText = text;
|
|
344
339
|
stableCount = 0;
|
|
345
|
-
|
|
340
|
+
lastStableTime = Date.now();
|
|
346
341
|
}
|
|
347
342
|
|
|
348
343
|
// ── 完成标记检测 ──
|
|
@@ -367,9 +362,14 @@ class YiyanBrowser {
|
|
|
367
362
|
hasCompletionMarker = true;
|
|
368
363
|
}
|
|
369
364
|
|
|
370
|
-
// ──
|
|
371
|
-
|
|
372
|
-
|
|
365
|
+
// ── 完成判断 ──
|
|
366
|
+
// 条件1: 标记出现 + 两者都稳定 2 次
|
|
367
|
+
// 条件2(备用): 两者都稳定 3 次(即使没有完成标记)
|
|
368
|
+
const condition1 = hasCompletionMarker && stableCount >= 2;
|
|
369
|
+
const condition2 = stableCount >= 3;
|
|
370
|
+
|
|
371
|
+
if (condition1 || condition2) {
|
|
372
|
+
// 检查 _isGenerating 作为最终确认
|
|
373
373
|
if (!await this._isGenerating()) {
|
|
374
374
|
await this.page.waitForTimeout(500);
|
|
375
375
|
logger.clearLine();
|
|
@@ -378,8 +378,7 @@ class YiyanBrowser {
|
|
|
378
378
|
}
|
|
379
379
|
// _isGenerating 说还在生成,重置计数继续等待
|
|
380
380
|
stableCount = 0;
|
|
381
|
-
|
|
382
|
-
lastCheckTime = Date.now();
|
|
381
|
+
lastStableTime = Date.now();
|
|
383
382
|
}
|
|
384
383
|
|
|
385
384
|
// Progress indicator
|
|
@@ -488,26 +487,7 @@ class YiyanBrowser {
|
|
|
488
487
|
|
|
489
488
|
async _isGenerating() {
|
|
490
489
|
return await this.page.evaluate(() => {
|
|
491
|
-
// ── 1.
|
|
492
|
-
const thinkingSelectors = [
|
|
493
|
-
'.container__SPpahQHm', // Yiyan 思考过程区域
|
|
494
|
-
'[class*="container__SPpah"]',
|
|
495
|
-
'[class*="thinking"]',
|
|
496
|
-
'[class*="Thinking"]',
|
|
497
|
-
'[class*="thought"]',
|
|
498
|
-
];
|
|
499
|
-
for (const sel of thinkingSelectors) {
|
|
500
|
-
const el = document.querySelector(sel);
|
|
501
|
-
if (el) {
|
|
502
|
-
const s = window.getComputedStyle(el);
|
|
503
|
-
// 元素可见且有内容
|
|
504
|
-
if (s.display !== 'none' && s.visibility !== 'hidden' && el.innerText && el.innerText.length > 5) {
|
|
505
|
-
return true; // 思考区域有内容,还在生成
|
|
506
|
-
}
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
// ── 2. 检测停止按钮/生成状态 UI ──
|
|
490
|
+
// ── 1. 检测停止按钮/生成状态 UI ──
|
|
511
491
|
const stopSelectors = [
|
|
512
492
|
'button[aria-label*="Stop" i]',
|
|
513
493
|
'button[aria-label*="停止"]',
|
|
@@ -524,7 +504,7 @@ class YiyanBrowser {
|
|
|
524
504
|
}
|
|
525
505
|
}
|
|
526
506
|
|
|
527
|
-
// ──
|
|
507
|
+
// ── 2. 检测加载动画/typing指示器 ──
|
|
528
508
|
const loaderSelectors = [
|
|
529
509
|
'[class*="typing"]',
|
|
530
510
|
'[class*="loading"]',
|
|
@@ -546,7 +526,7 @@ class YiyanBrowser {
|
|
|
546
526
|
}
|
|
547
527
|
}
|
|
548
528
|
|
|
549
|
-
// ──
|
|
529
|
+
// ── 3. 检测是否缺少完成标记元素 ──
|
|
550
530
|
const completionMarkers = [
|
|
551
531
|
'[class*="dialogCardBottom"]',
|
|
552
532
|
'.dialogCardBottom__qoXjps3z',
|