Skip to main content

synaps_cli/runtime/
types.rs

1use serde_json::Value;
2use serde::Deserialize;
3
4/// Top-level stream event — grouped into concern-specific sub-enums.
5#[derive(Debug, Clone)]
6pub enum StreamEvent {
7    Llm(LlmEvent),
8    Session(SessionEvent),
9    Agent(AgentEvent),
10}
11
12#[derive(Debug, Clone)]
13pub enum LlmEvent {
14    Thinking(String),
15    Text(String),
16    /// A tool-use block has begun streaming. `tool_id` is the call id the
17    /// model will reference in its eventual `tool_use` content block —
18    /// chat UIs use it to route subsequent `ToolUseDelta` chunks and the
19    /// final `ToolUse` finalize event to the correct on-screen block when
20    /// multiple tools run in parallel.
21    ToolUseStart {
22        tool_name: String,
23        tool_id: String,
24    },
25    /// Streaming chunk of a tool's input JSON. `tool_id` matches the
26    /// `ToolUseStart` it belongs to; with parallel tool calls the model
27    /// may interleave deltas from different tools.
28    ToolUseDelta {
29        tool_id: String,
30        delta: String,
31    },
32    ToolUse {
33        tool_name: String,
34        tool_id: String,
35        input: Value,
36    },
37    ToolResult {
38        tool_id: String,
39        result: String,
40    },
41    ToolResultDelta {
42        tool_id: String,
43        delta: String,
44    },
45}
46
47#[derive(Debug, Clone)]
48pub enum SessionEvent {
49    MessageHistory(Vec<Value>),
50    Usage {
51        input_tokens: u64,
52        output_tokens: u64,
53        cache_read_input_tokens: u64,
54        cache_creation_input_tokens: u64,
55        model: Option<String>,
56    },
57    Done,
58    Error(String),
59    /// Transient status line (e.g. retry notices) — display-only, never
60    /// persisted into message history or sent back to the API.
61    Notice(String),
62}
63
64#[derive(Debug, Clone)]
65pub enum AgentEvent {
66    SubagentStart {
67        subagent_id: u64,
68        agent_name: String,
69        task_preview: String,
70    },
71    SubagentUpdate {
72        subagent_id: u64,
73        agent_name: String,
74        status: String,
75    },
76    SubagentDone {
77        subagent_id: u64,
78        agent_name: String,
79        result_preview: String,
80        duration_secs: f64,
81    },
82    SteeringDelivered {
83        message: String,
84    },
85}
86
87/// Shared mutable auth state. Lives behind `Arc<RwLock<_>>` so the spawned
88/// streaming task and the parent Runtime always see the same (freshest) token.
89#[derive(Debug, Clone)]
90pub(super) struct AuthState {
91    pub(super) auth_token: String,
92    pub(super) auth_type: String,
93    pub(super) refresh_token: Option<String>,
94    pub(super) token_expires: Option<u64>,
95}
96
97#[derive(Debug, Deserialize)]
98pub(super) struct PiAuth {
99    pub(super) anthropic: AnthropicAuth,
100}
101
102#[allow(dead_code)]
103#[derive(Debug, Deserialize)]
104pub(super) struct AnthropicAuth {
105    #[serde(rename = "type")]
106    pub(super) auth_type: String,
107    pub(super) refresh: Option<String>,
108    pub(super) access: Option<String>,
109    pub(super) expires: Option<u64>,
110    pub(super) key: Option<String>,
111}