hiloop-sdk 0.5.5 → 0.7.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 +14 -1
- package/dist/client.js +34 -6
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -268,7 +268,9 @@ export declare class HiloopClient {
|
|
|
268
268
|
* Send a message in a conv session. Accepts plaintext — encrypts automatically
|
|
269
269
|
* using the session message key (`{agentPub}:{AES-GCM ciphertext}` format).
|
|
270
270
|
*/
|
|
271
|
-
sendConvSessionMessage(sessionId: string, content: string
|
|
271
|
+
sendConvSessionMessage(sessionId: string, content: string, opts?: {
|
|
272
|
+
agentName?: string;
|
|
273
|
+
}): Promise<ConvSessionMessage>;
|
|
272
274
|
/** Send a typing indicator to a conv session (HU-034). */
|
|
273
275
|
sendConvSessionTyping(sessionId: string, typing: boolean): Promise<void>;
|
|
274
276
|
/** Edit a previously sent conv session message. */
|
|
@@ -840,6 +842,17 @@ export declare class HiloopClient {
|
|
|
840
842
|
}>;
|
|
841
843
|
/** Decrypt an encrypted session message (e.g., from a webhook payload). */
|
|
842
844
|
decryptSessionMessage(encryptedContent: string): Promise<string | null>;
|
|
845
|
+
/**
|
|
846
|
+
* Decrypt an interaction webhook payload in place.
|
|
847
|
+
* Decrypts encryptedTitle, encryptedResponse, encryptedComment using contentWrappings.
|
|
848
|
+
* Returns the payload with added `title`, `response`, `comment` fields.
|
|
849
|
+
*/
|
|
850
|
+
decryptWebhookPayload<T extends Record<string, unknown>>(payload: T): Promise<T & {
|
|
851
|
+
title?: string;
|
|
852
|
+
response?: string;
|
|
853
|
+
comment?: string;
|
|
854
|
+
content?: string;
|
|
855
|
+
}>;
|
|
843
856
|
static generateKeyPair(): KeyPair;
|
|
844
857
|
/** Encrypt plaintext with AES-256-GCM for session messages. */
|
|
845
858
|
static encryptAes(plaintext: string, keyBase64: string): Promise<string>;
|
package/dist/client.js
CHANGED
|
@@ -87,13 +87,14 @@ export class HiloopClient {
|
|
|
87
87
|
this.initialized = true;
|
|
88
88
|
}
|
|
89
89
|
/** Raw HTTP request without triggering auto-init (used during init itself). */
|
|
90
|
-
buildHeaders() {
|
|
90
|
+
buildHeaders(agentName) {
|
|
91
91
|
const h = {
|
|
92
92
|
"Content-Type": "application/json",
|
|
93
93
|
"X-API-Key": this.apiKey,
|
|
94
94
|
};
|
|
95
|
-
|
|
96
|
-
|
|
95
|
+
const agent = agentName ?? this.options.agentName;
|
|
96
|
+
if (agent)
|
|
97
|
+
h["X-Agent"] = agent;
|
|
97
98
|
return h;
|
|
98
99
|
}
|
|
99
100
|
async rawRequest(method, path, options) {
|
|
@@ -164,7 +165,7 @@ export class HiloopClient {
|
|
|
164
165
|
try {
|
|
165
166
|
const res = await fetch(url, {
|
|
166
167
|
method,
|
|
167
|
-
headers: this.buildHeaders(),
|
|
168
|
+
headers: this.buildHeaders(options?.agentName),
|
|
168
169
|
body: options?.body !== undefined ? JSON.stringify(options.body) : undefined,
|
|
169
170
|
signal: controller.signal,
|
|
170
171
|
});
|
|
@@ -551,10 +552,10 @@ export class HiloopClient {
|
|
|
551
552
|
* Send a message in a conv session. Accepts plaintext — encrypts automatically
|
|
552
553
|
* using the session message key (`{agentPub}:{AES-GCM ciphertext}` format).
|
|
553
554
|
*/
|
|
554
|
-
async sendConvSessionMessage(sessionId, content) {
|
|
555
|
+
async sendConvSessionMessage(sessionId, content, opts) {
|
|
555
556
|
await this.ensureInitialized();
|
|
556
557
|
const encryptedContent = await this.crypto.encryptSessionMessage(content);
|
|
557
|
-
const data = await this.request("POST", `/agent/sessions/${sessionId}/messages`, { body: { encryptedContent } });
|
|
558
|
+
const data = await this.request("POST", `/agent/sessions/${sessionId}/messages`, { body: { encryptedContent }, agentName: opts?.agentName });
|
|
558
559
|
return parseConvSessionMessage(data);
|
|
559
560
|
}
|
|
560
561
|
/** Send a typing indicator to a conv session (HU-034). */
|
|
@@ -1236,6 +1237,33 @@ export class HiloopClient {
|
|
|
1236
1237
|
await this.ensureInitialized();
|
|
1237
1238
|
return this.crypto.decryptSessionMessage(encryptedContent);
|
|
1238
1239
|
}
|
|
1240
|
+
/**
|
|
1241
|
+
* Decrypt an interaction webhook payload in place.
|
|
1242
|
+
* Decrypts encryptedTitle, encryptedResponse, encryptedComment using contentWrappings.
|
|
1243
|
+
* Returns the payload with added `title`, `response`, `comment` fields.
|
|
1244
|
+
*/
|
|
1245
|
+
async decryptWebhookPayload(payload) {
|
|
1246
|
+
await this.ensureInitialized();
|
|
1247
|
+
const result = { ...payload };
|
|
1248
|
+
const wrappings = payload.contentWrappings;
|
|
1249
|
+
// Session message
|
|
1250
|
+
if (typeof payload.encryptedContent === "string") {
|
|
1251
|
+
const plain = await this.crypto.decryptSessionMessage(payload.encryptedContent);
|
|
1252
|
+
if (plain !== null)
|
|
1253
|
+
result.content = plain;
|
|
1254
|
+
}
|
|
1255
|
+
// Interaction fields (need content wrappings)
|
|
1256
|
+
if (wrappings?.length) {
|
|
1257
|
+
for (const [encrypted, decrypted] of [["encryptedTitle", "title"], ["encryptedResponse", "response"], ["encryptedComment", "comment"]]) {
|
|
1258
|
+
if (typeof payload[encrypted] === "string") {
|
|
1259
|
+
const plain = await this.crypto.decryptWrappedContent(payload[encrypted], wrappings);
|
|
1260
|
+
if (plain !== null)
|
|
1261
|
+
result[decrypted] = plain;
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
}
|
|
1265
|
+
return result;
|
|
1266
|
+
}
|
|
1239
1267
|
// -- Crypto -----------------------------------------------------------------
|
|
1240
1268
|
static generateKeyPair() {
|
|
1241
1269
|
return generateKeyPair();
|