Skip to main content

Module stream

Module stream 

Source

Functions§

append_pending
apply_context
Convert a resolved crate::context::EffectiveContext into the three optional fields that are stamped onto a StreamEventRequest.
drain_pending
inline_offset_bump
Record-count offset arithmetic for the inline (fileless) path, mirroring the byte-offset semantics of read_new_transcript_lines: returns (send_offset, next_offset) where send_offset is stamped on the request as transcript_offset (base for the server’s per-line chunk_index) and next_offset is persisted to .stream_offset.
inline_tool_is_error
Derive the event-level tool-error flag from inline transcript records. OpenCode tool events carry no tool_use_id, so extract_is_error_from_transcript can’t run; instead the plugin forwards a toolResult record whose isError signals the outcome. Returns Some(true|false) for the first toolResult record found, or None when there is none (non-tool events).
read_new_transcript_lines
Returns (lines, start_offset, end_offset): start_offset is the seek position read from offset_path (0 if absent), and end_offset is the byte offset after the last line read (the old bytes_read).
resolve_session_paths
Resolve the project root and session directory for a stream hook invocation.
resolve_transcript_source
Choose the transcript source for a stream event. Inline records (from a plugin-based agent like OpenCode) win over the file-read result whenever the hook event carries them — INCLUDING an empty vec, so an event with no new records (e.g. OpenCode stop) preserves the prior record-count offset instead of resetting it to the file-path’s 0.
run_stream
stamp_agent
Stamp the agent identity onto a request’s tool + protocol_version. Factored out so the mapping is testable without the network/FS-bound run_stream.