Skip to content

Commit 3a642cc

Browse files
committed
feat: Setting first message as chat title
1 parent 3f6468b commit 3a642cc

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

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

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ class ChatStore {
8383
type,
8484
timestamp: Date.now(),
8585
parent,
86+
thinking: '',
8687
children: []
8788
});
8889

@@ -107,23 +108,36 @@ class ChatStore {
107108
async sendMessage(content: string): Promise<void> {
108109
if (!content.trim() || this.isLoading) return;
109110

111+
let isNewConversation = false;
112+
110113
if (!this.activeConversation) {
111114
await this.createConversation();
115+
116+
isNewConversation = true;
112117
}
113118

114119
if (!this.activeConversation) {
115120
console.error('No active conversation available for sending message');
116121
return;
117122
}
123+
118124
this.isLoading = true;
119125
this.currentResponse = '';
120126

121127
try {
122128
const userMessage = await this.addMessage('user', content);
129+
123130
if (!userMessage) {
124131
throw new Error('Failed to add user message');
125132
}
126133

134+
// If this is a new conversation, update the title with the first user prompt
135+
if (isNewConversation && content) {
136+
const title = content.trim();
137+
138+
await this.updateConversationName(this.activeConversation.id, title);
139+
}
140+
127141
const allMessages = await DatabaseService.getConversationMessages(this.activeConversation.id);
128142

129143
const assistantMessage = await this.addMessage('assistant', '');
@@ -508,11 +522,12 @@ class ChatStore {
508522
this.isLoading = false;
509523
this.currentResponse = '';
510524

511-
const assistantMessageIndex = this.activeChatMessages.findIndex(
512-
(m) => m.id === assistantMessage.id
525+
const assistantMessageIndex = this.activeMessages.findIndex(
526+
(m: Message) => m.id === assistantMessage.id
513527
);
514528
if (assistantMessageIndex !== -1) {
515-
this.activeChatMessages[assistantMessageIndex].content = `Error: ${error.message}`;
529+
// Update message with parsed content
530+
this.activeMessages[assistantMessageIndex].content = `Error: ${error.message}`;
516531
}
517532
}
518533
}

0 commit comments

Comments
 (0)