@t2000/engine 1.24.12 → 1.24.13
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 +43 -49
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -7581,7 +7581,10 @@ var QueryEngine = class {
|
|
|
7581
7581
|
);
|
|
7582
7582
|
}
|
|
7583
7583
|
if (action.assistantContent?.length) {
|
|
7584
|
-
this.messages.push({
|
|
7584
|
+
this.messages.push({
|
|
7585
|
+
role: "assistant",
|
|
7586
|
+
content: stripPseudoThinking(action.assistantContent)
|
|
7587
|
+
});
|
|
7585
7588
|
}
|
|
7586
7589
|
const allResults = [
|
|
7587
7590
|
...(action.completedResults ?? []).map((r) => ({
|
|
@@ -7687,7 +7690,7 @@ var QueryEngine = class {
|
|
|
7687
7690
|
if (pendingInput.assistantContent.length > 0) {
|
|
7688
7691
|
this.messages.push({
|
|
7689
7692
|
role: "assistant",
|
|
7690
|
-
content: pendingInput.assistantContent
|
|
7693
|
+
content: stripPseudoThinking(pendingInput.assistantContent)
|
|
7691
7694
|
});
|
|
7692
7695
|
}
|
|
7693
7696
|
const tool = findTool(this.tools, pendingInput.toolName);
|
|
@@ -7856,10 +7859,6 @@ var QueryEngine = class {
|
|
|
7856
7859
|
blockvisionApiKey: this.blockvisionApiKey,
|
|
7857
7860
|
portfolioCache: this.portfolioCache
|
|
7858
7861
|
};
|
|
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;
|
|
7863
7862
|
const cacheInvalidationStart = Date.now();
|
|
7864
7863
|
if (this.walletAddress) {
|
|
7865
7864
|
this.portfolioCache?.delete(this.walletAddress);
|
|
@@ -7871,8 +7870,7 @@ var QueryEngine = class {
|
|
|
7871
7870
|
{ has_wallet: this.walletAddress ? "1" : "0" }
|
|
7872
7871
|
);
|
|
7873
7872
|
getTelemetrySink().counter("engine.pwr.skipped_sleep_count", {
|
|
7874
|
-
has_wallet: this.walletAddress ? "1" : "0"
|
|
7875
|
-
can_safety_net: canSafetyNet ? "1" : "0"
|
|
7873
|
+
has_wallet: this.walletAddress ? "1" : "0"
|
|
7876
7874
|
});
|
|
7877
7875
|
if (signal.aborted) return;
|
|
7878
7876
|
const refreshStart = Date.now();
|
|
@@ -7978,35 +7976,6 @@ var QueryEngine = class {
|
|
|
7978
7976
|
is_bundle: isBundle ? "1" : "0"
|
|
7979
7977
|
}
|
|
7980
7978
|
);
|
|
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
|
-
}
|
|
8010
7979
|
}
|
|
8011
7980
|
interrupt() {
|
|
8012
7981
|
this.abortController?.abort();
|
|
@@ -8370,14 +8339,20 @@ ${recipeCtx}`;
|
|
|
8370
8339
|
const hasEarlyResults = earlyResultBlocks.length > 0;
|
|
8371
8340
|
const hasRemainingCalls = acc.pendingToolCalls.length > 0;
|
|
8372
8341
|
if (!hasEarlyResults && !hasRemainingCalls) {
|
|
8373
|
-
this.messages.push({
|
|
8342
|
+
this.messages.push({
|
|
8343
|
+
role: "assistant",
|
|
8344
|
+
content: stripPseudoThinking(acc.assistantBlocks)
|
|
8345
|
+
});
|
|
8374
8346
|
getTelemetrySink().histogram("anthropic.latency_ms", Date.now() - turnStartMs);
|
|
8375
8347
|
yield { type: "turn_complete", stopReason: acc.stopReason };
|
|
8376
8348
|
recordTurnOutcome("turn_complete", { stopReason: acc.stopReason });
|
|
8377
8349
|
return;
|
|
8378
8350
|
}
|
|
8379
8351
|
if (signal.aborted) {
|
|
8380
|
-
this.messages.push({
|
|
8352
|
+
this.messages.push({
|
|
8353
|
+
role: "assistant",
|
|
8354
|
+
content: stripPseudoThinking(acc.assistantBlocks)
|
|
8355
|
+
});
|
|
8381
8356
|
if (hasEarlyResults) {
|
|
8382
8357
|
this.messages.push({ role: "user", content: earlyResultBlocks });
|
|
8383
8358
|
}
|
|
@@ -8683,7 +8658,10 @@ ${recipeCtx}`;
|
|
|
8683
8658
|
guardPassedWrites.push(write);
|
|
8684
8659
|
}
|
|
8685
8660
|
if (anyGuardBlocked) {
|
|
8686
|
-
this.messages.push({
|
|
8661
|
+
this.messages.push({
|
|
8662
|
+
role: "assistant",
|
|
8663
|
+
content: stripPseudoThinking(acc.assistantBlocks)
|
|
8664
|
+
});
|
|
8687
8665
|
this.messages.push({ role: "user", content: toolResultBlocks });
|
|
8688
8666
|
getTelemetrySink().counter("engine.turn_outcome", {
|
|
8689
8667
|
entry: freshPrompt !== null ? "submit" : "resume",
|
|
@@ -8714,7 +8692,10 @@ ${recipeCtx}`;
|
|
|
8714
8692
|
isError: true
|
|
8715
8693
|
});
|
|
8716
8694
|
}
|
|
8717
|
-
this.messages.push({
|
|
8695
|
+
this.messages.push({
|
|
8696
|
+
role: "assistant",
|
|
8697
|
+
content: stripPseudoThinking(acc.assistantBlocks)
|
|
8698
|
+
});
|
|
8718
8699
|
this.messages.push({ role: "user", content: toolResultBlocks });
|
|
8719
8700
|
getTelemetrySink().counter("engine.turn_outcome", {
|
|
8720
8701
|
entry: freshPrompt !== null ? "submit" : "resume",
|
|
@@ -8799,7 +8780,10 @@ ${recipeCtx}`;
|
|
|
8799
8780
|
recordTurnOutcome("pending_action_single");
|
|
8800
8781
|
return;
|
|
8801
8782
|
}
|
|
8802
|
-
this.messages.push({
|
|
8783
|
+
this.messages.push({
|
|
8784
|
+
role: "assistant",
|
|
8785
|
+
content: stripPseudoThinking(acc.assistantBlocks)
|
|
8786
|
+
});
|
|
8803
8787
|
this.messages.push({ role: "user", content: toolResultBlocks });
|
|
8804
8788
|
const toolUseBlocks = acc.assistantBlocks.filter((b) => b.type === "tool_use");
|
|
8805
8789
|
const allUpdateTodo = toolUseBlocks.length > 0 && toolUseBlocks.every((b) => b.name === "update_todo");
|
|
@@ -8937,17 +8921,27 @@ ${recipeCtx}`;
|
|
|
8937
8921
|
}
|
|
8938
8922
|
}
|
|
8939
8923
|
};
|
|
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
|
-
}
|
|
8947
8924
|
function isCorruptHistoryError(err) {
|
|
8948
8925
|
const msg = err instanceof Error ? err.message : String(err);
|
|
8949
8926
|
return msg.includes("tool_use") && msg.includes("tool_result") || msg.includes("roles must alternate") || msg.includes("400") && msg.includes("invalid_request_error");
|
|
8950
8927
|
}
|
|
8928
|
+
function stripPseudoThinking(blocks) {
|
|
8929
|
+
const out = [];
|
|
8930
|
+
for (const b of blocks) {
|
|
8931
|
+
if (b.type !== "text") {
|
|
8932
|
+
out.push(b);
|
|
8933
|
+
continue;
|
|
8934
|
+
}
|
|
8935
|
+
const stripped = b.text.replace(/<thinking\b[^>]*>[\s\S]*?(?:<\/thinking>|$)/gi, "").trim();
|
|
8936
|
+
if (stripped.length > 0) {
|
|
8937
|
+
out.push({ ...b, text: stripped });
|
|
8938
|
+
}
|
|
8939
|
+
}
|
|
8940
|
+
if (out.length === 0 && blocks.length > 0) {
|
|
8941
|
+
out.push({ type: "text", text: "[narration omitted]" });
|
|
8942
|
+
}
|
|
8943
|
+
return out;
|
|
8944
|
+
}
|
|
8951
8945
|
function validateHistory(messages) {
|
|
8952
8946
|
const result = [];
|
|
8953
8947
|
let i = 0;
|