fix: llm node output variable

This commit is contained in:
zxhlyh
2026-02-11 16:36:38 +08:00
parent f01f7a0d32
commit 29d6d030f8
5 changed files with 77 additions and 44 deletions

View File

@ -343,12 +343,7 @@ const findExceptVarInObject = (
}
const getLLMNodeOutputVars = (llmNodeData: LLMNodeType): Var[] => {
const isComputerUseEnabled = !!llmNodeData.computer_use
const vars = [...LLM_OUTPUT_STRUCT].filter((item) => {
if (isComputerUseEnabled)
return true
return item.variable !== 'generation'
})
const vars = [...LLM_OUTPUT_STRUCT]
if (
llmNodeData.structured_output_enabled
@ -379,6 +374,7 @@ const formatItem = (
nodeId: id,
title: data.title,
vars: [],
nodeType: data?.type,
}
switch (data.type) {
case BlockEnum.Start: {

View File

@ -1,13 +1,14 @@
import type { Node, NodeOutPutVar, ValueSelector, Var } from '@/app/components/workflow/types'
import { useMemo } from 'react'
import { useShallow } from 'zustand/react/shallow'
import { useFeatures } from '@/app/components/base/features/hooks'
import {
useIsChatMode,
useWorkflow,
useWorkflowVariables,
} from '@/app/components/workflow/hooks'
import { useStore as useWorkflowStore } from '@/app/components/workflow/store'
import { BlockEnum } from '@/app/components/workflow/types'
import { BlockEnum, VarType } from '@/app/components/workflow/types'
import { inputVarTypeToVarType } from '../../data-source/utils'
import useNodeInfo from './use-node-info'
@ -33,6 +34,8 @@ const useAvailableVarList = (nodeId: string, {
const { getTreeLeafNodes, getNodeById, getBeforeNodesInSameBranchIncludeParent } = useWorkflow()
const { getNodeAvailableVars } = useWorkflowVariables()
const isChatMode = useIsChatMode()
const features = useFeatures(s => s.features)
const isSupportSandbox = !!features.sandbox?.enabled
const baseAvailableNodes = useMemo(() => {
return passedInAvailableNodes || (onlyLeafNodeVar ? getTreeLeafNodes(nodeId) : getBeforeNodesInSameBranchIncludeParent(nodeId))
}, [passedInAvailableNodes, onlyLeafNodeVar, nodeId, getTreeLeafNodes, getBeforeNodesInSameBranchIncludeParent])
@ -105,9 +108,12 @@ const useAvailableVarList = (nodeId: string, {
.map((nodeVar) => {
if (!llmNodeIds.has(nodeVar.nodeId))
return nodeVar
const nextVars = nodeVar.vars.filter(item => item.variable !== 'context')
if (nextVars.length === nodeVar.vars.length)
return nodeVar
const nextVars = nodeVar.vars.filter(item => item.variable !== 'context').filter((item) => {
if (isSupportSandbox && item.type === VarType.string)
return item.variable !== 'text' && item.variable !== 'reasoning_content'
return true
})
return {
...nodeVar,
vars: nextVars,

View File

@ -405,40 +405,46 @@ const Panel: FC<NodePanelProps<LLMNodeType>> = ({
)}
>
<>
{!!inputs.computer_use && (
<VarItem
name="generation"
type="object"
description={t(`${i18nPrefix}.outputVars.generation`, { ns: 'workflow' })}
subItems={[
{
name: 'content',
type: 'string',
description: '',
},
{
name: 'reasoning_content',
type: 'array[string]',
description: '',
},
{
name: 'tool_calls',
type: 'array[object]',
description: '',
},
]}
/>
)}
<VarItem
name="text"
type="string"
description={t(`${i18nPrefix}.outputVars.output`, { ns: 'workflow' })}
/>
<VarItem
name="reasoning_content"
type="string"
description={t(`${i18nPrefix}.outputVars.reasoning_content`, { ns: 'workflow' })}
name="generation"
type="object"
description={t(`${i18nPrefix}.outputVars.generation`, { ns: 'workflow' })}
subItems={[
{
name: 'content',
type: 'string',
description: '',
},
{
name: 'reasoning_content',
type: 'array[string]',
description: '',
},
{
name: 'tool_calls',
type: 'array[object]',
description: '',
},
]}
/>
{
!isSupportSandbox && (
<VarItem
name="text"
type="string"
description={t(`${i18nPrefix}.outputVars.output`, { ns: 'workflow' })}
/>
)
}
{
!isSupportSandbox && (
<VarItem
name="reasoning_content"
type="string"
description={t(`${i18nPrefix}.outputVars.reasoning_content`, { ns: 'workflow' })}
/>
)
}
<VarItem
name="usage"
type="object"

View File

@ -8,13 +8,13 @@ import type {
VariableAssignerNodeType,
} from './types'
import { uniqBy } from 'es-toolkit/compat'
import { produce } from 'immer'
import { useCallback } from 'react'
import {
useNodes,
useStoreApi,
} from 'reactflow'
import { useFeatures } from '@/app/components/base/features/hooks'
import {
useIsChatMode,
useNodeDataUpdate,
@ -22,6 +22,7 @@ import {
useWorkflowVariables,
} from '../../hooks'
import { useWorkflowStore } from '../../store'
import { BlockEnum, VarType } from '../../types'
export const useVariableAssigner = () => {
const store = useStoreApi()
@ -129,6 +130,8 @@ export const useGetAvailableVars = () => {
const { getBeforeNodesInSameBranchIncludeParent } = useWorkflow()
const { getNodeAvailableVars } = useWorkflowVariables()
const isChatMode = useIsChatMode()
const features = useFeatures(s => s.features)
const isSupportSandbox = !!features.sandbox?.enabled
const getAvailableVars = useCallback((nodeId: string, handleId: string, filterVar: (v: Var) => boolean, hideEnv = false) => {
const availableNodes: Node[] = []
const currentNode = nodes.find(node => node.id === nodeId)!
@ -152,6 +155,17 @@ export const useGetAvailableVars = () => {
...node,
vars: node.isStartNode ? node.vars.filter(v => !v.variable.startsWith('sys.')) : node.vars,
}))
.map((node) => {
return {
...node,
vars: node.vars.filter((item) => {
if (isSupportSandbox && item.type === VarType.string && node.nodeType === BlockEnum.LLM)
return item.variable !== 'text' && item.variable !== 'reasoning_content'
return true
}),
}
})
.filter(item => item.vars.length > 0)
}
@ -160,8 +174,18 @@ export const useGetAvailableVars = () => {
beforeNodes: uniqBy(availableNodes, 'id').filter(node => node.id !== nodeId),
isChatMode,
filterVar,
}).map((node) => {
return {
...node,
vars: node.vars.filter((item) => {
if (isSupportSandbox && item.type === VarType.string && node.nodeType === BlockEnum.LLM)
return item.variable !== 'text' && item.variable !== 'reasoning_content'
return true
}),
}
})
}, [nodes, getBeforeNodesInSameBranchIncludeParent, getNodeAvailableVars, isChatMode])
}, [nodes, getBeforeNodesInSameBranchIncludeParent, getNodeAvailableVars, isChatMode, isSupportSandbox])
return getAvailableVars
}

View File

@ -355,6 +355,7 @@ export type NodeOutPutVar = {
isStartNode?: boolean
isLoop?: boolean
isFlat?: boolean
nodeType?: BlockEnum
}
// allow node default validators with narrower payload types to be stored in shared collections.