import type { AttachmentAdapter } from "@assistant-ui/core"; import { generateId } from "ai"; const getFileDataURL = (file: File) => new Promise((resolve, reject) => { const reader = new FileReader(); reader.onload = () => resolve(reader.result as string); reader.onerror = (error) => reject(error); reader.readAsDataURL(file); }); export const vercelAttachmentAdapter: AttachmentAdapter = { accept: "*", async add({ file }) { return { id: generateId(), type: file.type.startsWith("image/") ? "image" : "file", name: file.name, file, contentType: file.type, content: [], status: { type: "requires-action", reason: "composer-send" }, }; }, async send(attachment) { // noop return { ...attachment, status: { type: "complete" }, content: [ { type: "file", mimeType: attachment.contentType ?? "", filename: attachment.name, data: await getFileDataURL(attachment.file), }, ], }; }, async remove() { // noop }, };