1use super::input::present_optional;
4use super::response::{GenerateContentResponseBody, ResponseOutputItem};
5use crate::Rest;
6use serde::{Deserialize, Serialize};
7
8#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11#[serde(tag = "type")]
12#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
13#[derive(gproxy_protocol_macros::DeclaredFields)]
14pub enum StreamEvent {
15 #[serde(rename = "keepalive")]
17 Keepalive,
18 #[serde(rename = "response.created")]
19 Created(ResponseCreated),
20 #[serde(rename = "response.queued")]
21 Queued(ResponseQueued),
22 #[serde(rename = "response.in_progress")]
23 InProgress(ResponseInProgress),
24 #[serde(rename = "response.completed")]
25 Completed(ResponseCompleted),
26 #[serde(rename = "response.failed")]
27 Failed(ResponseFailed),
28 #[serde(rename = "response.incomplete")]
29 Incomplete(ResponseIncomplete),
30 #[serde(rename = "response.output_item.added")]
31 OutputItemAdded(OutputItemEvent),
32 #[serde(rename = "response.output_item.done")]
33 OutputItemDone(OutputItemEvent),
34 #[serde(rename = "response.content_part.added")]
35 ContentPartAdded(ContentPartEvent),
36 #[serde(rename = "response.content_part.done")]
37 ContentPartDone(ContentPartEvent),
38 #[serde(rename = "response.output_text.delta")]
39 OutputTextDelta(OutputTextDelta),
40 #[serde(rename = "response.output_text.done")]
41 OutputTextDone(OutputTextDone),
42 #[serde(rename = "response.output_text.annotation.added")]
43 OutputTextAnnotationAdded(OutputTextAnnotationAdded),
44 #[serde(rename = "response.refusal.delta")]
45 RefusalDelta(RefusalDelta),
46 #[serde(rename = "response.refusal.done")]
47 RefusalDone(RefusalDone),
48 #[serde(rename = "response.reasoning_text.delta")]
49 ReasoningTextDelta(ReasoningTextDelta),
50 #[serde(rename = "response.reasoning_text.done")]
51 ReasoningTextDone(ReasoningTextDone),
52 #[serde(rename = "response.reasoning_summary_part.added")]
53 ReasoningSummaryPartAdded(ReasoningSummaryPartAddedEvent),
54 #[serde(rename = "response.reasoning_summary_part.done")]
55 ReasoningSummaryPartDone(ReasoningSummaryPartDoneEvent),
56 #[serde(rename = "response.reasoning_summary_text.delta")]
57 ReasoningSummaryTextDelta(ReasoningSummaryTextDelta),
58 #[serde(rename = "response.reasoning_summary_text.done")]
59 ReasoningSummaryTextDone(ReasoningSummaryTextDone),
60 #[serde(rename = "response.function_call_arguments.delta")]
61 FunctionCallArgumentsDelta(FunctionCallArgumentsDelta),
62 #[serde(rename = "response.function_call_arguments.done")]
63 FunctionCallArgumentsDone(FunctionCallArgumentsDone),
64 #[serde(rename = "response.custom_tool_call_input.delta")]
65 CustomToolInputDelta(CustomToolInputDelta),
66 #[serde(rename = "response.custom_tool_call_input.done")]
67 CustomToolInputDone(CustomToolInputDone),
68 #[serde(rename = "response.code_interpreter_call_code.delta")]
69 CodeInterpreterCodeDelta(CodeInterpreterCodeDelta),
70 #[serde(rename = "response.code_interpreter_call_code.done")]
71 CodeInterpreterCodeDone(CodeInterpreterCodeDone),
72 #[serde(rename = "response.audio.delta")]
73 AudioDelta(AudioDelta),
74 #[serde(rename = "response.audio.done")]
75 AudioDone(AudioDone),
76 #[serde(rename = "response.audio.transcript.delta")]
77 AudioTranscriptDelta(AudioTranscriptDelta),
78 #[serde(rename = "response.audio.transcript.done")]
79 AudioTranscriptDone(AudioTranscriptDone),
80 #[serde(rename = "response.image_generation_call.partial_image")]
81 ImagePartial(ImagePartial),
82 #[serde(rename = "response.image_generation_call.in_progress")]
83 ImageCall(ImageCallEvent),
84 #[serde(rename = "response.image_generation_call.generating")]
85 ImageGenerating(ImageCallEvent),
86 #[serde(rename = "response.image_generation_call.completed")]
87 ImageCompleted(ImageCallEvent),
88 #[serde(rename = "response.code_interpreter_call.in_progress")]
89 CodeInterpreterInProgress(CodeInterpreterEvent),
90 #[serde(rename = "response.code_interpreter_call.interpreting")]
91 CodeInterpreterInterpreting(CodeInterpreterEvent),
92 #[serde(rename = "response.code_interpreter_call.completed")]
93 CodeInterpreterCompleted(CodeInterpreterEvent),
94 #[serde(rename = "response.file_search_call.in_progress")]
95 FileSearchInProgress(ToolCallEvent),
96 #[serde(rename = "response.file_search_call.searching")]
97 FileSearchSearching(ToolCallEvent),
98 #[serde(rename = "response.file_search_call.completed")]
99 FileSearchCompleted(ToolCallEvent),
100 #[serde(rename = "response.web_search_call.in_progress")]
101 WebSearchInProgress(ToolCallEvent),
102 #[serde(rename = "response.web_search_call.searching")]
103 WebSearchSearching(ToolCallEvent),
104 #[serde(rename = "response.web_search_call.completed")]
105 WebSearchCompleted(ToolCallEvent),
106 #[serde(rename = "response.mcp_call_arguments.delta")]
107 McpArgumentsDelta(McpArgumentsDelta),
108 #[serde(rename = "response.mcp_call_arguments.done")]
109 McpArgumentsDone(McpArgumentsDone),
110 #[serde(rename = "response.mcp_call.in_progress")]
111 McpInProgress(McpCallEvent),
112 #[serde(rename = "response.mcp_call.completed")]
113 McpCompleted(McpCallEvent),
114 #[serde(rename = "response.mcp_call.failed")]
115 McpFailed(McpCallEvent),
116 #[serde(rename = "response.mcp_list_tools.in_progress")]
117 McpListToolsInProgress(McpListToolsEvent),
118 #[serde(rename = "response.mcp_list_tools.completed")]
119 McpListToolsCompleted(McpListToolsEvent),
120 #[serde(rename = "response.mcp_list_tools.failed")]
121 McpListToolsFailed(McpListToolsEvent),
122 #[serde(rename = "error")]
123 Error(ResponseErrorEvent),
124}
125macro_rules! event_struct { ($name:ident { $($field:ident : $ty:ty),* $(,)? }) => { #[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)] #[serde(rename_all="snake_case")] #[cfg_attr(not(feature="exhaustive"), non_exhaustive)] #[derive(gproxy_protocol_macros::DeclaredFields)]
126pub struct $name { pub sequence_number: i64, $(pub $field: $ty,)* #[serde(default, flatten, skip_serializing_if="serde_json::Map::is_empty")] pub rest: Rest } }; }
127macro_rules! agent_event_struct { ($name:ident { $($field:ident : $ty:ty),* $(,)? }) => { #[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)] #[serde(rename_all="snake_case")] #[cfg_attr(not(feature="exhaustive"), non_exhaustive)] #[derive(gproxy_protocol_macros::DeclaredFields)]
128pub struct $name { #[serde(default, deserialize_with = "super::input::present_nullable", skip_serializing_if = "Option::is_none")] pub agent: Option<Option<super::multi_agent::Agent>>, pub sequence_number: i64, $(pub $field: $ty,)* #[serde(default, flatten, skip_serializing_if="serde_json::Map::is_empty")] pub rest: Rest } }; }
129event_struct!(ResponseCreated {
130 response: GenerateContentResponseBody
131});
132event_struct!(ResponseQueued {
133 response: GenerateContentResponseBody
134});
135event_struct!(ResponseInProgress {
136 response: GenerateContentResponseBody
137});
138event_struct!(ResponseCompleted {
139 response: GenerateContentResponseBody
140});
141event_struct!(ResponseFailed {
142 response: GenerateContentResponseBody
143});
144event_struct!(ResponseIncomplete {
145 response: GenerateContentResponseBody
146});
147agent_event_struct!(OutputItemEvent {
148 output_index: i64,
149 item: ResponseOutputItem
150});
151agent_event_struct!(ContentPartEvent {
152 item_id: String,
153 output_index: i64,
154 content_index: i64,
155 part: OutputContentPart
156});
157agent_event_struct!(OutputTextDelta { item_id: String, output_index: i64, content_index: i64, delta: String, logprobs: Vec<StreamLogprob> });
158agent_event_struct!(OutputTextDone { item_id: String, output_index: i64, content_index: i64, text: String, logprobs: Vec<StreamLogprob> });
159agent_event_struct!(OutputTextAnnotationAdded {
160 item_id: String,
161 output_index: i64,
162 content_index: i64,
163 annotation_index: i64,
164 annotation: serde_json::Value
165});
166agent_event_struct!(RefusalDelta {
167 item_id: String,
168 output_index: i64,
169 content_index: i64,
170 delta: String
171});
172agent_event_struct!(RefusalDone {
173 item_id: String,
174 output_index: i64,
175 content_index: i64,
176 refusal: String
177});
178agent_event_struct!(ReasoningTextDelta {
179 item_id: String,
180 output_index: i64,
181 content_index: i64,
182 delta: String
183});
184agent_event_struct!(ReasoningTextDone {
185 item_id: String,
186 output_index: i64,
187 content_index: i64,
188 text: String
189});
190agent_event_struct!(ReasoningSummaryPartAddedEvent {
191 item_id: String,
192 output_index: i64,
193 summary_index: i64,
194 part: ReasoningSummaryPart
195});
196#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
197#[serde(rename_all = "snake_case")]
198#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
199#[derive(gproxy_protocol_macros::DeclaredFields)]
200pub struct ReasoningSummaryPartDoneEvent {
201 #[serde(
202 default,
203 deserialize_with = "super::input::present_nullable",
204 skip_serializing_if = "Option::is_none"
205 )]
206 pub agent: Option<Option<super::multi_agent::Agent>>,
207 pub sequence_number: i64,
208 pub item_id: String,
209 pub output_index: i64,
210 pub summary_index: i64,
211 pub part: ReasoningSummaryPart,
212 #[serde(
213 default,
214 deserialize_with = "present_optional",
215 skip_serializing_if = "Option::is_none"
216 )]
217 pub status: Option<SummaryPartStatus>,
218 #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
219 pub rest: Rest,
220}
221#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
222#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
223#[derive(gproxy_protocol_macros::DeclaredFields)]
224pub enum SummaryPartStatus {
225 #[serde(rename = "incomplete")]
226 Incomplete,
227}
228agent_event_struct!(ReasoningSummaryTextDelta {
229 item_id: String,
230 output_index: i64,
231 summary_index: i64,
232 delta: String
233});
234agent_event_struct!(ReasoningSummaryTextDone {
235 item_id: String,
236 output_index: i64,
237 summary_index: i64,
238 text: String
239});
240agent_event_struct!(FunctionCallArgumentsDelta {
241 item_id: String,
242 output_index: i64,
243 delta: String
244});
245agent_event_struct!(FunctionCallArgumentsDone {
246 item_id: String,
247 output_index: i64,
248 name: String,
249 arguments: String
250});
251agent_event_struct!(CustomToolInputDelta {
252 item_id: String,
253 output_index: i64,
254 delta: String
255});
256agent_event_struct!(CustomToolInputDone {
257 item_id: String,
258 output_index: i64,
259 input: String
260});
261agent_event_struct!(CodeInterpreterCodeDelta {
262 item_id: String,
263 output_index: i64,
264 delta: String
265});
266agent_event_struct!(CodeInterpreterCodeDone {
267 item_id: String,
268 output_index: i64,
269 code: String
270});
271agent_event_struct!(AudioDelta { delta: String });
272agent_event_struct!(AudioDone {});
273agent_event_struct!(AudioTranscriptDelta { delta: String });
274agent_event_struct!(AudioTranscriptDone {});
275agent_event_struct!(ImagePartial {
276 item_id: String,
277 output_index: i64,
278 partial_image_index: i64,
279 partial_image_b64: String
280});
281agent_event_struct!(ImageCall {
282 item_id: String,
283 output_index: i64
284});
285pub type ImageCallEvent = ImageCall;
286agent_event_struct!(CodeInterpreterEvent {
287 item_id: String,
288 output_index: i64
289});
290agent_event_struct!(ToolCallEvent {
291 item_id: String,
292 output_index: i64
293});
294agent_event_struct!(McpArgumentsDelta {
295 item_id: String,
296 output_index: i64,
297 delta: String
298});
299agent_event_struct!(McpArgumentsDone {
300 item_id: String,
301 output_index: i64,
302 arguments: String
303});
304agent_event_struct!(McpCallEvent {
305 item_id: String,
306 output_index: i64
307});
308agent_event_struct!(McpListToolsEvent {
309 item_id: String,
310 output_index: i64
311});
312pub type ResponseStream = crate::WireResponse<crate::connection::ByteStream>;
313
314#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
315#[serde(untagged)]
316#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
317#[derive(gproxy_protocol_macros::DeclaredFields)]
318pub enum OutputContentPart {
319 Text(super::input::ResponseOutputText),
320 Refusal(super::input::ResponseOutputRefusal),
321 Reasoning(ReasoningText),
322}
323#[derive(
324 Debug, Clone, PartialEq, Eq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder,
325)]
326#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
327#[derive(gproxy_protocol_macros::DeclaredFields)]
328pub struct ReasoningText {
329 pub text: String,
330 #[serde(rename = "type")]
331 pub type_: ReasoningTextType,
332 #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
333 pub rest: Rest,
334}
335#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
336#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
337#[derive(gproxy_protocol_macros::DeclaredFields)]
338pub enum ReasoningTextType {
339 #[serde(rename = "reasoning_text")]
340 ReasoningText,
341}
342#[derive(
343 Debug, Clone, PartialEq, Eq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder,
344)]
345#[serde(rename_all = "snake_case")]
346#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
347#[derive(gproxy_protocol_macros::DeclaredFields)]
348pub struct StreamLogprob {
349 pub token: String,
350 pub logprob: serde_json::Number,
351 #[serde(
352 default,
353 deserialize_with = "present_optional",
354 skip_serializing_if = "Option::is_none"
355 )]
356 pub top_logprobs: Option<Vec<StreamTopLogprob>>,
357 #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
358 pub rest: Rest,
359}
360#[derive(
361 Debug, Clone, PartialEq, Eq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder,
362)]
363#[serde(rename_all = "snake_case")]
364#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
365#[derive(gproxy_protocol_macros::DeclaredFields)]
366pub struct StreamTopLogprob {
367 #[serde(
368 default,
369 deserialize_with = "present_optional",
370 skip_serializing_if = "Option::is_none"
371 )]
372 pub token: Option<String>,
373 #[serde(
374 default,
375 deserialize_with = "present_optional",
376 skip_serializing_if = "Option::is_none"
377 )]
378 pub logprob: Option<serde_json::Number>,
379 #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
380 pub rest: Rest,
381}
382#[derive(
383 Debug, Clone, PartialEq, Eq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder,
384)]
385#[serde(rename_all = "snake_case")]
386#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
387#[derive(gproxy_protocol_macros::DeclaredFields)]
388pub struct ReasoningSummaryPart {
389 pub text: String,
390 #[serde(rename = "type")]
391 pub type_: ReasoningSummaryPartType,
392 #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
393 pub rest: Rest,
394}
395#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
396#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
397#[derive(gproxy_protocol_macros::DeclaredFields)]
398pub enum ReasoningSummaryPartType {
399 #[serde(rename = "summary_text")]
400 SummaryText,
401}
402#[derive(
403 Debug, Clone, PartialEq, Eq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder,
404)]
405#[serde(rename_all = "snake_case")]
406#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
407#[derive(gproxy_protocol_macros::DeclaredFields)]
408pub struct ResponseErrorEvent {
409 #[wire(required)]
410 #[serde(deserialize_with = "super::input::required_nullable")]
411 pub code: Option<String>,
412 pub message: String,
413 #[wire(required)]
414 #[serde(deserialize_with = "super::input::required_nullable")]
415 pub param: Option<String>,
416 pub sequence_number: i64,
417 #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
418 pub rest: Rest,
419}
420
421impl StreamEvent {
422 pub fn agent(&self) -> Option<&super::multi_agent::Agent> {
423 match self {
424 Self::OutputItemAdded(v) => v.agent.as_ref().and_then(Option::as_ref),
425 Self::OutputItemDone(v) => v.agent.as_ref().and_then(Option::as_ref),
426 Self::ContentPartAdded(v) => v.agent.as_ref().and_then(Option::as_ref),
427 Self::ContentPartDone(v) => v.agent.as_ref().and_then(Option::as_ref),
428 Self::OutputTextDelta(v) => v.agent.as_ref().and_then(Option::as_ref),
429 Self::OutputTextDone(v) => v.agent.as_ref().and_then(Option::as_ref),
430 Self::OutputTextAnnotationAdded(v) => v.agent.as_ref().and_then(Option::as_ref),
431 Self::RefusalDelta(v) => v.agent.as_ref().and_then(Option::as_ref),
432 Self::RefusalDone(v) => v.agent.as_ref().and_then(Option::as_ref),
433 Self::ReasoningTextDelta(v) => v.agent.as_ref().and_then(Option::as_ref),
434 Self::ReasoningTextDone(v) => v.agent.as_ref().and_then(Option::as_ref),
435 Self::ReasoningSummaryPartAdded(v) => v.agent.as_ref().and_then(Option::as_ref),
436 Self::ReasoningSummaryPartDone(v) => v.agent.as_ref().and_then(Option::as_ref),
437 Self::ReasoningSummaryTextDelta(v) => v.agent.as_ref().and_then(Option::as_ref),
438 Self::ReasoningSummaryTextDone(v) => v.agent.as_ref().and_then(Option::as_ref),
439 Self::FunctionCallArgumentsDelta(v) => v.agent.as_ref().and_then(Option::as_ref),
440 Self::FunctionCallArgumentsDone(v) => v.agent.as_ref().and_then(Option::as_ref),
441 Self::CustomToolInputDelta(v) => v.agent.as_ref().and_then(Option::as_ref),
442 Self::CustomToolInputDone(v) => v.agent.as_ref().and_then(Option::as_ref),
443 Self::CodeInterpreterCodeDelta(v) => v.agent.as_ref().and_then(Option::as_ref),
444 Self::CodeInterpreterCodeDone(v) => v.agent.as_ref().and_then(Option::as_ref),
445 Self::AudioDelta(v) => v.agent.as_ref().and_then(Option::as_ref),
446 Self::AudioDone(v) => v.agent.as_ref().and_then(Option::as_ref),
447 Self::AudioTranscriptDelta(v) => v.agent.as_ref().and_then(Option::as_ref),
448 Self::AudioTranscriptDone(v) => v.agent.as_ref().and_then(Option::as_ref),
449 Self::ImagePartial(v) => v.agent.as_ref().and_then(Option::as_ref),
450 Self::ImageCall(v) => v.agent.as_ref().and_then(Option::as_ref),
451 Self::ImageGenerating(v) => v.agent.as_ref().and_then(Option::as_ref),
452 Self::ImageCompleted(v) => v.agent.as_ref().and_then(Option::as_ref),
453 Self::CodeInterpreterInProgress(v) => v.agent.as_ref().and_then(Option::as_ref),
454 Self::CodeInterpreterInterpreting(v) => v.agent.as_ref().and_then(Option::as_ref),
455 Self::CodeInterpreterCompleted(v) => v.agent.as_ref().and_then(Option::as_ref),
456 Self::FileSearchInProgress(v) => v.agent.as_ref().and_then(Option::as_ref),
457 Self::FileSearchSearching(v) => v.agent.as_ref().and_then(Option::as_ref),
458 Self::FileSearchCompleted(v) => v.agent.as_ref().and_then(Option::as_ref),
459 Self::WebSearchInProgress(v) => v.agent.as_ref().and_then(Option::as_ref),
460 Self::WebSearchSearching(v) => v.agent.as_ref().and_then(Option::as_ref),
461 Self::WebSearchCompleted(v) => v.agent.as_ref().and_then(Option::as_ref),
462 Self::McpArgumentsDelta(v) => v.agent.as_ref().and_then(Option::as_ref),
463 Self::McpArgumentsDone(v) => v.agent.as_ref().and_then(Option::as_ref),
464 Self::McpInProgress(v) => v.agent.as_ref().and_then(Option::as_ref),
465 Self::McpCompleted(v) => v.agent.as_ref().and_then(Option::as_ref),
466 Self::McpFailed(v) => v.agent.as_ref().and_then(Option::as_ref),
467 Self::McpListToolsInProgress(v) => v.agent.as_ref().and_then(Option::as_ref),
468 Self::McpListToolsCompleted(v) => v.agent.as_ref().and_then(Option::as_ref),
469 Self::McpListToolsFailed(v) => v.agent.as_ref().and_then(Option::as_ref),
470 _ => None,
471 }
472 }
473 pub(crate) fn set_agent(&mut self, agent: Option<super::multi_agent::Agent>) {
474 match self {
475 Self::OutputItemAdded(v) => v.agent = agent.map(Some),
476 Self::OutputItemDone(v) => v.agent = agent.map(Some),
477 Self::ContentPartAdded(v) => v.agent = agent.map(Some),
478 Self::ContentPartDone(v) => v.agent = agent.map(Some),
479 Self::OutputTextDelta(v) => v.agent = agent.map(Some),
480 Self::OutputTextDone(v) => v.agent = agent.map(Some),
481 Self::OutputTextAnnotationAdded(v) => v.agent = agent.map(Some),
482 Self::RefusalDelta(v) => v.agent = agent.map(Some),
483 Self::RefusalDone(v) => v.agent = agent.map(Some),
484 Self::ReasoningTextDelta(v) => v.agent = agent.map(Some),
485 Self::ReasoningTextDone(v) => v.agent = agent.map(Some),
486 Self::ReasoningSummaryPartAdded(v) => v.agent = agent.map(Some),
487 Self::ReasoningSummaryPartDone(v) => v.agent = agent.map(Some),
488 Self::ReasoningSummaryTextDelta(v) => v.agent = agent.map(Some),
489 Self::ReasoningSummaryTextDone(v) => v.agent = agent.map(Some),
490 Self::FunctionCallArgumentsDelta(v) => v.agent = agent.map(Some),
491 Self::FunctionCallArgumentsDone(v) => v.agent = agent.map(Some),
492 Self::CustomToolInputDelta(v) => v.agent = agent.map(Some),
493 Self::CustomToolInputDone(v) => v.agent = agent.map(Some),
494 Self::CodeInterpreterCodeDelta(v) => v.agent = agent.map(Some),
495 Self::CodeInterpreterCodeDone(v) => v.agent = agent.map(Some),
496 Self::AudioDelta(v) => v.agent = agent.map(Some),
497 Self::AudioDone(v) => v.agent = agent.map(Some),
498 Self::AudioTranscriptDelta(v) => v.agent = agent.map(Some),
499 Self::AudioTranscriptDone(v) => v.agent = agent.map(Some),
500 Self::ImagePartial(v) => v.agent = agent.map(Some),
501 Self::ImageCall(v) => v.agent = agent.map(Some),
502 Self::ImageGenerating(v) => v.agent = agent.map(Some),
503 Self::ImageCompleted(v) => v.agent = agent.map(Some),
504 Self::CodeInterpreterInProgress(v) => v.agent = agent.map(Some),
505 Self::CodeInterpreterInterpreting(v) => v.agent = agent.map(Some),
506 Self::CodeInterpreterCompleted(v) => v.agent = agent.map(Some),
507 Self::FileSearchInProgress(v) => v.agent = agent.map(Some),
508 Self::FileSearchSearching(v) => v.agent = agent.map(Some),
509 Self::FileSearchCompleted(v) => v.agent = agent.map(Some),
510 Self::WebSearchInProgress(v) => v.agent = agent.map(Some),
511 Self::WebSearchSearching(v) => v.agent = agent.map(Some),
512 Self::WebSearchCompleted(v) => v.agent = agent.map(Some),
513 Self::McpArgumentsDelta(v) => v.agent = agent.map(Some),
514 Self::McpArgumentsDone(v) => v.agent = agent.map(Some),
515 Self::McpInProgress(v) => v.agent = agent.map(Some),
516 Self::McpCompleted(v) => v.agent = agent.map(Some),
517 Self::McpFailed(v) => v.agent = agent.map(Some),
518 Self::McpListToolsInProgress(v) => v.agent = agent.map(Some),
519 Self::McpListToolsCompleted(v) => v.agent = agent.map(Some),
520 Self::McpListToolsFailed(v) => v.agent = agent.map(Some),
521 _ => {}
522 }
523 }
524}
525
526impl StreamEvent {
527 pub(crate) fn output_index(&self) -> Option<i64> {
528 match self {
529 Self::OutputItemAdded(v) => Some(v.output_index),
530 Self::OutputItemDone(v) => Some(v.output_index),
531 Self::ContentPartAdded(v) => Some(v.output_index),
532 Self::ContentPartDone(v) => Some(v.output_index),
533 Self::OutputTextDelta(v) => Some(v.output_index),
534 Self::OutputTextDone(v) => Some(v.output_index),
535 Self::OutputTextAnnotationAdded(v) => Some(v.output_index),
536 Self::RefusalDelta(v) => Some(v.output_index),
537 Self::RefusalDone(v) => Some(v.output_index),
538 Self::ReasoningTextDelta(v) => Some(v.output_index),
539 Self::ReasoningTextDone(v) => Some(v.output_index),
540 Self::ReasoningSummaryPartAdded(v) => Some(v.output_index),
541 Self::ReasoningSummaryPartDone(v) => Some(v.output_index),
542 Self::ReasoningSummaryTextDelta(v) => Some(v.output_index),
543 Self::ReasoningSummaryTextDone(v) => Some(v.output_index),
544 Self::FunctionCallArgumentsDelta(v) => Some(v.output_index),
545 Self::FunctionCallArgumentsDone(v) => Some(v.output_index),
546 Self::CustomToolInputDelta(v) => Some(v.output_index),
547 Self::CustomToolInputDone(v) => Some(v.output_index),
548 Self::CodeInterpreterCodeDelta(v) => Some(v.output_index),
549 Self::CodeInterpreterCodeDone(v) => Some(v.output_index),
550 Self::ImagePartial(v) => Some(v.output_index),
551 Self::ImageCall(v) | Self::ImageGenerating(v) | Self::ImageCompleted(v) => {
552 Some(v.output_index)
553 }
554 Self::CodeInterpreterInProgress(v) => Some(v.output_index),
555 Self::CodeInterpreterInterpreting(v) => Some(v.output_index),
556 Self::CodeInterpreterCompleted(v) => Some(v.output_index),
557 Self::FileSearchInProgress(v) => Some(v.output_index),
558 Self::FileSearchSearching(v) => Some(v.output_index),
559 Self::FileSearchCompleted(v) => Some(v.output_index),
560 Self::WebSearchInProgress(v) => Some(v.output_index),
561 Self::WebSearchSearching(v) => Some(v.output_index),
562 Self::WebSearchCompleted(v) => Some(v.output_index),
563 Self::McpArgumentsDelta(v) => Some(v.output_index),
564 Self::McpArgumentsDone(v) => Some(v.output_index),
565 Self::McpInProgress(v) => Some(v.output_index),
566 Self::McpCompleted(v) => Some(v.output_index),
567 Self::McpFailed(v) => Some(v.output_index),
568 Self::McpListToolsInProgress(v) => Some(v.output_index),
569 Self::McpListToolsCompleted(v) => Some(v.output_index),
570 Self::McpListToolsFailed(v) => Some(v.output_index),
571 _ => None,
572 }
573 }
574}