mirror of
https://github.com/langgenius/dify.git
synced 2026-09-05 16:55:14 +08:00
Co-authored-by: zhangx1n <zhangxin@dify.ai> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
24 lines
905 B
TypeScript
24 lines
905 B
TypeScript
import type { LLMEnvironmentVariableValue } from '@/app/components/workflow/types'
|
|
|
|
const VALID_LLM_ENVIRONMENT_VARIABLE_MODES = new Set(['chat', 'completion'])
|
|
|
|
export function isLLMEnvironmentVariableValue(
|
|
value: unknown,
|
|
): value is LLMEnvironmentVariableValue {
|
|
if (typeof value !== 'object' || value === null) return false
|
|
|
|
const candidate = value as Partial<LLMEnvironmentVariableValue>
|
|
return (
|
|
typeof candidate.provider === 'string' &&
|
|
candidate.provider.trim().length > 0 &&
|
|
typeof candidate.name === 'string' &&
|
|
candidate.name.trim().length > 0 &&
|
|
typeof candidate.mode === 'string' &&
|
|
VALID_LLM_ENVIRONMENT_VARIABLE_MODES.has(candidate.mode) &&
|
|
(candidate.completion_params === undefined ||
|
|
(typeof candidate.completion_params === 'object' &&
|
|
candidate.completion_params !== null &&
|
|
!Array.isArray(candidate.completion_params)))
|
|
)
|
|
}
|