acp_onboarding_modal.rs

  1use gpui::{
  2    ClickEvent, DismissEvent, Entity, EventEmitter, FocusHandle, Focusable, MouseDownEvent, Render,
  3    linear_color_stop, linear_gradient,
  4};
  5use project::agent_server_store::GEMINI_NAME;
  6use ui::{TintColor, Vector, VectorName, prelude::*};
  7use workspace::{ModalView, Workspace};
  8
  9use crate::agent_panel::{AgentPanel, AgentType};
 10
 11macro_rules! acp_onboarding_event {
 12    ($name:expr) => {
 13        telemetry::event!($name, source = "ACP Onboarding");
 14    };
 15    ($name:expr, $($key:ident $(= $value:expr)?),+ $(,)?) => {
 16        telemetry::event!($name, source = "ACP Onboarding", $($key $(= $value)?),+);
 17    };
 18}
 19
 20pub struct AcpOnboardingModal {
 21    focus_handle: FocusHandle,
 22    workspace: Entity<Workspace>,
 23}
 24
 25impl AcpOnboardingModal {
 26    pub fn toggle(workspace: &mut Workspace, window: &mut Window, cx: &mut Context<Workspace>) {
 27        let workspace_entity = cx.entity();
 28        workspace.toggle_modal(window, cx, |_window, cx| Self {
 29            workspace: workspace_entity,
 30            focus_handle: cx.focus_handle(),
 31        });
 32    }
 33
 34    fn open_panel(&mut self, _: &ClickEvent, window: &mut Window, cx: &mut Context<Self>) {
 35        self.workspace.update(cx, |workspace, cx| {
 36            workspace.focus_panel::<AgentPanel>(window, cx);
 37
 38            if let Some(panel) = workspace.panel::<AgentPanel>(cx) {
 39                panel.update(cx, |panel, cx| {
 40                    panel.new_agent_thread(
 41                        AgentType::Custom {
 42                            name: GEMINI_NAME.into(),
 43                        },
 44                        window,
 45                        cx,
 46                    );
 47                });
 48            }
 49        });
 50
 51        cx.emit(DismissEvent);
 52
 53        acp_onboarding_event!("Open Panel Clicked");
 54    }
 55
 56    fn open_agent_registry(&mut self, _: &ClickEvent, window: &mut Window, cx: &mut Context<Self>) {
 57        window.dispatch_action(Box::new(zed_actions::AcpRegistry), cx);
 58        cx.notify();
 59
 60        acp_onboarding_event!("Open Agent Registry Clicked");
 61    }
 62
 63    fn cancel(&mut self, _: &menu::Cancel, _: &mut Window, cx: &mut Context<Self>) {
 64        cx.emit(DismissEvent);
 65    }
 66}
 67
 68impl EventEmitter<DismissEvent> for AcpOnboardingModal {}
 69
 70impl Focusable for AcpOnboardingModal {
 71    fn focus_handle(&self, _cx: &App) -> FocusHandle {
 72        self.focus_handle.clone()
 73    }
 74}
 75
 76impl ModalView for AcpOnboardingModal {}
 77
 78impl Render for AcpOnboardingModal {
 79    fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
 80        let illustration_element = |label: bool, opacity: f32| {
 81            h_flex()
 82                .px_1()
 83                .py_0p5()
 84                .gap_1()
 85                .rounded_sm()
 86                .bg(cx.theme().colors().element_active.opacity(0.05))
 87                .border_1()
 88                .border_color(cx.theme().colors().border)
 89                .border_dashed()
 90                .child(
 91                    Icon::new(IconName::Stop)
 92                        .size(IconSize::Small)
 93                        .color(Color::Custom(cx.theme().colors().text_muted.opacity(0.15))),
 94                )
 95                .map(|this| {
 96                    if label {
 97                        this.child(
 98                            Label::new("Your Agent Here")
 99                                .size(LabelSize::Small)
100                                .color(Color::Muted),
101                        )
102                    } else {
103                        this.child(
104                            div().w_16().h_1().rounded_full().bg(cx
105                                .theme()
106                                .colors()
107                                .element_active
108                                .opacity(0.6)),
109                        )
110                    }
111                })
112                .opacity(opacity)
113        };
114
115        let illustration = h_flex()
116            .relative()
117            .h(rems_from_px(126.))
118            .bg(cx.theme().colors().editor_background)
119            .border_b_1()
120            .border_color(cx.theme().colors().border_variant)
121            .justify_center()
122            .gap_8()
123            .rounded_t_md()
124            .overflow_hidden()
125            .child(
126                div().absolute().inset_0().w(px(515.)).h(px(126.)).child(
127                    Vector::new(VectorName::AcpGrid, rems_from_px(515.), rems_from_px(126.))
128                        .color(ui::Color::Custom(cx.theme().colors().text.opacity(0.02))),
129                ),
130            )
131            .child(div().absolute().inset_0().size_full().bg(linear_gradient(
132                0.,
133                linear_color_stop(
134                    cx.theme().colors().elevated_surface_background.opacity(0.1),
135                    0.9,
136                ),
137                linear_color_stop(
138                    cx.theme().colors().elevated_surface_background.opacity(0.),
139                    0.,
140                ),
141            )))
142            .child(
143                div()
144                    .absolute()
145                    .inset_0()
146                    .size_full()
147                    .bg(gpui::black().opacity(0.15)),
148            )
149            .child(
150                Vector::new(
151                    VectorName::AcpLogoSerif,
152                    rems_from_px(257.),
153                    rems_from_px(47.),
154                )
155                .color(ui::Color::Custom(cx.theme().colors().text.opacity(0.8))),
156            )
157            .child(
158                v_flex()
159                    .gap_1p5()
160                    .child(illustration_element(false, 0.15))
161                    .child(illustration_element(true, 0.3))
162                    .child(
163                        h_flex()
164                            .pl_1()
165                            .pr_2()
166                            .py_0p5()
167                            .gap_1()
168                            .rounded_sm()
169                            .bg(cx.theme().colors().element_active.opacity(0.2))
170                            .border_1()
171                            .border_color(cx.theme().colors().border)
172                            .child(
173                                Icon::new(IconName::AiGemini)
174                                    .size(IconSize::Small)
175                                    .color(Color::Muted),
176                            )
177                            .child(Label::new("New Gemini CLI Thread").size(LabelSize::Small)),
178                    )
179                    .child(illustration_element(true, 0.3))
180                    .child(illustration_element(false, 0.15)),
181            );
182
183        let heading = v_flex()
184            .w_full()
185            .gap_1()
186            .child(
187                Label::new("Now Available")
188                    .size(LabelSize::Small)
189                    .color(Color::Muted),
190            )
191            .child(Headline::new("Bring Your Own Agent to Zed").size(HeadlineSize::Large));
192
193        let copy = "Bring the agent of your choice to Zed via our new Agent Client Protocol (ACP), starting with Google's Gemini CLI integration.";
194
195        let open_panel_button = Button::new("open-panel", "Start with Gemini CLI")
196            .icon_size(IconSize::Indicator)
197            .style(ButtonStyle::Tinted(TintColor::Accent))
198            .full_width()
199            .on_click(cx.listener(Self::open_panel));
200
201        let docs_button = Button::new("add-other-agents", "Add Other Agents")
202            .icon(IconName::ArrowUpRight)
203            .icon_size(IconSize::Indicator)
204            .icon_color(Color::Muted)
205            .full_width()
206            .on_click(cx.listener(Self::open_agent_registry));
207
208        let close_button = h_flex().absolute().top_2().right_2().child(
209            IconButton::new("cancel", IconName::Close).on_click(cx.listener(
210                |_, _: &ClickEvent, _window, cx| {
211                    acp_onboarding_event!("Canceled", trigger = "X click");
212                    cx.emit(DismissEvent);
213                },
214            )),
215        );
216
217        v_flex()
218            .id("acp-onboarding")
219            .key_context("AcpOnboardingModal")
220            .relative()
221            .w(rems(34.))
222            .h_full()
223            .elevation_3(cx)
224            .track_focus(&self.focus_handle(cx))
225            .overflow_hidden()
226            .on_action(cx.listener(Self::cancel))
227            .on_action(cx.listener(|_, _: &menu::Cancel, _window, cx| {
228                acp_onboarding_event!("Canceled", trigger = "Action");
229                cx.emit(DismissEvent);
230            }))
231            .on_any_mouse_down(cx.listener(|this, _: &MouseDownEvent, window, cx| {
232                this.focus_handle.focus(window, cx);
233            }))
234            .child(illustration)
235            .child(
236                v_flex()
237                    .p_4()
238                    .gap_2()
239                    .child(heading)
240                    .child(Label::new(copy).color(Color::Muted))
241                    .child(
242                        v_flex()
243                            .w_full()
244                            .mt_2()
245                            .gap_1()
246                            .child(open_panel_button)
247                            .child(docs_button),
248                    ),
249            )
250            .child(close_button)
251    }
252}