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}
24
25/// Send a message to an agent and receive a streamed response.
26#[derive(Debug, Clone, Serialize, Deserialize)]
27pub struct StreamRequest {
28    /// Target agent identifier.
29    pub agent: CompactString,
30    /// Message content.
31    pub content: String,
32}
33
34/// Request download of a model's files with progress reporting.
35#[derive(Debug, Clone, Serialize, Deserialize)]
36pub struct DownloadRequest {
37    /// HuggingFace model ID.
38    pub model: CompactString,
39}
40
41/// Install or uninstall a hub package.
42#[derive(Debug, Clone, Serialize, Deserialize)]
43pub struct HubRequest {
44    /// Package identifier in `scope/name` format.
45    pub package: CompactString,
46    /// Action to perform.
47    pub action: HubAction,
48}
49
50/// Messages sent by the client to the gateway.
51#[derive(Debug, Clone, Serialize, Deserialize)]
52#[serde(tag = "type", rename_all = "snake_case")]
53pub enum ClientMessage {
54    /// Send a message to an agent and receive a complete response.
55    Send {
56        /// Target agent identifier.
57        agent: CompactString,
58        /// Message content.
59        content: String,
60    },
61    /// Send a message to an agent and receive a streamed response.
62    Stream {
63        /// Target agent identifier.
64        agent: CompactString,
65        /// Message content.
66        content: String,
67    },
68    /// Request download of a model's files with progress reporting.
69    Download {
70        /// HuggingFace model ID (e.g. "microsoft/Phi-3.5-mini-instruct").
71        model: CompactString,
72    },
73    /// Ping the server (keepalive).
74    Ping,
75    /// Install or uninstall a hub package.
76    Hub {
77        /// Package identifier in `scope/name` format.
78        package: CompactString,
79        /// Action to perform.
80        action: HubAction,
81    },
82}
83
84impl From<SendRequest> for ClientMessage {
85    fn from(r: SendRequest) -> Self {
86        Self::Send {
87            agent: r.agent,
88            content: r.content,
89        }
90    }
91}
92
93impl From<StreamRequest> for ClientMessage {
94    fn from(r: StreamRequest) -> Self {
95        Self::Stream {
96            agent: r.agent,
97            content: r.content,
98        }
99    }
100}
101
102impl From<DownloadRequest> for ClientMessage {
103    fn from(r: DownloadRequest) -> Self {
104        Self::Download { model: r.model }
105    }
106}
107
108impl From<HubRequest> for ClientMessage {
109    fn from(r: HubRequest) -> Self {
110        Self::Hub {
111            package: r.package,
112            action: r.action,
113        }
114    }
115}