Skip to main content

codex_protocol/
capabilities.rs

1use codex_utils_path_uri::LegacyAppPathString;
2use codex_utils_path_uri::PathUri;
3use schemars::JsonSchema;
4use serde::Deserialize;
5use serde::Serialize;
6use ts_rs::TS;
7
8/// A user-selected root that can expose one or more runtime capabilities.
9#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema, TS)]
10#[serde(rename_all = "camelCase")]
11#[ts(export_to = "v2/")]
12pub struct SelectedCapabilityRoot {
13    /// Stable identifier supplied by the capability selection platform.
14    pub id: String,
15    /// Where the selected root can be resolved.
16    pub location: CapabilityRootLocation,
17}
18
19/// Location used to resolve a selected capability root.
20#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema, TS)]
21#[serde(tag = "type", rename_all = "camelCase")]
22#[ts(tag = "type")]
23#[ts(export_to = "v2/")]
24pub enum CapabilityRootLocation {
25    /// A path owned by an execution environment.
26    Environment {
27        #[serde(rename = "environmentId")]
28        #[ts(rename = "environmentId")]
29        environment_id: String,
30        /// Absolute path for the root in the selected environment.
31        #[serde(deserialize_with = "deserialize_path_uri_from_api_path")]
32        #[schemars(with = "String")]
33        #[ts(type = "string")]
34        path: PathUri,
35    },
36}
37
38fn deserialize_path_uri_from_api_path<'de, D>(deserializer: D) -> Result<PathUri, D::Error>
39where
40    D: serde::Deserializer<'de>,
41{
42    let path = LegacyAppPathString::deserialize(deserializer)?;
43    if let Ok(path_uri) = PathUri::parse(path.as_str()) {
44        return Ok(path_uri);
45    }
46    path.try_into().map_err(serde::de::Error::custom)
47}
48
49#[cfg(test)]
50#[path = "capabilities_tests.rs"]
51mod tests;