ProtecteddoneProtectedfailureProtected ReadonlyflushProtectednotifyProtected ReadonlyqueueEnds the stream. A given error is raised to the consumer once the buffered parts are drained.
Optionalerror: unknownResolves once everything pushed so far has been taken by the consumer.
Needed because a tool call has to be reported before the tool runs: the caller creates the record of the call from the stream, and the tool handler then completes that record. Handing the part over and invoking the handler in the same turn would leave the handler with nothing to complete.
ProtectedreleaseProtectedwake
Collects the stream parts produced by the session events and by the tool handlers, and hands them to the consuming generator as they arrive.
A buffer is needed because the parts originate from callbacks rather than from a stream we can await, and because the tool handlers of a turn run while its response is still being produced.