move check to an outer layer

This commit is contained in:
Jacob Kim 2025-07-02 17:53:58 -07:00
parent ab96f9529b
commit 023e8ae9fc

View file

@ -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);