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