1use serde::{Deserialize, Serialize};
2
3use super::{
4 content_part::ContentPart, conversation::Conversation, error::RealtimeAPIError, item::Item,
5 rate_limit::RateLimit, response_resource::ResponseResource, session_resource::SessionResource,
6};
7
8#[derive(Debug, Serialize, Deserialize, Clone)]
9pub struct ErrorEvent {
10 pub event_id: String,
12 pub error: RealtimeAPIError,
14}
15
16#[derive(Debug, Serialize, Deserialize, Clone)]
17pub struct SessionCreatedEvent {
18 pub event_id: String,
20 pub session: SessionResource,
22}
23
24#[derive(Debug, Serialize, Deserialize, Clone)]
25pub struct SessionUpdatedEvent {
26 pub event_id: String,
28 pub session: SessionResource,
30}
31
32#[derive(Debug, Serialize, Deserialize, Clone)]
33pub struct ConversationCreatedEvent {
34 pub event_id: String,
36 pub conversation: Conversation,
38}
39
40#[derive(Debug, Serialize, Deserialize, Clone)]
41pub struct InputAudioBufferCommittedEvent {
42 pub event_id: String,
44 pub previous_item_id: String,
46 pub item_id: String,
48}
49
50#[derive(Debug, Serialize, Deserialize, Clone)]
51pub struct InputAudioBufferClearedEvent {
52 pub event_id: String,
54}
55
56#[derive(Debug, Serialize, Deserialize, Clone)]
57pub struct InputAudioBufferSpeechStartedEvent {
58 pub event_id: String,
60 pub audio_start_ms: u32,
62 pub item_id: String,
64}
65
66#[derive(Debug, Serialize, Deserialize, Clone)]
67pub struct InputAudioBufferSpeechStoppedEvent {
68 pub event_id: String,
70 pub audio_end_ms: u32,
72 pub item_id: String,
74}
75
76#[derive(Debug, Serialize, Deserialize, Clone)]
77pub struct ConversationItemCreatedEvent {
78 pub event_id: String,
80 pub previous_item_id: Option<String>,
82 pub item: Item,
84}
85
86#[derive(Debug, Serialize, Deserialize, Clone)]
87pub struct LogProb {
89 pub bytes: Vec<u8>,
91 pub logprob: f64,
93 pub token: String,
95}
96
97#[derive(Debug, Serialize, Deserialize, Clone)]
98pub struct ConversationItemInputAudioTranscriptionCompletedEvent {
99 pub event_id: String,
101 pub item_id: String,
103 pub content_index: u32,
105 pub transcript: String,
107 pub logprobs: Option<Vec<LogProb>>,
109}
110
111#[derive(Debug, Serialize, Deserialize, Clone)]
112pub struct ConversationItemInputAudioTranscriptionDeltaEvent {
113 pub event_id: String,
115 pub item_id: String,
117 pub content_index: u32,
119 pub delta: String,
121 pub logprobs: Option<Vec<LogProb>>,
123}
124
125#[derive(Debug, Serialize, Deserialize, Clone)]
126pub struct ConversationItemInputAudioTranscriptionFailedEvent {
127 pub event_id: String,
129 pub item_id: String,
131 pub content_index: u32,
133 pub error: RealtimeAPIError,
135}
136
137#[derive(Debug, Serialize, Deserialize, Clone)]
138pub struct ConversationItemTruncatedEvent {
139 pub event_id: String,
141 pub item_id: String,
143 pub content_index: u32,
145 pub audio_end_ms: u32,
147}
148
149#[derive(Debug, Serialize, Deserialize, Clone)]
150pub struct ConversationItemDeletedEvent {
151 pub event_id: String,
153 pub item_id: String,
155}
156
157#[derive(Debug, Serialize, Deserialize, Clone)]
158pub struct ResponseCreatedEvent {
159 pub event_id: String,
161 pub response: ResponseResource,
163}
164
165#[derive(Debug, Serialize, Deserialize, Clone)]
166pub struct ResponseDoneEvent {
167 pub event_id: String,
169 pub response: ResponseResource,
171}
172
173#[derive(Debug, Serialize, Deserialize, Clone)]
174pub struct ResponseOutputItemAddedEvent {
175 pub event_id: String,
177 pub response_id: String,
179 pub output_index: u32,
181 pub item: Item,
183}
184
185#[derive(Debug, Serialize, Deserialize, Clone)]
186pub struct ResponseOutputItemDoneEvent {
187 pub event_id: String,
189 pub response_id: String,
191 pub output_index: u32,
193 pub item: Item,
195}
196
197#[derive(Debug, Serialize, Deserialize, Clone)]
198pub struct ResponseContentPartAddedEvent {
199 pub event_id: String,
201 pub response_id: String,
203 pub item_id: String,
205 pub output_index: u32,
207 pub content_index: u32,
209 pub part: ContentPart,
211}
212
213#[derive(Debug, Serialize, Deserialize, Clone)]
214pub struct ResponseContentPartDoneEvent {
215 pub event_id: String,
217 pub response_id: String,
219 pub item_id: String,
221 pub output_index: u32,
223 pub content_index: u32,
225 pub part: ContentPart,
227}
228
229#[derive(Debug, Serialize, Deserialize, Clone)]
230pub struct ResponseTextDeltaEvent {
231 pub event_id: String,
233 pub response_id: String,
235 pub item_id: String,
237 pub output_index: u32,
239 pub content_index: u32,
241 pub delta: String,
243}
244
245#[derive(Debug, Serialize, Deserialize, Clone)]
246pub struct ResponseTextDoneEvent {
247 pub event_id: String,
249 pub response_id: String,
251 pub item_id: String,
253 pub output_index: u32,
255 pub content_index: u32,
257 pub text: String,
259}
260
261#[derive(Debug, Serialize, Deserialize, Clone)]
262pub struct ResponseAudioTranscriptDeltaEvent {
263 pub event_id: String,
265 pub response_id: String,
267 pub item_id: String,
269 pub output_index: u32,
271 pub content_index: u32,
273 pub delta: String,
275}
276
277#[derive(Debug, Serialize, Deserialize, Clone)]
278pub struct ResponseAudioTranscriptDoneEvent {
279 pub event_id: String,
281 pub response_id: String,
283 pub item_id: String,
285 pub output_index: u32,
287 pub content_index: u32,
289 pub transcript: String,
291}
292
293#[derive(Debug, Serialize, Deserialize, Clone)]
294pub struct ResponseAudioDeltaEvent {
295 pub event_id: String,
297 pub response_id: String,
299 pub item_id: String,
301 pub output_index: u32,
303 pub content_index: u32,
305 pub delta: String,
307}
308
309#[derive(Debug, Serialize, Deserialize, Clone)]
310pub struct ResponseAudioDoneEvent {
311 pub event_id: String,
313 pub response_id: String,
315 pub item_id: String,
317 pub output_index: u32,
319 pub content_index: u32,
321}
322
323#[derive(Debug, Serialize, Deserialize, Clone)]
324pub struct ResponseFunctionCallArgumentsDeltaEvent {
325 pub event_id: String,
327 pub response_id: String,
329 pub item_id: String,
331 pub output_index: u32,
333 pub call_id: String,
335 pub delta: String,
337}
338
339#[derive(Debug, Serialize, Deserialize, Clone)]
340pub struct ResponseFunctionCallArgumentsDoneEvent {
341 pub event_id: String,
343 pub response_id: String,
345 pub item_id: String,
347 pub output_index: u32,
349 pub call_id: String,
351 pub arguments: String,
353}
354
355#[derive(Debug, Serialize, Deserialize, Clone)]
356pub struct RateLimitsUpdatedEvent {
357 pub event_id: String,
359 pub rate_limits: Vec<RateLimit>,
360}
361
362#[derive(Debug, Serialize, Deserialize, Clone)]
364#[serde(tag = "type")]
365pub enum ServerEvent {
366 #[serde(rename = "error")]
368 Error(ErrorEvent),
369
370 #[serde(rename = "session.created")]
372 SessionCreated(SessionCreatedEvent),
373
374 #[serde(rename = "session.updated")]
376 SessionUpdated(SessionUpdatedEvent),
377
378 #[serde(rename = "conversation.created")]
380 ConversationCreated(ConversationCreatedEvent),
381
382 #[serde(rename = "input_audio_buffer.committed")]
384 InputAudioBufferCommitted(InputAudioBufferCommittedEvent),
385
386 #[serde(rename = "input_audio_buffer.cleared")]
388 InputAudioBufferCleared(InputAudioBufferClearedEvent),
389
390 #[serde(rename = "input_audio_buffer.speech_started")]
392 InputAudioBufferSpeechStarted(InputAudioBufferSpeechStartedEvent),
393
394 #[serde(rename = "input_audio_buffer.speech_stopped")]
396 InputAudioBufferSpeechStopped(InputAudioBufferSpeechStoppedEvent),
397
398 #[serde(rename = "conversation.item.created")]
400 ConversationItemCreated(ConversationItemCreatedEvent),
401
402 #[serde(rename = "conversation.item.input_audio_transcription.completed")]
404 ConversationItemInputAudioTranscriptionCompleted(
405 ConversationItemInputAudioTranscriptionCompletedEvent,
406 ),
407
408 #[serde(rename = "conversation.item.input_audio_transcription.delta")]
409 ConversationItemInputAudioTranscriptionDelta(ConversationItemInputAudioTranscriptionDeltaEvent),
410
411 #[serde(rename = "conversation.item.input_audio_transcription.failed")]
413 ConversationItemInputAudioTranscriptionFailed(
414 ConversationItemInputAudioTranscriptionFailedEvent,
415 ),
416
417 #[serde(rename = "conversation.item.truncated")]
419 ConversationItemTruncated(ConversationItemTruncatedEvent),
420
421 #[serde(rename = "conversation.item.deleted")]
423 ConversationItemDeleted(ConversationItemDeletedEvent),
424
425 #[serde(rename = "response.created")]
427 ResponseCreated(ResponseCreatedEvent),
428
429 #[serde(rename = "response.done")]
431 ResponseDone(ResponseDoneEvent),
432
433 #[serde(rename = "response.output_item.added")]
435 ResponseOutputItemAdded(ResponseOutputItemAddedEvent),
436
437 #[serde(rename = "response.output_item.done")]
439 ResponseOutputItemDone(ResponseOutputItemDoneEvent),
440
441 #[serde(rename = "response.content_part.added")]
443 ResponseContentPartAdded(ResponseContentPartAddedEvent),
444
445 #[serde(rename = "response.content_part.done")]
448 ResponseContentPartDone(ResponseContentPartDoneEvent),
449
450 #[serde(rename = "response.text.delta")]
452 ResponseTextDelta(ResponseTextDeltaEvent),
453
454 #[serde(rename = "response.text.done")]
457 ResponseTextDone(ResponseTextDoneEvent),
458
459 #[serde(rename = "response.audio_transcript.delta")]
461 ResponseAudioTranscriptDelta(ResponseAudioTranscriptDeltaEvent),
462
463 #[serde(rename = "response.audio_transcript.done")]
466 ResponseAudioTranscriptDone(ResponseAudioTranscriptDoneEvent),
467
468 #[serde(rename = "response.audio.delta")]
470 ResponseAudioDelta(ResponseAudioDeltaEvent),
471
472 #[serde(rename = "response.audio.done")]
475 ResponseAudioDone(ResponseAudioDoneEvent),
476
477 #[serde(rename = "response.function_call_arguments.delta")]
479 ResponseFunctionCallArgumentsDelta(ResponseFunctionCallArgumentsDeltaEvent),
480
481 #[serde(rename = "response.function_call_arguments.done")]
484 ResponseFunctionCallArgumentsDone(ResponseFunctionCallArgumentsDoneEvent),
485
486 #[serde(rename = "rate_limits.updated")]
488 RateLimitsUpdated(RateLimitsUpdatedEvent),
489}