Skip to content

Commit cba3059

Browse files
authored
fix(web,mobile): image-only messages show the image, not the placeholder prompt (#26769)
1 parent 812c0a7 commit cba3059

9 files changed

Lines changed: 161 additions & 26 deletions

File tree

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

Lines changed: 30 additions & 7 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
@@ -1649,7 +1665,11 @@ function renderFeedEntry(
16491665
attachmentId={attachment.uploadedAttachmentId}
16501666
name={attachment.name}
16511667
mimeType={attachment.mimeType}
1652-
className="h-[140px] w-[180px] rounded-[14px]"
1668+
className={
1669+
mediaOnly
1670+
? "h-[140px] w-[180px] rounded-[20px]"
1671+
: "h-[140px] w-[180px] rounded-[14px]"
1672+
}
16531673
onPressPreview={props.onPressPreview}
16541674
/>
16551675
) : attachment.type === "image" ? (
@@ -1668,7 +1688,7 @@ function renderFeedEntry(
16681688
>
16691689
<Image
16701690
source={{ uri: attachment.previewUri }}
1671-
style={{ width: 180, height: 140, borderRadius: 14 }}
1691+
style={{ width: 180, height: 140, borderRadius: mediaOnly ? 20 : 14 }}
16721692
/>
16731693
</Pressable>
16741694
) : (
@@ -1689,7 +1709,10 @@ function renderFeedEntry(
16891709
className={
16901710
inlineAttachmentIds.size
16911711
? "h-24 w-24 rounded-[14px] bg-user-bubble-foreground/15"
1692-
: "aspect-[1.3] w-full 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"
16931716
}
16941717
onPressPreview={props.onPressPreview}
16951718
/>
@@ -1707,7 +1730,7 @@ function renderFeedEntry(
17071730
})}
17081731
</View>
17091732
) : null}
1710-
{message.text.trim().length > 0 ? (
1733+
{presentation.text.trim().length > 0 ? (
17111734
<MarkdownImageAvailableWidthContext
17121735
value={props.userBubbleMaxWidth - USER_BUBBLE_HORIZONTAL_PADDING * 2}
17131736
>

‎apps/mobile/src/features/threads/threadQueueControlPresentation.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { EnvironmentId, RunId, ThreadId } from "@t3tools/contracts";
22
import { assistantCitationsToPlainText } from "@t3tools/shared/assistantCitations";
3+
import { isAttachmentOnlyBootstrapPrompt } from "@t3tools/shared/composerContextReferences";
34

45
export const REMOVE_QUEUED_MESSAGE_ACCESSIBILITY_LABEL = "Remove queued message";
56

@@ -35,7 +36,9 @@ export function resolveThreadQueueRowControls(input: {
3536
canSend: mutationEnabled && (input.canPromoteToSteer || input.canSendNow) && !isEditing,
3637
dismissAccessibilityLabel: REMOVE_QUEUED_MESSAGE_ACCESSIBILITY_LABEL,
3738
// Editing and sending keep the original text so quoted citations stay linked.
38-
displayText: assistantCitationsToPlainText(input.text),
39+
displayText: isAttachmentOnlyBootstrapPrompt(input.text)
40+
? ""
41+
: assistantCitationsToPlainText(input.text),
3942
isEditing,
4043
};
4144
}

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import { scopeThreadRef } from "@t3tools/client-runtime/environment";
22
import { deriveThreadQueueWorkflowState } from "@t3tools/client-runtime/state/thread-workflows";
33
import { assistantCitationsToPlainText } from "@t3tools/shared/assistantCitations";
4-
import { replaceComposerContextReferences } from "@t3tools/shared/composerContextReferences";
4+
import {
5+
isAttachmentOnlyBootstrapPrompt,
6+
replaceComposerContextReferences,
7+
} from "@t3tools/shared/composerContextReferences";
58
import type {
69
ChatAttachment as ContractChatAttachment,
710
EnvironmentId,
@@ -237,11 +240,13 @@ export function QueuedRunsControl({
237240
</span>
238241
<ol className="flex flex-col items-end gap-3" id={queueListId}>
239242
{visibleItems.map((item, position) => {
240-
const previewText = assistantCitationsToPlainText(
241-
replaceComposerContextReferences(item.text, (reference) =>
242-
reference.kind === "image" && item.thumbnails.length > 0 ? "" : reference.label,
243-
),
244-
).trim();
243+
const previewText = isAttachmentOnlyBootstrapPrompt(item.text)
244+
? ""
245+
: assistantCitationsToPlainText(
246+
replaceComposerContextReferences(item.text, (reference) =>
247+
reference.kind === "image" && item.thumbnails.length > 0 ? "" : reference.label,
248+
),
249+
).trim();
245250
const isEditing = item.runId !== null && item.runId === props.editingRunId;
246251
return (
247252
<li

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

Lines changed: 77 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ import {
8181
import { UserMessageContextReferenceChip } from "./UserMessageContextChips";
8282
import { resolvePreviewAnnotationImage } from "./TimelineUserMessageRow.logic";
8383

84+
// Drawn inside the media so dark screenshots keep an edge on the dark background.
85+
const MEDIA_EDGE_CLASS_NAME =
86+
"relative after:pointer-events-none after:absolute after:inset-0 after:z-10 after:rounded-[inherit] after:ring-1 after:ring-inset after:ring-black/9 dark:after:ring-white/12";
87+
8488
const BUBBLE_CHIP_CLASS_NAME =
8589
"[&_[data-slot=context-chip]]:[--context-chip-ink:var(--context-chip-message,var(--context-chip-accent))]";
8690

@@ -327,9 +331,7 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
327331
: null,
328332
);
329333
const senderLabel = senderShell?.title.trim() || "Agent";
330-
const resolvedContext = resolveUserMessageContext(
331-
userMessage.attribution === "guest" ? { ...row.message, text: userMessage.text } : row.message,
332-
);
334+
const resolvedContext = resolveUserMessageContext({ ...row.message, text: userMessage.text });
333335
const previewImages = userImages.filter((image) => image.name.startsWith("preview-annotation-"));
334336
const revertTurnCount = row.revertTurnCount;
335337
const chippedAttachmentIds = new Set(
@@ -340,6 +342,27 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
340342
);
341343
const regularImages = userImages.filter((image) => !image.name.startsWith("preview-annotation-"));
342344
const unchippedFiles = otherUserFiles.filter((file) => !chippedAttachmentIds.has(file.id));
345+
// Images or videos sent without words show as media, not as a bubble around them.
346+
const mediaOnly =
347+
!folded &&
348+
userMessage.attribution !== "guest" &&
349+
resolvedContext.text.trim() === "" &&
350+
userAudio.length === 0 &&
351+
unchippedFiles.length === 0 &&
352+
unknownAttachments.length === 0 &&
353+
regularImages.length + userVideos.length > 0;
354+
// A lone image keeps its own shape; a 4:3 crop hides most of a wide screenshot.
355+
const loneImage =
356+
mediaOnly &&
357+
userVideos.length === 0 &&
358+
regularImages.length === 1 &&
359+
regularImages[0]!.source?.kind !== "snap-shot";
360+
// Several images sent without words share one rounded shape, split by hairlines.
361+
const collage =
362+
mediaOnly &&
363+
userVideos.length === 0 &&
364+
regularImages.length > 1 &&
365+
regularImages.every((image) => image.source?.kind !== "snap-shot");
343366
const annotationRecordIds = resolvedContext.records
344367
.filter((record) => record.kind === "preview-annotation")
345368
.map((record) => record.contextId);
@@ -469,8 +492,10 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
469492
className={cn(
470493
"relative min-w-0 max-w-[80%] rounded-2xl text-message-foreground",
471494
BUBBLE_CHIP_CLASS_NAME,
472-
userMessage.attribution === "guest" ? guestBubbleClassName(false) : "bg-message",
473-
!folded && "p-3",
495+
userMessage.attribution === "guest"
496+
? guestBubbleClassName(false)
497+
: !mediaOnly && "bg-message",
498+
!folded && !mediaOnly && "p-3",
474499
folded && expanded && "w-full",
475500
)}
476501
>
@@ -502,15 +527,45 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
502527
)}
503528
>
504529
{(regularImages.length > 0 || userVideos.length > 0) && (
505-
<div className="mb-2 grid max-w-[210px] grid-cols-2 gap-2">
506-
{regularImages.map((image) => (
530+
<div
531+
className={cn(
532+
"grid",
533+
!mediaOnly
534+
? "mb-2 max-w-[210px] grid-cols-2 gap-2"
535+
: loneImage
536+
? "max-w-full"
537+
: collage
538+
? cn(
539+
MEDIA_EDGE_CLASS_NAME,
540+
"w-80 max-w-full gap-px overflow-hidden rounded-2xl bg-black/9 dark:bg-white/12",
541+
regularImages.length === 2
542+
? "auto-rows-[12rem] grid-cols-2"
543+
: regularImages.length === 3
544+
? "auto-rows-[calc(6rem-0.5px)] grid-cols-[3fr_2fr]"
545+
: "auto-rows-[6rem] grid-cols-2",
546+
)
547+
: "w-80 max-w-full grid-cols-2 gap-2",
548+
)}
549+
>
550+
{regularImages.map((image, index) => (
507551
<div
508552
key={image.id}
509553
className={cn(
510554
"bg-background/70",
511555
image.source?.kind === "snap-shot" && image.previewUrl
512556
? cn(SNAP_SHOT_ATTACHMENT_FRAME_CLASS, "col-span-2")
513-
: "aspect-[4/3] overflow-hidden rounded-lg border border-border/80",
557+
: loneImage
558+
? cn(MEDIA_EDGE_CLASS_NAME, "overflow-hidden rounded-2xl")
559+
: collage
560+
? cn(
561+
"overflow-hidden bg-background",
562+
regularImages.length === 3 && index === 0 && "row-span-2",
563+
regularImages.length > 3 &&
564+
regularImages.length % 2 === 1 &&
565+
index === regularImages.length - 1 &&
566+
"col-span-2",
567+
)
568+
: "aspect-[4/3] overflow-hidden rounded-lg border border-border/80",
514569
)}
515570
>
516571
{image.previewUrl ? (
@@ -532,11 +587,23 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
532587
alt={image.name}
533588
decoding="async"
534589
loading="lazy"
535-
className="block size-full transform-gpu object-cover"
590+
className={cn(
591+
"block transform-gpu",
592+
// A fixed height keeps the row from growing when the image loads.
593+
loneImage
594+
? "h-48 w-auto min-w-24 max-w-full object-cover"
595+
: "size-full object-cover",
596+
)}
536597
/>
537598
</button>
538599
) : (
539-
<div className="flex min-h-[72px] items-center justify-center px-2 py-3 text-center text-2xs text-muted-foreground/70">
600+
<div
601+
className={cn(
602+
"flex min-h-[72px] items-center justify-center px-2 py-3 text-center text-2xs text-muted-foreground/70",
603+
loneImage && "h-48 w-64 max-w-full",
604+
collage && "h-full",
605+
)}
606+
>
540607
{image.name}
541608
</div>
542609
)}

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

Lines changed: 14 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,19 @@ describe("resolveUserMessagePresentation", () => {
2122
}
2223
});
2324

25+
it("hides the prompt that stands in for an attachment-only message", () => {
26+
for (const text of [
27+
ATTACHMENT_ONLY_BOOTSTRAP_PROMPT,
28+
`Ultrathink:\n${ATTACHMENT_ONLY_BOOTSTRAP_PROMPT}`,
29+
]) {
30+
expect(resolveUserMessagePresentation({ role: "user", text })).toEqual({
31+
text: "",
32+
attribution: null,
33+
scheduledTaskId: undefined,
34+
});
35+
}
36+
});
37+
2438
it("shows a guest's own words and name, not the attributed text the agent reads", () => {
2539
expect(
2640
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 { isAttachmentOnlyBootstrapPrompt } 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: isAttachmentOnlyBootstrapPrompt(message.text) ? "" : message.text,
7274
attribution:
7375
message.createdBy !== "agent"
7476
? null

‎packages/shared/src/composerContextReferences.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ export function collectComposerContextReferences(
132132
export const ATTACHMENT_ONLY_BOOTSTRAP_PROMPT =
133133
"[User attached one or more files without additional text. Respond using the conversation context and the attached files.]";
134134

135+
/** Claude's ultrathink effort sends the prompt as `Ultrathink:\n<prompt>`. */
136+
export function isAttachmentOnlyBootstrapPrompt(text: string): boolean {
137+
return text.replace(/^Ultrathink:\s*/i, "") === ATTACHMENT_ONLY_BOOTSTRAP_PROMPT;
138+
}
139+
135140
export function isImageReferencesOnly(text: string): boolean {
136141
const references = collectComposerContextReferences(text);
137142
return (

‎packages/shared/src/threadFindText.test.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { EnvironmentId, MessageId, ThreadId } from "@t3tools/contracts";
22
import { expect, it } from "vite-plus/test";
33
import { serializeAssistantCitation } from "./assistantCitations.ts";
4+
import { ATTACHMENT_ONLY_BOOTSTRAP_PROMPT } from "./composerContextReferences.ts";
45
import { searchableMessageSegments } from "./threadFindText.ts";
56

67
it("excludes review attachments rendered as context chips", () => {
@@ -31,6 +32,16 @@ it("excludes structured context chips without joining text across them", () => {
3132
).toEqual(["before", "after"]);
3233
});
3334

35+
it("excludes the hidden prompt of an attachment-only message", () => {
36+
expect(
37+
searchableMessageSegments({
38+
role: "user",
39+
streaming: false,
40+
text: ATTACHMENT_ONLY_BOOTSTRAP_PROMPT,
41+
}),
42+
).toEqual([]);
43+
});
44+
3445
it("does not upgrade literal legacy tags in messages with structured context", () => {
3546
const text =
3647
"<terminal_context>\n- Terminal 1 line 12:\n 12 | visible output\n</terminal_context>";

‎packages/shared/src/threadFindText.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ import {
2121
resolveMarkdownFileLinkTarget,
2222
} from "./markdownLinks.ts";
2323
import { upgradeLegacyContextMessage } from "./composerContextLegacy.ts";
24-
import { parseComposerContextHref } from "./composerContextReferences.ts";
24+
import {
25+
isAttachmentOnlyBootstrapPrompt,
26+
parseComposerContextHref,
27+
} from "./composerContextReferences.ts";
2528
import { assistantCitationLabel, parseAssistantCitationHref } from "./assistantCitations.ts";
2629
import type { OrchestrationV2ConversationMessage } from "@t3tools/contracts";
2730
import { proposedPlanTitle, stripDisplayedPlanMarkdown } from "./proposedPlanText.ts";
@@ -216,6 +219,8 @@ export function searchableMessageSegments(
216219
skills: readonly InlineSkill[] = [],
217220
): readonly string[] | null {
218221
if (message.role === "user") {
222+
// Clients hide this prompt, so find must not match text nobody can see.
223+
if (isAttachmentOnlyBootstrapPrompt(message.text)) return [];
219224
const text = message.context ? message.text : upgradeLegacyContextMessage(message.text).text;
220225
return markdownThreadFindText(text, true, cwd, skills);
221226
}

0 commit comments

Comments
 (0)