@lobehub/chat 1.77.7 → 1.77.8

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,39 @@
2
2
 
3
3
  # Changelog
4
4
 
5
+ ### [Version 1.77.8](https://github.com/lobehub/lobe-chat/compare/v1.77.7...v1.77.8)
6
+
7
+ <sup>Released on **2025-04-03**</sup>
8
+
9
+ #### 🐛 Bug Fixes
10
+
11
+ - **misc**: Add `SEARCH1API_CRAWL_API_KEY` env.
12
+
13
+ #### 💄 Styles
14
+
15
+ - **misc**: Auto refresh TokenTag count.
16
+
17
+ <br/>
18
+
19
+ <details>
20
+ <summary><kbd>Improvements and Fixes</kbd></summary>
21
+
22
+ #### What's fixed
23
+
24
+ - **misc**: Add `SEARCH1API_CRAWL_API_KEY` env, closes [#7270](https://github.com/lobehub/lobe-chat/issues/7270) ([85e8ff1](https://github.com/lobehub/lobe-chat/commit/85e8ff1))
25
+
26
+ #### Styles
27
+
28
+ - **misc**: Auto refresh TokenTag count, closes [#7011](https://github.com/lobehub/lobe-chat/issues/7011) ([9d62451](https://github.com/lobehub/lobe-chat/commit/9d62451))
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
+
5
38
  ### [Version 1.77.7](https://github.com/lobehub/lobe-chat/compare/v1.77.6...v1.77.7)
6
39
 
7
40
  <sup>Released on **2025-04-03**</sup>
package/changelog/v1.json CHANGED
@@ -1,4 +1,16 @@
1
1
  [
2
+ {
3
+ "children": {
4
+ "fixes": [
5
+ "Add SEARCH1API_CRAWL_API_KEY env."
6
+ ],
7
+ "improvements": [
8
+ "Auto refresh TokenTag count."
9
+ ]
10
+ },
11
+ "date": "2025-04-03",
12
+ "version": "1.77.8"
13
+ },
2
14
  {
3
15
  "children": {
4
16
  "improvements": [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/chat",
3
- "version": "1.77.7",
3
+ "version": "1.77.8",
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",
@@ -7,18 +7,20 @@ interface Search1ApiResponse {
7
7
  url: string;
8
8
  };
9
9
  results: {
10
- title?: string;
11
- link?: string;
12
10
  content?: string;
11
+ link?: string;
12
+ title?: string;
13
13
  };
14
14
  }
15
15
 
16
16
  export const search1api: CrawlImpl = async (url) => {
17
17
  // Get API key from environment variable
18
- const apiKey = process.env.SEARCH1API_API_KEY;
19
-
18
+ const apiKey = process.env.SEARCH1API_CRAWL_API_KEY || process.env.SEARCH1API_API_KEY;
19
+
20
20
  if (!apiKey) {
21
- throw new Error('SEARCH1API_API_KEY environment variable is not set. Visit https://www.search1api.com to get free quota.');
21
+ throw new Error(
22
+ 'SEARCH1API_API_KEY environment variable is not set. Visit https://www.search1api.com to get free quota.',
23
+ );
22
24
  }
23
25
 
24
26
  let res: Response;
@@ -26,14 +28,14 @@ export const search1api: CrawlImpl = async (url) => {
26
28
  try {
27
29
  res = await withTimeout(
28
30
  fetch('https://api.search1api.com/crawl', {
29
- method: 'POST',
31
+ body: JSON.stringify({
32
+ url,
33
+ }),
30
34
  headers: {
31
35
  'Authorization': `Bearer ${apiKey}`,
32
36
  'Content-Type': 'application/json',
33
37
  },
34
- body: JSON.stringify({
35
- url,
36
- }),
38
+ method: 'POST',
37
39
  }),
38
40
  DEFAULT_TIMEOUT,
39
41
  );
@@ -54,30 +56,31 @@ export const search1api: CrawlImpl = async (url) => {
54
56
  if (res.status === 404) {
55
57
  throw new PageNotFoundError(res.statusText);
56
58
  }
57
-
59
+
58
60
  throw new Error(`Search1API request failed with status ${res.status}: ${res.statusText}`);
59
61
  }
60
62
 
61
63
  try {
62
- const data = await res.json() as Search1ApiResponse;
63
-
64
+ const data = (await res.json()) as Search1ApiResponse;
65
+
64
66
  // Check if content is empty or too short
65
67
  if (!data.results.content || data.results.content.length < 100) {
66
68
  return;
67
69
  }
68
-
70
+
69
71
  return {
70
72
  content: data.results.content,
71
73
  contentType: 'text',
72
- title: data.results.title,
73
- description: data.results.title, // Using title as description since API doesn't provide a separate description
74
+ description: data.results.title,
75
+ // Using title as description since API doesn't provide a separate description
74
76
  length: data.results.content.length,
75
77
  siteName: new URL(url).hostname,
78
+ title: data.results.title,
76
79
  url: data.results.link || url,
77
80
  } satisfies CrawlSuccessResult;
78
81
  } catch (error) {
79
82
  console.error(error);
80
83
  }
81
-
84
+
82
85
  return;
83
- };
86
+ };
@@ -2,7 +2,7 @@ import { TokenTag, Tooltip } from '@lobehub/ui';
2
2
  import { Popover } from 'antd';
3
3
  import { useTheme } from 'antd-style';
4
4
  import numeral from 'numeral';
5
- import { memo } from 'react';
5
+ import { memo, useMemo } from 'react';
6
6
  import { useTranslation } from 'react-i18next';
7
7
  import { Center, Flexbox } from 'react-layout-kit';
8
8
 
@@ -12,7 +12,7 @@ import { useTokenCount } from '@/hooks/useTokenCount';
12
12
  import { useAgentStore } from '@/store/agent';
13
13
  import { agentChatConfigSelectors, agentSelectors } from '@/store/agent/selectors';
14
14
  import { useChatStore } from '@/store/chat';
15
- import { topicSelectors } from '@/store/chat/selectors';
15
+ import { chatSelectors, topicSelectors } from '@/store/chat/selectors';
16
16
  import { useToolStore } from '@/store/tool';
17
17
  import { toolSelectors } from '@/store/tool/selectors';
18
18
 
@@ -41,6 +41,11 @@ const Token = memo<TokenTagProps>(({ total: messageString }) => {
41
41
  ];
42
42
  });
43
43
 
44
+ const [historyCount, enableHistoryCount] = useAgentStore((s) => [
45
+ agentChatConfigSelectors.historyCount(s),
46
+ agentChatConfigSelectors.enableHistoryCount(s),
47
+ ]);
48
+
44
49
  const maxTokens = useModelContextWindowTokens(model, provider);
45
50
 
46
51
  // Tool usage token
@@ -60,7 +65,12 @@ const Token = memo<TokenTagProps>(({ total: messageString }) => {
60
65
  // Chat usage token
61
66
  const inputTokenCount = useTokenCount(input);
62
67
 
63
- const chatsToken = useTokenCount(messageString) + inputTokenCount;
68
+ const chatsString = useMemo(() => {
69
+ const chats = chatSelectors.mainAIChatsWithHistoryConfig(useChatStore.getState());
70
+ return chats.map(chat => chat.content).join('');
71
+ }, [messageString, historyCount, enableHistoryCount]);
72
+
73
+ const chatsToken = useTokenCount(chatsString) + inputTokenCount;
64
74
 
65
75
  // SystemRole token
66
76
  const systemRoleToken = useTokenCount(systemRole);