Skip to main content

lc_core/runnables/
config.rs

1// src/core/runnables/config.rs
2//! Runnable execution configuration.
3
4use serde_json::Value;
5use std::collections::HashMap;
6use std::sync::Arc;
7use uuid::Uuid;
8
9use lc_callbacks::CallbackManager;
10
11/// Runnable execution configuration.
12#[derive(Debug, Clone, Default)]
13pub struct RunnableConfig {
14    /// Tags for filtering and tracking.
15    pub tags: Vec<String>,
16
17    /// Metadata - custom data (JSON serializable).
18    pub metadata: HashMap<String, Value>,
19
20    /// Max concurrency for batch operations.
21    pub max_concurrency: Option<usize>,
22
23    /// Run ID for tracking.
24    pub run_id: Option<Uuid>,
25
26    /// Run name for debugging.
27    pub run_name: Option<String>,
28
29    /// Callback manager for tracing and monitoring.
30    pub callbacks: Option<Arc<CallbackManager>>,
31}
32
33impl RunnableConfig {
34    /// Creates an empty configuration.
35    pub fn new() -> Self {
36        Self::default()
37    }
38
39    /// Adds a tag.
40    pub fn with_tag(mut self, tag: impl Into<String>) -> Self {
41        self.tags.push(tag.into());
42        self
43    }
44
45    /// Adds metadata.
46    pub fn with_metadata(mut self, key: impl Into<String>, value: Value) -> Self {
47        self.metadata.insert(key.into(), value);
48        self
49    }
50
51    /// Sets max concurrency.
52    pub fn with_max_concurrency(mut self, max: usize) -> Self {
53        self.max_concurrency = Some(max);
54        self
55    }
56
57    /// Sets run ID.
58    pub fn with_run_id(mut self, id: Uuid) -> Self {
59        self.run_id = Some(id);
60        self
61    }
62
63    /// Sets run name.
64    pub fn with_run_name(mut self, name: impl Into<String>) -> Self {
65        self.run_name = Some(name.into());
66        self
67    }
68
69    /// Sets callback manager.
70    pub fn with_callbacks(mut self, callbacks: Arc<CallbackManager>) -> Self {
71        self.callbacks = Some(callbacks);
72        self
73    }
74
75    /// Merges two configurations (later overrides earlier).
76    pub fn merge(mut self, other: RunnableConfig) -> Self {
77        // Merge tags (union)
78        self.tags.extend(other.tags);
79        self.tags.sort();
80        self.tags.dedup();
81
82        // Merge metadata (override)
83        self.metadata.extend(other.metadata);
84
85        // Override other fields
86        if other.max_concurrency.is_some() {
87            self.max_concurrency = other.max_concurrency;
88        }
89        if other.run_id.is_some() {
90            self.run_id = other.run_id;
91        }
92        if other.run_name.is_some() {
93            self.run_name = other.run_name;
94        }
95        if other.callbacks.is_some() {
96            self.callbacks = other.callbacks;
97        }
98
99        self
100    }
101}