diff --git a/middleware.ts b/middleware.ts index 5e90d8e5..a55d7f83 100644 --- a/middleware.ts +++ b/middleware.ts @@ -51,12 +51,26 @@ export default async function middleware(request: NextRequest) { const hostHeader = headers.get('x-forwarded-host') || headers.get('host') || fallbackHost; urlObj.protocol = proto; - - effectiveRequest = new NextRequest(urlObj, { - headers: request.headers, - method: request.method, - body: request.body, - }); + // Do NOT reconstruct NextRequest for GET/HEAD requests to avoid stream locking/piping errors. + // next-intl middleware primarily uses the URL and headers, so a simplified request-like object + // or a redirected URL is often enough. For robustness, we only clone if we really have to. + if (method === 'GET' || method === 'HEAD') { + // In Next.js 15+, we can clone headers but avoid re-passing the body stream. + effectiveRequest = new NextRequest(urlObj, { + headers: new Headers(request.headers), + method: request.method, + // No body for GET/HEAD + }); + } else { + // For POST/PUT etc, we must be careful. Re-passing the body can only be done once. + // If we don't need to fix the URL for the body-reading part, we can skip it. + // But usually intl-middleware doesn't care about the body. + effectiveRequest = new NextRequest(urlObj, { + headers: new Headers(request.headers), + method: request.method, + body: request.body, + }); + } if (process.env.NODE_ENV !== 'production' || !process.env.CI) { console.log( diff --git a/patches/@mintel__payload-ai@1.9.15.patch b/patches/@mintel__payload-ai@1.9.15.patch index 3593550a..5bac5422 100644 --- a/patches/@mintel__payload-ai@1.9.15.patch +++ b/patches/@mintel__payload-ai@1.9.15.patch @@ -129,3 +129,16 @@ index 9081ae77d4eae53ce660e285c1a6babde99ceaab..f262f1dd0fd1199734024cc27905d956 export const ChatWindowProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => { return ( + +diff --git a/dist/endpoints/chatEndpoint.js b/dist/endpoints/chatEndpoint.js +--- a/dist/endpoints/chatEndpoint.js ++++ b/dist/endpoints/chatEndpoint.js +@@ -50,7 +50,7 @@ + try { + const result = streamText({ + // @ts-ignore - AI SDK type mismatch +- model: openrouter('google/gemini-3.0-flash'), ++ model: openrouter('google/gemini-3.1-flash-lite-preview'), + messages, + tools: activeTools, + system: `You are a helpful Payload CMS MCP Assistant orchestrating the local Mintel ecosystem.