@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.
- package/README.md +83 -0
- package/dist/_virtual/_commonjsHelpers.js +7 -0
- package/dist/_virtual/_commonjsHelpers.js.map +1 -0
- package/dist/_virtual/index.js +8 -0
- package/dist/_virtual/index.js.map +1 -0
- package/dist/_virtual/index10.js +5 -0
- package/dist/_virtual/index10.js.map +1 -0
- package/dist/_virtual/index11.js +5 -0
- package/dist/_virtual/index11.js.map +1 -0
- package/dist/_virtual/index12.js +8 -0
- package/dist/_virtual/index12.js.map +1 -0
- package/dist/_virtual/index13.js +5 -0
- package/dist/_virtual/index13.js.map +1 -0
- package/dist/_virtual/index14.js +5 -0
- package/dist/_virtual/index14.js.map +1 -0
- package/dist/_virtual/index2.js +3 -0
- package/dist/_virtual/index2.js.map +1 -0
- package/dist/_virtual/index3.js +8 -0
- package/dist/_virtual/index3.js.map +1 -0
- package/dist/_virtual/index4.js +8 -0
- package/dist/_virtual/index4.js.map +1 -0
- package/dist/_virtual/index5.js +6 -0
- package/dist/_virtual/index5.js.map +1 -0
- package/dist/_virtual/index6.js +8 -0
- package/dist/_virtual/index6.js.map +1 -0
- package/dist/_virtual/index7.js +5 -0
- package/dist/_virtual/index7.js.map +1 -0
- package/dist/_virtual/index8.js +5 -0
- package/dist/_virtual/index8.js.map +1 -0
- package/dist/_virtual/index9.js +5 -0
- package/dist/_virtual/index9.js.map +1 -0
- package/dist/_virtual/lower-bound.js +5 -0
- package/dist/_virtual/lower-bound.js.map +1 -0
- package/dist/_virtual/priority-queue.js +5 -0
- package/dist/_virtual/priority-queue.js.map +1 -0
- package/dist/_virtual/re.js +5 -0
- package/dist/_virtual/re.js.map +1 -0
- package/dist/_virtual/retry.js +5 -0
- package/dist/_virtual/retry.js.map +1 -0
- package/dist/agents/index.d.ts +0 -0
- package/dist/hcs10/HCS10Client.d.ts +117 -0
- package/dist/hcs10/HCS10Client.js +251 -0
- package/dist/hcs10/HCS10Client.js.map +1 -0
- package/dist/hcs10/index.d.ts +1 -0
- package/dist/hcs10/types.d.ts +35 -0
- package/dist/index.d.ts +5 -2
- package/dist/index.es.js +9747 -11699
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +44 -0
- package/dist/index.js.map +1 -0
- package/dist/init.d.ts +59 -0
- package/dist/init.js +92 -0
- package/dist/init.js.map +1 -0
- package/dist/node_modules/@langchain/core/dist/callbacks/base.js +98 -0
- package/dist/node_modules/@langchain/core/dist/callbacks/base.js.map +1 -0
- package/dist/node_modules/@langchain/core/dist/callbacks/manager.js +419 -0
- package/dist/node_modules/@langchain/core/dist/callbacks/manager.js.map +1 -0
- package/dist/node_modules/@langchain/core/dist/callbacks/promises.js +16 -0
- package/dist/node_modules/@langchain/core/dist/callbacks/promises.js.map +1 -0
- package/dist/node_modules/@langchain/core/dist/language_models/base.js +42 -0
- package/dist/node_modules/@langchain/core/dist/language_models/base.js.map +1 -0
- package/dist/node_modules/@langchain/core/dist/load/map_keys.js +16 -0
- package/dist/node_modules/@langchain/core/dist/load/map_keys.js.map +1 -0
- package/dist/node_modules/@langchain/core/dist/load/serializable.js +121 -0
- package/dist/node_modules/@langchain/core/dist/load/serializable.js.map +1 -0
- package/dist/node_modules/@langchain/core/dist/messages/ai.js +95 -0
- package/dist/node_modules/@langchain/core/dist/messages/ai.js.map +1 -0
- package/dist/node_modules/@langchain/core/dist/messages/base.js +112 -0
- package/dist/node_modules/@langchain/core/dist/messages/base.js.map +1 -0
- package/dist/node_modules/@langchain/core/dist/messages/utils.js +30 -0
- package/dist/node_modules/@langchain/core/dist/messages/utils.js.map +1 -0
- package/dist/node_modules/@langchain/core/dist/runnables/base.js +1277 -0
- package/dist/node_modules/@langchain/core/dist/runnables/base.js.map +1 -0
- package/dist/node_modules/@langchain/core/dist/runnables/config.js +83 -0
- package/dist/node_modules/@langchain/core/dist/runnables/config.js.map +1 -0
- package/dist/node_modules/@langchain/core/dist/runnables/graph.js +106 -0
- package/dist/node_modules/@langchain/core/dist/runnables/graph.js.map +1 -0
- package/dist/node_modules/@langchain/core/dist/runnables/iter.js +33 -0
- package/dist/node_modules/@langchain/core/dist/runnables/iter.js.map +1 -0
- package/dist/node_modules/@langchain/core/dist/runnables/utils.js +54 -0
- package/dist/node_modules/@langchain/core/dist/runnables/utils.js.map +1 -0
- package/dist/node_modules/@langchain/core/dist/runnables/wrappers.js +20 -0
- package/dist/node_modules/@langchain/core/dist/runnables/wrappers.js.map +1 -0
- package/dist/node_modules/@langchain/core/dist/singletons/index.js +34 -0
- package/dist/node_modules/@langchain/core/dist/singletons/index.js.map +1 -0
- package/dist/node_modules/@langchain/core/dist/tools.js +69 -0
- package/dist/node_modules/@langchain/core/dist/tools.js.map +1 -0
- package/dist/node_modules/@langchain/core/dist/tracers/base.js +299 -0
- package/dist/node_modules/@langchain/core/dist/tracers/base.js.map +1 -0
- package/dist/node_modules/@langchain/core/dist/tracers/console.js +193 -0
- package/dist/node_modules/@langchain/core/dist/tracers/console.js.map +1 -0
- package/dist/node_modules/@langchain/core/dist/tracers/initialize.js +10 -0
- package/dist/node_modules/@langchain/core/dist/tracers/initialize.js.map +1 -0
- package/dist/node_modules/@langchain/core/dist/tracers/log_stream.js +284 -0
- package/dist/node_modules/@langchain/core/dist/tracers/log_stream.js.map +1 -0
- package/dist/node_modules/@langchain/core/dist/tracers/root_listener.js +54 -0
- package/dist/node_modules/@langchain/core/dist/tracers/root_listener.js.map +1 -0
- package/dist/node_modules/@langchain/core/dist/tracers/tracer_langchain.js +68 -0
- package/dist/node_modules/@langchain/core/dist/tracers/tracer_langchain.js.map +1 -0
- package/dist/node_modules/@langchain/core/dist/utils/async_caller.js +86 -0
- package/dist/node_modules/@langchain/core/dist/utils/async_caller.js.map +1 -0
- package/dist/node_modules/@langchain/core/dist/utils/env.js +33 -0
- package/dist/node_modules/@langchain/core/dist/utils/env.js.map +1 -0
- package/dist/node_modules/@langchain/core/dist/utils/fast-json-patch/core.js +218 -0
- package/dist/node_modules/@langchain/core/dist/utils/fast-json-patch/core.js.map +1 -0
- package/dist/node_modules/@langchain/core/dist/utils/fast-json-patch/helpers.js +117 -0
- package/dist/node_modules/@langchain/core/dist/utils/fast-json-patch/helpers.js.map +1 -0
- package/dist/node_modules/@langchain/core/dist/utils/json.js +40 -0
- package/dist/node_modules/@langchain/core/dist/utils/json.js.map +1 -0
- package/dist/node_modules/@langchain/core/dist/utils/stream.js +164 -0
- package/dist/node_modules/@langchain/core/dist/utils/stream.js.map +1 -0
- package/dist/node_modules/@langchain/core/node_modules/ansi-styles/index.js +111 -0
- package/dist/node_modules/@langchain/core/node_modules/ansi-styles/index.js.map +1 -0
- package/dist/node_modules/@langchain/core/node_modules/camelcase/index.js +30 -0
- package/dist/node_modules/@langchain/core/node_modules/camelcase/index.js.map +1 -0
- package/dist/node_modules/@langchain/core/node_modules/langsmith/dist/client.js +2002 -0
- package/dist/node_modules/@langchain/core/node_modules/langsmith/dist/client.js.map +1 -0
- package/dist/node_modules/@langchain/core/node_modules/langsmith/dist/index.js +8 -0
- package/dist/node_modules/@langchain/core/node_modules/langsmith/dist/index.js.map +1 -0
- package/dist/node_modules/@langchain/core/node_modules/langsmith/dist/singletons/fetch.js +5 -0
- package/dist/node_modules/@langchain/core/node_modules/langsmith/dist/singletons/fetch.js.map +1 -0
- package/dist/node_modules/@langchain/core/node_modules/langsmith/dist/utils/_uuid.js +12 -0
- package/dist/node_modules/@langchain/core/node_modules/langsmith/dist/utils/_uuid.js.map +1 -0
- package/dist/node_modules/@langchain/core/node_modules/langsmith/dist/utils/async_caller.js +94 -0
- package/dist/node_modules/@langchain/core/node_modules/langsmith/dist/utils/async_caller.js.map +1 -0
- package/dist/node_modules/@langchain/core/node_modules/langsmith/dist/utils/env.js +96 -0
- package/dist/node_modules/@langchain/core/node_modules/langsmith/dist/utils/env.js.map +1 -0
- package/dist/node_modules/@langchain/core/node_modules/langsmith/dist/utils/error.js +20 -0
- package/dist/node_modules/@langchain/core/node_modules/langsmith/dist/utils/error.js.map +1 -0
- package/dist/node_modules/@langchain/core/node_modules/langsmith/dist/utils/fast-safe-stringify/index.js +82 -0
- package/dist/node_modules/@langchain/core/node_modules/langsmith/dist/utils/fast-safe-stringify/index.js.map +1 -0
- package/dist/node_modules/@langchain/core/node_modules/langsmith/dist/utils/messages.js +15 -0
- package/dist/node_modules/@langchain/core/node_modules/langsmith/dist/utils/messages.js.map +1 -0
- package/dist/node_modules/@langchain/core/node_modules/langsmith/dist/utils/prompts.js +27 -0
- package/dist/node_modules/@langchain/core/node_modules/langsmith/dist/utils/prompts.js.map +1 -0
- package/dist/node_modules/@langchain/core/node_modules/langsmith/dist/utils/warn.js +8 -0
- package/dist/node_modules/@langchain/core/node_modules/langsmith/dist/utils/warn.js.map +1 -0
- package/dist/node_modules/@langchain/core/node_modules/langsmith/node_modules/uuid/dist/esm-browser/native.js +8 -0
- package/dist/node_modules/@langchain/core/node_modules/langsmith/node_modules/uuid/dist/esm-browser/native.js.map +1 -0
- package/dist/node_modules/@langchain/core/node_modules/langsmith/node_modules/uuid/dist/esm-browser/regex.js +5 -0
- package/dist/node_modules/@langchain/core/node_modules/langsmith/node_modules/uuid/dist/esm-browser/regex.js.map +1 -0
- package/dist/node_modules/@langchain/core/node_modules/langsmith/node_modules/uuid/dist/esm-browser/rng.js +10 -0
- package/dist/node_modules/@langchain/core/node_modules/langsmith/node_modules/uuid/dist/esm-browser/rng.js.map +1 -0
- package/dist/node_modules/@langchain/core/node_modules/langsmith/node_modules/uuid/dist/esm-browser/stringify.js +10 -0
- package/dist/node_modules/@langchain/core/node_modules/langsmith/node_modules/uuid/dist/esm-browser/stringify.js.map +1 -0
- package/dist/node_modules/@langchain/core/node_modules/langsmith/node_modules/uuid/dist/esm-browser/v4.js +14 -0
- package/dist/node_modules/@langchain/core/node_modules/langsmith/node_modules/uuid/dist/esm-browser/v4.js.map +1 -0
- package/dist/node_modules/@langchain/core/node_modules/langsmith/node_modules/uuid/dist/esm-browser/validate.js +8 -0
- package/dist/node_modules/@langchain/core/node_modules/langsmith/node_modules/uuid/dist/esm-browser/validate.js.map +1 -0
- package/dist/node_modules/@langchain/core/node_modules/uuid/dist/esm-browser/native.js +7 -0
- package/dist/node_modules/@langchain/core/node_modules/uuid/dist/esm-browser/native.js.map +1 -0
- package/dist/node_modules/@langchain/core/node_modules/uuid/dist/esm-browser/regex.js +5 -0
- package/dist/node_modules/@langchain/core/node_modules/uuid/dist/esm-browser/regex.js.map +1 -0
- package/dist/node_modules/@langchain/core/node_modules/uuid/dist/esm-browser/rng.js +11 -0
- package/dist/node_modules/@langchain/core/node_modules/uuid/dist/esm-browser/rng.js.map +1 -0
- package/dist/node_modules/@langchain/core/node_modules/uuid/dist/esm-browser/stringify.js +10 -0
- package/dist/node_modules/@langchain/core/node_modules/uuid/dist/esm-browser/stringify.js.map +1 -0
- package/dist/node_modules/@langchain/core/node_modules/uuid/dist/esm-browser/v4.js +14 -0
- package/dist/node_modules/@langchain/core/node_modules/uuid/dist/esm-browser/v4.js.map +1 -0
- package/dist/node_modules/@langchain/core/node_modules/uuid/dist/esm-browser/validate.js +8 -0
- package/dist/node_modules/@langchain/core/node_modules/uuid/dist/esm-browser/validate.js.map +1 -0
- package/dist/node_modules/base64-js/index.js +53 -0
- package/dist/node_modules/base64-js/index.js.map +1 -0
- package/dist/node_modules/decamelize/index.js +12 -0
- package/dist/node_modules/decamelize/index.js.map +1 -0
- package/dist/node_modules/eventemitter3/index.js +112 -0
- package/dist/node_modules/eventemitter3/index.js.map +1 -0
- package/dist/node_modules/js-tiktoken/dist/chunk-Z5MDQTGX.js +117 -0
- package/dist/node_modules/js-tiktoken/dist/chunk-Z5MDQTGX.js.map +1 -0
- package/dist/node_modules/p-finally/index.js +18 -0
- package/dist/node_modules/p-finally/index.js.map +1 -0
- package/dist/node_modules/p-queue/dist/index.js +198 -0
- package/dist/node_modules/p-queue/dist/index.js.map +1 -0
- package/dist/node_modules/p-queue/dist/lower-bound.js +20 -0
- package/dist/node_modules/p-queue/dist/lower-bound.js.map +1 -0
- package/dist/node_modules/p-queue/dist/priority-queue.js +41 -0
- package/dist/node_modules/p-queue/dist/priority-queue.js.map +1 -0
- package/dist/node_modules/p-retry/index.js +63 -0
- package/dist/node_modules/p-retry/index.js.map +1 -0
- package/dist/node_modules/p-timeout/index.js +45 -0
- package/dist/node_modules/p-timeout/index.js.map +1 -0
- package/dist/node_modules/retry/index.js +9 -0
- package/dist/node_modules/retry/index.js.map +1 -0
- package/dist/node_modules/retry/lib/retry.js +59 -0
- package/dist/node_modules/retry/lib/retry.js.map +1 -0
- package/dist/node_modules/retry/lib/retry_operation.js +58 -0
- package/dist/node_modules/retry/lib/retry_operation.js.map +1 -0
- package/dist/node_modules/semver/classes/comparator.js +57 -0
- package/dist/node_modules/semver/classes/comparator.js.map +1 -0
- package/dist/node_modules/semver/classes/range.js +149 -0
- package/dist/node_modules/semver/classes/range.js.map +1 -0
- package/dist/node_modules/semver/classes/semver.js +170 -0
- package/dist/node_modules/semver/classes/semver.js.map +1 -0
- package/dist/node_modules/semver/functions/clean.js +15 -0
- package/dist/node_modules/semver/functions/clean.js.map +1 -0
- package/dist/node_modules/semver/functions/cmp.js +40 -0
- package/dist/node_modules/semver/functions/cmp.js.map +1 -0
- package/dist/node_modules/semver/functions/coerce.js +34 -0
- package/dist/node_modules/semver/functions/coerce.js.map +1 -0
- package/dist/node_modules/semver/functions/compare-build.js +15 -0
- package/dist/node_modules/semver/functions/compare-build.js.map +1 -0
- package/dist/node_modules/semver/functions/compare-loose.js +12 -0
- package/dist/node_modules/semver/functions/compare-loose.js.map +1 -0
- package/dist/node_modules/semver/functions/compare.js +12 -0
- package/dist/node_modules/semver/functions/compare.js.map +1 -0
- package/dist/node_modules/semver/functions/diff.js +25 -0
- package/dist/node_modules/semver/functions/diff.js.map +1 -0
- package/dist/node_modules/semver/functions/eq.js +12 -0
- package/dist/node_modules/semver/functions/eq.js.map +1 -0
- package/dist/node_modules/semver/functions/gt.js +12 -0
- package/dist/node_modules/semver/functions/gt.js.map +1 -0
- package/dist/node_modules/semver/functions/gte.js +12 -0
- package/dist/node_modules/semver/functions/gte.js.map +1 -0
- package/dist/node_modules/semver/functions/inc.js +22 -0
- package/dist/node_modules/semver/functions/inc.js.map +1 -0
- package/dist/node_modules/semver/functions/lt.js +12 -0
- package/dist/node_modules/semver/functions/lt.js.map +1 -0
- package/dist/node_modules/semver/functions/lte.js +12 -0
- package/dist/node_modules/semver/functions/lte.js.map +1 -0
- package/dist/node_modules/semver/functions/major.js +12 -0
- package/dist/node_modules/semver/functions/major.js.map +1 -0
- package/dist/node_modules/semver/functions/minor.js +12 -0
- package/dist/node_modules/semver/functions/minor.js.map +1 -0
- package/dist/node_modules/semver/functions/neq.js +12 -0
- package/dist/node_modules/semver/functions/neq.js.map +1 -0
- package/dist/node_modules/semver/functions/parse.js +22 -0
- package/dist/node_modules/semver/functions/parse.js.map +1 -0
- package/dist/node_modules/semver/functions/patch.js +12 -0
- package/dist/node_modules/semver/functions/patch.js.map +1 -0
- package/dist/node_modules/semver/functions/prerelease.js +15 -0
- package/dist/node_modules/semver/functions/prerelease.js.map +1 -0
- package/dist/node_modules/semver/functions/rcompare.js +12 -0
- package/dist/node_modules/semver/functions/rcompare.js.map +1 -0
- package/dist/node_modules/semver/functions/rsort.js +12 -0
- package/dist/node_modules/semver/functions/rsort.js.map +1 -0
- package/dist/node_modules/semver/functions/satisfies.js +19 -0
- package/dist/node_modules/semver/functions/satisfies.js.map +1 -0
- package/dist/node_modules/semver/functions/sort.js +12 -0
- package/dist/node_modules/semver/functions/sort.js.map +1 -0
- package/dist/node_modules/semver/functions/valid.js +15 -0
- package/dist/node_modules/semver/functions/valid.js.map +1 -0
- package/dist/node_modules/semver/index.js +98 -0
- package/dist/node_modules/semver/index.js.map +1 -0
- package/dist/node_modules/semver/internal/constants.js +29 -0
- package/dist/node_modules/semver/internal/constants.js.map +1 -0
- package/dist/node_modules/semver/internal/debug.js +9 -0
- package/dist/node_modules/semver/internal/debug.js.map +1 -0
- package/dist/node_modules/semver/internal/identifiers.js +17 -0
- package/dist/node_modules/semver/internal/identifiers.js.map +1 -0
- package/dist/node_modules/semver/internal/lrucache.js +33 -0
- package/dist/node_modules/semver/internal/lrucache.js.map +1 -0
- package/dist/node_modules/semver/internal/parse-options.js +11 -0
- package/dist/node_modules/semver/internal/parse-options.js.map +1 -0
- package/dist/node_modules/semver/internal/re.js +33 -0
- package/dist/node_modules/semver/internal/re.js.map +1 -0
- package/dist/node_modules/semver/ranges/gtr.js +12 -0
- package/dist/node_modules/semver/ranges/gtr.js.map +1 -0
- package/dist/node_modules/semver/ranges/intersects.js +12 -0
- package/dist/node_modules/semver/ranges/intersects.js.map +1 -0
- package/dist/node_modules/semver/ranges/ltr.js +12 -0
- package/dist/node_modules/semver/ranges/ltr.js.map +1 -0
- package/dist/node_modules/semver/ranges/max-satisfying.js +23 -0
- package/dist/node_modules/semver/ranges/max-satisfying.js.map +1 -0
- package/dist/node_modules/semver/ranges/min-satisfying.js +23 -0
- package/dist/node_modules/semver/ranges/min-satisfying.js.map +1 -0
- package/dist/node_modules/semver/ranges/min-version.js +43 -0
- package/dist/node_modules/semver/ranges/min-version.js.map +1 -0
- package/dist/node_modules/semver/ranges/outside.js +45 -0
- package/dist/node_modules/semver/ranges/outside.js.map +1 -0
- package/dist/node_modules/semver/ranges/simplify.js +25 -0
- package/dist/node_modules/semver/ranges/simplify.js.map +1 -0
- package/dist/node_modules/semver/ranges/subset.js +95 -0
- package/dist/node_modules/semver/ranges/subset.js.map +1 -0
- package/dist/node_modules/semver/ranges/to-comparators.js +12 -0
- package/dist/node_modules/semver/ranges/to-comparators.js.map +1 -0
- package/dist/node_modules/semver/ranges/valid.js +18 -0
- package/dist/node_modules/semver/ranges/valid.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/Options.js +32 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/Options.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/Refs.js +22 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/Refs.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/errorMessages.js +14 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/errorMessages.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parseDef.js +44 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parseDef.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/any.js +7 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/any.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/array.js +17 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/array.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/bigint.js +26 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/bigint.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/boolean.js +9 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/boolean.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/branded.js +8 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/branded.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/catch.js +6 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/catch.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/date.js +59 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/date.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/default.js +11 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/default.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/effects.js +8 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/effects.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/enum.js +10 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/enum.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/intersection.js +36 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/intersection.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/literal.js +16 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/literal.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/map.js +27 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/map.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/nativeEnum.js +11 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/nativeEnum.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/never.js +9 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/never.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/null.js +12 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/null.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/nullable.js +30 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/nullable.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/number.js +28 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/number.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/object.js +50 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/object.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/optional.js +22 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/optional.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/pipeline.js +21 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/pipeline.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/promise.js +8 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/promise.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/readonly.js +6 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/readonly.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/record.js +56 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/record.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/set.js +17 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/set.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/string.js +245 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/string.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/tuple.js +27 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/tuple.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/undefined.js +9 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/undefined.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/union.js +69 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/union.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/unknown.js +7 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/unknown.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/selectParser.js +110 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/selectParser.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/zodToJsonSchema.js +26 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/zodToJsonSchema.js.map +1 -0
- package/dist/plugins/BasePlugin.d.ts +28 -0
- package/dist/plugins/BasePlugin.js +19 -0
- package/dist/plugins/BasePlugin.js.map +1 -0
- package/dist/plugins/PluginInterface.d.ts +64 -0
- package/dist/plugins/PluginLoader.d.ts +38 -0
- package/dist/plugins/PluginLoader.js +60 -0
- package/dist/plugins/PluginLoader.js.map +1 -0
- package/dist/plugins/PluginRegistry.d.ts +47 -0
- package/dist/plugins/PluginRegistry.js +71 -0
- package/dist/plugins/PluginRegistry.js.map +1 -0
- package/dist/plugins/__tests__/BasePlugin.test.d.ts +1 -0
- package/dist/plugins/__tests__/PluginLoader.test.d.ts +1 -0
- package/dist/plugins/__tests__/PluginRegistry.test.d.ts +1 -0
- package/dist/plugins/defi/index.d.ts +13 -0
- package/dist/plugins/hedera/HbarPricePlugin.d.ts +45 -0
- package/dist/plugins/hedera/HbarPricePlugin.js +70 -0
- package/dist/plugins/hedera/HbarPricePlugin.js.map +1 -0
- package/dist/plugins/hedera/__tests__/HbarPricePlugin.test.d.ts +1 -0
- package/dist/plugins/index.d.ts +5 -0
- package/dist/plugins/weather/index.d.ts +15 -0
- package/dist/src/agents/index.d.ts +0 -0
- package/dist/src/init.d.ts +2 -2
- package/dist/src/plugins/hedera/HbarPricePlugin.d.ts +45 -0
- package/dist/src/plugins/index.d.ts +1 -0
- package/dist/src/tools/CheckMessagesTool.d.ts +9 -2
- package/dist/src/utils/state-tools.d.ts +23 -0
- package/dist/state/index.d.ts +2 -0
- package/dist/state/open-convai-state.d.ts +84 -0
- package/dist/state/open-convai-state.js +132 -0
- package/dist/state/open-convai-state.js.map +1 -0
- package/dist/state/state-types.d.ts +143 -0
- package/dist/tools/AcceptConnectionRequestTool.d.ts +33 -0
- package/dist/tools/AcceptConnectionRequestTool.js +116 -0
- package/dist/tools/AcceptConnectionRequestTool.js.map +1 -0
- package/dist/tools/CheckMessagesTool.d.ts +34 -0
- package/dist/tools/CheckMessagesTool.js +96 -0
- package/dist/tools/CheckMessagesTool.js.map +1 -0
- package/dist/tools/ConnectionMonitorTool.d.ts +96 -0
- package/dist/tools/ConnectionMonitorTool.js +289 -0
- package/dist/tools/ConnectionMonitorTool.js.map +1 -0
- package/dist/tools/ConnectionTool.d.ts +40 -0
- package/dist/tools/ConnectionTool.js +114 -0
- package/dist/tools/ConnectionTool.js.map +1 -0
- package/dist/tools/FindRegistrationsTool.d.ts +27 -0
- package/dist/tools/FindRegistrationsTool.js +64 -0
- package/dist/tools/FindRegistrationsTool.js.map +1 -0
- package/dist/tools/InitiateConnectionTool.d.ts +30 -0
- package/dist/tools/InitiateConnectionTool.js +79 -0
- package/dist/tools/InitiateConnectionTool.js.map +1 -0
- package/dist/tools/ListConnectionsTool.d.ts +33 -0
- package/dist/tools/ListConnectionsTool.js +327 -0
- package/dist/tools/ListConnectionsTool.js.map +1 -0
- package/dist/tools/ListUnapprovedConnectionRequestsTool.d.ts +53 -0
- package/dist/tools/ListUnapprovedConnectionRequestsTool.js +177 -0
- package/dist/tools/ListUnapprovedConnectionRequestsTool.js.map +1 -0
- package/dist/tools/ManageConnectionRequestsTool.d.ts +39 -0
- package/dist/tools/ManageConnectionRequestsTool.js +161 -0
- package/dist/tools/ManageConnectionRequestsTool.js.map +1 -0
- package/dist/tools/RegisterAgentTool.d.ts +188 -0
- package/dist/tools/RegisterAgentTool.js +331 -0
- package/dist/tools/RegisterAgentTool.js.map +1 -0
- package/dist/tools/RetrieveProfileTool.d.ts +34 -0
- package/dist/tools/RetrieveProfileTool.js +53 -0
- package/dist/tools/RetrieveProfileTool.js.map +1 -0
- package/dist/tools/SendMessageToConnectionTool.d.ts +31 -0
- package/dist/tools/SendMessageToConnectionTool.js +74 -0
- package/dist/tools/SendMessageToConnectionTool.js.map +1 -0
- package/dist/tools/SendMessageTool.d.ts +44 -0
- package/dist/tools/SendMessageTool.js +75 -0
- package/dist/tools/SendMessageTool.js.map +1 -0
- package/dist/tools/index.d.ts +13 -0
- package/dist/utils/Encryption.d.ts +7 -0
- package/dist/utils/Encryption.js +7 -0
- package/dist/utils/Encryption.js.map +1 -0
- package/dist/utils/HederaClient.d.ts +18 -0
- package/dist/utils/connectionUtils.d.ts +15 -0
- package/dist/utils/connectionUtils.js +64 -0
- package/dist/utils/connectionUtils.js.map +1 -0
- package/dist/utils/state-tools.d.ts +23 -0
- package/dist/utils/state-tools.js +90 -0
- package/dist/utils/state-tools.js.map +1 -0
- package/package.json +20 -10
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { StructuredTool as w } from "../node_modules/@langchain/core/dist/tools.js";
|
|
2
|
+
import { z as p } from "zod";
|
|
3
|
+
import { Logger as y } from "@hashgraphonline/standards-sdk";
|
|
4
|
+
class I extends w {
|
|
5
|
+
constructor({ hcsClient: g, stateManager: m, ...h }) {
|
|
6
|
+
super(h), this.name = "check_messages", this.description = `Checks for and retrieves messages from an active connection.
|
|
7
|
+
Identify the target agent using their account ID (e.g., 0.0.12345) or the connection number shown in 'list_connections'.
|
|
8
|
+
By default, it only retrieves messages newer than the last check.
|
|
9
|
+
Use 'fetchLatest: true' to get the most recent messages regardless of when they arrived.
|
|
10
|
+
Use 'lastMessagesCount' to specify how many latest messages to retrieve (default 1 when fetchLatest is true).`, this.schema = p.object({
|
|
11
|
+
targetIdentifier: p.string().describe(
|
|
12
|
+
"The account ID (e.g., 0.0.12345) of the target agent OR the connection number (e.g., '1', '2') from the 'list_connections' tool to check messages for."
|
|
13
|
+
),
|
|
14
|
+
fetchLatest: p.boolean().optional().default(!1).describe(
|
|
15
|
+
"Set to true to fetch the latest messages even if they have been seen before, ignoring the last checked timestamp. Defaults to false (fetching only new messages)."
|
|
16
|
+
),
|
|
17
|
+
lastMessagesCount: p.number().int().positive().optional().describe(
|
|
18
|
+
"When fetchLatest is true, specifies how many of the most recent messages to retrieve. Defaults to 1."
|
|
19
|
+
)
|
|
20
|
+
}), this.hcsClient = g, this.stateManager = m, this.logger = y.getInstance({ module: "CheckMessagesTool" });
|
|
21
|
+
}
|
|
22
|
+
async _call({
|
|
23
|
+
targetIdentifier: g,
|
|
24
|
+
fetchLatest: m,
|
|
25
|
+
lastMessagesCount: h
|
|
26
|
+
}) {
|
|
27
|
+
const l = this.stateManager.getConnectionByIdentifier(g);
|
|
28
|
+
if (!l)
|
|
29
|
+
return `Error: Could not find an active connection matching identifier "${g}". Use 'list_connections' to see active connections.`;
|
|
30
|
+
const s = l.connectionTopicId, i = l.targetAgentName, r = this.stateManager.getLastTimestamp(s);
|
|
31
|
+
this.logger.info(
|
|
32
|
+
`Checking messages for connection with ${i} (${l.targetAccountId}) on topic ${s} (fetchLatest: ${m}, lastCount: ${h}, since: ${r})`
|
|
33
|
+
);
|
|
34
|
+
try {
|
|
35
|
+
const f = (await this.hcsClient.getMessages(s)).messages;
|
|
36
|
+
if (!f || f.length === 0)
|
|
37
|
+
return `No messages found on connection topic ${s}.`;
|
|
38
|
+
let o = [], u = r;
|
|
39
|
+
const d = m === !0;
|
|
40
|
+
if (d) {
|
|
41
|
+
this.logger.info("Fetching latest messages regardless of timestamp.");
|
|
42
|
+
const t = h ?? 1;
|
|
43
|
+
o = f.slice(-t);
|
|
44
|
+
} else
|
|
45
|
+
this.logger.info(
|
|
46
|
+
`Filtering for messages newer than ${r}`
|
|
47
|
+
), o = f.filter((t) => t.timestamp * 1e6 > r), o.length > 0 && (u = o.reduce(
|
|
48
|
+
(t, e) => Math.max(t, e.timestamp * 1e6),
|
|
49
|
+
r
|
|
50
|
+
));
|
|
51
|
+
if (o.length === 0)
|
|
52
|
+
return d ? `Could not retrieve the latest message(s). No messages found on topic ${s}.` : `No new messages found for connection with ${i} since last check.`;
|
|
53
|
+
this.logger.info(`Processing ${o.length} message(s).`);
|
|
54
|
+
let $ = d ? `Latest message(s) from ${i}:
|
|
55
|
+
` : `New messages from ${i}:
|
|
56
|
+
`;
|
|
57
|
+
for (const t of o) {
|
|
58
|
+
let e = t.data;
|
|
59
|
+
try {
|
|
60
|
+
typeof e == "string" && e.startsWith("hcs://") && (this.logger.debug(`Resolving inscribed message: ${e}`), e = await this.hcsClient.getMessageContent(e), this.logger.debug(`Resolved content length: ${e == null ? void 0 : e.length}`));
|
|
61
|
+
let n = e;
|
|
62
|
+
try {
|
|
63
|
+
const a = JSON.parse(e);
|
|
64
|
+
a.p === "hcs-10" && a.op === "message" && a.data ? n = `[${a.operator_id || "unknown_sender"}]: ${a.data}` : n = e;
|
|
65
|
+
} catch {
|
|
66
|
+
n = e;
|
|
67
|
+
}
|
|
68
|
+
const b = new Date(t.timestamp);
|
|
69
|
+
$ += `
|
|
70
|
+
[${b.toLocaleString()}] (Seq: ${t.sequence_number})
|
|
71
|
+
${n}
|
|
72
|
+
`;
|
|
73
|
+
} catch (n) {
|
|
74
|
+
const b = `Error processing message (Seq: ${t.sequence_number}): ${n instanceof Error ? n.message : String(n)}`;
|
|
75
|
+
this.logger.error(b), $ += `
|
|
76
|
+
[Error processing message Seq: ${t.sequence_number}]
|
|
77
|
+
`;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return !d && u > r && (this.logger.debug(
|
|
81
|
+
`Updating timestamp for topic ${s} to ${u}`
|
|
82
|
+
), this.stateManager.updateTimestamp(
|
|
83
|
+
s,
|
|
84
|
+
u
|
|
85
|
+
)), $.trim();
|
|
86
|
+
} catch (c) {
|
|
87
|
+
return this.logger.error(
|
|
88
|
+
`Failed to check messages for topic ${s}: ${c}`
|
|
89
|
+
), `Error checking messages for ${i}: ${c instanceof Error ? c.message : String(c)}`;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
export {
|
|
94
|
+
I as CheckMessagesTool
|
|
95
|
+
};
|
|
96
|
+
//# sourceMappingURL=CheckMessagesTool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CheckMessagesTool.js","sources":["../../src/tools/CheckMessagesTool.ts"],"sourcesContent":["import { StructuredTool, ToolParams } from '@langchain/core/tools';\nimport { z } from 'zod';\nimport { HCS10Client, HCSMessageWithTimestamp } from '../hcs10/HCS10Client';\nimport { IStateManager } from '../state/state-types';\nimport { Logger } from '@hashgraphonline/standards-sdk'; // Assuming logger utility\n\nexport interface CheckMessagesToolParams extends ToolParams {\n hcsClient: HCS10Client;\n stateManager: IStateManager;\n}\n\n/**\n * A tool to check for new messages on an active HCS-10 connection topic,\n * or optionally fetch the latest messages regardless of timestamp.\n */\nexport class CheckMessagesTool extends StructuredTool {\n name = 'check_messages';\n description = `Checks for and retrieves messages from an active connection. \nIdentify the target agent using their account ID (e.g., 0.0.12345) or the connection number shown in 'list_connections'. \nBy default, it only retrieves messages newer than the last check. \nUse 'fetchLatest: true' to get the most recent messages regardless of when they arrived. \nUse 'lastMessagesCount' to specify how many latest messages to retrieve (default 1 when fetchLatest is true).`;\n schema = z.object({\n targetIdentifier: z\n .string()\n .describe(\n \"The account ID (e.g., 0.0.12345) of the target agent OR the connection number (e.g., '1', '2') from the 'list_connections' tool to check messages for.\"\n ),\n fetchLatest: z\n .boolean()\n .optional()\n .default(false)\n .describe(\n 'Set to true to fetch the latest messages even if they have been seen before, ignoring the last checked timestamp. Defaults to false (fetching only new messages).'\n ),\n lastMessagesCount: z\n .number()\n .int()\n .positive()\n .optional()\n .describe(\n 'When fetchLatest is true, specifies how many of the most recent messages to retrieve. Defaults to 1.'\n ),\n });\n\n public hcsClient: HCS10Client;\n private stateManager: IStateManager;\n private logger: Logger;\n\n constructor({ hcsClient, stateManager, ...rest }: CheckMessagesToolParams) {\n super(rest);\n this.hcsClient = hcsClient;\n this.stateManager = stateManager;\n this.logger = Logger.getInstance({ module: 'CheckMessagesTool' });\n }\n\n protected async _call({\n targetIdentifier,\n fetchLatest,\n lastMessagesCount,\n }: z.infer<this['schema']>): Promise<string> {\n const connection =\n this.stateManager.getConnectionByIdentifier(targetIdentifier);\n\n if (!connection) {\n return `Error: Could not find an active connection matching identifier \"${targetIdentifier}\". Use 'list_connections' to see active connections.`;\n }\n\n const connectionTopicId = connection.connectionTopicId;\n const targetAgentName = connection.targetAgentName;\n const lastProcessedTimestamp =\n this.stateManager.getLastTimestamp(connectionTopicId);\n\n this.logger.info(\n `Checking messages for connection with ${targetAgentName} (${connection.targetAccountId}) on topic ${connectionTopicId} (fetchLatest: ${fetchLatest}, lastCount: ${lastMessagesCount}, since: ${lastProcessedTimestamp})`\n );\n\n try {\n // 1. Get messages from the topic\n const result = await this.hcsClient.getMessages(connectionTopicId);\n const allMessages = result.messages;\n\n if (!allMessages || allMessages.length === 0) {\n return `No messages found on connection topic ${connectionTopicId}.`;\n }\n\n let messagesToProcess: HCSMessageWithTimestamp[] = [];\n let latestTimestampNanos = lastProcessedTimestamp;\n const isFetchingLatest = fetchLatest === true;\n\n if (isFetchingLatest) {\n this.logger.info('Fetching latest messages regardless of timestamp.');\n const count = lastMessagesCount ?? 1;\n messagesToProcess = allMessages.slice(-count);\n } else {\n this.logger.info(\n `Filtering for messages newer than ${lastProcessedTimestamp}`\n );\n messagesToProcess = allMessages.filter((msg) => {\n const msgTimestampNanos = msg.timestamp * 1_000_000;\n return msgTimestampNanos > lastProcessedTimestamp;\n });\n \n if (messagesToProcess.length > 0) {\n latestTimestampNanos = messagesToProcess.reduce((maxTs, msg) => \n Math.max(maxTs, msg.timestamp * 1_000_000), \n lastProcessedTimestamp\n );\n }\n }\n\n if (messagesToProcess.length === 0) {\n return isFetchingLatest\n ? `Could not retrieve the latest message(s). No messages found on topic ${connectionTopicId}.`\n : `No new messages found for connection with ${targetAgentName} since last check.`;\n }\n\n this.logger.info(`Processing ${messagesToProcess.length} message(s).`);\n\n // 3. Process messages (resolve inscriptions, format)\n let outputString = isFetchingLatest\n ? `Latest message(s) from ${targetAgentName}:\n`\n : `New messages from ${targetAgentName}:\n`;\n\n for (const msg of messagesToProcess) {\n let content = msg.data;\n try {\n // Check for inscription HRL\n if (typeof content === 'string' && content.startsWith('hcs://')) {\n this.logger.debug(`Resolving inscribed message: ${content}`);\n content = await this.hcsClient.getMessageContent(content);\n this.logger.debug(`Resolved content length: ${content?.length}`);\n }\n\n // Attempt to parse the content as the HCS-10 structure\n let displayContent = content; // Default to raw content\n try {\n const parsed = JSON.parse(content);\n if (\n parsed.p === 'hcs-10' &&\n parsed.op === 'message' &&\n parsed.data\n ) {\n // Extract sender and actual data from standard message format\n const senderOpId = parsed.operator_id || 'unknown_sender';\n displayContent = `[${senderOpId}]: ${parsed.data}`;\n } else {\n // If not standard format, maybe just show raw stringified version\n displayContent = content; // Keep raw if parsing worked but not expected format\n }\n } catch (parseError) {\n // Content wasn't JSON, keep raw content\n displayContent = content;\n }\n\n const messageDate = new Date(msg.timestamp);\n outputString += `\\n[${messageDate.toLocaleString()}] (Seq: ${\n msg.sequence_number\n })\n${displayContent}\n`;\n } catch (error) {\n const errorMsg = `Error processing message (Seq: ${\n msg.sequence_number\n }): ${error instanceof Error ? error.message : String(error)}`;\n this.logger.error(errorMsg);\n outputString += `\\n[Error processing message Seq: ${msg.sequence_number}]\\n`;\n }\n }\n\n // 4. Update the timestamp in demo state ONLY if fetching NEW messages\n if (!isFetchingLatest && latestTimestampNanos > lastProcessedTimestamp) {\n this.logger.debug(\n `Updating timestamp for topic ${connectionTopicId} to ${latestTimestampNanos}`\n );\n this.stateManager.updateTimestamp(\n connectionTopicId,\n latestTimestampNanos\n );\n }\n\n return outputString.trim();\n } catch (error) {\n this.logger.error(\n `Failed to check messages for topic ${connectionTopicId}: ${error}`\n );\n return `Error checking messages for ${targetAgentName}: ${\n error instanceof Error ? error.message : String(error)\n }`;\n }\n }\n}\n"],"names":["CheckMessagesTool","StructuredTool","hcsClient","stateManager","rest","z","Logger","targetIdentifier","fetchLatest","lastMessagesCount","connection","connectionTopicId","targetAgentName","lastProcessedTimestamp","allMessages","messagesToProcess","latestTimestampNanos","isFetchingLatest","count","msg","maxTs","outputString","content","displayContent","parsed","messageDate","error","errorMsg"],"mappings":";;;AAeO,MAAMA,UAA0BC,EAAe;AAAA,EAkCpD,YAAY,EAAE,WAAAC,GAAW,cAAAC,GAAc,GAAGC,KAAiC;AACzE,UAAMA,CAAI,GAlCL,KAAA,OAAA,kBACO,KAAA,cAAA;AAAA;AAAA;AAAA;AAAA,gHAKd,KAAA,SAASC,EAAE,OAAO;AAAA,MAChB,kBAAkBA,EACf,OAAA,EACA;AAAA,QACC;AAAA,MACF;AAAA,MACF,aA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AAAA,QACV,gCAAgCF,CAAiB,OAAOK,CAAoB;AAAA,MAC9E,GACA,KAAK,aAAa;AAAA,QAChBL;AAAA,QACAK;AAAA,MACF,IAGKK,EAAa,KAAK;AAAA,aAClBK,GAAO;AACd,kBAAK,OAAO;AAAA,QACV,sCAAsCf,CAAiB,KAAKe,CAAK;AAAA,MACnE,GACO,+BAA+Bd,CAAe,KACnDc,aAAiB,QAAQA,EAAM,UAAU,OAAOA,CAAK,CACvD;AAAA,IAAA;AAAA,EACF;AAEJ;"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { StructuredTool, ToolParams } from '@langchain/core/tools';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { HCS10Client } from '../hcs10/HCS10Client';
|
|
4
|
+
import { IStateManager } from '../state/state-types';
|
|
5
|
+
export interface FeeDefinition {
|
|
6
|
+
amount: number;
|
|
7
|
+
collectorAccount?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface TokenFeeDefinition extends FeeDefinition {
|
|
10
|
+
tokenId: string;
|
|
11
|
+
}
|
|
12
|
+
export interface ConnectionMonitorToolParams extends ToolParams {
|
|
13
|
+
hcsClient: HCS10Client;
|
|
14
|
+
stateManager: IStateManager;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* A tool for monitoring incoming connection requests and accepting them with optional fee settings.
|
|
18
|
+
*/
|
|
19
|
+
export declare class ConnectionMonitorTool extends StructuredTool {
|
|
20
|
+
name: string;
|
|
21
|
+
description: string;
|
|
22
|
+
schema: z.ZodObject<{
|
|
23
|
+
acceptAll: z.ZodOptional<z.ZodBoolean>;
|
|
24
|
+
targetAccountId: z.ZodOptional<z.ZodString>;
|
|
25
|
+
hbarFees: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
26
|
+
amount: z.ZodNumber;
|
|
27
|
+
collectorAccount: z.ZodOptional<z.ZodString>;
|
|
28
|
+
}, "strip", z.ZodTypeAny, {
|
|
29
|
+
amount: number;
|
|
30
|
+
collectorAccount?: string | undefined;
|
|
31
|
+
}, {
|
|
32
|
+
amount: number;
|
|
33
|
+
collectorAccount?: string | undefined;
|
|
34
|
+
}>, "many">>;
|
|
35
|
+
tokenFees: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
36
|
+
amount: z.ZodNumber;
|
|
37
|
+
tokenId: z.ZodString;
|
|
38
|
+
collectorAccount: z.ZodOptional<z.ZodString>;
|
|
39
|
+
}, "strip", z.ZodTypeAny, {
|
|
40
|
+
amount: number;
|
|
41
|
+
tokenId: string;
|
|
42
|
+
collectorAccount?: string | undefined;
|
|
43
|
+
}, {
|
|
44
|
+
amount: number;
|
|
45
|
+
tokenId: string;
|
|
46
|
+
collectorAccount?: string | undefined;
|
|
47
|
+
}>, "many">>;
|
|
48
|
+
exemptAccountIds: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
49
|
+
monitorDurationSeconds: z.ZodOptional<z.ZodNumber>;
|
|
50
|
+
defaultCollectorAccount: z.ZodOptional<z.ZodString>;
|
|
51
|
+
}, "strip", z.ZodTypeAny, {
|
|
52
|
+
hbarFees?: {
|
|
53
|
+
amount: number;
|
|
54
|
+
collectorAccount?: string | undefined;
|
|
55
|
+
}[] | undefined;
|
|
56
|
+
tokenFees?: {
|
|
57
|
+
amount: number;
|
|
58
|
+
tokenId: string;
|
|
59
|
+
collectorAccount?: string | undefined;
|
|
60
|
+
}[] | undefined;
|
|
61
|
+
exemptAccountIds?: string[] | undefined;
|
|
62
|
+
targetAccountId?: string | undefined;
|
|
63
|
+
acceptAll?: boolean | undefined;
|
|
64
|
+
monitorDurationSeconds?: number | undefined;
|
|
65
|
+
defaultCollectorAccount?: string | undefined;
|
|
66
|
+
}, {
|
|
67
|
+
hbarFees?: {
|
|
68
|
+
amount: number;
|
|
69
|
+
collectorAccount?: string | undefined;
|
|
70
|
+
}[] | undefined;
|
|
71
|
+
tokenFees?: {
|
|
72
|
+
amount: number;
|
|
73
|
+
tokenId: string;
|
|
74
|
+
collectorAccount?: string | undefined;
|
|
75
|
+
}[] | undefined;
|
|
76
|
+
exemptAccountIds?: string[] | undefined;
|
|
77
|
+
targetAccountId?: string | undefined;
|
|
78
|
+
acceptAll?: boolean | undefined;
|
|
79
|
+
monitorDurationSeconds?: number | undefined;
|
|
80
|
+
defaultCollectorAccount?: string | undefined;
|
|
81
|
+
}>;
|
|
82
|
+
private hcsClient;
|
|
83
|
+
private stateManager;
|
|
84
|
+
private logger;
|
|
85
|
+
private isMonitoring;
|
|
86
|
+
private listConnectionsTool;
|
|
87
|
+
private static processedRequests;
|
|
88
|
+
constructor({ hcsClient, stateManager, ...rest }: ConnectionMonitorToolParams);
|
|
89
|
+
updateClient(newClient: HCS10Client): void;
|
|
90
|
+
call(args: z.infer<this['schema']>): Promise<string>;
|
|
91
|
+
protected _call({ acceptAll, targetAccountId, hbarFees, tokenFees, exemptAccountIds, monitorDurationSeconds, defaultCollectorAccount, }: z.infer<this['schema']>): Promise<string>;
|
|
92
|
+
private createFeeConfig;
|
|
93
|
+
private extractAccountId;
|
|
94
|
+
private acceptConnectionRequest;
|
|
95
|
+
private formatFeeString;
|
|
96
|
+
}
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
import { StructuredTool as v } from "../node_modules/@langchain/core/dist/tools.js";
|
|
2
|
+
import { z as s } from "zod";
|
|
3
|
+
import { Logger as S, FeeConfigBuilder as x } from "@hashgraphonline/standards-sdk";
|
|
4
|
+
import { ListConnectionsTool as y } from "./ListConnectionsTool.js";
|
|
5
|
+
const m = class m extends v {
|
|
6
|
+
constructor({
|
|
7
|
+
hcsClient: e,
|
|
8
|
+
stateManager: t,
|
|
9
|
+
...c
|
|
10
|
+
}) {
|
|
11
|
+
super(c), this.name = "monitor_connections", this.description = "Monitors for incoming connection requests and accepts them with optional fee settings. Use this to watch for connection requests and accept them, optionally setting HBAR or token fees on the connection.", this.schema = s.object({
|
|
12
|
+
acceptAll: s.boolean().optional().describe(
|
|
13
|
+
"Whether to automatically accept all incoming connection requests. Default is false."
|
|
14
|
+
),
|
|
15
|
+
targetAccountId: s.string().optional().describe(
|
|
16
|
+
"If provided, only accept connection requests from this specific account ID."
|
|
17
|
+
),
|
|
18
|
+
hbarFees: s.array(
|
|
19
|
+
s.object({
|
|
20
|
+
amount: s.number(),
|
|
21
|
+
collectorAccount: s.string().optional()
|
|
22
|
+
})
|
|
23
|
+
).optional().describe(
|
|
24
|
+
"Array of HBAR fee amounts to charge per message (with optional collector accounts)."
|
|
25
|
+
),
|
|
26
|
+
tokenFees: s.array(
|
|
27
|
+
s.object({
|
|
28
|
+
amount: s.number(),
|
|
29
|
+
tokenId: s.string(),
|
|
30
|
+
collectorAccount: s.string().optional()
|
|
31
|
+
})
|
|
32
|
+
).optional().describe(
|
|
33
|
+
"Array of token fee amounts and IDs to charge per message (with optional collector accounts)."
|
|
34
|
+
),
|
|
35
|
+
exemptAccountIds: s.array(s.string()).optional().describe(
|
|
36
|
+
"Array of account IDs to exempt from ALL fees set in this request."
|
|
37
|
+
),
|
|
38
|
+
monitorDurationSeconds: s.number().optional().describe(
|
|
39
|
+
"How long to monitor for incoming requests in seconds. Default is 60."
|
|
40
|
+
),
|
|
41
|
+
defaultCollectorAccount: s.string().optional().describe(
|
|
42
|
+
"Default account to collect fees if not specified at the fee level. Defaults to the agent account."
|
|
43
|
+
)
|
|
44
|
+
}), this.isMonitoring = !1, this.hcsClient = e, this.stateManager = t, this.logger = S.getInstance({
|
|
45
|
+
module: "ConnectionMonitorTool",
|
|
46
|
+
level: "error"
|
|
47
|
+
}), this.listConnectionsTool = new y({
|
|
48
|
+
stateManager: t,
|
|
49
|
+
hcsClient: e,
|
|
50
|
+
...c
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
updateClient(e) {
|
|
54
|
+
this.hcsClient = e, this.logger.info("Updated HCS10Client instance for ConnectionMonitorTool"), this.listConnectionsTool = new y({
|
|
55
|
+
stateManager: this.stateManager,
|
|
56
|
+
hcsClient: e
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
async call(e) {
|
|
60
|
+
return this._call(e);
|
|
61
|
+
}
|
|
62
|
+
async _call({
|
|
63
|
+
acceptAll: e = !1,
|
|
64
|
+
targetAccountId: t,
|
|
65
|
+
hbarFees: c = [],
|
|
66
|
+
tokenFees: a = [],
|
|
67
|
+
exemptAccountIds: o,
|
|
68
|
+
monitorDurationSeconds: n = 60,
|
|
69
|
+
defaultCollectorAccount: f
|
|
70
|
+
}) {
|
|
71
|
+
if (!this.stateManager.getCurrentAgent())
|
|
72
|
+
return "Error: Cannot monitor for connections. No agent is currently active. Please register or select an agent first.";
|
|
73
|
+
if (this.isMonitoring)
|
|
74
|
+
return "Already monitoring for connection requests. Please wait for the current monitoring session to complete.";
|
|
75
|
+
try {
|
|
76
|
+
this.isMonitoring = !0;
|
|
77
|
+
const i = await this.hcsClient.getInboundTopicId();
|
|
78
|
+
if (!i)
|
|
79
|
+
return this.isMonitoring = !1, "Error: Could not find inbound topic ID for the current agent.";
|
|
80
|
+
this.logger.info(
|
|
81
|
+
`Starting to monitor inbound topic ${i} for connection requests...`
|
|
82
|
+
);
|
|
83
|
+
const r = this.createFeeConfig(
|
|
84
|
+
c,
|
|
85
|
+
a,
|
|
86
|
+
o,
|
|
87
|
+
t,
|
|
88
|
+
f
|
|
89
|
+
), g = Date.now() + n * 1e3, u = 3e3;
|
|
90
|
+
let w = 0, C = 0, q = 0, A = 0;
|
|
91
|
+
const k = this.hcsClient.getAccountAndSigner().accountId, M = ($) => `${k}:${$}`;
|
|
92
|
+
for (; Date.now() < g; )
|
|
93
|
+
try {
|
|
94
|
+
await this.listConnectionsTool.invoke({
|
|
95
|
+
includeDetails: !1,
|
|
96
|
+
showPending: !1
|
|
97
|
+
});
|
|
98
|
+
const $ = this.stateManager.listConnections(), I = new Set(
|
|
99
|
+
$.filter(
|
|
100
|
+
(l) => l.status === "established" && !l.isPending
|
|
101
|
+
).map((l) => l.targetAccountId)
|
|
102
|
+
), R = (await this.hcsClient.getMessages(
|
|
103
|
+
i
|
|
104
|
+
)).messages.filter((l) => !l.sequence_number || l.sequence_number <= w ? !1 : (w = Math.max(
|
|
105
|
+
w,
|
|
106
|
+
l.sequence_number
|
|
107
|
+
), l.op === "connection_request"));
|
|
108
|
+
for (const l of R) {
|
|
109
|
+
const h = l.sequence_number;
|
|
110
|
+
if (!h)
|
|
111
|
+
continue;
|
|
112
|
+
C++;
|
|
113
|
+
const b = M(h);
|
|
114
|
+
if (m.processedRequests.has(b)) {
|
|
115
|
+
this.logger.info(
|
|
116
|
+
`Request #${h} already processed, skipping`
|
|
117
|
+
), A++;
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
const p = this.extractAccountId(l);
|
|
121
|
+
if (!p) {
|
|
122
|
+
m.processedRequests.add(b);
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
if (t && p !== t) {
|
|
126
|
+
this.logger.info(
|
|
127
|
+
`Request #${h} doesn't match target ${t}`
|
|
128
|
+
);
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
if (I.has(p)) {
|
|
132
|
+
this.logger.info(
|
|
133
|
+
`Already connected to ${p}, skipping request #${h}`
|
|
134
|
+
), m.processedRequests.add(b), A++;
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
if (e) {
|
|
138
|
+
const D = await this.acceptConnectionRequest(
|
|
139
|
+
h,
|
|
140
|
+
p,
|
|
141
|
+
r
|
|
142
|
+
);
|
|
143
|
+
m.processedRequests.add(b), D.success && (q++, this.logger.info(
|
|
144
|
+
`Successfully accepted connection with ${p}`
|
|
145
|
+
));
|
|
146
|
+
} else
|
|
147
|
+
this.logger.info(
|
|
148
|
+
`Found request #${h} from ${p} (not auto-accepting)`
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
await new Promise((l) => setTimeout(l, u));
|
|
152
|
+
} catch ($) {
|
|
153
|
+
this.logger.error(`Error polling for messages: ${$}`), await new Promise((I) => setTimeout(I, u));
|
|
154
|
+
}
|
|
155
|
+
return this.isMonitoring = !1, C === 0 ? `No connection requests received during the ${n} second monitoring period.` : e ? `Monitored for ${n} seconds. Found ${C} connection requests, accepted ${q} connections, skipped ${A} existing connections${this.formatFeeString(
|
|
156
|
+
c,
|
|
157
|
+
a
|
|
158
|
+
)}.` : `Monitored for ${n} seconds. Found ${C} connection requests. To accept them, call this tool again with acceptAll=true.`;
|
|
159
|
+
} catch (i) {
|
|
160
|
+
return this.isMonitoring = !1, this.logger.error(`Connection monitoring failed: ${i}`), `Error monitoring for connections: ${i instanceof Error ? i.message : String(i)}`;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
createFeeConfig(e = [], t = [], c, a, o) {
|
|
164
|
+
if (!(e.length === 0 && t.length === 0))
|
|
165
|
+
try {
|
|
166
|
+
const n = this.hcsClient.getAccountAndSigner().accountId, f = o || n, d = new x({
|
|
167
|
+
network: this.hcsClient.getNetwork(),
|
|
168
|
+
logger: this.logger,
|
|
169
|
+
defaultCollectorAccountId: f
|
|
170
|
+
}), i = [...c || []];
|
|
171
|
+
a && !i.includes(a) && i.push(a);
|
|
172
|
+
for (const r of e)
|
|
173
|
+
if (r.amount > 0) {
|
|
174
|
+
const g = r.collectorAccount || f;
|
|
175
|
+
d.addHbarFee(r.amount, g, i), this.logger.info(
|
|
176
|
+
`Added HBAR fee: ${r.amount} HBAR to be collected by ${g}`
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
for (const r of t)
|
|
180
|
+
if (r.amount > 0 && r.tokenId) {
|
|
181
|
+
const g = r.collectorAccount || f;
|
|
182
|
+
d.addTokenFee(
|
|
183
|
+
r.amount,
|
|
184
|
+
r.tokenId,
|
|
185
|
+
g,
|
|
186
|
+
void 0,
|
|
187
|
+
i
|
|
188
|
+
), this.logger.info(
|
|
189
|
+
`Added token fee: ${r.amount} of token ${r.tokenId} to be collected by ${g}`
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
return d;
|
|
193
|
+
} catch (n) {
|
|
194
|
+
this.logger.error(`Error creating fee configuration: ${n}`);
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
extractAccountId(e) {
|
|
199
|
+
if (e.operator_id)
|
|
200
|
+
return this.hcsClient.standardClient.extractAccountFromOperatorId(
|
|
201
|
+
e.operator_id
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
async acceptConnectionRequest(e, t, c) {
|
|
205
|
+
var a, o;
|
|
206
|
+
try {
|
|
207
|
+
const n = await this.hcsClient.getInboundTopicId();
|
|
208
|
+
this.logger.info(
|
|
209
|
+
`Accepting connection request #${e} from ${t}`
|
|
210
|
+
);
|
|
211
|
+
const f = await this.hcsClient.handleConnectionRequest(
|
|
212
|
+
n,
|
|
213
|
+
t,
|
|
214
|
+
e,
|
|
215
|
+
c
|
|
216
|
+
);
|
|
217
|
+
if (!(f != null && f.connectionTopicId))
|
|
218
|
+
return {
|
|
219
|
+
success: !1,
|
|
220
|
+
error: "Connection acceptance returned no connection topic ID"
|
|
221
|
+
};
|
|
222
|
+
const d = f.connectionTopicId;
|
|
223
|
+
this.logger.info(
|
|
224
|
+
`Connection established! Topic ID: ${d}`
|
|
225
|
+
);
|
|
226
|
+
let i;
|
|
227
|
+
try {
|
|
228
|
+
const u = await this.hcsClient.getAgentProfile(
|
|
229
|
+
t
|
|
230
|
+
);
|
|
231
|
+
u.success && u.profile && (i = {
|
|
232
|
+
name: u.profile.display_name || u.profile.alias,
|
|
233
|
+
bio: u.profile.bio,
|
|
234
|
+
avatar: u.profile.profileImage,
|
|
235
|
+
type: u.profile.type
|
|
236
|
+
});
|
|
237
|
+
} catch (u) {
|
|
238
|
+
this.logger.warn(
|
|
239
|
+
`Could not fetch profile for ${t}: ${u}`
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
const r = ((o = (a = await this.hcsClient.getAgentProfile(t)) == null ? void 0 : a.topicInfo) == null ? void 0 : o.inboundTopic) || "", g = {
|
|
243
|
+
targetAccountId: t,
|
|
244
|
+
targetAgentName: (i == null ? void 0 : i.name) || `Agent ${t}`,
|
|
245
|
+
targetInboundTopicId: r,
|
|
246
|
+
connectionTopicId: d,
|
|
247
|
+
profileInfo: i,
|
|
248
|
+
created: /* @__PURE__ */ new Date(),
|
|
249
|
+
status: "established"
|
|
250
|
+
};
|
|
251
|
+
return this.stateManager.addActiveConnection(g), {
|
|
252
|
+
success: !0,
|
|
253
|
+
connectionTopicId: d
|
|
254
|
+
};
|
|
255
|
+
} catch (n) {
|
|
256
|
+
return this.logger.error(`Error accepting connection request: ${n}`), {
|
|
257
|
+
success: !1,
|
|
258
|
+
error: n instanceof Error ? n.message : String(n)
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
formatFeeString(e = [], t = []) {
|
|
263
|
+
if (e.length === 0 && t.length === 0)
|
|
264
|
+
return "";
|
|
265
|
+
let c = " with fees: ";
|
|
266
|
+
if (e.length > 0) {
|
|
267
|
+
const a = e.filter((o) => o.amount > 0).map((o) => {
|
|
268
|
+
const n = o.collectorAccount ? ` to ${o.collectorAccount}` : "";
|
|
269
|
+
return `${o.amount} HBAR${n}`;
|
|
270
|
+
}).join(", ");
|
|
271
|
+
a && (c += a);
|
|
272
|
+
}
|
|
273
|
+
if (t.length > 0) {
|
|
274
|
+
e.length > 0 && (c += " and ");
|
|
275
|
+
const a = t.filter((o) => o.amount > 0 && o.tokenId).map((o) => {
|
|
276
|
+
const n = o.collectorAccount ? ` to ${o.collectorAccount}` : "";
|
|
277
|
+
return `${o.amount} of token ${o.tokenId}${n}`;
|
|
278
|
+
}).join(", ");
|
|
279
|
+
a && (c += a);
|
|
280
|
+
}
|
|
281
|
+
return c === " with fees: " ? "" : c;
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
m.processedRequests = /* @__PURE__ */ new Set();
|
|
285
|
+
let T = m;
|
|
286
|
+
export {
|
|
287
|
+
T as ConnectionMonitorTool
|
|
288
|
+
};
|
|
289
|
+
//# sourceMappingURL=ConnectionMonitorTool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConnectionMonitorTool.js","sources":["../../src/tools/ConnectionMonitorTool.ts"],"sourcesContent":["import { StructuredTool, ToolParams } from '@langchain/core/tools';\nimport { z } from 'zod';\nimport { HCS10Client } from '../hcs10/HCS10Client';\nimport {\n IStateManager,\n ActiveConnection,\n AgentProfileInfo,\n} from '../state/state-types';\nimport {\n Logger,\n FeeConfigBuilder,\n HCSMessage,\n FeeConfigBuilderInterface,\n} from '@hashgraphonline/standards-sdk';\nimport { ListConnectionsTool } from './ListConnectionsTool';\n\nexport interface FeeDefinition {\n amount: number;\n collectorAccount?: string;\n}\n\nexport interface TokenFeeDefinition extends FeeDefinition {\n tokenId: string;\n}\n\nexport interface ConnectionMonitorToolParams extends ToolParams {\n hcsClient: HCS10Client;\n stateManager: IStateManager;\n}\n\n/**\n * A tool for monitoring incoming connection requests and accepting them with optional fee settings.\n */\nexport class ConnectionMonitorTool extends StructuredTool {\n name = 'monitor_connections';\n description =\n 'Monitors for incoming connection requests and accepts them with optional fee settings. Use this to watch for connection requests and accept them, optionally setting HBAR or token fees on the connection.';\n schema = z.object({\n acceptAll: z\n .boolean()\n .optional()\n .describe(\n 'Whether to automatically accept all incoming connection requests. Default is false.'\n ),\n targetAccountId: z\n .string()\n .optional()\n .describe(\n 'If provided, only accept connection requests from this specific account ID.'\n ),\n hbarFees: z\n .array(\n z.object({\n amount: z.number(),\n collectorAccount: z.string().optional(),\n })\n )\n .optional()\n .describe(\n 'Array of HBAR fee amounts to charge per message (with optional collector accounts).'\n ),\n tokenFees: z\n .array(\n z.object({\n amount: z.number(),\n tokenId: z.string(),\n collectorAccount: z.string().optional(),\n })\n )\n .optional()\n .describe(\n 'Array of token fee amounts and IDs to charge per message (with optional collector accounts).'\n ),\n exemptAccountIds: z\n .array(z.string())\n .optional()\n .describe(\n 'Array of account IDs to exempt from ALL fees set in this request.'\n ),\n monitorDurationSeconds: z\n .number()\n .optional()\n .describe(\n 'How long to monitor for incoming requests in seconds. Default is 60.'\n ),\n defaultCollectorAccount: z\n .string()\n .optional()\n .describe(\n 'Default account to collect fees if not specified at the fee level. Defaults to the agent account.'\n ),\n });\n\n private hcsClient: HCS10Client;\n private stateManager: IStateManager;\n private logger: Logger;\n private isMonitoring: boolean = false;\n private listConnectionsTool: ListConnectionsTool;\n private static processedRequests = new Set<string>();\n\n constructor({\n hcsClient,\n stateManager,\n ...rest\n }: ConnectionMonitorToolParams) {\n super(rest);\n this.hcsClient = hcsClient;\n this.stateManager = stateManager;\n this.logger = Logger.getInstance({\n module: 'ConnectionMonitorTool',\n level: 'error',\n });\n this.listConnectionsTool = new ListConnectionsTool({\n stateManager,\n hcsClient,\n ...rest,\n });\n }\n\n updateClient(newClient: HCS10Client): void {\n this.hcsClient = newClient;\n this.logger.info('Updated HCS10Client instance for ConnectionMonitorTool');\n this.listConnectionsTool = new ListConnectionsTool({\n stateManager: this.stateManager,\n hcsClient: newClient,\n });\n }\n\n async call(args: z.infer<this['schema']>): Promise<string> {\n return this._call(args);\n }\n\n protected async _call({\n acceptAll = false,\n targetAccountId,\n hbarFees = [],\n tokenFees = [],\n exemptAccountIds,\n monitorDurationSeconds = 60,\n defaultCollectorAccount,\n }: z.infer<this['schema']>): Promise<string> {\n const currentAgent = this.stateManager.getCurrentAgent();\n if (!currentAgent) {\n return 'Error: Cannot monitor for connections. No agent is currently active. Please register or select an agent first.';\n }\n\n if (this.isMonitoring) {\n return 'Already monitoring for connection requests. Please wait for the current monitoring session to complete.';\n }\n\n try {\n this.isMonitoring = true;\n const inboundTopicId = await this.hcsClient.getInboundTopicId();\n\n if (!inboundTopicId) {\n this.isMonitoring = false;\n return 'Error: Could not find inbound topic ID for the current agent.';\n }\n\n this.logger.info(\n `Starting to monitor inbound topic ${inboundTopicId} for connection requests...`\n );\n\n const feeConfig = this.createFeeConfig(\n hbarFees,\n tokenFees,\n exemptAccountIds,\n targetAccountId,\n defaultCollectorAccount\n );\n\n const endTime = Date.now() + monitorDurationSeconds * 1000;\n const pollIntervalMs = 3000;\n let lastSequenceNumber = 0;\n let connectionRequestsFound = 0;\n let acceptedConnections = 0;\n let skippedRequests = 0;\n const agentId = this.hcsClient.getAccountAndSigner().accountId;\n const requestIdKey = (reqId: number) => `${agentId}:${reqId}`;\n\n while (Date.now() < endTime) {\n try {\n await this.listConnectionsTool.invoke({\n includeDetails: false,\n showPending: false,\n });\n const currentConnections = this.stateManager.listConnections();\n const connectedAccountIds = new Set(\n currentConnections\n .filter(\n (conn) => conn.status === 'established' && !conn.isPending\n )\n .map((conn) => conn.targetAccountId)\n );\n\n const messagesResult = await this.hcsClient.getMessages(\n inboundTopicId\n );\n const newMessages = messagesResult.messages.filter((msg) => {\n if (\n !msg.sequence_number ||\n msg.sequence_number <= lastSequenceNumber\n ) {\n return false;\n }\n lastSequenceNumber = Math.max(\n lastSequenceNumber,\n msg.sequence_number\n );\n return msg.op === 'connection_request';\n });\n\n for (const request of newMessages) {\n const requestId = request.sequence_number;\n if (!requestId) {\n continue;\n }\n\n connectionRequestsFound++;\n\n const reqKey = requestIdKey(requestId);\n if (ConnectionMonitorTool.processedRequests.has(reqKey)) {\n this.logger.info(\n `Request #${requestId} already processed, skipping`\n );\n skippedRequests++;\n continue;\n }\n\n const requestorAccountId = this.extractAccountId(request);\n if (!requestorAccountId) {\n ConnectionMonitorTool.processedRequests.add(reqKey);\n continue;\n }\n\n if (targetAccountId && requestorAccountId !== targetAccountId) {\n this.logger.info(\n `Request #${requestId} doesn't match target ${targetAccountId}`\n );\n continue;\n }\n\n if (connectedAccountIds.has(requestorAccountId)) {\n this.logger.info(\n `Already connected to ${requestorAccountId}, skipping request #${requestId}`\n );\n ConnectionMonitorTool.processedRequests.add(reqKey);\n skippedRequests++;\n continue;\n }\n\n if (acceptAll) {\n const result = await this.acceptConnectionRequest(\n requestId,\n requestorAccountId,\n feeConfig\n );\n ConnectionMonitorTool.processedRequests.add(reqKey);\n\n if (result.success) {\n acceptedConnections++;\n this.logger.info(\n `Successfully accepted connection with ${requestorAccountId}`\n );\n }\n } else {\n this.logger.info(\n `Found request #${requestId} from ${requestorAccountId} (not auto-accepting)`\n );\n }\n }\n\n await new Promise((resolve) => setTimeout(resolve, pollIntervalMs));\n } catch (error) {\n this.logger.error(`Error polling for messages: ${error}`);\n await new Promise((resolve) => setTimeout(resolve, pollIntervalMs));\n }\n }\n\n this.isMonitoring = false;\n\n if (connectionRequestsFound === 0) {\n return `No connection requests received during the ${monitorDurationSeconds} second monitoring period.`;\n } else if (acceptAll) {\n return `Monitored for ${monitorDurationSeconds} seconds. Found ${connectionRequestsFound} connection requests, accepted ${acceptedConnections} connections, skipped ${skippedRequests} existing connections${this.formatFeeString(\n hbarFees,\n tokenFees\n )}.`;\n } else {\n return `Monitored for ${monitorDurationSeconds} seconds. Found ${connectionRequestsFound} connection requests. To accept them, call this tool again with acceptAll=true.`;\n }\n } catch (error) {\n this.isMonitoring = false;\n this.logger.error(`Connection monitoring failed: ${error}`);\n return `Error monitoring for connections: ${\n error instanceof Error ? error.message : String(error)\n }`;\n }\n }\n\n private createFeeConfig(\n hbarFees: FeeDefinition[] = [],\n tokenFees: TokenFeeDefinition[] = [],\n exemptAccountIds?: string[],\n targetAccountId?: string,\n defaultCollectorAccount?: string\n ): FeeConfigBuilderInterface | undefined {\n if (hbarFees.length === 0 && tokenFees.length === 0) {\n return undefined;\n }\n\n try {\n const agentAccountId = this.hcsClient.getAccountAndSigner().accountId;\n const defaultCollector = defaultCollectorAccount || agentAccountId;\n\n const builder = new FeeConfigBuilder({\n network: this.hcsClient.getNetwork(),\n logger: this.logger,\n defaultCollectorAccountId: defaultCollector,\n });\n\n const exemptIds = [...(exemptAccountIds || [])];\n if (targetAccountId && !exemptIds.includes(targetAccountId)) {\n exemptIds.push(targetAccountId);\n }\n\n for (const hbarFee of hbarFees) {\n if (hbarFee.amount > 0) {\n const collector = hbarFee.collectorAccount || defaultCollector;\n builder.addHbarFee(hbarFee.amount, collector, exemptIds);\n this.logger.info(\n `Added HBAR fee: ${hbarFee.amount} HBAR to be collected by ${collector}`\n );\n }\n }\n\n for (const tokenFee of tokenFees) {\n if (tokenFee.amount > 0 && tokenFee.tokenId) {\n const collector = tokenFee.collectorAccount || defaultCollector;\n builder.addTokenFee(\n tokenFee.amount,\n tokenFee.tokenId,\n collector,\n undefined,\n exemptIds\n );\n this.logger.info(\n `Added token fee: ${tokenFee.amount} of token ${tokenFee.tokenId} to be collected by ${collector}`\n );\n }\n }\n\n return builder;\n } catch (error) {\n this.logger.error(`Error creating fee configuration: ${error}`);\n return undefined;\n }\n }\n\n private extractAccountId(request: HCSMessage): string | undefined {\n if (request.operator_id) {\n return this.hcsClient.standardClient.extractAccountFromOperatorId(\n request.operator_id\n );\n }\n return undefined;\n }\n\n private async acceptConnectionRequest(\n connectionRequestId: number,\n requestingAccountId: string,\n feeConfig?: FeeConfigBuilderInterface\n ): Promise<{ success: boolean; connectionTopicId?: string; error?: string }> {\n try {\n const inboundTopicId = await this.hcsClient.getInboundTopicId();\n this.logger.info(\n `Accepting connection request #${connectionRequestId} from ${requestingAccountId}`\n );\n\n const result = await this.hcsClient.handleConnectionRequest(\n inboundTopicId,\n requestingAccountId,\n connectionRequestId,\n feeConfig\n );\n\n if (!result?.connectionTopicId) {\n return {\n success: false,\n error: 'Connection acceptance returned no connection topic ID',\n };\n }\n\n const connectionTopicId = result.connectionTopicId;\n this.logger.info(\n `Connection established! Topic ID: ${connectionTopicId}`\n );\n\n let profileInfo: AgentProfileInfo | undefined;\n try {\n const profile = await this.hcsClient.getAgentProfile(\n requestingAccountId\n );\n if (profile.success && profile.profile) {\n profileInfo = {\n name: profile.profile.display_name || profile.profile.alias,\n bio: profile.profile.bio,\n avatar: profile.profile.profileImage,\n type: profile.profile.type,\n };\n }\n } catch (profileError) {\n this.logger.warn(\n `Could not fetch profile for ${requestingAccountId}: ${profileError}`\n );\n }\n\n const targetInboundTopicId =\n (await this.hcsClient.getAgentProfile(requestingAccountId))?.topicInfo\n ?.inboundTopic || '';\n\n const newConnection: ActiveConnection = {\n targetAccountId: requestingAccountId,\n targetAgentName: profileInfo?.name || `Agent ${requestingAccountId}`,\n targetInboundTopicId,\n connectionTopicId,\n profileInfo,\n created: new Date(),\n status: 'established',\n };\n\n this.stateManager.addActiveConnection(newConnection);\n\n return {\n success: true,\n connectionTopicId,\n };\n } catch (error) {\n this.logger.error(`Error accepting connection request: ${error}`);\n return {\n success: false,\n error: error instanceof Error ? error.message : String(error),\n };\n }\n }\n\n private formatFeeString(\n hbarFees: FeeDefinition[] = [],\n tokenFees: TokenFeeDefinition[] = []\n ): string {\n if (hbarFees.length === 0 && tokenFees.length === 0) {\n return '';\n }\n\n let feeString = ' with fees: ';\n\n if (hbarFees.length > 0) {\n const hbarFeeDetails = hbarFees\n .filter((fee) => fee.amount > 0)\n .map((fee) => {\n const collector = fee.collectorAccount\n ? ` to ${fee.collectorAccount}`\n : '';\n return `${fee.amount} HBAR${collector}`;\n })\n .join(', ');\n\n if (hbarFeeDetails) {\n feeString += hbarFeeDetails;\n }\n }\n\n if (tokenFees.length > 0) {\n if (hbarFees.length > 0) {\n feeString += ' and ';\n }\n\n const tokenFeeDetails = tokenFees\n .filter((fee) => fee.amount > 0 && fee.tokenId)\n .map((fee) => {\n const collector = fee.collectorAccount\n ? ` to ${fee.collectorAccount}`\n : '';\n return `${fee.amount} of token ${fee.tokenId}${collector}`;\n })\n .join(', ');\n\n if (tokenFeeDetails) {\n feeString += tokenFeeDetails;\n }\n }\n\n return feeString === ' with fees: ' ? '' : feeString;\n }\n}\n"],"names":["_ConnectionMonitorTool","StructuredTool","hcsClient","stateManager","rest","z","Logger","ListConnectionsTool","newClient","args","acceptAll","targetAccountId","hbarFees","tokenFees","exemptAccountIds","monitorDurationSeconds","defaultCollectorAccount","inboundTopicId","feeConfig","endTime","pollIntervalMs","lastSequenceNumber","connectionRequestsFound","acceptedConnections","skippedRequests","agentId","requestIdKey","reqId","currentConnections","connectedAccountIds","conn","newMessages","msg","request","requestId","reqKey","requestorAccountId","result","resolve","error","agentAccountId","defaultCollector","builder","FeeConfigBuilder","exemptIds","hbarFee","collector","tokenFee","connectionRequestId","requestingAccountId","connectionTopicId","profileInfo","profile","profileError","targetInboundTopicId","_b","_a","newConnection","feeString","hbarFeeDetails","fee","tokenFeeDetails","ConnectionMonitorTool"],"mappings":";;;;AAiCO,MAAMA,IAAN,MAAMA,UAA8BC,EAAe;AAAA,EAmExD,YAAY;AAAA,IACV,WAAAC;AAAA,IACA,cAAAC;AAAA,IACA,GAAGC;AAAA,EAAA,GAC2B;AAC9B,UAAMA,CAAI,GAvEL,KAAA,OAAA,uBAEL,KAAA,cAAA,8MACF,KAAA,SAASC,EAAE,OAAO;AAAA,MAChB,WAAWA,EACR,UACA,SACA,EAAA;AAAA,QACC;AAAA,MACF;AAAA,MACF,iBAAiBA,EACd,SACA,SACA,EAAA;AAAA,QACC;AAAA,MACF;AAAA,MACF,UAAUA,EACP;AAAA,QACCA,EAAE,OAAO;AAAA,UACP,QAAQA,EAAE,OAAO;AAAA,UACjB,kBAAkBA,EAAE,OAAO,EAAE,SAAS;AAAA,QACvC,CAAA;AAAA,MAAA,EAEF,SACA,EAAA;AAAA,QACC;AAAA,MACF;AAAA,MACF,WAAWA,EACR;AAAA,QACCA,EAAE,OAAO;AAAA,UACP,QAAQA,EAAE,OAAO;AAAA,UACjB,SAASA,EAAE,OAAO;AAAA,UAClB,kBAAkBA,EAAE,OAAO,EAAE,SAAS;AAAA,QACvC,CAAA;AAAA,MAAA,EAEF,SACA,EAAA;AAAA,QACC;AAAA,MACF;AAAA,MACF,kBAAkBA,EACf,MAAMA,EAAE,QAAQ,EAChB,WACA;AAAA,QACC;AAAA,MACF;AAAA,MACF,wBAAwBA,EACrB,SACA,SACA,EAAA;AAAA,QACC;AAAA,MACF;AAAA,MACF,yBAAyBA,EACtB,SACA,SACA,EAAA;AAAA,QACC;AAAA,MAAA;AAAA,IAC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,QAAQA,EAAM,UAAU,OAAOA,CAAK;AAAA,MAC9D;AAAA,IAAA;AAAA,EACF;AAAA,EAGM,gBACN3B,IAA4B,IAC5BC,IAAkC,CAAA,GAC1B;AACR,QAAID,EAAS,WAAW,KAAKC,EAAU,WAAW;AACzC,aAAA;AAGT,QAAI6C,IAAY;AAEZ,QAAA9C,EAAS,SAAS,GAAG;AACjB,YAAA+C,IAAiB/C,EACpB,OAAO,CAACgD,MAAQA,EAAI,SAAS,CAAC,EAC9B,IAAI,CAACA,MAAQ;AACZ,cAAMd,IAAYc,EAAI,mBAClB,OAAOA,EAAI,gBAAgB,KAC3B;AACJ,eAAO,GAAGA,EAAI,MAAM,QAAQd,CAAS;AAAA,MAAA,CACtC,EACA,KAAK,IAAI;AAEZ,MAAIa,MACWD,KAAAC;AAAA,IACf;AAGE,QAAA9C,EAAU,SAAS,GAAG;AACpB,MAAAD,EAAS,SAAS,MACP8C,KAAA;AAGf,YAAMG,IAAkBhD,EACrB,OAAO,CAAC+C,MAAQA,EAAI,SAAS,KAAKA,EAAI,OAAO,EAC7C,IAAI,CAACA,MAAQ;AACZ,cAAMd,IAAYc,EAAI,mBAClB,OAAOA,EAAI,gBAAgB,KAC3B;AACJ,eAAO,GAAGA,EAAI,MAAM,aAAaA,EAAI,OAAO,GAAGd,CAAS;AAAA,MAAA,CACzD,EACA,KAAK,IAAI;AAEZ,MAAIe,MACWH,KAAAG;AAAA,IACf;AAGK,WAAAH,MAAc,iBAAiB,KAAKA;AAAA,EAAA;AAE/C;AA5YiB1D,EAAA,wCAAwB,IAAY;AAjE9C,IAAM8D,IAAN9D;"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { HCS10Client } from '../hcs10/HCS10Client';
|
|
2
|
+
import { StructuredTool, ToolParams } from '@langchain/core/tools';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { Logger } from '@hashgraphonline/standards-sdk';
|
|
5
|
+
import { IStateManager } from '../state/state-types';
|
|
6
|
+
export interface ConnectionToolParams extends ToolParams {
|
|
7
|
+
client: HCS10Client;
|
|
8
|
+
stateManager: IStateManager;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* ConnectionTool monitors the *current* agent's inbound topic for connection requests
|
|
12
|
+
* and automatically handles them using the HCS-10 standard SDK flow.
|
|
13
|
+
* Use this ONLY to passively LISTEN for other agents trying to connect TO YOU.
|
|
14
|
+
* This tool takes NO arguments and does NOT start outgoing connections.
|
|
15
|
+
*/
|
|
16
|
+
export declare class ConnectionTool extends StructuredTool {
|
|
17
|
+
name: string;
|
|
18
|
+
description: string;
|
|
19
|
+
client: HCS10Client;
|
|
20
|
+
logger: Logger;
|
|
21
|
+
private stateManager;
|
|
22
|
+
private isMonitoring;
|
|
23
|
+
private monitoringTopic;
|
|
24
|
+
schema: z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
|
|
25
|
+
/**
|
|
26
|
+
* @param client - Instance of HCS10Client.
|
|
27
|
+
* @param stateManager - Instance of StateManager for shared state management.
|
|
28
|
+
*/
|
|
29
|
+
constructor({ client, stateManager, ...rest }: ConnectionToolParams);
|
|
30
|
+
/**
|
|
31
|
+
* Initiates the connection request monitoring process in the background.
|
|
32
|
+
* Gets the inbound topic ID from the configured client.
|
|
33
|
+
*/
|
|
34
|
+
_call(_input: z.infer<typeof this.schema>): Promise<string>;
|
|
35
|
+
/**
|
|
36
|
+
* The core monitoring loop.
|
|
37
|
+
*/
|
|
38
|
+
private monitorIncomingRequests;
|
|
39
|
+
stopMonitoring(): void;
|
|
40
|
+
}
|