assistant.rs

  1mod active_thread;
  2mod assistant_configuration;
  3mod assistant_diff;
  4mod assistant_model_selector;
  5mod assistant_panel;
  6mod buffer_codegen;
  7mod context;
  8mod context_picker;
  9mod context_store;
 10mod context_strip;
 11mod history_store;
 12mod inline_assistant;
 13mod inline_prompt_editor;
 14mod message_editor;
 15mod terminal_codegen;
 16mod terminal_inline_assistant;
 17mod thread;
 18mod thread_history;
 19mod thread_store;
 20mod tool_selector;
 21mod tool_use;
 22mod ui;
 23
 24use std::sync::Arc;
 25
 26use assistant_settings::AssistantSettings;
 27use client::Client;
 28use command_palette_hooks::CommandPaletteFilter;
 29use feature_flags::{Assistant2FeatureFlag, FeatureFlagAppExt};
 30use fs::Fs;
 31use gpui::{actions, App};
 32use prompt_store::PromptBuilder;
 33use settings::Settings as _;
 34
 35pub use crate::active_thread::ActiveThread;
 36pub use crate::assistant_panel::{AssistantPanel, ConcreteAssistantPanelDelegate};
 37pub use crate::inline_assistant::InlineAssistant;
 38pub use crate::thread::{Message, RequestKind, Thread, ThreadEvent};
 39pub use crate::thread_store::ThreadStore;
 40pub use assistant_diff::AssistantDiff;
 41
 42actions!(
 43    assistant2,
 44    [
 45        NewThread,
 46        NewPromptEditor,
 47        ToggleContextPicker,
 48        RemoveAllContext,
 49        OpenHistory,
 50        OpenConfiguration,
 51        RemoveSelectedThread,
 52        Chat,
 53        ChatMode,
 54        CycleNextInlineAssist,
 55        CyclePreviousInlineAssist,
 56        FocusUp,
 57        FocusDown,
 58        FocusLeft,
 59        FocusRight,
 60        RemoveFocusedContext,
 61        AcceptSuggestedContext,
 62        OpenActiveThreadAsMarkdown
 63    ]
 64);
 65
 66const NAMESPACE: &str = "assistant2";
 67
 68/// Initializes the `assistant2` crate.
 69pub fn init(
 70    fs: Arc<dyn Fs>,
 71    client: Arc<Client>,
 72    prompt_builder: Arc<PromptBuilder>,
 73    cx: &mut App,
 74) {
 75    AssistantSettings::register(cx);
 76    thread_store::init(cx);
 77    assistant_panel::init(cx);
 78
 79    inline_assistant::init(
 80        fs.clone(),
 81        prompt_builder.clone(),
 82        client.telemetry().clone(),
 83        cx,
 84    );
 85    terminal_inline_assistant::init(
 86        fs.clone(),
 87        prompt_builder.clone(),
 88        client.telemetry().clone(),
 89        cx,
 90    );
 91
 92    feature_gate_assistant2_actions(cx);
 93}
 94
 95fn feature_gate_assistant2_actions(cx: &mut App) {
 96    CommandPaletteFilter::update_global(cx, |filter, _cx| {
 97        filter.hide_namespace(NAMESPACE);
 98    });
 99
100    cx.observe_flag::<Assistant2FeatureFlag, _>(move |is_enabled, cx| {
101        if is_enabled {
102            CommandPaletteFilter::update_global(cx, |filter, _cx| {
103                filter.show_namespace(NAMESPACE);
104            });
105        } else {
106            CommandPaletteFilter::update_global(cx, |filter, _cx| {
107                filter.hide_namespace(NAMESPACE);
108            });
109        }
110    })
111    .detach();
112}