refactor(status): pakai context::tokens dan context::window
Status bar sekarang memakai penghitungan token yang sama persis dengan compaction (bukan heuristik /4 terpisah), dan selalu menampilkan angka context window nyata alih-alih '?' saat model role tidak override context_window secara eksplisit — konsisten dengan fallback yang sudah dipakai compaction sendiri.
This commit is contained in:
+6
-14
@@ -56,33 +56,25 @@ pub fn draw_status_bar(frame: &mut Frame, area: Rect, state: &crate::app::state:
|
|||||||
];
|
];
|
||||||
|
|
||||||
// ── Right segment: metadata ───────────────────────────────────────────
|
// ── Right segment: metadata ───────────────────────────────────────────
|
||||||
let right_str = if let Some(ref rt) = state.session_runtime {
|
let max_tokens = crate::app::runtime::context::window::resolve(&state.app_config, &state.settings);
|
||||||
let max_tokens = state.app_config.model_roles.values()
|
|
||||||
.find(|role| role.provider == state.settings.provider && role.model == state.settings.model)
|
|
||||||
.and_then(|role| role.context_window);
|
|
||||||
|
|
||||||
let total_chars: usize = rt.messages.iter()
|
let right_str = if let Some(ref rt) = state.session_runtime {
|
||||||
|
let current_tokens: usize = rt.messages.iter()
|
||||||
.filter_map(|m| m.content.as_deref())
|
.filter_map(|m| m.content.as_deref())
|
||||||
.map(str::len)
|
.map(crate::app::runtime::context::tokens::count_tokens)
|
||||||
.sum();
|
.sum();
|
||||||
let current_tokens = total_chars / 4;
|
|
||||||
|
|
||||||
let mut parts = Vec::new();
|
let mut parts = Vec::new();
|
||||||
if rt.usage.last_tokens_in > 0 || rt.usage.last_tokens_out > 0 {
|
if rt.usage.last_tokens_in > 0 || rt.usage.last_tokens_out > 0 {
|
||||||
parts.push(format!("↑{} ↓{}", rt.usage.last_tokens_in, rt.usage.last_tokens_out));
|
parts.push(format!("↑{} ↓{}", rt.usage.last_tokens_in, rt.usage.last_tokens_out));
|
||||||
}
|
}
|
||||||
let max_str = max_tokens.map_or_else(|| "?".to_string(), |v| v.to_string());
|
parts.push(format!("{current_tokens}/{max_tokens}"));
|
||||||
parts.push(format!("{current_tokens}/{max_str}"));
|
|
||||||
parts.push(state.settings.provider.clone());
|
parts.push(state.settings.provider.clone());
|
||||||
parts.push(state.settings.model.clone());
|
parts.push(state.settings.model.clone());
|
||||||
|
|
||||||
format!(" {} ", parts.join(" · "))
|
format!(" {} ", parts.join(" · "))
|
||||||
} else {
|
} else {
|
||||||
let max_tokens = state.app_config.model_roles.values()
|
format!(" 0/{} · {} · {} ", max_tokens, state.settings.provider, state.settings.model)
|
||||||
.find(|role| role.provider == state.settings.provider && role.model == state.settings.model)
|
|
||||||
.and_then(|role| role.context_window);
|
|
||||||
let max_str = max_tokens.map_or_else(|| "?".to_string(), |v| v.to_string());
|
|
||||||
format!(" 0/{} · {} · {} ", max_str, state.settings.provider, state.settings.model)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// ── Combine everything ────────────────────────────────────────────────
|
// ── Combine everything ────────────────────────────────────────────────
|
||||||
|
|||||||
Reference in New Issue
Block a user