Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

agent_ui: Add reload controls for failed agent connections (#62669)

CodeNebula96382d8e7e3a
diff --git a/crates/agent_ui/src/agent_panel.rs b/crates/agent_ui/src/agent_panel.rs
index d274906c813..5496df4a5a9 100644
--- a/crates/agent_ui/src/agent_panel.rs
+++ b/crates/agent_ui/src/agent_panel.rs
@@ -5752,6 +5752,17 @@ impl AgentPanel {
menu = menu.action("Log Out", Box::new(LogoutAgent))
}
+ if let Some(conversation_view) = conversation_view.as_ref() {
+ menu = menu.entry("Reload Agent", None, {
+ let conversation_view = conversation_view.clone();
+ move |window, cx| {
+ conversation_view.update(cx, |conversation_view, cx| {
+ conversation_view.retry_connection(window, cx);
+ });
+ }
+ });
+ }
+
menu
}))
}
diff --git a/crates/agent_ui/src/conversation_view.rs b/crates/agent_ui/src/conversation_view.rs
index 0b52beb4cdb..d31efedb763 100644
--- a/crates/agent_ui/src/conversation_view.rs
+++ b/crates/agent_ui/src/conversation_view.rs
@@ -979,6 +979,15 @@ impl ConversationView {
.request_elicitations()
}
+ /// Drops the cached connection for this agent (so the next request spawns a
+ /// fresh server process) and rebuilds the thread state from scratch.
+ pub(crate) fn retry_connection(&mut self, window: &mut Window, cx: &mut Context<Self>) {
+ self.connection_store.update(cx, |store, cx| {
+ store.restart_connection(self.connection_key.clone(), self.agent.clone(), cx);
+ });
+ self.reset(window, cx);
+ }
+
fn reset(&mut self, window: &mut Window, cx: &mut Context<Self>) {
let (resume_session_id, work_dirs, title) = self
.root_thread_view()
@@ -2715,7 +2724,7 @@ impl ConversationView {
window: &mut Window,
cx: &mut Context<Self>,
) -> AnyElement {
- let (title, message, action_slot): (_, SharedString, _) = match e {
+ let (title, message) = match e {
LoadError::Unsupported {
command: path,
current_version,
@@ -2723,35 +2732,36 @@ impl ConversationView {
} => {
return self.render_unsupported(path, current_version, minimum_version, window, cx);
}
- LoadError::FailedToInstall(msg) => (
- "Failed to Install",
- msg.into(),
- Some(self.create_copy_button(msg.to_string()).into_any_element()),
- ),
+ LoadError::FailedToInstall(msg) => ("Failed to Install", msg.to_string()),
LoadError::Exited { status, stderr } => {
let mut message = format!("Server exited with status {status}");
if let Some(stderr) = stderr {
message.push_str("\n");
message.push_str(stderr);
};
- let action_slot = stderr
- .is_some()
- .then(|| self.create_copy_button(message.clone()).into_any_element());
- ("Failed to Launch", message.into(), action_slot)
+ ("Failed to Launch", message)
}
- LoadError::Other(msg) => (
- "Failed to Launch",
- msg.into(),
- Some(self.create_copy_button(msg.to_string()).into_any_element()),
- ),
+ LoadError::Other(msg) => ("Failed to Launch", msg.to_string()),
};
+ let action_slot = h_flex()
+ .gap_1()
+ .child(
+ Button::new("retry-agent-launch", "Retry")
+ .tooltip(Tooltip::text("Try to restart the agent"))
+ .on_click(cx.listener(move |this, _, window, cx| {
+ this.retry_connection(window, cx);
+ })),
+ )
+ .child(self.create_copy_button(message.clone()))
+ .into_any_element();
+
Callout::new()
.severity(Severity::Error)
.icon(IconName::XCircleFilled)
.title(title)
.description(message)
- .actions_slot(div().children(action_slot))
+ .actions_slot(action_slot)
.into_any_element()
}