2026-01-05 10:37:09 +07:00
|
|
|
// Format identifiers
|
|
|
|
|
export const FORMATS = {
|
|
|
|
|
OPENAI: "openai",
|
|
|
|
|
OPENAI_RESPONSES: "openai-responses",
|
|
|
|
|
OPENAI_RESPONSE: "openai-response",
|
|
|
|
|
CLAUDE: "claude",
|
|
|
|
|
GEMINI: "gemini",
|
|
|
|
|
GEMINI_CLI: "gemini-cli",
|
2026-03-26 23:46:47 -04:00
|
|
|
VERTEX: "vertex",
|
2026-01-05 10:37:09 +07:00
|
|
|
CODEX: "codex",
|
2026-01-15 18:29:47 +07:00
|
|
|
ANTIGRAVITY: "antigravity",
|
2026-02-05 11:06:20 +07:00
|
|
|
KIRO: "kiro",
|
2026-03-12 15:24:10 +07:00
|
|
|
CURSOR: "cursor",
|
|
|
|
|
OLLAMA: "ollama"
|
2026-01-05 10:37:09 +07:00
|
|
|
};
|
|
|
|
|
|
2026-03-01 15:35:41 +07:00
|
|
|
/**
|
2026-03-01 18:40:55 +07:00
|
|
|
* Detect source format from request URL pathname + body.
|
|
|
|
|
* Returns null to fall back to body-based detection.
|
2026-03-01 15:35:41 +07:00
|
|
|
*/
|
2026-03-01 18:40:55 +07:00
|
|
|
export function detectFormatByEndpoint(pathname, body) {
|
|
|
|
|
// /v1/responses is always openai-responses
|
|
|
|
|
if (pathname.includes("/v1/responses")) return FORMATS.OPENAI_RESPONSES;
|
|
|
|
|
|
2026-03-27 06:38:37 +03:00
|
|
|
// /v1/messages is always Claude
|
|
|
|
|
if (pathname.includes("/v1/messages")) return FORMATS.CLAUDE;
|
|
|
|
|
|
2026-03-01 18:40:55 +07:00
|
|
|
// /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;
|
2026-03-01 15:35:41 +07:00
|
|
|
}
|
2026-03-01 18:40:55 +07:00
|
|
|
|
2026-03-01 15:35:41 +07:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|