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///
10/// Serializable for logs and tests; the serialized form is not part of the
11/// stable set and may change in any release.
12#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
13pub enum Protocol {
14    /// OpenAI Chat Completions request and response format.
15    #[serde(rename = "openai_chat_completions")]
16    OpenAiChatCompletions,
17    /// Anthropic Messages request and response format.
18    #[serde(rename = "anthropic_messages")]
19    AnthropicMessages,
20    /// OpenAI Responses request and response format.
21    #[serde(rename = "openai_responses")]
22    OpenAiResponses,
23}
24
25impl Protocol {
26    /// The stable protocol name used by its serde representation.
27    pub fn as_str(self) -> &'static str {
28        match self {
29            Self::OpenAiChatCompletions => "openai_chat_completions",
30            Self::AnthropicMessages => "anthropic_messages",
31            Self::OpenAiResponses => "openai_responses",
32        }
33    }
34}
35
36impl std::fmt::Display for Protocol {
37    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
38        f.write_str(self.as_str())
39    }
40}