Documentation
¶
Overview ¶
Package automation is the protocol between the nsgo tool and an app `nsgo dev -automation` built: the tool sends a Request and the app's agent (package nsgotest) answers it. Tool and app come from one module version, so the protocol is internal and unversioned; MCP (`nsgo mcp`) and nsgotest are the public interfaces (docs/architecture/tool.md, Automation).
Index ¶
- Constants
- Variables
- func ValidateAppTool(tool AppTool) error
- type AlertInfo
- type AlertParams
- type AlertResult
- type Answer
- type AppTool
- type Code
- type DragParams
- type Element
- type Error
- type FindParams
- type FindResult
- type HoverParams
- type KeyParams
- type LogsParams
- type LogsResult
- type MenuParams
- type Point
- type PressParams
- type ReloadParams
- type Request
- type ScreenshotParams
- type ScreenshotResult
- type ScrollParams
- type SnapshotParams
- type SnapshotResult
- type StatusParams
- type StatusResult
- type StepResult
- type TypeParams
- type WaitParams
- type Window
- type WindowsParams
- type WindowsResult
Constants ¶
const ( Windows = "windows" Snapshot = "snapshot" Find = "find" Press = "press" Type = "type" Key = "key" Scroll = "scroll" Drag = "drag" Hover = "hover" Menu = "menu" Alert = "alert" Wait = "wait" Screenshot = "screenshot" )
The app's methods, which its agent answers.
const ( Status = "status" Logs = "logs" Reload = "reload" )
The tool's methods, which nsgo dev answers itself.
const AppToolListTimeout = 250 * time.Millisecond
AppToolListTimeout bounds discovery while the graph is busy.
const ListAppTools = "_nsgo/list-app-tools"
ListAppTools asks for the running graph's app-defined tools.
Variables ¶
var ( ErrUnknownAppTool = errors.New("automation: unknown app tool") ErrAppToolInput = errors.New("automation: expected a JSON object") )
var Params = map[string]func() any{ Windows: func() any { return &WindowsParams{} }, Snapshot: func() any { return &SnapshotParams{} }, Find: func() any { return &FindParams{} }, Press: func() any { return &PressParams{} }, Type: func() any { return &TypeParams{} }, Key: func() any { return &KeyParams{} }, Scroll: func() any { return &ScrollParams{} }, Drag: func() any { return &DragParams{} }, Hover: func() any { return &HoverParams{} }, Menu: func() any { return &MenuParams{} }, Alert: func() any { return &AlertParams{} }, Wait: func() any { return &WaitParams{} }, Screenshot: func() any { return &ScreenshotParams{} }, Status: func() any { return &StatusParams{} }, Logs: func() any { return &LogsParams{} }, Reload: func() any { return &ReloadParams{} }, }
Params are each method's params type, as a new value.
Functions ¶
func ValidateAppTool ¶
ValidateAppTool checks the published name and the MCP input shape.
Types ¶
type AlertInfo ¶
type AlertInfo struct {
ID uint32 `json:"id"`
Window uint32 `json:"window"`
Title string `json:"title,omitempty"`
Message string `json:"message,omitempty"`
Buttons []string `json:"buttons"`
}
AlertInfo is an alert showing, which a window or an app's own surface (window 0 for the first graph) shows.
type AlertParams ¶
type AlertParams struct {
Window *uint32 `` /* 128-byte string literal not displayed */
ID uint32 `` /* 147-byte string literal not displayed */
Answer *int `json:"answer,omitempty" jsonschema:"press the button at this index, or -1 to dismiss; without it the alerts are listed"`
}
AlertParams list the alerts showing, or answer one.
type AlertResult ¶
type AlertResult struct {
Alerts []AlertInfo `json:"alerts"`
}
AlertResult lists the alerts showing, oldest first, after any answer.
type Answer ¶
type Answer struct {
ID uint64 `json:"id"`
Result json.RawMessage `json:"result,omitempty"`
Error *Error `json:"error,omitempty"`
}
Answer answers the Request of its ID with Result, one of the result types below, or Error.
type AppTool ¶
type AppTool struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
InputSchema json.RawMessage `json:"inputSchema"`
}
AppTool is the published description of a tool the app registered.
type Code ¶
type Code string
Code says what kind of failure an Error is.
const ( // InvalidRequest is a request that cannot be read: bad JSON, a bad selector, a button the alert lacks. InvalidRequest Code = "invalid_request" // UnknownMethod names no method. UnknownMethod Code = "unknown_method" // NoApp is a request no app connected to answer, or whose app went away. NoApp Code = "no_app" // NoWindow names no window the app shows. NoWindow Code = "no_window" // NoMatch is a selector or a menu path that matches nothing shown. NoMatch Code = "no_match" // Unsupported is what the platform cannot do, such as screenshots headless. Unsupported Code = "unsupported" // Timeout is a wait that ran out of time. Timeout Code = "timeout" // Failed is a step that could not be taken, such as a press on a disabled view. Failed Code = "failed" )
type DragParams ¶
type DragParams struct {
Window uint32 `json:"window,omitempty" jsonschema:"a window ID as windows lists it; the newest window by default"`
Selector string `` /* 203-byte string literal not displayed */
At *Point `json:"at,omitempty" jsonschema:"start at this point of the match, in its own points, instead of its middle"`
Path []Point `json:"path" jsonschema:"the points to move through, as offsets from where the drag starts"`
Snapshot bool `json:"snapshot,omitempty" jsonschema:"answer with the window's snapshot after the step"`
}
DragParams drag from what a selector names.
type Element ¶
type Element struct {
// Ref is a selector naming the view alone, view:<node>, until the app starts again.
Ref string `json:"ref"`
Role string `json:"role"`
Name string `json:"name,omitempty"`
Text string `json:"text,omitempty"`
Value string `json:"value,omitempty"`
TestID string `json:"test_id,omitempty"`
States []string `json:"states,omitempty"`
// Bounds are its frame in the window's points: x, y, width, height.
Bounds *[4]float64 `json:"bounds,omitempty"`
}
Element is a view a selector matched.
type Error ¶
Error is why a request failed.
type FindParams ¶
type FindParams struct {
Window uint32 `json:"window,omitempty" jsonschema:"a window ID as windows lists it; the newest window by default"`
Selector string `` /* 203-byte string literal not displayed */
Mounted bool `json:"mounted,omitempty" jsonschema:"match every view mounted, shown or not"`
}
FindParams list the elements a selector matches.
type FindResult ¶
type FindResult struct {
Elements []Element `json:"elements"`
}
FindResult lists what a selector matched, in the order a user finds it.
type HoverParams ¶
type HoverParams struct {
Window uint32 `json:"window,omitempty" jsonschema:"a window ID as windows lists it; the newest window by default"`
Selector string `` /* 203-byte string literal not displayed */
Snapshot bool `json:"snapshot,omitempty" jsonschema:"answer with the window's snapshot after the step"`
}
HoverParams move the mouse over what a selector names.
type KeyParams ¶
type KeyParams struct {
Window uint32 `json:"window,omitempty" jsonschema:"a window ID as windows lists it; the newest window by default"`
Selector string `` /* 126-byte string literal not displayed */
Key string `` /* 128-byte string literal not displayed */
Snapshot bool `json:"snapshot,omitempty" jsonschema:"answer with the window's snapshot after the step"`
}
KeyParams press a key.
type LogsParams ¶
type LogsParams struct {
Lines int `json:"lines,omitempty" jsonschema:"how many of the latest lines; 200 by default, 2000 at most"`
}
LogsParams read the app's latest output.
type LogsResult ¶
type LogsResult struct {
Lines []string `json:"lines"`
}
LogsResult is the app's latest output, oldest line first.
type MenuParams ¶
type MenuParams struct {
Window uint32 `json:"window,omitempty" jsonschema:"a window ID as windows lists it; the newest window by default"`
Path []string `json:"path" jsonschema:"the item's labels from the menu bar down, such as File, New"`
Popup bool `json:"popup,omitempty" jsonschema:"choose in the context menu showing instead of the application menu"`
Dock bool `` /* 221-byte string literal not displayed */
Snapshot bool `json:"snapshot,omitempty" jsonschema:"answer with the window's snapshot after the step"`
}
MenuParams choose a menu item.
type PressParams ¶
type PressParams struct {
Window uint32 `json:"window,omitempty" jsonschema:"a window ID as windows lists it; the newest window by default"`
Selector string `` /* 203-byte string literal not displayed */
At *Point `json:"at,omitempty" jsonschema:"press this point of the match, in its own points, instead of its middle"`
Mode string `json:"mode,omitempty" jsonschema:"tap (the default), long or right"`
Snapshot bool `json:"snapshot,omitempty" jsonschema:"answer with the window's snapshot after the step"`
}
PressParams press what a selector names.
type Request ¶
type Request struct {
ID uint64 `json:"id"`
Method string `json:"method"`
Params json.RawMessage `json:"params,omitempty"`
}
Request asks the app, or the tool for Status, Logs and Reload, to do Method with Params, one of the params types below.
type ScreenshotParams ¶
type ScreenshotParams struct {
Window uint32 `json:"window,omitempty" jsonschema:"a window ID as windows lists it; the newest window by default"`
}
ScreenshotParams capture a window.
type ScreenshotResult ¶
type ScreenshotResult struct {
PNG []byte `json:"png"`
Width int `json:"width"`
Height int `json:"height"`
}
ScreenshotResult is a window as a PNG, in pixels.
type ScrollParams ¶
type ScrollParams struct {
Window uint32 `json:"window,omitempty" jsonschema:"a window ID as windows lists it; the newest window by default"`
Selector string `` /* 203-byte string literal not displayed */
By float64 `json:"by,omitempty" jsonschema:"points to scroll along the view's axis; positive shows what is further down or right"`
To *float64 `json:"to,omitempty" jsonschema:"the offset to scroll to along the view's axis, instead of by"`
Snapshot bool `json:"snapshot,omitempty" jsonschema:"answer with the window's snapshot after the step"`
}
ScrollParams scroll the scroll view a selector names, or the one around it.
type SnapshotParams ¶
type SnapshotParams struct {
Window uint32 `json:"window,omitempty" jsonschema:"a window ID as windows lists it; the newest window by default"`
All bool `json:"all,omitempty" jsonschema:"list every view shown, containers too, not only the named ones"`
Bounds bool `json:"bounds,omitempty" jsonschema:"add each element's frame in the window's points"`
}
SnapshotParams outline what a window shows.
type SnapshotResult ¶
SnapshotResult outlines what a window shows, an element a line: `- button "Add" [view:12] id=add focused`.
type StatusResult ¶
type StatusResult struct {
Target string `json:"target"`
Building bool `json:"building"`
BuildError string `json:"build_error,omitempty"`
// App is whether a running app is connected; Run counts the apps that connected, and view refs of an earlier run are stale.
App bool `json:"app"`
Run int `json:"run"`
}
StatusResult is how the app's build and run stand.
type StepResult ¶
type StepResult struct {
Settled bool `json:"settled"`
Snapshot string `json:"snapshot,omitempty"`
}
StepResult is what a step left: Settled is false when the app kept changing past the step's wait of 5 seconds.
type TypeParams ¶
type TypeParams struct {
Window uint32 `json:"window,omitempty" jsonschema:"a window ID as windows lists it; the newest window by default"`
Selector string `` /* 203-byte string literal not displayed */
Text string `json:"text,omitempty" jsonschema:"what to type at the end of the field's text"`
Clear bool `json:"clear,omitempty" jsonschema:"empty the field first"`
Submit bool `json:"submit,omitempty" jsonschema:"press Return after typing"`
Snapshot bool `json:"snapshot,omitempty" jsonschema:"answer with the window's snapshot after the step"`
}
TypeParams type into the field a selector names.
type WaitParams ¶
type WaitParams struct {
Window uint32 `json:"window,omitempty" jsonschema:"a window ID as windows lists it; the newest window by default"`
Selector string `` /* 203-byte string literal not displayed */
Gone bool `json:"gone,omitempty" jsonschema:"wait until nothing matches instead"`
TimeoutMS int `json:"timeout_ms,omitempty" jsonschema:"how long to wait in milliseconds; 5000 by default, 60000 at most"`
}
WaitParams wait until a selector matches, or matches nothing.
type Window ¶
type Window struct {
ID uint32 `json:"id"`
// Graph numbers the engine's reactive graph within the process, from 1, telling apart surfaces of several engines in one host.
Graph int `json:"graph,omitempty"`
Title string `json:"title"`
Kind string `json:"kind"`
Width float64 `json:"width"`
Height float64 `json:"height"`
// Default is the window requests without a window act on.
Default bool `json:"default,omitempty"`
}
Window is a window or embedded view the process shows.
type WindowsResult ¶
type WindowsResult struct {
Windows []Window `json:"windows"`
}
WindowsResult lists the app's windows, oldest first.