Skip to content

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

1.2 KB
Raw Blame
import { IDataset } from '@/interfaces/database/dataset';
import React, { createContext, ReactNode, useContext } from 'react';

interface KnowledgeBaseContextType {
  knowledgeBase: IDataset | null;
  loading: boolean;
}

const KnowledgeBaseContext = createContext<
  KnowledgeBaseContextType | undefined
>(undefined);

export const KnowledgeBaseProvider: React.FC<{
  children: ReactNode;
  knowledgeBase: IDataset | null;
  loading: boolean;
}> = ({ children, knowledgeBase, loading }) => {
  return (
    <KnowledgeBaseContext.Provider value={{ knowledgeBase, loading }}>
      {children}
    </KnowledgeBaseContext.Provider>
  );
};

// oxlint-disable-next-line react-refresh/only-export-components
export const useKnowledgeBaseContext = (): KnowledgeBaseContextType => {
  const context = useContext(KnowledgeBaseContext);
  if (context === undefined) {
    throw new Error(
      'useKnowledgeBaseContext must be used within a KnowledgeBaseProvider',
    );
  }
  return context;
};

// oxlint-disable-next-line react-refresh/only-export-components
export const useOwnerTenantId = (): string | undefined => {
  return useKnowledgeBaseContext().knowledgeBase?.tenant_id;
};