@@ -53,22 +53,25 @@ export function groupPromptsByRelativeDate(prompts: Prompt[]) {
5353 const promptsSorted = prompts . sort (
5454 ( a , b ) =>
5555 new Date ( b . conversation_timestamp ) . getTime ( ) -
56- new Date ( a . conversation_timestamp ) . getTime ( )
56+ new Date ( a . conversation_timestamp ) . getTime ( ) ,
5757 ) ;
5858
59- const grouped = promptsSorted . reduce ( ( groups , prompt ) => {
60- const promptDate = new Date ( prompt . conversation_timestamp ) ;
61- const now = new Date ( ) ;
62- const differenceInMs = now . getTime ( ) - promptDate . getTime ( ) ;
63- const group = getGroup ( differenceInMs , promptDate ) ;
59+ const grouped = promptsSorted . reduce (
60+ ( groups , prompt ) => {
61+ const promptDate = new Date ( prompt . conversation_timestamp ) ;
62+ const now = new Date ( ) ;
63+ const differenceInMs = now . getTime ( ) - promptDate . getTime ( ) ;
64+ const group = getGroup ( differenceInMs , promptDate ) ;
6465
65- if ( ! groups [ group ] ) {
66- groups [ group ] = [ ] ;
67- }
66+ if ( ! groups [ group ] ) {
67+ groups [ group ] = [ ] ;
68+ }
6869
69- groups [ group ] . push ( prompt ) ;
70- return groups ;
71- } , { } as Record < string , Prompt [ ] > ) ;
70+ groups [ group ] . push ( prompt ) ;
71+ return groups ;
72+ } ,
73+ { } as Record < string , Prompt [ ] > ,
74+ ) ;
7275
7376 return grouped ;
7477}
@@ -82,13 +85,13 @@ export function getAllIssues(alerts: Alert[]) {
8285 }
8386 return acc ;
8487 } ,
85- { }
88+ { } ,
8689 ) ;
8790
8891 const maxCount = Math . max ( ...Object . values ( groupedTriggerCounts ) ) ;
8992
9093 const sortedTagCounts = Object . entries ( groupedTriggerCounts ) . sort (
91- ( [ , countA ] , [ , countB ] ) => countB - countA
94+ ( [ , countA ] , [ , countB ] ) => countB - countA ,
9295 ) ;
9396 return { maxCount, sortedTagCounts } ;
9497}
@@ -120,22 +123,17 @@ export function sanitizeQuestionPrompt({
120123 answer : string ;
121124} ) {
122125 try {
126+ // it shouldn't be possible to receive the prompt answer without a question
127+ if ( ! answer ) return question ;
128+
123129 // Check if 'answer' is truthy; if so, try to find and return the text after "Query:"
124- if ( answer ) {
125- const index = question . indexOf ( "Query:" ) ;
126- if ( index !== - 1 ) {
127- // Return the substring starting right after the first occurrence of "Query:"
128- // Adding the length of "Query:" to the index to start after it
129- return question . substring ( index + "Query:" . length ) . trim ( ) ;
130- } else {
131- // If there is no "Query:" in the string, log the condition and return an empty string
132- console . log ( "No 'Query:' found in the question." ) ;
133- return "" ;
134- }
135- } else {
136- // If 'answer' is not provided or falsy, return the original question
137- return question ;
130+ const index = question . indexOf ( "Query:" ) ;
131+ if ( index !== - 1 ) {
132+ // Return the substring starting right after the first occurrence of "Query:"
133+ // Adding the length of "Query:" to the index to start after it
134+ return question . substring ( index + "Query:" . length ) . trim ( ) ;
138135 }
136+ return answer ;
139137 } catch ( error ) {
140138 // Log the error and return the original question as a fallback
141139 console . error ( "Error processing the question:" , error ) ;
0 commit comments