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