49 lines
1.0 KiB
Go
49 lines
1.0 KiB
Go
package tools
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
"net/http"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
func RegisterBuiltins(r *Registry) {
|
|
r.Register(&Tool{
|
|
Name: "web_fetch",
|
|
Description: "Fetch content from a URL",
|
|
Parameters: []Param{
|
|
{Name: "url", Type: "string", Required: true, Description: "URL to fetch"},
|
|
},
|
|
Execute: webFetch,
|
|
})
|
|
|
|
r.Register(&Tool{
|
|
Name: "web_search",
|
|
Description: "Search the web for information",
|
|
Parameters: []Param{
|
|
{Name: "query", Type: "string", Required: true, Description: "search query"},
|
|
},
|
|
Execute: webSearch,
|
|
})
|
|
}
|
|
|
|
func webFetch(ctx context.Context, args string) (string, error) {
|
|
client := &http.Client{Timeout: 30 * time.Second}
|
|
resp, err := client.Get(strings.TrimSpace(args))
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
defer resp.Body.Close()
|
|
|
|
body, err := io.ReadAll(resp.Body)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return string(body), nil
|
|
}
|
|
|
|
func webSearch(ctx context.Context, args string) (string, error) {
|
|
return "Web search not yet implemented. Query: " + args, nil
|
|
}
|