Skip to content

Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.

fix(web): preview image attachments (#98)

Leo3247adaade42
diff --git a/apps/web/src/components/roster/BotMessageAttachments.test.tsx b/apps/web/src/components/roster/BotMessageAttachments.test.tsx
new file mode 100644
index 000000000..fa326f203
--- /dev/null
+++ b/apps/web/src/components/roster/BotMessageAttachments.test.tsx
@@ -0,0 +1,57 @@
+import type { ChatAttachment } from "@t3tools/contracts";
+import { describe, expect, it } from "vite-plus/test";
+
+import { buildBotMessageAttachmentPreview } from "./BotMessageAttachments";
+
+const attachments: ChatAttachment[] = [
+ {
+ type: "image",
+ id: "attachment-first",
+ name: "first.png",
+ mimeType: "image/png",
+ sizeBytes: 10,
+ },
+ {
+ type: "image",
+ id: "attachment-second",
+ name: "second.png",
+ mimeType: "image/png",
+ sizeBytes: 20,
+ },
+];
+
+describe("sent bot message attachments", () => {
+ it("preserves image order and opens the selected image", () => {
+ expect(
+ buildBotMessageAttachmentPreview(
+ attachments,
+ ["http://example.test/first", "http://example.test/second"],
+ "attachment-second",
+ ),
+ ).toEqual({
+ images: [
+ { src: "http://example.test/first", name: "first.png" },
+ { src: "http://example.test/second", name: "second.png" },
+ ],
+ index: 1,
+ });
+ });
+
+ it("excludes unresolved and failed images from the preview", () => {
+ expect(
+ buildBotMessageAttachmentPreview(
+ attachments,
+ [null, "http://example.test/second"],
+ "attachment-first",
+ ),
+ ).toBeNull();
+ expect(
+ buildBotMessageAttachmentPreview(
+ attachments,
+ ["http://example.test/first", "http://example.test/second"],
+ "attachment-second",
+ new Set(["attachment-second"]),
+ ),
+ ).toBeNull();
+ });
+});
diff --git a/apps/web/src/components/roster/BotMessageAttachments.tsx b/apps/web/src/components/roster/BotMessageAttachments.tsx
new file mode 100644
index 000000000..07e173dcc
--- /dev/null
+++ b/apps/web/src/components/roster/BotMessageAttachments.tsx
@@ -0,0 +1,87 @@
+import type { ChatAttachment, EnvironmentId } from "@t3tools/contracts";
+import { useMemo, useState } from "react";
+
+import { useAssetUrls } from "../../assets/assetUrls";
+import { ExpandedImageDialog } from "../chat/ExpandedImageDialog";
+import { buildExpandedImagePreview, type ExpandedImagePreview } from "../chat/ExpandedImagePreview";
+
+export function buildBotMessageAttachmentPreview(
+ attachments: ReadonlyArray<ChatAttachment>,
+ urls: ReadonlyArray<string | null>,
+ selectedAttachmentId: string,
+ failedIds: ReadonlySet<string> = new Set(),
+): ExpandedImagePreview | null {
+ return buildExpandedImagePreview(
+ attachments.map((attachment, index) => ({
+ id: attachment.id,
+ name: attachment.name,
+ ...(urls[index] && !failedIds.has(attachment.id) ? { previewUrl: urls[index] } : {}),
+ })),
+ selectedAttachmentId,
+ );
+}
+
+export function BotMessageAttachments({
+ attachments,
+ environmentId,
+}: {
+ readonly attachments: ReadonlyArray<ChatAttachment>;
+ readonly environmentId: EnvironmentId;
+}) {
+ const resources = useMemo(
+ () =>
+ attachments.map((attachment) => ({
+ _tag: "attachment" as const,
+ attachmentId: attachment.id,
+ })),
+ [attachments],
+ );
+ const urls = useAssetUrls(environmentId, resources);
+ const [failedIds, setFailedIds] = useState<ReadonlySet<string>>(() => new Set());
+ const [preview, setPreview] = useState<ExpandedImagePreview | null>(null);
+ if (attachments.length === 0) return null;
+
+ return (
+ <>
+ <div className="grid max-w-[420px] grid-cols-1 gap-2 sm:grid-cols-2">
+ {attachments.map((attachment, index) => {
+ const url = urls[index];
+ const canPreview = url !== null && !failedIds.has(attachment.id);
+ return (
+ <div
+ key={attachment.id}
+ data-testid="bot-message-attachment"
+ className="aspect-[4/3] min-h-20 overflow-hidden rounded-lg border border-border/70 bg-background/45"
+ >
+ {canPreview ? (
+ <button
+ type="button"
+ aria-label={`Preview ${attachment.name}`}
+ className="size-full cursor-zoom-in focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset"
+ onClick={() =>
+ setPreview(
+ buildBotMessageAttachmentPreview(attachments, urls, attachment.id, failedIds),
+ )
+ }
+ >
+ <img
+ src={url}
+ alt={attachment.name}
+ className="size-full max-h-[220px] object-cover"
+ draggable={false}
+ onError={() => setFailedIds((current) => new Set(current).add(attachment.id))}
+ />
+ </button>
+ ) : (
+ <span className="flex size-full items-center justify-center text-xs text-muted-foreground">
+ Image unavailable
+ </span>
+ )}
+ </div>
+ );
+ })}
+ </div>
+ {preview ? <ExpandedImageDialog preview={preview} onClose={() => setPreview(null)} /> : null}
+ </>
+ );
+}
diff --git a/apps/web/src/components/roster/BotPromptAttachments.tsx b/apps/web/src/components/roster/BotPromptAttachments.tsx
new file mode 100644
index 000000000..92cb068b5
--- /dev/null
+++ b/apps/web/src/components/roster/BotPromptAttachments.tsx
@@ -0,0 +1,123 @@
+import { XIcon } from "lucide-react";
+
+import { cn } from "../../lib/utils";
+import { buildExpandedImagePreview, type ExpandedImagePreview } from "../chat/ExpandedImagePreview";
+
+/** A staged composer file plus the object URL that backs its live thumbnail. */
+export interface BotPromptAttachment {
+ readonly id: string;
+ readonly file: File;
+ readonly previewUrl: string | null;
+}
+
+let attachmentSequence = 0;
+
+/**
+ * Wraps picked files for the composer strip. Images get an object URL so the
+ * thumbnail renders before any upload starts; the caller owns releasing them.
+ */
+export function createBotPromptAttachments(files: readonly File[]): BotPromptAttachment[] {
+ return files.map((file) => {
+ attachmentSequence += 1;
+ return {
+ id: `bot-prompt-attachment-${attachmentSequence}`,
+ file,
+ previewUrl: file.type.startsWith("image/") ? URL.createObjectURL(file) : null,
+ };
+ });
+}
+
+/** Revokes every object URL held by the given attachments. */
+export function releaseBotPromptAttachments(attachments: readonly BotPromptAttachment[]): void {
+ for (const attachment of attachments) {
+ if (attachment.previewUrl !== null) {
+ URL.revokeObjectURL(attachment.previewUrl);
+ }
+ }
+}
+
+/** Builds the lightbox payload so expanding one thumbnail can page the rest. */
+export function buildBotPromptAttachmentPreview(
+ attachments: readonly BotPromptAttachment[],
+ attachmentId: string,
+ failedAttachmentIds: ReadonlySet<string> = new Set(),
+): ExpandedImagePreview | null {
+ return buildExpandedImagePreview(
+ attachments.map((attachment) => ({
+ id: attachment.id,
+ name: attachment.file.name,
+ ...(attachment.previewUrl !== null && !failedAttachmentIds.has(attachment.id)
+ ? { previewUrl: attachment.previewUrl }
+ : {}),
+ })),
+ attachmentId,
+ );
+}
+
+export function BotPromptAttachments({
+ attachments,
+ onExpand,
+ onPreviewError,
+ onRemove,
+ className,
+}: {
+ attachments: ReadonlyArray<BotPromptAttachment>;
+ onExpand: (attachmentId: string) => void;
+ onPreviewError: (attachmentId: string) => void;
+ onRemove: (attachmentId: string) => void;
+ className?: string;
+}) {
+ if (attachments.length === 0) return null;
+
+ return (
+ <div className={cn("flex flex-wrap gap-2", className)}>
+ {attachments.map((attachment) => (
+ <div
+ key={attachment.id}
+ data-testid="bot-prompt-attachment"
+ className="relative size-16 shrink-0 overflow-hidden rounded-lg border border-white/10 bg-background/65"
+ >
+ {attachment.previewUrl !== null ? (
+ <button
+ type="button"
+ aria-label={`Preview ${attachment.file.name}`}
+ className="size-full cursor-zoom-in"
+ onClick={() => onExpand(attachment.id)}
+ >
+ <img
+ src={attachment.previewUrl}
+ alt={attachment.file.name}
+ className="size-full object-cover"
+ draggable={false}
+ onError={(event) => {
+ onPreviewError(attachment.id);
+ event.currentTarget.hidden = true;
+ event.currentTarget.nextElementSibling?.removeAttribute("hidden");
+ event.currentTarget.closest("button")?.setAttribute("disabled", "");
+ }}
+ />
+ <span
+ hidden
+ className="flex size-full items-center justify-center break-all px-1 text-center text-[10px] leading-tight text-muted-foreground"
+ >
+ {attachment.file.name}
+ </span>
+ </button>
+ ) : (
+ <span className="flex size-full items-center justify-center break-all px-1 text-center text-[10px] leading-tight text-muted-foreground">
+ {attachment.file.name}
+ </span>
+ )}
+ <button
+ type="button"
+ aria-label={`Remove ${attachment.file.name}`}
+ onClick={() => onRemove(attachment.id)}
+ className="absolute right-1 top-1 flex size-5 items-center justify-center rounded-full bg-background/80 text-muted-foreground hover:bg-background hover:text-foreground"
+ >
+ <XIcon className="size-3" />
+ </button>
+ </div>
+ ))}
+ </div>
+ );
+}
diff --git a/apps/web/src/components/roster/BotPromptComposer.test.tsx b/apps/web/src/components/roster/BotPromptComposer.test.tsx
index 6eb9ad302..cce498462 100644
--- a/apps/web/src/components/roster/BotPromptComposer.test.tsx
+++ b/apps/web/src/components/roster/BotPromptComposer.test.tsx
@@ -1,8 +1,16 @@
import { renderToStaticMarkup } from "react-dom/server";
-import { describe, expect, it, vi } from "vite-plus/test";
+import { afterEach, describe, expect, it, vi } from "vite-plus/test";
import { deriveProviderInstanceEntries } from "../../providerInstances";
import { composerTestInstanceId, makeComposerTestProvider } from "../../test/chatComposerProps";
+import { visitElements } from "../../test/reactElementTree";
+import {
+ BotPromptAttachments,
+ buildBotPromptAttachmentPreview,
+ createBotPromptAttachments,
+ releaseBotPromptAttachments,
+ type BotPromptAttachment,
+} from "./BotPromptAttachments";
import {
BotPromptComposer,
canSubmitBotPrompt,
@@ -11,6 +19,14 @@ import {
shouldFocusBotPromptForKey,
} from "./BotPromptComposer";
+afterEach(() => {
+ vi.restoreAllMocks();
+});
+
+function imageFile(name: string): File {
+ return new File([name], name, { type: "image/png" });
+}
+
describe("bot prompt composer", () => {
it("does not submit while disabled", () => {
expect(canSubmitBotPrompt(true, "Send this", 0)).toBe(false);
@@ -89,4 +105,96 @@ describe("bot prompt composer", () => {
expect(markup).toContain('aria-label="Change model"');
expect(markup).toContain("data-chat-provider-model-picker");
});
+
+ it("creates stable previews in file order and releases their object URLs", () => {
+ const first = imageFile("same-name.png");
+ const second = imageFile("same-name.png");
+ const createObjectURL = vi
+ .spyOn(URL, "createObjectURL")
+ .mockReturnValueOnce("blob:first")
+ .mockReturnValueOnce("blob:second");
+ const revokeObjectURL = vi.spyOn(URL, "revokeObjectURL").mockImplementation(() => {});
+
+ const attachments = createBotPromptAttachments([first, second]);
+
+ expect(attachments.map((attachment) => attachment.file)).toEqual([first, second]);
+ expect(attachments[0]?.id).not.toBe(attachments[1]?.id);
+ expect(createObjectURL).toHaveBeenCalledTimes(2);
+ expect(buildBotPromptAttachmentPreview(attachments, attachments[1]!.id)).toEqual({
+ images: [
+ { src: "blob:first", name: "same-name.png" },
+ { src: "blob:second", name: "same-name.png" },
+ ],
+ index: 1,
+ });
+ expect(
+ buildBotPromptAttachmentPreview(
+ attachments,
+ attachments[1]!.id,
+ new Set([attachments[0]!.id]),
+ ),
+ ).toEqual({
+ images: [{ src: "blob:second", name: "same-name.png" }],
+ index: 0,
+ });
+
+ releaseBotPromptAttachments(attachments);
+ expect(revokeObjectURL.mock.calls).toEqual([["blob:first"], ["blob:second"]]);
+ });
+
+ it("renders a live thumbnail with independent preview and remove controls", () => {
+ const onExpand = vi.fn();
+ const onPreviewError = vi.fn();
+ const onRemove = vi.fn();
+ const attachment: BotPromptAttachment = {
+ id: "attachment-1",
+ file: imageFile("preview.png"),
+ previewUrl: "blob:preview",
+ };
+ const tree = BotPromptAttachments({
+ attachments: [attachment],
+ onExpand,
+ onPreviewError,
+ onRemove,
+ });
+ const markup = renderToStaticMarkup(tree);
+ const preview = visitElements(
+ tree,
+ (element) => element.props["aria-label"] === "Preview preview.png",
+ );
+ const remove = visitElements(
+ tree,
+ (element) => element.props["aria-label"] === "Remove preview.png",
+ );
+ const image = visitElements(tree, (element) => element.props.alt === "preview.png");
+
+ expect(markup).toContain('src="blob:preview"');
+ expect(markup).toContain('alt="preview.png"');
+ expect(markup).not.toContain("PaperclipIcon");
+
+ (preview?.props.onClick as (() => void) | undefined)?.();
+ expect(onExpand).toHaveBeenCalledOnce();
+ expect(onExpand).toHaveBeenCalledWith("attachment-1");
+ expect(onRemove).not.toHaveBeenCalled();
+
+ (remove?.props.onClick as (() => void) | undefined)?.();
+ expect(onRemove).toHaveBeenCalledOnce();
+ expect(onRemove).toHaveBeenCalledWith("attachment-1");
+ expect(onExpand).toHaveBeenCalledOnce();
+
+ const removeAttribute = vi.fn();
+ const setAttribute = vi.fn();
+ const currentTarget = {
+ hidden: false,
+ nextElementSibling: { removeAttribute },
+ closest: () => ({ setAttribute }),
+ };
+ (
+ image?.props.onError as ((event: { currentTarget: typeof currentTarget }) => void) | undefined
+ )?.({ currentTarget });
+ expect(currentTarget.hidden).toBe(true);
+ expect(onPreviewError).toHaveBeenCalledWith("attachment-1");
+ expect(removeAttribute).toHaveBeenCalledWith("hidden");
+ expect(setAttribute).toHaveBeenCalledWith("disabled", "");
+ });
});
diff --git a/apps/web/src/components/roster/BotPromptComposer.tsx b/apps/web/src/components/roster/BotPromptComposer.tsx
index 35cb54803..97250dfab 100644
--- a/apps/web/src/components/roster/BotPromptComposer.tsx
+++ b/apps/web/src/components/roster/BotPromptComposer.tsx
@@ -1,10 +1,18 @@
-import { ArrowUpIcon, AtSignIcon, PaperclipIcon, PlusIcon, XIcon } from "lucide-react";
+import { ArrowUpIcon, AtSignIcon, PaperclipIcon, PlusIcon } from "lucide-react";
import { type ComponentProps, useEffect, useRef, useState } from "react";
import { cn } from "../../lib/utils";
+import { ExpandedImageDialog } from "../chat/ExpandedImageDialog";
import { Menu, MenuItem, MenuPopup, MenuTrigger } from "../ui/menu";
import { clearBotDraft, readBotDraft, writeBotDraft } from "./botDraftStore";
import { BotModelPicker } from "./BotModelPicker";
+import {
+ BotPromptAttachments,
+ buildBotPromptAttachmentPreview,
+ createBotPromptAttachments,
+ releaseBotPromptAttachments,
+ type BotPromptAttachment,
+} from "./BotPromptAttachments";
type BotModelPickerProps = Pick<
ComponentProps<typeof BotModelPicker>,
@@ -79,9 +87,28 @@ export function BotPromptComposer({
onSubmit: (prompt: string, files: readonly File[], respondingBotId?: string) => Promise<boolean>;
}) {
const [draft, setDraft] = useState(() => (draftKey ? readBotDraft(draftKey) : ""));
- const [files, setFiles] = useState<File[]>([]);
+ const [attachments, setAttachments] = useState<BotPromptAttachment[]>([]);
+ const [failedAttachmentIds, setFailedAttachmentIds] = useState<ReadonlySet<string>>(
+ () => new Set(),
+ );
+ const [expandedAttachmentId, setExpandedAttachmentId] = useState<string | null>(null);
+ const attachmentsRef = useRef<BotPromptAttachment[]>([]);
+ const releasedPreviewUrlsRef = useRef(new Set<string>());
const fileInputRef = useRef<HTMLInputElement>(null);
const promptInputRef = useRef<HTMLTextAreaElement>(null);
+ const releaseAttachments = (items: readonly BotPromptAttachment[]) => {
+ const unreleased = items.filter((attachment) => {
+ if (
+ attachment.previewUrl === null ||
+ releasedPreviewUrlsRef.current.has(attachment.previewUrl)
+ ) {
+ return false;
+ }
+ releasedPreviewUrlsRef.current.add(attachment.previewUrl);
+ return true;
+ });
+ releaseBotPromptAttachments(unreleased);
+ };
const persistDraft = (next: string) => {
setDraft(next);
if (draftKey) writeBotDraft(draftKey, next);
@@ -92,9 +119,42 @@ export function BotPromptComposer({
useEffect(() => {
setDraft(draftKey ? readBotDraft(draftKey) : "");
}, [draftKey]);
- const expanded = modelPicker !== null || files.length > 0 || isBotPromptExpanded(draft);
- const addFiles = (next: FileList | readonly File[]) =>
- setFiles((current) => [...current, ...Array.from(next)]);
+ useEffect(
+ () => () => {
+ releaseAttachments(attachmentsRef.current);
+ attachmentsRef.current = [];
+ },
+ [],
+ );
+
+ const expanded = modelPicker !== null || attachments.length > 0 || isBotPromptExpanded(draft);
+ const addFiles = (next: FileList | readonly File[]) => {
+ const added = createBotPromptAttachments(Array.from(next));
+ const updated = [...attachmentsRef.current, ...added];
+ attachmentsRef.current = updated;
+ setAttachments(updated);
+ };
+ const removeAttachment = (attachmentId: string) => {
+ const removed = attachmentsRef.current.find((attachment) => attachment.id === attachmentId);
+ if (!removed) return;
+ const updated = attachmentsRef.current.filter((attachment) => attachment.id !== attachmentId);
+ attachmentsRef.current = updated;
+ setAttachments(updated);
+ setFailedAttachmentIds((current) => {
+ if (!current.has(attachmentId)) return current;
+ const next = new Set(current);
+ next.delete(attachmentId);
+ return next;
+ });
+ if (expandedAttachmentId === attachmentId) {
+ setExpandedAttachmentId(null);
+ }
+ releaseAttachments([removed]);
+ };
+ const expandedPreview =
+ expandedAttachmentId === null
+ ? null
+ : buildBotPromptAttachmentPreview(attachments, expandedAttachmentId, failedAttachmentIds);
useEffect(() => {
const onKeyDown = (event: KeyboardEvent) => {
@@ -134,14 +194,33 @@ export function BotPromptComposer({
onSubmit={(event) => {
event.preventDefault();
const prompt = draft.trim();
- if (!canSubmitBotPrompt(disabled, prompt, files.length)) return;
- void onSubmit(prompt, files, findMentionedBotId(prompt, mentionBots)).then((sent) => {
- if (sent) {
+ const submittedAttachments = [...attachmentsRef.current];
+ if (!canSubmitBotPrompt(disabled, prompt, submittedAttachments.length)) return;
+ const submittedIds = new Set(submittedAttachments.map((attachment) => attachment.id));
+ void onSubmit(
+ prompt,
+ submittedAttachments.map((attachment) => attachment.file),
+ findMentionedBotId(prompt, mentionBots),
+ ).then(
+ (sent) => {
+ if (!sent) return;
persistDraft("");
if (draftKey) clearBotDraft(draftKey);
- setFiles([]);
- }
- });
+ const remaining = attachmentsRef.current.filter(
+ (attachment) => !submittedIds.has(attachment.id),
+ );
+ attachmentsRef.current = remaining;
+ setAttachments(remaining);
+ setFailedAttachmentIds(
+ (current) => new Set([...current].filter((id) => !submittedIds.has(id))),
+ );
+ if (expandedAttachmentId && submittedIds.has(expandedAttachmentId)) {
+ setExpandedAttachmentId(null);
+ }
+ releaseAttachments(submittedAttachments);
+ },
+ () => undefined,
+ );
}}
>
<div
@@ -152,27 +231,16 @@ export function BotPromptComposer({
expanded && "min-h-28",
)}
>
- {files.length > 0 ? (
- <div className="flex flex-wrap gap-1.5 px-3 pt-3">
- {files.map((file, index) => (
- <span
- key={`${file.name}:${file.size}:${file.lastModified}`}
- className="flex max-w-48 items-center gap-1.5 rounded-full bg-background/65 py-1 pe-1 ps-2.5 text-xs"
- >
- <PaperclipIcon className="size-3" />
- <span className="truncate">{file.name}</span>
- <button
- type="button"
- aria-label={`Remove ${file.name}`}
- onClick={() => setFiles((current) => current.filter((_, item) => item !== index))}
- className="flex size-5 items-center justify-center rounded-full text-muted-foreground hover:bg-foreground/10"
- >
- <XIcon className="size-3" />
- </button>
- </span>
- ))}
- </div>
- ) : null}
+ <BotPromptAttachments
+ attachments={attachments}
+ className="px-3 pt-3"
+ onExpand={setExpandedAttachmentId}
+ onPreviewError={(attachmentId) => {
+ setFailedAttachmentIds((current) => new Set(current).add(attachmentId));
+ if (expandedAttachmentId === attachmentId) setExpandedAttachmentId(null);
+ }}
+ onRemove={removeAttachment}
+ />
<textarea
ref={promptInputRef}
aria-label={`Message ${botName}`}
@@ -249,7 +317,7 @@ export function BotPromptComposer({
<button
type="submit"
aria-label="Send message"
- disabled={!canSubmitBotPrompt(disabled, draft, files.length)}
+ disabled={!canSubmitBotPrompt(disabled, draft, attachments.length)}
className="pointer-events-auto flex size-9 items-center justify-center rounded-full bg-foreground text-background disabled:opacity-25"
>
<ArrowUpIcon className="size-5" />
@@ -267,6 +335,13 @@ export function BotPromptComposer({
event.currentTarget.value = "";
}}
/>
+ {expandedPreview ? (
+ <ExpandedImageDialog
+ key={`${expandedAttachmentId}:${attachments.map((attachment) => attachment.id).join(":")}`}
+ preview={expandedPreview}
+ onClose={() => setExpandedAttachmentId(null)}
+ />
+ ) : null}
</form>
);
}
diff --git a/apps/web/src/components/roster/BotThreadLanding.tsx b/apps/web/src/components/roster/BotThreadLanding.tsx
index 564f6f77d..86863fb79 100644
--- a/apps/web/src/components/roster/BotThreadLanding.tsx
+++ b/apps/web/src/components/roster/BotThreadLanding.tsx
@@ -35,6 +35,7 @@ import { DelegationCard } from "./DelegationCard";
import { visibleBotChatMessages } from "./botConversationPresentation";
import { resolveStickyBotEngine } from "./botEngineSelection";
import { BotPromptComposer } from "./BotPromptComposer";
+import { BotMessageAttachments } from "./BotMessageAttachments";
import { BotStepMeter } from "./BotStepMeter";
import { buildBotStepMeters } from "./botStepMeter.logic";
import { ThreadErrorBanner } from "../chat/ThreadErrorBanner";
@@ -186,17 +187,13 @@ export function BotThreadLanding({ botId }: { readonly botId: string }) {
) : (
<div key={message.id} className="flex justify-end" data-testid="bot-user-message">
<div className="max-w-[78%] rounded-2xl bg-foreground/10 px-3.5 py-2 text-sm leading-6">
- <p className="whitespace-pre-wrap">{message.text}</p>
+ {message.text ? <p className="whitespace-pre-wrap">{message.text}</p> : null}
{message.attachments?.length ? (
- <div className="mt-1.5 flex flex-wrap justify-end gap-1.5">
- {message.attachments.map((attachment) => (
- <span
- key={attachment.id}
- className="rounded-full bg-background/60 px-2 py-0.5 text-xs text-muted-foreground"
- >
- {attachment.name}
- </span>
- ))}
+ <div className={message.text ? "mt-2" : undefined}>
+ <BotMessageAttachments
+ attachments={message.attachments}
+ environmentId={environmentId ?? NO_ENVIRONMENT}
+ />
</div>
) : null}
</div>
diff --git a/apps/web/src/components/roster/GroupThreadLanding.tsx b/apps/web/src/components/roster/GroupThreadLanding.tsx
index 082d669a9..1ce1c7876 100644
--- a/apps/web/src/components/roster/GroupThreadLanding.tsx
+++ b/apps/web/src/components/roster/GroupThreadLanding.tsx
@@ -22,6 +22,7 @@ import { BotConversationScrollArea } from "./BotConversationScrollArea";
import { DelegationCard } from "./DelegationCard";
import { visibleBotChatMessages } from "./botConversationPresentation";
import { BotPromptComposer } from "./BotPromptComposer";
+import { BotMessageAttachments } from "./BotMessageAttachments";
import { BotStepMeter } from "./BotStepMeter";
import { buildBotStepMeters } from "./botStepMeter.logic";
import { useGroupPresence } from "./botPresence";
@@ -143,7 +144,15 @@ export function GroupThreadLanding({ groupId }: { readonly groupId: string }) {
return (
<div key={message.id} className="flex justify-end" data-testid="group-user-message">
<div className="max-w-[78%] rounded-2xl bg-foreground/10 px-3.5 py-2 text-sm leading-6">
- <p className="whitespace-pre-wrap">{message.text}</p>
+ {message.text ? <p className="whitespace-pre-wrap">{message.text}</p> : null}
+ {message.attachments?.length ? (
+ <div className={message.text ? "mt-2" : undefined}>
+ <BotMessageAttachments
+ attachments={message.attachments}
+ environmentId={environmentId ?? NO_ENVIRONMENT}
+ />
+ </div>
+ ) : null}
</div>
</div>
);