hiloop-sdk 0.2.0 → 0.3.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 +3 -0
- package/dist/client.js +17 -9
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -7,6 +7,8 @@ export declare class HiloopError extends Error {
|
|
|
7
7
|
}
|
|
8
8
|
export interface HiloopClientOptions {
|
|
9
9
|
apiKey: string;
|
|
10
|
+
/** Agent name. Auto-creates the agent if it doesn't exist (space API keys only). */
|
|
11
|
+
agentName?: string;
|
|
10
12
|
baseUrl?: string;
|
|
11
13
|
/** Agent's X25519 secret key (base64). Required for E2E encryption. */
|
|
12
14
|
secretKey?: string;
|
|
@@ -38,6 +40,7 @@ export declare class HiloopClient {
|
|
|
38
40
|
private ensureInitialized;
|
|
39
41
|
private doInit;
|
|
40
42
|
/** Raw HTTP request without triggering auto-init (used during init itself). */
|
|
43
|
+
private buildHeaders;
|
|
41
44
|
private rawRequest;
|
|
42
45
|
private encryptField;
|
|
43
46
|
/**
|
package/dist/client.js
CHANGED
|
@@ -87,15 +87,20 @@ export class HiloopClient {
|
|
|
87
87
|
this.initialized = true;
|
|
88
88
|
}
|
|
89
89
|
/** Raw HTTP request without triggering auto-init (used during init itself). */
|
|
90
|
-
|
|
91
|
-
const
|
|
92
|
-
const headers = {
|
|
90
|
+
buildHeaders() {
|
|
91
|
+
const h = {
|
|
93
92
|
"Content-Type": "application/json",
|
|
94
93
|
"X-API-Key": this.apiKey,
|
|
95
94
|
};
|
|
95
|
+
if (this.options.agentName)
|
|
96
|
+
h["X-Agent"] = this.options.agentName;
|
|
97
|
+
return h;
|
|
98
|
+
}
|
|
99
|
+
async rawRequest(method, path, options) {
|
|
100
|
+
const url = `${this.baseUrl}/v1${path}`;
|
|
96
101
|
const res = await fetch(url, {
|
|
97
102
|
method,
|
|
98
|
-
headers,
|
|
103
|
+
headers: this.buildHeaders(),
|
|
99
104
|
body: options?.body ? JSON.stringify(options.body) : undefined,
|
|
100
105
|
});
|
|
101
106
|
if (!res.ok) {
|
|
@@ -115,6 +120,7 @@ export class HiloopClient {
|
|
|
115
120
|
* with the same (scope, recipientKeyId) are silently dropped.
|
|
116
121
|
*/
|
|
117
122
|
async encryptFields(fields) {
|
|
123
|
+
await this.ensureInitialized();
|
|
118
124
|
const encrypted = {};
|
|
119
125
|
const entries = Object.entries(fields).filter(([, v]) => v !== undefined);
|
|
120
126
|
if (entries.length === 0)
|
|
@@ -158,10 +164,7 @@ export class HiloopClient {
|
|
|
158
164
|
try {
|
|
159
165
|
const res = await fetch(url, {
|
|
160
166
|
method,
|
|
161
|
-
headers:
|
|
162
|
-
"X-API-Key": this.apiKey,
|
|
163
|
-
"Content-Type": "application/json",
|
|
164
|
-
},
|
|
167
|
+
headers: this.buildHeaders(),
|
|
165
168
|
body: options?.body !== undefined ? JSON.stringify(options.body) : undefined,
|
|
166
169
|
signal: controller.signal,
|
|
167
170
|
});
|
|
@@ -184,7 +187,7 @@ export class HiloopClient {
|
|
|
184
187
|
try {
|
|
185
188
|
const res = await fetch(url, {
|
|
186
189
|
method: "GET",
|
|
187
|
-
headers:
|
|
190
|
+
headers: this.buildHeaders(),
|
|
188
191
|
signal: controller.signal,
|
|
189
192
|
});
|
|
190
193
|
if (!res.ok) {
|
|
@@ -358,6 +361,7 @@ export class HiloopClient {
|
|
|
358
361
|
}
|
|
359
362
|
/** Push content blocks to an interaction. */
|
|
360
363
|
async pushContentBlocks(interactionId, blocks) {
|
|
364
|
+
await this.ensureInitialized();
|
|
361
365
|
const encryptedBlocks = await Promise.all(blocks.map(async (block) => {
|
|
362
366
|
const plaintext = JSON.stringify(block.data);
|
|
363
367
|
const wrapped = await this.crypto.encryptWithWrapping(plaintext);
|
|
@@ -488,6 +492,7 @@ export class HiloopClient {
|
|
|
488
492
|
}
|
|
489
493
|
// -- Conversation Sessions -------------------------------------------------
|
|
490
494
|
async createConvSession(opts) {
|
|
495
|
+
await this.ensureInitialized();
|
|
491
496
|
const body = {
|
|
492
497
|
sessionType: opts.sessionType ?? "direct",
|
|
493
498
|
isPublic: opts.isPublic ?? false,
|
|
@@ -547,6 +552,7 @@ export class HiloopClient {
|
|
|
547
552
|
* using the session message key (`{agentPub}:{AES-GCM ciphertext}` format).
|
|
548
553
|
*/
|
|
549
554
|
async sendConvSessionMessage(sessionId, content) {
|
|
555
|
+
await this.ensureInitialized();
|
|
550
556
|
const encryptedContent = await this.crypto.encryptSessionMessage(content);
|
|
551
557
|
const data = await this.request("POST", `/agent/sessions/${sessionId}/messages`, { body: { encryptedContent } });
|
|
552
558
|
return parseConvSessionMessage(data);
|
|
@@ -1039,6 +1045,7 @@ export class HiloopClient {
|
|
|
1039
1045
|
// -- Channels ---------------------------------------------------------------
|
|
1040
1046
|
/** Create a new agent-to-agent channel. */
|
|
1041
1047
|
async createChannel(opts) {
|
|
1048
|
+
await this.ensureInitialized();
|
|
1042
1049
|
const body = {};
|
|
1043
1050
|
if (opts.name !== undefined) {
|
|
1044
1051
|
const w = await this.crypto.encryptWithWrapping(opts.name);
|
|
@@ -1095,6 +1102,7 @@ export class HiloopClient {
|
|
|
1095
1102
|
}
|
|
1096
1103
|
/** Send a message in a channel. */
|
|
1097
1104
|
async sendChannelMessage(channelId, content) {
|
|
1105
|
+
await this.ensureInitialized();
|
|
1098
1106
|
const wrapped = await this.crypto.encryptWithWrapping(content);
|
|
1099
1107
|
const body = {
|
|
1100
1108
|
encryptedContent: wrapped.ciphertext,
|