@hashgraphonline/standards-sdk 0.0.64 → 0.0.66

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 (294) hide show
  1. package/dist/es/fees/fee-config-builder.d.ts.map +1 -0
  2. package/dist/es/fees/index.d.ts +3 -0
  3. package/dist/es/fees/index.d.ts.map +1 -0
  4. package/dist/es/fees/types.d.ts +24 -0
  5. package/dist/es/fees/types.d.ts.map +1 -0
  6. package/dist/es/hcs-10/base-client.d.ts +1 -1
  7. package/dist/es/hcs-10/base-client.d.ts.map +1 -1
  8. package/dist/es/hcs-10/browser.d.ts +20 -35
  9. package/dist/es/hcs-10/browser.d.ts.map +1 -1
  10. package/dist/es/hcs-10/index.d.ts +4 -6
  11. package/dist/es/hcs-10/index.d.ts.map +1 -1
  12. package/dist/es/hcs-10/registrations.d.ts.map +1 -1
  13. package/dist/es/hcs-10/sdk.d.ts +16 -8
  14. package/dist/es/hcs-10/sdk.d.ts.map +1 -1
  15. package/dist/es/hcs-10/types.d.ts +2 -62
  16. package/dist/es/hcs-10/types.d.ts.map +1 -1
  17. package/dist/es/hcs-11/agent-builder.d.ts +53 -0
  18. package/dist/es/hcs-11/agent-builder.d.ts.map +1 -0
  19. package/dist/es/hcs-11/client.d.ts +82 -0
  20. package/dist/es/hcs-11/client.d.ts.map +1 -0
  21. package/dist/es/hcs-11/index.d.ts +4 -190
  22. package/dist/es/hcs-11/index.d.ts.map +1 -1
  23. package/dist/es/hcs-11/person-builder.d.ts +29 -0
  24. package/dist/es/hcs-11/person-builder.d.ts.map +1 -0
  25. package/dist/es/hcs-11/types.d.ts +165 -0
  26. package/dist/es/hcs-11/types.d.ts.map +1 -0
  27. package/dist/es/index.d.ts +1 -0
  28. package/dist/es/index.d.ts.map +1 -1
  29. package/dist/es/services/mirror-node.d.ts +2 -1
  30. package/dist/es/services/mirror-node.d.ts.map +1 -1
  31. package/dist/es/services/types.d.ts +0 -1
  32. package/dist/es/services/types.d.ts.map +1 -1
  33. package/dist/es/standards-sdk.es.js +9 -7
  34. package/dist/es/standards-sdk.es.js.map +1 -1
  35. package/dist/es/standards-sdk.es10.js +114 -1046
  36. package/dist/es/standards-sdk.es10.js.map +1 -1
  37. package/dist/es/standards-sdk.es100.js +3 -792
  38. package/dist/es/standards-sdk.es100.js.map +1 -1
  39. package/dist/es/standards-sdk.es101.js +2282 -174
  40. package/dist/es/standards-sdk.es101.js.map +1 -1
  41. package/dist/es/standards-sdk.es102.js +14 -141
  42. package/dist/es/standards-sdk.es102.js.map +1 -1
  43. package/dist/es/standards-sdk.es103.js +5 -3
  44. package/dist/es/standards-sdk.es103.js.map +1 -1
  45. package/dist/es/standards-sdk.es104.js +39 -2
  46. package/dist/es/standards-sdk.es104.js.map +1 -1
  47. package/dist/es/standards-sdk.es105.js +40 -2
  48. package/dist/es/standards-sdk.es105.js.map +1 -1
  49. package/dist/es/standards-sdk.es106.js +37 -34
  50. package/dist/es/standards-sdk.es106.js.map +1 -1
  51. package/dist/es/standards-sdk.es107.js +74 -29
  52. package/dist/es/standards-sdk.es107.js.map +1 -1
  53. package/dist/es/standards-sdk.es108.js +3 -9
  54. package/dist/es/standards-sdk.es108.js.map +1 -1
  55. package/dist/es/standards-sdk.es109.js +2 -34
  56. package/dist/es/standards-sdk.es109.js.map +1 -1
  57. package/dist/es/standards-sdk.es11.js +80 -71
  58. package/dist/es/standards-sdk.es11.js.map +1 -1
  59. package/dist/es/standards-sdk.es110.js +2 -21
  60. package/dist/es/standards-sdk.es110.js.map +1 -1
  61. package/dist/es/standards-sdk.es111.js +33 -26
  62. package/dist/es/standards-sdk.es111.js.map +1 -1
  63. package/dist/es/standards-sdk.es112.js +32 -25
  64. package/dist/es/standards-sdk.es112.js.map +1 -1
  65. package/dist/es/standards-sdk.es113.js +9 -38
  66. package/dist/es/standards-sdk.es113.js.map +1 -1
  67. package/dist/es/standards-sdk.es114.js +37 -0
  68. package/dist/es/standards-sdk.es114.js.map +1 -0
  69. package/dist/es/standards-sdk.es12.js +650 -7
  70. package/dist/es/standards-sdk.es12.js.map +1 -1
  71. package/dist/es/standards-sdk.es13.js +10 -664
  72. package/dist/es/standards-sdk.es13.js.map +1 -1
  73. package/dist/es/standards-sdk.es14.js +3 -0
  74. package/dist/es/standards-sdk.es14.js.map +1 -1
  75. package/dist/es/standards-sdk.es17.js +2 -2
  76. package/dist/es/standards-sdk.es18.js +3 -3
  77. package/dist/es/standards-sdk.es18.js.map +1 -1
  78. package/dist/es/standards-sdk.es19.js +82 -1754
  79. package/dist/es/standards-sdk.es19.js.map +1 -1
  80. package/dist/es/standards-sdk.es20.js +1767 -3
  81. package/dist/es/standards-sdk.es20.js.map +1 -1
  82. package/dist/es/standards-sdk.es21.js +36 -4167
  83. package/dist/es/standards-sdk.es21.js.map +1 -1
  84. package/dist/es/standards-sdk.es22.js +21 -6600
  85. package/dist/es/standards-sdk.es22.js.map +1 -1
  86. package/dist/es/standards-sdk.es23.js +6627 -36
  87. package/dist/es/standards-sdk.es23.js.map +1 -1
  88. package/dist/es/standards-sdk.es24.js +3 -48
  89. package/dist/es/standards-sdk.es24.js.map +1 -1
  90. package/dist/es/standards-sdk.es26.js +10 -10
  91. package/dist/es/standards-sdk.es27.js +2 -2
  92. package/dist/es/standards-sdk.es28.js +4147 -81
  93. package/dist/es/standards-sdk.es28.js.map +1 -1
  94. package/dist/es/standards-sdk.es29.js +419 -2
  95. package/dist/es/standards-sdk.es29.js.map +1 -1
  96. package/dist/es/standards-sdk.es30.js +2 -16
  97. package/dist/es/standards-sdk.es30.js.map +1 -1
  98. package/dist/es/standards-sdk.es31.js +106 -395
  99. package/dist/es/standards-sdk.es31.js.map +1 -1
  100. package/dist/es/standards-sdk.es32.js +2 -2282
  101. package/dist/es/standards-sdk.es32.js.map +1 -1
  102. package/dist/es/standards-sdk.es33.js +68 -148
  103. package/dist/es/standards-sdk.es33.js.map +1 -1
  104. package/dist/es/standards-sdk.es34.js +23 -3
  105. package/dist/es/standards-sdk.es34.js.map +1 -1
  106. package/dist/es/standards-sdk.es35.js +131 -402
  107. package/dist/es/standards-sdk.es35.js.map +1 -1
  108. package/dist/es/standards-sdk.es36.js +91 -2
  109. package/dist/es/standards-sdk.es36.js.map +1 -1
  110. package/dist/es/standards-sdk.es37.js +190 -115
  111. package/dist/es/standards-sdk.es37.js.map +1 -1
  112. package/dist/es/standards-sdk.es38.js +437 -3
  113. package/dist/es/standards-sdk.es38.js.map +1 -1
  114. package/dist/es/standards-sdk.es39.js +19 -358
  115. package/dist/es/standards-sdk.es39.js.map +1 -1
  116. package/dist/es/standards-sdk.es40.js +138 -5
  117. package/dist/es/standards-sdk.es40.js.map +1 -1
  118. package/dist/es/standards-sdk.es41.js +13 -174
  119. package/dist/es/standards-sdk.es41.js.map +1 -1
  120. package/dist/es/standards-sdk.es42.js +23 -75
  121. package/dist/es/standards-sdk.es42.js.map +1 -1
  122. package/dist/es/standards-sdk.es43.js +26 -111
  123. package/dist/es/standards-sdk.es43.js.map +1 -1
  124. package/dist/es/standards-sdk.es44.js +16 -47
  125. package/dist/es/standards-sdk.es44.js.map +1 -1
  126. package/dist/es/standards-sdk.es45.js +43 -9
  127. package/dist/es/standards-sdk.es45.js.map +1 -1
  128. package/dist/es/standards-sdk.es46.js +13 -92
  129. package/dist/es/standards-sdk.es46.js.map +1 -1
  130. package/dist/es/standards-sdk.es47.js +60 -3
  131. package/dist/es/standards-sdk.es47.js.map +1 -1
  132. package/dist/es/standards-sdk.es48.js +1289 -2
  133. package/dist/es/standards-sdk.es48.js.map +1 -1
  134. package/dist/es/standards-sdk.es49.js +27 -108
  135. package/dist/es/standards-sdk.es49.js.map +1 -1
  136. package/dist/es/standards-sdk.es5.js +393 -891
  137. package/dist/es/standards-sdk.es5.js.map +1 -1
  138. package/dist/es/standards-sdk.es50.js +5 -73
  139. package/dist/es/standards-sdk.es50.js.map +1 -1
  140. package/dist/es/standards-sdk.es51.js +158 -5
  141. package/dist/es/standards-sdk.es51.js.map +1 -1
  142. package/dist/es/standards-sdk.es52.js +792 -4
  143. package/dist/es/standards-sdk.es52.js.map +1 -1
  144. package/dist/es/standards-sdk.es53.js +162 -209
  145. package/dist/es/standards-sdk.es53.js.map +1 -1
  146. package/dist/es/standards-sdk.es54.js +137 -52
  147. package/dist/es/standards-sdk.es54.js.map +1 -1
  148. package/dist/es/standards-sdk.es55.js +4 -69
  149. package/dist/es/standards-sdk.es55.js.map +1 -1
  150. package/dist/es/standards-sdk.es56.js +357 -25
  151. package/dist/es/standards-sdk.es56.js.map +1 -1
  152. package/dist/es/standards-sdk.es57.js +5 -62
  153. package/dist/es/standards-sdk.es57.js.map +1 -1
  154. package/dist/es/standards-sdk.es58.js +173 -44
  155. package/dist/es/standards-sdk.es58.js.map +1 -1
  156. package/dist/es/standards-sdk.es59.js +80 -9
  157. package/dist/es/standards-sdk.es59.js.map +1 -1
  158. package/dist/es/standards-sdk.es60.js +106 -57
  159. package/dist/es/standards-sdk.es60.js.map +1 -1
  160. package/dist/es/standards-sdk.es61.js +52 -6
  161. package/dist/es/standards-sdk.es61.js.map +1 -1
  162. package/dist/es/standards-sdk.es62.js +9 -14
  163. package/dist/es/standards-sdk.es62.js.map +1 -1
  164. package/dist/es/standards-sdk.es63.js +97 -7
  165. package/dist/es/standards-sdk.es63.js.map +1 -1
  166. package/dist/es/standards-sdk.es64.js +4 -45
  167. package/dist/es/standards-sdk.es64.js.map +1 -1
  168. package/dist/es/standards-sdk.es65.js +2 -2
  169. package/dist/es/standards-sdk.es65.js.map +1 -1
  170. package/dist/es/standards-sdk.es66.js +105 -128
  171. package/dist/es/standards-sdk.es66.js.map +1 -1
  172. package/dist/es/standards-sdk.es67.js +70 -168
  173. package/dist/es/standards-sdk.es67.js.map +1 -1
  174. package/dist/es/standards-sdk.es68.js +6 -2
  175. package/dist/es/standards-sdk.es68.js.map +1 -1
  176. package/dist/es/standards-sdk.es69.js +5 -13
  177. package/dist/es/standards-sdk.es69.js.map +1 -1
  178. package/dist/es/standards-sdk.es7.js +959 -94
  179. package/dist/es/standards-sdk.es7.js.map +1 -1
  180. package/dist/es/standards-sdk.es70.js +221 -13
  181. package/dist/es/standards-sdk.es70.js.map +1 -1
  182. package/dist/es/standards-sdk.es71.js +56 -30
  183. package/dist/es/standards-sdk.es71.js.map +1 -1
  184. package/dist/es/standards-sdk.es72.js +69 -15
  185. package/dist/es/standards-sdk.es72.js.map +1 -1
  186. package/dist/es/standards-sdk.es73.js +20 -3
  187. package/dist/es/standards-sdk.es73.js.map +1 -1
  188. package/dist/es/standards-sdk.es74.js +26 -3
  189. package/dist/es/standards-sdk.es74.js.map +1 -1
  190. package/dist/es/standards-sdk.es75.js +24 -14
  191. package/dist/es/standards-sdk.es75.js.map +1 -1
  192. package/dist/es/standards-sdk.es76.js +37 -4
  193. package/dist/es/standards-sdk.es76.js.map +1 -1
  194. package/dist/es/standards-sdk.es77.js +3 -39
  195. package/dist/es/standards-sdk.es77.js.map +1 -1
  196. package/dist/es/standards-sdk.es78.js +158 -34
  197. package/dist/es/standards-sdk.es78.js.map +1 -1
  198. package/dist/es/standards-sdk.es79.js +30 -35
  199. package/dist/es/standards-sdk.es79.js.map +1 -1
  200. package/dist/es/standards-sdk.es8.js +1049 -393
  201. package/dist/es/standards-sdk.es8.js.map +1 -1
  202. package/dist/es/standards-sdk.es80.js +57 -72
  203. package/dist/es/standards-sdk.es80.js.map +1 -1
  204. package/dist/es/standards-sdk.es81.js +46 -191
  205. package/dist/es/standards-sdk.es81.js.map +1 -1
  206. package/dist/es/standards-sdk.es82.js +8 -436
  207. package/dist/es/standards-sdk.es82.js.map +1 -1
  208. package/dist/es/standards-sdk.es83.js +60 -20
  209. package/dist/es/standards-sdk.es83.js.map +1 -1
  210. package/dist/es/standards-sdk.es84.js +6 -139
  211. package/dist/es/standards-sdk.es84.js.map +1 -1
  212. package/dist/es/standards-sdk.es85.js +14 -17
  213. package/dist/es/standards-sdk.es85.js.map +1 -1
  214. package/dist/es/standards-sdk.es86.js +7 -29
  215. package/dist/es/standards-sdk.es86.js.map +1 -1
  216. package/dist/es/standards-sdk.es87.js +44 -28
  217. package/dist/es/standards-sdk.es87.js.map +1 -1
  218. package/dist/es/standards-sdk.es88.js +2 -21
  219. package/dist/es/standards-sdk.es88.js.map +1 -1
  220. package/dist/es/standards-sdk.es89.js +135 -43
  221. package/dist/es/standards-sdk.es89.js.map +1 -1
  222. package/dist/es/standards-sdk.es9.js +1 -1
  223. package/dist/es/standards-sdk.es9.js.map +1 -1
  224. package/dist/es/standards-sdk.es90.js +168 -14
  225. package/dist/es/standards-sdk.es90.js.map +1 -1
  226. package/dist/es/standards-sdk.es91.js +95 -55
  227. package/dist/es/standards-sdk.es91.js.map +1 -1
  228. package/dist/es/standards-sdk.es92.js +2 -1289
  229. package/dist/es/standards-sdk.es92.js.map +1 -1
  230. package/dist/es/standards-sdk.es93.js +15 -147
  231. package/dist/es/standards-sdk.es93.js.map +1 -1
  232. package/dist/es/standards-sdk.es94.js +403 -85
  233. package/dist/es/standards-sdk.es94.js.map +1 -1
  234. package/dist/es/standards-sdk.es95.js +13 -84
  235. package/dist/es/standards-sdk.es95.js.map +1 -1
  236. package/dist/es/standards-sdk.es96.js +13 -32
  237. package/dist/es/standards-sdk.es96.js.map +1 -1
  238. package/dist/es/standards-sdk.es97.js +31 -5
  239. package/dist/es/standards-sdk.es97.js.map +1 -1
  240. package/dist/es/standards-sdk.es98.js +13 -157
  241. package/dist/es/standards-sdk.es98.js.map +1 -1
  242. package/dist/es/standards-sdk.es99.js +3 -22
  243. package/dist/es/standards-sdk.es99.js.map +1 -1
  244. package/dist/es/utils/logger.d.ts +1 -0
  245. package/dist/es/utils/logger.d.ts.map +1 -1
  246. package/dist/es/utils/types.d.ts +2 -0
  247. package/dist/es/utils/types.d.ts.map +1 -0
  248. package/dist/umd/fees/fee-config-builder.d.ts.map +1 -0
  249. package/dist/umd/fees/index.d.ts +3 -0
  250. package/dist/umd/fees/index.d.ts.map +1 -0
  251. package/dist/umd/fees/types.d.ts +24 -0
  252. package/dist/umd/fees/types.d.ts.map +1 -0
  253. package/dist/umd/hcs-10/base-client.d.ts +1 -1
  254. package/dist/umd/hcs-10/base-client.d.ts.map +1 -1
  255. package/dist/umd/hcs-10/browser.d.ts +20 -35
  256. package/dist/umd/hcs-10/browser.d.ts.map +1 -1
  257. package/dist/umd/hcs-10/index.d.ts +4 -6
  258. package/dist/umd/hcs-10/index.d.ts.map +1 -1
  259. package/dist/umd/hcs-10/registrations.d.ts.map +1 -1
  260. package/dist/umd/hcs-10/sdk.d.ts +16 -8
  261. package/dist/umd/hcs-10/sdk.d.ts.map +1 -1
  262. package/dist/umd/hcs-10/types.d.ts +2 -62
  263. package/dist/umd/hcs-10/types.d.ts.map +1 -1
  264. package/dist/umd/hcs-11/agent-builder.d.ts +53 -0
  265. package/dist/umd/hcs-11/agent-builder.d.ts.map +1 -0
  266. package/dist/umd/hcs-11/client.d.ts +82 -0
  267. package/dist/umd/hcs-11/client.d.ts.map +1 -0
  268. package/dist/umd/hcs-11/index.d.ts +4 -190
  269. package/dist/umd/hcs-11/index.d.ts.map +1 -1
  270. package/dist/umd/hcs-11/person-builder.d.ts +29 -0
  271. package/dist/umd/hcs-11/person-builder.d.ts.map +1 -0
  272. package/dist/umd/hcs-11/types.d.ts +165 -0
  273. package/dist/umd/hcs-11/types.d.ts.map +1 -0
  274. package/dist/umd/index.d.ts +1 -0
  275. package/dist/umd/index.d.ts.map +1 -1
  276. package/dist/umd/services/mirror-node.d.ts +2 -1
  277. package/dist/umd/services/mirror-node.d.ts.map +1 -1
  278. package/dist/umd/services/types.d.ts +0 -1
  279. package/dist/umd/services/types.d.ts.map +1 -1
  280. package/dist/umd/standards-sdk.umd.js +7 -7
  281. package/dist/umd/standards-sdk.umd.js.map +1 -1
  282. package/dist/umd/utils/logger.d.ts +1 -0
  283. package/dist/umd/utils/logger.d.ts.map +1 -1
  284. package/dist/umd/utils/types.d.ts +2 -0
  285. package/dist/umd/utils/types.d.ts.map +1 -0
  286. package/package.json +3 -4
  287. package/dist/es/hcs-10/agent-builder.d.ts +0 -45
  288. package/dist/es/hcs-10/agent-builder.d.ts.map +0 -1
  289. package/dist/es/hcs-10/fee-config-builder.d.ts.map +0 -1
  290. package/dist/umd/hcs-10/agent-builder.d.ts +0 -45
  291. package/dist/umd/hcs-10/agent-builder.d.ts.map +0 -1
  292. package/dist/umd/hcs-10/fee-config-builder.d.ts.map +0 -1
  293. /package/dist/es/{hcs-10 → fees}/fee-config-builder.d.ts +0 -0
  294. /package/dist/umd/{hcs-10 → fees}/fee-config-builder.d.ts +0 -0
@@ -1,1084 +1,152 @@
1
- import Buffer from "./standards-sdk.es19.js";
2
- import { KeyList, TopicCreateTransaction, Transaction, TopicMessageSubmitTransaction, Hbar } from "@hashgraph/sdk";
1
+ import { InboundTopicType } from "./standards-sdk.es13.js";
3
2
  import { Logger } from "./standards-sdk.es14.js";
4
- import { InscriptionSDK } from "./standards-sdk.es22.js";
5
- import { HCS10BaseClient, Hcs10MemoType } from "./standards-sdk.es8.js";
6
- import { m as mimeTypesExports } from "./standards-sdk.es20.js";
7
- import { HCS11Client } from "./standards-sdk.es13.js";
8
- import { ProgressReporter } from "./standards-sdk.es16.js";
9
- const isBrowser = typeof window !== "undefined";
10
- class BrowserHCSClient extends HCS10BaseClient {
11
- constructor(config) {
12
- super({
13
- network: config.network,
14
- logLevel: config.logLevel,
15
- prettyPrint: config.prettyPrint,
16
- feeAmount: config.feeAmount
17
- });
18
- this.hcs11Client = null;
19
- this.hwc = config.hwc;
20
- this.guardedRegistryBaseUrl = config.guardedRegistryBaseUrl || "https://moonscape.tech";
3
+ class AgentBuilder {
4
+ constructor() {
5
+ this.config = {};
21
6
  this.logger = Logger.getInstance({
22
- level: config.logLevel || "info",
23
- module: "HCS-Browser",
24
- prettyPrint: config.prettyPrint
7
+ module: "AgentBuilder"
25
8
  });
26
- if (isBrowser) {
27
- try {
28
- const { accountId, signer } = this.getAccountAndSigner();
29
- this.hcs11Client = new HCS11Client({
30
- network: config.network,
31
- auth: {
32
- operatorId: accountId,
33
- signer
34
- },
35
- logLevel: config.logLevel
36
- });
37
- } catch (err) {
38
- this.logger.warn(`Failed to initialize HCS11Client: ${err}`);
39
- }
40
- } else {
41
- this.logger.error(
42
- "BrowserHCSClient initialized in server environment - browser-specific features will not be available. Use HCS10Client instead."
43
- );
44
- }
45
9
  }
46
- async sendMessage(connectionTopicId, data, memo, submitKey) {
47
- this.logger.info("Sending message");
48
- const operatorId = await this.getOperatorId();
49
- const payload = {
50
- p: "hcs-10",
51
- op: "message",
52
- operator_id: operatorId,
53
- data,
54
- m: memo
55
- };
56
- const submissionCheck = await this.canSubmitToTopic(
57
- connectionTopicId,
58
- this.hwc.getAccountInfo().accountId
59
- );
60
- const payloadString = JSON.stringify(payload);
61
- const isLargePayload = Buffer.from(payloadString).length > 1e3;
62
- if (isLargePayload) {
63
- this.logger.info(
64
- "Message payload exceeds 1000 bytes, storing via inscription"
65
- );
66
- try {
67
- const contentBuffer = Buffer.from(data);
68
- const fileName = `message-${Date.now()}.json`;
69
- const inscriptionResult = await this.inscribeFile(
70
- contentBuffer,
71
- fileName
72
- );
73
- if (inscriptionResult?.topic_id) {
74
- payload.data = `hcs://1/${inscriptionResult.topic_id}`;
75
- this.logger.info(
76
- `Large message inscribed with topic ID: ${inscriptionResult.topic_id}`
77
- );
78
- } else {
79
- throw new Error("Failed to inscribe large message content");
80
- }
81
- } catch (error) {
82
- this.logger.error("Error inscribing large message:", error);
83
- throw new Error(
84
- `Failed to handle large message: ${error instanceof Error ? error.message : "Unknown error"}`
85
- );
86
- }
87
- }
88
- return await this.submitPayload(
89
- connectionTopicId,
90
- payload,
91
- submitKey,
92
- submissionCheck.requiresFee
93
- );
10
+ setName(name) {
11
+ this.config.name = name;
12
+ return this;
94
13
  }
95
- async submitConnectionRequest(inboundTopicId, memo) {
96
- this.logger.info("Submitting connection request");
97
- const accountResponse = this.getAccountAndSigner();
98
- if (!accountResponse.accountId) {
99
- throw new Error("Failed to retrieve user account ID");
100
- }
101
- const operatorId = await this.getOperatorId();
102
- const accountId = accountResponse.accountId;
103
- const connectionRequestMessage = {
104
- p: "hcs-10",
105
- op: "connection_request",
106
- operator_id: operatorId,
107
- m: memo
108
- };
109
- const response = await this.submitPayload(
110
- inboundTopicId,
111
- connectionRequestMessage
112
- );
113
- this.logger.info(
114
- `Submitted connection request to topic ID: ${inboundTopicId}`
115
- );
116
- const outboundTopic = await this.retrieveOutboundConnectTopic(accountId);
117
- if (!outboundTopic?.outboundTopic) {
118
- this.logger.error(
119
- `Failed to retrieve outbound topic for account ID: ${accountId}`
120
- );
121
- throw new Error(
122
- `Failed to retrieve outbound topic for account ID: ${accountId}`
123
- );
124
- }
125
- this.logger.info(
126
- `Retrieved outbound topic ID: ${outboundTopic.outboundTopic} for account ID: ${accountId}`
127
- );
128
- const responseSequenceNumber = response?.topicSequenceNumber?.toNumber();
129
- if (!responseSequenceNumber) {
130
- throw new Error("Failed to get response sequence number");
131
- }
132
- await this.submitPayload(outboundTopic.outboundTopic, {
133
- ...connectionRequestMessage,
134
- outbound_topic_id: inboundTopicId,
135
- connection_request_id: responseSequenceNumber
136
- });
137
- return response;
14
+ setAlias(alias) {
15
+ this.config.alias = alias;
16
+ return this;
138
17
  }
139
- async getPublicKey(accountId) {
140
- return await this.mirrorNode.getPublicKey(accountId);
18
+ setBio(bio) {
19
+ this.config.bio = bio;
20
+ return this;
141
21
  }
142
- async handleConnectionRequest(inboundTopicId, requestingAccountId, connectionId, connectionMemo = "Connection accepted. Looking forward to collaborating!", ttl = 60) {
143
- this.logger.info("Handling connection request");
144
- const userAccountId = this.hwc.getAccountInfo().accountId;
145
- if (!userAccountId) {
146
- throw new Error("Failed to retrieve user account ID");
147
- }
148
- const requesterKey = await this.mirrorNode.getPublicKey(
149
- requestingAccountId
150
- );
151
- const accountKey = await this.mirrorNode.getPublicKey(userAccountId);
152
- if (!accountKey) {
153
- throw new Error("Failed to retrieve public key");
154
- }
155
- const thresholdKey = new KeyList([accountKey, requesterKey], 1);
156
- const memo = this._generateHcs10Memo(Hcs10MemoType.CONNECTION, {
157
- ttl,
158
- inboundTopicId,
159
- connectionId
160
- });
161
- const transaction = new TopicCreateTransaction().setTopicMemo(memo).setAdminKey(thresholdKey).setSubmitKey(thresholdKey);
162
- this.logger.debug("Executing topic creation transaction");
163
- const txResponse = await this.hwc.executeTransactionWithErrorHandling(
164
- transaction,
165
- false
166
- );
167
- if (txResponse.error) {
168
- this.logger.error(txResponse.error);
169
- throw new Error(txResponse.error);
170
- }
171
- const resultReceipt = txResponse.result;
172
- if (!resultReceipt?.topicId) {
173
- this.logger.error("Failed to create topic: topicId is null");
174
- throw new Error("Failed to create topic: topicId is null");
175
- }
176
- const connectionTopicId = resultReceipt.topicId.toString();
177
- const operatorId = `${inboundTopicId}@${userAccountId}`;
178
- const confirmedConnectionSequenceNumber = await this.confirmConnection(
179
- inboundTopicId,
180
- connectionTopicId,
181
- requestingAccountId,
182
- connectionId,
183
- operatorId,
184
- connectionMemo
185
- );
186
- return {
187
- connectionTopicId,
188
- confirmedConnectionSequenceNumber,
189
- operatorId
190
- };
22
+ /**
23
+ * @deprecated Use setBio instead
24
+ */
25
+ setDescription(description) {
26
+ this.config.bio = description;
27
+ return this;
191
28
  }
192
- async confirmConnection(inboundTopicId, connectionTopicId, connectedAccountId, connectionId, operatorId, memo) {
193
- this.logger.info("Confirming connection");
194
- const payload = {
195
- p: "hcs-10",
196
- op: "connection_created",
197
- connection_topic_id: connectionTopicId,
198
- connected_account_id: connectedAccountId,
199
- operator_id: operatorId,
200
- connection_id: connectionId,
201
- m: memo
202
- };
203
- const transactionResponse = await this.submitPayload(
204
- inboundTopicId,
205
- payload
206
- );
207
- if (!transactionResponse?.topicSequenceNumber) {
208
- this.logger.error(
209
- "Failed to confirm connection: sequence number is null"
210
- );
211
- throw new Error("Failed to confirm connection: sequence number is null");
212
- }
213
- return transactionResponse.topicSequenceNumber.toNumber();
29
+ setCapabilities(capabilities) {
30
+ this.config.capabilities = capabilities;
31
+ return this;
214
32
  }
215
33
  /**
216
- * Creates an agent directly, but does not register.
217
- * We highly recommend calling createAndRegisterAgent instead.
218
- *
219
- * @param pfpBuffer - The buffer containing the PFP image.
220
- * @param pfpFileName - The name of the file containing the PFP image.
221
- * @param agentName - The name of the agent.
222
- * @param agentDescription - The description of the agent.
223
- * @param capabilities - The capabilities of the agent.
224
- * @param metadata - The metadata of the agent.
225
- * @param existingPfpTopicId - The topic ID of the existing PFP.
226
- * @param options - Optional configuration options.
227
- * @returns A promise that resolves to the agent creation state.
34
+ * @deprecated Use setType instead
228
35
  */
229
- async createAgent(pfpBuffer, pfpFileName, agentName, agentDescription, capabilities, metadata, existingPfpTopicId, options) {
230
- try {
231
- const progressCallback = options?.progressCallback;
232
- const progressReporter = new ProgressReporter({
233
- module: "AgentCreate",
234
- logger: this.logger,
235
- callback: progressCallback
236
- });
237
- let state = options?.existingState || {
238
- currentStage: "init",
239
- completedPercentage: 0,
240
- createdResources: []
241
- };
242
- if (!state.outboundTopicId) {
243
- state.currentStage = "topics";
244
- progressReporter.preparing("Creating agent outbound topic", 0, {
245
- state
246
- });
247
- const outboundMemo = this._generateHcs10Memo(Hcs10MemoType.OUTBOUND, {
248
- ttl: options?.ttl
249
- });
250
- const outboundResult = await this.createTopic(outboundMemo, true, true);
251
- if (!outboundResult.success || !outboundResult.topicId) {
252
- state.error = outboundResult.error || "Failed to create outbound topic";
253
- progressReporter.failed(
254
- `Failed to create outbound topic: ${state.error}`,
255
- { state }
256
- );
257
- return {
258
- outboundTopicId: "",
259
- inboundTopicId: "",
260
- pfpTopicId: "",
261
- profileTopicId: "",
262
- success: false,
263
- error: state.error,
264
- state
265
- };
266
- }
267
- state.outboundTopicId = outboundResult.topicId;
268
- if (state.createdResources) {
269
- state.createdResources.push(`outbound:${state.outboundTopicId}`);
270
- }
271
- progressReporter.preparing("Outbound topic created", 20, { state });
272
- } else {
273
- progressReporter.preparing("Using existing outbound topic", 20, {
274
- state
275
- });
276
- }
277
- const accountId = this.hwc.getAccountInfo().accountId;
278
- if (!accountId) {
279
- throw new Error("Failed to retrieve user account ID");
280
- }
281
- if (!state.inboundTopicId) {
282
- const inboundMemo = this._generateHcs10Memo(Hcs10MemoType.INBOUND, {
283
- accountId,
284
- ttl: options?.ttl
285
- });
286
- const inboundResult = await this.createTopic(inboundMemo, true, true);
287
- if (!inboundResult.success || !inboundResult.topicId) {
288
- state.error = inboundResult.error || "Failed to create inbound topic";
289
- progressReporter.failed(
290
- `Failed to create inbound topic: ${state.error}`,
291
- { state }
292
- );
293
- return {
294
- outboundTopicId: state.outboundTopicId || "",
295
- inboundTopicId: "",
296
- pfpTopicId: "",
297
- profileTopicId: "",
298
- success: false,
299
- error: state.error,
300
- state
301
- };
302
- }
303
- state.inboundTopicId = inboundResult.topicId;
304
- if (state.createdResources) {
305
- state.createdResources.push(`inbound:${state.inboundTopicId}`);
306
- }
307
- progressReporter.preparing("Inbound topic created", 40, { state });
308
- } else {
309
- progressReporter.preparing("Using existing inbound topic", 40, {
310
- state
311
- });
312
- }
313
- if (!state.pfpTopicId && !existingPfpTopicId) {
314
- state.currentStage = "pfp";
315
- progressReporter.preparing("Creating agent profile picture", 40, {
316
- state
317
- });
318
- const pfpProgress = progressReporter.createSubProgress({
319
- minPercent: 40,
320
- maxPercent: 60,
321
- logPrefix: "PFP"
322
- });
323
- const pfpResult = await this.inscribePfp(pfpBuffer, pfpFileName, {
324
- progressCallback: (data) => {
325
- pfpProgress.report({
326
- stage: data.stage,
327
- message: data.message,
328
- progressPercent: data.progressPercent || 0,
329
- details: { ...data.details, state }
330
- });
331
- }
332
- });
333
- if (!pfpResult.success) {
334
- state.error = pfpResult.error || "Failed to inscribe profile picture";
335
- progressReporter.failed(
336
- `Failed to inscribe profile picture: ${state.error}`,
337
- { state }
338
- );
339
- return {
340
- outboundTopicId: state.outboundTopicId || "",
341
- inboundTopicId: state.inboundTopicId || "",
342
- pfpTopicId: "",
343
- profileTopicId: "",
344
- success: false,
345
- error: state.error,
346
- state
347
- };
348
- }
349
- state.pfpTopicId = pfpResult.pfpTopicId;
350
- state.completedPercentage = 60;
351
- if (state.createdResources) {
352
- state.createdResources.push(`pfp:${state.pfpTopicId}`);
353
- }
354
- progressReporter.preparing("Profile picture created", 60, { state });
355
- } else {
356
- state.pfpTopicId = existingPfpTopicId || state.pfpTopicId;
357
- progressReporter.preparing(
358
- `Using existing profile picture: ${state.pfpTopicId}`,
359
- 60,
360
- {
361
- state
362
- }
363
- );
364
- }
365
- if (!state.profileTopicId) {
366
- state.currentStage = "profile";
367
- progressReporter.preparing("Creating agent profile", 60, { state });
368
- const profileProgress = progressReporter.createSubProgress({
369
- minPercent: 60,
370
- maxPercent: 100,
371
- logPrefix: "Profile"
372
- });
373
- if (!this.hcs11Client) {
374
- state.error = "HCS11Client is not available in this environment";
375
- progressReporter.failed(state.error, { state });
376
- return {
377
- outboundTopicId: state.outboundTopicId || "",
378
- inboundTopicId: state.inboundTopicId || "",
379
- pfpTopicId: state.pfpTopicId || "",
380
- profileTopicId: "",
381
- success: false,
382
- error: state.error,
383
- state
384
- };
385
- }
386
- const storeProfileResult = await this.storeHCS11Profile(
387
- agentName,
388
- agentDescription,
389
- state.inboundTopicId,
390
- state.outboundTopicId,
391
- capabilities,
392
- metadata,
393
- void 0,
394
- void 0,
395
- state.pfpTopicId,
396
- {
397
- progressCallback: (data) => {
398
- profileProgress.report({
399
- stage: data.stage,
400
- message: data.message,
401
- progressPercent: data.progressPercent || 0,
402
- details: { ...data.details, state }
403
- });
404
- }
405
- }
406
- );
407
- if (!storeProfileResult.success) {
408
- state.error = storeProfileResult.error || "Failed to store agent profile";
409
- progressReporter.failed(
410
- `Failed to store agent profile: ${state.error}`,
411
- { state }
412
- );
413
- return {
414
- outboundTopicId: state.outboundTopicId || "",
415
- inboundTopicId: state.inboundTopicId || "",
416
- pfpTopicId: state.pfpTopicId || "",
417
- profileTopicId: "",
418
- success: false,
419
- error: state.error,
420
- state
421
- };
422
- }
423
- state.profileTopicId = storeProfileResult.profileTopicId;
424
- if (state.createdResources) {
425
- state.createdResources.push(`profile:${state.profileTopicId}`);
426
- }
427
- state.currentStage = "complete";
428
- state.completedPercentage = 100;
429
- } else {
430
- progressReporter.preparing("Using existing agent profile", 100, {
431
- state
432
- });
433
- if (state.currentStage !== "complete") {
434
- state.currentStage = "complete";
435
- state.completedPercentage = 100;
436
- }
437
- }
438
- progressReporter.completed("Agent successfully created", {
439
- inboundTopicId: state.inboundTopicId,
440
- outboundTopicId: state.outboundTopicId,
441
- pfpTopicId: state.pfpTopicId,
442
- profileTopicId: state.profileTopicId,
443
- state
444
- });
445
- return {
446
- outboundTopicId: state.outboundTopicId || "",
447
- inboundTopicId: state.inboundTopicId || "",
448
- pfpTopicId: state.pfpTopicId || "",
449
- profileTopicId: state.profileTopicId || "",
450
- success: true,
451
- state
452
- };
453
- } catch (error) {
454
- this.logger.error(`Error creating agent: ${error.message}`);
455
- return {
456
- outboundTopicId: "",
457
- inboundTopicId: "",
458
- pfpTopicId: "",
459
- profileTopicId: "",
460
- success: false,
461
- error: `Error creating agent: ${error.message}`,
462
- state: {
463
- currentStage: "init",
464
- completedPercentage: 0,
465
- error: error.message
466
- }
467
- };
36
+ setAgentType(type) {
37
+ if (!this.config.metadata) {
38
+ this.config.metadata = { type };
39
+ } else {
40
+ this.config.metadata.type = type;
468
41
  }
42
+ return this;
469
43
  }
470
- initializeRegistrationState(inboundTopicId, existingState) {
471
- const state = existingState || {
472
- inboundTopicId,
473
- currentStage: "registration",
474
- completedPercentage: 0,
475
- createdResources: []
476
- };
477
- if (state.currentStage !== "registration" && state.currentStage !== "complete") {
478
- state.currentStage = "registration";
44
+ setType(type) {
45
+ if (!this.config.metadata) {
46
+ this.config.metadata = { type };
47
+ } else {
48
+ this.config.metadata.type = type;
479
49
  }
480
- return state;
50
+ return this;
481
51
  }
482
- updateStateForCompletedRegistration(state, inboundTopicId) {
483
- state.currentStage = "complete";
484
- state.completedPercentage = 100;
485
- if (state.createdResources) {
486
- state.createdResources.push(`registration:${inboundTopicId}`);
52
+ setModel(model) {
53
+ if (!this.config.metadata) {
54
+ this.config.metadata = { type: "manual" };
487
55
  }
56
+ this.config.metadata.model = model;
57
+ return this;
488
58
  }
489
- async registerAgentWithGuardedRegistry(accountId, network = this.network, options) {
490
- try {
491
- this.logger.info("Registering agent with guarded registry");
492
- const agentProfile = await this.retrieveProfile(accountId);
493
- const inboundTopicId = agentProfile.topicInfo.inboundTopic;
494
- const state = this.initializeRegistrationState(
495
- inboundTopicId,
496
- options?.existingState
497
- );
498
- const progressReporter = new ProgressReporter({
499
- module: "AgentRegistration",
500
- logger: this.logger,
501
- callback: options?.progressCallback
502
- });
503
- progressReporter.preparing("Preparing agent registration", 10, {
504
- inboundTopicId,
505
- accountId
506
- });
507
- const registrationResult = await this.executeRegistration(
508
- accountId,
509
- network,
510
- this.guardedRegistryBaseUrl,
511
- this.logger
512
- );
513
- if (!registrationResult.success) {
514
- return {
515
- ...registrationResult,
516
- state
517
- };
518
- }
519
- progressReporter.submitting("Submitting registration to registry", 30, {
520
- transactionId: registrationResult.transactionId
521
- });
522
- if (registrationResult.transaction) {
523
- const transaction = Transaction.fromBytes(
524
- Buffer.from(registrationResult.transaction, "base64")
525
- );
526
- this.logger.info(`Processing registration transaction`);
527
- const txResult = await this.hwc.executeTransactionWithErrorHandling(
528
- transaction,
529
- true
530
- );
531
- if (txResult.error) {
532
- return {
533
- ...registrationResult,
534
- error: txResult.error,
535
- success: false,
536
- state
537
- };
538
- }
539
- this.logger.info(`Successfully processed registration transaction`);
540
- }
541
- progressReporter.confirming("Confirming registration transaction", 60, {
542
- accountId,
543
- inboundTopicId,
544
- transactionId: registrationResult.transactionId
545
- });
546
- const maxAttempts = options?.maxAttempts ?? 60;
547
- const delayMs = options?.delayMs ?? 2e3;
548
- const confirmed = await this.waitForRegistrationConfirmation(
549
- registrationResult.transactionId,
550
- network,
551
- this.guardedRegistryBaseUrl,
552
- maxAttempts,
553
- delayMs,
554
- this.logger
555
- );
556
- this.updateStateForCompletedRegistration(state, inboundTopicId);
557
- progressReporter.completed("Agent registration complete", {
558
- transactionId: registrationResult.transactionId,
559
- inboundTopicId,
560
- state,
561
- confirmed
562
- });
563
- return {
564
- ...registrationResult,
565
- confirmed,
566
- state
567
- };
568
- } catch (error) {
569
- this.logger.error(`Registration error: ${error.message}`);
570
- return {
571
- error: `Error during registration: ${error.message}`,
572
- success: false,
573
- state: {
574
- currentStage: "registration",
575
- completedPercentage: 0,
576
- error: error.message
577
- }
578
- };
59
+ setCreator(creator) {
60
+ if (!this.config.metadata) {
61
+ this.config.metadata = { type: "manual" };
579
62
  }
63
+ this.config.metadata.creator = creator;
64
+ return this;
580
65
  }
581
- async createAndRegisterAgent(builder, options) {
582
- try {
583
- const config = builder.build();
584
- const progressCallback = options?.progressCallback;
585
- const progressReporter = new ProgressReporter({
586
- module: "AgentCreateRegister",
587
- logger: this.logger,
588
- callback: progressCallback
589
- });
590
- let state = options?.existingState || {
591
- currentStage: "init",
592
- completedPercentage: 0,
593
- createdResources: []
594
- };
595
- state.agentMetadata = config.metadata;
596
- progressReporter.preparing("Starting agent creation process", 0, {
597
- state
598
- });
599
- if (state.currentStage !== "complete" || !state.inboundTopicId || !state.outboundTopicId || !state.profileTopicId) {
600
- const agentResult = await this.createAgent(
601
- config.pfpBuffer || Buffer.from([]),
602
- config.pfpFileName || "default.png",
603
- config.name,
604
- config.description,
605
- config.capabilities,
606
- config.metadata,
607
- config.existingPfpTopicId,
608
- {
609
- progressCallback: (progress) => {
610
- const adjustedPercent = (progress.progressPercent || 0) * 0.3;
611
- progressReporter.report({
612
- stage: progress.stage,
613
- message: progress.message,
614
- progressPercent: adjustedPercent,
615
- details: {
616
- ...progress.details,
617
- state: progress.details?.state || state
618
- }
619
- });
620
- },
621
- existingState: state
622
- }
623
- );
624
- if (!agentResult.success) {
625
- throw new Error(
626
- agentResult.error || "Failed to create agent with topics"
627
- );
628
- }
629
- state = agentResult.state;
630
- state.agentMetadata = config.metadata;
631
- }
632
- progressReporter.preparing(
633
- `Agent creation status: ${state.currentStage}, ${state.completedPercentage}%`,
634
- 30,
635
- { state }
636
- );
637
- const { accountId } = this.getAccountAndSigner();
638
- if (state.currentStage !== "complete" || !state.createdResources?.includes(
639
- `registration:${state.inboundTopicId}`
640
- )) {
641
- if (options?.baseUrl) {
642
- this.guardedRegistryBaseUrl = options.baseUrl;
643
- }
644
- const registrationResult = await this.registerAgentWithGuardedRegistry(
645
- accountId,
646
- config.network,
647
- {
648
- progressCallback: (progress) => {
649
- const adjustedPercent = 30 + (progress.progressPercent || 0) * 0.7;
650
- progressReporter.report({
651
- stage: progress.stage,
652
- message: progress.message,
653
- progressPercent: adjustedPercent,
654
- details: {
655
- ...progress.details,
656
- state: progress.details?.state || state
657
- }
658
- });
659
- },
660
- maxAttempts: options?.maxAttempts,
661
- delayMs: options?.delayMs,
662
- existingState: state
663
- }
664
- );
665
- if (!registrationResult.success) {
666
- throw new Error(
667
- registrationResult.error || "Failed to register agent with registry"
668
- );
669
- }
670
- state = registrationResult.state;
671
- }
672
- progressReporter.completed("Agent creation and registration complete", {
673
- state
674
- });
675
- return {
676
- success: true,
677
- state,
678
- metadata: {
679
- accountId,
680
- operatorId: `${state.inboundTopicId}@${accountId}`,
681
- inboundTopicId: state.inboundTopicId,
682
- outboundTopicId: state.outboundTopicId,
683
- profileTopicId: state.profileTopicId,
684
- pfpTopicId: state.pfpTopicId,
685
- privateKey: null,
686
- ...state.agentMetadata
687
- }
688
- };
689
- } catch (error) {
690
- throw new Error(`Failed to create and register agent: ${error.message}`);
66
+ addSocial(platform, handle) {
67
+ if (!this.config.metadata) {
68
+ this.config.metadata = { type: "manual" };
691
69
  }
692
- }
693
- async storeHCS11Profile(agentName, agentDescription, inboundTopicId, outboundTopicId, capabilities = [], metadata = {}, pfpBuffer, pfpFileName, existingPfpTopicId, options) {
694
- try {
695
- const progressCallback = options?.progressCallback;
696
- const progressReporter = new ProgressReporter({
697
- module: "StoreHCS11Profile",
698
- logger: this.logger,
699
- callback: progressCallback
700
- });
701
- progressReporter.preparing("Preparing agent profile data", 0);
702
- let pfpTopicId = existingPfpTopicId;
703
- if (!pfpTopicId && pfpBuffer && pfpFileName) {
704
- const pfpProgress = progressReporter.createSubProgress({
705
- minPercent: 0,
706
- maxPercent: 60,
707
- logPrefix: "PFP"
708
- });
709
- const pfpResult = await this.inscribePfp(pfpBuffer, pfpFileName, {
710
- progressCallback: (data) => {
711
- pfpProgress.report({
712
- stage: data.stage,
713
- message: data.message,
714
- progressPercent: data.progressPercent || 0,
715
- details: data.details
716
- });
717
- }
718
- });
719
- if (!pfpResult.success) {
720
- progressReporter.failed(
721
- "Failed to inscribe profile picture, continuing without PFP"
722
- );
723
- } else {
724
- pfpTopicId = pfpResult.pfpTopicId;
725
- }
726
- } else if (existingPfpTopicId) {
727
- progressReporter.preparing(
728
- `Using existing profile picture: ${existingPfpTopicId}`,
729
- 30
730
- );
731
- } else {
732
- progressReporter.preparing("No profile picture provided", 30);
733
- }
734
- const agentType = this.hcs11Client?.getAgentTypeFromMetadata({
735
- type: metadata.type || "autonomous"
736
- });
737
- progressReporter.preparing("Building agent profile", 65);
738
- const formattedSocials = [];
739
- if (metadata.socials) {
740
- if (metadata.socials.twitter) {
741
- formattedSocials.push({
742
- platform: "twitter",
743
- handle: metadata.socials.twitter
744
- });
745
- }
746
- if (metadata.socials.discord) {
747
- formattedSocials.push({
748
- platform: "discord",
749
- handle: metadata.socials.discord
750
- });
751
- }
752
- if (metadata.socials.github) {
753
- formattedSocials.push({
754
- platform: "github",
755
- handle: metadata.socials.github
756
- });
757
- }
758
- if (metadata.socials.website) {
759
- formattedSocials.push({
760
- platform: "website",
761
- handle: metadata.socials.website
762
- });
763
- }
764
- if (metadata.socials.x) {
765
- formattedSocials.push({
766
- platform: "twitter",
767
- handle: metadata.socials.x
768
- });
769
- }
770
- if (metadata.socials.linkedin) {
771
- formattedSocials.push({
772
- platform: "linkedin",
773
- handle: metadata.socials.linkedin
774
- });
775
- }
776
- if (metadata.socials.youtube) {
777
- formattedSocials.push({
778
- platform: "youtube",
779
- handle: metadata.socials.youtube
780
- });
781
- }
782
- if (metadata.socials.telegram) {
783
- formattedSocials.push({
784
- platform: "telegram",
785
- handle: metadata.socials.telegram
786
- });
787
- }
788
- }
789
- if (!this.hcs11Client) {
790
- progressReporter.failed(
791
- "HCS11Client is not available in this environment"
792
- );
793
- return {
794
- profileTopicId: "",
795
- success: false,
796
- error: "HCS11Client is not available in this environment",
797
- transactionId: ""
798
- };
799
- }
800
- const profile = this.hcs11Client.createAIAgentProfile(
801
- agentName,
802
- agentType,
803
- capabilities,
804
- metadata.model || "unknown",
805
- {
806
- alias: agentName.toLowerCase().replace(/\s+/g, "_"),
807
- bio: agentDescription,
808
- profileImage: pfpTopicId ? `hcs://1/${pfpTopicId}` : void 0,
809
- socials: formattedSocials.length > 0 ? formattedSocials : void 0,
810
- properties: {
811
- description: agentDescription,
812
- version: metadata.version || "1.0.0",
813
- creator: metadata.creator || "Unknown",
814
- supported_languages: metadata.supported_languages || ["en"],
815
- permissions: metadata.permissions || [],
816
- model_details: metadata.model_details,
817
- training: metadata.training,
818
- capabilities_description: metadata.capabilities_description,
819
- ...metadata
820
- },
821
- inboundTopicId,
822
- outboundTopicId,
823
- creator: metadata.creator
824
- }
825
- );
826
- const profileProgress = progressReporter.createSubProgress({
827
- minPercent: 65,
828
- maxPercent: 100,
829
- logPrefix: "Profile"
830
- });
831
- const profileResult = await this.hcs11Client.createAndInscribeProfile(
832
- profile,
833
- true,
834
- {
835
- progressCallback: (profileData) => {
836
- profileProgress.report({
837
- stage: profileData.stage,
838
- message: profileData.message,
839
- progressPercent: profileData.progressPercent || 0,
840
- details: profileData.details
841
- });
842
- }
843
- }
844
- );
845
- if (!profileResult.success) {
846
- progressReporter.failed("Failed to inscribe profile");
847
- return {
848
- profileTopicId: "",
849
- success: false,
850
- error: profileResult.error || "Failed to inscribe profile",
851
- transactionId: profileResult.transactionId || ""
852
- };
853
- }
854
- progressReporter.completed("Profile stored successfully", {
855
- profileTopicId: profileResult.profileTopicId
856
- });
857
- return {
858
- profileTopicId: profileResult.profileTopicId,
859
- pfpTopicId,
860
- success: true,
861
- transactionId: profileResult.transactionId || ""
862
- };
863
- } catch (error) {
864
- this.logger.error(`Error storing HCS11 profile: ${error.message}`);
865
- return {
866
- profileTopicId: "",
867
- success: false,
868
- error: error.message,
869
- transactionId: ""
870
- };
70
+ if (!this.config.metadata.socials) {
71
+ this.config.metadata.socials = {};
871
72
  }
73
+ this.config.metadata.socials[platform] = handle;
74
+ return this;
872
75
  }
873
- async createTopic(memo, adminKey, submitKey) {
874
- this.logger.info("Creating topic");
875
- const { accountId, signer } = this.getAccountAndSigner();
876
- const transaction = new TopicCreateTransaction().setTopicMemo(memo);
877
- const publicKey = await this.mirrorNode.getPublicKey(accountId);
878
- if (adminKey && publicKey) {
879
- transaction.setAdminKey(publicKey);
880
- transaction.setAutoRenewAccountId(accountId);
881
- }
882
- if (submitKey && publicKey) {
883
- transaction.setSubmitKey(publicKey);
76
+ addProperty(key, value) {
77
+ if (!this.config.metadata) {
78
+ this.config.metadata = { type: "manual" };
884
79
  }
885
- const transactionResponse = await this.hwc.executeTransactionWithErrorHandling(
886
- transaction,
887
- false
888
- );
889
- const error = transactionResponse.error;
890
- if (error) {
891
- this.logger.error(error);
892
- return {
893
- success: false,
894
- error
895
- };
80
+ if (!this.config.metadata.properties) {
81
+ this.config.metadata.properties = {};
896
82
  }
897
- const resultReceipt = transactionResponse.result;
898
- if (!resultReceipt?.topicId) {
899
- this.logger.error("Failed to create topic: topicId is null");
900
- return {
901
- success: false,
902
- error: "Failed to create topic: topicId is null"
903
- };
904
- }
905
- return {
906
- success: true,
907
- topicId: resultReceipt.topicId.toString()
908
- };
83
+ this.config.metadata.properties[key] = value;
84
+ return this;
909
85
  }
910
- async submitPayload(topicId, payload, submitKey, requiresFee) {
911
- this.logger.debug(`Submitting payload to topic ${topicId}`);
912
- let message;
913
- if (typeof payload === "string") {
914
- message = payload;
915
- } else {
916
- message = JSON.stringify(payload);
917
- }
918
- const transaction = new TopicMessageSubmitTransaction().setTopicId(topicId).setMessage(message);
919
- let transactionResponse;
920
- if (requiresFee) {
921
- this.logger.info(
922
- "Topic requires fee payment, setting max transaction fee"
923
- );
924
- transaction.setMaxTransactionFee(new Hbar(this.feeAmount));
925
- transaction.setTransactionMemo("HIP-991 Fee Payment");
86
+ setMetadata(metadata) {
87
+ this.config.metadata = metadata;
88
+ return this;
89
+ }
90
+ setProfilePicture(pfpBuffer, pfpFileName) {
91
+ this.config.pfpBuffer = pfpBuffer;
92
+ this.config.pfpFileName = pfpFileName;
93
+ return this;
94
+ }
95
+ setExistingProfilePicture(pfpTopicId) {
96
+ this.config.existingPfpTopicId = pfpTopicId;
97
+ return this;
98
+ }
99
+ setNetwork(network) {
100
+ this.config.network = network;
101
+ return this;
102
+ }
103
+ setInboundTopicType(inboundTopicType) {
104
+ this.config.inboundTopicType = inboundTopicType;
105
+ return this;
106
+ }
107
+ setFeeConfig(feeConfigBuilder) {
108
+ this.config.feeConfig = feeConfigBuilder;
109
+ return this;
110
+ }
111
+ setConnectionFeeConfig(feeConfigBuilder) {
112
+ this.config.connectionFeeConfig = feeConfigBuilder;
113
+ return this;
114
+ }
115
+ setExistingAccount(accountId, privateKey) {
116
+ this.config.existingAccount = { accountId, privateKey };
117
+ return this;
118
+ }
119
+ build() {
120
+ if (!this.config.name) {
121
+ throw new Error("Agent display name is required");
926
122
  }
927
- if (submitKey) {
928
- const { accountId, signer } = this.getAccountAndSigner();
929
- transaction.freezeWithSigner(signer);
930
- const signedTransaction = await transaction.sign(submitKey);
931
- transactionResponse = await this.hwc.executeTransactionWithErrorHandling(
932
- signedTransaction,
933
- true
934
- );
935
- } else {
936
- transactionResponse = await this.hwc.executeTransactionWithErrorHandling(
937
- transaction,
938
- false
939
- );
123
+ if (!this.config.bio) {
124
+ this.logger?.warn("Agent description is not set");
940
125
  }
941
- if (transactionResponse?.error) {
942
- this.logger.error(
943
- `Failed to submit payload: ${transactionResponse.error}`
944
- );
945
- throw new Error(`Failed to submit payload: ${transactionResponse.error}`);
126
+ if (!this.config.pfpBuffer && !this.config.existingPfpTopicId) {
127
+ this.logger.warn("No profile picture provided or referenced.");
946
128
  }
947
- if (!transactionResponse?.result) {
948
- this.logger.error(
949
- "Failed to submit message: receipt is null or undefined"
950
- );
951
- throw new Error("Failed to submit message: receipt is null or undefined");
129
+ if (!this.config.network) {
130
+ throw new Error("Network is required");
952
131
  }
953
- this.logger.debug("Payload submitted successfully via HWC");
954
- return transactionResponse.result;
955
- }
956
- async inscribeFile(buffer, fileName) {
957
- const { accountId, signer } = this.getAccountAndSigner();
958
- const mimeType = mimeTypesExports.lookup(fileName) || "application/octet-stream";
959
- const sdk = await InscriptionSDK.createWithAuth({
960
- type: "client",
961
- accountId,
962
- signer,
963
- network: this.network
964
- });
965
- const result = await sdk.inscribe(
966
- {
967
- file: {
968
- type: "base64",
969
- base64: buffer.toString("base64"),
970
- fileName,
971
- mimeType
972
- },
973
- holderId: accountId.toString(),
974
- mode: "file",
975
- network: this.network
976
- },
977
- signer
978
- );
979
- if (!result.transactionId || !result.jobId) {
980
- this.logger.error("Failed to inscribe, no transaction ID or job ID.");
981
- throw new Error("Failed to inscribe, no transaction ID or job ID.");
132
+ if (!this.config.inboundTopicType) {
133
+ this.config.inboundTopicType = InboundTopicType.PUBLIC;
982
134
  }
983
- if (result.transactionId && result.jobId) {
984
- this.logger.info(
985
- `Transaction ID: ${result.transactionId}, Job ID: ${result.jobId}`
986
- );
135
+ if (!this.config.capabilities) {
136
+ this.config.capabilities = [];
987
137
  }
988
- const status = await sdk.waitForInscription(result.jobId, 30, 4e3, true);
989
- return status;
990
- }
991
- getAccountAndSigner() {
992
- const accountInfo = this.hwc.getAccountInfo();
993
- const accountId = accountInfo.accountId.toString();
994
- const signer = this.hwc.dAppConnector.signers.find((s) => {
995
- return s.getAccountId().toString() === accountId;
996
- });
997
- if (!signer) {
998
- this.logger.error("Failed to find signer");
999
- throw new Error("Failed to find signer");
138
+ if (!this.config.metadata) {
139
+ this.config.metadata = { type: "manual" };
140
+ } else if (!this.config.metadata.type) {
141
+ this.config.metadata.type = "manual";
1000
142
  }
1001
- return { accountId, signer };
1002
- }
1003
- /**
1004
- * Inscribes a profile picture (PFP) on HCS-11.
1005
- *
1006
- * @param buffer - The buffer containing the PFP image.
1007
- * @param fileName - The name of the file containing the PFP image.
1008
- * @param options - Optional configuration options.
1009
- * @returns A promise that resolves to the topic ID of the inscribed PFP.
1010
- */
1011
- async inscribePfp(buffer, fileName, options) {
1012
- try {
1013
- const progressCallback = options?.progressCallback;
1014
- const progressReporter = new ProgressReporter({
1015
- module: "PFP-Inscription",
1016
- logger: this.logger,
1017
- callback: progressCallback
1018
- });
1019
- if (!this.hcs11Client) {
1020
- progressReporter.failed(
1021
- "HCS11Client is not available in this environment"
1022
- );
1023
- return {
1024
- pfpTopicId: "",
1025
- success: false,
1026
- error: "HCS11Client is not available in this environment",
1027
- transactionId: ""
1028
- };
1029
- }
1030
- progressReporter.preparing("Preparing to inscribe profile picture", 10);
1031
- this.logger.info("Inscribing profile picture using HCS-11 client");
1032
- const wrappedProgressCallback = (data) => {
1033
- progressReporter.report({
1034
- stage: data.stage || "confirming",
1035
- message: data.message || "Processing PFP inscription",
1036
- progressPercent: data.progressPercent || 50,
1037
- details: data.details
1038
- });
1039
- };
1040
- const imageResult = await this.hcs11Client.inscribeImage(
1041
- buffer,
1042
- fileName,
1043
- { progressCallback: wrappedProgressCallback }
1044
- );
1045
- if (!imageResult.success) {
1046
- progressReporter.failed(
1047
- `Failed to inscribe profile picture: ${imageResult.error}`
1048
- );
1049
- this.logger.error(
1050
- `Failed to inscribe profile picture: ${imageResult.error}`
1051
- );
1052
- return {
1053
- pfpTopicId: "",
1054
- success: false,
1055
- error: imageResult.error || "Failed to inscribe profile picture",
1056
- transactionId: imageResult.transactionId || ""
1057
- };
1058
- }
1059
- progressReporter.completed("Successfully inscribed profile picture", {
1060
- pfpTopicId: imageResult.imageTopicId
1061
- });
1062
- this.logger.info(
1063
- `Successfully inscribed profile picture with topic ID: ${imageResult.imageTopicId}`
1064
- );
1065
- return {
1066
- pfpTopicId: imageResult.imageTopicId,
1067
- success: true,
1068
- transactionId: imageResult.transactionId || ""
1069
- };
1070
- } catch (error) {
1071
- this.logger.error(`Error inscribing profile picture: ${error.message}`);
1072
- return {
1073
- pfpTopicId: "",
1074
- success: false,
1075
- error: error.message,
1076
- transactionId: ""
1077
- };
143
+ if (this.config.inboundTopicType === InboundTopicType.FEE_BASED && !this.config.feeConfig) {
144
+ throw new Error("Fee configuration is required for fee-based topics");
1078
145
  }
146
+ return this.config;
1079
147
  }
1080
148
  }
1081
149
  export {
1082
- BrowserHCSClient
150
+ AgentBuilder
1083
151
  };
1084
152
  //# sourceMappingURL=standards-sdk.es10.js.map