generated from nhcarrigan/template
feat: massive overhaul to manage costs (#103)
### Explanation _No response_ ### Issue Closes #102 ### Attestations - [ ] I have read and agree to the [Code of Conduct](https://docs.nhcarrigan.com/community/coc/) - [ ] I have read and agree to the [Community Guidelines](https://docs.nhcarrigan.com/community/guide/). - [ ] My contribution complies with the [Contributor Covenant](https://docs.nhcarrigan.com/dev/covenant/). ### Dependencies - [ ] I have pinned the dependencies to a specific patch version. ### Style - [ ] I have run the linter and resolved any errors. - [ ] My pull request uses an appropriate title, matching the conventional commit standards. - [ ] My scope of feat/fix/chore/etc. correctly matches the nature of changes in my pull request. ### Tests - [ ] My contribution adds new code, and I have added tests to cover it. - [ ] My contribution modifies existing code, and I have updated the tests to reflect these changes. - [ ] All new and existing tests pass locally with my changes. - [ ] Code coverage remains at or above the configured threshold. ### Documentation _No response_ ### Versioning _No response_ Reviewed-on: #103 Co-authored-by: Naomi Carrigan <commits@nhcarrigan.com> Co-committed-by: Naomi Carrigan <commits@nhcarrigan.com>
This commit was merged in pull request #103.
This commit is contained in:
@@ -96,6 +96,22 @@ pub struct HikariConfig {
|
||||
// Custom theme colors
|
||||
#[serde(default)]
|
||||
pub custom_theme_colors: CustomThemeColors,
|
||||
|
||||
// Token budget settings
|
||||
#[serde(default)]
|
||||
pub budget_enabled: bool,
|
||||
|
||||
#[serde(default)]
|
||||
pub session_token_budget: Option<u64>,
|
||||
|
||||
#[serde(default)]
|
||||
pub session_cost_budget: Option<f64>,
|
||||
|
||||
#[serde(default = "default_budget_action")]
|
||||
pub budget_action: BudgetAction,
|
||||
|
||||
#[serde(default = "default_budget_warning_threshold")]
|
||||
pub budget_warning_threshold: f32,
|
||||
}
|
||||
|
||||
impl Default for HikariConfig {
|
||||
@@ -123,6 +139,11 @@ impl Default for HikariConfig {
|
||||
profile_avatar_path: None,
|
||||
profile_bio: None,
|
||||
custom_theme_colors: CustomThemeColors::default(),
|
||||
budget_enabled: false,
|
||||
session_token_budget: None,
|
||||
session_cost_budget: None,
|
||||
budget_action: BudgetAction::Warn,
|
||||
budget_warning_threshold: 0.8,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -147,6 +168,22 @@ fn default_font_size() -> u32 {
|
||||
14
|
||||
}
|
||||
|
||||
fn default_budget_action() -> BudgetAction {
|
||||
BudgetAction::Warn
|
||||
}
|
||||
|
||||
fn default_budget_warning_threshold() -> f32 {
|
||||
0.8
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum BudgetAction {
|
||||
#[default]
|
||||
Warn,
|
||||
Block,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum Theme {
|
||||
@@ -205,6 +242,11 @@ mod tests {
|
||||
assert!(config.profile_avatar_path.is_none());
|
||||
assert!(config.profile_bio.is_none());
|
||||
assert_eq!(config.custom_theme_colors, CustomThemeColors::default());
|
||||
assert!(!config.budget_enabled);
|
||||
assert!(config.session_token_budget.is_none());
|
||||
assert!(config.session_cost_budget.is_none());
|
||||
assert_eq!(config.budget_action, BudgetAction::Warn);
|
||||
assert!((config.budget_warning_threshold - 0.8).abs() < f32::EPSILON);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -232,6 +274,11 @@ mod tests {
|
||||
profile_avatar_path: None,
|
||||
profile_bio: Some("A test bio".to_string()),
|
||||
custom_theme_colors: CustomThemeColors::default(),
|
||||
budget_enabled: true,
|
||||
session_token_budget: Some(100000),
|
||||
session_cost_budget: Some(1.50),
|
||||
budget_action: BudgetAction::Block,
|
||||
budget_warning_threshold: 0.75,
|
||||
};
|
||||
|
||||
let json = serde_json::to_string(&config).unwrap();
|
||||
|
||||
Reference in New Issue
Block a user