agent_block_core/bus/source.rs
1//! [`Source`] trait: something that produces [`Event`]s.
2//!
3//! In the final wiring (Subtask 3), concrete implementations will include a
4//! mesh adapter that turns `agent_mesh_sdk::RequestHandler::handle` calls
5//! into events pushed to the bus.
6//!
7//! Sources that need a response from the Lua handler (request/response
8//! round-trip) construct events via [`Event::with_ack`] and await the
9//! receiver side themselves. Sources that are fire-and-forget use
10//! [`Event::fire_and_forget`].
11//!
12//! Note: the `next()` API on this trait is kept for symmetry with
13//! pull-style sources. The canonical wiring in `agent-block` uses a single
14//! shared `mpsc::Sender<Event>` that sources push into directly (see
15//! plan.md §設計選択 A1). `next()` is retained for adapters that prefer a
16//! pull interface and for the in-crate mock used by `#[cfg(test)]` in the
17//! dispatcher module.
18
19use async_trait::async_trait;
20
21use crate::bus::event::Event;
22use agent_block_types::error::BlockError;
23
24/// A producer of [`Event`]s.
25///
26/// ST3 uses push-style ingress (`mpsc::Sender<Event>` cloned into each
27/// adapter) and does not exercise this trait. Retained for ST4+ adapters
28/// that prefer a pull interface.
29#[allow(dead_code)]
30#[async_trait]
31pub trait Source: Send + Sync {
32 /// Canonical kind string used by this source (e.g. `"mesh"`).
33 fn kind(&self) -> &str;
34
35 /// Pull the next event. `Ok(None)` signals the source has been
36 /// exhausted and will produce no more events. `Err` is logged by the
37 /// dispatcher (or the caller) and does not terminate the bus.
38 async fn next(&mut self) -> Result<Option<Event>, BlockError>;
39}