use super::*;
impl SessionRegistry {
pub fn record_tool_started(
&self,
id: &str,
tool: &str,
call_id: &str,
args: &str,
) -> Result<(), RpcError> {
self.ensure_exists(id)?;
self.record(
id,
Event::ToolStarted {
session_id: id.to_string(),
tool: tool.to_string(),
call_id: call_id.to_string(),
args_preview: crate::events::preview(args, 500),
},
);
Ok(())
}
pub fn record_tool_finished(
&self,
id: &str,
tool: &str,
call_id: &str,
success: bool,
result: &str,
) -> Result<(), RpcError> {
self.ensure_exists(id)?;
self.record(
id,
Event::ToolFinished {
session_id: id.to_string(),
tool: tool.to_string(),
call_id: call_id.to_string(),
success,
result_preview: crate::events::preview(result, 500),
},
);
Ok(())
}
pub fn record_tool_error(
&self,
id: &str,
tool: &str,
call_id: &str,
error: &str,
) -> Result<(), RpcError> {
self.ensure_exists(id)?;
self.record(
id,
Event::ToolError {
session_id: id.to_string(),
tool: tool.to_string(),
call_id: call_id.to_string(),
error: error.to_string(),
},
);
Ok(())
}
pub fn record_log(&self, id: &str, level: &str, message: &str) -> Result<(), RpcError> {
self.ensure_exists(id)?;
self.record(
id,
Event::Log {
session_id: id.to_string(),
level: level.to_string(),
message: message.to_string(),
},
);
Ok(())
}
pub fn record_progress(
&self,
id: &str,
message: &str,
percent: Option<f32>,
) -> Result<(), RpcError> {
self.ensure_exists(id)?;
self.record(
id,
Event::Progress {
session_id: id.to_string(),
message: message.to_string(),
percent,
},
);
Ok(())
}
pub fn record_message(&self, id: &str, text: &str) -> Result<(), RpcError> {
self.ensure_exists(id)?;
self.record(
id,
Event::Message {
session_id: id.to_string(),
text: text.to_string(),
},
);
Ok(())
}
fn ensure_exists(&self, id: &str) -> Result<(), RpcError> {
if self.lock().contains_key(id) {
Ok(())
} else {
Err(RpcError::session_not_found(id))
}
}
}