assistant.rs

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