Skip to main content

mermaid_cli/domain/
action.rs

1//! Value types describing one tool action's display.
2//!
3//! These ride alongside `ChatMessage::actions` — the chat renderer
4//! paints one per tool call attached to an assistant message. Pure
5//! data; no runtime, no I/O.
6//!
7//! New tool executions land here via `domain::transition::
8//! action_display_for`, which reads the `PendingToolCall` and
9//! `ToolOutcome` produced by the reducer. The chat widget then
10//! paints the `ActionDetails` variant's specific layout.
11
12use serde::{Deserialize, Serialize};
13
14use super::runtime::ToolRunMetadata;
15
16/// Result shape carried on an `ActionDisplay`. Discriminates the
17/// success/error path; the chat widget colors them differently and
18/// `Success` may carry image data for multimodal tools.
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[must_use]
21pub enum ActionResult {
22    Success {
23        output: String,
24        #[serde(default)]
25        images: Option<Vec<String>>,
26    },
27    Error {
28        error: String,
29    },
30    /// Call is still in flight. Only ever synthesized by the render layer
31    /// for the live transcript view (the chat widget blinks the header dot);
32    /// never committed to the message log, so it never reaches disk.
33    Running,
34}
35
36/// Attached to a committed assistant `ChatMessage` — one per tool
37/// call that ran during that turn.
38#[derive(Debug, Clone, Serialize, Deserialize)]
39pub struct ActionDisplay {
40    /// Human-readable kind ("Read", "Bash", "Update", "Web Search", …).
41    pub action_type: String,
42    /// Target string (file path, command, query, …).
43    pub target: String,
44    /// Success / error outcome.
45    pub result: ActionResult,
46    /// Type-specific display data.
47    #[serde(default)]
48    pub details: ActionDetails,
49    /// Wall-clock time in seconds, for long-running operations.
50    pub duration_seconds: Option<f64>,
51    /// Structured facts about the tool run. Optional for old saved
52    /// conversations and simple actions.
53    #[serde(default)]
54    pub metadata: Option<ToolRunMetadata>,
55}
56
57/// Per-action-type display payload. The chat widget matches on this
58/// to render code blocks, diffs, agent summaries, etc.
59#[derive(Debug, Clone, Default, Serialize, Deserialize)]
60pub enum ActionDetails {
61    /// No extra data — delete, mkdir, old history without richer
62    /// info.
63    #[default]
64    Simple,
65    /// Plain preview with optional line count (read, command output,
66    /// web search results).
67    Preview {
68        text: String,
69        line_count: Option<usize>,
70    },
71    /// Whole-file write — renders syntax-highlighted preview.
72    FileContent { line_count: usize, content: String },
73    /// Targeted edit — renders summary + diff.
74    Diff { summary: String, diff: String },
75}