hiloop-sdk 0.8.7 → 0.9.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/client.d.ts +2 -2
- package/dist/client.js +4 -15
- package/dist/ws.d.ts +3 -3
- package/dist/ws.js +3 -6
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -17,8 +17,8 @@ export interface SendOptions {
|
|
|
17
17
|
}
|
|
18
18
|
export interface HiloopClientOptions {
|
|
19
19
|
apiKey: string;
|
|
20
|
-
/** Agent name
|
|
21
|
-
agentName
|
|
20
|
+
/** Agent name or UUID. Sent as X-Hiloop header to identify the agent. */
|
|
21
|
+
agentName: string;
|
|
22
22
|
baseUrl?: string;
|
|
23
23
|
/** Agent's X25519 secret key (base64). Required for E2E encryption. */
|
|
24
24
|
secretKey?: string;
|
package/dist/client.js
CHANGED
|
@@ -15,10 +15,6 @@ export class HiloopClient {
|
|
|
15
15
|
this.initialized = false;
|
|
16
16
|
this.initPromise = null;
|
|
17
17
|
this.apiKey = options.apiKey;
|
|
18
|
-
if (options.apiKey.startsWith("hlp_prov_")) {
|
|
19
|
-
throw new Error("Provisioning keys (hlp_prov_*) cannot be used with HiloopClient. " +
|
|
20
|
-
"Use the agent API key returned by POST /v1/provision/agents instead.");
|
|
21
|
-
}
|
|
22
18
|
this.baseUrl = (options.baseUrl ?? "https://api.hi-loop.com").replace(/\/$/, "");
|
|
23
19
|
this.timeout = options.timeout ?? 30000;
|
|
24
20
|
this.options = options;
|
|
@@ -38,11 +34,7 @@ export class HiloopClient {
|
|
|
38
34
|
* Initialize encryption: derive keypair from API key, register public key,
|
|
39
35
|
* and fetch space encryption info. Called automatically on first API call.
|
|
40
36
|
*/
|
|
41
|
-
async ensureInitialized(
|
|
42
|
-
// If an agentName is provided and we don't have one yet, store it for init
|
|
43
|
-
if (agentName && !this.options.agentName) {
|
|
44
|
-
this.options = { ...this.options, agentName };
|
|
45
|
-
}
|
|
37
|
+
async ensureInitialized() {
|
|
46
38
|
if (this.initialized)
|
|
47
39
|
return;
|
|
48
40
|
if (this.initPromise)
|
|
@@ -96,14 +88,11 @@ export class HiloopClient {
|
|
|
96
88
|
}
|
|
97
89
|
/** Raw HTTP request without triggering auto-init (used during init itself). */
|
|
98
90
|
buildHeaders(agentName) {
|
|
99
|
-
|
|
91
|
+
return {
|
|
100
92
|
"Content-Type": "application/json",
|
|
101
93
|
"X-API-Key": this.apiKey,
|
|
94
|
+
"X-Hiloop": agentName ?? this.options.agentName,
|
|
102
95
|
};
|
|
103
|
-
const agent = agentName ?? this.options.agentName;
|
|
104
|
-
if (agent)
|
|
105
|
-
h["X-Agent"] = agent;
|
|
106
|
-
return h;
|
|
107
96
|
}
|
|
108
97
|
async rawRequest(method, path, options) {
|
|
109
98
|
const url = `${this.baseUrl}/v1${path}`;
|
|
@@ -319,7 +308,7 @@ export class HiloopClient {
|
|
|
319
308
|
// -- Unified Message API ----------------------------------------------------
|
|
320
309
|
/** Options for send / sendText. */
|
|
321
310
|
async sendComponents(sessionId, components, opts) {
|
|
322
|
-
await this.ensureInitialized(
|
|
311
|
+
await this.ensureInitialized();
|
|
323
312
|
const encryptedComponents = await this.crypto.encryptSessionMessage(JSON.stringify(components));
|
|
324
313
|
const body = { encryptedComponents };
|
|
325
314
|
// Extract metadata from components for server-side routing
|
package/dist/ws.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Usage:
|
|
5
5
|
* const ws = new HiloopWsClient({
|
|
6
|
-
* apiKey: "
|
|
6
|
+
* apiKey: "hlp_...",
|
|
7
7
|
* agentName: "my-bot",
|
|
8
8
|
* });
|
|
9
9
|
* ws.on("session.message.new", (msg) => console.log(msg.content));
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
*/
|
|
14
14
|
export interface HiloopWsClientOptions {
|
|
15
15
|
apiKey: string;
|
|
16
|
-
/** Agent name
|
|
17
|
-
agentName
|
|
16
|
+
/** Agent name or UUID. Sent as X-Hiloop header and query param. */
|
|
17
|
+
agentName: string;
|
|
18
18
|
baseUrl?: string;
|
|
19
19
|
/** Auto-reconnect on disconnect (default: true). */
|
|
20
20
|
autoReconnect?: boolean;
|
package/dist/ws.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Usage:
|
|
5
5
|
* const ws = new HiloopWsClient({
|
|
6
|
-
* apiKey: "
|
|
6
|
+
* apiKey: "hlp_...",
|
|
7
7
|
* agentName: "my-bot",
|
|
8
8
|
* });
|
|
9
9
|
* ws.on("session.message.new", (msg) => console.log(msg.content));
|
|
@@ -41,8 +41,7 @@ export class HiloopWsClient {
|
|
|
41
41
|
"X-API-Key": this.options.apiKey,
|
|
42
42
|
"Content-Type": "application/json",
|
|
43
43
|
};
|
|
44
|
-
|
|
45
|
-
headers["X-Agent"] = this.options.agentName;
|
|
44
|
+
headers["X-Hiloop"] = this.options.agentName;
|
|
46
45
|
// Register public key
|
|
47
46
|
const fingerprint = await computeFingerprint(kp.publicKey);
|
|
48
47
|
try {
|
|
@@ -70,9 +69,7 @@ export class HiloopWsClient {
|
|
|
70
69
|
return new Promise((resolve, reject) => {
|
|
71
70
|
const baseUrl = (this.options.baseUrl ?? "https://api.hi-loop.com").replace(/\/$/, "");
|
|
72
71
|
const wsUrl = baseUrl.replace(/^http/, "ws");
|
|
73
|
-
const params = new URLSearchParams({ key: this.options.apiKey });
|
|
74
|
-
if (this.options.agentName)
|
|
75
|
-
params.set("agent", this.options.agentName);
|
|
72
|
+
const params = new URLSearchParams({ key: this.options.apiKey, agent: this.options.agentName });
|
|
76
73
|
this.ws = new WebSocket(`${wsUrl}/v1/agent/ws?${params}`);
|
|
77
74
|
this.ws.onopen = () => {
|
|
78
75
|
this.reconnectAttempts = 0;
|