Adjust read_dir description and return value
This commit is contained in:
parent
5ff763ecda
commit
4ae5c5e717
@ -43,16 +43,16 @@ var AvailableTools = map[string]AvailableTool{
|
|||||||
|
|
||||||
Results are returned as JSON in the following format:
|
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": [
|
"result": [
|
||||||
{"name": "a_file", "type": "file", "length": 123},
|
{"name": "a_file", "type": "file", "size": 123},
|
||||||
{"name": "a_directory", "type": "dir", "length": 5},
|
{"name": "a_directory/", "type": "dir", "size": 11},
|
||||||
... // more files or directories
|
... // more files or directories
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
For type: file, length represents the size (in bytes) of the file.
|
For files, size represents the size (in bytes) of the file.
|
||||||
For type: dir, length represents the number of entries in that directory.`,
|
For directories, size represents the number of entries in that directory.`,
|
||||||
Parameters: FunctionParameters{
|
Parameters: FunctionParameters{
|
||||||
Type: "object",
|
Type: "object",
|
||||||
Properties: map[string]FunctionParameter{
|
Properties: map[string]FunctionParameter{
|
||||||
@ -205,19 +205,21 @@ func ReadDir(path string) string {
|
|||||||
for _, f := range files {
|
for _, f := range files {
|
||||||
info, _ := f.Info()
|
info, _ := f.Info()
|
||||||
|
|
||||||
contentType := "file"
|
name := f.Name()
|
||||||
length := info.Size()
|
entryType := "file"
|
||||||
|
size := info.Size()
|
||||||
|
|
||||||
if info.IsDir() {
|
if info.IsDir() {
|
||||||
contentType = "dir"
|
name += "/"
|
||||||
|
entryType = "dir"
|
||||||
subdirfiles, _ := os.ReadDir(filepath.Join(".", path, info.Name()))
|
subdirfiles, _ := os.ReadDir(filepath.Join(".", path, info.Name()))
|
||||||
length = int64(len(subdirfiles))
|
size = int64(len(subdirfiles))
|
||||||
}
|
}
|
||||||
|
|
||||||
dirContents = append(dirContents, map[string]interface{}{
|
dirContents = append(dirContents, map[string]interface{}{
|
||||||
"name": f.Name(),
|
"name": name,
|
||||||
"type": contentType,
|
"type": entryType,
|
||||||
"length": length,
|
"size": size,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user