webhooks

package
v0.0.0-...-4048c46 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: AGPL-3.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultQueueName = "default"

Variables

This section is empty.

Functions

func BuildPayload

func BuildPayload(r *http.Request, req WebhookPayloadRequest) map[string]any

func DecodeJSONObject

func DecodeJSONObject(raw []byte) (map[string]any, string, error)

func ExistingBodyHash

func ExistingBodyHash(payloadJSON string) string

func ExtractCorrelationID

func ExtractCorrelationID(r *http.Request, body map[string]any) string

func ExtractDeliveryID

func ExtractDeliveryID(r *http.Request) string

func ExtractIdempotencyKey

func ExtractIdempotencyKey(r *http.Request) string

func IntentFromBody

func IntentFromBody(body map[string]any) string

func PresentedToken

func PresentedToken(r *http.Request, tokenHeader ...string) string

func ProviderFromTopic

func ProviderFromTopic(topic string) string

func QueryValuesToMap

func QueryValuesToMap(r *http.Request) map[string]any

func ReadBody

func ReadBody(r *http.Request, limit int64) ([]byte, error)

func RegisterRoutes

func RegisterRoutes(app *echo.Echo, opts RouteOptions)

func RequestContentTypeIsJSON

func RequestContentTypeIsJSON(r *http.Request) bool

func SanitizeHeaders

func SanitizeHeaders(headers http.Header) map[string]string

func TokenHash

func TokenHash(token string) string

func ValidTokenHash

func ValidTokenHash(r *http.Request, hash string, tokenHeader ...string) bool

func ValidateExternalTopic

func ValidateExternalTopic(topic string) error

Types

type AcceptedResponse

type AcceptedResponse struct {
	Accepted      bool   `json:"accepted"`
	Topic         string `json:"topic"`
	EventID       string `json:"event_id"`
	Sequence      int64  `json:"sequence"`
	CorrelationID string `json:"correlation_id"`
}

type EventQueryStore

type EventQueryStore interface {
	ListEventSummaries(context.Context, domain.TopicEventFilter) ([]domain.EventSummary, int, error)
	ListEventTopics(context.Context, string, int, int) ([]domain.EventTopicSummary, int, error)
	GetEventTrace(context.Context, string, int) (domain.EventTrace, error)
}

EventQueryStore provides the lightweight HTTP event-query projections.

type EventRunJSON

type EventRunJSON struct {
	EventID     string `json:"event_id"`
	SchedulerID string `json:"scheduler_id"`
	RunID       string `json:"run_id,omitempty"`
	TriggerID   string `json:"trigger_id"`
	Status      string `json:"status"`
	Error       string `json:"error,omitempty"`
	CreatedAt   string `json:"created_at"`
	UpdatedAt   string `json:"updated_at"`
}

type EventRunTraceJSON

type EventRunTraceJSON struct {
	Delivery  EventRunJSON              `json:"delivery"`
	Scheduler *EventSchedulerJSON       `json:"scheduler,omitempty"`
	Run       *EventSchedulerRunJSON    `json:"run,omitempty"`
	Events    []EventSchedulerEventJSON `json:"events"`
}

type EventRunsResponse

type EventRunsResponse struct {
	EventID       string         `json:"event_id"`
	CorrelationID string         `json:"correlation_id"`
	Runs          []EventRunJSON `json:"runs"`
}

func EventRunsResponseFor

func EventRunsResponseFor(item domain.TopicEventRecord, deliveries []domain.EventDelivery) EventRunsResponse

type EventSandboxJSON

type EventSandboxJSON struct {
	SandboxID        string `json:"sandbox_id"`
	Relation         string `json:"relation"`
	SchedulerID      string `json:"scheduler_id,omitempty"`
	RunID            string `json:"run_id,omitempty"`
	TriggerID        string `json:"trigger_id,omitempty"`
	SchedulerEventID string `json:"scheduler_event_id,omitempty"`
	EventID          string `json:"event_id"`
	CreatedAt        string `json:"created_at"`
}

type EventSandboxSummaryJSON

type EventSandboxSummaryJSON struct {
	SandboxID string `json:"sandbox_id"`
	Title     string `json:"title"`
	Status    string `json:"status"`
	ProjectID string `json:"project_id,omitempty"`
	AgentName string `json:"agent_name,omitempty"`
	CreatedAt string `json:"created_at"`
	UpdatedAt string `json:"updated_at"`
}

type EventSandboxesResponse

type EventSandboxesResponse struct {
	EventID       string             `json:"event_id"`
	CorrelationID string             `json:"correlation_id"`
	Sandboxes     []EventSandboxJSON `json:"sandboxes"`
}

type EventSchedulerEventJSON

type EventSchedulerEventJSON struct {
	EventID         string `json:"event_id"`
	Type            string `json:"type"`
	Level           string `json:"level"`
	Message         string `json:"message"`
	LinkedSandboxID string `json:"linked_sandbox_id,omitempty"`
	CreatedAt       string `json:"created_at"`
}

type EventSchedulerJSON

type EventSchedulerJSON struct {
	SchedulerID string `json:"scheduler_id"`
	ProjectID   string `json:"project_id"`
	AgentName   string `json:"agent_name"`
	Name        string `json:"name"`
}

type EventSchedulerRunJSON

type EventSchedulerRunJSON struct {
	RunID       string `json:"run_id"`
	Status      string `json:"status"`
	StartedAt   string `json:"started_at"`
	CompletedAt string `json:"completed_at,omitempty"`
	DurationMs  int64  `json:"duration_ms"`
	Error       string `json:"error,omitempty"`
}

type EventSummaryJSON

type EventSummaryJSON struct {
	EventID        string `json:"event_id"`
	Sequence       int64  `json:"sequence"`
	Topic          string `json:"topic"`
	Source         string `json:"source"`
	Provider       string `json:"provider,omitempty"`
	Intent         string `json:"intent,omitempty"`
	CorrelationID  string `json:"correlation_id"`
	DeliveryID     string `json:"delivery_id,omitempty"`
	DispatchStatus string `json:"dispatch_status"`
	ParentEventID  string `json:"parent_event_id,omitempty"`
	PublisherType  string `json:"publisher_type,omitempty"`
	PublisherID    string `json:"publisher_id,omitempty"`
	PublisherRunID string `json:"publisher_run_id,omitempty"`
	CreatedAt      string `json:"created_at"`
	DispatchedAt   string `json:"dispatched_at,omitempty"`
}

type EventSummaryListResponse

type EventSummaryListResponse struct {
	Items             []EventSummaryJSON `json:"items"`
	Total             int                `json:"total"`
	NextAfterSequence int64              `json:"next_after_sequence,omitempty"`
}

type EventTopicJSON

type EventTopicJSON struct {
	Topic         string `json:"topic"`
	EventCount    int    `json:"event_count"`
	LatestEventAt string `json:"latest_event_at"`
}

type EventTopicListResponse

type EventTopicListResponse struct {
	Items []EventTopicJSON `json:"items"`
	Total int              `json:"total"`
}

type EventTraceResponse

type EventTraceResponse struct {
	SandboxSummariesIncomplete bool                    `json:"sandbox_summaries_incomplete,omitempty"`
	Event                      EventSummaryJSON        `json:"event"`
	Runs                       []EventRunTraceJSON     `json:"runs"`
	Sandboxes                  []EventTraceSandboxJSON `json:"sandboxes"`
	DescendantsTruncated       bool                    `json:"descendants_truncated"`
}

type EventTraceSandboxJSON

type EventTraceSandboxJSON struct {
	EventSandboxJSON
	Sandbox *EventSandboxSummaryJSON `json:"sandbox,omitempty"`
}

type Reservation

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

func NoopReservations

func NoopReservations(count int) []*Reservation

func (*Reservation) Release

func (r *Reservation) Release()

type RouteOptions

type RouteOptions struct {
	Store              Store
	QueryStore         EventQueryStore
	Sandboxes          SandboxSummaryReader
	WebhookBodyLimit   int64
	NewEventID         func() string
	MarshalJSONCompact func(any) (string, error)
	RunStopper         RunStopper
}

type RunQueue

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

func NewRunQueue

func NewRunQueue(defaultWorkers int) *RunQueue

func NewRunQueueFromConfig

func NewRunQueueFromConfig(config *appconfig.Config) (*RunQueue, error)

func (*RunQueue) Match

func (q *RunQueue) Match(event domain.SchedulerTopicEvent) (string, int)

func (*RunQueue) Reserve

func (q *RunQueue) Reserve(event domain.SchedulerTopicEvent) (*Reservation, bool)

type RunStopper

type RunStopper interface {
	RequestSchedulerRunStop(context.Context, string, string, string) (bool, error)
}

type SandboxSummaryReader

type SandboxSummaryReader interface {
	ListSandboxSummaries(context.Context, []string) (map[string]domain.SandboxSummary, error)
}

SandboxSummaryReader batches optional sandbox enrichment for event traces.

type SourceJSON

type SourceJSON struct {
	ID                 string `json:"id"`
	Name               string `json:"name"`
	Enabled            bool   `json:"enabled"`
	Provider           string `json:"provider"`
	TopicPrefix        string `json:"topic_prefix"`
	HasToken           bool   `json:"has_token"`
	TokenHeader        string `json:"token_header,omitempty"`
	SignatureType      string `json:"signature_type,omitempty"`
	HasSignatureSecret bool   `json:"has_signature_secret"`
	BodyLimitBytes     int64  `json:"body_limit_bytes,omitempty"`
	CreatedAt          string `json:"created_at"`
	UpdatedAt          string `json:"updated_at"`
}

func SourceToJSON

func SourceToJSON(source domain.WebhookSource) SourceJSON

type SourceListResponse

type SourceListResponse struct {
	Items []SourceJSON `json:"items"`
}

type SourceRequest

type SourceRequest struct {
	Name            string  `json:"name"`
	Enabled         *bool   `json:"enabled,omitempty"`
	Provider        string  `json:"provider"`
	TopicPrefix     string  `json:"topic_prefix"`
	Token           string  `json:"token"`
	TokenHash       string  `json:"token_hash"`
	TokenHeader     *string `json:"token_header,omitempty"`
	ClearToken      bool    `json:"clear_token"`
	SignatureType   string  `json:"signature_type"`
	SignatureSecret string  `json:"signature_secret"`
	ClearSignature  bool    `json:"clear_signature"`
	BodyLimitBytes  int64   `json:"body_limit_bytes"`
}

type SourceResponse

type SourceResponse struct {
	Source SourceJSON `json:"source"`
}

type Store

type Store interface {
	FindEventByIdempotencyKey(context.Context, string, string) (domain.TopicEventRecord, bool, error)
	CreateEvent(context.Context, domain.TopicEventRecord) (domain.TopicEventRecord, error)
	GetEvent(context.Context, string) (domain.TopicEventRecord, error)
	ListEvents(context.Context, domain.TopicEventFilter) ([]domain.TopicEventRecord, int, error)
	ListDescendantEventIDs(context.Context, string, int) ([]string, error)
	ListCorrelatedEventIDs(context.Context, string, int) ([]string, error)
	ListEventSandboxLinks(context.Context, []string) ([]domain.EventSandboxTraceItem, error)
	ListEventDeliveries(context.Context, []string) ([]domain.EventDelivery, error)
	CancelEventDispatch(context.Context, []string, string) (domain.EventDispatchCancellation, error)
	ListWebhookSources(context.Context) ([]domain.WebhookSource, error)
	GetWebhookSource(context.Context, string) (domain.WebhookSource, bool, error)
	UpsertWebhookSource(context.Context, domain.WebhookSource) (domain.WebhookSource, error)
	DeleteWebhookSource(context.Context, string) error
	ListEnabledWebhookSourcesForTopic(context.Context, string) ([]domain.WebhookSource, error)
}

type TopicEventJSON

type TopicEventJSON struct {
	EventID        string         `json:"event_id"`
	Sequence       int64          `json:"sequence"`
	Topic          string         `json:"topic"`
	Source         string         `json:"source"`
	Provider       string         `json:"provider,omitempty"`
	Intent         string         `json:"intent,omitempty"`
	CorrelationID  string         `json:"correlation_id"`
	IdempotencyKey string         `json:"idempotency_key,omitempty"`
	DeliveryID     string         `json:"delivery_id,omitempty"`
	DispatchStatus string         `json:"dispatch_status"`
	ParentEventID  string         `json:"parent_event_id,omitempty"`
	PublisherType  string         `json:"publisher_type,omitempty"`
	PublisherID    string         `json:"publisher_id,omitempty"`
	PublisherRunID string         `json:"publisher_run_id,omitempty"`
	CreatedAt      string         `json:"created_at"`
	DispatchedAt   string         `json:"dispatched_at,omitempty"`
	Payload        map[string]any `json:"payload"`
}

func TopicEventToJSON

func TopicEventToJSON(item domain.TopicEventRecord) TopicEventJSON

type TopicEventListResponse

type TopicEventListResponse struct {
	Items             []TopicEventJSON `json:"items"`
	Total             int              `json:"total"`
	NextAfterSequence int64            `json:"next_after_sequence,omitempty"`
}

type TopicEventResponse

type TopicEventResponse struct {
	Event TopicEventJSON `json:"event"`
}

type WebhookPayloadRequest

type WebhookPayloadRequest struct {
	EventID        string
	Sequence       int64
	Topic          string
	CorrelationID  string
	IdempotencyKey string
	Source         domain.WebhookSource
	Body           map[string]any
}

WebhookPayloadRequest describes the event metadata BuildPayload assembles alongside the inbound HTTP request into a delivery payload.

Jump to

Keyboard shortcuts

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