@lobehub/chat 0.161.4 → 0.161.5

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,31 @@
2
2
 
3
3
  # Changelog
4
4
 
5
+ ### [Version 0.161.5](https://github.com/lobehub/lobe-chat/compare/v0.161.4...v0.161.5)
6
+
7
+ <sup>Released on **2024-05-22**</sup>
8
+
9
+ #### ♻ Code Refactoring
10
+
11
+ - **misc**: Move feature flags ENV.
12
+
13
+ <br/>
14
+
15
+ <details>
16
+ <summary><kbd>Improvements and Fixes</kbd></summary>
17
+
18
+ #### Code refactoring
19
+
20
+ - **misc**: Move feature flags ENV, closes [#2605](https://github.com/lobehub/lobe-chat/issues/2605) ([054a404](https://github.com/lobehub/lobe-chat/commit/054a404))
21
+
22
+ </details>
23
+
24
+ <div align="right">
25
+
26
+ [![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)
27
+
28
+ </div>
29
+
5
30
  ### [Version 0.161.4](https://github.com/lobehub/lobe-chat/compare/v0.161.3...v0.161.4)
6
31
 
7
32
  <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.4",
3
+ "version": "0.161.5",
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",
@@ -2,7 +2,7 @@ import { notFound } from 'next/navigation';
2
2
  import { PropsWithChildren } from 'react';
3
3
 
4
4
  import ServerLayout from '@/components/server/ServerLayout';
5
- import { serverFeatureFlags } from '@/config/server/featureFlags';
5
+ import { serverFeatureFlags } from '@/config/featureFlags';
6
6
 
7
7
  import Desktop from './_layout/Desktop';
8
8
  import Mobile from './_layout/Mobile';
@@ -1,6 +1,6 @@
1
1
  import { notFound } from 'next/navigation';
2
2
 
3
- import { serverFeatureFlags } from '@/config/server/featureFlags';
3
+ import { serverFeatureFlags } from '@/config/featureFlags';
4
4
  import { metadataModule } from '@/server/metadata';
5
5
  import { translation } from '@/server/translation';
6
6
 
@@ -1,6 +1,6 @@
1
1
  import { notFound } from 'next/navigation';
2
2
 
3
- import { serverFeatureFlags } from '@/config/server/featureFlags';
3
+ import { serverFeatureFlags } from '@/config/featureFlags';
4
4
  import { metadataModule } from '@/server/metadata';
5
5
  import { translation } from '@/server/translation';
6
6
  import { gerServerDeviceInfo, isMobileDevice } from '@/utils/responsive';
@@ -1,57 +1,31 @@
1
- /* eslint-disable sort-keys-fix/sort-keys-fix */
1
+ import { createEnv } from '@t3-oss/env-nextjs';
2
2
  import { z } from 'zod';
3
3
 
4
- export const FeatureFlagsSchema = z.object({
5
- webrtc_sync: z.boolean().optional(),
4
+ import { merge } from '@/utils/merge';
6
5
 
7
- language_model_settings: z.boolean().optional(),
6
+ import { DEFAULT_FEATURE_FLAGS, mapFeatureFlagsEnvToState } from './schema';
7
+ import { parseFeatureFlag } from './utils/parser';
8
8
 
9
- openai_api_key: z.boolean().optional(),
10
- openai_proxy_url: z.boolean().optional(),
9
+ const env = createEnv({
10
+ runtimeEnv: {
11
+ FEATURE_FLAGS: process.env.FEATURE_FLAGS,
12
+ },
11
13
 
12
- create_session: z.boolean().optional(),
13
- edit_agent: z.boolean().optional(),
14
-
15
- dalle: z.boolean().optional(),
16
-
17
- check_updates: z.boolean().optional(),
18
- welcome_suggest: z.boolean().optional(),
14
+ server: {
15
+ FEATURE_FLAGS: z.string().optional(),
16
+ },
19
17
  });
20
18
 
21
- // TypeScript 类型,从 Zod schema 生成
22
- export type IFeatureFlags = z.infer<typeof FeatureFlagsSchema>;
23
-
24
- export const DEFAULT_FEATURE_FLAGS: IFeatureFlags = {
25
- webrtc_sync: true,
26
-
27
- language_model_settings: true,
28
-
29
- openai_api_key: true,
30
- openai_proxy_url: true,
31
-
32
- create_session: true,
33
- edit_agent: true,
19
+ export const getServerFeatureFlagsValue = () => {
20
+ const flags = parseFeatureFlag(env.FEATURE_FLAGS);
34
21
 
35
- dalle: true,
36
-
37
- check_updates: true,
38
- welcome_suggest: true,
22
+ return merge(DEFAULT_FEATURE_FLAGS, flags);
39
23
  };
40
24
 
41
- export const mapFeatureFlagsEnvToState = (config: IFeatureFlags) => {
42
- return {
43
- enableWebrtc: config.webrtc_sync,
44
- isAgentEditable: config.edit_agent,
45
-
46
- showCreateSession: config.create_session,
47
- showLLM: config.language_model_settings,
48
-
49
- showOpenAIApiKey: config.openai_api_key,
50
- showOpenAIProxyUrl: config.openai_proxy_url,
25
+ export const serverFeatureFlags = () => {
26
+ const serverConfig = getServerFeatureFlagsValue();
51
27
 
52
- showDalle: config.dalle,
53
-
54
- enableCheckUpdates: config.check_updates,
55
- showWelcomeSuggest: config.welcome_suggest,
56
- };
28
+ return mapFeatureFlagsEnvToState(serverConfig);
57
29
  };
30
+
31
+ export * from './schema';
@@ -1,6 +1,6 @@
1
1
  import { describe, expect, it } from 'vitest';
2
2
 
3
- import { FeatureFlagsSchema, mapFeatureFlagsEnvToState } from './index';
3
+ import { FeatureFlagsSchema, mapFeatureFlagsEnvToState } from './schema';
4
4
 
5
5
  describe('FeatureFlagsSchema', () => {
6
6
  it('should validate correct feature flags', () => {
@@ -0,0 +1,57 @@
1
+ /* eslint-disable sort-keys-fix/sort-keys-fix */
2
+ import { z } from 'zod';
3
+
4
+ export const FeatureFlagsSchema = z.object({
5
+ webrtc_sync: z.boolean().optional(),
6
+
7
+ language_model_settings: z.boolean().optional(),
8
+
9
+ openai_api_key: z.boolean().optional(),
10
+ openai_proxy_url: z.boolean().optional(),
11
+
12
+ create_session: z.boolean().optional(),
13
+ edit_agent: z.boolean().optional(),
14
+
15
+ dalle: z.boolean().optional(),
16
+
17
+ check_updates: z.boolean().optional(),
18
+ welcome_suggest: z.boolean().optional(),
19
+ });
20
+
21
+ // TypeScript 类型,从 Zod schema 生成
22
+ export type IFeatureFlags = z.infer<typeof FeatureFlagsSchema>;
23
+
24
+ export const DEFAULT_FEATURE_FLAGS: IFeatureFlags = {
25
+ webrtc_sync: true,
26
+
27
+ language_model_settings: true,
28
+
29
+ openai_api_key: true,
30
+ openai_proxy_url: true,
31
+
32
+ create_session: true,
33
+ edit_agent: true,
34
+
35
+ dalle: true,
36
+
37
+ check_updates: true,
38
+ welcome_suggest: true,
39
+ };
40
+
41
+ export const mapFeatureFlagsEnvToState = (config: IFeatureFlags) => {
42
+ return {
43
+ enableWebrtc: config.webrtc_sync,
44
+ isAgentEditable: config.edit_agent,
45
+
46
+ showCreateSession: config.create_session,
47
+ showLLM: config.language_model_settings,
48
+
49
+ showOpenAIApiKey: config.openai_api_key,
50
+ showOpenAIProxyUrl: config.openai_proxy_url,
51
+
52
+ showDalle: config.dalle,
53
+
54
+ enableCheckUpdates: config.check_updates,
55
+ showWelcomeSuggest: config.welcome_suggest,
56
+ };
57
+ };
@@ -1,4 +1,4 @@
1
- import { FeatureFlagsSchema, IFeatureFlags } from '@/config/featureFlags';
1
+ import { FeatureFlagsSchema, IFeatureFlags } from '../schema';
2
2
 
3
3
  /**
4
4
  * 解析环境变量中的特性标志字符串。
@@ -3,7 +3,7 @@ import { cookies } from 'next/headers';
3
3
  import { FC, ReactNode } from 'react';
4
4
 
5
5
  import { getClientConfig } from '@/config/client';
6
- import { getServerFeatureFlagsValue } from '@/config/server/featureFlags';
6
+ import { getServerFeatureFlagsValue } from '@/config/featureFlags';
7
7
  import { LOBE_LOCALE_COOKIE } from '@/const/locale';
8
8
  import {
9
9
  LOBE_THEME_APPEARANCE,
@@ -1,29 +0,0 @@
1
- import { createEnv } from '@t3-oss/env-nextjs';
2
- import { z } from 'zod';
3
-
4
- import { DEFAULT_FEATURE_FLAGS, mapFeatureFlagsEnvToState } from '@/config/featureFlags';
5
- import { merge } from '@/utils/merge';
6
-
7
- import { parseFeatureFlag } from './parser';
8
-
9
- const env = createEnv({
10
- runtimeEnv: {
11
- FEATURE_FLAGS: process.env.FEATURE_FLAGS,
12
- },
13
-
14
- server: {
15
- FEATURE_FLAGS: z.string().optional(),
16
- },
17
- });
18
-
19
- export const getServerFeatureFlagsValue = () => {
20
- const flags = parseFeatureFlag(env.FEATURE_FLAGS);
21
-
22
- return merge(DEFAULT_FEATURE_FLAGS, flags);
23
- };
24
-
25
- export const serverFeatureFlags = () => {
26
- const serverConfig = getServerFeatureFlagsValue();
27
-
28
- return mapFeatureFlagsEnvToState(serverConfig);
29
- };