datasource

This commit is contained in:
zxhlyh
2025-05-23 16:27:19 +08:00
parent c9bf99a1e2
commit e19adbbbc5
16 changed files with 293 additions and 165 deletions

View File

@ -7,6 +7,7 @@ import type {
OnSelectBlock,
ToolWithProvider,
} from '../types'
import type { ToolDefaultValue } from './types'
import Tools from './tools'
import { ViewType } from './view-type-select'
import cn from '@/utils/classnames'
@ -30,8 +31,14 @@ const DataSources = ({
const pluginRef = useRef<ListRef>(null)
const wrapElemRef = useRef<HTMLDivElement>(null)
const formatedDataSources = dataSources.map(item => ({ ...item, tools: item.datasources || [] }))
const handleSelect = useCallback<OnSelectBlock>((_, toolDefaultValue) => {
onSelect(BlockEnum.DataSource, toolDefaultValue)
const handleSelect = useCallback((_: any, toolDefaultValue: ToolDefaultValue) => {
onSelect(BlockEnum.DataSource, toolDefaultValue && {
provider_id: toolDefaultValue?.provider_id,
provider_type: toolDefaultValue?.provider_type,
provider_name: toolDefaultValue?.provider_name,
datasource_name: toolDefaultValue?.tool_name,
datasource_label: toolDefaultValue?.tool_label,
})
}, [onSelect])
return (
@ -45,7 +52,7 @@ const DataSources = ({
className={toolContentClassName}
showWorkflowEmpty={false}
tools={formatedDataSources}
onSelect={handleSelect}
onSelect={handleSelect as OnSelectBlock}
viewType={ViewType.flat}
hasSearchText={!!searchText}
/>

View File

@ -4,9 +4,9 @@ import { useAllBuiltInTools, useAllCustomTools, useAllWorkflowTools } from '@/se
import type {
BlockEnum,
NodeDefault,
OnSelectBlock,
ToolWithProvider,
} from '../types'
import type { ToolDefaultValue } from './types'
import { TabsEnum } from './types'
import Blocks from './blocks'
import AllTools from './all-tools'
@ -16,7 +16,7 @@ export type TabsProps = {
activeTab: TabsEnum
searchText: string
tags: string[]
onSelect: (type: BlockEnum, tool?: ToolDefaultValue) => void
onSelect: OnSelectBlock
availableBlocksTypes?: BlockEnum[]
blocks: NodeDefault[]
dataSources?: ToolWithProvider[]

View File

@ -33,6 +33,14 @@ export type ToolDefaultValue = {
output_schema: Record<string, any>
}
export type DataSourceDefaultValue = {
provider_id: string
provider_type: string
provider_name: string
datasource_name: string
datasource_label: string
}
export type ToolValue = {
provider_name: string
tool_name: string