| import { useCallback, useEffect } from 'react' | import { useCallback, useEffect } from 'react' | ||||
| import { useDatasourceOptions } from '../hooks' | import { useDatasourceOptions } from '../hooks' | ||||
| import OptionCard from './option-card' | import OptionCard from './option-card' | ||||
| import { File, Watercrawl } from '@/app/components/base/icons/src/public/knowledge' | |||||
| import { Notion } from '@/app/components/base/icons/src/public/common' | |||||
| import { Jina } from '@/app/components/base/icons/src/public/llm' | |||||
| import { DataSourceType } from '@/models/datasets' | |||||
| import { DataSourceProvider } from '@/models/common' | |||||
| import type { Datasource } from '../types' | import type { Datasource } from '../types' | ||||
| type DataSourceOptionsProps = { | type DataSourceOptionsProps = { | ||||
| onSelect: (option: Datasource) => void | onSelect: (option: Datasource) => void | ||||
| } | } | ||||
| // TODO: replace all icons with tool icon_url | |||||
| const DATA_SOURCE_ICONS = { | |||||
| [DataSourceType.FILE]: File as React.FC<React.SVGProps<SVGSVGElement>>, | |||||
| [DataSourceType.NOTION]: Notion as React.FC<React.SVGProps<SVGSVGElement>>, | |||||
| [DataSourceProvider.fireCrawl]: '🔥', | |||||
| [DataSourceProvider.jinaReader]: Jina as React.FC<React.SVGProps<SVGSVGElement>>, | |||||
| [DataSourceProvider.waterCrawl]: Watercrawl as React.FC<React.SVGProps<SVGSVGElement>>, | |||||
| } | |||||
| type KeyType = keyof typeof DATA_SOURCE_ICONS | |||||
| const DataSourceOptions = ({ | const DataSourceOptions = ({ | ||||
| datasourceNodeId, | datasourceNodeId, | ||||
| onSelect, | onSelect, | ||||
| <OptionCard | <OptionCard | ||||
| key={option.value} | key={option.value} | ||||
| label={option.label} | label={option.label} | ||||
| nodeData={option.data} | |||||
| selected={datasourceNodeId === option.value} | selected={datasourceNodeId === option.value} | ||||
| Icon={DATA_SOURCE_ICONS[option.type as KeyType]} | |||||
| onClick={handelSelect.bind(null, option.value)} | onClick={handelSelect.bind(null, option.value)} | ||||
| /> | /> | ||||
| ))} | ))} |
| import React from 'react' | import React from 'react' | ||||
| import cn from '@/utils/classnames' | import cn from '@/utils/classnames' | ||||
| import BlockIcon from '@/app/components/workflow/block-icon' | |||||
| import { BlockEnum } from '@/app/components/workflow/types' | |||||
| import type { DataSourceNodeType } from '@/app/components/workflow/nodes/data-source/types' | |||||
| import { useToolIcon } from '@/app/components/workflow/hooks' | |||||
| type OptionCardProps = { | type OptionCardProps = { | ||||
| label: string | label: string | ||||
| Icon: React.FC<React.SVGProps<SVGSVGElement>> | string | |||||
| selected: boolean | selected: boolean | ||||
| nodeData: DataSourceNodeType | |||||
| onClick?: () => void | onClick?: () => void | ||||
| } | } | ||||
| const OptionCard = ({ | const OptionCard = ({ | ||||
| label, | label, | ||||
| Icon, | |||||
| selected, | selected, | ||||
| nodeData, | |||||
| onClick, | onClick, | ||||
| }: OptionCardProps) => { | }: OptionCardProps) => { | ||||
| const toolIcon = useToolIcon(nodeData) | |||||
| return ( | return ( | ||||
| <div | <div | ||||
| className={cn( | className={cn( | ||||
| onClick={onClick} | onClick={onClick} | ||||
| > | > | ||||
| <div className='flex size-7 items-center justify-center rounded-lg border-[0.5px] border-components-panel-border bg-background-default-dodge p-1'> | <div className='flex size-7 items-center justify-center rounded-lg border-[0.5px] border-components-panel-border bg-background-default-dodge p-1'> | ||||
| { | |||||
| typeof Icon === 'string' | |||||
| ? <div className='text-[18px] leading-[18px]'>{Icon}</div> | |||||
| : <Icon className='size-5' /> | |||||
| } | |||||
| <BlockIcon | |||||
| type={BlockEnum.DataSource} | |||||
| toolIcon={toolIcon} | |||||
| /> | |||||
| </div> | </div> | ||||
| <div className={cn('system-sm-medium text-text-secondary', selected && 'text-primary')}> | <div className={cn('system-sm-medium text-text-secondary', selected && 'text-primary')}> | ||||
| {label} | {label} |
| type: node.data.provider_type as DatasourceType, | type: node.data.provider_type as DatasourceType, | ||||
| variables: node.data.variables || [], | variables: node.data.variables || [], | ||||
| description: node.data.desc || '', | description: node.data.desc || '', | ||||
| docTitle: '', // todo: Add docTitle and docLink if needed, or remove these properties if not used | |||||
| docTitle: '', // todo: Add docTitle and docLink | |||||
| docLink: '', | docLink: '', | ||||
| } | } | ||||
| }) | }) | ||||
| const options = useMemo(() => { | const options = useMemo(() => { | ||||
| const options: DataSourceOption[] = [] | const options: DataSourceOption[] = [] | ||||
| datasourceNodes.forEach((node) => { | datasourceNodes.forEach((node) => { | ||||
| const type = node.data.provider_type as DatasourceType | |||||
| const label = node.data.title | const label = node.data.title | ||||
| options.push({ | options.push({ | ||||
| label, | label, | ||||
| value: node.id, | value: node.id, | ||||
| type, | |||||
| data: node.data, | |||||
| }) | }) | ||||
| }) | }) | ||||
| return options | return options |
| import type { DataSourceNodeType } from '@/app/components/workflow/nodes/data-source/types' | |||||
| import type { DatasourceType, RAGPipelineVariables } from '@/models/pipeline' | import type { DatasourceType, RAGPipelineVariables } from '@/models/pipeline' | ||||
| export enum TestRunStep { | export enum TestRunStep { | ||||
| export type DataSourceOption = { | export type DataSourceOption = { | ||||
| label: string | label: string | ||||
| value: string | value: string | ||||
| type: DatasourceType | |||||
| data: DataSourceNodeType | |||||
| } | } | ||||
| export type Datasource = { | export type Datasource = { |
| import type { TransferMethod } from '@/types/app' | import type { TransferMethod } from '@/types/app' | ||||
| export enum DatasourceType { | export enum DatasourceType { | ||||
| localFile = 'local-file', | |||||
| onlineDocument = 'online-document', | |||||
| websiteCrawl = 'website-crawl', | |||||
| localFile = 'local_file', | |||||
| onlineDocument = 'online_document', | |||||
| websiteCrawl = 'website_crawl', | |||||
| } | } | ||||
| export type PipelineTemplateListParams = { | export type PipelineTemplateListParams = { |