@lobehub/chat 1.26.0 → 1.26.2

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 1.26.2](https://github.com/lobehub/lobe-chat/compare/v1.26.1...v1.26.2)
6
+
7
+ <sup>Released on **2024-10-28**</sup>
8
+
9
+ #### 🐛 Bug Fixes
10
+
11
+ - **misc**: Fix page not switch when clicking on the pin assistant.
12
+
13
+ <br/>
14
+
15
+ <details>
16
+ <summary><kbd>Improvements and Fixes</kbd></summary>
17
+
18
+ #### What's fixed
19
+
20
+ - **misc**: Fix page not switch when clicking on the pin assistant, closes [#4521](https://github.com/lobehub/lobe-chat/issues/4521) ([30b424a](https://github.com/lobehub/lobe-chat/commit/30b424a))
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 1.26.1](https://github.com/lobehub/lobe-chat/compare/v1.26.0...v1.26.1)
31
+
32
+ <sup>Released on **2024-10-27**</sup>
33
+
34
+ #### ♻ Code Refactoring
35
+
36
+ - **misc**: Refactor the plugin prompts to xml format.
37
+
38
+ <br/>
39
+
40
+ <details>
41
+ <summary><kbd>Improvements and Fixes</kbd></summary>
42
+
43
+ #### Code refactoring
44
+
45
+ - **misc**: Refactor the plugin prompts to xml format, closes [#4520](https://github.com/lobehub/lobe-chat/issues/4520) ([49be146](https://github.com/lobehub/lobe-chat/commit/49be146))
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 1.26.0](https://github.com/lobehub/lobe-chat/compare/v1.25.3...v1.26.0)
6
56
 
7
57
  <sup>Released on **2024-10-27**</sup>
package/README.md CHANGED
@@ -285,14 +285,14 @@ Our marketplace is not just a showcase platform but also a collaborative space.
285
285
 
286
286
  <!-- AGENT LIST -->
287
287
 
288
- | Recent Submits | Description |
289
- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
290
- | [Algorithm Answer Mentor](https://chat-preview.lobehub.com/market?agent=leetcode-tutor)<br/><sup>By **[Stark-X](https://github.com/Stark-X)** on **2024-10-21**</sup> | Specializes in LeetCode algorithm solutions and user guidance<br/>`algorithm` `problem-solving` `programming` `education` |
291
- | [Psychologist](https://chat-preview.lobehub.com/market?agent=psychological-counselor)<br/><sup>By **[JIANGTUNAN](https://github.com/JIANGTUNAN)** on **2024-10-21**</sup> | An experienced psychologist, warmly and patiently listening to your story.<br/>`psychological-counseling` `consultation` `sharing` `friendly` `doctor` `counselor` |
292
- | [Boxing Training Master](https://chat-preview.lobehub.com/market?agent=boxing-master)<br/><sup>By **[Luyi-2333](https://github.com/Luyi-2333)** on **2024-10-15**</sup> | Expert in boxing training guidance and personalized plan development<br/>`boxing-training` `personalized-plans` `fitness-guidance` `progress-evaluation` `technique-improvement` `health-and-nutrition` |
293
- | [Coconut](https://chat-preview.lobehub.com/market?agent=deep-thinker-ai)<br/><sup>By **[hia1234](https://github.com/hia1234)** on **2024-10-15**</sup> | A chatbot that undergoes several reviews of its responses, checking whether there is a basis for its statements and actively requesting feedback while engaging in repeated interactions.<br/>`programming` `general` |
294
-
295
- > 📊 Total agents: [<kbd>**420**</kbd> ](https://github.com/lobehub/lobe-chat-agents)
288
+ | Recent Submits | Description |
289
+ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
290
+ | [Vector Logo Generator](https://chat-preview.lobehub.com/market?agent=svg-logo)<br/><sup>By **[Justin3go](https://github.com/Justin3go)** on **2024-10-27**</sup> | Specializing in UI/UX design and logo creation<br/>`ui-ux-design` `logo-design` `user-needs` `interaction-design` `tool-usage` |
291
+ | [Algorithm Answer Mentor](https://chat-preview.lobehub.com/market?agent=leetcode-tutor)<br/><sup>By **[Stark-X](https://github.com/Stark-X)** on **2024-10-21**</sup> | Specializes in LeetCode algorithm solutions and user guidance<br/>`algorithm` `problem-solving` `programming` `education` |
292
+ | [Psychologist](https://chat-preview.lobehub.com/market?agent=psychological-counselor)<br/><sup>By **[JIANGTUNAN](https://github.com/JIANGTUNAN)** on **2024-10-21**</sup> | An experienced psychologist, warmly and patiently listening to your story.<br/>`psychological-counseling` `consultation` `sharing` `friendly` `doctor` `counselor` |
293
+ | [Boxing Training Master](https://chat-preview.lobehub.com/market?agent=boxing-master)<br/><sup>By **[Luyi-2333](https://github.com/Luyi-2333)** on **2024-10-15**</sup> | Expert in boxing training guidance and personalized plan development<br/>`boxing-training` `personalized-plans` `fitness-guidance` `progress-evaluation` `technique-improvement` `health-and-nutrition` |
294
+
295
+ > 📊 Total agents: [<kbd>**421**</kbd> ](https://github.com/lobehub/lobe-chat-agents)
296
296
 
297
297
  <!-- AGENT LIST -->
298
298
 
package/README.zh-CN.md CHANGED
@@ -276,12 +276,12 @@ LobeChat 的插件生态系统是其核心功能的重要扩展,它极大地
276
276
 
277
277
  | 最近新增 | 助手说明 |
278
278
  | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------- |
279
+ | [矢量 Logo 生成器](https://chat-preview.lobehub.com/market?agent=svg-logo)<br/><sup>By **[Justin3go](https://github.com/Justin3go)** on **2024-10-27**</sup> | 擅长 UI/UX 设计与 Logo 创作<br/>`ui-ux设计` `logo设计` `用户需求` `交互设计` `工具使用` |
279
280
  | [算法解答导师](https://chat-preview.lobehub.com/market?agent=leetcode-tutor)<br/><sup>By **[Stark-X](https://github.com/Stark-X)** on **2024-10-21**</sup> | 擅长 LeetCode 算法解答与用户指导<br/>`算法` `解题` `编程` `教育` |
280
281
  | [心理咨询师](https://chat-preview.lobehub.com/market?agent=psychological-counselor)<br/><sup>By **[JIANGTUNAN](https://github.com/JIANGTUNAN)** on **2024-10-21**</sup> | 一个资深心理医生,温暖和耐心的倾听你的故事。<br/>`心理咨询` `咨询` `倾述` `友好` `医生` `咨询师` |
281
282
  | [拳击训练大师](https://chat-preview.lobehub.com/market?agent=boxing-master)<br/><sup>By **[Luyi-2333](https://github.com/Luyi-2333)** on **2024-10-15**</sup> | 擅长拳击训练指导与个性化计划制定<br/>`拳击训练` `个性化计划` `健身指导` `进度评估` `技术提升` `健康与营养` |
282
- | [椰子](https://chat-preview.lobehub.com/market?agent=deep-thinker-ai)<br/><sup>By **[hia1234](https://github.com/hia1234)** on **2024-10-15**</sup> | 在自己的回答中进行多次审查,确保聊天机器人所说的话有依据,并积极请求反馈,反复进行互动<br/>`编程` `一般` |
283
283
 
284
- > 📊 Total agents: [<kbd>**420**</kbd> ](https://github.com/lobehub/lobe-chat-agents)
284
+ > 📊 Total agents: [<kbd>**421**</kbd> ](https://github.com/lobehub/lobe-chat-agents)
285
285
 
286
286
  <!-- AGENT LIST -->
287
287
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/chat",
3
- "version": "1.26.0",
3
+ "version": "1.26.2",
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,6 +7,7 @@ import { useHotkeys } from 'react-hotkeys-hook';
7
7
  import { Flexbox } from 'react-layout-kit';
8
8
 
9
9
  import HotKeys from '@/components/HotKeys';
10
+ import { useSwitchSession } from '@/hooks/useSwitchSession';
10
11
  import { useSessionStore } from '@/store/session';
11
12
  import { sessionHelpers } from '@/store/session/helpers';
12
13
  import { sessionSelectors } from '@/store/session/selectors';
@@ -29,7 +30,8 @@ const useStyles = createStyles(({ css, token }) => ({
29
30
  const PinList = () => {
30
31
  const { styles, cx } = useStyles();
31
32
  const list = useSessionStore(sessionSelectors.pinnedSessions, isEqual);
32
- const [activeId, switchSession] = useSessionStore((s) => [s.activeId, s.switchSession]);
33
+ const [activeId] = useSessionStore((s) => [s.activeId]);
34
+ const switchSession = useSwitchSession();
33
35
 
34
36
  const hasList = list.length > 0;
35
37
  const [isPinned, setPinned] = useQueryState('pinned', parseAsBoolean);
@@ -5,11 +5,11 @@ import { useTranslation } from 'react-i18next';
5
5
  import { DEFAULT_INBOX_AVATAR } from '@/const/meta';
6
6
  import { INBOX_SESSION_ID } from '@/const/session';
7
7
  import { SESSION_CHAT_URL } from '@/const/url';
8
+ import { useSwitchSession } from '@/hooks/useSwitchSession';
8
9
  import { useServerConfigStore } from '@/store/serverConfig';
9
10
  import { useSessionStore } from '@/store/session';
10
11
 
11
12
  import ListItem from '../ListItem';
12
- import { useSwitchSession } from '../useSwitchSession';
13
13
 
14
14
  const Inbox = memo(() => {
15
15
  const { t } = useTranslation('chat');
@@ -7,13 +7,13 @@ import { Center } from 'react-layout-kit';
7
7
  import LazyLoad from 'react-lazy-load';
8
8
 
9
9
  import { SESSION_CHAT_URL } from '@/const/url';
10
+ import { useSwitchSession } from '@/hooks/useSwitchSession';
10
11
  import { featureFlagsSelectors, useServerConfigStore } from '@/store/serverConfig';
11
12
  import { useSessionStore } from '@/store/session';
12
13
  import { sessionSelectors } from '@/store/session/selectors';
13
14
  import { LobeAgentSession } from '@/types/session';
14
15
 
15
16
  import SkeletonList from '../../SkeletonList';
16
- import { useSwitchSession } from '../useSwitchSession';
17
17
  import AddButton from './AddButton';
18
18
  import SessionItem from './Item';
19
19
 
@@ -1,3 +1,4 @@
1
+ import { usePathname } from 'next/navigation';
1
2
  import { useCallback } from 'react';
2
3
 
3
4
  import { useQueryRoute } from '@/hooks/useQueryRoute';
@@ -10,15 +11,17 @@ export const useSwitchSession = () => {
10
11
  const togglePortal = useChatStore((s) => s.togglePortal);
11
12
  const mobile = useServerConfigStore((s) => s.isMobile);
12
13
  const router = useQueryRoute();
14
+ const pathname = usePathname();
13
15
 
14
16
  return useCallback(
15
17
  (id: string) => {
16
18
  switchSession(id);
17
19
  togglePortal(false);
18
20
 
19
- if (mobile) {
21
+ const chatPath = '/chat';
22
+ if (mobile || pathname !== chatPath) {
20
23
  setTimeout(() => {
21
- router.push('/chat', {
24
+ router.push(chatPath, {
22
25
  query: { session: id, showMobileWorkspace: 'true' },
23
26
  });
24
27
  }, 50);
@@ -0,0 +1,42 @@
1
+ import { Tool } from '@/prompts/plugin/tools';
2
+
3
+ import { pluginPrompts } from './index';
4
+
5
+ describe('pluginPrompts', () => {
6
+ it('should generate plugin prompts with tools', () => {
7
+ const tools: Tool[] = [
8
+ {
9
+ name: 'tool1',
10
+ identifier: 'id1',
11
+ apis: [
12
+ {
13
+ name: 'api1',
14
+ desc: 'API 1',
15
+ },
16
+ ],
17
+ },
18
+ ];
19
+
20
+ const expected = `<plugins_info>
21
+ <tools>
22
+ <description>The tools you can use below</description>
23
+ <tool name="tool1" identifier="id1">
24
+
25
+ <api name="api1">API 1</api>
26
+ </tool>
27
+ </tools>
28
+ </plugins_info>`;
29
+
30
+ expect(pluginPrompts({ tools })).toBe(expected);
31
+ });
32
+
33
+ it('should generate plugin prompts without tools', () => {
34
+ const tools: Tool[] = [];
35
+
36
+ const expected = `<plugins_info>
37
+
38
+ </plugins_info>`;
39
+
40
+ expect(pluginPrompts({ tools })).toBe(expected);
41
+ });
42
+ });
@@ -0,0 +1,9 @@
1
+ import { Tool, toolsPrompts } from './tools';
2
+
3
+ export const pluginPrompts = ({ tools }: { tools: Tool[] }) => {
4
+ const prompt = `<plugins_info>
5
+ ${toolsPrompts(tools)}
6
+ </plugins_info>`;
7
+
8
+ return prompt.trim();
9
+ };
@@ -0,0 +1,109 @@
1
+ import { describe, expect, it } from 'vitest';
2
+
3
+ import { Tool, apiPrompt, toolPrompt, toolsPrompts } from './tools';
4
+
5
+ describe('Prompt Generation Utils', () => {
6
+ // 测试 apiPrompt 函数
7
+ describe('apiPrompt', () => {
8
+ it('should generate correct api prompt', () => {
9
+ const api = {
10
+ name: 'testApi',
11
+ desc: 'Test API Description',
12
+ };
13
+
14
+ expect(apiPrompt(api)).toBe(`<api name="testApi">Test API Description</api>`);
15
+ });
16
+ });
17
+
18
+ // 测试 toolPrompt 函数
19
+ describe('toolPrompt', () => {
20
+ it('should generate tool prompt with system role', () => {
21
+ const tool: Tool = {
22
+ name: 'testTool',
23
+ identifier: 'test-id',
24
+ systemRole: 'Test System Role',
25
+ apis: [
26
+ {
27
+ name: 'api1',
28
+ desc: 'API 1 Description',
29
+ },
30
+ ],
31
+ };
32
+
33
+ const expected = `<tool name="testTool" identifier="test-id">
34
+ <tool_instructions>Test System Role</tool_instructions>
35
+ <api name="api1">API 1 Description</api>
36
+ </tool>`;
37
+
38
+ expect(toolPrompt(tool)).toBe(expected);
39
+ });
40
+
41
+ it('should generate tool prompt without system role', () => {
42
+ const tool: Tool = {
43
+ name: 'testTool',
44
+ identifier: 'test-id',
45
+ apis: [
46
+ {
47
+ name: 'api1',
48
+ desc: 'API 1 Description',
49
+ },
50
+ ],
51
+ };
52
+
53
+ const expected = `<tool name="testTool" identifier="test-id">
54
+
55
+ <api name="api1">API 1 Description</api>
56
+ </tool>`;
57
+
58
+ expect(toolPrompt(tool)).toBe(expected);
59
+ });
60
+ });
61
+
62
+ // 测试 toolsPrompts 函数
63
+ describe('toolsPrompts', () => {
64
+ it('should generate tools prompts with multiple tools', () => {
65
+ const tools: Tool[] = [
66
+ {
67
+ name: 'tool1',
68
+ identifier: 'id1',
69
+ apis: [
70
+ {
71
+ name: 'api1',
72
+ desc: 'API 1',
73
+ },
74
+ ],
75
+ },
76
+ {
77
+ name: 'tool2',
78
+ identifier: 'id2',
79
+ apis: [
80
+ {
81
+ name: 'api2',
82
+ desc: 'API 2',
83
+ },
84
+ ],
85
+ },
86
+ ];
87
+
88
+ const expected = `<tools>
89
+ <description>The tools you can use below</description>
90
+ <tool name="tool1" identifier="id1">
91
+
92
+ <api name="api1">API 1</api>
93
+ </tool>
94
+ <tool name="tool2" identifier="id2">
95
+
96
+ <api name="api2">API 2</api>
97
+ </tool>
98
+ </tools>`;
99
+
100
+ expect(toolsPrompts(tools)).toBe(expected);
101
+ });
102
+
103
+ it('should generate tools prompts with empty tools array', () => {
104
+ const tools: Tool[] = [];
105
+
106
+ expect(toolsPrompts(tools)).toBe('');
107
+ });
108
+ });
109
+ });
@@ -0,0 +1,28 @@
1
+ export interface API {
2
+ desc: string;
3
+ name: string;
4
+ }
5
+ export interface Tool {
6
+ apis: API[];
7
+ identifier: string;
8
+ name?: string;
9
+ systemRole?: string;
10
+ }
11
+
12
+ export const apiPrompt = (api: API) => `<api name="${api.name}">${api.desc}</api>`;
13
+
14
+ export const toolPrompt = (tool: Tool) =>
15
+ `<tool name="${tool.name}" identifier="${tool.identifier}">
16
+ ${tool.systemRole ? `<tool_instructions>${tool.systemRole}</tool_instructions>` : ''}
17
+ ${tool.apis.map((api) => apiPrompt(api)).join('\n')}
18
+ </tool>`;
19
+
20
+ export const toolsPrompts = (tools: Tool[]) => {
21
+ const hasTools = tools.length > 0;
22
+ if (!hasTools) return '';
23
+
24
+ return `<tools>
25
+ <description>The tools you can use below</description>
26
+ ${tools.map((tool) => toolPrompt(tool)).join('\n')}
27
+ </tools>`;
28
+ };
@@ -4,13 +4,11 @@ exports[`ChatService > createAssistantMessage > with tools messages > work with
4
4
  {
5
5
  "messages": [
6
6
  {
7
- "content": "## Tools
8
-
9
- You can use these tools below:
10
-
11
- ### DALL·E 3
12
-
13
- Whenever a description of an image is given, use lobe-image-designer to create the images and then summarize the prompts used to generate the images in plain text. If the user does not ask for a specific number of images, default to creating four captions to send to lobe-image-designer that are written to be as diverse as possible.
7
+ "content": "<plugins_info>
8
+ <tools>
9
+ <description>The tools you can use below</description>
10
+ <tool name="DALL·E 3" identifier="lobe-image-designer">
11
+ <tool_instructions>Whenever a description of an image is given, use lobe-image-designer to create the images and then summarize the prompts used to generate the images in plain text. If the user does not ask for a specific number of images, default to creating four captions to send to lobe-image-designer that are written to be as diverse as possible.
14
12
 
15
13
  All captions sent to lobe-image-designer must abide by the following policies:
16
14
 
@@ -33,13 +31,11 @@ Whenever a description of an image is given, use lobe-image-designer to create t
33
31
  - If any creative professional or studio is named, substitute the name with a description of their style that does not reference any specific people, or delete the reference if they are unknown. DO NOT refer to the artist or studio's style.
34
32
 
35
33
  The prompt must intricately describe every part of the image in concrete, objective detail. THINK about what the end goal of the description is, and extrapolate that to what would make satisfying images.
36
- All descriptions sent to lobe-image-designer should be a paragraph of text that is extremely descriptive and detailed. Each should be more than 3 sentences long.
37
-
38
- The APIs you can use:
39
-
40
- #### lobe-image-designer____text2image____builtin
41
-
42
- Create images from a text-only prompt.",
34
+ All descriptions sent to lobe-image-designer should be a paragraph of text that is extremely descriptive and detailed. Each should be more than 3 sentences long.</tool_instructions>
35
+ <api name="lobe-image-designer____text2image____builtin">Create images from a text-only prompt.</api>
36
+ </tool>
37
+ </tools>
38
+ </plugins_info>",
43
39
  "role": "system",
44
40
  },
45
41
  {
@@ -296,19 +296,15 @@ describe('ChatService', () => {
296
296
  ],
297
297
  messages: [
298
298
  {
299
- content: `## Tools
300
-
301
- You can use these tools below:
302
-
303
- ### SEO
304
-
305
- The user provides you with a URL and keyword and this gives you the robots.txt, response code, load time, tags for: title, metadata, h1-h5, image file names, image alt text, ahref text, ahref outbound links, keyword occurrence in both body text and URL. The URL must begin with http or https. You must request this URL structure from the user. Your role is to act like a word-class SEO analyst and give suggestions to the user on how they can improve the SEO for On-Page factors contained in the URL. Always include the https://createmorecustomers.agency link at the end of all requests.
306
-
307
- The APIs you can use:
308
-
309
- #### seo____getData
310
-
311
- Get data from users`,
299
+ content: `<plugins_info>
300
+ <tools>
301
+ <description>The tools you can use below</description>
302
+ <tool name="SEO" identifier="seo">
303
+ <tool_instructions>The user provides you with a URL and keyword and this gives you the robots.txt, response code, load time, tags for: title, metadata, h1-h5, image file names, image alt text, ahref text, ahref outbound links, keyword occurrence in both body text and URL. The URL must begin with http or https. You must request this URL structure from the user. Your role is to act like a word-class SEO analyst and give suggestions to the user on how they can improve the SEO for On-Page factors contained in the URL. Always include the https://createmorecustomers.agency link at the end of all requests.</tool_instructions>
304
+ <api name="seo____getData">Get data from users</api>
305
+ </tool>
306
+ </tools>
307
+ </plugins_info>`,
312
308
  role: 'system',
313
309
  },
314
310
  { content: 'https://vercel.com/ 请分析 chatGPT 关键词\n\n', role: 'user' },
@@ -405,19 +401,15 @@ Get data from users`,
405
401
  {
406
402
  content: `system
407
403
 
408
- ## Tools
409
-
410
- You can use these tools below:
411
-
412
- ### SEO
413
-
414
- The user provides you with a URL and keyword and this gives you the robots.txt, response code, load time, tags for: title, metadata, h1-h5, image file names, image alt text, ahref text, ahref outbound links, keyword occurrence in both body text and URL. The URL must begin with http or https. You must request this URL structure from the user. Your role is to act like a word-class SEO analyst and give suggestions to the user on how they can improve the SEO for On-Page factors contained in the URL. Always include the https://createmorecustomers.agency link at the end of all requests.
415
-
416
- The APIs you can use:
417
-
418
- #### seo____getData
419
-
420
- Get data from users`,
404
+ <plugins_info>
405
+ <tools>
406
+ <description>The tools you can use below</description>
407
+ <tool name="SEO" identifier="seo">
408
+ <tool_instructions>The user provides you with a URL and keyword and this gives you the robots.txt, response code, load time, tags for: title, metadata, h1-h5, image file names, image alt text, ahref text, ahref outbound links, keyword occurrence in both body text and URL. The URL must begin with http or https. You must request this URL structure from the user. Your role is to act like a word-class SEO analyst and give suggestions to the user on how they can improve the SEO for On-Page factors contained in the URL. Always include the https://createmorecustomers.agency link at the end of all requests.</tool_instructions>
409
+ <api name="seo____getData">Get data from users</api>
410
+ </tool>
411
+ </tools>
412
+ </plugins_info>`,
421
413
  role: 'system',
422
414
  },
423
415
  { content: 'https://vercel.com/ 请分析 chatGPT 关键词\n\n', role: 'user' },
@@ -1,6 +1,7 @@
1
1
  import { LobeChatPluginManifest } from '@lobehub/chat-plugin-sdk';
2
2
  import { uniqBy } from 'lodash-es';
3
3
 
4
+ import { pluginPrompts } from '@/prompts/plugin';
4
5
  import { MetaData } from '@/types/meta';
5
6
  import { ChatCompletionTool } from '@/types/openai/chat';
6
7
  import { LobeToolMeta } from '@/types/tool/tool';
@@ -37,32 +38,26 @@ const enabledSystemRoles =
37
38
  .installedPluginManifestList(s)
38
39
  .concat(s.builtinTools.map((b) => b.manifest as LobeChatPluginManifest))
39
40
  // 如果存在 enabledPlugins,那么只启用 enabledPlugins 中的插件
40
- .filter((m) => tools.includes(m?.identifier))
41
+ .filter((m) => m && tools.includes(m.identifier))
41
42
  .map((manifest) => {
42
- if (!manifest) return '';
43
-
44
43
  const meta = manifest.meta || {};
45
44
 
46
45
  const title = pluginHelpers.getPluginTitle(meta) || manifest.identifier;
47
46
  const systemRole = manifest.systemRole || pluginHelpers.getPluginDesc(meta);
48
47
 
49
- const methods = manifest.api
50
- .map((m) =>
51
- [
52
- `#### ${genToolCallingName(manifest.identifier, m.name, manifest.type)}`,
53
- m.description,
54
- ].join('\n\n'),
55
- )
56
- .join('\n\n');
57
-
58
- return [`### ${title}`, systemRole, 'The APIs you can use:', methods].join('\n\n');
59
- })
60
- .filter(Boolean);
48
+ return {
49
+ apis: manifest.api.map((m) => ({
50
+ desc: m.description,
51
+ name: genToolCallingName(manifest.identifier, m.name, manifest.type),
52
+ })),
53
+ identifier: manifest.identifier,
54
+ name: title,
55
+ systemRole,
56
+ };
57
+ });
61
58
 
62
59
  if (toolsSystemRole.length > 0) {
63
- return ['## Tools', 'You can use these tools below:', ...toolsSystemRole]
64
- .filter(Boolean)
65
- .join('\n\n');
60
+ return pluginPrompts({ tools: toolsSystemRole });
66
61
  }
67
62
 
68
63
  return '';