Land OKF aliases, view SSE, workbook nav, and explicit parent ctor.
Complete the core agent roadmap: soft KB hits via Task aliases, EventBus-backed view streaming, D4 writeback/workbook navigation, and I3 explicit-super without implicit auto-super. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
d1ddb74235
commit
2a9fceb51c
26 files changed
+918
-54
No files matched your search
@@ -99,6 +99,7 @@ pub enum HostFn {
|
||||
WritebackScanPath = 97,
|
||||
HttpPostSse = 98,
|
||||
OpenAiSseParse = 99,
|
||||
StreamPublish = 100,
|
||||
}
|
||||
|
||||
impl HostFn {
|
||||
@@ -194,6 +195,7 @@ impl HostFn {
|
||||
97 => Self::WritebackScanPath,
|
||||
98 => Self::HttpPostSse,
|
||||
99 => Self::OpenAiSseParse,
|
||||
100 => Self::StreamPublish,
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
@@ -227,6 +229,7 @@ impl HostFn {
|
||||
"host_http_post" | "http_post" => Self::HttpPost,
|
||||
"host_http_post_sse" | "http_post_sse" => Self::HttpPostSse,
|
||||
"host_openai_sse_parse" | "openai_sse_parse" => Self::OpenAiSseParse,
|
||||
"host_stream_publish" | "stream_publish" => Self::StreamPublish,
|
||||
"host_url_encode" => Self::UrlEncode,
|
||||
"host_pi" => Self::Pi,
|
||||
"host_e" => Self::EConst,
|
||||
@@ -329,6 +332,7 @@ impl HostFn {
|
||||
Self::HttpPost => "host_http_post",
|
||||
Self::HttpPostSse => "host_http_post_sse",
|
||||
Self::OpenAiSseParse => "host_openai_sse_parse",
|
||||
Self::StreamPublish => "host_stream_publish",
|
||||
Self::UrlEncode => "host_url_encode",
|
||||
Self::Pi => "host_pi",
|
||||
Self::EConst => "host_e",
|
||||
@@ -417,6 +421,7 @@ impl HostFn {
|
||||
Self::HttpPost => &["url", "body"],
|
||||
Self::HttpPostSse => &["url", "body"],
|
||||
Self::OpenAiSseParse => &["text"],
|
||||
Self::StreamPublish => &["event"],
|
||||
Self::HttpRequest => &["method", "url"],
|
||||
Self::DotenvLoad => &[],
|
||||
Self::Pi | Self::EConst | Self::Random => &[],
|
||||
@@ -547,6 +552,10 @@ pub fn call_host(
|
||||
HostFn::OpenAiSseParse => {
|
||||
net::openai_sse_parse(require(bound, "text")?, bound.get("echo"))
|
||||
}
|
||||
HostFn::StreamPublish => {
|
||||
crate::host::event_bus::publish(require(bound, "event")?);
|
||||
Ok(Value::Bool(true))
|
||||
}
|
||||
HostFn::HttpRequest => net::http_request(
|
||||
ctx,
|
||||
require(bound, "method")?,
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
//! Process-wide stream event bus for `marqdo view` SSE (S3).
|
||||
//! Publishers: LLM SSE parse, optional `host_stream_publish`.
|
||||
//! Subscribers: view `GET /api/events`.
|
||||
|
||||
use std::sync::mpsc::{self, Receiver, Sender};
|
||||
use std::sync::{Mutex, OnceLock};
|
||||
|
||||
use crate::host::json::value_to_json;
|
||||
use crate::value::Value;
|
||||
|
||||
static BUS: OnceLock<EventBus> = OnceLock::new();
|
||||
|
||||
pub struct EventBus {
|
||||
subs: Mutex<Vec<Sender<String>>>,
|
||||
}
|
||||
|
||||
impl EventBus {
|
||||
fn new() -> Self {
|
||||
Self {
|
||||
subs: Mutex::new(Vec::new()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn global() -> &'static EventBus {
|
||||
BUS.get_or_init(EventBus::new)
|
||||
}
|
||||
|
||||
/// Subscribe to JSON event lines (already serialized maps).
|
||||
pub fn subscribe(&self) -> Receiver<String> {
|
||||
let (tx, rx) = mpsc::channel();
|
||||
if let Ok(mut g) = self.subs.lock() {
|
||||
g.push(tx);
|
||||
}
|
||||
rx
|
||||
}
|
||||
|
||||
pub fn publish_json(&self, json_line: &str) {
|
||||
let Ok(mut g) = self.subs.lock() else {
|
||||
return;
|
||||
};
|
||||
g.retain(|tx| tx.send(json_line.to_string()).is_ok());
|
||||
}
|
||||
|
||||
pub fn publish_value(&self, v: &Value) {
|
||||
if let Ok(j) = value_to_json(v) {
|
||||
self.publish_json(&j.to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Publish a Marqdo map (or any value) onto the global bus.
|
||||
pub fn publish(v: &Value) {
|
||||
EventBus::global().publish_value(v);
|
||||
}
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
pub mod agent_rt;
|
||||
mod dispatch;
|
||||
pub mod event_bus;
|
||||
pub mod foreign;
|
||||
mod fs;
|
||||
pub(crate) mod json;
|
||||
|
||||
+20
-10
@@ -232,10 +232,12 @@ fn push_openai_delta_events(
|
||||
.and_then(|m| m.as_str())
|
||||
.or_else(|| e.as_str())
|
||||
}) {
|
||||
events.push(event_map(vec![
|
||||
let ev = event_map(vec![
|
||||
("type", Value::Text("error".into())),
|
||||
("message", Value::Text(msg.into())),
|
||||
]));
|
||||
]);
|
||||
crate::host::event_bus::publish(&ev);
|
||||
events.push(ev);
|
||||
return true;
|
||||
}
|
||||
let reasoning = v
|
||||
@@ -249,10 +251,12 @@ fn push_openai_delta_events(
|
||||
let _ = std::io::stdout().flush();
|
||||
*echoed = true;
|
||||
}
|
||||
events.push(event_map(vec![
|
||||
let ev = event_map(vec![
|
||||
("type", Value::Text("reasoning".into())),
|
||||
("text", Value::Text(reasoning.into())),
|
||||
]));
|
||||
]);
|
||||
crate::host::event_bus::publish(&ev);
|
||||
events.push(ev);
|
||||
}
|
||||
let content = v
|
||||
.pointer("/choices/0/delta/content")
|
||||
@@ -269,10 +273,12 @@ fn push_openai_delta_events(
|
||||
let _ = std::io::stdout().flush();
|
||||
*echoed = true;
|
||||
}
|
||||
events.push(event_map(vec![
|
||||
let ev = event_map(vec![
|
||||
("type", Value::Text("delta".into())),
|
||||
("text", Value::Text(content.into())),
|
||||
]));
|
||||
]);
|
||||
crate::host::event_bus::publish(&ev);
|
||||
events.push(ev);
|
||||
}
|
||||
false
|
||||
}
|
||||
@@ -321,10 +327,12 @@ pub fn openai_chat_sse_events(text: &str, echo: bool) -> Result<Vec<Value>, Stri
|
||||
]));
|
||||
return Ok(events);
|
||||
}
|
||||
events.push(event_map(vec![
|
||||
let done = event_map(vec![
|
||||
("type", Value::Text("done".into())),
|
||||
("result", Value::Text(result)),
|
||||
]));
|
||||
]);
|
||||
crate::host::event_bus::publish(&done);
|
||||
events.push(done);
|
||||
Ok(events)
|
||||
}
|
||||
|
||||
@@ -424,10 +432,12 @@ fn read_sse_body_to_events<R: BufRead>(
|
||||
if events.iter().any(|e| matches!(e, Value::Map(m) if m.iter().any(|(k,v)| k == "type" && matches!(v, Value::Text(t) if t == "error")))) {
|
||||
return Ok(events);
|
||||
}
|
||||
events.push(event_map(vec![
|
||||
let done = event_map(vec![
|
||||
("type", Value::Text("done".into())),
|
||||
("result", Value::Text(result)),
|
||||
]));
|
||||
]);
|
||||
crate::host::event_bus::publish(&done);
|
||||
events.push(done);
|
||||
Ok(events)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user