Documentation
¶
Overview ¶
Package webhook sends a workspace's events to its HTTP endpoints: a task waiting on someone, an answer, a run that finished or failed, an agent going online or offline.
Events come from the activity log, so nothing is missed while a receiver is down and several replicas don't send twice: a cursor (locked while it moves) turns new log entries into delivery rows, and senders claim due rows with SKIP LOCKED. Each request is signed (see Sign and Verify) and retried with backoff.
Index ¶
Constants ¶
const ( TaskWaiting = "task.waiting" TaskAnswered = "task.answered" RunCompleted = "run.completed" RunFailed = "run.failed" AddressOnline = "address.online" AddressOffline = "address.offline" // Ping is sent by "Send test"; endpoints always get it. Ping = "ping" )
Event types.
const ( SignatureHeader = "Lagrange-Signature" EventHeader = "Lagrange-Event" DeliveryHeader = "Lagrange-Delivery" )
Headers on every delivery.
Variables ¶
var ErrBadSignature = errors.New("webhook: bad signature")
ErrBadSignature means a delivery's signature doesn't match, or is too old.
var Types = []string{TaskWaiting, TaskAnswered, RunCompleted, RunFailed, AddressOnline, AddressOffline}
Types lists the event types an endpoint can subscribe to.
Functions ¶
func NewClient ¶
NewClient returns the client deliveries use. Unless allowPrivate, it refuses to connect to loopback, private, link-local and unspecified addresses, checked on the resolved IP of every connection (so DNS tricks and redirects can't reach internal services), as the A2A spec asks of push notifications (13.2).
func Sign ¶
Sign returns the Lagrange-Signature header for body at time t: "t=<unix seconds>,v1=<hex HMAC-SHA256 of "<t>.<body>" with secret>".
Types ¶
type Dispatcher ¶
type Dispatcher struct {
DB *pg.DB
Activity *activity.Log
// Handles returns the addresses of a workspace: its events are those from or to them.
Handles func(ctx context.Context, workspaceID int64) ([]string, error)
// PublicURL makes links back to the web app.
PublicURL string
// Client sends the requests; nil means an SSRF-guarded client (see NewClient).
Client *http.Client
// RetryBase is the first retry delay (default 10s); each next one is three times
// longer, up to six hours.
RetryBase time.Duration
// MaxAttempts is how often a delivery is tried before it fails (default 8).
MaxAttempts int
Logger *slog.Logger
}
Dispatcher fans activity out to webhooks and sends the deliveries.
func (*Dispatcher) Fanout ¶
func (d *Dispatcher) Fanout(ctx context.Context) error
Fanout turns new activity entries into deliveries for the webhooks that want them. Only one replica moves the cursor at a time; the others skip.