@t2000/engine 0.5.1 → 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 +12 -1
- package/dist/index.js +19 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -143,6 +143,9 @@ interface EngineConfig {
|
|
|
143
143
|
model?: string;
|
|
144
144
|
maxTurns?: number;
|
|
145
145
|
maxTokens?: number;
|
|
146
|
+
temperature?: number;
|
|
147
|
+
/** Force tool usage on the first LLM turn (prevents text-only refusals). */
|
|
148
|
+
toolChoice?: ToolChoice;
|
|
146
149
|
costTracker?: {
|
|
147
150
|
budgetLimitUsd?: number;
|
|
148
151
|
inputCostPerToken?: number;
|
|
@@ -152,12 +155,18 @@ interface EngineConfig {
|
|
|
152
155
|
interface LLMProvider {
|
|
153
156
|
chat(params: ChatParams): AsyncGenerator<ProviderEvent>;
|
|
154
157
|
}
|
|
158
|
+
type ToolChoice = 'auto' | 'any' | {
|
|
159
|
+
type: 'tool';
|
|
160
|
+
name: string;
|
|
161
|
+
};
|
|
155
162
|
interface ChatParams {
|
|
156
163
|
messages: Message[];
|
|
157
164
|
systemPrompt: string;
|
|
158
165
|
tools: ToolDefinition[];
|
|
159
166
|
model?: string;
|
|
160
167
|
maxTokens?: number;
|
|
168
|
+
temperature?: number;
|
|
169
|
+
toolChoice?: ToolChoice;
|
|
161
170
|
signal?: AbortSignal;
|
|
162
171
|
}
|
|
163
172
|
interface ToolDefinition {
|
|
@@ -232,6 +241,8 @@ declare class QueryEngine {
|
|
|
232
241
|
private readonly model;
|
|
233
242
|
private readonly maxTurns;
|
|
234
243
|
private readonly maxTokens;
|
|
244
|
+
private readonly temperature;
|
|
245
|
+
private readonly toolChoice;
|
|
235
246
|
private readonly agent;
|
|
236
247
|
private readonly mcpManager;
|
|
237
248
|
private readonly walletAddress;
|
|
@@ -1041,4 +1052,4 @@ declare function clearPriceCache(): void;
|
|
|
1041
1052
|
|
|
1042
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.";
|
|
1043
1054
|
|
|
1044
|
-
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
|
@@ -1759,6 +1759,8 @@ var QueryEngine = class {
|
|
|
1759
1759
|
model;
|
|
1760
1760
|
maxTurns;
|
|
1761
1761
|
maxTokens;
|
|
1762
|
+
temperature;
|
|
1763
|
+
toolChoice;
|
|
1762
1764
|
agent;
|
|
1763
1765
|
mcpManager;
|
|
1764
1766
|
walletAddress;
|
|
@@ -1778,6 +1780,8 @@ var QueryEngine = class {
|
|
|
1778
1780
|
this.model = config.model;
|
|
1779
1781
|
this.maxTurns = config.maxTurns ?? DEFAULT_MAX_TURNS;
|
|
1780
1782
|
this.maxTokens = config.maxTokens ?? DEFAULT_MAX_TOKENS;
|
|
1783
|
+
this.temperature = config.temperature;
|
|
1784
|
+
this.toolChoice = config.toolChoice;
|
|
1781
1785
|
this.systemPrompt = config.systemPrompt ?? DEFAULT_SYSTEM_PROMPT;
|
|
1782
1786
|
this.costTracker = new CostTracker(config.costTracker);
|
|
1783
1787
|
this.tools = config.tools ?? (config.agent ? getDefaultTools() : []);
|
|
@@ -1921,6 +1925,8 @@ ${summary.join("\n")}`);
|
|
|
1921
1925
|
tools: toolDefs,
|
|
1922
1926
|
model: this.model,
|
|
1923
1927
|
maxTokens: this.maxTokens,
|
|
1928
|
+
temperature: this.temperature,
|
|
1929
|
+
toolChoice: turns === 1 ? this.toolChoice : void 0,
|
|
1924
1930
|
signal
|
|
1925
1931
|
});
|
|
1926
1932
|
for await (const event of stream) {
|
|
@@ -2678,12 +2684,24 @@ var AnthropicProvider = class {
|
|
|
2678
2684
|
params.messages.map(toAnthropicMessage)
|
|
2679
2685
|
);
|
|
2680
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
|
+
}
|
|
2681
2697
|
const streamParams = {
|
|
2682
2698
|
model: params.model ?? this.defaultModel,
|
|
2683
2699
|
max_tokens: params.maxTokens ?? this.defaultMaxTokens,
|
|
2684
2700
|
system: params.systemPrompt,
|
|
2685
2701
|
messages,
|
|
2686
|
-
tools: tools.length > 0 ? tools : void 0
|
|
2702
|
+
tools: tools.length > 0 ? tools : void 0,
|
|
2703
|
+
...params.temperature !== void 0 && { temperature: params.temperature },
|
|
2704
|
+
...toolChoice && { tool_choice: toolChoice }
|
|
2687
2705
|
};
|
|
2688
2706
|
const stream = params.signal ? this.client.messages.stream(streamParams, { signal: params.signal }) : this.client.messages.stream(streamParams);
|
|
2689
2707
|
const toolInputBuffers = /* @__PURE__ */ new Map();
|