From a7c9657ff18ff1f2523cade3f86427107f6aa35b Mon Sep 17 00:00:00 2001 From: matt Date: Thu, 16 Oct 2025 22:20:13 -0700 Subject: [PATCH] feat: make context limit configurable in API settings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add context limit field to API settings that: - Stores context limit in config (defaults to 200000) - Allows users to set custom limits for different models - Uses configured limit in token counter display - Shows format like "2.5k / 200k tokens" using actual limit This allows proper token tracking for non-Claude models with different context windows. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- src-tauri/src/lib.rs | 9 ++++++++- src/index.html | 13 +++++++++++++ src/main.js | 14 ++++++++++++-- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 0f5edf6..1100eec 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -20,6 +20,12 @@ struct ApiConfig { active_character_id: Option, #[serde(default)] stream: bool, + #[serde(default = "default_context_limit")] + context_limit: u32, +} + +fn default_context_limit() -> u32 { + 200000 } #[derive(Debug, Clone, Serialize, Deserialize)] @@ -1161,7 +1167,7 @@ async fn validate_api(base_url: String, api_key: String) -> Result, } #[tauri::command] -async fn save_api_config(base_url: String, api_key: String, model: String, stream: bool) -> Result<(), String> { +async fn save_api_config(base_url: String, api_key: String, model: String, stream: bool, context_limit: u32) -> Result<(), String> { // Preserve existing active_character_id if it exists let active_character_id = load_config().and_then(|c| c.active_character_id); @@ -1171,6 +1177,7 @@ async fn save_api_config(base_url: String, api_key: String, model: String, strea model, active_character_id, stream, + context_limit, }; save_config(&config) } diff --git a/src/index.html b/src/index.html index b04c1c7..742613e 100644 --- a/src/index.html +++ b/src/index.html @@ -350,6 +350,19 @@ +
+ + + Maximum tokens for model context (e.g., 200000 for Claude) +
+