Skip to content

Commit 78c78df

Browse files
committed
fix(web,mobile): keep attachment captions accurate and stable
1 parent 27e6b55 commit 78c78df

4 files changed

Lines changed: 41 additions & 21 deletions

File tree

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1527,10 +1527,10 @@ function renderFeedEntry(
15271527
const foldExpanded = foldRowId !== null && (props.expandedWorkRows[foldRowId] ?? false);
15281528
const bubbleBodyVisible = foldRowId === null || foldExpanded;
15291529
const intentBadge = resolveUserMessageIntentBadge(message.inputIntent);
1530-
// The bootstrap prompt is for the agent, not the reader: a person's photo-only message shows a
1531-
// caption instead. Messages from other agents keep their folded rendering.
15321530
const attachmentOnly =
1533-
presentation.attribution !== "agent" && isAttachmentOnlyBootstrapText(message.text);
1531+
presentation.attribution !== "agent" &&
1532+
attachments.length > 0 &&
1533+
isAttachmentOnlyBootstrapText(presentation.text);
15341534
const referenceIds = new Set(
15351535
collectComposerContextReferences(message.text).map((reference) => reference.contextId),
15361536
);
@@ -1658,7 +1658,7 @@ function renderFeedEntry(
16581658
{attachmentOnly ? (
16591659
<AttachmentOnlyCaption
16601660
label={attachments.every(isImageAttachment) ? "Image only" : "Attachment only"}
1661-
instruction={message.text.trim()}
1661+
instruction={presentation.text}
16621662
/>
16631663
) : null}
16641664
{message.text.trim().length > 0 && !attachmentOnly ? (
@@ -1881,7 +1881,6 @@ type UserMessageContentProps = {
18811881
readonly renderImage: MarkdownImageRenderer;
18821882
};
18831883

1884-
/** Sent with no text: a quiet caption stands in for the agent's bootstrap prompt, and a tap reveals it. */
18851884
function AttachmentOnlyCaption(props: { readonly label: string; readonly instruction: string }) {
18861885
const [expanded, setExpanded] = useState(false);
18871886
return (

‎apps/web/src/components/chat/MessagesTimeline.browser.test.tsx‎

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,33 @@ describe("MessagesTimeline attachment-only messages", () => {
495495
expect(screen.buttons("Image only")).toHaveLength(0);
496496
});
497497

498+
it("keeps literal bootstrap text visible without attachments", async () => {
499+
setup();
500+
await using screen = await renderTimeline([message(ATTACHMENT_ONLY_BOOTSTRAP_PROMPT)]);
501+
expect(screen.text()).toContain(ATTACHMENT_ONLY_BOOTSTRAP_PROMPT);
502+
expect(screen.buttons("Image only")).toHaveLength(0);
503+
expect(screen.buttons(/^Copy message$/i)).toHaveLength(1);
504+
});
505+
506+
it("labels audio-only messages as attachment only", async () => {
507+
setup();
508+
await using screen = await renderTimeline([
509+
message(ATTACHMENT_ONLY_BOOTSTRAP_PROMPT, {
510+
attachments: [
511+
{
512+
type: "file",
513+
id: ChatAttachmentId.make("attachment-audio"),
514+
name: "voice.wav",
515+
mimeType: "audio/wav",
516+
sizeBytes: 1024,
517+
},
518+
],
519+
}),
520+
]);
521+
expect(screen.buttons("Attachment only")).toHaveLength(1);
522+
expect(screen.buttons("Image only")).toHaveLength(0);
523+
});
524+
498525
it("leaves a photo-only message from another agent as a folded message", async () => {
499526
setup();
500527
await using screen = await renderTimeline([
@@ -517,7 +544,7 @@ describe("MessagesTimeline attachment-only messages", () => {
517544
attachments: [photo],
518545
}),
519546
]);
520-
expect(screen.text()).not.toContain("Sent without text");
547+
expect(screen.buttons("Image only")).toHaveLength(0);
521548
expect(screen.text()).toContain("Also check the colors.");
522549
});
523550
});

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,10 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
317317
const resolvedContext = resolveUserMessageContext(
318318
userMessage.attribution === "guest" ? { ...row.message, text: userMessage.text } : row.message,
319319
);
320-
const attachmentOnly = !folded && isAttachmentOnlyBootstrapText(resolvedContext.text);
320+
const attachmentOnly =
321+
!folded &&
322+
(row.message.attachments?.length ?? 0) > 0 &&
323+
isAttachmentOnlyBootstrapText(resolvedContext.text);
321324
const bodyText = attachmentOnly ? "" : resolvedContext.text;
322325
const previewImages = userImages.filter((image) => image.name.startsWith("preview-annotation-"));
323326
const revertTurnCount = row.revertTurnCount;
@@ -488,11 +491,8 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
488491
<div
489492
className={cn(
490493
"mb-2 grid gap-2",
491-
// A lone photo sent without text fills its bubble instead of leaving half of it empty.
492-
// It sits at the bubble's right edge so opening the caption grows the bubble leftward
493-
// without moving the photo.
494494
attachmentOnly && regularImages.length + userVideos.length === 1
495-
? "ms-auto max-w-[240px] grid-cols-1"
495+
? "ms-auto w-[240px] max-w-full grid-cols-1"
496496
: "max-w-[210px] grid-cols-2",
497497
)}
498498
>
@@ -626,9 +626,9 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
626626
{attachmentOnly ? (
627627
<AttachmentOnlyCaption
628628
label={
629-
userVideos.length + unchippedFiles.length + unknownAttachments.length > 0
630-
? "Attachment only"
631-
: "Image only"
629+
row.message.attachments?.every(isImageAttachment)
630+
? "Image only"
631+
: "Attachment only"
632632
}
633633
instruction={resolvedContext.text}
634634
/>
@@ -695,7 +695,6 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
695695
);
696696
}
697697

698-
/** Sent with no text: a quiet caption stands in for the agent's bootstrap prompt, and a click reveals it. */
699698
function AttachmentOnlyCaption({
700699
label,
701700
instruction,
@@ -705,7 +704,7 @@ function AttachmentOnlyCaption({
705704
}) {
706705
const [expanded, setExpanded] = useState(false);
707706
return (
708-
<div className="text-xs text-muted-foreground" data-user-message-attachment-only="true">
707+
<div className="text-xs text-muted-foreground">
709708
<button
710709
type="button"
711710
aria-expanded={expanded}

‎packages/shared/src/composerContextReferences.ts‎

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

120-
/**
121-
* True when a stored user message is only the bootstrap prompt T3 Code sends in place of
122-
* empty text. Clients hide that prompt in the chat and show a status line instead; the
123-
* message itself, and what the agent received, stay untouched.
124-
*/
125120
export function isAttachmentOnlyBootstrapText(text: string): boolean {
126121
return text.trim() === ATTACHMENT_ONLY_BOOTSTRAP_PROMPT;
127122
}

0 commit comments

Comments
 (0)