refactor(open-sse): extract chunkBuilder, dedup chat.completion.chunk (B1)

Add helpers/chunkBuilder.js; apply to claude/gemini/kiro/ollama/commandcode/
openai-responses response translators. Caller supplies id/created/model so each
keeps exact id-generation + usage semantics. Extend golden response stream to
openai-responses (codex). No behavior change; gate: no regression.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
decolua
2026-06-13 17:05:42 +07:00
co-authored by Cursor
parent 0e34358e74
commit 17202f7111
10 changed files with 270 additions and 295 deletions
@@ -17,6 +17,7 @@
*/
import { register } from "../index.js";
import { FORMATS } from "../formats.js";
import { buildChunk } from "../helpers/chunkBuilder.js";
function ensureState(state, model) {
if (!state.responseId) {
@@ -34,13 +35,11 @@ function ensureState(state, model) {
}
function makeChunk(state, delta, finishReason = null) {
return {
id: state.responseId,
object: "chat.completion.chunk",
created: state.created,
model: state.model,
choices: [{ index: 0, delta, finish_reason: finishReason }],
};
return buildChunk(
{ id: state.responseId, created: state.created, model: state.model },
delta,
finishReason
);
}
function mapFinishReason(reason) {