llmkit_core/stream.rs
1//! Streaming response types.
2
3use std::pin::Pin;
4
5use futures_core::Stream;
6
7use crate::error::LlmResult;
8use crate::usage::TokenUsage;
9
10/// A boxed async stream of [`StreamDelta`] items, the unified streaming output
11/// across every provider.
12pub type ChatStream = Pin<Box<dyn Stream<Item = LlmResult<StreamDelta>> + Send>>;
13
14/// One incremental event in a streaming chat response.
15#[derive(Debug, Clone, PartialEq)]
16pub enum StreamDelta {
17 /// A chunk of generated text.
18 Text(String),
19 /// A streamed tool call (arguments may arrive incrementally).
20 ToolCall {
21 /// Provider-assigned tool call id, if known yet.
22 id: Option<String>,
23 /// Tool name, if known yet.
24 name: Option<String>,
25 /// Partial JSON arguments for this delta.
26 input_delta: String,
27 },
28 /// Terminal event carrying final usage.
29 Done {
30 /// Final token usage.
31 usage: TokenUsage,
32 },
33}