From 53cdee1e2fdf431c7234e22c2af0061451e48a62 Mon Sep 17 00:00:00 2001 From: zxhlyh Date: Wed, 23 Jul 2025 10:46:45 +0800 Subject: [PATCH] pipeline template --- .../rag-pipeline/hooks/use-pipeline-refresh-draft.ts | 6 +++++- .../rag-pipeline/hooks/use-pipeline-template.ts | 5 ++++- web/app/components/rag-pipeline/index.tsx | 6 ++---- web/app/components/rag-pipeline/utils/nodes.ts | 9 ++------- .../workflow/nodes/data-source-empty/index.tsx | 6 +++++- 5 files changed, 18 insertions(+), 14 deletions(-) diff --git a/web/app/components/rag-pipeline/hooks/use-pipeline-refresh-draft.ts b/web/app/components/rag-pipeline/hooks/use-pipeline-refresh-draft.ts index 7d33bb7530..bf0f5bb67a 100644 --- a/web/app/components/rag-pipeline/hooks/use-pipeline-refresh-draft.ts +++ b/web/app/components/rag-pipeline/hooks/use-pipeline-refresh-draft.ts @@ -3,6 +3,7 @@ import { useWorkflowStore } from '@/app/components/workflow/store' import { fetchWorkflowDraft } from '@/service/workflow' import type { WorkflowDataUpdater } from '@/app/components/workflow/types' import { useWorkflowUpdate } from '@/app/components/workflow/hooks' +import { processNodesWithoutDataSource } from '../utils' export const usePipelineRefreshDraft = () => { const workflowStore = useWorkflowStore() @@ -18,7 +19,10 @@ export const usePipelineRefreshDraft = () => { } = workflowStore.getState() setIsSyncingWorkflowDraft(true) fetchWorkflowDraft(`/rag/pipelines/${pipelineId}/workflows/draft`).then((response) => { - handleUpdateWorkflowCanvas(response.graph as WorkflowDataUpdater) + handleUpdateWorkflowCanvas({ + ...response.graph, + nodes: processNodesWithoutDataSource(response.graph.nodes), + } as WorkflowDataUpdater) setSyncWorkflowDraftHash(response.hash) setEnvSecrets((response.environment_variables || []).filter(env => env.value_type === 'secret').reduce((acc, env) => { acc[env.id] = env.value diff --git a/web/app/components/rag-pipeline/hooks/use-pipeline-template.ts b/web/app/components/rag-pipeline/hooks/use-pipeline-template.ts index 3779ca733a..753088f83c 100644 --- a/web/app/components/rag-pipeline/hooks/use-pipeline-template.ts +++ b/web/app/components/rag-pipeline/hooks/use-pipeline-template.ts @@ -15,7 +15,10 @@ export const usePipelineTemplate = () => { type: knowledgeBaseDefault.metaData.type, title: t(`workflow.blocks.${knowledgeBaseDefault.metaData.type}`), }, - position: START_INITIAL_POSITION, + position: { + x: START_INITIAL_POSITION.x + 500, + y: START_INITIAL_POSITION.y, + }, }) return { diff --git a/web/app/components/rag-pipeline/index.tsx b/web/app/components/rag-pipeline/index.tsx index 6e1e4c7e5f..dbbb256c95 100644 --- a/web/app/components/rag-pipeline/index.tsx +++ b/web/app/components/rag-pipeline/index.tsx @@ -14,7 +14,6 @@ import RagPipelineMain from './components/rag-pipeline-main' import { usePipelineInit } from './hooks' import { useDatasetDetailContextWithSelector } from '@/context/dataset-detail' import Conversion from './components/conversion' -import type { Node } from '@/app/components/workflow/types' import { processNodesWithoutDataSource } from './utils' const RagPipeline = () => { @@ -23,11 +22,10 @@ const RagPipeline = () => { isLoading, } = usePipelineInit() const nodesData = useMemo(() => { - let result: Node[] = [] if (data) - result = initialNodes(data.graph.nodes, data.graph.edges) + return processNodesWithoutDataSource(initialNodes(data.graph.nodes, data.graph.edges)) - return processNodesWithoutDataSource(result) + return [] }, [data]) const edgesData = useMemo(() => { if (data) diff --git a/web/app/components/rag-pipeline/utils/nodes.ts b/web/app/components/rag-pipeline/utils/nodes.ts index f283267d00..da46b3d632 100644 --- a/web/app/components/rag-pipeline/utils/nodes.ts +++ b/web/app/components/rag-pipeline/utils/nodes.ts @@ -8,8 +8,6 @@ import type { NoteNodeType } from '@/app/components/workflow/note-node/types' import { CUSTOM_NODE } from '@/app/components/workflow/constants' export const processNodesWithoutDataSource = (nodes: Node[]) => { - if (!nodes || nodes.length === 0) return [] - let leftNode let hasNoteBySystem for (let i = 0; i < nodes.length; i++) { @@ -17,16 +15,13 @@ export const processNodesWithoutDataSource = (nodes: Node[]) => { if (node.type === CUSTOM_NOTE_NODE && node.data.noteBySystem) hasNoteBySystem = true - if (node.type !== CUSTOM_NODE) - continue - if (node.data.type === BlockEnum.DataSource) return nodes - if (!leftNode) + if (node.type === CUSTOM_NODE && !leftNode) leftNode = node - if (node.position.x < leftNode.position.x) + if (node.type === CUSTOM_NODE && leftNode && node.position.x < leftNode.position.x) leftNode = node } diff --git a/web/app/components/workflow/nodes/data-source-empty/index.tsx b/web/app/components/workflow/nodes/data-source-empty/index.tsx index 7c556160d7..6b4e249f3b 100644 --- a/web/app/components/workflow/nodes/data-source-empty/index.tsx +++ b/web/app/components/workflow/nodes/data-source-empty/index.tsx @@ -10,7 +10,7 @@ import Button from '@/app/components/base/button' import BlockSelector from '@/app/components/workflow/block-selector' import { useReplaceDataSourceNode } from './hooks' -const DataSourceEmptyNode = ({ id }: NodeProps) => { +const DataSourceEmptyNode = ({ id, data }: NodeProps) => { const { t } = useTranslation() const { handleReplaceNode } = useReplaceDataSourceNode(id) @@ -32,6 +32,10 @@ const DataSourceEmptyNode = ({ id }: NodeProps) => { 'relative flex rounded-2xl border', 'border-transparent', )} + style={{ + width: data.width, + height: data.height, + }} >