* Adds the createFile function to the codepilot instance.
(codepilot)
| 61 | * Adds the createFile function to the codepilot instance. |
| 62 | */ |
| 63 | function addCreateFile(codepilot) { |
| 64 | codepilot.addFunction(createFileFunction, (args) => __awaiter(this, void 0, void 0, function* () { |
| 65 | const { filePath, contents } = args; |
| 66 | // Check if the file already exists |
| 67 | if (yield fs.access(path.join(process.cwd(), filePath)).then(() => true).catch(() => false)) { |
| 68 | return `A file already exists at that path.\nGive the user detailed instructions for how they should modify that file instead.`; |
| 69 | } |
| 70 | try { |
| 71 | // Create the directory path if it doesn't exist |
| 72 | const directoryPath = path.dirname(filePath); |
| 73 | yield fs.mkdir(directoryPath, { recursive: true }); |
| 74 | // Write the code to the file |
| 75 | yield fs.writeFile(path.join(process.cwd(), filePath), contents); |
| 76 | // Add the file to the code index |
| 77 | yield codepilot.index.upsertDocument(filePath); |
| 78 | console.log(internals_1.Colorize.highlight(`Created a new file: ${filePath}`)); |
| 79 | return `Successfully created file at ${filePath}`; |
| 80 | } |
| 81 | catch (error) { |
| 82 | return `Failed to create file at ${filePath} due to the following error:\n${error.message}`; |
| 83 | } |
| 84 | })); |
| 85 | } |
| 86 | exports.addCreateFile = addCreateFile; |
| 87 | //# sourceMappingURL=createFile.js.map |
nothing calls this directly
no test coverage detected