@hol-org/rb-client 0.1.180 → 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
@@ -4233,10 +4531,98 @@ async function registerOwnedMoltbookAgent(client, uaid, request) {
4233
4531
  }
4234
4532
 
4235
4533
  // ../../src/services/registry-broker/client/guard.ts
4534
+ function isStatusError(error) {
4535
+ if (error instanceof RegistryBrokerError) {
4536
+ return true;
4537
+ }
4538
+ if (typeof error !== "object" || error === null || !("status" in error)) {
4539
+ return false;
4540
+ }
4541
+ return typeof Reflect.get(error, "status") === "number";
4542
+ }
4543
+ function toPortalCanonicalGuardPath(path) {
4544
+ const segments = path.split("/");
4545
+ const findPatternStart = (size, matcher) => {
4546
+ for (let startIndex = segments.length - size; startIndex >= 0; startIndex -= 1) {
4547
+ if (matcher(startIndex)) {
4548
+ return startIndex;
4549
+ }
4550
+ }
4551
+ return -1;
4552
+ };
4553
+ const replaceAt = (startIndex, consumed) => [
4554
+ ...segments.slice(0, startIndex),
4555
+ "api",
4556
+ "guard",
4557
+ ...segments.slice(startIndex + consumed)
4558
+ ].join("/");
4559
+ const registryStart = findPatternStart(
4560
+ 4,
4561
+ (startIndex) => segments[startIndex] === "registry" && segments[startIndex + 1] === "api" && /^v\d+$/.test(segments[startIndex + 2] ?? "") && segments[startIndex + 3] === "guard"
4562
+ );
4563
+ if (registryStart >= 0) {
4564
+ return replaceAt(registryStart, 4);
4565
+ }
4566
+ const apiVersionStart = findPatternStart(
4567
+ 3,
4568
+ (startIndex) => segments[startIndex] === "api" && /^v\d+$/.test(segments[startIndex + 1] ?? "") && segments[startIndex + 2] === "guard"
4569
+ );
4570
+ if (apiVersionStart >= 0) {
4571
+ return replaceAt(apiVersionStart, 3);
4572
+ }
4573
+ for (let index = segments.length - 1; index >= 0; index -= 1) {
4574
+ if (segments[index] === "guard" && segments[index - 1] !== "api") {
4575
+ return [
4576
+ ...segments.slice(0, index),
4577
+ "api",
4578
+ "guard",
4579
+ ...segments.slice(index + 1)
4580
+ ].join("/");
4581
+ }
4582
+ }
4583
+ return path;
4584
+ }
4585
+ function buildPortalCanonicalGuardUrl(baseUrl, path) {
4586
+ const target = new URL(path, "https://guard.local");
4587
+ const normalizedBasePath = (() => {
4588
+ try {
4589
+ const base = new URL(baseUrl);
4590
+ return base.pathname.replace(/\/+$/, "");
4591
+ } catch {
4592
+ return baseUrl.replace(/\/+$/, "");
4593
+ }
4594
+ })();
4595
+ const requestedPath = `${normalizedBasePath}${target.pathname}`;
4596
+ const canonicalPath = toPortalCanonicalGuardPath(requestedPath);
4597
+ const canonicalRelativePath = `${canonicalPath}${target.search}`;
4598
+ try {
4599
+ const base = new URL(baseUrl);
4600
+ return `${base.origin}${canonicalRelativePath}`;
4601
+ } catch {
4602
+ return canonicalRelativePath;
4603
+ }
4604
+ }
4605
+ async function requestPortalFirstJson(client, path, init) {
4606
+ try {
4607
+ return await client.requestJson(path, init);
4608
+ } catch (error) {
4609
+ if (isStatusError(error) && (error.status === 404 || error.status === 501)) {
4610
+ return client.requestAbsoluteJson(
4611
+ buildPortalCanonicalGuardUrl(client.baseUrl, path),
4612
+ init
4613
+ );
4614
+ }
4615
+ throw error;
4616
+ }
4617
+ }
4236
4618
  async function getGuardSession(client) {
4237
- const raw = await client.requestJson("/guard/auth/session", {
4238
- method: "GET"
4239
- });
4619
+ const raw = await requestPortalFirstJson(
4620
+ client,
4621
+ "/guard/auth/session",
4622
+ {
4623
+ method: "GET"
4624
+ }
4625
+ );
4240
4626
  return client.parseWithSchema(
4241
4627
  raw,
4242
4628
  guardSessionResponseSchema,
@@ -4244,9 +4630,13 @@ async function getGuardSession(client) {
4244
4630
  );
4245
4631
  }
4246
4632
  async function getGuardEntitlements(client) {
4247
- const raw = await client.requestJson("/guard/entitlements", {
4248
- method: "GET"
4249
- });
4633
+ const raw = await requestPortalFirstJson(
4634
+ client,
4635
+ "/guard/entitlements",
4636
+ {
4637
+ method: "GET"
4638
+ }
4639
+ );
4250
4640
  return client.parseWithSchema(
4251
4641
  raw,
4252
4642
  guardSessionResponseSchema,
@@ -4254,9 +4644,13 @@ async function getGuardEntitlements(client) {
4254
4644
  );
4255
4645
  }
4256
4646
  async function getGuardBillingBalance(client) {
4257
- const raw = await client.requestJson("/guard/billing/balance", {
4258
- method: "GET"
4259
- });
4647
+ const raw = await requestPortalFirstJson(
4648
+ client,
4649
+ "/guard/billing/balance",
4650
+ {
4651
+ method: "GET"
4652
+ }
4653
+ );
4260
4654
  return client.parseWithSchema(
4261
4655
  raw,
4262
4656
  guardBalanceResponseSchema,
@@ -4270,9 +4664,13 @@ async function getGuardFeed(client, limit) {
4270
4664
  }
4271
4665
  const query = params.toString();
4272
4666
  const suffix = query ? `?${query}` : "";
4273
- const raw = await client.requestJson(`/guard/feed${suffix}`, {
4274
- method: "GET"
4275
- });
4667
+ const raw = await requestPortalFirstJson(
4668
+ client,
4669
+ `/guard/feed${suffix}`,
4670
+ {
4671
+ method: "GET"
4672
+ }
4673
+ );
4276
4674
  return client.parseWithSchema(
4277
4675
  raw,
4278
4676
  guardFeedResponseSchema,
@@ -4280,9 +4678,13 @@ async function getGuardFeed(client, limit) {
4280
4678
  );
4281
4679
  }
4282
4680
  async function getGuardOverview(client) {
4283
- const raw = await client.requestJson("/guard/overview", {
4284
- method: "GET"
4285
- });
4681
+ const raw = await requestPortalFirstJson(
4682
+ client,
4683
+ "/guard/overview",
4684
+ {
4685
+ method: "GET"
4686
+ }
4687
+ );
4286
4688
  return client.parseWithSchema(
4287
4689
  raw,
4288
4690
  guardOverviewResponseSchema,
@@ -4294,7 +4696,8 @@ async function getGuardTrustByHash(client, sha256) {
4294
4696
  if (!normalizedHash) {
4295
4697
  throw new Error("sha256 is required");
4296
4698
  }
4297
- const raw = await client.requestJson(
4699
+ const raw = await requestPortalFirstJson(
4700
+ client,
4298
4701
  `/guard/trust/by-hash/${encodeURIComponent(normalizedHash)}`,
4299
4702
  { method: "GET" }
4300
4703
  );
@@ -4316,7 +4719,8 @@ async function resolveGuardTrust(client, query) {
4316
4719
  params.set("version", query.version.trim());
4317
4720
  }
4318
4721
  const suffix = params.size > 0 ? `?${params.toString()}` : "";
4319
- const raw = await client.requestJson(
4722
+ const raw = await requestPortalFirstJson(
4723
+ client,
4320
4724
  `/guard/trust/resolve${suffix}`,
4321
4725
  { method: "GET" }
4322
4726
  );
@@ -4327,9 +4731,13 @@ async function resolveGuardTrust(client, query) {
4327
4731
  );
4328
4732
  }
4329
4733
  async function getGuardRevocations(client) {
4330
- const raw = await client.requestJson("/guard/revocations", {
4331
- method: "GET"
4332
- });
4734
+ const raw = await requestPortalFirstJson(
4735
+ client,
4736
+ "/guard/revocations",
4737
+ {
4738
+ method: "GET"
4739
+ }
4740
+ );
4333
4741
  return client.parseWithSchema(
4334
4742
  raw,
4335
4743
  guardRevocationResponseSchema,
@@ -4337,9 +4745,13 @@ async function getGuardRevocations(client) {
4337
4745
  );
4338
4746
  }
4339
4747
  async function fetchGuardAdvisories(client) {
4340
- const raw = await client.requestJson("/guard/advisories", {
4341
- method: "GET"
4342
- });
4748
+ const raw = await requestPortalFirstJson(
4749
+ client,
4750
+ "/guard/advisories",
4751
+ {
4752
+ method: "GET"
4753
+ }
4754
+ );
4343
4755
  return client.parseWithSchema(
4344
4756
  raw,
4345
4757
  guardRevocationResponseSchema,
@@ -4347,9 +4759,13 @@ async function fetchGuardAdvisories(client) {
4347
4759
  );
4348
4760
  }
4349
4761
  async function fetchGuardPolicy(client) {
4350
- const raw = await client.requestJson("/guard/policy/fetch", {
4351
- method: "GET"
4352
- });
4762
+ const raw = await requestPortalFirstJson(
4763
+ client,
4764
+ "/guard/policy/fetch",
4765
+ {
4766
+ method: "GET"
4767
+ }
4768
+ );
4353
4769
  return client.parseWithSchema(
4354
4770
  raw,
4355
4771
  guardPolicySchema,
@@ -4357,9 +4773,13 @@ async function fetchGuardPolicy(client) {
4357
4773
  );
4358
4774
  }
4359
4775
  async function getGuardInventory(client) {
4360
- const raw = await client.requestJson("/guard/inventory", {
4361
- method: "GET"
4362
- });
4776
+ const raw = await requestPortalFirstJson(
4777
+ client,
4778
+ "/guard/inventory",
4779
+ {
4780
+ method: "GET"
4781
+ }
4782
+ );
4363
4783
  return client.parseWithSchema(
4364
4784
  raw,
4365
4785
  guardInventoryResponseSchema,
@@ -4367,9 +4787,13 @@ async function getGuardInventory(client) {
4367
4787
  );
4368
4788
  }
4369
4789
  async function getGuardReceiptHistory(client) {
4370
- const raw = await client.requestJson("/guard/history", {
4371
- method: "GET"
4372
- });
4790
+ const raw = await requestPortalFirstJson(
4791
+ client,
4792
+ "/guard/history",
4793
+ {
4794
+ method: "GET"
4795
+ }
4796
+ );
4373
4797
  return client.parseWithSchema(
4374
4798
  raw,
4375
4799
  guardReceiptHistoryResponseSchema,
@@ -4381,7 +4805,8 @@ async function getGuardArtifactTimeline(client, artifactId) {
4381
4805
  if (!normalizedArtifactId) {
4382
4806
  throw new Error("artifactId is required");
4383
4807
  }
4384
- const raw = await client.requestJson(
4808
+ const raw = await requestPortalFirstJson(
4809
+ client,
4385
4810
  `/guard/history/${encodeURIComponent(normalizedArtifactId)}`,
4386
4811
  { method: "GET" }
4387
4812
  );
@@ -4392,7 +4817,7 @@ async function getGuardArtifactTimeline(client, artifactId) {
4392
4817
  );
4393
4818
  }
4394
4819
  async function exportGuardAbom(client) {
4395
- const raw = await client.requestJson("/guard/abom", {
4820
+ const raw = await requestPortalFirstJson(client, "/guard/abom", {
4396
4821
  method: "GET"
4397
4822
  });
4398
4823
  return client.parseWithSchema(
@@ -4406,7 +4831,8 @@ async function exportGuardArtifactAbom(client, artifactId) {
4406
4831
  if (!normalizedArtifactId) {
4407
4832
  throw new Error("artifactId is required");
4408
4833
  }
4409
- const raw = await client.requestJson(
4834
+ const raw = await requestPortalFirstJson(
4835
+ client,
4410
4836
  `/guard/abom/${encodeURIComponent(normalizedArtifactId)}`,
4411
4837
  { method: "GET" }
4412
4838
  );
@@ -4417,9 +4843,13 @@ async function exportGuardArtifactAbom(client, artifactId) {
4417
4843
  );
4418
4844
  }
4419
4845
  async function exportGuardReceipts(client) {
4420
- const raw = await client.requestJson("/guard/receipts/export", {
4421
- method: "GET"
4422
- });
4846
+ const raw = await requestPortalFirstJson(
4847
+ client,
4848
+ "/guard/receipts/export",
4849
+ {
4850
+ method: "GET"
4851
+ }
4852
+ );
4423
4853
  return client.parseWithSchema(
4424
4854
  raw,
4425
4855
  guardReceiptExportResponseSchema,
@@ -4427,9 +4857,13 @@ async function exportGuardReceipts(client) {
4427
4857
  );
4428
4858
  }
4429
4859
  async function getGuardInventoryDiff(client) {
4430
- const raw = await client.requestJson("/guard/inventory/diff", {
4431
- method: "GET"
4432
- });
4860
+ const raw = await requestPortalFirstJson(
4861
+ client,
4862
+ "/guard/inventory/diff",
4863
+ {
4864
+ method: "GET"
4865
+ }
4866
+ );
4433
4867
  return client.parseWithSchema(
4434
4868
  raw,
4435
4869
  guardInventoryDiffResponseSchema,
@@ -4437,9 +4871,13 @@ async function getGuardInventoryDiff(client) {
4437
4871
  );
4438
4872
  }
4439
4873
  async function getGuardDevices(client) {
4440
- const raw = await client.requestJson("/guard/devices", {
4441
- method: "GET"
4442
- });
4874
+ const raw = await requestPortalFirstJson(
4875
+ client,
4876
+ "/guard/devices",
4877
+ {
4878
+ method: "GET"
4879
+ }
4880
+ );
4443
4881
  return client.parseWithSchema(
4444
4882
  raw,
4445
4883
  guardDeviceListResponseSchema,
@@ -4447,9 +4885,13 @@ async function getGuardDevices(client) {
4447
4885
  );
4448
4886
  }
4449
4887
  async function getGuardAlertPreferences(client) {
4450
- const raw = await client.requestJson("/guard/alerts/preferences", {
4451
- method: "GET"
4452
- });
4888
+ const raw = await requestPortalFirstJson(
4889
+ client,
4890
+ "/guard/alerts/preferences",
4891
+ {
4892
+ method: "GET"
4893
+ }
4894
+ );
4453
4895
  return client.parseWithSchema(
4454
4896
  raw,
4455
4897
  guardAlertPreferencesSchema,
@@ -4457,10 +4899,14 @@ async function getGuardAlertPreferences(client) {
4457
4899
  );
4458
4900
  }
4459
4901
  async function updateGuardAlertPreferences(client, payload) {
4460
- const raw = await client.requestJson("/guard/alerts/preferences", {
4461
- method: "PUT",
4462
- body: payload
4463
- });
4902
+ const raw = await requestPortalFirstJson(
4903
+ client,
4904
+ "/guard/alerts/preferences",
4905
+ {
4906
+ method: "PUT",
4907
+ body: payload
4908
+ }
4909
+ );
4464
4910
  return client.parseWithSchema(
4465
4911
  raw,
4466
4912
  guardAlertPreferencesSchema,
@@ -4468,9 +4914,13 @@ async function updateGuardAlertPreferences(client, payload) {
4468
4914
  );
4469
4915
  }
4470
4916
  async function getGuardExceptions(client) {
4471
- const raw = await client.requestJson("/guard/exceptions", {
4472
- method: "GET"
4473
- });
4917
+ const raw = await requestPortalFirstJson(
4918
+ client,
4919
+ "/guard/exceptions",
4920
+ {
4921
+ method: "GET"
4922
+ }
4923
+ );
4474
4924
  return client.parseWithSchema(
4475
4925
  raw,
4476
4926
  guardExceptionListResponseSchema,
@@ -4478,9 +4928,13 @@ async function getGuardExceptions(client) {
4478
4928
  );
4479
4929
  }
4480
4930
  async function getGuardWatchlist(client) {
4481
- const raw = await client.requestJson("/guard/watchlist", {
4482
- method: "GET"
4483
- });
4931
+ const raw = await requestPortalFirstJson(
4932
+ client,
4933
+ "/guard/watchlist",
4934
+ {
4935
+ method: "GET"
4936
+ }
4937
+ );
4484
4938
  return client.parseWithSchema(
4485
4939
  raw,
4486
4940
  guardWatchlistResponseSchema,
@@ -4488,10 +4942,14 @@ async function getGuardWatchlist(client) {
4488
4942
  );
4489
4943
  }
4490
4944
  async function lookupGuardWatchlist(client, payload) {
4491
- const raw = await client.requestJson("/guard/watchlist/lookup", {
4492
- method: "POST",
4493
- body: payload
4494
- });
4945
+ const raw = await requestPortalFirstJson(
4946
+ client,
4947
+ "/guard/watchlist/lookup",
4948
+ {
4949
+ method: "POST",
4950
+ body: payload
4951
+ }
4952
+ );
4495
4953
  return client.parseWithSchema(
4496
4954
  raw,
4497
4955
  guardWatchlistLookupResponseSchema,
@@ -4499,9 +4957,13 @@ async function lookupGuardWatchlist(client, payload) {
4499
4957
  );
4500
4958
  }
4501
4959
  async function getGuardPainSignals(client) {
4502
- const raw = await client.requestJson("/guard/signals/pain", {
4503
- method: "GET"
4504
- });
4960
+ const raw = await requestPortalFirstJson(
4961
+ client,
4962
+ "/guard/signals/pain",
4963
+ {
4964
+ method: "GET"
4965
+ }
4966
+ );
4505
4967
  return client.parseWithSchema(
4506
4968
  raw,
4507
4969
  guardPainSignalListResponseSchema,
@@ -4509,7 +4971,8 @@ async function getGuardPainSignals(client) {
4509
4971
  );
4510
4972
  }
4511
4973
  async function getGuardAggregatedPainSignals(client) {
4512
- const raw = await client.requestJson(
4974
+ const raw = await requestPortalFirstJson(
4975
+ client,
4513
4976
  "/guard/signals/pain/aggregate",
4514
4977
  {
4515
4978
  method: "GET"
@@ -4522,7 +4985,7 @@ async function getGuardAggregatedPainSignals(client) {
4522
4985
  );
4523
4986
  }
4524
4987
  async function getGuardPreflightVerdict(client, path, payload) {
4525
- const raw = await client.requestJson(path, {
4988
+ const raw = await requestPortalFirstJson(client, path, {
4526
4989
  method: "POST",
4527
4990
  body: payload
4528
4991
  });
@@ -4547,10 +5010,14 @@ async function getGuardPreExecutionVerdict(client, payload) {
4547
5010
  );
4548
5011
  }
4549
5012
  async function ingestGuardPainSignals(client, items) {
4550
- const raw = await client.requestJson("/guard/signals/pain", {
4551
- method: "POST",
4552
- body: { items }
4553
- });
5013
+ const raw = await requestPortalFirstJson(
5014
+ client,
5015
+ "/guard/signals/pain",
5016
+ {
5017
+ method: "POST",
5018
+ body: { items }
5019
+ }
5020
+ );
4554
5021
  return client.parseWithSchema(
4555
5022
  raw,
4556
5023
  guardPainSignalListResponseSchema,
@@ -4558,10 +5025,14 @@ async function ingestGuardPainSignals(client, items) {
4558
5025
  );
4559
5026
  }
4560
5027
  async function submitGuardReceipts(client, payload) {
4561
- const raw = await client.requestJson("/guard/receipts/submit", {
4562
- method: "POST",
4563
- body: payload
4564
- });
5028
+ const raw = await requestPortalFirstJson(
5029
+ client,
5030
+ "/guard/receipts/submit",
5031
+ {
5032
+ method: "POST",
5033
+ body: payload
5034
+ }
5035
+ );
4565
5036
  return client.parseWithSchema(
4566
5037
  raw,
4567
5038
  guardReceiptSyncResponseSchema,
@@ -4569,10 +5040,14 @@ async function submitGuardReceipts(client, payload) {
4569
5040
  );
4570
5041
  }
4571
5042
  async function addGuardWatchlistItem(client, payload) {
4572
- const raw = await client.requestJson("/guard/watchlist", {
4573
- method: "POST",
4574
- body: payload
4575
- });
5043
+ const raw = await requestPortalFirstJson(
5044
+ client,
5045
+ "/guard/watchlist",
5046
+ {
5047
+ method: "POST",
5048
+ body: payload
5049
+ }
5050
+ );
4576
5051
  return client.parseWithSchema(
4577
5052
  raw,
4578
5053
  guardWatchlistResponseSchema,
@@ -4584,7 +5059,8 @@ async function removeGuardWatchlistItem(client, artifactId) {
4584
5059
  if (!normalizedArtifactId) {
4585
5060
  throw new Error("artifactId is required");
4586
5061
  }
4587
- const raw = await client.requestJson(
5062
+ const raw = await requestPortalFirstJson(
5063
+ client,
4588
5064
  `/guard/watchlist/${encodeURIComponent(normalizedArtifactId)}`,
4589
5065
  { method: "DELETE" }
4590
5066
  );
@@ -4595,10 +5071,14 @@ async function removeGuardWatchlistItem(client, artifactId) {
4595
5071
  );
4596
5072
  }
4597
5073
  async function addGuardException(client, payload) {
4598
- const raw = await client.requestJson("/guard/exceptions", {
4599
- method: "POST",
4600
- body: payload
4601
- });
5074
+ const raw = await requestPortalFirstJson(
5075
+ client,
5076
+ "/guard/exceptions",
5077
+ {
5078
+ method: "POST",
5079
+ body: payload
5080
+ }
5081
+ );
4602
5082
  return client.parseWithSchema(
4603
5083
  raw,
4604
5084
  guardExceptionListResponseSchema,
@@ -4606,10 +5086,14 @@ async function addGuardException(client, payload) {
4606
5086
  );
4607
5087
  }
4608
5088
  async function requestGuardException(client, payload) {
4609
- const raw = await client.requestJson("/guard/exceptions/request", {
4610
- method: "POST",
4611
- body: payload
4612
- });
5089
+ const raw = await requestPortalFirstJson(
5090
+ client,
5091
+ "/guard/exceptions/request",
5092
+ {
5093
+ method: "POST",
5094
+ body: payload
5095
+ }
5096
+ );
4613
5097
  return client.parseWithSchema(
4614
5098
  raw,
4615
5099
  guardExceptionListResponseSchema,
@@ -4617,10 +5101,14 @@ async function requestGuardException(client, payload) {
4617
5101
  );
4618
5102
  }
4619
5103
  async function syncGuardInventory(client, payload) {
4620
- const raw = await client.requestJson("/guard/inventory/sync", {
4621
- method: "POST",
4622
- body: payload
4623
- });
5104
+ const raw = await requestPortalFirstJson(
5105
+ client,
5106
+ "/guard/inventory/sync",
5107
+ {
5108
+ method: "POST",
5109
+ body: payload
5110
+ }
5111
+ );
4624
5112
  return client.parseWithSchema(
4625
5113
  raw,
4626
5114
  guardReceiptSyncResponseSchema,
@@ -4632,7 +5120,8 @@ async function removeGuardException(client, exceptionId) {
4632
5120
  if (!normalizedExceptionId) {
4633
5121
  throw new Error("exceptionId is required");
4634
5122
  }
4635
- const raw = await client.requestJson(
5123
+ const raw = await requestPortalFirstJson(
5124
+ client,
4636
5125
  `/guard/exceptions/${encodeURIComponent(normalizedExceptionId)}`,
4637
5126
  { method: "DELETE" }
4638
5127
  );
@@ -4643,9 +5132,13 @@ async function removeGuardException(client, exceptionId) {
4643
5132
  );
4644
5133
  }
4645
5134
  async function getGuardTeamPolicyPack(client) {
4646
- const raw = await client.requestJson("/guard/team/policy-pack", {
4647
- method: "GET"
4648
- });
5135
+ const raw = await requestPortalFirstJson(
5136
+ client,
5137
+ "/guard/team/policy-pack",
5138
+ {
5139
+ method: "GET"
5140
+ }
5141
+ );
4649
5142
  return client.parseWithSchema(
4650
5143
  raw,
4651
5144
  guardTeamPolicyPackSchema,
@@ -4653,10 +5146,14 @@ async function getGuardTeamPolicyPack(client) {
4653
5146
  );
4654
5147
  }
4655
5148
  async function updateGuardTeamPolicyPack(client, payload) {
4656
- const raw = await client.requestJson("/guard/team/policy-pack", {
4657
- method: "PUT",
4658
- body: payload
4659
- });
5149
+ const raw = await requestPortalFirstJson(
5150
+ client,
5151
+ "/guard/team/policy-pack",
5152
+ {
5153
+ method: "PUT",
5154
+ body: payload
5155
+ }
5156
+ );
4660
5157
  return client.parseWithSchema(
4661
5158
  raw,
4662
5159
  guardTeamPolicyPackSchema,
@@ -4664,10 +5161,14 @@ async function updateGuardTeamPolicyPack(client, payload) {
4664
5161
  );
4665
5162
  }
4666
5163
  async function syncGuardReceipts(client, payload) {
4667
- const raw = await client.requestJson("/guard/receipts/sync", {
4668
- method: "POST",
4669
- body: payload
4670
- });
5164
+ const raw = await requestPortalFirstJson(
5165
+ client,
5166
+ "/guard/receipts/sync",
5167
+ {
5168
+ method: "POST",
5169
+ body: payload
5170
+ }
5171
+ );
4671
5172
  return client.parseWithSchema(
4672
5173
  raw,
4673
5174
  guardReceiptSyncResponseSchema,
@@ -6003,7 +6504,7 @@ var RegistryBrokerClient = class _RegistryBrokerClient {
6003
6504
  const normalisedPath = path.startsWith("/") ? path : `/${path}`;
6004
6505
  return `${this.baseUrl}${normalisedPath}`;
6005
6506
  }
6006
- async request(path, config) {
6507
+ buildRequestInit(config) {
6007
6508
  const headers = new Headers();
6008
6509
  Object.entries(this.defaultHeaders).forEach(([key, value]) => {
6009
6510
  headers.set(key, value);
@@ -6029,6 +6530,10 @@ var RegistryBrokerClient = class _RegistryBrokerClient {
6029
6530
  headers.set("content-type", "application/json");
6030
6531
  }
6031
6532
  }
6533
+ return init;
6534
+ }
6535
+ async request(path, config) {
6536
+ const init = this.buildRequestInit(config);
6032
6537
  const response = await this.fetchImpl(this.buildUrl(path), init);
6033
6538
  if (response.ok) {
6034
6539
  return response;
@@ -6040,6 +6545,19 @@ var RegistryBrokerClient = class _RegistryBrokerClient {
6040
6545
  body: errorBody
6041
6546
  });
6042
6547
  }
6548
+ async requestAbsolute(url, config) {
6549
+ const init = this.buildRequestInit(config);
6550
+ const response = await this.fetchImpl(url, init);
6551
+ if (response.ok) {
6552
+ return response;
6553
+ }
6554
+ const errorBody = await this.extractErrorBody(response);
6555
+ throw new RegistryBrokerError("Registry broker request failed", {
6556
+ status: response.status,
6557
+ statusText: response.statusText,
6558
+ body: errorBody
6559
+ });
6560
+ }
6043
6561
  async requestJson(path, config) {
6044
6562
  const response = await this.request(path, config);
6045
6563
  const contentType = response.headers?.get("content-type") ?? "";
@@ -6052,6 +6570,18 @@ var RegistryBrokerClient = class _RegistryBrokerClient {
6052
6570
  }
6053
6571
  return await response.json();
6054
6572
  }
6573
+ async requestAbsoluteJson(url, config) {
6574
+ const response = await this.requestAbsolute(url, config);
6575
+ const contentType = response.headers?.get("content-type") ?? "";
6576
+ if (!JSON_CONTENT_TYPE.test(contentType)) {
6577
+ const body = await response.text();
6578
+ throw new RegistryBrokerParseError(
6579
+ "Expected JSON response from registry broker",
6580
+ body
6581
+ );
6582
+ }
6583
+ return await response.json();
6584
+ }
6055
6585
  async getAgentFeedback(uaid, options = {}) {
6056
6586
  const normalized = uaid.trim();
6057
6587
  if (!normalized) {
@@ -6686,6 +7216,9 @@ var RegistryBrokerClient = class _RegistryBrokerClient {
6686
7216
  async createSession(payload, allowHistoryAutoTopUp = true) {
6687
7217
  return createSession(this, payload, allowHistoryAutoTopUp);
6688
7218
  }
7219
+ async checkChatReadiness(payload) {
7220
+ return checkChatReadiness(this, payload);
7221
+ }
6689
7222
  async startChat(options) {
6690
7223
  return startChat(this, this.getEncryptedChatManager(), options);
6691
7224
  }
@@ -6711,6 +7244,12 @@ var RegistryBrokerClient = class _RegistryBrokerClient {
6711
7244
  sendMessage(payload) {
6712
7245
  return sendMessage(this, payload);
6713
7246
  }
7247
+ retryMessage(messageId, payload) {
7248
+ return retryMessage(this, messageId, payload);
7249
+ }
7250
+ cancelSession(sessionId) {
7251
+ return cancelSession(this, sessionId);
7252
+ }
6714
7253
  endSession(sessionId) {
6715
7254
  return endSession(this, sessionId);
6716
7255
  }
@@ -6977,6 +7516,10 @@ var isPendingRegisterAgentResponse = (response) => response.status === "pending"
6977
7516
  var isPartialRegisterAgentResponse = (response) => response.status === "partial" && response.success === false;
6978
7517
  var isSuccessRegisterAgentResponse = (response) => response.success === true && response.status !== "pending";
6979
7518
 
7519
+ // ../../src/services/registry-broker/types.ts
7520
+ var GUARD_CANONICAL_PATH_PREFIX = "/api/guard";
7521
+ var GUARD_COMPAT_PATH_PREFIX = "/guard";
7522
+
6980
7523
  // ../../src/services/registry-broker/hol-chat-ops.ts
6981
7524
  var HOL_CHAT_PROTOCOL_ID = "hol-chat";
6982
7525
  var isRecord = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value);
@@ -7033,6 +7576,8 @@ var buildJobStatusMessage = (input) => JSON.stringify({
7033
7576
  data: { job_id: input.jobId }
7034
7577
  });
7035
7578
  export {
7579
+ GUARD_CANONICAL_PATH_PREFIX,
7580
+ GUARD_COMPAT_PATH_PREFIX,
7036
7581
  HOL_CHAT_PROTOCOL_ID,
7037
7582
  RegistryBrokerClient,
7038
7583
  RegistryBrokerError,