host: expose harness state and actions over the world API

This commit is contained in:
2026-11-07 19:22:06 +00:00
parent c3c5b36d09
commit 5dc4833e28
33 changed files with 33178 additions and 112 deletions
+22 -2
View File
@@ -15,6 +15,14 @@ pub enum Input {
#[serde(rename = "requestId")]
request_id: String,
},
Api {
id: String,
method: String,
path: String,
body: Value,
#[serde(skip)]
reply: mpsc::UnboundedSender<Value>,
},
Stop,
}
@@ -31,8 +39,20 @@ pub(super) struct Inbox(pub tokio::sync::Mutex<Receiver>);
#[serde]
pub async fn op_input(state: Rc<RefCell<OpState>>) -> Result<serde_json::Value, JsErrorBox> {
let inbox = state.borrow().borrow::<Rc<Inbox>>().clone();
serde_json::to_value(inbox.0.lock().await.recv().await)
.map_err(|error| JsErrorBox::generic(error.to_string()))
let input = inbox.0.lock().await.recv().await;
if let Some(Input::Api { id, reply, .. }) = &input {
state
.borrow_mut()
.borrow_mut::<super::http::Replies>()
.insert(
id.clone(),
super::http::Reply {
sender: reply.clone(),
finished: Default::default(),
},
);
}
serde_json::to_value(input).map_err(|error| JsErrorBox::generic(error.to_string()))
}
pub(super) fn console(sender: Sender) {