Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix(web): fill workflow tool output descriptions from schema (#32117)

weiguang li18f14c04dcfa
diff --git a/web/app/components/tools/workflow-tool/utils.test.ts b/web/app/components/tools/workflow-tool/utils.test.ts
index bc2dc98c195..ef95699af67 100644
--- a/web/app/components/tools/workflow-tool/utils.test.ts
+++ b/web/app/components/tools/workflow-tool/utils.test.ts
@@ -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 },
+ ])
+ })
})
diff --git a/web/app/components/tools/workflow-tool/utils.ts b/web/app/components/tools/workflow-tool/utils.ts
index 80d832fb47b..c5a5ef17d9c 100644
--- a/web/app/components/tools/workflow-tool/utils.ts
+++ b/web/app/components/tools/workflow-tool/utils.ts
@@ -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),
}))
}