Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

5.2 KB
Raw Blame
/*
 *  Copyright 2026 The InfiniFlow Authors. All Rights Reserved.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

import { IconFontFill } from '@/components/icon-font';
import SvgIcon from '@/components/svg-icon';
import queritLogo from '@/assets/querit.png';
import search1apiLogo from '@/assets/search1api.png';
import { cn } from '@/lib/utils';
import {
  Columns3Cog,
  FileCode,
  FileText,
  HousePlus,
  Infinity as InfinityIcon,
  LogOut,
  LucideBlocks,
  LucideFile,
  LucideFilePlay,
  LucideFileStack,
  LucideHeading,
  LucideListPlus,
} from 'lucide-react';
import { Component } from 'react';
import { Operator } from '../constants/agent';

interface IProps {
  name: Operator;
  className?: string;
}

export const OperatorIconMap = {
  [Operator.Retrieval]: 'KR',
  [Operator.Begin]: 'house-plus',
  [Operator.Categorize]: 'a-QuestionClassification',
  [Operator.Message]: 'reply',
  [Operator.Iteration]: 'loop',
  [Operator.Switch]: 'condition',
  [Operator.Code]: 'code-set',
  [Operator.Agent]: 'agent-ai',
  [Operator.UserFillUp]: 'await',
  [Operator.StringTransform]: 'a-textprocessing',
  [Operator.Note]: 'notebook-pen',
  [Operator.ExeSQL]: 'executesql-0',
  [Operator.Invoke]: 'httprequest-0',
  [Operator.Email]: 'sendemail-0',
  [Operator.ListOperations]: 'a-listoperations',
  [Operator.VariableAssigner]: 'a-ariableassigner',
  [Operator.VariableAggregator]: 'aggregator',
};

export const SVGIconMap = {
  [Operator.ArXiv]: 'arxiv',
  [Operator.GitHub]: 'github',
  [Operator.Bing]: 'bing',
  [Operator.DuckDuckGo]: 'duck',
  [Operator.Google]: 'google',
  [Operator.GoogleScholar]: 'google-scholar',
  [Operator.PubMed]: 'pubmed',
  [Operator.BGPT]: 'bgpt',
  [Operator.SearXNG]: 'searxng',
  [Operator.KeenableSearch]: 'keenable',
  [Operator.YouComSearch]: 'youcom',
  [Operator.SofyaSearch]: 'sofya',
  [Operator.TavilyExtract]: 'tavily',
  [Operator.TavilySearch]: 'tavily',
  [Operator.QueritContents]: 'querit',
  [Operator.QueritSearch]: 'querit',
  [Operator.Search1APISearch]: 'search1api',
  [Operator.Search1APICrawl]: 'search1api',
  [Operator.Wikipedia]: 'wikipedia',
  [Operator.YahooFinance]: 'yahoo-finance',
  [Operator.WenCai]: 'wencai',
  [Operator.Crawler]: 'crawler',
};
export const LucideIconMap = {
  [Operator.DataOperations]: FileCode,
  [Operator.Loop]: InfinityIcon,
  [Operator.ExitLoop]: LogOut,
  [Operator.DocGenerator]: FileText,
  [Operator.Compiler]: Columns3Cog,
  [Operator.File]: LucideFile,
  [Operator.Parser]: LucideFilePlay,
  [Operator.Tokenizer]: LucideListPlus,
  [Operator.GeneralChunker]: LucideBlocks,
  [Operator.TokenChunker]: LucideBlocks,
  [Operator.TitleChunker]: LucideHeading,
  [Operator.Extractor]: LucideFileStack,
};

const Empty = () => {
  return <div className="hidden"></div>;
};

class SvgErrorBoundary extends Component<{
  children: React.ReactNode;
  fallback?: React.ReactNode;
}> {
  state = { hasError: false };

  static getDerivedStateFromError() {
    return { hasError: true };
  }

  render() {
    if (this.state.hasError) {
      return this.props.fallback || <Empty />;
    }

    return this.props.children;
  }
}

const OperatorIcon = ({ name, className }: IProps) => {
  const Icon = OperatorIconMap[name as keyof typeof OperatorIconMap];
  const svgIcon = SVGIconMap[name as keyof typeof SVGIconMap];
  const LucideIcon = LucideIconMap[name as keyof typeof LucideIconMap];

  if (name === Operator.QueritContents || name === Operator.QueritSearch) {
    return (
      <img
        src={queritLogo}
        alt=""
        className={cn('size-5 object-contain', className)}
      />
    );
  }

  if (name === Operator.Search1APISearch || name === Operator.Search1APICrawl) {
    return (
      <img
        src={search1apiLogo}
        alt=""
        className={cn('size-5 object-contain', className)}
      />
    );
  }

  if (name === Operator.Begin) {
    return (
      <div
        className={cn(
          'inline-block p-1 bg-accent-primary rounded-sm',
          className,
        )}
      >
        <HousePlus className="rounded size-3" />
      </div>
    );
  }

  if (Icon) {
    return (
      <SvgErrorBoundary fallback={<Empty />}>
        <IconFontFill
          name={Icon}
          className={cn('size-5 ', className)}
        ></IconFontFill>
      </SvgErrorBoundary>
    );
  }

  if (LucideIcon) {
    return (
      <SvgErrorBoundary fallback={<Empty />}>
        <LucideIcon className={cn('size-5', className)} />
      </SvgErrorBoundary>
    );
  }

  if (svgIcon) {
    return (
      <SvgErrorBoundary fallback={<Empty />}>
        <SvgIcon
          name={svgIcon}
          width={'100%'}
          className={cn('size-5 fill-current', className)}
        ></SvgIcon>
      </SvgErrorBoundary>
    );
  }

  return <Empty></Empty>;
};

export default OperatorIcon;