From 45c9b77e82750cb6dbb9486ea71582c9e9a15251 Mon Sep 17 00:00:00 2001 From: Joel Date: Fri, 13 Jun 2025 14:42:25 +0800 Subject: [PATCH 1/2] fix: match var reg --- web/config/index.spec.ts | 26 ++++++++++++++++++++++++++ web/config/index.ts | 2 +- 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 web/config/index.spec.ts diff --git a/web/config/index.spec.ts b/web/config/index.spec.ts new file mode 100644 index 0000000000..06dfbdbf2f --- /dev/null +++ b/web/config/index.spec.ts @@ -0,0 +1,26 @@ +// 写测试用例, VAR_REGEX 能匹配的情况和不能匹配的情况 +import { VAR_REGEX, resetReg } from './index' +describe('VAR_REGEX', () => { + it('matched variable names', () => { + const vars = [ + // node output variables + '{{#1749783300519.text#}}', + '{{#1749783300519.llm.a#}}', + '{{#1749783300519.llm.a.b.c#}}', + '{{#1749783300519.llm.a#}}', + // system variables + '{{#sys.query#}}', + // conversation variables + '{{#conversation.aaa#}}', + // env variables + '{{#env.a#}}', + // rag variables + '{{#rag.1748945155129.a#}}', + '{{#rag.shared.bbb#}}', + ] + vars.forEach((variable) => { + expect(VAR_REGEX.test(variable)).toBe(true) + resetReg() + }) + }) +}) diff --git a/web/config/index.ts b/web/config/index.ts index f1fffc8646..5c49fe4061 100644 --- a/web/config/index.ts +++ b/web/config/index.ts @@ -275,7 +275,7 @@ Thought: {{agent_scratchpad}} `, } -export const VAR_REGEX = /\{\{(#[a-zA-Z0-9_-]{1,50}(\.[a-zA-Z_]?\w{0,29}){1,10}(\.[a-zA-Z0-9_-]{1,50})?#)\}\}/gi +export const VAR_REGEX = /\{\{(#[a-zA-Z0-9_-]{1,50}(\.\d+)?(\.[a-zA-Z_]\w{0,29}){1,10}#)\}\}/gi export const resetReg = () => VAR_REGEX.lastIndex = 0 From 55bff10f0dcc59b5246c49912e08f653fdf070df Mon Sep 17 00:00:00 2001 From: zxhlyh Date: Fri, 13 Jun 2025 14:42:27 +0800 Subject: [PATCH 2/2] fix --- web/app/components/workflow/nodes/code/use-config.ts | 5 ++--- .../components/workflow/nodes/data-source/panel.tsx | 12 ++++++++---- .../components/workflow/operator/export-image.tsx | 8 +++++--- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/web/app/components/workflow/nodes/code/use-config.ts b/web/app/components/workflow/nodes/code/use-config.ts index 13b8962439..16f06c18ce 100644 --- a/web/app/components/workflow/nodes/code/use-config.ts +++ b/web/app/components/workflow/nodes/code/use-config.ts @@ -10,7 +10,6 @@ import { CodeLanguage } from './types' import useNodeCrud from '@/app/components/workflow/nodes/_base/hooks/use-node-crud' import useOneStepRun from '@/app/components/workflow/nodes/_base/hooks/use-one-step-run' import { fetchNodeDefault } from '@/service/workflow' -import { useStore as useAppStore } from '@/app/components/app/store' import { useNodesReadOnly, } from '@/app/components/workflow/hooks' @@ -18,7 +17,7 @@ import { const useConfig = (id: string, payload: CodeNodeType) => { const { nodesReadOnly: readOnly } = useNodesReadOnly() - const appId = useAppStore.getState().appDetail?.id + const appId = useStore(s => s.appId) const [allLanguageDefault, setAllLanguageDefault] = useState | null>(null) useEffect(() => { @@ -34,7 +33,7 @@ const useConfig = (id: string, payload: CodeNodeType) => { } }, [appId]) - const defaultConfig = useStore(s => s.nodesDefaultConfigs)[payload.type] + const defaultConfig = useStore(s => s.nodesDefaultConfigs)?.[payload.type] const { inputs, setInputs } = useNodeCrud(id, payload) const { handleVarListChange, handleAddVariable } = useVarList({ inputs, diff --git a/web/app/components/workflow/nodes/data-source/panel.tsx b/web/app/components/workflow/nodes/data-source/panel.tsx index 1d79e5a119..4e498fd780 100644 --- a/web/app/components/workflow/nodes/data-source/panel.tsx +++ b/web/app/components/workflow/nodes/data-source/panel.tsx @@ -159,8 +159,9 @@ const Panel: FC> = ({ id, data }) => { } { - COMMON_OUTPUT.map(item => ( + COMMON_OUTPUT.map((item, index) => ( > = ({ id, data }) => { )) } { - isLocalFile && LOCAL_FILE_OUTPUT.map(item => ( + isLocalFile && LOCAL_FILE_OUTPUT.map((item, index) => ( > = ({ id, data }) => { )) } { - isWebsiteCrawl && WEBSITE_CRAWL_OUTPUT.map(item => ( + isWebsiteCrawl && WEBSITE_CRAWL_OUTPUT.map((item, index) => ( > = ({ id, data }) => { )) } { - isOnlineDocument && ONLINE_DOCUMENT_OUTPUT.map(item => ( + isOnlineDocument && ONLINE_DOCUMENT_OUTPUT.map((item, index) => ( { const { t } = useTranslation() @@ -23,9 +24,10 @@ const ExportImage: FC = () => { const appDetail = useAppStore(s => s.appDetail) const [open, setOpen] = useState(false) + const knowledgeName = useStore(s => s.knowledgeName) const handleExportImage = useCallback(async (type: 'png' | 'jpeg' | 'svg') => { - if (!appDetail) + if (!appDetail && !knowledgeName) return if (getNodesReadOnly()) @@ -60,7 +62,7 @@ const ExportImage: FC = () => { const link = document.createElement('a') link.href = dataUrl - link.download = `${appDetail.name}.${type}` + link.download = `${appDetail ? appDetail.name : knowledgeName}.${type}` document.body.appendChild(link) link.click() document.body.removeChild(link) @@ -68,7 +70,7 @@ const ExportImage: FC = () => { catch (error) { console.error('Export image failed:', error) } - }, [getNodesReadOnly, appDetail]) + }, [getNodesReadOnly, appDetail, knowledgeName]) const handleTrigger = useCallback(() => { if (getNodesReadOnly())