@juspay/neurolink 13.16.1 → 13.17.0

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 (121) hide show
  1. package/CHANGELOG.md +3 -3
  2. package/dist/adapters/providerImageAdapter.js +29 -495
  3. package/dist/browser/neurolink.min.js +464 -470
  4. package/dist/constants/contextWindows.js +13 -328
  5. package/dist/constants/enums.d.ts +1 -0
  6. package/dist/constants/enums.js +2 -1
  7. package/dist/context/anthropicLoopGuard.d.ts +1 -1
  8. package/dist/context/anthropicLoopGuard.js +2 -1
  9. package/dist/core/constants.js +6 -53
  10. package/dist/core/geminiLoopAdapter.js +8 -6
  11. package/dist/core/modules/structuredOutputPolicy.d.ts +0 -21
  12. package/dist/core/modules/structuredOutputPolicy.js +4 -54
  13. package/dist/factories/providerDescriptors.js +3 -2
  14. package/dist/factories/providerRegistry.js +3 -2
  15. package/dist/models/manifests/anthropic.d.ts +1 -1
  16. package/dist/models/manifests/anthropic.js +1 -1
  17. package/dist/models/manifests/azure.js +9 -9
  18. package/dist/models/manifests/ollama.js +13 -0
  19. package/dist/models/manifests/openai.d.ts +1 -1
  20. package/dist/models/manifests/openai.js +1 -1
  21. package/dist/models/modelRegistry.js +17 -42
  22. package/dist/providers/amazonBedrock/client.js +9 -37
  23. package/dist/providers/amazonBedrock/loopAdapter.js +3 -11
  24. package/dist/providers/anthropic/client.js +42 -97
  25. package/dist/providers/anthropic/loopAdapter.js +24 -22
  26. package/dist/providers/anthropic/structuredOutput.d.ts +0 -2
  27. package/dist/providers/anthropic/structuredOutput.js +3 -5
  28. package/dist/providers/azureOpenai.js +4 -22
  29. package/dist/providers/catalog/loader.js +12 -25
  30. package/dist/providers/cohere.js +5 -30
  31. package/dist/providers/googleAiStudio/client.js +12 -61
  32. package/dist/providers/googleNativeGemini3/utils.js +43 -102
  33. package/dist/providers/googleVertex/client.js +123 -184
  34. package/dist/providers/litellm/client.js +10 -50
  35. package/dist/providers/llamaCpp.js +4 -15
  36. package/dist/providers/lmStudio.js +9 -14
  37. package/dist/providers/nvidiaNim/client.js +4 -62
  38. package/dist/providers/ollama/client.js +14 -54
  39. package/dist/providers/ollama/constants.d.ts +1 -3
  40. package/dist/providers/ollama/constants.js +2 -3
  41. package/dist/providers/openAI/client.js +5 -57
  42. package/dist/providers/openRouter/client.js +4 -65
  43. package/dist/providers/openaiChatCompletionsBase.js +34 -58
  44. package/dist/providers/openaiChatCompletionsClient.js +17 -57
  45. package/dist/providers/openaiCompatible/client.js +9 -36
  46. package/dist/providers/rules/README.md +100 -0
  47. package/dist/providers/rules/anthropic.json +104 -0
  48. package/dist/providers/rules/azure.json +13 -0
  49. package/dist/providers/rules/bedrock.json +48 -0
  50. package/dist/providers/rules/cohere.json +32 -0
  51. package/dist/providers/rules/credentials.json +34 -0
  52. package/dist/providers/rules/errorRules.d.ts +17 -0
  53. package/dist/providers/rules/errorRules.js +197 -0
  54. package/dist/providers/rules/errorSignals.d.ts +2 -0
  55. package/dist/providers/rules/errorSignals.js +28 -0
  56. package/dist/providers/rules/fallbackModel.d.ts +4 -0
  57. package/dist/providers/rules/fallbackModel.js +21 -0
  58. package/dist/providers/rules/finalResultTool.d.ts +11 -0
  59. package/dist/providers/rules/finalResultTool.js +17 -0
  60. package/dist/providers/rules/finishReasons.d.ts +10 -0
  61. package/dist/providers/rules/finishReasons.js +28 -0
  62. package/dist/providers/rules/gemini.json +92 -0
  63. package/dist/providers/rules/google-ai.json +55 -0
  64. package/dist/providers/rules/limits.json +338 -0
  65. package/dist/providers/rules/litellm.json +36 -0
  66. package/dist/providers/rules/llamacpp.json +23 -0
  67. package/dist/providers/rules/lm-studio.json +21 -0
  68. package/dist/providers/rules/model-families.json +109 -0
  69. package/dist/providers/rules/modelFamilies.d.ts +10 -0
  70. package/dist/providers/rules/modelFamilies.js +45 -0
  71. package/dist/providers/rules/nvidia-nim.json +43 -0
  72. package/dist/providers/rules/ollama.json +37 -0
  73. package/dist/providers/rules/openai-chat.json +66 -0
  74. package/dist/providers/rules/openai-compatible.json +31 -0
  75. package/dist/providers/rules/openai.json +38 -0
  76. package/dist/providers/rules/openrouter.json +57 -0
  77. package/dist/providers/rules/proxy.json +44 -0
  78. package/dist/providers/rules/registry.d.ts +7 -0
  79. package/dist/providers/rules/registry.js +76 -0
  80. package/dist/providers/rules/requestDefaults.d.ts +7 -0
  81. package/dist/providers/rules/requestDefaults.js +9 -0
  82. package/dist/providers/rules/requestFields.d.ts +18 -0
  83. package/dist/providers/rules/requestFields.js +38 -0
  84. package/dist/providers/rules/sagemaker.json +88 -0
  85. package/dist/providers/rules/schema.d.ts +234 -0
  86. package/dist/providers/rules/schema.js +352 -0
  87. package/dist/providers/rules/structured-output.json +36 -0
  88. package/dist/providers/rules/thinkingLimits.d.ts +7 -0
  89. package/dist/providers/rules/thinkingLimits.js +9 -0
  90. package/dist/providers/rules/toolRules.d.ts +16 -0
  91. package/dist/providers/rules/toolRules.js +95 -0
  92. package/dist/providers/rules/usage.json +51 -0
  93. package/dist/providers/rules/vertex.json +65 -0
  94. package/dist/providers/rules/vision.json +505 -0
  95. package/dist/providers/rules/wireUsage.d.ts +38 -0
  96. package/dist/providers/rules/wireUsage.js +82 -0
  97. package/dist/providers/sagemaker/language-model.js +6 -33
  98. package/dist/providers/sagemaker/parsers.js +13 -48
  99. package/dist/providers/sagemaker/streaming.js +9 -16
  100. package/dist/proxy/claudeFormat.js +3 -16
  101. package/dist/proxy/geminiFormat.js +3 -9
  102. package/dist/proxy/openaiFormat.js +3 -16
  103. package/dist/types/index.d.ts +1 -0
  104. package/dist/types/index.js +2 -0
  105. package/dist/types/providerRules.d.ts +407 -0
  106. package/dist/types/providerRules.js +10 -0
  107. package/dist/utils/errorClassifier.d.ts +2 -2
  108. package/dist/utils/errorClassifier.js +3 -2
  109. package/dist/utils/modelDetection.d.ts +1 -1
  110. package/dist/utils/modelDetection.js +30 -71
  111. package/dist/utils/providerConfig.d.ts +10 -9
  112. package/dist/utils/providerConfig.js +26 -25
  113. package/dist/utils/providerHealth.js +1 -0
  114. package/dist/utils/thinkingConfig.d.ts +1 -1
  115. package/dist/utils/thinkingConfig.js +8 -8
  116. package/dist/utils/tokenUtils.d.ts +12 -38
  117. package/dist/utils/tokenUtils.js +44 -127
  118. package/docs-site/static/search-index.json +5 -5
  119. package/package.json +2 -1
  120. package/dist/providers/localRuntimeOpenAICompat.d.ts +0 -16
  121. package/dist/providers/localRuntimeOpenAICompat.js +0 -26
@@ -16,6 +16,17 @@ import { resolveManifestEntryStrict } from "../models/manifestRegistry.js";
16
16
  import { getCatalogJsonEntries } from "../providers/catalog/loader.js";
17
17
  import { bedrockModelIdForLookup } from "./bedrockIdentifiers.js";
18
18
  export { stripBedrockGeoPrefix } from "./bedrockIdentifiers.js";
19
+ import { getProviderRules } from "../providers/rules/registry.js";
20
+ // Per-model context windows and provider aliases live in
21
+ // src/lib/providers/rules/limits.json (`contextWindowNotes` keeps the reasons).
22
+ const LIMITS = loadLimits();
23
+ function loadLimits() {
24
+ const { contextWindows, providerAliases } = getProviderRules("limits");
25
+ if (!contextWindows || !providerAliases) {
26
+ throw new Error('limits.json needs "contextWindows" and "providerAliases"');
27
+ }
28
+ return { contextWindows, providerAliases };
29
+ }
19
30
  /**
20
31
  * Per-provider context window blocks for the 9 JSON-catalog providers
21
32
  * (cerebras, cloudflare, fireworks, groq, mistral, perplexity, sambanova,
@@ -96,315 +107,7 @@ export const DEFAULT_OUTPUT_RESERVE_RATIO = 0.35;
96
107
  * The "_default" key is the fallback for unknown models within a provider.
97
108
  */
98
109
  export const MODEL_CONTEXT_WINDOWS = {
99
- "nvidia-nim": {
100
- _default: 128_000,
101
- "meta/llama-3.3-70b-instruct": 128_000,
102
- "meta/llama-3.1-405b-instruct": 128_000,
103
- "meta/llama-3.1-70b-instruct": 128_000,
104
- "meta/llama-3.2-90b-vision-instruct": 128_000,
105
- "meta/llama-3.2-11b-vision-instruct": 128_000,
106
- "nvidia/llama-3.3-nemotron-super-49b-v1": 128_000,
107
- "nvidia/llama-3.1-nemotron-nano-8b-v1": 128_000,
108
- "nvidia/llama-3.1-nemotron-70b-instruct": 128_000,
109
- "deepseek-ai/deepseek-r1": 128_000,
110
- "deepseek-ai/deepseek-r1-distill-llama-70b": 128_000,
111
- "mistralai/mixtral-8x22b-instruct-v0.1": 65_536,
112
- "mistralai/mixtral-8x7b-instruct-v0.1": 32_768,
113
- "microsoft/phi-4": 16_384,
114
- "google/gemma-3-27b-it": 8_192,
115
- "openai/gpt-oss-20b": 131_072,
116
- },
117
- "lm-studio": {
118
- _default: 8_192,
119
- },
120
- llamacpp: {
121
- _default: 8_192,
122
- },
123
- cohere: {
124
- _default: 128_000,
125
- "command-r-plus": 128_000,
126
- "command-r": 128_000,
127
- "command-r7b-12-2024": 128_000,
128
- },
129
- replicate: {
130
- // Per-model — Replicate hosts arbitrary models; sensible default.
131
- _default: 32_768,
132
- },
133
- voyage: {
134
- // Voyage embeddings: max input tokens vary 16K-32K per model
135
- _default: 32_000,
136
- "voyage-4": 32_000,
137
- "voyage-4-large": 32_000,
138
- "voyage-4-lite": 32_000,
139
- "voyage-code-4": 32_000,
140
- "voyage-3.5": 32_000,
141
- "voyage-3.5-lite": 32_000,
142
- "voyage-3-large": 32_000,
143
- "voyage-code-3": 32_000,
144
- "voyage-finance-2": 32_000,
145
- "voyage-law-2": 16_000,
146
- "voyage-multilingual-2": 32_000,
147
- },
148
- jina: {
149
- // Jina embeddings: 8K input tokens for v3; 8K for v2; 32K for ColBERT-v2
150
- _default: 8_192,
151
- "jina-embeddings-v3": 8_192,
152
- "jina-embeddings-v2-base-en": 8_192,
153
- "jina-embeddings-v2-small-en": 8_192,
154
- "jina-colbert-v2": 32_000,
155
- },
156
- stability: {
157
- // Image-gen — context is prompt length only; ~2000 char limit
158
- _default: 2_000,
159
- },
160
- ideogram: {
161
- _default: 2_000,
162
- },
163
- recraft: {
164
- _default: 2_000,
165
- },
166
- anthropic: {
167
- _default: 200_000,
168
- // Claude 5.5 / 5.1 (Sep 2026) — 1M context window, confirmed on
169
- // platform.claude.com/docs/en/about-claude/models/overview
170
- "claude-opus-5-5": 1_000_000,
171
- "claude-sonnet-5-5": 1_000_000,
172
- "claude-fable-5-1": 1_000_000,
173
- // Claude 5 (mid 2026) — 1M context window
174
- "claude-sonnet-5": 1_000_000,
175
- "claude-opus-5": 1_000_000,
176
- "claude-fable-5": 1_000_000,
177
- // Claude 4.7 / 4.8 — 1M context window (platform.claude.com/docs/en/models)
178
- "claude-opus-4-8": 1_000_000,
179
- "claude-opus-4-7": 1_000_000,
180
- // Claude 4.6 (Feb 2026) — 1M context window
181
- "claude-opus-4-6": 1_000_000,
182
- "claude-sonnet-4-6": 1_000_000,
183
- // Claude 4.5
184
- "claude-opus-4-5-20251101": 200_000,
185
- "claude-sonnet-4-5-20250929": 200_000,
186
- "claude-haiku-4-5-20251001": 200_000,
187
- // Claude 4.x
188
- "claude-opus-4-1-20250805": 200_000,
189
- "claude-opus-4-20250514": 200_000,
190
- "claude-sonnet-4-20250514": 200_000,
191
- // Claude 3.x
192
- "claude-3-7-sonnet-20250219": 200_000,
193
- "claude-3-5-sonnet-20241022": 200_000,
194
- "claude-3-5-haiku-20241022": 200_000,
195
- "claude-3-opus-20240229": 200_000,
196
- "claude-3-sonnet-20240229": 200_000,
197
- "claude-3-haiku-20240307": 200_000,
198
- },
199
- openai: {
200
- _default: 128_000,
201
- // GPT-6 family (Sep 2026) — 1.05M context, per
202
- // developers.openai.com/api/docs/models
203
- "gpt-6-astra": 1_050_000,
204
- "gpt-6-sol": 1_050_000,
205
- "gpt-6-luna": 1_050_000,
206
- // GPT-5.4 family — 1.05M context
207
- "gpt-5.4": 1_050_000,
208
- "gpt-5.4-mini": 400_000,
209
- "gpt-5.4-nano": 400_000,
210
- "gpt-5.4-pro": 1_050_000,
211
- // GPT-5.x family — 400K context
212
- "gpt-5.3-codex": 400_000,
213
- "gpt-5.2": 400_000,
214
- "gpt-5.2-pro": 400_000,
215
- "gpt-5.2-codex": 400_000,
216
- "gpt-5.2-chat-latest": 128_000,
217
- "gpt-5.1": 400_000,
218
- "gpt-5.1-codex": 400_000,
219
- "gpt-5.1-codex-max": 400_000,
220
- "gpt-5.1-codex-mini": 400_000,
221
- "gpt-5.1-chat-latest": 128_000,
222
- "gpt-5": 400_000,
223
- "gpt-5-mini": 400_000,
224
- "gpt-5-nano": 400_000,
225
- "gpt-5-pro": 400_000,
226
- "gpt-5-codex": 400_000,
227
- "gpt-5-chat-latest": 128_000,
228
- // GPT Open Source
229
- "gpt-oss-120b": 128_000,
230
- "gpt-oss-20b": 128_000,
231
- // GPT-4.1 family — 1M context
232
- "gpt-4.1": 1_047_576,
233
- "gpt-4.1-mini": 1_047_576,
234
- "gpt-4.1-nano": 1_047_576,
235
- // GPT-4o
236
- "gpt-4o": 128_000,
237
- "gpt-4o-mini": 128_000,
238
- // O-series reasoning — 200K context
239
- o1: 200_000,
240
- "o1-mini": 128_000,
241
- "o1-pro": 200_000,
242
- o3: 200_000,
243
- "o3-mini": 200_000,
244
- "o3-pro": 200_000,
245
- "o4-mini": 200_000,
246
- // Legacy
247
- "gpt-4-turbo": 128_000,
248
- "gpt-4": 8_192,
249
- "gpt-3.5-turbo": 16_385,
250
- },
251
- "google-ai": {
252
- _default: 1_048_576,
253
- // Gemini 3.1 Series (all require -preview suffix)
254
- "gemini-3.1-pro-preview": 1_048_576,
255
- "gemini-3.1-flash-lite-preview": 1_048_576,
256
- "gemini-3.1-flash-image-preview": 1_048_576,
257
- "gemini-3.1-pro-preview-customtools": 1_048_576,
258
- // Gemini 3 Series
259
- "gemini-3-flash-preview": 1_048_576,
260
- "gemini-3-pro-image-preview": 65_536,
261
- /** @deprecated SHUT DOWN March 9, 2026. Migrate to gemini-3.1-pro-preview. */
262
- "gemini-3-pro-preview": 1_048_576,
263
- "gemini-2.5-pro": 1_048_576,
264
- "gemini-2.5-flash": 1_048_576,
265
- "gemini-2.5-flash-lite": 1_048_576,
266
- "gemini-2.5-flash-image": 32_768,
267
- "gemini-2.0-flash": 1_048_576,
268
- "gemini-1.5-pro": 2_097_152,
269
- "gemini-1.5-flash": 1_048_576,
270
- },
271
- vertex: {
272
- _default: 1_048_576,
273
- // Claude on Vertex
274
- "claude-opus-5-5": 1_000_000,
275
- "claude-sonnet-5-5": 1_000_000,
276
- "claude-fable-5-1": 1_000_000,
277
- "claude-sonnet-5": 1_000_000,
278
- // Placed before the 200K `claude-opus-4` prefix key below: the lookup takes
279
- // the first prefix that matches, so a dated `claude-opus-4-8@...` id would
280
- // otherwise land on 200K.
281
- "claude-opus-5": 1_000_000,
282
- "claude-fable-5": 1_000_000,
283
- "claude-opus-4-8": 1_000_000,
284
- "claude-opus-4-7": 1_000_000,
285
- "claude-opus-4-6": 1_000_000,
286
- "claude-sonnet-4-6": 1_000_000,
287
- "claude-sonnet-4-5": 200_000,
288
- "claude-opus-4-5": 200_000,
289
- "claude-haiku-4-5": 200_000,
290
- "claude-sonnet-4": 200_000,
291
- "claude-sonnet-4-20250514": 200_000,
292
- "claude-opus-4-20250514": 200_000,
293
- "claude-opus-4": 200_000,
294
- // Catch-all for UNKNOWN Claude models on Vertex (prefix match runs after
295
- // the specific keys above). Without this, an unlisted Claude model falls
296
- // to the Gemini-shaped _default (1,048,576) — ABOVE Anthropic's real 1M
297
- // API cap — so the pre-dispatch budget check and the in-loop context
298
- // guard both under-guard it (the claude-sonnet-5 1,005,647-token 400s).
299
- // 200K is the conservative Anthropic floor; list real models explicitly.
300
- "claude-": 200_000,
301
- // Gemini 3.1 on Vertex (all require -preview suffix)
302
- "gemini-3.1-pro-preview": 1_048_576,
303
- "gemini-3.1-flash-lite-preview": 1_048_576,
304
- "gemini-3.1-flash-image-preview": 1_048_576,
305
- "gemini-3.1-pro-preview-customtools": 1_048_576,
306
- // Gemini 3 on Vertex
307
- "gemini-3-flash-preview": 1_048_576,
308
- "gemini-3-pro-image-preview": 65_536,
309
- /** @deprecated SHUT DOWN March 9, 2026. Migrate to gemini-3.1-pro-preview. */
310
- "gemini-3-pro-preview": 1_048_576,
311
- // Gemini 2.x on Vertex
312
- "gemini-2.5-pro": 1_048_576,
313
- "gemini-2.5-flash": 1_048_576,
314
- "gemini-2.0-flash": 1_048_576,
315
- "gemini-1.5-pro": 2_097_152,
316
- "gemini-1.5-flash": 1_048_576,
317
- },
318
- bedrock: {
319
- _default: 200_000,
320
- // Claude 5.5 / 5.1 (Sep 2026)
321
- "anthropic.claude-opus-5-5": 1_000_000,
322
- "anthropic.claude-sonnet-5-5": 1_000_000,
323
- "anthropic.claude-fable-5-1": 1_000_000,
324
- // Claude 4.6
325
- "anthropic.claude-opus-4-6-v1": 1_000_000,
326
- "anthropic.claude-sonnet-4-6": 1_000_000,
327
- // Claude 4.5
328
- "anthropic.claude-opus-4-5-20251101-v1:0": 200_000,
329
- "anthropic.claude-sonnet-4-5-20250929-v1:0": 200_000,
330
- "anthropic.claude-haiku-4-5-20251001-v1:0": 200_000,
331
- // Claude 4.1 / 4 — the AWS Bedrock model cards state 200K tokens
332
- "anthropic.claude-opus-4-1-20250805-v1:0": 200_000,
333
- "anthropic.claude-sonnet-4-20250514-v1:0": 200_000,
334
- // Claude legacy. AWS lists no model card for 3.7 Sonnet; 200K is the window
335
- // of the same model in the Anthropic manifest. The `us.` id is its
336
- // cross-region inference profile, the form tokens.ts keys its output cap by.
337
- "anthropic.claude-3-7-sonnet-20250219-v1:0": 200_000,
338
- "us.anthropic.claude-3-7-sonnet-20250219-v1:0": 200_000,
339
- "anthropic.claude-3-5-sonnet-20241022-v1:0": 200_000,
340
- "anthropic.claude-3-5-haiku-20241022-v1:0": 200_000,
341
- "anthropic.claude-3-opus-20240229-v1:0": 200_000,
342
- "anthropic.claude-3-sonnet-20240229-v1:0": 200_000,
343
- "anthropic.claude-3-haiku-20240307-v1:0": 200_000,
344
- // Amazon Nova
345
- "amazon.nova-pro-v1:0": 300_000,
346
- "amazon.nova-lite-v1:0": 300_000,
347
- "amazon.nova-2-lite-v1:0": 1_000_000,
348
- // Writer
349
- "writer.palmyra-x5-v1:0": 1_000_000,
350
- "writer.palmyra-x4-v1:0": 128_000,
351
- // NVIDIA
352
- "nvidia.nemotron-nano-3-30b": 256_000,
353
- },
354
- azure: {
355
- _default: 128_000,
356
- // GPT-6 family (Sep 2026) — 1.05M context, per
357
- // learn.microsoft.com/azure/ai-foundry/openai/concepts/models
358
- "gpt-6-astra": 1_050_000,
359
- "gpt-6-sol": 1_050_000,
360
- "gpt-6-luna": 1_050_000,
361
- // GPT-5.6 / GPT-5.5 — Azure-only as of Sep 2026, same 1.05M context
362
- "gpt-5.6-sol": 1_050_000,
363
- "gpt-5.6-terra": 1_050_000,
364
- "gpt-5.6-luna": 1_050_000,
365
- "gpt-5.5": 1_050_000,
366
- // GPT-5.4
367
- "gpt-5.4": 1_050_000,
368
- "gpt-5.4-mini": 400_000,
369
- "gpt-5.4-nano": 400_000,
370
- "gpt-5.4-pro": 1_050_000,
371
- // GPT-5.x
372
- "gpt-5.2": 400_000,
373
- "gpt-5.2-pro": 400_000,
374
- "gpt-5.2-codex": 400_000,
375
- "gpt-5.1": 400_000,
376
- "gpt-5": 400_000,
377
- "gpt-5-mini": 400_000,
378
- // GPT-4.1
379
- "gpt-4.1": 1_047_576,
380
- "gpt-4.1-mini": 1_047_576,
381
- // GPT-4o
382
- "gpt-4o": 128_000,
383
- "gpt-4o-mini": 128_000,
384
- // O-series
385
- o3: 200_000,
386
- "o3-mini": 200_000,
387
- "o4-mini": 200_000,
388
- // Legacy
389
- "gpt-4-turbo": 128_000,
390
- "gpt-4": 8_192,
391
- },
392
- ollama: {
393
- _default: 128_000,
394
- },
395
- litellm: {
396
- _default: 128_000,
397
- },
398
- huggingface: {
399
- _default: 32_000,
400
- },
401
- sagemaker: {
402
- _default: 128_000,
403
- // NVIDIA Nemotron 3 Nano (February 2026) — 1M context
404
- "nvidia-nemotron-3-nano-30b": 1_000_000,
405
- // Qwen3 VL — 32K context
406
- "qwen3-vl-8b-instruct": 32_768,
407
- },
110
+ ...LIMITS.contextWindows,
408
111
  ...CATALOG_CONTEXT_WINDOWS,
409
112
  };
410
113
  /**
@@ -420,25 +123,7 @@ export const MODEL_CONTEXT_WINDOWS = {
420
123
  * The keys here are the result of stripping non-alpha characters, so
421
124
  * `lm-studio` -> `lmstudio`, `nvidia-nim` -> `nvidianim`, `llama.cpp` -> `llamacpp`.
422
125
  */
423
- const PROVIDER_ALIAS_MAP = {
424
- // Both spellings resolve to `google-ai`, the ONLY key this table holds for
425
- // AI Studio. `google-ai-studio` was never a key, so every realistic spelling
426
- // ("googleAiStudio" from the native client, "google-ai-studio", "googleai")
427
- // missed the table and fell back to DEFAULT_CONTEXT_WINDOW — reporting
428
- // 128K for a 1,048,576-token Gemini. That understated the loop-guard budget
429
- // by ~8x, so AI Studio agent loops reclaimed tool history that still fitted
430
- // comfortably. `google-ai` itself only resolved via the raw-provider
431
- // fallback below, which the normalized lookup now covers directly.
432
- aws: "bedrock",
433
- googleaistudio: "google-ai",
434
- googleai: "google-ai",
435
- lmstudio: "lm-studio",
436
- llamacpp: "llamacpp",
437
- nvidianim: "nvidia-nim",
438
- nim: "nvidia-nim",
439
- nvidia: "nvidia-nim",
440
- deepseek: "deepseek",
441
- };
126
+ const PROVIDER_ALIAS_MAP = LIMITS.providerAliases;
442
127
  function normalizeProviderForLookup(provider) {
443
128
  const stripped = provider.toLowerCase().replace(/[^a-z]/g, "");
444
129
  // On alias miss, return the *stripped* key — not the raw input — so case /
@@ -516,6 +516,7 @@ export declare enum OllamaModels {
516
516
  MISTRAL_SMALL_LATEST = "mistral-small:latest",
517
517
  MISTRAL_NEMO_LATEST = "mistral-nemo:latest",
518
518
  MISTRAL_LARGE_LATEST = "mistral-large:latest",
519
+ GEMMA4_E2B = "gemma4:e2b",
519
520
  GEMMA3_LATEST = "gemma3:latest",
520
521
  GEMMA2_2B = "gemma2:2b",
521
522
  GEMMA2_9B = "gemma2:9b",
@@ -575,7 +575,7 @@ export var GoogleAIModels;
575
575
  export var AnthropicModels;
576
576
  (function (AnthropicModels) {
577
577
  // Claude 5 Series (mid 2026). MODEL_CONTEXT_WINDOWS.anthropic
578
- // (src/lib/constants/contextWindows.ts) already carries the 1M window
578
+ // (src/lib/providers/rules/limits.json) already carries the 1M window
579
579
  // these ids resolve to.
580
580
  AnthropicModels["CLAUDE_OPUS_5"] = "claude-opus-5";
581
581
  AnthropicModels["CLAUDE_SONNET_5"] = "claude-sonnet-5";
@@ -672,6 +672,7 @@ export var OllamaModels;
672
672
  OllamaModels["MISTRAL_NEMO_LATEST"] = "mistral-nemo:latest";
673
673
  OllamaModels["MISTRAL_LARGE_LATEST"] = "mistral-large:latest";
674
674
  // Google Gemma Series - Efficient edge and cloud models
675
+ OllamaModels["GEMMA4_E2B"] = "gemma4:e2b";
675
676
  OllamaModels["GEMMA3_LATEST"] = "gemma3:latest";
676
677
  OllamaModels["GEMMA2_2B"] = "gemma2:2b";
677
678
  OllamaModels["GEMMA2_9B"] = "gemma2:9b";
@@ -18,7 +18,7 @@
18
18
  */
19
19
  import type { AnthropicGuardMessage, LoopGuardPlan } from "../types/index.js";
20
20
  /** Marker left where dropped history used to be. */
21
- export declare const ANTHROPIC_ELISION_NOTE = "[Earlier tool exchanges were removed to fit the context window.]";
21
+ export declare const ANTHROPIC_ELISION_NOTE: string;
22
22
  /**
23
23
  * Text-level preview used for an oversized `tool_result` payload. Exposed so
24
24
  * the caller can apply it to its OWN block type — this module never rebuilds
@@ -20,11 +20,12 @@ import { estimateTokens, TOKENS_PER_MESSAGE, } from "../utils/tokenEstimation.js
20
20
  import { exceedsToolOutputPreviewBudget, generateToolOutputPreview, } from "./toolOutputLimits.js";
21
21
  import { planLoopGuardReclaim } from "./loopGuardCore.js";
22
22
  import { logger } from "../utils/logger.js";
23
+ import { getContextTexts } from "../providers/rules/requestFields.js";
23
24
  /** Preview budget for an old tool output. Matches the other loop guards. */
24
25
  const OLD_TOOL_OUTPUT_PREVIEW_BYTES = 2_048;
25
26
  const OLD_TOOL_OUTPUT_PREVIEW_LINES = 60;
26
27
  /** Marker left where dropped history used to be. */
27
- export const ANTHROPIC_ELISION_NOTE = "[Earlier tool exchanges were removed to fit the context window.]";
28
+ export const ANTHROPIC_ELISION_NOTE = getContextTexts("anthropic").elisionNote;
28
29
  /** Serialize any value to text for estimation. Never throws. */
29
30
  function toText(value) {
30
31
  if (typeof value === "string") {
@@ -11,50 +11,15 @@ import { azureManifest } from "../models/manifests/azure.js";
11
11
  import { mistralManifest } from "../models/manifests/mistral.js";
12
12
  import { ollamaManifest } from "../models/manifests/ollama.js";
13
13
  import { litellmManifest } from "../models/manifests/litellm.js";
14
- // Image Generation Model Identifiers
15
- // Used to detect if a model is an image generation model (not text generation).
14
+ import { getModelList } from "../providers/rules/modelFamilies.js";
15
+ // Image-generation model ids (model-families.json `modelLists`). See
16
+ // `modelListNotes` there for why each group is listed.
16
17
  // `isImageGenerationModel(name)` (below) does boundary-aware matching:
17
18
  // the modelName must equal an entry OR contain an entry followed by a
18
19
  // non-alphanumeric character (`-`, `_`, `:`, `/`, `.`, end-of-string).
19
20
  // This prevents short identifiers like `"V_1"` or `"gpt-image-1"` from
20
21
  // accidentally matching unrelated model names that happen to embed them.
21
- export const IMAGE_GENERATION_MODELS = [
22
- // Gemini image models (Vertex AI, Google AI Studio)
23
- "gemini-3-pro-image-preview",
24
- "gemini-2.5-flash-image",
25
- "gemini-3.1-flash-image-preview",
26
- // Stability AI (direct provider — image-only)
27
- "stable-image-ultra",
28
- "stable-image-core",
29
- "sd3.5-large",
30
- "sd3.5-large-turbo",
31
- "sd3.5-medium",
32
- // Ideogram (direct provider — image-only). API uses model-version
33
- // identifiers like "V_1", "V_1_TURBO", "V_2", "V_2_TURBO", "V_2A",
34
- // "V_2A_TURBO", "V_3". Keep prefixes that won't collide with generic
35
- // text-model names.
36
- "V_1",
37
- "V_1_TURBO",
38
- "V_2",
39
- "V_2_TURBO",
40
- "V_2A",
41
- "V_2A_TURBO",
42
- "V_3",
43
- // Recraft (direct provider — image-only)
44
- "recraftv3",
45
- "recraftv2",
46
- // OpenAI image models (DALL-E + GPT-Image). Substring match keeps
47
- // version variants like "dall-e-3" / "dall-e-2" routed correctly.
48
- "gpt-image-1",
49
- "dall-e-3",
50
- "dall-e-2",
51
- // Replicate-hosted image models (matched on model slug prefix).
52
- // Replicate model slugs are passed through as-is via the LLM
53
- // provider; image-gen models trigger the image-gen path.
54
- "black-forest-labs/flux",
55
- "stability-ai/sdxl",
56
- "stability-ai/stable-diffusion",
57
- ];
22
+ export const IMAGE_GENERATION_MODELS = getModelList("imageGeneration");
58
23
  /**
59
24
  * Boundary-aware test for whether `modelName` represents an image-generation
60
25
  * model.
@@ -88,27 +53,15 @@ export function isImageGenerationModel(modelName) {
88
53
  }
89
54
  // PDF Image Generation Models
90
55
  // Models that support generating images from PDFs
91
- export const PDF_IMAGE_GENERATION_MODELS = [
92
- "gemini-3-pro-image-preview",
93
- "gemini-3.1-flash-image-preview",
94
- ];
56
+ export const PDF_IMAGE_GENERATION_MODELS = getModelList("pdfImageGeneration");
95
57
  // Global Location Models
96
58
  // Models that require global location configuration (uses aiplatform.googleapis.com instead of region-specific endpoints)
97
59
  // Includes Gemini 3.x text and image models, which are only available via the global endpoint on Vertex AI.
98
60
  // IMAGE_GENERATION_MODELS is spread in to keep the two lists from drifting:
99
61
  // any new image-gen model added there is automatically routed to global here.
100
62
  export const GLOBAL_LOCATION_MODELS = [
101
- // Image generation (sourced from IMAGE_GENERATION_MODELS)
102
63
  ...IMAGE_GENERATION_MODELS,
103
- // Gemini 3.1 text models (global-only)
104
- "gemini-3.1-pro-preview",
105
- "gemini-3.1-flash-lite-preview",
106
- "gemini-3.1-pro-preview-customtools",
107
- // Gemini 3 text models (global-only)
108
- "gemini-3-pro-preview",
109
- "gemini-3-pro-preview-11-2025",
110
- "gemini-3-pro-latest",
111
- "gemini-3-flash-preview",
64
+ ...getModelList("vertexGlobalLocationText"),
112
65
  ];
113
66
  // Core AI Generation Defaults
114
67
  export const DEFAULT_MAX_TOKENS = undefined; // Unlimited by default - let providers decide their own limits
@@ -19,6 +19,8 @@
19
19
  import { guardToolExecutor } from "./toolExecutionGuards.js";
20
20
  import { resolveLiveTool } from "../tools/toolDiscovery.js";
21
21
  import { collectStreamChunksIncremental, extractTextFromParts, mapGeminiFinishReason, pushModelResponseToHistory, refreshNativeToolDeclarations, } from "../providers/googleNativeGemini3/utils.js";
22
+ import { getWireUsage, outputWithReasoning, splitIncludedCount, } from "../providers/rules/wireUsage.js";
23
+ const GEMINI_USAGE = getWireUsage("gemini");
22
24
  /**
23
25
  * @description Describes one Gemini request as the request half of a Langfuse generation.
24
26
  * @param provider {string} - Provider name used to price the call.
@@ -251,14 +253,14 @@ export function createGeminiLoopAdapter(config) {
251
253
  // the prompt is not billed as extra tokens, and a thinking token is billed
252
254
  // at the output rate.
253
255
  observedUsage(usage) {
254
- const cached = usage.cacheReadTokens === undefined
255
- ? undefined
256
- : Math.min(usage.cacheReadTokens, usage.inputTokens);
256
+ const split = splitIncludedCount(usage.inputTokens, usage.cacheReadTokens ?? 0);
257
257
  return {
258
258
  ...usage,
259
- inputTokens: Math.max(0, usage.inputTokens - (cached ?? 0)),
260
- outputTokens: usage.outputTokens + (usage.reasoningTokens ?? 0),
261
- ...(cached !== undefined && { cacheReadTokens: cached }),
259
+ inputTokens: split.rest,
260
+ outputTokens: outputWithReasoning(GEMINI_USAGE, usage.outputTokens, usage.reasoningTokens),
261
+ ...(usage.cacheReadTokens !== undefined && {
262
+ cacheReadTokens: split.part,
263
+ }),
262
264
  };
263
265
  },
264
266
  mapFinishReason(rawStopReason, hadToolCallsAtCap) {
@@ -95,24 +95,3 @@ export declare function isSchemaComplexityError(error: unknown): boolean;
95
95
  * degrade to best-effort JSON, not throw.
96
96
  */
97
97
  export declare function isResponseFormatUnsupportedError(error: unknown): boolean;
98
- /**
99
- * True when a provider error indicates the request was rejected because the
100
- * `temperature` parameter is deprecated / unsupported for the model. The newest
101
- * Anthropic models (e.g. claude-opus-4-8, with tools + advanced beta features)
102
- * reject `temperature` — "`temperature` is deprecated for this model." — in
103
- * favour of reasoning-effort controls. Detect this so the call can be retried
104
- * once without `temperature` instead of failing the turn.
105
- */
106
- export declare function isTemperatureDeprecatedError(error: unknown): boolean;
107
- /**
108
- * True when the model is known to reject the `temperature` parameter (the
109
- * reasoning-effort Anthropic models — claude-opus-4-8 and newer — deprecate it
110
- * in favour of effort controls). Used to omit `temperature` proactively so the
111
- * request does not fail-then-retry on every turn: the reactive
112
- * isTemperatureDeprecatedError() retry remains the safety net for any model not
113
- * matched here, but a guaranteed-to-fail first request is pure wasted latency.
114
- *
115
- * Matches opus 4.8+ (4-8, 4-9, 4-10, …) while leaving 4.1/4.5/4.6 and Sonnet/
116
- * Haiku — which still accept `temperature` — untouched.
117
- */
118
- export declare function modelDeprecatesTemperature(modelName: string | undefined): boolean;
@@ -15,6 +15,7 @@
15
15
  * a gate keyed on "any Vertex model" wrongly disables it for the primary
16
16
  * production config and forces fragile hand-parsed JSON.
17
17
  */
18
+ import { matchesErrorSignal } from "../../providers/rules/errorSignals.js";
18
19
  /** True when the provider+model is a Gemini model (the only family with the tools↔schema conflict). */
19
20
  export function isGeminiProvider(providerName, modelName) {
20
21
  if (providerName === "google-ai") {
@@ -66,15 +67,7 @@ export function isToolsSchemaExclusionInForce(providerName, modelName, shouldUse
66
67
  * and retried without structured output instead of failing the call.
67
68
  */
68
69
  export function isToolsSchemaConflictError(error) {
69
- const message = error instanceof Error
70
- ? error.message
71
- : typeof error === "string"
72
- ? error
73
- : "";
74
- return (/cannot be combined with (a )?(tool|function)/i.test(message) ||
75
- /json[\s_-]?(mode|schema|object|output)[^.]{0,60}(tool|function)/i.test(message) ||
76
- /(tool|function)[\s-]?call[^.]{0,60}json[\s_-]?(mode|schema)/i.test(message) ||
77
- /response_format[^.]{0,60}(tool|function)/i.test(message));
70
+ return matchesErrorSignal("toolsSchemaConflict", error);
78
71
  }
79
72
  /**
80
73
  * True when a provider error indicates the request was rejected because the
@@ -95,12 +88,7 @@ export function isToolsSchemaConflictError(error) {
95
88
  * (same flow as isToolsSchemaConflictError).
96
89
  */
97
90
  export function isSchemaComplexityError(error) {
98
- const message = error instanceof Error
99
- ? error.message
100
- : typeof error === "string"
101
- ? error
102
- : "";
103
- return /too many states/i.test(message);
91
+ return matchesErrorSignal("schemaComplexity", error);
104
92
  }
105
93
  /**
106
94
  * True when a provider error indicates the MODEL (not the provider as a
@@ -129,43 +117,5 @@ export function isSchemaComplexityError(error) {
129
117
  * degrade to best-effort JSON, not throw.
130
118
  */
131
119
  export function isResponseFormatUnsupportedError(error) {
132
- const message = error instanceof Error
133
- ? error.message
134
- : typeof error === "string"
135
- ? error
136
- : "";
137
- return (/does not support[^.]{0,80}response[\s_-]?format/i.test(message) ||
138
- /response[\s_-]?format[^.]{0,60}(?:is )?not support/i.test(message) ||
139
- /unsupported response[\s_-]?format/i.test(message));
140
- }
141
- /**
142
- * True when a provider error indicates the request was rejected because the
143
- * `temperature` parameter is deprecated / unsupported for the model. The newest
144
- * Anthropic models (e.g. claude-opus-4-8, with tools + advanced beta features)
145
- * reject `temperature` — "`temperature` is deprecated for this model." — in
146
- * favour of reasoning-effort controls. Detect this so the call can be retried
147
- * once without `temperature` instead of failing the turn.
148
- */
149
- export function isTemperatureDeprecatedError(error) {
150
- const message = error instanceof Error
151
- ? error.message
152
- : typeof error === "string"
153
- ? error
154
- : "";
155
- return /\btemperature\b[^.]{0,40}\b(deprecated|unsupported|not[\s_-]?(supported|allowed))\b/i.test(message);
156
- }
157
- /**
158
- * True when the model is known to reject the `temperature` parameter (the
159
- * reasoning-effort Anthropic models — claude-opus-4-8 and newer — deprecate it
160
- * in favour of effort controls). Used to omit `temperature` proactively so the
161
- * request does not fail-then-retry on every turn: the reactive
162
- * isTemperatureDeprecatedError() retry remains the safety net for any model not
163
- * matched here, but a guaranteed-to-fail first request is pure wasted latency.
164
- *
165
- * Matches opus 4.8+ (4-8, 4-9, 4-10, …) while leaving 4.1/4.5/4.6 and Sonnet/
166
- * Haiku — which still accept `temperature` — untouched.
167
- */
168
- export function modelDeprecatesTemperature(modelName) {
169
- const m = (modelName ?? "").toLowerCase();
170
- return /opus[-_.]?4[-_.]?(?:[89]|\d{2,})\b/.test(m);
120
+ return matchesErrorSignal("responseFormatUnsupported", error);
171
121
  }
@@ -1,6 +1,7 @@
1
1
  import { AIProviderName } from "../constants/enums.js";
2
- import { GoogleAIModels, OpenAIModels, AnthropicModels, VertexModels, OllamaModels, LiteLLMModels, NvidiaNimModels, OpenRouterModels, CohereModels, VoyageModels, TypeSafeModels, PerplexityDeciderModels, CloudflareClefModels, JinaModels, StabilityModels, IdeogramModels, RecraftModels, ReplicateModels, } from "../constants/enums.js";
2
+ import { GoogleAIModels, OpenAIModels, AnthropicModels, VertexModels, LiteLLMModels, NvidiaNimModels, OpenRouterModels, CohereModels, VoyageModels, TypeSafeModels, PerplexityDeciderModels, CloudflareClefModels, JinaModels, StabilityModels, IdeogramModels, RecraftModels, ReplicateModels, } from "../constants/enums.js";
3
3
  import { API_KEY_FORMATS } from "../utils/providerConfig.js";
4
+ import { getDefaultModel } from "../providers/rules/fallbackModel.js";
4
5
  import { getCatalogJsonEntries, getDecideCatalogEntries, catalogCredentialsKey, catalogEnvVar, } from "../providers/catalog/loader.js";
5
6
  import { DEFAULT_INFERENCE_KINDS } from "../types/index.js";
6
7
  /**
@@ -206,7 +207,7 @@ const HAND_DESCRIPTORS = [
206
207
  model: "OLLAMA_MODEL",
207
208
  optional: true,
208
209
  },
209
- defaultModel: OllamaModels.LLAMA3_2_LATEST,
210
+ defaultModel: getDefaultModel("ollama"),
210
211
  toolSupport: "model-dependent",
211
212
  localRuntime: true,
212
213
  healthCheck: "models-probe",