eventlog

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: MIT Imports: 9 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package eventlog is the per-run AG-UI event log contract and its in-process implementation (MemoryLog). Shared implementations (Redis streams for live tailing, the store for durability) live in the adapter packages, e.g. redisx.

Index

Constants

This section is empty.

Variables

View Source
var ErrConflict = errors.New("eventlog: seq already written by another writer")

ErrConflict means another writer already wrote this seq (ownership lost).

Functions

func Persist

func Persist(ctx context.Context, st store.Store, runID string, evs []store.Event) ([]store.Event, error)

Persist writes events to the store; it returns the events still to write (transient error) and drops only rows the store refuses permanently (data/constraint errors). Adapters use it to flush their buffers.

Types

type Log

type Log interface {
	Writer(runID string, lastSeq int64) Writer
	// Resume positions a writer after the highest seq already written (live
	// stream or store), backfilling the store first. Used to finish runs of a
	// dead runtime.
	Resume(ctx context.Context, runID string, dbLastSeq int64) (Writer, error)
	// Repair copies, from the live stream to the store, the events of runs whose final flush
	// failed (store outage at run end). Idempotent; returns runs completed.
	Repair(ctx context.Context) (int, error)
	// Replay streams events with seq > afterSeq, gap- and duplicate-free, then
	// tails until a terminal event. The channel closes at the end or on ctx done.
	Replay(ctx context.Context, runID string, afterSeq int64) <-chan store.Event
	// Finalizing marks a run whose row is (about to be) terminal while its end-of-run
	// continuations still emit events before the terminal one: replay keeps waiting
	// for the real terminal event instead of synthesizing one. The returned func
	// clears the mark (it also expires after ttl).
	Finalizing(ctx context.Context, runID string, ttl time.Duration) func()
}

Log creates writers and replays runs.

type MemoryLog

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

MemoryLog is a Log that needs no Redis: the live events of a run are held in the process (tailing is a broadcast) and Flush persists them to the Store. It is the log of a single-process host (TUI, desktop app, tests); runs of a previous process replay from the Store.

func NewMemory

func NewMemory(st store.Store) *MemoryLog

NewMemory returns a MemoryLog persisting to st (nil: nothing is persisted).

func (*MemoryLog) Finalizing

func (l *MemoryLog) Finalizing(context.Context, string, time.Duration) func()

Finalizing is a no-op: replay never synthesizes a terminal event.

func (*MemoryLog) Repair

func (l *MemoryLog) Repair(context.Context) (int, error)

Repair is a no-op: nothing is copied between stores.

func (*MemoryLog) Replay

func (l *MemoryLog) Replay(ctx context.Context, runID string, afterSeq int64) <-chan store.Event

Replay streams events with seq > afterSeq, then tails until a terminal event.

func (*MemoryLog) Resume

func (l *MemoryLog) Resume(ctx context.Context, runID string, dbLastSeq int64) (Writer, error)

Resume positions a writer after the highest seq written, in memory or in the store.

func (*MemoryLog) Writer

func (l *MemoryLog) Writer(runID string, lastSeq int64) Writer

type Writer

type Writer interface {
	// Append assigns the next seq, publishes the event live and buffers it for the store.
	Append(ctx context.Context, ev agui.Event) (int64, error)
	// Flush persists buffered events to the store (and work_runs.last_seq).
	Flush(ctx context.Context) error
	// Close flushes and schedules expiry of the live stream.
	Close(ctx context.Context) error
	LastSeq() int64
	// Terminal returns the log's terminal event (RUN_FINISHED/RUN_ERROR) if it has one.
	Terminal() (store.Event, bool)
}

Writer appends events of one run. There is a single writer per run.

Jump to

Keyboard shortcuts

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