Skip to main content

ras_types/domain/
action_result.rs

1use indexmap::IndexMap;
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug, Clone, Default, Serialize, Deserialize)]
5pub struct ActionResult {
6    pub extracted_content: Option<String>,
7    pub include_in_memory: bool,
8    pub error: Option<String>,
9    pub is_done: bool,
10    pub long_term_memory: Option<String>,
11    pub attachments: Vec<String>,
12    pub images: Vec<String>,
13    pub metadata: IndexMap<String, serde_json::Value>,
14}
15
16impl ActionResult {
17    #[must_use]
18    pub fn ok(content: impl Into<String>) -> Self {
19        Self {
20            extracted_content: Some(content.into()),
21            include_in_memory: true,
22            ..Self::default()
23        }
24    }
25
26    #[must_use]
27    pub fn err(message: impl Into<String>) -> Self {
28        Self {
29            error: Some(message.into()),
30            include_in_memory: true,
31            ..Self::default()
32        }
33    }
34
35    #[must_use]
36    pub fn done(content: impl Into<String>) -> Self {
37        Self {
38            extracted_content: Some(content.into()),
39            include_in_memory: true,
40            is_done: true,
41            ..Self::default()
42        }
43    }
44
45    #[must_use]
46    pub fn with_attachment(mut self, path: impl Into<String>) -> Self {
47        self.attachments.push(path.into());
48        self
49    }
50
51    #[must_use]
52    pub fn with_image(mut self, b64: impl Into<String>) -> Self {
53        self.images.push(b64.into());
54        self
55    }
56
57    #[must_use]
58    pub fn is_error(&self) -> bool {
59        self.error.is_some()
60    }
61}