pub mod acp;mod agent_configuration;mod agent_diff;mod agent_model_selector;mod agent_panel;mod agent_registry_ui;mod buffer_codegen;mod completion_provider;mod context;mod context_server_configuration;mod favorite_models;mod inline_assistant;mod inline_prompt_editor;mod language_model_selector;mod mention_set;mod profile_selector;mod slash_command;mod slash_command_picker;mod terminal_codegen;mod terminal_inline_assistant;mod text_thread_editor;mod text_thread_history;mod ui; use std::rc::Rc;use std::sync::Arc; // Another commentuse agent_settings::{AgentProfileId, AgentSettings};use assistant_slash_command::SlashCommandRegistry;use client::Client;use command_palette_hooks::CommandPaletteFilter;use feature_flags::{AgentV2FeatureFlag, FeatureFlagAppExt as _};use fs::Fs;use gpui::{Action, App, Context, Entity, SharedString, Window, actions};use language::{ LanguageRegistry, language_settings::{AllLanguageSettings, EditPredictionProvider},};use language_model::{ ConfiguredModel, LanguageModelId, LanguageModelProviderId, LanguageModelRegistry,};use project::DisableAiSettings;use prompt_store::PromptBuilder;use schemars::JsonSchema;use serde::{Deserialize, Serialize};use settings::{LanguageModelSelection, Settings as _, SettingsStore};use std::any::TypeId;use workspace::Workspace; use crate::agent_configuration::{ConfigureContextServerModal, ManageProfilesModal};pub use crate::agent_panel::{AgentPanel, AgentPanelEvent, ConcreteAssistantPanelDelegate};use crate::agent_registry_ui::AgentRegistryPage;pub use crate::inline_assistant::InlineAssistant;pub use agent_diff::{AgentDiffPane, AgentDiffToolbar};pub use text_thread_editor::{AgentPanelDelegate, TextThreadEditor};use zed_actions; actions!( agent, [ /// Creates a new text-based conversation thread. NewTextThread, /// Toggles the menu to create new agent threads. ToggleNewThreadMenu, /// Toggles the navigation menu for switching between threads and views. ToggleNavigationMenu, /// Toggles the options menu for agent settings and preferences. ToggleOptionsMenu, /// Toggles the profile or mode selector for switching between agent profiles. ToggleProfileSelector, /// Cycles through available session modes. CycleModeSelector, /// Cycles through favorited models in the ACP model selector. CycleFavoriteModels, /// Expands the message editor to full size. ExpandMessageEditor, /// Removes all thread history. RemoveHistory, /// Opens the conversation history view. OpenHistory, /// Adds a context server to the configuration. AddContextServer, /// Removes the currently selected thread. RemoveSelectedThread, /// Starts a chat conversation with follow-up enabled. ChatWithFollow, /// Cycles to the next inline assist suggestion. CycleNextInlineAssist, /// Cycles to the previous inline assist suggestion. CyclePreviousInlineAssist, /// Moves focus up in the interface. FocusUp, /// Moves focus down in the interface. FocusDown, /// Moves focus left in the interface. FocusLeft, /// Moves focus right in the interface. FocusRight, /// Opens the active thread as a markdown file. OpenActiveThreadAsMarkdown, /// Opens the agent diff view to review changes. OpenAgentDiff, /// Copies the current thread to the clipboard as JSON for debugging. CopyThreadToClipboard, /// Loads a thread from the clipboard JSON for debugging. LoadThreadFromClipboard, /// Keeps the current suggestion or change. Keep, /// Rejects the current suggestion or change. Reject, /// Rejects all suggestions or changes. RejectAll, /// Undoes the most recent reject operation, restoring the rejected changes. UndoLastReject, /// Keeps all suggestions or changes. KeepAll, /// Allow this operation only this time. AllowOnce, /// Allow this operation and remember the choice. AllowAlways, /// Reject this operation only this time. RejectOnce, /// Follows the agent's suggestions. Follow, /// Resets the trial upsell notification. ResetTrialUpsell, /// Resets the trial end upsell notification. ResetTrialEndUpsell, /// Opens the "Add Context" menu in the message editor. OpenAddContextMenu, /// Continues the current thread. ContinueThread, /// Interrupts the current generation and sends the message immediately. SendImmediately, /// Sends the next queued message immediately. SendNextQueuedMessage, /// Removes the first message from the queue (the next one to be sent). RemoveFirstQueuedMessage, /// Edits the first message in the queue (the next one to be sent). EditFirstQueuedMessage, /// Clears all messages from the queue. ClearMessageQueue, /// Opens the permission granularity dropdown for the current tool call. OpenPermissionDropdown, /// Toggles thinking mode for models that support extended thinking. ToggleThinkingMode, /// Cycles through available thinking effort levels for the current model. CycleThinkingEffort, /// Toggles the thinking effort selector menu open or closed. ToggleThinkingEffortMenu, ]); /// Action to authorize a tool call with a specific permission option./// This is used by the permission granularity dropdown to authorize tool calls.#[derive(Clone, PartialEq, Deserialize, JsonSchema, Action)]#[action(namespace = agent)]#[serde(deny_unknown_fields)]pub struct AuthorizeToolCall { /// The tool call ID to authorize. pub tool_call_id: String, /// The permission option ID to use. pub option_id: String, /// The kind of permission option (serialized as string). pub option_kind: String,} /// Action to select a permission granularity option from the dropdown./// This updates the selected granularity without triggering authorization.#[derive(Clone, PartialEq, Deserialize, JsonSchema, Action)]#[action(namespace = agent)]#[serde(deny_unknown_fields)]pub struct SelectPermissionGranularity { /// The tool call ID for which to select the granularity. pub tool_call_id: String, /// The index of the selected granularity option. pub index: usize,} /// Creates a new conversation thread, optionally based on an existing thread.#[derive(Default, Clone, PartialEq, Deserialize, JsonSchema, Action)]#[action(namespace = agent)]#[serde(deny_unknown_fields)]pub struct NewThread; /// Creates a new external agent conversation thread.#[derive(Default, Clone, PartialEq, Deserialize, JsonSchema, Action)]#[action(namespace = agent)]#[serde(deny_unknown_fields)]pub struct NewExternalAgentThread { /// Which agent to use for the conversation. agent: Option<ExternalAgent>,} #[derive(Clone, PartialEq, Deserialize, JsonSchema, Action)]#[action(namespace = agent)]#[serde(deny_unknown_fields)]pub struct NewNativeAgentThreadFromSummary { from_session_id: agent_client_protocol::SessionId,} // TODO unify this with AgentType#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]#[serde(rename_all = "snake_case")]pub enum ExternalAgent { Gemini, ClaudeCode, Codex, NativeAgent, Custom { name: SharedString },} impl ExternalAgent { pub fn server( &self, fs: Arc<dyn fs::Fs>, thread_store: Entity<agent::ThreadStore>, ) -> Rc<dyn agent_servers::AgentServer> { match self { Self::Gemini => Rc::new(agent_servers::Gemini), Self::ClaudeCode => Rc::new(agent_servers::ClaudeCode), Self::Codex => Rc::new(agent_servers::Codex), Self::NativeAgent => Rc::new(agent::NativeAgentServer::new(fs, thread_store)), Self::Custom { name } => Rc::new(agent_servers::CustomAgentServer::new(name.clone())), } }} /// Content to initialize new external agent with.pub enum AgentInitialContent { ThreadSummary(acp_thread::AgentSessionInfo), ContentBlock { blocks: Vec<agent_client_protocol::ContentBlock>, auto_submit: bool, },} /// Opens the profile management interface for configuring agent tools and settings.#[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema, Action)]#[action(namespace = agent)]#[serde(deny_unknown_fields)]pub struct ManageProfiles { #[serde(default)] pub customize_tools: Option<AgentProfileId>,} impl ManageProfiles { pub fn customize_tools(profile_id: AgentProfileId) -> Self { Self { customize_tools: Some(profile_id), } }} #[derive(Clone)]pub(crate) enum ModelUsageContext { InlineAssistant,} impl ModelUsageContext { pub fn configured_model(&self, cx: &App) -> Option<ConfiguredModel> { match self { Self::InlineAssistant => { LanguageModelRegistry::read_global(cx).inline_assistant_model() } } }} /// Initializes the `agent` crate.pub fn init( fs: Arc<dyn Fs>, client: Arc<Client>, prompt_builder: Arc<PromptBuilder>, language_registry: Arc<LanguageRegistry>, is_eval: bool, cx: &mut App,) { agent::ThreadStore::init_global(cx); assistant_text_thread::init(client, cx); rules_library::init(cx); if !is_eval { // Initializing the language model from the user settings messes with the eval, so we only initialize them when // we're not running inside of the eval. init_language_model_settings(cx); } assistant_slash_command::init(cx); agent_panel::init(cx); context_server_configuration::init(language_registry.clone(), fs.clone(), cx); TextThreadEditor::init(cx); register_slash_commands(cx); inline_assistant::init(fs.clone(), prompt_builder.clone(), cx); terminal_inline_assistant::init(fs.clone(), prompt_builder, cx); cx.observe_new(move |workspace, window, cx| { ConfigureContextServerModal::register(workspace, language_registry.clone(), window, cx) }) .detach(); cx.observe_new(|workspace: &mut Workspace, _window, _cx| { workspace.register_action( move |workspace: &mut Workspace, _: &zed_actions::AcpRegistry, window: &mut Window, cx: &mut Context<Workspace>| { let existing = workspace .active_pane() .read(cx) .items() .find_map(|item| item.downcast::<AgentRegistryPage>()); if let Some(existing) = existing { workspace.activate_item(&existing, true, true, window, cx); } else { let registry_page = AgentRegistryPage::new(workspace, window, cx); workspace.add_item_to_active_pane( Box::new(registry_page), None, true, window, cx, ); } }, ); }) .detach(); cx.observe_new(ManageProfilesModal::register).detach(); // Update command palette filter based on AI settings update_command_palette_filter(cx); // Watch for settings changes cx.observe_global::<SettingsStore>(|app_cx| { // When settings change, update the command palette filter update_command_palette_filter(app_cx); }) .detach(); cx.on_flags_ready(|_, cx| { update_command_palette_filter(cx); }) .detach();} fn update_command_palette_filter(cx: &mut App) { let disable_ai = DisableAiSettings::get_global(cx).disable_ai; let agent_enabled = AgentSettings::get_global(cx).enabled; let agent_v2_enabled = cx.has_flag::<AgentV2FeatureFlag>(); let edit_prediction_provider = AllLanguageSettings::get_global(cx) .edit_predictions .provider; CommandPaletteFilter::update_global(cx, |filter, _| { use editor::actions::{ AcceptEditPrediction, AcceptNextLineEditPrediction, AcceptNextWordEditPrediction, NextEditPrediction, PreviousEditPrediction, ShowEditPrediction, ToggleEditPrediction, }; let edit_prediction_actions = [ TypeId::of::<AcceptEditPrediction>(), TypeId::of::<AcceptNextWordEditPrediction>(), TypeId::of::<AcceptNextLineEditPrediction>(), TypeId::of::<AcceptEditPrediction>(), TypeId::of::<ShowEditPrediction>(), TypeId::of::<NextEditPrediction>(), TypeId::of::<PreviousEditPrediction>(), TypeId::of::<ToggleEditPrediction>(), ]; if disable_ai { filter.hide_namespace("agent"); filter.hide_namespace("agents"); filter.hide_namespace("assistant"); filter.hide_namespace("copilot"); filter.hide_namespace("supermaven"); filter.hide_namespace("zed_predict_onboarding"); filter.hide_namespace("edit_prediction"); filter.hide_action_types(&edit_prediction_actions); filter.hide_action_types(&[TypeId::of::<zed_actions::OpenZedPredictOnboarding>()]); } else { if agent_enabled { filter.show_namespace("agent"); filter.show_namespace("agents"); filter.show_namespace("assistant"); } else { filter.hide_namespace("agent"); filter.hide_namespace("agents"); filter.hide_namespace("assistant"); } match edit_prediction_provider { EditPredictionProvider::None => { filter.hide_namespace("edit_prediction"); filter.hide_namespace("copilot"); filter.hide_namespace("supermaven"); filter.hide_action_types(&edit_prediction_actions); } EditPredictionProvider::Copilot => { filter.show_namespace("edit_prediction"); filter.show_namespace("copilot"); filter.hide_namespace("supermaven"); filter.show_action_types(edit_prediction_actions.iter()); } EditPredictionProvider::Supermaven => { filter.show_namespace("edit_prediction"); filter.hide_namespace("copilot"); filter.show_namespace("supermaven"); filter.show_action_types(edit_prediction_actions.iter()); } EditPredictionProvider::Zed | EditPredictionProvider::Codestral | EditPredictionProvider::Ollama | EditPredictionProvider::OpenAiCompatibleApi | EditPredictionProvider::Sweep | EditPredictionProvider::Mercury | EditPredictionProvider::Experimental(_) => { filter.show_namespace("edit_prediction"); filter.hide_namespace("copilot"); filter.hide_namespace("supermaven"); filter.show_action_types(edit_prediction_actions.iter()); } } filter.show_namespace("zed_predict_onboarding"); filter.show_action_types(&[TypeId::of::<zed_actions::OpenZedPredictOnboarding>()]); } if agent_v2_enabled { filter.show_namespace("multi_workspace"); } else { filter.hide_namespace("multi_workspace"); } });} fn init_language_model_settings(cx: &mut App) { update_active_language_model_from_settings(cx); cx.observe_global::<SettingsStore>(update_active_language_model_from_settings) .detach(); cx.subscribe( &LanguageModelRegistry::global(cx), |_, event: &language_model::Event, cx| match event { language_model::Event::ProviderStateChanged(_) | language_model::Event::AddedProvider(_) | language_model::Event::RemovedProvider(_) | language_model::Event::ProvidersChanged => { update_active_language_model_from_settings(cx); } _ => {} }, ) .detach();} fn update_active_language_model_from_settings(cx: &mut App) { let settings = AgentSettings::get_global(cx); fn to_selected_model(selection: &LanguageModelSelection) -> language_model::SelectedModel { language_model::SelectedModel { provider: LanguageModelProviderId::from(selection.provider.0.clone()), model: LanguageModelId::from(selection.model.clone()), } } let default = settings.default_model.as_ref().map(to_selected_model); let inline_assistant = settings .inline_assistant_model .as_ref() .map(to_selected_model); let commit_message = settings .commit_message_model .as_ref() .map(to_selected_model); let thread_summary = settings .thread_summary_model .as_ref() .map(to_selected_model); let inline_alternatives = settings .inline_alternatives .iter() .map(to_selected_model) .collect::<Vec<_>>(); LanguageModelRegistry::global(cx).update(cx, |registry, cx| { registry.select_default_model(default.as_ref(), cx); registry.select_inline_assistant_model(inline_assistant.as_ref(), cx); registry.select_commit_message_model(commit_message.as_ref(), cx); registry.select_thread_summary_model(thread_summary.as_ref(), cx); registry.select_inline_alternative_models(inline_alternatives, cx); });} fn register_slash_commands(cx: &mut App) { let slash_command_registry = SlashCommandRegistry::global(cx); slash_command_registry.register_command(assistant_slash_commands::FileSlashCommand, true); slash_command_registry.register_command(assistant_slash_commands::DeltaSlashCommand, true); slash_command_registry.register_command(assistant_slash_commands::OutlineSlashCommand, true);Lines 1–500 of 667. Load more
pub mod acp; mod agent_configuration; mod agent_diff; mod agent_model_selector; mod agent_panel; mod agent_registry_ui; mod buffer_codegen; mod completion_provider; mod context; mod context_server_configuration; mod favorite_models; mod inline_assistant; mod inline_prompt_editor; mod language_model_selector; mod mention_set; mod profile_selector; mod slash_command; mod slash_command_picker; mod terminal_codegen; mod terminal_inline_assistant; mod text_thread_editor; mod text_thread_history; mod ui; use std::rc::Rc; use std::sync::Arc; // Another comment use agent_settings::{AgentProfileId, AgentSettings}; use assistant_slash_command::SlashCommandRegistry; use client::Client; use command_palette_hooks::CommandPaletteFilter; use feature_flags::{AgentV2FeatureFlag, FeatureFlagAppExt as _}; use fs::Fs; use gpui::{Action, App, Context, Entity, SharedString, Window, actions}; use language::{ LanguageRegistry, language_settings::{AllLanguageSettings, EditPredictionProvider}, }; use language_model::{ ConfiguredModel, LanguageModelId, LanguageModelProviderId, LanguageModelRegistry, }; use project::DisableAiSettings; use prompt_store::PromptBuilder; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; use settings::{LanguageModelSelection, Settings as _, SettingsStore}; use std::any::TypeId; use workspace::Workspace; use crate::agent_configuration::{ConfigureContextServerModal, ManageProfilesModal}; pub use crate::agent_panel::{AgentPanel, AgentPanelEvent, ConcreteAssistantPanelDelegate}; use crate::agent_registry_ui::AgentRegistryPage; pub use crate::inline_assistant::InlineAssistant; pub use agent_diff::{AgentDiffPane, AgentDiffToolbar}; pub use text_thread_editor::{AgentPanelDelegate, TextThreadEditor}; use zed_actions; actions!( agent, [ /// Creates a new text-based conversation thread. NewTextThread, /// Toggles the menu to create new agent threads. ToggleNewThreadMenu, /// Toggles the navigation menu for switching between threads and views. ToggleNavigationMenu, /// Toggles the options menu for agent settings and preferences. ToggleOptionsMenu, /// Toggles the profile or mode selector for switching between agent profiles. ToggleProfileSelector, /// Cycles through available session modes. CycleModeSelector, /// Cycles through favorited models in the ACP model selector. CycleFavoriteModels, /// Expands the message editor to full size. ExpandMessageEditor, /// Removes all thread history. RemoveHistory, /// Opens the conversation history view. OpenHistory, /// Adds a context server to the configuration. AddContextServer, /// Removes the currently selected thread. RemoveSelectedThread, /// Starts a chat conversation with follow-up enabled. ChatWithFollow, /// Cycles to the next inline assist suggestion. CycleNextInlineAssist, /// Cycles to the previous inline assist suggestion. CyclePreviousInlineAssist, /// Moves focus up in the interface. FocusUp, /// Moves focus down in the interface. FocusDown, /// Moves focus left in the interface. FocusLeft, /// Moves focus right in the interface. FocusRight, /// Opens the active thread as a markdown file. OpenActiveThreadAsMarkdown, /// Opens the agent diff view to review changes. OpenAgentDiff, /// Copies the current thread to the clipboard as JSON for debugging. CopyThreadToClipboard, /// Loads a thread from the clipboard JSON for debugging. LoadThreadFromClipboard, /// Keeps the current suggestion or change. Keep, /// Rejects the current suggestion or change. Reject, /// Rejects all suggestions or changes. RejectAll, /// Undoes the most recent reject operation, restoring the rejected changes. UndoLastReject, /// Keeps all suggestions or changes. KeepAll, /// Allow this operation only this time. AllowOnce, /// Allow this operation and remember the choice. AllowAlways, /// Reject this operation only this time. RejectOnce, /// Follows the agent's suggestions. Follow, /// Resets the trial upsell notification. ResetTrialUpsell, /// Resets the trial end upsell notification. ResetTrialEndUpsell, /// Opens the "Add Context" menu in the message editor. OpenAddContextMenu, /// Continues the current thread. ContinueThread, /// Interrupts the current generation and sends the message immediately. SendImmediately, /// Sends the next queued message immediately. SendNextQueuedMessage, /// Removes the first message from the queue (the next one to be sent). RemoveFirstQueuedMessage, /// Edits the first message in the queue (the next one to be sent). EditFirstQueuedMessage, /// Clears all messages from the queue. ClearMessageQueue, /// Opens the permission granularity dropdown for the current tool call. OpenPermissionDropdown, /// Toggles thinking mode for models that support extended thinking. ToggleThinkingMode, /// Cycles through available thinking effort levels for the current model. CycleThinkingEffort, /// Toggles the thinking effort selector menu open or closed. ToggleThinkingEffortMenu, ] ); /// Action to authorize a tool call with a specific permission option. /// This is used by the permission granularity dropdown to authorize tool calls. #[derive(Clone, PartialEq, Deserialize, JsonSchema, Action)] #[action(namespace = agent)] #[serde(deny_unknown_fields)] pub struct AuthorizeToolCall { /// The tool call ID to authorize. pub tool_call_id: String, /// The permission option ID to use. pub option_id: String, /// The kind of permission option (serialized as string). pub option_kind: String, } /// Action to select a permission granularity option from the dropdown. /// This updates the selected granularity without triggering authorization. #[derive(Clone, PartialEq, Deserialize, JsonSchema, Action)] #[action(namespace = agent)] #[serde(deny_unknown_fields)] pub struct SelectPermissionGranularity { /// The tool call ID for which to select the granularity. pub tool_call_id: String, /// The index of the selected granularity option. pub index: usize, } /// Creates a new conversation thread, optionally based on an existing thread. #[derive(Default, Clone, PartialEq, Deserialize, JsonSchema, Action)] #[action(namespace = agent)] #[serde(deny_unknown_fields)] pub struct NewThread; /// Creates a new external agent conversation thread. #[derive(Default, Clone, PartialEq, Deserialize, JsonSchema, Action)] #[action(namespace = agent)] #[serde(deny_unknown_fields)] pub struct NewExternalAgentThread { /// Which agent to use for the conversation. agent: Option<ExternalAgent>, } #[derive(Clone, PartialEq, Deserialize, JsonSchema, Action)] #[action(namespace = agent)] #[serde(deny_unknown_fields)] pub struct NewNativeAgentThreadFromSummary { from_session_id: agent_client_protocol::SessionId, } // TODO unify this with AgentType #[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)] #[serde(rename_all = "snake_case")] pub enum ExternalAgent { Gemini, ClaudeCode, Codex, NativeAgent, Custom { name: SharedString }, } impl ExternalAgent { pub fn server( &self, fs: Arc<dyn fs::Fs>, thread_store: Entity<agent::ThreadStore>, ) -> Rc<dyn agent_servers::AgentServer> { match self { Self::Gemini => Rc::new(agent_servers::Gemini), Self::ClaudeCode => Rc::new(agent_servers::ClaudeCode), Self::Codex => Rc::new(agent_servers::Codex), Self::NativeAgent => Rc::new(agent::NativeAgentServer::new(fs, thread_store)), Self::Custom { name } => Rc::new(agent_servers::CustomAgentServer::new(name.clone())), } } } /// Content to initialize new external agent with. pub enum AgentInitialContent { ThreadSummary(acp_thread::AgentSessionInfo), ContentBlock { blocks: Vec<agent_client_protocol::ContentBlock>, auto_submit: bool, }, } /// Opens the profile management interface for configuring agent tools and settings. #[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema, Action)] #[action(namespace = agent)] #[serde(deny_unknown_fields)] pub struct ManageProfiles { #[serde(default)] pub customize_tools: Option<AgentProfileId>, } impl ManageProfiles { pub fn customize_tools(profile_id: AgentProfileId) -> Self { Self { customize_tools: Some(profile_id), } } } #[derive(Clone)] pub(crate) enum ModelUsageContext { InlineAssistant, } impl ModelUsageContext { pub fn configured_model(&self, cx: &App) -> Option<ConfiguredModel> { match self { Self::InlineAssistant => { LanguageModelRegistry::read_global(cx).inline_assistant_model() } } } } /// Initializes the `agent` crate. pub fn init( fs: Arc<dyn Fs>, client: Arc<Client>, prompt_builder: Arc<PromptBuilder>, language_registry: Arc<LanguageRegistry>, is_eval: bool, cx: &mut App, ) { agent::ThreadStore::init_global(cx); assistant_text_thread::init(client, cx); rules_library::init(cx); if !is_eval { // Initializing the language model from the user settings messes with the eval, so we only initialize them when // we're not running inside of the eval. init_language_model_settings(cx); } assistant_slash_command::init(cx); agent_panel::init(cx); context_server_configuration::init(language_registry.clone(), fs.clone(), cx); TextThreadEditor::init(cx); register_slash_commands(cx); inline_assistant::init(fs.clone(), prompt_builder.clone(), cx); terminal_inline_assistant::init(fs.clone(), prompt_builder, cx); cx.observe_new(move |workspace, window, cx| { ConfigureContextServerModal::register(workspace, language_registry.clone(), window, cx) }) .detach(); cx.observe_new(|workspace: &mut Workspace, _window, _cx| { workspace.register_action( move |workspace: &mut Workspace, _: &zed_actions::AcpRegistry, window: &mut Window, cx: &mut Context<Workspace>| { let existing = workspace .active_pane() .read(cx) .items() .find_map(|item| item.downcast::<AgentRegistryPage>()); if let Some(existing) = existing { workspace.activate_item(&existing, true, true, window, cx); } else { let registry_page = AgentRegistryPage::new(workspace, window, cx); workspace.add_item_to_active_pane( Box::new(registry_page), None, true, window, cx, ); } }, ); }) .detach(); cx.observe_new(ManageProfilesModal::register).detach(); // Update command palette filter based on AI settings update_command_palette_filter(cx); // Watch for settings changes cx.observe_global::<SettingsStore>(|app_cx| { // When settings change, update the command palette filter update_command_palette_filter(app_cx); }) .detach(); cx.on_flags_ready(|_, cx| { update_command_palette_filter(cx); }) .detach(); } fn update_command_palette_filter(cx: &mut App) { let disable_ai = DisableAiSettings::get_global(cx).disable_ai; let agent_enabled = AgentSettings::get_global(cx).enabled; let agent_v2_enabled = cx.has_flag::<AgentV2FeatureFlag>(); let edit_prediction_provider = AllLanguageSettings::get_global(cx) .edit_predictions .provider; CommandPaletteFilter::update_global(cx, |filter, _| { use editor::actions::{ AcceptEditPrediction, AcceptNextLineEditPrediction, AcceptNextWordEditPrediction, NextEditPrediction, PreviousEditPrediction, ShowEditPrediction, ToggleEditPrediction, }; let edit_prediction_actions = [ TypeId::of::<AcceptEditPrediction>(), TypeId::of::<AcceptNextWordEditPrediction>(), TypeId::of::<AcceptNextLineEditPrediction>(), TypeId::of::<AcceptEditPrediction>(), TypeId::of::<ShowEditPrediction>(), TypeId::of::<NextEditPrediction>(), TypeId::of::<PreviousEditPrediction>(), TypeId::of::<ToggleEditPrediction>(), ]; if disable_ai { filter.hide_namespace("agent"); filter.hide_namespace("agents"); filter.hide_namespace("assistant"); filter.hide_namespace("copilot"); filter.hide_namespace("supermaven"); filter.hide_namespace("zed_predict_onboarding"); filter.hide_namespace("edit_prediction"); filter.hide_action_types(&edit_prediction_actions); filter.hide_action_types(&[TypeId::of::<zed_actions::OpenZedPredictOnboarding>()]); } else { if agent_enabled { filter.show_namespace("agent"); filter.show_namespace("agents"); filter.show_namespace("assistant"); } else { filter.hide_namespace("agent"); filter.hide_namespace("agents"); filter.hide_namespace("assistant"); } match edit_prediction_provider { EditPredictionProvider::None => { filter.hide_namespace("edit_prediction"); filter.hide_namespace("copilot"); filter.hide_namespace("supermaven"); filter.hide_action_types(&edit_prediction_actions); } EditPredictionProvider::Copilot => { filter.show_namespace("edit_prediction"); filter.show_namespace("copilot"); filter.hide_namespace("supermaven"); filter.show_action_types(edit_prediction_actions.iter()); } EditPredictionProvider::Supermaven => { filter.show_namespace("edit_prediction"); filter.hide_namespace("copilot"); filter.show_namespace("supermaven"); filter.show_action_types(edit_prediction_actions.iter()); } EditPredictionProvider::Zed | EditPredictionProvider::Codestral | EditPredictionProvider::Ollama | EditPredictionProvider::OpenAiCompatibleApi | EditPredictionProvider::Sweep | EditPredictionProvider::Mercury | EditPredictionProvider::Experimental(_) => { filter.show_namespace("edit_prediction"); filter.hide_namespace("copilot"); filter.hide_namespace("supermaven"); filter.show_action_types(edit_prediction_actions.iter()); } } filter.show_namespace("zed_predict_onboarding"); filter.show_action_types(&[TypeId::of::<zed_actions::OpenZedPredictOnboarding>()]); } if agent_v2_enabled { filter.show_namespace("multi_workspace"); } else { filter.hide_namespace("multi_workspace"); } }); } fn init_language_model_settings(cx: &mut App) { update_active_language_model_from_settings(cx); cx.observe_global::<SettingsStore>(update_active_language_model_from_settings) .detach(); cx.subscribe( &LanguageModelRegistry::global(cx), |_, event: &language_model::Event, cx| match event { language_model::Event::ProviderStateChanged(_) | language_model::Event::AddedProvider(_) | language_model::Event::RemovedProvider(_) | language_model::Event::ProvidersChanged => { update_active_language_model_from_settings(cx); } _ => {} }, ) .detach(); } fn update_active_language_model_from_settings(cx: &mut App) { let settings = AgentSettings::get_global(cx); fn to_selected_model(selection: &LanguageModelSelection) -> language_model::SelectedModel { language_model::SelectedModel { provider: LanguageModelProviderId::from(selection.provider.0.clone()), model: LanguageModelId::from(selection.model.clone()), } } let default = settings.default_model.as_ref().map(to_selected_model); let inline_assistant = settings .inline_assistant_model .as_ref() .map(to_selected_model); let commit_message = settings .commit_message_model .as_ref() .map(to_selected_model); let thread_summary = settings .thread_summary_model .as_ref() .map(to_selected_model); let inline_alternatives = settings .inline_alternatives .iter() .map(to_selected_model) .collect::<Vec<_>>(); LanguageModelRegistry::global(cx).update(cx, |registry, cx| { registry.select_default_model(default.as_ref(), cx); registry.select_inline_assistant_model(inline_assistant.as_ref(), cx); registry.select_commit_message_model(commit_message.as_ref(), cx); registry.select_thread_summary_model(thread_summary.as_ref(), cx); registry.select_inline_alternative_models(inline_alternatives, cx); }); } fn register_slash_commands(cx: &mut App) { let slash_command_registry = SlashCommandRegistry::global(cx); slash_command_registry.register_command(assistant_slash_commands::FileSlashCommand, true); slash_command_registry.register_command(assistant_slash_commands::DeltaSlashCommand, true); slash_command_registry.register_command(assistant_slash_commands::OutlineSlashCommand, true);