1use std::sync::Arc;
2
3use collections::IndexMap;
4use gpui::SharedString;
5use schemars::JsonSchema;
6use serde::{Deserialize, Serialize};
7
8pub mod builtin_profiles {
9 use super::AgentProfileId;
10
11 pub const WRITE: &str = "write";
12 pub const ASK: &str = "ask";
13 pub const MINIMAL: &str = "minimal";
14
15 pub fn is_builtin(profile_id: &AgentProfileId) -> bool {
16 profile_id.as_str() == WRITE || profile_id.as_str() == ASK || profile_id.as_str() == MINIMAL
17 }
18}
19
20#[derive(Default)]
21pub struct GroupedAgentProfiles {
22 pub builtin: IndexMap<AgentProfileId, AgentProfile>,
23 pub custom: IndexMap<AgentProfileId, AgentProfile>,
24}
25
26impl GroupedAgentProfiles {
27 pub fn from_settings(settings: &crate::AgentSettings) -> Self {
28 let mut builtin = IndexMap::default();
29 let mut custom = IndexMap::default();
30
31 for (profile_id, profile) in settings.profiles.clone() {
32 if builtin_profiles::is_builtin(&profile_id) {
33 builtin.insert(profile_id, profile);
34 } else {
35 custom.insert(profile_id, profile);
36 }
37 }
38
39 Self { builtin, custom }
40 }
41}
42
43#[derive(Debug, PartialEq, Eq, Hash, Clone, Serialize, Deserialize, JsonSchema)]
44pub struct AgentProfileId(pub Arc<str>);
45
46impl AgentProfileId {
47 pub fn as_str(&self) -> &str {
48 &self.0
49 }
50}
51
52impl std::fmt::Display for AgentProfileId {
53 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
54 write!(f, "{}", self.0)
55 }
56}
57
58impl Default for AgentProfileId {
59 fn default() -> Self {
60 Self("write".into())
61 }
62}
63
64/// A profile for the Zed Agent that controls its behavior.
65#[derive(Debug, Clone)]
66pub struct AgentProfile {
67 /// The name of the profile.
68 pub name: SharedString,
69 pub tools: IndexMap<Arc<str>, bool>,
70 pub enable_all_context_servers: bool,
71 pub context_servers: IndexMap<Arc<str>, ContextServerPreset>,
72}
73
74#[derive(Debug, Clone, Default)]
75pub struct ContextServerPreset {
76 pub tools: IndexMap<Arc<str>, bool>,
77}