@lobehub/chat 0.115.8 β 0.115.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 +26 -0
- package/locales/zh-TW/common.json +1 -1
- package/package.json +1 -1
- package/src/app/api/{plugins β plugin/gateway}/route.ts +4 -2
- package/src/app/api/plugin/store/Store.ts +19 -0
- package/src/app/api/plugin/store/route.ts +21 -0
- package/src/const/url.ts +0 -9
- package/src/services/__tests__/plugin.test.ts +3 -10
- package/src/services/_url.ts +6 -3
- package/src/services/chat.ts +2 -2
- package/src/services/file.ts +2 -2
- package/src/services/plugin.ts +6 -9
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,32 @@
|
|
|
2
2
|
|
|
3
3
|
# Changelog
|
|
4
4
|
|
|
5
|
+
### [Version 0.115.9](https://github.com/lobehub/lobe-chat/compare/v0.115.8...v0.115.9)
|
|
6
|
+
|
|
7
|
+
<sup>Released on **2023-12-24**</sup>
|
|
8
|
+
|
|
9
|
+
#### π Bug Fixes
|
|
10
|
+
|
|
11
|
+
- **misc**: Fix `PLUGINS_INDEX_URL` not working, fix a translation error in Traditional Chinese.
|
|
12
|
+
|
|
13
|
+
<br/>
|
|
14
|
+
|
|
15
|
+
<details>
|
|
16
|
+
<summary><kbd>Improvements and Fixes</kbd></summary>
|
|
17
|
+
|
|
18
|
+
#### What's fixed
|
|
19
|
+
|
|
20
|
+
- **misc**: Fix `PLUGINS_INDEX_URL` not working, closes [#793](https://github.com/lobehub/lobe-chat/issues/793) ([152913e](https://github.com/lobehub/lobe-chat/commit/152913e))
|
|
21
|
+
- **misc**: Fix a translation error in Traditional Chinese, closes [#789](https://github.com/lobehub/lobe-chat/issues/789) ([80c02ee](https://github.com/lobehub/lobe-chat/commit/80c02ee))
|
|
22
|
+
|
|
23
|
+
</details>
|
|
24
|
+
|
|
25
|
+
<div align="right">
|
|
26
|
+
|
|
27
|
+
[](#readme-top)
|
|
28
|
+
|
|
29
|
+
</div>
|
|
30
|
+
|
|
5
31
|
### [Version 0.115.8](https://github.com/lobehub/lobe-chat/compare/v0.115.7...v0.115.8)
|
|
6
32
|
|
|
7
33
|
<sup>Released on **2023-12-24**</sup>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lobehub/chat",
|
|
3
|
-
"version": "0.115.
|
|
3
|
+
"version": "0.115.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,5 +1,7 @@
|
|
|
1
1
|
import { createGatewayOnEdgeRuntime } from '@lobehub/chat-plugins-gateway';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { getServerConfig } from '@/config/server';
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
const pluginsIndexUrl = getServerConfig().PLUGINS_INDEX_URL;
|
|
6
|
+
|
|
7
|
+
export const POST = createGatewayOnEdgeRuntime({ pluginsIndexUrl });
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import urlJoin from 'url-join';
|
|
2
|
+
|
|
3
|
+
import { getServerConfig } from '@/config/server';
|
|
4
|
+
import { DEFAULT_LANG, checkLang } from '@/const/locale';
|
|
5
|
+
import { Locales } from '@/locales/resources';
|
|
6
|
+
|
|
7
|
+
export class PluginStore {
|
|
8
|
+
private readonly baseUrl: string;
|
|
9
|
+
|
|
10
|
+
constructor(baseUrl?: string) {
|
|
11
|
+
this.baseUrl = baseUrl || getServerConfig().PLUGINS_INDEX_URL;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
getPluginIndexUrl = (lang: Locales = DEFAULT_LANG) => {
|
|
15
|
+
if (checkLang(lang)) return this.baseUrl;
|
|
16
|
+
|
|
17
|
+
return urlJoin(this.baseUrl, `index.${lang}.json`);
|
|
18
|
+
};
|
|
19
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { DEFAULT_LANG } from '@/const/locale';
|
|
2
|
+
|
|
3
|
+
import { PluginStore } from './Store';
|
|
4
|
+
|
|
5
|
+
export const runtime = 'edge';
|
|
6
|
+
|
|
7
|
+
export const GET = async (req: Request) => {
|
|
8
|
+
const locale = new URL(req.url).searchParams.get('locale');
|
|
9
|
+
|
|
10
|
+
const pluginStore = new PluginStore();
|
|
11
|
+
|
|
12
|
+
let res: Response;
|
|
13
|
+
|
|
14
|
+
res = await fetch(pluginStore.getPluginIndexUrl(locale as any));
|
|
15
|
+
|
|
16
|
+
if (res.status === 404) {
|
|
17
|
+
res = await fetch(pluginStore.getPluginIndexUrl(DEFAULT_LANG));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return res;
|
|
21
|
+
};
|
package/src/const/url.ts
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import urlJoin from 'url-join';
|
|
2
2
|
|
|
3
|
-
import { Locales } from '@/locales/resources';
|
|
4
|
-
|
|
5
3
|
import pkg from '../../package.json';
|
|
6
|
-
import { DEFAULT_LANG, checkLang } from './locale';
|
|
7
4
|
import { INBOX_SESSION_ID } from './session';
|
|
8
5
|
|
|
9
6
|
export const GITHUB = pkg.homepage;
|
|
@@ -16,12 +13,6 @@ export const DISCORD = 'https://discord.gg/AYFPHvv2jT';
|
|
|
16
13
|
|
|
17
14
|
export const PLUGINS_INDEX_URL = 'https://chat-plugins.lobehub.com';
|
|
18
15
|
|
|
19
|
-
export const getPluginIndexJSON = (lang: Locales = DEFAULT_LANG, baseUrl = PLUGINS_INDEX_URL) => {
|
|
20
|
-
if (checkLang(lang)) return baseUrl;
|
|
21
|
-
|
|
22
|
-
return urlJoin(baseUrl, `index.${lang}.json`);
|
|
23
|
-
};
|
|
24
|
-
|
|
25
16
|
export const AGENTS_INDEX_GITHUB = 'https://github.com/lobehub/lobe-chat-agents';
|
|
26
17
|
export const AGENTS_INDEX_GITHUB_ISSUE = urlJoin(AGENTS_INDEX_GITHUB, 'issues/new');
|
|
27
18
|
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { LobeChatPluginManifest } from '@lobehub/chat-plugin-sdk';
|
|
2
2
|
import { Mock, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
3
3
|
|
|
4
|
-
import { getPluginIndexJSON } from '@/const/url';
|
|
5
4
|
import { PluginModel } from '@/database/models/plugin';
|
|
6
5
|
import { DB_Plugin } from '@/database/schemas/plugin';
|
|
7
6
|
import { globalHelpers } from '@/store/global/helpers';
|
|
@@ -13,9 +12,7 @@ import openAPIV3 from './openai/OpenAPI_V3.json';
|
|
|
13
12
|
import OpenAIPlugin from './openai/plugin.json';
|
|
14
13
|
|
|
15
14
|
// Mocking modules and functions
|
|
16
|
-
|
|
17
|
-
getPluginIndexJSON: vi.fn(),
|
|
18
|
-
}));
|
|
15
|
+
|
|
19
16
|
vi.mock('@/store/global/helpers', () => ({
|
|
20
17
|
globalHelpers: {
|
|
21
18
|
getCurrentLanguage: vi.fn(),
|
|
@@ -40,9 +37,7 @@ describe('PluginService', () => {
|
|
|
40
37
|
it('should fetch and return the plugin list', async () => {
|
|
41
38
|
// Arrange
|
|
42
39
|
const fakeResponse = { plugins: [{ name: 'TestPlugin' }] };
|
|
43
|
-
|
|
44
|
-
(globalHelpers.getCurrentLanguage as Mock).mockReturnValue('en');
|
|
45
|
-
(getPluginIndexJSON as Mock).mockReturnValue(fakeUrl);
|
|
40
|
+
(globalHelpers.getCurrentLanguage as Mock).mockReturnValue('tt');
|
|
46
41
|
global.fetch = vi.fn(() =>
|
|
47
42
|
Promise.resolve({
|
|
48
43
|
json: () => Promise.resolve(fakeResponse),
|
|
@@ -54,8 +49,7 @@ describe('PluginService', () => {
|
|
|
54
49
|
|
|
55
50
|
// Assert
|
|
56
51
|
expect(globalHelpers.getCurrentLanguage).toHaveBeenCalled();
|
|
57
|
-
expect(
|
|
58
|
-
expect(fetch).toHaveBeenCalledWith(fakeUrl);
|
|
52
|
+
expect(fetch).toHaveBeenCalledWith('/api/plugin/store?locale=tt');
|
|
59
53
|
expect(pluginList).toEqual(fakeResponse);
|
|
60
54
|
});
|
|
61
55
|
|
|
@@ -63,7 +57,6 @@ describe('PluginService', () => {
|
|
|
63
57
|
// Arrange
|
|
64
58
|
const fakeUrl = 'http://fake-url.com/plugins.json';
|
|
65
59
|
(globalHelpers.getCurrentLanguage as Mock).mockReturnValue('en');
|
|
66
|
-
(getPluginIndexJSON as Mock).mockReturnValue(fakeUrl);
|
|
67
60
|
global.fetch = vi.fn(() => Promise.reject(new Error('Network error')));
|
|
68
61
|
|
|
69
62
|
// Act & Assert
|
package/src/services/_url.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
export const URLS = {
|
|
2
2
|
config: '/api/config',
|
|
3
3
|
market: '/api/market',
|
|
4
|
-
|
|
4
|
+
proxy: '/api/proxy',
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export const PLUGINS_URLS = {
|
|
8
|
+
gateway: '/api/plugin/gateway',
|
|
9
|
+
store: '/api/plugin/store',
|
|
5
10
|
};
|
|
6
11
|
|
|
7
12
|
export const OPENAI_URLS = {
|
|
@@ -16,5 +21,3 @@ export const TTS_URL = {
|
|
|
16
21
|
edge: '/api/tts/edge-speech',
|
|
17
22
|
microsoft: '/api/tts/microsoft-speech',
|
|
18
23
|
};
|
|
19
|
-
|
|
20
|
-
export const PROXY_URL = '/api/proxy';
|
package/src/services/chat.ts
CHANGED
|
@@ -13,7 +13,7 @@ import { UserMessageContentPart } from '@/types/openai/chat';
|
|
|
13
13
|
import { fetchAIFactory, getMessageError } from '@/utils/fetch';
|
|
14
14
|
|
|
15
15
|
import { createHeaderWithOpenAI } from './_header';
|
|
16
|
-
import { OPENAI_URLS,
|
|
16
|
+
import { OPENAI_URLS, PLUGINS_URLS } from './_url';
|
|
17
17
|
|
|
18
18
|
const isVisionModel = (model?: string) => model && VISION_MODEL_WHITE_LIST.includes(model);
|
|
19
19
|
|
|
@@ -92,7 +92,7 @@ class ChatService {
|
|
|
92
92
|
|
|
93
93
|
const gatewayURL = manifest?.gateway;
|
|
94
94
|
|
|
95
|
-
const res = await fetch(gatewayURL ??
|
|
95
|
+
const res = await fetch(gatewayURL ?? PLUGINS_URLS.gateway, {
|
|
96
96
|
body: JSON.stringify({ ...params, manifest }),
|
|
97
97
|
headers: createHeadersWithPluginSettings(settings),
|
|
98
98
|
method: 'POST',
|
package/src/services/file.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FileModel } from '@/database/models/file';
|
|
2
2
|
import { DB_File } from '@/database/schemas/files';
|
|
3
|
-
import {
|
|
3
|
+
import { URLS } from '@/services/_url';
|
|
4
4
|
import { FilePreview } from '@/types/files';
|
|
5
5
|
import compressImage from '@/utils/compressImage';
|
|
6
6
|
|
|
@@ -43,7 +43,7 @@ class FileService {
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
async uploadImageByUrl(url: string, file: Pick<DB_File, 'name' | 'metadata'>) {
|
|
46
|
-
const res = await fetch(
|
|
46
|
+
const res = await fetch(URLS.proxy, { body: url, method: 'POST' });
|
|
47
47
|
const data = await res.arrayBuffer();
|
|
48
48
|
const fileType = res.headers.get('content-type') || 'image/webp';
|
|
49
49
|
|
package/src/services/plugin.ts
CHANGED
|
@@ -4,9 +4,8 @@ import {
|
|
|
4
4
|
pluginManifestSchema,
|
|
5
5
|
} from '@lobehub/chat-plugin-sdk';
|
|
6
6
|
|
|
7
|
-
import { getPluginIndexJSON } from '@/const/url';
|
|
8
7
|
import { PluginModel } from '@/database/models/plugin';
|
|
9
|
-
import {
|
|
8
|
+
import { PLUGINS_URLS, URLS } from '@/services/_url';
|
|
10
9
|
import { globalHelpers } from '@/store/global/helpers';
|
|
11
10
|
import { OpenAIPluginManifest } from '@/types/openai/plugin';
|
|
12
11
|
import { LobeTool } from '@/types/tool';
|
|
@@ -22,7 +21,7 @@ class PluginService {
|
|
|
22
21
|
// 2. ειθ―·ζ±
|
|
23
22
|
let res: Response;
|
|
24
23
|
try {
|
|
25
|
-
res = await (proxy ? fetch(
|
|
24
|
+
res = await (proxy ? fetch(URLS.proxy, { body: url, method: 'POST' }) : fetch(url));
|
|
26
25
|
} catch {
|
|
27
26
|
throw new TypeError('fetchError');
|
|
28
27
|
}
|
|
@@ -52,14 +51,12 @@ class PluginService {
|
|
|
52
51
|
/**
|
|
53
52
|
* get plugin list from store
|
|
54
53
|
*/
|
|
55
|
-
getPluginList = async () => {
|
|
56
|
-
const
|
|
54
|
+
getPluginList = async (): Promise<LobeChatPluginsMarketIndex> => {
|
|
55
|
+
const locale = globalHelpers.getCurrentLanguage();
|
|
57
56
|
|
|
58
|
-
const res = await fetch(
|
|
57
|
+
const res = await fetch(`${PLUGINS_URLS.store}?locale=${locale}`);
|
|
59
58
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
return data;
|
|
59
|
+
return res.json();
|
|
63
60
|
};
|
|
64
61
|
|
|
65
62
|
getPluginManifest = async (
|