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