Skip to main content

systemprompt_models/services/ai/
model.rs

1//! Per-provider AI policy and per-model descriptors.
2//!
3//! [`AiProviderConfig`] is the deployment policy layered on a registry provider
4//! (enable flag, default-model overrides, resilience). [`ModelDefinition`] and
5//! its [`ModelCapabilities`], [`ModelLimits`], and [`ModelPricing`] are the
6//! per-model descriptors shared with `profile.providers`. Connectivity itself
7//! is never modelled here — it lives in the provider registry.
8
9use serde::{Deserialize, Serialize};
10
11use super::config::ResilienceSettings;
12
13const fn default_true() -> bool {
14    true
15}
16
17#[expect(
18    clippy::struct_excessive_bools,
19    reason = "model capability matrix: each bool is an independent provider feature flag, not \
20              state"
21)]
22#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize, schemars::JsonSchema)]
23pub struct ModelCapabilities {
24    #[serde(default)]
25    pub vision: bool,
26
27    #[serde(default)]
28    pub audio_input: bool,
29
30    #[serde(default)]
31    pub video_input: bool,
32
33    #[serde(default)]
34    pub image_generation: bool,
35
36    #[serde(default)]
37    pub audio_generation: bool,
38
39    #[serde(default)]
40    pub streaming: bool,
41
42    #[serde(default)]
43    pub tools: bool,
44
45    #[serde(default)]
46    pub structured_output: bool,
47
48    #[serde(default)]
49    pub system_prompts: bool,
50
51    #[serde(default)]
52    pub image_resolution_config: bool,
53}
54
55#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize, schemars::JsonSchema)]
56pub struct ModelLimits {
57    #[serde(default)]
58    pub context_window: u32,
59
60    #[serde(default)]
61    pub max_output_tokens: u32,
62
63    /// Maximum extended-thinking / reasoning budget (in tokens) the upstream
64    /// accepts for this model. `None` means the provider validates the budget
65    /// itself (Anthropic) or maps it to an effort bucket (`OpenAI`); set it for
66    /// providers that reject an out-of-range numeric budget (Gemini: 24576 for
67    /// flash, 32768 for pro). The gateway clamps the requested budget to this.
68    #[serde(default, skip_serializing_if = "Option::is_none")]
69    pub max_thinking_budget: Option<u32>,
70}
71
72#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize, schemars::JsonSchema)]
73pub struct ModelPricing {
74    #[serde(default)]
75    pub input_per_million: f64,
76
77    #[serde(default)]
78    pub output_per_million: f64,
79
80    #[serde(default)]
81    pub per_image_cents: Option<f64>,
82}
83
84#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize)]
85pub struct ModelDefinition {
86    #[serde(default)]
87    pub capabilities: ModelCapabilities,
88
89    #[serde(default)]
90    pub limits: ModelLimits,
91
92    #[serde(default)]
93    pub pricing: ModelPricing,
94}
95
96/// Per-provider AI *policy*, keyed by registry provider name.
97///
98/// Connectivity (endpoint, credential, model catalog) lives in the profile
99/// `providers` registry; this struct carries only the policy a deployment
100/// layers on top of an entry: whether the provider is enabled, its agent-side
101/// default-model override, image defaults, web-search toggle, and resilience.
102#[derive(Debug, Clone, Serialize, Deserialize)]
103pub struct AiProviderConfig {
104    #[serde(default = "default_true")]
105    pub enabled: bool,
106
107    /// Overrides the provider client's built-in default model when non-empty.
108    #[serde(default)]
109    pub default_model: String,
110
111    #[serde(default)]
112    pub default_image_model: String,
113
114    #[serde(default)]
115    pub google_search_enabled: bool,
116
117    /// Resilience policy applied to outbound AI provider calls (timeouts,
118    /// retry, circuit breaker, bulkhead).
119    #[serde(default)]
120    pub resilience: ResilienceSettings,
121}
122
123impl Default for AiProviderConfig {
124    fn default() -> Self {
125        Self {
126            enabled: true,
127            default_model: String::new(),
128            default_image_model: String::new(),
129            google_search_enabled: false,
130            resilience: ResilienceSettings::default(),
131        }
132    }
133}