relay_hook

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package relay_hook bridges Nexus lifecycle events to webhook notifications. When registered as an extension, it captures lifecycle events and forwards them as typed events to a configurable webhook endpoint.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

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

Event is a relay webhook event payload.

type EventType

type EventType string

EventType identifies the kind of lifecycle event.

const (
	// Request events
	EventRequestReceived  EventType = "request.received"
	EventRequestCompleted EventType = "request.completed"
	EventRequestFailed    EventType = "request.failed"
	EventRequestCached    EventType = "request.cached"

	// Provider events
	EventProviderFailed    EventType = "provider.failed"
	EventCircuitOpened     EventType = "circuit.opened"
	EventFallbackTriggered EventType = "fallback.triggered"

	// Guardrail events
	EventGuardrailBlocked  EventType = "guardrail.blocked"
	EventGuardrailRedacted EventType = "guardrail.redacted"

	// Tenant events
	EventTenantCreated  EventType = "tenant.created"
	EventTenantDisabled EventType = "tenant.disabled"

	// Key events
	EventKeyCreated EventType = "key.created"
	EventKeyRevoked EventType = "key.revoked"

	// Budget events
	EventBudgetWarning  EventType = "budget.warning"
	EventBudgetExceeded EventType = "budget.exceeded"

	// Stream events
	EventStreamStarted   EventType = "stream.started"
	EventStreamCompleted EventType = "stream.completed"
	EventStreamFailed    EventType = "stream.failed"
)

type Extension

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

Extension is the relay webhook extension.

func New

func New(sender Sender, opts ...Option) *Extension

New creates a new relay hook extension with the given sender.

func NewWebhook

func NewWebhook(url string, opts ...Option) *Extension

NewWebhook creates a relay extension that POSTs events to a URL.

func (*Extension) Name

func (e *Extension) Name() string

func (*Extension) OnBudgetExceeded

func (e *Extension) OnBudgetExceeded(ctx context.Context, tenantID id.TenantID) error

func (*Extension) OnBudgetWarning

func (e *Extension) OnBudgetWarning(ctx context.Context, tenantID id.TenantID, usedPct float64) error

func (*Extension) OnCircuitOpened

func (e *Extension) OnCircuitOpened(ctx context.Context, providerName string) error

func (*Extension) OnFallbackTriggered

func (e *Extension) OnFallbackTriggered(ctx context.Context, from, to string) error

func (*Extension) OnGuardrailBlocked

func (e *Extension) OnGuardrailBlocked(ctx context.Context, guardName string, requestID id.RequestID) error

func (*Extension) OnKeyCreated

func (e *Extension) OnKeyCreated(ctx context.Context, keyID id.KeyID, tenantID id.TenantID) error

func (*Extension) OnKeyRevoked

func (e *Extension) OnKeyRevoked(ctx context.Context, keyID id.KeyID) error

func (*Extension) OnProviderFailed

func (e *Extension) OnProviderFailed(ctx context.Context, providerName, model string, err error) error

func (*Extension) OnRequestCached

func (e *Extension) OnRequestCached(ctx context.Context, requestID id.RequestID, model string) error

func (*Extension) OnRequestCompleted

func (e *Extension) OnRequestCompleted(ctx context.Context, requestID id.RequestID, model, providerName string, elapsed time.Duration, inputTokens, outputTokens int) error

func (*Extension) OnRequestFailed

func (e *Extension) OnRequestFailed(ctx context.Context, requestID id.RequestID, model string, err error) error

func (*Extension) OnRequestReceived

func (e *Extension) OnRequestReceived(ctx context.Context, requestID id.RequestID, model, tenantID string) error

func (*Extension) OnStreamCompleted

func (e *Extension) OnStreamCompleted(ctx context.Context, requestID id.RequestID, model, providerName string, elapsed time.Duration, final *provider.CompletionResponse) error

func (*Extension) OnStreamFailed

func (e *Extension) OnStreamFailed(ctx context.Context, requestID id.RequestID, model string, err error) error

func (*Extension) OnStreamStarted

func (e *Extension) OnStreamStarted(ctx context.Context, requestID id.RequestID, model, providerName string) error

func (*Extension) OnTenantCreated

func (e *Extension) OnTenantCreated(ctx context.Context, tenantID id.TenantID) error

func (*Extension) OnTenantDisabled

func (e *Extension) OnTenantDisabled(ctx context.Context, tenantID id.TenantID) error

type Option

type Option func(*Extension)

Option configures the relay extension.

func WithLogger

func WithLogger(l log.Logger) Option

WithLogger sets a custom logger.

type Sender

type Sender interface {
	Send(ctx context.Context, event *Event) error
}

Sender delivers relay events to a destination.

type SenderFunc

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

SenderFunc adapts a function to the Sender interface.

func (SenderFunc) Send

func (f SenderFunc) Send(ctx context.Context, event *Event) error

Jump to

Keyboard shortcuts

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