Select execution observers from context

This commit is contained in:
2026-11-22 18:07:17 +00:00
parent f762c0358e
commit ea7cc170ad
6 changed files with 104 additions and 6 deletions

View File

@@ -17,6 +17,18 @@ import (
// event, and Promptkit keeps no asynchronous queue or durable history.
type ExecutionObserver func(ExecutionEvent)
// WithExecutionObserver adds an observer to executions using the returned
// context. Inherited observers run before the newly added observer. A nil
// observer leaves the context unchanged.
func WithExecutionObserver(ctx context.Context, observer ExecutionObserver) context.Context {
if observer == nil {
return ctx
}
return observation.WithObserver(ctx, func(event domain.ExecutionEvent) {
observer(fromDomainExecutionEvent(event))
})
}
// ComposeObservers returns a synchronous ordered fan-out of non-nil observers.
// It copies the input slice; a panic propagates and prevents later callbacks.
func ComposeObservers(observers ...ExecutionObserver) ExecutionObserver {