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 22, 12:00 UTC
feat(web): pasted text, voice notes, snapshots and sending files get their own shapes (#27377)
maria committed
Oct 30, 2026 at 16:39 UTC
e57ae5a0bf38a4a38018df57d250fce323702401
7 files changed
+189
-39
apps/web/src/components/ContextChip.tsx
+7
-2
@@ -35,6 +35,10 @@ const contextChipVariants = cva(
35
"doc-slides": "[--context-chip-accent:var(--context-chip-doc-slides)]",
36
"doc-epub": "[--context-chip-accent:var(--context-chip-doc-epub)]",
37
},
38
+ shape: {
39
+ inline: "",
40
+ bubble: "w-64 gap-2 rounded-2xl bg-message px-3 py-2 text-sm text-message-foreground",
41
+ },
42
state: {
43
unresolved: "data-[state=unresolved]:[--context-chip-accent:currentColor]",
44
invalid:
@@ -49,11 +53,12 @@ type ContextChipKind = NonNullable<VariantProps<typeof contextChipVariants>["kin
53
interface ContextChipProps extends useRender.ComponentProps<"span"> {
54
kind?: ContextChipKind;
55
state?: "unresolved" | "invalid";
56
+ shape?: "inline" | "bubble";
57
}
58
54
-function ContextChip({ className, kind, state, render, ...props }: ContextChipProps) {
59
+function ContextChip({ className, kind, state, shape, render, ...props }: ContextChipProps) {
60
const defaultProps = {
56
- className: cn(contextChipVariants({ kind, state }), className),
61
+ className: cn(contextChipVariants({ kind, state, shape }), className),
62
"data-slot": "context-chip",
63
"data-state": state,
64
};
apps/web/src/components/chat/MessagesTimeline.browser.test.tsx
+75
@@ -3,6 +3,7 @@ import { onTestFinished } from "vite-plus/test";
3
import { page } from "vite-plus/test/browser";
4
import { stubGlobal } from "../../../test/render";
5
import {
6
+ ComposerContextId,
7
EnvironmentId,
8
MessageId,
9
RunAttemptId,
@@ -32,6 +33,11 @@ import { toastManager } from "../ui/toast";
33
import type { CitedHistory } from "./citationProcedure";
34
import type { TimelineNavigation } from "./timelineViewport";
35
import { rememberTimelinePosition } from "./timelineScrollAnchoring";
36
+import {
37
+ COMPOSER_CONTEXT_CLIPBOARD_MIME,
38
+ decodeComposerContextFragment,
39
+} from "@t3tools/shared/composerContextClipboard";
40
+import { collectComposerContextReferences } from "@t3tools/shared/composerContextReferences";
41
42
const environmentQuery = vi.hoisted(() => ({
43
error: "Pull request not found",
@@ -642,6 +648,75 @@ describe("MessagesTimeline agent messages", () => {
648
});
649
650
describe("MessagesTimeline attachments", () => {
651
+ it.each(["image", "file"] as const)(
652
+ "copies only matching context records for a wordless %s attachment",
653
+ async (kind) => {
654
+ const attachment = {
655
+ type: kind,
656
+ id: "media",
657
+ name: kind === "image" ? "photo.png" : "clip.mp4",
658
+ mimeType: kind === "image" ? "image/png" : "video/mp4",
659
+ sizeBytes: 100,
660
+ downloadable: false,
661
+ };
662
+ const record = {
663
+ version: 1 as const,
664
+ ...(kind === "image" ? { kind: "image" as const } : { kind: "file" as const }),
665
+ contextId: ComposerContextId.make("media-context"),
666
+ label: attachment.name,
667
+ attachmentId: attachment.id,
668
+ name: attachment.name,
669
+ mimeType: attachment.mimeType,
670
+ sizeBytes: attachment.sizeBytes,
671
+ };
672
+ await using screen = await renderTimeline([message("", { attachments: [attachment] })]);
673
+ expect(screen.buttons("Copy message")).toHaveLength(0);
674
+ await screen.rerender(
675
+ <MessagesTimeline
676
+ {...baseProps()}
677
+ timelineEntries={[
678
+ message("", {
679
+ attachments: [attachment],
680
+ context: { version: 1, records: [{ ...record, attachmentId: "other" }] },
681
+ }),
682
+ ]}
683
+ />,
684
+ );
685
+ expect(screen.buttons("Copy message")).toHaveLength(0);
686
+ await screen.rerender(
687
+ <MessagesTimeline
688
+ {...baseProps()}
689
+ timelineEntries={[
690
+ message("", {
691
+ attachments: [attachment],
692
+ context: {
693
+ version: 1,
694
+ records: [
695
+ record,
696
+ {
697
+ ...record,
698
+ contextId: ComposerContextId.make("other-context"),
699
+ attachmentId: "other",
700
+ },
701
+ ],
702
+ },
703
+ }),
704
+ ]}
705
+ />,
706
+ );
707
+ using write = vi.spyOn(navigator.clipboard, "write").mockResolvedValue();
708
+ await click(screen.button("Copy message"));
709
+ await vi.waitFor(() => expect(write).toHaveBeenCalledOnce());
710
+ const [item] = write.mock.calls[0]![0];
711
+ const text = await (await item!.getType("text/plain")).text();
712
+ const fragment = await (await item!.getType(COMPOSER_CONTEXT_CLIPBOARD_MIME)).text();
713
+ expect(
714
+ collectComposerContextReferences(text).map((reference) => reference.contextId),
715
+ ).toEqual([record.contextId]);
716
+ expect(decodeComposerContextFragment(fragment)?.records).toEqual([record]);
717
+ },
718
+ );
719
+
720
it.each(["loadedmetadata", "loadeddata", "canplay"])(
721
"plays audio with unknown duration after %s and updates the total later",
722
async (readyEvent) => {
apps/web/src/components/chat/TimelineUserMessageRow.logic.ts
+5
-1
@@ -1,7 +1,11 @@
1
-import { type ChatImageAttachment } from "../../types";
1
+import { type ChatFileAttachment, type ChatImageAttachment } from "../../types";
2
import type { ComposerContextRecord, KnownComposerContextRecord } from "@t3tools/contracts";
3
import { asKnownContextRecord } from "~/lib/composerContextRecords";
4
5
+export function userMessageFileLabel(file: Pick<ChatFileAttachment, "name" | "source">) {
6
+ return file.source?._tag === "pasted-text" ? "Pasted text" : file.name;
7
+}
8
+
9
export function resolvePreviewAnnotationImage(input: {
10
record: Extract<KnownComposerContextRecord, { kind: "preview-annotation" }>;
11
recordsById: ReadonlyMap<string, ComposerContextRecord>;
apps/web/src/components/chat/TimelineUserMessageRow.tsx
+90
-31
@@ -62,7 +62,10 @@ import {
62
resolveUserMessageContext,
63
selectedMessageContextFragment,
64
} from "~/lib/composerContextRecords";
65
-import { collectComposerContextReferences } from "@t3tools/shared/composerContextReferences";
65
+import {
66
+ collectComposerContextReferences,
67
+ formatComposerContextReference,
68
+} from "@t3tools/shared/composerContextReferences";
69
import {
70
COMPOSER_CONTEXT_CLIPBOARD_MIME,
71
encodeComposerContextClipboardHtml,
@@ -80,7 +83,10 @@ import {
83
TimelineRowTimestamp,
84
} from "./TimelineRowParts";
85
import { UserMessageContextReferenceChip } from "./UserMessageContextChips";
83
-import { resolvePreviewAnnotationImage } from "./TimelineUserMessageRow.logic";
86
+import {
87
+ resolvePreviewAnnotationImage,
88
+ userMessageFileLabel,
89
+} from "./TimelineUserMessageRow.logic";
90
91
// Drawn inside the media so dark screenshots keep an edge on the dark background.
92
const MEDIA_EDGE_CLASS_NAME =
@@ -97,6 +103,8 @@ function UserFileCard({
103
readonly copyMarkdown: string | undefined;
104
}) {
105
const ctx = use(TimelineRowCtx);
106
+ const pastedText = file.source?._tag === "pasted-text";
107
+ const label = userMessageFileLabel(file);
108
const extension = /\.([a-z0-9]{1,8})$/i.exec(file.name)?.[1]?.toUpperCase() ?? "File";
109
const identity = (
110
<>
@@ -105,10 +113,17 @@ function UserFileCard({
113
</span>
114
<span className="min-w-0 flex-1">
115
<span className="block truncate text-sm font-medium group-hover/file:underline">
108
- {file.name}
116
+ {label}
117
</span>
118
<span className="block text-xs text-muted-foreground tabular-nums">
111
- {extension} · {formatBytes(file.sizeBytes)}
119
+ {file.downloadable === false ? (
120
+ "Sending…"
121
+ ) : (
122
+ <>
123
+ {!pastedText && `${extension} · `}
124
+ {formatBytes(file.sizeBytes)}
125
+ </>
126
+ )}
127
</span>
128
</span>
129
</>
@@ -119,12 +134,17 @@ function UserFileCard({
134
className="flex w-64 max-w-full items-center gap-1 rounded-2xl bg-message py-2 ps-2 pe-1 text-message-foreground"
135
>
136
{file.downloadable === false ? (
122
- <div className="flex min-w-0 flex-1 items-center gap-3">{identity}</div>
137
+ <>
138
+ <div className="flex min-w-0 flex-1 items-center gap-3">{identity}</div>
139
+ <Button size="icon-xs" variant="ghost-muted" disabled aria-label="Sending attachment">
140
+ <DownloadIcon />
141
+ </Button>
142
+ </>
143
) : (
144
<>
145
<button
146
type="button"
127
- aria-label={`Preview ${file.name}`}
147
+ aria-label={`Preview ${label}`}
148
onClick={() => ctx.onFileOpen(file)}
149
className="group/file focus-visible:ring-ring/70 flex min-w-0 flex-1 cursor-pointer items-center gap-3 rounded-xl text-left focus-visible:ring-2 focus-visible:ring-inset focus-visible:outline-none"
150
>
@@ -136,14 +156,14 @@ function UserFileCard({
156
<Button
157
size="icon-xs"
158
variant="ghost-muted"
139
- aria-label={`Download ${file.name}`}
159
+ aria-label={`Download ${label}`}
160
onClick={() => ctx.onFileDownload(file)}
161
/>
162
}
163
>
164
<DownloadIcon />
165
</TooltipTrigger>
146
- <TooltipPopup side="top">Download {file.name}</TooltipPopup>
166
+ <TooltipPopup side="top">Download {label}</TooltipPopup>
167
</Tooltip>
168
</>
169
)}
@@ -457,11 +477,7 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
477
regularImages.length + userVideos.length > 0;
478
const standaloneMedia = mediaOnly || mediaAboveText;
479
// A lone image keeps its own shape; a 4:3 crop hides most of a wide screenshot.
460
- const loneImage =
461
- standaloneMedia &&
462
- userVideos.length === 0 &&
463
- regularImages.length === 1 &&
464
- regularImages[0]!.source?.kind !== "snap-shot";
480
+ const loneImage = standaloneMedia && userVideos.length === 0 && regularImages.length === 1;
481
// Several images share one rounded shape, split by hairlines.
482
const collage =
483
standaloneMedia &&
@@ -483,6 +499,21 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
499
? ""
500
: reference.label,
501
).trim() === "";
502
+ const audioOnly =
503
+ !folded &&
504
+ userMessage.attribution !== "guest" &&
505
+ userAudio.length > 0 &&
506
+ regularImages.length + userVideos.length + otherUserFiles.length + unknownAttachments.length ===
507
+ 0 &&
508
+ replaceComposerContextReferences(resolvedContext.text, (reference) =>
509
+ attachmentReferences.some(
510
+ (attached) =>
511
+ attached.contextId === reference.contextId &&
512
+ userAudio.some((file) => file.id === attached.attachmentId),
513
+ )
514
+ ? ""
515
+ : reference.label,
516
+ ).trim() === "";
517
const annotationRecordIds = resolvedContext.records
518
.filter((record) => record.kind === "preview-annotation")
519
.map((record) => record.contextId);
@@ -496,8 +527,19 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
527
.split(/\r?\n/)
528
.find((line) => line.trim().length > 0)
529
?.trim() ?? "";
530
+ const mediaCopyRecords = mediaOnly
531
+ ? resolvedContext.records.flatMap((record) => {
532
+ const known = asKnownContextRecord(record);
533
+ return (known?.kind === "image" || known?.kind === "file") &&
534
+ (regularImages.some((image) => image.id === known.attachmentId) ||
535
+ userVideos.some((file) => file.id === known.attachmentId))
536
+ ? [known]
537
+ : [];
538
+ })
539
+ : [];
540
+ const copyRecords = mediaOnly ? mediaCopyRecords : resolvedContext.records;
541
const contextClipboardFragment =
500
- resolvedContext.records.length === 0
542
+ copyRecords.length === 0
543
? null
544
: encodeComposerContextFragment({
545
version: 1,
@@ -506,8 +548,10 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
548
...(ctx.threadRef ? { threadId: ctx.threadRef.threadId } : {}),
549
messageId: row.message.id,
550
},
509
- records: resolvedContext.records,
551
+ records: copyRecords,
552
});
553
+ const copyText =
554
+ resolvedContext.text || mediaCopyRecords.map(formatComposerContextReference).join("\n");
555
const onBodyCopyCapture = (event: React.ClipboardEvent<HTMLDivElement>) => {
556
if (resolvedContext.records.length === 0 || !event.clipboardData) return;
557
const selection = window.getSelection();
@@ -616,9 +660,13 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
660
"bg-background/70",
661
image.source?.kind === "snap-shot" && image.previewUrl
662
? cn(
619
- SNAP_SHOT_ATTACHMENT_FRAME_CLASS,
663
"col-span-2",
621
- standaloneMedia && "justify-self-end",
664
+ standaloneMedia
665
+ ? cn(
666
+ MEDIA_EDGE_CLASS_NAME,
667
+ "min-h-16 justify-self-end overflow-hidden rounded-2xl",
668
+ )
669
+ : SNAP_SHOT_ATTACHMENT_FRAME_CLASS,
670
)
671
: loneImage
672
? cn(MEDIA_EDGE_CLASS_NAME, "overflow-hidden rounded-2xl")
@@ -657,10 +705,11 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
705
loading="lazy"
706
className={cn(
707
"block transform-gpu",
660
- // A fixed height keeps the row from growing when the image loads.
661
- loneImage
662
- ? "h-48 w-auto min-w-24 max-w-full object-cover"
663
- : "size-full object-cover",
708
+ standaloneMedia && image.source?.kind === "snap-shot"
709
+ ? "h-auto max-h-48 w-auto min-w-24 max-w-full object-contain"
710
+ : loneImage
711
+ ? "h-48 w-auto min-w-24 max-w-full object-cover"
712
+ : "size-full object-cover",
713
)}
714
/>
715
</button>
@@ -724,8 +773,8 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
773
BUBBLE_CHIP_CLASS_NAME,
774
userMessage.attribution === "guest"
775
? guestBubbleClassName(false)
727
- : !mediaOnly && !fileCardsOnly && "bg-message",
728
- !folded && !mediaOnly && !fileCardsOnly && "p-3",
776
+ : !mediaOnly && !fileCardsOnly && !audioOnly && "bg-message",
777
+ !folded && !mediaOnly && !fileCardsOnly && !audioOnly && "p-3",
778
folded && expanded && "w-full",
779
)}
780
>
@@ -760,11 +809,12 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
809
>
810
{!mediaAboveText && mediaBlock}
811
{userAudio.length > 0 ? (
763
- <div className="mb-2 flex max-w-full flex-col gap-1">
812
+ <div className={cn("flex max-w-full flex-col gap-1", !audioOnly && "mb-2")}>
813
{userAudio.map((file) => (
814
<InlineAudioPreview
815
key={file.id}
816
name={file.name}
817
+ variant={audioOnly ? "bubble" : "chip"}
818
environmentId={ctx.activeThreadEnvironmentId}
819
resource={{
820
_tag: "attachment",
@@ -795,6 +845,8 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
845
{!fileCardsOnly && (unchippedFiles.length > 0 || unknownAttachments.length > 0) ? (
846
<div className="mb-2 flex flex-col gap-1">
847
{unchippedFiles.map((file) => {
848
+ const pastedText = file.source?._tag === "pasted-text";
849
+ const label = userMessageFileLabel(file);
850
const fileIdentity = (
851
<>
852
<PierreEntryIcon
@@ -802,7 +854,14 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
854
kind="file"
855
theme={ctx.resolvedTheme}
856
/>
805
- <span className="min-w-0 flex-1 truncate">{file.name}</span>
857
+ <span className="min-w-0 flex-1">
858
+ <span className="block truncate">{label}</span>
859
+ {file.downloadable === false || pastedText ? (
860
+ <span className="block text-xs text-muted-foreground tabular-nums">
861
+ {file.downloadable === false ? "Sending…" : formatBytes(file.sizeBytes)}
862
+ </span>
863
+ ) : null}
864
+ </span>
865
</>
866
);
867
if (file.downloadable !== false) {
@@ -810,7 +869,7 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
869
<div key={file.id} className="flex min-w-0 items-center gap-1">
870
<button
871
type="button"
813
- aria-label={`Preview ${file.name}`}
872
+ aria-label={`Preview ${label}`}
873
onClick={() => ctx.onFileOpen(file)}
874
className="focus-visible:ring-ring/70 flex min-w-0 flex-1 cursor-pointer items-center gap-2 rounded-md py-1 text-left text-sm hover:underline focus-visible:ring-2 focus-visible:ring-inset focus-visible:outline-none"
875
>
@@ -823,14 +882,14 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
882
<Button
883
size="icon-xs"
884
variant="ghost-muted"
826
- aria-label={`Download ${file.name}`}
885
+ aria-label={`Download ${label}`}
886
onClick={() => ctx.onFileDownload(file)}
887
/>
888
}
889
>
890
<DownloadIcon />
891
</TooltipTrigger>
833
- <TooltipPopup side="top">Download {file.name}</TooltipPopup>
892
+ <TooltipPopup side="top">Download {label}</TooltipPopup>
893
</Tooltip>
894
</div>
895
);
@@ -854,7 +913,7 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
913
))}
914
</div>
915
) : null}
857
- {fileCardsOnly ? null : (
916
+ {fileCardsOnly || audioOnly ? null : (
917
<div onCopyCapture={onBodyCopyCapture}>
918
<CollapsibleUserMessageBody
919
text={resolvedContext.text}
@@ -889,9 +948,9 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
948
{typeof revertTurnCount === "number" && (
949
<RevertUserMessageButton turnCount={revertTurnCount} messageId={row.message.id} />
950
)}
892
- {resolvedContext.text && (
951
+ {copyText && (
952
<MessageCopyButton
894
- text={contextClipboardFragment ? resolvedContext.text : plainText}
953
+ text={contextClipboardFragment ? copyText : plainText}
954
{...(contextClipboardFragment
955
? {
956
extraFlavors: {
apps/web/src/components/chat/UserMessageContextChips.tsx
+7
-4
@@ -60,6 +60,7 @@ import {
60
type ReviewCommentContext,
61
} from "../../reviewCommentContext";
62
import { TimelineRowCtx } from "./timelineRowContext";
63
+import { userMessageFileLabel } from "./TimelineUserMessageRow.logic";
64
65
function UserMessageMentionChip(props: {
66
record: Extract<KnownComposerContextRecord, { kind: "mention" }>;
@@ -372,12 +373,14 @@ const userMessageContextPresentationRegistry = createContextPresentationRegistry
373
}
374
const attachment = context.attachment;
375
const isVideo = isVideoAttachment(attachment);
376
+ const label = userMessageFileLabel(attachment);
377
const disabled =
378
attachment.downloadable === false && (!isVideo || attachment.previewUrl === undefined);
377
- const size = formatAttachmentSize(record.sizeBytes);
379
+ const size =
380
+ attachment.downloadable === false ? "Sending…" : formatAttachmentSize(record.sizeBytes);
381
return (
382
<FileChip
380
- name={record.name}
383
+ name={label}
384
svgPreview={
385
isSvgAttachment(attachment)
386
? { environmentId: context.environmentId, attachmentId: attachment.id }
@@ -387,12 +390,12 @@ const userMessageContextPresentationRegistry = createContextPresentationRegistry
390
isVideo={isVideo}
391
theme={context.resolvedTheme}
392
disabled={disabled}
390
- accessibleLabel={`${isVideo ? "Video" : "File"} attachment, ${record.name}, ${size}`}
393
+ accessibleLabel={`${isVideo ? "Video" : "File"} attachment, ${label}, ${size}`}
394
copyMarkdown={context.copyMarkdown}
395
onOpen={() =>
396
isVideo ? context.onExpandVideo(attachment) : context.onOpenFile(attachment)
397
}
395
- tooltip={`${record.name}\n${size}`}
398
+ tooltip={`${label}\n${size}`}
399
/>
400
);
401
},
apps/web/src/components/files/AudioPreview.tsx
+3
-1
@@ -15,6 +15,7 @@ type AudioPreviewProps = {
15
readonly revision?: string | null;
16
readonly onError?: () => void;
17
readonly compact?: boolean;
18
+ readonly variant?: "chip" | "bubble";
19
readonly failed?: boolean;
20
readonly onOpen?: (() => void) | undefined;
21
readonly onRetry?: () => void;
@@ -111,6 +112,7 @@ function AudioChip(props: AudioPreviewProps) {
112
<ContextChip
113
kind="file"
114
{...(props.failed ? { state: "invalid" as const } : {})}
115
+ {...(props.variant === "bubble" ? { shape: "bubble" as const } : {})}
116
className="relative isolate overflow-hidden"
117
title={props.failed ? "Audio unavailable. Open the file or retry playback." : props.name}
118
>
@@ -140,7 +142,7 @@ function AudioChip(props: AudioPreviewProps) {
142
>
143
<Icon aria-hidden className={loading && props.src ? "animate-spin" : undefined} />
144
</ContextChipAction>
143
- <ContextChipLabel className="max-w-72">
145
+ <ContextChipLabel className={props.variant === "bubble" ? "flex-1" : "max-w-72"}>
146
{open ? (
147
<button
148
type="button"
apps/web/src/components/files/InlineAudioPreview.tsx
+2
@@ -12,6 +12,7 @@ export function InlineAudioPreview(props: {
12
readonly src?: string;
13
readonly copyMarkdown?: string;
14
readonly onOpen?: () => void;
15
+ readonly variant?: "chip" | "bubble";
16
}) {
17
const container = useRef<HTMLSpanElement>(null);
18
const [visible, setVisible] = useState(false);
@@ -41,6 +42,7 @@ export function InlineAudioPreview(props: {
42
<span ref={container} data-markdown-copy={props.copyMarkdown}>
43
<AudioPreview
44
compact
45
+ variant={props.variant ?? "chip"}
46
name={props.name}
47
src={src ?? ""}
48
revision={