context_server_settings.rs

 1use std::sync::Arc;
 2
 3use collections::HashMap;
 4use gpui::App;
 5use schemars::JsonSchema;
 6use schemars::r#gen::SchemaGenerator;
 7use schemars::schema::{InstanceType, Schema, SchemaObject};
 8use serde::{Deserialize, Serialize};
 9use settings::{Settings, SettingsSources};
10
11pub fn init(cx: &mut App) {
12    ContextServerSettings::register(cx);
13}
14
15#[derive(Deserialize, Serialize, Clone, PartialEq, Eq, JsonSchema, Debug, Default)]
16pub struct ServerConfig {
17    /// The command to run this context server.
18    ///
19    /// This will override the command set by an extension.
20    pub command: Option<ServerCommand>,
21    /// The settings for this context server.
22    ///
23    /// Consult the documentation for the context server to see what settings
24    /// are supported.
25    #[schemars(schema_with = "server_config_settings_json_schema")]
26    pub settings: Option<serde_json::Value>,
27}
28
29fn server_config_settings_json_schema(_generator: &mut SchemaGenerator) -> Schema {
30    Schema::Object(SchemaObject {
31        instance_type: Some(InstanceType::Object.into()),
32        ..Default::default()
33    })
34}
35
36#[derive(Deserialize, Serialize, Clone, PartialEq, Eq, JsonSchema, Debug)]
37pub struct ServerCommand {
38    pub path: String,
39    pub args: Vec<String>,
40    pub env: Option<HashMap<String, String>>,
41}
42
43#[derive(Deserialize, Serialize, Default, Clone, PartialEq, Eq, JsonSchema, Debug)]
44pub struct ContextServerSettings {
45    /// Settings for context servers used in the Assistant.
46    #[serde(default)]
47    pub context_servers: HashMap<Arc<str>, ServerConfig>,
48}
49
50impl Settings for ContextServerSettings {
51    const KEY: Option<&'static str> = None;
52
53    type FileContent = Self;
54
55    fn load(
56        sources: SettingsSources<Self::FileContent>,
57        _: &mut gpui::App,
58    ) -> anyhow::Result<Self> {
59        sources.json_merge()
60    }
61}