Skip to main content

gproxy_protocol/claude/common/blocks/
sources.rs

1use serde::{Deserialize, Serialize};
2
3use super::super::JsonObject;
4use super::{ImageBlock, TextBlock};
5
6#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7#[serde(untagged)]
8#[non_exhaustive]
9pub enum ImageSource {
10    Base64(Base64ImageSource),
11    Url(UrlImageSource),
12    File(FileImageSource),
13    Raw(serde_json::Value),
14}
15
16#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
17#[serde(untagged)]
18#[non_exhaustive]
19pub enum DocumentSource {
20    Base64(Base64PdfSource),
21    Text(PlainTextSource),
22    Content(ContentSource),
23    Url(UrlDocumentSource),
24    File(FileDocumentSource),
25    Raw(serde_json::Value),
26}
27
28#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
29#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
30pub struct Base64ImageSource {
31    pub data: String,
32    pub media_type: ImageMediaType,
33    #[serde(rename = "type")]
34    pub type_: Base64SourceType,
35    #[serde(default, flatten, skip_serializing_if = "JsonObject::is_empty")]
36    pub rest: serde_json::Map<String, serde_json::Value>,
37}
38
39#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
40#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
41pub struct Base64PdfSource {
42    pub data: String,
43    pub media_type: PdfMediaType,
44    #[serde(rename = "type")]
45    pub type_: Base64SourceType,
46    #[serde(default, flatten, skip_serializing_if = "JsonObject::is_empty")]
47    pub rest: serde_json::Map<String, serde_json::Value>,
48}
49
50#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
51#[non_exhaustive]
52pub enum Base64SourceType {
53    #[serde(rename = "base64")]
54    Base64,
55}
56
57#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
58#[non_exhaustive]
59pub enum ImageMediaType {
60    #[serde(rename = "image/jpeg")]
61    Jpeg,
62    #[serde(rename = "image/png")]
63    Png,
64    #[serde(rename = "image/gif")]
65    Gif,
66    #[serde(rename = "image/webp")]
67    Webp,
68}
69
70#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
71#[non_exhaustive]
72pub enum PdfMediaType {
73    #[serde(rename = "application/pdf")]
74    ApplicationPdf,
75}
76
77#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
78#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
79pub struct UrlImageSource {
80    #[serde(rename = "type")]
81    pub type_: UrlSourceType,
82    pub url: String,
83    #[serde(default, flatten, skip_serializing_if = "JsonObject::is_empty")]
84    pub rest: serde_json::Map<String, serde_json::Value>,
85}
86
87#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
88#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
89pub struct UrlDocumentSource {
90    #[serde(rename = "type")]
91    pub type_: UrlSourceType,
92    pub url: String,
93    #[serde(default, flatten, skip_serializing_if = "JsonObject::is_empty")]
94    pub rest: serde_json::Map<String, serde_json::Value>,
95}
96
97#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
98#[non_exhaustive]
99pub enum UrlSourceType {
100    #[serde(rename = "url")]
101    Url,
102}
103
104#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
105#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
106pub struct FileImageSource {
107    pub file_id: String,
108    #[serde(rename = "type")]
109    pub type_: FileSourceType,
110    #[serde(default, flatten, skip_serializing_if = "JsonObject::is_empty")]
111    pub rest: serde_json::Map<String, serde_json::Value>,
112}
113
114#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
115#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
116pub struct FileDocumentSource {
117    pub file_id: String,
118    #[serde(rename = "type")]
119    pub type_: FileSourceType,
120    #[serde(default, flatten, skip_serializing_if = "JsonObject::is_empty")]
121    pub rest: serde_json::Map<String, serde_json::Value>,
122}
123
124#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
125#[non_exhaustive]
126pub enum FileSourceType {
127    #[serde(rename = "file")]
128    File,
129}
130
131#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
132#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
133pub struct PlainTextSource {
134    pub data: String,
135    pub media_type: PlainTextMediaType,
136    #[serde(rename = "type")]
137    pub type_: TextSourceType,
138    #[serde(default, flatten, skip_serializing_if = "JsonObject::is_empty")]
139    pub rest: serde_json::Map<String, serde_json::Value>,
140}
141
142#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
143#[non_exhaustive]
144pub enum PlainTextMediaType {
145    #[serde(rename = "text/plain")]
146    TextPlain,
147}
148
149#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
150#[non_exhaustive]
151pub enum TextSourceType {
152    #[serde(rename = "text")]
153    Text,
154}
155
156#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
157#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
158pub struct ContentSource {
159    pub content: ContentSourceContent,
160    #[serde(rename = "type")]
161    pub type_: ContentSourceType,
162    #[serde(default, flatten, skip_serializing_if = "JsonObject::is_empty")]
163    pub rest: serde_json::Map<String, serde_json::Value>,
164}
165
166#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
167#[non_exhaustive]
168pub enum ContentSourceType {
169    #[serde(rename = "content")]
170    Content,
171}
172
173#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
174#[serde(untagged)]
175#[non_exhaustive]
176pub enum ContentSourceContent {
177    Text(String),
178    Blocks(Vec<ContentSourceBlock>),
179    Raw(serde_json::Value),
180}
181
182#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
183#[serde(untagged)]
184#[non_exhaustive]
185pub enum ContentSourceBlock {
186    Text(TextBlock),
187    Image(ImageBlock),
188    Raw(serde_json::Value),
189}