constants.tsx


Overview

constants.tsx is a utility constants file primarily focused on defining key mappings and enumerations used across the user settings and local language model (LLM) features of the application. It exports:

This file serves as a centralized source for icon assignments, LLM factory references, and role definitions, enabling consistent usage throughout the user interface and backend logic.


Detailed Explanation of Exports

UserSettingIconMap

export const UserSettingIconMap: Record<UserSettingRouteKey, JSX.Element>
import { UserSettingIconMap } from '@/constants/constants';

// Using the icon dynamically based on a route key
const routeKey = UserSettingRouteKey.Profile;
const IconComponent = UserSettingIconMap[routeKey];

return <div>{IconComponent} User Profile Settings</div>;

LocalLlmFactories

export const LocalLlmFactories: LLMFactory[]
import { LocalLlmFactories } from '@/constants/constants';

LocalLlmFactories.forEach(factory => {
  console.log(`Available LLM: ${factory.name}`);
});

TenantRole

export enum TenantRole {
  Owner = 'owner',
  Invite = 'invite',
  Normal = 'normal',
}
import { TenantRole } from '@/constants/constants';

function canEditSettings(role: TenantRole): boolean {
  return role === TenantRole.Owner;
}

console.log(canEditSettings(TenantRole.Invite)); // false

Re-export from @/constants/setting

export * from '@/constants/setting';

Important Implementation Details


Interaction with Other Parts of the System


Visual Diagram

Below is a flowchart representing the main exported constants and their relationships:

flowchart TD
    A[constants.tsx]

    A --> B[UserSettingIconMap]
    B -->|keys| C[UserSettingRouteKey (enum)]
    B -->|values| D[React JSX Icon Components]
    D --> E[ProfileIcon]
    D --> F[PasswordIcon]
    D --> G[ModelProviderIcon]
    D --> H[MonitorOutlined]
    D --> I[IconFont (custom MCP icon)]
    D --> J[TeamIcon]
    D --> K[LogOutIcon]
    D --> L[ApiIcon]

    A --> M[LocalLlmFactories]
    M --> N[LLMFactory.Ollama]
    M --> O[LLMFactory.Xinference]
    M --> P[LLMFactory.LocalAI]
    M --> Q[LLMFactory.LMStudio]
    M --> R[...other LLMFactories]

    A --> S[TenantRole Enum]
    S --> T[Owner = 'owner']
    S --> U[Invite = 'invite']
    S --> V[Normal = 'normal']

    A --> W[Exports from '@/constants/setting']

Summary

This structure supports a modular, scalable approach to managing application constants across user interface elements, backend logic, and multi-tenant management.