@t2000/engine 1.8.0 → 1.9.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 +128 -1
- package/dist/index.js +163 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1535,6 +1535,14 @@ declare class QueryEngine {
|
|
|
1535
1535
|
private runPostWriteRefresh;
|
|
1536
1536
|
interrupt(): void;
|
|
1537
1537
|
getMessages(): readonly Message[];
|
|
1538
|
+
/**
|
|
1539
|
+
* [SPEC 7 P2.4b] Read-only access to the engine's tool registry.
|
|
1540
|
+
* Exposed so out-of-band utilities like `regenerateBundle` can call
|
|
1541
|
+
* `composeBundleFromToolResults({ tools: engine.getTools(), ... })`
|
|
1542
|
+
* without forcing the host to hand-thread the tool array. Mirrors
|
|
1543
|
+
* `getMessages()` access pattern.
|
|
1544
|
+
*/
|
|
1545
|
+
getTools(): readonly Tool[];
|
|
1538
1546
|
getMatchedRecipe(): Recipe | null;
|
|
1539
1547
|
getContextBudget(): ContextBudget;
|
|
1540
1548
|
reset(): void;
|
|
@@ -1632,6 +1640,125 @@ declare function bundleShortestTtl(toolUseIds: string[], toolNamesById: Record<s
|
|
|
1632
1640
|
/** The set of read tools whose results re-fire on REGENERATE. */
|
|
1633
1641
|
declare const REGENERATABLE_READ_TOOLS: ReadonlySet<string>;
|
|
1634
1642
|
|
|
1643
|
+
/**
|
|
1644
|
+
* SPEC 7 v0.3 Quote-Refresh ReviewCard — engine-side bundle regeneration.
|
|
1645
|
+
*
|
|
1646
|
+
* When a user takes 30–60s to read a multi-step Payment Stream
|
|
1647
|
+
* `pending_action`, the upstream read results that fed bundle composition
|
|
1648
|
+
* (Cetus quotes, NAVI APYs, wallet balances) drift. Today the user has to
|
|
1649
|
+
* either approve with stale data (Sui dry-run is the safety gate, but the
|
|
1650
|
+
* UX is "did this just lie to me?") or cancel and re-prompt the LLM
|
|
1651
|
+
* (loses the narrative thread). The Quote-Refresh ReviewCard adds a
|
|
1652
|
+
* third option: an explicit REGENERATE button that re-fires the
|
|
1653
|
+
* upstream reads (no LLM call), rebuilds the bundle in place, and
|
|
1654
|
+
* yields a fresh `pending_action` with new per-step `attemptId`s.
|
|
1655
|
+
*
|
|
1656
|
+
* **What this function does NOT do.**
|
|
1657
|
+
* - Run the LLM. Regenerate is "re-evaluate the same intent against
|
|
1658
|
+
* fresh state" — the writes' tool names + inputs stay identical;
|
|
1659
|
+
* only the upstream read TIMESTAMPS change (and any downstream
|
|
1660
|
+
* derivations the host made off them).
|
|
1661
|
+
* - Run the bundle on-chain. The host still presents the new
|
|
1662
|
+
* PermissionCard for confirmation; user can approve, regenerate
|
|
1663
|
+
* again, or deny.
|
|
1664
|
+
* - Mutate `TurnMetrics` rows. The host route owns analytics — see
|
|
1665
|
+
* `audric/apps/web/app/api/engine/regenerate/route.ts`.
|
|
1666
|
+
*
|
|
1667
|
+
* **Spec 1 / Spec 2 invariants preserved.**
|
|
1668
|
+
* - Each regeneration produces its own per-step `attemptId` (UUID v4),
|
|
1669
|
+
* so the host can write a fresh `TurnMetrics` row keyed on it.
|
|
1670
|
+
* - The original `pending_action`'s `attemptId` stays valid for the
|
|
1671
|
+
* host's `pendingActionOutcome = 'regenerated'` update — no
|
|
1672
|
+
* accidental over-write of the original row.
|
|
1673
|
+
*
|
|
1674
|
+
* **Why synchronous (no SSE).** The chat stream that originally
|
|
1675
|
+
* yielded the bundled `pending_action` has already closed by the time
|
|
1676
|
+
* the user taps Regenerate (`useEngine.ts` flips `isStreaming: false`
|
|
1677
|
+
* on `pending_action`). Reopening a stream for a sub-second round-trip
|
|
1678
|
+
* would be heavier than the host needs. Instead, the host endpoint
|
|
1679
|
+
* calls this function synchronously and returns
|
|
1680
|
+
* `{ success, newPendingAction, timelineEvents[] }` in the response
|
|
1681
|
+
* body — host renders `timelineEvents[]` as a "↻ Regenerated · Ns"
|
|
1682
|
+
* group above the new card.
|
|
1683
|
+
*/
|
|
1684
|
+
|
|
1685
|
+
/**
|
|
1686
|
+
* One event in the `timelineEvents[]` array returned to the host.
|
|
1687
|
+
* Mirrors the engine's normal SSE event shapes for `tool_start` and
|
|
1688
|
+
* `tool_result` so the host can push them onto its timeline as if they
|
|
1689
|
+
* had streamed live.
|
|
1690
|
+
*/
|
|
1691
|
+
type RegenerateTimelineEvent = {
|
|
1692
|
+
type: 'tool_start';
|
|
1693
|
+
toolName: string;
|
|
1694
|
+
toolUseId: string;
|
|
1695
|
+
input: unknown;
|
|
1696
|
+
} | {
|
|
1697
|
+
type: 'tool_result';
|
|
1698
|
+
toolName: string;
|
|
1699
|
+
toolUseId: string;
|
|
1700
|
+
result: unknown;
|
|
1701
|
+
isError: boolean;
|
|
1702
|
+
durationMs: number;
|
|
1703
|
+
};
|
|
1704
|
+
interface RegenerateSuccess {
|
|
1705
|
+
success: true;
|
|
1706
|
+
/**
|
|
1707
|
+
* Fresh `pending_action` with new per-step `attemptId`s. The host
|
|
1708
|
+
* swaps this in for the original `PermissionCard` payload; the
|
|
1709
|
+
* existing PermissionCard renderer requires no changes — it sees a
|
|
1710
|
+
* fresh action with a fresh `quoteAge` of ~0ms.
|
|
1711
|
+
*/
|
|
1712
|
+
newPendingAction: PendingAction;
|
|
1713
|
+
/**
|
|
1714
|
+
* Re-fired upstream read events the host renders as a
|
|
1715
|
+
* "↻ Regenerated · Ns" group above the new card. Order: every
|
|
1716
|
+
* `tool_start` for one read is paired with its `tool_result`; reads
|
|
1717
|
+
* are processed serially (so durations sum cleanly for the group
|
|
1718
|
+
* label).
|
|
1719
|
+
*/
|
|
1720
|
+
timelineEvents: RegenerateTimelineEvent[];
|
|
1721
|
+
}
|
|
1722
|
+
interface RegenerateFailure {
|
|
1723
|
+
success: false;
|
|
1724
|
+
reason: 'pending_action_not_found' | 'cannot_regenerate' | 'engine_error';
|
|
1725
|
+
message: string;
|
|
1726
|
+
}
|
|
1727
|
+
type RegenerateResult = RegenerateSuccess | RegenerateFailure;
|
|
1728
|
+
/**
|
|
1729
|
+
* Re-fire the upstream reads that fed a bundled pending_action and
|
|
1730
|
+
* compose a fresh bundle. The engine MUST be created with the same
|
|
1731
|
+
* tool registry + ToolContext as the chat turn that produced the
|
|
1732
|
+
* original action. The host typically reaches this by calling
|
|
1733
|
+
* `createEngine({ address, session })` on the same session that
|
|
1734
|
+
* persisted the pending_action.
|
|
1735
|
+
*
|
|
1736
|
+
* **Side effect.** On success, this mutates the engine's message
|
|
1737
|
+
* history by appending one synthetic assistant message (carrying the
|
|
1738
|
+
* regenerated `tool_use` blocks) and one user message (carrying the
|
|
1739
|
+
* fresh `tool_result` blocks). This is so the LLM sees the fresh
|
|
1740
|
+
* data when the user approves the new bundle and the engine resumes.
|
|
1741
|
+
* The host should persist `engine.getMessages()` back to its session
|
|
1742
|
+
* store after a successful regenerate.
|
|
1743
|
+
*
|
|
1744
|
+
* **Failure modes.**
|
|
1745
|
+
* - `pending_action_not_found` — the action isn't a bundle (no
|
|
1746
|
+
* `steps`, or fewer than 2 steps). Single-write actions can't be
|
|
1747
|
+
* regenerated by design.
|
|
1748
|
+
* - `cannot_regenerate` — the action's `canRegenerate` flag is
|
|
1749
|
+
* false, OR no contributing read tool_use_ids could be located in
|
|
1750
|
+
* session history.
|
|
1751
|
+
* - `engine_error` — a tool re-execution threw, OR bundle
|
|
1752
|
+
* composition rejected (defensive — should not happen if the
|
|
1753
|
+
* original bundle was valid).
|
|
1754
|
+
*
|
|
1755
|
+
* Errors in tool re-execution short-circuit the whole regenerate
|
|
1756
|
+
* (bundle composition would inherit a broken read result). The host
|
|
1757
|
+
* surfaces this as a toast: "Could not regenerate. The original card
|
|
1758
|
+
* is still valid."
|
|
1759
|
+
*/
|
|
1760
|
+
declare function regenerateBundle(engine: QueryEngine, action: PendingAction): Promise<RegenerateResult>;
|
|
1761
|
+
|
|
1635
1762
|
interface BuildToolOptions<TInput, TOutput> {
|
|
1636
1763
|
name: string;
|
|
1637
1764
|
description: string;
|
|
@@ -3521,4 +3648,4 @@ declare function getTelemetrySink(): TelemetrySink;
|
|
|
3521
3648
|
/** Restore the default noop sink. Used by test teardowns. */
|
|
3522
3649
|
declare function resetTelemetrySink(): void;
|
|
3523
3650
|
|
|
3524
|
-
export { type AddressPortfolio, AnthropicProvider, type AnthropicProviderConfig, type AudricHistoryRecord, type AudricPortfolioResult, type AwaitOrFetchOpts, type BalancePrices, type BalanceResult, BalanceTracker, type BuildToolOptions, 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 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, 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 PendingReward, type PendingToolCall, type PermissionLevel, type PermissionOperation, type PermissionResponse, type PermissionRule, type PortfolioCoin, type PositionEntry, type PreflightResult, type ProtocolStats, type ProviderEvent, QueryEngine, READ_TOOLS, REGENERATABLE_READ_TOOLS, type RatesResult, type Recipe, type RecipePrerequisite, RecipeRegistry, type RecipeStep, type RecipeStepOnError, 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, WRITE_TOOLS, type WalletCacheEntry, type WalletCacheStore, type WalletCoin, _resetNaviCircuitBreaker, activitySummaryTool, adaptAllMcpTools, adaptAllServerTools, adaptMcpTool, applyToolFlags, awaitOrFetch, balanceCheckTool, borrowTool, budgetToolResult, buildCachedSystemPrompt, buildMcpTools, buildProactivenessInstructions, buildProfileContext, buildSelfEvaluationInstruction, buildStateContext, buildTool, bundleShortestTtl, claimRewardsTool, clampThinkingForEffort, classifyEffort, clearPortfolioCache, clearPortfolioCacheFor, clearPriceMapCache, compactMessages, createGuardRunnerState, engineToSSE, estimateTokens, explainTxTool, extractConversationText, extractMcpText, 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, parseRecipe, parseSSE, payApiTool, portfolioAnalysisTool, protocolDeepDiveTool, ratesInfoTool, 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, swapExecuteTool, swapQuoteTool, tokenPricesTool, toolNameToOperation, toolsToDefinitions, transactionHistoryTool, transformBalance, transformHealthFactor, transformPositions, transformRates, transformRewards, transformSavings, updateGuardStateAfterToolResult, updateTodoTool, validateHistory, voloStakeTool, voloStatsTool, voloUnstakeTool, webSearchTool, withdrawTool, yieldSummaryTool };
|
|
3651
|
+
export { type AddressPortfolio, AnthropicProvider, type AnthropicProviderConfig, type AudricHistoryRecord, type AudricPortfolioResult, type AwaitOrFetchOpts, type BalancePrices, type BalanceResult, BalanceTracker, type BuildToolOptions, 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 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, 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 PendingReward, type PendingToolCall, type PermissionLevel, type PermissionOperation, type PermissionResponse, type PermissionRule, type PortfolioCoin, type PositionEntry, type PreflightResult, 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, WRITE_TOOLS, type WalletCacheEntry, type WalletCacheStore, type WalletCoin, _resetNaviCircuitBreaker, activitySummaryTool, adaptAllMcpTools, adaptAllServerTools, adaptMcpTool, applyToolFlags, awaitOrFetch, balanceCheckTool, borrowTool, budgetToolResult, buildCachedSystemPrompt, buildMcpTools, buildProactivenessInstructions, buildProfileContext, buildSelfEvaluationInstruction, buildStateContext, buildTool, bundleShortestTtl, claimRewardsTool, clampThinkingForEffort, classifyEffort, clearPortfolioCache, clearPortfolioCacheFor, clearPriceMapCache, compactMessages, createGuardRunnerState, engineToSSE, estimateTokens, explainTxTool, extractConversationText, extractMcpText, 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, 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, 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
|
@@ -7160,6 +7160,16 @@ var QueryEngine = class {
|
|
|
7160
7160
|
getMessages() {
|
|
7161
7161
|
return this.messages;
|
|
7162
7162
|
}
|
|
7163
|
+
/**
|
|
7164
|
+
* [SPEC 7 P2.4b] Read-only access to the engine's tool registry.
|
|
7165
|
+
* Exposed so out-of-band utilities like `regenerateBundle` can call
|
|
7166
|
+
* `composeBundleFromToolResults({ tools: engine.getTools(), ... })`
|
|
7167
|
+
* without forcing the host to hand-thread the tool array. Mirrors
|
|
7168
|
+
* `getMessages()` access pattern.
|
|
7169
|
+
*/
|
|
7170
|
+
getTools() {
|
|
7171
|
+
return this.tools;
|
|
7172
|
+
}
|
|
7163
7173
|
getMatchedRecipe() {
|
|
7164
7174
|
return this.matchedRecipe;
|
|
7165
7175
|
}
|
|
@@ -8022,6 +8032,158 @@ function harnessShapeForEffort(effort) {
|
|
|
8022
8032
|
return "max";
|
|
8023
8033
|
}
|
|
8024
8034
|
}
|
|
8035
|
+
async function regenerateBundle(engine, action) {
|
|
8036
|
+
if (!action.steps || action.steps.length < 2) {
|
|
8037
|
+
return {
|
|
8038
|
+
success: false,
|
|
8039
|
+
reason: "pending_action_not_found",
|
|
8040
|
+
message: "Action is not a multi-step bundle"
|
|
8041
|
+
};
|
|
8042
|
+
}
|
|
8043
|
+
if (action.canRegenerate !== true) {
|
|
8044
|
+
return {
|
|
8045
|
+
success: false,
|
|
8046
|
+
reason: "cannot_regenerate",
|
|
8047
|
+
message: "Bundle has canRegenerate=false (no upstream reads contributed)"
|
|
8048
|
+
};
|
|
8049
|
+
}
|
|
8050
|
+
const regenIds = action.regenerateInput?.toolUseIds ?? [];
|
|
8051
|
+
if (regenIds.length === 0) {
|
|
8052
|
+
return {
|
|
8053
|
+
success: false,
|
|
8054
|
+
reason: "cannot_regenerate",
|
|
8055
|
+
message: "Bundle has no regenerateInput.toolUseIds"
|
|
8056
|
+
};
|
|
8057
|
+
}
|
|
8058
|
+
const messages = engine.getMessages();
|
|
8059
|
+
const tools = [...engine.getTools()];
|
|
8060
|
+
const originalReads = [];
|
|
8061
|
+
for (const id of regenIds) {
|
|
8062
|
+
let found = null;
|
|
8063
|
+
outer: for (const msg of messages) {
|
|
8064
|
+
if (msg.role !== "assistant") continue;
|
|
8065
|
+
for (const block of msg.content) {
|
|
8066
|
+
if (block.type === "tool_use" && block.id === id) {
|
|
8067
|
+
found = {
|
|
8068
|
+
name: block.name,
|
|
8069
|
+
input: block.input
|
|
8070
|
+
};
|
|
8071
|
+
break outer;
|
|
8072
|
+
}
|
|
8073
|
+
}
|
|
8074
|
+
}
|
|
8075
|
+
if (!found) {
|
|
8076
|
+
return {
|
|
8077
|
+
success: false,
|
|
8078
|
+
reason: "engine_error",
|
|
8079
|
+
message: `Original tool_use ${id} not found in session history`
|
|
8080
|
+
};
|
|
8081
|
+
}
|
|
8082
|
+
if (!REGENERATABLE_READ_TOOLS.has(found.name)) {
|
|
8083
|
+
continue;
|
|
8084
|
+
}
|
|
8085
|
+
originalReads.push({ toolName: found.name, input: found.input });
|
|
8086
|
+
}
|
|
8087
|
+
if (originalReads.length === 0) {
|
|
8088
|
+
return {
|
|
8089
|
+
success: false,
|
|
8090
|
+
reason: "cannot_regenerate",
|
|
8091
|
+
message: "No regeneratable read tool_use blocks found in session history"
|
|
8092
|
+
};
|
|
8093
|
+
}
|
|
8094
|
+
const timelineEvents = [];
|
|
8095
|
+
const newReads = [];
|
|
8096
|
+
for (const r of originalReads) {
|
|
8097
|
+
const newToolUseId = `regen_${randomUUID().replace(/-/g, "").slice(0, 16)}`;
|
|
8098
|
+
timelineEvents.push({
|
|
8099
|
+
type: "tool_start",
|
|
8100
|
+
toolName: r.toolName,
|
|
8101
|
+
toolUseId: newToolUseId,
|
|
8102
|
+
input: r.input
|
|
8103
|
+
});
|
|
8104
|
+
const t0 = Date.now();
|
|
8105
|
+
let outcome;
|
|
8106
|
+
try {
|
|
8107
|
+
outcome = await engine.invokeReadTool(r.toolName, r.input);
|
|
8108
|
+
} catch (err) {
|
|
8109
|
+
outcome = {
|
|
8110
|
+
data: { error: err instanceof Error ? err.message : String(err) },
|
|
8111
|
+
isError: true
|
|
8112
|
+
};
|
|
8113
|
+
}
|
|
8114
|
+
const durationMs = Date.now() - t0;
|
|
8115
|
+
timelineEvents.push({
|
|
8116
|
+
type: "tool_result",
|
|
8117
|
+
toolName: r.toolName,
|
|
8118
|
+
toolUseId: newToolUseId,
|
|
8119
|
+
result: outcome.data,
|
|
8120
|
+
isError: outcome.isError,
|
|
8121
|
+
durationMs
|
|
8122
|
+
});
|
|
8123
|
+
if (outcome.isError) {
|
|
8124
|
+
return {
|
|
8125
|
+
success: false,
|
|
8126
|
+
reason: "engine_error",
|
|
8127
|
+
message: `Re-execution of ${r.toolName} failed`
|
|
8128
|
+
};
|
|
8129
|
+
}
|
|
8130
|
+
newReads.push({
|
|
8131
|
+
toolUseId: newToolUseId,
|
|
8132
|
+
toolName: r.toolName,
|
|
8133
|
+
input: r.input,
|
|
8134
|
+
result: outcome.data,
|
|
8135
|
+
isError: false,
|
|
8136
|
+
timestamp: t0
|
|
8137
|
+
});
|
|
8138
|
+
}
|
|
8139
|
+
const synthAssistantBlocks = newReads.map((r) => ({
|
|
8140
|
+
type: "tool_use",
|
|
8141
|
+
id: r.toolUseId,
|
|
8142
|
+
name: r.toolName,
|
|
8143
|
+
input: r.input
|
|
8144
|
+
}));
|
|
8145
|
+
const synthUserBlocks = newReads.map((r) => ({
|
|
8146
|
+
type: "tool_result",
|
|
8147
|
+
toolUseId: r.toolUseId,
|
|
8148
|
+
content: typeof r.result === "string" ? r.result : JSON.stringify(r.result),
|
|
8149
|
+
isError: r.isError
|
|
8150
|
+
}));
|
|
8151
|
+
const synthMessages = [
|
|
8152
|
+
{ role: "assistant", content: synthAssistantBlocks },
|
|
8153
|
+
{ role: "user", content: synthUserBlocks }
|
|
8154
|
+
];
|
|
8155
|
+
engine.loadMessages([...messages, ...synthMessages]);
|
|
8156
|
+
const pendingWrites = action.steps.map((step) => ({
|
|
8157
|
+
id: step.toolUseId,
|
|
8158
|
+
name: step.toolName,
|
|
8159
|
+
input: step.input
|
|
8160
|
+
}));
|
|
8161
|
+
const readResults = newReads.map((r) => ({
|
|
8162
|
+
toolUseId: r.toolUseId,
|
|
8163
|
+
toolName: r.toolName,
|
|
8164
|
+
timestamp: r.timestamp
|
|
8165
|
+
}));
|
|
8166
|
+
const assistantContent = action.assistantContent ?? [];
|
|
8167
|
+
const completedResults = action.completedResults ?? [];
|
|
8168
|
+
let newPendingAction;
|
|
8169
|
+
try {
|
|
8170
|
+
newPendingAction = composeBundleFromToolResults({
|
|
8171
|
+
pendingWrites,
|
|
8172
|
+
tools,
|
|
8173
|
+
readResults,
|
|
8174
|
+
assistantContent,
|
|
8175
|
+
completedResults,
|
|
8176
|
+
turnIndex: action.turnIndex
|
|
8177
|
+
});
|
|
8178
|
+
} catch (err) {
|
|
8179
|
+
return {
|
|
8180
|
+
success: false,
|
|
8181
|
+
reason: "engine_error",
|
|
8182
|
+
message: err instanceof Error ? err.message : "Bundle rebuild failed"
|
|
8183
|
+
};
|
|
8184
|
+
}
|
|
8185
|
+
return { success: true, newPendingAction, timelineEvents };
|
|
8186
|
+
}
|
|
8025
8187
|
|
|
8026
8188
|
// src/streaming.ts
|
|
8027
8189
|
function serializeSSE(event) {
|
|
@@ -9123,6 +9285,6 @@ function sanitizeAnthropicMessages(messages) {
|
|
|
9123
9285
|
return merged;
|
|
9124
9286
|
}
|
|
9125
9287
|
|
|
9126
|
-
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, 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, WRITE_TOOLS, _resetNaviCircuitBreaker, activitySummaryTool, adaptAllMcpTools, adaptAllServerTools, adaptMcpTool, applyToolFlags, awaitOrFetch, balanceCheckTool, borrowTool, budgetToolResult, buildCachedSystemPrompt, buildMcpTools, buildProactivenessInstructions, buildProfileContext, buildSelfEvaluationInstruction, buildStateContext, buildTool, bundleShortestTtl, claimRewardsTool, clampThinkingForEffort, classifyEffort, clearPortfolioCache, clearPortfolioCacheFor, clearPriceMapCache, compactMessages, createGuardRunnerState, engineToSSE, estimateTokens, explainTxTool, extractConversationText, extractMcpText, 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, parseRecipe, parseSSE, payApiTool, portfolioAnalysisTool, protocolDeepDiveTool, ratesInfoTool, 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, swapExecuteTool, swapQuoteTool, tokenPricesTool, toolNameToOperation, toolsToDefinitions, transactionHistoryTool, transformBalance, transformHealthFactor, transformPositions, transformRates, transformRewards, transformSavings, updateGuardStateAfterToolResult, updateTodoTool, validateHistory, voloStakeTool, voloStatsTool, voloUnstakeTool, webSearchTool, withdrawTool, yieldSummaryTool };
|
|
9288
|
+
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, 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, WRITE_TOOLS, _resetNaviCircuitBreaker, activitySummaryTool, adaptAllMcpTools, adaptAllServerTools, adaptMcpTool, applyToolFlags, awaitOrFetch, balanceCheckTool, borrowTool, budgetToolResult, buildCachedSystemPrompt, buildMcpTools, buildProactivenessInstructions, buildProfileContext, buildSelfEvaluationInstruction, buildStateContext, buildTool, bundleShortestTtl, claimRewardsTool, clampThinkingForEffort, classifyEffort, clearPortfolioCache, clearPortfolioCacheFor, clearPriceMapCache, compactMessages, createGuardRunnerState, engineToSSE, estimateTokens, explainTxTool, extractConversationText, extractMcpText, 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, 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, swapExecuteTool, swapQuoteTool, tokenPricesTool, toolNameToOperation, toolsToDefinitions, transactionHistoryTool, transformBalance, transformHealthFactor, transformPositions, transformRates, transformRewards, transformSavings, updateGuardStateAfterToolResult, updateTodoTool, validateHistory, voloStakeTool, voloStatsTool, voloUnstakeTool, webSearchTool, withdrawTool, yieldSummaryTool };
|
|
9127
9289
|
//# sourceMappingURL=index.js.map
|
|
9128
9290
|
//# sourceMappingURL=index.js.map
|