'use client' import type { FC } from 'react' import type { WorkflowNodesMap } from '../workflow-variable-block/node' import type { FormInputItem } from '@/app/components/workflow/nodes/human-input/types' import type { Type } from '@/app/components/workflow/nodes/llm/types' import type { ValueSelector, Var } from '@/app/components/workflow/types' import { RiDeleteBinLine, RiEditLine } from '@remixicon/react' import { useBoolean } from 'ahooks' import * as React from 'react' import { useCallback, useEffect, useMemo, useRef } from 'react' import { InputVarType } from '@/app/components/workflow/types' import ActionButton from '../../../action-button' import { VariableX } from '../../../icons/src/vender/workflow' import Modal from '../../../modal' import InputField from './input-field' import VariableBlock from './variable-block' type HITLInputComponentUIProps = { nodeId: string varName: string formInput?: FormInputItem onChange: (input: FormInputItem) => void onRename: (payload: FormInputItem, oldName: string) => void onRemove: (varName: string) => void workflowNodesMap: WorkflowNodesMap environmentVariables?: Var[] conversationVariables?: Var[] ragVariables?: Var[] getVarType?: (payload: { nodeId: string valueSelector: ValueSelector }) => Type readonly?: boolean } const HITLInputComponentUI: FC = ({ nodeId, varName, formInput = { type: InputVarType.paragraph, output_variable_name: varName, default: { type: 'constant', selector: [], value: '', }, }, onChange, onRename, onRemove, workflowNodesMap = {}, getVarType, environmentVariables, conversationVariables, ragVariables, readonly, }) => { const [isShowEditModal, { setTrue: showEditModal, setFalse: hideEditModal, }] = useBoolean(false) // Lexical delegate the click make it unable to add click by the method of react const editBtnRef = useRef(null) useEffect(() => { const editBtn = editBtnRef.current if (editBtn) editBtn.addEventListener('click', showEditModal) return () => { if (editBtn) editBtn.removeEventListener('click', showEditModal) } // eslint-disable-next-line react-hooks/exhaustive-deps }, []) const removeBtnRef = useRef(null) useEffect(() => { const removeBtn = removeBtnRef.current const removeHandler = () => onRemove(varName) if (removeBtn) removeBtn.addEventListener('click', removeHandler) return () => { if (removeBtn) removeBtn.removeEventListener('click', removeHandler) } }, [onRemove, varName]) const handleChange = useCallback((newPayload: FormInputItem) => { if (varName === newPayload.output_variable_name) onChange(newPayload) else onRename(newPayload, varName) hideEditModal() }, [hideEditModal, onChange, onRename, varName]) const isDefaultValueVariable = useMemo(() => { return formInput.default?.type === 'variable' }, [formInput.default?.type]) return (
{varName}
{/* Default Value Info */} {isDefaultValueVariable && ( )} {!isDefaultValueVariable && (
{formInput.default?.value}
)}
{/* Actions */} {!readonly && (
)}
{isShowEditModal && ( )}
) } export default React.memo(HITLInputComponentUI)