Elffuss BraidHub

kikocis/continue public

93a8eb04e36c · 979 BRawPermalink
1import { resolveRelativePathInDir } from "../../util/ideUtils";
2import { getUriPathBasename } from "../../util/uri";
3
4import { ToolImpl } from ".";
5import { getStringArg } from "../parseArgs";
6import { throwIfFileExceedsHalfOfContext } from "./readFileLimit";
7
8export const readFileImpl: ToolImpl = async (args, extras) => {
9 const filepath = getStringArg(args, "filepath");
10
11 const firstUriMatch = await resolveRelativePathInDir(filepath, extras.ide);
12 if (!firstUriMatch) {
13 throw new Error(
14 `File "${filepath}" does not exist. You might want to check the path and try again.`,
15 );
16 }
17 const content = await extras.ide.readFile(firstUriMatch);
18
19 await throwIfFileExceedsHalfOfContext(
20 filepath,
21 content,
22 extras.config.selectedModelByRole.chat,
23 );
24
25 return [
26 {
27 name: getUriPathBasename(firstUriMatch),
28 description: filepath,
29 content,
30 uri: {
31 type: "file",
32 value: firstUriMatch,
33 },
34 },
35 ];
36};