@hashgraphonline/standards-agent-kit 0.2.159 → 0.2.161
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/builders/inscriber/inscriber-builder.d.ts +4 -3
- package/dist/cjs/standards-agent-kit.cjs +1 -1
- package/dist/cjs/standards-agent-kit.cjs.map +1 -1
- package/dist/es/builders/inscriber/inscriber-builder.d.ts +4 -3
- package/dist/es/standards-agent-kit.es48.js +7 -3
- package/dist/es/standards-agent-kit.es48.js.map +1 -1
- package/dist/es/standards-agent-kit.es49.js +3 -7
- package/dist/es/standards-agent-kit.es49.js.map +1 -1
- package/dist/es/standards-agent-kit.es6.js +1 -1
- package/dist/es/standards-agent-kit.es7.js +1 -1
- package/dist/es/standards-agent-kit.es8.js +33 -20
- package/dist/es/standards-agent-kit.es8.js.map +1 -1
- package/dist/es/standards-agent-kit.es9.js +1 -1
- package/dist/umd/builders/inscriber/inscriber-builder.d.ts +4 -3
- package/dist/umd/standards-agent-kit.umd.js +1 -1
- package/dist/umd/standards-agent-kit.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/builders/inscriber/inscriber-builder.ts +54 -27
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hashgraphonline/standards-agent-kit",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.161",
|
|
4
4
|
"description": "A modular SDK for building on-chain autonomous agents using Hashgraph Online Standards, including HCS-10 for agent discovery and communication.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/cjs/standards-agent-kit.cjs",
|
|
@@ -12,7 +12,11 @@ import {
|
|
|
12
12
|
NetworkType,
|
|
13
13
|
getTopicId,
|
|
14
14
|
} from '@hashgraphonline/standards-sdk';
|
|
15
|
-
import {
|
|
15
|
+
import {
|
|
16
|
+
InscriptionSDK,
|
|
17
|
+
type InscriptionResult,
|
|
18
|
+
type RegistrationProgressData,
|
|
19
|
+
} from '@kiloscribe/inscription-sdk';
|
|
16
20
|
import type { AgentOperationalMode } from 'hedera-agent-kit';
|
|
17
21
|
|
|
18
22
|
/**
|
|
@@ -41,8 +45,15 @@ export interface CompletedInscriptionResponse {
|
|
|
41
45
|
/**
|
|
42
46
|
* Builder for Inscription operations
|
|
43
47
|
*/
|
|
48
|
+
type InscriptionSDKInstance = InstanceType<typeof InscriptionSDK>;
|
|
49
|
+
type InscriptionSDKAuthParams = Parameters<
|
|
50
|
+
typeof InscriptionSDK.createWithAuth
|
|
51
|
+
>[0];
|
|
52
|
+
type ClientAuthConfig = Extract<InscriptionSDKAuthParams, { type: 'client' }>;
|
|
53
|
+
type ServerAuthConfig = Extract<InscriptionSDKAuthParams, { type: 'server' }>;
|
|
54
|
+
|
|
44
55
|
export class InscriberBuilder extends BaseServiceBuilder {
|
|
45
|
-
protected inscriptionSDK?:
|
|
56
|
+
protected inscriptionSDK?: InscriptionSDKInstance;
|
|
46
57
|
private static signerProvider?: () =>
|
|
47
58
|
| Promise<DAppSigner | null>
|
|
48
59
|
| DAppSigner
|
|
@@ -129,40 +140,48 @@ export class InscriberBuilder extends BaseServiceBuilder {
|
|
|
129
140
|
*/
|
|
130
141
|
protected async getInscriptionSDK(
|
|
131
142
|
_options: InscriptionOptions
|
|
132
|
-
): Promise<
|
|
143
|
+
): Promise<InscriptionSDKInstance | null> {
|
|
133
144
|
if (this.inscriptionSDK) {
|
|
134
145
|
return this.inscriptionSDK;
|
|
135
146
|
}
|
|
136
147
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
const accountId = this.hederaKit.signer.getAccountId().toString();
|
|
148
|
+
const network = this.hederaKit.client.network;
|
|
149
|
+
const networkType: 'mainnet' | 'testnet' = network
|
|
150
|
+
.toString()
|
|
151
|
+
.includes('mainnet')
|
|
152
|
+
? 'mainnet'
|
|
153
|
+
: 'testnet';
|
|
154
|
+
const accountId = this.hederaKit.signer.getAccountId().toString();
|
|
145
155
|
|
|
146
|
-
|
|
156
|
+
try {
|
|
157
|
+
const privateKey = this.hederaKit.signer?.getOperatorPrivateKey();
|
|
158
|
+
if (privateKey) {
|
|
147
159
|
this.inscriptionSDK = await InscriptionSDK.createWithAuth({
|
|
148
|
-
type: '
|
|
160
|
+
type: 'server',
|
|
149
161
|
accountId,
|
|
150
|
-
|
|
162
|
+
privateKey:
|
|
163
|
+
privateKey.toStringRaw() as ServerAuthConfig['privateKey'],
|
|
151
164
|
network: networkType,
|
|
152
165
|
});
|
|
153
|
-
} else {
|
|
154
|
-
const privateKey = this.hederaKit.signer?.getOperatorPrivateKey();
|
|
155
|
-
if (privateKey) {
|
|
156
|
-
this.inscriptionSDK = await InscriptionSDK.createWithAuth({
|
|
157
|
-
type: 'server',
|
|
158
|
-
accountId,
|
|
159
|
-
privateKey: privateKey.toStringRaw(),
|
|
160
|
-
network: networkType,
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
166
|
}
|
|
164
167
|
} catch (error) {
|
|
165
168
|
this.logger.warn('Failed to create InscriptionSDK with auth', error);
|
|
169
|
+
this.inscriptionSDK = undefined;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (!this.inscriptionSDK) {
|
|
173
|
+
try {
|
|
174
|
+
this.inscriptionSDK = new InscriptionSDK({
|
|
175
|
+
apiKey: 'public-access',
|
|
176
|
+
network: networkType,
|
|
177
|
+
connectionMode: 'http',
|
|
178
|
+
});
|
|
179
|
+
} catch (fallbackError) {
|
|
180
|
+
this.logger.warn(
|
|
181
|
+
'Failed to create InscriptionSDK fallback instance',
|
|
182
|
+
fallbackError
|
|
183
|
+
);
|
|
184
|
+
}
|
|
166
185
|
}
|
|
167
186
|
|
|
168
187
|
return this.inscriptionSDK || null;
|
|
@@ -358,14 +377,18 @@ export class InscriberBuilder extends BaseServiceBuilder {
|
|
|
358
377
|
const intervalMs =
|
|
359
378
|
(options as { waitIntervalMs?: number }).waitIntervalMs ?? 5000;
|
|
360
379
|
|
|
380
|
+
const pollId = startResponse.tx_id || transactionId;
|
|
361
381
|
const sdk = await this.getInscriptionSDK(options);
|
|
362
382
|
if (sdk) {
|
|
363
383
|
const retrieved: RetrievedInscriptionResult =
|
|
364
384
|
await sdk.waitForInscription(
|
|
365
|
-
|
|
385
|
+
pollId,
|
|
366
386
|
maxAttempts,
|
|
367
387
|
intervalMs,
|
|
368
|
-
true
|
|
388
|
+
true,
|
|
389
|
+
(progress: RegistrationProgressData) => {
|
|
390
|
+
this.logger.info('checking inscription', progress);
|
|
391
|
+
}
|
|
369
392
|
);
|
|
370
393
|
const topicIdFromInscription: string | undefined = getTopicId(
|
|
371
394
|
retrieved as unknown
|
|
@@ -382,7 +405,11 @@ export class InscriberBuilder extends BaseServiceBuilder {
|
|
|
382
405
|
},
|
|
383
406
|
inscription: retrieved,
|
|
384
407
|
} as unknown as InscriptionResponse;
|
|
385
|
-
this.logger.debug(
|
|
408
|
+
this.logger.debug(
|
|
409
|
+
'retrieved inscription',
|
|
410
|
+
resultConfirmed,
|
|
411
|
+
retrieved
|
|
412
|
+
);
|
|
386
413
|
return resultConfirmed;
|
|
387
414
|
}
|
|
388
415
|
}
|