Skip to main content

mini_chat_sdk/
models.rs

1use serde::{Deserialize, Serialize};
2use time::OffsetDateTime;
3use uuid::Uuid;
4
5/// Current policy version metadata for a user.
6#[derive(Debug, Clone)]
7pub struct PolicyVersionInfo {
8    pub user_id: Uuid,
9    pub policy_version: u64,
10    pub generated_at: OffsetDateTime,
11}
12
13/// Full policy snapshot for a given version, including the model catalog.
14#[derive(Debug, Clone)]
15pub struct PolicySnapshot {
16    pub user_id: Uuid,
17    pub policy_version: u64,
18    pub model_catalog: Vec<ModelCatalogEntry>,
19    pub kill_switches: KillSwitches,
20}
21
22/// Tenant-level kill switches from the policy snapshot.
23#[allow(clippy::struct_excessive_bools)]
24#[derive(Debug, Clone, Default, Serialize, Deserialize)]
25pub struct KillSwitches {
26    pub disable_premium_tier: bool,
27    pub force_standard_tier: bool,
28    pub disable_web_search: bool,
29    pub disable_file_search: bool,
30}
31
32/// A single model in the catalog.
33#[derive(Debug, Clone, Serialize, Deserialize)]
34pub struct ModelCatalogEntry {
35    pub model_id: String,
36    /// The model ID on the provider side (e.g., `"gpt-5.2"` for `OpenAI`,
37    /// `"claude-opus-4-6"` for Anthropic). Sent in LLM API requests.
38    pub provider_model_id: String,
39    pub display_name: String,
40    pub tier: ModelTier,
41    pub global_enabled: bool,
42    pub is_default: bool,
43    /// Credit multiplier for input tokens (micro-credits per 1000 tokens).
44    pub input_tokens_credit_multiplier_micro: u64,
45    /// Credit multiplier for output tokens (micro-credits per 1000 tokens).
46    pub output_tokens_credit_multiplier_micro: u64,
47    /// Model capabilities, e.g. `VISION_INPUT`, `IMAGE_GENERATION`.
48    pub multimodal_capabilities: Vec<String>,
49    /// Maximum context window size in tokens.
50    pub context_window: u32,
51    /// Maximum output tokens the model can generate.
52    pub max_output_tokens: u32,
53    /// Human-readable model description.
54    pub description: String,
55    /// Display name for the provider (e.g. `OpenAI`).
56    pub provider_display_name: String,
57    /// Human-readable multiplier display string (e.g. "1x", "3x").
58    pub multiplier_display: String,
59    /// Routing identifier for provider resolution. Maps to a key in
60    /// `MiniChatConfig.providers`. Values: `"openai"`, `"azure_openai"`.
61    pub provider_id: String,
62}
63
64/// Model pricing/capability tier.
65#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
66pub enum ModelTier {
67    Standard,
68    Premium,
69}
70
71/// Per-user credit allocations for a specific policy version.
72/// NOT part of the immutable shared `PolicySnapshot` (DESIGN.md §5.2.6).
73#[derive(Debug, Clone, Serialize, Deserialize)]
74pub struct UserLimits {
75    pub user_id: Uuid,
76    pub policy_version: u64,
77    pub standard: TierLimits,
78    pub premium: TierLimits,
79}
80
81/// Credit limits for a single tier within a billing period.
82#[derive(Debug, Clone, Serialize, Deserialize)]
83pub struct TierLimits {
84    pub limit_daily_credits_micro: i64,
85    pub limit_monthly_credits_micro: i64,
86}
87
88/// Token usage reported by the provider.
89#[derive(Debug, Clone, Serialize, Deserialize)]
90pub struct UsageTokens {
91    pub input_tokens: u64,
92    pub output_tokens: u64,
93}
94
95/// Canonical usage event payload published via the outbox after finalization.
96///
97/// Single canonical type — both the outbox enqueuer (infra) and the plugin
98/// `publish_usage()` method use this same struct.
99#[derive(Debug, Clone, Serialize, Deserialize)]
100pub struct UsageEvent {
101    pub tenant_id: Uuid,
102    pub user_id: Uuid,
103    pub chat_id: Uuid,
104    pub turn_id: Uuid,
105    pub request_id: Uuid,
106    pub effective_model: String,
107    pub selected_model: String,
108    pub terminal_state: String,
109    pub billing_outcome: String,
110    pub usage: Option<UsageTokens>,
111    pub actual_credits_micro: i64,
112    pub settlement_method: String,
113    pub policy_version_applied: i64,
114    pub timestamp: OffsetDateTime,
115}