* Is this a max_output_tokens error message? If so, the streaming loop should * withhold it from SDK callers until we know whether the recovery loop can * continue. Yielding early leaks an intermediate error to SDK callers (e.g. * cowork/desktop) that terminate the session on any `error` field —
( msg: Message | StreamEvent | undefined, )
| 213 | * Mirrors reactiveCompact.isWithheldPromptTooLong. |
| 214 | */ |
| 215 | function isWithheldMaxOutputTokens( |
| 216 | msg: Message | StreamEvent | undefined, |
| 217 | ): msg is AssistantMessage { |
| 218 | return msg?.type === 'assistant' && msg.apiError === 'max_output_tokens' |
| 219 | } |
| 220 | |
| 221 | function isMalformedToolOutputApiError( |
| 222 | msg: Message | StreamEvent | undefined, |