pub struct StreamingSession { /* private fields */ }Expand description
A live streaming session connected to an agent subprocess.
stdin is piped for sending NDJSON messages, stdout is piped for reading NDJSON events. The session owns the child process.
Implementations§
Source§impl StreamingSession
impl StreamingSession
Sourcepub async fn send(&mut self, message: &str) -> Result<()>
pub async fn send(&mut self, message: &str) -> Result<()>
Send a raw NDJSON line to the agent’s stdin.
The message should be a single JSON object (no trailing newline needed).
Sourcepub async fn send_user_message(&mut self, content: &str) -> Result<()>
pub async fn send_user_message(&mut self, content: &str) -> Result<()>
Send a user message to the agent.
Formats the content as a {"type":"user_message","content":"..."} NDJSON line.
§Mid-turn semantics
The effect of calling this while the agent is still producing a
response on the current turn is provider-specific. Check
ProviderCapability::features.streaming_input.semantics at runtime
to branch on behavior. The possible values are:
"queue"— buffered and delivered at the next turn boundary; the current turn runs to completion. This is Claude’s behavior, which is the only provider currently exposing aStreamingSession."interrupt"— cancels the current turn and starts a new one with the new input."between-turns-only"— mid-turn sends are an error or no-op; wait for the current turn to finish before sending.
See the module-level documentation for the full matrix.
Sourcepub async fn next_event(&mut self) -> Result<Option<Event>>
pub async fn next_event(&mut self) -> Result<Option<Event>>
Read the next unified event from the agent’s stdout.
Lines are parsed as Claude’s native stream-json schema and then
converted into the unified Event enum. Events that don’t map to a
user-visible unified event (e.g. thinking blocks) are skipped
transparently, as are blank and unparseable lines.
A unified Result event is returned at the end of each agent turn;
callers can use it as a turn boundary. Ok(None) is returned only
when the subprocess closes its stdout (EOF).
Sourcepub fn close_input(&mut self)
pub fn close_input(&mut self)
Close the stdin pipe, signaling no more input to the agent.