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 ¶
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.
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 ¶
New creates a bus. store (may be nil) is invoked for every non-ephemeral event before it is delivered to subscribers.
func (*Bus) Dropped ¶
Dropped reports how many deliveries were skipped because a subscriber's buffer was full.
func (*Bus) Publish ¶
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 ¶
Subscribe returns a channel receiving every published event. Call the returned function to unsubscribe.
func (*Bus) Subscribers ¶
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.