hypha-debugger 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/hypha-debugger.js
CHANGED
|
@@ -13852,6 +13852,23 @@
|
|
|
13852
13852
|
* Images are downscaled before being returned so agents don't receive
|
|
13853
13853
|
* multi-megabyte base64 payloads that can crash their context window.
|
|
13854
13854
|
*/
|
|
13855
|
+
/** Extract a useful string from an unknown error value. */
|
|
13856
|
+
function errorMessage(err) {
|
|
13857
|
+
if (!err)
|
|
13858
|
+
return "Unknown error";
|
|
13859
|
+
if (typeof err === "string")
|
|
13860
|
+
return err;
|
|
13861
|
+
if (err.message)
|
|
13862
|
+
return err.message;
|
|
13863
|
+
if (err instanceof Event)
|
|
13864
|
+
return `Event: ${err.type}`;
|
|
13865
|
+
try {
|
|
13866
|
+
return JSON.stringify(err);
|
|
13867
|
+
}
|
|
13868
|
+
catch {
|
|
13869
|
+
return String(err);
|
|
13870
|
+
}
|
|
13871
|
+
}
|
|
13855
13872
|
/**
|
|
13856
13873
|
* Resize an image data URL via a canvas. Returns a new data URL at the
|
|
13857
13874
|
* requested format/quality. Maintains aspect ratio: fits within
|
|
@@ -13861,31 +13878,34 @@
|
|
|
13861
13878
|
return new Promise((resolve, reject) => {
|
|
13862
13879
|
const img = new Image();
|
|
13863
13880
|
img.onload = () => {
|
|
13864
|
-
|
|
13865
|
-
|
|
13866
|
-
|
|
13867
|
-
|
|
13868
|
-
|
|
13869
|
-
|
|
13870
|
-
|
|
13871
|
-
|
|
13872
|
-
|
|
13873
|
-
|
|
13874
|
-
|
|
13875
|
-
|
|
13876
|
-
|
|
13881
|
+
try {
|
|
13882
|
+
const srcW = img.naturalWidth;
|
|
13883
|
+
const srcH = img.naturalHeight;
|
|
13884
|
+
const scale = Math.min(maxWidth / srcW, maxHeight / srcH, 1);
|
|
13885
|
+
const dstW = Math.max(1, Math.round(srcW * scale));
|
|
13886
|
+
const dstH = Math.max(1, Math.round(srcH * scale));
|
|
13887
|
+
const canvas = document.createElement("canvas");
|
|
13888
|
+
canvas.width = dstW;
|
|
13889
|
+
canvas.height = dstH;
|
|
13890
|
+
const ctx = canvas.getContext("2d");
|
|
13891
|
+
if (!ctx) {
|
|
13892
|
+
reject(new Error("Could not get 2D canvas context"));
|
|
13893
|
+
return;
|
|
13894
|
+
}
|
|
13895
|
+
if (format === "jpeg") {
|
|
13896
|
+
ctx.fillStyle = "#ffffff";
|
|
13897
|
+
ctx.fillRect(0, 0, dstW, dstH);
|
|
13898
|
+
}
|
|
13899
|
+
ctx.drawImage(img, 0, 0, dstW, dstH);
|
|
13900
|
+
const mime = format === "jpeg" ? "image/jpeg" : "image/png";
|
|
13901
|
+
const out = canvas.toDataURL(mime, quality);
|
|
13902
|
+
resolve({ dataUrl: out, width: dstW, height: dstH });
|
|
13877
13903
|
}
|
|
13878
|
-
|
|
13879
|
-
|
|
13880
|
-
ctx.fillStyle = "#ffffff";
|
|
13881
|
-
ctx.fillRect(0, 0, dstW, dstH);
|
|
13904
|
+
catch (drawErr) {
|
|
13905
|
+
reject(new Error(`Canvas resize failed: ${errorMessage(drawErr)}`));
|
|
13882
13906
|
}
|
|
13883
|
-
ctx.drawImage(img, 0, 0, dstW, dstH);
|
|
13884
|
-
const mime = format === "jpeg" ? "image/jpeg" : "image/png";
|
|
13885
|
-
const out = canvas.toDataURL(mime, quality);
|
|
13886
|
-
resolve({ dataUrl: out, width: dstW, height: dstH });
|
|
13887
13907
|
};
|
|
13888
|
-
img.onerror = () => reject(new Error(
|
|
13908
|
+
img.onerror = (ev) => reject(new Error(`Failed to load captured image for resizing${ev instanceof Event ? ` (${ev.type})` : ""}`));
|
|
13889
13909
|
img.src = dataUrl;
|
|
13890
13910
|
});
|
|
13891
13911
|
}
|
|
@@ -13938,25 +13958,49 @@
|
|
|
13938
13958
|
captureOptions.height = viewportH;
|
|
13939
13959
|
}
|
|
13940
13960
|
let dataUrl;
|
|
13941
|
-
|
|
13942
|
-
|
|
13961
|
+
try {
|
|
13962
|
+
if (fmt === "jpeg") {
|
|
13963
|
+
dataUrl = await toJpeg(node, captureOptions);
|
|
13964
|
+
}
|
|
13965
|
+
else {
|
|
13966
|
+
dataUrl = await toPng(node, captureOptions);
|
|
13967
|
+
}
|
|
13943
13968
|
}
|
|
13944
|
-
|
|
13945
|
-
|
|
13969
|
+
catch (captureErr) {
|
|
13970
|
+
return {
|
|
13971
|
+
error: `Capture failed (html-to-image): ${errorMessage(captureErr)}`,
|
|
13972
|
+
};
|
|
13973
|
+
}
|
|
13974
|
+
// Resize down to fit within (maxW × maxH) and re-encode. If resize
|
|
13975
|
+
// fails (e.g. data URL too large to load back into an Image), fall
|
|
13976
|
+
// back to returning the original capture so the caller still gets
|
|
13977
|
+
// something useful.
|
|
13978
|
+
try {
|
|
13979
|
+
const resized = await resizeDataUrl(dataUrl, maxW, maxH, fmt, qual);
|
|
13980
|
+
const sizeKb = Math.round((resized.dataUrl.length * 0.75) / 1024);
|
|
13981
|
+
return {
|
|
13982
|
+
data: resized.dataUrl,
|
|
13983
|
+
format: fmt,
|
|
13984
|
+
width: resized.width,
|
|
13985
|
+
height: resized.height,
|
|
13986
|
+
size_kb: sizeKb,
|
|
13987
|
+
};
|
|
13988
|
+
}
|
|
13989
|
+
catch (resizeErr) {
|
|
13990
|
+
const rect = node.getBoundingClientRect();
|
|
13991
|
+
const sizeKb = Math.round((dataUrl.length * 0.75) / 1024);
|
|
13992
|
+
return {
|
|
13993
|
+
data: dataUrl,
|
|
13994
|
+
format: fmt,
|
|
13995
|
+
width: Math.round(rect.width),
|
|
13996
|
+
height: Math.round(rect.height),
|
|
13997
|
+
size_kb: sizeKb,
|
|
13998
|
+
warning: `Resize failed, returning original: ${errorMessage(resizeErr)}`,
|
|
13999
|
+
};
|
|
13946
14000
|
}
|
|
13947
|
-
// Resize down to fit within (maxW × maxH) and re-encode
|
|
13948
|
-
const resized = await resizeDataUrl(dataUrl, maxW, maxH, fmt, qual);
|
|
13949
|
-
const sizeKb = Math.round((resized.dataUrl.length * 0.75) / 1024); // rough base64 → bytes
|
|
13950
|
-
return {
|
|
13951
|
-
data: resized.dataUrl,
|
|
13952
|
-
format: fmt,
|
|
13953
|
-
width: resized.width,
|
|
13954
|
-
height: resized.height,
|
|
13955
|
-
size_kb: sizeKb,
|
|
13956
|
-
};
|
|
13957
14001
|
}
|
|
13958
14002
|
catch (err) {
|
|
13959
|
-
return { error: `Screenshot failed: ${err
|
|
14003
|
+
return { error: `Screenshot failed: ${errorMessage(err)}` };
|
|
13960
14004
|
}
|
|
13961
14005
|
}
|
|
13962
14006
|
takeScreenshot.__schema__ = {
|