feat(claude): forward x-claude-code-session-id on OAuth requests

This commit is contained in:
decolua
2026-09-26 17:15:12 +07:00
parent 0249464d74
commit 6aea3875ef
3 changed files with 58 additions and 1 deletions

View File

@@ -25,10 +25,25 @@ function deriveUuid(seed) {
function generateFakeUserID(sessionId, apiKey) {
const deviceId = apiKey ? createHash("sha256").update(`device:${apiKey}`).digest("hex") : randomBytes(32).toString("hex");
const accountUuid = apiKey ? deriveUuid(`account:${apiKey}`) : randomUUID();
const sessionUuid = sessionId || randomUUID();
const cleanSessionId = typeof sessionId === "string" ? sessionId.replace(/^claude:/i, "").trim() : null;
const sessionUuid = cleanSessionId || randomUUID();
return `{"device_id":"${deviceId}","account_uuid":"${accountUuid}","session_id":"${sessionUuid}"}`;
}
export function extractClaudeSessionIdFromUserId(userId) {
if (typeof userId !== "string" || !userId) return null;
if (userId[0] === "{") {
try {
const sid = JSON.parse(userId)?.session_id;
return typeof sid === "string" && sid ? sid.replace(/^claude:/i, "").trim() || null : null;
} catch {
return null;
}
}
const clean = userId.replace(/^claude:/i, "").trim();
return clean || null;
}
/**
* Cloak tools before sending to Claude provider (anti-ban):
* - Rename client tools with the CLAUDE_TOOL_SUFFIX ("_ide") in tools[] and messages[]