diff --git a/web/app/components/workflow/nodes/_base/components/variable/object-child-tree-panel/picker/index.tsx b/web/app/components/workflow/nodes/_base/components/variable/object-child-tree-panel/picker/index.tsx index 5a84300fcd..af86cc78cd 100644 --- a/web/app/components/workflow/nodes/_base/components/variable/object-child-tree-panel/picker/index.tsx +++ b/web/app/components/workflow/nodes/_base/components/variable/object-child-tree-panel/picker/index.tsx @@ -9,7 +9,7 @@ import type { ValueSelector } from '@/app/components/workflow/types' type Props = { className?: string - root: { nodeId?: string, nodeName?: string, attrName: string } + root: { nodeId?: string, nodeName?: string, attrName: string, attrAlias?: string } payload: StructuredOutput readonly?: boolean onSelect?: (valueSelector: ValueSelector) => void @@ -52,8 +52,7 @@ export const PickerPanelMain: FC = ({ )}
{root.attrName}
- {/* It must be object */} -
object
+
{root.attrAlias || 'object'}
{fieldNames.map(name => ( { - const output = payload.output_schema!.properties[outputKey] - const dataType = output?.properties?.dify_builtin_type ? output.properties.dify_builtin_type.enum[0] : output.type - dynamicOutputSchema.push({ - variable: outputKey, - type: dataType === 'array' - ? `array[${output.items?.type.slice(0, 1).toLocaleLowerCase()}${output.items?.type.slice(1)}]` - : `${dataType.slice(0, 1).toLocaleLowerCase()}${dataType.slice(1)}`, - description: output.description, - children: output.type === 'object' ? { - schema: { - type: 'object', - properties: Object.fromEntries( - Object.entries(output.properties).filter(([key]) => key !== 'dify_builtin_type'), - ), - }, - } : undefined, - }) - }) - res.vars = [ - ...baseVars, - ...dynamicOutputSchema, - { - variable: 'output', - type: VarType.object, - children: dynamicOutputSchema, - }, - ] - } - else { - res.vars = baseVars - } + const dataSourceVars = DataSourceNodeDefault.getOutputVars?.(payload, ragVars) || [] + res.vars = dataSourceVars break } @@ -952,7 +920,7 @@ export const getVarType = ({ const isStructuredOutputVar = !!targetVar.children?.schema?.properties if (isStructuredOutputVar) { if (valueSelector.length === 2) { // root - return VarType.object + return targetVar.alias || VarType.object } let currProperties = targetVar.children.schema; (valueSelector as ValueSelector).slice(2).forEach((key, i) => { diff --git a/web/app/components/workflow/nodes/_base/components/variable/var-reference-vars.tsx b/web/app/components/workflow/nodes/_base/components/variable/var-reference-vars.tsx index 3ea397a440..0d82c299d4 100644 --- a/web/app/components/workflow/nodes/_base/components/variable/var-reference-vars.tsx +++ b/web/app/components/workflow/nodes/_base/components/variable/var-reference-vars.tsx @@ -173,7 +173,7 @@ const Item: FC = ({
{itemData.variable.split('.').slice(-1)[0]}
)} -
{itemData.type}
+
{itemData.alias || itemData.type}
{ (isObj || isStructureOutput) && ( @@ -186,7 +186,7 @@ const Item: FC = ({ }}> {(isStructureOutput || isObj) && ( { diff --git a/web/app/components/workflow/nodes/data-source/default.ts b/web/app/components/workflow/nodes/data-source/default.ts index f3a9e3e4cc..b34be80e7f 100644 --- a/web/app/components/workflow/nodes/data-source/default.ts +++ b/web/app/components/workflow/nodes/data-source/default.ts @@ -58,6 +58,29 @@ const nodeDefault: NodeDefault = { provider_type, } = payload const isLocalFile = provider_type === DataSourceClassification.localFile + const dynamicOutputSchema: any[] = [] + if (payload.output_schema?.properties) { + Object.keys(payload.output_schema.properties).forEach((outputKey) => { + const output = payload.output_schema!.properties[outputKey] + const dataType = output.type + dynamicOutputSchema.push({ + variable: outputKey, + type: dataType === 'array' + ? `array[${output.items?.type.slice(0, 1).toLocaleLowerCase()}${output.items?.type.slice(1)}]` + : `${dataType.slice(0, 1).toLocaleLowerCase()}${dataType.slice(1)}`, + description: output.description, + alias: output?.properties.dify_builtin_type?.enum?.[0], + children: output.type === 'object' ? { + schema: { + type: 'object', + properties: Object.fromEntries( + Object.entries(output.properties).filter(([key]) => key !== 'dify_builtin_type'), + ), + }, + } : undefined, + }) + }) + } return [ ...COMMON_OUTPUT.map(item => ({ variable: item.name, type: item.type })), ...( @@ -66,6 +89,7 @@ const nodeDefault: NodeDefault = { : [] ), ...ragVars, + ...dynamicOutputSchema, ] }, } diff --git a/web/app/components/workflow/nodes/data-source/panel.tsx b/web/app/components/workflow/nodes/data-source/panel.tsx index e6e3255dd5..1894ff56e1 100644 --- a/web/app/components/workflow/nodes/data-source/panel.tsx +++ b/web/app/components/workflow/nodes/data-source/panel.tsx @@ -50,7 +50,7 @@ const Panel: FC> = ({ id, data }) => { const pipelineId = useStore(s => s.pipelineId) const setShowInputFieldPanel = useStore(s => s.setShowInputFieldPanel) const wrapStructuredVarItem = (outputItem: any): StructuredOutput => { - const dataType = outputItem.value?.properties?.dify_builtin_type ? outputItem.value?.properties?.dify_builtin_type.enum[0] : Type.object + const dataType = Type.object const properties = Object.fromEntries( Object.entries(outputItem.value?.properties || {}).filter(([key]) => key !== 'dify_builtin_type'), ) as Record @@ -61,6 +61,7 @@ const Panel: FC> = ({ id, data }) => { [outputItem.name]: { ...outputItem.value, properties, + alias: outputItem.value?.properties?.dify_builtin_type?.enum?.[0], }, }, additionalProperties: false, diff --git a/web/app/components/workflow/nodes/llm/types.ts b/web/app/components/workflow/nodes/llm/types.ts index 8314592e6a..ff2a5fc5f4 100644 --- a/web/app/components/workflow/nodes/llm/types.ts +++ b/web/app/components/workflow/nodes/llm/types.ts @@ -55,6 +55,7 @@ export type Field = { items?: ArrayItems // Array has items. Define the item type enum?: SchemaEnumType // Enum values additionalProperties?: false // Required in object by api. Just set false + alias?: string // Alias of the field } export type StructuredOutput = { diff --git a/web/app/components/workflow/nodes/llm/utils.ts b/web/app/components/workflow/nodes/llm/utils.ts index fd943d1fa3..f7ba1db63a 100644 --- a/web/app/components/workflow/nodes/llm/utils.ts +++ b/web/app/components/workflow/nodes/llm/utils.ts @@ -10,9 +10,12 @@ export const checkNodeValid = (_payload: LLMNodeType) => { } export const getFieldType = (field: Field) => { - const { type, items } = field - if (type !== Type.array || !items) + const { type, items, alias } = field + if (type !== Type.array || !items) { + if (alias) + return alias return type + } return ArrayType[items.type] } diff --git a/web/app/components/workflow/types.ts b/web/app/components/workflow/types.ts index 04fd03c440..9724c44504 100644 --- a/web/app/components/workflow/types.ts +++ b/web/app/components/workflow/types.ts @@ -302,6 +302,7 @@ export type Var = { isLoopVariable?: boolean nodeId?: string isRagVariable?: boolean + alias?: string } export type NodeOutPutVar = {