Forked from vadimfedenko/analyze-images
Forked from vadimfedenko/analyze-images
src / inlineImage.ts
import { ChatMessage, type FileHandle, type LMStudioClient } from "@lmstudio/sdk";
import { IMAGE_LIMIT } from "./attachmentIdentity";
// SDK uploads are owned by the client connection and expire on disconnect.
// Embed bytes in the serialized message so saved chats can survive restarts.
export function inlineImage(client: LMStudioClient, name: string, bytes: Buffer): FileHandle {
if (!bytes.length || bytes.length > IMAGE_LIMIT) throw new Error("Image exceeds inline attachment size limit.");
return ChatMessage.from({ role: "user", content: [{ type: "file", name,
identifier: `base64:${bytes.toString("base64")}`, sizeBytes: bytes.length, fileType: "image",
}] }).getFiles(client)[0];
}
src / inlineImage.ts
import { ChatMessage, type FileHandle, type LMStudioClient } from "@lmstudio/sdk";
import { IMAGE_LIMIT } from "./attachmentIdentity";
// SDK uploads are owned by the client connection and expire on disconnect.
// Embed bytes in the serialized message so saved chats can survive restarts.
export function inlineImage(client: LMStudioClient, name: string, bytes: Buffer): FileHandle {
if (!bytes.length || bytes.length > IMAGE_LIMIT) throw new Error("Image exceeds inline attachment size limit.");
return ChatMessage.from({ role: "user", content: [{ type: "file", name,
identifier: `base64:${bytes.toString("base64")}`, sizeBytes: bytes.length, fileType: "image",
}] }).getFiles(client)[0];
}