mirror of
https://github.com/langgenius/dify.git
synced 2026-05-03 00:48:04 +08:00
datasource panel
This commit is contained in:
@ -1,5 +1,34 @@
|
||||
import { useCallback } from 'react'
|
||||
import { useStoreApi } from 'reactflow'
|
||||
import { useNodeDataUpdate } from '@/app/components/workflow/hooks'
|
||||
import type { DataSourceNodeType } from '../types'
|
||||
|
||||
export const useConfig = (id: string) => {
|
||||
const store = useStoreApi()
|
||||
const { handleNodeDataUpdateWithSyncDraft } = useNodeDataUpdate()
|
||||
|
||||
const getNodeData = useCallback(() => {
|
||||
const { getNodes } = store.getState()
|
||||
const nodes = getNodes()
|
||||
|
||||
return nodes.find(node => node.id === id)
|
||||
}, [store, id])
|
||||
|
||||
const handleNodeDataUpdate = useCallback((data: Partial<DataSourceNodeType>) => {
|
||||
handleNodeDataUpdateWithSyncDraft({
|
||||
id,
|
||||
data,
|
||||
})
|
||||
}, [id, handleNodeDataUpdateWithSyncDraft])
|
||||
const handleFileExtensionsChange = useCallback((fileExtensions: string[]) => {
|
||||
const nodeData = getNodeData()
|
||||
handleNodeDataUpdate({
|
||||
...nodeData?.data,
|
||||
fileExtensions,
|
||||
})
|
||||
}, [handleNodeDataUpdate, getNodeData])
|
||||
|
||||
return {
|
||||
id,
|
||||
handleFileExtensionsChange,
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,15 +5,27 @@ import {
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { memo } from 'react'
|
||||
import type { DataSourceNodeType } from './types'
|
||||
import { CollectionType } from '@/app/components/tools/types'
|
||||
import type { NodePanelProps } from '@/app/components/workflow/types'
|
||||
import { GroupWithBox } from '@/app/components/workflow/nodes/_base/components/layout'
|
||||
import {
|
||||
Field,
|
||||
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 TagInput from '@/app/components/base/tag-input'
|
||||
import { Type } from '../llm/types'
|
||||
import { useConfig } from './hooks/use-config'
|
||||
|
||||
const Panel: FC<NodePanelProps<DataSourceNodeType>> = ({ data }) => {
|
||||
const Panel: FC<NodePanelProps<DataSourceNodeType>> = ({ id, data }) => {
|
||||
const { t } = useTranslation()
|
||||
const { output_schema = {} } = data
|
||||
const {
|
||||
output_schema = {},
|
||||
provider_id,
|
||||
provider_type,
|
||||
fileExtensions = [],
|
||||
} = data
|
||||
const { handleFileExtensionsChange } = useConfig(id)
|
||||
const outputSchema = useMemo(() => {
|
||||
const res: any[] = []
|
||||
if (!output_schema)
|
||||
@ -48,52 +60,66 @@ const Panel: FC<NodePanelProps<DataSourceNodeType>> = ({ data }) => {
|
||||
|
||||
return (
|
||||
<div >
|
||||
<GroupWithBox boxProps={{ withBorderBottom: true }}>
|
||||
|
||||
</GroupWithBox>
|
||||
{
|
||||
provider_id === 'langgenius/file/file' && provider_type === CollectionType.datasource && (
|
||||
<GroupWithBox boxProps={{ withBorderBottom: true }}>
|
||||
<Field
|
||||
fieldTitleProps={{
|
||||
title: 'supported file formats',
|
||||
}}
|
||||
>
|
||||
<TagInput
|
||||
items={fileExtensions}
|
||||
onChange={handleFileExtensionsChange}
|
||||
placeholder='File extension, e.g. doc'
|
||||
/>
|
||||
</Field>
|
||||
</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,
|
||||
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,
|
||||
},
|
||||
}} />
|
||||
) : (
|
||||
<VarItem
|
||||
name={outputItem.name}
|
||||
type={outputItem.type.toLocaleLowerCase()}
|
||||
description={outputItem.description}
|
||||
isIndent={hasObjectOutput}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
additionalProperties: false,
|
||||
},
|
||||
}} />
|
||||
) : (
|
||||
<VarItem
|
||||
name={outputItem.name}
|
||||
type={outputItem.type.toLocaleLowerCase()}
|
||||
description={outputItem.description}
|
||||
isIndent={hasObjectOutput}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</OutputVars>
|
||||
</div>
|
||||
)
|
||||
|
||||
@ -1,7 +1,11 @@
|
||||
import type { CommonNodeType } from '@/app/components/workflow/types'
|
||||
import type { RAGPipelineVariables } from '@/models/pipeline'
|
||||
import type { CollectionType } from '@/app/components/tools/types'
|
||||
|
||||
export type DataSourceNodeType = CommonNodeType & {
|
||||
variables: RAGPipelineVariables
|
||||
output_schema: Record<string, any>
|
||||
provider_id: string
|
||||
provider_type: CollectionType
|
||||
fileExtensions?: string[]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user