events

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Token lifecycle
	TokenCreated = "token.created"
	TokenUpdated = "token.updated"
	TokenDeleted = "token.deleted"
	TokenExpired = "token.expired"

	// Policy rule matches
	RuleViolation = "rule.violation"
	RuleWarning   = "rule.warning"
	RuleMatch     = "rule.match"
	RuleMask      = "rule.mask"

	// Budget and rate limiting
	BudgetExceeded = "budget.exceeded"
	BudgetUpdate   = "budget.update"
	RateExceeded   = "rate.exceeded"

	// Request lifecycle
	RequestCompleted = "request.completed"

	// OpenClaw integration
	OpenClawAgentRequest  = "openclaw.agent.request"
	OpenClawAgentSuccess  = "openclaw.agent.success"
	OpenClawAgentError    = "openclaw.agent.error"
	OpenClawRuleViolation = "openclaw.rule.violation"

	// System
	ServerStart = "server.start"
)

Event types emitted by Tokenomics.

Variables

This section is empty.

Functions

This section is empty.

Types

type Emitter

type Emitter interface {
	// Emit delivers an event. Implementations should be non-blocking
	// or use their own internal queue to avoid slowing the caller.
	Emit(ctx context.Context, event Event) error

	// Close flushes pending events and releases resources.
	Close() error
}

Emitter is the interface for delivering events to external systems. Implementations include webhooks, message buses, log sinks, etc.

type Event

type Event struct {
	ID        string                 `json:"id"`
	Type      string                 `json:"type"`
	Timestamp string                 `json:"timestamp"`
	Data      map[string]interface{} `json:"data,omitempty"`
}

Event is the payload delivered to emitters.

func New

func New(eventType string, data map[string]interface{}) Event

New creates an Event with a generated ID and current timestamp.

func (Event) JSON

func (e Event) JSON() []byte

JSON returns the event as a JSON byte slice.

type Multi

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

Multi fans out events to multiple emitters.

func NewMulti

func NewMulti(emitters ...Emitter) *Multi

NewMulti creates a fan-out emitter that delivers to all given emitters.

func (*Multi) Close

func (m *Multi) Close() error

Close shuts down all registered emitters.

func (*Multi) Emit

func (m *Multi) Emit(ctx context.Context, event Event) error

Emit delivers the event to all registered emitters. Errors are logged but do not stop delivery to remaining emitters.

type Nop

type Nop struct{}

Nop is a no-op emitter used when no webhooks are configured.

func (Nop) Close

func (Nop) Close() error

func (Nop) Emit

func (Nop) Emit(context.Context, Event) error

type WebhookConfig

type WebhookConfig struct {
	URL        string   `mapstructure:"url" json:"url"`
	Secret     string   `mapstructure:"secret" json:"secret,omitempty"`           // Shared secret sent as X-Webhook-Secret header
	SigningKey string   `mapstructure:"signing_key" json:"signing_key,omitempty"` // HMAC-SHA256 signing key; signature sent as X-Webhook-Signature
	Events     []string `mapstructure:"events" json:"events,omitempty"`           // Event type filter (supports trailing * wildcard); empty = all
	TimeoutSec int      `mapstructure:"timeout" json:"timeout,omitempty"`         // HTTP timeout in seconds (default 10)
	Insecure   bool     `mapstructure:"insecure" json:"insecure,omitempty"`       // Skip TLS certificate verification (for self-signed certs)
}

WebhookConfig configures a single webhook endpoint.

type WebhookEmitter

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

WebhookEmitter delivers events to an HTTP endpoint.

func NewWebhookEmitter

func NewWebhookEmitter(cfg WebhookConfig) *WebhookEmitter

NewWebhookEmitter creates a webhook emitter that sends events asynchronously. Events are buffered in a channel and delivered in a background goroutine.

func (*WebhookEmitter) Close

func (w *WebhookEmitter) Close() error

Close drains the queue and shuts down the worker.

func (*WebhookEmitter) Emit

func (w *WebhookEmitter) Emit(_ context.Context, event Event) error

Emit queues an event for async delivery. Non-blocking; drops if the buffer is full.

Jump to

Keyboard shortcuts

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