yiyan-browser-agent 1.7.9 → 1.8.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 +36 -45
package/package.json
CHANGED
package/src/browser.js
CHANGED
|
@@ -297,26 +297,49 @@ 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
|
-
// 条件: dialogCardBottom 出现 +
|
|
300
|
+
// 条件: dialogCardBottom 出现 + answer稳定 + 思考区域稳定
|
|
301
301
|
let lastText = '';
|
|
302
|
+
let lastThinkingText = '';
|
|
302
303
|
let stableCount = 0;
|
|
303
|
-
let
|
|
304
|
+
let thinkingStableCount = 0;
|
|
305
|
+
let lastCheckTime = Date.now();
|
|
304
306
|
let dotCount = 0;
|
|
305
307
|
let hasCompletionMarker = false;
|
|
306
308
|
|
|
307
309
|
while (Date.now() - start < timeout) {
|
|
308
310
|
const text = await this._extractLastMessage();
|
|
309
311
|
|
|
310
|
-
// ──
|
|
312
|
+
// ── 思考区域内容检测 ──
|
|
313
|
+
const thinkingInfo = await this.page.evaluate(() => {
|
|
314
|
+
const thinkingEl = document.querySelector('.container__SPpahQHm, [class*="container__SPpah"]');
|
|
315
|
+
if (!thinkingEl) return { text: '', exists: false };
|
|
316
|
+
|
|
317
|
+
const s = window.getComputedStyle(thinkingEl);
|
|
318
|
+
const isVisible = s.display !== 'none' && s.visibility !== 'hidden';
|
|
319
|
+
const text = isVisible ? (thinkingEl.innerText || '') : '';
|
|
320
|
+
|
|
321
|
+
return { text, exists: true };
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
// ── 思考区域稳定性检测 ──
|
|
325
|
+
if (thinkingInfo.text === lastThinkingText && thinkingInfo.text.length > 5) {
|
|
326
|
+
if (Date.now() - lastCheckTime >= stableDelay) {
|
|
327
|
+
thinkingStableCount++;
|
|
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
|
+
}
|
|
335
|
+
|
|
336
|
+
// ── answer 稳定性检测 ──
|
|
311
337
|
if (text === lastText && text.length > 50) {
|
|
312
|
-
// 内容没变化,检查是否达到稳定时间
|
|
313
338
|
if (Date.now() - lastCheckTime >= stableDelay) {
|
|
314
339
|
stableCount++;
|
|
315
|
-
|
|
316
|
-
logger.dim(`Stable count: ${stableCount}/2 (${text.length} chars)`);
|
|
340
|
+
logger.dim(`Answer stable: ${stableCount}/2 (${text.length} chars)`);
|
|
317
341
|
}
|
|
318
|
-
} else {
|
|
319
|
-
// 内容变化,重置
|
|
342
|
+
} else if (text !== lastText) {
|
|
320
343
|
lastText = text;
|
|
321
344
|
stableCount = 0;
|
|
322
345
|
lastCheckTime = Date.now();
|
|
@@ -344,30 +367,9 @@ class YiyanBrowser {
|
|
|
344
367
|
hasCompletionMarker = true;
|
|
345
368
|
}
|
|
346
369
|
|
|
347
|
-
// ── 完成判断:标记出现 +
|
|
348
|
-
if (hasCompletionMarker && stableCount >= 2) {
|
|
349
|
-
//
|
|
350
|
-
const thinkingStatus = await this.page.evaluate(() => {
|
|
351
|
-
const thinkingEl = document.querySelector('.container__SPpahQHm, [class*="container__SPpah"]');
|
|
352
|
-
if (!thinkingEl) return { exists: false, hasContent: false };
|
|
353
|
-
|
|
354
|
-
const s = window.getComputedStyle(thinkingEl);
|
|
355
|
-
const isVisible = s.display !== 'none' && s.visibility !== 'hidden';
|
|
356
|
-
const text = thinkingEl.innerText || '';
|
|
357
|
-
const hasContent = text.length > 5;
|
|
358
|
-
|
|
359
|
-
return { exists: true, isVisible, hasContent };
|
|
360
|
-
});
|
|
361
|
-
|
|
362
|
-
// 思考区域存在且可见且有内容 → 还在思考,继续等待
|
|
363
|
-
if (thinkingStatus.exists && thinkingStatus.isVisible && thinkingStatus.hasContent) {
|
|
364
|
-
stableCount = 0;
|
|
365
|
-
lastCheckTime = Date.now();
|
|
366
|
-
logger.dim('Thinking in progress, continue waiting...');
|
|
367
|
-
continue;
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
// 思考区域已消失/不可见/无内容 → 检查 _isGenerating
|
|
370
|
+
// ── 完成判断:标记出现 + answer稳定 + 思考区域稳定 ──
|
|
371
|
+
if (hasCompletionMarker && stableCount >= 2 && thinkingStableCount >= 2) {
|
|
372
|
+
// 思考区域和答案都已稳定,检查 _isGenerating 作为最终确认
|
|
371
373
|
if (!await this._isGenerating()) {
|
|
372
374
|
await this.page.waitForTimeout(500);
|
|
373
375
|
logger.clearLine();
|
|
@@ -376,6 +378,7 @@ class YiyanBrowser {
|
|
|
376
378
|
}
|
|
377
379
|
// _isGenerating 说还在生成,重置计数继续等待
|
|
378
380
|
stableCount = 0;
|
|
381
|
+
thinkingStableCount = 0;
|
|
379
382
|
lastCheckTime = Date.now();
|
|
380
383
|
}
|
|
381
384
|
|
|
@@ -472,19 +475,7 @@ class YiyanBrowser {
|
|
|
472
475
|
return result.trim();
|
|
473
476
|
}
|
|
474
477
|
|
|
475
|
-
// ──
|
|
476
|
-
const thinkingEl = document.querySelector('.container__SPpahQHm, [class*="container__SPpah"]');
|
|
477
|
-
if (thinkingEl) {
|
|
478
|
-
const s = window.getComputedStyle(thinkingEl);
|
|
479
|
-
const isVisible = s.display !== 'none' && s.visibility !== 'hidden';
|
|
480
|
-
const thinkingText = thinkingEl.innerText || '';
|
|
481
|
-
if (isVisible && thinkingText.length > 5) {
|
|
482
|
-
// 思考区域有内容,返回空字符串(等待思考完成)
|
|
483
|
-
return '';
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
// ── 思考区域无内容,从 answer_text_id 提取 ──
|
|
478
|
+
// ── 从 answer_text_id 提取内容 ──
|
|
488
479
|
const answerEl = document.querySelector('#answer_text_id');
|
|
489
480
|
if (answerEl) {
|
|
490
481
|
return getFullText(answerEl);
|