Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

messageImageGallery.ts

26 lines1.2 KB

1import type { ChatAttachment, EnvironmentId, ThreadId } from "@t3tools/contracts";
2import { imageMimeType } from "@t3tools/shared/image";
3import type { FilePreviewItem } from "../../components/ui/FilePreviewModal.types";
4import { remoteAttachmentImageSource } from "../../lib/filePreviewGallery";
5import { markdownImageSources } from "../../lib/markdownImageSources";
6import { resolveMarkdownMediaPreview } from "../../lib/markdownMedia";
7​
8export function messageImageGallery(
9 message: { readonly text: string; readonly attachments?: readonly ChatAttachment[] },
10 context: {
11 environmentId: EnvironmentId;
12 threadId: ThreadId;
13 workspaceRoot: string | null | undefined;
14 },
15): FilePreviewItem[] {
16 const images: FilePreviewItem[] = [];
17 for (const attachment of message.attachments ?? []) {
18 if (attachment.type !== "image" && imageMimeType(attachment) === null) continue;
19 images.push(remoteAttachmentImageSource(context.environmentId, attachment.id, attachment));
20 }
21 for (const href of markdownImageSources(message.text)) {
22 const preview = resolveMarkdownMediaPreview(href, { ...context, imageEmbed: true });
23 if (preview?.kind === "image") images.push(preview.source);
24 }
25 return images;