Documentation
¶
Index ¶
- Variables
- type ActionContext
- type ActionRunner
- type Event
- type EventType
- type InputValidationError
- type Instance
- func (in *Instance) CurrentStepID() string
- func (in *Instance) Definition() *definition.WorkflowDefinition
- func (in *Instance) Events() []Event
- func (in *Instance) IsTerminal() bool
- func (in *Instance) RunID() string
- func (in *Instance) RunUntilBlocked() RunResult
- func (in *Instance) Snapshot() Snapshot
- func (in *Instance) Step() (*definition.Step, error)
- func (in *Instance) StepByID(id string) (*definition.Step, error)
- func (in *Instance) SubmitInput(input map[string]any) SubmitInputResult
- func (in *Instance) Variables() map[string]any
- type Options
- type Registry
- type RunResult
- type RunStatus
- type Snapshot
- type SubmitInputResult
- type SubmitInputStatus
- type UnknownStepError
Constants ¶
This section is empty.
Variables ¶
var ( ErrNilDefinition = errors.New("engine: workflow definition is nil") ErrEmptyInitialStepID = errors.New("engine: initialStepId is empty") ErrInitialStepUnknown = errors.New("engine: initialStepId not found in steps") ErrEmptyStepID = errors.New("engine: step id is empty") ErrEmptyStepKind = errors.New("engine: step kind is empty") ErrDuplicateStepID = errors.New("engine: duplicate step id") ErrNoMatchingTransition = errors.New("engine: no matching transition") ErrUnknownActionType = errors.New("engine: unknown action type") ErrCELGuard = errors.New("engine: cel guard evaluation failed") )
Functions ¶
This section is empty.
Types ¶
type ActionContext ¶
type ActionContext struct {
RunID string
StepID string
ListName string // "onEnter" or "onExit"
Index int
Action definition.Action
Variables map[string]any
}
ActionContext is the input to ActionRunner.Run for one action invocation.
type ActionRunner ¶
type ActionRunner interface {
Run(ctx ActionContext) error
}
ActionRunner executes a single workflow action (stub, http, or custom types).
func NewHTTPRunner ¶
func NewHTTPRunner(client *http.Client) ActionRunner
NewHTTPRunner builds an ActionRunner for workflow actions with type "http".
func NewStubRunner ¶
func NewStubRunner() ActionRunner
NewStubRunner returns the built-in "stub" runner (params.set merges JSON values into variables).
type Event ¶
type Event struct {
Seq int `json:"seq"`
RunID string `json:"runId,omitempty"`
Type EventType `json:"type"`
StepID string `json:"stepId,omitempty"`
// input.accepted
InputKeys []string `json:"inputKeys,omitempty"`
// action.ran
ActionList string `json:"actionList,omitempty"` // "onEnter" or "onExit"
ActionID string `json:"actionId,omitempty"`
ActionType string `json:"actionType,omitempty"`
// transition.guard / transition.taken:
TransitionIndex int `json:"transitionIndex,omitempty"`
FromStepID string `json:"fromStepId,omitempty"`
ToStepID string `json:"toStepId,omitempty"`
// transition.guard:
GuardResult string `json:"guardResult,omitempty"` // "true", "false", "error"
GuardError string `json:"guardError,omitempty"`
}
Event is one row in the execution trace (JSON-serializable).
type EventType ¶
type EventType string
EventType identifies the kind of trace Event.
const ( EventStepEntered EventType = "step.entered" EventInputAccepted EventType = "input.accepted" EventActionRan EventType = "action.ran" EventTransitionGuard EventType = "transition.guard" EventTransitionTaken EventType = "transition.taken" EventBlocked EventType = "run.blocked" EventCompleted EventType = "run.completed" )
type InputValidationError ¶
InputValidationError means SubmitInput input failed JSON Schema validation for a human step.
func (*InputValidationError) Error ¶
func (e *InputValidationError) Error() string
func (*InputValidationError) Unwrap ¶
func (e *InputValidationError) Unwrap() error
type Instance ¶
type Instance struct {
// contains filtered or unexported fields
}
func NewInstance ¶
func NewInstance(def *definition.WorkflowDefinition, opts Options) (*Instance, error)
NewInstance creates an Instance positioned at def.InitialStepID with a shallow copy of opts.InitialVariables. It validates step ids, initial step presence, and terminal rules (via workflowgraph.BuildTerminalSet).
func NewInstanceFromSnapshot ¶
func NewInstanceFromSnapshot(def *definition.WorkflowDefinition, snap Snapshot, opts Options) (*Instance, error)
NewInstanceFromSnapshot restores an Instance from Snapshot plus the workflow used when the run began. def must describe the same graph as at snapshot time (same ids and compatible steps/transitions).
Registry: pass the same ActionRegistry semantics as then the run was created (or rely on defaults consistently). RunID uses opts.RunID when non-empty, otherwise snap.RunID. TraceGuards is true if either opts.TraceGuards or snap.TraceGuards is true.
func (*Instance) CurrentStepID ¶
CurrentStepID returns the step the engine is currently on.
func (*Instance) Definition ¶
func (in *Instance) Definition() *definition.WorkflowDefinition
Definition returns the workflow bound to this instance, or nil if in is nil. Callers must not mutate the returned pointer or its contents.
func (*Instance) Events ¶
Events returns a copy of recorded trace events (safe to read without racing the instance).
func (*Instance) IsTerminal ¶
IsTerminal reports whether the current step is both kind "end" and listed in terminalStepIds.
func (*Instance) RunUntilBlocked ¶
RunUntilBlocked advances execution until the engine must stop and yield to the host.
RunBlocked: current step is human - call SubmitInput next. RunCompleted: reached a declared terminal end step. RunFailed: Err describes the failure; StepID and Events reflect progress up to the failure.
Returned Events is a snapshot at return time (same ordering as Instance.Events()).
func (*Instance) Snapshot ¶
Snapshot builds a Snapshot value from the current instance. Variables and Events are shallow-copied (top-level maps/slices only); nested values may still alias live state.
func (*Instance) Step ¶
func (in *Instance) Step() (*definition.Step, error)
Step returns the definition for the current step.
func (*Instance) StepByID ¶
func (in *Instance) StepByID(id string) (*definition.Step, error)
StepByID returns the step definition for id. If id is not in the workflow, the error satisfies errors.As(..., *UnknownStepError).
func (*Instance) SubmitInput ¶
func (in *Instance) SubmitInput(input map[string]any) SubmitInputResult
SubmitInput applies user input on the current human step.
It validates against inputSchema (when present), merges top-level keys into variables, evaluates outbound transitions, runs onExit actions when leaving, and moves currentStepID when a transition fires.
SubmitStayOnStep means input was accepted but no transition matched (caller may prompt again or extend variables). SubmitAdvanced means the instance advanced to StepID (now the next step). SubmitFailed sets Err (schema failure wraps *InputValidationError when applicable).
type Options ¶
type Options struct {
RunID string
InitialVariables map[string]any
TraceGuards bool
ActionRegistry *Registry
}
Options configures a new workflow instance (identity, initial variables, tracing, action runners).
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry maps workflow action "type" strings to ActionRunner implementations. Register everything needed by the workflow before passing the registry to NewInstance.
func DefaultRegistry ¶
func DefaultRegistry() *Registry
DefaultRegistry returns a registry with the built-in "stub" runner registered.
func NewRegistry ¶
func NewRegistry() *Registry
NewRegistry returns an empty registry (no built-in types registered).
func RegistryWithHTTP ¶
RegistryWithHTTP returns DefaultRegistry plus an "http" runner using client.
func (*Registry) Lookup ¶
func (r *Registry) Lookup(actionType string) (ActionRunner, bool)
Lookup returns the runner for actionType and whether it exists.
func (*Registry) MustRegister ¶
func (r *Registry) MustRegister(actionType string, runner ActionRunner)
MustRegister calls Register and panics if Register returns an error.
type RunResult ¶
RunResult is the outcome of RunUntilBlocked.
Events is a point-in-time snapshot (matches Instance.Events() at return). Err is non-nil only when Status is RunFailed.
type Snapshot ¶
type Snapshot struct {
RunID string `json:"runId"`
TraceGuards bool `json:"traceGuards"`
CurrentStepID string `json:"currentStepId"`
OnEnterRan bool `json:"onEnterRan"`
Variables map[string]any `json:"variables"`
Events []Event `json:"events,omitempty"`
NextSeq int `json:"nextSeq"`
}
Snapshot is JSON-friendly runtime state: correlation id, step position, variables, and trace. It does not store compiled CEL programs or compiled input schemas; those are rebuilt after restore.
type SubmitInputResult ¶
type SubmitInputResult struct {
Status SubmitInputStatus
StepID string
Err error
}
SubmitInputResult is returned by Instance.SubmitInput.
StepID is the current step after the call (unchanged on SubmitStayOnStep and SubmitFailed except where noted). Err is set only when Status is SubmitFailed.
type SubmitInputStatus ¶
type SubmitInputStatus int
SubmitInputStatus is the outcome of SubmitInput.
const ( // SubmitStayOnStep means input was stored but no outbound transition matched; still on the human step. SubmitStayOnStep SubmitInputStatus = iota + 1 // SubmitAdvanced means input was accepted and currentStepID moved to StepID (the next step). SubmitAdvanced // SubmitFailed means validation or leaving the step failed; see SubmitInputResult.Err. SubmitFailed )
type UnknownStepError ¶
type UnknownStepError struct {
StepID string
}
func (*UnknownStepError) Error ¶
func (e *UnknownStepError) Error() string