From b87d900cd846efec645000804bf267f3e21a197a Mon Sep 17 00:00:00 2001 From: foxhui Date: Thu, 26 Mar 2026 21:04:50 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=B1=86=E5=8C=85?= =?UTF-8?q?=E9=80=89=E6=8B=A9=E6=A8=A1=E5=9E=8B=EF=BC=8C=E6=9B=B4=E6=AD=A3?= =?UTF-8?q?=E8=B1=86=E5=8C=85=E8=B6=85=E6=97=B6=E6=97=B6=E9=97=B4=E8=B7=9F?= =?UTF-8?q?=E9=9A=8F=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=20(closes=20#34)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 7 +++++++ src/backend/adapter/doubao_text.js | 24 ++++++++++++++++-------- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e1c460..a336167 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [3.6.0] - 2026-03-26 + +### 🐛 Fixed +- **适配器** + - 再次修复豆包适配器无法点击选择模型的问题 + - 修复豆包超时时间跟随配置文件 + ## [3.5.9] - 2026-03-25 ### 🐛 Fixed diff --git a/src/backend/adapter/doubao_text.js b/src/backend/adapter/doubao_text.js index 1f3e84c..7d1a454 100644 --- a/src/backend/adapter/doubao_text.js +++ b/src/backend/adapter/doubao_text.js @@ -28,7 +28,8 @@ const TARGET_URL = 'https://www.doubao.com/chat/'; * @returns {Promise<{text?: string, reasoning?: string, error?: string}>} */ async function generate(context, prompt, imgPaths, modelId, meta = {}) { - const { page } = context; + const { page, config } = context; + const waitTimeout = config?.backend?.pool?.waitTimeout ?? 120000; // 是否使用深度思考模式 const useThinking = modelId === 'seed-thinking' || modelId === 'seed-pro'; @@ -70,7 +71,7 @@ async function generate(context, prompt, imgPaths, modelId, meta = {}) { try { // 点击上传菜单按钮 - const uploadMenuBtn = page.locator('main button[aria-haspopup="menu"]:not(:has(div[data-testid="deep-thinking-action-button"]))').first(); + const uploadMenuBtn = page.locator('button[aria-haspopup="menu"]:not(:has(div[data-testid="deep-thinking-action-button"]))').first(); await safeClick(page, uploadMenuBtn, { bias: 'button' }); await sleep(300, 500); @@ -97,8 +98,15 @@ async function generate(context, prompt, imgPaths, modelId, meta = {}) { const modelMenuName = MODEL_MENU_MAP[modelId] || MODEL_MENU_MAP['seed']; logger.debug('适配器', `选择模型: ${modelId} -> ${modelMenuName}`, meta); - const modelSelectorBtn = page.locator('main button[aria-haspopup="menu"]:has(div[data-testid="deep-thinking-action-button"])'); - const selectorExists = await modelSelectorBtn.count() > 0; + // 给予 3 秒的缓冲时间等待 React 渲染按钮 + const modelSelectorBtn = page.locator('button[aria-haspopup="menu"]:has(div[data-testid="deep-thinking-action-button"])').first(); + let selectorExists = false; + try { + await modelSelectorBtn.waitFor({ state: 'attached', timeout: 3000 }); + selectorExists = true; + } catch (e) { + selectorExists = false; + } if (selectorExists) { await safeClick(page, modelSelectorBtn, { bias: 'button' }); @@ -122,12 +130,12 @@ async function generate(context, prompt, imgPaths, modelId, meta = {}) { let isResolved = false; const resultPromise = new Promise((resolve, reject) => { - const timeout = setTimeout(() => { + const timeoutId = setTimeout(() => { if (!isResolved) { isResolved = true; - reject(new Error('API_TIMEOUT: 响应超时 (120秒)')); + reject(new Error(`API_TIMEOUT: 响应超时 (${Math.round(waitTimeout / 1000)}秒)`)); } - }, 120000); + }, waitTimeout); // 监听页面响应 const handleResponse = async (response) => { @@ -149,7 +157,7 @@ async function generate(context, prompt, imgPaths, modelId, meta = {}) { if (!isResolved) { isResolved = true; - clearTimeout(timeout); + clearTimeout(timeoutId); page.off('response', handleResponse); resolve(); }