| 592 | // abort on cancellation instead of blocking on an undrained buffer. |
| 593 | // serverStreamError is an error the SERVER reported inside the SSE stream, as |
| 594 | // opposed to a transport failure. Typed so the replay path can tell the two |
| 595 | // apart: resending a request the server already refused just repeats the refusal. |
| 596 | type serverStreamError struct{ msg string } |
| 597 | |
| 598 | func (e *serverStreamError) Error() string { |
| 599 | return "the server reported a stream error: " + e.msg |
| 600 | } |
| 601 | |
| 602 | func readSSE(parent context.Context, body io.Reader, budget cloud.BudgetStatus, out chan<- Event, onFrame func(output bool)) (*chmctx.Message, int, int, error) { |
| 603 | scanner := bufio.NewScanner(body) |
| 604 | scanner.Buffer(make([]byte, 1<<16), 4<<20) |
| 605 | |
| 606 | var ( |
| 607 | fullContent strings.Builder |
| 608 | slots = map[int]*toolSlot{} |