yiyan-browser-agent 1.7.4 → 1.7.6

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 +46 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yiyan-browser-agent",
3
- "version": "1.7.4",
3
+ "version": "1.7.6",
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
@@ -344,8 +344,29 @@ class YiyanBrowser {
344
344
  hasCompletionMarker = true;
345
345
  }
346
346
 
347
- // ── 完成判断:标记出现 + 连续两次稳定 + _isGenerating 确认 ──
347
+ // ── 完成判断:标记出现 + 连续两次稳定 + _isGenerating 确认 + 思考区域检查 ──
348
348
  if (hasCompletionMarker && stableCount >= 2) {
349
+ // 检查思考区域是否有内容
350
+ const hasThinkingContent = await this.page.evaluate(() => {
351
+ const thinkingEl = document.querySelector('.container__SPpahQHm, [class*="container__SPpah"]');
352
+ if (thinkingEl) {
353
+ const s = window.getComputedStyle(thinkingEl);
354
+ if (s.display !== 'none' && s.visibility !== 'hidden') {
355
+ const text = thinkingEl.innerText || '';
356
+ return text.length > 5; // 思考区域有内容
357
+ }
358
+ }
359
+ return false;
360
+ });
361
+
362
+ if (hasThinkingContent) {
363
+ // 思考区域有内容,还没完成
364
+ stableCount = 0;
365
+ lastCheckTime = Date.now();
366
+ logger.dim('Thinking in progress, continue waiting...');
367
+ continue;
368
+ }
369
+
349
370
  if (!await this._isGenerating()) {
350
371
  await this.page.waitForTimeout(500);
351
372
  logger.clearLine();
@@ -534,7 +555,26 @@ class YiyanBrowser {
534
555
 
535
556
  async _isGenerating() {
536
557
  return await this.page.evaluate(() => {
537
- // ── 1. 检测停止按钮/生成状态 UI ──
558
+ // ── 1. 检测思考过程区域(最重要)──
559
+ const thinkingSelectors = [
560
+ '.container__SPpahQHm', // Yiyan 思考过程区域
561
+ '[class*="container__SPpah"]',
562
+ '[class*="thinking"]',
563
+ '[class*="Thinking"]',
564
+ '[class*="thought"]',
565
+ ];
566
+ for (const sel of thinkingSelectors) {
567
+ const el = document.querySelector(sel);
568
+ if (el) {
569
+ const s = window.getComputedStyle(el);
570
+ // 元素可见且有内容
571
+ if (s.display !== 'none' && s.visibility !== 'hidden' && el.innerText && el.innerText.length > 5) {
572
+ return true; // 思考区域有内容,还在生成
573
+ }
574
+ }
575
+ }
576
+
577
+ // ── 2. 检测停止按钮/生成状态 UI ──
538
578
  const stopSelectors = [
539
579
  'button[aria-label*="Stop" i]',
540
580
  'button[aria-label*="停止"]',
@@ -551,7 +591,7 @@ class YiyanBrowser {
551
591
  }
552
592
  }
553
593
 
554
- // ── 2. 检测加载动画/typing指示器 ──
594
+ // ── 3. 检测加载动画/typing指示器 ──
555
595
  const loaderSelectors = [
556
596
  '[class*="typing"]',
557
597
  '[class*="loading"]',
@@ -573,11 +613,10 @@ class YiyanBrowser {
573
613
  }
574
614
  }
575
615
 
576
- // ── 3. 检测是否缺少完成标记元素 ──
577
- // dialogCardBottom 是 Yiyan 响应完成后的底部操作区域
616
+ // ── 4. 检测是否缺少完成标记元素 ──
578
617
  const completionMarkers = [
579
- '[class*="dialogCardBottom"]', // Yiyan 对话卡片底部
580
- '.dialogCardBottom__qoXjps3z', // Yiyan 特定 class
618
+ '[class*="dialogCardBottom"]',
619
+ '.dialogCardBottom__qoXjps3z',
581
620
  '[class*="copy-btn"]',
582
621
  '[class*="copyBtn"]',
583
622
  '[aria-label*="Copy" i]',