Skip to main content

batuta/serve/banco/
types.rs

1//! Banco API types — re-exports from domain-specific modules.
2
3#[path = "types_chat.rs"]
4mod types_chat;
5#[path = "types_data.rs"]
6mod types_data;
7
8// Re-export all types for backward compatibility
9pub use types_chat::*;
10pub use types_data::*;
11
12use serde::{Deserialize, Serialize};
13
14// ============================================================================
15// BANCO-TYP-004: Health / Models / System
16// ============================================================================
17
18/// Health endpoint response.
19#[derive(Debug, Clone, Serialize, Deserialize)]
20pub struct HealthResponse {
21    pub status: String,
22    pub circuit_breaker_state: String,
23    pub uptime_secs: u64,
24}
25
26/// A single model entry.
27#[derive(Debug, Clone, Serialize, Deserialize)]
28pub struct ModelInfo {
29    pub id: String,
30    pub object: String,
31    pub owned_by: String,
32    pub local: bool,
33}
34
35/// Models list response.
36#[derive(Debug, Clone, Serialize, Deserialize)]
37pub struct ModelsResponse {
38    pub object: String,
39    pub data: Vec<ModelInfo>,
40}
41
42/// System information response.
43#[derive(Debug, Clone, Serialize, Deserialize)]
44pub struct SystemResponse {
45    pub privacy_tier: String,
46    pub backends: Vec<String>,
47    pub gpu_available: bool,
48    pub version: String,
49    pub telemetry: bool,
50    pub model_loaded: bool,
51    #[serde(skip_serializing_if = "Option::is_none")]
52    pub model_id: Option<String>,
53    /// Hint for next action (empty when fully operational)
54    #[serde(skip_serializing_if = "Option::is_none")]
55    pub hint: Option<String>,
56    /// Tokenizer mode: "bpe" or "greedy". Null when no model loaded.
57    #[serde(skip_serializing_if = "Option::is_none")]
58    pub tokenizer: Option<String>,
59    /// Operational stats
60    pub endpoints: u32,
61    pub files: usize,
62    pub conversations: usize,
63    pub rag_indexed: bool,
64    pub rag_chunks: usize,
65    pub training_runs: usize,
66    pub audit_entries: usize,
67}
68
69// ============================================================================
70// BANCO-TYP-005: Error Response
71// ============================================================================
72
73/// OpenAI-compatible error response.
74#[derive(Debug, Clone, Serialize, Deserialize)]
75pub struct ErrorResponse {
76    pub error: ErrorDetail,
77}
78
79/// Error detail within an error response.
80#[derive(Debug, Clone, Serialize, Deserialize)]
81pub struct ErrorDetail {
82    pub message: String,
83    #[serde(rename = "type")]
84    pub type_: String,
85    pub code: u16,
86}
87
88impl ErrorResponse {
89    #[must_use]
90    pub fn new(message: impl Into<String>, type_: impl Into<String>, code: u16) -> Self {
91        Self { error: ErrorDetail { message: message.into(), type_: type_.into(), code } }
92    }
93}
94
95// ============================================================================
96// BANCO-TYP-008: Conversations
97// ============================================================================
98
99/// Create conversation request.
100#[derive(Debug, Clone, Default, Serialize, Deserialize)]
101pub struct CreateConversationRequest {
102    #[serde(default)]
103    pub model: Option<String>,
104    #[serde(default)]
105    pub title: Option<String>,
106}
107
108/// Conversation list response.
109#[derive(Debug, Clone, Serialize, Deserialize)]
110pub struct ConversationsListResponse {
111    pub conversations: Vec<super::conversations::ConversationMeta>,
112}
113
114/// Single conversation response (with messages).
115#[derive(Debug, Clone, Serialize, Deserialize)]
116pub struct ConversationResponse {
117    #[serde(flatten)]
118    pub conversation: super::conversations::Conversation,
119}
120
121/// Conversation created response.
122#[derive(Debug, Clone, Serialize, Deserialize)]
123pub struct ConversationCreatedResponse {
124    pub id: String,
125    pub title: String,
126}
127
128// ============================================================================
129// BANCO-TYP-010: Model Management
130// ============================================================================
131
132/// Model load request.
133#[derive(Debug, Clone, Serialize, Deserialize)]
134pub struct ModelLoadRequest {
135    pub model: String,
136    #[serde(default = "default_slot")]
137    pub slot: String,
138}
139
140fn default_slot() -> String {
141    "primary".to_string()
142}
143
144/// Model status response.
145#[derive(Debug, Clone, Serialize, Deserialize)]
146pub struct ModelStatusResponse {
147    pub loaded: bool,
148    #[serde(skip_serializing_if = "Option::is_none")]
149    pub model: Option<super::model_slot::ModelSlotInfo>,
150    #[serde(skip_serializing_if = "Option::is_none")]
151    pub uptime_secs: Option<u64>,
152    /// Tokenizer mode: "bpe" (proper merge rules) or "greedy" (approximate fallback).
153    #[serde(skip_serializing_if = "Option::is_none")]
154    pub tokenizer: Option<String>,
155}
156
157// ============================================================================
158// BANCO-TYP-009: Prompt Presets
159// ============================================================================
160
161/// Create/update prompt preset request.
162#[derive(Debug, Clone, Serialize, Deserialize)]
163pub struct SavePromptRequest {
164    pub name: String,
165    pub content: String,
166}
167
168/// Prompt presets list response.
169#[derive(Debug, Clone, Serialize, Deserialize)]
170pub struct PromptsListResponse {
171    pub presets: Vec<super::prompts::PromptPreset>,
172}