hiloop-sdk 0.4.2 → 0.5.0
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/ws.d.ts +0 -2
- package/dist/ws.js +19 -16
- package/package.json +1 -1
package/dist/ws.d.ts
CHANGED
|
@@ -55,8 +55,6 @@ export declare class HiloopWsClient {
|
|
|
55
55
|
onAny(handler: WsEventHandler): () => void;
|
|
56
56
|
/** Remove all listeners for an event type. */
|
|
57
57
|
off(eventType: string): void;
|
|
58
|
-
/** Auto-decrypt a session message's encryptedContent field. */
|
|
59
|
-
decryptSessionMessage(encryptedContent: string): Promise<string | null>;
|
|
60
58
|
private send;
|
|
61
59
|
private emit;
|
|
62
60
|
private scheduleReconnect;
|
package/dist/ws.js
CHANGED
|
@@ -77,18 +77,26 @@ export class HiloopWsClient {
|
|
|
77
77
|
this.reconnectAttempts = 0;
|
|
78
78
|
};
|
|
79
79
|
this.ws.onmessage = (event) => {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
80
|
+
(async () => {
|
|
81
|
+
try {
|
|
82
|
+
const data = JSON.parse(event.data);
|
|
83
|
+
if (data.type === "connected") {
|
|
84
|
+
resolve();
|
|
85
|
+
}
|
|
86
|
+
// Skip metadata-only message.new (agents get the richer session.message.new instead)
|
|
87
|
+
if (data.type === "message.new") {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
// Auto-decrypt session messages
|
|
91
|
+
if (data.type === "session.message.new" && data.encryptedContent && this.crypto) {
|
|
92
|
+
const plain = await this.crypto.decryptSessionMessage(data.encryptedContent);
|
|
93
|
+
if (plain !== null)
|
|
94
|
+
data.content = plain;
|
|
95
|
+
}
|
|
96
|
+
this.emit(data.type, data);
|
|
88
97
|
}
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
catch { /* ignore malformed */ }
|
|
98
|
+
catch { /* ignore malformed */ }
|
|
99
|
+
})();
|
|
92
100
|
};
|
|
93
101
|
this.ws.onclose = () => {
|
|
94
102
|
if (!this.closed && (this.options.autoReconnect ?? true)) {
|
|
@@ -151,11 +159,6 @@ export class HiloopWsClient {
|
|
|
151
159
|
off(eventType) {
|
|
152
160
|
this.handlers.delete(eventType);
|
|
153
161
|
}
|
|
154
|
-
/** Auto-decrypt a session message's encryptedContent field. */
|
|
155
|
-
async decryptSessionMessage(encryptedContent) {
|
|
156
|
-
await this.ensureCrypto();
|
|
157
|
-
return this.crypto.decryptSessionMessage(encryptedContent);
|
|
158
|
-
}
|
|
159
162
|
// -- Private ----------------------------------------------------------------
|
|
160
163
|
send(data) {
|
|
161
164
|
if (this.ws?.readyState === WebSocket.OPEN) {
|