@juspay/neurolink
Version:
Universal AI Development Platform with working MCP integration, multi-provider support, voice (TTS/STT/realtime), and professional CLI. 58+ external MCP servers discoverable, multimodal file processing, RAG pipelines. Build, test, and deploy AI applicatio
136 lines • 3.98 kB
JavaScript
/**
* Multimodal Content Types for NeuroLink
*
* Central registry for all multimodal input/output types.
* This file consolidates types from content.ts and conversation.ts
* to provide a single source of truth for multimodal functionality.
*
* @module types/multimodal
*
* @example Basic Multimodal Input
* ```typescript
* import type { MultimodalInput } from './types/multimodal.js';
*
* const input: MultimodalInput = {
* text: "What's in this image?",
* images: [imageBuffer, "https://example.com/image.jpg"],
* pdfFiles: [pdfBuffer]
* };
* ```
*
* @example Audio/Video Input (Future)
* ```typescript
* const avInput: MultimodalInput = {
* text: "Transcribe this audio and analyze this video",
* audioFiles: [audioBuffer],
* videoFiles: ["path/to/video.mp4"]
* };
* ```
*
* @example Advanced Content Array
* ```typescript
* const advanced: MultimodalInput = {
* text: "irrelevant", // ignored when content[] is provided
* content: [
* { type: "text", text: "Analyze these items:" },
* { type: "image", data: imageBuffer, mediaType: "image/jpeg" },
* { type: "pdf", data: pdfBuffer, metadata: { filename: "report.pdf" } }
* ]
* };
* ```
*/
// ============================================
// TYPE GUARDS
// ============================================
/**
* Type guard to check if content is TextContent
*/
export function isTextContent(content) {
return content.type === "text";
}
/**
* Type guard to check if content is ImageContent
*/
export function isImageContent(content) {
return content.type === "image";
}
/**
* Type guard to check if content is CSVContent
*/
export function isCSVContent(content) {
return content.type === "csv";
}
/**
* Type guard to check if content is PDFContent
*/
export function isPDFContent(content) {
return content.type === "pdf";
}
/**
* Type guard to check if content is AudioContent
*/
export function isAudioContent(content) {
return content.type === "audio";
}
/**
* Type guard to check if content is VideoContent
*/
export function isVideoContent(content) {
return content.type === "video";
}
/**
* Type guard to check if input contains multimodal content
* Now includes audio and video detection
*/
/**
* Type guard to validate if an object matches the DirectorSegment shape.
* Checks for required prompt (string) and image (Buffer, string, or ImageWithAltText).
*/
function isDirectorSegment(segment) {
if (!segment || typeof segment !== "object") {
return false;
}
const maybeSegment = segment;
// Check for required prompt field
if (typeof maybeSegment.prompt !== "string" || !maybeSegment.prompt) {
return false;
}
// Check for required image field
const { image } = maybeSegment;
if (!image) {
return false;
}
// Validate image type: Buffer, string (URL/path), or ImageWithAltText
if (Buffer.isBuffer(image)) {
return true;
}
if (typeof image === "string") {
return true;
}
// Check for ImageWithAltText structure
if (typeof image === "object" && "data" in image) {
const imgData = image.data;
return Buffer.isBuffer(imgData) || typeof imgData === "string";
}
return false;
}
export function isMultimodalInput(input) {
const maybeInput = input;
return !!(maybeInput?.images?.length ||
maybeInput?.csvFiles?.length ||
maybeInput?.pdfFiles?.length ||
maybeInput?.files?.length ||
maybeInput?.content?.length ||
maybeInput?.audioFiles?.length ||
maybeInput?.videoFiles?.length ||
(maybeInput?.segments?.length &&
Array.isArray(maybeInput.segments) &&
maybeInput.segments.every(isDirectorSegment)));
}
/**
* Type guard to check if message content is multimodal (array)
*/
export function isMultimodalMessageContent(content) {
return Array.isArray(content);
}
//# sourceMappingURL=multimodal.js.map