diff --git a/backend-integration/api-proxy.js b/backend-integration/api-proxy.js index 94734a3b..d4821948 100644 --- a/backend-integration/api-proxy.js +++ b/backend-integration/api-proxy.js @@ -413,15 +413,17 @@ async function handleChat(req, res) { recordProxyFailure(curProv); console.error(`[代理] ${curProv} 请求失败: ${err.message}`); - if (isLastAttempt && !res.headersSent) { + // If headers already sent (partial streaming started), can't switch provider + if (res.headersSent) return; + + if (isLastAttempt) { jsonResponse(res, 502, { error: true, code: 'ALL_PROVIDERS_FAILED', message: '所有模型提供商均请求失败,请稍后重试' }); } - // If not last attempt and headers not sent, try next provider - if (res.headersSent) return; + // Otherwise continue to next provider } } } diff --git a/src/brain/memory-manager.js b/src/brain/memory-manager.js index ccafaeb8..3d2c4e17 100644 --- a/src/brain/memory-manager.js +++ b/src/brain/memory-manager.js @@ -55,8 +55,8 @@ function generateCandidates(text, source = 'user') { const end = Math.min(text.length, idx + 80); const excerpt = text.slice(start, end).replace(/\n/g, ' ').trim(); - // 检查中期记忆中的出现次数 - const memKey = type + ':' + excerpt.slice(0, 20); + // 检查中期记忆中的出现次数(使用类型+摘要前40字符作为键,降低碰撞风险) + const memKey = type + ':' + excerpt.slice(0, 40).replace(/\s+/g, '_'); const taskEntry = taskMemory.get(memKey) || { count: 0 }; taskEntry.count++; taskEntry.lastSeen = Date.now(); diff --git a/src/brain/model-router.js b/src/brain/model-router.js index a6cb3557..f203d4a5 100644 --- a/src/brain/model-router.js +++ b/src/brain/model-router.js @@ -100,7 +100,7 @@ function isInCooldown(provider, model) { failureLog.delete(key); return false; } - return entry.count >= 3; // 5分钟内失败3次以上才冷却 + return entry.count >= 3; // 5分钟内失败3次及以上才冷却 } /** diff --git a/src/schemas/hli/brain/prompt.schema.json b/src/schemas/hli/brain/prompt.schema.json index 1a81c99f..c49c9e43 100644 --- a/src/schemas/hli/brain/prompt.schema.json +++ b/src/schemas/hli/brain/prompt.schema.json @@ -13,6 +13,7 @@ "ghUser": { "type": "string", "description": "GitHub 用户名" }, "role": { "type": "string", "enum": ["founder", "supreme", "main", "dev", "guest"] }, "mode": { "type": "string", "enum": ["chat", "build", "review", "brain"] }, + "text": { "type": "string", "description": "当前用户输入文本(用于自动检测模式)" }, "devStatus": { "type": "object", "description": "开发者状态" } } },