@hashgraphonline/standards-agent-kit 0.2.112 → 0.2.113

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.
Files changed (126) hide show
  1. package/dist/cjs/index.d.ts +1 -1
  2. package/dist/cjs/standards-agent-kit.cjs +1 -1
  3. package/dist/cjs/standards-agent-kit.cjs.map +1 -1
  4. package/dist/cjs/tools/hcs6/CreateDynamicRegistryTool.d.ts +44 -0
  5. package/dist/cjs/tools/hcs6/QueryDynamicRegistryTool.d.ts +50 -0
  6. package/dist/cjs/tools/hcs6/RegisterDynamicHashinalTool.d.ts +102 -0
  7. package/dist/cjs/tools/hcs6/UpdateDynamicHashinalTool.d.ts +96 -0
  8. package/dist/cjs/tools/hcs6/base-hcs6-tools.d.ts +28 -0
  9. package/dist/cjs/tools/hcs6/hcs6-tool-params.d.ts +18 -0
  10. package/dist/cjs/tools/hcs6/index.d.ts +6 -0
  11. package/dist/cjs/tools/index.d.ts +1 -0
  12. package/dist/cjs/tools/inscriber/InscribeFromBufferTool.d.ts +4 -4
  13. package/dist/es/index.d.ts +1 -1
  14. package/dist/es/standards-agent-kit.es.js +44 -31
  15. package/dist/es/standards-agent-kit.es.js.map +1 -1
  16. package/dist/es/standards-agent-kit.es10.js +27 -27
  17. package/dist/es/standards-agent-kit.es10.js.map +1 -1
  18. package/dist/es/standards-agent-kit.es11.js +20 -30
  19. package/dist/es/standards-agent-kit.es11.js.map +1 -1
  20. package/dist/es/standards-agent-kit.es12.js +27 -37
  21. package/dist/es/standards-agent-kit.es12.js.map +1 -1
  22. package/dist/es/standards-agent-kit.es13.js +48 -60
  23. package/dist/es/standards-agent-kit.es13.js.map +1 -1
  24. package/dist/es/standards-agent-kit.es14.js +60 -23
  25. package/dist/es/standards-agent-kit.es14.js.map +1 -1
  26. package/dist/es/standards-agent-kit.es15.js +23 -23
  27. package/dist/es/standards-agent-kit.es15.js.map +1 -1
  28. package/dist/es/standards-agent-kit.es16.js +23 -33
  29. package/dist/es/standards-agent-kit.es16.js.map +1 -1
  30. package/dist/es/standards-agent-kit.es17.js +34 -10
  31. package/dist/es/standards-agent-kit.es17.js.map +1 -1
  32. package/dist/es/standards-agent-kit.es18.js +16 -155
  33. package/dist/es/standards-agent-kit.es18.js.map +1 -1
  34. package/dist/es/standards-agent-kit.es19.js +150 -22
  35. package/dist/es/standards-agent-kit.es19.js.map +1 -1
  36. package/dist/es/standards-agent-kit.es20.js +25 -39
  37. package/dist/es/standards-agent-kit.es20.js.map +1 -1
  38. package/dist/es/standards-agent-kit.es21.js +26 -28
  39. package/dist/es/standards-agent-kit.es21.js.map +1 -1
  40. package/dist/es/standards-agent-kit.es22.js +16 -19
  41. package/dist/es/standards-agent-kit.es22.js.map +1 -1
  42. package/dist/es/standards-agent-kit.es23.js +21 -15
  43. package/dist/es/standards-agent-kit.es23.js.map +1 -1
  44. package/dist/es/standards-agent-kit.es24.js +18 -21
  45. package/dist/es/standards-agent-kit.es24.js.map +1 -1
  46. package/dist/es/standards-agent-kit.es25.js +35 -32
  47. package/dist/es/standards-agent-kit.es25.js.map +1 -1
  48. package/dist/es/standards-agent-kit.es26.js +38 -25
  49. package/dist/es/standards-agent-kit.es26.js.map +1 -1
  50. package/dist/es/standards-agent-kit.es27.js +25 -116
  51. package/dist/es/standards-agent-kit.es27.js.map +1 -1
  52. package/dist/es/standards-agent-kit.es28.js +33 -166
  53. package/dist/es/standards-agent-kit.es28.js.map +1 -1
  54. package/dist/es/standards-agent-kit.es29.js +42 -121
  55. package/dist/es/standards-agent-kit.es29.js.map +1 -1
  56. package/dist/es/standards-agent-kit.es30.js +40 -77
  57. package/dist/es/standards-agent-kit.es30.js.map +1 -1
  58. package/dist/es/standards-agent-kit.es31.js +42 -37
  59. package/dist/es/standards-agent-kit.es31.js.map +1 -1
  60. package/dist/es/standards-agent-kit.es32.js +20 -237
  61. package/dist/es/standards-agent-kit.es32.js.map +1 -1
  62. package/dist/es/standards-agent-kit.es33.js +154 -135
  63. package/dist/es/standards-agent-kit.es33.js.map +1 -1
  64. package/dist/es/standards-agent-kit.es34.js +168 -23
  65. package/dist/es/standards-agent-kit.es34.js.map +1 -1
  66. package/dist/es/standards-agent-kit.es35.js +126 -21
  67. package/dist/es/standards-agent-kit.es35.js.map +1 -1
  68. package/dist/es/standards-agent-kit.es36.js +86 -3
  69. package/dist/es/standards-agent-kit.es36.js.map +1 -1
  70. package/dist/es/standards-agent-kit.es37.js +45 -0
  71. package/dist/es/standards-agent-kit.es37.js.map +1 -0
  72. package/dist/es/standards-agent-kit.es38.js +249 -0
  73. package/dist/es/standards-agent-kit.es38.js.map +1 -0
  74. package/dist/es/standards-agent-kit.es39.js +141 -0
  75. package/dist/es/standards-agent-kit.es39.js.map +1 -0
  76. package/dist/es/standards-agent-kit.es4.js +65 -32
  77. package/dist/es/standards-agent-kit.es4.js.map +1 -1
  78. package/dist/es/standards-agent-kit.es40.js +33 -0
  79. package/dist/es/standards-agent-kit.es40.js.map +1 -0
  80. package/dist/es/standards-agent-kit.es41.js +28 -0
  81. package/dist/es/standards-agent-kit.es41.js.map +1 -0
  82. package/dist/es/standards-agent-kit.es42.js +7 -0
  83. package/dist/es/standards-agent-kit.es42.js.map +1 -0
  84. package/dist/es/standards-agent-kit.es5.js +35 -311
  85. package/dist/es/standards-agent-kit.es5.js.map +1 -1
  86. package/dist/es/standards-agent-kit.es6.js +320 -20
  87. package/dist/es/standards-agent-kit.es6.js.map +1 -1
  88. package/dist/es/standards-agent-kit.es7.js +19 -227
  89. package/dist/es/standards-agent-kit.es7.js.map +1 -1
  90. package/dist/es/standards-agent-kit.es8.js +216 -65
  91. package/dist/es/standards-agent-kit.es8.js.map +1 -1
  92. package/dist/es/standards-agent-kit.es9.js +72 -23
  93. package/dist/es/standards-agent-kit.es9.js.map +1 -1
  94. package/dist/es/tools/hcs6/CreateDynamicRegistryTool.d.ts +44 -0
  95. package/dist/es/tools/hcs6/QueryDynamicRegistryTool.d.ts +50 -0
  96. package/dist/es/tools/hcs6/RegisterDynamicHashinalTool.d.ts +102 -0
  97. package/dist/es/tools/hcs6/UpdateDynamicHashinalTool.d.ts +96 -0
  98. package/dist/es/tools/hcs6/base-hcs6-tools.d.ts +28 -0
  99. package/dist/es/tools/hcs6/hcs6-tool-params.d.ts +18 -0
  100. package/dist/es/tools/hcs6/index.d.ts +6 -0
  101. package/dist/es/tools/index.d.ts +1 -0
  102. package/dist/es/tools/inscriber/InscribeFromBufferTool.d.ts +4 -4
  103. package/dist/umd/index.d.ts +1 -1
  104. package/dist/umd/standards-agent-kit.umd.js +1 -1
  105. package/dist/umd/standards-agent-kit.umd.js.map +1 -1
  106. package/dist/umd/tools/hcs6/CreateDynamicRegistryTool.d.ts +44 -0
  107. package/dist/umd/tools/hcs6/QueryDynamicRegistryTool.d.ts +50 -0
  108. package/dist/umd/tools/hcs6/RegisterDynamicHashinalTool.d.ts +102 -0
  109. package/dist/umd/tools/hcs6/UpdateDynamicHashinalTool.d.ts +96 -0
  110. package/dist/umd/tools/hcs6/base-hcs6-tools.d.ts +28 -0
  111. package/dist/umd/tools/hcs6/hcs6-tool-params.d.ts +18 -0
  112. package/dist/umd/tools/hcs6/index.d.ts +6 -0
  113. package/dist/umd/tools/index.d.ts +1 -0
  114. package/dist/umd/tools/inscriber/InscribeFromBufferTool.d.ts +4 -4
  115. package/package.json +1 -1
  116. package/src/index.ts +1 -1
  117. package/src/tools/hcs6/CreateDynamicRegistryTool.ts +66 -0
  118. package/src/tools/hcs6/QueryDynamicRegistryTool.ts +72 -0
  119. package/src/tools/hcs6/RegisterDynamicHashinalTool.ts +79 -0
  120. package/src/tools/hcs6/UpdateDynamicHashinalTool.ts +74 -0
  121. package/src/tools/hcs6/base-hcs6-tools.ts +63 -0
  122. package/src/tools/hcs6/hcs6-tool-params.ts +21 -0
  123. package/src/tools/hcs6/index.ts +6 -0
  124. package/src/tools/index.ts +1 -0
  125. package/src/tools/inscriber/InscribeFromBufferTool.ts +1 -1
  126. package/src/tools/inscriber/InscribeFromUrlTool.ts +60 -7
@@ -1,32 +1,332 @@
1
- import { BaseHederaTransactionTool, BaseHederaQueryTool } from "hedera-agent-kit";
2
- class BaseHCS10TransactionTool extends BaseHederaTransactionTool {
3
- constructor(params) {
4
- super(params);
5
- this.namespace = "hcs10";
6
- this.hcs10Builder = params.hcs10Builder;
1
+ import { HCS10Client as HCS10Client$1, Logger, AgentBuilder, AIAgentCapability, InboundTopicType } from "@hashgraphonline/standards-sdk";
2
+ import { encryptMessage } from "./standards-agent-kit.es42.js";
3
+ class HCS10Client {
4
+ constructor(operatorId, operatorPrivateKey, network, options) {
5
+ this.standardClient = new HCS10Client$1({
6
+ network,
7
+ operatorId,
8
+ operatorPrivateKey,
9
+ guardedRegistryBaseUrl: options?.registryUrl,
10
+ logLevel: options?.logLevel
11
+ });
12
+ this.guardedRegistryBaseUrl = options?.registryUrl || "";
13
+ this.useEncryption = options?.useEncryption || false;
14
+ const shouldSilence = process.env.DISABLE_LOGGING === "true";
15
+ this.logger = new Logger({
16
+ level: options?.logLevel || "info",
17
+ silent: shouldSilence
18
+ });
19
+ }
20
+ getOperatorId() {
21
+ const operator = this.standardClient.getClient().operatorAccountId;
22
+ if (!operator) {
23
+ throw new Error("Operator Account ID not configured in standard client.");
24
+ }
25
+ return operator.toString();
26
+ }
27
+ getNetwork() {
28
+ return this.standardClient.getNetwork();
29
+ }
30
+ async handleConnectionRequest(inboundTopicId, requestingAccountId, connectionRequestId, feeConfig) {
31
+ try {
32
+ const result = await this.standardClient.handleConnectionRequest(
33
+ inboundTopicId,
34
+ requestingAccountId,
35
+ connectionRequestId,
36
+ feeConfig
37
+ );
38
+ return result;
39
+ } catch (error) {
40
+ this.logger.error(
41
+ `Error handling connection request #${connectionRequestId} for topic ${inboundTopicId}:`,
42
+ error
43
+ );
44
+ throw new Error(
45
+ `Failed to handle connection request: ${error instanceof Error ? error.message : String(error)}`
46
+ );
47
+ }
7
48
  }
8
49
  /**
9
- * Override to return the HCS10Builder
50
+ * Retrieves the profile for a given account ID using the standard SDK.
10
51
  */
11
- getServiceBuilder() {
12
- return this.hcs10Builder;
52
+ async getAgentProfile(accountId) {
53
+ return this.standardClient.retrieveProfile(accountId);
13
54
  }
14
- }
15
- class BaseHCS10QueryTool extends BaseHederaQueryTool {
16
- constructor(params) {
17
- super(params);
18
- this.namespace = "hcs10";
19
- this.hcs10Builder = params.hcs10Builder;
55
+ /**
56
+ * Exposes the standard SDK's submitConnectionRequest method.
57
+ */
58
+ async submitConnectionRequest(inboundTopicId, memo) {
59
+ return this.standardClient.submitConnectionRequest(
60
+ inboundTopicId,
61
+ memo
62
+ );
63
+ }
64
+ /**
65
+ * Exposes the standard SDK's waitForConnectionConfirmation method.
66
+ */
67
+ async waitForConnectionConfirmation(outboundTopicId, connectionRequestId, maxAttempts = 60, delayMs = 2e3) {
68
+ return this.standardClient.waitForConnectionConfirmation(
69
+ outboundTopicId,
70
+ connectionRequestId,
71
+ maxAttempts,
72
+ delayMs
73
+ );
20
74
  }
21
75
  /**
22
- * Override to return the HCS10Builder
76
+ * Creates and registers an agent using the standard SDK's HCS10Client.
77
+ * This handles account creation, key generation, topic setup, and registration.
78
+ *
79
+ * When metadata includes fee configuration:
80
+ * 1. The properties.feeConfig will be passed to the AgentBuilder
81
+ * 2. The properties.inboundTopicType will be set to FEE_BASED
82
+ * 3. The SDK's createAndRegisterAgent will apply the fees to the agent's inbound topic
83
+ *
84
+ * @param metadata - The agent's metadata, potentially including pfpBuffer, pfpFileName,
85
+ * and fee configuration in properties.feeConfig
86
+ * @returns The registration result from the standard SDK, containing accountId, keys, topics etc.
23
87
  */
24
- getServiceBuilder() {
25
- return this.hcs10Builder;
88
+ async createAndRegisterAgent(metadata) {
89
+ const builder = new AgentBuilder().setName(metadata.name).setBio(metadata.description || "").setCapabilities(
90
+ metadata.capabilities ? metadata.capabilities : [AIAgentCapability.TEXT_GENERATION]
91
+ ).setType(metadata.type || "autonomous").setModel(metadata.model || "agent-model-2024").setNetwork(this.getNetwork()).setInboundTopicType(InboundTopicType.PUBLIC);
92
+ if (metadata?.feeConfig) {
93
+ builder.setInboundTopicType(InboundTopicType.FEE_BASED);
94
+ builder.setFeeConfig(metadata.feeConfig);
95
+ }
96
+ if (metadata.pfpBuffer && metadata.pfpFileName) {
97
+ if (metadata.pfpBuffer.byteLength === 0) {
98
+ this.logger.warn(
99
+ "Provided PFP buffer is empty. Skipping profile picture."
100
+ );
101
+ } else {
102
+ this.logger.info(
103
+ `Setting profile picture: ${metadata.pfpFileName} (${metadata.pfpBuffer.byteLength} bytes)`
104
+ );
105
+ builder.setProfilePicture(metadata.pfpBuffer, metadata.pfpFileName);
106
+ }
107
+ } else {
108
+ this.logger.warn(
109
+ "Profile picture not provided in metadata. Agent creation might fail if required by the underlying SDK builder."
110
+ );
111
+ }
112
+ if (metadata.social) {
113
+ Object.entries(metadata.social).forEach(([platform, handle]) => {
114
+ builder.addSocial(platform, handle);
115
+ });
116
+ }
117
+ if (metadata.properties) {
118
+ Object.entries(metadata.properties).forEach(([key, value]) => {
119
+ builder.addProperty(key, value);
120
+ });
121
+ }
122
+ try {
123
+ const hasFees = Boolean(metadata?.feeConfig);
124
+ const result = await this.standardClient.createAndRegisterAgent(builder, {
125
+ initialBalance: hasFees ? 50 : void 0
126
+ });
127
+ if (result?.metadata?.inboundTopicId && result?.metadata?.outboundTopicId) {
128
+ this.agentChannels = {
129
+ inboundTopicId: result.metadata.inboundTopicId,
130
+ outboundTopicId: result.metadata.outboundTopicId
131
+ };
132
+ }
133
+ return result;
134
+ } catch (error) {
135
+ this.logger.error("Error during agent creation/registration:", error);
136
+ throw new Error(
137
+ `Failed to create/register agent: ${error instanceof Error ? error.message : String(error)}`
138
+ );
139
+ }
140
+ }
141
+ /**
142
+ * Sends a structured HCS-10 message to the specified topic using the standard SDK client.
143
+ * Handles potential inscription for large messages.
144
+ *
145
+ * @param topicId - The target topic ID (likely a connection topic).
146
+ * @param operatorId - The operator ID string (e.g., "inboundTopic@accountId").
147
+ * @param data - The actual message content/data.
148
+ * @param memo - Optional memo for the message.
149
+ * @param submitKey - Optional private key for topics requiring specific submit keys.
150
+ * @returns A confirmation status string from the transaction receipt.
151
+ */
152
+ async sendMessage(topicId, data, memo, submitKey) {
153
+ if (this.useEncryption) {
154
+ data = encryptMessage(data);
155
+ }
156
+ try {
157
+ const messageResponse = await this.standardClient.sendMessage(
158
+ topicId,
159
+ data,
160
+ memo,
161
+ submitKey
162
+ );
163
+ return messageResponse.topicSequenceNumber?.toNumber();
164
+ } catch (error) {
165
+ this.logger.error(`Error sending message to topic ${topicId}:`, error);
166
+ throw new Error(
167
+ `Failed to send message: ${error instanceof Error ? error.message : String(error)}`
168
+ );
169
+ }
170
+ }
171
+ /**
172
+ * Retrieves messages from a topic using the standard SDK client.
173
+ *
174
+ * @param topicId - The topic ID to get messages from.
175
+ * @returns Messages from the topic, mapped to the expected format.
176
+ */
177
+ async getMessages(topicId) {
178
+ try {
179
+ const result = await this.standardClient.getMessages(topicId);
180
+ const mappedMessages = result.messages.map((sdkMessage) => {
181
+ const timestamp = sdkMessage?.created?.getTime() || 0;
182
+ return {
183
+ ...sdkMessage,
184
+ timestamp,
185
+ data: sdkMessage.data,
186
+ sequence_number: sdkMessage.sequence_number
187
+ };
188
+ });
189
+ mappedMessages.sort(
190
+ (a, b) => a.timestamp - b.timestamp
191
+ );
192
+ return { messages: mappedMessages };
193
+ } catch (error) {
194
+ this.logger.error(`Error getting messages from topic ${topicId}:`, error);
195
+ return { messages: [] };
196
+ }
197
+ }
198
+ async getMessageStream(topicId) {
199
+ const result = this.standardClient.getMessageStream(topicId);
200
+ return result;
201
+ }
202
+ /**
203
+ * Retrieves content from an inscribed message using the standard SDK client.
204
+ * @param inscriptionIdOrData - The inscription ID (hcs://...) or potentially raw data string.
205
+ * @returns The resolved message content.
206
+ */
207
+ async getMessageContent(inscriptionIdOrData) {
208
+ try {
209
+ const content = await this.standardClient.getMessageContent(
210
+ inscriptionIdOrData
211
+ );
212
+ return content;
213
+ } catch (error) {
214
+ this.logger.error(
215
+ `Error retrieving message content for: ${inscriptionIdOrData}`,
216
+ error
217
+ );
218
+ throw new Error(
219
+ `Failed to retrieve message content: ${error instanceof Error ? error.message : String(error)}`
220
+ );
221
+ }
222
+ }
223
+ /**
224
+ * Retrieves the inbound topic ID associated with the current operator.
225
+ * This typically involves fetching the operator's own HCS-10 profile.
226
+ * @returns A promise that resolves to the operator's inbound topic ID.
227
+ * @throws {Error} If the operator ID cannot be determined or the profile/topic cannot be retrieved.
228
+ */
229
+ async getInboundTopicId() {
230
+ try {
231
+ const operatorId = this.getOperatorId();
232
+ this.logger.info(
233
+ `[HCS10Client] Retrieving profile for operator ${operatorId} to find inbound topic...`
234
+ );
235
+ const profileResponse = await this.getAgentProfile(operatorId);
236
+ if (profileResponse.success && profileResponse.topicInfo?.inboundTopic) {
237
+ this.logger.info(
238
+ `[HCS10Client] Found inbound topic for operator ${operatorId}: ${profileResponse.topicInfo.inboundTopic}`
239
+ );
240
+ return profileResponse.topicInfo.inboundTopic;
241
+ } else {
242
+ throw new Error(
243
+ `Could not retrieve inbound topic from profile for ${operatorId}. Profile success: ${profileResponse.success}, Error: ${profileResponse.error}`
244
+ );
245
+ }
246
+ } catch (error) {
247
+ this.logger.error(
248
+ `[HCS10Client] Error fetching operator's inbound topic ID (${this.getOperatorId()}):`,
249
+ error
250
+ );
251
+ const operatorId = this.getOperatorId();
252
+ let detailedMessage = `Failed to get inbound topic ID for operator ${operatorId}.`;
253
+ if (error instanceof Error && error.message.includes("does not have a valid HCS-11 memo")) {
254
+ detailedMessage += ` The account profile may not exist or is invalid. Please ensure this operator account (${operatorId}) is registered as an HCS-10 agent. You might need to register it first (e.g., using the 'register_agent' tool or SDK function).`;
255
+ } else if (error instanceof Error) {
256
+ detailedMessage += ` Reason: ${error.message}`;
257
+ } else {
258
+ detailedMessage += ` Unexpected error: ${String(error)}`;
259
+ }
260
+ throw new Error(detailedMessage);
261
+ }
262
+ }
263
+ /**
264
+ * Retrieves the configured operator account ID and private key.
265
+ * Required by tools needing to identify the current agent instance.
266
+ */
267
+ getAccountAndSigner() {
268
+ const result = this.standardClient.getAccountAndSigner();
269
+ return {
270
+ accountId: result.accountId,
271
+ signer: result.signer
272
+ };
273
+ }
274
+ /**
275
+ * Retrieves the outbound topic ID for the current operator.
276
+ * Fetches the operator's profile if necessary.
277
+ * @returns The outbound topic ID string.
278
+ * @throws If the outbound topic cannot be determined.
279
+ */
280
+ async getOutboundTopicId() {
281
+ const operatorId = this.getOperatorId();
282
+ const profile = await this.getAgentProfile(operatorId);
283
+ if (profile.success && profile.topicInfo?.outboundTopic) {
284
+ return profile.topicInfo.outboundTopic;
285
+ } else {
286
+ throw new Error(
287
+ `Could not retrieve outbound topic from profile for ${operatorId}. Profile success: ${profile.success}, Error: ${profile.error}`
288
+ );
289
+ }
290
+ }
291
+ setClient(accountId, privateKey) {
292
+ this.standardClient = new HCS10Client$1({
293
+ network: this.getNetwork(),
294
+ operatorId: accountId,
295
+ operatorPrivateKey: privateKey,
296
+ guardedRegistryBaseUrl: this.guardedRegistryBaseUrl
297
+ });
298
+ return this.standardClient;
299
+ }
300
+ /**
301
+ * Validates that the operator account exists and has proper access for agent operations
302
+ */
303
+ async validateOperator(options) {
304
+ try {
305
+ this.setClient(options.accountId, options.privateKey);
306
+ const operatorId = this.getOperatorId();
307
+ return {
308
+ isValid: true,
309
+ operator: { accountId: operatorId }
310
+ };
311
+ } catch (error) {
312
+ this.logger.error(`Validation error: ${error}`);
313
+ return {
314
+ isValid: false,
315
+ error: error instanceof Error ? error.message : String(error)
316
+ };
317
+ }
318
+ }
319
+ async initializeWithValidation(options) {
320
+ const validationResult = await this.validateOperator(options);
321
+ if (validationResult.isValid) {
322
+ if (options.stateManager) {
323
+ options.stateManager.initializeConnectionsManager(this.standardClient);
324
+ }
325
+ }
326
+ return validationResult;
26
327
  }
27
328
  }
28
329
  export {
29
- BaseHCS10QueryTool,
30
- BaseHCS10TransactionTool
330
+ HCS10Client
31
331
  };
32
332
  //# sourceMappingURL=standards-agent-kit.es6.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"standards-agent-kit.es6.js","sources":["../../src/tools/hcs10/base-hcs10-tools.ts"],"sourcesContent":["import {\n BaseHederaTransactionTool,\n BaseHederaQueryTool,\n BaseServiceBuilder,\n} from 'hedera-agent-kit';\nimport { HCS10Builder } from '../../builders/hcs10/hcs10-builder';\nimport {\n HCS10TransactionToolParams,\n HCS10QueryToolParams,\n} from './hcs10-tool-params';\nimport { z } from 'zod';\n\n/**\n * Base class for HCS10 transaction tools\n */\nexport abstract class BaseHCS10TransactionTool<\n T extends z.ZodObject<\n z.ZodRawShape,\n z.UnknownKeysParam,\n z.ZodTypeAny\n > = z.ZodObject<z.ZodRawShape>\n> extends BaseHederaTransactionTool<T> {\n protected hcs10Builder: HCS10Builder;\n namespace = 'hcs10' as const;\n\n constructor(params: HCS10TransactionToolParams) {\n super(params);\n this.hcs10Builder = params.hcs10Builder;\n }\n\n /**\n * Override to return the HCS10Builder\n */\n protected getServiceBuilder(): BaseServiceBuilder {\n return this.hcs10Builder;\n }\n}\n\n/**\n * Base class for HCS10 query tools\n */\nexport abstract class BaseHCS10QueryTool<\n T extends z.ZodObject<\n z.ZodRawShape,\n z.UnknownKeysParam,\n z.ZodTypeAny\n > = z.ZodObject<z.ZodRawShape>\n> extends BaseHederaQueryTool<T> {\n protected hcs10Builder: HCS10Builder;\n namespace = 'hcs10' as const;\n\n constructor(params: HCS10QueryToolParams) {\n super(params);\n this.hcs10Builder = params.hcs10Builder;\n }\n\n /**\n * Override to return the HCS10Builder\n */\n protected getServiceBuilder(): BaseServiceBuilder {\n return this.hcs10Builder;\n }\n}\n"],"names":[],"mappings":";AAeO,MAAe,iCAMZ,0BAA6B;AAAA,EAIrC,YAAY,QAAoC;AAC9C,UAAM,MAAM;AAHd,SAAA,YAAY;AAIV,SAAK,eAAe,OAAO;AAAA,EAC7B;AAAA;AAAA;AAAA;AAAA,EAKU,oBAAwC;AAChD,WAAO,KAAK;AAAA,EACd;AACF;AAKO,MAAe,2BAMZ,oBAAuB;AAAA,EAI/B,YAAY,QAA8B;AACxC,UAAM,MAAM;AAHd,SAAA,YAAY;AAIV,SAAK,eAAe,OAAO;AAAA,EAC7B;AAAA;AAAA;AAAA;AAAA,EAKU,oBAAwC;AAChD,WAAO,KAAK;AAAA,EACd;AACF;"}
1
+ {"version":3,"file":"standards-agent-kit.es6.js","sources":["../../src/hcs10/HCS10Client.ts"],"sourcesContent":["import { TransactionReceipt, PrivateKey } from '@hashgraph/sdk';\nimport {\n HCS10Client as StandardSDKClient,\n AgentBuilder,\n InboundTopicType as StandardInboundTopicType,\n AIAgentCapability as StandardAIAgentCapability,\n AgentRegistrationResult,\n WaitForConnectionConfirmationResponse,\n ProfileResponse as SDKProfileResponse,\n HCSMessage,\n LogLevel,\n Logger,\n FeeConfigBuilderInterface,\n SocialPlatform,\n} from '@hashgraphonline/standards-sdk';\nimport { AgentMetadata, AgentChannels } from './types';\nimport { encryptMessage } from '../utils/Encryption';\nimport { IStateManager } from '../state/state-types';\n\n// Keep type alias as they were removed accidentally\ntype StandardHandleConnectionRequest = InstanceType<\n typeof StandardSDKClient\n>['handleConnectionRequest'];\ntype HandleConnectionRequestResponse = Awaited<\n ReturnType<StandardHandleConnectionRequest>\n>;\nexport type StandardNetworkType = 'mainnet' | 'testnet';\n\nexport interface ClientValidationOptions {\n accountId: string;\n privateKey: string;\n network?: StandardNetworkType;\n stateManager?: IStateManager;\n}\n\nexport interface HCSMessageWithTimestamp extends HCSMessage {\n timestamp: number;\n data?: string;\n sequence_number: number;\n}\n\nexport interface ExtendedAgentMetadata extends AgentMetadata {\n pfpBuffer?: Buffer;\n pfpFileName?: string;\n feeConfig?: FeeConfigBuilderInterface;\n}\n\n/**\n * HCS10Client wraps the HCS-10 functionalities using the @hashgraphonline/standards-sdk.\n * - Creates and registers agents using the standard SDK flow.\n * - Manages agent communication channels (handled by standard SDK).\n * - Sends messages on Hedera topics (currently manual, potential for standard SDK integration).\n */\nexport class HCS10Client {\n public standardClient: StandardSDKClient;\n private useEncryption: boolean;\n public agentChannels?: AgentChannels;\n public guardedRegistryBaseUrl: string;\n public logger: Logger;\n\n constructor(\n operatorId: string,\n operatorPrivateKey: string,\n network: StandardNetworkType,\n options?: {\n useEncryption?: boolean;\n registryUrl?: string;\n logLevel?: LogLevel;\n }\n ) {\n this.standardClient = new StandardSDKClient({\n network: network,\n operatorId: operatorId,\n operatorPrivateKey: operatorPrivateKey,\n guardedRegistryBaseUrl: options?.registryUrl,\n logLevel: options?.logLevel,\n });\n this.guardedRegistryBaseUrl = options?.registryUrl || '';\n this.useEncryption = options?.useEncryption || false;\n const shouldSilence = process.env.DISABLE_LOGGING === 'true';\n this.logger = new Logger({\n level: options?.logLevel || 'info',\n silent: shouldSilence,\n });\n }\n\n public getOperatorId(): string {\n const operator = this.standardClient.getClient().operatorAccountId;\n if (!operator) {\n throw new Error('Operator Account ID not configured in standard client.');\n }\n return operator.toString();\n }\n\n public getNetwork(): StandardNetworkType {\n return this.standardClient.getNetwork() as StandardNetworkType;\n }\n\n public async handleConnectionRequest(\n inboundTopicId: string,\n requestingAccountId: string,\n connectionRequestId: number,\n feeConfig?: FeeConfigBuilderInterface\n ): Promise<HandleConnectionRequestResponse> {\n try {\n const result = await this.standardClient.handleConnectionRequest(\n inboundTopicId,\n requestingAccountId,\n connectionRequestId,\n feeConfig\n );\n return result;\n } catch (error) {\n this.logger.error(\n `Error handling connection request #${connectionRequestId} for topic ${inboundTopicId}:`,\n error\n );\n throw new Error(\n `Failed to handle connection request: ${\n error instanceof Error ? error.message : String(error)\n }`\n );\n }\n }\n\n /**\n * Retrieves the profile for a given account ID using the standard SDK.\n */\n public async getAgentProfile(accountId: string): Promise<SDKProfileResponse> {\n return this.standardClient.retrieveProfile(accountId);\n }\n\n /**\n * Exposes the standard SDK's submitConnectionRequest method.\n */\n public async submitConnectionRequest(\n inboundTopicId: string,\n memo: string\n ): Promise<TransactionReceipt> {\n return this.standardClient.submitConnectionRequest(\n inboundTopicId,\n memo\n ) as Promise<TransactionReceipt>;\n }\n\n /**\n * Exposes the standard SDK's waitForConnectionConfirmation method.\n */\n public async waitForConnectionConfirmation(\n outboundTopicId: string,\n connectionRequestId: number,\n maxAttempts = 60,\n delayMs = 2000\n ): Promise<WaitForConnectionConfirmationResponse> {\n return this.standardClient.waitForConnectionConfirmation(\n outboundTopicId,\n connectionRequestId,\n maxAttempts,\n delayMs\n );\n }\n\n /**\n * Creates and registers an agent using the standard SDK's HCS10Client.\n * This handles account creation, key generation, topic setup, and registration.\n *\n * When metadata includes fee configuration:\n * 1. The properties.feeConfig will be passed to the AgentBuilder\n * 2. The properties.inboundTopicType will be set to FEE_BASED\n * 3. The SDK's createAndRegisterAgent will apply the fees to the agent's inbound topic\n *\n * @param metadata - The agent's metadata, potentially including pfpBuffer, pfpFileName,\n * and fee configuration in properties.feeConfig\n * @returns The registration result from the standard SDK, containing accountId, keys, topics etc.\n */\n public async createAndRegisterAgent(\n metadata: ExtendedAgentMetadata\n ): Promise<AgentRegistrationResult> {\n const builder = new AgentBuilder()\n .setName(metadata.name)\n .setBio(metadata.description || '')\n .setCapabilities(\n metadata.capabilities\n ? metadata.capabilities\n : [StandardAIAgentCapability.TEXT_GENERATION]\n )\n .setType((metadata.type || 'autonomous') as 'autonomous' | 'manual')\n .setModel(metadata.model || 'agent-model-2024')\n .setNetwork(this.getNetwork())\n .setInboundTopicType(StandardInboundTopicType.PUBLIC);\n\n if (metadata?.feeConfig) {\n builder.setInboundTopicType(StandardInboundTopicType.FEE_BASED);\n builder.setFeeConfig(metadata.feeConfig);\n }\n\n if (metadata.pfpBuffer && metadata.pfpFileName) {\n if (metadata.pfpBuffer.byteLength === 0) {\n this.logger.warn(\n 'Provided PFP buffer is empty. Skipping profile picture.'\n );\n } else {\n this.logger.info(\n `Setting profile picture: ${metadata.pfpFileName} (${metadata.pfpBuffer.byteLength} bytes)`\n );\n builder.setProfilePicture(metadata.pfpBuffer, metadata.pfpFileName);\n }\n } else {\n this.logger.warn(\n 'Profile picture not provided in metadata. Agent creation might fail if required by the underlying SDK builder.'\n );\n }\n\n if (metadata.social) {\n Object.entries(metadata.social).forEach(([platform, handle]) => {\n builder.addSocial(platform as SocialPlatform, handle);\n });\n }\n\n if (metadata.properties) {\n Object.entries(metadata.properties).forEach(([key, value]) => {\n builder.addProperty(key, value);\n });\n }\n\n try {\n const hasFees = Boolean(metadata?.feeConfig);\n const result = await this.standardClient.createAndRegisterAgent(builder, {\n initialBalance: hasFees ? 50 : undefined,\n });\n if (\n result?.metadata?.inboundTopicId &&\n result?.metadata?.outboundTopicId\n ) {\n this.agentChannels = {\n inboundTopicId: result.metadata.inboundTopicId,\n outboundTopicId: result.metadata.outboundTopicId,\n };\n }\n return result;\n } catch (error) {\n this.logger.error('Error during agent creation/registration:', error);\n throw new Error(\n `Failed to create/register agent: ${\n error instanceof Error ? error.message : String(error)\n }`\n );\n }\n }\n\n /**\n * Sends a structured HCS-10 message to the specified topic using the standard SDK client.\n * Handles potential inscription for large messages.\n *\n * @param topicId - The target topic ID (likely a connection topic).\n * @param operatorId - The operator ID string (e.g., \"inboundTopic@accountId\").\n * @param data - The actual message content/data.\n * @param memo - Optional memo for the message.\n * @param submitKey - Optional private key for topics requiring specific submit keys.\n * @returns A confirmation status string from the transaction receipt.\n */\n public async sendMessage(\n topicId: string,\n data: string,\n memo?: string,\n submitKey?: PrivateKey\n ): Promise<number | undefined> {\n if (this.useEncryption) {\n data = encryptMessage(data);\n }\n\n try {\n const messageResponse = await this.standardClient.sendMessage(\n topicId,\n data,\n memo,\n submitKey\n );\n return messageResponse.topicSequenceNumber?.toNumber();\n } catch (error) {\n this.logger.error(`Error sending message to topic ${topicId}:`, error);\n throw new Error(\n `Failed to send message: ${\n error instanceof Error ? error.message : String(error)\n }`\n );\n }\n }\n\n /**\n * Retrieves messages from a topic using the standard SDK client.\n *\n * @param topicId - The topic ID to get messages from.\n * @returns Messages from the topic, mapped to the expected format.\n */\n public async getMessages(topicId: string): Promise<{\n messages: HCSMessageWithTimestamp[];\n }> {\n try {\n const result = await this.standardClient.getMessages(topicId);\n\n const mappedMessages = result.messages.map((sdkMessage) => {\n const timestamp = sdkMessage?.created?.getTime() || 0;\n\n return {\n ...sdkMessage,\n timestamp: timestamp,\n data: sdkMessage.data,\n sequence_number: sdkMessage.sequence_number,\n };\n });\n mappedMessages.sort(\n (a: { timestamp: number }, b: { timestamp: number }) =>\n a.timestamp - b.timestamp\n );\n return { messages: mappedMessages as HCSMessageWithTimestamp[] };\n } catch (error) {\n this.logger.error(`Error getting messages from topic ${topicId}:`, error);\n return { messages: [] };\n }\n }\n\n public async getMessageStream(topicId: string): Promise<{\n messages: HCSMessage[];\n }> {\n const result = this.standardClient.getMessageStream(topicId);\n return result as Promise<{ messages: HCSMessage[] }>;\n }\n\n /**\n * Retrieves content from an inscribed message using the standard SDK client.\n * @param inscriptionIdOrData - The inscription ID (hcs://...) or potentially raw data string.\n * @returns The resolved message content.\n */\n public async getMessageContent(inscriptionIdOrData: string): Promise<string> {\n try {\n const content = await this.standardClient.getMessageContent(\n inscriptionIdOrData\n );\n return content as string;\n } catch (error) {\n this.logger.error(\n `Error retrieving message content for: ${inscriptionIdOrData}`,\n error\n );\n throw new Error(\n `Failed to retrieve message content: ${\n error instanceof Error ? error.message : String(error)\n }`\n );\n }\n }\n\n /**\n * Retrieves the inbound topic ID associated with the current operator.\n * This typically involves fetching the operator's own HCS-10 profile.\n * @returns A promise that resolves to the operator's inbound topic ID.\n * @throws {Error} If the operator ID cannot be determined or the profile/topic cannot be retrieved.\n */\n public async getInboundTopicId(): Promise<string> {\n try {\n const operatorId = this.getOperatorId();\n this.logger.info(\n `[HCS10Client] Retrieving profile for operator ${operatorId} to find inbound topic...`\n );\n const profileResponse = await this.getAgentProfile(operatorId);\n if (profileResponse.success && profileResponse.topicInfo?.inboundTopic) {\n this.logger.info(\n `[HCS10Client] Found inbound topic for operator ${operatorId}: ${profileResponse.topicInfo.inboundTopic}`\n );\n return profileResponse.topicInfo.inboundTopic;\n } else {\n throw new Error(\n `Could not retrieve inbound topic from profile for ${operatorId}. Profile success: ${profileResponse.success}, Error: ${profileResponse.error}`\n );\n }\n } catch (error) {\n this.logger.error(\n `[HCS10Client] Error fetching operator's inbound topic ID (${this.getOperatorId()}):`,\n error\n );\n const operatorId = this.getOperatorId();\n let detailedMessage = `Failed to get inbound topic ID for operator ${operatorId}.`;\n if (\n error instanceof Error &&\n error.message.includes('does not have a valid HCS-11 memo')\n ) {\n detailedMessage += ` The account profile may not exist or is invalid. Please ensure this operator account (${operatorId}) is registered as an HCS-10 agent. You might need to register it first (e.g., using the 'register_agent' tool or SDK function).`;\n } else if (error instanceof Error) {\n detailedMessage += ` Reason: ${error.message}`;\n } else {\n detailedMessage += ` Unexpected error: ${String(error)}`;\n }\n throw new Error(detailedMessage);\n }\n }\n\n /**\n * Retrieves the configured operator account ID and private key.\n * Required by tools needing to identify the current agent instance.\n */\n public getAccountAndSigner(): { accountId: string; signer: PrivateKey } {\n const result = this.standardClient.getAccountAndSigner();\n return {\n accountId: result.accountId,\n signer: result.signer as unknown as PrivateKey,\n };\n }\n\n /**\n * Retrieves the outbound topic ID for the current operator.\n * Fetches the operator's profile if necessary.\n * @returns The outbound topic ID string.\n * @throws If the outbound topic cannot be determined.\n */\n public async getOutboundTopicId(): Promise<string> {\n const operatorId = this.getOperatorId();\n const profile = await this.getAgentProfile(operatorId);\n if (profile.success && profile.topicInfo?.outboundTopic) {\n return profile.topicInfo.outboundTopic;\n } else {\n throw new Error(\n `Could not retrieve outbound topic from profile for ${operatorId}. Profile success: ${profile.success}, Error: ${profile.error}`\n );\n }\n }\n\n public setClient(accountId: string, privateKey: string): StandardSDKClient {\n this.standardClient = new StandardSDKClient({\n network: this.getNetwork(),\n operatorId: accountId,\n operatorPrivateKey: privateKey,\n guardedRegistryBaseUrl: this.guardedRegistryBaseUrl,\n });\n return this.standardClient;\n }\n\n /**\n * Validates that the operator account exists and has proper access for agent operations\n */\n private async validateOperator(options: ClientValidationOptions): Promise<{\n isValid: boolean;\n operator?: { accountId: string };\n error?: string;\n }> {\n try {\n // Set up client with provided operator details\n this.setClient(options.accountId, options.privateKey);\n\n // Check if we can retrieve the operator ID\n const operatorId = this.getOperatorId();\n\n // If we got this far, basic validation passed\n return {\n isValid: true,\n operator: { accountId: operatorId },\n };\n } catch (error) {\n this.logger.error(`Validation error: ${error}`);\n return {\n isValid: false,\n error: error instanceof Error ? error.message : String(error),\n };\n }\n }\n\n async initializeWithValidation(options: ClientValidationOptions): Promise<{\n isValid: boolean;\n operator?: { accountId: string };\n error?: string;\n }> {\n const validationResult = await this.validateOperator(options);\n\n if (validationResult.isValid) {\n // If we have access to the state manager, initialize its connections manager\n if (options.stateManager) {\n options.stateManager.initializeConnectionsManager(this.standardClient);\n }\n }\n\n return validationResult;\n }\n}\n"],"names":["StandardSDKClient","StandardAIAgentCapability","StandardInboundTopicType"],"mappings":";;AAqDO,MAAM,YAAY;AAAA,EAOvB,YACE,YACA,oBACA,SACA,SAKA;AACA,SAAK,iBAAiB,IAAIA,cAAkB;AAAA,MAC1C;AAAA,MACA;AAAA,MACA;AAAA,MACA,wBAAwB,SAAS;AAAA,MACjC,UAAU,SAAS;AAAA,IAAA,CACpB;AACD,SAAK,yBAAyB,SAAS,eAAe;AACtD,SAAK,gBAAgB,SAAS,iBAAiB;AAC/C,UAAM,gBAAgB,QAAQ,IAAI,oBAAoB;AACtD,SAAK,SAAS,IAAI,OAAO;AAAA,MACvB,OAAO,SAAS,YAAY;AAAA,MAC5B,QAAQ;AAAA,IAAA,CACT;AAAA,EACH;AAAA,EAEO,gBAAwB;AAC7B,UAAM,WAAW,KAAK,eAAe,UAAA,EAAY;AACjD,QAAI,CAAC,UAAU;AACb,YAAM,IAAI,MAAM,wDAAwD;AAAA,IAC1E;AACA,WAAO,SAAS,SAAA;AAAA,EAClB;AAAA,EAEO,aAAkC;AACvC,WAAO,KAAK,eAAe,WAAA;AA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I,iBAAiB,SAAS;AAE5B,UAAI,QAAQ,cAAc;AACxB,gBAAQ,aAAa,6BAA6B,KAAK,cAAc;AAAA,MACvE;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AACF;"}
@@ -1,240 +1,32 @@
1
- import { AIAgentCapability } from "@hashgraphonline/standards-sdk";
2
- import { z } from "zod";
3
- import { BaseHCS10TransactionTool } from "./standards-agent-kit.es6.js";
4
- import { NaturalLanguageMapper } from "./standards-agent-kit.es18.js";
5
- const RegisterAgentZodSchema = z.object({
6
- name: z.string().min(1).max(50).describe("A unique name for the agent (1-50 characters)"),
7
- description: z.string().max(500).optional().describe("Optional bio description for the agent (max 500 characters)"),
8
- alias: z.string().optional().transform((val) => {
9
- if (!val || val.toLowerCase().includes("random")) {
10
- const timestamp = Date.now().toString(36);
11
- const randomChars = Math.random().toString(36);
12
- return `bot${timestamp}${randomChars}`;
13
- }
14
- return val;
15
- }).describe(
16
- 'Optional custom username/alias for the agent. Use "random" to generate a unique alias'
17
- ),
18
- type: z.enum(["autonomous", "manual"]).optional().describe("Agent type (default: autonomous)"),
19
- model: z.string().optional().describe("AI model identifier (default: agent-model-2024)"),
20
- capabilities: z.union([
21
- z.array(z.nativeEnum(AIAgentCapability)),
22
- z.array(z.string()),
23
- z.string()
24
- ]).optional().transform((val) => {
25
- if (!val) return void 0;
26
- if (typeof val === "string") {
27
- return NaturalLanguageMapper.parseCapabilities(val);
28
- }
29
- if (Array.isArray(val) && val.length > 0 && typeof val[0] === "string") {
30
- return NaturalLanguageMapper.parseTagsOrCapabilities(val);
31
- }
32
- return val;
33
- }).describe('Agent capabilities - can be capability names (e.g. "ai", "data processing"), capability enum values, or array of either. Common values: "ai"/"text" (TEXT_GENERATION), "data" (DATA_INTEGRATION), "analytics" (TRANSACTION_ANALYTICS)'),
34
- tags: z.union([
35
- z.array(z.string()),
36
- z.string()
37
- ]).optional().transform((val) => {
38
- if (!val) return void 0;
39
- if (typeof val === "string") {
40
- return NaturalLanguageMapper.parseCapabilities(val);
41
- }
42
- return NaturalLanguageMapper.parseTagsOrCapabilities(val);
43
- }).describe('Tags for the agent (alternative to capabilities) - e.g. "ai", "data", "analytics". Will be converted to appropriate capabilities.'),
44
- creator: z.string().optional().describe("Creator attribution for the agent"),
45
- socials: z.record(
46
- z.enum([
47
- "twitter",
48
- "github",
49
- "discord",
50
- "telegram",
51
- "linkedin",
52
- "youtube",
53
- "website",
54
- "x"
55
- ]),
56
- z.string()
57
- ).optional().describe(
58
- 'Social media links (e.g., {"twitter": "@handle", "discord": "username"})'
59
- ),
60
- properties: z.record(z.unknown()).optional().describe("Custom metadata properties for the agent"),
61
- profilePicture: z.union([
62
- z.string().describe("URL or local file path to profile picture"),
63
- z.object({
64
- url: z.string().optional(),
65
- path: z.string().optional(),
66
- filename: z.string().optional()
67
- })
68
- ]).optional().describe(
69
- "Optional profile picture as URL, file path, or object with url/path/filename"
70
- ),
71
- existingProfilePictureTopicId: z.string().optional().describe(
72
- "Topic ID of an existing profile picture to reuse (e.g., 0.0.12345)"
73
- ),
74
- initialBalance: z.number().positive().optional().describe(
75
- "Optional initial HBAR balance for the new agent account (will create new account if provided)"
76
- ),
77
- userAccountId: z.string().optional().describe(
78
- "Optional account ID (e.g., 0.0.12345) to use as the agent account instead of creating a new one"
79
- ),
80
- hbarFee: z.number().positive().optional().describe(
81
- "Optional HBAR fee amount to charge per message on the inbound topic"
82
- ),
83
- tokenFees: z.array(
84
- z.object({
85
- amount: z.number().positive(),
86
- tokenId: z.string()
87
- })
88
- ).optional().describe("Optional token fees to charge per message"),
89
- exemptAccountIds: z.array(z.string()).optional().describe("Optional account IDs to exempt from fees"),
90
- setAsCurrent: z.boolean().optional().describe("Whether to set as current agent (default: true)"),
91
- persistence: z.object({
92
- prefix: z.string().optional()
93
- }).optional().describe("Optional persistence configuration")
94
- });
95
- class RegisterAgentTool extends BaseHCS10TransactionTool {
1
+ import { BaseHederaTransactionTool, BaseHederaQueryTool } from "hedera-agent-kit";
2
+ class BaseHCS10TransactionTool extends BaseHederaTransactionTool {
96
3
  constructor(params) {
97
4
  super(params);
98
- this.name = "register_agent";
99
- this.description = 'Creates and registers the AI agent on the Hedera network. Returns JSON string with agent details (accountId, privateKey, topics) on success. Supports natural language for capabilities/tags like "ai", "data processing", "analytics". Note: This tool requires multiple transactions and cannot be used in returnBytes mode. If alias is set to "random" or contains "random", a unique alias will be generated.';
100
- this.specificInputSchema = RegisterAgentZodSchema;
101
- this.neverScheduleThisTool = true;
102
- this.requiresMultipleTransactions = true;
103
- }
104
- async callBuilderMethod(builder, specificArgs) {
105
- const hcs10Builder = builder;
106
- this.specificArgs = specificArgs;
107
- const params = {
108
- name: specificArgs.name
109
- };
110
- if (specificArgs.description !== void 0) {
111
- params.bio = specificArgs.description;
112
- }
113
- if (specificArgs.alias !== void 0) {
114
- params.alias = specificArgs.alias;
115
- } else {
116
- const randomSuffix = Date.now().toString(36);
117
- params.alias = `${specificArgs.name}${randomSuffix}`;
118
- }
119
- if (specificArgs.type !== void 0) {
120
- params.type = specificArgs.type;
121
- }
122
- if (specificArgs.model !== void 0) {
123
- params.model = specificArgs.model;
124
- }
125
- if (specificArgs.tags !== void 0) {
126
- params.capabilities = specificArgs.tags;
127
- } else if (specificArgs.capabilities !== void 0) {
128
- params.capabilities = specificArgs.capabilities;
129
- }
130
- if (specificArgs.creator !== void 0) {
131
- params.creator = specificArgs.creator;
132
- }
133
- if (specificArgs.socials !== void 0) {
134
- params.socials = specificArgs.socials;
135
- }
136
- if (specificArgs.properties !== void 0) {
137
- params.properties = specificArgs.properties;
138
- }
139
- if (specificArgs.profilePicture !== void 0) {
140
- if (typeof specificArgs.profilePicture === "string") {
141
- params.profilePicture = specificArgs.profilePicture;
142
- } else {
143
- const profilePicObj = {};
144
- if (specificArgs.profilePicture.url !== void 0) {
145
- profilePicObj.url = specificArgs.profilePicture.url;
146
- }
147
- if (specificArgs.profilePicture.path !== void 0) {
148
- profilePicObj.path = specificArgs.profilePicture.path;
149
- }
150
- if (specificArgs.profilePicture.filename !== void 0) {
151
- profilePicObj.filename = specificArgs.profilePicture.filename;
152
- }
153
- params.profilePicture = profilePicObj;
154
- }
155
- }
156
- if (specificArgs.existingProfilePictureTopicId !== void 0) {
157
- params.existingProfilePictureTopicId = specificArgs.existingProfilePictureTopicId;
158
- }
159
- if (specificArgs.userAccountId !== void 0) {
160
- params.userAccountId = specificArgs.userAccountId;
161
- }
162
- if (specificArgs.hbarFee !== void 0) {
163
- params.hbarFee = specificArgs.hbarFee;
164
- }
165
- if (specificArgs.tokenFees !== void 0) {
166
- params.tokenFees = specificArgs.tokenFees;
167
- }
168
- if (specificArgs.exemptAccountIds !== void 0) {
169
- params.exemptAccountIds = specificArgs.exemptAccountIds;
170
- }
171
- if (specificArgs.initialBalance !== void 0) {
172
- params.initialBalance = specificArgs.initialBalance;
173
- }
174
- await hcs10Builder.registerAgent(params);
5
+ this.namespace = "hcs10";
6
+ this.hcs10Builder = params.hcs10Builder;
175
7
  }
176
8
  /**
177
- * Override _call to intercept the result and save agent to state if needed
9
+ * Override to return the HCS10Builder
178
10
  */
179
- async _call(args, runManager) {
180
- const result = await super._call(args, runManager);
181
- const shouldSetAsCurrent = this.specificArgs?.setAsCurrent !== false;
182
- if (this.specificArgs && shouldSetAsCurrent) {
183
- try {
184
- const parsed = JSON.parse(result);
185
- if (parsed.rawResult) {
186
- this._handleRegistrationResult(parsed.rawResult);
187
- } else if (parsed.state || parsed.accountId || parsed.metadata) {
188
- this._handleRegistrationResult(parsed);
189
- }
190
- } catch (e) {
191
- }
192
- }
193
- return result;
11
+ getServiceBuilder() {
12
+ return this.hcs10Builder;
13
+ }
14
+ }
15
+ class BaseHCS10QueryTool extends BaseHederaQueryTool {
16
+ constructor(params) {
17
+ super(params);
18
+ this.namespace = "hcs10";
19
+ this.hcs10Builder = params.hcs10Builder;
194
20
  }
195
21
  /**
196
- * Extract agent data from registration result and save to state
22
+ * Override to return the HCS10Builder
197
23
  */
198
- _handleRegistrationResult(rawResult) {
199
- let accountId = rawResult.accountId || rawResult.metadata?.accountId;
200
- if (!accountId && rawResult.state?.createdResources) {
201
- const accountResource = rawResult.state.createdResources.find(
202
- (r) => r.startsWith("account:")
203
- );
204
- if (accountResource) {
205
- accountId = accountResource.split(":")[1];
206
- }
207
- }
208
- const inboundTopicId = rawResult.inboundTopicId || rawResult.metadata?.inboundTopicId || rawResult.state?.inboundTopicId;
209
- const outboundTopicId = rawResult.outboundTopicId || rawResult.metadata?.outboundTopicId || rawResult.state?.outboundTopicId;
210
- const profileTopicId = rawResult.profileTopicId || rawResult.metadata?.profileTopicId || rawResult.state?.profileTopicId;
211
- const privateKey = rawResult.privateKey || rawResult.metadata?.privateKey;
212
- if (accountId && inboundTopicId && outboundTopicId && this.specificArgs) {
213
- const registeredAgent = {
214
- name: this.specificArgs.name,
215
- accountId,
216
- inboundTopicId,
217
- outboundTopicId,
218
- profileTopicId,
219
- privateKey
220
- };
221
- const hcs10Builder = this.getServiceBuilder();
222
- const stateManager = hcs10Builder.getStateManager();
223
- if (stateManager) {
224
- stateManager.setCurrentAgent(registeredAgent);
225
- if (stateManager.persistAgentData) {
226
- const prefix = this.specificArgs.persistence?.prefix || this.specificArgs.name.toUpperCase().replace(/[^A-Z0-9]/g, "_");
227
- stateManager.persistAgentData(registeredAgent, {
228
- type: "env-file",
229
- prefix
230
- }).catch(() => {
231
- });
232
- }
233
- }
234
- }
24
+ getServiceBuilder() {
25
+ return this.hcs10Builder;
235
26
  }
236
27
  }
237
28
  export {
238
- RegisterAgentTool
29
+ BaseHCS10QueryTool,
30
+ BaseHCS10TransactionTool
239
31
  };
240
32
  //# sourceMappingURL=standards-agent-kit.es7.js.map