@hol-org/rb-client 0.1.181 → 0.1.182

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,128 @@ 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 chatReadinessStatusSchema = z2.enum([
254
+ "responsive",
255
+ "delivery_only",
256
+ "degraded",
257
+ "blocked",
258
+ "unknown"
259
+ ]);
260
+ var chatReplyModeSchema = z2.enum([
261
+ "direct",
262
+ "stream",
263
+ "poll",
264
+ "delivery_only",
265
+ "none"
266
+ ]);
267
+ var chatRouteTypeSchema = z2.enum([
268
+ "a2a",
269
+ "hcs-10",
270
+ "mcp",
271
+ "openrouter",
272
+ "acp",
273
+ "xmtp",
274
+ "moltbook",
275
+ "agentverse",
276
+ "nanda",
277
+ "http",
278
+ "erc-8004",
279
+ "x402",
280
+ "unknown"
281
+ ]);
282
+ var chatSessionStateSchema = z2.enum([
283
+ "connecting",
284
+ "ready",
285
+ "blocked",
286
+ "ended",
287
+ "expired"
288
+ ]);
289
+ var chatErrorCodeSchema = z2.enum([
290
+ "AUTH_REQUIRED",
291
+ "CREDITS_REQUIRED",
292
+ "PAYMENT_REQUIRED",
293
+ "AGENT_UNRESPONSIVE",
294
+ "ROUTE_UNAVAILABLE",
295
+ "PROTOCOL_UNSUPPORTED",
296
+ "BROKER_NOT_EXECUTABLE",
297
+ "NETWORK_TIMEOUT",
298
+ "STREAM_STALLED",
299
+ "HISTORY_UNAVAILABLE",
300
+ "ENCRYPTION_REQUIRED",
301
+ "RATE_LIMITED",
302
+ "VALIDATION_ERROR",
303
+ "UNKNOWN_ERROR"
304
+ ]);
305
+ var chatRouteSummarySchema = z2.object({
306
+ type: chatRouteTypeSchema,
307
+ replyMode: chatReplyModeSchema,
308
+ transport: z2.string(),
309
+ endpoint: z2.string().optional()
310
+ });
311
+ var chatPaymentStateSchema = z2.object({
312
+ required: z2.boolean(),
313
+ provider: z2.enum(["credits", "x402", "acp", "openrouter"]).optional(),
314
+ status: z2.enum([
315
+ "not_required",
316
+ "preflight",
317
+ "required",
318
+ "approved",
319
+ "paid",
320
+ "failed"
321
+ ]),
322
+ estimatedCredits: z2.number().nullable().optional(),
323
+ estimatedUsd: z2.number().nullable().optional()
324
+ });
325
+ var chatReadinessResponseSchema = z2.object({
326
+ status: chatReadinessStatusSchema,
327
+ routeType: chatRouteTypeSchema,
328
+ replyMode: chatReplyModeSchema,
329
+ transport: z2.string(),
330
+ endpoint: z2.string().optional(),
331
+ checkedAt: z2.string(),
332
+ cachedUntil: z2.string(),
333
+ latencyMs: z2.number().nullable().optional(),
334
+ lastSuccessfulReplyAt: z2.string().nullable().optional(),
335
+ lastDeliveryConfirmationAt: z2.string().nullable().optional(),
336
+ lastFailureCode: chatErrorCodeSchema.nullable().optional(),
337
+ supportsStreaming: z2.boolean(),
338
+ supportsHistory: z2.boolean(),
339
+ supportsEncryption: z2.boolean(),
340
+ supportsPayments: z2.boolean(),
341
+ supportsAttachments: z2.boolean(),
342
+ requiresAuth: z2.boolean(),
343
+ operatorActionRequired: z2.boolean(),
344
+ issue: z2.object({
345
+ code: z2.string(),
346
+ message: z2.string(),
347
+ details: z2.string().optional()
348
+ }).optional()
349
+ });
234
350
  var metadataFacetSchema = z2.record(
235
351
  z2.union([
236
352
  z2.array(jsonValueSchema),
@@ -430,7 +546,16 @@ var createSessionResponseSchema = z2.object({
430
546
  }),
431
547
  history: z2.array(chatHistoryEntrySchema).optional().default([]),
432
548
  historyTtlSeconds: z2.number().nullable().optional(),
433
- encryption: sessionEncryptionSummarySchema.nullable().optional()
549
+ encryption: sessionEncryptionSummarySchema.nullable().optional(),
550
+ route: chatRouteSummarySchema.optional(),
551
+ transport: z2.string().optional(),
552
+ senderUaid: z2.string().nullable().optional(),
553
+ visibility: z2.enum(["private", "public"]).optional(),
554
+ payment: chatPaymentStateSchema.optional(),
555
+ readiness: chatReadinessResponseSchema.optional(),
556
+ state: chatSessionStateSchema.optional(),
557
+ traceId: z2.string().optional(),
558
+ expiresAt: z2.string().nullable().optional()
434
559
  });
435
560
  var sendMessageResponseSchema = z2.object({
436
561
  sessionId: z2.string(),
@@ -442,7 +567,20 @@ var sendMessageResponseSchema = z2.object({
442
567
  ops: z2.array(z2.record(jsonValueSchema)).optional(),
443
568
  history: z2.array(chatHistoryEntrySchema).optional(),
444
569
  historyTtlSeconds: z2.number().nullable().optional(),
445
- encrypted: z2.boolean().optional()
570
+ encrypted: z2.boolean().optional(),
571
+ messageId: z2.string().optional(),
572
+ assistantMessageId: z2.string().nullable().optional(),
573
+ deliveryState: chatDeliveryStateSchema.optional(),
574
+ replyMode: chatReplyModeSchema.optional(),
575
+ deliveryConfirmation: z2.boolean().optional(),
576
+ idempotent: z2.boolean().optional(),
577
+ metadata: z2.record(jsonValueSchema).optional(),
578
+ errorCode: chatErrorCodeSchema.optional()
579
+ });
580
+ var chatSessionEndResponseSchema = z2.object({
581
+ message: z2.string(),
582
+ sessionId: z2.string(),
583
+ state: chatSessionStateSchema.optional()
446
584
  });
447
585
  var chatHistorySnapshotResponseSchema = z2.object({
448
586
  sessionId: z2.string(),
@@ -2916,8 +3054,11 @@ var EncryptedChatManager = class {
2916
3054
  function createChatApi(client, encryptedManager) {
2917
3055
  return {
2918
3056
  start: (options) => client.startChat(options),
3057
+ readiness: (payload) => client.checkChatReadiness(payload),
2919
3058
  createSession: (payload) => client.createSession(payload),
2920
3059
  sendMessage: (payload) => client.sendMessage(payload),
3060
+ retryMessage: (messageId, payload) => client.retryMessage(messageId, payload),
3061
+ cancelSession: (sessionId) => client.cancelSession(sessionId),
2921
3062
  endSession: (sessionId) => client.endSession(sessionId),
2922
3063
  getHistory: (sessionId, options) => client.fetchHistorySnapshot(sessionId, options),
2923
3064
  compactHistory: (payload) => client.compactHistory(payload),
@@ -2929,6 +3070,30 @@ function createChatApi(client, encryptedManager) {
2929
3070
  acceptEncryptedSession: (options) => encryptedManager.acceptSession(options)
2930
3071
  };
2931
3072
  }
3073
+ async function checkChatReadiness(client, payload) {
3074
+ const body = {};
3075
+ const uaid = "uaid" in payload ? payload.uaid?.trim() : void 0;
3076
+ const agentUrl = "agentUrl" in payload ? payload.agentUrl?.trim() : void 0;
3077
+ if (!uaid && !agentUrl) {
3078
+ throw new Error("uaid or agentUrl is required to check chat readiness");
3079
+ }
3080
+ if (uaid) {
3081
+ body.uaid = uaid;
3082
+ }
3083
+ if (agentUrl) {
3084
+ body.agentUrl = agentUrl;
3085
+ }
3086
+ const raw = await client.requestJson("/chat/readiness", {
3087
+ method: "POST",
3088
+ body,
3089
+ headers: { "content-type": "application/json" }
3090
+ });
3091
+ return client.parseWithSchema(
3092
+ raw,
3093
+ chatReadinessResponseSchema,
3094
+ "chat readiness response"
3095
+ );
3096
+ }
2932
3097
  async function createSession(client, payload, allowHistoryAutoTopUp = true) {
2933
3098
  const body = {};
2934
3099
  if ("uaid" in payload && payload.uaid) {
@@ -2949,6 +3114,9 @@ async function createSession(client, payload, allowHistoryAutoTopUp = true) {
2949
3114
  if (payload.senderUaid) {
2950
3115
  body.senderUaid = payload.senderUaid;
2951
3116
  }
3117
+ if (payload.visibility) {
3118
+ body.visibility = payload.visibility;
3119
+ }
2952
3120
  try {
2953
3121
  const raw = await client.requestJson("/chat/session", {
2954
3122
  method: "POST",
@@ -3183,6 +3351,15 @@ async function sendMessage(client, payload) {
3183
3351
  if (payload.streaming !== void 0) {
3184
3352
  body.streaming = payload.streaming;
3185
3353
  }
3354
+ if (payload.idempotencyKey) {
3355
+ body.idempotencyKey = payload.idempotencyKey;
3356
+ }
3357
+ if (payload.senderUaid) {
3358
+ body.senderUaid = payload.senderUaid;
3359
+ }
3360
+ if (payload.transport) {
3361
+ body.transport = payload.transport;
3362
+ }
3186
3363
  if (payload.auth) {
3187
3364
  body.auth = serialiseAuthConfig(payload.auth);
3188
3365
  }
@@ -3226,9 +3403,130 @@ async function sendMessage(client, payload) {
3226
3403
  );
3227
3404
  }
3228
3405
  async function endSession(client, sessionId) {
3229
- await client.request(`/chat/session/${encodeURIComponent(sessionId)}`, {
3230
- method: "DELETE"
3231
- });
3406
+ const normalizedSessionId = sessionId?.trim();
3407
+ if (!normalizedSessionId) {
3408
+ throw new Error("sessionId is required to end a chat session");
3409
+ }
3410
+ const response = await client.request(
3411
+ `/chat/session/${encodeURIComponent(normalizedSessionId)}`,
3412
+ { method: "DELETE" }
3413
+ );
3414
+ if (response.status === 204) {
3415
+ return {
3416
+ message: "Session ended",
3417
+ sessionId: normalizedSessionId,
3418
+ state: "ended"
3419
+ };
3420
+ }
3421
+ const contentType = response.headers?.get("content-type") ?? "";
3422
+ if (!contentType.toLowerCase().includes("json")) {
3423
+ await response.text();
3424
+ return {
3425
+ message: "Session ended",
3426
+ sessionId: normalizedSessionId,
3427
+ state: "ended"
3428
+ };
3429
+ }
3430
+ const responseBody = await response.text();
3431
+ if (responseBody.trim().length === 0) {
3432
+ return {
3433
+ message: "Session ended",
3434
+ sessionId: normalizedSessionId,
3435
+ state: "ended"
3436
+ };
3437
+ }
3438
+ const raw = JSON.parse(responseBody);
3439
+ return client.parseWithSchema(
3440
+ raw,
3441
+ chatSessionEndResponseSchema,
3442
+ "chat session end response"
3443
+ );
3444
+ }
3445
+ async function cancelSession(client, sessionId) {
3446
+ const normalizedSessionId = sessionId?.trim();
3447
+ if (!normalizedSessionId) {
3448
+ throw new Error("sessionId is required to cancel a chat session");
3449
+ }
3450
+ const raw = await client.requestJson(
3451
+ `/chat/session/${encodeURIComponent(normalizedSessionId)}/cancel`,
3452
+ {
3453
+ method: "POST"
3454
+ }
3455
+ );
3456
+ return client.parseWithSchema(
3457
+ raw,
3458
+ chatSessionEndResponseSchema,
3459
+ "chat session cancel response"
3460
+ );
3461
+ }
3462
+ async function retryMessage(client, messageId, payload) {
3463
+ const normalizedMessageId = messageId?.trim();
3464
+ const normalizedSessionId = payload.sessionId?.trim();
3465
+ const normalizedMessage = payload.message?.trim();
3466
+ if (!normalizedMessageId) {
3467
+ throw new Error("messageId is required to retry a message");
3468
+ }
3469
+ if (!normalizedSessionId) {
3470
+ throw new Error("sessionId is required to retry a message");
3471
+ }
3472
+ if (!normalizedMessage) {
3473
+ throw new Error("message is required to retry a message");
3474
+ }
3475
+ const body = {
3476
+ sessionId: normalizedSessionId,
3477
+ message: payload.message
3478
+ };
3479
+ if (payload.streaming !== void 0) {
3480
+ body.streaming = payload.streaming;
3481
+ }
3482
+ if (payload.transport) {
3483
+ body.transport = payload.transport;
3484
+ }
3485
+ const uaid = payload.uaid?.trim();
3486
+ const agentUrl = payload.agentUrl?.trim();
3487
+ const idempotencyKey = payload.idempotencyKey?.trim();
3488
+ const senderUaid = payload.senderUaid?.trim();
3489
+ if (uaid) {
3490
+ body.uaid = uaid;
3491
+ }
3492
+ if (agentUrl) {
3493
+ body.agentUrl = agentUrl;
3494
+ }
3495
+ if (idempotencyKey) {
3496
+ body.idempotencyKey = idempotencyKey;
3497
+ }
3498
+ if (senderUaid) {
3499
+ body.senderUaid = senderUaid;
3500
+ }
3501
+ if (payload.auth) {
3502
+ body.auth = serialiseAuthConfig(payload.auth);
3503
+ }
3504
+ let cipherEnvelope = payload.cipherEnvelope ?? null;
3505
+ if (payload.encryption) {
3506
+ if (!payload.encryption.recipients?.length) {
3507
+ throw new Error("recipients are required for encrypted chat payloads");
3508
+ }
3509
+ cipherEnvelope = client.encryption.encryptCipherEnvelope({
3510
+ ...payload.encryption,
3511
+ sessionId: payload.encryption.sessionId ?? normalizedSessionId
3512
+ });
3513
+ }
3514
+ if (cipherEnvelope) {
3515
+ body.cipherEnvelope = toJsonObject(cipherEnvelope);
3516
+ }
3517
+ const raw = await client.requestJson(
3518
+ `/chat/message/${encodeURIComponent(normalizedMessageId)}/retry`,
3519
+ {
3520
+ method: "POST",
3521
+ body,
3522
+ headers: { "content-type": "application/json" }
3523
+ }
3524
+ );
3525
+ return client.parseWithSchema(
3526
+ raw,
3527
+ sendMessageResponseSchema,
3528
+ "chat retry response"
3529
+ );
3232
3530
  }
3233
3531
 
3234
3532
  // ../../src/services/registry-broker/client/encryption.ts
@@ -6918,6 +7216,9 @@ var RegistryBrokerClient = class _RegistryBrokerClient {
6918
7216
  async createSession(payload, allowHistoryAutoTopUp = true) {
6919
7217
  return createSession(this, payload, allowHistoryAutoTopUp);
6920
7218
  }
7219
+ async checkChatReadiness(payload) {
7220
+ return checkChatReadiness(this, payload);
7221
+ }
6921
7222
  async startChat(options) {
6922
7223
  return startChat(this, this.getEncryptedChatManager(), options);
6923
7224
  }
@@ -6943,6 +7244,12 @@ var RegistryBrokerClient = class _RegistryBrokerClient {
6943
7244
  sendMessage(payload) {
6944
7245
  return sendMessage(this, payload);
6945
7246
  }
7247
+ retryMessage(messageId, payload) {
7248
+ return retryMessage(this, messageId, payload);
7249
+ }
7250
+ cancelSession(sessionId) {
7251
+ return cancelSession(this, sessionId);
7252
+ }
6946
7253
  endSession(sessionId) {
6947
7254
  return endSession(this, sessionId);
6948
7255
  }
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.182",
4
4
  "description": "Lightweight Registry Broker client for HOL registries.",
5
5
  "type": "module",
6
6
  "files": [