Skip to main content

causa_protocol/
protocol.rs

1//! Wire-protocol discriminator for provider adapters.
2
3use serde::{Deserialize, Serialize};
4
5/// Discriminator for the message protocol a provider entry speaks.
6///
7/// Exhaustive on purpose: a gateway is built for exactly one protocol and a
8/// host selects by it, so a new one is a breaking change.
9#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
10pub enum Protocol {
11    /// OpenAI Chat Completions request and response format.
12    #[serde(rename = "openai_chat_completions")]
13    OpenAiChatCompletions,
14    /// Anthropic Messages request and response format.
15    #[serde(rename = "anthropic_messages")]
16    AnthropicMessages,
17    /// OpenAI Responses request and response format.
18    #[serde(rename = "openai_responses")]
19    OpenAiResponses,
20}
21
22impl Protocol {
23    /// The stable protocol name used by its serde representation.
24    pub fn as_str(self) -> &'static str {
25        match self {
26            Self::OpenAiChatCompletions => "openai_chat_completions",
27            Self::AnthropicMessages => "anthropic_messages",
28            Self::OpenAiResponses => "openai_responses",
29        }
30    }
31}
32
33impl std::fmt::Display for Protocol {
34    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
35        f.write_str(self.as_str())
36    }
37}