Skip to content
TypeScript

fix(web,mobile): image-only messages show the image, not the placeholder prompt (#26769)

mariacba30591f958
diff --git a/apps/mobile/src/features/threads/ThreadFeed.tsx b/apps/mobile/src/features/threads/ThreadFeed.tsx
index da127a29ef9..33a57859ff8 100644
--- a/apps/mobile/src/features/threads/ThreadFeed.tsx
+++ b/apps/mobile/src/features/threads/ThreadFeed.tsx
@@ -1596,6 +1596,16 @@ function renderFeedEntry(
const visibleAttachments = attachments.filter(
(attachment) => isImageAttachment(attachment) || !inlineAttachmentIds.has(attachment.id),
);
+ // Images sent without words show as images, not as a bubble around them.
+ const mediaOnly =
+ foldRowId === null &&
+ presentation.attribution !== "guest" &&
+ presentation.text.trim() === "" &&
+ visibleAttachments.length + (entry.pendingMessage?.attachments.length ?? 0) > 0 &&
+ visibleAttachments.every(isImageAttachment) &&
+ (entry.pendingMessage?.attachments ?? []).every(
+ (attachment) => attachment.type === "image",
+ );
return (
<Animated.View
className="mb-5 items-end"
@@ -1612,13 +1622,13 @@ function renderFeedEntry(
<View
className="min-w-0 rounded-[20px]"
style={{
- backgroundColor: userBubbleColor,
+ backgroundColor: mediaOnly ? undefined : userBubbleColor,
maxWidth: props.duoColumns ? "85%" : props.userBubbleMaxWidth,
...(!bubbleBodyVisible
? null
: hasReviewCommentContext
? { width: props.reviewCommentBubbleWidth }
- : hasWideBlock || foldExpanded
+ : hasWideBlock || foldExpanded || (mediaOnly && visibleAttachments.length > 0)
? { width: props.duoColumns ? "85%" : props.userBubbleMaxWidth }
: null),
}}
@@ -1640,7 +1650,13 @@ function renderFeedEntry(
/>
) : null}
{bubbleBodyVisible ? (
- <View className={cn("gap-2 px-3.5 pb-2.5", foldRowId === null && "pt-2.5")}>
+ <View
+ className={cn(
+ "gap-2",
+ !mediaOnly && "px-3.5 pb-2.5",
+ !mediaOnly && foldRowId === null && "pt-2.5",
+ )}
+ >
{entry.pendingMessage?.attachments.map((attachment) =>
attachment.type === "image" && attachment.uploadedAttachmentId ? (
<MessageAttachmentImage
@@ -1649,7 +1665,11 @@ function renderFeedEntry(
attachmentId={attachment.uploadedAttachmentId}
name={attachment.name}
mimeType={attachment.mimeType}
- className="h-[140px] w-[180px] rounded-[14px]"
+ className={
+ mediaOnly
+ ? "h-[140px] w-[180px] rounded-[20px]"
+ : "h-[140px] w-[180px] rounded-[14px]"
+ }
onPressPreview={props.onPressPreview}
/>
) : attachment.type === "image" ? (
@@ -1668,7 +1688,7 @@ function renderFeedEntry(
>
<Image
source={{ uri: attachment.previewUri }}
- style={{ width: 180, height: 140, borderRadius: 14 }}
+ style={{ width: 180, height: 140, borderRadius: mediaOnly ? 20 : 14 }}
/>
</Pressable>
) : (
@@ -1689,7 +1709,10 @@ function renderFeedEntry(
className={
inlineAttachmentIds.size
? "h-24 w-24 rounded-[14px] bg-user-bubble-foreground/15"
- : "aspect-[1.3] w-full rounded-[14px] bg-user-bubble-foreground/15"
+ : mediaOnly
+ ? // Matches the bubble's corners; native borders sit inside, so the edge adds no size.
+ "aspect-[1.3] w-full rounded-[20px] border border-border bg-user-bubble-foreground/15"
+ : "aspect-[1.3] w-full rounded-[14px] bg-user-bubble-foreground/15"
}
onPressPreview={props.onPressPreview}
/>
@@ -1707,7 +1730,7 @@ function renderFeedEntry(
})}
</View>
) : null}
- {message.text.trim().length > 0 ? (
+ {presentation.text.trim().length > 0 ? (
<MarkdownImageAvailableWidthContext
value={props.userBubbleMaxWidth - USER_BUBBLE_HORIZONTAL_PADDING * 2}
>
diff --git a/apps/mobile/src/features/threads/threadQueueControlPresentation.ts b/apps/mobile/src/features/threads/threadQueueControlPresentation.ts
index 444d969176b..a62e29e1479 100644
--- a/apps/mobile/src/features/threads/threadQueueControlPresentation.ts
+++ b/apps/mobile/src/features/threads/threadQueueControlPresentation.ts
@@ -1,5 +1,6 @@
import type { EnvironmentId, RunId, ThreadId } from "@t3tools/contracts";
import { assistantCitationsToPlainText } from "@t3tools/shared/assistantCitations";
+import { isAttachmentOnlyBootstrapPrompt } from "@t3tools/shared/composerContextReferences";
export const REMOVE_QUEUED_MESSAGE_ACCESSIBILITY_LABEL = "Remove queued message";
@@ -35,7 +36,9 @@ export function resolveThreadQueueRowControls(input: {
canSend: mutationEnabled && (input.canPromoteToSteer || input.canSendNow) && !isEditing,
dismissAccessibilityLabel: REMOVE_QUEUED_MESSAGE_ACCESSIBILITY_LABEL,
// Editing and sending keep the original text so quoted citations stay linked.
- displayText: assistantCitationsToPlainText(input.text),
+ displayText: isAttachmentOnlyBootstrapPrompt(input.text)
+ ? ""
+ : assistantCitationsToPlainText(input.text),
isEditing,
};
}
diff --git a/apps/web/src/components/chat/QueuedRunsControl.tsx b/apps/web/src/components/chat/QueuedRunsControl.tsx
index 866612bc110..ca98e919ff9 100644
--- a/apps/web/src/components/chat/QueuedRunsControl.tsx
+++ b/apps/web/src/components/chat/QueuedRunsControl.tsx
@@ -1,7 +1,10 @@
import { scopeThreadRef } from "@t3tools/client-runtime/environment";
import { deriveThreadQueueWorkflowState } from "@t3tools/client-runtime/state/thread-workflows";
import { assistantCitationsToPlainText } from "@t3tools/shared/assistantCitations";
-import { replaceComposerContextReferences } from "@t3tools/shared/composerContextReferences";
+import {
+ isAttachmentOnlyBootstrapPrompt,
+ replaceComposerContextReferences,
+} from "@t3tools/shared/composerContextReferences";
import type {
ChatAttachment as ContractChatAttachment,
EnvironmentId,
@@ -237,11 +240,13 @@ export function QueuedRunsControl({
</span>
<ol className="flex flex-col items-end gap-3" id={queueListId}>
{visibleItems.map((item, position) => {
- const previewText = assistantCitationsToPlainText(
- replaceComposerContextReferences(item.text, (reference) =>
- reference.kind === "image" && item.thumbnails.length > 0 ? "" : reference.label,
- ),
- ).trim();
+ const previewText = isAttachmentOnlyBootstrapPrompt(item.text)
+ ? ""
+ : assistantCitationsToPlainText(
+ replaceComposerContextReferences(item.text, (reference) =>
+ reference.kind === "image" && item.thumbnails.length > 0 ? "" : reference.label,
+ ),
+ ).trim();
const isEditing = item.runId !== null && item.runId === props.editingRunId;
return (
<li
diff --git a/apps/web/src/components/chat/TimelineUserMessageRow.tsx b/apps/web/src/components/chat/TimelineUserMessageRow.tsx
index 66cbb0bcc5e..c4363a1b459 100644
--- a/apps/web/src/components/chat/TimelineUserMessageRow.tsx
+++ b/apps/web/src/components/chat/TimelineUserMessageRow.tsx
@@ -81,6 +81,10 @@ import {
import { UserMessageContextReferenceChip } from "./UserMessageContextChips";
import { resolvePreviewAnnotationImage } from "./TimelineUserMessageRow.logic";
+// Drawn inside the media so dark screenshots keep an edge on the dark background.
+const MEDIA_EDGE_CLASS_NAME =
+ "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";
+
const BUBBLE_CHIP_CLASS_NAME =
"[&_[data-slot=context-chip]]:[--context-chip-ink:var(--context-chip-message,var(--context-chip-accent))]";
@@ -327,9 +331,7 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
: null,
);
const senderLabel = senderShell?.title.trim() || "Agent";
- const resolvedContext = resolveUserMessageContext(
- userMessage.attribution === "guest" ? { ...row.message, text: userMessage.text } : row.message,
- );
+ const resolvedContext = resolveUserMessageContext({ ...row.message, text: userMessage.text });
const previewImages = userImages.filter((image) => image.name.startsWith("preview-annotation-"));
const revertTurnCount = row.revertTurnCount;
const chippedAttachmentIds = new Set(
@@ -340,6 +342,27 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
);
const regularImages = userImages.filter((image) => !image.name.startsWith("preview-annotation-"));
const unchippedFiles = otherUserFiles.filter((file) => !chippedAttachmentIds.has(file.id));
+ // Images or videos sent without words show as media, not as a bubble around them.
+ const mediaOnly =
+ !folded &&
+ userMessage.attribution !== "guest" &&
+ resolvedContext.text.trim() === "" &&
+ userAudio.length === 0 &&
+ unchippedFiles.length === 0 &&
+ unknownAttachments.length === 0 &&
+ regularImages.length + userVideos.length > 0;
+ // A lone image keeps its own shape; a 4:3 crop hides most of a wide screenshot.
+ const loneImage =
+ mediaOnly &&
+ userVideos.length === 0 &&
+ regularImages.length === 1 &&
+ regularImages[0]!.source?.kind !== "snap-shot";
+ // Several images sent without words share one rounded shape, split by hairlines.
+ const collage =
+ mediaOnly &&
+ userVideos.length === 0 &&
+ regularImages.length > 1 &&
+ regularImages.every((image) => image.source?.kind !== "snap-shot");
const annotationRecordIds = resolvedContext.records
.filter((record) => record.kind === "preview-annotation")
.map((record) => record.contextId);
@@ -469,8 +492,10 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
className={cn(
"relative min-w-0 max-w-[80%] rounded-2xl text-message-foreground",
BUBBLE_CHIP_CLASS_NAME,
- userMessage.attribution === "guest" ? guestBubbleClassName(false) : "bg-message",
- !folded && "p-3",
+ userMessage.attribution === "guest"
+ ? guestBubbleClassName(false)
+ : !mediaOnly && "bg-message",
+ !folded && !mediaOnly && "p-3",
folded && expanded && "w-full",
)}
>
@@ -502,15 +527,45 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
)}
>
{(regularImages.length > 0 || userVideos.length > 0) && (
- <div className="mb-2 grid max-w-[210px] grid-cols-2 gap-2">
- {regularImages.map((image) => (
+ <div
+ className={cn(
+ "grid",
+ !mediaOnly
+ ? "mb-2 max-w-[210px] grid-cols-2 gap-2"
+ : loneImage
+ ? "max-w-full"
+ : collage
+ ? cn(
+ MEDIA_EDGE_CLASS_NAME,
+ "w-80 max-w-full gap-px overflow-hidden rounded-2xl bg-black/9 dark:bg-white/12",
+ regularImages.length === 2
+ ? "auto-rows-[12rem] grid-cols-2"
+ : regularImages.length === 3
+ ? "auto-rows-[calc(6rem-0.5px)] grid-cols-[3fr_2fr]"
+ : "auto-rows-[6rem] grid-cols-2",
+ )
+ : "w-80 max-w-full grid-cols-2 gap-2",
+ )}
+ >
+ {regularImages.map((image, index) => (
<div
key={image.id}
className={cn(
"bg-background/70",
image.source?.kind === "snap-shot" && image.previewUrl
? cn(SNAP_SHOT_ATTACHMENT_FRAME_CLASS, "col-span-2")
- : "aspect-[4/3] overflow-hidden rounded-lg border border-border/80",
+ : loneImage
+ ? cn(MEDIA_EDGE_CLASS_NAME, "overflow-hidden rounded-2xl")
+ : collage
+ ? cn(
+ "overflow-hidden bg-background",
+ regularImages.length === 3 && index === 0 && "row-span-2",
+ regularImages.length > 3 &&
+ regularImages.length % 2 === 1 &&
+ index === regularImages.length - 1 &&
+ "col-span-2",
+ )
+ : "aspect-[4/3] overflow-hidden rounded-lg border border-border/80",
)}
>
{image.previewUrl ? (
@@ -532,11 +587,23 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
alt={image.name}
decoding="async"
loading="lazy"
- className="block size-full transform-gpu object-cover"
+ className={cn(
+ "block transform-gpu",
+ // A fixed height keeps the row from growing when the image loads.
+ loneImage
+ ? "h-48 w-auto min-w-24 max-w-full object-cover"
+ : "size-full object-cover",
+ )}
/>
</button>
) : (
- <div className="flex min-h-[72px] items-center justify-center px-2 py-3 text-center text-2xs text-muted-foreground/70">
+ <div
+ className={cn(
+ "flex min-h-[72px] items-center justify-center px-2 py-3 text-center text-2xs text-muted-foreground/70",
+ loneImage && "h-48 w-64 max-w-full",
+ collage && "h-full",
+ )}
+ >
{image.name}
</div>
)}
diff --git a/packages/client-runtime/src/userMessage.test.ts b/packages/client-runtime/src/userMessage.test.ts
index 0447dc54d1b..207939cf2f3 100644
--- a/packages/client-runtime/src/userMessage.test.ts
+++ b/packages/client-runtime/src/userMessage.test.ts
@@ -1,6 +1,7 @@
import { describe, expect, it } from "vite-plus/test";
import { GuestMessageId } from "@t3tools/contracts";
+import { ATTACHMENT_ONLY_BOOTSTRAP_PROMPT } from "@t3tools/shared/composerContextReferences";
import { resolveUserMessagePresentation } from "./userMessage.ts";
@@ -21,6 +22,19 @@ describe("resolveUserMessagePresentation", () => {
}
});
+ it("hides the prompt that stands in for an attachment-only message", () => {
+ for (const text of [
+ ATTACHMENT_ONLY_BOOTSTRAP_PROMPT,
+ `Ultrathink:\n${ATTACHMENT_ONLY_BOOTSTRAP_PROMPT}`,
+ ]) {
+ expect(resolveUserMessagePresentation({ role: "user", text })).toEqual({
+ text: "",
+ attribution: null,
+ scheduledTaskId: undefined,
+ });
+ }
+ });
+
it("shows a guest's own words and name, not the attributed text the agent reads", () => {
expect(
resolveUserMessagePresentation({
diff --git a/packages/client-runtime/src/userMessage.ts b/packages/client-runtime/src/userMessage.ts
index d5d7c5ac089..8a80f31b155 100644
--- a/packages/client-runtime/src/userMessage.ts
+++ b/packages/client-runtime/src/userMessage.ts
@@ -5,6 +5,7 @@ import {
type OrchestrationV2IdleCompaction,
ScheduledTaskId,
} from "@t3tools/contracts";
+import { isAttachmentOnlyBootstrapPrompt } from "@t3tools/shared/composerContextReferences";
/** The working row while T3 Code's own compaction runs. */
export const IDLE_COMPACTING_LABELS = {
@@ -68,7 +69,8 @@ export function resolveUserMessagePresentation(message: {
};
}
return {
- text: message.text,
+ // The agent needs words to start a turn; people sent only the attachments.
+ text: isAttachmentOnlyBootstrapPrompt(message.text) ? "" : message.text,
attribution:
message.createdBy !== "agent"
? null
diff --git a/packages/shared/src/composerContextReferences.ts b/packages/shared/src/composerContextReferences.ts
index e1b25bc094a..88361606a9a 100644
--- a/packages/shared/src/composerContextReferences.ts
+++ b/packages/shared/src/composerContextReferences.ts
@@ -132,6 +132,11 @@ export function collectComposerContextReferences(
export const ATTACHMENT_ONLY_BOOTSTRAP_PROMPT =
"[User attached one or more files without additional text. Respond using the conversation context and the attached files.]";
+/** Claude's ultrathink effort sends the prompt as `Ultrathink:\n<prompt>`. */
+export function isAttachmentOnlyBootstrapPrompt(text: string): boolean {
+ return text.replace(/^Ultrathink:\s*/i, "") === ATTACHMENT_ONLY_BOOTSTRAP_PROMPT;
+}
+
export function isImageReferencesOnly(text: string): boolean {
const references = collectComposerContextReferences(text);
return (
diff --git a/packages/shared/src/threadFindText.test.ts b/packages/shared/src/threadFindText.test.ts
index 0dd6a87ae1d..77a0874c213 100644
--- a/packages/shared/src/threadFindText.test.ts
+++ b/packages/shared/src/threadFindText.test.ts
@@ -1,6 +1,7 @@
import { EnvironmentId, MessageId, ThreadId } from "@t3tools/contracts";
import { expect, it } from "vite-plus/test";
import { serializeAssistantCitation } from "./assistantCitations.ts";
+import { ATTACHMENT_ONLY_BOOTSTRAP_PROMPT } from "./composerContextReferences.ts";
import { searchableMessageSegments } from "./threadFindText.ts";
it("excludes review attachments rendered as context chips", () => {
@@ -31,6 +32,16 @@ it("excludes structured context chips without joining text across them", () => {
).toEqual(["before", "after"]);
});
+it("excludes the hidden prompt of an attachment-only message", () => {
+ expect(
+ searchableMessageSegments({
+ role: "user",
+ streaming: false,
+ text: ATTACHMENT_ONLY_BOOTSTRAP_PROMPT,
+ }),
+ ).toEqual([]);
+});
+
it("does not upgrade literal legacy tags in messages with structured context", () => {
const text =
"<terminal_context>\n- Terminal 1 line 12:\n 12 | visible output\n</terminal_context>";
diff --git a/packages/shared/src/threadFindText.ts b/packages/shared/src/threadFindText.ts
index a2e5b4dbb98..3afec6e0472 100644
--- a/packages/shared/src/threadFindText.ts
+++ b/packages/shared/src/threadFindText.ts
@@ -21,7 +21,10 @@ import {
resolveMarkdownFileLinkTarget,
} from "./markdownLinks.ts";
import { upgradeLegacyContextMessage } from "./composerContextLegacy.ts";
-import { parseComposerContextHref } from "./composerContextReferences.ts";
+import {
+ isAttachmentOnlyBootstrapPrompt,
+ parseComposerContextHref,
+} from "./composerContextReferences.ts";
import { assistantCitationLabel, parseAssistantCitationHref } from "./assistantCitations.ts";
import type { OrchestrationV2ConversationMessage } from "@t3tools/contracts";
import { proposedPlanTitle, stripDisplayedPlanMarkdown } from "./proposedPlanText.ts";
@@ -216,6 +219,8 @@ export function searchableMessageSegments(
skills: readonly InlineSkill[] = [],
): readonly string[] | null {
if (message.role === "user") {
+ // Clients hide this prompt, so find must not match text nobody can see.
+ if (isAttachmentOnlyBootstrapPrompt(message.text)) return [];
const text = message.context ? message.text : upgradeLegacyContextMessage(message.text).text;
return markdownThreadFindText(text, true, cwd, skills);
}