@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.cjs CHANGED
@@ -29,6 +29,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
29
29
  // src/index.ts
30
30
  var src_exports = {};
31
31
  __export(src_exports, {
32
+ GUARD_CANONICAL_PATH_PREFIX: () => GUARD_CANONICAL_PATH_PREFIX,
33
+ GUARD_COMPAT_PATH_PREFIX: () => GUARD_COMPAT_PATH_PREFIX,
32
34
  HOL_CHAT_PROTOCOL_ID: () => HOL_CHAT_PROTOCOL_ID,
33
35
  RegistryBrokerClient: () => RegistryBrokerClient,
34
36
  RegistryBrokerError: () => RegistryBrokerError,
@@ -284,12 +286,128 @@ var sessionEncryptionSummarySchema = import_zod2.z.object({
284
286
  });
285
287
  var chatHistoryEntrySchema = import_zod2.z.object({
286
288
  messageId: import_zod2.z.string(),
287
- 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
+ ]),
288
298
  content: import_zod2.z.string(),
289
299
  timestamp: import_zod2.z.string(),
290
300
  cipherEnvelope: cipherEnvelopeSchema.optional(),
291
301
  metadata: import_zod2.z.record(jsonValueSchema).optional()
292
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 chatReadinessStatusSchema = import_zod2.z.enum([
315
+ "responsive",
316
+ "delivery_only",
317
+ "degraded",
318
+ "blocked",
319
+ "unknown"
320
+ ]);
321
+ var chatReplyModeSchema = import_zod2.z.enum([
322
+ "direct",
323
+ "stream",
324
+ "poll",
325
+ "delivery_only",
326
+ "none"
327
+ ]);
328
+ var chatRouteTypeSchema = import_zod2.z.enum([
329
+ "a2a",
330
+ "hcs-10",
331
+ "mcp",
332
+ "openrouter",
333
+ "acp",
334
+ "xmtp",
335
+ "moltbook",
336
+ "agentverse",
337
+ "nanda",
338
+ "http",
339
+ "erc-8004",
340
+ "x402",
341
+ "unknown"
342
+ ]);
343
+ var chatSessionStateSchema = import_zod2.z.enum([
344
+ "connecting",
345
+ "ready",
346
+ "blocked",
347
+ "ended",
348
+ "expired"
349
+ ]);
350
+ var chatErrorCodeSchema = import_zod2.z.enum([
351
+ "AUTH_REQUIRED",
352
+ "CREDITS_REQUIRED",
353
+ "PAYMENT_REQUIRED",
354
+ "AGENT_UNRESPONSIVE",
355
+ "ROUTE_UNAVAILABLE",
356
+ "PROTOCOL_UNSUPPORTED",
357
+ "BROKER_NOT_EXECUTABLE",
358
+ "NETWORK_TIMEOUT",
359
+ "STREAM_STALLED",
360
+ "HISTORY_UNAVAILABLE",
361
+ "ENCRYPTION_REQUIRED",
362
+ "RATE_LIMITED",
363
+ "VALIDATION_ERROR",
364
+ "UNKNOWN_ERROR"
365
+ ]);
366
+ var chatRouteSummarySchema = import_zod2.z.object({
367
+ type: chatRouteTypeSchema,
368
+ replyMode: chatReplyModeSchema,
369
+ transport: import_zod2.z.string(),
370
+ endpoint: import_zod2.z.string().optional()
371
+ });
372
+ var chatPaymentStateSchema = import_zod2.z.object({
373
+ required: import_zod2.z.boolean(),
374
+ provider: import_zod2.z.enum(["credits", "x402", "acp", "openrouter"]).optional(),
375
+ status: import_zod2.z.enum([
376
+ "not_required",
377
+ "preflight",
378
+ "required",
379
+ "approved",
380
+ "paid",
381
+ "failed"
382
+ ]),
383
+ estimatedCredits: import_zod2.z.number().nullable().optional(),
384
+ estimatedUsd: import_zod2.z.number().nullable().optional()
385
+ });
386
+ var chatReadinessResponseSchema = import_zod2.z.object({
387
+ status: chatReadinessStatusSchema,
388
+ routeType: chatRouteTypeSchema,
389
+ replyMode: chatReplyModeSchema,
390
+ transport: import_zod2.z.string(),
391
+ endpoint: import_zod2.z.string().optional(),
392
+ checkedAt: import_zod2.z.string(),
393
+ cachedUntil: import_zod2.z.string(),
394
+ latencyMs: import_zod2.z.number().nullable().optional(),
395
+ lastSuccessfulReplyAt: import_zod2.z.string().nullable().optional(),
396
+ lastDeliveryConfirmationAt: import_zod2.z.string().nullable().optional(),
397
+ lastFailureCode: chatErrorCodeSchema.nullable().optional(),
398
+ supportsStreaming: import_zod2.z.boolean(),
399
+ supportsHistory: import_zod2.z.boolean(),
400
+ supportsEncryption: import_zod2.z.boolean(),
401
+ supportsPayments: import_zod2.z.boolean(),
402
+ supportsAttachments: import_zod2.z.boolean(),
403
+ requiresAuth: import_zod2.z.boolean(),
404
+ operatorActionRequired: import_zod2.z.boolean(),
405
+ issue: import_zod2.z.object({
406
+ code: import_zod2.z.string(),
407
+ message: import_zod2.z.string(),
408
+ details: import_zod2.z.string().optional()
409
+ }).optional()
410
+ });
293
411
  var metadataFacetSchema = import_zod2.z.record(
294
412
  import_zod2.z.union([
295
413
  import_zod2.z.array(jsonValueSchema),
@@ -489,7 +607,16 @@ var createSessionResponseSchema = import_zod2.z.object({
489
607
  }),
490
608
  history: import_zod2.z.array(chatHistoryEntrySchema).optional().default([]),
491
609
  historyTtlSeconds: import_zod2.z.number().nullable().optional(),
492
- encryption: sessionEncryptionSummarySchema.nullable().optional()
610
+ encryption: sessionEncryptionSummarySchema.nullable().optional(),
611
+ route: chatRouteSummarySchema.optional(),
612
+ transport: import_zod2.z.string().optional(),
613
+ senderUaid: import_zod2.z.string().nullable().optional(),
614
+ visibility: import_zod2.z.enum(["private", "public"]).optional(),
615
+ payment: chatPaymentStateSchema.optional(),
616
+ readiness: chatReadinessResponseSchema.optional(),
617
+ state: chatSessionStateSchema.optional(),
618
+ traceId: import_zod2.z.string().optional(),
619
+ expiresAt: import_zod2.z.string().nullable().optional()
493
620
  });
494
621
  var sendMessageResponseSchema = import_zod2.z.object({
495
622
  sessionId: import_zod2.z.string(),
@@ -501,7 +628,20 @@ var sendMessageResponseSchema = import_zod2.z.object({
501
628
  ops: import_zod2.z.array(import_zod2.z.record(jsonValueSchema)).optional(),
502
629
  history: import_zod2.z.array(chatHistoryEntrySchema).optional(),
503
630
  historyTtlSeconds: import_zod2.z.number().nullable().optional(),
504
- encrypted: import_zod2.z.boolean().optional()
631
+ encrypted: import_zod2.z.boolean().optional(),
632
+ messageId: import_zod2.z.string().optional(),
633
+ assistantMessageId: import_zod2.z.string().nullable().optional(),
634
+ deliveryState: chatDeliveryStateSchema.optional(),
635
+ replyMode: chatReplyModeSchema.optional(),
636
+ deliveryConfirmation: import_zod2.z.boolean().optional(),
637
+ idempotent: import_zod2.z.boolean().optional(),
638
+ metadata: import_zod2.z.record(jsonValueSchema).optional(),
639
+ errorCode: chatErrorCodeSchema.optional()
640
+ });
641
+ var chatSessionEndResponseSchema = import_zod2.z.object({
642
+ message: import_zod2.z.string(),
643
+ sessionId: import_zod2.z.string(),
644
+ state: chatSessionStateSchema.optional()
505
645
  });
506
646
  var chatHistorySnapshotResponseSchema = import_zod2.z.object({
507
647
  sessionId: import_zod2.z.string(),
@@ -2975,8 +3115,11 @@ var EncryptedChatManager = class {
2975
3115
  function createChatApi(client, encryptedManager) {
2976
3116
  return {
2977
3117
  start: (options) => client.startChat(options),
3118
+ readiness: (payload) => client.checkChatReadiness(payload),
2978
3119
  createSession: (payload) => client.createSession(payload),
2979
3120
  sendMessage: (payload) => client.sendMessage(payload),
3121
+ retryMessage: (messageId, payload) => client.retryMessage(messageId, payload),
3122
+ cancelSession: (sessionId) => client.cancelSession(sessionId),
2980
3123
  endSession: (sessionId) => client.endSession(sessionId),
2981
3124
  getHistory: (sessionId, options) => client.fetchHistorySnapshot(sessionId, options),
2982
3125
  compactHistory: (payload) => client.compactHistory(payload),
@@ -2988,6 +3131,30 @@ function createChatApi(client, encryptedManager) {
2988
3131
  acceptEncryptedSession: (options) => encryptedManager.acceptSession(options)
2989
3132
  };
2990
3133
  }
3134
+ async function checkChatReadiness(client, payload) {
3135
+ const body = {};
3136
+ const uaid = "uaid" in payload ? payload.uaid?.trim() : void 0;
3137
+ const agentUrl = "agentUrl" in payload ? payload.agentUrl?.trim() : void 0;
3138
+ if (!uaid && !agentUrl) {
3139
+ throw new Error("uaid or agentUrl is required to check chat readiness");
3140
+ }
3141
+ if (uaid) {
3142
+ body.uaid = uaid;
3143
+ }
3144
+ if (agentUrl) {
3145
+ body.agentUrl = agentUrl;
3146
+ }
3147
+ const raw = await client.requestJson("/chat/readiness", {
3148
+ method: "POST",
3149
+ body,
3150
+ headers: { "content-type": "application/json" }
3151
+ });
3152
+ return client.parseWithSchema(
3153
+ raw,
3154
+ chatReadinessResponseSchema,
3155
+ "chat readiness response"
3156
+ );
3157
+ }
2991
3158
  async function createSession(client, payload, allowHistoryAutoTopUp = true) {
2992
3159
  const body = {};
2993
3160
  if ("uaid" in payload && payload.uaid) {
@@ -3008,6 +3175,9 @@ async function createSession(client, payload, allowHistoryAutoTopUp = true) {
3008
3175
  if (payload.senderUaid) {
3009
3176
  body.senderUaid = payload.senderUaid;
3010
3177
  }
3178
+ if (payload.visibility) {
3179
+ body.visibility = payload.visibility;
3180
+ }
3011
3181
  try {
3012
3182
  const raw = await client.requestJson("/chat/session", {
3013
3183
  method: "POST",
@@ -3242,6 +3412,15 @@ async function sendMessage(client, payload) {
3242
3412
  if (payload.streaming !== void 0) {
3243
3413
  body.streaming = payload.streaming;
3244
3414
  }
3415
+ if (payload.idempotencyKey) {
3416
+ body.idempotencyKey = payload.idempotencyKey;
3417
+ }
3418
+ if (payload.senderUaid) {
3419
+ body.senderUaid = payload.senderUaid;
3420
+ }
3421
+ if (payload.transport) {
3422
+ body.transport = payload.transport;
3423
+ }
3245
3424
  if (payload.auth) {
3246
3425
  body.auth = serialiseAuthConfig(payload.auth);
3247
3426
  }
@@ -3285,9 +3464,130 @@ async function sendMessage(client, payload) {
3285
3464
  );
3286
3465
  }
3287
3466
  async function endSession(client, sessionId) {
3288
- await client.request(`/chat/session/${encodeURIComponent(sessionId)}`, {
3289
- method: "DELETE"
3290
- });
3467
+ const normalizedSessionId = sessionId?.trim();
3468
+ if (!normalizedSessionId) {
3469
+ throw new Error("sessionId is required to end a chat session");
3470
+ }
3471
+ const response = await client.request(
3472
+ `/chat/session/${encodeURIComponent(normalizedSessionId)}`,
3473
+ { method: "DELETE" }
3474
+ );
3475
+ if (response.status === 204) {
3476
+ return {
3477
+ message: "Session ended",
3478
+ sessionId: normalizedSessionId,
3479
+ state: "ended"
3480
+ };
3481
+ }
3482
+ const contentType = response.headers?.get("content-type") ?? "";
3483
+ if (!contentType.toLowerCase().includes("json")) {
3484
+ await response.text();
3485
+ return {
3486
+ message: "Session ended",
3487
+ sessionId: normalizedSessionId,
3488
+ state: "ended"
3489
+ };
3490
+ }
3491
+ const responseBody = await response.text();
3492
+ if (responseBody.trim().length === 0) {
3493
+ return {
3494
+ message: "Session ended",
3495
+ sessionId: normalizedSessionId,
3496
+ state: "ended"
3497
+ };
3498
+ }
3499
+ const raw = JSON.parse(responseBody);
3500
+ return client.parseWithSchema(
3501
+ raw,
3502
+ chatSessionEndResponseSchema,
3503
+ "chat session end response"
3504
+ );
3505
+ }
3506
+ async function cancelSession(client, sessionId) {
3507
+ const normalizedSessionId = sessionId?.trim();
3508
+ if (!normalizedSessionId) {
3509
+ throw new Error("sessionId is required to cancel a chat session");
3510
+ }
3511
+ const raw = await client.requestJson(
3512
+ `/chat/session/${encodeURIComponent(normalizedSessionId)}/cancel`,
3513
+ {
3514
+ method: "POST"
3515
+ }
3516
+ );
3517
+ return client.parseWithSchema(
3518
+ raw,
3519
+ chatSessionEndResponseSchema,
3520
+ "chat session cancel response"
3521
+ );
3522
+ }
3523
+ async function retryMessage(client, messageId, payload) {
3524
+ const normalizedMessageId = messageId?.trim();
3525
+ const normalizedSessionId = payload.sessionId?.trim();
3526
+ const normalizedMessage = payload.message?.trim();
3527
+ if (!normalizedMessageId) {
3528
+ throw new Error("messageId is required to retry a message");
3529
+ }
3530
+ if (!normalizedSessionId) {
3531
+ throw new Error("sessionId is required to retry a message");
3532
+ }
3533
+ if (!normalizedMessage) {
3534
+ throw new Error("message is required to retry a message");
3535
+ }
3536
+ const body = {
3537
+ sessionId: normalizedSessionId,
3538
+ message: payload.message
3539
+ };
3540
+ if (payload.streaming !== void 0) {
3541
+ body.streaming = payload.streaming;
3542
+ }
3543
+ if (payload.transport) {
3544
+ body.transport = payload.transport;
3545
+ }
3546
+ const uaid = payload.uaid?.trim();
3547
+ const agentUrl = payload.agentUrl?.trim();
3548
+ const idempotencyKey = payload.idempotencyKey?.trim();
3549
+ const senderUaid = payload.senderUaid?.trim();
3550
+ if (uaid) {
3551
+ body.uaid = uaid;
3552
+ }
3553
+ if (agentUrl) {
3554
+ body.agentUrl = agentUrl;
3555
+ }
3556
+ if (idempotencyKey) {
3557
+ body.idempotencyKey = idempotencyKey;
3558
+ }
3559
+ if (senderUaid) {
3560
+ body.senderUaid = senderUaid;
3561
+ }
3562
+ if (payload.auth) {
3563
+ body.auth = serialiseAuthConfig(payload.auth);
3564
+ }
3565
+ let cipherEnvelope = payload.cipherEnvelope ?? null;
3566
+ if (payload.encryption) {
3567
+ if (!payload.encryption.recipients?.length) {
3568
+ throw new Error("recipients are required for encrypted chat payloads");
3569
+ }
3570
+ cipherEnvelope = client.encryption.encryptCipherEnvelope({
3571
+ ...payload.encryption,
3572
+ sessionId: payload.encryption.sessionId ?? normalizedSessionId
3573
+ });
3574
+ }
3575
+ if (cipherEnvelope) {
3576
+ body.cipherEnvelope = toJsonObject(cipherEnvelope);
3577
+ }
3578
+ const raw = await client.requestJson(
3579
+ `/chat/message/${encodeURIComponent(normalizedMessageId)}/retry`,
3580
+ {
3581
+ method: "POST",
3582
+ body,
3583
+ headers: { "content-type": "application/json" }
3584
+ }
3585
+ );
3586
+ return client.parseWithSchema(
3587
+ raw,
3588
+ sendMessageResponseSchema,
3589
+ "chat retry response"
3590
+ );
3291
3591
  }
3292
3592
 
3293
3593
  // ../../src/services/registry-broker/client/encryption.ts
@@ -4293,10 +4593,98 @@ async function registerOwnedMoltbookAgent(client, uaid, request) {
4293
4593
  }
4294
4594
 
4295
4595
  // ../../src/services/registry-broker/client/guard.ts
4596
+ function isStatusError(error) {
4597
+ if (error instanceof RegistryBrokerError) {
4598
+ return true;
4599
+ }
4600
+ if (typeof error !== "object" || error === null || !("status" in error)) {
4601
+ return false;
4602
+ }
4603
+ return typeof Reflect.get(error, "status") === "number";
4604
+ }
4605
+ function toPortalCanonicalGuardPath(path) {
4606
+ const segments = path.split("/");
4607
+ const findPatternStart = (size, matcher) => {
4608
+ for (let startIndex = segments.length - size; startIndex >= 0; startIndex -= 1) {
4609
+ if (matcher(startIndex)) {
4610
+ return startIndex;
4611
+ }
4612
+ }
4613
+ return -1;
4614
+ };
4615
+ const replaceAt = (startIndex, consumed) => [
4616
+ ...segments.slice(0, startIndex),
4617
+ "api",
4618
+ "guard",
4619
+ ...segments.slice(startIndex + consumed)
4620
+ ].join("/");
4621
+ const registryStart = findPatternStart(
4622
+ 4,
4623
+ (startIndex) => segments[startIndex] === "registry" && segments[startIndex + 1] === "api" && /^v\d+$/.test(segments[startIndex + 2] ?? "") && segments[startIndex + 3] === "guard"
4624
+ );
4625
+ if (registryStart >= 0) {
4626
+ return replaceAt(registryStart, 4);
4627
+ }
4628
+ const apiVersionStart = findPatternStart(
4629
+ 3,
4630
+ (startIndex) => segments[startIndex] === "api" && /^v\d+$/.test(segments[startIndex + 1] ?? "") && segments[startIndex + 2] === "guard"
4631
+ );
4632
+ if (apiVersionStart >= 0) {
4633
+ return replaceAt(apiVersionStart, 3);
4634
+ }
4635
+ for (let index = segments.length - 1; index >= 0; index -= 1) {
4636
+ if (segments[index] === "guard" && segments[index - 1] !== "api") {
4637
+ return [
4638
+ ...segments.slice(0, index),
4639
+ "api",
4640
+ "guard",
4641
+ ...segments.slice(index + 1)
4642
+ ].join("/");
4643
+ }
4644
+ }
4645
+ return path;
4646
+ }
4647
+ function buildPortalCanonicalGuardUrl(baseUrl, path) {
4648
+ const target = new URL(path, "https://guard.local");
4649
+ const normalizedBasePath = (() => {
4650
+ try {
4651
+ const base = new URL(baseUrl);
4652
+ return base.pathname.replace(/\/+$/, "");
4653
+ } catch {
4654
+ return baseUrl.replace(/\/+$/, "");
4655
+ }
4656
+ })();
4657
+ const requestedPath = `${normalizedBasePath}${target.pathname}`;
4658
+ const canonicalPath = toPortalCanonicalGuardPath(requestedPath);
4659
+ const canonicalRelativePath = `${canonicalPath}${target.search}`;
4660
+ try {
4661
+ const base = new URL(baseUrl);
4662
+ return `${base.origin}${canonicalRelativePath}`;
4663
+ } catch {
4664
+ return canonicalRelativePath;
4665
+ }
4666
+ }
4667
+ async function requestPortalFirstJson(client, path, init) {
4668
+ try {
4669
+ return await client.requestJson(path, init);
4670
+ } catch (error) {
4671
+ if (isStatusError(error) && (error.status === 404 || error.status === 501)) {
4672
+ return client.requestAbsoluteJson(
4673
+ buildPortalCanonicalGuardUrl(client.baseUrl, path),
4674
+ init
4675
+ );
4676
+ }
4677
+ throw error;
4678
+ }
4679
+ }
4296
4680
  async function getGuardSession(client) {
4297
- const raw = await client.requestJson("/guard/auth/session", {
4298
- method: "GET"
4299
- });
4681
+ const raw = await requestPortalFirstJson(
4682
+ client,
4683
+ "/guard/auth/session",
4684
+ {
4685
+ method: "GET"
4686
+ }
4687
+ );
4300
4688
  return client.parseWithSchema(
4301
4689
  raw,
4302
4690
  guardSessionResponseSchema,
@@ -4304,9 +4692,13 @@ async function getGuardSession(client) {
4304
4692
  );
4305
4693
  }
4306
4694
  async function getGuardEntitlements(client) {
4307
- const raw = await client.requestJson("/guard/entitlements", {
4308
- method: "GET"
4309
- });
4695
+ const raw = await requestPortalFirstJson(
4696
+ client,
4697
+ "/guard/entitlements",
4698
+ {
4699
+ method: "GET"
4700
+ }
4701
+ );
4310
4702
  return client.parseWithSchema(
4311
4703
  raw,
4312
4704
  guardSessionResponseSchema,
@@ -4314,9 +4706,13 @@ async function getGuardEntitlements(client) {
4314
4706
  );
4315
4707
  }
4316
4708
  async function getGuardBillingBalance(client) {
4317
- const raw = await client.requestJson("/guard/billing/balance", {
4318
- method: "GET"
4319
- });
4709
+ const raw = await requestPortalFirstJson(
4710
+ client,
4711
+ "/guard/billing/balance",
4712
+ {
4713
+ method: "GET"
4714
+ }
4715
+ );
4320
4716
  return client.parseWithSchema(
4321
4717
  raw,
4322
4718
  guardBalanceResponseSchema,
@@ -4330,9 +4726,13 @@ async function getGuardFeed(client, limit) {
4330
4726
  }
4331
4727
  const query = params.toString();
4332
4728
  const suffix = query ? `?${query}` : "";
4333
- const raw = await client.requestJson(`/guard/feed${suffix}`, {
4334
- method: "GET"
4335
- });
4729
+ const raw = await requestPortalFirstJson(
4730
+ client,
4731
+ `/guard/feed${suffix}`,
4732
+ {
4733
+ method: "GET"
4734
+ }
4735
+ );
4336
4736
  return client.parseWithSchema(
4337
4737
  raw,
4338
4738
  guardFeedResponseSchema,
@@ -4340,9 +4740,13 @@ async function getGuardFeed(client, limit) {
4340
4740
  );
4341
4741
  }
4342
4742
  async function getGuardOverview(client) {
4343
- const raw = await client.requestJson("/guard/overview", {
4344
- method: "GET"
4345
- });
4743
+ const raw = await requestPortalFirstJson(
4744
+ client,
4745
+ "/guard/overview",
4746
+ {
4747
+ method: "GET"
4748
+ }
4749
+ );
4346
4750
  return client.parseWithSchema(
4347
4751
  raw,
4348
4752
  guardOverviewResponseSchema,
@@ -4354,7 +4758,8 @@ async function getGuardTrustByHash(client, sha256) {
4354
4758
  if (!normalizedHash) {
4355
4759
  throw new Error("sha256 is required");
4356
4760
  }
4357
- const raw = await client.requestJson(
4761
+ const raw = await requestPortalFirstJson(
4762
+ client,
4358
4763
  `/guard/trust/by-hash/${encodeURIComponent(normalizedHash)}`,
4359
4764
  { method: "GET" }
4360
4765
  );
@@ -4376,7 +4781,8 @@ async function resolveGuardTrust(client, query) {
4376
4781
  params.set("version", query.version.trim());
4377
4782
  }
4378
4783
  const suffix = params.size > 0 ? `?${params.toString()}` : "";
4379
- const raw = await client.requestJson(
4784
+ const raw = await requestPortalFirstJson(
4785
+ client,
4380
4786
  `/guard/trust/resolve${suffix}`,
4381
4787
  { method: "GET" }
4382
4788
  );
@@ -4387,9 +4793,13 @@ async function resolveGuardTrust(client, query) {
4387
4793
  );
4388
4794
  }
4389
4795
  async function getGuardRevocations(client) {
4390
- const raw = await client.requestJson("/guard/revocations", {
4391
- method: "GET"
4392
- });
4796
+ const raw = await requestPortalFirstJson(
4797
+ client,
4798
+ "/guard/revocations",
4799
+ {
4800
+ method: "GET"
4801
+ }
4802
+ );
4393
4803
  return client.parseWithSchema(
4394
4804
  raw,
4395
4805
  guardRevocationResponseSchema,
@@ -4397,9 +4807,13 @@ async function getGuardRevocations(client) {
4397
4807
  );
4398
4808
  }
4399
4809
  async function fetchGuardAdvisories(client) {
4400
- const raw = await client.requestJson("/guard/advisories", {
4401
- method: "GET"
4402
- });
4810
+ const raw = await requestPortalFirstJson(
4811
+ client,
4812
+ "/guard/advisories",
4813
+ {
4814
+ method: "GET"
4815
+ }
4816
+ );
4403
4817
  return client.parseWithSchema(
4404
4818
  raw,
4405
4819
  guardRevocationResponseSchema,
@@ -4407,9 +4821,13 @@ async function fetchGuardAdvisories(client) {
4407
4821
  );
4408
4822
  }
4409
4823
  async function fetchGuardPolicy(client) {
4410
- const raw = await client.requestJson("/guard/policy/fetch", {
4411
- method: "GET"
4412
- });
4824
+ const raw = await requestPortalFirstJson(
4825
+ client,
4826
+ "/guard/policy/fetch",
4827
+ {
4828
+ method: "GET"
4829
+ }
4830
+ );
4413
4831
  return client.parseWithSchema(
4414
4832
  raw,
4415
4833
  guardPolicySchema,
@@ -4417,9 +4835,13 @@ async function fetchGuardPolicy(client) {
4417
4835
  );
4418
4836
  }
4419
4837
  async function getGuardInventory(client) {
4420
- const raw = await client.requestJson("/guard/inventory", {
4421
- method: "GET"
4422
- });
4838
+ const raw = await requestPortalFirstJson(
4839
+ client,
4840
+ "/guard/inventory",
4841
+ {
4842
+ method: "GET"
4843
+ }
4844
+ );
4423
4845
  return client.parseWithSchema(
4424
4846
  raw,
4425
4847
  guardInventoryResponseSchema,
@@ -4427,9 +4849,13 @@ async function getGuardInventory(client) {
4427
4849
  );
4428
4850
  }
4429
4851
  async function getGuardReceiptHistory(client) {
4430
- const raw = await client.requestJson("/guard/history", {
4431
- method: "GET"
4432
- });
4852
+ const raw = await requestPortalFirstJson(
4853
+ client,
4854
+ "/guard/history",
4855
+ {
4856
+ method: "GET"
4857
+ }
4858
+ );
4433
4859
  return client.parseWithSchema(
4434
4860
  raw,
4435
4861
  guardReceiptHistoryResponseSchema,
@@ -4441,7 +4867,8 @@ async function getGuardArtifactTimeline(client, artifactId) {
4441
4867
  if (!normalizedArtifactId) {
4442
4868
  throw new Error("artifactId is required");
4443
4869
  }
4444
- const raw = await client.requestJson(
4870
+ const raw = await requestPortalFirstJson(
4871
+ client,
4445
4872
  `/guard/history/${encodeURIComponent(normalizedArtifactId)}`,
4446
4873
  { method: "GET" }
4447
4874
  );
@@ -4452,7 +4879,7 @@ async function getGuardArtifactTimeline(client, artifactId) {
4452
4879
  );
4453
4880
  }
4454
4881
  async function exportGuardAbom(client) {
4455
- const raw = await client.requestJson("/guard/abom", {
4882
+ const raw = await requestPortalFirstJson(client, "/guard/abom", {
4456
4883
  method: "GET"
4457
4884
  });
4458
4885
  return client.parseWithSchema(
@@ -4466,7 +4893,8 @@ async function exportGuardArtifactAbom(client, artifactId) {
4466
4893
  if (!normalizedArtifactId) {
4467
4894
  throw new Error("artifactId is required");
4468
4895
  }
4469
- const raw = await client.requestJson(
4896
+ const raw = await requestPortalFirstJson(
4897
+ client,
4470
4898
  `/guard/abom/${encodeURIComponent(normalizedArtifactId)}`,
4471
4899
  { method: "GET" }
4472
4900
  );
@@ -4477,9 +4905,13 @@ async function exportGuardArtifactAbom(client, artifactId) {
4477
4905
  );
4478
4906
  }
4479
4907
  async function exportGuardReceipts(client) {
4480
- const raw = await client.requestJson("/guard/receipts/export", {
4481
- method: "GET"
4482
- });
4908
+ const raw = await requestPortalFirstJson(
4909
+ client,
4910
+ "/guard/receipts/export",
4911
+ {
4912
+ method: "GET"
4913
+ }
4914
+ );
4483
4915
  return client.parseWithSchema(
4484
4916
  raw,
4485
4917
  guardReceiptExportResponseSchema,
@@ -4487,9 +4919,13 @@ async function exportGuardReceipts(client) {
4487
4919
  );
4488
4920
  }
4489
4921
  async function getGuardInventoryDiff(client) {
4490
- const raw = await client.requestJson("/guard/inventory/diff", {
4491
- method: "GET"
4492
- });
4922
+ const raw = await requestPortalFirstJson(
4923
+ client,
4924
+ "/guard/inventory/diff",
4925
+ {
4926
+ method: "GET"
4927
+ }
4928
+ );
4493
4929
  return client.parseWithSchema(
4494
4930
  raw,
4495
4931
  guardInventoryDiffResponseSchema,
@@ -4497,9 +4933,13 @@ async function getGuardInventoryDiff(client) {
4497
4933
  );
4498
4934
  }
4499
4935
  async function getGuardDevices(client) {
4500
- const raw = await client.requestJson("/guard/devices", {
4501
- method: "GET"
4502
- });
4936
+ const raw = await requestPortalFirstJson(
4937
+ client,
4938
+ "/guard/devices",
4939
+ {
4940
+ method: "GET"
4941
+ }
4942
+ );
4503
4943
  return client.parseWithSchema(
4504
4944
  raw,
4505
4945
  guardDeviceListResponseSchema,
@@ -4507,9 +4947,13 @@ async function getGuardDevices(client) {
4507
4947
  );
4508
4948
  }
4509
4949
  async function getGuardAlertPreferences(client) {
4510
- const raw = await client.requestJson("/guard/alerts/preferences", {
4511
- method: "GET"
4512
- });
4950
+ const raw = await requestPortalFirstJson(
4951
+ client,
4952
+ "/guard/alerts/preferences",
4953
+ {
4954
+ method: "GET"
4955
+ }
4956
+ );
4513
4957
  return client.parseWithSchema(
4514
4958
  raw,
4515
4959
  guardAlertPreferencesSchema,
@@ -4517,10 +4961,14 @@ async function getGuardAlertPreferences(client) {
4517
4961
  );
4518
4962
  }
4519
4963
  async function updateGuardAlertPreferences(client, payload) {
4520
- const raw = await client.requestJson("/guard/alerts/preferences", {
4521
- method: "PUT",
4522
- body: payload
4523
- });
4964
+ const raw = await requestPortalFirstJson(
4965
+ client,
4966
+ "/guard/alerts/preferences",
4967
+ {
4968
+ method: "PUT",
4969
+ body: payload
4970
+ }
4971
+ );
4524
4972
  return client.parseWithSchema(
4525
4973
  raw,
4526
4974
  guardAlertPreferencesSchema,
@@ -4528,9 +4976,13 @@ async function updateGuardAlertPreferences(client, payload) {
4528
4976
  );
4529
4977
  }
4530
4978
  async function getGuardExceptions(client) {
4531
- const raw = await client.requestJson("/guard/exceptions", {
4532
- method: "GET"
4533
- });
4979
+ const raw = await requestPortalFirstJson(
4980
+ client,
4981
+ "/guard/exceptions",
4982
+ {
4983
+ method: "GET"
4984
+ }
4985
+ );
4534
4986
  return client.parseWithSchema(
4535
4987
  raw,
4536
4988
  guardExceptionListResponseSchema,
@@ -4538,9 +4990,13 @@ async function getGuardExceptions(client) {
4538
4990
  );
4539
4991
  }
4540
4992
  async function getGuardWatchlist(client) {
4541
- const raw = await client.requestJson("/guard/watchlist", {
4542
- method: "GET"
4543
- });
4993
+ const raw = await requestPortalFirstJson(
4994
+ client,
4995
+ "/guard/watchlist",
4996
+ {
4997
+ method: "GET"
4998
+ }
4999
+ );
4544
5000
  return client.parseWithSchema(
4545
5001
  raw,
4546
5002
  guardWatchlistResponseSchema,
@@ -4548,10 +5004,14 @@ async function getGuardWatchlist(client) {
4548
5004
  );
4549
5005
  }
4550
5006
  async function lookupGuardWatchlist(client, payload) {
4551
- const raw = await client.requestJson("/guard/watchlist/lookup", {
4552
- method: "POST",
4553
- body: payload
4554
- });
5007
+ const raw = await requestPortalFirstJson(
5008
+ client,
5009
+ "/guard/watchlist/lookup",
5010
+ {
5011
+ method: "POST",
5012
+ body: payload
5013
+ }
5014
+ );
4555
5015
  return client.parseWithSchema(
4556
5016
  raw,
4557
5017
  guardWatchlistLookupResponseSchema,
@@ -4559,9 +5019,13 @@ async function lookupGuardWatchlist(client, payload) {
4559
5019
  );
4560
5020
  }
4561
5021
  async function getGuardPainSignals(client) {
4562
- const raw = await client.requestJson("/guard/signals/pain", {
4563
- method: "GET"
4564
- });
5022
+ const raw = await requestPortalFirstJson(
5023
+ client,
5024
+ "/guard/signals/pain",
5025
+ {
5026
+ method: "GET"
5027
+ }
5028
+ );
4565
5029
  return client.parseWithSchema(
4566
5030
  raw,
4567
5031
  guardPainSignalListResponseSchema,
@@ -4569,7 +5033,8 @@ async function getGuardPainSignals(client) {
4569
5033
  );
4570
5034
  }
4571
5035
  async function getGuardAggregatedPainSignals(client) {
4572
- const raw = await client.requestJson(
5036
+ const raw = await requestPortalFirstJson(
5037
+ client,
4573
5038
  "/guard/signals/pain/aggregate",
4574
5039
  {
4575
5040
  method: "GET"
@@ -4582,7 +5047,7 @@ async function getGuardAggregatedPainSignals(client) {
4582
5047
  );
4583
5048
  }
4584
5049
  async function getGuardPreflightVerdict(client, path, payload) {
4585
- const raw = await client.requestJson(path, {
5050
+ const raw = await requestPortalFirstJson(client, path, {
4586
5051
  method: "POST",
4587
5052
  body: payload
4588
5053
  });
@@ -4607,10 +5072,14 @@ async function getGuardPreExecutionVerdict(client, payload) {
4607
5072
  );
4608
5073
  }
4609
5074
  async function ingestGuardPainSignals(client, items) {
4610
- const raw = await client.requestJson("/guard/signals/pain", {
4611
- method: "POST",
4612
- body: { items }
4613
- });
5075
+ const raw = await requestPortalFirstJson(
5076
+ client,
5077
+ "/guard/signals/pain",
5078
+ {
5079
+ method: "POST",
5080
+ body: { items }
5081
+ }
5082
+ );
4614
5083
  return client.parseWithSchema(
4615
5084
  raw,
4616
5085
  guardPainSignalListResponseSchema,
@@ -4618,10 +5087,14 @@ async function ingestGuardPainSignals(client, items) {
4618
5087
  );
4619
5088
  }
4620
5089
  async function submitGuardReceipts(client, payload) {
4621
- const raw = await client.requestJson("/guard/receipts/submit", {
4622
- method: "POST",
4623
- body: payload
4624
- });
5090
+ const raw = await requestPortalFirstJson(
5091
+ client,
5092
+ "/guard/receipts/submit",
5093
+ {
5094
+ method: "POST",
5095
+ body: payload
5096
+ }
5097
+ );
4625
5098
  return client.parseWithSchema(
4626
5099
  raw,
4627
5100
  guardReceiptSyncResponseSchema,
@@ -4629,10 +5102,14 @@ async function submitGuardReceipts(client, payload) {
4629
5102
  );
4630
5103
  }
4631
5104
  async function addGuardWatchlistItem(client, payload) {
4632
- const raw = await client.requestJson("/guard/watchlist", {
4633
- method: "POST",
4634
- body: payload
4635
- });
5105
+ const raw = await requestPortalFirstJson(
5106
+ client,
5107
+ "/guard/watchlist",
5108
+ {
5109
+ method: "POST",
5110
+ body: payload
5111
+ }
5112
+ );
4636
5113
  return client.parseWithSchema(
4637
5114
  raw,
4638
5115
  guardWatchlistResponseSchema,
@@ -4644,7 +5121,8 @@ async function removeGuardWatchlistItem(client, artifactId) {
4644
5121
  if (!normalizedArtifactId) {
4645
5122
  throw new Error("artifactId is required");
4646
5123
  }
4647
- const raw = await client.requestJson(
5124
+ const raw = await requestPortalFirstJson(
5125
+ client,
4648
5126
  `/guard/watchlist/${encodeURIComponent(normalizedArtifactId)}`,
4649
5127
  { method: "DELETE" }
4650
5128
  );
@@ -4655,10 +5133,14 @@ async function removeGuardWatchlistItem(client, artifactId) {
4655
5133
  );
4656
5134
  }
4657
5135
  async function addGuardException(client, payload) {
4658
- const raw = await client.requestJson("/guard/exceptions", {
4659
- method: "POST",
4660
- body: payload
4661
- });
5136
+ const raw = await requestPortalFirstJson(
5137
+ client,
5138
+ "/guard/exceptions",
5139
+ {
5140
+ method: "POST",
5141
+ body: payload
5142
+ }
5143
+ );
4662
5144
  return client.parseWithSchema(
4663
5145
  raw,
4664
5146
  guardExceptionListResponseSchema,
@@ -4666,10 +5148,14 @@ async function addGuardException(client, payload) {
4666
5148
  );
4667
5149
  }
4668
5150
  async function requestGuardException(client, payload) {
4669
- const raw = await client.requestJson("/guard/exceptions/request", {
4670
- method: "POST",
4671
- body: payload
4672
- });
5151
+ const raw = await requestPortalFirstJson(
5152
+ client,
5153
+ "/guard/exceptions/request",
5154
+ {
5155
+ method: "POST",
5156
+ body: payload
5157
+ }
5158
+ );
4673
5159
  return client.parseWithSchema(
4674
5160
  raw,
4675
5161
  guardExceptionListResponseSchema,
@@ -4677,10 +5163,14 @@ async function requestGuardException(client, payload) {
4677
5163
  );
4678
5164
  }
4679
5165
  async function syncGuardInventory(client, payload) {
4680
- const raw = await client.requestJson("/guard/inventory/sync", {
4681
- method: "POST",
4682
- body: payload
4683
- });
5166
+ const raw = await requestPortalFirstJson(
5167
+ client,
5168
+ "/guard/inventory/sync",
5169
+ {
5170
+ method: "POST",
5171
+ body: payload
5172
+ }
5173
+ );
4684
5174
  return client.parseWithSchema(
4685
5175
  raw,
4686
5176
  guardReceiptSyncResponseSchema,
@@ -4692,7 +5182,8 @@ async function removeGuardException(client, exceptionId) {
4692
5182
  if (!normalizedExceptionId) {
4693
5183
  throw new Error("exceptionId is required");
4694
5184
  }
4695
- const raw = await client.requestJson(
5185
+ const raw = await requestPortalFirstJson(
5186
+ client,
4696
5187
  `/guard/exceptions/${encodeURIComponent(normalizedExceptionId)}`,
4697
5188
  { method: "DELETE" }
4698
5189
  );
@@ -4703,9 +5194,13 @@ async function removeGuardException(client, exceptionId) {
4703
5194
  );
4704
5195
  }
4705
5196
  async function getGuardTeamPolicyPack(client) {
4706
- const raw = await client.requestJson("/guard/team/policy-pack", {
4707
- method: "GET"
4708
- });
5197
+ const raw = await requestPortalFirstJson(
5198
+ client,
5199
+ "/guard/team/policy-pack",
5200
+ {
5201
+ method: "GET"
5202
+ }
5203
+ );
4709
5204
  return client.parseWithSchema(
4710
5205
  raw,
4711
5206
  guardTeamPolicyPackSchema,
@@ -4713,10 +5208,14 @@ async function getGuardTeamPolicyPack(client) {
4713
5208
  );
4714
5209
  }
4715
5210
  async function updateGuardTeamPolicyPack(client, payload) {
4716
- const raw = await client.requestJson("/guard/team/policy-pack", {
4717
- method: "PUT",
4718
- body: payload
4719
- });
5211
+ const raw = await requestPortalFirstJson(
5212
+ client,
5213
+ "/guard/team/policy-pack",
5214
+ {
5215
+ method: "PUT",
5216
+ body: payload
5217
+ }
5218
+ );
4720
5219
  return client.parseWithSchema(
4721
5220
  raw,
4722
5221
  guardTeamPolicyPackSchema,
@@ -4724,10 +5223,14 @@ async function updateGuardTeamPolicyPack(client, payload) {
4724
5223
  );
4725
5224
  }
4726
5225
  async function syncGuardReceipts(client, payload) {
4727
- const raw = await client.requestJson("/guard/receipts/sync", {
4728
- method: "POST",
4729
- body: payload
4730
- });
5226
+ const raw = await requestPortalFirstJson(
5227
+ client,
5228
+ "/guard/receipts/sync",
5229
+ {
5230
+ method: "POST",
5231
+ body: payload
5232
+ }
5233
+ );
4731
5234
  return client.parseWithSchema(
4732
5235
  raw,
4733
5236
  guardReceiptSyncResponseSchema,
@@ -6063,7 +6566,7 @@ var RegistryBrokerClient = class _RegistryBrokerClient {
6063
6566
  const normalisedPath = path.startsWith("/") ? path : `/${path}`;
6064
6567
  return `${this.baseUrl}${normalisedPath}`;
6065
6568
  }
6066
- async request(path, config) {
6569
+ buildRequestInit(config) {
6067
6570
  const headers = new Headers();
6068
6571
  Object.entries(this.defaultHeaders).forEach(([key, value]) => {
6069
6572
  headers.set(key, value);
@@ -6089,6 +6592,10 @@ var RegistryBrokerClient = class _RegistryBrokerClient {
6089
6592
  headers.set("content-type", "application/json");
6090
6593
  }
6091
6594
  }
6595
+ return init;
6596
+ }
6597
+ async request(path, config) {
6598
+ const init = this.buildRequestInit(config);
6092
6599
  const response = await this.fetchImpl(this.buildUrl(path), init);
6093
6600
  if (response.ok) {
6094
6601
  return response;
@@ -6100,6 +6607,19 @@ var RegistryBrokerClient = class _RegistryBrokerClient {
6100
6607
  body: errorBody
6101
6608
  });
6102
6609
  }
6610
+ async requestAbsolute(url, config) {
6611
+ const init = this.buildRequestInit(config);
6612
+ const response = await this.fetchImpl(url, init);
6613
+ if (response.ok) {
6614
+ return response;
6615
+ }
6616
+ const errorBody = await this.extractErrorBody(response);
6617
+ throw new RegistryBrokerError("Registry broker request failed", {
6618
+ status: response.status,
6619
+ statusText: response.statusText,
6620
+ body: errorBody
6621
+ });
6622
+ }
6103
6623
  async requestJson(path, config) {
6104
6624
  const response = await this.request(path, config);
6105
6625
  const contentType = response.headers?.get("content-type") ?? "";
@@ -6112,6 +6632,18 @@ var RegistryBrokerClient = class _RegistryBrokerClient {
6112
6632
  }
6113
6633
  return await response.json();
6114
6634
  }
6635
+ async requestAbsoluteJson(url, config) {
6636
+ const response = await this.requestAbsolute(url, config);
6637
+ const contentType = response.headers?.get("content-type") ?? "";
6638
+ if (!JSON_CONTENT_TYPE.test(contentType)) {
6639
+ const body = await response.text();
6640
+ throw new RegistryBrokerParseError(
6641
+ "Expected JSON response from registry broker",
6642
+ body
6643
+ );
6644
+ }
6645
+ return await response.json();
6646
+ }
6115
6647
  async getAgentFeedback(uaid, options = {}) {
6116
6648
  const normalized = uaid.trim();
6117
6649
  if (!normalized) {
@@ -6746,6 +7278,9 @@ var RegistryBrokerClient = class _RegistryBrokerClient {
6746
7278
  async createSession(payload, allowHistoryAutoTopUp = true) {
6747
7279
  return createSession(this, payload, allowHistoryAutoTopUp);
6748
7280
  }
7281
+ async checkChatReadiness(payload) {
7282
+ return checkChatReadiness(this, payload);
7283
+ }
6749
7284
  async startChat(options) {
6750
7285
  return startChat(this, this.getEncryptedChatManager(), options);
6751
7286
  }
@@ -6771,6 +7306,12 @@ var RegistryBrokerClient = class _RegistryBrokerClient {
6771
7306
  sendMessage(payload) {
6772
7307
  return sendMessage(this, payload);
6773
7308
  }
7309
+ retryMessage(messageId, payload) {
7310
+ return retryMessage(this, messageId, payload);
7311
+ }
7312
+ cancelSession(sessionId) {
7313
+ return cancelSession(this, sessionId);
7314
+ }
6774
7315
  endSession(sessionId) {
6775
7316
  return endSession(this, sessionId);
6776
7317
  }
@@ -7037,6 +7578,10 @@ var isPendingRegisterAgentResponse = (response) => response.status === "pending"
7037
7578
  var isPartialRegisterAgentResponse = (response) => response.status === "partial" && response.success === false;
7038
7579
  var isSuccessRegisterAgentResponse = (response) => response.success === true && response.status !== "pending";
7039
7580
 
7581
+ // ../../src/services/registry-broker/types.ts
7582
+ var GUARD_CANONICAL_PATH_PREFIX = "/api/guard";
7583
+ var GUARD_COMPAT_PATH_PREFIX = "/guard";
7584
+
7040
7585
  // ../../src/services/registry-broker/hol-chat-ops.ts
7041
7586
  var HOL_CHAT_PROTOCOL_ID = "hol-chat";
7042
7587
  var isRecord = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value);
@@ -7094,6 +7639,8 @@ var buildJobStatusMessage = (input) => JSON.stringify({
7094
7639
  });
7095
7640
  // Annotate the CommonJS export names for ESM import in node:
7096
7641
  0 && (module.exports = {
7642
+ GUARD_CANONICAL_PATH_PREFIX,
7643
+ GUARD_COMPAT_PATH_PREFIX,
7097
7644
  HOL_CHAT_PROTOCOL_ID,
7098
7645
  RegistryBrokerClient,
7099
7646
  RegistryBrokerError,