hiloop-sdk 0.4.1 → 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.
Files changed (3) hide show
  1. package/dist/ws.d.ts +0 -3
  2. package/dist/ws.js +19 -22
  3. package/package.json +1 -1
package/dist/ws.d.ts CHANGED
@@ -26,7 +26,6 @@ export type WsEventHandler = (data: any) => void;
26
26
  export declare class HiloopWsClient {
27
27
  private ws;
28
28
  private options;
29
- private agentId;
30
29
  private handlers;
31
30
  private anyHandlers;
32
31
  private reconnectAttempts;
@@ -56,8 +55,6 @@ export declare class HiloopWsClient {
56
55
  onAny(handler: WsEventHandler): () => void;
57
56
  /** Remove all listeners for an event type. */
58
57
  off(eventType: string): void;
59
- /** Auto-decrypt a session message's encryptedContent field. */
60
- decryptSessionMessage(encryptedContent: string): Promise<string | null>;
61
58
  private send;
62
59
  private emit;
63
60
  private scheduleReconnect;
package/dist/ws.js CHANGED
@@ -15,7 +15,6 @@ import { CryptoContext, deriveKeyPairFromApiKey, computeFingerprint } from "./cr
15
15
  export class HiloopWsClient {
16
16
  constructor(options) {
17
17
  this.ws = null;
18
- this.agentId = null;
19
18
  this.handlers = new Map();
20
19
  this.anyHandlers = new Set();
21
20
  this.reconnectAttempts = 0;
@@ -78,23 +77,26 @@ export class HiloopWsClient {
78
77
  this.reconnectAttempts = 0;
79
78
  };
80
79
  this.ws.onmessage = (event) => {
81
- try {
82
- const data = JSON.parse(event.data);
83
- if (data.type === "connected") {
84
- this.agentId = data.agentId;
85
- resolve();
86
- }
87
- // Skip metadata-only message.new (agents get the richer session.message.new instead)
88
- if (data.type === "message.new") {
89
- return;
90
- }
91
- // Skip echoes: don't emit session messages sent by this agent
92
- if (data.type === "session.message.new" && data.senderType === "agent" && data.senderId === this.agentId) {
93
- return;
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);
94
97
  }
95
- this.emit(data.type, data);
96
- }
97
- catch { /* ignore malformed */ }
98
+ catch { /* ignore malformed */ }
99
+ })();
98
100
  };
99
101
  this.ws.onclose = () => {
100
102
  if (!this.closed && (this.options.autoReconnect ?? true)) {
@@ -157,11 +159,6 @@ export class HiloopWsClient {
157
159
  off(eventType) {
158
160
  this.handlers.delete(eventType);
159
161
  }
160
- /** Auto-decrypt a session message's encryptedContent field. */
161
- async decryptSessionMessage(encryptedContent) {
162
- await this.ensureCrypto();
163
- return this.crypto.decryptSessionMessage(encryptedContent);
164
- }
165
162
  // -- Private ----------------------------------------------------------------
166
163
  send(data) {
167
164
  if (this.ws?.readyState === WebSocket.OPEN) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hiloop-sdk",
3
- "version": "0.4.1",
3
+ "version": "0.5.0",
4
4
  "description": "TypeScript SDK for Hiloop — zero-trust human-AI agent interaction platform",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",