Skip to content

Commit ae613c7

Browse files
authored
♻️ refactor: remove language_model_settings and remove isDeprecatedEdition (#10264)
1 parent 8184f9d commit ae613c7

File tree

56 files changed

+336
-837
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+336
-837
lines changed

packages/const/src/version.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,8 @@ import { BRANDING_NAME, ORG_NAME } from './branding';
44

55
export const CURRENT_VERSION = pkg.version;
66

7-
export const isServerMode = true;
8-
export const isUsePgliteDB = false;
9-
107
export const isDesktop = process.env.NEXT_PUBLIC_IS_DESKTOP_APP === '1';
118

12-
export const isDeprecatedEdition = false;
13-
149
// @ts-ignore
1510
export const isCustomBranding = BRANDING_NAME !== 'LobeHub';
1611
// @ts-ignore

packages/database/src/models/__tests__/chunk.test.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,44 @@ describe('ChunkModel', () => {
287287
expect(result[1].index).toBe(1);
288288
expect(result[2].index).toBe(2);
289289
});
290+
291+
it('should handle chunks with null metadata and return undefined pageNumber', async () => {
292+
const fileId = '1';
293+
const [chunk] = await serverDB
294+
.insert(chunks)
295+
.values([{ text: 'Chunk with null metadata', userId, index: 0, metadata: null }])
296+
.returning();
297+
298+
await serverDB.insert(fileChunks).values([{ fileId, chunkId: chunk.id, userId }]);
299+
300+
const result = await chunkModel.findByFileId(fileId, 0);
301+
302+
expect(result).toHaveLength(1);
303+
expect(result[0].metadata).toBeNull();
304+
expect(result[0].pageNumber).toBeUndefined();
305+
});
306+
307+
it('should handle chunks with metadata containing pageNumber', async () => {
308+
const fileId = '1';
309+
const [chunk] = await serverDB
310+
.insert(chunks)
311+
.values([
312+
{
313+
text: 'Chunk with pageNumber',
314+
userId,
315+
index: 0,
316+
metadata: { pageNumber: 5 } as any,
317+
},
318+
])
319+
.returning();
320+
321+
await serverDB.insert(fileChunks).values([{ fileId, chunkId: chunk.id, userId }]);
322+
323+
const result = await chunkModel.findByFileId(fileId, 0);
324+
325+
expect(result).toHaveLength(1);
326+
expect(result[0].pageNumber).toBe(5);
327+
});
290328
});
291329

292330
describe('getChunksTextByFileId', () => {

src/app/(backend)/api/webhooks/clerk/route.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import { NextResponse } from 'next/server';
22

3-
import { isServerMode } from '@/const/version';
43
import { serverDB } from '@/database/server';
54
import { authEnv } from '@/envs/auth';
65
import { pino } from '@/libs/logger';
76
import { UserService } from '@/server/services/user';
87

98
import { validateRequest } from './validateRequest';
109

11-
if (authEnv.NEXT_PUBLIC_ENABLE_CLERK_AUTH && isServerMode && !authEnv.CLERK_WEBHOOK_SECRET) {
10+
if (authEnv.NEXT_PUBLIC_ENABLE_CLERK_AUTH && !authEnv.CLERK_WEBHOOK_SECRET) {
1211
throw new Error('`CLERK_WEBHOOK_SECRET` environment variable is missing');
1312
}
1413

src/app/[variants]/(main)/(mobile)/me/(home)/__tests__/useCategory.test.tsx

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ vi.mock('react-i18next', () => ({
2323
})),
2424
}));
2525

26-
vi.mock('../../settings/features/useCategory', () => ({
27-
useCategory: vi.fn(() => [{ key: 'extraSetting', label: 'Extra Setting' }]),
28-
}));
29-
3026
// 定义一个变量来存储 enableAuth 的值
3127
let enableAuth = true;
3228
let enableClerk = true;
@@ -68,7 +64,6 @@ describe('useCategory', () => {
6864
const items = result.current;
6965
expect(items.some((item) => item.key === 'profile')).toBe(true);
7066
expect(items.some((item) => item.key === 'setting')).toBe(true);
71-
expect(items.some((item) => item.key === 'data')).toBe(true);
7267
expect(items.some((item) => item.key === 'docs')).toBe(true);
7368
expect(items.some((item) => item.key === 'feedback')).toBe(true);
7469
expect(items.some((item) => item.key === 'changelog')).toBe(true);
@@ -93,19 +88,4 @@ describe('useCategory', () => {
9388
expect(items.some((item) => item.key === 'changelog')).toBe(true);
9489
});
9590
});
96-
97-
it('should handle settings for non-authenticated users', () => {
98-
act(() => {
99-
useUserStore.setState({ isSignedIn: false });
100-
});
101-
enableClerk = false;
102-
enableAuth = false;
103-
104-
const { result } = renderHook(() => useCategory(), { wrapper });
105-
106-
act(() => {
107-
const items = result.current;
108-
expect(items.some((item) => item.key === 'extraSetting')).toBe(true);
109-
});
110-
});
11191
});

src/app/[variants]/(main)/(mobile)/me/(home)/features/useCategory.tsx

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
import { DOCUMENTS, FEEDBACK, LOBE_CHAT_CLOUD, OFFICIAL_URL, UTM_SOURCE } from '@lobechat/const';
12
import {
23
Book,
34
CircleUserRound,
45
Cloudy,
5-
Database,
66
Download,
77
Feather,
88
FileClockIcon,
@@ -12,26 +12,17 @@ import { useRouter } from 'next/navigation';
1212
import { useTranslation } from 'react-i18next';
1313

1414
import { CellProps } from '@/components/Cell';
15-
import { enableAuth } from '@/const/auth';
16-
import { LOBE_CHAT_CLOUD } from '@/const/branding';
17-
import { DOCUMENTS, FEEDBACK, OFFICIAL_URL, UTM_SOURCE } from '@/const/url';
18-
import { isServerMode } from '@/const/version';
1915
import { usePWAInstall } from '@/hooks/usePWAInstall';
2016
import { featureFlagsSelectors, useServerConfigStore } from '@/store/serverConfig';
2117
import { useUserStore } from '@/store/user';
2218
import { authSelectors } from '@/store/user/selectors';
2319

24-
import { useCategory as useSettingsCategory } from '../../settings/features/useCategory';
25-
2620
export const useCategory = () => {
2721
const router = useRouter();
2822
const { canInstall, install } = usePWAInstall();
2923
const { t } = useTranslation(['common', 'setting', 'auth']);
3024
const { showCloudPromotion, hideDocs } = useServerConfigStore(featureFlagsSelectors);
31-
const [isLogin, isLoginWithAuth] = useUserStore((s) => [
32-
authSelectors.isLogin(s),
33-
authSelectors.isLoginWithAuth(s),
34-
]);
25+
const [isLoginWithAuth] = useUserStore((s) => [authSelectors.isLoginWithAuth(s)]);
3526

3627
const profile: CellProps[] = [
3728
{
@@ -66,29 +57,10 @@ export const useCategory = () => {
6657
},
6758
];
6859

69-
const settingsWithoutAuth = [
70-
...useSettingsCategory(),
71-
{
72-
type: 'divider',
73-
},
74-
];
75-
7660
/* ↓ cloud slot ↓ */
7761

7862
/* ↑ cloud slot ↑ */
7963

80-
const data: CellProps[] = [
81-
{
82-
icon: Database,
83-
key: 'data',
84-
label: t('userPanel.data'),
85-
onClick: () => router.push('/me/data'),
86-
},
87-
{
88-
type: 'divider',
89-
},
90-
];
91-
9264
const helps: CellProps[] = [
9365
showCloudPromotion && {
9466
icon: Cloudy,
@@ -120,13 +92,12 @@ export const useCategory = () => {
12092
{
12193
type: 'divider',
12294
},
123-
...(!enableAuth || (enableAuth && isLoginWithAuth) ? profile : []),
124-
...(enableAuth ? (isLoginWithAuth ? settings : []) : settingsWithoutAuth),
95+
...(isLoginWithAuth ? profile : []),
96+
...(isLoginWithAuth ? settings : []),
12597
/* ↓ cloud slot ↓ */
12698

12799
/* ↑ cloud slot ↑ */
128100
...(canInstall ? pwa : []),
129-
...(isLogin && !isServerMode ? data : []),
130101
...(!hideDocs ? helps : []),
131102
].filter(Boolean) as CellProps[];
132103

src/app/[variants]/(main)/(mobile)/me/profile/features/Category.tsx

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import { memo } from 'react';
66
import { useTranslation } from 'react-i18next';
77

88
import Cell, { CellProps } from '@/components/Cell';
9-
import { enableAuth } from '@/const/auth';
10-
import { isDeprecatedEdition } from '@/const/version';
119
import { ProfileTabs } from '@/store/global/initialState';
1210
import { useUserStore } from '@/store/user';
1311
import { authSelectors } from '@/store/user/selectors';
@@ -27,33 +25,30 @@ const Category = memo(() => {
2725
label: t('tab.profile'),
2826
onClick: () => router.push('/profile'),
2927
},
30-
enableAuth &&
31-
isLoginWithClerk && {
32-
icon: ShieldCheck,
33-
key: ProfileTabs.Security,
34-
label: t('tab.security'),
35-
onClick: () => router.push('/profile/security'),
36-
},
37-
!isDeprecatedEdition && {
28+
isLoginWithClerk && {
29+
icon: ShieldCheck,
30+
key: ProfileTabs.Security,
31+
label: t('tab.security'),
32+
onClick: () => router.push('/profile/security'),
33+
},
34+
{
3835
icon: ChartColumnBigIcon,
3936
key: ProfileTabs.Stats,
4037
label: t('tab.stats'),
4138
onClick: () => router.push('/profile/stats'),
4239
},
43-
enableAuth &&
44-
isLogin && {
45-
type: 'divider',
46-
},
47-
enableAuth &&
48-
isLogin && {
49-
icon: LogOut,
50-
key: 'logout',
51-
label: t('signout', { ns: 'auth' }),
52-
onClick: () => {
53-
signOut();
54-
router.push('/login');
55-
},
40+
isLogin && {
41+
type: 'divider',
42+
},
43+
isLogin && {
44+
icon: LogOut,
45+
key: 'logout',
46+
label: t('signout', { ns: 'auth' }),
47+
onClick: () => {
48+
signOut();
49+
router.push('/login');
5650
},
51+
},
5752
].filter(Boolean) as CellProps[];
5853

5954
return items?.map(({ key, ...item }, index) => <Cell key={key || index} {...item} />);

src/app/[variants]/(main)/(mobile)/me/settings/features/useCategory.tsx

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,11 @@ import { useRouter } from 'next/navigation';
33
import { useTranslation } from 'react-i18next';
44

55
import { CellProps } from '@/components/Cell';
6-
import { isDeprecatedEdition } from '@/const/version';
76
import { SettingsTabs } from '@/store/global/initialState';
8-
import { featureFlagsSelectors, useServerConfigStore } from '@/store/serverConfig';
97

108
export const useCategory = () => {
119
const router = useRouter();
1210
const { t } = useTranslation('setting');
13-
const { showLLM } = useServerConfigStore(featureFlagsSelectors);
1411

1512
const items: CellProps[] = [
1613
{
@@ -23,18 +20,11 @@ export const useCategory = () => {
2320
key: SettingsTabs.SystemAgent,
2421
label: t('tab.system-agent'),
2522
},
26-
showLLM &&
27-
(isDeprecatedEdition
28-
? {
29-
icon: Brain,
30-
key: SettingsTabs.LLM,
31-
label: t('tab.llm'),
32-
}
33-
: {
34-
icon: Brain,
35-
key: SettingsTabs.Provider,
36-
label: t('tab.provider'),
37-
}),
23+
{
24+
icon: Brain,
25+
key: SettingsTabs.Provider,
26+
label: t('tab.provider'),
27+
},
3828
{ icon: Mic2, key: SettingsTabs.TTS, label: t('tab.tts') },
3929
{
4030
icon: Bot,

src/app/[variants]/(main)/discover/(detail)/provider/[...slugs]/features/Sidebar/ActionButton/ProviderConfig.tsx

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use client';
22

3+
import { isDesktop } from '@lobechat/const';
34
import { Button, Icon } from '@lobehub/ui';
45
import { Dropdown } from 'antd';
56
import { createStyles } from 'antd-style';
@@ -9,8 +10,6 @@ import { useRouter } from 'nextjs-toploader/app';
910
import { memo } from 'react';
1011
import { useTranslation } from 'react-i18next';
1112

12-
import { isDeprecatedEdition, isDesktop } from '@/const/version';
13-
1413
import { useDetailContext } from '../../DetailProvider';
1514

1615
const useStyles = createStyles(({ css }) => ({
@@ -27,10 +26,8 @@ const ProviderConfig = memo(() => {
2726
const { url, modelsUrl, identifier } = useDetailContext();
2827
const router = useRouter();
2928
const openSettings = async () => {
30-
const searchParams = isDeprecatedEdition
31-
? { active: 'llm' }
32-
: { active: 'provider', provider: identifier };
33-
const tab = isDeprecatedEdition ? 'llm' : 'provider';
29+
const searchParams = { active: 'provider', provider: identifier };
30+
const tab = 'provider';
3431

3532
if (isDesktop) {
3633
const { dispatch } = await import('@lobechat/electron-client-ipc');
@@ -41,11 +38,7 @@ const ProviderConfig = memo(() => {
4138
return;
4239
}
4340

44-
router.push(
45-
isDeprecatedEdition
46-
? '/settings?active=llm'
47-
: `/settings?active=provider&provider=${identifier}`,
48-
);
41+
router.push(`/settings?active=provider&provider=${identifier}`);
4942
};
5043

5144
const icon = <Icon icon={SquareArrowOutUpRight} size={16} />;

0 commit comments

Comments
 (0)