@@ -76,7 +76,7 @@ export function AskAIResults({
76
76
77
77
const [ conversationId , setConversationId ] = useState < string > ( '' )
78
78
79
- const handleAICannotAnswer = ( ) => {
79
+ const handleAICannotAnswer = ( passedConversationId ?: string ) => {
80
80
setInitialLoading ( false )
81
81
setResponseLoading ( false )
82
82
setAICouldNotAnswer ( true )
@@ -87,6 +87,7 @@ export function AskAIResults({
87
87
eventGroupId : askAIEventGroupId . current ,
88
88
couldNotAnswer : true ,
89
89
status : 400 ,
90
+ connectedEventId : passedConversationId || conversationId ,
90
91
} )
91
92
setMessage ( cannedResponse )
92
93
setAnnouncement ( cannedResponse )
@@ -98,6 +99,7 @@ export function AskAIResults({
98
99
message : cannedResponse ,
99
100
sources : [ ] ,
100
101
aiCouldNotAnswer : true ,
102
+ connectedEventId : passedConversationId || conversationId ,
101
103
} ,
102
104
version ,
103
105
router . locale || 'en' ,
@@ -123,6 +125,7 @@ export function AskAIResults({
123
125
if ( cachedData ) {
124
126
setMessage ( cachedData . message )
125
127
setReferences ( cachedData . sources )
128
+ setConversationId ( cachedData . connectedEventId || '' )
126
129
setAICouldNotAnswer ( cachedData . aiCouldNotAnswer || false )
127
130
setInitialLoading ( false )
128
131
setResponseLoading ( false )
@@ -150,10 +153,6 @@ export function AskAIResults({
150
153
151
154
try {
152
155
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
- }
157
156
if ( ! response . ok ) {
158
157
console . error (
159
158
`Failed to fetch search results.\nStatus ${ response . status } \n${ response . statusText } ` ,
@@ -219,7 +218,14 @@ export function AskAIResults({
219
218
continue
220
219
}
221
220
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' ) {
223
229
if ( ! isCancelled ) {
224
230
sourcesBuffer = sourcesBuffer . concat ( parsedLine . sources )
225
231
sourcesBuffer = uniqBy ( sourcesBuffer , 'url' )
@@ -230,9 +236,9 @@ export function AskAIResults({
230
236
messageBuffer += parsedLine . text
231
237
setMessage ( messageBuffer )
232
238
}
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 )
236
242
}
237
243
if ( ! isCancelled ) {
238
244
setAnnouncement ( 'Copilot Response Loading...' )
0 commit comments