Documentation
¶
Index ¶
- Constants
- func InvalidateSession(publisher Publisher, botID, sessionID string)
- func NotifyScheduleChanged(publisher Publisher, botID, scheduleID string)
- func UserTopic(userID string) string
- type Event
- type EventType
- type Hub
- type Publisher
- type ScheduleChange
- type SessionInvalidation
- type Subscriber
- type Subscription
Constants ¶
const (
// DefaultBufferSize is the default per-subscriber channel buffer.
DefaultBufferSize = 64
)
Variables ¶
This section is empty.
Functions ¶
func InvalidateSession ¶ added in v0.20.0
func NotifyScheduleChanged ¶ added in v0.21.0
NotifyScheduleChanged broadcasts a best-effort bot-scoped invalidation.
Types ¶
type Event ¶
type Event struct {
Type EventType `json:"type"`
BotID string `json:"bot_id"`
Data json.RawMessage `json:"data,omitempty"`
}
Event is the normalized payload emitted by the in-process message event hub.
type EventType ¶
type EventType string
EventType identifies the event category published by the message event hub.
const ( // EventTypeMessageCreated is emitted after a message is persisted successfully. EventTypeMessageCreated EventType = "message_created" // EventTypeSessionCreated is emitted after a new user-facing session is // created. Consumers use it to surface a fresh session in sidebars before // the first message arrives. EventTypeSessionCreated EventType = "session_created" // EventTypeSessionTitleUpdated is emitted after a session title is auto-generated. EventTypeSessionTitleUpdated EventType = "session_title_updated" // EventTypeBackgroundTask is emitted for live background task updates. EventTypeBackgroundTask EventType = "background_task" // EventTypeCompactionChanged invalidates the bot's live compaction snapshot. EventTypeCompactionChanged EventType = "compaction_changed" // EventTypeSessionInvalidated marks cached transcripts stale when runtime // admission changes them, or after history is cleared without a new message. EventTypeSessionInvalidated EventType = "session_invalidated" // EventTypeScheduleChanged invalidates a bot's schedule-list snapshot after // a task is created, updated, deleted, or advances its run counters. EventTypeScheduleChanged EventType = "schedule_changed" // EventTypeSessionAttention is published on a user topic when one of that // user's sessions starts needing attention (a run finished, failed or waits // for a decision). It never carries message content. EventTypeSessionAttention EventType = "session_attention" // EventTypeSessionRead is published on a user topic when that user's read // cursor for a session moves, so other tabs and devices clear the dot. EventTypeSessionRead EventType = "session_read" // EventTypeSessionUnread is published on a user topic when that user marks // a session unread. Unlike session_attention it never raises a // notification; it only brings the dot back on other tabs and devices. EventTypeSessionUnread EventType = "session_unread" )
type Hub ¶
type Hub struct {
// contains filtered or unexported fields
}
Hub is an in-process pub/sub dispatcher. Events are keyed by Event.BotID, which is a topic: a bot ID for bot-scoped events, or UserTopic for events addressed to one user.
func NewHub ¶
NewHub creates an empty message event hub. An optional logger is used to rate-limit-log dropped events; if nil, slog.Default() is used.
func (*Hub) Publish ¶
Publish broadcasts one event to all subscribers under the same bot ID. Slow subscribers are accounted for non-blockingly: the per-subscription dropped counter is bumped so the SSE writer can surface a `dropped` frame to the client, and a hub-wide counter is logged at most once per interval for operator visibility.
type Publisher ¶
type Publisher interface {
Publish(event Event)
}
Publisher publishes events to subscribers.
type ScheduleChange ¶ added in v0.21.0
type ScheduleChange struct {
ScheduleID string `json:"schedule_id"`
}
ScheduleChange contains only the changed task identity. Consumers re-read the authorized bot-scoped schedule snapshot instead of trusting event data.
type SessionInvalidation ¶ added in v0.20.0
type SessionInvalidation struct {
SessionID string `json:"session_id"`
}
SessionInvalidation contains only an address. An empty SessionID invalidates all cached sessions of the bot, without exposing any private session ids.
type Subscriber ¶
type Subscriber interface {
Subscribe(botID string, buffer int) (*Subscription, func())
}
Subscriber subscribes to bot-scoped events.
type Subscription ¶
type Subscription struct {
ID string
Events <-chan Event
// contains filtered or unexported fields
}
Subscription is a live event subscription handed back from Subscribe. It exposes the read-only event channel and a counter of events dropped on account of a full subscriber buffer. The counter is consumer-reset so SSE writers can surface a "your view is stale" frame on the wire between regular events.
func (*Subscription) DroppedSinceLastRead ¶
func (s *Subscription) DroppedSinceLastRead() int64
DroppedSinceLastRead returns the number of events dropped on this subscription since the last call (or since Subscribe), then resets the counter to zero atomically. Returning and resetting in one operation keeps the producer free to keep counting concurrent drops.