agent: Add token count in the thread view (#28037)

This PR adds the token count to the active thread view. It doesn't
behaves quite like Assistant 1 where it updates as you type, though; it
updates after you submit the message.

<img
src="https://github.com/user-attachments/assets/82d2a180-554a-43ee-b776-3743359b609b"
width="700" />

---

Release Notes:

- agent: Add token count in the thread view

---------

Co-authored-by: Agus Zubiaga <hi@aguz.me>
This commit is contained in:
Danilo Leal 2025-04-03 15:43:58 -03:00 committed by GitHub
parent e5b347b03a
commit b9724d9cbe
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 132 additions and 27 deletions

View file

@ -3703,6 +3703,18 @@ pub fn humanize_token_count(count: usize) -> String {
format!("{}.{}k", thousands, hundreds)
}
}
1_000_000..=9_999_999 => {
let millions = count / 1_000_000;
let hundred_thousands = (count % 1_000_000 + 50_000) / 100_000;
if hundred_thousands == 0 {
format!("{}M", millions)
} else if hundred_thousands == 10 {
format!("{}M", millions + 1)
} else {
format!("{}.{}M", millions, hundred_thousands)
}
}
10_000_000.. => format!("{}M", (count + 500_000) / 1_000_000),
_ => format!("{}k", (count + 500) / 1000),
}
}