@t2000/engine 1.24.9 → 1.24.11
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 +56 -1
- package/dist/index.js +154 -9
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -53,6 +53,25 @@ declare function extractAllProactiveMarkers(text: string): Array<{
|
|
|
53
53
|
subjectKey: string;
|
|
54
54
|
}>;
|
|
55
55
|
|
|
56
|
+
type PostWritePollOutcome = 'detected_change' | 'ceiling' | 'aborted' | 'fallback_no_baseline' | 'fallback_no_address' | 'fallback_no_rpc';
|
|
57
|
+
interface PostWritePollResult {
|
|
58
|
+
outcome: PostWritePollOutcome;
|
|
59
|
+
/** Number of poll attempts made (0 if fallback fired before polling). */
|
|
60
|
+
attempts: number;
|
|
61
|
+
/** Wall-clock ms from `pollForIndexerCatchup` entry to return. */
|
|
62
|
+
resolvedAtMs: number;
|
|
63
|
+
}
|
|
64
|
+
interface PostWritePollOptions {
|
|
65
|
+
suiRpcUrl: string | undefined;
|
|
66
|
+
address: string | undefined;
|
|
67
|
+
/** Hard ceiling on total wait time. Default 1500ms (matches old fixed sleep). */
|
|
68
|
+
ceilingMs: number;
|
|
69
|
+
/** Wait between poll attempts. Default 250ms. */
|
|
70
|
+
pollIntervalMs: number;
|
|
71
|
+
signal: AbortSignal;
|
|
72
|
+
}
|
|
73
|
+
declare function pollForIndexerCatchup(options: PostWritePollOptions): Promise<PostWritePollResult>;
|
|
74
|
+
|
|
56
75
|
/** Rough token count for a message array. */
|
|
57
76
|
declare function estimateTokens(messages: Message[]): number;
|
|
58
77
|
interface CompactOptions {
|
|
@@ -1717,6 +1736,41 @@ interface EngineConfig {
|
|
|
1717
1736
|
* Omit (undefined / empty map) to disable post-write refresh entirely.
|
|
1718
1737
|
*/
|
|
1719
1738
|
postWriteRefresh?: Record<string, string[]>;
|
|
1739
|
+
/**
|
|
1740
|
+
* [SPEC 19 Phase B / 2026-05-09] Pre-warmed indexer-catchup poll Promise.
|
|
1741
|
+
*
|
|
1742
|
+
* Hosts that know the wallet address + Sui RPC URL the moment a resume
|
|
1743
|
+
* request lands (e.g. `app/api/engine/resume/route.ts`, where both are
|
|
1744
|
+
* available immediately after JWT validation) can fire
|
|
1745
|
+
* `pollForIndexerCatchup` in parallel with `createEngine` and pass the
|
|
1746
|
+
* returned Promise here. The engine awaits this Promise inside
|
|
1747
|
+
* `runPostWriteRefresh` instead of starting a fresh poll, eliminating
|
|
1748
|
+
* up to ~1.5s of serial wait when engine boot wall-clock ≥ poll
|
|
1749
|
+
* wall-clock.
|
|
1750
|
+
*
|
|
1751
|
+
* Behavior:
|
|
1752
|
+
* - Promise resolves before refresh starts → instant pass-through
|
|
1753
|
+
* (poll already done during boot). This is the typical case.
|
|
1754
|
+
* - Promise still pending when refresh starts → engine awaits it.
|
|
1755
|
+
* Net effect: same as pre-Phase-B fresh-poll behavior.
|
|
1756
|
+
* - Promise undefined → engine starts a fresh poll (pre-Phase-B path).
|
|
1757
|
+
* - Promise rejects → engine logs warn + falls back to fresh poll
|
|
1758
|
+
* (correctness preserved; same as `outcome: 'fallback_*'`).
|
|
1759
|
+
*
|
|
1760
|
+
* Telemetry: `engine.pwr.sleep_ms` carries `source` tag = `'pre-warmed' | 'engine'`
|
|
1761
|
+
* so the host can verify the parallelization is shaving wall-clock.
|
|
1762
|
+
* On the pre-warmed path, the `outcome` + `attempts` tags are inherited
|
|
1763
|
+
* from the host's poll result — same shape, just resolved earlier.
|
|
1764
|
+
*
|
|
1765
|
+
* Safe because:
|
|
1766
|
+
* - Poll baseline is captured via Sui RPC `getAllBalances` and is
|
|
1767
|
+
* independent of any BlockVision cache state. Pre-firing the poll
|
|
1768
|
+
* before engine boot does NOT race the engine's cache invalidation.
|
|
1769
|
+
* - The poll's correctness contract (never proceed until indexer
|
|
1770
|
+
* reflects the write) is preserved — it just runs on a different
|
|
1771
|
+
* timeline.
|
|
1772
|
+
*/
|
|
1773
|
+
indexerCatchupPromise?: Promise<PostWritePollResult>;
|
|
1720
1774
|
}
|
|
1721
1775
|
interface LLMProvider {
|
|
1722
1776
|
chat(params: ChatParams): AsyncGenerator<ProviderEvent>;
|
|
@@ -1867,6 +1921,7 @@ declare class QueryEngine {
|
|
|
1867
1921
|
private readonly blockvisionApiKey;
|
|
1868
1922
|
private readonly portfolioCache;
|
|
1869
1923
|
private readonly postWriteRefresh;
|
|
1924
|
+
private readonly indexerCatchupPromise;
|
|
1870
1925
|
private matchedRecipe;
|
|
1871
1926
|
private messages;
|
|
1872
1927
|
private abortController;
|
|
@@ -4328,4 +4383,4 @@ declare function getTelemetrySink(): TelemetrySink;
|
|
|
4328
4383
|
/** Restore the default noop sink. Used by test teardowns. */
|
|
4329
4384
|
declare function resetTelemetrySink(): void;
|
|
4330
4385
|
|
|
4331
|
-
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 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, 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 };
|
|
4386
|
+
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 };
|
package/dist/index.js
CHANGED
|
@@ -5786,6 +5786,120 @@ Only offer to execute actions you have tools for. If you retrieved a quote, data
|
|
|
5786
5786
|
- Cap: at most ONE proactive block per turn.
|
|
5787
5787
|
- Skip proactive blocks when nothing notable changed since the last turn, when the user is mid-flow on something else, or when you'd just be restating the financial-context block. Quality over quantity \u2014 a block ignored is worse than no block.`;
|
|
5788
5788
|
|
|
5789
|
+
// src/post-write-poll.ts
|
|
5790
|
+
async function pollForIndexerCatchup(options) {
|
|
5791
|
+
const { suiRpcUrl, address, ceilingMs, pollIntervalMs, signal } = options;
|
|
5792
|
+
const start = Date.now();
|
|
5793
|
+
if (!suiRpcUrl) {
|
|
5794
|
+
await sleepWithFallback(ceilingMs, signal);
|
|
5795
|
+
return {
|
|
5796
|
+
outcome: "fallback_no_rpc",
|
|
5797
|
+
attempts: 0,
|
|
5798
|
+
resolvedAtMs: Date.now() - start
|
|
5799
|
+
};
|
|
5800
|
+
}
|
|
5801
|
+
if (!address) {
|
|
5802
|
+
await sleepWithFallback(ceilingMs, signal);
|
|
5803
|
+
return {
|
|
5804
|
+
outcome: "fallback_no_address",
|
|
5805
|
+
attempts: 0,
|
|
5806
|
+
resolvedAtMs: Date.now() - start
|
|
5807
|
+
};
|
|
5808
|
+
}
|
|
5809
|
+
let baseline;
|
|
5810
|
+
try {
|
|
5811
|
+
const coins = await fetchWalletCoins(address, suiRpcUrl);
|
|
5812
|
+
baseline = new Map(
|
|
5813
|
+
coins.map((c) => [c.coinType, BigInt(c.totalBalance)])
|
|
5814
|
+
);
|
|
5815
|
+
} catch (err) {
|
|
5816
|
+
console.warn(
|
|
5817
|
+
"[post-write-poll] baseline fetch failed; falling back to fixed sleep:",
|
|
5818
|
+
err
|
|
5819
|
+
);
|
|
5820
|
+
await sleepWithFallback(ceilingMs, signal);
|
|
5821
|
+
return {
|
|
5822
|
+
outcome: "fallback_no_baseline",
|
|
5823
|
+
attempts: 0,
|
|
5824
|
+
resolvedAtMs: Date.now() - start
|
|
5825
|
+
};
|
|
5826
|
+
}
|
|
5827
|
+
const maxAttempts = Math.max(1, Math.floor(ceilingMs / pollIntervalMs));
|
|
5828
|
+
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
5829
|
+
if (signal.aborted) {
|
|
5830
|
+
return {
|
|
5831
|
+
outcome: "aborted",
|
|
5832
|
+
attempts: attempt - 1,
|
|
5833
|
+
resolvedAtMs: Date.now() - start
|
|
5834
|
+
};
|
|
5835
|
+
}
|
|
5836
|
+
await new Promise((resolve) => {
|
|
5837
|
+
const t = setTimeout(resolve, pollIntervalMs);
|
|
5838
|
+
signal.addEventListener(
|
|
5839
|
+
"abort",
|
|
5840
|
+
() => {
|
|
5841
|
+
clearTimeout(t);
|
|
5842
|
+
resolve();
|
|
5843
|
+
},
|
|
5844
|
+
{ once: true }
|
|
5845
|
+
);
|
|
5846
|
+
});
|
|
5847
|
+
if (signal.aborted) {
|
|
5848
|
+
return {
|
|
5849
|
+
outcome: "aborted",
|
|
5850
|
+
attempts: attempt,
|
|
5851
|
+
resolvedAtMs: Date.now() - start
|
|
5852
|
+
};
|
|
5853
|
+
}
|
|
5854
|
+
let current;
|
|
5855
|
+
try {
|
|
5856
|
+
const coins = await fetchWalletCoins(address, suiRpcUrl);
|
|
5857
|
+
current = new Map(
|
|
5858
|
+
coins.map((c) => [c.coinType, BigInt(c.totalBalance)])
|
|
5859
|
+
);
|
|
5860
|
+
} catch (err) {
|
|
5861
|
+
console.warn(
|
|
5862
|
+
`[post-write-poll] poll attempt ${attempt} failed; continuing:`,
|
|
5863
|
+
err
|
|
5864
|
+
);
|
|
5865
|
+
continue;
|
|
5866
|
+
}
|
|
5867
|
+
if (balancesDiffer(baseline, current)) {
|
|
5868
|
+
return {
|
|
5869
|
+
outcome: "detected_change",
|
|
5870
|
+
attempts: attempt,
|
|
5871
|
+
resolvedAtMs: Date.now() - start
|
|
5872
|
+
};
|
|
5873
|
+
}
|
|
5874
|
+
}
|
|
5875
|
+
return {
|
|
5876
|
+
outcome: "ceiling",
|
|
5877
|
+
attempts: maxAttempts,
|
|
5878
|
+
resolvedAtMs: Date.now() - start
|
|
5879
|
+
};
|
|
5880
|
+
}
|
|
5881
|
+
function balancesDiffer(a, b) {
|
|
5882
|
+
if (a.size !== b.size) return true;
|
|
5883
|
+
for (const [coinType, balance] of a) {
|
|
5884
|
+
if (b.get(coinType) !== balance) return true;
|
|
5885
|
+
}
|
|
5886
|
+
return false;
|
|
5887
|
+
}
|
|
5888
|
+
async function sleepWithFallback(ms, signal) {
|
|
5889
|
+
if (signal.aborted) return;
|
|
5890
|
+
await new Promise((resolve) => {
|
|
5891
|
+
const t = setTimeout(resolve, ms);
|
|
5892
|
+
signal.addEventListener(
|
|
5893
|
+
"abort",
|
|
5894
|
+
() => {
|
|
5895
|
+
clearTimeout(t);
|
|
5896
|
+
resolve();
|
|
5897
|
+
},
|
|
5898
|
+
{ once: true }
|
|
5899
|
+
);
|
|
5900
|
+
});
|
|
5901
|
+
}
|
|
5902
|
+
|
|
5789
5903
|
// src/proactive-marker.ts
|
|
5790
5904
|
var VALID_TYPES = /* @__PURE__ */ new Set([
|
|
5791
5905
|
"idle_balance",
|
|
@@ -7392,6 +7506,12 @@ var QueryEngine = class {
|
|
|
7392
7506
|
// [v1.5] See `EngineConfig.postWriteRefresh` — drives the post-write
|
|
7393
7507
|
// synthetic read injection in `resumeWithToolResult`.
|
|
7394
7508
|
postWriteRefresh;
|
|
7509
|
+
// [SPEC 19 Phase B / 2026-05-09] Pre-warmed indexer-catchup poll Promise.
|
|
7510
|
+
// When provided by the host (resume route fires `pollForIndexerCatchup`
|
|
7511
|
+
// in parallel with `createEngine`), `runPostWriteRefresh` awaits this
|
|
7512
|
+
// instead of starting a fresh poll. See `EngineConfig.indexerCatchupPromise`
|
|
7513
|
+
// for the full design rationale.
|
|
7514
|
+
indexerCatchupPromise;
|
|
7395
7515
|
matchedRecipe = null;
|
|
7396
7516
|
messages = [];
|
|
7397
7517
|
abortController = null;
|
|
@@ -7467,6 +7587,7 @@ var QueryEngine = class {
|
|
|
7467
7587
|
this.onAutoExecuted = config.onAutoExecuted;
|
|
7468
7588
|
this.onGuardFired = config.onGuardFired;
|
|
7469
7589
|
this.postWriteRefresh = config.postWriteRefresh;
|
|
7590
|
+
this.indexerCatchupPromise = config.indexerCatchupPromise;
|
|
7470
7591
|
this.blockvisionApiKey = config.blockvisionApiKey;
|
|
7471
7592
|
this.portfolioCache = config.portfolioCache;
|
|
7472
7593
|
this.tools = config.tools ?? (config.agent ? getDefaultTools() : []);
|
|
@@ -7867,19 +7988,43 @@ var QueryEngine = class {
|
|
|
7867
7988
|
{ has_wallet: this.walletAddress ? "1" : "0" }
|
|
7868
7989
|
);
|
|
7869
7990
|
const sleepStart = Date.now();
|
|
7870
|
-
|
|
7871
|
-
|
|
7872
|
-
|
|
7873
|
-
|
|
7874
|
-
|
|
7875
|
-
|
|
7876
|
-
|
|
7991
|
+
let pollResult;
|
|
7992
|
+
let sleepSource = "engine";
|
|
7993
|
+
if (this.indexerCatchupPromise) {
|
|
7994
|
+
try {
|
|
7995
|
+
pollResult = await this.indexerCatchupPromise;
|
|
7996
|
+
sleepSource = "pre-warmed";
|
|
7997
|
+
} catch (err) {
|
|
7998
|
+
console.warn(
|
|
7999
|
+
"[engine.pwr] pre-warmed indexer catchup promise rejected; falling back to fresh poll:",
|
|
8000
|
+
err
|
|
8001
|
+
);
|
|
8002
|
+
pollResult = await pollForIndexerCatchup({
|
|
8003
|
+
suiRpcUrl: this.suiRpcUrl,
|
|
8004
|
+
address: this.walletAddress,
|
|
8005
|
+
ceilingMs: 1500,
|
|
8006
|
+
pollIntervalMs: 250,
|
|
8007
|
+
signal
|
|
8008
|
+
});
|
|
8009
|
+
}
|
|
8010
|
+
} else {
|
|
8011
|
+
pollResult = await pollForIndexerCatchup({
|
|
8012
|
+
suiRpcUrl: this.suiRpcUrl,
|
|
8013
|
+
address: this.walletAddress,
|
|
8014
|
+
ceilingMs: 1500,
|
|
8015
|
+
pollIntervalMs: 250,
|
|
8016
|
+
signal
|
|
7877
8017
|
});
|
|
7878
8018
|
}
|
|
7879
8019
|
getTelemetrySink().histogram(
|
|
7880
8020
|
"engine.pwr.sleep_ms",
|
|
7881
8021
|
Date.now() - sleepStart,
|
|
7882
|
-
{
|
|
8022
|
+
{
|
|
8023
|
+
aborted: signal.aborted ? "1" : "0",
|
|
8024
|
+
outcome: pollResult.outcome,
|
|
8025
|
+
attempts: String(pollResult.attempts),
|
|
8026
|
+
source: sleepSource
|
|
8027
|
+
}
|
|
7883
8028
|
);
|
|
7884
8029
|
if (signal.aborted) return;
|
|
7885
8030
|
const refreshStart = Date.now();
|
|
@@ -10333,6 +10478,6 @@ function sanitizeAnthropicMessages(messages) {
|
|
|
10333
10478
|
return merged;
|
|
10334
10479
|
}
|
|
10335
10480
|
|
|
10336
|
-
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, 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 };
|
|
10481
|
+
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 };
|
|
10337
10482
|
//# sourceMappingURL=index.js.map
|
|
10338
10483
|
//# sourceMappingURL=index.js.map
|