yiyan-browser-agent 1.6.5 → 1.6.7
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.
- package/package.json +1 -1
- package/src/browser.js +50 -17
package/package.json
CHANGED
package/src/browser.js
CHANGED
|
@@ -281,54 +281,87 @@ class YiyanBrowser {
|
|
|
281
281
|
const stableDelay = config.STABLE_DELAY;
|
|
282
282
|
const start = Date.now();
|
|
283
283
|
|
|
284
|
-
// Phase 1: wait for
|
|
284
|
+
// Phase 1: wait for response container to appear
|
|
285
285
|
const initialCount = await this._getMessageCount();
|
|
286
|
-
let
|
|
286
|
+
let appeared = false;
|
|
287
287
|
|
|
288
288
|
for (let i = 0; i < 40; i++) {
|
|
289
289
|
const count = await this._getMessageCount();
|
|
290
|
-
if (count > initialCount) {
|
|
290
|
+
if (count > initialCount) {
|
|
291
|
+
appeared = true;
|
|
292
|
+
break;
|
|
293
|
+
}
|
|
291
294
|
await this.page.waitForTimeout(200);
|
|
292
295
|
}
|
|
293
296
|
|
|
294
297
|
if (!appeared) logger.warn('Response may have been delayed — continuing to wait...');
|
|
295
298
|
|
|
296
|
-
// Phase 2: wait for
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
let
|
|
300
|
-
let
|
|
299
|
+
// Phase 2: wait for completion
|
|
300
|
+
// 主要:dialogCardBottom 出现
|
|
301
|
+
// 备用:内容稳定 + _isGenerating() 确认
|
|
302
|
+
let lastText = '';
|
|
303
|
+
let stableStart = null;
|
|
304
|
+
let stableCount = 0;
|
|
305
|
+
let dotCount = 0;
|
|
301
306
|
|
|
302
307
|
while (Date.now() - start < timeout) {
|
|
303
308
|
const text = await this._extractLastMessage();
|
|
304
309
|
|
|
310
|
+
// ── 稳定性检测(备用退出路径)──
|
|
305
311
|
if (text !== lastText) {
|
|
306
312
|
lastText = text;
|
|
307
313
|
stableStart = null;
|
|
308
|
-
stableCount = 0;
|
|
309
|
-
} else if (text.length >
|
|
314
|
+
stableCount = 0;
|
|
315
|
+
} else if (text.length > 50) { // 内容足够长才进入稳定检测
|
|
310
316
|
if (!stableStart) stableStart = Date.now();
|
|
311
317
|
else if (Date.now() - stableStart >= stableDelay) {
|
|
312
|
-
// 增加稳定性计数
|
|
313
318
|
stableCount++;
|
|
314
319
|
|
|
315
|
-
//
|
|
316
|
-
if (stableCount >= 2) {
|
|
317
|
-
if (!await this._isGenerating())
|
|
318
|
-
|
|
320
|
+
// 连续稳定检测 + _isGenerating 确认
|
|
321
|
+
if (stableCount >= 2) {
|
|
322
|
+
if (!await this._isGenerating()) {
|
|
323
|
+
logger.clearLine();
|
|
324
|
+
logger.dim('Stable completion detected');
|
|
325
|
+
break;
|
|
326
|
+
}
|
|
327
|
+
stableCount = 0;
|
|
319
328
|
stableStart = null;
|
|
320
329
|
} else {
|
|
321
|
-
// 第一次稳定,继续等待下一次检测
|
|
322
330
|
stableStart = null;
|
|
323
331
|
}
|
|
324
332
|
}
|
|
325
333
|
}
|
|
326
334
|
|
|
335
|
+
// ── 完成标记检测(主要退出路径)──
|
|
336
|
+
const hasCompletion = await this.page.evaluate(() => {
|
|
337
|
+
const selectors = [
|
|
338
|
+
'.dialogCardBottom__qoXjps3z',
|
|
339
|
+
'[class*="dialogCardBottom"]',
|
|
340
|
+
'[class*="dialog-bottom"]',
|
|
341
|
+
'[class*="response-footer"]',
|
|
342
|
+
];
|
|
343
|
+
for (const sel of selectors) {
|
|
344
|
+
const el = document.querySelector(sel);
|
|
345
|
+
if (el) {
|
|
346
|
+
const s = window.getComputedStyle(el);
|
|
347
|
+
if (s.display !== 'none' && s.visibility !== 'hidden') return true;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
return false;
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
if (hasCompletion) {
|
|
354
|
+
await this.page.waitForTimeout(500);
|
|
355
|
+
logger.clearLine();
|
|
356
|
+
logger.dim('Completion marker detected');
|
|
357
|
+
break;
|
|
358
|
+
}
|
|
359
|
+
|
|
327
360
|
// Progress indicator
|
|
328
361
|
dotCount = (dotCount + 1) % 4;
|
|
329
362
|
logger.thinking(`Receiving response${'.'.repeat(dotCount)} (${text.length} chars)`);
|
|
330
363
|
|
|
331
|
-
// 等待 200ms 给 DOM
|
|
364
|
+
// 等待 200ms 给 DOM 时间更新
|
|
332
365
|
await this.page.waitForTimeout(200);
|
|
333
366
|
}
|
|
334
367
|
|