Skip to main content

systemprompt_files/repository/file/
request.rs

1//! Typed insert parameters for file rows.
2//!
3//! Copyright (c) systemprompt.io — Business Source License 1.1.
4//! See <https://systemprompt.io> for licensing details.
5
6use systemprompt_identifiers::{ContextId, FileId, SessionId, TraceId, UserId};
7
8use crate::models::FileMetadata;
9
10#[derive(Debug, Clone)]
11pub struct InsertFileRequest {
12    pub id: FileId,
13    pub path: String,
14    pub public_url: String,
15    pub mime_type: String,
16    pub size_bytes: Option<i64>,
17    pub ai_content: bool,
18    pub metadata: FileMetadata,
19    pub user_id: Option<UserId>,
20    pub session_id: Option<SessionId>,
21    pub trace_id: Option<TraceId>,
22    pub context_id: Option<ContextId>,
23}
24
25impl InsertFileRequest {
26    pub fn new(
27        id: FileId,
28        path: impl Into<String>,
29        public_url: impl Into<String>,
30        mime_type: impl Into<String>,
31    ) -> Self {
32        Self {
33            id,
34            path: path.into(),
35            public_url: public_url.into(),
36            mime_type: mime_type.into(),
37            size_bytes: None,
38            ai_content: false,
39            metadata: FileMetadata::default(),
40            user_id: None,
41            session_id: None,
42            trace_id: None,
43            context_id: None,
44        }
45    }
46
47    pub const fn with_size(mut self, size: i64) -> Self {
48        self.size_bytes = Some(size);
49        self
50    }
51
52    pub const fn with_ai_content(mut self, ai_content: bool) -> Self {
53        self.ai_content = ai_content;
54        self
55    }
56
57    pub fn with_metadata(mut self, metadata: FileMetadata) -> Self {
58        self.metadata = metadata;
59        self
60    }
61
62    pub fn with_user_id(mut self, user_id: UserId) -> Self {
63        self.user_id = Some(user_id);
64        self
65    }
66
67    pub fn with_session_id(mut self, session_id: SessionId) -> Self {
68        self.session_id = Some(session_id);
69        self
70    }
71
72    pub fn with_trace_id(mut self, trace_id: TraceId) -> Self {
73        self.trace_id = Some(trace_id);
74        self
75    }
76
77    pub fn with_context_id(mut self, context_id: ContextId) -> Self {
78        self.context_id = Some(context_id);
79        self
80    }
81}