Skip to main content

remem/ai/
types.rs

1/// AI call timeout (seconds)
2pub(super) const AI_TIMEOUT_SECS: u64 = 90;
3
4#[derive(Clone, Copy)]
5pub struct UsageContext<'a> {
6    pub project: Option<&'a str>,
7    pub session_id: Option<&'a str>,
8    pub operation: &'a str,
9    pub host: Option<&'a str>,
10    pub profile: Option<&'a str>,
11}
12
13#[derive(Clone, Debug, Default, PartialEq, Eq)]
14pub(crate) struct TokenUsage {
15    pub input_tokens: i64,
16    pub output_tokens: i64,
17    pub reasoning_tokens: i64,
18    pub cache_creation_tokens: i64,
19    pub cache_read_tokens: i64,
20    pub raw_input_tokens: i64,
21    pub raw_output_tokens: i64,
22}
23
24impl TokenUsage {
25    pub fn estimated(input_tokens: i64, output_tokens: i64) -> Self {
26        Self {
27            input_tokens,
28            output_tokens,
29            raw_input_tokens: input_tokens,
30            raw_output_tokens: output_tokens,
31            ..Self::default()
32        }
33    }
34
35    pub fn total_tokens(&self) -> i64 {
36        self.input_tokens
37            + self.output_tokens
38            + self.reasoning_tokens
39            + self.cache_creation_tokens
40            + self.cache_read_tokens
41    }
42
43    pub fn is_empty(&self) -> bool {
44        self.total_tokens() == 0
45    }
46
47    pub fn add(&mut self, other: &Self) {
48        self.input_tokens += other.input_tokens;
49        self.output_tokens += other.output_tokens;
50        self.reasoning_tokens += other.reasoning_tokens;
51        self.cache_creation_tokens += other.cache_creation_tokens;
52        self.cache_read_tokens += other.cache_read_tokens;
53        self.raw_input_tokens += other.raw_input_tokens;
54        self.raw_output_tokens += other.raw_output_tokens;
55    }
56}
57
58pub(super) struct AiCallResult {
59    pub text: String,
60    pub executor: &'static str,
61    pub model: String,
62    pub usage: Option<TokenUsage>,
63    pub usage_source: Option<&'static str>,
64}