Files
dify/web/app/components/tools/workflow-tool/utils.ts
Stephen Zhou a84c2d36a3 style: format with vp fmt (#38803)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2026-07-12 15:57:46 +00:00

42 lines
1.3 KiB
TypeScript

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[] => {
const schemaProperties = 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(schemaProperties).map(([name, schema]) => ({
name,
description: schema.description || '',
type: normalizeVarType(schema.type),
}))
}