hooks.ts


Overview

The hooks.ts file is a utility module containing a set of custom React hooks designed to facilitate interaction with knowledge base configurations and related UI states within the application. It primarily focuses on:

These hooks abstract away complex state, data fetching, and UI logic, providing reusable, composable functionality to components that consume knowledge base information.


Detailed Explanation of Exports

1. useSelectChunkMethodList()

Purpose

Returns a filtered list of parser options, excluding certain "hidden" fields that should not be displayed in the chunk method selection UI.

Implementation Details

Parameters

Returns

Usage Example

const chunkMethods = useSelectChunkMethodList();
chunkMethods.forEach(method => console.log(method.label));

2. useSelectEmbeddingModelOptions()

Purpose

Provides a list of embedding model options filtered by the embedding model type.

Implementation Details

Parameters

Returns

Usage Example

const embeddingModels = useSelectEmbeddingModelOptions();

3. useHasParsedDocument()

Purpose

Determines whether the knowledge base has any parsed document chunks.

Implementation Details

Parameters

Returns

Usage Example

const hasParsedDocs = useHasParsedDocument();
if (hasParsedDocs) {
  // Show parsed docs related UI
}

4. useFetchKnowledgeConfigurationOnMount(form: UseFormReturn)

Purpose

Fetches the knowledge base configuration data on component mount and resets the provided form's values with this data.

Implementation Details

Parameters

Returns

Usage Example

const form = useForm({ ... });
const knowledgeDetails = useFetchKnowledgeConfigurationOnMount(form);

5. useSelectKnowledgeDetailsLoading()

Purpose

Indicates whether the knowledge details are currently being fetched.

Implementation Details

Parameters

Returns

Usage Example

const isLoading = useSelectKnowledgeDetailsLoading();
if (isLoading) {
  // Show loading spinner
}

6. useRenameKnowledgeTag()

Purpose

Manages the state and UI controls needed for renaming a knowledge tag, including modal visibility and the current tag being renamed.

Implementation Details

Returns

Usage Example

const {
  initialName,
  tagRenameVisible,
  hideTagRenameModal,
  showTagRenameModal,
} = useRenameKnowledgeTag();

// To open rename modal for a tag:
showTagRenameModal("OldTagName");

Important Implementation Details


Interaction with Other Parts of the System


Mermaid Diagram - Hook Relationships Flowchart

flowchart TD
    A[useSelectParserList] --> B[useSelectChunkMethodList]
    C[useSelectLlmOptionsByModelType] --> D[useSelectEmbeddingModelOptions]
    E[useFetchKnowledgeBaseConfiguration] --> F[useHasParsedDocument]
    E --> G[useFetchKnowledgeConfigurationOnMount]
    H[useIsFetching] --> I[useSelectKnowledgeDetailsLoading]
    J[useSetModalState] --> K[useRenameKnowledgeTag]
    K --> L[tag state & modal control]

    subgraph Data Fetching
        E
        F
        G
        I
    end

    subgraph Model & Parser Options
        A
        B
        C
        D
    end

    subgraph UI State Management
        J
        K
        L
    end

Summary

The hooks.ts file encapsulates critical logic for managing knowledge base configurations and associated UI state in a modular and reusable manner. It bridges data fetching, form initialization, UI control (modals), and option filtering, enabling smoother component implementation and maintenance.

This file is a core utility layer in the knowledge base management feature of the application, tightly integrated with React Query for data, React Hook Form for form management, and custom hooks for UI state.