mirror of
https://github.com/langgenius/dify.git
synced 2025-11-11 08:53:17 +00:00
datasource list
This commit is contained in:
parent
324c0d7b4c
commit
b5f88c77a3
@ -3,6 +3,8 @@ import type { StateCreator } from 'zustand'
|
|||||||
import type {
|
import type {
|
||||||
ToolWithProvider,
|
ToolWithProvider,
|
||||||
} from '@/app/components/workflow/types'
|
} 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 = {
|
export type RagPipelineSliceShape = {
|
||||||
pipelineId: string
|
pipelineId: string
|
||||||
@ -13,7 +15,7 @@ export type RagPipelineSliceShape = {
|
|||||||
ragPipelineVariables: RAGPipelineVariables
|
ragPipelineVariables: RAGPipelineVariables
|
||||||
setRagPipelineVariables: (ragPipelineVariables: RAGPipelineVariables) => void
|
setRagPipelineVariables: (ragPipelineVariables: RAGPipelineVariables) => void
|
||||||
dataSourceList: ToolWithProvider[]
|
dataSourceList: ToolWithProvider[]
|
||||||
setDataSourceList: (dataSourceList: ToolWithProvider[]) => void
|
setDataSourceList: (dataSourceList: DataSourceItem[]) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
export type CreateRagPipelineSliceSlice = StateCreator<RagPipelineSliceShape>
|
export type CreateRagPipelineSliceSlice = StateCreator<RagPipelineSliceShape>
|
||||||
@ -26,5 +28,8 @@ export const createRagPipelineSliceSlice: StateCreator<RagPipelineSliceShape> =
|
|||||||
ragPipelineVariables: [],
|
ragPipelineVariables: [],
|
||||||
setRagPipelineVariables: (ragPipelineVariables: RAGPipelineVariables) => set(() => ({ ragPipelineVariables })),
|
setRagPipelineVariables: (ragPipelineVariables: RAGPipelineVariables) => set(() => ({ ragPipelineVariables })),
|
||||||
dataSourceList: [],
|
dataSourceList: [],
|
||||||
setDataSourceList: (dataSourceList: ToolWithProvider[]) => set(() => ({ dataSourceList })),
|
setDataSourceList: (dataSourceList: DataSourceItem[]) => {
|
||||||
|
const formatedDataSourceList = dataSourceList.map(item => transformDataSourceToTool(item))
|
||||||
|
set(() => ({ dataSourceList: formatedDataSourceList }))
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
@ -30,7 +30,6 @@ const DataSources = ({
|
|||||||
}: AllToolsProps) => {
|
}: AllToolsProps) => {
|
||||||
const pluginRef = useRef<ListRef>(null)
|
const pluginRef = useRef<ListRef>(null)
|
||||||
const wrapElemRef = useRef<HTMLDivElement>(null)
|
const wrapElemRef = useRef<HTMLDivElement>(null)
|
||||||
const formatedDataSources = dataSources.map(item => ({ ...item, tools: item.datasources || [] }))
|
|
||||||
const handleSelect = useCallback((_: any, toolDefaultValue: ToolDefaultValue) => {
|
const handleSelect = useCallback((_: any, toolDefaultValue: ToolDefaultValue) => {
|
||||||
onSelect(BlockEnum.DataSource, toolDefaultValue && {
|
onSelect(BlockEnum.DataSource, toolDefaultValue && {
|
||||||
provider_id: toolDefaultValue?.provider_id,
|
provider_id: toolDefaultValue?.provider_id,
|
||||||
@ -52,7 +51,7 @@ const DataSources = ({
|
|||||||
<Tools
|
<Tools
|
||||||
className={toolContentClassName}
|
className={toolContentClassName}
|
||||||
showWorkflowEmpty={false}
|
showWorkflowEmpty={false}
|
||||||
tools={formatedDataSources}
|
tools={dataSources}
|
||||||
onSelect={handleSelect as OnSelectBlock}
|
onSelect={handleSelect as OnSelectBlock}
|
||||||
viewType={ViewType.flat}
|
viewType={ViewType.flat}
|
||||||
hasSearchText={!!searchText}
|
hasSearchText={!!searchText}
|
||||||
|
|||||||
@ -55,6 +55,7 @@ const Blocks = ({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
console.log(tools, 'tools')
|
||||||
const { letters, groups: withLetterAndGroupViewToolsData } = groupItems(tools, tool => tool.label[language][0])
|
const { letters, groups: withLetterAndGroupViewToolsData } = groupItems(tools, tool => tool.label[language][0])
|
||||||
const treeViewToolsData = useMemo(() => {
|
const treeViewToolsData = useMemo(() => {
|
||||||
const result: Record<string, ToolWithProvider[]> = {}
|
const result: Record<string, ToolWithProvider[]> = {}
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
import type { TypeWithI18N } from '@/app/components/header/account-setting/model-provider-page/declarations'
|
||||||
|
|
||||||
export enum TabsEnum {
|
export enum TabsEnum {
|
||||||
Blocks = 'blocks',
|
Blocks = 'blocks',
|
||||||
Tools = 'tools',
|
Tools = 'tools',
|
||||||
@ -51,3 +53,32 @@ export type ToolValue = {
|
|||||||
enabled?: boolean
|
enabled?: boolean
|
||||||
extra?: Record<string, any>
|
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[]
|
||||||
|
}[]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
31
web/app/components/workflow/block-selector/utils.ts
Normal file
31
web/app/components/workflow/block-selector/utils.ts
Normal 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
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -519,8 +519,6 @@ const formatItem = (
|
|||||||
const isFile = v.type === VarType.file
|
const isFile = v.type === VarType.file
|
||||||
const children = (() => {
|
const children = (() => {
|
||||||
if (isFile) {
|
if (isFile) {
|
||||||
if (v.children)
|
|
||||||
return v.children
|
|
||||||
return OUTPUT_FILE_SUB_VARIABLES.map((key) => {
|
return OUTPUT_FILE_SUB_VARIABLES.map((key) => {
|
||||||
return {
|
return {
|
||||||
variable: key,
|
variable: key,
|
||||||
@ -539,8 +537,6 @@ const formatItem = (
|
|||||||
const isFile = v.type === VarType.file
|
const isFile = v.type === VarType.file
|
||||||
const { children } = (() => {
|
const { children } = (() => {
|
||||||
if (isFile) {
|
if (isFile) {
|
||||||
if (v.children)
|
|
||||||
return { children: v.children }
|
|
||||||
return {
|
return {
|
||||||
children: OUTPUT_FILE_SUB_VARIABLES.map((key) => {
|
children: OUTPUT_FILE_SUB_VARIABLES.map((key) => {
|
||||||
return {
|
return {
|
||||||
|
|||||||
@ -57,7 +57,6 @@ const Panel: FC<NodePanelProps<DataSourceNodeType>> = ({ id, data }) => {
|
|||||||
name={OUTPUT_VARIABLES_MAP.file.name}
|
name={OUTPUT_VARIABLES_MAP.file.name}
|
||||||
type={OUTPUT_VARIABLES_MAP.file.type}
|
type={OUTPUT_VARIABLES_MAP.file.type}
|
||||||
description={OUTPUT_VARIABLES_MAP.file.description}
|
description={OUTPUT_VARIABLES_MAP.file.description}
|
||||||
subItems={OUTPUT_VARIABLES_MAP.file.subItems}
|
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -417,7 +417,6 @@ export type MoreInfo = {
|
|||||||
|
|
||||||
export type ToolWithProvider = Collection & {
|
export type ToolWithProvider = Collection & {
|
||||||
tools: Tool[]
|
tools: Tool[]
|
||||||
datasources?: Tool[]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum SupportUploadFileTypes {
|
export enum SupportUploadFileTypes {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user