fix: normalize model-visible images with Pi processing

This commit is contained in:
amosblomqvist
2026-10-28 18:16:04 +02:00
parent 8f6fd7cd29
commit 84f93999c5
28 changed files with 1870 additions and 60 deletions
@@ -0,0 +1,32 @@
// Ported from @earendil-works/pi-coding-agent 1.1.0, dist/utils/image-resize-worker.js (MIT).
import { parentPort } from "node:worker_threads";
import { IMAGE_RESIZE_WORKER_RESPONSE_TYPE, resizeImageInProcess, } from "./resize-core.mjs";
function isResizeImageWorkerRequest(value) {
if (!value || typeof value !== "object")
return false;
const record = value;
return record.inputBytes instanceof Uint8Array && typeof record.mimeType === "string";
}
const port = parentPort;
if (!port) {
throw new Error("image resize worker requires parentPort");
}
port.once("message", (message) => {
void (async () => {
try {
if (!isResizeImageWorkerRequest(message)) {
throw new Error("Invalid image resize worker request");
}
const result = await resizeImageInProcess(message.inputBytes, message.mimeType, message.options);
const response = { type: IMAGE_RESIZE_WORKER_RESPONSE_TYPE, result };
port.postMessage(response);
}
catch (error) {
const response = {
type: IMAGE_RESIZE_WORKER_RESPONSE_TYPE,
error: error instanceof Error ? error.message : String(error),
};
port.postMessage(response);
}
})();
});