@hashgraphonline/standards-sdk 0.1.147 → 0.1.148
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/hcs-3/src/types.d.ts +64 -0
- package/dist/cjs/hcs-3/src/types.d.ts.map +1 -0
- package/dist/cjs/inscribe/inscriber.d.ts.map +1 -1
- package/dist/cjs/services/registry-broker/client/adapters.d.ts +15 -18
- package/dist/cjs/services/registry-broker/client/adapters.d.ts.map +1 -1
- package/dist/cjs/services/registry-broker/client/agents.d.ts +11 -14
- package/dist/cjs/services/registry-broker/client/agents.d.ts.map +1 -1
- package/dist/cjs/services/registry-broker/client/base-client.d.ts +100 -1
- package/dist/cjs/services/registry-broker/client/base-client.d.ts.map +1 -1
- package/dist/cjs/services/registry-broker/client/chat-history.d.ts +8 -12
- package/dist/cjs/services/registry-broker/client/chat-history.d.ts.map +1 -1
- package/dist/cjs/services/registry-broker/client/chat.d.ts +29 -30
- package/dist/cjs/services/registry-broker/client/chat.d.ts.map +1 -1
- package/dist/cjs/services/registry-broker/client/credits.d.ts +14 -18
- package/dist/cjs/services/registry-broker/client/credits.d.ts.map +1 -1
- package/dist/cjs/services/registry-broker/client/encrypted-chat-manager.d.ts +0 -5
- package/dist/cjs/services/registry-broker/client/encrypted-chat-manager.d.ts.map +1 -1
- package/dist/cjs/services/registry-broker/client/encryption.d.ts +32 -30
- package/dist/cjs/services/registry-broker/client/encryption.d.ts.map +1 -1
- package/dist/cjs/services/registry-broker/client/ledger-auth.d.ts +5 -8
- package/dist/cjs/services/registry-broker/client/ledger-auth.d.ts.map +1 -1
- package/dist/cjs/services/registry-broker/client/search.d.ts +14 -17
- package/dist/cjs/services/registry-broker/client/search.d.ts.map +1 -1
- package/dist/cjs/services/registry-broker/schemas.d.ts +9 -9
- package/dist/cjs/services/registry-broker/types.d.ts +1 -0
- package/dist/cjs/services/registry-broker/types.d.ts.map +1 -1
- package/dist/cjs/standards-sdk.cjs +3 -3
- package/dist/cjs/standards-sdk.cjs.map +1 -1
- package/dist/es/hcs-3/src/types.d.ts +64 -0
- package/dist/es/hcs-3/src/types.d.ts.map +1 -0
- package/dist/es/inscribe/inscriber.d.ts.map +1 -1
- package/dist/es/services/registry-broker/client/adapters.d.ts +15 -18
- package/dist/es/services/registry-broker/client/adapters.d.ts.map +1 -1
- package/dist/es/services/registry-broker/client/agents.d.ts +11 -14
- package/dist/es/services/registry-broker/client/agents.d.ts.map +1 -1
- package/dist/es/services/registry-broker/client/base-client.d.ts +100 -1
- package/dist/es/services/registry-broker/client/base-client.d.ts.map +1 -1
- package/dist/es/services/registry-broker/client/chat-history.d.ts +8 -12
- package/dist/es/services/registry-broker/client/chat-history.d.ts.map +1 -1
- package/dist/es/services/registry-broker/client/chat.d.ts +29 -30
- package/dist/es/services/registry-broker/client/chat.d.ts.map +1 -1
- package/dist/es/services/registry-broker/client/credits.d.ts +14 -18
- package/dist/es/services/registry-broker/client/credits.d.ts.map +1 -1
- package/dist/es/services/registry-broker/client/encrypted-chat-manager.d.ts +0 -5
- package/dist/es/services/registry-broker/client/encrypted-chat-manager.d.ts.map +1 -1
- package/dist/es/services/registry-broker/client/encryption.d.ts +32 -30
- package/dist/es/services/registry-broker/client/encryption.d.ts.map +1 -1
- package/dist/es/services/registry-broker/client/ledger-auth.d.ts +5 -8
- package/dist/es/services/registry-broker/client/ledger-auth.d.ts.map +1 -1
- package/dist/es/services/registry-broker/client/search.d.ts +14 -17
- package/dist/es/services/registry-broker/client/search.d.ts.map +1 -1
- package/dist/es/services/registry-broker/schemas.d.ts +9 -9
- package/dist/es/services/registry-broker/types.d.ts +1 -0
- package/dist/es/services/registry-broker/types.d.ts.map +1 -1
- package/dist/es/standards-sdk.es.js +13 -16
- package/dist/es/standards-sdk.es.js.map +1 -1
- package/dist/es/standards-sdk.es101.js +1 -1
- package/dist/es/standards-sdk.es103.js +1 -1
- package/dist/es/standards-sdk.es109.js +3 -10
- package/dist/es/standards-sdk.es109.js.map +1 -1
- package/dist/es/standards-sdk.es11.js +1 -1
- package/dist/es/standards-sdk.es110.js +5 -5
- package/dist/es/standards-sdk.es12.js +1 -1
- package/dist/es/standards-sdk.es120.js +1 -1
- package/dist/es/standards-sdk.es121.js +1 -1
- package/dist/es/standards-sdk.es122.js +5 -5
- package/dist/es/standards-sdk.es124.js +20 -1
- package/dist/es/standards-sdk.es124.js.map +1 -1
- package/dist/es/standards-sdk.es125.js +1 -1
- package/dist/es/standards-sdk.es127.js +960 -178
- package/dist/es/standards-sdk.es127.js.map +1 -1
- package/dist/es/standards-sdk.es128.js +15 -205
- package/dist/es/standards-sdk.es128.js.map +1 -1
- package/dist/es/standards-sdk.es129.js +79 -96
- package/dist/es/standards-sdk.es129.js.map +1 -1
- package/dist/es/standards-sdk.es130.js +72 -112
- package/dist/es/standards-sdk.es130.js.map +1 -1
- package/dist/es/standards-sdk.es131.js +760 -213
- package/dist/es/standards-sdk.es131.js.map +1 -1
- package/dist/es/standards-sdk.es132.js +53 -173
- package/dist/es/standards-sdk.es132.js.map +1 -1
- package/dist/es/standards-sdk.es133.js +156 -119
- package/dist/es/standards-sdk.es133.js.map +1 -1
- package/dist/es/standards-sdk.es134.js +8 -327
- package/dist/es/standards-sdk.es134.js.map +1 -1
- package/dist/es/standards-sdk.es135.js +74 -452
- package/dist/es/standards-sdk.es135.js.map +1 -1
- package/dist/es/standards-sdk.es136.js +61 -13
- package/dist/es/standards-sdk.es136.js.map +1 -1
- package/dist/es/standards-sdk.es137.js +30 -81
- package/dist/es/standards-sdk.es137.js.map +1 -1
- package/dist/es/standards-sdk.es138.js +34 -87
- package/dist/es/standards-sdk.es138.js.map +1 -1
- package/dist/es/standards-sdk.es139.js +28 -60
- package/dist/es/standards-sdk.es139.js.map +1 -1
- package/dist/es/standards-sdk.es140.js +12263 -133
- package/dist/es/standards-sdk.es140.js.map +1 -1
- package/dist/es/standards-sdk.es141.js +138 -7
- package/dist/es/standards-sdk.es141.js.map +1 -1
- package/dist/es/standards-sdk.es142.js +12 -81
- package/dist/es/standards-sdk.es142.js.map +1 -1
- package/dist/es/standards-sdk.es143.js +35 -58
- package/dist/es/standards-sdk.es143.js.map +1 -1
- package/dist/es/standards-sdk.es144.js +172 -30
- package/dist/es/standards-sdk.es144.js.map +1 -1
- package/dist/es/standards-sdk.es145.js +322 -34
- package/dist/es/standards-sdk.es145.js.map +1 -1
- package/dist/es/standards-sdk.es146.js +346 -28
- package/dist/es/standards-sdk.es146.js.map +1 -1
- package/dist/es/standards-sdk.es147.js +427 -112
- package/dist/es/standards-sdk.es147.js.map +1 -1
- package/dist/es/standards-sdk.es148.js +329 -40
- package/dist/es/standards-sdk.es148.js.map +1 -1
- package/dist/es/standards-sdk.es149.js +69 -49
- package/dist/es/standards-sdk.es149.js.map +1 -1
- package/dist/es/standards-sdk.es150.js +48 -76
- package/dist/es/standards-sdk.es150.js.map +1 -1
- package/dist/es/standards-sdk.es151.js +84 -959
- package/dist/es/standards-sdk.es151.js.map +1 -1
- package/dist/es/standards-sdk.es152.js +169 -14
- package/dist/es/standards-sdk.es152.js.map +1 -1
- package/dist/es/standards-sdk.es153.js +201 -12268
- package/dist/es/standards-sdk.es153.js.map +1 -1
- package/dist/es/standards-sdk.es154.js +223 -156
- package/dist/es/standards-sdk.es154.js.map +1 -1
- package/dist/es/standards-sdk.es155.js +112 -315
- package/dist/es/standards-sdk.es155.js.map +1 -1
- package/dist/es/standards-sdk.es156.js +116 -336
- package/dist/es/standards-sdk.es156.js.map +1 -1
- package/dist/es/standards-sdk.es157.js +151 -443
- package/dist/es/standards-sdk.es157.js.map +1 -1
- package/dist/es/standards-sdk.es158.js +170 -316
- package/dist/es/standards-sdk.es158.js.map +1 -1
- package/dist/es/standards-sdk.es159.js +132 -69
- package/dist/es/standards-sdk.es159.js.map +1 -1
- package/dist/es/standards-sdk.es16.js +3 -10
- package/dist/es/standards-sdk.es16.js.map +1 -1
- package/dist/es/standards-sdk.es160.js +300 -208
- package/dist/es/standards-sdk.es160.js.map +1 -1
- package/dist/es/standards-sdk.es161.js +16 -1
- package/dist/es/standards-sdk.es161.js.map +1 -1
- package/dist/es/standards-sdk.es18.js +6 -13
- package/dist/es/standards-sdk.es18.js.map +1 -1
- package/dist/es/standards-sdk.es19.js +4 -11
- package/dist/es/standards-sdk.es19.js.map +1 -1
- package/dist/es/standards-sdk.es22.js +1 -1
- package/dist/es/standards-sdk.es27.js +6 -13
- package/dist/es/standards-sdk.es27.js.map +1 -1
- package/dist/es/standards-sdk.es30.js +1 -1
- package/dist/es/standards-sdk.es31.js +1 -1
- package/dist/es/standards-sdk.es35.js +5 -11
- package/dist/es/standards-sdk.es35.js.map +1 -1
- package/dist/es/standards-sdk.es36.js +3 -3
- package/dist/es/standards-sdk.es37.js +1 -1
- package/dist/es/standards-sdk.es4.js +1 -1
- package/dist/es/standards-sdk.es53.js +1 -1
- package/dist/es/standards-sdk.es56.js +1 -1
- package/dist/es/standards-sdk.es58.js +1 -1
- package/dist/es/standards-sdk.es59.js +1 -1
- package/dist/es/standards-sdk.es60.js +4 -11
- package/dist/es/standards-sdk.es60.js.map +1 -1
- package/dist/es/standards-sdk.es62.js +1 -1
- package/dist/es/standards-sdk.es64.js +1 -1
- package/dist/es/standards-sdk.es65.js +2 -2
- package/dist/es/standards-sdk.es68.js +2 -2
- package/dist/es/standards-sdk.es69.js +1 -1
- package/dist/es/standards-sdk.es7.js +1 -1
- package/dist/es/standards-sdk.es71.js +1 -1
- package/dist/es/standards-sdk.es76.js +1 -1
- package/dist/es/standards-sdk.es77.js +3 -10
- package/dist/es/standards-sdk.es77.js.map +1 -1
- package/dist/es/standards-sdk.es78.js +1 -1
- package/dist/es/standards-sdk.es81.js +1 -1
- package/dist/es/standards-sdk.es83.js +1 -1
- package/dist/es/standards-sdk.es87.js +3 -3
- package/dist/es/standards-sdk.es91.js +1 -1
- package/dist/es/standards-sdk.es92.js +1 -1
- package/dist/es/standards-sdk.es97.js +1 -1
- package/dist/es/standards-sdk.es99.js +1 -1
- package/package.json +2 -1
|
@@ -1,250 +1,797 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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.es127.js";
|
|
6
|
+
import { fetchHistorySnapshot, attachDecryptedHistory, registerConversationContextForEncryption, resolveDecryptionContext, decryptHistoryEntryFromContext } from "./standards-sdk.es159.js";
|
|
7
|
+
import { createChatApi, createSession, startChat, startConversation, acceptConversation, compactHistory, fetchEncryptionStatus, postEncryptionHandshake, sendMessage, endSession, createPlaintextConversationHandle } from "./standards-sdk.es160.js";
|
|
8
|
+
import { EncryptedChatManager } from "./standards-sdk.es161.js";
|
|
9
|
+
import { createEncryptionApi, generateEncryptionKeyPair, bootstrapEncryptionOptions } from "./standards-sdk.es152.js";
|
|
10
|
+
import { adapters, adaptersDetailed, adapterRegistryCategories, adapterRegistryAdapters, createAdapterRegistryCategory, submitAdapterRegistryAdapter, adapterRegistrySubmissionStatus } from "./standards-sdk.es155.js";
|
|
11
|
+
import { resolveUaid, getRegistrationQuote, updateAgent, getRegistrationProgress, waitForRegistrationCompletion, validateUaid, getUaidConnectionStatus, closeUaidConnection, dashboardStats } from "./standards-sdk.es157.js";
|
|
12
|
+
import { purchaseCreditsWithHbar, getX402Minimums, purchaseCreditsWithX402, buyCreditsWithX402 } from "./standards-sdk.es156.js";
|
|
13
|
+
import { createLedgerChallenge, verifyLedgerChallenge, authenticateWithLedger, authenticateWithLedgerCredentials } from "./standards-sdk.es158.js";
|
|
14
|
+
import { search, stats, registries, getAdditionalRegistries, popularSearches, listProtocols, detectProtocol, registrySearchByNamespace, vectorSearch, searchStatus, websocketStats, metricsSummary, facets } from "./standards-sdk.es153.js";
|
|
15
|
+
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.es154.js";
|
|
16
|
+
import { RegistryBrokerError, RegistryBrokerParseError } from "./standards-sdk.es128.js";
|
|
17
|
+
class RegistryBrokerClient {
|
|
18
|
+
constructor(options = {}) {
|
|
19
|
+
this.encryptionBootstrapPromise = null;
|
|
20
|
+
this.chatApi = null;
|
|
21
|
+
this.encryptedChatManager = null;
|
|
22
|
+
this.encryptionApi = null;
|
|
23
|
+
this.conversationContexts = /* @__PURE__ */ new Map();
|
|
24
|
+
const {
|
|
25
|
+
baseUrl = DEFAULT_BASE_URL,
|
|
26
|
+
fetchImplementation,
|
|
27
|
+
defaultHeaders,
|
|
28
|
+
apiKey,
|
|
29
|
+
ledgerApiKey,
|
|
30
|
+
registrationAutoTopUp,
|
|
31
|
+
historyAutoTopUp,
|
|
32
|
+
encryption
|
|
33
|
+
} = options;
|
|
34
|
+
this.baseUrl = normaliseBaseUrl(baseUrl);
|
|
35
|
+
const resolvedFetch = fetchImplementation ?? (typeof globalThis.fetch === "function" ? globalThis.fetch : null);
|
|
36
|
+
if (!resolvedFetch) {
|
|
37
|
+
throw new Error(
|
|
38
|
+
"A fetch implementation is required for RegistryBrokerClient"
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
this.fetchImpl = resolvedFetch;
|
|
42
|
+
this.defaultHeaders = {
|
|
43
|
+
...defaultHeaders ?? {}
|
|
44
|
+
};
|
|
45
|
+
Object.entries(this.defaultHeaders).forEach(([key, value]) => {
|
|
46
|
+
const headerName = normaliseHeaderName(key);
|
|
47
|
+
if (headerName !== key) {
|
|
48
|
+
delete this.defaultHeaders[key];
|
|
49
|
+
this.defaultHeaders[headerName] = value;
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
if (apiKey) {
|
|
53
|
+
this.defaultHeaders["x-api-key"] = apiKey;
|
|
54
|
+
}
|
|
55
|
+
if (ledgerApiKey) {
|
|
56
|
+
this.defaultHeaders["x-ledger-api-key"] = ledgerApiKey;
|
|
57
|
+
}
|
|
58
|
+
this.registrationAutoTopUp = registrationAutoTopUp;
|
|
59
|
+
this.historyAutoTopUp = historyAutoTopUp;
|
|
60
|
+
this.encryptionOptions = encryption;
|
|
61
|
+
if (this.encryptionOptions) {
|
|
62
|
+
this.encryptionBootstrapPromise = this.initializeEncryptionBootstrap(
|
|
63
|
+
this.encryptionOptions
|
|
64
|
+
);
|
|
65
|
+
}
|
|
20
66
|
}
|
|
21
|
-
|
|
22
|
-
|
|
67
|
+
static async initializeAgent(options) {
|
|
68
|
+
const { uaid, ensureEncryptionKey = true, ...clientOptions } = options;
|
|
69
|
+
const client = new RegistryBrokerClient(clientOptions);
|
|
70
|
+
let encryption = null;
|
|
71
|
+
if (ensureEncryptionKey) {
|
|
72
|
+
const ensureOptions = typeof ensureEncryptionKey === "object" ? ensureEncryptionKey : { generateIfMissing: true };
|
|
73
|
+
encryption = await client.encryption.ensureAgentKey({
|
|
74
|
+
uaid,
|
|
75
|
+
...ensureOptions
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
return { client, encryption };
|
|
23
79
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return
|
|
31
|
-
}
|
|
32
|
-
return Math.max(
|
|
33
|
-
Math.ceil(shortfallCredits),
|
|
34
|
-
MINIMUM_REGISTRATION_AUTO_TOP_UP_CREDITS
|
|
35
|
-
);
|
|
36
|
-
}
|
|
37
|
-
async function ensureCreditsForRegistration(client, payload, autoTopUp) {
|
|
38
|
-
const details = autoTopUp ?? null;
|
|
39
|
-
if (!details) {
|
|
40
|
-
return;
|
|
80
|
+
get chat() {
|
|
81
|
+
if (this.chatApi) {
|
|
82
|
+
return this.chatApi;
|
|
83
|
+
}
|
|
84
|
+
const api = createChatApi(this, this.getEncryptedChatManager());
|
|
85
|
+
this.chatApi = api;
|
|
86
|
+
return api;
|
|
41
87
|
}
|
|
42
|
-
|
|
43
|
-
|
|
88
|
+
get encryption() {
|
|
89
|
+
if (this.encryptionApi) {
|
|
90
|
+
return this.encryptionApi;
|
|
91
|
+
}
|
|
92
|
+
const api = createEncryptionApi(this);
|
|
93
|
+
this.encryptionApi = api;
|
|
94
|
+
return api;
|
|
95
|
+
}
|
|
96
|
+
setApiKey(apiKey) {
|
|
97
|
+
this.setDefaultHeader("x-api-key", apiKey);
|
|
44
98
|
}
|
|
45
|
-
|
|
46
|
-
|
|
99
|
+
setLedgerApiKey(apiKey) {
|
|
100
|
+
this.setDefaultHeader("x-ledger-api-key", apiKey);
|
|
47
101
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const shortfall = quote.shortfallCredits ?? 0;
|
|
51
|
-
if (shortfall <= 0) {
|
|
102
|
+
setDefaultHeader(name, value) {
|
|
103
|
+
if (!name || name.trim().length === 0) {
|
|
52
104
|
return;
|
|
53
105
|
}
|
|
54
|
-
const
|
|
55
|
-
if (
|
|
106
|
+
const headerName = normaliseHeaderName(name);
|
|
107
|
+
if (!value || value.trim().length === 0) {
|
|
108
|
+
delete this.defaultHeaders[headerName];
|
|
56
109
|
return;
|
|
57
110
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
111
|
+
this.defaultHeaders[headerName] = value.trim();
|
|
112
|
+
}
|
|
113
|
+
getDefaultHeaders() {
|
|
114
|
+
return { ...this.defaultHeaders };
|
|
115
|
+
}
|
|
116
|
+
async encryptionReady() {
|
|
117
|
+
if (!this.encryptionBootstrapPromise) {
|
|
118
|
+
return;
|
|
61
119
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
120
|
+
await this.encryptionBootstrapPromise;
|
|
121
|
+
}
|
|
122
|
+
buildUrl(path) {
|
|
123
|
+
const normalisedPath = path.startsWith("/") ? path : `/${path}`;
|
|
124
|
+
return `${this.baseUrl}${normalisedPath}`;
|
|
125
|
+
}
|
|
126
|
+
async request(path, config) {
|
|
127
|
+
const headers = new Headers();
|
|
128
|
+
Object.entries(this.defaultHeaders).forEach(([key, value]) => {
|
|
129
|
+
headers.set(key, value);
|
|
130
|
+
});
|
|
131
|
+
if (config.headers) {
|
|
132
|
+
Object.entries(config.headers).forEach(([key, value]) => {
|
|
133
|
+
headers.set(key, value);
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
if (!headers.has("accept")) {
|
|
137
|
+
headers.set("accept", "application/json");
|
|
138
|
+
}
|
|
139
|
+
if (!headers.has("user-agent") && !isBrowserRuntime()) {
|
|
140
|
+
headers.set("user-agent", DEFAULT_USER_AGENT);
|
|
141
|
+
}
|
|
142
|
+
const init = {
|
|
143
|
+
method: config.method ?? "GET",
|
|
144
|
+
headers
|
|
145
|
+
};
|
|
146
|
+
if (config.body !== void 0) {
|
|
147
|
+
init.body = JSON.stringify(config.body);
|
|
148
|
+
if (!headers.has("content-type")) {
|
|
149
|
+
headers.set("content-type", "application/json");
|
|
72
150
|
}
|
|
151
|
+
}
|
|
152
|
+
const response = await this.fetchImpl(this.buildUrl(path), init);
|
|
153
|
+
if (response.ok) {
|
|
154
|
+
return response;
|
|
155
|
+
}
|
|
156
|
+
const errorBody = await this.extractErrorBody(response);
|
|
157
|
+
throw new RegistryBrokerError("Registry broker request failed", {
|
|
158
|
+
status: response.status,
|
|
159
|
+
statusText: response.statusText,
|
|
160
|
+
body: errorBody
|
|
73
161
|
});
|
|
74
162
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
163
|
+
async requestJson(path, config) {
|
|
164
|
+
const response = await this.request(path, config);
|
|
165
|
+
const contentType = response.headers?.get("content-type") ?? "";
|
|
166
|
+
if (!JSON_CONTENT_TYPE.test(contentType)) {
|
|
167
|
+
const body = await response.text();
|
|
168
|
+
throw new RegistryBrokerParseError(
|
|
169
|
+
"Expected JSON response from registry broker",
|
|
170
|
+
body
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
return await response.json();
|
|
78
174
|
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
175
|
+
async getAgentFeedback(uaid, options = {}) {
|
|
176
|
+
const normalized = uaid.trim();
|
|
177
|
+
if (!normalized) {
|
|
178
|
+
throw new Error("uaid is required");
|
|
179
|
+
}
|
|
180
|
+
const query = options.includeRevoked === true ? "?includeRevoked=true" : "";
|
|
181
|
+
const raw = await this.requestJson(
|
|
182
|
+
`/agents/${encodeURIComponent(normalized)}/feedback${query}`,
|
|
183
|
+
{ method: "GET" }
|
|
184
|
+
);
|
|
185
|
+
return this.parseWithSchema(
|
|
186
|
+
raw,
|
|
187
|
+
agentFeedbackResponseSchema,
|
|
188
|
+
"agent feedback response"
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
async listAgentFeedbackIndex(options = {}) {
|
|
192
|
+
const params = new URLSearchParams();
|
|
193
|
+
if (typeof options.page === "number" && Number.isFinite(options.page)) {
|
|
194
|
+
params.set("page", String(Math.trunc(options.page)));
|
|
195
|
+
}
|
|
196
|
+
if (typeof options.limit === "number" && Number.isFinite(options.limit)) {
|
|
197
|
+
params.set("limit", String(Math.trunc(options.limit)));
|
|
198
|
+
}
|
|
199
|
+
if (options.registries?.length) {
|
|
200
|
+
params.set("registry", options.registries.join(","));
|
|
201
|
+
}
|
|
202
|
+
const suffix = params.size > 0 ? `?${params.toString()}` : "";
|
|
203
|
+
const raw = await this.requestJson(`/agents/feedback${suffix}`, {
|
|
84
204
|
method: "GET"
|
|
205
|
+
});
|
|
206
|
+
return this.parseWithSchema(
|
|
207
|
+
raw,
|
|
208
|
+
agentFeedbackIndexResponseSchema,
|
|
209
|
+
"agent feedback index response"
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
async listAgentFeedbackEntriesIndex(options = {}) {
|
|
213
|
+
const params = new URLSearchParams();
|
|
214
|
+
if (typeof options.page === "number" && Number.isFinite(options.page)) {
|
|
215
|
+
params.set("page", String(Math.trunc(options.page)));
|
|
85
216
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
raw,
|
|
89
|
-
resolveResponseSchema,
|
|
90
|
-
"resolve UAID response"
|
|
91
|
-
);
|
|
92
|
-
};
|
|
93
|
-
RegistryBrokerClient.prototype.registerAgent = async function(payload, options) {
|
|
94
|
-
const autoTopUp = options?.autoTopUp ?? this.registrationAutoTopUp;
|
|
95
|
-
if (!autoTopUp) {
|
|
96
|
-
return performRegisterAgent(this, payload);
|
|
97
|
-
}
|
|
98
|
-
await ensureCreditsForRegistration(this, payload, autoTopUp);
|
|
99
|
-
let retried = false;
|
|
100
|
-
while (true) {
|
|
101
|
-
try {
|
|
102
|
-
return await performRegisterAgent(this, payload);
|
|
103
|
-
} catch (error) {
|
|
104
|
-
const shortfall = this.extractInsufficientCreditsDetails(error);
|
|
105
|
-
if (shortfall && !retried) {
|
|
106
|
-
await ensureCreditsForRegistration(this, payload, autoTopUp);
|
|
107
|
-
retried = true;
|
|
108
|
-
continue;
|
|
109
|
-
}
|
|
110
|
-
throw error;
|
|
217
|
+
if (typeof options.limit === "number" && Number.isFinite(options.limit)) {
|
|
218
|
+
params.set("limit", String(Math.trunc(options.limit)));
|
|
111
219
|
}
|
|
220
|
+
if (options.registries?.length) {
|
|
221
|
+
params.set("registry", options.registries.join(","));
|
|
222
|
+
}
|
|
223
|
+
const suffix = params.size > 0 ? `?${params.toString()}` : "";
|
|
224
|
+
const raw = await this.requestJson(
|
|
225
|
+
`/agents/feedback/entries${suffix}`,
|
|
226
|
+
{ method: "GET" }
|
|
227
|
+
);
|
|
228
|
+
return this.parseWithSchema(
|
|
229
|
+
raw,
|
|
230
|
+
agentFeedbackEntriesIndexResponseSchema,
|
|
231
|
+
"agent feedback entries index response"
|
|
232
|
+
);
|
|
112
233
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
body: serialiseAgentRegistrationRequest(payload),
|
|
118
|
-
headers: { "content-type": "application/json" }
|
|
119
|
-
});
|
|
120
|
-
return this.parseWithSchema(
|
|
121
|
-
raw,
|
|
122
|
-
registrationQuoteResponseSchema,
|
|
123
|
-
"registration quote response"
|
|
124
|
-
);
|
|
125
|
-
};
|
|
126
|
-
RegistryBrokerClient.prototype.updateAgent = async function(uaid, payload) {
|
|
127
|
-
const raw = await this.requestJson(
|
|
128
|
-
`/register/${encodeURIComponent(uaid)}`,
|
|
129
|
-
{
|
|
130
|
-
method: "PUT",
|
|
131
|
-
body: serialiseAgentRegistrationRequest(payload),
|
|
132
|
-
headers: { "content-type": "application/json" }
|
|
234
|
+
async checkAgentFeedbackEligibility(uaid, payload) {
|
|
235
|
+
const normalized = uaid.trim();
|
|
236
|
+
if (!normalized) {
|
|
237
|
+
throw new Error("uaid is required");
|
|
133
238
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
239
|
+
const raw = await this.requestJson(
|
|
240
|
+
`/agents/${encodeURIComponent(normalized)}/feedback/eligibility`,
|
|
241
|
+
{
|
|
242
|
+
method: "POST",
|
|
243
|
+
body: payload,
|
|
244
|
+
headers: { "content-type": "application/json" }
|
|
245
|
+
}
|
|
246
|
+
);
|
|
247
|
+
return this.parseWithSchema(
|
|
248
|
+
raw,
|
|
249
|
+
agentFeedbackEligibilityResponseSchema,
|
|
250
|
+
"agent feedback eligibility response"
|
|
251
|
+
);
|
|
145
252
|
}
|
|
146
|
-
|
|
253
|
+
async submitAgentFeedback(uaid, payload) {
|
|
254
|
+
const normalized = uaid.trim();
|
|
255
|
+
if (!normalized) {
|
|
256
|
+
throw new Error("uaid is required");
|
|
257
|
+
}
|
|
147
258
|
const raw = await this.requestJson(
|
|
148
|
-
`/
|
|
149
|
-
{
|
|
259
|
+
`/agents/${encodeURIComponent(normalized)}/feedback`,
|
|
260
|
+
{
|
|
261
|
+
method: "POST",
|
|
262
|
+
body: payload,
|
|
263
|
+
headers: { "content-type": "application/json" }
|
|
264
|
+
}
|
|
150
265
|
);
|
|
151
|
-
|
|
266
|
+
return this.parseWithSchema(
|
|
152
267
|
raw,
|
|
153
|
-
|
|
154
|
-
"
|
|
268
|
+
agentFeedbackSubmissionResponseSchema,
|
|
269
|
+
"agent feedback submission response"
|
|
155
270
|
);
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
271
|
+
}
|
|
272
|
+
async search(params = {}) {
|
|
273
|
+
return search(this, params);
|
|
274
|
+
}
|
|
275
|
+
async stats() {
|
|
276
|
+
return stats(this);
|
|
277
|
+
}
|
|
278
|
+
async registries() {
|
|
279
|
+
return registries(this);
|
|
280
|
+
}
|
|
281
|
+
async getAdditionalRegistries() {
|
|
282
|
+
return getAdditionalRegistries(this);
|
|
283
|
+
}
|
|
284
|
+
async popularSearches() {
|
|
285
|
+
return popularSearches(this);
|
|
286
|
+
}
|
|
287
|
+
async listProtocols() {
|
|
288
|
+
return listProtocols(this);
|
|
289
|
+
}
|
|
290
|
+
async detectProtocol(message) {
|
|
291
|
+
return detectProtocol(this, message);
|
|
292
|
+
}
|
|
293
|
+
async registrySearchByNamespace(registry, query) {
|
|
294
|
+
return registrySearchByNamespace(this, registry, query);
|
|
295
|
+
}
|
|
296
|
+
async vectorSearch(request) {
|
|
297
|
+
return vectorSearch(this, request);
|
|
298
|
+
}
|
|
299
|
+
async searchStatus() {
|
|
300
|
+
return searchStatus(this);
|
|
301
|
+
}
|
|
302
|
+
async websocketStats() {
|
|
303
|
+
return websocketStats(this);
|
|
304
|
+
}
|
|
305
|
+
async metricsSummary() {
|
|
306
|
+
return metricsSummary(this);
|
|
307
|
+
}
|
|
308
|
+
async facets(adapter) {
|
|
309
|
+
return facets(this, adapter);
|
|
310
|
+
}
|
|
311
|
+
async adapters() {
|
|
312
|
+
return adapters(this);
|
|
313
|
+
}
|
|
314
|
+
async adaptersDetailed() {
|
|
315
|
+
return adaptersDetailed(this);
|
|
316
|
+
}
|
|
317
|
+
async adapterRegistryCategories() {
|
|
318
|
+
return adapterRegistryCategories(this);
|
|
319
|
+
}
|
|
320
|
+
async adapterRegistryAdapters(filters) {
|
|
321
|
+
return adapterRegistryAdapters(this, filters);
|
|
322
|
+
}
|
|
323
|
+
async createAdapterRegistryCategory(payload) {
|
|
324
|
+
return createAdapterRegistryCategory(this, payload);
|
|
325
|
+
}
|
|
326
|
+
async submitAdapterRegistryAdapter(payload) {
|
|
327
|
+
return submitAdapterRegistryAdapter(this, payload);
|
|
328
|
+
}
|
|
329
|
+
async adapterRegistrySubmissionStatus(submissionId) {
|
|
330
|
+
return adapterRegistrySubmissionStatus(this, submissionId);
|
|
331
|
+
}
|
|
332
|
+
async resolveUaid(uaid) {
|
|
333
|
+
return resolveUaid(this, uaid);
|
|
334
|
+
}
|
|
335
|
+
async performRegisterAgent(payload) {
|
|
336
|
+
const raw = await this.requestJson("/register", {
|
|
337
|
+
method: "POST",
|
|
338
|
+
body: serialiseAgentRegistrationRequest(payload),
|
|
339
|
+
headers: { "content-type": "application/json" }
|
|
340
|
+
});
|
|
341
|
+
return this.parseWithSchema(
|
|
342
|
+
raw,
|
|
343
|
+
registerAgentResponseSchema,
|
|
344
|
+
"register agent response"
|
|
345
|
+
);
|
|
346
|
+
}
|
|
347
|
+
calculateHbarAmount(creditsToPurchase, creditsPerHbar) {
|
|
348
|
+
if (creditsPerHbar <= 0) {
|
|
349
|
+
throw new Error("creditsPerHbar must be positive");
|
|
350
|
+
}
|
|
351
|
+
if (creditsToPurchase <= 0) {
|
|
352
|
+
throw new Error("creditsToPurchase must be positive");
|
|
160
353
|
}
|
|
161
|
-
|
|
354
|
+
const rawHbar = creditsToPurchase / creditsPerHbar;
|
|
355
|
+
const tinybars = Math.ceil(rawHbar * 1e8);
|
|
356
|
+
return tinybars / 1e8;
|
|
162
357
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
)
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
358
|
+
resolveCreditsToPurchase(shortfallCredits) {
|
|
359
|
+
if (!Number.isFinite(shortfallCredits) || shortfallCredits <= 0) {
|
|
360
|
+
return 0;
|
|
361
|
+
}
|
|
362
|
+
return Math.max(
|
|
363
|
+
Math.ceil(shortfallCredits),
|
|
364
|
+
MINIMUM_REGISTRATION_AUTO_TOP_UP_CREDITS
|
|
365
|
+
);
|
|
366
|
+
}
|
|
367
|
+
async ensureCreditsForRegistration(payload, autoTopUp) {
|
|
368
|
+
const details = autoTopUp ?? null;
|
|
369
|
+
if (!details) {
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
if (!details.accountId || !details.accountId.trim()) {
|
|
373
|
+
throw new Error("autoTopUp.accountId is required");
|
|
374
|
+
}
|
|
375
|
+
if (!details.privateKey || !details.privateKey.trim()) {
|
|
376
|
+
throw new Error("autoTopUp.privateKey is required");
|
|
377
|
+
}
|
|
378
|
+
for (let attempt = 0; attempt < 3; attempt += 1) {
|
|
379
|
+
const quote = await this.getRegistrationQuote(payload);
|
|
380
|
+
const shortfall = quote.shortfallCredits ?? 0;
|
|
381
|
+
if (shortfall <= 0) {
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
384
|
+
const creditsToPurchase = this.resolveCreditsToPurchase(shortfall);
|
|
385
|
+
if (creditsToPurchase <= 0) {
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
const creditsPerHbar = quote.creditsPerHbar ?? null;
|
|
389
|
+
if (!creditsPerHbar || creditsPerHbar <= 0) {
|
|
390
|
+
throw new Error("Unable to determine credits per HBAR for auto top-up");
|
|
186
391
|
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
392
|
+
const hbarAmount = this.calculateHbarAmount(
|
|
393
|
+
creditsToPurchase,
|
|
394
|
+
creditsPerHbar
|
|
395
|
+
);
|
|
396
|
+
await this.purchaseCreditsWithHbar({
|
|
397
|
+
accountId: details.accountId.trim(),
|
|
398
|
+
privateKey: details.privateKey.trim(),
|
|
399
|
+
hbarAmount,
|
|
400
|
+
memo: details.memo ?? "Registry Broker auto top-up",
|
|
401
|
+
metadata: {
|
|
402
|
+
shortfallCredits: shortfall,
|
|
403
|
+
requiredCredits: quote.requiredCredits,
|
|
404
|
+
purchasedCredits: creditsToPurchase
|
|
197
405
|
}
|
|
198
|
-
|
|
406
|
+
});
|
|
407
|
+
}
|
|
408
|
+
const finalQuote = await this.getRegistrationQuote(payload);
|
|
409
|
+
if ((finalQuote.shortfallCredits ?? 0) > 0) {
|
|
410
|
+
throw new Error("Unable to purchase sufficient credits for registration");
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
async registerAgent(payload, options) {
|
|
414
|
+
const autoTopUp = options?.autoTopUp ?? this.registrationAutoTopUp;
|
|
415
|
+
if (!autoTopUp) {
|
|
416
|
+
return this.performRegisterAgent(payload);
|
|
417
|
+
}
|
|
418
|
+
await this.ensureCreditsForRegistration(payload, autoTopUp);
|
|
419
|
+
let retried = false;
|
|
420
|
+
while (true) {
|
|
421
|
+
try {
|
|
422
|
+
return await this.performRegisterAgent(payload);
|
|
423
|
+
} catch (error) {
|
|
424
|
+
const shortfall = this.extractInsufficientCreditsDetails(error);
|
|
425
|
+
if (shortfall && !retried) {
|
|
426
|
+
await this.ensureCreditsForRegistration(payload, autoTopUp);
|
|
427
|
+
retried = true;
|
|
428
|
+
continue;
|
|
429
|
+
}
|
|
430
|
+
throw error;
|
|
199
431
|
}
|
|
200
432
|
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
433
|
+
}
|
|
434
|
+
async getRegistrationQuote(payload) {
|
|
435
|
+
return getRegistrationQuote(this, payload);
|
|
436
|
+
}
|
|
437
|
+
async updateAgent(uaid, payload) {
|
|
438
|
+
return updateAgent(this, uaid, payload);
|
|
439
|
+
}
|
|
440
|
+
async getRegistrationProgress(attemptId) {
|
|
441
|
+
return getRegistrationProgress(this, attemptId);
|
|
442
|
+
}
|
|
443
|
+
async waitForRegistrationCompletion(attemptId, options) {
|
|
444
|
+
return waitForRegistrationCompletion(this, attemptId, options);
|
|
445
|
+
}
|
|
446
|
+
async validateUaid(uaid) {
|
|
447
|
+
return validateUaid(this, uaid);
|
|
448
|
+
}
|
|
449
|
+
async getUaidConnectionStatus(uaid) {
|
|
450
|
+
return getUaidConnectionStatus(this, uaid);
|
|
451
|
+
}
|
|
452
|
+
async closeUaidConnection(uaid) {
|
|
453
|
+
return closeUaidConnection(this, uaid);
|
|
454
|
+
}
|
|
455
|
+
async dashboardStats() {
|
|
456
|
+
return dashboardStats(this);
|
|
457
|
+
}
|
|
458
|
+
async purchaseCreditsWithHbar(params) {
|
|
459
|
+
return purchaseCreditsWithHbar(this, params);
|
|
460
|
+
}
|
|
461
|
+
async getX402Minimums() {
|
|
462
|
+
return getX402Minimums(this);
|
|
463
|
+
}
|
|
464
|
+
async purchaseCreditsWithX402(params) {
|
|
465
|
+
return purchaseCreditsWithX402(this, params);
|
|
466
|
+
}
|
|
467
|
+
async buyCreditsWithX402(params) {
|
|
468
|
+
return buyCreditsWithX402(this, params);
|
|
469
|
+
}
|
|
470
|
+
async generateEncryptionKeyPair(options = {}) {
|
|
471
|
+
return generateEncryptionKeyPair(this, options);
|
|
472
|
+
}
|
|
473
|
+
async createLedgerChallenge(payload) {
|
|
474
|
+
return createLedgerChallenge(this, payload);
|
|
475
|
+
}
|
|
476
|
+
async verifyLedgerChallenge(payload) {
|
|
477
|
+
return verifyLedgerChallenge(this, payload);
|
|
478
|
+
}
|
|
479
|
+
async authenticateWithLedger(options) {
|
|
480
|
+
return authenticateWithLedger(this, options);
|
|
481
|
+
}
|
|
482
|
+
async authenticateWithLedgerCredentials(options) {
|
|
483
|
+
return authenticateWithLedgerCredentials(this, options);
|
|
484
|
+
}
|
|
485
|
+
async fetchHistorySnapshot(sessionId, options) {
|
|
486
|
+
return fetchHistorySnapshot(
|
|
487
|
+
this.conversationContexts,
|
|
488
|
+
this,
|
|
489
|
+
sessionId,
|
|
490
|
+
options
|
|
491
|
+
);
|
|
492
|
+
}
|
|
493
|
+
attachDecryptedHistory(sessionId, snapshot, options) {
|
|
494
|
+
return attachDecryptedHistory(
|
|
495
|
+
this.conversationContexts,
|
|
496
|
+
this,
|
|
497
|
+
sessionId,
|
|
498
|
+
snapshot,
|
|
499
|
+
options
|
|
500
|
+
);
|
|
501
|
+
}
|
|
502
|
+
registerConversationContextForEncryption(context) {
|
|
503
|
+
registerConversationContextForEncryption(
|
|
504
|
+
this.conversationContexts,
|
|
505
|
+
context
|
|
506
|
+
);
|
|
507
|
+
}
|
|
508
|
+
resolveDecryptionContext(sessionId, options) {
|
|
509
|
+
return resolveDecryptionContext(
|
|
510
|
+
this.conversationContexts,
|
|
511
|
+
this,
|
|
512
|
+
sessionId,
|
|
513
|
+
options
|
|
514
|
+
);
|
|
515
|
+
}
|
|
516
|
+
decryptHistoryEntryFromContext(_sessionId, entry, context) {
|
|
517
|
+
return decryptHistoryEntryFromContext(this, entry, context);
|
|
518
|
+
}
|
|
519
|
+
async createSession(payload, allowHistoryAutoTopUp = true) {
|
|
520
|
+
return createSession(this, payload, allowHistoryAutoTopUp);
|
|
521
|
+
}
|
|
522
|
+
async startChat(options) {
|
|
523
|
+
return startChat(this, this.getEncryptedChatManager(), options);
|
|
524
|
+
}
|
|
525
|
+
async startConversation(options) {
|
|
526
|
+
return startConversation(this, this.getEncryptedChatManager(), options);
|
|
527
|
+
}
|
|
528
|
+
async acceptConversation(options) {
|
|
529
|
+
return acceptConversation(
|
|
530
|
+
this,
|
|
531
|
+
this.getEncryptedChatManager(),
|
|
532
|
+
options
|
|
533
|
+
);
|
|
534
|
+
}
|
|
535
|
+
compactHistory(payload) {
|
|
536
|
+
return compactHistory(this, payload);
|
|
537
|
+
}
|
|
538
|
+
fetchEncryptionStatus(sessionId) {
|
|
539
|
+
return fetchEncryptionStatus(this, sessionId);
|
|
540
|
+
}
|
|
541
|
+
postEncryptionHandshake(sessionId, payload) {
|
|
542
|
+
return postEncryptionHandshake(this, sessionId, payload);
|
|
543
|
+
}
|
|
544
|
+
sendMessage(payload) {
|
|
545
|
+
return sendMessage(this, payload);
|
|
546
|
+
}
|
|
547
|
+
endSession(sessionId) {
|
|
548
|
+
return endSession(this, sessionId);
|
|
549
|
+
}
|
|
550
|
+
createPlaintextConversationHandle(sessionId, summary, defaultAuth, context) {
|
|
551
|
+
return createPlaintextConversationHandle(
|
|
552
|
+
this,
|
|
553
|
+
sessionId,
|
|
554
|
+
summary,
|
|
555
|
+
defaultAuth,
|
|
556
|
+
context
|
|
557
|
+
);
|
|
558
|
+
}
|
|
559
|
+
getEncryptedChatManager() {
|
|
560
|
+
if (this.encryptedChatManager) {
|
|
561
|
+
return this.encryptedChatManager;
|
|
562
|
+
}
|
|
563
|
+
const manager = new EncryptedChatManager(this);
|
|
564
|
+
this.encryptedChatManager = manager;
|
|
565
|
+
return manager;
|
|
566
|
+
}
|
|
567
|
+
async extractErrorBody(response) {
|
|
568
|
+
const contentType = response.headers?.get("content-type") ?? "";
|
|
569
|
+
if (JSON_CONTENT_TYPE.test(contentType)) {
|
|
570
|
+
try {
|
|
571
|
+
return await response.json();
|
|
572
|
+
} catch (error) {
|
|
573
|
+
return { parseError: String(error) };
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
try {
|
|
577
|
+
return await response.text();
|
|
578
|
+
} catch (error) {
|
|
579
|
+
return { parseError: String(error) };
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
parseWithSchema(value, schema, context) {
|
|
583
|
+
try {
|
|
584
|
+
return schema.parse(value);
|
|
585
|
+
} catch (error) {
|
|
586
|
+
throw new RegistryBrokerParseError(
|
|
587
|
+
`Failed to parse ${context}`,
|
|
588
|
+
error instanceof ZodError || error instanceof Error ? error : String(error),
|
|
589
|
+
value
|
|
204
590
|
);
|
|
205
591
|
}
|
|
206
|
-
await this.delay(interval, signal);
|
|
207
592
|
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
593
|
+
async delay(ms, signal) {
|
|
594
|
+
if (ms <= 0) {
|
|
595
|
+
if (signal?.aborted) {
|
|
596
|
+
throw createAbortError();
|
|
597
|
+
}
|
|
598
|
+
return;
|
|
214
599
|
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
};
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
600
|
+
await new Promise((resolve, reject) => {
|
|
601
|
+
const timer = setTimeout(() => {
|
|
602
|
+
if (signal) {
|
|
603
|
+
signal.removeEventListener("abort", onAbort);
|
|
604
|
+
}
|
|
605
|
+
resolve();
|
|
606
|
+
}, ms);
|
|
607
|
+
const onAbort = () => {
|
|
608
|
+
clearTimeout(timer);
|
|
609
|
+
signal?.removeEventListener("abort", onAbort);
|
|
610
|
+
reject(createAbortError());
|
|
611
|
+
};
|
|
612
|
+
if (signal) {
|
|
613
|
+
if (signal.aborted) {
|
|
614
|
+
clearTimeout(timer);
|
|
615
|
+
reject(createAbortError());
|
|
616
|
+
return;
|
|
617
|
+
}
|
|
618
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
619
|
+
}
|
|
620
|
+
});
|
|
621
|
+
}
|
|
622
|
+
assertNodeRuntime(feature) {
|
|
623
|
+
if (typeof process === "undefined" || !process.versions?.node) {
|
|
624
|
+
throw new Error(`${feature} is only available in Node.js environments`);
|
|
227
625
|
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
626
|
+
}
|
|
627
|
+
createEphemeralKeyPair() {
|
|
628
|
+
this.assertNodeRuntime("generateEphemeralKeyPair");
|
|
629
|
+
const privateKeyBytes = randomBytes(32);
|
|
630
|
+
const publicKey = secp256k1.getPublicKey(privateKeyBytes, true);
|
|
631
|
+
return {
|
|
632
|
+
privateKey: Buffer.from(privateKeyBytes).toString("hex"),
|
|
633
|
+
publicKey: Buffer.from(publicKey).toString("hex")
|
|
634
|
+
};
|
|
635
|
+
}
|
|
636
|
+
deriveSharedSecret(options) {
|
|
637
|
+
this.assertNodeRuntime("deriveSharedSecret");
|
|
638
|
+
const privateKey = this.hexToBuffer(options.privateKey);
|
|
639
|
+
const peerPublicKey = this.hexToBuffer(options.peerPublicKey);
|
|
640
|
+
const shared = secp256k1.getSharedSecret(privateKey, peerPublicKey, true);
|
|
641
|
+
return createHash("sha256").update(Buffer.from(shared)).digest();
|
|
642
|
+
}
|
|
643
|
+
buildCipherEnvelope(options) {
|
|
644
|
+
this.assertNodeRuntime("encryptCipherEnvelope");
|
|
645
|
+
const sharedSecret = this.normalizeSharedSecret(options.sharedSecret);
|
|
646
|
+
const iv = randomBytes(12);
|
|
647
|
+
const cipher = createCipheriv("aes-256-gcm", sharedSecret, iv);
|
|
648
|
+
const aadSource = options.associatedData ?? options.sessionId;
|
|
649
|
+
const associatedDataEncoded = aadSource ? Buffer.from(aadSource, "utf8").toString("base64") : void 0;
|
|
650
|
+
if (aadSource) {
|
|
651
|
+
cipher.setAAD(Buffer.from(aadSource, "utf8"));
|
|
652
|
+
}
|
|
653
|
+
const ciphertext = Buffer.concat([
|
|
654
|
+
cipher.update(Buffer.from(options.plaintext, "utf8")),
|
|
655
|
+
cipher.final()
|
|
656
|
+
]);
|
|
657
|
+
const tag = cipher.getAuthTag();
|
|
658
|
+
const payload = Buffer.concat([ciphertext, tag]);
|
|
659
|
+
return {
|
|
660
|
+
algorithm: "aes-256-gcm",
|
|
661
|
+
ciphertext: payload.toString("base64"),
|
|
662
|
+
nonce: iv.toString("base64"),
|
|
663
|
+
associatedData: associatedDataEncoded,
|
|
664
|
+
keyLocator: {
|
|
665
|
+
sessionId: options.sessionId,
|
|
666
|
+
revision: options.revision ?? 1
|
|
667
|
+
},
|
|
668
|
+
recipients: options.recipients.map((recipient) => ({
|
|
669
|
+
...recipient,
|
|
670
|
+
encryptedShare: ""
|
|
671
|
+
}))
|
|
672
|
+
};
|
|
673
|
+
}
|
|
674
|
+
openCipherEnvelope(options) {
|
|
675
|
+
this.assertNodeRuntime("decryptCipherEnvelope");
|
|
676
|
+
const sharedSecret = this.normalizeSharedSecret(options.sharedSecret);
|
|
677
|
+
const payload = Buffer.from(options.envelope.ciphertext, "base64");
|
|
678
|
+
const nonce = Buffer.from(options.envelope.nonce, "base64");
|
|
679
|
+
const ciphertext = payload.slice(0, payload.length - 16);
|
|
680
|
+
const tag = payload.slice(payload.length - 16);
|
|
681
|
+
const decipher = createDecipheriv("aes-256-gcm", sharedSecret, nonce);
|
|
682
|
+
if (options.envelope.associatedData) {
|
|
683
|
+
decipher.setAAD(Buffer.from(options.envelope.associatedData, "base64"));
|
|
684
|
+
}
|
|
685
|
+
decipher.setAuthTag(tag);
|
|
686
|
+
const plaintext = Buffer.concat([
|
|
687
|
+
decipher.update(ciphertext),
|
|
688
|
+
decipher.final()
|
|
689
|
+
]);
|
|
690
|
+
return plaintext.toString(options.encoding ?? "utf8");
|
|
691
|
+
}
|
|
692
|
+
normalizeSharedSecret(input) {
|
|
693
|
+
if (Buffer.isBuffer(input)) {
|
|
694
|
+
return Buffer.from(input);
|
|
695
|
+
}
|
|
696
|
+
if (input instanceof Uint8Array) {
|
|
697
|
+
return Buffer.from(input);
|
|
698
|
+
}
|
|
699
|
+
if (typeof input === "string") {
|
|
700
|
+
return this.bufferFromString(input);
|
|
701
|
+
}
|
|
702
|
+
throw new Error("Unsupported shared secret input");
|
|
703
|
+
}
|
|
704
|
+
bufferFromString(value) {
|
|
705
|
+
const trimmed = value.trim();
|
|
706
|
+
if (!trimmed) {
|
|
707
|
+
throw new Error("sharedSecret string cannot be empty");
|
|
708
|
+
}
|
|
709
|
+
const normalized = trimmed.startsWith("0x") ? trimmed.slice(2) : trimmed;
|
|
710
|
+
if (/^[0-9a-fA-F]+$/.test(normalized) && normalized.length % 2 === 0) {
|
|
711
|
+
return Buffer.from(normalized, "hex");
|
|
712
|
+
}
|
|
713
|
+
return Buffer.from(trimmed, "base64");
|
|
714
|
+
}
|
|
715
|
+
hexToBuffer(value) {
|
|
716
|
+
const normalized = value.startsWith("0x") ? value.slice(2) : value;
|
|
717
|
+
if (!/^[0-9a-fA-F]+$/.test(normalized) || normalized.length % 2 !== 0) {
|
|
718
|
+
throw new Error("Expected hex-encoded value");
|
|
719
|
+
}
|
|
720
|
+
return Buffer.from(normalized, "hex");
|
|
721
|
+
}
|
|
722
|
+
extractInsufficientCreditsDetails(error) {
|
|
723
|
+
if (!(error instanceof RegistryBrokerError) || error.status !== 402) {
|
|
724
|
+
return null;
|
|
725
|
+
}
|
|
726
|
+
const body = error.body;
|
|
727
|
+
if (!body || typeof body !== "object" || Array.isArray(body)) {
|
|
728
|
+
return null;
|
|
729
|
+
}
|
|
730
|
+
const maybeShortfall = body["shortfallCredits"];
|
|
731
|
+
if (typeof maybeShortfall !== "number" || maybeShortfall <= 0) {
|
|
732
|
+
return null;
|
|
733
|
+
}
|
|
734
|
+
return { shortfallCredits: maybeShortfall };
|
|
735
|
+
}
|
|
736
|
+
extractErrorMessage(body) {
|
|
737
|
+
if (typeof body === "string") {
|
|
738
|
+
return body;
|
|
739
|
+
}
|
|
740
|
+
if (isJsonObject(body) && typeof body.error === "string") {
|
|
741
|
+
return body.error;
|
|
742
|
+
}
|
|
743
|
+
if (isJsonObject(body) && typeof body.message === "string") {
|
|
744
|
+
return body.message;
|
|
745
|
+
}
|
|
746
|
+
return void 0;
|
|
747
|
+
}
|
|
748
|
+
shouldAutoTopUpHistory(payload, error) {
|
|
749
|
+
if (!this.historyAutoTopUp || payload.historyTtlSeconds === void 0) {
|
|
750
|
+
return false;
|
|
751
|
+
}
|
|
752
|
+
if (!(error instanceof RegistryBrokerError)) {
|
|
753
|
+
return false;
|
|
754
|
+
}
|
|
755
|
+
if (error.status !== 402) {
|
|
756
|
+
return false;
|
|
757
|
+
}
|
|
758
|
+
const message = this.extractErrorMessage(error.body);
|
|
759
|
+
if (!message) {
|
|
760
|
+
return true;
|
|
761
|
+
}
|
|
762
|
+
const normalised = message.toLowerCase();
|
|
763
|
+
return normalised.includes("history") || normalised.includes("chat history");
|
|
764
|
+
}
|
|
765
|
+
async executeHistoryAutoTopUp(reason) {
|
|
766
|
+
if (!this.historyAutoTopUp) {
|
|
767
|
+
return;
|
|
768
|
+
}
|
|
769
|
+
const hbarAmount = this.historyAutoTopUp.hbarAmount && this.historyAutoTopUp.hbarAmount > 0 ? this.historyAutoTopUp.hbarAmount : DEFAULT_HISTORY_TOP_UP_HBAR;
|
|
770
|
+
await this.purchaseCreditsWithHbar({
|
|
771
|
+
accountId: this.historyAutoTopUp.accountId,
|
|
772
|
+
privateKey: this.historyAutoTopUp.privateKey,
|
|
773
|
+
hbarAmount,
|
|
774
|
+
memo: this.historyAutoTopUp.memo ?? "registry-broker-client:chat-history-topup",
|
|
775
|
+
metadata: {
|
|
776
|
+
purpose: "chat-history",
|
|
777
|
+
reason
|
|
778
|
+
}
|
|
779
|
+
});
|
|
780
|
+
}
|
|
781
|
+
initializeEncryptionBootstrap(options) {
|
|
782
|
+
return this.bootstrapEncryptionOptions(options).then(() => void 0);
|
|
783
|
+
}
|
|
784
|
+
bootstrapEncryptionOptions(options) {
|
|
785
|
+
return bootstrapEncryptionOptions(this, options);
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
const isPendingRegisterAgentResponse = (response) => response.status === "pending";
|
|
789
|
+
const isPartialRegisterAgentResponse = (response) => response.status === "partial" && response.success === false;
|
|
790
|
+
const isSuccessRegisterAgentResponse = (response) => response.success === true && response.status !== "pending";
|
|
791
|
+
export {
|
|
792
|
+
RegistryBrokerClient,
|
|
793
|
+
isPartialRegisterAgentResponse,
|
|
794
|
+
isPendingRegisterAgentResponse,
|
|
795
|
+
isSuccessRegisterAgentResponse
|
|
249
796
|
};
|
|
250
797
|
//# sourceMappingURL=standards-sdk.es131.js.map
|