events

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package events provides an event bus implementation for internal application events. It supports publishing events and subscribing to specific event types.

Package events provides an event bus implementation for internal application events. It defines event types and structures for communication between components.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bus

type Bus interface {
	Publish(event Event)
	Subscribe(eventType EventType, handler HandlerFunc)
}

Bus provides a simple publish/subscribe mechanism for internal events.

func NewBus

func NewBus() Bus

NewBus creates a new simple event bus.

type Event

type Event interface {
	Type() EventType
	Timestamp() time.Time
}

Event is the interface that all event types must implement.

type EventType

type EventType string

EventType identifies the type of an event.

const (
	// ServerAdded is the event type for when a new server is added
	ServerAdded EventType = "server.added"
	// ServerRemoved is the event type for when a server is removed
	ServerRemoved EventType = "server.removed"
	// ToolsUpdated indicates tools for a specific server were updated
	ToolsUpdated EventType = "tools.updated"
	// ServerStatusChanged indicates the connection status of a server has changed
	ServerStatusChanged EventType = "server.status.changed"
	// ToolsProcessedInDB indicates that the backend service has finished processing tools from an update event.
	ToolsProcessedInDB EventType = "tools.processed.db"
	// LocalToolsRefreshed indicates the agent's own exposed toolset was potentially updated.
	LocalToolsRefreshed EventType = "local.tools.refreshed"
	// ServerDataUpdated signals that backend data relevant to the UI has changed.
	ServerDataUpdated EventType = "server.data.updated"
)

type HandlerFunc

type HandlerFunc func(event Event)

HandlerFunc defines the function signature for event handlers.

type LocalToolsRefreshedEvent

type LocalToolsRefreshedEvent struct {
	// contains filtered or unexported fields
}

LocalToolsRefreshedEvent is published by the ConnectionManager after refreshMCPServerTools completes. It signals that the list of tools exposed by this agent's MCP server may have changed.

func NewLocalToolsRefreshedEvent

func NewLocalToolsRefreshedEvent() *LocalToolsRefreshedEvent

NewLocalToolsRefreshedEvent creates a new LocalToolsRefreshedEvent.

func (LocalToolsRefreshedEvent) Timestamp

func (e LocalToolsRefreshedEvent) Timestamp() time.Time

func (LocalToolsRefreshedEvent) Type

func (e LocalToolsRefreshedEvent) Type() EventType

type ServerAddedEvent

type ServerAddedEvent struct {
	Server models.MCPServer
	// contains filtered or unexported fields
}

ServerAddedEvent is published when a new MCP server is added.

func NewServerAddedEvent

func NewServerAddedEvent(server models.MCPServer) *ServerAddedEvent

NewServerAddedEvent creates a new event for when a server is added

func (ServerAddedEvent) Timestamp

func (e ServerAddedEvent) Timestamp() time.Time

func (ServerAddedEvent) Type

func (e ServerAddedEvent) Type() EventType

type ServerDataUpdatedEvent

type ServerDataUpdatedEvent struct {
	// contains filtered or unexported fields
}

ServerDataUpdatedEvent is published by the BackendService after any operation that changes data relevant to the UI (add, remove, status update, etc.).

func NewServerDataUpdatedEvent

func NewServerDataUpdatedEvent() *ServerDataUpdatedEvent

NewServerDataUpdatedEvent creates a new ServerDataUpdatedEvent.

func (ServerDataUpdatedEvent) Timestamp

func (e ServerDataUpdatedEvent) Timestamp() time.Time

func (ServerDataUpdatedEvent) Type

func (e ServerDataUpdatedEvent) Type() EventType

type ServerRemovedEvent

type ServerRemovedEvent struct {
	ServerID  int64
	ServerURL string // Include URL for potential listeners that don't have the ID cached
	// contains filtered or unexported fields
}

ServerRemovedEvent is published when an MCP server is removed.

func NewServerRemovedEvent

func NewServerRemovedEvent(serverID int64, serverURL string) *ServerRemovedEvent

NewServerRemovedEvent creates a new event for when a server is removed

func (ServerRemovedEvent) Timestamp

func (e ServerRemovedEvent) Timestamp() time.Time

func (ServerRemovedEvent) Type

func (e ServerRemovedEvent) Type() EventType

type ServerStatusChangedEvent

type ServerStatusChangedEvent struct {
	ServerID  int64
	ServerURL string
	NewState  models.ConnectionState
	LastError *string
	// contains filtered or unexported fields
}

ServerStatusChangedEvent is published when an MCP server's connection status changes. This is typically triggered by the ConnectionManager detecting a change and updating the backend.

func NewServerStatusChangedEvent

func NewServerStatusChangedEvent(serverID int64, serverURL string, newState models.ConnectionState, lastError *string) *ServerStatusChangedEvent

NewServerStatusChangedEvent creates a new event for server status changes.

func (ServerStatusChangedEvent) Timestamp

func (e ServerStatusChangedEvent) Timestamp() time.Time

func (ServerStatusChangedEvent) Type

func (e ServerStatusChangedEvent) Type() EventType

type ToolsProcessedInDBEvent

type ToolsProcessedInDBEvent struct {
	ServerID  int64
	ServerURL string // Include URL as ID might not be known to all potential future listeners
	// contains filtered or unexported fields
}

ToolsProcessedInDBEvent is published by the BackendService after it finishes processing tools from a ToolsUpdatedEvent. This signals the ConnectionManager that it's safe to update the internal MCP server's tool list.

func NewToolsProcessedInDBEvent

func NewToolsProcessedInDBEvent(serverID int64, serverURL string) *ToolsProcessedInDBEvent

NewToolsProcessedInDBEvent creates a new ToolsProcessedInDBEvent.

func (ToolsProcessedInDBEvent) Timestamp

func (e ToolsProcessedInDBEvent) Timestamp() time.Time

func (ToolsProcessedInDBEvent) Type

func (e ToolsProcessedInDBEvent) Type() EventType

type ToolsUpdatedEvent

type ToolsUpdatedEvent struct {
	ServerID     int64
	ServerURL    string
	FetchedCount int
	Tools        []models.Tool
	// contains filtered or unexported fields
}

ToolsUpdatedEvent is published when the updater successfully fetches and processes tools for a server.

func NewToolsUpdatedEvent

func NewToolsUpdatedEvent(serverID int64, serverURL string, tools []models.Tool) *ToolsUpdatedEvent

NewToolsUpdatedEvent creates a new event for when tools are updated for a server

func (ToolsUpdatedEvent) Timestamp

func (e ToolsUpdatedEvent) Timestamp() time.Time

func (ToolsUpdatedEvent) Type

func (e ToolsUpdatedEvent) Type() EventType

Jump to

Keyboard shortcuts

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