Skip to main content

convergio_ipc/
types.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, thiserror::Error)]
4pub enum IpcError {
5    #[error("database: {0}")]
6    Db(#[from] rusqlite::Error),
7    #[error("pool: {0}")]
8    Pool(#[from] r2d2::Error),
9    #[error("rate limited: {0}")]
10    RateLimited(String),
11    #[error("not found: {0}")]
12    NotFound(String),
13    #[error("http: {0}")]
14    Http(String),
15}
16
17pub type IpcResult<T> = Result<T, IpcError>;
18
19#[derive(Debug, Clone, Serialize, Deserialize)]
20pub struct AgentInfo {
21    pub name: String,
22    pub host: String,
23    pub agent_type: String,
24    pub pid: Option<u32>,
25    pub last_seen: String,
26    pub parent_agent: Option<String>,
27}
28
29#[derive(Debug, Clone, Serialize, Deserialize)]
30pub struct MessageInfo {
31    pub id: String,
32    pub from_agent: String,
33    pub to_agent: Option<String>,
34    pub channel: Option<String>,
35    pub content: String,
36    pub msg_type: String,
37    pub created_at: String,
38}
39
40#[derive(Debug, Clone, Serialize, Deserialize)]
41pub struct ChannelInfo {
42    pub name: String,
43    pub description: Option<String>,
44    pub created_by: String,
45    pub created_at: String,
46}
47
48#[derive(Debug, Clone, Serialize, Deserialize)]
49pub struct ContextEntry {
50    pub key: String,
51    pub value: String,
52    pub version: i64,
53    pub set_by: String,
54    pub updated_at: String,
55}
56
57#[derive(Debug, Clone, Serialize, Deserialize)]
58pub struct AgentSkill {
59    pub agent: String,
60    pub host: String,
61    pub skill: String,
62    pub confidence: f64,
63    pub last_used: String,
64}
65
66#[derive(Debug, Clone, Serialize, Deserialize)]
67pub struct ModelEntry {
68    pub host: String,
69    pub provider: String,
70    pub model: String,
71    pub size_gb: f64,
72    pub quantization: String,
73    pub last_seen: String,
74}
75
76#[derive(Debug, Clone, Serialize, Deserialize)]
77pub struct NodeCapabilities {
78    pub host: String,
79    pub provider: String,
80    pub models: Vec<String>,
81    pub updated_at: String,
82}
83
84#[derive(Debug, Clone, Serialize, Deserialize)]
85pub struct Subscription {
86    pub name: String,
87    pub provider: String,
88    pub plan: String,
89    pub budget_usd: f64,
90    pub reset_day: i32,
91    pub models: Vec<String>,
92}
93
94#[derive(Debug, Clone, Serialize, Deserialize)]
95pub struct BudgetEntry {
96    pub subscription: String,
97    pub date: String,
98    pub tokens_in: i64,
99    pub tokens_out: i64,
100    pub estimated_cost_usd: f64,
101    pub model: String,
102    pub task_ref: String,
103}
104
105#[derive(Debug, Clone, Serialize)]
106pub struct BudgetStatus {
107    pub subscription: String,
108    pub budget_usd: f64,
109    pub total_spent: f64,
110    pub remaining_budget: f64,
111    pub days_remaining: i32,
112    pub daily_avg: f64,
113    pub projected_total: f64,
114    pub usage_pct: f64,
115}
116
117#[derive(Debug, Clone, Serialize)]
118pub struct BudgetAlert {
119    pub subscription: String,
120    pub level: AlertLevel,
121    pub usage_pct: f64,
122    pub message: String,
123}
124
125#[derive(Debug, Clone, Serialize, PartialEq)]
126pub enum AlertLevel {
127    Warning,
128    High,
129    Critical,
130}
131
132#[derive(Debug, Clone, Serialize)]
133pub struct IpcStats {
134    pub agents: u64,
135    pub messages: u64,
136    pub channels: u64,
137    pub context_keys: u64,
138}
139
140#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
141pub struct FileLock {
142    pub file_path: String,
143    pub locked_by: String,
144    pub host: String,
145    pub pid: i64,
146    pub locked_at: String,
147}
148
149#[derive(Debug, Clone, PartialEq)]
150pub enum AcquireResult {
151    Acquired,
152    Rejected(FileLock),
153}