agent_profile.rs

 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(Debug, PartialEq, Eq, Hash, Clone, Serialize, Deserialize, JsonSchema)]
21pub struct AgentProfileId(pub Arc<str>);
22
23impl AgentProfileId {
24    pub fn as_str(&self) -> &str {
25        &self.0
26    }
27}
28
29impl std::fmt::Display for AgentProfileId {
30    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
31        write!(f, "{}", self.0)
32    }
33}
34
35impl Default for AgentProfileId {
36    fn default() -> Self {
37        Self("write".into())
38    }
39}
40
41/// A profile for the Zed Agent that controls its behavior.
42#[derive(Debug, Clone)]
43pub struct AgentProfileSettings {
44    /// The name of the profile.
45    pub name: SharedString,
46    pub tools: IndexMap<Arc<str>, bool>,
47    pub enable_all_context_servers: bool,
48    pub context_servers: IndexMap<Arc<str>, ContextServerPreset>,
49}
50
51impl AgentProfileSettings {
52    pub fn is_tool_enabled(&self, tool_name: &str) -> bool {
53        self.tools.get(tool_name) == Some(&true)
54    }
55
56    pub fn is_context_server_tool_enabled(&self, server_id: &str, tool_name: &str) -> bool {
57        self.enable_all_context_servers
58            || self
59                .context_servers
60                .get(server_id)
61                .is_some_and(|preset| preset.tools.get(tool_name) == Some(&true))
62    }
63}
64
65#[derive(Debug, Clone, Default)]
66pub struct ContextServerPreset {
67    pub tools: IndexMap<Arc<str>, bool>,
68}