fix: 修复错误信息、reasoning_content 透传及豆包模型菜单问题

- 修正 Playwright TimeoutError 提示为页面操作超时(非网络问题)
- 新增 CLICK_TIMEOUT 错误归一化处理,标记为 retryable
- buildChatCompletion/buildChatCompletionChunk 支持 reasoningContent 参数
- doubao_text 模型选择菜单增加重试逻辑(最多 3 次),waitFor 超时从 2s 改为 5s
This commit is contained in:
daidai
2026-04-07 16:32:55 +08:00
Unverified
parent b5c9a79dfc
commit 04bb4a70d2
3 changed files with 21 additions and 10 deletions
+13 -5
View File
@@ -60,18 +60,26 @@ async function generate(context, prompt, imgPaths, modelId, meta = {}) {
.first();
let selectorExists = false;
try {
await modelSelectorBtn.waitFor({ state: 'attached', timeout: 1000 });
await modelSelectorBtn.waitFor({ state: 'attached', timeout: 5000 });
selectorExists = true;
} catch (e) {
selectorExists = false;
}
if (selectorExists) {
await safeClick(page, modelSelectorBtn, { bias: 'button' });
await sleep(300, 500);
const menuItem = page.getByRole('menuitem', { name: modelMenuName });
await menuItem.waitFor({ state: 'visible', timeout: 5000 });
// 点击模型选择按钮,最多重试 3 次(菜单偶尔不弹出)
for (let attempt = 1; attempt <= 3; attempt++) {
await sleep(500, 1000);
await safeClick(page, modelSelectorBtn, { bias: 'button' });
try {
await menuItem.waitFor({ state: 'visible', timeout: 3000 });
break; // 菜单弹出,退出重试
} catch {
logger.warn('适配器', `模型菜单未弹出,重试 ${attempt}/3`, meta);
if (attempt === 3) throw new Error('模型选择菜单未弹出');
}
}
await safeClick(page, menuItem, { bias: 'button' });
await sleep(200, 400);
}
+8 -3
View File
@@ -68,10 +68,15 @@ export function normalizePageError(err, meta = {}) {
logger.error('适配器', err.message, meta);
return { error: err.message, code: ADAPTER_ERRORS.TIMEOUT_ERROR, retryable: true };
}
// 兼容原生 TimeoutError (其他地方抛出的)
// CLICK_TIMEOUT: safeClick 内部超时
if (err.message?.includes('CLICK_TIMEOUT')) {
logger.error('适配器', `点击操作超时: ${err.message}`, meta);
return { error: err.message, code: ADAPTER_ERRORS.TIMEOUT_ERROR, retryable: true };
}
// 兼容原生 TimeoutError (Playwright 元素操作超时等)
if (err.name === 'TimeoutError' || err.message?.includes('Timeout')) {
logger.error('适配器', '请求超时', meta);
return { error: '请求超时, 请检查网络或稍后重试', code: ADAPTER_ERRORS.TIMEOUT_ERROR, retryable: true };
logger.error('适配器', `页面操作超时: ${err.message}`, meta);
return { error: '页面操作超时, 页面可能未正常加载或元素未找到', code: ADAPTER_ERRORS.TIMEOUT_ERROR, retryable: true };
}
// PAGE_ERROR_DETECTED: waitApiResponse 页面 UI 中检测到的错误关键词
if (err.message?.startsWith('PAGE_ERROR_DETECTED:')) {
-2
View File
@@ -114,7 +114,6 @@ export function buildChatCompletion(content, modelName, reasoningContent) {
role: 'assistant',
content: content
};
if (reasoningContent) {
message.reasoning_content = reasoningContent;
}
@@ -142,7 +141,6 @@ export function buildChatCompletion(content, modelName, reasoningContent) {
*/
export function buildChatCompletionChunk(content, modelName, finishReason = 'stop', reasoningContent) {
const delta = { content };
if (reasoningContent) {
delta.reasoning_content = reasoningContent;
}