Skip to main content

muse_code_sdk/msp/method/lifecycle/
session_config_mt_providers.rs

1// @generated from the MSP stable schema and protocol sources; do not edit by hand.
2
3use super::session_config_mt::SessionEndpointTransportAuthMode;
4use serde::Deserialize;
5use serde::Deserializer;
6use serde::Serialize;
7use serde::de::Error as _;
8use std::collections::BTreeMap;
9use std::fmt;
10
11/// The header-name rule every header map of the override follows.
12pub(super) fn check_header_names<'a>(
13    names: impl IntoIterator<Item = &'a String>,
14) -> Result<(), &'static str> {
15    for name in names {
16        if name.trim().is_empty() {
17            return Err(
18                "session config modelEndpointTransportOverride header name must not be blank",
19            );
20        }
21        if name.trim() != name {
22            return Err(
23                "session config modelEndpointTransportOverride header name must not contain surrounding whitespace",
24            );
25        }
26    }
27    Ok(())
28}
29
30/// AC-D5: `providers` of the transport override. Closed: a provider this
31/// version does not name fails the decode.
32#[derive(Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
33#[serde(rename_all = "camelCase", deny_unknown_fields)]
34pub struct SessionEndpointProviders {
35    /// Merged field by field over the top-level fields for the session's
36    /// Meta endpoint.
37    #[serde(default, skip_serializing_if = "Option::is_none")]
38    pub meta: Option<SessionEndpointProviderOverride>,
39    /// The session's own Anthropic endpoint, which serves its Claude
40    /// models; it inherits nothing from the top level and needs a
41    /// `baseUrl`. Absent: the host's Anthropic route.
42    #[serde(default, skip_serializing_if = "Option::is_none")]
43    pub anthropic: Option<SessionEndpointProviderOverride>,
44}
45
46impl fmt::Debug for SessionEndpointProviders {
47    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
48        formatter
49            .debug_struct("SessionEndpointProviders")
50            .field("meta", &self.meta)
51            .field("anthropic", &self.anthropic)
52            .finish()
53    }
54}
55
56/// One provider's endpoint: the top level's transport fields, under the
57/// same wire names, without `allowOpenai`. Closed: an unknown field fails
58/// the decode.
59#[derive(Clone, Default, PartialEq, Eq, Serialize)]
60#[serde(rename_all = "camelCase")]
61pub struct SessionEndpointProviderOverride {
62    /// Endpoint base URL. Configuration diagnostics never echo it.
63    #[serde(default, skip_serializing_if = "Option::is_none")]
64    pub base_url: Option<String>,
65    /// Literal provider request headers.
66    #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
67    pub http_headers: BTreeMap<String, String>,
68    /// Provider header name -> environment variable name.
69    #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
70    pub env_http_headers: BTreeMap<String, String>,
71    /// An explicit HTTP proxy URL. Diagnostics never echo it.
72    #[serde(default, skip_serializing_if = "Option::is_none")]
73    pub proxy: Option<String>,
74    /// Path to the mTLS client certificate (PEM).
75    #[serde(default, skip_serializing_if = "Option::is_none")]
76    pub client_cert: Option<String>,
77    /// Path to the mTLS client private key (PEM).
78    #[serde(default, skip_serializing_if = "Option::is_none")]
79    pub client_key: Option<String>,
80    /// Optional CA bundle (PEM) to trust for the server side.
81    #[serde(default, skip_serializing_if = "Option::is_none")]
82    pub ca_bundle: Option<String>,
83    /// Auth mode. Absent = `bearer`.
84    #[serde(default, skip_serializing_if = "Option::is_none")]
85    pub auth: Option<SessionEndpointTransportAuthMode>,
86}
87
88impl fmt::Debug for SessionEndpointProviderOverride {
89    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
90        formatter
91            .debug_struct("SessionEndpointProviderOverride")
92            .field("base_url_present", &self.base_url.is_some())
93            .field("http_header_name_count", &self.http_headers.len())
94            .field("env_http_header_name_count", &self.env_http_headers.len())
95            .field("proxy_present", &self.proxy.is_some())
96            .field("client_cert_present", &self.client_cert.is_some())
97            .field("client_key_present", &self.client_key.is_some())
98            .field("ca_bundle_present", &self.ca_bundle.is_some())
99            .field("auth", &self.auth)
100            .finish()
101    }
102}
103
104impl<'de> Deserialize<'de> for SessionEndpointProviderOverride {
105    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
106    where
107        D: Deserializer<'de>,
108    {
109        #[derive(Deserialize)]
110        #[serde(rename_all = "camelCase", deny_unknown_fields)]
111        struct Wire {
112            #[serde(default)]
113            base_url: Option<String>,
114            #[serde(default)]
115            http_headers: BTreeMap<String, String>,
116            #[serde(default)]
117            env_http_headers: BTreeMap<String, String>,
118            #[serde(default)]
119            proxy: Option<String>,
120            #[serde(default)]
121            client_cert: Option<String>,
122            #[serde(default)]
123            client_key: Option<String>,
124            #[serde(default)]
125            ca_bundle: Option<String>,
126            #[serde(default)]
127            auth: Option<SessionEndpointTransportAuthMode>,
128        }
129
130        let wire = Wire::deserialize(deserializer).map_err(|_| {
131            D::Error::custom(
132                "session config modelEndpointTransportOverride.providers has a provider that is not an object, a field with the wrong type, or an unknown field",
133            )
134        })?;
135        check_header_names(wire.http_headers.keys().chain(wire.env_http_headers.keys()))
136            .map_err(D::Error::custom)?;
137        Ok(Self {
138            base_url: wire.base_url,
139            http_headers: wire.http_headers,
140            env_http_headers: wire.env_http_headers,
141            proxy: wire.proxy,
142            client_cert: wire.client_cert,
143            client_key: wire.client_key,
144            ca_bundle: wire.ca_bundle,
145            auth: wire.auth,
146        })
147    }
148}