use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
#[serde(default, deny_unknown_fields)]
pub struct CursorRunnerConfig {
#[serde(skip_serializing_if = "Option::is_none")]
pub model_params: Option<BTreeMap<String, CursorModelParamValue>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub setting_sources: Option<Vec<CursorSettingSource>>,
}
impl CursorRunnerConfig {
pub fn merge_from(&mut self, other: Self) {
if let Some(other_params) = other.model_params {
match &mut self.model_params {
Some(existing) => existing.extend(other_params),
None => self.model_params = Some(other_params),
}
}
if other.setting_sources.is_some() {
self.setting_sources = other.setting_sources;
}
}
pub fn is_effectively_empty(&self) -> bool {
self.model_params.as_ref().is_none_or(BTreeMap::is_empty)
&& self.setting_sources.as_ref().is_none_or(Vec::is_empty)
}
}
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
#[serde(untagged)]
pub enum CursorModelParamValue {
String(String),
Bool(bool),
}
impl CursorModelParamValue {
pub fn as_sdk_value(&self) -> String {
match self {
CursorModelParamValue::String(value) => value.clone(),
CursorModelParamValue::Bool(value) => value.to_string(),
}
}
}
#[derive(Debug, Clone, Copy, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum CursorSettingSource {
Project,
User,
Team,
Mdm,
Plugins,
All,
}
impl CursorSettingSource {
pub fn as_sdk_value(self) -> &'static str {
match self {
CursorSettingSource::Project => "project",
CursorSettingSource::User => "user",
CursorSettingSource::Team => "team",
CursorSettingSource::Mdm => "mdm",
CursorSettingSource::Plugins => "plugins",
CursorSettingSource::All => "all",
}
}
}