Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
chore(agents): open agent-session images in the channel lightbox (#6639)
Wolf Mermelstein0a7313828267
diff --git a/apps/web/src/features/block-agent/component/parts/AttachmentPart.test.tsx b/apps/web/src/features/block-agent/component/parts/AttachmentPart.test.tsxindex a9fcec1399..603a7668bf 100644--- a/apps/web/src/features/block-agent/component/parts/AttachmentPart.test.tsx+++ b/apps/web/src/features/block-agent/component/parts/AttachmentPart.test.tsx@@ -2,11 +2,12 @@* @vitest-environment jsdom** What an attached file renders as is decided by its media type: images and- * videos as media, everything else as a chip that opens the file.+ * videos as media that open the channel lightbox, everything else as a chip+ * that opens the file.*/import type { MessagePart } from '@service-agent-fold/generated/types';-import { render } from '@solidjs/testing-library';+import { fireEvent, render } from '@solidjs/testing-library';import { describe, expect, it, vi } from 'vitest';import { AttachmentPart, attachmentMedium } from './AttachmentPart';@@ -32,6 +33,16 @@ vi.mock('@channel/Media/MediaVideo', () => ({PlayOverlay: () => null,},}));+vi.mock('@channel/Media/MediaViewerDialog', () => ({+ MediaViewerDialog: (props: {+ items: () => { id: string; fullSrc: string; kind: string }[];+ open: boolean;+ }) => (+ <div data-open={String(props.open)} data-testid="media-viewer">+ {props.items()[0]?.kind}:{props.items()[0]?.fullSrc}+ </div>+ ),+}));// The block registry eagerly imports every block's definition, which drags// the chat input's storage module into jsdom; the extension-to-icon mapping// is all this component needs from it.@@ -84,8 +95,8 @@ describe('attachmentMedium', () => {});describe('AttachmentPart', () => {- it('renders an image as a sized thumbnail linking to the original', () => {- const { getByTestId, container } = render(() => (+ it('renders an image as a sized thumbnail that opens the media viewer', () => {+ const { getByLabelText, getByTestId, container } = render(() => (<AttachmentPartpart={attachment({ name: 'shot.png', mimeType: 'image/png' })}/>@@ -93,13 +104,18 @@ describe('AttachmentPart', () => {expect(getByTestId('media-image').getAttribute('src')).toBe('https://static.example/file/1?size=1080');- expect(container.querySelector('a')?.getAttribute('href')).toBe(- 'https://static.example/file/1'+ expect(container.querySelector('a')).toBeNull();+ expect(getByTestId('media-viewer').getAttribute('data-open')).toBe('false');++ fireEvent.click(getByLabelText('Open image viewer'));+ expect(getByTestId('media-viewer').getAttribute('data-open')).toBe('true');+ expect(getByTestId('media-viewer').textContent).toBe(+ 'image:https://static.example/file/1');});- it('renders a video as a preview', () => {- const { getByTestId } = render(() => (+ it('renders a video as a preview that opens the media viewer', () => {+ const { getByLabelText, getByTestId, container } = render(() => (<AttachmentPartpart={attachment({ name: 'clip.mp4', mimeType: 'video/mp4' })}/>@@ -107,6 +123,14 @@ describe('AttachmentPart', () => {expect(getByTestId('media-video').getAttribute('src')).toBe('https://static.example/file/1');+ expect(container.querySelector('a')).toBeNull();+ expect(getByTestId('media-viewer').getAttribute('data-open')).toBe('false');++ fireEvent.click(getByLabelText('Open video viewer'));+ expect(getByTestId('media-viewer').getAttribute('data-open')).toBe('true');+ expect(getByTestId('media-viewer').textContent).toBe(+ 'video:https://static.example/file/1'+ );});it('renders anything else as a named chip that opens the file', () => {diff --git a/apps/web/src/features/block-agent/component/parts/AttachmentPart.tsx b/apps/web/src/features/block-agent/component/parts/AttachmentPart.tsxindex 1710ebba8f..6fd3d0f2a6 100644--- a/apps/web/src/features/block-agent/component/parts/AttachmentPart.tsx+++ b/apps/web/src/features/block-agent/component/parts/AttachmentPart.tsx@@ -1,18 +1,20 @@/*** A file the user attached to their prompt. Images and videos render as the- * channel composer's media thumbnails; anything else is a chip that opens- * the file. The fold hands over a URL, never bytes, so this is a plain- * fetch from the static file service.+ * channel composer's media thumbnails and open the same lightbox; anything+ * else is a chip that opens the file. The fold hands over a URL, never bytes,+ * so this is a plain fetch from the static file service.*/import { getAttachmentKindFromFile } from '@channel/Input/utils/file-helpers';import { MediaImage } from '@channel/Media/MediaImage';import { MediaVideo } from '@channel/Media/MediaVideo';+import { MediaViewerDialog } from '@channel/Media/MediaViewerDialog';+import type { MediaItem } from '@channel/Media/media-items';import { EntityIcon } from '@core/component/EntityIcon';import { fileTypeToBlockName } from '@core/constant/allBlocks';import { staticFileSizedUrl } from '@core/constant/servers';import type { MessagePart } from '@service-agent-fold/generated/types';-import { Match, Switch } from 'solid-js';+import { createSignal, Match, Show, Switch } from 'solid-js';type AttachmentPartData = Extract<MessagePart, { kind: 'attachment' }>;@@ -40,14 +42,47 @@ function fileExtension(name: string): string | undefined {return extension;}+/** Last path segment of a static-file URL — the lightbox download name. */+function staticFileIdFromUri(uri: string): string {+ try {+ const last = new URL(uri).pathname.split('/').filter(Boolean).at(-1);+ return last ?? uri;+ } catch {+ return uri;+ }+}++function mediaItemFromAttachment(+ part: AttachmentPartData+): MediaItem | undefined {+ const kind = attachmentMedium(part);+ if (kind !== 'image' && kind !== 'video') return undefined;+ return {+ id: staticFileIdFromUri(part.uri),+ src: kind === 'image' ? staticFileSizedUrl(part.uri, 'medium') : part.uri,+ fullSrc: part.uri,+ kind,+ };+}+export function AttachmentPart(props: { part: AttachmentPartData }) {const medium = () => attachmentMedium(props.part);+ const [viewerOpen, setViewerOpen] = createSignal(false);+ const mediaItems = () => {+ const item = mediaItemFromAttachment(props.part);+ return item ? [item] : [];+ };+ const openViewer = () => setViewerOpen(true);return (<div class="ph-no-capture my-1 first:mt-0 last:mb-0" data-attachment-part><Switch><Match when={medium() === 'image'}>- <a href={props.part.uri} target="_blank" rel="noreferrer">+ <button+ type="button"+ aria-label="Open image viewer"+ onClick={openViewer}+ ><MediaImage.Root><MediaImage.Imagesrc={staticFileSizedUrl(props.part.uri, 'medium')}@@ -56,10 +91,14 @@ export function AttachmentPart(props: { part: AttachmentPartData }) {fallback={<MediaImage.Fallback square />}/></MediaImage.Root>- </a>+ </button></Match><Match when={medium() === 'video'}>- <a href={props.part.uri} target="_blank" rel="noreferrer">+ <button+ type="button"+ aria-label="Open video viewer"+ onClick={openViewer}+ ><MediaVideo.Root class="group max-h-64 overflow-hidden border border-edge bg-surface"><MediaVideo.Previewsrc={props.part.uri}@@ -67,7 +106,7 @@ export function AttachmentPart(props: { part: AttachmentPartData }) {/><MediaVideo.PlayOverlay /></MediaVideo.Root>- </a>+ </button></Match><Match when={medium() === 'file'}><a@@ -88,6 +127,15 @@ export function AttachmentPart(props: { part: AttachmentPartData }) {</a></Match></Switch>+ <Show when={mediaItems().length > 0}>+ <MediaViewerDialog+ items={mediaItems}+ open={viewerOpen()}+ onOpenChange={setViewerOpen}+ currentIndex={() => 0}+ onCurrentIndexChange={() => {}}+ />+ </Show></div>);}diff --git a/docs/AGENT_GUIDE/ai-chat.md b/docs/AGENT_GUIDE/ai-chat.mdindex 8580e1ade8..857723563c 100644--- a/docs/AGENT_GUIDE/ai-chat.md+++ b/docs/AGENT_GUIDE/ai-chat.md@@ -322,8 +322,9 @@ clipboard, or use the paperclip **`Attach files`** button. Every file uploads tostatic file service and shows as a chip above the text (media thumbnails, documentpills with a remove `×`); **Send** is disabled while an upload is pending. The agentreceives each file as an ACP `resource_link` (a URL it can fetch) after the prompt text,-and the sent prompt renders its files in the transcript (image thumbnails, video-previews, file chips that open the file). A prompt may be files only, including the+and the sent prompt renders its files in the transcript (image thumbnails and+video previews that open the same lightbox as channel media; file chips that+open the file). A prompt may be files only, including thefirst message in a new conversation. Uploading attachments survive switching theagent or opening repository settings; sending clears the attachment previews.Queued prompts