yiyan-browser-agent 1.7.7 → 1.7.9

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 +15 -74
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yiyan-browser-agent",
3
- "version": "1.7.7",
3
+ "version": "1.7.9",
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
@@ -472,84 +472,25 @@ class YiyanBrowser {
472
472
  return result.trim();
473
473
  }
474
474
 
475
- // ── 优先:仅从 answer_text_id 提取内容(排除思考区域)──
476
- const answerEl = document.querySelector('#answer_text_id');
477
- if (answerEl) {
478
- const t = getFullText(answerEl);
479
- if (t.length > 0) return t;
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
+ }
480
485
  }
481
486
 
482
- // ── 备用:其他选择器(仅当 answer_text_id 不存在时)──
483
- const backupSelectors = [
484
- '[class*="answer"]',
485
- '[class*="response"]',
486
- '[class*="message"][class*="content"]',
487
- '.ds-markdown',
488
- '[class*="assistant"] [class*="markdown"]',
489
- '[class*="assistant"] [class*="content"]',
490
- '[data-role="assistant"] [class*="content"]',
491
- '[class*="ai-message"] [class*="content"]',
492
- '[class*="bot-message"] [class*="content"]',
493
- '[class*="response-content"]',
494
- '[class*="message-content"]:last-child',
495
- ];
496
-
497
- for (const sel of backupSelectors) {
498
- try {
499
- const els = document.querySelectorAll(sel);
500
- if (els.length > 0) {
501
- const t = getFullText(els[els.length - 1]);
502
- if (t.length > 5) return t;
503
- }
504
- } catch {}
487
+ // ── 思考区域无内容,从 answer_text_id 提取 ──
488
+ const answerEl = document.querySelector('#answer_text_id');
489
+ if (answerEl) {
490
+ return getFullText(answerEl);
505
491
  }
506
492
 
507
- try {
508
- const markdownEls = document.querySelectorAll(
509
- '[class*="markdown"], [class*="prose"], [class*="rendered"], [class*="content"]'
510
- );
511
- if (markdownEls.length > 0) {
512
- const t = getFullText(markdownEls[markdownEls.length - 1]);
513
- if (t.length > 10) return t;
514
- }
515
- } catch {}
516
-
517
- try {
518
- const allBlocks = Array.from(
519
- document.querySelectorAll('[class*="message"], [class*="chat-item"], [class*="turn"], [class*="answer"], [class*="content"]')
520
- );
521
- const candidates = allBlocks.filter(el => {
522
- const cls = el.className || '';
523
- const id = el.id || '';
524
- return (
525
- !cls.toLowerCase().includes('input') &&
526
- !cls.toLowerCase().includes('user') &&
527
- !cls.toLowerCase().includes('editable') &&
528
- !id.toLowerCase().includes('input') &&
529
- !el.querySelector('textarea, input[type="text"], [contenteditable="true"]') &&
530
- (el.innerText || '').length > 20
531
- );
532
- });
533
-
534
- if (candidates.length > 0) {
535
- return getFullText(candidates[candidates.length - 1]);
536
- }
537
- } catch {}
538
-
539
- try {
540
- const allDivs = Array.from(document.querySelectorAll('div, section'));
541
- const textBlocks = allDivs.filter(el => {
542
- const text = el.innerText || '';
543
- const cls = el.className || '';
544
- if (cls.includes('input') || cls.includes('editable') || cls.includes('user')) return false;
545
- return text.length > 50 && !el.querySelector('textarea, [contenteditable]');
546
- });
547
- if (textBlocks.length > 0) {
548
- textBlocks.sort((a, b) => (b.innerText || '').length - (a.innerText || '').length);
549
- return getFullText(textBlocks[0]);
550
- }
551
- } catch {}
552
-
493
+ // answer_text_id 不存在,返回空字符串
553
494
  return '';
554
495
  });
555
496
  }