Skip to main content

behest_core/
events.rs

1//! Streaming event schema for chat providers.
2
3use serde::{Deserialize, Serialize};
4
5use crate::id::{ModelName, ProviderId};
6use crate::message::{FinishReason, TokenUsage};
7use crate::tool_types::ToolCall;
8
9/// Event emitted by a streaming chat provider.
10#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11#[serde(rename_all = "snake_case", tag = "type")]
12#[non_exhaustive]
13pub enum ChatStreamEvent {
14    /// Stream has started.
15    Started {
16        /// Provider serving the stream.
17        provider: ProviderId,
18        /// Model serving the stream.
19        model: ModelName,
20    },
21    /// Text delta produced by the model.
22    TextDelta {
23        /// Incremental text chunk.
24        delta: String,
25    },
26    /// Tool call has started.
27    ToolCallStarted {
28        /// Provider-generated call identifier.
29        id: String,
30        /// Tool name requested by the model.
31        name: String,
32    },
33    /// Tool call argument JSON delta.
34    ToolCallArgumentsDelta {
35        /// Provider-generated call identifier.
36        id: String,
37        /// Incremental argument chunk.
38        delta: String,
39    },
40    /// Tool call has completed and can be executed.
41    ToolCallCompleted {
42        /// Completed tool call.
43        call: ToolCall,
44    },
45    /// Stream has finished.
46    Finished {
47        /// Reason the provider stopped generation.
48        finish_reason: FinishReason,
49        /// Token accounting, when supplied by the provider.
50        usage: Option<TokenUsage>,
51    },
52}