1use collections::{HashMap, IndexMap};
2use gpui::SharedString;
3use schemars::{JsonSchema, json_schema};
4use serde::{Deserialize, Serialize};
5use serde_with::skip_serializing_none;
6use settings_macros::MergeFrom;
7use std::{borrow::Cow, path::PathBuf, sync::Arc};
8
9use crate::DockPosition;
10
11#[skip_serializing_none]
12#[derive(Clone, PartialEq, Serialize, Deserialize, JsonSchema, MergeFrom, Debug, Default)]
13pub struct AgentSettingsContent {
14 /// Whether the Agent is enabled.
15 ///
16 /// Default: true
17 pub enabled: Option<bool>,
18 /// Whether to show the agent panel button in the status bar.
19 ///
20 /// Default: true
21 pub button: Option<bool>,
22 /// Where to dock the agent panel.
23 ///
24 /// Default: right
25 pub dock: Option<DockPosition>,
26 /// Default width in pixels when the agent panel is docked to the left or right.
27 ///
28 /// Default: 640
29 pub default_width: Option<f32>,
30 /// Default height in pixels when the agent panel is docked to the bottom.
31 ///
32 /// Default: 320
33 pub default_height: Option<f32>,
34 /// The default model to use when creating new chats and for other features when a specific model is not specified.
35 pub default_model: Option<LanguageModelSelection>,
36 /// Model to use for the inline assistant. Defaults to default_model when not specified.
37 pub inline_assistant_model: Option<LanguageModelSelection>,
38 /// Model to use for generating git commit messages. Defaults to default_model when not specified.
39 pub commit_message_model: Option<LanguageModelSelection>,
40 /// Model to use for generating thread summaries. Defaults to default_model when not specified.
41 pub thread_summary_model: Option<LanguageModelSelection>,
42 /// Additional models with which to generate alternatives when performing inline assists.
43 pub inline_alternatives: Option<Vec<LanguageModelSelection>>,
44 /// The default profile to use in the Agent.
45 ///
46 /// Default: write
47 pub default_profile: Option<Arc<str>>,
48 /// Which view type to show by default in the agent panel.
49 ///
50 /// Default: "thread"
51 pub default_view: Option<DefaultAgentView>,
52 /// The available agent profiles.
53 pub profiles: Option<IndexMap<Arc<str>, AgentProfileContent>>,
54 /// Whenever a tool action would normally wait for your confirmation
55 /// that you allow it, always choose to allow it.
56 ///
57 /// This setting has no effect on external agents that support permission modes, such as Claude Code.
58 ///
59 /// Set `agent_servers.claude.default_mode` to `bypassPermissions`, to disable all permission requests when using Claude Code.
60 ///
61 /// Default: false
62 pub always_allow_tool_actions: Option<bool>,
63 /// Where to show a popup notification when the agent is waiting for user input.
64 ///
65 /// Default: "primary_screen"
66 pub notify_when_agent_waiting: Option<NotifyWhenAgentWaiting>,
67 /// Whether to play a sound when the agent has either completed its response, or needs user input.
68 ///
69 /// Default: false
70 pub play_sound_when_agent_done: Option<bool>,
71 /// Whether to stream edits from the agent as they are received.
72 ///
73 /// Default: false
74 pub stream_edits: Option<bool>,
75 /// Whether to display agent edits in single-file editors in addition to the review multibuffer pane.
76 ///
77 /// Default: true
78 pub single_file_review: Option<bool>,
79 /// Additional parameters for language model requests. When making a request
80 /// to a model, parameters will be taken from the last entry in this list
81 /// that matches the model's provider and name. In each entry, both provider
82 /// and model are optional, so that you can specify parameters for either
83 /// one.
84 ///
85 /// Default: []
86 #[serde(default)]
87 pub model_parameters: Vec<LanguageModelParameters>,
88 /// What completion mode to enable for new threads
89 ///
90 /// Default: normal
91 pub preferred_completion_mode: Option<CompletionMode>,
92 /// Whether to show thumb buttons for feedback in the agent panel.
93 ///
94 /// Default: true
95 pub enable_feedback: Option<bool>,
96 /// Whether to have edit cards in the agent panel expanded, showing a preview of the full diff.
97 ///
98 /// Default: true
99 pub expand_edit_card: Option<bool>,
100 /// Whether to have terminal cards in the agent panel expanded, showing the whole command output.
101 ///
102 /// Default: true
103 pub expand_terminal_card: Option<bool>,
104 /// Whether to always use cmd-enter (or ctrl-enter on Linux or Windows) to send messages in the agent panel.
105 ///
106 /// Default: false
107 pub use_modifier_to_send: Option<bool>,
108 /// Minimum number of lines of height the agent message editor should have.
109 ///
110 /// Default: 4
111 pub message_editor_min_lines: Option<usize>,
112}
113
114impl AgentSettingsContent {
115 pub fn set_dock(&mut self, dock: DockPosition) {
116 self.dock = Some(dock);
117 }
118
119 pub fn set_model(&mut self, language_model: LanguageModelSelection) {
120 // let model = language_model.id().0.to_string();
121 // let provider = language_model.provider_id().0.to_string();
122 // self.default_model = Some(LanguageModelSelection {
123 // provider: provider.into(),
124 // model,
125 // });
126 self.default_model = Some(language_model)
127 }
128
129 pub fn set_inline_assistant_model(&mut self, provider: String, model: String) {
130 self.inline_assistant_model = Some(LanguageModelSelection {
131 provider: provider.into(),
132 model,
133 });
134 }
135
136 pub fn set_commit_message_model(&mut self, provider: String, model: String) {
137 self.commit_message_model = Some(LanguageModelSelection {
138 provider: provider.into(),
139 model,
140 });
141 }
142
143 pub fn set_thread_summary_model(&mut self, provider: String, model: String) {
144 self.thread_summary_model = Some(LanguageModelSelection {
145 provider: provider.into(),
146 model,
147 });
148 }
149
150 pub fn set_always_allow_tool_actions(&mut self, allow: bool) {
151 self.always_allow_tool_actions = Some(allow);
152 }
153
154 pub fn set_play_sound_when_agent_done(&mut self, allow: bool) {
155 self.play_sound_when_agent_done = Some(allow);
156 }
157
158 pub fn set_single_file_review(&mut self, allow: bool) {
159 self.single_file_review = Some(allow);
160 }
161
162 pub fn set_use_modifier_to_send(&mut self, always_use: bool) {
163 self.use_modifier_to_send = Some(always_use);
164 }
165
166 pub fn set_profile(&mut self, profile_id: Arc<str>) {
167 self.default_profile = Some(profile_id);
168 }
169}
170
171#[skip_serializing_none]
172#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, JsonSchema, MergeFrom)]
173pub struct AgentProfileContent {
174 pub name: Arc<str>,
175 #[serde(default)]
176 pub tools: IndexMap<Arc<str>, bool>,
177 /// Whether all context servers are enabled by default.
178 pub enable_all_context_servers: Option<bool>,
179 #[serde(default)]
180 pub context_servers: IndexMap<Arc<str>, ContextServerPresetContent>,
181}
182
183#[skip_serializing_none]
184#[derive(Debug, PartialEq, Clone, Default, Serialize, Deserialize, JsonSchema, MergeFrom)]
185pub struct ContextServerPresetContent {
186 pub tools: IndexMap<Arc<str>, bool>,
187}
188
189#[derive(Copy, Clone, Default, Debug, PartialEq, Serialize, Deserialize, JsonSchema, MergeFrom)]
190#[serde(rename_all = "snake_case")]
191pub enum DefaultAgentView {
192 #[default]
193 Thread,
194 TextThread,
195}
196
197#[derive(Copy, Clone, Default, Debug, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq)]
198#[serde(rename_all = "snake_case")]
199pub enum NotifyWhenAgentWaiting {
200 #[default]
201 PrimaryScreen,
202 AllScreens,
203 Never,
204}
205
206#[skip_serializing_none]
207#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq)]
208pub struct LanguageModelSelection {
209 pub provider: LanguageModelProviderSetting,
210 pub model: String,
211}
212
213#[derive(Clone, Copy, Debug, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq, Default)]
214#[serde(rename_all = "snake_case")]
215pub enum CompletionMode {
216 #[default]
217 Normal,
218 #[serde(alias = "max")]
219 Burn,
220}
221
222#[skip_serializing_none]
223#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq)]
224pub struct LanguageModelParameters {
225 pub provider: Option<LanguageModelProviderSetting>,
226 pub model: Option<SharedString>,
227 pub temperature: Option<f32>,
228}
229
230#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, MergeFrom)]
231pub struct LanguageModelProviderSetting(pub String);
232
233impl JsonSchema for LanguageModelProviderSetting {
234 fn schema_name() -> Cow<'static, str> {
235 "LanguageModelProviderSetting".into()
236 }
237
238 fn json_schema(_: &mut schemars::SchemaGenerator) -> schemars::Schema {
239 // list the builtin providers as a subset so that we still auto complete them in the settings
240 json_schema!({
241 "anyOf": [
242 {
243 "type": "string",
244 "enum": [
245 "amazon-bedrock",
246 "anthropic",
247 "copilot_chat",
248 "deepseek",
249 "google",
250 "lmstudio",
251 "mistral",
252 "ollama",
253 "openai",
254 "openrouter",
255 "vercel",
256 "x_ai",
257 "zed.dev"
258 ]
259 },
260 {
261 "type": "string",
262 }
263 ]
264 })
265 }
266}
267
268impl From<String> for LanguageModelProviderSetting {
269 fn from(provider: String) -> Self {
270 Self(provider)
271 }
272}
273
274impl From<&str> for LanguageModelProviderSetting {
275 fn from(provider: &str) -> Self {
276 Self(provider.to_string())
277 }
278}
279
280#[skip_serializing_none]
281#[derive(Default, PartialEq, Deserialize, Serialize, Clone, JsonSchema, MergeFrom, Debug)]
282pub struct AllAgentServersSettings {
283 pub gemini: Option<BuiltinAgentServerSettings>,
284 pub claude: Option<BuiltinAgentServerSettings>,
285
286 /// Custom agent servers configured by the user
287 #[serde(flatten)]
288 pub custom: HashMap<SharedString, CustomAgentServerSettings>,
289}
290
291#[skip_serializing_none]
292#[derive(Default, Deserialize, Serialize, Clone, JsonSchema, MergeFrom, Debug, PartialEq)]
293pub struct BuiltinAgentServerSettings {
294 /// Absolute path to a binary to be used when launching this agent.
295 ///
296 /// This can be used to run a specific binary without automatic downloads or searching `$PATH`.
297 #[serde(rename = "command")]
298 pub path: Option<PathBuf>,
299 /// If a binary is specified in `command`, it will be passed these arguments.
300 pub args: Option<Vec<String>>,
301 /// If a binary is specified in `command`, it will be passed these environment variables.
302 pub env: Option<HashMap<String, String>>,
303 /// Whether to skip searching `$PATH` for an agent server binary when
304 /// launching this agent.
305 ///
306 /// This has no effect if a `command` is specified. Otherwise, when this is
307 /// `false`, Zed will search `$PATH` for an agent server binary and, if one
308 /// is found, use it for threads with this agent. If no agent binary is
309 /// found on `$PATH`, Zed will automatically install and use its own binary.
310 /// When this is `true`, Zed will not search `$PATH`, and will always use
311 /// its own binary.
312 ///
313 /// Default: true
314 pub ignore_system_version: Option<bool>,
315 /// The default mode to use for this agent.
316 ///
317 /// Note: Not only all agents support modes.
318 ///
319 /// Default: None
320 pub default_mode: Option<String>,
321}
322
323#[skip_serializing_none]
324#[derive(Deserialize, Serialize, Clone, JsonSchema, MergeFrom, Debug, PartialEq)]
325pub struct CustomAgentServerSettings {
326 #[serde(rename = "command")]
327 pub path: PathBuf,
328 #[serde(default)]
329 pub args: Vec<String>,
330 pub env: Option<HashMap<String, String>>,
331 /// The default mode to use for this agent.
332 ///
333 /// Note: Not only all agents support modes.
334 ///
335 /// Default: None
336 pub default_mode: Option<String>,
337}