rinne_core/worker/event.rs
1//! Streaming worker events (`CONTEXT.md` §8 lifecycle, §6 stream pane).
2//!
3//! A worker emits events as it runs; the dispatcher forwards them to the
4//! interface's stream pane. The channel is the worker's only way to narrate
5//! progress before its final [`ExecuteResult`](super::ExecuteResult).
6
7use serde::{Deserialize, Serialize};
8
9/// A single streamed event from a running worker.
10#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
11#[serde(rename_all = "snake_case", tag = "kind", content = "data")]
12pub enum WorkerEvent {
13 /// A line of human-readable narration ("reading src/, editing app.ts").
14 Message(String),
15 /// A raw streaming text delta from a token-streaming worker (API/HTTP, Grok).
16 /// Consumers concatenate these verbatim — fragments are often mid-word, so no
17 /// separator is inserted between them. This is what lets the UI reconstruct
18 /// and markdown-render any streamed model output regardless of the worker.
19 Token(String),
20 /// A reasoning ("thinking") delta from a reasoning model (e.g. DeepSeek-R1,
21 /// o-series). Streamed separately from [`Token`] content and never part of
22 /// the final answer, so the UI can show it dimmed without polluting the
23 /// result passed to the next node.
24 Thinking(String),
25 /// The worker began reading a file/path.
26 Reading(String),
27 /// The worker edited a file/path.
28 Editing(String),
29 /// The worker invoked a tool/command.
30 ToolUse(String),
31 /// Raw stdout/stderr passthrough, used when no richer structure exists.
32 Raw(String),
33 /// Terminal marker: the worker finished emitting events.
34 Done,
35}
36
37/// The sink a worker writes events to. The dispatcher owns the receiver.
38///
39/// Unbounded so a worker never blocks on a slow consumer; events are cheap and
40/// the UI drains them promptly.
41pub type EventSink = tokio::sync::mpsc::UnboundedSender<WorkerEvent>;
42
43/// Convenience: send an event, ignoring the error if the receiver is gone
44/// (e.g. the run was cancelled and the dispatcher dropped its end).
45pub fn emit(sink: &EventSink, event: WorkerEvent) {
46 let _ = sink.send(event);
47}