pub struct FileAttachment {
pub file_id: String,
pub filename: String,
pub size: u64,
pub mime_type: Option<String>,
pub channel: String,
pub message_id: Option<String>,
pub uploaded_by: Option<String>,
pub stored_at: DateTime<Utc>,
pub ref_count: usize,
}Expand description
Unified file attachment representation
This struct wraps a FileHandle from agent-diva-files and adds
channel-specific metadata for tracking which channel and message
the file was associated with.
Fields§
§file_id: StringContent-addressed file ID (SHA256 hash)
filename: StringOriginal filename as uploaded
size: u64File size in bytes
mime_type: Option<String>MIME type if known
channel: StringSource channel (e.g., “telegram”, “discord”, “slack”)
message_id: Option<String>Associated message ID from the channel
uploaded_by: Option<String>User who uploaded the file
stored_at: DateTime<Utc>When the file was stored
ref_count: usizeReference count (number of channel associations)
Implementations§
Source§impl FileAttachment
impl FileAttachment
Sourcepub fn from_handle(
handle: FileHandle,
channel: &str,
message_id: Option<&str>,
) -> Self
pub fn from_handle( handle: FileHandle, channel: &str, message_id: Option<&str>, ) -> Self
Create a FileAttachment from a FileHandle and channel info
§Arguments
handle- The FileHandle from agent-diva-fileschannel- The source channel identifiermessage_id- Optional message ID from the channel
§Example
use agent_diva_core::attachment::FileAttachment;
use agent_diva_files::{FileManager, FileConfig};
use agent_diva_files::handle::FileMetadata;
use std::path::PathBuf;
let config = FileConfig::with_path(PathBuf::from("./data"));
let manager = FileManager::new(config).await?;
let metadata = FileMetadata {
name: "document.pdf".to_string(),
size: 1024,
mime_type: Some("application/pdf".to_string()),
source: Some("telegram".to_string()),
created_at: chrono::Utc::now(),
last_accessed_at: None,
preview: None,
};
let handle = manager.store(b"dummy content", metadata).await?;
let attachment = FileAttachment::from_handle(handle, "telegram", Some("123456"));Sourcepub fn from_metadata(
file_id: &str,
metadata: &FileMetadata,
channel: &str,
message_id: Option<&str>,
ref_count: usize,
) -> Self
pub fn from_metadata( file_id: &str, metadata: &FileMetadata, channel: &str, message_id: Option<&str>, ref_count: usize, ) -> Self
Create a FileAttachment from stored metadata
This is useful when reconstructing an attachment from the database without needing the full FileHandle.
Sourcepub fn display(&self) -> String
pub fn display(&self) -> String
Get a display string for the attachment
§Example
use agent_diva_core::attachment::FileAttachment;
use agent_diva_files::{FileManager, FileConfig};
use agent_diva_files::handle::FileMetadata;
use std::path::PathBuf;
let config = FileConfig::with_path(PathBuf::from("./data"));
let manager = FileManager::new(config).await?;
let metadata = FileMetadata {
name: "document.pdf".to_string(),
size: 1024 * 1024, // 1 MB
mime_type: Some("application/pdf".to_string()),
source: Some("telegram".to_string()),
created_at: chrono::Utc::now(),
last_accessed_at: None,
preview: None,
};
let handle = manager.store(b"dummy content", metadata).await?;
let attachment = FileAttachment::from_handle(handle, "telegram", Some("msg_123"));
let display = attachment.display();
// "document.pdf (1.0 MB) from telegram"Sourcepub fn is_document(&self) -> bool
pub fn is_document(&self) -> bool
Check if this attachment is a document
Trait Implementations§
Source§impl Clone for FileAttachment
impl Clone for FileAttachment
Source§fn clone(&self) -> FileAttachment
fn clone(&self) -> FileAttachment
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for FileAttachment
impl Debug for FileAttachment
Source§impl<'de> Deserialize<'de> for FileAttachment
impl<'de> Deserialize<'de> for FileAttachment
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Display for FileAttachment
impl Display for FileAttachment
Auto Trait Implementations§
impl Freeze for FileAttachment
impl RefUnwindSafe for FileAttachment
impl Send for FileAttachment
impl Sync for FileAttachment
impl Unpin for FileAttachment
impl UnsafeUnpin for FileAttachment
impl UnwindSafe for FileAttachment
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more