@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.cjs CHANGED
@@ -286,12 +286,173 @@ var sessionEncryptionSummarySchema = import_zod2.z.object({
286
286
  });
287
287
  var chatHistoryEntrySchema = import_zod2.z.object({
288
288
  messageId: import_zod2.z.string(),
289
- role: import_zod2.z.enum(["user", "agent"]),
289
+ role: import_zod2.z.enum([
290
+ "user",
291
+ "agent",
292
+ "system",
293
+ "tool",
294
+ "payment",
295
+ "delivery",
296
+ "error"
297
+ ]),
290
298
  content: import_zod2.z.string(),
291
299
  timestamp: import_zod2.z.string(),
292
300
  cipherEnvelope: cipherEnvelopeSchema.optional(),
293
301
  metadata: import_zod2.z.record(jsonValueSchema).optional()
294
302
  });
303
+ var chatDeliveryStateSchema = import_zod2.z.enum([
304
+ "draft",
305
+ "queued",
306
+ "persisted",
307
+ "delivered",
308
+ "streaming",
309
+ "responded",
310
+ "failed",
311
+ "timeout",
312
+ "cancelled"
313
+ ]);
314
+ var chatAttachmentStateSchema = import_zod2.z.object({
315
+ supported: import_zod2.z.boolean(),
316
+ status: import_zod2.z.enum([
317
+ "unsupported",
318
+ "available",
319
+ "selected",
320
+ "uploading",
321
+ "scanning",
322
+ "ready",
323
+ "failed",
324
+ "rejected"
325
+ ]),
326
+ maxBytes: import_zod2.z.number().nullable().optional(),
327
+ acceptedMimeTypes: import_zod2.z.array(import_zod2.z.string()).optional(),
328
+ reason: import_zod2.z.string().optional()
329
+ });
330
+ var chatTimelineEntrySchema = import_zod2.z.object({
331
+ messageId: import_zod2.z.string(),
332
+ kind: import_zod2.z.enum([
333
+ "user",
334
+ "assistant",
335
+ "system",
336
+ "tool",
337
+ "payment",
338
+ "delivery",
339
+ "error"
340
+ ]),
341
+ content: import_zod2.z.string(),
342
+ timestamp: import_zod2.z.string(),
343
+ deliveryState: chatDeliveryStateSchema.optional(),
344
+ errorCode: import_zod2.z.string().optional(),
345
+ metadata: import_zod2.z.record(jsonValueSchema).optional(),
346
+ attachment: chatAttachmentStateSchema.optional()
347
+ });
348
+ var chatReadinessStatusSchema = import_zod2.z.enum([
349
+ "responsive",
350
+ "delivery_only",
351
+ "degraded",
352
+ "blocked",
353
+ "unknown"
354
+ ]);
355
+ var chatReplyModeSchema = import_zod2.z.enum([
356
+ "direct",
357
+ "stream",
358
+ "poll",
359
+ "delivery_only",
360
+ "none"
361
+ ]);
362
+ var chatRouteTypeSchema = import_zod2.z.enum([
363
+ "a2a",
364
+ "hcs-10",
365
+ "mcp",
366
+ "openrouter",
367
+ "acp",
368
+ "xmtp",
369
+ "moltbook",
370
+ "agentverse",
371
+ "nanda",
372
+ "http",
373
+ "erc-8004",
374
+ "x402",
375
+ "unknown"
376
+ ]);
377
+ var chatSessionStateSchema = import_zod2.z.enum([
378
+ "connecting",
379
+ "ready",
380
+ "blocked",
381
+ "ended",
382
+ "expired"
383
+ ]);
384
+ var chatErrorCodeSchema = import_zod2.z.enum([
385
+ "AUTH_REQUIRED",
386
+ "CREDITS_REQUIRED",
387
+ "PAYMENT_REQUIRED",
388
+ "AGENT_UNRESPONSIVE",
389
+ "ROUTE_UNAVAILABLE",
390
+ "PROTOCOL_UNSUPPORTED",
391
+ "BROKER_NOT_EXECUTABLE",
392
+ "NETWORK_TIMEOUT",
393
+ "STREAM_STALLED",
394
+ "HISTORY_UNAVAILABLE",
395
+ "ENCRYPTION_REQUIRED",
396
+ "RATE_LIMITED",
397
+ "VALIDATION_ERROR",
398
+ "UNKNOWN_ERROR"
399
+ ]);
400
+ var chatRouteSummarySchema = import_zod2.z.object({
401
+ type: chatRouteTypeSchema,
402
+ replyMode: chatReplyModeSchema,
403
+ transport: import_zod2.z.string(),
404
+ endpoint: import_zod2.z.string().optional()
405
+ });
406
+ var chatPaymentStateSchema = import_zod2.z.object({
407
+ required: import_zod2.z.boolean(),
408
+ provider: import_zod2.z.enum(["credits", "x402", "acp", "openrouter"]).optional(),
409
+ status: import_zod2.z.enum([
410
+ "not_required",
411
+ "preflight",
412
+ "required",
413
+ "approved",
414
+ "paid",
415
+ "failed"
416
+ ]),
417
+ estimatedCredits: import_zod2.z.number().nullable().optional(),
418
+ estimatedUsd: import_zod2.z.number().nullable().optional()
419
+ });
420
+ var chatReadinessResponseSchema = import_zod2.z.object({
421
+ status: chatReadinessStatusSchema,
422
+ routeType: chatRouteTypeSchema,
423
+ replyMode: chatReplyModeSchema,
424
+ transport: import_zod2.z.string(),
425
+ endpoint: import_zod2.z.string().optional(),
426
+ checkedAt: import_zod2.z.string(),
427
+ cachedUntil: import_zod2.z.string(),
428
+ latencyMs: import_zod2.z.number().nullable().optional(),
429
+ lastSuccessfulReplyAt: import_zod2.z.string().nullable().optional(),
430
+ lastDeliveryConfirmationAt: import_zod2.z.string().nullable().optional(),
431
+ lastFailureCode: chatErrorCodeSchema.nullable().optional(),
432
+ supportsStreaming: import_zod2.z.boolean(),
433
+ supportsHistory: import_zod2.z.boolean(),
434
+ supportsEncryption: import_zod2.z.boolean(),
435
+ supportsPayments: import_zod2.z.boolean(),
436
+ supportsAttachments: import_zod2.z.boolean(),
437
+ requiresAuth: import_zod2.z.boolean(),
438
+ operatorActionRequired: import_zod2.z.boolean(),
439
+ issue: import_zod2.z.object({
440
+ code: import_zod2.z.string(),
441
+ message: import_zod2.z.string(),
442
+ details: import_zod2.z.string().optional()
443
+ }).optional()
444
+ });
445
+ var chatSessionResumeResponseSchema = import_zod2.z.object({
446
+ sessionId: import_zod2.z.string(),
447
+ uaid: import_zod2.z.string().nullable().optional(),
448
+ agentUrl: import_zod2.z.string().nullable().optional(),
449
+ route: chatRouteSummarySchema,
450
+ transport: import_zod2.z.string(),
451
+ history: import_zod2.z.array(chatHistoryEntrySchema),
452
+ historyTtlSeconds: import_zod2.z.number().optional(),
453
+ visibility: import_zod2.z.enum(["private", "public"]).optional(),
454
+ state: chatSessionStateSchema
455
+ });
295
456
  var metadataFacetSchema = import_zod2.z.record(
296
457
  import_zod2.z.union([
297
458
  import_zod2.z.array(jsonValueSchema),
@@ -491,7 +652,16 @@ var createSessionResponseSchema = import_zod2.z.object({
491
652
  }),
492
653
  history: import_zod2.z.array(chatHistoryEntrySchema).optional().default([]),
493
654
  historyTtlSeconds: import_zod2.z.number().nullable().optional(),
494
- encryption: sessionEncryptionSummarySchema.nullable().optional()
655
+ encryption: sessionEncryptionSummarySchema.nullable().optional(),
656
+ route: chatRouteSummarySchema.optional(),
657
+ transport: import_zod2.z.string().optional(),
658
+ senderUaid: import_zod2.z.string().nullable().optional(),
659
+ visibility: import_zod2.z.enum(["private", "public"]).optional(),
660
+ payment: chatPaymentStateSchema.optional(),
661
+ readiness: chatReadinessResponseSchema.optional(),
662
+ state: chatSessionStateSchema.optional(),
663
+ traceId: import_zod2.z.string().optional(),
664
+ expiresAt: import_zod2.z.string().nullable().optional()
495
665
  });
496
666
  var sendMessageResponseSchema = import_zod2.z.object({
497
667
  sessionId: import_zod2.z.string(),
@@ -503,7 +673,20 @@ var sendMessageResponseSchema = import_zod2.z.object({
503
673
  ops: import_zod2.z.array(import_zod2.z.record(jsonValueSchema)).optional(),
504
674
  history: import_zod2.z.array(chatHistoryEntrySchema).optional(),
505
675
  historyTtlSeconds: import_zod2.z.number().nullable().optional(),
506
- encrypted: import_zod2.z.boolean().optional()
676
+ encrypted: import_zod2.z.boolean().optional(),
677
+ messageId: import_zod2.z.string().optional(),
678
+ assistantMessageId: import_zod2.z.string().nullable().optional(),
679
+ deliveryState: chatDeliveryStateSchema.optional(),
680
+ replyMode: chatReplyModeSchema.optional(),
681
+ deliveryConfirmation: import_zod2.z.boolean().optional(),
682
+ idempotent: import_zod2.z.boolean().optional(),
683
+ metadata: import_zod2.z.record(jsonValueSchema).optional(),
684
+ errorCode: chatErrorCodeSchema.optional()
685
+ });
686
+ var chatSessionEndResponseSchema = import_zod2.z.object({
687
+ message: import_zod2.z.string(),
688
+ sessionId: import_zod2.z.string(),
689
+ state: chatSessionStateSchema.optional()
507
690
  });
508
691
  var chatHistorySnapshotResponseSchema = import_zod2.z.object({
509
692
  sessionId: import_zod2.z.string(),
@@ -2977,8 +3160,12 @@ var EncryptedChatManager = class {
2977
3160
  function createChatApi(client, encryptedManager) {
2978
3161
  return {
2979
3162
  start: (options) => client.startChat(options),
3163
+ readiness: (payload) => client.checkChatReadiness(payload),
2980
3164
  createSession: (payload) => client.createSession(payload),
3165
+ resumeSession: (sessionId) => client.resumeSession(sessionId),
2981
3166
  sendMessage: (payload) => client.sendMessage(payload),
3167
+ retryMessage: (messageId, payload) => client.retryMessage(messageId, payload),
3168
+ cancelSession: (sessionId) => client.cancelSession(sessionId),
2982
3169
  endSession: (sessionId) => client.endSession(sessionId),
2983
3170
  getHistory: (sessionId, options) => client.fetchHistorySnapshot(sessionId, options),
2984
3171
  compactHistory: (payload) => client.compactHistory(payload),
@@ -2990,6 +3177,33 @@ function createChatApi(client, encryptedManager) {
2990
3177
  acceptEncryptedSession: (options) => encryptedManager.acceptSession(options)
2991
3178
  };
2992
3179
  }
3180
+ async function checkChatReadiness(client, payload) {
3181
+ const body = {};
3182
+ const uaid = "uaid" in payload ? payload.uaid?.trim() : void 0;
3183
+ const agentUrl = "agentUrl" in payload ? payload.agentUrl?.trim() : void 0;
3184
+ if (!uaid && !agentUrl) {
3185
+ throw new Error("uaid or agentUrl is required to check chat readiness");
3186
+ }
3187
+ if (uaid) {
3188
+ body.uaid = uaid;
3189
+ }
3190
+ if (agentUrl) {
3191
+ body.agentUrl = agentUrl;
3192
+ }
3193
+ if (payload.forceRefresh !== void 0) {
3194
+ body.forceRefresh = payload.forceRefresh;
3195
+ }
3196
+ const raw = await client.requestJson("/chat/readiness", {
3197
+ method: "POST",
3198
+ body,
3199
+ headers: { "content-type": "application/json" }
3200
+ });
3201
+ return client.parseWithSchema(
3202
+ raw,
3203
+ chatReadinessResponseSchema,
3204
+ "chat readiness response"
3205
+ );
3206
+ }
2993
3207
  async function createSession(client, payload, allowHistoryAutoTopUp = true) {
2994
3208
  const body = {};
2995
3209
  if ("uaid" in payload && payload.uaid) {
@@ -3010,6 +3224,12 @@ async function createSession(client, payload, allowHistoryAutoTopUp = true) {
3010
3224
  if (payload.senderUaid) {
3011
3225
  body.senderUaid = payload.senderUaid;
3012
3226
  }
3227
+ if (payload.visibility) {
3228
+ body.visibility = payload.visibility;
3229
+ }
3230
+ if (payload.idempotencyKey) {
3231
+ body.idempotencyKey = payload.idempotencyKey;
3232
+ }
3013
3233
  try {
3014
3234
  const raw = await client.requestJson("/chat/session", {
3015
3235
  method: "POST",
@@ -3030,6 +3250,21 @@ async function createSession(client, payload, allowHistoryAutoTopUp = true) {
3030
3250
  throw error;
3031
3251
  }
3032
3252
  }
3253
+ async function resumeSession(client, sessionId) {
3254
+ const normalized = sessionId.trim();
3255
+ if (!normalized) {
3256
+ throw new Error("sessionId is required to resume a chat session");
3257
+ }
3258
+ const raw = await client.requestJson(
3259
+ `/chat/session/${encodeURIComponent(normalized)}/resume`,
3260
+ { method: "GET" }
3261
+ );
3262
+ return client.parseWithSchema(
3263
+ raw,
3264
+ chatSessionResumeResponseSchema,
3265
+ "chat session resume response"
3266
+ );
3267
+ }
3033
3268
  async function startChat(client, encryptedManager, options) {
3034
3269
  if ("uaid" in options && options.uaid) {
3035
3270
  return startConversation(client, encryptedManager, {
@@ -3244,6 +3479,15 @@ async function sendMessage(client, payload) {
3244
3479
  if (payload.streaming !== void 0) {
3245
3480
  body.streaming = payload.streaming;
3246
3481
  }
3482
+ if (payload.idempotencyKey) {
3483
+ body.idempotencyKey = payload.idempotencyKey;
3484
+ }
3485
+ if (payload.senderUaid) {
3486
+ body.senderUaid = payload.senderUaid;
3487
+ }
3488
+ if (payload.transport) {
3489
+ body.transport = payload.transport;
3490
+ }
3247
3491
  if (payload.auth) {
3248
3492
  body.auth = serialiseAuthConfig(payload.auth);
3249
3493
  }
@@ -3287,9 +3531,130 @@ async function sendMessage(client, payload) {
3287
3531
  );
3288
3532
  }
3289
3533
  async function endSession(client, sessionId) {
3290
- await client.request(`/chat/session/${encodeURIComponent(sessionId)}`, {
3291
- method: "DELETE"
3292
- });
3534
+ const normalizedSessionId = sessionId?.trim();
3535
+ if (!normalizedSessionId) {
3536
+ throw new Error("sessionId is required to end a chat session");
3537
+ }
3538
+ const response = await client.request(
3539
+ `/chat/session/${encodeURIComponent(normalizedSessionId)}`,
3540
+ { method: "DELETE" }
3541
+ );
3542
+ if (response.status === 204) {
3543
+ return {
3544
+ message: "Session ended",
3545
+ sessionId: normalizedSessionId,
3546
+ state: "ended"
3547
+ };
3548
+ }
3549
+ const contentType = response.headers?.get("content-type") ?? "";
3550
+ if (!contentType.toLowerCase().includes("json")) {
3551
+ await response.text();
3552
+ return {
3553
+ message: "Session ended",
3554
+ sessionId: normalizedSessionId,
3555
+ state: "ended"
3556
+ };
3557
+ }
3558
+ const responseBody = await response.text();
3559
+ if (responseBody.trim().length === 0) {
3560
+ return {
3561
+ message: "Session ended",
3562
+ sessionId: normalizedSessionId,
3563
+ state: "ended"
3564
+ };
3565
+ }
3566
+ const raw = JSON.parse(responseBody);
3567
+ return client.parseWithSchema(
3568
+ raw,
3569
+ chatSessionEndResponseSchema,
3570
+ "chat session end response"
3571
+ );
3572
+ }
3573
+ async function cancelSession(client, sessionId) {
3574
+ const normalizedSessionId = sessionId?.trim();
3575
+ if (!normalizedSessionId) {
3576
+ throw new Error("sessionId is required to cancel a chat session");
3577
+ }
3578
+ const raw = await client.requestJson(
3579
+ `/chat/session/${encodeURIComponent(normalizedSessionId)}/cancel`,
3580
+ {
3581
+ method: "POST"
3582
+ }
3583
+ );
3584
+ return client.parseWithSchema(
3585
+ raw,
3586
+ chatSessionEndResponseSchema,
3587
+ "chat session cancel response"
3588
+ );
3589
+ }
3590
+ async function retryMessage(client, messageId, payload) {
3591
+ const normalizedMessageId = messageId?.trim();
3592
+ const normalizedSessionId = payload.sessionId?.trim();
3593
+ const normalizedMessage = payload.message?.trim();
3594
+ if (!normalizedMessageId) {
3595
+ throw new Error("messageId is required to retry a message");
3596
+ }
3597
+ if (!normalizedSessionId) {
3598
+ throw new Error("sessionId is required to retry a message");
3599
+ }
3600
+ if (!normalizedMessage) {
3601
+ throw new Error("message is required to retry a message");
3602
+ }
3603
+ const body = {
3604
+ sessionId: normalizedSessionId,
3605
+ message: payload.message
3606
+ };
3607
+ if (payload.streaming !== void 0) {
3608
+ body.streaming = payload.streaming;
3609
+ }
3610
+ if (payload.transport) {
3611
+ body.transport = payload.transport;
3612
+ }
3613
+ const uaid = payload.uaid?.trim();
3614
+ const agentUrl = payload.agentUrl?.trim();
3615
+ const idempotencyKey = payload.idempotencyKey?.trim();
3616
+ const senderUaid = payload.senderUaid?.trim();
3617
+ if (uaid) {
3618
+ body.uaid = uaid;
3619
+ }
3620
+ if (agentUrl) {
3621
+ body.agentUrl = agentUrl;
3622
+ }
3623
+ if (idempotencyKey) {
3624
+ body.idempotencyKey = idempotencyKey;
3625
+ }
3626
+ if (senderUaid) {
3627
+ body.senderUaid = senderUaid;
3628
+ }
3629
+ if (payload.auth) {
3630
+ body.auth = serialiseAuthConfig(payload.auth);
3631
+ }
3632
+ let cipherEnvelope = payload.cipherEnvelope ?? null;
3633
+ if (payload.encryption) {
3634
+ if (!payload.encryption.recipients?.length) {
3635
+ throw new Error("recipients are required for encrypted chat payloads");
3636
+ }
3637
+ cipherEnvelope = client.encryption.encryptCipherEnvelope({
3638
+ ...payload.encryption,
3639
+ sessionId: payload.encryption.sessionId ?? normalizedSessionId
3640
+ });
3641
+ }
3642
+ if (cipherEnvelope) {
3643
+ body.cipherEnvelope = toJsonObject(cipherEnvelope);
3644
+ }
3645
+ const raw = await client.requestJson(
3646
+ `/chat/message/${encodeURIComponent(normalizedMessageId)}/retry`,
3647
+ {
3648
+ method: "POST",
3649
+ body,
3650
+ headers: { "content-type": "application/json" }
3651
+ }
3652
+ );
3653
+ return client.parseWithSchema(
3654
+ raw,
3655
+ sendMessageResponseSchema,
3656
+ "chat retry response"
3657
+ );
3293
3658
  }
3294
3659
 
3295
3660
  // ../../src/services/registry-broker/client/encryption.ts
@@ -6980,6 +7345,12 @@ var RegistryBrokerClient = class _RegistryBrokerClient {
6980
7345
  async createSession(payload, allowHistoryAutoTopUp = true) {
6981
7346
  return createSession(this, payload, allowHistoryAutoTopUp);
6982
7347
  }
7348
+ async resumeSession(sessionId) {
7349
+ return resumeSession(this, sessionId);
7350
+ }
7351
+ async checkChatReadiness(payload) {
7352
+ return checkChatReadiness(this, payload);
7353
+ }
6983
7354
  async startChat(options) {
6984
7355
  return startChat(this, this.getEncryptedChatManager(), options);
6985
7356
  }
@@ -7005,6 +7376,12 @@ var RegistryBrokerClient = class _RegistryBrokerClient {
7005
7376
  sendMessage(payload) {
7006
7377
  return sendMessage(this, payload);
7007
7378
  }
7379
+ retryMessage(messageId, payload) {
7380
+ return retryMessage(this, messageId, payload);
7381
+ }
7382
+ cancelSession(sessionId) {
7383
+ return cancelSession(this, sessionId);
7384
+ }
7008
7385
  endSession(sessionId) {
7009
7386
  return endSession(this, sessionId);
7010
7387
  }