From 595ddf52afc11eea6db14791d925e3dc938f629c Mon Sep 17 00:00:00 2001 From: "CJACK." <155826701+CJackHwang@users.noreply.github.com> Date: Sat, 9 May 2026 18:16:47 +0800 Subject: [PATCH] fix(vercel): align js stream path guard with go chat alias --- internal/js/chat-stream/index.js | 2 +- tests/node/chat-stream.test.js | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/internal/js/chat-stream/index.js b/internal/js/chat-stream/index.js index 398fc9b..af9b264 100644 --- a/internal/js/chat-stream/index.js +++ b/internal/js/chat-stream/index.js @@ -88,7 +88,7 @@ function isVercelRuntime() { function isNodeStreamSupportedPath(rawURL) { const path = extractPathname(rawURL); - return path === '/v1/chat/completions'; + return path === '/v1/chat/completions' || path === '/chat/completions'; } function extractPathname(rawURL) { diff --git a/tests/node/chat-stream.test.js b/tests/node/chat-stream.test.js index 5ac771b..cf49fa1 100644 --- a/tests/node/chat-stream.test.js +++ b/tests/node/chat-stream.test.js @@ -758,9 +758,11 @@ test('shouldSkipPath skips dynamic response/fragments/*/status paths only', () = assert.equal(shouldSkipPath('response/status'), false); }); -test('node stream path guard only allows /v1/chat/completions', () => { +test('node stream path guard allows OpenAI v1 and root alias chat completions paths', () => { assert.equal(isNodeStreamSupportedPath('/v1/chat/completions'), true); assert.equal(isNodeStreamSupportedPath('/v1/chat/completions?x=1'), true); + assert.equal(isNodeStreamSupportedPath('/chat/completions'), true); + assert.equal(isNodeStreamSupportedPath('/chat/completions?x=1'), true); assert.equal(isNodeStreamSupportedPath('/v1beta/models/gemini-2.5-flash:streamGenerateContent'), false); assert.equal(isNodeStreamSupportedPath('/anthropic/v1/messages'), false); }); @@ -768,6 +770,7 @@ test('node stream path guard only allows /v1/chat/completions', () => { test('extractPathname strips query only', () => { assert.equal(extractPathname('/v1/chat/completions?stream=true'), '/v1/chat/completions'); assert.equal(extractPathname('/v1beta/models/gemini-2.5-flash:streamGenerateContent?key=1'), '/v1beta/models/gemini-2.5-flash:streamGenerateContent'); + assert.equal(extractPathname('/chat/completions?stream=true'), '/chat/completions'); }); test('setCorsHeaders reflects requested third-party headers and blocks internal-only headers', () => {