Skip to main content

walrus_core/protocol/message/
client.rs

1//! Messages sent by the client to the gateway.
2
3use compact_str::CompactString;
4use serde::{Deserialize, Serialize};
5
6/// Hub package action.
7#[derive(Debug, Clone, Serialize, Deserialize)]
8#[serde(rename_all = "snake_case")]
9pub enum HubAction {
10    /// Install a hub package.
11    Install,
12    /// Uninstall a hub package.
13    Uninstall,
14}
15
16/// Send a message to an agent and receive a complete response.
17#[derive(Debug, Clone, Serialize, Deserialize)]
18pub struct SendRequest {
19    /// Target agent identifier.
20    pub agent: CompactString,
21    /// Message content.
22    pub content: String,
23    /// Session to reuse. `None` creates a new session.
24    #[serde(default, skip_serializing_if = "Option::is_none")]
25    pub session: Option<u64>,
26    /// Sender identity (e.g. `"tg:12345"`, `"dc:67890"`). `None` = local.
27    #[serde(default, skip_serializing_if = "Option::is_none")]
28    pub sender: Option<CompactString>,
29}
30
31/// Send a message to an agent and receive a streamed response.
32#[derive(Debug, Clone, Serialize, Deserialize)]
33pub struct StreamRequest {
34    /// Target agent identifier.
35    pub agent: CompactString,
36    /// Message content.
37    pub content: String,
38    /// Session to reuse. `None` creates a new session.
39    #[serde(default, skip_serializing_if = "Option::is_none")]
40    pub session: Option<u64>,
41    /// Sender identity (e.g. `"tg:12345"`, `"dc:67890"`). `None` = local.
42    #[serde(default, skip_serializing_if = "Option::is_none")]
43    pub sender: Option<CompactString>,
44}
45
46/// Request download of a model's files with progress reporting.
47#[derive(Debug, Clone, Serialize, Deserialize)]
48pub struct DownloadRequest {
49    /// HuggingFace model ID.
50    pub model: CompactString,
51}
52
53/// Install or uninstall a hub package.
54#[derive(Debug, Clone, Serialize, Deserialize)]
55pub struct HubRequest {
56    /// Package identifier in `scope/name` format.
57    pub package: CompactString,
58    /// Action to perform.
59    pub action: HubAction,
60}
61
62/// Messages sent by the client to the gateway.
63#[derive(Debug, Clone, Serialize, Deserialize)]
64#[serde(tag = "type", rename_all = "snake_case")]
65pub enum ClientMessage {
66    /// Send a message to an agent and receive a complete response.
67    Send {
68        /// Target agent identifier.
69        agent: CompactString,
70        /// Message content.
71        content: String,
72        /// Session to reuse. `None` creates a new session.
73        #[serde(default, skip_serializing_if = "Option::is_none")]
74        session: Option<u64>,
75        /// Sender identity. `None` = local.
76        #[serde(default, skip_serializing_if = "Option::is_none")]
77        sender: Option<CompactString>,
78    },
79    /// Send a message to an agent and receive a streamed response.
80    Stream {
81        /// Target agent identifier.
82        agent: CompactString,
83        /// Message content.
84        content: String,
85        /// Session to reuse. `None` creates a new session.
86        #[serde(default, skip_serializing_if = "Option::is_none")]
87        session: Option<u64>,
88        /// Sender identity. `None` = local.
89        #[serde(default, skip_serializing_if = "Option::is_none")]
90        sender: Option<CompactString>,
91    },
92    /// Request download of a model's files with progress reporting.
93    Download {
94        /// HuggingFace model ID (e.g. "microsoft/Phi-3.5-mini-instruct").
95        model: CompactString,
96    },
97    /// Ping the server (keepalive).
98    Ping,
99    /// Install or uninstall a hub package.
100    Hub {
101        /// Package identifier in `scope/name` format.
102        package: CompactString,
103        /// Action to perform.
104        action: HubAction,
105    },
106    /// List active sessions.
107    Sessions,
108    /// Kill (close) a session.
109    Kill {
110        /// Session ID to close.
111        session: u64,
112    },
113    /// List tasks in the task registry.
114    Tasks,
115    /// Kill (cancel) a task.
116    KillTask {
117        /// Task ID to cancel.
118        task_id: u64,
119    },
120    /// Approve a blocked task's inbox item.
121    Approve {
122        /// Task ID to approve.
123        task_id: u64,
124        /// Response to send to the blocked tool call.
125        response: String,
126    },
127}
128
129impl From<SendRequest> for ClientMessage {
130    fn from(r: SendRequest) -> Self {
131        Self::Send {
132            agent: r.agent,
133            content: r.content,
134            session: r.session,
135            sender: r.sender,
136        }
137    }
138}
139
140impl From<StreamRequest> for ClientMessage {
141    fn from(r: StreamRequest) -> Self {
142        Self::Stream {
143            agent: r.agent,
144            content: r.content,
145            session: r.session,
146            sender: r.sender,
147        }
148    }
149}
150
151impl From<DownloadRequest> for ClientMessage {
152    fn from(r: DownloadRequest) -> Self {
153        Self::Download { model: r.model }
154    }
155}
156
157impl From<HubRequest> for ClientMessage {
158    fn from(r: HubRequest) -> Self {
159        Self::Hub {
160            package: r.package,
161            action: r.action,
162        }
163    }
164}