presets

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: May 27, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BuiltInDefaultVersion = "1"

	BuiltInTaskTerminal     = "task_terminal"
	BuiltInSessionUnhealthy = "session_unhealthy"
	BuiltInProviderFailure  = "provider_failure"
	BuiltInTaskRunPattern   = "task.run_*"

	CursorConsumerPrefix = "preset:"
)

Variables

View Source
var (
	ErrPresetNotFound      = errors.New("notifications: preset not found")
	ErrInvalidPreset       = errors.New("notifications: invalid preset")
	ErrPresetBuiltIn       = errors.New("notifications: built-in preset cannot be deleted")
	ErrPresetDuplicateName = errors.New("notifications: preset name already exists")
)

Functions

func MatchesAny

func MatchesAny(patterns []string, eventType string) bool

func MatchesEvent

func MatchesEvent(pattern string, eventType string) bool

func MutableHash

func MutableHash(p Preset) string

func NewTaskEventObserver

func NewTaskEventObserver(service *Service, tasks TaskReader, logger *slog.Logger) taskpkg.EventObserver

func ValidateEventPattern

func ValidateEventPattern(pattern string) error

Types

type BridgeRuntime

type BridgeRuntime interface {
	GetBridgeInstance(ctx context.Context, id string) (bridgepkg.BridgeInstance, error)
	ResolveBridgeTarget(
		ctx context.Context,
		bridgeID string,
		query string,
	) (bridgepkg.ResolveBridgeTargetResult, error)
	DeliverBridge(
		ctx context.Context,
		extensionName string,
		req bridgepkg.DeliveryRequest,
	) (bridgepkg.DeliveryAck, error)
}

BridgeRuntime is the bridge surface needed for preset fanout.

type Config

type Config struct {
	Store   Store
	Cursors notifications.CursorStore
	Bridges BridgeRuntime
	Events  store.EventSummaryStore
	Logger  *slog.Logger
	Now     func() time.Time
	Timeout time.Duration
}

Config wires a preset service.

type CreateRequest

type CreateRequest struct {
	Name    string   `json:"name"`
	Events  []string `json:"events"`
	Targets []Target `json:"targets,omitempty"`
	Filter  string   `json:"filter,omitempty"`
	Enabled bool     `json:"enabled,omitempty"`
}

CreateRequest captures one operator-created preset.

func (CreateRequest) Normalize

func (r CreateRequest) Normalize(now time.Time) (Preset, error)

type DispatchResult

type DispatchResult struct {
	Matched    int `json:"matched"`
	Delivered  int `json:"delivered"`
	Suppressed int `json:"suppressed"`
	Skipped    int `json:"skipped"`
	Failed     int `json:"failed"`
}

DispatchResult summarizes one event dispatch pass.

type Event

type Event struct {
	ID          string            `json:"id"`
	Type        string            `json:"type"`
	WorkspaceID string            `json:"workspace_id,omitempty"`
	AgentName   string            `json:"agent,omitempty"`
	Provider    string            `json:"provider,omitempty"`
	TaskID      string            `json:"task_id,omitempty"`
	RunID       string            `json:"run_id,omitempty"`
	Summary     string            `json:"summary,omitempty"`
	Outcome     eventspkg.Outcome `json:"outcome"`
	Sequence    int64             `json:"sequence"`
	Payload     json.RawMessage   `json:"payload,omitempty"`
	Timestamp   time.Time         `json:"timestamp"`
}

Event is the normalized runtime event shape consumed by preset dispatch.

func (Event) Normalize

func (e Event) Normalize(now time.Time) Event

func (Event) Validate

func (e Event) Validate() error

type Filter

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

func CompileFilter

func CompileFilter(expr string) (*Filter, error)

func (*Filter) Eval

func (f *Filter) Eval(event Event) bool

type Preset

type Preset struct {
	Name                   string    `json:"name"`
	Events                 []string  `json:"events"`
	Targets                []Target  `json:"targets"`
	Filter                 string    `json:"filter,omitempty"`
	Enabled                bool      `json:"enabled"`
	BuiltIn                bool      `json:"built_in"`
	DefaultVersion         string    `json:"default_version,omitempty"`
	DefaultHash            string    `json:"default_hash,omitempty"`
	UserModified           bool      `json:"user_modified"`
	DefaultUpdateAvailable bool      `json:"default_update_available"`
	CreatedAt              time.Time `json:"created_at"`
	UpdatedAt              time.Time `json:"updated_at"`
}

Preset is the SQLite-authoritative notification fanout policy.

func ApplyDefaultDrift

func ApplyDefaultDrift(p Preset) Preset

func BuiltInPresets

func BuiltInPresets(now time.Time) []Preset

func (Preset) Normalize

func (p Preset) Normalize() Preset

func (Preset) Validate

func (p Preset) Validate() error

type Query

type Query struct {
	Enabled *bool  `json:"enabled,omitempty"`
	BuiltIn *bool  `json:"built_in,omitempty"`
	Name    string `json:"name,omitempty"`
	Limit   int    `json:"limit,omitempty"`
}

Query filters preset list operations.

func (Query) Normalize

func (q Query) Normalize() Query

type Service

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

Service owns preset CRUD and cursor-backed fanout.

func NewService

func NewService(cfg Config) *Service

func (*Service) Create

func (s *Service) Create(ctx context.Context, req CreateRequest) (Preset, error)

func (*Service) Delete

func (s *Service) Delete(ctx context.Context, name string) error

func (*Service) Dispatch

func (s *Service) Dispatch(ctx context.Context, event Event) (DispatchResult, error)

func (*Service) EnsureBuiltIns

func (s *Service) EnsureBuiltIns(ctx context.Context) error

func (*Service) Get

func (s *Service) Get(ctx context.Context, name string) (Preset, error)

func (*Service) List

func (s *Service) List(ctx context.Context, query Query) ([]Preset, error)

func (*Service) Update

func (s *Service) Update(ctx context.Context, name string, req UpdateRequest) (Preset, error)

type Store

type Store interface {
	ListPresets(ctx context.Context, query Query) ([]Preset, error)
	GetPreset(ctx context.Context, name string) (Preset, error)
	CreatePreset(ctx context.Context, preset Preset) (Preset, error)
	UpdatePreset(ctx context.Context, name string, req UpdateRequest) (Preset, error)
	DeletePreset(ctx context.Context, name string) error
	EnsureBuiltInPresets(ctx context.Context, defaults []Preset) error
}

Store persists notification presets.

type Target

type Target struct {
	BridgeID       string                 `json:"bridge_id"`
	CanonicalRoute string                 `json:"canonical_route,omitempty"`
	DisplayName    string                 `json:"display_name,omitempty"`
	DeliveryMode   bridgepkg.DeliveryMode `json:"delivery_mode,omitempty"`
}

Target is one bridge destination attached to a notification preset.

func (Target) Normalize

func (t Target) Normalize() Target

func (Target) StableHash

func (t Target) StableHash() string

func (Target) Validate

func (t Target) Validate() error

type TaskReader

type TaskReader interface {
	GetTask(ctx context.Context, id string) (taskpkg.Task, error)
}

TaskReader loads task context needed to enrich task-event notifications.

type UpdateRequest

type UpdateRequest struct {
	Events  *[]string `json:"events,omitempty"`
	Targets *[]Target `json:"targets,omitempty"`
	Filter  *string   `json:"filter,omitempty"`
	Enabled *bool     `json:"enabled,omitempty"`
	Now     time.Time `json:"-"`
}

UpdateRequest captures mutable preset fields.

func (UpdateRequest) HasMutableField

func (r UpdateRequest) HasMutableField() bool

Jump to

Keyboard shortcuts

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