zen: fix routing non OC traffic

This commit is contained in:
Frank 2026-03-18 10:59:52 -04:00
parent 976aae7e42
commit 47cf267c23

View File

@ -120,6 +120,7 @@ export async function handler(
zenData, zenData,
authInfo, authInfo,
modelInfo, modelInfo,
ip,
sessionId, sessionId,
trialProviders, trialProviders,
retry, retry,
@ -402,6 +403,7 @@ export async function handler(
zenData: ZenData, zenData: ZenData,
authInfo: AuthInfo, authInfo: AuthInfo,
modelInfo: ModelInfo, modelInfo: ModelInfo,
ip: string,
sessionId: string, sessionId: string,
trialProviders: string[] | undefined, trialProviders: string[] | undefined,
retry: RetryOptions, retry: RetryOptions,
@ -430,10 +432,11 @@ export async function handler(
.flatMap((provider) => Array<typeof provider>(provider.weight ?? 1).fill(provider)) .flatMap((provider) => Array<typeof provider>(provider.weight ?? 1).fill(provider))
// Use the last 4 characters of session ID to select a provider // Use the last 4 characters of session ID to select a provider
const identifier = sessionId.length ? sessionId : ip
let h = 0 let h = 0
const l = sessionId.length const l = identifier.length
for (let i = l - 4; i < l; i++) { for (let i = l - 4; i < l; i++) {
h = (h * 31 + sessionId.charCodeAt(i)) | 0 // 32-bit int h = (h * 31 + identifier.charCodeAt(i)) | 0 // 32-bit int
} }
const index = (h >>> 0) % providers.length // make unsigned + range 0..length-1 const index = (h >>> 0) % providers.length // make unsigned + range 0..length-1
const provider = providers[index || 0] const provider = providers[index || 0]