| 1 | import { resolveRelativePathInDir } from "core/util/ideUtils"; |
| 2 | import { v4 as uuid } from "uuid"; |
| 3 | import { ClientToolImpl } from "./callClientTool"; |
| 4 | export const editToolImpl: ClientToolImpl = async ( |
| 5 | args, |
| 6 | toolCallId, |
| 7 | extras, |
| 8 | ) => { |
| 9 | const firstUriMatch = await resolveRelativePathInDir( |
| 10 | args.filepath, |
| 11 | extras.ideMessenger.ide, |
| 12 | ); |
| 13 | if (!firstUriMatch) { |
| 14 | throw new Error(`${args.filepath} does not exist`); |
| 15 | } |
| 16 | const streamId = uuid(); |
| 17 | extras.ideMessenger.post("applyToFile", { |
| 18 | streamId, |
| 19 | text: args.changes, |
| 20 | toolCallId, |
| 21 | filepath: firstUriMatch, |
| 22 | }); |
| 23 | |
| 24 | return { |
| 25 | respondImmediately: false, |
| 26 | output: undefined, // No immediate output. |
| 27 | }; |
| 28 | }; |