Expand description
Event callback — a simple observe/filter hook for SDK consumers.
The EventCallback is invoked for each ThreadEvent
before it is yielded from the stream. It can:
- Observe events (return
Some(event)unchanged) - Transform events (return
Some(modified_event)) - Filter events (return
Noneto suppress)
§Processing order
The EventCallback runs after the hook system (crate::hooks).
Events that are blocked or aborted by a hook never reach the EventCallback.
The pipeline per event is:
crate::hooks::dispatch_hook— async, classified, first-matchEventCallback— sync, raw event (only if the hook did not block/abort)
§Example
use std::sync::Arc;
use codex_cli_sdk::callback::EventCallback;
use codex_cli_sdk::ThreadEvent;
// Log all events, pass them through unchanged:
let logger: EventCallback = Arc::new(|event: ThreadEvent| {
eprintln!("received: {event:?}");
Some(event)
});
// Filter out turn-started events:
let filter: EventCallback = Arc::new(|event: ThreadEvent| {
match &event {
ThreadEvent::TurnStarted => None,
_ => Some(event),
}
});Functions§
- apply_
callback - Apply an event callback, or pass through if no callback is set.
Type Aliases§
- Event
Callback - Optional callback invoked for each event received from the CLI.