@hashgraphonline/standards-agent-kit 0.2.144 → 0.2.146
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 +15 -1
- 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 +2 -1
- package/dist/es/builders/inscriber/inscriber-builder.d.ts +15 -1
- 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.es51.js +1 -1
- package/dist/es/standards-agent-kit.es51.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 -15
- package/dist/es/standards-agent-kit.es8.js.map +1 -1
- package/dist/es/standards-agent-kit.es9.js +1 -1
- package/dist/es/utils/inscription-utils.d.ts +2 -1
- package/dist/umd/builders/inscriber/inscriber-builder.d.ts +15 -1
- package/dist/umd/standards-agent-kit.umd.js +1 -1
- package/dist/umd/standards-agent-kit.umd.js.map +1 -1
- package/dist/umd/utils/inscription-utils.d.ts +2 -1
- package/package.json +1 -1
- package/src/builders/inscriber/inscriber-builder.ts +121 -50
- package/src/utils/inscription-utils.ts +5 -2
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { RetrievedInscriptionResult } from '@kiloscribe/inscription-sdk';
|
|
1
2
|
export type NetworkType = 'mainnet' | 'testnet';
|
|
2
3
|
export interface TopicIds {
|
|
3
4
|
jsonTopicId?: string;
|
|
@@ -8,7 +9,7 @@ export interface TopicIds {
|
|
|
8
9
|
* - Prefers jsonTopicId when present (for CDN linking)
|
|
9
10
|
* - Collects topic_id/topicId from either inscription or result
|
|
10
11
|
*/
|
|
11
|
-
export declare function extractTopicIds(inscription
|
|
12
|
+
export declare function extractTopicIds(inscription?: RetrievedInscriptionResult, result?: unknown): TopicIds;
|
|
12
13
|
/**
|
|
13
14
|
* Build HRL/CDN URLs from extracted topic ids.
|
|
14
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.146",
|
|
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,7 @@ import {
|
|
|
12
12
|
NetworkType,
|
|
13
13
|
getTopicId,
|
|
14
14
|
} from '@hashgraphonline/standards-sdk';
|
|
15
|
-
import { InscriptionSDK } from '@kiloscribe/inscription-sdk';
|
|
15
|
+
import { InscriptionResult, InscriptionSDK } from '@kiloscribe/inscription-sdk';
|
|
16
16
|
import type { AgentOperationalMode } from 'hedera-agent-kit';
|
|
17
17
|
|
|
18
18
|
/**
|
|
@@ -23,23 +23,39 @@ interface DAppSigner {
|
|
|
23
23
|
[key: string]: unknown;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
export interface PendingInscriptionResponse {
|
|
27
|
+
transactionBytes: string;
|
|
28
|
+
tx_id?: string;
|
|
29
|
+
topic_id?: string;
|
|
30
|
+
status?: string;
|
|
31
|
+
completed?: boolean;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface CompletedInscriptionResponse {
|
|
35
|
+
confirmed?: boolean;
|
|
36
|
+
result?: InscriptionResult;
|
|
37
|
+
inscription?: RetrievedInscriptionResult;
|
|
38
|
+
jsonTopicId?: string;
|
|
39
|
+
network?: string;
|
|
40
|
+
}
|
|
26
41
|
/**
|
|
27
42
|
* Builder for Inscription operations
|
|
28
43
|
*/
|
|
29
44
|
export class InscriberBuilder extends BaseServiceBuilder {
|
|
30
45
|
protected inscriptionSDK?: InscriptionSDK;
|
|
31
|
-
private static signerProvider?: () =>
|
|
32
|
-
|
|
46
|
+
private static signerProvider?: () =>
|
|
47
|
+
| Promise<DAppSigner | null>
|
|
48
|
+
| DAppSigner
|
|
49
|
+
| null;
|
|
50
|
+
private static walletInfoResolver?: () =>
|
|
51
|
+
| Promise<{ accountId: string; network: 'mainnet' | 'testnet' } | null>
|
|
52
|
+
| { accountId: string; network: 'mainnet' | 'testnet' }
|
|
53
|
+
| null;
|
|
54
|
+
|
|
33
55
|
private static startInscriptionDelegate?: (
|
|
34
56
|
request: Record<string, unknown>,
|
|
35
57
|
network: 'mainnet' | 'testnet'
|
|
36
|
-
) => Promise<
|
|
37
|
-
transactionBytes: string;
|
|
38
|
-
tx_id?: string;
|
|
39
|
-
topic_id?: string;
|
|
40
|
-
status?: string;
|
|
41
|
-
completed?: boolean;
|
|
42
|
-
}>;
|
|
58
|
+
) => Promise<PendingInscriptionResponse | CompletedInscriptionResponse>;
|
|
43
59
|
private static walletExecutor?: (
|
|
44
60
|
base64: string,
|
|
45
61
|
network: 'mainnet' | 'testnet'
|
|
@@ -62,7 +78,10 @@ export class InscriberBuilder extends BaseServiceBuilder {
|
|
|
62
78
|
}
|
|
63
79
|
|
|
64
80
|
static setWalletInfoResolver(
|
|
65
|
-
resolver: () =>
|
|
81
|
+
resolver: () =>
|
|
82
|
+
| Promise<{ accountId: string; network: 'mainnet' | 'testnet' } | null>
|
|
83
|
+
| { accountId: string; network: 'mainnet' | 'testnet' }
|
|
84
|
+
| null
|
|
66
85
|
): void {
|
|
67
86
|
InscriberBuilder.walletInfoResolver = resolver;
|
|
68
87
|
}
|
|
@@ -71,13 +90,22 @@ export class InscriberBuilder extends BaseServiceBuilder {
|
|
|
71
90
|
delegate: (
|
|
72
91
|
request: Record<string, unknown>,
|
|
73
92
|
network: 'mainnet' | 'testnet'
|
|
74
|
-
) => Promise<{
|
|
93
|
+
) => Promise<{
|
|
94
|
+
transactionBytes: string;
|
|
95
|
+
tx_id?: string;
|
|
96
|
+
topic_id?: string;
|
|
97
|
+
status?: string;
|
|
98
|
+
completed?: boolean;
|
|
99
|
+
}>
|
|
75
100
|
): void {
|
|
76
101
|
InscriberBuilder.startInscriptionDelegate = delegate;
|
|
77
102
|
}
|
|
78
103
|
|
|
79
104
|
static setWalletExecutor(
|
|
80
|
-
executor: (
|
|
105
|
+
executor: (
|
|
106
|
+
base64: string,
|
|
107
|
+
network: 'mainnet' | 'testnet'
|
|
108
|
+
) => Promise<{ transactionId: string }>
|
|
81
109
|
): void {
|
|
82
110
|
InscriberBuilder.walletExecutor = executor;
|
|
83
111
|
}
|
|
@@ -94,7 +122,7 @@ export class InscriberBuilder extends BaseServiceBuilder {
|
|
|
94
122
|
if (!provider) return null;
|
|
95
123
|
try {
|
|
96
124
|
const maybe = provider();
|
|
97
|
-
return
|
|
125
|
+
return maybe && typeof (maybe as Promise<unknown>).then === 'function'
|
|
98
126
|
? await (maybe as Promise<DAppSigner | null>)
|
|
99
127
|
: (maybe as DAppSigner | null);
|
|
100
128
|
} catch {
|
|
@@ -162,13 +190,7 @@ export class InscriberBuilder extends BaseServiceBuilder {
|
|
|
162
190
|
}
|
|
163
191
|
|
|
164
192
|
type WalletInfo = { accountId: string; network: 'mainnet' | 'testnet' };
|
|
165
|
-
|
|
166
|
-
transactionBytes: string;
|
|
167
|
-
tx_id?: string;
|
|
168
|
-
topic_id?: string;
|
|
169
|
-
status?: string;
|
|
170
|
-
completed?: boolean;
|
|
171
|
-
};
|
|
193
|
+
|
|
172
194
|
type WalletExecutorResponse = { transactionId: string };
|
|
173
195
|
|
|
174
196
|
const infoMaybe: WalletInfo | null = InscriberBuilder.walletInfoResolver
|
|
@@ -176,7 +198,9 @@ export class InscriberBuilder extends BaseServiceBuilder {
|
|
|
176
198
|
: null;
|
|
177
199
|
|
|
178
200
|
if (InscriberBuilder.preferWalletOnly && !infoMaybe) {
|
|
179
|
-
const err = new Error(
|
|
201
|
+
const err = new Error(
|
|
202
|
+
'Wallet unavailable: connect a wallet or switch to autonomous mode'
|
|
203
|
+
);
|
|
180
204
|
(err as unknown as { code: string }).code = 'wallet_unavailable';
|
|
181
205
|
throw err;
|
|
182
206
|
}
|
|
@@ -193,7 +217,10 @@ export class InscriberBuilder extends BaseServiceBuilder {
|
|
|
193
217
|
fileStandard?: string;
|
|
194
218
|
chunkSize?: number;
|
|
195
219
|
jsonFileURL?: string;
|
|
196
|
-
metadata?: Record<string, unknown> & {
|
|
220
|
+
metadata?: Record<string, unknown> & {
|
|
221
|
+
creator?: string;
|
|
222
|
+
description?: string;
|
|
223
|
+
};
|
|
197
224
|
};
|
|
198
225
|
const ext = options as InscriptionOptionsExt;
|
|
199
226
|
|
|
@@ -204,7 +231,8 @@ export class InscriberBuilder extends BaseServiceBuilder {
|
|
|
204
231
|
mode: options.mode || 'file',
|
|
205
232
|
};
|
|
206
233
|
if (typeof ext.fileStandard !== 'undefined') {
|
|
207
|
-
(baseRequest as { fileStandard?: string }).fileStandard =
|
|
234
|
+
(baseRequest as { fileStandard?: string }).fileStandard =
|
|
235
|
+
ext.fileStandard;
|
|
208
236
|
}
|
|
209
237
|
if (typeof ext.chunkSize !== 'undefined') {
|
|
210
238
|
(baseRequest as { chunkSize?: number }).chunkSize = ext.chunkSize;
|
|
@@ -216,7 +244,10 @@ export class InscriberBuilder extends BaseServiceBuilder {
|
|
|
216
244
|
request = { ...baseRequest, file: { type: 'url', url: input.url } };
|
|
217
245
|
break;
|
|
218
246
|
case 'file':
|
|
219
|
-
request = {
|
|
247
|
+
request = {
|
|
248
|
+
...baseRequest,
|
|
249
|
+
file: { type: 'path', path: input.path },
|
|
250
|
+
};
|
|
220
251
|
break;
|
|
221
252
|
case 'buffer':
|
|
222
253
|
request = {
|
|
@@ -233,48 +264,85 @@ export class InscriberBuilder extends BaseServiceBuilder {
|
|
|
233
264
|
|
|
234
265
|
if (options.mode === 'hashinal') {
|
|
235
266
|
(request as { metadataObject?: unknown }).metadataObject = ext.metadata;
|
|
236
|
-
(request as { creator?: string }).creator =
|
|
237
|
-
|
|
267
|
+
(request as { creator?: string }).creator =
|
|
268
|
+
ext.metadata?.creator || holderId;
|
|
269
|
+
(request as { description?: string }).description =
|
|
270
|
+
ext.metadata?.description;
|
|
238
271
|
if (typeof ext.jsonFileURL === 'string' && ext.jsonFileURL.length > 0) {
|
|
239
272
|
(request as { jsonFileURL?: string }).jsonFileURL = ext.jsonFileURL;
|
|
240
273
|
}
|
|
241
274
|
}
|
|
242
275
|
|
|
243
|
-
const start
|
|
276
|
+
const start = await InscriberBuilder.startInscriptionDelegate(
|
|
244
277
|
request,
|
|
245
278
|
network
|
|
246
279
|
);
|
|
247
|
-
|
|
280
|
+
|
|
281
|
+
const completedStart = start as CompletedInscriptionResponse;
|
|
282
|
+
const isCompletedResponse =
|
|
283
|
+
completedStart?.inscription && completedStart?.confirmed;
|
|
284
|
+
|
|
285
|
+
if (isCompletedResponse) {
|
|
286
|
+
const completed = start as {
|
|
287
|
+
confirmed?: boolean;
|
|
288
|
+
result?: unknown;
|
|
289
|
+
inscription?: unknown;
|
|
290
|
+
};
|
|
291
|
+
return {
|
|
292
|
+
quote: false,
|
|
293
|
+
confirmed: completed.confirmed === true,
|
|
294
|
+
result: completed.result as InscriptionResult,
|
|
295
|
+
inscription: completed.inscription,
|
|
296
|
+
} as unknown as InscriptionResponse;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
const startResponse = start as {
|
|
300
|
+
transactionBytes: string;
|
|
301
|
+
tx_id?: string;
|
|
302
|
+
topic_id?: string;
|
|
303
|
+
status?: string;
|
|
304
|
+
completed?: boolean;
|
|
305
|
+
};
|
|
306
|
+
|
|
307
|
+
if (!startResponse || !startResponse.transactionBytes) {
|
|
248
308
|
throw new Error('Failed to start inscription (no transaction bytes)');
|
|
249
309
|
}
|
|
250
310
|
|
|
251
|
-
const exec: WalletExecutorResponse =
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
311
|
+
const exec: WalletExecutorResponse =
|
|
312
|
+
await InscriberBuilder.walletExecutor(
|
|
313
|
+
startResponse.transactionBytes,
|
|
314
|
+
network
|
|
315
|
+
);
|
|
255
316
|
const transactionId = exec?.transactionId || '';
|
|
256
317
|
|
|
257
|
-
const shouldWait = options.quoteOnly
|
|
318
|
+
const shouldWait = options.quoteOnly
|
|
319
|
+
? false
|
|
320
|
+
: options.waitForConfirmation ?? true;
|
|
258
321
|
if (shouldWait) {
|
|
259
|
-
const maxAttempts =
|
|
260
|
-
|
|
322
|
+
const maxAttempts =
|
|
323
|
+
(options as { waitMaxAttempts?: number }).waitMaxAttempts ?? 60;
|
|
324
|
+
const intervalMs =
|
|
325
|
+
(options as { waitIntervalMs?: number }).waitIntervalMs ?? 5000;
|
|
261
326
|
|
|
262
327
|
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
263
328
|
try {
|
|
264
|
-
const retrieved: RetrievedInscriptionResult =
|
|
265
|
-
transactionId,
|
|
266
|
-
|
|
329
|
+
const retrieved: RetrievedInscriptionResult =
|
|
330
|
+
await this.retrieveInscription(transactionId, options);
|
|
331
|
+
const topicIdFromInscription: string | undefined = getTopicId(
|
|
332
|
+
retrieved as unknown
|
|
267
333
|
);
|
|
268
|
-
const
|
|
269
|
-
|
|
270
|
-
const status: string | undefined = (
|
|
334
|
+
const topicId: string | undefined =
|
|
335
|
+
topicIdFromInscription ?? startResponse.topic_id;
|
|
336
|
+
const status: string | undefined = (
|
|
337
|
+
retrieved as { status?: string }
|
|
338
|
+
).status;
|
|
271
339
|
const isDone = status === 'completed' || !!topicId;
|
|
272
340
|
if (isDone) {
|
|
273
341
|
const resultConfirmed: InscriptionResponse = {
|
|
274
342
|
quote: false,
|
|
275
343
|
confirmed: true,
|
|
276
344
|
result: {
|
|
277
|
-
jobId:
|
|
345
|
+
jobId: startResponse.tx_id || '',
|
|
278
346
|
transactionId,
|
|
279
347
|
topicId,
|
|
280
348
|
},
|
|
@@ -282,8 +350,7 @@ export class InscriberBuilder extends BaseServiceBuilder {
|
|
|
282
350
|
} as unknown as InscriptionResponse;
|
|
283
351
|
return resultConfirmed;
|
|
284
352
|
}
|
|
285
|
-
} catch {
|
|
286
|
-
}
|
|
353
|
+
} catch {}
|
|
287
354
|
await new Promise((resolve) => setTimeout(resolve, intervalMs));
|
|
288
355
|
}
|
|
289
356
|
}
|
|
@@ -292,18 +359,22 @@ export class InscriberBuilder extends BaseServiceBuilder {
|
|
|
292
359
|
quote: false,
|
|
293
360
|
confirmed: false,
|
|
294
361
|
result: {
|
|
295
|
-
jobId:
|
|
362
|
+
jobId: startResponse.tx_id || '',
|
|
296
363
|
transactionId,
|
|
297
|
-
status:
|
|
298
|
-
completed:
|
|
364
|
+
status: startResponse.status,
|
|
365
|
+
completed: startResponse.completed,
|
|
299
366
|
},
|
|
300
|
-
inscription:
|
|
367
|
+
inscription: startResponse.topic_id
|
|
368
|
+
? { topic_id: startResponse.topic_id }
|
|
369
|
+
: undefined,
|
|
301
370
|
} as unknown as InscriptionResponse;
|
|
302
371
|
return partial;
|
|
303
372
|
}
|
|
304
373
|
|
|
305
374
|
if (InscriberBuilder.preferWalletOnly) {
|
|
306
|
-
const err = new Error(
|
|
375
|
+
const err = new Error(
|
|
376
|
+
'Wallet unavailable: connect a wallet or switch to autonomous mode'
|
|
377
|
+
);
|
|
307
378
|
(err as unknown as { code: string }).code = 'wallet_unavailable';
|
|
308
379
|
throw err;
|
|
309
380
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { RetrievedInscriptionResult } from '@kiloscribe/inscription-sdk';
|
|
2
|
+
|
|
1
3
|
export type NetworkType = 'mainnet' | 'testnet';
|
|
2
4
|
|
|
3
5
|
export interface TopicIds {
|
|
@@ -17,10 +19,11 @@ function getStringProp(obj: unknown, key: string): string | undefined {
|
|
|
17
19
|
* - Collects topic_id/topicId from either inscription or result
|
|
18
20
|
*/
|
|
19
21
|
export function extractTopicIds(
|
|
20
|
-
inscription
|
|
22
|
+
inscription?: RetrievedInscriptionResult,
|
|
21
23
|
result?: unknown
|
|
22
24
|
): TopicIds {
|
|
23
|
-
const jsonTopicId =
|
|
25
|
+
const jsonTopicId =
|
|
26
|
+
inscription?.jsonTopicId || getStringProp(inscription, 'json_topic_id');
|
|
24
27
|
|
|
25
28
|
const imageTopicId =
|
|
26
29
|
getStringProp(inscription, 'topic_id') ||
|