Use OpenAI chunks for early chat keepalives (#7136)

* Use OpenAI chunks for early chat keepalives

* Update keepalive assertion to match chat completion chunk format

---------

Co-authored-by: Diego Rodrigues de Sa e Souza <8016841+diegosouzapw@users.noreply.github.com>
This commit is contained in:
KooshaPari
2026-07-16 10:14:27 -07:00
committed by GitHub
parent 8e9cff3145
commit fd468b5ef1
4 changed files with 48 additions and 3 deletions

View File

@@ -5,7 +5,10 @@ import { generateRequestId } from "@/shared/utils/requestId";
import { initTranslators } from "@omniroute/open-sse/translator/index.ts";
import { createInjectionGuard } from "@/middleware/promptInjectionGuard";
import { acceptHeaderForcesStream } from "@omniroute/open-sse/utils/aiSdkCompat.ts";
import { withEarlyStreamKeepalive } from "@omniroute/open-sse/utils/earlyStreamKeepalive";
import {
OPENAI_KEEPALIVE_FRAME,
withEarlyStreamKeepalive,
} from "@omniroute/open-sse/utils/earlyStreamKeepalive";
import { resolveKeepaliveThreshold } from "@omniroute/open-sse/utils/keepaliveThreshold";
import { checkChatAdmission } from "@/shared/middleware/chatBodyAdmission";
import {
@@ -132,6 +135,7 @@ export async function POST(request) {
{
signal: request.signal,
thresholdMs: resolveKeepaliveThreshold(parsedBody?.model),
keepaliveFrame: OPENAI_KEEPALIVE_FRAME,
extraHeaders: { "X-Correlation-Id": reqId },
}
);