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