objectiveai_sdk/filesystem/logs/log_file.rs
1/// A structured log file entry produced by streaming chunks.
2///
3/// Instead of opaque path strings, each file carries semantic fields
4/// (route, id, optional indices) from which the on-disk path is derived.
5pub struct LogFile {
6 /// Directory route, e.g. `"agents/completions/messages/image"`.
7 pub route: String,
8 /// Chunk ID, e.g. `"acc-1"`.
9 pub id: String,
10 /// Message index within the completion (if applicable).
11 pub message_index: Option<u64>,
12 /// Media part index within the message (if applicable).
13 pub media_index: Option<u64>,
14 /// File extension without dot, e.g. `"json"`, `"png"`.
15 pub extension: String,
16 /// File content bytes.
17 pub content: Vec<u8>,
18}
19
20impl LogFile {
21 /// The filename stem without extension, e.g. `"acc-1"`, `"acc-1_0"`, `"acc-1_0_2"`.
22 pub fn stem(&self) -> String {
23 match (self.message_index, self.media_index) {
24 (None, _) => self.id.clone(),
25 (Some(mi), None) => format!("{}_{mi}", self.id),
26 (Some(mi), Some(mdi)) => format!("{}_{mi}_{mdi}", self.id),
27 }
28 }
29
30 /// The filename with extension, e.g. `"acc-1.json"`, `"acc-1_0_2.png"`.
31 pub fn filename(&self) -> String {
32 format!("{}.{}", self.stem(), self.extension)
33 }
34
35 /// The full relative path, e.g. `"agents/completions/messages/image/acc-1_0_2.png"`.
36 pub fn path(&self) -> String {
37 format!("{}/{}", self.route, self.filename())
38 }
39}