@t2000/engine 1.24.14 → 1.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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
@@ -7235,6 +7235,34 @@ var REGENERATABLE_READ_TOOLS = /* @__PURE__ */ new Set([
7235
7235
  "health_check"
7236
7236
  ]);
7237
7237
 
7238
+ // src/swap-route-matching.ts
7239
+ function findMatchingCetusRoute(swapExecuteInput, swapQuoteReads) {
7240
+ if (!isSwapExecuteInput(swapExecuteInput)) return void 0;
7241
+ if (swapQuoteReads.length === 0) return void 0;
7242
+ const target = normalizeSwapKey(swapExecuteInput);
7243
+ for (let i = swapQuoteReads.length - 1; i >= 0; i--) {
7244
+ const entry = swapQuoteReads[i];
7245
+ const candidate = normalizeSwapKey(entry.input);
7246
+ if (candidate.from === target.from && candidate.to === target.to && candidate.amount === target.amount && candidate.byAmountIn === target.byAmountIn) {
7247
+ return entry.result.serializedRoute;
7248
+ }
7249
+ }
7250
+ return void 0;
7251
+ }
7252
+ function isSwapExecuteInput(input) {
7253
+ if (typeof input !== "object" || input === null) return false;
7254
+ const obj = input;
7255
+ return typeof obj.from === "string" && typeof obj.to === "string" && typeof obj.amount === "number";
7256
+ }
7257
+ function normalizeSwapKey(input) {
7258
+ return {
7259
+ from: input.from.toLowerCase(),
7260
+ to: input.to.toLowerCase(),
7261
+ amount: input.amount,
7262
+ byAmountIn: input.byAmountIn ?? true
7263
+ };
7264
+ }
7265
+
7238
7266
  // src/compose-bundle.ts
7239
7267
  var MAX_BUNDLE_OPS = 4;
7240
7268
  var VALID_PAIRS = /* @__PURE__ */ new Set([
@@ -7310,13 +7338,15 @@ function composeBundleFromToolResults(input) {
7310
7338
  }
7311
7339
  const description = describeAction(tool, call);
7312
7340
  const modifiableFields = getModifiableFields(call.name);
7341
+ const cetusRoute = call.name === "swap_execute" && input.swapQuoteReads ? findMatchingCetusRoute(call.input, input.swapQuoteReads) : void 0;
7313
7342
  return {
7314
7343
  toolName: call.name,
7315
7344
  toolUseId: call.id,
7316
7345
  attemptId: randomUUID(),
7317
7346
  input: call.input,
7318
7347
  description,
7319
- ...modifiableFields?.length ? { modifiableFields } : {}
7348
+ ...modifiableFields?.length ? { modifiableFields } : {},
7349
+ ...cetusRoute ? { cetusRoute } : {}
7320
7350
  };
7321
7351
  });
7322
7352
  for (let i = 1; i < input.pendingWrites.length; i++) {
@@ -7349,6 +7379,10 @@ function composeBundleFromToolResults(input) {
7349
7379
  ...allGuardInjections.length ? { guardInjections: allGuardInjections } : {},
7350
7380
  turnIndex: input.turnIndex,
7351
7381
  attemptId: firstStep.attemptId,
7382
+ // [SPEC 20.2 / D-1 (a)] Mirror step[0]'s cetusRoute to the top-level
7383
+ // field for backward compat with pre-bundle hosts that don't iterate
7384
+ // steps[]. Bundle-aware hosts read per-step `step.cetusRoute`.
7385
+ ...firstStep.cetusRoute ? { cetusRoute: firstStep.cetusRoute } : {},
7352
7386
  steps,
7353
7387
  canRegenerate,
7354
7388
  ...quoteAge !== void 0 ? { quoteAge } : {},
@@ -7606,6 +7640,10 @@ var QueryEngine = class {
7606
7640
  })),
7607
7641
  ...writeResultBlocks
7608
7642
  ];
7643
+ const canonicalRouteText = response.approved ? buildCanonicalRouteText(action) : null;
7644
+ if (canonicalRouteText) {
7645
+ allResults.push({ type: "text", text: canonicalRouteText });
7646
+ }
7609
7647
  this.messages.push({ role: "user", content: allResults });
7610
7648
  if (isBundle) {
7611
7649
  const steps = action.steps;
@@ -8155,6 +8193,7 @@ var QueryEngine = class {
8155
8193
  sink.gauge("engine.turn_turns_used", turns, tags);
8156
8194
  };
8157
8195
  const turnReadToolResults = [];
8196
+ const swapQuoteReads = [];
8158
8197
  while (turns < this.maxTurns) {
8159
8198
  if (signal.aborted) {
8160
8199
  yield { type: "error", error: new Error("Aborted") };
@@ -8337,6 +8376,19 @@ ${recipeCtx}`;
8337
8376
  toolName: finalEvent.toolName,
8338
8377
  timestamp: Date.now()
8339
8378
  });
8379
+ if (finalEvent.toolName === "swap_quote" && earlyInput) {
8380
+ const r = finalEvent.result;
8381
+ const dataResult = r?.data && typeof r.data === "object" ? r.data : null;
8382
+ const serializedRoute = r?.serializedRoute ?? dataResult?.serializedRoute;
8383
+ if (serializedRoute) {
8384
+ swapQuoteReads.push({
8385
+ toolUseId: finalEvent.toolUseId,
8386
+ input: earlyInput,
8387
+ result: { serializedRoute },
8388
+ timestamp: Date.now()
8389
+ });
8390
+ }
8391
+ }
8340
8392
  }
8341
8393
  earlyResultBlocks.push({
8342
8394
  type: "tool_result",
@@ -8578,6 +8630,19 @@ ${recipeCtx}`;
8578
8630
  toolName: finalEvent.toolName,
8579
8631
  timestamp: Date.now()
8580
8632
  });
8633
+ if (finalEvent.toolName === "swap_quote" && originalCall) {
8634
+ const r = finalEvent.result;
8635
+ const dataResult = r?.data && typeof r.data === "object" ? r.data : null;
8636
+ const serializedRoute = r?.serializedRoute ?? dataResult?.serializedRoute;
8637
+ if (serializedRoute) {
8638
+ swapQuoteReads.push({
8639
+ toolUseId: finalEvent.toolUseId,
8640
+ input: originalCall.input,
8641
+ result: { serializedRoute },
8642
+ timestamp: Date.now()
8643
+ });
8644
+ }
8645
+ }
8581
8646
  } else {
8582
8647
  this.turnReadCache.clear();
8583
8648
  }
@@ -8728,6 +8793,7 @@ ${recipeCtx}`;
8728
8793
  pendingWrites: guardPassedWrites.map((w) => w.call),
8729
8794
  tools: this.tools,
8730
8795
  readResults: turnReadToolResults,
8796
+ swapQuoteReads,
8731
8797
  assistantContent: acc.assistantBlocks,
8732
8798
  completedResults,
8733
8799
  guardInjectionsByCallId,
@@ -8764,6 +8830,7 @@ ${recipeCtx}`;
8764
8830
  const modifiableFields = getModifiableFields(pendingWrite.call.name);
8765
8831
  const attemptId = randomUUID();
8766
8832
  const singleWriteRegen = computeRegenerateFields(turnReadToolResults);
8833
+ const singleCetusRoute = pendingWrite.call.name === "swap_execute" ? findMatchingCetusRoute(pendingWrite.call.input, swapQuoteReads) : void 0;
8767
8834
  yield {
8768
8835
  type: "pending_action",
8769
8836
  action: {
@@ -8781,6 +8848,7 @@ ${recipeCtx}`;
8781
8848
  ...modifiableFields?.length ? { modifiableFields } : {},
8782
8849
  turnIndex,
8783
8850
  attemptId,
8851
+ ...singleCetusRoute ? { cetusRoute: singleCetusRoute } : {},
8784
8852
  ...singleWriteRegen.canRegenerate ? {
8785
8853
  canRegenerate: true,
8786
8854
  regenerateInput: { toolUseIds: singleWriteRegen.regenerateToolUseIds },
@@ -8932,6 +9000,35 @@ ${recipeCtx}`;
8932
9000
  }
8933
9001
  }
8934
9002
  };
9003
+ function buildCanonicalRouteText(action) {
9004
+ const swaps = [];
9005
+ if (Array.isArray(action.steps) && action.steps.length > 0) {
9006
+ for (const step of action.steps) {
9007
+ if (step.toolName === "swap_execute" && step.cetusRoute) {
9008
+ swaps.push({ input: step.input, cetusRoute: step.cetusRoute });
9009
+ }
9010
+ }
9011
+ } else if (action.toolName === "swap_execute" && action.cetusRoute) {
9012
+ swaps.push({ input: action.input, cetusRoute: action.cetusRoute });
9013
+ }
9014
+ if (swaps.length === 0) return null;
9015
+ const blocks = swaps.map(({ input, cetusRoute }) => {
9016
+ const inp = input;
9017
+ const providers = cetusRoute.routerData.paths.map((p) => p.provider).filter(Boolean).slice(0, 5);
9018
+ const providerLine = providers.length > 0 ? providers.join(" + ") : "Cetus Aggregator";
9019
+ const impactPct = (cetusRoute.priceImpact * 100).toFixed(3);
9020
+ return [
9021
+ "<canonical_route>",
9022
+ `The user just approved a swap. The CANONICAL route taken on-chain is:`,
9023
+ `- Pair: ${inp?.from ?? "?"} \u2192 ${inp?.to ?? "?"}`,
9024
+ `- Path: ${providerLine}`,
9025
+ `- Price impact: ${impactPct}%`,
9026
+ `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.`,
9027
+ "</canonical_route>"
9028
+ ].join("\n");
9029
+ });
9030
+ return blocks.join("\n\n");
9031
+ }
8935
9032
  function isCorruptHistoryError(err) {
8936
9033
  const msg = err instanceof Error ? err.message : String(err);
8937
9034
  return msg.includes("tool_use") && msg.includes("tool_result") || msg.includes("roles must alternate") || msg.includes("400") && msg.includes("invalid_request_error");
@@ -10498,6 +10595,6 @@ function sanitizeAnthropicMessages(messages) {
10498
10595
  return merged;
10499
10596
  }
10500
10597
 
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 };
10598
+ 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
10599
  //# sourceMappingURL=index.js.map
10503
10600
  //# sourceMappingURL=index.js.map