assistant.rs

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