From f0aa9d528970de4ddd690df01f9f726caee8cd5b Mon Sep 17 00:00:00 2001
From: dawn <90008@klbr.net>
Date: Wed, 18 Nov 2026 20:05:10 +0300
Subject: [PATCH] feat(web): attach and play audio and video clips
Signed-off-by: dawn <90008@klbr.net>
---
web/scripts/transcript.test.mjs | 9 ++-
web/src/lib/chat/Chat.svelte | 32 +++++++++--
web/src/lib/chat/Clips.svelte | 95 +++++++++++++++++++++++++++++++
web/src/lib/chat/Composer.svelte | 50 +++++++++++++---
web/src/lib/chat/WorkSteps.svelte | 9 ++-
web/src/lib/chat/attachments.ts | 41 ++++++++++++-
web/src/lib/context.ts | 5 +-
web/src/lib/transcript.svelte.ts | 9 ++-
8 files changed, 229 insertions(+), 21 deletions(-)
create mode 100644 web/src/lib/chat/Clips.svelte
diff --git a/web/scripts/transcript.test.mjs b/web/scripts/transcript.test.mjs
index 73524d07c..47c54a08c 100644
--- a/web/scripts/transcript.test.mjs
+++ b/web/scripts/transcript.test.mjs
@@ -215,7 +215,7 @@ test('history shows file cards only from entry metadata and keeps label-like wor
};
attached.content.push({
kind: 'image',
- image: { reference: { url: '/image-one' } },
+ image: { mime_type: 'image/png', reference: { url: '/image-one' } },
});
api.reset([literal, attached]);
const transcript = new Transcript('session');
@@ -228,7 +228,12 @@ test('history shows file cards only from entry metadata and keeps label-like wor
assert.equal(second.text, 'inspect [Image #1]');
assert.deepEqual(second.files, [{ name: 'report.pdf', size: 12 }]);
assert.deepEqual(second.images, [
- { src: '/api/image-one', width: undefined, height: undefined },
+ {
+ src: '/api/image-one',
+ width: undefined,
+ height: undefined,
+ mime: 'image/png',
+ },
]);
});
diff --git a/web/src/lib/chat/Chat.svelte b/web/src/lib/chat/Chat.svelte
index 3cf0db2b7..b4397ba82 100644
--- a/web/src/lib/chat/Chat.svelte
+++ b/web/src/lib/chat/Chat.svelte
@@ -95,6 +95,7 @@
import { compose, drafts, finishNotes } from '../notes';
import { draftOf } from './drafts';
import {
+ clipKind,
filenameParts,
formatSize,
type Attached,
@@ -112,6 +113,7 @@
type Displayed,
type Group,
type Made,
+ type Picture,
} from '../transcript.svelte';
import { traceLink } from '../tracelink.svelte';
import {
@@ -121,6 +123,7 @@
import { VirtualList } from './virtual.svelte';
import Composer from './Composer.svelte';
import QueuePanel from './QueuePanel.svelte';
+ import Clips from './Clips.svelte';
import ImageGallery from './ImageGallery.svelte';
import Markdown from './Markdown.svelte';
import Receipt from './Receipt.svelte';
@@ -1501,6 +1504,14 @@
)}
{@const senderLabel =
(group.from?.trim() || null) ?? (agentRole ? 'agent' : null)}
+ {@const pictures = group.images.filter(
+ (picture) => !clipKind(picture.mime),
+ )}
+ {@const clips = group.images.filter((picture) =>
+ clipKind(picture.mime),
+ )}
+ {@const number = (picture: Picture) =>
+ group.images.indexOf(picture) + 1}
{/if}
{/if}
- {#if group.images.length}
+ {#if pictures.length}
-
+
{#snippet children(open)}
- {#each group.images as picture, index (index)}
+ {#each pictures as picture, index (index)}
{@const thumb = thumbnailSource(picture)}
{/if}
+ {#if clips.length}
+
+
+
+ {/if}
{#if group.files.length}
+ import type { Picture } from '../transcript.svelte';
+ import { clipKind } from './attachments';
+
+ // numbers default to clips only: pass them when the message has pictures too.
+ let {
+ clips,
+ label,
+ numbers = clips.map((_, index) => index + 1),
+ end = false,
+ }: {
+ clips: Picture[];
+ label: string;
+ numbers?: number[];
+ end?: boolean;
+ } = $props();
+
+
+
+ {#each clips as clip, index (index)}
+
+ {#if clipKind(clip.mime) === 'video'}
+
+
+ {:else}
+
+ {/if}
+ {clip.mime}
+
+ {/each}
+
+
+
diff --git a/web/src/lib/chat/Composer.svelte b/web/src/lib/chat/Composer.svelte
index 0fe67a74e..08b42b3c5 100644
--- a/web/src/lib/chat/Composer.svelte
+++ b/web/src/lib/chat/Composer.svelte
@@ -4,8 +4,10 @@
import { parse, suggest, type Command } from '../commands';
import { skillMentionAt } from '../skill-mentions';
import {
+ ACCEPTED,
attachmentSize,
chooseAttachment,
+ clipKind,
collectAttachments,
filenameParts,
formatSize,
@@ -229,13 +231,23 @@
tile.className = 'inline-tile';
tile.contentEditable = 'false';
tile.dataset.image = String(n);
- const img = document.createElement('img');
- img.src = image.preview;
- img.alt = marker(n);
+ const kind = clipKind(image.mime_type);
+ let face: HTMLElement;
+ if (kind) {
+ face = document.createElement('span');
+ face.className = 'tile-clip';
+ face.textContent = kind;
+ face.title = `${marker(n)}: ${image.mime_type}`;
+ } else {
+ const img = document.createElement('img');
+ img.src = image.preview;
+ img.alt = marker(n);
+ face = img;
+ }
const num = document.createElement('span');
num.className = 'tile-num';
num.textContent = `#${n}`;
- tile.append(img, num);
+ tile.append(face, num);
tile.addEventListener('pointerenter', () => showHover(n, tile));
tile.addEventListener('pointerleave', scheduleHideHover);
tile.addEventListener('click', (event) => {
@@ -847,6 +859,7 @@
{/if}
{#if hovered && images.has(hovered.n)}
+ {@const shown = images.get(hovered.n)!}
clearTimeout(hoverTimer)}
onpointerleave={scheduleHideHover}
>
-
+ {#if clipKind(shown.mime_type) === 'video'}
+
+
+ {:else if clipKind(shown.mime_type)}
+
+ {:else}
+
+ {/if}
#{hovered.n}
{
@@ -1348,6 +1368,17 @@
object-fit: cover;
border-radius: inherit;
}
+ .editor :global(.tile-clip) {
+ display: grid;
+ place-items: center;
+ width: 100%;
+ height: 100%;
+ color: var(--muted);
+ font-family: var(--mono);
+ font-size: var(--type-2xs);
+ background: var(--surface);
+ border-radius: inherit;
+ }
.editor :global(.tile-num) {
position: absolute;
right: -3px;
@@ -1379,13 +1410,18 @@
box-shadow: var(--shadow-lg);
transform: translateX(-50%);
}
- .tile-loupe img {
+ .tile-loupe img,
+ .tile-loupe video {
display: block;
width: 148px;
height: 98px;
object-fit: cover;
border-radius: 7px;
}
+ .tile-loupe audio {
+ display: block;
+ width: 240px;
+ }
.loupe-num {
position: absolute;
bottom: 7px;
diff --git a/web/src/lib/chat/WorkSteps.svelte b/web/src/lib/chat/WorkSteps.svelte
index a8538c403..529aef042 100644
--- a/web/src/lib/chat/WorkSteps.svelte
+++ b/web/src/lib/chat/WorkSteps.svelte
@@ -13,6 +13,8 @@
type Made,
type Transcript,
} from '../transcript.svelte';
+ import { clipKind } from './attachments';
+ import Clips from './Clips.svelte';
import ImageGallery from './ImageGallery.svelte';
import Markdown from './Markdown.svelte';
import LiveFace from '../LiveFace.svelte';
@@ -94,7 +96,9 @@
const tools = $derived(
steps.flatMap((step) => (step.kind === 'tool' ? [step.entry] : [])),
);
- const pictures = $derived(tools.flatMap(picturesOf));
+ const attached = $derived(tools.flatMap(picturesOf));
+ const pictures = $derived(attached.filter((item) => !clipKind(item.mime)));
+ const clips = $derived(attached.filter((item) => clipKind(item.mime)));
const summary = $derived(
summarize(
steps.flatMap((step): Step[] => {
@@ -389,6 +393,9 @@
{/if}
+ {#if clips.length}
+
+ {/if}