1mod active_thread;
2mod assistant_panel;
3mod assistant_settings;
4mod context;
5mod context_picker;
6mod context_store;
7mod context_strip;
8mod inline_assistant;
9mod inline_prompt_editor;
10mod message_editor;
11mod prompts;
12mod streaming_diff;
13mod terminal_inline_assistant;
14mod thread;
15mod thread_history;
16mod thread_store;
17mod ui;
18
19use std::sync::Arc;
20
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;
31use crate::assistant_settings::AssistantSettings;
32pub use crate::inline_assistant::InlineAssistant;
33
34actions!(
35 assistant2,
36 [
37 ToggleFocus,
38 NewThread,
39 ToggleContextPicker,
40 ToggleModelSelector,
41 OpenHistory,
42 Chat,
43 CycleNextInlineAssist,
44 CyclePreviousInlineAssist
45 ]
46);
47
48const NAMESPACE: &str = "assistant2";
49
50/// Initializes the `assistant2` crate.
51pub fn init(fs: Arc<dyn Fs>, client: Arc<Client>, stdout_is_a_pty: bool, cx: &mut AppContext) {
52 AssistantSettings::register(cx);
53 assistant_panel::init(cx);
54
55 let prompt_builder = prompts::PromptBuilder::new(Some(PromptLoadingParams {
56 fs: fs.clone(),
57 repo_path: stdout_is_a_pty
58 .then(|| std::env::current_dir().log_err())
59 .flatten(),
60 cx,
61 }))
62 .log_err()
63 .map(Arc::new)
64 .unwrap_or_else(|| Arc::new(prompts::PromptBuilder::new(None).unwrap()));
65 inline_assistant::init(
66 fs.clone(),
67 prompt_builder.clone(),
68 client.telemetry().clone(),
69 cx,
70 );
71 terminal_inline_assistant::init(
72 fs.clone(),
73 prompt_builder.clone(),
74 client.telemetry().clone(),
75 cx,
76 );
77
78 feature_gate_assistant2_actions(cx);
79}
80
81fn feature_gate_assistant2_actions(cx: &mut AppContext) {
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 });
91 } else {
92 CommandPaletteFilter::update_global(cx, |filter, _cx| {
93 filter.hide_namespace(NAMESPACE);
94 });
95 }
96 })
97 .detach();
98}