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(mobile): message media, file cards and grouped steers match web (#27373)
maria committed
Oct 30, 2026 at 15:58 UTC
e4ecaf629dbcf68d10a043944845cfa096b729a8
9 files changed
+902
-167
apps/mobile/src/components/MediaVideoPlayer.tsx
+5
-1
@@ -140,6 +140,7 @@ interface MediaVideoPlayerProps {
140
readonly paused?: boolean;
141
readonly onPlaybackStart?: () => void;
142
readonly actionsSource?: MediaActionsSource;
143
+ readonly borderRadius?: number;
144
}
145
146
function MediaVideoPlayerContent(props: MediaVideoPlayerProps) {
@@ -152,7 +153,10 @@ function MediaVideoPlayerContent(props: MediaVideoPlayerProps) {
153
<View
154
collapsable={false}
155
className="overflow-hidden rounded-[10px] bg-black"
155
- style={props.expanded ? { flex: 1 } : { width: "100%", maxWidth: 480, aspectRatio: 16 / 9 }}
156
+ style={[
157
+ props.expanded ? { flex: 1 } : { width: "100%", maxWidth: 480, aspectRatio: 16 / 9 },
158
+ props.borderRadius === undefined ? null : { borderRadius: props.borderRadius },
159
+ ]}
160
>
161
{playbackUri ? (
162
<LoadedMediaVideo
apps/mobile/src/features/threads/ThreadFeed.tsx
+494
-161
@@ -33,6 +33,7 @@ import { scopeThreadRef } from "@t3tools/client-runtime/environment";
33
import type { HandoffEndpoints } from "@t3tools/client-runtime/handoff";
34
import {
35
IDLE_COMPACTING_LABELS,
36
+ resolveUserMessageFileCards,
37
resolveUserMessagePresentation,
38
} from "@t3tools/client-runtime/user-message";
39
import { canForkProjectedAssistantItem } from "@t3tools/client-runtime/state/thread-workflows";
@@ -129,7 +130,10 @@ import { useResolveClassNames } from "uniwind";
130
import { useFilePreviewGallery, FilePreviewGallery } from "../../components/FilePreviewGallery";
131
import { assetImageSource } from "../../lib/assetImageSource";
132
import { composerImageGallery } from "../../lib/composerImageGallery";
133
+import { isFileBackedComposerAttachment } from "../../lib/composerImages";
134
+import { useLocalAttachmentPreview } from "../../lib/localAttachmentPreview";
135
import { messageImageGallery } from "./messageImageGallery";
136
+import { MARKDOWN_IMAGE_MAX_WIDTH, resolveMarkdownImageDisplaySize } from "./markdownImageSize";
137
import { FilePreviewModal, type FilePreviewSource } from "../../components/FilePreviewModal";
138
import { inlineFilePreviewKind, isPdfFile } from "../../lib/filePreview";
139
import { ThreadInlineFilePreview } from "./ThreadInlineFilePreview";
@@ -221,7 +225,9 @@ import {
225
import {
226
appendGuestPendingMessages,
227
appendPendingThreadMessages,
228
+ createThreadFeedGrouping,
229
isCompactionCommandFeedEntry,
230
+ type GroupedThreadFeedRow,
231
type ThreadFeedRow,
232
} from "./pending-thread-feed";
233
import type { QueuedThreadMessage } from "../../state/thread-outbox-model";
@@ -485,12 +491,57 @@ function AssistantForkButton(props: {
491
);
492
}
493
494
+function MessageImage(props: {
495
+ readonly source: ComponentPropsWithRef<typeof ExpoImage>["source"];
496
+ readonly className: string;
497
+ readonly maxWidth?: number;
498
+ readonly height?: number;
499
+ readonly onLoad?: () => void;
500
+ readonly onError?: () => void;
501
+}) {
502
+ const imageStyle = useResolveClassNames(props.className);
503
+ const [size, setSize] = useState<{ width: number; height: number } | null>(null);
504
+ const displaySize =
505
+ props.maxWidth !== undefined && size !== null
506
+ ? resolveMarkdownImageDisplaySize({
507
+ sourceWidth: size.width,
508
+ sourceHeight: size.height,
509
+ availableWidth: props.maxWidth,
510
+ })
511
+ : null;
512
+ return (
513
+ <ExpoImage
514
+ source={props.source}
515
+ cachePolicy="memory-disk"
516
+ style={[
517
+ imageStyle,
518
+ props.maxWidth !== undefined
519
+ ? (displaySize ?? {
520
+ width: Math.min(props.maxWidth, MARKDOWN_IMAGE_MAX_WIDTH),
521
+ aspectRatio: 1.3,
522
+ })
523
+ : props.height !== undefined
524
+ ? { height: props.height }
525
+ : undefined,
526
+ ]}
527
+ contentFit={props.maxWidth === undefined ? "cover" : "contain"}
528
+ onLoad={(event) => {
529
+ if (props.maxWidth !== undefined) setSize(event.source);
530
+ props.onLoad?.();
531
+ }}
532
+ onError={props.onError}
533
+ />
534
+ );
535
+}
536
+
537
function MessageAttachmentImage(props: {
538
readonly environmentId: EnvironmentId;
539
readonly attachmentId: string;
540
readonly name: string;
541
readonly mimeType: string;
542
readonly className: string;
543
+ readonly maxWidth?: number;
544
+ readonly height?: number;
545
readonly onPressPreview: (source: FilePreviewSource) => void;
546
}) {
547
const withGallery = useFilePreviewGallery();
@@ -504,11 +555,19 @@ function MessageAttachmentImage(props: {
555
const uri = useAssetUrl(props.environmentId, resource);
556
const refreshAssetUrl = useRefreshAssetUrl(props.environmentId, resource);
557
const retriedImage = useRef(false);
507
- const imageStyle = useResolveClassNames(props.className);
558
559
if (uri === null) {
560
return (
511
- <View className={`${props.className} items-center justify-center`}>
561
+ <View
562
+ className={`${props.className} items-center justify-center`}
563
+ style={
564
+ props.maxWidth !== undefined
565
+ ? { width: Math.min(props.maxWidth, MARKDOWN_IMAGE_MAX_WIDTH), aspectRatio: 1.3 }
566
+ : props.height !== undefined
567
+ ? { height: props.height }
568
+ : undefined
569
+ }
570
+ >
571
<AppActivityIndicator />
572
</View>
573
);
@@ -537,11 +596,11 @@ function MessageAttachmentImage(props: {
596
)
597
}
598
>
540
- <ExpoImage
599
+ <MessageImage
600
source={assetImageSource(props.environmentId, resource, uri)}
542
- cachePolicy="memory-disk"
543
- style={imageStyle}
544
- contentFit="cover"
601
+ className={props.className}
602
+ maxWidth={props.maxWidth}
603
+ height={props.height}
604
onLoad={() => {
605
retriedImage.current = false;
606
}}
@@ -564,11 +623,21 @@ function isFileAttachment(attachment: ChatAttachment): attachment is ChatFileAtt
623
return attachment.type === "file";
624
}
625
626
+function isMediaAttachment(attachment: ChatAttachment): boolean {
627
+ return (
628
+ isImageAttachment(attachment) ||
629
+ (isFileAttachment(attachment) && videoMimeType(attachment) !== null)
630
+ );
631
+}
632
+
633
function MessageAttachmentFile(props: {
634
readonly environmentId: EnvironmentId;
635
readonly attachment: ChatFileAttachment;
636
readonly onPressPreview: (source: FilePreviewSource) => void;
637
readonly onPlaybackStart: () => void;
638
+ readonly standaloneMedia?: boolean;
639
+ readonly standaloneFile?: boolean;
640
+ readonly available?: boolean;
641
}) {
642
const sourceIdentifier = useId();
643
const navigation = useNavigation();
@@ -603,7 +672,7 @@ function MessageAttachmentFile(props: {
672
);
673
674
const shareFile = (sourceIdentifier?: string) => {
606
- if (httpBaseUrl === null || openingRef.current) return;
675
+ if (props.available === false || httpBaseUrl === null || openingRef.current) return;
676
const controller = new AbortController();
677
openingRef.current = controller;
678
setOpening(true);
@@ -703,29 +772,34 @@ function MessageAttachmentFile(props: {
772
773
if (videoType !== null) {
774
return (
706
- <View className="my-1" style={{ width: 224, maxWidth: "100%" }}>
775
+ <View
776
+ className={props.standaloneMedia ? undefined : "my-1"}
777
+ style={{ width: props.standaloneMedia ? 320 : 224, maxWidth: "100%" }}
778
+ >
779
<ThreadMarkdownVideo
780
source={attachmentVideoPreviewSource(props.environmentId, attachment, sourceIdentifier)}
781
onPlaybackStart={props.onPlaybackStart}
782
+ borderRadius={props.standaloneMedia ? 20 : undefined}
783
/>
784
</View>
785
);
786
}
787
788
+ const disabled = props.available === false || opening || httpBaseUrl === null;
789
return (
716
- <>
717
- <PresentationSource
718
- identifier={sourceIdentifier}
719
- className="my-1"
720
- style={{ width: 280, maxWidth: "100%" }}
721
- >
790
+ <PresentationSource
791
+ identifier={sourceIdentifier}
792
+ className="my-1"
793
+ style={{ width: 280, maxWidth: "100%" }}
794
+ >
795
+ <View className="min-w-0 flex-row items-center overflow-hidden rounded-xl border border-border bg-card">
796
<Pressable
797
accessibilityRole="button"
798
accessibilityLabel={`Open ${attachment.name}`}
799
accessibilityValue={{ text: `${fileTypeLabel}, ${sizeLabel}` }}
726
- accessibilityState={{ disabled: opening || httpBaseUrl === null, busy: opening }}
727
- disabled={opening || httpBaseUrl === null}
728
- className="min-w-0 flex-row items-center gap-3 rounded-xl border border-border bg-card p-3 active:bg-subtle"
800
+ accessibilityState={{ disabled, busy: opening }}
801
+ disabled={disabled}
802
+ className="min-w-0 flex-1 flex-row items-center gap-3 p-3 active:bg-subtle"
803
onLongPress={() => shareFile(sourceIdentifier)}
804
onPress={openAttachment}
805
>
@@ -751,8 +825,205 @@ function MessageAttachmentFile(props: {
825
type="monochrome"
826
/>
827
</Pressable>
754
- </PresentationSource>
755
- </>
828
+ {props.standaloneFile ? (
829
+ <Pressable
830
+ accessibilityRole="button"
831
+ accessibilityLabel={`Download ${attachment.name}`}
832
+ accessibilityState={{ disabled, busy: opening }}
833
+ disabled={disabled}
834
+ className="mr-1 min-h-11 w-11 items-center justify-center rounded-lg active:bg-subtle disabled:opacity-40"
835
+ onPress={() => shareFile(sourceIdentifier)}
836
+ >
837
+ <SymbolView name="arrow.down" size={16} tintColorClassName="accent-foreground-muted" />
838
+ </Pressable>
839
+ ) : null}
840
+ </View>
841
+ </PresentationSource>
842
+ );
843
+}
844
+
845
+function UserMessageMedia(props: {
846
+ readonly attachments: ReadonlyArray<ChatAttachment>;
847
+ readonly pendingAttachments: QueuedThreadMessage["attachments"];
848
+ readonly environmentId: EnvironmentId;
849
+ readonly maxWidth: number;
850
+ readonly onPressPreview: (source: FilePreviewSource) => void;
851
+ readonly onPlaybackStart: () => void;
852
+}) {
853
+ const attachments = [...props.pendingAttachments, ...props.attachments];
854
+ const collage = attachments.length > 1 && attachments.every(isImageAttachment);
855
+ const imageProps = (index: number) => ({
856
+ className: "w-full bg-user-bubble-foreground/15",
857
+ maxWidth: collage ? undefined : props.maxWidth,
858
+ height: !collage
859
+ ? undefined
860
+ : attachments.length === 2 || (attachments.length === 3 && index === 0)
861
+ ? 192
862
+ : attachments.length === 3
863
+ ? (192 - StyleSheet.hairlineWidth) / 2
864
+ : 96,
865
+ });
866
+ const media = [
867
+ ...props.pendingAttachments.map((attachment, index) => {
868
+ const image = isImageAttachment(attachment);
869
+ return {
870
+ id: attachment.id,
871
+ image,
872
+ content:
873
+ image && attachment.uploadedAttachmentId ? (
874
+ <MessageAttachmentImage
875
+ environmentId={props.environmentId}
876
+ attachmentId={attachment.uploadedAttachmentId}
877
+ name={attachment.name}
878
+ mimeType={attachment.mimeType}
879
+ {...imageProps(index)}
880
+ onPressPreview={props.onPressPreview}
881
+ />
882
+ ) : !image && attachment.uploadedAttachmentId ? (
883
+ <ThreadMarkdownVideo
884
+ source={attachmentVideoPreviewSource(props.environmentId, {
885
+ ...attachment,
886
+ type: "file",
887
+ id: attachment.uploadedAttachmentId,
888
+ })}
889
+ onPlaybackStart={props.onPlaybackStart}
890
+ borderRadius={20}
891
+ />
892
+ ) : (
893
+ <PendingMessageMedia
894
+ attachment={attachment}
895
+ {...imageProps(index)}
896
+ onPressPreview={props.onPressPreview}
897
+ onPlaybackStart={props.onPlaybackStart}
898
+ />
899
+ ),
900
+ };
901
+ }),
902
+ ...props.attachments.map((attachment, index) => ({
903
+ id: attachment.id,
904
+ image: isImageAttachment(attachment),
905
+ content: isImageAttachment(attachment) ? (
906
+ <MessageAttachmentImage
907
+ environmentId={props.environmentId}
908
+ attachmentId={attachment.id}
909
+ name={attachment.name}
910
+ mimeType={attachment.mimeType}
911
+ {...imageProps(props.pendingAttachments.length + index)}
912
+ onPressPreview={props.onPressPreview}
913
+ />
914
+ ) : isFileAttachment(attachment) ? (
915
+ <MessageAttachmentFile
916
+ environmentId={props.environmentId}
917
+ attachment={attachment}
918
+ onPressPreview={props.onPressPreview}
919
+ onPlaybackStart={props.onPlaybackStart}
920
+ standaloneMedia
921
+ />
922
+ ) : null,
923
+ })),
924
+ ];
925
+ return collage ? (
926
+ <View
927
+ className="overflow-hidden rounded-[20px] bg-border"
928
+ style={{ width: 320, maxWidth: "100%", alignSelf: "flex-end", gap: StyleSheet.hairlineWidth }}
929
+ >
930
+ {media.length === 3 ? (
931
+ <View className="flex-row" style={{ gap: StyleSheet.hairlineWidth }}>
932
+ <View className="min-w-0" style={{ flex: 3 }}>
933
+ {media[0]!.content}
934
+ </View>
935
+ <View className="min-w-0" style={{ flex: 2, gap: StyleSheet.hairlineWidth }}>
936
+ {media[1]!.content}
937
+ {media[2]!.content}
938
+ </View>
939
+ </View>
940
+ ) : (
941
+ media
942
+ .filter((_, index) => index % 2 === 0)
943
+ .map((item, index) => (
944
+ <View key={item.id} className="flex-row" style={{ gap: StyleSheet.hairlineWidth }}>
945
+ <View className="min-w-0 flex-1">{item.content}</View>
946
+ {media[index * 2 + 1] ? (
947
+ <View className="min-w-0 flex-1">{media[index * 2 + 1]!.content}</View>
948
+ ) : null}
949
+ </View>
950
+ ))
951
+ )}
952
+ <View pointerEvents="none" className="absolute inset-0 rounded-[20px] border border-border" />
953
+ </View>
954
+ ) : (
955
+ <View className="items-end gap-2">
956
+ {media.map((item) => (
957
+ <View
958
+ key={item.id}
959
+ className="overflow-hidden rounded-[20px]"
960
+ style={{ width: item.image ? undefined : 320, maxWidth: "100%" }}
961
+ >
962
+ {item.content}
963
+ <View
964
+ pointerEvents="none"
965
+ className="absolute inset-0 rounded-[20px] border border-border"
966
+ />
967
+ </View>
968
+ ))}
969
+ </View>
970
+ );
971
+}
972
+
973
+function PendingMessageMedia(props: {
974
+ readonly attachment: QueuedThreadMessage["attachments"][number];
975
+ readonly className: string;
976
+ readonly maxWidth?: number;
977
+ readonly height?: number;
978
+ readonly onPressPreview: (source: FilePreviewSource) => void;
979
+ readonly onPlaybackStart: () => void;
980
+}) {
981
+ const withGallery = useFilePreviewGallery();
982
+ const { attachment } = props;
983
+ const fileBacked = isFileBackedComposerAttachment(attachment);
984
+ const preview = useLocalAttachmentPreview(fileBacked ? attachment : null);
985
+ if (isImageAttachment(attachment)) {
986
+ const uri = fileBacked ? preview.uri : (attachment.dataUrl ?? attachment.previewUri);
987
+ return (
988
+ <Pressable
989
+ accessibilityRole="imagebutton"
990
+ accessibilityLabel={`Open ${attachment.name}`}
991
+ onPress={() => {
992
+ const source = composerImageGallery([attachment])[0];
993
+ if (source) props.onPressPreview(withGallery(source));
994
+ }}
995
+ >
996
+ <MessageImage
997
+ source={uri === null ? undefined : { uri }}
998
+ className={props.className}
999
+ maxWidth={props.maxWidth}
1000
+ height={props.height}
1001
+ />
1002
+ </Pressable>
1003
+ );
1004
+ }
1005
+ if (preview.uri === null) {
1006
+ return (
1007
+ <View className="aspect-video items-center justify-center bg-black">
1008
+ {preview.error ? (
1009
+ <Text className="p-3 text-center text-xs text-white/70">{preview.error.message}</Text>
1010
+ ) : (
1011
+ <AppActivityIndicator />
1012
+ )}
1013
+ </View>
1014
+ );
1015
+ }
1016
+ return (
1017
+ <ThreadMarkdownVideo
1018
+ source={{
1019
+ type: "media",
1020
+ name: attachment.name,
1021
+ mimeType: attachment.mimeType,
1022
+ uri: preview.uri,
1023
+ }}
1024
+ onPlaybackStart={props.onPlaybackStart}
1025
+ borderRadius={20}
1026
+ />
1027
);
1028
}
1029
@@ -1338,6 +1609,7 @@ function renderFeedEntry(
1609
readonly contentWidth: number;
1610
readonly threadTitle: string;
1611
readonly workflowOpening: WorkflowOpening | null;
1612
+ readonly userMessageGrouping: GroupedThreadFeedRow["userMessageGrouping"];
1613
},
1614
) {
1615
const entry = info.item;
@@ -1582,7 +1854,9 @@ function renderFeedEntry(
1854
const foldRowId = presentation.attribution === "agent" ? `agent:${message.id}` : null;
1855
const foldExpanded = foldRowId !== null && (props.expandedWorkRows[foldRowId] ?? false);
1856
const bubbleBodyVisible = foldRowId === null || foldExpanded;
1585
- const intentBadge = resolveUserMessageIntentBadge(message.inputIntent);
1857
+ const intentBadge = props.userMessageGrouping.continuesSteer
1858
+ ? null
1859
+ : resolveUserMessageIntentBadge(message.inputIntent);
1860
const referenceIds = new Set(
1861
collectComposerContextReferences(message.text).map((reference) => reference.contextId),
1862
);
@@ -1593,22 +1867,36 @@ function renderFeedEntry(
1867
: [],
1868
),
1869
);
1870
+ const standaloneMedia = foldRowId === null && presentation.attribution !== "guest";
1871
+ const mediaAttachments = standaloneMedia ? attachments.filter(isMediaAttachment) : [];
1872
const visibleAttachments = attachments.filter(
1597
- (attachment) => isImageAttachment(attachment) || !inlineAttachmentIds.has(attachment.id),
1873
+ (attachment) =>
1874
+ !(standaloneMedia && isMediaAttachment(attachment)) &&
1875
+ (isImageAttachment(attachment) || !inlineAttachmentIds.has(attachment.id)),
1876
);
1599
- // Images sent without words show as images, not as a bubble around them.
1600
- const mediaOnly =
1601
- foldRowId === null &&
1602
- presentation.attribution !== "guest" &&
1603
- presentation.text.trim() === "" &&
1604
- visibleAttachments.length + (entry.pendingMessage?.attachments.length ?? 0) > 0 &&
1605
- visibleAttachments.every(isImageAttachment) &&
1606
- (entry.pendingMessage?.attachments ?? []).every(
1607
- (attachment) => attachment.type === "image",
1608
- );
1877
+ const pendingAttachments = entry.pendingMessage?.attachments ?? [];
1878
+ const pendingMedia = standaloneMedia ? pendingAttachments.filter(isMediaAttachment) : [];
1879
+ const pendingBubbleAttachments = standaloneMedia
1880
+ ? pendingAttachments.filter(
1881
+ (attachment) =>
1882
+ !isMediaAttachment(attachment) && !inlineAttachmentIds.has(attachment.id),
1883
+ )
1884
+ : pendingAttachments;
1885
+ const fileCards = standaloneMedia
1886
+ ? resolveUserMessageFileCards({
1887
+ text: presentation.text,
1888
+ attachments: attachments.length > 0 ? attachments : pendingAttachments,
1889
+ context: message.context,
1890
+ })
1891
+ : null;
1892
+ const hasBubble =
1893
+ fileCards === null &&
1894
+ (foldRowId !== null ||
1895
+ presentation.text.trim().length > 0 ||
1896
+ visibleAttachments.length + pendingBubbleAttachments.length > 0);
1897
return (
1898
<Animated.View
1611
- className="mb-5 items-end"
1899
+ className={cn("items-end", props.userMessageGrouping.groupedWithNext ? "mb-1" : "mb-5")}
1900
{...(enterAnimated ? { entering: FadeInUp.duration(220) } : {})}
1901
>
1902
{presentation.attribution === "t3code" ? (
@@ -1619,136 +1907,174 @@ function renderFeedEntry(
1907
{presentation.guestName !== undefined ? (
1908
<GuestMessageName name={presentation.guestName} />
1909
) : null}
1622
- <View
1623
- className="min-w-0 rounded-[20px]"
1624
- style={{
1625
- backgroundColor: mediaOnly ? undefined : userBubbleColor,
1626
- maxWidth: props.duoColumns ? "85%" : props.userBubbleMaxWidth,
1627
- ...(!bubbleBodyVisible
1628
- ? null
1629
- : hasReviewCommentContext
1630
- ? { width: props.reviewCommentBubbleWidth }
1631
- : hasWideBlock || foldExpanded || (mediaOnly && visibleAttachments.length > 0)
1632
- ? { width: props.duoColumns ? "85%" : props.userBubbleMaxWidth }
1633
- : null),
1634
- }}
1635
- >
1636
- {presentation.attribution === "guest" ? <GuestBubbleTint /> : null}
1637
- {foldRowId !== null ? (
1638
- <AgentMessageFoldHeader
1910
+ {mediaAttachments.length + pendingMedia.length > 0 ? (
1911
+ <View
1912
+ className={hasBubble ? "mb-2" : undefined}
1913
+ style={{ width: props.duoColumns ? "85%" : props.userBubbleMaxWidth }}
1914
+ >
1915
+ <UserMessageMedia
1916
+ attachments={mediaAttachments}
1917
+ pendingAttachments={pendingMedia}
1918
environmentId={props.environmentId}
1640
- senderThreadId={message.senderThreadId}
1641
- summary={
1642
- replaceComposerContextReferences(presentation.text, (ref) => ref.label)
1643
- .split(/\r?\n/)
1644
- .find((line) => line.trim().length > 0)
1645
- ?.trim() ?? ""
1646
- }
1647
- expanded={foldExpanded}
1648
- onToggle={() => props.onToggleWorkRow(foldRowId, entry.id)}
1649
- iconSubtleColor={iconSubtleColor}
1919
+ maxWidth={props.userBubbleMaxWidth}
1920
+ onPressPreview={props.onPressPreview}
1921
+ onPlaybackStart={props.onPlaybackStart}
1922
/>
1651
- ) : null}
1652
- {bubbleBodyVisible ? (
1653
- <View
1654
- className={cn(
1655
- "gap-2",
1656
- !mediaOnly && "px-3.5 pb-2.5",
1657
- !mediaOnly && foldRowId === null && "pt-2.5",
1658
- )}
1659
- >
1660
- {entry.pendingMessage?.attachments.map((attachment) =>
1661
- attachment.type === "image" && attachment.uploadedAttachmentId ? (
1662
- <MessageAttachmentImage
1663
- key={attachment.id}
1664
- environmentId={props.environmentId}
1665
- attachmentId={attachment.uploadedAttachmentId}
1666
- name={attachment.name}
1667
- mimeType={attachment.mimeType}
1668
- className={
1669
- mediaOnly
1670
- ? "h-[140px] w-[180px] rounded-[20px]"
1671
- : "h-[140px] w-[180px] rounded-[14px]"
1672
- }
1673
- onPressPreview={props.onPressPreview}
1674
- />
1675
- ) : attachment.type === "image" ? (
1676
- <Pressable
1677
- key={attachment.id}
1678
- accessibilityRole="imagebutton"
1679
- accessibilityLabel={`Open ${attachment.name}`}
1680
- onPress={() =>
1681
- props.onPressPreview({
1682
- kind: "image",
1683
- name: attachment.name,
1684
- uri: attachment.dataUrl ?? attachment.previewUri,
1685
- gallery: composerImageGallery(entry.pendingMessage?.attachments ?? []),
1686
- })
1687
- }
1688
- >
1689
- <Image
1690
- source={{ uri: attachment.previewUri }}
1691
- style={{ width: 180, height: 140, borderRadius: mediaOnly ? 20 : 14 }}
1923
+ </View>
1924
+ ) : null}
1925
+ {fileCards ? (
1926
+ <View
1927
+ className="items-end"
1928
+ style={{ maxWidth: props.duoColumns ? "85%" : props.userBubbleMaxWidth }}
1929
+ >
1930
+ {fileCards.map((file) => {
1931
+ const pendingFile = pendingAttachments.find(
1932
+ (attachment) => attachment.id === file.id,
1933
+ );
1934
+ return (
1935
+ <MessageAttachmentFile
1936
+ key={file.id}
1937
+ environmentId={props.environmentId}
1938
+ attachment={
1939
+ pendingFile?.uploadedAttachmentId
1940
+ ? { ...file, id: pendingFile.uploadedAttachmentId }
1941
+ : file
1942
+ }
1943
+ available={
1944
+ pendingFile === undefined || pendingFile.uploadedAttachmentId !== undefined
1945
+ }
1946
+ onPressPreview={props.onPressPreview}
1947
+ onPlaybackStart={props.onPlaybackStart}
1948
+ standaloneFile
1949
+ />
1950
+ );
1951
+ })}
1952
+ </View>
1953
+ ) : null}
1954
+ {hasBubble ? (
1955
+ <View
1956
+ className="min-w-0 rounded-[20px]"
1957
+ style={{
1958
+ backgroundColor: userBubbleColor,
1959
+ maxWidth: props.duoColumns ? "85%" : props.userBubbleMaxWidth,
1960
+ ...(!bubbleBodyVisible
1961
+ ? null
1962
+ : hasReviewCommentContext
1963
+ ? { width: props.reviewCommentBubbleWidth }
1964
+ : hasWideBlock || foldExpanded
1965
+ ? { width: props.duoColumns ? "85%" : props.userBubbleMaxWidth }
1966
+ : null),
1967
+ }}
1968
+ >
1969
+ {presentation.attribution === "guest" ? <GuestBubbleTint /> : null}
1970
+ {foldRowId !== null ? (
1971
+ <AgentMessageFoldHeader
1972
+ environmentId={props.environmentId}
1973
+ senderThreadId={message.senderThreadId}
1974
+ summary={
1975
+ replaceComposerContextReferences(presentation.text, (ref) => ref.label)
1976
+ .split(/\r?\n/)
1977
+ .find((line) => line.trim().length > 0)
1978
+ ?.trim() ?? ""
1979
+ }
1980
+ expanded={foldExpanded}
1981
+ onToggle={() => props.onToggleWorkRow(foldRowId, entry.id)}
1982
+ iconSubtleColor={iconSubtleColor}
1983
+ />
1984
+ ) : null}
1985
+ {bubbleBodyVisible ? (
1986
+ <View className={cn("gap-2 px-3.5 pb-2.5", foldRowId === null && "pt-2.5")}>
1987
+ {pendingBubbleAttachments.map((attachment) =>
1988
+ attachment.type === "image" && attachment.uploadedAttachmentId ? (
1989
+ <MessageAttachmentImage
1990
+ key={attachment.id}
1991
+ environmentId={props.environmentId}
1992
+ attachmentId={attachment.uploadedAttachmentId}
1993
+ name={attachment.name}
1994
+ mimeType={attachment.mimeType}
1995
+ className="h-[140px] w-[180px] rounded-[14px]"
1996
+ onPressPreview={props.onPressPreview}
1997
/>
1693
- </Pressable>
1694
- ) : (
1695
- <MessageAttachmentUnknown key={attachment.id} name={attachment.name} />
1696
- ),
1697
- )}
1698
- {/* An empty container still takes a gap, which pads every attachment-free bubble. */}
1699
- {visibleAttachments.length > 0 ? (
1700
- <View className={inlineAttachmentIds.size ? "flex-row flex-wrap gap-2" : "gap-2"}>
1701
- {visibleAttachments.map((attachment) => {
1702
- return isImageAttachment(attachment) ? (
1703
- <MessageAttachmentImage
1704
- key={attachment.id}
1705
- environmentId={props.environmentId}
1706
- attachmentId={attachment.id}
1707
- name={attachment.name}
1708
- mimeType={attachment.mimeType}
1709
- className={
1710
- inlineAttachmentIds.size
1711
- ? "h-24 w-24 rounded-[14px] bg-user-bubble-foreground/15"
1712
- : mediaOnly
1713
- ? // Matches the bubble's corners; native borders sit inside, so the edge adds no size.
1714
- "aspect-[1.3] w-full rounded-[20px] border border-border bg-user-bubble-foreground/15"
1715
- : "aspect-[1.3] w-full rounded-[14px] bg-user-bubble-foreground/15"
1716
- }
1717
- onPressPreview={props.onPressPreview}
1998
+ ) : attachment.type === "image" ? (
1999
+ <Pressable
2000
+ key={attachment.id}
2001
+ accessibilityRole="imagebutton"
2002
+ accessibilityLabel={`Open ${attachment.name}`}
2003
+ onPress={() => {
2004
+ const source = composerImageGallery([attachment])[0];
2005
+ if (source)
2006
+ props.onPressPreview({
2007
+ ...source,
2008
+ gallery: composerImageGallery(
2009
+ entry.pendingMessage?.attachments ?? [],
2010
+ props.environmentId,
2011
+ ),
2012
+ });
2013
+ }}
2014
+ >
2015
+ <Image
2016
+ source={{ uri: attachment.previewUri }}
2017
+ style={{ width: 180, height: 140, borderRadius: 14 }}
2018
/>
1719
- ) : isFileAttachment(attachment) ? (
1720
- <MessageAttachmentFile
1721
- key={attachment.id}
1722
- environmentId={props.environmentId}
1723
- attachment={attachment}
1724
- onPressPreview={props.onPressPreview}
1725
- onPlaybackStart={props.onPlaybackStart}
1726
- />
1727
- ) : (
1728
- <MessageAttachmentUnknown key={attachment.id} name={attachment.name} />
1729
- );
1730
- })}
1731
- </View>
1732
- ) : null}
1733
- {presentation.text.trim().length > 0 ? (
1734
- <MarkdownImageAvailableWidthContext
1735
- value={props.userBubbleMaxWidth - USER_BUBBLE_HORIZONTAL_PADDING * 2}
1736
- >
1737
- <UserMessageContent
1738
- text={renderedText}
1739
- environmentId={props.environmentId}
1740
- context={message.context}
1741
- markdownStyles={styles}
1742
- reviewCommentColors={props.reviewCommentColors}
1743
- skills={props.skills}
1744
- linkHandlers={props.markdownLinkHandlers}
1745
- renderImage={props.renderMarkdownImage}
1746
- />
1747
- </MarkdownImageAvailableWidthContext>
1748
- ) : null}
1749
- </View>
1750
- ) : null}
1751
- </View>
2019
+ </Pressable>
2020
+ ) : (
2021
+ <MessageAttachmentUnknown key={attachment.id} name={attachment.name} />
2022
+ ),
2023
+ )}
2024
+ {/* An empty container still takes a gap, which pads every attachment-free bubble. */}
2025
+ {visibleAttachments.length > 0 ? (
2026
+ <View
2027
+ className={inlineAttachmentIds.size ? "flex-row flex-wrap gap-2" : "gap-2"}
2028
+ >
2029
+ {visibleAttachments.map((attachment) => {
2030
+ return isImageAttachment(attachment) ? (
2031
+ <MessageAttachmentImage
2032
+ key={attachment.id}
2033
+ environmentId={props.environmentId}
2034
+ attachmentId={attachment.id}
2035
+ name={attachment.name}
2036
+ mimeType={attachment.mimeType}
2037
+ className={
2038
+ inlineAttachmentIds.size
2039
+ ? "h-24 w-24 rounded-[14px] bg-user-bubble-foreground/15"
2040
+ : "aspect-[1.3] w-full rounded-[14px] bg-user-bubble-foreground/15"
2041
+ }
2042
+ onPressPreview={props.onPressPreview}
2043
+ />
2044
+ ) : isFileAttachment(attachment) ? (
2045
+ <MessageAttachmentFile
2046
+ key={attachment.id}
2047
+ environmentId={props.environmentId}
2048
+ attachment={attachment}
2049
+ onPressPreview={props.onPressPreview}
2050
+ onPlaybackStart={props.onPlaybackStart}
2051
+ />
2052
+ ) : (
2053
+ <MessageAttachmentUnknown key={attachment.id} name={attachment.name} />
2054
+ );
2055
+ })}
2056
+ </View>
2057
+ ) : null}
2058
+ {presentation.text.trim().length > 0 ? (
2059
+ <MarkdownImageAvailableWidthContext
2060
+ value={props.userBubbleMaxWidth - USER_BUBBLE_HORIZONTAL_PADDING * 2}
2061
+ >
2062
+ <UserMessageContent
2063
+ text={renderedText}
2064
+ environmentId={props.environmentId}
2065
+ context={message.context}
2066
+ markdownStyles={styles}
2067
+ reviewCommentColors={props.reviewCommentColors}
2068
+ skills={props.skills}
2069
+ linkHandlers={props.markdownLinkHandlers}
2070
+ renderImage={props.renderMarkdownImage}
2071
+ />
2072
+ </MarkdownImageAvailableWidthContext>
2073
+ ) : null}
2074
+ </View>
2075
+ ) : null}
2076
+ </View>
2077
+ ) : null}
2078
{bubbleBodyVisible ? (
2079
<View className="mt-1 flex-row items-center justify-end gap-1 pr-0.5">
2080
{foldRowId !== null && message.senderThreadId ? (
@@ -2830,6 +3156,12 @@ export const ThreadFeed = memo(function ThreadFeed({
3156
const setupAnchorIndex = presentedFeed.findIndex(
3157
(entry) => entry.type === "message" && entry.message.role === "user",
3158
);
3159
+ const [groupFeed] = useState(createThreadFeedGrouping);
3160
+ const groupedFeed = groupFeed(presentedFeed, {
3161
+ workflowOpeningMessageId: workflowOpening?.messageId,
3162
+ setupAnchorIndex:
3163
+ props.worktreeSetup || props.setupWorkingStartedAt ? setupAnchorIndex : undefined,
3164
+ });
3165
// The empty↔filled key below remounts the list and resets its imperative
3166
// content-inset override. Seed each fresh instance as it attaches with the
3167
// current overlay height before the scroll integration's next reaction;
@@ -3149,7 +3481,7 @@ export const ThreadFeed = memo(function ThreadFeed({
3481
}
3482
}, [textSizeKey, contentWidth, hasHtmlRenders, beginReflow, listRef]);
3483
3152
- const renderItem = (info: { item: ThreadFeedRow; index: number }) => (
3484
+ const renderItem = (info: { item: GroupedThreadFeedRow; index: number }) => (
3485
<Animated.View
3486
key={info.item.id}
3487
entering={disclosureToggleSettling ? THREAD_FEED_DISCLOSURE_ENTER_TRANSITION : undefined}
@@ -3162,6 +3494,7 @@ export const ThreadFeed = memo(function ThreadFeed({
3494
>
3495
<ThreadMediaVisibility>
3496
{renderFeedEntry(info, {
3497
+ userMessageGrouping: info.item.userMessageGrouping,
3498
environmentId: props.environmentId,
3499
dispatchingMessageId: props.dispatchingMessageId,
3500
onEditPendingMessage: props.onEditPendingMessage,
@@ -3284,7 +3617,7 @@ export const ThreadFeed = memo(function ThreadFeed({
3617
maintainVisibleContentPosition={
3618
followsEnd && !disclosureToggleSettling ? false : maintainVisibleContentPosition
3619
}
3287
- data={presentedFeed}
3620
+ data={groupedFeed}
3621
extraData={listAppearanceData}
3622
renderItem={renderItem}
3623
viewabilityConfig={THREAD_MEDIA_VIEWABILITY_CONFIG}
@@ -3422,7 +3755,7 @@ function MessageImageGalleryScope(props: {
3755
entry.type === "message"
3756
? [
3757
...messageImageGallery(entry.message, { environmentId, threadId, workspaceRoot }),
3425
- ...composerImageGallery(entry.pendingMessage?.attachments ?? []),
3758
+ ...composerImageGallery(entry.pendingMessage?.attachments ?? [], environmentId),
3759
]
3760
: [];
3761
return <FilePreviewGallery value={images}>{props.children}</FilePreviewGallery>;
apps/mobile/src/features/threads/ThreadMarkdownVideo.tsx
+2
@@ -13,6 +13,7 @@ export function ThreadMarkdownVideo(props: {
13
readonly source: MediaVideoPreviewSource;
14
readonly thumbnailVisible?: boolean;
15
readonly onPlaybackStart?: () => void;
16
+ readonly borderRadius?: number;
17
}) {
18
const { source } = props;
19
const feedVisible = useContext(ThreadMediaVisibleContext);
@@ -43,6 +44,7 @@ export function ThreadMarkdownVideo(props: {
44
onPlaybackStart={props.onPlaybackStart}
45
unavailable={"resource" in source && asset._tag === "Failure"}
46
actionsSource={source.actionsSource}
47
+ borderRadius={props.borderRadius}
48
/>
49
);
50
}
apps/mobile/src/features/threads/pending-thread-feed.test.ts
+66
@@ -10,6 +10,7 @@ import {
10
import type { QueuedThreadMessage } from "../../state/thread-outbox-model";
11
import {
12
appendPendingThreadMessages,
13
+ createThreadFeedGrouping,
14
isCompactionCommandFeedEntry,
15
selectPendingAcknowledgedMessages,
16
} from "./pending-thread-feed";
@@ -25,6 +26,71 @@ const pending = (id: string): QueuedThreadMessage => ({
26
});
27
28
describe("pending timeline messages", () => {
29
+ it("keeps unchanged row identities while text streams and updates adjacent grouping", () => {
30
+ const group = createThreadFeedGrouping();
31
+ const [first, second, third] = appendPendingThreadMessages(
32
+ [],
33
+ [],
34
+ [pending("first"), pending("second"), pending("third")],
35
+ );
36
+ if (first?.type !== "message" || second?.type !== "message" || third?.type !== "message") {
37
+ throw new Error("Expected message rows");
38
+ }
39
+ const reply = {
40
+ ...third,
41
+ id: "reply",
42
+ message: { ...third.message, role: "assistant" as const, text: "start" },
43
+ };
44
+ const initial = group([first, second, reply], {});
45
+ const streamed = group(
46
+ [first, second, { ...reply, message: { ...reply.message, text: "streamed" } }],
47
+ {},
48
+ );
49
+ expect(streamed[0]).toBe(initial[0]);
50
+ expect(streamed[1]).toBe(initial[1]);
51
+ expect(streamed[2]).not.toBe(initial[2]);
52
+ const appended = group([first, second, third, reply], {});
53
+ expect(appended[0]).toBe(initial[0]);
54
+ expect(appended[1]).not.toBe(initial[1]);
55
+ expect(appended[1]?.userMessageGrouping.groupedWithNext).toBe(true);
56
+ expect(appended[2]?.userMessageGrouping.groupedWithPrevious).toBe(true);
57
+ const removed = group([first, second, reply], {});
58
+ expect(removed[1]?.userMessageGrouping.groupedWithNext).toBe(false);
59
+ const steer = {
60
+ ...second,
61
+ message: { ...second.message, inputIntent: "promoted_queued_to_steer" as const },
62
+ };
63
+ const singleSteer = group([first, steer], {});
64
+ const steers = group(
65
+ [{ ...first, message: { ...first.message, inputIntent: "steer" } }, steer],
66
+ {},
67
+ );
68
+ expect(steers[1]?.userMessageGrouping.continuesSteer).toBe(true);
69
+ expect(singleSteer[1]?.userMessageGrouping.continuesSteer).toBe(false);
70
+ expect(steers[1]).not.toBe(singleSteer[1]);
71
+ });
72
+
73
+ it("preserves setup, workflow, and compaction grouping boundaries", () => {
74
+ const group = createThreadFeedGrouping();
75
+ const feed = appendPendingThreadMessages([], [], [pending("first"), pending("second")]);
76
+ expect(group(feed, {})[0]?.userMessageGrouping.groupedWithNext).toBe(true);
77
+ for (const options of [{ setupAnchorIndex: 0 }, { workflowOpeningMessageId: "first" }]) {
78
+ const rows = group(feed, options);
79
+ expect(rows[0]?.userMessageGrouping.groupedWithNext).toBe(false);
80
+ expect(rows[1]?.userMessageGrouping.groupedWithPrevious).toBe(false);
81
+ }
82
+ const compact = appendPendingThreadMessages(
83
+ [],
84
+ [],
85
+ [{ ...pending("compact"), text: "/compact" }],
86
+ )[0]!;
87
+ expect(group([feed[0]!, compact], {})[0]?.userMessageGrouping.groupedWithNext).toBe(true);
88
+ expect(
89
+ group([feed[0]!, { ...compact, pendingMessage: undefined }], {})[0]?.userMessageGrouping
90
+ .groupedWithNext,
91
+ ).toBe(false);
92
+ });
93
+
94
it.each([false, true])(
95
"keeps a queued compact command in the pending message row (attachment: %s)",
96
(withAttachment) => {
apps/mobile/src/features/threads/pending-thread-feed.ts
+45
@@ -6,6 +6,7 @@ import {
6
import type { ThreadFeedEntry } from "../../lib/threadActivity";
7
import { scopedThreadKey } from "../../lib/scopedEntities";
8
import { threadHasCaughtUpTo } from "@t3tools/client-runtime/state/threads";
9
+import { resolveUserMessageGrouping } from "@t3tools/client-runtime/user-message";
10
import type {
11
AcknowledgedThreadMessage,
12
QueuedThreadMessage,
@@ -53,6 +54,50 @@ export function selectPendingAcknowledgedMessages(
54
/** A row of the thread feed's list. */
55
export type ThreadFeedRow = PendingThreadFeedEntry | GuestPendingFeedEntry;
56
57
+export type GroupedThreadFeedRow = ThreadFeedRow & {
58
+ readonly userMessageGrouping: ReturnType<typeof resolveUserMessageGrouping>;
59
+};
60
+
61
+export function createThreadFeedGrouping() {
62
+ const rows = new WeakMap<ThreadFeedRow, GroupedThreadFeedRow>();
63
+ const ungrouped = resolveUserMessageGrouping(undefined, undefined, undefined);
64
+ return (
65
+ feed: ReadonlyArray<ThreadFeedRow>,
66
+ options: { readonly workflowOpeningMessageId?: string; readonly setupAnchorIndex?: number },
67
+ ): ReadonlyArray<GroupedThreadFeedRow> => {
68
+ const groupingMessage = (index: number) => {
69
+ const entry = feed[index];
70
+ return entry?.type === "message" &&
71
+ entry.message.role === "user" &&
72
+ !isCompactionCommandFeedEntry(entry) &&
73
+ entry.message.id !== options.workflowOpeningMessageId
74
+ ? entry.message
75
+ : undefined;
76
+ };
77
+ return feed.map((entry, index) => {
78
+ const message = groupingMessage(index);
79
+ const grouping =
80
+ message === undefined
81
+ ? ungrouped
82
+ : resolveUserMessageGrouping(
83
+ message,
84
+ index - 1 === options.setupAnchorIndex ? undefined : groupingMessage(index - 1),
85
+ index === options.setupAnchorIndex ? undefined : groupingMessage(index + 1),
86
+ );
87
+ const previous = rows.get(entry);
88
+ if (
89
+ previous?.userMessageGrouping.groupedWithPrevious === grouping.groupedWithPrevious &&
90
+ previous.userMessageGrouping.groupedWithNext === grouping.groupedWithNext &&
91
+ previous.userMessageGrouping.continuesSteer === grouping.continuesSteer
92
+ )
93
+ return previous;
94
+ const row = { ...entry, userMessageGrouping: grouping };
95
+ rows.set(entry, row);
96
+ return row;
97
+ });
98
+ };
99
+}
100
+
101
/** Waiting guest messages go after the transcript, oldest first. */
102
export function appendGuestPendingMessages(
103
presentedFeed: ReadonlyArray<PendingThreadFeedEntry>,
apps/mobile/src/lib/composerImageGallery.ts
+17
@@ -1,12 +1,29 @@
1
import { imageMimeType } from "@t3tools/shared/image";
2
+import type { EnvironmentId } from "@t3tools/contracts";
3
import type { FilePreviewItem } from "../components/FilePreviewModal.types";
4
import { isFileBackedComposerAttachment, type DraftComposerAttachment } from "./composerImages";
5
6
export function composerImageGallery(
7
attachments: readonly DraftComposerAttachment[],
8
+ environmentId?: EnvironmentId,
9
): FilePreviewItem[] {
10
return attachments.flatMap((attachment): FilePreviewItem[] => {
11
if (attachment.type !== "image" && imageMimeType(attachment) === null) return [];
12
+ if (environmentId !== undefined && attachment.uploadedAttachmentId) {
13
+ return [
14
+ {
15
+ kind: "image",
16
+ name: attachment.name,
17
+ environmentId,
18
+ resource: {
19
+ _tag: "attachment",
20
+ attachmentId: attachment.uploadedAttachmentId,
21
+ fileName: attachment.name,
22
+ mimeType: attachment.mimeType,
23
+ },
24
+ },
25
+ ];
26
+ }
27
if (isFileBackedComposerAttachment(attachment)) {
28
return [{ kind: "image", name: attachment.name, attachment }];
29
}
apps/mobile/src/lib/filePreviewGallery.test.ts
+65
-2
@@ -1,9 +1,72 @@
1
-import { describe, expect, it } from "vite-plus/test";
2
-import { EnvironmentId } from "@t3tools/contracts";
1
+import { describe, expect, it, vi } from "vite-plus/test";
2
+import { EnvironmentId, ThreadId } from "@t3tools/contracts";
3
import type { FilePreviewItem } from "../components/FilePreviewModal.types";
4
+import type { DraftComposerAttachment } from "./composerImages";
5
+import { composerImageGallery } from "./composerImageGallery";
6
+import { messageImageGallery } from "../features/threads/messageImageGallery";
7
import { filePreviewGallery, filePreviewKey } from "./filePreviewGallery";
8
9
+vi.mock("./uuid", () => ({}));
10
+
11
describe("image preview groups", () => {
12
+ it.each([false, true])(
13
+ "keeps one entry per image through upload and delivery (file: %s)",
14
+ (fileBacked) => {
15
+ const environmentId = EnvironmentId.make("test");
16
+ const context = { environmentId, threadId: ThreadId.make("thread"), workspaceRoot: null };
17
+ const attachments: DraftComposerAttachment[] = ["a", "b"].map((id) => ({
18
+ id,
19
+ type: "image",
20
+ name: `${id}.png`,
21
+ mimeType: "image/png",
22
+ sizeBytes: 3,
23
+ previewUri: `data:image/png;base64,${id}`,
24
+ ...(fileBacked ? { fileUri: `file:///documents/${id}.png` } : {}),
25
+ }));
26
+ const delivered = (id: string) =>
27
+ messageImageGallery(
28
+ {
29
+ text: "",
30
+ attachments: [
31
+ {
32
+ type: "image",
33
+ id: `uploaded-${id}`,
34
+ name: `${id}.png`,
35
+ mimeType: "image/png",
36
+ sizeBytes: 3,
37
+ },
38
+ ],
39
+ },
40
+ context,
41
+ )[0]!;
42
+ const local = composerImageGallery(attachments, environmentId);
43
+ const uploading = composerImageGallery(
44
+ [{ ...attachments[0]!, uploadedAttachmentId: "uploaded-a" }, attachments[1]!],
45
+ environmentId,
46
+ );
47
+ const uploaded = composerImageGallery(
48
+ attachments.map((attachment) => ({
49
+ ...attachment,
50
+ uploadedAttachmentId: `uploaded-${attachment.id}`,
51
+ })),
52
+ environmentId,
53
+ );
54
+ for (const [selected, gallery] of [
55
+ [local[0]!, local],
56
+ [delivered("a"), uploading],
57
+ [uploading[1]!, uploading],
58
+ [delivered("a"), uploaded],
59
+ [delivered("a"), [...uploaded, delivered("a"), delivered("b")]],
60
+ [delivered("a"), [delivered("a"), delivered("b")]],
61
+ ] as const) {
62
+ const result = filePreviewGallery(selected, gallery);
63
+ expect(result).toHaveLength(2);
64
+ expect(result.map(filePreviewKey)).toEqual([...new Set(gallery.map(filePreviewKey))]);
65
+ }
66
+ expect(composerImageGallery(attachments)).toEqual(local);
67
+ },
68
+ );
69
+
70
it("matches remote originals despite metadata and property order differences", () => {
71
const environmentId = EnvironmentId.make("test");
72
const a: FilePreviewItem = {
packages/client-runtime/src/userMessage.test.ts
+150
-2
@@ -1,9 +1,157 @@
1
import { describe, expect, it } from "vite-plus/test";
2
3
-import { GuestMessageId } from "@t3tools/contracts";
3
+import { ComposerContextId, GuestMessageId, ScheduledTaskId } from "@t3tools/contracts";
4
import { ATTACHMENT_ONLY_BOOTSTRAP_PROMPT } from "@t3tools/shared/composerContextReferences";
5
6
-import { resolveUserMessagePresentation } from "./userMessage.ts";
6
+import {
7
+ resolveUserMessageFileCards,
8
+ resolveUserMessageGrouping,
9
+ resolveUserMessagePresentation,
10
+} from "./userMessage.ts";
11
+
12
+describe("resolveUserMessageGrouping", () => {
13
+ const own = { role: "user", text: "hello" };
14
+
15
+ it("groups only adjacent own messages", () => {
16
+ expect(resolveUserMessageGrouping(own, own, own)).toEqual({
17
+ groupedWithPrevious: true,
18
+ groupedWithNext: true,
19
+ continuesSteer: false,
20
+ });
21
+ expect(resolveUserMessageGrouping(own, undefined, own)).toMatchObject({
22
+ groupedWithPrevious: false,
23
+ groupedWithNext: true,
24
+ });
25
+ for (const boundary of [
26
+ undefined,
27
+ { ...own, role: "assistant" },
28
+ { ...own, createdBy: "agent" as const },
29
+ { ...own, createdBy: "agent" as const, creationSource: "server" as const },
30
+ { ...own, scheduledTaskId: ScheduledTaskId.make("task") },
31
+ {
32
+ ...own,
33
+ context: {
34
+ guest: { guestMessageId: GuestMessageId.make("guest"), name: "Sam", text: "hi" },
35
+ },
36
+ },
37
+ ]) {
38
+ expect(resolveUserMessageGrouping(own, boundary, boundary)).toEqual({
39
+ groupedWithPrevious: false,
40
+ groupedWithNext: false,
41
+ continuesSteer: false,
42
+ });
43
+ expect(resolveUserMessageGrouping(boundary, own, own)).toEqual({
44
+ groupedWithPrevious: false,
45
+ groupedWithNext: false,
46
+ continuesSteer: false,
47
+ });
48
+ }
49
+ });
50
+
51
+ it("shows one label for consecutive steers, including promoted queued messages", () => {
52
+ for (const inputIntent of ["steer", "promoted_queued_to_steer"] as const) {
53
+ const steer = { ...own, inputIntent };
54
+ expect(
55
+ resolveUserMessageGrouping(steer, { ...own, inputIntent: "steer" }, undefined)
56
+ .continuesSteer,
57
+ ).toBe(true);
58
+ expect(
59
+ resolveUserMessageGrouping(
60
+ steer,
61
+ { ...own, inputIntent: "promoted_queued_to_steer" },
62
+ undefined,
63
+ ).continuesSteer,
64
+ ).toBe(true);
65
+ expect(resolveUserMessageGrouping(steer, own, undefined).continuesSteer).toBe(false);
66
+ expect(resolveUserMessageGrouping(own, steer, undefined).continuesSteer).toBe(false);
67
+ }
68
+ });
69
+});
70
+
71
+describe("resolveUserMessageFileCards", () => {
72
+ const file = {
73
+ type: "file" as const,
74
+ id: "report",
75
+ name: "report.pdf",
76
+ mimeType: "application/pdf",
77
+ sizeBytes: 1024,
78
+ };
79
+ const record = {
80
+ ...file,
81
+ version: 1 as const,
82
+ kind: "file" as const,
83
+ contextId: ComposerContextId.make("report"),
84
+ label: file.name,
85
+ attachmentId: file.id,
86
+ };
87
+ const context = { version: 1 as const, records: [record] };
88
+ const reference = "[report.pdf](t3-context://v1/file/report)";
89
+
90
+ it("shows file cards for bare attachments and bound file references", () => {
91
+ for (const text of ["", " \n", reference]) {
92
+ expect(resolveUserMessageFileCards({ text, attachments: [file], context })).toEqual([file]);
93
+ }
94
+ expect(
95
+ resolveUserMessageFileCards({
96
+ text: `${reference}\n${reference}`,
97
+ attachments: [file],
98
+ context,
99
+ }),
100
+ ).toEqual([file]);
101
+ });
102
+
103
+ it("keeps words and unavailable or non-file references in the bubble", () => {
104
+ for (const text of [
105
+ `read ${reference}`,
106
+ "[missing.pdf](t3-context://v1/file/missing)",
107
+ "[report.pdf](t3-context://v1/mention/report)",
108
+ ]) {
109
+ expect(resolveUserMessageFileCards({ text, attachments: [file], context })).toBeNull();
110
+ }
111
+ expect(resolveUserMessageFileCards({ text: reference, attachments: [file] })).toBeNull();
112
+ expect(
113
+ resolveUserMessageFileCards({
114
+ text: reference,
115
+ attachments: [file],
116
+ context: {
117
+ version: 1,
118
+ records: [
119
+ {
120
+ version: 1,
121
+ kind: "file",
122
+ contextId: record.contextId,
123
+ label: file.name,
124
+ payload: {},
125
+ },
126
+ ],
127
+ },
128
+ }),
129
+ ).toBeNull();
130
+ expect(
131
+ resolveUserMessageFileCards({
132
+ text: reference,
133
+ attachments: [{ ...file, id: "other" }],
134
+ context,
135
+ }),
136
+ ).toBeNull();
137
+ });
138
+
139
+ it("keeps media, unknown attachments, and empty messages out of the file cards", () => {
140
+ const media = [
141
+ { ...file, type: "image" as const, name: "photo.png", mimeType: "image/png" },
142
+ { ...file, name: "photo.png", mimeType: "application/octet-stream" },
143
+ { ...file, name: "clip.mp4", mimeType: "video/mp4" },
144
+ { ...file, name: "clip.mov", mimeType: "application/octet-stream" },
145
+ { ...file, name: "voice.mp3", mimeType: "audio/mpeg" },
146
+ { ...file, type: "future" },
147
+ ];
148
+ expect(resolveUserMessageFileCards({ text: "", attachments: [] })).toBeNull();
149
+ for (const attachment of media) {
150
+ expect(resolveUserMessageFileCards({ text: "", attachments: [attachment] })).toBeNull();
151
+ expect(resolveUserMessageFileCards({ text: "", attachments: [file, attachment] })).toBeNull();
152
+ }
153
+ });
154
+});
155
156
describe("resolveUserMessagePresentation", () => {
157
const legacyText = "[Triggered by schedule task: Daily audit]\n\nCheck for crashes.\n";
packages/client-runtime/src/userMessage.ts
+58
-1
@@ -1,11 +1,21 @@
1
import {
2
+ type ChatAttachment,
3
+ type ChatFileAttachment,
4
type GuestMessageAttribution,
5
+ type OrchestrationMessageContext,
6
type OrchestrationV2Actor,
7
type OrchestrationV2CreationSource,
8
type OrchestrationV2IdleCompaction,
9
+ type OrchestrationV2UserMessageInputIntent,
10
ScheduledTaskId,
11
} from "@t3tools/contracts";
8
-import { isAttachmentOnlyBootstrapPrompt } from "@t3tools/shared/composerContextReferences";
12
+import {
13
+ isAttachmentOnlyBootstrapPrompt,
14
+ replaceComposerContextReferences,
15
+} from "@t3tools/shared/composerContextReferences";
16
+import { filePreviewKind } from "@t3tools/shared/filePreview";
17
+import { imageMimeType } from "@t3tools/shared/image";
18
+import { videoMimeType } from "@t3tools/shared/video";
19
20
/** The working row while T3 Code's own compaction runs. */
21
export const IDLE_COMPACTING_LABELS = {
@@ -22,6 +32,32 @@ export const IDLE_COMPACTION_TITLES = {
32
const LEGACY_AUTOMATION_PREFIX = /^\[Triggered by schedule task: [^\r\n]+\]\r?\n\r?\n/;
33
const LEGACY_AUTOMATION_MESSAGE_ID = /^scheduled-task-message:(.+):\d+:(?:scheduled|manual)$/;
34
35
+export function resolveUserMessageFileCards(message: {
36
+ readonly text: string;
37
+ readonly attachments: ReadonlyArray<ChatAttachment>;
38
+ readonly context?: OrchestrationMessageContext | undefined;
39
+}): ReadonlyArray<ChatFileAttachment> | null {
40
+ const files = message.attachments.filter(
41
+ (attachment): attachment is ChatFileAttachment =>
42
+ attachment.type === "file" &&
43
+ imageMimeType(attachment) === null &&
44
+ videoMimeType(attachment) === null &&
45
+ filePreviewKind(attachment) !== "audio",
46
+ );
47
+ if (files.length === 0 || files.length !== message.attachments.length) return null;
48
+ const fileIds = new Set(files.map((file) => file.id));
49
+ const remaining = replaceComposerContextReferences(message.text, (reference) => {
50
+ const record = message.context?.records.find((item) => item.contextId === reference.contextId);
51
+ return reference.kind === "file" &&
52
+ record?.kind === "file" &&
53
+ "attachmentId" in record &&
54
+ fileIds.has(record.attachmentId)
55
+ ? ""
56
+ : reference.label || reference.kind;
57
+ });
58
+ return remaining.trim() === "" ? files : null;
59
+}
60
+
61
export function resolveUserMessagePresentation(message: {
62
readonly id?: string;
63
readonly role: string;
@@ -80,3 +116,24 @@ export function resolveUserMessagePresentation(message: {
116
scheduledTaskId: undefined,
117
};
118
}
119
+
120
+type GroupableUserMessage = Parameters<typeof resolveUserMessagePresentation>[0] & {
121
+ readonly inputIntent?: OrchestrationV2UserMessageInputIntent;
122
+};
123
+
124
+export function resolveUserMessageGrouping(
125
+ message: GroupableUserMessage | undefined,
126
+ previous: GroupableUserMessage | undefined,
127
+ next: GroupableUserMessage | undefined,
128
+) {
129
+ const isOwnMessage = (value: GroupableUserMessage | undefined) =>
130
+ value?.role === "user" && resolveUserMessagePresentation(value).attribution === null;
131
+ const isSteer = (value: GroupableUserMessage | undefined) =>
132
+ value?.inputIntent === "steer" || value?.inputIntent === "promoted_queued_to_steer";
133
+ const groupedWithPrevious = isOwnMessage(message) && isOwnMessage(previous);
134
+ return {
135
+ groupedWithPrevious,
136
+ groupedWithNext: isOwnMessage(message) && isOwnMessage(next),
137
+ continuesSteer: groupedWithPrevious && isSteer(message) && isSteer(previous),
138
+ };
139
+}