| 95 | } |
| 96 | |
| 97 | fn derive_context(path: &Path) -> CodebuffContext { |
| 98 | let chat_id = path |
| 99 | .parent() |
| 100 | .and_then(Path::file_name) |
| 101 | .and_then(|name| name.to_str()) |
| 102 | .filter(|name| !name.is_empty()) |
| 103 | .unwrap_or("unknown") |
| 104 | .to_string(); |
| 105 | let chats_dir = path.parent().and_then(Path::parent); |
| 106 | let project_dir = chats_dir.and_then(Path::parent); |
| 107 | let project = project_dir |
| 108 | .and_then(Path::file_name) |
| 109 | .and_then(|name| name.to_str()) |
| 110 | .filter(|name| !name.is_empty()) |
| 111 | .unwrap_or("unknown") |
| 112 | .to_string(); |
| 113 | let channel = project_dir |
| 114 | .and_then(Path::parent) |
| 115 | .and_then(Path::parent) |
| 116 | .and_then(Path::file_name) |
| 117 | .and_then(|name| name.to_str()) |
| 118 | .filter(|name| !name.is_empty()) |
| 119 | .unwrap_or("manicode") |
| 120 | .to_string(); |
| 121 | CodebuffContext { |
| 122 | session_id: format!("{channel}/{project}/{chat_id}"), |
| 123 | chat_id, |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | fn is_assistant_message(message: &serde_json::Map<String, Value>) -> bool { |
| 128 | matches!( |