From accae951263ab46ce0e9c4e4b4f51cd0ae6adf9a Mon Sep 17 00:00:00 2001 From: balibabu Date: Tue, 13 Jan 2026 15:35:45 +0800 Subject: [PATCH] Feat: Exported Agent JSON Should Include Conversation Variables Configuration #11796 (#12579) ### What problem does this PR solve? Feat: Exported Agent JSON Should Include Conversation Variables Configuration #11796 ### Type of change - [x] New Feature (non-breaking change which adds functionality) --- web/src/hooks/use-agent-request.ts | 1 + web/src/pages/agent/hooks/use-export-json.ts | 4 ++- .../pages/agents/hooks/use-create-agent.ts | 1 + web/src/pages/agents/use-import-json.ts | 36 ++++++++++++------- 4 files changed, 29 insertions(+), 13 deletions(-) diff --git a/web/src/hooks/use-agent-request.ts b/web/src/hooks/use-agent-request.ts index 4ac0abc7c..482677acd 100644 --- a/web/src/hooks/use-agent-request.ts +++ b/web/src/hooks/use-agent-request.ts @@ -97,6 +97,7 @@ export const EmptyDsl = { retrieval: [], // reference history: [], path: [], + variables: [], globals: { [AgentGlobals.SysQuery]: '', [AgentGlobals.SysUserId]: '', diff --git a/web/src/pages/agent/hooks/use-export-json.ts b/web/src/pages/agent/hooks/use-export-json.ts index 2f2e9242e..ef7d27ef0 100644 --- a/web/src/pages/agent/hooks/use-export-json.ts +++ b/web/src/pages/agent/hooks/use-export-json.ts @@ -1,5 +1,6 @@ import { useFetchAgent } from '@/hooks/use-agent-request'; import { downloadJsonFile } from '@/utils/file-util'; +import { pick } from 'lodash'; import { useCallback } from 'react'; import { useBuildDslData } from './use-build-dsl'; @@ -8,7 +9,8 @@ export const useHandleExportJsonFile = () => { const { data } = useFetchAgent(); const handleExportJson = useCallback(() => { - downloadJsonFile(buildDslData().graph, `${data.title}.json`); + const dsl = pick(buildDslData(), ['graph', 'globals', 'variables']); + downloadJsonFile(dsl, `${data.title}.json`); }, [buildDslData, data.title]); return { diff --git a/web/src/pages/agents/hooks/use-create-agent.ts b/web/src/pages/agents/hooks/use-create-agent.ts index 7f3c61c35..74506964c 100644 --- a/web/src/pages/agents/hooks/use-create-agent.ts +++ b/web/src/pages/agents/hooks/use-create-agent.ts @@ -71,6 +71,7 @@ export const DataflowEmptyDsl = { history: [], path: [], globals: {}, + variables: [], }; export function useCreateAgentOrPipeline() { diff --git a/web/src/pages/agents/use-import-json.ts b/web/src/pages/agents/use-import-json.ts index e40247595..4fcac200c 100644 --- a/web/src/pages/agents/use-import-json.ts +++ b/web/src/pages/agents/use-import-json.ts @@ -34,25 +34,36 @@ export const useHandleImportJsonFile = () => { return; } - const graphStr = await file.text(); + const graphOrDslStr = await file.text(); const errorMessage = t('flow.jsonUploadContentErrorMessage'); try { - const graph = JSON.parse(graphStr); - if (graphStr && !isEmpty(graph) && Array.isArray(graph?.nodes)) { - const nodes: Node[] = graph.nodes; - + const graphOrDsl = JSON.parse(graphOrDslStr); + if (graphOrDslStr && !isEmpty(graphOrDsl)) { let isAgent = true; + // Compatible with older versions + const graph = graphOrDsl?.graph ? graphOrDsl.graph : graphOrDsl; + if (Array.isArray(graph?.nodes)) { + const nodes: Node[] = graph.nodes; - if ( - hasNode(nodes, DataflowOperator.Begin) && - hasNode(nodes, DataflowOperator.Parser) - ) { - isAgent = false; + if ( + hasNode(nodes, DataflowOperator.Begin) && + hasNode(nodes, DataflowOperator.Parser) + ) { + isAgent = false; + } } const dsl = isAgent - ? { ...EmptyDsl, graph } - : { ...DataflowEmptyDsl, graph }; + ? { ...EmptyDsl, graph: graph } + : { ...DataflowEmptyDsl, graph: graph }; + + if (graphOrDsl.globals) { + dsl.globals = graphOrDsl.globals; + } + + if (graphOrDsl.variables) { + dsl.variables = graphOrDsl.variables; + } setAgent({ title: name, @@ -66,6 +77,7 @@ export const useHandleImportJsonFile = () => { message.error(errorMessage); } } catch (error) { + console.log('🚀 ~ useHandleImportJsonFile ~ error:', error); message.error(errorMessage); } }