diff --git a/web/app/components/plugins/plugin-auth/authorize/add-oauth-button.tsx b/web/app/components/plugins/plugin-auth/authorize/add-oauth-button.tsx index 1fa6704768..3d7324306c 100644 --- a/web/app/components/plugins/plugin-auth/authorize/add-oauth-button.tsx +++ b/web/app/components/plugins/plugin-auth/authorize/add-oauth-button.tsx @@ -73,7 +73,7 @@ const AddOAuthButton = ({ is_system_oauth_params_exists, client_params, redirect_uri, - } = mergedOAuthData as any + } = mergedOAuthData as any || {} const isConfigured = is_system_oauth_params_exists || is_oauth_custom_client_enabled const handleOAuth = useCallback(async () => { const { authorization_url } = await getPluginOAuthUrl() diff --git a/web/app/components/workflow/nodes/_base/components/variable/utils.ts b/web/app/components/workflow/nodes/_base/components/variable/utils.ts index 680bd81382..5ecbc7fb01 100644 --- a/web/app/components/workflow/nodes/_base/components/variable/utils.ts +++ b/web/app/components/workflow/nodes/_base/components/variable/utils.ts @@ -39,6 +39,7 @@ import type { DataSourceNodeType } from '@/app/components/workflow/nodes/data-so import type { PromptItem } from '@/models/debug' import { VAR_REGEX } from '@/config' import type { AgentNodeType } from '../../../agent/types' +import { getOutputVariableAlias } from '@/app/components/workflow/utils/tool' export const isSystemVar = (valueSelector: ValueSelector) => { return valueSelector[0] === 'sys' || valueSelector[1] === 'sys' @@ -413,7 +414,7 @@ const formatItem = ( ? `array[${output.items?.type.slice(0, 1).toLocaleLowerCase()}${output.items?.type.slice(1)}]` : `${output.type.slice(0, 1).toLocaleLowerCase()}${output.type.slice(1)}`, description: output.description, - alias: output?.properties?.dify_builtin_type?.enum?.[0], + alias: getOutputVariableAlias(output.properties), children: output.type === 'object' ? { schema: { type: 'object', diff --git a/web/app/components/workflow/nodes/data-source/default.ts b/web/app/components/workflow/nodes/data-source/default.ts index a71d4de7fc..de1974ff1f 100644 --- a/web/app/components/workflow/nodes/data-source/default.ts +++ b/web/app/components/workflow/nodes/data-source/default.ts @@ -69,13 +69,10 @@ const nodeDefault: NodeDefault = { ? `array[${output.items?.type.slice(0, 1).toLocaleLowerCase()}${output.items?.type.slice(1)}]` : `${dataType.slice(0, 1).toLocaleLowerCase()}${dataType.slice(1)}`, description: output.description, - alias: output?.properties?.dify_builtin_type?.enum?.[0], children: output.type === 'object' ? { schema: { type: 'object', - properties: Object.fromEntries( - Object.entries(output.properties).filter(([key]) => key !== 'dify_builtin_type'), - ), + properties: output.properties, }, } : undefined, }) diff --git a/web/app/components/workflow/nodes/knowledge-base/panel.tsx b/web/app/components/workflow/nodes/knowledge-base/panel.tsx index 01ed3972c8..94de0bd70a 100644 --- a/web/app/components/workflow/nodes/knowledge-base/panel.tsx +++ b/web/app/components/workflow/nodes/knowledge-base/panel.tsx @@ -1,10 +1,12 @@ import type { FC } from 'react' import { memo, + useCallback, } from 'react' import { useTranslation } from 'react-i18next' import type { KnowledgeBaseNodeType } from './types' import { + ChunkStructureEnum, IndexMethodEnum, } from './types' import ChunkStructure from './components/chunk-structure' @@ -21,6 +23,8 @@ import { import Split from '../_base/components/split' import { useNodesReadOnly } from '@/app/components/workflow/hooks' import VarReferencePicker from '@/app/components/workflow/nodes/_base/components/variable/var-reference-picker' +import type { Var } from '@/app/components/workflow/types' +import { CHUNK_TYPE_MAP } from '@/app/components/workflow/utils/tool' const Panel: FC> = ({ id, @@ -43,6 +47,16 @@ const Panel: FC> = ({ handleInputVariableChange, } = useConfig(id) + const filterVar = useCallback((variable: Var) => { + if (data.chunk_structure === ChunkStructureEnum.general && variable.alias === CHUNK_TYPE_MAP.general_chunks) + return true + if (data.chunk_structure === ChunkStructureEnum.parent_child && variable.alias === CHUNK_TYPE_MAP.parent_child_chunks) + return true + if (data.chunk_structure === ChunkStructureEnum.question_answer && variable.alias === CHUNK_TYPE_MAP.qa_chunks) + return true + return false + }, [data.chunk_structure]) + return (
> = ({ value={data.index_chunk_variable_selector} onChange={handleInputVariableChange} readonly={nodesReadOnly} + filterVar={filterVar} + isSupportFileVar={false} /> { return const inputsWithDefaultValue = formattingParameters() setInputs(inputsWithDefaultValue) - // eslint-disable-next-line react-hooks/exhaustive-deps }, [currTool]) // setting when call @@ -191,7 +190,7 @@ const useConfig = (id: string, payload: ToolNodeType) => { name: outputKey, type: output.type === 'array' ? `Array[${output.items?.type.slice(0, 1).toLocaleUpperCase()}${output.items?.type.slice(1)}]` - : `${output.type.slice(0, 1).toLocaleUpperCase()}${output.type.slice(1)}`, + : `${output.type?.slice(0, 1).toLocaleUpperCase()}${output.type?.slice(1)}`, description: output.description, }) } diff --git a/web/app/components/workflow/utils/tool.ts b/web/app/components/workflow/utils/tool.ts index 479b7d7247..17494f704e 100644 --- a/web/app/components/workflow/utils/tool.ts +++ b/web/app/components/workflow/utils/tool.ts @@ -44,19 +44,29 @@ export const getToolCheckParams = ( } } +export const CHUNK_TYPE_MAP = { + general_chunks: 'GeneralStructureChunk', + parent_child_chunks: 'ParentChildStructureChunk', + qa_chunks: 'QAStructureChunk', +} + +export const getOutputVariableAlias = (variable: Record) => { + if (variable?.general_chunks) + return CHUNK_TYPE_MAP.general_chunks + if (variable?.parent_child_chunks) + return CHUNK_TYPE_MAP.parent_child_chunks + if (variable?.qa_chunks) + return CHUNK_TYPE_MAP.qa_chunks +} export const wrapStructuredVarItem = (outputItem: any): StructuredOutput => { const dataType = Type.object - const properties = Object.fromEntries( - Object.entries(outputItem.value?.properties || {}).filter(([key]) => key !== 'dify_builtin_type'), - ) as Record return { schema: { type: dataType, properties: { [outputItem.name]: { ...outputItem.value, - properties, - alias: outputItem.value?.properties?.dify_builtin_type?.enum?.[0], + alias: getOutputVariableAlias(outputItem.value?.properties), }, }, additionalProperties: false,