systemprompt_ai/services/gateway/
spec.rs1use serde::{Deserialize, Serialize};
14
15#[derive(Debug, Clone, Serialize, Deserialize)]
16#[serde(deny_unknown_fields)]
17pub struct QuotaWindow {
18 pub window_seconds: i32,
19 #[serde(default = "default_subject")]
20 pub subject: String,
21 pub max_requests: Option<i64>,
22 pub max_input_tokens: Option<i64>,
23 pub max_output_tokens: Option<i64>,
24 #[serde(default)]
25 pub max_cost_microdollars: Option<i64>,
26}
27
28impl Default for QuotaWindow {
29 fn default() -> Self {
30 Self {
31 window_seconds: 0,
32 subject: default_subject(),
33 max_requests: None,
34 max_input_tokens: None,
35 max_output_tokens: None,
36 max_cost_microdollars: None,
37 }
38 }
39}
40
41fn default_subject() -> String {
42 "user".to_owned()
43}
44
45pub const USER_QUOTA_SUBJECT: &str = "user";
46
47#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
53#[serde(rename_all = "lowercase")]
54pub enum SafetyHistoryMode {
55 #[default]
56 Off,
57 Audit,
58 Block,
59}
60
61#[derive(Debug, Clone, Serialize, Deserialize, Default)]
63#[serde(deny_unknown_fields)]
64pub struct HeuristicConfig {
65 #[serde(default)]
66 pub phrases: Option<Vec<String>>,
67 #[serde(default)]
68 pub extra_phrases: Vec<String>,
69 #[serde(default)]
70 pub disable_builtin: bool,
71}
72
73#[derive(Debug, Clone, Serialize, Deserialize, Default)]
74#[serde(deny_unknown_fields)]
75pub struct SafetyConfig {
76 #[serde(default)]
77 pub scanners: Vec<String>,
78 #[serde(default)]
79 pub heuristic: HeuristicConfig,
80 #[serde(default)]
81 pub block_categories: Vec<String>,
82 #[serde(default)]
83 pub block_response_categories: Vec<String>,
84 #[serde(default)]
85 pub history: SafetyHistoryMode,
86}
87
88#[derive(Debug, Clone, Serialize, Deserialize, Default)]
89#[serde(deny_unknown_fields)]
90pub struct GatewayPolicySpec {
91 #[serde(default)]
92 pub quota_windows: Vec<QuotaWindow>,
93 #[serde(default)]
94 pub safety: SafetyConfig,
95}
96
97impl GatewayPolicySpec {
98 #[must_use]
99 pub fn permissive() -> Self {
100 Self::default()
101 }
102}