fix: emit reasoning_content in Responses→Chat streaming translation

This commit is contained in:
AveryanAlex
2026-03-29 00:23:54 +03:00
parent dce355cce6
commit 7723e46c26
2 changed files with 30 additions and 4 deletions

View File

@@ -602,10 +602,21 @@ export function openaiResponsesToOpenAIResponse(chunk, state) {
return null;
}
// Reasoning events (convert to content or skip)
// Reasoning events — emit as reasoning_content in Chat format
if (eventType === "response.reasoning_summary_text.delta") {
// Optionally include reasoning as content, or skip
return null;
const reasoningDelta = data.delta || "";
if (!reasoningDelta) return null;
return {
id: state.chatId,
object: "chat.completion.chunk",
created: state.created,
model: state.model || "gpt-4",
choices: [{
index: 0,
delta: { reasoning_content: reasoningDelta },
finish_reason: null,
}],
};
}
// Ignore other events

View File

@@ -342,7 +342,7 @@ test("Chat→Responses: deprecated function role message converted to function_c
assert.equal(fcOutput.call_id, fcItem.call_id);
});
const { openaiToOpenAIResponsesResponse } = await import(
const { openaiToOpenAIResponsesResponse, openaiResponsesToOpenAIResponse } = await import(
"../../open-sse/translator/response/openai-responses.ts"
);
const { initState } = await import("../../open-sse/translator/index.ts");
@@ -388,3 +388,18 @@ test("Chat→Responses streaming: completed event includes accumulated output",
const msgOutput = completedEvent.data.response.output.find((o) => o.type === "message");
assert.ok(msgOutput, "should have message output item");
});
test("Responses→Chat streaming: reasoning delta emits reasoning_content in Chat chunk", () => {
const state = { started: false, chatId: null, created: null, toolCallIndex: 0, finishReasonSent: false };
const chunk = {
type: "response.reasoning_summary_text.delta",
delta: "thinking step...",
item_id: "rs_1",
output_index: 0,
summary_index: 0,
};
const result = openaiResponsesToOpenAIResponse(chunk, state);
assert.ok(result, "should return a chunk");
assert.equal(result.choices[0].delta.reasoning_content, "thinking step...");
});