@lobehub/chat 0.161.6 → 0.161.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,48 @@
2
2
 
3
3
  # Changelog
4
4
 
5
+ ### [Version 0.161.8](https://github.com/lobehub/lobe-chat/compare/v0.161.7...v0.161.8)
6
+
7
+ <sup>Released on **2024-05-22**</sup>
8
+
9
+ <br/>
10
+
11
+ <details>
12
+ <summary><kbd>Improvements and Fixes</kbd></summary>
13
+
14
+ </details>
15
+
16
+ <div align="right">
17
+
18
+ [![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)
19
+
20
+ </div>
21
+
22
+ ### [Version 0.161.7](https://github.com/lobehub/lobe-chat/compare/v0.161.6...v0.161.7)
23
+
24
+ <sup>Released on **2024-05-22**</sup>
25
+
26
+ #### ♻ Code Refactoring
27
+
28
+ - **misc**: Refactor to serverDB ENV.
29
+
30
+ <br/>
31
+
32
+ <details>
33
+ <summary><kbd>Improvements and Fixes</kbd></summary>
34
+
35
+ #### Code refactoring
36
+
37
+ - **misc**: Refactor to serverDB ENV, closes [#2612](https://github.com/lobehub/lobe-chat/issues/2612) ([fa1409e](https://github.com/lobehub/lobe-chat/commit/fa1409e))
38
+
39
+ </details>
40
+
41
+ <div align="right">
42
+
43
+ [![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)
44
+
45
+ </div>
46
+
5
47
  ### [Version 0.161.6](https://github.com/lobehub/lobe-chat/compare/v0.161.5...v0.161.6)
6
48
 
7
49
  <sup>Released on **2024-05-22**</sup>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/chat",
3
- "version": "0.161.6",
3
+ "version": "0.161.8",
4
4
  "description": "Lobe Chat - an open-source, high-performance chatbot framework that supports speech synthesis, multimodal, and extensible Function Call plugin system. Supports one-click free deployment of your private ChatGPT/LLM web application.",
5
5
  "keywords": [
6
6
  "framework",
@@ -1,9 +1,13 @@
1
+ import { Suspense, lazy } from 'react';
2
+
1
3
  import ServerLayout from '@/components/server/ServerLayout';
2
4
 
3
5
  import Desktop from './_layout/Desktop';
4
6
  import Mobile from './_layout/Mobile';
5
7
  import SessionHydration from './features/SessionHydration';
6
- import SessionListContent from './features/SessionListContent';
8
+ import SkeletonList from './features/SkeletonList';
9
+
10
+ const SessionListContent = lazy(() => import('./features/SessionListContent'));
7
11
 
8
12
  const Layout = ServerLayout({ Desktop, Mobile });
9
13
 
@@ -11,7 +15,9 @@ const Session = () => {
11
15
  return (
12
16
  <>
13
17
  <Layout>
14
- <SessionListContent />
18
+ <Suspense fallback={<SkeletonList />}>
19
+ <SessionListContent />
20
+ </Suspense>
15
21
  </Layout>
16
22
  <SessionHydration />
17
23
  </>
@@ -12,7 +12,7 @@ import { useSessionStore } from '@/store/session';
12
12
  import { sessionSelectors } from '@/store/session/selectors';
13
13
  import { LobeAgentSession } from '@/types/session';
14
14
 
15
- import SkeletonList from '../SkeletonList';
15
+ import SkeletonList from '../../SkeletonList';
16
16
  import AddButton from './AddButton';
17
17
  import SessionItem from './Item';
18
18
 
@@ -2,8 +2,8 @@ import { memo } from 'react';
2
2
 
3
3
  import { useSessionStore } from '@/store/session';
4
4
 
5
+ import SkeletonList from '../SkeletonList';
5
6
  import SessionList from './List';
6
- import SkeletonList from './SkeletonList';
7
7
 
8
8
  const SearchMode = memo(() => {
9
9
  const [sessionSearchKeywords, useSearchSessions] = useSessionStore((s) => [
@@ -1,3 +1,5 @@
1
+ 'use client';
2
+
1
3
  import { Skeleton } from 'antd';
2
4
  import { createStyles } from 'antd-style';
3
5
  import { memo } from 'react';
@@ -1,6 +1,6 @@
1
1
  import { describe, expect, it, vi } from 'vitest';
2
2
 
3
- import { getClientConfig } from '../client';
3
+ import { getDebugConfig } from '../debug';
4
4
 
5
5
  // 测试前重置 process.env
6
6
  vi.stubGlobal('process', {
@@ -17,7 +17,7 @@ describe('getClientConfig', () => {
17
17
  process.env.NEXT_PUBLIC_I18N_DEBUG_BROWSER = '1';
18
18
  process.env.NEXT_PUBLIC_I18N_DEBUG_SERVER = '1';
19
19
 
20
- const config = getClientConfig();
20
+ const config = getDebugConfig();
21
21
  expect(config.I18N_DEBUG).toBe(true);
22
22
  expect(config.I18N_DEBUG_BROWSER).toBe(true);
23
23
  expect(config.I18N_DEBUG_SERVER).toBe(true);
@@ -31,7 +31,7 @@ describe('getClientConfig', () => {
31
31
  process.env.NEXT_PUBLIC_I18N_DEBUG_BROWSER = '0';
32
32
  process.env.NEXT_PUBLIC_I18N_DEBUG_SERVER = '0';
33
33
 
34
- const config = getClientConfig();
34
+ const config = getDebugConfig();
35
35
 
36
36
  expect(config.I18N_DEBUG).toBe(false);
37
37
  expect(config.I18N_DEBUG_BROWSER).toBe(false);
@@ -0,0 +1,16 @@
1
+ /* eslint-disable sort-keys-fix/sort-keys-fix , typescript-sort-keys/interface */
2
+ import { createEnv } from '@t3-oss/env-nextjs';
3
+ import { z } from 'zod';
4
+
5
+ export const getServerDBConfig = () => {
6
+ return createEnv({
7
+ client: {
8
+ NEXT_PUBLIC_ENABLED_SERVER_SERVICE: z.boolean(),
9
+ },
10
+ runtimeEnv: {
11
+ NEXT_PUBLIC_ENABLED_SERVER_SERVICE: process.env.NEXT_PUBLIC_SERVICE_MODE === 'server',
12
+ },
13
+ });
14
+ };
15
+
16
+ export const serverDBEnv = getServerDBConfig();
@@ -1,32 +1,22 @@
1
- /**
2
- * the client config is only used in Vercel deployment
3
- */
4
-
5
- /* eslint-disable sort-keys-fix/sort-keys-fix , typescript-sort-keys/interface */
6
-
7
1
  declare global {
8
2
  // eslint-disable-next-line @typescript-eslint/no-namespace
9
3
  namespace NodeJS {
10
4
  interface ProcessEnv {
5
+ NEXT_PUBLIC_DEVELOPER_DEBUG: string;
11
6
  NEXT_PUBLIC_I18N_DEBUG: string;
12
7
  NEXT_PUBLIC_I18N_DEBUG_BROWSER: string;
13
- NEXT_PUBLIC_I18N_DEBUG_SERVER: string;
14
-
15
- NEXT_PUBLIC_DEVELOPER_DEBUG: string;
16
8
 
17
- NEXT_PUBLIC_SERVICE_MODE?: 'server' | 'browser';
9
+ NEXT_PUBLIC_I18N_DEBUG_SERVER: string;
18
10
  }
19
11
  }
20
12
  }
21
13
 
22
- export const getClientConfig = () => ({
23
- ENABLED_SERVER_SERVICE: process.env.NEXT_PUBLIC_SERVICE_MODE === 'server',
14
+ export const getDebugConfig = () => ({
15
+ // developer debug mode
16
+ DEBUG_MODE: process.env.NEXT_PUBLIC_DEVELOPER_DEBUG === '1',
24
17
 
25
18
  // i18n debug mode
26
19
  I18N_DEBUG: process.env.NEXT_PUBLIC_I18N_DEBUG === '1',
27
20
  I18N_DEBUG_BROWSER: process.env.NEXT_PUBLIC_I18N_DEBUG_BROWSER === '1',
28
21
  I18N_DEBUG_SERVER: process.env.NEXT_PUBLIC_I18N_DEBUG_SERVER === '1',
29
-
30
- // developer debug mode
31
- DEBUG_MODE: process.env.NEXT_PUBLIC_DEVELOPER_DEBUG === '1',
32
22
  });
@@ -1,6 +1,6 @@
1
1
  import pkg from '@/../package.json';
2
- import { getClientConfig } from '@/config/client';
2
+ import { getServerDBConfig } from '@/config/db';
3
3
 
4
4
  export const CURRENT_VERSION = pkg.version;
5
5
 
6
- export const isServerMode = getClientConfig().ENABLED_SERVER_SERVICE;
6
+ export const isServerMode = getServerDBConfig().NEXT_PUBLIC_ENABLED_SERVER_SERVICE;
@@ -2,7 +2,7 @@ import dynamic from 'next/dynamic';
2
2
  import { cookies } from 'next/headers';
3
3
  import { FC, ReactNode } from 'react';
4
4
 
5
- import { getClientConfig } from '@/config/client';
5
+ import { getDebugConfig } from '@/config/debug';
6
6
  import { getServerFeatureFlagsValue } from '@/config/featureFlags';
7
7
  import { LOBE_LOCALE_COOKIE } from '@/const/locale';
8
8
  import {
@@ -26,7 +26,7 @@ let DebugUI: FC = () => null;
26
26
  // refs: https://webpack.js.org/plugins/internal-plugins/#constplugin
27
27
  if (process.env.NODE_ENV === 'development') {
28
28
  // eslint-disable-next-line unicorn/no-lonely-if
29
- if (getClientConfig().DEBUG_MODE) {
29
+ if (getDebugConfig().DEBUG_MODE) {
30
30
  DebugUI = dynamic(() => import('@/features/DebugUI'), { ssr: false }) as FC;
31
31
  }
32
32
  }
@@ -4,13 +4,13 @@ import resourcesToBackend from 'i18next-resources-to-backend';
4
4
  import { initReactI18next } from 'react-i18next';
5
5
  import { isRtlLang } from 'rtl-detect';
6
6
 
7
- import { getClientConfig } from '@/config/client';
7
+ import { getDebugConfig } from '@/config/debug';
8
8
  import { DEFAULT_LANG, LOBE_LOCALE_COOKIE } from '@/const/locale';
9
9
  import { COOKIE_CACHE_DAYS } from '@/const/settings';
10
10
  import { normalizeLocale } from '@/locales/resources';
11
11
  import { isDev, isOnServerSide } from '@/utils/env';
12
12
 
13
- const { I18N_DEBUG, I18N_DEBUG_BROWSER, I18N_DEBUG_SERVER } = getClientConfig();
13
+ const { I18N_DEBUG, I18N_DEBUG_BROWSER, I18N_DEBUG_SERVER } = getDebugConfig();
14
14
  const debugMode = I18N_DEBUG ?? isOnServerSide ? I18N_DEBUG_SERVER : I18N_DEBUG_BROWSER;
15
15
 
16
16
  export const createI18nNext = (lang?: string) => {
@@ -194,6 +194,10 @@ export const createSessionSlice: StateCreator<
194
194
 
195
195
  useFetchSessions: () =>
196
196
  useClientDataSWR<ChatSessionList>(FETCH_SESSIONS_KEY, sessionService.getGroupedSessions, {
197
+ fallbackData: {
198
+ sessionGroups: [],
199
+ sessions: [],
200
+ },
197
201
  onSuccess: (data) => {
198
202
  if (
199
203
  get().isSessionsFirstFetchFinished &&
@@ -209,6 +213,7 @@ export const createSessionSlice: StateCreator<
209
213
  );
210
214
  set({ isSessionsFirstFetchFinished: true }, false, n('useFetchSessions/onSuccess', data));
211
215
  },
216
+ suspense: true,
212
217
  }),
213
218
  useSearchSessions: (keyword) =>
214
219
  useSWR<LobeSessions>(
@@ -1,4 +1,4 @@
1
- import { CustomSessionGroup, LobeAgentSession, LobeSessionGroups } from '@/types/session';
1
+ import { LobeAgentSession } from '@/types/session';
2
2
 
3
3
  export interface SessionState {
4
4
  /**
@@ -6,13 +6,11 @@ export interface SessionState {
6
6
  * @description 当前正在编辑或查看的会话
7
7
  */
8
8
  activeId: string;
9
- customSessionGroups: CustomSessionGroup[];
10
9
  defaultSessions: LobeAgentSession[];
11
10
  isSearching: boolean;
12
11
  isSessionsFirstFetchFinished: boolean;
13
12
  pinnedSessions: LobeAgentSession[];
14
13
  searchKeywords: string;
15
- sessionGroups: LobeSessionGroups;
16
14
  sessionSearchKeywords?: string;
17
15
  /**
18
16
  * it means defaultSessions
@@ -22,12 +20,10 @@ export interface SessionState {
22
20
 
23
21
  export const initialSessionState: SessionState = {
24
22
  activeId: 'inbox',
25
- customSessionGroups: [],
26
23
  defaultSessions: [],
27
24
  isSearching: false,
28
25
  isSessionsFirstFetchFinished: false,
29
26
  pinnedSessions: [],
30
27
  searchKeywords: '',
31
- sessionGroups: [],
32
28
  sessions: [],
33
29
  };
@@ -1,5 +1,12 @@
1
+ import { CustomSessionGroup, LobeSessionGroups } from '@/types/session';
2
+
1
3
  export interface SessionGroupState {
2
4
  activeGroupId?: string;
5
+ customSessionGroups: CustomSessionGroup[];
6
+ sessionGroups: LobeSessionGroups;
3
7
  }
4
8
 
5
- export const initSessionGroupState: SessionGroupState = {};
9
+ export const initSessionGroupState: SessionGroupState = {
10
+ customSessionGroups: [],
11
+ sessionGroups: [],
12
+ };