communication

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrStateNotFound = errors.New("state not found")
	ErrStateExpired  = errors.New("state has expired")
)

Functions

This section is empty.

Types

type Event

type Event struct {
	Type      EventType              `json:"type"`
	PluginID  string                 `json:"plugin_id"`
	Timestamp time.Time              `json:"timestamp"`
	Data      map[string]interface{} `json:"data"`
}

Event represents an event that can be published to the event bus

type EventBus

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

EventBus manages event publishing and subscription

func NewEventBus

func NewEventBus(logger hclog.Logger, bufferSize int) *EventBus

NewEventBus creates a new event bus

func (*EventBus) Close

func (b *EventBus) Close()

Close shuts down the event bus

func (*EventBus) Publish

func (b *EventBus) Publish(ctx context.Context, event *Event) error

Publish publishes an event to all subscribers

func (*EventBus) Subscribe

func (b *EventBus) Subscribe(eventType EventType, handler EventHandler)

Subscribe registers a handler for specific event type

func (*EventBus) SubscribeAll

func (b *EventBus) SubscribeAll(handler EventHandler)

SubscribeAll registers a handler for all event types

type EventHandler

type EventHandler func(ctx context.Context, event *Event) error

EventHandler is a function that handles events

type EventType

type EventType string

EventType represents the type of event

const (
	EventPluginStarted  EventType = "plugin.started"
	EventPluginFinished EventType = "plugin.finished"
	EventPluginFailed   EventType = "plugin.failed"
	EventStateChanged   EventType = "state.changed"
	EventCustom         EventType = "custom"
)

type Manager

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

Manager manages all inter-plugin communication

func NewManager

func NewManager(config *ManagerConfig) (*Manager, error)

NewManager creates a new communication manager

func (*Manager) Close

func (m *Manager) Close()

Close shuts down the communication manager

func (*Manager) EventBus

func (m *Manager) EventBus() *EventBus

EventBus returns the event bus

func (*Manager) PluginRegistry

func (m *Manager) PluginRegistry() *PluginRegistry

PluginRegistry returns the plugin registry

func (*Manager) StateStore

func (m *Manager) StateStore() *StateStore

StateStore returns the state store

type ManagerConfig

type ManagerConfig struct {
	StateDir        string
	EventBufferSize int
	Logger          hclog.Logger
}

ManagerConfig holds configuration for the communication manager

type PluginInfo

type PluginInfo struct {
	ID           string                 `json:"id"`
	Name         string                 `json:"name"`
	Version      string                 `json:"version"`
	Capabilities []string               `json:"capabilities"`
	Metadata     map[string]interface{} `json:"metadata"`
	Status       PluginStatus           `json:"status"`
}

PluginInfo represents information about a registered plugin

type PluginRegistry

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

PluginRegistry manages plugin registration and discovery

func NewPluginRegistry

func NewPluginRegistry(storeDir string, logger hclog.Logger) (*PluginRegistry, error)

NewPluginRegistry creates a new plugin registry

func (*PluginRegistry) FindByCapability

func (r *PluginRegistry) FindByCapability(ctx context.Context, capability string) []*PluginInfo

FindByCapability returns all plugins with a specific capability

func (*PluginRegistry) Get

func (r *PluginRegistry) Get(ctx context.Context, pluginID string) (*PluginInfo, error)

Get retrieves plugin information by ID

func (*PluginRegistry) List

func (r *PluginRegistry) List(ctx context.Context) []*PluginInfo

List returns all registered plugins

func (*PluginRegistry) Register

func (r *PluginRegistry) Register(ctx context.Context, info *PluginInfo) error

Register registers a plugin in the registry

func (*PluginRegistry) Unregister

func (r *PluginRegistry) Unregister(ctx context.Context, pluginID string) error

Unregister removes a plugin from the registry

func (*PluginRegistry) UpdateStatus

func (r *PluginRegistry) UpdateStatus(ctx context.Context, pluginID string, status PluginStatus) error

UpdateStatus updates the status of a plugin

type PluginStatus

type PluginStatus string

PluginStatus represents the status of a plugin

const (
	PluginStatusRegistered PluginStatus = "registered"
	PluginStatusRunning    PluginStatus = "running"
	PluginStatusFinished   PluginStatus = "finished"
	PluginStatusFailed     PluginStatus = "failed"
)

type StateEntry

type StateEntry struct {
	Key         string                 `json:"key"`
	Value       map[string]interface{} `json:"value"`
	PluginID    string                 `json:"plugin_id"`
	CreatedAt   time.Time              `json:"created_at"`
	UpdatedAt   time.Time              `json:"updated_at"`
	ExpiresAt   *time.Time             `json:"expires_at,omitempty"`
	AccessedAt  time.Time              `json:"accessed_at"`
	AccessCount int                    `json:"access_count"`
}

StateEntry represents a shared state entry

type StateStore

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

StateStore manages shared state between plugins

func NewStateStore

func NewStateStore(storeDir string, logger hclog.Logger) (*StateStore, error)

NewStateStore creates a new state store

func (*StateStore) Clean

func (s *StateStore) Clean(ctx context.Context) (int, error)

Clean removes expired state entries

func (*StateStore) Delete

func (s *StateStore) Delete(ctx context.Context, key string) error

Delete removes a state entry

func (*StateStore) Get

func (s *StateStore) Get(ctx context.Context, key string) (*StateEntry, error)

Get retrieves a state entry

func (*StateStore) List

func (s *StateStore) List(ctx context.Context) []*StateEntry

List returns all state entries

func (*StateStore) ListByPlugin

func (s *StateStore) ListByPlugin(ctx context.Context, pluginID string) []*StateEntry

ListByPlugin returns all state entries for a specific plugin

func (*StateStore) Set

func (s *StateStore) Set(ctx context.Context, key string, value map[string]interface{}, pluginID string, ttl *time.Duration) error

Set stores or updates a state entry

Jump to

Keyboard shortcuts

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