use std::fmt;
use serde::{Deserialize, Serialize};
pub const AUTO_SENTINEL: &str = "auto";
use crate::ProviderKind;
macro_rules! string_newtype {
($(#[$meta:meta])* $name:ident) => {
$(#[$meta])*
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(transparent)]
pub struct $name(String);
impl $name {
#[must_use]
pub fn as_str(&self) -> &str {
&self.0
}
}
impl From<&str> for $name {
fn from(value: &str) -> Self {
Self(value.to_string())
}
}
impl From<String> for $name {
fn from(value: String) -> Self {
Self(value)
}
}
impl AsRef<str> for $name {
fn as_ref(&self) -> &str {
&self.0
}
}
impl fmt::Display for $name {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.0)
}
}
};
}
string_newtype!(
ProviderId
);
string_newtype!(
ModelId
);
string_newtype!(
WireModelId
);
string_newtype!(
LogicalModelRef
);
impl ProviderId {
#[must_use]
pub fn from_kind(kind: ProviderKind) -> Self {
Self(kind.as_str().to_string())
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub enum NamespaceHint {
DeepseekAi,
Deepseek,
Anthropic,
Openai,
Qwen,
}
impl LogicalModelRef {
#[must_use]
pub fn raw(&self) -> &str {
self.as_str()
}
#[must_use]
pub fn is_auto(&self) -> bool {
self.raw() == AUTO_SENTINEL
}
#[must_use]
pub fn namespace_hint(&self) -> Option<NamespaceHint> {
let raw = self.raw();
if raw.starts_with("deepseek-ai/") {
Some(NamespaceHint::DeepseekAi)
} else if raw.starts_with("deepseek/") {
Some(NamespaceHint::Deepseek)
} else if raw.starts_with("anthropic/") {
Some(NamespaceHint::Anthropic)
} else if raw.starts_with("openai/") {
Some(NamespaceHint::Openai)
} else if raw.starts_with("qwen/") {
Some(NamespaceHint::Qwen)
} else {
None
}
}
}