events

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package events is the in-process event bus: every state change in the system is published here, persisted to the events table (unless ephemeral) and fanned out to live subscribers (dashboard SSE, TUI).

Index

Constants

View Source
const (
	RequestQueued       = "request.queued"
	RequestClaimed      = "request.claimed"
	RequestStreaming    = "request.streaming"
	RequestDelta        = "request.delta" // ephemeral
	RequestCompleted    = "request.completed"
	RequestFailed       = "request.failed"
	RequestRequeued     = "request.requeued"
	RequestCancelled    = "request.cancelled"
	RequestExpired      = "request.expired"
	RequestLeaseExpired = "request.lease_expired"

	ChannelOpened  = "channel.opened"
	ChannelClosed  = "channel.closed"
	ChannelOffline = "channel.offline"
	ChannelOnline  = "channel.online"

	KeyCreated   = "key.created"
	KeyRevoked   = "key.revoked"
	KeyUpdated   = "key.updated"
	TokenCreated = "token.created"
	TokenRevoked = "token.revoked"

	OAuthClientRegistered = "oauth.client_registered"
	OAuthTokenIssued      = "oauth.token_issued"
	OAuthConsentDenied    = "oauth.consent_denied"

	AuthLogin       = "auth.login"
	AuthLoginFailed = "auth.login_failed"
	AuthLogout      = "auth.logout"
	AuthRateLimited = "auth.rate_limited"

	SystemStarted  = "system.started"
	SystemStopped  = "system.stopped"
	SystemPruned   = "system.pruned"
	SettingChanged = "system.setting_changed"
)

Event kinds. Keep these stable: they appear in the dashboard filters and are stored in the database.

View Source
const (
	LevelInfo  = "info"
	LevelWarn  = "warn"
	LevelError = "error"
)

Levels.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bus

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

Bus persists events and fans them out to subscribers.

func New

func New(store func(Event)) *Bus

New creates a bus. store (may be nil) is invoked for every non-ephemeral event before it is delivered to subscribers.

func (*Bus) Close

func (b *Bus) Close()

Close stops accepting events and closes subscribers.

func (*Bus) Dropped

func (b *Bus) Dropped() int64

Dropped reports how many deliveries were skipped because a subscriber's buffer was full.

func (*Bus) Publish

func (b *Bus) Publish(e Event)

Publish records e and then delivers it to subscribers.

Persistence happens first and synchronously, so anything a subscriber learns about is already readable from the store: a dashboard that refreshes a request's timeline in response to an event is guaranteed to see that event. Delivery itself never blocks; a subscriber whose buffer is full misses the event.

Do not call Publish while holding a database transaction: the store writes on its own connection and would wait on the transaction's lock.

func (*Bus) Subscribe

func (b *Bus) Subscribe(buffer int) (<-chan Event, func())

Subscribe returns a channel receiving every published event. Call the returned function to unsubscribe.

func (*Bus) Subscribers

func (b *Bus) Subscribers() int

Subscribers reports the number of live subscribers.

type Event

type Event struct {
	ID             int64          `json:"id,omitempty"`
	Time           time.Time      `json:"time"`
	Kind           string         `json:"kind"`
	Level          string         `json:"level"`
	RequestID      string         `json:"request_id,omitempty"`
	ChannelID      string         `json:"channel_id,omitempty"`
	APIKeyID       string         `json:"api_key_id,omitempty"`
	ConversationID string         `json:"conversation_id,omitempty"`
	Message        string         `json:"message"`
	Data           map[string]any `json:"data,omitempty"`
	// Ephemeral events are fanned out to live subscribers but never persisted.
	Ephemeral bool `json:"-"`
}

Event is a single occurrence in the system.

Jump to

Keyboard shortcuts

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