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        "codex" => Some(CODEX_RUNTIME_SUPPORT),
21        _ => None,
22    }
23}
24
25pub fn resolve_runtime_support(
26    runtime_family: &str,
27    target_triple: &str,
28) -> Result<RuntimeSupportRecord, AgentWrapperError> {
29    let records = runtime_family_records(runtime_family).ok_or_else(|| {
30        AgentWrapperError::UnknownRuntimeFamily {
31            runtime_family: runtime_family.to_string(),
32        }
33    })?;
34    let record = records
35        .iter()
36        .find(|record| record.target_triple == target_triple);
37    let Some(record) = record else {
38        return Err(AgentWrapperError::UnsupportedTargetTriple {
39            runtime_family: runtime_family.to_string(),
40            target_triple: target_triple.to_string(),
41        });
42    };
43
44    let Some(version) = record.latest_validated else {
45        return Err(AgentWrapperError::MissingValidatedRuntime {
46            runtime_family: runtime_family.to_string(),
47            target_triple: target_triple.to_string(),
48        });
49    };
50
51    Ok(RuntimeSupportRecord {
52        runtime_family: runtime_family.to_string(),
53        target_triple: target_triple.to_string(),
54        version: version.to_string(),
55    })
56}
57
58pub fn list_runtime_support(
59    runtime_family: &str,
60) -> Result<Vec<RuntimeSupportRecord>, AgentWrapperError> {
61    let records = runtime_family_records(runtime_family).ok_or_else(|| {
62        AgentWrapperError::UnknownRuntimeFamily {
63            runtime_family: runtime_family.to_string(),
64        }
65    })?;
66
67    let mut resolved = records
68        .iter()
69        .filter_map(|record| {
70            record.latest_validated.map(|version| RuntimeSupportRecord {
71                runtime_family: runtime_family.to_string(),
72                target_triple: record.target_triple.to_string(),
73                version: version.to_string(),
74            })
75        })
76        .collect::<Vec<_>>();
77    resolved.sort_by(|left, right| left.target_triple.cmp(&right.target_triple));
78    Ok(resolved)
79}