@hashgraphonline/standards-agent-kit 0.0.37 → 0.2.0

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 (251) hide show
  1. package/dist/cjs/builders/hcs10/hcs10-builder.d.ts +262 -0
  2. package/dist/cjs/builders/index.d.ts +2 -0
  3. package/dist/cjs/builders/types.d.ts +10 -0
  4. package/dist/cjs/index.d.ts +3 -1
  5. package/dist/cjs/init/init.d.ts +21 -22
  6. package/dist/cjs/plugins/PluginInterface.d.ts +4 -80
  7. package/dist/cjs/plugins/PluginRegistry.d.ts +1 -47
  8. package/dist/cjs/plugins/defi/index.d.ts +7 -4
  9. package/dist/cjs/plugins/hedera/HbarPricePlugin.d.ts +7 -35
  10. package/dist/cjs/plugins/index.d.ts +0 -5
  11. package/dist/cjs/plugins/weather/index.d.ts +6 -5
  12. package/dist/cjs/standards-agent-kit.cjs +1 -1
  13. package/dist/cjs/standards-agent-kit.cjs.map +1 -1
  14. package/dist/cjs/state/state-types.d.ts +8 -8
  15. package/dist/cjs/tools/hcs10/AcceptConnectionRequestTool.d.ts +40 -0
  16. package/dist/cjs/tools/hcs10/CheckMessagesTool.d.ts +40 -0
  17. package/dist/cjs/tools/hcs10/ConnectionMonitorTool.d.ts +134 -0
  18. package/dist/cjs/tools/hcs10/FindRegistrationsTool.d.ts +34 -0
  19. package/dist/cjs/tools/hcs10/InitiateConnectionTool.d.ts +43 -0
  20. package/dist/cjs/tools/hcs10/ListConnectionsTool.d.ts +34 -0
  21. package/dist/cjs/tools/hcs10/ListUnapprovedConnectionRequestsTool.d.ts +15 -0
  22. package/dist/cjs/tools/hcs10/ManageConnectionRequestsTool.d.ts +34 -0
  23. package/dist/cjs/tools/hcs10/RegisterAgentTool.d.ts +218 -0
  24. package/dist/cjs/tools/hcs10/RetrieveProfileTool.d.ts +33 -0
  25. package/dist/cjs/tools/hcs10/SendMessageToConnectionTool.d.ts +40 -0
  26. package/dist/cjs/tools/hcs10/base-hcs10-tools.d.ts +28 -0
  27. package/dist/cjs/tools/hcs10/hcs10-tool-params.d.ts +18 -0
  28. package/dist/cjs/tools/hcs10/index.d.ts +13 -0
  29. package/dist/cjs/tools/index.d.ts +1 -13
  30. package/dist/es/builders/hcs10/hcs10-builder.d.ts +262 -0
  31. package/dist/es/builders/index.d.ts +2 -0
  32. package/dist/es/builders/types.d.ts +10 -0
  33. package/dist/es/index.d.ts +3 -1
  34. package/dist/es/init/init.d.ts +21 -22
  35. package/dist/es/plugins/PluginInterface.d.ts +4 -80
  36. package/dist/es/plugins/PluginRegistry.d.ts +1 -47
  37. package/dist/es/plugins/defi/index.d.ts +7 -4
  38. package/dist/es/plugins/hedera/HbarPricePlugin.d.ts +7 -35
  39. package/dist/es/plugins/index.d.ts +0 -5
  40. package/dist/es/plugins/weather/index.d.ts +6 -5
  41. package/dist/es/standards-agent-kit.es.js +10 -18
  42. package/dist/es/standards-agent-kit.es.js.map +1 -1
  43. package/dist/es/standards-agent-kit.es10.js +29 -76
  44. package/dist/es/standards-agent-kit.es10.js.map +1 -1
  45. package/dist/es/standards-agent-kit.es11.js +61 -384
  46. package/dist/es/standards-agent-kit.es11.js.map +1 -1
  47. package/dist/es/standards-agent-kit.es12.js +22 -190
  48. package/dist/es/standards-agent-kit.es12.js.map +1 -1
  49. package/dist/es/standards-agent-kit.es13.js +26 -138
  50. package/dist/es/standards-agent-kit.es13.js.map +1 -1
  51. package/dist/es/standards-agent-kit.es14.js +35 -59
  52. package/dist/es/standards-agent-kit.es14.js.map +1 -1
  53. package/dist/es/standards-agent-kit.es15.js +11 -117
  54. package/dist/es/standards-agent-kit.es15.js.map +1 -1
  55. package/dist/es/standards-agent-kit.es16.js +1 -1
  56. package/dist/es/standards-agent-kit.es16.js.map +1 -1
  57. package/dist/es/standards-agent-kit.es17.js +63 -46
  58. package/dist/es/standards-agent-kit.es17.js.map +1 -1
  59. package/dist/es/standards-agent-kit.es18.js +25 -74
  60. package/dist/es/standards-agent-kit.es18.js.map +1 -1
  61. package/dist/es/standards-agent-kit.es19.js +22 -13
  62. package/dist/es/standards-agent-kit.es19.js.map +1 -1
  63. package/dist/es/standards-agent-kit.es2.js +1381 -188
  64. package/dist/es/standards-agent-kit.es2.js.map +1 -1
  65. package/dist/es/standards-agent-kit.es20.js +3 -67
  66. package/dist/es/standards-agent-kit.es20.js.map +1 -1
  67. package/dist/es/standards-agent-kit.es3.js +285 -347
  68. package/dist/es/standards-agent-kit.es3.js.map +1 -1
  69. package/dist/es/standards-agent-kit.es4.js +22 -74
  70. package/dist/es/standards-agent-kit.es4.js.map +1 -1
  71. package/dist/es/standards-agent-kit.es5.js +127 -154
  72. package/dist/es/standards-agent-kit.es5.js.map +1 -1
  73. package/dist/es/standards-agent-kit.es6.js +21 -88
  74. package/dist/es/standards-agent-kit.es6.js.map +1 -1
  75. package/dist/es/standards-agent-kit.es7.js +28 -86
  76. package/dist/es/standards-agent-kit.es7.js.map +1 -1
  77. package/dist/es/standards-agent-kit.es8.js +27 -100
  78. package/dist/es/standards-agent-kit.es8.js.map +1 -1
  79. package/dist/es/standards-agent-kit.es9.js +35 -117
  80. package/dist/es/standards-agent-kit.es9.js.map +1 -1
  81. package/dist/es/state/state-types.d.ts +8 -8
  82. package/dist/es/tools/hcs10/AcceptConnectionRequestTool.d.ts +40 -0
  83. package/dist/es/tools/hcs10/CheckMessagesTool.d.ts +40 -0
  84. package/dist/es/tools/hcs10/ConnectionMonitorTool.d.ts +134 -0
  85. package/dist/es/tools/hcs10/FindRegistrationsTool.d.ts +34 -0
  86. package/dist/es/tools/hcs10/InitiateConnectionTool.d.ts +43 -0
  87. package/dist/es/tools/hcs10/ListConnectionsTool.d.ts +34 -0
  88. package/dist/es/tools/hcs10/ListUnapprovedConnectionRequestsTool.d.ts +15 -0
  89. package/dist/es/tools/hcs10/ManageConnectionRequestsTool.d.ts +34 -0
  90. package/dist/es/tools/hcs10/RegisterAgentTool.d.ts +218 -0
  91. package/dist/es/tools/hcs10/RetrieveProfileTool.d.ts +33 -0
  92. package/dist/es/tools/hcs10/SendMessageToConnectionTool.d.ts +40 -0
  93. package/dist/es/tools/hcs10/base-hcs10-tools.d.ts +28 -0
  94. package/dist/es/tools/hcs10/hcs10-tool-params.d.ts +18 -0
  95. package/dist/es/tools/hcs10/index.d.ts +13 -0
  96. package/dist/es/tools/index.d.ts +1 -13
  97. package/dist/umd/builders/hcs10/hcs10-builder.d.ts +262 -0
  98. package/dist/umd/builders/index.d.ts +2 -0
  99. package/dist/umd/builders/types.d.ts +10 -0
  100. package/dist/umd/index.d.ts +3 -1
  101. package/dist/umd/init/init.d.ts +21 -22
  102. package/dist/umd/plugins/PluginInterface.d.ts +4 -80
  103. package/dist/umd/plugins/PluginRegistry.d.ts +1 -47
  104. package/dist/umd/plugins/defi/index.d.ts +7 -4
  105. package/dist/umd/plugins/hedera/HbarPricePlugin.d.ts +7 -35
  106. package/dist/umd/plugins/index.d.ts +0 -5
  107. package/dist/umd/plugins/weather/index.d.ts +6 -5
  108. package/dist/umd/standards-agent-kit.umd.js +1 -164
  109. package/dist/umd/standards-agent-kit.umd.js.map +1 -1
  110. package/dist/umd/state/state-types.d.ts +8 -8
  111. package/dist/umd/tools/hcs10/AcceptConnectionRequestTool.d.ts +40 -0
  112. package/dist/umd/tools/hcs10/CheckMessagesTool.d.ts +40 -0
  113. package/dist/umd/tools/hcs10/ConnectionMonitorTool.d.ts +134 -0
  114. package/dist/umd/tools/hcs10/FindRegistrationsTool.d.ts +34 -0
  115. package/dist/umd/tools/hcs10/InitiateConnectionTool.d.ts +43 -0
  116. package/dist/umd/tools/hcs10/ListConnectionsTool.d.ts +34 -0
  117. package/dist/umd/tools/hcs10/ListUnapprovedConnectionRequestsTool.d.ts +15 -0
  118. package/dist/umd/tools/hcs10/ManageConnectionRequestsTool.d.ts +34 -0
  119. package/dist/umd/tools/hcs10/RegisterAgentTool.d.ts +218 -0
  120. package/dist/umd/tools/hcs10/RetrieveProfileTool.d.ts +33 -0
  121. package/dist/umd/tools/hcs10/SendMessageToConnectionTool.d.ts +40 -0
  122. package/dist/umd/tools/hcs10/base-hcs10-tools.d.ts +28 -0
  123. package/dist/umd/tools/hcs10/hcs10-tool-params.d.ts +18 -0
  124. package/dist/umd/tools/hcs10/index.d.ts +13 -0
  125. package/dist/umd/tools/index.d.ts +1 -13
  126. package/package.json +41 -41
  127. package/src/builders/hcs10/hcs10-builder.ts +2108 -0
  128. package/src/builders/index.ts +2 -0
  129. package/src/builders/types.ts +11 -0
  130. package/src/hcs10/HCS10Client.ts +3 -2
  131. package/src/index.ts +4 -2
  132. package/src/init/init.ts +85 -63
  133. package/src/plugins/PluginInterface.ts +15 -94
  134. package/src/plugins/PluginRegistry.ts +2 -98
  135. package/src/plugins/defi/index.ts +31 -118
  136. package/src/plugins/hedera/HbarPricePlugin.ts +19 -100
  137. package/src/plugins/index.ts +0 -5
  138. package/src/plugins/weather/index.ts +56 -40
  139. package/src/state/state-types.ts +9 -11
  140. package/src/tools/hcs10/AcceptConnectionRequestTool.ts +56 -0
  141. package/src/tools/hcs10/CheckMessagesTool.ts +73 -0
  142. package/src/tools/hcs10/ConnectionMonitorTool.ts +111 -0
  143. package/src/tools/hcs10/FindRegistrationsTool.ts +64 -0
  144. package/src/tools/hcs10/InitiateConnectionTool.ts +66 -0
  145. package/src/tools/hcs10/ListConnectionsTool.ts +58 -0
  146. package/src/tools/hcs10/ListUnapprovedConnectionRequestsTool.ts +26 -0
  147. package/src/tools/hcs10/ManageConnectionRequestsTool.ts +48 -0
  148. package/src/tools/hcs10/RegisterAgentTool.ts +213 -0
  149. package/src/tools/hcs10/RetrieveProfileTool.ts +61 -0
  150. package/src/tools/hcs10/SendMessageToConnectionTool.ts +45 -0
  151. package/src/tools/hcs10/base-hcs10-tools.ts +65 -0
  152. package/src/tools/hcs10/hcs10-tool-params.ts +21 -0
  153. package/src/tools/hcs10/index.ts +13 -0
  154. package/src/tools/index.ts +2 -13
  155. package/src/utils/HederaClient.ts +2 -2
  156. package/src/utils/ensure-agent-has-hbar.ts +3 -4
  157. package/dist/cjs/agents/index.d.ts +0 -0
  158. package/dist/cjs/plugins/BasePlugin.d.ts +0 -28
  159. package/dist/cjs/plugins/GenericPlugin.d.ts +0 -17
  160. package/dist/cjs/plugins/HCS10Plugin.d.ts +0 -13
  161. package/dist/cjs/plugins/PluginLoader.d.ts +0 -38
  162. package/dist/cjs/plugins/openconvai/OpenConvAIPlugin.d.ts +0 -23
  163. package/dist/cjs/plugins/openconvai/index.d.ts +0 -1
  164. package/dist/cjs/tools/AcceptConnectionRequestTool.d.ts +0 -33
  165. package/dist/cjs/tools/CheckMessagesTool.d.ts +0 -34
  166. package/dist/cjs/tools/ConnectionMonitorTool.d.ts +0 -100
  167. package/dist/cjs/tools/ConnectionTool.d.ts +0 -40
  168. package/dist/cjs/tools/FindRegistrationsTool.d.ts +0 -28
  169. package/dist/cjs/tools/InitiateConnectionTool.d.ts +0 -30
  170. package/dist/cjs/tools/ListConnectionsTool.d.ts +0 -33
  171. package/dist/cjs/tools/ListUnapprovedConnectionRequestsTool.d.ts +0 -41
  172. package/dist/cjs/tools/ManageConnectionRequestsTool.d.ts +0 -38
  173. package/dist/cjs/tools/RegisterAgentTool.d.ts +0 -188
  174. package/dist/cjs/tools/RetrieveProfileTool.d.ts +0 -34
  175. package/dist/cjs/tools/SendMessageToConnectionTool.d.ts +0 -34
  176. package/dist/cjs/tools/SendMessageTool.d.ts +0 -40
  177. package/dist/es/agents/index.d.ts +0 -0
  178. package/dist/es/plugins/BasePlugin.d.ts +0 -28
  179. package/dist/es/plugins/GenericPlugin.d.ts +0 -17
  180. package/dist/es/plugins/HCS10Plugin.d.ts +0 -13
  181. package/dist/es/plugins/PluginLoader.d.ts +0 -38
  182. package/dist/es/plugins/openconvai/OpenConvAIPlugin.d.ts +0 -23
  183. package/dist/es/plugins/openconvai/index.d.ts +0 -1
  184. package/dist/es/standards-agent-kit.es21.js +0 -92
  185. package/dist/es/standards-agent-kit.es21.js.map +0 -1
  186. package/dist/es/standards-agent-kit.es22.js +0 -7
  187. package/dist/es/standards-agent-kit.es22.js.map +0 -1
  188. package/dist/es/standards-agent-kit.es23.js +0 -106
  189. package/dist/es/standards-agent-kit.es23.js.map +0 -1
  190. package/dist/es/standards-agent-kit.es24.js +0 -7
  191. package/dist/es/standards-agent-kit.es24.js.map +0 -1
  192. package/dist/es/standards-agent-kit.es25.js +0 -7
  193. package/dist/es/standards-agent-kit.es25.js.map +0 -1
  194. package/dist/es/standards-agent-kit.es26.js +0 -85
  195. package/dist/es/standards-agent-kit.es26.js.map +0 -1
  196. package/dist/es/standards-agent-kit.es27.js +0 -28
  197. package/dist/es/standards-agent-kit.es27.js.map +0 -1
  198. package/dist/es/tools/AcceptConnectionRequestTool.d.ts +0 -33
  199. package/dist/es/tools/CheckMessagesTool.d.ts +0 -34
  200. package/dist/es/tools/ConnectionMonitorTool.d.ts +0 -100
  201. package/dist/es/tools/ConnectionTool.d.ts +0 -40
  202. package/dist/es/tools/FindRegistrationsTool.d.ts +0 -28
  203. package/dist/es/tools/InitiateConnectionTool.d.ts +0 -30
  204. package/dist/es/tools/ListConnectionsTool.d.ts +0 -33
  205. package/dist/es/tools/ListUnapprovedConnectionRequestsTool.d.ts +0 -41
  206. package/dist/es/tools/ManageConnectionRequestsTool.d.ts +0 -38
  207. package/dist/es/tools/RegisterAgentTool.d.ts +0 -188
  208. package/dist/es/tools/RetrieveProfileTool.d.ts +0 -34
  209. package/dist/es/tools/SendMessageToConnectionTool.d.ts +0 -34
  210. package/dist/es/tools/SendMessageTool.d.ts +0 -40
  211. package/dist/umd/agents/index.d.ts +0 -0
  212. package/dist/umd/plugins/BasePlugin.d.ts +0 -28
  213. package/dist/umd/plugins/GenericPlugin.d.ts +0 -17
  214. package/dist/umd/plugins/HCS10Plugin.d.ts +0 -13
  215. package/dist/umd/plugins/PluginLoader.d.ts +0 -38
  216. package/dist/umd/plugins/openconvai/OpenConvAIPlugin.d.ts +0 -23
  217. package/dist/umd/plugins/openconvai/index.d.ts +0 -1
  218. package/dist/umd/tools/AcceptConnectionRequestTool.d.ts +0 -33
  219. package/dist/umd/tools/CheckMessagesTool.d.ts +0 -34
  220. package/dist/umd/tools/ConnectionMonitorTool.d.ts +0 -100
  221. package/dist/umd/tools/ConnectionTool.d.ts +0 -40
  222. package/dist/umd/tools/FindRegistrationsTool.d.ts +0 -28
  223. package/dist/umd/tools/InitiateConnectionTool.d.ts +0 -30
  224. package/dist/umd/tools/ListConnectionsTool.d.ts +0 -33
  225. package/dist/umd/tools/ListUnapprovedConnectionRequestsTool.d.ts +0 -41
  226. package/dist/umd/tools/ManageConnectionRequestsTool.d.ts +0 -38
  227. package/dist/umd/tools/RegisterAgentTool.d.ts +0 -188
  228. package/dist/umd/tools/RetrieveProfileTool.d.ts +0 -34
  229. package/dist/umd/tools/SendMessageToConnectionTool.d.ts +0 -34
  230. package/dist/umd/tools/SendMessageTool.d.ts +0 -40
  231. package/src/agents/index.ts +0 -1
  232. package/src/plugins/BasePlugin.ts +0 -37
  233. package/src/plugins/GenericPlugin.ts +0 -19
  234. package/src/plugins/HCS10Plugin.ts +0 -14
  235. package/src/plugins/PluginLoader.ts +0 -121
  236. package/src/plugins/README.md +0 -113
  237. package/src/plugins/openconvai/OpenConvAIPlugin.ts +0 -124
  238. package/src/plugins/openconvai/index.ts +0 -1
  239. package/src/tools/AcceptConnectionRequestTool.ts +0 -196
  240. package/src/tools/CheckMessagesTool.ts +0 -194
  241. package/src/tools/ConnectionMonitorTool.ts +0 -550
  242. package/src/tools/ConnectionTool.ts +0 -231
  243. package/src/tools/FindRegistrationsTool.ts +0 -114
  244. package/src/tools/InitiateConnectionTool.ts +0 -137
  245. package/src/tools/ListConnectionsTool.ts +0 -158
  246. package/src/tools/ListUnapprovedConnectionRequestsTool.ts +0 -173
  247. package/src/tools/ManageConnectionRequestsTool.ts +0 -275
  248. package/src/tools/RegisterAgentTool.ts +0 -590
  249. package/src/tools/RetrieveProfileTool.ts +0 -94
  250. package/src/tools/SendMessageToConnectionTool.ts +0 -142
  251. package/src/tools/SendMessageTool.ts +0 -116
@@ -1,394 +1,332 @@
1
- import { Logger, AIAgentCapability, FeeConfigBuilder } from "@hashgraphonline/standards-sdk";
2
- import { ensureAgentHasEnoughHbar } from "./standards-agent-kit.es26.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 {
9
- /**
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
13
- */
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
- )
1
+ import { HCS10Client as HCS10Client$1, Logger, AgentBuilder, AIAgentCapability, InboundTopicType } from "@hashgraphonline/standards-sdk";
2
+ import { encryptMessage } from "./standards-agent-kit.es20.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
79
11
  });
80
- this.client = client;
81
- this.stateManager = stateManager;
82
- }
83
- /**
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
- */
88
- async loadProfilePicture(profilePicture) {
89
- const logger = Logger.getInstance({
90
- level: "debug"
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
91
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) {
92
31
  try {
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 };
138
- }
139
- return null;
32
+ const result = await this.standardClient.handleConnectionRequest(
33
+ inboundTopicId,
34
+ requestingAccountId,
35
+ connectionRequestId,
36
+ feeConfig
37
+ );
38
+ return result;
140
39
  } catch (error) {
141
- logger.error("Failed to load profile picture:", error);
142
- return null;
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
+ );
143
47
  }
144
48
  }
145
49
  /**
146
- * Calls createAndRegisterAgent() with the provided metadata.
147
- * Returns a JSON string with agent details on success, or an error string.
50
+ * Retrieves the profile for a given account ID using the standard SDK.
148
51
  */
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
- }
52
+ async getAgentProfile(accountId) {
53
+ return this.standardClient.retrieveProfile(accountId);
54
+ }
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
+ );
74
+ }
75
+ /**
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.
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);
178
95
  }
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.";
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);
188
106
  }
189
- const feeConfigBuilder = new FeeConfigBuilder({
190
- network: this.client.getNetwork(),
191
- logger
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);
192
120
  });
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
- }
253
121
  }
254
122
  try {
255
- logger.info("Registering agent with metadata");
256
- const result = await this.client.createAndRegisterAgent(
257
- metadata
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)}`
258
138
  );
259
- return this.processRegistrationResult(
260
- result,
261
- input,
262
- profilePictureSource
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
263
162
  );
163
+ return messageResponse.topicSequenceNumber?.toNumber();
264
164
  } catch (error) {
265
- return `Error: Failed to create/register agent "${input.name}". Reason: ${error instanceof Error ? error.message : String(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
+ );
266
169
  }
267
170
  }
268
171
  /**
269
- * Checks if the token fee configuration is valid
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.
270
176
  */
271
- hasValidTokenFee(tokenFee) {
272
- return !!(tokenFee && tokenFee.amount > 0 && tokenFee.tokenId && tokenFee.tokenId.trim() !== "");
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;
273
201
  }
274
202
  /**
275
- * Processes the registration result and returns formatted output
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.
276
206
  */
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
- };
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
+ );
335
221
  }
336
- return JSON.stringify(registrationDetails);
337
222
  }
338
223
  /**
339
- * Ensures the agent has enough HBAR for operations
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.
340
228
  */
341
- async ensureAgentHasFunds(accountId, agentName) {
229
+ async getInboundTopicId() {
342
230
  try {
343
- await ensureAgentHasEnoughHbar(
344
- Logger.getInstance({
345
- module: "RegisterAgentTool"
346
- }),
347
- this.client.standardClient,
348
- accountId,
349
- agentName
231
+ const operatorId = this.getOperatorId();
232
+ this.logger.info(
233
+ `[HCS10Client] Retrieving profile for operator ${operatorId} to find inbound topic...`
350
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
+ }
351
246
  } catch (error) {
352
- Logger.getInstance().error("Failed to auto fund agent", 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);
353
261
  }
354
262
  }
355
263
  /**
356
- * Validates that all required fields are present in the registration result
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.
357
279
  */
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(", ");
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 {
366
286
  throw new Error(
367
- `Registration failed. The HCS client returned incomplete details (Missing: ${missingFields}).`
287
+ `Could not retrieve outbound topic from profile for ${operatorId}. Profile success: ${profile.success}, Error: ${profile.error}`
368
288
  );
369
289
  }
370
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
+ }
371
300
  /**
372
- * Creates a description of the fees configured for the agent
301
+ * Validates that the operator account exists and has proper access for agent operations
373
302
  */
374
- createFeeDescription(input) {
375
- const hasHbarFee = input.hbarFee && input.hbarFee > 0;
376
- const hasTokenFee = this.hasValidTokenFee(input.tokenFee);
377
- if (!hasHbarFee && !hasTokenFee) {
378
- return "";
379
- }
380
- let description = "";
381
- if (hasHbarFee) {
382
- description += `${input.hbarFee} HBAR`;
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
+ };
383
317
  }
384
- if (hasTokenFee && input.tokenFee) {
385
- const tokenFeeText = `${input.tokenFee.amount} of token ${input.tokenFee.tokenId}`;
386
- description += description ? ` and ${tokenFeeText}` : tokenFeeText;
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
+ }
387
325
  }
388
- return description;
326
+ return validationResult;
389
327
  }
390
328
  }
391
329
  export {
392
- RegisterAgentTool
330
+ HCS10Client
393
331
  };
394
332
  //# sourceMappingURL=standards-agent-kit.es3.js.map