Elffuss BraidHub

kikocis/continue public

5befb967c92e · 944 BRawPermalink
1import { resolveRelativePathInDir } from "core/util/ideUtils";
2import { v4 as uuid } from "uuid";
3import { applyForEditTool } from "../../redux/thunks/handleApplyStateUpdate";
4import { ClientToolImpl } from "./callClientTool";
5export const editToolImpl: ClientToolImpl = async (
6 args,
7 toolCallId,
8 extras,
9) => {
10 if (!args.filepath || !args.changes) {
11 throw new Error(
12 "`filepath` and `changes` arguments are required to edit an existing file.",
13 );
14 }
15 const firstUriMatch = await resolveRelativePathInDir(
16 args.filepath,
17 extras.ideMessenger.ide,
18 );
19 if (!firstUriMatch) {
20 throw new Error(`${args.filepath} does not exist`);
21 }
22 const streamId = uuid();
23 void extras.dispatch(
24 applyForEditTool({
25 streamId,
26 text: args.changes,
27 toolCallId,
28 filepath: firstUriMatch,
29 }),
30 );
31
32 return {
33 respondImmediately: false,
34 output: undefined, // No immediate output.
35 };
36};