events

package
v0.9.3 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package events is the domain-event spine: a single typed, causation-aware bus that any part of Vega can publish onto and subscribe to. The SSE broker and worker telemetry become projections of it; the reactive trigger router is a third subscriber. See docs/reactive-agents-design.md (decision D3).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextWithOrigin

func ContextWithOrigin(ctx context.Context, o *Origin) context.Context

ContextWithOrigin attaches the causation an event should carry if it is emitted during work done on ctx's behalf. The reactive router sets this on a wake's context so any events the wake emits inherit its chain depth.

func Depth

func Depth(e Event) int

Depth returns an event's reactive-chain depth: its Origin's Depth, or 0 for a root event with no Origin.

Types

type Bus

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

Bus is an in-process publish/subscribe spine. Publish is non-blocking with respect to every subscriber regardless of delivery mode.

Durability here means guaranteed in-process, in-order delivery to durable subscribers. Cross-restart persistence (an events table with replay) is a later layer behind this same interface — see design §8 open decision #1.

func NewBus

func NewBus() *Bus

NewBus returns a ready-to-use Bus.

func (*Bus) Close

func (b *Bus) Close()

Close tears down the bus and all its subscriptions.

func (*Bus) Publish

func (b *Bus) Publish(e Event) Event

Publish stamps the event's ID and Time if unset, delivers it to every matching subscriber, and returns the stamped event.

func (*Bus) Subscribe

func (b *Bus) Subscribe(mode DeliveryMode, filter func(Event) bool) *Subscription

Subscribe registers a subscriber. If filter is non-nil, only events for which it returns true are delivered. Read from the returned Subscription's C channel; call Close when done.

type DeliveryMode

type DeliveryMode int

DeliveryMode controls how a subscriber tolerates backpressure.

const (
	// Lossy drops events when the subscriber's buffer is full rather than
	// blocking the publisher. Correct for a UI that can miss a frame.
	Lossy DeliveryMode = iota
	// Durable never drops: events queue without bound until delivered, in
	// order. Correct for reactive triggers, which must not miss a creak.
	Durable
)

type Event

type Event struct {
	ID     string
	Type   string
	Data   map[string]any
	Origin *Origin
	Time   time.Time
}

Event is a single occurrence on the spine. Type is a dotted noun.verb string (e.g. "agent.completed"). Data carries the event-specific payload. ID and Time are stamped by the bus at Publish if left zero.

type Origin

type Origin struct {
	EventID   string // the event that triggered the run that emitted this one
	AgentName string // the agent whose reactive run emitted it
	Depth     int    // reactive-chain depth
}

Origin carries typed causation — what caused this event. It is nil for external/root events (a human message, a cron fire, a sensor). When a reactive run emits events, they inherit the triggering event's Origin with Depth incremented, which is what the loop guard uses to cap reactive chains (design D2 / §5.3).

func OriginFromContext

func OriginFromContext(ctx context.Context) *Origin

OriginFromContext returns the causation attached to ctx, or nil for a root context (a human message, a cron fire, an external sensor).

type Subscription

type Subscription struct {
	C <-chan Event
	// contains filtered or unexported fields
}

Subscription is a handle to a stream of events. Read from C.

func (*Subscription) Close

func (s *Subscription) Close()

Close stops delivery to this subscription and closes C.

Jump to

Keyboard shortcuts

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