@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,590 +0,0 @@
1
- import {
2
- AIAgentCapability,
3
- Logger,
4
- FeeConfigBuilder,
5
- } from '@hashgraphonline/standards-sdk';
6
- import { ensureAgentHasEnoughHbar } from '../utils/ensure-agent-has-hbar';
7
- import { HCS10Client, ExtendedAgentMetadata } from '../hcs10/HCS10Client';
8
- import { StructuredTool } from '@langchain/core/tools';
9
- import { z } from 'zod';
10
- import { IStateManager } from '../state/state-types';
11
- import { AgentPersistenceOptions } from '../state/state-types';
12
- import fs from 'fs';
13
- import path from 'path';
14
- import axios from 'axios';
15
-
16
- /**
17
- * Interface for HCS10 registration result
18
- */
19
- interface HCS10RegistrationResult {
20
- metadata?: {
21
- accountId?: string;
22
- inboundTopicId?: string;
23
- outboundTopicId?: string;
24
- profileTopicId?: string;
25
- privateKey?: string;
26
- capabilities?: number[];
27
- [key: string]: string | number | boolean | number[] | object | undefined;
28
- };
29
- }
30
-
31
- /**
32
- * Agent registration details returned when successful
33
- */
34
- interface AgentRegistrationDetails {
35
- success: boolean;
36
- message: string;
37
- name: string;
38
- accountId: string;
39
- privateKey: string;
40
- inboundTopicId: string;
41
- outboundTopicId: string;
42
- profileTopicId: string;
43
- capabilities: number[];
44
- hasFees: boolean;
45
- hbarFee: number;
46
- tokenFee: { amount: number; tokenId: string } | null;
47
- profilePicture?: {
48
- source: string;
49
- topicId?: string;
50
- };
51
- }
52
-
53
- /**
54
- * Profile picture input types supported by the tool
55
- */
56
- type ProfilePictureInput =
57
- | string
58
- | {
59
- url: string;
60
- filename: string;
61
- }
62
- | {
63
- path: string;
64
- filename?: string;
65
- };
66
-
67
- /**
68
- * RegisterAgentTool wraps the createAndRegisterAgent() function of HCS10Client.
69
- * It creates and registers an agent on Hedera using the HCS-10 standard SDK flow.
70
- * On success, returns a JSON string containing the new agent's details (including private key).
71
- */
72
- export class RegisterAgentTool extends StructuredTool {
73
- name = 'register_agent';
74
- description =
75
- "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.";
76
- private client: HCS10Client;
77
- private stateManager?: IStateManager;
78
-
79
- schema = z.object({
80
- name: z.string().describe('The name of the agent to register'),
81
- description: z
82
- .string()
83
- .optional()
84
- .describe('Optional description of the agent'),
85
- type: z
86
- .enum(['autonomous', 'manual'])
87
- .optional()
88
- .describe('Optional agent type (default: autonomous)'),
89
- model: z
90
- .string()
91
- .optional()
92
- .describe('Optional model identifier for the agent'),
93
- capabilities: z
94
- .array(z.number())
95
- .optional()
96
- .describe(
97
- 'Optional array of AIAgentCapability enum values (0-18). If not provided, defaults to just TEXT_GENERATION (0)'
98
- ),
99
- profilePicture: z
100
- .union([
101
- z.string().describe('Path to a local image file or URL to an image'),
102
- z.object({
103
- url: z.string().describe('URL to an image file'),
104
- filename: z.string().describe('Filename to use for the image'),
105
- }),
106
- z.object({
107
- path: z.string().describe('Path to a local image file'),
108
- filename: z.string().optional().describe('Optional custom filename'),
109
- }),
110
- ])
111
- .optional()
112
- .describe(
113
- 'Optional profile picture for the agent (local file path or URL)'
114
- ),
115
- feeCollectorAccountId: z
116
- .string()
117
- .optional()
118
- .describe(
119
- "The account ID to collect fees. If not specified, the new agent's account ID will be used. Required if any fee is specified."
120
- ),
121
- hbarFee: z
122
- .number()
123
- .optional()
124
- .describe(
125
- '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.'
126
- ),
127
- tokenFee: z
128
- .object({
129
- amount: z.number(),
130
- tokenId: z.string(),
131
- })
132
- .optional()
133
- .describe(
134
- '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.'
135
- ),
136
- hbarFees: z
137
- .array(
138
- z.object({
139
- amount: z.number(),
140
- collectorAccount: z.string().optional(),
141
- })
142
- )
143
- .optional()
144
- .describe(
145
- 'Optional: Array of HBAR fees with different collectors. If specified, inboundTopicType will be set to FEE_BASED.'
146
- ),
147
- tokenFees: z
148
- .array(
149
- z.object({
150
- amount: z.number(),
151
- tokenId: z.string(),
152
- collectorAccount: z.string().optional(),
153
- })
154
- )
155
- .optional()
156
- .describe(
157
- 'Optional: Array of token fees with different collectors. If specified, inboundTopicType will be set to FEE_BASED.'
158
- ),
159
- exemptAccountIds: z
160
- .array(z.string())
161
- .optional()
162
- .describe(
163
- 'Optional: Array of account IDs to exempt from ALL fees set for this agent.'
164
- ),
165
- setAsCurrent: z
166
- .boolean()
167
- .optional()
168
- .describe(
169
- 'Optional: Whether to set the newly registered agent as the current active agent in the state manager. Default: true'
170
- ),
171
- persistence: z
172
- .object({
173
- prefix: z.string().optional(),
174
- })
175
- .optional()
176
- .describe(
177
- '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.'
178
- ),
179
- });
180
-
181
- /**
182
- * Creates a new RegisterAgentTool instance
183
- * @param client - Instance of HCS10Client (already configured with operator/network)
184
- * @param stateManager - Optional state manager to store agent details
185
- */
186
- constructor(client: HCS10Client, stateManager?: IStateManager) {
187
- super();
188
- this.client = client;
189
- this.stateManager = stateManager;
190
- }
191
-
192
- /**
193
- * Loads a profile picture from a local file or URL and returns a buffer
194
- * @param profilePicture - Local file path or URL
195
- * @returns Object containing buffer and filename
196
- */
197
- private async loadProfilePicture(
198
- profilePicture: ProfilePictureInput
199
- ): Promise<{ buffer: Buffer; filename: string } | null> {
200
- const logger = Logger.getInstance({
201
- level: 'debug',
202
- });
203
-
204
- try {
205
- if (!profilePicture) {
206
- return null;
207
- }
208
-
209
- if (typeof profilePicture === 'string') {
210
- const isUrl =
211
- profilePicture.startsWith('http://') ||
212
- profilePicture.startsWith('https://');
213
-
214
- if (isUrl) {
215
- logger.info(`Loading profile picture from URL: ${profilePicture}`);
216
- const response = await axios.get(profilePicture, {
217
- responseType: 'arraybuffer',
218
- });
219
- const buffer = Buffer.from(response.data);
220
-
221
- const urlPathname = new URL(profilePicture).pathname;
222
- const filename = path.basename(urlPathname) || 'profile.png';
223
-
224
- return { buffer, filename };
225
- } else {
226
- if (!fs.existsSync(profilePicture)) {
227
- logger.warn(`Profile picture file not found: ${profilePicture}`);
228
- return null;
229
- }
230
-
231
- logger.info(`Loading profile picture from file: ${profilePicture}`);
232
- const buffer = fs.readFileSync(profilePicture);
233
- const filename = path.basename(profilePicture);
234
-
235
- return { buffer, filename };
236
- }
237
- }
238
-
239
- if ('url' in profilePicture) {
240
- logger.info(`Loading profile picture from URL: ${profilePicture.url}`);
241
- const response = await axios.get(profilePicture.url, {
242
- responseType: 'arraybuffer',
243
- });
244
- const buffer = Buffer.from(response.data);
245
- const filename = profilePicture.filename || 'profile.png';
246
-
247
- return { buffer, filename };
248
- }
249
-
250
- if ('path' in profilePicture) {
251
- if (!fs.existsSync(profilePicture.path)) {
252
- logger.warn(`Profile picture file not found: ${profilePicture.path}`);
253
- return null;
254
- }
255
-
256
- logger.info(
257
- `Loading profile picture from file: ${profilePicture.path}`
258
- );
259
- const buffer = fs.readFileSync(profilePicture.path);
260
- const filename =
261
- profilePicture.filename || path.basename(profilePicture.path);
262
-
263
- return { buffer, filename };
264
- }
265
-
266
- return null;
267
- } catch (error) {
268
- logger.error('Failed to load profile picture:', error);
269
- return null;
270
- }
271
- }
272
-
273
- /**
274
- * Calls createAndRegisterAgent() with the provided metadata.
275
- * Returns a JSON string with agent details on success, or an error string.
276
- */
277
- async _call(input: z.infer<typeof this.schema>): Promise<string> {
278
- const logger = Logger.getInstance({
279
- level: 'debug',
280
- });
281
-
282
- const metadata: ExtendedAgentMetadata = {
283
- name: input.name,
284
- description: input.description,
285
- type: input.type,
286
- model: input.model,
287
- capabilities: input.capabilities || [AIAgentCapability.TEXT_GENERATION],
288
- properties: {},
289
- };
290
-
291
- let profilePictureSource = '';
292
- if (input.profilePicture) {
293
- const profilePictureData = await this.loadProfilePicture(
294
- input.profilePicture
295
- );
296
- if (profilePictureData) {
297
- const { buffer, filename } = profilePictureData;
298
- metadata.pfpBuffer = buffer;
299
- metadata.pfpFileName = filename;
300
-
301
- if (typeof input.profilePicture === 'string') {
302
- profilePictureSource = input.profilePicture;
303
- } else if ('url' in input.profilePicture) {
304
- profilePictureSource = input.profilePicture.url;
305
- } else if ('path' in input.profilePicture) {
306
- profilePictureSource = input.profilePicture.path;
307
- }
308
- }
309
- }
310
-
311
- const hasHbarFee = input.hbarFee !== undefined && input.hbarFee > 0;
312
- const hasTokenFee = this.hasValidTokenFee(input.tokenFee);
313
- const hasHbarFees = input.hbarFees && input.hbarFees.length > 0;
314
- const hasTokenFees = input.tokenFees && input.tokenFees.length > 0;
315
-
316
- if (hasHbarFee || hasTokenFee || hasHbarFees || hasTokenFees) {
317
- const { accountId: operatorAccountId } =
318
- this.client.getAccountAndSigner();
319
- const collectorId = input.feeCollectorAccountId || operatorAccountId;
320
-
321
- if (!collectorId) {
322
- return 'Error: Fee collector account ID is required when specifying fees and could not be determined.';
323
- }
324
-
325
- const feeConfigBuilder = new FeeConfigBuilder({
326
- network: this.client.getNetwork(),
327
- logger,
328
- });
329
-
330
- try {
331
- const exemptAccountIds =
332
- input.exemptAccountIds?.filter(
333
- (id) => id !== collectorId && id.startsWith('0.0')
334
- ) || [];
335
-
336
- let updatedFeeConfig = feeConfigBuilder;
337
-
338
- if (hasHbarFee) {
339
- logger.info(
340
- `Adding HBAR fee: ${input.hbarFee} HBAR to be collected by ${collectorId}`
341
- );
342
- updatedFeeConfig = updatedFeeConfig.addHbarFee(
343
- input.hbarFee!,
344
- collectorId,
345
- exemptAccountIds
346
- );
347
- }
348
-
349
- if (hasHbarFees) {
350
- for (const fee of input.hbarFees!) {
351
- const feeCollector = fee.collectorAccount || collectorId;
352
- logger.info(
353
- `Adding HBAR fee: ${fee.amount} HBAR to be collected by ${feeCollector}`
354
- );
355
- updatedFeeConfig = updatedFeeConfig.addHbarFee(
356
- fee.amount,
357
- feeCollector,
358
- exemptAccountIds
359
- );
360
- }
361
- }
362
-
363
- if (hasTokenFee) {
364
- logger.info(
365
- `Adding token fee: ${input.tokenFee!.amount} of token ${
366
- input.tokenFee!.tokenId
367
- } to be collected by ${collectorId}`
368
- );
369
- updatedFeeConfig = await updatedFeeConfig.addTokenFee(
370
- input.tokenFee!.amount,
371
- input.tokenFee!.tokenId,
372
- collectorId,
373
- undefined,
374
- exemptAccountIds
375
- );
376
- }
377
-
378
- if (hasTokenFees) {
379
- for (const fee of input.tokenFees!) {
380
- const feeCollector = fee.collectorAccount || collectorId;
381
- logger.info(
382
- `Adding token fee: ${fee.amount} of token ${fee.tokenId} to be collected by ${feeCollector}`
383
- );
384
- updatedFeeConfig = await updatedFeeConfig.addTokenFee(
385
- fee.amount,
386
- fee.tokenId,
387
- feeCollector,
388
- undefined,
389
- exemptAccountIds
390
- );
391
- }
392
- }
393
-
394
- metadata.feeConfig = updatedFeeConfig;
395
- logger.info('FeeConfigBuilder created successfully');
396
- } catch (error) {
397
- return `Error: Failed to configure fees. Reason: ${
398
- error instanceof Error ? error.message : String(error)
399
- }`;
400
- }
401
- }
402
-
403
- try {
404
- logger.info('Registering agent with metadata');
405
-
406
- const result = (await this.client.createAndRegisterAgent(
407
- metadata
408
- )) as unknown as HCS10RegistrationResult;
409
-
410
- return this.processRegistrationResult(
411
- result,
412
- input,
413
- profilePictureSource
414
- );
415
- } catch (error) {
416
- return `Error: Failed to create/register agent "${input.name}". Reason: ${
417
- error instanceof Error ? error.message : String(error)
418
- }`;
419
- }
420
- }
421
-
422
- /**
423
- * Checks if the token fee configuration is valid
424
- */
425
- private hasValidTokenFee(tokenFee?: {
426
- amount: number;
427
- tokenId: string;
428
- }): boolean {
429
- return !!(
430
- tokenFee &&
431
- tokenFee.amount > 0 &&
432
- tokenFee.tokenId &&
433
- tokenFee.tokenId.trim() !== ''
434
- );
435
- }
436
-
437
- /**
438
- * Processes the registration result and returns formatted output
439
- */
440
- private async processRegistrationResult(
441
- result: HCS10RegistrationResult,
442
- input: z.infer<typeof this.schema>,
443
- profilePictureSource: string = ''
444
- ): Promise<string> {
445
- const newAgentAccountId = result?.metadata?.accountId || '';
446
- const inboundTopicId = result?.metadata?.inboundTopicId || '';
447
- const outboundTopicId = result?.metadata?.outboundTopicId || '';
448
- const profileTopicId = result?.metadata?.profileTopicId || '';
449
- const privateKey = result?.metadata?.privateKey || '';
450
- const pfpTopicId = result?.metadata?.pfpTopicId;
451
-
452
- this.validateRegistrationResult(
453
- newAgentAccountId,
454
- inboundTopicId,
455
- outboundTopicId,
456
- privateKey
457
- );
458
-
459
- if (
460
- this.stateManager &&
461
- privateKey &&
462
- newAgentAccountId &&
463
- inboundTopicId &&
464
- outboundTopicId &&
465
- (input.setAsCurrent === undefined || input.setAsCurrent)
466
- ) {
467
- const agent = {
468
- name: input.name,
469
- accountId: newAgentAccountId,
470
- inboundTopicId,
471
- outboundTopicId,
472
- profileTopicId,
473
- privateKey,
474
- pfpTopicId: pfpTopicId as string,
475
- };
476
-
477
- this.stateManager.setCurrentAgent(agent);
478
-
479
- if (this.stateManager.persistAgentData && input.persistence) {
480
- try {
481
- const persistenceOptions: AgentPersistenceOptions = {
482
- type: 'env-file',
483
- prefix: input.persistence.prefix,
484
- };
485
-
486
- await this.stateManager.persistAgentData(agent, persistenceOptions);
487
- } catch (error) {
488
- Logger.getInstance().warn('Failed to persist agent data', error);
489
- }
490
- }
491
- }
492
-
493
- await this.ensureAgentHasFunds(newAgentAccountId, input.name);
494
-
495
- const feeDescription = this.createFeeDescription(input);
496
- const feeMessage = feeDescription
497
- ? ` with ${feeDescription} fee on inbound topic`
498
- : '';
499
-
500
- const registrationDetails: AgentRegistrationDetails = {
501
- success: true,
502
- message: `Successfully registered agent '${input.name}'${feeMessage}.`,
503
- name: input.name,
504
- accountId: newAgentAccountId,
505
- privateKey: privateKey,
506
- inboundTopicId: inboundTopicId,
507
- outboundTopicId: outboundTopicId,
508
- profileTopicId: profileTopicId || 'N/A',
509
- capabilities: input.capabilities || [AIAgentCapability.TEXT_GENERATION],
510
- hasFees: !!(input.hbarFee || this.hasValidTokenFee(input.tokenFee)),
511
- hbarFee: input.hbarFee || 0,
512
- tokenFee: input.tokenFee || null,
513
- };
514
-
515
- if (pfpTopicId || profilePictureSource) {
516
- registrationDetails.profilePicture = {
517
- source: profilePictureSource,
518
- topicId: pfpTopicId as string,
519
- };
520
- }
521
-
522
- return JSON.stringify(registrationDetails);
523
- }
524
-
525
- /**
526
- * Ensures the agent has enough HBAR for operations
527
- */
528
- private async ensureAgentHasFunds(
529
- accountId: string,
530
- agentName: string
531
- ): Promise<void> {
532
- try {
533
- await ensureAgentHasEnoughHbar(
534
- Logger.getInstance({
535
- module: 'RegisterAgentTool',
536
- }),
537
- this.client.standardClient,
538
- accountId,
539
- agentName
540
- );
541
- } catch (error) {
542
- Logger.getInstance().error('Failed to auto fund agent', error);
543
- }
544
- }
545
-
546
- /**
547
- * Validates that all required fields are present in the registration result
548
- */
549
- private validateRegistrationResult(
550
- accountId?: string,
551
- inboundTopicId?: string,
552
- outboundTopicId?: string,
553
- privateKey?: string
554
- ): void {
555
- if (!accountId || !inboundTopicId || !outboundTopicId || !privateKey) {
556
- const missingFields = [
557
- !accountId && 'accountId',
558
- !inboundTopicId && 'inboundTopicId',
559
- !outboundTopicId && 'outboundTopicId',
560
- !privateKey && 'privateKey',
561
- ]
562
- .filter(Boolean)
563
- .join(', ');
564
- throw new Error(
565
- `Registration failed. The HCS client returned incomplete details (Missing: ${missingFields}).`
566
- );
567
- }
568
- }
569
-
570
- /**
571
- * Creates a description of the fees configured for the agent
572
- */
573
- private createFeeDescription(input: z.infer<typeof this.schema>): string {
574
- const hasHbarFee = input.hbarFee && input.hbarFee > 0;
575
- const hasTokenFee = this.hasValidTokenFee(input.tokenFee);
576
- if (!hasHbarFee && !hasTokenFee) {
577
- return '';
578
- }
579
-
580
- let description = '';
581
- if (hasHbarFee) {
582
- description += `${input.hbarFee} HBAR`;
583
- }
584
- if (hasTokenFee && input.tokenFee) {
585
- const tokenFeeText = `${input.tokenFee.amount} of token ${input.tokenFee.tokenId}`;
586
- description += description ? ` and ${tokenFeeText}` : tokenFeeText;
587
- }
588
- return description;
589
- }
590
- }
@@ -1,94 +0,0 @@
1
- import { StructuredTool } from '@langchain/core/tools';
2
- import { z } from 'zod';
3
- import { HCS10Client } from '../hcs10/HCS10Client';
4
- import { Logger } from '@hashgraphonline/standards-sdk';
5
-
6
- /**
7
- * Tool for retrieving the HCS-11 profile associated with a Hedera account ID.
8
- * Utilizes the HCS10Client's retrieveProfile method, which handles fetching.
9
- */
10
- export class RetrieveProfileTool extends StructuredTool {
11
- name = 'retrieve_profile';
12
- description =
13
- 'Retrieves the HCS-11 profile data associated with a given Hedera account ID. If no account ID is provided, it defaults to the current operator account ID. Returns the profile object as a JSON string on success.';
14
-
15
- private client: HCS10Client;
16
- private logger: Logger;
17
-
18
- schema = z.object({
19
- accountId: z
20
- .string()
21
- .optional()
22
- .describe(
23
- 'The Hedera account ID (e.g., 0.0.12345) to retrieve the profile for. If omitted, defaults to the current operator account ID.'
24
- ),
25
- disableCache: z
26
- .boolean()
27
- .optional()
28
- .describe(
29
- 'Optional: Set to true to bypass the cache and fetch fresh profile data.'
30
- ),
31
- });
32
-
33
- /**
34
- * Creates a new RetrieveProfileTool instance.
35
- * @param client - An instance of HCS10Client.
36
- */
37
- constructor(client: HCS10Client) {
38
- super();
39
- this.client = client;
40
- this.logger = Logger.getInstance({ module: this.name });
41
- }
42
-
43
- /**
44
- * Executes the profile retrieval.
45
- * @param input - The input object containing accountId and optional disableCache flag.
46
- * @returns A JSON string of the profile on success, or an error message string.
47
- */
48
- async _call(input: z.infer<typeof this.schema>): Promise<string> {
49
- let targetAccountId: string;
50
- try {
51
- if (input.accountId) {
52
- targetAccountId = input.accountId;
53
- } else {
54
- this.logger.info('accountId not provided, defaulting to operator ID.');
55
- targetAccountId = this.client.getOperatorId();
56
- }
57
-
58
- if (!targetAccountId) {
59
- throw new Error('Could not determine target account ID.');
60
- }
61
-
62
- this.logger.info(
63
- `Attempting to retrieve profile for account: ${targetAccountId}, Disable Cache: ${!!input.disableCache}`
64
- );
65
-
66
- // Call retrieveProfile via the standardClient instance using the determined ID
67
- const result = await this.client.standardClient.retrieveProfile(
68
- targetAccountId,
69
- input.disableCache
70
- );
71
-
72
- if (result.success && result.profile) {
73
- this.logger.info(
74
- `Successfully retrieved profile for ${targetAccountId}.`
75
- );
76
-
77
- return JSON.stringify(result.profile, null, 2);
78
- } else {
79
- const errorMessage = `Error retrieving profile for ${targetAccountId}: ${
80
- result.error || 'Profile not found or invalid.'
81
- }`;
82
- this.logger.error(errorMessage);
83
- return errorMessage;
84
- }
85
- } catch (error) {
86
- const idForError = input.accountId || 'operator default';
87
- const errorMessage = `Unexpected error retrieving profile for ${idForError}: ${
88
- error instanceof Error ? error.message : String(error)
89
- }`;
90
- this.logger.error(errorMessage, error);
91
- return errorMessage;
92
- }
93
- }
94
- }