diff --git a/packages/acp-core/protocol/ClaudeCliProtocol.js b/packages/acp-core/protocol/ClaudeCliProtocol.js index f55eaa6..4050653 100644 --- a/packages/acp-core/protocol/ClaudeCliProtocol.js +++ b/packages/acp-core/protocol/ClaudeCliProtocol.js @@ -96,7 +96,20 @@ class ClaudeCliProtocol extends EventEmitter { const event = JSON.parse(line); this._handleStreamEvent(event); } catch (e) { - // 非 JSON 行,忽略 + // 非 JSON 行:拦截纯文本的崩溃日志或 API 拒绝日志 + const msg = line.trim(); + if (msg) { + console.log(`[ClaudeCliProtocol] 📝 非JSON文本:`, msg.substring(0, 300)); + // 触发类似 stderr 的检测逻辑 + if (this._promptReject && /error|rate.?limit|429|401|403|authentication|api.?key|quota|billing|失败/i.test(msg)) { + const err = new Error(`API 请求失败 (Raw): ${msg.substring(0, 500)}`); + console.error(`[ClaudeCliProtocol] 拦截到底层纯文本错误:`, err.message); + if (this._idleTimer) { clearTimeout(this._idleTimer); this._idleTimer = null; } + this._promptReject(err); + this._promptResolve = null; + this._promptReject = null; + } + } } } }); diff --git a/server/routes/agent-chat.js b/server/routes/agent-chat.js index 40bfde4..beb95cf 100644 --- a/server/routes/agent-chat.js +++ b/server/routes/agent-chat.js @@ -1753,7 +1753,7 @@ router.post('/:agentId/chat', async (req, res) => { entry.protocol.on('disconnected', onDisconnected); // 发出状态以便前端展示不卡壳 - sendSSE('agent_output', { agent: agentId, message: `_[系统正在通过 \`${fullSystemConfig.model}\` 请求响应...]_\\\n\\\n` }); + sendSSE('agent_output', { agent: agentId, message: `_[请求已发送,等待底层大模型响应...]_\\\n\\\n` }); // 发送 prompt 并等待完成 await entry.protocol.sendPrompt(prompt);