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