优化停止,出现API Error: Stream ended without receiving any events

优化停止,出现API Error: Stream ended without receiving any events
This commit is contained in:
zhb 2026-06-21 13:35:52 +08:00 committed by GitHub
parent b777e31b6a
commit eb5a1b0278
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1407,6 +1407,13 @@ export function translateCliMessage(cliMsg: any, sessionId: string): ServerMessa
switch (cliMsg.type) {
case 'assistant': {
if (cliMsg.error || cliMsg.isApiErrorMessage) {
// If the user requested stop, suppress API errors caused by the
// stream being interrupted (e.g. "Stream ended without receiving
// any events"). The result message handler also checks this flag,
// but the assistant error arrives first and would leak to the UI.
if (sessionStopRequested.has(sessionId)) {
return []
}
const message = extractAssistantText(cliMsg) || cliMsg.error || 'Unknown API error'
const code = typeof cliMsg.error === 'string' ? cliMsg.error : 'API_ERROR'
streamState.lastApiError = { message, code }