yiyan-browser-agent 1.6.8 → 1.7.0

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 +26 -33
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yiyan-browser-agent",
3
- "version": "1.6.8",
3
+ "version": "1.7.0",
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
@@ -296,43 +296,30 @@ class YiyanBrowser {
296
296
 
297
297
  if (!appeared) logger.warn('Response may have been delayed — continuing to wait...');
298
298
 
299
- // Phase 2: wait for completion (双重条件都必须满足)
300
- // 条件1: dialogCardBottom 出现
301
- // 条件2: 内容稳定 + _isGenerating() 确认
302
- let lastText = '';
303
- let stableStart = null;
304
- let stableCount = 0;
305
- let dotCount = 0;
299
+ // Phase 2: wait for completion
300
+ // 条件: dialogCardBottom 出现 + 连续两次内容稳定
301
+ let lastText = '';
302
+ let stableCount = 0;
303
+ let lastCheckTime = Date.now();
304
+ let dotCount = 0;
306
305
  let hasCompletionMarker = false;
307
306
 
308
307
  while (Date.now() - start < timeout) {
309
308
  const text = await this._extractLastMessage();
310
309
 
311
- // ── 稳定性检测 ──
312
- if (text !== lastText) {
313
- lastText = text;
314
- stableStart = null;
315
- stableCount = 0;
316
- } else if (text.length > 50) {
317
- if (!stableStart) stableStart = Date.now();
318
- else if (Date.now() - stableStart >= stableDelay) {
310
+ // ── 稳定性检测:内容不变则计数 ──
311
+ if (text === lastText && text.length > 50) {
312
+ // 内容没变化,检查是否达到稳定时间
313
+ if (Date.now() - lastCheckTime >= stableDelay) {
319
314
  stableCount++;
320
-
321
- if (stableCount >= 2) {
322
- if (!await this._isGenerating()) {
323
- // 稳定性检测通过,检查是否同时有完成标记
324
- if (hasCompletionMarker) {
325
- logger.clearLine();
326
- logger.dim('Completion confirmed (stable + marker)');
327
- break;
328
- }
329
- }
330
- stableCount = 0;
331
- stableStart = null;
332
- } else {
333
- stableStart = null;
334
- }
315
+ lastCheckTime = Date.now();
316
+ logger.dim(`Stable count: ${stableCount}/2 (${text.length} chars)`);
335
317
  }
318
+ } else {
319
+ // 内容变化,重置
320
+ lastText = text;
321
+ stableCount = 0;
322
+ lastCheckTime = Date.now();
336
323
  }
337
324
 
338
325
  // ── 完成标记检测 ──
@@ -355,13 +342,19 @@ class YiyanBrowser {
355
342
 
356
343
  if (detected) {
357
344
  hasCompletionMarker = true;
358
- // 有标记,检查稳定性是否也通过
359
- if (stableCount >= 2 && lastText.length > 50) {
345
+ }
346
+
347
+ // ── 完成判断:标记出现 + 连续两次稳定 + _isGenerating 确认 ──
348
+ if (hasCompletionMarker && stableCount >= 2) {
349
+ if (!await this._isGenerating()) {
360
350
  await this.page.waitForTimeout(500);
361
351
  logger.clearLine();
362
- logger.dim('Completion confirmed (marker + stable)');
352
+ logger.success('Response complete');
363
353
  break;
364
354
  }
355
+ // _isGenerating 说还在生成,重置计数继续等待
356
+ stableCount = 0;
357
+ lastCheckTime = Date.now();
365
358
  }
366
359
 
367
360
  // Progress indicator