mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-08 00:02:20 +03:00
fix(agentrouter): infer protocol from client endpoint - /v1/responses resolves AgentRouter as openai-responses - /v1/chat/completions resolves AgentRouter as openai - /v1/messages resolves AgentRouter as claude - Per-request protocol and credential cloning (no SQLite mutation) - Codex 0.146.0 and Claude Code 2.1.220 identity alignment - response.completed.usage.total_tokens normalization for strict Codex clients Closes #9224
36 lines
1.3 KiB
TypeScript
36 lines
1.3 KiB
TypeScript
/**
|
|
* Per-request AgentRouter protocol decisions kept outside the chatCore orchestration god-file.
|
|
* AgentRouter exposes Claude Messages, OpenAI Chat, and OpenAI Responses as distinct upstream
|
|
* protocols, so its dynamic target format must override the connection's default Claude wire image.
|
|
*/
|
|
|
|
import { isClaudeCodeCompatibleProvider } from "../../services/claudeCodeCompatible.ts";
|
|
import { FORMATS } from "../../translator/formats.ts";
|
|
|
|
export function usesClaudeBridge(
|
|
provider: string,
|
|
targetFormat: string,
|
|
credentials: unknown
|
|
): boolean {
|
|
const configuredTargetFormat = (
|
|
credentials as { providerSpecificData?: { targetFormat?: unknown } | null } | null | undefined
|
|
)?.providerSpecificData?.targetFormat;
|
|
const effectiveFormat = provider === "agentrouter" ? targetFormat : configuredTargetFormat;
|
|
return (
|
|
isClaudeCodeCompatibleProvider(provider) &&
|
|
effectiveFormat !== FORMATS.OPENAI &&
|
|
effectiveFormat !== FORMATS.OPENAI_RESPONSES
|
|
);
|
|
}
|
|
|
|
export function stripStore(
|
|
body: Record<string, unknown>,
|
|
provider: string,
|
|
targetFormat: string
|
|
): void {
|
|
const supportsStore =
|
|
provider === "openai" ||
|
|
(provider === "agentrouter" && targetFormat === FORMATS.OPENAI_RESPONSES);
|
|
if (!supportsStore && "store" in body) delete body.store;
|
|
}
|