Skip to main content

uarp_sdk/generated/api/
files.rs

1// Code generated by @uarp/codegen from spec/openapi.json. DO NOT EDIT.
2//!
3//! File upload for multimodal content
4
5#![allow(unused_imports, clippy::too_many_arguments)]
6
7use reqwest::Method;
8use serde::{Deserialize, Serialize};
9use futures_core::Stream;
10
11use crate::client::{Client, Request, NO_BODY, NO_QUERY};
12use crate::error::Result;
13use crate::generated::models;
14use crate::multipart::{field_text, FilePart};
15use crate::pagination::CursorGuard;
16use crate::util::encode_path;
17
18/// Query and header parameters for `listFiles`.
19#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
20pub struct ListFilesParams {
21    #[serde(default, skip_serializing_if = "Option::is_none")]
22    pub mime_prefix: Option<String>,
23    #[serde(default, skip_serializing_if = "Option::is_none")]
24    pub limit: Option<i64>,
25    #[serde(default, skip_serializing_if = "Option::is_none")]
26    pub cursor: Option<String>,
27}
28
29/// File upload for multimodal content
30#[derive(Debug, Clone)]
31pub struct FilesApi {
32    pub(crate) client: Client,
33}
34
35impl Client {
36    /// File upload for multimodal content
37    pub fn files(&self) -> FilesApi {
38        FilesApi { client: self.clone() }
39    }
40}
41
42impl FilesApi {
43    /// Delete file
44    ///
45    /// `DELETE /api/v1/files/{fileId}`
46    ///
47    /// Required scopes: `files:write`.
48    pub async fn delete(&self, file_id: &str) -> Result<models::DeleteFileResponse> {
49        self.client
50            .request_json(Request {
51                method: Method::DELETE,
52                path: format!("/api/v1/files/{}", encode_path(file_id)),
53                query: NO_QUERY,
54                body: NO_BODY,
55                headers: Vec::new(),
56                idempotent: true,
57            })
58            .await
59    }
60
61    /// Download file content
62    ///
63    /// `GET /api/v1/files/{fileId}/content`
64    ///
65    /// Required scopes: `files:read`.
66    pub async fn download_file_content(&self, file_id: &str) -> Result<bytes::Bytes> {
67        self.client
68            .request_bytes(Request {
69                method: Method::GET,
70                path: format!("/api/v1/files/{}/content", encode_path(file_id)),
71                query: NO_QUERY,
72                body: NO_BODY,
73                headers: Vec::new(),
74                idempotent: false,
75            })
76            .await
77    }
78
79    /// Get file metadata
80    ///
81    /// `GET /api/v1/files/{fileId}`
82    ///
83    /// Required scopes: `files:read`.
84    pub async fn get_file_metadata(&self, file_id: &str) -> Result<models::FileRecord> {
85        self.client
86            .request_json(Request {
87                method: Method::GET,
88                path: format!("/api/v1/files/{}", encode_path(file_id)),
89                query: NO_QUERY,
90                body: NO_BODY,
91                headers: Vec::new(),
92                idempotent: false,
93            })
94            .await
95    }
96
97    /// List files
98    ///
99    /// `GET /api/v1/files`
100    ///
101    /// Required scopes: `files:read`.
102    pub async fn list(&self, params: &ListFilesParams) -> Result<models::ListFilesResponse> {
103        self.client
104            .request_json(Request {
105                method: Method::GET,
106                path: "/api/v1/files".to_string(),
107                query: Some(params),
108                body: NO_BODY,
109                headers: Vec::new(),
110                idempotent: false,
111            })
112            .await
113    }
114
115    /// Stream every item returned by `listFiles`, following the `cursor` cursor until the server
116    /// reports no further pages.
117    pub fn list_all<'a>(&'a self, params: &'a ListFilesParams) -> impl Stream<Item = Result<models::FileEntry>> + 'a {
118        async_stream::try_stream! {
119            let mut guard = CursorGuard::new();
120            let mut cursor = params.cursor.clone();
121            loop {
122                let mut page_params = params.clone();
123                page_params.cursor = cursor.clone();
124                let page = self.list(&page_params).await?;
125                let items = page.items.unwrap_or_default();
126                let was_empty = items.is_empty();
127                for item in items {
128                    yield item;
129                }
130                match guard.advance(page.cursor, page.has_more, was_empty) {
131                    Some(next) => cursor = Some(next),
132                    None => break,
133                }
134            }
135        }
136    }
137
138    /// Upload a file for multimodal content
139    ///
140    /// Accepts multipart/form-data or base64 JSON. Files persist until explicit delete by default;
141    /// operators can opt into a retention policy via `config.retention.artifact_ttl_days`.
142    ///
143    /// `POST /api/v1/files`
144    ///
145    /// Required scopes: `files:write`.
146    pub async fn upload(&self, body: &models::UploadFileRequest) -> Result<models::UploadFileResponse> {
147        self.client
148            .request_json(Request {
149                method: Method::POST,
150                path: "/api/v1/files".to_string(),
151                query: NO_QUERY,
152                body: Some(body),
153                headers: Vec::new(),
154                idempotent: true,
155            })
156            .await
157    }
158}