@taewooopark/agent-blackbox 0.47.2 → 0.47.3
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/cli.js
CHANGED
|
@@ -2785,20 +2785,49 @@ async function broadcastSnapshot(clients, eventsFile) {
|
|
|
2785
2785
|
if (clients.size === 0) {
|
|
2786
2786
|
return;
|
|
2787
2787
|
}
|
|
2788
|
-
|
|
2788
|
+
let frame;
|
|
2789
|
+
try {
|
|
2790
|
+
frame = JSON.stringify({ type: "snapshot", data: await buildTraceSnapshot(eventsFile) });
|
|
2791
|
+
} catch (error) {
|
|
2792
|
+
const errFrame = JSON.stringify({
|
|
2793
|
+
type: "error",
|
|
2794
|
+
error: { message: error instanceof Error ? error.message : String(error) }
|
|
2795
|
+
});
|
|
2796
|
+
for (const client of clients)
|
|
2797
|
+
if (client.readyState === WebSocket.OPEN)
|
|
2798
|
+
client.send(errFrame);
|
|
2799
|
+
return;
|
|
2800
|
+
}
|
|
2801
|
+
for (const client of clients)
|
|
2802
|
+
if (client.readyState === WebSocket.OPEN)
|
|
2803
|
+
client.send(frame);
|
|
2789
2804
|
}
|
|
2790
2805
|
function makeBroadcastScheduler(clients, eventsFile, delayMs = 150) {
|
|
2791
2806
|
let timer = null;
|
|
2792
|
-
|
|
2807
|
+
let building = false;
|
|
2808
|
+
let pending = false;
|
|
2809
|
+
const schedule = () => {
|
|
2810
|
+
if (building) {
|
|
2811
|
+
pending = true;
|
|
2812
|
+
return;
|
|
2813
|
+
}
|
|
2793
2814
|
if (timer)
|
|
2794
2815
|
return;
|
|
2795
2816
|
timer = setTimeout(() => {
|
|
2796
2817
|
timer = null;
|
|
2797
|
-
|
|
2818
|
+
building = true;
|
|
2819
|
+
void broadcastSnapshot(clients, eventsFile).finally(() => {
|
|
2820
|
+
building = false;
|
|
2821
|
+
if (pending) {
|
|
2822
|
+
pending = false;
|
|
2823
|
+
schedule();
|
|
2824
|
+
}
|
|
2825
|
+
});
|
|
2798
2826
|
}, delayMs);
|
|
2799
2827
|
if (typeof timer.unref === "function")
|
|
2800
2828
|
timer.unref();
|
|
2801
2829
|
};
|
|
2830
|
+
return schedule;
|
|
2802
2831
|
}
|
|
2803
2832
|
async function sendSnapshot(client, eventsFile) {
|
|
2804
2833
|
if (client.readyState !== WebSocket.OPEN) {
|