Skip to main content

agent_api/
runtime_support.rs

1use crate::AgentWrapperError;
2
3#[derive(Clone, Debug, Eq, PartialEq)]
4pub struct RuntimeSupportRecord {
5    pub runtime_family: String,
6    pub target_triple: String,
7    pub version: String,
8}
9
10#[derive(Clone, Copy, Debug, Eq, PartialEq)]
11struct EmbeddedRuntimeSupportRecord {
12    target_triple: &'static str,
13    latest_validated: Option<&'static str>,
14}
15
16include!("runtime_support_data.rs");
17
18fn runtime_family_records(runtime_family: &str) -> Option<&'static [EmbeddedRuntimeSupportRecord]> {
19    match runtime_family {
20        #[cfg(feature = "codex")]
21        "codex" => Some(CODEX_RUNTIME_SUPPORT),
22        _ => None,
23    }
24}
25
26pub fn resolve_runtime_support(
27    runtime_family: &str,
28    target_triple: &str,
29) -> Result<RuntimeSupportRecord, AgentWrapperError> {
30    let records = runtime_family_records(runtime_family).ok_or_else(|| {
31        AgentWrapperError::UnknownRuntimeFamily {
32            runtime_family: runtime_family.to_string(),
33        }
34    })?;
35    let record = records
36        .iter()
37        .find(|record| record.target_triple == target_triple);
38    let Some(record) = record else {
39        return Err(AgentWrapperError::UnsupportedTargetTriple {
40            runtime_family: runtime_family.to_string(),
41            target_triple: target_triple.to_string(),
42        });
43    };
44
45    let Some(version) = record.latest_validated else {
46        return Err(AgentWrapperError::MissingValidatedRuntime {
47            runtime_family: runtime_family.to_string(),
48            target_triple: target_triple.to_string(),
49        });
50    };
51
52    Ok(RuntimeSupportRecord {
53        runtime_family: runtime_family.to_string(),
54        target_triple: target_triple.to_string(),
55        version: version.to_string(),
56    })
57}
58
59pub fn list_runtime_support(
60    runtime_family: &str,
61) -> Result<Vec<RuntimeSupportRecord>, AgentWrapperError> {
62    let records = runtime_family_records(runtime_family).ok_or_else(|| {
63        AgentWrapperError::UnknownRuntimeFamily {
64            runtime_family: runtime_family.to_string(),
65        }
66    })?;
67
68    let mut resolved = records
69        .iter()
70        .filter_map(|record| {
71            record.latest_validated.map(|version| RuntimeSupportRecord {
72                runtime_family: runtime_family.to_string(),
73                target_triple: record.target_triple.to_string(),
74                version: version.to_string(),
75            })
76        })
77        .collect::<Vec<_>>();
78    resolved.sort_by(|left, right| left.target_triple.cmp(&right.target_triple));
79    Ok(resolved)
80}