Skip to main content

vc_runtime/config/model/
backend.rs

1//! Backend domain model.
2//!
3//! This module defines the core types for backend configuration.
4//! Backend names are external (keys in `AppConfig.backends` HashMap).
5
6use serde::{Deserialize, Serialize};
7use std::path::PathBuf;
8use url::Url;
9
10// ============================================================
11// Backend-Specific Configurations
12// ============================================================
13
14/// Configuration for the dummy renderer (no-op, for testing).
15#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
16#[serde(default)]
17pub struct DummyConfig {}
18
19/// Configuration for the Python subprocess renderer.
20#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
21pub struct PythonConfig {
22    /// Path to the Python script that performs rendering.
23    pub script_path: PathBuf,
24    /// Optional custom Python interpreter path.
25    #[serde(default)]
26    pub python_path: Option<PathBuf>,
27}
28
29/// Configuration for the ComfyUI HTTP renderer.
30#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
31pub struct ComfyConfig {
32    /// Base URL of the ComfyUI server (e.g., "http://127.0.0.1:8188").
33    pub base_url: Url,
34
35    /// HTTP timeout in seconds.
36    #[serde(default = "default_timeout_secs")]
37    pub timeout_secs: u64,
38
39    /// Polling timeout in seconds.
40    #[serde(default = "default_poll_timeout_secs")]
41    pub poll_timeout_secs: u64,
42
43    /// Polling interval in milliseconds.
44    #[serde(default = "default_poll_interval_ms")]
45    pub poll_interval_ms: u64,
46
47    /// Path to the ComfyUI workflow template JSON file.
48    pub workflow_template_path: PathBuf,
49}
50
51/// Default HTTP timeout (seconds).
52fn default_timeout_secs() -> u64 {
53    30
54}
55
56/// Default polling timeout (seconds).
57fn default_poll_timeout_secs() -> u64 {
58    300
59}
60
61/// Default polling interval (milliseconds).
62fn default_poll_interval_ms() -> u64 {
63    500
64}
65
66// ============================================================
67// BackendOptions (Type-Safe Enum)
68// ============================================================
69
70/// Runtime-internal backend configuration.
71///
72/// This enum is the canonical representation of backend configuration
73/// inside the runtime.
74///
75/// Loaders convert external configuration formats into this type.
76/// New backend kinds extend this enum.
77#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
78#[serde(tag = "kind", content = "options")]
79#[serde(rename_all = "lowercase")]
80pub enum BackendOptions {
81    Dummy(DummyConfig),
82    Python(PythonConfig),
83    ComfyUi(ComfyConfig),
84}
85
86// ============================================================
87// BackendDefinition
88// ============================================================
89
90/// A complete backend definition.
91///
92/// The name is external (key in `AppConfig.backends` HashMap).
93/// This struct provides metadata (`enabled`) separate from the
94/// backend-specific options.
95#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
96pub struct BackendDefinition {
97    /// Whether this backend is enabled. Disabled backends cannot be
98    /// selected by any profile. Useful for feature flags, rollouts,
99    /// or deprecation.
100    #[serde(default = "default_enabled")]
101    pub enabled: bool,
102
103    /// Backend-specific configuration options.
104    pub options: BackendOptions,
105}
106
107/// Default enabled state for a backend.
108fn default_enabled() -> bool {
109    true
110}