refactor(open-sse): add reasoningDelta helper, dedup thinking deltas (B4)

Centralize the reasoning_content delta shape (optional assistant role) used by
claude/gemini/kiro/codex/commandcode response translators. Keeps the cross-format
convention consistent for future translators. Output byte-for-byte identical;
golden + gate clean. Ollama left as-is (mutates existing delta object).

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
decolua
2026-06-13 18:21:46 +07:00
parent 997860aa1f
commit 6597b81e5e
7 changed files with 18 additions and 12 deletions

View File

@@ -6,6 +6,7 @@ import { register } from "../index.js";
import { FORMATS } from "../formats.js";
import { buildChunk } from "../helpers/chunkBuilder.js";
import { fallbackToolCallId } from "../helpers/toolCallHelper.js";
import { reasoningDelta } from "../helpers/reasoningHelper.js";
// Build chunk meta for current kiro state
function chunkMeta(state) {
@@ -94,10 +95,7 @@ export function convertKiroToOpenAI(chunk, state) {
: (reasoning.text || reasoning.content || data.content || "");
if (!content) return null;
const openaiChunk = buildChunk(chunkMeta(state), {
...(state.chunkIndex === 0 ? { role: "assistant" } : {}),
reasoning_content: content
}, null);
const openaiChunk = buildChunk(chunkMeta(state), reasoningDelta(content, state.chunkIndex === 0), null);
state.chunkIndex++;
return openaiChunk;