From 0089040f2dfb10a64cc55db4737bf2a4790e779d Mon Sep 17 00:00:00 2001 From: Stardust <1441308506a@gmail.com> Date: Mon, 16 Mar 2026 17:21:05 +0800 Subject: [PATCH] fix(llm): flatten content array for OpenAI-compatible providers (#1222) * fix(llm): flatten content array for OpenAI-compatible providers * fix(llm): improve type safety in sanitizeMessages * fix(stage-ui): add notice comment for message content flattening compatibility Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --------- Co-authored-by: Neko Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- packages/stage-ui/src/stores/llm.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/stage-ui/src/stores/llm.ts b/packages/stage-ui/src/stores/llm.ts index 8adb6efb5..f47b181ab 100644 --- a/packages/stage-ui/src/stores/llm.ts +++ b/packages/stage-ui/src/stores/llm.ts @@ -34,6 +34,16 @@ function sanitizeMessages(messages: unknown[]): Message[] { content: `User encountered error: ${String(m.content ?? '')}`, } as Message } + // NOTICE: This block is critical for backward compatibility with LLM providers (e.g., DeepSeek) + // that expect message content to be a string, not an array of content parts. + // Failure to flatten array content (when no image_url is present) can lead to + // deserialization errors like "invalid type: sequence, expected a string". + if (m && Array.isArray(m.content)) { + const contentParts = m.content as { type?: string, text?: string }[] + if (!contentParts.some(p => p?.type === 'image_url')) { + return { ...m, content: contentParts.map(p => p?.text ?? '').join('') } as Message + } + } return m as Message }) }