@jaypie/llm 1.2.20 → 1.2.22

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.
Files changed (35) hide show
  1. package/dist/cjs/constants.d.ts +31 -31
  2. package/dist/cjs/index.cjs +58 -29
  3. package/dist/cjs/index.cjs.map +1 -1
  4. package/dist/cjs/operate/OperateLoop.d.ts +1 -0
  5. package/dist/cjs/operate/adapters/AnthropicAdapter.d.ts +1 -1
  6. package/dist/cjs/operate/adapters/GeminiAdapter.d.ts +1 -1
  7. package/dist/cjs/operate/adapters/OpenAiAdapter.d.ts +1 -1
  8. package/dist/cjs/operate/adapters/OpenRouterAdapter.d.ts +1 -1
  9. package/dist/cjs/operate/adapters/XaiAdapter.d.ts +1 -1
  10. package/dist/cjs/operate/types.d.ts +2 -0
  11. package/dist/cjs/providers/anthropic/utils.d.ts +1 -1
  12. package/dist/cjs/providers/gemini/utils.d.ts +1 -1
  13. package/dist/cjs/providers/openai/utils.d.ts +1 -1
  14. package/dist/cjs/providers/openrouter/utils.d.ts +1 -1
  15. package/dist/cjs/providers/xai/utils.d.ts +1 -1
  16. package/dist/cjs/util/logger.d.ts +2 -2
  17. package/dist/cjs/util/maxTurnsFromOptions.d.ts +1 -1
  18. package/dist/esm/constants.d.ts +31 -31
  19. package/dist/esm/index.js +58 -29
  20. package/dist/esm/index.js.map +1 -1
  21. package/dist/esm/operate/OperateLoop.d.ts +1 -0
  22. package/dist/esm/operate/adapters/AnthropicAdapter.d.ts +1 -1
  23. package/dist/esm/operate/adapters/GeminiAdapter.d.ts +1 -1
  24. package/dist/esm/operate/adapters/OpenAiAdapter.d.ts +1 -1
  25. package/dist/esm/operate/adapters/OpenRouterAdapter.d.ts +1 -1
  26. package/dist/esm/operate/adapters/XaiAdapter.d.ts +1 -1
  27. package/dist/esm/operate/types.d.ts +2 -0
  28. package/dist/esm/providers/anthropic/utils.d.ts +1 -1
  29. package/dist/esm/providers/gemini/utils.d.ts +1 -1
  30. package/dist/esm/providers/openai/utils.d.ts +1 -1
  31. package/dist/esm/providers/openrouter/utils.d.ts +1 -1
  32. package/dist/esm/providers/xai/utils.d.ts +1 -1
  33. package/dist/esm/util/logger.d.ts +2 -2
  34. package/dist/esm/util/maxTurnsFromOptions.d.ts +1 -1
  35. package/package.json +1 -1
@@ -4,9 +4,9 @@ export declare const PROVIDER: {
4
4
  readonly DEFAULT: 4096;
5
5
  };
6
6
  readonly MODEL: {
7
- readonly DEFAULT: "claude-sonnet-4-5";
8
- readonly LARGE: "claude-opus-4-5";
9
- readonly SMALL: "claude-sonnet-4-5";
7
+ readonly DEFAULT: "claude-sonnet-4-6";
8
+ readonly LARGE: "claude-opus-4-6";
9
+ readonly SMALL: "claude-sonnet-4-6";
10
10
  readonly TINY: "claude-haiku-4-5";
11
11
  };
12
12
  readonly MODEL_MATCH_WORDS: readonly ["anthropic", "claude", "haiku", "opus", "sonnet"];
@@ -26,10 +26,10 @@ export declare const PROVIDER: {
26
26
  };
27
27
  readonly GEMINI: {
28
28
  readonly MODEL: {
29
- readonly DEFAULT: "gemini-3-pro-preview";
30
- readonly LARGE: "gemini-3-pro-preview";
29
+ readonly DEFAULT: "gemini-3.1-pro-preview";
30
+ readonly LARGE: "gemini-3.1-pro-preview";
31
31
  readonly SMALL: "gemini-3-flash-preview";
32
- readonly TINY: "gemini-3-flash-preview";
32
+ readonly TINY: "gemini-3.1-flash-lite-preview";
33
33
  };
34
34
  readonly MODEL_MATCH_WORDS: readonly ["gemini", "google"];
35
35
  readonly NAME: "google";
@@ -40,20 +40,20 @@ export declare const PROVIDER: {
40
40
  };
41
41
  readonly OPENAI: {
42
42
  readonly MODEL: {
43
- readonly DEFAULT: "gpt-5.2";
44
- readonly LARGE: "gpt-5.2-pro";
45
- readonly SMALL: "gpt-5-mini";
46
- readonly TINY: "gpt-5-nano";
43
+ readonly DEFAULT: "gpt-5.4";
44
+ readonly LARGE: "gpt-5.4";
45
+ readonly SMALL: "gpt-5.4-mini";
46
+ readonly TINY: "gpt-5.4-nano";
47
47
  };
48
48
  readonly MODEL_MATCH_WORDS: readonly ["openai", "gpt", RegExp];
49
49
  readonly NAME: "openai";
50
50
  };
51
51
  readonly OPENROUTER: {
52
52
  readonly MODEL: {
53
- readonly DEFAULT: "z-ai/glm-4.7";
54
- readonly LARGE: "z-ai/glm-4.7";
55
- readonly SMALL: "z-ai/glm-4.7";
56
- readonly TINY: "z-ai/glm-4.7";
53
+ readonly DEFAULT: "anthropic/claude-sonnet-4-6";
54
+ readonly LARGE: "anthropic/claude-opus-4-6";
55
+ readonly SMALL: "anthropic/claude-sonnet-4-6";
56
+ readonly TINY: "anthropic/claude-haiku-4-5";
57
57
  };
58
58
  readonly MODEL_MATCH_WORDS: readonly ["openrouter"];
59
59
  readonly NAME: "openrouter";
@@ -68,10 +68,10 @@ export declare const PROVIDER: {
68
68
  readonly API_KEY: "XAI_API_KEY";
69
69
  readonly BASE_URL: "https://api.x.ai/v1";
70
70
  readonly MODEL: {
71
- readonly DEFAULT: "grok-4-1-fast-reasoning";
72
- readonly LARGE: "grok-4-1-fast-reasoning";
73
- readonly SMALL: "grok-3";
74
- readonly TINY: "grok-3-mini";
71
+ readonly DEFAULT: "grok-4.20-0309-reasoning";
72
+ readonly LARGE: "grok-4.20-0309-reasoning";
73
+ readonly SMALL: "grok-4.20-0309-non-reasoning";
74
+ readonly TINY: "grok-4-1-fast-non-reasoning";
75
75
  };
76
76
  readonly MODEL_MATCH_WORDS: readonly ["grok", "xai"];
77
77
  readonly NAME: "xai";
@@ -80,26 +80,26 @@ export declare const PROVIDER: {
80
80
  export type LlmProviderName = typeof PROVIDER.ANTHROPIC.NAME | typeof PROVIDER.GEMINI.NAME | typeof PROVIDER.OPENAI.NAME | typeof PROVIDER.OPENROUTER.NAME | typeof PROVIDER.XAI.NAME;
81
81
  export declare const DEFAULT: {
82
82
  readonly MODEL: {
83
- readonly BASE: "gpt-5.2";
84
- readonly LARGE: "gpt-5.2-pro";
85
- readonly SMALL: "gpt-5-mini";
86
- readonly TINY: "gpt-5-nano";
83
+ readonly BASE: "gpt-5.4";
84
+ readonly LARGE: "gpt-5.4";
85
+ readonly SMALL: "gpt-5.4-mini";
86
+ readonly TINY: "gpt-5.4-nano";
87
87
  };
88
88
  readonly PROVIDER: {
89
89
  readonly MODEL: {
90
- readonly DEFAULT: "gpt-5.2";
91
- readonly LARGE: "gpt-5.2-pro";
92
- readonly SMALL: "gpt-5-mini";
93
- readonly TINY: "gpt-5-nano";
90
+ readonly DEFAULT: "gpt-5.4";
91
+ readonly LARGE: "gpt-5.4";
92
+ readonly SMALL: "gpt-5.4-mini";
93
+ readonly TINY: "gpt-5.4-nano";
94
94
  };
95
95
  readonly MODEL_MATCH_WORDS: readonly ["openai", "gpt", RegExp];
96
96
  readonly NAME: "openai";
97
97
  };
98
98
  };
99
99
  export declare const ALL: {
100
- readonly BASE: readonly ["claude-sonnet-4-5", "gemini-3-pro-preview", "gpt-5.2", "grok-4-1-fast-reasoning"];
101
- readonly COMBINED: readonly ["claude-sonnet-4-5", "claude-opus-4-5", "claude-sonnet-4-5", "claude-haiku-4-5", "gemini-3-pro-preview", "gemini-3-pro-preview", "gemini-3-flash-preview", "gemini-3-flash-preview", "gpt-5.2", "gpt-5.2-pro", "gpt-5-mini", "gpt-5-nano", "grok-4-1-fast-reasoning", "grok-4-1-fast-reasoning", "grok-3", "grok-3-mini"];
102
- readonly LARGE: readonly ["claude-opus-4-5", "gemini-3-pro-preview", "gpt-5.2-pro", "grok-4-1-fast-reasoning"];
103
- readonly SMALL: readonly ["claude-sonnet-4-5", "gemini-3-flash-preview", "gpt-5-mini", "grok-3"];
104
- readonly TINY: readonly ["claude-haiku-4-5", "gemini-3-flash-preview", "gpt-5-nano", "grok-3-mini"];
100
+ readonly BASE: readonly ["claude-sonnet-4-6", "gemini-3.1-pro-preview", "gpt-5.4", "grok-4.20-0309-reasoning"];
101
+ readonly COMBINED: readonly ["claude-sonnet-4-6", "claude-opus-4-6", "claude-sonnet-4-6", "claude-haiku-4-5", "gemini-3.1-pro-preview", "gemini-3.1-pro-preview", "gemini-3-flash-preview", "gemini-3.1-flash-lite-preview", "gpt-5.4", "gpt-5.4", "gpt-5.4-mini", "gpt-5.4-nano", "grok-4.20-0309-reasoning", "grok-4.20-0309-reasoning", "grok-4.20-0309-non-reasoning", "grok-4-1-fast-non-reasoning"];
102
+ readonly LARGE: readonly ["claude-opus-4-6", "gemini-3.1-pro-preview", "gpt-5.4", "grok-4.20-0309-reasoning"];
103
+ readonly SMALL: readonly ["claude-sonnet-4-6", "gemini-3-flash-preview", "gpt-5.4-mini", "grok-4.20-0309-non-reasoning"];
104
+ readonly TINY: readonly ["claude-haiku-4-5", "gemini-3.1-flash-lite-preview", "gpt-5.4-nano", "grok-4-1-fast-non-reasoning"];
105
105
  };
@@ -14,35 +14,33 @@ var aws = require('@jaypie/aws');
14
14
  var openmeteo = require('openmeteo');
15
15
 
16
16
  const FIRST_CLASS_PROVIDER = {
17
+ // https://docs.anthropic.com/en/docs/about-claude/models/overview
17
18
  ANTHROPIC: {
18
- DEFAULT: "claude-sonnet-4-5",
19
- LARGE: "claude-opus-4-5",
20
- SMALL: "claude-sonnet-4-5",
19
+ DEFAULT: "claude-sonnet-4-6",
20
+ LARGE: "claude-opus-4-6",
21
+ SMALL: "claude-sonnet-4-6",
21
22
  TINY: "claude-haiku-4-5",
22
23
  },
24
+ // https://ai.google.dev/gemini-api/docs/models
23
25
  GEMINI: {
24
- DEFAULT: "gemini-3-pro-preview",
25
- LARGE: "gemini-3-pro-preview",
26
+ DEFAULT: "gemini-3.1-pro-preview",
27
+ LARGE: "gemini-3.1-pro-preview",
26
28
  SMALL: "gemini-3-flash-preview",
27
- TINY: "gemini-3-flash-preview",
29
+ TINY: "gemini-3.1-flash-lite-preview",
28
30
  },
31
+ // https://developers.openai.com/api/docs/models
29
32
  OPENAI: {
30
- DEFAULT: "gpt-5.2",
31
- LARGE: "gpt-5.2-pro",
32
- SMALL: "gpt-5-mini",
33
- TINY: "gpt-5-nano",
34
- },
35
- OPENROUTER: {
36
- DEFAULT: "z-ai/glm-4.7",
37
- LARGE: "z-ai/glm-4.7",
38
- SMALL: "z-ai/glm-4.7",
39
- TINY: "z-ai/glm-4.7",
33
+ DEFAULT: "gpt-5.4",
34
+ LARGE: "gpt-5.4",
35
+ SMALL: "gpt-5.4-mini",
36
+ TINY: "gpt-5.4-nano",
40
37
  },
38
+ // https://docs.x.ai/developers/models
41
39
  XAI: {
42
- DEFAULT: "grok-4-1-fast-reasoning",
43
- LARGE: "grok-4-1-fast-reasoning",
44
- SMALL: "grok-3",
45
- TINY: "grok-3-mini",
40
+ DEFAULT: "grok-4.20-0309-reasoning",
41
+ LARGE: "grok-4.20-0309-reasoning",
42
+ SMALL: "grok-4.20-0309-non-reasoning",
43
+ TINY: "grok-4-1-fast-non-reasoning",
46
44
  },
47
45
  };
48
46
  const PROVIDER = {
@@ -105,15 +103,11 @@ const PROVIDER = {
105
103
  NAME: "openai",
106
104
  },
107
105
  OPENROUTER: {
108
- // https://openrouter.ai/models
109
- // OpenRouter provides access to hundreds of models from various providers
110
- // The model format is: provider/model-name (e.g., "openai/gpt-4", "anthropic/claude-3-opus")
111
106
  MODEL: {
112
- // Default uses env var OPENROUTER_MODEL if set, otherwise a reasonable default
113
- DEFAULT: FIRST_CLASS_PROVIDER.OPENROUTER.DEFAULT,
114
- LARGE: FIRST_CLASS_PROVIDER.OPENROUTER.LARGE,
115
- SMALL: FIRST_CLASS_PROVIDER.OPENROUTER.SMALL,
116
- TINY: FIRST_CLASS_PROVIDER.OPENROUTER.TINY,
107
+ DEFAULT: `anthropic/${FIRST_CLASS_PROVIDER.ANTHROPIC.DEFAULT}`,
108
+ LARGE: `anthropic/${FIRST_CLASS_PROVIDER.ANTHROPIC.LARGE}`,
109
+ SMALL: `anthropic/${FIRST_CLASS_PROVIDER.ANTHROPIC.SMALL}`,
110
+ TINY: `anthropic/${FIRST_CLASS_PROVIDER.ANTHROPIC.TINY}`,
117
111
  },
118
112
  MODEL_MATCH_WORDS: ["openrouter"],
119
113
  NAME: "openrouter",
@@ -563,7 +557,7 @@ const log$1 = getLogger$5();
563
557
 
564
558
  // Turn policy constants
565
559
  const MAX_TURNS_ABSOLUTE_LIMIT = 72;
566
- const MAX_TURNS_DEFAULT_LIMIT = 12;
560
+ const MAX_TURNS_DEFAULT_LIMIT = 24;
567
561
  /**
568
562
  * Determines the maximum number of turns based on the provided options
569
563
  *
@@ -4155,6 +4149,7 @@ class RetryExecutor {
4155
4149
  const ERROR$1 = {
4156
4150
  BAD_FUNCTION_CALL: "Bad Function Call",
4157
4151
  };
4152
+ const MAX_CONSECUTIVE_TOOL_ERRORS = 6;
4158
4153
  //
4159
4154
  //
4160
4155
  // Helpers
@@ -4277,6 +4272,7 @@ class OperateLoop {
4277
4272
  }
4278
4273
  }
4279
4274
  return {
4275
+ consecutiveToolErrors: 0,
4280
4276
  currentInput: processedInput.history,
4281
4277
  currentTurn: 0,
4282
4278
  formattedFormat,
@@ -4401,6 +4397,8 @@ class OperateLoop {
4401
4397
  output: JSON.stringify(result),
4402
4398
  success: true,
4403
4399
  };
4400
+ // Reset consecutive error counter on success
4401
+ state.consecutiveToolErrors = 0;
4404
4402
  // Update provider request with tool result
4405
4403
  currentProviderRequest = this.adapter.appendToolResult(currentProviderRequest, toolCall, formattedResult);
4406
4404
  // Sync state from updated request
@@ -4442,6 +4440,19 @@ class OperateLoop {
4442
4440
  state.responseBuilder.appendToHistory(toolResultFormatted);
4443
4441
  log$1.error(`Error executing function call ${toolCall.name}`);
4444
4442
  log$1.var({ error });
4443
+ // Track consecutive errors and stop if threshold reached
4444
+ state.consecutiveToolErrors++;
4445
+ if (state.consecutiveToolErrors >= MAX_CONSECUTIVE_TOOL_ERRORS) {
4446
+ const detail = `Stopped after ${MAX_CONSECUTIVE_TOOL_ERRORS} consecutive tool errors`;
4447
+ log$1.warn(detail);
4448
+ state.responseBuilder.setError({
4449
+ detail,
4450
+ status: 502,
4451
+ title: ERROR$1.BAD_FUNCTION_CALL,
4452
+ });
4453
+ state.responseBuilder.incomplete();
4454
+ return false; // Stop loop
4455
+ }
4445
4456
  }
4446
4457
  }
4447
4458
  // Check if we've reached max turns
@@ -4689,6 +4700,7 @@ class StreamLoop {
4689
4700
  ? this.adapter.formatTools(toolkit, formattedFormat)
4690
4701
  : undefined;
4691
4702
  return {
4703
+ consecutiveToolErrors: 0,
4692
4704
  currentInput: processedInput.history,
4693
4705
  currentTurn: 0,
4694
4706
  formattedFormat,
@@ -4882,6 +4894,8 @@ class StreamLoop {
4882
4894
  result,
4883
4895
  toolName: toolCall.name,
4884
4896
  });
4897
+ // Reset consecutive error counter on success
4898
+ state.consecutiveToolErrors = 0;
4885
4899
  // Yield tool result chunk
4886
4900
  yield {
4887
4901
  type: exports.LlmStreamChunkType.ToolResult,
@@ -4934,6 +4948,21 @@ class StreamLoop {
4934
4948
  });
4935
4949
  log$1.error(`Error executing function call ${toolCall.name}`);
4936
4950
  log$1.var({ error });
4951
+ // Track consecutive errors and stop if threshold reached
4952
+ state.consecutiveToolErrors++;
4953
+ if (state.consecutiveToolErrors >= MAX_CONSECUTIVE_TOOL_ERRORS) {
4954
+ const stopDetail = `Stopped after ${MAX_CONSECUTIVE_TOOL_ERRORS} consecutive tool errors`;
4955
+ log$1.warn(stopDetail);
4956
+ yield {
4957
+ type: exports.LlmStreamChunkType.Error,
4958
+ error: {
4959
+ detail: stopDetail,
4960
+ status: 502,
4961
+ title: ERROR.BAD_FUNCTION_CALL,
4962
+ },
4963
+ };
4964
+ return; // Stop processing tools
4965
+ }
4937
4966
  }
4938
4967
  }
4939
4968
  }