1mod configure_context_server_modal;
2mod manage_profiles_modal;
3mod tool_picker;
4
5use std::{sync::Arc, time::Duration};
6
7use agent_settings::AgentSettings;
8use assistant_tool::{ToolSource, ToolWorkingSet};
9use collections::HashMap;
10use context_server::ContextServerId;
11use extension::ExtensionManifest;
12use extension_host::ExtensionStore;
13use fs::Fs;
14use gpui::{
15 Action, Animation, AnimationExt as _, AnyView, App, Corner, Entity, EventEmitter, FocusHandle,
16 Focusable, ScrollHandle, Subscription, Task, Transformation, WeakEntity, percentage,
17};
18use language::LanguageRegistry;
19use language_model::{LanguageModelProvider, LanguageModelProviderId, LanguageModelRegistry};
20use notifications::status_toast::{StatusToast, ToastIcon};
21use project::{
22 context_server_store::{ContextServerConfiguration, ContextServerStatus, ContextServerStore},
23 project_settings::ProjectSettings,
24};
25use settings::{Settings, update_settings_file};
26use ui::{
27 ContextMenu, Disclosure, ElevationIndex, Indicator, PopoverMenu, Scrollbar, ScrollbarState,
28 Switch, SwitchColor, Tooltip, prelude::*,
29};
30use util::ResultExt as _;
31use workspace::Workspace;
32use zed_actions::ExtensionCategoryFilter;
33
34pub(crate) use configure_context_server_modal::ConfigureContextServerModal;
35pub(crate) use manage_profiles_modal::ManageProfilesModal;
36
37use crate::AddContextServer;
38
39pub struct AgentConfiguration {
40 fs: Arc<dyn Fs>,
41 language_registry: Arc<LanguageRegistry>,
42 workspace: WeakEntity<Workspace>,
43 focus_handle: FocusHandle,
44 configuration_views_by_provider: HashMap<LanguageModelProviderId, AnyView>,
45 context_server_store: Entity<ContextServerStore>,
46 expanded_context_server_tools: HashMap<ContextServerId, bool>,
47 expanded_provider_configurations: HashMap<LanguageModelProviderId, bool>,
48 tools: Entity<ToolWorkingSet>,
49 _registry_subscription: Subscription,
50 scroll_handle: ScrollHandle,
51 scrollbar_state: ScrollbarState,
52}
53
54impl AgentConfiguration {
55 pub fn new(
56 fs: Arc<dyn Fs>,
57 context_server_store: Entity<ContextServerStore>,
58 tools: Entity<ToolWorkingSet>,
59 language_registry: Arc<LanguageRegistry>,
60 workspace: WeakEntity<Workspace>,
61 window: &mut Window,
62 cx: &mut Context<Self>,
63 ) -> Self {
64 let focus_handle = cx.focus_handle();
65
66 let registry_subscription = cx.subscribe_in(
67 &LanguageModelRegistry::global(cx),
68 window,
69 |this, _, event: &language_model::Event, window, cx| match event {
70 language_model::Event::AddedProvider(provider_id) => {
71 let provider = LanguageModelRegistry::read_global(cx).provider(provider_id);
72 if let Some(provider) = provider {
73 this.add_provider_configuration_view(&provider, window, cx);
74 }
75 }
76 language_model::Event::RemovedProvider(provider_id) => {
77 this.remove_provider_configuration_view(provider_id);
78 }
79 _ => {}
80 },
81 );
82
83 cx.subscribe(&context_server_store, |_, _, _, cx| cx.notify())
84 .detach();
85
86 let scroll_handle = ScrollHandle::new();
87 let scrollbar_state = ScrollbarState::new(scroll_handle.clone());
88
89 let mut this = Self {
90 fs,
91 language_registry,
92 workspace,
93 focus_handle,
94 configuration_views_by_provider: HashMap::default(),
95 context_server_store,
96 expanded_context_server_tools: HashMap::default(),
97 expanded_provider_configurations: HashMap::default(),
98 tools,
99 _registry_subscription: registry_subscription,
100 scroll_handle,
101 scrollbar_state,
102 };
103 this.build_provider_configuration_views(window, cx);
104 this
105 }
106
107 fn build_provider_configuration_views(&mut self, window: &mut Window, cx: &mut Context<Self>) {
108 let providers = LanguageModelRegistry::read_global(cx).providers();
109 for provider in providers {
110 self.add_provider_configuration_view(&provider, window, cx);
111 }
112 }
113
114 fn remove_provider_configuration_view(&mut self, provider_id: &LanguageModelProviderId) {
115 self.configuration_views_by_provider.remove(provider_id);
116 self.expanded_provider_configurations.remove(provider_id);
117 }
118
119 fn add_provider_configuration_view(
120 &mut self,
121 provider: &Arc<dyn LanguageModelProvider>,
122 window: &mut Window,
123 cx: &mut Context<Self>,
124 ) {
125 let configuration_view = provider.configuration_view(window, cx);
126 self.configuration_views_by_provider
127 .insert(provider.id(), configuration_view);
128 }
129}
130
131impl Focusable for AgentConfiguration {
132 fn focus_handle(&self, _: &App) -> FocusHandle {
133 self.focus_handle.clone()
134 }
135}
136
137pub enum AssistantConfigurationEvent {
138 NewThread(Arc<dyn LanguageModelProvider>),
139}
140
141impl EventEmitter<AssistantConfigurationEvent> for AgentConfiguration {}
142
143impl AgentConfiguration {
144 fn render_provider_configuration_block(
145 &mut self,
146 provider: &Arc<dyn LanguageModelProvider>,
147 cx: &mut Context<Self>,
148 ) -> impl IntoElement + use<> {
149 let provider_id = provider.id().0.clone();
150 let provider_name = provider.name().0.clone();
151 let configuration_view = self
152 .configuration_views_by_provider
153 .get(&provider.id())
154 .cloned();
155
156 let is_expanded = self
157 .expanded_provider_configurations
158 .get(&provider.id())
159 .copied()
160 .unwrap_or(false);
161
162 v_flex()
163 .pt_3()
164 .gap_1p5()
165 .border_t_1()
166 .border_color(cx.theme().colors().border.opacity(0.6))
167 .child(
168 h_flex()
169 .justify_between()
170 .child(
171 h_flex()
172 .gap_2()
173 .child(
174 Icon::new(provider.icon())
175 .size(IconSize::Small)
176 .color(Color::Muted),
177 )
178 .child(Label::new(provider_name.clone()).size(LabelSize::Large))
179 .when(provider.is_authenticated(cx) && !is_expanded, |parent| {
180 parent.child(Icon::new(IconName::Check).color(Color::Success))
181 }),
182 )
183 .child(
184 h_flex()
185 .gap_1()
186 .when(provider.is_authenticated(cx), |parent| {
187 parent.child(
188 Button::new(
189 SharedString::from(format!("new-thread-{provider_id}")),
190 "Start New Thread",
191 )
192 .icon_position(IconPosition::Start)
193 .icon(IconName::Plus)
194 .icon_size(IconSize::Small)
195 .layer(ElevationIndex::ModalSurface)
196 .label_size(LabelSize::Small)
197 .on_click(cx.listener({
198 let provider = provider.clone();
199 move |_this, _event, _window, cx| {
200 cx.emit(AssistantConfigurationEvent::NewThread(
201 provider.clone(),
202 ))
203 }
204 })),
205 )
206 })
207 .child(
208 Disclosure::new(
209 SharedString::from(format!(
210 "provider-disclosure-{provider_id}"
211 )),
212 is_expanded,
213 )
214 .opened_icon(IconName::ChevronUp)
215 .closed_icon(IconName::ChevronDown)
216 .on_click(cx.listener({
217 let provider_id = provider.id().clone();
218 move |this, _event, _window, _cx| {
219 let is_expanded = this
220 .expanded_provider_configurations
221 .entry(provider_id.clone())
222 .or_insert(false);
223
224 *is_expanded = !*is_expanded;
225 }
226 })),
227 ),
228 ),
229 )
230 .when(is_expanded, |parent| match configuration_view {
231 Some(configuration_view) => parent.child(configuration_view),
232 None => parent.child(Label::new(format!(
233 "No configuration view for {provider_name}",
234 ))),
235 })
236 }
237
238 fn render_provider_configuration_section(
239 &mut self,
240 cx: &mut Context<Self>,
241 ) -> impl IntoElement {
242 let providers = LanguageModelRegistry::read_global(cx).providers();
243
244 v_flex()
245 .p(DynamicSpacing::Base16.rems(cx))
246 .pr(DynamicSpacing::Base20.rems(cx))
247 .gap_4()
248 .border_b_1()
249 .border_color(cx.theme().colors().border)
250 .child(
251 v_flex()
252 .gap_0p5()
253 .child(Headline::new("LLM Providers"))
254 .child(
255 Label::new("Add at least one provider to use AI-powered features.")
256 .color(Color::Muted),
257 ),
258 )
259 .children(
260 providers
261 .into_iter()
262 .map(|provider| self.render_provider_configuration_block(&provider, cx)),
263 )
264 }
265
266 fn render_command_permission(&mut self, cx: &mut Context<Self>) -> impl IntoElement {
267 let always_allow_tool_actions = AgentSettings::get_global(cx).always_allow_tool_actions;
268
269 h_flex()
270 .gap_4()
271 .justify_between()
272 .flex_wrap()
273 .child(
274 v_flex()
275 .gap_0p5()
276 .max_w_5_6()
277 .child(Label::new("Allow running editing tools without asking for confirmation"))
278 .child(
279 Label::new(
280 "The agent can perform potentially destructive actions without asking for your confirmation.",
281 )
282 .color(Color::Muted),
283 ),
284 )
285 .child(
286 Switch::new(
287 "always-allow-tool-actions-switch",
288 always_allow_tool_actions.into(),
289 )
290 .color(SwitchColor::Accent)
291 .on_click({
292 let fs = self.fs.clone();
293 move |state, _window, cx| {
294 let allow = state == &ToggleState::Selected;
295 update_settings_file::<AgentSettings>(
296 fs.clone(),
297 cx,
298 move |settings, _| {
299 settings.set_always_allow_tool_actions(allow);
300 },
301 );
302 }
303 }),
304 )
305 }
306
307 fn render_single_file_review(&mut self, cx: &mut Context<Self>) -> impl IntoElement {
308 let single_file_review = AgentSettings::get_global(cx).single_file_review;
309
310 h_flex()
311 .gap_4()
312 .justify_between()
313 .flex_wrap()
314 .child(
315 v_flex()
316 .gap_0p5()
317 .max_w_5_6()
318 .child(Label::new("Enable single-file agent reviews"))
319 .child(
320 Label::new(
321 "Agent edits are also displayed in single-file editors for review.",
322 )
323 .color(Color::Muted),
324 ),
325 )
326 .child(
327 Switch::new("single-file-review-switch", single_file_review.into())
328 .color(SwitchColor::Accent)
329 .on_click({
330 let fs = self.fs.clone();
331 move |state, _window, cx| {
332 let allow = state == &ToggleState::Selected;
333 update_settings_file::<AgentSettings>(
334 fs.clone(),
335 cx,
336 move |settings, _| {
337 settings.set_single_file_review(allow);
338 },
339 );
340 }
341 }),
342 )
343 }
344
345 fn render_sound_notification(&mut self, cx: &mut Context<Self>) -> impl IntoElement {
346 let play_sound_when_agent_done = AgentSettings::get_global(cx).play_sound_when_agent_done;
347
348 h_flex()
349 .gap_4()
350 .justify_between()
351 .flex_wrap()
352 .child(
353 v_flex()
354 .gap_0p5()
355 .max_w_5_6()
356 .child(Label::new("Play sound when finished generating"))
357 .child(
358 Label::new(
359 "Hear a notification sound when the agent is done generating changes or needs your input.",
360 )
361 .color(Color::Muted),
362 ),
363 )
364 .child(
365 Switch::new("play-sound-notification-switch", play_sound_when_agent_done.into())
366 .color(SwitchColor::Accent)
367 .on_click({
368 let fs = self.fs.clone();
369 move |state, _window, cx| {
370 let allow = state == &ToggleState::Selected;
371 update_settings_file::<AgentSettings>(
372 fs.clone(),
373 cx,
374 move |settings, _| {
375 settings.set_play_sound_when_agent_done(allow);
376 },
377 );
378 }
379 }),
380 )
381 }
382
383 fn render_general_settings_section(&mut self, cx: &mut Context<Self>) -> impl IntoElement {
384 v_flex()
385 .p(DynamicSpacing::Base16.rems(cx))
386 .pr(DynamicSpacing::Base20.rems(cx))
387 .gap_2p5()
388 .border_b_1()
389 .border_color(cx.theme().colors().border)
390 .child(Headline::new("General Settings"))
391 .child(self.render_command_permission(cx))
392 .child(self.render_single_file_review(cx))
393 .child(self.render_sound_notification(cx))
394 }
395
396 fn render_context_servers_section(
397 &mut self,
398 window: &mut Window,
399 cx: &mut Context<Self>,
400 ) -> impl IntoElement {
401 let context_server_ids = self.context_server_store.read(cx).all_server_ids().clone();
402
403 v_flex()
404 .p(DynamicSpacing::Base16.rems(cx))
405 .pr(DynamicSpacing::Base20.rems(cx))
406 .gap_2()
407 .border_b_1()
408 .border_color(cx.theme().colors().border)
409 .child(
410 v_flex()
411 .gap_0p5()
412 .child(Headline::new("Model Context Protocol (MCP) Servers"))
413 .child(Label::new("Connect to context servers via the Model Context Protocol either via Zed extensions or directly.").color(Color::Muted)),
414 )
415 .children(
416 context_server_ids.into_iter().map(|context_server_id| {
417 self.render_context_server(context_server_id, window, cx)
418 }),
419 )
420 .child(
421 h_flex()
422 .justify_between()
423 .gap_2()
424 .child(
425 h_flex().w_full().child(
426 Button::new("add-context-server", "Add Custom Server")
427 .style(ButtonStyle::Filled)
428 .layer(ElevationIndex::ModalSurface)
429 .full_width()
430 .icon(IconName::Plus)
431 .icon_size(IconSize::Small)
432 .icon_position(IconPosition::Start)
433 .on_click(|_event, window, cx| {
434 window.dispatch_action(AddContextServer.boxed_clone(), cx)
435 }),
436 ),
437 )
438 .child(
439 h_flex().w_full().child(
440 Button::new(
441 "install-context-server-extensions",
442 "Install MCP Extensions",
443 )
444 .style(ButtonStyle::Filled)
445 .layer(ElevationIndex::ModalSurface)
446 .full_width()
447 .icon(IconName::Hammer)
448 .icon_size(IconSize::Small)
449 .icon_position(IconPosition::Start)
450 .on_click(|_event, window, cx| {
451 window.dispatch_action(
452 zed_actions::Extensions {
453 category_filter: Some(
454 ExtensionCategoryFilter::ContextServers,
455 ),
456 }
457 .boxed_clone(),
458 cx,
459 )
460 }),
461 ),
462 ),
463 )
464 }
465
466 fn render_context_server(
467 &self,
468 context_server_id: ContextServerId,
469 window: &mut Window,
470 cx: &mut Context<Self>,
471 ) -> impl use<> + IntoElement {
472 let tools_by_source = self.tools.read(cx).tools_by_source(cx);
473 let server_status = self
474 .context_server_store
475 .read(cx)
476 .status_for_server(&context_server_id)
477 .unwrap_or(ContextServerStatus::Stopped);
478 let server_configuration = self
479 .context_server_store
480 .read(cx)
481 .configuration_for_server(&context_server_id);
482
483 let is_running = matches!(server_status, ContextServerStatus::Running);
484 let item_id = SharedString::from(context_server_id.0.clone());
485 let is_from_extension = server_configuration
486 .as_ref()
487 .map(|config| {
488 matches!(
489 config.as_ref(),
490 ContextServerConfiguration::Extension { .. }
491 )
492 })
493 .unwrap_or(false);
494
495 let error = if let ContextServerStatus::Error(error) = server_status.clone() {
496 Some(error)
497 } else {
498 None
499 };
500
501 let are_tools_expanded = self
502 .expanded_context_server_tools
503 .get(&context_server_id)
504 .copied()
505 .unwrap_or_default();
506 let tools = tools_by_source
507 .get(&ToolSource::ContextServer {
508 id: context_server_id.0.clone().into(),
509 })
510 .map_or([].as_slice(), |tools| tools.as_slice());
511 let tool_count = tools.len();
512
513 let border_color = cx.theme().colors().border.opacity(0.6);
514
515 let (source_icon, source_tooltip) = if is_from_extension {
516 (
517 IconName::ZedMcpExtension,
518 "This MCP server was installed from an extension.",
519 )
520 } else {
521 (
522 IconName::ZedMcpCustom,
523 "This custom MCP server was installed directly.",
524 )
525 };
526
527 let (status_indicator, tooltip_text) = match server_status {
528 ContextServerStatus::Starting => (
529 Icon::new(IconName::LoadCircle)
530 .size(IconSize::XSmall)
531 .color(Color::Accent)
532 .with_animation(
533 SharedString::from(format!("{}-starting", context_server_id.0.clone(),)),
534 Animation::new(Duration::from_secs(3)).repeat(),
535 |icon, delta| icon.transform(Transformation::rotate(percentage(delta))),
536 )
537 .into_any_element(),
538 "Server is starting.",
539 ),
540 ContextServerStatus::Running => (
541 Indicator::dot().color(Color::Success).into_any_element(),
542 "Server is active.",
543 ),
544 ContextServerStatus::Error(_) => (
545 Indicator::dot().color(Color::Error).into_any_element(),
546 "Server has an error.",
547 ),
548 ContextServerStatus::Stopped => (
549 Indicator::dot().color(Color::Muted).into_any_element(),
550 "Server is stopped.",
551 ),
552 };
553
554 let context_server_configuration_menu = PopoverMenu::new("context-server-config-menu")
555 .trigger_with_tooltip(
556 IconButton::new("context-server-config-menu", IconName::Settings)
557 .icon_color(Color::Muted)
558 .icon_size(IconSize::Small),
559 Tooltip::text("Open MCP server options"),
560 )
561 .anchor(Corner::TopRight)
562 .menu({
563 let fs = self.fs.clone();
564 let context_server_id = context_server_id.clone();
565 let language_registry = self.language_registry.clone();
566 let context_server_store = self.context_server_store.clone();
567 let workspace = self.workspace.clone();
568 move |window, cx| {
569 Some(ContextMenu::build(window, cx, |menu, _window, _cx| {
570 menu.entry("Configure Server", None, {
571 let context_server_id = context_server_id.clone();
572 let language_registry = language_registry.clone();
573 let workspace = workspace.clone();
574 move |window, cx| {
575 ConfigureContextServerModal::show_modal_for_existing_server(
576 context_server_id.clone(),
577 language_registry.clone(),
578 workspace.clone(),
579 window,
580 cx,
581 )
582 .detach_and_log_err(cx);
583 }
584 })
585 .separator()
586 .entry("Delete", None, {
587 let fs = fs.clone();
588 let context_server_id = context_server_id.clone();
589 let context_server_store = context_server_store.clone();
590 let workspace = workspace.clone();
591 move |_, cx| {
592 let is_provided_by_extension = context_server_store
593 .read(cx)
594 .configuration_for_server(&context_server_id)
595 .as_ref()
596 .map(|config| {
597 matches!(
598 config.as_ref(),
599 ContextServerConfiguration::Extension { .. }
600 )
601 })
602 .unwrap_or(false);
603
604 let uninstall_extension_task = match (
605 is_provided_by_extension,
606 resolve_extension_for_context_server(&context_server_id, cx),
607 ) {
608 (true, Some((id, manifest))) => {
609 if extension_only_provides_context_server(manifest.as_ref())
610 {
611 ExtensionStore::global(cx).update(cx, |store, cx| {
612 store.uninstall_extension(id, cx)
613 })
614 } else {
615 workspace.update(cx, |workspace, cx| {
616 show_unable_to_uninstall_extension_with_context_server(workspace, context_server_id.clone(), cx);
617 }).log_err();
618 Task::ready(Ok(()))
619 }
620 }
621 _ => Task::ready(Ok(())),
622 };
623
624 cx.spawn({
625 let fs = fs.clone();
626 let context_server_id = context_server_id.clone();
627 async move |cx| {
628 uninstall_extension_task.await?;
629 cx.update(|cx| {
630 update_settings_file::<ProjectSettings>(
631 fs.clone(),
632 cx,
633 {
634 let context_server_id =
635 context_server_id.clone();
636 move |settings, _| {
637 settings
638 .context_servers
639 .remove(&context_server_id.0);
640 }
641 },
642 )
643 })
644 }
645 })
646 .detach_and_log_err(cx);
647 }
648 })
649 }))
650 }
651 });
652
653 v_flex()
654 .id(item_id.clone())
655 .border_1()
656 .rounded_md()
657 .border_color(border_color)
658 .bg(cx.theme().colors().background.opacity(0.2))
659 .overflow_hidden()
660 .child(
661 h_flex()
662 .p_1()
663 .justify_between()
664 .when(
665 error.is_some() || are_tools_expanded && tool_count >= 1,
666 |element| element.border_b_1().border_color(border_color),
667 )
668 .child(
669 h_flex()
670 .child(
671 Disclosure::new(
672 "tool-list-disclosure",
673 are_tools_expanded || error.is_some(),
674 )
675 .disabled(tool_count == 0)
676 .on_click(cx.listener({
677 let context_server_id = context_server_id.clone();
678 move |this, _event, _window, _cx| {
679 let is_open = this
680 .expanded_context_server_tools
681 .entry(context_server_id.clone())
682 .or_insert(false);
683
684 *is_open = !*is_open;
685 }
686 })),
687 )
688 .child(
689 h_flex()
690 .id(SharedString::from(format!("tooltip-{}", item_id)))
691 .h_full()
692 .w_3()
693 .mx_1()
694 .justify_center()
695 .tooltip(Tooltip::text(tooltip_text))
696 .child(status_indicator),
697 )
698 .child(Label::new(item_id).ml_0p5())
699 .child(
700 div()
701 .id("extension-source")
702 .mt_0p5()
703 .mx_1()
704 .tooltip(Tooltip::text(source_tooltip))
705 .child(
706 Icon::new(source_icon)
707 .size(IconSize::Small)
708 .color(Color::Muted),
709 ),
710 )
711 .when(is_running, |this| {
712 this.child(
713 Label::new(if tool_count == 1 {
714 SharedString::from("1 tool")
715 } else {
716 SharedString::from(format!("{} tools", tool_count))
717 })
718 .color(Color::Muted)
719 .size(LabelSize::Small),
720 )
721 }),
722 )
723 .child(
724 h_flex()
725 .gap_1()
726 .child(context_server_configuration_menu)
727 .child(
728 Switch::new("context-server-switch", is_running.into())
729 .color(SwitchColor::Accent)
730 .on_click({
731 let context_server_manager =
732 self.context_server_store.clone();
733 let context_server_id = context_server_id.clone();
734
735 move |state, _window, cx| match state {
736 ToggleState::Unselected
737 | ToggleState::Indeterminate => {
738 context_server_manager.update(cx, |this, cx| {
739 this.stop_server(&context_server_id, cx)
740 .log_err();
741 });
742 }
743 ToggleState::Selected => {
744 context_server_manager.update(cx, |this, cx| {
745 if let Some(server) =
746 this.get_server(&context_server_id)
747 {
748 this.start_server(server, cx);
749 }
750 })
751 }
752 }
753 }),
754 ),
755 ),
756 )
757 .map(|parent| {
758 if let Some(error) = error {
759 return parent.child(
760 h_flex()
761 .p_2()
762 .gap_2()
763 .items_start()
764 .child(
765 h_flex()
766 .flex_none()
767 .h(window.line_height() / 1.6_f32)
768 .justify_center()
769 .child(
770 Icon::new(IconName::XCircle)
771 .size(IconSize::XSmall)
772 .color(Color::Error),
773 ),
774 )
775 .child(
776 div().w_full().child(
777 Label::new(error)
778 .buffer_font(cx)
779 .color(Color::Muted)
780 .size(LabelSize::Small),
781 ),
782 ),
783 );
784 }
785
786 if !are_tools_expanded || tools.is_empty() {
787 return parent;
788 }
789
790 parent.child(v_flex().py_1p5().px_1().gap_1().children(
791 tools.into_iter().enumerate().map(|(ix, tool)| {
792 h_flex()
793 .id(("tool-item", ix))
794 .px_1()
795 .gap_2()
796 .justify_between()
797 .hover(|style| style.bg(cx.theme().colors().element_hover))
798 .rounded_sm()
799 .child(
800 Label::new(tool.name())
801 .buffer_font(cx)
802 .size(LabelSize::Small),
803 )
804 .child(
805 Icon::new(IconName::Info)
806 .size(IconSize::Small)
807 .color(Color::Ignored),
808 )
809 .tooltip(Tooltip::text(tool.description()))
810 }),
811 ))
812 })
813 }
814}
815
816impl Render for AgentConfiguration {
817 fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
818 v_flex()
819 .id("assistant-configuration")
820 .key_context("AgentConfiguration")
821 .track_focus(&self.focus_handle(cx))
822 .relative()
823 .size_full()
824 .pb_8()
825 .bg(cx.theme().colors().panel_background)
826 .child(
827 v_flex()
828 .id("assistant-configuration-content")
829 .track_scroll(&self.scroll_handle)
830 .size_full()
831 .overflow_y_scroll()
832 .child(self.render_general_settings_section(cx))
833 .child(self.render_context_servers_section(window, cx))
834 .child(self.render_provider_configuration_section(cx)),
835 )
836 .child(
837 div()
838 .id("assistant-configuration-scrollbar")
839 .occlude()
840 .absolute()
841 .right(px(3.))
842 .top_0()
843 .bottom_0()
844 .pb_6()
845 .w(px(12.))
846 .cursor_default()
847 .on_mouse_move(cx.listener(|_, _, _window, cx| {
848 cx.notify();
849 cx.stop_propagation()
850 }))
851 .on_hover(|_, _window, cx| {
852 cx.stop_propagation();
853 })
854 .on_any_mouse_down(|_, _window, cx| {
855 cx.stop_propagation();
856 })
857 .on_scroll_wheel(cx.listener(|_, _, _window, cx| {
858 cx.notify();
859 }))
860 .children(Scrollbar::vertical(self.scrollbar_state.clone())),
861 )
862 }
863}
864
865fn extension_only_provides_context_server(manifest: &ExtensionManifest) -> bool {
866 manifest.context_servers.len() == 1
867 && manifest.themes.is_empty()
868 && manifest.icon_themes.is_empty()
869 && manifest.languages.is_empty()
870 && manifest.grammars.is_empty()
871 && manifest.language_servers.is_empty()
872 && manifest.slash_commands.is_empty()
873 && manifest.indexed_docs_providers.is_empty()
874 && manifest.snippets.is_none()
875 && manifest.debug_locators.is_empty()
876}
877
878pub(crate) fn resolve_extension_for_context_server(
879 id: &ContextServerId,
880 cx: &App,
881) -> Option<(Arc<str>, Arc<ExtensionManifest>)> {
882 ExtensionStore::global(cx)
883 .read(cx)
884 .installed_extensions()
885 .iter()
886 .find(|(_, entry)| entry.manifest.context_servers.contains_key(&id.0))
887 .map(|(id, entry)| (id.clone(), entry.manifest.clone()))
888}
889
890// This notification appears when trying to delete
891// an MCP server extension that not only provides
892// the server, but other things, too, like language servers and more.
893fn show_unable_to_uninstall_extension_with_context_server(
894 workspace: &mut Workspace,
895 id: ContextServerId,
896 cx: &mut App,
897) {
898 let status_toast = StatusToast::new(
899 format!(
900 "Unable to uninstall the {} extension, as it provides more than just the MCP server.",
901 id.0
902 ),
903 cx,
904 |this, _cx| {
905 this.icon(ToastIcon::new(IconName::Warning).color(Color::Warning))
906 .action("Dismiss", |_, _| {})
907 },
908 );
909
910 workspace.toggle_status_toast(status_toast, cx);
911}