vc-runtime 0.1.0

Runtime backend for Visual Compiler
Documentation
//! Backend domain model.
//!
//! This module defines the core types for backend configuration.
//! Backend names are external (keys in `AppConfig.backends` HashMap).

use serde::{Deserialize, Serialize};
use std::path::PathBuf;
use url::Url;

// ============================================================
// Backend-Specific Configurations
// ============================================================

/// Configuration for the dummy renderer (no-op, for testing).
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
#[serde(default)]
pub struct DummyConfig {}

/// Configuration for the Python subprocess renderer.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct PythonConfig {
    /// Path to the Python script that performs rendering.
    pub script_path: PathBuf,
    /// Optional custom Python interpreter path.
    #[serde(default)]
    pub python_path: Option<PathBuf>,
}

/// Configuration for the ComfyUI HTTP renderer.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ComfyConfig {
    /// Base URL of the ComfyUI server (e.g., "http://127.0.0.1:8188").
    pub base_url: Url,

    /// HTTP timeout in seconds.
    #[serde(default = "default_timeout_secs")]
    pub timeout_secs: u64,

    /// Polling timeout in seconds.
    #[serde(default = "default_poll_timeout_secs")]
    pub poll_timeout_secs: u64,

    /// Polling interval in milliseconds.
    #[serde(default = "default_poll_interval_ms")]
    pub poll_interval_ms: u64,

    /// Path to the ComfyUI workflow template JSON file.
    pub workflow_template_path: PathBuf,
}

/// Default HTTP timeout (seconds).
fn default_timeout_secs() -> u64 {
    30
}

/// Default polling timeout (seconds).
fn default_poll_timeout_secs() -> u64 {
    300
}

/// Default polling interval (milliseconds).
fn default_poll_interval_ms() -> u64 {
    500
}

// ============================================================
// BackendOptions (Type-Safe Enum)
// ============================================================

/// Runtime-internal backend configuration.
///
/// This enum is the canonical representation of backend configuration
/// inside the runtime.
///
/// Loaders convert external configuration formats into this type.
/// New backend kinds extend this enum.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(tag = "kind", content = "options")]
#[serde(rename_all = "lowercase")]
pub enum BackendOptions {
    Dummy(DummyConfig),
    Python(PythonConfig),
    ComfyUi(ComfyConfig),
}

// ============================================================
// BackendDefinition
// ============================================================

/// A complete backend definition.
///
/// The name is external (key in `AppConfig.backends` HashMap).
/// This struct provides metadata (`enabled`) separate from the
/// backend-specific options.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct BackendDefinition {
    /// Whether this backend is enabled. Disabled backends cannot be
    /// selected by any profile. Useful for feature flags, rollouts,
    /// or deprecation.
    #[serde(default = "default_enabled")]
    pub enabled: bool,

    /// Backend-specific configuration options.
    pub options: BackendOptions,
}

/// Default enabled state for a backend.
fn default_enabled() -> bool {
    true
}