automation

package
v0.3.10 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTaskNotFound = errors.New("automation task not found")
)

Functions

func BuildDispatchText

func BuildDispatchText(action Action) (string, error)

func NextRunAt

func NextRunAt(from time.Time, schedule Schedule) time.Time

func ValidateTask

func ValidateTask(task Task) error

Types

type Action

type Action struct {
	Type           ActionType `json:"type"`
	Text           string     `json:"text"`
	Prompt         string     `json:"prompt,omitempty"`
	Model          string     `json:"model,omitempty"`
	Profile        string     `json:"profile,omitempty"`
	MentionUserIDs []string   `json:"mention_user_ids,omitempty"`
}

type ActionType

type ActionType string
const (
	ActionTypeSendText ActionType = "send_text"
	ActionTypeRunLLM   ActionType = "run_llm"
)

type Actor

type Actor struct {
	UserID string `json:"user_id,omitempty"`
	OpenID string `json:"open_id,omitempty"`
	Name   string `json:"name,omitempty"`
}

func (Actor) PreferredID

func (a Actor) PreferredID() string

type Engine

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

func NewEngine

func NewEngine(store *Store, sender TextSender) *Engine

func (*Engine) RegisterSystemTask

func (e *Engine) RegisterSystemTask(name string, interval time.Duration, run SystemTaskFunc) error

func (*Engine) Run

func (e *Engine) Run(ctx context.Context)

func (*Engine) SetLLMRunner

func (e *Engine) SetLLMRunner(runner LLMRunner)

func (*Engine) SetRunEnv

func (e *Engine) SetRunEnv(env map[string]string)

func (*Engine) SetUserTaskTimeout

func (e *Engine) SetUserTaskTimeout(timeout time.Duration)

type LLMRunner

type LLMRunner interface {
	Run(ctx context.Context, req llm.RunRequest) (llm.RunResult, error)
}

type ManageMode

type ManageMode string
const (
	ManageModeCreatorOnly ManageMode = "creator_only"
	ManageModeScopeAll    ManageMode = "scope_all"
)

type Route

type Route struct {
	ReceiveIDType string `json:"receive_id_type"`
	ReceiveID     string `json:"receive_id"`
}

type Schedule

type Schedule struct {
	Type         ScheduleType `json:"type"`
	EverySeconds int          `json:"every_seconds"`
	CronExpr     string       `json:"cron_expr,omitempty"`
}

type ScheduleType

type ScheduleType string
const (
	ScheduleTypeInterval ScheduleType = "interval"
	ScheduleTypeCron     ScheduleType = "cron"
)

type Scope

type Scope struct {
	Kind ScopeKind `json:"kind"`
	ID   string    `json:"id"`
}

type ScopeKind

type ScopeKind string
const (
	ScopeKindUser ScopeKind = "user"
	ScopeKindChat ScopeKind = "chat"
)

type Snapshot

type Snapshot struct {
	Version int    `json:"version"`
	Tasks   []Task `json:"tasks"`
}

type Store

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

func NewStore

func NewStore(path string) *Store

func (*Store) ClaimDueTasks

func (s *Store) ClaimDueTasks(at time.Time, limit int) ([]Task, error)

func (*Store) CreateTask

func (s *Store) CreateTask(task Task) (Task, error)

func (*Store) GetTask

func (s *Store) GetTask(taskID string) (Task, error)

func (*Store) ListTasks

func (s *Store) ListTasks(scope Scope, statusFilter string, limit int) ([]Task, error)

func (*Store) PatchTask

func (s *Store) PatchTask(taskID string, mutate func(task *Task) error) (Task, error)

func (*Store) Path

func (s *Store) Path() string

func (*Store) RecordTaskResult

func (s *Store) RecordTaskResult(taskID string, at time.Time, runErr error) error

func (*Store) ResetRunningTasks

func (s *Store) ResetRunningTasks() error

type SystemTaskFunc

type SystemTaskFunc func(ctx context.Context)

type Task

type Task struct {
	ID                  string     `json:"id"`
	Title               string     `json:"title,omitempty"`
	Scope               Scope      `json:"scope"`
	Route               Route      `json:"route"`
	Creator             Actor      `json:"creator"`
	ManageMode          ManageMode `json:"manage_mode"`
	Schedule            Schedule   `json:"schedule"`
	Action              Action     `json:"action"`
	Status              TaskStatus `json:"status"`
	MaxRuns             int        `json:"max_runs,omitempty"`
	RunCount            int        `json:"run_count,omitempty"`
	CreatedAt           time.Time  `json:"created_at"`
	UpdatedAt           time.Time  `json:"updated_at"`
	NextRunAt           time.Time  `json:"next_run_at"`
	LastRunAt           time.Time  `json:"last_run_at,omitempty"`
	Running             bool       `json:"running,omitempty"`
	LastResult          string     `json:"last_result,omitempty"`
	ConsecutiveFailures int        `json:"consecutive_failures,omitempty"`
	Revision            int64      `json:"revision"`
}

func NormalizeTask

func NormalizeTask(task Task) Task

type TaskStatus

type TaskStatus string
const (
	TaskStatusActive  TaskStatus = "active"
	TaskStatusPaused  TaskStatus = "paused"
	TaskStatusDeleted TaskStatus = "deleted"
)

func ParseStatusFilter

func ParseStatusFilter(raw string) (TaskStatus, bool, error)

type TextSender

type TextSender interface {
	SendText(ctx context.Context, receiveIDType, receiveID, text string) error
}

Jump to

Keyboard shortcuts

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