@lobehub/chat 1.2.11 → 1.2.13
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 +51 -0
- package/package.json +30 -30
- package/src/app/(auth)/signup/[[...signup]]/page.tsx +8 -0
- package/src/app/(main)/settings/_layout/Mobile/Header.tsx +12 -2
- package/src/config/featureFlags/schema.ts +6 -0
- package/src/layout/AuthProvider/Clerk/index.tsx +19 -1
- package/src/libs/agent-runtime/google/index.test.ts +2 -2
- package/src/services/__tests__/chat.test.ts +136 -1
- package/src/services/chat.ts +44 -2
- package/src/store/serverConfig/selectors.test.ts +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,57 @@
|
|
|
2
2
|
|
|
3
3
|
# Changelog
|
|
4
4
|
|
|
5
|
+
### [Version 1.2.13](https://github.com/lobehub/lobe-chat/compare/v1.2.12...v1.2.13)
|
|
6
|
+
|
|
7
|
+
<sup>Released on **2024-07-07**</sup>
|
|
8
|
+
|
|
9
|
+
#### 🐛 Bug Fixes
|
|
10
|
+
|
|
11
|
+
- **misc**: Fix tool message order.
|
|
12
|
+
|
|
13
|
+
<br/>
|
|
14
|
+
|
|
15
|
+
<details>
|
|
16
|
+
<summary><kbd>Improvements and Fixes</kbd></summary>
|
|
17
|
+
|
|
18
|
+
#### What's fixed
|
|
19
|
+
|
|
20
|
+
- **misc**: Fix tool message order, closes [#3155](https://github.com/lobehub/lobe-chat/issues/3155) ([6171b2a](https://github.com/lobehub/lobe-chat/commit/6171b2a))
|
|
21
|
+
|
|
22
|
+
</details>
|
|
23
|
+
|
|
24
|
+
<div align="right">
|
|
25
|
+
|
|
26
|
+
[](#readme-top)
|
|
27
|
+
|
|
28
|
+
</div>
|
|
29
|
+
|
|
30
|
+
### [Version 1.2.12](https://github.com/lobehub/lobe-chat/compare/v1.2.11...v1.2.12)
|
|
31
|
+
|
|
32
|
+
<sup>Released on **2024-07-07**</sup>
|
|
33
|
+
|
|
34
|
+
#### 🐛 Bug Fixes
|
|
35
|
+
|
|
36
|
+
- **misc**: Fixed mobile web page navigation issue with inbox assistant, support to disable clerk signup with feature flag.
|
|
37
|
+
|
|
38
|
+
<br/>
|
|
39
|
+
|
|
40
|
+
<details>
|
|
41
|
+
<summary><kbd>Improvements and Fixes</kbd></summary>
|
|
42
|
+
|
|
43
|
+
#### What's fixed
|
|
44
|
+
|
|
45
|
+
- **misc**: Fixed mobile web page navigation issue with inbox assistant, closes [#2693](https://github.com/lobehub/lobe-chat/issues/2693) ([4476a5e](https://github.com/lobehub/lobe-chat/commit/4476a5e))
|
|
46
|
+
- **misc**: Support to disable clerk signup with feature flag, closes [#3126](https://github.com/lobehub/lobe-chat/issues/3126) ([4ead315](https://github.com/lobehub/lobe-chat/commit/4ead315))
|
|
47
|
+
|
|
48
|
+
</details>
|
|
49
|
+
|
|
50
|
+
<div align="right">
|
|
51
|
+
|
|
52
|
+
[](#readme-top)
|
|
53
|
+
|
|
54
|
+
</div>
|
|
55
|
+
|
|
5
56
|
### [Version 1.2.11](https://github.com/lobehub/lobe-chat/compare/v1.2.10...v1.2.11)
|
|
6
57
|
|
|
7
58
|
<sup>Released on **2024-07-07**</sup>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lobehub/chat",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.13",
|
|
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",
|
|
@@ -97,29 +97,29 @@
|
|
|
97
97
|
},
|
|
98
98
|
"dependencies": {
|
|
99
99
|
"@ant-design/icons": "^5.3.7",
|
|
100
|
-
"@anthropic-ai/sdk": "^0.24.
|
|
100
|
+
"@anthropic-ai/sdk": "^0.24.3",
|
|
101
101
|
"@auth/core": "0.28.0",
|
|
102
|
-
"@aws-sdk/client-bedrock-runtime": "^3.
|
|
103
|
-
"@aws-sdk/client-s3": "^3.
|
|
104
|
-
"@aws-sdk/s3-request-presigner": "^3.
|
|
102
|
+
"@aws-sdk/client-bedrock-runtime": "^3.609.0",
|
|
103
|
+
"@aws-sdk/client-s3": "^3.609.0",
|
|
104
|
+
"@aws-sdk/s3-request-presigner": "^3.609.0",
|
|
105
105
|
"@azure/core-rest-pipeline": "1.16.0",
|
|
106
106
|
"@azure/openai": "1.0.0-beta.12",
|
|
107
107
|
"@cfworker/json-schema": "^1.12.8",
|
|
108
108
|
"@clerk/localizations": "2.0.0",
|
|
109
109
|
"@clerk/nextjs": "^5.2.2",
|
|
110
110
|
"@clerk/themes": "^2.1.10",
|
|
111
|
-
"@google/generative-ai": "^0.
|
|
112
|
-
"@icons-pack/react-simple-icons": "^9.
|
|
111
|
+
"@google/generative-ai": "^0.14.1",
|
|
112
|
+
"@icons-pack/react-simple-icons": "^9.6.0",
|
|
113
113
|
"@khmyznikov/pwa-install": "^0.3.9",
|
|
114
|
-
"@lobehub/chat-plugin-sdk": "^1.32.
|
|
114
|
+
"@lobehub/chat-plugin-sdk": "^1.32.4",
|
|
115
115
|
"@lobehub/chat-plugins-gateway": "^1.9.0",
|
|
116
|
-
"@lobehub/icons": "^1.25.
|
|
117
|
-
"@lobehub/tts": "^1.24.
|
|
118
|
-
"@lobehub/ui": "^1.146.
|
|
116
|
+
"@lobehub/icons": "^1.25.2",
|
|
117
|
+
"@lobehub/tts": "^1.24.3",
|
|
118
|
+
"@lobehub/ui": "^1.146.4",
|
|
119
119
|
"@microsoft/fetch-event-source": "^2.0.1",
|
|
120
|
-
"@neondatabase/serverless": "^0.9.
|
|
120
|
+
"@neondatabase/serverless": "^0.9.4",
|
|
121
121
|
"@next/third-parties": "^14.2.4",
|
|
122
|
-
"@sentry/nextjs": "^7.
|
|
122
|
+
"@sentry/nextjs": "^7.118.0",
|
|
123
123
|
"@t3-oss/env-nextjs": "^0.10.1",
|
|
124
124
|
"@trpc/client": "next",
|
|
125
125
|
"@trpc/next": "next",
|
|
@@ -127,8 +127,8 @@
|
|
|
127
127
|
"@vercel/analytics": "^1.3.1",
|
|
128
128
|
"@vercel/speed-insights": "^1.0.12",
|
|
129
129
|
"ahooks": "^3.8.0",
|
|
130
|
-
"ai": "^3.2.
|
|
131
|
-
"antd": "^5.
|
|
130
|
+
"ai": "^3.2.16",
|
|
131
|
+
"antd": "^5.19.1",
|
|
132
132
|
"antd-style": "^3.6.2",
|
|
133
133
|
"brotli-wasm": "^3.0.1",
|
|
134
134
|
"chroma-js": "^2.4.2",
|
|
@@ -146,9 +146,9 @@
|
|
|
146
146
|
"idb-keyval": "^6.2.1",
|
|
147
147
|
"immer": "^10.1.1",
|
|
148
148
|
"ip": "^2.0.1",
|
|
149
|
-
"jose": "^5.
|
|
150
|
-
"langfuse": "^3.
|
|
151
|
-
"langfuse-core": "^3.
|
|
149
|
+
"jose": "^5.6.3",
|
|
150
|
+
"langfuse": "^3.14.0",
|
|
151
|
+
"langfuse-core": "^3.14.0",
|
|
152
152
|
"lodash-es": "^4.17.21",
|
|
153
153
|
"lucide-react": "latest",
|
|
154
154
|
"modern-screenshot": "^4.4.39",
|
|
@@ -159,12 +159,12 @@
|
|
|
159
159
|
"numeral": "^2.0.6",
|
|
160
160
|
"nuqs": "^1.17.4",
|
|
161
161
|
"ollama": "^0.5.2",
|
|
162
|
-
"openai": "^4.52.
|
|
162
|
+
"openai": "^4.52.3",
|
|
163
163
|
"partial-json": "^0.1.7",
|
|
164
164
|
"pg": "^8.12.0",
|
|
165
165
|
"pino": "^9.2.0",
|
|
166
166
|
"polished": "^4.3.1",
|
|
167
|
-
"posthog-js": "^1.
|
|
167
|
+
"posthog-js": "^1.144.2",
|
|
168
168
|
"pwa-install-handler": "^2.6.0",
|
|
169
169
|
"query-string": "^9.0.0",
|
|
170
170
|
"random-words": "^2.0.1",
|
|
@@ -193,13 +193,13 @@
|
|
|
193
193
|
"use-merge-value": "^1.2.0",
|
|
194
194
|
"utility-types": "^3.11.0",
|
|
195
195
|
"uuid": "^10.0.0",
|
|
196
|
-
"ws": "^8.
|
|
196
|
+
"ws": "^8.18.0",
|
|
197
197
|
"y-protocols": "^1.0.6",
|
|
198
198
|
"y-webrtc": "^10.3.0",
|
|
199
199
|
"yaml": "^2.4.5",
|
|
200
200
|
"yjs": "^13.6.18",
|
|
201
201
|
"zod": "^3.23.8",
|
|
202
|
-
"zustand": "^4.5.
|
|
202
|
+
"zustand": "^4.5.4",
|
|
203
203
|
"zustand-utils": "^1.3.2"
|
|
204
204
|
},
|
|
205
205
|
"devDependencies": {
|
|
@@ -219,9 +219,9 @@
|
|
|
219
219
|
"@types/diff": "^5.2.1",
|
|
220
220
|
"@types/ip": "^1.1.3",
|
|
221
221
|
"@types/json-schema": "^7.0.15",
|
|
222
|
-
"@types/lodash": "^4.17.
|
|
222
|
+
"@types/lodash": "^4.17.6",
|
|
223
223
|
"@types/lodash-es": "^4.17.12",
|
|
224
|
-
"@types/node": "^20.14.
|
|
224
|
+
"@types/node": "^20.14.10",
|
|
225
225
|
"@types/numeral": "^2.0.5",
|
|
226
226
|
"@types/pg": "^8.11.6",
|
|
227
227
|
"@types/react": "^18.3.3",
|
|
@@ -238,13 +238,13 @@
|
|
|
238
238
|
"consola": "^3.2.3",
|
|
239
239
|
"dotenv": "^16.4.5",
|
|
240
240
|
"dpdm": "^3.14.0",
|
|
241
|
-
"drizzle-kit": "^0.22.
|
|
241
|
+
"drizzle-kit": "^0.22.8",
|
|
242
242
|
"eslint": "^8.57.0",
|
|
243
243
|
"eslint-plugin-mdx": "^2.3.4",
|
|
244
244
|
"fake-indexeddb": "^6.0.0",
|
|
245
|
-
"glob": "^10.4.
|
|
245
|
+
"glob": "^10.4.3",
|
|
246
246
|
"gray-matter": "^4.0.3",
|
|
247
|
-
"happy-dom": "^14.12.
|
|
247
|
+
"happy-dom": "^14.12.3",
|
|
248
248
|
"husky": "^9.0.11",
|
|
249
249
|
"just-diff": "^6.0.2",
|
|
250
250
|
"lint-staged": "^15.2.7",
|
|
@@ -258,11 +258,11 @@
|
|
|
258
258
|
"remark-parse": "^10.0.2",
|
|
259
259
|
"semantic-release": "^21.1.2",
|
|
260
260
|
"stylelint": "^15.11.0",
|
|
261
|
-
"tsx": "^4.
|
|
262
|
-
"typescript": "^5.5.
|
|
261
|
+
"tsx": "^4.16.2",
|
|
262
|
+
"typescript": "^5.5.3",
|
|
263
263
|
"unified": "^11.0.5",
|
|
264
264
|
"unist-util-visit": "^5.0.0",
|
|
265
|
-
"vite": "^5.3.
|
|
265
|
+
"vite": "^5.3.3",
|
|
266
266
|
"vitest": "~1.2.2",
|
|
267
267
|
"vitest-canvas-mock": "^0.3.3"
|
|
268
268
|
},
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { SignUp } from '@clerk/nextjs';
|
|
2
|
+
import { redirect } from 'next/navigation';
|
|
2
3
|
|
|
4
|
+
import { serverFeatureFlags } from '@/config/featureFlags';
|
|
3
5
|
import { metadataModule } from '@/server/metadata';
|
|
4
6
|
import { translation } from '@/server/translation';
|
|
5
7
|
|
|
@@ -13,6 +15,12 @@ export const generateMetadata = async () => {
|
|
|
13
15
|
};
|
|
14
16
|
|
|
15
17
|
const Page = () => {
|
|
18
|
+
const enableClerkSignUp = serverFeatureFlags().enableClerkSignUp;
|
|
19
|
+
|
|
20
|
+
if (!enableClerkSignUp) {
|
|
21
|
+
redirect('/login');
|
|
22
|
+
}
|
|
23
|
+
|
|
16
24
|
return <SignUp path="/signup" />;
|
|
17
25
|
};
|
|
18
26
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { MobileNavBar, MobileNavBarTitle } from '@lobehub/ui';
|
|
4
4
|
import { Tag } from 'antd';
|
|
5
|
-
import { useRouter } from 'next/navigation';
|
|
5
|
+
import { useRouter, useSearchParams } from 'next/navigation';
|
|
6
6
|
import { memo } from 'react';
|
|
7
7
|
import { useTranslation } from 'react-i18next';
|
|
8
8
|
import { Flexbox } from 'react-layout-kit';
|
|
@@ -16,7 +16,17 @@ const Header = memo(() => {
|
|
|
16
16
|
const { t } = useTranslation('setting');
|
|
17
17
|
|
|
18
18
|
const router = useRouter();
|
|
19
|
+
const searchParams = useSearchParams();
|
|
19
20
|
const activeSettingsKey = useActiveSettingsKey();
|
|
21
|
+
|
|
22
|
+
const handleBackClick = () => {
|
|
23
|
+
if (searchParams.has('session') && searchParams.has('showMobileWorkspace')) {
|
|
24
|
+
router.push(`/chat?${searchParams.toString()}`);
|
|
25
|
+
} else {
|
|
26
|
+
router.push(enableAuth ? '/me/settings' : '/me');
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
20
30
|
return (
|
|
21
31
|
<MobileNavBar
|
|
22
32
|
center={
|
|
@@ -33,7 +43,7 @@ const Header = memo(() => {
|
|
|
33
43
|
}
|
|
34
44
|
/>
|
|
35
45
|
}
|
|
36
|
-
onBackClick={
|
|
46
|
+
onBackClick={handleBackClick}
|
|
37
47
|
showBackButton
|
|
38
48
|
style={mobileHeaderSticky}
|
|
39
49
|
/>
|
|
@@ -16,6 +16,8 @@ export const FeatureFlagsSchema = z.object({
|
|
|
16
16
|
|
|
17
17
|
check_updates: z.boolean().optional(),
|
|
18
18
|
welcome_suggest: z.boolean().optional(),
|
|
19
|
+
|
|
20
|
+
clerk_sign_up: z.boolean().optional(),
|
|
19
21
|
});
|
|
20
22
|
|
|
21
23
|
// TypeScript 类型,从 Zod schema 生成
|
|
@@ -36,6 +38,8 @@ export const DEFAULT_FEATURE_FLAGS: IFeatureFlags = {
|
|
|
36
38
|
|
|
37
39
|
check_updates: true,
|
|
38
40
|
welcome_suggest: true,
|
|
41
|
+
|
|
42
|
+
clerk_sign_up: true,
|
|
39
43
|
};
|
|
40
44
|
|
|
41
45
|
export const mapFeatureFlagsEnvToState = (config: IFeatureFlags) => {
|
|
@@ -53,5 +57,7 @@ export const mapFeatureFlagsEnvToState = (config: IFeatureFlags) => {
|
|
|
53
57
|
|
|
54
58
|
enableCheckUpdates: config.check_updates,
|
|
55
59
|
showWelcomeSuggest: config.welcome_suggest,
|
|
60
|
+
|
|
61
|
+
enableClerkSignUp: config.clerk_sign_up,
|
|
56
62
|
};
|
|
57
63
|
};
|
|
@@ -4,10 +4,13 @@ import { ClerkProvider } from '@clerk/nextjs';
|
|
|
4
4
|
import { PropsWithChildren, memo, useEffect, useMemo, useState, useTransition } from 'react';
|
|
5
5
|
import { useTranslation } from 'react-i18next';
|
|
6
6
|
|
|
7
|
+
import { featureFlagsSelectors, useServerConfigStore } from '@/store/serverConfig';
|
|
8
|
+
|
|
7
9
|
import UserUpdater from './UserUpdater';
|
|
8
10
|
import { useAppearance } from './useAppearance';
|
|
9
11
|
|
|
10
12
|
const Clerk = memo(({ children }: PropsWithChildren) => {
|
|
13
|
+
const { enableClerkSignUp } = useServerConfigStore(featureFlagsSelectors);
|
|
11
14
|
const appearance = useAppearance();
|
|
12
15
|
const {
|
|
13
16
|
i18n: { language, getResourceBundle },
|
|
@@ -27,8 +30,23 @@ const Clerk = memo(({ children }: PropsWithChildren) => {
|
|
|
27
30
|
});
|
|
28
31
|
}, [count, setCount, isPending, startTransition]);
|
|
29
32
|
|
|
33
|
+
const updatedAppearance = useMemo(
|
|
34
|
+
() => ({
|
|
35
|
+
...appearance,
|
|
36
|
+
elements: {
|
|
37
|
+
...appearance.elements,
|
|
38
|
+
...(!enableClerkSignUp ? { footerAction: { display: 'none' } } : {}),
|
|
39
|
+
},
|
|
40
|
+
}),
|
|
41
|
+
[appearance, enableClerkSignUp],
|
|
42
|
+
);
|
|
43
|
+
|
|
30
44
|
return (
|
|
31
|
-
<ClerkProvider
|
|
45
|
+
<ClerkProvider
|
|
46
|
+
appearance={updatedAppearance}
|
|
47
|
+
localization={localization}
|
|
48
|
+
signUpUrl={!enableClerkSignUp ? '/login' : '/signup'} // Redirect sign-up to sign-in if disabled
|
|
49
|
+
>
|
|
32
50
|
{children}
|
|
33
51
|
<UserUpdater />
|
|
34
52
|
</ClerkProvider>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @vitest-environment edge-runtime
|
|
2
|
-
import { FunctionDeclarationSchemaType } from '@google/generative-ai';
|
|
2
|
+
import { FunctionDeclarationSchemaType, FunctionDeclarationsTool } from '@google/generative-ai';
|
|
3
3
|
import { JSONSchema7 } from 'json-schema';
|
|
4
4
|
import OpenAI from 'openai';
|
|
5
5
|
import { Mock, afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
@@ -456,7 +456,7 @@ describe('LobeGoogleAI', () => {
|
|
|
456
456
|
const googleTools = instance['buildGoogleTools'](tools);
|
|
457
457
|
|
|
458
458
|
expect(googleTools).toHaveLength(1);
|
|
459
|
-
expect(googleTools![0].functionDeclarations![0]).toEqual({
|
|
459
|
+
expect((googleTools![0] as FunctionDeclarationsTool).functionDeclarations![0]).toEqual({
|
|
460
460
|
name: 'testTool',
|
|
461
461
|
description: 'A test tool',
|
|
462
462
|
parameters: {
|
|
@@ -32,7 +32,7 @@ import { UserStore } from '@/store/user';
|
|
|
32
32
|
import { UserSettingsState, initialSettingsState } from '@/store/user/slices/settings/initialState';
|
|
33
33
|
import { DalleManifest } from '@/tools/dalle';
|
|
34
34
|
import { ChatMessage } from '@/types/message';
|
|
35
|
-
import { ChatStreamPayload } from '@/types/openai/chat';
|
|
35
|
+
import { ChatStreamPayload, type OpenAIChatMessage } from '@/types/openai/chat';
|
|
36
36
|
import { LobeTool } from '@/types/tool';
|
|
37
37
|
|
|
38
38
|
import { chatService, initializeWithClientStore } from '../chat';
|
|
@@ -666,6 +666,141 @@ Get data from users`,
|
|
|
666
666
|
expect(onLoadingChange).toHaveBeenCalledWith(false); // 确认加载状态已经被设置为 false
|
|
667
667
|
});
|
|
668
668
|
});
|
|
669
|
+
|
|
670
|
+
describe('processMessage', () => {
|
|
671
|
+
it('should reorderToolMessages', () => {
|
|
672
|
+
const input: OpenAIChatMessage[] = [
|
|
673
|
+
{
|
|
674
|
+
content: '## Tools\n\nYou can use these tools',
|
|
675
|
+
role: 'system',
|
|
676
|
+
},
|
|
677
|
+
{
|
|
678
|
+
content: '',
|
|
679
|
+
role: 'assistant',
|
|
680
|
+
tool_calls: [
|
|
681
|
+
{
|
|
682
|
+
function: {
|
|
683
|
+
arguments:
|
|
684
|
+
'{"query":"LobeChat","searchEngines":["brave","google","duckduckgo","qwant"]}',
|
|
685
|
+
name: 'lobe-web-browsing____searchWithSearXNG____builtin',
|
|
686
|
+
},
|
|
687
|
+
id: 'call_6xCmrOtFOyBAcqpqO1TGfw2B',
|
|
688
|
+
type: 'function',
|
|
689
|
+
},
|
|
690
|
+
{
|
|
691
|
+
function: {
|
|
692
|
+
arguments:
|
|
693
|
+
'{"query":"LobeChat","searchEngines":["brave","google","duckduckgo","qwant"]}',
|
|
694
|
+
name: 'lobe-web-browsing____searchWithSearXNG____builtin',
|
|
695
|
+
},
|
|
696
|
+
id: 'tool_call_nXxXHW8Z',
|
|
697
|
+
type: 'function',
|
|
698
|
+
},
|
|
699
|
+
{
|
|
700
|
+
function: {
|
|
701
|
+
arguments: '{"query":"LobeHub","searchEngines":["bilibili"]}',
|
|
702
|
+
name: 'lobe-web-browsing____searchWithSearXNG____builtin',
|
|
703
|
+
},
|
|
704
|
+
id: 'tool_call_2f3CEKz9',
|
|
705
|
+
type: 'function',
|
|
706
|
+
},
|
|
707
|
+
],
|
|
708
|
+
},
|
|
709
|
+
{
|
|
710
|
+
content: '[]',
|
|
711
|
+
name: 'lobe-web-browsing____searchWithSearXNG____builtin',
|
|
712
|
+
role: 'tool',
|
|
713
|
+
tool_call_id: 'call_6xCmrOtFOyBAcqpqO1TGfw2B',
|
|
714
|
+
},
|
|
715
|
+
{
|
|
716
|
+
content: 'LobeHub 是一个专注于设计和开发现代人工智能生成内容(AIGC)工具和组件的团队。',
|
|
717
|
+
role: 'assistant',
|
|
718
|
+
},
|
|
719
|
+
{
|
|
720
|
+
content: '[]',
|
|
721
|
+
name: 'lobe-web-browsing____searchWithSearXNG____builtin',
|
|
722
|
+
role: 'tool',
|
|
723
|
+
tool_call_id: 'tool_call_nXxXHW8Z',
|
|
724
|
+
},
|
|
725
|
+
{
|
|
726
|
+
content: '[]',
|
|
727
|
+
name: 'lobe-web-browsing____searchWithSearXNG____builtin',
|
|
728
|
+
role: 'tool',
|
|
729
|
+
tool_call_id: 'tool_call_2f3CEKz9',
|
|
730
|
+
},
|
|
731
|
+
{
|
|
732
|
+
content: '### LobeHub 智能AI聚合神器\n\nLobeHub 是一个强大的AI聚合平台',
|
|
733
|
+
role: 'assistant',
|
|
734
|
+
},
|
|
735
|
+
];
|
|
736
|
+
const output = chatService['reorderToolMessages'](input);
|
|
737
|
+
|
|
738
|
+
expect(output).toEqual([
|
|
739
|
+
{
|
|
740
|
+
content: '## Tools\n\nYou can use these tools',
|
|
741
|
+
role: 'system',
|
|
742
|
+
},
|
|
743
|
+
{
|
|
744
|
+
content: '',
|
|
745
|
+
role: 'assistant',
|
|
746
|
+
tool_calls: [
|
|
747
|
+
{
|
|
748
|
+
function: {
|
|
749
|
+
arguments:
|
|
750
|
+
'{"query":"LobeChat","searchEngines":["brave","google","duckduckgo","qwant"]}',
|
|
751
|
+
name: 'lobe-web-browsing____searchWithSearXNG____builtin',
|
|
752
|
+
},
|
|
753
|
+
id: 'call_6xCmrOtFOyBAcqpqO1TGfw2B',
|
|
754
|
+
type: 'function',
|
|
755
|
+
},
|
|
756
|
+
{
|
|
757
|
+
function: {
|
|
758
|
+
arguments:
|
|
759
|
+
'{"query":"LobeChat","searchEngines":["brave","google","duckduckgo","qwant"]}',
|
|
760
|
+
name: 'lobe-web-browsing____searchWithSearXNG____builtin',
|
|
761
|
+
},
|
|
762
|
+
id: 'tool_call_nXxXHW8Z',
|
|
763
|
+
type: 'function',
|
|
764
|
+
},
|
|
765
|
+
{
|
|
766
|
+
function: {
|
|
767
|
+
arguments: '{"query":"LobeHub","searchEngines":["bilibili"]}',
|
|
768
|
+
name: 'lobe-web-browsing____searchWithSearXNG____builtin',
|
|
769
|
+
},
|
|
770
|
+
id: 'tool_call_2f3CEKz9',
|
|
771
|
+
type: 'function',
|
|
772
|
+
},
|
|
773
|
+
],
|
|
774
|
+
},
|
|
775
|
+
{
|
|
776
|
+
content: '[]',
|
|
777
|
+
name: 'lobe-web-browsing____searchWithSearXNG____builtin',
|
|
778
|
+
role: 'tool',
|
|
779
|
+
tool_call_id: 'call_6xCmrOtFOyBAcqpqO1TGfw2B',
|
|
780
|
+
},
|
|
781
|
+
{
|
|
782
|
+
content: '[]',
|
|
783
|
+
name: 'lobe-web-browsing____searchWithSearXNG____builtin',
|
|
784
|
+
role: 'tool',
|
|
785
|
+
tool_call_id: 'tool_call_nXxXHW8Z',
|
|
786
|
+
},
|
|
787
|
+
{
|
|
788
|
+
content: '[]',
|
|
789
|
+
name: 'lobe-web-browsing____searchWithSearXNG____builtin',
|
|
790
|
+
role: 'tool',
|
|
791
|
+
tool_call_id: 'tool_call_2f3CEKz9',
|
|
792
|
+
},
|
|
793
|
+
{
|
|
794
|
+
content: 'LobeHub 是一个专注于设计和开发现代人工智能生成内容(AIGC)工具和组件的团队。',
|
|
795
|
+
role: 'assistant',
|
|
796
|
+
},
|
|
797
|
+
{
|
|
798
|
+
content: '### LobeHub 智能AI聚合神器\n\nLobeHub 是一个强大的AI聚合平台',
|
|
799
|
+
role: 'assistant',
|
|
800
|
+
},
|
|
801
|
+
]);
|
|
802
|
+
});
|
|
803
|
+
});
|
|
669
804
|
});
|
|
670
805
|
|
|
671
806
|
/**
|
package/src/services/chat.ts
CHANGED
|
@@ -420,7 +420,7 @@ class ChatService {
|
|
|
420
420
|
] as UserMessageContentPart[];
|
|
421
421
|
};
|
|
422
422
|
|
|
423
|
-
|
|
423
|
+
let postMessages = messages.map((m): OpenAIChatMessage => {
|
|
424
424
|
switch (m.role) {
|
|
425
425
|
case 'user': {
|
|
426
426
|
return { content: getContent(m), role: m.role };
|
|
@@ -458,7 +458,7 @@ class ChatService {
|
|
|
458
458
|
}
|
|
459
459
|
});
|
|
460
460
|
|
|
461
|
-
|
|
461
|
+
postMessages = produce(postMessages, (draft) => {
|
|
462
462
|
// if it's a welcome question, inject InboxGuide SystemRole
|
|
463
463
|
const inboxGuideSystemRole =
|
|
464
464
|
options?.isWelcomeQuestion &&
|
|
@@ -492,6 +492,8 @@ class ChatService {
|
|
|
492
492
|
});
|
|
493
493
|
}
|
|
494
494
|
});
|
|
495
|
+
|
|
496
|
+
return this.reorderToolMessages(postMessages);
|
|
495
497
|
};
|
|
496
498
|
|
|
497
499
|
private mapTrace(trace?: TracePayload, tag?: TraceTagMap): TracePayload {
|
|
@@ -523,6 +525,46 @@ class ChatService {
|
|
|
523
525
|
|
|
524
526
|
return agentRuntime.chat(data, { signal: params.signal });
|
|
525
527
|
};
|
|
528
|
+
|
|
529
|
+
/**
|
|
530
|
+
* Reorder tool messages to ensure that tool messages are displayed in the correct order.
|
|
531
|
+
* see https://github.com/lobehub/lobe-chat/pull/3155
|
|
532
|
+
*/
|
|
533
|
+
private reorderToolMessages = (messages: OpenAIChatMessage[]): OpenAIChatMessage[] => {
|
|
534
|
+
const reorderedMessages: OpenAIChatMessage[] = [];
|
|
535
|
+
const toolMessages: Record<string, OpenAIChatMessage> = {};
|
|
536
|
+
|
|
537
|
+
// 1. collect all tool messages
|
|
538
|
+
messages.forEach((message) => {
|
|
539
|
+
if (message.role === 'tool' && message.tool_call_id) {
|
|
540
|
+
toolMessages[message.tool_call_id] = message;
|
|
541
|
+
}
|
|
542
|
+
});
|
|
543
|
+
|
|
544
|
+
// 2. reorder messages
|
|
545
|
+
messages.forEach((message) => {
|
|
546
|
+
const hasPushed = reorderedMessages.some(
|
|
547
|
+
(m) => !!message.tool_call_id && m.tool_call_id === message.tool_call_id,
|
|
548
|
+
);
|
|
549
|
+
|
|
550
|
+
if (hasPushed) return;
|
|
551
|
+
|
|
552
|
+
reorderedMessages.push(message);
|
|
553
|
+
|
|
554
|
+
if (message.role === 'assistant' && message.tool_calls) {
|
|
555
|
+
message.tool_calls.forEach((toolCall) => {
|
|
556
|
+
const correspondingToolMessage = toolMessages[toolCall.id];
|
|
557
|
+
if (correspondingToolMessage) {
|
|
558
|
+
reorderedMessages.push(correspondingToolMessage);
|
|
559
|
+
// 从 toolMessages 中删除已处理的消息,避免重复
|
|
560
|
+
delete toolMessages[toolCall.id];
|
|
561
|
+
}
|
|
562
|
+
});
|
|
563
|
+
}
|
|
564
|
+
});
|
|
565
|
+
|
|
566
|
+
return reorderedMessages;
|
|
567
|
+
};
|
|
526
568
|
}
|
|
527
569
|
|
|
528
570
|
export const chatService = new ChatService();
|