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