agent_context/context/events/subscribe.rs
1//! 订阅管理请求消息。
2//!
3//! 动态管理 [`AgentContext`](crate::AgentContext) 的订阅者,支持 spawn 后随时订阅/退订。
4//!
5//! 每条消息的 `impl Message<…> for `[`AgentContext`](super::super::actor::AgentContext) 块定义在
6//! [`context::actor`](super::super::actor) 模块中。
7
8use kameo::actor::{Recipient, ReplyRecipient};
9
10use super::outbound::{NotifyChange, NotifyCompressedForReply};
11
12/// 添加变更通知订阅者。Reply = `()`。
13///
14/// 订阅后,每次对 incremental 区的写操作都会通过 [`NotifyChange`] 通知该订阅者。
15/// 可重复调用注册多个订阅者。若该订阅者已存在则无操作。
16pub struct RequestSubscribeChange<M: Send + 'static> {
17 /// 要添加的订阅者引用
18 pub recipient: Recipient<NotifyChange<M>>,
19}
20
21/// 移除变更通知订阅者。Reply = `bool`。
22///
23/// 返回 `true` 表示该订阅者存在并被移除,`false` 表示未找到。
24pub struct RequestUnsubscribeChange<M: Send + 'static> {
25 /// 要移除的订阅者引用
26 pub recipient: Recipient<NotifyChange<M>>,
27}
28
29/// 设置压缩结果订阅者。Reply = `()`。
30///
31/// 在 [`RequestCompress`](super::inbound::RequestCompress) 生成摘要后、写入 compressed 区之前,
32/// 将 [`NotifyCompressedForReply`] 发送给订阅者,订阅者返回修改后的 `(摘要, 保留)` 对。
33/// 后设覆盖前设(单例语义)。
34pub struct RequestSubscribeCompressed<M: Send + 'static> {
35 /// 压缩结果订阅者引用
36 pub recipient: ReplyRecipient<NotifyCompressedForReply<M>, (Vec<M>, Vec<M>)>,
37}
38
39/// 清除压缩结果订阅者。Reply = `()`。
40///
41/// 清除后 [`RequestCompress`](super::inbound::RequestCompress) 将跳过订阅者处理,直接使用原始摘要。
42pub struct RequestUnsubscribeCompressed;