Elffuss BraidHub

kikocis/continue public

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