| 1 | use std::rc::Rc; |
| 2 | |
| 3 | use agents::{AgentAction, Environment}; |
| 4 | use chrono::Utc; |
| 5 | use gpui_kit::assets::IconName; |
| 6 | use gpui_kit::component::{ |
| 7 | ActiveTheme as _, h_flex, |
| 8 | input::{InputEvent, Textarea, TextareaState}, |
| 9 | v_flex, |
| 10 | }; |
| 11 | use gpui_kit::prelude::FluentBuilder as _; |
| 12 | use gpui_kit::*; |
| 13 | |
| 14 | use super::runs::{SessionTarget, StartOptions, StartRequest}; |
| 15 | use super::session_options::{ |
| 16 | SessionOption, attach_inboxes, default_wsl_distro, load_sessions, merged_options, run_options, |
| 17 | }; |
| 18 | use super::start_dialog_pickers::{MenuPart, MenuRow, locked_select, picker_row, select}; |
| 19 | use super::{ |
| 20 | mcp_bridge, message_context, raise_notice, runs_handle, start_run, start_run_when_mcp_ready, |
| 21 | }; |
| 22 | use crate::app_state::AppState; |
| 23 | use crate::i18n::tr; |
| 24 | use crate::theme::{self, ElevatedSurface as _}; |
| 25 | use crate::views::widgets::{icon, symbol}; |
| 26 | |
| 27 | const CARD_WIDTH: f32 = 520.; |
| 28 | const CARD_RADIUS: f32 = 10.; |
| 29 | const CARD_PADDING: f32 = 16.; |
| 30 | const CARD_MARGIN: f32 = 32.; |
| 31 | const SECTION_GAP: f32 = 12.; |
| 32 | const BACKDROP_OPACITY: f32 = 0.55; |
| 33 | const CLOSE_SIZE: f32 = 28.; |
| 34 | const BUTTON_HEIGHT: f32 = 32.; |
| 35 | const QUOTE_LINES: usize = 3; |
| 36 | const FIELD_MIN_ROWS: usize = 3; |
| 37 | const FIELD_MAX_ROWS: usize = 6; |
| 38 | const PROMPT_SIZE: f32 = 12.; |
| 39 | const DISABLED_OPACITY: f32 = 0.5; |
| 40 | const DEFAULT_PLACEHOLDER: &str = "e.g. only the backend, open a PR when done"; |
| 41 | |
| 42 | pub enum StartDialogEvent { |
| 43 | Close, |
| 44 | } |
| 45 | |
| 46 | pub struct StartDialog { |
| 47 | app: Entity<AppState>, |
| 48 | request: StartRequest, |
| 49 | action: AgentAction, |
| 50 | subtitle: String, |
| 51 | sender: String, |
| 52 | quote: String, |
| 53 | needs_allow: bool, |
| 54 | input: Entity<TextareaState>, |
| 55 | show_prompt: bool, |
| 56 | environment: Environment, |
| 57 | default_working_dir: String, |
| 58 | working_dir: String, |
| 59 | recent_working_dirs: Vec<String>, |
| 60 | offers_sessions: bool, |
| 61 | asks_for_directory: bool, |
| 62 | scans_external: bool, |
| 63 | run_sessions: Vec<SessionOption>, |
| 64 | external_sessions: Vec<SessionOption>, |
| 65 | selected_session: Option<SessionOption>, |
| 66 | } |
| 67 | |
| 68 | impl EventEmitter<StartDialogEvent> for StartDialog {} |
| 69 | |
| 70 | impl StartDialog { |
| 71 | pub fn new( |
| 72 | app: Entity<AppState>, |
| 73 | request: StartRequest, |
| 74 | action: AgentAction, |
| 75 | agent_name: &str, |
| 76 | window: &mut Window, |
| 77 | cx: &mut Context<Self>, |
| 78 | ) -> Self { |
| 79 | let context = |
| 80 | message_context::build(app.read(cx), &request.conversation_id, &request.message_id); |
| 81 | let (sender, quote) = context |
| 82 | .map(|context| (context.sender, context.message)) |
| 83 | .unwrap_or_default(); |
| 84 | let input = cx.new(|cx| { |
| 85 | TextareaState::new(window, cx) |
| 86 | .auto_grow(FIELD_MIN_ROWS, FIELD_MAX_ROWS) |
| 87 | .placeholder(DEFAULT_PLACEHOLDER) |
| 88 | }); |
| 89 | input.update(cx, |input, cx| input.focus(window, cx)); |
| 90 | cx.subscribe(&input, |_, _, event: &InputEvent, cx| { |
| 91 | if matches!(event, InputEvent::Change) { |
| 92 | cx.notify(); |
| 93 | } |
| 94 | }) |
| 95 | .detach(); |
| 96 | let runs = runs_handle(cx).map(|runs| runs.read(cx)); |
| 97 | let profile = runs.and_then(|runs| { |
| 98 | runs.settings() |
| 99 | .agents |
| 100 | .iter() |
| 101 | .find(|profile| profile.id == action.agent_id) |
| 102 | .cloned() |
| 103 | }); |
| 104 | let recent_working_dirs = runs |
| 105 | .map(|runs| { |
| 106 | runs.settings() |
| 107 | .recent_working_dirs_of(&action.agent_id) |
| 108 | .to_vec() |
| 109 | }) |
| 110 | .unwrap_or_default(); |
| 111 | let offers_sessions = profile.as_ref().is_some_and(agents::supports_resume); |
| 112 | let asks_for_directory = profile.as_ref().is_none_or(|profile| profile.is_command()); |
| 113 | let run_sessions = match runs { |
| 114 | Some(runs) if offers_sessions => { |
| 115 | run_options(&runs.for_agent(&action.agent_id), app.read(cx), Utc::now()) |
| 116 | } |
| 117 | _ => Vec::new(), |
| 118 | }; |
| 119 | let mut dialog = StartDialog { |
| 120 | app, |
| 121 | subtitle: agent_name.to_owned(), |
| 122 | needs_allow: !mcp_bridge::chat_allowed(&request.conversation_id, cx), |
| 123 | request, |
| 124 | sender, |
| 125 | quote, |
| 126 | input, |
| 127 | show_prompt: false, |
| 128 | environment: profile |
| 129 | .as_ref() |
| 130 | .map(|profile| profile.environment.clone()) |
| 131 | .unwrap_or_default(), |
| 132 | default_working_dir: action.working_dir.clone(), |
| 133 | working_dir: action.working_dir.clone(), |
| 134 | recent_working_dirs, |
| 135 | offers_sessions, |
| 136 | asks_for_directory, |
| 137 | scans_external: profile |
| 138 | .is_some_and(|profile| profile.output == agents::OutputFormat::ClaudeStreamJson) |
| 139 | && offers_sessions, |
| 140 | run_sessions, |
| 141 | external_sessions: Vec::new(), |
| 142 | selected_session: None, |
| 143 | action, |
| 144 | }; |
| 145 | dialog.load_external(cx); |
| 146 | dialog |
| 147 | } |
| 148 | |
| 149 | fn load_external(&mut self, cx: &mut Context<Self>) { |
| 150 | if !self.scans_external { |
| 151 | return; |
| 152 | } |
| 153 | let environment = self.environment.clone(); |
| 154 | let known_session_ids = runs_handle(cx) |
| 155 | .map(|runs| runs.read(cx).session_ids()) |
| 156 | .unwrap_or_default(); |
| 157 | let demo = crate::agent_api::is_demo(cx); |
| 158 | cx.spawn(async move |this, cx| { |
| 159 | let loaded = cx |
| 160 | .background_executor() |
| 161 | .spawn(async move { load_sessions(&environment, demo) }) |
| 162 | .await; |
| 163 | this.update(cx, |this, cx| { |
| 164 | this.external_sessions = merged_options( |
| 165 | &loaded.desktop, |
| 166 | &loaded.running, |
| 167 | &loaded.sessions_dir, |
| 168 | &known_session_ids, |
| 169 | Utc::now(), |
| 170 | ); |
| 171 | attach_inboxes(&mut this.run_sessions, &loaded); |
| 172 | cx.notify(); |
| 173 | }) |
| 174 | .ok(); |
| 175 | }) |
| 176 | .detach(); |
| 177 | } |
| 178 | |
| 179 | fn choose_session( |
| 180 | &mut self, |
| 181 | session: Option<SessionOption>, |
| 182 | window: &mut Window, |
| 183 | cx: &mut Context<Self>, |
| 184 | ) { |
| 185 | let placeholder = if session.is_some() { |
| 186 | tr("agents.start.message_placeholder") |
| 187 | } else { |
| 188 | DEFAULT_PLACEHOLDER.to_owned() |
| 189 | }; |
| 190 | self.input.update(cx, |input, cx| { |
| 191 | input.set_placeholder(placeholder, window, cx) |
| 192 | }); |
| 193 | self.selected_session = session; |
| 194 | cx.notify(); |
| 195 | } |
| 196 | |
| 197 | fn choose_working_dir(&mut self, working_dir: String, cx: &mut Context<Self>) { |
| 198 | self.working_dir = working_dir; |
| 199 | cx.notify(); |
| 200 | } |
| 201 | |
| 202 | fn browse(&mut self, cx: &mut Context<Self>) { |
| 203 | let receiver = cx.prompt_for_paths(PathPromptOptions { |
| 204 | files: false, |
| 205 | directories: true, |
| 206 | multiple: false, |
| 207 | prompt: None, |
| 208 | }); |
| 209 | let environment = self.environment.clone(); |
| 210 | cx.spawn(async move |this, cx| { |
| 211 | let Ok(Ok(Some(paths))) = receiver.await else { |
| 212 | return; |
| 213 | }; |
| 214 | let Some(path) = paths.into_iter().next() else { |
| 215 | return; |
| 216 | }; |
| 217 | let text = path.to_string_lossy().into_owned(); |
| 218 | let working_dir = match &environment { |
| 219 | Environment::Host => text, |
| 220 | Environment::Wsl { distro } => { |
| 221 | let chosen = agents::wsl_unc_distro(&text).map(str::to_owned); |
| 222 | let wanted = match (&chosen, distro) { |
| 223 | (_, Some(distro)) => Some(distro.clone()), |
| 224 | (Some(_), None) => { |
| 225 | let demo = cx.update(|cx| crate::agent_api::is_demo(cx)); |
| 226 | cx.background_executor() |
| 227 | .spawn(async move { default_wsl_distro(demo) }) |
| 228 | .await |
| 229 | } |
| 230 | (None, None) => None, |
| 231 | }; |
| 232 | if chosen.is_some() && wanted.is_some() && chosen != wanted { |
| 233 | cx.update(|cx| { |
| 234 | raise_notice( |
| 235 | "That folder is in a different WSL distro than the agent" |
| 236 | .to_owned(), |
| 237 | cx, |
| 238 | ) |
| 239 | }); |
| 240 | return; |
| 241 | } |
| 242 | agents::linux_path(&text) |
| 243 | } |
| 244 | }; |
| 245 | this.update(cx, |this, cx| this.choose_working_dir(working_dir, cx)) |
| 246 | .ok(); |
| 247 | }) |
| 248 | .detach(); |
| 249 | } |
| 250 | |
| 251 | fn start_options(&self) -> StartOptions { |
| 252 | match &self.selected_session { |
| 253 | Some(session) => StartOptions { |
| 254 | working_dir: None, |
| 255 | remember_working_dir: false, |
| 256 | session: Some(SessionTarget { |
| 257 | session_id: session.session_id.clone(), |
| 258 | working_dir: session.working_dir.clone(), |
| 259 | inbox: session.inbox.clone(), |
| 260 | }), |
| 261 | }, |
| 262 | None => StartOptions { |
| 263 | working_dir: (self.working_dir != self.default_working_dir) |
| 264 | .then(|| self.working_dir.clone()), |
| 265 | remember_working_dir: true, |
| 266 | session: None, |
| 267 | }, |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | fn start(&mut self, cx: &mut Context<Self>) { |
| 272 | let extra = self.input.read(cx).value().trim().to_owned(); |
| 273 | if self.selected_session.is_some() && extra.is_empty() { |
| 274 | return; |
| 275 | } |
| 276 | let options = self.start_options(); |
| 277 | if self.needs_allow { |
| 278 | mcp_bridge::allow_chat(&self.request.conversation_id, cx); |
| 279 | } |
| 280 | if self.needs_allow && mcp_bridge::endpoint(cx).is_none() { |
| 281 | start_run_when_mcp_ready( |
| 282 | self.request.action_id.clone(), |
| 283 | self.request.conversation_id.clone(), |
| 284 | self.request.message_id.clone(), |
| 285 | extra, |
| 286 | options, |
| 287 | cx, |
| 288 | ); |
| 289 | } else { |
| 290 | start_run( |
| 291 | &self.request.action_id, |
| 292 | &self.request.conversation_id, |
| 293 | &self.request.message_id, |
| 294 | &extra, |
| 295 | options, |
| 296 | cx, |
| 297 | ); |
| 298 | } |
| 299 | cx.emit(StartDialogEvent::Close); |
| 300 | } |
| 301 | |
| 302 | fn on_key_down(&mut self, event: &KeyDownEvent, _: &mut Window, cx: &mut Context<Self>) { |
| 303 | match event.keystroke.key.as_str() { |
| 304 | "escape" => cx.emit(StartDialogEvent::Close), |
| 305 | "enter" if event.keystroke.modifiers.control => self.start(cx), |
| 306 | _ => return, |
| 307 | } |
| 308 | cx.stop_propagation(); |
| 309 | } |
| 310 | |
| 311 | fn header(&self, cx: &mut Context<Self>) -> Div { |
| 312 | h_flex() |
| 313 | .w_full() |
| 314 | .items_start() |
| 315 | .gap(px(SECTION_GAP)) |
| 316 | .child( |
| 317 | v_flex() |
| 318 | .flex_1() |
| 319 | .min_w(px(0.)) |
| 320 | .child( |
| 321 | div() |
| 322 | .text_size(px(15.)) |
| 323 | .font_weight(FontWeight::BOLD) |
| 324 | .child(self.action.label.clone()), |
| 325 | ) |
| 326 | .child( |
| 327 | div() |
| 328 | .truncate() |
| 329 | .text_size(px(12.)) |
| 330 | .text_color(theme::text_muted()) |
| 331 | .child(self.subtitle.clone()), |
| 332 | ), |
| 333 | ) |
| 334 | .child( |
| 335 | div() |
| 336 | .id("agent-dialog-close") |
| 337 | .size(px(CLOSE_SIZE)) |
| 338 | .flex_none() |
| 339 | .flex() |
| 340 | .items_center() |
| 341 | .justify_center() |
| 342 | .rounded_full() |
| 343 | .cursor_pointer() |
| 344 | .hover(|button| button.bg(theme::popup_hover())) |
| 345 | .on_click(cx.listener(|_, _, _, cx| cx.emit(StartDialogEvent::Close))) |
| 346 | .child(symbol("close", 16., theme::text_muted())), |
| 347 | ) |
| 348 | } |
| 349 | |
| 350 | fn quote(&self) -> impl IntoElement { |
| 351 | let text = format!("{} - {}", self.sender, self.quote); |
| 352 | let sender_style = HighlightStyle { |
| 353 | color: Some(theme::text()), |
| 354 | font_weight: Some(FontWeight::BOLD), |
| 355 | ..Default::default() |
| 356 | }; |
| 357 | let sender_range = 0..self.sender.len(); |
| 358 | div() |
| 359 | .w_full() |
| 360 | .px(px(12.)) |
| 361 | .py(px(8.)) |
| 362 | .rounded(px(8.)) |
| 363 | .bg(theme::reply_surface()) |
| 364 | .text_size(px(12.)) |
| 365 | .line_height(relative(1.4)) |
| 366 | .text_color(theme::text_soft()) |
| 367 | .line_clamp(QUOTE_LINES) |
| 368 | .text_ellipsis() |
| 369 | .child(StyledText::new(text).with_highlights([(sender_range, sender_style)])) |
| 370 | } |
| 371 | |
| 372 | fn session_parts(&self, dialog: &Entity<Self>) -> Vec<MenuPart> { |
| 373 | let row = |session: &SessionOption| { |
| 374 | let dialog = dialog.clone(); |
| 375 | let chosen = session.clone(); |
| 376 | MenuPart::Row(MenuRow { |
| 377 | label: session.label.clone(), |
| 378 | meta: Some(session.meta.clone()), |
| 379 | running: session.running, |
| 380 | selected: self |
| 381 | .selected_session |
| 382 | .as_ref() |
| 383 | .is_some_and(|selected| selected.session_id == session.session_id), |
| 384 | choose: Rc::new(move |window, cx| { |
| 385 | let chosen = chosen.clone(); |
| 386 | dialog.update(cx, |dialog, cx| { |
| 387 | dialog.choose_session(Some(chosen), window, cx) |
| 388 | }); |
| 389 | }), |
| 390 | }) |
| 391 | }; |
| 392 | let new_dialog = dialog.clone(); |
| 393 | let mut parts = vec![MenuPart::Row(MenuRow { |
| 394 | label: tr("agents.start.new_session"), |
| 395 | meta: None, |
| 396 | running: false, |
| 397 | selected: self.selected_session.is_none(), |
| 398 | choose: Rc::new(move |window, cx| { |
| 399 | new_dialog.update(cx, |dialog, cx| dialog.choose_session(None, window, cx)); |
| 400 | }), |
| 401 | })]; |
| 402 | if !self.run_sessions.is_empty() { |
| 403 | parts.push(MenuPart::Separator); |
| 404 | parts.push(MenuPart::Header(tr("agents.start.recent_sessions"))); |
| 405 | parts.extend(self.run_sessions.iter().map(row)); |
| 406 | } |
| 407 | if !self.external_sessions.is_empty() { |
| 408 | parts.push(MenuPart::Separator); |
| 409 | parts.push(MenuPart::Header(tr("agents.start.other_sessions"))); |
| 410 | parts.extend(self.external_sessions.iter().map(row)); |
| 411 | } |
| 412 | parts |
| 413 | } |
| 414 | |
| 415 | fn working_dir_parts(&self, dialog: &Entity<Self>) -> Vec<MenuPart> { |
| 416 | let row = |working_dir: &str, meta: Option<&str>| { |
| 417 | let dialog = dialog.clone(); |
| 418 | let chosen = working_dir.to_owned(); |
| 419 | MenuPart::Row(MenuRow { |
| 420 | label: working_dir.to_owned(), |
| 421 | meta: meta.map(str::to_owned), |
| 422 | running: false, |
| 423 | selected: self.working_dir == working_dir, |
| 424 | choose: Rc::new(move |_, cx| { |
| 425 | let chosen = chosen.clone(); |
| 426 | dialog.update(cx, |dialog, cx| dialog.choose_working_dir(chosen, cx)); |
| 427 | }), |
| 428 | }) |
| 429 | }; |
| 430 | let browse_dialog = dialog.clone(); |
| 431 | let mut parts = vec![ |
| 432 | MenuPart::Header(tr("agents.start.recent")), |
| 433 | row(&self.default_working_dir, Some("action default")), |
| 434 | ]; |
| 435 | parts.extend( |
| 436 | self.recent_working_dirs |
| 437 | .iter() |
| 438 | .filter(|working_dir| **working_dir != self.default_working_dir) |
| 439 | .map(|working_dir| row(working_dir, None)), |
| 440 | ); |
| 441 | parts.push(MenuPart::Separator); |
| 442 | parts.push(MenuPart::Row(MenuRow { |
| 443 | label: tr("agents.start.browse"), |
| 444 | meta: None, |
| 445 | running: false, |
| 446 | selected: false, |
| 447 | choose: Rc::new(move |_, cx| { |
| 448 | browse_dialog.update(cx, |dialog, cx| dialog.browse(cx)); |
| 449 | }), |
| 450 | })); |
| 451 | parts |
| 452 | } |
| 453 | |
| 454 | fn pickers(&self, cx: &mut Context<Self>) -> Div { |
| 455 | let dialog = cx.entity(); |
| 456 | let session_row = self.offers_sessions.then(|| { |
| 457 | let (value, meta, running) = match &self.selected_session { |
| 458 | Some(session) => ( |
| 459 | session.label.clone(), |
| 460 | Some(session.meta.clone()), |
| 461 | session.running, |
| 462 | ), |
| 463 | None => (tr("agents.start.new_session"), None, false), |
| 464 | }; |
| 465 | picker_row( |
| 466 | tr("agents.start.session"), |
| 467 | select( |
| 468 | "agent-dialog-session", |
| 469 | value, |
| 470 | meta, |
| 471 | running, |
| 472 | self.session_parts(&dialog), |
| 473 | ), |
| 474 | ) |
| 475 | }); |
| 476 | let working_dir_control = match &self.selected_session { |
| 477 | Some(session) => { |
| 478 | locked_select(session.working_dir.clone(), "from session").into_any_element() |
| 479 | } |
| 480 | None => select( |
| 481 | "agent-dialog-working-dir", |
| 482 | self.working_dir.clone(), |
| 483 | None, |
| 484 | false, |
| 485 | self.working_dir_parts(&dialog), |
| 486 | ) |
| 487 | .into_any_element(), |
| 488 | }; |
| 489 | v_flex() |
| 490 | .w_full() |
| 491 | .gap(px(8.)) |
| 492 | .children(session_row) |
| 493 | .when(self.asks_for_directory, |rows| { |
| 494 | rows.child(picker_row( |
| 495 | tr("agents.start.working_dir"), |
| 496 | working_dir_control, |
| 497 | )) |
| 498 | }) |
| 499 | } |
| 500 | |
| 501 | fn field(&self, window: &Window, cx: &App) -> Div { |
| 502 | let focused = self.input.focus_handle(cx).contains_focused(window, cx); |
| 503 | v_flex() |
| 504 | .w_full() |
| 505 | .gap(px(6.)) |
| 506 | .child( |
| 507 | div() |
| 508 | .text_size(px(11.)) |
| 509 | .font_weight(FontWeight::SEMIBOLD) |
| 510 | .text_color(theme::text_faint()) |
| 511 | .child(if self.selected_session.is_some() { |
| 512 | tr("agents.start.message_to_session") |
| 513 | } else { |
| 514 | tr("agents.start.extra_instructions") |
| 515 | }), |
| 516 | ) |
| 517 | .child( |
| 518 | div() |
| 519 | .w_full() |
| 520 | .px(px(12.)) |
| 521 | .py(px(8.)) |
| 522 | .rounded(px(8.)) |
| 523 | .bg(theme::surface_raised()) |
| 524 | .border_1() |
| 525 | .border_color(if focused { |
| 526 | theme::accent() |
| 527 | } else { |
| 528 | theme::surface_raised() |
| 529 | }) |
| 530 | .child(Textarea::new(&self.input).appearance(false).bordered(false)), |
| 531 | ) |
| 532 | } |
| 533 | |
| 534 | fn prompt_toggle(&self, cx: &mut Context<Self>) -> Stateful<Div> { |
| 535 | h_flex() |
| 536 | .id("agent-dialog-prompt-toggle") |
| 537 | .gap(px(4.)) |
| 538 | .items_center() |
| 539 | .cursor_pointer() |
| 540 | .text_size(px(12.)) |
| 541 | .text_color(theme::text_muted()) |
| 542 | .hover(|toggle| toggle.text_color(theme::text_soft())) |
| 543 | .child(icon( |
| 544 | if self.show_prompt { |
| 545 | IconName::ChevronDown |
| 546 | } else { |
| 547 | IconName::ChevronRight |
| 548 | }, |
| 549 | 12., |
| 550 | theme::text_muted(), |
| 551 | )) |
| 552 | .child(tr("agents.start.show_prompt")) |
| 553 | .on_click(cx.listener(|this, _, _, cx| { |
| 554 | this.show_prompt = !this.show_prompt; |
| 555 | cx.notify(); |
| 556 | })) |
| 557 | } |
| 558 | |
| 559 | fn prompt_box(&self, cx: &mut Context<Self>) -> Div { |
| 560 | let extra = self.input.read(cx).value().trim().to_owned(); |
| 561 | let prompt = if self.selected_session.is_some() { |
| 562 | extra |
| 563 | } else { |
| 564 | message_context::preview_prompt( |
| 565 | self.app.read(cx), |
| 566 | &self.action, |
| 567 | &self.request.conversation_id, |
| 568 | &self.request.message_id, |
| 569 | &extra, |
| 570 | ) |
| 571 | .unwrap_or_default() |
| 572 | }; |
| 573 | div() |
| 574 | .w_full() |
| 575 | .max_h(px(160.)) |
| 576 | .px(px(12.)) |
| 577 | .py(px(8.)) |
| 578 | .rounded(px(8.)) |
| 579 | .bg(theme::reply_surface()) |
| 580 | .overflow_hidden() |
| 581 | .font_family(cx.theme().mono_font_family.clone()) |
| 582 | .text_size(px(PROMPT_SIZE)) |
| 583 | .line_height(relative(1.5)) |
| 584 | .text_color(theme::text_muted()) |
| 585 | .child(prompt) |
| 586 | } |
| 587 | |
| 588 | fn buttons(&self, cx: &mut Context<Self>) -> Div { |
| 589 | let blocked = |
| 590 | self.selected_session.is_some() && self.input.read(cx).value().trim().is_empty(); |
| 591 | let start_label = if self.selected_session.is_some() { |
| 592 | tr("agents.start.send") |
| 593 | } else if self.needs_allow { |
| 594 | tr("agents.start.allow_and_start") |
| 595 | } else { |
| 596 | tr("agents.start.start") |
| 597 | }; |
| 598 | h_flex() |
| 599 | .w_full() |
| 600 | .items_center() |
| 601 | .gap(px(8.)) |
| 602 | .child(self.prompt_toggle(cx)) |
| 603 | .child(div().flex_1()) |
| 604 | .child( |
| 605 | h_flex() |
| 606 | .id("agent-dialog-cancel") |
| 607 | .h(px(BUTTON_HEIGHT)) |
| 608 | .px(px(12.)) |
| 609 | .items_center() |
| 610 | .rounded(px(8.)) |
| 611 | .cursor_pointer() |
| 612 | .bg(theme::surface_raised()) |
| 613 | .hover(|button| button.bg(theme::popup_hover())) |
| 614 | .text_size(px(13.)) |
| 615 | .child(tr("common.cancel")) |
| 616 | .on_click(cx.listener(|_, _, _, cx| cx.emit(StartDialogEvent::Close))), |
| 617 | ) |
| 618 | .child( |
| 619 | h_flex() |
| 620 | .id("agent-dialog-start") |
| 621 | .h(px(BUTTON_HEIGHT)) |
| 622 | .px(px(12.)) |
| 623 | .items_center() |
| 624 | .rounded(px(8.)) |
| 625 | .bg(theme::accent()) |
| 626 | .text_color(theme::on_accent()) |
| 627 | .text_size(px(13.)) |
| 628 | .font_weight(FontWeight::SEMIBOLD) |
| 629 | .child(start_label) |
| 630 | .when(blocked, |button| button.opacity(DISABLED_OPACITY)) |
| 631 | .when(!blocked, |button| { |
| 632 | button |
| 633 | .cursor_pointer() |
| 634 | .hover(|button| button.bg(theme::accent_text())) |
| 635 | .on_click(cx.listener(|this, _, _, cx| this.start(cx))) |
| 636 | }), |
| 637 | ) |
| 638 | } |
| 639 | } |
| 640 | |
| 641 | impl Render for StartDialog { |
| 642 | fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement { |
| 643 | div() |
| 644 | .id("agent-dialog-layer") |
| 645 | .absolute() |
| 646 | .top_0() |
| 647 | .left_0() |
| 648 | .size_full() |
| 649 | .flex() |
| 650 | .items_center() |
| 651 | .justify_center() |
| 652 | .child( |
| 653 | div() |
| 654 | .id("agent-dialog-backdrop") |
| 655 | .absolute() |
| 656 | .top_0() |
| 657 | .left_0() |
| 658 | .size_full() |
| 659 | .bg(black().opacity(BACKDROP_OPACITY)) |
| 660 | .occlude() |
| 661 | .on_click(cx.listener(|_, _, _, cx| cx.emit(StartDialogEvent::Close))), |
| 662 | ) |
| 663 | .child( |
| 664 | v_flex() |
| 665 | .id("agent-dialog-card") |
| 666 | .w(px(CARD_WIDTH)) |
| 667 | .max_w(relative(1.)) |
| 668 | .max_h(relative(1.)) |
| 669 | .m(px(CARD_MARGIN)) |
| 670 | .p(px(CARD_PADDING)) |
| 671 | .gap(px(SECTION_GAP)) |
| 672 | .rounded(px(CARD_RADIUS)) |
| 673 | .dialog_surface() |
| 674 | .text_color(theme::text()) |
| 675 | .occlude() |
| 676 | .capture_key_down(cx.listener(Self::on_key_down)) |
| 677 | .child(self.header(cx)) |
| 678 | .child(self.quote()) |
| 679 | .when(self.needs_allow, |card| { |
| 680 | card.child( |
| 681 | div() |
| 682 | .text_size(px(12.)) |
| 683 | .text_color(theme::text_soft()) |
| 684 | .child(tr("agents.start.chat_invisible")), |
| 685 | ) |
| 686 | }) |
| 687 | .child(self.pickers(cx)) |
| 688 | .child(self.field(window, cx)) |
| 689 | .when(self.show_prompt, |card| card.child(self.prompt_box(cx))) |
| 690 | .child(self.buttons(cx)), |
| 691 | ) |
| 692 | } |
| 693 | } |