Skip to main content

cpa_core/
format.rs

1//! Wire formats a request or response can be in (sdk/translator/formats.go).
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
4pub enum Format {
5    /// OpenAI Chat Completions.
6    OpenAI,
7    /// OpenAI Responses.
8    OpenAIResponse,
9    /// Anthropic Messages.
10    Claude,
11    /// Gemini generateContent.
12    Gemini,
13    /// Codex flavour of the Responses API.
14    Codex,
15    /// Antigravity envelope around Gemini.
16    Antigravity,
17    /// Gemini Interactions.
18    Interactions,
19}
20
21impl Format {
22    pub const ALL: [Format; 7] = [
23        Format::OpenAI,
24        Format::OpenAIResponse,
25        Format::Claude,
26        Format::Gemini,
27        Format::Codex,
28        Format::Antigravity,
29        Format::Interactions,
30    ];
31
32    /// Identifier used by CLIProxyAPI in config and payload rules.
33    pub fn as_str(self) -> &'static str {
34        match self {
35            Format::OpenAI => "openai",
36            Format::OpenAIResponse => "openai-response",
37            Format::Claude => "claude",
38            Format::Gemini => "gemini",
39            Format::Codex => "codex",
40            Format::Antigravity => "antigravity",
41            Format::Interactions => "interactions",
42        }
43    }
44
45    pub fn parse(s: &str) -> Option<Self> {
46        Self::ALL.into_iter().find(|f| f.as_str() == s)
47    }
48}