gemini_rust/files/
model.rs

1use mime::Mime;
2use reqwest::Url;
3use serde::{Deserialize, Serialize};
4use time::OffsetDateTime;
5
6use crate::common::serde::*;
7
8/// Represents a file resource in the Gemini API.
9#[derive(Debug, Default, Clone, Serialize, Deserialize)]
10#[serde(rename_all = "camelCase")]
11pub struct File {
12    /// The unique identifier for the file.
13    pub name: String,
14    /// The URI of the file.
15    #[serde(skip_serializing_if = "Option::is_none")]
16    pub uri: Option<Url>,
17    /// The download URI of the file.
18    #[serde(skip_serializing_if = "Option::is_none")]
19    pub download_uri: Option<Url>,
20    /// The display name of the file.
21    #[serde(skip_serializing_if = "Option::is_none")]
22    pub display_name: Option<String>,
23    /// The MIME type of the file.
24    #[serde(
25        with = "crate::common::serde::mime_as_string::optional",
26        skip_serializing_if = "Option::is_none"
27    )]
28    pub mime_type: Option<Mime>,
29    /// The size of the file in bytes.
30    #[serde(default, with = "i64_as_string::optional")]
31    #[serde(skip_serializing_if = "Option::is_none")]
32    pub size_bytes: Option<i64>,
33    /// The creation time of the file.
34    #[serde(skip_serializing_if = "Option::is_none")]
35    #[serde(default, with = "time::serde::rfc3339::option")]
36    pub create_time: Option<OffsetDateTime>,
37    /// The expiration time of the file.
38    #[serde(skip_serializing_if = "Option::is_none")]
39    #[serde(default, with = "time::serde::rfc3339::option")]
40    pub expiration_time: Option<OffsetDateTime>,
41    /// The last update time of the file.
42    #[serde(skip_serializing_if = "Option::is_none")]
43    #[serde(default, with = "time::serde::rfc3339::option")]
44    pub update_time: Option<OffsetDateTime>,
45    /// The SHA-256 hash of the file.
46    #[serde(skip_serializing_if = "Option::is_none")]
47    pub sha256_hash: Option<String>,
48    /// The current state of the file.
49    #[serde(skip_serializing_if = "Option::is_none")]
50    pub state: Option<FileState>,
51}
52
53/// The state of a file.
54#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
55#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
56pub enum FileState {
57    /// File state is unspecified
58    StateUnspecified,
59    /// File is being processed
60    Processing,
61    /// File is active and ready for use
62    Active,
63    /// File processing failed
64    Failed,
65    /// File has been deleted
66    Deleted,
67}
68
69/// Response from the Gemini API for listing files.
70#[derive(Debug, serde::Deserialize)]
71#[serde(rename_all = "camelCase")]
72pub struct ListFilesResponse {
73    /// A list of files.
74    #[serde(default)]
75    pub files: Vec<File>,
76    /// A token to retrieve the next page of results.
77    pub next_page_token: Option<String>,
78}