2025-05-21 16:37:02 +08:00
|
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
import { AddDocumentsStep } from './types'
|
2025-05-22 14:49:40 +08:00
|
|
|
import type { DataSourceOption, Datasource } from '@/app/components/rag-pipeline/components/panel/test-run/types'
|
|
|
|
import { useMemo } from 'react'
|
|
|
|
import { BlockEnum, type Node } from '@/app/components/workflow/types'
|
|
|
|
import type { DataSourceNodeType } from '@/app/components/workflow/nodes/data-source/types'
|
2025-05-27 11:01:38 +08:00
|
|
|
import type { DatasourceType } from '@/models/pipeline'
|
2025-05-21 16:37:02 +08:00
|
|
|
|
|
|
|
export const useAddDocumentsSteps = () => {
|
|
|
|
const { t } = useTranslation()
|
|
|
|
const steps = [
|
|
|
|
{
|
|
|
|
label: t('datasetPipeline.addDocuments.steps.chooseDatasource'),
|
|
|
|
value: AddDocumentsStep.dataSource,
|
|
|
|
},
|
|
|
|
{
|
2025-05-22 23:05:58 +08:00
|
|
|
label: t('datasetPipeline.addDocuments.steps.processDocuments'),
|
2025-05-21 16:37:02 +08:00
|
|
|
value: AddDocumentsStep.processDocuments,
|
|
|
|
},
|
|
|
|
{
|
2025-05-22 23:05:58 +08:00
|
|
|
label: t('datasetPipeline.addDocuments.steps.processingDocuments'),
|
2025-05-21 16:37:02 +08:00
|
|
|
value: AddDocumentsStep.processingDocuments,
|
|
|
|
},
|
|
|
|
]
|
|
|
|
return steps
|
|
|
|
}
|
2025-05-22 14:49:40 +08:00
|
|
|
|
|
|
|
export const useDatasourceOptions = (pipelineNodes: Node<DataSourceNodeType>[]) => {
|
2025-05-27 11:01:38 +08:00
|
|
|
const datasourceNodes = pipelineNodes.filter(node => node.data.type === BlockEnum.DataSource)
|
2025-05-22 14:49:40 +08:00
|
|
|
const datasources: Datasource[] = useMemo(() => {
|
|
|
|
return datasourceNodes.map((node) => {
|
|
|
|
return {
|
|
|
|
nodeId: node.id,
|
2025-05-27 11:01:38 +08:00
|
|
|
type: node.data.provider_type as DatasourceType,
|
|
|
|
variables: node.data.variables || [],
|
|
|
|
description: node.data.desc || '',
|
|
|
|
docTitle: '', // todo: Add docTitle and docLink if needed, or remove these properties if not used
|
|
|
|
docLink: '',
|
2025-05-27 14:39:52 +08:00
|
|
|
fileExtensions: node.data.fileExtensions || [],
|
2025-05-22 14:49:40 +08:00
|
|
|
}
|
|
|
|
})
|
2025-05-27 11:01:38 +08:00
|
|
|
}, [datasourceNodes])
|
2025-05-22 14:49:40 +08:00
|
|
|
|
|
|
|
const options = useMemo(() => {
|
|
|
|
const options: DataSourceOption[] = []
|
2025-05-27 11:01:38 +08:00
|
|
|
datasourceNodes.forEach((node) => {
|
|
|
|
const label = node.data.title
|
|
|
|
options.push({
|
|
|
|
label,
|
|
|
|
value: node.id,
|
2025-05-27 14:17:55 +08:00
|
|
|
data: node.data,
|
2025-05-27 11:01:38 +08:00
|
|
|
})
|
2025-05-22 14:49:40 +08:00
|
|
|
})
|
|
|
|
return options
|
2025-05-27 11:01:38 +08:00
|
|
|
}, [datasourceNodes])
|
2025-05-22 14:49:40 +08:00
|
|
|
|
|
|
|
return { datasources, options }
|
|
|
|
}
|