editcodewithai
Version:
Edit Code With AI
74 lines (73 loc) • 3.05 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FORMAT_INSTRUCTIONS = exports.PROMPT_TEMPLATE_VERSION = void 0;
exports.assembleFullPrompt = assembleFullPrompt;
// Versions of the prompt template.
exports.PROMPT_TEMPLATE_VERSION = 1;
// Template pieces
const TASK = (prompt) => `## Your Task\n\n${prompt}`;
const FILES = (filesContext) => `## Original Files\n\n${filesContext}`;
exports.FORMAT_INSTRUCTIONS = {
whole: [
"## Formatting Instructions\n\n",
"Suggest changes to the original files using this exact format:\n\n",
"**fileA.js**\n\n```js\n// Entire updated code for fileA\n```\n\n",
"**fileB.js**\n\n```js\n// Entire updated code for fileB\n```\n\n",
"Only include the files that need to be updated or created.\n\n",
"To suggest changes you MUST include the ENTIRE content of the updated file.\n\n",
'NEVER leave out sections as in "... rest of the code remain the same ...".\n\n',
"Refactor large files into smaller files in the same directory.\n\n",
"Delete all unused files, but we need to keep `README.md`. ",
"Files can be deleted by setting their content to empty, for example:\n\n",
"**fileToDelete.js**\n\n```\n```\n\n",
].join(""),
diff: [
"## Formatting Instructions\n\n",
"Suggest changes to the original files using this search/replace block format:\n\n",
"path/to/filename.ext\n",
"```\n",
"<<<<<<< SEARCH\n",
"// code to be replaced\n",
"=======\n",
"// new code\n",
">>>>>>> REPLACE\n",
"```\n",
].join(""),
"diff-fenced": [
"## Formatting Instructions\n\n",
"Suggest changes to the original files using this search/replace block format with the file path inside the fence:\n\n",
"```\n",
"path/to/filename.ext\n",
"<<<<<<< SEARCH\n",
"// code to be replaced\n",
"=======\n",
"// new code\n",
">>>>>>> REPLACE\n",
"```\n",
].join(""),
udiff: [
"## Formatting Instructions\n\n",
"Suggest changes to the original files using the unified diff format:\n\n",
"```diff\n",
"--- path/to/filename.ext\n",
"+++ path/to/filename.ext\n",
"@@ ... @@\n",
"-// line to be removed\n",
"+// line to be added\n",
"```\n",
].join(""),
};
/**
* Assembles the full prompt by combining task, files context, and formatting instructions
*/
function assembleFullPrompt({ filesContext, prompt, editFormat = "whole", imageFiles = [], }) {
const FORMAT = exports.FORMAT_INSTRUCTIONS[editFormat];
// Add image files list if there are any
let imageFilesSection = "";
if (imageFiles.length > 0) {
imageFilesSection =
"\nImage files available:\n\n" +
imageFiles.map((fileName) => ` * \`${fileName}\``).join("\n");
}
return [TASK(prompt), FILES(filesContext), FORMAT + imageFilesSection].join("\n\n");
}