mirror of
https://github.com/langgenius/dify.git
synced 2026-04-26 05:35:58 +08:00
feat: Add support for array[message](List[promptMessage]) variable type
in workflow
This commit is contained in:
@ -224,7 +224,7 @@ const FormInputItem: FC<Props> = ({
|
||||
else if (isObject)
|
||||
return (varPayload: any) => varPayload.type === VarType.object
|
||||
else if (isArray)
|
||||
return (varPayload: any) => [VarType.array, VarType.arrayString, VarType.arrayNumber, VarType.arrayObject].includes(varPayload.type)
|
||||
return (varPayload: any) => [VarType.array, VarType.arrayString, VarType.arrayNumber, VarType.arrayObject, VarType.arrayMessage].includes(varPayload.type)
|
||||
return undefined
|
||||
}
|
||||
|
||||
|
||||
@ -162,6 +162,7 @@ export const varTypeToStructType = (type: VarType): Type => {
|
||||
[VarType.arrayNumber]: Type.array,
|
||||
[VarType.arrayObject]: Type.array,
|
||||
[VarType.arrayFile]: Type.array,
|
||||
[VarType.arrayMessage]: Type.array,
|
||||
} as any
|
||||
)[type] || Type.string
|
||||
)
|
||||
@ -940,6 +941,7 @@ const getIterationItemType = ({
|
||||
case VarType.arrayBoolean:
|
||||
return VarType.boolean
|
||||
case VarType.arrayObject:
|
||||
case VarType.arrayMessage:
|
||||
return VarType.object
|
||||
case VarType.array:
|
||||
return VarType.arrayObject // Use more specific type instead of any
|
||||
@ -994,6 +996,7 @@ const getLoopItemType = ({
|
||||
case VarType.arrayNumber:
|
||||
return VarType.number
|
||||
case VarType.arrayObject:
|
||||
case VarType.arrayMessage:
|
||||
return VarType.object
|
||||
case VarType.arrayBoolean:
|
||||
return VarType.boolean
|
||||
|
||||
@ -19,7 +19,7 @@ type Props = {
|
||||
onChange: (value: string) => void
|
||||
}
|
||||
|
||||
const TYPES = [VarType.string, VarType.number, VarType.boolean, VarType.arrayNumber, VarType.arrayString, VarType.arrayBoolean, VarType.arrayObject, VarType.object]
|
||||
const TYPES = [VarType.string, VarType.number, VarType.boolean, VarType.arrayNumber, VarType.arrayString, VarType.arrayBoolean, VarType.arrayObject, VarType.arrayMessage, VarType.object]
|
||||
const VarReferencePicker: FC<Props> = ({
|
||||
readonly,
|
||||
className,
|
||||
|
||||
@ -21,6 +21,7 @@ const TYPE_DISPLAY_NAMES: Record<VarType, string> = {
|
||||
[VarType.arrayNumber]: 'Array[Number]',
|
||||
[VarType.arrayBoolean]: 'Array[Boolean]',
|
||||
[VarType.arrayObject]: 'Array[Object]',
|
||||
[VarType.arrayMessage]: 'Array[Message]',
|
||||
[VarType.secret]: 'Secret',
|
||||
[VarType.array]: 'Array',
|
||||
'array[file]': 'Array[File]',
|
||||
@ -73,6 +74,8 @@ export const normalizeParameterType = (input: string | undefined | null): VarTyp
|
||||
return VarType.arrayBoolean
|
||||
else if (trimmed === 'array[object]')
|
||||
return VarType.arrayObject
|
||||
else if (trimmed === 'array[message]')
|
||||
return VarType.arrayMessage
|
||||
else if (trimmed === 'array')
|
||||
// Migrate legacy 'array' type to 'array[string]'
|
||||
return VarType.arrayString
|
||||
|
||||
@ -307,6 +307,7 @@ export enum VarType {
|
||||
arrayObject = 'array[object]',
|
||||
arrayBoolean = 'array[boolean]',
|
||||
arrayFile = 'array[file]',
|
||||
arrayMessage = 'array[message]',
|
||||
any = 'any',
|
||||
arrayAny = 'array[any]',
|
||||
}
|
||||
|
||||
@ -17,6 +17,7 @@ import { VariableIconWithColor } from '@/app/components/workflow/nodes/_base/com
|
||||
import { VarInInspectType } from '@/types/workflow'
|
||||
import { cn } from '@/utils/classnames'
|
||||
import { useToolIcon } from '../hooks'
|
||||
import { formatVarTypeLabel } from './utils'
|
||||
|
||||
type Props = {
|
||||
nodeData?: NodeWithVar
|
||||
@ -161,7 +162,7 @@ const Group = ({
|
||||
className="size-4"
|
||||
/>
|
||||
<div className="system-sm-medium grow truncate text-text-secondary">{varItem.name}</div>
|
||||
<div className="system-xs-regular shrink-0 text-text-tertiary">{varItem.value_type}</div>
|
||||
<div className="system-xs-regular shrink-0 text-text-tertiary">{formatVarTypeLabel(varItem.value_type)}</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
@ -34,6 +34,7 @@ import { CodeLanguage } from '../nodes/code/types'
|
||||
import { useStore } from '../store'
|
||||
import { BlockEnum } from '../types'
|
||||
import Empty from './empty'
|
||||
import { formatVarTypeLabel } from './utils'
|
||||
import ValueContent from './value-content'
|
||||
|
||||
type Props = {
|
||||
@ -159,7 +160,13 @@ const Right = ({
|
||||
handleHidePromptGenerator()
|
||||
}, [setInputs, blockType, nodeId, node?.data, handleHidePromptGenerator])
|
||||
|
||||
const displaySchemaType = currentNodeVar?.var.schemaType ? (`(${currentNodeVar.var.schemaType})`) : ''
|
||||
const schemaType = currentNodeVar?.var.schemaType
|
||||
const valueType = currentNodeVar?.var.value_type
|
||||
const valueTypeLabel = formatVarTypeLabel(valueType)
|
||||
const shouldShowSchemaType = !!schemaType
|
||||
&& schemaType !== valueType
|
||||
&& schemaType !== valueTypeLabel
|
||||
const displaySchemaType = shouldShowSchemaType ? (`(${schemaType})`) : ''
|
||||
|
||||
return (
|
||||
<div className={cn('flex h-full flex-col')}>
|
||||
@ -198,7 +205,7 @@ const Right = ({
|
||||
)}
|
||||
<div title={currentNodeVar.var.name} className="system-sm-semibold truncate text-text-secondary">{currentNodeVar.var.name}</div>
|
||||
<div className="system-xs-medium ml-1 shrink-0 space-x-2 text-text-tertiary">
|
||||
<span>{`${currentNodeVar.var.value_type}${displaySchemaType}`}</span>
|
||||
<span>{`${valueTypeLabel}${displaySchemaType}`}</span>
|
||||
{isTruncated && (
|
||||
<>
|
||||
<span>·</span>
|
||||
|
||||
@ -23,7 +23,7 @@ export const validateJSONSchema = (schema: any, type: string) => {
|
||||
const result = jsonSchema.safeParse(schema)
|
||||
return result
|
||||
}
|
||||
else if (type === 'array[object]') {
|
||||
else if (type === 'array[object]' || type === 'array[message]') {
|
||||
const result = arrayJsonSchema.safeParse(schema)
|
||||
return result
|
||||
}
|
||||
@ -31,3 +31,9 @@ export const validateJSONSchema = (schema: any, type: string) => {
|
||||
return { success: true } as any
|
||||
}
|
||||
}
|
||||
|
||||
export const formatVarTypeLabel = (valueType?: string) => {
|
||||
if (valueType === 'array[message]')
|
||||
return 'List[promptMessage]'
|
||||
return valueType || ''
|
||||
}
|
||||
|
||||
@ -46,7 +46,15 @@ const ValueContent = ({
|
||||
const showBoolEditor = typeof currentVar.value === 'boolean'
|
||||
const showBoolArrayEditor = Array.isArray(currentVar.value) && currentVar.value.every(v => typeof v === 'boolean')
|
||||
const isSysFiles = currentVar.type === VarInInspectType.system && currentVar.name === 'files'
|
||||
const showJSONEditor = !isSysFiles && (currentVar.value_type === 'object' || currentVar.value_type === 'array[string]' || currentVar.value_type === 'array[number]' || currentVar.value_type === 'array[object]' || currentVar.value_type === 'array[any]')
|
||||
// FIXME: use enum to instead hardcode string
|
||||
const showJSONEditor = !isSysFiles && (
|
||||
currentVar.value_type === 'object'
|
||||
|| currentVar.value_type === 'array[string]'
|
||||
|| currentVar.value_type === 'array[number]'
|
||||
|| currentVar.value_type === 'array[object]'
|
||||
|| currentVar.value_type === 'array[message]'
|
||||
|| currentVar.value_type === 'array[any]'
|
||||
)
|
||||
const showFileEditor = isSysFiles || currentVar.value_type === 'file' || currentVar.value_type === 'array[file]'
|
||||
const textEditorDisabled = currentVar.type === VarInInspectType.environment || (currentVar.type === VarInInspectType.system && currentVar.name !== 'query' && currentVar.name !== 'files')
|
||||
const JSONEditorDisabled = currentVar.value_type === 'array[any]'
|
||||
|
||||
Reference in New Issue
Block a user