File tree Expand file tree Collapse file tree
web-common/src/features/chat/core Expand file tree Collapse file tree Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 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 ();
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 );
You can’t perform that action at this time.
0 commit comments