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
41 lines
814 B
Go
41 lines
814 B
Go
package cmd
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"browseros-cli/output"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
func init() {
|
|
cmd := &cobra.Command{
|
|
Use: "eval <expression>",
|
|
Annotations: map[string]string{"group": "Observe:"},
|
|
Short: "Execute JavaScript in the page context",
|
|
Args: cobra.MinimumNArgs(1),
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
expression := strings.Join(args, " ")
|
|
c := newClient()
|
|
pageID, err := resolvePageID(c)
|
|
if err != nil {
|
|
output.Error(err.Error(), 2)
|
|
}
|
|
result, err := c.CallTool("evaluate_script", map[string]any{
|
|
"page": pageID,
|
|
"expression": expression,
|
|
})
|
|
if err != nil {
|
|
output.Error(err.Error(), 1)
|
|
}
|
|
if jsonOut {
|
|
output.JSON(result)
|
|
} else {
|
|
output.Text(result)
|
|
}
|
|
},
|
|
}
|
|
|
|
rootCmd.AddCommand(cmd)
|
|
}
|