yiyan-browser-agent 1.7.3 → 1.7.5
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 +56 -10
package/package.json
CHANGED
package/src/browser.js
CHANGED
|
@@ -411,11 +411,17 @@ class YiyanBrowser {
|
|
|
411
411
|
if (node.nodeType !== Node.ELEMENT_NODE) return;
|
|
412
412
|
const tag = node.tagName.toLowerCase();
|
|
413
413
|
|
|
414
|
+
// 排除思考过程区域
|
|
415
|
+
const cls = node.className || '';
|
|
416
|
+
if (cls.includes('container__SPpahQHm') || cls.includes('thinking') || cls.includes('Thinking')) {
|
|
417
|
+
return; // 跳过思考区域
|
|
418
|
+
}
|
|
419
|
+
|
|
414
420
|
if (tag === 'pre') {
|
|
415
421
|
const codeEl = node.querySelector('code');
|
|
416
422
|
if (codeEl) {
|
|
417
|
-
const
|
|
418
|
-
const lang = (
|
|
423
|
+
const cls2 = codeEl.className || '';
|
|
424
|
+
const lang = (cls2.match(/language-(\S+)/) || [])[1] || '';
|
|
419
425
|
const body = codeEl.textContent || '';
|
|
420
426
|
result += '\n```' + lang + '\n' + body + '\n```\n';
|
|
421
427
|
} else {
|
|
@@ -444,7 +450,7 @@ class YiyanBrowser {
|
|
|
444
450
|
return result.trim();
|
|
445
451
|
}
|
|
446
452
|
|
|
447
|
-
// ── 优先:仅从 answer_text_id
|
|
453
|
+
// ── 优先:仅从 answer_text_id 提取内容(排除思考区域)──
|
|
448
454
|
const answerEl = document.querySelector('#answer_text_id');
|
|
449
455
|
if (answerEl) {
|
|
450
456
|
const t = getFullText(answerEl);
|
|
@@ -528,7 +534,26 @@ class YiyanBrowser {
|
|
|
528
534
|
|
|
529
535
|
async _isGenerating() {
|
|
530
536
|
return await this.page.evaluate(() => {
|
|
531
|
-
// ── 1.
|
|
537
|
+
// ── 1. 检测思考过程区域(最重要)──
|
|
538
|
+
const thinkingSelectors = [
|
|
539
|
+
'.container__SPpahQHm', // Yiyan 思考过程区域
|
|
540
|
+
'[class*="container__SPpah"]',
|
|
541
|
+
'[class*="thinking"]',
|
|
542
|
+
'[class*="Thinking"]',
|
|
543
|
+
'[class*="thought"]',
|
|
544
|
+
];
|
|
545
|
+
for (const sel of thinkingSelectors) {
|
|
546
|
+
const el = document.querySelector(sel);
|
|
547
|
+
if (el) {
|
|
548
|
+
const s = window.getComputedStyle(el);
|
|
549
|
+
// 元素可见且有内容
|
|
550
|
+
if (s.display !== 'none' && s.visibility !== 'hidden' && el.innerText && el.innerText.length > 5) {
|
|
551
|
+
return true; // 思考区域有内容,还在生成
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
// ── 2. 检测停止按钮/生成状态 UI ──
|
|
532
557
|
const stopSelectors = [
|
|
533
558
|
'button[aria-label*="Stop" i]',
|
|
534
559
|
'button[aria-label*="停止"]',
|
|
@@ -545,7 +570,7 @@ class YiyanBrowser {
|
|
|
545
570
|
}
|
|
546
571
|
}
|
|
547
572
|
|
|
548
|
-
// ──
|
|
573
|
+
// ── 3. 检测加载动画/typing指示器 ──
|
|
549
574
|
const loaderSelectors = [
|
|
550
575
|
'[class*="typing"]',
|
|
551
576
|
'[class*="loading"]',
|
|
@@ -567,11 +592,10 @@ class YiyanBrowser {
|
|
|
567
592
|
}
|
|
568
593
|
}
|
|
569
594
|
|
|
570
|
-
// ──
|
|
571
|
-
// dialogCardBottom 是 Yiyan 响应完成后的底部操作区域
|
|
595
|
+
// ── 4. 检测是否缺少完成标记元素 ──
|
|
572
596
|
const completionMarkers = [
|
|
573
|
-
'[class*="dialogCardBottom"]',
|
|
574
|
-
'.dialogCardBottom__qoXjps3z',
|
|
597
|
+
'[class*="dialogCardBottom"]',
|
|
598
|
+
'.dialogCardBottom__qoXjps3z',
|
|
575
599
|
'[class*="copy-btn"]',
|
|
576
600
|
'[class*="copyBtn"]',
|
|
577
601
|
'[aria-label*="Copy" i]',
|
|
@@ -605,7 +629,26 @@ class YiyanBrowser {
|
|
|
605
629
|
_cleanText(text) {
|
|
606
630
|
if (!text) return '';
|
|
607
631
|
|
|
608
|
-
// Remove
|
|
632
|
+
// Remove thinking process markers (Yiyan's 思考过程)
|
|
633
|
+
const thinkingMarkers = [
|
|
634
|
+
'正在思考中',
|
|
635
|
+
'正在思考',
|
|
636
|
+
'思考过程',
|
|
637
|
+
'我来',
|
|
638
|
+
'我需要',
|
|
639
|
+
'根据搜索结果',
|
|
640
|
+
'参考',
|
|
641
|
+
'picaole需要',
|
|
642
|
+
];
|
|
643
|
+
|
|
644
|
+
// Remove lines that contain thinking markers
|
|
645
|
+
for (const marker of thinkingMarkers) {
|
|
646
|
+
// 如果整行包含思考标记,移除该行
|
|
647
|
+
const lines = text.split('\n');
|
|
648
|
+
text = lines.filter(line => !line.includes(marker)).join('\n');
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
// Remove everything before "准备输出结果" (Yiyan's thinking process end marker)
|
|
609
652
|
const outputMarker = '准备输出结果';
|
|
610
653
|
const markerIndex = text.indexOf(outputMarker);
|
|
611
654
|
if (markerIndex !== -1) {
|
|
@@ -624,6 +667,9 @@ class YiyanBrowser {
|
|
|
624
667
|
|
|
625
668
|
return text
|
|
626
669
|
// Strip any remaining AI thinking blocks
|
|
670
|
+
.replace(/阶段性总结[\s\S]*?(?=```|$)/gi, '')
|
|
671
|
+
.replace(/根据搜索结果[\s\S]*?(?=```|$)/gi, '')
|
|
672
|
+
// Strip think tags
|
|
627
673
|
.replace(/<think>[\s\S]*?<\/think>\n?/gi, '')
|
|
628
674
|
// Strip copy-code button artifacts
|
|
629
675
|
.replace(/^\d+(?:Copy|Run|Insert|Edit)\b.*$/gm, '')
|