@melaya/runner 1.0.14 → 1.0.15
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/localRelay.js +25 -7
- package/package.json +1 -1
package/dist/localRelay.js
CHANGED
|
@@ -20,20 +20,38 @@ let _throttleQueue = [];
|
|
|
20
20
|
function _flushThrottle(socket, verbose) {
|
|
21
21
|
if (_throttleQueue.length === 0)
|
|
22
22
|
return;
|
|
23
|
-
//
|
|
24
|
-
|
|
23
|
+
// Coalescing rule:
|
|
24
|
+
// - `agent_message` is a streaming event type whose payload GROWS
|
|
25
|
+
// over time (each update replaces the previous with more text).
|
|
26
|
+
// Only the LAST per replyId matters — keep the last-write-wins
|
|
27
|
+
// dedup for these.
|
|
28
|
+
// - Everything else (reasoning / tool_call / tool_result /
|
|
29
|
+
// agent_reply / cost / session_status / compact / hook) is a
|
|
30
|
+
// discrete event — coalescing drops real information. Emit every
|
|
31
|
+
// one exactly once, preserving order.
|
|
32
|
+
const streamingByReply = new Map();
|
|
33
|
+
const discrete = [];
|
|
25
34
|
for (const p of _throttleQueue) {
|
|
26
|
-
|
|
27
|
-
|
|
35
|
+
if (p.event_type === "agent_message") {
|
|
36
|
+
const key = p.replyId || p.run_id || "default";
|
|
37
|
+
streamingByReply.set(key, p);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
discrete.push(p);
|
|
41
|
+
}
|
|
28
42
|
}
|
|
29
|
-
|
|
43
|
+
const emit = (payload) => {
|
|
30
44
|
socket.emit("runner:event", payload);
|
|
31
45
|
if (verbose) {
|
|
32
46
|
const type = payload.event_type || "unknown";
|
|
33
|
-
const agent = payload.replyName || "";
|
|
47
|
+
const agent = payload.replyName || payload.agent_name || "";
|
|
34
48
|
process.stdout.write(` [relay] ${type}${agent ? ` (${agent})` : ""}\n`);
|
|
35
49
|
}
|
|
36
|
-
}
|
|
50
|
+
};
|
|
51
|
+
for (const payload of discrete)
|
|
52
|
+
emit(payload);
|
|
53
|
+
for (const payload of streamingByReply.values())
|
|
54
|
+
emit(payload);
|
|
37
55
|
_throttleQueue = [];
|
|
38
56
|
_throttleTimer = null;
|
|
39
57
|
}
|