/** * @license * Copyright 2025 Steven Roussey * SPDX-License-Identifier: Apache-2.0 */ /** * Shared helpers for AI provider run/stream functions that produce image * outputs. Each helper takes a wire form delivered by a provider SDK * (encoded PNG/JPEG bytes, a base64 data URI, or a Blob) and returns a * platform-appropriate {@link ImageValue}: * * - Node / Bun: a {@link NodeImageValue} wrapping the encoded bytes plus * dimensions read from a sharp metadata probe. The encoded buffer is * retained as-is — no decode/re-encode round trip. * - Browser: a {@link BrowserImageValue} wrapping an `ImageBitmap` * created via `createImageBitmap(blob)`. * * Provider responses are always either PNG or JPEG. WebP and other formats * are not produced by the supported endpoints and would need explicit * mime detection if added later. */ import type { ImageValue, NodeImageFormat } from "@workglow/util/media"; import type { ModelConfig } from "../model/ModelSchema"; /** * Resolve a human-readable model identifier for image error messages: * `model_id`, then `provider_config.model_name`, then the provider's * `fallback` label. Shared by every image generate/edit run-fn so the * resolution order stays consistent across providers. */ export declare function modelIdForError(model: ModelConfig | undefined, fallback: string): string; /** * Wrap an encoded image buffer in a Node {@link ImageValue}. Reads * width/height via a sharp metadata probe; no pixel decode is performed. */ export declare function pngBytesToImageValue(bytes: Uint8Array, format?: NodeImageFormat): Promise; /** * Decode a `data:;base64,...` URI into an {@link ImageValue}. * On node, retains the encoded bytes via {@link pngBytesToImageValue}. In a * browser environment, decodes via `createImageBitmap` instead. */ export declare function dataUriToImageValue(dataUri: string): Promise; /** * Convert a `Blob` (e.g. from the HF Inference SDK) into an * {@link ImageValue}. On node uses sharp metadata to size the wrapper; in * a browser uses `createImageBitmap` directly. */ export declare function blobToImageValue(blob: Blob): Promise; /** * Encode an inbound provider-input image into PNG bytes suitable for upload. * * Accepts the wire forms an `ImageValue` port may carry into a worker: * - {@link NodeImageValue} — encodes via sharp (raw-rgba) or returns bytes * directly if already PNG/JPEG. * - {@link BrowserImageValue} — encodes via canvas/`OffscreenCanvas`. * - `data:` URI string — legacy materialization form; base64-decodes the * payload. * * Always returns PNG bytes. Callers wrap the result in whatever transport * shape the SDK expects (Blob, File, OpenAI.toFile, inlineData Part). */ export declare function imageValueToPngBytes(image: unknown): Promise; /** * Encode an inbound provider-input image into a PNG `Blob` suitable for SDKs * that accept Blob/File-shaped inputs (e.g. HuggingFace Transformers.js * pipelines). Thin wrapper around {@link imageValueToPngBytes}. */ export declare function imageValueToBlob(image: unknown): Promise; //# sourceMappingURL=imageOutputHelpers.d.ts.map