Skip to main content

relay_knowledge/model_provider/
mod.rs

1//! Model provider profiles, catalog cache, and connectivity diagnostics.
2//!
3//! The module owns provider configuration data and async file/network workflows.
4//! It does not read environment variables directly; callers pass resolved paths,
5//! network policy, and retrieval runtime metadata.
6
7mod catalog;
8mod connectivity;
9mod fallback;
10mod persistence;
11mod profile;
12mod profile_config;
13mod profiles;
14
15use std::{error::Error, fmt};
16
17pub use catalog::{ModelCatalogModel, ModelCatalogProvider, ModelCatalogResult};
18pub use connectivity::{
19    ModelConnectivityDiagnostics, ModelConnectivityProbeRequest, ModelConnectivityProbeResult,
20    ModelConnectivityTokenUsage, ModelDiscoveryEntry, ModelDiscoveryRequest, ModelDiscoveryResult,
21};
22pub use fallback::{ModelFallbackConfig, ModelFallbackPolicy, ModelFallbackStrategy};
23pub use profile::{
24    ModelCapabilities, ModelModalityMatrix, ModelProfileRuntimeSummary, ModelProfileSaveRequest,
25    ModelProfileView, ModelProfilesResponse, ModelProviderKind, ModelRequestHeader,
26};
27
28use crate::paths::RuntimePaths;
29
30const DEFAULT_CATALOG_SOURCE_URL: &str = "https://models.dev/api.json";
31
32#[cfg(test)]
33mod test_support;
34
35/// Async model provider configuration service.
36#[derive(Debug, Clone)]
37pub struct ModelProviderConfigService {
38    paths: RuntimePaths,
39    catalog_source_url: String,
40}
41
42impl ModelProviderConfigService {
43    pub fn new(paths: RuntimePaths) -> Self {
44        Self {
45            paths,
46            catalog_source_url: DEFAULT_CATALOG_SOURCE_URL.to_owned(),
47        }
48    }
49}
50
51/// Error from model provider configuration and diagnostics.
52#[derive(Debug, Clone, PartialEq, Eq)]
53pub enum ModelProviderError {
54    InvalidInput(String),
55    Io(String),
56    Json(String),
57    Network(String),
58}
59
60impl fmt::Display for ModelProviderError {
61    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
62        match self {
63            Self::InvalidInput(message)
64            | Self::Io(message)
65            | Self::Json(message)
66            | Self::Network(message) => formatter.write_str(message),
67        }
68    }
69}
70
71impl Error for ModelProviderError {}
72
73impl From<std::io::Error> for ModelProviderError {
74    fn from(error: std::io::Error) -> Self {
75        Self::Io(error.to_string())
76    }
77}
78
79impl From<serde_json::Error> for ModelProviderError {
80    fn from(error: serde_json::Error) -> Self {
81        Self::Json(error.to_string())
82    }
83}