move isBase64ContentBlock to multimodal-utils.ts
This commit is contained in:
@@ -6,7 +6,7 @@ import { cn } from "@/lib/utils";
|
|||||||
import { Textarea } from "@/components/ui/textarea";
|
import { Textarea } from "@/components/ui/textarea";
|
||||||
import { BranchSwitcher, CommandBar } from "./shared";
|
import { BranchSwitcher, CommandBar } from "./shared";
|
||||||
import { MultimodalPreview } from "@/components/thread/MultimodalPreview";
|
import { MultimodalPreview } from "@/components/thread/MultimodalPreview";
|
||||||
import type { Base64ContentBlock } from "@langchain/core/messages";
|
import { isBase64ContentBlock } from "@/lib/multimodal-utils";
|
||||||
|
|
||||||
function EditableContent({
|
function EditableContent({
|
||||||
value,
|
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({
|
export function HumanMessage({
|
||||||
message,
|
message,
|
||||||
isLoading,
|
isLoading,
|
||||||
|
|||||||
@@ -55,3 +55,35 @@ export async function fileToBase64(file: File): Promise<string> {
|
|||||||
reader.readAsDataURL(file);
|
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;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user