use agent_client_protocol::{
schema::v1::{Meta, SessionId},
Error, UntypedMessage,
};
use serde_json::{json, Value};
pub(super) const METHOD: &str = "_session/steering";
pub(super) fn supported(meta: Option<&Meta>) -> bool {
meta.and_then(|meta| meta.get("steering"))
.and_then(|steering| steering.get("supported"))
.and_then(Value::as_bool)
== Some(true)
}
pub(super) fn request(session_id: &SessionId, text: &str) -> Result<UntypedMessage, Error> {
UntypedMessage::new(
METHOD,
json!({
"sessionId": session_id,
"prompt": [{"type": "text", "text": text}],
"_meta": {"steering": {"idleBehavior": "promptRequired"}},
}),
)
}
#[derive(Debug, PartialEq, Eq)]
pub(super) enum Delivery {
Injected,
NextTurn,
}
pub(super) fn delivery(reply: &Value) -> Delivery {
match reply.get("outcome").and_then(Value::as_str) {
Some("injected") => Delivery::Injected,
_ => Delivery::NextTurn,
}
}