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.
This commit is contained in:
sam committed 2026-09-30 03:57:39 +10:00
1 parent 7fb91173da
commit 170d9e4303
9 files changed
+354 -13

No files matched your search

+31
View File
@@ -0,0 +1,31 @@
<script setup lang="ts">
import { Paperclip } from "@lucide/vue";
import { mediaDetail, mediaLabel } from "./attachment";
import type { ChatMedia } from "./state";
/**
* One attachment a message carried, as the transcript shows it.
*
* The bytes are gone by design — they are turn-scoped and are stripped before
* the record is stored — so this is a labelled chip rather than a preview. It
* links out only when the attachment itself carried a URL; a platform file id
* is deliberately never rendered, because it is a handle rather than an
* address and a chip that 404s is worse than no chip.
*/
defineProps<{ attachment: ChatMedia }>();
</script>
<template>
<component
:is="attachment.url ? 'a' : 'span'"
:href="attachment.url"
:target="attachment.url ? '_blank' : undefined"
:rel="attachment.url ? 'noopener noreferrer' : undefined"
:title="mediaDetail(attachment)"
class="inline-flex max-w-full items-center gap-1.5 rounded-full border border-border bg-muted px-2.5 py-1 text-xs font-medium text-muted-foreground"
>
<Paperclip aria-hidden="true" class="size-3.5 shrink-0" />
<span class="truncate">{{ mediaLabel(attachment) }}</span>
</component>
</template>
+12 -2
View File
@@ -1,8 +1,9 @@
<script setup lang="ts">
import { cn } from "@/lib/utils";
import ChatAttachment from "./ChatAttachment.vue";
import ChatMarkdown from "./ChatMarkdown.vue";
import ChatToolCall from "./ChatToolCall.vue";
import type { ChatToolCall as ToolCall } from "./state";
import type { ChatMedia, ChatToolCall as ToolCall } from "./state";
/**
* One message, from either side of the conversation. There is no speaker
@@ -14,11 +15,13 @@ withDefaults(
defineProps<{
text: string;
tools?: ToolCall[];
/** Attachments the message carried, which have no bytes left to render. */
media?: ChatMedia[];
assistant?: boolean;
/** The turn is still arriving: a tool call with no outcome is running. */
streaming?: boolean;
}>(),
{ tools: () => [], assistant: false, streaming: false },
{ tools: () => [], media: () => [], assistant: false, streaming: false },
);
</script>
@@ -40,6 +43,13 @@ withDefaults(
:streaming="streaming"
/>
</div>
<div v-if="media.length" class="mb-2 flex flex-wrap gap-1.5">
<ChatAttachment
v-for="(attachment, i) in media"
:key="i"
:attachment="attachment"
/>
</div>
<ChatMarkdown v-if="assistant" :text="text" />
<div v-else class="whitespace-pre-wrap">{{ text }}</div>
<slot />
+4
View File
@@ -37,6 +37,9 @@ function parts(message: ChatMessage) {
return {
text: message.text ?? message.Text ?? "",
tools: message.tool_calls || message.ToolCalls || [],
// Attachments have no bytes left to render -- the record kept their
// metadata only -- so the bubble labels them.
media: message.media || [],
assistant: from !== "web",
};
}
@@ -63,6 +66,7 @@ const bubbles = computed(() => messages.value.map(parts));
<ChatBubble
:text="bubble.text"
:tools="bubble.tools"
:media="bubble.media"
:assistant="bubble.assistant"
/>
</MessageScrollerItem>
+50
View File
@@ -0,0 +1,50 @@
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(" · ");
}
+21
View File
@@ -58,10 +58,31 @@ export interface ChatToolCall {
err?: string;
}
/**
* One attachment a message carried, as a recorded transcript serves it. The
* bytes are turn-scoped and never reach a browser, so this is metadata only;
* `url` is present exactly when the attachment itself carried one, and a
* platform file id never appears here because it is a handle, not an address.
*/
export interface ChatMedia {
type: string;
file_name?: string;
mime_type?: string;
file_size?: number;
width?: number;
height?: number;
duration?: number;
url?: string;
}
/** One message in the transcript, from either side. */
export interface ChatMessage {
from?: string;
text?: string;
// Attachments only ever arrive in the served transcript, never from this
// browser's composer, so unlike the fields below this one has no second
// spelling to read.
media?: ChatMedia[];
tool_calls?: ChatToolCall[];
// The same view reaches the browser from more than one composition, so both
// spellings are read rather than assuming one serialiser.