feat: 标题去除特殊tag

This commit is contained in:
ZyGuo committed 2026-06-02 16:24:01 +08:00
1 parent 0122d3e361
commit 3c92e87156
2 files changed
+18 -2

No files matched your search

@@ -3,6 +3,7 @@ import { useEffect } from "react";
import { useI18n } from "@/core/i18n/hooks"; import { useI18n } from "@/core/i18n/hooks";
import type { AgentThreadState } from "@/core/threads"; import type { AgentThreadState } from "@/core/threads";
import { sanitizeThreadTitleForDisplay } from "@/core/threads/utils";
import { desensitize } from "@/lib/desensitize"; import { desensitize } from "@/lib/desensitize";
import { useThreadChat } from "./chats"; import { useThreadChat } from "./chats";
@@ -18,11 +19,13 @@ export function ThreadTitle({
}) { }) {
const { t } = useI18n(); const { t } = useI18n();
const { isNewThread } = useThreadChat(); const { isNewThread } = useThreadChat();
const displayTitle = sanitizeThreadTitleForDisplay(thread.values?.title);
useEffect(() => { useEffect(() => {
let _title = t.pages.untitled; let _title = t.pages.untitled;
if (thread.values?.title) { if (thread.values?.title) {
_title = thread.values.title; _title = displayTitle;
} else if (isNewThread) { } else if (isNewThread) {
_title = t.pages.newChat; _title = t.pages.newChat;
} }
@@ -38,6 +41,7 @@ export function ThreadTitle({
t.pages.appName, t.pages.appName,
thread.isThreadLoading, thread.isThreadLoading,
thread.values, thread.values,
displayTitle,
]); ]);
if (!thread.values?.title) { if (!thread.values?.title) {
@@ -45,7 +49,7 @@ export function ThreadTitle({
} }
return ( return (
<FlipDisplay uniqueKey={threadId}> <FlipDisplay uniqueKey={threadId}>
{desensitize(thread.values.title ?? "Untitled")} {desensitize(displayTitle)}
</FlipDisplay> </FlipDisplay>
); );
} }
+12
View File
@@ -65,3 +65,15 @@ export function textOfMessage(message: Message) {
export function titleOfThread(thread: AgentThread) { export function titleOfThread(thread: AgentThread) {
return thread.values?.title ?? "Untitled"; return thread.values?.title ?? "Untitled";
} }
export function sanitizeThreadTitleForDisplay(title: string | null | undefined) {
if (!title) return "Untitled";
const cleaned = title
.replace(/<\/?[^>\n]+>/g, " ")
.replace(/<[^>\n]*$/g, " ")
.replace(/\s+/g, " ")
.trim();
return cleaned || "Untitled";
}