Skip to main content

merry_runtime/
session_projection.rs

1use crate::session::TranscriptItemSnapshot;
2use merry_core::{ImageSummary, PendingToolCall, ToolCallId, ToolCallResult, ToolOutput};
3
4/// Read-only public projection of persisted session transcript items.
5///
6/// This is intended for UI/SDK resume views. It is not provider wire history and
7/// does not mutate runtime state.
8#[derive(Debug, Clone, PartialEq, Eq)]
9pub enum SessionTranscriptItem {
10    UserMessage {
11        text: String,
12        images: Vec<ImageSummary>,
13    },
14    AssistantText {
15        text: String,
16    },
17    ToolCall {
18        call: PendingToolCall,
19    },
20    ToolResult {
21        call_id: ToolCallId,
22        result: ToolCallResult,
23        output: Option<ToolOutput>,
24    },
25}
26
27impl From<TranscriptItemSnapshot> for SessionTranscriptItem {
28    fn from(value: TranscriptItemSnapshot) -> Self {
29        match value {
30            TranscriptItemSnapshot::UserMessage { text, images, .. } => Self::UserMessage {
31                text,
32                images: images
33                    .into_iter()
34                    .map(|image| ImageSummary::new(image.label(), image.width(), image.height()))
35                    .collect(),
36            },
37            TranscriptItemSnapshot::AssistantText { text } => Self::AssistantText { text },
38            TranscriptItemSnapshot::ToolCall { call } => Self::ToolCall { call },
39            TranscriptItemSnapshot::ToolResult {
40                call_id,
41                result,
42                output,
43                ..
44            } => Self::ToolResult {
45                call_id,
46                result,
47                output: Some(output),
48            },
49        }
50    }
51}