agent_ui.rs

  1mod agent_configuration;
  2pub(crate) mod agent_connection_store;
  3mod agent_diff;
  4mod agent_model_selector;
  5mod agent_panel;
  6mod agent_registry_ui;
  7mod branch_names;
  8mod buffer_codegen;
  9mod completion_provider;
 10mod config_options;
 11mod context;
 12mod context_server_configuration;
 13pub(crate) mod conversation_view;
 14mod entry_view_state;
 15mod external_source_prompt;
 16mod favorite_models;
 17mod inline_assistant;
 18mod inline_prompt_editor;
 19mod language_model_selector;
 20mod mention_set;
 21mod message_editor;
 22mod mode_selector;
 23mod model_selector;
 24mod model_selector_popover;
 25mod profile_selector;
 26mod slash_command;
 27mod slash_command_picker;
 28mod terminal_codegen;
 29mod terminal_inline_assistant;
 30#[cfg(any(test, feature = "test-support"))]
 31pub mod test_support;
 32mod text_thread_editor;
 33mod text_thread_history;
 34mod thread_history;
 35mod thread_history_view;
 36mod thread_metadata_store;
 37mod threads_archive_view;
 38mod threads_panel;
 39mod ui;
 40
 41use std::rc::Rc;
 42use std::sync::Arc;
 43
 44use agent_client_protocol as acp;
 45use agent_settings::{AgentProfileId, AgentSettings};
 46use assistant_slash_command::SlashCommandRegistry;
 47use client::Client;
 48use command_palette_hooks::CommandPaletteFilter;
 49use feature_flags::{AgentV2FeatureFlag, FeatureFlagAppExt as _};
 50use fs::Fs;
 51use gpui::{Action, App, Context, Entity, SharedString, Window, actions};
 52use language::{
 53    LanguageRegistry,
 54    language_settings::{AllLanguageSettings, EditPredictionProvider},
 55};
 56use language_model::{
 57    ConfiguredModel, LanguageModelId, LanguageModelProviderId, LanguageModelRegistry,
 58};
 59use project::{AgentId, DisableAiSettings};
 60use prompt_store::PromptBuilder;
 61use schemars::JsonSchema;
 62use serde::{Deserialize, Serialize};
 63use settings::{LanguageModelSelection, Settings as _, SettingsStore};
 64use std::any::TypeId;
 65use workspace::Workspace;
 66
 67use crate::agent_configuration::{ConfigureContextServerModal, ManageProfilesModal};
 68pub use crate::agent_panel::{
 69    AgentPanel, AgentPanelEvent, ConcreteAssistantPanelDelegate, WorktreeCreationStatus,
 70};
 71use crate::agent_registry_ui::AgentRegistryPage;
 72pub use crate::inline_assistant::InlineAssistant;
 73pub use agent_diff::{AgentDiffPane, AgentDiffToolbar};
 74pub(crate) use conversation_view::ConversationView;
 75pub use external_source_prompt::ExternalSourcePrompt;
 76pub(crate) use mode_selector::ModeSelector;
 77pub(crate) use model_selector::ModelSelector;
 78pub(crate) use model_selector_popover::ModelSelectorPopover;
 79pub use text_thread_editor::{AgentPanelDelegate, TextThreadEditor};
 80pub(crate) use thread_history::ThreadHistory;
 81pub(crate) use thread_history_view::*;
 82pub use threads_panel::ThreadsPanel;
 83use zed_actions;
 84
 85actions!(
 86    agent,
 87    [
 88        /// Creates a new text-based conversation thread.
 89        NewTextThread,
 90        /// Toggles the menu to create new agent threads.
 91        ToggleNewThreadMenu,
 92        /// Cycles through the options for where new threads start (current project or new worktree).
 93        CycleStartThreadIn,
 94        /// Toggles the navigation menu for switching between threads and views.
 95        ToggleNavigationMenu,
 96        /// Toggles the options menu for agent settings and preferences.
 97        ToggleOptionsMenu,
 98        /// Toggles the profile or mode selector for switching between agent profiles.
 99        ToggleProfileSelector,
100        /// Cycles through available session modes.
101        CycleModeSelector,
102        /// Cycles through favorited models in the ACP model selector.
103        CycleFavoriteModels,
104        /// Expands the message editor to full size.
105        ExpandMessageEditor,
106        /// Removes all thread history.
107        RemoveHistory,
108        /// Opens the conversation history view.
109        OpenHistory,
110        /// Adds a context server to the configuration.
111        AddContextServer,
112        /// Removes the currently selected thread.
113        RemoveSelectedThread,
114        /// Starts a chat conversation with follow-up enabled.
115        ChatWithFollow,
116        /// Cycles to the next inline assist suggestion.
117        CycleNextInlineAssist,
118        /// Cycles to the previous inline assist suggestion.
119        CyclePreviousInlineAssist,
120        /// Moves focus up in the interface.
121        FocusUp,
122        /// Moves focus down in the interface.
123        FocusDown,
124        /// Moves focus left in the interface.
125        FocusLeft,
126        /// Moves focus right in the interface.
127        FocusRight,
128        /// Opens the active thread as a markdown file.
129        OpenActiveThreadAsMarkdown,
130        /// Opens the agent diff view to review changes.
131        OpenAgentDiff,
132        /// Copies the current thread to the clipboard as JSON for debugging.
133        CopyThreadToClipboard,
134        /// Loads a thread from the clipboard JSON for debugging.
135        LoadThreadFromClipboard,
136        /// Keeps the current suggestion or change.
137        Keep,
138        /// Rejects the current suggestion or change.
139        Reject,
140        /// Rejects all suggestions or changes.
141        RejectAll,
142        /// Undoes the most recent reject operation, restoring the rejected changes.
143        UndoLastReject,
144        /// Keeps all suggestions or changes.
145        KeepAll,
146        /// Allow this operation only this time.
147        AllowOnce,
148        /// Allow this operation and remember the choice.
149        AllowAlways,
150        /// Reject this operation only this time.
151        RejectOnce,
152        /// Follows the agent's suggestions.
153        Follow,
154        /// Resets the trial upsell notification.
155        ResetTrialUpsell,
156        /// Resets the trial end upsell notification.
157        ResetTrialEndUpsell,
158        /// Opens the "Add Context" menu in the message editor.
159        OpenAddContextMenu,
160        /// Continues the current thread.
161        ContinueThread,
162        /// Interrupts the current generation and sends the message immediately.
163        SendImmediately,
164        /// Sends the next queued message immediately.
165        SendNextQueuedMessage,
166        /// Removes the first message from the queue (the next one to be sent).
167        RemoveFirstQueuedMessage,
168        /// Edits the first message in the queue (the next one to be sent).
169        EditFirstQueuedMessage,
170        /// Clears all messages from the queue.
171        ClearMessageQueue,
172        /// Opens the permission granularity dropdown for the current tool call.
173        OpenPermissionDropdown,
174        /// Toggles thinking mode for models that support extended thinking.
175        ToggleThinkingMode,
176        /// Cycles through available thinking effort levels for the current model.
177        CycleThinkingEffort,
178        /// Toggles the thinking effort selector menu open or closed.
179        ToggleThinkingEffortMenu,
180        /// Toggles fast mode for models that support it.
181        ToggleFastMode,
182    ]
183);
184
185/// Action to authorize a tool call with a specific permission option.
186/// This is used by the permission granularity dropdown to authorize tool calls.
187#[derive(Clone, PartialEq, Deserialize, JsonSchema, Action)]
188#[action(namespace = agent)]
189#[serde(deny_unknown_fields)]
190pub struct AuthorizeToolCall {
191    /// The tool call ID to authorize.
192    pub tool_call_id: String,
193    /// The permission option ID to use.
194    pub option_id: String,
195    /// The kind of permission option (serialized as string).
196    pub option_kind: String,
197}
198
199/// Creates a new conversation thread, optionally based on an existing thread.
200#[derive(Default, Clone, PartialEq, Deserialize, JsonSchema, Action)]
201#[action(namespace = agent)]
202#[serde(deny_unknown_fields)]
203pub struct NewThread;
204
205/// Creates a new external agent conversation thread.
206#[derive(Default, Clone, PartialEq, Deserialize, JsonSchema, Action)]
207#[action(namespace = agent)]
208#[serde(deny_unknown_fields)]
209pub struct NewExternalAgentThread {
210    /// Which agent to use for the conversation.
211    agent: Option<Agent>,
212}
213
214#[derive(Clone, PartialEq, Deserialize, JsonSchema, Action)]
215#[action(namespace = agent)]
216#[serde(deny_unknown_fields)]
217pub struct NewNativeAgentThreadFromSummary {
218    from_session_id: agent_client_protocol::SessionId,
219}
220
221// TODO unify this with AgentType
222#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
223#[serde(rename_all = "snake_case")]
224pub enum Agent {
225    NativeAgent,
226    Custom {
227        #[serde(rename = "name")]
228        id: AgentId,
229    },
230}
231
232impl Agent {
233    pub fn server(
234        &self,
235        fs: Arc<dyn fs::Fs>,
236        thread_store: Entity<agent::ThreadStore>,
237    ) -> Rc<dyn agent_servers::AgentServer> {
238        match self {
239            Self::NativeAgent => Rc::new(agent::NativeAgentServer::new(fs, thread_store)),
240            Self::Custom { id: name } => {
241                Rc::new(agent_servers::CustomAgentServer::new(name.clone()))
242            }
243        }
244    }
245}
246
247/// Sets where new threads will run.
248#[derive(
249    Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema, Action,
250)]
251#[action(namespace = agent)]
252#[serde(rename_all = "snake_case", tag = "kind")]
253pub enum StartThreadIn {
254    #[default]
255    LocalProject,
256    NewWorktree,
257}
258
259/// Content to initialize new external agent with.
260pub enum AgentInitialContent {
261    ThreadSummary {
262        session_id: acp::SessionId,
263        title: Option<SharedString>,
264    },
265    ContentBlock {
266        blocks: Vec<agent_client_protocol::ContentBlock>,
267        auto_submit: bool,
268    },
269    FromExternalSource(ExternalSourcePrompt),
270}
271
272impl From<ExternalSourcePrompt> for AgentInitialContent {
273    fn from(prompt: ExternalSourcePrompt) -> Self {
274        Self::FromExternalSource(prompt)
275    }
276}
277
278/// Opens the profile management interface for configuring agent tools and settings.
279#[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema, Action)]
280#[action(namespace = agent)]
281#[serde(deny_unknown_fields)]
282pub struct ManageProfiles {
283    #[serde(default)]
284    pub customize_tools: Option<AgentProfileId>,
285}
286
287impl ManageProfiles {
288    pub fn customize_tools(profile_id: AgentProfileId) -> Self {
289        Self {
290            customize_tools: Some(profile_id),
291        }
292    }
293}
294
295#[derive(Clone)]
296pub(crate) enum ModelUsageContext {
297    InlineAssistant,
298}
299
300impl ModelUsageContext {
301    pub fn configured_model(&self, cx: &App) -> Option<ConfiguredModel> {
302        match self {
303            Self::InlineAssistant => {
304                LanguageModelRegistry::read_global(cx).inline_assistant_model()
305            }
306        }
307    }
308}
309
310/// Initializes the `agent` crate.
311pub fn init(
312    fs: Arc<dyn Fs>,
313    client: Arc<Client>,
314    prompt_builder: Arc<PromptBuilder>,
315    language_registry: Arc<LanguageRegistry>,
316    is_eval: bool,
317    cx: &mut App,
318) {
319    agent::ThreadStore::init_global(cx);
320    assistant_text_thread::init(client, cx);
321    rules_library::init(cx);
322    if !is_eval {
323        // Initializing the language model from the user settings messes with the eval, so we only initialize them when
324        // we're not running inside of the eval.
325        init_language_model_settings(cx);
326    }
327    assistant_slash_command::init(cx);
328    agent_panel::init(cx);
329    context_server_configuration::init(language_registry.clone(), fs.clone(), cx);
330    TextThreadEditor::init(cx);
331    thread_metadata_store::init(cx);
332
333    register_slash_commands(cx);
334    inline_assistant::init(fs.clone(), prompt_builder.clone(), cx);
335    terminal_inline_assistant::init(fs.clone(), prompt_builder, cx);
336    cx.observe_new(move |workspace, window, cx| {
337        ConfigureContextServerModal::register(workspace, language_registry.clone(), window, cx)
338    })
339    .detach();
340    cx.observe_new(|workspace: &mut Workspace, _window, _cx| {
341        workspace.register_action(
342            move |workspace: &mut Workspace,
343                  _: &zed_actions::AcpRegistry,
344                  window: &mut Window,
345                  cx: &mut Context<Workspace>| {
346                let existing = workspace
347                    .active_pane()
348                    .read(cx)
349                    .items()
350                    .find_map(|item| item.downcast::<AgentRegistryPage>());
351
352                if let Some(existing) = existing {
353                    existing.update(cx, |_, cx| {
354                        project::AgentRegistryStore::global(cx)
355                            .update(cx, |store, cx| store.refresh(cx));
356                    });
357                    workspace.activate_item(&existing, true, true, window, cx);
358                } else {
359                    let registry_page = AgentRegistryPage::new(workspace, window, cx);
360                    workspace.add_item_to_active_pane(
361                        Box::new(registry_page),
362                        None,
363                        true,
364                        window,
365                        cx,
366                    );
367                }
368            },
369        );
370    })
371    .detach();
372    cx.observe_new(ManageProfilesModal::register).detach();
373
374    // Update command palette filter based on AI settings
375    update_command_palette_filter(cx);
376
377    // Watch for settings changes
378    cx.observe_global::<SettingsStore>(|app_cx| {
379        // When settings change, update the command palette filter
380        update_command_palette_filter(app_cx);
381    })
382    .detach();
383
384    cx.on_flags_ready(|_, cx| {
385        update_command_palette_filter(cx);
386    })
387    .detach();
388}
389
390fn update_command_palette_filter(cx: &mut App) {
391    let disable_ai = DisableAiSettings::get_global(cx).disable_ai;
392    let agent_enabled = AgentSettings::get_global(cx).enabled;
393    let agent_v2_enabled = cx.has_flag::<AgentV2FeatureFlag>();
394    let edit_prediction_provider = AllLanguageSettings::get_global(cx)
395        .edit_predictions
396        .provider;
397
398    CommandPaletteFilter::update_global(cx, |filter, _| {
399        use editor::actions::{
400            AcceptEditPrediction, AcceptNextLineEditPrediction, AcceptNextWordEditPrediction,
401            NextEditPrediction, PreviousEditPrediction, ShowEditPrediction, ToggleEditPrediction,
402        };
403        let edit_prediction_actions = [
404            TypeId::of::<AcceptEditPrediction>(),
405            TypeId::of::<AcceptNextWordEditPrediction>(),
406            TypeId::of::<AcceptNextLineEditPrediction>(),
407            TypeId::of::<AcceptEditPrediction>(),
408            TypeId::of::<ShowEditPrediction>(),
409            TypeId::of::<NextEditPrediction>(),
410            TypeId::of::<PreviousEditPrediction>(),
411            TypeId::of::<ToggleEditPrediction>(),
412        ];
413
414        if disable_ai {
415            filter.hide_namespace("agent");
416            filter.hide_namespace("agents");
417            filter.hide_namespace("assistant");
418            filter.hide_namespace("copilot");
419            filter.hide_namespace("zed_predict_onboarding");
420            filter.hide_namespace("edit_prediction");
421
422            filter.hide_action_types(&edit_prediction_actions);
423            filter.hide_action_types(&[TypeId::of::<zed_actions::OpenZedPredictOnboarding>()]);
424        } else {
425            if agent_enabled {
426                filter.show_namespace("agent");
427                filter.show_namespace("agents");
428                filter.show_namespace("assistant");
429            } else {
430                filter.hide_namespace("agent");
431                filter.hide_namespace("agents");
432                filter.hide_namespace("assistant");
433            }
434
435            match edit_prediction_provider {
436                EditPredictionProvider::None => {
437                    filter.hide_namespace("edit_prediction");
438                    filter.hide_namespace("copilot");
439                    filter.hide_action_types(&edit_prediction_actions);
440                }
441                EditPredictionProvider::Copilot => {
442                    filter.show_namespace("edit_prediction");
443                    filter.show_namespace("copilot");
444                    filter.show_action_types(edit_prediction_actions.iter());
445                }
446                EditPredictionProvider::Zed
447                | EditPredictionProvider::Codestral
448                | EditPredictionProvider::Ollama
449                | EditPredictionProvider::OpenAiCompatibleApi
450                | EditPredictionProvider::Sweep
451                | EditPredictionProvider::Mercury
452                | EditPredictionProvider::Experimental(_) => {
453                    filter.show_namespace("edit_prediction");
454                    filter.hide_namespace("copilot");
455                    filter.show_action_types(edit_prediction_actions.iter());
456                }
457            }
458
459            filter.show_namespace("zed_predict_onboarding");
460            filter.show_action_types(&[TypeId::of::<zed_actions::OpenZedPredictOnboarding>()]);
461        }
462
463        if agent_v2_enabled {
464            filter.show_namespace("multi_workspace");
465        } else {
466            filter.hide_namespace("multi_workspace");
467        }
468    });
469}
470
471fn init_language_model_settings(cx: &mut App) {
472    update_active_language_model_from_settings(cx);
473
474    cx.observe_global::<SettingsStore>(update_active_language_model_from_settings)
475        .detach();
476    cx.subscribe(
477        &LanguageModelRegistry::global(cx),
478        |_, event: &language_model::Event, cx| match event {
479            language_model::Event::ProviderStateChanged(_)
480            | language_model::Event::AddedProvider(_)
481            | language_model::Event::RemovedProvider(_)
482            | language_model::Event::ProvidersChanged => {
483                update_active_language_model_from_settings(cx);
484            }
485            _ => {}
486        },
487    )
488    .detach();
489}
490
491fn update_active_language_model_from_settings(cx: &mut App) {
492    let settings = AgentSettings::get_global(cx);
493
494    fn to_selected_model(selection: &LanguageModelSelection) -> language_model::SelectedModel {
495        language_model::SelectedModel {
496            provider: LanguageModelProviderId::from(selection.provider.0.clone()),
497            model: LanguageModelId::from(selection.model.clone()),
498        }
499    }
500
501    let default = settings.default_model.as_ref().map(to_selected_model);
502    let inline_assistant = settings
503        .inline_assistant_model
504        .as_ref()
505        .map(to_selected_model);
506    let commit_message = settings
507        .commit_message_model
508        .as_ref()
509        .map(to_selected_model);
510    let thread_summary = settings
511        .thread_summary_model
512        .as_ref()
513        .map(to_selected_model);
514    let inline_alternatives = settings
515        .inline_alternatives
516        .iter()
517        .map(to_selected_model)
518        .collect::<Vec<_>>();
519
520    LanguageModelRegistry::global(cx).update(cx, |registry, cx| {
521        registry.select_default_model(default.as_ref(), cx);
522        registry.select_inline_assistant_model(inline_assistant.as_ref(), cx);
523        registry.select_commit_message_model(commit_message.as_ref(), cx);
524        registry.select_thread_summary_model(thread_summary.as_ref(), cx);
525        registry.select_inline_alternative_models(inline_alternatives, cx);
526    });
527}
528
529fn register_slash_commands(cx: &mut App) {
530    let slash_command_registry = SlashCommandRegistry::global(cx);
531
532    slash_command_registry.register_command(assistant_slash_commands::FileSlashCommand, true);
533    slash_command_registry.register_command(assistant_slash_commands::DeltaSlashCommand, true);
534    slash_command_registry.register_command(assistant_slash_commands::OutlineSlashCommand, true);
535    slash_command_registry.register_command(assistant_slash_commands::TabSlashCommand, true);
536    slash_command_registry.register_command(assistant_slash_commands::PromptSlashCommand, true);
537    slash_command_registry.register_command(assistant_slash_commands::SelectionCommand, true);
538    slash_command_registry.register_command(assistant_slash_commands::DefaultSlashCommand, false);
539    slash_command_registry.register_command(assistant_slash_commands::NowSlashCommand, false);
540    slash_command_registry
541        .register_command(assistant_slash_commands::DiagnosticsSlashCommand, true);
542    slash_command_registry.register_command(assistant_slash_commands::FetchSlashCommand, true);
543
544    cx.observe_flag::<assistant_slash_commands::StreamingExampleSlashCommandFeatureFlag, _>({
545        move |is_enabled, _cx| {
546            if is_enabled {
547                slash_command_registry.register_command(
548                    assistant_slash_commands::StreamingExampleSlashCommand,
549                    false,
550                );
551            }
552        }
553    })
554    .detach();
555}
556
557#[cfg(test)]
558mod tests {
559    use super::*;
560    use agent_settings::{AgentProfileId, AgentSettings};
561    use command_palette_hooks::CommandPaletteFilter;
562    use editor::actions::AcceptEditPrediction;
563    use gpui::{BorrowAppContext, TestAppContext, px};
564    use project::DisableAiSettings;
565    use settings::{
566        DefaultAgentView, DockPosition, NotifyWhenAgentWaiting, Settings, SettingsStore,
567    };
568
569    #[gpui::test]
570    fn test_agent_command_palette_visibility(cx: &mut TestAppContext) {
571        // Init settings
572        cx.update(|cx| {
573            let store = SettingsStore::test(cx);
574            cx.set_global(store);
575            command_palette_hooks::init(cx);
576            AgentSettings::register(cx);
577            DisableAiSettings::register(cx);
578            AllLanguageSettings::register(cx);
579        });
580
581        let agent_settings = AgentSettings {
582            enabled: true,
583            button: true,
584            dock: DockPosition::Right,
585            default_width: px(300.),
586            default_height: px(600.),
587            default_model: None,
588            inline_assistant_model: None,
589            inline_assistant_use_streaming_tools: false,
590            commit_message_model: None,
591            thread_summary_model: None,
592            inline_alternatives: vec![],
593            favorite_models: vec![],
594            default_profile: AgentProfileId::default(),
595            default_view: DefaultAgentView::Thread,
596            profiles: Default::default(),
597
598            notify_when_agent_waiting: NotifyWhenAgentWaiting::default(),
599            play_sound_when_agent_done: false,
600            single_file_review: false,
601            model_parameters: vec![],
602            enable_feedback: false,
603            expand_edit_card: true,
604            expand_terminal_card: true,
605            cancel_generation_on_terminal_stop: true,
606            use_modifier_to_send: true,
607            message_editor_min_lines: 1,
608            tool_permissions: Default::default(),
609            show_turn_stats: false,
610            new_thread_location: Default::default(),
611        };
612
613        cx.update(|cx| {
614            AgentSettings::override_global(agent_settings.clone(), cx);
615            DisableAiSettings::override_global(DisableAiSettings { disable_ai: false }, cx);
616
617            // Initial update
618            update_command_palette_filter(cx);
619        });
620
621        // Assert visible
622        cx.update(|cx| {
623            let filter = CommandPaletteFilter::try_global(cx).unwrap();
624            assert!(
625                !filter.is_hidden(&NewThread),
626                "NewThread should be visible by default"
627            );
628            assert!(
629                !filter.is_hidden(&text_thread_editor::CopyCode),
630                "CopyCode should be visible when agent is enabled"
631            );
632        });
633
634        // Disable agent
635        cx.update(|cx| {
636            let mut new_settings = agent_settings.clone();
637            new_settings.enabled = false;
638            AgentSettings::override_global(new_settings, cx);
639
640            // Trigger update
641            update_command_palette_filter(cx);
642        });
643
644        // Assert hidden
645        cx.update(|cx| {
646            let filter = CommandPaletteFilter::try_global(cx).unwrap();
647            assert!(
648                filter.is_hidden(&NewThread),
649                "NewThread should be hidden when agent is disabled"
650            );
651            assert!(
652                filter.is_hidden(&text_thread_editor::CopyCode),
653                "CopyCode should be hidden when agent is disabled"
654            );
655        });
656
657        // Test EditPredictionProvider
658        // Enable EditPredictionProvider::Copilot
659        cx.update(|cx| {
660            cx.update_global::<SettingsStore, _>(|store, cx| {
661                store.update_user_settings(cx, |s| {
662                    s.project
663                        .all_languages
664                        .edit_predictions
665                        .get_or_insert(Default::default())
666                        .provider = Some(EditPredictionProvider::Copilot);
667                });
668            });
669            update_command_palette_filter(cx);
670        });
671
672        cx.update(|cx| {
673            let filter = CommandPaletteFilter::try_global(cx).unwrap();
674            assert!(
675                !filter.is_hidden(&AcceptEditPrediction),
676                "EditPrediction should be visible when provider is Copilot"
677            );
678        });
679
680        // Disable EditPredictionProvider (None)
681        cx.update(|cx| {
682            cx.update_global::<SettingsStore, _>(|store, cx| {
683                store.update_user_settings(cx, |s| {
684                    s.project
685                        .all_languages
686                        .edit_predictions
687                        .get_or_insert(Default::default())
688                        .provider = Some(EditPredictionProvider::None);
689                });
690            });
691            update_command_palette_filter(cx);
692        });
693
694        cx.update(|cx| {
695            let filter = CommandPaletteFilter::try_global(cx).unwrap();
696            assert!(
697                filter.is_hidden(&AcceptEditPrediction),
698                "EditPrediction should be hidden when provider is None"
699            );
700        });
701    }
702
703    #[test]
704    fn test_deserialize_external_agent_variants() {
705        assert_eq!(
706            serde_json::from_str::<Agent>(r#""native_agent""#).unwrap(),
707            Agent::NativeAgent,
708        );
709        assert_eq!(
710            serde_json::from_str::<Agent>(r#"{"custom":{"name":"my-agent"}}"#).unwrap(),
711            Agent::Custom {
712                id: "my-agent".into(),
713            },
714        );
715    }
716}