keyring-agent-core 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +169 -0
- package/dist/agent/AgentCore.d.ts +220 -0
- package/dist/agent/AgentCore.d.ts.map +1 -0
- package/dist/agent/AgentCore.js +950 -0
- package/dist/agent/AgentCore.js.map +1 -0
- package/dist/agent/QueryRewriter.d.ts +67 -0
- package/dist/agent/QueryRewriter.d.ts.map +1 -0
- package/dist/agent/QueryRewriter.js +262 -0
- package/dist/agent/QueryRewriter.js.map +1 -0
- package/dist/agent/Router.d.ts +33 -0
- package/dist/agent/Router.d.ts.map +1 -0
- package/dist/agent/Router.js +191 -0
- package/dist/agent/Router.js.map +1 -0
- package/dist/agent/Subagent.d.ts +63 -0
- package/dist/agent/Subagent.d.ts.map +1 -0
- package/dist/agent/Subagent.js +240 -0
- package/dist/agent/Subagent.js.map +1 -0
- package/dist/agent/Synthesizer.d.ts +11 -0
- package/dist/agent/Synthesizer.d.ts.map +1 -0
- package/dist/agent/Synthesizer.js +86 -0
- package/dist/agent/Synthesizer.js.map +1 -0
- package/dist/agent/index.d.ts +10 -0
- package/dist/agent/index.d.ts.map +1 -0
- package/dist/agent/index.js +24 -0
- package/dist/agent/index.js.map +1 -0
- package/dist/agent/subagents/AiAgent.d.ts +6 -0
- package/dist/agent/subagents/AiAgent.d.ts.map +1 -0
- package/dist/agent/subagents/AiAgent.js +48 -0
- package/dist/agent/subagents/AiAgent.js.map +1 -0
- package/dist/agent/subagents/NftAgent.d.ts +6 -0
- package/dist/agent/subagents/NftAgent.d.ts.map +1 -0
- package/dist/agent/subagents/NftAgent.js +69 -0
- package/dist/agent/subagents/NftAgent.js.map +1 -0
- package/dist/agent/subagents/PoolAgent.d.ts +6 -0
- package/dist/agent/subagents/PoolAgent.d.ts.map +1 -0
- package/dist/agent/subagents/PoolAgent.js +184 -0
- package/dist/agent/subagents/PoolAgent.js.map +1 -0
- package/dist/agent/subagents/TokenAgent.d.ts +6 -0
- package/dist/agent/subagents/TokenAgent.d.ts.map +1 -0
- package/dist/agent/subagents/TokenAgent.js +75 -0
- package/dist/agent/subagents/TokenAgent.js.map +1 -0
- package/dist/agent/subagents/WalletAgent.d.ts +6 -0
- package/dist/agent/subagents/WalletAgent.d.ts.map +1 -0
- package/dist/agent/subagents/WalletAgent.js +92 -0
- package/dist/agent/subagents/WalletAgent.js.map +1 -0
- package/dist/agent/subagents/index.d.ts +14 -0
- package/dist/agent/subagents/index.d.ts.map +1 -0
- package/dist/agent/subagents/index.js +38 -0
- package/dist/agent/subagents/index.js.map +1 -0
- package/dist/constants/abi.d.ts +520 -0
- package/dist/constants/abi.d.ts.map +1 -0
- package/dist/constants/abi.js +667 -0
- package/dist/constants/abi.js.map +1 -0
- package/dist/functions/pool.d.ts +25 -0
- package/dist/functions/pool.d.ts.map +1 -0
- package/dist/functions/pool.js +151 -0
- package/dist/functions/pool.js.map +1 -0
- package/dist/functions/web3.d.ts +32 -0
- package/dist/functions/web3.d.ts.map +1 -0
- package/dist/functions/web3.js +277 -0
- package/dist/functions/web3.js.map +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +65 -0
- package/dist/index.js.map +1 -0
- package/dist/llm/GeminiProvider.d.ts +16 -0
- package/dist/llm/GeminiProvider.d.ts.map +1 -0
- package/dist/llm/GeminiProvider.js +248 -0
- package/dist/llm/GeminiProvider.js.map +1 -0
- package/dist/llm/index.d.ts +2 -0
- package/dist/llm/index.d.ts.map +1 -0
- package/dist/llm/index.js +6 -0
- package/dist/llm/index.js.map +1 -0
- package/dist/memory/ChatHistory.d.ts +83 -0
- package/dist/memory/ChatHistory.d.ts.map +1 -0
- package/dist/memory/ChatHistory.js +143 -0
- package/dist/memory/ChatHistory.js.map +1 -0
- package/dist/memory/KnowledgeBase.d.ts +38 -0
- package/dist/memory/KnowledgeBase.d.ts.map +1 -0
- package/dist/memory/KnowledgeBase.js +139 -0
- package/dist/memory/KnowledgeBase.js.map +1 -0
- package/dist/memory/Summarizer.d.ts +12 -0
- package/dist/memory/Summarizer.d.ts.map +1 -0
- package/dist/memory/Summarizer.js +39 -0
- package/dist/memory/Summarizer.js.map +1 -0
- package/dist/memory/UpstashKnowledgeBase.d.ts +124 -0
- package/dist/memory/UpstashKnowledgeBase.d.ts.map +1 -0
- package/dist/memory/UpstashKnowledgeBase.js +152 -0
- package/dist/memory/UpstashKnowledgeBase.js.map +1 -0
- package/dist/memory/historyUtils.d.ts +58 -0
- package/dist/memory/historyUtils.d.ts.map +1 -0
- package/dist/memory/historyUtils.js +190 -0
- package/dist/memory/historyUtils.js.map +1 -0
- package/dist/memory/index.d.ts +7 -0
- package/dist/memory/index.d.ts.map +1 -0
- package/dist/memory/index.js +12 -0
- package/dist/memory/index.js.map +1 -0
- package/dist/memory/ingestKnowledgeBase.d.ts +17 -0
- package/dist/memory/ingestKnowledgeBase.d.ts.map +1 -0
- package/dist/memory/ingestKnowledgeBase.js +35 -0
- package/dist/memory/ingestKnowledgeBase.js.map +1 -0
- package/dist/services/MoralisService.d.ts +1350 -0
- package/dist/services/MoralisService.d.ts.map +1 -0
- package/dist/services/MoralisService.js +1364 -0
- package/dist/services/MoralisService.js.map +1 -0
- package/dist/services/PantographService.d.ts +38 -0
- package/dist/services/PantographService.d.ts.map +1 -0
- package/dist/services/PantographService.js +199 -0
- package/dist/services/PantographService.js.map +1 -0
- package/dist/services/PoolService.d.ts +241 -0
- package/dist/services/PoolService.d.ts.map +1 -0
- package/dist/services/PoolService.js +507 -0
- package/dist/services/PoolService.js.map +1 -0
- package/dist/services/UniswapService.d.ts +289 -0
- package/dist/services/UniswapService.d.ts.map +1 -0
- package/dist/services/UniswapService.js +585 -0
- package/dist/services/UniswapService.js.map +1 -0
- package/dist/services/swap/BaseSwapService.d.ts +17 -0
- package/dist/services/swap/BaseSwapService.d.ts.map +1 -0
- package/dist/services/swap/BaseSwapService.js +19 -0
- package/dist/services/swap/BaseSwapService.js.map +1 -0
- package/dist/services/swap/DebridgeAdapter.d.ts +20 -0
- package/dist/services/swap/DebridgeAdapter.d.ts.map +1 -0
- package/dist/services/swap/DebridgeAdapter.js +175 -0
- package/dist/services/swap/DebridgeAdapter.js.map +1 -0
- package/dist/services/swap/RelayAdapter.d.ts +19 -0
- package/dist/services/swap/RelayAdapter.d.ts.map +1 -0
- package/dist/services/swap/RelayAdapter.js +189 -0
- package/dist/services/swap/RelayAdapter.js.map +1 -0
- package/dist/services/swap/SwapServiceFactory.d.ts +24 -0
- package/dist/services/swap/SwapServiceFactory.d.ts.map +1 -0
- package/dist/services/swap/SwapServiceFactory.js +74 -0
- package/dist/services/swap/SwapServiceFactory.js.map +1 -0
- package/dist/services/swap/addresses.d.ts +3 -0
- package/dist/services/swap/addresses.d.ts.map +1 -0
- package/dist/services/swap/addresses.js +68 -0
- package/dist/services/swap/addresses.js.map +1 -0
- package/dist/services/swap/affiliate.d.ts +17 -0
- package/dist/services/swap/affiliate.d.ts.map +1 -0
- package/dist/services/swap/affiliate.js +126 -0
- package/dist/services/swap/affiliate.js.map +1 -0
- package/dist/services/swap/config.d.ts +9 -0
- package/dist/services/swap/config.d.ts.map +1 -0
- package/dist/services/swap/config.js +19 -0
- package/dist/services/swap/config.js.map +1 -0
- package/dist/services/swap/index.d.ts +10 -0
- package/dist/services/swap/index.d.ts.map +1 -0
- package/dist/services/swap/index.js +22 -0
- package/dist/services/swap/index.js.map +1 -0
- package/dist/services/swap/types.d.ts +89 -0
- package/dist/services/swap/types.d.ts.map +1 -0
- package/dist/services/swap/types.js +6 -0
- package/dist/services/swap/types.js.map +1 -0
- package/dist/tools/BaseTool.d.ts +15 -0
- package/dist/tools/BaseTool.d.ts.map +1 -0
- package/dist/tools/BaseTool.js +35 -0
- package/dist/tools/BaseTool.js.map +1 -0
- package/dist/tools/ToolRegistry.d.ts +27 -0
- package/dist/tools/ToolRegistry.d.ts.map +1 -0
- package/dist/tools/ToolRegistry.js +80 -0
- package/dist/tools/ToolRegistry.js.map +1 -0
- package/dist/tools/builtin/ai/MoralisCortexTool.d.ts +33 -0
- package/dist/tools/builtin/ai/MoralisCortexTool.d.ts.map +1 -0
- package/dist/tools/builtin/ai/MoralisCortexTool.js +76 -0
- package/dist/tools/builtin/ai/MoralisCortexTool.js.map +1 -0
- package/dist/tools/builtin/ai/SolanaCortexTool.d.ts +22 -0
- package/dist/tools/builtin/ai/SolanaCortexTool.d.ts.map +1 -0
- package/dist/tools/builtin/ai/SolanaCortexTool.js +80 -0
- package/dist/tools/builtin/ai/SolanaCortexTool.js.map +1 -0
- package/dist/tools/builtin/ai/index.d.ts +5 -0
- package/dist/tools/builtin/ai/index.d.ts.map +1 -0
- package/dist/tools/builtin/ai/index.js +8 -0
- package/dist/tools/builtin/ai/index.js.map +1 -0
- package/dist/tools/builtin/index.d.ts +6 -0
- package/dist/tools/builtin/index.d.ts.map +1 -0
- package/dist/tools/builtin/index.js +22 -0
- package/dist/tools/builtin/index.js.map +1 -0
- package/dist/tools/builtin/nft/NFTContractInfoTool.d.ts +21 -0
- package/dist/tools/builtin/nft/NFTContractInfoTool.d.ts.map +1 -0
- package/dist/tools/builtin/nft/NFTContractInfoTool.js +54 -0
- package/dist/tools/builtin/nft/NFTContractInfoTool.js.map +1 -0
- package/dist/tools/builtin/nft/NFTMetadataTool.d.ts +121 -0
- package/dist/tools/builtin/nft/NFTMetadataTool.d.ts.map +1 -0
- package/dist/tools/builtin/nft/NFTMetadataTool.js +159 -0
- package/dist/tools/builtin/nft/NFTMetadataTool.js.map +1 -0
- package/dist/tools/builtin/nft/WalletNFTsTool.d.ts +82 -0
- package/dist/tools/builtin/nft/WalletNFTsTool.d.ts.map +1 -0
- package/dist/tools/builtin/nft/WalletNFTsTool.js +172 -0
- package/dist/tools/builtin/nft/WalletNFTsTool.js.map +1 -0
- package/dist/tools/builtin/nft/index.d.ts +7 -0
- package/dist/tools/builtin/nft/index.d.ts.map +1 -0
- package/dist/tools/builtin/nft/index.js +10 -0
- package/dist/tools/builtin/nft/index.js.map +1 -0
- package/dist/tools/builtin/pool/EstimatePoolYieldTool.d.ts +124 -0
- package/dist/tools/builtin/pool/EstimatePoolYieldTool.d.ts.map +1 -0
- package/dist/tools/builtin/pool/EstimatePoolYieldTool.js +235 -0
- package/dist/tools/builtin/pool/EstimatePoolYieldTool.js.map +1 -0
- package/dist/tools/builtin/pool/OpenAddLiquidityFormTool.d.ts +127 -0
- package/dist/tools/builtin/pool/OpenAddLiquidityFormTool.d.ts.map +1 -0
- package/dist/tools/builtin/pool/OpenAddLiquidityFormTool.js +517 -0
- package/dist/tools/builtin/pool/OpenAddLiquidityFormTool.js.map +1 -0
- package/dist/tools/builtin/pool/PoolByAddressTool.d.ts +127 -0
- package/dist/tools/builtin/pool/PoolByAddressTool.d.ts.map +1 -0
- package/dist/tools/builtin/pool/PoolByAddressTool.js +237 -0
- package/dist/tools/builtin/pool/PoolByAddressTool.js.map +1 -0
- package/dist/tools/builtin/pool/PoolDetailTool.d.ts +127 -0
- package/dist/tools/builtin/pool/PoolDetailTool.d.ts.map +1 -0
- package/dist/tools/builtin/pool/PoolDetailTool.js +272 -0
- package/dist/tools/builtin/pool/PoolDetailTool.js.map +1 -0
- package/dist/tools/builtin/pool/PoolSearchTool.d.ts +50 -0
- package/dist/tools/builtin/pool/PoolSearchTool.d.ts.map +1 -0
- package/dist/tools/builtin/pool/PoolSearchTool.js +159 -0
- package/dist/tools/builtin/pool/PoolSearchTool.js.map +1 -0
- package/dist/tools/builtin/pool/PreviewAddLiquidityTool.d.ts +123 -0
- package/dist/tools/builtin/pool/PreviewAddLiquidityTool.d.ts.map +1 -0
- package/dist/tools/builtin/pool/PreviewAddLiquidityTool.js +380 -0
- package/dist/tools/builtin/pool/PreviewAddLiquidityTool.js.map +1 -0
- package/dist/tools/builtin/pool/TopPoolsTool.d.ts +68 -0
- package/dist/tools/builtin/pool/TopPoolsTool.d.ts.map +1 -0
- package/dist/tools/builtin/pool/TopPoolsTool.js +158 -0
- package/dist/tools/builtin/pool/TopPoolsTool.js.map +1 -0
- package/dist/tools/builtin/pool/index.d.ts +15 -0
- package/dist/tools/builtin/pool/index.d.ts.map +1 -0
- package/dist/tools/builtin/pool/index.js +18 -0
- package/dist/tools/builtin/pool/index.js.map +1 -0
- package/dist/tools/builtin/token/TokenAnalyticsTool.d.ts +71 -0
- package/dist/tools/builtin/token/TokenAnalyticsTool.d.ts.map +1 -0
- package/dist/tools/builtin/token/TokenAnalyticsTool.js +146 -0
- package/dist/tools/builtin/token/TokenAnalyticsTool.js.map +1 -0
- package/dist/tools/builtin/token/TokenHoldersTool.d.ts +81 -0
- package/dist/tools/builtin/token/TokenHoldersTool.d.ts.map +1 -0
- package/dist/tools/builtin/token/TokenHoldersTool.js +138 -0
- package/dist/tools/builtin/token/TokenHoldersTool.js.map +1 -0
- package/dist/tools/builtin/token/TokenInfoTool.d.ts +36 -0
- package/dist/tools/builtin/token/TokenInfoTool.d.ts.map +1 -0
- package/dist/tools/builtin/token/TokenInfoTool.js +163 -0
- package/dist/tools/builtin/token/TokenInfoTool.js.map +1 -0
- package/dist/tools/builtin/token/TokenScoreTool.d.ts +63 -0
- package/dist/tools/builtin/token/TokenScoreTool.d.ts.map +1 -0
- package/dist/tools/builtin/token/TokenScoreTool.js +147 -0
- package/dist/tools/builtin/token/TokenScoreTool.js.map +1 -0
- package/dist/tools/builtin/token/TopGainersTool.d.ts +46 -0
- package/dist/tools/builtin/token/TopGainersTool.d.ts.map +1 -0
- package/dist/tools/builtin/token/TopGainersTool.js +110 -0
- package/dist/tools/builtin/token/TopGainersTool.js.map +1 -0
- package/dist/tools/builtin/token/TopLosersTool.d.ts +66 -0
- package/dist/tools/builtin/token/TopLosersTool.d.ts.map +1 -0
- package/dist/tools/builtin/token/TopLosersTool.js +128 -0
- package/dist/tools/builtin/token/TopLosersTool.js.map +1 -0
- package/dist/tools/builtin/token/TrendingTokensTool.d.ts +39 -0
- package/dist/tools/builtin/token/TrendingTokensTool.d.ts.map +1 -0
- package/dist/tools/builtin/token/TrendingTokensTool.js +75 -0
- package/dist/tools/builtin/token/TrendingTokensTool.js.map +1 -0
- package/dist/tools/builtin/token/index.d.ts +15 -0
- package/dist/tools/builtin/token/index.d.ts.map +1 -0
- package/dist/tools/builtin/token/index.js +18 -0
- package/dist/tools/builtin/token/index.js.map +1 -0
- package/dist/tools/builtin/wallet/TransactionByHashTool.d.ts +70 -0
- package/dist/tools/builtin/wallet/TransactionByHashTool.d.ts.map +1 -0
- package/dist/tools/builtin/wallet/TransactionByHashTool.js +110 -0
- package/dist/tools/builtin/wallet/TransactionByHashTool.js.map +1 -0
- package/dist/tools/builtin/wallet/WalletApprovalsTool.d.ts +107 -0
- package/dist/tools/builtin/wallet/WalletApprovalsTool.d.ts.map +1 -0
- package/dist/tools/builtin/wallet/WalletApprovalsTool.js +163 -0
- package/dist/tools/builtin/wallet/WalletApprovalsTool.js.map +1 -0
- package/dist/tools/builtin/wallet/WalletDefiPositionsTool.d.ts +61 -0
- package/dist/tools/builtin/wallet/WalletDefiPositionsTool.d.ts.map +1 -0
- package/dist/tools/builtin/wallet/WalletDefiPositionsTool.js +99 -0
- package/dist/tools/builtin/wallet/WalletDefiPositionsTool.js.map +1 -0
- package/dist/tools/builtin/wallet/WalletDefiProtocolPositionsTool.d.ts +68 -0
- package/dist/tools/builtin/wallet/WalletDefiProtocolPositionsTool.d.ts.map +1 -0
- package/dist/tools/builtin/wallet/WalletDefiProtocolPositionsTool.js +114 -0
- package/dist/tools/builtin/wallet/WalletDefiProtocolPositionsTool.js.map +1 -0
- package/dist/tools/builtin/wallet/WalletDefiSummaryTool.d.ts +50 -0
- package/dist/tools/builtin/wallet/WalletDefiSummaryTool.d.ts.map +1 -0
- package/dist/tools/builtin/wallet/WalletDefiSummaryTool.js +79 -0
- package/dist/tools/builtin/wallet/WalletDefiSummaryTool.js.map +1 -0
- package/dist/tools/builtin/wallet/WalletHistoryTool.d.ts +31 -0
- package/dist/tools/builtin/wallet/WalletHistoryTool.d.ts.map +1 -0
- package/dist/tools/builtin/wallet/WalletHistoryTool.js +153 -0
- package/dist/tools/builtin/wallet/WalletHistoryTool.js.map +1 -0
- package/dist/tools/builtin/wallet/WalletNetWorthTool.d.ts +44 -0
- package/dist/tools/builtin/wallet/WalletNetWorthTool.d.ts.map +1 -0
- package/dist/tools/builtin/wallet/WalletNetWorthTool.js +122 -0
- package/dist/tools/builtin/wallet/WalletNetWorthTool.js.map +1 -0
- package/dist/tools/builtin/wallet/WalletNftTransfersTool.d.ts +86 -0
- package/dist/tools/builtin/wallet/WalletNftTransfersTool.d.ts.map +1 -0
- package/dist/tools/builtin/wallet/WalletNftTransfersTool.js +264 -0
- package/dist/tools/builtin/wallet/WalletNftTransfersTool.js.map +1 -0
- package/dist/tools/builtin/wallet/WalletPnlSummaryTool.d.ts +43 -0
- package/dist/tools/builtin/wallet/WalletPnlSummaryTool.d.ts.map +1 -0
- package/dist/tools/builtin/wallet/WalletPnlSummaryTool.js +88 -0
- package/dist/tools/builtin/wallet/WalletPnlSummaryTool.js.map +1 -0
- package/dist/tools/builtin/wallet/WalletPnlTool.d.ts +43 -0
- package/dist/tools/builtin/wallet/WalletPnlTool.d.ts.map +1 -0
- package/dist/tools/builtin/wallet/WalletPnlTool.js +174 -0
- package/dist/tools/builtin/wallet/WalletPnlTool.js.map +1 -0
- package/dist/tools/builtin/wallet/WalletTokenBalancesTool.d.ts +35 -0
- package/dist/tools/builtin/wallet/WalletTokenBalancesTool.d.ts.map +1 -0
- package/dist/tools/builtin/wallet/WalletTokenBalancesTool.js +67 -0
- package/dist/tools/builtin/wallet/WalletTokenBalancesTool.js.map +1 -0
- package/dist/tools/builtin/wallet/WalletTokenTransfersTool.d.ts +109 -0
- package/dist/tools/builtin/wallet/WalletTokenTransfersTool.d.ts.map +1 -0
- package/dist/tools/builtin/wallet/WalletTokenTransfersTool.js +353 -0
- package/dist/tools/builtin/wallet/WalletTokenTransfersTool.js.map +1 -0
- package/dist/tools/builtin/wallet/index.d.ts +25 -0
- package/dist/tools/builtin/wallet/index.d.ts.map +1 -0
- package/dist/tools/builtin/wallet/index.js +28 -0
- package/dist/tools/builtin/wallet/index.js.map +1 -0
- package/dist/tools/index.d.ts +4 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +23 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/types/index.d.ts +566 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +6 -0
- package/dist/types/index.js.map +1 -0
- package/package.json +52 -0
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getProviderByChain = getProviderByChain;
|
|
4
|
+
exports.getAffiliateFee = getAffiliateFee;
|
|
5
|
+
const AFFILIATE_SETTING_URL = 'https://exchange-api.keyring.app/admin/setting?configs=others';
|
|
6
|
+
const PROVIDER_MAP_URL_PROD = 'https://api.coinpool.app/config/bridgeProviderByChain';
|
|
7
|
+
const PROVIDER_MAP_URL_DEV = 'https://coinpool-api-op.bacoor-test001.xyz/config/bridgeProviderByChain';
|
|
8
|
+
function memoize(loader) {
|
|
9
|
+
let cached = null;
|
|
10
|
+
let pending = null;
|
|
11
|
+
return async () => {
|
|
12
|
+
if (cached)
|
|
13
|
+
return cached;
|
|
14
|
+
if (pending)
|
|
15
|
+
return pending;
|
|
16
|
+
pending = (async () => {
|
|
17
|
+
try {
|
|
18
|
+
const result = await loader();
|
|
19
|
+
cached = result;
|
|
20
|
+
return cached;
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
finally {
|
|
26
|
+
pending = null;
|
|
27
|
+
}
|
|
28
|
+
})();
|
|
29
|
+
return pending;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
async function fetchJson(url) {
|
|
33
|
+
const res = await fetch(url, {
|
|
34
|
+
method: 'GET',
|
|
35
|
+
headers: { Accept: 'application/json' },
|
|
36
|
+
});
|
|
37
|
+
return (await res.json());
|
|
38
|
+
}
|
|
39
|
+
const fetchAffiliateOthers = memoize(async () => {
|
|
40
|
+
const json = await fetchJson(AFFILIATE_SETTING_URL);
|
|
41
|
+
return json?.others ?? null;
|
|
42
|
+
});
|
|
43
|
+
const providerMapCache = {
|
|
44
|
+
prod: null,
|
|
45
|
+
dev: null,
|
|
46
|
+
};
|
|
47
|
+
const providerMapPending = { prod: null, dev: null };
|
|
48
|
+
async function fetchProviderMap(isProduction) {
|
|
49
|
+
const key = isProduction ? 'prod' : 'dev';
|
|
50
|
+
if (providerMapCache[key])
|
|
51
|
+
return providerMapCache[key];
|
|
52
|
+
if (providerMapPending[key])
|
|
53
|
+
return providerMapPending[key];
|
|
54
|
+
const url = isProduction ? PROVIDER_MAP_URL_PROD : PROVIDER_MAP_URL_DEV;
|
|
55
|
+
providerMapPending[key] = (async () => {
|
|
56
|
+
try {
|
|
57
|
+
const json = await fetchJson(url);
|
|
58
|
+
providerMapCache[key] = json?.data ?? null;
|
|
59
|
+
return providerMapCache[key];
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
finally {
|
|
65
|
+
providerMapPending[key] = null;
|
|
66
|
+
}
|
|
67
|
+
})();
|
|
68
|
+
return providerMapPending[key];
|
|
69
|
+
}
|
|
70
|
+
function parseRecipientMap(raw) {
|
|
71
|
+
if (!raw)
|
|
72
|
+
return null;
|
|
73
|
+
try {
|
|
74
|
+
const parsed = JSON.parse(raw);
|
|
75
|
+
return parsed && typeof parsed === 'object' ? parsed : null;
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function toPercent(value) {
|
|
82
|
+
if (value === undefined || value === null)
|
|
83
|
+
return 0;
|
|
84
|
+
const n = typeof value === 'number' ? value : Number(value);
|
|
85
|
+
return Number.isFinite(n) ? n : 0;
|
|
86
|
+
}
|
|
87
|
+
function isProviderName(value) {
|
|
88
|
+
return value === 'debridge' || value === 'relay';
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Returns the active provider for `chainId` from the coinpool config API, or
|
|
92
|
+
* `null` when the API is unreachable or the chain has no mapping (caller should
|
|
93
|
+
* fall back to a default).
|
|
94
|
+
*/
|
|
95
|
+
async function getProviderByChain(chainId, isProduction) {
|
|
96
|
+
const map = await fetchProviderMap(isProduction);
|
|
97
|
+
const candidate = map?.[String(chainId)];
|
|
98
|
+
return isProviderName(candidate) ? candidate : null;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Returns the affiliate fee tuple for the given provider+chain, or `null` when
|
|
102
|
+
* no fee should be attached (missing recipient or percent <= 0).
|
|
103
|
+
*/
|
|
104
|
+
async function getAffiliateFee(provider, chainId) {
|
|
105
|
+
const others = await fetchAffiliateOthers();
|
|
106
|
+
if (!others)
|
|
107
|
+
return null;
|
|
108
|
+
let recipient;
|
|
109
|
+
let percent;
|
|
110
|
+
if (provider === 'debridge') {
|
|
111
|
+
const map = parseRecipientMap(others.affiliateRecipient);
|
|
112
|
+
recipient = map?.[String(chainId)];
|
|
113
|
+
percent = toPercent(others.AFFILIATE_FEE_PERENT);
|
|
114
|
+
}
|
|
115
|
+
else if (provider === 'relay') {
|
|
116
|
+
recipient = others.RELAY_AFFILIATE_FEE_RECIPIENT;
|
|
117
|
+
percent = toPercent(others.RELAY_AFFILIATE_FEE_PERCENT);
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
if (!recipient || percent <= 0)
|
|
123
|
+
return null;
|
|
124
|
+
return { affiliateFeeRecipient: recipient, affiliateFeePercent: percent };
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=affiliate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"affiliate.js","sourceRoot":"","sources":["../../../src/services/swap/affiliate.ts"],"names":[],"mappings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AAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;QACnC,OAAO,GAAG,SAAS,CAAC,MAAM,CAAC,oBAAoB,CAAC,CAAC;IACnD,CAAC;SAAM,IAAI,QAAQ,KAAK,OAAO,EAAE,CAAC;QAChC,SAAS,GAAG,MAAM,CAAC,6BAA6B,CAAC;QACjD,OAAO,GAAG,SAAS,CAAC,MAAM,CAAC,2BAA2B,CAAC,CAAC;IAC1D,CAAC;SAAM,CAAC;QACN,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,CAAC,SAAS,IAAI,OAAO,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IAE5C,OAAO,EAAE,qBAAqB,EAAE,SAAS,EAAE,mBAAmB,EAAE,OAAO,EAAE,CAAC;AAC5E,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ExchangeProviderConfig, ProviderName } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Per-provider client config. The active provider for a given chain is decided
|
|
4
|
+
* at runtime by the exchange settings API (`bridgeProviderByChain`); this map
|
|
5
|
+
* only holds connection-level config (base URLs, tokens) for each provider.
|
|
6
|
+
*/
|
|
7
|
+
export declare const SWAP_PROVIDER_CONFIG: ExchangeProviderConfig;
|
|
8
|
+
export declare const DEFAULT_PROVIDER: ProviderName;
|
|
9
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/services/swap/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEpE;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,EAAE,sBAQlC,CAAC;AAEF,eAAO,MAAM,gBAAgB,EAAE,YAAyB,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_PROVIDER = exports.SWAP_PROVIDER_CONFIG = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Per-provider client config. The active provider for a given chain is decided
|
|
6
|
+
* at runtime by the exchange settings API (`bridgeProviderByChain`); this map
|
|
7
|
+
* only holds connection-level config (base URLs, tokens) for each provider.
|
|
8
|
+
*/
|
|
9
|
+
exports.SWAP_PROVIDER_CONFIG = {
|
|
10
|
+
debridge: {
|
|
11
|
+
apiBaseUrl: 'https://dln.debridge.finance/v1.0',
|
|
12
|
+
accessToken: 'd6c45897b8f6',
|
|
13
|
+
},
|
|
14
|
+
relay: {
|
|
15
|
+
apiBaseUrl: 'https://api.relay.link',
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
exports.DEFAULT_PROVIDER = 'debridge';
|
|
19
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/services/swap/config.ts"],"names":[],"mappings":";;;AAEA;;;;GAIG;AACU,QAAA,oBAAoB,GAA2B;IAC1D,QAAQ,EAAE;QACR,UAAU,EAAE,mCAAmC;QAC/C,WAAW,EAAE,cAAc;KAC5B;IACD,KAAK,EAAE;QACL,UAAU,EAAE,wBAAwB;KACrC;CACF,CAAC;AAEW,QAAA,gBAAgB,GAAiB,UAAU,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { BaseSwapService } from './BaseSwapService';
|
|
2
|
+
export { DebridgeAdapter } from './DebridgeAdapter';
|
|
3
|
+
export { RelayAdapter } from './RelayAdapter';
|
|
4
|
+
export { SwapServiceFactory, swapServiceFactory } from './SwapServiceFactory';
|
|
5
|
+
export { SWAP_PROVIDER_CONFIG, DEFAULT_PROVIDER } from './config';
|
|
6
|
+
export { getAffiliateFee, getProviderByChain } from './affiliate';
|
|
7
|
+
export type { AffiliateFee } from './affiliate';
|
|
8
|
+
export { getGatewayAddress, getPositionManagerAddress } from './addresses';
|
|
9
|
+
export type { CheckApprovalParams, CheckApprovalResult, ExchangeProviderConfig, ExecuteSwapParams, ExecuteSwapResult, ProviderName, SwapQuoteParams, SwapQuoteResult, SwapServiceConfig, SwapTxData, TrackStatus, TrackTransactionParams, TrackTransactionResult, } from './types';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/swap/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC9E,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAClE,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAClE,YAAY,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,iBAAiB,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AAC3E,YAAY,EACV,mBAAmB,EACnB,mBAAmB,EACnB,sBAAsB,EACtB,iBAAiB,EACjB,iBAAiB,EACjB,YAAY,EACZ,eAAe,EACf,eAAe,EACf,iBAAiB,EACjB,UAAU,EACV,WAAW,EACX,sBAAsB,EACtB,sBAAsB,GACvB,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPositionManagerAddress = exports.getGatewayAddress = exports.getProviderByChain = exports.getAffiliateFee = exports.DEFAULT_PROVIDER = exports.SWAP_PROVIDER_CONFIG = exports.swapServiceFactory = exports.SwapServiceFactory = exports.RelayAdapter = exports.DebridgeAdapter = exports.BaseSwapService = void 0;
|
|
4
|
+
var BaseSwapService_1 = require("./BaseSwapService");
|
|
5
|
+
Object.defineProperty(exports, "BaseSwapService", { enumerable: true, get: function () { return BaseSwapService_1.BaseSwapService; } });
|
|
6
|
+
var DebridgeAdapter_1 = require("./DebridgeAdapter");
|
|
7
|
+
Object.defineProperty(exports, "DebridgeAdapter", { enumerable: true, get: function () { return DebridgeAdapter_1.DebridgeAdapter; } });
|
|
8
|
+
var RelayAdapter_1 = require("./RelayAdapter");
|
|
9
|
+
Object.defineProperty(exports, "RelayAdapter", { enumerable: true, get: function () { return RelayAdapter_1.RelayAdapter; } });
|
|
10
|
+
var SwapServiceFactory_1 = require("./SwapServiceFactory");
|
|
11
|
+
Object.defineProperty(exports, "SwapServiceFactory", { enumerable: true, get: function () { return SwapServiceFactory_1.SwapServiceFactory; } });
|
|
12
|
+
Object.defineProperty(exports, "swapServiceFactory", { enumerable: true, get: function () { return SwapServiceFactory_1.swapServiceFactory; } });
|
|
13
|
+
var config_1 = require("./config");
|
|
14
|
+
Object.defineProperty(exports, "SWAP_PROVIDER_CONFIG", { enumerable: true, get: function () { return config_1.SWAP_PROVIDER_CONFIG; } });
|
|
15
|
+
Object.defineProperty(exports, "DEFAULT_PROVIDER", { enumerable: true, get: function () { return config_1.DEFAULT_PROVIDER; } });
|
|
16
|
+
var affiliate_1 = require("./affiliate");
|
|
17
|
+
Object.defineProperty(exports, "getAffiliateFee", { enumerable: true, get: function () { return affiliate_1.getAffiliateFee; } });
|
|
18
|
+
Object.defineProperty(exports, "getProviderByChain", { enumerable: true, get: function () { return affiliate_1.getProviderByChain; } });
|
|
19
|
+
var addresses_1 = require("./addresses");
|
|
20
|
+
Object.defineProperty(exports, "getGatewayAddress", { enumerable: true, get: function () { return addresses_1.getGatewayAddress; } });
|
|
21
|
+
Object.defineProperty(exports, "getPositionManagerAddress", { enumerable: true, get: function () { return addresses_1.getPositionManagerAddress; } });
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/services/swap/index.ts"],"names":[],"mappings":";;;AAAA,qDAAoD;AAA3C,kHAAA,eAAe,OAAA;AACxB,qDAAoD;AAA3C,kHAAA,eAAe,OAAA;AACxB,+CAA8C;AAArC,4GAAA,YAAY,OAAA;AACrB,2DAA8E;AAArE,wHAAA,kBAAkB,OAAA;AAAE,wHAAA,kBAAkB,OAAA;AAC/C,mCAAkE;AAAzD,8GAAA,oBAAoB,OAAA;AAAE,0GAAA,gBAAgB,OAAA;AAC/C,yCAAkE;AAAzD,4GAAA,eAAe,OAAA;AAAE,+GAAA,kBAAkB,OAAA;AAE5C,yCAA2E;AAAlE,8GAAA,iBAAiB,OAAA;AAAE,sHAAA,yBAAyB,OAAA"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared types for swap/bridge service providers.
|
|
3
|
+
*/
|
|
4
|
+
export type ProviderName = 'debridge' | 'relay';
|
|
5
|
+
export interface SwapQuoteParams {
|
|
6
|
+
srcChainId: number | string;
|
|
7
|
+
srcTokenAddress: string;
|
|
8
|
+
srcTokenAmount: string;
|
|
9
|
+
dstChainId: number | string;
|
|
10
|
+
dstTokenAddress: string;
|
|
11
|
+
recipientAddress: string;
|
|
12
|
+
senderAddress: string;
|
|
13
|
+
/**
|
|
14
|
+
* Slippage tolerance. Either a percent (e.g. 0.5 for 0.5%) or the literal
|
|
15
|
+
* 'auto' — adapters decide what 'auto' means (deBridge forwards it; Relay
|
|
16
|
+
* falls back to its server-side default).
|
|
17
|
+
*/
|
|
18
|
+
slippage?: number | 'auto';
|
|
19
|
+
isCrossChain?: boolean;
|
|
20
|
+
isHasAffiliate?: boolean;
|
|
21
|
+
}
|
|
22
|
+
export interface SwapTxData {
|
|
23
|
+
from?: string;
|
|
24
|
+
to?: string;
|
|
25
|
+
data?: string | {
|
|
26
|
+
instructions: unknown[];
|
|
27
|
+
addressLookupTableAddresses?: string[];
|
|
28
|
+
};
|
|
29
|
+
value?: string;
|
|
30
|
+
chainId?: number | string;
|
|
31
|
+
maxFeePerGas?: string;
|
|
32
|
+
maxPriorityFeePerGas?: string;
|
|
33
|
+
}
|
|
34
|
+
export interface SwapQuoteResult {
|
|
35
|
+
success: boolean;
|
|
36
|
+
provider?: ProviderName;
|
|
37
|
+
tx?: SwapTxData | null;
|
|
38
|
+
estimation?: Record<string, unknown>;
|
|
39
|
+
isCrossChain?: boolean;
|
|
40
|
+
srcChainId?: number | string;
|
|
41
|
+
dstChainId?: number | string;
|
|
42
|
+
error?: unknown;
|
|
43
|
+
errorMessage?: string;
|
|
44
|
+
/** Provider-specific raw payload — consumers can read additional fields here. */
|
|
45
|
+
raw?: Record<string, unknown>;
|
|
46
|
+
}
|
|
47
|
+
export interface CheckApprovalParams {
|
|
48
|
+
chain?: string;
|
|
49
|
+
userAddress: string;
|
|
50
|
+
tokenAddress: string;
|
|
51
|
+
amount: string;
|
|
52
|
+
tokenDecimals: number;
|
|
53
|
+
quoteData: SwapQuoteResult;
|
|
54
|
+
}
|
|
55
|
+
export interface CheckApprovalResult {
|
|
56
|
+
isNeeded: boolean;
|
|
57
|
+
integrated?: boolean;
|
|
58
|
+
contractAddress?: string;
|
|
59
|
+
approvalData?: unknown;
|
|
60
|
+
message?: string;
|
|
61
|
+
error?: string;
|
|
62
|
+
}
|
|
63
|
+
export interface ExecuteSwapParams {
|
|
64
|
+
quoteData: SwapQuoteResult;
|
|
65
|
+
}
|
|
66
|
+
export interface ExecuteSwapResult {
|
|
67
|
+
success: boolean;
|
|
68
|
+
provider?: ProviderName;
|
|
69
|
+
txData?: SwapTxData;
|
|
70
|
+
steps?: unknown[];
|
|
71
|
+
estimation?: Record<string, unknown>;
|
|
72
|
+
error?: string;
|
|
73
|
+
}
|
|
74
|
+
export interface TrackTransactionParams {
|
|
75
|
+
requestIdOrTxHash: string;
|
|
76
|
+
}
|
|
77
|
+
export type TrackStatus = 'PENDING' | 'COMPLETED' | 'FAILED' | 'ERROR';
|
|
78
|
+
export interface TrackTransactionResult {
|
|
79
|
+
success: boolean;
|
|
80
|
+
status: TrackStatus;
|
|
81
|
+
error?: string;
|
|
82
|
+
}
|
|
83
|
+
export interface SwapServiceConfig {
|
|
84
|
+
apiBaseUrl?: string;
|
|
85
|
+
apiKey?: string;
|
|
86
|
+
accessToken?: string;
|
|
87
|
+
}
|
|
88
|
+
export type ExchangeProviderConfig = Record<ProviderName, SwapServiceConfig>;
|
|
89
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/services/swap/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,MAAM,YAAY,GAAG,UAAU,GAAG,OAAO,CAAC;AAEhD,MAAM,WAAW,eAAe;IAC9B,UAAU,EAAE,MAAM,GAAG,MAAM,CAAC;IAC5B,eAAe,EAAE,MAAM,CAAC;IACxB,cAAc,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,MAAM,GAAG,MAAM,CAAC;IAC5B,eAAe,EAAE,MAAM,CAAC;IACxB,gBAAgB,EAAE,MAAM,CAAC;IACzB,aAAa,EAAE,MAAM,CAAC;IACtB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC3B,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,GAAG;QAAE,YAAY,EAAE,OAAO,EAAE,CAAC;QAAC,2BAA2B,CAAC,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC;IACpF,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,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B,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB,KAAK,CAAC,EAAE,OAAO,EAAE,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,sBAAsB;IACrC,iBAAiB,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG,WAAW,GAAG,QAAQ,GAAG,OAAO,CAAC;AAEvE,MAAM,WAAW,sBAAsB;IACrC,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,WAAW,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,iBAAiB;IAChC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,MAAM,sBAAsB,GAAG,MAAM,CAAC,YAAY,EAAE,iBAAiB,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/services/swap/types.ts"],"names":[],"mappings":";AAAA;;GAEG"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Tool, ToolParameter, ToolResult, UserContext } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Convenience base class for building tools.
|
|
4
|
+
* Consumers extend this and implement `run()`.
|
|
5
|
+
*/
|
|
6
|
+
export declare abstract class BaseTool implements Tool {
|
|
7
|
+
abstract name: string;
|
|
8
|
+
abstract description: string;
|
|
9
|
+
abstract parameters: ToolParameter[];
|
|
10
|
+
category?: string;
|
|
11
|
+
/** Implement the actual tool logic here. */
|
|
12
|
+
protected abstract run(args: Record<string, unknown>, userContext?: UserContext): Promise<unknown>;
|
|
13
|
+
execute(args: Record<string, unknown>, userContext?: UserContext): Promise<ToolResult>;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=BaseTool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BaseTool.d.ts","sourceRoot":"","sources":["../../src/tools/BaseTool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAE7E;;;GAGG;AACH,8BAAsB,QAAS,YAAW,IAAI;IAC5C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,UAAU,EAAE,aAAa,EAAE,CAAC;IACrC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,4CAA4C;IAC5C,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC;IAE5F,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC;CAsB7F"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseTool = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Convenience base class for building tools.
|
|
6
|
+
* Consumers extend this and implement `run()`.
|
|
7
|
+
*/
|
|
8
|
+
class BaseTool {
|
|
9
|
+
category;
|
|
10
|
+
async execute(args, userContext) {
|
|
11
|
+
const callId = `call_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;
|
|
12
|
+
const start = Date.now();
|
|
13
|
+
try {
|
|
14
|
+
const data = await this.run(args, userContext);
|
|
15
|
+
return {
|
|
16
|
+
toolName: this.name,
|
|
17
|
+
callId,
|
|
18
|
+
success: true,
|
|
19
|
+
data,
|
|
20
|
+
duration: Date.now() - start,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
catch (err) {
|
|
24
|
+
return {
|
|
25
|
+
toolName: this.name,
|
|
26
|
+
callId,
|
|
27
|
+
success: false,
|
|
28
|
+
error: err instanceof Error ? err.message : String(err),
|
|
29
|
+
duration: Date.now() - start,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.BaseTool = BaseTool;
|
|
35
|
+
//# sourceMappingURL=BaseTool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BaseTool.js","sourceRoot":"","sources":["../../src/tools/BaseTool.ts"],"names":[],"mappings":";;;AAEA;;;GAGG;AACH,MAAsB,QAAQ;IAI5B,QAAQ,CAAU;IAKlB,KAAK,CAAC,OAAO,CAAC,IAA6B,EAAE,WAAyB;QACpE,MAAM,MAAM,GAAG,QAAQ,IAAI,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;QAC9E,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACzB,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;YAC/C,OAAO;gBACL,QAAQ,EAAE,IAAI,CAAC,IAAI;gBACnB,MAAM;gBACN,OAAO,EAAE,IAAI;gBACb,IAAI;gBACJ,QAAQ,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK;aAC7B,CAAC;QACJ,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO;gBACL,QAAQ,EAAE,IAAI,CAAC,IAAI;gBACnB,MAAM;gBACN,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC;gBACvD,QAAQ,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK;aAC7B,CAAC;QACJ,CAAC;IACH,CAAC;CACF;AA/BD,4BA+BC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Tool, ToolDefinition, ToolResult, UserContext } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Registry that holds all available tools.
|
|
4
|
+
* Consumer registers tools here; the Router and Subagents query the registry.
|
|
5
|
+
*/
|
|
6
|
+
export declare class ToolRegistry {
|
|
7
|
+
private tools;
|
|
8
|
+
/** Register a tool. Throws if a tool with the same name already exists. */
|
|
9
|
+
register(tool: Tool): void;
|
|
10
|
+
/** Unregister a tool by name. */
|
|
11
|
+
unregister(name: string): boolean;
|
|
12
|
+
/** Get a tool by name. */
|
|
13
|
+
get(name: string): Tool | undefined;
|
|
14
|
+
/** Check if a tool exists. */
|
|
15
|
+
has(name: string): boolean;
|
|
16
|
+
/** Return definitions of all registered tools (used for LLM function calling). */
|
|
17
|
+
getDefinitions(): ToolDefinition[];
|
|
18
|
+
/** Return definitions filtered by category. */
|
|
19
|
+
getDefinitionsByCategory(category: string): ToolDefinition[];
|
|
20
|
+
/** Execute a tool by name. Returns an error ToolResult if the tool is not found. */
|
|
21
|
+
execute(name: string, args: Record<string, unknown>, userContext?: UserContext): Promise<ToolResult>;
|
|
22
|
+
/** Number of registered tools. */
|
|
23
|
+
get size(): number;
|
|
24
|
+
/** List all registered tool names. */
|
|
25
|
+
listNames(): string[];
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=ToolRegistry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ToolRegistry.d.ts","sourceRoot":"","sources":["../../src/tools/ToolRegistry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,cAAc,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAE9E;;;GAGG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,KAAK,CAA2B;IAExC,2EAA2E;IAC3E,QAAQ,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI;IAO1B,iCAAiC;IACjC,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAIjC,0BAA0B;IAC1B,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS;IAInC,8BAA8B;IAC9B,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAI1B,kFAAkF;IAClF,cAAc,IAAI,cAAc,EAAE;IAUlC,+CAA+C;IAC/C,wBAAwB,CAAC,QAAQ,EAAE,MAAM,GAAG,cAAc,EAAE;IAI5D,oFAAoF;IAC9E,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC;IA2B1G,kCAAkC;IAClC,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,sCAAsC;IACtC,SAAS,IAAI,MAAM,EAAE;CAGtB"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ToolRegistry = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Registry that holds all available tools.
|
|
6
|
+
* Consumer registers tools here; the Router and Subagents query the registry.
|
|
7
|
+
*/
|
|
8
|
+
class ToolRegistry {
|
|
9
|
+
tools = new Map();
|
|
10
|
+
/** Register a tool. Throws if a tool with the same name already exists. */
|
|
11
|
+
register(tool) {
|
|
12
|
+
if (this.tools.has(tool.name)) {
|
|
13
|
+
throw new Error(`Tool "${tool.name}" is already registered`);
|
|
14
|
+
}
|
|
15
|
+
this.tools.set(tool.name, tool);
|
|
16
|
+
}
|
|
17
|
+
/** Unregister a tool by name. */
|
|
18
|
+
unregister(name) {
|
|
19
|
+
return this.tools.delete(name);
|
|
20
|
+
}
|
|
21
|
+
/** Get a tool by name. */
|
|
22
|
+
get(name) {
|
|
23
|
+
return this.tools.get(name);
|
|
24
|
+
}
|
|
25
|
+
/** Check if a tool exists. */
|
|
26
|
+
has(name) {
|
|
27
|
+
return this.tools.has(name);
|
|
28
|
+
}
|
|
29
|
+
/** Return definitions of all registered tools (used for LLM function calling). */
|
|
30
|
+
getDefinitions() {
|
|
31
|
+
return Array.from(this.tools.values()).map((t) => ({
|
|
32
|
+
name: t.name,
|
|
33
|
+
description: t.description,
|
|
34
|
+
parameters: t.parameters,
|
|
35
|
+
category: t.category,
|
|
36
|
+
kind: t.kind,
|
|
37
|
+
}));
|
|
38
|
+
}
|
|
39
|
+
/** Return definitions filtered by category. */
|
|
40
|
+
getDefinitionsByCategory(category) {
|
|
41
|
+
return this.getDefinitions().filter((d) => d.category === category);
|
|
42
|
+
}
|
|
43
|
+
/** Execute a tool by name. Returns an error ToolResult if the tool is not found. */
|
|
44
|
+
async execute(name, args, userContext) {
|
|
45
|
+
const tool = this.tools.get(name);
|
|
46
|
+
if (!tool) {
|
|
47
|
+
return {
|
|
48
|
+
toolName: name,
|
|
49
|
+
callId: `err_${Date.now()}`,
|
|
50
|
+
success: false,
|
|
51
|
+
error: `Tool "${name}" not found in registry`,
|
|
52
|
+
duration: 0,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
const start = Date.now();
|
|
56
|
+
try {
|
|
57
|
+
const result = await tool.execute(args, userContext);
|
|
58
|
+
return { ...result, duration: Date.now() - start };
|
|
59
|
+
}
|
|
60
|
+
catch (err) {
|
|
61
|
+
return {
|
|
62
|
+
toolName: name,
|
|
63
|
+
callId: `err_${Date.now()}`,
|
|
64
|
+
success: false,
|
|
65
|
+
error: err instanceof Error ? err.message : String(err),
|
|
66
|
+
duration: Date.now() - start,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/** Number of registered tools. */
|
|
71
|
+
get size() {
|
|
72
|
+
return this.tools.size;
|
|
73
|
+
}
|
|
74
|
+
/** List all registered tool names. */
|
|
75
|
+
listNames() {
|
|
76
|
+
return Array.from(this.tools.keys());
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
exports.ToolRegistry = ToolRegistry;
|
|
80
|
+
//# sourceMappingURL=ToolRegistry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ToolRegistry.js","sourceRoot":"","sources":["../../src/tools/ToolRegistry.ts"],"names":[],"mappings":";;;AAEA;;;GAGG;AACH,MAAa,YAAY;IACf,KAAK,GAAG,IAAI,GAAG,EAAgB,CAAC;IAExC,2EAA2E;IAC3E,QAAQ,CAAC,IAAU;QACjB,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YAC9B,MAAM,IAAI,KAAK,CAAC,SAAS,IAAI,CAAC,IAAI,yBAAyB,CAAC,CAAC;QAC/D,CAAC;QACD,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAClC,CAAC;IAED,iCAAiC;IACjC,UAAU,CAAC,IAAY;QACrB,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACjC,CAAC;IAED,0BAA0B;IAC1B,GAAG,CAAC,IAAY;QACd,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC;IAED,8BAA8B;IAC9B,GAAG,CAAC,IAAY;QACd,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC;IAED,kFAAkF;IAClF,cAAc;QACZ,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC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,CAAC,GAAG,EAAE,EAAE;gBAC3B,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC;gBACvD,QAAQ,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK;aAC7B,CAAC;QACJ,CAAC;IACH,CAAC;IAED,kCAAkC;IAClC,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;IACzB,CAAC;IAED,sCAAsC;IACtC,SAAS;QACP,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;IACvC,CAAC;CACF;AA/ED,oCA+EC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { BaseTool } from '../../BaseTool';
|
|
2
|
+
import type { ToolParameter, UserContext } from '../../../types';
|
|
3
|
+
import { type MoralisServiceConfig } from '../../../services/MoralisService';
|
|
4
|
+
export type MoralisCortexToolConfig = MoralisServiceConfig;
|
|
5
|
+
/**
|
|
6
|
+
* Tool: moralis-cortex-ai
|
|
7
|
+
*
|
|
8
|
+
* AI fallback tool that uses Moralis Cortex AI for blockchain questions
|
|
9
|
+
* that the direct API tools cannot answer. Examples: market analysis,
|
|
10
|
+
* trend predictions, complex DeFi explanations, cross-chain comparisons,
|
|
11
|
+
* protocol-specific questions, etc.
|
|
12
|
+
*
|
|
13
|
+
* This should only be used when the dedicated data tools (get-wallet-token-balances,
|
|
14
|
+
* get-token-info, get-wallet-nfts, get-nft-contract-info) cannot fulfill the request.
|
|
15
|
+
*/
|
|
16
|
+
export declare class MoralisCortexTool extends BaseTool {
|
|
17
|
+
name: string;
|
|
18
|
+
description: string;
|
|
19
|
+
category: string;
|
|
20
|
+
parameters: ToolParameter[];
|
|
21
|
+
private service;
|
|
22
|
+
constructor(config?: MoralisCortexToolConfig);
|
|
23
|
+
protected run(args: Record<string, unknown>, userContext?: UserContext): Promise<{
|
|
24
|
+
error: string;
|
|
25
|
+
source?: undefined;
|
|
26
|
+
answer?: undefined;
|
|
27
|
+
} | {
|
|
28
|
+
source: string;
|
|
29
|
+
answer: string;
|
|
30
|
+
error?: undefined;
|
|
31
|
+
}>;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=MoralisCortexTool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MoralisCortexTool.d.ts","sourceRoot":"","sources":["../../../../src/tools/builtin/ai/MoralisCortexTool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AACjE,OAAO,EAAkB,KAAK,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AAE7F,MAAM,MAAM,uBAAuB,GAAG,oBAAoB,CAAC;AAE3D;;;;;;;;;;GAUG;AACH,qBAAa,iBAAkB,SAAQ,QAAQ;IAC7C,IAAI,SAAuB;IAC3B,WAAW,SAgB+D;IAC1E,QAAQ,SAAmB;IAC3B,UAAU,EAAE,aAAa,EAAE,CASzB;IAEF,OAAO,CAAC,OAAO,CAAiB;gBAEpB,MAAM,CAAC,EAAE,uBAAuB;cAK5B,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,CAAC,EAAE,WAAW;;;;;;;;;CA8B7E"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MoralisCortexTool = void 0;
|
|
4
|
+
const BaseTool_1 = require("../../BaseTool");
|
|
5
|
+
const MoralisService_1 = require("../../../services/MoralisService");
|
|
6
|
+
/**
|
|
7
|
+
* Tool: moralis-cortex-ai
|
|
8
|
+
*
|
|
9
|
+
* AI fallback tool that uses Moralis Cortex AI for blockchain questions
|
|
10
|
+
* that the direct API tools cannot answer. Examples: market analysis,
|
|
11
|
+
* trend predictions, complex DeFi explanations, cross-chain comparisons,
|
|
12
|
+
* protocol-specific questions, etc.
|
|
13
|
+
*
|
|
14
|
+
* This should only be used when the dedicated data tools (get-wallet-token-balances,
|
|
15
|
+
* get-token-info, get-wallet-nfts, get-nft-contract-info) cannot fulfill the request.
|
|
16
|
+
*/
|
|
17
|
+
class MoralisCortexTool extends BaseTool_1.BaseTool {
|
|
18
|
+
name = 'moralis-cortex-ai';
|
|
19
|
+
description = 'Ask Moralis Cortex AI for EVM blockchain/crypto insights that no dedicated tool can answer. ' +
|
|
20
|
+
'Use this ONLY as a last-resort fallback for EVM chains when all other tools are insufficient. ' +
|
|
21
|
+
'Good for: market analysis, DeFi protocol explanations, cross-chain comparisons, ' +
|
|
22
|
+
'trend analysis, gas fee insights, complex on-chain analytics, and general crypto questions ' +
|
|
23
|
+
'that require AI reasoning over EVM blockchain data. ' +
|
|
24
|
+
'Do NOT use this for: ' +
|
|
25
|
+
'token balances → get-wallet-token-balances; ' +
|
|
26
|
+
'token prices/info → get-token-info; ' +
|
|
27
|
+
'NFTs → get-wallet-nfts or get-nft-contract-info; ' +
|
|
28
|
+
'transaction details → get-transaction-by-hash; ' +
|
|
29
|
+
'wallet history → get-wallet-history; ' +
|
|
30
|
+
'token transfers → get-wallet-token-transfers; ' +
|
|
31
|
+
'NFT transfers → get-wallet-nft-transfers; ' +
|
|
32
|
+
'token holders → get-token-holders; ' +
|
|
33
|
+
'wallet PnL → get-wallet-pnl or get-wallet-pnl-summary; ' +
|
|
34
|
+
'ANY Solana question or Solana address → use solana-cortex-ai instead.';
|
|
35
|
+
category = 'blockchain-ai';
|
|
36
|
+
parameters = [
|
|
37
|
+
{
|
|
38
|
+
name: 'prompt',
|
|
39
|
+
type: 'string',
|
|
40
|
+
description: 'A clear, specific question about blockchain/crypto for the AI to answer. ' +
|
|
41
|
+
'Should be a well-formed English query with relevant context.',
|
|
42
|
+
required: true,
|
|
43
|
+
},
|
|
44
|
+
];
|
|
45
|
+
service;
|
|
46
|
+
constructor(config) {
|
|
47
|
+
super();
|
|
48
|
+
this.service = new MoralisService_1.MoralisService(config);
|
|
49
|
+
}
|
|
50
|
+
async run(args, userContext) {
|
|
51
|
+
const prompt = args.prompt;
|
|
52
|
+
if (!prompt) {
|
|
53
|
+
return { error: 'Missing required parameter: prompt' };
|
|
54
|
+
}
|
|
55
|
+
// Enrich prompt with explicit, clearly-labelled user context so Cortex
|
|
56
|
+
// does not confuse the connected wallet / chain with the question itself.
|
|
57
|
+
const contextLines = [];
|
|
58
|
+
if (userContext?.walletAddress) {
|
|
59
|
+
contextLines.push(`- Connected wallet address: ${userContext.walletAddress}`);
|
|
60
|
+
}
|
|
61
|
+
if (userContext?.chain) {
|
|
62
|
+
contextLines.push(`- Current chain: ${userContext.chain}`);
|
|
63
|
+
}
|
|
64
|
+
const enrichedPrompt = contextLines.length > 0 ? `[USER CONTEXT]\n${contextLines.join('\n')}\n\n[USER QUESTION]\n${prompt}` : prompt;
|
|
65
|
+
const result = await this.service.chatWithCortex({ prompt: enrichedPrompt });
|
|
66
|
+
if (!result.success) {
|
|
67
|
+
return { error: result.error || 'Cortex AI request failed' };
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
source: 'moralis-cortex-ai',
|
|
71
|
+
answer: result.data?.text || '',
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
exports.MoralisCortexTool = MoralisCortexTool;
|
|
76
|
+
//# sourceMappingURL=MoralisCortexTool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MoralisCortexTool.js","sourceRoot":"","sources":["../../../../src/tools/builtin/ai/MoralisCortexTool.ts"],"names":[],"mappings":";;;AAAA,6CAA0C;AAE1C,qEAA6F;AAI7F;;;;;;;;;;GAUG;AACH,MAAa,iBAAkB,SAAQ,mBAAQ;IAC7C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AI,CAAC,IAAI,CAAC,wBAAwB,MAAM,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC;QAEhH,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE,MAAM,EAAE,cAAc,EAAE,CAAC,CAAC;QAE7E,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YACpB,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,IAAI,0BAA0B,EAAE,CAAC;QAC/D,CAAC;QAED,OAAO;YACL,MAAM,EAAE,mBAAmB;YAC3B,MAAM,EAAE,MAAM,CAAC,IAAI,EAAE,IAAI,IAAI,EAAE;SAChC,CAAC;IACJ,CAAC;CACF;AApED,8CAoEC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { BaseTool } from '../../BaseTool';
|
|
2
|
+
import type { ToolParameter, UserContext } from '../../../types';
|
|
3
|
+
import { type MoralisServiceConfig } from '../../../services/MoralisService';
|
|
4
|
+
export type SolanaCortexToolConfig = MoralisServiceConfig;
|
|
5
|
+
export declare class SolanaCortexTool extends BaseTool {
|
|
6
|
+
name: string;
|
|
7
|
+
description: string;
|
|
8
|
+
category: string;
|
|
9
|
+
parameters: ToolParameter[];
|
|
10
|
+
private service;
|
|
11
|
+
constructor(config?: SolanaCortexToolConfig);
|
|
12
|
+
protected run(args: Record<string, unknown>, userContext?: UserContext): Promise<{
|
|
13
|
+
error: string;
|
|
14
|
+
source?: undefined;
|
|
15
|
+
answer?: undefined;
|
|
16
|
+
} | {
|
|
17
|
+
source: string;
|
|
18
|
+
answer: string;
|
|
19
|
+
error?: undefined;
|
|
20
|
+
}>;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=SolanaCortexTool.d.ts.map
|