Fix (tools): use fs tools
This commit is contained in:
458
tools/tools.go
458
tools/tools.go
@@ -35,7 +35,7 @@ Your current tools:
|
||||
{
|
||||
"name":"run",
|
||||
"args": ["command"],
|
||||
"when_to_use": "Main tool for file operations, shell commands, memory, git, and todo. Use run \"help\" for all commands. Examples: run \"ls -la\", run \"help\", run \"mkdir -p foo/bar\", run \"cat file.txt\", run \"view_img image.png\", run \"git status\", run \"memory store foo bar\", run \"todo create task\", run \"grep pattern file\", run \"cd /path\", run \"pwd\", run \"find . -name *.txt\", run \"file image.png\", run \"head file\", run \"tail file\", run \"wc -l file\", run \"sort file\", run \"uniq file\", run \"sed 's/old/new/' file\", run \"echo text\", run \"go build ./...\", run \"time\", run \"stat file\", run \"cp src dst\", run \"mv src dst\", run \"rm file\""
|
||||
"when_to_use": "Main tool for file operations, shell commands, memory, git, and todo. Use run \"help\" for all commands. Examples: run \"ls -la\", run \"help\", run \"mkdir -p foo/bar\", run \"cat file.txt\", run \"write file.txt content\", run \"view_img image.png\", run \"git status\", run \"memory store foo bar\", run \"todo create task\", run \"grep pattern file\", run \"cd /path\", run \"pwd\", run \"find . -name *.txt\", run \"file image.png\", run \"head file\", run \"tail file\", run \"wc -l file\", run \"sort file\", run \"uniq file\", run \"sed 's/old/new/' file\", run \"echo text\", run \"go build ./...\", run \"time\", run \"stat file\", run \"cp src dst\", run \"mv src dst\", run \"rm file\""
|
||||
},
|
||||
{
|
||||
"name":"view_img",
|
||||
@@ -403,7 +403,7 @@ func runCmd(args map[string]string) []byte {
|
||||
case "browser":
|
||||
// browser <action> [args...] - Playwright browser automation
|
||||
return runBrowserCommand(rest, args)
|
||||
case "mkdir", "ls", "cat", "pwd", "cd", "cp", "mv", "rm", "sed", "grep", "head", "tail", "wc", "sort", "uniq", "echo", "time", "stat", "go", "find", "file":
|
||||
case "mkdir", "ls", "cat", "write", "stat", "pwd", "cd", "cp", "mv", "rm", "sed", "grep", "head", "tail", "wc", "sort", "uniq", "echo", "time", "go", "find", "file":
|
||||
// File operations and shell commands - use ExecChain which has whitelist
|
||||
return executeCommand(args)
|
||||
case "git":
|
||||
@@ -1293,467 +1293,13 @@ func summarizeChat(args map[string]string) []byte {
|
||||
return data
|
||||
}
|
||||
|
||||
// func removePlaywrightToolsFromBaseTools() {
|
||||
// playwrightToolNames := map[string]bool{
|
||||
// "pw_start": true,
|
||||
// "pw_stop": true,
|
||||
// "pw_is_running": true,
|
||||
// "pw_navigate": true,
|
||||
// "pw_click": true,
|
||||
// "pw_click_at": true,
|
||||
// "pw_fill": true,
|
||||
// "pw_extract_text": true,
|
||||
// "pw_screenshot": true,
|
||||
// "pw_screenshot_and_view": true,
|
||||
// "pw_wait_for_selector": true,
|
||||
// "pw_drag": true,
|
||||
// }
|
||||
// var filtered []models.Tool
|
||||
// for _, tool := range BaseTools {
|
||||
// if !playwrightToolNames[tool.Function.Name] {
|
||||
// filtered = append(filtered, tool)
|
||||
// }
|
||||
// }
|
||||
// BaseTools = filtered
|
||||
// delete(FnMap, "pw_start")
|
||||
// delete(FnMap, "pw_stop")
|
||||
// delete(FnMap, "pw_is_running")
|
||||
// delete(FnMap, "pw_navigate")
|
||||
// delete(FnMap, "pw_click")
|
||||
// delete(FnMap, "pw_click_at")
|
||||
// delete(FnMap, "pw_fill")
|
||||
// delete(FnMap, "pw_extract_text")
|
||||
// delete(FnMap, "pw_screenshot")
|
||||
// delete(FnMap, "pw_screenshot_and_view")
|
||||
// delete(FnMap, "pw_wait_for_selector")
|
||||
// delete(FnMap, "pw_drag")
|
||||
// }
|
||||
|
||||
// func (t *Tools) RegisterWindowTools(modelHasVision bool) {
|
||||
// removeWindowToolsFromBaseTools()
|
||||
// if t.WindowToolsAvailable {
|
||||
// FnMap["list_windows"] = listWindows
|
||||
// FnMap["capture_window"] = captureWindow
|
||||
// windowTools := []models.Tool{
|
||||
// {
|
||||
// Type: "function",
|
||||
// Function: models.ToolFunc{
|
||||
// Name: "list_windows",
|
||||
// Description: "List all visible windows with their IDs and names. Returns a map of window ID to window name.",
|
||||
// Parameters: models.ToolFuncParams{
|
||||
// Type: "object",
|
||||
// Required: []string{},
|
||||
// Properties: map[string]models.ToolArgProps{},
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// Type: "function",
|
||||
// Function: models.ToolFunc{
|
||||
// Name: "capture_window",
|
||||
// Description: "Capture a screenshot of a specific window and save it to /tmp. Requires window parameter (window ID or name substring).",
|
||||
// Parameters: models.ToolFuncParams{
|
||||
// Type: "object",
|
||||
// Required: []string{"window"},
|
||||
// Properties: map[string]models.ToolArgProps{
|
||||
// "window": models.ToolArgProps{
|
||||
// Type: "string",
|
||||
// Description: "window ID or window name (partial match)",
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// }
|
||||
// if modelHasVision {
|
||||
// FnMap["capture_window_and_view"] = captureWindowAndView
|
||||
// windowTools = append(windowTools, models.Tool{
|
||||
// Type: "function",
|
||||
// Function: models.ToolFunc{
|
||||
// Name: "capture_window_and_view",
|
||||
// Description: "Capture a screenshot of a specific window, save it to /tmp, and return the image for viewing. Requires window parameter (window ID or name substring).",
|
||||
// Parameters: models.ToolFuncParams{
|
||||
// Type: "object",
|
||||
// Required: []string{"window"},
|
||||
// Properties: map[string]models.ToolArgProps{
|
||||
// "window": models.ToolArgProps{
|
||||
// Type: "string",
|
||||
// Description: "window ID or window name (partial match)",
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// })
|
||||
// }
|
||||
// BaseTools = append(BaseTools, windowTools...)
|
||||
// ToolSysMsg += windowToolSysMsg
|
||||
// }
|
||||
// }
|
||||
|
||||
// for pw agentA
|
||||
// var browserAgentSysPrompt = `You are an autonomous browser automation agent. Your goal is to complete the user's task by intelligently using browser automation
|
||||
|
||||
// Important: The browser may already be running from a previous task! Always check pw_is_running first before starting a new browser.
|
||||
|
||||
// Available tools:
|
||||
// - pw_start: Start browser (only if not already running)
|
||||
// - pw_stop: Stop browser (only when you're truly done and browser is no longer needed)
|
||||
// - pw_is_running: Check if browser is running
|
||||
// - pw_navigate: Go to a URL
|
||||
// - pw_click: Click an element by CSS selector
|
||||
// - pw_fill: Type text into an input
|
||||
// - pw_extract_text: Get text from page/element
|
||||
// - pw_screenshot: Take a screenshot (returns file path)
|
||||
// - pw_screenshot_and_view: Take screenshot with image for viewing
|
||||
// - pw_wait_for_selector: Wait for element to appear
|
||||
// - pw_drag: Drag mouse from one point to another
|
||||
// - pw_click_at: Click at X,Y coordinates
|
||||
// - pw_get_html: Get HTML content
|
||||
// - pw_get_dom: Get structured DOM tree
|
||||
// - pw_search_elements: Search for elements by text or selector
|
||||
|
||||
// Workflow:
|
||||
// 1. First, check if browser is already running (pw_is_running)
|
||||
// 2. Only start browser if not already running (pw_start)
|
||||
// 3. Navigate to required pages (pw_navigate)
|
||||
// 4. Interact with elements as needed (click, fill, etc.)
|
||||
// 5. Extract information or take screenshots as requested
|
||||
// 6. IMPORTANT: Do NOT stop the browser when done! Leave it running so the user can continue interacting with the page in subsequent requests.
|
||||
|
||||
// Always provide clear feedback about what you're doing and what you found.`
|
||||
|
||||
// func (t *Tools) runBrowserAgent(args map[string]string) []byte {
|
||||
// task, ok := args["task"]
|
||||
// if !ok || task == "" {
|
||||
// return []byte(`{"error": "task argument is required"}`)
|
||||
// }
|
||||
// client := t.GetWebAgentClient()
|
||||
// pwAgent := agent.NewPWAgent(client, browserAgentSysPrompt)
|
||||
// pwAgent.SetTools(agent.GetPWTools())
|
||||
// return pwAgent.ProcessTask(task)
|
||||
// }
|
||||
|
||||
// func registerPlaywrightTools() {
|
||||
// removePlaywrightToolsFromBaseTools()
|
||||
// if cfg != nil && cfg.PlaywrightEnabled {
|
||||
// FnMap["pw_start"] = pwStart
|
||||
// FnMap["pw_stop"] = pwStop
|
||||
// FnMap["pw_is_running"] = pwIsRunning
|
||||
// FnMap["pw_navigate"] = pwNavigate
|
||||
// FnMap["pw_click"] = pwClick
|
||||
// FnMap["pw_click_at"] = pwClickAt
|
||||
// FnMap["pw_fill"] = pwFill
|
||||
// FnMap["pw_extract_text"] = pwExtractText
|
||||
// FnMap["pw_screenshot"] = pwScreenshot
|
||||
// FnMap["pw_screenshot_and_view"] = pwScreenshotAndView
|
||||
// FnMap["pw_wait_for_selector"] = pwWaitForSelector
|
||||
// FnMap["pw_drag"] = pwDrag
|
||||
// FnMap["pw_get_html"] = pwGetHTML
|
||||
// FnMap["pw_get_dom"] = pwGetDOM
|
||||
// FnMap["pw_search_elements"] = pwSearchElements
|
||||
// playwrightTools := []models.Tool{
|
||||
// {
|
||||
// Type: "function",
|
||||
// Function: models.ToolFunc{
|
||||
// Name: "pw_start",
|
||||
// Description: "Start a Playwright browser instance. Call this first before using other pw_ Uses headless mode by default (set PlaywrightHeadless=false in config for GUI).",
|
||||
// Parameters: models.ToolFuncParams{
|
||||
// Type: "object",
|
||||
// Required: []string{},
|
||||
// Properties: map[string]models.ToolArgProps{},
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// Type: "function",
|
||||
// Function: models.ToolFunc{
|
||||
// Name: "pw_stop",
|
||||
// Description: "Stop the Playwright browser instance. Call when done with browser automation.",
|
||||
// Parameters: models.ToolFuncParams{
|
||||
// Type: "object",
|
||||
// Required: []string{},
|
||||
// Properties: map[string]models.ToolArgProps{},
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// Type: "function",
|
||||
// Function: models.ToolFunc{
|
||||
// Name: "pw_is_running",
|
||||
// Description: "Check if Playwright browser is currently running.",
|
||||
// Parameters: models.ToolFuncParams{
|
||||
// Type: "object",
|
||||
// Required: []string{},
|
||||
// Properties: map[string]models.ToolArgProps{},
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// Type: "function",
|
||||
// Function: models.ToolFunc{
|
||||
// Name: "pw_navigate",
|
||||
// Description: "Navigate to a URL in the browser.",
|
||||
// Parameters: models.ToolFuncParams{
|
||||
// Type: "object",
|
||||
// Required: []string{"url"},
|
||||
// Properties: map[string]models.ToolArgProps{
|
||||
// "url": models.ToolArgProps{
|
||||
// Type: "string",
|
||||
// Description: "URL to navigate to",
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// Type: "function",
|
||||
// Function: models.ToolFunc{
|
||||
// Name: "pw_click",
|
||||
// Description: "Click on an element using CSS selector. Use 'index' for multiple matches (default 0).",
|
||||
// Parameters: models.ToolFuncParams{
|
||||
// Type: "object",
|
||||
// Required: []string{"selector"},
|
||||
// Properties: map[string]models.ToolArgProps{
|
||||
// "selector": models.ToolArgProps{
|
||||
// Type: "string",
|
||||
// Description: "CSS selector for the element to click",
|
||||
// },
|
||||
// "index": models.ToolArgProps{
|
||||
// Type: "string",
|
||||
// Description: "optional index for multiple matches (default 0)",
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// Type: "function",
|
||||
// Function: models.ToolFunc{
|
||||
// Name: "pw_fill",
|
||||
// Description: "Fill an input field with text using CSS selector.",
|
||||
// Parameters: models.ToolFuncParams{
|
||||
// Type: "object",
|
||||
// Required: []string{"selector", "text"},
|
||||
// Properties: map[string]models.ToolArgProps{
|
||||
// "selector": models.ToolArgProps{
|
||||
// Type: "string",
|
||||
// Description: "CSS selector for the input element",
|
||||
// },
|
||||
// "text": models.ToolArgProps{
|
||||
// Type: "string",
|
||||
// Description: "text to fill into the input",
|
||||
// },
|
||||
// "index": models.ToolArgProps{
|
||||
// Type: "string",
|
||||
// Description: "optional index for multiple matches (default 0)",
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// Type: "function",
|
||||
// Function: models.ToolFunc{
|
||||
// Name: "pw_extract_text",
|
||||
// Description: "Extract text content from the page or specific elements using CSS selector. Use 'body' for all page text.",
|
||||
// Parameters: models.ToolFuncParams{
|
||||
// Type: "object",
|
||||
// Required: []string{"selector"},
|
||||
// Properties: map[string]models.ToolArgProps{
|
||||
// "selector": models.ToolArgProps{
|
||||
// Type: "string",
|
||||
// Description: "CSS selector (use 'body' for all page text)",
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// Type: "function",
|
||||
// Function: models.ToolFunc{
|
||||
// Name: "pw_screenshot",
|
||||
// Description: "Take a screenshot of the page or a specific element. Returns file path to saved image.",
|
||||
// Parameters: models.ToolFuncParams{
|
||||
// Type: "object",
|
||||
// Required: []string{},
|
||||
// Properties: map[string]models.ToolArgProps{
|
||||
// "selector": models.ToolArgProps{
|
||||
// Type: "string",
|
||||
// Description: "optional CSS selector for element to screenshot",
|
||||
// },
|
||||
// "full_page": models.ToolArgProps{
|
||||
// Type: "string",
|
||||
// Description: "optional: 'true' to capture full page (default false)",
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// Type: "function",
|
||||
// Function: models.ToolFunc{
|
||||
// Name: "pw_screenshot_and_view",
|
||||
// Description: "Take a screenshot and return the image for viewing. Use when model needs to see the screenshot.",
|
||||
// Parameters: models.ToolFuncParams{
|
||||
// Type: "object",
|
||||
// Required: []string{},
|
||||
// Properties: map[string]models.ToolArgProps{
|
||||
// "selector": models.ToolArgProps{
|
||||
// Type: "string",
|
||||
// Description: "optional CSS selector for element to screenshot",
|
||||
// },
|
||||
// "full_page": models.ToolArgProps{
|
||||
// Type: "string",
|
||||
// Description: "optional: 'true' to capture full page (default false)",
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// Type: "function",
|
||||
// Function: models.ToolFunc{
|
||||
// Name: "pw_wait_for_selector",
|
||||
// Description: "Wait for an element to appear on the page.",
|
||||
// Parameters: models.ToolFuncParams{
|
||||
// Type: "object",
|
||||
// Required: []string{"selector"},
|
||||
// Properties: map[string]models.ToolArgProps{
|
||||
// "selector": models.ToolArgProps{
|
||||
// Type: "string",
|
||||
// Description: "CSS selector to wait for",
|
||||
// },
|
||||
// "timeout": models.ToolArgProps{
|
||||
// Type: "string",
|
||||
// Description: "optional timeout in ms (default 30000)",
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// Type: "function",
|
||||
// Function: models.ToolFunc{
|
||||
// Name: "pw_drag",
|
||||
// Description: "Drag the mouse from one point to another.",
|
||||
// Parameters: models.ToolFuncParams{
|
||||
// Type: "object",
|
||||
// Required: []string{"x1", "y1", "x2", "y2"},
|
||||
// Properties: map[string]models.ToolArgProps{
|
||||
// "x1": models.ToolArgProps{
|
||||
// Type: "string",
|
||||
// Description: "starting X coordinate",
|
||||
// },
|
||||
// "y1": models.ToolArgProps{
|
||||
// Type: "string",
|
||||
// Description: "starting Y coordinate",
|
||||
// },
|
||||
// "x2": models.ToolArgProps{
|
||||
// Type: "string",
|
||||
// Description: "ending X coordinate",
|
||||
// },
|
||||
// "y2": models.ToolArgProps{
|
||||
// Type: "string",
|
||||
// Description: "ending Y coordinate",
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// Type: "function",
|
||||
// Function: models.ToolFunc{
|
||||
// Name: "pw_get_html",
|
||||
// Description: "Get the HTML content of the page or a specific element.",
|
||||
// Parameters: models.ToolFuncParams{
|
||||
// Type: "object",
|
||||
// Required: []string{},
|
||||
// Properties: map[string]models.ToolArgProps{
|
||||
// "selector": models.ToolArgProps{
|
||||
// Type: "string",
|
||||
// Description: "optional CSS selector (default: body)",
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// Type: "function",
|
||||
// Function: models.ToolFunc{
|
||||
// Name: "pw_get_dom",
|
||||
// Description: "Get a structured DOM representation of an element with tag, attributes, text, and children.",
|
||||
// Parameters: models.ToolFuncParams{
|
||||
// Type: "object",
|
||||
// Required: []string{},
|
||||
// Properties: map[string]models.ToolArgProps{
|
||||
// "selector": models.ToolArgProps{
|
||||
// Type: "string",
|
||||
// Description: "optional CSS selector (default: body)",
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// Type: "function",
|
||||
// Function: models.ToolFunc{
|
||||
// Name: "pw_search_elements",
|
||||
// Description: "Search for elements by text content or CSS selector. Returns matching elements with their tags, text, and HTML.",
|
||||
// Parameters: models.ToolFuncParams{
|
||||
// Type: "object",
|
||||
// Required: []string{},
|
||||
// Properties: map[string]models.ToolArgProps{
|
||||
// "text": models.ToolArgProps{
|
||||
// Type: "string",
|
||||
// Description: "text to search for in elements",
|
||||
// },
|
||||
// "selector": models.ToolArgProps{
|
||||
// Type: "string",
|
||||
// Description: "CSS selector to search for",
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// }
|
||||
// BaseTools = append(BaseTools, playwrightTools...)
|
||||
// ToolSysMsg += browserToolSysMsg
|
||||
// agent.RegisterPWTool("pw_start", pwStart)
|
||||
// agent.RegisterPWTool("pw_stop", pwStop)
|
||||
// agent.RegisterPWTool("pw_is_running", pwIsRunning)
|
||||
// agent.RegisterPWTool("pw_navigate", pwNavigate)
|
||||
// agent.RegisterPWTool("pw_click", pwClick)
|
||||
// agent.RegisterPWTool("pw_click_at", pwClickAt)
|
||||
// agent.RegisterPWTool("pw_fill", pwFill)
|
||||
// agent.RegisterPWTool("pw_extract_text", pwExtractText)
|
||||
// agent.RegisterPWTool("pw_screenshot", pwScreenshot)
|
||||
// agent.RegisterPWTool("pw_screenshot_and_view", pwScreenshotAndView)
|
||||
// agent.RegisterPWTool("pw_wait_for_selector", pwWaitForSelector)
|
||||
// agent.RegisterPWTool("pw_drag", pwDrag)
|
||||
// agent.RegisterPWTool("pw_get_html", pwGetHTML)
|
||||
// agent.RegisterPWTool("pw_get_dom", pwGetDOM)
|
||||
// agent.RegisterPWTool("pw_search_elements", pwSearchElements)
|
||||
// browserAgentTool := []models.Tool{
|
||||
// {
|
||||
// Type: "function",
|
||||
// Function: models.ToolFunc{
|
||||
// Name: "browser_agent",
|
||||
// Description: "Autonomous browser automation agent. Use for complex multi-step browser tasks like 'go to website, login, and take screenshot'. The agent will plan and execute steps automatically using browser ",
|
||||
// Parameters: models.ToolFuncParams{
|
||||
// Type: "object",
|
||||
// Required: []string{"task"},
|
||||
// Properties: map[string]models.ToolArgProps{
|
||||
// "task": {Type: "string", Description: "The task to accomplish, e.g., 'go to github.com and take a screenshot of the homepage'"},
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// }
|
||||
// BaseTools = append(BaseTools, browserAgentTool...)
|
||||
// FnMap["browser_agent"] = tooler.runBrowserAgent
|
||||
// }
|
||||
// }
|
||||
|
||||
func CallToolWithAgent(name string, args map[string]string) ([]byte, bool) {
|
||||
f, ok := FnMap[name]
|
||||
if !ok {
|
||||
|
||||
Reference in New Issue
Block a user