yiyan-browser-agent 1.6.3 → 1.6.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/browser.js +51 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yiyan-browser-agent",
3
- "version": "1.6.3",
3
+ "version": "1.6.5",
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
@@ -293,9 +293,10 @@ class YiyanBrowser {
293
293
 
294
294
  if (!appeared) logger.warn('Response may have been delayed — continuing to wait...');
295
295
 
296
- // Phase 2: wait for text to stabilise
296
+ // Phase 2: wait for text to stabilise (with multiple checks)
297
297
  let lastText = '';
298
298
  let stableStart = null;
299
+ let stableCount = 0; // 连续稳定次数计数
299
300
  let dotCount = 0;
300
301
 
301
302
  while (Date.now() - start < timeout) {
@@ -304,11 +305,22 @@ class YiyanBrowser {
304
305
  if (text !== lastText) {
305
306
  lastText = text;
306
307
  stableStart = null;
308
+ stableCount = 0; // 内容变化,重置计数
307
309
  } else if (text.length > 0) {
308
310
  if (!stableStart) stableStart = Date.now();
309
311
  else if (Date.now() - stableStart >= stableDelay) {
310
- if (!await this._isGenerating()) break;
311
- stableStart = null;
312
+ // 增加稳定性计数
313
+ stableCount++;
314
+
315
+ // 需要连续稳定检测 + _isGenerating 确认
316
+ if (stableCount >= 2) { // 连续 2 次稳定检测
317
+ if (!await this._isGenerating()) break;
318
+ stableCount = 0; // _isGenerating 说还在生成,重置
319
+ stableStart = null;
320
+ } else {
321
+ // 第一次稳定,继续等待下一次检测
322
+ stableStart = null;
323
+ }
312
324
  }
313
325
  }
314
326
 
@@ -479,11 +491,14 @@ class YiyanBrowser {
479
491
 
480
492
  async _isGenerating() {
481
493
  return await this.page.evaluate(() => {
494
+ // ── 1. 检测停止按钮/生成状态 UI ──
482
495
  const stopSelectors = [
483
496
  'button[aria-label*="Stop" i]',
497
+ 'button[aria-label*="停止"]',
484
498
  '[class*="stop-gen"]',
485
499
  '[class*="stopGen"]',
486
500
  '[class*="generating"]',
501
+ '[class*=" Generating"]',
487
502
  ];
488
503
  for (const sel of stopSelectors) {
489
504
  const el = document.querySelector(sel);
@@ -493,6 +508,7 @@ class YiyanBrowser {
493
508
  }
494
509
  }
495
510
 
511
+ // ── 2. 检测加载动画/typing指示器 ──
496
512
  const loaderSelectors = [
497
513
  '[class*="typing"]',
498
514
  '[class*="loading"]',
@@ -500,8 +516,11 @@ class YiyanBrowser {
500
516
  '[class*="blink"]',
501
517
  '[class*="cursor"]',
502
518
  '[class*="pulsing"]',
519
+ '[class*="thinking"]',
503
520
  'svg[class*="loading"]',
504
521
  'svg[class*="spinner"]',
522
+ '.loading-indicator',
523
+ '.generating-indicator',
505
524
  ];
506
525
  for (const sel of loaderSelectors) {
507
526
  const el = document.querySelector(sel);
@@ -511,6 +530,35 @@ class YiyanBrowser {
511
530
  }
512
531
  }
513
532
 
533
+ // ── 3. 检测是否缺少完成标记元素 ──
534
+ // dialogCardBottom 是 Yiyan 响应完成后的底部操作区域
535
+ const completionMarkers = [
536
+ '[class*="dialogCardBottom"]', // Yiyan 对话卡片底部
537
+ '.dialogCardBottom__qoXjps3z', // Yiyan 特定 class
538
+ '[class*="copy-btn"]',
539
+ '[class*="copyBtn"]',
540
+ '[aria-label*="Copy" i]',
541
+ '[aria-label*="复制"]',
542
+ '[class*="regenerate"]',
543
+ '[class*="retry"]',
544
+ '[class*="action-btn"]',
545
+ ];
546
+ let hasCompletionMarker = false;
547
+ for (const sel of completionMarkers) {
548
+ if (document.querySelector(sel)) {
549
+ hasCompletionMarker = true;
550
+ break;
551
+ }
552
+ }
553
+
554
+ // 如果有响应内容但没有完成标记 → 还在生成
555
+ const answerArea = document.querySelector('[class*="answer"], [class*="response"], [class*="markdown"]');
556
+ if (answerArea && answerArea.innerText && answerArea.innerText.length > 50) {
557
+ if (!hasCompletionMarker) {
558
+ return true;
559
+ }
560
+ }
561
+
514
562
  return false;
515
563
  });
516
564
  }