Files
OmniRoute/open-sse/handlers/chatCore/agentRouterProtocol.ts
Bob.Hou 6b259812a7 fix(sse): preserve store parameter semantics for openai-compatible responses (#11826) (#11916)
stripStore() now forces store=false for stateless OpenAI-compatible Responses-API targets unless the connection explicitly opts in via providerSpecificData.openaiStoreEnabled, instead of only handling the openai/agentrouter cases — a client-supplied store value previously passed through untouched to backends that don't actually persist responses server-side. Closes #11826. Thanks!
2026-08-28 16:25:19 -03:00

49 lines
1.7 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,
providerSpecificData?: unknown
): void {
if (provider.startsWith("openai-compatible-") && targetFormat === FORMATS.OPENAI_RESPONSES) {
const psd =
providerSpecificData && typeof providerSpecificData === "object"
? (providerSpecificData as Record<string, unknown>)
: undefined;
if (psd?.openaiStoreEnabled === true) {
return;
}
body.store = false;
return;
}
const supportsStore =
provider === "openai" ||
(provider === "agentrouter" && targetFormat === FORMATS.OPENAI_RESPONSES);
if (!supportsStore && "store" in body) delete body.store;
}