Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions app/utils/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -624,19 +624,13 @@ export function streamWithThink(
if (!isInThinkingMode || isThinkingChanged) {
// If this is a new thinking block or mode changed, add prefix
isInThinkingMode = true;
if (remainText.length > 0) {
if (remainText.length > 0 && !remainText.endsWith("\n")) {
remainText += "\n";
}
remainText += "> " + chunk.content;
} else {
// Handle newlines in thinking content
if (chunk.content.includes("\n\n")) {
const lines = chunk.content.split("\n\n");
remainText += lines.join("\n\n> ");
} else {
remainText += chunk.content;
}
remainText += "> ";
}
// Append content, ensuring newlines are quoted
remainText += chunk.content.replace(/\n/g, "\n> ");
} else {
Comment on lines +627 to 634
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Thinking-mode chunks can lose the > prefix after a newline split across SSE chunks

When a thinking chunk ends with \n and the next chunk continues thinking, the first line of the next chunk won’t be prefixed because "> " is only added on block start. Add a prefix whenever we’re still in thinking mode and remainText currently ends with \n.

           if (chunk.isThinking) {
             // If in thinking mode
             if (!isInThinkingMode || isThinkingChanged) {
               // If this is a new thinking block or mode changed, add prefix
               isInThinkingMode = true;
               if (remainText.length > 0 && !remainText.endsWith("\n")) {
                 remainText += "\n";
               }
               remainText += "> ";
-            }
+            } else if (remainText.endsWith("\n")) {
+              // preserve quoting across chunk boundaries
+              remainText += "> ";
+            }
             // Append content, ensuring newlines are quoted
-            remainText += chunk.content.replace(/\n/g, "\n> ");
+            remainText += chunk.content.replace(/\n/g, "\n> ");
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (remainText.length > 0 && !remainText.endsWith("\n")) {
remainText += "\n";
}
remainText += "> " + chunk.content;
} else {
// Handle newlines in thinking content
if (chunk.content.includes("\n\n")) {
const lines = chunk.content.split("\n\n");
remainText += lines.join("\n\n> ");
} else {
remainText += chunk.content;
}
remainText += "> ";
}
// Append content, ensuring newlines are quoted
remainText += chunk.content.replace(/\n/g, "\n> ");
} else {
if (remainText.length > 0 && !remainText.endsWith("\n")) {
remainText += "\n";
}
remainText += "> ";
} else if (remainText.endsWith("\n")) {
// preserve quoting across chunk boundaries
remainText += "> ";
}
// Append content, ensuring newlines are quoted
remainText += chunk.content.replace(/\n/g, "\n> ");
} else {
🤖 Prompt for AI Agents
In app/utils/chat.ts around lines 627 to 634, the logic that prepares quoted
"thinking" text must also add a "> " prefix when remainText already ends with a
newline (split across SSE chunks). Modify the branch so that when still in
thinking mode and remainText.endsWith("\n") you append "> " before adding the
next chunk, and keep the existing logic that adds a newline when remainText is
non-empty and does not end with "\n"; then proceed to append the chunk content
with .replace(/\n/g, "\n> ") as before.

// If in normal mode
if (isInThinkingMode || isThinkingChanged) {
Expand Down