/** * Internal dependencies */ import CandidatesStreamProcessor from './classes/candidates-stream-processor'; import HistoryPersistence from './classes/history-persistence'; import type { ContentRole as ContentRoleType, Content, Candidates, AsyncCandidatesGenerator } from './types'; type WordPressAttachmentSizeData = { url: string; width: number; height: number; }; type WordPressAttachment = { id: number; url: string; mime: string; icon: string; sizes?: Record; [key: string]: unknown; }; /** * Converts a text string to a Content object. * * @since 0.2.0 * * @param text - The text. * @param role - Optional. The role to use for the content. Default 'user'. * @returns The Content object. */ export declare function textToContent(text: string, role?: ContentRoleType): Content; /** * Converts a text string and attachment to a multimodal Content instance. * * The text will be included as a prompt as the first part of the content, and the attachment (e.g. an image or * audio file) will be included as the second part. * * @since 0.5.0 * * @param text - The text. * @param attachment - The attachment object. * @param role - Optional. The role to use for the content. Default 'user'. * @returns The Content object. */ export declare function textAndAttachmentToContent(text: string, attachment: WordPressAttachment, role?: ContentRoleType): Promise; /** * Converts a text string and an array of attachments to a multimodal Content instance. * * The text will be included as a prompt as the first part of the content, and the attachments (e.g. image or audio * files) will be included as the subsequent parts. * * @since 0.6.0 * * @param text - The text. * @param attachments - The attachment objects. * @param role - Optional. The role to use for the content. Default 'user'. * @returns The Content object. */ export declare function textAndAttachmentsToContent(text: string, attachments: WordPressAttachment[], role?: ContentRoleType): Promise; /** * Converts a Content object to a text string. * * This function will return the combined text from all consecutive text parts in the content. * Realistically, this should almost always return the text from just one part, as API responses typically do not * contain multiple text parts in a row - but it might be possible. * * @since 0.2.0 * * @param content - The Content object. * @returns The text, or an empty string if there are no text parts. */ export declare function contentToText(content: Content): string; /** * Gets the text from the first Content object in the given list which contains text. * * @since 0.2.0 * * @param contents - The list of Content objects. * @returns The text, or an empty string if no Content object has text parts. */ export declare function getTextFromContents(contents: Content[]): string; /** * Gets the first Content object in the given list which contains text. * * @since 0.5.0 * * @param contents - The list of Content objects. * @returns The Content object, or null if no Content object has text parts. */ export declare function getTextContentFromContents(contents: Content[]): Content | null; /** * Gets the Content objects for each candidate in the given list. * * @since 0.2.0 * * @param candidates - The list of candidates. * @returns The list of Content objects. */ export declare function getCandidateContents(candidates: Candidates): Content[]; /** * Processes a stream of candidates, aggregating the candidates chunks into a single candidates instance. * * This method returns a stream processor instance that can be used to read all chunks from the given candidates * generator and process them with a callback. Alternatively, you can read from the generator yourself and provide * all chunks to the processor manually. * * @since 0.3.0 * * @param generator - The generator that yields the chunks of response candidates. * @returns The stream processor instance. */ export declare function processCandidatesStream(generator: AsyncCandidatesGenerator): CandidatesStreamProcessor; /** * Gets the history persistence instance, to load, save, and clear histories. * * @since 0.5.0 * * @returns The history persistence instance. */ export declare function historyPersistence(): HistoryPersistence; /** * Returns the base64-encoded data URL representation of the given file URL. * * @since 0.5.0 * * @param file - The file URL. * @param mimeType - Optional. The MIME type of the file, to prefix `data:{mime_type};base64,`. Default empty string. * @returns The base64-encoded file data URL, or empty string on failure. */ export declare function fileToBase64DataUrl(file: string, mimeType?: string): Promise; /** * Returns the binary data blob representation of the given file URL. * * @since 0.5.0 * * @param file - The file URL. * @param mimeType - Optional. The MIME type of the file, to override detected MIME type. Default empty string. * @returns The binary data blob, or null on failure. */ export declare function fileToBlob(file: string, mimeType?: string): Promise; /** * Returns the base64-encoded data URL representation of the given binary data blob. * * @since 0.5.0 * * @param blob - The binary data blob. * @returns The base64-encoded data URL, or empty string on failure. */ export declare function blobToBase64DataUrl(blob: Blob): Promise; /** * Returns the binary data blob representation of the given base64-encoded data URL. * * @since 0.5.0 * * @param base64DataUrl - The base64-encoded data URL. * @returns The binary data blob, or null on failure. */ export declare function base64DataUrlToBlob(base64DataUrl: string): Promise; /** * Ensures the given base64 data is prefixed correctly to be a data URL. * * @since 0.6.0 * * @param base64Data - Base64-encoded data. If it is already a data URL, it will be returned as is. * @param mimeType - MIME type for the data. * @returns The base64 data URL. */ export declare function base64DataToBase64DataUrl(base64Data: string, mimeType: string): string; /** * Ensures the given base64 data URL has its prefix removed to be just the base64 data. * * @since 0.6.0 * * @param base64DataUrl - Base64 data URL. If it is already without prefix, it will be returned as is. * @returns The base64-encoded data. */ export declare function base64DataUrlToBase64Data(base64DataUrl: string): string; export {}; //# sourceMappingURL=helpers.d.ts.map