Skip to main content

enact_core/streaming/
mod.rs

1//! Streaming - Event delivery and persistence
2//!
3//! This module handles **delivery** of events to consumers. It subscribes to
4//! kernel events and delivers them via SSE, persistence, etc.
5//!
6//! ## Important: Source of Truth
7//!
8//! IDs and Events are DEFINED in `kernel/` (source of truth).
9//! This module RE-EXPORTS them for convenience and provides:
10//! - **event_logger.rs**: Append-only event log (EventStore, EventLog)
11//! - **event_stream.rs**: Wire format for SSE (StreamEvent, data-* protocol)
12//!
13//! ## Architecture
14//!
15//! ```text
16//! ExecutionKernel (owns IDs and Events)
17//!       │
18//!       │ emit events
19//!       ▼
20//! ┌─────────────────────────────────────────────────────────┐
21//! │                    streaming/                            │
22//! │  ┌────────────┐  ┌────────────────────┐                 │
23//! │  │event_logger│  │  event_stream.rs   │                 │
24//! │  │ (persist)  │  │  (wire format)     │                 │
25//! │  └────────────┘  └─────────┬──────────┘                 │
26//! └────────────────────────────┼────────────────────────────┘
27//!                              │
28//!                ┌─────────────┼─────────────────┐
29//!                ▼             ▼                 ▼
30//!          ┌──────────┐ ┌───────────┐      ┌───────────┐
31//!          │   TUI    │ │ GUI (SSE) │      │ telemetry │
32//!          │(ratatui) │ │ (web)     │      │  (OTel)   │
33//!          └──────────┘ └───────────┘      └───────────┘
34//! ```
35//!
36//! ## Event Protocol
37//! All events use `data-*` prefix for SSE compatibility:
38//! - Standard: `data-text-start`, `data-text-delta`, `data-finish`, etc.
39//! - Custom: `data-execution-start`, `data-step-start`, etc.
40//!
41//! @see docs/TECHNICAL/01-EXECUTION-TELEMETRY.md
42//! @see https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol
43
44mod event_logger;
45mod event_stream;
46mod jsonl_event_store;
47mod jsonl_state_store;
48mod pause_cancel;
49mod sse;
50
51// =============================================================================
52// Stream Events (wire format for SSE)
53// =============================================================================
54pub use event_stream::{EventEmitter, EventStream, StreamEvent, StreamMode};
55
56// =============================================================================
57// Event Log (persistence)
58// =============================================================================
59pub use event_logger::{EventLog, EventLogEntry, EventStore, InMemoryEventStore};
60pub use jsonl_event_store::JsonlEventStore;
61pub use jsonl_state_store::JsonlStateStore;
62
63// =============================================================================
64// Re-exports from kernel (source of truth)
65// =============================================================================
66// IDs and Events are DEFINED in kernel/. We re-export for convenience.
67pub use crate::kernel::{
68    prefixes,
69    // IDs
70    ArtifactId,
71    // Events
72    ControlAction,
73    ControlActor,
74    ControlEvent,
75    ControlOutcome,
76    DecisionAlternative,
77    DecisionInput,
78    DecisionRecord,
79    DecisionType,
80    Event,
81    ExecutionContext,
82    ExecutionEvent,
83    ExecutionEventType,
84    ExecutionId,
85    GraphId,
86    MessageId,
87    ModelContext,
88    NodeId,
89    ParentLink,
90    ParentType,
91    RunId,
92    StepId,
93    StepType,
94    TenantId,
95    ThreadId,
96    UserId,
97};
98
99// =============================================================================
100// Protection Layer (feat-09: Guardrails)
101// =============================================================================
102// Output processors that run BEFORE storage/streaming.
103// @see docs/TECHNICAL/17-GUARDRAILS-PROTECTION.md
104// @see docs/TECHNICAL/25-STREAM-PROCESSORS.md
105mod protected_emitter;
106pub mod protection;
107
108pub use protected_emitter::ProtectedEventEmitter;
109pub use protection::{
110    DataDestination, EncryptionProcessor, OutputProcessor, PiiProtectionProcessor, ProcessedEvent,
111    ProcessorPipeline, ProtectionContext,
112};