assistant.rs

 1mod assistant_panel;
 2mod message_editor;
 3mod thread;
 4mod thread_store;
 5
 6use command_palette_hooks::CommandPaletteFilter;
 7use feature_flags::{Assistant2FeatureFlag, FeatureFlagAppExt};
 8use gpui::{actions, AppContext};
 9
10pub use crate::assistant_panel::AssistantPanel;
11
12actions!(
13    assistant2,
14    [ToggleFocus, NewThread, ToggleModelSelector, Chat]
15);
16
17const NAMESPACE: &str = "assistant2";
18
19/// Initializes the `assistant2` crate.
20pub fn init(cx: &mut AppContext) {
21    assistant_panel::init(cx);
22    feature_gate_assistant2_actions(cx);
23}
24
25fn feature_gate_assistant2_actions(cx: &mut AppContext) {
26    const ASSISTANT1_NAMESPACE: &str = "assistant";
27
28    CommandPaletteFilter::update_global(cx, |filter, _cx| {
29        filter.hide_namespace(NAMESPACE);
30    });
31
32    cx.observe_flag::<Assistant2FeatureFlag, _>(move |is_enabled, cx| {
33        if is_enabled {
34            CommandPaletteFilter::update_global(cx, |filter, _cx| {
35                filter.show_namespace(NAMESPACE);
36                filter.hide_namespace(ASSISTANT1_NAMESPACE);
37            });
38        } else {
39            CommandPaletteFilter::update_global(cx, |filter, _cx| {
40                filter.hide_namespace(NAMESPACE);
41                filter.show_namespace(ASSISTANT1_NAMESPACE);
42            });
43        }
44    })
45    .detach();
46}