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
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:
1 parent
1a1ace014a
commit
04b06e7623
4 files changed
+83
-67
No files matched your search
+44
-30
@@ -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()
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user