Spaces:
Running
Running
Update server/chatStream.js
Browse files- server/chatStream.js +8 -3
server/chatStream.js
CHANGED
|
@@ -172,12 +172,17 @@ export async function streamChat(ws, {
|
|
| 172 |
}
|
| 173 |
|
| 174 |
function normalizeMessage(msg) {
|
| 175 |
-
if (msg.role === "tool") {
|
| 176 |
-
return { role: "tool", tool_call_id: msg.tool_call_id, content: String(msg.content) };
|
| 177 |
-
}
|
| 178 |
if (msg.role === "assistant" && msg.tool_calls) {
|
| 179 |
return { role: "assistant", content: "", tool_calls: msg.tool_calls };
|
| 180 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 181 |
return { role: msg.role, content: msg.content };
|
| 182 |
}
|
| 183 |
|
|
|
|
| 172 |
}
|
| 173 |
|
| 174 |
function normalizeMessage(msg) {
|
|
|
|
|
|
|
|
|
|
| 175 |
if (msg.role === "assistant" && msg.tool_calls) {
|
| 176 |
return { role: "assistant", content: "", tool_calls: msg.tool_calls };
|
| 177 |
}
|
| 178 |
+
// Flatten multipart content arrays to text-only for history
|
| 179 |
+
if (Array.isArray(msg.content)) {
|
| 180 |
+
const textOnly = msg.content
|
| 181 |
+
.filter(b => b.type === "text")
|
| 182 |
+
.map(b => b.text)
|
| 183 |
+
.join("\n");
|
| 184 |
+
return { role: msg.role, content: textOnly || "" };
|
| 185 |
+
}
|
| 186 |
return { role: msg.role, content: msg.content };
|
| 187 |
}
|
| 188 |
|