gemini_rust/files/
model.rs

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