openai_api_rs/realtime/
server_event.rs

1use serde::{Deserialize, Serialize};
2
3use crate::realtime::types::{
4    APIError, ContentPart, Conversation, Item, RateLimit, Response, Session,
5};
6
7#[derive(Debug, Serialize, Deserialize, Clone)]
8pub struct Error {
9    pub event_id: String,
10    pub error: APIError,
11}
12
13#[derive(Debug, Serialize, Deserialize, Clone)]
14pub struct SessionCreated {
15    pub event_id: String,
16    pub session: Session,
17}
18
19#[derive(Debug, Serialize, Deserialize, Clone)]
20pub struct SessionUpdated {
21    pub event_id: String,
22    pub session: Session,
23}
24
25#[derive(Debug, Serialize, Deserialize, Clone)]
26pub struct ConversationCreated {
27    pub event_id: String,
28    pub conversation: Conversation,
29}
30
31#[derive(Debug, Serialize, Deserialize, Clone)]
32pub struct InputAudioBufferCommited {
33    pub event_id: String,
34    pub previous_item_id: Option<String>,
35    pub item_id: String,
36}
37
38#[derive(Debug, Serialize, Deserialize, Clone)]
39pub struct InputAudioBufferCleared {
40    pub event_id: String,
41}
42
43#[derive(Debug, Serialize, Deserialize, Clone)]
44pub struct InputAudioBufferSpeechStarted {
45    pub event_id: String,
46    pub audio_start_ms: u32,
47    pub item_id: String,
48}
49
50#[derive(Debug, Serialize, Deserialize, Clone)]
51pub struct InputAudioBufferSpeechStopped {
52    pub event_id: String,
53    pub audio_end_ms: u32,
54    pub item_id: String,
55}
56
57#[derive(Debug, Serialize, Deserialize, Clone)]
58pub struct ConversationItemCreated {
59    pub event_id: String,
60    pub previous_item_id: Option<String>,
61    pub item: Item,
62}
63
64#[derive(Debug, Serialize, Deserialize, Clone)]
65pub struct ConversationItemInputAudioTranscriptionCompleted {
66    pub event_id: String,
67    pub item_id: String,
68    pub content_index: u32,
69    pub transcript: String,
70}
71
72#[derive(Debug, Serialize, Deserialize, Clone)]
73pub struct ConversationItemInputAudioTranscriptionFailed {
74    pub event_id: String,
75    pub item_id: String,
76    pub content_index: u32,
77    pub error: APIError,
78}
79
80#[derive(Debug, Serialize, Deserialize, Clone)]
81pub struct ConversationItemTruncated {
82    pub event_id: String,
83    pub item_id: String,
84    pub content_index: u32,
85    pub audio_end_ms: u32,
86}
87
88#[derive(Debug, Serialize, Deserialize, Clone)]
89pub struct ConversationItemDeleted {
90    pub event_id: String,
91    pub item_id: String,
92}
93
94#[derive(Debug, Serialize, Deserialize, Clone)]
95pub struct OutputAudioBufferStarted {
96    pub event_id: String,
97    pub response_id: String,
98}
99
100#[derive(Debug, Serialize, Deserialize, Clone)]
101pub struct OutputAudioBufferStopped {
102    pub event_id: String,
103    pub response_id: String,
104}
105
106#[derive(Debug, Serialize, Deserialize, Clone)]
107pub struct OutputAudioBufferCleared {
108    pub event_id: String,
109    pub response_id: String,
110}
111
112#[derive(Debug, Serialize, Deserialize, Clone)]
113pub struct ResponseCreated {
114    pub event_id: String,
115    pub response: Response,
116}
117
118#[derive(Debug, Serialize, Deserialize, Clone)]
119pub struct ResponseDone {
120    pub event_id: String,
121    pub response: Response,
122}
123
124#[derive(Debug, Serialize, Deserialize, Clone)]
125pub struct ResponseOutputItemAdded {
126    pub event_id: String,
127    pub response_id: String,
128    pub output_index: u32,
129    pub item: Item,
130}
131
132#[derive(Debug, Serialize, Deserialize, Clone)]
133pub struct ResponseOutputItemDone {
134    pub event_id: String,
135    pub response_id: String,
136    pub output_index: u32,
137    pub item: Item,
138}
139
140#[derive(Debug, Serialize, Deserialize, Clone)]
141pub struct ResponseContentPartAdded {
142    pub event_id: String,
143    pub response_id: String,
144    pub item_id: String,
145    pub output_index: u32,
146    pub content_index: u32,
147    pub part: ContentPart,
148}
149
150#[derive(Debug, Serialize, Deserialize, Clone)]
151pub struct ResponseContentPartDone {
152    pub event_id: String,
153    pub response_id: String,
154    pub item_id: String,
155    pub output_index: u32,
156    pub content_index: u32,
157    pub part: ContentPart,
158}
159
160#[derive(Debug, Serialize, Deserialize, Clone)]
161pub struct ResponseTextDelta {
162    pub event_id: String,
163    pub response_id: String,
164    pub item_id: String,
165    pub output_index: u32,
166    pub content_index: u32,
167    pub delta: String,
168}
169
170#[derive(Debug, Serialize, Deserialize, Clone)]
171pub struct ResponseTextDone {
172    pub event_id: String,
173    pub response_id: String,
174    pub item_id: String,
175    pub output_index: u32,
176    pub content_index: u32,
177    pub text: String,
178}
179
180#[derive(Debug, Serialize, Deserialize, Clone)]
181pub struct ResponseAudioTranscriptDelta {
182    pub event_id: String,
183    pub response_id: String,
184    pub item_id: String,
185    pub output_index: u32,
186    pub content_index: u32,
187    pub delta: String,
188}
189
190#[derive(Debug, Serialize, Deserialize, Clone)]
191pub struct ResponseAudioTranscriptDone {
192    pub event_id: String,
193    pub response_id: String,
194    pub item_id: String,
195    pub output_index: u32,
196    pub content_index: u32,
197    pub transcript: String,
198}
199
200#[derive(Debug, Serialize, Deserialize, Clone)]
201pub struct ResponseAudioDelta {
202    pub event_id: String,
203    pub response_id: String,
204    pub item_id: String,
205    pub output_index: u32,
206    pub content_index: u32,
207    pub delta: String,
208}
209
210#[derive(Debug, Serialize, Deserialize, Clone)]
211pub struct ResponseAudioDone {
212    pub event_id: String,
213    pub response_id: String,
214    pub item_id: String,
215    pub output_index: u32,
216    pub content_index: u32,
217}
218
219#[derive(Debug, Serialize, Deserialize, Clone)]
220pub struct ResponseFunctionCallArgumentsDelta {
221    pub event_id: String,
222    pub response_id: String,
223    pub item_id: String,
224    pub output_index: u32,
225    pub call_id: String,
226    pub delta: String,
227}
228
229#[derive(Debug, Serialize, Deserialize, Clone)]
230pub struct ResponseFunctionCallArgumentsDone {
231    pub event_id: String,
232    pub response_id: String,
233    pub item_id: String,
234    pub output_index: u32,
235    pub call_id: String,
236    pub arguments: String,
237}
238
239#[derive(Debug, Serialize, Deserialize, Clone)]
240pub struct RateLimitsUpdated {
241    pub event_id: String,
242    pub rate_limits: Vec<RateLimit>,
243}
244
245#[derive(Debug, Serialize, Deserialize, Clone)]
246#[serde(tag = "type")]
247pub enum ServerEvent {
248    #[serde(rename = "error")]
249    Error(Error),
250    #[serde(rename = "session.created")]
251    SessionCreated(SessionCreated),
252    #[serde(rename = "session.updated")]
253    SessionUpdated(SessionUpdated),
254    #[serde(rename = "conversation.created")]
255    ConversationCreated(ConversationCreated),
256    #[serde(rename = "input_audio_buffer.committed")]
257    InputAudioBufferCommited(InputAudioBufferCommited),
258    #[serde(rename = "input_audio_buffer.cleared")]
259    InputAudioBufferCleared(InputAudioBufferCleared),
260    #[serde(rename = "input_audio_buffer.speech_started")]
261    InputAudioBufferSpeechStarted(InputAudioBufferSpeechStarted),
262    #[serde(rename = "input_audio_buffer.speech_stopped")]
263    InputAudioBufferSpeechStopped(InputAudioBufferSpeechStopped),
264    #[serde(rename = "conversation.item.created")]
265    ConversationItemCreated(ConversationItemCreated),
266    #[serde(rename = "conversation.item.input_audio_transcription.completed")]
267    ConversationItemInputAudioTranscriptionCompleted(
268        ConversationItemInputAudioTranscriptionCompleted,
269    ),
270    #[serde(rename = "conversation.item.input_audio_transcription.failed")]
271    ConversationItemInputAudioTranscriptionFailed(ConversationItemInputAudioTranscriptionFailed),
272    #[serde(rename = "conversation.item.truncated")]
273    ConversationItemTruncated(ConversationItemTruncated),
274    #[serde(rename = "conversation.item.deleted")]
275    ConversationItemDeleted(ConversationItemDeleted),
276    #[serde(rename = "output_audio_buffer.started")]
277    OutputAudioBufferStarted(OutputAudioBufferStarted),
278    #[serde(rename = "output_audio_buffer.stopped")]
279    OutputAudioBufferStopped(OutputAudioBufferStopped),
280    #[serde(rename = "output_audio_buffer.cleared")]
281    OutputAudioBufferCleared(OutputAudioBufferCleared),
282    #[serde(rename = "response.created")]
283    ResponseCreated(ResponseCreated),
284    #[serde(rename = "response.done")]
285    ResponseDone(ResponseDone),
286    #[serde(rename = "response.output_item.added")]
287    ResponseOutputItemAdded(ResponseOutputItemAdded),
288    #[serde(rename = "response.output_item.done")]
289    ResponseOutputItemDone(ResponseOutputItemDone),
290    #[serde(rename = "response.content_part.added")]
291    ResponseContentPartAdded(ResponseContentPartAdded),
292    #[serde(rename = "response.content_part.done")]
293    ResponseContentPartDone(ResponseContentPartDone),
294    #[serde(rename = "response.text.delta")]
295    ResponseTextDelta(ResponseTextDelta),
296    #[serde(rename = "response.text.done")]
297    ResponseTextDone(ResponseTextDone),
298    #[serde(rename = "response.audio_transcript.delta")]
299    ResponseAudioTranscriptDelta(ResponseAudioTranscriptDelta),
300    #[serde(rename = "response.audio_transcript.done")]
301    ResponseAudioTranscriptDone(ResponseAudioTranscriptDone),
302    #[serde(rename = "response.audio.delta")]
303    ResponseAudioDelta(ResponseAudioDelta),
304    #[serde(rename = "response.audio.done")]
305    ResponseAudioDone(ResponseAudioDone),
306    #[serde(rename = "response.function_call_arguments.delta")]
307    ResponseFunctionCallArgumentsDelta(ResponseFunctionCallArgumentsDelta),
308    #[serde(rename = "response.function_call_arguments.done")]
309    ResponseFunctionCallArgumentsDone(ResponseFunctionCallArgumentsDone),
310    #[serde(rename = "rate_limits.updated")]
311    RateLimitsUpdated(RateLimitsUpdated),
312}