Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

3.6 KB
Raw Blame
import type { currentVarType } from './panel'
import type { VarInInspect } from '@/types/workflow'
import { Button } from '@langgenius/dify-ui/button'
import { cn } from '@langgenius/dify-ui/cn'
// import { useState } from 'react'
import { useTranslation } from 'react-i18next'
import { VarInInspectType } from '@/types/workflow'
import useCurrentVars from '../hooks/use-inspect-vars-crud'
import { useNodesInteractions } from '../hooks/use-nodes-interactions'
import { useStore } from '../store'
import Group from './group'

type Props = Readonly<{
  currentNodeVar?: currentVarType
  handleVarSelect: (state: any) => void
}>

const Left = ({ currentNodeVar, handleVarSelect }: Props) => {
  const { t } = useTranslation(['workflowDebug'])

  const environmentVariables = useStore((s) => s.environmentVariables)
  const setCurrentFocusNodeId = useStore((s) => s.setCurrentFocusNodeId)

  const {
    conversationVars,
    systemVars,
    nodesWithInspectVars,
    deleteAllInspectorVars,
    deleteNodeInspectorVars,
  } = useCurrentVars()
  const { handleNodeSelect } = useNodesInteractions()

  const showDivider =
    environmentVariables.length > 0 || conversationVars.length > 0 || systemVars.length > 0

  const handleClearAll = () => {
    deleteAllInspectorVars()
    setCurrentFocusNodeId('')
  }

  const handleClearNode = (nodeId: string) => {
    deleteNodeInspectorVars(nodeId)
    setCurrentFocusNodeId('')
  }

  return (
    <div className={cn('flex h-full flex-col')}>
      {/* header */}
      <div className="flex shrink-0 items-center justify-between gap-1 pt-2 pr-1 pl-4">
        <div className="truncate system-sm-semibold-uppercase text-text-primary">
          {t(($) => $['debug.variableInspect.title'], { ns: 'workflowDebug' })}
        </div>
        <Button variant="ghost" size="small" className="shrink-0" onClick={handleClearAll}>
          {t(($) => $['debug.variableInspect.clearAll'], { ns: 'workflowDebug' })}
        </Button>
      </div>
      {/* content */}
      <div className="grow overflow-y-auto py-1">
        {/* group ENV */}
        {environmentVariables.length > 0 && (
          <Group
            varType={VarInInspectType.environment}
            varList={environmentVariables as VarInInspect[]}
            currentVar={currentNodeVar}
            handleSelect={handleVarSelect}
          />
        )}
        {/* group CHAT VAR */}
        {conversationVars.length > 0 && (
          <Group
            varType={VarInInspectType.conversation}
            varList={conversationVars}
            currentVar={currentNodeVar}
            handleSelect={handleVarSelect}
          />
        )}
        {/* group SYSTEM VAR */}
        {systemVars.length > 0 && (
          <Group
            varType={VarInInspectType.system}
            varList={systemVars}
            currentVar={currentNodeVar}
            handleSelect={handleVarSelect}
          />
        )}
        {/* divider */}
        {showDivider && (
          <div className="px-4 py-1">
            <div className="h-px bg-divider-subtle"></div>
          </div>
        )}
        {/* group nodes */}
        {nodesWithInspectVars.length > 0 &&
          nodesWithInspectVars.map((group) => (
            <Group
              key={group.nodeId}
              varType={VarInInspectType.node}
              varList={group.vars}
              nodeData={group}
              currentVar={currentNodeVar}
              handleSelect={handleVarSelect}
              handleView={() => handleNodeSelect(group.nodeId, false, true)}
              handleClear={() => handleClearNode(group.nodeId)}
            />
          ))}
      </div>
    </div>
  )
}

export default Left