fix(translator): stop emitting empty <think> markers into OpenAI content

This commit is contained in:
MrBeanDev
2026-09-26 11:31:54 +07:00
parent 3e4323e2fd
commit 5d2cfbf3c5
5 changed files with 185 additions and 38 deletions

View File

@@ -333,6 +333,9 @@ export function createResponsesApiTransformStream(logger = null) {
// Regular text content
if (content) {
// The answer starts, so thinking is over. Upstreams that send reasoning via
// reasoning_content never emit "</think>", so close it here rather than at finish.
closeReasoning(controller);
if (!state.msgItemAdded[idx]) {
state.msgItemAdded[idx] = true;
const msgId = `msg_${state.responseId}_${idx}`;
@@ -372,6 +375,7 @@ export function createResponsesApiTransformStream(logger = null) {
// Handle tool_calls
if (delta.tool_calls) {
closeReasoning(controller);
closeMessage(controller, idx);
for (const tc of delta.tool_calls) {