causa_runtime/event/observation.rs
1use crate::executor::ToolProcessingError;
2use causa_kernel::{ContextBlock, InvocationId, ModelOutput, ModelRequest, StreamDelta, ToolBatch};
3
4/// Borrowed execution observations. Callbacks must return promptly.
5///
6/// No event history is retained by the runner. `ModelDelta` excludes `Done`
7/// and `Error`; a committed notification describes only the actual append.
8#[derive(Debug)]
9pub enum RunEvent<'a> {
10 /// A complete logical request, immediately before gateway entry.
11 ModelRequestReady {
12 /// The request to be sent.
13 request: &'a ModelRequest,
14 },
15 /// A nonterminal streaming observation.
16 ModelDelta {
17 /// The logical invocation.
18 invocation_id: &'a InvocationId,
19 /// Text, reasoning, tool-call or usage observation.
20 delta: &'a StreamDelta,
21 },
22 /// A complete model output, before material conversion.
23 ModelOutput {
24 /// The logical invocation.
25 invocation_id: &'a InvocationId,
26 /// The accepted complete output.
27 output: &'a ModelOutput,
28 },
29 /// An atomic append succeeded, including an empty append.
30 BlocksCommitted {
31 /// The logical invocation.
32 invocation_id: &'a InvocationId,
33 /// Actual appended blocks borrowed from the context.
34 blocks: &'a [ContextBlock],
35 },
36 /// Newly committed declarations are about to enter tool processing.
37 ToolBatchReady {
38 /// The logical invocation.
39 invocation_id: &'a InvocationId,
40 /// The complete uncommitted batch.
41 batch: &'a ToolBatch,
42 },
43 /// Tool processing actually returned; results are not yet committed.
44 ToolBatchReturned {
45 /// The logical invocation.
46 invocation_id: &'a InvocationId,
47 /// The complete returned batch.
48 batch: &'a ToolBatch,
49 /// The module's return status, independent of subsequent commit.
50 result: Result<(), &'a ToolProcessingError>,
51 },
52}
53/// A synchronous callback borrowing each observation for the duration of the call.
54pub type RunObserver = dyn for<'a> Fn(&RunEvent<'a>) + Send + Sync;