macp_runtime/extensions/
provider.rs1use std::collections::HashMap;
2
3#[derive(Debug)]
4pub enum ExtensionError {
5 Internal(String),
6}
7
8impl std::fmt::Display for ExtensionError {
9 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
10 match self {
11 ExtensionError::Internal(msg) => write!(f, "extension error: {msg}"),
12 }
13 }
14}
15
16impl std::error::Error for ExtensionError {}
17
18pub enum SessionOutcome {
19 Resolved,
20 Expired,
21}
22
23#[async_trait::async_trait]
29pub trait SessionExtensionProvider: Send + Sync {
30 fn key(&self) -> &str;
31
32 async fn on_session_start(
33 &self,
34 session_id: &str,
35 extensions: &HashMap<String, Vec<u8>>,
36 ) -> Result<(), ExtensionError>;
37
38 async fn on_session_terminal(
39 &self,
40 session_id: &str,
41 outcome: SessionOutcome,
42 ) -> Result<(), ExtensionError>;
43}