@hol-org/rb-client 0.1.171 → 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 +197 -3
- package/dist/index.d.cts +17772 -60
- package/dist/index.d.ts +17772 -60
- package/dist/index.js +186 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -239,6 +239,13 @@ var metadataFacetSchema = z2.record(
|
|
|
239
239
|
jsonValueSchema
|
|
240
240
|
])
|
|
241
241
|
).optional();
|
|
242
|
+
var searchHitMetadataSchema = z2.object({
|
|
243
|
+
delegationRoles: jsonValueSchema.optional(),
|
|
244
|
+
delegationTaskTags: jsonValueSchema.optional(),
|
|
245
|
+
delegationProtocols: jsonValueSchema.optional(),
|
|
246
|
+
delegationSummary: jsonValueSchema.optional(),
|
|
247
|
+
delegationSignals: jsonValueSchema.optional()
|
|
248
|
+
}).passthrough();
|
|
242
249
|
var searchHitSchema = z2.object({
|
|
243
250
|
id: z2.string(),
|
|
244
251
|
uaid: z2.string(),
|
|
@@ -247,7 +254,7 @@ var searchHitSchema = z2.object({
|
|
|
247
254
|
description: z2.string().optional(),
|
|
248
255
|
capabilities: z2.array(capabilityValueSchema),
|
|
249
256
|
endpoints: z2.union([z2.record(jsonValueSchema), z2.array(z2.string())]).optional(),
|
|
250
|
-
metadata:
|
|
257
|
+
metadata: searchHitMetadataSchema.optional(),
|
|
251
258
|
metadataFacet: metadataFacetSchema,
|
|
252
259
|
profile: agentProfileSchema.optional(),
|
|
253
260
|
protocols: z2.array(z2.string()).optional(),
|
|
@@ -291,6 +298,62 @@ var popularResponseSchema = z2.object({
|
|
|
291
298
|
var resolveResponseSchema = z2.object({
|
|
292
299
|
agent: searchHitSchema
|
|
293
300
|
});
|
|
301
|
+
var delegationPlanCandidateSchema = z2.object({
|
|
302
|
+
uaid: z2.string(),
|
|
303
|
+
label: z2.string(),
|
|
304
|
+
registry: z2.string().optional(),
|
|
305
|
+
agent: searchHitSchema,
|
|
306
|
+
score: z2.number(),
|
|
307
|
+
matchedQueries: z2.array(z2.string()).optional(),
|
|
308
|
+
matchedRoles: z2.array(z2.string()).optional(),
|
|
309
|
+
matchedProtocols: z2.array(z2.string()).optional(),
|
|
310
|
+
matchedSurfaces: z2.array(z2.string()).optional(),
|
|
311
|
+
matchedLanguages: z2.array(z2.string()).optional(),
|
|
312
|
+
matchedArtifacts: z2.array(z2.string()).optional(),
|
|
313
|
+
matchedTaskTags: z2.array(z2.string()).optional(),
|
|
314
|
+
reasons: z2.array(z2.string()).optional(),
|
|
315
|
+
suggestedMessage: z2.string().optional(),
|
|
316
|
+
trustScore: z2.number().optional(),
|
|
317
|
+
verified: z2.boolean().optional(),
|
|
318
|
+
communicationSupported: z2.boolean().optional(),
|
|
319
|
+
availability: z2.boolean().optional(),
|
|
320
|
+
explanation: z2.string().optional()
|
|
321
|
+
}).passthrough();
|
|
322
|
+
var delegationOpportunitySchema = z2.object({
|
|
323
|
+
id: z2.string(),
|
|
324
|
+
title: z2.string(),
|
|
325
|
+
reason: z2.string(),
|
|
326
|
+
role: z2.string(),
|
|
327
|
+
type: z2.enum(["ai-agents", "mcp-servers"]),
|
|
328
|
+
suggestedMode: z2.enum(["best-match", "fallback", "parallel"]),
|
|
329
|
+
searchQueries: z2.array(z2.string()),
|
|
330
|
+
protocols: z2.array(z2.string()).optional(),
|
|
331
|
+
surfaces: z2.array(z2.string()).optional(),
|
|
332
|
+
languages: z2.array(z2.string()).optional(),
|
|
333
|
+
artifacts: z2.array(z2.string()).optional(),
|
|
334
|
+
candidates: z2.array(delegationPlanCandidateSchema)
|
|
335
|
+
}).passthrough();
|
|
336
|
+
var delegationRecommendationSchema = z2.object({
|
|
337
|
+
action: z2.enum(["delegate-now", "review-shortlist", "handle-locally"]),
|
|
338
|
+
confidence: z2.number(),
|
|
339
|
+
reason: z2.string(),
|
|
340
|
+
opportunityId: z2.string().optional(),
|
|
341
|
+
candidate: delegationPlanCandidateSchema.optional()
|
|
342
|
+
}).passthrough();
|
|
343
|
+
var delegationPlanResponseSchema = z2.object({
|
|
344
|
+
task: z2.string(),
|
|
345
|
+
context: z2.string().optional(),
|
|
346
|
+
summary: z2.string().optional(),
|
|
347
|
+
intents: z2.array(z2.string()),
|
|
348
|
+
protocols: z2.array(z2.string()),
|
|
349
|
+
surfaces: z2.array(z2.string()),
|
|
350
|
+
languages: z2.array(z2.string()).optional(),
|
|
351
|
+
artifacts: z2.array(z2.string()).optional(),
|
|
352
|
+
shouldDelegate: z2.boolean(),
|
|
353
|
+
localFirstReason: z2.string().optional(),
|
|
354
|
+
recommendation: delegationRecommendationSchema.optional(),
|
|
355
|
+
opportunities: z2.array(delegationOpportunitySchema)
|
|
356
|
+
}).passthrough();
|
|
294
357
|
var agentFeedbackSummarySchema = z2.object({
|
|
295
358
|
averageScore: z2.number(),
|
|
296
359
|
totalFeedbacks: z2.number(),
|
|
@@ -2070,6 +2133,18 @@ async function search(client, params = {}) {
|
|
|
2070
2133
|
});
|
|
2071
2134
|
return client.parseWithSchema(raw, searchResponseSchema, "search response");
|
|
2072
2135
|
}
|
|
2136
|
+
async function delegate(client, request) {
|
|
2137
|
+
const raw = await client.requestJson("/delegate", {
|
|
2138
|
+
method: "POST",
|
|
2139
|
+
body: request,
|
|
2140
|
+
headers: { "content-type": "application/json" }
|
|
2141
|
+
});
|
|
2142
|
+
return client.parseWithSchema(
|
|
2143
|
+
raw,
|
|
2144
|
+
delegationPlanResponseSchema,
|
|
2145
|
+
"delegate response"
|
|
2146
|
+
);
|
|
2147
|
+
}
|
|
2073
2148
|
async function stats(client) {
|
|
2074
2149
|
const raw = await client.requestJson("/stats", { method: "GET" });
|
|
2075
2150
|
return client.parseWithSchema(raw, statsResponseSchema, "stats response");
|
|
@@ -2450,6 +2525,81 @@ async function buyCreditsWithX402(client, params) {
|
|
|
2450
2525
|
}
|
|
2451
2526
|
|
|
2452
2527
|
// ../../src/services/registry-broker/client/agents.ts
|
|
2528
|
+
async function performRegisterAgent(client, payload) {
|
|
2529
|
+
const raw = await client.requestJson("/register", {
|
|
2530
|
+
method: "POST",
|
|
2531
|
+
body: serialiseAgentRegistrationRequest(payload),
|
|
2532
|
+
headers: { "content-type": "application/json" }
|
|
2533
|
+
});
|
|
2534
|
+
return client.parseWithSchema(
|
|
2535
|
+
raw,
|
|
2536
|
+
registerAgentResponseSchema,
|
|
2537
|
+
"register agent response"
|
|
2538
|
+
);
|
|
2539
|
+
}
|
|
2540
|
+
function calculateHbarAmount(creditsToPurchase, creditsPerHbar) {
|
|
2541
|
+
if (creditsPerHbar <= 0) {
|
|
2542
|
+
throw new Error("creditsPerHbar must be positive");
|
|
2543
|
+
}
|
|
2544
|
+
if (creditsToPurchase <= 0) {
|
|
2545
|
+
throw new Error("creditsToPurchase must be positive");
|
|
2546
|
+
}
|
|
2547
|
+
const rawHbar = creditsToPurchase / creditsPerHbar;
|
|
2548
|
+
const tinybars = Math.ceil(rawHbar * 1e8);
|
|
2549
|
+
return tinybars / 1e8;
|
|
2550
|
+
}
|
|
2551
|
+
function resolveCreditsToPurchase(shortfallCredits) {
|
|
2552
|
+
if (!Number.isFinite(shortfallCredits) || shortfallCredits <= 0) {
|
|
2553
|
+
return 0;
|
|
2554
|
+
}
|
|
2555
|
+
return Math.max(
|
|
2556
|
+
Math.ceil(shortfallCredits),
|
|
2557
|
+
MINIMUM_REGISTRATION_AUTO_TOP_UP_CREDITS
|
|
2558
|
+
);
|
|
2559
|
+
}
|
|
2560
|
+
async function ensureCreditsForRegistration(client, payload, autoTopUp) {
|
|
2561
|
+
const details = autoTopUp ?? null;
|
|
2562
|
+
if (!details) {
|
|
2563
|
+
return;
|
|
2564
|
+
}
|
|
2565
|
+
if (!details.accountId || !details.accountId.trim()) {
|
|
2566
|
+
throw new Error("autoTopUp.accountId is required");
|
|
2567
|
+
}
|
|
2568
|
+
if (!details.privateKey || !details.privateKey.trim()) {
|
|
2569
|
+
throw new Error("autoTopUp.privateKey is required");
|
|
2570
|
+
}
|
|
2571
|
+
for (let attempt = 0; attempt < 3; attempt += 1) {
|
|
2572
|
+
const quote = await getRegistrationQuote(client, payload);
|
|
2573
|
+
const shortfall = quote.shortfallCredits ?? 0;
|
|
2574
|
+
if (shortfall <= 0) {
|
|
2575
|
+
return;
|
|
2576
|
+
}
|
|
2577
|
+
const creditsToPurchase = resolveCreditsToPurchase(shortfall);
|
|
2578
|
+
if (creditsToPurchase <= 0) {
|
|
2579
|
+
return;
|
|
2580
|
+
}
|
|
2581
|
+
const creditsPerHbar = quote.creditsPerHbar ?? null;
|
|
2582
|
+
if (!creditsPerHbar || creditsPerHbar <= 0) {
|
|
2583
|
+
throw new Error("Unable to determine credits per HBAR for auto top-up");
|
|
2584
|
+
}
|
|
2585
|
+
const hbarAmount = calculateHbarAmount(creditsToPurchase, creditsPerHbar);
|
|
2586
|
+
await purchaseCreditsWithHbar(client, {
|
|
2587
|
+
accountId: details.accountId.trim(),
|
|
2588
|
+
privateKey: details.privateKey.trim(),
|
|
2589
|
+
hbarAmount,
|
|
2590
|
+
memo: details.memo ?? "Registry Broker auto top-up",
|
|
2591
|
+
metadata: {
|
|
2592
|
+
shortfallCredits: shortfall,
|
|
2593
|
+
requiredCredits: quote.requiredCredits,
|
|
2594
|
+
purchasedCredits: creditsToPurchase
|
|
2595
|
+
}
|
|
2596
|
+
});
|
|
2597
|
+
}
|
|
2598
|
+
const finalQuote = await getRegistrationQuote(client, payload);
|
|
2599
|
+
if ((finalQuote.shortfallCredits ?? 0) > 0) {
|
|
2600
|
+
throw new Error("Unable to purchase sufficient credits for registration");
|
|
2601
|
+
}
|
|
2602
|
+
}
|
|
2453
2603
|
async function resolveUaid(client, uaid) {
|
|
2454
2604
|
const raw = await client.requestJson(
|
|
2455
2605
|
`/resolve/${encodeURIComponent(uaid)}`,
|
|
@@ -2463,6 +2613,27 @@ async function resolveUaid(client, uaid) {
|
|
|
2463
2613
|
"resolve UAID response"
|
|
2464
2614
|
);
|
|
2465
2615
|
}
|
|
2616
|
+
async function registerAgent(client, payload, options) {
|
|
2617
|
+
const autoTopUp = options?.autoTopUp ?? client.registrationAutoTopUp;
|
|
2618
|
+
if (!autoTopUp) {
|
|
2619
|
+
return performRegisterAgent(client, payload);
|
|
2620
|
+
}
|
|
2621
|
+
await ensureCreditsForRegistration(client, payload, autoTopUp);
|
|
2622
|
+
let retried = false;
|
|
2623
|
+
while (true) {
|
|
2624
|
+
try {
|
|
2625
|
+
return await performRegisterAgent(client, payload);
|
|
2626
|
+
} catch (error) {
|
|
2627
|
+
const shortfall = client.extractInsufficientCreditsDetails(error);
|
|
2628
|
+
if (shortfall && !retried) {
|
|
2629
|
+
await ensureCreditsForRegistration(client, payload, autoTopUp);
|
|
2630
|
+
retried = true;
|
|
2631
|
+
continue;
|
|
2632
|
+
}
|
|
2633
|
+
throw error;
|
|
2634
|
+
}
|
|
2635
|
+
}
|
|
2636
|
+
}
|
|
2466
2637
|
async function getRegistrationQuote(client, payload) {
|
|
2467
2638
|
const raw = await client.requestJson("/register/quote", {
|
|
2468
2639
|
method: "POST",
|
|
@@ -4610,6 +4781,9 @@ var RegistryBrokerClient = class _RegistryBrokerClient {
|
|
|
4610
4781
|
async search(params = {}) {
|
|
4611
4782
|
return search(this, params);
|
|
4612
4783
|
}
|
|
4784
|
+
async delegate(request) {
|
|
4785
|
+
return delegate(this, request);
|
|
4786
|
+
}
|
|
4613
4787
|
async searchErc8004ByAgentId(params) {
|
|
4614
4788
|
const chainId = Math.floor(params.chainId);
|
|
4615
4789
|
if (!Number.isFinite(chainId) || chainId <= 0) {
|
|
@@ -5322,11 +5496,21 @@ export {
|
|
|
5322
5496
|
buildPaymentApproveMessage,
|
|
5323
5497
|
buildPaymentDeclineMessage,
|
|
5324
5498
|
canonicalizeLedgerNetwork,
|
|
5499
|
+
closeUaidConnection,
|
|
5325
5500
|
createPrivateKeySigner,
|
|
5326
5501
|
createPrivateKeySignerAsync,
|
|
5502
|
+
dashboardStats,
|
|
5503
|
+
getRegistrationProgress,
|
|
5504
|
+
getRegistrationQuote,
|
|
5505
|
+
getUaidConnectionStatus,
|
|
5327
5506
|
isHolChatOp,
|
|
5328
5507
|
isPartialRegisterAgentResponse,
|
|
5329
5508
|
isPendingRegisterAgentResponse,
|
|
5330
5509
|
isSuccessRegisterAgentResponse,
|
|
5331
|
-
parseHolChatOps
|
|
5510
|
+
parseHolChatOps,
|
|
5511
|
+
registerAgent,
|
|
5512
|
+
resolveUaid,
|
|
5513
|
+
updateAgent,
|
|
5514
|
+
validateUaid,
|
|
5515
|
+
waitForRegistrationCompletion
|
|
5332
5516
|
};
|