Skip to content

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

2.8 KB
Raw Blame
import { Card } from '@/components/ui/card';
import {
  ResizableHandle,
  ResizablePanel,
  ResizablePanelGroup,
} from '@/components/ui/resizable';
import { GenerateType } from '@/constants/knowledge';
import {
  useGenerateStatus,
  useTraceRunData,
} from '@/hooks/use-dataset-generate';
import {
  useFetchArtifactTopicList,
  useFetchKnowledgeBaseConfiguration,
} from '@/hooks/use-knowledge-request';
import { useState } from 'react';

import { LeftPanelTab, ViewMode } from './constants';
import CompilationEmptyState from './empty-state';
import { useCompilationArtifact } from './hooks/use-compilation-artifact';
import { useRunEndEffect } from './hooks/use-run-end-effect';
import { CompilationLoadingCard } from './loading-card';
import { WikiDetailContent } from './wiki-detail-content';
import { WikiLeftPanel } from './wiki-left-panel';

export function LlmWikiView() {
  const [leftTab, setLeftTab] = useState<LeftPanelTab>(LeftPanelTab.Contents);
  useFetchKnowledgeBaseConfiguration();
  const { topics, loading: topicListLoading } = useFetchArtifactTopicList();
  const {
    selectedArtifact,
    selectedVersion,
    selectVersion,
    handleSelectArtifact,
    clearSelectedArtifact,
  } = useCompilationArtifact();

  const { data: artifactRunData } = useTraceRunData(GenerateType.Artifact);
  const { status: artifactStatus } = useGenerateStatus(artifactRunData);

  useRunEndEffect(artifactStatus);

  const handleLeftTabChange = (value: string) => {
    setLeftTab(value as LeftPanelTab);
  };

  const isLoading = topicListLoading && topics.length === 0;
  const isEmpty = topics.length === 0 && !topicListLoading;

  if (isLoading) {
    return <CompilationLoadingCard />;
  }

  if (isEmpty) {
    return (
      <CompilationEmptyState type={ViewMode.LlmWiki} data={artifactRunData} />
    );
  }

  return (
    <Card className="flex-1 min-h-0 overflow-hidden flex border-border-button rounded-xl flex-col">
      <ResizablePanelGroup direction="horizontal" className="flex-1">
        <ResizablePanel id="wiki-left" order={1} defaultSize={50}>
          <WikiLeftPanel
            tab={leftTab}
            onTabChange={handleLeftTabChange}
            selectedArtifact={selectedArtifact}
            onSelectArtifact={handleSelectArtifact}
            onClearArtifact={clearSelectedArtifact}
          />
        </ResizablePanel>
        {selectedArtifact && (
          <>
            <ResizableHandle withHandle />
            <ResizablePanel id="wiki-detail" order={2}>
              <WikiDetailContent
                selectedArtifact={selectedArtifact}
                selectedVersion={selectedVersion}
                onSelectVersion={selectVersion}
                onSelectArtifact={handleSelectArtifact}
              />
            </ResizablePanel>
          </>
        )}
      </ResizablePanelGroup>
    </Card>
  );
}