Skip to content

Commit d9f94c7

Browse files
committed
feat: Continuation logic & prompt improvements
1 parent 23557ee commit d9f94c7

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

tools/server/webui/src/lib/components/app/chat/ChatMessages/ChatMessage.svelte

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,12 @@
119119
120120
function handleSaveEdit() {
121121
if (message.role === 'user') {
122+
// For user messages, trim to avoid accidental whitespace
122123
onEditWithBranching?.(message, editedContent.trim());
123124
} else {
124-
onEditWithReplacement?.(message, editedContent.trim(), shouldBranchAfterEdit);
125+
// For assistant messages, preserve exact content including trailing whitespace
126+
// This is important for the Continue feature to work properly
127+
onEditWithReplacement?.(message, editedContent, shouldBranchAfterEdit);
125128
}
126129
127130
isEditing = false;
@@ -130,6 +133,7 @@
130133
131134
function handleSaveEditOnly() {
132135
if (message.role === 'user') {
136+
// For user messages, trim to avoid accidental whitespace
133137
onEditUserMessagePreserveResponses?.(message, editedContent.trim());
134138
}
135139

tools/server/webui/src/lib/stores/chat.svelte.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1742,20 +1742,30 @@ class ChatStore {
17421742
this.setConversationLoading(this.activeConversation.id, true);
17431743
this.clearConversationStreaming(this.activeConversation.id);
17441744

1745+
// Get current content (includes any edits made to the message)
1746+
// This comes from activeMessages which is kept in sync with the database
17451747
const originalContent = messageToContinue.content;
17461748
const originalThinking = messageToContinue.thinking || '';
17471749

1748-
// Get conversation context up to and including the message to continue
1749-
const conversationContext = this.activeMessages.slice(0, messageIndex + 1);
1750+
// Get conversation context up to (but not including) the message to continue
1751+
const conversationContext = this.activeMessages.slice(0, messageIndex);
17501752

17511753
// Add a synthetic "continue" prompt to signal continuation
1754+
// We check if original content ends with whitespace to preserve it in the instruction
1755+
const endsWithWhitespace = /\s$/.test(originalContent);
1756+
const continueInstruction = endsWithWhitespace
1757+
? 'Continue your response. Start directly without adding extra spacing.'
1758+
: 'Continue your response from where you left off.';
1759+
17521760
const continuePrompt: ApiChatMessageData = {
17531761
role: 'user',
1754-
content: 'Continue from where you left off.'
1762+
content: continueInstruction
17551763
};
17561764

1765+
// Build context: all previous messages + assistant message + synthetic user prompt
1766+
// The user prompt is only sent to the API, not saved to the database
17571767
const contextWithContinue = [
1758-
...conversationContext.slice(0, -1).map((msg) => {
1768+
...conversationContext.map((msg) => {
17591769
if ('id' in msg && 'convId' in msg && 'timestamp' in msg) {
17601770
return msg as DatabaseMessage & { extra?: DatabaseMessageExtra[] };
17611771
}
@@ -1778,6 +1788,8 @@ class ChatStore {
17781788

17791789
onChunk: (chunk: string) => {
17801790
appendedContent += chunk;
1791+
// Preserve originalContent exactly as-is, including any trailing whitespace
1792+
// The concatenation naturally preserves any whitespace at the end of originalContent
17811793
const fullContent = originalContent + appendedContent;
17821794
this.setConversationStreaming(
17831795
messageToContinue.convId,

0 commit comments

Comments
 (0)