@lobehub/chat 0.159.7 β†’ 0.159.9

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,56 @@
2
2
 
3
3
  # Changelog
4
4
 
5
+ ### [Version 0.159.9](https://github.com/lobehub/lobe-chat/compare/v0.159.8...v0.159.9)
6
+
7
+ <sup>Released on **2024-05-14**</sup>
8
+
9
+ #### πŸ› Bug Fixes
10
+
11
+ - **misc**: Fix agent config on page init.
12
+
13
+ <br/>
14
+
15
+ <details>
16
+ <summary><kbd>Improvements and Fixes</kbd></summary>
17
+
18
+ #### What's fixed
19
+
20
+ - **misc**: Fix agent config on page init, closes [#2506](https://github.com/lobehub/lobe-chat/issues/2506) ([90e742d](https://github.com/lobehub/lobe-chat/commit/90e742d))
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
+
30
+ ### [Version 0.159.8](https://github.com/lobehub/lobe-chat/compare/v0.159.7...v0.159.8)
31
+
32
+ <sup>Released on **2024-05-14**</sup>
33
+
34
+ #### πŸ› Bug Fixes
35
+
36
+ - **misc**: Fix retry issue when hide page.
37
+
38
+ <br/>
39
+
40
+ <details>
41
+ <summary><kbd>Improvements and Fixes</kbd></summary>
42
+
43
+ #### What's fixed
44
+
45
+ - **misc**: Fix retry issue when hide page, closes [#2503](https://github.com/lobehub/lobe-chat/issues/2503) ([24489bc](https://github.com/lobehub/lobe-chat/commit/24489bc))
46
+
47
+ </details>
48
+
49
+ <div align="right">
50
+
51
+ [![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)
52
+
53
+ </div>
54
+
5
55
  ### [Version 0.159.7](https://github.com/lobehub/lobe-chat/compare/v0.159.6...v0.159.7)
6
56
 
7
57
  <sup>Released on **2024-05-14**</sup>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/chat",
3
- "version": "0.159.7",
3
+ "version": "0.159.9",
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",
@@ -1,30 +1,10 @@
1
- import { useEffect } from 'react';
2
-
3
1
  import { useAgentStore } from '@/store/agent';
4
- import { useChatStore } from '@/store/chat';
5
2
  import { useSessionStore } from '@/store/session';
6
3
 
7
4
  export const useInitAgentConfig = () => {
8
5
  const [useFetchAgentConfig] = useAgentStore((s) => [s.useFetchAgentConfig]);
9
6
 
10
- const [switchTopic] = useChatStore((s) => [s.switchTopic]);
11
7
  const [sessionId] = useSessionStore((s) => [s.activeId]);
12
8
 
13
- useEffect(() => {
14
- // // when activeId changed, switch topic to undefined
15
- const unsubscribe = useSessionStore.subscribe(
16
- (s) => s.activeId,
17
- (activeId) => {
18
- switchTopic();
19
-
20
- useAgentStore.setState({ activeId }, false, 'updateActiveId');
21
- },
22
- );
23
-
24
- return () => {
25
- unsubscribe();
26
- };
27
- }, []);
28
-
29
9
  return useFetchAgentConfig(sessionId);
30
10
  };
@@ -1,32 +1,35 @@
1
1
  'use client';
2
2
 
3
- import { useResponsive } from 'antd-style';
4
3
  import { useQueryState } from 'nuqs';
5
4
  import { parseAsString } from 'nuqs/server';
6
5
  import { memo, useEffect } from 'react';
7
6
  import { createStoreUpdater } from 'zustand-utils';
8
7
 
8
+ import { useAgentStore } from '@/store/agent';
9
+ import { useChatStore } from '@/store/chat';
9
10
  import { useSessionStore } from '@/store/session';
10
11
 
11
12
  // sync outside state to useSessionStore
12
13
  const SessionHydration = memo(() => {
13
14
  const useStoreUpdater = createStoreUpdater(useSessionStore);
14
-
15
- // TODO: εŽι’θ€ƒθ™‘ε―δ»₯εˆ ι™€δΊ†οΌŒη”¨ useServerConfigStore ε°±δΈιœ€θ¦ε†θΏ™ι‡Œζ³¨ε…₯δΊ†
16
- const { mobile } = useResponsive();
17
- useStoreUpdater('isMobile', mobile);
15
+ const useAgentStoreUpdater = createStoreUpdater(useAgentStore);
16
+ const [switchTopic] = useChatStore((s) => [s.switchTopic]);
18
17
 
19
18
  // two-way bindings the url and session store
20
19
  const [session, setSession] = useQueryState(
21
20
  'session',
22
- parseAsString.withDefault('inbox').withOptions({ history: 'replace', throttleMs: 500 }),
21
+ parseAsString.withDefault('inbox').withOptions({ history: 'replace', throttleMs: 50 }),
23
22
  );
24
23
  useStoreUpdater('activeId', session);
24
+ useAgentStoreUpdater('activeId', session);
25
25
 
26
26
  useEffect(() => {
27
27
  const unsubscribe = useSessionStore.subscribe(
28
28
  (s) => s.activeId,
29
- (state) => setSession(state),
29
+ (state) => {
30
+ switchTopic();
31
+ setSession(state);
32
+ },
30
33
  );
31
34
 
32
35
  return () => {
@@ -3,7 +3,7 @@ import { App, Button, Typography } from 'antd';
3
3
  import isEqual from 'fast-deep-equal';
4
4
  import { startCase } from 'lodash-es';
5
5
  import { useRouter } from 'next/navigation';
6
- import { memo } from 'react';
6
+ import { memo, useState } from 'react';
7
7
  import { useTranslation } from 'react-i18next';
8
8
  import { Center, Flexbox } from 'react-layout-kit';
9
9
 
@@ -23,7 +23,7 @@ const Header = memo(() => {
23
23
  const { styles } = useStyles();
24
24
  const createSession = useSessionStore((s) => s.createSession);
25
25
  const agentItem = useMarketStore(agentMarketSelectors.currentAgentItem, isEqual);
26
-
26
+ const [isLoading, setIsLoading] = useState(false);
27
27
  const { message } = App.useApp();
28
28
 
29
29
  const { meta, createAt, author, homepage, config } = agentItem;
@@ -34,15 +34,19 @@ const Header = memo(() => {
34
34
  const handleAddAgentAndConverse = async () => {
35
35
  if (!agentItem) return;
36
36
 
37
+ setIsLoading(true);
37
38
  const session = await createSession({ config, meta });
39
+ setIsLoading(false);
38
40
  message.success(t('addAgentSuccess'));
39
41
  router.push(SESSION_CHAT_URL(session, isMobile));
40
42
  };
41
43
 
42
- const handleAddAgent = () => {
44
+ const handleAddAgent = async () => {
43
45
  if (!agentItem) return;
46
+ setIsLoading(true);
44
47
  createSession({ config, meta }, false);
45
48
  message.success(t('addAgentSuccess'));
49
+ setIsLoading(false);
46
50
  };
47
51
 
48
52
  return (
@@ -56,10 +60,10 @@ const Header = memo(() => {
56
60
  ))}
57
61
  </Center>
58
62
  <div className={styles.desc}>{description}</div>
59
- <Button block onClick={handleAddAgentAndConverse} type={'primary'}>
63
+ <Button block loading={isLoading} onClick={handleAddAgentAndConverse} type={'primary'}>
60
64
  {t('addAgentAndConverse')}
61
65
  </Button>
62
- <Button block onClick={handleAddAgent}>
66
+ <Button block loading={isLoading} onClick={handleAddAgent}>
63
67
  {t('addAgent')}
64
68
  </Button>
65
69
  <Flexbox align={'center'} gap={12} horizontal>
@@ -101,9 +101,6 @@ describe('SessionAction', () => {
101
101
  expect(call[1]).toMatchObject({ config: { displayMode: 'docs' } });
102
102
 
103
103
  expect(createdSessionId).toBe(newSessionId);
104
- expect(mockRouterPush).not.toHaveBeenCalledWith(
105
- SESSION_CHAT_URL(newSessionId, result.current.isMobile),
106
- );
107
104
  });
108
105
  });
109
106
 
@@ -8,7 +8,6 @@ export interface SessionState {
8
8
  activeId: string;
9
9
  customSessionGroups: CustomSessionGroup[];
10
10
  defaultSessions: LobeAgentSession[];
11
- isMobile?: boolean;
12
11
  isSearching: boolean;
13
12
  isSessionsFirstFetchFinished: boolean;
14
13
  pinnedSessions: LobeAgentSession[];
@@ -25,7 +24,6 @@ export const initialSessionState: SessionState = {
25
24
  activeId: 'inbox',
26
25
  customSessionGroups: [],
27
26
  defaultSessions: [],
28
- isMobile: false,
29
27
  isSearching: false,
30
28
  isSessionsFirstFetchFinished: false,
31
29
  pinnedSessions: [],
@@ -363,7 +363,9 @@ export const fetchSSE = async (url: string, options: RequestInit & FetchSSEOptio
363
363
  return;
364
364
  }
365
365
  },
366
-
366
+ // we should keep open when page hidden, or it will case lots of token cost
367
+ // refs: https://github.com/lobehub/lobe-chat/issues/2501
368
+ openWhenHidden: true,
367
369
  signal: options.signal,
368
370
  });
369
371
  } catch {}