This repository was archived by the owner on Jul 8, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +45
-12
lines changed Expand file tree Collapse file tree 3 files changed +45
-12
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ import { useParams } from "react-router-dom";
88import { usePromptsStore } from "@/hooks/usePromptsStore" ;
99import { Markdown } from "./Markdown" ;
1010import { useEffect } from "react" ;
11+ import { sanitizeQuestionPrompt } from "@/lib/utils" ;
1112
1213export function Chat ( ) {
1314 const { id } = useParams ( ) ;
@@ -31,7 +32,10 @@ export function Chat() {
3132 < ChatBubbleAvatar fallback = "User" className = "w-14" />
3233 < ChatBubbleMessage variant = "sent" className = "bg-zinc-700" >
3334 < Markdown className = "text-gray-300" >
34- { question ?. message }
35+ { sanitizeQuestionPrompt ( {
36+ question : question ?. message ,
37+ answer : answer ?. message ,
38+ } ) }
3539 </ Markdown >
3640 </ ChatBubbleMessage >
3741 </ ChatBubble >
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import { Link } from "react-router-dom";
33import {
44 extractTitleFromMessage ,
55 groupPromptsByRelativeDate ,
6+ sanitizeQuestionPrompt ,
67} from "@/lib/utils" ;
78import { usePromptsStore } from "@/hooks/usePromptsStore" ;
89import clsx from "clsx" ;
@@ -28,8 +29,14 @@ export function PromptList({ prompts }: { prompts: Prompt[] }) {
2829 ) }
2930 >
3031 { extractTitleFromMessage (
31- prompt . question_answers ?. [ 0 ] . question . message ??
32- `Prompt ${ prompt . conversation_timestamp } `
32+ prompt . question_answers ?. [ 0 ] . question . message
33+ ? sanitizeQuestionPrompt ( {
34+ question :
35+ prompt . question_answers ?. [ 0 ] . question . message ,
36+ answer :
37+ prompt . question_answers ?. [ 0 ] ?. answer ?. message ?? "" ,
38+ } )
39+ : `Prompt ${ prompt . conversation_timestamp } `
3340 ) }
3441 </ Link >
3542 </ li >
Original file line number Diff line number Diff line change @@ -13,18 +13,22 @@ export function cn(...inputs: ClassValue[]) {
1313}
1414
1515export function extractTitleFromMessage ( message : string ) {
16- const regex = / ^ ( .* ) ` ` ` [ \s \S ] * ?` ` ` ( .* ) $ / s;
17- const match = message . match ( regex ) ;
16+ try {
17+ const regex = / ^ ( .* ) ` ` ` [ \s \S ] * ?` ` ` ( .* ) $ / s;
18+ const match = message . match ( regex ) ;
1819
19- if ( match ) {
20- const beforeMarkdown = match [ 1 ] . trim ( ) ;
21- const afterMarkdown = match [ 2 ] . trim ( ) ;
20+ if ( match ) {
21+ const beforeMarkdown = match [ 1 ] . trim ( ) ;
22+ const afterMarkdown = match [ 2 ] . trim ( ) ;
2223
23- const title = beforeMarkdown || afterMarkdown ;
24- return title ;
25- }
24+ const title = beforeMarkdown || afterMarkdown ;
25+ return title ;
26+ }
2627
27- return message . trim ( ) ;
28+ return message . trim ( ) ;
29+ } catch {
30+ return message . trim ( ) ;
31+ }
2832}
2933
3034function getGroup ( differenceInMs : number , promptDate : Date ) : string {
@@ -108,3 +112,21 @@ export function getMaliciousPackages() {
108112
109113 return chartData ;
110114}
115+
116+ export function sanitizeQuestionPrompt ( {
117+ question,
118+ answer,
119+ } : {
120+ question : string ;
121+ answer : string ;
122+ } ) {
123+ try {
124+ if ( answer ) {
125+ return question . split ( "Query:" ) . pop ( ) ?? "" ;
126+ }
127+
128+ return question ;
129+ } catch {
130+ return question ;
131+ }
132+ }
You can’t perform that action at this time.
0 commit comments