assistant.rs

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