pub struct AiSdkEncoder { /* private fields */ }Expand description
Stateful encoder for AI SDK v6 UI Message Stream protocol.
Tracks text block lifecycle (open/close) across tool calls, ensuring
text-start and text-end are always properly paired. This mirrors the
pattern used by AG-UI encoders for AG-UI.
§Text lifecycle rules
TextDeltawith text closed → prependtext-start, open textToolCallStartwith text open → prependtext-end, close textRunFinishwith text open → prependtext-endbeforefinishError→ terminal, notext-endneeded
Implementations§
Source§impl AiSdkEncoder
impl AiSdkEncoder
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new encoder.
The encoder is fully initialized when the first RunStart event
arrives, which sets the message_id from the run ID.
Sourcepub fn message_id(&self) -> &str
pub fn message_id(&self) -> &str
Get the message ID.
Sourcepub fn on_agent_event(&mut self, ev: &AgentEvent) -> Vec<UIStreamEvent>
pub fn on_agent_event(&mut self, ev: &AgentEvent) -> Vec<UIStreamEvent>
Convert an AgentEvent to UI stream events with proper text lifecycle.
Trait Implementations§
Source§impl Debug for AiSdkEncoder
impl Debug for AiSdkEncoder
Source§impl Default for AiSdkEncoder
impl Default for AiSdkEncoder
Source§impl Transcoder for AiSdkEncoder
impl Transcoder for AiSdkEncoder
Source§type Input = AgentEvent
type Input = AgentEvent
Input item type consumed by this transcoder.
Source§type Output = UIStreamEvent
type Output = UIStreamEvent
Output item type produced by this transcoder.
Source§fn transcode(&mut self, item: &AgentEvent) -> Vec<UIStreamEvent>
fn transcode(&mut self, item: &AgentEvent) -> Vec<UIStreamEvent>
Map one input item to zero or more output items.
Auto Trait Implementations§
impl Freeze for AiSdkEncoder
impl RefUnwindSafe for AiSdkEncoder
impl Send for AiSdkEncoder
impl Sync for AiSdkEncoder
impl Unpin for AiSdkEncoder
impl UnwindSafe for AiSdkEncoder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more