assistant.rs

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