/** * Media type helpers used to decide how request and response bodies are encoded. * * Issue #105: binary responses were decoded as UTF-8 strings (corrupting every * non-UTF-8 byte) and binary request bodies were sent as JSON objects. These * helpers classify media types so bodies can be passed through as raw bytes. */ /** * Normalize a Content-Type header value to its lower-cased media type, * stripping any parameters (e.g. `"Image/PNG; charset=binary"` → `"image/png"`). */ export declare function normalizeMediaType(contentType: unknown): string | undefined; /** * Extract the `charset` parameter from a Content-Type header value. */ export declare function getCharset(contentType: unknown): string | undefined; export declare function isJsonMediaType(mediaType: string): boolean; export declare function isTextualMediaType(mediaType: string): boolean; export declare function isKnownBinaryMediaType(mediaType: string): boolean; /** * Decide whether a request body with the given media type and (inlined) schema * should be sent as raw bytes rather than serialized as JSON / form data. */ export declare function isBinaryRequestBody(contentType: string | undefined, schema?: unknown): boolean; /** * Content-Type to send for a binary request body. Wildcard media ranges from the * spec (e.g. `image/*`, `*\/*`) are not valid Content-Type values. */ export declare function binaryRequestContentType(contentType: string | undefined): string; /** * Decode a binary request body supplied by a tool caller. * Accepts plain base64, base64url, or a `data:;base64,` URL. * * @throws Error if the value is not valid base64 */ export declare function decodeBase64Body(value: unknown, paramName?: string): Buffer; /** * A non-textual HTTP response body, kept as raw bytes. */ export declare class BinaryResponse { readonly data: Buffer; readonly mimeType: string; readonly uri?: string | undefined; constructor(data: Buffer, mimeType: string, uri?: string | undefined); get size(): number; toBase64(): string; /** * Keep JSON serialization meaningful (instead of a giant byte array) for library users. */ toJSON(): { mimeType: string; size: number; uri?: string; base64: string; }; } /** * Decode a raw HTTP response body according to its Content-Type. * * - JSON types → parsed value (falls back to the text if it does not parse) * - textual types → string * - binary types → {@link BinaryResponse} with the untouched bytes * - unknown/missing types → text if the bytes are valid UTF-8, otherwise binary * * Values that are not raw bytes (e.g. already decoded by a custom adapter) are returned as-is. */ export declare function decodeResponseBody(data: unknown, contentType: unknown, uri?: string): unknown;