Skip to main content

objectiveai_sdk/functions/executions/response/streaming/
reasoning_summary_chunk.rs

1use crate::{agent, error};
2use serde::{Deserialize, Serialize};
3use schemars::JsonSchema;
4
5#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default, JsonSchema, arbitrary::Arbitrary)]
6#[schemars(rename = "functions.executions.response.streaming.ReasoningSummaryChunk")]
7pub struct ReasoningSummaryChunk {
8    #[serde(flatten)]
9    pub inner: agent::completions::response::streaming::AgentCompletionChunk,
10    #[serde(skip_serializing_if = "Option::is_none")]
11    #[schemars(extend("omitempty" = true))]
12    pub error: Option<error::ResponseError>,
13}
14
15impl ReasoningSummaryChunk {
16    pub fn push(&mut self, other: &ReasoningSummaryChunk) {
17        self.inner.push(&other.inner);
18        if let Some(error) = &other.error {
19            self.error = Some(error.clone());
20        }
21    }
22
23    /// Produces log files for this reasoning summary.
24    ///
25    /// Returns `(reference, files)`. Files under `agent/completions/`.
26    #[cfg(feature = "filesystem")]
27    pub fn produce_files(&self) -> (serde_json::Value, Vec<crate::filesystem::logs::LogFile>) {
28        let (mut reference, files) = match self.inner.produce_files() {
29            Some((reference, files)) => (reference, files),
30            None => return (serde_json::json!({ "type": "reference" }), Vec::new()),
31        };
32        if let Some(error) = &self.error {
33            if let Some(map) = reference.as_object_mut() {
34                map.insert("error".to_string(), serde_json::to_value(error).unwrap());
35            }
36        }
37        (reference, files)
38    }
39}