gglib_core/events/
app.rs

1//! Application-level events (model lifecycle).
2
3use serde::{Deserialize, Serialize};
4
5use super::AppEvent;
6
7/// Summary of a model for event payloads.
8///
9/// This is a lightweight representation for events — not the full `Model`.
10#[derive(Debug, Clone, Serialize, Deserialize)]
11#[serde(rename_all = "camelCase")]
12pub struct ModelSummary {
13    /// Database ID of the model.
14    pub id: i64,
15    /// Human-readable model name.
16    pub name: String,
17    /// File path to the model.
18    pub file_path: String,
19    /// Model architecture (e.g., "llama").
20    #[serde(skip_serializing_if = "Option::is_none")]
21    pub architecture: Option<String>,
22    /// Quantization type (e.g., "`Q4_0`").
23    #[serde(skip_serializing_if = "Option::is_none")]
24    pub quantization: Option<String>,
25}
26
27impl ModelSummary {
28    /// Create a new model summary.
29    pub fn new(
30        id: i64,
31        name: impl Into<String>,
32        file_path: impl Into<String>,
33        architecture: Option<String>,
34        quantization: Option<String>,
35    ) -> Self {
36        Self {
37            id,
38            name: name.into(),
39            file_path: file_path.into(),
40            architecture,
41            quantization,
42        }
43    }
44}
45
46impl AppEvent {
47    /// Create a model added event.
48    pub const fn model_added(model: ModelSummary) -> Self {
49        Self::ModelAdded { model }
50    }
51
52    /// Create a model removed event.
53    pub const fn model_removed(model_id: i64) -> Self {
54        Self::ModelRemoved { model_id }
55    }
56
57    /// Create a model updated event.
58    pub const fn model_updated(model: ModelSummary) -> Self {
59        Self::ModelUpdated { model }
60    }
61}