Skip to main content

objectiveai_sdk/agent/
upstream.rs

1//! Upstream enumeration.
2
3use schemars::JsonSchema;
4use serde::{Deserialize, Serialize};
5
6/// Supported agent upstreams.
7#[derive(
8    Debug,
9    Clone,
10    Copy,
11    PartialEq,
12    Eq,
13    Hash,
14    Serialize,
15    Deserialize,
16    Default,
17    JsonSchema,
18    arbitrary::Arbitrary,
19)]
20#[serde(rename_all = "snake_case")]
21#[schemars(rename = "agent.Upstream")]
22pub enum Upstream {
23    /// Unknown Upstream.
24    #[schemars(title = "Unknown")]
25    #[default]
26    Unknown,
27    /// OpenRouter Upstream.
28    #[schemars(title = "Openrouter")]
29    Openrouter,
30    /// Claude Agent SDK Upstream.
31    #[schemars(title = "ClaudeAgentSdk")]
32    ClaudeAgentSdk,
33    /// Codex SDK Upstream.
34    #[schemars(title = "CodexSdk")]
35    CodexSdk,
36    /// Mock Upstream.
37    #[schemars(title = "Mock")]
38    Mock,
39    /// Script Upstream.
40    #[schemars(title = "Script")]
41    Script,
42}
43
44pub mod validate {
45    use super::Upstream;
46
47    pub fn validate(upstreams: &[Upstream]) -> Result<(), String> {
48        // Check for duplicates
49        let mut seen = std::collections::HashSet::new();
50        for upstream in upstreams {
51            if !seen.insert(upstream) {
52                return Err(
53                    "`upstreams` contains duplicate entries".to_string()
54                );
55            }
56        }
57
58        // Check for Unknown
59        if seen.contains(&Upstream::Unknown) {
60            return Err("`upstreams` contains unknown upstream".to_string());
61        }
62
63        Ok(())
64    }
65}