@t2000/engine 0.5.2 → 0.5.3
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 +9 -1
- package/dist/index.js +15 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -144,6 +144,8 @@ interface EngineConfig {
|
|
|
144
144
|
maxTurns?: number;
|
|
145
145
|
maxTokens?: number;
|
|
146
146
|
temperature?: number;
|
|
147
|
+
/** Force tool usage on the first LLM turn (prevents text-only refusals). */
|
|
148
|
+
toolChoice?: ToolChoice;
|
|
147
149
|
costTracker?: {
|
|
148
150
|
budgetLimitUsd?: number;
|
|
149
151
|
inputCostPerToken?: number;
|
|
@@ -153,6 +155,10 @@ interface EngineConfig {
|
|
|
153
155
|
interface LLMProvider {
|
|
154
156
|
chat(params: ChatParams): AsyncGenerator<ProviderEvent>;
|
|
155
157
|
}
|
|
158
|
+
type ToolChoice = 'auto' | 'any' | {
|
|
159
|
+
type: 'tool';
|
|
160
|
+
name: string;
|
|
161
|
+
};
|
|
156
162
|
interface ChatParams {
|
|
157
163
|
messages: Message[];
|
|
158
164
|
systemPrompt: string;
|
|
@@ -160,6 +166,7 @@ interface ChatParams {
|
|
|
160
166
|
model?: string;
|
|
161
167
|
maxTokens?: number;
|
|
162
168
|
temperature?: number;
|
|
169
|
+
toolChoice?: ToolChoice;
|
|
163
170
|
signal?: AbortSignal;
|
|
164
171
|
}
|
|
165
172
|
interface ToolDefinition {
|
|
@@ -235,6 +242,7 @@ declare class QueryEngine {
|
|
|
235
242
|
private readonly maxTurns;
|
|
236
243
|
private readonly maxTokens;
|
|
237
244
|
private readonly temperature;
|
|
245
|
+
private readonly toolChoice;
|
|
238
246
|
private readonly agent;
|
|
239
247
|
private readonly mcpManager;
|
|
240
248
|
private readonly walletAddress;
|
|
@@ -1044,4 +1052,4 @@ declare function clearPriceCache(): void;
|
|
|
1044
1052
|
|
|
1045
1053
|
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 any NAVI asset: USDC (default), USDT, SUI, USDe, USDsui. Pass asset param for non-USDC.\n- \"Deposit SUI to earn yield\": save_deposit with asset=\"SUI\" for NAVI lending, or volo_stake for 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.";
|
|
1046
1054
|
|
|
1047
|
-
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 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, parseMcpJson, parseSSE, payApiTool, ratesInfoTool, registerEngineTools, repayDebtTool, requireAgent, runTools, saveDepositTool, savingsInfoTool, sendTransferTool, serializeSSE, swapExecuteTool, swapQuoteTool, toolsToDefinitions, transactionHistoryTool, transformBalance, transformHealthFactor, transformPositions, transformRates, transformRewards, transformSavings, validateHistory, voloStakeTool, voloStatsTool, voloUnstakeTool, withdrawTool };
|
|
1055
|
+
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, parseMcpJson, parseSSE, payApiTool, ratesInfoTool, registerEngineTools, repayDebtTool, requireAgent, runTools, saveDepositTool, savingsInfoTool, sendTransferTool, serializeSSE, swapExecuteTool, swapQuoteTool, toolsToDefinitions, transactionHistoryTool, transformBalance, transformHealthFactor, transformPositions, transformRates, transformRewards, transformSavings, validateHistory, voloStakeTool, voloStatsTool, voloUnstakeTool, withdrawTool };
|
package/dist/index.js
CHANGED
|
@@ -1760,6 +1760,7 @@ var QueryEngine = class {
|
|
|
1760
1760
|
maxTurns;
|
|
1761
1761
|
maxTokens;
|
|
1762
1762
|
temperature;
|
|
1763
|
+
toolChoice;
|
|
1763
1764
|
agent;
|
|
1764
1765
|
mcpManager;
|
|
1765
1766
|
walletAddress;
|
|
@@ -1780,6 +1781,7 @@ var QueryEngine = class {
|
|
|
1780
1781
|
this.maxTurns = config.maxTurns ?? DEFAULT_MAX_TURNS;
|
|
1781
1782
|
this.maxTokens = config.maxTokens ?? DEFAULT_MAX_TOKENS;
|
|
1782
1783
|
this.temperature = config.temperature;
|
|
1784
|
+
this.toolChoice = config.toolChoice;
|
|
1783
1785
|
this.systemPrompt = config.systemPrompt ?? DEFAULT_SYSTEM_PROMPT;
|
|
1784
1786
|
this.costTracker = new CostTracker(config.costTracker);
|
|
1785
1787
|
this.tools = config.tools ?? (config.agent ? getDefaultTools() : []);
|
|
@@ -1924,6 +1926,7 @@ ${summary.join("\n")}`);
|
|
|
1924
1926
|
model: this.model,
|
|
1925
1927
|
maxTokens: this.maxTokens,
|
|
1926
1928
|
temperature: this.temperature,
|
|
1929
|
+
toolChoice: turns === 1 ? this.toolChoice : void 0,
|
|
1927
1930
|
signal
|
|
1928
1931
|
});
|
|
1929
1932
|
for await (const event of stream) {
|
|
@@ -2681,13 +2684,24 @@ var AnthropicProvider = class {
|
|
|
2681
2684
|
params.messages.map(toAnthropicMessage)
|
|
2682
2685
|
);
|
|
2683
2686
|
const tools = params.tools.map(toAnthropicTool);
|
|
2687
|
+
let toolChoice;
|
|
2688
|
+
if (params.toolChoice && tools.length > 0) {
|
|
2689
|
+
if (params.toolChoice === "any") {
|
|
2690
|
+
toolChoice = { type: "any" };
|
|
2691
|
+
} else if (params.toolChoice === "auto") {
|
|
2692
|
+
toolChoice = { type: "auto" };
|
|
2693
|
+
} else if (typeof params.toolChoice === "object") {
|
|
2694
|
+
toolChoice = { type: "tool", name: params.toolChoice.name };
|
|
2695
|
+
}
|
|
2696
|
+
}
|
|
2684
2697
|
const streamParams = {
|
|
2685
2698
|
model: params.model ?? this.defaultModel,
|
|
2686
2699
|
max_tokens: params.maxTokens ?? this.defaultMaxTokens,
|
|
2687
2700
|
system: params.systemPrompt,
|
|
2688
2701
|
messages,
|
|
2689
2702
|
tools: tools.length > 0 ? tools : void 0,
|
|
2690
|
-
...params.temperature !== void 0 && { temperature: params.temperature }
|
|
2703
|
+
...params.temperature !== void 0 && { temperature: params.temperature },
|
|
2704
|
+
...toolChoice && { tool_choice: toolChoice }
|
|
2691
2705
|
};
|
|
2692
2706
|
const stream = params.signal ? this.client.messages.stream(streamParams, { signal: params.signal }) : this.client.messages.stream(streamParams);
|
|
2693
2707
|
const toolInputBuffers = /* @__PURE__ */ new Map();
|