events

package
v1.38.0 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2026 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

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

func NewApprovalResponseEvent(sessionID string, approved bool, context string) *Event

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

func NewSessionAcknowledgedEvent(sessionID, reason string) *Event

NewSessionAcknowledgedEvent creates an event for session acknowledgments.

func NewSessionCreatedEvent

func NewSessionCreatedEvent(sess *session.Instance) *Event

NewSessionCreatedEvent creates an event for session creation.

func NewSessionDeletedEvent

func NewSessionDeletedEvent(sessionID string) *Event

NewSessionDeletedEvent creates an event for session deletion.

func NewSessionUpdatedEvent

func NewSessionUpdatedEvent(sess *session.Instance, updatedFields []string) *Event

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

func NewUserInteractionEvent(sessionID, interactionType, context string) *Event

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

func NewEventBus(bufferSize int) *EventBus

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

func (eb *EventBus) EventsSince(afterSeq uint64) []*Event

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

func (eb *EventBus) Publish(event *Event)

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

func (eb *EventBus) Subscribe(ctx context.Context) (<-chan *Event, string)

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

func (eb *EventBus) SubscriberCount() int

SubscriberCount returns the current number of active subscribers. Useful for monitoring and testing.

func (*EventBus) Unsubscribe

func (eb *EventBus) Unsubscribe(id string)

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

type Subscriber struct {
	ID     string
	Events <-chan *Event
	// contains filtered or unexported fields
}

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.

Jump to

Keyboard shortcuts

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