@@ -53,22 +53,25 @@ export function groupPromptsByRelativeDate(prompts: Prompt[]) {
53
53
const promptsSorted = prompts . sort (
54
54
( a , b ) =>
55
55
new Date ( b . conversation_timestamp ) . getTime ( ) -
56
- new Date ( a . conversation_timestamp ) . getTime ( )
56
+ new Date ( a . conversation_timestamp ) . getTime ( ) ,
57
57
) ;
58
58
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 ) ;
64
65
65
- if ( ! groups [ group ] ) {
66
- groups [ group ] = [ ] ;
67
- }
66
+ if ( ! groups [ group ] ) {
67
+ groups [ group ] = [ ] ;
68
+ }
68
69
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
+ ) ;
72
75
73
76
return grouped ;
74
77
}
@@ -82,13 +85,13 @@ export function getAllIssues(alerts: Alert[]) {
82
85
}
83
86
return acc ;
84
87
} ,
85
- { }
88
+ { } ,
86
89
) ;
87
90
88
91
const maxCount = Math . max ( ...Object . values ( groupedTriggerCounts ) ) ;
89
92
90
93
const sortedTagCounts = Object . entries ( groupedTriggerCounts ) . sort (
91
- ( [ , countA ] , [ , countB ] ) => countB - countA
94
+ ( [ , countA ] , [ , countB ] ) => countB - countA ,
92
95
) ;
93
96
return { maxCount, sortedTagCounts } ;
94
97
}
@@ -120,22 +123,17 @@ export function sanitizeQuestionPrompt({
120
123
answer : string ;
121
124
} ) {
122
125
try {
126
+ // it shouldn't be possible to receive the prompt answer without a question
127
+ if ( ! answer ) return question ;
128
+
123
129
// 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 ( ) ;
138
135
}
136
+ return answer ;
139
137
} catch ( error ) {
140
138
// Log the error and return the original question as a fallback
141
139
console . error ( "Error processing the question:" , error ) ;
0 commit comments