Skip to content

Commit 905d868

Browse files
authored
[AI Search] Support conversation_id in AISearchResultEvent and SurveyEvent (#55102)
1 parent 632815e commit 905d868

File tree

4 files changed

+26
-17
lines changed

4 files changed

+26
-17
lines changed

Diff for: src/events/lib/schema.ts

+8-10
Original file line numberDiff line numberDiff line change
@@ -418,8 +418,6 @@ const aiSearchResult = {
418418
required: [
419419
'type',
420420
'context',
421-
'ai_search_result_query',
422-
'ai_search_result_response',
423421
'ai_search_result_links_json',
424422
'ai_search_result_provided_answer',
425423
'ai_search_result_response_status',
@@ -430,14 +428,6 @@ const aiSearchResult = {
430428
type: 'string',
431429
pattern: '^aiSearchResult$',
432430
},
433-
ai_search_result_query: {
434-
type: 'string',
435-
description: 'The query the user searched for.',
436-
},
437-
ai_search_result_response: {
438-
type: 'string',
439-
description: "The GPT's response to the query.",
440-
},
441431
ai_search_result_links_json: {
442432
type: 'string',
443433
description:
@@ -451,6 +441,10 @@ const aiSearchResult = {
451441
type: 'number',
452442
description: 'The status code of the GPT response.',
453443
},
444+
ai_search_result_connected_event_id: {
445+
type: 'string',
446+
description: 'The id of the corresponding CSE copilot conversation event.',
447+
},
454448
},
455449
}
456450

@@ -487,6 +481,10 @@ const survey = {
487481
description:
488482
'The guessed language of the survey comment. The guessed language is very inaccurate when the string contains fewer than 3 or 4 words.',
489483
},
484+
survey_connected_event_id: {
485+
type: 'string',
486+
description: 'The id of the corresponding CSE copilot conversation event.',
487+
},
490488
},
491489
}
492490

Diff for: src/events/types.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,12 @@ export type EventProps = {
5555

5656
export type EventPropsByType = {
5757
[EventType.aiSearchResult]: {
58-
ai_search_result_query: string
59-
ai_search_result_response: string
6058
// Dynamic JSON string of an array of "link" objects in the form:
6159
// [{ "type": "reference" | "inline", "url": "https://..", "product": "issues" | "pages" | ... }, ...]
6260
ai_search_result_links_json: string
6361
ai_search_result_provided_answer: boolean
6462
ai_search_result_response_status: number
63+
ai_search_result_connected_event_id?: string
6564
}
6665
[EventType.clipboard]: {
6766
clipboard_operation: string
@@ -119,5 +118,6 @@ export type EventPropsByType = {
119118
survey_email?: string
120119
survey_rating?: number
121120
survey_comment_language?: string
121+
survey_connected_event_id?: string
122122
}
123123
}

Diff for: src/search/components/input/AskAIResults.tsx

+15-3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ type AISearchResultEventParams = {
3838
eventGroupId: string
3939
couldNotAnswer?: boolean
4040
status: number
41+
connectedEventId?: string
4142
}
4243

4344
export function AskAIResults({
@@ -67,11 +68,14 @@ export function AskAIResults({
6768
message: string
6869
sources: AIReference[]
6970
aiCouldNotAnswer: boolean
71+
connectedEventId?: string
7072
}>('ai-query-cache', 1000, 7)
7173

7274
const [isCopied, setCopied] = useClipboard(message, { successDuration: 1400 })
7375
const [feedbackSelected, setFeedbackSelected] = useState<null | 'up' | 'down'>(null)
7476

77+
const [conversationId, setConversationId] = useState<string>('')
78+
7579
const handleAICannotAnswer = () => {
7680
setInitialLoading(false)
7781
setResponseLoading(false)
@@ -129,6 +133,7 @@ export function AskAIResults({
129133
eventGroupId: askAIEventGroupId.current,
130134
couldNotAnswer: cachedData.aiCouldNotAnswer,
131135
status: cachedData.aiCouldNotAnswer ? 400 : 200,
136+
connectedEventId: cachedData.connectedEventId,
132137
})
133138

134139
setTimeout(() => {
@@ -141,6 +146,7 @@ export function AskAIResults({
141146
async function fetchData() {
142147
let messageBuffer = ''
143148
let sourcesBuffer: AIReference[] = []
149+
let conversationIdBuffer = ''
144150

145151
try {
146152
const response = await executeAISearch(router, version, query, debug)
@@ -212,6 +218,9 @@ export function AskAIResults({
212218
messageBuffer += parsedLine.text
213219
setMessage(messageBuffer)
214220
}
221+
} else if (parsedLine.chunkType === 'CONVERSATION_ID') {
222+
conversationIdBuffer = parsedLine.conversation_id
223+
setConversationId(parsedLine.conversation_id)
215224
}
216225
if (!isCancelled) {
217226
setAnnouncement('Copilot Response Loading...')
@@ -233,6 +242,7 @@ export function AskAIResults({
233242
message: messageBuffer,
234243
sources: sourcesBuffer,
235244
aiCouldNotAnswer: false,
245+
connectedEventId: conversationIdBuffer,
236246
},
237247
version,
238248
router.locale || 'en',
@@ -245,6 +255,7 @@ export function AskAIResults({
245255
eventGroupId: askAIEventGroupId.current,
246256
couldNotAnswer: false,
247257
status: 200,
258+
connectedEventId: conversationIdBuffer,
248259
})
249260
}
250261
}
@@ -299,6 +310,7 @@ export function AskAIResults({
299310
survey_vote: true,
300311
eventGroupKey: ASK_AI_EVENT_GROUP,
301312
eventGroupId: askAIEventGroupId.current,
313+
survey_connected_event_id: conversationId,
302314
})
303315
}}
304316
></IconButton>
@@ -320,6 +332,7 @@ export function AskAIResults({
320332
survey_vote: false,
321333
eventGroupKey: ASK_AI_EVENT_GROUP,
322334
eventGroupId: askAIEventGroupId.current,
335+
survey_connected_event_id: conversationId,
323336
})
324337
}}
325338
></IconButton>
@@ -409,6 +422,7 @@ function sendAISearchResultEvent({
409422
eventGroupId,
410423
couldNotAnswer = false,
411424
status,
425+
connectedEventId,
412426
}: AISearchResultEventParams) {
413427
let searchResultLinksJson = '[]'
414428
try {
@@ -418,12 +432,10 @@ function sendAISearchResultEvent({
418432
}
419433
sendEvent({
420434
type: EventType.aiSearchResult,
421-
// TODO: Remove PII so we can include the actual data
422-
ai_search_result_query: 'REDACTED',
423-
ai_search_result_response: 'REDACTED',
424435
ai_search_result_links_json: searchResultLinksJson,
425436
ai_search_result_provided_answer: couldNotAnswer ? false : true,
426437
ai_search_result_response_status: status,
438+
ai_search_result_connected_event_id: connectedEventId,
427439
eventGroupKey: ASK_AI_EVENT_GROUP,
428440
eventGroupId: eventGroupId,
429441
})

Diff for: src/search/components/input/SearchOverlay.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ export function SearchOverlay({
313313
sendEvent({
314314
type: EventType.search,
315315
// TODO: Remove PII so we can include the actual query
316-
search_query: 'REDACTED',
316+
search_query: urlSearchInputQuery,
317317
search_context: GENERAL_SEARCH_CONTEXT,
318318
eventGroupKey: SEARCH_OVERLAY_EVENT_GROUP,
319319
eventGroupId: searchEventGroupId.current,
@@ -343,7 +343,6 @@ export function SearchOverlay({
343343
// Fire event from onSelect instead of inside the API request function (executeAISearch), because the result could be cached and not trigger an event
344344
sendEvent({
345345
type: EventType.search,
346-
// TODO: Remove PII so we can include the actual query
347346
search_query: 'REDACTED',
348347
search_context: AI_SEARCH_CONTEXT,
349348
eventGroupKey: ASK_AI_EVENT_GROUP,

0 commit comments

Comments
 (0)