recording

package
v1.1.6 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package recording provides session recording export and import for replay and analysis.

Package recording provides session recording export, import, and replay.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EventIterator

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

EventIterator provides iteration over events in time order.

func (*EventIterator) Next

func (it *EventIterator) Next() (RecordedEvent, bool)

Next returns the next event and true, or false if no more events.

type ExportOptions

type ExportOptions struct {
	// ProviderName to include in metadata.
	ProviderName string

	// Model to include in metadata.
	Model string

	// Custom metadata to include.
	Custom map[string]any
}

ExportOptions configures the export process.

type Format

type Format string

Format specifies the recording file format.

const (
	// FormatJSON uses JSON encoding (human-readable, larger files).
	FormatJSON Format = "json"
	// FormatJSONLines uses JSON Lines encoding (streamable, one event per line).
	FormatJSONLines Format = "jsonl"
)

type MessageSnapshot

type MessageSnapshot struct {
	Role      string
	Content   string
	Timestamp time.Time
	Offset    time.Duration
}

MessageSnapshot represents a message at a point in time.

type Metadata

type Metadata struct {
	// SessionID is the unique identifier for this session.
	SessionID string `json:"session_id"`

	// ConversationID groups related turns within a session.
	ConversationID string `json:"conversation_id,omitempty"`

	// StartTime is when the session began.
	StartTime time.Time `json:"start_time"`

	// EndTime is when the session ended.
	EndTime time.Time `json:"end_time"`

	// Duration is the total session length.
	Duration time.Duration `json:"duration"`

	// EventCount is the total number of events.
	EventCount int `json:"event_count"`

	// ProviderName is the LLM provider used (e.g., "openai", "gemini").
	ProviderName string `json:"provider_name,omitempty"`

	// Model is the model identifier used.
	Model string `json:"model,omitempty"`

	// Version is the recording format version.
	Version string `json:"version"`

	// CreatedAt is when this recording was exported.
	CreatedAt time.Time `json:"created_at"`

	// Custom allows arbitrary metadata to be attached.
	Custom map[string]any `json:"custom,omitempty"`
}

Metadata contains session-level information.

type PlaybackState

type PlaybackState struct {
	// Position is the current offset from session start.
	Position time.Duration

	// Timestamp is the absolute timestamp at this position.
	Timestamp time.Time

	// CurrentEvents are events occurring at exactly this position (within tolerance).
	CurrentEvents []RecordedEvent

	// RecentEvents are events that occurred in the last `window` duration.
	RecentEvents []RecordedEvent

	// ActiveAnnotations are annotations whose time range includes this position.
	ActiveAnnotations []*annotations.Annotation

	// Messages accumulated up to this point.
	Messages []MessageSnapshot

	// AudioInputActive indicates if user audio is present at this position.
	AudioInputActive bool

	// AudioOutputActive indicates if assistant audio is present at this position.
	AudioOutputActive bool
}

PlaybackState represents the state at a given playback position.

type RecordedEvent

type RecordedEvent struct {
	// Sequence is the event's position in the recording.
	Sequence int64 `json:"seq"`

	// ParentSequence links to a parent event (for causality).
	ParentSequence int64 `json:"parent_seq,omitempty"`

	// Type is the event type.
	Type events.EventType `json:"type"`

	// Timestamp is when the event occurred.
	Timestamp time.Time `json:"timestamp"`

	// Offset is the time since session start.
	Offset time.Duration `json:"offset"`

	// SessionID identifies the session.
	SessionID string `json:"session_id"`

	// ConversationID identifies the conversation within the session.
	ConversationID string `json:"conversation_id,omitempty"`

	// RunID identifies the specific run/request.
	RunID string `json:"run_id,omitempty"`

	// DataType is the Go type name of the original data.
	DataType string `json:"data_type,omitempty"`

	// Data is the event payload as raw JSON.
	Data json.RawMessage `json:"data,omitempty"`
}

RecordedEvent wraps an event with additional recording-specific data.

type ReplayPlayer

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

ReplayPlayer provides synchronized playback of session recordings with event correlation. It allows seeking to any position and retrieving events/annotations at that time.

func NewReplayPlayer

func NewReplayPlayer(rec *SessionRecording) (*ReplayPlayer, error)

NewReplayPlayer creates a new replay player for the given recording.

func (*ReplayPlayer) Advance

func (rp *ReplayPlayer) Advance(duration time.Duration) []RecordedEvent

Advance moves the position forward by the specified duration and returns any events that occurred during that interval.

func (*ReplayPlayer) AdvanceTo

func (rp *ReplayPlayer) AdvanceTo(target time.Duration) []RecordedEvent

AdvanceTo moves to the specified position and returns events encountered.

func (*ReplayPlayer) Duration

func (rp *ReplayPlayer) Duration() time.Duration

Duration returns the total recording duration.

func (*ReplayPlayer) FormatPosition

func (rp *ReplayPlayer) FormatPosition() string

FormatPosition returns a human-readable position string.

func (*ReplayPlayer) GetEventsByType

func (rp *ReplayPlayer) GetEventsByType(eventType events.EventType) []RecordedEvent

GetEventsByType returns all events of the specified type.

func (*ReplayPlayer) GetEventsInRange

func (rp *ReplayPlayer) GetEventsInRange(start, end time.Duration) []RecordedEvent

GetEventsInRange returns all events within the specified time range.

func (*ReplayPlayer) GetState

func (rp *ReplayPlayer) GetState() *PlaybackState

GetState returns the playback state at the current position.

func (*ReplayPlayer) GetStateAt

func (rp *ReplayPlayer) GetStateAt(offset time.Duration) *PlaybackState

GetStateAt returns the playback state at the specified offset.

func (*ReplayPlayer) NewEventIterator

func (rp *ReplayPlayer) NewEventIterator(start, end time.Duration) *EventIterator

NewEventIterator creates an iterator over events from start to end.

func (*ReplayPlayer) Position

func (rp *ReplayPlayer) Position() time.Duration

Position returns the current playback position.

func (*ReplayPlayer) Recording

func (rp *ReplayPlayer) Recording() *SessionRecording

Recording returns the underlying session recording.

func (*ReplayPlayer) Seek

func (rp *ReplayPlayer) Seek(offset time.Duration)

Seek moves the playback position to the specified offset from session start.

func (*ReplayPlayer) SetAnnotations

func (rp *ReplayPlayer) SetAnnotations(anns []*annotations.Annotation)

SetAnnotations adds annotations for correlation during playback.

func (*ReplayPlayer) Timeline

func (rp *ReplayPlayer) Timeline() *events.MediaTimeline

Timeline returns the media timeline for audio access.

type SessionRecording

type SessionRecording struct {
	// Metadata about the recording
	Metadata Metadata `json:"metadata"`

	// Events in chronological order
	Events []RecordedEvent `json:"events"`
}

SessionRecording is a self-contained artifact for replay and analysis. It contains all information needed to replay a session without access to the original event store.

func Export

func Export(ctx context.Context, store events.EventStore, sessionID string) (*SessionRecording, error)

Export creates a SessionRecording from stored events.

func ExportWithOptions

func ExportWithOptions(
	ctx context.Context,
	store events.EventStore,
	sessionID string,
	opts ExportOptions,
) (*SessionRecording, error)

ExportWithOptions creates a SessionRecording with additional metadata.

func Load

func Load(path string) (*SessionRecording, error)

Load reads a recording from a file. Supports multiple formats: - JSON: Full SessionRecording struct - JSONL (SessionRecording): First line is {"type":"metadata",...}, subsequent lines are {"type":"event",...} - JSONL (EventStore): Lines are {"seq":N,"event":{...}} format from FileEventStore

func (*SessionRecording) Duration

func (r *SessionRecording) Duration() time.Duration

Duration returns the total duration of the recording.

func (*SessionRecording) SaveTo

func (r *SessionRecording) SaveTo(path string, format Format) error

SaveTo writes the recording to a file.

func (*SessionRecording) String

func (r *SessionRecording) String() string

String returns a human-readable summary of the recording.

func (*SessionRecording) ToEvents

func (r *SessionRecording) ToEvents() []*events.Event

ToEvents converts recorded events back to Event objects. Note: Data is left as nil since concrete types cannot be recovered without deserialization. Use ToTypedEvents() for full data recovery.

func (*SessionRecording) ToMediaTimeline

func (r *SessionRecording) ToMediaTimeline(blobStore events.BlobStore) (*events.MediaTimeline, error)

ToMediaTimeline creates a MediaTimeline from this recording for audio/video reconstruction. The blobStore is optional and used for loading external blob references (nil for inline data only).

func (*SessionRecording) ToTypedEvents

func (r *SessionRecording) ToTypedEvents() ([]*events.Event, error)

ToTypedEvents converts recorded events back to Event objects with properly typed Data fields. This enables reconstruction of audio/video tracks via MediaTimeline.

Jump to

Keyboard shortcuts

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