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
parent 0e34358e74
commit 17202f7111
10 changed files with 270 additions and 295 deletions

View File

@@ -1,5 +1,6 @@
import { register } from "../index.js";
import { FORMATS } from "../formats.js";
import { buildChunk } from "../helpers/chunkBuilder.js";
/**
* Convert Ollama NDJSON response to OpenAI SSE format
@@ -36,18 +37,9 @@ export function ollamaToOpenAI(chunk, state) {
finishReason = "tool_calls";
}
return {
id: id,
object: "chat.completion.chunk",
created: created,
model: model,
choices: [{
index: 0,
delta: {},
finish_reason: finishReason
}],
usage: usage
};
const doneChunk = buildChunk({ id, created, model }, {}, finishReason);
doneChunk.usage = usage;
return doneChunk;
}
// Content chunk
@@ -79,17 +71,7 @@ export function ollamaToOpenAI(chunk, state) {
delta.tool_calls = convertToolCalls(toolCalls);
}
return {
id: id,
object: "chat.completion.chunk",
created: created,
model: model,
choices: [{
index: 0,
delta: delta,
finish_reason: null
}]
};
return buildChunk({ id, created, model }, delta, null);
}
/**