summaryrefslogtreecommitdiffhomepage
path: root/internal/llm/tools/fetch.go
diff options
context:
space:
mode:
authorKujtim Hoxha <[email protected]>2025-04-08 19:15:23 +0200
committerKujtim Hoxha <[email protected]>2025-04-08 19:15:23 +0200
commit94923948e1a1525988bf13025a10cc9226652684 (patch)
tree91d6b5b78b6af47a7272e92b54386eee42f21e50 /internal/llm/tools/fetch.go
parent5acf0cba6040aaf90acb5dcacd3e4127d6833ac5 (diff)
downloadopencode-94923948e1a1525988bf13025a10cc9226652684.tar.gz
opencode-94923948e1a1525988bf13025a10cc9226652684.zip
structure tools the same
- add some tests - fix some tests - change how we handle permissions
Diffstat (limited to 'internal/llm/tools/fetch.go')
-rw-r--r--internal/llm/tools/fetch.go39
1 files changed, 20 insertions, 19 deletions
diff --git a/internal/llm/tools/fetch.go b/internal/llm/tools/fetch.go
index 0a852626c..5ea0c7633 100644
--- a/internal/llm/tools/fetch.go
+++ b/internal/llm/tools/fetch.go
@@ -15,6 +15,23 @@ import (
"github.com/kujtimiihoxha/termai/internal/permission"
)
+type FetchParams struct {
+ URL string `json:"url"`
+ Format string `json:"format"`
+ Timeout int `json:"timeout,omitempty"`
+}
+
+type FetchPermissionsParams struct {
+ URL string `json:"url"`
+ Format string `json:"format"`
+ Timeout int `json:"timeout,omitempty"`
+}
+
+type fetchTool struct {
+ client *http.Client
+ permissions permission.Service
+}
+
const (
FetchToolName = "fetch"
fetchToolDescription = `Fetches content from a URL and returns it in the specified format.
@@ -48,27 +65,12 @@ TIPS:
- Set appropriate timeouts for potentially slow websites`
)
-type FetchParams struct {
- URL string `json:"url"`
- Format string `json:"format"`
- Timeout int `json:"timeout,omitempty"`
-}
-
-type FetchPermissionsParams struct {
- URL string `json:"url"`
- Format string `json:"format"`
- Timeout int `json:"timeout,omitempty"`
-}
-
-type fetchTool struct {
- client *http.Client
-}
-
-func NewFetchTool() BaseTool {
+func NewFetchTool(permissions permission.Service) BaseTool {
return &fetchTool{
client: &http.Client{
Timeout: 30 * time.Second,
},
+ permissions: permissions,
}
}
@@ -113,7 +115,7 @@ func (t *fetchTool) Run(ctx context.Context, call ToolCall) (ToolResponse, error
return NewTextErrorResponse("URL must start with http:// or https://"), nil
}
- p := permission.Default.Request(
+ p := t.permissions.Request(
permission.CreatePermissionRequest{
Path: config.WorkingDirectory(),
ToolName: FetchToolName,
@@ -220,4 +222,3 @@ func convertHTMLToMarkdown(html string) (string, error) {
return markdown, nil
}
-