@hol-org/rb-client 0.1.170 → 0.1.172

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
@@ -37,13 +37,23 @@ __export(src_exports, {
37
37
  buildPaymentApproveMessage: () => buildPaymentApproveMessage,
38
38
  buildPaymentDeclineMessage: () => buildPaymentDeclineMessage,
39
39
  canonicalizeLedgerNetwork: () => canonicalizeLedgerNetwork,
40
+ closeUaidConnection: () => closeUaidConnection,
40
41
  createPrivateKeySigner: () => createPrivateKeySigner,
41
42
  createPrivateKeySignerAsync: () => createPrivateKeySignerAsync,
43
+ dashboardStats: () => dashboardStats,
44
+ getRegistrationProgress: () => getRegistrationProgress,
45
+ getRegistrationQuote: () => getRegistrationQuote,
46
+ getUaidConnectionStatus: () => getUaidConnectionStatus,
42
47
  isHolChatOp: () => isHolChatOp,
43
48
  isPartialRegisterAgentResponse: () => isPartialRegisterAgentResponse,
44
49
  isPendingRegisterAgentResponse: () => isPendingRegisterAgentResponse,
45
50
  isSuccessRegisterAgentResponse: () => isSuccessRegisterAgentResponse,
46
- parseHolChatOps: () => parseHolChatOps
51
+ parseHolChatOps: () => parseHolChatOps,
52
+ registerAgent: () => registerAgent,
53
+ resolveUaid: () => resolveUaid,
54
+ updateAgent: () => updateAgent,
55
+ validateUaid: () => validateUaid,
56
+ waitForRegistrationCompletion: () => waitForRegistrationCompletion
47
57
  });
48
58
  module.exports = __toCommonJS(src_exports);
49
59
 
@@ -288,6 +298,13 @@ var metadataFacetSchema = import_zod2.z.record(
288
298
  jsonValueSchema
289
299
  ])
290
300
  ).optional();
301
+ var searchHitMetadataSchema = import_zod2.z.object({
302
+ delegationRoles: jsonValueSchema.optional(),
303
+ delegationTaskTags: jsonValueSchema.optional(),
304
+ delegationProtocols: jsonValueSchema.optional(),
305
+ delegationSummary: jsonValueSchema.optional(),
306
+ delegationSignals: jsonValueSchema.optional()
307
+ }).passthrough();
291
308
  var searchHitSchema = import_zod2.z.object({
292
309
  id: import_zod2.z.string(),
293
310
  uaid: import_zod2.z.string(),
@@ -296,7 +313,7 @@ var searchHitSchema = import_zod2.z.object({
296
313
  description: import_zod2.z.string().optional(),
297
314
  capabilities: import_zod2.z.array(capabilityValueSchema),
298
315
  endpoints: import_zod2.z.union([import_zod2.z.record(jsonValueSchema), import_zod2.z.array(import_zod2.z.string())]).optional(),
299
- metadata: import_zod2.z.record(jsonValueSchema).optional(),
316
+ metadata: searchHitMetadataSchema.optional(),
300
317
  metadataFacet: metadataFacetSchema,
301
318
  profile: agentProfileSchema.optional(),
302
319
  protocols: import_zod2.z.array(import_zod2.z.string()).optional(),
@@ -340,6 +357,62 @@ var popularResponseSchema = import_zod2.z.object({
340
357
  var resolveResponseSchema = import_zod2.z.object({
341
358
  agent: searchHitSchema
342
359
  });
360
+ var delegationPlanCandidateSchema = import_zod2.z.object({
361
+ uaid: import_zod2.z.string(),
362
+ label: import_zod2.z.string(),
363
+ registry: import_zod2.z.string().optional(),
364
+ agent: searchHitSchema,
365
+ score: import_zod2.z.number(),
366
+ matchedQueries: import_zod2.z.array(import_zod2.z.string()).optional(),
367
+ matchedRoles: import_zod2.z.array(import_zod2.z.string()).optional(),
368
+ matchedProtocols: import_zod2.z.array(import_zod2.z.string()).optional(),
369
+ matchedSurfaces: import_zod2.z.array(import_zod2.z.string()).optional(),
370
+ matchedLanguages: import_zod2.z.array(import_zod2.z.string()).optional(),
371
+ matchedArtifacts: import_zod2.z.array(import_zod2.z.string()).optional(),
372
+ matchedTaskTags: import_zod2.z.array(import_zod2.z.string()).optional(),
373
+ reasons: import_zod2.z.array(import_zod2.z.string()).optional(),
374
+ suggestedMessage: import_zod2.z.string().optional(),
375
+ trustScore: import_zod2.z.number().optional(),
376
+ verified: import_zod2.z.boolean().optional(),
377
+ communicationSupported: import_zod2.z.boolean().optional(),
378
+ availability: import_zod2.z.boolean().optional(),
379
+ explanation: import_zod2.z.string().optional()
380
+ }).passthrough();
381
+ var delegationOpportunitySchema = import_zod2.z.object({
382
+ id: import_zod2.z.string(),
383
+ title: import_zod2.z.string(),
384
+ reason: import_zod2.z.string(),
385
+ role: import_zod2.z.string(),
386
+ type: import_zod2.z.enum(["ai-agents", "mcp-servers"]),
387
+ suggestedMode: import_zod2.z.enum(["best-match", "fallback", "parallel"]),
388
+ searchQueries: import_zod2.z.array(import_zod2.z.string()),
389
+ protocols: import_zod2.z.array(import_zod2.z.string()).optional(),
390
+ surfaces: import_zod2.z.array(import_zod2.z.string()).optional(),
391
+ languages: import_zod2.z.array(import_zod2.z.string()).optional(),
392
+ artifacts: import_zod2.z.array(import_zod2.z.string()).optional(),
393
+ candidates: import_zod2.z.array(delegationPlanCandidateSchema)
394
+ }).passthrough();
395
+ var delegationRecommendationSchema = import_zod2.z.object({
396
+ action: import_zod2.z.enum(["delegate-now", "review-shortlist", "handle-locally"]),
397
+ confidence: import_zod2.z.number(),
398
+ reason: import_zod2.z.string(),
399
+ opportunityId: import_zod2.z.string().optional(),
400
+ candidate: delegationPlanCandidateSchema.optional()
401
+ }).passthrough();
402
+ var delegationPlanResponseSchema = import_zod2.z.object({
403
+ task: import_zod2.z.string(),
404
+ context: import_zod2.z.string().optional(),
405
+ summary: import_zod2.z.string().optional(),
406
+ intents: import_zod2.z.array(import_zod2.z.string()),
407
+ protocols: import_zod2.z.array(import_zod2.z.string()),
408
+ surfaces: import_zod2.z.array(import_zod2.z.string()),
409
+ languages: import_zod2.z.array(import_zod2.z.string()).optional(),
410
+ artifacts: import_zod2.z.array(import_zod2.z.string()).optional(),
411
+ shouldDelegate: import_zod2.z.boolean(),
412
+ localFirstReason: import_zod2.z.string().optional(),
413
+ recommendation: delegationRecommendationSchema.optional(),
414
+ opportunities: import_zod2.z.array(delegationOpportunitySchema)
415
+ }).passthrough();
343
416
  var agentFeedbackSummarySchema = import_zod2.z.object({
344
417
  averageScore: import_zod2.z.number(),
345
418
  totalFeedbacks: import_zod2.z.number(),
@@ -2119,6 +2192,18 @@ async function search(client, params = {}) {
2119
2192
  });
2120
2193
  return client.parseWithSchema(raw, searchResponseSchema, "search response");
2121
2194
  }
2195
+ async function delegate(client, request) {
2196
+ const raw = await client.requestJson("/delegate", {
2197
+ method: "POST",
2198
+ body: request,
2199
+ headers: { "content-type": "application/json" }
2200
+ });
2201
+ return client.parseWithSchema(
2202
+ raw,
2203
+ delegationPlanResponseSchema,
2204
+ "delegate response"
2205
+ );
2206
+ }
2122
2207
  async function stats(client) {
2123
2208
  const raw = await client.requestJson("/stats", { method: "GET" });
2124
2209
  return client.parseWithSchema(raw, statsResponseSchema, "stats response");
@@ -2499,6 +2584,81 @@ async function buyCreditsWithX402(client, params) {
2499
2584
  }
2500
2585
 
2501
2586
  // ../../src/services/registry-broker/client/agents.ts
2587
+ async function performRegisterAgent(client, payload) {
2588
+ const raw = await client.requestJson("/register", {
2589
+ method: "POST",
2590
+ body: serialiseAgentRegistrationRequest(payload),
2591
+ headers: { "content-type": "application/json" }
2592
+ });
2593
+ return client.parseWithSchema(
2594
+ raw,
2595
+ registerAgentResponseSchema,
2596
+ "register agent response"
2597
+ );
2598
+ }
2599
+ function calculateHbarAmount(creditsToPurchase, creditsPerHbar) {
2600
+ if (creditsPerHbar <= 0) {
2601
+ throw new Error("creditsPerHbar must be positive");
2602
+ }
2603
+ if (creditsToPurchase <= 0) {
2604
+ throw new Error("creditsToPurchase must be positive");
2605
+ }
2606
+ const rawHbar = creditsToPurchase / creditsPerHbar;
2607
+ const tinybars = Math.ceil(rawHbar * 1e8);
2608
+ return tinybars / 1e8;
2609
+ }
2610
+ function resolveCreditsToPurchase(shortfallCredits) {
2611
+ if (!Number.isFinite(shortfallCredits) || shortfallCredits <= 0) {
2612
+ return 0;
2613
+ }
2614
+ return Math.max(
2615
+ Math.ceil(shortfallCredits),
2616
+ MINIMUM_REGISTRATION_AUTO_TOP_UP_CREDITS
2617
+ );
2618
+ }
2619
+ async function ensureCreditsForRegistration(client, payload, autoTopUp) {
2620
+ const details = autoTopUp ?? null;
2621
+ if (!details) {
2622
+ return;
2623
+ }
2624
+ if (!details.accountId || !details.accountId.trim()) {
2625
+ throw new Error("autoTopUp.accountId is required");
2626
+ }
2627
+ if (!details.privateKey || !details.privateKey.trim()) {
2628
+ throw new Error("autoTopUp.privateKey is required");
2629
+ }
2630
+ for (let attempt = 0; attempt < 3; attempt += 1) {
2631
+ const quote = await getRegistrationQuote(client, payload);
2632
+ const shortfall = quote.shortfallCredits ?? 0;
2633
+ if (shortfall <= 0) {
2634
+ return;
2635
+ }
2636
+ const creditsToPurchase = resolveCreditsToPurchase(shortfall);
2637
+ if (creditsToPurchase <= 0) {
2638
+ return;
2639
+ }
2640
+ const creditsPerHbar = quote.creditsPerHbar ?? null;
2641
+ if (!creditsPerHbar || creditsPerHbar <= 0) {
2642
+ throw new Error("Unable to determine credits per HBAR for auto top-up");
2643
+ }
2644
+ const hbarAmount = calculateHbarAmount(creditsToPurchase, creditsPerHbar);
2645
+ await purchaseCreditsWithHbar(client, {
2646
+ accountId: details.accountId.trim(),
2647
+ privateKey: details.privateKey.trim(),
2648
+ hbarAmount,
2649
+ memo: details.memo ?? "Registry Broker auto top-up",
2650
+ metadata: {
2651
+ shortfallCredits: shortfall,
2652
+ requiredCredits: quote.requiredCredits,
2653
+ purchasedCredits: creditsToPurchase
2654
+ }
2655
+ });
2656
+ }
2657
+ const finalQuote = await getRegistrationQuote(client, payload);
2658
+ if ((finalQuote.shortfallCredits ?? 0) > 0) {
2659
+ throw new Error("Unable to purchase sufficient credits for registration");
2660
+ }
2661
+ }
2502
2662
  async function resolveUaid(client, uaid) {
2503
2663
  const raw = await client.requestJson(
2504
2664
  `/resolve/${encodeURIComponent(uaid)}`,
@@ -2512,6 +2672,27 @@ async function resolveUaid(client, uaid) {
2512
2672
  "resolve UAID response"
2513
2673
  );
2514
2674
  }
2675
+ async function registerAgent(client, payload, options) {
2676
+ const autoTopUp = options?.autoTopUp ?? client.registrationAutoTopUp;
2677
+ if (!autoTopUp) {
2678
+ return performRegisterAgent(client, payload);
2679
+ }
2680
+ await ensureCreditsForRegistration(client, payload, autoTopUp);
2681
+ let retried = false;
2682
+ while (true) {
2683
+ try {
2684
+ return await performRegisterAgent(client, payload);
2685
+ } catch (error) {
2686
+ const shortfall = client.extractInsufficientCreditsDetails(error);
2687
+ if (shortfall && !retried) {
2688
+ await ensureCreditsForRegistration(client, payload, autoTopUp);
2689
+ retried = true;
2690
+ continue;
2691
+ }
2692
+ throw error;
2693
+ }
2694
+ }
2695
+ }
2515
2696
  async function getRegistrationQuote(client, payload) {
2516
2697
  const raw = await client.requestJson("/register/quote", {
2517
2698
  method: "POST",
@@ -4654,6 +4835,9 @@ var RegistryBrokerClient = class _RegistryBrokerClient {
4654
4835
  async search(params = {}) {
4655
4836
  return search(this, params);
4656
4837
  }
4838
+ async delegate(request) {
4839
+ return delegate(this, request);
4840
+ }
4657
4841
  async searchErc8004ByAgentId(params) {
4658
4842
  const chainId = Math.floor(params.chainId);
4659
4843
  if (!Number.isFinite(chainId) || chainId <= 0) {
@@ -5367,11 +5551,21 @@ var buildJobStatusMessage = (input) => JSON.stringify({
5367
5551
  buildPaymentApproveMessage,
5368
5552
  buildPaymentDeclineMessage,
5369
5553
  canonicalizeLedgerNetwork,
5554
+ closeUaidConnection,
5370
5555
  createPrivateKeySigner,
5371
5556
  createPrivateKeySignerAsync,
5557
+ dashboardStats,
5558
+ getRegistrationProgress,
5559
+ getRegistrationQuote,
5560
+ getUaidConnectionStatus,
5372
5561
  isHolChatOp,
5373
5562
  isPartialRegisterAgentResponse,
5374
5563
  isPendingRegisterAgentResponse,
5375
5564
  isSuccessRegisterAgentResponse,
5376
- parseHolChatOps
5565
+ parseHolChatOps,
5566
+ registerAgent,
5567
+ resolveUaid,
5568
+ updateAgent,
5569
+ validateUaid,
5570
+ waitForRegistrationCompletion
5377
5571
  });