Skip to content
This repository was archived by the owner on Jul 8, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/components/PromptList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export function PromptList({ prompts }: { prompts: Prompt[] }) {
const { currentPromptId, setCurrentPromptId } = usePromptsStore();

const groupedPrompts = groupPromptsByRelativeDate(prompts);

return (
<div className="mx-2">
{Object.entries(groupedPrompts).map(([group, prompts]) => (
Expand Down
9 changes: 7 additions & 2 deletions src/hooks/useBreadcrumb.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { extractTitleFromMessage } from "@/lib/utils";
import { extractTitleFromMessage, sanitizeQuestionPrompt } from "@/lib/utils";
import { useLocation } from "react-router-dom";
import { usePromptsStore } from "./usePromptsStore";

Expand All @@ -20,7 +20,12 @@ export function useBreadcrumb() {
try {
const chat = prompts.find((prompt) => prompt.chat_id === currentPromptId);
const title = chat?.question_answers?.[0].question.message ?? "";
return extractTitleFromMessage(title) ?? "";

const sanitized = sanitizeQuestionPrompt({
question: title,
answer: chat?.question_answers?.[0]?.answer?.message ?? "",
});
return extractTitleFromMessage(sanitized) ?? "";
} catch {
return "";
}
Expand Down
26 changes: 21 additions & 5 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@ export function cn(...inputs: ClassValue[]) {
}

export function extractTitleFromMessage(message: string) {
if (message.includes("review codegate")) {
console.log("message is");
console.log(JSON.stringify(message, null, 2));
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 why we need to log this? usually it is better to avoid console log for security reason

try {
const regex = /^(.*)```[\s\S]*?```(.*)$/s;
const match = message.match(regex);

if (match) {
const beforeMarkdown = match[1].trim();
const afterMarkdown = match[2].trim();

const title = beforeMarkdown || afterMarkdown;
return title;
}
Expand Down Expand Up @@ -121,12 +124,25 @@ export function sanitizeQuestionPrompt({
answer: string;
}) {
try {
// Check if 'answer' is truthy; if so, try to find and return the text after "Query:"
if (answer) {
return question.split("Query:").pop() ?? "";
const index = question.indexOf("Query:");
if (index !== -1) {
// Return the substring starting right after the first occurrence of "Query:"
// Adding the length of "Query:" to the index to start after it
return question.substring(index + "Query:".length).trim();
} else {
// If there is no "Query:" in the string, log the condition and return an empty string
console.log("No 'Query:' found in the question.");
return "";
}
} else {
// If 'answer' is not provided or falsy, return the original question
return question;
}

return question;
} catch {
} catch (error) {
// Log the error and return the original question as a fallback
console.error("Error processing the question:", error);
return question;
}
}