mirror of
https://github.com/langgenius/dify.git
synced 2026-04-29 04:26:30 +08:00
support variable for string
This commit is contained in:
parent
91b89d755e
commit
d51bd90394
@ -22,6 +22,10 @@ import ToolSelector from '@/app/components/plugins/plugin-detail-panel/tool-sele
|
|||||||
import MultipleToolSelector from '@/app/components/plugins/plugin-detail-panel/multiple-tool-selector'
|
import MultipleToolSelector from '@/app/components/plugins/plugin-detail-panel/multiple-tool-selector'
|
||||||
import AppSelector from '@/app/components/plugins/plugin-detail-panel/app-selector'
|
import AppSelector from '@/app/components/plugins/plugin-detail-panel/app-selector'
|
||||||
import RadioE from '@/app/components/base/radio/ui'
|
import RadioE from '@/app/components/base/radio/ui'
|
||||||
|
import type {
|
||||||
|
NodeOutPutVar,
|
||||||
|
} from '@/app/components/workflow/types'
|
||||||
|
import type { Node } from 'reactflow'
|
||||||
|
|
||||||
type FormProps<
|
type FormProps<
|
||||||
CustomFormSchema extends Omit<CredentialFormSchema, 'type'> & { type: string } = never,
|
CustomFormSchema extends Omit<CredentialFormSchema, 'type'> & { type: string } = never,
|
||||||
@ -47,6 +51,9 @@ type FormProps<
|
|||||||
) => ReactNode
|
) => ReactNode
|
||||||
// If return falsy value, this field will fallback to default render
|
// If return falsy value, this field will fallback to default render
|
||||||
override?: [Array<FormTypeEnum>, (formSchema: CredentialFormSchema, props: Omit<FormProps<CustomFormSchema>, 'override' | 'customRenderField'>) => ReactNode]
|
override?: [Array<FormTypeEnum>, (formSchema: CredentialFormSchema, props: Omit<FormProps<CustomFormSchema>, 'override' | 'customRenderField'>) => ReactNode]
|
||||||
|
nodeId?: string
|
||||||
|
nodeOutputVars?: NodeOutPutVar[],
|
||||||
|
availableNodes?: Node[],
|
||||||
}
|
}
|
||||||
|
|
||||||
function Form<
|
function Form<
|
||||||
@ -69,6 +76,9 @@ function Form<
|
|||||||
fieldMoreInfo,
|
fieldMoreInfo,
|
||||||
customRenderField,
|
customRenderField,
|
||||||
override,
|
override,
|
||||||
|
nodeId,
|
||||||
|
nodeOutputVars,
|
||||||
|
availableNodes,
|
||||||
}: FormProps<CustomFormSchema>) {
|
}: FormProps<CustomFormSchema>) {
|
||||||
const language = useLanguage()
|
const language = useLanguage()
|
||||||
const [changeKey, setChangeKey] = useState('')
|
const [changeKey, setChangeKey] = useState('')
|
||||||
@ -326,8 +336,9 @@ function Form<
|
|||||||
</div>
|
</div>
|
||||||
<ToolSelector
|
<ToolSelector
|
||||||
scope={scope}
|
scope={scope}
|
||||||
nodeOutputVars={[]}
|
nodeId={nodeId}
|
||||||
availableNodes={[]}
|
nodeOutputVars={nodeOutputVars || []}
|
||||||
|
availableNodes={availableNodes || []}
|
||||||
disabled={readonly}
|
disabled={readonly}
|
||||||
value={value[variable]}
|
value={value[variable]}
|
||||||
// selectedTools={value[variable] ? [value[variable]] : []}
|
// selectedTools={value[variable] ? [value[variable]] : []}
|
||||||
@ -353,8 +364,9 @@ function Form<
|
|||||||
<div key={variable} className={cn(itemClassName, 'py-3')}>
|
<div key={variable} className={cn(itemClassName, 'py-3')}>
|
||||||
<MultipleToolSelector
|
<MultipleToolSelector
|
||||||
disabled={readonly}
|
disabled={readonly}
|
||||||
nodeOutputVars={[]}
|
nodeId={nodeId}
|
||||||
availableNodes={[]}
|
nodeOutputVars={nodeOutputVars || []}
|
||||||
|
availableNodes={availableNodes || []}
|
||||||
scope={scope}
|
scope={scope}
|
||||||
label={label[language] || label.en_US}
|
label={label[language] || label.en_US}
|
||||||
required={required}
|
required={required}
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { useCallback, useState } from 'react'
|
import { useCallback } from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import produce from 'immer'
|
import produce from 'immer'
|
||||||
import {
|
import {
|
||||||
@ -36,7 +36,7 @@ const ReasoningConfigForm: React.FC<Props> = ({
|
|||||||
onChange,
|
onChange,
|
||||||
schemas,
|
schemas,
|
||||||
nodeOutputVars,
|
nodeOutputVars,
|
||||||
availableNodes,
|
// availableNodes,
|
||||||
nodeId,
|
nodeId,
|
||||||
}) => {
|
}) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
@ -51,52 +51,52 @@ const ReasoningConfigForm: React.FC<Props> = ({
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const [inputsIsFocus, setInputsIsFocus] = useState<Record<string, boolean>>({})
|
// const [inputsIsFocus, setInputsIsFocus] = useState<Record<string, boolean>>({})
|
||||||
const handleInputFocus = useCallback((variable: string) => {
|
// const handleInputFocus = useCallback((variable: string) => {
|
||||||
return (value: boolean) => {
|
// return (value: boolean) => {
|
||||||
setInputsIsFocus((prev) => {
|
// setInputsIsFocus((prev) => {
|
||||||
return {
|
// return {
|
||||||
...prev,
|
// ...prev,
|
||||||
[variable]: value,
|
// [variable]: value,
|
||||||
}
|
// }
|
||||||
})
|
// })
|
||||||
}
|
// }
|
||||||
}, [])
|
// }, [])
|
||||||
const handleNotMixedTypeChange = useCallback((variable: string) => {
|
const handleNotMixedTypeChange = useCallback((variable: string, toString = false) => {
|
||||||
return (varValue: ValueSelector | string, varKindType: VarKindType) => {
|
return (varValue: ValueSelector | string, varKindType: VarKindType) => {
|
||||||
const newValue = produce(value, (draft: ToolVarInputs) => {
|
const newValue = produce(value, (draft: ToolVarInputs) => {
|
||||||
const target = draft[variable].value
|
const target = draft[variable].value
|
||||||
if (target) {
|
if (target) {
|
||||||
target.type = varKindType
|
target.type = varKindType
|
||||||
target.value = varValue
|
target.value = toString ? `${varValue}` : varValue
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
draft[variable].value = {
|
draft[variable].value = {
|
||||||
type: varKindType,
|
type: varKindType,
|
||||||
value: varValue,
|
value: toString ? `${varValue}` : varValue,
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
onChange(newValue)
|
|
||||||
}
|
|
||||||
}, [value, onChange])
|
|
||||||
const handleMixedTypeChange = useCallback((variable: string) => {
|
|
||||||
return (itemValue: string) => {
|
|
||||||
const newValue = produce(value, (draft: ToolVarInputs) => {
|
|
||||||
const target = draft[variable].value
|
|
||||||
if (target) {
|
|
||||||
target.value = itemValue
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
draft[variable].value = {
|
|
||||||
type: VarKindType.mixed,
|
|
||||||
value: itemValue,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
onChange(newValue)
|
onChange(newValue)
|
||||||
}
|
}
|
||||||
}, [value, onChange])
|
}, [value, onChange])
|
||||||
|
// const handleMixedTypeChange = useCallback((variable: string) => {
|
||||||
|
// return (itemValue: string) => {
|
||||||
|
// const newValue = produce(value, (draft: ToolVarInputs) => {
|
||||||
|
// const target = draft[variable].value
|
||||||
|
// if (target) {
|
||||||
|
// target.value = itemValue
|
||||||
|
// }
|
||||||
|
// else {
|
||||||
|
// draft[variable].value = {
|
||||||
|
// type: VarKindType.mixed,
|
||||||
|
// value: itemValue,
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// })
|
||||||
|
// onChange(newValue)
|
||||||
|
// }
|
||||||
|
// }, [value, onChange])
|
||||||
const handleFileChange = useCallback((variable: string) => {
|
const handleFileChange = useCallback((variable: string) => {
|
||||||
return (varValue: ValueSelector | string) => {
|
return (varValue: ValueSelector | string) => {
|
||||||
const newValue = produce(value, (draft: ToolVarInputs) => {
|
const newValue = produce(value, (draft: ToolVarInputs) => {
|
||||||
@ -192,8 +192,21 @@ const ReasoningConfigForm: React.FC<Props> = ({
|
|||||||
placeholderClassName='!leading-[21px]'
|
placeholderClassName='!leading-[21px]'
|
||||||
/>
|
/>
|
||||||
)} */}
|
)} */}
|
||||||
|
{isString && (
|
||||||
|
<VarReferencePicker
|
||||||
|
zIndex={1001}
|
||||||
|
readonly={false}
|
||||||
|
isShowNodeName
|
||||||
|
nodeId={nodeId}
|
||||||
|
value={varInput?.value || []}
|
||||||
|
onChange={handleNotMixedTypeChange(variable, true)}
|
||||||
|
defaultVarKindType={VarKindType.variable}
|
||||||
|
filterVar={(varPayload: Var) => varPayload.type === VarType.number || varPayload.type === VarType.secret || varPayload.type === VarType.string}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
{(isNumber || isSelect) && (
|
{(isNumber || isSelect) && (
|
||||||
<VarReferencePicker
|
<VarReferencePicker
|
||||||
|
zIndex={1001}
|
||||||
readonly={false}
|
readonly={false}
|
||||||
isShowNodeName
|
isShowNodeName
|
||||||
nodeId={nodeId}
|
nodeId={nodeId}
|
||||||
@ -208,6 +221,7 @@ const ReasoningConfigForm: React.FC<Props> = ({
|
|||||||
)}
|
)}
|
||||||
{isFile && (
|
{isFile && (
|
||||||
<VarReferencePicker
|
<VarReferencePicker
|
||||||
|
zIndex={1001}
|
||||||
readonly={false}
|
readonly={false}
|
||||||
isShowNodeName
|
isShowNodeName
|
||||||
nodeId={nodeId}
|
nodeId={nodeId}
|
||||||
|
|||||||
@ -156,9 +156,9 @@ export const AgentStrategy = memo((props: AgentStrategyProps) => {
|
|||||||
>
|
>
|
||||||
<ToolSelector
|
<ToolSelector
|
||||||
supportVariables
|
supportVariables
|
||||||
nodeId={nodeId || ''}
|
nodeId={props.nodeId || ''}
|
||||||
nodeOutputVars={nodeOutputVars || []}
|
nodeOutputVars={props.nodeOutputVars || []}
|
||||||
availableNodes={availableNodes || []}
|
availableNodes={props.availableNodes || []}
|
||||||
scope={schema.scope}
|
scope={schema.scope}
|
||||||
value={value}
|
value={value}
|
||||||
onSelect={item => onChange(item)}
|
onSelect={item => onChange(item)}
|
||||||
@ -175,9 +175,9 @@ export const AgentStrategy = memo((props: AgentStrategyProps) => {
|
|||||||
return (
|
return (
|
||||||
<MultipleToolSelector
|
<MultipleToolSelector
|
||||||
supportVariables
|
supportVariables
|
||||||
nodeId={nodeId || ''}
|
nodeId={props.nodeId || ''}
|
||||||
nodeOutputVars={nodeOutputVars || []}
|
nodeOutputVars={props.nodeOutputVars || []}
|
||||||
availableNodes={availableNodes || []}
|
availableNodes={props.availableNodes || []}
|
||||||
scope={schema.scope}
|
scope={schema.scope}
|
||||||
value={value || []}
|
value={value || []}
|
||||||
label={renderI18nObject(schema.label)}
|
label={renderI18nObject(schema.label)}
|
||||||
@ -208,6 +208,9 @@ export const AgentStrategy = memo((props: AgentStrategyProps) => {
|
|||||||
fieldLabelClassName='uppercase'
|
fieldLabelClassName='uppercase'
|
||||||
customRenderField={renderField}
|
customRenderField={renderField}
|
||||||
override={override}
|
override={override}
|
||||||
|
nodeId={nodeId}
|
||||||
|
nodeOutputVars={nodeOutputVars || []}
|
||||||
|
availableNodes={availableNodes || []}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
: <ListEmpty
|
: <ListEmpty
|
||||||
|
|||||||
@ -64,6 +64,7 @@ type Props = {
|
|||||||
placeholder?: string
|
placeholder?: string
|
||||||
minWidth?: number
|
minWidth?: number
|
||||||
popupFor?: 'assigned' | 'toAssigned'
|
popupFor?: 'assigned' | 'toAssigned'
|
||||||
|
zIndex?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
const VarReferencePicker: FC<Props> = ({
|
const VarReferencePicker: FC<Props> = ({
|
||||||
@ -90,6 +91,7 @@ const VarReferencePicker: FC<Props> = ({
|
|||||||
placeholder,
|
placeholder,
|
||||||
minWidth,
|
minWidth,
|
||||||
popupFor,
|
popupFor,
|
||||||
|
zIndex,
|
||||||
}) => {
|
}) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const store = useStoreApi()
|
const store = useStoreApi()
|
||||||
@ -386,7 +388,7 @@ const VarReferencePicker: FC<Props> = ({
|
|||||||
</>
|
</>
|
||||||
</WrapElem>
|
</WrapElem>
|
||||||
<PortalToFollowElemContent style={{
|
<PortalToFollowElemContent style={{
|
||||||
zIndex: 100,
|
zIndex: zIndex || 100,
|
||||||
}} className='mt-1'>
|
}} className='mt-1'>
|
||||||
{!isConstant && (
|
{!isConstant && (
|
||||||
<VarReferencePopup
|
<VarReferencePopup
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user