9router/open-sse/translator/formats.js

36 lines
978 B
JavaScript
Raw Normal View History

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