diff --git a/crates/agent_ui/src/agent_connection_store.rs b/crates/agent_ui/src/agent_connection_store.rs index 936b9b7a2de984f20f59c8f050ecb3bff1386595..c9be46aea3ad99dec77724710db9088ae459696e 100644 --- a/crates/agent_ui/src/agent_connection_store.rs +++ b/crates/agent_ui/src/agent_connection_store.rs @@ -9,7 +9,7 @@ use gpui::{AppContext, Context, Entity, EventEmitter, SharedString, Subscription use project::{AgentServerStore, AgentServersUpdated, Project}; use watch::Receiver; -use crate::{ExternalAgent, ThreadHistory}; +use crate::{Agent, ThreadHistory}; use project::ExternalAgentServerName; pub enum AgentConnectionEntry { @@ -53,7 +53,7 @@ impl EventEmitter for AgentConnectionEntry {} pub struct AgentConnectionStore { project: Entity, - entries: HashMap>, + entries: HashMap>, _subscriptions: Vec, } @@ -68,13 +68,13 @@ impl AgentConnectionStore { } } - pub fn entry(&self, key: &ExternalAgent) -> Option<&Entity> { + pub fn entry(&self, key: &Agent) -> Option<&Entity> { self.entries.get(key) } pub fn request_connection( &mut self, - key: ExternalAgent, + key: Agent, server: Rc, cx: &mut Context, ) -> Entity { @@ -142,8 +142,8 @@ impl AgentConnectionStore { ) { let store = store.read(cx); self.entries.retain(|key, _| match key { - ExternalAgent::NativeAgent => true, - ExternalAgent::Custom { name } => store + Agent::NativeAgent => true, + Agent::Custom { name } => store .external_agents .contains_key(&ExternalAgentServerName(name.clone())), }); diff --git a/crates/agent_ui/src/agent_panel.rs b/crates/agent_ui/src/agent_panel.rs index 741e995c8f1b2e44677ec7c7de7bef22a3421f3c..09d52b6000392693d435217b4739ddc452b8de6d 100644 --- a/crates/agent_ui/src/agent_panel.rs +++ b/crates/agent_ui/src/agent_panel.rs @@ -42,7 +42,7 @@ use crate::{ ui::EndTrialUpsell, }; use crate::{ - AgentInitialContent, ExternalAgent, ExternalSourcePrompt, NewExternalAgentThread, + Agent, AgentInitialContent, ExternalSourcePrompt, NewExternalAgentThread, NewNativeAgentThreadFromSummary, }; use crate::{ @@ -738,11 +738,11 @@ impl AgentType { } } -impl From for AgentType { - fn from(value: ExternalAgent) -> Self { +impl From for AgentType { + fn from(value: Agent) -> Self { match value { - ExternalAgent::Custom { name } => Self::Custom { name }, - ExternalAgent::NativeAgent => Self::NativeAgent, + Agent::Custom { name } => Self::Custom { name }, + Agent::NativeAgent => Self::NativeAgent, } } } @@ -1283,7 +1283,7 @@ impl AgentPanel { cx: &mut Context, ) { self.external_thread( - Some(crate::ExternalAgent::NativeAgent), + Some(crate::Agent::NativeAgent), Some(session_id), cwd, title, @@ -1335,7 +1335,7 @@ impl AgentPanel { window: &mut Window, cx: &mut Context, ) { - let agent = ExternalAgent::NativeAgent; + let agent = Agent::NativeAgent; let server = agent.server(self.fs.clone(), self.thread_store.clone()); let session_id = action.from_session_id.clone(); @@ -1417,7 +1417,7 @@ impl AgentPanel { fn external_thread( &mut self, - agent_choice: Option, + agent_choice: Option, resume_session_id: Option, cwd: Option, title: Option, @@ -1435,7 +1435,7 @@ impl AgentPanel { #[derive(Serialize, Deserialize)] struct LastUsedExternalAgent { - agent: crate::ExternalAgent, + agent: crate::Agent, } let thread_store = self.thread_store.clone(); @@ -1473,7 +1473,7 @@ impl AgentPanel { } else { cx.spawn_in(window, async move |this, cx| { let ext_agent = if is_via_collab { - ExternalAgent::NativeAgent + Agent::NativeAgent } else { cx.background_spawn(async move { KEY_VALUE_STORE.read_kvp(LAST_USED_EXTERNAL_AGENT_KEY) @@ -1485,7 +1485,7 @@ impl AgentPanel { serde_json::from_str::(&value).log_err() }) .map(|agent| agent.agent) - .unwrap_or(ExternalAgent::NativeAgent) + .unwrap_or(Agent::NativeAgent) }; let server = ext_agent.server(fs, thread_store); @@ -1554,7 +1554,7 @@ impl AgentPanel { match &self.selected_agent { AgentType::TextThread | AgentType::NativeAgent => true, AgentType::Custom { name } => { - let agent = ExternalAgent::Custom { name: name.clone() }; + let agent = Agent::Custom { name: name.clone() }; self.connection_store .read(cx) .entry(&agent) @@ -1574,7 +1574,7 @@ impl AgentPanel { let history = self .connection_store .read(cx) - .entry(&ExternalAgent::NativeAgent)? + .entry(&Agent::NativeAgent)? .read(cx) .history()? .clone(); @@ -1584,7 +1584,7 @@ impl AgentPanel { }) } AgentType::Custom { name } => { - let agent = ExternalAgent::Custom { name: name.clone() }; + let agent = Agent::Custom { name: name.clone() }; let history = self .connection_store .read(cx) @@ -2376,10 +2376,10 @@ impl AgentPanel { cx.notify(); } - fn selected_external_agent(&self) -> Option { + fn selected_external_agent(&self) -> Option { match &self.selected_agent { - AgentType::NativeAgent => Some(ExternalAgent::NativeAgent), - AgentType::Custom { name } => Some(ExternalAgent::Custom { name: name.clone() }), + AgentType::NativeAgent => Some(Agent::NativeAgent), + AgentType::Custom { name } => Some(Agent::Custom { name: name.clone() }), AgentType::TextThread => None, } } @@ -2448,7 +2448,7 @@ impl AgentPanel { window.dispatch_action(NewTextThread.boxed_clone(), cx); } AgentType::NativeAgent => self.external_thread( - Some(crate::ExternalAgent::NativeAgent), + Some(crate::Agent::NativeAgent), None, None, None, @@ -2458,7 +2458,7 @@ impl AgentPanel { cx, ), AgentType::Custom { name } => self.external_thread( - Some(crate::ExternalAgent::Custom { name }), + Some(crate::Agent::Custom { name }), None, None, None, @@ -2544,7 +2544,7 @@ impl AgentPanel { initial_content: Option, workspace: WeakEntity, project: Entity, - ext_agent: ExternalAgent, + ext_agent: Agent, focus: bool, window: &mut Window, cx: &mut Context, @@ -4976,7 +4976,7 @@ impl rules_library::InlineAssistDelegate for PromptLibraryInlineAssist { .read(cx) .connection_store() .read(cx) - .entry(&crate::ExternalAgent::NativeAgent) + .entry(&crate::Agent::NativeAgent) .and_then(|s| s.read(cx).history()) else { log::error!("No connection entry found for native agent"); @@ -5158,7 +5158,7 @@ impl AgentPanel { let workspace = self.workspace.clone(); let project = self.project.clone(); - let ext_agent = ExternalAgent::Custom { + let ext_agent = Agent::Custom { name: server.name(), }; diff --git a/crates/agent_ui/src/agent_ui.rs b/crates/agent_ui/src/agent_ui.rs index 52ce6f0bd7a312966b6602fb43be4074d7f3e620..fbf47615cb23b75eaeff1f785ada8bf8605556d3 100644 --- a/crates/agent_ui/src/agent_ui.rs +++ b/crates/agent_ui/src/agent_ui.rs @@ -205,7 +205,7 @@ pub struct NewThread; #[serde(deny_unknown_fields)] pub struct NewExternalAgentThread { /// Which agent to use for the conversation. - agent: Option, + agent: Option, } #[derive(Clone, PartialEq, Deserialize, JsonSchema, Action)] @@ -218,7 +218,7 @@ pub struct NewNativeAgentThreadFromSummary { // TODO unify this with AgentType #[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, JsonSchema)] #[serde(rename_all = "snake_case")] -pub enum ExternalAgent { +pub enum Agent { NativeAgent, Custom { name: SharedString }, } @@ -227,7 +227,7 @@ pub enum ExternalAgent { // the registry: "claude_code" -> Custom { name: "claude-acp" }, "codex" -> Custom { name: // "codex-acp" }, "gemini" -> Custom { name: "gemini" }. // Can be removed at some point in the future and go back to #[derive(Deserialize)]. -impl<'de> serde::Deserialize<'de> for ExternalAgent { +impl<'de> serde::Deserialize<'de> for Agent { fn deserialize(deserializer: D) -> Result where D: serde::Deserializer<'de>, @@ -280,7 +280,7 @@ impl<'de> serde::Deserialize<'de> for ExternalAgent { } } -impl ExternalAgent { +impl Agent { pub fn server( &self, fs: Arc, @@ -752,20 +752,20 @@ mod tests { use project::agent_server_store::{CLAUDE_AGENT_NAME, CODEX_NAME, GEMINI_NAME}; assert_eq!( - serde_json::from_str::(r#""claude_code""#).unwrap(), - ExternalAgent::Custom { + serde_json::from_str::(r#""claude_code""#).unwrap(), + Agent::Custom { name: CLAUDE_AGENT_NAME.into(), }, ); assert_eq!( - serde_json::from_str::(r#""codex""#).unwrap(), - ExternalAgent::Custom { + serde_json::from_str::(r#""codex""#).unwrap(), + Agent::Custom { name: CODEX_NAME.into(), }, ); assert_eq!( - serde_json::from_str::(r#""gemini""#).unwrap(), - ExternalAgent::Custom { + serde_json::from_str::(r#""gemini""#).unwrap(), + Agent::Custom { name: GEMINI_NAME.into(), }, ); @@ -774,12 +774,12 @@ mod tests { #[test] fn test_deserialize_current_external_agent_variants() { assert_eq!( - serde_json::from_str::(r#""native_agent""#).unwrap(), - ExternalAgent::NativeAgent, + serde_json::from_str::(r#""native_agent""#).unwrap(), + Agent::NativeAgent, ); assert_eq!( - serde_json::from_str::(r#"{"custom":{"name":"my-agent"}}"#).unwrap(), - ExternalAgent::Custom { + serde_json::from_str::(r#"{"custom":{"name":"my-agent"}}"#).unwrap(), + Agent::Custom { name: "my-agent".into(), }, ); diff --git a/crates/agent_ui/src/connection_view.rs b/crates/agent_ui/src/connection_view.rs index 8aeacbd61ad404f94c39efbd14a846a3b52150d9..e84e18e645ed4a84bd667564416682298b35ce17 100644 --- a/crates/agent_ui/src/connection_view.rs +++ b/crates/agent_ui/src/connection_view.rs @@ -76,9 +76,9 @@ use crate::message_editor::{MessageEditor, MessageEditorEvent}; use crate::profile_selector::{ProfileProvider, ProfileSelector}; use crate::ui::{AgentNotification, AgentNotificationEvent}; use crate::{ - AgentDiffPane, AgentInitialContent, AgentPanel, AllowAlways, AllowOnce, AuthorizeToolCall, - ClearMessageQueue, CycleFavoriteModels, CycleModeSelector, CycleThinkingEffort, - EditFirstQueuedMessage, ExpandMessageEditor, ExternalAgent, Follow, KeepAll, NewThread, + Agent, AgentDiffPane, AgentInitialContent, AgentPanel, AllowAlways, AllowOnce, + AuthorizeToolCall, ClearMessageQueue, CycleFavoriteModels, CycleModeSelector, + CycleThinkingEffort, EditFirstQueuedMessage, ExpandMessageEditor, Follow, KeepAll, NewThread, OpenAddContextMenu, OpenAgentDiff, OpenHistory, RejectAll, RejectOnce, RemoveFirstQueuedMessage, SendImmediately, SendNextQueuedMessage, ToggleFastMode, ToggleProfileSelector, ToggleThinkingEffortMenu, ToggleThinkingMode, UndoLastReject, @@ -309,7 +309,7 @@ impl EventEmitter for ConnectionView {} pub struct ConnectionView { agent: Rc, connection_store: Entity, - connection_key: ExternalAgent, + connection_key: Agent, agent_server_store: Entity, workspace: WeakEntity, project: Entity, @@ -477,7 +477,7 @@ impl ConnectionView { pub fn new( agent: Rc, connection_store: Entity, - connection_key: ExternalAgent, + connection_key: Agent, resume_session_id: Option, cwd: Option, title: Option, @@ -597,7 +597,7 @@ impl ConnectionView { fn initial_state( agent: Rc, connection_store: Entity, - connection_key: ExternalAgent, + connection_key: Agent, resume_session_id: Option, cwd: Option, title: Option, @@ -2918,7 +2918,7 @@ pub(crate) mod tests { ConnectionView::new( Rc::new(StubAgentServer::default_response()), connection_store, - ExternalAgent::Custom { + Agent::Custom { name: "Test".into(), }, None, @@ -3030,7 +3030,7 @@ pub(crate) mod tests { ConnectionView::new( Rc::new(StubAgentServer::new(ResumeOnlyAgentConnection)), connection_store, - ExternalAgent::Custom { + Agent::Custom { name: "Test".into(), }, Some(SessionId::new("resume-session")), @@ -3087,7 +3087,7 @@ pub(crate) mod tests { ConnectionView::new( Rc::new(StubAgentServer::new(connection)), connection_store, - ExternalAgent::Custom { + Agent::Custom { name: "Test".into(), }, Some(SessionId::new("session-1")), @@ -3142,7 +3142,7 @@ pub(crate) mod tests { ConnectionView::new( Rc::new(StubAgentServer::new(connection)), connection_store, - ExternalAgent::Custom { + Agent::Custom { name: "Test".into(), }, Some(SessionId::new("session-1")), @@ -3197,7 +3197,7 @@ pub(crate) mod tests { ConnectionView::new( Rc::new(StubAgentServer::new(connection)), connection_store, - ExternalAgent::Custom { + Agent::Custom { name: "Test".into(), }, Some(SessionId::new("session-1")), @@ -3514,7 +3514,7 @@ pub(crate) mod tests { ConnectionView::new( Rc::new(agent), connection_store, - ExternalAgent::Custom { + Agent::Custom { name: "Test".into(), }, None, @@ -3729,7 +3729,7 @@ pub(crate) mod tests { let connection_store = cx.update(|_window, cx| cx.new(|cx| AgentConnectionStore::new(project.clone(), cx))); - let agent_key = ExternalAgent::Custom { + let agent_key = Agent::Custom { name: "Test".into(), }; @@ -4479,7 +4479,7 @@ pub(crate) mod tests { ConnectionView::new( Rc::new(StubAgentServer::new(connection.as_ref().clone())), connection_store, - ExternalAgent::Custom { + Agent::Custom { name: "Test".into(), }, None, diff --git a/crates/agent_ui/src/inline_assistant.rs b/crates/agent_ui/src/inline_assistant.rs index 8fde876183db385c019e6ccb1f2e5a0d4b121892..1fc66f6079fa146440a1f5a594d9f160e4580ab2 100644 --- a/crates/agent_ui/src/inline_assistant.rs +++ b/crates/agent_ui/src/inline_assistant.rs @@ -281,7 +281,7 @@ impl InlineAssistant { let Some(history) = agent_panel .connection_store() .read(cx) - .entry(&crate::ExternalAgent::NativeAgent) + .entry(&crate::Agent::NativeAgent) .and_then(|s| s.read(cx).history().cloned()) else { log::error!("No connection entry found for native agent"); @@ -1981,7 +1981,7 @@ impl CodeActionProvider for AssistantCodeActionProvider { let history = panel .connection_store() .read(cx) - .entry(&crate::ExternalAgent::NativeAgent) + .entry(&crate::Agent::NativeAgent) .and_then(|e| e.read(cx).history()) .context("no history found for native agent")? .downgrade();