mini_chat_sdk/plugin_api.rs
1use async_trait::async_trait;
2use uuid::Uuid;
3
4use crate::error::{MiniChatModelPolicyPluginError, PublishError};
5use crate::models::{PolicySnapshot, PolicyVersionInfo, UsageEvent, UserLimits};
6
7/// Plugin API trait for mini-chat model policy implementations.
8///
9/// Plugins implement this trait to provide model catalog and policy data.
10/// The mini-chat module discovers plugins via GTS types-registry and
11/// delegates policy queries to the selected plugin.
12#[async_trait]
13pub trait MiniChatModelPolicyPluginClientV1: Send + Sync {
14 /// Get the current policy version for a user.
15 async fn get_current_policy_version(
16 &self,
17 user_id: Uuid,
18 ) -> Result<PolicyVersionInfo, MiniChatModelPolicyPluginError>;
19
20 /// Get the full policy snapshot for a given version, including
21 /// model catalog and kill switches.
22 async fn get_policy_snapshot(
23 &self,
24 user_id: Uuid,
25 policy_version: u64,
26 ) -> Result<PolicySnapshot, MiniChatModelPolicyPluginError>;
27
28 /// Get per-user credit limits for a specific policy version.
29 async fn get_user_limits(
30 &self,
31 user_id: Uuid,
32 policy_version: u64,
33 ) -> Result<UserLimits, MiniChatModelPolicyPluginError>;
34
35 /// Publish a usage event after turn finalization.
36 ///
37 /// Called by the outbox processor after the finalization transaction
38 /// commits. Plugins can forward the event to external billing systems.
39 async fn publish_usage(&self, payload: UsageEvent) -> Result<(), PublishError>;
40}