@lobehub/chat 1.36.2 → 1.36.4

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 CHANGED
@@ -2,6 +2,48 @@
2
2
 
3
3
  # Changelog
4
4
 
5
+ ### [Version 1.36.4](https://github.com/lobehub/lobe-chat/compare/v1.36.3...v1.36.4)
6
+
7
+ <sup>Released on **2024-12-09**</sup>
8
+
9
+ <br/>
10
+
11
+ <details>
12
+ <summary><kbd>Improvements and Fixes</kbd></summary>
13
+
14
+ </details>
15
+
16
+ <div align="right">
17
+
18
+ [![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)
19
+
20
+ </div>
21
+
22
+ ### [Version 1.36.3](https://github.com/lobehub/lobe-chat/compare/v1.36.2...v1.36.3)
23
+
24
+ <sup>Released on **2024-12-08**</sup>
25
+
26
+ #### 🐛 Bug Fixes
27
+
28
+ - **misc**: Support request headers for chat.
29
+
30
+ <br/>
31
+
32
+ <details>
33
+ <summary><kbd>Improvements and Fixes</kbd></summary>
34
+
35
+ #### What's fixed
36
+
37
+ - **misc**: Support request headers for chat, closes [#4934](https://github.com/lobehub/lobe-chat/issues/4934) ([8cdc062](https://github.com/lobehub/lobe-chat/commit/8cdc062))
38
+
39
+ </details>
40
+
41
+ <div align="right">
42
+
43
+ [![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)
44
+
45
+ </div>
46
+
5
47
  ### [Version 1.36.2](https://github.com/lobehub/lobe-chat/compare/v1.36.1...v1.36.2)
6
48
 
7
49
  <sup>Released on **2024-12-07**</sup>
package/changelog/v1.json CHANGED
@@ -1,4 +1,18 @@
1
1
  [
2
+ {
3
+ "children": {},
4
+ "date": "2024-12-09",
5
+ "version": "1.36.4"
6
+ },
7
+ {
8
+ "children": {
9
+ "fixes": [
10
+ "Support request headers for chat."
11
+ ]
12
+ },
13
+ "date": "2024-12-08",
14
+ "version": "1.36.3"
15
+ },
2
16
  {
3
17
  "children": {
4
18
  "improvements": [
@@ -17,8 +17,6 @@ We are excited to announce the official release of the long-awaited database Doc
17
17
  - **Cloud Synchronization**: Enjoy a seamless cloud data synchronization experience right after deployment.
18
18
  - **Flexible Authentication**: Supports integration with third-party SSO service providers like Auth0.
19
19
 
20
- ![LobeChat Database Docker Deployment Diagram](https://github.com/user-attachments/assets/database-docker-deploy)
21
-
22
20
  ## 📘 Upgraded Deployment Documentation
23
21
 
24
22
  To ensure users can complete the deployment smoothly, we have optimized the structure of our deployment documentation:
@@ -14,8 +14,6 @@ description: LobeChat v1.8.0 推出官方数据库 Docker 镜像,支持云端
14
14
  - **云端同步**:部署后即可享受流畅的云端数据同步体验
15
15
  - **灵活认证**:支持与 Auth0 等第三方 SSO 服务提供商集成
16
16
 
17
- ![LobeChat Database Docker 部署示意图](https://github.com/user-attachments/assets/database-docker-deploy)
18
-
19
17
  ## 📘 部署文档全新升级
20
18
 
21
19
  为确保用户能够顺利完成部署,我们优化了部署文档的结构:
@@ -17,7 +17,7 @@ In this version, we have nearly fully replicated the core features of Claude Art
17
17
 
18
18
  It is worth mentioning that the Python code execution feature has also been developed and will be available in future versions. At that time, users will be able to utilize both Claude Artifacts and OpenAI Code Interpreter, significantly enhancing the practicality of the AI assistant.
19
19
 
20
- ![Artifacts Feature Showcase](https://github.com/user-attachments/artifacts-demo.png)
20
+ ![Artifacts Feature Showcase](https://github.com/user-attachments/assets/639ed70b-abc5-476f-9eb0-10c739e5a115)
21
21
 
22
22
  ## 🔍 New Discovery Page: Explore More Possibilities
23
23
 
@@ -19,7 +19,7 @@ description: >-
19
19
 
20
20
  值得一提的是,Python 代码执行功能也已完成开发,将在后续版本中与大家见面。届时,用户将能够同时运用 Claude Artifacts 和 OpenAI Code Interpreter 这两大强大工具,极大提升 AI 助手的实用性。
21
21
 
22
- ![Artifacts 功能展示](https://github.com/user-attachments/artifacts-demo.png)
22
+ ![Artifacts 功能展示](https://github.com/user-attachments/assets/2787824c-a13c-466c-ba6f-820bddfe099f)
23
23
 
24
24
  ## 🔍 全新发现页面:探索更多可能
25
25
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/chat",
3
- "version": "1.36.2",
3
+ "version": "1.36.4",
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",
@@ -151,7 +151,7 @@
151
151
  "debug": "^4.3.7",
152
152
  "dexie": "^3.2.7",
153
153
  "diff": "^5.2.0",
154
- "drizzle-orm": "^0.36.0",
154
+ "drizzle-orm": "^0.37.0",
155
155
  "drizzle-zod": "^0.5.1",
156
156
  "fast-deep-equal": "^3.1.3",
157
157
  "file-type": "^19.6.0",
@@ -194,6 +194,7 @@
194
194
  "pwa-install-handler": "^2.6.1",
195
195
  "query-string": "^9.1.1",
196
196
  "random-words": "^2.0.1",
197
+ "re-resizable": "6.10.1",
197
198
  "react": "^18.3.1",
198
199
  "react-confetti": "^6.1.0",
199
200
  "react-dom": "^18.3.1",
@@ -275,7 +276,7 @@
275
276
  "consola": "^3.2.3",
276
277
  "dotenv": "^16.4.5",
277
278
  "dpdm-fast": "^1.0.4",
278
- "drizzle-kit": "^0.28.0",
279
+ "drizzle-kit": "^0.29.0",
279
280
  "eslint": "^8.57.1",
280
281
  "eslint-plugin-mdx": "^2.3.4",
281
282
  "eslint-plugin-unused-imports": "4.0.1",
@@ -96,7 +96,14 @@ export interface ChatStreamPayload {
96
96
 
97
97
  export interface ChatCompetitionOptions {
98
98
  callback?: ChatStreamCallbacks;
99
+ /**
100
+ * response headers
101
+ */
99
102
  headers?: Record<string, any>;
103
+ /**
104
+ * send the request to the ai api endpoint
105
+ */
106
+ requestHeaders?: Record<string, any>;
100
107
  signal?: AbortSignal;
101
108
  /**
102
109
  * userId for the chat completion
@@ -211,7 +211,7 @@ export const LobeOpenAICompatibleFactory = <T extends Record<string, any> = any>
211
211
  },
212
212
  {
213
213
  // https://github.com/lobehub/lobe-chat/pull/318
214
- headers: { Accept: '*/*' },
214
+ headers: { Accept: '*/*', ...options?.requestHeaders },
215
215
  signal: options?.signal,
216
216
  },
217
217
  );
@@ -0,0 +1,54 @@
1
+ import { describe, expect, it } from 'vitest';
2
+
3
+ import { getClientIP } from './clientIP';
4
+
5
+ describe('getClientIP', () => {
6
+ // Helper function to create Headers object
7
+ const createHeaders = (entries: [string, string][]) => {
8
+ return new Headers(entries);
9
+ };
10
+
11
+ it('should return null when no IP headers are present', () => {
12
+ const headers = createHeaders([]);
13
+ expect(getClientIP(headers)).toBe('');
14
+ });
15
+
16
+ it('should handle Cloudflare IP header', () => {
17
+ const headers = createHeaders([['cf-connecting-ip', '1.2.3.4']]);
18
+ expect(getClientIP(headers)).toBe('1.2.3.4');
19
+ });
20
+
21
+ it('should handle x-forwarded-for with single IP', () => {
22
+ const headers = createHeaders([['x-forwarded-for', '5.6.7.8']]);
23
+ expect(getClientIP(headers)).toBe('5.6.7.8');
24
+ });
25
+
26
+ it('should handle x-forwarded-for with multiple IPs and return the first one', () => {
27
+ const headers = createHeaders([['x-forwarded-for', '9.10.11.12, 13.14.15.16, 17.18.19.20']]);
28
+ expect(getClientIP(headers)).toBe('9.10.11.12');
29
+ });
30
+
31
+ it('should handle x-real-ip header', () => {
32
+ const headers = createHeaders([['x-real-ip', '21.22.23.24']]);
33
+ expect(getClientIP(headers)).toBe('21.22.23.24');
34
+ });
35
+
36
+ it('should trim whitespace from IP addresses', () => {
37
+ const headers = createHeaders([['x-client-ip', ' 25.26.27.28 ']]);
38
+ expect(getClientIP(headers)).toBe('25.26.27.28');
39
+ });
40
+
41
+ it('should respect header priority order', () => {
42
+ const headers = createHeaders([
43
+ ['x-forwarded-for', '1.1.1.1'],
44
+ ['cf-connecting-ip', '2.2.2.2'], // Should take precedence
45
+ ['x-real-ip', '3.3.3.3'],
46
+ ]);
47
+ expect(getClientIP(headers)).toBe('2.2.2.2');
48
+ });
49
+
50
+ it('should handle empty x-forwarded-for value', () => {
51
+ const headers = createHeaders([['x-forwarded-for', '']]);
52
+ expect(getClientIP(headers)).toBe('');
53
+ });
54
+ });
@@ -0,0 +1,34 @@
1
+ /**
2
+ * 获取客户端 IP
3
+ * @param headers HTTP 请求头
4
+ */
5
+ export const getClientIP = (headers: Headers): string => {
6
+ // 按优先级顺序检查各种 IP 头
7
+ const ipHeaders = [
8
+ 'cf-connecting-ip', // Cloudflare
9
+ 'x-real-ip', // Nginx proxy
10
+ 'x-forwarded-for', // 标准代理头
11
+ 'x-client-ip', // Apache
12
+ 'true-client-ip', // Akamai and Cloudflare
13
+ 'x-cluster-client-ip', // 负载均衡
14
+ 'forwarded', // RFC 7239
15
+ 'fastly-client-ip', // Fastly CDN
16
+ 'x-forwarded', // General forward
17
+ 'x-original-forwarded-for', // Original forwarded
18
+ ];
19
+
20
+ for (const header of ipHeaders) {
21
+ const value = headers.get(header);
22
+ if (!value) continue;
23
+
24
+ // 处理可能包含多个 IP 的情况(比如 x-forwarded-for)
25
+ if (header.toLowerCase() === 'x-forwarded-for') {
26
+ const firstIP = value.split(',')[0].trim();
27
+ if (firstIP) return firstIP;
28
+ }
29
+
30
+ return value.trim();
31
+ }
32
+
33
+ return '';
34
+ };