@lobehub/chat 0.126.3 โ†’ 0.126.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,73 @@
2
2
 
3
3
  # Changelog
4
4
 
5
+ ### [Version 0.126.5](https://github.com/lobehub/lobe-chat/compare/v0.126.4...v0.126.5)
6
+
7
+ <sup>Released on **2024-02-12**</sup>
8
+
9
+ #### โ™ป Code Refactoring
10
+
11
+ - **misc**: Refactor with the auth code.
12
+
13
+ #### ๐Ÿ› Bug Fixes
14
+
15
+ - **misc**: Fix middleware auth console error.
16
+
17
+ <br/>
18
+
19
+ <details>
20
+ <summary><kbd>Improvements and Fixes</kbd></summary>
21
+
22
+ #### Code refactoring
23
+
24
+ - **misc**: Refactor with the auth code ([8cee01f](https://github.com/lobehub/lobe-chat/commit/8cee01f))
25
+
26
+ #### What's fixed
27
+
28
+ - **misc**: Fix middleware auth console error ([ad3ade8](https://github.com/lobehub/lobe-chat/commit/ad3ade8))
29
+
30
+ </details>
31
+
32
+ <div align="right">
33
+
34
+ [![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)
35
+
36
+ </div>
37
+
38
+ ### [Version 0.126.4](https://github.com/lobehub/lobe-chat/compare/v0.126.3...v0.126.4)
39
+
40
+ <sup>Released on **2024-02-11**</sup>
41
+
42
+ #### โ™ป Code Refactoring
43
+
44
+ - **misc**: Update Model provider request url.
45
+
46
+ #### ๐Ÿ› Bug Fixes
47
+
48
+ - **misc**: Fix auth error in console, fix token tag usage display.
49
+
50
+ <br/>
51
+
52
+ <details>
53
+ <summary><kbd>Improvements and Fixes</kbd></summary>
54
+
55
+ #### Code refactoring
56
+
57
+ - **misc**: Update Model provider request url ([b64acc0](https://github.com/lobehub/lobe-chat/commit/b64acc0))
58
+
59
+ #### What's fixed
60
+
61
+ - **misc**: Fix auth error in console ([8e7ee82](https://github.com/lobehub/lobe-chat/commit/8e7ee82))
62
+ - **misc**: Fix token tag usage display ([6e7134b](https://github.com/lobehub/lobe-chat/commit/6e7134b))
63
+
64
+ </details>
65
+
66
+ <div align="right">
67
+
68
+ [![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)
69
+
70
+ </div>
71
+
5
72
  ### [Version 0.126.3](https://github.com/lobehub/lobe-chat/compare/v0.126.2...v0.126.3)
6
73
 
7
74
  <sup>Released on **2024-02-09**</sup>
package/README.md CHANGED
@@ -225,14 +225,14 @@ Our marketplace is not just a showcase platform but also a collaborative space.
225
225
 
226
226
  <!-- AGENT LIST -->
227
227
 
228
- | Recent Submits | Description |
229
- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
230
- | [Vocabulary Wizard](https://chat-preview.lobehub.com/market?agent=awl-vocab-wizard)<br/><sup>By **[bentwnghk](https://github.com/bentwnghk)** on **2024-02-09**</sup> | Expert in generating vocabulary lists and MCQ tests<br/>`vocabulary` `academic-word-list` `language-learning` `testing` |
231
- | [English Proficiency Evaluator](https://chat-preview.lobehub.com/market?agent=english-proficiency-assessor)<br/><sup>By **[bentwnghk](https://github.com/bentwnghk)** on **2024-02-09**</sup> | Expert in creating adaptive English proficiency diagnostic tests<br/>`test-creation` `english-proficiency` `assessment` |
232
- | [Glossary Generator](https://chat-preview.lobehub.com/market?agent=glossary-generator)<br/><sup>By **[bentwnghk](https://github.com/bentwnghk)** on **2024-02-09**</sup> | Expert in generating glossaries with English definitions and example sentences<br/>`glossary` `translation` `language` |
233
- | [Grammar Worksheet Creator](https://chat-preview.lobehub.com/market?agent=grammar-revision-worksheets)<br/><sup>By **[bentwnghk](https://github.com/bentwnghk)** on **2024-02-09**</sup> | Specializes in creating English grammar learning materials and exercises<br/>`english-grammar` `worksheet` `learning` `practice` `mc-qs` |
234
-
235
- > ๐Ÿ“Š Total agents: [<kbd>**170**</kbd> ](https://github.com/lobehub/lobe-chat-agents)
228
+ | Recent Submits | Description |
229
+ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
230
+ | [Product Review](https://chat-preview.lobehub.com/market?agent=product-reviews)<br/><sup>By **[pllz7](https://github.com/pllz7)** on **2024-02-11**</sup> | Expert in creating persuasive product testimonials highlighting the benefits and value proposition of \[your product/service].<br/>`ecommerce` |
231
+ | [Tarot Reader](https://chat-preview.lobehub.com/market?agent=augur)<br/><sup>By **[CLOT-LIU](https://github.com/CLOT-LIU)** on **2024-02-10**</sup> | Specializes in tarot reading and interpreting tarot cards<br/>`tarot-reading` `interpretation` `advice` |
232
+ | [Happy Loong Year](https://chat-preview.lobehub.com/market?agent=happy-loong-year)<br/><sup>By **[canisminor1990](https://github.com/canisminor1990)** on **2024-02-10**</sup> | Loong Year's Assistant combines traditional and modern elements to create interesting New Year blessings.<br/>`new-years-greetings` `creativity` `copywriting` `dragon-year` |
233
+ | [Vocabulary Wizard](https://chat-preview.lobehub.com/market?agent=awl-vocab-wizard)<br/><sup>By **[bentwnghk](https://github.com/bentwnghk)** on **2024-02-09**</sup> | Expert in generating vocabulary lists and MCQ tests<br/>`vocabulary` `academic-word-list` `language-learning` `testing` |
234
+
235
+ > ๐Ÿ“Š Total agents: [<kbd>**173**</kbd> ](https://github.com/lobehub/lobe-chat-agents)
236
236
 
237
237
  <!-- AGENT LIST -->
238
238
 
package/README.zh-CN.md CHANGED
@@ -205,14 +205,14 @@ LobeChat ็š„ๆ’ไปถ็”Ÿๆ€็ณป็ปŸๆ˜ฏๅ…ถๆ ธๅฟƒๅŠŸ่ƒฝ็š„้‡่ฆๆ‰ฉๅฑ•๏ผŒๅฎƒๆžๅคงๅœฐ
205
205
 
206
206
  <!-- AGENT LIST -->
207
207
 
208
- | ๆœ€่ฟ‘ๆ–ฐๅขž | ๅŠฉๆ‰‹่ฏดๆ˜Ž |
209
- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------ |
210
- | [่ฏๆฑ‡ๅคงๅธˆ](https://chat-preview.lobehub.com/market?agent=awl-vocab-wizard)<br/><sup>By **[bentwnghk](https://github.com/bentwnghk)** on **2024-02-09**</sup> | ๆ“…้•ฟ็”Ÿๆˆ่ฏๆฑ‡ๅˆ—่กจๅ’Œๅคš้กน้€‰ๆ‹ฉๆต‹่ฏ•<br/>`่ฏๆฑ‡` `ๅญฆๆœฏ่ฏๆฑ‡่กจ` `่ฏญ่จ€ๅญฆไน ` `ๆต‹่ฏ•` |
211
- | [่‹ฑ่ฏญ็†Ÿ็ปƒๅบฆ่ฏ„ไผฐๅ™จ](https://chat-preview.lobehub.com/market?agent=english-proficiency-assessor)<br/><sup>By **[bentwnghk](https://github.com/bentwnghk)** on **2024-02-09**</sup> | ไธ“ไธšๅˆ›ๅปบ่‡ช้€‚ๅบ”่‹ฑ่ฏญ็†Ÿ็ปƒๅบฆ่ฏŠๆ–ญๆต‹่ฏ•็š„ไธ“ๅฎถ<br/>`ๆต‹่ฏ•ๅˆ›ๅปบ` `่‹ฑ่ฏญ็†Ÿ็ปƒๅบฆ` `่ฏ„ไผฐ` |
212
- | [ๆœฏ่ฏญ่กจ็”Ÿๆˆๅ™จ](https://chat-preview.lobehub.com/market?agent=glossary-generator)<br/><sup>By **[bentwnghk](https://github.com/bentwnghk)** on **2024-02-09**</sup> | ๆ“…้•ฟ็”Ÿๆˆๅธฆๆœ‰่‹ฑๆ–‡ๅฎšไน‰ๅ’Œไพ‹ๅฅ็š„ๆœฏ่ฏญ่กจ<br/>`ๆœฏ่ฏญ่กจ` `็ฟป่ฏ‘` `่ฏญ่จ€` |
213
- | [่ฏญๆณ•ๅทฅไฝœ่กจ็”Ÿๆˆๅ™จ](https://chat-preview.lobehub.com/market?agent=grammar-revision-worksheets)<br/><sup>By **[bentwnghk](https://github.com/bentwnghk)** on **2024-02-09**</sup> | ไธ“ๆณจไบŽๅˆ›ๅปบ่‹ฑ่ฏญ่ฏญๆณ•ๅญฆไน ๆๆ–™ๅ’Œ็ปƒไน <br/>`english-grammar` `worksheet` `learning` `practice` `mc-qs` |
214
-
215
- > ๐Ÿ“Š Total agents: [<kbd>**170**</kbd> ](https://github.com/lobehub/lobe-chat-agents)
208
+ | ๆœ€่ฟ‘ๆ–ฐๅขž | ๅŠฉๆ‰‹่ฏดๆ˜Ž |
209
+ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- |
210
+ | [ไบงๅ“่ฏ„ไปท](https://chat-preview.lobehub.com/market?agent=product-reviews)<br/><sup>By **[pllz7](https://github.com/pllz7)** on **2024-02-11**</sup> | ๆ“…้•ฟๆ’ฐๅ†™ๆœ‰่ฏดๆœๅŠ›็š„ไบงๅ“ๆŽจ่๏ผŒ็ชๅ‡บ \[ๆ‚จ็š„ไบงๅ“ / ๆœๅŠก] ็š„ไผ˜ๅŠฟๅ’Œไปทๅ€ผไธปๅผ ใ€‚<br/>`็”ตๅญๅ•†ๅŠก` |
211
+ | [ๅก”็ฝ—ๅ ๅœๅธˆ](https://chat-preview.lobehub.com/market?agent=augur)<br/><sup>By **[CLOT-LIU](https://github.com/CLOT-LIU)** on **2024-02-10**</sup> | ๆ“…้•ฟๅก”็ฝ—ๅ ๅœ๏ผŒไผšๅฏนๅก”็ฝ—็‰Œ่ฟ›่กŒ่งฃ่ฏป<br/>`ๅก”็ฝ—ๅ ๅœ` `่งฃ่ฏป` `ๅปบ่ฎฎ` |
212
+ | [ๆ–ฐๅนดๅฟซไน](https://chat-preview.lobehub.com/market?agent=happy-loong-year)<br/><sup>By **[canisminor1990](https://github.com/canisminor1990)** on **2024-02-10**</sup> | ้พ™ๅนดๆ‹œๅนดๅฐๅŠฉๆ‰‹๏ผŒ็ป“ๅˆไผ ็ปŸไธŽ็Žฐไปฃๅ…ƒ็ด ๏ผŒๅˆ›้€ ๆœ‰่ถฃ็š„้พ™ๅนด็ฅ็ฆ่ฏญใ€‚<br/>`ๆ‹œๅนด็ฅ็ฆ` `ๅˆ›ๆ„` `ๆ–‡ๆกˆ` `้พ™ๅนด` |
213
+ | [่ฏๆฑ‡ๅคงๅธˆ](https://chat-preview.lobehub.com/market?agent=awl-vocab-wizard)<br/><sup>By **[bentwnghk](https://github.com/bentwnghk)** on **2024-02-09**</sup> | ๆ“…้•ฟ็”Ÿๆˆ่ฏๆฑ‡ๅˆ—่กจๅ’Œๅคš้กน้€‰ๆ‹ฉๆต‹่ฏ•<br/>`่ฏๆฑ‡` `ๅญฆๆœฏ่ฏๆฑ‡่กจ` `่ฏญ่จ€ๅญฆไน ` `ๆต‹่ฏ•` |
214
+
215
+ > ๐Ÿ“Š Total agents: [<kbd>**173**</kbd> ](https://github.com/lobehub/lobe-chat-agents)
216
216
 
217
217
  <!-- AGENT LIST -->
218
218
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/chat",
3
- "version": "0.126.3",
3
+ "version": "0.126.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",
@@ -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",
@@ -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, 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
+ };
@@ -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 = ({ children, defaultLang, ...theme }: GlobalLayoutProps) => {
52
- return (
53
- <SessionProvider basePath={API_ENDPOINTS.oauth}>
54
- <AppTheme {...theme}>
55
- <Locale defaultLang={defaultLang}>
56
- <StoreHydration />
57
- <Container>{children}</Container>
58
- <DebugUI />
59
- </Locale>
60
- </AppTheme>
61
- </SessionProvider>
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
 
@@ -20,9 +20,7 @@ export class LobeMoonshotAI implements LobeRuntimeAI {
20
20
  constructor(apiKey?: string, baseURL: string = DEFAULT_BASE_URL) {
21
21
  if (!apiKey) throw AgentRuntimeError.createError(AgentRuntimeErrorType.InvalidMoonshotAPIKey);
22
22
 
23
- const header = { Authorization: `Bearer ${apiKey}` };
24
-
25
- this._llm = new OpenAI({ apiKey, baseURL, defaultHeaders: header });
23
+ this._llm = new OpenAI({ apiKey, baseURL });
26
24
  this.baseURL = this._llm.baseURL;
27
25
  }
28
26
 
package/src/middleware.ts CHANGED
@@ -1,14 +1,16 @@
1
- // export { auth as middleware } from './app/api/next-auth';
2
1
  import { NextResponse } from 'next/server';
3
2
 
3
+ import { getServerConfig } from '@/config/server';
4
+
4
5
  import { auth } from './app/api/auth/next-auth';
5
6
  import { OAUTH_AUTHORIZED } from './const/auth';
6
7
 
7
8
  export const config = {
8
9
  matcher: '/api/:path*',
9
10
  };
11
+ const defaultMiddleware = () => NextResponse.next();
10
12
 
11
- export default auth((req) => {
13
+ const withAuthMiddleware = auth((req) => {
12
14
  // Just check if session exists
13
15
  const session = req.auth;
14
16
  const isLoggedIn = !!session;
@@ -23,3 +25,7 @@ export default auth((req) => {
23
25
  },
24
26
  });
25
27
  });
28
+
29
+ const { ENABLE_OAUTH_SSO } = getServerConfig();
30
+
31
+ export default !ENABLE_OAUTH_SSO ? defaultMiddleware : withAuthMiddleware;