agent: Add newtype for profile IDs (#27939)

This PR adds an `AgentProfileId` newtype for profile IDs that we can use
instead of `Arc<str>` everywhere.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2025-04-02 13:12:52 -04:00 committed by GitHub
parent b2904e5d9f
commit 646f65511c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 59 additions and 27 deletions

View file

@ -2,6 +2,29 @@ use std::sync::Arc;
use gpui::SharedString;
use indexmap::IndexMap;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
#[derive(Debug, PartialEq, Eq, Hash, Clone, Serialize, Deserialize, JsonSchema)]
pub struct AgentProfileId(pub Arc<str>);
impl AgentProfileId {
pub fn as_str(&self) -> &str {
&self.0
}
}
impl std::fmt::Display for AgentProfileId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}
impl Default for AgentProfileId {
fn default() -> Self {
Self("write".into())
}
}
/// A profile for the Zed Agent that controls its behavior.
#[derive(Debug, Clone)]

View file

@ -81,8 +81,8 @@ pub struct AssistantSettings {
pub inline_alternatives: Vec<LanguageModelSelection>,
pub using_outdated_settings_version: bool,
pub enable_experimental_live_diffs: bool,
pub default_profile: Arc<str>,
pub profiles: IndexMap<Arc<str>, AgentProfile>,
pub default_profile: AgentProfileId,
pub profiles: IndexMap<AgentProfileId, AgentProfile>,
pub always_allow_tool_actions: bool,
pub notify_when_agent_waiting: NotifyWhenAgentWaiting,
}
@ -325,7 +325,7 @@ impl AssistantSettingsContent {
}
}
pub fn set_profile(&mut self, profile_id: Arc<str>) {
pub fn set_profile(&mut self, profile_id: AgentProfileId) {
let AssistantSettingsContent::Versioned(VersionedAssistantSettingsContent::V2(settings)) =
self
else {
@ -335,7 +335,11 @@ impl AssistantSettingsContent {
settings.default_profile = Some(profile_id);
}
pub fn create_profile(&mut self, profile_id: Arc<str>, profile: AgentProfile) -> Result<()> {
pub fn create_profile(
&mut self,
profile_id: AgentProfileId,
profile: AgentProfile,
) -> Result<()> {
let AssistantSettingsContent::Versioned(VersionedAssistantSettingsContent::V2(settings)) =
self
else {
@ -436,9 +440,9 @@ pub struct AssistantSettingsContentV2 {
/// The default profile to use in the Agent.
///
/// Default: write
default_profile: Option<Arc<str>>,
default_profile: Option<AgentProfileId>,
/// The available agent profiles.
pub profiles: Option<IndexMap<Arc<str>, AgentProfileContent>>,
pub profiles: Option<IndexMap<AgentProfileId, AgentProfileContent>>,
/// Whenever a tool action would normally wait for your confirmation
/// that you allow it, always choose to allow it.
///