Skip to main content

codetether_agent/tui/ui/chat_view/
title.rs

1//! Chat-panel block title (model + session labels).
2//!
3//! [`build_title`] composes the title bar string shown above the messages
4//! area, e.g. `CodeTether Agent [main] model:gpt-4o session:abc-123…`.
5
6use crate::session::Session;
7use crate::tui::app::state::App;
8use crate::tui::ui::status_bar::session_model_label;
9
10/// Build the messages-panel title string from the active model and session.
11///
12/// # Examples
13///
14/// ```rust,no_run
15/// use codetether_agent::tui::ui::chat_view::title::build_title;
16/// # fn demo(app: &codetether_agent::tui::app::state::App, sess: &codetether_agent::session::Session) {
17/// let title = build_title(app, sess);
18/// assert!(title.contains("model:"));
19/// # }
20/// ```
21pub fn build_title(app: &App, session: &Session) -> String {
22    let session_label = app
23        .state
24        .session_id
25        .as_deref()
26        .map(|id| {
27            if id.len() > 18 {
28                format!("{}…", &id[..18])
29            } else {
30                id.to_string()
31            }
32        })
33        .unwrap_or_else(|| "new".to_string());
34    let model_label = session
35        .metadata
36        .model
37        .clone()
38        .or_else(|| session_model_label(&app.state))
39        .unwrap_or_else(|| "auto".to_string());
40    format!(" CodeTether Agent [main] model:{model_label} session:{session_label} ")
41}