2025-04-22 16:46:33 +08:00
|
|
|
import type { FC } from 'react'
|
2025-05-23 10:46:28 +08:00
|
|
|
import { useTranslation } from 'react-i18next'
|
2025-04-22 16:46:33 +08:00
|
|
|
import { memo } from 'react'
|
|
|
|
import type { DataSourceNodeType } from './types'
|
2025-05-23 11:50:36 +08:00
|
|
|
import { CollectionType } from '@/app/components/tools/types'
|
2025-04-22 16:46:33 +08:00
|
|
|
import type { NodePanelProps } from '@/app/components/workflow/types'
|
2025-05-23 16:27:19 +08:00
|
|
|
import { BoxGroupField } from '@/app/components/workflow/nodes/_base/components/layout'
|
2025-05-23 10:46:28 +08:00
|
|
|
import OutputVars, { VarItem } from '@/app/components/workflow/nodes/_base/components/output-vars'
|
2025-05-23 11:50:36 +08:00
|
|
|
import TagInput from '@/app/components/base/tag-input'
|
|
|
|
import { useConfig } from './hooks/use-config'
|
2025-05-23 10:46:28 +08:00
|
|
|
|
2025-05-23 11:50:36 +08:00
|
|
|
const Panel: FC<NodePanelProps<DataSourceNodeType>> = ({ id, data }) => {
|
2025-05-23 10:46:28 +08:00
|
|
|
const { t } = useTranslation()
|
2025-05-23 11:50:36 +08:00
|
|
|
const {
|
|
|
|
provider_id,
|
|
|
|
provider_type,
|
|
|
|
fileExtensions = [],
|
|
|
|
} = data
|
|
|
|
const { handleFileExtensionsChange } = useConfig(id)
|
2025-05-23 16:27:19 +08:00
|
|
|
const isLocalFile = provider_id === 'langgenius/file/file' && provider_type === CollectionType.datasource
|
2025-04-22 16:46:33 +08:00
|
|
|
|
|
|
|
return (
|
2025-05-23 10:46:28 +08:00
|
|
|
<div >
|
2025-05-23 11:50:36 +08:00
|
|
|
{
|
2025-05-23 16:27:19 +08:00
|
|
|
isLocalFile && (
|
|
|
|
<BoxGroupField
|
|
|
|
boxGroupProps={{
|
|
|
|
boxProps: { withBorderBottom: true },
|
|
|
|
}}
|
|
|
|
fieldProps={{
|
|
|
|
fieldTitleProps: {
|
2025-05-23 14:25:38 +08:00
|
|
|
title: t('workflow.nodes.dataSource.supportedFileFormats'),
|
2025-05-23 16:27:19 +08:00
|
|
|
},
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<div className='rounded-lg bg-components-input-bg-normal p-1 pt-0'>
|
|
|
|
<TagInput
|
|
|
|
items={fileExtensions}
|
|
|
|
onChange={handleFileExtensionsChange}
|
|
|
|
placeholder={t('workflow.nodes.dataSource.supportedFileFormatsPlaceholder')}
|
|
|
|
inputClassName='bg-transparent'
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</BoxGroupField>
|
2025-05-23 11:50:36 +08:00
|
|
|
)
|
|
|
|
}
|
2025-05-23 10:46:28 +08:00
|
|
|
<OutputVars>
|
|
|
|
<VarItem
|
2025-05-23 16:27:19 +08:00
|
|
|
name='datasource_type'
|
2025-05-23 11:50:36 +08:00
|
|
|
type='string'
|
2025-05-23 16:27:19 +08:00
|
|
|
description={'local_file, online_document, website_crawl'}
|
2025-05-23 11:50:36 +08:00
|
|
|
/>
|
2025-05-23 16:27:19 +08:00
|
|
|
{
|
|
|
|
isLocalFile && (
|
|
|
|
<VarItem
|
|
|
|
name='file'
|
|
|
|
type='Object'
|
|
|
|
description={'file'}
|
|
|
|
subItems={[
|
|
|
|
{
|
|
|
|
name: 'type',
|
|
|
|
type: 'string',
|
|
|
|
description: '',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'upload_file_id',
|
|
|
|
type: 'string',
|
|
|
|
description: '',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'name',
|
|
|
|
type: 'string',
|
|
|
|
description: '',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'size',
|
|
|
|
type: 'number',
|
|
|
|
description: '',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'extension',
|
|
|
|
type: 'string',
|
|
|
|
description: '',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'mime_type',
|
|
|
|
type: 'string',
|
|
|
|
description: '',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'upload_file_url',
|
|
|
|
type: 'string',
|
|
|
|
description: '',
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
2025-05-23 10:46:28 +08:00
|
|
|
</OutputVars>
|
2025-04-22 16:46:33 +08:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default memo(Panel)
|