@lobehub/lobehub 2.0.0-next.61 → 2.0.0-next.62
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 +25 -0
- package/changelog/v1.json +5 -0
- package/package.json +1 -1
- package/src/app/(backend)/middleware/auth/index.ts +7 -2
- package/src/app/(backend)/trpc/async/[trpc]/route.ts +9 -3
- package/src/app/(backend)/trpc/desktop/[trpc]/route.ts +9 -3
- package/src/app/(backend)/trpc/lambda/[trpc]/route.ts +9 -3
- package/src/app/(backend)/trpc/mobile/[trpc]/route.ts +9 -3
- package/src/app/(backend)/trpc/tools/[trpc]/route.ts +9 -3
- package/src/libs/trpc/utils/request-adapter.ts +20 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,31 @@
|
|
|
2
2
|
|
|
3
3
|
# Changelog
|
|
4
4
|
|
|
5
|
+
## [Version 2.0.0-next.62](https://github.com/lobehub/lobe-chat/compare/v2.0.0-next.61...v2.0.0-next.62)
|
|
6
|
+
|
|
7
|
+
<sup>Released on **2025-11-15**</sup>
|
|
8
|
+
|
|
9
|
+
#### 🐛 Bug Fixes
|
|
10
|
+
|
|
11
|
+
- **next16**: Resolve 'Response body object should not be disturbed or locked' error.
|
|
12
|
+
|
|
13
|
+
<br/>
|
|
14
|
+
|
|
15
|
+
<details>
|
|
16
|
+
<summary><kbd>Improvements and Fixes</kbd></summary>
|
|
17
|
+
|
|
18
|
+
#### What's fixed
|
|
19
|
+
|
|
20
|
+
- **next16**: Resolve 'Response body object should not be disturbed or locked' error, closes [#10226](https://github.com/lobehub/lobe-chat/issues/10226) ([caa9c78](https://github.com/lobehub/lobe-chat/commit/caa9c78))
|
|
21
|
+
|
|
22
|
+
</details>
|
|
23
|
+
|
|
24
|
+
<div align="right">
|
|
25
|
+
|
|
26
|
+
[](#readme-top)
|
|
27
|
+
|
|
28
|
+
</div>
|
|
29
|
+
|
|
5
30
|
## [Version 2.0.0-next.61](https://github.com/lobehub/lobe-chat/compare/v2.0.0-next.60...v2.0.0-next.61)
|
|
6
31
|
|
|
7
32
|
<sup>Released on **2025-11-15**</sup>
|
package/changelog/v1.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lobehub/lobehub",
|
|
3
|
-
"version": "2.0.0-next.
|
|
3
|
+
"version": "2.0.0-next.62",
|
|
4
4
|
"description": "LobeHub - an open-source,comprehensive AI Agent 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",
|
|
@@ -33,10 +33,15 @@ export type RequestHandler = (
|
|
|
33
33
|
|
|
34
34
|
export const checkAuth =
|
|
35
35
|
(handler: RequestHandler) => async (req: Request, options: RequestOptions) => {
|
|
36
|
+
// Clone the request to avoid "Response body object should not be disturbed or locked" error
|
|
37
|
+
// in Next.js 16 when the body stream has been consumed by Next.js internal mechanisms
|
|
38
|
+
// This ensures the handler can safely read the request body
|
|
39
|
+
const clonedReq = req.clone();
|
|
40
|
+
|
|
36
41
|
// we have a special header to debug the api endpoint in development mode
|
|
37
42
|
const isDebugApi = req.headers.get('lobe-auth-dev-backend-api') === '1';
|
|
38
43
|
if (process.env.NODE_ENV === 'development' && isDebugApi) {
|
|
39
|
-
return handler(
|
|
44
|
+
return handler(clonedReq, { ...options, jwtPayload: { userId: 'DEV_USER' } });
|
|
40
45
|
}
|
|
41
46
|
|
|
42
47
|
let jwtPayload: ClientSecretPayload;
|
|
@@ -107,5 +112,5 @@ export const checkAuth =
|
|
|
107
112
|
return createErrorResponse(errorType, { error, ...res, provider: params?.provider });
|
|
108
113
|
}
|
|
109
114
|
|
|
110
|
-
return handler(
|
|
115
|
+
return handler(clonedReq, { ...options, jwtPayload });
|
|
111
116
|
};
|
|
@@ -3,10 +3,15 @@ import type { NextRequest } from 'next/server';
|
|
|
3
3
|
|
|
4
4
|
import { pino } from '@/libs/logger';
|
|
5
5
|
import { createAsyncRouteContext } from '@/libs/trpc/async/context';
|
|
6
|
+
import { prepareRequestForTRPC } from '@/libs/trpc/utils/request-adapter';
|
|
6
7
|
import { asyncRouter } from '@/server/routers/async';
|
|
7
8
|
|
|
8
|
-
const handler = (req: NextRequest) =>
|
|
9
|
-
|
|
9
|
+
const handler = (req: NextRequest) => {
|
|
10
|
+
// Clone the request to avoid "Response body object should not be disturbed or locked" error
|
|
11
|
+
// in Next.js 16 when the body stream has been consumed by Next.js internal mechanisms
|
|
12
|
+
const preparedReq = prepareRequestForTRPC(req);
|
|
13
|
+
|
|
14
|
+
return fetchRequestHandler({
|
|
10
15
|
// 避免请求之间互相影响
|
|
11
16
|
// https://github.com/lobehub/lobe-chat/discussions/7442#discussioncomment-13658563
|
|
12
17
|
allowBatching: false,
|
|
@@ -23,8 +28,9 @@ const handler = (req: NextRequest) =>
|
|
|
23
28
|
console.error(error);
|
|
24
29
|
},
|
|
25
30
|
|
|
26
|
-
req,
|
|
31
|
+
req: preparedReq,
|
|
27
32
|
router: asyncRouter,
|
|
28
33
|
});
|
|
34
|
+
};
|
|
29
35
|
|
|
30
36
|
export { handler as GET, handler as POST };
|
|
@@ -3,10 +3,15 @@ import type { NextRequest } from 'next/server';
|
|
|
3
3
|
|
|
4
4
|
import { pino } from '@/libs/logger';
|
|
5
5
|
import { createLambdaContext } from '@/libs/trpc/lambda/context';
|
|
6
|
+
import { prepareRequestForTRPC } from '@/libs/trpc/utils/request-adapter';
|
|
6
7
|
import { desktopRouter } from '@/server/routers/desktop';
|
|
7
8
|
|
|
8
|
-
const handler = (req: NextRequest) =>
|
|
9
|
-
|
|
9
|
+
const handler = (req: NextRequest) => {
|
|
10
|
+
// Clone the request to avoid "Response body object should not be disturbed or locked" error
|
|
11
|
+
// in Next.js 16 when the body stream has been consumed by Next.js internal mechanisms
|
|
12
|
+
const preparedReq = prepareRequestForTRPC(req);
|
|
13
|
+
|
|
14
|
+
return fetchRequestHandler({
|
|
10
15
|
/**
|
|
11
16
|
* @link https://trpc.io/docs/v11/context
|
|
12
17
|
*/
|
|
@@ -19,7 +24,7 @@ const handler = (req: NextRequest) =>
|
|
|
19
24
|
console.error(error);
|
|
20
25
|
},
|
|
21
26
|
|
|
22
|
-
req,
|
|
27
|
+
req: preparedReq,
|
|
23
28
|
responseMeta({ ctx }) {
|
|
24
29
|
const headers = ctx?.resHeaders;
|
|
25
30
|
|
|
@@ -27,5 +32,6 @@ const handler = (req: NextRequest) =>
|
|
|
27
32
|
},
|
|
28
33
|
router: desktopRouter,
|
|
29
34
|
});
|
|
35
|
+
};
|
|
30
36
|
|
|
31
37
|
export { handler as GET, handler as POST };
|
|
@@ -3,10 +3,15 @@ import type { NextRequest } from 'next/server';
|
|
|
3
3
|
|
|
4
4
|
import { pino } from '@/libs/logger';
|
|
5
5
|
import { createLambdaContext } from '@/libs/trpc/lambda/context';
|
|
6
|
+
import { prepareRequestForTRPC } from '@/libs/trpc/utils/request-adapter';
|
|
6
7
|
import { lambdaRouter } from '@/server/routers/lambda';
|
|
7
8
|
|
|
8
|
-
const handler = (req: NextRequest) =>
|
|
9
|
-
|
|
9
|
+
const handler = (req: NextRequest) => {
|
|
10
|
+
// Clone the request to avoid "Response body object should not be disturbed or locked" error
|
|
11
|
+
// in Next.js 16 when the body stream has been consumed by Next.js internal mechanisms
|
|
12
|
+
const preparedReq = prepareRequestForTRPC(req);
|
|
13
|
+
|
|
14
|
+
return fetchRequestHandler({
|
|
10
15
|
/**
|
|
11
16
|
* @link https://trpc.io/docs/v11/context
|
|
12
17
|
*/
|
|
@@ -19,7 +24,7 @@ const handler = (req: NextRequest) =>
|
|
|
19
24
|
console.error(error);
|
|
20
25
|
},
|
|
21
26
|
|
|
22
|
-
req,
|
|
27
|
+
req: preparedReq,
|
|
23
28
|
responseMeta({ ctx }) {
|
|
24
29
|
const headers = ctx?.resHeaders;
|
|
25
30
|
|
|
@@ -27,5 +32,6 @@ const handler = (req: NextRequest) =>
|
|
|
27
32
|
},
|
|
28
33
|
router: lambdaRouter,
|
|
29
34
|
});
|
|
35
|
+
};
|
|
30
36
|
|
|
31
37
|
export { handler as GET, handler as POST };
|
|
@@ -3,10 +3,15 @@ import type { NextRequest } from 'next/server';
|
|
|
3
3
|
|
|
4
4
|
import { pino } from '@/libs/logger';
|
|
5
5
|
import { createLambdaContext } from '@/libs/trpc/lambda/context';
|
|
6
|
+
import { prepareRequestForTRPC } from '@/libs/trpc/utils/request-adapter';
|
|
6
7
|
import { mobileRouter } from '@/server/routers/mobile';
|
|
7
8
|
|
|
8
|
-
const handler = (req: NextRequest) =>
|
|
9
|
-
|
|
9
|
+
const handler = (req: NextRequest) => {
|
|
10
|
+
// Clone the request to avoid "Response body object should not be disturbed or locked" error
|
|
11
|
+
// in Next.js 16 when the body stream has been consumed by Next.js internal mechanisms
|
|
12
|
+
const preparedReq = prepareRequestForTRPC(req);
|
|
13
|
+
|
|
14
|
+
return fetchRequestHandler({
|
|
10
15
|
/**
|
|
11
16
|
* @link https://trpc.io/docs/v11/context
|
|
12
17
|
*/
|
|
@@ -19,7 +24,7 @@ const handler = (req: NextRequest) =>
|
|
|
19
24
|
console.error(error);
|
|
20
25
|
},
|
|
21
26
|
|
|
22
|
-
req,
|
|
27
|
+
req: preparedReq,
|
|
23
28
|
responseMeta({ ctx }) {
|
|
24
29
|
const headers = ctx?.resHeaders;
|
|
25
30
|
|
|
@@ -27,5 +32,6 @@ const handler = (req: NextRequest) =>
|
|
|
27
32
|
},
|
|
28
33
|
router: mobileRouter,
|
|
29
34
|
});
|
|
35
|
+
};
|
|
30
36
|
|
|
31
37
|
export { handler as GET, handler as POST };
|
|
@@ -3,10 +3,15 @@ import type { NextRequest } from 'next/server';
|
|
|
3
3
|
|
|
4
4
|
import { pino } from '@/libs/logger';
|
|
5
5
|
import { createLambdaContext } from '@/libs/trpc/lambda/context';
|
|
6
|
+
import { prepareRequestForTRPC } from '@/libs/trpc/utils/request-adapter';
|
|
6
7
|
import { toolsRouter } from '@/server/routers/tools';
|
|
7
8
|
|
|
8
|
-
const handler = (req: NextRequest) =>
|
|
9
|
-
|
|
9
|
+
const handler = (req: NextRequest) => {
|
|
10
|
+
// Clone the request to avoid "Response body object should not be disturbed or locked" error
|
|
11
|
+
// in Next.js 16 when the body stream has been consumed by Next.js internal mechanisms
|
|
12
|
+
const preparedReq = prepareRequestForTRPC(req);
|
|
13
|
+
|
|
14
|
+
return fetchRequestHandler({
|
|
10
15
|
/**
|
|
11
16
|
* @link https://trpc.io/docs/v11/context
|
|
12
17
|
*/
|
|
@@ -19,8 +24,9 @@ const handler = (req: NextRequest) =>
|
|
|
19
24
|
console.error(error);
|
|
20
25
|
},
|
|
21
26
|
|
|
22
|
-
req,
|
|
27
|
+
req: preparedReq,
|
|
23
28
|
router: toolsRouter,
|
|
24
29
|
});
|
|
30
|
+
};
|
|
25
31
|
|
|
26
32
|
export { handler as GET, handler as POST };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { NextRequest } from 'next/server';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Prepare Request object for tRPC fetchRequestHandler
|
|
5
|
+
*
|
|
6
|
+
* This function solves the "Response body object should not be disturbed or locked" error
|
|
7
|
+
* that occurs in Next.js 16 when the request body stream has been consumed or locked
|
|
8
|
+
* by Next.js internal mechanisms.
|
|
9
|
+
*
|
|
10
|
+
* By cloning the Request object, we create an independent body stream that tRPC can safely read.
|
|
11
|
+
*
|
|
12
|
+
* @see https://github.com/vercel/next.js/issues/83453
|
|
13
|
+
* @param req - The original NextRequest object
|
|
14
|
+
* @returns A cloned Request object with an independent body stream
|
|
15
|
+
*/
|
|
16
|
+
export function prepareRequestForTRPC(req: NextRequest): Request {
|
|
17
|
+
// Clone the Request to create an independent body stream
|
|
18
|
+
// This ensures tRPC can read the body even if the original request's body was disturbed
|
|
19
|
+
return req.clone();
|
|
20
|
+
}
|