diff --git a/src/components/thread/messages/human.tsx b/src/components/thread/messages/human.tsx index 8aa019f..2769721 100644 --- a/src/components/thread/messages/human.tsx +++ b/src/components/thread/messages/human.tsx @@ -6,7 +6,7 @@ import { cn } from "@/lib/utils"; import { Textarea } from "@/components/ui/textarea"; import { BranchSwitcher, CommandBar } from "./shared"; import { MultimodalPreview } from "@/components/thread/MultimodalPreview"; -import type { Base64ContentBlock } from "@langchain/core/messages"; +import { isBase64ContentBlock } from "@/lib/multimodal-utils"; function EditableContent({ value, @@ -34,36 +34,6 @@ function EditableContent({ ); } -// Type guard for Base64ContentBlock -function isBase64ContentBlock(block: unknown): block is Base64ContentBlock { - if (typeof block !== "object" || block === null || !("type" in block)) - return false; - // file type (legacy) - if ( - (block as { type: unknown }).type === "file" && - "source_type" in block && - (block as { source_type: unknown }).source_type === "base64" && - "mime_type" in block && - typeof (block as { mime_type?: unknown }).mime_type === "string" && - ((block as { mime_type: string }).mime_type.startsWith("image/") || - (block as { mime_type: string }).mime_type === "application/pdf") - ) { - return true; - } - // image type (new) - if ( - (block as { type: unknown }).type === "image" && - "source_type" in block && - (block as { source_type: unknown }).source_type === "base64" && - "mime_type" in block && - typeof (block as { mime_type?: unknown }).mime_type === "string" && - (block as { mime_type: string }).mime_type.startsWith("image/") - ) { - return true; - } - return false; -} - export function HumanMessage({ message, isLoading, diff --git a/src/lib/multimodal-utils.ts b/src/lib/multimodal-utils.ts index 1ebfe44..e28cfb8 100644 --- a/src/lib/multimodal-utils.ts +++ b/src/lib/multimodal-utils.ts @@ -55,3 +55,35 @@ export async function fileToBase64(file: File): Promise { reader.readAsDataURL(file); }); } + +// Type guard for Base64ContentBlock +export function isBase64ContentBlock( + block: unknown, +): block is Base64ContentBlock { + if (typeof block !== "object" || block === null || !("type" in block)) + return false; + // file type (legacy) + if ( + (block as { type: unknown }).type === "file" && + "source_type" in block && + (block as { source_type: unknown }).source_type === "base64" && + "mime_type" in block && + typeof (block as { mime_type?: unknown }).mime_type === "string" && + ((block as { mime_type: string }).mime_type.startsWith("image/") || + (block as { mime_type: string }).mime_type === "application/pdf") + ) { + return true; + } + // image type (new) + if ( + (block as { type: unknown }).type === "image" && + "source_type" in block && + (block as { source_type: unknown }).source_type === "base64" && + "mime_type" in block && + typeof (block as { mime_type?: unknown }).mime_type === "string" && + (block as { mime_type: string }).mime_type.startsWith("image/") + ) { + return true; + } + return false; +}