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