@t2000/engine 1.24.9 → 1.24.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.js +126 -10
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
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",
|
|
@@ -7867,19 +7981,21 @@ var QueryEngine = class {
|
|
|
7867
7981
|
{ has_wallet: this.walletAddress ? "1" : "0" }
|
|
7868
7982
|
);
|
|
7869
7983
|
const sleepStart = Date.now();
|
|
7870
|
-
|
|
7871
|
-
|
|
7872
|
-
|
|
7873
|
-
|
|
7874
|
-
|
|
7875
|
-
|
|
7876
|
-
|
|
7877
|
-
});
|
|
7878
|
-
}
|
|
7984
|
+
const pollResult = await pollForIndexerCatchup({
|
|
7985
|
+
suiRpcUrl: this.suiRpcUrl,
|
|
7986
|
+
address: this.walletAddress,
|
|
7987
|
+
ceilingMs: 1500,
|
|
7988
|
+
pollIntervalMs: 250,
|
|
7989
|
+
signal
|
|
7990
|
+
});
|
|
7879
7991
|
getTelemetrySink().histogram(
|
|
7880
7992
|
"engine.pwr.sleep_ms",
|
|
7881
7993
|
Date.now() - sleepStart,
|
|
7882
|
-
{
|
|
7994
|
+
{
|
|
7995
|
+
aborted: signal.aborted ? "1" : "0",
|
|
7996
|
+
outcome: pollResult.outcome,
|
|
7997
|
+
attempts: String(pollResult.attempts)
|
|
7998
|
+
}
|
|
7883
7999
|
);
|
|
7884
8000
|
if (signal.aborted) return;
|
|
7885
8001
|
const refreshStart = Date.now();
|