mirror of
https://github.com/langgenius/dify.git
synced 2026-05-03 00:48:04 +08:00
datasource
This commit is contained in:
@ -4,8 +4,7 @@ import type { DataSourceNodeType } from './types'
|
||||
import type { NodeProps } from '@/app/components/workflow/types'
|
||||
const Node: FC<NodeProps<DataSourceNodeType>> = () => {
|
||||
return (
|
||||
<div className='mb-1 px-3 py-1'>
|
||||
DataSource
|
||||
<div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@ -1,27 +1,100 @@
|
||||
import type { FC } from 'react'
|
||||
import {
|
||||
useMemo,
|
||||
} from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { memo } from 'react'
|
||||
import type { DataSourceNodeType } from './types'
|
||||
import type { NodePanelProps } from '@/app/components/workflow/types'
|
||||
import VariableOrConstantInputField from '@/app/components/base/form/components/field/variable-or-constant-input'
|
||||
import VariableSelector from '@/app/components/base/form/components/field/variable-selector'
|
||||
import { GroupWithBox } from '@/app/components/workflow/nodes/_base/components/layout'
|
||||
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'
|
||||
|
||||
const Panel: FC<NodePanelProps<DataSourceNodeType>> = ({ data }) => {
|
||||
const { t } = useTranslation()
|
||||
const { output_schema = {} } = data
|
||||
const outputSchema = useMemo(() => {
|
||||
const res: any[] = []
|
||||
if (!output_schema)
|
||||
return []
|
||||
Object.keys(output_schema.properties).forEach((outputKey) => {
|
||||
const output = output_schema.properties[outputKey]
|
||||
const type = output.type
|
||||
if (type === 'object') {
|
||||
res.push({
|
||||
name: outputKey,
|
||||
value: output,
|
||||
})
|
||||
}
|
||||
else {
|
||||
res.push({
|
||||
name: outputKey,
|
||||
type: output.type === 'array'
|
||||
? `Array[${output.items?.type.slice(0, 1).toLocaleUpperCase()}${output.items?.type.slice(1)}]`
|
||||
: `${output.type.slice(0, 1).toLocaleUpperCase()}${output.type.slice(1)}`,
|
||||
description: output.description,
|
||||
})
|
||||
}
|
||||
})
|
||||
return res
|
||||
}, [output_schema])
|
||||
const hasObjectOutput = useMemo(() => {
|
||||
if (!output_schema)
|
||||
return false
|
||||
const properties = output_schema.properties
|
||||
return Object.keys(properties).some(key => properties[key].type === 'object')
|
||||
}, [output_schema])
|
||||
|
||||
const Panel: FC<NodePanelProps<DataSourceNodeType>> = () => {
|
||||
return (
|
||||
<div className='mb-2 mt-2 space-y-4 px-4'>
|
||||
datasource
|
||||
<div className='space-y-1'>
|
||||
<VariableSelector
|
||||
className='py-1'
|
||||
label='Child delimiter'
|
||||
labelOptions={{
|
||||
isRequired: true,
|
||||
}}
|
||||
/>
|
||||
<VariableOrConstantInputField
|
||||
className='py-1'
|
||||
label='Parent maximum chunk length'
|
||||
/>
|
||||
</div>
|
||||
<div >
|
||||
<GroupWithBox boxProps={{ withBorderBottom: true }}>
|
||||
|
||||
</GroupWithBox>
|
||||
<OutputVars>
|
||||
<VarItem
|
||||
name='text'
|
||||
type='string'
|
||||
description={t('workflow.nodes.tool.outputVars.text')}
|
||||
isIndent={hasObjectOutput}
|
||||
/>
|
||||
<VarItem
|
||||
name='files'
|
||||
type='array[file]'
|
||||
description={t('workflow.nodes.tool.outputVars.files.title')}
|
||||
isIndent={hasObjectOutput}
|
||||
/>
|
||||
<VarItem
|
||||
name='json'
|
||||
type='array[object]'
|
||||
description={t('workflow.nodes.tool.outputVars.json')}
|
||||
isIndent={hasObjectOutput}
|
||||
/>
|
||||
{outputSchema.map((outputItem: any) => (
|
||||
<div key={outputItem.name}>
|
||||
{outputItem.value?.type === 'object' ? (
|
||||
<StructureOutputItem
|
||||
rootClassName='code-sm-semibold text-text-secondary'
|
||||
payload={{
|
||||
schema: {
|
||||
type: Type.object,
|
||||
properties: {
|
||||
[outputItem.name]: outputItem.value,
|
||||
},
|
||||
additionalProperties: false,
|
||||
},
|
||||
}} />
|
||||
) : (
|
||||
<VarItem
|
||||
name={outputItem.name}
|
||||
type={outputItem.type.toLocaleLowerCase()}
|
||||
description={outputItem.description}
|
||||
isIndent={hasObjectOutput}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</OutputVars>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@ -3,4 +3,5 @@ import type { RAGPipelineVariables } from '@/models/pipeline'
|
||||
|
||||
export type DataSourceNodeType = CommonNodeType & {
|
||||
variables: RAGPipelineVariables
|
||||
output_schema: Record<string, any>
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user