Delete a session
(&mut self, id: &str)
| 1072 | |
| 1073 | /// Delete a session |
| 1074 | pub fn delete(&mut self, id: &str) -> Option<Session> { |
| 1075 | let children: Vec<String> = self.children(id).iter().map(|s| s.id.clone()).collect(); |
| 1076 | for child_id in children { |
| 1077 | self.delete(&child_id); |
| 1078 | } |
| 1079 | |
| 1080 | let session = self.sessions.remove(id)?; |
| 1081 | self.events.push(SessionEvent::Deleted { |
| 1082 | info: session.clone(), |
| 1083 | }); |
| 1084 | |
| 1085 | // Publish to Bus |
| 1086 | self.publish_session_event(&SESSION_DELETED_EVENT, &session); |
| 1087 | |
| 1088 | // Plugin hook: session.end — notify plugins of session deletion |
| 1089 | if let Ok(handle) = tokio::runtime::Handle::try_current() { |
| 1090 | let session_id = session.id.clone(); |
| 1091 | handle.spawn(async move { |
| 1092 | opencode_plugin::trigger( |
| 1093 | HookContext::new(HookEvent::SessionEnd).with_session(&session_id), |
| 1094 | ) |
| 1095 | .await; |
| 1096 | }); |
| 1097 | } |
| 1098 | |
| 1099 | Some(session) |
| 1100 | } |
| 1101 | |
| 1102 | /// Update a session |
| 1103 | pub fn update(&mut self, session: Session) { |