All files / src/models/adapters index.ts

94.44% Statements 51/54
60% Branches 3/5
23.07% Functions 3/13
93.18% Lines 41/44

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 8310x           10x 10x 10x 10x 10x 10x 10x 10x 10x   10x     10x           10x 10x 10x 10x 10x 10x 10x 10x 10x     10x 10x 10x   10x     10x                       10x 10x 10x   10x 400x 400x 354x     46x 198x 46x   46x           46x 46x     10x 9x    
import {
  ModelAdapter,
  BaseModelAdapter,
  DEFAULT_TEMPERATURE,
  ModelAdapterCapabilityContract,
} from "./base";
import { DeepSeekAdapter } from "./deepseek";
import { KimiAdapter } from "./kimi";
import { GlmAdapter } from "./glm";
import { NemotronAdapter } from "./nemotron";
import { NemotronLightningAdapter } from "./nemotron-lightning";
import { MinimaxAdapter } from "./minimax";
import { StepfunAdapter } from "./stepfun";
import { InklingAdapter } from "./inkling";
import { MuseGlimmerAdapter } from "./muse-glimmer";
 
export {
  ModelAdapter,
  NvidiaModelRequestProfile,
  BaseModelAdapter,
  ModelAdapterCapabilityContract,
  ReasoningParameterFormat,
  ToolCallProtocol,
  ReasoningRouting,
} from "./base";
export { DeepSeekAdapter } from "./deepseek";
export { KimiAdapter } from "./kimi";
export { GlmAdapter } from "./glm";
export { NemotronAdapter } from "./nemotron";
export { NemotronLightningAdapter } from "./nemotron-lightning";
export { MinimaxAdapter } from "./minimax";
export { StepfunAdapter } from "./stepfun";
export { InklingAdapter } from "./inkling";
export { MuseGlimmerAdapter } from "./muse-glimmer";
 
class DefaultAdapter extends BaseModelAdapter {
  readonly idPattern = /.*/;
  readonly defaultTemperature = DEFAULT_TEMPERATURE;
  readonly toolTemperature = 0.3;
  readonly toolSystemMessage =
    "You are an expert AI programming assistant. Provide correct, concise, production-ready code. Prefer simple solutions. Analyze the problem before coding. When tools are available, answer with concise user-facing text or a valid tool call. Do not include disclaimers or apologies.";
}
 
const ADAPTERS: ModelAdapter[] = [
  new DeepSeekAdapter(),
  new KimiAdapter(),
  new GlmAdapter(),
  new NemotronLightningAdapter(),
  new NemotronAdapter(),
  new MinimaxAdapter(),
  new StepfunAdapter(),
  new InklingAdapter(),
  new MuseGlimmerAdapter(),
];
 
const DEFAULT_ADAPTER = new DefaultAdapter();
const adapterCache = new Map<string, ModelAdapter>();
const MAX_ADAPTER_CACHE_SIZE = 64;
 
export function getModelAdapter(modelId: string): ModelAdapter {
  const cached = adapterCache.get(modelId);
  if (cached) {
    return cached;
  }
 
  const normalizedModelId = modelId.toLowerCase();
  const matched = ADAPTERS.find((adapter) => adapter.matches(normalizedModelId));
  const result = matched ?? DEFAULT_ADAPTER;
 
  Iif (adapterCache.size >= MAX_ADAPTER_CACHE_SIZE) {
    const firstKey = adapterCache.keys().next().value;
    Iif (firstKey !== undefined) {
      adapterCache.delete(firstKey);
    }
  }
  adapterCache.set(modelId, result);
  return result;
}
 
export function getModelCapabilityContract(modelId: string): ModelAdapterCapabilityContract {
  return getModelAdapter(modelId).getCapabilityContract();
}