Skip to main content

gproxy_protocol/protocol/claude/common/blocks/
response.rs

1use serde::{Deserialize, Serialize};
2
3use super::super::server_tools::ResponseWebSearchToolResultContent;
4use super::super::{Caller, Citation, JsonObject, ServerToolUseName, StringOrArray};
5use super::{
6    CompactionBlockType, ContainerUploadBlockType, ServerToolUseBlockType, TextBlockType,
7    ToolUseBlockType, WebSearchResultBlockType, WebSearchToolResultBlockType,
8};
9
10#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
11#[non_exhaustive]
12pub struct ResponseTextBlock {
13    #[serde(skip_serializing_if = "Option::is_none")]
14    pub citations: Option<Vec<Citation>>,
15    pub text: String,
16    #[serde(rename = "type")]
17    pub type_: TextBlockType,
18    #[serde(default, flatten, skip_serializing_if = "JsonObject::is_empty")]
19    pub extra: JsonObject,
20}
21
22#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
23#[non_exhaustive]
24pub struct ResponseToolUseBlock {
25    pub id: String,
26    pub input: JsonObject,
27    pub name: String,
28    #[serde(rename = "type")]
29    pub type_: ToolUseBlockType,
30    #[serde(skip_serializing_if = "Option::is_none")]
31    pub caller: Option<Caller>,
32    #[serde(default, flatten, skip_serializing_if = "JsonObject::is_empty")]
33    pub extra: JsonObject,
34}
35
36#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
37#[non_exhaustive]
38pub struct ResponseServerToolUseBlock {
39    pub id: String,
40    pub input: JsonObject,
41    pub name: ServerToolUseName,
42    #[serde(rename = "type")]
43    pub type_: ServerToolUseBlockType,
44    #[serde(skip_serializing_if = "Option::is_none")]
45    pub caller: Option<Caller>,
46    #[serde(default, flatten, skip_serializing_if = "JsonObject::is_empty")]
47    pub extra: JsonObject,
48}
49
50#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
51#[non_exhaustive]
52pub struct ResponseWebSearchToolResultBlock {
53    pub content: ResponseWebSearchToolResultContent,
54    pub tool_use_id: String,
55    #[serde(rename = "type")]
56    pub type_: WebSearchToolResultBlockType,
57    #[serde(skip_serializing_if = "Option::is_none")]
58    pub caller: Option<Caller>,
59    #[serde(default, flatten, skip_serializing_if = "JsonObject::is_empty")]
60    pub extra: JsonObject,
61}
62
63#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
64#[non_exhaustive]
65pub struct ResponseWebSearchResultBlock {
66    pub encrypted_content: String,
67    pub page_age: Option<String>,
68    pub title: String,
69    #[serde(rename = "type")]
70    pub type_: WebSearchResultBlockType,
71    pub url: String,
72    #[serde(default, flatten, skip_serializing_if = "JsonObject::is_empty")]
73    pub extra: JsonObject,
74}
75
76#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
77#[non_exhaustive]
78pub struct ResponseToolReferenceBlock {
79    pub tool_name: String,
80    #[serde(rename = "type")]
81    pub type_: ResponseToolReferenceBlockType,
82    #[serde(default, flatten, skip_serializing_if = "JsonObject::is_empty")]
83    pub extra: JsonObject,
84}
85
86#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
87#[non_exhaustive]
88pub enum ResponseToolReferenceBlockType {
89    #[serde(rename = "tool_reference")]
90    ToolReference,
91}
92
93#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
94#[non_exhaustive]
95pub struct ResponseMcpToolUseBlock {
96    pub id: String,
97    pub input: JsonObject,
98    pub name: String,
99    pub server_name: String,
100    #[serde(rename = "type")]
101    pub type_: ResponseMcpToolUseBlockType,
102    #[serde(default, flatten, skip_serializing_if = "JsonObject::is_empty")]
103    pub extra: JsonObject,
104}
105
106#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
107#[non_exhaustive]
108pub enum ResponseMcpToolUseBlockType {
109    #[serde(rename = "mcp_tool_use")]
110    McpToolUse,
111}
112
113#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
114#[non_exhaustive]
115pub struct ResponseMcpToolResultBlock {
116    pub content: ResponseMcpToolResultContent,
117    pub is_error: bool,
118    pub tool_use_id: String,
119    #[serde(rename = "type")]
120    pub type_: ResponseMcpToolResultBlockType,
121    #[serde(default, flatten, skip_serializing_if = "JsonObject::is_empty")]
122    pub extra: JsonObject,
123}
124
125#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
126#[non_exhaustive]
127pub enum ResponseMcpToolResultBlockType {
128    #[serde(rename = "mcp_tool_result")]
129    McpToolResult,
130}
131
132pub type ResponseMcpToolResultContent = StringOrArray<ResponseTextBlock>;
133
134#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
135#[non_exhaustive]
136pub struct ResponseContainerUploadBlock {
137    pub file_id: String,
138    #[serde(rename = "type")]
139    pub type_: ContainerUploadBlockType,
140    #[serde(default, flatten, skip_serializing_if = "JsonObject::is_empty")]
141    pub extra: JsonObject,
142}
143
144#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
145#[non_exhaustive]
146pub struct ResponseCompactionBlock {
147    pub content: Option<String>,
148    pub encrypted_content: String,
149    #[serde(rename = "type")]
150    pub type_: CompactionBlockType,
151    #[serde(default, flatten, skip_serializing_if = "JsonObject::is_empty")]
152    pub extra: JsonObject,
153}