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