Skip to content

Commit bb1d3ce

Browse files
committed
fix(web,mobile): image-only messages show the image, not the placeholder prompt
1 parent 5eebf77 commit bb1d3ce

4 files changed

Lines changed: 71 additions & 13 deletions

File tree

‎apps/mobile/src/features/threads/ThreadFeed.tsx‎

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1596,6 +1596,16 @@ function renderFeedEntry(
15961596
const visibleAttachments = attachments.filter(
15971597
(attachment) => isImageAttachment(attachment) || !inlineAttachmentIds.has(attachment.id),
15981598
);
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+
);
15991609
return (
16001610
<Animated.View
16011611
className="mb-5 items-end"
@@ -1612,13 +1622,13 @@ function renderFeedEntry(
16121622
<View
16131623
className="min-w-0 rounded-[20px]"
16141624
style={{
1615-
backgroundColor: userBubbleColor,
1625+
backgroundColor: mediaOnly ? undefined : userBubbleColor,
16161626
maxWidth: props.duoColumns ? "85%" : props.userBubbleMaxWidth,
16171627
...(!bubbleBodyVisible
16181628
? null
16191629
: hasReviewCommentContext
16201630
? { width: props.reviewCommentBubbleWidth }
1621-
: hasWideBlock || foldExpanded
1631+
: hasWideBlock || foldExpanded || (mediaOnly && visibleAttachments.length > 0)
16221632
? { width: props.duoColumns ? "85%" : props.userBubbleMaxWidth }
16231633
: null),
16241634
}}
@@ -1640,7 +1650,13 @@ function renderFeedEntry(
16401650
/>
16411651
) : null}
16421652
{bubbleBodyVisible ? (
1643-
<View className={cn("gap-2 px-3.5 pb-2.5", foldRowId === null && "pt-2.5")}>
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+
>
16441660
{entry.pendingMessage?.attachments.map((attachment) =>
16451661
attachment.type === "image" && attachment.uploadedAttachmentId ? (
16461662
<MessageAttachmentImage
@@ -1707,7 +1723,7 @@ function renderFeedEntry(
17071723
})}
17081724
</View>
17091725
) : null}
1710-
{message.text.trim().length > 0 ? (
1726+
{presentation.text.trim().length > 0 ? (
17111727
<MarkdownImageAvailableWidthContext
17121728
value={props.userBubbleMaxWidth - USER_BUBBLE_HORIZONTAL_PADDING * 2}
17131729
>

‎apps/web/src/components/chat/TimelineUserMessageRow.tsx‎

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -327,9 +327,7 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
327327
: null,
328328
);
329329
const senderLabel = senderShell?.title.trim() || "Agent";
330-
const resolvedContext = resolveUserMessageContext(
331-
userMessage.attribution === "guest" ? { ...row.message, text: userMessage.text } : row.message,
332-
);
330+
const resolvedContext = resolveUserMessageContext({ ...row.message, text: userMessage.text });
333331
const previewImages = userImages.filter((image) => image.name.startsWith("preview-annotation-"));
334332
const revertTurnCount = row.revertTurnCount;
335333
const chippedAttachmentIds = new Set(
@@ -340,6 +338,21 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
340338
);
341339
const regularImages = userImages.filter((image) => !image.name.startsWith("preview-annotation-"));
342340
const unchippedFiles = otherUserFiles.filter((file) => !chippedAttachmentIds.has(file.id));
341+
// Images or videos sent without words show as media, not as a bubble around them.
342+
const mediaOnly =
343+
!folded &&
344+
userMessage.attribution !== "guest" &&
345+
resolvedContext.text.trim() === "" &&
346+
userAudio.length === 0 &&
347+
unchippedFiles.length === 0 &&
348+
unknownAttachments.length === 0 &&
349+
regularImages.length + userVideos.length > 0;
350+
// A lone image keeps its own shape; a 4:3 crop hides most of a wide screenshot.
351+
const loneImage =
352+
mediaOnly &&
353+
userVideos.length === 0 &&
354+
regularImages.length === 1 &&
355+
regularImages[0]!.source?.kind !== "snap-shot";
343356
const annotationRecordIds = resolvedContext.records
344357
.filter((record) => record.kind === "preview-annotation")
345358
.map((record) => record.contextId);
@@ -469,8 +482,10 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
469482
className={cn(
470483
"relative min-w-0 max-w-[80%] rounded-2xl text-message-foreground",
471484
BUBBLE_CHIP_CLASS_NAME,
472-
userMessage.attribution === "guest" ? guestBubbleClassName(false) : "bg-message",
473-
!folded && "p-3",
485+
userMessage.attribution === "guest"
486+
? guestBubbleClassName(false)
487+
: !mediaOnly && "bg-message",
488+
!folded && !mediaOnly && "p-3",
474489
folded && expanded && "w-full",
475490
)}
476491
>
@@ -502,15 +517,27 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
502517
)}
503518
>
504519
{(regularImages.length > 0 || userVideos.length > 0) && (
505-
<div className="mb-2 grid max-w-[210px] grid-cols-2 gap-2">
520+
<div
521+
className={cn(
522+
"grid gap-2",
523+
!mediaOnly
524+
? "mb-2 max-w-[210px] grid-cols-2"
525+
: loneImage
526+
? "max-w-full"
527+
: "w-80 max-w-full grid-cols-2",
528+
)}
529+
>
506530
{regularImages.map((image) => (
507531
<div
508532
key={image.id}
509533
className={cn(
510534
"bg-background/70",
511535
image.source?.kind === "snap-shot" && image.previewUrl
512536
? cn(SNAP_SHOT_ATTACHMENT_FRAME_CLASS, "col-span-2")
513-
: "aspect-[4/3] overflow-hidden rounded-lg border border-border/80",
537+
: cn(
538+
"overflow-hidden rounded-lg border border-border/80",
539+
!loneImage && "aspect-[4/3]",
540+
),
514541
)}
515542
>
516543
{image.previewUrl ? (
@@ -532,7 +559,13 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
532559
alt={image.name}
533560
decoding="async"
534561
loading="lazy"
535-
className="block size-full transform-gpu object-cover"
562+
className={cn(
563+
"block transform-gpu",
564+
// A fixed height keeps the row from growing when the image loads.
565+
loneImage
566+
? "h-48 w-auto min-w-24 max-w-full object-cover"
567+
: "size-full object-cover",
568+
)}
536569
/>
537570
</button>
538571
) : (

‎packages/client-runtime/src/userMessage.test.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { describe, expect, it } from "vite-plus/test";
22

33
import { GuestMessageId } from "@t3tools/contracts";
4+
import { ATTACHMENT_ONLY_BOOTSTRAP_PROMPT } from "@t3tools/shared/composerContextReferences";
45

56
import { resolveUserMessagePresentation } from "./userMessage.ts";
67

@@ -21,6 +22,12 @@ describe("resolveUserMessagePresentation", () => {
2122
}
2223
});
2324

25+
it("hides the prompt that stands in for an attachment-only message", () => {
26+
expect(
27+
resolveUserMessagePresentation({ role: "user", text: ATTACHMENT_ONLY_BOOTSTRAP_PROMPT }),
28+
).toEqual({ text: "", attribution: null, scheduledTaskId: undefined });
29+
});
30+
2431
it("shows a guest's own words and name, not the attributed text the agent reads", () => {
2532
expect(
2633
resolveUserMessagePresentation({

‎packages/client-runtime/src/userMessage.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
type OrchestrationV2IdleCompaction,
66
ScheduledTaskId,
77
} from "@t3tools/contracts";
8+
import { ATTACHMENT_ONLY_BOOTSTRAP_PROMPT } from "@t3tools/shared/composerContextReferences";
89

910
/** The working row while T3 Code's own compaction runs. */
1011
export const IDLE_COMPACTING_LABELS = {
@@ -68,7 +69,8 @@ export function resolveUserMessagePresentation(message: {
6869
};
6970
}
7071
return {
71-
text: message.text,
72+
// The agent needs words to start a turn; people sent only the attachments.
73+
text: message.text === ATTACHMENT_ONLY_BOOTSTRAP_PROMPT ? "" : message.text,
7274
attribution:
7375
message.createdBy !== "agent"
7476
? null

0 commit comments

Comments
 (0)