Skip to main content

prodigy/subprocess/streaming/
types.rs

1//! Core types for streaming infrastructure
2
3use std::time::Duration;
4
5/// Streaming mode configuration
6#[derive(Debug, Clone)]
7pub enum StreamingMode {
8    /// Traditional batch capture (default)
9    Batch,
10    /// Line-by-line streaming
11    Streaming,
12    /// Streaming with structured parsing
13    StructuredStreaming { format: OutputFormat },
14}
15
16impl Default for StreamingMode {
17    fn default() -> Self {
18        Self::Batch
19    }
20}
21
22/// Output format for structured streaming
23#[derive(Debug, Clone)]
24pub enum OutputFormat {
25    PlainText,
26    JsonLines,
27    YamlStream,
28}
29
30/// Stream source identifier
31#[derive(Debug, Clone, Copy, PartialEq, Eq)]
32pub enum StreamSource {
33    Stdout,
34    Stderr,
35}
36
37/// Buffer configuration for streaming
38#[derive(Debug, Clone)]
39pub struct BufferConfig {
40    /// Line buffer size in bytes
41    pub line_buffer_size: usize,
42    /// Maximum number of lines to keep in memory
43    pub max_lines: Option<usize>,
44    /// Buffer overflow strategy
45    pub overflow_strategy: crate::subprocess::streaming::backpressure::OverflowStrategy,
46    /// Maximum time to wait for buffer space (for Block strategy)
47    pub block_timeout: Duration,
48}
49
50impl Default for BufferConfig {
51    fn default() -> Self {
52        Self {
53            line_buffer_size: 8192,
54            max_lines: Some(10000),
55            overflow_strategy:
56                crate::subprocess::streaming::backpressure::OverflowStrategy::DropOldest,
57            block_timeout: Duration::from_secs(5),
58        }
59    }
60}
61
62/// Streaming configuration
63#[derive(Debug, Clone)]
64pub struct StreamingConfig {
65    /// Enable streaming mode
66    pub enabled: bool,
67    /// Streaming mode
68    pub mode: StreamingMode,
69    /// Buffer configuration
70    pub buffer_config: BufferConfig,
71    /// Processor configurations
72    pub processors: Vec<ProcessorConfig>,
73}
74
75impl Default for StreamingConfig {
76    fn default() -> Self {
77        Self {
78            enabled: false,
79            mode: StreamingMode::Batch,
80            buffer_config: BufferConfig::default(),
81            processors: Vec::new(),
82        }
83    }
84}
85
86/// Processor configuration
87#[derive(Debug, Clone)]
88pub enum ProcessorConfig {
89    /// Parse JSON lines and emit events
90    JsonLines { emit_events: bool },
91    /// Match patterns in output
92    PatternMatcher { patterns: Vec<regex::Regex> },
93    /// Emit events of a specific type
94    EventEmitter { event_type: String },
95    /// Custom processor (not cloneable, so we use a marker)
96    Custom { id: String },
97}
98
99/// Output from streaming command execution
100#[derive(Debug)]
101pub struct StreamingOutput {
102    /// Process exit status
103    pub status: std::process::ExitStatus,
104    /// Captured stdout lines
105    pub stdout: Vec<String>,
106    /// Captured stderr lines
107    pub stderr: Vec<String>,
108    /// Execution duration
109    pub duration: Duration,
110}