fix(web): guard LLM node model_selector against persisted null (#41707)

This commit is contained in:
Benjamin 2026-09-03 06:20:48 +00:00 committed by GitHub
parent b015aa416f
commit 8f7cca3ae2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 2 deletions

View File

@ -1,4 +1,8 @@
import type { EnvironmentVariable, ModelConfig } from '@/app/components/workflow/types'
import type {
EnvironmentVariable,
ModelConfig,
ValueSelector,
} from '@/app/components/workflow/types'
import { AppModeEnum } from '@/types/app'
import {
getLLMEnvironmentModel,
@ -160,5 +164,14 @@ describe('llm utils', () => {
expect(isEnvironmentModelSource(selector)).toBe(false)
expect(resolveLLMNodeModel(model, selector, environmentVariables)).toBe(model)
})
it('keeps the static model when the persisted selector is null', () => {
// A DSL exported from an older/AI-generated workflow can persist `model_selector: null`
// instead of omitting the key; this must not crash the same way `undefined` doesn't.
const selector = null as unknown as ValueSelector
expect(isEnvironmentModelSource(selector)).toBe(false)
expect(resolveLLMNodeModel(model, selector, environmentVariables)).toBe(model)
})
})
})

View File

@ -24,7 +24,7 @@ const isLLMEnvironmentVariableValue = (value: unknown): value is LLMEnvironmentV
}
export const isEnvironmentModelSource = (modelSelector: ValueSelector | undefined) =>
modelSelector !== undefined && (modelSelector.length === 0 || modelSelector[0] === 'env')
modelSelector != null && (modelSelector.length === 0 || modelSelector[0] === 'env')
export const getLLMEnvironmentModel = (
modelSelector: ValueSelector | undefined,