@t2000/engine 0.5.13 → 0.6.1

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/dist/index.d.ts CHANGED
@@ -94,6 +94,8 @@ interface ToolContext {
94
94
  serverPositions?: ServerPositionData;
95
95
  /** Fresh on-chain position reader — bypasses MCP caching. If provided, read tools prefer this. */
96
96
  positionFetcher?: (address: string) => Promise<ServerPositionData>;
97
+ /** Environment variables passed to tools (e.g. API keys not in process.env) */
98
+ env?: Record<string, string>;
97
99
  signal?: AbortSignal;
98
100
  }
99
101
  interface ServerPositionData {
@@ -981,6 +983,83 @@ declare const saveContactTool: Tool<{
981
983
  address: string;
982
984
  }>;
983
985
 
986
+ interface SearchResult {
987
+ title: string;
988
+ url: string;
989
+ description: string;
990
+ }
991
+ interface WebSearchData {
992
+ results: SearchResult[];
993
+ error?: string;
994
+ }
995
+ declare const webSearchTool: Tool<{
996
+ query: string;
997
+ count?: number | undefined;
998
+ }, WebSearchData>;
999
+
1000
+ interface TxEffect {
1001
+ type: string;
1002
+ description: string;
1003
+ }
1004
+ interface ExplainedTx {
1005
+ digest: string;
1006
+ sender: string;
1007
+ status: string;
1008
+ gasUsed: string;
1009
+ timestamp?: string;
1010
+ effects: TxEffect[];
1011
+ summary: string;
1012
+ }
1013
+ declare const explainTxTool: Tool<{
1014
+ digest: string;
1015
+ }, ExplainedTx>;
1016
+
1017
+ interface AssetAllocation {
1018
+ symbol: string;
1019
+ amount: number;
1020
+ usdValue: number;
1021
+ percentage: number;
1022
+ }
1023
+ interface PortfolioInsight {
1024
+ type: 'info' | 'warning' | 'suggestion';
1025
+ message: string;
1026
+ }
1027
+ interface PortfolioResult {
1028
+ totalValue: number;
1029
+ walletValue: number;
1030
+ savingsValue: number;
1031
+ debtValue: number;
1032
+ healthFactor: number | null;
1033
+ allocations: AssetAllocation[];
1034
+ stablePercentage: number;
1035
+ insights: PortfolioInsight[];
1036
+ }
1037
+ declare const portfolioAnalysisTool: Tool<{
1038
+ address?: string | undefined;
1039
+ }, PortfolioResult>;
1040
+
1041
+ interface ProtocolProfile {
1042
+ name: string;
1043
+ slug: string;
1044
+ category: string;
1045
+ chains: string[];
1046
+ tvl: number;
1047
+ tvlChange1d: number;
1048
+ tvlChange7d: number;
1049
+ tvlChange30d: number;
1050
+ mcap: number | null;
1051
+ fees24h: number | null;
1052
+ revenue24h: number | null;
1053
+ audits: string[];
1054
+ url: string;
1055
+ twitter: string | null;
1056
+ riskFactors: string[];
1057
+ safetyScore: string;
1058
+ }
1059
+ declare const protocolDeepDiveTool: Tool<{
1060
+ protocol: string;
1061
+ }, ProtocolProfile>;
1062
+
984
1063
  declare const defillamaYieldPoolsTool: Tool<{
985
1064
  limit?: number | undefined;
986
1065
  chain?: string | undefined;
@@ -1094,4 +1173,4 @@ declare function clearPriceCache(): void;
1094
1173
 
1095
1174
  declare const DEFAULT_SYSTEM_PROMPT = "You are a financial agent on Sui. You manage money and access paid APIs via MPP micropayments.\n\n## Response rules\n- 1-2 sentences max. No bullet lists unless asked. No preambles.\n- Never say \"Would you like me to...\", \"Sure!\", \"Great question!\", \"Absolutely!\" \u2014 just do it or say you can't.\n- Lead with the result. After tool calls, state the outcome with real numbers. Done.\n- Present amounts as $1,234.56 and rates as X.XX% APY.\n- Show top 3 results unless asked for more. Summarize totals in one line.\n\n## Execution rule\nOnly offer to execute actions you have tools for. If you retrieved a quote, data, or information but have no tool to act on it, give the user the result and tell them where to execute manually \u2014 in one sentence. Never say \"Would you like me to proceed?\" unless you have a tool that can actually proceed.\n\n## Before acting\n- ALWAYS call a read tool first before any write tool \u2014 balance_check before save/send/borrow, savings_info before withdraw.\n- Show real numbers from tools \u2014 never fabricate rates, amounts, or balances.\n- When user says \"all\" or an imprecise amount, call the read tool first to get the exact number.\n\n## Tool usage\n- Use tools proactively \u2014 don't refuse requests you can handle.\n- For real-world questions (weather, search, news, prices), use pay_api. Tell the user the cost first.\n- For broad market data (yields across protocols, token prices, TVL, protocol comparisons), use defillama_* tools.\n- To discover Sui protocols, use defillama_sui_protocols first, then defillama_protocol_info with the slug.\n- Run multiple read-only tools in parallel when you need several data points.\n- If a tool errors, say what went wrong and what to try instead. One sentence.\n\n## Multi-step flows\n- \"How much X for Y?\": swap_quote first, then swap_execute if user confirms.\n- \"Swap then save\": swap_execute \u2192 balance_check \u2192 save_deposit. Confirm each step.\n- \"Buy $X of token\": defillama_token_prices \u2192 calculate amount \u2192 swap_execute.\n- \"Best yield on SUI\": compare rates_info (NAVI lending) + defillama_yield_pools (broader) + volo_stats.\n- save_deposit supports: USDC (default), USDT, SUI, USDe, USDsui. Pass asset param for non-USDC.\n- withdraw supports: USDC, USDT, SUI, USDe, USDsui. Pass asset param to withdraw a specific token.\n- \"Deposit SUI to earn yield\": save_deposit with asset=\"SUI\" for NAVI lending, or volo_stake for SUI liquid staking.\n- \"What protocols are on Sui?\": defillama_sui_protocols \u2192 defillama_protocol_info for details.\n\n## Safety\n- Never encourage risky financial behavior.\n- Warn when health factor < 1.5.\n- All amounts in USDC unless stated otherwise.";
1096
1175
 
1097
- export { AnthropicProvider, type AnthropicProviderConfig, type BalancePrices, type BalanceResult, type BuildToolOptions, type ChatParams, type CompactOptions, type ContentBlock, type CostSnapshot, CostTracker, type CostTrackerConfig, DEFAULT_SYSTEM_PROMPT, type EngineConfig, type EngineEvent, type HealthFactorResult, type LLMProvider, type McpCallResult, McpClientManager, McpResponseCache, type McpServerConfig, type McpServerConnection, type McpToolAdapterConfig, type McpToolDescriptor, MemorySessionStore, type Message, NAVI_MCP_CONFIG, NAVI_MCP_URL, NAVI_SERVER_NAME, type NaviRawCoin, type NaviRawHealthFactor, type NaviRawPool, type NaviRawPosition, type NaviRawPositionsResponse, type NaviRawProtocolStats, type NaviRawRewardsResponse, type NaviReadOptions, NaviTools, type PendingAction, type PendingReward, type PendingToolCall, type PermissionLevel, type PermissionResponse, type PositionEntry, type ProtocolStats, type ProviderEvent, QueryEngine, READ_TOOLS, type RatesResult, type SSEEvent, type SavingsResult, type ServerPositionData, type SessionData, type SessionStore, type StopReason, type SuiCoinBalance, type Tool, type ToolChoice, type ToolContext, type ToolDefinition, type ToolJsonSchema, type ToolResult, TxMutex, WRITE_TOOLS, type WalletCoin, adaptAllMcpTools, adaptAllServerTools, adaptMcpTool, balanceCheckTool, borrowTool, buildMcpTools, buildTool, claimRewardsTool, clearPriceCache, compactMessages, defillamaChainTvlTool, defillamaPriceChangeTool, defillamaProtocolFeesTool, defillamaProtocolInfoTool, defillamaSuiProtocolsTool, defillamaTokenPricesTool, defillamaYieldPoolsTool, engineToSSE, estimateTokens, extractMcpText, fetchAvailableRewards, fetchBalance, fetchHealthFactor, fetchPositions, fetchProtocolStats, fetchRates, fetchSavings, fetchTokenPrices, fetchWalletCoins, findTool, getDefaultTools, getMcpManager, getWalletAddress, hasNaviMcp, healthCheckTool, mppServicesTool, parseMcpJson, parseSSE, payApiTool, ratesInfoTool, registerEngineTools, repayDebtTool, requireAgent, runTools, saveContactTool, saveDepositTool, savingsInfoTool, sendTransferTool, serializeSSE, swapExecuteTool, swapQuoteTool, toolsToDefinitions, transactionHistoryTool, transformBalance, transformHealthFactor, transformPositions, transformRates, transformRewards, transformSavings, validateHistory, voloStakeTool, voloStatsTool, voloUnstakeTool, withdrawTool };
1176
+ export { AnthropicProvider, type AnthropicProviderConfig, type BalancePrices, type BalanceResult, type BuildToolOptions, type ChatParams, type CompactOptions, type ContentBlock, type CostSnapshot, CostTracker, type CostTrackerConfig, DEFAULT_SYSTEM_PROMPT, type EngineConfig, type EngineEvent, type HealthFactorResult, type LLMProvider, type McpCallResult, McpClientManager, McpResponseCache, type McpServerConfig, type McpServerConnection, type McpToolAdapterConfig, type McpToolDescriptor, MemorySessionStore, type Message, NAVI_MCP_CONFIG, NAVI_MCP_URL, NAVI_SERVER_NAME, type NaviRawCoin, type NaviRawHealthFactor, type NaviRawPool, type NaviRawPosition, type NaviRawPositionsResponse, type NaviRawProtocolStats, type NaviRawRewardsResponse, type NaviReadOptions, NaviTools, type PendingAction, type PendingReward, type PendingToolCall, type PermissionLevel, type PermissionResponse, type PositionEntry, type ProtocolStats, type ProviderEvent, QueryEngine, READ_TOOLS, type RatesResult, type SSEEvent, type SavingsResult, type ServerPositionData, type SessionData, type SessionStore, type StopReason, type SuiCoinBalance, type Tool, type ToolChoice, type ToolContext, type ToolDefinition, type ToolJsonSchema, type ToolResult, TxMutex, WRITE_TOOLS, type WalletCoin, adaptAllMcpTools, adaptAllServerTools, adaptMcpTool, balanceCheckTool, borrowTool, buildMcpTools, buildTool, claimRewardsTool, clearPriceCache, compactMessages, defillamaChainTvlTool, defillamaPriceChangeTool, defillamaProtocolFeesTool, defillamaProtocolInfoTool, defillamaSuiProtocolsTool, defillamaTokenPricesTool, defillamaYieldPoolsTool, engineToSSE, estimateTokens, explainTxTool, extractMcpText, fetchAvailableRewards, fetchBalance, fetchHealthFactor, fetchPositions, fetchProtocolStats, fetchRates, fetchSavings, fetchTokenPrices, fetchWalletCoins, findTool, getDefaultTools, getMcpManager, getWalletAddress, hasNaviMcp, healthCheckTool, mppServicesTool, parseMcpJson, parseSSE, payApiTool, portfolioAnalysisTool, protocolDeepDiveTool, ratesInfoTool, registerEngineTools, repayDebtTool, requireAgent, runTools, saveContactTool, saveDepositTool, savingsInfoTool, sendTransferTool, serializeSSE, swapExecuteTool, swapQuoteTool, toolsToDefinitions, transactionHistoryTool, transformBalance, transformHealthFactor, transformPositions, transformRates, transformRewards, transformSavings, validateHistory, voloStakeTool, voloStatsTool, voloUnstakeTool, webSearchTool, withdrawTool };
package/dist/index.js CHANGED
@@ -1526,7 +1526,356 @@ var saveContactTool = buildTool({
1526
1526
  };
1527
1527
  }
1528
1528
  });
1529
+ var BRAVE_API = "https://api.search.brave.com/res/v1/web/search";
1530
+ var inputSchema = z.object({
1531
+ query: z.string().describe("Search query"),
1532
+ count: z.number().optional().default(5).describe("Number of results (1-10)")
1533
+ });
1534
+ var webSearchTool = buildTool({
1535
+ name: "web_search",
1536
+ description: "Search the web for real-time information. Use for news, token info, project details, protocol documentation, or any question that needs current web data. Free for users.",
1537
+ inputSchema,
1538
+ jsonSchema: {
1539
+ type: "object",
1540
+ properties: {
1541
+ query: { type: "string", description: "Search query" },
1542
+ count: { type: "number", description: "Number of results (1-10)", default: 5 }
1543
+ },
1544
+ required: ["query"]
1545
+ },
1546
+ isReadOnly: true,
1547
+ async call(input, context) {
1548
+ const apiKey = context.env?.BRAVE_API_KEY ?? process.env.BRAVE_API_KEY;
1549
+ if (!apiKey) {
1550
+ return {
1551
+ data: { results: [], error: "Web search not configured" },
1552
+ displayText: "Web search is not available."
1553
+ };
1554
+ }
1555
+ const count = Math.min(Math.max(input.count ?? 5, 1), 10);
1556
+ const url = `${BRAVE_API}?q=${encodeURIComponent(input.query)}&count=${count}&text_decorations=false`;
1557
+ const res = await fetch(url, {
1558
+ headers: {
1559
+ "Accept": "application/json",
1560
+ "Accept-Encoding": "gzip",
1561
+ "X-Subscription-Token": apiKey
1562
+ },
1563
+ signal: AbortSignal.timeout(8e3)
1564
+ });
1565
+ if (!res.ok) {
1566
+ throw new Error(`Brave Search API error: HTTP ${res.status}`);
1567
+ }
1568
+ const json = await res.json();
1569
+ const results = (json.web?.results ?? []).slice(0, count).map((r) => ({
1570
+ title: r.title,
1571
+ url: r.url,
1572
+ description: r.description
1573
+ }));
1574
+ const displayText = results.length > 0 ? results.map((r, i) => `${i + 1}. ${r.title}
1575
+ ${r.url}
1576
+ ${r.description}`).join("\n\n") : "No results found.";
1577
+ return { data: { results }, displayText };
1578
+ }
1579
+ });
1580
+ var inputSchema2 = z.object({
1581
+ digest: z.string().describe("Sui transaction digest to explain")
1582
+ });
1583
+ var SIX_DECIMAL_TOKENS = /* @__PURE__ */ new Set(["USDC", "USDT", "USDe", "WBTC"]);
1584
+ var EIGHT_DECIMAL_TOKENS = /* @__PURE__ */ new Set(["WETH", "ETH"]);
1585
+ function guessDecimals(coinType) {
1586
+ const symbol = coinType.split("::").pop()?.toUpperCase() ?? "";
1587
+ if (SIX_DECIMAL_TOKENS.has(symbol)) return 6;
1588
+ if (EIGHT_DECIMAL_TOKENS.has(symbol)) return 8;
1589
+ return 9;
1590
+ }
1591
+ var explainTxTool = buildTool({
1592
+ name: "explain_tx",
1593
+ description: "Explain a Sui transaction in plain English. Provide a transaction digest and get a human-readable breakdown of what happened \u2014 transfers, swaps, deposits, etc.",
1594
+ inputSchema: inputSchema2,
1595
+ jsonSchema: {
1596
+ type: "object",
1597
+ properties: {
1598
+ digest: { type: "string", description: "Sui transaction digest" }
1599
+ },
1600
+ required: ["digest"]
1601
+ },
1602
+ isReadOnly: true,
1603
+ async call(input, context) {
1604
+ const rpcUrl = context.suiRpcUrl ?? "https://fullnode.mainnet.sui.io:443";
1605
+ const res = await fetch(rpcUrl, {
1606
+ method: "POST",
1607
+ headers: { "Content-Type": "application/json" },
1608
+ body: JSON.stringify({
1609
+ jsonrpc: "2.0",
1610
+ id: 1,
1611
+ method: "sui_getTransactionBlock",
1612
+ params: [
1613
+ input.digest,
1614
+ {
1615
+ showInput: true,
1616
+ showEffects: true,
1617
+ showEvents: true,
1618
+ showBalanceChanges: true,
1619
+ showObjectChanges: true
1620
+ }
1621
+ ]
1622
+ }),
1623
+ signal: AbortSignal.timeout(1e4)
1624
+ });
1625
+ if (!res.ok) throw new Error(`Sui RPC error: HTTP ${res.status}`);
1626
+ const json = await res.json();
1627
+ if (json.error) throw new Error(json.error.message);
1628
+ if (!json.result) throw new Error("Transaction not found");
1629
+ const tx = json.result;
1630
+ const txInput = tx.transaction;
1631
+ const effects = tx.effects;
1632
+ const balanceChanges = tx.balanceChanges;
1633
+ const events = tx.events;
1634
+ const sender = txInput?.data?.sender ?? "unknown";
1635
+ const status = effects?.status?.status ?? "unknown";
1636
+ const gasUsed = effects?.gasUsed;
1637
+ const gasCost = gasUsed ? (Number(gasUsed.computationCost ?? 0) + Number(gasUsed.storageCost ?? 0) - Number(gasUsed.storageRebate ?? 0)) / 1e9 : 0;
1638
+ const timestamp = tx.timestampMs ? new Date(Number(tx.timestampMs)).toISOString() : void 0;
1639
+ const txEffects = [];
1640
+ if (balanceChanges?.length) {
1641
+ for (const bc of balanceChanges) {
1642
+ const ownerAddr = bc.owner?.AddressOwner ?? bc.owner?.ObjectOwner ?? "unknown";
1643
+ const coinParts = bc.coinType.split("::");
1644
+ const symbol = coinParts[coinParts.length - 1] ?? bc.coinType;
1645
+ const amount = Number(bc.amount);
1646
+ const isNegative = amount < 0;
1647
+ const decimals = guessDecimals(bc.coinType);
1648
+ txEffects.push({
1649
+ type: isNegative ? "send" : "receive",
1650
+ description: `${ownerAddr.slice(0, 8)}...${ownerAddr.slice(-4)} ${isNegative ? "sent" : "received"} ${Math.abs(amount / 10 ** decimals).toFixed(decimals > 6 ? 4 : 2)} ${symbol}`
1651
+ });
1652
+ }
1653
+ }
1654
+ if (events?.length) {
1655
+ for (const evt of events.slice(0, 5)) {
1656
+ const eventParts = evt.type.split("::");
1657
+ const eventName = eventParts[eventParts.length - 1] ?? evt.type;
1658
+ txEffects.push({
1659
+ type: "event",
1660
+ description: `Event: ${eventName}`
1661
+ });
1662
+ }
1663
+ }
1664
+ const summary = txEffects.length > 0 ? txEffects.filter((e) => e.type !== "event").map((e) => e.description).join("; ") : `Transaction ${status}`;
1665
+ const result = {
1666
+ digest: input.digest,
1667
+ sender,
1668
+ status,
1669
+ gasUsed: `${gasCost.toFixed(6)} SUI`,
1670
+ timestamp,
1671
+ effects: txEffects,
1672
+ summary
1673
+ };
1674
+ return {
1675
+ data: result,
1676
+ displayText: `**Tx ${input.digest.slice(0, 8)}...** (${status})
1677
+ Sender: ${sender}
1678
+ Gas: ${result.gasUsed}
1679
+ ${summary}`
1680
+ };
1681
+ }
1682
+ });
1683
+ var inputSchema3 = z.object({
1684
+ address: z.string().optional().describe("Sui address to analyze (defaults to connected wallet)")
1685
+ });
1686
+ var STABLECOINS = /* @__PURE__ */ new Set(["USDC", "USDT", "USDe", "USDsui", "DAI", "BUCK"]);
1687
+ var portfolioAnalysisTool = buildTool({
1688
+ name: "portfolio_analysis",
1689
+ description: "Analyze portfolio allocation, risk exposure, and yield optimization. Shows asset breakdown, diversification score, health factor assessment, and actionable suggestions.",
1690
+ inputSchema: inputSchema3,
1691
+ jsonSchema: {
1692
+ type: "object",
1693
+ properties: {
1694
+ address: { type: "string", description: "Sui address to analyze (defaults to connected wallet)" }
1695
+ },
1696
+ required: []
1697
+ },
1698
+ isReadOnly: true,
1699
+ async call(input, context) {
1700
+ const address = input.address ?? context.walletAddress;
1701
+ if (!address) {
1702
+ throw new Error("No wallet address provided. Sign in first.");
1703
+ }
1704
+ const rpcUrl = context.suiRpcUrl ?? "https://fullnode.mainnet.sui.io:443";
1705
+ const coins = await fetchWalletCoins(address, rpcUrl);
1706
+ const nonZero = coins.filter((c) => Number(c.totalBalance) > 0);
1707
+ const prices = await fetchTokenPrices(nonZero.map((c) => c.coinType)).catch(() => ({}));
1708
+ let walletValue = 0;
1709
+ const allocations = [];
1710
+ for (const coin of nonZero) {
1711
+ const amount = Number(coin.totalBalance) / 10 ** coin.decimals;
1712
+ const price = prices[coin.coinType] ?? 0;
1713
+ const usdValue = amount * price;
1714
+ walletValue += usdValue;
1715
+ allocations.push({ symbol: coin.symbol, amount, usdValue, percentage: 0 });
1716
+ }
1717
+ let savingsValue = 0;
1718
+ let debtValue = 0;
1719
+ let healthFactor = null;
1720
+ if (context.positionFetcher) {
1721
+ try {
1722
+ const positions = await context.positionFetcher(address);
1723
+ savingsValue = positions.savings ?? 0;
1724
+ debtValue = positions.borrows ?? 0;
1725
+ healthFactor = positions.healthFactor ?? null;
1726
+ } catch {
1727
+ }
1728
+ }
1729
+ const totalValue = walletValue + savingsValue;
1730
+ for (const a of allocations) {
1731
+ a.percentage = totalValue > 0 ? a.usdValue / totalValue * 100 : 0;
1732
+ }
1733
+ allocations.sort((a, b) => b.usdValue - a.usdValue);
1734
+ const stableValue = allocations.filter((a) => STABLECOINS.has(a.symbol)).reduce((s, a) => s + a.usdValue, 0) + savingsValue;
1735
+ const stablePercentage = totalValue > 0 ? stableValue / totalValue * 100 : 0;
1736
+ const insights = [];
1737
+ if (healthFactor !== null && healthFactor < 1.5) {
1738
+ insights.push({
1739
+ type: "warning",
1740
+ message: `Health factor ${healthFactor.toFixed(2)} is dangerously low. Consider repaying debt or adding collateral.`
1741
+ });
1742
+ } else if (healthFactor !== null && healthFactor < 2.5) {
1743
+ insights.push({
1744
+ type: "warning",
1745
+ message: `Health factor ${healthFactor.toFixed(2)} is moderate. Monitor your positions.`
1746
+ });
1747
+ }
1748
+ if (stablePercentage > 80) {
1749
+ insights.push({
1750
+ type: "suggestion",
1751
+ message: `${stablePercentage.toFixed(0)}% stablecoins. Consider diversifying into yield-bearing positions.`
1752
+ });
1753
+ }
1754
+ const idleCash = allocations.find((a) => a.symbol === "USDC");
1755
+ if (idleCash && idleCash.usdValue > 10) {
1756
+ insights.push({
1757
+ type: "suggestion",
1758
+ message: `$${idleCash.usdValue.toFixed(2)} USDC idle in wallet. Deposit into NAVI savings for ~4-5% APY.`
1759
+ });
1760
+ }
1761
+ if (allocations.length === 1) {
1762
+ insights.push({
1763
+ type: "info",
1764
+ message: "Portfolio is concentrated in a single asset."
1765
+ });
1766
+ }
1767
+ const result = {
1768
+ totalValue,
1769
+ walletValue,
1770
+ savingsValue,
1771
+ debtValue,
1772
+ healthFactor,
1773
+ allocations: allocations.slice(0, 10),
1774
+ stablePercentage,
1775
+ insights
1776
+ };
1777
+ const topLine = `Total: $${totalValue.toFixed(2)} | Wallet: $${walletValue.toFixed(2)} | Savings: $${savingsValue.toFixed(2)}`;
1778
+ const insightLines = insights.map((i) => `${i.type === "warning" ? "\u26A0" : "\u2192"} ${i.message}`).join("\n");
1779
+ return {
1780
+ data: result,
1781
+ displayText: `${topLine}
1782
+ ${insightLines}`
1783
+ };
1784
+ }
1785
+ });
1529
1786
  var LLAMA_API = "https://api.llama.fi";
1787
+ var inputSchema4 = z.object({
1788
+ protocol: z.string().describe('Protocol slug (e.g. "navi-protocol", "cetus", "scallop-lend")')
1789
+ });
1790
+ var protocolDeepDiveTool = buildTool({
1791
+ name: "protocol_deep_dive",
1792
+ description: 'Get a comprehensive safety and financial profile of a DeFi protocol. Includes TVL trends, revenue, audit status, and risk assessment. Use when users ask "is X safe?" or "tell me about protocol Y".',
1793
+ inputSchema: inputSchema4,
1794
+ jsonSchema: {
1795
+ type: "object",
1796
+ properties: {
1797
+ protocol: { type: "string", description: 'Protocol slug (e.g. "navi-protocol", "cetus")' }
1798
+ },
1799
+ required: ["protocol"]
1800
+ },
1801
+ isReadOnly: true,
1802
+ async call(input) {
1803
+ const slug = input.protocol.toLowerCase().replace(/\s+/g, "-");
1804
+ const [protocolRes, feesRes] = await Promise.allSettled([
1805
+ fetch(`${LLAMA_API}/protocol/${slug}`, { signal: AbortSignal.timeout(1e4) }).then((r) => {
1806
+ if (!r.ok) throw new Error(`HTTP ${r.status}`);
1807
+ return r.json();
1808
+ }),
1809
+ fetch(`${LLAMA_API}/summary/fees/${slug}?dataType=dailyFees`, { signal: AbortSignal.timeout(8e3) }).then((r) => {
1810
+ if (!r.ok) return null;
1811
+ return r.json();
1812
+ })
1813
+ ]);
1814
+ if (protocolRes.status === "rejected") {
1815
+ throw new Error(`Protocol "${slug}" not found on DefiLlama.`);
1816
+ }
1817
+ const proto = protocolRes.value;
1818
+ const tvl = Number(proto.tvl ?? 0);
1819
+ const tvlChange1d = Number(proto.change_1d ?? 0);
1820
+ const tvlChange7d = Number(proto.change_7d ?? 0);
1821
+ const tvlChange30d = Number(proto.change_1m ?? 0);
1822
+ const chains = proto.chains ?? [];
1823
+ const category = proto.category ?? "Unknown";
1824
+ const audits = proto.audits ?? proto.audit_links ?? [];
1825
+ const auditNote = proto.audit_note ?? proto.audits;
1826
+ let fees24h = null;
1827
+ let revenue24h = null;
1828
+ if (feesRes.status === "fulfilled" && feesRes.value) {
1829
+ const feesData = feesRes.value;
1830
+ fees24h = feesData.total24h != null ? Number(feesData.total24h) : null;
1831
+ revenue24h = feesData.totalRevenue24h != null ? Number(feesData.totalRevenue24h) : null;
1832
+ }
1833
+ const riskFactors = [];
1834
+ if (tvl < 1e6) riskFactors.push("TVL under $1M \u2014 low liquidity risk");
1835
+ if (tvl < 1e7) riskFactors.push("TVL under $10M \u2014 moderate liquidity");
1836
+ if (tvlChange7d < -15) riskFactors.push(`TVL dropped ${tvlChange7d.toFixed(1)}% in 7 days`);
1837
+ if (chains.length === 1) riskFactors.push("Single-chain deployment");
1838
+ if (!audits.length && !auditNote) riskFactors.push("No published audits found");
1839
+ if (audits.length > 0) riskFactors.push(`${audits.length} audit(s) on file`);
1840
+ let safetyScore;
1841
+ if (tvl > 1e8 && audits.length > 0 && tvlChange7d > -10) {
1842
+ safetyScore = "High \u2014 established protocol with audits and significant TVL";
1843
+ } else if (tvl > 1e7 && tvlChange7d > -20) {
1844
+ safetyScore = "Moderate \u2014 decent TVL, use with caution";
1845
+ } else {
1846
+ safetyScore = "Low \u2014 small or declining TVL, proceed carefully";
1847
+ }
1848
+ const result = {
1849
+ name: proto.name ?? slug,
1850
+ slug,
1851
+ category,
1852
+ chains,
1853
+ tvl,
1854
+ tvlChange1d,
1855
+ tvlChange7d,
1856
+ tvlChange30d,
1857
+ mcap: proto.mcap ? Number(proto.mcap) : null,
1858
+ fees24h,
1859
+ revenue24h,
1860
+ audits: typeof auditNote === "string" ? [auditNote] : audits.map(String),
1861
+ url: proto.url ?? "",
1862
+ twitter: proto.twitter ?? null,
1863
+ riskFactors,
1864
+ safetyScore
1865
+ };
1866
+ const tvlStr = tvl > 1e9 ? `$${(tvl / 1e9).toFixed(2)}B` : `$${(tvl / 1e6).toFixed(1)}M`;
1867
+ const feesStr = fees24h != null ? ` | Fees 24h: $${fees24h.toLocaleString()}` : "";
1868
+ return {
1869
+ data: result,
1870
+ displayText: `**${result.name}** (${category})
1871
+ TVL: ${tvlStr} (7d: ${tvlChange7d > 0 ? "+" : ""}${tvlChange7d.toFixed(1)}%)${feesStr}
1872
+ Chains: ${chains.join(", ")}
1873
+ Safety: ${safetyScore}
1874
+ Risks: ${riskFactors.join("; ")}`
1875
+ };
1876
+ }
1877
+ });
1878
+ var LLAMA_API2 = "https://api.llama.fi";
1530
1879
  var YIELDS_API = "https://yields.llama.fi";
1531
1880
  var COINS_API = "https://coins.llama.fi";
1532
1881
  var CACHE_TTL3 = 6e4;
@@ -1596,7 +1945,7 @@ var defillamaProtocolInfoTool = buildTool({
1596
1945
  },
1597
1946
  isReadOnly: true,
1598
1947
  async call(input) {
1599
- const data = await cachedFetch(`${LLAMA_API}/protocol/${encodeURIComponent(input.name)}`);
1948
+ const data = await cachedFetch(`${LLAMA_API2}/protocol/${encodeURIComponent(input.name)}`);
1600
1949
  const result = {
1601
1950
  name: data.name,
1602
1951
  category: data.category,
@@ -1707,7 +2056,7 @@ var defillamaChainTvlTool = buildTool({
1707
2056
  },
1708
2057
  isReadOnly: true,
1709
2058
  async call(input) {
1710
- const data = await cachedFetch(`${LLAMA_API}/v2/chains`);
2059
+ const data = await cachedFetch(`${LLAMA_API2}/v2/chains`);
1711
2060
  const sorted = [...data].sort((a, b) => b.tvl - a.tvl);
1712
2061
  const limit = input.limit ?? 10;
1713
2062
  const top = sorted.slice(0, limit);
@@ -1739,7 +2088,7 @@ var defillamaProtocolFeesTool = buildTool({
1739
2088
  },
1740
2089
  isReadOnly: true,
1741
2090
  async call(input) {
1742
- const data = await cachedFetch(`${LLAMA_API}/overview/fees`);
2091
+ const data = await cachedFetch(`${LLAMA_API2}/overview/fees`);
1743
2092
  let protocols = data.protocols ?? [];
1744
2093
  if (input.chain) {
1745
2094
  const chain = input.chain.toLowerCase();
@@ -1777,7 +2126,7 @@ var defillamaSuiProtocolsTool = buildTool({
1777
2126
  isReadOnly: true,
1778
2127
  async call(input) {
1779
2128
  const limit = input.limit ?? 10;
1780
- const data = await cachedFetch(`${LLAMA_API}/protocols`);
2129
+ const data = await cachedFetch(`${LLAMA_API2}/protocols`);
1781
2130
  const suiProtocols = data.filter((p) => p.chains?.includes("Sui") && p.tvl > 0).sort((a, b) => b.tvl - a.tvl).slice(0, limit);
1782
2131
  const results = suiProtocols.map((p) => ({
1783
2132
  name: p.name,
@@ -1802,6 +2151,10 @@ var READ_TOOLS = [
1802
2151
  swapQuoteTool,
1803
2152
  voloStatsTool,
1804
2153
  mppServicesTool,
2154
+ webSearchTool,
2155
+ explainTxTool,
2156
+ portfolioAnalysisTool,
2157
+ protocolDeepDiveTool,
1805
2158
  defillamaYieldPoolsTool,
1806
2159
  defillamaProtocolInfoTool,
1807
2160
  defillamaTokenPricesTool,
@@ -3096,6 +3449,6 @@ function sanitizeAnthropicMessages(messages) {
3096
3449
  return merged;
3097
3450
  }
3098
3451
 
3099
- export { AnthropicProvider, CostTracker, DEFAULT_SYSTEM_PROMPT, McpClientManager, McpResponseCache, MemorySessionStore, NAVI_MCP_CONFIG, NAVI_MCP_URL, NAVI_SERVER_NAME, NaviTools, QueryEngine, READ_TOOLS, TxMutex, WRITE_TOOLS, adaptAllMcpTools, adaptAllServerTools, adaptMcpTool, balanceCheckTool, borrowTool, buildMcpTools, buildTool, claimRewardsTool, clearPriceCache, compactMessages, defillamaChainTvlTool, defillamaPriceChangeTool, defillamaProtocolFeesTool, defillamaProtocolInfoTool, defillamaSuiProtocolsTool, defillamaTokenPricesTool, defillamaYieldPoolsTool, engineToSSE, estimateTokens, extractMcpText, fetchAvailableRewards, fetchBalance, fetchHealthFactor, fetchPositions, fetchProtocolStats, fetchRates, fetchSavings, fetchTokenPrices, fetchWalletCoins, findTool, getDefaultTools, getMcpManager, getWalletAddress, hasNaviMcp, healthCheckTool, mppServicesTool, parseMcpJson, parseSSE, payApiTool, ratesInfoTool, registerEngineTools, repayDebtTool, requireAgent, runTools, saveContactTool, saveDepositTool, savingsInfoTool, sendTransferTool, serializeSSE, swapExecuteTool, swapQuoteTool, toolsToDefinitions, transactionHistoryTool, transformBalance, transformHealthFactor, transformPositions, transformRates, transformRewards, transformSavings, validateHistory, voloStakeTool, voloStatsTool, voloUnstakeTool, withdrawTool };
3452
+ export { AnthropicProvider, CostTracker, DEFAULT_SYSTEM_PROMPT, McpClientManager, McpResponseCache, MemorySessionStore, NAVI_MCP_CONFIG, NAVI_MCP_URL, NAVI_SERVER_NAME, NaviTools, QueryEngine, READ_TOOLS, TxMutex, WRITE_TOOLS, adaptAllMcpTools, adaptAllServerTools, adaptMcpTool, balanceCheckTool, borrowTool, buildMcpTools, buildTool, claimRewardsTool, clearPriceCache, compactMessages, defillamaChainTvlTool, defillamaPriceChangeTool, defillamaProtocolFeesTool, defillamaProtocolInfoTool, defillamaSuiProtocolsTool, defillamaTokenPricesTool, defillamaYieldPoolsTool, engineToSSE, estimateTokens, explainTxTool, extractMcpText, fetchAvailableRewards, fetchBalance, fetchHealthFactor, fetchPositions, fetchProtocolStats, fetchRates, fetchSavings, fetchTokenPrices, fetchWalletCoins, findTool, getDefaultTools, getMcpManager, getWalletAddress, hasNaviMcp, healthCheckTool, mppServicesTool, parseMcpJson, parseSSE, payApiTool, portfolioAnalysisTool, protocolDeepDiveTool, ratesInfoTool, registerEngineTools, repayDebtTool, requireAgent, runTools, saveContactTool, saveDepositTool, savingsInfoTool, sendTransferTool, serializeSSE, swapExecuteTool, swapQuoteTool, toolsToDefinitions, transactionHistoryTool, transformBalance, transformHealthFactor, transformPositions, transformRates, transformRewards, transformSavings, validateHistory, voloStakeTool, voloStatsTool, voloUnstakeTool, webSearchTool, withdrawTool };
3100
3453
  //# sourceMappingURL=index.js.map
3101
3454
  //# sourceMappingURL=index.js.map