@hashgraphonline/standards-sdk 0.1.146-chore-jsr-improvements.canary.01d3174.92 → 0.1.146-chore-jsr-improvements.canary.62a5b19.93

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 (165) hide show
  1. package/dist/cjs/services/registry-broker/client/adapters.d.ts +4 -19
  2. package/dist/cjs/services/registry-broker/client/adapters.d.ts.map +1 -1
  3. package/dist/cjs/services/registry-broker/client/agents.d.ts +4 -15
  4. package/dist/cjs/services/registry-broker/client/agents.d.ts.map +1 -1
  5. package/dist/cjs/services/registry-broker/client/base-client.d.ts +51 -1
  6. package/dist/cjs/services/registry-broker/client/base-client.d.ts.map +1 -1
  7. package/dist/cjs/services/registry-broker/client/chat-history.d.ts +4 -22
  8. package/dist/cjs/services/registry-broker/client/chat-history.d.ts.map +1 -1
  9. package/dist/cjs/services/registry-broker/client/chat.d.ts +4 -32
  10. package/dist/cjs/services/registry-broker/client/chat.d.ts.map +1 -1
  11. package/dist/cjs/services/registry-broker/client/credits.d.ts +4 -39
  12. package/dist/cjs/services/registry-broker/client/credits.d.ts.map +1 -1
  13. package/dist/cjs/services/registry-broker/client/encrypted-chat-manager.d.ts +4 -34
  14. package/dist/cjs/services/registry-broker/client/encrypted-chat-manager.d.ts.map +1 -1
  15. package/dist/cjs/services/registry-broker/client/encryption.d.ts +4 -32
  16. package/dist/cjs/services/registry-broker/client/encryption.d.ts.map +1 -1
  17. package/dist/cjs/services/registry-broker/client/ledger-auth.d.ts +4 -9
  18. package/dist/cjs/services/registry-broker/client/ledger-auth.d.ts.map +1 -1
  19. package/dist/cjs/services/registry-broker/client.d.ts +4 -0
  20. package/dist/cjs/services/registry-broker/client.d.ts.map +1 -1
  21. package/dist/cjs/standards-sdk.cjs +3 -3
  22. package/dist/cjs/standards-sdk.cjs.map +1 -1
  23. package/dist/es/services/registry-broker/client/adapters.d.ts +4 -19
  24. package/dist/es/services/registry-broker/client/adapters.d.ts.map +1 -1
  25. package/dist/es/services/registry-broker/client/agents.d.ts +4 -15
  26. package/dist/es/services/registry-broker/client/agents.d.ts.map +1 -1
  27. package/dist/es/services/registry-broker/client/base-client.d.ts +51 -1
  28. package/dist/es/services/registry-broker/client/base-client.d.ts.map +1 -1
  29. package/dist/es/services/registry-broker/client/chat-history.d.ts +4 -22
  30. package/dist/es/services/registry-broker/client/chat-history.d.ts.map +1 -1
  31. package/dist/es/services/registry-broker/client/chat.d.ts +4 -32
  32. package/dist/es/services/registry-broker/client/chat.d.ts.map +1 -1
  33. package/dist/es/services/registry-broker/client/credits.d.ts +4 -39
  34. package/dist/es/services/registry-broker/client/credits.d.ts.map +1 -1
  35. package/dist/es/services/registry-broker/client/encrypted-chat-manager.d.ts +4 -34
  36. package/dist/es/services/registry-broker/client/encrypted-chat-manager.d.ts.map +1 -1
  37. package/dist/es/services/registry-broker/client/encryption.d.ts +4 -32
  38. package/dist/es/services/registry-broker/client/encryption.d.ts.map +1 -1
  39. package/dist/es/services/registry-broker/client/ledger-auth.d.ts +4 -9
  40. package/dist/es/services/registry-broker/client/ledger-auth.d.ts.map +1 -1
  41. package/dist/es/services/registry-broker/client.d.ts +4 -0
  42. package/dist/es/services/registry-broker/client.d.ts.map +1 -1
  43. package/dist/es/standards-sdk.es.js +9 -16
  44. package/dist/es/standards-sdk.es.js.map +1 -1
  45. package/dist/es/standards-sdk.es101.js +1 -1
  46. package/dist/es/standards-sdk.es103.js +1 -1
  47. package/dist/es/standards-sdk.es109.js +2 -9
  48. package/dist/es/standards-sdk.es109.js.map +1 -1
  49. package/dist/es/standards-sdk.es11.js +1 -1
  50. package/dist/es/standards-sdk.es110.js +5 -5
  51. package/dist/es/standards-sdk.es12.js +1 -1
  52. package/dist/es/standards-sdk.es120.js +1 -1
  53. package/dist/es/standards-sdk.es121.js +1 -1
  54. package/dist/es/standards-sdk.es122.js +5 -5
  55. package/dist/es/standards-sdk.es124.js +1 -1
  56. package/dist/es/standards-sdk.es125.js +1 -1
  57. package/dist/es/standards-sdk.es127.js +624 -155
  58. package/dist/es/standards-sdk.es127.js.map +1 -1
  59. package/dist/es/standards-sdk.es128.js +16 -103
  60. package/dist/es/standards-sdk.es128.js.map +1 -1
  61. package/dist/es/standards-sdk.es129.js +72 -112
  62. package/dist/es/standards-sdk.es129.js.map +1 -1
  63. package/dist/es/standards-sdk.es130.js +75 -235
  64. package/dist/es/standards-sdk.es130.js.map +1 -1
  65. package/dist/es/standards-sdk.es131.js +53 -173
  66. package/dist/es/standards-sdk.es131.js.map +1 -1
  67. package/dist/es/standards-sdk.es132.js +156 -119
  68. package/dist/es/standards-sdk.es132.js.map +1 -1
  69. package/dist/es/standards-sdk.es133.js +8 -327
  70. package/dist/es/standards-sdk.es133.js.map +1 -1
  71. package/dist/es/standards-sdk.es134.js +74 -613
  72. package/dist/es/standards-sdk.es134.js.map +1 -1
  73. package/dist/es/standards-sdk.es135.js +61 -13
  74. package/dist/es/standards-sdk.es135.js.map +1 -1
  75. package/dist/es/standards-sdk.es136.js +30 -81
  76. package/dist/es/standards-sdk.es136.js.map +1 -1
  77. package/dist/es/standards-sdk.es137.js +34 -87
  78. package/dist/es/standards-sdk.es137.js.map +1 -1
  79. package/dist/es/standards-sdk.es138.js +28 -60
  80. package/dist/es/standards-sdk.es138.js.map +1 -1
  81. package/dist/es/standards-sdk.es139.js +933 -159
  82. package/dist/es/standards-sdk.es139.js.map +1 -1
  83. package/dist/es/standards-sdk.es140.js +12289 -7
  84. package/dist/es/standards-sdk.es140.js.map +1 -1
  85. package/dist/es/standards-sdk.es141.js +122 -70
  86. package/dist/es/standards-sdk.es141.js.map +1 -1
  87. package/dist/es/standards-sdk.es142.js +35 -58
  88. package/dist/es/standards-sdk.es142.js.map +1 -1
  89. package/dist/es/standards-sdk.es143.js +56 -30
  90. package/dist/es/standards-sdk.es143.js.map +1 -1
  91. package/dist/es/standards-sdk.es144.js +84 -34
  92. package/dist/es/standards-sdk.es144.js.map +1 -1
  93. package/dist/es/standards-sdk.es145.js +17 -28
  94. package/dist/es/standards-sdk.es145.js.map +1 -1
  95. package/dist/es/standards-sdk.es146.js +152 -118
  96. package/dist/es/standards-sdk.es146.js.map +1 -1
  97. package/dist/es/standards-sdk.es147.js +314 -34
  98. package/dist/es/standards-sdk.es147.js.map +1 -1
  99. package/dist/es/standards-sdk.es148.js +342 -13
  100. package/dist/es/standards-sdk.es148.js.map +1 -1
  101. package/dist/es/standards-sdk.es149.js +395 -12231
  102. package/dist/es/standards-sdk.es149.js.map +1 -1
  103. package/dist/es/standards-sdk.es150.js +331 -959
  104. package/dist/es/standards-sdk.es150.js.map +1 -1
  105. package/dist/es/standards-sdk.es151.js +69 -49
  106. package/dist/es/standards-sdk.es151.js.map +1 -1
  107. package/dist/es/standards-sdk.es152.js +121 -66
  108. package/dist/es/standards-sdk.es152.js.map +1 -1
  109. package/dist/es/standards-sdk.es16.js +2 -9
  110. package/dist/es/standards-sdk.es16.js.map +1 -1
  111. package/dist/es/standards-sdk.es18.js +5 -12
  112. package/dist/es/standards-sdk.es18.js.map +1 -1
  113. package/dist/es/standards-sdk.es19.js +3 -10
  114. package/dist/es/standards-sdk.es19.js.map +1 -1
  115. package/dist/es/standards-sdk.es22.js +1 -1
  116. package/dist/es/standards-sdk.es27.js +5 -12
  117. package/dist/es/standards-sdk.es27.js.map +1 -1
  118. package/dist/es/standards-sdk.es30.js +1 -1
  119. package/dist/es/standards-sdk.es31.js +1 -1
  120. package/dist/es/standards-sdk.es35.js +3 -10
  121. package/dist/es/standards-sdk.es35.js.map +1 -1
  122. package/dist/es/standards-sdk.es36.js +3 -3
  123. package/dist/es/standards-sdk.es37.js +1 -1
  124. package/dist/es/standards-sdk.es4.js +1 -1
  125. package/dist/es/standards-sdk.es53.js +1 -1
  126. package/dist/es/standards-sdk.es56.js +1 -1
  127. package/dist/es/standards-sdk.es58.js +1 -1
  128. package/dist/es/standards-sdk.es59.js +1 -1
  129. package/dist/es/standards-sdk.es60.js +3 -10
  130. package/dist/es/standards-sdk.es60.js.map +1 -1
  131. package/dist/es/standards-sdk.es62.js +1 -1
  132. package/dist/es/standards-sdk.es64.js +1 -1
  133. package/dist/es/standards-sdk.es65.js +2 -2
  134. package/dist/es/standards-sdk.es68.js +2 -2
  135. package/dist/es/standards-sdk.es69.js +1 -1
  136. package/dist/es/standards-sdk.es7.js +1 -1
  137. package/dist/es/standards-sdk.es71.js +1 -1
  138. package/dist/es/standards-sdk.es76.js +1 -1
  139. package/dist/es/standards-sdk.es77.js +2 -9
  140. package/dist/es/standards-sdk.es77.js.map +1 -1
  141. package/dist/es/standards-sdk.es78.js +1 -1
  142. package/dist/es/standards-sdk.es81.js +1 -1
  143. package/dist/es/standards-sdk.es83.js +1 -1
  144. package/dist/es/standards-sdk.es87.js +3 -3
  145. package/dist/es/standards-sdk.es91.js +1 -1
  146. package/dist/es/standards-sdk.es92.js +1 -1
  147. package/dist/es/standards-sdk.es97.js +1 -1
  148. package/dist/es/standards-sdk.es99.js +1 -1
  149. package/package.json +1 -1
  150. package/dist/es/standards-sdk.es153.js +0 -175
  151. package/dist/es/standards-sdk.es153.js.map +0 -1
  152. package/dist/es/standards-sdk.es154.js +0 -325
  153. package/dist/es/standards-sdk.es154.js.map +0 -1
  154. package/dist/es/standards-sdk.es155.js +0 -349
  155. package/dist/es/standards-sdk.es155.js.map +0 -1
  156. package/dist/es/standards-sdk.es156.js +0 -456
  157. package/dist/es/standards-sdk.es156.js.map +0 -1
  158. package/dist/es/standards-sdk.es157.js +0 -334
  159. package/dist/es/standards-sdk.es157.js.map +0 -1
  160. package/dist/es/standards-sdk.es158.js +0 -79
  161. package/dist/es/standards-sdk.es158.js.map +0 -1
  162. package/dist/es/standards-sdk.es159.js +0 -242
  163. package/dist/es/standards-sdk.es159.js.map +0 -1
  164. package/dist/es/standards-sdk.es160.js +0 -247
  165. package/dist/es/standards-sdk.es160.js.map +0 -1
@@ -1,628 +1,89 @@
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, searchResponseSchema, statsResponseSchema, registriesResponseSchema, additionalRegistryCatalogResponseSchema, popularResponseSchema, protocolsResponseSchema, detectProtocolResponseSchema, registrySearchByNamespaceSchema, vectorSearchResponseSchema, searchStatusResponseSchema, websocketStatsResponseSchema, metricsSummaryResponseSchema, searchFacetsResponseSchema } from "./standards-sdk.es150.js";
6
- import { DEFAULT_BASE_URL, normaliseBaseUrl, normaliseHeaderName, isBrowserRuntime, DEFAULT_USER_AGENT, JSON_CONTENT_TYPE, createAbortError, isJsonObject, DEFAULT_HISTORY_TOP_UP_HBAR, buildSearchQuery } from "./standards-sdk.es159.js";
7
- import { RegistryBrokerError, RegistryBrokerParseError } from "./standards-sdk.es135.js";
8
- class RegistryBrokerClient {
9
- constructor(options = {}) {
10
- this.encryptionBootstrapPromise = null;
11
- const {
12
- baseUrl = DEFAULT_BASE_URL,
13
- fetchImplementation,
14
- defaultHeaders,
15
- apiKey,
16
- ledgerApiKey,
17
- registrationAutoTopUp,
18
- historyAutoTopUp,
19
- encryption
20
- } = options;
21
- this.baseUrl = normaliseBaseUrl(baseUrl);
22
- this.fetchImpl = fetchImplementation ?? fetch;
23
- this.defaultHeaders = {
24
- ...defaultHeaders ?? {}
25
- };
26
- Object.entries(this.defaultHeaders).forEach(([key, value]) => {
27
- const headerName = normaliseHeaderName(key);
28
- if (headerName !== key) {
29
- delete this.defaultHeaders[key];
30
- this.defaultHeaders[headerName] = value;
31
- }
32
- });
33
- if (apiKey) {
34
- this.defaultHeaders["x-api-key"] = apiKey;
35
- }
36
- if (ledgerApiKey) {
37
- this.defaultHeaders["x-ledger-api-key"] = ledgerApiKey;
38
- }
39
- this.registrationAutoTopUp = registrationAutoTopUp;
40
- this.historyAutoTopUp = historyAutoTopUp;
41
- this.encryptionOptions = encryption;
42
- if (this.encryptionOptions) {
43
- this.encryptionBootstrapPromise = this.initializeEncryptionBootstrap(
44
- this.encryptionOptions
45
- );
46
- }
47
- }
48
- static async initializeAgent(options) {
49
- const { uaid, ensureEncryptionKey = true, ...clientOptions } = options;
50
- const client = new RegistryBrokerClient(clientOptions);
51
- let encryption = null;
52
- if (ensureEncryptionKey) {
53
- const ensureOptions = typeof ensureEncryptionKey === "object" ? ensureEncryptionKey : { generateIfMissing: true };
54
- encryption = await client.encryption.ensureAgentKey({
55
- uaid,
56
- ...ensureOptions
57
- });
58
- }
59
- return { client, encryption };
60
- }
61
- setApiKey(apiKey) {
62
- this.setDefaultHeader("x-api-key", apiKey);
63
- }
64
- setLedgerApiKey(apiKey) {
65
- this.setDefaultHeader("x-ledger-api-key", apiKey);
66
- }
67
- setDefaultHeader(name, value) {
68
- if (!name || name.trim().length === 0) {
69
- return;
70
- }
71
- const headerName = normaliseHeaderName(name);
72
- if (!value || value.trim().length === 0) {
73
- delete this.defaultHeaders[headerName];
74
- return;
75
- }
76
- this.defaultHeaders[headerName] = value.trim();
77
- }
78
- getDefaultHeaders() {
79
- return { ...this.defaultHeaders };
80
- }
81
- async encryptionReady() {
82
- if (!this.encryptionBootstrapPromise) {
83
- return;
84
- }
85
- await this.encryptionBootstrapPromise;
86
- }
87
- buildUrl(path) {
88
- const normalisedPath = path.startsWith("/") ? path : `/${path}`;
89
- return `${this.baseUrl}${normalisedPath}`;
90
- }
91
- async request(path, config) {
92
- const headers = new Headers();
93
- Object.entries(this.defaultHeaders).forEach(([key, value]) => {
94
- headers.set(key, value);
95
- });
96
- if (config.headers) {
97
- Object.entries(config.headers).forEach(([key, value]) => {
98
- headers.set(key, value);
1
+ import { Logger } from "./standards-sdk.es105.js";
2
+ class ContentResolverRegistryImpl {
3
+ constructor() {
4
+ this.resolver = null;
5
+ this.onUnavailableCallbacks = [];
6
+ this.logger = Logger.getInstance({ module: "ContentResolverRegistry" });
7
+ }
8
+ static getInstance() {
9
+ if (!ContentResolverRegistryImpl._instance) {
10
+ ContentResolverRegistryImpl._instance = new ContentResolverRegistryImpl();
11
+ }
12
+ return ContentResolverRegistryImpl._instance;
13
+ }
14
+ /**
15
+ * Register a content resolver (typically called by ContentStoreManager)
16
+ */
17
+ register(resolver) {
18
+ if (this.resolver) {
19
+ this.logger.warn("Resolver already registered, replacing existing");
20
+ }
21
+ this.resolver = resolver;
22
+ this.logger.info("Content resolver registered");
23
+ }
24
+ /**
25
+ * Get the registered content resolver
26
+ */
27
+ getResolver() {
28
+ return this.resolver;
29
+ }
30
+ /**
31
+ * Check if a resolver is available
32
+ */
33
+ isAvailable() {
34
+ return this.resolver !== null;
35
+ }
36
+ /**
37
+ * Unregister the current resolver
38
+ */
39
+ unregister() {
40
+ if (this.resolver) {
41
+ this.resolver = null;
42
+ this.logger.info("Content resolver unregistered");
43
+ this.onUnavailableCallbacks.forEach((callback) => {
44
+ try {
45
+ callback();
46
+ } catch (error) {
47
+ this.logger.error("Error in unavailable callback:", error);
48
+ }
99
49
  });
100
50
  }
101
- if (!headers.has("accept")) {
102
- headers.set("accept", "application/json");
103
- }
104
- if (!headers.has("user-agent") && !isBrowserRuntime()) {
105
- headers.set("user-agent", DEFAULT_USER_AGENT);
106
- }
107
- const init = {
108
- method: config.method ?? "GET",
109
- headers
110
- };
111
- if (config.body !== void 0) {
112
- init.body = JSON.stringify(config.body);
113
- if (!headers.has("content-type")) {
114
- headers.set("content-type", "application/json");
115
- }
116
- }
117
- const response = await this.fetchImpl(this.buildUrl(path), init);
118
- if (response.ok) {
119
- return response;
120
- }
121
- const errorBody = await this.extractErrorBody(response);
122
- throw new RegistryBrokerError("Registry broker request failed", {
123
- status: response.status,
124
- statusText: response.statusText,
125
- body: errorBody
126
- });
127
51
  }
128
- async requestJson(path, config) {
129
- const response = await this.request(path, config);
130
- const contentType = response.headers?.get("content-type") ?? "";
131
- if (!JSON_CONTENT_TYPE.test(contentType)) {
132
- const body = await response.text();
133
- throw new RegistryBrokerParseError(
134
- "Expected JSON response from registry broker",
135
- body
136
- );
137
- }
138
- return await response.json();
52
+ /**
53
+ * Register callback for when resolver becomes unavailable
54
+ */
55
+ onUnavailable(callback) {
56
+ this.onUnavailableCallbacks.push(callback);
139
57
  }
140
- async getAgentFeedback(uaid, options = {}) {
141
- const normalized = uaid.trim();
142
- if (!normalized) {
143
- throw new Error("uaid is required");
58
+ /**
59
+ * Remove unavailable callback
60
+ */
61
+ offUnavailable(callback) {
62
+ const index = this.onUnavailableCallbacks.indexOf(callback);
63
+ if (index !== -1) {
64
+ this.onUnavailableCallbacks.splice(index, 1);
144
65
  }
145
- const query = options.includeRevoked === true ? "?includeRevoked=true" : "";
146
- const raw = await this.requestJson(
147
- `/agents/${encodeURIComponent(normalized)}/feedback${query}`,
148
- { method: "GET" }
149
- );
150
- return this.parseWithSchema(
151
- raw,
152
- agentFeedbackResponseSchema,
153
- "agent feedback response"
154
- );
155
66
  }
156
- async listAgentFeedbackIndex(options = {}) {
157
- const params = new URLSearchParams();
158
- if (typeof options.page === "number" && Number.isFinite(options.page)) {
159
- params.set("page", String(Math.trunc(options.page)));
160
- }
161
- if (typeof options.limit === "number" && Number.isFinite(options.limit)) {
162
- params.set("limit", String(Math.trunc(options.limit)));
163
- }
164
- if (options.registries?.length) {
165
- params.set("registry", options.registries.join(","));
166
- }
167
- const suffix = params.size > 0 ? `?${params.toString()}` : "";
168
- const raw = await this.requestJson(`/agents/feedback${suffix}`, {
169
- method: "GET"
170
- });
171
- return this.parseWithSchema(
172
- raw,
173
- agentFeedbackIndexResponseSchema,
174
- "agent feedback index response"
175
- );
176
- }
177
- async listAgentFeedbackEntriesIndex(options = {}) {
178
- const params = new URLSearchParams();
179
- if (typeof options.page === "number" && Number.isFinite(options.page)) {
180
- params.set("page", String(Math.trunc(options.page)));
181
- }
182
- if (typeof options.limit === "number" && Number.isFinite(options.limit)) {
183
- params.set("limit", String(Math.trunc(options.limit)));
184
- }
185
- if (options.registries?.length) {
186
- params.set("registry", options.registries.join(","));
187
- }
188
- const suffix = params.size > 0 ? `?${params.toString()}` : "";
189
- const raw = await this.requestJson(
190
- `/agents/feedback/entries${suffix}`,
191
- { method: "GET" }
192
- );
193
- return this.parseWithSchema(
194
- raw,
195
- agentFeedbackEntriesIndexResponseSchema,
196
- "agent feedback entries index response"
197
- );
198
- }
199
- async checkAgentFeedbackEligibility(uaid, payload) {
200
- const normalized = uaid.trim();
201
- if (!normalized) {
202
- throw new Error("uaid is required");
203
- }
204
- const raw = await this.requestJson(
205
- `/agents/${encodeURIComponent(normalized)}/feedback/eligibility`,
206
- {
207
- method: "POST",
208
- body: payload,
209
- headers: { "content-type": "application/json" }
210
- }
211
- );
212
- return this.parseWithSchema(
213
- raw,
214
- agentFeedbackEligibilityResponseSchema,
215
- "agent feedback eligibility response"
216
- );
217
- }
218
- async submitAgentFeedback(uaid, payload) {
219
- const normalized = uaid.trim();
220
- if (!normalized) {
221
- throw new Error("uaid is required");
222
- }
223
- const raw = await this.requestJson(
224
- `/agents/${encodeURIComponent(normalized)}/feedback`,
225
- {
226
- method: "POST",
227
- body: payload,
228
- headers: { "content-type": "application/json" }
229
- }
230
- );
231
- return this.parseWithSchema(
232
- raw,
233
- agentFeedbackSubmissionResponseSchema,
234
- "agent feedback submission response"
235
- );
236
- }
237
- async extractErrorBody(response) {
238
- const contentType = response.headers?.get("content-type") ?? "";
239
- if (JSON_CONTENT_TYPE.test(contentType)) {
67
+ /**
68
+ * Execute operation with resolver or fallback
69
+ */
70
+ async withResolver(operation, fallback) {
71
+ if (this.resolver) {
240
72
  try {
241
- return await response.json();
73
+ return await operation(this.resolver);
242
74
  } catch (error) {
243
- return { parseError: String(error) };
244
- }
245
- }
246
- try {
247
- return await response.text();
248
- } catch (error) {
249
- return { parseError: String(error) };
250
- }
251
- }
252
- parseWithSchema(value, schema, context) {
253
- try {
254
- return schema.parse(value);
255
- } catch (error) {
256
- throw new RegistryBrokerParseError(
257
- `Failed to parse ${context}`,
258
- error instanceof ZodError || error instanceof Error ? error : String(error),
259
- value
260
- );
261
- }
262
- }
263
- async delay(ms, signal) {
264
- if (ms <= 0) {
265
- if (signal?.aborted) {
266
- throw createAbortError();
267
- }
268
- return;
269
- }
270
- await new Promise((resolve, reject) => {
271
- const timer = setTimeout(() => {
272
- if (signal) {
273
- signal.removeEventListener("abort", onAbort);
274
- }
275
- resolve();
276
- }, ms);
277
- const onAbort = () => {
278
- clearTimeout(timer);
279
- signal?.removeEventListener("abort", onAbort);
280
- reject(createAbortError());
281
- };
282
- if (signal) {
283
- if (signal.aborted) {
284
- clearTimeout(timer);
285
- reject(createAbortError());
286
- return;
287
- }
288
- signal.addEventListener("abort", onAbort, { once: true });
289
- }
290
- });
291
- }
292
- assertNodeRuntime(feature) {
293
- if (typeof process === "undefined" || !process.versions?.node) {
294
- throw new Error(`${feature} is only available in Node.js environments`);
295
- }
296
- }
297
- createEphemeralKeyPair() {
298
- this.assertNodeRuntime("generateEphemeralKeyPair");
299
- const privateKeyBytes = randomBytes(32);
300
- const publicKey = secp256k1.getPublicKey(privateKeyBytes, true);
301
- return {
302
- privateKey: Buffer.from(privateKeyBytes).toString("hex"),
303
- publicKey: Buffer.from(publicKey).toString("hex")
304
- };
305
- }
306
- deriveSharedSecret(options) {
307
- this.assertNodeRuntime("deriveSharedSecret");
308
- const privateKey = this.hexToBuffer(options.privateKey);
309
- const peerPublicKey = this.hexToBuffer(options.peerPublicKey);
310
- const shared = secp256k1.getSharedSecret(privateKey, peerPublicKey, true);
311
- return createHash("sha256").update(Buffer.from(shared)).digest();
312
- }
313
- buildCipherEnvelope(options) {
314
- this.assertNodeRuntime("encryptCipherEnvelope");
315
- const sharedSecret = this.normalizeSharedSecret(options.sharedSecret);
316
- const iv = randomBytes(12);
317
- const cipher = createCipheriv("aes-256-gcm", sharedSecret, iv);
318
- const aadSource = options.associatedData ?? options.sessionId;
319
- const associatedDataEncoded = aadSource ? Buffer.from(aadSource, "utf8").toString("base64") : void 0;
320
- if (aadSource) {
321
- cipher.setAAD(Buffer.from(aadSource, "utf8"));
322
- }
323
- const ciphertext = Buffer.concat([
324
- cipher.update(Buffer.from(options.plaintext, "utf8")),
325
- cipher.final()
326
- ]);
327
- const tag = cipher.getAuthTag();
328
- const payload = Buffer.concat([ciphertext, tag]);
329
- return {
330
- algorithm: "aes-256-gcm",
331
- ciphertext: payload.toString("base64"),
332
- nonce: iv.toString("base64"),
333
- associatedData: associatedDataEncoded,
334
- keyLocator: {
335
- sessionId: options.sessionId,
336
- revision: options.revision ?? 1
337
- },
338
- recipients: options.recipients.map((recipient) => ({
339
- ...recipient,
340
- encryptedShare: ""
341
- }))
342
- };
343
- }
344
- openCipherEnvelope(options) {
345
- this.assertNodeRuntime("decryptCipherEnvelope");
346
- const sharedSecret = this.normalizeSharedSecret(options.sharedSecret);
347
- const payload = Buffer.from(options.envelope.ciphertext, "base64");
348
- const nonce = Buffer.from(options.envelope.nonce, "base64");
349
- const ciphertext = payload.slice(0, payload.length - 16);
350
- const tag = payload.slice(payload.length - 16);
351
- const decipher = createDecipheriv("aes-256-gcm", sharedSecret, nonce);
352
- if (options.envelope.associatedData) {
353
- decipher.setAAD(Buffer.from(options.envelope.associatedData, "base64"));
354
- }
355
- decipher.setAuthTag(tag);
356
- const plaintext = Buffer.concat([
357
- decipher.update(ciphertext),
358
- decipher.final()
359
- ]);
360
- return plaintext.toString(options.encoding ?? "utf8");
361
- }
362
- normalizeSharedSecret(input) {
363
- if (Buffer.isBuffer(input)) {
364
- return Buffer.from(input);
365
- }
366
- if (input instanceof Uint8Array) {
367
- return Buffer.from(input);
368
- }
369
- if (typeof input === "string") {
370
- return this.bufferFromString(input);
371
- }
372
- throw new Error("Unsupported shared secret input");
373
- }
374
- bufferFromString(value) {
375
- const trimmed = value.trim();
376
- if (!trimmed) {
377
- throw new Error("sharedSecret string cannot be empty");
378
- }
379
- const normalized = trimmed.startsWith("0x") ? trimmed.slice(2) : trimmed;
380
- if (/^[0-9a-fA-F]+$/.test(normalized) && normalized.length % 2 === 0) {
381
- return Buffer.from(normalized, "hex");
382
- }
383
- return Buffer.from(trimmed, "base64");
384
- }
385
- hexToBuffer(value) {
386
- const normalized = value.startsWith("0x") ? value.slice(2) : value;
387
- if (!/^[0-9a-fA-F]+$/.test(normalized) || normalized.length % 2 !== 0) {
388
- throw new Error("Expected hex-encoded value");
389
- }
390
- return Buffer.from(normalized, "hex");
391
- }
392
- extractInsufficientCreditsDetails(error) {
393
- if (!(error instanceof RegistryBrokerError) || error.status !== 402) {
394
- return null;
395
- }
396
- const body = error.body;
397
- if (!body || typeof body !== "object" || Array.isArray(body)) {
398
- return null;
399
- }
400
- const maybeShortfall = body["shortfallCredits"];
401
- if (typeof maybeShortfall !== "number" || maybeShortfall <= 0) {
402
- return null;
403
- }
404
- return { shortfallCredits: maybeShortfall };
405
- }
406
- extractErrorMessage(body) {
407
- if (typeof body === "string") {
408
- return body;
409
- }
410
- if (isJsonObject(body) && typeof body.error === "string") {
411
- return body.error;
412
- }
413
- if (isJsonObject(body) && typeof body.message === "string") {
414
- return body.message;
415
- }
416
- return void 0;
417
- }
418
- shouldAutoTopUpHistory(payload, error) {
419
- if (!this.historyAutoTopUp || payload.historyTtlSeconds === void 0) {
420
- return false;
421
- }
422
- if (!(error instanceof RegistryBrokerError)) {
423
- return false;
424
- }
425
- if (error.status !== 402) {
426
- return false;
427
- }
428
- const message = this.extractErrorMessage(error.body);
429
- if (!message) {
430
- return true;
431
- }
432
- const normalised = message.toLowerCase();
433
- return normalised.includes("history") || normalised.includes("chat history");
434
- }
435
- async executeHistoryAutoTopUp(reason) {
436
- if (!this.historyAutoTopUp) {
437
- return;
438
- }
439
- const hbarAmount = this.historyAutoTopUp.hbarAmount && this.historyAutoTopUp.hbarAmount > 0 ? this.historyAutoTopUp.hbarAmount : DEFAULT_HISTORY_TOP_UP_HBAR;
440
- await this.purchaseCreditsWithHbar({
441
- accountId: this.historyAutoTopUp.accountId,
442
- privateKey: this.historyAutoTopUp.privateKey,
443
- hbarAmount,
444
- memo: this.historyAutoTopUp.memo ?? "registry-broker-client:chat-history-topup",
445
- metadata: {
446
- purpose: "chat-history",
447
- reason
75
+ this.logger.warn("Resolver operation failed, using fallback:", error);
76
+ return await fallback();
448
77
  }
449
- });
450
- }
451
- initializeEncryptionBootstrap(options) {
452
- return this.bootstrapEncryptionOptions(options).then(() => void 0);
453
- }
454
- bootstrapEncryptionOptions(_options) {
455
- return Promise.resolve(null);
456
- }
457
- async search(params = {}) {
458
- const query = buildSearchQuery(params);
459
- const raw = await this.requestJson(`/search${query}`, {
460
- method: "GET"
461
- });
462
- return this.parseWithSchema(raw, searchResponseSchema, "search response");
463
- }
464
- async stats() {
465
- const raw = await this.requestJson("/stats", { method: "GET" });
466
- return this.parseWithSchema(raw, statsResponseSchema, "stats response");
467
- }
468
- async registries() {
469
- const raw = await this.requestJson("/registries", {
470
- method: "GET"
471
- });
472
- return this.parseWithSchema(
473
- raw,
474
- registriesResponseSchema,
475
- "registries response"
476
- );
477
- }
478
- async getAdditionalRegistries() {
479
- const raw = await this.requestJson(
480
- "/register/additional-registries",
481
- {
482
- method: "GET"
483
- }
484
- );
485
- return this.parseWithSchema(
486
- raw,
487
- additionalRegistryCatalogResponseSchema,
488
- "additional registry catalog response"
489
- );
490
- }
491
- async popularSearches() {
492
- const raw = await this.requestJson("/popular", {
493
- method: "GET"
494
- });
495
- return this.parseWithSchema(
496
- raw,
497
- popularResponseSchema,
498
- "popular searches response"
499
- );
500
- }
501
- async listProtocols() {
502
- const raw = await this.requestJson("/protocols", {
503
- method: "GET"
504
- });
505
- return this.parseWithSchema(
506
- raw,
507
- protocolsResponseSchema,
508
- "protocols response"
509
- );
510
- }
511
- async detectProtocol(message) {
512
- const raw = await this.requestJson("/detect-protocol", {
513
- method: "POST",
514
- body: { message },
515
- headers: { "content-type": "application/json" }
516
- });
517
- return this.parseWithSchema(
518
- raw,
519
- detectProtocolResponseSchema,
520
- "detect protocol response"
521
- );
522
- }
523
- async registrySearchByNamespace(registry, query) {
524
- const params = new URLSearchParams();
525
- if (query) {
526
- params.set("q", query);
527
- }
528
- const suffix = params.size > 0 ? `?${params.toString()}` : "";
529
- const raw = await this.requestJson(
530
- `/registries/${encodeURIComponent(registry)}/search${suffix}`,
531
- {
532
- method: "GET"
533
- }
534
- );
535
- return this.parseWithSchema(
536
- raw,
537
- registrySearchByNamespaceSchema,
538
- "registry search response"
539
- );
540
- }
541
- async vectorSearch(request) {
542
- try {
543
- const raw = await this.requestJson("/search", {
544
- method: "POST",
545
- body: request,
546
- headers: { "content-type": "application/json" }
547
- });
548
- return this.parseWithSchema(
549
- raw,
550
- vectorSearchResponseSchema,
551
- "vector search response"
552
- );
553
- } catch (error) {
554
- if (error instanceof RegistryBrokerError && error.status === 501) {
555
- const fallbackParams = { q: request.query };
556
- if (request.limit) fallbackParams.limit = request.limit;
557
- if (request.filter?.registry) fallbackParams.registry = request.filter.registry;
558
- if (request.filter?.protocols?.length) fallbackParams.protocols = [...request.filter.protocols];
559
- const fallback = await this.search(fallbackParams);
560
- return {
561
- hits: fallback.hits.map((agent) => ({ agent, score: 0, highlights: {} })),
562
- total: fallback.total,
563
- took: 0,
564
- totalAvailable: fallback.total,
565
- visible: fallback.hits.length,
566
- limited: fallback.total > fallback.limit,
567
- credits_used: 0
568
- };
569
- }
570
- throw error;
571
- }
572
- }
573
- async searchStatus() {
574
- const raw = await this.requestJson("/search/status", {
575
- method: "GET"
576
- });
577
- return this.parseWithSchema(
578
- raw,
579
- searchStatusResponseSchema,
580
- "search status response"
581
- );
582
- }
583
- async websocketStats() {
584
- const raw = await this.requestJson("/websocket/stats", {
585
- method: "GET"
586
- });
587
- return this.parseWithSchema(
588
- raw,
589
- websocketStatsResponseSchema,
590
- "websocket stats response"
591
- );
592
- }
593
- async metricsSummary() {
594
- const raw = await this.requestJson("/metrics", {
595
- method: "GET"
596
- });
597
- return this.parseWithSchema(
598
- raw,
599
- metricsSummaryResponseSchema,
600
- "metrics summary response"
601
- );
602
- }
603
- async facets(adapter) {
604
- const params = new URLSearchParams();
605
- if (adapter) {
606
- params.set("adapter", adapter);
78
+ } else {
79
+ this.logger.warn("No resolver available, using fallback");
80
+ return await fallback();
607
81
  }
608
- const suffix = params.size > 0 ? `?${params.toString()}` : "";
609
- const raw = await this.requestJson(`/search/facets${suffix}`, {
610
- method: "GET"
611
- });
612
- return this.parseWithSchema(
613
- raw,
614
- searchFacetsResponseSchema,
615
- "search facets response"
616
- );
617
82
  }
618
83
  }
619
- const isPendingRegisterAgentResponse = (response) => response.status === "pending";
620
- const isPartialRegisterAgentResponse = (response) => response.status === "partial" && response.success === false;
621
- const isSuccessRegisterAgentResponse = (response) => response.success === true && response.status !== "pending";
84
+ const ContentResolverRegistry = ContentResolverRegistryImpl.getInstance();
622
85
  export {
623
- RegistryBrokerClient,
624
- isPartialRegisterAgentResponse,
625
- isPendingRegisterAgentResponse,
626
- isSuccessRegisterAgentResponse
86
+ ContentResolverRegistry,
87
+ ContentResolverRegistryImpl
627
88
  };
628
89
  //# sourceMappingURL=standards-sdk.es134.js.map