fix: trim leading whitespace from assembled content in log summaries

NVIDIA and other providers emit token deltas with leading spaces
(e.g. ' The', ' user'). When joined, these produce a leading space in
the provider_response and parsed non-streaming response logs. Trim
the joined content and reasoning_content in both buildOpenAISummary
and parseSSEToOpenAIResponse for consistent log output.
This commit is contained in:
Mikhail Salnikov
2026-03-29 21:44:13 +03:00
parent aa93276e6e
commit d3a24446b8
2 changed files with 10 additions and 6 deletions

View File

@@ -98,12 +98,14 @@ export function parseSSEToOpenAIResponse(rawSSE, fallbackModel) {
}
}
const joinedContent = contentParts.length > 0 ? contentParts.join("").trim() : null;
const joinedReasoning = reasoningParts.length > 0 ? reasoningParts.join("").trim() : null;
const message: Record<string, unknown> = {
role: "assistant",
content: contentParts.length > 0 ? contentParts.join("") : null,
content: joinedContent || null,
};
if (reasoningParts.length > 0) {
message.reasoning_content = reasoningParts.join("");
if (joinedReasoning) {
message.reasoning_content = joinedReasoning;
}
const finalToolCalls = [...accumulatedToolCalls.values()].filter(Boolean).sort((a, b) => {

View File

@@ -207,12 +207,14 @@ function buildOpenAISummary(events: StructuredSSEEvent[], fallbackModel?: string
}
}
const joinedContent = contentParts.length > 0 ? contentParts.join("").trim() : null;
const joinedReasoning = reasoningParts.length > 0 ? reasoningParts.join("").trim() : null;
const message: JsonRecord = {
role: "assistant",
content: contentParts.length > 0 ? contentParts.join("") : null,
content: joinedContent || null,
};
if (reasoningParts.length > 0) {
message.reasoning_content = reasoningParts.join("");
if (joinedReasoning) {
message.reasoning_content = joinedReasoning;
}
const finalToolCalls = [...toolCalls.values()].sort((a, b) => a.index - b.index);