Skip to main content

merry_runtime/
tool_catalog.rs

1use crate::{FileSessionStore, RuntimeError, session::SessionState};
2use merry_core::SessionId;
3
4/// A validated persisted session loaded once before runtime construction.
5///
6/// The runtime owns the complete session state. Surface adapters may load and
7/// validate a session before transferring this handle into
8/// [`crate::RuntimeBuilder`] without loading the session a second time.
9pub struct LoadedSession {
10    state: SessionState,
11}
12
13impl LoadedSession {
14    /// Loads and validates one session from the supplied store.
15    pub async fn load(
16        store: &FileSessionStore,
17        session_id: &SessionId,
18    ) -> Result<Self, RuntimeError> {
19        Ok(Self {
20            state: SessionState::load_from(store, session_id).await?,
21        })
22    }
23
24    pub(crate) fn into_state(self) -> SessionState {
25        self.state
26    }
27
28    pub(crate) fn transcript_items(&self) -> Vec<crate::SessionTranscriptItem> {
29        self.state
30            .full_transcript_snapshot()
31            .into_iter()
32            .map(crate::SessionTranscriptItem::from)
33            .collect()
34    }
35}