fix: 修复豆包选择模型,更正豆包超时时间跟随配置文件 (closes #34)

This commit is contained in:
foxhui
2026-03-26 21:04:50 +08:00
Unverified
parent c234943fc2
commit b87d900cd8
2 changed files with 23 additions and 8 deletions
+7
View File
@@ -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
+16 -8
View File
@@ -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();
}