Merge pull request #883 from zhbdesign/patch-5

优化停止,出现API Error: Stream ended without receiving any events
This commit is contained in:
程序员阿江-Relakkes 2026-06-22 22:10:06 +08:00 committed by GitHub
commit dbb2ad08ac
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 }