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