Commit 2d4f84836 for llama.cpp
commit 2d4f84836c8c1d1722496b9eb3d5d99dd1ed1ba5
Author: Aleksander Grygier <aleksander.grygier@gmail.com>
Date: Thu Dec 3 19:37:51 2026 +0100
ui: one slideshow for every image of the conversation, in its order (#33622)
* ui: open the slideshow at the trace image that was clicked
The thread is walked from its leaf to its root and then sorted by
timestamp. Messages saved in the same millisecond, as the results of
parallel tool calls can be, kept the walk's leaf-first order through the
stable sort, so the slideshow listed a trace's images backwards and opened
each at its mirror. The path is put root first before the sort.
Assisted-by: Claude (Opus 5.5 Medium)
* ui: one slideshow for every image of the conversation, in its order
The attachment lists and the slideshow showed their items newest first,
while the image clicked was found in the thread's own order: each click
opened its mirror. Nothing is reversed now: attachment lists keep the
order the files were added in and the slideshow the thread's order, so
the image clicked is the one that opens.
The images a tool call shows once opened (read media, a tool's output, a
shell command's) and an attachment's image in Markdown open the same
slideshow at themselves.
Assisted-by: Claude (Opus 5.5 Medium)
diff --git a/ui/apps/chat/src/lib/components/app/chat/ChatAttachments/ChatAttachmentsGalleryImage.svelte b/ui/apps/chat/src/lib/components/app/chat/ChatAttachments/ChatAttachmentsGalleryImage.svelte
new file mode 100644
index 000000000..3ca386802
--- /dev/null
+++ b/ui/apps/chat/src/lib/components/app/chat/ChatAttachments/ChatAttachmentsGalleryImage.svelte
@@ -0,0 +1,31 @@
+<!--
+ An image of the thread shown in place, a tool's output for one: a click opens the conversation's
+ slideshow at it.
+-->
+<script lang="ts">
+ import { IMAGE_PREVIEW_LABEL } from '#lib/constants/index.ts';
+ import { mediaGalleryStore } from '#lib/stores/index.ts';
+ import type { DatabaseMessageExtraImageFile } from '#lib/types/database.js';
+ import type { ClassValue } from 'svelte/elements';
+
+ interface Props {
+ /** The button's classes. */
+ class?: ClassValue;
+ image: DatabaseMessageExtraImageFile;
+ imageClass?: ClassValue;
+ /** What the image is called, its file name unless given. */
+ name?: string;
+ }
+
+ let { class: className, image, imageClass, name }: Props = $props();
+</script>
+
+<button
+ aria-label={IMAGE_PREVIEW_LABEL(name ?? image.name)}
+ class={['block max-w-full cursor-zoom-in', className]}
+ onclick={() => mediaGalleryStore.show(image)}
+ type="button"
+>
+ <!-- the button carries the name -->
+ <img alt="" class={imageClass} loading="lazy" src={image.base64Url} />
+</button>
diff --git a/ui/apps/chat/src/lib/components/app/chat/ChatMessages/ChatMessage/ChatMessageToolCall/ChatMessageToolCallBlockDefault.svelte b/ui/apps/chat/src/lib/components/app/chat/ChatMessages/ChatMessage/ChatMessageToolCall/ChatMessageToolCallBlockDefault.svelte
index 9485dc8f1..984c26737 100644
--- a/ui/apps/chat/src/lib/components/app/chat/ChatMessages/ChatMessage/ChatMessageToolCall/ChatMessageToolCallBlockDefault.svelte
+++ b/ui/apps/chat/src/lib/components/app/chat/ChatMessages/ChatMessage/ChatMessageToolCall/ChatMessageToolCallBlockDefault.svelte
@@ -7,7 +7,11 @@
import ToolCallTitle from './ToolCallTitle.svelte';
import { simpleToolArgFields } from '@ggml-org/llama-harness';
import { Loader2 } from '@lucide/svelte';
- import { MarkdownContent, SyntaxHighlightedCode } from '#lib/components/app/index.ts';
+ import {
+ ChatAttachmentsGalleryImage,
+ MarkdownContent,
+ SyntaxHighlightedCode
+ } from '#lib/components/app/index.ts';
import { MAX_HEIGHT_CODE_BLOCK } from '#lib/constants/index.ts';
import { AttachmentType, FileTypeText, MimeTypeAudio, ToolResultKind } from '#lib/enums/index.ts';
import type { AgenticSection, DatabaseMessageExtra, ToolResultLine } from '#lib/types/index.ts';
@@ -145,11 +149,9 @@
</audio>
</div>
{:else}
- <img
- alt={line.media.name}
- class="mt-2 mb-2 h-auto max-w-full rounded-lg"
- loading="lazy"
- src={line.media.base64Url}
+ <ChatAttachmentsGalleryImage
+ image={line.media}
+ imageClass="mt-2 mb-2 h-auto max-w-full rounded-lg"
/>
{/if}
{/if}
diff --git a/ui/apps/chat/src/lib/components/app/chat/ChatMessages/ChatMessage/ChatMessageToolCall/ChatMessageToolCallBlockExecShellCommand.svelte b/ui/apps/chat/src/lib/components/app/chat/ChatMessages/ChatMessage/ChatMessageToolCall/ChatMessageToolCallBlockExecShellCommand.svelte
index 2a5096d77..d7a49a03c 100644
--- a/ui/apps/chat/src/lib/components/app/chat/ChatMessages/ChatMessage/ChatMessageToolCall/ChatMessageToolCallBlockExecShellCommand.svelte
+++ b/ui/apps/chat/src/lib/components/app/chat/ChatMessages/ChatMessage/ChatMessageToolCall/ChatMessageToolCallBlockExecShellCommand.svelte
@@ -18,7 +18,7 @@
SquareArrowDown,
XCircle
} from '@lucide/svelte';
- import { ShellPromptLine } from '#lib/components/app/index.ts';
+ import { ChatAttachmentsGalleryImage, ShellPromptLine } from '#lib/components/app/index.ts';
import {
BACKGROUND_TASK_DETACH_LABEL,
BACKGROUND_TASK_DETACH_TITLE,
@@ -314,11 +314,9 @@
</div>
{#if line.media?.type === AttachmentType.IMAGE}
- <img
- alt={line.media.name}
- class="mt-2 mb-2 h-auto max-w-full rounded-lg"
- loading="lazy"
- src={line.media.base64Url}
+ <ChatAttachmentsGalleryImage
+ image={line.media}
+ imageClass="mt-2 mb-2 h-auto max-w-full rounded-lg"
/>
{/if}
{/each}
diff --git a/ui/apps/chat/src/lib/components/app/chat/ChatMessages/ChatMessage/ChatMessageToolCall/ChatMessageToolCallBlockReadMedia.svelte b/ui/apps/chat/src/lib/components/app/chat/ChatMessages/ChatMessage/ChatMessageToolCall/ChatMessageToolCallBlockReadMedia.svelte
index 1091b8dcb..82b473d22 100644
--- a/ui/apps/chat/src/lib/components/app/chat/ChatMessages/ChatMessage/ChatMessageToolCall/ChatMessageToolCallBlockReadMedia.svelte
+++ b/ui/apps/chat/src/lib/components/app/chat/ChatMessages/ChatMessage/ChatMessageToolCall/ChatMessageToolCallBlockReadMedia.svelte
@@ -2,6 +2,7 @@
import { parseReadMediaMeta } from './parsers/read-media';
import ToolCallBlock from './ToolCallBlock.svelte';
import ToolCallTitle from './ToolCallTitle.svelte';
+ import { ChatAttachmentsGalleryImage } from '#lib/components/app/index.ts';
import { ATTACHMENT_SAVED_REGEX } from '#lib/constants/agentic.constants.ts';
import { AttachmentType, MimeTypeAudio } from '#lib/enums/index.ts';
import type {
@@ -70,11 +71,10 @@
</div>
{:else}
<div class="mt-2">
- <img
- alt={readMediaMeta?.fileName ?? 'media'}
- class="max-h-[60vh] max-w-full rounded-lg object-contain shadow-(--elevation-raised)"
- loading="lazy"
- src={mediaAttachment.base64Url}
+ <ChatAttachmentsGalleryImage
+ image={mediaAttachment}
+ imageClass="max-h-[60vh] max-w-full rounded-lg object-contain shadow-(--elevation-raised)"
+ name={readMediaMeta?.fileName}
/>
</div>
{/if}
diff --git a/ui/apps/chat/src/lib/components/app/chat/ChatMessages/ChatMessage/ChatMessageToolCall/ChatMessageToolCallGroup.svelte b/ui/apps/chat/src/lib/components/app/chat/ChatMessages/ChatMessage/ChatMessageToolCall/ChatMessageToolCallGroup.svelte
index ebc3460cd..a82d5fec0 100644
--- a/ui/apps/chat/src/lib/components/app/chat/ChatMessages/ChatMessage/ChatMessageToolCall/ChatMessageToolCallGroup.svelte
+++ b/ui/apps/chat/src/lib/components/app/chat/ChatMessages/ChatMessage/ChatMessageToolCall/ChatMessageToolCallGroup.svelte
@@ -6,10 +6,13 @@
import { describeToolActivity, summarizeToolCalls } from './parsers/tool-call-phrasing';
import ToolCallElapsed from './ToolCallElapsed.svelte';
- import { CollapsibleContentBlock } from '#lib/components/app/index.ts';
- import { ScrollCarousel } from '#lib/components/app/index.ts';
+ import {
+ ChatAttachmentsGalleryImage,
+ CollapsibleContentBlock,
+ ScrollCarousel
+ } from '#lib/components/app/index.ts';
import { ScrollCarouselVariant } from '#lib/enums/index.ts';
- import { mediaGalleryStore, settingsStore } from '#lib/stores/index.ts';
+ import { settingsStore } from '#lib/stores/index.ts';
import type { AgenticSection } from '#lib/types/index.ts';
import { imageExtras, toolCallShownArg } from '#lib/utils/index.ts';
import type { Snippet } from 'svelte';
@@ -86,19 +89,11 @@
<div transition:fade={{ duration: 150 }} class="tool-call-media">
<ScrollCarousel gapSize="2" variant={ScrollCarouselVariant.CENTER}>
{#each images as image, i (i)}
- <button
- aria-label={image.name ? `Preview ${image.name}` : 'Preview image'}
+ <ChatAttachmentsGalleryImage
class="h-16 shrink-0 overflow-hidden rounded-md border border-border/60 transition-opacity hover:opacity-80"
- onclick={() => mediaGalleryStore.show(image)}
- type="button"
- >
- <img
- alt=""
- class="h-full w-auto max-w-60 object-cover"
- loading="lazy"
- src={image.base64Url}
- />
- </button>
+ {image}
+ imageClass="h-full w-auto max-w-60 object-cover"
+ />
{/each}
</ScrollCarousel>
</div>
diff --git a/ui/apps/chat/src/lib/components/app/chat/index.ts b/ui/apps/chat/src/lib/components/app/chat/index.ts
index 2276eff89..fa4ad1800 100644
--- a/ui/apps/chat/src/lib/components/app/chat/index.ts
+++ b/ui/apps/chat/src/lib/components/app/chat/index.ts
@@ -94,6 +94,9 @@ export { default as ChatAttachmentsListItemVoice } from './ChatAttachments/ChatA
*/
export { default as ChatAttachmentsListItemThumbnailImage } from './ChatAttachments/ChatAttachmentsList/ChatAttachmentsListItem/ChatAttachmentsListItemThumbnailImage.svelte';
+/** An image of the thread shown in place; a click opens the conversation's slideshow at it. */
+export { default as ChatAttachmentsGalleryImage } from './ChatAttachments/ChatAttachmentsGalleryImage.svelte';
+
/**
* Unified attachment preview component for dialog display. Shows a single file
* preview without carousel, or a gallery/carousel view when multiple items exist.
diff --git a/ui/apps/chat/src/lib/components/app/content/MarkdownContent/MarkdownContent.svelte b/ui/apps/chat/src/lib/components/app/content/MarkdownContent/MarkdownContent.svelte
index 0edd8cbcd..113dd2be3 100644
--- a/ui/apps/chat/src/lib/components/app/content/MarkdownContent/MarkdownContent.svelte
+++ b/ui/apps/chat/src/lib/components/app/content/MarkdownContent/MarkdownContent.svelte
@@ -30,9 +30,9 @@
SETTINGS_KEYS,
SVG
} from '#lib/constants/index.ts';
- import { BooleanString, ColorMode, UrlProtocol } from '#lib/enums/index.ts';
+ import { AttachmentType, BooleanString, ColorMode, UrlProtocol } from '#lib/enums/index.ts';
import { createStickToBottom } from '#lib/hooks/use-stick-to-bottom.svelte.ts';
- import { settingsStore } from '#lib/stores/index.ts';
+ import { mediaGalleryStore, settingsStore } from '#lib/stores/index.ts';
import type { DatabaseMessageExtra } from '#lib/types/database.js';
import {
copyCodeToClipboard,
@@ -456,8 +456,23 @@
* Also handles copy and preview button clicks for mermaid blocks.
* Uses event delegation: a single handler on the container.
*/
- async function handleMermaidClick(event: MouseEvent) {
+ async function handleContentClick(event: MouseEvent) {
const target = event.target as HTMLElement;
+ // an attachment's image opens the conversation's slideshow at it
+ const image = target.closest('img');
+ const attachment =
+ image &&
+ attachments?.find(
+ (extra) =>
+ extra.type === AttachmentType.IMAGE && extra.base64Url === image.getAttribute('src')
+ );
+
+ if (attachment) {
+ event.preventDefault();
+ mediaGalleryStore.show(attachment);
+
+ return;
+ }
if (toggleDiagramSource(target)) {
event.preventDefault();
@@ -648,7 +663,7 @@
class="{className}{settingsStore.config[SETTINGS_KEYS.FULL_HEIGHT_CODE_BLOCKS]
? ' full-height-code-blocks'
: ''}"
- onclick={handleMermaidClick}
+ onclick={handleContentClick}
>
{#each renderedBlocks as block (block.id)}
<div class="markdown-block" {...{ [MARKDOWN_DATA_ATTRS.BLOCK_ID]: block.id }}>
diff --git a/ui/apps/chat/src/lib/constants/image.constants.ts b/ui/apps/chat/src/lib/constants/image.constants.ts
index 53a90eaa4..bffed37de 100644
--- a/ui/apps/chat/src/lib/constants/image.constants.ts
+++ b/ui/apps/chat/src/lib/constants/image.constants.ts
@@ -7,6 +7,10 @@ export const IMAGE = {
MEGAPIXELS_TO_PIXELS: 1_000_000
} as const;
+/** What a screen reader calls an image that opens the slideshow at itself. */
+export const IMAGE_PREVIEW_LABEL = (name?: string): string =>
+ name ? `Preview ${name}` : 'Preview image';
+
/**
* JPEG and EXIF binary format constants for orientation parsing.
*/
diff --git a/ui/apps/chat/src/lib/utils/attachment-display.ts b/ui/apps/chat/src/lib/utils/attachment-display.ts
index 0bbfa4c03..16fdf6730 100644
--- a/ui/apps/chat/src/lib/utils/attachment-display.ts
+++ b/ui/apps/chat/src/lib/utils/attachment-display.ts
@@ -48,7 +48,7 @@ function getUploadedFileCategory(file: ChatUploadedFile): FileTypeCategory | nul
/**
* Creates a unified list of display items from uploaded files and stored attachments.
- * Items are returned in reverse order (newest first).
+ * Items keep the order they were added in.
*/
export function getAttachmentDisplayItems(
options: AttachmentDisplayItemsOptions
@@ -96,5 +96,5 @@ export function getAttachmentDisplayItems(
});
}
- return items.reverse();
+ return items;
}
diff --git a/ui/apps/chat/src/lib/utils/branching.ts b/ui/apps/chat/src/lib/utils/branching.ts
index b74b0a5c0..7ed05c070 100644
--- a/ui/apps/chat/src/lib/utils/branching.ts
+++ b/ui/apps/chat/src/lib/utils/branching.ts
@@ -83,6 +83,10 @@ export function filterByLeafNodeId(
currentNode = nodeMap.get(currentNode.parent);
}
+ // root first, so messages of the same timestamp (results of parallel tool calls) keep their
+ // order through the stable sort below
+ result.reverse();
+
// Sort: system messages first, then by timestamp
result.sort((a, b) => {
if (a.role === MessageRole.SYSTEM && b.role !== MessageRole.SYSTEM) return -1;
diff --git a/ui/apps/chat/tests/unit/attachment-display.test.ts b/ui/apps/chat/tests/unit/attachment-display.test.ts
new file mode 100644
index 000000000..f4f31e2fc
--- /dev/null
+++ b/ui/apps/chat/tests/unit/attachment-display.test.ts
@@ -0,0 +1,23 @@
+// The order getAttachmentDisplayItems returns: the order the attachments were added in, as the
+// attachment lists show them.
+
+import { AttachmentType } from '#lib/enums/index.ts';
+import type { DatabaseMessageExtra } from '#lib/types/database.js';
+import { getAttachmentDisplayItems } from '#lib/utils/attachment-display.ts';
+import { describe, expect, it } from 'vitest';
+
+const attachments = ['first.png', 'second.png'].map(
+ (name): DatabaseMessageExtra => ({
+ base64Url: `data:image/png;base64,${name}`,
+ name,
+ type: AttachmentType.IMAGE
+ })
+);
+
+describe('getAttachmentDisplayItems', () => {
+ it('keeps the order they were added in', () => {
+ const names = getAttachmentDisplayItems({ attachments }).map((item) => item.name);
+
+ expect(names).toEqual(['first.png', 'second.png']);
+ });
+});
diff --git a/ui/apps/chat/tests/unit/branching.test.ts b/ui/apps/chat/tests/unit/branching.test.ts
index 0832998ea..fa80ac653 100644
--- a/ui/apps/chat/tests/unit/branching.test.ts
+++ b/ui/apps/chat/tests/unit/branching.test.ts
@@ -4,7 +4,7 @@
import { MessageRole, MessageType } from '#lib/enums/index.ts';
import type { DatabaseMessage } from '#lib/types/database.js';
-import { buildSiblingInfoMap, findLeafNode } from '#lib/utils/branching.ts';
+import { buildSiblingInfoMap, filterByLeafNodeId, findLeafNode } from '#lib/utils/branching.ts';
import { describe, expect, it } from 'vitest';
function msg(id: string, parent: string | null, children: string[] = []): DatabaseMessage {
@@ -93,3 +93,12 @@ describe('buildSiblingInfoMap', () => {
}
});
});
+
+describe('filterByLeafNodeId', () => {
+ it('keeps the path order for messages of the same timestamp', () => {
+ // every message of the chain has timestamp 0, as parallel tool results can
+ const ids = filterByLeafNodeId(linearChain(3), 'm3').map((message) => message.id);
+
+ expect(ids).toEqual(['m0', 'm1', 'm2', 'm3']);
+ });
+});