Help us shape the future of Go! Take the 2026 Go Developer Survey

controller

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2025 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateSchema

func GenerateSchema(typeDefinition interface{}) string

func RegisterAction

func RegisterAction[T, D any](
	c *Controller,
	name string,
	description string,
	function einoUtils.InvokeFunc[T, D],
	domains []string,
	pageFilter func(playwright.Page) bool,
) error

func ValidateSchema

func ValidateSchema(schemaString string, data map[string]interface{}) error

Types

type ActModel

type ActModel map[string]interface{}

func (*ActModel) GetIndex

func (am *ActModel) GetIndex() *int

Get the index of the action

func (*ActModel) SetIndex

func (am *ActModel) SetIndex(index int)

Overwrite the index of the action

type ActionModel

type ActionModel struct {
	/*
	* this will have all the registered actions, e.g.
	* click_element_by_index = param_model = ClickElementParams
	* done = param_model = nil
	 */
	Actions map[string]*RegisteredAction `json:"actions"`
}

Base model for dynamically created action models

type ActionRegistry

type ActionRegistry struct {
	Actions map[string]*RegisteredAction
}

Model representing the action registry

func NewActionRegistry

func NewActionRegistry() *ActionRegistry

func (*ActionRegistry) GetPromptDescription

func (ar *ActionRegistry) GetPromptDescription(page playwright.Page) string

Get a description of all actions for the prompt

type ActionResult

type ActionResult struct {
	IsDone           *bool   `json:"is_done,omitempty"`
	Success          *bool   `json:"success,omitempty"`
	ExtractedContent *string `json:"extracted_content,omitempty"`
	Error            *string `json:"error,omitempty"`
	IncludeInMemory  bool    `json:"include_in_memory"`
}

func NewActionResult

func NewActionResult() *ActionResult

type ClickElementAction

type ClickElementAction struct {
	Index int     `json:"index"`
	Xpath *string `json:"xpath,omitempty" jsonschema:"anyof_type=string;null,default=null"`
}

type CloseTabAction

type CloseTabAction struct {
	PageId int `json:"page_id"`
}

type Controller

type Controller struct {
	Registry *Registry
}

func NewController

func NewController() *Controller

func (*Controller) ClickElementByIndex

func (c *Controller) ClickElementByIndex(ctx context.Context, params ClickElementAction) (*ActionResult, error)

ExecuteAction: action.Function(validatedParams, extraArgs)

func (*Controller) CloseTab

func (c *Controller) CloseTab(ctx context.Context, params CloseTabAction) (*ActionResult, error)

func (*Controller) Done

func (c *Controller) Done(_ context.Context, params DoneAction) (*ActionResult, error)

func (*Controller) DragDrop

func (c *Controller) DragDrop(ctx context.Context, params DragDropAction) (*ActionResult, error)

Performs a precise drag and drop operation between elements or coordinates.

func (*Controller) ExecuteAction

func (c *Controller) ExecuteAction(
	action *ActModel,
	browserContext *browser.BrowserContext,
	pageExtractionLlm model.ToolCallingChatModel,
	sensitiveData map[string]string,
	availableFilePaths []string,

) (*ActionResult, error)

Act

func (*Controller) ExtractContent

func (c *Controller) ExtractContent(ctx context.Context, params ExtractContentAction) (*ActionResult, error)

func (*Controller) GetDropdownOptions

func (c *Controller) GetDropdownOptions(ctx context.Context, params GetDropdownOptionsAction) (*ActionResult, error)

func (*Controller) GoBack

func (c *Controller) GoBack(ctx context.Context, params GoBackAction) (*ActionResult, error)

func (*Controller) GoToUrl

func (c *Controller) GoToUrl(ctx context.Context, params GoToUrlAction) (*ActionResult, error)

func (*Controller) InputText

func (c *Controller) InputText(ctx context.Context, params InputTextAction) (*ActionResult, error)

func (*Controller) OpenTab

func (c *Controller) OpenTab(ctx context.Context, params OpenTabAction) (*ActionResult, error)

func (*Controller) SavePdf

func (c *Controller) SavePdf(ctx context.Context, params SavePdfAction) (*ActionResult, error)

func (*Controller) ScrollDown

func (c *Controller) ScrollDown(ctx context.Context, params ScrollDownAction) (*ActionResult, error)

func (*Controller) ScrollToText

func (c *Controller) ScrollToText(ctx context.Context, params ScrollToTextAction) (*ActionResult, error)

func (*Controller) ScrollUp

func (c *Controller) ScrollUp(ctx context.Context, params ScrollUpAction) (*ActionResult, error)

func (*Controller) SearchGoogle

func (c *Controller) SearchGoogle(ctx context.Context, params SearchGoogleAction) (*ActionResult, error)

func (*Controller) SelectDropdownOption

func (c *Controller) SelectDropdownOption(ctx context.Context, params SelectDropdownOptionAction) (*ActionResult, error)

func (*Controller) SendKeys

func (this *Controller) SendKeys(ctx context.Context, params SendKeysAction) (*ActionResult, error)

func (*Controller) SwitchTab

func (c *Controller) SwitchTab(ctx context.Context, params SwitchTabAction) (*ActionResult, error)

func (*Controller) Wait

func (c *Controller) Wait(ctx context.Context, params WaitAction) (*ActionResult, error)

type DoneAction

type DoneAction struct {
	Text    string `json:"text"`
	Success bool   `json:"success"`
}

type DragDropAction

type DragDropAction struct {
	// Element-based approach
	ElementSource       *string   `json:"element_source,omitempty" jsonschema:"anyof_type=string;null,default=null"`
	ElementTarget       *string   `json:"element_target,omitempty" jsonschema:"anyof_type=string;null,default=null"`
	ElementSourceOffset *Position `json:"element_source_offset,omitempty" jsonschema:"anyof_type=object;null,default=null"`
	ElementTargetOffset *Position `json:"element_target_offset,omitempty" jsonschema:"anyof_type=object;null,default=null"`

	// Coordinate-based approach (used if selectors not provided)
	CoordSourceX *int `json:"coord_source_x,omitempty" jsonschema:"anyof_type=integer;null,default=null"`
	CoordSourceY *int `json:"coord_source_y,omitempty" jsonschema:"anyof_type=integer;null,default=null"`
	CoordTargetX *int `json:"coord_target_x,omitempty" jsonschema:"anyof_type=integer;null,default=null"`
	CoordTargetY *int `json:"coord_target_y,omitempty" jsonschema:"anyof_type=integer;null,default=null"`

	// Common options
	Steps   *int `json:"steps,omitempty" jsonschema:"anyof_type=integer;null,default=null"`
	DelayMs *int `json:"delay_ms,omitempty" jsonschema:"anyof_type=integer;null,default=null"`
}

func NewDragDropAction

func NewDragDropAction() *DragDropAction

type ExtractContentAction

type ExtractContentAction struct {
	Goal                string `json:"goal"`
	ShouldStripLinkUrls bool   `json:"should_strip_link_urls"`
}

type ExtractPageContentAction

type ExtractPageContentAction struct {
	Value string `json:"value"`
}

type GetDropdownOptionsAction

type GetDropdownOptionsAction struct {
	Index int `json:"index"`
}

type GoBackAction

type GoBackAction struct {
}

type GoToUrlAction

type GoToUrlAction struct {
	Url string `json:"url"`
}

type GroupTabsAction

type GroupTabsAction struct {
	TabIds []int   `json:"tab_ids"`
	Title  string  `json:"title"`
	Color  *string `json:"color,omitempty" jsonschema:"anyof_type=string;null,default=null"`
}

type InputTextAction

type InputTextAction struct {
	Index int     `json:"index"`
	Text  string  `json:"text"`
	Xpath *string `json:"xpath,omitempty" jsonschema:"anyof_type=string;null,default=null"`
}

type NoParamsAction

type NoParamsAction struct {
}

func (NoParamsAction) IgnoreAllInputs

func (NoParamsAction) IgnoreAllInputs(values map[string]interface{}) *NoParamsAction

type OpenTabAction

type OpenTabAction struct {
	Url string `json:"url"`
}

type Position

type Position struct {
	X int `json:"x"`
	Y int `json:"y"`
}

type RegisteredAction

type RegisteredAction struct {
	Tool *tool.InvokableTool
	// filters: provide specific domains or a function to determine whether the action should be available on the given page or not
	Domains    []string // # e.g. ['*.google.com', 'www.bing.com', 'yahoo.*]
	PageFilter func(playwright.Page) bool
}

func NewRegisteredAction

func NewRegisteredAction[T, D any](
	name string,
	description string,
	actionFunc einoUtils.InvokeFunc[T, D],
	domains []string,
	pageFilter func(playwright.Page) bool,
) (*RegisteredAction, error)

func (*RegisteredAction) PromptDescription

func (ra *RegisteredAction) PromptDescription() string
example

----------------- INPUT ------------------------------ description: "Search for text" name: "search" param_model:

class SearchParams(BaseModel):
	query: str
	case_sensitive: bool

{
    "query": {"type": "string", "title": "검색어"},
    "case_sensitive": {"type": "boolean", "title": "대소문자 구분"}
}

----------------- OUTPUT ------------------------------ Search for text: {search: {'query': {'type': 'string'}, 'case_sensitive': {'type': 'boolean'}}}

type Registry

type Registry struct {
	Registry       *ActionRegistry
	ExcludeActions []string
}

The main service class that manages action registration and execution

func NewRegistry

func NewRegistry() *Registry

func (*Registry) CreateActionModel

func (r *Registry) CreateActionModel(includeActions []string, page playwright.Page) *ActionModel

func (*Registry) ExecuteAction

func (r *Registry) ExecuteAction(
	actionName string,
	argumentsInJson string,
	browser *browser.BrowserContext,
	pageExtractionLlm model.ToolCallingChatModel,
	sensitiveData map[string]string,
	availableFilePaths []string,
) (string, error)

Execute a registered action TODO(LOW): support Context

func (*Registry) GetPromptDescription

func (r *Registry) GetPromptDescription(page playwright.Page) string

type SavePdfAction

type SavePdfAction struct {
}

type ScrollDownAction

type ScrollDownAction struct {
	Amount *int `json:"amount,omitempty" jsonschema:"anyof_type=integer;null,default=null"`
}

type ScrollToTextAction

type ScrollToTextAction struct {
	Text string `json:"text"`
}

type ScrollUpAction

type ScrollUpAction struct {
	Amount *int `json:"amount,omitempty" jsonschema:"anyof_type=integer;null,default=null"`
}

type SearchGoogleAction

type SearchGoogleAction struct {
	Query string `json:"query"`
}

Action Input Models

type SelectDropdownOptionAction

type SelectDropdownOptionAction struct {
	Index int    `json:"index"`
	Text  string `json:"text"`
}

type SendKeysAction

type SendKeysAction struct {
	Keys string `json:"keys"`
}

type SwitchTabAction

type SwitchTabAction struct {
	PageId int `json:"page_id"`
}

type UngroupTabsAction

type UngroupTabsAction struct {
	TabIds []int `json:"tab_ids"`
}

type WaitAction

type WaitAction struct {
	Seconds int `json:"seconds"`
}

Jump to

Keyboard shortcuts

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