@lobehub/chat 0.157.0 → 0.157.1

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.
Files changed (57) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/package.json +30 -30
  3. package/src/app/api/chat/[provider]/route.test.ts +2 -2
  4. package/src/app/api/chat/[provider]/route.ts +1 -1
  5. package/src/app/api/chat/models/[provider]/route.ts +1 -1
  6. package/src/app/api/config.test.ts +1 -51
  7. package/src/app/api/openai/createBizOpenAI/auth.test.ts +52 -0
  8. package/src/app/api/openai/createBizOpenAI/index.ts +1 -1
  9. package/src/app/api/plugin/gateway/route.ts +1 -1
  10. package/src/app/api/text-to-image/[provider]/route.ts +61 -0
  11. package/src/components/GalleyGrid/index.tsx +2 -2
  12. package/src/database/client/schemas/message.ts +2 -0
  13. package/src/features/Conversation/Actions/Assistant.tsx +3 -2
  14. package/src/features/Conversation/Actions/Tool.tsx +23 -11
  15. package/src/features/Conversation/Messages/Assistant/ToolCalls/index.tsx +9 -14
  16. package/src/features/Conversation/Messages/Assistant/index.tsx +7 -3
  17. package/src/features/Conversation/Messages/Tool/Inspector/index.tsx +1 -1
  18. package/src/features/Conversation/Plugins/Render/index.tsx +11 -2
  19. package/src/hooks/useTokenCount.test.ts +38 -0
  20. package/src/hooks/useTokenCount.ts +1 -2
  21. package/src/libs/agent-runtime/AgentRuntime.ts +9 -1
  22. package/src/libs/agent-runtime/BaseAI.ts +3 -0
  23. package/src/libs/agent-runtime/types/index.ts +1 -0
  24. package/src/libs/agent-runtime/types/textToImage.ts +34 -0
  25. package/src/libs/agent-runtime/utils/createError.ts +1 -0
  26. package/src/libs/agent-runtime/utils/openaiCompatibleFactory/index.ts +51 -0
  27. package/src/locales/default/tool.ts +1 -0
  28. package/src/services/_url.ts +1 -1
  29. package/src/services/{imageGeneration.ts → textToImage.ts} +11 -2
  30. package/src/store/chat/initialState.ts +1 -1
  31. package/src/store/chat/selectors.ts +1 -1
  32. package/src/store/chat/slices/{tool → builtinTool}/action.test.ts +1 -1
  33. package/src/store/chat/slices/{tool → builtinTool}/action.ts +16 -4
  34. package/src/store/chat/slices/enchance/action.ts +10 -11
  35. package/src/store/chat/slices/message/action.ts +30 -92
  36. package/src/store/chat/slices/message/initialState.ts +5 -0
  37. package/src/store/chat/slices/message/selectors.ts +8 -0
  38. package/src/store/chat/slices/plugin/action.test.ts +1 -1
  39. package/src/store/chat/slices/plugin/action.ts +95 -80
  40. package/src/store/chat/store.ts +2 -2
  41. package/src/store/tool/slices/store/action.test.ts +6 -2
  42. package/src/store/tool/slices/store/action.ts +3 -1
  43. package/src/tools/dalle/Render/Item/Error.tsx +50 -0
  44. package/src/tools/dalle/Render/Item/Image.tsx +44 -0
  45. package/src/tools/dalle/Render/{Item.tsx → Item/index.tsx} +20 -29
  46. package/src/utils/fetch.test.ts +208 -3
  47. package/src/utils/fetch.ts +242 -19
  48. package/src/app/api/openai/images/createImageGeneration.ts +0 -26
  49. package/src/app/api/openai/images/route.ts +0 -16
  50. package/src/features/Conversation/Actions/Function.tsx +0 -17
  51. /package/src/app/api/{chat → middleware}/auth/index.test.ts +0 -0
  52. /package/src/app/api/{chat → middleware}/auth/index.ts +0 -0
  53. /package/src/app/api/{chat → middleware}/auth/utils.ts +0 -0
  54. /package/src/app/api/{auth.ts → openai/createBizOpenAI/auth.ts} +0 -0
  55. /package/src/store/chat/slices/{tool → builtinTool}/initialState.ts +0 -0
  56. /package/src/store/chat/slices/{tool → builtinTool}/selectors.ts +0 -0
  57. /package/src/tools/dalle/Render/{EditMode.tsx → Item/EditMode.tsx} +0 -0
package/CHANGELOG.md CHANGED
@@ -2,6 +2,31 @@
2
2
 
3
3
  # Changelog
4
4
 
5
+ ### [Version 0.157.1](https://github.com/lobehub/lobe-chat/compare/v0.157.0...v0.157.1)
6
+
7
+ <sup>Released on **2024-05-12**</sup>
8
+
9
+ #### 🐛 Bug Fixes
10
+
11
+ - **misc**: Fix dalle error.
12
+
13
+ <br/>
14
+
15
+ <details>
16
+ <summary><kbd>Improvements and Fixes</kbd></summary>
17
+
18
+ #### What's fixed
19
+
20
+ - **misc**: Fix dalle error ([7c493de](https://github.com/lobehub/lobe-chat/commit/7c493de))
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
+
5
30
  ## [Version 0.157.0](https://github.com/lobehub/lobe-chat/compare/v0.156.2...v0.157.0)
6
31
 
7
32
  <sup>Released on **2024-05-11**</sup>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/chat",
3
- "version": "0.157.0",
3
+ "version": "0.157.1",
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",
@@ -81,25 +81,25 @@
81
81
  ]
82
82
  },
83
83
  "dependencies": {
84
- "@ant-design/icons": "^5.3.6",
84
+ "@ant-design/icons": "^5.3.7",
85
85
  "@anthropic-ai/sdk": "^0.20.9",
86
86
  "@auth/core": "0.28.0",
87
- "@aws-sdk/client-bedrock-runtime": "^3.565.0",
88
- "@azure/openai": "^1.0.0-beta.12",
87
+ "@aws-sdk/client-bedrock-runtime": "^3.574.0",
88
+ "@azure/openai": "1.0.0-beta.12",
89
89
  "@cfworker/json-schema": "^1.12.8",
90
90
  "@clerk/localizations": "2.0.0",
91
- "@clerk/nextjs": "^5.0.6",
92
- "@clerk/themes": "^2.0.0",
91
+ "@clerk/nextjs": "^5.0.8",
92
+ "@clerk/themes": "^2.1.3",
93
93
  "@google/generative-ai": "^0.10.0",
94
- "@icons-pack/react-simple-icons": "^9.4.1",
94
+ "@icons-pack/react-simple-icons": "^9.5.0",
95
95
  "@lobehub/chat-plugin-sdk": "latest",
96
96
  "@lobehub/chat-plugins-gateway": "latest",
97
97
  "@lobehub/icons": "latest",
98
98
  "@lobehub/tts": "latest",
99
- "@lobehub/ui": "^1.138.17",
99
+ "@lobehub/ui": "^1.138.23",
100
100
  "@microsoft/fetch-event-source": "^2.0.1",
101
101
  "@next/third-parties": "^14.2.3",
102
- "@sentry/nextjs": "^7.112.2",
102
+ "@sentry/nextjs": "^7.114.0",
103
103
  "@t3-oss/env-nextjs": "^0.10.1",
104
104
  "@trpc/client": "next",
105
105
  "@trpc/next": "next",
@@ -118,15 +118,15 @@
118
118
  "diff": "^5.2.0",
119
119
  "fast-deep-equal": "^3.1.3",
120
120
  "gpt-tokenizer": "^2.1.2",
121
- "i18next": "^23.11.3",
121
+ "i18next": "^23.11.4",
122
122
  "i18next-browser-languagedetector": "^7.2.1",
123
123
  "i18next-resources-to-backend": "^1.2.1",
124
124
  "idb-keyval": "^6.2.1",
125
125
  "immer": "^10.1.1",
126
126
  "ip": "^2.0.1",
127
- "jose": "^5.2.4",
128
- "langfuse": "^3.8.0",
129
- "langfuse-core": "^3.8.0",
127
+ "jose": "^5.3.0",
128
+ "langfuse": "^3.10.0",
129
+ "langfuse-core": "^3.10.0",
130
130
  "lodash-es": "^4.17.21",
131
131
  "lucide-react": "latest",
132
132
  "modern-screenshot": "^4.4.39",
@@ -135,12 +135,12 @@
135
135
  "next-auth": "5.0.0-beta.15",
136
136
  "next-sitemap": "^4.2.3",
137
137
  "numeral": "^2.0.6",
138
- "nuqs": "^1.17.1",
139
- "ollama": "^0.5.0",
140
- "openai": "^4.39.0",
138
+ "nuqs": "^1.17.2",
139
+ "ollama": "^0.5.1",
140
+ "openai": "^4.45.0",
141
141
  "pino": "^9.0.0",
142
142
  "polished": "^4.3.1",
143
- "posthog-js": "^1.130.1",
143
+ "posthog-js": "^1.131.4",
144
144
  "query-string": "^9.0.0",
145
145
  "random-words": "^2.0.1",
146
146
  "react": "^18.3.1",
@@ -155,7 +155,7 @@
155
155
  "remark-gfm": "^3.0.1",
156
156
  "remark-html": "^15.0.2",
157
157
  "rtl-detect": "^1.1.2",
158
- "semver": "^7.6.0",
158
+ "semver": "^7.6.2",
159
159
  "sharp": "^0.33.3",
160
160
  "superjson": "^2.2.1",
161
161
  "swr": "^2.2.5",
@@ -170,13 +170,13 @@
170
170
  "y-webrtc": "^10.3.0",
171
171
  "yaml": "^2.4.2",
172
172
  "yjs": "^13.6.15",
173
- "zod": "^3.23.5",
173
+ "zod": "^3.23.8",
174
174
  "zustand": "^4.5.2",
175
175
  "zustand-utils": "^1.3.2"
176
176
  },
177
177
  "devDependencies": {
178
178
  "@commitlint/cli": "^19.3.0",
179
- "@ducanh2912/next-pwa": "^10.2.6",
179
+ "@ducanh2912/next-pwa": "^10.2.7",
180
180
  "@edge-runtime/vm": "^3.2.0",
181
181
  "@lobehub/i18n-cli": "^1.18.1",
182
182
  "@lobehub/lint": "^1.23.4",
@@ -185,24 +185,24 @@
185
185
  "@next/eslint-plugin-next": "^14.2.3",
186
186
  "@peculiar/webcrypto": "^1.4.6",
187
187
  "@testing-library/jest-dom": "^6.4.5",
188
- "@testing-library/react": "^15.0.6",
188
+ "@testing-library/react": "^15.0.7",
189
189
  "@types/chroma-js": "^2.4.4",
190
190
  "@types/debug": "^4.1.12",
191
- "@types/diff": "^5.2.0",
191
+ "@types/diff": "^5.2.1",
192
192
  "@types/ip": "^1.1.3",
193
193
  "@types/json-schema": "^7.0.15",
194
- "@types/lodash": "^4.17.0",
194
+ "@types/lodash": "^4.17.1",
195
195
  "@types/lodash-es": "^4.17.12",
196
- "@types/node": "^20.12.7",
196
+ "@types/node": "^20.12.11",
197
197
  "@types/numeral": "^2.0.5",
198
- "@types/react": "^18.3.1",
198
+ "@types/react": "^18.3.2",
199
199
  "@types/react-dom": "^18.3.0",
200
200
  "@types/rtl-detect": "^1.0.3",
201
201
  "@types/semver": "^7.5.8",
202
202
  "@types/systemjs": "^6.13.5",
203
203
  "@types/ua-parser-js": "^0.7.39",
204
204
  "@types/uuid": "^9.0.8",
205
- "@umijs/lint": "^4.1.10",
205
+ "@umijs/lint": "^4.2.2",
206
206
  "@vitest/coverage-v8": "~1.2.2",
207
207
  "ajv-keywords": "^5.1.0",
208
208
  "commitlint": "^19.3.0",
@@ -211,9 +211,9 @@
211
211
  "eslint": "^8.57.0",
212
212
  "eslint-plugin-mdx": "^2.3.4",
213
213
  "fake-indexeddb": "^5.0.2",
214
- "glob": "^10.3.12",
214
+ "glob": "^10.3.15",
215
215
  "gray-matter": "^4.0.3",
216
- "happy-dom": "^14.7.1",
216
+ "happy-dom": "^14.10.1",
217
217
  "husky": "^9.0.11",
218
218
  "just-diff": "^6.0.2",
219
219
  "lint-staged": "^15.2.2",
@@ -227,11 +227,11 @@
227
227
  "remark-parse": "^10.0.2",
228
228
  "semantic-release": "^21.1.2",
229
229
  "stylelint": "^15.11.0",
230
- "tsx": "^4.7.3",
230
+ "tsx": "^4.10.0",
231
231
  "typescript": "^5.4.5",
232
232
  "unified": "^11.0.4",
233
233
  "unist-util-visit": "^5.0.0",
234
- "vite": "^5.2.10",
234
+ "vite": "^5.2.11",
235
235
  "vitest": "~1.2.2",
236
236
  "vitest-canvas-mock": "^0.3.3"
237
237
  },
@@ -2,18 +2,18 @@
2
2
  import { getAuth } from '@clerk/nextjs/server';
3
3
  import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
4
4
 
5
+ import { checkAuthMethod, getJWTPayload } from '@/app/api/middleware/auth/utils';
5
6
  import { LOBE_CHAT_AUTH_HEADER, OAUTH_AUTHORIZED } from '@/const/auth';
6
7
  import { AgentRuntime, LobeRuntimeAI } from '@/libs/agent-runtime';
7
8
  import { ChatErrorType } from '@/types/fetch';
8
9
 
9
- import { checkAuthMethod, getJWTPayload } from '../auth/utils';
10
10
  import { POST } from './route';
11
11
 
12
12
  vi.mock('@clerk/nextjs/server', () => ({
13
13
  getAuth: vi.fn(),
14
14
  }));
15
15
 
16
- vi.mock('../auth/utils', () => ({
16
+ vi.mock('../../middleware/auth/utils', () => ({
17
17
  getJWTPayload: vi.fn(),
18
18
  checkAuthMethod: vi.fn(),
19
19
  }));
@@ -5,8 +5,8 @@ import { ChatErrorType } from '@/types/fetch';
5
5
  import { ChatStreamPayload } from '@/types/openai/chat';
6
6
  import { getTracePayload } from '@/utils/trace';
7
7
 
8
+ import { checkAuth } from '../../middleware/auth';
8
9
  import { createTraceOptions, initAgentRuntimeWithUserPayload } from '../agentRuntime';
9
- import { checkAuth } from '../auth';
10
10
 
11
11
  export const runtime = 'edge';
12
12
 
@@ -5,8 +5,8 @@ import { createErrorResponse } from '@/app/api/errorResponse';
5
5
  import { ChatCompletionErrorPayload, ModelProvider } from '@/libs/agent-runtime';
6
6
  import { ChatErrorType } from '@/types/fetch';
7
7
 
8
+ import { checkAuth } from '../../../middleware/auth';
8
9
  import { initAgentRuntimeWithUserPayload } from '../../agentRuntime';
9
- import { checkAuth } from '../../auth';
10
10
 
11
11
  export const runtime = 'edge';
12
12
 
@@ -1,7 +1,7 @@
1
1
  import { describe, expect, it, vi } from 'vitest';
2
2
 
3
- import { checkAuth } from './auth';
4
3
  import { getPreferredRegion } from './config';
4
+ import { checkAuth } from './openai/createBizOpenAI/auth';
5
5
 
6
6
  // Stub the global process object to safely mock environment variables
7
7
  vi.stubGlobal('process', {
@@ -41,53 +41,3 @@ describe('getPreferredRegion', () => {
41
41
  expect(preferredRegion).toStrictEqual(['ida1', 'sfo1']);
42
42
  });
43
43
  });
44
-
45
- describe('ACCESS_CODE', () => {
46
- let auth = false;
47
-
48
- beforeEach(() => {
49
- auth = false;
50
- process.env.ACCESS_CODE = undefined;
51
- // Reset environment variables before each test case
52
- vi.restoreAllMocks();
53
- });
54
-
55
- it('set multiple access codes', () => {
56
- process.env.ACCESS_CODE = ',code1,code2,code3';
57
- ({ auth } = checkAuth({ accessCode: 'code1' }));
58
- expect(auth).toBe(true);
59
- ({ auth } = checkAuth({ accessCode: 'code2' }));
60
- expect(auth).toBe(true);
61
- ({ auth } = checkAuth({ accessCode: 'code1,code2' }));
62
- expect(auth).toBe(false);
63
- });
64
-
65
- it('set individual access code', () => {
66
- process.env.ACCESS_CODE = 'code1';
67
- ({ auth } = checkAuth({ accessCode: 'code1' }));
68
- expect(auth).toBe(true);
69
- ({ auth } = checkAuth({ accessCode: 'code2' }));
70
- expect(auth).toBe(false);
71
- });
72
-
73
- it('no access code', () => {
74
- ({ auth } = checkAuth({ accessCode: 'code1' }));
75
- expect(auth).toBe(true);
76
- ({ auth } = checkAuth({}));
77
- expect(auth).toBe(true);
78
- });
79
-
80
- it('empty access code', () => {
81
- process.env.ACCESS_CODE = '';
82
- ({ auth } = checkAuth({ accessCode: 'code1' }));
83
- expect(auth).toBe(true);
84
- ({ auth } = checkAuth({}));
85
- expect(auth).toBe(true);
86
-
87
- process.env.ACCESS_CODE = ',,';
88
- ({ auth } = checkAuth({ accessCode: 'code1' }));
89
- expect(auth).toBe(true);
90
- ({ auth } = checkAuth({}));
91
- expect(auth).toBe(true);
92
- });
93
- });
@@ -0,0 +1,52 @@
1
+ import { checkAuth } from './auth';
2
+
3
+ describe('ACCESS_CODE', () => {
4
+ let auth = false;
5
+
6
+ beforeEach(() => {
7
+ auth = false;
8
+ process.env.ACCESS_CODE = undefined;
9
+ // Reset environment variables before each test case
10
+ vi.restoreAllMocks();
11
+ });
12
+
13
+ it('set multiple access codes', () => {
14
+ process.env.ACCESS_CODE = ',code1,code2,code3';
15
+ ({ auth } = checkAuth({ accessCode: 'code1' }));
16
+ expect(auth).toBe(true);
17
+ ({ auth } = checkAuth({ accessCode: 'code2' }));
18
+ expect(auth).toBe(true);
19
+ ({ auth } = checkAuth({ accessCode: 'code1,code2' }));
20
+ expect(auth).toBe(false);
21
+ });
22
+
23
+ it('set individual access code', () => {
24
+ process.env.ACCESS_CODE = 'code1';
25
+ ({ auth } = checkAuth({ accessCode: 'code1' }));
26
+ expect(auth).toBe(true);
27
+ ({ auth } = checkAuth({ accessCode: 'code2' }));
28
+ expect(auth).toBe(false);
29
+ });
30
+
31
+ it('no access code', () => {
32
+ delete process.env.ACCESS_CODE;
33
+ ({ auth } = checkAuth({ accessCode: 'code1' }));
34
+ expect(auth).toBe(true);
35
+ ({ auth } = checkAuth({}));
36
+ expect(auth).toBe(true);
37
+ });
38
+
39
+ it('empty access code', () => {
40
+ process.env.ACCESS_CODE = '';
41
+ ({ auth } = checkAuth({ accessCode: 'code1' }));
42
+ expect(auth).toBe(true);
43
+ ({ auth } = checkAuth({}));
44
+ expect(auth).toBe(true);
45
+
46
+ process.env.ACCESS_CODE = ',,';
47
+ ({ auth } = checkAuth({ accessCode: 'code1' }));
48
+ expect(auth).toBe(true);
49
+ ({ auth } = checkAuth({}));
50
+ expect(auth).toBe(true);
51
+ });
52
+ });
@@ -1,10 +1,10 @@
1
1
  import OpenAI from 'openai';
2
2
 
3
- import { checkAuth } from '@/app/api/auth';
4
3
  import { getOpenAIAuthFromRequest } from '@/const/fetch';
5
4
  import { ChatErrorType, ErrorType } from '@/types/fetch';
6
5
 
7
6
  import { createErrorResponse } from '../../errorResponse';
7
+ import { checkAuth } from './auth';
8
8
  import { createOpenai } from './createOpenai';
9
9
 
10
10
  /**
@@ -1,8 +1,8 @@
1
1
  import { PluginRequestPayload } from '@lobehub/chat-plugin-sdk';
2
2
  import { createGatewayOnEdgeRuntime } from '@lobehub/chat-plugins-gateway';
3
3
 
4
- import { getJWTPayload } from '@/app/api/chat/auth/utils';
5
4
  import { createErrorResponse } from '@/app/api/errorResponse';
5
+ import { getJWTPayload } from '@/app/api/middleware/auth/utils';
6
6
  import { getServerConfig } from '@/config/server';
7
7
  import { LOBE_CHAT_AUTH_HEADER, OAUTH_AUTHORIZED, enableNextAuth } from '@/const/auth';
8
8
  import { LOBE_CHAT_TRACE_ID, TraceNameMap } from '@/const/trace';
@@ -0,0 +1,61 @@
1
+ import { NextResponse } from 'next/server';
2
+
3
+ import { getPreferredRegion } from '@/app/api/config';
4
+ import { createErrorResponse } from '@/app/api/errorResponse';
5
+ import { ChatCompletionErrorPayload } from '@/libs/agent-runtime';
6
+ import { TextToImagePayload } from '@/libs/agent-runtime/types';
7
+ import { ChatErrorType } from '@/types/fetch';
8
+
9
+ import { initAgentRuntimeWithUserPayload } from '../../chat/agentRuntime';
10
+ import { checkAuth } from '../../middleware/auth';
11
+
12
+ export const runtime = 'edge';
13
+
14
+ export const preferredRegion = getPreferredRegion();
15
+
16
+ // return NextResponse.json(
17
+ // {
18
+ // body: {
19
+ // endpoint: 'https://ai****ix.com/v1',
20
+ // error: {
21
+ // code: 'content_policy_violation',
22
+ // message:
23
+ // 'Your request was rejected as a result of our safety system. Image descriptions generated from your prompt may contain text that is not allowed by our safety system. If you believe this was done in error, your request may succeed if retried, or by adjusting your prompt.',
24
+ // param: null,
25
+ // type: 'invalid_request_error',
26
+ // },
27
+ // provider: 'openai',
28
+ // },
29
+ // errorType: 'OpenAIBizError',
30
+ // },
31
+ // { status: 400 },
32
+ // );
33
+
34
+ export const POST = checkAuth(async (req: Request, { params, jwtPayload }) => {
35
+ const { provider } = params;
36
+
37
+ try {
38
+ // ============ 1. init chat model ============ //
39
+ const agentRuntime = await initAgentRuntimeWithUserPayload(provider, jwtPayload);
40
+
41
+ // ============ 2. create chat completion ============ //
42
+
43
+ const data = (await req.json()) as TextToImagePayload;
44
+
45
+ const images = await agentRuntime.textToImage(data);
46
+
47
+ return NextResponse.json(images);
48
+ } catch (e) {
49
+ const {
50
+ errorType = ChatErrorType.InternalServerError,
51
+ error: errorContent,
52
+ ...res
53
+ } = e as ChatCompletionErrorPayload;
54
+
55
+ const error = errorContent || e;
56
+ // track the error at server side
57
+ console.error(`Route: [${provider}] ${errorType}:`, error);
58
+
59
+ return createErrorResponse(errorType, { error, ...res, provider });
60
+ }
61
+ });
@@ -41,13 +41,13 @@ const GalleyGrid = memo<GalleyGridProps>(({ items, renderItem: Render }) => {
41
41
  <Flexbox gap={gap}>
42
42
  <Grid col={firstRow.length} gap={gap} max={max}>
43
43
  {firstRow.map((i, index) => (
44
- <Render {...i} key={index} />
44
+ <Render {...i} index={index} key={index} />
45
45
  ))}
46
46
  </Grid>
47
47
  {lastRow.length > 0 && (
48
48
  <Grid col={lastRow.length > 2 ? 3 : lastRow.length} gap={gap} max={max}>
49
49
  {lastRow.map((i, index) => (
50
- <Render {...i} key={index} />
50
+ <Render {...i} index={index} key={index} />
51
51
  ))}
52
52
  </Grid>
53
53
  )}
@@ -30,6 +30,8 @@ export const DB_MessageSchema = z.object({
30
30
 
31
31
  plugin: PluginSchema.optional(),
32
32
  pluginState: z.any().optional(),
33
+ pluginError: z.any().optional(),
34
+
33
35
  fromModel: z.string().optional(),
34
36
  fromProvider: z.string().optional(),
35
37
  translate: TranslateSchema.optional().or(z.literal(false)),
@@ -6,9 +6,10 @@ import { RenderAction } from '../types';
6
6
  import { ErrorActionsBar } from './Error';
7
7
  import { useCustomActions } from './customAction';
8
8
 
9
- export const AssistantActionsBar: RenderAction = memo(({ id, onActionClick, error }) => {
9
+ export const AssistantActionsBar: RenderAction = memo(({ id, onActionClick, error, tools }) => {
10
10
  const { regenerate, edit, delAndRegenerate, copy, divider, del } = useChatListActionsBar();
11
11
  const { translate, tts } = useCustomActions();
12
+ const hasTools = !!tools;
12
13
 
13
14
  if (id === 'default') return;
14
15
 
@@ -27,7 +28,7 @@ export const AssistantActionsBar: RenderAction = memo(({ id, onActionClick, erro
27
28
  delAndRegenerate,
28
29
  del,
29
30
  ]}
30
- items={[edit, copy]}
31
+ items={[hasTools ? delAndRegenerate : edit, copy]}
31
32
  onActionClick={onActionClick}
32
33
  type="ghost"
33
34
  />
@@ -1,16 +1,28 @@
1
+ import { ActionIconGroup } from '@lobehub/ui';
1
2
  import { memo } from 'react';
2
3
 
4
+ import { useChatStore } from '@/store/chat';
5
+
6
+ import { useChatListActionsBar } from '../hooks/useChatListActionsBar';
3
7
  import { RenderAction } from '../types';
4
8
 
5
- export const ToolActionsBar: RenderAction = memo(() => {
6
- return undefined;
7
- // const { regenerate } = useChatListActionsBar();
8
- // return (
9
- // <ActionIconGroup
10
- // dropdownMenu={[regenerate]}
11
- // items={[regenerate]}
12
- // onActionClick={onActionClick}
13
- // type="ghost"
14
- // />
15
- // );
9
+ export const ToolActionsBar: RenderAction = memo(({ id }) => {
10
+ const { regenerate } = useChatListActionsBar();
11
+ const [reInvokeToolMessage] = useChatStore((s) => [s.reInvokeToolMessage]);
12
+
13
+ return (
14
+ <ActionIconGroup
15
+ // dropdownMenu={[regenerate]}
16
+ items={[regenerate]}
17
+ onActionClick={(event) => {
18
+ switch (event.key) {
19
+ case 'regenerate': {
20
+ reInvokeToolMessage(id);
21
+ break;
22
+ }
23
+ }
24
+ }}
25
+ type="ghost"
26
+ />
27
+ );
16
28
  });
@@ -1,12 +1,12 @@
1
1
  import { Avatar, Highlighter, Icon } from '@lobehub/ui';
2
2
  import isEqual from 'fast-deep-equal';
3
3
  import { Loader2, LucideChevronDown, LucideChevronRight, LucideToyBrick } from 'lucide-react';
4
- import { memo, useState } from 'react';
4
+ import { CSSProperties, memo, useState } from 'react';
5
5
  import { useTranslation } from 'react-i18next';
6
6
  import { Center, Flexbox } from 'react-layout-kit';
7
7
 
8
8
  import { useChatStore } from '@/store/chat';
9
- import { chatSelectors } from '@/store/chat/slices/message/selectors';
9
+ import { chatSelectors } from '@/store/chat/selectors';
10
10
  import { pluginHelpers, useToolStore } from '@/store/tool';
11
11
  import { toolSelectors } from '@/store/tool/selectors';
12
12
 
@@ -15,15 +15,17 @@ import { useStyles } from './style';
15
15
  export interface InspectorProps {
16
16
  arguments?: string;
17
17
  identifier: string;
18
+ index: number;
18
19
  messageId: string;
20
+ style: CSSProperties;
19
21
  }
20
22
 
21
23
  const CallItem = memo<InspectorProps>(
22
- ({ arguments: requestArgs = '{}', messageId, identifier }) => {
24
+ ({ arguments: requestArgs = '{}', messageId, index, identifier, style }) => {
23
25
  const { t } = useTranslation('plugin');
24
26
  const { styles } = useStyles();
25
27
  const [open, setOpen] = useState(false);
26
- const loading = useChatStore(chatSelectors.isMessageGenerating(messageId));
28
+ const loading = useChatStore(chatSelectors.isToolCallStreaming(messageId, index));
27
29
 
28
30
  const pluginMeta = useToolStore(toolSelectors.getMetaById(identifier), isEqual);
29
31
 
@@ -32,20 +34,13 @@ const CallItem = memo<InspectorProps>(
32
34
  const pluginTitle = pluginHelpers.getPluginTitle(pluginMeta) ?? t('unknownPlugin');
33
35
 
34
36
  const avatar = pluginAvatar ? (
35
- <Avatar avatar={pluginAvatar} size={32} />
37
+ <Avatar alt={pluginTitle} avatar={pluginAvatar} size={32} />
36
38
  ) : (
37
39
  <Icon icon={LucideToyBrick} />
38
40
  );
39
41
 
40
- let params;
41
- try {
42
- params = JSON.stringify(JSON.parse(requestArgs), null, 2);
43
- } catch {
44
- params = requestArgs;
45
- }
46
-
47
42
  return (
48
- <Flexbox gap={8}>
43
+ <Flexbox gap={8} style={style}>
49
44
  <Flexbox
50
45
  align={'center'}
51
46
  className={styles.container}
@@ -69,7 +64,7 @@ const CallItem = memo<InspectorProps>(
69
64
  </Flexbox>
70
65
  <Icon icon={open ? LucideChevronDown : LucideChevronRight} />
71
66
  </Flexbox>
72
- {(open || loading) && <Highlighter language={'json'}>{params}</Highlighter>}
67
+ {(open || loading) && <Highlighter language={'json'}>{requestArgs}</Highlighter>}
73
68
  </Flexbox>
74
69
  );
75
70
  },
@@ -7,7 +7,7 @@ import { chatSelectors } from '@/store/chat/selectors';
7
7
  import { ChatMessage } from '@/types/message';
8
8
 
9
9
  import { DefaultMessage } from '../Default';
10
- import ToolCalls from './ToolCalls';
10
+ import ToolCall from './ToolCalls';
11
11
 
12
12
  export const AssistantMessage = memo<
13
13
  ChatMessage & {
@@ -32,12 +32,16 @@ export const AssistantMessage = memo<
32
32
  )}
33
33
  {!editing && tools && (
34
34
  <Flexbox gap={8} horizontal>
35
- {tools.map((toolCall) => (
36
- <ToolCalls
35
+ {tools.map((toolCall, index) => (
36
+ <ToolCall
37
37
  arguments={toolCall.arguments}
38
38
  identifier={toolCall.identifier}
39
+ index={index}
39
40
  key={toolCall.id}
40
41
  messageId={id}
42
+ style={{
43
+ maxWidth: `max(${100 / tools.length}%, 300px)`,
44
+ }}
41
45
  />
42
46
  ))}
43
47
  </Flexbox>
@@ -53,7 +53,7 @@ const Inspector = memo<InspectorProps>(
53
53
  const pluginTitle = pluginHelpers.getPluginTitle(pluginMeta) ?? t('unknownPlugin');
54
54
 
55
55
  const avatar = pluginAvatar ? (
56
- <Avatar avatar={pluginAvatar} size={32} />
56
+ <Avatar alt={pluginTitle} avatar={pluginAvatar} size={32} />
57
57
  ) : (
58
58
  <Icon icon={LucideToyBrick} />
59
59
  );
@@ -1,12 +1,21 @@
1
1
  import { PluginRequestPayload } from '@lobehub/chat-plugin-sdk';
2
+ import { Skeleton } from 'antd';
3
+ import dynamic from 'next/dynamic';
2
4
  import { memo } from 'react';
3
5
 
4
6
  import { LobeToolRenderType } from '@/types/tool';
5
7
 
6
- import BuiltinType from '././BuiltinType';
7
8
  import DefaultType from './DefaultType';
8
9
  import Markdown from './MarkdownType';
9
- import Standalone from './StandaloneType';
10
+
11
+ const loading = () => (
12
+ <Skeleton.Node active style={{ width: '100%' }}>
13
+ {' '}
14
+ </Skeleton.Node>
15
+ );
16
+
17
+ const Standalone = dynamic(() => import('./StandaloneType'), { loading });
18
+ const BuiltinType = dynamic(() => import('./BuiltinType'), { loading });
10
19
 
11
20
  export interface PluginRenderProps {
12
21
  content: string;