fix(web/claw): render and download the images a turn hands over
ci / checks (push) Successful in 1m13s
android / debug (push) Successful in 2m17s
android / release (push) Successful in 2m13s
ci / test (push) Successful in 42s
ci / chart (push) Successful in 5s
ci / docker (push) Successful in 1m52s
ci / web (push) Successful in 12s
ci / publish-edge-images (deploy/docker/claw.Dockerfile, rhema-claw) (push) Successful in 1m57s
ci / publish-edge-images (deploy/docker/ui.Dockerfile, rhema-claw-ui) (push) Successful in 13s
ci / publish-edge-chart (push) Successful in 3s

An attachment card lands inside the turn that produced it, and both
passes that touch image cards scanned only the top-level rows. The pass
that fetches bytes never saw the card, so it stayed a name and a size
with no picture. The pass that stores the fetched object URL had the
same blind spot, so even a fetch that ran dropped its result. Both now
walk finished turns and the live one, through one helper that knows
where cards live. Consents move to the same helper: a card whose turn
already closed had the same problem.

The download control was hidden for `media: "image"`, which left an
image with no way out of the store when its bytes did not paint, as
they never did. Every card offers it now. The anchor also joins the
document for the click, which some browsers require before they follow
a `download` on a blob URL.
This commit is contained in:
vhaudiquet committed 2026-11-24 21:17:02 +01:00
1 parent 1a1ace014a
commit 04b06e7623
4 files changed
+83 -67

No files matched your search

+10 -5
View File
@@ -112,11 +112,16 @@ Two consequences worth knowing before changing this code:
and again on the stream's `consent_resolved` echo; nothing persists
client-side, so a reload rebuilds the cards from the replay.
- **Attachments render inline.** An `attachment` event becomes a card
— media glyph, file name, B/KB/MB size, caption. Images fetch the
bearer-guarded bytes (`GET /v1/attachments/{id}`, blob → object URL,
like the identity images) and render capped at 240px; code and file
cards download on click. Object URLs cache per id, so a replay never
refetches.
— media glyph, file name, B/KB/MB size, caption. The media kind comes
from the file extension, decided by the daemon when it stores the
file, so a `.png` renders and a `.patch` downloads without the client
guessing. Images fetch the bearer-guarded bytes
(`GET /v1/attachments/{id}`, blob → object URL, like the identity
images) and render capped at 240px; every card downloads on click,
images included. A card lives inside the turn that produced it, so
the scan that fetches image bytes walks finished turns and the live
one, not just the top-level rows. Object URLs cache per id, so a
replay never refetches.
- **Your images ride along.** The composer's `+` — and an image on the
clipboard — stage as removable chips (`▣1 photo.png 1.2 MB`), the
claw's own budget enforced client-side (8 a message, 5 MiB decoded
+44 -30
View File
@@ -22,7 +22,7 @@ import type {
StreamStatus,
} from '~/composables/useClaw'
import { composeChips, useTranscript } from '~/composables/useTranscript'
import type { StagedImage } from '~/composables/useTranscript'
import type { AttachmentCard, StagedImage } from '~/composables/useTranscript'
const TOKEN_STORE_KEY = 'claw.token'
const ACTIVE_STORE_KEY = 'claw.activeKey'
@@ -131,39 +131,49 @@ const attemptedAttachments = new Set<string>()
// their attachment ids, never the bytes; locally sent rows hold their
// own object URLs.
//
// The watch is deep (rows mutate in place as their bytes land), and it
// fires on every streamed delta, so the scan covers only the items the
// last pass did not see — the transcript only ever appends.
let scannedItems = 0
watch(
transcriptItems,
(items) => {
for (const item of items.slice(scannedItems)) {
if (item.kind === 'attachment') {
const { id, media, url } = item.attachment
if (media !== 'image' || url !== null || attemptedAttachments.has(id)) continue
// The cards sit at two depths. One handed over mid-turn lands in the
// open turn's entries and rides into the finished turn with it, so a
// scan of the top-level rows alone would never see it and the card
// would stay a name with no picture. Every path that can hold a card is
// walked here; the attempt set makes a repeated pass free.
function requestAttachmentImages(): void {
const fetchAttachment = (attachment: AttachmentCard) => {
const { id, media, url } = attachment
if (media !== 'image' || url !== null || attemptedAttachments.has(id)) return
attemptedAttachments.add(id)
claw
.attachmentUrl(id)
.then((fetched) => transcript.setAttachmentUrl(id, fetched))
.catch((err) => noteApiError(err))
}
for (const item of transcriptItems.value) {
if (item.kind === 'attachment') {
fetchAttachment(item.attachment)
} else if (item.kind === 'turn') {
for (const entry of item.turn.entries) {
if (entry.kind === 'attachment') fetchAttachment(entry.attachment)
}
} else if (item.kind === 'sent') {
for (const image of item.images) {
const { id, url } = image
if (id === null || url !== null || attemptedAttachments.has(id)) continue
attemptedAttachments.add(id)
claw
.attachmentUrl(id)
.then((fetched) => transcript.setAttachmentUrl(id, fetched))
.then((fetched) => transcript.setSentImageUrl(id, fetched))
.catch((err) => noteApiError(err))
} else if (item.kind === 'sent') {
for (const image of item.images) {
const { id, url } = image
if (id === null || url !== null || attemptedAttachments.has(id)) continue
attemptedAttachments.add(id)
claw
.attachmentUrl(id)
.then((fetched) => transcript.setSentImageUrl(id, fetched))
.catch((err) => noteApiError(err))
}
}
}
scannedItems = items.length
},
{ deep: true },
)
}
for (const entry of transcript.live.value?.entries ?? []) {
if (entry.kind === 'attachment') fetchAttachment(entry.attachment)
}
}
watch([transcriptItems, transcript.live], requestAttachmentImages, {
deep: true,
immediate: true,
})
// --- the agent's identity --------------------------------------------
const identity = ref<AgentIdentity | null>(null)
@@ -652,7 +662,11 @@ async function downloadAttachment(id: string, name: string): Promise<void> {
const anchor = document.createElement('a')
anchor.href = url
anchor.download = name
// A click on a detached anchor is a no-op in some browsers; the
// element joins the document for the length of the click.
document.body.append(anchor)
anchor.click()
anchor.remove()
} catch (err) {
noteApiError(err)
}
@@ -719,7 +733,7 @@ function resubscribe(): void {
transcript.reset()
olderAvailable.value = true
attemptedAttachments.clear()
scannedItems = 0
requestAttachmentImages()
},
onStatus: (status) => {
streamStatus.value = status
@@ -729,7 +743,7 @@ function resubscribe(): void {
// during the outage should retry against the recovered stream.
if (status === 'reconnecting') {
attemptedAttachments.clear()
scannedItems = 0
requestAttachmentImages()
}
if (status === 'open') void refreshSessions()
},
@@ -1,7 +1,9 @@
<script setup lang="ts">
// The agent handing a file over: a head row naming it, the image (when
// there is one) under it, capped so a screenshot cannot take the
// stream; code and file download on click.
// stream. Every card downloads, images included: a picture the browser
// cannot paint, an SVG, or bytes that failed to fetch must still come
// out of the store.
import type { AttachmentCard } from '~/composables/useTranscript'
defineProps<{ attachment: AttachmentCard }>()
@@ -35,7 +37,6 @@ function formatBytes(size: number): string {
<span class="attachment-name mono">{{ attachment.name }}</span>
<span class="attachment-size mono">{{ formatBytes(attachment.size) }}</span>
<button
v-if="attachment.media !== 'image'"
class="ghost"
:title="`download ${attachment.name}`"
@click="emit('download', attachment.id, attachment.name)"
+26 -30
View File
@@ -409,21 +409,29 @@ export function useTranscript() {
if (pending !== -1) pendingSent.splice(pending, 1)
}
/** A consent card resolved: flipped in place, or ignored when no
* card carries the id. The in-flight turn's entries hold the cards a
* running turn asked for; finished turns keep their own copies. */
function resolveConsent(id: string, granted: boolean): void {
if (live.value) {
for (const entry of live.value.entries) {
if (entry.kind === 'consent' && entry.consent.id === id) {
entry.consent.granted = granted
return
}
/** The cards on the mirror, at either depth. A card lands in the open
* turn's entries and rides into the finished turn with it, so a scan
* of the top-level rows alone misses everything a turn handed over.
* The returned objects are the mirror's own, not copies: flipping one
* flips what the panel renders. */
function cards(): TurnEntry[] {
const found: TurnEntry[] = [...(live.value?.entries ?? [])]
for (const item of items.value) {
if (item.kind === 'consent' || item.kind === 'attachment') {
found.push(item)
} else if (item.kind === 'turn') {
found.push(...item.turn.entries)
}
}
for (const item of items.value) {
if (item.kind === 'consent' && item.consent.id === id) {
item.consent.granted = granted
return found
}
/** A consent card resolved: flipped in place, or ignored when no
* card carries the id. */
function resolveConsent(id: string, granted: boolean): void {
for (const card of cards()) {
if (card.kind === 'consent' && card.consent.id === id) {
card.consent.granted = granted
return
}
}
@@ -432,17 +440,9 @@ export function useTranscript() {
/** An attachment's object URL landed; stored on its card. The useClaw
* cache keeps a reconnect's replay from refetching the bytes. */
function setAttachmentUrl(id: string, url: string): void {
if (live.value) {
for (const entry of live.value.entries) {
if (entry.kind === 'attachment' && entry.attachment.id === id) {
entry.attachment.url = url
return
}
}
}
for (const item of items.value) {
if (item.kind === 'attachment' && item.attachment.id === id) {
item.attachment.url = url
for (const card of cards()) {
if (card.kind === 'attachment' && card.attachment.id === id) {
card.attachment.url = url
return
}
}
@@ -466,16 +466,12 @@ export function useTranscript() {
/** Whether a card for this consent id is already on the mirror — a
* replayed request never stacks a second card beside the first. */
function findConsent(id: string): boolean {
if (live.value?.entries.some((e) => e.kind === 'consent' && e.consent.id === id)) return true
return items.value.some((item) => item.kind === 'consent' && item.consent.id === id)
return cards().some((card) => card.kind === 'consent' && card.consent.id === id)
}
/** Whether a card for this attachment id is already on the mirror. */
function findAttachment(id: string): boolean {
if (live.value?.entries.some((e) => e.kind === 'attachment' && e.attachment.id === id)) {
return true
}
return items.value.some((item) => item.kind === 'attachment' && item.attachment.id === id)
return cards().some((card) => card.kind === 'attachment' && card.attachment.id === id)
}
/** Reads one page of older turns (whole turns, oldest first) and