Skip to main content

codex_convert_proxy/convert/streaming/
events.rs

1//! Response stream event types for the Responses API streaming protocol.
2
3use crate::types::response_api::ResponseObject;
4
5use super::state::ResponseRequestContext;
6
7/// SSE event types for Responses API streaming.
8#[derive(Debug, Clone)]
9pub enum ResponseStreamEvent {
10    /// Initial response created event.
11    Created {
12        id: String,
13        model: String,
14        status: String,
15        created_at: i64,
16        request_context: Option<ResponseRequestContext>,
17    },
18    /// Response is in progress.
19    InProgress {
20        id: String,
21        model: String,
22        status: String,
23        created_at: i64,
24        request_context: Option<ResponseRequestContext>,
25    },
26    /// Output item was added.
27    OutputItemAdded {
28        output_index: u32,
29        item_id: String,
30        item_type: String,
31        role: Option<String>,
32        call_id: Option<String>,
33        name: Option<String>,
34    },
35    /// Content part was added.
36    ContentPartAdded {
37        item_id: String,
38        output_index: u32,
39        content_index: u32,
40        part_type: String,
41    },
42    /// Output text delta (content chunk).
43    OutputTextDelta {
44        item_id: String,
45        output_index: u32,
46        content_index: u32,
47        delta: String,
48    },
49    /// Output text done.
50    OutputTextDone {
51        item_id: String,
52        output_index: u32,
53        content_index: u32,
54        text: String,
55    },
56    /// Content part done.
57    ContentPartDone {
58        item_id: String,
59        output_index: u32,
60        content_index: u32,
61        part_type: String,
62        text: String,
63    },
64    /// Output item done.
65    OutputItemDone {
66        output_index: u32,
67        item_id: String,
68        item_type: String,
69        role: Option<String>,
70        call_id: Option<String>,
71        name: Option<String>,
72        arguments: Option<String>,
73        text: Option<String>,
74        refusal: Option<String>,
75        summary: Option<Vec<crate::types::response_api::ReasoningSummaryPart>>,
76    },
77    /// Reasoning output item added.
78    ReasoningAdded {
79        output_index: u32,
80        item_id: String,
81    },
82    /// Reasoning text delta.
83    ReasoningDelta {
84        item_id: String,
85        output_index: u32,
86        content_index: u32,
87        delta: String,
88    },
89    /// Reasoning text done.
90    ReasoningTextDone {
91        item_id: String,
92        output_index: u32,
93        content_index: u32,
94        text: String,
95    },
96    /// Reasoning summary text delta.
97    ReasoningSummaryTextDelta {
98        item_id: String,
99        output_index: u32,
100        content_index: u32,
101        delta: String,
102    },
103    /// Reasoning summary text done.
104    ReasoningSummaryTextDone {
105        item_id: String,
106        output_index: u32,
107        content_index: u32,
108        text: String,
109    },
110    /// Function call arguments delta.
111    FunctionCallArgumentsDelta {
112        output_index: u32,
113        item_id: String,
114        call_id: Option<String>,
115        delta: String,
116    },
117    /// Function call arguments done.
118    FunctionCallArgumentsDone {
119        output_index: u32,
120        item_id: String,
121        call_id: String,
122        arguments: String,
123    },
124    /// Response completed with final object.
125    Completed {
126        response: Box<ResponseObject>,
127    },
128    /// Response error event.
129    Error {
130        id: Option<String>,
131        error_type: String,
132        message: String,
133        code: Option<String>,
134    },
135    /// Response failed event.
136    Failed {
137        id: String,
138        model: String,
139        status: String,
140        created_at: i64,
141    },
142    /// Response incomplete event.
143    Incomplete {
144        id: String,
145        model: String,
146        status: String,
147        created_at: i64,
148        reason: Option<String>,
149    },
150    /// Refusal content delta.
151    RefusalDelta {
152        item_id: String,
153        output_index: u32,
154        content_index: u32,
155        delta: String,
156    },
157    /// Refusal content done.
158    RefusalDone {
159        item_id: String,
160        output_index: u32,
161        content_index: u32,
162        refusal: String,
163    },
164}