diff --git a/web/app/components/base/prompt-editor/plugins/workflow-variable-block/component.tsx b/web/app/components/base/prompt-editor/plugins/workflow-variable-block/component.tsx index da5ad84cb1..06b583543a 100644 --- a/web/app/components/base/prompt-editor/plugins/workflow-variable-block/component.tsx +++ b/web/app/components/base/prompt-editor/plugins/workflow-variable-block/component.tsx @@ -10,10 +10,6 @@ import { } from 'lexical' import { mergeRegister } from '@lexical/utils' import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext' -import { - RiErrorWarningFill, - RiMoreLine, -} from '@remixicon/react' import { useReactFlow, useStoreApi } from 'reactflow' import { useSelectOrDelete } from '../../hooks' import type { WorkflowNodesMap } from './node' @@ -22,17 +18,15 @@ import { DELETE_WORKFLOW_VARIABLE_BLOCK_COMMAND, UPDATE_WORKFLOW_NODES_MAP, } from './index' -import cn from '@/utils/classnames' -import { Variable02 } from '@/app/components/base/icons/src/vender/solid/development' -import { BubbleX, Env } from '@/app/components/base/icons/src/vender/line/others' -import { VarBlockIcon } from '@/app/components/workflow/block-icon' -import { Line3 } from '@/app/components/base/icons/src/public/common' import { isConversationVar, isENV, isSystemVar } from '@/app/components/workflow/nodes/_base/components/variable/utils' import Tooltip from '@/app/components/base/tooltip' import { isExceptionVariable } from '@/app/components/workflow/utils' import VarFullPathPanel from '@/app/components/workflow/nodes/_base/components/variable/var-full-path-panel' import { Type } from '@/app/components/workflow/nodes/llm/types' import type { ValueSelector, Var } from '@/app/components/workflow/types' +import { + VariableLabelInEditor, +} from '@/app/components/workflow/nodes/_base/components/variable/variable-label' type WorkflowVariableBlockComponentProps = { nodeKey: string @@ -126,69 +120,22 @@ const WorkflowVariableBlockComponent = ({ }, [node, reactflow, store]) const Item = ( -
{ e.stopPropagation() handleVariableJump() }} + isExceptionVariable={isException} + errorMsg={!variableValid ? t('workflow.errorMsg.invalidVariable') : undefined} + isSelected={isSelected} ref={ref} - > - {!isEnv && !isChatVar && ( -
- { - node?.type && ( -
- -
- ) - } -
{node?.title}
- -
- )} - {isShowAPart && ( -
- - -
- )} - -
- {!isEnv && !isChatVar && } - {isEnv && } - {isChatVar && } -
{varName}
- { - !variableValid && ( - - ) - } -
-
+ notShowFullPath={isShowAPart} + /> ) - if (!variableValid) { - return ( - - {Item} - - ) - } - if (!node) return Item diff --git a/web/app/components/workflow/nodes/_base/components/readonly-input-with-select-var.tsx b/web/app/components/workflow/nodes/_base/components/readonly-input-with-select-var.tsx index 4a4ca454d3..c1927011dc 100644 --- a/web/app/components/workflow/nodes/_base/components/readonly-input-with-select-var.tsx +++ b/web/app/components/workflow/nodes/_base/components/readonly-input-with-select-var.tsx @@ -4,12 +4,10 @@ import React from 'react' import cn from 'classnames' import { useWorkflow } from '../../../hooks' import { BlockEnum } from '../../../types' -import { VarBlockIcon } from '../../../block-icon' -import { getNodeInfoById, isConversationVar, isENV, isSystemVar } from './variable/utils' -import { Line3 } from '@/app/components/base/icons/src/public/common' -import { Variable02 } from '@/app/components/base/icons/src/vender/solid/development' -import { BubbleX, Env } from '@/app/components/base/icons/src/vender/line/others' -import { RiMoreLine } from '@remixicon/react' +import { getNodeInfoById, isSystemVar } from './variable/utils' +import { + VariableLabelInText, +} from '@/app/components/workflow/nodes/_base/components/variable/variable-label' type Props = { nodeId: string value: string @@ -42,40 +40,17 @@ const ReadonlyInputWithSelectVar: FC = ({ const value = vars[index].split('.') const isSystem = isSystemVar(value) - const isEnv = isENV(value) - const isChatVar = isConversationVar(value) const node = (isSystem ? startNode : getNodeInfoById(availableNodes, value[0]))?.data - const varName = `${isSystem ? 'sys.' : ''}${value[value.length - 1]}` const isShowAPart = value.length > 2 return ( {str} -
- {!isEnv && !isChatVar && ( -
-
- -
-
{node?.title}
- -
- )} - {isShowAPart && ( -
- - -
- )} -
- {!isEnv && !isChatVar && } - {isEnv && } - {isChatVar && } -
{varName}
-
-
+
) }) return html diff --git a/web/app/components/workflow/nodes/_base/components/variable-tag.tsx b/web/app/components/workflow/nodes/_base/components/variable-tag.tsx index d73a3d4924..163cbba49e 100644 --- a/web/app/components/workflow/nodes/_base/components/variable-tag.tsx +++ b/web/app/components/workflow/nodes/_base/components/variable-tag.tsx @@ -1,9 +1,6 @@ import { useCallback, useMemo } from 'react' import { useNodes, useReactFlow, useStoreApi } from 'reactflow' -import { capitalize } from 'lodash-es' import { useTranslation } from 'react-i18next' -import { RiErrorWarningFill } from '@remixicon/react' -import { VarBlockIcon } from '@/app/components/workflow/block-icon' import type { CommonNodeType, Node, @@ -11,13 +8,11 @@ import type { VarType, } from '@/app/components/workflow/types' import { BlockEnum } from '@/app/components/workflow/types' -import { Line3 } from '@/app/components/base/icons/src/public/common' -import { Variable02 } from '@/app/components/base/icons/src/vender/solid/development' -import { BubbleX, Env } from '@/app/components/base/icons/src/vender/line/others' import { getNodeInfoById, isConversationVar, isENV, isSystemVar } from '@/app/components/workflow/nodes/_base/components/variable/utils' -import Tooltip from '@/app/components/base/tooltip' -import cn from '@/utils/classnames' import { isExceptionVariable } from '@/app/components/workflow/utils' +import { + VariableLabelInSelect, +} from '@/app/components/workflow/nodes/_base/components/variable/variable-label' type VariableTagProps = { valueSelector: ValueSelector @@ -73,51 +68,20 @@ const VariableTag = ({ const { t } = useTranslation() return ( - -
{ - if (e.metaKey || e.ctrlKey) { - e.stopPropagation() - handleVariableJump() - } - }} - > - {(!isEnv && !isChatVar && <> - {node && ( - <> - -
- {node?.data.title} -
- - )} - - - )} - {isEnv && } - {isChatVar && } -
- {variableName} -
- { - !isShort && varType && ( -
{capitalize(varType)}
- ) + { + if (e.metaKey || e.ctrlKey) { + e.stopPropagation() + handleVariableJump() } - {!isValid && } -
-
+ }} + errorMsg={!isValid ? t('workflow.errorMsg.invalidVariable') : undefined} + isExceptionVariable={isException} + /> ) } diff --git a/web/app/components/workflow/nodes/_base/components/variable/var-reference-picker.tsx b/web/app/components/workflow/nodes/_base/components/variable/var-reference-picker.tsx index e6f3ce1fa1..0e57db0d8f 100644 --- a/web/app/components/workflow/nodes/_base/components/variable/var-reference-picker.tsx +++ b/web/app/components/workflow/nodes/_base/components/variable/var-reference-picker.tsx @@ -23,7 +23,6 @@ import { type CredentialFormSchema, type FormOption, FormTypeEnum } from '@/app/ import { BlockEnum } from '@/app/components/workflow/types' import { VarBlockIcon } from '@/app/components/workflow/block-icon' import { Line3 } from '@/app/components/base/icons/src/public/common' -import { BubbleX, Env } from '@/app/components/base/icons/src/vender/line/others' import { Variable02 } from '@/app/components/base/icons/src/vender/solid/development' import { PortalToFollowElem, @@ -44,6 +43,7 @@ import VarFullPathPanel from './var-full-path-panel' import { noop } from 'lodash-es' import { useFetchDynamicOptions } from '@/service/use-plugins' import type { Tool } from '@/app/components/tools/types' +import { VariableIconWithColor } from '@/app/components/workflow/nodes/_base/components/variable/variable-label' const TRIGGER_DEFAULT_WIDTH = 227 @@ -138,7 +138,6 @@ const VarReferencePicker: FC = ({ useEffect(() => { if (triggerRef.current) setTriggerWidth(triggerRef.current.clientWidth) - // eslint-disable-next-line react-hooks/exhaustive-deps }, [triggerRef.current]) const [varKindType, setVarKindType] = useState(defaultVarKindType) @@ -149,7 +148,6 @@ const VarReferencePicker: FC = ({ const [open, setOpen] = useState(false) useEffect(() => { onOpen() - // eslint-disable-next-line react-hooks/exhaustive-deps }, [open]) const hasValue = !isConstant && value.length > 0 @@ -362,6 +360,13 @@ const VarReferencePicker: FC = ({ return schema }, [dynamicOptions]) + const variableCategory = useMemo(() => { + if (isEnv) return 'environment' + if (isChatVar) return 'conversation' + if (isLoopVar) return 'loop' + return 'system' + }, [isEnv, isChatVar, isLoopVar]) + return (
= ({
)}
- {!hasValue && } {isLoading && } - {isEnv && } - {isChatVar && } +
{varName}
diff --git a/web/app/components/workflow/nodes/_base/components/variable/var-reference-vars.tsx b/web/app/components/workflow/nodes/_base/components/variable/var-reference-vars.tsx index 303840d8e7..2c600ba66c 100644 --- a/web/app/components/workflow/nodes/_base/components/variable/var-reference-vars.tsx +++ b/web/app/components/workflow/nodes/_base/components/variable/var-reference-vars.tsx @@ -5,7 +5,6 @@ import { useHover } from 'ahooks' import { useTranslation } from 'react-i18next' import cn from '@/utils/classnames' import { type NodeOutPutVar, type ValueSelector, type Var, VarType } from '@/app/components/workflow/types' -import { Variable02 } from '@/app/components/base/icons/src/vender/solid/development' import { ChevronRight } from '@/app/components/base/icons/src/vender/line/arrows' import { PortalToFollowElem, @@ -13,7 +12,6 @@ import { PortalToFollowElemTrigger, } from '@/app/components/base/portal-to-follow-elem' import Input from '@/app/components/base/input' -import { BubbleX, Env } from '@/app/components/base/icons/src/vender/line/others' import { checkKeys } from '@/utils/var' import type { StructuredOutput } from '../../../llm/types' import { Type } from '../../../llm/types' @@ -21,8 +19,8 @@ import PickerStructurePanel from '@/app/components/workflow/nodes/_base/componen import { varTypeToStructType } from './utils' import type { Field } from '@/app/components/workflow/nodes/llm/types' import { FILE_STRUCT } from '@/app/components/workflow/constants' -import { Loop } from '@/app/components/base/icons/src/vender/workflow' import { noop } from 'lodash-es' +import { VariableIconWithColor } from '@/app/components/workflow/nodes/_base/components/variable/variable-label' type ObjectChildrenProps = { nodeId: string @@ -118,7 +116,6 @@ const Item: FC = ({ const open = (isObj || isStructureOutput) && isHovering useEffect(() => { onHovering && onHovering(isHovering) - // eslint-disable-next-line react-hooks/exhaustive-deps }, [isHovering]) const handleChosen = (e: React.MouseEvent) => { e.stopPropagation() @@ -132,6 +129,12 @@ const Item: FC = ({ onChange([nodeId, ...objPath, itemData.variable], itemData) } } + const variableCategory = useMemo(() => { + if (isEnv) return 'environment' + if (isChatVar) return 'conversation' + if (isLoopVar) return 'loop' + return 'system' + }, [isEnv, isChatVar, isSys, isLoopVar]) return ( = ({ onMouseDown={e => e.preventDefault()} >
- {!isEnv && !isChatVar && !isLoopVar && } - {isEnv && } - {isChatVar && } - {isLoopVar && } + {!isEnv && !isChatVar && (
{itemData.variable}
)} @@ -219,11 +222,9 @@ const ObjectChildren: FC = ({ const isHovering = isItemHovering || isChildrenHovering useEffect(() => { onHovering && onHovering(isHovering) - // eslint-disable-next-line react-hooks/exhaustive-deps }, [isHovering]) useEffect(() => { onHovering && onHovering(isItemHovering) - // eslint-disable-next-line react-hooks/exhaustive-deps }, [isItemHovering]) // absolute top-[-2px] return ( diff --git a/web/app/components/workflow/nodes/_base/components/variable/variable-label/base/variable-icon.tsx b/web/app/components/workflow/nodes/_base/components/variable/variable-label/base/variable-icon.tsx new file mode 100644 index 0000000000..93f47f794a --- /dev/null +++ b/web/app/components/workflow/nodes/_base/components/variable/variable-label/base/variable-icon.tsx @@ -0,0 +1,28 @@ +import { memo } from 'react' +import cn from '@/utils/classnames' +import { useVarIcon } from '../hooks' +import type { VarInInspectType } from '@/types/workflow' + +export type VariableIconProps = { + className?: string + variables?: string[] + variableCategory?: VarInInspectType | string +} +const VariableIcon = ({ + className, + variables = [], + variableCategory, +}: VariableIconProps) => { + const VarIcon = useVarIcon(variables, variableCategory) + + return VarIcon && ( + + ) +} + +export default memo(VariableIcon) diff --git a/web/app/components/workflow/nodes/_base/components/variable/variable-label/base/variable-label.tsx b/web/app/components/workflow/nodes/_base/components/variable/variable-label/base/variable-label.tsx new file mode 100644 index 0000000000..99f080f545 --- /dev/null +++ b/web/app/components/workflow/nodes/_base/components/variable/variable-label/base/variable-label.tsx @@ -0,0 +1,83 @@ +import { memo } from 'react' +import { capitalize } from 'lodash-es' +import { + RiErrorWarningFill, + RiMoreLine, +} from '@remixicon/react' +import type { VariablePayload } from '../types' +import { useVarColor } from '../hooks' +import VariableNodeLabel from './variable-node-label' +import VariableIcon from './variable-icon' +import VariableName from './variable-name' +import cn from '@/utils/classnames' +import Tooltip from '@/app/components/base/tooltip' + +const VariableLabel = ({ + nodeType, + nodeTitle, + variables, + variableType, + className, + errorMsg, + onClick, + isExceptionVariable, + ref, + notShowFullPath, + rightSlot, +}: VariablePayload) => { + const varColorClassName = useVarColor(variables, isExceptionVariable) + return ( +
+ + { + notShowFullPath && ( + <> + +
/
+ + ) + } + + + { + variableType && ( +
+ {capitalize(variableType)} +
+ ) + } + { + !!errorMsg && ( + + + + ) + } + { + rightSlot + } +
+ ) +} + +export default memo(VariableLabel) diff --git a/web/app/components/workflow/nodes/_base/components/variable/variable-label/base/variable-name.tsx b/web/app/components/workflow/nodes/_base/components/variable/variable-label/base/variable-name.tsx new file mode 100644 index 0000000000..f656b780a5 --- /dev/null +++ b/web/app/components/workflow/nodes/_base/components/variable/variable-label/base/variable-name.tsx @@ -0,0 +1,30 @@ +import { memo } from 'react' +import { useVarName } from '../hooks' +import cn from '@/utils/classnames' + +type VariableNameProps = { + variables: string[] + className?: string + notShowFullPath?: boolean +} +const VariableName = ({ + variables, + className, + notShowFullPath, +}: VariableNameProps) => { + const varName = useVarName(variables, notShowFullPath) + + return ( +
+ {varName} +
+ ) +} + +export default memo(VariableName) diff --git a/web/app/components/workflow/nodes/_base/components/variable/variable-label/base/variable-node-label.tsx b/web/app/components/workflow/nodes/_base/components/variable/variable-label/base/variable-node-label.tsx new file mode 100644 index 0000000000..e4b0e52866 --- /dev/null +++ b/web/app/components/workflow/nodes/_base/components/variable/variable-label/base/variable-node-label.tsx @@ -0,0 +1,37 @@ +import { memo } from 'react' +import { VarBlockIcon } from '@/app/components/workflow/block-icon' +import type { BlockEnum } from '@/app/components/workflow/types' + +type VariableNodeLabelProps = { + nodeType?: BlockEnum + nodeTitle?: string +} +const VariableNodeLabel = ({ + nodeType, + nodeTitle, +}: VariableNodeLabelProps) => { + if (!nodeType) + return null + + return ( + <> + + { + nodeTitle && ( +
+ {nodeTitle} +
+ ) + } +
/
+ + ) +} + +export default memo(VariableNodeLabel) diff --git a/web/app/components/workflow/nodes/_base/components/variable/variable-label/hooks.ts b/web/app/components/workflow/nodes/_base/components/variable/variable-label/hooks.ts new file mode 100644 index 0000000000..14ca87903b --- /dev/null +++ b/web/app/components/workflow/nodes/_base/components/variable/variable-label/hooks.ts @@ -0,0 +1,89 @@ +import { useMemo } from 'react' +import { Variable02 } from '@/app/components/base/icons/src/vender/solid/development' +import { BubbleX, Env } from '@/app/components/base/icons/src/vender/line/others' +import { Loop } from '@/app/components/base/icons/src/vender/workflow' +import { + isConversationVar, + isENV, + isSystemVar, +} from '../utils' +import { VarInInspectType } from '@/types/workflow' + +export const useVarIcon = (variables: string[], variableCategory?: VarInInspectType | string) => { + if (variableCategory === 'loop') + return Loop + + if (isENV(variables) || variableCategory === VarInInspectType.environment || variableCategory === 'environment') + return Env + + if (isConversationVar(variables) || variableCategory === VarInInspectType.conversation || variableCategory === 'conversation') + return BubbleX + + return Variable02 +} + +export const useVarColor = (variables: string[], isExceptionVariable?: boolean, variableCategory?: VarInInspectType | string) => { + return useMemo(() => { + if (isExceptionVariable) + return 'text-text-warning' + + if (variableCategory === 'loop') + return 'text-util-colors-cyan-cyan-500' + + if (isENV(variables) || variableCategory === VarInInspectType.environment || variableCategory === 'environment') + return 'text-util-colors-violet-violet-600' + + if (isConversationVar(variables) || variableCategory === VarInInspectType.conversation || variableCategory === 'conversation') + return 'text-util-colors-teal-teal-700' + + return 'text-text-accent' + }, [variables, isExceptionVariable]) +} + +export const useVarName = (variables: string[], notShowFullPath?: boolean) => { + const variableFullPathName = variables.slice(1).join('.') + const variablesLength = variables.length + const varName = useMemo(() => { + const isSystem = isSystemVar(variables) + const varName = notShowFullPath ? variables[variablesLength - 1] : variableFullPathName + return `${isSystem ? 'sys.' : ''}${varName}` + }, [variables, notShowFullPath]) + + return varName +} + +export const useVarBgColorInEditor = (variables: string[], hasError?: boolean) => { + if (hasError) { + return { + hoverBorderColor: 'hover:border-state-destructive-active', + hoverBgColor: 'hover:bg-state-destructive-hover', + selectedBorderColor: '!border-state-destructive-solid', + selectedBgColor: '!bg-state-destructive-hover', + } + } + + if (isENV(variables)) { + return { + hoverBorderColor: 'hover:border-util-colors-violet-violet-100', + hoverBgColor: 'hover:bg-util-colors-violet-violet-50', + selectedBorderColor: 'border-util-colors-violet-violet-600', + selectedBgColor: 'bg-util-colors-violet-violet-50', + } + } + + if (isConversationVar(variables)) { + return { + hoverBorderColor: 'hover:border-util-colors-teal-teal-100', + hoverBgColor: 'hover:bg-util-colors-teal-teal-50', + selectedBorderColor: 'border-util-colors-teal-teal-600', + selectedBgColor: 'bg-util-colors-teal-teal-50', + } + } + + return { + hoverBorderColor: 'hover:border-state-accent-alt', + hoverBgColor: 'hover:bg-state-accent-hover', + selectedBorderColor: 'border-state-accent-solid', + selectedBgColor: 'bg-state-accent-hover', + } +} diff --git a/web/app/components/workflow/nodes/_base/components/variable/variable-label/index.tsx b/web/app/components/workflow/nodes/_base/components/variable/variable-label/index.tsx new file mode 100644 index 0000000000..012522e0aa --- /dev/null +++ b/web/app/components/workflow/nodes/_base/components/variable/variable-label/index.tsx @@ -0,0 +1,5 @@ +export { default as VariableLabelInSelect } from './variable-label-in-select' +export { default as VariableLabelInEditor } from './variable-label-in-editor' +export { default as VariableLabelInNode } from './variable-label-in-node' +export { default as VariableLabelInText } from './variable-label-in-text' +export { default as VariableIconWithColor } from './variable-icon-with-color' diff --git a/web/app/components/workflow/nodes/_base/components/variable/variable-label/types.ts b/web/app/components/workflow/nodes/_base/components/variable/variable-label/types.ts new file mode 100644 index 0000000000..6f3b06f6ee --- /dev/null +++ b/web/app/components/workflow/nodes/_base/components/variable/variable-label/types.ts @@ -0,0 +1,19 @@ +import type { ReactNode } from 'react' +import type { + BlockEnum, + VarType, +} from '@/app/components/workflow/types' + +export type VariablePayload = { + className?: string + nodeType?: BlockEnum + nodeTitle?: string + variables: string[] + variableType?: VarType + onClick?: (e: React.MouseEvent) => void + errorMsg?: string + isExceptionVariable?: boolean + ref?: React.Ref + notShowFullPath?: boolean + rightSlot?: ReactNode +} diff --git a/web/app/components/workflow/nodes/_base/components/variable/variable-label/variable-icon-with-color.tsx b/web/app/components/workflow/nodes/_base/components/variable/variable-label/variable-icon-with-color.tsx new file mode 100644 index 0000000000..56d6c3738e --- /dev/null +++ b/web/app/components/workflow/nodes/_base/components/variable/variable-label/variable-icon-with-color.tsx @@ -0,0 +1,30 @@ +import { memo } from 'react' +import VariableIcon from './base/variable-icon' +import type { VariableIconProps } from './base/variable-icon' +import { useVarColor } from './hooks' +import cn from '@/utils/classnames' + +type VariableIconWithColorProps = { + isExceptionVariable?: boolean +} & VariableIconProps + +const VariableIconWithColor = ({ + isExceptionVariable, + variableCategory, + variables = [], + className, +}: VariableIconWithColorProps) => { + const varColorClassName = useVarColor(variables, isExceptionVariable, variableCategory) + return ( + + ) +} + +export default memo(VariableIconWithColor) diff --git a/web/app/components/workflow/nodes/_base/components/variable/variable-label/variable-label-in-editor.tsx b/web/app/components/workflow/nodes/_base/components/variable/variable-label/variable-label-in-editor.tsx new file mode 100644 index 0000000000..fa5ae57f91 --- /dev/null +++ b/web/app/components/workflow/nodes/_base/components/variable/variable-label/variable-label-in-editor.tsx @@ -0,0 +1,40 @@ +import { memo } from 'react' +import type { VariablePayload } from './types' +import VariableLabel from './base/variable-label' +import { useVarBgColorInEditor } from './hooks' +import cn from '@/utils/classnames' + +type VariableLabelInEditorProps = { + isSelected?: boolean +} & VariablePayload +const VariableLabelInEditor = ({ + isSelected, + variables, + errorMsg, + ...rest +}: VariableLabelInEditorProps) => { + const { + hoverBorderColor, + hoverBgColor, + selectedBorderColor, + selectedBgColor, + } = useVarBgColorInEditor(variables, !!errorMsg) + + return ( + + ) +} + +export default memo(VariableLabelInEditor) diff --git a/web/app/components/workflow/nodes/_base/components/variable/variable-label/variable-label-in-node.tsx b/web/app/components/workflow/nodes/_base/components/variable/variable-label/variable-label-in-node.tsx new file mode 100644 index 0000000000..cebe140e26 --- /dev/null +++ b/web/app/components/workflow/nodes/_base/components/variable/variable-label/variable-label-in-node.tsx @@ -0,0 +1,17 @@ +import { memo } from 'react' +import type { VariablePayload } from './types' +import VariableLabel from './base/variable-label' +import cn from '@/utils/classnames' + +const VariableLabelInNode = (variablePayload: VariablePayload) => { + return ( + + ) +} + +export default memo(VariableLabelInNode) diff --git a/web/app/components/workflow/nodes/_base/components/variable/variable-label/variable-label-in-select.tsx b/web/app/components/workflow/nodes/_base/components/variable/variable-label/variable-label-in-select.tsx new file mode 100644 index 0000000000..34e7b5f461 --- /dev/null +++ b/web/app/components/workflow/nodes/_base/components/variable/variable-label/variable-label-in-select.tsx @@ -0,0 +1,13 @@ +import { memo } from 'react' +import type { VariablePayload } from './types' +import VariableLabel from './base/variable-label' + +const VariableLabelInSelect = (variablePayload: VariablePayload) => { + return ( + + ) +} + +export default memo(VariableLabelInSelect) diff --git a/web/app/components/workflow/nodes/_base/components/variable/variable-label/variable-label-in-text.tsx b/web/app/components/workflow/nodes/_base/components/variable/variable-label/variable-label-in-text.tsx new file mode 100644 index 0000000000..dd0d6fcf8b --- /dev/null +++ b/web/app/components/workflow/nodes/_base/components/variable/variable-label/variable-label-in-text.tsx @@ -0,0 +1,17 @@ +import { memo } from 'react' +import type { VariablePayload } from './types' +import VariableLabel from './base/variable-label' +import cn from '@/utils/classnames' + +const VariableLabelInText = (variablePayload: VariablePayload) => { + return ( + + ) +} + +export default memo(VariableLabelInText) diff --git a/web/app/components/workflow/nodes/assigner/node.tsx b/web/app/components/workflow/nodes/assigner/node.tsx index 2dd1ead4f8..5e5950d715 100644 --- a/web/app/components/workflow/nodes/assigner/node.tsx +++ b/web/app/components/workflow/nodes/assigner/node.tsx @@ -2,10 +2,13 @@ import type { FC } from 'react' import React from 'react' import { useNodes } from 'reactflow' import { useTranslation } from 'react-i18next' -import NodeVariableItem from '../variable-assigner/components/node-variable-item' import type { AssignerNodeType } from './types' -import { isConversationVar, isENV, isSystemVar } from '@/app/components/workflow/nodes/_base/components/variable/utils' +import { isSystemVar } from '@/app/components/workflow/nodes/_base/components/variable/utils' import { BlockEnum, type Node, type NodeProps } from '@/app/components/workflow/types' +import { + VariableLabelInNode, +} from '@/app/components/workflow/nodes/_base/components/variable/variable-label' +import Badge from '@/app/components/base/badge' const i18nPrefix = 'workflow.nodes.assigner' @@ -38,19 +41,16 @@ const NodeComponent: FC> = ({ if (!variable || variable.length === 0) return null const isSystem = isSystemVar(variable) - const isEnv = isENV(variable) - const isChatVar = isConversationVar(variable) const node = isSystem ? nodes.find(node => node.data.type === BlockEnum.Start) : nodes.find(node => node.id === variable[0]) - const varName = isSystem ? `sys.${variable[variable.length - 1]}` : variable.slice(1).join('.') return ( - + } /> ) })} @@ -63,21 +63,17 @@ const NodeComponent: FC> = ({ if (!variable || variable.length === 0) return null const isSystem = isSystemVar(variable) - const isEnv = isENV(variable) - const isChatVar = isConversationVar(variable) - const node = isSystem ? nodes.find(node => node.data.type === BlockEnum.Start) : nodes.find(node => node.id === variable[0]) - const varName = isSystem ? `sys.${variable[variable.length - 1]}` : variable.slice(1).join('.') return (
- + } />
) diff --git a/web/app/components/workflow/nodes/document-extractor/node.tsx b/web/app/components/workflow/nodes/document-extractor/node.tsx index 6b1d4343be..ab7fe9a9a6 100644 --- a/web/app/components/workflow/nodes/document-extractor/node.tsx +++ b/web/app/components/workflow/nodes/document-extractor/node.tsx @@ -2,10 +2,12 @@ import type { FC } from 'react' import React from 'react' import { useNodes } from 'reactflow' import { useTranslation } from 'react-i18next' -import NodeVariableItem from '../variable-assigner/components/node-variable-item' import type { DocExtractorNodeType } from './types' -import { isConversationVar, isENV, isSystemVar } from '@/app/components/workflow/nodes/_base/components/variable/utils' +import { isSystemVar } from '@/app/components/workflow/nodes/_base/components/variable/utils' import { BlockEnum, type Node, type NodeProps } from '@/app/components/workflow/types' +import { + VariableLabelInNode, +} from '@/app/components/workflow/nodes/_base/components/variable/variable-label' const i18nPrefix = 'workflow.nodes.docExtractor' @@ -21,19 +23,14 @@ const NodeComponent: FC> = ({ return null const isSystem = isSystemVar(variable) - const isEnv = isENV(variable) - const isChatVar = isConversationVar(variable) const node = isSystem ? nodes.find(node => node.data.type === BlockEnum.Start) : nodes.find(node => node.id === variable[0]) - const varName = isSystem ? `sys.${variable[variable.length - 1]}` : variable.slice(1).join('.') return (
{t(`${i18nPrefix}.inputVar`)}
-
) diff --git a/web/app/components/workflow/nodes/end/node.tsx b/web/app/components/workflow/nodes/end/node.tsx index 6906e0f77c..2583e61b68 100644 --- a/web/app/components/workflow/nodes/end/node.tsx +++ b/web/app/components/workflow/nodes/end/node.tsx @@ -1,19 +1,16 @@ import type { FC } from 'react' import React from 'react' -import cn from 'classnames' import type { EndNodeType } from './types' import type { NodeProps, Variable } from '@/app/components/workflow/types' -import { isConversationVar, isENV, isSystemVar } from '@/app/components/workflow/nodes/_base/components/variable/utils' import { useIsChatMode, useWorkflow, useWorkflowVariables, } from '@/app/components/workflow/hooks' -import { VarBlockIcon } from '@/app/components/workflow/block-icon' -import { Line3 } from '@/app/components/base/icons/src/public/common' -import { Variable02 } from '@/app/components/base/icons/src/vender/solid/development' -import { BubbleX, Env } from '@/app/components/base/icons/src/vender/line/others' import { BlockEnum } from '@/app/components/workflow/types' +import { + VariableLabelInNode, +} from '@/app/components/workflow/nodes/_base/components/variable/variable-label' const Node: FC> = ({ id, @@ -42,42 +39,20 @@ const Node: FC> = ({
{filteredOutputs.map(({ value_selector }, index) => { const node = getNode(value_selector[0]) - const isSystem = isSystemVar(value_selector) - const isEnv = isENV(value_selector) - const isChatVar = isConversationVar(value_selector) - const varName = isSystem ? `sys.${value_selector[value_selector.length - 1]}` : value_selector[value_selector.length - 1] const varType = getCurrentVariableType({ valueSelector: value_selector, availableNodes, isChatMode, }) - return ( -
-
- {!isEnv && !isChatVar && ( - <> -
- -
-
{node?.data.title}
- - - )} -
- {!isEnv && !isChatVar && } - {isEnv && } - {isChatVar && } -
{varName}
-
-
-
-
{varType}
-
-
+ return ( + ) })} diff --git a/web/app/components/workflow/nodes/http/node.tsx b/web/app/components/workflow/nodes/http/node.tsx index aa1912bd59..6002bf737d 100644 --- a/web/app/components/workflow/nodes/http/node.tsx +++ b/web/app/components/workflow/nodes/http/node.tsx @@ -15,7 +15,7 @@ const Node: FC> = ({
{method}
-
+
{ const notHasValue = comparisonOperatorNotRequireValue(c.comparison_operator) if (notHasValue) @@ -76,19 +72,11 @@ const ConditionValue = ({ return (
- {!isEnvVar && !isChatVar && } - {isEnvVar && } - {isChatVar && } - -
- {variableName} -
+
| undefined = nodes.find(n => n.id === variableSelector[0]) as Node const isException = isExceptionVariable(variableName, node?.data.type) const formatValue = useMemo(() => { @@ -76,20 +74,14 @@ const ConditionValue = ({ return (
- {!isEnvVar && !isChatVar && } - {isEnvVar && } - {isChatVar && } - -
- {variableName} -
+
> = ({ return null const isSystem = isSystemVar(variable) - const isEnv = isENV(variable) - const isChatVar = isConversationVar(variable) const node = isSystem ? nodes.find(node => node.data.type === BlockEnum.Start) : nodes.find(node => node.id === variable[0]) - const varName = isSystem ? `sys.${variable[variable.length - 1]}` : variable.slice(1).join('.') return (
{t(`${i18nPrefix}.inputVar`)}
-
) diff --git a/web/app/components/workflow/nodes/loop/components/condition-files-list-value.tsx b/web/app/components/workflow/nodes/loop/components/condition-files-list-value.tsx index 772b960953..00eec93de3 100644 --- a/web/app/components/workflow/nodes/loop/components/condition-files-list-value.tsx +++ b/web/app/components/workflow/nodes/loop/components/condition-files-list-value.tsx @@ -11,10 +11,10 @@ import { } from '../utils' import type { ValueSelector } from '../../../types' import { FILE_TYPE_OPTIONS, TRANSFER_METHOD } from './../default' -import { Variable02 } from '@/app/components/base/icons/src/vender/solid/development' -import { BubbleX, Env } from '@/app/components/base/icons/src/vender/line/others' -import cn from '@/utils/classnames' -import { isConversationVar, isENV, isSystemVar } from '@/app/components/workflow/nodes/_base/components/variable/utils' +import { isSystemVar } from '@/app/components/workflow/nodes/_base/components/variable/utils' +import { + VariableLabelInNode, +} from '@/app/components/workflow/nodes/_base/components/variable/variable-label' const i18nPrefix = 'workflow.nodes.ifElse' type ConditionValueProps = { @@ -32,11 +32,7 @@ const ConditionValue = ({ const variableSelector = variable_selector as ValueSelector - const variableName = (isSystemVar(variableSelector) ? variableSelector.slice(0).join('.') : variableSelector.slice(1).join('.')) const operatorName = isComparisonOperatorNeedTranslate(operator) ? t(`workflow.nodes.ifElse.comparisonOperator.${operator}`) : operator - const notHasValue = comparisonOperatorNotRequireValue(operator) - const isEnvVar = isENV(variableSelector) - const isChatVar = isConversationVar(variableSelector) const formatValue = useCallback((c: Condition) => { const notHasValue = comparisonOperatorNotRequireValue(c.comparison_operator) if (notHasValue) @@ -76,19 +72,11 @@ const ConditionValue = ({ return (
- {!isEnvVar && !isChatVar && } - {isEnvVar && } - {isChatVar && } - -
- {variableName} -
+
{ const { t } = useTranslation() - const variableName = labelName || (isSystemVar(variableSelector) ? variableSelector.slice(0).join('.') : variableSelector.slice(1).join('.')) const operatorName = isComparisonOperatorNeedTranslate(operator) ? t(`workflow.nodes.ifElse.comparisonOperator.${operator}`) : operator const notHasValue = comparisonOperatorNotRequireValue(operator) - const isEnvVar = isENV(variableSelector) - const isChatVar = isConversationVar(variableSelector) const formatValue = useMemo(() => { if (notHasValue) return '' @@ -67,19 +64,11 @@ const ConditionValue = ({ return (
- {!isEnvVar && !isChatVar && } - {isEnvVar && } - {isChatVar && } - -
- {variableName} -
+
{ - const isSystem = isSystemVar(variable) - const isEnv = isENV(variable) - const isChatVar = isConversationVar(variable) + !!item.variables.length && ( +
+ { + item.variables.map((variable = [], index) => { + const isSystem = isSystemVar(variable) - const node = isSystem ? nodes.find(node => node.data.type === BlockEnum.Start) : nodes.find(node => node.id === variable[0]) - const varName = isSystem ? `sys.${variable[variable.length - 1]}` : variable.slice(1).join('.') - const isException = isExceptionVariable(varName, node?.data.type) + const node = isSystem ? nodes.find(node => node.data.type === BlockEnum.Start) : nodes.find(node => node.id === variable[0]) + const varName = isSystem ? `sys.${variable[variable.length - 1]}` : variable.slice(1).join('.') + const isException = isExceptionVariable(varName, node?.data.type) - return ( - - ) - }) + return ( + + ) + }) + } +
+ ) }
) diff --git a/web/app/components/workflow/nodes/variable-assigner/components/node-variable-item.tsx b/web/app/components/workflow/nodes/variable-assigner/components/node-variable-item.tsx deleted file mode 100644 index f5d05aae26..0000000000 --- a/web/app/components/workflow/nodes/variable-assigner/components/node-variable-item.tsx +++ /dev/null @@ -1,111 +0,0 @@ -import { - memo, - useMemo, -} from 'react' -import { useTranslation } from 'react-i18next' -import cn from '@/utils/classnames' -import { VarBlockIcon } from '@/app/components/workflow/block-icon' -import { Line3 } from '@/app/components/base/icons/src/public/common' -import { Variable02 } from '@/app/components/base/icons/src/vender/solid/development' -import { BubbleX, Env } from '@/app/components/base/icons/src/vender/line/others' -import Badge from '@/app/components/base/badge' -import type { Node } from '@/app/components/workflow/types' - -type NodeVariableItemProps = { - isEnv: boolean - isChatVar: boolean - node: Node - varName: string - writeMode?: string - showBorder?: boolean - className?: string - isException?: boolean -} - -const i18nPrefix = 'workflow.nodes.assigner' - -const NodeVariableItem = ({ - isEnv, - isChatVar, - node, - varName, - writeMode, - showBorder, - className, - isException, -}: NodeVariableItemProps) => { - const { t } = useTranslation() - - const VariableIcon = useMemo(() => { - if (isEnv) { - return ( - - ) - } - - if (isChatVar) { - return ( - - ) - } - - return ( - - ) - }, [isEnv, isChatVar, isException]) - - const VariableName = useMemo(() => { - return ( -
- {varName} -
- ) - }, [isEnv, isChatVar, varName, isException]) - return ( -
-
- { - node && ( - <> -
- -
-
- {node?.data.title} -
- - - ) - } - {VariableIcon} - {VariableName} -
- {writeMode && } -
- ) -} - -export default memo(NodeVariableItem) diff --git a/web/app/components/workflow/variable-inspect/group.tsx b/web/app/components/workflow/variable-inspect/group.tsx index 1b032c8992..29b6c3ca44 100644 --- a/web/app/components/workflow/variable-inspect/group.tsx +++ b/web/app/components/workflow/variable-inspect/group.tsx @@ -11,16 +11,12 @@ import { import ActionButton from '@/app/components/base/action-button' import Tooltip from '@/app/components/base/tooltip' import BlockIcon from '@/app/components/workflow/block-icon' -import { - BubbleX, - Env, -} from '@/app/components/base/icons/src/vender/line/others' -import { Variable02 } from '@/app/components/base/icons/src/vender/solid/development' import type { currentVarType } from './panel' import { VarInInspectType } from '@/types/workflow' import type { NodeWithVar, VarInInspect } from '@/types/workflow' import cn from '@/utils/classnames' import { useToolIcon } from '../hooks' +import { VariableIconWithColor } from '@/app/components/workflow/nodes/_base/components/variable/variable-label' type Props = { nodeData?: NodeWithVar @@ -158,9 +154,11 @@ const Group = ({ )} onClick={() => handleSelectVar(varItem, varType)} > - {isEnv && } - {isChatVar && } - {(isSystem || nodeData) && } +
{varItem.name}
{varItem.value_type}
diff --git a/web/app/components/workflow/variable-inspect/right.tsx b/web/app/components/workflow/variable-inspect/right.tsx index 6ddd0d47d3..aa318cfe79 100644 --- a/web/app/components/workflow/variable-inspect/right.tsx +++ b/web/app/components/workflow/variable-inspect/right.tsx @@ -14,12 +14,11 @@ import Badge from '@/app/components/base/badge' import CopyFeedback from '@/app/components/base/copy-feedback' import Tooltip from '@/app/components/base/tooltip' import BlockIcon from '@/app/components/workflow/block-icon' -import { BubbleX, Env } from '@/app/components/base/icons/src/vender/line/others' -import { Variable02 } from '@/app/components/base/icons/src/vender/solid/development' import Loading from '@/app/components/base/loading' import type { currentVarType } from './panel' import { VarInInspectType } from '@/types/workflow' import cn from '@/utils/classnames' +import { VariableIconWithColor } from '@/app/components/workflow/nodes/_base/components/variable/variable-label' type Props = { currentNodeVar?: currentVarType @@ -86,15 +85,14 @@ const Right = ({
{currentNodeVar && ( <> - {currentNodeVar.nodeType === VarInInspectType.environment && ( - - )} - {currentNodeVar.nodeType === VarInInspectType.conversation && ( - - )} - {currentNodeVar.nodeType === VarInInspectType.system && ( - - )} + { + [VarInInspectType.environment, VarInInspectType.conversation, VarInInspectType.system].includes(currentNodeVar.nodeType as VarInInspectType) && ( + + ) + } {currentNodeVar.nodeType !== VarInInspectType.environment && currentNodeVar.nodeType !== VarInInspectType.conversation && currentNodeVar.nodeType !== VarInInspectType.system && ( <>