@hashgraphonline/standards-agent-kit 0.0.32 → 0.0.34

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 (176) hide show
  1. package/dist/cjs/init/index.d.ts +1 -0
  2. package/dist/cjs/{src → init}/init.d.ts +16 -16
  3. package/dist/cjs/standards-agent-kit.cjs +1 -1
  4. package/dist/cjs/standards-agent-kit.cjs.map +1 -1
  5. package/dist/{umd/src → cjs}/tools/AcceptConnectionRequestTool.d.ts +6 -6
  6. package/dist/cjs/{src/tools → tools}/CheckMessagesTool.d.ts +6 -6
  7. package/dist/{umd/src → cjs}/tools/ConnectionMonitorTool.d.ts +34 -34
  8. package/dist/{umd/src → cjs}/tools/FindRegistrationsTool.d.ts +4 -4
  9. package/dist/cjs/{src/tools → tools}/InitiateConnectionTool.d.ts +2 -2
  10. package/dist/{umd/src → cjs}/tools/ListConnectionsTool.d.ts +4 -4
  11. package/dist/{es/src → cjs}/tools/ListUnapprovedConnectionRequestsTool.d.ts +4 -4
  12. package/dist/{es/src → cjs}/tools/ManageConnectionRequestsTool.d.ts +4 -4
  13. package/dist/cjs/{src/tools → tools}/RegisterAgentTool.d.ts +76 -76
  14. package/dist/{es/src → cjs}/tools/RetrieveProfileTool.d.ts +4 -4
  15. package/dist/{es/src → cjs}/tools/SendMessageToConnectionTool.d.ts +6 -6
  16. package/dist/cjs/{src/tools → tools}/SendMessageTool.d.ts +6 -6
  17. package/dist/es/index.d.ts +5 -2
  18. package/dist/es/init/index.d.ts +1 -0
  19. package/dist/{umd/src → es/init}/init.d.ts +16 -16
  20. package/dist/es/standards-agent-kit.es.js +17 -17
  21. package/dist/es/standards-agent-kit.es10.js +65 -104
  22. package/dist/es/standards-agent-kit.es10.js.map +1 -1
  23. package/dist/es/standards-agent-kit.es11.js +371 -66
  24. package/dist/es/standards-agent-kit.es11.js.map +1 -1
  25. package/dist/es/standards-agent-kit.es12.js +153 -348
  26. package/dist/es/standards-agent-kit.es12.js.map +1 -1
  27. package/dist/es/standards-agent-kit.es13.js +105 -161
  28. package/dist/es/standards-agent-kit.es13.js.map +1 -1
  29. package/dist/es/standards-agent-kit.es14.js +48 -126
  30. package/dist/es/standards-agent-kit.es14.js.map +1 -1
  31. package/dist/es/standards-agent-kit.es15.js +108 -50
  32. package/dist/es/standards-agent-kit.es15.js.map +1 -1
  33. package/dist/es/standards-agent-kit.es16.js +239 -117
  34. package/dist/es/standards-agent-kit.es16.js.map +1 -1
  35. package/dist/es/standards-agent-kit.es17.js +120 -245
  36. package/dist/es/standards-agent-kit.es17.js.map +1 -1
  37. package/dist/es/standards-agent-kit.es2.js +321 -114
  38. package/dist/es/standards-agent-kit.es2.js.map +1 -1
  39. package/dist/es/standards-agent-kit.es23.js +15 -15
  40. package/dist/es/standards-agent-kit.es24.js +79 -22
  41. package/dist/es/standards-agent-kit.es24.js.map +1 -1
  42. package/dist/es/standards-agent-kit.es25.js +24 -3
  43. package/dist/es/standards-agent-kit.es25.js.map +1 -1
  44. package/dist/es/standards-agent-kit.es26.js +3 -81
  45. package/dist/es/standards-agent-kit.es26.js.map +1 -1
  46. package/dist/es/standards-agent-kit.es3.js +347 -284
  47. package/dist/es/standards-agent-kit.es3.js.map +1 -1
  48. package/dist/es/standards-agent-kit.es4.js +56 -366
  49. package/dist/es/standards-agent-kit.es4.js.map +1 -1
  50. package/dist/es/standards-agent-kit.es5.js +142 -58
  51. package/dist/es/standards-agent-kit.es5.js.map +1 -1
  52. package/dist/es/standards-agent-kit.es6.js +73 -143
  53. package/dist/es/standards-agent-kit.es6.js.map +1 -1
  54. package/dist/es/standards-agent-kit.es7.js +63 -63
  55. package/dist/es/standards-agent-kit.es7.js.map +1 -1
  56. package/dist/es/standards-agent-kit.es8.js +91 -77
  57. package/dist/es/standards-agent-kit.es8.js.map +1 -1
  58. package/dist/es/standards-agent-kit.es9.js +109 -90
  59. package/dist/es/standards-agent-kit.es9.js.map +1 -1
  60. package/dist/es/{src/tools → tools}/AcceptConnectionRequestTool.d.ts +6 -6
  61. package/dist/{umd/src → es}/tools/CheckMessagesTool.d.ts +6 -6
  62. package/dist/es/{src/tools → tools}/ConnectionMonitorTool.d.ts +34 -34
  63. package/dist/{cjs/src → es}/tools/FindRegistrationsTool.d.ts +4 -4
  64. package/dist/{umd/src → es}/tools/InitiateConnectionTool.d.ts +2 -2
  65. package/dist/{cjs/src → es}/tools/ListConnectionsTool.d.ts +4 -4
  66. package/dist/{cjs/src → es}/tools/ListUnapprovedConnectionRequestsTool.d.ts +4 -4
  67. package/dist/{umd/src → es}/tools/ManageConnectionRequestsTool.d.ts +4 -4
  68. package/dist/{umd/src → es}/tools/RegisterAgentTool.d.ts +76 -76
  69. package/dist/{cjs/src → es}/tools/RetrieveProfileTool.d.ts +4 -4
  70. package/dist/{umd/src → es}/tools/SendMessageToConnectionTool.d.ts +6 -6
  71. package/dist/{umd/src → es}/tools/SendMessageTool.d.ts +6 -6
  72. package/dist/umd/init/index.d.ts +1 -0
  73. package/dist/{es/src → umd/init}/init.d.ts +16 -16
  74. package/dist/umd/standards-agent-kit.umd.js +15 -14
  75. package/dist/umd/standards-agent-kit.umd.js.map +1 -1
  76. package/dist/{cjs/src → umd}/tools/AcceptConnectionRequestTool.d.ts +6 -6
  77. package/dist/{es/src → umd}/tools/CheckMessagesTool.d.ts +6 -6
  78. package/dist/{cjs/src → umd}/tools/ConnectionMonitorTool.d.ts +34 -34
  79. package/dist/{es/src → umd}/tools/FindRegistrationsTool.d.ts +4 -4
  80. package/dist/{es/src → umd}/tools/InitiateConnectionTool.d.ts +2 -2
  81. package/dist/{es/src → umd}/tools/ListConnectionsTool.d.ts +4 -4
  82. package/dist/umd/{src/tools → tools}/ListUnapprovedConnectionRequestsTool.d.ts +4 -4
  83. package/dist/{cjs/src → umd}/tools/ManageConnectionRequestsTool.d.ts +4 -4
  84. package/dist/{es/src → umd}/tools/RegisterAgentTool.d.ts +76 -76
  85. package/dist/umd/{src/tools → tools}/RetrieveProfileTool.d.ts +4 -4
  86. package/dist/{cjs/src → umd}/tools/SendMessageToConnectionTool.d.ts +6 -6
  87. package/dist/{es/src → umd}/tools/SendMessageTool.d.ts +6 -6
  88. package/package.json +2 -2
  89. package/src/hcs10/HCS10Client.ts +3 -7
  90. package/src/init/index.ts +1 -0
  91. package/src/{init.ts → init/init.ts} +22 -20
  92. package/src/tools/InitiateConnectionTool.ts +13 -13
  93. package/dist/umd/src/index.d.ts +0 -5
  94. /package/dist/cjs/{src/agents → agents}/index.d.ts +0 -0
  95. /package/dist/cjs/{src/hcs10 → hcs10}/HCS10Client.d.ts +0 -0
  96. /package/dist/cjs/{src/hcs10 → hcs10}/index.d.ts +0 -0
  97. /package/dist/cjs/{src/hcs10 → hcs10}/types.d.ts +0 -0
  98. /package/dist/cjs/{src/index.d.ts → index.d.ts} +0 -0
  99. /package/dist/cjs/{src/plugins → plugins}/BasePlugin.d.ts +0 -0
  100. /package/dist/cjs/{src/plugins → plugins}/GenericPlugin.d.ts +0 -0
  101. /package/dist/cjs/{src/plugins → plugins}/HCS10Plugin.d.ts +0 -0
  102. /package/dist/cjs/{src/plugins → plugins}/PluginInterface.d.ts +0 -0
  103. /package/dist/cjs/{src/plugins → plugins}/PluginLoader.d.ts +0 -0
  104. /package/dist/cjs/{src/plugins → plugins}/PluginRegistry.d.ts +0 -0
  105. /package/dist/cjs/{src/plugins → plugins}/defi/index.d.ts +0 -0
  106. /package/dist/cjs/{src/plugins → plugins}/hedera/HbarPricePlugin.d.ts +0 -0
  107. /package/dist/cjs/{src/plugins → plugins}/hedera/index.d.ts +0 -0
  108. /package/dist/cjs/{src/plugins → plugins}/index.d.ts +0 -0
  109. /package/dist/cjs/{src/plugins → plugins}/openconvai/OpenConvAIPlugin.d.ts +0 -0
  110. /package/dist/cjs/{src/plugins → plugins}/openconvai/index.d.ts +0 -0
  111. /package/dist/cjs/{src/plugins → plugins}/weather/index.d.ts +0 -0
  112. /package/dist/cjs/{src/state → state}/index.d.ts +0 -0
  113. /package/dist/cjs/{src/state → state}/open-convai-state.d.ts +0 -0
  114. /package/dist/cjs/{src/state → state}/state-types.d.ts +0 -0
  115. /package/dist/cjs/{src/tools → tools}/ConnectionTool.d.ts +0 -0
  116. /package/dist/cjs/{src/tools → tools}/index.d.ts +0 -0
  117. /package/dist/cjs/{src/utils → utils}/Encryption.d.ts +0 -0
  118. /package/dist/cjs/{src/utils → utils}/HederaClient.d.ts +0 -0
  119. /package/dist/cjs/{src/utils → utils}/connectionUtils.d.ts +0 -0
  120. /package/dist/cjs/{src/utils → utils}/ensure-agent-has-hbar.d.ts +0 -0
  121. /package/dist/cjs/{src/utils → utils}/state-tools.d.ts +0 -0
  122. /package/dist/es/{src/agents → agents}/index.d.ts +0 -0
  123. /package/dist/es/{src/hcs10 → hcs10}/HCS10Client.d.ts +0 -0
  124. /package/dist/es/{src/hcs10 → hcs10}/index.d.ts +0 -0
  125. /package/dist/es/{src/hcs10 → hcs10}/types.d.ts +0 -0
  126. /package/dist/es/{src/plugins → plugins}/BasePlugin.d.ts +0 -0
  127. /package/dist/es/{src/plugins → plugins}/GenericPlugin.d.ts +0 -0
  128. /package/dist/es/{src/plugins → plugins}/HCS10Plugin.d.ts +0 -0
  129. /package/dist/es/{src/plugins → plugins}/PluginInterface.d.ts +0 -0
  130. /package/dist/es/{src/plugins → plugins}/PluginLoader.d.ts +0 -0
  131. /package/dist/es/{src/plugins → plugins}/PluginRegistry.d.ts +0 -0
  132. /package/dist/es/{src/plugins → plugins}/defi/index.d.ts +0 -0
  133. /package/dist/es/{src/plugins → plugins}/hedera/HbarPricePlugin.d.ts +0 -0
  134. /package/dist/es/{src/plugins → plugins}/hedera/index.d.ts +0 -0
  135. /package/dist/es/{src/plugins → plugins}/index.d.ts +0 -0
  136. /package/dist/es/{src/plugins → plugins}/openconvai/OpenConvAIPlugin.d.ts +0 -0
  137. /package/dist/es/{src/plugins → plugins}/openconvai/index.d.ts +0 -0
  138. /package/dist/es/{src/plugins → plugins}/weather/index.d.ts +0 -0
  139. /package/dist/es/{src/state → state}/index.d.ts +0 -0
  140. /package/dist/es/{src/state → state}/open-convai-state.d.ts +0 -0
  141. /package/dist/es/{src/state → state}/state-types.d.ts +0 -0
  142. /package/dist/es/{src/tools → tools}/ConnectionTool.d.ts +0 -0
  143. /package/dist/es/{src/tools → tools}/index.d.ts +0 -0
  144. /package/dist/es/{src/utils → utils}/Encryption.d.ts +0 -0
  145. /package/dist/es/{src/utils → utils}/HederaClient.d.ts +0 -0
  146. /package/dist/es/{src/utils → utils}/connectionUtils.d.ts +0 -0
  147. /package/dist/es/{src/utils → utils}/ensure-agent-has-hbar.d.ts +0 -0
  148. /package/dist/es/{src/utils → utils}/state-tools.d.ts +0 -0
  149. /package/dist/umd/{src/agents → agents}/index.d.ts +0 -0
  150. /package/dist/umd/{src/hcs10 → hcs10}/HCS10Client.d.ts +0 -0
  151. /package/dist/umd/{src/hcs10 → hcs10}/index.d.ts +0 -0
  152. /package/dist/umd/{src/hcs10 → hcs10}/types.d.ts +0 -0
  153. /package/dist/{es/src → umd}/index.d.ts +0 -0
  154. /package/dist/umd/{src/plugins → plugins}/BasePlugin.d.ts +0 -0
  155. /package/dist/umd/{src/plugins → plugins}/GenericPlugin.d.ts +0 -0
  156. /package/dist/umd/{src/plugins → plugins}/HCS10Plugin.d.ts +0 -0
  157. /package/dist/umd/{src/plugins → plugins}/PluginInterface.d.ts +0 -0
  158. /package/dist/umd/{src/plugins → plugins}/PluginLoader.d.ts +0 -0
  159. /package/dist/umd/{src/plugins → plugins}/PluginRegistry.d.ts +0 -0
  160. /package/dist/umd/{src/plugins → plugins}/defi/index.d.ts +0 -0
  161. /package/dist/umd/{src/plugins → plugins}/hedera/HbarPricePlugin.d.ts +0 -0
  162. /package/dist/umd/{src/plugins → plugins}/hedera/index.d.ts +0 -0
  163. /package/dist/umd/{src/plugins → plugins}/index.d.ts +0 -0
  164. /package/dist/umd/{src/plugins → plugins}/openconvai/OpenConvAIPlugin.d.ts +0 -0
  165. /package/dist/umd/{src/plugins → plugins}/openconvai/index.d.ts +0 -0
  166. /package/dist/umd/{src/plugins → plugins}/weather/index.d.ts +0 -0
  167. /package/dist/umd/{src/state → state}/index.d.ts +0 -0
  168. /package/dist/umd/{src/state → state}/open-convai-state.d.ts +0 -0
  169. /package/dist/umd/{src/state → state}/state-types.d.ts +0 -0
  170. /package/dist/umd/{src/tools → tools}/ConnectionTool.d.ts +0 -0
  171. /package/dist/umd/{src/tools → tools}/index.d.ts +0 -0
  172. /package/dist/umd/{src/utils → utils}/Encryption.d.ts +0 -0
  173. /package/dist/umd/{src/utils → utils}/HederaClient.d.ts +0 -0
  174. /package/dist/umd/{src/utils → utils}/connectionUtils.d.ts +0 -0
  175. /package/dist/umd/{src/utils → utils}/ensure-agent-has-hbar.d.ts +0 -0
  176. /package/dist/umd/{src/utils → utils}/state-tools.d.ts +0 -0
@@ -1,331 +1,394 @@
1
- import { HCS10Client as HCS10Client$1, Logger, AgentBuilder, AIAgentCapability, InboundTopicType } from "@hashgraphonline/standards-sdk";
2
- import { encryptMessage } from "./standards-agent-kit.es25.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
- }
48
- }
49
- /**
50
- * Retrieves the profile for a given account ID using the standard SDK.
51
- */
52
- async getAgentProfile(accountId) {
53
- return this.standardClient.retrieveProfile(accountId);
54
- }
1
+ import { Logger, AIAgentCapability, FeeConfigBuilder } from "@hashgraphonline/standards-sdk";
2
+ import { ensureAgentHasEnoughHbar } from "./standards-agent-kit.es24.js";
3
+ import { StructuredTool } from "@langchain/core/tools";
4
+ import { z } from "zod";
5
+ import fs__default from "fs";
6
+ import path__default from "path";
7
+ import axios from "axios";
8
+ class RegisterAgentTool extends StructuredTool {
55
9
  /**
56
- * Exposes the standard SDK's submitConnectionRequest method.
10
+ * Creates a new RegisterAgentTool instance
11
+ * @param client - Instance of HCS10Client (already configured with operator/network)
12
+ * @param stateManager - Optional state manager to store agent details
57
13
  */
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
- );
14
+ constructor(client, stateManager) {
15
+ super();
16
+ this.name = "register_agent";
17
+ this.description = "Creates and registers the AI agent on the Hedera network. Returns JSON string with agent details (accountId, privateKey, topics) on success. Optionally supports fee configuration for the agent's inbound topic using HBAR or specific tokens.";
18
+ this.schema = z.object({
19
+ name: z.string().describe("The name of the agent to register"),
20
+ description: z.string().optional().describe("Optional description of the agent"),
21
+ type: z.enum(["autonomous", "manual"]).optional().describe("Optional agent type (default: autonomous)"),
22
+ model: z.string().optional().describe("Optional model identifier for the agent"),
23
+ capabilities: z.array(z.number()).optional().describe(
24
+ "Optional array of AIAgentCapability enum values (0-18). If not provided, defaults to just TEXT_GENERATION (0)"
25
+ ),
26
+ profilePicture: z.union([
27
+ z.string().describe("Path to a local image file or URL to an image"),
28
+ z.object({
29
+ url: z.string().describe("URL to an image file"),
30
+ filename: z.string().describe("Filename to use for the image")
31
+ }),
32
+ z.object({
33
+ path: z.string().describe("Path to a local image file"),
34
+ filename: z.string().optional().describe("Optional custom filename")
35
+ })
36
+ ]).optional().describe(
37
+ "Optional profile picture for the agent (local file path or URL)"
38
+ ),
39
+ feeCollectorAccountId: z.string().optional().describe(
40
+ "The account ID to collect fees. If not specified, the new agent's account ID will be used. Required if any fee is specified."
41
+ ),
42
+ hbarFee: z.number().optional().describe(
43
+ "Optional: The fee amount in HBAR to charge per message on the inbound topic (e.g., 0.5). If specified, inboundTopicType will be set to FEE_BASED."
44
+ ),
45
+ tokenFee: z.object({
46
+ amount: z.number(),
47
+ tokenId: z.string()
48
+ }).optional().describe(
49
+ 'Optional: The fee amount and token ID to charge per message on the inbound topic (e.g., { amount: 10, tokenId: "0.0.12345" }). If specified, inboundTopicType will be set to FEE_BASED.'
50
+ ),
51
+ hbarFees: z.array(
52
+ z.object({
53
+ amount: z.number(),
54
+ collectorAccount: z.string().optional()
55
+ })
56
+ ).optional().describe(
57
+ "Optional: Array of HBAR fees with different collectors. If specified, inboundTopicType will be set to FEE_BASED."
58
+ ),
59
+ tokenFees: z.array(
60
+ z.object({
61
+ amount: z.number(),
62
+ tokenId: z.string(),
63
+ collectorAccount: z.string().optional()
64
+ })
65
+ ).optional().describe(
66
+ "Optional: Array of token fees with different collectors. If specified, inboundTopicType will be set to FEE_BASED."
67
+ ),
68
+ exemptAccountIds: z.array(z.string()).optional().describe(
69
+ "Optional: Array of account IDs to exempt from ALL fees set for this agent."
70
+ ),
71
+ setAsCurrent: z.boolean().optional().describe(
72
+ "Optional: Whether to set the newly registered agent as the current active agent in the state manager. Default: true"
73
+ ),
74
+ persistence: z.object({
75
+ prefix: z.string().optional()
76
+ }).optional().describe(
77
+ "Optional: Configuration for persisting agent data to environment variables. The prefix will determine the environment variable names (e.g., PREFIX_ACCOUNT_ID). Defaults to TODD if not specified."
78
+ )
79
+ });
80
+ this.client = client;
81
+ this.stateManager = stateManager;
74
82
  }
75
83
  /**
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.
84
+ * Loads a profile picture from a local file or URL and returns a buffer
85
+ * @param profilePicture - Local file path or URL
86
+ * @returns Object containing buffer and filename
87
87
  */
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
- }
88
+ async loadProfilePicture(profilePicture) {
89
+ const logger = Logger.getInstance({
90
+ level: "debug"
91
+ });
122
92
  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
- };
93
+ if (!profilePicture) {
94
+ return null;
95
+ }
96
+ if (typeof profilePicture === "string") {
97
+ const isUrl = profilePicture.startsWith("http://") || profilePicture.startsWith("https://");
98
+ if (isUrl) {
99
+ logger.info(`Loading profile picture from URL: ${profilePicture}`);
100
+ const response = await axios.get(profilePicture, {
101
+ responseType: "arraybuffer"
102
+ });
103
+ const buffer = Buffer.from(response.data);
104
+ const urlPathname = new URL(profilePicture).pathname;
105
+ const filename = path__default.basename(urlPathname) || "profile.png";
106
+ return { buffer, filename };
107
+ } else {
108
+ if (!fs__default.existsSync(profilePicture)) {
109
+ logger.warn(`Profile picture file not found: ${profilePicture}`);
110
+ return null;
111
+ }
112
+ logger.info(`Loading profile picture from file: ${profilePicture}`);
113
+ const buffer = fs__default.readFileSync(profilePicture);
114
+ const filename = path__default.basename(profilePicture);
115
+ return { buffer, filename };
116
+ }
117
+ }
118
+ if ("url" in profilePicture) {
119
+ logger.info(`Loading profile picture from URL: ${profilePicture.url}`);
120
+ const response = await axios.get(profilePicture.url, {
121
+ responseType: "arraybuffer"
122
+ });
123
+ const buffer = Buffer.from(response.data);
124
+ const filename = profilePicture.filename || "profile.png";
125
+ return { buffer, filename };
126
+ }
127
+ if ("path" in profilePicture) {
128
+ if (!fs__default.existsSync(profilePicture.path)) {
129
+ logger.warn(`Profile picture file not found: ${profilePicture.path}`);
130
+ return null;
131
+ }
132
+ logger.info(
133
+ `Loading profile picture from file: ${profilePicture.path}`
134
+ );
135
+ const buffer = fs__default.readFileSync(profilePicture.path);
136
+ const filename = profilePicture.filename || path__default.basename(profilePicture.path);
137
+ return { buffer, filename };
132
138
  }
133
- return result;
139
+ return null;
134
140
  } 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
- );
141
+ logger.error("Failed to load profile picture:", error);
142
+ return null;
139
143
  }
140
144
  }
141
145
  /**
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.
146
+ * Calls createAndRegisterAgent() with the provided metadata.
147
+ * Returns a JSON string with agent details on success, or an error string.
151
148
  */
152
- async sendMessage(topicId, data, memo, submitKey) {
153
- if (this.useEncryption) {
154
- data = encryptMessage(data);
149
+ async _call(input) {
150
+ const logger = Logger.getInstance({
151
+ level: "debug"
152
+ });
153
+ const metadata = {
154
+ name: input.name,
155
+ description: input.description,
156
+ type: input.type,
157
+ model: input.model,
158
+ capabilities: input.capabilities || [AIAgentCapability.TEXT_GENERATION],
159
+ properties: {}
160
+ };
161
+ let profilePictureSource = "";
162
+ if (input.profilePicture) {
163
+ const profilePictureData = await this.loadProfilePicture(
164
+ input.profilePicture
165
+ );
166
+ if (profilePictureData) {
167
+ const { buffer, filename } = profilePictureData;
168
+ metadata.pfpBuffer = buffer;
169
+ metadata.pfpFileName = filename;
170
+ if (typeof input.profilePicture === "string") {
171
+ profilePictureSource = input.profilePicture;
172
+ } else if ("url" in input.profilePicture) {
173
+ profilePictureSource = input.profilePicture.url;
174
+ } else if ("path" in input.profilePicture) {
175
+ profilePictureSource = input.profilePicture.path;
176
+ }
177
+ }
178
+ }
179
+ const hasHbarFee = input.hbarFee !== void 0 && input.hbarFee > 0;
180
+ const hasTokenFee = this.hasValidTokenFee(input.tokenFee);
181
+ const hasHbarFees = input.hbarFees && input.hbarFees.length > 0;
182
+ const hasTokenFees = input.tokenFees && input.tokenFees.length > 0;
183
+ if (hasHbarFee || hasTokenFee || hasHbarFees || hasTokenFees) {
184
+ const { accountId: operatorAccountId } = this.client.getAccountAndSigner();
185
+ const collectorId = input.feeCollectorAccountId || operatorAccountId;
186
+ if (!collectorId) {
187
+ return "Error: Fee collector account ID is required when specifying fees and could not be determined.";
188
+ }
189
+ const feeConfigBuilder = new FeeConfigBuilder({
190
+ network: this.client.getNetwork(),
191
+ logger
192
+ });
193
+ try {
194
+ const exemptAccountIds = input.exemptAccountIds?.filter(
195
+ (id) => id !== collectorId && id.startsWith("0.0")
196
+ ) || [];
197
+ let updatedFeeConfig = feeConfigBuilder;
198
+ if (hasHbarFee) {
199
+ logger.info(
200
+ `Adding HBAR fee: ${input.hbarFee} HBAR to be collected by ${collectorId}`
201
+ );
202
+ updatedFeeConfig = updatedFeeConfig.addHbarFee(
203
+ input.hbarFee,
204
+ collectorId,
205
+ exemptAccountIds
206
+ );
207
+ }
208
+ if (hasHbarFees) {
209
+ for (const fee of input.hbarFees) {
210
+ const feeCollector = fee.collectorAccount || collectorId;
211
+ logger.info(
212
+ `Adding HBAR fee: ${fee.amount} HBAR to be collected by ${feeCollector}`
213
+ );
214
+ updatedFeeConfig = updatedFeeConfig.addHbarFee(
215
+ fee.amount,
216
+ feeCollector,
217
+ exemptAccountIds
218
+ );
219
+ }
220
+ }
221
+ if (hasTokenFee) {
222
+ logger.info(
223
+ `Adding token fee: ${input.tokenFee.amount} of token ${input.tokenFee.tokenId} to be collected by ${collectorId}`
224
+ );
225
+ updatedFeeConfig = await updatedFeeConfig.addTokenFee(
226
+ input.tokenFee.amount,
227
+ input.tokenFee.tokenId,
228
+ collectorId,
229
+ void 0,
230
+ exemptAccountIds
231
+ );
232
+ }
233
+ if (hasTokenFees) {
234
+ for (const fee of input.tokenFees) {
235
+ const feeCollector = fee.collectorAccount || collectorId;
236
+ logger.info(
237
+ `Adding token fee: ${fee.amount} of token ${fee.tokenId} to be collected by ${feeCollector}`
238
+ );
239
+ updatedFeeConfig = await updatedFeeConfig.addTokenFee(
240
+ fee.amount,
241
+ fee.tokenId,
242
+ feeCollector,
243
+ void 0,
244
+ exemptAccountIds
245
+ );
246
+ }
247
+ }
248
+ metadata.feeConfig = updatedFeeConfig;
249
+ logger.info("FeeConfigBuilder created successfully");
250
+ } catch (error) {
251
+ return `Error: Failed to configure fees. Reason: ${error instanceof Error ? error.message : String(error)}`;
252
+ }
155
253
  }
156
254
  try {
157
- const messageResponse = await this.standardClient.sendMessage(
158
- topicId,
159
- data,
160
- memo,
161
- submitKey
255
+ logger.info("Registering agent with metadata");
256
+ const result = await this.client.createAndRegisterAgent(
257
+ metadata
162
258
  );
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)}`
259
+ return this.processRegistrationResult(
260
+ result,
261
+ input,
262
+ profilePictureSource
168
263
  );
264
+ } catch (error) {
265
+ return `Error: Failed to create/register agent "${input.name}". Reason: ${error instanceof Error ? error.message : String(error)}`;
169
266
  }
170
267
  }
171
268
  /**
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.
269
+ * Checks if the token fee configuration is valid
176
270
  */
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
- return this.standardClient.getMessageStream(topicId);
271
+ hasValidTokenFee(tokenFee) {
272
+ return !!(tokenFee && tokenFee.amount > 0 && tokenFee.tokenId && tokenFee.tokenId.trim() !== "");
200
273
  }
201
274
  /**
202
- * Retrieves content from an inscribed message using the standard SDK client.
203
- * @param inscriptionIdOrData - The inscription ID (hcs://...) or potentially raw data string.
204
- * @returns The resolved message content.
275
+ * Processes the registration result and returns formatted output
205
276
  */
206
- async getMessageContent(inscriptionIdOrData) {
207
- try {
208
- const content = await this.standardClient.getMessageContent(
209
- inscriptionIdOrData
210
- );
211
- return content;
212
- } catch (error) {
213
- this.logger.error(
214
- `Error retrieving message content for: ${inscriptionIdOrData}`,
215
- error
216
- );
217
- throw new Error(
218
- `Failed to retrieve message content: ${error instanceof Error ? error.message : String(error)}`
219
- );
277
+ async processRegistrationResult(result, input, profilePictureSource = "") {
278
+ const newAgentAccountId = result?.metadata?.accountId || "";
279
+ const inboundTopicId = result?.metadata?.inboundTopicId || "";
280
+ const outboundTopicId = result?.metadata?.outboundTopicId || "";
281
+ const profileTopicId = result?.metadata?.profileTopicId || "";
282
+ const privateKey = result?.metadata?.privateKey || "";
283
+ const pfpTopicId = result?.metadata?.pfpTopicId;
284
+ this.validateRegistrationResult(
285
+ newAgentAccountId,
286
+ inboundTopicId,
287
+ outboundTopicId,
288
+ privateKey
289
+ );
290
+ if (this.stateManager && privateKey && newAgentAccountId && inboundTopicId && outboundTopicId && (input.setAsCurrent === void 0 || input.setAsCurrent)) {
291
+ const agent = {
292
+ name: input.name,
293
+ accountId: newAgentAccountId,
294
+ inboundTopicId,
295
+ outboundTopicId,
296
+ profileTopicId,
297
+ privateKey,
298
+ pfpTopicId
299
+ };
300
+ this.stateManager.setCurrentAgent(agent);
301
+ if (this.stateManager.persistAgentData && input.persistence) {
302
+ try {
303
+ const persistenceOptions = {
304
+ type: "env-file",
305
+ prefix: input.persistence.prefix
306
+ };
307
+ await this.stateManager.persistAgentData(agent, persistenceOptions);
308
+ } catch (error) {
309
+ Logger.getInstance().warn("Failed to persist agent data", error);
310
+ }
311
+ }
312
+ }
313
+ await this.ensureAgentHasFunds(newAgentAccountId, input.name);
314
+ const feeDescription = this.createFeeDescription(input);
315
+ const feeMessage = feeDescription ? ` with ${feeDescription} fee on inbound topic` : "";
316
+ const registrationDetails = {
317
+ success: true,
318
+ message: `Successfully registered agent '${input.name}'${feeMessage}.`,
319
+ name: input.name,
320
+ accountId: newAgentAccountId,
321
+ privateKey,
322
+ inboundTopicId,
323
+ outboundTopicId,
324
+ profileTopicId: profileTopicId || "N/A",
325
+ capabilities: input.capabilities || [AIAgentCapability.TEXT_GENERATION],
326
+ hasFees: !!(input.hbarFee || this.hasValidTokenFee(input.tokenFee)),
327
+ hbarFee: input.hbarFee || 0,
328
+ tokenFee: input.tokenFee || null
329
+ };
330
+ if (pfpTopicId || profilePictureSource) {
331
+ registrationDetails.profilePicture = {
332
+ source: profilePictureSource,
333
+ topicId: pfpTopicId
334
+ };
220
335
  }
336
+ return JSON.stringify(registrationDetails);
221
337
  }
222
338
  /**
223
- * Retrieves the inbound topic ID associated with the current operator.
224
- * This typically involves fetching the operator's own HCS-10 profile.
225
- * @returns A promise that resolves to the operator's inbound topic ID.
226
- * @throws {Error} If the operator ID cannot be determined or the profile/topic cannot be retrieved.
339
+ * Ensures the agent has enough HBAR for operations
227
340
  */
228
- async getInboundTopicId() {
341
+ async ensureAgentHasFunds(accountId, agentName) {
229
342
  try {
230
- const operatorId = this.getOperatorId();
231
- this.logger.info(
232
- `[HCS10Client] Retrieving profile for operator ${operatorId} to find inbound topic...`
343
+ await ensureAgentHasEnoughHbar(
344
+ Logger.getInstance({
345
+ module: "RegisterAgentTool"
346
+ }),
347
+ this.client.standardClient,
348
+ accountId,
349
+ agentName
233
350
  );
234
- const profileResponse = await this.getAgentProfile(operatorId);
235
- if (profileResponse.success && profileResponse.topicInfo?.inboundTopic) {
236
- this.logger.info(
237
- `[HCS10Client] Found inbound topic for operator ${operatorId}: ${profileResponse.topicInfo.inboundTopic}`
238
- );
239
- return profileResponse.topicInfo.inboundTopic;
240
- } else {
241
- throw new Error(
242
- `Could not retrieve inbound topic from profile for ${operatorId}. Profile success: ${profileResponse.success}, Error: ${profileResponse.error}`
243
- );
244
- }
245
351
  } catch (error) {
246
- this.logger.error(
247
- `[HCS10Client] Error fetching operator's inbound topic ID (${this.getOperatorId()}):`,
248
- error
249
- );
250
- const operatorId = this.getOperatorId();
251
- let detailedMessage = `Failed to get inbound topic ID for operator ${operatorId}.`;
252
- if (error instanceof Error && error.message.includes("does not have a valid HCS-11 memo")) {
253
- 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).`;
254
- } else if (error instanceof Error) {
255
- detailedMessage += ` Reason: ${error.message}`;
256
- } else {
257
- detailedMessage += ` Unexpected error: ${String(error)}`;
258
- }
259
- throw new Error(detailedMessage);
352
+ Logger.getInstance().error("Failed to auto fund agent", error);
260
353
  }
261
354
  }
262
355
  /**
263
- * Retrieves the configured operator account ID and private key.
264
- * Required by tools needing to identify the current agent instance.
265
- */
266
- getAccountAndSigner() {
267
- const result = this.standardClient.getAccountAndSigner();
268
- return {
269
- accountId: result.accountId,
270
- signer: result.signer
271
- };
272
- }
273
- /**
274
- * Retrieves the outbound topic ID for the current operator.
275
- * Fetches the operator's profile if necessary.
276
- * @returns The outbound topic ID string.
277
- * @throws If the outbound topic cannot be determined.
356
+ * Validates that all required fields are present in the registration result
278
357
  */
279
- async getOutboundTopicId() {
280
- const operatorId = this.getOperatorId();
281
- const profile = await this.getAgentProfile(operatorId);
282
- if (profile.success && profile.topicInfo?.outboundTopic) {
283
- return profile.topicInfo.outboundTopic;
284
- } else {
358
+ validateRegistrationResult(accountId, inboundTopicId, outboundTopicId, privateKey) {
359
+ if (!accountId || !inboundTopicId || !outboundTopicId || !privateKey) {
360
+ const missingFields = [
361
+ !accountId && "accountId",
362
+ !inboundTopicId && "inboundTopicId",
363
+ !outboundTopicId && "outboundTopicId",
364
+ !privateKey && "privateKey"
365
+ ].filter(Boolean).join(", ");
285
366
  throw new Error(
286
- `Could not retrieve outbound topic from profile for ${operatorId}. Profile success: ${profile.success}, Error: ${profile.error}`
367
+ `Registration failed. The HCS client returned incomplete details (Missing: ${missingFields}).`
287
368
  );
288
369
  }
289
370
  }
290
- setClient(accountId, privateKey) {
291
- this.standardClient = new HCS10Client$1({
292
- network: this.getNetwork(),
293
- operatorId: accountId,
294
- operatorPrivateKey: privateKey,
295
- guardedRegistryBaseUrl: this.guardedRegistryBaseUrl
296
- });
297
- return this.standardClient;
298
- }
299
371
  /**
300
- * Validates that the operator account exists and has proper access for agent operations
372
+ * Creates a description of the fees configured for the agent
301
373
  */
302
- async validateOperator(options) {
303
- try {
304
- this.setClient(options.accountId, options.privateKey);
305
- const operatorId = this.getOperatorId();
306
- return {
307
- isValid: true,
308
- operator: { accountId: operatorId }
309
- };
310
- } catch (error) {
311
- this.logger.error(`Validation error: ${error}`);
312
- return {
313
- isValid: false,
314
- error: error instanceof Error ? error.message : String(error)
315
- };
374
+ createFeeDescription(input) {
375
+ const hasHbarFee = input.hbarFee && input.hbarFee > 0;
376
+ const hasTokenFee = this.hasValidTokenFee(input.tokenFee);
377
+ if (!hasHbarFee && !hasTokenFee) {
378
+ return "";
316
379
  }
317
- }
318
- async initializeWithValidation(options) {
319
- const validationResult = await this.validateOperator(options);
320
- if (validationResult.isValid) {
321
- if (options.stateManager) {
322
- options.stateManager.initializeConnectionsManager(this.standardClient);
323
- }
380
+ let description = "";
381
+ if (hasHbarFee) {
382
+ description += `${input.hbarFee} HBAR`;
383
+ }
384
+ if (hasTokenFee && input.tokenFee) {
385
+ const tokenFeeText = `${input.tokenFee.amount} of token ${input.tokenFee.tokenId}`;
386
+ description += description ? ` and ${tokenFeeText}` : tokenFeeText;
324
387
  }
325
- return validationResult;
388
+ return description;
326
389
  }
327
390
  }
328
391
  export {
329
- HCS10Client
392
+ RegisterAgentTool
330
393
  };
331
394
  //# sourceMappingURL=standards-agent-kit.es3.js.map