assistant.rs

  1mod active_thread;
  2mod assistant_panel;
  3mod assistant_settings;
  4mod context;
  5mod context_picker;
  6mod context_store;
  7mod context_strip;
  8mod inline_assistant;
  9mod message_editor;
 10mod prompts;
 11mod streaming_diff;
 12mod terminal_inline_assistant;
 13mod thread;
 14mod thread_history;
 15mod thread_store;
 16mod ui;
 17
 18use std::any::TypeId;
 19use std::sync::Arc;
 20
 21use client::Client;
 22use command_palette_hooks::CommandPaletteFilter;
 23use feature_flags::{Assistant2FeatureFlag, FeatureFlagAppExt};
 24use fs::Fs;
 25use gpui::{actions, AppContext};
 26use prompts::PromptLoadingParams;
 27use settings::Settings as _;
 28use util::ResultExt;
 29
 30pub use crate::assistant_panel::AssistantPanel;
 31use crate::assistant_settings::AssistantSettings;
 32pub use crate::inline_assistant::InlineAssistant;
 33
 34actions!(
 35    assistant2,
 36    [
 37        ToggleFocus,
 38        NewThread,
 39        ToggleContextPicker,
 40        ToggleModelSelector,
 41        OpenHistory,
 42        Chat,
 43        CycleNextInlineAssist,
 44        CyclePreviousInlineAssist
 45    ]
 46);
 47
 48const NAMESPACE: &str = "assistant2";
 49
 50/// Initializes the `assistant2` crate.
 51pub fn init(fs: Arc<dyn Fs>, client: Arc<Client>, stdout_is_a_pty: bool, cx: &mut AppContext) {
 52    AssistantSettings::register(cx);
 53    assistant_panel::init(cx);
 54
 55    let prompt_builder = prompts::PromptBuilder::new(Some(PromptLoadingParams {
 56        fs: fs.clone(),
 57        repo_path: stdout_is_a_pty
 58            .then(|| std::env::current_dir().log_err())
 59            .flatten(),
 60        cx,
 61    }))
 62    .log_err()
 63    .map(Arc::new)
 64    .unwrap_or_else(|| Arc::new(prompts::PromptBuilder::new(None).unwrap()));
 65    inline_assistant::init(
 66        fs.clone(),
 67        prompt_builder.clone(),
 68        client.telemetry().clone(),
 69        cx,
 70    );
 71    terminal_inline_assistant::init(
 72        fs.clone(),
 73        prompt_builder.clone(),
 74        client.telemetry().clone(),
 75        cx,
 76    );
 77
 78    feature_gate_assistant2_actions(cx);
 79}
 80
 81fn feature_gate_assistant2_actions(cx: &mut AppContext) {
 82    const ASSISTANT1_NAMESPACE: &str = "assistant";
 83
 84    let inline_assist_actions = [TypeId::of::<zed_actions::InlineAssist>()];
 85
 86    CommandPaletteFilter::update_global(cx, |filter, _cx| {
 87        filter.hide_namespace(NAMESPACE);
 88    });
 89
 90    cx.observe_flag::<Assistant2FeatureFlag, _>(move |is_enabled, cx| {
 91        if is_enabled {
 92            CommandPaletteFilter::update_global(cx, |filter, _cx| {
 93                filter.show_namespace(NAMESPACE);
 94                filter.hide_namespace(ASSISTANT1_NAMESPACE);
 95
 96                // We're hiding all of the `assistant: ` actions, but we want to
 97                // keep the inline assist action around so we can use the same
 98                // one in Assistant2.
 99                filter.show_action_types(inline_assist_actions.iter());
100            });
101        } else {
102            CommandPaletteFilter::update_global(cx, |filter, _cx| {
103                filter.hide_namespace(NAMESPACE);
104                filter.show_namespace(ASSISTANT1_NAMESPACE);
105            });
106        }
107    })
108    .detach();
109}