@lobehub/chat 1.110.4 → 1.110.6
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 +42 -0
- package/apps/desktop/package.json +1 -1
- package/changelog/v1.json +14 -0
- package/locales/ar/setting.json +11 -0
- package/locales/bg-BG/setting.json +11 -0
- package/locales/de-DE/setting.json +11 -0
- package/locales/en-US/setting.json +11 -0
- package/locales/es-ES/setting.json +11 -0
- package/locales/fa-IR/setting.json +11 -0
- package/locales/fr-FR/setting.json +11 -0
- package/locales/it-IT/setting.json +11 -0
- package/locales/ja-JP/setting.json +11 -0
- package/locales/ko-KR/setting.json +11 -0
- package/locales/nl-NL/setting.json +11 -0
- package/locales/pl-PL/setting.json +11 -0
- package/locales/pt-BR/setting.json +11 -0
- package/locales/ru-RU/setting.json +11 -0
- package/locales/tr-TR/setting.json +11 -0
- package/locales/vi-VN/setting.json +11 -0
- package/locales/zh-CN/setting.json +11 -0
- package/locales/zh-TW/setting.json +11 -0
- package/package.json +46 -46
- package/packages/types/src/user/settings/general.ts +3 -0
- package/src/app/[variants]/(main)/settings/common/features/Common.tsx +33 -5
- package/src/const/settings/common.ts +1 -0
- package/src/layout/GlobalProvider/AppTheme.tsx +4 -4
- package/src/libs/model-runtime/google/index.ts +8 -98
- package/src/libs/model-runtime/utils/googleErrorParser.test.ts +228 -0
- package/src/libs/model-runtime/utils/googleErrorParser.ts +228 -0
- package/src/locales/default/setting.ts +11 -0
- package/src/server/routers/lambda/agent.ts +2 -2
- package/src/server/services/user/index.ts +2 -2
- package/src/store/user/slices/settings/selectors/general.test.ts +1 -0
- package/src/store/user/slices/settings/selectors/general.ts +2 -0
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@lobehub/chat",
|
3
|
-
"version": "1.110.
|
3
|
+
"version": "1.110.6",
|
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",
|
@@ -122,26 +122,26 @@
|
|
122
122
|
"@ant-design/icons": "^5.6.1",
|
123
123
|
"@ant-design/pro-components": "^2.8.10",
|
124
124
|
"@anthropic-ai/sdk": "^0.57.0",
|
125
|
-
"@auth/core": "^0.
|
126
|
-
"@aws-sdk/client-bedrock-runtime": "^3.
|
127
|
-
"@aws-sdk/client-s3": "^3.
|
128
|
-
"@aws-sdk/s3-request-presigner": "^3.
|
125
|
+
"@auth/core": "^0.40.0",
|
126
|
+
"@aws-sdk/client-bedrock-runtime": "^3.862.0",
|
127
|
+
"@aws-sdk/client-s3": "^3.862.0",
|
128
|
+
"@aws-sdk/s3-request-presigner": "^3.862.0",
|
129
129
|
"@azure-rest/ai-inference": "1.0.0-beta.5",
|
130
130
|
"@azure/core-auth": "^1.10.0",
|
131
131
|
"@cfworker/json-schema": "^4.1.1",
|
132
|
-
"@clerk/localizations": "^3.20.
|
133
|
-
"@clerk/nextjs": "^6.
|
134
|
-
"@clerk/themes": "^2.4.
|
132
|
+
"@clerk/localizations": "^3.20.7",
|
133
|
+
"@clerk/nextjs": "^6.29.0",
|
134
|
+
"@clerk/themes": "^2.4.5",
|
135
135
|
"@codesandbox/sandpack-react": "^2.20.0",
|
136
136
|
"@cyntler/react-doc-viewer": "^1.17.0",
|
137
137
|
"@electric-sql/pglite": "0.2.17",
|
138
138
|
"@fal-ai/client": "^1.6.1",
|
139
139
|
"@formkit/auto-animate": "^0.8.2",
|
140
|
-
"@google/genai": "^1.
|
140
|
+
"@google/genai": "^1.13.0",
|
141
141
|
"@huggingface/inference": "^2.8.1",
|
142
142
|
"@icons-pack/react-simple-icons": "9.6.0",
|
143
143
|
"@khmyznikov/pwa-install": "0.3.9",
|
144
|
-
"@langchain/community": "^0.3.
|
144
|
+
"@langchain/community": "^0.3.50",
|
145
145
|
"@lobechat/electron-client-ipc": "workspace:*",
|
146
146
|
"@lobechat/electron-server-ipc": "workspace:*",
|
147
147
|
"@lobechat/file-loaders": "workspace:*",
|
@@ -150,29 +150,29 @@
|
|
150
150
|
"@lobehub/charts": "^2.0.0",
|
151
151
|
"@lobehub/chat-plugin-sdk": "^1.32.4",
|
152
152
|
"@lobehub/chat-plugins-gateway": "^1.9.0",
|
153
|
-
"@lobehub/icons": "^2.
|
153
|
+
"@lobehub/icons": "^2.25.0",
|
154
154
|
"@lobehub/market-sdk": "^0.22.7",
|
155
155
|
"@lobehub/tts": "^2.0.1",
|
156
|
-
"@lobehub/ui": "^2.
|
157
|
-
"@modelcontextprotocol/sdk": "^1.
|
156
|
+
"@lobehub/ui": "^2.8.3",
|
157
|
+
"@modelcontextprotocol/sdk": "^1.17.1",
|
158
158
|
"@neondatabase/serverless": "^1.0.1",
|
159
|
-
"@next/third-parties": "^15.4.
|
159
|
+
"@next/third-parties": "^15.4.6",
|
160
160
|
"@react-spring/web": "^9.7.5",
|
161
|
-
"@sentry/nextjs": "^7.120.
|
161
|
+
"@sentry/nextjs": "^7.120.4",
|
162
162
|
"@serwist/next": "^9.1.1",
|
163
|
-
"@t3-oss/env-nextjs": "^0.
|
164
|
-
"@tanstack/react-query": "^5.
|
165
|
-
"@trpc/client": "^11.4.
|
166
|
-
"@trpc/next": "^11.4.
|
167
|
-
"@trpc/react-query": "^11.4.
|
168
|
-
"@trpc/server": "^11.4.
|
163
|
+
"@t3-oss/env-nextjs": "^0.13.8",
|
164
|
+
"@tanstack/react-query": "^5.84.1",
|
165
|
+
"@trpc/client": "^11.4.4",
|
166
|
+
"@trpc/next": "^11.4.4",
|
167
|
+
"@trpc/react-query": "^11.4.4",
|
168
|
+
"@trpc/server": "^11.4.4",
|
169
169
|
"@vercel/analytics": "^1.5.0",
|
170
170
|
"@vercel/edge-config": "^1.4.0",
|
171
|
-
"@vercel/functions": "^2.2.
|
171
|
+
"@vercel/functions": "^2.2.8",
|
172
172
|
"@vercel/speed-insights": "^1.2.0",
|
173
173
|
"@xterm/xterm": "^5.5.0",
|
174
174
|
"ahooks": "^3.9.0",
|
175
|
-
"antd": "^5.26.
|
175
|
+
"antd": "^5.26.7",
|
176
176
|
"antd-style": "^3.7.1",
|
177
177
|
"brotli-wasm": "^3.0.1",
|
178
178
|
"chroma-js": "^3.1.2",
|
@@ -182,16 +182,16 @@
|
|
182
182
|
"debug": "^4.4.1",
|
183
183
|
"dexie": "^3.2.7",
|
184
184
|
"diff": "^7.0.0",
|
185
|
-
"drizzle-orm": "^0.44.
|
185
|
+
"drizzle-orm": "^0.44.4",
|
186
186
|
"drizzle-zod": "^0.5.1",
|
187
187
|
"epub2": "^3.0.2",
|
188
188
|
"fast-deep-equal": "^3.1.3",
|
189
189
|
"file-type": "^20.5.0",
|
190
|
-
"framer-motion": "^12.23.
|
190
|
+
"framer-motion": "^12.23.12",
|
191
191
|
"gpt-tokenizer": "^2.9.0",
|
192
192
|
"gray-matter": "^4.0.3",
|
193
193
|
"html-to-text": "^9.0.5",
|
194
|
-
"i18next": "^
|
194
|
+
"i18next": "^25.3.2",
|
195
195
|
"i18next-browser-languagedetector": "^8.2.0",
|
196
196
|
"i18next-resources-to-backend": "^1.2.1",
|
197
197
|
"idb-keyval": "^6.2.2",
|
@@ -205,7 +205,7 @@
|
|
205
205
|
"langfuse-core": "^3.38.4",
|
206
206
|
"lodash-es": "^4.17.21",
|
207
207
|
"lucide-react": "^0.536.0",
|
208
|
-
"mammoth": "^1.
|
208
|
+
"mammoth": "^1.10.0",
|
209
209
|
"markdown-to-txt": "^2.0.1",
|
210
210
|
"mdast-util-to-markdown": "^2.1.2",
|
211
211
|
"modern-screenshot": "^4.6.5",
|
@@ -227,17 +227,17 @@
|
|
227
227
|
"pdf-parse": "^1.1.1",
|
228
228
|
"pdfjs-dist": "4.8.69",
|
229
229
|
"pg": "^8.16.3",
|
230
|
-
"pino": "^9.
|
230
|
+
"pino": "^9.8.0",
|
231
231
|
"plaiceholder": "^3.0.0",
|
232
232
|
"polished": "^4.3.1",
|
233
|
-
"posthog-js": "^1.
|
233
|
+
"posthog-js": "^1.258.6",
|
234
234
|
"pure-rand": "^7.0.1",
|
235
|
-
"pwa-install-handler": "^2.6.
|
235
|
+
"pwa-install-handler": "^2.6.3",
|
236
236
|
"query-string": "^9.2.2",
|
237
237
|
"random-words": "^2.0.1",
|
238
|
-
"react": "^19.1.
|
238
|
+
"react": "^19.1.1",
|
239
239
|
"react-confetti": "^6.4.0",
|
240
|
-
"react-dom": "^19.1.
|
240
|
+
"react-dom": "^19.1.1",
|
241
241
|
"react-fast-marquee": "^1.6.5",
|
242
242
|
"react-hotkeys-hook": "^5.1.0",
|
243
243
|
"react-i18next": "^15.6.1",
|
@@ -256,10 +256,10 @@
|
|
256
256
|
"rtl-detect": "^1.1.2",
|
257
257
|
"semver": "^7.7.2",
|
258
258
|
"sharp": "^0.34.3",
|
259
|
-
"shiki": "^3.
|
259
|
+
"shiki": "^3.9.2",
|
260
260
|
"stripe": "^17.7.0",
|
261
261
|
"superjson": "^2.2.2",
|
262
|
-
"svix": "^1.
|
262
|
+
"svix": "^1.70.1",
|
263
263
|
"swr": "^2.3.4",
|
264
264
|
"systemjs": "^6.15.1",
|
265
265
|
"tokenx": "^0.4.1",
|
@@ -272,7 +272,7 @@
|
|
272
272
|
"ws": "^8.18.3",
|
273
273
|
"y-protocols": "^1.0.6",
|
274
274
|
"y-webrtc": "^10.3.0",
|
275
|
-
"yaml": "^2.8.
|
275
|
+
"yaml": "^2.8.1",
|
276
276
|
"yjs": "^13.6.27",
|
277
277
|
"zod": "^3.25.76",
|
278
278
|
"zustand": "5.0.4",
|
@@ -287,12 +287,12 @@
|
|
287
287
|
"@lobehub/lint": "^1.26.2",
|
288
288
|
"@lobehub/market-types": "^1.11.4",
|
289
289
|
"@lobehub/seo-cli": "^1.7.0",
|
290
|
-
"@next/bundle-analyzer": "^15.4.
|
291
|
-
"@next/eslint-plugin-next": "^15.4.
|
290
|
+
"@next/bundle-analyzer": "^15.4.6",
|
291
|
+
"@next/eslint-plugin-next": "^15.4.6",
|
292
292
|
"@peculiar/webcrypto": "^1.5.0",
|
293
293
|
"@prettier/sync": "^0.6.1",
|
294
294
|
"@semantic-release/exec": "^6.0.3",
|
295
|
-
"@testing-library/jest-dom": "^6.6.
|
295
|
+
"@testing-library/jest-dom": "^6.6.4",
|
296
296
|
"@testing-library/react": "^16.3.0",
|
297
297
|
"@testing-library/user-event": "^14.6.1",
|
298
298
|
"@types/chroma-js": "^3.1.1",
|
@@ -304,12 +304,12 @@
|
|
304
304
|
"@types/json-schema": "^7.0.15",
|
305
305
|
"@types/lodash": "^4.17.20",
|
306
306
|
"@types/lodash-es": "^4.17.12",
|
307
|
-
"@types/node": "^22.
|
307
|
+
"@types/node": "^22.17.0",
|
308
308
|
"@types/numeral": "^2.0.5",
|
309
|
-
"@types/oidc-provider": "^9.1.
|
310
|
-
"@types/pg": "^8.15.
|
311
|
-
"@types/react": "^19.1.
|
312
|
-
"@types/react-dom": "^19.1.
|
309
|
+
"@types/oidc-provider": "^9.1.2",
|
310
|
+
"@types/pg": "^8.15.5",
|
311
|
+
"@types/react": "^19.1.9",
|
312
|
+
"@types/react-dom": "^19.1.7",
|
313
313
|
"@types/rtl-detect": "^1.0.3",
|
314
314
|
"@types/semver": "^7.7.0",
|
315
315
|
"@types/systemjs": "^6.15.3",
|
@@ -332,7 +332,7 @@
|
|
332
332
|
"eslint": "^8.57.1",
|
333
333
|
"eslint-plugin-mdx": "^3.6.2",
|
334
334
|
"fake-indexeddb": "^6.0.1",
|
335
|
-
"fs-extra": "^11.3.
|
335
|
+
"fs-extra": "^11.3.1",
|
336
336
|
"glob": "^11.0.3",
|
337
337
|
"happy-dom": "^17.6.3",
|
338
338
|
"husky": "^9.1.7",
|
@@ -343,7 +343,7 @@
|
|
343
343
|
"mcp-hello-world": "^1.1.2",
|
344
344
|
"mime": "^4.0.7",
|
345
345
|
"node-fetch": "^3.3.2",
|
346
|
-
"node-gyp": "^11.
|
346
|
+
"node-gyp": "^11.3.0",
|
347
347
|
"openapi-typescript": "^7.8.0",
|
348
348
|
"p-map": "^7.0.3",
|
349
349
|
"prettier": "^3.6.2",
|
@@ -354,7 +354,7 @@
|
|
354
354
|
"semantic-release": "^21.1.2",
|
355
355
|
"serwist": "^9.1.1",
|
356
356
|
"stylelint": "^15.11.0",
|
357
|
-
"tsx": "
|
357
|
+
"tsx": "^4.20.3",
|
358
358
|
"type-fest": "^4.41.0",
|
359
359
|
"typescript": "^5.9.2",
|
360
360
|
"unified": "^11.0.5",
|
@@ -2,7 +2,10 @@ import type { HighlighterProps, MermaidProps, NeutralColors, PrimaryColors } fro
|
|
2
2
|
|
3
3
|
import { ResponseAnimationStyle } from '@/types/llm';
|
4
4
|
|
5
|
+
export type AnimationMode = 'disabled' | 'agile' | 'elegant';
|
6
|
+
|
5
7
|
export interface UserGeneralConfig {
|
8
|
+
animationMode?: AnimationMode;
|
6
9
|
fontSize: number;
|
7
10
|
highlighterTheme?: HighlighterProps['theme'];
|
8
11
|
mermaidTheme?: MermaidProps['theme'];
|
@@ -2,9 +2,9 @@
|
|
2
2
|
|
3
3
|
import { Form, type FormGroupItemType, Icon, ImageSelect, InputPassword } from '@lobehub/ui';
|
4
4
|
import { Select } from '@lobehub/ui';
|
5
|
-
import { Skeleton } from 'antd';
|
5
|
+
import { Segmented, Skeleton } from 'antd';
|
6
6
|
import isEqual from 'fast-deep-equal';
|
7
|
-
import { Loader2Icon, Monitor, Moon, Sun } from 'lucide-react';
|
7
|
+
import { Ban, Gauge, Loader2Icon, Monitor, Moon, Sun, Waves } from 'lucide-react';
|
8
8
|
import { memo, useState } from 'react';
|
9
9
|
import { useTranslation } from 'react-i18next';
|
10
10
|
|
@@ -22,7 +22,7 @@ const Common = memo(() => {
|
|
22
22
|
const { t } = useTranslation('setting');
|
23
23
|
|
24
24
|
const showAccessCodeConfig = useServerConfigStore(serverConfigSelectors.enabledAccessCode);
|
25
|
-
const
|
25
|
+
const general = useUserStore((s) => settingsSelectors.currentSettings(s).general, isEqual);
|
26
26
|
const themeMode = useGlobalStore(systemStatusSelectors.themeMode);
|
27
27
|
const language = useGlobalStore(systemStatusSelectors.language);
|
28
28
|
const [setSettings, isUserStateInit] = useUserStore((s) => [s.setSettings, s.isUserStateInit]);
|
@@ -81,6 +81,34 @@ const Common = memo(() => {
|
|
81
81
|
),
|
82
82
|
label: t('settingCommon.lang.title'),
|
83
83
|
},
|
84
|
+
{
|
85
|
+
children: (
|
86
|
+
<Segmented
|
87
|
+
options={[
|
88
|
+
{
|
89
|
+
icon: <Icon icon={Ban} size={16} />,
|
90
|
+
label: t('settingAppearance.animationMode.disabled'),
|
91
|
+
value: 'disabled',
|
92
|
+
},
|
93
|
+
{
|
94
|
+
icon: <Icon icon={Gauge} size={16} />,
|
95
|
+
label: t('settingAppearance.animationMode.agile'),
|
96
|
+
value: 'agile',
|
97
|
+
},
|
98
|
+
{
|
99
|
+
icon: <Icon icon={Waves} size={16} />,
|
100
|
+
label: t('settingAppearance.animationMode.elegant'),
|
101
|
+
value: 'elegant',
|
102
|
+
},
|
103
|
+
]}
|
104
|
+
/>
|
105
|
+
),
|
106
|
+
desc: t('settingAppearance.animationMode.desc'),
|
107
|
+
label: t('settingAppearance.animationMode.title'),
|
108
|
+
minWidth: undefined,
|
109
|
+
name: 'animationMode',
|
110
|
+
},
|
111
|
+
|
84
112
|
{
|
85
113
|
children: (
|
86
114
|
<InputPassword
|
@@ -100,12 +128,12 @@ const Common = memo(() => {
|
|
100
128
|
|
101
129
|
return (
|
102
130
|
<Form
|
103
|
-
initialValues={
|
131
|
+
initialValues={general}
|
104
132
|
items={[theme]}
|
105
133
|
itemsType={'group'}
|
106
134
|
onValuesChange={async (v) => {
|
107
135
|
setLoading(true);
|
108
|
-
await setSettings({
|
136
|
+
await setSettings({ general: v });
|
109
137
|
setLoading(false);
|
110
138
|
}}
|
111
139
|
variant={'borderless'}
|
@@ -102,14 +102,12 @@ const AppTheme = memo<AppThemeProps>(
|
|
102
102
|
customFontURL,
|
103
103
|
customFontFamily,
|
104
104
|
}) => {
|
105
|
-
// console.debug('server:appearance', defaultAppearance);
|
106
|
-
// console.debug('server:primaryColor', defaultPrimaryColor);
|
107
|
-
// console.debug('server:neutralColor', defaultNeutralColor);
|
108
105
|
const themeMode = useGlobalStore(systemStatusSelectors.themeMode);
|
109
106
|
const { styles, cx, theme } = useStyles();
|
110
|
-
const [primaryColor, neutralColor] = useUserStore((s) => [
|
107
|
+
const [primaryColor, neutralColor, animationMode] = useUserStore((s) => [
|
111
108
|
userGeneralSettingsSelectors.primaryColor(s),
|
112
109
|
userGeneralSettingsSelectors.neutralColor(s),
|
110
|
+
userGeneralSettingsSelectors.animationMode(s),
|
113
111
|
]);
|
114
112
|
|
115
113
|
useEffect(() => {
|
@@ -138,6 +136,8 @@ const AppTheme = memo<AppThemeProps>(
|
|
138
136
|
cssVar: true,
|
139
137
|
token: {
|
140
138
|
fontFamily: customFontFamily ? `${customFontFamily},${theme.fontFamily}` : undefined,
|
139
|
+
motion: animationMode !== 'disabled',
|
140
|
+
motionUnit: animationMode === 'agile' ? 0.05 : 0.1,
|
141
141
|
},
|
142
142
|
}}
|
143
143
|
themeMode={themeMode}
|
@@ -14,7 +14,7 @@ import { imageUrlToBase64 } from '@/utils/imageToBase64';
|
|
14
14
|
import { safeParseJSON } from '@/utils/safeParseJSON';
|
15
15
|
|
16
16
|
import { LobeRuntimeAI } from '../BaseAI';
|
17
|
-
import { AgentRuntimeErrorType
|
17
|
+
import { AgentRuntimeErrorType } from '../error';
|
18
18
|
import {
|
19
19
|
ChatCompletionTool,
|
20
20
|
ChatMethodOptions,
|
@@ -25,6 +25,7 @@ import {
|
|
25
25
|
import { CreateImagePayload, CreateImageResponse } from '../types/image';
|
26
26
|
import { AgentRuntimeError } from '../utils/createError';
|
27
27
|
import { debugStream } from '../utils/debugStream';
|
28
|
+
import { parseGoogleErrorMessage } from '../utils/googleErrorParser';
|
28
29
|
import { StreamingResponse } from '../utils/response';
|
29
30
|
import { GoogleGenerativeAIStream, VertexAIStream } from '../utils/streams';
|
30
31
|
import { parseDataUri } from '../utils/uriParser';
|
@@ -249,7 +250,7 @@ export class LobeGoogleAI implements LobeRuntimeAI {
|
|
249
250
|
}
|
250
251
|
|
251
252
|
console.log(err);
|
252
|
-
const { errorType, error } =
|
253
|
+
const { errorType, error } = parseGoogleErrorMessage(err.message);
|
253
254
|
|
254
255
|
throw AgentRuntimeError.chat({ error, errorType, provider: this.provider });
|
255
256
|
}
|
@@ -292,7 +293,7 @@ export class LobeGoogleAI implements LobeRuntimeAI {
|
|
292
293
|
const err = error as Error;
|
293
294
|
console.error('Google AI image generation error:', err);
|
294
295
|
|
295
|
-
const { errorType, error: parsedError } =
|
296
|
+
const { errorType, error: parsedError } = parseGoogleErrorMessage(err.message);
|
296
297
|
throw AgentRuntimeError.createImage({
|
297
298
|
error: parsedError,
|
298
299
|
errorType,
|
@@ -509,59 +510,12 @@ export class LobeGoogleAI implements LobeRuntimeAI {
|
|
509
510
|
.filter((message) => message.role !== 'function')
|
510
511
|
.map(async (msg) => await this.convertOAIMessagesToGoogleMessage(msg, toolCallNameMap));
|
511
512
|
|
512
|
-
|
513
|
+
const contents = await Promise.all(pools);
|
514
|
+
|
515
|
+
// 筛除空消息: contents.parts must not be empty.
|
516
|
+
return contents.filter((content: Content) => content.parts && content.parts.length > 0);
|
513
517
|
};
|
514
518
|
|
515
|
-
private parseErrorMessage(message: string): {
|
516
|
-
error: any;
|
517
|
-
errorType: ILobeAgentRuntimeErrorType;
|
518
|
-
} {
|
519
|
-
const defaultError = {
|
520
|
-
error: { message },
|
521
|
-
errorType: AgentRuntimeErrorType.ProviderBizError,
|
522
|
-
};
|
523
|
-
|
524
|
-
if (message.includes('location is not supported'))
|
525
|
-
return { error: { message }, errorType: AgentRuntimeErrorType.LocationNotSupportError };
|
526
|
-
|
527
|
-
const startIndex = message.lastIndexOf('[');
|
528
|
-
if (startIndex === -1) {
|
529
|
-
return defaultError;
|
530
|
-
}
|
531
|
-
|
532
|
-
try {
|
533
|
-
// 从开始位置截取字符串到最后
|
534
|
-
const jsonString = message.slice(startIndex);
|
535
|
-
|
536
|
-
// 尝试解析 JSON 字符串
|
537
|
-
const json: GoogleChatErrors = JSON.parse(jsonString);
|
538
|
-
|
539
|
-
const bizError = json[0];
|
540
|
-
|
541
|
-
switch (bizError.reason) {
|
542
|
-
case 'API_KEY_INVALID': {
|
543
|
-
return { ...defaultError, errorType: AgentRuntimeErrorType.InvalidProviderAPIKey };
|
544
|
-
}
|
545
|
-
|
546
|
-
default: {
|
547
|
-
return { error: json, errorType: AgentRuntimeErrorType.ProviderBizError };
|
548
|
-
}
|
549
|
-
}
|
550
|
-
} catch {
|
551
|
-
//
|
552
|
-
}
|
553
|
-
|
554
|
-
const errorObj = this.extractErrorObjectFromError(message);
|
555
|
-
|
556
|
-
const { errorDetails } = errorObj;
|
557
|
-
|
558
|
-
if (errorDetails) {
|
559
|
-
return { error: errorDetails, errorType: AgentRuntimeErrorType.ProviderBizError };
|
560
|
-
}
|
561
|
-
|
562
|
-
return defaultError;
|
563
|
-
}
|
564
|
-
|
565
519
|
private buildGoogleTools(
|
566
520
|
tools: ChatCompletionTool[] | undefined,
|
567
521
|
payload?: ChatStreamPayload,
|
@@ -610,50 +564,6 @@ export class LobeGoogleAI implements LobeRuntimeAI {
|
|
610
564
|
};
|
611
565
|
};
|
612
566
|
|
613
|
-
private extractErrorObjectFromError(message: string) {
|
614
|
-
// 使用正则表达式匹配状态码部分 [数字 描述文本]
|
615
|
-
const regex = /^(.*?)(\[\d+ [^\]]+])(.*)$/;
|
616
|
-
const match = message.match(regex);
|
617
|
-
|
618
|
-
if (match) {
|
619
|
-
const prefix = match[1].trim();
|
620
|
-
const statusCodeWithBrackets = match[2].trim();
|
621
|
-
const message = match[3].trim();
|
622
|
-
|
623
|
-
// 提取状态码数字
|
624
|
-
const statusCodeMatch = statusCodeWithBrackets.match(/\[(\d+)/);
|
625
|
-
const statusCode = statusCodeMatch ? parseInt(statusCodeMatch[1]) : null;
|
626
|
-
|
627
|
-
// 创建包含状态码和消息的JSON
|
628
|
-
const resultJson = {
|
629
|
-
message: message,
|
630
|
-
statusCode: statusCode,
|
631
|
-
statusCodeText: statusCodeWithBrackets,
|
632
|
-
};
|
633
|
-
|
634
|
-
return {
|
635
|
-
errorDetails: resultJson,
|
636
|
-
prefix: prefix,
|
637
|
-
};
|
638
|
-
}
|
639
|
-
|
640
|
-
// 如果无法匹配,返回原始消息
|
641
|
-
return {
|
642
|
-
errorDetails: null,
|
643
|
-
prefix: message,
|
644
|
-
};
|
645
|
-
}
|
646
567
|
}
|
647
568
|
|
648
569
|
export default LobeGoogleAI;
|
649
|
-
|
650
|
-
type GoogleChatErrors = GoogleChatError[];
|
651
|
-
|
652
|
-
interface GoogleChatError {
|
653
|
-
'@type': string;
|
654
|
-
'domain': string;
|
655
|
-
'metadata': {
|
656
|
-
service: string;
|
657
|
-
};
|
658
|
-
'reason': string;
|
659
|
-
}
|