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 InputAudioBufferCommitedEvent {
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 ConversationItemInputAudioTranscriptionCompletedEvent {
88 pub event_id: String,
90 pub item_id: String,
92 pub content_index: u32,
94 pub transcript: String,
96}
97
98#[derive(Debug, Serialize, Deserialize, Clone)]
99pub struct ConversationItemInputAudioTranscriptionFailedEvent {
100 pub event_id: String,
102 pub item_id: String,
104 pub content_index: u32,
106 pub error: RealtimeAPIError,
108}
109
110#[derive(Debug, Serialize, Deserialize, Clone)]
111pub struct ConversationItemTruncatedEvent {
112 pub event_id: String,
114 pub item_id: String,
116 pub content_index: u32,
118 pub audio_end_ms: u32,
120}
121
122#[derive(Debug, Serialize, Deserialize, Clone)]
123pub struct ConversationItemDeletedEvent {
124 pub event_id: String,
126 pub item_id: String,
128}
129
130#[derive(Debug, Serialize, Deserialize, Clone)]
131pub struct ResponseCreatedEvent {
132 pub event_id: String,
134 pub response: ResponseResource,
136}
137
138#[derive(Debug, Serialize, Deserialize, Clone)]
139pub struct ResponseDoneEvent {
140 pub event_id: String,
142 pub response: ResponseResource,
144}
145
146#[derive(Debug, Serialize, Deserialize, Clone)]
147pub struct ResponseOutputItemAddedEvent {
148 pub event_id: String,
150 pub response_id: String,
152 pub output_index: u32,
154 pub item: Item,
156}
157
158#[derive(Debug, Serialize, Deserialize, Clone)]
159pub struct ResponseOutputItemDoneEvent {
160 pub event_id: String,
162 pub response_id: String,
164 pub output_index: u32,
166 pub item: Item,
168}
169
170#[derive(Debug, Serialize, Deserialize, Clone)]
171pub struct ResponseContentPartAddedEvent {
172 pub event_id: String,
174 pub response_id: String,
176 pub item_id: String,
178 pub output_index: u32,
180 pub content_index: u32,
182 pub part: ContentPart,
184}
185
186#[derive(Debug, Serialize, Deserialize, Clone)]
187pub struct ResponseContentPartDoneEvent {
188 pub event_id: String,
190 pub response_id: String,
192 pub item_id: String,
194 pub output_index: u32,
196 pub content_index: u32,
198 pub part: ContentPart,
200}
201
202#[derive(Debug, Serialize, Deserialize, Clone)]
203pub struct ResponseTextDeltaEvent {
204 pub event_id: String,
206 pub response_id: String,
208 pub item_id: String,
210 pub output_index: u32,
212 pub content_index: u32,
214 pub delta: String,
216}
217
218#[derive(Debug, Serialize, Deserialize, Clone)]
219pub struct ResponseTextDoneEvent {
220 pub event_id: String,
222 pub response_id: String,
224 pub item_id: String,
226 pub output_index: u32,
228 pub content_index: u32,
230 pub text: String,
232}
233
234#[derive(Debug, Serialize, Deserialize, Clone)]
235pub struct ResponseAudioTranscriptDeltaEvent {
236 pub event_id: String,
238 pub response_id: String,
240 pub item_id: String,
242 pub output_index: u32,
244 pub content_index: u32,
246 pub delta: String,
248}
249
250#[derive(Debug, Serialize, Deserialize, Clone)]
251pub struct ResponseAudioTranscriptDoneEvent {
252 pub event_id: String,
254 pub response_id: String,
256 pub item_id: String,
258 pub output_index: u32,
260 pub content_index: u32,
262 pub transcript: String,
264}
265
266#[derive(Debug, Serialize, Deserialize, Clone)]
267pub struct ResponseAudioDeltaEvent {
268 pub event_id: String,
270 pub response_id: String,
272 pub item_id: String,
274 pub output_index: u32,
276 pub content_index: u32,
278 pub delta: String,
280}
281
282#[derive(Debug, Serialize, Deserialize, Clone)]
283pub struct ResponseAudioDoneEvent {
284 pub event_id: String,
286 pub response_id: String,
288 pub item_id: String,
290 pub output_index: u32,
292 pub content_index: u32,
294}
295
296#[derive(Debug, Serialize, Deserialize, Clone)]
297pub struct ResponseFunctionCallArgumentsDeltaEvent {
298 pub event_id: String,
300 pub response_id: String,
302 pub item_id: String,
304 pub output_index: u32,
306 pub call_id: String,
308 pub delta: String,
310}
311
312#[derive(Debug, Serialize, Deserialize, Clone)]
313pub struct ResponseFunctionCallArgumentsDoneEvent {
314 pub event_id: String,
316 pub response_id: String,
318 pub item_id: String,
320 pub output_index: u32,
322 pub call_id: String,
324 pub arguments: String,
326}
327
328#[derive(Debug, Serialize, Deserialize, Clone)]
329pub struct RateLimitsUpdatedEvent {
330 pub event_id: String,
332 pub rate_limits: Vec<RateLimit>,
333}
334
335#[derive(Debug, Serialize, Deserialize, Clone)]
337#[serde(tag = "type")]
338pub enum ServerEvent {
339 #[serde(rename = "error")]
341 Error(ErrorEvent),
342
343 #[serde(rename = "session.created")]
345 SessionCreated(SessionCreatedEvent),
346
347 #[serde(rename = "session.updated")]
349 SessionUpdated(SessionUpdatedEvent),
350
351 #[serde(rename = "conversation.created")]
353 ConversationCreated(ConversationCreatedEvent),
354
355 #[serde(rename = "input_audio_buffer.committed")]
357 InputAudioBufferCommited(InputAudioBufferCommitedEvent),
358
359 #[serde(rename = "input_audio_buffer.cleared")]
361 InputAudioBufferCleared(InputAudioBufferClearedEvent),
362
363 #[serde(rename = "input_audio_buffer.speech_started")]
365 InputAudioBufferSpeechStarted(InputAudioBufferSpeechStartedEvent),
366
367 #[serde(rename = "input_audio_buffer.speech_stopped")]
369 InputAudioBufferSpeechStopped(InputAudioBufferSpeechStoppedEvent),
370
371 #[serde(rename = "conversation.item.created")]
373 ConversationItemCreated(ConversationItemCreatedEvent),
374
375 #[serde(rename = "conversation.item.input_audio_transcription.completed")]
377 ConversationItemInputAudioTranscriptionCompleted(
378 ConversationItemInputAudioTranscriptionCompletedEvent,
379 ),
380
381 #[serde(rename = "conversation.item.input_audio_transcription.failed")]
383 ConversationItemInputAudioTranscriptionFailed(
384 ConversationItemInputAudioTranscriptionFailedEvent,
385 ),
386
387 #[serde(rename = "conversation.item.truncated")]
389 ConversationItemTruncated(ConversationItemTruncatedEvent),
390
391 #[serde(rename = "conversation.item.deleted")]
393 ConversationItemDeleted(ConversationItemDeletedEvent),
394
395 #[serde(rename = "response.created")]
397 ResponseCreated(ResponseCreatedEvent),
398
399 #[serde(rename = "response.done")]
401 ResponseDone(ResponseDoneEvent),
402
403 #[serde(rename = "response.output_item.added")]
405 ResponseOutputItemAdded(ResponseOutputItemAddedEvent),
406
407 #[serde(rename = "response.output_item.done")]
409 ResponseOutputItemDone(ResponseOutputItemDoneEvent),
410
411 #[serde(rename = "response.content_part.added")]
413 ResponseContentPartAdded(ResponseContentPartAddedEvent),
414
415 #[serde(rename = "response.content_part.done")]
418 ResponseContentPartDone(ResponseContentPartDoneEvent),
419
420 #[serde(rename = "response.text.delta")]
422 ResponseTextDelta(ResponseTextDeltaEvent),
423
424 #[serde(rename = "response.text.done")]
427 ResponseTextDone(ResponseTextDoneEvent),
428
429 #[serde(rename = "response.audio_transcript.delta")]
431 ResponseAudioTranscriptDelta(ResponseAudioTranscriptDeltaEvent),
432
433 #[serde(rename = "response.audio_transcript.done")]
436 ResponseAudioTranscriptDone(ResponseAudioTranscriptDoneEvent),
437
438 #[serde(rename = "response.audio.delta")]
440 ResponseAudioDelta(ResponseAudioDeltaEvent),
441
442 #[serde(rename = "response.audio.done")]
445 ResponseAudioDone(ResponseAudioDoneEvent),
446
447 #[serde(rename = "response.function_call_arguments.delta")]
449 ResponseFunctionCallArgumentsDelta(ResponseFunctionCallArgumentsDeltaEvent),
450
451 #[serde(rename = "response.function_call_arguments.done")]
454 ResponseFunctionCallArgumentsDone(ResponseFunctionCallArgumentsDoneEvent),
455
456 #[serde(rename = "rate_limits.updated")]
458 RateLimitsUpdated(RateLimitsUpdatedEvent),
459}