diff --git a/ChromiumBasedEditors/plugins/ai-agent/src/lib/utils.ts b/ChromiumBasedEditors/plugins/ai-agent/src/lib/utils.ts index ff575365..e8c4226f 100644 --- a/ChromiumBasedEditors/plugins/ai-agent/src/lib/utils.ts +++ b/ChromiumBasedEditors/plugins/ai-agent/src/lib/utils.ts @@ -39,12 +39,16 @@ export const convertMessagesToMd = (messages: ThreadMessageLike[]) => { return content; }; +export const removeSpecialCharacter = (str: string) => { + return str.replace(/[\\/:*"<>|?]/g, ""); +}; + export const getMessageTitleFromMd = (md: string) => { const lines = md.split("\n"); const title = lines[0].replace("## ", ""); - return title.substring(0, 30); + return removeSpecialCharacter(title).substring(0, 30); }; export const isDocument = (type: number) => { diff --git a/ChromiumBasedEditors/plugins/ai-agent/src/store/useThreadsStore.ts b/ChromiumBasedEditors/plugins/ai-agent/src/store/useThreadsStore.ts index 297e8a72..6eef523e 100644 --- a/ChromiumBasedEditors/plugins/ai-agent/src/store/useThreadsStore.ts +++ b/ChromiumBasedEditors/plugins/ai-agent/src/store/useThreadsStore.ts @@ -9,7 +9,7 @@ import { } from "@/database/threads"; import { readMessages } from "@/database/messages"; import type { Thread } from "@/lib/types"; -import { convertMessagesToMd } from "@/lib/utils"; +import { convertMessagesToMd, removeSpecialCharacter } from "@/lib/utils"; type UseThreadsStoreProps = { threadId: string; @@ -71,7 +71,7 @@ const useThreadsStore = create((set, get) => ({ const thread = thisStore.threads.find((t) => t.threadId === id); const messages = await readMessages(id); - const title = thread?.title || "Chat Export"; + const title = removeSpecialCharacter(thread?.title || "Chat Export"); const content = convertMessagesToMd(messages);