datasource

This commit is contained in:
zxhlyh 2025-05-23 18:19:01 +08:00
parent db4958be05
commit e7370766bd
6 changed files with 98 additions and 45 deletions

View File

@ -38,6 +38,7 @@ const DataSources = ({
provider_name: toolDefaultValue?.provider_name,
datasource_name: toolDefaultValue?.tool_name,
datasource_label: toolDefaultValue?.tool_label,
title: toolDefaultValue?.title,
})
}, [onSelect])

View File

@ -33,6 +33,7 @@ import {
TEMPLATE_TRANSFORM_OUTPUT_STRUCT,
TOOL_OUTPUT_STRUCT,
} from '@/app/components/workflow/constants'
import DataSourceNodeDefault from '@/app/components/workflow/nodes/data-source/default'
import type { PromptItem } from '@/models/debug'
import { VAR_REGEX } from '@/config'
import type { AgentNodeType } from '../../../agent/types'
@ -457,6 +458,11 @@ const formatItem = (
break
}
case BlockEnum.DataSource: {
res.vars = DataSourceNodeDefault.getOutputVars?.(data as any) || []
break
}
case 'env': {
res.vars = data.envList.map((env: EnvironmentVariable) => {
return {
@ -513,6 +519,8 @@ 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,
@ -529,9 +537,10 @@ const formatItem = (
return obj?.children && ((obj?.children as Var[]).length > 0 || Object.keys((obj?.children as StructuredOutput)?.schema?.properties || {}).length > 0)
}).map((v) => {
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

@ -0,0 +1,46 @@
import { VarType } from '@/app/components/workflow/types'
export const OUTPUT_VARIABLES_MAP = {
datasource_type: {
name: 'datasource_type',
type: VarType.string,
description: 'local_file, online_document, website_crawl',
},
file: {
name: 'file',
type: VarType.file,
description: 'file',
subItems: [
{
name: 'type',
type: VarType.string,
description: '',
},
{
name: 'upload_file_id',
type: VarType.string,
description: '',
},
{
name: 'name',
type: VarType.string,
description: '',
},
{
name: 'size',
type: VarType.number,
description: '',
},
{
name: 'extension',
type: VarType.string,
description: '',
},
{
name: 'mime_type',
type: VarType.string,
description: '',
},
],
},
}

View File

@ -2,6 +2,8 @@ import type { NodeDefault } from '../../types'
import type { DataSourceNodeType } from './types'
import { genNodeMetaData } from '@/app/components/workflow/utils'
import { BlockEnum } from '@/app/components/workflow/types'
import { CollectionType } from '@/app/components/tools/types'
import { OUTPUT_VARIABLES_MAP } from './constants'
const metaData = genNodeMetaData({
sort: -1,
@ -9,13 +11,42 @@ const metaData = genNodeMetaData({
})
const nodeDefault: NodeDefault<DataSourceNodeType> = {
metaData,
defaultValue: {},
defaultValue: {
datasource_parameters: {},
datasource_configurations: {},
},
checkValid() {
return {
isValid: true,
errorMessage: '',
}
},
getOutputVars(payload) {
const { provider_id, provider_type } = payload
const isLocalFile = provider_id === 'langgenius/file/file' && provider_type === CollectionType.datasource
return [
{
variable: OUTPUT_VARIABLES_MAP.datasource_type.name,
type: OUTPUT_VARIABLES_MAP.datasource_type.type,
},
...(
isLocalFile
? [
{
variable: OUTPUT_VARIABLES_MAP.file.name,
type: OUTPUT_VARIABLES_MAP.file.type,
children: OUTPUT_VARIABLES_MAP.file.subItems.map((item) => {
return {
variable: item.name,
type: item.type,
}
}),
},
]
: []
),
]
},
}
export default nodeDefault

View File

@ -8,6 +8,7 @@ import { BoxGroupField } from '@/app/components/workflow/nodes/_base/components/
import OutputVars, { VarItem } from '@/app/components/workflow/nodes/_base/components/output-vars'
import TagInput from '@/app/components/base/tag-input'
import { useConfig } from './hooks/use-config'
import { OUTPUT_VARIABLES_MAP } from './constants'
const Panel: FC<NodePanelProps<DataSourceNodeType>> = ({ id, data }) => {
const { t } = useTranslation()
@ -46,53 +47,17 @@ const Panel: FC<NodePanelProps<DataSourceNodeType>> = ({ id, data }) => {
}
<OutputVars>
<VarItem
name='datasource_type'
type='string'
description={'local_file, online_document, website_crawl'}
name={OUTPUT_VARIABLES_MAP.datasource_type.name}
type={OUTPUT_VARIABLES_MAP.datasource_type.type}
description={OUTPUT_VARIABLES_MAP.datasource_type.description}
/>
{
isLocalFile && (
<VarItem
name='file'
type='Object'
description={'file'}
subItems={[
{
name: 'type',
type: 'string',
description: '',
},
{
name: 'upload_file_id',
type: 'string',
description: '',
},
{
name: 'name',
type: 'string',
description: '',
},
{
name: 'size',
type: 'number',
description: '',
},
{
name: 'extension',
type: 'string',
description: '',
},
{
name: 'mime_type',
type: 'string',
description: '',
},
{
name: 'upload_file_url',
type: 'string',
description: '',
},
]}
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

@ -313,6 +313,7 @@ export type NodeDefault<T = {}> = {
}
defaultValue: Partial<T>
checkValid: (payload: T, t: any, moreDataForCheckValid?: any) => { isValid: boolean; errorMessage?: string }
getOutputVars?: (payload: T) => Var[]
}
export type OnSelectBlock = (type: BlockEnum, toolDefaultValue?: ToolDefaultValue | DataSourceDefaultValue) => void