yiyan-browser-agent 1.7.2 → 1.7.4

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/browser.js +42 -10
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yiyan-browser-agent",
3
- "version": "1.7.2",
3
+ "version": "1.7.4",
4
4
  "description": "AI coding agent powered by Yiyan (文心一言) via browser automation — no API key needed",
5
5
  "main": "src/index.js",
6
6
  "bin": {
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 cls = codeEl.className || '';
418
- const lang = (cls.match(/language-(\S+)/) || [])[1] || '';
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,11 +450,15 @@ class YiyanBrowser {
444
450
  return result.trim();
445
451
  }
446
452
 
447
- const directSelectors = [
448
- // Yiyan specific: answer text container (highest priority)
449
- '#answer_text_id',
450
- '[id="answer_text_id"]',
451
- // Generic selectors
453
+ // ── 优先:仅从 answer_text_id 提取内容(排除思考区域)──
454
+ const answerEl = document.querySelector('#answer_text_id');
455
+ if (answerEl) {
456
+ const t = getFullText(answerEl);
457
+ if (t.length > 0) return t;
458
+ }
459
+
460
+ // ── 备用:其他选择器(仅当 answer_text_id 不存在时)──
461
+ const backupSelectors = [
452
462
  '[class*="answer"]',
453
463
  '[class*="response"]',
454
464
  '[class*="message"][class*="content"]',
@@ -462,12 +472,12 @@ class YiyanBrowser {
462
472
  '[class*="message-content"]:last-child',
463
473
  ];
464
474
 
465
- for (const sel of directSelectors) {
475
+ for (const sel of backupSelectors) {
466
476
  try {
467
477
  const els = document.querySelectorAll(sel);
468
478
  if (els.length > 0) {
469
479
  const t = getFullText(els[els.length - 1]);
470
- if (t.length > 10) return t;
480
+ if (t.length > 5) return t;
471
481
  }
472
482
  } catch {}
473
483
  }
@@ -601,7 +611,26 @@ class YiyanBrowser {
601
611
  _cleanText(text) {
602
612
  if (!text) return '';
603
613
 
604
- // Remove everything before "准备输出结果" (Yiyan's thinking process)
614
+ // Remove thinking process markers (Yiyan's 思考过程)
615
+ const thinkingMarkers = [
616
+ '正在思考中',
617
+ '正在思考',
618
+ '思考过程',
619
+ '我来',
620
+ '我需要',
621
+ '根据搜索结果',
622
+ '参考',
623
+ 'picaole需要',
624
+ ];
625
+
626
+ // Remove lines that contain thinking markers
627
+ for (const marker of thinkingMarkers) {
628
+ // 如果整行包含思考标记,移除该行
629
+ const lines = text.split('\n');
630
+ text = lines.filter(line => !line.includes(marker)).join('\n');
631
+ }
632
+
633
+ // Remove everything before "准备输出结果" (Yiyan's thinking process end marker)
605
634
  const outputMarker = '准备输出结果';
606
635
  const markerIndex = text.indexOf(outputMarker);
607
636
  if (markerIndex !== -1) {
@@ -620,6 +649,9 @@ class YiyanBrowser {
620
649
 
621
650
  return text
622
651
  // Strip any remaining AI thinking blocks
652
+ .replace(/阶段性总结[\s\S]*?(?=```|$)/gi, '')
653
+ .replace(/根据搜索结果[\s\S]*?(?=```|$)/gi, '')
654
+ // Strip think tags
623
655
  .replace(/<think>[\s\S]*?<\/think>\n?/gi, '')
624
656
  // Strip copy-code button artifacts
625
657
  .replace(/^\d+(?:Copy|Run|Insert|Edit)\b.*$/gm, '')