E2E CI / Check Duplicate Run (push) Failing after 3s
🔄 Branch Synchronization / sync-branches (push) Failing after 3s
Test CI / Check Duplicate Run (push) Failing after 3s
E2E CI / Test Web App (push) Has been skipped
Test CI / Test App (shard 1/3) (push) Has been skipped
Test CI / Test Packages (push) Has been skipped
Test CI / Test App (shard 3/3) (push) Has been skipped
Test CI / Test App (shard 2/3) (push) Has been skipped
Test CI / Test Database (push) Has been skipped
Test CI / Test Desktop App (push) Has been skipped
Test CI / Merge and Upload App Coverage (push) Has been skipped
235 lines
6.3 KiB
TypeScript
235 lines
6.3 KiB
TypeScript
import { isDesktop } from '@lobechat/const';
|
|
import { Avatar } from '@lobehub/ui';
|
|
import { SkillsIcon } from '@lobehub/ui/icons';
|
|
import {
|
|
// BellIcon,
|
|
Brain,
|
|
BrainCircuit,
|
|
ChartColumnBigIcon,
|
|
Coins,
|
|
CreditCard,
|
|
Database,
|
|
EllipsisIcon,
|
|
EthernetPort,
|
|
Gift,
|
|
Info,
|
|
KeyboardIcon,
|
|
KeyIcon,
|
|
KeyRound,
|
|
Map,
|
|
PaletteIcon,
|
|
Sparkles,
|
|
TerminalSquare,
|
|
} from 'lucide-react';
|
|
import { useMemo } from 'react';
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
import { useEnterpriseRoles } from '@/hooks/useEnterpriseRoles';
|
|
import { useElectronStore } from '@/store/electron';
|
|
import { electronSyncSelectors } from '@/store/electron/selectors';
|
|
import { SettingsTabs } from '@/store/global/initialState';
|
|
import {
|
|
featureFlagsSelectors,
|
|
serverConfigSelectors,
|
|
useServerConfigStore,
|
|
} from '@/store/serverConfig';
|
|
import { useUserStore } from '@/store/user';
|
|
import { userProfileSelectors } from '@/store/user/slices/auth/selectors';
|
|
import { userGeneralSettingsSelectors } from '@/store/user/slices/settings/selectors';
|
|
|
|
export enum SettingsGroupKey {
|
|
Agent = 'agent',
|
|
General = 'general',
|
|
Subscription = 'subscription',
|
|
System = 'system',
|
|
}
|
|
|
|
export interface CategoryItem {
|
|
icon: any;
|
|
key: SettingsTabs;
|
|
label: string;
|
|
}
|
|
|
|
export interface CategoryGroup {
|
|
items: CategoryItem[];
|
|
key: SettingsGroupKey;
|
|
title: string;
|
|
}
|
|
|
|
export const useCategory = () => {
|
|
const { t } = useTranslation('setting');
|
|
const { t: tAuth } = useTranslation('auth');
|
|
const { t: tSubscription } = useTranslation('subscription');
|
|
const mobile = useServerConfigStore((s) => s.isMobile);
|
|
const { hideDocs, showApiKeyManage } = useServerConfigStore(featureFlagsSelectors);
|
|
const [avatar, username] = useUserStore((s) => [
|
|
userProfileSelectors.userAvatar(s),
|
|
userProfileSelectors.nickName(s),
|
|
]);
|
|
const remoteServerUrl = useElectronStore(electronSyncSelectors.remoteServerUrl);
|
|
const isDevMode = useUserStore((s) => userGeneralSettingsSelectors.config(s).isDevMode);
|
|
const { is_admin: isEnterpriseModelAdmin } = useEnterpriseRoles();
|
|
|
|
const avatarUrl = useMemo(() => {
|
|
if (!avatar) return undefined;
|
|
if (isDesktop && avatar.startsWith('/') && remoteServerUrl) {
|
|
return remoteServerUrl + avatar;
|
|
}
|
|
return avatar;
|
|
}, [avatar, remoteServerUrl]);
|
|
const enableBusinessFeatures = useServerConfigStore(serverConfigSelectors.enableBusinessFeatures);
|
|
const categoryGroups: CategoryGroup[] = useMemo(() => {
|
|
const groups: CategoryGroup[] = [];
|
|
|
|
// General group
|
|
const generalItems: CategoryItem[] = [
|
|
{
|
|
icon: avatarUrl ? <Avatar avatar={avatarUrl} shape={'square'} size={26} /> : undefined,
|
|
key: SettingsTabs.Profile,
|
|
label: username ? username : tAuth('tab.profile'),
|
|
},
|
|
{
|
|
icon: ChartColumnBigIcon,
|
|
key: SettingsTabs.Stats,
|
|
label: tAuth('tab.stats'),
|
|
},
|
|
{
|
|
icon: PaletteIcon,
|
|
key: SettingsTabs.Appearance,
|
|
label: t('tab.appearance'),
|
|
},
|
|
!mobile && {
|
|
icon: KeyboardIcon,
|
|
key: SettingsTabs.Hotkey,
|
|
label: t('tab.hotkey'),
|
|
},
|
|
// TODO: temporarily disabled until notification UI is polished
|
|
// enableBusinessFeatures && {
|
|
// icon: BellIcon,
|
|
// key: SettingsTabs.Notification,
|
|
// label: t('tab.notification'),
|
|
// },
|
|
].filter(Boolean) as CategoryItem[];
|
|
|
|
groups.push({
|
|
items: generalItems,
|
|
key: SettingsGroupKey.General,
|
|
title: t('group.common'),
|
|
});
|
|
|
|
// Subscription group
|
|
if (enableBusinessFeatures) {
|
|
const subscriptionItems: CategoryItem[] = [
|
|
{ icon: Map, key: SettingsTabs.Plans, label: tSubscription('tab.plans') },
|
|
{ icon: ChartColumnBigIcon, key: SettingsTabs.Usage, label: t('tab.usage') },
|
|
{ icon: Coins, key: SettingsTabs.Credits, label: tSubscription('tab.credits') },
|
|
{ icon: CreditCard, key: SettingsTabs.Billing, label: tSubscription('tab.billing') },
|
|
{ icon: Gift, key: SettingsTabs.Referral, label: tSubscription('tab.referral') },
|
|
];
|
|
|
|
groups.push({
|
|
items: subscriptionItems,
|
|
key: SettingsGroupKey.Subscription,
|
|
title: t('group.subscription'),
|
|
});
|
|
}
|
|
|
|
// Agent group
|
|
const agentItems: CategoryItem[] = [
|
|
(!enableBusinessFeatures || isDevMode) &&
|
|
isEnterpriseModelAdmin && {
|
|
icon: Brain,
|
|
key: SettingsTabs.Provider,
|
|
label: t('tab.provider'),
|
|
},
|
|
isEnterpriseModelAdmin && {
|
|
icon: Sparkles,
|
|
key: SettingsTabs.ServiceModel,
|
|
label: t('tab.serviceModel'),
|
|
},
|
|
{
|
|
icon: SkillsIcon,
|
|
key: SettingsTabs.Skill,
|
|
label: t('tab.skill'),
|
|
},
|
|
{
|
|
icon: BrainCircuit,
|
|
key: SettingsTabs.Memory,
|
|
label: t('tab.memory'),
|
|
},
|
|
{
|
|
icon: KeyRound,
|
|
key: SettingsTabs.Creds,
|
|
label: t('tab.creds'),
|
|
},
|
|
showApiKeyManage && {
|
|
icon: KeyIcon,
|
|
key: SettingsTabs.APIKey,
|
|
label: tAuth('tab.apikey'),
|
|
},
|
|
].filter(Boolean) as CategoryItem[];
|
|
|
|
groups.push({
|
|
items: agentItems,
|
|
key: SettingsGroupKey.Agent,
|
|
title: t('group.aiConfig'),
|
|
});
|
|
|
|
// System group
|
|
const systemItems: CategoryItem[] = [
|
|
isDesktop && {
|
|
icon: EthernetPort,
|
|
key: SettingsTabs.Proxy,
|
|
label: t('tab.proxy'),
|
|
},
|
|
isDesktop && {
|
|
icon: TerminalSquare,
|
|
key: SettingsTabs.SystemTools,
|
|
label: t('tab.systemTools'),
|
|
},
|
|
{
|
|
icon: Database,
|
|
key: SettingsTabs.Storage,
|
|
label: t('tab.storage'),
|
|
},
|
|
isDevMode && {
|
|
icon: KeyIcon,
|
|
key: SettingsTabs.APIKey,
|
|
label: tAuth('tab.apikey'),
|
|
},
|
|
{
|
|
icon: EllipsisIcon,
|
|
key: SettingsTabs.Advanced,
|
|
label: t('tab.advanced'),
|
|
},
|
|
!hideDocs && {
|
|
icon: Info,
|
|
key: SettingsTabs.About,
|
|
label: t('tab.about'),
|
|
},
|
|
].filter(Boolean) as CategoryItem[];
|
|
|
|
groups.push({
|
|
items: systemItems,
|
|
key: SettingsGroupKey.System,
|
|
title: t('group.system'),
|
|
});
|
|
|
|
return groups;
|
|
}, [
|
|
t,
|
|
tAuth,
|
|
tSubscription,
|
|
enableBusinessFeatures,
|
|
hideDocs,
|
|
mobile,
|
|
showApiKeyManage,
|
|
isDevMode,
|
|
isEnterpriseModelAdmin,
|
|
avatarUrl,
|
|
username,
|
|
]);
|
|
|
|
return categoryGroups;
|
|
};
|