datasource

pull/21398/head
zxhlyh 11 months ago
parent 90ca98ff3a
commit f0413f359a

@ -23,6 +23,7 @@ export const useNodesSyncDraft = () => {
edges, edges,
transform, transform,
} = store.getState() } = store.getState()
const nodes = getNodes()
const [x, y, zoom] = transform const [x, y, zoom] = transform
const { const {
pipelineId, pipelineId,
@ -32,8 +33,6 @@ export const useNodesSyncDraft = () => {
} = workflowStore.getState() } = workflowStore.getState()
if (pipelineId) { if (pipelineId) {
const nodes = getNodes()
const producedNodes = produce(nodes, (draft) => { const producedNodes = produce(nodes, (draft) => {
draft.forEach((node) => { draft.forEach((node) => {
Object.keys(node.data).forEach((key) => { Object.keys(node.data).forEach((key) => {

@ -32,7 +32,7 @@ const DataSources = ({
const wrapElemRef = useRef<HTMLDivElement>(null) const wrapElemRef = useRef<HTMLDivElement>(null)
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, plugin_id: toolDefaultValue?.provider_id,
provider_type: toolDefaultValue?.provider_type, provider_type: toolDefaultValue?.provider_type,
provider_name: toolDefaultValue?.provider_name, provider_name: toolDefaultValue?.provider_name,
datasource_name: toolDefaultValue?.tool_name, datasource_name: toolDefaultValue?.tool_name,

@ -36,7 +36,7 @@ export type ToolDefaultValue = {
} }
export type DataSourceDefaultValue = { export type DataSourceDefaultValue = {
provider_id: string plugin_id: string
provider_type: string provider_type: string
provider_name: string provider_name: string
datasource_name: string datasource_name: string

@ -5,7 +5,7 @@ export const transformDataSourceToTool = (dataSourceItem: DataSourceItem) => {
return { return {
id: dataSourceItem.plugin_id, id: dataSourceItem.plugin_id,
provider: dataSourceItem.provider, provider: dataSourceItem.provider,
name: dataSourceItem.declaration.identity.name, name: dataSourceItem.provider,
author: dataSourceItem.declaration.identity.author, author: dataSourceItem.declaration.identity.author,
description: dataSourceItem.declaration.identity.description, description: dataSourceItem.declaration.identity.description,
icon: dataSourceItem.declaration.identity.icon, icon: dataSourceItem.declaration.identity.icon,

@ -375,4 +375,4 @@ const WorkflowWithDefaultContext = ({
) )
} }
export default memo(WorkflowWithDefaultContext) export default WorkflowWithDefaultContext

@ -23,13 +23,16 @@ export const DEFAULT_FILE_EXTENSIONS_IN_LOCAL_FILE_DATA_SOURCE = [
'html', 'html',
] ]
export const OUTPUT_VARIABLES_MAP = { export const COMMON_OUTPUT = [
datasource_type: { {
name: 'datasource_type', name: 'datasource_type',
type: VarType.string, type: VarType.string,
description: 'local_file, online_document, website_crawl', description: 'local_file, online_document, website_crawl',
}, },
file: { ]
export const FILE_OUTPUT = [
{
name: 'file', name: 'file',
type: VarType.file, type: VarType.file,
description: 'file', description: 'file',
@ -76,4 +79,27 @@ export const OUTPUT_VARIABLES_MAP = {
}, },
], ],
}, },
} ]
export const WEBSITE_OUTPUT = [
{
name: 'source_url',
type: VarType.string,
description: 'The URL of the crawled website',
},
{
name: 'content',
type: VarType.string,
description: 'The content of the crawled website',
},
{
name: 'title',
type: VarType.string,
description: 'The title of the crawled website',
},
{
name: 'description',
type: VarType.string,
description: 'The description of the crawled website',
},
]

@ -1,8 +1,13 @@
import type { NodeDefault } from '../../types' import type { NodeDefault } from '../../types'
import type { DataSourceNodeType } from './types' import type { DataSourceNodeType } from './types'
import { DataSourceClassification } from './types'
import { genNodeMetaData } from '@/app/components/workflow/utils' import { genNodeMetaData } from '@/app/components/workflow/utils'
import { BlockEnum } from '@/app/components/workflow/types' import { BlockEnum } from '@/app/components/workflow/types'
import { OUTPUT_VARIABLES_MAP } from './constants' import {
COMMON_OUTPUT,
FILE_OUTPUT,
WEBSITE_OUTPUT,
} from './constants'
const metaData = genNodeMetaData({ const metaData = genNodeMetaData({
sort: -1, sort: -1,
@ -24,20 +29,18 @@ const nodeDefault: NodeDefault<DataSourceNodeType> = {
const { const {
provider_type, provider_type,
} = payload } = payload
const isLocalFile = provider_type === 'local_file' const isLocalFile = provider_type === DataSourceClassification.file
const isWebsiteCrawl = provider_type === DataSourceClassification.website
return [ return [
{ ...COMMON_OUTPUT.map(item => ({ variable: item.name, type: item.type })),
variable: OUTPUT_VARIABLES_MAP.datasource_type.name,
type: OUTPUT_VARIABLES_MAP.datasource_type.type,
},
...( ...(
isLocalFile isLocalFile
? [ ? FILE_OUTPUT.map(item => ({ variable: item.name, type: item.type }))
{ : []
variable: OUTPUT_VARIABLES_MAP.file.name, ),
type: OUTPUT_VARIABLES_MAP.file.type, ...(
}, isWebsiteCrawl
] ? WEBSITE_OUTPUT.map(item => ({ variable: item.name, type: item.type }))
: [] : []
), ),
...ragVars, ...ragVars,

@ -8,6 +8,7 @@ import { useTranslation } from 'react-i18next'
import { memo } from 'react' import { memo } from 'react'
import { useBoolean } from 'ahooks' import { useBoolean } from 'ahooks'
import type { DataSourceNodeType } from './types' import type { DataSourceNodeType } from './types'
import { DataSourceClassification } from './types'
import type { NodePanelProps } from '@/app/components/workflow/types' import type { NodePanelProps } from '@/app/components/workflow/types'
import { import {
BoxGroupField, BoxGroupField,
@ -17,7 +18,11 @@ import OutputVars, { VarItem } from '@/app/components/workflow/nodes/_base/compo
import TagInput from '@/app/components/base/tag-input' import TagInput from '@/app/components/base/tag-input'
import { useNodesReadOnly } from '@/app/components/workflow/hooks' import { useNodesReadOnly } from '@/app/components/workflow/hooks'
import { useConfig } from './hooks/use-config' import { useConfig } from './hooks/use-config'
import { OUTPUT_VARIABLES_MAP } from './constants' import {
COMMON_OUTPUT,
FILE_OUTPUT,
WEBSITE_OUTPUT,
} from './constants'
import { useStore } from '@/app/components/workflow/store' import { useStore } from '@/app/components/workflow/store'
import Button from '@/app/components/base/button' import Button from '@/app/components/base/button'
import ConfigCredential from './components/config-credential' import ConfigCredential from './components/config-credential'
@ -35,7 +40,7 @@ const Panel: FC<NodePanelProps<DataSourceNodeType>> = ({ id, data }) => {
const dataSourceList = useStore(s => s.dataSourceList) const dataSourceList = useStore(s => s.dataSourceList)
const { const {
provider_type, provider_type,
provider_id, plugin_id,
fileExtensions = [], fileExtensions = [],
datasource_parameters, datasource_parameters,
} = data } = data
@ -43,8 +48,9 @@ const Panel: FC<NodePanelProps<DataSourceNodeType>> = ({ id, data }) => {
handleFileExtensionsChange, handleFileExtensionsChange,
handleParametersChange, handleParametersChange,
} = useConfig(id) } = useConfig(id)
const isLocalFile = provider_type === 'local_file' const isLocalFile = provider_type === DataSourceClassification.file
const currentDataSource = dataSourceList?.find(ds => ds.plugin_id === provider_id) const isWebsiteCrawl = provider_type === DataSourceClassification.website
const currentDataSource = dataSourceList?.find(ds => ds.plugin_id === plugin_id)
const isAuthorized = !!currentDataSource?.is_authorized const isAuthorized = !!currentDataSource?.is_authorized
const [showAuthModal, { const [showAuthModal, {
setTrue: openAuthModal, setTrue: openAuthModal,
@ -150,24 +156,37 @@ const Panel: FC<NodePanelProps<DataSourceNodeType>> = ({ id, data }) => {
) )
} }
<OutputVars> <OutputVars>
<VarItem
name={OUTPUT_VARIABLES_MAP.datasource_type.name}
type={OUTPUT_VARIABLES_MAP.datasource_type.type}
description={OUTPUT_VARIABLES_MAP.datasource_type.description}
/>
{ {
isLocalFile && ( COMMON_OUTPUT.map(item => (
<VarItem
name={item.name}
type={item.type}
description={item.description}
/>
))
}
{
isLocalFile && FILE_OUTPUT.map(item => (
<VarItem <VarItem
name={OUTPUT_VARIABLES_MAP.file.name} name={item.name}
type={OUTPUT_VARIABLES_MAP.file.type} type={item.type}
description={OUTPUT_VARIABLES_MAP.file.description} description={item.description}
subItems={OUTPUT_VARIABLES_MAP.file.subItems.map(item => ({ subItems={item.subItems.map(item => ({
name: item.name, name: item.name,
type: item.type, type: item.type,
description: item.description, description: item.description,
}))} }))}
/> />
) ))
}
{
isWebsiteCrawl && WEBSITE_OUTPUT.map(item => (
<VarItem
name={item.name}
type={item.type}
description={item.description}
/>
))
} }
</OutputVars> </OutputVars>
{ {

@ -6,6 +6,11 @@ export enum VarType {
mixed = 'mixed', mixed = 'mixed',
} }
export enum DataSourceClassification {
file = 'local_file',
website = 'website_crawl',
}
export type ToolVarInputs = Record<string, { export type ToolVarInputs = Record<string, {
type: VarType type: VarType
value?: string | ValueSelector | any value?: string | ValueSelector | any
@ -13,7 +18,7 @@ export type ToolVarInputs = Record<string, {
export type DataSourceNodeType = CommonNodeType & { export type DataSourceNodeType = CommonNodeType & {
fileExtensions?: string[] fileExtensions?: string[]
provider_id: string plugin_id: string
provider_type: string provider_type: string
provider_name: string provider_name: string
datasource_name: string datasource_name: string

@ -100,7 +100,7 @@ export type CommonNodeType<T = {}> = {
retry_config?: WorkflowRetryConfig retry_config?: WorkflowRetryConfig
default_value?: DefaultValueForm[] default_value?: DefaultValueForm[]
} & T & Partial<Pick<ToolDefaultValue, 'provider_id' | 'provider_type' | 'provider_name' | 'tool_name'>> } & T & Partial<Pick<ToolDefaultValue, 'provider_id' | 'provider_type' | 'provider_name' | 'tool_name'>>
& Partial<Pick<DataSourceDefaultValue, 'provider_id' | 'provider_type' | 'provider_name' | 'datasource_name'>> & Partial<Pick<DataSourceDefaultValue, 'plugin_id' | 'provider_type' | 'provider_name' | 'datasource_name'>>
export type CommonEdgeType = { export type CommonEdgeType = {
_hovering?: boolean _hovering?: boolean

Loading…
Cancel
Save