@hashgraphonline/standards-agent-kit 0.2.160 → 0.2.162
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 +6 -4
- package/dist/cjs/standards-agent-kit.cjs +1 -1
- package/dist/cjs/standards-agent-kit.cjs.map +1 -1
- package/dist/cjs/utils/inscription-utils.d.ts +1 -1
- package/dist/es/builders/inscriber/inscriber-builder.d.ts +6 -4
- package/dist/es/standards-agent-kit.es51.js +1 -1
- package/dist/es/standards-agent-kit.es51.js.map +1 -1
- package/dist/es/standards-agent-kit.es8.js +86 -35
- package/dist/es/standards-agent-kit.es8.js.map +1 -1
- package/dist/es/utils/inscription-utils.d.ts +1 -1
- package/dist/umd/builders/inscriber/inscriber-builder.d.ts +6 -4
- package/dist/umd/standards-agent-kit.umd.js +30 -30
- package/dist/umd/standards-agent-kit.umd.js.map +1 -1
- package/dist/umd/utils/inscription-utils.d.ts +1 -1
- package/package.json +1 -1
- package/src/builders/inscriber/inscriber-builder.ts +109 -46
- package/src/utils/inscription-utils.ts +3 -2
|
@@ -9,7 +9,7 @@ export interface TopicIds {
|
|
|
9
9
|
* - Prefers jsonTopicId when present (for CDN linking)
|
|
10
10
|
* - Collects topic_id/topicId from either inscription or result
|
|
11
11
|
*/
|
|
12
|
-
export declare function extractTopicIds(inscription: RetrievedInscriptionResult, result?: unknown): TopicIds;
|
|
12
|
+
export declare function extractTopicIds(inscription: RetrievedInscriptionResult | undefined, result?: unknown): TopicIds;
|
|
13
13
|
/**
|
|
14
14
|
* Build HRL/CDN URLs from extracted topic ids.
|
|
15
15
|
* - HRL prefers jsonTopicId, falls back to topicId
|
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.162",
|
|
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",
|
|
@@ -11,8 +11,13 @@ import {
|
|
|
11
11
|
HederaClientConfig,
|
|
12
12
|
NetworkType,
|
|
13
13
|
getTopicId,
|
|
14
|
+
Logger,
|
|
14
15
|
} from '@hashgraphonline/standards-sdk';
|
|
15
|
-
import
|
|
16
|
+
import {
|
|
17
|
+
InscriptionSDK,
|
|
18
|
+
type InscriptionResult,
|
|
19
|
+
type RegistrationProgressData,
|
|
20
|
+
} from '@kiloscribe/inscription-sdk';
|
|
16
21
|
import type { AgentOperationalMode } from 'hedera-agent-kit';
|
|
17
22
|
|
|
18
23
|
/**
|
|
@@ -41,24 +46,32 @@ export interface CompletedInscriptionResponse {
|
|
|
41
46
|
/**
|
|
42
47
|
* Builder for Inscription operations
|
|
43
48
|
*/
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
'@kiloscribe/inscription-sdk'
|
|
49
|
-
)) as typeof import('@kiloscribe/inscription-sdk');
|
|
50
|
-
}
|
|
51
|
-
return cachedInscriptionSdkModule;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
type InscriptionSDKType = Awaited<
|
|
55
|
-
ReturnType<typeof loadInscriptionSdkModule>
|
|
56
|
-
>['InscriptionSDK'];
|
|
57
|
-
type InscriptionSDKInstance = InstanceType<InscriptionSDKType>;
|
|
58
|
-
type InscriptionSDKAuthParams = Parameters<InscriptionSDKType['createWithAuth']>[0];
|
|
49
|
+
type InscriptionSDKInstance = InstanceType<typeof InscriptionSDK>;
|
|
50
|
+
type InscriptionSDKAuthParams = Parameters<
|
|
51
|
+
typeof InscriptionSDK.createWithAuth
|
|
52
|
+
>[0];
|
|
59
53
|
type ClientAuthConfig = Extract<InscriptionSDKAuthParams, { type: 'client' }>;
|
|
60
54
|
type ServerAuthConfig = Extract<InscriptionSDKAuthParams, { type: 'server' }>;
|
|
61
55
|
|
|
56
|
+
export const toDashedTransactionId = (transactionId: string): string => {
|
|
57
|
+
if (transactionId.includes('-')) {
|
|
58
|
+
return transactionId;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const [account, timePart] = transactionId.split('@');
|
|
62
|
+
if (!account || !timePart) {
|
|
63
|
+
return transactionId;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const [secondsPart, nanosPart] = timePart.split('.');
|
|
67
|
+
if (!secondsPart) {
|
|
68
|
+
return transactionId;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const normalizedNanos = (nanosPart ?? '0').padEnd(9, '0').slice(0, 9);
|
|
72
|
+
return `${account}-${secondsPart}-${normalizedNanos}`;
|
|
73
|
+
};
|
|
74
|
+
|
|
62
75
|
export class InscriberBuilder extends BaseServiceBuilder {
|
|
63
76
|
protected inscriptionSDK?: InscriptionSDKInstance;
|
|
64
77
|
private static signerProvider?: () =>
|
|
@@ -153,32 +166,30 @@ export class InscriberBuilder extends BaseServiceBuilder {
|
|
|
153
166
|
}
|
|
154
167
|
|
|
155
168
|
const network = this.hederaKit.client.network;
|
|
156
|
-
const networkType: 'mainnet' | 'testnet' = network
|
|
169
|
+
const networkType: 'mainnet' | 'testnet' = network
|
|
170
|
+
.toString()
|
|
171
|
+
.includes('mainnet')
|
|
157
172
|
? 'mainnet'
|
|
158
173
|
: 'testnet';
|
|
159
174
|
const accountId = this.hederaKit.signer.getAccountId().toString();
|
|
160
175
|
|
|
161
176
|
try {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
177
|
+
this.logger.info('Attempting InscriptionSDK.createWithAuth', {
|
|
178
|
+
accountId,
|
|
179
|
+
network: networkType,
|
|
180
|
+
});
|
|
181
|
+
const privateKey = this.hederaKit.signer?.getOperatorPrivateKey();
|
|
182
|
+
if (privateKey) {
|
|
166
183
|
this.inscriptionSDK = await InscriptionSDK.createWithAuth({
|
|
167
|
-
type: '
|
|
184
|
+
type: 'server',
|
|
168
185
|
accountId,
|
|
169
|
-
|
|
186
|
+
privateKey:
|
|
187
|
+
privateKey.toStringRaw() as ServerAuthConfig['privateKey'],
|
|
188
|
+
network: networkType,
|
|
189
|
+
});
|
|
190
|
+
this.logger.info('Created InscriptionSDK via createWithAuth', {
|
|
170
191
|
network: networkType,
|
|
171
192
|
});
|
|
172
|
-
} else {
|
|
173
|
-
const privateKey = this.hederaKit.signer?.getOperatorPrivateKey();
|
|
174
|
-
if (privateKey) {
|
|
175
|
-
this.inscriptionSDK = await InscriptionSDK.createWithAuth({
|
|
176
|
-
type: 'server',
|
|
177
|
-
accountId,
|
|
178
|
-
privateKey: privateKey.toStringRaw() as ServerAuthConfig['privateKey'],
|
|
179
|
-
network: networkType,
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
193
|
}
|
|
183
194
|
} catch (error) {
|
|
184
195
|
this.logger.warn('Failed to create InscriptionSDK with auth', error);
|
|
@@ -187,21 +198,29 @@ export class InscriberBuilder extends BaseServiceBuilder {
|
|
|
187
198
|
|
|
188
199
|
if (!this.inscriptionSDK) {
|
|
189
200
|
try {
|
|
190
|
-
|
|
201
|
+
this.logger.info('Creating fallback InscriptionSDK instance', {
|
|
202
|
+
network: networkType,
|
|
203
|
+
});
|
|
191
204
|
this.inscriptionSDK = new InscriptionSDK({
|
|
192
205
|
apiKey: 'public-access',
|
|
193
206
|
network: networkType,
|
|
194
207
|
connectionMode: 'http',
|
|
195
208
|
});
|
|
209
|
+
this.logger.info('Created fallback InscriptionSDK instance', {
|
|
210
|
+
network: networkType,
|
|
211
|
+
});
|
|
212
|
+
return this.inscriptionSDK;
|
|
196
213
|
} catch (fallbackError) {
|
|
197
|
-
this.logger.
|
|
214
|
+
this.logger.error(
|
|
198
215
|
'Failed to create InscriptionSDK fallback instance',
|
|
199
216
|
fallbackError
|
|
200
217
|
);
|
|
201
218
|
}
|
|
202
219
|
}
|
|
203
220
|
|
|
204
|
-
|
|
221
|
+
this.logger.error('failed to setup sdk');
|
|
222
|
+
|
|
223
|
+
return null;
|
|
205
224
|
}
|
|
206
225
|
|
|
207
226
|
/**
|
|
@@ -343,6 +362,14 @@ export class InscriberBuilder extends BaseServiceBuilder {
|
|
|
343
362
|
network
|
|
344
363
|
);
|
|
345
364
|
|
|
365
|
+
this.logger.info('inscribeAuto start response', {
|
|
366
|
+
hasTransactionBytes:
|
|
367
|
+
typeof (start as { transactionBytes?: unknown }).transactionBytes ===
|
|
368
|
+
'string',
|
|
369
|
+
txId: (start as { tx_id?: unknown }).tx_id,
|
|
370
|
+
status: (start as { status?: unknown }).status,
|
|
371
|
+
});
|
|
372
|
+
|
|
346
373
|
const completedStart = start as CompletedInscriptionResponse;
|
|
347
374
|
const isCompletedResponse =
|
|
348
375
|
Boolean(completedStart?.inscription) && completedStart?.confirmed;
|
|
@@ -384,25 +411,57 @@ export class InscriberBuilder extends BaseServiceBuilder {
|
|
|
384
411
|
);
|
|
385
412
|
const transactionId = exec?.transactionId || '';
|
|
386
413
|
|
|
414
|
+
this.logger.info('inscribeAuto wallet execution', {
|
|
415
|
+
transactionId,
|
|
416
|
+
network,
|
|
417
|
+
});
|
|
418
|
+
|
|
387
419
|
const shouldWait = options.quoteOnly
|
|
388
420
|
? false
|
|
389
421
|
: options.waitForConfirmation ?? true;
|
|
422
|
+
const canonicalTransactionId = toDashedTransactionId(
|
|
423
|
+
startResponse.tx_id || transactionId
|
|
424
|
+
);
|
|
390
425
|
if (shouldWait) {
|
|
391
|
-
this.logger.debug('Will be retrieving inscription');
|
|
392
426
|
const maxAttempts =
|
|
393
427
|
(options as { waitMaxAttempts?: number }).waitMaxAttempts ?? 60;
|
|
394
428
|
const intervalMs =
|
|
395
429
|
(options as { waitIntervalMs?: number }).waitIntervalMs ?? 5000;
|
|
430
|
+
const pollId = canonicalTransactionId;
|
|
431
|
+
this.logger.debug('Will be retrieving inscription', pollId);
|
|
396
432
|
|
|
433
|
+
let retrieved: RetrievedInscriptionResult | null = null;
|
|
397
434
|
const sdk = await this.getInscriptionSDK(options);
|
|
435
|
+
|
|
436
|
+
console.log('got an SDK', sdk);
|
|
437
|
+
|
|
398
438
|
if (sdk) {
|
|
399
|
-
|
|
400
|
-
await sdk.waitForInscription(
|
|
401
|
-
|
|
439
|
+
try {
|
|
440
|
+
retrieved = await sdk.waitForInscription(
|
|
441
|
+
pollId,
|
|
402
442
|
maxAttempts,
|
|
403
443
|
intervalMs,
|
|
404
|
-
true
|
|
444
|
+
true,
|
|
445
|
+
(progress: RegistrationProgressData) => {
|
|
446
|
+
this.logger.debug('checking inscription', progress);
|
|
447
|
+
}
|
|
405
448
|
);
|
|
449
|
+
} catch (error) {
|
|
450
|
+
this.logger.warn('Primary inscription wait failed', {
|
|
451
|
+
pollId,
|
|
452
|
+
error: error instanceof Error ? error.message : String(error),
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
} else {
|
|
456
|
+
this.logger.warn(
|
|
457
|
+
'No inscription SDK available, using public client',
|
|
458
|
+
{
|
|
459
|
+
pollId,
|
|
460
|
+
}
|
|
461
|
+
);
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
if (retrieved) {
|
|
406
465
|
const topicIdFromInscription: string | undefined = getTopicId(
|
|
407
466
|
retrieved as unknown
|
|
408
467
|
);
|
|
@@ -412,13 +471,17 @@ export class InscriberBuilder extends BaseServiceBuilder {
|
|
|
412
471
|
quote: false,
|
|
413
472
|
confirmed: true,
|
|
414
473
|
result: {
|
|
415
|
-
jobId: startResponse.tx_id || '',
|
|
416
|
-
transactionId,
|
|
474
|
+
jobId: toDashedTransactionId(startResponse.tx_id || ''),
|
|
475
|
+
transactionId: canonicalTransactionId,
|
|
417
476
|
topicId,
|
|
418
477
|
},
|
|
419
478
|
inscription: retrieved,
|
|
420
479
|
} as unknown as InscriptionResponse;
|
|
421
|
-
this.logger.debug(
|
|
480
|
+
this.logger.debug(
|
|
481
|
+
'retrieved inscription confirmed',
|
|
482
|
+
resultConfirmed,
|
|
483
|
+
retrieved
|
|
484
|
+
);
|
|
422
485
|
return resultConfirmed;
|
|
423
486
|
}
|
|
424
487
|
}
|
|
@@ -427,8 +490,8 @@ export class InscriberBuilder extends BaseServiceBuilder {
|
|
|
427
490
|
quote: false,
|
|
428
491
|
confirmed: false,
|
|
429
492
|
result: {
|
|
430
|
-
jobId: startResponse.tx_id || '',
|
|
431
|
-
transactionId,
|
|
493
|
+
jobId: toDashedTransactionId(startResponse.tx_id || ''),
|
|
494
|
+
transactionId: canonicalTransactionId,
|
|
432
495
|
status: startResponse.status,
|
|
433
496
|
completed: startResponse.completed,
|
|
434
497
|
},
|
|
@@ -19,11 +19,12 @@ function getStringProp(obj: unknown, key: string): string | undefined {
|
|
|
19
19
|
* - Collects topic_id/topicId from either inscription or result
|
|
20
20
|
*/
|
|
21
21
|
export function extractTopicIds(
|
|
22
|
-
inscription: RetrievedInscriptionResult,
|
|
22
|
+
inscription: RetrievedInscriptionResult | undefined,
|
|
23
23
|
result?: unknown
|
|
24
24
|
): TopicIds {
|
|
25
25
|
const jsonTopicId =
|
|
26
|
-
inscription
|
|
26
|
+
(inscription as RetrievedInscriptionResult | undefined)?.jsonTopicId ||
|
|
27
|
+
getStringProp(inscription, 'json_topic_id');
|
|
27
28
|
|
|
28
29
|
const imageTopicId =
|
|
29
30
|
getStringProp(inscription, 'topic_id') ||
|