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    [
15        ToggleFocus,
16        NewThread,
17        ToggleModelSelector,
18        OpenHistory,
19        Chat
20    ]
21);
22
23const NAMESPACE: &str = "assistant2";
24
25/// Initializes the `assistant2` crate.
26pub fn init(cx: &mut AppContext) {
27    assistant_panel::init(cx);
28    feature_gate_assistant2_actions(cx);
29}
30
31fn feature_gate_assistant2_actions(cx: &mut AppContext) {
32    const ASSISTANT1_NAMESPACE: &str = "assistant";
33
34    CommandPaletteFilter::update_global(cx, |filter, _cx| {
35        filter.hide_namespace(NAMESPACE);
36    });
37
38    cx.observe_flag::<Assistant2FeatureFlag, _>(move |is_enabled, cx| {
39        if is_enabled {
40            CommandPaletteFilter::update_global(cx, |filter, _cx| {
41                filter.show_namespace(NAMESPACE);
42                filter.hide_namespace(ASSISTANT1_NAMESPACE);
43            });
44        } else {
45            CommandPaletteFilter::update_global(cx, |filter, _cx| {
46                filter.hide_namespace(NAMESPACE);
47                filter.show_namespace(ASSISTANT1_NAMESPACE);
48            });
49        }
50    })
51    .detach();
52}