dispatch

package
v2.37.0 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2026 License: AGPL-3.0 Imports: 20 Imported by: 0

Documentation

Overview

Package dispatch delivers chat lifecycle events to an external webhook.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CapacityClass

type CapacityClass int

CapacityClass selects which share of dispatch capacity an event draws from.

const (
	CapacityClassUnset CapacityClass = iota
	CapacityClassAdmission
	CapacityClassGeneration
)

type Dispatcher

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

Dispatcher delivers lifecycle hook attempts. It keeps no delivery or decision state, so delivery is best-effort and consumers own both.

func New

func New(
	logger slog.Logger,
	client *http.Client,
	hookURL string,
	allowInsecureURL bool,
	secret string,
	timeout time.Duration,
	deploymentID string,
	coderVersion string,
	reg prometheus.Registerer,
) *Dispatcher

New copies (or creates) the HTTP client and disables redirects for signed requests.

func (*Dispatcher) Dispatch

func (d *Dispatcher) Dispatch(ctx context.Context, event Event) (agenthooks.Response, uuid.UUID, error)

Dispatch delivers one event. The returned ID correlates the attempt in logs and Error values; the dispatcher does not persist delivery state.

func (*Dispatcher) Enabled

func (d *Dispatcher) Enabled() bool

Enabled reports whether a hook URL is configured. A nil dispatcher reads as disabled so callers can hold one unconditionally.

type Error

type Error struct {
	Class      Result
	DispatchID uuid.UUID
	Err        error
}

Error preserves the attempt ID and failure class.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

type Event

type Event struct {
	Type agenthooks.EventType
	agenthooks.ChatRef
	Data     any
	Capacity CapacityClass
}

Event carries the identities delivered with each dispatch attempt.

type Result

type Result string

Result classifies the terminal outcome of a dispatch attempt.

const (
	ResultOK              Result = "ok"
	ResultDenied          Result = "denied"
	ResultHTTPError       Result = "http_error"
	ResultProtocolError   Result = "protocol_error"
	ResultTimeout         Result = "timeout"
	ResultConnectionError Result = "connection_error"
	ResultOverCapacity    Result = "over_capacity"
	ResultInternalError   Result = "internal_error"
)

Jump to

Keyboard shortcuts

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