Skip to content

Commit b4d4294

Browse files
as-ciibennetbo
andauthored
Restore token count for text threads (#36989)
Release Notes: - N/A Co-authored-by: Bennet Bo Fenner <[email protected]>
1 parent e5c0614 commit b4d4294

File tree

2 files changed

+56
-61
lines changed

2 files changed

+56
-61
lines changed

crates/agent_ui/src/agent_panel.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ use crate::{
2929
slash_command::SlashCommandCompletionProvider,
3030
text_thread_editor::{
3131
AgentPanelDelegate, TextThreadEditor, humanize_token_count, make_lsp_adapter_delegate,
32-
render_remaining_tokens,
3332
},
3433
thread_history::{HistoryEntryElement, ThreadHistory},
3534
ui::{AgentOnboardingModal, EndTrialUpsell},
@@ -2875,12 +2874,8 @@ impl AgentPanel {
28752874

28762875
Some(token_count)
28772876
}
2878-
ActiveView::TextThread { context_editor, .. } => {
2879-
let element = render_remaining_tokens(context_editor, cx)?;
2880-
2881-
Some(element.into_any_element())
2882-
}
28832877
ActiveView::ExternalAgentThread { .. }
2878+
| ActiveView::TextThread { .. }
28842879
| ActiveView::History
28852880
| ActiveView::Configuration => None,
28862881
}

crates/agent_ui/src/text_thread_editor.rs

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1857,6 +1857,53 @@ impl TextThreadEditor {
18571857
.update(cx, |context, cx| context.summarize(true, cx));
18581858
}
18591859

1860+
fn render_remaining_tokens(&self, cx: &App) -> Option<impl IntoElement + use<>> {
1861+
let (token_count_color, token_count, max_token_count, tooltip) =
1862+
match token_state(&self.context, cx)? {
1863+
TokenState::NoTokensLeft {
1864+
max_token_count,
1865+
token_count,
1866+
} => (
1867+
Color::Error,
1868+
token_count,
1869+
max_token_count,
1870+
Some("Token Limit Reached"),
1871+
),
1872+
TokenState::HasMoreTokens {
1873+
max_token_count,
1874+
token_count,
1875+
over_warn_threshold,
1876+
} => {
1877+
let (color, tooltip) = if over_warn_threshold {
1878+
(Color::Warning, Some("Token Limit is Close to Exhaustion"))
1879+
} else {
1880+
(Color::Muted, None)
1881+
};
1882+
(color, token_count, max_token_count, tooltip)
1883+
}
1884+
};
1885+
1886+
Some(
1887+
h_flex()
1888+
.id("token-count")
1889+
.gap_0p5()
1890+
.child(
1891+
Label::new(humanize_token_count(token_count))
1892+
.size(LabelSize::Small)
1893+
.color(token_count_color),
1894+
)
1895+
.child(Label::new("/").size(LabelSize::Small).color(Color::Muted))
1896+
.child(
1897+
Label::new(humanize_token_count(max_token_count))
1898+
.size(LabelSize::Small)
1899+
.color(Color::Muted),
1900+
)
1901+
.when_some(tooltip, |element, tooltip| {
1902+
element.tooltip(Tooltip::text(tooltip))
1903+
}),
1904+
)
1905+
}
1906+
18601907
fn render_send_button(&self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
18611908
let focus_handle = self.focus_handle(cx);
18621909

@@ -2420,9 +2467,14 @@ impl Render for TextThreadEditor {
24202467
)
24212468
.child(
24222469
h_flex()
2423-
.gap_1()
2424-
.child(self.render_language_model_selector(window, cx))
2425-
.child(self.render_send_button(window, cx)),
2470+
.gap_2p5()
2471+
.children(self.render_remaining_tokens(cx))
2472+
.child(
2473+
h_flex()
2474+
.gap_1()
2475+
.child(self.render_language_model_selector(window, cx))
2476+
.child(self.render_send_button(window, cx)),
2477+
),
24262478
),
24272479
)
24282480
}
@@ -2710,58 +2762,6 @@ impl FollowableItem for TextThreadEditor {
27102762
}
27112763
}
27122764

2713-
pub fn render_remaining_tokens(
2714-
context_editor: &Entity<TextThreadEditor>,
2715-
cx: &App,
2716-
) -> Option<impl IntoElement + use<>> {
2717-
let context = &context_editor.read(cx).context;
2718-
2719-
let (token_count_color, token_count, max_token_count, tooltip) = match token_state(context, cx)?
2720-
{
2721-
TokenState::NoTokensLeft {
2722-
max_token_count,
2723-
token_count,
2724-
} => (
2725-
Color::Error,
2726-
token_count,
2727-
max_token_count,
2728-
Some("Token Limit Reached"),
2729-
),
2730-
TokenState::HasMoreTokens {
2731-
max_token_count,
2732-
token_count,
2733-
over_warn_threshold,
2734-
} => {
2735-
let (color, tooltip) = if over_warn_threshold {
2736-
(Color::Warning, Some("Token Limit is Close to Exhaustion"))
2737-
} else {
2738-
(Color::Muted, None)
2739-
};
2740-
(color, token_count, max_token_count, tooltip)
2741-
}
2742-
};
2743-
2744-
Some(
2745-
h_flex()
2746-
.id("token-count")
2747-
.gap_0p5()
2748-
.child(
2749-
Label::new(humanize_token_count(token_count))
2750-
.size(LabelSize::Small)
2751-
.color(token_count_color),
2752-
)
2753-
.child(Label::new("/").size(LabelSize::Small).color(Color::Muted))
2754-
.child(
2755-
Label::new(humanize_token_count(max_token_count))
2756-
.size(LabelSize::Small)
2757-
.color(Color::Muted),
2758-
)
2759-
.when_some(tooltip, |element, tooltip| {
2760-
element.tooltip(Tooltip::text(tooltip))
2761-
}),
2762-
)
2763-
}
2764-
27652765
enum PendingSlashCommand {}
27662766

27672767
fn invoked_slash_command_fold_placeholder(

0 commit comments

Comments
 (0)