Skip to main content

objectiveai_sdk/functions/inventions/recursive/response/streaming/
inner_error.rs

1use std::borrow::Cow;
2
3use serde::{Deserialize, Serialize};
4
5use crate::error;
6
7/// An inner error from a [`FunctionInventionRecursiveChunk`](super::FunctionInventionRecursiveChunk).
8///
9/// Always carries `function_invention_index` identifying which wrapped
10/// non-recursive `FunctionInventionChunk` produced the error (matches
11/// [`FunctionInventionChunk::index`](super::FunctionInventionChunk::index)).
12///
13/// The optional `agent_completion_index` disambiguates the failure site:
14///
15/// - `None` → the wrapped invention's own top-level `.error` (the invention
16///   itself failed).
17/// - `Some(N)` → an inner error from agent completion `N` inside the
18///   wrapped invention (one of the items the non-recursive invention's
19///   own `inner_errors()` would have yielded).
20///
21/// Wire shape:
22/// ```json
23/// { "function_invention_index": 0, "error": { } }
24/// { "function_invention_index": 0, "agent_completion_index": 2, "error": { } }
25/// ```
26///
27/// `agent_completion_index` is omitted on the wire when `None`,
28/// matching the chunk-format conventions in the rest of the SDK.
29///
30/// The recursive chunk has no top-level `.error` field of its own,
31/// so there is nothing to exclude at this level.
32#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
33pub struct InnerError<'a> {
34    /// Index of the wrapped non-recursive `FunctionInventionChunk`.
35    pub function_invention_index: u64,
36    /// `Some(N)` if the error came from agent completion `N` inside the
37    /// wrapped invention; `None` if the error is the wrapped invention's
38    /// own top-level `.error`.
39    #[serde(default, skip_serializing_if = "Option::is_none")]
40    pub agent_completion_index: Option<u64>,
41    /// The underlying error.
42    pub error: Cow<'a, error::ResponseError>,
43}