use serde_json::{Map, Value, json};
use crate::boundary::Action;
use super::str_of;
pub(super) const MESSAGE: &str = "message";
pub(super) const INTERRUPT: &str = "interrupt";
pub(super) fn deposit(op: &str, workspace: &str, agent: &str, content: &str) -> Value {
json!({ "op": op, "workspace": workspace, "agent": agent, "content": content })
}
pub(super) fn deposited(op: &str, o: &Map<String, Value>) -> Result<Action, String> {
let workspace = str_of(o, "workspace")?;
let agent = str_of(o, "agent")?;
let content = str_of(o, "content")?;
Ok(match op {
INTERRUPT => Action::Interrupt {
workspace,
agent,
content,
},
_ => Action::Message {
workspace,
agent,
content,
},
})
}