Skip to main content

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 policy snapshot for a given version.
21    async fn get_policy_snapshot(
22        &self,
23        user_id: Uuid,
24        policy_version: u64,
25    ) -> Result<PolicySnapshot, MiniChatModelPolicyPluginError>;
26
27    /// Get per-user credit allocations for a specific policy version.
28    async fn get_user_limits(
29        &self,
30        user_id: Uuid,
31        policy_version: u64,
32    ) -> Result<UserLimits, MiniChatModelPolicyPluginError>;
33
34    /// Publish a usage event after turn finalization.
35    ///
36    /// Called by the outbox processor after the finalization transaction
37    /// commits. Plugins can forward the event to external billing systems.
38    async fn publish_usage(&self, payload: UsageEvent) -> Result<(), PublishError>;
39}