codex_protocol/
capabilities.rs1use 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#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema, TS)]
10#[serde(rename_all = "camelCase")]
11#[ts(export_to = "v2/")]
12pub struct SelectedCapabilityRoot {
13 pub id: String,
15 pub location: CapabilityRootLocation,
17}
18
19#[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 Environment {
27 #[serde(rename = "environmentId")]
28 #[ts(rename = "environmentId")]
29 environment_id: String,
30 #[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;