52 lines
1.3 KiB
TypeScript
Raw Normal View History

2025-04-22 16:46:33 +08:00
import type { NodeDefault } from '../../types'
import type { DataSourceNodeType } from './types'
2025-06-05 16:51:01 +08:00
import { DataSourceClassification } from './types'
2025-04-25 11:32:17 +08:00
import { genNodeMetaData } from '@/app/components/workflow/utils'
import { BlockEnum } from '@/app/components/workflow/types'
2025-06-05 16:51:01 +08:00
import {
COMMON_OUTPUT,
FILE_OUTPUT,
WEBSITE_OUTPUT,
} from './constants'
2025-04-22 16:46:33 +08:00
2025-04-29 16:11:54 +08:00
const metaData = genNodeMetaData({
sort: -1,
type: BlockEnum.DataSource,
})
2025-04-22 16:46:33 +08:00
const nodeDefault: NodeDefault<DataSourceNodeType> = {
2025-04-29 16:11:54 +08:00
metaData,
2025-05-23 18:19:01 +08:00
defaultValue: {
datasource_parameters: {},
datasource_configurations: {},
},
2025-04-22 16:46:33 +08:00
checkValid() {
return {
isValid: true,
errorMessage: '',
}
},
2025-06-03 16:07:58 +08:00
getOutputVars(payload, ragVars = []) {
2025-05-27 18:44:04 +08:00
const {
provider_type,
} = payload
2025-06-05 16:51:01 +08:00
const isLocalFile = provider_type === DataSourceClassification.file
const isWebsiteCrawl = provider_type === DataSourceClassification.website
2025-05-23 18:19:01 +08:00
return [
2025-06-05 16:51:01 +08:00
...COMMON_OUTPUT.map(item => ({ variable: item.name, type: item.type })),
2025-05-23 18:19:01 +08:00
...(
isLocalFile
2025-06-05 16:51:01 +08:00
? FILE_OUTPUT.map(item => ({ variable: item.name, type: item.type }))
: []
),
...(
isWebsiteCrawl
? WEBSITE_OUTPUT.map(item => ({ variable: item.name, type: item.type }))
2025-05-23 18:19:01 +08:00
: []
),
2025-06-03 16:07:58 +08:00
...ragVars,
2025-05-23 18:19:01 +08:00
]
},
2025-04-22 16:46:33 +08:00
}
export default nodeDefault