Skip to content

Commit 4c79461

Browse files
committed
Add callbacks for direct callers
1 parent 3375365 commit 4c79461

2 files changed

Lines changed: 9 additions & 11 deletions

File tree

web-common/src/features/chat/core/conversation.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,10 @@ export class Conversation {
121121
* @param context - Chat context to be sent with the message
122122
* @param options - Callback functions for different stages of message sending
123123
*/
124-
public async sendMessage(context: RuntimeServiceCompleteBody): Promise<void> {
124+
public async sendMessage(
125+
context: RuntimeServiceCompleteBody,
126+
options?: { onStreamStart?: () => void },
127+
): Promise<void> {
125128
// Prevent concurrent message sending
126129
if (get(this.isStreaming)) {
127130
this.streamError.set("Please wait for the current response to complete");
@@ -140,7 +143,8 @@ export class Conversation {
140143
const userMessage = this.addOptimisticUserMessage(prompt);
141144

142145
try {
143-
this.events.emit("stream-start");
146+
options?.onStreamStart?.(); // Callback for direct callers
147+
this.events.emit("stream-start"); // Event for external listeners
144148
// Start streaming - this establishes the connection
145149
const streamPromise = this.startStreaming(prompt, context);
146150

web-common/src/features/chat/core/input/ChatInput.svelte

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,6 @@
2727
$: draftMessageStore = currentConversation.draftMessage;
2828
$: isStreamingStore = currentConversation.isStreaming;
2929
30-
let streamStartUnsub: (() => void) | undefined = undefined;
31-
$: {
32-
streamStartUnsub?.();
33-
streamStartUnsub = currentConversation.on("stream-start", () => {
34-
editor.commands.setContent("");
35-
});
36-
}
37-
3830
$: value = $draftMessageStore;
3931
$: disabled = $getConversationQuery?.isLoading || $isStreamingStore;
4032
$: canSend = !disabled && value.trim();
@@ -48,7 +40,9 @@
4840
4941
// Message handling with input focus
5042
try {
51-
await currentConversation.sendMessage($additionalContextStore);
43+
await currentConversation.sendMessage($additionalContextStore, {
44+
onStreamStart: () => editor.commands.setContent(""),
45+
});
5246
onSend?.();
5347
} catch (error) {
5448
console.error("Failed to send message:", error);

0 commit comments

Comments
 (0)