workflow

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2026 License: MIT Imports: 12 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"`
	Steps []Step `yaml:"steps"`
}

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"`
}

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 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
	// 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.

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 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 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"`
	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
}

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 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"`
	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.

Jump to

Keyboard shortcuts

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