aimo_core/
transport.rs

1use std::collections::HashMap;
2
3use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Serialize, Deserialize)]
6pub enum MessagePayload {
7    Request(Request),
8    Response(Response),
9    // Heartbeat(HeartbeatPayload),
10}
11
12#[derive(Debug, Clone, Serialize, Deserialize)]
13pub struct Request {
14    pub sender_id: String, // client id / public key
15    pub request_id: String,
16    pub service_id: String,
17    pub endpoint: Option<String>,
18    pub request_type: String, // Resource type: "completion_model", "embedding_model", etc.
19    pub method: String,       // HTTP method: "GET", "POST", "PUT", "DELETE", etc.
20    pub payload: String,
21    pub headers: HashMap<String, String>, // Only essential headers
22    pub payload_encrypted: bool,
23    pub signature: Option<String>,
24}
25
26#[derive(Debug, Clone, Serialize, Deserialize)]
27pub struct Response {
28    pub request_id: String,
29    pub status_code: u16,
30    pub content_type: String,
31    pub payload: String,
32    pub headers: HashMap<String, String>, // Only essential headers
33    pub is_stream_chunk: bool,
34    pub stream_done: bool,
35}
36
37// /// Headers that should be included in requests to reduce message size
38// pub const ESSENTIAL_REQUEST_HEADERS: &[&str] = &[
39//     "content-type",
40//     "content-length",
41//     "authorization",
42//     "accept",
43//     "accept-encoding",
44//     "user-agent",
45//     "x-forwarded-for",
46//     "x-real-ip",
47// ];
48
49// /// Headers that should be included in responses to reduce message size
50// pub const ESSENTIAL_RESPONSE_HEADERS: &[&str] = &[
51//     "content-type",
52//     "content-length",
53//     "content-encoding",
54//     "cache-control",
55//     "expires",
56//     "last-modified",
57//     "etag",
58//     "access-control-allow-origin",
59//     "access-control-allow-methods",
60//     "access-control-allow-headers",
61// ];
62
63// /// Filter headers to only include essential ones
64// pub fn filter_essential_headers(
65//     headers: &HashMap<String, String>,
66//     essential: &[&str],
67// ) -> HashMap<String, String> {
68//     headers
69//         .iter()
70//         .filter(|(key, _)| {
71//             let key_lower = key.to_lowercase();
72//             essential
73//                 .iter()
74//                 .any(|&essential_key| key_lower == essential_key)
75//         })
76//         .map(|(k, v)| (k.clone(), v.clone()))
77//         .collect()
78// }