hiloop-sdk 0.8.6 → 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 CHANGED
@@ -10,11 +10,15 @@ export interface SendOptions {
10
10
  priority?: string;
11
11
  deadlineMinutes?: number;
12
12
  replyToMessageId?: string;
13
+ /** Client-supplied correlation key (e.g. tool_use_id). Unique per session. */
14
+ referenceId?: string;
15
+ /** Resolve a referenceId to a message and set replyToMessageId automatically. */
16
+ replyToReferenceId?: string;
13
17
  }
14
18
  export interface HiloopClientOptions {
15
19
  apiKey: string;
16
- /** Agent name. Auto-creates the agent if it doesn't exist (space API keys only). */
17
- agentName?: string;
20
+ /** Agent name or UUID. Sent as X-Hiloop header to identify the agent. */
21
+ agentName: string;
18
22
  baseUrl?: string;
19
23
  /** Agent's X25519 secret key (base64). Required for E2E encryption. */
20
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(agentName) {
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
- const h = {
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(opts?.agentName);
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
@@ -335,6 +324,10 @@ export class HiloopClient {
335
324
  body.deadlineMinutes = opts.deadlineMinutes;
336
325
  if (opts?.replyToMessageId)
337
326
  body.replyToMessageId = opts.replyToMessageId;
327
+ if (opts?.referenceId)
328
+ body.referenceId = opts.referenceId;
329
+ if (opts?.replyToReferenceId)
330
+ body.replyToReferenceId = opts.replyToReferenceId;
338
331
  const data = await this.request("POST", `/agent/sessions/${sessionId}/messages`, { body, agentName: opts?.agentName });
339
332
  return parseSessionMessage(data);
340
333
  }
package/dist/types.d.ts CHANGED
@@ -139,6 +139,7 @@ export interface SessionMessage {
139
139
  priority?: string | null;
140
140
  status?: string | null;
141
141
  deadlineAt?: string | null;
142
+ referenceId?: string | null;
142
143
  replyToMessageId?: string | null;
143
144
  respondedAt?: string | null;
144
145
  viewedAt?: string | null;
package/dist/types.js CHANGED
@@ -100,6 +100,7 @@ export function parseSessionMessage(data) {
100
100
  priority: m.priority ?? null,
101
101
  status: m.status ?? null,
102
102
  deadlineAt: m.deadlineAt ?? null,
103
+ referenceId: m.referenceId ?? null,
103
104
  replyToMessageId: m.replyToMessageId ?? null,
104
105
  respondedAt: m.respondedAt ?? null,
105
106
  viewedAt: m.viewedAt ?? null,
package/dist/ws.d.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * Usage:
5
5
  * const ws = new HiloopWsClient({
6
- * apiKey: "hlp_space_...",
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 (required for space API keys, auto-creates if needed). */
17
- agentName?: string;
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: "hlp_space_...",
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
- if (this.options.agentName)
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hiloop-sdk",
3
- "version": "0.8.6",
3
+ "version": "0.9.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",