Skip to main content

do_memory_mcp/server/audit/
episode_ops.rs

1//! Audit logging operations - Episode operations
2//!
3//! This module provides logging methods for episode-related operations.
4
5use super::core::AuditLogger;
6use super::types::AuditLogLevel;
7use serde_json::json;
8
9impl AuditLogger {
10    /// Log episode creation
11    pub async fn log_episode_creation(
12        &self,
13        client_id: &str,
14        episode_id: &str,
15        task_description: &str,
16        success: bool,
17        error: Option<&str>,
18    ) {
19        let metadata = json!({
20            "episode_id": episode_id,
21            "task_description": task_description,
22            "error": error
23        });
24
25        self.log_event(
26            AuditLogLevel::Info,
27            client_id,
28            "create_episode",
29            if success { "success" } else { "failure" },
30            metadata,
31        )
32        .await;
33    }
34
35    /// Log episode modification
36    pub async fn log_episode_modification(
37        &self,
38        client_id: &str,
39        episode_id: &str,
40        operation: &str,
41        success: bool,
42        error: Option<&str>,
43    ) {
44        let metadata = json!({
45            "episode_id": episode_id,
46            "modification_type": operation,
47            "error": error
48        });
49
50        self.log_event(
51            AuditLogLevel::Info,
52            client_id,
53            "modify_episode",
54            if success { "success" } else { "failure" },
55            metadata,
56        )
57        .await;
58    }
59
60    /// Log episode deletion
61    pub async fn log_episode_deletion(
62        &self,
63        client_id: &str,
64        episode_id: &str,
65        success: bool,
66        error: Option<&str>,
67    ) {
68        let metadata = json!({
69            "episode_id": episode_id,
70            "error": error
71        });
72
73        self.log_event(
74            AuditLogLevel::Warn,
75            client_id,
76            "delete_episode",
77            if success { "success" } else { "failure" },
78            metadata,
79        )
80        .await;
81    }
82
83    /// Log episode step addition
84    pub async fn log_episode_step(
85        &self,
86        client_id: &str,
87        episode_id: &str,
88        step_number: u32,
89        tool: &str,
90        success: bool,
91    ) {
92        let metadata = json!({
93            "episode_id": episode_id,
94            "step_number": step_number,
95            "tool": tool
96        });
97
98        self.log_event(
99            AuditLogLevel::Debug,
100            client_id,
101            "add_episode_step",
102            if success { "success" } else { "failure" },
103            metadata,
104        )
105        .await;
106    }
107
108    /// Log episode completion
109    pub async fn log_episode_completion(
110        &self,
111        client_id: &str,
112        episode_id: &str,
113        outcome: &str,
114        success: bool,
115    ) {
116        let metadata = json!({
117            "episode_id": episode_id,
118            "outcome": outcome
119        });
120
121        self.log_event(
122            AuditLogLevel::Info,
123            client_id,
124            "complete_episode",
125            if success { "success" } else { "failure" },
126            metadata,
127        )
128        .await;
129    }
130}