Help us shape the future of Go! Take the 2026 Go Developer Survey

alerts

package
v0.87.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Alert

type Alert struct {
	ID             string         `json:"id"`
	Type           AlertType      `json:"type"`
	Severity       Severity       `json:"severity"`
	ConversationID string         `json:"conversationId,omitempty"`
	CounselorID    string         `json:"counselorId,omitempty"`
	Title          string         `json:"title"`
	Description    string         `json:"description"`
	CreatedAt      time.Time      `json:"createdAt"`
	AcknowledgedAt *time.Time     `json:"acknowledgedAt,omitempty"`
	ResolvedAt     *time.Time     `json:"resolvedAt,omitempty"`
	Metadata       map[string]any `json:"metadata,omitempty"`
}

Alert represents a supervisor alert.

type AlertEngine

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

AlertEngine generates and manages supervisor alerts using a hybrid rule-based + AI approach.

func NewAlertEngine

func NewAlertEngine(provider LLMProvider, cfg Config) *AlertEngine

NewAlertEngine creates a new AlertEngine. If provider is nil, only rule-based detection is used.

func (*AlertEngine) AcknowledgeAlert

func (e *AlertEngine) AcknowledgeAlert(alertID string) error

AcknowledgeAlert marks an alert as acknowledged.

func (*AlertEngine) Evaluate

func (e *AlertEngine) Evaluate(ctx context.Context, evalCtx *EvalContext) []Alert

Evaluate runs all alert rules against the given context and returns any new alerts.

func (*AlertEngine) EvaluateRiskEscalation

func (e *AlertEngine) EvaluateRiskEscalation(ctx context.Context, conversationID string, classification *classifier.Classification) []Alert

EvaluateRiskEscalation checks for risk escalation in a conversation.

func (*AlertEngine) EvaluateSentimentDrop

func (e *AlertEngine) EvaluateSentimentDrop(ctx context.Context, conversationID string, trend *sentiment.Trend) []Alert

EvaluateSentimentDrop checks for sentiment drops in a conversation.

func (*AlertEngine) EvaluateWaitTime

func (e *AlertEngine) EvaluateWaitTime(ctx context.Context, conversationID string, waitTime time.Duration) []Alert

EvaluateWaitTime checks conversation wait times.

func (*AlertEngine) EvaluateWorkload

func (e *AlertEngine) EvaluateWorkload(ctx context.Context, workloads []CounselorWorkload) []Alert

EvaluateWorkload checks workload distribution across counselors.

func (*AlertEngine) GetAlerts

func (e *AlertEngine) GetAlerts(filter AlertFilter) []Alert

GetAlerts returns alerts matching the given filter.

func (*AlertEngine) ResolveAlert

func (e *AlertEngine) ResolveAlert(alertID string) error

ResolveAlert marks an alert as resolved.

type AlertFilter

type AlertFilter struct {
	Type           *AlertType `json:"type,omitempty"`
	Severity       *Severity  `json:"severity,omitempty"`
	ConversationID string     `json:"conversationId,omitempty"`
	Unresolved     bool       `json:"unresolved,omitempty"`
	Since          *time.Time `json:"since,omitempty"`
	Limit          int        `json:"limit,omitempty"`
}

AlertFilter defines criteria for filtering alerts.

type AlertRule

type AlertRule struct {
	Type     AlertType
	Evaluate func(ctx *EvalContext) *Alert
}

AlertRule defines a rule for generating alerts.

type AlertType

type AlertType string

AlertType represents the type of supervisor alert.

const (
	AlertRiskEscalation    AlertType = "risk_escalation"
	AlertWorkloadImbalance AlertType = "workload_imbalance"
	AlertSentimentDrop     AlertType = "sentiment_drop"
	AlertLongWaitTime      AlertType = "long_wait_time"
)

type Config

type Config struct {
	MaxAlerts                int
	MaxConversationsPerAgent int
	MaxWaitTime              time.Duration
	OnAlert                  func(Alert)
}

Config holds configuration for the AlertEngine.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns default alert engine configuration.

type CounselorWorkload

type CounselorWorkload struct {
	CounselorID         string        `json:"counselorId"`
	ActiveConversations int           `json:"activeConversations"`
	AverageWaitTime     time.Duration `json:"averageWaitTime"`
}

CounselorWorkload represents a counselor's current workload.

type EvalContext

type EvalContext struct {
	ConversationID string
	CounselorID    string
	Classification *classifier.Classification
	Sentiment      *sentiment.Trend
	Workloads      []CounselorWorkload
	WaitTime       time.Duration
	Timestamp      time.Time
}

EvalContext provides data to alert rules during evaluation.

type Handler

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

Handler provides HTTP handlers for the alerts API.

func NewHandler

func NewHandler(engine *AlertEngine) *Handler

NewHandler creates a new alerts API handler.

func (*Handler) HandleAcknowledge

func (h *Handler) HandleAcknowledge(w http.ResponseWriter, r *http.Request)

HandleAcknowledge handles POST /api/alerts/{id}/acknowledge.

func (*Handler) HandleGetAlerts

func (h *Handler) HandleGetAlerts(w http.ResponseWriter, r *http.Request)

HandleGetAlerts handles GET /api/alerts. Supports query parameters: type, severity, conversationId, unresolved, since, limit.

func (*Handler) HandleResolve

func (h *Handler) HandleResolve(w http.ResponseWriter, r *http.Request)

HandleResolve handles POST /api/alerts/{id}/resolve.

func (*Handler) RegisterRoutes

func (h *Handler) RegisterRoutes(mux *http.ServeMux)

RegisterRoutes registers the alerts API routes on a ServeMux.

type LLMProvider

type LLMProvider interface {
	EvaluateRisk(ctx context.Context, systemPrompt, userPrompt string) (*Alert, error)
}

LLMProvider abstracts the AI backend for enhanced alert detection.

type Severity

type Severity string

Severity represents the urgency of an alert.

const (
	SeverityCritical Severity = "critical"
	SeverityHigh     Severity = "high"
	SeverityMedium   Severity = "medium"
	SeverityLow      Severity = "low"
)

Jump to

Keyboard shortcuts

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