From 722bdbf97d7d44890e5a2cac96ec91cd3f3ed83f Mon Sep 17 00:00:00 2001 From: Jacob Kim Date: Wed, 6 Aug 2025 18:24:17 -0700 Subject: [PATCH] refactor: use next edit model enum --- core/llm/autodetect.ts | 7 ++++--- core/nextEdit/templating/NextEditPromptEngine.ts | 12 +++++------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/core/llm/autodetect.ts b/core/llm/autodetect.ts index 4d59bd667..b2943e316 100644 --- a/core/llm/autodetect.ts +++ b/core/llm/autodetect.ts @@ -1,4 +1,5 @@ import { ChatMessage, ModelCapability, TemplateType } from "../index.js"; +import { NEXT_EDIT_MODELS } from "./constants.js"; import { anthropicTemplateMessages, @@ -176,14 +177,14 @@ function isProviderHandlesTemplatingOrNoTemplateTypeRequired( // NOTE: When updating this list, // update core/nextEdit/templating/NextEditPromptEngine.ts as well. const MODEL_SUPPORTS_NEXT_EDIT: string[] = [ - "mercury-coder-nextedit", - "model-1", + NEXT_EDIT_MODELS.MERCURY_CODER_NEXTEDIT, + NEXT_EDIT_MODELS.MODEL_1, ]; function modelSupportsNextEdit( + capabilities: ModelCapability | undefined, model: string, title: string | undefined, - capabilities: ModelCapability | undefined, ): boolean { if (capabilities?.nextEdit !== undefined) { return capabilities.nextEdit; diff --git a/core/nextEdit/templating/NextEditPromptEngine.ts b/core/nextEdit/templating/NextEditPromptEngine.ts index bfab03a73..29e958b18 100644 --- a/core/nextEdit/templating/NextEditPromptEngine.ts +++ b/core/nextEdit/templating/NextEditPromptEngine.ts @@ -30,13 +30,11 @@ import { insertCursorToken, insertEditableRegionTokensWithStaticRange, } from "./utils"; +import { NEXT_EDIT_MODELS } from "../../llm/constants"; type TemplateRenderer = (vars: TemplateVars) => string; -// NOTE: When updating this union, update core/llm/autodetect.ts as well. -export type NextEditModelName = "mercury-coder-nextedit" | "model-1"; - -const NEXT_EDIT_MODEL_TEMPLATES: Record = { +const NEXT_EDIT_MODEL_TEMPLATES: Record = { "mercury-coder-nextedit": { 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\nThe developer was working on a section of code within the tags \`<|code_to_edit|>\` in the file located at {{{currentFilePath}}}.\nUsing the given \`recently_viewed_code_snippets\`, \`current_file_content\`, \`edit_diff_history\`, and the cursor position marked as \`<|cursor|>\`, please continue the developer's work. Update the \`code_to_edit\` section by predicting and completing the changes they would have made next. Provide the revised code that was between the \`<|code_to_edit|>\` and \`<|/code_to_edit|>\` tags, including the tags themselves.`, }, @@ -47,7 +45,7 @@ const NEXT_EDIT_MODEL_TEMPLATES: Record = { }; function templateRendererOfModel( - modelName: NextEditModelName, + modelName: NEXT_EDIT_MODELS, ): TemplateRenderer { let template = NEXT_EDIT_MODEL_TEMPLATES[modelName]; if (!template) { @@ -65,7 +63,7 @@ export async function renderPrompt( helper: HelperVars, ctx: any, ): Promise { - let modelName = helper.modelName as NextEditModelName; + let modelName = helper.modelName as NEXT_EDIT_MODELS; // Validate that the modelName is actually a supported model. if (!Object.keys(NEXT_EDIT_MODEL_TEMPLATES).includes(modelName)) { @@ -75,7 +73,7 @@ export async function renderPrompt( ); if (matchingModel) { - modelName = matchingModel as NextEditModelName; + modelName = matchingModel as NEXT_EDIT_MODELS; } else { throw new Error( `${helper.modelName} is not yet supported for next edit.`,