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.
- package/package.json +1 -1
- package/src/browser.js +36 -31
package/package.json
CHANGED
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
|
|
283
|
+
// Phase 1: wait for response container to appear
|
|
285
284
|
const initialCount = await this._getMessageCount();
|
|
286
|
-
let
|
|
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) {
|
|
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
|
|
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
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
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
|
-
|
|
328
|
-
|
|
329
|
-
|
|
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
|
|