agent: Remove unneeded tracking of request usage (#29894)

This PR removes some unneeded tracking of the model request usage in the
`ActiveThread` and `ThreadEvent::UsageUpdated` events.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2025-05-04 21:16:53 -04:00 committed by GitHub
parent fe177f5d69
commit 3db4744e18
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 4 additions and 18 deletions

View file

@ -29,8 +29,7 @@ use gpui::{
};
use language::{Buffer, Language, LanguageRegistry};
use language_model::{
LanguageModelRequestMessage, LanguageModelToolUseId, MessageContent, RequestUsage, Role,
StopReason,
LanguageModelRequestMessage, LanguageModelToolUseId, MessageContent, Role, StopReason,
};
use markdown::parser::{CodeBlockKind, CodeBlockMetadata};
use markdown::{HeadingLevelStyles, Markdown, MarkdownElement, MarkdownStyle, ParsedMarkdown};
@ -72,7 +71,6 @@ pub struct ActiveThread {
expanded_thinking_segments: HashMap<(MessageId, usize), bool>,
expanded_code_blocks: HashMap<(MessageId, usize), bool>,
last_error: Option<ThreadError>,
last_usage: Option<RequestUsage>,
notifications: Vec<WindowHandle<AgentNotification>>,
copied_code_block_ids: HashSet<(MessageId, usize)>,
_subscriptions: Vec<Subscription>,
@ -783,7 +781,6 @@ impl ActiveThread {
hide_scrollbar_task: None,
editing_message: None,
last_error: None,
last_usage: None,
copied_code_block_ids: HashSet::default(),
notifications: Vec::new(),
_subscriptions: subscriptions,
@ -840,10 +837,6 @@ impl ActiveThread {
self.last_error.take();
}
pub fn last_usage(&self) -> Option<RequestUsage> {
self.last_usage
}
/// Returns the editing message id and the estimated token count in the content
pub fn editing_message_id(&self) -> Option<(MessageId, usize)> {
self.editing_message
@ -949,9 +942,6 @@ impl ActiveThread {
ThreadEvent::ShowError(error) => {
self.last_error = Some(error.clone());
}
ThreadEvent::UsageUpdated(usage) => {
self.last_usage = Some(*usage);
}
ThreadEvent::NewRequest | ThreadEvent::CompletionCanceled => {
cx.notify();
}

View file

@ -1366,7 +1366,6 @@ impl AgentDiff {
}
// intentionally being exhaustive in case we add a variant we should handle
ThreadEvent::Stopped(Ok(StopReason::ToolUse))
| ThreadEvent::UsageUpdated(_)
| ThreadEvent::StreamedCompletion
| ThreadEvent::ReceivedTextChunk
| ThreadEvent::StreamedAssistantText(_, _)

View file

@ -1545,7 +1545,6 @@ impl Thread {
let usage = RequestUsage { limit, amount: amount as i32 };
thread.last_usage = Some(usage);
cx.emit(ThreadEvent::UsageUpdated(usage));
}
CompletionRequestStatus::ToolUseLimitReached => {
thread.tool_use_limit_reached = true;
@ -1714,11 +1713,11 @@ impl Thread {
LanguageModelCompletionEvent::StatusUpdate(
CompletionRequestStatus::UsageUpdated { amount, limit },
) => {
this.update(cx, |_, cx| {
cx.emit(ThreadEvent::UsageUpdated(RequestUsage {
this.update(cx, |thread, _cx| {
thread.last_usage = Some(RequestUsage {
limit,
amount: amount as i32,
}));
});
})?;
continue;
}
@ -2565,7 +2564,6 @@ pub enum ThreadError {
#[derive(Debug, Clone)]
pub enum ThreadEvent {
ShowError(ThreadError),
UsageUpdated(RequestUsage),
StreamedCompletion,
ReceivedTextChunk,
NewRequest,