diff --git a/packages/coding-agent/CHANGELOG.md b/packages/coding-agent/CHANGELOG.md index 1d1c9b029..cb5107ab1 100644 --- a/packages/coding-agent/CHANGELOG.md +++ b/packages/coding-agent/CHANGELOG.md @@ -1,6 +1,9 @@ # Changelog ## [Unreleased] +### Added + +- Added Buffer.toBase64() polyfill for Bun compatibility to enable base64 encoding of buffers ## [12.18.0] - 2026-02-21 diff --git a/packages/coding-agent/src/utils/image-resize.ts b/packages/coding-agent/src/utils/image-resize.ts index 748026824..123d0692a 100644 --- a/packages/coding-agent/src/utils/image-resize.ts +++ b/packages/coding-agent/src/utils/image-resize.ts @@ -37,6 +37,11 @@ function pickSmaller( return a.buffer.length <= b.buffer.length ? a : b; } +/** Polyfill for Buffer.toBase64, technically since it derives from Uint8Array it should exist but Bun reasons... */ +Buffer.prototype.toBase64 = function (this: Buffer) { + return new Uint8Array(this.buffer, this.byteOffset, this.byteLength).toBase64(); +}; + /** * Resize an image to fit within the specified max dimensions and file size. * Returns the original image if it already fits within the limits. diff --git a/packages/coding-agent/test/image-b64poly.test.ts b/packages/coding-agent/test/image-b64poly.test.ts new file mode 100644 index 000000000..00d975fec --- /dev/null +++ b/packages/coding-agent/test/image-b64poly.test.ts @@ -0,0 +1,14 @@ +import { describe, expect, it } from "bun:test"; + +describe("Buffer.toBase64", async () => { + await import("../src/utils/image-resize"); + + it("should be defined", () => { + expect(Buffer.prototype.toBase64).toBeDefined(); + }); + + it("should return a base64 string", () => { + const buffer = Buffer.from("Hello, world!"); + expect(buffer.toBase64()).toBe("SGVsbG8sIHdvcmxkIQ=="); + }); +});