Skip to content

Commit 068d892

Browse files
committed
fix (chat): tool code rendering
1 parent e8d55e4 commit 068d892

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

src/client/components/ChatBubble.js

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,16 @@ const ChatBubble = ({
258258
for (const match of message.matchAll(regex)) {
259259
// Capture the text before the current tag
260260
if (match.index > lastIndex) {
261-
contentParts.push({
262-
type: "text",
263-
content: message.substring(lastIndex, match.index)
264-
})
261+
const textContent = message.substring(lastIndex, match.index)
262+
const isPartialTag =
263+
textContent.startsWith("<tool_") ||
264+
textContent.startsWith("<think")
265+
if (textContent.trim() && !isPartialTag) {
266+
contentParts.push({
267+
type: "text",
268+
content: textContent
269+
})
270+
}
265271
}
266272

267273
const tag = match[0] // The full tag match
@@ -308,10 +314,16 @@ const ChatBubble = ({
308314

309315
// Capture any remaining text after the last tag
310316
if (lastIndex < message.length) {
311-
contentParts.push({
312-
type: "text", // The final part of the message
313-
content: message.substring(lastIndex)
314-
})
317+
const textContent = message.substring(lastIndex)
318+
const isPartialTag =
319+
textContent.startsWith("<tool_") ||
320+
textContent.startsWith("<think")
321+
if (textContent.trim() && !isPartialTag) {
322+
contentParts.push({
323+
type: "text", // The final part of the message
324+
content: textContent
325+
})
326+
}
315327
}
316328

317329
return contentParts.map((part, index) => {

0 commit comments

Comments
 (0)