mirror of
https://github.com/langgenius/dify.git
synced 2026-02-09 23:20:12 -05:00
fix: fix mcp output schema is union type frontend crash (#31779)
Co-authored-by: Stephen Zhou <38493346+hyoban@users.noreply.github.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import type { ToolNodeType, ToolVarInputs } from './types'
|
import type { ToolNodeType, ToolVarInputs } from './types'
|
||||||
import type { InputVar } from '@/app/components/workflow/types'
|
import type { InputVar } from '@/app/components/workflow/types'
|
||||||
import { useBoolean } from 'ahooks'
|
import { useBoolean } from 'ahooks'
|
||||||
|
import { capitalize } from 'es-toolkit/string'
|
||||||
import { produce } from 'immer'
|
import { produce } from 'immer'
|
||||||
import { useCallback, useEffect, useMemo, useState } from 'react'
|
import { useCallback, useEffect, useMemo, useState } from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
@@ -25,6 +26,12 @@ import {
|
|||||||
} from '@/service/use-tools'
|
} from '@/service/use-tools'
|
||||||
import { canFindTool } from '@/utils'
|
import { canFindTool } from '@/utils'
|
||||||
import { useWorkflowStore } from '../../store'
|
import { useWorkflowStore } from '../../store'
|
||||||
|
import { normalizeJsonSchemaType } from './output-schema-utils'
|
||||||
|
|
||||||
|
const formatDisplayType = (output: Record<string, unknown>): string => {
|
||||||
|
const normalizedType = normalizeJsonSchemaType(output) || 'Unknown'
|
||||||
|
return capitalize(normalizedType)
|
||||||
|
}
|
||||||
|
|
||||||
const useConfig = (id: string, payload: ToolNodeType) => {
|
const useConfig = (id: string, payload: ToolNodeType) => {
|
||||||
const workflowStore = useWorkflowStore()
|
const workflowStore = useWorkflowStore()
|
||||||
@@ -247,20 +254,13 @@ const useConfig = (id: string, payload: ToolNodeType) => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
const normalizedType = normalizeJsonSchemaType(output)
|
||||||
res.push({
|
res.push({
|
||||||
name: outputKey,
|
name: outputKey,
|
||||||
type:
|
type:
|
||||||
output.type === 'array'
|
normalizedType === 'array'
|
||||||
? `Array[${output.items?.type
|
? `Array[${output.items ? formatDisplayType(output.items) : 'Unknown'}]`
|
||||||
? output.items.type.slice(0, 1).toLocaleUpperCase()
|
: formatDisplayType(output),
|
||||||
+ output.items.type.slice(1)
|
|
||||||
: 'Unknown'
|
|
||||||
}]`
|
|
||||||
: `${output.type
|
|
||||||
? output.type.slice(0, 1).toLocaleUpperCase()
|
|
||||||
+ output.type.slice(1)
|
|
||||||
: 'Unknown'
|
|
||||||
}`,
|
|
||||||
description: output.description,
|
description: output.description,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user