parent
106aa0d9cc
commit
e5c6a596a9
3 changed files with 547 additions and 11 deletions
|
@ -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()
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue