@lobehub/chat 1.62.0 → 1.62.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/.github/ISSUE_TEMPLATE/1_bug_report_cn.yml +8 -0
- package/.github/ISSUE_TEMPLATE/config.yml +4 -1
- package/CHANGELOG.md +50 -0
- package/changelog/v1.json +18 -0
- package/locales/ar/components.json +1 -0
- package/locales/bg-BG/components.json +1 -0
- package/locales/de-DE/components.json +1 -0
- package/locales/en-US/components.json +1 -0
- package/locales/es-ES/components.json +1 -0
- package/locales/fa-IR/components.json +1 -0
- package/locales/fr-FR/components.json +1 -0
- package/locales/it-IT/components.json +1 -0
- package/locales/ja-JP/components.json +1 -0
- package/locales/ko-KR/components.json +1 -0
- package/locales/nl-NL/components.json +1 -0
- package/locales/pl-PL/components.json +1 -0
- package/locales/pt-BR/components.json +1 -0
- package/locales/ru-RU/components.json +1 -0
- package/locales/tr-TR/components.json +1 -0
- package/locales/vi-VN/components.json +1 -0
- package/locales/zh-CN/components.json +2 -1
- package/locales/zh-TW/components.json +1 -0
- package/package.json +2 -2
- package/src/config/modelProviders/sambanova.ts +4 -1
- package/src/libs/agent-runtime/azureOpenai/index.ts +20 -1
- package/src/server/services/nextAuthUser/index.test.ts +109 -0
- package/src/services/user/client.test.ts +10 -0
- package/src/services/user/server.test.ts +149 -0
@@ -2,7 +2,15 @@ name: '🐛 反馈缺陷'
|
|
2
2
|
description: '反馈一个问题缺陷'
|
3
3
|
title: '[Bug] '
|
4
4
|
labels: ['🐛 Bug']
|
5
|
+
type: Bug
|
5
6
|
body:
|
7
|
+
- type: markdown
|
8
|
+
attributes:
|
9
|
+
value: |
|
10
|
+
在创建新的 Issue 之前,请先[搜索已有问题](https://github.com/lobehub/lobe-chat/issues),如果发现已有类似的问题,请给它 **👍 点赞**,这样可以帮助我们更快地解决问题。
|
11
|
+
如果你在使用过程中遇到问题,可以尝试以下方式获取帮助:
|
12
|
+
- 在 [GitHub Discussions](https://github.com/lobehub/lobe-chat/discussions) 的版块发起讨论。
|
13
|
+
- 在 [LobeChat 社区](https://discord.gg/AYFPHvv2jT) 提问,与其他用户交流。
|
6
14
|
- type: dropdown
|
7
15
|
attributes:
|
8
16
|
label: '📦 部署环境'
|
@@ -1,4 +1,7 @@
|
|
1
1
|
contact_links:
|
2
|
-
- name:
|
2
|
+
- name: Ask a question for self-hosting | 咨询自部署问题
|
3
|
+
url: https://github.com/lobehub/lobe-chat/discussions/new?category=self-hosting-%E7%A7%81%E6%9C%89%E5%8C%96%E9%83%A8%E7%BD%B2
|
4
|
+
about: Please post questions, and ideas in discussions. | 请在讨论区发布问题和想法。
|
5
|
+
- name: Questions and ideas | 其他问题和想法
|
3
6
|
url: https://github.com/lobehub/lobe-chat/discussions/new/choose
|
4
7
|
about: Please post questions, and ideas in discussions. | 请在讨论区发布问题和想法。
|
package/CHANGELOG.md
CHANGED
@@ -2,6 +2,56 @@
|
|
2
2
|
|
3
3
|
# Changelog
|
4
4
|
|
5
|
+
### [Version 1.62.2](https://github.com/lobehub/lobe-chat/compare/v1.62.1...v1.62.2)
|
6
|
+
|
7
|
+
<sup>Released on **2025-02-20**</sup>
|
8
|
+
|
9
|
+
#### 🐛 Bug Fixes
|
10
|
+
|
11
|
+
- **misc**: Fix message roles for specific Azure OpenAI models.
|
12
|
+
|
13
|
+
<br/>
|
14
|
+
|
15
|
+
<details>
|
16
|
+
<summary><kbd>Improvements and Fixes</kbd></summary>
|
17
|
+
|
18
|
+
#### What's fixed
|
19
|
+
|
20
|
+
- **misc**: Fix message roles for specific Azure OpenAI models, closes [#6222](https://github.com/lobehub/lobe-chat/issues/6222) ([d49329a](https://github.com/lobehub/lobe-chat/commit/d49329a))
|
21
|
+
|
22
|
+
</details>
|
23
|
+
|
24
|
+
<div align="right">
|
25
|
+
|
26
|
+
[](#readme-top)
|
27
|
+
|
28
|
+
</div>
|
29
|
+
|
30
|
+
### [Version 1.62.1](https://github.com/lobehub/lobe-chat/compare/v1.62.0...v1.62.1)
|
31
|
+
|
32
|
+
<sup>Released on **2025-02-20**</sup>
|
33
|
+
|
34
|
+
#### 🐛 Bug Fixes
|
35
|
+
|
36
|
+
- **misc**: Add sambanova proxy url.
|
37
|
+
|
38
|
+
<br/>
|
39
|
+
|
40
|
+
<details>
|
41
|
+
<summary><kbd>Improvements and Fixes</kbd></summary>
|
42
|
+
|
43
|
+
#### What's fixed
|
44
|
+
|
45
|
+
- **misc**: Add sambanova proxy url, closes [#6348](https://github.com/lobehub/lobe-chat/issues/6348) ([c9cb7d9](https://github.com/lobehub/lobe-chat/commit/c9cb7d9))
|
46
|
+
|
47
|
+
</details>
|
48
|
+
|
49
|
+
<div align="right">
|
50
|
+
|
51
|
+
[](#readme-top)
|
52
|
+
|
53
|
+
</div>
|
54
|
+
|
5
55
|
## [Version 1.62.0](https://github.com/lobehub/lobe-chat/compare/v1.61.6...v1.62.0)
|
6
56
|
|
7
57
|
<sup>Released on **2025-02-20**</sup>
|
package/changelog/v1.json
CHANGED
@@ -1,4 +1,22 @@
|
|
1
1
|
[
|
2
|
+
{
|
3
|
+
"children": {
|
4
|
+
"fixes": [
|
5
|
+
"Fix message roles for specific Azure OpenAI models."
|
6
|
+
]
|
7
|
+
},
|
8
|
+
"date": "2025-02-20",
|
9
|
+
"version": "1.62.2"
|
10
|
+
},
|
11
|
+
{
|
12
|
+
"children": {
|
13
|
+
"fixes": [
|
14
|
+
"Add sambanova proxy url."
|
15
|
+
]
|
16
|
+
},
|
17
|
+
"date": "2025-02-20",
|
18
|
+
"version": "1.62.1"
|
19
|
+
},
|
2
20
|
{
|
3
21
|
"children": {
|
4
22
|
"features": [
|
@@ -77,6 +77,7 @@
|
|
77
77
|
"file": "يدعم هذا النموذج قراءة وتعرف الملفات المرفوعة",
|
78
78
|
"functionCall": "يدعم هذا النموذج استدعاء الوظائف",
|
79
79
|
"reasoning": "يدعم هذا النموذج التفكير العميق",
|
80
|
+
"search": "يدعم هذا النموذج البحث عبر الإنترنت",
|
80
81
|
"tokens": "يدعم هذا النموذج حتى {{tokens}} رمزًا في جلسة واحدة",
|
81
82
|
"vision": "يدعم هذا النموذج التعرف البصري"
|
82
83
|
},
|
@@ -77,6 +77,7 @@
|
|
77
77
|
"file": "Този модел поддържа качване на файлове и разпознаване",
|
78
78
|
"functionCall": "Този модел поддържа функционални обаждания (Function Call)",
|
79
79
|
"reasoning": "Този модел поддържа дълбочинно мислене",
|
80
|
+
"search": "Този модел поддържа търсене в мрежата",
|
80
81
|
"tokens": "Този модел поддържа до {{tokens}} токена за една сесия",
|
81
82
|
"vision": "Този модел поддържа визуално разпознаване"
|
82
83
|
},
|
@@ -77,6 +77,7 @@
|
|
77
77
|
"file": "Dieses Modell unterstützt das Hochladen von Dateien und deren Erkennung.",
|
78
78
|
"functionCall": "Dieses Modell unterstützt Funktionsaufrufe.",
|
79
79
|
"reasoning": "Dieses Modell unterstützt tiefes Denken",
|
80
|
+
"search": "Dieses Modell unterstützt die Online-Suche",
|
80
81
|
"tokens": "Dieses Modell unterstützt maximal {{tokens}} Tokens pro Sitzung.",
|
81
82
|
"vision": "Dieses Modell unterstützt die visuelle Erkennung."
|
82
83
|
},
|
@@ -77,6 +77,7 @@
|
|
77
77
|
"file": "This model supports file upload for reading and recognition.",
|
78
78
|
"functionCall": "This model supports function call.",
|
79
79
|
"reasoning": "This model supports deep thinking",
|
80
|
+
"search": "This model supports online search",
|
80
81
|
"tokens": "This model supports up to {{tokens}} tokens in a single session.",
|
81
82
|
"vision": "This model supports visual recognition."
|
82
83
|
},
|
@@ -77,6 +77,7 @@
|
|
77
77
|
"file": "Este modelo admite la carga y reconocimiento de archivos.",
|
78
78
|
"functionCall": "Este modelo admite llamadas de función.",
|
79
79
|
"reasoning": "Este modelo admite un pensamiento profundo",
|
80
|
+
"search": "Este modelo admite búsqueda en línea",
|
80
81
|
"tokens": "Este modelo admite un máximo de {{tokens}} tokens por sesión.",
|
81
82
|
"vision": "Este modelo admite el reconocimiento visual."
|
82
83
|
},
|
@@ -77,6 +77,7 @@
|
|
77
77
|
"file": "این مدل از بارگذاری و شناسایی فایلها پشتیبانی میکند",
|
78
78
|
"functionCall": "این مدل از فراخوانی توابع (Function Call) پشتیبانی میکند",
|
79
79
|
"reasoning": "این مدل از تفکر عمیق پشتیبانی میکند",
|
80
|
+
"search": "این مدل از جستجوی آنلاین پشتیبانی میکند",
|
80
81
|
"tokens": "این مدل در هر جلسه حداکثر از {{tokens}} توکن پشتیبانی میکند",
|
81
82
|
"vision": "این مدل از تشخیص بصری پشتیبانی میکند"
|
82
83
|
},
|
@@ -77,6 +77,7 @@
|
|
77
77
|
"file": "Ce modèle prend en charge la lecture et la reconnaissance de fichiers téléchargés.",
|
78
78
|
"functionCall": "Ce modèle prend en charge les appels de fonction.",
|
79
79
|
"reasoning": "Ce modèle prend en charge une réflexion approfondie",
|
80
|
+
"search": "Ce modèle prend en charge la recherche en ligne",
|
80
81
|
"tokens": "Ce modèle prend en charge jusqu'à {{tokens}} jetons par session.",
|
81
82
|
"vision": "Ce modèle prend en charge la reconnaissance visuelle."
|
82
83
|
},
|
@@ -77,6 +77,7 @@
|
|
77
77
|
"file": "Questo modello supporta il caricamento e il riconoscimento di file.",
|
78
78
|
"functionCall": "Questo modello supporta la chiamata di funzioni.",
|
79
79
|
"reasoning": "Questo modello supporta un pensiero profondo",
|
80
|
+
"search": "Questo modello supporta la ricerca online",
|
80
81
|
"tokens": "Questo modello supporta un massimo di {{tokens}} token per sessione.",
|
81
82
|
"vision": "Questo modello supporta il riconoscimento visivo."
|
82
83
|
},
|
@@ -77,6 +77,7 @@
|
|
77
77
|
"file": "このモデルはファイルのアップロードと認識をサポートしています。",
|
78
78
|
"functionCall": "このモデルは関数呼び出し(Function Call)をサポートしています。",
|
79
79
|
"reasoning": "このモデルは深い思考をサポートしています",
|
80
|
+
"search": "このモデルはオンライン検索をサポートしています",
|
80
81
|
"tokens": "このモデルは1つのセッションあたり最大{{tokens}}トークンをサポートしています。",
|
81
82
|
"vision": "このモデルはビジョン認識をサポートしています。"
|
82
83
|
},
|
@@ -77,6 +77,7 @@
|
|
77
77
|
"file": "This model supports file upload for reading and recognition.",
|
78
78
|
"functionCall": "This model supports function call.",
|
79
79
|
"reasoning": "Dit model ondersteunt diepgaand denken",
|
80
|
+
"search": "Dit model ondersteunt online zoeken",
|
80
81
|
"tokens": "This model supports up to {{tokens}} tokens in a single session.",
|
81
82
|
"vision": "This model supports visual recognition."
|
82
83
|
},
|
@@ -77,6 +77,7 @@
|
|
77
77
|
"file": "Ten model obsługuje wczytywanie plików i rozpoznawanie",
|
78
78
|
"functionCall": "Ten model obsługuje wywołania funkcji (Function Call).",
|
79
79
|
"reasoning": "Ten model wspiera głębokie myślenie",
|
80
|
+
"search": "Ten model wspiera wyszukiwanie w sieci",
|
80
81
|
"tokens": "Ten model obsługuje maksymalnie {{tokens}} tokenów w pojedynczej sesji.",
|
81
82
|
"vision": "Ten model obsługuje rozpoznawanie wizualne."
|
82
83
|
},
|
@@ -77,6 +77,7 @@
|
|
77
77
|
"file": "Este modelo suporta leitura e reconhecimento de arquivos enviados.",
|
78
78
|
"functionCall": "Este modelo suporta chamadas de função.",
|
79
79
|
"reasoning": "Este modelo suporta pensamento profundo",
|
80
|
+
"search": "Este modelo suporta pesquisa online",
|
80
81
|
"tokens": "Este modelo suporta no máximo {{tokens}} tokens por sessão.",
|
81
82
|
"vision": "Este modelo suporta reconhecimento visual."
|
82
83
|
},
|
@@ -77,6 +77,7 @@
|
|
77
77
|
"file": "Эта модель поддерживает загрузку и распознавание файлов",
|
78
78
|
"functionCall": "Эта модель поддерживает вызов функций",
|
79
79
|
"reasoning": "Эта модель поддерживает глубокое мышление",
|
80
|
+
"search": "Эта модель поддерживает поиск в интернете",
|
80
81
|
"tokens": "Эта модель поддерживает до {{tokens}} токенов в одной сессии",
|
81
82
|
"vision": "Эта модель поддерживает распознавание изображений"
|
82
83
|
},
|
@@ -77,6 +77,7 @@
|
|
77
77
|
"file": "Bu model dosya yükleme ve tanımayı destekler",
|
78
78
|
"functionCall": "Bu model fonksiyon çağrısını destekler",
|
79
79
|
"reasoning": "Bu model derin düşünmeyi destekler",
|
80
|
+
"search": "Bu model çevrimiçi aramayı destekler",
|
80
81
|
"tokens": "Bu model tek bir oturumda en fazla {{tokens}} Token destekler",
|
81
82
|
"vision": "Bu model görüntü tanımıyı destekler"
|
82
83
|
},
|
@@ -77,6 +77,7 @@
|
|
77
77
|
"file": "Mô hình này hỗ trợ tải lên và nhận diện tệp",
|
78
78
|
"functionCall": "Mô hình này hỗ trợ cuộc gọi hàm (Function Call)",
|
79
79
|
"reasoning": "Mô hình này hỗ trợ tư duy sâu sắc",
|
80
|
+
"search": "Mô hình này hỗ trợ tìm kiếm trực tuyến",
|
80
81
|
"tokens": "Mỗi phiên của mô hình này hỗ trợ tối đa {{tokens}} Tokens",
|
81
82
|
"vision": "Mô hình này hỗ trợ nhận diện hình ảnh"
|
82
83
|
},
|
@@ -77,6 +77,7 @@
|
|
77
77
|
"file": "该模型支持上传文件读取与识别",
|
78
78
|
"functionCall": "该模型支持函数调用(Function Call)",
|
79
79
|
"reasoning": "该模型支持深度思考",
|
80
|
+
"search": "该模型支持联网搜索",
|
80
81
|
"tokens": "该模型单个会话最多支持 {{tokens}} Tokens",
|
81
82
|
"vision": "该模型支持视觉识别"
|
82
83
|
},
|
@@ -115,4 +116,4 @@
|
|
115
116
|
"thought": "已深度思考(用时 {{duration}} 秒)",
|
116
117
|
"thoughtWithDuration": "已深度思考"
|
117
118
|
}
|
118
|
-
}
|
119
|
+
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@lobehub/chat",
|
3
|
-
"version": "1.62.
|
3
|
+
"version": "1.62.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",
|
@@ -159,7 +159,7 @@
|
|
159
159
|
"drizzle-orm": "^0.39.0",
|
160
160
|
"drizzle-zod": "^0.5.1",
|
161
161
|
"fast-deep-equal": "^3.1.3",
|
162
|
-
"file-type": "^
|
162
|
+
"file-type": "^20.0.0",
|
163
163
|
"framer-motion": "^11.16.0",
|
164
164
|
"gpt-tokenizer": "^2.8.1",
|
165
165
|
"i18next": "^24.2.1",
|
@@ -10,9 +10,12 @@ const SambaNova: ModelProviderCard = {
|
|
10
10
|
name: 'SambaNova',
|
11
11
|
settings: {
|
12
12
|
disableBrowserRequest: true,
|
13
|
+
proxyUrl: {
|
14
|
+
placeholder: 'https://api.sambanova.ai/v1',
|
15
|
+
},
|
13
16
|
sdkType: 'openai',
|
14
17
|
},
|
15
18
|
url: 'https://cloud.sambanova.ai',
|
16
19
|
};
|
17
20
|
|
18
|
-
export default SambaNova;
|
21
|
+
export default SambaNova;
|
@@ -33,9 +33,28 @@ export class LobeAzureOpenAI implements LobeRuntimeAI {
|
|
33
33
|
const { messages, model, ...params } = payload;
|
34
34
|
// o1 series models on Azure OpenAI does not support streaming currently
|
35
35
|
const enableStreaming = model.includes('o1') ? false : (params.stream ?? true);
|
36
|
+
|
37
|
+
// Convert 'system' role to 'user' or 'developer' based on the model
|
38
|
+
const systemToUserModels = new Set([
|
39
|
+
'o1-preview',
|
40
|
+
'o1-preview-2024-09-12',
|
41
|
+
'o1-mini',
|
42
|
+
'o1-mini-2024-09-12',
|
43
|
+
]);
|
44
|
+
|
45
|
+
const updatedMessages = messages.map((message) => ({
|
46
|
+
...message,
|
47
|
+
role:
|
48
|
+
(model.includes('o1') || model.includes('o3')) && message.role === 'system'
|
49
|
+
? [...systemToUserModels].some((sub) => model.includes(sub))
|
50
|
+
? 'user'
|
51
|
+
: 'developer'
|
52
|
+
: message.role,
|
53
|
+
}));
|
54
|
+
|
36
55
|
try {
|
37
56
|
const response = await this.client.chat.completions.create({
|
38
|
-
messages:
|
57
|
+
messages: updatedMessages as OpenAI.ChatCompletionMessageParam[],
|
39
58
|
model,
|
40
59
|
...params,
|
41
60
|
max_completion_tokens: null,
|
@@ -0,0 +1,109 @@
|
|
1
|
+
// @vitest-environment node
|
2
|
+
import { NextResponse } from 'next/server';
|
3
|
+
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
4
|
+
|
5
|
+
import { UserItem } from '@/database/schemas';
|
6
|
+
import { serverDB } from '@/database/server';
|
7
|
+
import { UserModel } from '@/database/server/models/user';
|
8
|
+
import { pino } from '@/libs/logger';
|
9
|
+
import { LobeNextAuthDbAdapter } from '@/libs/next-auth/adapter';
|
10
|
+
|
11
|
+
import { NextAuthUserService } from './index';
|
12
|
+
|
13
|
+
vi.mock('@/libs/logger', () => ({
|
14
|
+
pino: {
|
15
|
+
info: vi.fn(),
|
16
|
+
warn: vi.fn(),
|
17
|
+
},
|
18
|
+
}));
|
19
|
+
|
20
|
+
vi.mock('@/database/server/models/user');
|
21
|
+
vi.mock('@/database/server');
|
22
|
+
|
23
|
+
describe('NextAuthUserService', () => {
|
24
|
+
let service: NextAuthUserService;
|
25
|
+
|
26
|
+
beforeEach(() => {
|
27
|
+
vi.clearAllMocks();
|
28
|
+
service = new NextAuthUserService();
|
29
|
+
});
|
30
|
+
|
31
|
+
describe('safeUpdateUser', () => {
|
32
|
+
const mockUser = {
|
33
|
+
id: 'user-123',
|
34
|
+
email: 'test@example.com',
|
35
|
+
};
|
36
|
+
|
37
|
+
const mockAccount = {
|
38
|
+
provider: 'github',
|
39
|
+
providerAccountId: '12345',
|
40
|
+
};
|
41
|
+
|
42
|
+
const mockUpdateData: Partial<UserItem> = {
|
43
|
+
avatar: 'https://example.com/avatar.jpg',
|
44
|
+
email: 'new@example.com',
|
45
|
+
fullName: 'Test User',
|
46
|
+
};
|
47
|
+
|
48
|
+
it('should update user when user is found', async () => {
|
49
|
+
const mockUserModel = {
|
50
|
+
updateUser: vi.fn().mockResolvedValue({}),
|
51
|
+
};
|
52
|
+
|
53
|
+
vi.mocked(UserModel).mockImplementation(() => mockUserModel as any);
|
54
|
+
|
55
|
+
// Mock the adapter directly on the service instance
|
56
|
+
service.adapter = {
|
57
|
+
getUserByAccount: vi.fn().mockResolvedValue(mockUser),
|
58
|
+
};
|
59
|
+
|
60
|
+
const response = await service.safeUpdateUser(mockAccount, mockUpdateData);
|
61
|
+
|
62
|
+
expect(pino.info).toHaveBeenCalledWith(
|
63
|
+
`updating user "${JSON.stringify(mockAccount)}" due to webhook`,
|
64
|
+
);
|
65
|
+
|
66
|
+
expect(service.adapter.getUserByAccount).toHaveBeenCalledWith(mockAccount);
|
67
|
+
expect(UserModel).toHaveBeenCalledWith(serverDB, mockUser.id);
|
68
|
+
expect(mockUserModel.updateUser).toHaveBeenCalledWith(mockUpdateData);
|
69
|
+
|
70
|
+
expect(response).toBeInstanceOf(NextResponse);
|
71
|
+
expect(response.status).toBe(200);
|
72
|
+
const data = await response.json();
|
73
|
+
expect(data).toEqual({ message: 'user updated', success: true });
|
74
|
+
});
|
75
|
+
|
76
|
+
it('should handle case when user is not found', async () => {
|
77
|
+
// Mock the adapter directly on the service instance
|
78
|
+
service.adapter = {
|
79
|
+
getUserByAccount: vi.fn().mockResolvedValue(null),
|
80
|
+
};
|
81
|
+
|
82
|
+
const response = await service.safeUpdateUser(mockAccount, mockUpdateData);
|
83
|
+
|
84
|
+
expect(pino.warn).toHaveBeenCalledWith(
|
85
|
+
`[${mockAccount.provider}]: Webhooks handler user "${JSON.stringify(mockAccount)}" update for "${JSON.stringify(mockUpdateData)}", but no user was found by the providerAccountId.`,
|
86
|
+
);
|
87
|
+
|
88
|
+
expect(UserModel).not.toHaveBeenCalled();
|
89
|
+
|
90
|
+
expect(response).toBeInstanceOf(NextResponse);
|
91
|
+
expect(response.status).toBe(200);
|
92
|
+
const data = await response.json();
|
93
|
+
expect(data).toEqual({ message: 'user updated', success: true });
|
94
|
+
});
|
95
|
+
|
96
|
+
it('should handle errors during user update', async () => {
|
97
|
+
const mockError = new Error('Database error');
|
98
|
+
|
99
|
+
// Mock the adapter directly on the service instance
|
100
|
+
service.adapter = {
|
101
|
+
getUserByAccount: vi.fn().mockRejectedValue(mockError),
|
102
|
+
};
|
103
|
+
|
104
|
+
await expect(service.safeUpdateUser(mockAccount, mockUpdateData)).rejects.toThrow(mockError);
|
105
|
+
|
106
|
+
expect(UserModel).not.toHaveBeenCalled();
|
107
|
+
});
|
108
|
+
});
|
109
|
+
});
|
@@ -95,4 +95,14 @@ describe('ClientService', () => {
|
|
95
95
|
expect(spyOn).toHaveBeenCalledWith(newPreference);
|
96
96
|
expect(spyOn).toHaveBeenCalledTimes(1);
|
97
97
|
});
|
98
|
+
|
99
|
+
it('should return empty array for getUserSSOProviders', async () => {
|
100
|
+
const providers = await clientService.getUserSSOProviders();
|
101
|
+
expect(providers).toEqual([]);
|
102
|
+
});
|
103
|
+
|
104
|
+
it('should do nothing when unlinkSSOProvider is called', async () => {
|
105
|
+
const result = await clientService.unlinkSSOProvider('google', '123');
|
106
|
+
expect(result).toBeUndefined();
|
107
|
+
});
|
98
108
|
});
|
@@ -0,0 +1,149 @@
|
|
1
|
+
import { DeepPartial } from 'utility-types';
|
2
|
+
import { describe, expect, it, vi } from 'vitest';
|
3
|
+
|
4
|
+
import { lambdaClient } from '@/libs/trpc/client';
|
5
|
+
import { UserInitializationState, UserPreference } from '@/types/user';
|
6
|
+
import { UserSettings } from '@/types/user/settings';
|
7
|
+
|
8
|
+
import { ServerService } from './server';
|
9
|
+
|
10
|
+
vi.mock('@/libs/trpc/client', () => ({
|
11
|
+
lambdaClient: {
|
12
|
+
user: {
|
13
|
+
getUserRegistrationDuration: {
|
14
|
+
query: vi.fn(),
|
15
|
+
},
|
16
|
+
getUserState: {
|
17
|
+
query: vi.fn(),
|
18
|
+
},
|
19
|
+
getUserSSOProviders: {
|
20
|
+
query: vi.fn(),
|
21
|
+
},
|
22
|
+
unlinkSSOProvider: {
|
23
|
+
mutate: vi.fn(),
|
24
|
+
},
|
25
|
+
makeUserOnboarded: {
|
26
|
+
mutate: vi.fn(),
|
27
|
+
},
|
28
|
+
updatePreference: {
|
29
|
+
mutate: vi.fn(),
|
30
|
+
},
|
31
|
+
updateGuide: {
|
32
|
+
mutate: vi.fn(),
|
33
|
+
},
|
34
|
+
updateSettings: {
|
35
|
+
mutate: vi.fn(),
|
36
|
+
},
|
37
|
+
resetSettings: {
|
38
|
+
mutate: vi.fn(),
|
39
|
+
},
|
40
|
+
},
|
41
|
+
},
|
42
|
+
}));
|
43
|
+
|
44
|
+
describe('ServerService', () => {
|
45
|
+
const service = new ServerService();
|
46
|
+
|
47
|
+
it('should get user registration duration', async () => {
|
48
|
+
const mockData = {
|
49
|
+
createdAt: '2023-01-01',
|
50
|
+
duration: 100,
|
51
|
+
updatedAt: '2023-01-02',
|
52
|
+
};
|
53
|
+
vi.mocked(lambdaClient.user.getUserRegistrationDuration.query).mockResolvedValue(mockData);
|
54
|
+
|
55
|
+
const result = await service.getUserRegistrationDuration();
|
56
|
+
expect(result).toEqual(mockData);
|
57
|
+
});
|
58
|
+
|
59
|
+
it('should get user state', async () => {
|
60
|
+
const mockState: UserInitializationState = {
|
61
|
+
isOnboard: true,
|
62
|
+
preference: {
|
63
|
+
telemetry: true,
|
64
|
+
},
|
65
|
+
settings: {},
|
66
|
+
};
|
67
|
+
vi.mocked(lambdaClient.user.getUserState.query).mockResolvedValue(mockState);
|
68
|
+
|
69
|
+
const result = await service.getUserState();
|
70
|
+
expect(result).toEqual(mockState);
|
71
|
+
});
|
72
|
+
|
73
|
+
it('should get user SSO providers', async () => {
|
74
|
+
const mockProviders = [
|
75
|
+
{
|
76
|
+
provider: 'google',
|
77
|
+
providerAccountId: '123',
|
78
|
+
userId: 'user1',
|
79
|
+
type: 'oauth' as const,
|
80
|
+
access_token: 'token',
|
81
|
+
token_type: 'bearer' as const,
|
82
|
+
expires_at: 123,
|
83
|
+
scope: 'email profile',
|
84
|
+
},
|
85
|
+
];
|
86
|
+
vi.mocked(lambdaClient.user.getUserSSOProviders.query).mockResolvedValue(mockProviders);
|
87
|
+
|
88
|
+
const result = await service.getUserSSOProviders();
|
89
|
+
expect(result).toEqual(mockProviders);
|
90
|
+
});
|
91
|
+
|
92
|
+
it('should unlink SSO provider', async () => {
|
93
|
+
const provider = 'google';
|
94
|
+
const providerAccountId = '123';
|
95
|
+
await service.unlinkSSOProvider(provider, providerAccountId);
|
96
|
+
|
97
|
+
expect(lambdaClient.user.unlinkSSOProvider.mutate).toHaveBeenCalledWith({
|
98
|
+
provider,
|
99
|
+
providerAccountId,
|
100
|
+
});
|
101
|
+
});
|
102
|
+
|
103
|
+
it('should make user onboarded', async () => {
|
104
|
+
await service.makeUserOnboarded();
|
105
|
+
expect(lambdaClient.user.makeUserOnboarded.mutate).toHaveBeenCalled();
|
106
|
+
});
|
107
|
+
|
108
|
+
it('should update user preference', async () => {
|
109
|
+
const preference: Partial<UserPreference> = {
|
110
|
+
telemetry: true,
|
111
|
+
useCmdEnterToSend: true,
|
112
|
+
};
|
113
|
+
await service.updatePreference(preference);
|
114
|
+
expect(lambdaClient.user.updatePreference.mutate).toHaveBeenCalledWith(preference);
|
115
|
+
});
|
116
|
+
|
117
|
+
it('should update user guide', async () => {
|
118
|
+
const guide = {
|
119
|
+
moveSettingsToAvatar: true,
|
120
|
+
topic: false,
|
121
|
+
uploadFileInKnowledgeBase: true,
|
122
|
+
};
|
123
|
+
await service.updateGuide(guide);
|
124
|
+
expect(lambdaClient.user.updateGuide.mutate).toHaveBeenCalledWith(guide);
|
125
|
+
});
|
126
|
+
|
127
|
+
it('should update user settings', async () => {
|
128
|
+
const settings: DeepPartial<UserSettings> = {
|
129
|
+
defaultAgent: {
|
130
|
+
config: {
|
131
|
+
model: 'gpt-4',
|
132
|
+
provider: 'openai',
|
133
|
+
},
|
134
|
+
meta: {
|
135
|
+
avatar: 'avatar',
|
136
|
+
description: 'test agent',
|
137
|
+
},
|
138
|
+
},
|
139
|
+
};
|
140
|
+
const signal = new AbortController().signal;
|
141
|
+
await service.updateUserSettings(settings, signal);
|
142
|
+
expect(lambdaClient.user.updateSettings.mutate).toHaveBeenCalledWith(settings, { signal });
|
143
|
+
});
|
144
|
+
|
145
|
+
it('should reset user settings', async () => {
|
146
|
+
await service.resetUserSettings();
|
147
|
+
expect(lambdaClient.user.resetSettings.mutate).toHaveBeenCalled();
|
148
|
+
});
|
149
|
+
});
|