@bitkyc08/opencodex
Version:
Universal provider proxy for OpenAI Codex & Claude Code — use any LLM with Codex CLI/App/SDK and Claude Code
24 lines (22 loc) • 978 B
text/typescript
import { createHash } from "node:crypto";
/** Shared conversation identity precedence; Desktop cohort cache keys never bind sessions. */
export function oauthSessionKeyFromParts(input: {
sessionIdHeader?: string | null;
threadIdHeader?: string | null;
promptCacheKey?: string | null;
clientThreadId?: string | null;
/** When true, prompt_cache_key is a shared Desktop cohort — ignore it for affinity. */
promptCacheKeyIsSharedCohort?: boolean;
}): string | null {
const preferred = input.clientThreadId?.trim()
|| input.sessionIdHeader?.trim()
|| input.threadIdHeader?.trim()
|| "";
if (preferred) {
return preferred.length <= 128 ? preferred : createHash("sha256").update(preferred).digest("hex");
}
if (input.promptCacheKeyIsSharedCohort) return null;
const cacheKey = input.promptCacheKey?.trim() ?? "";
if (!cacheKey) return null;
return cacheKey.length <= 128 ? cacheKey : createHash("sha256").update(cacheKey).digest("hex");
}