(messages: Message[], isLoading: boolean, hasActivePrompt = false, {
enabled = true
}: {
enabled?: boolean;
} = {})
| 45 | return false; |
| 46 | } |
| 47 | export function useMemorySurvey(messages: Message[], isLoading: boolean, hasActivePrompt = false, { |
| 48 | enabled = true |
| 49 | }: { |
| 50 | enabled?: boolean; |
| 51 | } = {}): { |
| 52 | state: 'closed' | 'open' | 'thanks' | 'transcript_prompt' | 'submitting' | 'submitted'; |
| 53 | lastResponse: FeedbackSurveyResponse | null; |
| 54 | handleSelect: (selected: FeedbackSurveyResponse) => void; |
| 55 | handleTranscriptSelect: (selected: TranscriptShareResponse) => void; |
| 56 | } { |
| 57 | // Track assistant message UUIDs that were already evaluated so we don't |
| 58 | // re-roll probability on re-renders or re-scan messages for the same turn. |
| 59 | const seenAssistantUuids = useRef<Set<string>>(new Set()); |
| 60 | // Once a memory file read is observed it stays true for the session — |
| 61 | // skip the O(n) scan on subsequent turns. |
| 62 | const memoryReadSeen = useRef(false); |
| 63 | const messagesRef = useRef(messages); |
| 64 | messagesRef.current = messages; |
| 65 | const onOpen = useCallback((appearanceId: string) => { |
| 66 | logEvent(MEMORY_SURVEY_EVENT, { |
| 67 | event_type: 'appeared' as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS, |
| 68 | appearance_id: appearanceId as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS |
| 69 | }); |
| 70 | void logOTelEvent('feedback_survey', { |
| 71 | event_type: 'appeared', |
| 72 | appearance_id: appearanceId, |
| 73 | survey_type: 'memory' |
| 74 | }); |
| 75 | }, []); |
| 76 | const onSelect = useCallback((appearanceId_0: string, selected: FeedbackSurveyResponse) => { |
| 77 | logEvent(MEMORY_SURVEY_EVENT, { |
| 78 | event_type: 'responded' as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS, |
| 79 | appearance_id: appearanceId_0 as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS, |
| 80 | response: selected as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS |
| 81 | }); |
| 82 | void logOTelEvent('feedback_survey', { |
| 83 | event_type: 'responded', |
| 84 | appearance_id: appearanceId_0, |
| 85 | response: selected, |
| 86 | survey_type: 'memory' |
| 87 | }); |
| 88 | }, []); |
| 89 | const shouldShowTranscriptPrompt = useCallback((selected_0: FeedbackSurveyResponse) => { |
| 90 | if ("external" !== 'ant') { |
| 91 | return false; |
| 92 | } |
| 93 | if (selected_0 !== 'bad' && selected_0 !== 'good') { |
| 94 | return false; |
| 95 | } |
| 96 | if (getGlobalConfig().transcriptShareDismissed) { |
| 97 | return false; |
| 98 | } |
| 99 | if (!isPolicyAllowed('allow_product_feedback')) { |
| 100 | return false; |
| 101 | } |
| 102 | return true; |
| 103 | }, []); |
| 104 | const onTranscriptPromptShown = useCallback((appearanceId_1: string) => { |
no test coverage detected