hive-agent: add stream_enrich module — stamp _icon/_summary/_category on SSE events
Move per-message rendering logic from frontend JS to backend Rust. A new stream_enrich::enrich() function stamps display fields onto LiveEvent::Stream payloads at SSE-emit time (both live tail and history replay), so the frontend can consume pre-computed fields instead of re-implementing the dispatch logic in JavaScript. Phase 1: backend stamps _icon/_summary/_category; client falls back to its own JS tables when absent. Zero user-visible change. - system events: _category (drop/thinking_tok/note/details) + _summary and optional _body (commands_changed expands to a slash-cmd list) - assistant tool_use entries: _icon + _summary per tool; rich tools (Write, Edit, send, ask, answer) get _category: 'rich' - enrichment applied in web_ui/stream.rs at emit time; DB stores raw events so no migration is needed when enrichment logic changes - idempotent: existing _-prefixed fields are left unchanged
This commit is contained in:
parent
617eecf94e
commit
ae3f011eb3
3 changed files with 733 additions and 1 deletions
|
|
@ -40,6 +40,17 @@ pub(super) async fn events_history(
|
|||
};
|
||||
|
||||
let (events, min_id, has_more) = state.bus.history_page(before, limit);
|
||||
// Apply the same enrichment as the live SSE path so history replay
|
||||
// and live tail deliver identical shapes. The DB stores raw events.
|
||||
let events: Vec<_> = events
|
||||
.into_iter()
|
||||
.map(|mut se| {
|
||||
if let crate::events::LiveEvent::Stream(ref mut v) = se.event {
|
||||
crate::stream_enrich::enrich(v);
|
||||
}
|
||||
se
|
||||
})
|
||||
.collect();
|
||||
let mut resp = serde_json::json!({
|
||||
"events": events,
|
||||
"min_id": min_id,
|
||||
|
|
@ -68,7 +79,15 @@ pub(super) async fn events_stream(
|
|||
.unwrap_or_default(),
|
||||
);
|
||||
let live = BroadcastStream::new(rx).filter_map(|res| {
|
||||
let ev = res.ok()?;
|
||||
let mut ev = res.ok()?;
|
||||
// Enrich stream-json values with pre-computed display fields
|
||||
// (`_icon`, `_summary`, `_category`) so the frontend doesn't need to
|
||||
// duplicate the dispatch logic. The DB stores raw events; enrichment
|
||||
// is applied here so both the live tail and the history endpoint
|
||||
// deliver the same shape (see `events_history` below).
|
||||
if let crate::events::LiveEvent::Stream(ref mut v) = ev.event {
|
||||
crate::stream_enrich::enrich(v);
|
||||
}
|
||||
let json = serde_json::to_string(&ev).ok()?;
|
||||
Some(Ok(Event::default().data(json)))
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue