Add input and output token tracking to SessionMetadata (#1979)

This commit is contained in:
Young Kim
2025-04-01 11:08:28 -07:00
committed by GitHub
parent 45e0f7f717
commit 2fbf601446
5 changed files with 20 additions and 4 deletions
+10
View File
@@ -27,6 +27,10 @@ pub struct SessionMetadata {
pub message_count: usize,
/// The total number of tokens used in the session. Retrieved from the provider's last usage.
pub total_tokens: Option<i32>,
/// The number of input tokens used in the session. Retrieved from the provider's last usage.
pub input_tokens: Option<i32>,
/// The number of output tokens used in the session. Retrieved from the provider's last usage.
pub output_tokens: Option<i32>,
}
// Custom deserializer to handle old sessions without working_dir
@@ -40,6 +44,8 @@ impl<'de> Deserialize<'de> for SessionMetadata {
description: String,
message_count: usize,
total_tokens: Option<i32>,
input_tokens: Option<i32>,
output_tokens: Option<i32>,
working_dir: Option<PathBuf>,
}
@@ -49,6 +55,8 @@ impl<'de> Deserialize<'de> for SessionMetadata {
description: helper.description,
message_count: helper.message_count,
total_tokens: helper.total_tokens,
input_tokens: helper.input_tokens,
output_tokens: helper.output_tokens,
working_dir: helper.working_dir.unwrap_or_else(get_home_dir),
})
}
@@ -61,6 +69,8 @@ impl SessionMetadata {
description: String::new(),
message_count: 0,
total_tokens: None,
input_tokens: None,
output_tokens: None,
}
}
}