From 94923948e1a1525988bf13025a10cc9226652684 Mon Sep 17 00:00:00 2001 From: Kujtim Hoxha Date: Tue, 8 Apr 2025 19:15:23 +0200 Subject: structure tools the same - add some tests - fix some tests - change how we handle permissions --- internal/llm/tools/fetch.go | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) (limited to 'internal/llm/tools/fetch.go') 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 } - -- cgit v1.2.3