Skip to main content

videre_api/
types.rs

1use serde::Serialize;
2
3/// Versioned model context attached to evidence captured by a Gallery action.
4#[derive(Debug, Clone, PartialEq, Eq)]
5pub struct TeachingContext {
6    pub embedding_model_id: String,
7    pub active_profile_id: Option<i64>,
8    /// Whether this mutation records teaching evidence. False while face
9    /// learning is off: the same checks and face writes, no events.
10    pub record: bool,
11}
12
13/// Durable learning work committed with a visible people mutation.
14#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
15pub struct LearningAcknowledgement {
16    pub generation: u64,
17    pub event_ids: Vec<i64>,
18    pub message_key: String,
19}
20
21/// Learning status for the gallery background worker.
22#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
23pub struct FaceLearningStatus {
24    /// Whether face learning is on for this library (`faces.learning`).
25    pub enabled: bool,
26    pub generation: u64,
27    pub trained_generation: u64,
28    pub status: String,
29    pub last_profile_id: Option<i64>,
30    /// What became of the last trained candidate: `promoted` or `rejected`,
31    /// or `None` before any candidate was stored. Lets a `current` status
32    /// say whether the last run changed the profile in use.
33    pub last_candidate: Option<String>,
34    pub last_error: Option<String>,
35    /// While `status` is `waiting`: the feedback training still needs, in
36    /// words the People page shows as is (`dissolve 2 more wrong clusters`).
37    pub feedback_needed: Option<String>,
38    pub pending_questions: usize,
39    /// The profile in use, if any: its id and stage (`suggestion` asks
40    /// questions, `grouping` may also shape clustering).
41    pub active_profile: Option<ActiveProfile>,
42    /// What learning contributes right now, in one sentence for the People
43    /// toolbar.
44    pub summary: String,
45}
46
47impl FaceLearningStatus {
48    /// The same stored state, reported for a library with learning off.
49    pub fn turned_off(self) -> Self {
50        Self {
51            enabled: false,
52            summary: "Learning: off for this library.".to_owned(),
53            ..self
54        }
55    }
56}
57
58#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
59pub struct ActiveProfile {
60    pub profile_id: i64,
61    pub stage: String,
62}
63
64/// The stored outcome of one background training run.
65#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
66pub struct TrainedProfileSummary {
67    pub profile_id: i64,
68    pub model_kind: String,
69    pub promoted: bool,
70}
71
72/// Result of answering one identity question: the new delivery state and, for
73/// Yes and No, the durable learning work the answer committed.
74#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
75pub struct QuestionAnswerOutcome {
76    pub status: String,
77    pub acknowledgement: Option<LearningAcknowledgement>,
78}
79
80/// One labeled person: their confirmed faces plus a representative face id
81/// (the primary, or lowest id) used as the card thumbnail.
82#[derive(Serialize, Clone)]
83pub struct PersonData {
84    /// Identity: normalized, what URLs and actions use.
85    pub label: String,
86    /// What a reader sees. Falls back to `label` for a person whose row
87    /// predates the people table.
88    pub full_name: String,
89    pub face_ids: Vec<i64>,
90    pub representative_id: i64,
91    pub hashes: Vec<String>,
92}
93
94/// One unassigned cluster (green section in the labeling UI).
95#[derive(Serialize, Clone)]
96pub struct ClusterData {
97    pub cluster_id: i64,
98    pub face_ids: Vec<i64>,
99    pub hashes: Vec<String>,
100}
101
102/// One unclustered, unassigned face (orange section).
103#[derive(Serialize, Clone)]
104pub struct SingletonData {
105    pub face_id: i64,
106    pub hash: String,
107}
108
109/// Top-level payload for the labeling page.
110///
111/// `Default` is the "detection has never run" answer, which is a state rather
112/// than an error. See `faces_list`.
113#[derive(Serialize, Clone, Default)]
114pub struct FacesData {
115    pub people: Vec<PersonData>,
116    pub clusters: Vec<ClusterData>,
117    pub singletons: Vec<SingletonData>,
118}
119
120/// One face row on a cluster detail page.
121#[derive(Serialize, Clone)]
122pub struct ClusterFaceData {
123    pub face_id: i64,
124    pub hash: String,
125    pub path: String,
126}
127
128/// Cluster detail: every face in one unassigned cluster.
129#[derive(Serialize, Clone)]
130pub struct ClusterDetail {
131    pub cluster_id: i64,
132    pub faces: Vec<ClusterFaceData>,
133}
134
135/// One face row on a person detail page. `is_primary` marks the current
136/// default photo (the person's thumbnail on the labeling page).
137#[derive(Serialize, Clone)]
138pub struct PersonFaceData {
139    pub face_id: i64,
140    pub hash: String,
141    pub path: String,
142    pub is_primary: bool,
143}
144
145/// Person detail: every confirmed face for one person.
146#[derive(Serialize, Clone)]
147pub struct PersonDetail {
148    /// Identity: what the URL and every face row use.
149    pub label: String,
150    /// What a reader sees, and what the page lets them edit.
151    pub full_name: String,
152    pub faces: Vec<PersonFaceData>,
153}