Skip to main content

gproxy_protocol/wire/claude/
files.rs

1//! Source: upstream_docs/claude/docs/files/{upload,list,index,delete,download}.md.
2use crate::connection::{HttpBody, MultipartPart};
3use crate::{Rest, WireRequest, WireResponse};
4use serde::{Deserialize, Serialize};
5
6#[derive(
7    Debug, Clone, PartialEq, Eq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder,
8)]
9#[serde(rename_all = "snake_case")]
10#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
11#[derive(gproxy_protocol_macros::DeclaredFields)]
12#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
13pub struct FileMetadata {
14    #[serde(
15        default,
16        deserialize_with = "present_nullable",
17        skip_serializing_if = "Option::is_none"
18    )]
19    pub expires_at: Option<Option<String>>,
20    pub id: String,
21    pub created_at: String,
22    pub filename: String,
23    pub mime_type: String,
24    pub size_bytes: i64,
25    #[serde(rename = "type")]
26    pub type_: FileType,
27    #[serde(
28        default,
29        deserialize_with = "present_optional",
30        skip_serializing_if = "Option::is_none"
31    )]
32    pub downloadable: Option<bool>,
33    #[serde(
34        default,
35        deserialize_with = "present_optional",
36        skip_serializing_if = "Option::is_none"
37    )]
38    pub scope: Option<FileScope>,
39    #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
40    pub rest: Rest,
41}
42#[derive(
43    Debug, Clone, PartialEq, Eq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder,
44)]
45#[serde(rename_all = "snake_case")]
46#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
47#[derive(gproxy_protocol_macros::DeclaredFields)]
48#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
49pub struct FileScope {
50    pub id: String,
51    #[serde(rename = "type")]
52    pub type_: FileScopeType,
53    #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
54    pub rest: Rest,
55}
56#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
57#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
58#[derive(gproxy_protocol_macros::DeclaredFields)]
59#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
60pub enum FileType {
61    #[serde(rename = "file")]
62    File,
63}
64#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
65#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
66#[derive(gproxy_protocol_macros::DeclaredFields)]
67#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
68pub enum FileScopeType {
69    #[serde(rename = "session")]
70    Session,
71}
72#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
73#[serde(rename_all = "snake_case")]
74#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
75#[derive(gproxy_protocol_macros::DeclaredFields)]
76#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
77pub struct ListFilesQuery {
78    #[serde(skip_serializing_if = "Option::is_none")]
79    pub page: Option<String>,
80    #[serde(skip_serializing_if = "Option::is_none")]
81    pub ids: Option<Vec<String>>,
82    #[serde(
83        default,
84        deserialize_with = "present_optional",
85        skip_serializing_if = "Option::is_none"
86    )]
87    pub after_id: Option<String>,
88    #[serde(
89        default,
90        deserialize_with = "present_optional",
91        skip_serializing_if = "Option::is_none"
92    )]
93    pub before_id: Option<String>,
94    #[serde(
95        default,
96        deserialize_with = "present_optional",
97        skip_serializing_if = "Option::is_none"
98    )]
99    pub limit: Option<i64>,
100    #[serde(
101        default,
102        deserialize_with = "present_optional",
103        skip_serializing_if = "Option::is_none"
104    )]
105    pub scope_id: Option<String>,
106    #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
107    pub rest: Rest,
108}
109#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
110#[serde(rename_all = "snake_case")]
111#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
112#[derive(gproxy_protocol_macros::DeclaredFields)]
113#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
114pub struct ListFilesResponseBody {
115    #[serde(
116        default,
117        deserialize_with = "present_nullable",
118        skip_serializing_if = "Option::is_none"
119    )]
120    pub next_page: Option<Option<String>>,
121    pub data: Vec<FileMetadata>,
122    #[serde(
123        default,
124        deserialize_with = "present_optional",
125        skip_serializing_if = "Option::is_none"
126    )]
127    pub first_id: Option<String>,
128    #[serde(
129        default,
130        deserialize_with = "present_optional",
131        skip_serializing_if = "Option::is_none"
132    )]
133    pub has_more: Option<bool>,
134    #[serde(
135        default,
136        deserialize_with = "present_optional",
137        skip_serializing_if = "Option::is_none"
138    )]
139    pub last_id: Option<String>,
140    #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
141    pub rest: Rest,
142}
143#[derive(
144    Debug, Clone, PartialEq, Eq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder,
145)]
146#[serde(rename_all = "snake_case")]
147#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
148#[derive(gproxy_protocol_macros::DeclaredFields)]
149#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
150pub struct DeleteFileResponseBody {
151    pub id: String,
152    #[serde(
153        rename = "type",
154        default,
155        deserialize_with = "present_optional",
156        skip_serializing_if = "Option::is_none"
157    )]
158    pub type_: Option<DeletedFileType>,
159    #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
160    pub rest: Rest,
161}
162#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
163#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
164#[derive(gproxy_protocol_macros::DeclaredFields)]
165#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
166pub enum DeletedFileType {
167    #[serde(rename = "file_deleted")]
168    FileDeleted,
169}
170#[derive(Debug, gproxy_protocol_macros::WireBuilder)]
171#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
172#[derive(gproxy_protocol_macros::DeclaredFields)]
173#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
174pub struct UploadFileForm {
175    pub expires_in_seconds: Option<i64>,
176    pub file: MultipartPart,
177}
178pub type UploadFileRequest = WireRequest<UploadFileForm>;
179pub type RawUploadFileRequest = WireRequest<crate::connection::Multipart>;
180pub type UploadFileResponse = WireResponse<FileMetadata>;
181pub type ListFilesRequest = WireRequest<()>;
182pub type ListFilesResponse = WireResponse<ListFilesResponseBody>;
183pub type ListFilesWireResponse = WireResponse<ListFilesResponseBody>;
184pub type RetrieveFileRequest = WireRequest<()>;
185pub type RetrieveFileResponse = WireResponse<FileMetadata>;
186pub type RetrieveFileContentRequest = WireRequest<()>;
187pub type RetrieveFileContentResponse = WireResponse<HttpBody>;
188pub type DeleteFileRequest = WireRequest<()>;
189pub type DeleteFileResponse = WireResponse<DeleteFileResponseBody>;
190pub type DeleteFileWireResponse = DeleteFileResponse;
191
192fn present_optional<'de, D, T>(d: D) -> Result<Option<T>, D::Error>
193where
194    D: serde::Deserializer<'de>,
195    T: Deserialize<'de>,
196{
197    T::deserialize(d).map(Some)
198}
199
200fn present_nullable<'de, D, T>(d: D) -> Result<Option<Option<T>>, D::Error>
201where
202    D: serde::Deserializer<'de>,
203    T: Deserialize<'de>,
204{
205    Option::<T>::deserialize(d).map(Some)
206}