Skip to main content

systemprompt_models/profile/providers/
protocol.rs

1//! Wire-protocol family for an upstream AI provider.
2//!
3//! [`WireProtocol`] names the *request/response shape* a provider speaks, not
4//! the vendor. It is the single key that both the gateway's outbound adapters
5//! and the agent-flow provider clients resolve a wire codec from: `minimax`
6//! speaks [`WireProtocol::Anthropic`]; `moonshot` and `qwen` speak
7//! [`WireProtocol::OpenAiChat`]. Decoupling the protocol from the provider name
8//! is what lets a new vendor reuse an existing codec by declaring its protocol.
9
10use serde::{Deserialize, Serialize};
11
12/// The wire-format family a provider's endpoint speaks.
13#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, schemars::JsonSchema)]
14pub enum WireProtocol {
15    #[serde(rename = "anthropic")]
16    Anthropic,
17    #[serde(rename = "openai-chat", alias = "openai_chat", alias = "openai")]
18    OpenAiChat,
19    #[serde(rename = "openai-responses", alias = "openai_responses")]
20    OpenAiResponses,
21    #[serde(rename = "gemini")]
22    Gemini,
23}
24
25impl WireProtocol {
26    /// The stable string tag used to resolve a codec/adapter for this protocol.
27    #[must_use]
28    pub const fn as_tag(self) -> &'static str {
29        match self {
30            Self::Anthropic => "anthropic",
31            Self::OpenAiChat => "openai-chat",
32            Self::OpenAiResponses => "openai-responses",
33            Self::Gemini => "gemini",
34        }
35    }
36}
37
38impl std::fmt::Display for WireProtocol {
39    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
40        f.write_str(self.as_tag())
41    }
42}