Types

TypeScript types exported and used by react-ai-chat.


Overview

react-ai-chat provides TypeScript types for embedding providers, RAG indexes, chatbot configuration, and theme customization.

You can import the types directly from the package:

import type {
  ChatbotProps,
  ChatbotTheme,
  ChatbotThemeTokens,
  EmbeddingIndex,
  EmbeddingProvider,
} from "react-ai-chat";

EmbeddingProvider

Defines the interface required by an embedding provider.

interface EmbeddingProvider {
  name: string;
  model: string;
  maxBatchSize: number;

  embed(text: string, type?: "document" | "query"): Promise<number[]>;

  embedMany?(texts: string[], type?: "document" | "query"): Promise<number[][]>;
}

Properties

PropertyTypeDescription
namestringProvider name
modelstringEmbedding model
maxBatchSizenumberMaximum number of texts supported per batch
embedfunctionGenerates an embedding vector for one text
embedManyfunctionOptionally generates embeddings for many texts

The optional type argument identifies whether the text is being embedded as a document or query.

await provider.embed(text, "document");
await provider.embed(question, "query");

Document

Represents a source document before it is split into chunks.

interface Document {
  id: string;
  text: string;
}

Chunk

Represents a document chunk before an embedding is generated.

interface Chunk {
  id: string;
  source: string;
  chunk: number;
  text: string;
}
PropertyTypeDescription
idstringUnique chunk identifier
sourcestringSource document
chunknumberChunk number
textstringChunk content

EmbeddedChunk

Represents a chunk together with its embedding vector.

interface EmbeddedChunk {
  id: string;
  source: string;
  chunk: number;
  text: string;
  embedding: number[];
  embeddingModel?: string;
}

The embeddingModel property is optional.

EmbeddingIndex

Represents the generated RAG index.

interface EmbeddingIndex {
  provider: string;
  model: string;
  fallbackModel?: string;
  dimensions: number;
  chunks: EmbeddedChunk[];
}

Properties

PropertyTypeDescription
providerstringProvider used to generate the index
modelstringPrimary embedding model
fallbackModelstringFallback model, when configured
dimensionsnumberVector dimensions
chunksEmbeddedChunk[]Embedded document chunks

This is the structure stored in the generated embeddings.json.

CreateIndexOptions

Options used when creating an embedding index.

interface CreateIndexOptions {
  provider: EmbeddingProvider;
  fallbackProvider?: EmbeddingProvider;
  documentsPath?: string;
  outputPath?: string;
  embeddingBatchSize?: number;
}

Properties

PropertyTypeDescription
providerEmbeddingProviderPrimary embedding provider
fallbackProviderEmbeddingProviderOptional fallback provider
documentsPathstringSource documents directory
outputPathstringGenerated index output path
embeddingBatchSizenumberOptional batch size used during index generation

RetrieveContextOptions

Options used when retrieving relevant document chunks.

interface RetrieveContextOptions {
  question: string;
  embeddings: EmbeddedChunk[];
  embedFn: (text: string) => Promise<number[]>;
  topK?: number;
}

Properties

PropertyTypeDescription
questionstringUser's retrieval query
embeddingsEmbeddedChunk[]Indexed document chunks
embedFnfunctionGenerates the query embedding
topKnumberMaximum number of chunks to retrieve

ChatRouteOptions

Options accepted by createChatRoute().

interface ChatRouteOptions {
  model: LanguageModel;
  systemPrompt?: string;
  maxMessages?: number;
  rag?: {
    index: EmbeddingIndex;
    provider: EmbeddingProvider;
    topK?: number;
  };
}

model

The AI SDK language model used to generate the response.

systemPrompt

Optional system instructions.

maxMessages

Optional limit for the number of messages processed by the route.

rag

Optional RAG configuration.

rag?: {
  index: EmbeddingIndex;
  provider: EmbeddingProvider;
  topK?: number;
}

See RAG.

GoogleEmbeddingOptions

interface GoogleEmbeddingOptions {
  model?: string;
  dimensions?: number;
}

OpenAIEmbeddingOptions

interface OpenAIEmbeddingOptions {
  model?: string;
  dimensions?: number;
}

VoyageEmbeddingOptions

interface VoyageEmbeddingOptions {
  model?: string;
  dimensions?: number;
}

CohereEmbeddingOptions

interface CohereEmbeddingOptions {
  model?: string;
  dimensions?: number;
}

JinaEmbeddingOptions

interface JinaEmbeddingOptions {
  model?: string;
  dimensions?: number;
}

HuggingFaceEmbeddingOptions

interface HuggingFaceEmbeddingOptions {
  model?: string;
  dimensions?: number;
}

All embedding provider options use the same shape. model selects the embedding model and dimensions can be used when the provider supports configurable dimensions.

ChatbotThemeTokens

Defines the individual theme values used by the chatbot.

interface ChatbotThemeTokens {
  primaryColor?: string;
  primaryForeground?: string;
  background?: string;
  foreground?: string;
  mutedBackground?: string;
  mutedForeground?: string;
  borderColor?: string;
}

Theme tokens

TokenDescription
primaryColorPrimary accent color for buttons, header, and user bubbles
primaryForegroundText color on primary elements
backgroundMain chat window background
foregroundMain text color
mutedBackgroundBackground for bot messages, input, and chips
mutedForegroundSecondary text color
borderColorBorder color for inputs and prompt chips

Example:

const theme = {
  primaryColor: "#7c3aed",
  primaryForeground: "#ffffff",
  background: "#ffffff",
  foreground: "#18181b",
  mutedBackground: "#f4f4f5",
  mutedForeground: "#71717a",
  borderColor: "#e4e4e7",
};

ChatbotTheme

Supports flat theme tokens and separate light and dark overrides.

type ChatbotTheme = ChatbotThemeTokens & {
  light?: ChatbotThemeTokens;
  dark?: ChatbotThemeTokens;
};

Example:

const theme = {
  primaryColor: "#7c3aed",

  light: {
    background: "#ffffff",
    foreground: "#18181b",
  },

  dark: {
    background: "#18181b",
    foreground: "#fafafa",
  },
};

ChatbotProps

Defines the props accepted by the ready-made <Chatbot /> component.

interface ChatbotProps {
  title?: string;
  subtitle?: string;
  triggerText?: string;
  triggerIcon?: ReactNode;
  sendIcon?: ReactNode;
  closeIcon?: ReactNode;
  position?: "bottom-right" | "bottom-left" | "top-right" | "top-left";
  starterPrompts?: string[];
  emptyStateText?: string;
  placeholder?: string;
  starterPromptsLabel?: string;
  apiEndpoint?: string;
  initialOpen?: boolean;
  themeMode?: "auto" | "light" | "dark";
  classNames?: {
    wrapper?: string;
    trigger?: string;
    window?: string;
    header?: string;
  };
  theme?: ChatbotTheme;
  onError?: (error: Error) => void;
}

classNames

The ready-made chatbot accepts four custom class names:

classNames?: {
  wrapper?: string;
  trigger?: string;
  window?: string;
  header?: string;
}

Example:

<Chatbot
  classNames={{
    wrapper: "my-chatbot",
    trigger: "my-trigger",
    window: "my-window",
    header: "my-header",
  }}
/>

themeMode

The supported values are:

themeMode?: "auto" | "light" | "dark";

Use auto to follow the system preference.

<Chatbot themeMode="auto" />

onError

Receives an Error when the chatbot encounters an error.

<Chatbot
  onError={(error) => {
    console.error(error);
  }}
/>

On this page