mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-17 04:36:01 +08:00
feat: var picker can show the right var
This commit is contained in:
parent
84eb6a4715
commit
8adf0fa698
@ -82,7 +82,7 @@ const Panel: FC = () => {
|
|||||||
? LangfuseIcon
|
? LangfuseIcon
|
||||||
: inUseTracingProvider === TracingProvider.opik
|
: inUseTracingProvider === TracingProvider.opik
|
||||||
? OpikIcon
|
? OpikIcon
|
||||||
: null
|
: LangsmithIcon
|
||||||
|
|
||||||
const [langSmithConfig, setLangSmithConfig] = useState<LangSmithConfig | null>(null)
|
const [langSmithConfig, setLangSmithConfig] = useState<LangSmithConfig | null>(null)
|
||||||
const [langFuseConfig, setLangFuseConfig] = useState<LangFuseConfig | null>(null)
|
const [langFuseConfig, setLangFuseConfig] = useState<LangFuseConfig | null>(null)
|
||||||
|
@ -58,11 +58,11 @@ const Field: FC<Props> = ({
|
|||||||
|
|
||||||
{depth <= MAX_DEPTH && payload.type === Type.object && payload.properties && (
|
{depth <= MAX_DEPTH && payload.type === Type.object && payload.properties && (
|
||||||
<div>
|
<div>
|
||||||
{Object.keys(payload.properties).map(name => (
|
{Object.keys(payload.properties).map(propName => (
|
||||||
<Field
|
<Field
|
||||||
key={name}
|
key={propName}
|
||||||
name={name}
|
name={propName}
|
||||||
payload={payload.properties?.[name] as FieldType}
|
payload={payload.properties?.[propName] as FieldType}
|
||||||
depth={depth + 1}
|
depth={depth + 1}
|
||||||
readonly={readonly}
|
readonly={readonly}
|
||||||
valueSelector={[...valueSelector, name]}
|
valueSelector={[...valueSelector, name]}
|
||||||
|
@ -656,10 +656,30 @@ export const getVarType = ({
|
|||||||
|
|
||||||
let type: VarType = VarType.string
|
let type: VarType = VarType.string
|
||||||
let curr: any = targetVar.vars
|
let curr: any = targetVar.vars
|
||||||
|
|
||||||
if (isSystem || isEnv || isChatVar) {
|
if (isSystem || isEnv || isChatVar) {
|
||||||
return curr.find((v: any) => v.variable === (valueSelector as ValueSelector).join('.'))?.type
|
return curr.find((v: any) => v.variable === (valueSelector as ValueSelector).join('.'))?.type
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
const targetVar = curr.find((v: any) => v.variable === valueSelector[1])
|
||||||
|
if (!targetVar)
|
||||||
|
return VarType.string
|
||||||
|
|
||||||
|
const isStructuredOutputVar = !!targetVar.children.schema?.properties
|
||||||
|
if (isStructuredOutputVar) {
|
||||||
|
let currProperties = targetVar.children.schema;
|
||||||
|
(valueSelector as ValueSelector).slice(2).forEach((key, i) => {
|
||||||
|
const isLast = i === valueSelector.length - 3
|
||||||
|
if (!currProperties)
|
||||||
|
return
|
||||||
|
|
||||||
|
currProperties = currProperties.properties[key]
|
||||||
|
if (isLast)
|
||||||
|
type = structTypeToVarType(currProperties?.type)
|
||||||
|
})
|
||||||
|
return type
|
||||||
|
}
|
||||||
|
|
||||||
(valueSelector as ValueSelector).slice(1).forEach((key, i) => {
|
(valueSelector as ValueSelector).slice(1).forEach((key, i) => {
|
||||||
const isLast = i === valueSelector.length - 2
|
const isLast = i === valueSelector.length - 2
|
||||||
if (Array.isArray(curr))
|
if (Array.isArray(curr))
|
||||||
|
@ -13,7 +13,7 @@ import { useStoreApi } from 'reactflow'
|
|||||||
import RemoveButton from '../remove-button'
|
import RemoveButton from '../remove-button'
|
||||||
import useAvailableVarList from '../../hooks/use-available-var-list'
|
import useAvailableVarList from '../../hooks/use-available-var-list'
|
||||||
import VarReferencePopup from './var-reference-popup'
|
import VarReferencePopup from './var-reference-popup'
|
||||||
import { getNodeInfoById, isConversationVar, isENV, isSystemVar } from './utils'
|
import { getNodeInfoById, isConversationVar, isENV, isSystemVar, varTypeToStructType } from './utils'
|
||||||
import ConstantField from './constant-field'
|
import ConstantField from './constant-field'
|
||||||
import cn from '@/utils/classnames'
|
import cn from '@/utils/classnames'
|
||||||
import type { Node, NodeOutPutVar, ValueSelector, Var } from '@/app/components/workflow/types'
|
import type { Node, NodeOutPutVar, ValueSelector, Var } from '@/app/components/workflow/types'
|
||||||
@ -39,7 +39,6 @@ import Badge from '@/app/components/base/badge'
|
|||||||
import Tooltip from '@/app/components/base/tooltip'
|
import Tooltip from '@/app/components/base/tooltip'
|
||||||
import { isExceptionVariable } from '@/app/components/workflow/utils'
|
import { isExceptionVariable } from '@/app/components/workflow/utils'
|
||||||
import VarFullPathPanel from './var-full-path-panel'
|
import VarFullPathPanel from './var-full-path-panel'
|
||||||
import { Type } from '../../../llm/types'
|
|
||||||
|
|
||||||
const TRIGGER_DEFAULT_WIDTH = 227
|
const TRIGGER_DEFAULT_WIDTH = 227
|
||||||
|
|
||||||
@ -262,7 +261,7 @@ const VarReferencePicker: FC<Props> = ({
|
|||||||
<VarFullPathPanel
|
<VarFullPathPanel
|
||||||
nodeName={outputVarNode?.title}
|
nodeName={outputVarNode?.title}
|
||||||
path={(value as ValueSelector).slice(1)}
|
path={(value as ValueSelector).slice(1)}
|
||||||
varType={Type.string}
|
varType={varTypeToStructType(type)}
|
||||||
nodeType={outputVarNode?.type}
|
nodeType={outputVarNode?.type}
|
||||||
/>)
|
/>)
|
||||||
}
|
}
|
||||||
@ -270,7 +269,7 @@ const VarReferencePicker: FC<Props> = ({
|
|||||||
return t('workflow.errorMsg.invalidVariable')
|
return t('workflow.errorMsg.invalidVariable')
|
||||||
|
|
||||||
return null
|
return null
|
||||||
}, [isValidVar, isShowAPart, hasValue, t, outputVarNode?.title, outputVarNode?.type, value])
|
}, [isValidVar, isShowAPart, hasValue, t, outputVarNode?.title, outputVarNode?.type, value, type])
|
||||||
return (
|
return (
|
||||||
<div className={cn(className, !readonly && 'cursor-pointer')}>
|
<div className={cn(className, !readonly && 'cursor-pointer')}>
|
||||||
<PortalToFollowElem
|
<PortalToFollowElem
|
||||||
|
Loading…
x
Reference in New Issue
Block a user