From 4ae5c5e7174ba5b675153407343587b28d329aa2 Mon Sep 17 00:00:00 2001 From: Matt Low Date: Sun, 26 Nov 2023 06:37:54 +0000 Subject: [PATCH] Adjust read_dir description and return value --- pkg/cli/functions.go | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/pkg/cli/functions.go b/pkg/cli/functions.go index 1f46093..ba12bbc 100644 --- a/pkg/cli/functions.go +++ b/pkg/cli/functions.go @@ -43,16 +43,16 @@ var AvailableTools = map[string]AvailableTool{ Results are returned as JSON in the following format: { - "message": "success", // "success" if successful, or a different message indicating failure + "message": "success", // if successful, or a different message indicating failure "result": [ - {"name": "a_file", "type": "file", "length": 123}, - {"name": "a_directory", "type": "dir", "length": 5}, + {"name": "a_file", "type": "file", "size": 123}, + {"name": "a_directory/", "type": "dir", "size": 11}, ... // more files or directories ] } -For type: file, length represents the size (in bytes) of the file. -For type: dir, length represents the number of entries in that directory.`, +For files, size represents the size (in bytes) of the file. +For directories, size represents the number of entries in that directory.`, Parameters: FunctionParameters{ Type: "object", Properties: map[string]FunctionParameter{ @@ -205,19 +205,21 @@ func ReadDir(path string) string { for _, f := range files { info, _ := f.Info() - contentType := "file" - length := info.Size() + name := f.Name() + entryType := "file" + size := info.Size() if info.IsDir() { - contentType = "dir" + name += "/" + entryType = "dir" subdirfiles, _ := os.ReadDir(filepath.Join(".", path, info.Name())) - length = int64(len(subdirfiles)) + size = int64(len(subdirfiles)) } dirContents = append(dirContents, map[string]interface{}{ - "name": f.Name(), - "type": contentType, - "length": length, + "name": name, + "type": entryType, + "size": size, }) }