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}
60
61#[derive(Debug, Clone)]
62pub enum AgentEvent {
63    SubagentStart {
64        subagent_id: u64,
65        agent_name: String,
66        task_preview: String,
67    },
68    SubagentUpdate {
69        subagent_id: u64,
70        agent_name: String,
71        status: String,
72    },
73    SubagentDone {
74        subagent_id: u64,
75        agent_name: String,
76        result_preview: String,
77        duration_secs: f64,
78    },
79    SteeringDelivered {
80        message: String,
81    },
82}
83
84/// Shared mutable auth state. Lives behind `Arc<RwLock<_>>` so the spawned
85/// streaming task and the parent Runtime always see the same (freshest) token.
86#[derive(Debug, Clone)]
87pub(super) struct AuthState {
88    pub(super) auth_token: String,
89    pub(super) auth_type: String,
90    pub(super) refresh_token: Option<String>,
91    pub(super) token_expires: Option<u64>,
92}
93
94#[derive(Debug, Deserialize)]
95pub(super) struct PiAuth {
96    pub(super) anthropic: AnthropicAuth,
97}
98
99#[allow(dead_code)]
100#[derive(Debug, Deserialize)]
101pub(super) struct AnthropicAuth {
102    #[serde(rename = "type")]
103    pub(super) auth_type: String,
104    pub(super) refresh: Option<String>,
105    pub(super) access: Option<String>,
106    pub(super) expires: Option<u64>,
107    pub(super) key: Option<String>,
108}