@@ -76,7 +76,7 @@ export function AskAIResults({
7676
7777 const [ conversationId , setConversationId ] = useState < string > ( '' )
7878
79- const handleAICannotAnswer = ( ) => {
79+ const handleAICannotAnswer = ( passedConversationId ?: string ) => {
8080 setInitialLoading ( false )
8181 setResponseLoading ( false )
8282 setAICouldNotAnswer ( true )
@@ -87,6 +87,7 @@ export function AskAIResults({
8787 eventGroupId : askAIEventGroupId . current ,
8888 couldNotAnswer : true ,
8989 status : 400 ,
90+ connectedEventId : passedConversationId || conversationId ,
9091 } )
9192 setMessage ( cannedResponse )
9293 setAnnouncement ( cannedResponse )
@@ -98,6 +99,7 @@ export function AskAIResults({
9899 message : cannedResponse ,
99100 sources : [ ] ,
100101 aiCouldNotAnswer : true ,
102+ connectedEventId : passedConversationId || conversationId ,
101103 } ,
102104 version ,
103105 router . locale || 'en' ,
@@ -123,6 +125,7 @@ export function AskAIResults({
123125 if ( cachedData ) {
124126 setMessage ( cachedData . message )
125127 setReferences ( cachedData . sources )
128+ setConversationId ( cachedData . connectedEventId || '' )
126129 setAICouldNotAnswer ( cachedData . aiCouldNotAnswer || false )
127130 setInitialLoading ( false )
128131 setResponseLoading ( false )
@@ -150,10 +153,6 @@ export function AskAIResults({
150153
151154 try {
152155 const response = await executeAISearch ( router , version , query , debug )
153- // Serve canned response. A question that cannot be answered was asked
154- if ( response . status === 400 ) {
155- return handleAICannotAnswer ( )
156- }
157156 if ( ! response . ok ) {
158157 console . error (
159158 `Failed to fetch search results.\nStatus ${ response . status } \n${ response . statusText } ` ,
@@ -219,7 +218,14 @@ export function AskAIResults({
219218 continue
220219 }
221220
222- if ( parsedLine . chunkType === 'SOURCES' ) {
221+ // A conversation ID will still be sent when a question cannot be answered
222+ if ( parsedLine . chunkType === 'CONVERSATION_ID' ) {
223+ conversationIdBuffer = parsedLine . conversation_id
224+ setConversationId ( parsedLine . conversation_id )
225+ } else if ( parsedLine . chunkType === 'NO_CONTENT_SIGNAL' ) {
226+ // Serve canned response. A question that cannot be answered was asked
227+ handleAICannotAnswer ( conversationIdBuffer )
228+ } else if ( parsedLine . chunkType === 'SOURCES' ) {
223229 if ( ! isCancelled ) {
224230 sourcesBuffer = sourcesBuffer . concat ( parsedLine . sources )
225231 sourcesBuffer = uniqBy ( sourcesBuffer , 'url' )
@@ -230,9 +236,9 @@ export function AskAIResults({
230236 messageBuffer += parsedLine . text
231237 setMessage ( messageBuffer )
232238 }
233- } else if ( parsedLine . chunkType === 'CONVERSATION_ID ' ) {
234- conversationIdBuffer = parsedLine . conversation_id
235- setConversationId ( parsedLine . conversation_id )
239+ } else if ( parsedLine . chunkType === 'INPUT_CONTENT_FILTER ' ) {
240+ // Serve canned response. A spam question was asked
241+ handleAICannotAnswer ( conversationIdBuffer )
236242 }
237243 if ( ! isCancelled ) {
238244 setAnnouncement ( 'Copilot Response Loading...' )
0 commit comments