Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions crates/protocol/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ pub enum ServerEvent {
},
SessionEvent(StoredEvent),
SessionStatusReplaced(Box<SessionStatus>),
SessionUsageChanged {
usage: Option<TokenUsage>,
context_window: Option<u64>,
},
SessionPlanReplaced(SessionPlan),
ProvidersReplaced(ProvidersStatus),
GitStatusReplaced(GitStatusStatus),
Expand Down
2 changes: 2 additions & 0 deletions crates/protocol/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ pub use wire::{
// host then sends the text as an ordinary turn. Index subscriptions may carry
// known_index; matching content receives IndexUnchanged instead of a snapshot.
// ReadFilePreview rejects files larger than 512 KiB before transferring bytes.
// SessionUsageChanged carries usage and meter capacity when the rest of the
// session status is unchanged; subscription replies remain full statuses.
pub const PROTOCOL_VERSION: u32 = 12;

#[cfg(test)]
Expand Down
17 changes: 15 additions & 2 deletions crates/runtime/src/app/snapshots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,25 @@ impl DomainDiff {
.collect();
changed_ids.sort_unstable();
for id in changed_ids {
let status = session_statuses[id].clone();
let status = &session_statuses[id];
let usage_only = self.session_statuses.get_mut(id).is_some_and(|previous| {
previous.usage = status.usage;
previous.context_window = status.context_window;
previous == status
});
let event = if usage_only {
ServerEvent::SessionUsageChanged {
usage: status.usage,
context_window: status.context_window,
}
} else {
ServerEvent::SessionStatusReplaced(Box::new(status.clone()))
};
emit_replacement(
Topic::SessionStatus {
session_id: id.to_string(),
},
ServerEvent::SessionStatusReplaced(Box::new(status)),
event,
cx,
);
}
Expand Down
24 changes: 24 additions & 0 deletions crates/ui/src/store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1342,6 +1342,30 @@ impl WorkspaceStore {
self.sync_active_conversation_ui();
}
}
(
Topic::SessionStatus { session_id },
ServerEvent::SessionUsageChanged {
usage,
context_window,
},
) if self.baseline_topics.contains(&envelope.topic) => {
if let Some(status) = self
.threads
.get_mut(session_id)
.and_then(|thread| thread.status.as_mut())
{
status.usage = *usage;
status.context_window = *context_window;
}
if let Some(status) = self
.session_status_replica
.as_mut()
.filter(|status| status.session_id == *session_id)
{
status.usage = *usage;
status.context_window = *context_window;
}
}
(Topic::SessionPlan { session_id }, ServerEvent::SessionPlanReplaced(plan))
if plan.session_id == *session_id =>
{
Expand Down
Loading