Documentation
¶
Index ¶
- type Event
- func NewApprovalResponseEvent(sessionID string, approved bool, context string) *Event
- func NewNotificationEvent(sessionID string, sessionName string, notificationID string, ...) *Event
- func NewSessionAcknowledgedEvent(sessionID, reason string) *Event
- func NewSessionCreatedEvent(sess *session.Instance) *Event
- func NewSessionDeletedEvent(sessionID string) *Event
- func NewSessionUpdatedEvent(sess *session.Instance, updatedFields []string) *Event
- func NewSessionUpdatedEventWithDetection(sess *session.Instance, updatedFields []string, ...) *Event
- func NewUserInteractionEvent(sessionID, interactionType, context string) *Event
- type EventBus
- type EventType
- type Subscriber
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Event ¶
type Event struct {
// Seq is assigned by the EventBus when Publish is called. Zero means unpublished.
Seq uint64
// Type of the event
Type EventType
// Timestamp when the event occurred
Timestamp time.Time
// Session affected by the event (may be nil for delete events)
Session *session.Instance
// SessionID for delete events when Session is nil
SessionID string
// UpdatedFields tracks which fields were modified (for update events)
UpdatedFields []string
// OldStatus for status change events
OldStatus session.Status
// NewStatus for status change events
NewStatus session.Status
// DetectedStatus is kept for legacy compatibility; no longer serialized to wire.
DetectedStatus string
// DetectedContext is the human-readable context from the terminal detector
// (e.g. "Waiting for tool approval"). Empty when DetectedStatus is empty.
DetectedContext string
// DetectedStatusTyped is the typed DetectedStatus for SessionUpdatedEvent.
// Zero value (detection.StatusUnknown) means no detection data is available.
DetectedStatusTyped detection.DetectedStatus
// InteractionType for user interaction events
InteractionType string
// Approved for approval response events (true = approved, false = denied)
Approved bool
// Context provides additional context about the event
Context string
// Notification fields for notification events
NotificationID string
NotificationType int32 // Maps to sessionv1.NotificationType
NotificationPriority int32 // Maps to sessionv1.NotificationPriority
NotificationTitle string
NotificationMessage string
NotificationMetadata map[string]string
}
Event represents a session state change event. This is the internal Go representation that will be converted to protobuf events.
func NewApprovalResponseEvent ¶
NewApprovalResponseEvent creates an event for approval responses.
func NewNotificationEvent ¶
func NewNotificationEvent( sessionID string, sessionName string, notificationID string, notificationType int32, priority int32, title string, message string, metadata map[string]string, ) *Event
NewNotificationEvent creates an event for session notifications.
func NewSessionAcknowledgedEvent ¶
NewSessionAcknowledgedEvent creates an event for session acknowledgments.
func NewSessionCreatedEvent ¶
NewSessionCreatedEvent creates an event for session creation.
func NewSessionDeletedEvent ¶
NewSessionDeletedEvent creates an event for session deletion.
func NewSessionUpdatedEvent ¶
NewSessionUpdatedEvent creates an event for session updates.
func NewSessionUpdatedEventWithDetection ¶
func NewSessionUpdatedEventWithDetection( sess *session.Instance, updatedFields []string, detectedStatus detection.DetectedStatus, detectedContext string, ) *Event
NewSessionUpdatedEventWithDetection creates a session update event that includes typed detected-status information from the terminal detection layer. Use this instead of NewSessionUpdatedEvent when the detection state is known and should be propagated to frontend clients (e.g. the UpdateSession RPC path).
func NewUserInteractionEvent ¶
NewUserInteractionEvent creates an event for user interactions.
type EventBus ¶
type EventBus struct {
// contains filtered or unexported fields
}
EventBus provides a thread-safe pub/sub event bus for session events. It uses Go channels for event distribution and supports multiple concurrent subscribers.
func NewEventBus ¶
NewEventBus creates a new event bus with the specified buffer size. Buffer size determines how many events can be queued per subscriber before dropping.
func (*EventBus) Close ¶
func (eb *EventBus) Close()
Close unsubscribes all subscribers and closes their channels. Should be called during graceful shutdown.
func (*EventBus) EventsSince ¶
EventsSince returns buffered events with Seq > afterSeq in ascending order. Returns nil when afterSeq is 0 (no replay requested) or all buffered events are at or below afterSeq. Events older than one hour are not available.
func (*EventBus) Publish ¶
Publish assigns a sequence number to the event, appends it to the ring buffer, then broadcasts it to all active subscribers. Events are sent asynchronously and non-blocking. If a subscriber's buffer is full, the event is dropped for that subscriber to prevent blocking other subscribers.
func (*EventBus) Subscribe ¶
Subscribe creates a new subscription to the event bus. Returns a read-only channel for receiving events and a subscription ID for cleanup. The subscription is automatically cleaned up when the context is canceled.
func (*EventBus) SubscriberCount ¶
SubscriberCount returns the current number of active subscribers. Useful for monitoring and testing.
func (*EventBus) Unsubscribe ¶
Unsubscribe removes a subscriber and closes their channel. This is idempotent - calling it multiple times with the same ID is safe.
type EventType ¶
type EventType string
EventType represents the type of session event that occurred.
const ( // EventSessionCreated is emitted when a new session is created EventSessionCreated EventType = "session.created" // EventSessionUpdated is emitted when session properties are modified EventSessionUpdated EventType = "session.updated" // EventSessionDeleted is emitted when a session is deleted EventSessionDeleted EventType = "session.deleted" // EventUserInteraction is emitted when user interacts with a session EventUserInteraction EventType = "session.user_interaction" // EventSessionAcknowledged is emitted when user acknowledges a session EventSessionAcknowledged EventType = "session.acknowledged" // EventApprovalResponse is emitted when user responds to an approval prompt EventApprovalResponse EventType = "session.approval_response" // EventNotification is emitted when a session sends a notification EventNotification EventType = "session.notification" )
type Subscriber ¶
Subscriber represents an active event bus subscription. Provides a convenient wrapper around the channel and subscription ID.
func NewSubscriber ¶
func NewSubscriber(id string, events <-chan *Event, cleanup func()) *Subscriber
NewSubscriber creates a Subscriber wrapper. This is primarily for convenience and testing.
func (*Subscriber) Close ¶
func (s *Subscriber) Close()
Close unsubscribes and cleans up the subscriber.