1mod active_thread;
2mod agent_diff;
3mod assistant_configuration;
4mod assistant_model_selector;
5mod assistant_panel;
6mod buffer_codegen;
7mod context;
8mod context_picker;
9mod context_store;
10mod context_strip;
11mod history_store;
12mod inline_assistant;
13mod inline_prompt_editor;
14mod message_editor;
15mod profile_selector;
16mod terminal_codegen;
17mod terminal_inline_assistant;
18mod thread;
19mod thread_history;
20mod thread_store;
21mod tool_use;
22mod ui;
23
24use std::sync::Arc;
25
26use assistant_settings::{AgentProfileId, AssistantSettings};
27use client::Client;
28use command_palette_hooks::CommandPaletteFilter;
29use feature_flags::{Assistant2FeatureFlag, FeatureFlagAppExt};
30use fs::Fs;
31use gpui::{App, actions, impl_actions};
32use prompt_store::PromptBuilder;
33use schemars::JsonSchema;
34use serde::Deserialize;
35use settings::Settings as _;
36use thread::ThreadId;
37
38pub use crate::active_thread::ActiveThread;
39use crate::assistant_configuration::{AddContextServerModal, ManageProfilesModal};
40pub use crate::assistant_panel::{AssistantPanel, ConcreteAssistantPanelDelegate};
41pub use crate::inline_assistant::InlineAssistant;
42pub use crate::thread::{Message, RequestKind, Thread, ThreadEvent};
43pub use crate::thread_store::ThreadStore;
44pub use agent_diff::{AgentDiff, AgentDiffToolbar};
45
46actions!(
47 agent,
48 [
49 NewPromptEditor,
50 ToggleContextPicker,
51 ToggleProfileSelector,
52 RemoveAllContext,
53 OpenHistory,
54 AddContextServer,
55 RemoveSelectedThread,
56 Chat,
57 ChatMode,
58 CycleNextInlineAssist,
59 CyclePreviousInlineAssist,
60 FocusUp,
61 FocusDown,
62 FocusLeft,
63 FocusRight,
64 RemoveFocusedContext,
65 AcceptSuggestedContext,
66 OpenActiveThreadAsMarkdown,
67 OpenAgentDiff,
68 Keep,
69 Reject,
70 RejectAll,
71 KeepAll
72 ]
73);
74
75#[derive(Default, Clone, PartialEq, Deserialize, JsonSchema)]
76pub struct NewThread {
77 #[serde(default)]
78 from_thread_id: Option<ThreadId>,
79}
80
81#[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema)]
82pub struct ManageProfiles {
83 #[serde(default)]
84 pub customize_tools: Option<AgentProfileId>,
85}
86
87impl ManageProfiles {
88 pub fn customize_tools(profile_id: AgentProfileId) -> Self {
89 Self {
90 customize_tools: Some(profile_id),
91 }
92 }
93}
94
95impl_actions!(agent, [NewThread, ManageProfiles]);
96
97const NAMESPACE: &str = "agent";
98
99/// Initializes the `agent` crate.
100pub fn init(
101 fs: Arc<dyn Fs>,
102 client: Arc<Client>,
103 prompt_builder: Arc<PromptBuilder>,
104 cx: &mut App,
105) {
106 AssistantSettings::register(cx);
107 thread_store::init(cx);
108 assistant_panel::init(cx);
109
110 inline_assistant::init(
111 fs.clone(),
112 prompt_builder.clone(),
113 client.telemetry().clone(),
114 cx,
115 );
116 terminal_inline_assistant::init(
117 fs.clone(),
118 prompt_builder.clone(),
119 client.telemetry().clone(),
120 cx,
121 );
122 cx.observe_new(AddContextServerModal::register).detach();
123 cx.observe_new(ManageProfilesModal::register).detach();
124
125 feature_gate_agent_actions(cx);
126}
127
128fn feature_gate_agent_actions(cx: &mut App) {
129 CommandPaletteFilter::update_global(cx, |filter, _cx| {
130 filter.hide_namespace(NAMESPACE);
131 });
132
133 cx.observe_flag::<Assistant2FeatureFlag, _>(move |is_enabled, cx| {
134 if is_enabled {
135 CommandPaletteFilter::update_global(cx, |filter, _cx| {
136 filter.show_namespace(NAMESPACE);
137 });
138 } else {
139 CommandPaletteFilter::update_global(cx, |filter, _cx| {
140 filter.hide_namespace(NAMESPACE);
141 });
142 }
143 })
144 .detach();
145}