yiyan-browser-agent 1.8.1 → 1.8.3

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 +20 -26
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yiyan-browser-agent",
3
- "version": "1.8.1",
3
+ "version": "1.8.3",
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
@@ -297,12 +297,11 @@ class YiyanBrowser {
297
297
  if (!appeared) logger.warn('Response may have been delayed — continuing to wait...');
298
298
 
299
299
  // Phase 2: wait for completion
300
- // 条件: dialogCardBottom 出现 + answer稳定 + 思考区域稳定
300
+ // 条件: 思考区域和答案区域都稳定不变
301
301
  let lastText = '';
302
302
  let lastThinkingText = '';
303
303
  let stableCount = 0;
304
- let thinkingStableCount = 0;
305
- let lastCheckTime = Date.now();
304
+ let lastStableTime = Date.now();
306
305
  let dotCount = 0;
307
306
  let hasCompletionMarker = false;
308
307
 
@@ -321,28 +320,24 @@ class YiyanBrowser {
321
320
  return { text, exists: true };
322
321
  });
323
322
 
324
- // ── 思考区域稳定性检测 ──
325
- if (thinkingInfo.text === lastThinkingText && thinkingInfo.text.length > 5) {
326
- if (Date.now() - lastCheckTime >= stableDelay) {
327
- thinkingStableCount++;
328
- logger.dim(`Thinking stable: ${thinkingStableCount}/2 (${thinkingInfo.text.length} chars)`);
329
- }
330
- } else if (thinkingInfo.text !== lastThinkingText) {
331
- lastThinkingText = thinkingInfo.text;
332
- thinkingStableCount = 0;
333
- lastCheckTime = Date.now();
334
- }
323
+ // ── 统一稳定性检测:两者都不变才算稳定 ──
324
+ const thinkingStable = thinkingInfo.text === lastThinkingText;
325
+ const answerStable = text === lastText;
326
+ const hasContent = thinkingInfo.text.length > 5 && text.length > 5;
335
327
 
336
- // ── answer 稳定性检测 ──
337
- if (text === lastText && text.length > 50) {
338
- if (Date.now() - lastCheckTime >= stableDelay) {
328
+ if (thinkingStable && answerStable && hasContent) {
329
+ // 两者都稳定且有内容,检查稳定时间
330
+ if (Date.now() - lastStableTime >= stableDelay) {
339
331
  stableCount++;
340
- logger.dim(`Answer stable: ${stableCount}/2 (${text.length} chars)`);
332
+ lastStableTime = Date.now();
333
+ logger.dim(`Both stable: ${stableCount}/2 (thinking: ${thinkingInfo.text.length} chars, answer: ${text.length} chars)`);
341
334
  }
342
- } else if (text !== lastText) {
335
+ } else {
336
+ // 任一变化,重置
337
+ lastThinkingText = thinkingInfo.text;
343
338
  lastText = text;
344
339
  stableCount = 0;
345
- lastCheckTime = Date.now();
340
+ lastStableTime = Date.now();
346
341
  }
347
342
 
348
343
  // ── 完成标记检测 ──
@@ -368,10 +363,10 @@ class YiyanBrowser {
368
363
  }
369
364
 
370
365
  // ── 完成判断 ──
371
- // 条件1: 标记出现 + answer稳定 + 思考区域稳定
372
- // 条件2(备用): 两者都稳定达到 4 次(即使没有完成标记)
373
- const condition1 = hasCompletionMarker && stableCount >= 2 && thinkingStableCount >= 2;
374
- const condition2 = stableCount >= 4 && thinkingStableCount >= 4;
366
+ // 条件1: 标记出现 + 两者都稳定 2
367
+ // 条件2(备用): 两者都稳定 3 次(即使没有完成标记)
368
+ const condition1 = hasCompletionMarker && stableCount >= 2;
369
+ const condition2 = stableCount >= 3;
375
370
 
376
371
  if (condition1 || condition2) {
377
372
  // 检查 _isGenerating 作为最终确认
@@ -383,8 +378,7 @@ class YiyanBrowser {
383
378
  }
384
379
  // _isGenerating 说还在生成,重置计数继续等待
385
380
  stableCount = 0;
386
- thinkingStableCount = 0;
387
- lastCheckTime = Date.now();
381
+ lastStableTime = Date.now();
388
382
  }
389
383
 
390
384
  // Progress indicator