continue-custom/core/tools/implementations/readFile.ts
2024-12-18 23:05:06 -08:00

26 lines
660 B
TypeScript

import { resolveRelativePathInDir } from "../../util/ideUtils";
import { getUriPathBasename } from "../../util/uri";
import { ToolImpl } from ".";
export const readFileImpl: ToolImpl = async (args, extras) => {
const firstUriMatch = await resolveRelativePathInDir(
args.filepath,
extras.ide,
);
if (!firstUriMatch) {
throw new Error(`Could not find file ${args.filepath}`);
}
const content = await extras.ide.readFile(firstUriMatch);
return [
{
name: getUriPathBasename(args.filepath),
description: args.filepath,
content,
uri: {
type: "file",
value: firstUriMatch,
},
},
];
};