66import { LlmSettingSchema } from '@/components/llm-setting-items/next' ;
77import { MessageHistoryWindowSizeFormField } from '@/components/message-history-window-size-item' ;
88import { SelectWithSearch } from '@/components/originui/select-with-search' ;
9+ import { RAGFlowFormItem } from '@/components/ragflow-form' ;
910import { Button } from '@/components/ui/button' ;
1011import {
1112 Form ,
@@ -15,6 +16,7 @@ import {
1516 FormLabel ,
1617} from '@/components/ui/form' ;
1718import { Input , NumberInput } from '@/components/ui/input' ;
19+ import { Label } from '@/components/ui/label' ;
1820import { Separator } from '@/components/ui/separator' ;
1921import { Switch } from '@/components/ui/switch' ;
2022import { LlmModelType } from '@/constants/knowledge' ;
@@ -26,9 +28,9 @@ import { useTranslation } from 'react-i18next';
2628import { z } from 'zod' ;
2729import {
2830 AgentExceptionMethod ,
31+ AgentStructuredOutputField ,
2932 NodeHandleId ,
3033 VariableType ,
31- initialAgentValues ,
3234} from '../../constant' ;
3335import { INextOperatorForm } from '../../interface' ;
3436import useGraphStore from '../../store' ;
@@ -71,18 +73,20 @@ const FormSchema = z.object({
7173 exception_default_value : z . string ( ) . optional ( ) ,
7274 ...LargeModelFilterFormSchema ,
7375 cite : z . boolean ( ) . optional ( ) ,
76+ showStructuredOutput : z . boolean ( ) . optional ( ) ,
77+ [ AgentStructuredOutputField ] : z . record ( z . any ( ) ) ,
7478} ) ;
7579
7680export type AgentFormSchemaType = z . infer < typeof FormSchema > ;
7781
78- const outputList = buildOutputList ( initialAgentValues . outputs ) ;
79-
8082function AgentForm ( { node } : INextOperatorForm ) {
8183 const { t } = useTranslation ( ) ;
8284 const { edges, deleteEdgesBySourceAndSourceHandle } = useGraphStore (
8385 ( state ) => state ,
8486 ) ;
8587
88+ const outputList = buildOutputList ( node ?. data . form . outputs ) ;
89+
8690 const defaultValues = useValues ( node ) ;
8791
8892 const { extraOptions } = useBuildPromptExtraPromptOptions ( edges , node ?. id ) ;
@@ -112,13 +116,18 @@ function AgentForm({ node }: INextOperatorForm) {
112116 name : 'exception_method' ,
113117 } ) ;
114118
119+ const showStructuredOutput = useWatch ( {
120+ control : form . control ,
121+ name : 'showStructuredOutput' ,
122+ } ) ;
123+
115124 const {
116125 initialStructuredOutput,
117126 showStructuredOutputDialog,
118127 structuredOutputDialogVisible,
119128 hideStructuredOutputDialog,
120129 handleStructuredOutputDialogOk,
121- } = useShowStructuredOutputDialog ( node ?. id ) ;
130+ } = useShowStructuredOutputDialog ( form ) ;
122131
123132 useEffect ( ( ) => {
124133 if ( exceptionMethod !== AgentExceptionMethod . Goto ) {
@@ -275,18 +284,42 @@ function AgentForm({ node }: INextOperatorForm) {
275284 ) }
276285 </ section >
277286 </ Collapse >
278- < Output list = { outputList } > </ Output >
279- < section className = "space-y-2" >
280- < div className = "flex justify-between items-center" >
281- { t ( 'flow.structuredOutput.structuredOutput' ) }
282- < Button variant = { 'outline' } onClick = { showStructuredOutputDialog } >
283- { t ( 'flow.structuredOutput.configuration' ) }
284- </ Button >
285- </ div >
286- < StructuredOutputPanel
287- value = { initialStructuredOutput }
288- > </ StructuredOutputPanel >
289- </ section >
287+ < RAGFlowFormItem name = { AgentStructuredOutputField } className = "hidden" >
288+ < Input > </ Input >
289+ </ RAGFlowFormItem >
290+ < Output list = { outputList } >
291+ < RAGFlowFormItem name = "showStructuredOutput" >
292+ { ( field ) => (
293+ < div className = "flex items-center space-x-2" >
294+ < Label htmlFor = "airplane-mode" >
295+ { t ( 'flow.structuredOutput.structuredOutput' ) }
296+ </ Label >
297+ < Switch
298+ id = "airplane-mode"
299+ checked = { field . value }
300+ onCheckedChange = { field . onChange }
301+ />
302+ </ div >
303+ ) }
304+ </ RAGFlowFormItem >
305+ </ Output >
306+ { showStructuredOutput && (
307+ < section className = "space-y-2" >
308+ < div className = "flex justify-between items-center" >
309+ { t ( 'flow.structuredOutput.structuredOutput' ) }
310+ < Button
311+ variant = { 'outline' }
312+ onClick = { showStructuredOutputDialog }
313+ >
314+ { t ( 'flow.structuredOutput.configuration' ) }
315+ </ Button >
316+ </ div >
317+
318+ < StructuredOutputPanel
319+ value = { initialStructuredOutput }
320+ > </ StructuredOutputPanel >
321+ </ section >
322+ ) }
290323 </ FormWrapper >
291324 </ Form >
292325 { structuredOutputDialogVisible && (
0 commit comments