systemprompt_models/bridge/
profile.rs1use serde::{Deserialize, Serialize};
19
20use crate::profile::{ApiSurface, ProviderRegistry};
21
22#[derive(Debug, Clone, Serialize, Deserialize)]
23pub struct BridgeProfileResponse {
24 pub inference_gateway_base_url: String,
25 pub auth_scheme: String,
26 #[serde(default)]
27 pub models: Vec<String>,
28 #[serde(default, skip_serializing_if = "Option::is_none")]
31 pub default_model: Option<String>,
32 #[serde(default)]
33 pub organization_uuid: Option<String>,
34 #[serde(default)]
35 pub providers: Vec<ProviderHealth>,
36}
37
38#[derive(Debug, Clone, Serialize, Deserialize)]
41pub struct ProviderHealth {
42 pub name: String,
43 pub surface: ApiSurface,
44 pub configured: bool,
45 #[serde(default)]
46 pub models: Vec<String>,
47 #[serde(default, skip_serializing_if = "Option::is_none")]
48 pub config_issue: Option<String>,
49}
50
51pub fn provider_health(
52 registry: &ProviderRegistry,
53 secret_present: impl Fn(&str) -> bool,
54) -> Vec<ProviderHealth> {
55 registry
56 .advertised_providers()
57 .map(|entry| {
58 let secret = entry.api_key_secret.as_str();
59 let configured = secret_present(secret);
60 ProviderHealth {
61 name: entry.name.as_str().to_owned(),
62 surface: entry.surface,
63 configured,
64 models: entry
65 .models
66 .iter()
67 .flat_map(|m| {
68 std::iter::once(m.id.as_str().to_owned())
69 .chain(m.aliases.iter().map(|a| a.as_str().to_owned()))
70 })
71 .collect(),
72 config_issue: (!configured)
73 .then(|| format!("API key secret '{secret}' is not configured")),
74 }
75 })
76 .collect()
77}
78
79#[derive(Debug, Clone)]
80pub struct BridgeProfileParams<'a> {
81 pub inference_gateway_base_url: String,
82 pub auth_scheme: String,
83 pub organization_uuid: Option<String>,
84 pub default_model: Option<String>,
85 pub registry: &'a ProviderRegistry,
86}
87
88#[must_use]
89pub fn build(
90 params: BridgeProfileParams<'_>,
91 secret_present: impl Fn(&str) -> bool,
92) -> BridgeProfileResponse {
93 let BridgeProfileParams {
94 inference_gateway_base_url,
95 auth_scheme,
96 organization_uuid,
97 default_model,
98 registry,
99 } = params;
100 BridgeProfileResponse {
101 inference_gateway_base_url,
102 auth_scheme,
103 models: registry.advertised_model_ids(&[ApiSurface::Anthropic]),
104 default_model,
105 organization_uuid,
106 providers: provider_health(registry, secret_present),
107 }
108}