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