@t2000/engine 1.24.10 → 1.24.12
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 +20 -1
- package/dist/index.js +158 -131
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -2016,6 +2016,25 @@ declare class QueryEngine {
|
|
|
2016
2016
|
*/
|
|
2017
2017
|
declare function validateHistory(messages: Message[]): Message[];
|
|
2018
2018
|
|
|
2019
|
+
type PostWritePollOutcome = 'detected_change' | 'ceiling' | 'aborted' | 'fallback_no_baseline' | 'fallback_no_address' | 'fallback_no_rpc';
|
|
2020
|
+
interface PostWritePollResult {
|
|
2021
|
+
outcome: PostWritePollOutcome;
|
|
2022
|
+
/** Number of poll attempts made (0 if fallback fired before polling). */
|
|
2023
|
+
attempts: number;
|
|
2024
|
+
/** Wall-clock ms from `pollForIndexerCatchup` entry to return. */
|
|
2025
|
+
resolvedAtMs: number;
|
|
2026
|
+
}
|
|
2027
|
+
interface PostWritePollOptions {
|
|
2028
|
+
suiRpcUrl: string | undefined;
|
|
2029
|
+
address: string | undefined;
|
|
2030
|
+
/** Hard ceiling on total wait time. Default 1500ms (matches old fixed sleep). */
|
|
2031
|
+
ceilingMs: number;
|
|
2032
|
+
/** Wait between poll attempts. Default 250ms. */
|
|
2033
|
+
pollIntervalMs: number;
|
|
2034
|
+
signal: AbortSignal;
|
|
2035
|
+
}
|
|
2036
|
+
declare function pollForIndexerCatchup(options: PostWritePollOptions): Promise<PostWritePollResult>;
|
|
2037
|
+
|
|
2019
2038
|
/**
|
|
2020
2039
|
* SPEC 7 v0.3 Quote-Refresh ReviewCard — per-tool result freshness budgets.
|
|
2021
2040
|
*
|
|
@@ -4328,4 +4347,4 @@ declare function getTelemetrySink(): TelemetrySink;
|
|
|
4328
4347
|
/** Restore the default noop sink. Used by test teardowns. */
|
|
4329
4348
|
declare function resetTelemetrySink(): void;
|
|
4330
4349
|
|
|
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 };
|
|
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 };
|
package/dist/index.js
CHANGED
|
@@ -5786,120 +5786,6 @@ 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
|
-
|
|
5903
5789
|
// src/proactive-marker.ts
|
|
5904
5790
|
var VALID_TYPES = /* @__PURE__ */ new Set([
|
|
5905
5791
|
"idle_balance",
|
|
@@ -7970,6 +7856,10 @@ var QueryEngine = class {
|
|
|
7970
7856
|
blockvisionApiKey: this.blockvisionApiKey,
|
|
7971
7857
|
portfolioCache: this.portfolioCache
|
|
7972
7858
|
};
|
|
7859
|
+
const canSafetyNet = !!(this.walletAddress && this.suiRpcUrl);
|
|
7860
|
+
const safetyNetBaseline = canSafetyNet ? fetchWalletCoins(this.walletAddress, this.suiRpcUrl).then(
|
|
7861
|
+
(coins) => new Map(coins.map((c) => [c.coinType, BigInt(c.totalBalance)]))
|
|
7862
|
+
).catch(() => null) : null;
|
|
7973
7863
|
const cacheInvalidationStart = Date.now();
|
|
7974
7864
|
if (this.walletAddress) {
|
|
7975
7865
|
this.portfolioCache?.delete(this.walletAddress);
|
|
@@ -7980,23 +7870,10 @@ var QueryEngine = class {
|
|
|
7980
7870
|
Date.now() - cacheInvalidationStart,
|
|
7981
7871
|
{ has_wallet: this.walletAddress ? "1" : "0" }
|
|
7982
7872
|
);
|
|
7983
|
-
|
|
7984
|
-
|
|
7985
|
-
|
|
7986
|
-
address: this.walletAddress,
|
|
7987
|
-
ceilingMs: 1500,
|
|
7988
|
-
pollIntervalMs: 250,
|
|
7989
|
-
signal
|
|
7873
|
+
getTelemetrySink().counter("engine.pwr.skipped_sleep_count", {
|
|
7874
|
+
has_wallet: this.walletAddress ? "1" : "0",
|
|
7875
|
+
can_safety_net: canSafetyNet ? "1" : "0"
|
|
7990
7876
|
});
|
|
7991
|
-
getTelemetrySink().histogram(
|
|
7992
|
-
"engine.pwr.sleep_ms",
|
|
7993
|
-
Date.now() - sleepStart,
|
|
7994
|
-
{
|
|
7995
|
-
aborted: signal.aborted ? "1" : "0",
|
|
7996
|
-
outcome: pollResult.outcome,
|
|
7997
|
-
attempts: String(pollResult.attempts)
|
|
7998
|
-
}
|
|
7999
|
-
);
|
|
8000
7877
|
if (signal.aborted) return;
|
|
8001
7878
|
const refreshStart = Date.now();
|
|
8002
7879
|
const idStem = `pwr_${action.toolUseId.slice(-6)}`;
|
|
@@ -8101,6 +7978,35 @@ var QueryEngine = class {
|
|
|
8101
7978
|
is_bundle: isBundle ? "1" : "0"
|
|
8102
7979
|
}
|
|
8103
7980
|
);
|
|
7981
|
+
if (safetyNetBaseline && canSafetyNet) {
|
|
7982
|
+
const wallet = this.walletAddress;
|
|
7983
|
+
const rpc = this.suiRpcUrl;
|
|
7984
|
+
void (async () => {
|
|
7985
|
+
try {
|
|
7986
|
+
const [baseline, current] = await Promise.all([
|
|
7987
|
+
safetyNetBaseline,
|
|
7988
|
+
fetchWalletCoins(wallet, rpc).then(
|
|
7989
|
+
(coins) => new Map(
|
|
7990
|
+
coins.map((c) => [c.coinType, BigInt(c.totalBalance)])
|
|
7991
|
+
)
|
|
7992
|
+
).catch(() => null)
|
|
7993
|
+
]);
|
|
7994
|
+
if (!baseline || !current) return;
|
|
7995
|
+
const stale = !walletStateChanged(baseline, current);
|
|
7996
|
+
if (stale) {
|
|
7997
|
+
getTelemetrySink().counter(
|
|
7998
|
+
"engine.pwr.observed_stale_balance_check",
|
|
7999
|
+
{
|
|
8000
|
+
stale: "1",
|
|
8001
|
+
is_bundle: isBundle ? "1" : "0",
|
|
8002
|
+
tool_count: String(refreshTools.length)
|
|
8003
|
+
}
|
|
8004
|
+
);
|
|
8005
|
+
}
|
|
8006
|
+
} catch {
|
|
8007
|
+
}
|
|
8008
|
+
})();
|
|
8009
|
+
}
|
|
8104
8010
|
}
|
|
8105
8011
|
interrupt() {
|
|
8106
8012
|
this.abortController?.abort();
|
|
@@ -9031,6 +8937,13 @@ ${recipeCtx}`;
|
|
|
9031
8937
|
}
|
|
9032
8938
|
}
|
|
9033
8939
|
};
|
|
8940
|
+
function walletStateChanged(before, after) {
|
|
8941
|
+
if (before.size !== after.size) return true;
|
|
8942
|
+
for (const [coinType, balance] of before) {
|
|
8943
|
+
if (after.get(coinType) !== balance) return true;
|
|
8944
|
+
}
|
|
8945
|
+
return false;
|
|
8946
|
+
}
|
|
9034
8947
|
function isCorruptHistoryError(err) {
|
|
9035
8948
|
const msg = err instanceof Error ? err.message : String(err);
|
|
9036
8949
|
return msg.includes("tool_use") && msg.includes("tool_result") || msg.includes("roles must alternate") || msg.includes("400") && msg.includes("invalid_request_error");
|
|
@@ -9140,6 +9053,120 @@ function harnessShapeForEffort(effort) {
|
|
|
9140
9053
|
return "max";
|
|
9141
9054
|
}
|
|
9142
9055
|
}
|
|
9056
|
+
|
|
9057
|
+
// src/post-write-poll.ts
|
|
9058
|
+
async function pollForIndexerCatchup(options) {
|
|
9059
|
+
const { suiRpcUrl, address, ceilingMs, pollIntervalMs, signal } = options;
|
|
9060
|
+
const start = Date.now();
|
|
9061
|
+
if (!suiRpcUrl) {
|
|
9062
|
+
await sleepWithFallback(ceilingMs, signal);
|
|
9063
|
+
return {
|
|
9064
|
+
outcome: "fallback_no_rpc",
|
|
9065
|
+
attempts: 0,
|
|
9066
|
+
resolvedAtMs: Date.now() - start
|
|
9067
|
+
};
|
|
9068
|
+
}
|
|
9069
|
+
if (!address) {
|
|
9070
|
+
await sleepWithFallback(ceilingMs, signal);
|
|
9071
|
+
return {
|
|
9072
|
+
outcome: "fallback_no_address",
|
|
9073
|
+
attempts: 0,
|
|
9074
|
+
resolvedAtMs: Date.now() - start
|
|
9075
|
+
};
|
|
9076
|
+
}
|
|
9077
|
+
let baseline;
|
|
9078
|
+
try {
|
|
9079
|
+
const coins = await fetchWalletCoins(address, suiRpcUrl);
|
|
9080
|
+
baseline = new Map(
|
|
9081
|
+
coins.map((c) => [c.coinType, BigInt(c.totalBalance)])
|
|
9082
|
+
);
|
|
9083
|
+
} catch (err) {
|
|
9084
|
+
console.warn(
|
|
9085
|
+
"[post-write-poll] baseline fetch failed; falling back to fixed sleep:",
|
|
9086
|
+
err
|
|
9087
|
+
);
|
|
9088
|
+
await sleepWithFallback(ceilingMs, signal);
|
|
9089
|
+
return {
|
|
9090
|
+
outcome: "fallback_no_baseline",
|
|
9091
|
+
attempts: 0,
|
|
9092
|
+
resolvedAtMs: Date.now() - start
|
|
9093
|
+
};
|
|
9094
|
+
}
|
|
9095
|
+
const maxAttempts = Math.max(1, Math.floor(ceilingMs / pollIntervalMs));
|
|
9096
|
+
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
9097
|
+
if (signal.aborted) {
|
|
9098
|
+
return {
|
|
9099
|
+
outcome: "aborted",
|
|
9100
|
+
attempts: attempt - 1,
|
|
9101
|
+
resolvedAtMs: Date.now() - start
|
|
9102
|
+
};
|
|
9103
|
+
}
|
|
9104
|
+
await new Promise((resolve) => {
|
|
9105
|
+
const t = setTimeout(resolve, pollIntervalMs);
|
|
9106
|
+
signal.addEventListener(
|
|
9107
|
+
"abort",
|
|
9108
|
+
() => {
|
|
9109
|
+
clearTimeout(t);
|
|
9110
|
+
resolve();
|
|
9111
|
+
},
|
|
9112
|
+
{ once: true }
|
|
9113
|
+
);
|
|
9114
|
+
});
|
|
9115
|
+
if (signal.aborted) {
|
|
9116
|
+
return {
|
|
9117
|
+
outcome: "aborted",
|
|
9118
|
+
attempts: attempt,
|
|
9119
|
+
resolvedAtMs: Date.now() - start
|
|
9120
|
+
};
|
|
9121
|
+
}
|
|
9122
|
+
let current;
|
|
9123
|
+
try {
|
|
9124
|
+
const coins = await fetchWalletCoins(address, suiRpcUrl);
|
|
9125
|
+
current = new Map(
|
|
9126
|
+
coins.map((c) => [c.coinType, BigInt(c.totalBalance)])
|
|
9127
|
+
);
|
|
9128
|
+
} catch (err) {
|
|
9129
|
+
console.warn(
|
|
9130
|
+
`[post-write-poll] poll attempt ${attempt} failed; continuing:`,
|
|
9131
|
+
err
|
|
9132
|
+
);
|
|
9133
|
+
continue;
|
|
9134
|
+
}
|
|
9135
|
+
if (balancesDiffer(baseline, current)) {
|
|
9136
|
+
return {
|
|
9137
|
+
outcome: "detected_change",
|
|
9138
|
+
attempts: attempt,
|
|
9139
|
+
resolvedAtMs: Date.now() - start
|
|
9140
|
+
};
|
|
9141
|
+
}
|
|
9142
|
+
}
|
|
9143
|
+
return {
|
|
9144
|
+
outcome: "ceiling",
|
|
9145
|
+
attempts: maxAttempts,
|
|
9146
|
+
resolvedAtMs: Date.now() - start
|
|
9147
|
+
};
|
|
9148
|
+
}
|
|
9149
|
+
function balancesDiffer(a, b) {
|
|
9150
|
+
if (a.size !== b.size) return true;
|
|
9151
|
+
for (const [coinType, balance] of a) {
|
|
9152
|
+
if (b.get(coinType) !== balance) return true;
|
|
9153
|
+
}
|
|
9154
|
+
return false;
|
|
9155
|
+
}
|
|
9156
|
+
async function sleepWithFallback(ms, signal) {
|
|
9157
|
+
if (signal.aborted) return;
|
|
9158
|
+
await new Promise((resolve) => {
|
|
9159
|
+
const t = setTimeout(resolve, ms);
|
|
9160
|
+
signal.addEventListener(
|
|
9161
|
+
"abort",
|
|
9162
|
+
() => {
|
|
9163
|
+
clearTimeout(t);
|
|
9164
|
+
resolve();
|
|
9165
|
+
},
|
|
9166
|
+
{ once: true }
|
|
9167
|
+
);
|
|
9168
|
+
});
|
|
9169
|
+
}
|
|
9143
9170
|
async function regenerateBundle(engine, action) {
|
|
9144
9171
|
if (action.canRegenerate !== true) {
|
|
9145
9172
|
return {
|
|
@@ -10449,6 +10476,6 @@ function sanitizeAnthropicMessages(messages) {
|
|
|
10449
10476
|
return merged;
|
|
10450
10477
|
}
|
|
10451
10478
|
|
|
10452
|
-
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 };
|
|
10479
|
+
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 };
|
|
10453
10480
|
//# sourceMappingURL=index.js.map
|
|
10454
10481
|
//# sourceMappingURL=index.js.map
|