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
@@ -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);
|
||||
}
|
||||
Reference in new issue
Block a user