From 023e8ae9fc738cdad42e23686349de5554fe2b33 Mon Sep 17 00:00:00 2001 From: Jacob Kim Date: Wed, 2 Jul 2025 17:53:58 -0700 Subject: [PATCH] move check to an outer layer --- .../templating/NextEditPromptEngine.ts | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/core/nextEdit/templating/NextEditPromptEngine.ts b/core/nextEdit/templating/NextEditPromptEngine.ts index d69730606..7b21232d6 100644 --- a/core/nextEdit/templating/NextEditPromptEngine.ts +++ b/core/nextEdit/templating/NextEditPromptEngine.ts @@ -51,16 +51,7 @@ function templateRendererOfModel( ): TemplateRenderer { let template = NEXT_EDIT_MODEL_TEMPLATES[modelName]; if (!template) { - // Check if modelName includes any known model name as substring. - const matchingModel = Object.keys(NEXT_EDIT_MODEL_TEMPLATES).find((key) => - modelName.includes(key), - ); - - if (matchingModel) { - template = NEXT_EDIT_MODEL_TEMPLATES[matchingModel as NextEditModelName]; - } else { - throw new Error(`Model ${modelName} is not supported for next edit.`); - } + throw new Error(`Model ${modelName} is not supported for next edit.`); } const compiledTemplate = Handlebars.compile(template.template); @@ -74,7 +65,7 @@ export function renderPrompt( helper: HelperVars, userEdits: string, ): UserPrompt { - const modelName = helper.modelName as NextEditModelName; + let modelName = helper.modelName as NextEditModelName; if (modelName === "this field is not used") { return { @@ -85,7 +76,18 @@ export function renderPrompt( // Validate that the modelName is actually a supported model. if (!Object.keys(NEXT_EDIT_MODEL_TEMPLATES).includes(modelName)) { - throw new Error(`${helper.modelName} is not yet supported for next edit.`); + // Check if modelName includes any known model name as substring. + const matchingModel = Object.keys(NEXT_EDIT_MODEL_TEMPLATES).find((key) => + modelName.includes(key), + ); + + if (matchingModel) { + modelName = matchingModel as NextEditModelName; + } else { + throw new Error( + `${helper.modelName} is not yet supported for next edit.`, + ); + } } const renderer = templateRendererOfModel(modelName);