@t2000/engine 1.24.14 → 1.25.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 +81 -3
- package/dist/index.js +127 -2
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import * as _t2000_sdk from '@t2000/sdk';
|
|
2
|
+
import { SerializedCetusRoute, PendingReward as PendingReward$1, SwapQuoteResult, T2000 } from '@t2000/sdk';
|
|
1
3
|
import { z } from 'zod';
|
|
2
4
|
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
3
5
|
import { Transport } from '@modelcontextprotocol/sdk/shared/transport.js';
|
|
4
6
|
import { Tool as Tool$1 } from '@modelcontextprotocol/sdk/types.js';
|
|
5
|
-
import * as _t2000_sdk from '@t2000/sdk';
|
|
6
|
-
import { PendingReward as PendingReward$1, SwapQuoteResult, T2000 } from '@t2000/sdk';
|
|
7
7
|
|
|
8
8
|
type ProactiveType = 'idle_balance' | 'hf_warning' | 'apy_drift' | 'goal_progress';
|
|
9
9
|
interface ProactiveMarker {
|
|
@@ -1223,6 +1223,12 @@ interface PendingActionStep {
|
|
|
1223
1223
|
* `inputCoinFromStep < currentStepIndex` (forward-only references).
|
|
1224
1224
|
*/
|
|
1225
1225
|
inputCoinFromStep?: number;
|
|
1226
|
+
/**
|
|
1227
|
+
* [SPEC 20.2 / D-1 (a)] Per-step Cetus route — populated for `swap_execute`
|
|
1228
|
+
* steps when a same-turn `swap_quote` matched the step's input. See
|
|
1229
|
+
* `PendingAction.cetusRoute` for the full contract.
|
|
1230
|
+
*/
|
|
1231
|
+
cetusRoute?: _t2000_sdk.SerializedCetusRoute;
|
|
1226
1232
|
}
|
|
1227
1233
|
/**
|
|
1228
1234
|
* Serializable description of a write tool that needs user approval.
|
|
@@ -1283,6 +1289,25 @@ interface PendingAction {
|
|
|
1283
1289
|
* route loops `stepResults` and updates each per-step row.
|
|
1284
1290
|
*/
|
|
1285
1291
|
attemptId: string;
|
|
1292
|
+
/**
|
|
1293
|
+
* [SPEC 20.2 / D-1 (a)] Cetus route captured at `swap_quote` time and
|
|
1294
|
+
* threaded through to the prepare-route to skip the ~400-500ms
|
|
1295
|
+
* `findSwapRoute()` re-discovery call. Only populated when the same-turn
|
|
1296
|
+
* read pipeline included a successful `swap_quote` whose input matches
|
|
1297
|
+
* this `pending_action`'s amount/from/to (the engine matches at emission
|
|
1298
|
+
* time). Audric's prepare-route validates freshness + coin-type match
|
|
1299
|
+
* before using as fast-path; falls back to fresh discovery on any
|
|
1300
|
+
* mismatch (D-2 structural verification + D-3 TTL re-validation).
|
|
1301
|
+
*
|
|
1302
|
+
* Also rendered into the post-write resume system prompt as a
|
|
1303
|
+
* `<canonical_route>` block (D-4) so LLM narration grounds against the
|
|
1304
|
+
* canonical route — closes S19-F2 (LLM cites stale swap routes).
|
|
1305
|
+
*
|
|
1306
|
+
* **Bundles:** when present on a `steps[]` entry, the per-step
|
|
1307
|
+
* `cetusRoute` takes precedence over the top-level field (which mirrors
|
|
1308
|
+
* `steps[0].cetusRoute` for backward compat with pre-bundle hosts).
|
|
1309
|
+
*/
|
|
1310
|
+
cetusRoute?: _t2000_sdk.SerializedCetusRoute;
|
|
1286
1311
|
/**
|
|
1287
1312
|
* [SPEC 7 v0.4 Layer 2] When set, this `pending_action` represents a
|
|
1288
1313
|
* multi-write Payment Intent. Single-step bundles are NOT created — the
|
|
@@ -2078,6 +2103,51 @@ declare function bundleShortestTtl(toolUseIds: string[], toolNamesById: Record<s
|
|
|
2078
2103
|
/** The set of read tools whose results re-fire on REGENERATE. */
|
|
2079
2104
|
declare const REGENERATABLE_READ_TOOLS: ReadonlySet<string>;
|
|
2080
2105
|
|
|
2106
|
+
/**
|
|
2107
|
+
* [SPEC 20.2 / D-1 (a)] Match a `swap_execute` pending write against the
|
|
2108
|
+
* same-turn `swap_quote` reads to thread the captured Cetus route into
|
|
2109
|
+
* the emitted `pending_action.cetusRoute`.
|
|
2110
|
+
*
|
|
2111
|
+
* The match key is `(from, to, amount, byAmountIn)` — the four fields that
|
|
2112
|
+
* deterministically identify a Cetus route. `slippage` is NOT part of the
|
|
2113
|
+
* key because slippage is a tx-build-time parameter, not a route-discovery
|
|
2114
|
+
* parameter (Cetus's `findSwapRoute` does not take slippage).
|
|
2115
|
+
*
|
|
2116
|
+
* No match → return undefined → caller emits the pending_action without
|
|
2117
|
+
* `cetusRoute`, audric prepare-route falls back to fresh `findSwapRoute()`
|
|
2118
|
+
* (D-5 dual-path). This is the legacy path; correct behavior, just slower.
|
|
2119
|
+
*/
|
|
2120
|
+
|
|
2121
|
+
interface SwapQuoteInput {
|
|
2122
|
+
from: string;
|
|
2123
|
+
to: string;
|
|
2124
|
+
amount: number;
|
|
2125
|
+
byAmountIn?: boolean;
|
|
2126
|
+
}
|
|
2127
|
+
interface SwapQuoteResultLike {
|
|
2128
|
+
serializedRoute?: SerializedCetusRoute;
|
|
2129
|
+
}
|
|
2130
|
+
/**
|
|
2131
|
+
* Per-turn read-result entry for swap_quote matching. The engine collects
|
|
2132
|
+
* these alongside the existing `turnReadToolResults` metadata array;
|
|
2133
|
+
* `data` + `input` are populated only for successful `swap_quote` results.
|
|
2134
|
+
*/
|
|
2135
|
+
interface SwapQuoteReadEntry {
|
|
2136
|
+
toolUseId: string;
|
|
2137
|
+
input: SwapQuoteInput;
|
|
2138
|
+
result: SwapQuoteResultLike;
|
|
2139
|
+
timestamp: number;
|
|
2140
|
+
}
|
|
2141
|
+
/**
|
|
2142
|
+
* Return the most recent matching `swap_quote`'s serialized route, or
|
|
2143
|
+
* undefined if no same-turn quote matches the swap_execute's input.
|
|
2144
|
+
*
|
|
2145
|
+
* "Most recent" matters when the LLM calls `swap_quote` multiple times in
|
|
2146
|
+
* the same turn (e.g. exploring different amounts) — the most recent
|
|
2147
|
+
* matching quote is the one the user just saw on the quote card.
|
|
2148
|
+
*/
|
|
2149
|
+
declare function findMatchingCetusRoute(swapExecuteInput: unknown, swapQuoteReads: SwapQuoteReadEntry[]): SerializedCetusRoute | undefined;
|
|
2150
|
+
|
|
2081
2151
|
/**
|
|
2082
2152
|
* [Phase 0 → Phase 3a / SPEC 13] Maximum number of writes per atomic bundle.
|
|
2083
2153
|
*
|
|
@@ -2230,6 +2300,14 @@ interface BundleCompositionInput {
|
|
|
2230
2300
|
toolName: string;
|
|
2231
2301
|
timestamp: number;
|
|
2232
2302
|
}>;
|
|
2303
|
+
/**
|
|
2304
|
+
* [SPEC 20.2 / D-1 (a)] Same-turn `swap_quote` results paired with their
|
|
2305
|
+
* input + serialized Cetus route. Used to populate `step.cetusRoute` for
|
|
2306
|
+
* any `swap_execute` step whose input matches a quote. Empty / undefined
|
|
2307
|
+
* is fine — the bundle still composes correctly without per-step routes
|
|
2308
|
+
* (audric's prepare-route falls back to fresh `findSwapRoute()`).
|
|
2309
|
+
*/
|
|
2310
|
+
swapQuoteReads?: SwapQuoteReadEntry[];
|
|
2233
2311
|
/** Full assistant message blocks for the deferred turn (engine.ts uses this). */
|
|
2234
2312
|
assistantContent: ContentBlock[];
|
|
2235
2313
|
/** Already-resolved tool_result blocks (early-dispatched reads + auto writes). */
|
|
@@ -4347,4 +4425,4 @@ declare function getTelemetrySink(): TelemetrySink;
|
|
|
4347
4425
|
/** Restore the default noop sink. Used by test teardowns. */
|
|
4348
4426
|
declare function resetTelemetrySink(): void;
|
|
4349
4427
|
|
|
4350
|
-
export { type AddressPortfolio, AnthropicProvider, type AnthropicProviderConfig, type AudricHistoryRecord, type AudricPortfolioResult, type AwaitOrFetchOpts, type BalancePrices, type BalanceResult, BalanceTracker, type BuildToolOptions, type BundleCompositionInput, CANVAS_TEMPLATES, type CanvasTemplate, type ChatParams, type CompactOptions, type ContentBlock, ContextBudget, type ContextBudgetConfig, type ConversationState, type ConversationStateStore, type CostSnapshot, CostTracker, type CostTrackerConfig, DEFAULT_GUARD_CONFIG, DEFAULT_LEASE_SEC, DEFAULT_PERMISSION_CONFIG, DEFAULT_POLL_BUDGET_MS, DEFAULT_POLL_INTERVAL_MS, DEFAULT_SYSTEM_PROMPT, DEFAULT_TOOL_TTL_MS, type DefiCacheEntry, type DefiCacheStore, type DefiProtocol, type DefiSummary, EFFORT_THINKING_BUDGET_CAPS, EarlyToolDispatcher, type EngineConfig, type EngineEvent, type EvalSummaryParseResult, type EvaluationItem, type EvaluationStatus, type FetchLock, type FormField, type FormFieldKind, type FormSchema, type GuardCheckResult, type GuardConfig, type GuardEvent, type GuardInjection, type GuardResult, type GuardRunnerState, type GuardTier, type GuardVerdict, type HarnessShape, type HealthFactorResult, InMemoryDefiCacheStore, InMemoryFetchLock, InMemoryNaviCacheStore, InMemoryWalletCacheStore, InvalidAddressError, type LLMProvider, MAX_BUNDLE_OPS, type McpCallResult, McpClientManager, McpResponseCache, type McpServerConfig, type McpServerConnection, type McpToolAdapterConfig, type McpToolDescriptor, MemorySessionStore, type Message, NAVI_ADDR_TTL_SEC, NAVI_MCP_CONFIG, NAVI_MCP_URL, NAVI_RATES_TTL_SEC, NAVI_SERVER_NAME, type NaviCacheEntry, type NaviCacheStore, type NaviRawCoin, type NaviRawHealthFactor, type NaviRawPool, type NaviRawPosition, type NaviRawPositionsResponse, type NaviRawProtocolStats, type NaviRawRewardsResponse, type NaviReadOptions, NaviTools, type NormalizedAddress, type OutputConfig, PERMISSION_PRESETS, type PendingAction, type PendingActionModifiableField, type PendingActionStep, type PendingInput, type PendingInputState, type PendingReward, type PendingToolCall, type PermissionLevel, type PermissionOperation, type PermissionResponse, type PermissionRule, type PortfolioCoin, type PositionEntry, type PostWritePollOptions, type PostWritePollOutcome, type PostWritePollResult, type PreflightResult, type ProactiveMarker, type ProactiveType, type ProtocolStats, type ProviderEvent, QueryEngine, READ_TOOLS, REGENERATABLE_READ_TOOLS, type RatesResult, type Recipe, type RecipePrerequisite, RecipeRegistry, type RecipeStep, type RecipeStepOnError, type RegenerateFailure, type RegenerateResult, type RegenerateSuccess, type RegenerateTimelineEvent, RetryTracker, type SSEEvent, SUINS_NAME_REGEX, SUI_ADDRESS_REGEX, SUI_ADDRESS_STRICT_REGEX, type SavingsResult, type ServerPositionData, type SessionData, type SessionStore, type StateType, type StopReason, type SuiCoinBalance, SuinsNotRegisteredError, SuinsRpcError, type SystemBlock, type SystemPrompt, TOOL_FLAGS, TOOL_MODIFIABLE_FIELDS, TOOL_TTL_MS, type TelemetrySink, type TelemetryTags, type ThinkingConfig, type ThinkingEffort, type TodoItem$1 as TodoItem, type Tool, type ToolChoice, type ToolContext, type ToolDefinition, type ToolFlags, type ToolJsonSchema, type ToolResult, TxMutex, type UpdateTodoInput, type TodoItem as UpdateTodoItem, type UserFinancialProfile, type UserPermissionConfig, VALID_PAIRS, WRITE_TOOLS, type WalletCacheEntry, type WalletCacheStore, type WalletCoin, _resetNaviCircuitBreaker, activitySummaryTool, adaptAllMcpTools, adaptAllServerTools, adaptMcpTool, addRecipientTool, applyToolFlags, awaitOrFetch, balanceCheckTool, borrowTool, budgetToolResult, buildCachedSystemPrompt, buildMcpTools, buildProactivenessInstructions, buildProfileContext, buildSelfEvaluationInstruction, buildStateContext, buildTool, bundleShortestTtl, checkValidPair, claimRewardsTool, clampThinkingForEffort, classifyEffort, clearPortfolioCache, clearPortfolioCacheFor, clearPriceMapCache, compactMessages, composeBundleFromToolResults, computeRegenerateFields, createGuardRunnerState, engineToSSE, estimateTokens, explainTxTool, extractAllProactiveMarkers, extractConversationText, extractMcpText, extractTrustedAddressesFromResult, fetchAddressDefiPortfolio, fetchAddressPortfolio, fetchAudricHistory, fetchAudricPortfolio, fetchAvailableRewards, fetchBalance, fetchHealthFactor, fetchPositions, fetchProtocolStats, fetchRates, fetchSavings, fetchTokenPrices, fetchWalletCoins, findTool, getAudricApiBase, getDefaultTools, getDefiCacheStore, getFetchLock, getMcpManager, getModifiableFields, getNaviCacheStore, getTelemetrySink, getToolFlags, getWalletAddress, getWalletCacheStore, guardArtifactPreview, guardStaleData, harnessShapeForEffort, hasNaviMcp, healthCheckTool, isBundleableTool, loadRecipes, looksLikeSuiNs, microcompact, mppServicesTool, naviKey, normalizeAddressInput, parseEvalSummary, parseMcpJson, parseProactiveMarker, parseRecipe, parseSSE, payApiTool, pollForIndexerCatchup, portfolioAnalysisTool, protocolDeepDiveTool, ratesInfoTool, regenerateBundle, registerEngineTools, renderCanvasTool, repayDebtTool, requireAgent, resetDefiCacheStore, resetFetchLock, resetNaviCacheStore, resetTelemetrySink, resetWalletCacheStore, resolveAddressToSuinsViaRpc, resolvePermissionTier, resolveSuinsTool, resolveSuinsViaRpc, resolveUsdValue, runGuards, runTools, saveContactTool, saveDepositTool, savingsInfoTool, sendTransferTool, serializeSSE, setDefiCacheStore, setFetchLock, setNaviCacheStore, setTelemetrySink, setWalletCacheStore, spendingAnalyticsTool, stripProactiveMarkers, swapExecuteTool, swapQuoteTool, tokenPricesTool, toolNameToOperation, toolsToDefinitions, transactionHistoryTool, transformBalance, transformHealthFactor, transformPositions, transformRates, transformRewards, transformSavings, updateGuardStateAfterToolResult, updateTodoTool, validateHistory, voloStakeTool, voloStatsTool, voloUnstakeTool, webSearchTool, withdrawTool, yieldSummaryTool };
|
|
4428
|
+
export { type AddressPortfolio, AnthropicProvider, type AnthropicProviderConfig, type AudricHistoryRecord, type AudricPortfolioResult, type AwaitOrFetchOpts, type BalancePrices, type BalanceResult, BalanceTracker, type BuildToolOptions, type BundleCompositionInput, CANVAS_TEMPLATES, type CanvasTemplate, type ChatParams, type CompactOptions, type ContentBlock, ContextBudget, type ContextBudgetConfig, type ConversationState, type ConversationStateStore, type CostSnapshot, CostTracker, type CostTrackerConfig, DEFAULT_GUARD_CONFIG, DEFAULT_LEASE_SEC, DEFAULT_PERMISSION_CONFIG, DEFAULT_POLL_BUDGET_MS, DEFAULT_POLL_INTERVAL_MS, DEFAULT_SYSTEM_PROMPT, DEFAULT_TOOL_TTL_MS, type DefiCacheEntry, type DefiCacheStore, type DefiProtocol, type DefiSummary, EFFORT_THINKING_BUDGET_CAPS, EarlyToolDispatcher, type EngineConfig, type EngineEvent, type EvalSummaryParseResult, type EvaluationItem, type EvaluationStatus, type FetchLock, type FormField, type FormFieldKind, type FormSchema, type GuardCheckResult, type GuardConfig, type GuardEvent, type GuardInjection, type GuardResult, type GuardRunnerState, type GuardTier, type GuardVerdict, type HarnessShape, type HealthFactorResult, InMemoryDefiCacheStore, InMemoryFetchLock, InMemoryNaviCacheStore, InMemoryWalletCacheStore, InvalidAddressError, type LLMProvider, MAX_BUNDLE_OPS, type McpCallResult, McpClientManager, McpResponseCache, type McpServerConfig, type McpServerConnection, type McpToolAdapterConfig, type McpToolDescriptor, MemorySessionStore, type Message, NAVI_ADDR_TTL_SEC, NAVI_MCP_CONFIG, NAVI_MCP_URL, NAVI_RATES_TTL_SEC, NAVI_SERVER_NAME, type NaviCacheEntry, type NaviCacheStore, type NaviRawCoin, type NaviRawHealthFactor, type NaviRawPool, type NaviRawPosition, type NaviRawPositionsResponse, type NaviRawProtocolStats, type NaviRawRewardsResponse, type NaviReadOptions, NaviTools, type NormalizedAddress, type OutputConfig, PERMISSION_PRESETS, type PendingAction, type PendingActionModifiableField, type PendingActionStep, type PendingInput, type PendingInputState, type PendingReward, type PendingToolCall, type PermissionLevel, type PermissionOperation, type PermissionResponse, type PermissionRule, type PortfolioCoin, type PositionEntry, type PostWritePollOptions, type PostWritePollOutcome, type PostWritePollResult, type PreflightResult, type ProactiveMarker, type ProactiveType, type ProtocolStats, type ProviderEvent, QueryEngine, READ_TOOLS, REGENERATABLE_READ_TOOLS, type RatesResult, type Recipe, type RecipePrerequisite, RecipeRegistry, type RecipeStep, type RecipeStepOnError, type RegenerateFailure, type RegenerateResult, type RegenerateSuccess, type RegenerateTimelineEvent, RetryTracker, type SSEEvent, SUINS_NAME_REGEX, SUI_ADDRESS_REGEX, SUI_ADDRESS_STRICT_REGEX, type SavingsResult, type ServerPositionData, type SessionData, type SessionStore, type StateType, type StopReason, type SuiCoinBalance, SuinsNotRegisteredError, SuinsRpcError, type SwapQuoteReadEntry, type SystemBlock, type SystemPrompt, TOOL_FLAGS, TOOL_MODIFIABLE_FIELDS, TOOL_TTL_MS, type TelemetrySink, type TelemetryTags, type ThinkingConfig, type ThinkingEffort, type TodoItem$1 as TodoItem, type Tool, type ToolChoice, type ToolContext, type ToolDefinition, type ToolFlags, type ToolJsonSchema, type ToolResult, TxMutex, type UpdateTodoInput, type TodoItem as UpdateTodoItem, type UserFinancialProfile, type UserPermissionConfig, VALID_PAIRS, WRITE_TOOLS, type WalletCacheEntry, type WalletCacheStore, type WalletCoin, _resetNaviCircuitBreaker, activitySummaryTool, adaptAllMcpTools, adaptAllServerTools, adaptMcpTool, addRecipientTool, applyToolFlags, awaitOrFetch, balanceCheckTool, borrowTool, budgetToolResult, buildCachedSystemPrompt, buildMcpTools, buildProactivenessInstructions, buildProfileContext, buildSelfEvaluationInstruction, buildStateContext, buildTool, bundleShortestTtl, checkValidPair, claimRewardsTool, clampThinkingForEffort, classifyEffort, clearPortfolioCache, clearPortfolioCacheFor, clearPriceMapCache, compactMessages, composeBundleFromToolResults, computeRegenerateFields, createGuardRunnerState, engineToSSE, estimateTokens, explainTxTool, extractAllProactiveMarkers, extractConversationText, extractMcpText, extractTrustedAddressesFromResult, fetchAddressDefiPortfolio, fetchAddressPortfolio, fetchAudricHistory, fetchAudricPortfolio, fetchAvailableRewards, fetchBalance, fetchHealthFactor, fetchPositions, fetchProtocolStats, fetchRates, fetchSavings, fetchTokenPrices, fetchWalletCoins, findMatchingCetusRoute, findTool, getAudricApiBase, getDefaultTools, getDefiCacheStore, getFetchLock, getMcpManager, getModifiableFields, getNaviCacheStore, getTelemetrySink, getToolFlags, getWalletAddress, getWalletCacheStore, guardArtifactPreview, guardStaleData, harnessShapeForEffort, hasNaviMcp, healthCheckTool, isBundleableTool, loadRecipes, looksLikeSuiNs, microcompact, mppServicesTool, naviKey, normalizeAddressInput, parseEvalSummary, parseMcpJson, parseProactiveMarker, parseRecipe, parseSSE, payApiTool, pollForIndexerCatchup, portfolioAnalysisTool, protocolDeepDiveTool, ratesInfoTool, regenerateBundle, registerEngineTools, renderCanvasTool, repayDebtTool, requireAgent, resetDefiCacheStore, resetFetchLock, resetNaviCacheStore, resetTelemetrySink, resetWalletCacheStore, resolveAddressToSuinsViaRpc, resolvePermissionTier, resolveSuinsTool, resolveSuinsViaRpc, resolveUsdValue, runGuards, runTools, saveContactTool, saveDepositTool, savingsInfoTool, sendTransferTool, serializeSSE, setDefiCacheStore, setFetchLock, setNaviCacheStore, setTelemetrySink, setWalletCacheStore, spendingAnalyticsTool, stripProactiveMarkers, swapExecuteTool, swapQuoteTool, tokenPricesTool, toolNameToOperation, toolsToDefinitions, transactionHistoryTool, transformBalance, transformHealthFactor, transformPositions, transformRates, transformRewards, transformSavings, updateGuardStateAfterToolResult, updateTodoTool, validateHistory, voloStakeTool, voloStatsTool, voloUnstakeTool, webSearchTool, withdrawTool, yieldSummaryTool };
|
package/dist/index.js
CHANGED
|
@@ -3771,6 +3771,34 @@ var swapQuoteTool = buildTool({
|
|
|
3771
3771
|
required: ["from", "to", "amount"]
|
|
3772
3772
|
},
|
|
3773
3773
|
isReadOnly: true,
|
|
3774
|
+
// [SPEC 20.2 / D-1 (a) follow-on, 2026-05-10] Quote results MUST NOT be
|
|
3775
|
+
// cross-turn deduped by microcompact. Every call legitimately produces a
|
|
3776
|
+
// new result — pool reserves move per block, slippage windows update, the
|
|
3777
|
+
// best route can shift if liquidity moves, and the result's `discoveredAt`
|
|
3778
|
+
// timestamp is different per call by definition.
|
|
3779
|
+
//
|
|
3780
|
+
// Pre-fix: microcompact's default `cacheable: true` replaced the second
|
|
3781
|
+
// identical-input swap_quote tool_result with a `[Same result as call #N
|
|
3782
|
+
// — swap_quote with identical inputs. Result unchanged.]` placeholder.
|
|
3783
|
+
// The placeholder lied — the route and `discoveredAt` had legitimately
|
|
3784
|
+
// updated. Audric's bundle fast-path (which reads quote results from the
|
|
3785
|
+
// persisted ledger to thread `step.cetusRoute`) lost the fresh route and
|
|
3786
|
+
// had to fall back to whichever earlier same-input call WAS preserved
|
|
3787
|
+
// (the "first-seen" anchor, often >30s old → rejected by audric's
|
|
3788
|
+
// `isCetusRouteFresh` 30s gate → fast path missed → bundle paid full
|
|
3789
|
+
// ~400-500ms `findSwapRoute()` round-trip at confirm time).
|
|
3790
|
+
//
|
|
3791
|
+
// Production smoke trace (2026-05-10, session s_1778362657811_c0ed9009a5fb):
|
|
3792
|
+
// T0 swap_quote(USDC,SUI,0.5) → route X discovered
|
|
3793
|
+
// T0+34s swap_quote(USDC,SUI,0.5) [bundle] → route Y discovered (FRESH)
|
|
3794
|
+
// T0+50s "Confirm" → fast-path walks history → walker sees placeholder
|
|
3795
|
+
// on route Y, falls back
|
|
3796
|
+
// to route X (52s old)
|
|
3797
|
+
// T0+52s prepare → cetusRoute STALE → fallback → no perf win
|
|
3798
|
+
//
|
|
3799
|
+
// With `cacheable: false`: route Y stays as full content in the ledger,
|
|
3800
|
+
// walker finds it (~18s old), passes the freshness gate, fast path fires.
|
|
3801
|
+
cacheable: false,
|
|
3774
3802
|
async call(input, context) {
|
|
3775
3803
|
const walletAddress = context.agent ? context.agent.address() : getWalletAddress(context);
|
|
3776
3804
|
const sink = getTelemetrySink();
|
|
@@ -7235,6 +7263,34 @@ var REGENERATABLE_READ_TOOLS = /* @__PURE__ */ new Set([
|
|
|
7235
7263
|
"health_check"
|
|
7236
7264
|
]);
|
|
7237
7265
|
|
|
7266
|
+
// src/swap-route-matching.ts
|
|
7267
|
+
function findMatchingCetusRoute(swapExecuteInput, swapQuoteReads) {
|
|
7268
|
+
if (!isSwapExecuteInput(swapExecuteInput)) return void 0;
|
|
7269
|
+
if (swapQuoteReads.length === 0) return void 0;
|
|
7270
|
+
const target = normalizeSwapKey(swapExecuteInput);
|
|
7271
|
+
for (let i = swapQuoteReads.length - 1; i >= 0; i--) {
|
|
7272
|
+
const entry = swapQuoteReads[i];
|
|
7273
|
+
const candidate = normalizeSwapKey(entry.input);
|
|
7274
|
+
if (candidate.from === target.from && candidate.to === target.to && candidate.amount === target.amount && candidate.byAmountIn === target.byAmountIn) {
|
|
7275
|
+
return entry.result.serializedRoute;
|
|
7276
|
+
}
|
|
7277
|
+
}
|
|
7278
|
+
return void 0;
|
|
7279
|
+
}
|
|
7280
|
+
function isSwapExecuteInput(input) {
|
|
7281
|
+
if (typeof input !== "object" || input === null) return false;
|
|
7282
|
+
const obj = input;
|
|
7283
|
+
return typeof obj.from === "string" && typeof obj.to === "string" && typeof obj.amount === "number";
|
|
7284
|
+
}
|
|
7285
|
+
function normalizeSwapKey(input) {
|
|
7286
|
+
return {
|
|
7287
|
+
from: input.from.toLowerCase(),
|
|
7288
|
+
to: input.to.toLowerCase(),
|
|
7289
|
+
amount: input.amount,
|
|
7290
|
+
byAmountIn: input.byAmountIn ?? true
|
|
7291
|
+
};
|
|
7292
|
+
}
|
|
7293
|
+
|
|
7238
7294
|
// src/compose-bundle.ts
|
|
7239
7295
|
var MAX_BUNDLE_OPS = 4;
|
|
7240
7296
|
var VALID_PAIRS = /* @__PURE__ */ new Set([
|
|
@@ -7310,13 +7366,15 @@ function composeBundleFromToolResults(input) {
|
|
|
7310
7366
|
}
|
|
7311
7367
|
const description = describeAction(tool, call);
|
|
7312
7368
|
const modifiableFields = getModifiableFields(call.name);
|
|
7369
|
+
const cetusRoute = call.name === "swap_execute" && input.swapQuoteReads ? findMatchingCetusRoute(call.input, input.swapQuoteReads) : void 0;
|
|
7313
7370
|
return {
|
|
7314
7371
|
toolName: call.name,
|
|
7315
7372
|
toolUseId: call.id,
|
|
7316
7373
|
attemptId: randomUUID(),
|
|
7317
7374
|
input: call.input,
|
|
7318
7375
|
description,
|
|
7319
|
-
...modifiableFields?.length ? { modifiableFields } : {}
|
|
7376
|
+
...modifiableFields?.length ? { modifiableFields } : {},
|
|
7377
|
+
...cetusRoute ? { cetusRoute } : {}
|
|
7320
7378
|
};
|
|
7321
7379
|
});
|
|
7322
7380
|
for (let i = 1; i < input.pendingWrites.length; i++) {
|
|
@@ -7349,6 +7407,10 @@ function composeBundleFromToolResults(input) {
|
|
|
7349
7407
|
...allGuardInjections.length ? { guardInjections: allGuardInjections } : {},
|
|
7350
7408
|
turnIndex: input.turnIndex,
|
|
7351
7409
|
attemptId: firstStep.attemptId,
|
|
7410
|
+
// [SPEC 20.2 / D-1 (a)] Mirror step[0]'s cetusRoute to the top-level
|
|
7411
|
+
// field for backward compat with pre-bundle hosts that don't iterate
|
|
7412
|
+
// steps[]. Bundle-aware hosts read per-step `step.cetusRoute`.
|
|
7413
|
+
...firstStep.cetusRoute ? { cetusRoute: firstStep.cetusRoute } : {},
|
|
7352
7414
|
steps,
|
|
7353
7415
|
canRegenerate,
|
|
7354
7416
|
...quoteAge !== void 0 ? { quoteAge } : {},
|
|
@@ -7606,6 +7668,10 @@ var QueryEngine = class {
|
|
|
7606
7668
|
})),
|
|
7607
7669
|
...writeResultBlocks
|
|
7608
7670
|
];
|
|
7671
|
+
const canonicalRouteText = response.approved ? buildCanonicalRouteText(action) : null;
|
|
7672
|
+
if (canonicalRouteText) {
|
|
7673
|
+
allResults.push({ type: "text", text: canonicalRouteText });
|
|
7674
|
+
}
|
|
7609
7675
|
this.messages.push({ role: "user", content: allResults });
|
|
7610
7676
|
if (isBundle) {
|
|
7611
7677
|
const steps = action.steps;
|
|
@@ -8155,6 +8221,7 @@ var QueryEngine = class {
|
|
|
8155
8221
|
sink.gauge("engine.turn_turns_used", turns, tags);
|
|
8156
8222
|
};
|
|
8157
8223
|
const turnReadToolResults = [];
|
|
8224
|
+
const swapQuoteReads = [];
|
|
8158
8225
|
while (turns < this.maxTurns) {
|
|
8159
8226
|
if (signal.aborted) {
|
|
8160
8227
|
yield { type: "error", error: new Error("Aborted") };
|
|
@@ -8337,6 +8404,19 @@ ${recipeCtx}`;
|
|
|
8337
8404
|
toolName: finalEvent.toolName,
|
|
8338
8405
|
timestamp: Date.now()
|
|
8339
8406
|
});
|
|
8407
|
+
if (finalEvent.toolName === "swap_quote" && earlyInput) {
|
|
8408
|
+
const r = finalEvent.result;
|
|
8409
|
+
const dataResult = r?.data && typeof r.data === "object" ? r.data : null;
|
|
8410
|
+
const serializedRoute = r?.serializedRoute ?? dataResult?.serializedRoute;
|
|
8411
|
+
if (serializedRoute) {
|
|
8412
|
+
swapQuoteReads.push({
|
|
8413
|
+
toolUseId: finalEvent.toolUseId,
|
|
8414
|
+
input: earlyInput,
|
|
8415
|
+
result: { serializedRoute },
|
|
8416
|
+
timestamp: Date.now()
|
|
8417
|
+
});
|
|
8418
|
+
}
|
|
8419
|
+
}
|
|
8340
8420
|
}
|
|
8341
8421
|
earlyResultBlocks.push({
|
|
8342
8422
|
type: "tool_result",
|
|
@@ -8578,6 +8658,19 @@ ${recipeCtx}`;
|
|
|
8578
8658
|
toolName: finalEvent.toolName,
|
|
8579
8659
|
timestamp: Date.now()
|
|
8580
8660
|
});
|
|
8661
|
+
if (finalEvent.toolName === "swap_quote" && originalCall) {
|
|
8662
|
+
const r = finalEvent.result;
|
|
8663
|
+
const dataResult = r?.data && typeof r.data === "object" ? r.data : null;
|
|
8664
|
+
const serializedRoute = r?.serializedRoute ?? dataResult?.serializedRoute;
|
|
8665
|
+
if (serializedRoute) {
|
|
8666
|
+
swapQuoteReads.push({
|
|
8667
|
+
toolUseId: finalEvent.toolUseId,
|
|
8668
|
+
input: originalCall.input,
|
|
8669
|
+
result: { serializedRoute },
|
|
8670
|
+
timestamp: Date.now()
|
|
8671
|
+
});
|
|
8672
|
+
}
|
|
8673
|
+
}
|
|
8581
8674
|
} else {
|
|
8582
8675
|
this.turnReadCache.clear();
|
|
8583
8676
|
}
|
|
@@ -8728,6 +8821,7 @@ ${recipeCtx}`;
|
|
|
8728
8821
|
pendingWrites: guardPassedWrites.map((w) => w.call),
|
|
8729
8822
|
tools: this.tools,
|
|
8730
8823
|
readResults: turnReadToolResults,
|
|
8824
|
+
swapQuoteReads,
|
|
8731
8825
|
assistantContent: acc.assistantBlocks,
|
|
8732
8826
|
completedResults,
|
|
8733
8827
|
guardInjectionsByCallId,
|
|
@@ -8764,6 +8858,7 @@ ${recipeCtx}`;
|
|
|
8764
8858
|
const modifiableFields = getModifiableFields(pendingWrite.call.name);
|
|
8765
8859
|
const attemptId = randomUUID();
|
|
8766
8860
|
const singleWriteRegen = computeRegenerateFields(turnReadToolResults);
|
|
8861
|
+
const singleCetusRoute = pendingWrite.call.name === "swap_execute" ? findMatchingCetusRoute(pendingWrite.call.input, swapQuoteReads) : void 0;
|
|
8767
8862
|
yield {
|
|
8768
8863
|
type: "pending_action",
|
|
8769
8864
|
action: {
|
|
@@ -8781,6 +8876,7 @@ ${recipeCtx}`;
|
|
|
8781
8876
|
...modifiableFields?.length ? { modifiableFields } : {},
|
|
8782
8877
|
turnIndex,
|
|
8783
8878
|
attemptId,
|
|
8879
|
+
...singleCetusRoute ? { cetusRoute: singleCetusRoute } : {},
|
|
8784
8880
|
...singleWriteRegen.canRegenerate ? {
|
|
8785
8881
|
canRegenerate: true,
|
|
8786
8882
|
regenerateInput: { toolUseIds: singleWriteRegen.regenerateToolUseIds },
|
|
@@ -8932,6 +9028,35 @@ ${recipeCtx}`;
|
|
|
8932
9028
|
}
|
|
8933
9029
|
}
|
|
8934
9030
|
};
|
|
9031
|
+
function buildCanonicalRouteText(action) {
|
|
9032
|
+
const swaps = [];
|
|
9033
|
+
if (Array.isArray(action.steps) && action.steps.length > 0) {
|
|
9034
|
+
for (const step of action.steps) {
|
|
9035
|
+
if (step.toolName === "swap_execute" && step.cetusRoute) {
|
|
9036
|
+
swaps.push({ input: step.input, cetusRoute: step.cetusRoute });
|
|
9037
|
+
}
|
|
9038
|
+
}
|
|
9039
|
+
} else if (action.toolName === "swap_execute" && action.cetusRoute) {
|
|
9040
|
+
swaps.push({ input: action.input, cetusRoute: action.cetusRoute });
|
|
9041
|
+
}
|
|
9042
|
+
if (swaps.length === 0) return null;
|
|
9043
|
+
const blocks = swaps.map(({ input, cetusRoute }) => {
|
|
9044
|
+
const inp = input;
|
|
9045
|
+
const providers = cetusRoute.routerData.paths.map((p) => p.provider).filter(Boolean).slice(0, 5);
|
|
9046
|
+
const providerLine = providers.length > 0 ? providers.join(" + ") : "Cetus Aggregator";
|
|
9047
|
+
const impactPct = (cetusRoute.priceImpact * 100).toFixed(3);
|
|
9048
|
+
return [
|
|
9049
|
+
"<canonical_route>",
|
|
9050
|
+
`The user just approved a swap. The CANONICAL route taken on-chain is:`,
|
|
9051
|
+
`- Pair: ${inp?.from ?? "?"} \u2192 ${inp?.to ?? "?"}`,
|
|
9052
|
+
`- Path: ${providerLine}`,
|
|
9053
|
+
`- Price impact: ${impactPct}%`,
|
|
9054
|
+
`When narrating this swap, cite this EXACT path string. Do NOT reference any prior swap_quote that produced a different route \u2014 that quote is no longer canonical.`,
|
|
9055
|
+
"</canonical_route>"
|
|
9056
|
+
].join("\n");
|
|
9057
|
+
});
|
|
9058
|
+
return blocks.join("\n\n");
|
|
9059
|
+
}
|
|
8935
9060
|
function isCorruptHistoryError(err) {
|
|
8936
9061
|
const msg = err instanceof Error ? err.message : String(err);
|
|
8937
9062
|
return msg.includes("tool_use") && msg.includes("tool_result") || msg.includes("roles must alternate") || msg.includes("400") && msg.includes("invalid_request_error");
|
|
@@ -10498,6 +10623,6 @@ function sanitizeAnthropicMessages(messages) {
|
|
|
10498
10623
|
return merged;
|
|
10499
10624
|
}
|
|
10500
10625
|
|
|
10501
|
-
export { AnthropicProvider, BalanceTracker, CANVAS_TEMPLATES, ContextBudget, CostTracker, DEFAULT_GUARD_CONFIG, DEFAULT_LEASE_SEC, DEFAULT_PERMISSION_CONFIG, DEFAULT_POLL_BUDGET_MS, DEFAULT_POLL_INTERVAL_MS, DEFAULT_SYSTEM_PROMPT, DEFAULT_TOOL_TTL_MS, EFFORT_THINKING_BUDGET_CAPS, EarlyToolDispatcher, InMemoryDefiCacheStore, InMemoryFetchLock, InMemoryNaviCacheStore, InMemoryWalletCacheStore, InvalidAddressError, MAX_BUNDLE_OPS, McpClientManager, McpResponseCache, MemorySessionStore, NAVI_ADDR_TTL_SEC, NAVI_MCP_CONFIG, NAVI_MCP_URL, NAVI_RATES_TTL_SEC, NAVI_SERVER_NAME, NaviTools, PERMISSION_PRESETS, QueryEngine, READ_TOOLS, REGENERATABLE_READ_TOOLS, RecipeRegistry, RetryTracker, SUINS_NAME_REGEX, SUI_ADDRESS_REGEX, SUI_ADDRESS_STRICT_REGEX, SuinsNotRegisteredError, SuinsRpcError, TOOL_FLAGS, TOOL_MODIFIABLE_FIELDS, TOOL_TTL_MS, TxMutex, VALID_PAIRS, WRITE_TOOLS, _resetNaviCircuitBreaker, activitySummaryTool, adaptAllMcpTools, adaptAllServerTools, adaptMcpTool, addRecipientTool, applyToolFlags, awaitOrFetch, balanceCheckTool, borrowTool, budgetToolResult, buildCachedSystemPrompt, buildMcpTools, buildProactivenessInstructions, buildProfileContext, buildSelfEvaluationInstruction, buildStateContext, buildTool, bundleShortestTtl, checkValidPair, claimRewardsTool, clampThinkingForEffort, classifyEffort, clearPortfolioCache, clearPortfolioCacheFor, clearPriceMapCache, compactMessages, composeBundleFromToolResults, computeRegenerateFields, createGuardRunnerState, engineToSSE, estimateTokens, explainTxTool, extractAllProactiveMarkers, extractConversationText, extractMcpText, extractTrustedAddressesFromResult, fetchAddressDefiPortfolio, fetchAddressPortfolio, fetchAudricHistory, fetchAudricPortfolio, fetchAvailableRewards, fetchBalance, fetchHealthFactor, fetchPositions, fetchProtocolStats, fetchRates, fetchSavings, fetchTokenPrices, fetchWalletCoins, findTool, getAudricApiBase, getDefaultTools, getDefiCacheStore, getFetchLock, getMcpManager, getModifiableFields, getNaviCacheStore, getTelemetrySink, getToolFlags, getWalletAddress, getWalletCacheStore, guardArtifactPreview, guardStaleData, harnessShapeForEffort, hasNaviMcp, healthCheckTool, isBundleableTool, loadRecipes, looksLikeSuiNs, microcompact, mppServicesTool, naviKey, normalizeAddressInput, parseEvalSummary, parseMcpJson, parseProactiveMarker, parseRecipe, parseSSE, payApiTool, pollForIndexerCatchup, portfolioAnalysisTool, protocolDeepDiveTool, ratesInfoTool, regenerateBundle, registerEngineTools, renderCanvasTool, repayDebtTool, requireAgent, resetDefiCacheStore, resetFetchLock, resetNaviCacheStore, resetTelemetrySink, resetWalletCacheStore, resolveAddressToSuinsViaRpc, resolvePermissionTier, resolveSuinsTool, resolveSuinsViaRpc, resolveUsdValue, runGuards, runTools, saveContactTool, saveDepositTool, savingsInfoTool, sendTransferTool, serializeSSE, setDefiCacheStore, setFetchLock, setNaviCacheStore, setTelemetrySink, setWalletCacheStore, spendingAnalyticsTool, stripProactiveMarkers, swapExecuteTool, swapQuoteTool, tokenPricesTool, toolNameToOperation, toolsToDefinitions, transactionHistoryTool, transformBalance, transformHealthFactor, transformPositions, transformRates, transformRewards, transformSavings, updateGuardStateAfterToolResult, updateTodoTool, validateHistory, voloStakeTool, voloStatsTool, voloUnstakeTool, webSearchTool, withdrawTool, yieldSummaryTool };
|
|
10626
|
+
export { AnthropicProvider, BalanceTracker, CANVAS_TEMPLATES, ContextBudget, CostTracker, DEFAULT_GUARD_CONFIG, DEFAULT_LEASE_SEC, DEFAULT_PERMISSION_CONFIG, DEFAULT_POLL_BUDGET_MS, DEFAULT_POLL_INTERVAL_MS, DEFAULT_SYSTEM_PROMPT, DEFAULT_TOOL_TTL_MS, EFFORT_THINKING_BUDGET_CAPS, EarlyToolDispatcher, InMemoryDefiCacheStore, InMemoryFetchLock, InMemoryNaviCacheStore, InMemoryWalletCacheStore, InvalidAddressError, MAX_BUNDLE_OPS, McpClientManager, McpResponseCache, MemorySessionStore, NAVI_ADDR_TTL_SEC, NAVI_MCP_CONFIG, NAVI_MCP_URL, NAVI_RATES_TTL_SEC, NAVI_SERVER_NAME, NaviTools, PERMISSION_PRESETS, QueryEngine, READ_TOOLS, REGENERATABLE_READ_TOOLS, RecipeRegistry, RetryTracker, SUINS_NAME_REGEX, SUI_ADDRESS_REGEX, SUI_ADDRESS_STRICT_REGEX, SuinsNotRegisteredError, SuinsRpcError, TOOL_FLAGS, TOOL_MODIFIABLE_FIELDS, TOOL_TTL_MS, TxMutex, VALID_PAIRS, WRITE_TOOLS, _resetNaviCircuitBreaker, activitySummaryTool, adaptAllMcpTools, adaptAllServerTools, adaptMcpTool, addRecipientTool, applyToolFlags, awaitOrFetch, balanceCheckTool, borrowTool, budgetToolResult, buildCachedSystemPrompt, buildMcpTools, buildProactivenessInstructions, buildProfileContext, buildSelfEvaluationInstruction, buildStateContext, buildTool, bundleShortestTtl, checkValidPair, claimRewardsTool, clampThinkingForEffort, classifyEffort, clearPortfolioCache, clearPortfolioCacheFor, clearPriceMapCache, compactMessages, composeBundleFromToolResults, computeRegenerateFields, createGuardRunnerState, engineToSSE, estimateTokens, explainTxTool, extractAllProactiveMarkers, extractConversationText, extractMcpText, extractTrustedAddressesFromResult, fetchAddressDefiPortfolio, fetchAddressPortfolio, fetchAudricHistory, fetchAudricPortfolio, fetchAvailableRewards, fetchBalance, fetchHealthFactor, fetchPositions, fetchProtocolStats, fetchRates, fetchSavings, fetchTokenPrices, fetchWalletCoins, findMatchingCetusRoute, findTool, getAudricApiBase, getDefaultTools, getDefiCacheStore, getFetchLock, getMcpManager, getModifiableFields, getNaviCacheStore, getTelemetrySink, getToolFlags, getWalletAddress, getWalletCacheStore, guardArtifactPreview, guardStaleData, harnessShapeForEffort, hasNaviMcp, healthCheckTool, isBundleableTool, loadRecipes, looksLikeSuiNs, microcompact, mppServicesTool, naviKey, normalizeAddressInput, parseEvalSummary, parseMcpJson, parseProactiveMarker, parseRecipe, parseSSE, payApiTool, pollForIndexerCatchup, portfolioAnalysisTool, protocolDeepDiveTool, ratesInfoTool, regenerateBundle, registerEngineTools, renderCanvasTool, repayDebtTool, requireAgent, resetDefiCacheStore, resetFetchLock, resetNaviCacheStore, resetTelemetrySink, resetWalletCacheStore, resolveAddressToSuinsViaRpc, resolvePermissionTier, resolveSuinsTool, resolveSuinsViaRpc, resolveUsdValue, runGuards, runTools, saveContactTool, saveDepositTool, savingsInfoTool, sendTransferTool, serializeSSE, setDefiCacheStore, setFetchLock, setNaviCacheStore, setTelemetrySink, setWalletCacheStore, spendingAnalyticsTool, stripProactiveMarkers, swapExecuteTool, swapQuoteTool, tokenPricesTool, toolNameToOperation, toolsToDefinitions, transactionHistoryTool, transformBalance, transformHealthFactor, transformPositions, transformRates, transformRewards, transformSavings, updateGuardStateAfterToolResult, updateTodoTool, validateHistory, voloStakeTool, voloStatsTool, voloUnstakeTool, webSearchTool, withdrawTool, yieldSummaryTool };
|
|
10502
10627
|
//# sourceMappingURL=index.js.map
|
|
10503
10628
|
//# sourceMappingURL=index.js.map
|