Elffuss BraidHub

kikocis/continue public

2ff6e1c400a1 · 1.3 KiBRawPermalink
1import { resolveRelativePathInDir } from "core/util/ideUtils";
2import { ClientToolImpl } from "./callClientTool";
3
4export const editToolImpl: ClientToolImpl = async (
5 args,
6 toolCallId,
7 extras,
8) => {
9 if (!extras.streamId) {
10 throw new Error("Invalid apply state");
11 }
12 const firstUriMatch = await resolveRelativePathInDir(
13 args.filepath,
14 extras.ideMessenger.ide,
15 );
16 if (!firstUriMatch) {
17 throw new Error(`${args.filepath} does not exist`);
18 }
19 const apply = await extras.ideMessenger.request("applyToFile", {
20 streamId: extras.streamId,
21 text: args.changes,
22 toolCallId,
23 filepath: firstUriMatch,
24 });
25 if (apply.status === "error") {
26 throw new Error(apply.error);
27 }
28 const state = extras.getState();
29 const autoAccept = !!state.config.config.ui?.autoAcceptEditToolDiffs;
30 if (autoAccept) {
31 const out = await extras.ideMessenger.request("acceptDiff", {
32 streamId: extras.streamId,
33 filepath: firstUriMatch,
34 });
35 if (out.status === "error") {
36 throw new Error(out.error);
37 }
38 return {
39 respondImmediately: true,
40 output: undefined, // TODO - feed edit results back to model (also in parallel listeners)
41 };
42 }
43 return {
44 respondImmediately: false,
45 output: undefined, // No immediate output.
46 };
47};