webhook

package
v0.1.14 Latest Latest
Warning

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

Go to latest
Published: May 1, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package webhook dispatches attention_raised events to a user-configured HTTP endpoint. Retries with exponential backoff and debounces duplicate (session, alert) pairs within a configurable window to prevent flapping.

Index

Constants

This section is empty.

Variables

View Source
var ErrDisabled = errors.New("webhook dispatcher disabled")

ErrDisabled is kept for potential future callers that want to check whether a dispatcher was disabled. Currently Run just returns nil.

Functions

This section is empty.

Types

type Config

type Config struct {
	URL         string
	AuthHeader  string
	UIBaseURL   string
	Timeout     time.Duration
	DebounceFor time.Duration
	// RetryDelays lets tests inject short delays. Nil → {1s, 2s, 4s}.
	RetryDelays []time.Duration
}

Config configures the dispatcher. Zero-value fields fall back to sensible defaults; an empty URL disables dispatch entirely.

type Dispatcher

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

Dispatcher subscribes to the hub and dispatches attention_raised events via HTTP POST, retrying on failure and debouncing duplicates.

func NewDispatcher

func NewDispatcher(hub *events.Hub, resolver SessionResolver, cfg Config, httpClient *http.Client) *Dispatcher

NewDispatcher constructs a Dispatcher. httpClient may be nil; a client with the configured per-attempt Timeout is built on demand.

func (*Dispatcher) Run

func (d *Dispatcher) Run(ctx context.Context) error

Run subscribes to the hub's global stream, dispatching attention_raised events until ctx is done. When cfg.URL is empty, it logs and returns immediately. Active POST goroutines honour ctx cancellation; Run waits for them before returning.

type Payload

type Payload struct {
	Alert       string    `json:"alert"`
	Session     string    `json:"session"`
	SessionUUID string    `json:"session_uuid,omitempty"`
	Workdir     string    `json:"workdir,omitempty"`
	Mode        string    `json:"mode,omitempty"`
	Details     string    `json:"details,omitempty"`
	TS          time.Time `json:"ts"`
	UIURL       string    `json:"ui_url,omitempty"`
}

Payload matches spec §6 exactly. Time is serialized as RFC 3339.

type SessionResolver

type SessionResolver interface {
	Resolve(name string) (uuid string, workdir string, mode string, ok bool)
}

SessionResolver returns metadata for a session name. Zero values are acceptable when unknown — the dispatcher emits whatever is provided.

Jump to

Keyboard shortcuts

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