| 1 | import { getUriDescription } from "../../util/uri"; |
| 2 | |
| 3 | import { ToolImpl } from "."; |
| 4 | import { throwIfFileExceedsHalfOfContext } from "./readFileLimit"; |
| 5 | |
| 6 | export const readCurrentlyOpenFileImpl: ToolImpl = async (args, extras) => { |
| 7 | const result = await extras.ide.getCurrentFile(); |
| 8 | |
| 9 | if (result) { |
| 10 | await throwIfFileExceedsHalfOfContext( |
| 11 | result.path, |
| 12 | result.contents, |
| 13 | extras.config.selectedModelByRole.chat, |
| 14 | ); |
| 15 | |
| 16 | const { relativePathOrBasename, last2Parts, baseName } = getUriDescription( |
| 17 | result.path, |
| 18 | await extras.ide.getWorkspaceDirs(), |
| 19 | ); |
| 20 | |
| 21 | return [ |
| 22 | { |
| 23 | name: `Current file: ${baseName}`, |
| 24 | description: last2Parts, |
| 25 | content: `\`\`\`${relativePathOrBasename}\n${result.contents}\n\`\`\``, |
| 26 | uri: { |
| 27 | type: "file", |
| 28 | value: result.path, |
| 29 | }, |
| 30 | }, |
| 31 | ]; |
| 32 | } else { |
| 33 | return [ |
| 34 | { |
| 35 | name: `No Current File`, |
| 36 | description: "", |
| 37 | content: "There are no files currently open.", |
| 38 | }, |
| 39 | ]; |
| 40 | } |
| 41 | }; |