gproxy_protocol/protocol/claude/common/server_tools/
errors.rs1use serde::{Deserialize, Serialize};
2
3use super::super::JsonObject;
4
5#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6pub struct ServerToolResultError<C, T> {
7 pub error_code: C,
8 #[serde(rename = "type")]
9 pub type_: T,
10 #[serde(skip_serializing_if = "Option::is_none")]
11 pub error_message: Option<String>,
12 #[serde(default, flatten, skip_serializing_if = "JsonObject::is_empty")]
13 pub extra: JsonObject,
14}
15
16macro_rules! error_code {
17 ($outer:ident, $known:ident { $($variant:ident => $wire:literal),+ $(,)? }) => {
18 #[derive(Debug, Clone, PartialEq, Eq, Serialize)]
19 #[serde(untagged)]
20 pub enum $outer {
21 Known($known),
22 Unknown(String),
23 }
24
25 impl<'de> serde::Deserialize<'de> for $outer {
29 fn deserialize<D: serde::Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
30 crate::protocol::extensible::deserialize_extensible(d, Self::Known, Self::Unknown)
31 }
32 }
33
34 #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
35 pub enum $known {
36 $(#[serde(rename = $wire)] $variant,)+
37 }
38 };
39}
40
41macro_rules! error_type {
42 ($name:ident { $variant:ident => $wire:literal }) => {
43 #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
44 pub enum $name {
45 #[serde(rename = $wire)]
46 $variant,
47 }
48 };
49}
50
51error_code!(WebSearchToolResultErrorCode, WebSearchToolResultErrorCodeKnown {
52 InvalidToolInput => "invalid_tool_input",
53 Unavailable => "unavailable",
54 MaxUsesExceeded => "max_uses_exceeded",
55 TooManyRequests => "too_many_requests",
56 QueryTooLong => "query_too_long",
57 RequestTooLarge => "request_too_large",
58});
59error_type!(WebSearchToolResultErrorType {
60 WebSearchToolResultError => "web_search_tool_result_error"
61});
62pub type WebSearchToolResultError =
63 ServerToolResultError<WebSearchToolResultErrorCode, WebSearchToolResultErrorType>;
64
65error_code!(WebFetchToolResultErrorCode, WebFetchToolResultErrorCodeKnown {
66 InvalidToolInput => "invalid_tool_input",
67 UrlTooLong => "url_too_long",
68 UrlNotAllowed => "url_not_allowed",
69 UrlNotInPriorContext => "url_not_in_prior_context",
70 UrlNotAccessible => "url_not_accessible",
71 UnsupportedContentType => "unsupported_content_type",
72 TooManyRequests => "too_many_requests",
73 MaxUsesExceeded => "max_uses_exceeded",
74 Unavailable => "unavailable",
75});
76error_type!(WebFetchToolResultErrorType {
77 WebFetchToolResultError => "web_fetch_tool_result_error"
78});
79pub type WebFetchToolResultError =
80 ServerToolResultError<WebFetchToolResultErrorCode, WebFetchToolResultErrorType>;
81
82error_code!(AdvisorToolResultErrorCode, AdvisorToolResultErrorCodeKnown {
83 MaxUsesExceeded => "max_uses_exceeded",
84 PromptTooLong => "prompt_too_long",
85 TooManyRequests => "too_many_requests",
86 Overloaded => "overloaded",
87 Unavailable => "unavailable",
88 ExecutionTimeExceeded => "execution_time_exceeded",
89});
90error_type!(AdvisorToolResultErrorType {
91 AdvisorToolResultError => "advisor_tool_result_error"
92});
93pub type AdvisorToolResultError =
94 ServerToolResultError<AdvisorToolResultErrorCode, AdvisorToolResultErrorType>;
95
96error_code!(CodeExecutionToolResultErrorCode, CodeExecutionToolResultErrorCodeKnown {
97 InvalidToolInput => "invalid_tool_input",
98 Unavailable => "unavailable",
99 TooManyRequests => "too_many_requests",
100 ExecutionTimeExceeded => "execution_time_exceeded",
101});
102error_type!(CodeExecutionToolResultErrorType {
103 CodeExecutionToolResultError => "code_execution_tool_result_error"
104});
105pub type CodeExecutionToolResultError =
106 ServerToolResultError<CodeExecutionToolResultErrorCode, CodeExecutionToolResultErrorType>;
107
108error_code!(
109 BashCodeExecutionToolResultErrorCode,
110 BashCodeExecutionToolResultErrorCodeKnown {
111 InvalidToolInput => "invalid_tool_input",
112 Unavailable => "unavailable",
113 TooManyRequests => "too_many_requests",
114 ExecutionTimeExceeded => "execution_time_exceeded",
115 OutputFileTooLarge => "output_file_too_large",
116 }
117);
118error_type!(BashCodeExecutionToolResultErrorType {
119 BashCodeExecutionToolResultError => "bash_code_execution_tool_result_error"
120});
121pub type BashCodeExecutionToolResultError = ServerToolResultError<
122 BashCodeExecutionToolResultErrorCode,
123 BashCodeExecutionToolResultErrorType,
124>;
125
126error_code!(
127 TextEditorCodeExecutionToolResultErrorCode,
128 TextEditorCodeExecutionToolResultErrorCodeKnown {
129 InvalidToolInput => "invalid_tool_input",
130 Unavailable => "unavailable",
131 TooManyRequests => "too_many_requests",
132 ExecutionTimeExceeded => "execution_time_exceeded",
133 FileNotFound => "file_not_found",
134 }
135);
136error_type!(TextEditorCodeExecutionToolResultErrorType {
137 TextEditorCodeExecutionToolResultError => "text_editor_code_execution_tool_result_error"
138});
139pub type TextEditorCodeExecutionToolResultError = ServerToolResultError<
140 TextEditorCodeExecutionToolResultErrorCode,
141 TextEditorCodeExecutionToolResultErrorType,
142>;
143
144error_code!(ToolSearchToolResultErrorCode, ToolSearchToolResultErrorCodeKnown {
145 InvalidToolInput => "invalid_tool_input",
146 Unavailable => "unavailable",
147 TooManyRequests => "too_many_requests",
148 ExecutionTimeExceeded => "execution_time_exceeded",
149});
150error_type!(ToolSearchToolResultErrorType {
151 ToolSearchToolResultError => "tool_search_tool_result_error"
152});
153pub type ToolSearchToolResultError =
154 ServerToolResultError<ToolSearchToolResultErrorCode, ToolSearchToolResultErrorType>;