From d394adfaf7862f3d9e63bd7871a48580c78c2a7c Mon Sep 17 00:00:00 2001 From: zhsama Date: Tue, 13 Jan 2026 22:57:05 +0800 Subject: [PATCH] feat: Fix prompt template handling for Jinja2 edition type --- web/app/components/sub-graph/index.tsx | 39 ++++++++++++++----- .../tool/components/sub-graph-modal/index.tsx | 13 +++++-- 2 files changed, 39 insertions(+), 13 deletions(-) diff --git a/web/app/components/sub-graph/index.tsx b/web/app/components/sub-graph/index.tsx index 1ae9ad935d..91d70fab7d 100644 --- a/web/app/components/sub-graph/index.tsx +++ b/web/app/components/sub-graph/index.tsx @@ -6,7 +6,7 @@ import type { PromptItem } from '@/app/components/workflow/types' import { memo, useMemo } from 'react' import WorkflowWithDefaultContext from '@/app/components/workflow' import { WorkflowContextProvider } from '@/app/components/workflow/context' -import { BlockEnum, PromptRole } from '@/app/components/workflow/types' +import { BlockEnum, EditionType, PromptRole } from '@/app/components/workflow/types' import SubGraphMain from './components/sub-graph-main' import { useSubGraphNodes } from './hooks' import { createSubGraphSlice } from './store' @@ -62,21 +62,40 @@ const SubGraph: FC = (props) => { if (!extractorNode) return null - const nextPromptTemplate = Array.isArray(extractorNode.data.prompt_template) - ? extractorNode.data.prompt_template.map((item: PromptItem) => { - if (item.role === PromptRole.system) - return { ...item, text: promptText } - return item - }) - : { - ...extractorNode.data.prompt_template, + const updateSystemPrompt = (item: PromptItem) => { + if (item.role !== PromptRole.system) + return item + if (item.edition_type === EditionType.jinja2) { + return { + ...item, text: promptText, + jinja2_text: promptText, } + } + return { ...item, text: promptText } + } + + const nextPromptTemplate = Array.isArray(extractorNode.data.prompt_template) + ? extractorNode.data.prompt_template.map(updateSystemPrompt) + : updateSystemPrompt(extractorNode.data.prompt_template as PromptItem) const hasSystemPrompt = Array.isArray(nextPromptTemplate) && nextPromptTemplate.some((item: PromptItem) => item.role === PromptRole.system) + const defaultSystemPrompt: PromptItem = (() => { + const useJinja = Array.isArray(nextPromptTemplate) + && nextPromptTemplate.some((item: PromptItem) => item.edition_type === EditionType.jinja2) + if (useJinja) { + return { + role: PromptRole.system, + text: promptText, + jinja2_text: promptText, + edition_type: EditionType.jinja2, + } + } + return { role: PromptRole.system, text: promptText } + })() const normalizedPromptTemplate = Array.isArray(nextPromptTemplate) - ? (hasSystemPrompt ? nextPromptTemplate : [{ role: PromptRole.system, text: promptText }, ...nextPromptTemplate]) + ? (hasSystemPrompt ? nextPromptTemplate : [defaultSystemPrompt, ...nextPromptTemplate]) : nextPromptTemplate return { diff --git a/web/app/components/workflow/nodes/tool/components/sub-graph-modal/index.tsx b/web/app/components/workflow/nodes/tool/components/sub-graph-modal/index.tsx index 3ee27c3b54..1886c4c2e2 100644 --- a/web/app/components/workflow/nodes/tool/components/sub-graph-modal/index.tsx +++ b/web/app/components/workflow/nodes/tool/components/sub-graph-modal/index.tsx @@ -13,7 +13,7 @@ import { useStoreApi } from 'reactflow' import { Agent } from '@/app/components/base/icons/src/vender/workflow' import { useNodesSyncDraft } from '@/app/components/workflow/hooks' import { useStore } from '@/app/components/workflow/store' -import { PromptRole } from '@/app/components/workflow/types' +import { EditionType, PromptRole } from '@/app/components/workflow/types' import SubGraphCanvas from './sub-graph-canvas' const SubGraphModal: FC = ({ @@ -43,11 +43,18 @@ const SubGraphModal: FC = ({ const getSystemPromptText = useCallback((promptTemplate?: PromptItem[] | PromptItem) => { if (!promptTemplate) return '' + const resolveText = (item?: PromptItem) => { + if (!item) + return '' + if (item.edition_type === EditionType.jinja2) + return item.jinja2_text || item.text || '' + return item.text || '' + } if (Array.isArray(promptTemplate)) { const systemPrompt = promptTemplate.find(item => item.role === PromptRole.system) - return systemPrompt?.text || '' + return resolveText(systemPrompt) } - return promptTemplate.text || '' + return resolveText(promptTemplate) }, []) const handleSave = useCallback((subGraphNodes: any[], _edges: any[]) => {