/**
 * Base64 + UTF-8 helpers for multimodal host-tool handlers (sandbox_llm,
 * take_screenshot). Promote to `utils/` when a third caller appears.
 */
/** Chunked to avoid blowing `String.fromCharCode.apply`'s argument stack on multi-MB inputs. */
export function bytesToBase64(bytes) {
    const CHUNK = 0x8000;
    let binary = '';
    for (let offset = 0; offset < bytes.length; offset += CHUNK) {
        const slice = bytes.subarray(offset, offset + CHUNK);
        binary += String.fromCharCode.apply(null, Array.from(slice));
    }
    return globalThis.btoa(binary);
}
export function bytesToUtf8(bytes) {
    return new TextDecoder('utf-8', { fatal: false }).decode(bytes);
}
export function base64ToBytes(b64) {
    const binary = globalThis.atob(b64);
    const bytes = new Uint8Array(binary.length);
    for (let i = 0; i < binary.length; i += 1)
        bytes[i] = binary.charCodeAt(i);
    return bytes;
}
//# sourceMappingURL=base64.js.map