summaryrefslogtreecommitdiffhomepage
path: root/internal/llm/tools/fetch.go
diff options
context:
space:
mode:
authorKujtim Hoxha <[email protected]>2025-04-21 19:59:35 +0200
committerGitHub <[email protected]>2025-04-21 19:59:35 +0200
commitf33dff87725764af0b675b5e5b2e011b21c14c90 (patch)
tree4fe2c022305f13775f2cab3cdd80cd808259765b /internal/llm/tools/fetch.go
parent6b1c64bcc75b89c530294b6a2d4404682b435d56 (diff)
parent3a6a26981a8074b6ab0eaadb520db986e04799ff (diff)
downloadopencode-f33dff87725764af0b675b5e5b2e011b21c14c90.tar.gz
opencode-f33dff87725764af0b675b5e5b2e011b21c14c90.zip
Merge pull request #27 from kujtimiihoxha/opencode
OpenCode - Initial Implementation
Diffstat (limited to 'internal/llm/tools/fetch.go')
-rw-r--r--internal/llm/tools/fetch.go19
1 files changed, 13 insertions, 6 deletions
diff --git a/internal/llm/tools/fetch.go b/internal/llm/tools/fetch.go
index 19e644281..47ff03e57 100644
--- a/internal/llm/tools/fetch.go
+++ b/internal/llm/tools/fetch.go
@@ -11,8 +11,8 @@ import (
md "github.com/JohannesKaufmann/html-to-markdown"
"github.com/PuerkitoBio/goquery"
- "github.com/kujtimiihoxha/termai/internal/config"
- "github.com/kujtimiihoxha/termai/internal/permission"
+ "github.com/kujtimiihoxha/opencode/internal/config"
+ "github.com/kujtimiihoxha/opencode/internal/permission"
)
type FetchParams struct {
@@ -86,6 +86,7 @@ func (t *fetchTool) Info() ToolInfo {
"format": map[string]any{
"type": "string",
"description": "The format to return the content in (text, markdown, or html)",
+ "enum": []string{"text", "markdown", "html"},
},
"timeout": map[string]any{
"type": "number",
@@ -115,8 +116,14 @@ func (t *fetchTool) Run(ctx context.Context, call ToolCall) (ToolResponse, error
return NewTextErrorResponse("URL must start with http:// or https://"), nil
}
+ sessionID, messageID := GetContextValues(ctx)
+ if sessionID == "" || messageID == "" {
+ return ToolResponse{}, fmt.Errorf("session ID and message ID are required for creating a new file")
+ }
+
p := t.permissions.Request(
permission.CreatePermissionRequest{
+ SessionID: sessionID,
Path: config.WorkingDirectory(),
ToolName: FetchToolName,
Action: "fetch",
@@ -126,7 +133,7 @@ func (t *fetchTool) Run(ctx context.Context, call ToolCall) (ToolResponse, error
)
if !p {
- return NewTextErrorResponse("Permission denied to fetch from URL: " + params.URL), nil
+ return ToolResponse{}, permission.ErrorPermissionDenied
}
client := t.client
@@ -142,14 +149,14 @@ func (t *fetchTool) Run(ctx context.Context, call ToolCall) (ToolResponse, error
req, err := http.NewRequestWithContext(ctx, "GET", params.URL, nil)
if err != nil {
- return NewTextErrorResponse("Failed to create request: " + err.Error()), nil
+ return ToolResponse{}, fmt.Errorf("failed to create request: %w", err)
}
- req.Header.Set("User-Agent", "termai/1.0")
+ req.Header.Set("User-Agent", "opencode/1.0")
resp, err := client.Do(req)
if err != nil {
- return NewTextErrorResponse("Failed to execute request: " + err.Error()), nil
+ return ToolResponse{}, fmt.Errorf("failed to fetch URL: %w", err)
}
defer resp.Body.Close()