Elffuss BraidHub

kikocis/continue public

cfc91aa76b54 · 915 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(`Could not find file ${filepath}`);
14 }
15 const content = await extras.ide.readFile(firstUriMatch);
16
17 await throwIfFileExceedsHalfOfContext(
18 filepath,
19 content,
20 extras.config.selectedModelByRole.chat,
21 );
22
23 return [
24 {
25 name: getUriPathBasename(firstUriMatch),
26 description: filepath,
27 content,
28 uri: {
29 type: "file",
30 value: firstUriMatch,
31 },
32 },
33 ];
34};