Skip to main content

bamboo_engine/events/
change_feed.rs

1//! The sequenced change-feed event type.
2//!
3//! A [`ChangeEvent`] is an [`AgentEvent`] stamped with a global monotonic
4//! sequence number and routing metadata. It is the unit carried on the account
5//! `GET /api/v1/stream` feed and persisted, one JSON line each, in the durable
6//! journal (see [`super::journal`]).
7//!
8//! Classification of which events are durable lives on the event type itself:
9//! [`AgentEvent::is_durable_change`]. Keeping it in `bamboo-agent-core` lets
10//! both the server and the engine forwarder filter before cloning onto the
11//! feed.
12
13use bamboo_agent_core::AgentEvent;
14use chrono::{DateTime, Utc};
15use serde::{Deserialize, Serialize};
16
17/// An [`AgentEvent`] stamped with its global sequence number for the account
18/// change feed.
19///
20/// The `seq` of a [`AgentEvent::MessageAppended`] event is also the message's
21/// feed coordinate, used by `GET /history/{id}?since={seq}` to compute deltas.
22#[derive(Debug, Clone, Serialize, Deserialize)]
23pub struct ChangeEvent {
24    /// Global monotonic sequence number (account-wide, 1-based, strictly
25    /// increasing, stable across restarts).
26    pub seq: u64,
27    /// When the writer task stamped this event.
28    pub ts: DateTime<Utc>,
29    /// Session this event pertains to, if any (client-side routing key).
30    #[serde(default, skip_serializing_if = "Option::is_none")]
31    pub session_id: Option<String>,
32    /// The underlying agent event.
33    pub event: AgentEvent,
34}