continue-custom/gui/src/util/clientTools/editImpl.ts
2025-08-20 23:23:16 -07:00

51 lines
1.3 KiB
TypeScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { resolveRelativePathInDir } from "core/util/ideUtils";
import { v4 as uuid } from "uuid";
import { updateApplyState } from "../../redux/slices/sessionSlice";
import { handleEditToolApplyError } from "../../redux/thunks/handleApplyStateUpdate";
import { ClientToolImpl } from "./callClientTool";
export const editToolImpl: ClientToolImpl = async (
args,
toolCallId,
extras,
) => {
if (!args.filepath || !args.changes) {
throw new Error(
"`filepath` and `changes` arguments are required to edit an existing file.",
);
}
const firstUriMatch = await resolveRelativePathInDir(
args.filepath,
extras.ideMessenger.ide,
);
if (!firstUriMatch) {
throw new Error(`${args.filepath} does not exist`);
}
const streamId = uuid();
extras.dispatch(
updateApplyState({
streamId,
toolCallId,
status: "not-started",
}),
);
void extras.ideMessenger
.request("applyToFile", {
streamId,
text: args.changes,
toolCallId,
filepath: firstUriMatch,
})
.then((res) => {
if (res.status === "error") {
void extras.dispatch(
handleEditToolApplyError({
toolCallId,
}),
);
}
});
return {
respondImmediately: false,
output: undefined, // No immediate output.
};
};