mirror of https://github.com/langgenius/dify.git
fix(web): fill workflow tool output descriptions from schema (#32117)
This commit is contained in:
parent
14251b249d
commit
18f14c04dc
|
|
@ -13,6 +13,54 @@ describe('buildWorkflowOutputParameters', () => {
|
|||
expect(result).toBe(params)
|
||||
})
|
||||
|
||||
it('fills missing output description and type from schema when array input exists', () => {
|
||||
const params: WorkflowToolProviderOutputParameter[] = [
|
||||
{ name: 'answer', description: '', type: undefined },
|
||||
{ name: 'files', description: 'keep this description', type: VarType.arrayFile },
|
||||
]
|
||||
const schema: WorkflowToolProviderOutputSchema = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
answer: {
|
||||
type: VarType.string,
|
||||
description: 'Generated answer',
|
||||
},
|
||||
files: {
|
||||
type: VarType.arrayFile,
|
||||
description: 'Schema files description',
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
const result = buildWorkflowOutputParameters(params, schema)
|
||||
|
||||
expect(result).toEqual([
|
||||
{ name: 'answer', description: 'Generated answer', type: VarType.string },
|
||||
{ name: 'files', description: 'keep this description', type: VarType.arrayFile },
|
||||
])
|
||||
})
|
||||
|
||||
it('falls back to empty description when both payload and schema descriptions are missing', () => {
|
||||
const params: WorkflowToolProviderOutputParameter[] = [
|
||||
{ name: 'missing_desc', description: '', type: undefined },
|
||||
]
|
||||
const schema: WorkflowToolProviderOutputSchema = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
other_field: {
|
||||
type: VarType.string,
|
||||
description: 'Other',
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
const result = buildWorkflowOutputParameters(params, schema)
|
||||
|
||||
expect(result).toEqual([
|
||||
{ name: 'missing_desc', description: '', type: undefined },
|
||||
])
|
||||
})
|
||||
|
||||
it('derives parameters from schema when explicit array missing', () => {
|
||||
const schema: WorkflowToolProviderOutputSchema = {
|
||||
type: 'object',
|
||||
|
|
@ -44,4 +92,56 @@ describe('buildWorkflowOutputParameters', () => {
|
|||
it('returns empty array when no source information is provided', () => {
|
||||
expect(buildWorkflowOutputParameters(null, null)).toEqual([])
|
||||
})
|
||||
|
||||
it('derives parameters from schema when explicit array is empty', () => {
|
||||
const schema: WorkflowToolProviderOutputSchema = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
output_text: {
|
||||
type: VarType.string,
|
||||
description: 'Output text',
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
const result = buildWorkflowOutputParameters([], schema)
|
||||
|
||||
expect(result).toEqual([
|
||||
{ name: 'output_text', description: 'Output text', type: VarType.string },
|
||||
])
|
||||
})
|
||||
|
||||
it('returns undefined type when schema output type is missing', () => {
|
||||
const schema = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
answer: {
|
||||
description: 'Answer without type',
|
||||
},
|
||||
},
|
||||
} as unknown as WorkflowToolProviderOutputSchema
|
||||
|
||||
const result = buildWorkflowOutputParameters(undefined, schema)
|
||||
|
||||
expect(result).toEqual([
|
||||
{ name: 'answer', description: 'Answer without type', type: undefined },
|
||||
])
|
||||
})
|
||||
|
||||
it('falls back to empty description when schema-derived description is missing', () => {
|
||||
const schema = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
answer: {
|
||||
type: VarType.string,
|
||||
},
|
||||
},
|
||||
} as unknown as WorkflowToolProviderOutputSchema
|
||||
|
||||
const result = buildWorkflowOutputParameters(undefined, schema)
|
||||
|
||||
expect(result).toEqual([
|
||||
{ name: 'answer', description: '', type: VarType.string },
|
||||
])
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -14,15 +14,28 @@ export const buildWorkflowOutputParameters = (
|
|||
outputParameters: WorkflowToolProviderOutputParameter[] | null | undefined,
|
||||
outputSchema?: WorkflowToolProviderOutputSchema | null,
|
||||
): WorkflowToolProviderOutputParameter[] => {
|
||||
if (Array.isArray(outputParameters))
|
||||
return outputParameters
|
||||
const schemaProperties = outputSchema?.properties
|
||||
|
||||
if (!outputSchema?.properties)
|
||||
if (Array.isArray(outputParameters) && outputParameters.length > 0) {
|
||||
if (!schemaProperties)
|
||||
return outputParameters
|
||||
|
||||
return outputParameters.map((item) => {
|
||||
const schema = schemaProperties[item.name]
|
||||
return {
|
||||
...item,
|
||||
description: item.description || schema?.description || '',
|
||||
type: normalizeVarType(item.type || schema?.type),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
if (!schemaProperties)
|
||||
return []
|
||||
|
||||
return Object.entries(outputSchema.properties).map(([name, schema]) => ({
|
||||
return Object.entries(schemaProperties).map(([name, schema]) => ({
|
||||
name,
|
||||
description: schema.description,
|
||||
description: schema.description || '',
|
||||
type: normalizeVarType(schema.type),
|
||||
}))
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue