Skip to content

Commit 47cf267

Browse files
committed
zen: fix routing non OC traffic
1 parent 976aae7 commit 47cf267

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

  • packages/console/app/src/routes/zen/util

packages/console/app/src/routes/zen/util/handler.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ export async function handler(
120120
zenData,
121121
authInfo,
122122
modelInfo,
123+
ip,
123124
sessionId,
124125
trialProviders,
125126
retry,
@@ -402,6 +403,7 @@ export async function handler(
402403
zenData: ZenData,
403404
authInfo: AuthInfo,
404405
modelInfo: ModelInfo,
406+
ip: string,
405407
sessionId: string,
406408
trialProviders: string[] | undefined,
407409
retry: RetryOptions,
@@ -430,10 +432,11 @@ export async function handler(
430432
.flatMap((provider) => Array<typeof provider>(provider.weight ?? 1).fill(provider))
431433

432434
// Use the last 4 characters of session ID to select a provider
435+
const identifier = sessionId.length ? sessionId : ip
433436
let h = 0
434-
const l = sessionId.length
437+
const l = identifier.length
435438
for (let i = l - 4; i < l; i++) {
436-
h = (h * 31 + sessionId.charCodeAt(i)) | 0 // 32-bit int
439+
h = (h * 31 + identifier.charCodeAt(i)) | 0 // 32-bit int
437440
}
438441
const index = (h >>> 0) % providers.length // make unsigned + range 0..length-1
439442
const provider = providers[index || 0]

0 commit comments

Comments
 (0)