Documentation
¶
Overview ¶
Package rpa provides a Robotic Process Automation platform for browser automation.
Index ¶
- Constants
- type BrowserConfig
- type Duration
- type ErrorHandler
- type Evaluator
- type ExecutionStatus
- type Executor
- type ExecutorConfig
- type ForEachConfig
- type ParserValidationError
- type Resolver
- func (r *Resolver) Get(path string) (any, bool)
- func (r *Resolver) GetString(path string) (string, bool)
- func (r *Resolver) Resolve(value string) (string, error)
- func (r *Resolver) ResolveAny(value any) (any, error)
- func (r *Resolver) ResolveMap(m map[string]any) (map[string]any, error)
- func (r *Resolver) ResolveSlice(s []any) ([]any, error)
- func (r *Resolver) Set(name string, value any)
- func (r *Resolver) Variables() map[string]any
- type RetryConfig
- type Screenshot
- type Step
- type StepResult
- type ValidationError
- type ViewportConfig
- type Workflow
- type WorkflowResult
- func (r *WorkflowResult) AddScreenshot(screenshot Screenshot)
- func (r *WorkflowResult) AddStep(step StepResult)
- func (r *WorkflowResult) Complete(status ExecutionStatus, err error)
- func (r *WorkflowResult) FailureCount() int
- func (r *WorkflowResult) IsSuccess() bool
- func (r *WorkflowResult) JSON() ([]byte, error)
- func (r *WorkflowResult) SkippedCount() int
- func (r *WorkflowResult) SuccessCount() int
- func (r *WorkflowResult) TotalSteps() int
Constants ¶
const DefaultMaxRetries = 3
DefaultMaxRetries is the default maximum number of retry attempts.
const DefaultRetryDelay = time.Second
DefaultRetryDelay is the default delay between retries.
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 ¶
Duration represents a duration that can be unmarshaled from YAML/JSON strings.
func (Duration) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
func (Duration) MarshalYAML ¶
MarshalYAML implements yaml.Marshaler.
func (*Duration) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
func (*Duration) UnmarshalYAML ¶
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 ¶
NewEvaluator creates a new Evaluator with the given resolver.
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) RunWorkflow ¶
RunWorkflow executes a parsed workflow.
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 ¶
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 ¶
NewResolver creates a new Resolver with the given variables.
func (*Resolver) ResolveAny ¶
ResolveAny resolves variables in any value.
func (*Resolver) ResolveMap ¶
ResolveMap interpolates variables in all string values of a map.
func (*Resolver) ResolveSlice ¶
ResolveSlice interpolates variables in all string values of a slice.
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) GetTimeout ¶
GetTimeout returns the step's timeout, or the default if not set.
func (*Step) HasCondition ¶
HasCondition returns true if the step has a conditional expression.
func (*Step) HasForEach ¶
HasForEach returns true if the step is a forEach loop.
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 ¶
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 ¶
MustParseFile parses a workflow from a file and panics on error.
func ParseBytes ¶
ParseBytes parses a workflow from bytes, auto-detecting format. If the data starts with '{' or '[', it's treated as JSON, otherwise YAML.
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.