The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 17:15 UTC
fix(web): images in expanded tool rows page through the group's viewed images (#36321)
Julius Marminge committed
Nov 13, 2026 at 12:31 UTC
250d372e51f4768712651e35aa7d5c4f7099db26
7 files changed
+227
-45
apps/web/src/components/chat/ChatMarkdownMedia.tsx
+60
-40
@@ -322,19 +322,61 @@ export function ChatMarkdownVideo(props: {
322
);
323
}
324
325
+type ChatMarkdownAssetResource = Extract<
326
+ AssetResource,
327
+ {
328
+ readonly _tag:
329
+ | "attachment"
330
+ | "workspace-file"
331
+ | "media-file"
332
+ | typeof SOURCE_CONTROL_MEDIA_ASSET
333
+ | "tool-output-image";
334
+ }
335
+>;
336
+
337
+export function assetMediaActionsSource(input: {
338
+ readonly environmentId: EnvironmentId;
339
+ readonly resource: ChatMarkdownAssetResource;
340
+ readonly kind: "image" | "video";
341
+ readonly name: string;
342
+ readonly src: string | null;
343
+ readonly workspaceRoot?: string | undefined;
344
+ readonly originalUrl?: string | undefined;
345
+ readonly downloadable?: boolean | undefined;
346
+}): MediaActionSource {
347
+ const { environmentId, resource } = input;
348
+ const path =
349
+ resource._tag === "media-file"
350
+ ? resource.path
351
+ : resource._tag === "workspace-file" && input.workspaceRoot
352
+ ? `${input.workspaceRoot.replace(/[\\/]+$/, "")}/${resource.path}`
353
+ : undefined;
354
+ const reference = path
355
+ ? mediaFileReference(path, input.workspaceRoot)
356
+ : input.originalUrl
357
+ ? mediaUrlReference(input.originalUrl)
358
+ : undefined;
359
+ const relativePath = reference?.kind === "file" ? reference.relativePath : undefined;
360
+ return {
361
+ kind: input.kind,
362
+ name: input.name,
363
+ src: input.src,
364
+ ...(input.downloadable === false ? {} : { asset: { environmentId, resource } }),
365
+ ...(reference ? { reference } : {}),
366
+ ...(relativePath && (resource._tag === "media-file" || resource._tag === "workspace-file")
367
+ ? {
368
+ onOpenFile: () =>
369
+ useRightPanelStore
370
+ .getState()
371
+ .openFile({ environmentId, threadId: resource.threadId }, relativePath),
372
+ }
373
+ : {}),
374
+ };
375
+}
376
+
377
export const ChatMarkdownAssetImage = memo(function ChatMarkdownAssetImage(props: {
378
readonly environmentId: EnvironmentId;
327
- readonly resource: Extract<
328
- AssetResource,
329
- {
330
- readonly _tag:
331
- | "attachment"
332
- | "workspace-file"
333
- | "media-file"
334
- | typeof SOURCE_CONTROL_MEDIA_ASSET
335
- | "tool-output-image";
336
- }
337
- >;
379
+ readonly resource: ChatMarkdownAssetResource;
380
readonly kind?: "image" | "video";
381
readonly alt: string;
382
readonly copyMarkdown?: string;
@@ -366,18 +408,6 @@ export const ChatMarkdownAssetImage = memo(function ChatMarkdownAssetImage(props
408
: undefined,
409
);
410
const refreshAssetUrl = useAssetUrlRefresh(props.environmentId, resource);
369
- const path =
370
- resource._tag === "media-file"
371
- ? resource.path
372
- : resource._tag === "workspace-file" && props.workspaceRoot
373
- ? `${props.workspaceRoot.replace(/[\\/]+$/, "")}/${resource.path}`
374
- : undefined;
375
- const reference = path
376
- ? mediaFileReference(path, props.workspaceRoot)
377
- : props.originalUrl
378
- ? mediaUrlReference(props.originalUrl)
379
- : undefined;
380
- const relativePath = reference?.kind === "file" ? reference.relativePath : undefined;
411
const fallbackSrc = assetUrl._tag === "Failure" ? props.fallbackSrc : undefined;
412
const src =
413
assetUrl._tag === "Success"
@@ -394,26 +424,16 @@ export const ChatMarkdownAssetImage = memo(function ChatMarkdownAssetImage(props
424
: maxHeightRem !== 30
425
? { maxHeight: `${maxHeightRem}rem` }
426
: undefined);
397
- const actionsSource: MediaActionSource = {
427
+ const actionsSource = assetMediaActionsSource({
428
+ environmentId: props.environmentId,
429
+ resource,
430
kind: props.kind ?? "image",
431
name: props.alt || (props.kind ?? "image"),
432
src,
401
- ...(fallbackSrc === undefined
402
- ? { asset: { environmentId: props.environmentId, resource } }
403
- : {}),
404
- ...(reference ? { reference } : {}),
405
- ...(relativePath && (resource._tag === "media-file" || resource._tag === "workspace-file")
406
- ? {
407
- onOpenFile: () =>
408
- useRightPanelStore
409
- .getState()
410
- .openFile(
411
- { environmentId: props.environmentId, threadId: resource.threadId },
412
- relativePath,
413
- ),
414
- }
415
- : {}),
416
- };
433
+ workspaceRoot: props.workspaceRoot,
434
+ originalUrl: props.originalUrl,
435
+ downloadable: fallbackSrc === undefined,
436
+ });
437
438
if (props.kind === "video") {
439
return (
apps/web/src/components/chat/MessagesTimeline.browser.test.tsx
+45
@@ -86,6 +86,10 @@ vi.mock(import("~/assets/assetUrls"), async (original) => {
86
stubbedAsset.url
87
? { _tag: "Success", url: stubbedAsset.url }
88
: actual.useAssetUrlState(...args)) as typeof actual.useAssetUrlState,
89
+ useAssetUrls: ((...args: Parameters<typeof actual.useAssetUrls>) =>
90
+ stubbedAsset.url
91
+ ? args[1].map(() => stubbedAsset.url)
92
+ : actual.useAssetUrls(...args)) as typeof actual.useAssetUrls,
93
};
94
});
95
@@ -1711,6 +1715,47 @@ describe("MessagesTimeline attachments", () => {
1715
}),
1716
);
1717
});
1718
+
1719
+ it("opens an image from an expanded tool row as a gallery of the turn's viewed images", async () => {
1720
+ stubbedAsset.url =
1721
+ "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=";
1722
+ onTestFinished(() => {
1723
+ stubbedAsset.url = "";
1724
+ });
1725
+ const onImageExpand = vi.fn<ComponentProps<typeof MessagesTimeline>["onImageExpand"]>();
1726
+ const read = (name: string) =>
1727
+ work(`read-${name}`, {
1728
+ label: `Read ${name}`,
1729
+ toolTitle: "Read",
1730
+ tone: "tool",
1731
+ itemType: "dynamic_tool",
1732
+ toolLifecycleStatus: "completed",
1733
+ viewedImagePath: `/repo/${name}`,
1734
+ });
1735
+ await using screen = await renderTimeline(
1736
+ [read("first.png"), read("second.png"), read("third.png")],
1737
+ { onImageExpand, workspaceRoot: "/repo" },
1738
+ );
1739
+ await click(screen.button(/^Read 3 files/));
1740
+ await vi.waitFor(() => expect(screen.buttons("Read")).toHaveLength(3));
1741
+ await click(screen.buttons("Read")[1]!);
1742
+ const inRow = await vi.waitFor(() => {
1743
+ const image = [...screen.container.querySelectorAll("img")].find(
1744
+ (img) => img.alt === "second.png" && !img.closest("[data-image-gallery]"),
1745
+ );
1746
+ expect(image).toBeTruthy();
1747
+ return image!;
1748
+ });
1749
+ await click(inRow.closest<HTMLElement>("button, [role=button]")!);
1750
+ expect(onImageExpand).toHaveBeenCalledExactlyOnceWith(
1751
+ expect.objectContaining({
1752
+ index: 1,
1753
+ images: ["first.png", "second.png", "third.png"].map((name) =>
1754
+ expect.objectContaining({ name }),
1755
+ ),
1756
+ }),
1757
+ );
1758
+ });
1759
});
1760
1761
describe("MessagesTimeline thread find", () => {
apps/web/src/components/chat/TimelineWorkEntryRow.tsx
+12
-3
@@ -32,6 +32,8 @@ import {
32
} from "../../session-logic";
33
import ChatMarkdown from "../ChatMarkdown";
34
import { ChatMarkdownAssetImage } from "./ChatMarkdownMedia";
35
+import type { ExpandedImagePreview } from "./ExpandedImagePreview";
36
+import { workGroupImageGallery } from "./markdownImageGallery";
37
import { ChevronRightIcon, CircleAlertIcon, XIcon, RotateCcwIcon } from "lucide-react";
38
import { Button, InlineButton } from "../ui/button";
39
import { useAssetUrls } from "../../assets/assetUrls";
@@ -355,6 +357,13 @@ function WorkEntryLogRow(props: WorkEntryRowProps) {
357
workspaceRoot,
358
})
359
: null;
360
+ const groupViewedImages = groupView?.viewedImages;
361
+ // Images in this entry's expanded body page through the group's viewed images, like its strip.
362
+ const expandImage =
363
+ viewedImage && groupViewedImages
364
+ ? (preview: ExpandedImagePreview) =>
365
+ onImageExpand(workGroupImageGallery(groupViewedImages, viewedImagePath, preview))
366
+ : onImageExpand;
367
const canExpand =
368
previewText.trim().length > 0 ||
369
(workEntry.itemType === "dynamic_tool" && workEntry.toolData !== undefined) ||
@@ -558,7 +567,7 @@ function WorkEntryLogRow(props: WorkEntryRowProps) {
567
srcFragment={viewedImage.srcFragment}
568
workspaceRoot={workspaceRoot}
569
maxHeightRem={16}
561
- onImageExpand={onImageExpand}
570
+ onImageExpand={expandImage}
571
/>
572
</WorkLogDetails>
573
) : null}
@@ -582,7 +591,7 @@ function WorkEntryLogRow(props: WorkEntryRowProps) {
591
cwd={ctx.markdownCwd}
592
workspaceRoot={workspaceRoot}
593
onOpenToolDiff={ctx.onOpenToolDiff}
585
- onImageExpand={ctx.onImageExpand}
594
+ onImageExpand={expandImage}
595
source={ctx.turnItemSource}
596
/>
597
) : (
@@ -595,7 +604,7 @@ function WorkEntryLogRow(props: WorkEntryRowProps) {
604
onInitialOutputReady={onInitialOutputReady}
605
projectedItem={workEntry.projectedItem}
606
environmentId={ctx.activeThreadEnvironmentId}
598
- onImageExpand={onImageExpand}
607
+ onImageExpand={expandImage}
608
source={ctx.turnItemSource}
609
/>
610
) : null}
apps/web/src/components/chat/TimelineWorkGroupRows.tsx
+56
-1
@@ -2,8 +2,13 @@ import { TimelinePendingApprovalRow } from "./TimelinePendingApprovalRow";
2
import { WorkLogButton, WorkLogList, WorkLogRow } from "./WorkLog";
3
import type { WorktreeSetupSnapshot } from "@t3tools/contracts";
4
import { type ToolActivityIcon } from "@t3tools/contracts";
5
-import { liveThoughtLine } from "@t3tools/client-runtime/work-log/presentation";
5
+import {
6
+ liveThoughtLine,
7
+ resolveViewedImageAsset,
8
+ workEntriesViewedImagePaths,
9
+} from "@t3tools/client-runtime/work-log/presentation";
10
import { resolveWorkGroupScrollAnchor } from "@t3tools/client-runtime/work-log/scroll-anchor";
11
+import { useAssetUrls } from "~/assets/assetUrls";
12
import { observeResize } from "~/lib/observeResize";
13
import { tickTextContent } from "~/lib/tickTextContent";
14
import { observeVisibleAnimation } from "../../lib/visibleAnimation";
@@ -11,6 +16,7 @@ import { memo, use, useLayoutEffect, useRef, useState, type ReactNode } from "re
16
import { LegendList, type LegendListRef } from "@legendapp/list/react";
17
import { workEntryDisplayIndicatesToolFailure } from "../../session-logic";
18
import ChatMarkdown from "../ChatMarkdown";
19
+import { assetMediaActionsSource } from "./ChatMarkdownMedia";
20
import { Minimize2Icon, XIcon } from "lucide-react";
21
import { Button } from "../ui/button";
22
import { getVirtualizedScrollFadeClassName } from "../ui/scroll-area";
@@ -30,6 +36,7 @@ import {
36
TimelineRowCtx,
37
TimelineRowActivityCtx,
38
WorkGroupViewCtx,
39
+ type WorkGroupViewedImage,
40
type TimelineWorkEntry,
41
type TimelineRow,
42
} from "./timelineRowContext";
@@ -95,6 +102,7 @@ export const WorkGroupSection = memo(function WorkGroupSection({
102
anchorKey={anchorKey}
103
disclosureAnchorKey={disclosureAnchorKey}
104
entries={nonEmptyEntries}
105
+ groupedEntries={groupedEntries}
106
workspaceRoot={workspaceRoot}
107
/>
108
);
@@ -129,15 +137,60 @@ function WorkingTimer({ createdAt }: { createdAt: string }) {
137
138
const compactWorkEntryHeight = 24;
139
140
+// The thumbnail strip below the group is its own virtualized row, so the gallery an expanded
141
+// entry opens is built from the same entries rather than from the strip's mounted images.
142
+function useWorkGroupViewedImages(
143
+ groupedEntries: ReadonlyArray<TimelineWorkEntry>,
144
+): ReadonlyArray<WorkGroupViewedImage> {
145
+ const { threadRef, workspaceRoot, activeThreadEnvironmentId } = use(TimelineRowCtx);
146
+ const viewed = threadRef
147
+ ? workEntriesViewedImagePaths(groupedEntries).flatMap((path) => {
148
+ const asset = resolveViewedImageAsset(path, {
149
+ threadId: threadRef.threadId,
150
+ workspaceRoot,
151
+ });
152
+ return asset ? [{ path, asset }] : [];
153
+ })
154
+ : [];
155
+ const environmentId = threadRef?.environmentId ?? activeThreadEnvironmentId;
156
+ const urls = useAssetUrls(
157
+ environmentId,
158
+ viewed.map(({ asset }) => asset.resource),
159
+ );
160
+ return viewed.map(({ path, asset }, index) => {
161
+ const url = urls[index];
162
+ if (!url) return { path, item: null };
163
+ const src = url + asset.srcFragment;
164
+ const name = asset.alt.trim() || "image";
165
+ return {
166
+ path,
167
+ item: {
168
+ src,
169
+ name,
170
+ actionsSource: assetMediaActionsSource({
171
+ environmentId,
172
+ resource: asset.resource,
173
+ kind: "image",
174
+ name: asset.alt || "image",
175
+ src,
176
+ workspaceRoot,
177
+ }),
178
+ },
179
+ };
180
+ });
181
+}
182
+
183
function ExpandedWorkGroupEntries({
184
anchorKey,
185
disclosureAnchorKey,
186
entries,
187
+ groupedEntries,
188
workspaceRoot,
189
}: {
190
anchorKey: string;
191
disclosureAnchorKey: string;
192
entries: TimelineWorkEntry[];
193
+ groupedEntries: ReadonlyArray<TimelineWorkEntry>;
194
workspaceRoot: string | undefined;
195
}) {
196
const {
@@ -164,8 +217,10 @@ function ExpandedWorkGroupEntries({
217
});
218
}
219
220
+ const viewedImages = useWorkGroupViewedImages(groupedEntries);
221
const groupView = {
222
state: viewState,
223
+ viewedImages,
224
onToggleEntry: (collapsed: boolean, entryId: string) =>
225
onToggleWorkEntry(disclosureAnchorKey, collapsed, entryId),
226
onContentReady: (entryId: string) => onWorkEntryContentReady?.(disclosureAnchorKey, entryId),
apps/web/src/components/chat/markdownImageGallery.test.ts
new
+22
@@ -0,0 +1,22 @@
1
+import { describe, expect, it } from "vite-plus/test";
2
+
3
+import { workGroupImageGallery } from "./markdownImageGallery";
4
+
5
+const item = (name: string) => ({ src: `https://assets.test/${name}`, name });
6
+
7
+describe("workGroupImageGallery", () => {
8
+ it("pages the clicked image through the group's resolved images", () => {
9
+ const clicked = { ...item("second.png"), src: "https://assets.test/second.png#fresh" };
10
+ const viewed = [
11
+ { path: "/repo/first.png", item: item("first.png") },
12
+ { path: "/repo/pending.png", item: null },
13
+ { path: "/repo/second.png", item: item("second.png") },
14
+ { path: "/repo/third.png", item: item("third.png") },
15
+ ];
16
+ expect(
17
+ workGroupImageGallery(viewed, "/repo/second.png", { images: [clicked], index: 0 }),
18
+ ).toEqual({ images: [item("first.png"), clicked, item("third.png")], index: 1 });
19
+ const single = { images: [clicked], index: 0 };
20
+ expect(workGroupImageGallery(viewed, "/repo/other.png", single)).toBe(single);
21
+ });
22
+});
apps/web/src/components/chat/markdownImageGallery.ts
+24
@@ -47,3 +47,27 @@ export function markdownImageGallery(
47
}
48
return index < 0 ? { images: [selected], index: 0 } : { images, index };
49
}
50
+
51
+/**
52
+ * Widens the single-image preview of an image in an expanded tool row to the images its group
53
+ * viewed. Built from the group's entries: its thumbnail strip can be virtualized out of the DOM.
54
+ */
55
+export function workGroupImageGallery(
56
+ viewedImages: ReadonlyArray<{ readonly path: string; readonly item: ExpandedImageItem | null }>,
57
+ clickedPath: string | null,
58
+ preview: ExpandedImagePreview,
59
+): ExpandedImagePreview {
60
+ const selected = preview.images[preview.index];
61
+ if (preview.images.length !== 1 || !selected) return preview;
62
+ const images: ExpandedImageItem[] = [];
63
+ let index = -1;
64
+ for (const viewed of viewedImages) {
65
+ if (viewed.path === clickedPath) {
66
+ index = images.length;
67
+ images.push(selected);
68
+ } else if (viewed.item) {
69
+ images.push(viewed.item);
70
+ }
71
+ }
72
+ return index < 0 ? preview : { images, index };
73
+}
apps/web/src/components/chat/timelineRowContext.ts
+8
-1
@@ -24,7 +24,7 @@ import { type LegendListRef } from "@legendapp/list/react";
24
import type { CodexArtifactTemplate } from "@t3tools/shared/codexArtifactTemplates";
25
import type { PendingApproval } from "../../session-logic";
26
import { type ChatFileAttachment } from "../../types";
27
-import { ExpandedImagePreview } from "./ExpandedImagePreview";
27
+import { type ExpandedImageItem, ExpandedImagePreview } from "./ExpandedImagePreview";
28
import { type AssistantCitationTarget } from "./AssistantCitationSource";
29
import { type MessagesTimelineRow, type WorkGroupScrollAnchor } from "./MessagesTimeline.logic";
30
import { type TimestampFormat } from "@t3tools/contracts/settings";
@@ -127,8 +127,15 @@ export interface WorkGroupViewState {
127
expandedEntries: Set<string>;
128
}
129
130
+/** One image the group's agent viewed; `item` is null until its URL resolves. */
131
+export interface WorkGroupViewedImage {
132
+ readonly path: string;
133
+ readonly item: ExpandedImageItem | null;
134
+}
135
+
136
export const WorkGroupViewCtx = createContext<{
137
state: WorkGroupViewState;
138
+ viewedImages: ReadonlyArray<WorkGroupViewedImage>;
139
onToggleEntry: (collapsed: boolean, entryId: string) => void;
140
onContentReady?: ((entryId: string) => void) | undefined;
141
} | null>(null);