mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-15 14:03:49 +00:00
fix(coding-agent): fix standalone binary WASM loading on Linux, fixes #784
- Import photon-node from ESM entry point (photon_rs_bg.js) instead of CJS entry, allowing Bun to embed WASM in compiled binaries - Add photon.d.ts for TypeScript support of ESM entry - Add scripts/build-binaries.sh for local binary builds - Simplify GitHub workflow to use the build script - Add binaries/ to gitignore
This commit is contained in:
parent
0c33e0dee5
commit
5aa0689828
7 changed files with 177 additions and 87 deletions
|
|
@ -1,4 +1,6 @@
|
|||
import photon from "@silvia-odwyer/photon-node";
|
||||
// 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";
|
||||
|
||||
/**
|
||||
* Convert image to PNG format for terminal display.
|
||||
|
|
@ -14,7 +16,7 @@ export async function convertToPng(
|
|||
}
|
||||
|
||||
try {
|
||||
const image = photon.PhotonImage.new_from_byteslice(new Uint8Array(Buffer.from(base64Data, "base64")));
|
||||
const image = PhotonImage.new_from_byteslice(new Uint8Array(Buffer.from(base64Data, "base64")));
|
||||
try {
|
||||
const pngBuffer = image.get_bytes();
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
import type { ImageContent } from "@mariozechner/pi-ai";
|
||||
import photon from "@silvia-odwyer/photon-node";
|
||||
// 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, resize, SamplingFilter } from "@silvia-odwyer/photon-node/photon_rs_bg.js";
|
||||
|
||||
export interface ImageResizeOptions {
|
||||
maxWidth?: number; // Default: 2000
|
||||
|
|
@ -53,9 +55,9 @@ export async function resizeImage(img: ImageContent, options?: ImageResizeOption
|
|||
const opts = { ...DEFAULT_OPTIONS, ...options };
|
||||
const inputBuffer = Buffer.from(img.data, "base64");
|
||||
|
||||
let image: ReturnType<typeof photon.PhotonImage.new_from_byteslice> | undefined;
|
||||
let image: ReturnType<typeof PhotonImage.new_from_byteslice> | undefined;
|
||||
try {
|
||||
image = photon.PhotonImage.new_from_byteslice(new Uint8Array(inputBuffer));
|
||||
image = PhotonImage.new_from_byteslice(new Uint8Array(inputBuffer));
|
||||
|
||||
const originalWidth = image.get_width();
|
||||
const originalHeight = image.get_height();
|
||||
|
|
@ -94,7 +96,7 @@ export async function resizeImage(img: ImageContent, options?: ImageResizeOption
|
|||
height: number,
|
||||
jpegQuality: number,
|
||||
): { buffer: Uint8Array; mimeType: string } {
|
||||
const resized = photon.resize(image!, width, height, photon.SamplingFilter.Lanczos3);
|
||||
const resized = resize(image!, width, height, SamplingFilter.Lanczos3);
|
||||
|
||||
try {
|
||||
const pngBuffer = resized.get_bytes();
|
||||
|
|
|
|||
5
packages/coding-agent/src/utils/photon.d.ts
vendored
Normal file
5
packages/coding-agent/src/utils/photon.d.ts
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
// Type declarations for the ESM entry point of @silvia-odwyer/photon-node
|
||||
// The ESM entry exports the same API but uses WASM imports that bundlers can embed
|
||||
declare module "@silvia-odwyer/photon-node/photon_rs_bg.js" {
|
||||
export * from "@silvia-odwyer/photon-node";
|
||||
}
|
||||
|
|
@ -5,5 +5,5 @@
|
|||
"rootDir": "./src"
|
||||
},
|
||||
"include": ["src/**/*.ts"],
|
||||
"exclude": ["node_modules", "dist", "**/*.d.ts", "src/**/*.d.ts"]
|
||||
"exclude": ["node_modules", "dist"]
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue