observers

package
v0.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 12, 2026 License: BSD-2-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package observers provides pipeline observers: components that watch the frames flowing through a pipeline to derive turn, latency and startup metrics, or to log the stream, without modifying it. Register them via pipeline.TaskParams.Observers.

The pipeline reports frames at its two ends, so these observers track the turn-taking and bot-output frames that travel there (StartFrame, the user/bot speaking frames, TTS audio). Each observer is safe for concurrent use: the two ends run on separate goroutines.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LatencyConfig

type LatencyConfig struct {
	// OnLatency is called with the time from the user stopping speaking to the
	// bot starting — the user-perceived response latency.
	OnLatency func(d time.Duration)
}

LatencyConfig configures a UserBotLatency observer.

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

Logger logs every frame it observes, for debugging a pipeline's frame flow.

func NewLogger

func NewLogger(cfg LoggerConfig) *Logger

NewLogger builds a Logger observer.

func (*Logger) OnFrame

func (o *Logger) OnFrame(f frames.Frame, dir processor.Direction)

OnFrame implements pipeline.Observer.

type LoggerConfig

type LoggerConfig struct {
	// Logger is the destination; slog.Default() when nil.
	Logger *slog.Logger
	// Level is the log level; the zero value is slog.LevelInfo.
	Level slog.Level
	// Filter, when set, logs only frames for which it returns true.
	Filter func(frames.Frame) bool
}

LoggerConfig configures a Logger observer.

type StartupConfig

type StartupConfig struct {
	// OnStartup is called once with the time from pipeline start to the first bot
	// audio — the cold-start latency of the first response.
	OnStartup func(d time.Duration)
}

StartupConfig configures a StartupTiming observer.

type StartupTiming

type StartupTiming struct {
	// contains filtered or unexported fields
}

StartupTiming measures the time from the pipeline starting to the first bot audio, the cold-start latency before the bot first speaks.

func NewStartupTiming

func NewStartupTiming(cfg StartupConfig) *StartupTiming

NewStartupTiming builds a StartupTiming observer.

func (*StartupTiming) OnFrame

func (o *StartupTiming) OnFrame(f frames.Frame, _ processor.Direction)

OnFrame implements pipeline.Observer.

type TurnTracking

type TurnTracking struct {
	// contains filtered or unexported fields
}

TurnTracking tracks conversational turns. The first turn starts with the pipeline; a turn ends when the bot finishes speaking (after TurnEndTimeout) or is interrupted by the user, at which point the next turn starts.

func NewTurnTracking

func NewTurnTracking(cfg TurnTrackingConfig) *TurnTracking

NewTurnTracking builds a TurnTracking observer.

func (*TurnTracking) OnFrame

func (o *TurnTracking) OnFrame(f frames.Frame, _ processor.Direction)

OnFrame implements pipeline.Observer.

type TurnTrackingConfig

type TurnTrackingConfig struct {
	// TurnEndTimeout is how long after the bot stops speaking a turn ends; 0 uses
	// 2.5s. The delay lets a turn survive a brief gap between bot utterances (an
	// HTTP TTS boundary, a function call) without splitting into two turns.
	TurnEndTimeout time.Duration
	// OnTurnStarted is called when a turn begins, with the 1-based turn number.
	OnTurnStarted func(turn int)
	// OnTurnEnded is called when a turn ends, with the turn number, its duration,
	// and whether it was cut short by an interruption.
	OnTurnEnded func(turn int, duration time.Duration, interrupted bool)
}

TurnTrackingConfig configures a TurnTracking observer.

type UserBotLatency

type UserBotLatency struct {
	// contains filtered or unexported fields
}

UserBotLatency measures the response latency of each turn: the gap between the user stopping speaking and the bot starting.

func NewUserBotLatency

func NewUserBotLatency(cfg LatencyConfig) *UserBotLatency

NewUserBotLatency builds a UserBotLatency observer.

func (*UserBotLatency) OnFrame

func (o *UserBotLatency) OnFrame(f frames.Frame, _ processor.Direction)

OnFrame implements pipeline.Observer.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL