llmist 16.2.2 → 16.2.4

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 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;
@@ -5291,6 +5306,45 @@ var init_activation = __esm({
5291
5306
  }
5292
5307
  });
5293
5308
 
5309
+ // src/skills/load-skill-gadget.ts
5310
+ function createLoadSkillGadget(registry) {
5311
+ const summaries = registry.getMetadataSummaries();
5312
+ const skillNames = registry.getModelInvocable().map((s) => s.name);
5313
+ const description = [
5314
+ "Load a skill's specialized instructions into context for a task.",
5315
+ "Available skills:",
5316
+ summaries
5317
+ ].join("\n");
5318
+ return createGadget({
5319
+ name: LOAD_SKILL_GADGET_NAME,
5320
+ description,
5321
+ schema: import_zod2.z.object({
5322
+ skill: import_zod2.z.enum(skillNames).describe("Name of the skill to load"),
5323
+ arguments: import_zod2.z.string().optional().describe("Arguments for the skill (e.g., a filename, issue number, or search query)")
5324
+ }),
5325
+ execute: async ({ skill: skillName, arguments: args }) => {
5326
+ const skill = registry.get(skillName);
5327
+ if (!skill) {
5328
+ return `Unknown skill: "${skillName}". Available skills: ${skillNames.join(", ")}`;
5329
+ }
5330
+ const activation = await skill.activate({
5331
+ arguments: args,
5332
+ cwd: process.cwd()
5333
+ });
5334
+ return activation.resolvedInstructions;
5335
+ }
5336
+ });
5337
+ }
5338
+ var import_zod2, LOAD_SKILL_GADGET_NAME;
5339
+ var init_load_skill_gadget = __esm({
5340
+ "src/skills/load-skill-gadget.ts"() {
5341
+ "use strict";
5342
+ import_zod2 = require("zod");
5343
+ init_create_gadget();
5344
+ LOAD_SKILL_GADGET_NAME = "LoadSkill";
5345
+ }
5346
+ });
5347
+
5294
5348
  // src/skills/parser.ts
5295
5349
  function parseFrontmatter(content) {
5296
5350
  const trimmed = content.trimStart();
@@ -5784,45 +5838,6 @@ var init_loader = __esm({
5784
5838
  }
5785
5839
  });
5786
5840
 
5787
- // src/skills/use-skill-gadget.ts
5788
- function createUseSkillGadget(registry) {
5789
- const summaries = registry.getMetadataSummaries();
5790
- const skillNames = registry.getModelInvocable().map((s) => s.name);
5791
- const description = [
5792
- "Activate a skill to get specialized instructions for a task.",
5793
- "Available skills:",
5794
- summaries
5795
- ].join("\n");
5796
- return createGadget({
5797
- name: USE_SKILL_GADGET_NAME,
5798
- description,
5799
- schema: import_zod2.z.object({
5800
- skill: import_zod2.z.enum(skillNames).describe("Name of the skill to activate"),
5801
- arguments: import_zod2.z.string().optional().describe("Arguments for the skill (e.g., a filename, issue number, or search query)")
5802
- }),
5803
- execute: async ({ skill: skillName, arguments: args }) => {
5804
- const skill = registry.get(skillName);
5805
- if (!skill) {
5806
- return `Unknown skill: "${skillName}". Available skills: ${skillNames.join(", ")}`;
5807
- }
5808
- const activation = await skill.activate({
5809
- arguments: args,
5810
- cwd: process.cwd()
5811
- });
5812
- return activation.resolvedInstructions;
5813
- }
5814
- });
5815
- }
5816
- var import_zod2, USE_SKILL_GADGET_NAME;
5817
- var init_use_skill_gadget = __esm({
5818
- "src/skills/use-skill-gadget.ts"() {
5819
- "use strict";
5820
- import_zod2 = require("zod");
5821
- init_create_gadget();
5822
- USE_SKILL_GADGET_NAME = "UseSkill";
5823
- }
5824
- });
5825
-
5826
5841
  // src/agent/builder-utils.ts
5827
5842
  function formatGadgetCall(gadgetName, invocationId, parameters, prefixes) {
5828
5843
  const startPrefix = prefixes?.start ?? GADGET_START_PREFIX;
@@ -11843,7 +11858,18 @@ Original error: ${error.message}`
11843
11858
  Original error: ${error.message}`
11844
11859
  );
11845
11860
  }
11846
- if (message.includes("401") || message.includes("unauthorized") || message.includes("invalid")) {
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}`
@@ -12828,9 +12854,9 @@ var init_builder = __esm({
12828
12854
  init_model_shortcuts();
12829
12855
  init_registry();
12830
12856
  init_activation();
12857
+ init_load_skill_gadget();
12831
12858
  init_loader();
12832
12859
  init_parser();
12833
- init_use_skill_gadget();
12834
12860
  init_agent();
12835
12861
  init_agent_internal_key();
12836
12862
  init_builder_utils();
@@ -13165,7 +13191,7 @@ ${resolved}`);
13165
13191
  const skillRegistry = this.resolveSkillRegistry();
13166
13192
  if (skillRegistry && skillRegistry.size > 0) {
13167
13193
  if (skillRegistry.getModelInvocable().length > 0) {
13168
- registry.registerByClass(createUseSkillGadget(skillRegistry));
13194
+ registry.registerByClass(createLoadSkillGadget(skillRegistry));
13169
13195
  }
13170
13196
  const preActivatedBlock = this.resolvePreActivatedInstructions(skillRegistry);
13171
13197
  if (preActivatedBlock) {
@@ -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,
@@ -16982,6 +17046,7 @@ __export(index_exports, {
16982
17046
  HybridStrategy: () => HybridStrategy,
16983
17047
  LLMMessageBuilder: () => LLMMessageBuilder,
16984
17048
  LLMist: () => LLMist,
17049
+ LOAD_SKILL_GADGET_NAME: () => LOAD_SKILL_GADGET_NAME,
16985
17050
  MODEL_ALIASES: () => MODEL_ALIASES,
16986
17051
  MediaStore: () => MediaStore,
16987
17052
  ModelIdentifierParser: () => ModelIdentifierParser,
@@ -16998,7 +17063,6 @@ __export(index_exports, {
16998
17063
  SummarizationStrategy: () => SummarizationStrategy,
16999
17064
  TaskCompletionSignal: () => TaskCompletionSignal,
17000
17065
  TimeoutException: () => TimeoutException,
17001
- USE_SKILL_GADGET_NAME: () => USE_SKILL_GADGET_NAME,
17002
17066
  audioFromBase64: () => audioFromBase64,
17003
17067
  audioFromBuffer: () => audioFromBuffer,
17004
17068
  collectEvents: () => collectEvents,
@@ -17011,12 +17075,12 @@ __export(index_exports, {
17011
17075
  createGeminiProviderFromEnv: () => createGeminiProviderFromEnv,
17012
17076
  createHints: () => createHints,
17013
17077
  createHuggingFaceProviderFromEnv: () => createHuggingFaceProviderFromEnv,
17078
+ createLoadSkillGadget: () => createLoadSkillGadget,
17014
17079
  createLogger: () => createLogger,
17015
17080
  createMediaOutput: () => createMediaOutput,
17016
17081
  createOpenAIProviderFromEnv: () => createOpenAIProviderFromEnv,
17017
17082
  createOpenRouterProviderFromEnv: () => createOpenRouterProviderFromEnv,
17018
17083
  createSubagent: () => createSubagent,
17019
- createUseSkillGadget: () => createUseSkillGadget,
17020
17084
  defaultLogger: () => defaultLogger,
17021
17085
  detectAudioMimeType: () => detectAudioMimeType,
17022
17086
  detectImageMimeType: () => detectImageMimeType,
@@ -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,
@@ -17696,11 +17761,11 @@ var SimpleSessionManager = class extends BaseSessionManager {
17696
17761
 
17697
17762
  // src/skills/index.ts
17698
17763
  init_activation();
17764
+ init_load_skill_gadget();
17699
17765
  init_loader();
17700
17766
  init_parser();
17701
17767
  init_registry2();
17702
17768
  init_skill();
17703
- init_use_skill_gadget();
17704
17769
 
17705
17770
  // src/utils/format.ts
17706
17771
  function truncate(text3, maxLength, suffix = "...") {
@@ -17889,6 +17954,7 @@ function getHostExports2(ctx) {
17889
17954
  HybridStrategy,
17890
17955
  LLMMessageBuilder,
17891
17956
  LLMist,
17957
+ LOAD_SKILL_GADGET_NAME,
17892
17958
  MODEL_ALIASES,
17893
17959
  MediaStore,
17894
17960
  ModelIdentifierParser,
@@ -17905,7 +17971,6 @@ function getHostExports2(ctx) {
17905
17971
  SummarizationStrategy,
17906
17972
  TaskCompletionSignal,
17907
17973
  TimeoutException,
17908
- USE_SKILL_GADGET_NAME,
17909
17974
  audioFromBase64,
17910
17975
  audioFromBuffer,
17911
17976
  collectEvents,
@@ -17918,12 +17983,12 @@ function getHostExports2(ctx) {
17918
17983
  createGeminiProviderFromEnv,
17919
17984
  createHints,
17920
17985
  createHuggingFaceProviderFromEnv,
17986
+ createLoadSkillGadget,
17921
17987
  createLogger,
17922
17988
  createMediaOutput,
17923
17989
  createOpenAIProviderFromEnv,
17924
17990
  createOpenRouterProviderFromEnv,
17925
17991
  createSubagent,
17926
- createUseSkillGadget,
17927
17992
  defaultLogger,
17928
17993
  detectAudioMimeType,
17929
17994
  detectImageMimeType,
@@ -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,