feat: implement structured output wrapping for pipeline items

This commit is contained in:
Harry
2025-08-06 17:40:53 +08:00
parent 5b433aa2d1
commit 1d79c21ae3

View File

@@ -15,6 +15,7 @@ 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,
@@ -48,7 +49,24 @@ const Panel: FC<NodePanelProps<DataSourceNodeType>> = ({ id, data }) => {
const pipelineId = useStore(s => s.pipelineId)
const setShowInputFieldPanel = useStore(s => s.setShowInputFieldPanel)
const wrapStructuredVarItem = (outputItem: any): StructuredOutput => {
const dataType = outputItem.value?.properties?.dify_builtin_type ? outputItem.value?.properties?.dify_builtin_type.enum[0] : Type.object
const properties = Object.fromEntries(
Object.entries(outputItem.value?.properties || {}).filter(([key]) => key !== 'dify_builtin_type'),
) as Record<string, any>
return {
schema: {
type: dataType,
properties: {
[outputItem.name]: {
...outputItem.value,
properties,
},
},
additionalProperties: false,
},
}
}
return (
<div >
{
@@ -123,15 +141,7 @@ const Panel: FC<NodePanelProps<DataSourceNodeType>> = ({ id, data }) => {
{outputItem.value?.type === 'object' ? (
<StructureOutputItem
rootClassName='code-sm-semibold text-text-secondary'
payload={{
schema: {
type: Type.object,
properties: {
[outputItem.name]: outputItem.value,
},
additionalProperties: false,
},
}} />
payload={wrapStructuredVarItem(outputItem)} />
) : (
<VarItem
name={outputItem.name}