yiyan-browser-agent 1.6.5 → 1.6.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 +36 -31
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yiyan-browser-agent",
3
- "version": "1.6.5",
3
+ "version": "1.6.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
@@ -278,57 +278,62 @@ class YiyanBrowser {
278
278
  */
279
279
  async waitForResponse() {
280
280
  const timeout = config.RESPONSE_TIMEOUT;
281
- const stableDelay = config.STABLE_DELAY;
282
281
  const start = Date.now();
283
282
 
284
- // Phase 1: wait for a new message to appear
283
+ // Phase 1: wait for response container to appear
285
284
  const initialCount = await this._getMessageCount();
286
- let appeared = false;
285
+ let appeared = false;
287
286
 
288
287
  for (let i = 0; i < 40; i++) {
289
288
  const count = await this._getMessageCount();
290
- if (count > initialCount) { appeared = true; break; }
289
+ if (count > initialCount) {
290
+ appeared = true;
291
+ break;
292
+ }
291
293
  await this.page.waitForTimeout(200);
292
294
  }
293
295
 
294
296
  if (!appeared) logger.warn('Response may have been delayed — continuing to wait...');
295
297
 
296
- // Phase 2: wait for text to stabilise (with multiple checks)
297
- let lastText = '';
298
- let stableStart = null;
299
- let stableCount = 0; // 连续稳定次数计数
298
+ // Phase 2: wait for completion marker (dialogCardBottom) to appear
300
299
  let dotCount = 0;
300
+ let lastLength = 0;
301
301
 
302
302
  while (Date.now() - start < timeout) {
303
303
  const text = await this._extractLastMessage();
304
+ lastLength = text.length;
304
305
 
305
- if (text !== lastText) {
306
- lastText = text;
307
- stableStart = null;
308
- stableCount = 0; // 内容变化,重置计数
309
- } else if (text.length > 0) {
310
- if (!stableStart) stableStart = Date.now();
311
- else if (Date.now() - stableStart >= stableDelay) {
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;
306
+ // Progress indicator
307
+ dotCount = (dotCount + 1) % 4;
308
+ logger.thinking(`Receiving response${'.'.repeat(dotCount)} (${lastLength} chars)`);
309
+
310
+ // 检测完成标记:dialogCardBottom 出现
311
+ const hasCompletion = await this.page.evaluate(() => {
312
+ const selectors = [
313
+ '.dialogCardBottom__qoXjps3z',
314
+ '[class*="dialogCardBottom"]',
315
+ '[class*="dialog-bottom"]',
316
+ '[class*="response-footer"]',
317
+ ];
318
+ for (const sel of selectors) {
319
+ const el = document.querySelector(sel);
320
+ if (el) {
321
+ const s = window.getComputedStyle(el);
322
+ if (s.display !== 'none' && s.visibility !== 'hidden') return true;
323
323
  }
324
324
  }
325
- }
325
+ return false;
326
+ });
326
327
 
327
- // Progress indicator
328
- dotCount = (dotCount + 1) % 4;
329
- logger.thinking(`Receiving response${'.'.repeat(dotCount)} (${text.length} chars)`);
328
+ if (hasCompletion) {
329
+ // 完成标记出现,等待一小段时间确保内容完整
330
+ await this.page.waitForTimeout(500);
331
+ logger.clearLine();
332
+ logger.dim('Completion marker detected, finishing...');
333
+ break;
334
+ }
330
335
 
331
- // 等待 200ms 给 DOM 时间更新,避免高频轮询读取不完整内容
336
+ // 等待 200ms 给 DOM 时间更新
332
337
  await this.page.waitForTimeout(200);
333
338
  }
334
339