fix: sanitize thread titles — reject UUID/hash/empty values, fallback to 新对话
Deploy LangGraph Server to Azure Web App / build-and-deploy (push) Failing after 37s
Deploy LangGraph UI to Azure Static Web Apps / build-and-deploy (push) Failing after 47s

This commit is contained in:
gongzhiyong
2026-04-12 15:01:29 +08:00
parent b93f08f206
commit 66eaf7680d
+14 -7
View File
@@ -37,6 +37,13 @@ function getLocalTitle(threadId: string): string | null {
}
}
// Reject titles that look like UUIDs, short hashes, or empty strings
const BAD_TITLE = /^[0-9a-f-]{8,}$/i;
function sanitizeTitle(s: unknown): string | null {
if (typeof s !== "string" || !s.trim() || BAD_TITLE.test(s.trim())) return null;
return s.trim();
}
function groupByDate(threads: ThreadItem[]): { label: string; threads: ThreadItem[] }[] {
const now = new Date();
const groups: Record<string, ThreadItem[]> = {};
@@ -101,10 +108,10 @@ export function ThreadSidebar({
const filtered = threads.filter((t) => {
const label =
getLocalTitle(t.thread_id) ??
(t.metadata?.title as string) ??
(t.metadata?.firstMessage as string) ??
t.thread_id;
sanitizeTitle(getLocalTitle(t.thread_id)) ??
sanitizeTitle(t.metadata?.title) ??
sanitizeTitle(t.metadata?.firstMessage) ??
"新对话";
return label.toLowerCase().includes(searchQuery.toLowerCase());
});
@@ -190,9 +197,9 @@ export function ThreadSidebar({
{groupThreads.map((t) => {
const isActive = t.thread_id === currentThreadId;
const itemLabel =
getLocalTitle(t.thread_id) ??
(t.metadata?.title as string) ??
(t.metadata?.firstMessage as string) ??
sanitizeTitle(getLocalTitle(t.thread_id)) ??
sanitizeTitle(t.metadata?.title) ??
sanitizeTitle(t.metadata?.firstMessage) ??
"新对话";
const displayLabel = itemLabel.length > 16
? itemLabel.slice(0, 16) + "…"