refactor(open-sse): DRY SSE primitives into utils/sseConstants.js
Gom SSE_DONE + SSE_HEADERS + SSE_HEADERS_NO_BUFFER vào 1 file không phụ thuộc (tránh kéo usageDb vào executor). Áp cho kiro, cursor, qoder, github, commandcode, perplexity-web, grok-web. Byte-for-byte verified (headers/DONE giữ nguyên; biến thể no-buffer dùng const riêng). Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { BaseExecutor } from "./base.js";
|
||||
import { PROVIDERS } from "../config/providers.js";
|
||||
import { SSE_DONE, SSE_HEADERS_NO_BUFFER } from "../utils/sseConstants.js";
|
||||
|
||||
const PPLX_SSE_ENDPOINT = PROVIDERS["perplexity-web"].baseUrl;
|
||||
const PPLX_API_VERSION = "2.18";
|
||||
@@ -340,7 +341,7 @@ function buildStreamingResponse(eventStream, model, cid, created, history, curre
|
||||
id: cid, object: "chat.completion.chunk", created, model, system_fingerprint: null,
|
||||
choices: [{ index: 0, delta: {}, finish_reason: "stop", logprobs: null }],
|
||||
})));
|
||||
controller.enqueue(encoder.encode("data: [DONE]\n\n"));
|
||||
controller.enqueue(encoder.encode(SSE_DONE));
|
||||
|
||||
sessionStore(history, currentMsg, cleanResponse(fullAnswer), respBackendUuid);
|
||||
} catch (err) {
|
||||
@@ -348,7 +349,7 @@ function buildStreamingResponse(eventStream, model, cid, created, history, curre
|
||||
id: cid, object: "chat.completion.chunk", created, model, system_fingerprint: null,
|
||||
choices: [{ index: 0, delta: { content: `[Stream error: ${err.message || String(err)}]` }, finish_reason: "stop", logprobs: null }],
|
||||
})));
|
||||
controller.enqueue(encoder.encode("data: [DONE]\n\n"));
|
||||
controller.enqueue(encoder.encode(SSE_DONE));
|
||||
} finally {
|
||||
controller.close();
|
||||
}
|
||||
@@ -493,7 +494,7 @@ export class PerplexityWebExecutor extends BaseExecutor {
|
||||
const sseStream = buildStreamingResponse(response.body, model, cid, created, parsed.history, parsed.currentMsg, signal);
|
||||
finalResponse = new Response(sseStream, {
|
||||
status: 200,
|
||||
headers: { "Content-Type": "text/event-stream", "Cache-Control": "no-cache", "X-Accel-Buffering": "no" },
|
||||
headers: { ...SSE_HEADERS_NO_BUFFER },
|
||||
});
|
||||
} else {
|
||||
finalResponse = await buildNonStreamingResponse(response.body, model, cid, created, parsed.history, parsed.currentMsg, signal);
|
||||
|
||||
Reference in New Issue
Block a user