Skip to main content

sqz_engine/
types.rs

1use std::path::PathBuf;
2use chrono::{DateTime, Utc};
3use serde::{Deserialize, Serialize};
4
5// Type aliases
6pub type SessionId = String;
7pub type AgentId = String;
8pub type CorrectionId = String;
9pub type ToolId = String;
10
11// --- Enums ---
12
13#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
14pub enum ImageFormat {
15    Png,
16    Jpeg,
17    Gif,
18    WebP,
19}
20
21#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
22#[serde(rename_all = "lowercase")]
23pub enum Role {
24    User,
25    Assistant,
26    System,
27}
28
29#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
30pub enum ContentType {
31    Json,
32    CliOutput { command: String },
33    Code { language: String, path: PathBuf },
34    PlainText,
35    Image { format: ImageFormat },
36}
37
38#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
39pub enum ModelFamily {
40    AnthropicClaude,
41    OpenAiGpt,
42    GoogleGemini,
43    Local(String),
44}
45
46#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
47pub enum Provider {
48    /// 90% cache discount
49    Anthropic,
50    /// 50% cache discount
51    OpenAI,
52    /// No cache boundary
53    Google,
54}
55
56#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
57pub enum TaskClassification {
58    Simple,
59    Complex,
60}
61
62// --- Content types ---
63
64#[derive(Debug, Clone, Serialize, Deserialize)]
65pub struct ContentMetadata {
66    pub source: Option<String>,
67    pub path: Option<PathBuf>,
68    pub language: Option<String>,
69}
70
71#[derive(Debug, Clone, Serialize, Deserialize)]
72pub struct Content {
73    pub raw: String,
74    pub content_type: ContentType,
75    pub metadata: ContentMetadata,
76    pub tokens_original: u32,
77}
78
79#[derive(Debug, Clone, Serialize, Deserialize)]
80pub struct CompressedContent {
81    pub data: String,
82    pub tokens_compressed: u32,
83    pub tokens_original: u32,
84    pub stages_applied: Vec<String>,
85    pub compression_ratio: f64,
86}
87
88// --- Session types ---
89
90#[derive(Debug, Clone, Serialize, Deserialize)]
91pub struct ConversationTurn {
92    pub role: Role,
93    pub content: String,
94    pub tokens: u32,
95    pub pinned: bool,
96    pub timestamp: DateTime<Utc>,
97}
98
99#[derive(Debug, Clone, Serialize, Deserialize)]
100pub struct PinEntry {
101    pub turn_index: usize,
102    pub reason: String,
103    pub tokens: u32,
104}
105
106#[derive(Debug, Clone, Serialize, Deserialize)]
107pub struct Learning {
108    pub key: String,
109    pub value: String,
110    pub source_turn: usize,
111}
112
113#[derive(Debug, Clone, Serialize, Deserialize)]
114pub struct BudgetState {
115    pub window_size: u32,
116    pub consumed: u32,
117    pub pinned: u32,
118    pub model_family: ModelFamily,
119}
120
121#[derive(Debug, Clone, Serialize, Deserialize)]
122pub struct ToolUsageRecord {
123    pub tool_name: String,
124    pub tokens_input: u32,
125    pub tokens_output: u32,
126    pub cost_usd: f64,
127    pub timestamp: DateTime<Utc>,
128}
129
130#[derive(Debug, Clone, Serialize, Deserialize)]
131pub struct CorrectionEntry {
132    pub id: CorrectionId,
133    pub timestamp: DateTime<Utc>,
134    pub original: String,
135    pub correction: String,
136    pub context: String,
137}
138
139#[derive(Debug, Clone, Serialize, Deserialize, Default)]
140pub struct CorrectionLog {
141    pub entries: Vec<CorrectionEntry>,
142}
143
144#[derive(Debug, Clone, Serialize, Deserialize)]
145pub struct SessionState {
146    pub id: SessionId,
147    pub project_dir: PathBuf,
148    pub conversation: Vec<ConversationTurn>,
149    pub corrections: CorrectionLog,
150    pub pins: Vec<PinEntry>,
151    pub learnings: Vec<Learning>,
152    pub compressed_summary: String,
153    pub budget: BudgetState,
154    pub tool_usage: Vec<ToolUsageRecord>,
155    pub created_at: DateTime<Utc>,
156    pub updated_at: DateTime<Utc>,
157}
158
159/// Configuration for a single compression stage
160#[derive(Debug, Clone, Serialize, Deserialize, Default)]
161pub struct StageConfig {
162    pub enabled: bool,
163    #[serde(default)]
164    pub options: serde_json::Value,
165}