@@ -34,28 +34,6 @@ export const createMynahUI = (ideApi: any, amazonQEnabled: boolean) => {
3434 } )
3535 } ,
3636 } )
37- /*
38- function countNumberOfCodeBlocks(messageGenerated: string | undefined): number {
39- if (messageGenerated === undefined) {
40- return 0
41- }
42- let totalCodeBlocks = 0
43- let codeBlockIndex = messageGenerated.indexOf('```')
44- while (codeBlockIndex !== -1) {
45- totalCodeBlocks++
46- codeBlockIndex = messageGenerated.indexOf('```', codeBlockIndex + 1)
47- }
48- return Math.floor(totalCodeBlocks / 2)
49- }
50- */
51- function countNumberOfCodeBlocks ( messageGenerated : string ) : number {
52- if ( messageGenerated === undefined ) {
53- return 0
54- }
55- const matches = messageGenerated . match ( / ` ` ` / g)
56- const totalCodeBlockOpenAndClose = matches ? matches . length : 0 //totalCodeBlockOpenAndClose
57- return Math . floor ( totalCodeBlockOpenAndClose / 2 )
58- }
5937
6038 // Adding the first tab as CWC tab
6139 tabsStorage . addTab ( {
@@ -207,10 +185,6 @@ export const createMynahUI = (ideApi: any, amazonQEnabled: boolean) => {
207185 } ,
208186 onChatAnswerReceived : ( tabID : string , item : ChatItem ) => {
209187 if ( item . type === ChatItemType . ANSWER_PART || item . type === ChatItemType . CODE_RESULT ) {
210- if ( item . body !== undefined && item . messageId !== undefined ) {
211- const totalCodeBlocks = countNumberOfCodeBlocks ( item . body )
212- connector . handleMessageofStreamedData ( tabID , totalCodeBlocks , item . messageId )
213- }
214188 mynahUI . updateLastChatAnswer ( tabID , {
215189 ...( item . messageId !== undefined ? { messageId : item . messageId } : { } ) ,
216190 ...( item . canBeVoted !== undefined ? { canBeVoted : item . canBeVoted } : { } ) ,
@@ -249,6 +223,10 @@ export const createMynahUI = (ideApi: any, amazonQEnabled: boolean) => {
249223 }
250224
251225 if ( item . type === ChatItemType . ANSWER ) {
226+ if ( item . messageId !== undefined ) {
227+ const count = mynahUI . endMessageStream ( tabID , item . messageId ) . totalNumberOfCodeBlocks
228+ connector . handleMessageofStreamedData ( tabID , count === undefined ? 0 : count , item . messageId )
229+ }
252230 mynahUI . updateStore ( tabID , {
253231 loadingChat : false ,
254232 promptInputDisabledState : tabsStorage . isTabDead ( tabID ) ,
0 commit comments