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, Deserialize)]
19 #[serde(untagged)]
20 pub enum $outer {
21 Known($known),
22 Unknown(String),
23 }
24
25 #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
26 pub enum $known {
27 $(#[serde(rename = $wire)] $variant,)+
28 }
29 };
30}
31
32macro_rules! error_type {
33 ($name:ident { $variant:ident => $wire:literal }) => {
34 #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
35 pub enum $name {
36 #[serde(rename = $wire)]
37 $variant,
38 }
39 };
40}
41
42error_code!(WebSearchToolResultErrorCode, WebSearchToolResultErrorCodeKnown {
43 InvalidToolInput => "invalid_tool_input",
44 Unavailable => "unavailable",
45 MaxUsesExceeded => "max_uses_exceeded",
46 TooManyRequests => "too_many_requests",
47 QueryTooLong => "query_too_long",
48 RequestTooLarge => "request_too_large",
49});
50error_type!(WebSearchToolResultErrorType {
51 WebSearchToolResultError => "web_search_tool_result_error"
52});
53pub type WebSearchToolResultError =
54 ServerToolResultError<WebSearchToolResultErrorCode, WebSearchToolResultErrorType>;
55
56error_code!(WebFetchToolResultErrorCode, WebFetchToolResultErrorCodeKnown {
57 InvalidToolInput => "invalid_tool_input",
58 UrlTooLong => "url_too_long",
59 UrlNotAllowed => "url_not_allowed",
60 UrlNotInPriorContext => "url_not_in_prior_context",
61 UrlNotAccessible => "url_not_accessible",
62 UnsupportedContentType => "unsupported_content_type",
63 TooManyRequests => "too_many_requests",
64 MaxUsesExceeded => "max_uses_exceeded",
65 Unavailable => "unavailable",
66});
67error_type!(WebFetchToolResultErrorType {
68 WebFetchToolResultError => "web_fetch_tool_result_error"
69});
70pub type WebFetchToolResultError =
71 ServerToolResultError<WebFetchToolResultErrorCode, WebFetchToolResultErrorType>;
72
73error_code!(AdvisorToolResultErrorCode, AdvisorToolResultErrorCodeKnown {
74 MaxUsesExceeded => "max_uses_exceeded",
75 PromptTooLong => "prompt_too_long",
76 TooManyRequests => "too_many_requests",
77 Overloaded => "overloaded",
78 Unavailable => "unavailable",
79 ExecutionTimeExceeded => "execution_time_exceeded",
80});
81error_type!(AdvisorToolResultErrorType {
82 AdvisorToolResultError => "advisor_tool_result_error"
83});
84pub type AdvisorToolResultError =
85 ServerToolResultError<AdvisorToolResultErrorCode, AdvisorToolResultErrorType>;
86
87error_code!(CodeExecutionToolResultErrorCode, CodeExecutionToolResultErrorCodeKnown {
88 InvalidToolInput => "invalid_tool_input",
89 Unavailable => "unavailable",
90 TooManyRequests => "too_many_requests",
91 ExecutionTimeExceeded => "execution_time_exceeded",
92});
93error_type!(CodeExecutionToolResultErrorType {
94 CodeExecutionToolResultError => "code_execution_tool_result_error"
95});
96pub type CodeExecutionToolResultError =
97 ServerToolResultError<CodeExecutionToolResultErrorCode, CodeExecutionToolResultErrorType>;
98
99error_code!(
100 BashCodeExecutionToolResultErrorCode,
101 BashCodeExecutionToolResultErrorCodeKnown {
102 InvalidToolInput => "invalid_tool_input",
103 Unavailable => "unavailable",
104 TooManyRequests => "too_many_requests",
105 ExecutionTimeExceeded => "execution_time_exceeded",
106 OutputFileTooLarge => "output_file_too_large",
107 }
108);
109error_type!(BashCodeExecutionToolResultErrorType {
110 BashCodeExecutionToolResultError => "bash_code_execution_tool_result_error"
111});
112pub type BashCodeExecutionToolResultError = ServerToolResultError<
113 BashCodeExecutionToolResultErrorCode,
114 BashCodeExecutionToolResultErrorType,
115>;
116
117error_code!(
118 TextEditorCodeExecutionToolResultErrorCode,
119 TextEditorCodeExecutionToolResultErrorCodeKnown {
120 InvalidToolInput => "invalid_tool_input",
121 Unavailable => "unavailable",
122 TooManyRequests => "too_many_requests",
123 ExecutionTimeExceeded => "execution_time_exceeded",
124 FileNotFound => "file_not_found",
125 }
126);
127error_type!(TextEditorCodeExecutionToolResultErrorType {
128 TextEditorCodeExecutionToolResultError => "text_editor_code_execution_tool_result_error"
129});
130pub type TextEditorCodeExecutionToolResultError = ServerToolResultError<
131 TextEditorCodeExecutionToolResultErrorCode,
132 TextEditorCodeExecutionToolResultErrorType,
133>;
134
135error_code!(ToolSearchToolResultErrorCode, ToolSearchToolResultErrorCodeKnown {
136 InvalidToolInput => "invalid_tool_input",
137 Unavailable => "unavailable",
138 TooManyRequests => "too_many_requests",
139 ExecutionTimeExceeded => "execution_time_exceeded",
140});
141error_type!(ToolSearchToolResultErrorType {
142 ToolSearchToolResultError => "tool_search_tool_result_error"
143});
144pub type ToolSearchToolResultError =
145 ServerToolResultError<ToolSearchToolResultErrorCode, ToolSearchToolResultErrorType>;