1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//! Generic event firehose scaffolding for microapps.
//!
//! Lifted from `agent-creator-microapp::firehose` so any microapp
//! that wants the same shape — typed daemon notifications fanned
//! out over SSE while persisted to a SQLite append-log for
//! backfill — can drop a few lines into `main.rs` instead of
//! rewriting ~900 LOC of store + listener + sweep.
//!
//! The four pieces, gated behind the `events` feature:
//!
//! - [`EventMetadata`] — projections (`kind`, `agent_id`,
//! `tenant_id`, `at_ms`) the store needs to index any event
//! type. Implemented out of the box for
//! `nexo_tool_meta::admin::agent_events::AgentEventKind`.
//! - [`EventStore`] — SQLite append + filtered list + two-phase
//! retention sweep. Generic over `T: EventMetadata + Serialize
//! + DeserializeOwned`.
//! - [`EventBroadcastState`] — store + `tokio::broadcast::Sender`
//! pair. SSE handlers `subscribe()` per connection.
//! - [`build_persisting_listener`] — the
//! `Arc<dyn Fn(serde_json::Value)>` you hand to
//! `Microapp::with_notification_listener`. Decodes, broadcasts,
//! and asynchronously appends to the store.
//! - [`SweepConfig`] + [`spawn_sweep_loop`] — background retention
//! task with operator-driven cancellation.
//!
//! HTTP routes (backfill `GET …` + SSE stream `GET …/stream`) stay
//! in the microapp because per-connection filter logic varies by
//! event type. See `agent-creator-microapp::firehose::routes` for
//! a reference implementation that uses
//! [`nexo_microapp_http::sse::sse_filtered_broadcast`].
use Error;
/// Result alias used by [`EventStore`] operations.
pub type Result<T> = Result;
/// Typed error surface for the `events` feature. Distinct from
/// the SDK runtime [`crate::Error`] so callers can `match` on
/// SQLite vs JSON vs invalid-config without falling back to
/// downcast.
pub use ;
pub use EventMetadata;
pub use ;
pub use ;