| | |
| | | import Input from '@/app/components/workflow/nodes/_base/components/input-support-select-var' |
| | | import useAvailableVarList from '@/app/components/workflow/nodes/_base/hooks/use-available-var-list' |
| | | import { VarType } from '@/app/components/workflow/types' |
| | | import AppSelector from '@/app/components/plugins/plugin-detail-panel/app-selector' |
| | | import ModelParameterModal from '@/app/components/plugins/plugin-detail-panel/model-selector' |
| | | import { noop } from 'lodash-es' |
| | | |
| | | type Props = { |
| | | readOnly: boolean |
| | | nodeId: string |
| | |
| | | schema, |
| | | value, |
| | | onChange, |
| | | onOpen = noop, |
| | | onOpen = () => { }, |
| | | isSupportConstantValue, |
| | | filterVar, |
| | | }) => { |
| | |
| | | const paramType = (type: string) => { |
| | | if (type === FormTypeEnum.textNumber) |
| | | return 'Number' |
| | | else if (type === FormTypeEnum.file || type === FormTypeEnum.files) |
| | | else if (type === FormTypeEnum.file) |
| | | return 'File' |
| | | else if (type === FormTypeEnum.files) |
| | | return 'Files' |
| | | else if (type === FormTypeEnum.appSelector) |
| | | return 'AppSelector' |
| | | else if (type === FormTypeEnum.modelSelector) |
| | | return 'ModelSelector' |
| | | else if (type === FormTypeEnum.toolSelector) |
| | | return 'ToolSelector' |
| | | else if (type === FormTypeEnum.select) |
| | | return 'Options' |
| | | else |
| | | return 'String' |
| | | } |
| | |
| | | }) |
| | | onChange(newValue) |
| | | } |
| | | }, [value, onChange]) |
| | | }, [value, onChange, isSupportConstantValue]) |
| | | |
| | | const handleMixedTypeChange = useCallback((variable: string) => { |
| | | return (itemValue: string) => { |
| | |
| | | } |
| | | }, [value, onChange]) |
| | | |
| | | const handleAppChange = useCallback((variable: string) => { |
| | | return (app: { |
| | | app_id: string |
| | | inputs: Record<string, any> |
| | | files?: any[] |
| | | }) => { |
| | | const newValue = produce(value, (draft: ToolVarInputs) => { |
| | | draft[variable] = app as any |
| | | }) |
| | | onChange(newValue) |
| | | } |
| | | }, [onChange, value]) |
| | | const handleModelChange = useCallback((variable: string) => { |
| | | return (model: any) => { |
| | | const newValue = produce(value, (draft: ToolVarInputs) => { |
| | | draft[variable] = { |
| | | ...draft[variable], |
| | | ...model, |
| | | } as any |
| | | }) |
| | | onChange(newValue) |
| | | } |
| | | }, [onChange, value]) |
| | | |
| | | const [inputsIsFocus, setInputsIsFocus] = useState<Record<string, boolean>>({}) |
| | | const handleInputFocus = useCallback((variable: string) => { |
| | | return (value: boolean) => { |
| | |
| | | type, |
| | | required, |
| | | tooltip, |
| | | scope, |
| | | } = schema |
| | | const varInput = value[variable] |
| | | const isNumber = type === FormTypeEnum.textNumber |
| | | const isSelect = type === FormTypeEnum.select |
| | | const isFile = type === FormTypeEnum.file || type === FormTypeEnum.files |
| | | const isAppSelector = type === FormTypeEnum.appSelector |
| | | const isModelSelector = type === FormTypeEnum.modelSelector |
| | | // const isToolSelector = type === FormTypeEnum.toolSelector |
| | | const isString = !isNumber && !isSelect && !isFile && !isAppSelector && !isModelSelector |
| | | const isFile = type === FormTypeEnum.file |
| | | const isFileArray = type === FormTypeEnum.files |
| | | const isString = !isNumber && !isSelect && !isFile && !isFileArray |
| | | |
| | | return ( |
| | | <div key={variable} className='space-y-1'> |
| | | <div className='flex h-[18px] items-center space-x-2'> |
| | | <span className='code-sm-semibold text-text-secondary'>{label[language] || label.en_US}</span> |
| | | <span className='system-xs-regular text-text-tertiary'>{paramType(type)}</span> |
| | | {required && <span className='system-xs-regular text-util-colors-orange-dark-orange-dark-600'>Required</span>} |
| | | <div className='flex items-center h-[18px] space-x-2'> |
| | | <span className='text-text-secondary code-sm-semibold'>{label[language] || label.en_US}</span> |
| | | <span className='text-text-tertiary system-xs-regular'>{paramType(type)}</span> |
| | | {required && <span className='text-util-colors-orange-dark-orange-dark-600 system-xs-regular'>Required</span>} |
| | | </div> |
| | | {isString && ( |
| | | <Input |
| | | className={cn(inputsIsFocus[variable] ? 'border-components-input-border-active bg-components-input-bg-active shadow-xs' : 'border-components-input-border-hover bg-components-input-bg-normal', 'rounded-lg border px-3 py-[6px]')} |
| | | className={cn(inputsIsFocus[variable] ? 'shadow-xs bg-gray-50 border-gray-300' : 'bg-gray-100 border-gray-100', 'rounded-lg px-3 py-[6px] border')} |
| | | value={varInput?.value as string || ''} |
| | | onChange={handleMixedTypeChange(variable)} |
| | | readOnly={readOnly} |
| | |
| | | onChange={handleFileChange(variable)} |
| | | onOpen={handleOpen(index)} |
| | | defaultVarKindType={VarKindType.variable} |
| | | filterVar={(varPayload: Var) => varPayload.type === VarType.file || varPayload.type === VarType.arrayFile} |
| | | filterVar={(varPayload: Var) => varPayload.type === VarType.file} |
| | | /> |
| | | )} |
| | | {isAppSelector && ( |
| | | <AppSelector |
| | | disabled={readOnly} |
| | | scope={scope || 'all'} |
| | | value={varInput as any} |
| | | onSelect={handleAppChange(variable)} |
| | | /> |
| | | )} |
| | | {isModelSelector && ( |
| | | <ModelParameterModal |
| | | popupClassName='!w-[387px]' |
| | | isAdvancedMode |
| | | isInWorkflow |
| | | value={varInput as any} |
| | | setModel={handleModelChange(variable)} |
| | | {isFileArray && ( |
| | | <VarReferencePicker |
| | | readonly={readOnly} |
| | | scope={scope} |
| | | isShowNodeName |
| | | nodeId={nodeId} |
| | | value={varInput?.value || []} |
| | | onChange={handleFileChange(variable)} |
| | | onOpen={handleOpen(index)} |
| | | defaultVarKindType={VarKindType.variable} |
| | | filterVar={(varPayload: Var) => varPayload.type === VarType.arrayFile} |
| | | /> |
| | | )} |
| | | {tooltip && <div className='body-xs-regular text-text-tertiary'>{tooltip[language] || tooltip.en_US}</div>} |
| | | {tooltip && <div className='text-text-tertiary body-xs-regular'>{tooltip[language] || tooltip.en_US}</div>} |
| | | </div> |
| | | ) |
| | | }) |