@lobehub/chat 0.126.2 → 0.126.4

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,65 @@
2
2
 
3
3
  # Changelog
4
4
 
5
+ ### [Version 0.126.4](https://github.com/lobehub/lobe-chat/compare/v0.126.3...v0.126.4)
6
+
7
+ <sup>Released on **2024-02-11**</sup>
8
+
9
+ #### ♻ Code Refactoring
10
+
11
+ - **misc**: Update Model provider request url.
12
+
13
+ #### 🐛 Bug Fixes
14
+
15
+ - **misc**: Fix auth error in console, fix token tag usage display.
16
+
17
+ <br/>
18
+
19
+ <details>
20
+ <summary><kbd>Improvements and Fixes</kbd></summary>
21
+
22
+ #### Code refactoring
23
+
24
+ - **misc**: Update Model provider request url ([b64acc0](https://github.com/lobehub/lobe-chat/commit/b64acc0))
25
+
26
+ #### What's fixed
27
+
28
+ - **misc**: Fix auth error in console ([8e7ee82](https://github.com/lobehub/lobe-chat/commit/8e7ee82))
29
+ - **misc**: Fix token tag usage display ([6e7134b](https://github.com/lobehub/lobe-chat/commit/6e7134b))
30
+
31
+ </details>
32
+
33
+ <div align="right">
34
+
35
+ [![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)
36
+
37
+ </div>
38
+
39
+ ### [Version 0.126.3](https://github.com/lobehub/lobe-chat/compare/v0.126.2...v0.126.3)
40
+
41
+ <sup>Released on **2024-02-09**</sup>
42
+
43
+ #### 🐛 Bug Fixes
44
+
45
+ - **misc**: Fix auth layout error.
46
+
47
+ <br/>
48
+
49
+ <details>
50
+ <summary><kbd>Improvements and Fixes</kbd></summary>
51
+
52
+ #### What's fixed
53
+
54
+ - **misc**: Fix auth layout error ([efd7d14](https://github.com/lobehub/lobe-chat/commit/efd7d14))
55
+
56
+ </details>
57
+
58
+ <div align="right">
59
+
60
+ [![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)
61
+
62
+ </div>
63
+
5
64
  ### [Version 0.126.2](https://github.com/lobehub/lobe-chat/compare/v0.126.1...v0.126.2)
6
65
 
7
66
  <sup>Released on **2024-02-09**</sup>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/chat",
3
- "version": "0.126.2",
3
+ "version": "0.126.4",
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",
@@ -73,6 +73,7 @@
73
73
  },
74
74
  "dependencies": {
75
75
  "@ant-design/icons": "^5",
76
+ "@auth/core": "^0.26.3",
76
77
  "@aws-sdk/client-bedrock-runtime": "^3.503.1",
77
78
  "@azure/openai": "^1.0.0-beta.11",
78
79
  "@cfworker/json-schema": "^1",
@@ -2,7 +2,7 @@ import { Form, type ItemGroup, SelectWithImg, SliderWithInput } from '@lobehub/u
2
2
  import { Form as AntForm, App, Button, Input, Select } from 'antd';
3
3
  import isEqual from 'fast-deep-equal';
4
4
  import { AppWindow, Monitor, Moon, Palette, Sun } from 'lucide-react';
5
- import { signIn, signOut, useSession } from 'next-auth/react';
5
+ import { signIn, signOut } from 'next-auth/react';
6
6
  import { memo, useCallback, useEffect } from 'react';
7
7
  import { useTranslation } from 'react-i18next';
8
8
 
@@ -10,6 +10,7 @@ import { FORM_STYLE } from '@/const/layoutTokens';
10
10
  import { DEFAULT_SETTINGS } from '@/const/settings';
11
11
  import { imageUrl } from '@/const/url';
12
12
  import AvatarWithUpload from '@/features/AvatarWithUpload';
13
+ import { useOAuthSession } from '@/hooks/useOAuthSession';
13
14
  import { localeOptions } from '@/locales/resources';
14
15
  import { useChatStore } from '@/store/chat';
15
16
  import { useFileStore } from '@/store/file';
@@ -32,8 +33,7 @@ const Common = memo<SettingsCommonProps>(({ showAccessCodeConfig, showOAuthLogin
32
33
  const { t } = useTranslation('setting');
33
34
  const [form] = AntForm.useForm();
34
35
 
35
- const { data: session, status } = useSession();
36
- const isOAuthLoggedIn = status === 'authenticated' && session && session.user;
36
+ const { user, isOAuthLoggedIn } = useOAuthSession();
37
37
 
38
38
  const [clearSessions, clearSessionGroups] = useSessionStore((s) => [
39
39
  s.clearSessions,
@@ -227,7 +227,7 @@ const Common = memo<SettingsCommonProps>(({ showAccessCodeConfig, showOAuthLogin
227
227
  </Button>
228
228
  ),
229
229
  desc: isOAuthLoggedIn
230
- ? `${session.user?.email} ${t('settingSystem.oauth.info.desc')}`
230
+ ? `${user?.email} ${t('settingSystem.oauth.info.desc')}`
231
231
  : t('settingSystem.oauth.signin.desc'),
232
232
  hidden: !showOAuthLogin,
233
233
  label: isOAuthLoggedIn
@@ -6,6 +6,7 @@ import { Trans, useTranslation } from 'react-i18next';
6
6
 
7
7
  import Footer from '@/app/settings/features/Footer';
8
8
  import PageTitle from '@/components/PageTitle';
9
+ import { MORE_MODEL_PROVIDER_REQUEST_URL } from '@/const/url';
9
10
  import { useSwitchSideBarOnInit } from '@/store/global/hooks/useSwitchSettingsOnInit';
10
11
  import { SettingsTabs } from '@/store/global/initialState';
11
12
 
@@ -30,11 +31,7 @@ export default memo(() => {
30
31
  <Footer>
31
32
  <Trans i18nKey="llm.waitingForMore" ns={'setting'}>
32
33
  更多模型正在
33
- <Link
34
- aria-label={'todo'}
35
- href="https://github.com/lobehub/lobe-chat/issues/151"
36
- target="_blank"
37
- >
34
+ <Link aria-label={'todo'} href={MORE_MODEL_PROVIDER_REQUEST_URL} target="_blank">
38
35
  计划接入
39
36
  </Link>
40
37
  中 ,敬请期待 ✨
package/src/const/url.ts CHANGED
@@ -15,6 +15,9 @@ export const DISCORD = 'https://discord.gg/AYFPHvv2jT';
15
15
 
16
16
  export const PLUGINS_INDEX_URL = 'https://chat-plugins.lobehub.com';
17
17
 
18
+ export const MORE_MODEL_PROVIDER_REQUEST_URL =
19
+ 'https://github.com/lobehub/lobe-chat/discussions/1284';
20
+
18
21
  export const AGENTS_INDEX_GITHUB = 'https://github.com/lobehub/lobe-chat-agents';
19
22
  export const AGENTS_INDEX_GITHUB_ISSUE = urlJoin(AGENTS_INDEX_GITHUB, 'issues/new');
20
23
 
@@ -30,10 +30,11 @@ const Token = memo(() => {
30
30
  agentSelectors.currentAgentModel(s) as LanguageModel,
31
31
  ]);
32
32
 
33
- const tokens = useGlobalStore(modelProviderSelectors.modelMaxToken(model));
33
+ const maxTokens = useGlobalStore(modelProviderSelectors.modelMaxToken(model));
34
34
 
35
+ // Tool usage token
36
+ const canUseTool = useGlobalStore(modelProviderSelectors.modelEnabledFunctionCall(model));
35
37
  const plugins = useSessionStore(agentSelectors.currentAgentPlugins);
36
-
37
38
  const toolsString = useToolStore((s) => {
38
39
  const pluginSystemRoles = toolSelectors.enabledSystemRoles(plugins)(s);
39
40
  const schemaNumber = toolSelectors
@@ -43,13 +44,17 @@ const Token = memo(() => {
43
44
 
44
45
  return pluginSystemRoles + schemaNumber;
45
46
  });
47
+ const toolsToken = useTokenCount(canUseTool ? toolsString : '');
46
48
 
49
+ // Chat usage token
47
50
  const inputTokenCount = useTokenCount(input);
51
+
48
52
  const chatsToken = useTokenCount(messageString) + inputTokenCount;
49
53
 
50
- const toolsToken = useTokenCount(toolsString);
54
+ // SystemRole token
51
55
  const systemRoleToken = useTokenCount(systemRole);
52
56
 
57
+ // Total token
53
58
  const totalToken = systemRoleToken + toolsToken + chatsToken;
54
59
  return (
55
60
  <Tooltip
@@ -74,18 +79,18 @@ const Token = memo(() => {
74
79
  </Flexbox>
75
80
  <Flexbox horizontal justify={'space-between'} style={{ marginTop: 8 }}>
76
81
  <span>{t('tokenDetails.total')}</span>
77
- <span>{format(tokens)}</span>
82
+ <span>{format(maxTokens)}</span>
78
83
  </Flexbox>
79
84
  <Flexbox horizontal justify={'space-between'}>
80
85
  <span>{t('tokenDetails.rest')}</span>
81
- <span>{format(tokens - totalToken)}</span>
86
+ <span>{format(maxTokens - totalToken)}</span>
82
87
  </Flexbox>
83
88
  </Flexbox>
84
89
  }
85
90
  >
86
91
  <TokenTag
87
92
  displayMode={'used'}
88
- maxValue={tokens}
93
+ maxValue={maxTokens}
89
94
  style={{ marginLeft: 8 }}
90
95
  text={{
91
96
  overload: t('tokenTag.overload'),
@@ -1,11 +1,12 @@
1
1
  import { Icon } from '@lobehub/ui';
2
2
  import { App, Button } from 'antd';
3
3
  import { ScanFace } from 'lucide-react';
4
- import { signIn, signOut, useSession } from 'next-auth/react';
4
+ import { signIn, signOut } from 'next-auth/react';
5
5
  import { memo, useCallback } from 'react';
6
6
  import { useTranslation } from 'react-i18next';
7
7
  import { Center, Flexbox } from 'react-layout-kit';
8
8
 
9
+ import { useOAuthSession } from '@/hooks/useOAuthSession';
9
10
  import { useChatStore } from '@/store/chat';
10
11
 
11
12
  import { FormAction } from './style';
@@ -13,8 +14,7 @@ import { FormAction } from './style';
13
14
  const OAuthForm = memo<{ id: string }>(({ id }) => {
14
15
  const { t } = useTranslation('error');
15
16
 
16
- const { data: session, status } = useSession();
17
- const isOAuthLoggedIn = status === 'authenticated' && session && session.user;
17
+ const { user, isOAuthLoggedIn } = useOAuthSession();
18
18
 
19
19
  const [resend, deleteMessage] = useChatStore((s) => [s.resendMessage, s.deleteMessage]);
20
20
 
@@ -38,7 +38,7 @@ const OAuthForm = memo<{ id: string }>(({ id }) => {
38
38
  avatar={isOAuthLoggedIn ? '✅' : '🕵️‍♂️'}
39
39
  description={
40
40
  isOAuthLoggedIn
41
- ? `${t('unlock.oauth.welcome')} ${session?.user?.name}`
41
+ ? `${t('unlock.oauth.welcome')} ${user?.name}`
42
42
  : t('unlock.oauth.description')
43
43
  }
44
44
  title={isOAuthLoggedIn ? t('unlock.oauth.success') : t('unlock.oauth.title')}
@@ -0,0 +1,24 @@
1
+ import { User } from '@auth/core/types';
2
+ import { SessionContextValue, useSession } from 'next-auth/react';
3
+ import { useMemo } from 'react';
4
+
5
+ interface OAuthSession {
6
+ isOAuthLoggedIn: boolean;
7
+ user?: User | null;
8
+ }
9
+
10
+ export const useOAuthSession = () => {
11
+ let authSession: SessionContextValue | null;
12
+ try {
13
+ // refs: https://github.com/lobehub/lobe-chat/pull/1286
14
+ // eslint-disable-next-line react-hooks/rules-of-hooks
15
+ authSession = useSession();
16
+ } catch {
17
+ authSession = null;
18
+ }
19
+
20
+ const { data: session, status } = authSession || {};
21
+ const isOAuthLoggedIn = (status === 'authenticated' && session && !!session.user) || false;
22
+
23
+ return useMemo<OAuthSession>(() => ({ isOAuthLoggedIn, user: session?.user }), [session, status]);
24
+ };