🌙 feat: Moonshot Provider Support (#11621)

*  feat: Add Moonshot Provider Support

- Updated the `isKnownCustomProvider` function to include `Providers.MOONSHOT` in the list of recognized custom providers.
- Enhanced the `providerConfigMap` to initialize `MOONSHOT` with the custom initialization function.
- Introduced `MoonshotIcon` component for visual representation in the UI, integrated into the `UnknownIcon` component.
- Updated various files across the API and client to support the new `MOONSHOT` provider, including configuration and response handling.

This update expands the capabilities of the application by integrating support for the Moonshot provider, enhancing both backend and frontend functionalities.

*  feat: Add Moonshot/Kimi Model Pricing and Tests

- Introduced new pricing configurations for Moonshot and Kimi models in `tx.js`, including various model variations and their respective prompt and completion values.
- Expanded unit tests in `tx.spec.js` and `tokens.spec.js` to validate pricing and token limits for the newly added Moonshot/Kimi models, ensuring accurate calculations and handling of model variations.
- Updated utility functions to support the new model structures and ensure compatibility with existing functionalities.

This update enhances the pricing model capabilities and improves test coverage for the Moonshot/Kimi integration.

*  feat: Enhance Token Pricing Documentation and Configuration

- Added comprehensive documentation for token pricing configuration in `tx.js` and `tokens.ts`, emphasizing the importance of key ordering for pattern matching.
- Clarified the process for defining base and specific patterns to ensure accurate pricing retrieval based on model names.
- Improved code comments to guide future additions of model families, enhancing maintainability and understanding of the pricing structure.

This update improves the clarity and usability of the token pricing configuration, facilitating better integration and future enhancements.

* chore: import order

* chore: linting
This commit is contained in:
Danny Avila 2026-02-04 10:53:57 +01:00 committed by GitHub
parent 56a1b28293
commit f34052c6bb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 492 additions and 40 deletions

View file

@ -132,6 +132,7 @@ export function overrideDeferLoadingForDiscoveredTools(
const customProviders = new Set([
Providers.XAI,
Providers.DEEPSEEK,
Providers.MOONSHOT,
Providers.OPENROUTER,
KnownEndpoints.ollama,
]);

View file

@ -21,7 +21,7 @@ export type InitializeFn = (params: BaseInitializeParams) => Promise<InitializeR
* @returns True if the provider is a known custom provider, false otherwise
*/
export function isKnownCustomProvider(provider?: string): boolean {
return [Providers.XAI, Providers.DEEPSEEK, Providers.OPENROUTER].includes(
return [Providers.XAI, Providers.DEEPSEEK, Providers.OPENROUTER, Providers.MOONSHOT].includes(
(provider?.toLowerCase() ?? '') as Providers,
);
}
@ -32,6 +32,7 @@ export function isKnownCustomProvider(provider?: string): boolean {
export const providerConfigMap: Record<string, InitializeFn> = {
[Providers.XAI]: initializeCustom,
[Providers.DEEPSEEK]: initializeCustom,
[Providers.MOONSHOT]: initializeCustom,
[Providers.OPENROUTER]: initializeCustom,
[EModelEndpoint.openAI]: initializeOpenAI,
[EModelEndpoint.google]: initializeGoogle,

View file

@ -2,6 +2,34 @@ import z from 'zod';
import { EModelEndpoint } from 'librechat-data-provider';
import type { EndpointTokenConfig, TokenConfig } from '~/types';
/**
* Model Token Configuration Maps
*
* IMPORTANT: Key Ordering for Pattern Matching
* ============================================
* The `findMatchingPattern` function iterates through object keys in REVERSE order
* (last-defined keys are checked first) and uses `modelName.includes(key)` for matching.
*
* This means:
* 1. BASE PATTERNS must be defined FIRST (e.g., "kimi", "moonshot")
* 2. SPECIFIC PATTERNS must be defined AFTER their base patterns (e.g., "kimi-k2", "kimi-k2.5")
*
* Example ordering for Kimi models:
* kimi: 262144, // Base pattern - checked last
* 'kimi-k2': 262144, // More specific - checked before "kimi"
* 'kimi-k2.5': 262144, // Most specific - checked first
*
* Why this matters:
* - Model name "kimi-k2.5" contains both "kimi" and "kimi-k2" as substrings
* - If "kimi" were checked first, it would incorrectly match "kimi-k2.5"
* - By defining specific patterns AFTER base patterns, they're checked first in reverse iteration
*
* When adding new model families:
* 1. Define the base/generic pattern first
* 2. Define increasingly specific patterns after
* 3. Ensure no pattern is a substring of another that should match differently
*/
const openAIModels = {
'o4-mini': 200000,
'o3-mini': 195000, // -5000 from max
@ -134,6 +162,42 @@ const deepseekModels = {
'deepseek.r1': 128000,
};
const moonshotModels = {
// Base patterns (check last due to reverse iteration)
kimi: 262144,
moonshot: 131072,
// kimi-k2 series (specific patterns)
'kimi-latest': 128000,
'kimi-k2': 262144,
'kimi-k2.5': 262144,
'kimi-k2-turbo': 262144,
'kimi-k2-turbo-preview': 262144,
'kimi-k2-0905': 262144,
'kimi-k2-0905-preview': 262144,
'kimi-k2-0711': 131072,
'kimi-k2-0711-preview': 131072,
'kimi-k2-thinking': 262144,
'kimi-k2-thinking-turbo': 262144,
// moonshot-v1 series (specific patterns)
'moonshot-v1': 131072,
'moonshot-v1-auto': 131072,
'moonshot-v1-8k': 8192,
'moonshot-v1-8k-vision': 8192,
'moonshot-v1-8k-vision-preview': 8192,
'moonshot-v1-32k': 32768,
'moonshot-v1-32k-vision': 32768,
'moonshot-v1-32k-vision-preview': 32768,
'moonshot-v1-128k': 131072,
'moonshot-v1-128k-vision': 131072,
'moonshot-v1-128k-vision-preview': 131072,
// Bedrock moonshot models
'moonshot.kimi': 262144,
'moonshot.kimi-k2': 262144,
'moonshot.kimi-k2.5': 262144,
'moonshot.kimi-k2-thinking': 262144,
'moonshot.kimi-k2-0711': 131072,
};
const metaModels = {
// Basic patterns
llama3: 8000,
@ -248,6 +312,7 @@ const bedrockModels = {
...mistralModels,
...cohereModels,
...deepseekModels,
...moonshotModels,
...metaModels,
...ai21Models,
...amazonModels,
@ -279,8 +344,6 @@ const aggregateModels = {
...bedrockModels,
...xAIModels,
...qwenModels,
// misc.
kimi: 131000,
// GPT-OSS
'gpt-oss': 131000,
'gpt-oss:20b': 131000,