agent_ui: More agent notifications (#35441)

Release Notes:

- N/A
This commit is contained in:
Ben Brandt 2025-08-01 16:29:02 +02:00 committed by GitHub
parent 106aa0d9cc
commit e5c6a596a9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 547 additions and 11 deletions

View file

@ -580,6 +580,9 @@ pub struct AcpThread {
pub enum AcpThreadEvent {
NewEntry,
EntryUpdated(usize),
ToolAuthorizationRequired,
Stopped,
Error,
}
impl EventEmitter<AcpThreadEvent> for AcpThread {}
@ -676,6 +679,18 @@ impl AcpThread {
false
}
pub fn used_tools_since_last_user_message(&self) -> bool {
for entry in self.entries.iter().rev() {
match entry {
AgentThreadEntry::UserMessage(..) => return false,
AgentThreadEntry::AssistantMessage(..) => continue,
AgentThreadEntry::ToolCall(..) => return true,
}
}
false
}
pub fn handle_session_update(
&mut self,
update: acp::SessionUpdate,
@ -879,6 +894,7 @@ impl AcpThread {
};
self.upsert_tool_call_inner(tool_call, status, cx);
cx.emit(AcpThreadEvent::ToolAuthorizationRequired);
rx
}
@ -1018,12 +1034,18 @@ impl AcpThread {
.log_err();
}));
async move {
match rx.await {
Ok(Err(e)) => Err(e)?,
_ => Ok(()),
cx.spawn(async move |this, cx| match rx.await {
Ok(Err(e)) => {
this.update(cx, |_, cx| cx.emit(AcpThreadEvent::Error))
.log_err();
Err(e)?
}
}
_ => {
this.update(cx, |_, cx| cx.emit(AcpThreadEvent::Stopped))
.log_err();
Ok(())
}
})
.boxed()
}