mirror of
https://github.com/CJackHwang/ds2api.git
synced 2026-05-17 06:35:14 +08:00
Restrict Vercel Node stream path to OpenAI chat to avoid Gemini empty responses
This commit is contained in:
@@ -59,8 +59,9 @@ async function handler(req, res) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Keep all non-stream behavior on Go side to avoid compatibility regressions.
|
||||
if (!toBool(payload.stream)) {
|
||||
// Keep all non-stream behavior and non-OpenAI-chat paths on Go side to avoid
|
||||
// protocol-shape regressions (e.g. Gemini/Claude clients expecting their own formats).
|
||||
if (!toBool(payload.stream) || !isNodeStreamSupportedPath(req.url || '')) {
|
||||
await proxyToGo(req, res, rawBody);
|
||||
return;
|
||||
}
|
||||
@@ -76,6 +77,23 @@ function isVercelRuntime() {
|
||||
return asString(process.env.VERCEL) !== '' || asString(process.env.NOW_REGION) !== '';
|
||||
}
|
||||
|
||||
function isNodeStreamSupportedPath(rawURL) {
|
||||
const path = extractPathname(rawURL);
|
||||
return path === '/v1/chat/completions';
|
||||
}
|
||||
|
||||
function extractPathname(rawURL) {
|
||||
const text = asString(rawURL);
|
||||
if (!text) {
|
||||
return '';
|
||||
}
|
||||
const q = text.indexOf('?');
|
||||
if (q >= 0) {
|
||||
return text.slice(0, q);
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
module.exports = handler;
|
||||
|
||||
module.exports.__test = {
|
||||
@@ -89,4 +107,6 @@ module.exports.__test = {
|
||||
boolDefaultTrue,
|
||||
filterIncrementalToolCallDeltasByAllowed,
|
||||
estimateTokens,
|
||||
isNodeStreamSupportedPath,
|
||||
extractPathname,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user