From cfdccebb178bc2c49eacf321e5da483ed1e48511 Mon Sep 17 00:00:00 2001 From: balibabu Date: Wed, 19 Nov 2025 20:11:53 +0800 Subject: [PATCH] Feat: Fixed an issue where modifying fields in the agent operator caused the loss of structured data. #10427 (#11388) ### What problem does this PR solve? Feat: Fixed an issue where modifying fields in the agent operator caused the loss of structured data. #10427 ### Type of change - [x] New Feature (non-breaking change which adds functionality) --- web/src/locales/en.ts | 2 +- web/src/pages/agent/form/agent-form/index.tsx | 19 +++++++++++++++++-- .../agent/form/agent-form/use-watch-change.ts | 13 +++---------- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/web/src/locales/en.ts b/web/src/locales/en.ts index e49f97ed1..38bc6c212 100644 --- a/web/src/locales/en.ts +++ b/web/src/locales/en.ts @@ -1855,7 +1855,7 @@ Important structured information may include: names, dates, locations, events, k desc: 'Descending', }, variableAssignerLogicalOperatorOptions: { - overwrite: 'Overwrite', + overwrite: 'Overwritten By', clear: 'Clear', set: 'Set', '+=': 'Add', diff --git a/web/src/pages/agent/form/agent-form/index.tsx b/web/src/pages/agent/form/agent-form/index.tsx index 83e68e23b..2b23010cd 100644 --- a/web/src/pages/agent/form/agent-form/index.tsx +++ b/web/src/pages/agent/form/agent-form/index.tsx @@ -22,12 +22,13 @@ import { Switch } from '@/components/ui/switch'; import { LlmModelType } from '@/constants/knowledge'; import { useFindLlmByUuid } from '@/hooks/use-llm-request'; import { zodResolver } from '@hookform/resolvers/zod'; -import { memo, useEffect, useMemo } from 'react'; +import { memo, useCallback, useEffect, useMemo } from 'react'; import { useForm, useWatch } from 'react-hook-form'; import { useTranslation } from 'react-i18next'; import { z } from 'zod'; import { AgentExceptionMethod, + AgentStructuredOutputField, NodeHandleId, VariableType, } from '../../constant'; @@ -127,6 +128,17 @@ function AgentForm({ node }: INextOperatorForm) { handleStructuredOutputDialogOk, } = useShowStructuredOutputDialog(node?.id); + const updateNodeForm = useGraphStore((state) => state.updateNodeForm); + + const handleShowStructuredOutput = useCallback( + (val: boolean) => { + if (node?.id && val) { + updateNodeForm(node?.id, {}, ['outputs', AgentStructuredOutputField]); + } + }, + [node?.id, updateNodeForm], + ); + useEffect(() => { if (exceptionMethod !== AgentExceptionMethod.Goto) { if (node?.id) { @@ -293,7 +305,10 @@ function AgentForm({ node }: INextOperatorForm) { { + handleShowStructuredOutput(val); + field.onChange(val); + }} /> )} diff --git a/web/src/pages/agent/form/agent-form/use-watch-change.ts b/web/src/pages/agent/form/agent-form/use-watch-change.ts index 9cd793289..7c53a8d40 100644 --- a/web/src/pages/agent/form/agent-form/use-watch-change.ts +++ b/web/src/pages/agent/form/agent-form/use-watch-change.ts @@ -17,20 +17,13 @@ export function useWatchFormChange(id?: string, form?: UseFormReturn) { prompts: [{ role: PromptRole.User, content: values.prompts }], }; - if (values.showStructuredOutput) { - nextValues = { - ...nextValues, - outputs: { - ...values.outputs, - [AgentStructuredOutputField]: - values[AgentStructuredOutputField] ?? {}, - }, - }; - } else { + if (!values.showStructuredOutput) { nextValues = { ...nextValues, outputs: omit(values.outputs, [AgentStructuredOutputField]), }; + } else { + nextValues = omit(nextValues, 'outputs'); } updateNodeForm(id, nextValues); }