rpa

package
v0.5.0 Latest Latest
Warning

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

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

Documentation

Overview

Package rpa provides a Robotic Process Automation platform for browser automation.

Index

Constants

View Source
const DefaultMaxRetries = 3

DefaultMaxRetries is the default maximum number of retry attempts.

View Source
const DefaultRetryDelay = time.Second

DefaultRetryDelay is the default delay between retries.

View Source
const DefaultTimeout = 30 * time.Second

DefaultTimeout is the default timeout for operations.

Variables

This section is empty.

Functions

This section is empty.

Types

type BrowserConfig

type BrowserConfig struct {
	// Headless runs the browser without a visible UI.
	Headless bool `yaml:"headless" json:"headless"`

	// Timeout is the default timeout for browser operations.
	Timeout Duration `yaml:"timeout,omitempty" json:"timeout,omitempty"`

	// Viewport sets the browser viewport dimensions.
	Viewport *ViewportConfig `yaml:"viewport,omitempty" json:"viewport,omitempty"`

	// UserAgent overrides the browser's user agent string.
	UserAgent string `yaml:"userAgent,omitempty" json:"userAgent,omitempty"`

	// IgnoreHTTPSErrors ignores HTTPS certificate errors.
	IgnoreHTTPSErrors bool `yaml:"ignoreHTTPSErrors,omitempty" json:"ignoreHTTPSErrors,omitempty"`
}

BrowserConfig contains browser-specific configuration options.

type Duration

type Duration time.Duration

Duration represents a duration that can be unmarshaled from YAML/JSON strings.

func (Duration) Duration

func (d Duration) Duration() time.Duration

Duration returns the underlying time.Duration.

func (Duration) MarshalJSON

func (d Duration) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (Duration) MarshalYAML

func (d Duration) MarshalYAML() (interface{}, error)

MarshalYAML implements yaml.Marshaler.

func (*Duration) UnmarshalJSON

func (d *Duration) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (*Duration) UnmarshalYAML

func (d *Duration) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements yaml.Unmarshaler.

type ErrorHandler

type ErrorHandler struct {
	// Screenshot captures a screenshot when an error occurs.
	Screenshot bool `yaml:"screenshot" json:"screenshot"`

	// Steps are optional steps to execute when an error occurs.
	Steps []Step `yaml:"steps,omitempty" json:"steps,omitempty"`
}

ErrorHandler configures error handling behavior.

type Evaluator

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

Evaluator handles condition expressions.

func NewEvaluator

func NewEvaluator(resolver *Resolver) *Evaluator

NewEvaluator creates a new Evaluator with the given resolver.

func (*Evaluator) Evaluate

func (e *Evaluator) Evaluate(expr string) (bool, error)

Evaluate evaluates a simple condition expression. Supports:

  • ${var} - truthy check
  • ${var} == 'value'
  • ${var} != 'value'
  • ${var} > number
  • ${var} < number
  • ${var} >= number
  • ${var} <= number
  • !${var} - falsy check

type ExecutionStatus

type ExecutionStatus string

ExecutionStatus represents the state of a workflow or step execution.

const (
	StatusPending ExecutionStatus = "pending"
	StatusRunning ExecutionStatus = "running"
	StatusSuccess ExecutionStatus = "success"
	StatusFailure ExecutionStatus = "failure"
	StatusSkipped ExecutionStatus = "skipped"
)

func (ExecutionStatus) IsTerminal

func (s ExecutionStatus) IsTerminal() bool

IsTerminal returns true if the status is a terminal state.

func (ExecutionStatus) String

func (s ExecutionStatus) String() string

String returns the string representation of the status.

type Executor

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

Executor runs RPA workflows.

func NewExecutor

func NewExecutor(config ExecutorConfig) *Executor

NewExecutor creates a new workflow executor.

func (*Executor) RunFile

func (e *Executor) RunFile(ctx context.Context, path string) (*WorkflowResult, error)

RunFile executes a workflow from a file.

func (*Executor) RunWorkflow

func (e *Executor) RunWorkflow(ctx context.Context, wf *Workflow) (*WorkflowResult, error)

RunWorkflow executes a parsed workflow.

func (*Executor) Validate

func (e *Executor) Validate(ctx context.Context, wf *Workflow) []ValidationError

Validate checks a workflow for errors without executing.

type ExecutorConfig

type ExecutorConfig struct {
	// Headless runs the browser in headless mode.
	Headless bool

	// DefaultTimeout is the default timeout for operations.
	DefaultTimeout time.Duration

	// WorkDir is the working directory for file operations.
	WorkDir string

	// Variables contains runtime variable overrides.
	Variables map[string]string

	// DryRun parses and validates without executing.
	DryRun bool

	// Logger is the structured logger.
	Logger *slog.Logger

	// OnStepStart is called when a step starts.
	OnStepStart func(step *Step)

	// OnStepComplete is called when a step completes.
	OnStepComplete func(step *Step, result *StepResult)
}

ExecutorConfig configures the workflow executor.

type ForEachConfig

type ForEachConfig struct {
	// Items is the variable name or expression containing the items to iterate.
	Items string `yaml:"items" json:"items"`

	// Variable is the name of the loop variable (available as ${variable}).
	Variable string `yaml:"as" json:"as"`

	// Steps are the steps to execute for each item.
	Steps []Step `yaml:"steps" json:"steps"`
}

ForEachConfig configures iteration over a collection.

type ParserValidationError

type ParserValidationError struct {
	Path    string
	Field   string
	Message string
}

ParserValidationError represents a validation error during parsing.

func (ParserValidationError) Error

func (e ParserValidationError) Error() string

type Resolver

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

Resolver handles variable interpolation and expression evaluation.

func NewResolver

func NewResolver(variables map[string]any) *Resolver

NewResolver creates a new Resolver with the given variables.

func (*Resolver) Get

func (r *Resolver) Get(path string) (any, bool)

Get retrieves a variable value by path (supports dot notation).

func (*Resolver) GetString

func (r *Resolver) GetString(path string) (string, bool)

GetString retrieves a variable as a string.

func (*Resolver) Resolve

func (r *Resolver) Resolve(value string) (string, error)

Resolve interpolates variables in a string value.

func (*Resolver) ResolveAny

func (r *Resolver) ResolveAny(value any) (any, error)

ResolveAny resolves variables in any value.

func (*Resolver) ResolveMap

func (r *Resolver) ResolveMap(m map[string]any) (map[string]any, error)

ResolveMap interpolates variables in all string values of a map.

func (*Resolver) ResolveSlice

func (r *Resolver) ResolveSlice(s []any) ([]any, error)

ResolveSlice interpolates variables in all string values of a slice.

func (*Resolver) Set

func (r *Resolver) Set(name string, value any)

Set sets a variable value.

func (*Resolver) Variables

func (r *Resolver) Variables() map[string]any

Variables returns the underlying variables map.

type RetryConfig

type RetryConfig struct {
	// MaxAttempts is the maximum number of retry attempts.
	MaxAttempts int `yaml:"maxAttempts" json:"maxAttempts"`

	// Delay is the delay between retry attempts.
	Delay Duration `yaml:"delay" json:"delay"`

	// BackoffMultiplier multiplies the delay after each retry (default: 1.0).
	BackoffMultiplier float64 `yaml:"backoffMultiplier,omitempty" json:"backoffMultiplier,omitempty"`
}

RetryConfig configures automatic retry behavior.

type Screenshot

type Screenshot struct {
	// StepID is the ID of the step that triggered the screenshot.
	StepID string `json:"stepId,omitempty"`

	// Timestamp is when the screenshot was captured.
	Timestamp time.Time `json:"timestamp"`

	// Data is the base64-encoded PNG image data.
	Data string `json:"data"`

	// Reason describes why the screenshot was captured.
	Reason string `json:"reason,omitempty"`
}

Screenshot represents a captured screenshot.

type Step

type Step struct {
	// ID is a unique identifier for the step (optional).
	ID string `yaml:"id,omitempty" json:"id,omitempty"`

	// Name is a human-readable name for the step.
	Name string `yaml:"name,omitempty" json:"name,omitempty"`

	// Activity is the activity type to execute (e.g., "browser.navigate").
	Activity string `yaml:"activity" json:"activity"`

	// Params contains the parameters for the activity.
	Params map[string]interface{} `yaml:"params,omitempty" json:"params,omitempty"`

	// Condition is an expression that must evaluate to true for the step to execute.
	Condition string `yaml:"if,omitempty" json:"if,omitempty"`

	// ForEach enables iteration over a collection.
	ForEach *ForEachConfig `yaml:"forEach,omitempty" json:"forEach,omitempty"`

	// Store specifies a variable name to store the step's output.
	Store string `yaml:"store,omitempty" json:"store,omitempty"`

	// ContinueOnError allows the workflow to continue if this step fails.
	ContinueOnError bool `yaml:"continueOnError,omitempty" json:"continueOnError,omitempty"`

	// Retry configures automatic retry behavior.
	Retry *RetryConfig `yaml:"retry,omitempty" json:"retry,omitempty"`

	// Timeout overrides the default timeout for this step.
	Timeout Duration `yaml:"timeout,omitempty" json:"timeout,omitempty"`

	// Steps contains nested steps (for control flow activities).
	Steps []Step `yaml:"steps,omitempty" json:"steps,omitempty"`
}

Step represents a single step in a workflow.

func (*Step) GetID

func (s *Step) GetID() string

GetID returns the step's ID, generating one from the name if not set.

func (*Step) GetTimeout

func (s *Step) GetTimeout(defaultTimeout Duration) Duration

GetTimeout returns the step's timeout, or the default if not set.

func (*Step) HasCondition

func (s *Step) HasCondition() bool

HasCondition returns true if the step has a conditional expression.

func (*Step) HasForEach

func (s *Step) HasForEach() bool

HasForEach returns true if the step is a forEach loop.

func (*Step) HasRetry

func (s *Step) HasRetry() bool

HasRetry returns true if the step has retry configuration.

type StepResult

type StepResult struct {
	// StepID is the unique identifier of the step.
	StepID string `json:"stepId"`

	// StepName is the human-readable name of the step.
	StepName string `json:"stepName"`

	// Activity is the activity type that was executed.
	Activity string `json:"activity"`

	// Status is the execution status of the step.
	Status ExecutionStatus `json:"status"`

	// StartTime is when the step started.
	StartTime time.Time `json:"startTime"`

	// EndTime is when the step finished.
	EndTime time.Time `json:"endTime"`

	// Duration is the step execution time.
	Duration time.Duration `json:"duration"`

	// Output contains the step's output value.
	Output interface{} `json:"output,omitempty"`

	// Error contains the error message if the step failed.
	Error string `json:"error,omitempty"`

	// Screenshot contains a screenshot if captured (base64 encoded).
	Screenshot string `json:"screenshot,omitempty"`

	// Retries is the number of retry attempts made.
	Retries int `json:"retries,omitempty"`

	// Params contains the resolved parameters used for execution.
	Params map[string]interface{} `json:"params,omitempty"`
}

StepResult contains the result of a single step execution.

func NewStepResult

func NewStepResult(step *Step) *StepResult

NewStepResult creates a new StepResult with initialized fields.

func (*StepResult) Complete

func (r *StepResult) Complete(status ExecutionStatus, output interface{}, err error)

Complete finalizes the step result.

func (*StepResult) MarkRunning

func (r *StepResult) MarkRunning()

MarkRunning marks the step as running.

func (*StepResult) MarkSkipped

func (r *StepResult) MarkSkipped(reason string)

MarkSkipped marks the step as skipped with a reason.

type ValidationError

type ValidationError struct {
	StepID  string
	Field   string
	Message string
}

ValidationError represents a validation error.

type ViewportConfig

type ViewportConfig struct {
	Width  int `yaml:"width" json:"width"`
	Height int `yaml:"height" json:"height"`
}

ViewportConfig defines browser viewport dimensions.

type Workflow

type Workflow struct {
	// Name is the human-readable name of the workflow.
	Name string `yaml:"name" json:"name"`

	// Description provides additional context about the workflow.
	Description string `yaml:"description,omitempty" json:"description,omitempty"`

	// Version is the semantic version of the workflow definition.
	Version string `yaml:"version,omitempty" json:"version,omitempty"`

	// Browser contains browser-specific configuration.
	Browser BrowserConfig `yaml:"browser,omitempty" json:"browser,omitempty"`

	// Variables defines workflow-level variables with default values.
	// These can be overridden at runtime.
	Variables map[string]string `yaml:"variables,omitempty" json:"variables,omitempty"`

	// Steps is the ordered list of steps to execute.
	Steps []Step `yaml:"steps" json:"steps"`

	// OnError defines error handling behavior for the workflow.
	OnError *ErrorHandler `yaml:"onError,omitempty" json:"onError,omitempty"`
}

Workflow represents a complete automation workflow.

func MustParseFile

func MustParseFile(path string) *Workflow

MustParseFile parses a workflow from a file and panics on error.

func ParseBytes

func ParseBytes(data []byte) (*Workflow, error)

ParseBytes parses a workflow from bytes, auto-detecting format. If the data starts with '{' or '[', it's treated as JSON, otherwise YAML.

func ParseFile

func ParseFile(path string) (*Workflow, error)

ParseFile parses a workflow from a file, auto-detecting format.

func ParseReader

func ParseReader(r io.Reader, format string) (*Workflow, error)

ParseReader parses a workflow from a reader.

type WorkflowResult

type WorkflowResult struct {
	// WorkflowName is the name of the executed workflow.
	WorkflowName string `json:"workflowName"`

	// Status is the final execution status.
	Status ExecutionStatus `json:"status"`

	// StartTime is when the workflow started.
	StartTime time.Time `json:"startTime"`

	// EndTime is when the workflow finished.
	EndTime time.Time `json:"endTime"`

	// Duration is the total execution time.
	Duration time.Duration `json:"duration"`

	// Steps contains results for each executed step.
	Steps []StepResult `json:"steps"`

	// Variables contains the final state of all variables.
	Variables map[string]interface{} `json:"variables"`

	// Error contains the error message if the workflow failed.
	Error string `json:"error,omitempty"`

	// Screenshots contains any captured screenshots (base64 encoded).
	Screenshots []Screenshot `json:"screenshots,omitempty"`
}

WorkflowResult contains the results of a workflow execution.

func NewWorkflowResult

func NewWorkflowResult(workflowName string) *WorkflowResult

NewWorkflowResult creates a new WorkflowResult with initialized fields.

func (*WorkflowResult) AddScreenshot

func (r *WorkflowResult) AddScreenshot(screenshot Screenshot)

AddScreenshot adds a screenshot to the workflow result.

func (*WorkflowResult) AddStep

func (r *WorkflowResult) AddStep(step StepResult)

AddStep adds a step result to the workflow result.

func (*WorkflowResult) Complete

func (r *WorkflowResult) Complete(status ExecutionStatus, err error)

Complete finalizes the workflow result.

func (*WorkflowResult) FailureCount

func (r *WorkflowResult) FailureCount() int

FailureCount returns the number of failed steps.

func (*WorkflowResult) IsSuccess

func (r *WorkflowResult) IsSuccess() bool

IsSuccess returns true if the workflow completed successfully.

func (*WorkflowResult) JSON

func (r *WorkflowResult) JSON() ([]byte, error)

JSON returns the result as formatted JSON.

func (*WorkflowResult) SkippedCount

func (r *WorkflowResult) SkippedCount() int

SkippedCount returns the number of skipped steps.

func (*WorkflowResult) SuccessCount

func (r *WorkflowResult) SuccessCount() int

SuccessCount returns the number of successful steps.

func (*WorkflowResult) TotalSteps

func (r *WorkflowResult) TotalSteps() int

TotalSteps returns the total number of executed steps.

Directories

Path Synopsis
Package activity provides the activity system for RPA workflow execution.
Package activity provides the activity system for RPA workflow execution.

Jump to

Keyboard shortcuts

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