(athena: Athena)
| 15 | } |
| 16 | |
| 17 | async load(athena: Athena) { |
| 18 | athena.registerTool( |
| 19 | { |
| 20 | name: "fs/list", |
| 21 | desc: "List a directory", |
| 22 | args: { |
| 23 | path: { |
| 24 | type: "string", |
| 25 | desc: "The path to list", |
| 26 | required: true, |
| 27 | }, |
| 28 | }, |
| 29 | retvals: { |
| 30 | content: { |
| 31 | type: "array", |
| 32 | desc: "The content of the directory", |
| 33 | required: true, |
| 34 | of: { |
| 35 | type: "object", |
| 36 | desc: "The file or directory", |
| 37 | required: true, |
| 38 | of: { |
| 39 | name: { |
| 40 | type: "string", |
| 41 | desc: "The name of the file or directory", |
| 42 | required: true, |
| 43 | }, |
| 44 | type: { |
| 45 | type: "string", |
| 46 | desc: "The type of the file or directory", |
| 47 | required: true, |
| 48 | }, |
| 49 | size: { |
| 50 | type: "number", |
| 51 | desc: "The size of the file in bytes", |
| 52 | required: false, |
| 53 | }, |
| 54 | }, |
| 55 | }, |
| 56 | }, |
| 57 | }, |
| 58 | }, |
| 59 | { |
| 60 | fn: async (args: Dict<any>) => { |
| 61 | const content = await fs.readdir(args.path, { withFileTypes: true }); |
| 62 | const ret = []; |
| 63 | for (const entry of content) { |
| 64 | ret.push({ |
| 65 | name: entry.name, |
| 66 | type: entry.isDirectory() ? "directory" : "file", |
| 67 | size: entry.isFile() |
| 68 | ? (await fs.stat(`${args.path}/${entry.name}`)).size |
| 69 | : undefined, |
| 70 | }); |
| 71 | } |
| 72 | return { content: ret }; |
| 73 | }, |
| 74 | explain_args: (args: Dict<any>) => ({ |
nothing calls this directly
no test coverage detected