UNPKG

captivate-chat-api

Version:

This is a wrapper for captivate chat api socket custom channel

190 lines (189 loc) 6.96 kB
/** * Represents a file attachment with both file data and extracted text content. * Supports direct file uploads only (URL processing not supported by the API). */ export declare class CaptivateChatFileInput { private static readonly FILE_TO_TEXT_API_URL; readonly type: 'files'; readonly files: Array<{ filename: string; type: string; file?: File | Blob; url?: string; textContent: { type: 'file_content'; text: string; metadata: { source: 'file_attachment'; originalFileName: string; storageType?: 'direct'; }; }; }>; constructor(file: File | Blob, textContent: { type: 'file_content'; text: string; metadata: { source: 'file_attachment'; originalFileName: string; storageType?: 'direct'; }; }, type: string); /** * Factory method to create a CaptivateChatFileInput with automatic file-to-text conversion for direct file uploads. * @param options - Configuration options for the file input. * @param options.file - The file to convert. * @param options.fileName - Optional custom file name. * @param options.fileType - Optional custom file type. * @param options.storage - Whether to store the file for future reference (default: true). * @param options.url - URL to reference the file when storage is false (required when storage is false). * @returns A promise that resolves to a CaptivateChatFileInput instance with converted text. */ static create(options: { file: File | Blob; fileName?: string; fileType?: string; storage?: boolean; url?: string; }): Promise<CaptivateChatFileInput>; /** * Gets the first file from the files array for convenience. * @returns The first file object, or undefined if no files exist. */ getFirstFile(): { filename: string; type: string; file?: File | Blob; url?: string; textContent: { type: "file_content"; text: string; metadata: { source: "file_attachment"; originalFileName: string; storageType?: "direct"; }; }; }; /** * Gets the filename of the first file. * @returns The filename, or undefined if no files exist. */ getFilename(): string; /** * Gets the text content of the first file. * @returns The text content, or empty string if no files exist. */ getTextContent(): string; /** * Gets the file type of the first file. * @returns The file type, or undefined if no files exist. */ getFileType(): string; /** * Returns the files array directly for compatibility with the files property. * This allows using fileInputObj directly as the files value. * @returns The files array. */ toFilesArray(): { filename: string; type: string; file?: File | Blob; url?: string; textContent: { type: "file_content"; text: string; metadata: { source: "file_attachment"; originalFileName: string; storageType?: "direct"; }; }; }[]; /** * Makes the class iterable so it can be used directly as an array. */ [Symbol.iterator](): Generator<{ filename: string; type: string; file?: File | Blob; url?: string; textContent: { type: "file_content"; text: string; metadata: { source: "file_attachment"; originalFileName: string; storageType?: "direct"; }; }; }, void, unknown>; /** * Getter that returns the files array, allowing the class to be used directly as files. * This enables: files: fileInputObj instead of files: fileInputObj.files */ get [Symbol.toStringTag](): string; /** * Returns the length of the files array for array-like behavior. */ get length(): number; /** * Proxy handler to make the class behave like the files array. * This allows using fileInputObj directly as files: fileInputObj */ static createProxy(instance: CaptivateChatFileInput): CaptivateChatFileInput; /** * Factory method to create a single file object with automatic file-to-text conversion. * Returns just the file object instead of the full CaptivateChatFileInput wrapper. * @param options - Configuration options for the file input. * @param options.file - The file to convert. * @param options.fileName - Optional custom file name. * @param options.fileType - Optional custom file type. * @param options.storage - Whether to store the file for future reference (default: true). * @param options.url - URL to reference the file when storage is false (required when storage is false). * @returns A promise that resolves to a single file object. */ static createFile(options: { file: File | Blob; fileName?: string; fileType?: string; storage?: boolean; url?: string; }): Promise<{ filename: string; type: string; file?: File | Blob; textContent: { type: 'file_content'; text: string; metadata: { source: 'file_attachment'; originalFileName: string; storageType?: 'direct'; }; }; }>; /** * Factory method to create multiple file inputs from an array of files. * Processes all files in parallel and returns a single CaptivateChatFileInput with all files. * @param options - Configuration options for all files. * @param options.files - Array of files to process. * @param options.storage - Whether to store the files for future reference (default: true). * @param options.urls - Array of URLs to reference files when storage is false (required when storage is false). * @returns A promise that resolves to a CaptivateChatFileInput instance with all processed files. */ static createMultiple(options: { files: (File | Blob)[]; storage?: boolean; urls?: string[]; }): Promise<CaptivateChatFileInput>; /** * Converts a file to text using the file-to-text API endpoint. * @param file - The file to convert (File or Blob). * @param fileName - The name of the file. * @param includeMetadata - Whether to include additional metadata in the response. * @param storage - Whether to store the file for future reference. * @returns A promise that resolves to the extracted text. */ private static convertFileToText; }