@lobehub/chat 0.80.2 → 0.81.0

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.81.0](https://github.com/lobehub/lobe-chat/compare/v0.80.2...v0.81.0)
6
+
7
+ <sup>Released on **2023-09-27**</sup>
8
+
9
+ #### ✨ Features
10
+
11
+ - **misc**: Add several analytics sdk.
12
+
13
+ <br/>
14
+
15
+ <details>
16
+ <summary><kbd>Improvements and Fixes</kbd></summary>
17
+
18
+ #### What's improved
19
+
20
+ - **misc**: Add several analytics sdk, closes [#244](https://github.com/lobehub/lobe-chat/issues/244) ([65c6c93](https://github.com/lobehub/lobe-chat/commit/65c6c93))
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.80.2](https://github.com/lobehub/lobe-chat/compare/v0.80.1...v0.80.2)
6
31
 
7
32
  <sup>Released on **2023-09-27**</sup>
@@ -0,0 +1,19 @@
1
+ # 数据统计
2
+
3
+ 为更好地帮助分析 LobeChat 的用户使用情况,我们在 LobeChat 中集成了若干免费 / 开源的数据统计服务,用于收集用户的使用情况,你可以按需开启。
4
+
5
+ ## Vercel Analytics
6
+
7
+ [Vercel Analytics](https://vercel.com/analytics) 是 Vercel 推出的一款数据分析服务,它可以帮助你收集网站的访问情况,包括访问量、访问来源、访问设备等等。
8
+
9
+ 由于我们推荐使用 Vercel 一键部署 LobeChat,因此我们在代码中默认集成了 Vercel Analytics,你可以通过自行打开部署项目中 \[Insights] tab,查看你的应用访问情况。
10
+
11
+ Vercel Analytics 提供了 2500 次 / 月的免费 Web Analytics Events (可以理解为 PV),对于个人部署自用的产品来说基本够用。
12
+
13
+ 如果你需要了解 Vercel Analytics 的详细使用教程,请查阅[Vercel Web Analytics 快速开始](https://vercel.com/docs/analytics/quickstart)
14
+
15
+ 如果你不需要 Vercel Analytics,你可以通过设置环境变量 `NEXT_PUBLIC_ANALYTICS_VERCEL=0` 来关闭它。
16
+
17
+ ## 🚧 Posthog
18
+
19
+ ## 🚧 Mixpanel
@@ -17,6 +17,13 @@ LobeChat 在部署时提供了一些额外的配置项,使用环境变量进
17
17
  - [`PLUGINS_INDEX_URL`](#plugins_index_url)
18
18
  - [角色服务](#角色服务)
19
19
  - [`AGENTS_INDEX_URL`](#agents_index_url)
20
+ - [数据统计](#数据统计)
21
+ - [Vercel Analytics](#vercel-analytics)
22
+ - [Mixpanel Analytics](#mixpanel-analytics)
23
+ - [`NEXT_PUBLIC_MIXPANEL_PROJECT_TOKEN`](#next_public_mixpanel_project_token)
24
+ - [`NEXT_PUBLIC_MIXPANEL_DEBUG`](#next_public_mixpanel_debug)
25
+ - [Posthog Analytics](#posthog-analytics)
26
+ - [`NEXT_PUBLIC_POSTHOG_DEBUG`](#next_public_posthog_debug)
20
27
  - [开发环境](#开发环境)
21
28
  - [`DEV_API_END_PORT_URL`](#dev_api_end_port_url)
22
29
 
@@ -94,7 +101,76 @@ LobeChat 在部署时提供了一些额外的配置项,使用环境变量进
94
101
  - 描述:LobeChat 角色市场的索引地址,如果你自行部署了角色市场的服务,可以使用该变量来覆盖默认的插件市场地址
95
102
  - 默认值:`https://chat-agents.lobehub.com`
96
103
 
97
- <br/>
104
+ ## 数据统计
105
+
106
+ ### Vercel Analytics
107
+
108
+ #### `NEXT_PUBLIC_ANALYTICS_VERCEL`
109
+
110
+ - 类型:可选
111
+ - 描述:用于配置 Vercel Analytics 的环境变量,当设为 `0` 则关闭 Vercel Analytics
112
+ - 默认值: -
113
+ - 示例:`0`
114
+
115
+ #### `NEXT_PUBLIC_VERCEL_DEBUG`
116
+
117
+ - 类型:可选
118
+ - 描述:用于开启 Vercel Analytics 的调试模式
119
+ - 默认值: -
120
+ - 示例:`1`
121
+
122
+ ### Mixpanel Analytics
123
+
124
+ #### `NEXT_PUBLIC_ANALYTICS_MIXPANEL`
125
+
126
+ - 类型:可选
127
+ - 描述:用于开启 [Mixpanel Analytics][mixpanel-analytics-url] 的环境变量,设为 `1` 时开启 Mixpanel Analytics
128
+ - 默认值: -
129
+ - 示例:`1`
130
+
131
+ ### `NEXT_PUBLIC_MIXPANEL_PROJECT_TOKEN`
132
+
133
+ - 类型:可选
134
+ - 描述:设置 Mixpanel 项目的识别 Token,可以在[这里][mixpanel-project-url]找到
135
+ - 默认值: -
136
+ - 示例:`60db2abae7fdd29961f4e8f91b074b3a`
137
+
138
+ ### `NEXT_PUBLIC_MIXPANEL_DEBUG`
139
+
140
+ - 类型:可选
141
+ - 描述:开启 Mixpanel 的调试模式
142
+ - 默认值: -
143
+ - 示例:`1`
144
+
145
+ ### Posthog Analytics
146
+
147
+ #### `NEXT_PUBLIC_ANALYTICS_POSTHOG`
148
+
149
+ - 类型:可选
150
+ - 描述:用于开启 [PostHog Analytics][posthog-analytics-url] 的环境变量,设为 `1` 时开启 PostHog Analytics
151
+ - 默认值: -
152
+ - 示例:`1`
153
+
154
+ #### `NEXT_PUBLIC_POSTHOG_KEY`
155
+
156
+ - 类型:可选
157
+ - 描述:设置 PostHog 项目 Key
158
+ - 默认值: -
159
+ - 示例:`phc_xxxxxxxx`
160
+
161
+ #### `NEXT_PUBLIC_POSTHOG_HOST`
162
+
163
+ - 类型:可选
164
+ - 描述:设置 PostHog 服务的部署地址,默认为官方的 SAAS 地址
165
+ - 默认值:`https://app.posthog.com`
166
+ - 示例:`https://example.com`
167
+
168
+ ### `NEXT_PUBLIC_POSTHOG_DEBUG`
169
+
170
+ - 类型:可选
171
+ - 描述:开启 PostHog 的调试模式
172
+ - 默认值: -
173
+ - 示例:`1`
98
174
 
99
175
  ## 开发环境
100
176
 
@@ -106,4 +182,7 @@ LobeChat 在部署时提供了一些额外的配置项,使用环境变量进
106
182
  - 示例:`https://chat-preview.lobehub.com`
107
183
 
108
184
  [azure-api-verion-url]: https://docs.microsoft.com/zh-cn/azure/developer/javascript/api-reference/es-modules/azure-sdk/ai-translation/translationconfiguration?view=azure-node-latest#api-version
185
+ [mixpanel-analytics-url]: https://mixpanel.com
186
+ [mixpanel-project-url]: https://mixpanel.com/settings/project
109
187
  [openai-api-page]: https://platform.openai.com/account/api-keys
188
+ [posthog-analytics-url]: https://posthog.com
package/next.config.mjs CHANGED
@@ -41,6 +41,10 @@ const nextConfig = {
41
41
  },
42
42
  ];
43
43
  },
44
+ env: {
45
+ AGENTS_INDEX_URL: process.env.AGENTS_INDEX_URL,
46
+ PLUGINS_INDEX_URL: process.env.PLUGINS_INDEX_URL,
47
+ },
44
48
  };
45
49
 
46
50
  export default isProd ? withPWA(nextConfig) : nextConfig;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/chat",
3
- "version": "0.80.2",
3
+ "version": "0.81.0",
4
4
  "description": "An open-source, extensible (Function Calling), high-performance chatbot framework. It supports one-click free deployment of your private ChatGPT/LLM web application",
5
5
  "keywords": [
6
6
  "chatbot",
@@ -86,10 +86,12 @@
86
86
  "immer": "^10",
87
87
  "lodash-es": "^4",
88
88
  "lucide-react": "latest",
89
+ "mixpanel-browser": "^2",
89
90
  "nanoid": "^5",
90
91
  "next": "^13.5.3",
91
92
  "openai": "^4",
92
93
  "polished": "^4",
94
+ "posthog-js": "^1",
93
95
  "react": "^18",
94
96
  "react-dom": "^18",
95
97
  "react-hotkeys-hook": "^4",
@@ -116,6 +118,7 @@
116
118
  "@testing-library/react": "^14",
117
119
  "@types/chroma-js": "^2",
118
120
  "@types/lodash-es": "^4",
121
+ "@types/mixpanel-browser": "^2",
119
122
  "@types/node": "^20",
120
123
  "@types/react": "^18",
121
124
  "@types/react-dom": "^18",
@@ -0,0 +1,23 @@
1
+ 'use client';
2
+
3
+ import mixpanel from 'mixpanel-browser';
4
+ import { memo, useEffect } from 'react';
5
+
6
+ import { getClientConfig } from '@/config/client';
7
+
8
+ const { MIXPANEL_PROJECT_TOKEN, MIXPANEL_DEBUG } = getClientConfig();
9
+
10
+ const MixpanelAnalytics = memo(() => {
11
+ useEffect(() => {
12
+ if (!MIXPANEL_PROJECT_TOKEN) return;
13
+
14
+ mixpanel.init(MIXPANEL_PROJECT_TOKEN, {
15
+ debug: MIXPANEL_DEBUG,
16
+ persistence: 'localStorage',
17
+ track_pageview: true,
18
+ });
19
+ }, []);
20
+ return null;
21
+ });
22
+
23
+ export default MixpanelAnalytics;
@@ -0,0 +1,18 @@
1
+ 'use client';
2
+
3
+ import Script from 'next/script';
4
+ import { memo } from 'react';
5
+
6
+ import { getClientConfig } from '@/config/client';
7
+
8
+ const { PLAUSIBLE_DOMAIN } = getClientConfig();
9
+
10
+ const PlausibleAnalytics = memo(() => {
11
+ return (
12
+ PLAUSIBLE_DOMAIN && (
13
+ <Script data-domain={PLAUSIBLE_DOMAIN} defer src="https://plausible.io/js/script.js" />
14
+ )
15
+ );
16
+ });
17
+
18
+ export default PlausibleAnalytics;
@@ -0,0 +1,23 @@
1
+ 'use client';
2
+
3
+ import posthog from 'posthog-js';
4
+ import { FC, memo, useEffect } from 'react';
5
+
6
+ import { getClientConfig } from '@/config/client';
7
+
8
+ const { POSTHOG_HOST, POSTHOG_KEY, POSTHOG_DEBUG } = getClientConfig();
9
+
10
+ const PostHog: FC = memo(() => {
11
+ useEffect(() => {
12
+ if (!POSTHOG_KEY) return;
13
+
14
+ posthog.init(POSTHOG_KEY, {
15
+ api_host: POSTHOG_HOST ?? 'https://app.posthog.com',
16
+ debug: POSTHOG_DEBUG,
17
+ });
18
+ }, []);
19
+
20
+ return null;
21
+ });
22
+
23
+ export default PostHog;
@@ -0,0 +1,12 @@
1
+ 'use client';
2
+
3
+ import { Analytics } from '@vercel/analytics/react';
4
+ import { memo } from 'react';
5
+
6
+ import { getClientConfig } from '@/config/client';
7
+
8
+ const { VERCEL_DEBUG } = getClientConfig();
9
+
10
+ const VercelAnalytics = memo(() => <Analytics debug={VERCEL_DEBUG} />);
11
+
12
+ export default VercelAnalytics;
@@ -1,7 +1,24 @@
1
- import { Analytics as VercelAnalytics } from '@vercel/analytics/react';
1
+ import dynamic from 'next/dynamic';
2
+
3
+ import { getClientConfig } from '@/config/client';
4
+
5
+ const Vercel = dynamic(() => import('./Vercel'), { ssr: false });
6
+ const Mixpanel = dynamic(() => import('./Mixpanel'), { ssr: false });
7
+ const Plausible = dynamic(() => import('./Plausible'), { ssr: false });
8
+ const Posthog = dynamic(() => import('./Posthog'), { ssr: false });
9
+
10
+ const { ANALYTICS_VERCEL, ANALYTICS_POSTHOG, ANALYTICS_MIXPANEL, ANALYTICS_PLAUSIBLE } =
11
+ getClientConfig();
2
12
 
3
13
  const Analytics = () => {
4
- return <VercelAnalytics />;
14
+ return (
15
+ <>
16
+ {ANALYTICS_VERCEL && <Vercel />}
17
+ {ANALYTICS_PLAUSIBLE && <Plausible />}
18
+ {ANALYTICS_MIXPANEL && <Mixpanel />}
19
+ {ANALYTICS_POSTHOG && <Posthog />}
20
+ </>
21
+ );
5
22
  };
6
23
 
7
24
  export default Analytics;
@@ -20,9 +20,9 @@ export interface AppThemeProps {
20
20
 
21
21
  const AppTheme = memo<AppThemeProps>(
22
22
  ({ children, defaultAppearance, defaultPrimaryColor, defaultNeutralColor }) => {
23
- console.log('server:appearance', defaultAppearance);
24
- console.log('server:primaryColor', defaultPrimaryColor);
25
- console.log('server:neutralColor', defaultNeutralColor);
23
+ // console.log('server:appearance', defaultAppearance);
24
+ // console.log('server:primaryColor', defaultPrimaryColor);
25
+ // console.log('server:neutralColor', defaultNeutralColor);
26
26
  const themeMode = useGlobalStore((s) => s.settings.themeMode);
27
27
 
28
28
  const [primaryColor, neutralColor] = useGlobalStore((s) => [
@@ -31,7 +31,6 @@ const AppTheme = memo<AppThemeProps>(
31
31
  ]);
32
32
 
33
33
  useEffect(() => {
34
- console.log(primaryColor);
35
34
  setCookie(LOBE_THEME_PRIMARY_COLOR, primaryColor);
36
35
  }, [primaryColor]);
37
36
 
@@ -0,0 +1,46 @@
1
+ /* eslint-disable sort-keys-fix/sort-keys-fix , typescript-sort-keys/interface */
2
+
3
+ declare global {
4
+ // eslint-disable-next-line @typescript-eslint/no-namespace
5
+ namespace NodeJS {
6
+ interface ProcessEnv {
7
+ AGENTS_INDEX_URL?: string;
8
+ PLUGINS_INDEX_URL?: string;
9
+
10
+ NEXT_PUBLIC_ANALYTICS_VERCEL?: string;
11
+ NEXT_PUBLIC_VERCEL_DEBUG?: string;
12
+
13
+ NEXT_PUBLIC_ANALYTICS_MIXPANEL?: string;
14
+ NEXT_PUBLIC_MIXPANEL_PROJECT_TOKEN?: string;
15
+ NEXT_PUBLIC_MIXPANEL_DEBUG?: string;
16
+
17
+ NEXT_PUBLIC_ANALYTICS_PLAUSIBLE?: string;
18
+ NEXT_PUBLIC_PLAUSIBLE_DOMAIN?: string;
19
+
20
+ NEXT_PUBLIC_ANALYTICS_POSTHOG: string;
21
+ NEXT_PUBLIC_POSTHOG_KEY: string;
22
+ NEXT_PUBLIC_POSTHOG_HOST: string;
23
+ NEXT_PUBLIC_POSTHOG_DEBUG: string;
24
+ }
25
+ }
26
+ }
27
+
28
+ export const getClientConfig = () => ({
29
+ AGENTS_INDEX_URL: process.env.AGENTS_INDEX_URL,
30
+ PLUGINS_INDEX_URL: process.env.PLUGINS_INDEX_URL,
31
+
32
+ ANALYTICS_VERCEL: process.env.NEXT_PUBLIC_ANALYTICS_VERCEL !== '0',
33
+ VERCEL_DEBUG: process.env.NEXT_PUBLIC_VERCEL_DEBUG === '1',
34
+
35
+ ANALYTICS_PLAUSIBLE: process.env.NEXT_PUBLIC_ANALYTICS_PLAUSIBLE === '1',
36
+ PLAUSIBLE_DOMAIN: process.env.NEXT_PUBLIC_PLAUSIBLE_DOMAIN,
37
+
38
+ ANALYTICS_MIXPANEL: process.env.NEXT_PUBLIC_ANALYTICS_MIXPANEL === '1',
39
+ MIXPANEL_PROJECT_TOKEN: process.env.NEXT_PUBLIC_MIXPANEL_PROJECT_TOKEN,
40
+ MIXPANEL_DEBUG: process.env.NEXT_PUBLIC_MIXPANEL_DEBUG === '1',
41
+
42
+ ANALYTICS_POSTHOG: process.env.NEXT_PUBLIC_ANALYTICS_POSTHOG === '1',
43
+ POSTHOG_KEY: process.env.NEXT_PUBLIC_POSTHOG_KEY,
44
+ POSTHOG_HOST: process.env.NEXT_PUBLIC_POSTHOG_HOST,
45
+ POSTHOG_DEBUG: process.env.NEXT_PUBLIC_POSTHOG_DEBUG === '1',
46
+ });
@@ -1,12 +1,16 @@
1
+ /* eslint-disable sort-keys-fix/sort-keys-fix , typescript-sort-keys/interface */
2
+
1
3
  declare global {
2
4
  // eslint-disable-next-line @typescript-eslint/no-namespace
3
5
  namespace NodeJS {
4
6
  interface ProcessEnv {
5
7
  ACCESS_CODE?: string;
6
- AZURE_API_KEY?: string;
7
- AZURE_API_VERSION?: string;
8
+
8
9
  OPENAI_API_KEY?: string;
9
10
  OPENAI_PROXY_URL?: string;
11
+
12
+ AZURE_API_KEY?: string;
13
+ AZURE_API_VERSION?: string;
10
14
  USE_AZURE_OPENAI?: string;
11
15
  }
12
16
  }
@@ -19,13 +23,12 @@ export const getServerConfig = () => {
19
23
 
20
24
  return {
21
25
  ACCESS_CODE: process.env.ACCESS_CODE,
22
- /* eslint-disable sort-keys-fix/sort-keys-fix */
23
- AZURE_API_KEY: process.env.AZURE_API_KEY,
24
- AZURE_API_VERSION: process.env.AZURE_API_VERSION,
25
- /* eslint-enabled */
26
26
 
27
27
  OPENAI_API_KEY: process.env.OPENAI_API_KEY,
28
28
  OPENAI_PROXY_URL: process.env.OPENAI_PROXY_URL,
29
+
30
+ AZURE_API_KEY: process.env.AZURE_API_KEY,
31
+ AZURE_API_VERSION: process.env.AZURE_API_VERSION,
29
32
  USE_AZURE_OPENAI: process.env.USE_AZURE_OPENAI === '1',
30
33
  };
31
34
  };
package/src/const/url.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import urlJoin from 'url-join';
2
2
 
3
+ import { getClientConfig } from '@/config/client';
3
4
  import { localeOptions } from '@/locales/options';
4
5
  import { Locales } from '@/locales/resources';
5
6
 
@@ -13,7 +14,7 @@ export const FEEDBACK = pkg.bugs.url;
13
14
  export const DISCORD = 'https://discord.gg/AYFPHvv2jT';
14
15
 
15
16
  export const PLUGINS_INDEX_URL =
16
- process.env.PLUGINS_INDEX_URL ?? 'https://chat-plugins.lobehub.com';
17
+ getClientConfig().PLUGINS_INDEX_URL ?? 'https://chat-plugins.lobehub.com';
17
18
 
18
19
  export const DEFAULT_LANG = 'en-US';
19
20
 
@@ -26,7 +27,8 @@ export const getPluginIndexJSON = (lang: Locales = DEFAULT_LANG, baseUrl = PLUGI
26
27
  return urlJoin(baseUrl, `index.${lang}.json`);
27
28
  };
28
29
 
29
- export const AGENTS_INDEX_URL = process.env.AGENTS_INDEX_URL ?? 'https://chat-agents.lobehub.com';
30
+ export const AGENTS_INDEX_URL =
31
+ getClientConfig().AGENTS_INDEX_URL ?? 'https://chat-agents.lobehub.com';
30
32
 
31
33
  export const getAgentIndexJSON = (lang: Locales = DEFAULT_LANG, baseUrl = AGENTS_INDEX_URL) => {
32
34
  if (checkLang(lang)) return baseUrl;