From d5f82d0d5f23424a609c6a39a8cc0c584d373ac6 Mon Sep 17 00:00:00 2001 From: zxhlyh Date: Thu, 7 Aug 2025 16:36:32 +0800 Subject: [PATCH] fix: json schema --- .../nodes/_base/components/variable/utils.ts | 1 + .../workflow/nodes/data-source/default.ts | 2 +- .../workflow/nodes/data-source/panel.tsx | 23 ++----------------- .../components/workflow/nodes/tool/panel.tsx | 12 ++-------- web/app/components/workflow/utils/tool.ts | 22 ++++++++++++++++++ 5 files changed, 28 insertions(+), 32 deletions(-) diff --git a/web/app/components/workflow/nodes/_base/components/variable/utils.ts b/web/app/components/workflow/nodes/_base/components/variable/utils.ts index 3616f0a109..680bd81382 100644 --- a/web/app/components/workflow/nodes/_base/components/variable/utils.ts +++ b/web/app/components/workflow/nodes/_base/components/variable/utils.ts @@ -413,6 +413,7 @@ const formatItem = ( ? `array[${output.items?.type.slice(0, 1).toLocaleLowerCase()}${output.items?.type.slice(1)}]` : `${output.type.slice(0, 1).toLocaleLowerCase()}${output.type.slice(1)}`, description: output.description, + alias: output?.properties?.dify_builtin_type?.enum?.[0], children: output.type === 'object' ? { schema: { type: 'object', diff --git a/web/app/components/workflow/nodes/data-source/default.ts b/web/app/components/workflow/nodes/data-source/default.ts index b34be80e7f..a71d4de7fc 100644 --- a/web/app/components/workflow/nodes/data-source/default.ts +++ b/web/app/components/workflow/nodes/data-source/default.ts @@ -69,7 +69,7 @@ const nodeDefault: NodeDefault = { ? `array[${output.items?.type.slice(0, 1).toLocaleLowerCase()}${output.items?.type.slice(1)}]` : `${dataType.slice(0, 1).toLocaleLowerCase()}${dataType.slice(1)}`, description: output.description, - alias: output?.properties.dify_builtin_type?.enum?.[0], + alias: output?.properties?.dify_builtin_type?.enum?.[0], children: output.type === 'object' ? { schema: { type: 'object', diff --git a/web/app/components/workflow/nodes/data-source/panel.tsx b/web/app/components/workflow/nodes/data-source/panel.tsx index 1894ff56e1..96241bad89 100644 --- a/web/app/components/workflow/nodes/data-source/panel.tsx +++ b/web/app/components/workflow/nodes/data-source/panel.tsx @@ -15,14 +15,13 @@ import StructureOutputItem from '@/app/components/workflow/nodes/_base/component import TagInput from '@/app/components/base/tag-input' import { useNodesReadOnly } from '@/app/components/workflow/hooks' import { useConfig } from './hooks/use-config' -import type { StructuredOutput } from '@/app/components/workflow/nodes/llm/types' -import { Type } from '@/app/components/workflow/nodes/llm/types' import { COMMON_OUTPUT, } from './constants' import { useStore } from '@/app/components/workflow/store' import { toolParametersToFormSchemas } from '@/app/components/tools/utils/to-form-schema' import ToolForm from '../tool/components/tool-form' +import { wrapStructuredVarItem } from '@/app/components/workflow/utils/tool' const Panel: FC> = ({ id, data }) => { const { t } = useTranslation() @@ -49,25 +48,7 @@ const Panel: FC> = ({ id, data }) => { const pipelineId = useStore(s => s.pipelineId) const setShowInputFieldPanel = useStore(s => s.setShowInputFieldPanel) - const wrapStructuredVarItem = (outputItem: any): StructuredOutput => { - const dataType = Type.object - const properties = Object.fromEntries( - Object.entries(outputItem.value?.properties || {}).filter(([key]) => key !== 'dify_builtin_type'), - ) as Record - return { - schema: { - type: dataType, - properties: { - [outputItem.name]: { - ...outputItem.value, - properties, - alias: outputItem.value?.properties?.dify_builtin_type?.enum?.[0], - }, - }, - additionalProperties: false, - }, - } - } + return (
{ diff --git a/web/app/components/workflow/nodes/tool/panel.tsx b/web/app/components/workflow/nodes/tool/panel.tsx index 029cc32edb..7312fb0a89 100644 --- a/web/app/components/workflow/nodes/tool/panel.tsx +++ b/web/app/components/workflow/nodes/tool/panel.tsx @@ -10,8 +10,8 @@ import type { NodePanelProps } from '@/app/components/workflow/types' import Loading from '@/app/components/base/loading' import OutputVars, { VarItem } from '@/app/components/workflow/nodes/_base/components/output-vars' import StructureOutputItem from '@/app/components/workflow/nodes/_base/components/variable/object-child-tree-panel/show' -import { Type } from '../llm/types' import { useStore } from '@/app/components/workflow/store' +import { wrapStructuredVarItem } from '@/app/components/workflow/utils/tool' const i18nPrefix = 'workflow.nodes.tool' @@ -121,15 +121,7 @@ const Panel: FC> = ({ {outputItem.value?.type === 'object' ? ( + payload={wrapStructuredVarItem(outputItem)} /> ) : ( { + const dataType = Type.object + const properties = Object.fromEntries( + Object.entries(outputItem.value?.properties || {}).filter(([key]) => key !== 'dify_builtin_type'), + ) as Record + return { + schema: { + type: dataType, + properties: { + [outputItem.name]: { + ...outputItem.value, + properties, + alias: outputItem.value?.properties?.dify_builtin_type?.enum?.[0], + }, + }, + additionalProperties: false, + }, + } +}