| 1 | import { Tool } from "../.."; |
| 2 | import { EDIT_CODE_INSTRUCTIONS } from "../../llm/defaultSystemMessages"; |
| 3 | import { BUILT_IN_GROUP_NAME, BuiltInToolNames } from "../builtIn"; |
| 4 | |
| 5 | export interface EditToolArgs { |
| 6 | filepath: string; |
| 7 | changes: string; |
| 8 | } |
| 9 | |
| 10 | export const editFileTool: Tool = { |
| 11 | type: "function", |
| 12 | displayTitle: "Edit File", |
| 13 | wouldLikeTo: "edit {{{ filepath }}}", |
| 14 | isCurrently: "editing {{{ filepath }}}", |
| 15 | hasAlready: "edited {{{ filepath }}}", |
| 16 | group: BUILT_IN_GROUP_NAME, |
| 17 | readonly: false, |
| 18 | isInstant: false, |
| 19 | function: { |
| 20 | name: BuiltInToolNames.EditExistingFile, |
| 21 | description: `Use this tool to edit an existing file. If you don't know the contents of the file, read it first.\n${EDIT_CODE_INSTRUCTIONS}`, |
| 22 | parameters: { |
| 23 | type: "object", |
| 24 | required: ["filepath", "changes"], |
| 25 | properties: { |
| 26 | filepath: { |
| 27 | type: "string", |
| 28 | description: |
| 29 | "The path of the file to edit, relative to the root of the workspace.", |
| 30 | }, |
| 31 | changes: { |
| 32 | type: "string", |
| 33 | description: |
| 34 | "Any modifications to the file, showing only needed changes. Do NOT wrap this in a codeblock or write anything besides the code changes. In larger files, use brief language-appropriate placeholders for large unmodified sections, e.g. '// ... existing code ...'", |
| 35 | }, |
| 36 | }, |
| 37 | }, |
| 38 | }, |
| 39 | }; |