@hashgraphonline/standards-agent-kit 0.0.17 → 0.0.19

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 (431) hide show
  1. package/README.md +83 -0
  2. package/dist/_virtual/_commonjsHelpers.js +7 -0
  3. package/dist/_virtual/_commonjsHelpers.js.map +1 -0
  4. package/dist/_virtual/index.js +8 -0
  5. package/dist/_virtual/index.js.map +1 -0
  6. package/dist/_virtual/index10.js +5 -0
  7. package/dist/_virtual/index10.js.map +1 -0
  8. package/dist/_virtual/index11.js +5 -0
  9. package/dist/_virtual/index11.js.map +1 -0
  10. package/dist/_virtual/index12.js +8 -0
  11. package/dist/_virtual/index12.js.map +1 -0
  12. package/dist/_virtual/index13.js +5 -0
  13. package/dist/_virtual/index13.js.map +1 -0
  14. package/dist/_virtual/index14.js +5 -0
  15. package/dist/_virtual/index14.js.map +1 -0
  16. package/dist/_virtual/index2.js +3 -0
  17. package/dist/_virtual/index2.js.map +1 -0
  18. package/dist/_virtual/index3.js +8 -0
  19. package/dist/_virtual/index3.js.map +1 -0
  20. package/dist/_virtual/index4.js +8 -0
  21. package/dist/_virtual/index4.js.map +1 -0
  22. package/dist/_virtual/index5.js +6 -0
  23. package/dist/_virtual/index5.js.map +1 -0
  24. package/dist/_virtual/index6.js +8 -0
  25. package/dist/_virtual/index6.js.map +1 -0
  26. package/dist/_virtual/index7.js +5 -0
  27. package/dist/_virtual/index7.js.map +1 -0
  28. package/dist/_virtual/index8.js +5 -0
  29. package/dist/_virtual/index8.js.map +1 -0
  30. package/dist/_virtual/index9.js +5 -0
  31. package/dist/_virtual/index9.js.map +1 -0
  32. package/dist/_virtual/lower-bound.js +5 -0
  33. package/dist/_virtual/lower-bound.js.map +1 -0
  34. package/dist/_virtual/priority-queue.js +5 -0
  35. package/dist/_virtual/priority-queue.js.map +1 -0
  36. package/dist/_virtual/re.js +5 -0
  37. package/dist/_virtual/re.js.map +1 -0
  38. package/dist/_virtual/retry.js +5 -0
  39. package/dist/_virtual/retry.js.map +1 -0
  40. package/dist/agents/index.d.ts +0 -0
  41. package/dist/hcs10/HCS10Client.d.ts +117 -0
  42. package/dist/hcs10/HCS10Client.js +251 -0
  43. package/dist/hcs10/HCS10Client.js.map +1 -0
  44. package/dist/hcs10/index.d.ts +1 -0
  45. package/dist/hcs10/types.d.ts +35 -0
  46. package/dist/index.d.ts +5 -2
  47. package/dist/index.es.js +9747 -11699
  48. package/dist/index.es.js.map +1 -1
  49. package/dist/index.js +44 -0
  50. package/dist/index.js.map +1 -0
  51. package/dist/init.d.ts +59 -0
  52. package/dist/init.js +92 -0
  53. package/dist/init.js.map +1 -0
  54. package/dist/node_modules/@langchain/core/dist/callbacks/base.js +98 -0
  55. package/dist/node_modules/@langchain/core/dist/callbacks/base.js.map +1 -0
  56. package/dist/node_modules/@langchain/core/dist/callbacks/manager.js +419 -0
  57. package/dist/node_modules/@langchain/core/dist/callbacks/manager.js.map +1 -0
  58. package/dist/node_modules/@langchain/core/dist/callbacks/promises.js +16 -0
  59. package/dist/node_modules/@langchain/core/dist/callbacks/promises.js.map +1 -0
  60. package/dist/node_modules/@langchain/core/dist/language_models/base.js +42 -0
  61. package/dist/node_modules/@langchain/core/dist/language_models/base.js.map +1 -0
  62. package/dist/node_modules/@langchain/core/dist/load/map_keys.js +16 -0
  63. package/dist/node_modules/@langchain/core/dist/load/map_keys.js.map +1 -0
  64. package/dist/node_modules/@langchain/core/dist/load/serializable.js +121 -0
  65. package/dist/node_modules/@langchain/core/dist/load/serializable.js.map +1 -0
  66. package/dist/node_modules/@langchain/core/dist/messages/ai.js +95 -0
  67. package/dist/node_modules/@langchain/core/dist/messages/ai.js.map +1 -0
  68. package/dist/node_modules/@langchain/core/dist/messages/base.js +112 -0
  69. package/dist/node_modules/@langchain/core/dist/messages/base.js.map +1 -0
  70. package/dist/node_modules/@langchain/core/dist/messages/utils.js +30 -0
  71. package/dist/node_modules/@langchain/core/dist/messages/utils.js.map +1 -0
  72. package/dist/node_modules/@langchain/core/dist/runnables/base.js +1277 -0
  73. package/dist/node_modules/@langchain/core/dist/runnables/base.js.map +1 -0
  74. package/dist/node_modules/@langchain/core/dist/runnables/config.js +83 -0
  75. package/dist/node_modules/@langchain/core/dist/runnables/config.js.map +1 -0
  76. package/dist/node_modules/@langchain/core/dist/runnables/graph.js +106 -0
  77. package/dist/node_modules/@langchain/core/dist/runnables/graph.js.map +1 -0
  78. package/dist/node_modules/@langchain/core/dist/runnables/iter.js +33 -0
  79. package/dist/node_modules/@langchain/core/dist/runnables/iter.js.map +1 -0
  80. package/dist/node_modules/@langchain/core/dist/runnables/utils.js +54 -0
  81. package/dist/node_modules/@langchain/core/dist/runnables/utils.js.map +1 -0
  82. package/dist/node_modules/@langchain/core/dist/runnables/wrappers.js +20 -0
  83. package/dist/node_modules/@langchain/core/dist/runnables/wrappers.js.map +1 -0
  84. package/dist/node_modules/@langchain/core/dist/singletons/index.js +34 -0
  85. package/dist/node_modules/@langchain/core/dist/singletons/index.js.map +1 -0
  86. package/dist/node_modules/@langchain/core/dist/tools.js +69 -0
  87. package/dist/node_modules/@langchain/core/dist/tools.js.map +1 -0
  88. package/dist/node_modules/@langchain/core/dist/tracers/base.js +299 -0
  89. package/dist/node_modules/@langchain/core/dist/tracers/base.js.map +1 -0
  90. package/dist/node_modules/@langchain/core/dist/tracers/console.js +193 -0
  91. package/dist/node_modules/@langchain/core/dist/tracers/console.js.map +1 -0
  92. package/dist/node_modules/@langchain/core/dist/tracers/initialize.js +10 -0
  93. package/dist/node_modules/@langchain/core/dist/tracers/initialize.js.map +1 -0
  94. package/dist/node_modules/@langchain/core/dist/tracers/log_stream.js +284 -0
  95. package/dist/node_modules/@langchain/core/dist/tracers/log_stream.js.map +1 -0
  96. package/dist/node_modules/@langchain/core/dist/tracers/root_listener.js +54 -0
  97. package/dist/node_modules/@langchain/core/dist/tracers/root_listener.js.map +1 -0
  98. package/dist/node_modules/@langchain/core/dist/tracers/tracer_langchain.js +68 -0
  99. package/dist/node_modules/@langchain/core/dist/tracers/tracer_langchain.js.map +1 -0
  100. package/dist/node_modules/@langchain/core/dist/utils/async_caller.js +86 -0
  101. package/dist/node_modules/@langchain/core/dist/utils/async_caller.js.map +1 -0
  102. package/dist/node_modules/@langchain/core/dist/utils/env.js +33 -0
  103. package/dist/node_modules/@langchain/core/dist/utils/env.js.map +1 -0
  104. package/dist/node_modules/@langchain/core/dist/utils/fast-json-patch/core.js +218 -0
  105. package/dist/node_modules/@langchain/core/dist/utils/fast-json-patch/core.js.map +1 -0
  106. package/dist/node_modules/@langchain/core/dist/utils/fast-json-patch/helpers.js +117 -0
  107. package/dist/node_modules/@langchain/core/dist/utils/fast-json-patch/helpers.js.map +1 -0
  108. package/dist/node_modules/@langchain/core/dist/utils/json.js +40 -0
  109. package/dist/node_modules/@langchain/core/dist/utils/json.js.map +1 -0
  110. package/dist/node_modules/@langchain/core/dist/utils/stream.js +164 -0
  111. package/dist/node_modules/@langchain/core/dist/utils/stream.js.map +1 -0
  112. package/dist/node_modules/@langchain/core/node_modules/ansi-styles/index.js +111 -0
  113. package/dist/node_modules/@langchain/core/node_modules/ansi-styles/index.js.map +1 -0
  114. package/dist/node_modules/@langchain/core/node_modules/camelcase/index.js +30 -0
  115. package/dist/node_modules/@langchain/core/node_modules/camelcase/index.js.map +1 -0
  116. package/dist/node_modules/@langchain/core/node_modules/langsmith/dist/client.js +2002 -0
  117. package/dist/node_modules/@langchain/core/node_modules/langsmith/dist/client.js.map +1 -0
  118. package/dist/node_modules/@langchain/core/node_modules/langsmith/dist/index.js +8 -0
  119. package/dist/node_modules/@langchain/core/node_modules/langsmith/dist/index.js.map +1 -0
  120. package/dist/node_modules/@langchain/core/node_modules/langsmith/dist/singletons/fetch.js +5 -0
  121. package/dist/node_modules/@langchain/core/node_modules/langsmith/dist/singletons/fetch.js.map +1 -0
  122. package/dist/node_modules/@langchain/core/node_modules/langsmith/dist/utils/_uuid.js +12 -0
  123. package/dist/node_modules/@langchain/core/node_modules/langsmith/dist/utils/_uuid.js.map +1 -0
  124. package/dist/node_modules/@langchain/core/node_modules/langsmith/dist/utils/async_caller.js +94 -0
  125. package/dist/node_modules/@langchain/core/node_modules/langsmith/dist/utils/async_caller.js.map +1 -0
  126. package/dist/node_modules/@langchain/core/node_modules/langsmith/dist/utils/env.js +96 -0
  127. package/dist/node_modules/@langchain/core/node_modules/langsmith/dist/utils/env.js.map +1 -0
  128. package/dist/node_modules/@langchain/core/node_modules/langsmith/dist/utils/error.js +20 -0
  129. package/dist/node_modules/@langchain/core/node_modules/langsmith/dist/utils/error.js.map +1 -0
  130. package/dist/node_modules/@langchain/core/node_modules/langsmith/dist/utils/fast-safe-stringify/index.js +82 -0
  131. package/dist/node_modules/@langchain/core/node_modules/langsmith/dist/utils/fast-safe-stringify/index.js.map +1 -0
  132. package/dist/node_modules/@langchain/core/node_modules/langsmith/dist/utils/messages.js +15 -0
  133. package/dist/node_modules/@langchain/core/node_modules/langsmith/dist/utils/messages.js.map +1 -0
  134. package/dist/node_modules/@langchain/core/node_modules/langsmith/dist/utils/prompts.js +27 -0
  135. package/dist/node_modules/@langchain/core/node_modules/langsmith/dist/utils/prompts.js.map +1 -0
  136. package/dist/node_modules/@langchain/core/node_modules/langsmith/dist/utils/warn.js +8 -0
  137. package/dist/node_modules/@langchain/core/node_modules/langsmith/dist/utils/warn.js.map +1 -0
  138. package/dist/node_modules/@langchain/core/node_modules/langsmith/node_modules/uuid/dist/esm-browser/native.js +8 -0
  139. package/dist/node_modules/@langchain/core/node_modules/langsmith/node_modules/uuid/dist/esm-browser/native.js.map +1 -0
  140. package/dist/node_modules/@langchain/core/node_modules/langsmith/node_modules/uuid/dist/esm-browser/regex.js +5 -0
  141. package/dist/node_modules/@langchain/core/node_modules/langsmith/node_modules/uuid/dist/esm-browser/regex.js.map +1 -0
  142. package/dist/node_modules/@langchain/core/node_modules/langsmith/node_modules/uuid/dist/esm-browser/rng.js +10 -0
  143. package/dist/node_modules/@langchain/core/node_modules/langsmith/node_modules/uuid/dist/esm-browser/rng.js.map +1 -0
  144. package/dist/node_modules/@langchain/core/node_modules/langsmith/node_modules/uuid/dist/esm-browser/stringify.js +10 -0
  145. package/dist/node_modules/@langchain/core/node_modules/langsmith/node_modules/uuid/dist/esm-browser/stringify.js.map +1 -0
  146. package/dist/node_modules/@langchain/core/node_modules/langsmith/node_modules/uuid/dist/esm-browser/v4.js +14 -0
  147. package/dist/node_modules/@langchain/core/node_modules/langsmith/node_modules/uuid/dist/esm-browser/v4.js.map +1 -0
  148. package/dist/node_modules/@langchain/core/node_modules/langsmith/node_modules/uuid/dist/esm-browser/validate.js +8 -0
  149. package/dist/node_modules/@langchain/core/node_modules/langsmith/node_modules/uuid/dist/esm-browser/validate.js.map +1 -0
  150. package/dist/node_modules/@langchain/core/node_modules/uuid/dist/esm-browser/native.js +7 -0
  151. package/dist/node_modules/@langchain/core/node_modules/uuid/dist/esm-browser/native.js.map +1 -0
  152. package/dist/node_modules/@langchain/core/node_modules/uuid/dist/esm-browser/regex.js +5 -0
  153. package/dist/node_modules/@langchain/core/node_modules/uuid/dist/esm-browser/regex.js.map +1 -0
  154. package/dist/node_modules/@langchain/core/node_modules/uuid/dist/esm-browser/rng.js +11 -0
  155. package/dist/node_modules/@langchain/core/node_modules/uuid/dist/esm-browser/rng.js.map +1 -0
  156. package/dist/node_modules/@langchain/core/node_modules/uuid/dist/esm-browser/stringify.js +10 -0
  157. package/dist/node_modules/@langchain/core/node_modules/uuid/dist/esm-browser/stringify.js.map +1 -0
  158. package/dist/node_modules/@langchain/core/node_modules/uuid/dist/esm-browser/v4.js +14 -0
  159. package/dist/node_modules/@langchain/core/node_modules/uuid/dist/esm-browser/v4.js.map +1 -0
  160. package/dist/node_modules/@langchain/core/node_modules/uuid/dist/esm-browser/validate.js +8 -0
  161. package/dist/node_modules/@langchain/core/node_modules/uuid/dist/esm-browser/validate.js.map +1 -0
  162. package/dist/node_modules/base64-js/index.js +53 -0
  163. package/dist/node_modules/base64-js/index.js.map +1 -0
  164. package/dist/node_modules/decamelize/index.js +12 -0
  165. package/dist/node_modules/decamelize/index.js.map +1 -0
  166. package/dist/node_modules/eventemitter3/index.js +112 -0
  167. package/dist/node_modules/eventemitter3/index.js.map +1 -0
  168. package/dist/node_modules/js-tiktoken/dist/chunk-Z5MDQTGX.js +117 -0
  169. package/dist/node_modules/js-tiktoken/dist/chunk-Z5MDQTGX.js.map +1 -0
  170. package/dist/node_modules/p-finally/index.js +18 -0
  171. package/dist/node_modules/p-finally/index.js.map +1 -0
  172. package/dist/node_modules/p-queue/dist/index.js +198 -0
  173. package/dist/node_modules/p-queue/dist/index.js.map +1 -0
  174. package/dist/node_modules/p-queue/dist/lower-bound.js +20 -0
  175. package/dist/node_modules/p-queue/dist/lower-bound.js.map +1 -0
  176. package/dist/node_modules/p-queue/dist/priority-queue.js +41 -0
  177. package/dist/node_modules/p-queue/dist/priority-queue.js.map +1 -0
  178. package/dist/node_modules/p-retry/index.js +63 -0
  179. package/dist/node_modules/p-retry/index.js.map +1 -0
  180. package/dist/node_modules/p-timeout/index.js +45 -0
  181. package/dist/node_modules/p-timeout/index.js.map +1 -0
  182. package/dist/node_modules/retry/index.js +9 -0
  183. package/dist/node_modules/retry/index.js.map +1 -0
  184. package/dist/node_modules/retry/lib/retry.js +59 -0
  185. package/dist/node_modules/retry/lib/retry.js.map +1 -0
  186. package/dist/node_modules/retry/lib/retry_operation.js +58 -0
  187. package/dist/node_modules/retry/lib/retry_operation.js.map +1 -0
  188. package/dist/node_modules/semver/classes/comparator.js +57 -0
  189. package/dist/node_modules/semver/classes/comparator.js.map +1 -0
  190. package/dist/node_modules/semver/classes/range.js +149 -0
  191. package/dist/node_modules/semver/classes/range.js.map +1 -0
  192. package/dist/node_modules/semver/classes/semver.js +170 -0
  193. package/dist/node_modules/semver/classes/semver.js.map +1 -0
  194. package/dist/node_modules/semver/functions/clean.js +15 -0
  195. package/dist/node_modules/semver/functions/clean.js.map +1 -0
  196. package/dist/node_modules/semver/functions/cmp.js +40 -0
  197. package/dist/node_modules/semver/functions/cmp.js.map +1 -0
  198. package/dist/node_modules/semver/functions/coerce.js +34 -0
  199. package/dist/node_modules/semver/functions/coerce.js.map +1 -0
  200. package/dist/node_modules/semver/functions/compare-build.js +15 -0
  201. package/dist/node_modules/semver/functions/compare-build.js.map +1 -0
  202. package/dist/node_modules/semver/functions/compare-loose.js +12 -0
  203. package/dist/node_modules/semver/functions/compare-loose.js.map +1 -0
  204. package/dist/node_modules/semver/functions/compare.js +12 -0
  205. package/dist/node_modules/semver/functions/compare.js.map +1 -0
  206. package/dist/node_modules/semver/functions/diff.js +25 -0
  207. package/dist/node_modules/semver/functions/diff.js.map +1 -0
  208. package/dist/node_modules/semver/functions/eq.js +12 -0
  209. package/dist/node_modules/semver/functions/eq.js.map +1 -0
  210. package/dist/node_modules/semver/functions/gt.js +12 -0
  211. package/dist/node_modules/semver/functions/gt.js.map +1 -0
  212. package/dist/node_modules/semver/functions/gte.js +12 -0
  213. package/dist/node_modules/semver/functions/gte.js.map +1 -0
  214. package/dist/node_modules/semver/functions/inc.js +22 -0
  215. package/dist/node_modules/semver/functions/inc.js.map +1 -0
  216. package/dist/node_modules/semver/functions/lt.js +12 -0
  217. package/dist/node_modules/semver/functions/lt.js.map +1 -0
  218. package/dist/node_modules/semver/functions/lte.js +12 -0
  219. package/dist/node_modules/semver/functions/lte.js.map +1 -0
  220. package/dist/node_modules/semver/functions/major.js +12 -0
  221. package/dist/node_modules/semver/functions/major.js.map +1 -0
  222. package/dist/node_modules/semver/functions/minor.js +12 -0
  223. package/dist/node_modules/semver/functions/minor.js.map +1 -0
  224. package/dist/node_modules/semver/functions/neq.js +12 -0
  225. package/dist/node_modules/semver/functions/neq.js.map +1 -0
  226. package/dist/node_modules/semver/functions/parse.js +22 -0
  227. package/dist/node_modules/semver/functions/parse.js.map +1 -0
  228. package/dist/node_modules/semver/functions/patch.js +12 -0
  229. package/dist/node_modules/semver/functions/patch.js.map +1 -0
  230. package/dist/node_modules/semver/functions/prerelease.js +15 -0
  231. package/dist/node_modules/semver/functions/prerelease.js.map +1 -0
  232. package/dist/node_modules/semver/functions/rcompare.js +12 -0
  233. package/dist/node_modules/semver/functions/rcompare.js.map +1 -0
  234. package/dist/node_modules/semver/functions/rsort.js +12 -0
  235. package/dist/node_modules/semver/functions/rsort.js.map +1 -0
  236. package/dist/node_modules/semver/functions/satisfies.js +19 -0
  237. package/dist/node_modules/semver/functions/satisfies.js.map +1 -0
  238. package/dist/node_modules/semver/functions/sort.js +12 -0
  239. package/dist/node_modules/semver/functions/sort.js.map +1 -0
  240. package/dist/node_modules/semver/functions/valid.js +15 -0
  241. package/dist/node_modules/semver/functions/valid.js.map +1 -0
  242. package/dist/node_modules/semver/index.js +98 -0
  243. package/dist/node_modules/semver/index.js.map +1 -0
  244. package/dist/node_modules/semver/internal/constants.js +29 -0
  245. package/dist/node_modules/semver/internal/constants.js.map +1 -0
  246. package/dist/node_modules/semver/internal/debug.js +9 -0
  247. package/dist/node_modules/semver/internal/debug.js.map +1 -0
  248. package/dist/node_modules/semver/internal/identifiers.js +17 -0
  249. package/dist/node_modules/semver/internal/identifiers.js.map +1 -0
  250. package/dist/node_modules/semver/internal/lrucache.js +33 -0
  251. package/dist/node_modules/semver/internal/lrucache.js.map +1 -0
  252. package/dist/node_modules/semver/internal/parse-options.js +11 -0
  253. package/dist/node_modules/semver/internal/parse-options.js.map +1 -0
  254. package/dist/node_modules/semver/internal/re.js +33 -0
  255. package/dist/node_modules/semver/internal/re.js.map +1 -0
  256. package/dist/node_modules/semver/ranges/gtr.js +12 -0
  257. package/dist/node_modules/semver/ranges/gtr.js.map +1 -0
  258. package/dist/node_modules/semver/ranges/intersects.js +12 -0
  259. package/dist/node_modules/semver/ranges/intersects.js.map +1 -0
  260. package/dist/node_modules/semver/ranges/ltr.js +12 -0
  261. package/dist/node_modules/semver/ranges/ltr.js.map +1 -0
  262. package/dist/node_modules/semver/ranges/max-satisfying.js +23 -0
  263. package/dist/node_modules/semver/ranges/max-satisfying.js.map +1 -0
  264. package/dist/node_modules/semver/ranges/min-satisfying.js +23 -0
  265. package/dist/node_modules/semver/ranges/min-satisfying.js.map +1 -0
  266. package/dist/node_modules/semver/ranges/min-version.js +43 -0
  267. package/dist/node_modules/semver/ranges/min-version.js.map +1 -0
  268. package/dist/node_modules/semver/ranges/outside.js +45 -0
  269. package/dist/node_modules/semver/ranges/outside.js.map +1 -0
  270. package/dist/node_modules/semver/ranges/simplify.js +25 -0
  271. package/dist/node_modules/semver/ranges/simplify.js.map +1 -0
  272. package/dist/node_modules/semver/ranges/subset.js +95 -0
  273. package/dist/node_modules/semver/ranges/subset.js.map +1 -0
  274. package/dist/node_modules/semver/ranges/to-comparators.js +12 -0
  275. package/dist/node_modules/semver/ranges/to-comparators.js.map +1 -0
  276. package/dist/node_modules/semver/ranges/valid.js +18 -0
  277. package/dist/node_modules/semver/ranges/valid.js.map +1 -0
  278. package/dist/node_modules/zod-to-json-schema/dist/esm/Options.js +32 -0
  279. package/dist/node_modules/zod-to-json-schema/dist/esm/Options.js.map +1 -0
  280. package/dist/node_modules/zod-to-json-schema/dist/esm/Refs.js +22 -0
  281. package/dist/node_modules/zod-to-json-schema/dist/esm/Refs.js.map +1 -0
  282. package/dist/node_modules/zod-to-json-schema/dist/esm/errorMessages.js +14 -0
  283. package/dist/node_modules/zod-to-json-schema/dist/esm/errorMessages.js.map +1 -0
  284. package/dist/node_modules/zod-to-json-schema/dist/esm/parseDef.js +44 -0
  285. package/dist/node_modules/zod-to-json-schema/dist/esm/parseDef.js.map +1 -0
  286. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/any.js +7 -0
  287. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/any.js.map +1 -0
  288. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/array.js +17 -0
  289. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/array.js.map +1 -0
  290. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/bigint.js +26 -0
  291. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/bigint.js.map +1 -0
  292. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/boolean.js +9 -0
  293. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/boolean.js.map +1 -0
  294. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/branded.js +8 -0
  295. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/branded.js.map +1 -0
  296. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/catch.js +6 -0
  297. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/catch.js.map +1 -0
  298. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/date.js +59 -0
  299. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/date.js.map +1 -0
  300. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/default.js +11 -0
  301. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/default.js.map +1 -0
  302. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/effects.js +8 -0
  303. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/effects.js.map +1 -0
  304. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/enum.js +10 -0
  305. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/enum.js.map +1 -0
  306. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/intersection.js +36 -0
  307. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/intersection.js.map +1 -0
  308. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/literal.js +16 -0
  309. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/literal.js.map +1 -0
  310. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/map.js +27 -0
  311. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/map.js.map +1 -0
  312. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/nativeEnum.js +11 -0
  313. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/nativeEnum.js.map +1 -0
  314. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/never.js +9 -0
  315. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/never.js.map +1 -0
  316. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/null.js +12 -0
  317. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/null.js.map +1 -0
  318. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/nullable.js +30 -0
  319. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/nullable.js.map +1 -0
  320. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/number.js +28 -0
  321. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/number.js.map +1 -0
  322. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/object.js +50 -0
  323. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/object.js.map +1 -0
  324. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/optional.js +22 -0
  325. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/optional.js.map +1 -0
  326. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/pipeline.js +21 -0
  327. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/pipeline.js.map +1 -0
  328. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/promise.js +8 -0
  329. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/promise.js.map +1 -0
  330. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/readonly.js +6 -0
  331. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/readonly.js.map +1 -0
  332. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/record.js +56 -0
  333. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/record.js.map +1 -0
  334. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/set.js +17 -0
  335. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/set.js.map +1 -0
  336. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/string.js +245 -0
  337. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/string.js.map +1 -0
  338. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/tuple.js +27 -0
  339. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/tuple.js.map +1 -0
  340. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/undefined.js +9 -0
  341. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/undefined.js.map +1 -0
  342. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/union.js +69 -0
  343. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/union.js.map +1 -0
  344. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/unknown.js +7 -0
  345. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/unknown.js.map +1 -0
  346. package/dist/node_modules/zod-to-json-schema/dist/esm/selectParser.js +110 -0
  347. package/dist/node_modules/zod-to-json-schema/dist/esm/selectParser.js.map +1 -0
  348. package/dist/node_modules/zod-to-json-schema/dist/esm/zodToJsonSchema.js +26 -0
  349. package/dist/node_modules/zod-to-json-schema/dist/esm/zodToJsonSchema.js.map +1 -0
  350. package/dist/plugins/BasePlugin.d.ts +28 -0
  351. package/dist/plugins/BasePlugin.js +19 -0
  352. package/dist/plugins/BasePlugin.js.map +1 -0
  353. package/dist/plugins/PluginInterface.d.ts +64 -0
  354. package/dist/plugins/PluginLoader.d.ts +38 -0
  355. package/dist/plugins/PluginLoader.js +60 -0
  356. package/dist/plugins/PluginLoader.js.map +1 -0
  357. package/dist/plugins/PluginRegistry.d.ts +47 -0
  358. package/dist/plugins/PluginRegistry.js +71 -0
  359. package/dist/plugins/PluginRegistry.js.map +1 -0
  360. package/dist/plugins/__tests__/BasePlugin.test.d.ts +1 -0
  361. package/dist/plugins/__tests__/PluginLoader.test.d.ts +1 -0
  362. package/dist/plugins/__tests__/PluginRegistry.test.d.ts +1 -0
  363. package/dist/plugins/defi/index.d.ts +13 -0
  364. package/dist/plugins/hedera/HbarPricePlugin.d.ts +45 -0
  365. package/dist/plugins/hedera/HbarPricePlugin.js +70 -0
  366. package/dist/plugins/hedera/HbarPricePlugin.js.map +1 -0
  367. package/dist/plugins/hedera/__tests__/HbarPricePlugin.test.d.ts +1 -0
  368. package/dist/plugins/index.d.ts +5 -0
  369. package/dist/plugins/weather/index.d.ts +15 -0
  370. package/dist/src/agents/index.d.ts +0 -0
  371. package/dist/src/init.d.ts +2 -2
  372. package/dist/src/plugins/hedera/HbarPricePlugin.d.ts +45 -0
  373. package/dist/src/plugins/index.d.ts +1 -0
  374. package/dist/src/tools/CheckMessagesTool.d.ts +9 -2
  375. package/dist/src/utils/state-tools.d.ts +23 -0
  376. package/dist/state/index.d.ts +2 -0
  377. package/dist/state/open-convai-state.d.ts +84 -0
  378. package/dist/state/open-convai-state.js +132 -0
  379. package/dist/state/open-convai-state.js.map +1 -0
  380. package/dist/state/state-types.d.ts +143 -0
  381. package/dist/tools/AcceptConnectionRequestTool.d.ts +33 -0
  382. package/dist/tools/AcceptConnectionRequestTool.js +116 -0
  383. package/dist/tools/AcceptConnectionRequestTool.js.map +1 -0
  384. package/dist/tools/CheckMessagesTool.d.ts +34 -0
  385. package/dist/tools/CheckMessagesTool.js +96 -0
  386. package/dist/tools/CheckMessagesTool.js.map +1 -0
  387. package/dist/tools/ConnectionMonitorTool.d.ts +96 -0
  388. package/dist/tools/ConnectionMonitorTool.js +289 -0
  389. package/dist/tools/ConnectionMonitorTool.js.map +1 -0
  390. package/dist/tools/ConnectionTool.d.ts +40 -0
  391. package/dist/tools/ConnectionTool.js +114 -0
  392. package/dist/tools/ConnectionTool.js.map +1 -0
  393. package/dist/tools/FindRegistrationsTool.d.ts +27 -0
  394. package/dist/tools/FindRegistrationsTool.js +64 -0
  395. package/dist/tools/FindRegistrationsTool.js.map +1 -0
  396. package/dist/tools/InitiateConnectionTool.d.ts +30 -0
  397. package/dist/tools/InitiateConnectionTool.js +79 -0
  398. package/dist/tools/InitiateConnectionTool.js.map +1 -0
  399. package/dist/tools/ListConnectionsTool.d.ts +33 -0
  400. package/dist/tools/ListConnectionsTool.js +327 -0
  401. package/dist/tools/ListConnectionsTool.js.map +1 -0
  402. package/dist/tools/ListUnapprovedConnectionRequestsTool.d.ts +53 -0
  403. package/dist/tools/ListUnapprovedConnectionRequestsTool.js +177 -0
  404. package/dist/tools/ListUnapprovedConnectionRequestsTool.js.map +1 -0
  405. package/dist/tools/ManageConnectionRequestsTool.d.ts +39 -0
  406. package/dist/tools/ManageConnectionRequestsTool.js +161 -0
  407. package/dist/tools/ManageConnectionRequestsTool.js.map +1 -0
  408. package/dist/tools/RegisterAgentTool.d.ts +188 -0
  409. package/dist/tools/RegisterAgentTool.js +331 -0
  410. package/dist/tools/RegisterAgentTool.js.map +1 -0
  411. package/dist/tools/RetrieveProfileTool.d.ts +34 -0
  412. package/dist/tools/RetrieveProfileTool.js +53 -0
  413. package/dist/tools/RetrieveProfileTool.js.map +1 -0
  414. package/dist/tools/SendMessageToConnectionTool.d.ts +31 -0
  415. package/dist/tools/SendMessageToConnectionTool.js +74 -0
  416. package/dist/tools/SendMessageToConnectionTool.js.map +1 -0
  417. package/dist/tools/SendMessageTool.d.ts +44 -0
  418. package/dist/tools/SendMessageTool.js +75 -0
  419. package/dist/tools/SendMessageTool.js.map +1 -0
  420. package/dist/tools/index.d.ts +13 -0
  421. package/dist/utils/Encryption.d.ts +7 -0
  422. package/dist/utils/Encryption.js +7 -0
  423. package/dist/utils/Encryption.js.map +1 -0
  424. package/dist/utils/HederaClient.d.ts +18 -0
  425. package/dist/utils/connectionUtils.d.ts +15 -0
  426. package/dist/utils/connectionUtils.js +64 -0
  427. package/dist/utils/connectionUtils.js.map +1 -0
  428. package/dist/utils/state-tools.d.ts +23 -0
  429. package/dist/utils/state-tools.js +90 -0
  430. package/dist/utils/state-tools.js.map +1 -0
  431. package/package.json +20 -10
@@ -0,0 +1,327 @@
1
+ import { StructuredTool as O } from "../node_modules/@langchain/core/dist/tools.js";
2
+ import { z as v } from "zod";
3
+ class H extends O {
4
+ constructor({ stateManager: o, hcsClient: n, ...g }) {
5
+ super(g), this.name = "list_connections", this.description = "Lists the currently active HCS-10 connections with detailed information. Shows connection status, agent details, and recent activity. Use this to get a comprehensive view of all active connections.", this.schema = v.object({
6
+ includeDetails: v.boolean().optional().describe(
7
+ "Whether to include detailed information about each connection"
8
+ ),
9
+ showPending: v.boolean().optional().describe("Whether to include pending connection requests")
10
+ }), this.stateManager = o, this.hcsClient = n;
11
+ }
12
+ async _call(o) {
13
+ const n = o.includeDetails ?? !0, g = o.showPending ?? !0, u = this.stateManager.listConnections(), A = await this.enhanceConnectionInfo(
14
+ u
15
+ );
16
+ if (A.length === 0)
17
+ return "There are currently no active connections.";
18
+ const m = A.filter(
19
+ (c) => !c.isPending && !c.needsConfirmation
20
+ ), I = A.filter((c) => c.isPending), y = A.filter(
21
+ (c) => c.needsConfirmation
22
+ );
23
+ let p = "";
24
+ return m.length > 0 && (p += `🟢 Active Connections (${m.length}):
25
+ `, m.forEach((c, b) => {
26
+ p += this.formatConnection(c, b, n);
27
+ }), p += `
28
+ `), g && y.length > 0 && (p += `🟠 Connections Needing Confirmation (${y.length}):
29
+ `, y.forEach((c, b) => {
30
+ p += this.formatConnection(c, b, n);
31
+ }), p += `
32
+ `), g && I.length > 0 && (p += `⚪ Pending Connection Requests (${I.length}):
33
+ `, I.forEach((c, b) => {
34
+ p += this.formatConnection(c, b, n);
35
+ })), p.trim();
36
+ }
37
+ formatConnection(o, n, g) {
38
+ var I, y;
39
+ let u = `${n + 1}. ${((I = o.profileInfo) == null ? void 0 : I.name) || o.targetAgentName || "Unknown Agent"} (${o.targetAccountId})
40
+ `;
41
+ const A = o.isPending ? "(Pending Request)" : o.connectionTopicId;
42
+ u += ` Topic: ${A}
43
+ `;
44
+ let m = "unknown";
45
+ if (o.isPending ? m = "pending request (sent)" : o.needsConfirmation ? m = "needs confirmation (received)" : o.status === "established" ? m = "established" : o.status && (m = o.status), u += ` Status: ${m}
46
+ `, g) {
47
+ if ((y = o.profileInfo) != null && y.bio && (u += ` Bio: ${o.profileInfo.bio.substring(0, 100)}${o.profileInfo.bio.length > 100 ? "..." : ""}
48
+ `), o.created) {
49
+ const p = o.isPending ? "Request sent" : "Connection established";
50
+ u += ` ${p}: ${o.created.toLocaleString()}
51
+ `;
52
+ }
53
+ o.lastActivity && (u += ` Last activity: ${o.lastActivity.toLocaleString()}
54
+ `);
55
+ }
56
+ return u;
57
+ }
58
+ async enhanceConnectionInfo(o) {
59
+ var $, S, k;
60
+ const n = /* @__PURE__ */ new Map(), g = /* @__PURE__ */ new Map(), u = /* @__PURE__ */ new Set(), A = /* @__PURE__ */ new Map(), m = ($ = this.hcsClient) == null ? void 0 : $.getAccountAndSigner().accountId;
61
+ for (const e of o)
62
+ e.targetAccountId && u.add(e.targetAccountId), n.set(e.connectionTopicId, {
63
+ ...e,
64
+ status: "established",
65
+ isPending: !1,
66
+ needsConfirmation: !1
67
+ });
68
+ if (!this.hcsClient)
69
+ return Array.from(n.values());
70
+ let I = [], y = { messages: [] };
71
+ try {
72
+ [I, y] = await Promise.all([
73
+ this.fetchOutboundMessages(),
74
+ this.hcsClient.getInboundTopicId().then((e) => this.hcsClient.getMessages(e)).catch((e) => ({ messages: [] }))
75
+ ]);
76
+ } catch {
77
+ }
78
+ const p = y.messages, c = /* @__PURE__ */ new Map(), b = /* @__PURE__ */ new Map(), P = /* @__PURE__ */ new Map(), D = /* @__PURE__ */ new Map();
79
+ for (const e of I) {
80
+ if (e.op === "connection_request" && e.connection_request_id) {
81
+ c.set(e.connection_request_id, e);
82
+ const t = this.hcsClient.standardClient.extractAccountFromOperatorId(
83
+ e.operator_id || ""
84
+ );
85
+ t && u.add(t);
86
+ }
87
+ if (e.op === "connection_created" && e.connection_request_id) {
88
+ b.set(e.connection_request_id, e);
89
+ const t = this.hcsClient.standardClient.extractAccountFromOperatorId(
90
+ e.operator_id || ""
91
+ );
92
+ t && u.add(t);
93
+ }
94
+ }
95
+ for (const e of p) {
96
+ if (e.op === "connection_request" && e.sequence_number) {
97
+ P.set(e.sequence_number, e);
98
+ const t = this.hcsClient.standardClient.extractAccountFromOperatorId(
99
+ e.operator_id || ""
100
+ );
101
+ t && u.add(t);
102
+ }
103
+ e.op === "connection_created" && e.connection_id && (D.set(e.connection_id, e), e.connected_account_id && u.add(e.connected_account_id));
104
+ }
105
+ const E = Array.from(u).map(
106
+ async (e) => {
107
+ try {
108
+ const t = await this.hcsClient.getAgentProfile(
109
+ e
110
+ );
111
+ t.success && t.profile && g.set(e, t.profile);
112
+ } catch {
113
+ }
114
+ }
115
+ );
116
+ await Promise.allSettled(E);
117
+ const T = (e) => {
118
+ if (!e)
119
+ return;
120
+ const t = g.get(e);
121
+ if (t)
122
+ return {
123
+ name: t.display_name || t.alias,
124
+ bio: t.bio,
125
+ avatar: t.profileImage,
126
+ type: t.type,
127
+ account_id: t.account_id,
128
+ profile_image_uri: t.profile_image_uri
129
+ };
130
+ };
131
+ for (const [e, t] of Array.from(c.entries())) {
132
+ let s;
133
+ try {
134
+ t.payload && (s = JSON.parse(t.payload).target_account_id);
135
+ } catch {
136
+ }
137
+ (!s || typeof s != "string") && t.operator_id && (s = this.hcsClient.standardClient.extractAccountFromOperatorId(
138
+ t.operator_id
139
+ )), s && A.set(e, s);
140
+ }
141
+ for (const [e, t] of Array.from(c.entries())) {
142
+ const s = this.hcsClient.standardClient.extractAccountFromOperatorId(
143
+ t.operator_id || ""
144
+ ), r = T(s), C = (r == null ? void 0 : r.name) || `Agent ${s || "Unknown"}`, l = b.get(e);
145
+ if (l != null && l.connection_topic_id) {
146
+ const i = l.connection_topic_id, d = A.get(e), a = T(d), w = (a == null ? void 0 : a.name) || `Agent ${d || "Unknown Target"}`;
147
+ if (!n.has(i) || (S = n.get(i)) != null && S.isPending) {
148
+ const x = {
149
+ connectionTopicId: i,
150
+ targetAccountId: d || "unknown",
151
+ targetAgentName: w,
152
+ targetInboundTopicId: "",
153
+ status: "established",
154
+ isPending: !1,
155
+ needsConfirmation: !1,
156
+ created: new Date(l.created || /* @__PURE__ */ new Date()),
157
+ profileInfo: a,
158
+ connection_request_id: e,
159
+ confirmed_request_id: l.confirmed_request_id
160
+ };
161
+ l.outbound_topic_id && (x.requestor_outbound_topic_id = l.outbound_topic_id), n.set(i, x);
162
+ }
163
+ const q = `pending_${e}`;
164
+ n.has(q) && n.delete(q);
165
+ continue;
166
+ }
167
+ let _, f;
168
+ try {
169
+ if (t.payload && (f = JSON.parse(t.payload).target_account_id), (!f || typeof f != "string") && m && g.size === 2 && (f = Array.from(g.keys()).find(
170
+ (d) => d !== m
171
+ )), f) {
172
+ let i = g.get(f);
173
+ if (!i)
174
+ try {
175
+ const d = await this.hcsClient.getAgentProfile(
176
+ f
177
+ );
178
+ d.success && d.profile && (i = d.profile, g.set(f, i));
179
+ } catch {
180
+ }
181
+ i != null && i.inboundTopicId && (_ = i.inboundTopicId);
182
+ }
183
+ } catch {
184
+ }
185
+ let h;
186
+ const M = 3, F = 500;
187
+ if (_)
188
+ for (let i = 1; i <= M; i++)
189
+ try {
190
+ if (h = (await this.hcsClient.getMessages(
191
+ _
192
+ )).messages.find(
193
+ (w) => w.op === "connection_created" && w.connection_id === e
194
+ ), h)
195
+ break;
196
+ if (i === M)
197
+ break;
198
+ } catch {
199
+ if (i === M)
200
+ break;
201
+ await new Promise(
202
+ (a) => setTimeout(a, F)
203
+ );
204
+ }
205
+ if (h != null && h.connection_topic_id) {
206
+ const i = h.connection_topic_id, d = `pending_${e}`, a = T(
207
+ f
208
+ ), w = (a == null ? void 0 : a.name) || `Agent ${f || "Unknown"}`;
209
+ if (!n.has(i) || (k = n.get(i)) != null && k.isPending) {
210
+ const q = {
211
+ connectionTopicId: i,
212
+ targetAccountId: f || "unknown",
213
+ targetAgentName: w,
214
+ targetInboundTopicId: _ || "",
215
+ status: "established",
216
+ isPending: !1,
217
+ needsConfirmation: !1,
218
+ created: new Date(h.created || /* @__PURE__ */ new Date()),
219
+ profileInfo: a,
220
+ connection_request_id: e
221
+ };
222
+ n.set(i, q);
223
+ }
224
+ n.has(d) && n.delete(d);
225
+ } else {
226
+ const i = `pending_${e}`;
227
+ if (!Array.from(n.values()).some(
228
+ (a) => a.connection_request_id === e && a.status === "established"
229
+ ) && !n.has(i)) {
230
+ const a = {
231
+ connectionTopicId: i,
232
+ targetAccountId: s || "unknown",
233
+ targetAgentName: C,
234
+ targetInboundTopicId: "",
235
+ status: "pending",
236
+ isPending: !0,
237
+ needsConfirmation: !1,
238
+ created: new Date(t.created || /* @__PURE__ */ new Date()),
239
+ profileInfo: r,
240
+ connection_request_id: e
241
+ };
242
+ n.set(i, a);
243
+ }
244
+ }
245
+ }
246
+ for (const [e, t] of Array.from(P.entries())) {
247
+ const s = this.hcsClient.standardClient.extractAccountFromOperatorId(
248
+ t.operator_id || ""
249
+ ), r = T(s), C = (r == null ? void 0 : r.name) || `Agent ${s || "Unknown"}`, l = D.get(e);
250
+ if (l) {
251
+ const _ = l.connection_topic_id || "";
252
+ if (!n.has(_)) {
253
+ const f = {
254
+ connectionTopicId: _,
255
+ targetAccountId: s || "unknown",
256
+ targetAgentName: C,
257
+ targetInboundTopicId: "",
258
+ status: "established",
259
+ isPending: !1,
260
+ needsConfirmation: !1,
261
+ created: new Date(l.created || t.created || /* @__PURE__ */ new Date()),
262
+ profileInfo: r,
263
+ inbound_request_id: e
264
+ };
265
+ n.set(_, f);
266
+ }
267
+ } else {
268
+ const _ = `needsConfirm_${e}`;
269
+ if (!Array.from(n.values()).some(
270
+ (h) => h.targetAccountId === s && (h.status === "established" || h.isPending)
271
+ ) && !n.has(_)) {
272
+ const h = {
273
+ connectionTopicId: _,
274
+ targetAccountId: s || "unknown",
275
+ targetAgentName: C,
276
+ targetInboundTopicId: "",
277
+ status: "needs confirmation",
278
+ isPending: !1,
279
+ needsConfirmation: !0,
280
+ created: new Date(t.created || /* @__PURE__ */ new Date()),
281
+ profileInfo: r,
282
+ inbound_request_id: e
283
+ };
284
+ n.set(_, h);
285
+ }
286
+ }
287
+ }
288
+ const N = Array.from(n.values()).filter(
289
+ (e) => e.status === "established" && !e.isPending && !e.needsConfirmation
290
+ ).map(async (e) => {
291
+ var t;
292
+ try {
293
+ const s = await this.hcsClient.getMessages(
294
+ e.connectionTopicId
295
+ );
296
+ if (((t = s == null ? void 0 : s.messages) == null ? void 0 : t.length) > 0) {
297
+ const r = s.messages.filter((C) => C.created).sort(
298
+ (C, l) => new Date(l.created).getTime() - new Date(C.created).getTime()
299
+ )[0];
300
+ if (r != null && r.created) {
301
+ const C = n.get(e.connectionTopicId);
302
+ C && (C.lastActivity = new Date(r.created));
303
+ }
304
+ }
305
+ } catch {
306
+ }
307
+ });
308
+ await Promise.allSettled(N);
309
+ for (const e of Array.from(n.values()))
310
+ this.stateManager.updateOrAddConnection(e);
311
+ return this.stateManager.listConnections();
312
+ }
313
+ async fetchOutboundMessages() {
314
+ if (!this.hcsClient)
315
+ return [];
316
+ try {
317
+ const o = await this.hcsClient.getOutboundTopicId();
318
+ return o ? (await this.hcsClient.getMessages(o)).messages || [] : [];
319
+ } catch {
320
+ return [];
321
+ }
322
+ }
323
+ }
324
+ export {
325
+ H as ListConnectionsTool
326
+ };
327
+ //# sourceMappingURL=ListConnectionsTool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ListConnectionsTool.js","sources":["../../src/tools/ListConnectionsTool.ts"],"sourcesContent":["import { StructuredTool, ToolParams } from '@langchain/core/tools';\nimport { z } from 'zod';\nimport { IStateManager, ActiveConnection } from '../state/state-types';\nimport { HCS10Client } from '../hcs10/HCS10Client';\nimport { HCSMessage } from '@hashgraphonline/standards-sdk';\n\ninterface ExtendedConnection extends ActiveConnection {\n connection_request_id?: number;\n confirmed_request_id?: number;\n requestor_outbound_topic_id?: string;\n inbound_request_id?: number;\n}\n\nexport interface ListConnectionsToolParams extends ToolParams {\n stateManager: IStateManager;\n hcsClient?: HCS10Client;\n}\n\n/**\n * A tool to list currently active HCS-10 connections stored in the state manager.\n * Enhanced to show more details similar to moonscape's implementation.\n */\nexport class ListConnectionsTool extends StructuredTool {\n name = 'list_connections';\n description =\n 'Lists the currently active HCS-10 connections with detailed information. Shows connection status, agent details, and recent activity. Use this to get a comprehensive view of all active connections.';\n schema = z.object({\n includeDetails: z\n .boolean()\n .optional()\n .describe(\n 'Whether to include detailed information about each connection'\n ),\n showPending: z\n .boolean()\n .optional()\n .describe('Whether to include pending connection requests'),\n });\n\n private stateManager: IStateManager;\n private hcsClient?: HCS10Client;\n\n constructor({ stateManager, hcsClient, ...rest }: ListConnectionsToolParams) {\n super(rest);\n this.stateManager = stateManager;\n this.hcsClient = hcsClient;\n }\n\n protected async _call(args: z.infer<this['schema']>): Promise<string> {\n const includeDetails = args.includeDetails ?? true;\n const showPending = args.showPending ?? true;\n\n const initialConnectionsFromState = this.stateManager.listConnections();\n\n const finalStateConnections = await this.enhanceConnectionInfo(\n initialConnectionsFromState\n );\n\n if (finalStateConnections.length === 0) {\n return 'There are currently no active connections.';\n }\n\n const activeConnections = finalStateConnections.filter(\n (c) => !c.isPending && !c.needsConfirmation\n );\n\n const pendingConnections = finalStateConnections.filter((c) => c.isPending);\n\n const needsConfirmation = finalStateConnections.filter(\n (c) => c.needsConfirmation\n );\n\n let output = '';\n\n if (activeConnections.length > 0) {\n output += `🟢 Active Connections (${activeConnections.length}):\\n`;\n activeConnections.forEach((conn, index) => {\n output += this.formatConnection(conn, index, includeDetails);\n });\n output += '\\n';\n }\n\n if (showPending && needsConfirmation.length > 0) {\n output += `🟠 Connections Needing Confirmation (${needsConfirmation.length}):\\n`;\n needsConfirmation.forEach((conn, index) => {\n output += this.formatConnection(conn, index, includeDetails);\n });\n output += '\\n';\n }\n\n if (showPending && pendingConnections.length > 0) {\n output += `⚪ Pending Connection Requests (${pendingConnections.length}):\\n`;\n pendingConnections.forEach((conn, index) => {\n output += this.formatConnection(conn, index, includeDetails);\n });\n }\n\n return output.trim();\n }\n\n private formatConnection(\n conn: ActiveConnection,\n index: number,\n includeDetails: boolean\n ): string {\n let output = `${index + 1}. ${\n conn.profileInfo?.name || conn.targetAgentName || 'Unknown Agent'\n } (${conn.targetAccountId})\\n`;\n const displayTopicId = conn.isPending\n ? '(Pending Request)'\n : conn.connectionTopicId;\n output += ` Topic: ${displayTopicId}\\n`;\n let statusText = 'unknown';\n if (conn.isPending) {\n statusText = 'pending request (sent)';\n } else if (conn.needsConfirmation) {\n statusText = 'needs confirmation (received)';\n } else if (conn.status === 'established') {\n statusText = 'established';\n } else if (conn.status) {\n statusText = conn.status;\n }\n output += ` Status: ${statusText}\\n`;\n\n if (includeDetails) {\n if (conn.profileInfo?.bio) {\n output += ` Bio: ${conn.profileInfo.bio.substring(0, 100)}${\n conn.profileInfo.bio.length > 100 ? '...' : ''\n }\\n`;\n }\n\n if (conn.created) {\n const createdLabel = conn.isPending\n ? 'Request sent'\n : 'Connection established';\n output += ` ${createdLabel}: ${conn.created.toLocaleString()}\\n`;\n }\n\n if (conn.lastActivity) {\n output += ` Last activity: ${conn.lastActivity.toLocaleString()}\\n`;\n }\n }\n\n return output;\n }\n\n private async enhanceConnectionInfo(\n connections: ActiveConnection[]\n ): Promise<ActiveConnection[]> {\n const finalConnections = new Map<string, ExtendedConnection>();\n const profileMap = new Map<string, any>();\n const targetAccountIds = new Set<string>();\n const requestTargetMap = new Map<number, string>();\n const activeAccountId = this.hcsClient?.getAccountAndSigner().accountId;\n\n for (const conn of connections) {\n if (conn.targetAccountId) {\n targetAccountIds.add(conn.targetAccountId);\n }\n finalConnections.set(conn.connectionTopicId, {\n ...conn,\n status: 'established',\n isPending: false,\n needsConfirmation: false,\n });\n }\n\n if (!this.hcsClient) {\n return Array.from(finalConnections.values());\n }\n\n let outboundMessages: HCSMessage[] = [];\n let inboundMessagesResult: { messages: HCSMessage[] } = { messages: [] };\n\n try {\n [outboundMessages, inboundMessagesResult] = await Promise.all([\n this.fetchOutboundMessages(),\n this.hcsClient\n .getInboundTopicId()\n .then((id) => this.hcsClient!.getMessages(id))\n .catch((_err) => ({ messages: [] })),\n ]);\n } catch (e) {\n /* empty */\n }\n\n const inboundMessages = inboundMessagesResult.messages;\n\n const outboundRequestMap = new Map<number, HCSMessage>();\n const outboundConfirmationMap = new Map<number, HCSMessage>();\n const inboundRequestMap = new Map<number, HCSMessage>();\n const inboundConfirmationMap = new Map<number, HCSMessage>();\n\n for (const msg of outboundMessages) {\n if (msg.op === 'connection_request' && msg.connection_request_id) {\n outboundRequestMap.set(msg.connection_request_id, msg);\n const targetAcc =\n this.hcsClient.standardClient.extractAccountFromOperatorId(\n msg.operator_id || ''\n );\n if (targetAcc) {\n targetAccountIds.add(targetAcc);\n }\n }\n if (msg.op === 'connection_created' && msg.connection_request_id) {\n outboundConfirmationMap.set(msg.connection_request_id, msg);\n const targetAcc =\n this.hcsClient.standardClient.extractAccountFromOperatorId(\n msg.operator_id || ''\n );\n if (targetAcc) {\n targetAccountIds.add(targetAcc);\n }\n }\n }\n\n for (const msg of inboundMessages) {\n if (msg.op === 'connection_request' && msg.sequence_number) {\n inboundRequestMap.set(msg.sequence_number, msg);\n const requestorAcc =\n this.hcsClient.standardClient.extractAccountFromOperatorId(\n msg.operator_id || ''\n );\n if (requestorAcc) {\n targetAccountIds.add(requestorAcc);\n }\n }\n if (msg.op === 'connection_created' && msg.connection_id) {\n inboundConfirmationMap.set(msg.connection_id, msg);\n if (msg.connected_account_id) {\n targetAccountIds.add(msg.connected_account_id);\n }\n }\n }\n\n const profileFetchPromises = Array.from(targetAccountIds).map(\n async (accountId) => {\n try {\n const profileResult = await this.hcsClient!.getAgentProfile(\n accountId\n );\n if (profileResult.success && profileResult.profile) {\n profileMap.set(accountId, profileResult.profile);\n }\n } catch (e) {\n /* empty */\n }\n }\n );\n await Promise.allSettled(profileFetchPromises);\n\n const getProfileInfo = (accountId?: string) => {\n if (!accountId) {\n return undefined;\n }\n const profile = profileMap.get(accountId);\n if (!profile) {\n return undefined;\n }\n return {\n name: profile.display_name || profile.alias,\n bio: profile.bio,\n avatar: profile.profileImage,\n type: profile.type,\n account_id: profile.account_id,\n profile_image_uri: profile.profile_image_uri,\n };\n };\n\n for (const [reqId, request] of Array.from(outboundRequestMap.entries())) {\n let targetAccountIdForReq: string | undefined;\n try {\n if ((request as any).payload) {\n const payloadData = JSON.parse((request as any).payload);\n targetAccountIdForReq = payloadData.target_account_id;\n }\n } catch {\n /* empty */\n }\n\n if (!targetAccountIdForReq || typeof targetAccountIdForReq !== 'string') {\n if (request.operator_id) {\n targetAccountIdForReq =\n this.hcsClient.standardClient.extractAccountFromOperatorId(\n request.operator_id\n );\n }\n }\n\n if (targetAccountIdForReq) {\n requestTargetMap.set(reqId, targetAccountIdForReq);\n }\n }\n\n for (const [reqId, request] of Array.from(outboundRequestMap.entries())) {\n const originalSenderAccountId =\n this.hcsClient.standardClient.extractAccountFromOperatorId(\n request.operator_id || ''\n );\n const originalSenderProfileInfo = getProfileInfo(originalSenderAccountId);\n const originalSenderAgentName =\n originalSenderProfileInfo?.name ||\n `Agent ${originalSenderAccountId || 'Unknown'}`;\n\n const outboundConfirmation = outboundConfirmationMap.get(reqId);\n\n if (outboundConfirmation?.connection_topic_id) {\n const connectionTopicId = outboundConfirmation.connection_topic_id;\n const correctTargetAccountId = requestTargetMap.get(reqId);\n const correctTargetProfileInfo = getProfileInfo(correctTargetAccountId);\n const correctTargetAgentName =\n correctTargetProfileInfo?.name ||\n `Agent ${correctTargetAccountId || 'Unknown Target'}`;\n\n if (\n !finalConnections.has(connectionTopicId) ||\n finalConnections.get(connectionTopicId)?.isPending\n ) {\n const newConnection: ExtendedConnection = {\n connectionTopicId,\n targetAccountId: correctTargetAccountId || 'unknown',\n targetAgentName: correctTargetAgentName,\n targetInboundTopicId: '',\n status: 'established',\n isPending: false,\n needsConfirmation: false,\n created: new Date(outboundConfirmation.created || new Date()),\n profileInfo: correctTargetProfileInfo,\n connection_request_id: reqId,\n confirmed_request_id: outboundConfirmation.confirmed_request_id,\n };\n if (outboundConfirmation.outbound_topic_id) {\n newConnection.requestor_outbound_topic_id = outboundConfirmation.outbound_topic_id;\n }\n finalConnections.set(connectionTopicId, newConnection);\n }\n const pendingKey = `pending_${reqId}`;\n if (finalConnections.has(pendingKey)) {\n finalConnections.delete(pendingKey);\n }\n continue;\n }\n\n let correctTargetInboundTopicId: string | undefined = undefined;\n let identifiedTargetAccountId: string | undefined = undefined;\n\n try {\n if ((request as any).payload) {\n const payloadData = JSON.parse((request as any).payload);\n identifiedTargetAccountId = payloadData.target_account_id;\n }\n if (\n !identifiedTargetAccountId ||\n typeof identifiedTargetAccountId !== 'string'\n ) {\n if (activeAccountId && profileMap.size === 2) {\n const profileKeys = Array.from(profileMap.keys());\n identifiedTargetAccountId = profileKeys.find(\n (id) => id !== activeAccountId\n );\n }\n }\n if (identifiedTargetAccountId) {\n let targetProfile = profileMap.get(identifiedTargetAccountId);\n if (!targetProfile) {\n try {\n const profileResult = await this.hcsClient!.getAgentProfile(\n identifiedTargetAccountId\n );\n if (profileResult.success && profileResult.profile) {\n targetProfile = profileResult.profile;\n profileMap.set(identifiedTargetAccountId, targetProfile);\n }\n } catch (profileError) {\n /* empty */\n }\n }\n if (targetProfile?.inboundTopicId) {\n correctTargetInboundTopicId = targetProfile.inboundTopicId;\n }\n }\n } catch (error) {\n /* empty */\n }\n\n let targetConfirmation: HCSMessage | undefined = undefined;\n const MAX_FETCH_ATTEMPTS = 3;\n const FETCH_DELAY_MS = 500;\n\n if (correctTargetInboundTopicId) {\n for (let attempt = 1; attempt <= MAX_FETCH_ATTEMPTS; attempt++) {\n try {\n const targetMessagesResult = await this.hcsClient.getMessages(\n correctTargetInboundTopicId\n );\n const targetMessages = targetMessagesResult.messages;\n targetConfirmation = targetMessages.find(\n (msg) =>\n msg.op === 'connection_created' && msg.connection_id === reqId\n );\n if (targetConfirmation) {\n break;\n } else if (attempt === MAX_FETCH_ATTEMPTS) {\n break;\n }\n } catch (targetFetchError) {\n if (attempt === MAX_FETCH_ATTEMPTS) {\n break;\n } else {\n await new Promise((resolve) =>\n setTimeout(resolve, FETCH_DELAY_MS)\n );\n }\n }\n }\n }\n\n if (targetConfirmation?.connection_topic_id) {\n const connectionTopicId = targetConfirmation.connection_topic_id;\n const pendingKey = `pending_${reqId}`;\n const correctTargetProfileInfo = getProfileInfo(\n identifiedTargetAccountId\n );\n const correctTargetAgentName =\n correctTargetProfileInfo?.name ||\n `Agent ${identifiedTargetAccountId || 'Unknown'}`;\n\n if (\n !finalConnections.has(connectionTopicId) ||\n finalConnections.get(connectionTopicId)?.isPending\n ) {\n const newConnection: ExtendedConnection = {\n connectionTopicId,\n targetAccountId: identifiedTargetAccountId || 'unknown',\n targetAgentName: correctTargetAgentName,\n targetInboundTopicId: correctTargetInboundTopicId || '',\n status: 'established',\n isPending: false,\n needsConfirmation: false,\n created: new Date(targetConfirmation.created || new Date()),\n profileInfo: correctTargetProfileInfo,\n connection_request_id: reqId,\n };\n finalConnections.set(connectionTopicId, newConnection);\n }\n if (finalConnections.has(pendingKey)) {\n finalConnections.delete(pendingKey);\n }\n } else {\n const pendingKey = `pending_${reqId}`;\n const alreadyEstablished = Array.from(finalConnections.values()).some(\n (c) => {\n const extConn = c as ExtendedConnection;\n return extConn.connection_request_id === reqId && c.status === 'established';\n }\n );\n\n if (!alreadyEstablished && !finalConnections.has(pendingKey)) {\n const newConnection: ExtendedConnection = {\n connectionTopicId: pendingKey,\n targetAccountId: originalSenderAccountId || 'unknown',\n targetAgentName: originalSenderAgentName,\n targetInboundTopicId: '',\n status: 'pending',\n isPending: true,\n needsConfirmation: false,\n created: new Date(request.created || new Date()),\n profileInfo: originalSenderProfileInfo,\n connection_request_id: reqId,\n };\n finalConnections.set(pendingKey, newConnection);\n }\n }\n }\n\n for (const [reqSeqNum, request] of Array.from(inboundRequestMap.entries())) {\n const requestorAccountId =\n this.hcsClient.standardClient.extractAccountFromOperatorId(\n request.operator_id || ''\n );\n const profileInfo = getProfileInfo(requestorAccountId);\n const requestorAgentName =\n profileInfo?.name || `Agent ${requestorAccountId || 'Unknown'}`;\n\n const inboundConfirmation = inboundConfirmationMap.get(reqSeqNum);\n\n if (!inboundConfirmation) {\n const needsConfirmKey = `needsConfirm_${reqSeqNum}`;\n const alreadyExists = Array.from(finalConnections.values()).some(\n (c) =>\n c.targetAccountId === requestorAccountId &&\n (c.status === 'established' || c.isPending)\n );\n if (!alreadyExists && !finalConnections.has(needsConfirmKey)) {\n const newConnection: ExtendedConnection = {\n connectionTopicId: needsConfirmKey,\n targetAccountId: requestorAccountId || 'unknown',\n targetAgentName: requestorAgentName,\n targetInboundTopicId: '',\n status: 'needs confirmation',\n isPending: false,\n needsConfirmation: true,\n created: new Date(request.created || new Date()),\n profileInfo: profileInfo,\n inbound_request_id: reqSeqNum,\n };\n finalConnections.set(needsConfirmKey, newConnection);\n }\n } else {\n const confirmedTopicId = inboundConfirmation.connection_topic_id || '';\n if (!finalConnections.has(confirmedTopicId)) {\n const newConnection: ExtendedConnection = {\n connectionTopicId: confirmedTopicId,\n targetAccountId: requestorAccountId || 'unknown',\n targetAgentName: requestorAgentName,\n targetInboundTopicId: '',\n status: 'established',\n isPending: false,\n needsConfirmation: false,\n created: new Date(inboundConfirmation.created || request.created || new Date()),\n profileInfo: profileInfo,\n inbound_request_id: reqSeqNum,\n };\n finalConnections.set(confirmedTopicId, newConnection);\n }\n }\n }\n\n const activityFetchPromises = Array.from(finalConnections.values())\n .filter(\n (c) =>\n c.status === 'established' && !c.isPending && !c.needsConfirmation\n )\n .map(async (conn) => {\n try {\n const messagesResult = await this.hcsClient!.getMessages(\n conn.connectionTopicId\n );\n if (messagesResult?.messages?.length > 0) {\n const lastMessage = messagesResult.messages\n .filter((m) => m.created)\n .sort(\n (a, b) =>\n new Date(b.created!).getTime() -\n new Date(a.created!).getTime()\n )[0];\n if (lastMessage?.created) {\n const existingConn = finalConnections.get(conn.connectionTopicId);\n if (existingConn) {\n existingConn.lastActivity = new Date(lastMessage.created);\n }\n }\n }\n } catch (activityError) {\n /* empty */\n }\n });\n await Promise.allSettled(activityFetchPromises);\n\n for (const connection of Array.from(finalConnections.values())) {\n this.stateManager.updateOrAddConnection(connection);\n }\n\n const updatedStateConnections = this.stateManager.listConnections();\n return updatedStateConnections;\n }\n\n private async fetchOutboundMessages(): Promise<HCSMessage[]> {\n if (!this.hcsClient) {\n return [];\n }\n\n try {\n const outboundTopicId = await this.hcsClient.getOutboundTopicId();\n if (!outboundTopicId) {\n return [];\n }\n const result = await this.hcsClient.getMessages(outboundTopicId);\n return result.messages || [];\n } catch (e) {\n return [];\n }\n }\n}\n"],"names":["ListConnectionsTool","StructuredTool","stateManager","hcsClient","rest","z","args","includeDetails","showPending","initialConnectionsFromState","finalStateConnections","activeConnections","pendingConnections","needsConfirmation","output","conn","index","_a","displayTopicId","statusText","_b","createdLabel","connections","finalConnections","profileMap","targetAccountIds","requestTargetMap","activeAccountId","outboundMessages","inboundMessagesResult","id","_err","inboundMessages","outboundRequestMap","outboundConfirmationMap","inboundRequestMap","inboundConfirmationMap","msg","targetAcc","requestorAcc","profileFetchPromises","accountId","profileResult","getProfileInfo","profile","reqId","request","targetAccountIdForReq","originalSenderAccountId","originalSenderProfileInfo","originalSenderAgentName","outboundConfirmation","connectionTopicId","correctTargetAccountId","correctTargetProfileInfo","correctTargetAgentName","newConnection","pendingKey","correctTargetInboundTopicId","identifiedTargetAccountId","targetProfile","targetConfirmation","MAX_FETCH_ATTEMPTS","FETCH_DELAY_MS","attempt","resolve","_c","c","reqSeqNum","requestorAccountId","profileInfo","requestorAgentName","inboundConfirmation","confirmedTopicId","needsConfirmKey","activityFetchPromises","messagesResult","lastMessage","m","a","b","existingConn","connection","outboundTopicId"],"mappings":";;AAsBO,MAAMA,UAA4BC,EAAe;AAAA,EAoBtD,YAAY,EAAE,cAAAC,GAAc,WAAAC,GAAW,GAAGC,KAAmC;AAC3E,UAAMA,CAAI,GApBL,KAAA,OAAA,oBAEL,KAAA,cAAA,yMACF,KAAA,SAASC,EAAE,OAAO;AAAA,MAChB,gBAAgBA,EACb,UACA,SACA,EAAA;AAAA,QACC;AAAA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,MACCA,EAAE,WAAW,iBAAiB,CAACA,EAAE,aAAa,CAACA,EAAE;AAAA,IAAA,EAEpD,IAAI,OAAOpD,MAAS;;AACf,UAAA;AACI,cAAA6D,IAAiB,MAAM,KAAK,UAAW;AAAA,UAC3C7D,EAAK;AAAA,QACP;AACI,cAAAE,IAAA2D,KAAA,gBAAAA,EAAgB,aAAhB,gBAAA3D,EAA0B,UAAS,GAAG;AAClC,gBAAA4D,IAAcD,EAAe,SAChC,OAAO,CAACE,MAAMA,EAAE,OAAO,EACvB;AAAA,YACC,CAACC,GAAGC,MACF,IAAI,KAAKA,EAAE,OAAQ,EAAE,QAAA,IACrB,IAAI,KAAKD,EAAE,OAAQ,EAAE,QAAQ;AAAA,YAC/B,CAAC;AACL,cAAIF,KAAA,QAAAA,EAAa,SAAS;AACxB,kBAAMI,IAAe1D,EAAiB,IAAIR,EAAK,iBAAiB;AAChE,YAAIkE,MACFA,EAAa,eAAe,IAAI,KAAKJ,EAAY,OAAO;AAAA,UAC1D;AAAA,QACF;AAAA,cAEoB;AAAA,MAAA;AAAA,IAExB,CACD;AACG,UAAA,QAAQ,WAAWF,CAAqB;AAE9C,eAAWO,KAAc,MAAM,KAAK3D,EAAiB,OAAA,CAAQ;AACtD,WAAA,aAAa,sBAAsB2D,CAAU;AAI7C,WADyB,KAAK,aAAa,gBAAgB;AAAA,EAC3D;AAAA,EAGT,MAAc,wBAA+C;AACvD,QAAA,CAAC,KAAK;AACR,aAAO,CAAC;AAGN,QAAA;AACF,YAAMC,IAAkB,MAAM,KAAK,UAAU,mBAAmB;AAChE,aAAKA,KAGU,MAAM,KAAK,UAAU,YAAYA,CAAe,GACjD,YAAY,CAAC,IAHlB,CAAC;AAAA,YAIA;AACV,aAAO,CAAC;AAAA,IAAA;AAAA,EACV;AAEJ;"}
@@ -0,0 +1,53 @@
1
+ import { StructuredTool, ToolParams } from '@langchain/core/tools';
2
+ import { z } from 'zod';
3
+ import { IStateManager } from '../state/state-types';
4
+ import { HCS10Client } from '../hcs10/HCS10Client';
5
+ type ListPendingRequestsToolParams = ToolParams & {
6
+ hcsClient: HCS10Client;
7
+ stateManager: IStateManager;
8
+ };
9
+ export declare class ListUnapprovedConnectionRequestsTool extends StructuredTool {
10
+ name: string;
11
+ description: string;
12
+ schema: z.ZodObject<{
13
+ sortBy: z.ZodOptional<z.ZodEnum<["time_asc", "time_desc", "name_asc", "name_desc"]>>;
14
+ limit: z.ZodOptional<z.ZodNumber>;
15
+ }, "strip", z.ZodTypeAny, {
16
+ sortBy?: "time_asc" | "time_desc" | "name_asc" | "name_desc" | undefined;
17
+ limit?: number | undefined;
18
+ }, {
19
+ sortBy?: "time_asc" | "time_desc" | "name_asc" | "name_desc" | undefined;
20
+ limit?: number | undefined;
21
+ }>;
22
+ private hcsClient;
23
+ private stateManager;
24
+ private logger;
25
+ constructor({ hcsClient, stateManager, ...rest }: ListPendingRequestsToolParams);
26
+ protected _call({ sortBy, limit, }: z.infer<this['schema']>): Promise<string>;
27
+ /**
28
+ * Processes the connection connectionMap to find all requests
29
+ * that are not fully established (incoming unapproved and outgoing pending).
30
+ */
31
+ private findAllPendingRequests;
32
+ /**
33
+ * Helper to attempt extracting target account ID from outbound request message.
34
+ */
35
+ private extractTargetAccountIdFromOutbound;
36
+ /**
37
+ * Maps HCS11Profile to the AgentProfileInfo used in state/display.
38
+ */
39
+ private mapSDKProfileToInfo;
40
+ /**
41
+ * Extracts the account ID from relevant fields in an HCSMessage.
42
+ */
43
+ private extractAccountIdFromMessage;
44
+ /**
45
+ * Formats the list of pending requests for display.
46
+ */
47
+ private formatRequestsList;
48
+ /**
49
+ * Sorts connection requests based on the specified criteria.
50
+ */
51
+ private sortRequests;
52
+ }
53
+ export {};
@@ -0,0 +1,177 @@
1
+ import { StructuredTool as g } from "../node_modules/@langchain/core/dist/tools.js";
2
+ import { z as l } from "zod";
3
+ import { Logger as f } from "@hashgraphonline/standards-sdk";
4
+ import { fetchConnectionMap as p } from "../utils/connectionUtils.js";
5
+ class I extends g {
6
+ constructor({
7
+ hcsClient: e,
8
+ stateManager: r,
9
+ ...o
10
+ }) {
11
+ super(o), this.name = "list_unapproved_connection_requests", this.description = "Lists all connection requests that are not fully established, including incoming requests needing approval and outgoing requests waiting for confirmation.", this.schema = l.object({
12
+ sortBy: l.enum(["time_asc", "time_desc", "name_asc", "name_desc"]).optional().describe(
13
+ "Optional sorting criteria for the requests list (default: time_desc, newest first)"
14
+ ),
15
+ limit: l.number().optional().describe(
16
+ "Optional limit on the number of requests to return (default: all)"
17
+ )
18
+ }), this.hcsClient = e, this.stateManager = r, this.logger = f.getInstance({
19
+ module: "ListPendingRequestsTool",
20
+ level: "debug"
21
+ });
22
+ }
23
+ async _call({
24
+ sortBy: e = "time_desc",
25
+ limit: r
26
+ }) {
27
+ if (!this.stateManager.getCurrentAgent())
28
+ return "Error: Cannot list pending requests. No agent is currently active. Please register or select an agent first.";
29
+ try {
30
+ const t = await p(this.hcsClient), n = this.findAllPendingRequests(t);
31
+ return this.formatRequestsList(n, e, r);
32
+ } catch (t) {
33
+ return this.logger.error(`Error in ${this.name}: ${t}`), `Error listing pending requests: ${t instanceof Error ? t.message : String(t)}`;
34
+ }
35
+ }
36
+ /**
37
+ * Processes the connection connectionMap to find all requests
38
+ * that are not fully established (incoming unapproved and outgoing pending).
39
+ */
40
+ findAllPendingRequests(e) {
41
+ const r = [];
42
+ for (const [o, t] of Array.from(
43
+ e.inboundRequests.entries()
44
+ )) {
45
+ if (e.confirmedRequestIds.has(o))
46
+ continue;
47
+ const n = this.extractAccountIdFromMessage(t);
48
+ if (!n || Array.from(
49
+ e.inboundConfirmations.values()
50
+ ).some((a) => a.connection_id === o) || this.stateManager.listConnections().some(
51
+ (a) => a.targetAccountId === n && a.status === "established" && !a.isPending && !a.needsConfirmation
52
+ ))
53
+ continue;
54
+ const u = e.profileMap.get(n), c = u ? this.mapSDKProfileToInfo(u) : void 0;
55
+ r.push({
56
+ id: o,
57
+ requestorId: n,
58
+ requestorName: (c == null ? void 0 : c.name) || `Agent ${n}`,
59
+ timestamp: new Date(t.created || Date.now()),
60
+ memo: t.m || "",
61
+ profile: c,
62
+ status: "needs_confirmation"
63
+ });
64
+ }
65
+ for (const [o, t] of Array.from(
66
+ e.outboundRequests.entries()
67
+ )) {
68
+ const n = e.inboundConfirmations.has(o), i = e.outboundConfirmations.has(o);
69
+ if (n || i)
70
+ continue;
71
+ const s = this.extractTargetAccountIdFromOutbound(t);
72
+ if (!s) {
73
+ this.logger.warn(
74
+ `Could not determine target account for outbound request ${o}`
75
+ );
76
+ continue;
77
+ }
78
+ if (this.stateManager.listConnections().some(
79
+ (d) => d.targetAccountId === s && d.status === "established" && !d.isPending && !d.needsConfirmation
80
+ ))
81
+ continue;
82
+ const c = e.profileMap.get(s), a = c ? this.mapSDKProfileToInfo(c) : void 0;
83
+ r.push({
84
+ id: o,
85
+ requestorId: s,
86
+ requestorName: (a == null ? void 0 : a.name) || `Agent ${s}`,
87
+ timestamp: new Date(t.created || Date.now()),
88
+ memo: t.m || "",
89
+ profile: a,
90
+ status: "pending_outbound"
91
+ });
92
+ }
93
+ return r;
94
+ }
95
+ /**
96
+ * Helper to attempt extracting target account ID from outbound request message.
97
+ */
98
+ extractTargetAccountIdFromOutbound(e) {
99
+ if (e.operator_id)
100
+ return this.hcsClient.standardClient.extractAccountFromOperatorId(
101
+ e.operator_id
102
+ );
103
+ }
104
+ /**
105
+ * Maps HCS11Profile to the AgentProfileInfo used in state/display.
106
+ */
107
+ mapSDKProfileToInfo(e) {
108
+ return {
109
+ name: e.display_name || e.alias,
110
+ bio: e.bio,
111
+ avatar: e.profileImage,
112
+ type: e.type === 1 ? "AI Agent" : "Personal"
113
+ };
114
+ }
115
+ /**
116
+ * Extracts the account ID from relevant fields in an HCSMessage.
117
+ */
118
+ extractAccountIdFromMessage(e) {
119
+ return e.operator_id ? this.hcsClient.standardClient.extractAccountFromOperatorId(
120
+ e.operator_id
121
+ ) : e.connected_account_id || void 0;
122
+ }
123
+ /**
124
+ * Formats the list of pending requests for display.
125
+ */
126
+ formatRequestsList(e, r, o) {
127
+ if (e.length === 0)
128
+ return "No pending connection requests found (incoming or outgoing).";
129
+ const t = this.sortRequests(e, r), n = o ? t.slice(0, o) : t;
130
+ let i = `Found ${e.length} pending connection request(s):
131
+
132
+ `;
133
+ return n.forEach((s, m) => {
134
+ var c;
135
+ const u = s.status === "needs_confirmation" ? "🟠 Incoming" : "⚪️ Outgoing";
136
+ i += `${m + 1}. ${u} - ID: ${s.id}
137
+ `, i += ` ${s.status === "needs_confirmation" ? "From:" : "To: "} ${s.requestorName} (${s.requestorId})
138
+ `, i += ` Sent/Rcvd: ${s.timestamp.toLocaleString()}
139
+ `, s.memo && (i += ` Memo: ${s.memo}
140
+ `), (c = s.profile) != null && c.bio && (i += ` Bio: ${s.profile.bio.substring(0, 100)}${s.profile.bio.length > 100 ? "..." : ""}
141
+ `), i += `
142
+ `;
143
+ }), i += "Use related tools (manage_requests, accept_request) to handle these items.", i;
144
+ }
145
+ /**
146
+ * Sorts connection requests based on the specified criteria.
147
+ */
148
+ sortRequests(e, r) {
149
+ const o = [...e];
150
+ switch (r) {
151
+ case "time_asc":
152
+ return o.sort(
153
+ (t, n) => t.timestamp.getTime() - n.timestamp.getTime()
154
+ );
155
+ case "time_desc":
156
+ return o.sort(
157
+ (t, n) => n.timestamp.getTime() - t.timestamp.getTime()
158
+ );
159
+ case "name_asc":
160
+ return o.sort(
161
+ (t, n) => t.requestorName.localeCompare(n.requestorName)
162
+ );
163
+ case "name_desc":
164
+ return o.sort(
165
+ (t, n) => n.requestorName.localeCompare(t.requestorName)
166
+ );
167
+ default:
168
+ return o.sort(
169
+ (t, n) => n.timestamp.getTime() - t.timestamp.getTime()
170
+ );
171
+ }
172
+ }
173
+ }
174
+ export {
175
+ I as ListUnapprovedConnectionRequestsTool
176
+ };
177
+ //# sourceMappingURL=ListUnapprovedConnectionRequestsTool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ListUnapprovedConnectionRequestsTool.js","sources":["../../src/tools/ListUnapprovedConnectionRequestsTool.ts"],"sourcesContent":["import { StructuredTool, ToolParams } from '@langchain/core/tools';\nimport { z } from 'zod';\nimport {\n IStateManager,\n ConnectionRequestInfo,\n AgentProfileInfo,\n} from '../state/state-types';\nimport { HCS10Client } from '../hcs10/HCS10Client';\nimport {\n Logger,\n HCSMessage,\n HCS11Profile,\n} from '@hashgraphonline/standards-sdk';\nimport { fetchConnectionMap, ConnectionMap } from '../utils/connectionUtils';\n\ninterface PendingRequest extends ConnectionRequestInfo {\n status: 'needs_confirmation' | 'pending_outbound';\n}\n\ntype ListPendingRequestsToolParams = ToolParams & {\n hcsClient: HCS10Client;\n stateManager: IStateManager;\n};\n\nexport class ListUnapprovedConnectionRequestsTool extends StructuredTool {\n name = 'list_unapproved_connection_requests';\n description =\n 'Lists all connection requests that are not fully established, including incoming requests needing approval and outgoing requests waiting for confirmation.';\n schema = z.object({\n sortBy: z\n .enum(['time_asc', 'time_desc', 'name_asc', 'name_desc'])\n .optional()\n .describe(\n 'Optional sorting criteria for the requests list (default: time_desc, newest first)'\n ),\n limit: z\n .number()\n .optional()\n .describe(\n 'Optional limit on the number of requests to return (default: all)'\n ),\n });\n\n private hcsClient: HCS10Client;\n private stateManager: IStateManager;\n private logger: Logger;\n\n constructor({\n hcsClient,\n stateManager,\n ...rest\n }: ListPendingRequestsToolParams) {\n super(rest);\n this.hcsClient = hcsClient;\n this.stateManager = stateManager;\n this.logger = Logger.getInstance({\n module: 'ListPendingRequestsTool',\n level: 'debug',\n });\n }\n\n protected async _call({\n sortBy = 'time_desc',\n limit,\n }: z.infer<this['schema']>): Promise<string> {\n const currentAgent = this.stateManager.getCurrentAgent();\n if (!currentAgent) {\n return 'Error: Cannot list pending requests. No agent is currently active. Please register or select an agent first.';\n }\n\n try {\n const connectionMap = await fetchConnectionMap(this.hcsClient);\n const pendingRequests = this.findAllPendingRequests(connectionMap);\n return this.formatRequestsList(pendingRequests, sortBy, limit);\n } catch (error) {\n this.logger.error(`Error in ${this.name}: ${error}`);\n return `Error listing pending requests: ${\n error instanceof Error ? error.message : String(error)\n }`;\n }\n }\n\n /**\n * Processes the connection connectionMap to find all requests\n * that are not fully established (incoming unapproved and outgoing pending).\n */\n private findAllPendingRequests(\n connectionMap: ConnectionMap\n ): PendingRequest[] {\n const pending: PendingRequest[] = [];\n\n for (const [reqSeqNum, request] of Array.from(\n connectionMap.inboundRequests.entries()\n )) {\n if (connectionMap.confirmedRequestIds.has(reqSeqNum)) {\n continue;\n }\n\n const requestorAccountId = this.extractAccountIdFromMessage(request);\n if (!requestorAccountId) {\n continue;\n }\n\n const alreadyEstablishedInbound = Array.from(\n connectionMap.inboundConfirmations.values()\n ).some((conf) => conf.connection_id === reqSeqNum);\n if (alreadyEstablishedInbound) {\n continue;\n }\n\n const existingConnections = this.stateManager.listConnections();\n const alreadyConnectedState = existingConnections.some(\n (conn) =>\n conn.targetAccountId === requestorAccountId &&\n conn.status === 'established' &&\n !conn.isPending &&\n !conn.needsConfirmation\n );\n if (alreadyConnectedState) {\n continue;\n }\n\n const profile = connectionMap.profileMap.get(requestorAccountId);\n const profileInfo = profile\n ? this.mapSDKProfileToInfo(profile)\n : undefined;\n\n pending.push({\n id: reqSeqNum,\n requestorId: requestorAccountId,\n requestorName: profileInfo?.name || `Agent ${requestorAccountId}`,\n timestamp: new Date(request.created || Date.now()),\n memo: request.m || '',\n profile: profileInfo,\n status: 'needs_confirmation',\n });\n }\n\n for (const [reqSeqNum, request] of Array.from(\n connectionMap.outboundRequests.entries()\n )) {\n const confirmedInbound =\n connectionMap.inboundConfirmations.has(reqSeqNum);\n const confirmedOutbound =\n connectionMap.outboundConfirmations.has(reqSeqNum);\n\n if (confirmedInbound || confirmedOutbound) {\n continue;\n }\n\n const targetAccountId = this.extractTargetAccountIdFromOutbound(request);\n if (!targetAccountId) {\n this.logger.warn(\n `Could not determine target account for outbound request ${reqSeqNum}`\n );\n continue;\n }\n\n const existingConnections = this.stateManager.listConnections();\n const alreadyConnectedState = existingConnections.some(\n (conn) =>\n conn.targetAccountId === targetAccountId &&\n conn.status === 'established' &&\n !conn.isPending &&\n !conn.needsConfirmation\n );\n if (alreadyConnectedState) {\n continue;\n }\n\n const profile = connectionMap.profileMap.get(targetAccountId);\n const profileInfo = profile\n ? this.mapSDKProfileToInfo(profile)\n : undefined;\n\n pending.push({\n id: reqSeqNum,\n requestorId: targetAccountId,\n requestorName: profileInfo?.name || `Agent ${targetAccountId}`,\n timestamp: new Date(request.created || Date.now()),\n memo: request.m || '',\n profile: profileInfo,\n status: 'pending_outbound',\n });\n }\n\n return pending;\n }\n\n /**\n * Helper to attempt extracting target account ID from outbound request message.\n */\n private extractTargetAccountIdFromOutbound(\n message: HCSMessage\n ): string | undefined {\n if (!message.operator_id) {\n return undefined;\n }\n return this.hcsClient.standardClient.extractAccountFromOperatorId(\n message.operator_id\n );\n }\n\n /**\n * Maps HCS11Profile to the AgentProfileInfo used in state/display.\n */\n private mapSDKProfileToInfo(profile: HCS11Profile): AgentProfileInfo {\n return {\n name: profile.display_name || profile.alias,\n bio: profile.bio,\n avatar: profile.profileImage,\n type: profile.type === 1 ? 'AI Agent' : 'Personal',\n };\n }\n\n /**\n * Extracts the account ID from relevant fields in an HCSMessage.\n */\n private extractAccountIdFromMessage(message: HCSMessage): string | undefined {\n if (message.operator_id) {\n return this.hcsClient.standardClient.extractAccountFromOperatorId(\n message.operator_id\n );\n }\n return message.connected_account_id || undefined;\n }\n\n /**\n * Formats the list of pending requests for display.\n */\n private formatRequestsList(\n requests: PendingRequest[],\n sortBy: string,\n limit?: number\n ): string {\n if (requests.length === 0) {\n return 'No pending connection requests found (incoming or outgoing).';\n }\n\n const sortedRequests = this.sortRequests(requests, sortBy);\n const limitedRequests = limit\n ? sortedRequests.slice(0, limit)\n : sortedRequests;\n\n let output = `Found ${requests.length} pending connection request(s):\\n\\n`;\n\n limitedRequests.forEach((request, index) => {\n const statusIndicator =\n request.status === 'needs_confirmation'\n ? '🟠 Incoming'\n : '⚪️ Outgoing';\n output += `${index + 1}. ${statusIndicator} - ID: ${request.id}\\n`;\n output += ` ${\n request.status === 'needs_confirmation' ? 'From:' : 'To: '\n } ${request.requestorName} (${request.requestorId})\\n`;\n output += ` Sent/Rcvd: ${request.timestamp.toLocaleString()}\\n`;\n if (request.memo) {\n output += ` Memo: ${request.memo}\\n`;\n }\n if (request.profile?.bio) {\n output += ` Bio: ${request.profile.bio.substring(0, 100)}${\n request.profile.bio.length > 100 ? '...' : ''\n }\\n`;\n }\n output += '\\n';\n });\n\n output +=\n 'Use related tools (manage_requests, accept_request) to handle these items.';\n return output;\n }\n\n /**\n * Sorts connection requests based on the specified criteria.\n */\n private sortRequests(\n requests: PendingRequest[],\n sortBy: string\n ): PendingRequest[] {\n const requestsCopy = [...requests];\n\n switch (sortBy) {\n case 'time_asc':\n return requestsCopy.sort(\n (a, b) => a.timestamp.getTime() - b.timestamp.getTime()\n );\n case 'time_desc':\n return requestsCopy.sort(\n (a, b) => b.timestamp.getTime() - a.timestamp.getTime()\n );\n case 'name_asc':\n return requestsCopy.sort((a, b) =>\n a.requestorName.localeCompare(b.requestorName)\n );\n case 'name_desc':\n return requestsCopy.sort((a, b) =>\n b.requestorName.localeCompare(a.requestorName)\n );\n default:\n return requestsCopy.sort(\n (a, b) => b.timestamp.getTime() - a.timestamp.getTime()\n );\n }\n }\n}\n"],"names":["ListUnapprovedConnectionRequestsTool","StructuredTool","hcsClient","stateManager","rest","z","Logger","sortBy","limit","connectionMap","fetchConnectionMap","pendingRequests","error","pending","reqSeqNum","request","requestorAccountId","conf","conn","profile","profileInfo","confirmedInbound","confirmedOutbound","targetAccountId","message","requests","sortedRequests","limitedRequests","output","index","statusIndicator","_a","requestsCopy","a","b"],"mappings":";;;;AAwBO,MAAMA,UAA6CC,EAAe;AAAA,EAuBvE,YAAY;AAAA,IACV,WAAAC;AAAA,IACA,cAAAC;AAAA,IACA,GAAGC;AAAA,EAAA,GAC6B;AAChC,UAAMA,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