Files
archie/ui/src/chat/attachment.ts
T
sam a7efb9bb00 feat(webui): show attachment metadata in the session transcript
A message's attachments persist as metadata (messaging.Message.Media) and
cross the gateway wire, but the dashboard transcript rendered text only, so
a photo was invisible to the operator while the model had seen it.

The transcript view now carries the persisted metadata, and the browser
labels each attachment in the placeholder vocabulary the channels already
write into a message's text ('[photo]', '[document: report.pdf]'), with the
surviving metadata (mime, name, size, dimensions, duration) in the chip's
tooltip.

Bytes are never rendered: they are turn-scoped and stripped before a record
is stored, so there is nothing to fetch and no broken image or 404 link. The
platform file id is deliberately not served either -- it is a download
handle, not an address -- so the chip links out only when the attachment
itself carried a URL. A message with no attachments omits the media key, so
transcripts written before this change keep the payload they had.
2026-09-30 03:57:39 +10:00

51 lines
1.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import type { ChatMedia } from "./state";
/**
* How a transcript renders an attachment whose bytes it does not have.
*
* The bytes are turn-scoped and never reach a browser, so the label stands in
* for the file. It reuses the placeholder vocabulary the channels already
* write into a message's text (`[photo]`, `[document: report.pdf]` — see the
* notes in `internal/channels/telegram/inboundmedia.go`), so the same
* attachment reads the same whether its metadata survived persistence or only
* the note in its text did.
*/
export function mediaLabel(attachment: ChatMedia): string {
switch (attachment.type) {
case "image":
return "[photo]";
case "video":
return "[video]";
case "audio":
return "[audio]";
case "document":
return attachment.file_name
? `[document: ${attachment.file_name}]`
: "[document]";
default:
return `[${attachment.type || "attachment"}]`;
}
}
/**
* The metadata behind the label, for the chip's tooltip: mime type, file name,
* size, dimensions and duration, in the order a reader asks about them.
*
* It reports only what the record actually carried, so an unknown size reads
* as absent rather than as zero, and it never names the platform file id — a
* handle is not information about the file.
*/
export function mediaDetail(attachment: ChatMedia): string {
const parts: string[] = [];
if (attachment.mime_type) parts.push(attachment.mime_type);
if (attachment.file_name) parts.push(attachment.file_name);
if (attachment.file_size !== undefined) {
parts.push(`${attachment.file_size} bytes`);
}
if (attachment.width && attachment.height) {
parts.push(`${attachment.width}×${attachment.height}`);
}
if (attachment.duration !== undefined) parts.push(`${attachment.duration} s`);
return parts.join(" · ");
}