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