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 per-call ceilings, quota windows,
5//! and safety 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 max_input_tokens_per_call: Option<u32>,
35    #[serde(default)]
36    pub max_tool_depth: Option<u32>,
37    #[serde(default)]
38    pub quota_windows: Vec<QuotaWindow>,
39    #[serde(default)]
40    pub safety: SafetyConfig,
41}
42
43impl GatewayPolicySpec {
44    #[must_use]
45    pub fn permissive() -> Self {
46        Self::default()
47    }
48}