@hol-org/rb-client 0.1.181 → 0.1.183

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/index.js CHANGED
@@ -225,12 +225,173 @@ var sessionEncryptionSummarySchema = z2.object({
225
225
  });
226
226
  var chatHistoryEntrySchema = z2.object({
227
227
  messageId: z2.string(),
228
- role: z2.enum(["user", "agent"]),
228
+ role: z2.enum([
229
+ "user",
230
+ "agent",
231
+ "system",
232
+ "tool",
233
+ "payment",
234
+ "delivery",
235
+ "error"
236
+ ]),
229
237
  content: z2.string(),
230
238
  timestamp: z2.string(),
231
239
  cipherEnvelope: cipherEnvelopeSchema.optional(),
232
240
  metadata: z2.record(jsonValueSchema).optional()
233
241
  });
242
+ var chatDeliveryStateSchema = z2.enum([
243
+ "draft",
244
+ "queued",
245
+ "persisted",
246
+ "delivered",
247
+ "streaming",
248
+ "responded",
249
+ "failed",
250
+ "timeout",
251
+ "cancelled"
252
+ ]);
253
+ var chatAttachmentStateSchema = z2.object({
254
+ supported: z2.boolean(),
255
+ status: z2.enum([
256
+ "unsupported",
257
+ "available",
258
+ "selected",
259
+ "uploading",
260
+ "scanning",
261
+ "ready",
262
+ "failed",
263
+ "rejected"
264
+ ]),
265
+ maxBytes: z2.number().nullable().optional(),
266
+ acceptedMimeTypes: z2.array(z2.string()).optional(),
267
+ reason: z2.string().optional()
268
+ });
269
+ var chatTimelineEntrySchema = z2.object({
270
+ messageId: z2.string(),
271
+ kind: z2.enum([
272
+ "user",
273
+ "assistant",
274
+ "system",
275
+ "tool",
276
+ "payment",
277
+ "delivery",
278
+ "error"
279
+ ]),
280
+ content: z2.string(),
281
+ timestamp: z2.string(),
282
+ deliveryState: chatDeliveryStateSchema.optional(),
283
+ errorCode: z2.string().optional(),
284
+ metadata: z2.record(jsonValueSchema).optional(),
285
+ attachment: chatAttachmentStateSchema.optional()
286
+ });
287
+ var chatReadinessStatusSchema = z2.enum([
288
+ "responsive",
289
+ "delivery_only",
290
+ "degraded",
291
+ "blocked",
292
+ "unknown"
293
+ ]);
294
+ var chatReplyModeSchema = z2.enum([
295
+ "direct",
296
+ "stream",
297
+ "poll",
298
+ "delivery_only",
299
+ "none"
300
+ ]);
301
+ var chatRouteTypeSchema = z2.enum([
302
+ "a2a",
303
+ "hcs-10",
304
+ "mcp",
305
+ "openrouter",
306
+ "acp",
307
+ "xmtp",
308
+ "moltbook",
309
+ "agentverse",
310
+ "nanda",
311
+ "http",
312
+ "erc-8004",
313
+ "x402",
314
+ "unknown"
315
+ ]);
316
+ var chatSessionStateSchema = z2.enum([
317
+ "connecting",
318
+ "ready",
319
+ "blocked",
320
+ "ended",
321
+ "expired"
322
+ ]);
323
+ var chatErrorCodeSchema = z2.enum([
324
+ "AUTH_REQUIRED",
325
+ "CREDITS_REQUIRED",
326
+ "PAYMENT_REQUIRED",
327
+ "AGENT_UNRESPONSIVE",
328
+ "ROUTE_UNAVAILABLE",
329
+ "PROTOCOL_UNSUPPORTED",
330
+ "BROKER_NOT_EXECUTABLE",
331
+ "NETWORK_TIMEOUT",
332
+ "STREAM_STALLED",
333
+ "HISTORY_UNAVAILABLE",
334
+ "ENCRYPTION_REQUIRED",
335
+ "RATE_LIMITED",
336
+ "VALIDATION_ERROR",
337
+ "UNKNOWN_ERROR"
338
+ ]);
339
+ var chatRouteSummarySchema = z2.object({
340
+ type: chatRouteTypeSchema,
341
+ replyMode: chatReplyModeSchema,
342
+ transport: z2.string(),
343
+ endpoint: z2.string().optional()
344
+ });
345
+ var chatPaymentStateSchema = z2.object({
346
+ required: z2.boolean(),
347
+ provider: z2.enum(["credits", "x402", "acp", "openrouter"]).optional(),
348
+ status: z2.enum([
349
+ "not_required",
350
+ "preflight",
351
+ "required",
352
+ "approved",
353
+ "paid",
354
+ "failed"
355
+ ]),
356
+ estimatedCredits: z2.number().nullable().optional(),
357
+ estimatedUsd: z2.number().nullable().optional()
358
+ });
359
+ var chatReadinessResponseSchema = z2.object({
360
+ status: chatReadinessStatusSchema,
361
+ routeType: chatRouteTypeSchema,
362
+ replyMode: chatReplyModeSchema,
363
+ transport: z2.string(),
364
+ endpoint: z2.string().optional(),
365
+ checkedAt: z2.string(),
366
+ cachedUntil: z2.string(),
367
+ latencyMs: z2.number().nullable().optional(),
368
+ lastSuccessfulReplyAt: z2.string().nullable().optional(),
369
+ lastDeliveryConfirmationAt: z2.string().nullable().optional(),
370
+ lastFailureCode: chatErrorCodeSchema.nullable().optional(),
371
+ supportsStreaming: z2.boolean(),
372
+ supportsHistory: z2.boolean(),
373
+ supportsEncryption: z2.boolean(),
374
+ supportsPayments: z2.boolean(),
375
+ supportsAttachments: z2.boolean(),
376
+ requiresAuth: z2.boolean(),
377
+ operatorActionRequired: z2.boolean(),
378
+ issue: z2.object({
379
+ code: z2.string(),
380
+ message: z2.string(),
381
+ details: z2.string().optional()
382
+ }).optional()
383
+ });
384
+ var chatSessionResumeResponseSchema = z2.object({
385
+ sessionId: z2.string(),
386
+ uaid: z2.string().nullable().optional(),
387
+ agentUrl: z2.string().nullable().optional(),
388
+ route: chatRouteSummarySchema,
389
+ transport: z2.string(),
390
+ history: z2.array(chatHistoryEntrySchema),
391
+ historyTtlSeconds: z2.number().optional(),
392
+ visibility: z2.enum(["private", "public"]).optional(),
393
+ state: chatSessionStateSchema
394
+ });
234
395
  var metadataFacetSchema = z2.record(
235
396
  z2.union([
236
397
  z2.array(jsonValueSchema),
@@ -430,7 +591,16 @@ var createSessionResponseSchema = z2.object({
430
591
  }),
431
592
  history: z2.array(chatHistoryEntrySchema).optional().default([]),
432
593
  historyTtlSeconds: z2.number().nullable().optional(),
433
- encryption: sessionEncryptionSummarySchema.nullable().optional()
594
+ encryption: sessionEncryptionSummarySchema.nullable().optional(),
595
+ route: chatRouteSummarySchema.optional(),
596
+ transport: z2.string().optional(),
597
+ senderUaid: z2.string().nullable().optional(),
598
+ visibility: z2.enum(["private", "public"]).optional(),
599
+ payment: chatPaymentStateSchema.optional(),
600
+ readiness: chatReadinessResponseSchema.optional(),
601
+ state: chatSessionStateSchema.optional(),
602
+ traceId: z2.string().optional(),
603
+ expiresAt: z2.string().nullable().optional()
434
604
  });
435
605
  var sendMessageResponseSchema = z2.object({
436
606
  sessionId: z2.string(),
@@ -442,7 +612,20 @@ var sendMessageResponseSchema = z2.object({
442
612
  ops: z2.array(z2.record(jsonValueSchema)).optional(),
443
613
  history: z2.array(chatHistoryEntrySchema).optional(),
444
614
  historyTtlSeconds: z2.number().nullable().optional(),
445
- encrypted: z2.boolean().optional()
615
+ encrypted: z2.boolean().optional(),
616
+ messageId: z2.string().optional(),
617
+ assistantMessageId: z2.string().nullable().optional(),
618
+ deliveryState: chatDeliveryStateSchema.optional(),
619
+ replyMode: chatReplyModeSchema.optional(),
620
+ deliveryConfirmation: z2.boolean().optional(),
621
+ idempotent: z2.boolean().optional(),
622
+ metadata: z2.record(jsonValueSchema).optional(),
623
+ errorCode: chatErrorCodeSchema.optional()
624
+ });
625
+ var chatSessionEndResponseSchema = z2.object({
626
+ message: z2.string(),
627
+ sessionId: z2.string(),
628
+ state: chatSessionStateSchema.optional()
446
629
  });
447
630
  var chatHistorySnapshotResponseSchema = z2.object({
448
631
  sessionId: z2.string(),
@@ -2916,8 +3099,12 @@ var EncryptedChatManager = class {
2916
3099
  function createChatApi(client, encryptedManager) {
2917
3100
  return {
2918
3101
  start: (options) => client.startChat(options),
3102
+ readiness: (payload) => client.checkChatReadiness(payload),
2919
3103
  createSession: (payload) => client.createSession(payload),
3104
+ resumeSession: (sessionId) => client.resumeSession(sessionId),
2920
3105
  sendMessage: (payload) => client.sendMessage(payload),
3106
+ retryMessage: (messageId, payload) => client.retryMessage(messageId, payload),
3107
+ cancelSession: (sessionId) => client.cancelSession(sessionId),
2921
3108
  endSession: (sessionId) => client.endSession(sessionId),
2922
3109
  getHistory: (sessionId, options) => client.fetchHistorySnapshot(sessionId, options),
2923
3110
  compactHistory: (payload) => client.compactHistory(payload),
@@ -2929,6 +3116,33 @@ function createChatApi(client, encryptedManager) {
2929
3116
  acceptEncryptedSession: (options) => encryptedManager.acceptSession(options)
2930
3117
  };
2931
3118
  }
3119
+ async function checkChatReadiness(client, payload) {
3120
+ const body = {};
3121
+ const uaid = "uaid" in payload ? payload.uaid?.trim() : void 0;
3122
+ const agentUrl = "agentUrl" in payload ? payload.agentUrl?.trim() : void 0;
3123
+ if (!uaid && !agentUrl) {
3124
+ throw new Error("uaid or agentUrl is required to check chat readiness");
3125
+ }
3126
+ if (uaid) {
3127
+ body.uaid = uaid;
3128
+ }
3129
+ if (agentUrl) {
3130
+ body.agentUrl = agentUrl;
3131
+ }
3132
+ if (payload.forceRefresh !== void 0) {
3133
+ body.forceRefresh = payload.forceRefresh;
3134
+ }
3135
+ const raw = await client.requestJson("/chat/readiness", {
3136
+ method: "POST",
3137
+ body,
3138
+ headers: { "content-type": "application/json" }
3139
+ });
3140
+ return client.parseWithSchema(
3141
+ raw,
3142
+ chatReadinessResponseSchema,
3143
+ "chat readiness response"
3144
+ );
3145
+ }
2932
3146
  async function createSession(client, payload, allowHistoryAutoTopUp = true) {
2933
3147
  const body = {};
2934
3148
  if ("uaid" in payload && payload.uaid) {
@@ -2949,6 +3163,12 @@ async function createSession(client, payload, allowHistoryAutoTopUp = true) {
2949
3163
  if (payload.senderUaid) {
2950
3164
  body.senderUaid = payload.senderUaid;
2951
3165
  }
3166
+ if (payload.visibility) {
3167
+ body.visibility = payload.visibility;
3168
+ }
3169
+ if (payload.idempotencyKey) {
3170
+ body.idempotencyKey = payload.idempotencyKey;
3171
+ }
2952
3172
  try {
2953
3173
  const raw = await client.requestJson("/chat/session", {
2954
3174
  method: "POST",
@@ -2969,6 +3189,21 @@ async function createSession(client, payload, allowHistoryAutoTopUp = true) {
2969
3189
  throw error;
2970
3190
  }
2971
3191
  }
3192
+ async function resumeSession(client, sessionId) {
3193
+ const normalized = sessionId.trim();
3194
+ if (!normalized) {
3195
+ throw new Error("sessionId is required to resume a chat session");
3196
+ }
3197
+ const raw = await client.requestJson(
3198
+ `/chat/session/${encodeURIComponent(normalized)}/resume`,
3199
+ { method: "GET" }
3200
+ );
3201
+ return client.parseWithSchema(
3202
+ raw,
3203
+ chatSessionResumeResponseSchema,
3204
+ "chat session resume response"
3205
+ );
3206
+ }
2972
3207
  async function startChat(client, encryptedManager, options) {
2973
3208
  if ("uaid" in options && options.uaid) {
2974
3209
  return startConversation(client, encryptedManager, {
@@ -3183,6 +3418,15 @@ async function sendMessage(client, payload) {
3183
3418
  if (payload.streaming !== void 0) {
3184
3419
  body.streaming = payload.streaming;
3185
3420
  }
3421
+ if (payload.idempotencyKey) {
3422
+ body.idempotencyKey = payload.idempotencyKey;
3423
+ }
3424
+ if (payload.senderUaid) {
3425
+ body.senderUaid = payload.senderUaid;
3426
+ }
3427
+ if (payload.transport) {
3428
+ body.transport = payload.transport;
3429
+ }
3186
3430
  if (payload.auth) {
3187
3431
  body.auth = serialiseAuthConfig(payload.auth);
3188
3432
  }
@@ -3226,9 +3470,130 @@ async function sendMessage(client, payload) {
3226
3470
  );
3227
3471
  }
3228
3472
  async function endSession(client, sessionId) {
3229
- await client.request(`/chat/session/${encodeURIComponent(sessionId)}`, {
3230
- method: "DELETE"
3231
- });
3473
+ const normalizedSessionId = sessionId?.trim();
3474
+ if (!normalizedSessionId) {
3475
+ throw new Error("sessionId is required to end a chat session");
3476
+ }
3477
+ const response = await client.request(
3478
+ `/chat/session/${encodeURIComponent(normalizedSessionId)}`,
3479
+ { method: "DELETE" }
3480
+ );
3481
+ if (response.status === 204) {
3482
+ return {
3483
+ message: "Session ended",
3484
+ sessionId: normalizedSessionId,
3485
+ state: "ended"
3486
+ };
3487
+ }
3488
+ const contentType = response.headers?.get("content-type") ?? "";
3489
+ if (!contentType.toLowerCase().includes("json")) {
3490
+ await response.text();
3491
+ return {
3492
+ message: "Session ended",
3493
+ sessionId: normalizedSessionId,
3494
+ state: "ended"
3495
+ };
3496
+ }
3497
+ const responseBody = await response.text();
3498
+ if (responseBody.trim().length === 0) {
3499
+ return {
3500
+ message: "Session ended",
3501
+ sessionId: normalizedSessionId,
3502
+ state: "ended"
3503
+ };
3504
+ }
3505
+ const raw = JSON.parse(responseBody);
3506
+ return client.parseWithSchema(
3507
+ raw,
3508
+ chatSessionEndResponseSchema,
3509
+ "chat session end response"
3510
+ );
3511
+ }
3512
+ async function cancelSession(client, sessionId) {
3513
+ const normalizedSessionId = sessionId?.trim();
3514
+ if (!normalizedSessionId) {
3515
+ throw new Error("sessionId is required to cancel a chat session");
3516
+ }
3517
+ const raw = await client.requestJson(
3518
+ `/chat/session/${encodeURIComponent(normalizedSessionId)}/cancel`,
3519
+ {
3520
+ method: "POST"
3521
+ }
3522
+ );
3523
+ return client.parseWithSchema(
3524
+ raw,
3525
+ chatSessionEndResponseSchema,
3526
+ "chat session cancel response"
3527
+ );
3528
+ }
3529
+ async function retryMessage(client, messageId, payload) {
3530
+ const normalizedMessageId = messageId?.trim();
3531
+ const normalizedSessionId = payload.sessionId?.trim();
3532
+ const normalizedMessage = payload.message?.trim();
3533
+ if (!normalizedMessageId) {
3534
+ throw new Error("messageId is required to retry a message");
3535
+ }
3536
+ if (!normalizedSessionId) {
3537
+ throw new Error("sessionId is required to retry a message");
3538
+ }
3539
+ if (!normalizedMessage) {
3540
+ throw new Error("message is required to retry a message");
3541
+ }
3542
+ const body = {
3543
+ sessionId: normalizedSessionId,
3544
+ message: payload.message
3545
+ };
3546
+ if (payload.streaming !== void 0) {
3547
+ body.streaming = payload.streaming;
3548
+ }
3549
+ if (payload.transport) {
3550
+ body.transport = payload.transport;
3551
+ }
3552
+ const uaid = payload.uaid?.trim();
3553
+ const agentUrl = payload.agentUrl?.trim();
3554
+ const idempotencyKey = payload.idempotencyKey?.trim();
3555
+ const senderUaid = payload.senderUaid?.trim();
3556
+ if (uaid) {
3557
+ body.uaid = uaid;
3558
+ }
3559
+ if (agentUrl) {
3560
+ body.agentUrl = agentUrl;
3561
+ }
3562
+ if (idempotencyKey) {
3563
+ body.idempotencyKey = idempotencyKey;
3564
+ }
3565
+ if (senderUaid) {
3566
+ body.senderUaid = senderUaid;
3567
+ }
3568
+ if (payload.auth) {
3569
+ body.auth = serialiseAuthConfig(payload.auth);
3570
+ }
3571
+ let cipherEnvelope = payload.cipherEnvelope ?? null;
3572
+ if (payload.encryption) {
3573
+ if (!payload.encryption.recipients?.length) {
3574
+ throw new Error("recipients are required for encrypted chat payloads");
3575
+ }
3576
+ cipherEnvelope = client.encryption.encryptCipherEnvelope({
3577
+ ...payload.encryption,
3578
+ sessionId: payload.encryption.sessionId ?? normalizedSessionId
3579
+ });
3580
+ }
3581
+ if (cipherEnvelope) {
3582
+ body.cipherEnvelope = toJsonObject(cipherEnvelope);
3583
+ }
3584
+ const raw = await client.requestJson(
3585
+ `/chat/message/${encodeURIComponent(normalizedMessageId)}/retry`,
3586
+ {
3587
+ method: "POST",
3588
+ body,
3589
+ headers: { "content-type": "application/json" }
3590
+ }
3591
+ );
3592
+ return client.parseWithSchema(
3593
+ raw,
3594
+ sendMessageResponseSchema,
3595
+ "chat retry response"
3596
+ );
3232
3597
  }
3233
3598
 
3234
3599
  // ../../src/services/registry-broker/client/encryption.ts
@@ -6918,6 +7283,12 @@ var RegistryBrokerClient = class _RegistryBrokerClient {
6918
7283
  async createSession(payload, allowHistoryAutoTopUp = true) {
6919
7284
  return createSession(this, payload, allowHistoryAutoTopUp);
6920
7285
  }
7286
+ async resumeSession(sessionId) {
7287
+ return resumeSession(this, sessionId);
7288
+ }
7289
+ async checkChatReadiness(payload) {
7290
+ return checkChatReadiness(this, payload);
7291
+ }
6921
7292
  async startChat(options) {
6922
7293
  return startChat(this, this.getEncryptedChatManager(), options);
6923
7294
  }
@@ -6943,6 +7314,12 @@ var RegistryBrokerClient = class _RegistryBrokerClient {
6943
7314
  sendMessage(payload) {
6944
7315
  return sendMessage(this, payload);
6945
7316
  }
7317
+ retryMessage(messageId, payload) {
7318
+ return retryMessage(this, messageId, payload);
7319
+ }
7320
+ cancelSession(sessionId) {
7321
+ return cancelSession(this, sessionId);
7322
+ }
6946
7323
  endSession(sessionId) {
6947
7324
  return endSession(this, sessionId);
6948
7325
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hol-org/rb-client",
3
- "version": "0.1.181",
3
+ "version": "0.1.183",
4
4
  "description": "Lightweight Registry Broker client for HOL registries.",
5
5
  "type": "module",
6
6
  "files": [