Skip to main content

protocol_droid/application/session/
mod.rs

1//! The session engine: one use case, assembled from a lifecycle and three ports.
2//!
3//! # What lives here
4//!
5//! The engine owns a [`Session`](crate::domain::session::Session) and a
6//! [`RequestRegistry`](crate::domain::session::RequestRegistry), asks a
7//! [`Lifecycle`] what each message means, and records what happened on an
8//! [`EventLog`]. It reaches the outside world through the traits it declares
9//! itself — [`Clock`], [`IdSource`], [`EventLog`], and a frame sink once the
10//! engine needs to write. None of them is implemented here. A transport
11//! implements the sink; a test implements the other three in three lines.
12//!
13//! # Why the engine knows nothing about MCP
14//!
15//! Every protocol-specific decision is a call into [`Lifecycle`]. The engine
16//! holds the negotiated profile and version as opaque values, passes the
17//! profile back whenever it needs a judgement, and renders the version into a
18//! string for the event log — it never inspects either. That is the whole
19//! reason [`Lifecycle`] has associated types instead of naming
20//! `FeatureProfile` and `ProtocolVersion`: an A2A session carries
21//! `Major.Minor` and a profile of a completely different shape, and it drops
22//! in as a second implementation of the same trait rather than as a fork of
23//! this module.
24//!
25//! # Why time is a port and not a call
26//!
27//! The engine decides that a request has outlived its budget, and that
28//! decision is arithmetic over two readings of the same clock. Taking the
29//! second reading from a global would mean a test could not set up a request
30//! that started ninety seconds ago without sleeping for ninety seconds. So the
31//! clock is injected, the reading is a `Duration` from an origin the adapter
32//! picked, and nothing in this module calls a clock function.
33
34pub mod clock;
35pub mod engine;
36pub mod event_log;
37pub mod frame_sink;
38pub mod id_source;
39pub mod lifecycle;
40
41pub use clock::Clock;
42pub use engine::{Dispatch, EngineError, Refusal, SessionEngine};
43pub use event_log::{EventLog, NullEventLog, SessionEvent};
44pub use frame_sink::{DynFrameSink, FrameSink, SinkError};
45pub use id_source::IdSource;
46pub use lifecycle::{
47    Classification, Declaration, DeclarationError, Lifecycle, MetaView, Resolution,
48};