plugin

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const SystemUserID = "system"

Variables

This section is empty.

Functions

func ContextWithAuth

func ContextWithAuth(ctx context.Context, auth AuthContext) context.Context

ContextWithAuth stores an AuthContext in ctx.

func ContextWithSystem

func ContextWithSystem(ctx context.Context) context.Context

ContextWithSystem marks ctx as originating from an internal system trigger (cron scheduler, workflow coordinator). The returned context carries a system AuthContext so plugins can identify the caller.

func IsSystemInitiated

func IsSystemInitiated(ctx context.Context) bool

IsSystemInitiated reports whether ctx was created by ContextWithSystem.

Types

type Action

type Action string
const (
	ActionCreate Action = "create"
	ActionStart  Action = "start"
	ActionStop   Action = "stop"
	ActionDelete Action = "delete"
	ActionUpdate Action = "update"
)

type AuthContext

type AuthContext struct {
	UserID string `json:"user_id,omitempty"`
	Token  string `json:"-"`
	Action Action `json:"action"`
}

func AuthFromContext

func AuthFromContext(ctx context.Context) AuthContext

AuthFromContext retrieves the AuthContext stored by ContextWithAuth. Returns a zero-value AuthContext when none is present.

type AuthorizeRequest

type AuthorizeRequest struct {
	Context AuthContext `json:"context"`
	Task    TaskInfo    `json:"task"`
}

type AuthorizeResponse

type AuthorizeResponse struct {
	Allow  bool   `json:"allow"`
	Reason string `json:"reason,omitempty"`
}

type DispatchRequest

type DispatchRequest struct {
	Context AuthContext `json:"context"`
	Task    TaskInfo    `json:"task"`
	Proplet PropletInfo `json:"proplet"`
}

type DispatchResponse

type DispatchResponse struct {
	Allow    bool              `json:"allow"`
	Reason   string            `json:"reason,omitempty"`
	ExtraEnv map[string]string `json:"extra_env,omitempty"`
}

type EnrichRequest

type EnrichRequest struct {
	Context AuthContext `json:"context"`
	Task    TaskInfo    `json:"task"`
}

type EnrichResponse

type EnrichResponse struct {
	Env      map[string]string `json:"env,omitempty"`
	Priority *int              `json:"priority,omitempty"`
	Inputs   []string          `json:"inputs,omitempty"`
	ImageURL string            `json:"image_url,omitempty"`
}

type Plugin

type Plugin interface {
	Name() string
	Authorize(ctx context.Context, req AuthorizeRequest) (AuthorizeResponse, error)
	Enrich(ctx context.Context, req EnrichRequest) (EnrichResponse, error)
	OnBeforePropletSelect(ctx context.Context, req PropletSelectRequest) (PropletSelectResponse, error)
	OnBeforeDispatch(ctx context.Context, req DispatchRequest) (DispatchResponse, error)
	OnTaskStart(ctx context.Context, evt TaskEvent) error
	OnTaskComplete(ctx context.Context, evt TaskEvent) error
	Close(ctx context.Context) error
}

func LoadWasm

func LoadWasm(ctx context.Context, name, path string, logger *slog.Logger) (Plugin, error)

type PropletInfo

type PropletInfo struct {
	ID               string   `json:"id"`
	Name             string   `json:"name"`
	Tags             []string `json:"tags,omitempty"`
	TotalMemoryBytes uint64   `json:"total_memory_bytes,omitempty"`
	Location         string   `json:"location,omitempty"`
}

type PropletSelectRequest

type PropletSelectRequest struct {
	Context AuthContext `json:"context"`
	Task    TaskInfo    `json:"task"`
}

type PropletSelectResponse

type PropletSelectResponse struct {
	Allow          bool     `json:"allow"`
	Reason         string   `json:"reason,omitempty"`
	RequiredTags   []string `json:"required_tags,omitempty"`
	MinMemoryBytes *uint64  `json:"min_memory_bytes,omitempty"`
}

type Registry

type Registry interface {
	List() []Plugin
	Close(ctx context.Context) error
}

func LoadDirectory

func LoadDirectory(ctx context.Context, dir string, logger *slog.Logger) (Registry, error)

type TaskEvent

type TaskEvent struct {
	Task    TaskInfo `json:"task"`
	Success bool     `json:"success,omitempty"`
	Result  string   `json:"result,omitempty"`
	Error   string   `json:"error,omitempty"`
}

type TaskInfo

type TaskInfo struct {
	ID        string            `json:"id"`
	Name      string            `json:"name"`
	Kind      string            `json:"kind,omitempty"`
	ImageURL  string            `json:"image_url,omitempty"`
	Inputs    []string          `json:"inputs,omitempty"`
	CLIArgs   []string          `json:"cli_args,omitempty"`
	Env       map[string]string `json:"env,omitempty"`
	PropletID string            `json:"proplet_id,omitempty"`
	Priority  int               `json:"priority,omitempty"`
	Daemon    bool              `json:"daemon,omitempty"`
	Encrypted bool              `json:"encrypted,omitempty"`
	CreatedAt time.Time         `json:"created_at,omitzero"`
}

func NewTaskInfo

func NewTaskInfo(t task.Task) TaskInfo

NewTaskInfo converts a task.Task to the TaskInfo passed to plugins.

Jump to

Keyboard shortcuts

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