Skip to main content

systemprompt_ai/services/gateway/
spec.rs

1//! Declarative gateway-policy specification.
2//!
3//! Spec payload of `ai_gateway_policies` rows, shared with the YAML schema in
4//! `services/gateway/policies.yaml`. Carries quota windows and safety
5//! configuration.
6//!
7//! Model exposure lives on the profile's gateway catalog, not here — see
8//! `GatewayConfig::is_model_exposed`.
9
10use serde::{Deserialize, Serialize};
11
12#[derive(Debug, Clone, Copy, Serialize, Deserialize, Default)]
13#[serde(deny_unknown_fields)]
14pub struct QuotaWindow {
15    pub window_seconds: i32,
16    pub max_requests: Option<i64>,
17    pub max_input_tokens: Option<i64>,
18    pub max_output_tokens: Option<i64>,
19}
20
21#[derive(Debug, Clone, Serialize, Deserialize, Default)]
22#[serde(deny_unknown_fields)]
23pub struct SafetyConfig {
24    #[serde(default)]
25    pub scanners: Vec<String>,
26    #[serde(default)]
27    pub block_categories: Vec<String>,
28}
29
30#[derive(Debug, Clone, Serialize, Deserialize, Default)]
31#[serde(deny_unknown_fields)]
32pub struct GatewayPolicySpec {
33    #[serde(default)]
34    pub quota_windows: Vec<QuotaWindow>,
35    #[serde(default)]
36    pub safety: SafetyConfig,
37}
38
39impl GatewayPolicySpec {
40    #[must_use]
41    pub fn permissive() -> Self {
42        Self::default()
43    }
44}