@lobehub/chat 0.126.3 → 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 +34 -0
- package/package.json +2 -1
- package/src/app/layout.tsx +4 -0
- package/src/app/settings/common/Common.tsx +4 -4
- package/src/app/settings/llm/page.tsx +2 -5
- package/src/const/url.ts +3 -0
- package/src/features/ChatInput/ActionBar/Token/TokenTag.tsx +11 -6
- package/src/features/Conversation/Error/OAuthForm.tsx +4 -4
- package/src/hooks/useOAuthSession.ts +24 -0
- package/src/layout/GlobalLayout/index.tsx +21 -11
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,40 @@
|
|
|
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
|
+
[](#readme-top)
|
|
36
|
+
|
|
37
|
+
</div>
|
|
38
|
+
|
|
5
39
|
### [Version 0.126.3](https://github.com/lobehub/lobe-chat/compare/v0.126.2...v0.126.3)
|
|
6
40
|
|
|
7
41
|
<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.
|
|
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",
|
package/src/app/layout.tsx
CHANGED
|
@@ -4,6 +4,7 @@ import { PropsWithChildren } from 'react';
|
|
|
4
4
|
import { isRtlLang } from 'rtl-detect';
|
|
5
5
|
|
|
6
6
|
import Analytics from '@/components/Analytics';
|
|
7
|
+
import { getServerConfig } from '@/config/server';
|
|
7
8
|
import { DEFAULT_LANG, LOBE_LOCALE_COOKIE } from '@/const/locale';
|
|
8
9
|
import {
|
|
9
10
|
LOBE_THEME_APPEARANCE,
|
|
@@ -14,6 +15,8 @@ import Layout from '@/layout/GlobalLayout';
|
|
|
14
15
|
|
|
15
16
|
import StyleRegistry from './StyleRegistry';
|
|
16
17
|
|
|
18
|
+
const { ENABLE_OAUTH_SSO } = getServerConfig();
|
|
19
|
+
|
|
17
20
|
const RootLayout = ({ children }: PropsWithChildren) => {
|
|
18
21
|
// get default theme config to use with ssr
|
|
19
22
|
const cookieStore = cookies();
|
|
@@ -32,6 +35,7 @@ const RootLayout = ({ children }: PropsWithChildren) => {
|
|
|
32
35
|
defaultLang={lang?.value}
|
|
33
36
|
defaultNeutralColor={neutralColor?.value as any}
|
|
34
37
|
defaultPrimaryColor={primaryColor?.value as any}
|
|
38
|
+
enableOAuthSSO={ENABLE_OAUTH_SSO}
|
|
35
39
|
>
|
|
36
40
|
{children}
|
|
37
41
|
</Layout>
|
|
@@ -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
|
|
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 {
|
|
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
|
-
? `${
|
|
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
|
|
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
|
-
|
|
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(
|
|
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(
|
|
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={
|
|
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
|
|
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 {
|
|
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')} ${
|
|
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
|
+
};
|
|
@@ -46,19 +46,29 @@ const Container = memo<PropsWithChildren>(({ children }) => {
|
|
|
46
46
|
|
|
47
47
|
interface GlobalLayoutProps extends AppThemeProps {
|
|
48
48
|
defaultLang?: string;
|
|
49
|
+
enableOAuthSSO?: boolean;
|
|
49
50
|
}
|
|
50
51
|
|
|
51
|
-
const GlobalLayout = ({
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
52
|
+
const GlobalLayout = ({
|
|
53
|
+
children,
|
|
54
|
+
defaultLang,
|
|
55
|
+
enableOAuthSSO = false,
|
|
56
|
+
...theme
|
|
57
|
+
}: GlobalLayoutProps) => {
|
|
58
|
+
const content = (
|
|
59
|
+
<AppTheme {...theme}>
|
|
60
|
+
<Locale defaultLang={defaultLang}>
|
|
61
|
+
<StoreHydration />
|
|
62
|
+
<Container>{children}</Container>
|
|
63
|
+
<DebugUI />
|
|
64
|
+
</Locale>
|
|
65
|
+
</AppTheme>
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
return enableOAuthSSO ? (
|
|
69
|
+
<SessionProvider basePath={API_ENDPOINTS.oauth}>{content}</SessionProvider>
|
|
70
|
+
) : (
|
|
71
|
+
content
|
|
62
72
|
);
|
|
63
73
|
};
|
|
64
74
|
|