mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-18 02:03:05 +00:00
fix(coding-agent): use lazy-loaded photon wrapper for Node.js compatibility
Previous commit broke Node.js/tsx by using the ESM entry point which doesn't work with Node. This creates a wrapper module that: - Uses require() for lazy loading (works in both Node and Bun) - Gracefully handles load failures (returns original image) - Works in Node.js, tsx, and Bun compiled binaries
This commit is contained in:
parent
5aa0689828
commit
75628e0cfd
5 changed files with 86 additions and 16 deletions
|
|
@ -1,6 +1,4 @@
|
|||
// Use ESM entry point so Bun can embed the WASM in compiled binaries
|
||||
// (the CJS entry uses fs.readFileSync which breaks in standalone binaries)
|
||||
import { PhotonImage } from "@silvia-odwyer/photon-node/photon_rs_bg.js";
|
||||
import { getPhoton } from "./photon.js";
|
||||
|
||||
/**
|
||||
* Convert image to PNG format for terminal display.
|
||||
|
|
@ -15,8 +13,14 @@ export async function convertToPng(
|
|||
return { data: base64Data, mimeType };
|
||||
}
|
||||
|
||||
const photon = getPhoton();
|
||||
if (!photon) {
|
||||
// Photon not available, can't convert
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
const image = PhotonImage.new_from_byteslice(new Uint8Array(Buffer.from(base64Data, "base64")));
|
||||
const image = photon.PhotonImage.new_from_byteslice(new Uint8Array(Buffer.from(base64Data, "base64")));
|
||||
try {
|
||||
const pngBuffer = image.get_bytes();
|
||||
return {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue