| 1 | import { resolveRelativePathInDir } from "core/util/ideUtils"; |
| 2 | import { ClientToolImpl } from "./callClientTool"; |
| 3 | |
| 4 | export 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 | |
| 29 | return { |
| 30 | respondImmediately: false, |
| 31 | output: undefined, // No immediate output. |
| 32 | }; |
| 33 | }; |