| 1 | import { resolveRelativePathInDir } from "../../util/ideUtils"; |
| 2 | import { getUriPathBasename } from "../../util/uri"; |
| 3 | |
| 4 | import { ToolImpl } from "."; |
| 5 | |
| 6 | export const readFileImpl: ToolImpl = async (args, extras) => { |
| 7 | const firstUriMatch = await resolveRelativePathInDir( |
| 8 | args.filepath, |
| 9 | extras.ide, |
| 10 | ); |
| 11 | if (!firstUriMatch) { |
| 12 | throw new Error(`Could not find file ${args.filepath}`); |
| 13 | } |
| 14 | const content = await extras.ide.readFile(firstUriMatch); |
| 15 | return [ |
| 16 | { |
| 17 | name: getUriPathBasename(args.filepath), |
| 18 | description: args.filepath, |
| 19 | content, |
| 20 | uri: { |
| 21 | type: "file", |
| 22 | value: firstUriMatch, |
| 23 | }, |
| 24 | }, |
| 25 | ]; |
| 26 | }; |