rs-plugin-common-interfaces 0.49.2

Common description for plugin creation
Documentation
use serde::{Deserialize, Serialize};

/// Where a background embedding pass over one library stands.
#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
#[serde(rename_all = "camelCase")]
pub enum EmbeddingPassState {
    /// Sent before the model is loaded and, the first time, downloaded.
    Started,
    /// Sent after each media.
    Running,
    Completed,
    /// Left because the library was paused; resuming starts a new pass.
    Paused,
    /// Left because embeddings were turned off for the library, or it was removed.
    Stopped,
    /// Left early after too many failures in a row; a later pass carries on.
    Interrupted,
    /// Could not run, for example because the model cannot be loaded.
    Failed,
}

/// Payload of the `embedding_progress` event. A pass sends `started` once, `running`
/// after each media, then exactly one of `completed`, `paused`, `stopped`,
/// `interrupted` or `failed`.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct EmbeddingProgressMessage {
    pub library: String,
    pub state: EmbeddingPassState,
    pub embedder: String,
    /// Medias tried so far in this pass.
    pub processed: u64,
    /// Of which embedded; the others failed.
    pub embedded: u64,
    /// Medias this pass covers: those pending when it started, kept in step with
    /// uploads and deletions since. Never below `processed`.
    pub total: u64,
}

/// Where the embedding model stands on the server.
#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
#[serde(rename_all = "camelCase")]
pub enum EmbeddingModelState {
    /// In memory, ready to embed.
    Loaded,
    /// On disk, loaded on first use.
    Available,
    Downloading,
    /// Downloaded on first use.
    Missing,
}

/// How many medias of a library have a vector.
#[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct MediaEmbeddingCounts {
    /// Photos and videos in the library.
    pub total: u64,
    pub embedded: u64,
    /// Still to embed, including failed medias that will be tried again.
    pub pending: u64,
    /// Gave up after too many failures.
    pub failed: u64,
}

/// The media embeddings of a library (`/libraries/{id}/medias/embeddings/status`, and
/// the answer of pause and resume).
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct MediaEmbeddingStatus {
    pub embedder: String,
    pub dimension: usize,
    pub search_dimension: usize,
    /// Library setting `embeddings`: new and existing medias are embedded in the background.
    pub enabled: bool,
    /// Library setting `embeddingsPaused`: nothing is embedded until it is resumed.
    pub paused: bool,
    pub model: EmbeddingModelState,
    /// A backfill is running on this server (any library).
    pub running: bool,
    #[serde(flatten)]
    pub counts: MediaEmbeddingCounts,
}

/// The answer to starting a pass (`/libraries/{id}/medias/embeddings/process`).
#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
#[serde(rename_all = "camelCase")]
pub enum MediaEmbeddingProcessStatus {
    /// Queued to start at once.
    Started,
    /// A pass is already running: it handles this library, or the next one does.
    AlreadyRunning,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct MediaEmbeddingProcessResult {
    pub status: MediaEmbeddingProcessStatus,
    pub message: String,
}