llmist 16.2.1 → 16.2.3
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.cjs +68 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +19 -1
- package/dist/index.d.ts +19 -1
- package/dist/index.js +67 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1982,6 +1982,21 @@ function isRetryableError(error) {
|
|
|
1982
1982
|
}
|
|
1983
1983
|
return false;
|
|
1984
1984
|
}
|
|
1985
|
+
function isLikelyContextOverflow(error) {
|
|
1986
|
+
const message = error.message.toLowerCase();
|
|
1987
|
+
const statusCode = getErrorStatusCode(error);
|
|
1988
|
+
if (message.includes("context length") || message.includes("token limit") || message.includes("payload too large") || message.includes("request too large") || message.includes("request entity too large") || message.includes("maximum context") || message.includes("content size exceeded") || message.includes("content too large")) {
|
|
1989
|
+
return true;
|
|
1990
|
+
}
|
|
1991
|
+
const is400 = statusCode === 400 || statusCode === void 0 && message.includes("400");
|
|
1992
|
+
if (!is400) {
|
|
1993
|
+
return false;
|
|
1994
|
+
}
|
|
1995
|
+
if (message.includes("authentication") || message.includes("unauthorized") || message.includes("invalid api key") || message.includes("invalid key") || message.includes("invalid model") || message.includes("invalid parameter") || message.includes("content policy") || message.includes("safety") || message.includes("permission") || message.includes("unsupported") || message.includes("not supported") || message.includes("missing required") || message.includes("malformed") || message.includes("not found")) {
|
|
1996
|
+
return false;
|
|
1997
|
+
}
|
|
1998
|
+
return true;
|
|
1999
|
+
}
|
|
1985
2000
|
function formatLLMError(error, context) {
|
|
1986
2001
|
const message = error.message;
|
|
1987
2002
|
const name = error.name;
|
|
@@ -11843,7 +11858,18 @@ Original error: ${error.message}`
|
|
|
11843
11858
|
Original error: ${error.message}`
|
|
11844
11859
|
);
|
|
11845
11860
|
}
|
|
11846
|
-
if (message.includes("
|
|
11861
|
+
if (message.includes("400") || message.includes("bad request")) {
|
|
11862
|
+
const enhanced = new Error(
|
|
11863
|
+
`OpenRouter: Provider returned error (400). This may indicate the request exceeded the model's limits, or a model-specific rejection.
|
|
11864
|
+
Original error: ${error.message}`
|
|
11865
|
+
);
|
|
11866
|
+
const originalStatus = error.status;
|
|
11867
|
+
Object.assign(enhanced, {
|
|
11868
|
+
status: typeof originalStatus === "number" ? originalStatus : 400
|
|
11869
|
+
});
|
|
11870
|
+
return enhanced;
|
|
11871
|
+
}
|
|
11872
|
+
if (message.includes("401") || message.includes("unauthorized") || message.includes("invalid api key") || message.includes("invalid key") || message.includes("invalid_api_key")) {
|
|
11847
11873
|
return new Error(
|
|
11848
11874
|
`OpenRouter: Authentication failed. Check that OPENROUTER_API_KEY is set correctly.
|
|
11849
11875
|
Original error: ${error.message}`
|
|
@@ -16224,7 +16250,7 @@ var init_stream_processor_factory = __esm({
|
|
|
16224
16250
|
});
|
|
16225
16251
|
|
|
16226
16252
|
// src/agent/agent.ts
|
|
16227
|
-
var Agent;
|
|
16253
|
+
var OVERFLOW_RECOVERY_MIN_HISTORY, Agent;
|
|
16228
16254
|
var init_agent = __esm({
|
|
16229
16255
|
"src/agent/agent.ts"() {
|
|
16230
16256
|
"use strict";
|
|
@@ -16247,6 +16273,7 @@ var init_agent = __esm({
|
|
|
16247
16273
|
init_safe_observe();
|
|
16248
16274
|
init_stream_processor_factory();
|
|
16249
16275
|
init_tree_hook_bridge();
|
|
16276
|
+
OVERFLOW_RECOVERY_MIN_HISTORY = 4;
|
|
16250
16277
|
Agent = class {
|
|
16251
16278
|
client;
|
|
16252
16279
|
model;
|
|
@@ -16624,6 +16651,7 @@ var init_agent = __esm({
|
|
|
16624
16651
|
});
|
|
16625
16652
|
let currentLLMNodeId;
|
|
16626
16653
|
let llmOptions;
|
|
16654
|
+
let hasAttemptedOverflowRecovery = false;
|
|
16627
16655
|
try {
|
|
16628
16656
|
while (currentIteration < this.maxIterations) {
|
|
16629
16657
|
if (await this.checkAbortAndNotify(currentIteration)) {
|
|
@@ -16710,6 +16738,34 @@ var init_agent = __esm({
|
|
|
16710
16738
|
}
|
|
16711
16739
|
}
|
|
16712
16740
|
} catch (error) {
|
|
16741
|
+
const historyLength = this.conversation.getHistoryMessages().length;
|
|
16742
|
+
if (this.compactionManager && !hasAttemptedOverflowRecovery && isLikelyContextOverflow(error) && historyLength >= OVERFLOW_RECOVERY_MIN_HISTORY) {
|
|
16743
|
+
hasAttemptedOverflowRecovery = true;
|
|
16744
|
+
this.logger.warn("Possible context overflow detected, attempting compaction recovery", {
|
|
16745
|
+
error: error.message,
|
|
16746
|
+
iteration: currentIteration,
|
|
16747
|
+
historyMessages: historyLength
|
|
16748
|
+
});
|
|
16749
|
+
try {
|
|
16750
|
+
const compactionEvent = await this.compactionManager.compact(
|
|
16751
|
+
this.conversation,
|
|
16752
|
+
currentIteration
|
|
16753
|
+
);
|
|
16754
|
+
if (compactionEvent) {
|
|
16755
|
+
const event = await this.emitCompactionEvent(compactionEvent, currentIteration);
|
|
16756
|
+
yield event;
|
|
16757
|
+
continue;
|
|
16758
|
+
}
|
|
16759
|
+
this.logger.warn("Compaction returned no result, cannot recover from overflow");
|
|
16760
|
+
} catch (compactionError) {
|
|
16761
|
+
this.logger.warn(
|
|
16762
|
+
"Compaction failed during overflow recovery, propagating original error",
|
|
16763
|
+
{
|
|
16764
|
+
compactionError: compactionError.message
|
|
16765
|
+
}
|
|
16766
|
+
);
|
|
16767
|
+
}
|
|
16768
|
+
}
|
|
16713
16769
|
const action = await this.llmCallLifecycle.notifyLLMError(
|
|
16714
16770
|
currentIteration,
|
|
16715
16771
|
currentLLMNodeId,
|
|
@@ -16906,6 +16962,14 @@ var init_agent = __esm({
|
|
|
16906
16962
|
iteration
|
|
16907
16963
|
);
|
|
16908
16964
|
if (!compactionEvent) return null;
|
|
16965
|
+
return this.emitCompactionEvent(compactionEvent, iteration);
|
|
16966
|
+
}
|
|
16967
|
+
/**
|
|
16968
|
+
* Log compaction, notify observers, and return a StreamEvent.
|
|
16969
|
+
* Shared by proactive compaction (checkAndPerformCompaction) and
|
|
16970
|
+
* reactive overflow recovery (catch block).
|
|
16971
|
+
*/
|
|
16972
|
+
async emitCompactionEvent(compactionEvent, iteration) {
|
|
16909
16973
|
this.logger.info("Context compacted", {
|
|
16910
16974
|
strategy: compactionEvent.strategy,
|
|
16911
16975
|
tokensBefore: compactionEvent.tokensBefore,
|
|
@@ -17057,6 +17121,7 @@ __export(index_exports, {
|
|
|
17057
17121
|
isGadgetEvent: () => isGadgetEvent,
|
|
17058
17122
|
isImagePart: () => isImagePart,
|
|
17059
17123
|
isLLMEvent: () => isLLMEvent,
|
|
17124
|
+
isLikelyContextOverflow: () => isLikelyContextOverflow,
|
|
17060
17125
|
isRetryableError: () => isRetryableError,
|
|
17061
17126
|
isRootEvent: () => isRootEvent,
|
|
17062
17127
|
isSubagentEvent: () => isSubagentEvent,
|
|
@@ -17964,6 +18029,7 @@ function getHostExports2(ctx) {
|
|
|
17964
18029
|
isGadgetEvent,
|
|
17965
18030
|
isImagePart,
|
|
17966
18031
|
isLLMEvent,
|
|
18032
|
+
isLikelyContextOverflow,
|
|
17967
18033
|
isRetryableError,
|
|
17968
18034
|
isRootEvent,
|
|
17969
18035
|
isSubagentEvent,
|