@p697/clawket 0.6.2 → 0.6.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/index.js +48 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -5839,6 +5839,15 @@ var RELAY_CONTROL_PREFIX = "__clawket_relay_control__:";
|
|
|
5839
5839
|
var BRIDGE_HEALTH_METHOD = "health";
|
|
5840
5840
|
var BRIDGE_HEALTH_PARAMS = {};
|
|
5841
5841
|
var DEFAULT_BRIDGE_HEALTH_PROBE_TIMEOUT_MS = 1e4;
|
|
5842
|
+
var TRACEABLE_RELAY_METHODS = /* @__PURE__ */ new Set([
|
|
5843
|
+
"sessions.list",
|
|
5844
|
+
"chat.history",
|
|
5845
|
+
"last-heartbeat",
|
|
5846
|
+
"model.current",
|
|
5847
|
+
"models.list",
|
|
5848
|
+
"agent.identity.get",
|
|
5849
|
+
"agents.list"
|
|
5850
|
+
]);
|
|
5842
5851
|
var HermesRelayRuntime = class {
|
|
5843
5852
|
options;
|
|
5844
5853
|
relaySocket = null;
|
|
@@ -5853,6 +5862,7 @@ var HermesRelayRuntime = class {
|
|
|
5853
5862
|
bridgeStatusProbeInFlight = false;
|
|
5854
5863
|
pendingBridgeMessages = [];
|
|
5855
5864
|
bridgeHealthProbeSeq = 0;
|
|
5865
|
+
relayMessageSeq = 0;
|
|
5856
5866
|
pendingBridgeHealthProbe = null;
|
|
5857
5867
|
snapshot;
|
|
5858
5868
|
constructor(options) {
|
|
@@ -6010,6 +6020,7 @@ var HermesRelayRuntime = class {
|
|
|
6010
6020
|
const text = normalizeText(data);
|
|
6011
6021
|
if (text == null)
|
|
6012
6022
|
return;
|
|
6023
|
+
this.traceRelayFrame("relay_in", text);
|
|
6013
6024
|
if (text.startsWith(RELAY_CONTROL_PREFIX)) {
|
|
6014
6025
|
this.handleRelayControl(text);
|
|
6015
6026
|
return;
|
|
@@ -6045,6 +6056,7 @@ var HermesRelayRuntime = class {
|
|
|
6045
6056
|
const text = normalizeText(data);
|
|
6046
6057
|
if (text == null)
|
|
6047
6058
|
return;
|
|
6059
|
+
this.traceRelayFrame("bridge_in", text);
|
|
6048
6060
|
if (this.handleBridgeHealthProbeResponse(text)) {
|
|
6049
6061
|
return;
|
|
6050
6062
|
}
|
|
@@ -6055,6 +6067,9 @@ var HermesRelayRuntime = class {
|
|
|
6055
6067
|
forwardOrQueueBridgeMessage(message) {
|
|
6056
6068
|
const bridge = this.bridgeSocket;
|
|
6057
6069
|
if (!bridge || bridge.readyState !== WebSocket2.OPEN) {
|
|
6070
|
+
if (message.text !== void 0) {
|
|
6071
|
+
this.traceRelayFrame("bridge_queue", message.text);
|
|
6072
|
+
}
|
|
6058
6073
|
if (this.pendingBridgeMessages.length < 256) {
|
|
6059
6074
|
this.pendingBridgeMessages.push(message);
|
|
6060
6075
|
}
|
|
@@ -6062,6 +6077,7 @@ var HermesRelayRuntime = class {
|
|
|
6062
6077
|
return;
|
|
6063
6078
|
}
|
|
6064
6079
|
if (message.text !== void 0) {
|
|
6080
|
+
this.traceRelayFrame("bridge_send", message.text);
|
|
6065
6081
|
bridge.send(message.text);
|
|
6066
6082
|
return;
|
|
6067
6083
|
}
|
|
@@ -6078,12 +6094,44 @@ var HermesRelayRuntime = class {
|
|
|
6078
6094
|
if (!next)
|
|
6079
6095
|
break;
|
|
6080
6096
|
if (next.text !== void 0) {
|
|
6097
|
+
this.traceRelayFrame("bridge_flush", next.text);
|
|
6081
6098
|
bridge.send(next.text);
|
|
6082
6099
|
} else if (next.data) {
|
|
6083
6100
|
bridge.send(next.data);
|
|
6084
6101
|
}
|
|
6085
6102
|
}
|
|
6086
6103
|
}
|
|
6104
|
+
traceRelayFrame(direction, text) {
|
|
6105
|
+
const details = this.describeRelayFrame(text);
|
|
6106
|
+
if (!details)
|
|
6107
|
+
return;
|
|
6108
|
+
this.log(`[trace] ${direction} seq=${++this.relayMessageSeq} ${details}`);
|
|
6109
|
+
}
|
|
6110
|
+
describeRelayFrame(text) {
|
|
6111
|
+
if (text.startsWith(RELAY_CONTROL_PREFIX)) {
|
|
6112
|
+
try {
|
|
6113
|
+
const parsed = JSON.parse(text.slice(RELAY_CONTROL_PREFIX.length));
|
|
6114
|
+
const event = typeof parsed?.event === "string" ? parsed.event : "unknown";
|
|
6115
|
+
return `controlEvent=${event}`;
|
|
6116
|
+
} catch {
|
|
6117
|
+
return "controlEvent=invalid";
|
|
6118
|
+
}
|
|
6119
|
+
}
|
|
6120
|
+
try {
|
|
6121
|
+
const parsed = JSON.parse(text);
|
|
6122
|
+
if (parsed?.type === "req" && typeof parsed.method === "string") {
|
|
6123
|
+
if (!TRACEABLE_RELAY_METHODS.has(parsed.method))
|
|
6124
|
+
return null;
|
|
6125
|
+
return `frame=req id=${String(parsed.id ?? "")} method=${parsed.method}`;
|
|
6126
|
+
}
|
|
6127
|
+
if (parsed?.type === "res" && typeof parsed.id === "string") {
|
|
6128
|
+
return `frame=res id=${parsed.id} ok=${parsed.ok === true ? "true" : "false"}`;
|
|
6129
|
+
}
|
|
6130
|
+
return null;
|
|
6131
|
+
} catch {
|
|
6132
|
+
return null;
|
|
6133
|
+
}
|
|
6134
|
+
}
|
|
6087
6135
|
scheduleRelayReconnect() {
|
|
6088
6136
|
if (this.stopped || this.reconnectTimer)
|
|
6089
6137
|
return;
|