datasource list

This commit is contained in:
zxhlyh 2025-05-26 14:13:28 +08:00
parent 324c0d7b4c
commit b5f88c77a3
8 changed files with 71 additions and 10 deletions

View File

@ -3,6 +3,8 @@ import type { StateCreator } from 'zustand'
import type {
ToolWithProvider,
} from '@/app/components/workflow/types'
import type { DataSourceItem } from '@/app/components/workflow/block-selector/types'
import { transformDataSourceToTool } from '@/app/components/workflow/block-selector/utils'
export type RagPipelineSliceShape = {
pipelineId: string
@ -13,7 +15,7 @@ export type RagPipelineSliceShape = {
ragPipelineVariables: RAGPipelineVariables
setRagPipelineVariables: (ragPipelineVariables: RAGPipelineVariables) => void
dataSourceList: ToolWithProvider[]
setDataSourceList: (dataSourceList: ToolWithProvider[]) => void
setDataSourceList: (dataSourceList: DataSourceItem[]) => void
}
export type CreateRagPipelineSliceSlice = StateCreator<RagPipelineSliceShape>
@ -26,5 +28,8 @@ export const createRagPipelineSliceSlice: StateCreator<RagPipelineSliceShape> =
ragPipelineVariables: [],
setRagPipelineVariables: (ragPipelineVariables: RAGPipelineVariables) => set(() => ({ ragPipelineVariables })),
dataSourceList: [],
setDataSourceList: (dataSourceList: ToolWithProvider[]) => set(() => ({ dataSourceList })),
setDataSourceList: (dataSourceList: DataSourceItem[]) => {
const formatedDataSourceList = dataSourceList.map(item => transformDataSourceToTool(item))
set(() => ({ dataSourceList: formatedDataSourceList }))
},
})

View File

@ -30,7 +30,6 @@ const DataSources = ({
}: AllToolsProps) => {
const pluginRef = useRef<ListRef>(null)
const wrapElemRef = useRef<HTMLDivElement>(null)
const formatedDataSources = dataSources.map(item => ({ ...item, tools: item.datasources || [] }))
const handleSelect = useCallback((_: any, toolDefaultValue: ToolDefaultValue) => {
onSelect(BlockEnum.DataSource, toolDefaultValue && {
provider_id: toolDefaultValue?.provider_id,
@ -52,7 +51,7 @@ const DataSources = ({
<Tools
className={toolContentClassName}
showWorkflowEmpty={false}
tools={formatedDataSources}
tools={dataSources}
onSelect={handleSelect as OnSelectBlock}
viewType={ViewType.flat}
hasSearchText={!!searchText}

View File

@ -55,6 +55,7 @@ const Blocks = ({
}
}
*/
console.log(tools, 'tools')
const { letters, groups: withLetterAndGroupViewToolsData } = groupItems(tools, tool => tool.label[language][0])
const treeViewToolsData = useMemo(() => {
const result: Record<string, ToolWithProvider[]> = {}

View File

@ -1,3 +1,5 @@
import type { TypeWithI18N } from '@/app/components/header/account-setting/model-provider-page/declarations'
export enum TabsEnum {
Blocks = 'blocks',
Tools = 'tools',
@ -51,3 +53,32 @@ export type ToolValue = {
enabled?: boolean
extra?: Record<string, any>
}
export type DataSourceItem = {
plugin_id: string
plugin_unique_identifier: string
provider: string
declaration: {
credentials_schema: any[]
provider_type: string
identity: {
author: string
description: TypeWithI18N
icon: string | { background: string; content: string }
label: TypeWithI18N
name: string
tags: string[]
}
datasources: {
description: TypeWithI18N
identity: {
author: string
icon?: string | { background: string; content: string }
label: TypeWithI18N
name: string
provider: string
}
parameters: any[]
}[]
}
}

View File

@ -0,0 +1,31 @@
import { CollectionType } from '@/app/components/tools/types'
import type { Tool } from '@/app/components/tools/types'
import type { DataSourceItem } from './types'
export const transformDataSourceToTool = (dataSourceItem: DataSourceItem) => {
return {
id: dataSourceItem.plugin_unique_identifier,
name: dataSourceItem.declaration.identity.name,
author: dataSourceItem.declaration.identity.author,
description: dataSourceItem.declaration.identity.description,
icon: dataSourceItem.declaration.identity.icon,
label: dataSourceItem.declaration.identity.label,
type: CollectionType.datasource,
team_credentials: {},
is_team_authorization: false,
allow_delete: true,
labels: dataSourceItem.declaration.identity.tags || [],
plugin_id: dataSourceItem.plugin_id,
tools: dataSourceItem.declaration.datasources.map((datasource) => {
return {
name: datasource.identity.name,
author: datasource.identity.author,
label: datasource.identity.label,
description: datasource.description,
parameters: datasource.parameters,
labels: [],
output_schema: {},
} as Tool
}),
}
}

View File

@ -519,8 +519,6 @@ const formatItem = (
const isFile = v.type === VarType.file
const children = (() => {
if (isFile) {
if (v.children)
return v.children
return OUTPUT_FILE_SUB_VARIABLES.map((key) => {
return {
variable: key,
@ -539,8 +537,6 @@ const formatItem = (
const isFile = v.type === VarType.file
const { children } = (() => {
if (isFile) {
if (v.children)
return { children: v.children }
return {
children: OUTPUT_FILE_SUB_VARIABLES.map((key) => {
return {

View File

@ -57,7 +57,6 @@ const Panel: FC<NodePanelProps<DataSourceNodeType>> = ({ id, data }) => {
name={OUTPUT_VARIABLES_MAP.file.name}
type={OUTPUT_VARIABLES_MAP.file.type}
description={OUTPUT_VARIABLES_MAP.file.description}
subItems={OUTPUT_VARIABLES_MAP.file.subItems}
/>
)
}

View File

@ -417,7 +417,6 @@ export type MoreInfo = {
export type ToolWithProvider = Collection & {
tools: Tool[]
datasources?: Tool[]
}
export enum SupportUploadFileTypes {