From 9d3772f7d681895fc6f98e1a047b4d163930f2a0 Mon Sep 17 00:00:00 2001 From: twwu Date: Wed, 3 Sep 2025 12:59:22 +0800 Subject: [PATCH] feat(workflow): add DisplayContent component for improved variable inspection and integrate schema type handling --- .../hooks/use-inspect-vars-crud-common.ts | 2 +- .../variable-inspect/display-content.tsx | 115 +++++++++++++ .../workflow/variable-inspect/right.tsx | 40 +++-- .../workflow/variable-inspect/types.ts | 12 ++ .../variable-inspect/value-content.tsx | 151 +++++------------- 5 files changed, 191 insertions(+), 129 deletions(-) create mode 100644 web/app/components/workflow/variable-inspect/display-content.tsx diff --git a/web/app/components/workflow/hooks/use-inspect-vars-crud-common.ts b/web/app/components/workflow/hooks/use-inspect-vars-crud-common.ts index 89ad87133f..dc131a150f 100644 --- a/web/app/components/workflow/hooks/use-inspect-vars-crud-common.ts +++ b/web/app/components/workflow/hooks/use-inspect-vars-crud-common.ts @@ -128,7 +128,7 @@ export const useInspectVarsCrudCommon = ({ const currentNodeOutputVars = toNodeOutputVars([currentNode], false, () => true, [], [], [], allPluginInfoList, schemaTypeDefinitions) const vars = await fetchNodeInspectVars(flowType, flowId, nodeId) const varsWithSchemaType = vars.map((varItem) => { - const schemaType = currentNodeOutputVars[0].vars.find(v => v.variable === varItem.name)?.schemaType || '' + const schemaType = currentNodeOutputVars[0]?.vars.find(v => v.variable === varItem.name)?.schemaType || '' return { ...varItem, schemaType, diff --git a/web/app/components/workflow/variable-inspect/display-content.tsx b/web/app/components/workflow/variable-inspect/display-content.tsx new file mode 100644 index 0000000000..06af502b26 --- /dev/null +++ b/web/app/components/workflow/variable-inspect/display-content.tsx @@ -0,0 +1,115 @@ +import React, { useMemo, useState } from 'react' +import { useTranslation } from 'react-i18next' +import { RiBracesLine, RiEyeLine } from '@remixicon/react' +import Textarea from '@/app/components/base/textarea' +import { Markdown } from '@/app/components/base/markdown' +import SchemaEditor from '@/app/components/workflow/nodes/llm/components/json-schema-config-modal/schema-editor' +import { SegmentedControl } from '@/app/components/base/segmented-control' +import cn from '@/utils/classnames' +import { ChunkCardList } from '@/app/components/rag-pipeline/components/chunk-card-list' +import type { ChunkInfo } from '@/app/components/rag-pipeline/components/chunk-card-list/types' +import type { ParentMode } from '@/models/datasets' +import { ChunkingMode } from '@/models/datasets' +import { PreviewType, ViewMode } from './types' +import type { VarType } from '../types' + +type DisplayContentProps = { + previewType: PreviewType + varType: VarType + schemaType?: string + mdString?: string + jsonString?: string + readonly: boolean + handleTextChange?: (value: string) => void + handleEditorChange?: (value: string) => void +} + +const DisplayContent = (props: DisplayContentProps) => { + const { previewType, varType, schemaType, mdString, jsonString, readonly, handleTextChange, handleEditorChange } = props + const [viewMode, setViewMode] = useState(ViewMode.Code) + const [isFocused, setIsFocused] = useState(false) + const { t } = useTranslation() + + const chunkType = useMemo(() => { + if (previewType !== PreviewType.Chunks || !schemaType) + return undefined + if (schemaType === 'general_structure') + return ChunkingMode.text + if (schemaType === 'parent_child_structure') + return ChunkingMode.parentChild + if (schemaType === 'qa_structure') + return ChunkingMode.qa + }, [previewType, schemaType]) + + const parentMode = useMemo(() => { + if (previewType !== PreviewType.Chunks || !schemaType || !jsonString) + return undefined + if (schemaType === 'parent_child_structure') + return JSON.parse(jsonString!)?.parent_mode as ParentMode + return undefined + }, [previewType, schemaType, jsonString]) + + return ( +
+
+ {previewType === PreviewType.Markdown && ( +
+ {previewType.toUpperCase()} +
+ )} + {previewType === PreviewType.Chunks && ( +
+ {varType.toUpperCase()}{schemaType ? `(${schemaType})` : ''} +
+ )} + +
+
+ {viewMode === ViewMode.Code && ( + previewType === PreviewType.Markdown + ?