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}
31
32/// Attached to a committed assistant `ChatMessage` — one per tool
33/// call that ran during that turn.
34#[derive(Debug, Clone, Serialize, Deserialize)]
35pub struct ActionDisplay {
36 /// Human-readable kind ("Read", "Bash", "Edit", "Web Search", …).
37 pub action_type: String,
38 /// Target string (file path, command, query, …).
39 pub target: String,
40 /// Success / error outcome.
41 pub result: ActionResult,
42 /// Type-specific display data.
43 #[serde(default)]
44 pub details: ActionDetails,
45 /// Wall-clock time in seconds, for long-running operations.
46 pub duration_seconds: Option<f64>,
47 /// Structured facts about the tool run. Optional for old saved
48 /// conversations and simple actions.
49 #[serde(default)]
50 pub metadata: Option<ToolRunMetadata>,
51}
52
53/// Per-action-type display payload. The chat widget matches on this
54/// to render code blocks, diffs, agent summaries, etc.
55#[derive(Debug, Clone, Default, Serialize, Deserialize)]
56pub enum ActionDetails {
57 /// No extra data — delete, mkdir, old history without richer
58 /// info.
59 #[default]
60 Simple,
61 /// Plain preview with optional line count (read, command output,
62 /// web search results).
63 Preview {
64 text: String,
65 line_count: Option<usize>,
66 },
67 /// Whole-file write — renders syntax-highlighted preview.
68 FileContent { line_count: usize, content: String },
69 /// Targeted edit — renders summary + diff.
70 Diff { summary: String, diff: String },
71}