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    pub display_name: String,
37    pub tier: ModelTier,
38    pub global_enabled: bool,
39    pub is_default: bool,
40    /// Credit multiplier for input tokens (micro-credits per 1000 tokens).
41    pub input_tokens_credit_multiplier_micro: u64,
42    /// Credit multiplier for output tokens (micro-credits per 1000 tokens).
43    pub output_tokens_credit_multiplier_micro: u64,
44    /// Model capabilities, e.g. `VISION_INPUT`, `IMAGE_GENERATION`.
45    pub multimodal_capabilities: Vec<String>,
46    /// Maximum context window size in tokens.
47    pub context_window: u32,
48    /// Maximum output tokens the model can generate.
49    pub max_output_tokens: u32,
50    /// Human-readable model description.
51    pub description: String,
52    /// Display name for the provider (e.g. `OpenAI`).
53    pub provider_display_name: String,
54    /// Human-readable multiplier display string (e.g. "1x", "3x").
55    pub multiplier_display: String,
56    /// Routing identifier for provider resolution. Maps to a key in
57    /// `MiniChatConfig.providers`. Values: `"openai"`, `"azure_openai"`.
58    pub provider_id: String,
59}
60
61/// Model pricing/capability tier.
62#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
63pub enum ModelTier {
64    Standard,
65    Premium,
66}
67
68/// Per-user credit allocations for a specific policy version.
69/// NOT part of the immutable shared `PolicySnapshot` (DESIGN.md §5.2.6).
70#[derive(Debug, Clone, Serialize, Deserialize)]
71pub struct UserLimits {
72    pub user_id: Uuid,
73    pub policy_version: u64,
74    pub standard: TierLimits,
75    pub premium: TierLimits,
76}
77
78/// Credit limits for a single tier within a billing period.
79#[derive(Debug, Clone, Serialize, Deserialize)]
80pub struct TierLimits {
81    pub limit_daily_credits_micro: i64,
82    pub limit_monthly_credits_micro: i64,
83}
84
85/// Token usage reported by the provider.
86#[derive(Debug, Clone, Serialize, Deserialize)]
87pub struct UsageTokens {
88    pub input_tokens: u64,
89    pub output_tokens: u64,
90}
91
92/// Canonical usage event payload published via the outbox after finalization.
93///
94/// Single canonical type — both the outbox enqueuer (infra) and the plugin
95/// `publish_usage()` method use this same struct.
96#[derive(Debug, Clone, Serialize, Deserialize)]
97pub struct UsageEvent {
98    pub tenant_id: Uuid,
99    pub user_id: Uuid,
100    pub chat_id: Uuid,
101    pub turn_id: Uuid,
102    pub request_id: Uuid,
103    pub effective_model: String,
104    pub selected_model: String,
105    pub terminal_state: String,
106    pub billing_outcome: String,
107    pub usage: Option<UsageTokens>,
108    pub actual_credits_micro: i64,
109    pub settlement_method: String,
110    pub policy_version_applied: i64,
111    pub timestamp: OffsetDateTime,
112}