ccs_proxy/provider/
mod.rs1use serde::{Deserialize, Serialize};
2use std::str::FromStr;
3
4pub mod claude;
5pub mod codex;
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
8#[serde(rename_all = "lowercase")]
9#[non_exhaustive]
10pub enum ProviderKind {
11 Claude,
12 Codex,
13}
14
15#[derive(Debug, thiserror::Error)]
16#[error("unknown provider `{0}` (supported: claude, codex)")]
17pub struct UnknownProvider(pub String);
18
19impl FromStr for ProviderKind {
20 type Err = UnknownProvider;
21 fn from_str(s: &str) -> Result<Self, Self::Err> {
22 match s {
23 "claude" => Ok(Self::Claude),
24 "codex" => Ok(Self::Codex),
25 other => Err(UnknownProvider(other.to_string())),
26 }
27 }
28}
29
30impl ProviderKind {
31 pub fn as_str(self) -> &'static str {
32 match self {
33 Self::Claude => "claude",
34 Self::Codex => "codex",
35 }
36 }
37
38 pub fn is_path_recognized(self, path: &str) -> bool {
39 match self {
40 Self::Claude => path.starts_with("/v1/messages"),
41 Self::Codex => {
42 path.starts_with("/v1/responses") || path.starts_with("/v1/chat/completions")
43 }
44 }
45 }
46}