mirror of https://github.com/langgenius/dify.git
fix: TypeError: outputParameters is not iterable (#29833)
This commit is contained in:
parent
acbeb04edc
commit
c086aa107c
|
|
@ -4,6 +4,7 @@ import React, { useMemo, useState } from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import { produce } from 'immer'
|
import { produce } from 'immer'
|
||||||
import type { Emoji, WorkflowToolProviderOutputParameter, WorkflowToolProviderParameter, WorkflowToolProviderRequest } from '../types'
|
import type { Emoji, WorkflowToolProviderOutputParameter, WorkflowToolProviderParameter, WorkflowToolProviderRequest } from '../types'
|
||||||
|
import { buildWorkflowOutputParameters } from './utils'
|
||||||
import cn from '@/utils/classnames'
|
import cn from '@/utils/classnames'
|
||||||
import Drawer from '@/app/components/base/drawer-plus'
|
import Drawer from '@/app/components/base/drawer-plus'
|
||||||
import Input from '@/app/components/base/input'
|
import Input from '@/app/components/base/input'
|
||||||
|
|
@ -47,7 +48,9 @@ const WorkflowToolAsModal: FC<Props> = ({
|
||||||
const [name, setName] = useState(payload.name)
|
const [name, setName] = useState(payload.name)
|
||||||
const [description, setDescription] = useState(payload.description)
|
const [description, setDescription] = useState(payload.description)
|
||||||
const [parameters, setParameters] = useState<WorkflowToolProviderParameter[]>(payload.parameters)
|
const [parameters, setParameters] = useState<WorkflowToolProviderParameter[]>(payload.parameters)
|
||||||
const outputParameters = useMemo<WorkflowToolProviderOutputParameter[]>(() => payload.outputParameters, [payload.outputParameters])
|
const rawOutputParameters = payload.outputParameters
|
||||||
|
const outputSchema = payload.tool?.output_schema
|
||||||
|
const outputParameters = useMemo<WorkflowToolProviderOutputParameter[]>(() => buildWorkflowOutputParameters(rawOutputParameters, outputSchema), [rawOutputParameters, outputSchema])
|
||||||
const reservedOutputParameters: WorkflowToolProviderOutputParameter[] = [
|
const reservedOutputParameters: WorkflowToolProviderOutputParameter[] = [
|
||||||
{
|
{
|
||||||
name: 'text',
|
name: 'text',
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,47 @@
|
||||||
|
import { VarType } from '@/app/components/workflow/types'
|
||||||
|
import type { WorkflowToolProviderOutputParameter, WorkflowToolProviderOutputSchema } from '../types'
|
||||||
|
import { buildWorkflowOutputParameters } from './utils'
|
||||||
|
|
||||||
|
describe('buildWorkflowOutputParameters', () => {
|
||||||
|
it('returns provided output parameters when array input exists', () => {
|
||||||
|
const params: WorkflowToolProviderOutputParameter[] = [
|
||||||
|
{ name: 'text', description: 'final text', type: VarType.string },
|
||||||
|
]
|
||||||
|
|
||||||
|
const result = buildWorkflowOutputParameters(params, null)
|
||||||
|
|
||||||
|
expect(result).toBe(params)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('derives parameters from schema when explicit array missing', () => {
|
||||||
|
const schema: WorkflowToolProviderOutputSchema = {
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
answer: {
|
||||||
|
type: VarType.string,
|
||||||
|
description: 'AI answer',
|
||||||
|
},
|
||||||
|
attachments: {
|
||||||
|
type: VarType.arrayFile,
|
||||||
|
description: 'Supporting files',
|
||||||
|
},
|
||||||
|
unknown: {
|
||||||
|
type: 'custom',
|
||||||
|
description: 'Unsupported type',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = buildWorkflowOutputParameters(undefined, schema)
|
||||||
|
|
||||||
|
expect(result).toEqual([
|
||||||
|
{ name: 'answer', description: 'AI answer', type: VarType.string },
|
||||||
|
{ name: 'attachments', description: 'Supporting files', type: VarType.arrayFile },
|
||||||
|
{ name: 'unknown', description: 'Unsupported type', type: undefined },
|
||||||
|
])
|
||||||
|
})
|
||||||
|
|
||||||
|
it('returns empty array when no source information is provided', () => {
|
||||||
|
expect(buildWorkflowOutputParameters(null, null)).toEqual([])
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
@ -0,0 +1,28 @@
|
||||||
|
import type { WorkflowToolProviderOutputParameter, WorkflowToolProviderOutputSchema } from '../types'
|
||||||
|
import { VarType } from '@/app/components/workflow/types'
|
||||||
|
|
||||||
|
const validVarTypes = new Set<string>(Object.values(VarType))
|
||||||
|
|
||||||
|
const normalizeVarType = (type?: string): VarType | undefined => {
|
||||||
|
if (!type)
|
||||||
|
return undefined
|
||||||
|
|
||||||
|
return validVarTypes.has(type) ? type as VarType : undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
export const buildWorkflowOutputParameters = (
|
||||||
|
outputParameters: WorkflowToolProviderOutputParameter[] | null | undefined,
|
||||||
|
outputSchema?: WorkflowToolProviderOutputSchema | null,
|
||||||
|
): WorkflowToolProviderOutputParameter[] => {
|
||||||
|
if (Array.isArray(outputParameters))
|
||||||
|
return outputParameters
|
||||||
|
|
||||||
|
if (!outputSchema?.properties)
|
||||||
|
return []
|
||||||
|
|
||||||
|
return Object.entries(outputSchema.properties).map(([name, schema]) => ({
|
||||||
|
name,
|
||||||
|
description: schema.description,
|
||||||
|
type: normalizeVarType(schema.type),
|
||||||
|
}))
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue