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
+41 -25

No files matched your search

@@ -1,9 +1,10 @@
import type { BaseStream } from "@langchain/langgraph-sdk"; import type { BaseStream } from "@langchain/langgraph-sdk";
import { useEffect } from "react"; 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 { desensitize } from "@/lib/desensitize"; import { sanitizeThreadTitleForDisplay } from "@/core/threads/utils";
import { desensitize } from "@/lib/desensitize";
import { useThreadChat } from "./chats"; import { useThreadChat } from "./chats";
import { FlipDisplay } from "./flip-display"; import { FlipDisplay } from "./flip-display";
@@ -16,16 +17,18 @@ export function ThreadTitle({
threadId: string; threadId: string;
thread: BaseStream<AgentThreadState>; thread: BaseStream<AgentThreadState>;
}) { }) {
const { t } = useI18n(); const { t } = useI18n();
const { isNewThread } = useThreadChat(); const { isNewThread } = useThreadChat();
useEffect(() => { const displayTitle = sanitizeThreadTitleForDisplay(thread.values?.title);
let _title = t.pages.untitled;
useEffect(() => {
if (thread.values?.title) { let _title = t.pages.untitled;
_title = thread.values.title;
} else if (isNewThread) { if (thread.values?.title) {
_title = t.pages.newChat; _title = displayTitle;
} } else if (isNewThread) {
_title = t.pages.newChat;
}
if (thread.isThreadLoading) { if (thread.isThreadLoading) {
document.title = `Loading... - ${t.pages.appName}`; document.title = `Loading... - ${t.pages.appName}`;
} else { } else {
@@ -35,17 +38,18 @@ export function ThreadTitle({
isNewThread, isNewThread,
t.pages.newChat, t.pages.newChat,
t.pages.untitled, t.pages.untitled,
t.pages.appName, t.pages.appName,
thread.isThreadLoading, thread.isThreadLoading,
thread.values, thread.values,
]); displayTitle,
]);
if (!thread.values?.title) { if (!thread.values?.title) {
return null; return null;
} }
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";
}