@t2000/engine 0.5.8 → 0.5.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -92,6 +92,8 @@ interface ToolContext {
92
92
  walletAddress?: string;
93
93
  suiRpcUrl?: string;
94
94
  serverPositions?: ServerPositionData;
95
+ /** Fresh on-chain position reader — bypasses MCP caching. If provided, read tools prefer this. */
96
+ positionFetcher?: (address: string) => Promise<ServerPositionData>;
95
97
  signal?: AbortSignal;
96
98
  }
97
99
  interface ServerPositionData {
@@ -138,6 +140,8 @@ interface EngineConfig {
138
140
  walletAddress?: string;
139
141
  suiRpcUrl?: string;
140
142
  serverPositions?: ServerPositionData;
143
+ /** Fresh on-chain position reader — called per tool invocation, bypasses MCP caching. */
144
+ positionFetcher?: (address: string) => Promise<ServerPositionData>;
141
145
  tools?: Tool[];
142
146
  systemPrompt?: string;
143
147
  model?: string;
@@ -248,6 +252,7 @@ declare class QueryEngine {
248
252
  private readonly walletAddress;
249
253
  private readonly suiRpcUrl;
250
254
  private serverPositions;
255
+ private readonly positionFetcher;
251
256
  private readonly txMutex;
252
257
  private readonly costTracker;
253
258
  private messages;
package/dist/index.js CHANGED
@@ -555,11 +555,11 @@ var balanceCheckTool = buildTool({
555
555
  });
556
556
  }
557
557
  }
558
- const sp = context.serverPositions;
559
558
  let savings;
560
559
  let debt;
561
560
  let pendingRewardsUsd;
562
- if (sp) {
561
+ if (context.positionFetcher && context.walletAddress) {
562
+ const sp = await context.positionFetcher(context.walletAddress);
563
563
  savings = sp.savings;
564
564
  debt = sp.borrows;
565
565
  pendingRewardsUsd = sp.pendingRewards;
@@ -693,7 +693,7 @@ async function fetchProtocolStats(manager, opts) {
693
693
  }
694
694
 
695
695
  // src/tools/savings.ts
696
- function buildSavingsFromServer(sp) {
696
+ function buildSavingsFromPositions(sp) {
697
697
  const positions = [
698
698
  ...sp.supplies.map((s) => ({
699
699
  protocol: s.protocol,
@@ -741,8 +741,9 @@ var savingsInfoTool = buildTool({
741
741
  jsonSchema: { type: "object", properties: {}, required: [] },
742
742
  isReadOnly: true,
743
743
  async call(_input, context) {
744
- if (context.serverPositions) {
745
- return { data: buildSavingsFromServer(context.serverPositions) };
744
+ if (context.positionFetcher && context.walletAddress) {
745
+ const sp = await context.positionFetcher(context.walletAddress);
746
+ return { data: buildSavingsFromPositions(sp) };
746
747
  }
747
748
  if (hasNaviMcp(context)) {
748
749
  const savings = await fetchSavings(
@@ -799,9 +800,9 @@ var healthCheckTool = buildTool({
799
800
  jsonSchema: { type: "object", properties: {}, required: [] },
800
801
  isReadOnly: true,
801
802
  async call(_input, context) {
802
- if (context.serverPositions) {
803
- const sp = context.serverPositions;
804
- const hfVal = sp.healthFactor ?? (sp.borrows > 0 ? Infinity : Infinity);
803
+ if (context.positionFetcher && context.walletAddress) {
804
+ const sp = await context.positionFetcher(context.walletAddress);
805
+ const hfVal = sp.healthFactor ?? (sp.borrows > 0 ? 0 : Infinity);
805
806
  const status2 = hfStatus(hfVal);
806
807
  const displayHf = Number.isFinite(hfVal) ? hfVal.toFixed(2) : "\u221E";
807
808
  return {
@@ -1936,6 +1937,7 @@ var QueryEngine = class {
1936
1937
  walletAddress;
1937
1938
  suiRpcUrl;
1938
1939
  serverPositions;
1940
+ positionFetcher;
1939
1941
  txMutex = new TxMutex();
1940
1942
  costTracker;
1941
1943
  messages = [];
@@ -1947,6 +1949,7 @@ var QueryEngine = class {
1947
1949
  this.walletAddress = config.walletAddress;
1948
1950
  this.suiRpcUrl = config.suiRpcUrl;
1949
1951
  this.serverPositions = config.serverPositions;
1952
+ this.positionFetcher = config.positionFetcher;
1950
1953
  this.model = config.model;
1951
1954
  this.maxTurns = config.maxTurns ?? DEFAULT_MAX_TURNS;
1952
1955
  this.maxTokens = config.maxTokens ?? DEFAULT_MAX_TOKENS;
@@ -2021,6 +2024,9 @@ var QueryEngine = class {
2021
2024
  yield { type: "turn_complete", stopReason: "end_turn" };
2022
2025
  return;
2023
2026
  }
2027
+ if (this.mcpManager && typeof this.mcpManager.cache?.invalidate === "function") {
2028
+ this.mcpManager.cache.invalidate();
2029
+ }
2024
2030
  yield* this.agentLoop(null, signal, false);
2025
2031
  }
2026
2032
  interrupt() {
@@ -2058,6 +2064,7 @@ var QueryEngine = class {
2058
2064
  walletAddress: this.walletAddress,
2059
2065
  suiRpcUrl: this.suiRpcUrl,
2060
2066
  serverPositions: this.serverPositions,
2067
+ positionFetcher: this.positionFetcher,
2061
2068
  signal
2062
2069
  };
2063
2070
  let turns = 0;