mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-05 06:42:12 +03:00
feat: adaptive keepalive threshold for web-session providers (#3397)
Integrated into release/v3.8.16
This commit is contained in:
@@ -3,6 +3,7 @@ import { withEarlyStreamKeepalive } from "@omniroute/open-sse/utils/earlyStreamK
|
||||
import { resolveResponsesApiModel } from "@/app/api/internal/codex-responses-ws/modelResolution";
|
||||
import { getModelInfo } from "@/sse/services/model";
|
||||
import { getComboByName } from "@/lib/db/combos";
|
||||
import { resolveKeepaliveThreshold } from "@omniroute/open-sse/utils/keepaliveThreshold";
|
||||
|
||||
// NOTE: We do NOT call initTranslators() here — the translator registry is
|
||||
// bootstrapped at module level inside open-sse/translator/index.ts when it
|
||||
@@ -68,7 +69,19 @@ export async function POST(request) {
|
||||
const resolved = await withCodexPreferredModel(request);
|
||||
const accept = String(request.headers?.get?.("accept") || "").toLowerCase();
|
||||
if (accept.includes("text/event-stream")) {
|
||||
return await withEarlyStreamKeepalive(handleChat(resolved), { signal: request.signal });
|
||||
// Adaptive threshold: web-session and anonymous-fallback providers are slower
|
||||
// to produce the first byte, so use a longer keepalive threshold (15s vs 2s).
|
||||
let model;
|
||||
try {
|
||||
const body = await resolved.clone().json().catch(() => null);
|
||||
model = body?.model;
|
||||
} catch {
|
||||
}
|
||||
const thresholdMs = resolveKeepaliveThreshold(model);
|
||||
return await withEarlyStreamKeepalive(handleChat(resolved), {
|
||||
signal: request.signal,
|
||||
thresholdMs,
|
||||
});
|
||||
}
|
||||
return await handleChat(resolved);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user