Skip to main content

awaken_contract/contract/
active_agent.rs

1//! Active agent state key.
2
3/// StateKey for the active agent ID. Handoff writes this.
4pub struct ActiveAgentIdKey;
5
6impl crate::state::StateKey for ActiveAgentIdKey {
7    const KEY: &'static str = "__runtime.active_agent";
8    type Value = Option<String>;
9    type Update = Option<String>;
10
11    fn apply(value: &mut Self::Value, update: Self::Update) {
12        *value = update;
13    }
14}
15
16#[cfg(test)]
17mod tests {
18    use super::*;
19
20    #[test]
21    fn active_agent_key_apply() {
22        use crate::state::StateKey;
23        let mut val: Option<String> = None;
24        ActiveAgentIdKey::apply(&mut val, Some("reviewer".into()));
25        assert_eq!(val.as_deref(), Some("reviewer"));
26        ActiveAgentIdKey::apply(&mut val, None);
27        assert!(val.is_none());
28    }
29}