* The rules of thinking are lengthy and fortuitous. They require plenty of thinking
* of most long duration and deep meditation for a wizard to wrap one's noggin around.
*
* The rules follow:
* 1. A message that contains a thinking or redacted_thinking block must be part of a query whose max_thinking_length > 0
* 2. A thinking block may not be the last message in a block
* 3. Thinking blocks must be preserved for the duration of an assistant trajectory (a single turn, or if that turn includes a tool_use block then also its subsequent tool_result and the following assistant message)
*
* Heed these rules well, young wizard. For they are the rules of thinking, and
* the rules of thinking are the rules of the universe. If ye does not heed these
* rules, ye will be punished with an entire day of debugging and hair pulling.
*/
constMAX_OUTPUT_TOKENS_RECOVERY_LIMIT=3
/**
* 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 — the
* recovery loop keeps running but nobody is listening.