mirror of
https://github.com/browseros-ai/BrowserOS.git
synced 2026-05-13 23:53:25 +00:00
git-subtree-dir: packages/browseros-agent git-subtree-mainline:8f148d0918git-subtree-split:90bd4be300
86 lines
2.0 KiB
Go
86 lines
2.0 KiB
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"browseros-cli/output"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
func init() {
|
|
fillCmd := &cobra.Command{
|
|
Use: "fill <element> <text>",
|
|
Annotations: map[string]string{"group": "Input:"},
|
|
Short: "Type text into an input element",
|
|
Args: cobra.MinimumNArgs(2),
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
var element int
|
|
if _, err := fmt.Sscanf(args[0], "%d", &element); err != nil {
|
|
output.Errorf(3, "invalid element ID: %s", args[0])
|
|
}
|
|
text := strings.Join(args[1:], " ")
|
|
noClear, _ := cmd.Flags().GetBool("no-clear")
|
|
|
|
c := newClient()
|
|
pageID, err := resolvePageID(c)
|
|
if err != nil {
|
|
output.Error(err.Error(), 2)
|
|
}
|
|
|
|
result, err := c.CallTool("fill", map[string]any{
|
|
"page": pageID,
|
|
"element": element,
|
|
"text": text,
|
|
"clear": !noClear,
|
|
})
|
|
if err != nil {
|
|
output.Error(err.Error(), 1)
|
|
}
|
|
if jsonOut {
|
|
output.JSON(result)
|
|
} else {
|
|
output.Confirm(result.TextContent())
|
|
}
|
|
},
|
|
}
|
|
fillCmd.Flags().Bool("no-clear", false, "Don't clear existing text before typing")
|
|
|
|
clearCmd := &cobra.Command{
|
|
Use: "clear <element>",
|
|
Annotations: map[string]string{"group": "Input:"},
|
|
Short: "Clear text content of an input element",
|
|
Args: cobra.ExactArgs(1),
|
|
Run: elementAction("clear"),
|
|
}
|
|
|
|
keyCmd := &cobra.Command{
|
|
Use: "key <key>",
|
|
Annotations: map[string]string{"group": "Input:"},
|
|
Short: "Press a key or key combination (e.g., Enter, Control+A)",
|
|
Args: cobra.ExactArgs(1),
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
c := newClient()
|
|
pageID, err := resolvePageID(c)
|
|
if err != nil {
|
|
output.Error(err.Error(), 2)
|
|
}
|
|
result, err := c.CallTool("press_key", map[string]any{
|
|
"page": pageID,
|
|
"key": args[0],
|
|
})
|
|
if err != nil {
|
|
output.Error(err.Error(), 1)
|
|
}
|
|
if jsonOut {
|
|
output.JSON(result)
|
|
} else {
|
|
output.Confirm(result.TextContent())
|
|
}
|
|
},
|
|
}
|
|
|
|
rootCmd.AddCommand(fillCmd, clearCmd, keyCmd)
|
|
}
|