Show token used when context window is unknown (#7497)

- Show context window usage in tokens instead of percentage when the
window length is unknown.
This commit is contained in:
Ahmed Ibrahim
2025-12-02 11:45:50 -08:00
committed by GitHub
parent 21ad1c1c90
commit 127e307f89
8 changed files with 118 additions and 14 deletions

View File

@@ -76,6 +76,7 @@ pub(crate) struct BottomPane {
/// Queued user messages to show above the composer while a turn is running.
queued_user_messages: QueuedUserMessages,
context_window_percent: Option<i64>,
context_window_used_tokens: Option<i64>,
}
pub(crate) struct BottomPaneParams {
@@ -118,6 +119,7 @@ impl BottomPane {
esc_backtrack_hint: false,
animations_enabled,
context_window_percent: None,
context_window_used_tokens: None,
}
}
@@ -130,6 +132,11 @@ impl BottomPane {
self.context_window_percent
}
#[cfg(test)]
pub(crate) fn context_window_used_tokens(&self) -> Option<i64> {
self.context_window_used_tokens
}
fn active_view(&self) -> Option<&dyn BottomPaneView> {
self.view_stack.last().map(std::convert::AsRef::as_ref)
}
@@ -344,13 +351,16 @@ impl BottomPane {
}
}
pub(crate) fn set_context_window_percent(&mut self, percent: Option<i64>) {
if self.context_window_percent == percent {
pub(crate) fn set_context_window(&mut self, percent: Option<i64>, used_tokens: Option<i64>) {
if self.context_window_percent == percent && self.context_window_used_tokens == used_tokens
{
return;
}
self.context_window_percent = percent;
self.composer.set_context_window_percent(percent);
self.context_window_used_tokens = used_tokens;
self.composer
.set_context_window(percent, self.context_window_used_tokens);
self.request_redraw();
}