workflow

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const InspectJS = `` /* 2995-byte string literal not displayed */

inspectJS extracts interactive elements from the DOM. Returns a JSON array of element descriptors. Designed to be compact and useful for LLM agents writing workflow YAML. InspectJS is the JavaScript that extracts interactive elements from the DOM. Exported so the CLI can call it via page.Eval().

Variables

This section is empty.

Functions

func InterpolateEnv

func InterpolateEnv(s string, workflowEnv map[string]string) string

InterpolateEnv replaces ${VAR_NAME} patterns with environment variable values. Checks the workflow's env map first, then os.Getenv.

func ParseTimeout

func ParseTimeout(s string) time.Duration

ParseTimeout converts a timeout string like "30s" or "2m" to a Duration. Defaults to 30s if empty or unparseable.

Types

type Action

type Action struct {
	URL           string       `yaml:"url,omitempty"`
	ForceNavigate bool         `yaml:"force_navigate,omitempty"` // navigate even if URL matches current page
	Headed        bool         `yaml:"headed,omitempty"`         // show browser window (used by BRZ_HEADED=auto)
	Viewport      *Viewport    `yaml:"viewport,omitempty"`       // override workflow-level viewport
	Steps         []Step       `yaml:"steps"`
	Eval          []EvalAssert `yaml:"eval,omitempty"` // post-action assertions
}

Action is a named sequence of steps with an optional starting URL.

type ActionResult

type ActionResult struct {
	OK               bool   `json:"ok"`
	Action           string `json:"action"`
	Steps            int    `json:"steps"`
	DurationMs       int64  `json:"duration_ms"`
	Download         string `json:"download,omitempty"`
	DownloadSize     int64  `json:"download_size,omitempty"`
	Error            string `json:"error,omitempty"`
	FailedStep       int    `json:"failed_step,omitempty"`
	StepType         string `json:"step_type,omitempty"`
	Screenshot       string `json:"screenshot,omitempty"`        // page state after failure
	ScreenshotBefore string `json:"screenshot_before,omitempty"` // page state before the failed step
	PageHTML         string `json:"page_html,omitempty"`         // page HTML at time of failure (for debugging)
	PageURL          string `json:"page_url,omitempty"`          // page URL at time of failure
	Escalated        bool   `json:"escalated,omitempty"`         // true if auto-escalated from headless to headed
	StatusCode       int    `json:"status_code,omitempty"`       // HTTP status code of the last navigation

	// Eval results
	EvalsPassed int      `json:"evals_passed,omitempty"` // number of eval assertions that passed
	EvalsFailed int      `json:"evals_failed,omitempty"` // number of eval assertions that failed
	EvalErrors  []string `json:"eval_errors,omitempty"`  // descriptions of failed assertions
}

ActionResult is the structured output of running a workflow action. Designed for machine consumption — LLM agents parse this as JSON.

type ClickStep

type ClickStep struct {
	Selector string `yaml:"selector"`
	Text     string `yaml:"text,omitempty"` // match by visible text
	Nth      int    `yaml:"nth,omitempty"`  // 0-indexed, use when multiple matches
	Timeout  string `yaml:"timeout,omitempty"`
}

type DownloadStep

type DownloadStep struct {
	Timeout string `yaml:"timeout,omitempty"`
	SaveAs  string `yaml:"save_as,omitempty"` // optional filename pattern
}

type ElementInfo

type ElementInfo struct {
	Selector    string `json:"selector"`
	Tag         string `json:"tag"`
	Type        string `json:"type,omitempty"`
	Name        string `json:"name,omitempty"`
	Placeholder string `json:"placeholder,omitempty"`
	Text        string `json:"text,omitempty"`
	Href        string `json:"href,omitempty"`
	Value       string `json:"value,omitempty"`
	Role        string `json:"role,omitempty"`
	Hidden      bool   `json:"hidden,omitempty"`
}

ElementInfo describes a single interactive DOM element.

type EvalAssert added in v0.3.0

type EvalAssert struct {
	// Page state
	JS          string `yaml:"js,omitempty"`           // JS expression that must return truthy
	URLContains string `yaml:"url_contains,omitempty"` // current URL must contain this string
	TextVisible string `yaml:"text_visible,omitempty"` // text must be visible on page
	NoText      string `yaml:"no_text,omitempty"`      // text must NOT be visible on page
	Selector    string `yaml:"selector,omitempty"`     // element must exist on page
	Timeout     string `yaml:"timeout,omitempty"`      // timeout for page-state checks (default "5s")

	// Response state
	StatusCode int `yaml:"status_code,omitempty"` // HTTP status code must match (e.g. 200)

	// Download state
	DownloadMinSize    int64    `yaml:"download_min_size,omitempty"`    // downloaded file must be at least N bytes
	DownloadMinRows    int      `yaml:"download_min_rows,omitempty"`    // CSV must have at least N data rows (excluding header)
	DownloadHasColumns []string `yaml:"download_has_columns,omitempty"` // CSV header must contain these columns

	// Metadata
	Label string `yaml:"label,omitempty"` // human-readable description for logging/errors
}

EvalAssert is a single post-action assertion. Exactly one field should be set.

type EvalResult added in v0.3.0

type EvalResult struct {
	Passed int
	Failed int
	Errors []string
}

EvalResult holds the outcome of running eval assertions on an action.

type Executor

type Executor struct {

	// LastDownload holds the path to the most recently downloaded file.
	LastDownload string
	// LastResult holds the string result of the most recent action (e.g. downloaded CSV content).
	LastResult string
	// LastStatusCode holds the HTTP status code from the most recent navigation.
	LastStatusCode int
	// contains filtered or unexported fields
}

Executor runs workflow actions against a real browser.

func NewExecutor

func NewExecutor(w *Workflow, opts ...Option) *Executor

NewExecutor creates an executor with browser configuration. Use functional options: WithHeaded(true), WithDebug(true), WithProfileDir("...").

func (*Executor) Close

func (e *Executor) Close()

Close shuts down the browser.

func (*Executor) IsHeaded

func (e *Executor) IsHeaded() bool

IsHeaded returns whether the browser is in headed (visible) mode.

func (*Executor) KeyPress

func (e *Executor) KeyPress(key input.Key) error

KeyPress sends a keyboard input to the current page.

func (*Executor) NavigateTo

func (e *Executor) NavigateTo(url string) error

NavigateTo creates a new page, injects stealth, and navigates to the given URL. Used by one-shot commands (inspect, screenshot, eval) that don't need a workflow.

func (*Executor) Page

func (e *Executor) Page() *rod.Page

Page returns the current page for advanced usage.

func (*Executor) RunAction

func (e *Executor) RunAction(name string) *ActionResult

RunAction executes a named action from the workflow. Returns a structured ActionResult suitable for JSON serialization.

func (*Executor) SetEnv

func (e *Executor) SetEnv(key, value string)

SetEnv sets an environment variable in the workflow's env map. These are used by InterpolateEnv for ${VAR} substitution in step values.

func (*Executor) Start

func (e *Executor) Start() error

Start launches the browser with stealth settings.

func (*Executor) UserAgent added in v0.7.1

func (e *Executor) UserAgent() string

UserAgent returns the User-Agent string the executor uses for page requests.

func (*Executor) WaitOnFailure added in v0.2.0

func (e *Executor) WaitOnFailure()

WaitOnFailure keeps the browser open for inspection when headed and an action failed. Call this from the CLI layer after RunAction returns a failure. Waits for the user to press Enter in the terminal, then returns.

type FillStep

type FillStep struct {
	Selector string `yaml:"selector"`
	Value    string `yaml:"value"`           // supports ${ENV_VAR} interpolation
	Clear    bool   `yaml:"clear,omitempty"` // clear field before filling
}

type InspectResult

type InspectResult struct {
	OK         bool          `json:"ok"`
	URL        string        `json:"url"`
	Title      string        `json:"title"`
	Elements   []ElementInfo `json:"elements"`
	Total      int           `json:"total"`
	Truncated  bool          `json:"truncated,omitempty"`
	DurationMs int64         `json:"duration_ms"`
	Error      string        `json:"error,omitempty"`
}

InspectResult is the structured output of inspecting a page's interactive elements.

type Option

type Option func(*Executor)

Option configures an Executor.

func WithAutoHeaded added in v0.2.0

func WithAutoHeaded(b bool) Option

WithAutoHeaded enables auto-escalation: start headless, but if an action marked headed:true fails, relaunch in headed mode and retry.

func WithDebug

func WithDebug(b bool) Option

WithDebug enables verbose logging and failure screenshots.

func WithHeaded

func WithHeaded(b bool) Option

WithHeaded shows the browser window (useful for CAPTCHAs or debugging).

func WithProfileDir

func WithProfileDir(dir string) Option

WithProfileDir sets the Chrome profile directory for session persistence.

type SelectStep added in v0.5.0

type SelectStep struct {
	Selector string `yaml:"selector"`
	Value    string `yaml:"value,omitempty"`   // option value to select (supports ${ENV_VAR})
	Text     string `yaml:"text,omitempty"`    // match by visible text instead of value
	Timeout  string `yaml:"timeout,omitempty"` // default 5s
}

type SleepStep

type SleepStep struct {
	Duration string `yaml:"duration"`
}

type Step

type Step struct {
	// Navigation
	Navigate string `yaml:"navigate,omitempty"`

	// Interactions
	Click    *ClickStep    `yaml:"click,omitempty"`
	Fill     *FillStep     `yaml:"fill,omitempty"`
	Select   *SelectStep   `yaml:"select,omitempty"`
	Upload   *UploadStep   `yaml:"upload,omitempty"`
	Download *DownloadStep `yaml:"download,omitempty"`

	// Waits
	WaitVisible *WaitStep    `yaml:"wait_visible,omitempty"`
	WaitText    *WaitStep    `yaml:"wait_text,omitempty"`
	WaitURL     *WaitURLStep `yaml:"wait_url,omitempty"`

	// Utilities
	Screenshot string     `yaml:"screenshot,omitempty"`
	Sleep      *SleepStep `yaml:"sleep,omitempty"`
	Eval       string     `yaml:"eval,omitempty"`

	// Control flow
	Label    string `yaml:"label,omitempty"`    // human-readable step description for logging
	Optional bool   `yaml:"optional,omitempty"` // if true, step failure is non-fatal
}

Step is a single browser operation. Exactly one field should be set.

type UploadStep

type UploadStep struct {
	Selector string `yaml:"selector"`
	Source   string `yaml:"source"` // "result" to use previous step's output, or a path
}

type Viewport added in v0.6.0

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

Viewport configures the browser window size.

func DefaultViewport added in v0.6.0

func DefaultViewport() Viewport

DefaultViewport returns the default browser viewport (1280x900).

func ResolveViewport added in v0.6.0

func ResolveViewport(workflow, action *Viewport) Viewport

ResolveViewport returns the effective viewport: action > workflow > default.

type WaitStep

type WaitStep struct {
	Selector string `yaml:"selector,omitempty"`
	Text     string `yaml:"text,omitempty"`
	State    string `yaml:"state,omitempty"` // visible, attached, hidden
	Timeout  string `yaml:"timeout,omitempty"`
}

type WaitURLStep

type WaitURLStep struct {
	Match   string `yaml:"match"`
	Timeout string `yaml:"timeout,omitempty"`
}

type Workflow

type Workflow struct {
	Name             string            `yaml:"name"`
	Env              map[string]string `yaml:"env,omitempty"`
	Viewport         *Viewport         `yaml:"viewport,omitempty"`
	DebugScreenshots *bool             `yaml:"debug_screenshots,omitempty"` // default: true
	Actions          map[string]Action `yaml:"actions"`
}

Workflow defines a complete browser automation workflow loaded from YAML.

func Load

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

Load reads and parses a workflow YAML file.

func LoadFromBytes added in v0.3.0

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

LoadFromBytes parses workflow YAML from a byte slice.

Jump to

Keyboard shortcuts

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