Skip to main content

adk_anthropic/types/
file_source.rs

1use serde::{Deserialize, Serialize};
2
3/// A file source referencing a server-side file by ID.
4///
5/// Used in image and document blocks to reference files uploaded via the Files API.
6#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
7pub struct FileSource {
8    /// The ID of the uploaded file.
9    pub file_id: String,
10}
11
12impl FileSource {
13    /// Create a new `FileSource` with the given file ID.
14    pub fn new(file_id: impl Into<String>) -> Self {
15        Self { file_id: file_id.into() }
16    }
17}
18
19#[cfg(test)]
20mod tests {
21    use super::*;
22    use serde_json::json;
23
24    #[test]
25    fn serialization() {
26        let source = FileSource::new("file-abc123");
27        let json = serde_json::to_value(&source).unwrap();
28        assert_eq!(json, json!({"file_id": "file-abc123"}));
29    }
30
31    #[test]
32    fn deserialization() {
33        let json = json!({"file_id": "file-xyz789"});
34        let source: FileSource = serde_json::from_value(json).unwrap();
35        assert_eq!(source.file_id, "file-xyz789");
36    }
37}