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 ¶
- Variables
- func Persist(ctx context.Context, st store.Store, runID string, evs []store.Event) ([]store.Event, error)
- type Log
- type MemoryLog
- func (l *MemoryLog) Finalizing(context.Context, string, time.Duration) func()
- func (l *MemoryLog) Repair(context.Context) (int, error)
- func (l *MemoryLog) Replay(ctx context.Context, runID string, afterSeq int64) <-chan store.Event
- func (l *MemoryLog) Resume(ctx context.Context, runID string, dbLastSeq int64) (Writer, error)
- func (l *MemoryLog) Writer(runID string, lastSeq int64) Writer
- type Writer
Constants ¶
This section is empty.
Variables ¶
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 (*MemoryLog) Finalizing ¶
Finalizing is a no-op: replay never synthesizes a terminal event.
func (*MemoryLog) Replay ¶
Replay streams events with seq > afterSeq, then tails until a terminal event.
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.