| 1 | import Handlebars from "handlebars"; |
| 2 | import { NEXT_EDIT_MODELS } from "../../llm/constants"; |
| 3 | import { |
| 4 | INSTINCT_USER_PROMPT_PREFIX, |
| 5 | MERCURY_CURRENT_FILE_CONTENT_CLOSE, |
| 6 | MERCURY_CURRENT_FILE_CONTENT_OPEN, |
| 7 | MERCURY_EDIT_DIFF_HISTORY_CLOSE, |
| 8 | MERCURY_EDIT_DIFF_HISTORY_OPEN, |
| 9 | MERCURY_RECENTLY_VIEWED_CODE_SNIPPETS_CLOSE, |
| 10 | MERCURY_RECENTLY_VIEWED_CODE_SNIPPETS_OPEN, |
| 11 | } from "../constants"; |
| 12 | import { NextEditTemplate, TemplateVars } from "../types"; |
| 13 | |
| 14 | // Keep the template registry |
| 15 | export const NEXT_EDIT_MODEL_TEMPLATES: Record< |
| 16 | NEXT_EDIT_MODELS, |
| 17 | NextEditTemplate |
| 18 | > = { |
| 19 | "mercury-coder": { |
| 20 | template: `${MERCURY_RECENTLY_VIEWED_CODE_SNIPPETS_OPEN}\n{{{recentlyViewedCodeSnippets}}}\n${MERCURY_RECENTLY_VIEWED_CODE_SNIPPETS_CLOSE}\n\n${MERCURY_CURRENT_FILE_CONTENT_OPEN}\n{{{currentFileContent}}}\n${MERCURY_CURRENT_FILE_CONTENT_CLOSE}\n\n${MERCURY_EDIT_DIFF_HISTORY_OPEN}\n{{{editDiffHistory}}}\n${MERCURY_EDIT_DIFF_HISTORY_CLOSE}\n`, |
| 21 | }, |
| 22 | instinct: { |
| 23 | template: `${INSTINCT_USER_PROMPT_PREFIX}\n\n### Context:\n{{{contextSnippets}}}\n\n### User Edits:\n\n{{{editDiffHistory}}}\n\n### User Excerpt:\n{{{currentFilePath}}}\n\n{{{currentFileContent}}}\`\`\`\n### Response:`, |
| 24 | }, |
| 25 | }; |
| 26 | |
| 27 | // Export a utility for providers to use |
| 28 | export class PromptTemplateRenderer { |
| 29 | private compiledTemplate: HandlebarsTemplateDelegate; |
| 30 | |
| 31 | constructor(template: string) { |
| 32 | this.compiledTemplate = Handlebars.compile(template); |
| 33 | } |
| 34 | |
| 35 | render(vars: TemplateVars): string { |
| 36 | return this.compiledTemplate(vars); |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | // Keep for backward compatibility or remove if not needed |
| 41 | export function getTemplateForModel(modelName: NEXT_EDIT_MODELS): string { |
| 42 | const template = NEXT_EDIT_MODEL_TEMPLATES[modelName]; |
| 43 | if (!template) { |
| 44 | throw new Error(`Model ${modelName} is not supported for next edit.`); |
| 45 | } |
| 46 | return template.template; |
| 47 | } |