workflow

package
v0.0.0-...-d25dbbd Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	TriggerManual = "manual"
	TriggerCron   = "cron"

	OverlapPolicySkip = "skip"

	NodeTypeShell       = "shell"
	NodeTypeHTTP        = "http"
	NodeTypeLLM         = "llm"
	NodeTypeAgent       = "agent"
	NodeTypeDocker      = "docker"
	NodeTypeSMTP        = "smtp"
	NodeTypeCondition   = "condition"
	NodeTypeManualGate  = "manual_gate"
	NodeTypeSubworkflow = "subworkflow"

	RunStatusPending    = "pending"
	RunStatusRunning    = "running"
	RunStatusSucceeded  = "succeeded"
	RunStatusFailed     = "failed"
	RunStatusCancelled  = "cancelled"
	RunStatusWaiting    = "waiting"
	RunStatusManualGate = "manual_gate"

	NodeStatusPending    = "pending"
	NodeStatusRunning    = "running"
	NodeStatusSucceeded  = "succeeded"
	NodeStatusFailed     = "failed"
	NodeStatusSkipped    = "skipped"
	NodeStatusCancelled  = "cancelled"
	NodeStatusWaiting    = "waiting"
	NodeStatusManualGate = "manual_gate"
)

Variables

View Source
var ErrOverlapSkipped = fmt.Errorf("workflow overlap policy skipped run")
View Source
var SupportedTriggerTypes = []string{TriggerManual, TriggerCron}
View Source
var WorkflowExecuteSSHCommandForTesting = workflowExecuteSSHCommand

WorkflowExecuteSSHCommandForTesting allows tests in other packages to stub SSH execution.

Functions

func CronSchedules

func CronSchedules(definitionYAML string) ([]string, error)

func DecodeDependsOnJSON

func DecodeDependsOnJSON(encoded string) ([]string, error)

func DecodeOutputJSON

func DecodeOutputJSON(encoded string) (map[string]any, error)

func DefinitionHasAINodes

func DefinitionHasAINodes(def *Definition) bool

func DefinitionTriggerTypes

func DefinitionTriggerTypes(def *Definition) []string

func EncodeOutputJSON

func EncodeOutputJSON(values map[string]any) string

func IsTerminalRunStatus

func IsTerminalRunStatus(status string) bool

func MarkRunOrphaned

func MarkRunOrphaned(ctx context.Context, repo Repository, runID string) error

func ValidateDefinition

func ValidateDefinition(def *Definition) error

Types

type CreateDefinitionInput

type CreateDefinitionInput struct {
	Name             string
	Description      string
	IsEnabled        bool
	DefinitionYAML   string
	DefaultServerID  string
	CreatedBy        string
	TriggerTypesJSON string
	NodeCount        int
	HasAINodes       bool
}

type CreateRunInput

type CreateRunInput struct {
	WorkflowID       string
	DefinitionYAML   string
	Status           string
	TriggerType      string
	ExecutionOwnerID string
	RequestedBy      string
	RequestedByEmail string
	ParamsJSON       string
	ResolvedServerID string
	OverlapPolicy    string
	ErrorMessage     string
}

type Definition

type Definition struct {
	Name            string           `yaml:"name" json:"name"`
	Description     string           `yaml:"description,omitempty" json:"description,omitempty"`
	Params          []Parameter      `yaml:"params,omitempty" json:"params,omitempty"`
	Triggers        []Trigger        `yaml:"triggers,omitempty" json:"triggers,omitempty"`
	OverlapPolicy   string           `yaml:"overlap_policy,omitempty" json:"overlap_policy,omitempty"`
	DefaultServerID string           `yaml:"default_server_id,omitempty" json:"default_server_id,omitempty"`
	Nodes           []NodeDefinition `yaml:"nodes" json:"nodes"`
}

func ParseDefinition

func ParseDefinition(definitionYAML string) (*Definition, error)

type DefinitionRecord

type DefinitionRecord struct {
	ID               string `json:"id"`
	Name             string `json:"name"`
	Description      string `json:"description"`
	IsEnabled        bool   `json:"is_enabled"`
	DefinitionYAML   string `json:"definition_yaml"`
	DefaultServerID  string `json:"default_server_id"`
	TriggerTypesJSON string `json:"trigger_types_json"`
	NodeCount        int    `json:"node_count"`
	HasAINodes       bool   `json:"has_ai_nodes"`
	CreatedBy        string `json:"created_by"`
	Created          string `json:"created"`
	Updated          string `json:"updated"`
}

type ExecutionContext

type ExecutionContext struct {
	Run      *RunRecord
	Nodes    []NodeDefinition
	NodeRuns map[string]*NodeRunRecord
}

type Executor

type Executor interface {
	Execute(ctx context.Context, execCtx *ExecutorContext, nodeRun *NodeRunRecord, node NodeDefinition) (string, map[string]any, error)
}

type ExecutorContext

type ExecutorContext struct {
	App        core.App
	Definition *Definition
	Run        *RunRecord
	NodeRuns   map[string]*NodeRunRecord
	Params     map[string]any
	Repo       Repository
	Resolver   copilot.ProviderResolver
}

type ExecutorRegistry

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

func NewExecutorRegistry

func NewExecutorRegistry(app core.App) *ExecutorRegistry

func (*ExecutorRegistry) Execute

func (r *ExecutorRegistry) Execute(ctx context.Context, execCtx *ExecutorContext, nodeRun *NodeRunRecord, node NodeDefinition) (string, map[string]any, error)

func (*ExecutorRegistry) Register

func (r *ExecutorRegistry) Register(nodeType string, executor Executor)

type NodeDefinition

type NodeDefinition struct {
	Key        string         `yaml:"key" json:"key"`
	Name       string         `yaml:"name,omitempty" json:"name,omitempty"`
	Type       string         `yaml:"type" json:"type"`
	DependsOn  []string       `yaml:"depends_on,omitempty" json:"depends_on,omitempty"`
	TimeoutSec int            `yaml:"timeout_sec,omitempty" json:"timeout_sec,omitempty"`
	Retry      RetryPolicy    `yaml:"retry,omitempty" json:"retry,omitempty"`
	Config     map[string]any `yaml:"config,omitempty" json:"config,omitempty"`
}

func ReadyNodes

func ReadyNodes(execCtx *ExecutionContext) []NodeDefinition

type NodeRunRecord

type NodeRunRecord struct {
	ID                    string `json:"id"`
	WorkflowRunID         string `json:"workflow_run_id"`
	NodeKey               string `json:"node_key"`
	NodeType              string `json:"node_type"`
	DisplayName           string `json:"display_name"`
	DependsOnJSON         string `json:"depends_on_json"`
	Status                string `json:"status"`
	RetryCount            int    `json:"retry_count"`
	OutputJSON            string `json:"output_json"`
	ErrorMessage          string `json:"error_message"`
	ExecutionLog          string `json:"execution_log"`
	ExecutionLogTruncated bool   `json:"execution_log_truncated"`
	StartedAt             string `json:"started_at"`
	EndedAt               string `json:"ended_at"`
	Created               string `json:"created"`
	Updated               string `json:"updated"`
}

type NodeRunSeed

type NodeRunSeed struct {
	NodeKey       string
	NodeType      string
	DisplayName   string
	DependsOnJSON string
	Status        string
}

type Parameter

type Parameter struct {
	Name    string `yaml:"name" json:"name"`
	Type    string `yaml:"type" json:"type"`
	Default any    `yaml:"default,omitempty" json:"default,omitempty"`
}

type PrepareRunInput

type PrepareRunInput struct {
	WorkflowID       string
	TriggerType      string
	ExecutionOwnerID string
	RequestedBy      string
	RequestedByEmail string
	Params           map[string]any
}

type PreparedRun

type PreparedRun struct {
	Definition *DefinitionRecord
	Run        *RunRecord
	NodeRuns   []*NodeRunRecord
}

type Repository

type Repository interface {
	ListDefinitions(ctx context.Context) ([]*DefinitionRecord, error)
	GetDefinition(ctx context.Context, id string) (*DefinitionRecord, error)
	CreateDefinition(ctx context.Context, input CreateDefinitionInput) (*DefinitionRecord, error)
	UpdateDefinition(ctx context.Context, id string, input UpdateDefinitionInput) (*DefinitionRecord, error)
	DeleteDefinition(ctx context.Context, id string) error

	CreatePreparedRun(ctx context.Context, input CreateRunInput, nodes []NodeRunSeed) (*RunRecord, []*NodeRunRecord, error)
	CreateRun(ctx context.Context, input CreateRunInput) (*RunRecord, error)
	GetRun(ctx context.Context, id string) (*RunRecord, error)
	UpdateRun(ctx context.Context, id string, input UpdateRunInput) (*RunRecord, error)
	ListRunsByWorkflow(ctx context.Context, workflowID string) ([]*RunRecord, error)

	CreateNodeRuns(ctx context.Context, workflowRunID string, nodes []NodeRunSeed) ([]*NodeRunRecord, error)
	ListNodeRunsByRun(ctx context.Context, workflowRunID string) ([]*NodeRunRecord, error)
	UpdateNodeRun(ctx context.Context, id string, input UpdateNodeRunInput) (*NodeRunRecord, error)
	ListActiveRunsByWorkflow(ctx context.Context, workflowID string) ([]*RunRecord, error)
	ListOrphanedRuns(ctx context.Context) ([]*RunRecord, error)
	ListCronEnabledDefinitions(ctx context.Context) ([]*DefinitionRecord, error)
}

type RetryPolicy

type RetryPolicy struct {
	Limit int `yaml:"limit,omitempty" json:"limit,omitempty"`
}

type RunRecord

type RunRecord struct {
	ID               string `json:"id"`
	WorkflowID       string `json:"workflow_id"`
	DefinitionYAML   string `json:"definition_yaml"`
	Status           string `json:"status"`
	TriggerType      string `json:"trigger_type"`
	ExecutionOwnerID string `json:"execution_owner_id"`
	RequestedBy      string `json:"requested_by"`
	RequestedByEmail string `json:"requested_by_email"`
	ParamsJSON       string `json:"params_json"`
	ResolvedServerID string `json:"resolved_server_id"`
	OverlapPolicy    string `json:"overlap_policy"`
	StartedAt        string `json:"started_at"`
	EndedAt          string `json:"ended_at"`
	ErrorMessage     string `json:"error_message"`
	Created          string `json:"created"`
	Updated          string `json:"updated"`
}

type RunResult

type RunResult struct {
	Status string
	Node   *NodeRunRecord
}

type Runner

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

func NewRunner

func NewRunner(repo Repository) *Runner

func (*Runner) LoadExecutionContext

func (r *Runner) LoadExecutionContext(ctx context.Context, runID string, definitionYAML string) (*ExecutionContext, error)

func (*Runner) Run

type Service

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

func NewService

func NewService(repo Repository) *Service

func (*Service) CreateDefinition

func (s *Service) CreateDefinition(ctx context.Context, input CreateDefinitionInput) (*DefinitionRecord, error)

func (*Service) GetDefinition

func (s *Service) GetDefinition(ctx context.Context, id string) (*DefinitionRecord, error)

func (*Service) ListCronEnabledDefinitions

func (s *Service) ListCronEnabledDefinitions(ctx context.Context) ([]*DefinitionRecord, error)

func (*Service) ListDefinitions

func (s *Service) ListDefinitions(ctx context.Context) ([]*DefinitionRecord, error)

func (*Service) PrepareRun

func (s *Service) PrepareRun(ctx context.Context, input PrepareRunInput) (*PreparedRun, error)

func (*Service) UpdateDefinition

func (s *Service) UpdateDefinition(ctx context.Context, id string, input UpdateDefinitionInput) (*DefinitionRecord, error)

type Trigger

type Trigger struct {
	Type     string `yaml:"type" json:"type"`
	Schedule string `yaml:"schedule,omitempty" json:"schedule,omitempty"`
}

type UpdateDefinitionInput

type UpdateDefinitionInput struct {
	Name             string
	Description      string
	IsEnabled        bool
	DefinitionYAML   string
	DefaultServerID  string
	TriggerTypesJSON string
	NodeCount        int
	HasAINodes       bool
}

type UpdateNodeRunInput

type UpdateNodeRunInput struct {
	Status                *string
	RetryCount            *int
	OutputJSON            *string
	ErrorMessage          *string
	ExecutionLog          *string
	ExecutionLogTruncated *bool
	StartedAt             *string
	EndedAt               *string
}

type UpdateRunInput

type UpdateRunInput struct {
	Status       *string
	StartedAt    *string
	EndedAt      *string
	ErrorMessage *string
}

Jump to

Keyboard shortcuts

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