hiloop-sdk 0.8.1 → 0.8.3
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.js +9 -5
- package/dist/crypto.js +4 -0
- package/package.json +1 -1
package/dist/client.js
CHANGED
|
@@ -34,7 +34,11 @@ export class HiloopClient {
|
|
|
34
34
|
* Initialize encryption: derive keypair from API key, register public key,
|
|
35
35
|
* and fetch space encryption info. Called automatically on first API call.
|
|
36
36
|
*/
|
|
37
|
-
async ensureInitialized() {
|
|
37
|
+
async ensureInitialized(agentName) {
|
|
38
|
+
// If an agentName is provided and we don't have one yet, store it for init
|
|
39
|
+
if (agentName && !this.options.agentName) {
|
|
40
|
+
this.options = { ...this.options, agentName };
|
|
41
|
+
}
|
|
38
42
|
if (this.initialized)
|
|
39
43
|
return;
|
|
40
44
|
if (this.initPromise)
|
|
@@ -75,8 +79,8 @@ export class HiloopClient {
|
|
|
75
79
|
if (!spacePublicKey || !spaceKeyId) {
|
|
76
80
|
try {
|
|
77
81
|
const info = await this.rawRequest("GET", "/agent/encryption-info");
|
|
78
|
-
spacePublicKey = info.spacePublicKey;
|
|
79
|
-
spaceKeyId = info.spaceKeyId;
|
|
82
|
+
spacePublicKey = info.spacePublicKey ?? "";
|
|
83
|
+
spaceKeyId = info.spaceKeyId ?? "";
|
|
80
84
|
}
|
|
81
85
|
catch {
|
|
82
86
|
// Space key not available — crypto operations will fail but non-crypto calls work
|
|
@@ -101,7 +105,7 @@ export class HiloopClient {
|
|
|
101
105
|
const url = `${this.baseUrl}/v1${path}`;
|
|
102
106
|
const res = await fetch(url, {
|
|
103
107
|
method,
|
|
104
|
-
headers: this.buildHeaders(),
|
|
108
|
+
headers: this.buildHeaders(options?.agentName),
|
|
105
109
|
body: options?.body ? JSON.stringify(options.body) : undefined,
|
|
106
110
|
});
|
|
107
111
|
if (!res.ok) {
|
|
@@ -316,7 +320,7 @@ export class HiloopClient {
|
|
|
316
320
|
* This is the primary method for agent-to-human communication.
|
|
317
321
|
*/
|
|
318
322
|
async sendMessage(sessionId, content, opts) {
|
|
319
|
-
await this.ensureInitialized();
|
|
323
|
+
await this.ensureInitialized(opts?.agentName);
|
|
320
324
|
const encryptedContent = await this.crypto.encryptSessionMessage(content);
|
|
321
325
|
const body = { encryptedContent };
|
|
322
326
|
if (opts?.components && opts.components.length > 0) {
|
package/dist/crypto.js
CHANGED
|
@@ -141,6 +141,10 @@ export class CryptoContext {
|
|
|
141
141
|
}
|
|
142
142
|
/** Compute X25519 ECDH shared secret with the recipient (space) public key. */
|
|
143
143
|
getSharedSecret() {
|
|
144
|
+
if (!this.recipientPublicKeyB64) {
|
|
145
|
+
throw new Error("Space public key not available. This usually means the space has no encryption keys yet — " +
|
|
146
|
+
"ensure a human user has logged into the space at least once to generate keys.");
|
|
147
|
+
}
|
|
144
148
|
const sk = util.decodeBase64(this.secretKeyB64);
|
|
145
149
|
const pk = util.decodeBase64(this.recipientPublicKeyB64);
|
|
146
150
|
return util.encodeBase64(nacl.scalarMult(sk, pk));
|