Skip to content

Commit 1acc64b

Browse files
ml12580steipete
andauthored
fix(ui): show original filename on chat history attachment cards instead of managed UUID suffix (#118628)
* fix(ui): prefer persisted fileName and strip managed UUID suffix from attachment card labels * fix(ui): anchor managed UUID removal to terminal storage suffix * fix(ui): preserve dotted UUID-shaped attachment names --------- Co-authored-by: Peter Steinberger <[email protected]>
1 parent 3b6cad7 commit 1acc64b

3 files changed

Lines changed: 130 additions & 4 deletions

File tree

‎ui/src/lib/chat/message-extract.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,16 @@ function hasTranscriptMediaFacts(message: unknown): boolean {
134134
export function readTranscriptMediaEntries(message: unknown): Array<{
135135
path: string;
136136
mediaType: string | undefined;
137+
fileName: string | undefined;
137138
}> {
138139
if (!message || typeof message !== "object") {
139140
return [];
140141
}
141142
return (readPersistedMediaFacts(message) ?? []).flatMap((fact) => {
142143
const path = fact.path ?? fact.url;
143-
return path ? [{ path, mediaType: fact.contentType ?? fact.kind }] : [];
144+
return path
145+
? [{ path, mediaType: fact.contentType ?? fact.kind, fileName: fact.fileName }]
146+
: [];
144147
});
145148
}
146149

‎ui/src/pages/chat/chat-history.media.test.ts‎

Lines changed: 111 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
import { describe, expect, it } from "vitest";
2-
import { isEmptyUserTextOnlyMessage } from "../../lib/chat/message-extract.ts";
2+
import {
3+
isEmptyUserTextOnlyMessage,
4+
readTranscriptMediaEntries,
5+
} from "../../lib/chat/message-extract.ts";
6+
import { extractTranscriptAttachments } from "./components/chat-message-media.ts";
7+
8+
const MANAGED_UUID = "43007e90-2ade-43f2-a781-42b843e9eca3";
9+
10+
function userMessageWithMedia(media: unknown[]): {
11+
role: string;
12+
content: string;
13+
__openclaw: { media: unknown[] };
14+
} {
15+
return { role: "user", content: "", __openclaw: { media } };
16+
}
317

418
describe("chat history canonical media filtering", () => {
519
it.each([
@@ -21,3 +35,99 @@ describe("chat history canonical media filtering", () => {
2135
expect(isEmptyUserTextOnlyMessage({ role: "user", content: "" })).toBe(true);
2236
});
2337
});
38+
39+
describe("chat history attachment card labels", () => {
40+
it("carries the persisted canonical fileName through the media projection", () => {
41+
const entries = readTranscriptMediaEntries(
42+
userMessageWithMedia([
43+
{
44+
path: `media://inbound/report---${MANAGED_UUID}.pdf`,
45+
fileName: "report.pdf",
46+
contentType: "application/pdf",
47+
},
48+
]),
49+
);
50+
expect(entries[0]?.fileName).toBe("report.pdf");
51+
});
52+
53+
it("labels a managed inbound attachment with the persisted original fileName", () => {
54+
const attachments = extractTranscriptAttachments(
55+
userMessageWithMedia([
56+
{
57+
path: `media://inbound/report---${MANAGED_UUID}.pdf`,
58+
fileName: "report.pdf",
59+
contentType: "application/pdf",
60+
},
61+
]),
62+
);
63+
expect(attachments[0]?.attachment.label).toBe("report.pdf");
64+
});
65+
66+
it("restores the original name from a legacy managed inbound UUID suffix when fileName is absent", () => {
67+
const attachments = extractTranscriptAttachments(
68+
userMessageWithMedia([
69+
{
70+
path: `media://inbound/openclaw-attachment-test---${MANAGED_UUID}.docx`,
71+
contentType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
72+
},
73+
]),
74+
);
75+
expect(attachments[0]?.attachment.label).toBe("openclaw-attachment-test.docx");
76+
});
77+
78+
it("leaves non-managed https attachment paths unchanged", () => {
79+
// `---old` is not a canonical managed UUID suffix, so it must not be stripped
80+
// from https URLs (which never carry the collision-safe managed suffix).
81+
const attachments = extractTranscriptAttachments(
82+
userMessageWithMedia([
83+
{
84+
path: "https://example.com/files/openclaw-attachment-test---old.docx",
85+
contentType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
86+
},
87+
]),
88+
);
89+
expect(attachments[0]?.attachment.label).toBe("openclaw-attachment-test---old.docx");
90+
});
91+
92+
it("does not strip a managed inbound basename that lacks a UUID suffix", () => {
93+
const attachments = extractTranscriptAttachments(
94+
userMessageWithMedia([
95+
{
96+
path: "media://inbound/plain-name.docx",
97+
contentType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
98+
},
99+
]),
100+
);
101+
expect(attachments[0]?.attachment.label).toBe("plain-name.docx");
102+
});
103+
104+
it("strips only the terminal managed UUID suffix, preserving a UUID-shaped segment in the original name", () => {
105+
// Legacy record (no persisted fileName) whose original filename itself
106+
// contains a "---<uuid>"-shaped segment before the terminal managed suffix.
107+
const attachments = extractTranscriptAttachments(
108+
userMessageWithMedia([
109+
{
110+
path: `media://inbound/report---a1b2c3d4-e5f6-7890-abcd-ef1234567890-final---${MANAGED_UUID}.docx`,
111+
contentType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
112+
},
113+
]),
114+
);
115+
expect(attachments[0]?.attachment.label).toBe(
116+
"report---a1b2c3d4-e5f6-7890-abcd-ef1234567890-final.docx",
117+
);
118+
});
119+
120+
it("preserves a dotted UUID-shaped segment in a legacy attachment name", () => {
121+
const path = `media://inbound/report---a1b2c3d4-e5f6-7890-abcd-ef1234567890.backup---${MANAGED_UUID}.pdf`;
122+
const attachments = extractTranscriptAttachments(
123+
userMessageWithMedia([{ path, contentType: "application/pdf" }]),
124+
);
125+
126+
expect(attachments[0]?.attachment).toMatchObject({
127+
url: path,
128+
label: "report---a1b2c3d4-e5f6-7890-abcd-ef1234567890.backup.pdf",
129+
mimeType: "application/pdf",
130+
});
131+
expect(attachments[0]?.attachment.label).not.toContain(MANAGED_UUID);
132+
});
133+
});

‎ui/src/pages/chat/components/chat-message-media.ts‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,8 +360,21 @@ function isVideoTranscriptMediaPath(path: string, mediaType: unknown): boolean {
360360
return hasVideoMediaFileExtension(path);
361361
}
362362

363+
// Collision-safe managed inbound URIs store the original filename plus a
364+
// terminal "---<uuid>" storage suffix in the basename
365+
// (e.g. media://inbound/report---<uuid>.pdf). Restore the original filename by
366+
// removing only that final generated segment, so an original name that itself
367+
// contains a "---<uuid>"-shaped part is preserved; the stored URI is unchanged.
368+
const MANAGED_INBOUND_MEDIA_PREFIX = "media://inbound/";
369+
const MANAGED_INBOUND_UUID_SUFFIX_PATTERN =
370+
/---[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}(?=\.[^./]*$|$)/i;
371+
363372
function labelForMediaPath(mediaPath: string): string {
364373
const trimmed = mediaPath.trim();
374+
if (trimmed.startsWith(MANAGED_INBOUND_MEDIA_PREFIX)) {
375+
const basename = trimmed.split("/").pop()?.trim() || trimmed;
376+
return basename.replace(MANAGED_INBOUND_UUID_SUFFIX_PATTERN, "") || basename;
377+
}
365378
try {
366379
if (/^https?:\/\//i.test(trimmed)) {
367380
const parsed = new URL(trimmed);
@@ -556,7 +569,7 @@ export function schedulePairingQrExpiryRefresh(
556569

557570
export function extractTranscriptAttachments(message: unknown): AttachmentItem[] {
558571
const attachments: AttachmentItem[] = [];
559-
for (const { path: mediaPath, mediaType } of readTranscriptMediaEntries(message)) {
572+
for (const { path: mediaPath, mediaType, fileName } of readTranscriptMediaEntries(message)) {
560573
if (isImageTranscriptMediaPath(mediaPath, mediaType)) {
561574
continue;
562575
}
@@ -570,7 +583,7 @@ export function extractTranscriptAttachments(message: unknown): AttachmentItem[]
570583
attachment: {
571584
url: mediaPath,
572585
kind,
573-
label: labelForMediaPath(mediaPath),
586+
label: fileName?.trim() || labelForMediaPath(mediaPath),
574587
...(typeof mediaType === "string" ? { mimeType: mediaType } : {}),
575588
},
576589
});

0 commit comments

Comments
 (0)