@hashgraphonline/standards-sdk 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.
Files changed (158) hide show
  1. package/dist/browser/services/registry-broker/client/base-client.d.ts +3 -2
  2. package/dist/browser/services/registry-broker/client/base-client.d.ts.map +1 -1
  3. package/dist/browser/services/registry-broker/client/search.d.ts +2 -1
  4. package/dist/browser/services/registry-broker/client/search.d.ts.map +1 -1
  5. package/dist/browser/services/registry-broker/client.d.ts +1 -0
  6. package/dist/browser/services/registry-broker/client.d.ts.map +1 -1
  7. package/dist/browser/services/registry-broker/schemas.d.ts +17723 -58
  8. package/dist/browser/services/registry-broker/schemas.d.ts.map +1 -1
  9. package/dist/browser/services/registry-broker/types.d.ts +36 -1
  10. package/dist/browser/services/registry-broker/types.d.ts.map +1 -1
  11. package/dist/browser/standards-sdk.browser.js +64 -1
  12. package/dist/browser/standards-sdk.browser.js.map +1 -1
  13. package/dist/cjs/services/registry-broker/client/base-client.d.ts +3 -2
  14. package/dist/cjs/services/registry-broker/client/base-client.d.ts.map +1 -1
  15. package/dist/cjs/services/registry-broker/client/search.d.ts +2 -1
  16. package/dist/cjs/services/registry-broker/client/search.d.ts.map +1 -1
  17. package/dist/cjs/services/registry-broker/client.d.ts +1 -0
  18. package/dist/cjs/services/registry-broker/client.d.ts.map +1 -1
  19. package/dist/cjs/services/registry-broker/schemas.d.ts +17814 -149
  20. package/dist/cjs/services/registry-broker/schemas.d.ts.map +1 -1
  21. package/dist/cjs/services/registry-broker/types.d.ts +36 -1
  22. package/dist/cjs/services/registry-broker/types.d.ts.map +1 -1
  23. package/dist/cjs/standards-sdk.cjs +3 -3
  24. package/dist/cjs/standards-sdk.cjs.map +1 -1
  25. package/dist/es/services/registry-broker/client/base-client.d.ts +3 -2
  26. package/dist/es/services/registry-broker/client/base-client.d.ts.map +1 -1
  27. package/dist/es/services/registry-broker/client/search.d.ts +2 -1
  28. package/dist/es/services/registry-broker/client/search.d.ts.map +1 -1
  29. package/dist/es/services/registry-broker/client.d.ts +1 -0
  30. package/dist/es/services/registry-broker/client.d.ts.map +1 -1
  31. package/dist/es/services/registry-broker/schemas.d.ts +17814 -149
  32. package/dist/es/services/registry-broker/schemas.d.ts.map +1 -1
  33. package/dist/es/services/registry-broker/types.d.ts +36 -1
  34. package/dist/es/services/registry-broker/types.d.ts.map +1 -1
  35. package/dist/es/standards-sdk.es.js +20 -9
  36. package/dist/es/standards-sdk.es.js.map +1 -1
  37. package/dist/es/standards-sdk.es104.js +1 -1
  38. package/dist/es/standards-sdk.es106.js +1 -1
  39. package/dist/es/standards-sdk.es108.js +1 -1
  40. package/dist/es/standards-sdk.es11.js +1 -1
  41. package/dist/es/standards-sdk.es110.js +1 -1
  42. package/dist/es/standards-sdk.es116.js +2 -2
  43. package/dist/es/standards-sdk.es12.js +1 -1
  44. package/dist/es/standards-sdk.es121.js +1 -1
  45. package/dist/es/standards-sdk.es127.js +1 -1
  46. package/dist/es/standards-sdk.es128.js +5 -5
  47. package/dist/es/standards-sdk.es138.js +1 -1
  48. package/dist/es/standards-sdk.es139.js +1 -1
  49. package/dist/es/standards-sdk.es140.js +5 -5
  50. package/dist/es/standards-sdk.es142.js +2 -2
  51. package/dist/es/standards-sdk.es143.js +1 -1
  52. package/dist/es/standards-sdk.es145.js +65 -1
  53. package/dist/es/standards-sdk.es145.js.map +1 -1
  54. package/dist/es/standards-sdk.es147.js +250 -78
  55. package/dist/es/standards-sdk.es147.js.map +1 -1
  56. package/dist/es/standards-sdk.es148.js +77 -71
  57. package/dist/es/standards-sdk.es148.js.map +1 -1
  58. package/dist/es/standards-sdk.es149.js +79 -936
  59. package/dist/es/standards-sdk.es149.js.map +1 -1
  60. package/dist/es/standards-sdk.es150.js +934 -53
  61. package/dist/es/standards-sdk.es150.js.map +1 -1
  62. package/dist/es/standards-sdk.es151.js +53 -152
  63. package/dist/es/standards-sdk.es151.js.map +1 -1
  64. package/dist/es/standards-sdk.es152.js +159 -7
  65. package/dist/es/standards-sdk.es152.js.map +1 -1
  66. package/dist/es/standards-sdk.es153.js +7 -86
  67. package/dist/es/standards-sdk.es153.js.map +1 -1
  68. package/dist/es/standards-sdk.es154.js +64 -43
  69. package/dist/es/standards-sdk.es154.js.map +1 -1
  70. package/dist/es/standards-sdk.es155.js +65 -30
  71. package/dist/es/standards-sdk.es155.js.map +1 -1
  72. package/dist/es/standards-sdk.es156.js +30 -34
  73. package/dist/es/standards-sdk.es156.js.map +1 -1
  74. package/dist/es/standards-sdk.es157.js +34 -48
  75. package/dist/es/standards-sdk.es157.js.map +1 -1
  76. package/dist/es/standards-sdk.es158.js +48 -138
  77. package/dist/es/standards-sdk.es158.js.map +1 -1
  78. package/dist/es/standards-sdk.es159.js +133 -37
  79. package/dist/es/standards-sdk.es159.js.map +1 -1
  80. package/dist/es/standards-sdk.es16.js +1 -1
  81. package/dist/es/standards-sdk.es160.js +34 -12474
  82. package/dist/es/standards-sdk.es160.js.map +1 -1
  83. package/dist/es/standards-sdk.es161.js +12413 -481
  84. package/dist/es/standards-sdk.es161.js.map +1 -1
  85. package/dist/es/standards-sdk.es162.js +51 -68
  86. package/dist/es/standards-sdk.es162.js.map +1 -1
  87. package/dist/es/standards-sdk.es163.js +76 -48
  88. package/dist/es/standards-sdk.es163.js.map +1 -1
  89. package/dist/es/standards-sdk.es164.js +66 -69
  90. package/dist/es/standards-sdk.es164.js.map +1 -1
  91. package/dist/es/standards-sdk.es165.js +180 -61
  92. package/dist/es/standards-sdk.es165.js.map +1 -1
  93. package/dist/es/standards-sdk.es166.js +14 -197
  94. package/dist/es/standards-sdk.es166.js.map +1 -1
  95. package/dist/es/standards-sdk.es167.js +71 -15
  96. package/dist/es/standards-sdk.es167.js.map +1 -1
  97. package/dist/es/standards-sdk.es168.js +538 -160
  98. package/dist/es/standards-sdk.es168.js.map +1 -1
  99. package/dist/es/standards-sdk.es169.js +139 -289
  100. package/dist/es/standards-sdk.es169.js.map +1 -1
  101. package/dist/es/standards-sdk.es170.js +274 -298
  102. package/dist/es/standards-sdk.es170.js.map +1 -1
  103. package/dist/es/standards-sdk.es171.js +262 -369
  104. package/dist/es/standards-sdk.es171.js.map +1 -1
  105. package/dist/es/standards-sdk.es172.js +316 -194
  106. package/dist/es/standards-sdk.es172.js.map +1 -1
  107. package/dist/es/standards-sdk.es173.js +319 -64
  108. package/dist/es/standards-sdk.es173.js.map +1 -1
  109. package/dist/es/standards-sdk.es174.js +61 -157
  110. package/dist/es/standards-sdk.es174.js.map +1 -1
  111. package/dist/es/standards-sdk.es175.js +152 -202
  112. package/dist/es/standards-sdk.es175.js.map +1 -1
  113. package/dist/es/standards-sdk.es176.js +219 -223
  114. package/dist/es/standards-sdk.es176.js.map +1 -1
  115. package/dist/es/standards-sdk.es177.js +227 -107
  116. package/dist/es/standards-sdk.es177.js.map +1 -1
  117. package/dist/es/standards-sdk.es178.js +98 -105
  118. package/dist/es/standards-sdk.es178.js.map +1 -1
  119. package/dist/es/standards-sdk.es179.js +105 -140
  120. package/dist/es/standards-sdk.es179.js.map +1 -1
  121. package/dist/es/standards-sdk.es18.js +4 -4
  122. package/dist/es/standards-sdk.es180.js +2 -2
  123. package/dist/es/standards-sdk.es182.js +1 -1
  124. package/dist/es/standards-sdk.es19.js +2 -2
  125. package/dist/es/standards-sdk.es22.js +1 -1
  126. package/dist/es/standards-sdk.es27.js +4 -4
  127. package/dist/es/standards-sdk.es30.js +1 -1
  128. package/dist/es/standards-sdk.es31.js +1 -1
  129. package/dist/es/standards-sdk.es35.js +2 -2
  130. package/dist/es/standards-sdk.es36.js +3 -3
  131. package/dist/es/standards-sdk.es37.js +1 -1
  132. package/dist/es/standards-sdk.es4.js +1 -1
  133. package/dist/es/standards-sdk.es53.js +1 -1
  134. package/dist/es/standards-sdk.es56.js +1 -1
  135. package/dist/es/standards-sdk.es59.js +1 -1
  136. package/dist/es/standards-sdk.es60.js +1 -1
  137. package/dist/es/standards-sdk.es62.js +1 -1
  138. package/dist/es/standards-sdk.es63.js +2 -2
  139. package/dist/es/standards-sdk.es64.js +1 -1
  140. package/dist/es/standards-sdk.es65.js +1 -1
  141. package/dist/es/standards-sdk.es66.js +1 -1
  142. package/dist/es/standards-sdk.es67.js +2 -2
  143. package/dist/es/standards-sdk.es69.js +1 -1
  144. package/dist/es/standards-sdk.es7.js +1 -1
  145. package/dist/es/standards-sdk.es71.js +1 -1
  146. package/dist/es/standards-sdk.es72.js +2 -2
  147. package/dist/es/standards-sdk.es75.js +3 -3
  148. package/dist/es/standards-sdk.es76.js +1 -1
  149. package/dist/es/standards-sdk.es78.js +1 -1
  150. package/dist/es/standards-sdk.es83.js +1 -1
  151. package/dist/es/standards-sdk.es84.js +1 -1
  152. package/dist/es/standards-sdk.es85.js +1 -1
  153. package/dist/es/standards-sdk.es88.js +1 -1
  154. package/dist/es/standards-sdk.es90.js +1 -1
  155. package/dist/es/standards-sdk.es94.js +3 -3
  156. package/dist/es/standards-sdk.es98.js +1 -1
  157. package/dist/es/standards-sdk.es99.js +1 -1
  158. package/package.json +1 -1
@@ -1,63 +1,944 @@
1
- const HOL_CHAT_PROTOCOL_ID = "hol-chat";
2
- const isRecord = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value);
3
- const isHolChatOp = (value) => {
4
- if (!isRecord(value)) {
5
- return false;
1
+ import { Buffer } from "buffer";
2
+ import { randomBytes, createHash, createCipheriv, createDecipheriv } from "crypto";
3
+ import { secp256k1 } from "@noble/curves/secp256k1.js";
4
+ import { ZodError } from "zod";
5
+ import { agentFeedbackResponseSchema, agentFeedbackIndexResponseSchema, agentFeedbackEntriesIndexResponseSchema, agentFeedbackEligibilityResponseSchema, agentFeedbackSubmissionResponseSchema, registerAgentResponseSchema } from "./standards-sdk.es145.js";
6
+ import { fetchHistorySnapshot, attachDecryptedHistory, registerConversationContextForEncryption, resolveDecryptionContext, decryptHistoryEntryFromContext } from "./standards-sdk.es181.js";
7
+ import { createChatApi, createSession, startChat, startConversation, acceptConversation, compactHistory, fetchEncryptionStatus, postEncryptionHandshake, sendMessage, endSession, createPlaintextConversationHandle } from "./standards-sdk.es182.js";
8
+ import { EncryptedChatManager } from "./standards-sdk.es183.js";
9
+ import { generateEncryptionKeyPair, bootstrapEncryptionOptions, createEncryptionApi } from "./standards-sdk.es175.js";
10
+ import { adapters, adaptersDetailed, adapterRegistryCategories, adapterRegistryAdapters, createAdapterRegistryCategory, submitAdapterRegistryAdapter, adapterRegistrySubmissionStatus } from "./standards-sdk.es178.js";
11
+ import { resolveUaid, getRegistrationQuote, updateAgent, getRegistrationProgress, waitForRegistrationCompletion, validateUaid, getUaidConnectionStatus, closeUaidConnection, dashboardStats } from "./standards-sdk.es147.js";
12
+ import { getRegisterStatus, registerOwnedMoltbookAgent, getVerificationStatus, createVerificationChallenge, getVerificationChallenge, verifyVerificationChallenge, getVerificationOwnership, verifySenderOwnership, verifyUaidDnsTxt, getVerificationDnsStatus } from "./standards-sdk.es184.js";
13
+ import { purchaseCreditsWithHbar, getX402Minimums, purchaseCreditsWithX402, buyCreditsWithX402 } from "./standards-sdk.es179.js";
14
+ import { createLedgerChallenge, verifyLedgerChallenge, authenticateWithLedger, authenticateWithLedgerCredentials } from "./standards-sdk.es180.js";
15
+ import { search, delegate, stats, registries, getAdditionalRegistries, popularSearches, listProtocols, detectProtocol, registrySearchByNamespace, vectorSearch, searchStatus, websocketStats, metricsSummary, facets } from "./standards-sdk.es176.js";
16
+ import { skillsConfig, listSkills, getSkillSecurityBreakdown, getSkillsCatalog, listSkillVersions, listMySkills, getMySkillsList, quoteSkillPublish, publishSkill, getSkillPublishJob, getSkillOwnership, getRecommendedSkillVersion, setRecommendedSkillVersion, getSkillDeprecations, setSkillDeprecation, getSkillBadge, listSkillTags, listSkillCategories, resolveSkillMarkdown, resolveSkillManifest, getSkillVoteStatus, setSkillVote, requestSkillVerification, getSkillVerificationStatus, createSkillDomainProofChallenge, verifySkillDomainProof } from "./standards-sdk.es168.js";
17
+ import { DEFAULT_BASE_URL, normaliseBaseUrl, normaliseHeaderName, isBrowserRuntime, DEFAULT_USER_AGENT, JSON_CONTENT_TYPE, serialiseAgentRegistrationRequest, MINIMUM_REGISTRATION_AUTO_TOP_UP_CREDITS, createAbortError, isJsonObject, DEFAULT_HISTORY_TOP_UP_HBAR } from "./standards-sdk.es177.js";
18
+ import { RegistryBrokerError, RegistryBrokerParseError } from "./standards-sdk.es146.js";
19
+ class RegistryBrokerClient {
20
+ constructor(options = {}) {
21
+ this.encryptionBootstrapPromise = null;
22
+ this.chatApi = null;
23
+ this.encryptedChatManager = null;
24
+ this.encryptionApi = null;
25
+ this.conversationContexts = /* @__PURE__ */ new Map();
26
+ const {
27
+ baseUrl = DEFAULT_BASE_URL,
28
+ fetchImplementation,
29
+ defaultHeaders,
30
+ apiKey,
31
+ accountId,
32
+ ledgerApiKey,
33
+ registrationAutoTopUp,
34
+ historyAutoTopUp,
35
+ encryption
36
+ } = options;
37
+ this.baseUrl = normaliseBaseUrl(baseUrl);
38
+ const resolvedFetch = fetchImplementation ?? (typeof globalThis.fetch === "function" ? globalThis.fetch : null);
39
+ if (!resolvedFetch) {
40
+ throw new Error(
41
+ "A fetch implementation is required for RegistryBrokerClient"
42
+ );
43
+ }
44
+ this.fetchImpl = resolvedFetch;
45
+ this.defaultHeaders = {
46
+ ...defaultHeaders ?? {}
47
+ };
48
+ Object.entries(this.defaultHeaders).forEach(([key, value]) => {
49
+ const headerName = normaliseHeaderName(key);
50
+ if (headerName !== key) {
51
+ delete this.defaultHeaders[key];
52
+ this.defaultHeaders[headerName] = value;
53
+ }
54
+ });
55
+ const existingLedgerHeader = this.defaultHeaders["x-ledger-api-key"]?.trim();
56
+ if (!this.defaultHeaders["x-api-key"] && existingLedgerHeader) {
57
+ this.defaultHeaders["x-api-key"] = existingLedgerHeader;
58
+ }
59
+ if (apiKey) {
60
+ this.defaultHeaders["x-api-key"] = apiKey;
61
+ }
62
+ if (typeof accountId === "string" && accountId.trim().length > 0) {
63
+ this.defaultHeaders["x-account-id"] = accountId.trim();
64
+ }
65
+ if (ledgerApiKey) {
66
+ if (!this.defaultHeaders["x-api-key"]) {
67
+ this.defaultHeaders["x-api-key"] = ledgerApiKey;
68
+ }
69
+ }
70
+ this.registrationAutoTopUp = registrationAutoTopUp;
71
+ this.historyAutoTopUp = historyAutoTopUp;
72
+ this.encryptionOptions = encryption;
73
+ if (this.encryptionOptions) {
74
+ this.encryptionBootstrapPromise = this.initializeEncryptionBootstrap(
75
+ this.encryptionOptions
76
+ );
77
+ }
6
78
  }
7
- if (value.p !== HOL_CHAT_PROTOCOL_ID) {
8
- return false;
79
+ static async initializeAgent(options) {
80
+ const { uaid, ensureEncryptionKey = true, ...clientOptions } = options;
81
+ const client = new RegistryBrokerClient(clientOptions);
82
+ let encryption = null;
83
+ if (ensureEncryptionKey) {
84
+ const ensureOptions = typeof ensureEncryptionKey === "object" ? ensureEncryptionKey : { generateIfMissing: true };
85
+ encryption = await client.encryption.ensureAgentKey({
86
+ uaid,
87
+ ...ensureOptions
88
+ });
89
+ }
90
+ return { client, encryption };
91
+ }
92
+ get chat() {
93
+ if (this.chatApi) {
94
+ return this.chatApi;
95
+ }
96
+ const api = createChatApi(this, this.getEncryptedChatManager());
97
+ this.chatApi = api;
98
+ return api;
9
99
  }
10
- if (typeof value.request_id !== "string" || value.request_id.trim().length === 0) {
11
- return false;
100
+ get encryption() {
101
+ if (this.encryptionApi) {
102
+ return this.encryptionApi;
103
+ }
104
+ const api = createEncryptionApi(this);
105
+ this.encryptionApi = api;
106
+ return api;
12
107
  }
13
- const op = value.op;
14
- if (op !== "payment_request" && op !== "payment_approve" && op !== "payment_decline" && op !== "payment_result" && op !== "job_status") {
15
- return false;
108
+ setApiKey(apiKey) {
109
+ this.setDefaultHeader("x-api-key", apiKey);
16
110
  }
17
- return true;
18
- };
19
- const parseHolChatOps = (ops) => {
20
- if (!Array.isArray(ops)) {
21
- return [];
22
- }
23
- return ops.filter(isHolChatOp).map((op) => {
24
- const next = {
25
- p: HOL_CHAT_PROTOCOL_ID,
26
- op: op.op,
27
- request_id: op.request_id.trim()
111
+ setLedgerApiKey(apiKey) {
112
+ this.setDefaultHeader("x-api-key", apiKey);
113
+ delete this.defaultHeaders["x-ledger-api-key"];
114
+ }
115
+ setDefaultHeader(name, value) {
116
+ if (!name || name.trim().length === 0) {
117
+ return;
118
+ }
119
+ const headerName = normaliseHeaderName(name);
120
+ if (!value || value.trim().length === 0) {
121
+ delete this.defaultHeaders[headerName];
122
+ return;
123
+ }
124
+ this.defaultHeaders[headerName] = value.trim();
125
+ }
126
+ getDefaultHeaders() {
127
+ return { ...this.defaultHeaders };
128
+ }
129
+ async encryptionReady() {
130
+ if (!this.encryptionBootstrapPromise) {
131
+ return;
132
+ }
133
+ await this.encryptionBootstrapPromise;
134
+ }
135
+ buildUrl(path) {
136
+ const normalisedPath = path.startsWith("/") ? path : `/${path}`;
137
+ return `${this.baseUrl}${normalisedPath}`;
138
+ }
139
+ async request(path, config) {
140
+ const headers = new Headers();
141
+ Object.entries(this.defaultHeaders).forEach(([key, value]) => {
142
+ headers.set(key, value);
143
+ });
144
+ if (config.headers) {
145
+ Object.entries(config.headers).forEach(([key, value]) => {
146
+ headers.set(key, value);
147
+ });
148
+ }
149
+ if (!headers.has("accept")) {
150
+ headers.set("accept", "application/json");
151
+ }
152
+ if (!headers.has("user-agent") && !isBrowserRuntime()) {
153
+ headers.set("user-agent", DEFAULT_USER_AGENT);
154
+ }
155
+ const init = {
156
+ method: config.method ?? "GET",
157
+ headers
28
158
  };
29
- if (typeof op.m === "string" && op.m.trim().length > 0) {
30
- next.m = op.m.trim();
159
+ if (config.body !== void 0) {
160
+ init.body = JSON.stringify(config.body);
161
+ if (!headers.has("content-type")) {
162
+ headers.set("content-type", "application/json");
163
+ }
31
164
  }
32
- if (isRecord(op.data)) {
33
- next.data = { ...op.data };
165
+ const response = await this.fetchImpl(this.buildUrl(path), init);
166
+ if (response.ok) {
167
+ return response;
34
168
  }
35
- return next;
36
- });
37
- };
38
- const buildPaymentApproveMessage = (input) => JSON.stringify({
39
- p: HOL_CHAT_PROTOCOL_ID,
40
- op: "payment_approve",
41
- request_id: input.requestId,
42
- data: { job_id: input.jobId }
43
- });
44
- const buildPaymentDeclineMessage = (input) => JSON.stringify({
45
- p: HOL_CHAT_PROTOCOL_ID,
46
- op: "payment_decline",
47
- request_id: input.requestId
48
- });
49
- const buildJobStatusMessage = (input) => JSON.stringify({
50
- p: HOL_CHAT_PROTOCOL_ID,
51
- op: "job_status",
52
- request_id: input.requestId,
53
- data: { job_id: input.jobId }
54
- });
169
+ const errorBody = await this.extractErrorBody(response);
170
+ throw new RegistryBrokerError("Registry broker request failed", {
171
+ status: response.status,
172
+ statusText: response.statusText,
173
+ body: errorBody
174
+ });
175
+ }
176
+ async requestJson(path, config) {
177
+ const response = await this.request(path, config);
178
+ const contentType = response.headers?.get("content-type") ?? "";
179
+ if (!JSON_CONTENT_TYPE.test(contentType)) {
180
+ const body = await response.text();
181
+ throw new RegistryBrokerParseError(
182
+ "Expected JSON response from registry broker",
183
+ body
184
+ );
185
+ }
186
+ return await response.json();
187
+ }
188
+ async getAgentFeedback(uaid, options = {}) {
189
+ const normalized = uaid.trim();
190
+ if (!normalized) {
191
+ throw new Error("uaid is required");
192
+ }
193
+ const query = options.includeRevoked === true ? "?includeRevoked=true" : "";
194
+ const raw = await this.requestJson(
195
+ `/agents/${encodeURIComponent(normalized)}/feedback${query}`,
196
+ { method: "GET" }
197
+ );
198
+ return this.parseWithSchema(
199
+ raw,
200
+ agentFeedbackResponseSchema,
201
+ "agent feedback response"
202
+ );
203
+ }
204
+ async listAgentFeedbackIndex(options = {}) {
205
+ const params = new URLSearchParams();
206
+ if (typeof options.page === "number" && Number.isFinite(options.page)) {
207
+ params.set("page", String(Math.trunc(options.page)));
208
+ }
209
+ if (typeof options.limit === "number" && Number.isFinite(options.limit)) {
210
+ params.set("limit", String(Math.trunc(options.limit)));
211
+ }
212
+ if (options.registries?.length) {
213
+ params.set("registry", options.registries.join(","));
214
+ }
215
+ const suffix = params.size > 0 ? `?${params.toString()}` : "";
216
+ const raw = await this.requestJson(`/agents/feedback${suffix}`, {
217
+ method: "GET"
218
+ });
219
+ return this.parseWithSchema(
220
+ raw,
221
+ agentFeedbackIndexResponseSchema,
222
+ "agent feedback index response"
223
+ );
224
+ }
225
+ async listAgentFeedbackEntriesIndex(options = {}) {
226
+ const params = new URLSearchParams();
227
+ if (typeof options.page === "number" && Number.isFinite(options.page)) {
228
+ params.set("page", String(Math.trunc(options.page)));
229
+ }
230
+ if (typeof options.limit === "number" && Number.isFinite(options.limit)) {
231
+ params.set("limit", String(Math.trunc(options.limit)));
232
+ }
233
+ if (options.registries?.length) {
234
+ params.set("registry", options.registries.join(","));
235
+ }
236
+ const suffix = params.size > 0 ? `?${params.toString()}` : "";
237
+ const raw = await this.requestJson(
238
+ `/agents/feedback/entries${suffix}`,
239
+ { method: "GET" }
240
+ );
241
+ return this.parseWithSchema(
242
+ raw,
243
+ agentFeedbackEntriesIndexResponseSchema,
244
+ "agent feedback entries index response"
245
+ );
246
+ }
247
+ async checkAgentFeedbackEligibility(uaid, payload) {
248
+ const normalized = uaid.trim();
249
+ if (!normalized) {
250
+ throw new Error("uaid is required");
251
+ }
252
+ const raw = await this.requestJson(
253
+ `/agents/${encodeURIComponent(normalized)}/feedback/eligibility`,
254
+ {
255
+ method: "POST",
256
+ body: payload,
257
+ headers: { "content-type": "application/json" }
258
+ }
259
+ );
260
+ return this.parseWithSchema(
261
+ raw,
262
+ agentFeedbackEligibilityResponseSchema,
263
+ "agent feedback eligibility response"
264
+ );
265
+ }
266
+ async submitAgentFeedback(uaid, payload) {
267
+ const normalized = uaid.trim();
268
+ if (!normalized) {
269
+ throw new Error("uaid is required");
270
+ }
271
+ const raw = await this.requestJson(
272
+ `/agents/${encodeURIComponent(normalized)}/feedback`,
273
+ {
274
+ method: "POST",
275
+ body: payload,
276
+ headers: { "content-type": "application/json" }
277
+ }
278
+ );
279
+ return this.parseWithSchema(
280
+ raw,
281
+ agentFeedbackSubmissionResponseSchema,
282
+ "agent feedback submission response"
283
+ );
284
+ }
285
+ async search(params = {}) {
286
+ return search(this, params);
287
+ }
288
+ async delegate(request) {
289
+ return delegate(this, request);
290
+ }
291
+ async searchErc8004ByAgentId(params) {
292
+ const chainId = Math.floor(params.chainId);
293
+ if (!Number.isFinite(chainId) || chainId <= 0) {
294
+ throw new Error("chainId must be a positive integer");
295
+ }
296
+ const rawAgentId = typeof params.agentId === "bigint" ? params.agentId.toString() : String(params.agentId);
297
+ const agentId = rawAgentId.trim();
298
+ if (!agentId) {
299
+ throw new Error("agentId is required");
300
+ }
301
+ const nativeId = `${chainId}:${agentId}`;
302
+ return search(this, {
303
+ registries: ["erc-8004"],
304
+ limit: params.limit ?? 1,
305
+ ...typeof params.page === "number" ? { page: params.page } : {},
306
+ ...typeof params.sortBy === "string" ? { sortBy: params.sortBy } : {},
307
+ ...typeof params.sortOrder === "string" ? { sortOrder: params.sortOrder } : {},
308
+ metadata: {
309
+ nativeId: [nativeId],
310
+ networkKey: [`eip155:${chainId}`]
311
+ }
312
+ });
313
+ }
314
+ async stats() {
315
+ return stats(this);
316
+ }
317
+ async registries() {
318
+ return registries(this);
319
+ }
320
+ async getAdditionalRegistries() {
321
+ return getAdditionalRegistries(this);
322
+ }
323
+ async popularSearches() {
324
+ return popularSearches(this);
325
+ }
326
+ async listProtocols() {
327
+ return listProtocols(this);
328
+ }
329
+ async detectProtocol(message) {
330
+ return detectProtocol(this, message);
331
+ }
332
+ async registrySearchByNamespace(registry, query) {
333
+ return registrySearchByNamespace(this, registry, query);
334
+ }
335
+ async vectorSearch(request) {
336
+ return vectorSearch(this, request);
337
+ }
338
+ async searchStatus() {
339
+ return searchStatus(this);
340
+ }
341
+ async websocketStats() {
342
+ return websocketStats(this);
343
+ }
344
+ async metricsSummary() {
345
+ return metricsSummary(this);
346
+ }
347
+ async facets(adapter) {
348
+ return facets(this, adapter);
349
+ }
350
+ async adapters() {
351
+ return adapters(this);
352
+ }
353
+ async skillsConfig() {
354
+ return skillsConfig(this);
355
+ }
356
+ async listSkills(options) {
357
+ return listSkills(this, options);
358
+ }
359
+ async getSkillSecurityBreakdown(params) {
360
+ return getSkillSecurityBreakdown(this, params);
361
+ }
362
+ async getSkillsCatalog(options) {
363
+ return getSkillsCatalog(this, options);
364
+ }
365
+ async listSkillVersions(params) {
366
+ return listSkillVersions(this, params);
367
+ }
368
+ async listMySkills(params) {
369
+ return listMySkills(this, params);
370
+ }
371
+ async getMySkillsList(params) {
372
+ return getMySkillsList(this, params);
373
+ }
374
+ async quoteSkillPublish(payload) {
375
+ return quoteSkillPublish(this, payload);
376
+ }
377
+ async publishSkill(payload) {
378
+ return publishSkill(this, payload);
379
+ }
380
+ async getSkillPublishJob(jobId, params) {
381
+ return getSkillPublishJob(this, jobId, params);
382
+ }
383
+ async getSkillOwnership(params) {
384
+ return getSkillOwnership(this, params);
385
+ }
386
+ async getRecommendedSkillVersion(params) {
387
+ return getRecommendedSkillVersion(this, params);
388
+ }
389
+ async setRecommendedSkillVersion(payload) {
390
+ return setRecommendedSkillVersion(this, payload);
391
+ }
392
+ async getSkillDeprecations(params) {
393
+ return getSkillDeprecations(this, params);
394
+ }
395
+ async setSkillDeprecation(payload) {
396
+ return setSkillDeprecation(this, payload);
397
+ }
398
+ async getSkillBadge(params) {
399
+ return getSkillBadge(this, params);
400
+ }
401
+ async listSkillTags() {
402
+ return listSkillTags(this);
403
+ }
404
+ async listSkillCategories() {
405
+ return listSkillCategories(this);
406
+ }
407
+ async resolveSkillMarkdown(skillRef) {
408
+ return resolveSkillMarkdown(this, skillRef);
409
+ }
410
+ async resolveSkillManifest(skillRef) {
411
+ return resolveSkillManifest(this, skillRef);
412
+ }
413
+ async getSkillVoteStatus(params) {
414
+ return getSkillVoteStatus(this, params);
415
+ }
416
+ async setSkillVote(payload) {
417
+ return setSkillVote(this, payload);
418
+ }
419
+ async requestSkillVerification(payload) {
420
+ return requestSkillVerification(this, payload);
421
+ }
422
+ async getSkillVerificationStatus(params) {
423
+ return getSkillVerificationStatus(this, params);
424
+ }
425
+ async createSkillDomainProofChallenge(payload) {
426
+ return createSkillDomainProofChallenge(this, payload);
427
+ }
428
+ async verifySkillDomainProof(payload) {
429
+ return verifySkillDomainProof(this, payload);
430
+ }
431
+ async adaptersDetailed() {
432
+ return adaptersDetailed(this);
433
+ }
434
+ async adapterRegistryCategories() {
435
+ return adapterRegistryCategories(this);
436
+ }
437
+ async adapterRegistryAdapters(filters) {
438
+ return adapterRegistryAdapters(this, filters);
439
+ }
440
+ async createAdapterRegistryCategory(payload) {
441
+ return createAdapterRegistryCategory(this, payload);
442
+ }
443
+ async submitAdapterRegistryAdapter(payload) {
444
+ return submitAdapterRegistryAdapter(this, payload);
445
+ }
446
+ async adapterRegistrySubmissionStatus(submissionId) {
447
+ return adapterRegistrySubmissionStatus(this, submissionId);
448
+ }
449
+ async resolveUaid(uaid) {
450
+ return resolveUaid(this, uaid);
451
+ }
452
+ async performRegisterAgent(payload) {
453
+ const raw = await this.requestJson("/register", {
454
+ method: "POST",
455
+ body: serialiseAgentRegistrationRequest(payload),
456
+ headers: { "content-type": "application/json" }
457
+ });
458
+ return this.parseWithSchema(
459
+ raw,
460
+ registerAgentResponseSchema,
461
+ "register agent response"
462
+ );
463
+ }
464
+ calculateHbarAmount(creditsToPurchase, creditsPerHbar) {
465
+ if (creditsPerHbar <= 0) {
466
+ throw new Error("creditsPerHbar must be positive");
467
+ }
468
+ if (creditsToPurchase <= 0) {
469
+ throw new Error("creditsToPurchase must be positive");
470
+ }
471
+ const rawHbar = creditsToPurchase / creditsPerHbar;
472
+ const tinybars = Math.ceil(rawHbar * 1e8);
473
+ return tinybars / 1e8;
474
+ }
475
+ resolveCreditsToPurchase(shortfallCredits) {
476
+ if (!Number.isFinite(shortfallCredits) || shortfallCredits <= 0) {
477
+ return 0;
478
+ }
479
+ return Math.max(
480
+ Math.ceil(shortfallCredits),
481
+ MINIMUM_REGISTRATION_AUTO_TOP_UP_CREDITS
482
+ );
483
+ }
484
+ async ensureCreditsForRegistration(payload, autoTopUp) {
485
+ const details = autoTopUp ?? null;
486
+ if (!details) {
487
+ return;
488
+ }
489
+ if (!details.accountId || !details.accountId.trim()) {
490
+ throw new Error("autoTopUp.accountId is required");
491
+ }
492
+ if (!details.privateKey || !details.privateKey.trim()) {
493
+ throw new Error("autoTopUp.privateKey is required");
494
+ }
495
+ for (let attempt = 0; attempt < 3; attempt += 1) {
496
+ const quote = await this.getRegistrationQuote(payload);
497
+ const shortfall = quote.shortfallCredits ?? 0;
498
+ if (shortfall <= 0) {
499
+ return;
500
+ }
501
+ const creditsToPurchase = this.resolveCreditsToPurchase(shortfall);
502
+ if (creditsToPurchase <= 0) {
503
+ return;
504
+ }
505
+ const creditsPerHbar = quote.creditsPerHbar ?? null;
506
+ if (!creditsPerHbar || creditsPerHbar <= 0) {
507
+ throw new Error("Unable to determine credits per HBAR for auto top-up");
508
+ }
509
+ const hbarAmount = this.calculateHbarAmount(
510
+ creditsToPurchase,
511
+ creditsPerHbar
512
+ );
513
+ await this.purchaseCreditsWithHbar({
514
+ accountId: details.accountId.trim(),
515
+ privateKey: details.privateKey.trim(),
516
+ hbarAmount,
517
+ memo: details.memo ?? "Registry Broker auto top-up",
518
+ metadata: {
519
+ shortfallCredits: shortfall,
520
+ requiredCredits: quote.requiredCredits,
521
+ purchasedCredits: creditsToPurchase
522
+ }
523
+ });
524
+ }
525
+ const finalQuote = await this.getRegistrationQuote(payload);
526
+ if ((finalQuote.shortfallCredits ?? 0) > 0) {
527
+ throw new Error("Unable to purchase sufficient credits for registration");
528
+ }
529
+ }
530
+ async registerAgent(payload, options) {
531
+ const autoTopUp = options?.autoTopUp ?? this.registrationAutoTopUp;
532
+ if (!autoTopUp) {
533
+ return this.performRegisterAgent(payload);
534
+ }
535
+ await this.ensureCreditsForRegistration(payload, autoTopUp);
536
+ let retried = false;
537
+ while (true) {
538
+ try {
539
+ return await this.performRegisterAgent(payload);
540
+ } catch (error) {
541
+ const shortfall = this.extractInsufficientCreditsDetails(error);
542
+ if (shortfall && !retried) {
543
+ await this.ensureCreditsForRegistration(payload, autoTopUp);
544
+ retried = true;
545
+ continue;
546
+ }
547
+ throw error;
548
+ }
549
+ }
550
+ }
551
+ async getRegistrationQuote(payload) {
552
+ return getRegistrationQuote(this, payload);
553
+ }
554
+ async updateAgent(uaid, payload) {
555
+ return updateAgent(this, uaid, payload);
556
+ }
557
+ async getRegisterStatus(uaid) {
558
+ return getRegisterStatus(this, uaid);
559
+ }
560
+ async registerOwnedMoltbookAgent(uaid, payload) {
561
+ return registerOwnedMoltbookAgent(this, uaid, payload);
562
+ }
563
+ async getRegistrationProgress(attemptId) {
564
+ return getRegistrationProgress(this, attemptId);
565
+ }
566
+ async waitForRegistrationCompletion(attemptId, options) {
567
+ return waitForRegistrationCompletion(this, attemptId, options);
568
+ }
569
+ async validateUaid(uaid) {
570
+ return validateUaid(this, uaid);
571
+ }
572
+ async getUaidConnectionStatus(uaid) {
573
+ return getUaidConnectionStatus(this, uaid);
574
+ }
575
+ async closeUaidConnection(uaid) {
576
+ return closeUaidConnection(this, uaid);
577
+ }
578
+ async dashboardStats() {
579
+ return dashboardStats(this);
580
+ }
581
+ async purchaseCreditsWithHbar(params) {
582
+ return purchaseCreditsWithHbar(this, params);
583
+ }
584
+ async getX402Minimums() {
585
+ return getX402Minimums(this);
586
+ }
587
+ async purchaseCreditsWithX402(params) {
588
+ return purchaseCreditsWithX402(this, params);
589
+ }
590
+ async buyCreditsWithX402(params) {
591
+ return buyCreditsWithX402(this, params);
592
+ }
593
+ async generateEncryptionKeyPair(options = {}) {
594
+ return generateEncryptionKeyPair(this, options);
595
+ }
596
+ async createLedgerChallenge(payload) {
597
+ return createLedgerChallenge(this, payload);
598
+ }
599
+ async verifyLedgerChallenge(payload) {
600
+ return verifyLedgerChallenge(this, payload);
601
+ }
602
+ async authenticateWithLedger(options) {
603
+ return authenticateWithLedger(this, options);
604
+ }
605
+ async authenticateWithLedgerCredentials(options) {
606
+ return authenticateWithLedgerCredentials(this, options);
607
+ }
608
+ async getVerificationStatus(uaid) {
609
+ return getVerificationStatus(this, uaid);
610
+ }
611
+ async createVerificationChallenge(uaid) {
612
+ return createVerificationChallenge(this, uaid);
613
+ }
614
+ async getVerificationChallenge(challengeId) {
615
+ return getVerificationChallenge(this, challengeId);
616
+ }
617
+ async verifyVerificationChallenge(params) {
618
+ return verifyVerificationChallenge(this, params);
619
+ }
620
+ async getVerificationOwnership(uaid) {
621
+ return getVerificationOwnership(this, uaid);
622
+ }
623
+ async verifySenderOwnership(uaid) {
624
+ return verifySenderOwnership(this, uaid);
625
+ }
626
+ async verifyUaidDnsTxt(payload) {
627
+ return verifyUaidDnsTxt(this, payload);
628
+ }
629
+ async getVerificationDnsStatus(uaid, query) {
630
+ return getVerificationDnsStatus(this, uaid, query);
631
+ }
632
+ async fetchHistorySnapshot(sessionId, options) {
633
+ return fetchHistorySnapshot(
634
+ this.conversationContexts,
635
+ this,
636
+ sessionId,
637
+ options
638
+ );
639
+ }
640
+ attachDecryptedHistory(sessionId, snapshot, options) {
641
+ return attachDecryptedHistory(
642
+ this.conversationContexts,
643
+ this,
644
+ sessionId,
645
+ snapshot,
646
+ options
647
+ );
648
+ }
649
+ registerConversationContextForEncryption(context) {
650
+ registerConversationContextForEncryption(
651
+ this.conversationContexts,
652
+ context
653
+ );
654
+ }
655
+ resolveDecryptionContext(sessionId, options) {
656
+ return resolveDecryptionContext(
657
+ this.conversationContexts,
658
+ this,
659
+ sessionId,
660
+ options
661
+ );
662
+ }
663
+ decryptHistoryEntryFromContext(_sessionId, entry, context) {
664
+ return decryptHistoryEntryFromContext(this, entry, context);
665
+ }
666
+ async createSession(payload, allowHistoryAutoTopUp = true) {
667
+ return createSession(this, payload, allowHistoryAutoTopUp);
668
+ }
669
+ async startChat(options) {
670
+ return startChat(this, this.getEncryptedChatManager(), options);
671
+ }
672
+ async startConversation(options) {
673
+ return startConversation(this, this.getEncryptedChatManager(), options);
674
+ }
675
+ async acceptConversation(options) {
676
+ return acceptConversation(
677
+ this,
678
+ this.getEncryptedChatManager(),
679
+ options
680
+ );
681
+ }
682
+ compactHistory(payload) {
683
+ return compactHistory(this, payload);
684
+ }
685
+ fetchEncryptionStatus(sessionId) {
686
+ return fetchEncryptionStatus(this, sessionId);
687
+ }
688
+ postEncryptionHandshake(sessionId, payload) {
689
+ return postEncryptionHandshake(this, sessionId, payload);
690
+ }
691
+ sendMessage(payload) {
692
+ return sendMessage(this, payload);
693
+ }
694
+ endSession(sessionId) {
695
+ return endSession(this, sessionId);
696
+ }
697
+ createPlaintextConversationHandle(sessionId, summary, defaultAuth, context) {
698
+ return createPlaintextConversationHandle(
699
+ this,
700
+ sessionId,
701
+ summary,
702
+ defaultAuth,
703
+ context
704
+ );
705
+ }
706
+ getEncryptedChatManager() {
707
+ if (this.encryptedChatManager) {
708
+ return this.encryptedChatManager;
709
+ }
710
+ const manager = new EncryptedChatManager(this);
711
+ this.encryptedChatManager = manager;
712
+ return manager;
713
+ }
714
+ async extractErrorBody(response) {
715
+ const contentType = response.headers?.get("content-type") ?? "";
716
+ if (JSON_CONTENT_TYPE.test(contentType)) {
717
+ try {
718
+ return await response.json();
719
+ } catch (error) {
720
+ return { parseError: String(error) };
721
+ }
722
+ }
723
+ try {
724
+ return await response.text();
725
+ } catch (error) {
726
+ return { parseError: String(error) };
727
+ }
728
+ }
729
+ parseWithSchema(value, schema, context) {
730
+ try {
731
+ return schema.parse(value);
732
+ } catch (error) {
733
+ throw new RegistryBrokerParseError(
734
+ `Failed to parse ${context}`,
735
+ error instanceof ZodError || error instanceof Error ? error : String(error),
736
+ value
737
+ );
738
+ }
739
+ }
740
+ async delay(ms, signal) {
741
+ if (ms <= 0) {
742
+ if (signal?.aborted) {
743
+ throw createAbortError();
744
+ }
745
+ return;
746
+ }
747
+ await new Promise((resolve, reject) => {
748
+ const timer = setTimeout(() => {
749
+ if (signal) {
750
+ signal.removeEventListener("abort", onAbort);
751
+ }
752
+ resolve();
753
+ }, ms);
754
+ const onAbort = () => {
755
+ clearTimeout(timer);
756
+ signal?.removeEventListener("abort", onAbort);
757
+ reject(createAbortError());
758
+ };
759
+ if (signal) {
760
+ if (signal.aborted) {
761
+ clearTimeout(timer);
762
+ reject(createAbortError());
763
+ return;
764
+ }
765
+ signal.addEventListener("abort", onAbort, { once: true });
766
+ }
767
+ });
768
+ }
769
+ assertNodeRuntime(feature) {
770
+ if (typeof process === "undefined" || !process.versions?.node) {
771
+ throw new Error(`${feature} is only available in Node.js environments`);
772
+ }
773
+ }
774
+ createEphemeralKeyPair() {
775
+ this.assertNodeRuntime("generateEphemeralKeyPair");
776
+ const privateKeyBytes = randomBytes(32);
777
+ const publicKey = secp256k1.getPublicKey(privateKeyBytes, true);
778
+ return {
779
+ privateKey: Buffer.from(privateKeyBytes).toString("hex"),
780
+ publicKey: Buffer.from(publicKey).toString("hex")
781
+ };
782
+ }
783
+ deriveSharedSecret(options) {
784
+ this.assertNodeRuntime("deriveSharedSecret");
785
+ const privateKey = this.hexToBuffer(options.privateKey);
786
+ const peerPublicKey = this.hexToBuffer(options.peerPublicKey);
787
+ const shared = secp256k1.getSharedSecret(privateKey, peerPublicKey, true);
788
+ return createHash("sha256").update(Buffer.from(shared)).digest();
789
+ }
790
+ buildCipherEnvelope(options) {
791
+ this.assertNodeRuntime("encryptCipherEnvelope");
792
+ const sharedSecret = this.normalizeSharedSecret(options.sharedSecret);
793
+ const iv = randomBytes(12);
794
+ const cipher = createCipheriv("aes-256-gcm", sharedSecret, iv);
795
+ const aadSource = options.associatedData ?? options.sessionId;
796
+ const associatedDataEncoded = aadSource ? Buffer.from(aadSource, "utf8").toString("base64") : void 0;
797
+ if (aadSource) {
798
+ cipher.setAAD(Buffer.from(aadSource, "utf8"));
799
+ }
800
+ const ciphertext = Buffer.concat([
801
+ cipher.update(Buffer.from(options.plaintext, "utf8")),
802
+ cipher.final()
803
+ ]);
804
+ const tag = cipher.getAuthTag();
805
+ const payload = Buffer.concat([ciphertext, tag]);
806
+ return {
807
+ algorithm: "aes-256-gcm",
808
+ ciphertext: payload.toString("base64"),
809
+ nonce: iv.toString("base64"),
810
+ associatedData: associatedDataEncoded,
811
+ keyLocator: {
812
+ sessionId: options.sessionId,
813
+ revision: options.revision ?? 1
814
+ },
815
+ recipients: options.recipients.map((recipient) => ({
816
+ ...recipient,
817
+ encryptedShare: ""
818
+ }))
819
+ };
820
+ }
821
+ openCipherEnvelope(options) {
822
+ this.assertNodeRuntime("decryptCipherEnvelope");
823
+ const sharedSecret = this.normalizeSharedSecret(options.sharedSecret);
824
+ const payload = Buffer.from(options.envelope.ciphertext, "base64");
825
+ const nonce = Buffer.from(options.envelope.nonce, "base64");
826
+ const ciphertext = payload.slice(0, payload.length - 16);
827
+ const tag = payload.slice(payload.length - 16);
828
+ const decipher = createDecipheriv("aes-256-gcm", sharedSecret, nonce);
829
+ if (options.envelope.associatedData) {
830
+ decipher.setAAD(Buffer.from(options.envelope.associatedData, "base64"));
831
+ }
832
+ decipher.setAuthTag(tag);
833
+ const plaintext = Buffer.concat([
834
+ decipher.update(ciphertext),
835
+ decipher.final()
836
+ ]);
837
+ return plaintext.toString(options.encoding ?? "utf8");
838
+ }
839
+ normalizeSharedSecret(input) {
840
+ if (Buffer.isBuffer(input)) {
841
+ return Buffer.from(input);
842
+ }
843
+ if (input instanceof Uint8Array) {
844
+ return Buffer.from(input);
845
+ }
846
+ if (typeof input === "string") {
847
+ return this.bufferFromString(input);
848
+ }
849
+ throw new Error("Unsupported shared secret input");
850
+ }
851
+ bufferFromString(value) {
852
+ const trimmed = value.trim();
853
+ if (!trimmed) {
854
+ throw new Error("sharedSecret string cannot be empty");
855
+ }
856
+ const normalized = trimmed.startsWith("0x") ? trimmed.slice(2) : trimmed;
857
+ if (/^[0-9a-fA-F]+$/.test(normalized) && normalized.length % 2 === 0) {
858
+ return Buffer.from(normalized, "hex");
859
+ }
860
+ return Buffer.from(trimmed, "base64");
861
+ }
862
+ hexToBuffer(value) {
863
+ const normalized = value.startsWith("0x") ? value.slice(2) : value;
864
+ if (!/^[0-9a-fA-F]+$/.test(normalized) || normalized.length % 2 !== 0) {
865
+ throw new Error("Expected hex-encoded value");
866
+ }
867
+ return Buffer.from(normalized, "hex");
868
+ }
869
+ extractInsufficientCreditsDetails(error) {
870
+ if (!(error instanceof RegistryBrokerError) || error.status !== 402) {
871
+ return null;
872
+ }
873
+ const body = error.body;
874
+ if (!body || typeof body !== "object" || Array.isArray(body)) {
875
+ return null;
876
+ }
877
+ const maybeShortfall = body["shortfallCredits"];
878
+ if (typeof maybeShortfall !== "number" || maybeShortfall <= 0) {
879
+ return null;
880
+ }
881
+ return { shortfallCredits: maybeShortfall };
882
+ }
883
+ extractErrorMessage(body) {
884
+ if (typeof body === "string") {
885
+ return body;
886
+ }
887
+ if (isJsonObject(body) && typeof body.error === "string") {
888
+ return body.error;
889
+ }
890
+ if (isJsonObject(body) && typeof body.message === "string") {
891
+ return body.message;
892
+ }
893
+ return void 0;
894
+ }
895
+ shouldAutoTopUpHistory(payload, error) {
896
+ if (!this.historyAutoTopUp || payload.historyTtlSeconds === void 0) {
897
+ return false;
898
+ }
899
+ if (!(error instanceof RegistryBrokerError)) {
900
+ return false;
901
+ }
902
+ if (error.status !== 402) {
903
+ return false;
904
+ }
905
+ const message = this.extractErrorMessage(error.body);
906
+ if (!message) {
907
+ return true;
908
+ }
909
+ const normalised = message.toLowerCase();
910
+ return normalised.includes("history") || normalised.includes("chat history");
911
+ }
912
+ async executeHistoryAutoTopUp(reason) {
913
+ if (!this.historyAutoTopUp) {
914
+ return;
915
+ }
916
+ const hbarAmount = this.historyAutoTopUp.hbarAmount && this.historyAutoTopUp.hbarAmount > 0 ? this.historyAutoTopUp.hbarAmount : DEFAULT_HISTORY_TOP_UP_HBAR;
917
+ await this.purchaseCreditsWithHbar({
918
+ accountId: this.historyAutoTopUp.accountId,
919
+ privateKey: this.historyAutoTopUp.privateKey,
920
+ hbarAmount,
921
+ memo: this.historyAutoTopUp.memo ?? "registry-broker-client:chat-history-topup",
922
+ metadata: {
923
+ purpose: "chat-history",
924
+ reason
925
+ }
926
+ });
927
+ }
928
+ initializeEncryptionBootstrap(options) {
929
+ return this.bootstrapEncryptionOptions(options).then(() => void 0);
930
+ }
931
+ bootstrapEncryptionOptions(options) {
932
+ return bootstrapEncryptionOptions(this, options);
933
+ }
934
+ }
935
+ const isPendingRegisterAgentResponse = (response) => response.status === "pending";
936
+ const isPartialRegisterAgentResponse = (response) => response.status === "partial" && response.success === false;
937
+ const isSuccessRegisterAgentResponse = (response) => response.success === true && response.status !== "pending";
55
938
  export {
56
- HOL_CHAT_PROTOCOL_ID,
57
- buildJobStatusMessage,
58
- buildPaymentApproveMessage,
59
- buildPaymentDeclineMessage,
60
- isHolChatOp,
61
- parseHolChatOps
939
+ RegistryBrokerClient,
940
+ isPartialRegisterAgentResponse,
941
+ isPendingRegisterAgentResponse,
942
+ isSuccessRegisterAgentResponse
62
943
  };
63
944
  //# sourceMappingURL=standards-sdk.es150.js.map