1use chrono::{DateTime, Duration, Utc};
4use serde::{Deserialize, Serialize};
5use std::collections::HashMap;
6use uuid::Uuid;
7
8#[derive(Debug, Clone, Serialize, Deserialize)]
10pub struct Session {
11 pub id: String,
13 pub name: String,
15 pub created_at: DateTime<Utc>,
17 pub updated_at: DateTime<Utc>,
19 pub status: SessionStatus,
21 pub context: SessionContext,
23 pub history: Vec<Message>,
25 pub background_agents: Vec<BackgroundAgent>,
27}
28
29impl Session {
30 pub fn new(name: String, context: SessionContext) -> Self {
32 let now = Utc::now();
33 Self {
34 id: Uuid::new_v4().to_string(),
35 name,
36 created_at: now,
37 updated_at: now,
38 status: SessionStatus::Active,
39 context,
40 history: Vec::new(),
41 background_agents: Vec::new(),
42 }
43 }
44}
45
46#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
48pub enum SessionStatus {
49 Active,
51 Paused,
53 Archived,
55}
56
57#[derive(Debug, Clone, Serialize, Deserialize)]
59pub struct SessionContext {
60 pub project_path: Option<String>,
62 pub provider: String,
64 pub model: String,
66 pub mode: SessionMode,
68 pub files: Vec<String>,
70 pub custom: HashMap<String, serde_json::Value>,
72}
73
74impl SessionContext {
75 pub fn new(provider: String, model: String, mode: SessionMode) -> Self {
77 Self {
78 project_path: None,
79 provider,
80 model,
81 mode,
82 files: Vec::new(),
83 custom: HashMap::new(),
84 }
85 }
86}
87
88#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
90pub enum SessionMode {
91 Chat,
93 Code,
95 Vibe,
97}
98
99#[derive(Debug, Clone, Serialize, Deserialize)]
101pub struct Message {
102 pub id: String,
104 pub role: MessageRole,
106 pub content: String,
108 pub timestamp: DateTime<Utc>,
110 pub metadata: MessageMetadata,
112}
113
114impl Message {
115 pub fn new(role: MessageRole, content: String) -> Self {
117 Self {
118 id: Uuid::new_v4().to_string(),
119 role,
120 content,
121 timestamp: Utc::now(),
122 metadata: MessageMetadata::default(),
123 }
124 }
125}
126
127#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
129pub enum MessageRole {
130 User,
132 Assistant,
134 System,
136}
137
138#[derive(Debug, Clone, Default, Serialize, Deserialize)]
140pub struct MessageMetadata {
141 pub tokens: Option<usize>,
143 pub model: Option<String>,
145 pub duration: Option<Duration>,
147}
148
149#[derive(Debug, Clone, Serialize, Deserialize)]
151pub struct BackgroundAgent {
152 pub id: String,
154 pub agent_type: String,
156 pub status: AgentStatus,
158 pub task: Option<String>,
160 pub started_at: DateTime<Utc>,
162 pub completed_at: Option<DateTime<Utc>>,
164}
165
166impl BackgroundAgent {
167 pub fn new(agent_type: String, task: Option<String>) -> Self {
169 Self {
170 id: Uuid::new_v4().to_string(),
171 agent_type,
172 status: AgentStatus::Running,
173 task,
174 started_at: Utc::now(),
175 completed_at: None,
176 }
177 }
178}
179
180#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
182pub enum AgentStatus {
183 Running,
185 Completed,
187 Failed,
189 Cancelled,
191}