Skip to main content

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

1use std::collections::BTreeMap;
2
3use serde::{Deserialize, Serialize};
4
5use super::super::{CacheControl, Citation, CitationConfig, JsonObject};
6use super::{DocumentSource, ImageSource};
7
8#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9pub struct TextBlock {
10    pub text: String,
11    #[serde(rename = "type")]
12    pub type_: TextBlockType,
13    #[serde(skip_serializing_if = "Option::is_none")]
14    pub cache_control: Option<CacheControl>,
15    #[serde(skip_serializing_if = "Option::is_none")]
16    pub citations: Option<Vec<Citation>>,
17    #[serde(default, flatten, skip_serializing_if = "BTreeMap::is_empty")]
18    pub extra: JsonObject,
19}
20
21#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
22pub enum TextBlockType {
23    #[serde(rename = "text")]
24    Text,
25}
26
27#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
28pub struct ImageBlock {
29    pub source: ImageSource,
30    #[serde(rename = "type")]
31    pub type_: ImageBlockType,
32    #[serde(skip_serializing_if = "Option::is_none")]
33    pub cache_control: Option<CacheControl>,
34}
35
36#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
37pub enum ImageBlockType {
38    #[serde(rename = "image")]
39    Image,
40}
41
42#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
43pub struct DocumentBlock {
44    pub source: DocumentSource,
45    #[serde(rename = "type")]
46    pub type_: DocumentBlockType,
47    #[serde(skip_serializing_if = "Option::is_none")]
48    pub cache_control: Option<CacheControl>,
49    #[serde(skip_serializing_if = "Option::is_none")]
50    pub citations: Option<CitationConfig>,
51    #[serde(skip_serializing_if = "Option::is_none")]
52    pub context: Option<String>,
53    #[serde(skip_serializing_if = "Option::is_none")]
54    pub title: Option<String>,
55}
56
57#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
58pub enum DocumentBlockType {
59    #[serde(rename = "document")]
60    Document,
61}
62
63#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
64pub struct SearchResultBlock {
65    pub content: Vec<TextBlock>,
66    pub source: String,
67    pub title: String,
68    #[serde(rename = "type")]
69    pub type_: SearchResultBlockType,
70    #[serde(skip_serializing_if = "Option::is_none")]
71    pub cache_control: Option<CacheControl>,
72    #[serde(skip_serializing_if = "Option::is_none")]
73    pub citations: Option<CitationConfig>,
74}
75
76#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
77pub enum SearchResultBlockType {
78    #[serde(rename = "search_result")]
79    SearchResult,
80}
81
82#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
83pub struct ThinkingBlock {
84    pub signature: String,
85    pub thinking: String,
86    #[serde(rename = "type")]
87    pub type_: ThinkingBlockType,
88}
89
90#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
91pub enum ThinkingBlockType {
92    #[serde(rename = "thinking")]
93    Thinking,
94}
95
96#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
97pub struct RedactedThinkingBlock {
98    pub data: String,
99    #[serde(rename = "type")]
100    pub type_: RedactedThinkingBlockType,
101}
102
103#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
104pub enum RedactedThinkingBlockType {
105    #[serde(rename = "redacted_thinking")]
106    RedactedThinking,
107}