Fix AG MITM

This commit is contained in:
decolua
2026-03-01 18:40:55 +07:00
parent 7076108550
commit 50990e84b4
6 changed files with 27 additions and 24 deletions

View File

@@ -12,20 +12,19 @@ export const FORMATS = {
CURSOR: "cursor"
};
// Map endpoint suffix → source format (takes priority over body-based detection)
const ENDPOINT_FORMAT_MAP = {
"/v1/responses": FORMATS.OPENAI_RESPONSES,
"/v1/chat/completions": FORMATS.OPENAI,
};
/**
* Detect source format from request URL pathname.
* Returns null if no matching endpoint found.
* Detect source format from request URL pathname + body.
* Returns null to fall back to body-based detection.
*/
export function detectFormatByEndpoint(pathname) {
for (const [segment, format] of Object.entries(ENDPOINT_FORMAT_MAP)) {
if (pathname.includes(segment)) return format;
export function detectFormatByEndpoint(pathname, body) {
// /v1/responses is always openai-responses
if (pathname.includes("/v1/responses")) return FORMATS.OPENAI_RESPONSES;
// /v1/chat/completions + input[] → treat as openai (Cursor CLI sends Responses body via chat endpoint)
if (pathname.includes("/v1/chat/completions") && Array.isArray(body?.input)) {
return FORMATS.OPENAI;
}
return null;
}