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 NewSessionStatusChangedEvent(sess *session.Instance, oldStatus, newStatus session.Status) *Event
- func NewSessionUpdatedEvent(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 {
// 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
// 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 NewSessionStatusChangedEvent ¶
func NewSessionStatusChangedEvent(sess *session.Instance, oldStatus, newStatus session.Status) *Event
NewSessionStatusChangedEvent creates an event for status transitions.
func NewSessionUpdatedEvent ¶
NewSessionUpdatedEvent creates an event for session updates.
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) Publish ¶
Publish broadcasts an event 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" // EventSessionStatusChanged is emitted when session status transitions EventSessionStatusChanged EventType = "session.status_changed" // 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.