Skip to main content

gproxy_protocol/wire/openai/responses/
errors.rs

1//! Tool errors from upstream_docs/openai/docs/Create a model response.md.
2use super::input::{present_optional, required_nullable};
3use crate::Rest;
4use serde::{Deserialize, Serialize};
5
6#[derive(
7    Debug, Clone, PartialEq, Eq, Serialize, Deserialize, gproxy_protocol_macros::DeclaredFields,
8)]
9#[serde(untagged)]
10#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
11#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
12pub enum McpToolCallError {
13    Detailed(McpToolCallErrorDetails),
14    /// Earlier Responses references represented MCP errors as strings.
15    Legacy(String),
16}
17
18#[derive(
19    Debug, Clone, PartialEq, Eq, Serialize, Deserialize, gproxy_protocol_macros::DeclaredFields,
20)]
21#[serde(tag = "type")]
22#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
23#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
24pub enum McpToolCallErrorDetails {
25    #[serde(rename = "mcp_protocol_error")]
26    Protocol {
27        code: i64,
28        message: String,
29        #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
30        rest: Rest,
31    },
32    #[serde(rename = "mcp_tool_execution_error")]
33    Execution {
34        content: serde_json::Value,
35        #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
36        rest: Rest,
37    },
38    #[serde(rename = "http_error")]
39    Http {
40        code: i64,
41        message: String,
42        #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
43        rest: Rest,
44    },
45}
46
47#[derive(
48    Debug,
49    Clone,
50    PartialEq,
51    Eq,
52    Serialize,
53    Deserialize,
54    gproxy_protocol_macros::WireBuilder,
55    gproxy_protocol_macros::DeclaredFields,
56)]
57#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
58#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
59pub struct ImageGenerationCallError {
60    #[wire(required)]
61    #[cfg_attr(feature = "schema", schemars(extend("x-gproxy-required" = true)))]
62    #[serde(deserialize_with = "required_nullable")]
63    pub code: Option<String>,
64    pub message: String,
65    #[wire(required)]
66    #[cfg_attr(feature = "schema", schemars(extend("x-gproxy-required" = true)))]
67    #[serde(deserialize_with = "required_nullable")]
68    pub param: Option<String>,
69    #[serde(rename = "type")]
70    pub type_: String,
71    #[serde(
72        default,
73        deserialize_with = "present_optional",
74        skip_serializing_if = "Option::is_none"
75    )]
76    pub moderation_details: Option<ImageModerationDetails>,
77    #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
78    pub rest: Rest,
79}
80
81#[derive(
82    Debug,
83    Clone,
84    PartialEq,
85    Eq,
86    Serialize,
87    Deserialize,
88    gproxy_protocol_macros::WireBuilder,
89    gproxy_protocol_macros::DeclaredFields,
90)]
91#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
92#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
93pub struct ImageModerationDetails {
94    pub categories: Vec<String>,
95    pub moderation_stage: ImageModerationStage,
96    #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
97    pub rest: Rest,
98}
99
100#[derive(
101    Debug,
102    Clone,
103    Copy,
104    PartialEq,
105    Eq,
106    Serialize,
107    Deserialize,
108    gproxy_protocol_macros::DeclaredFields,
109)]
110#[serde(rename_all = "snake_case")]
111#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
112#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
113pub enum ImageModerationStage {
114    Input,
115    Output,
116    Unknown,
117}