- Introduced Effort enum and ThinkingConfig metadata for per-model reasoning capabilities with min/max effort levels. - Migrated thinking level API from string-based ThinkingLevel to structured Effort enum across agent and AI packages. - Added model-thinking module with effort mapping, policy application, and semantic versioning utilities for provider-specific thinking modes. - Removed supportsXhigh() function and replaced effort clamping with model-aware validation using ThinkingConfig metadata. - Expanded models.json with thinking configuration objects for 50+ models including Claude, Gemini, and OpenAI variants. - Added Python analysis scripts for edit tool usage patterns and tool invocation stream processing.
57 lines
2.2 KiB
TypeScript
57 lines
2.2 KiB
TypeScript
import { enrichModelThinking } from "./model-thinking";
|
|
import MODELS from "./models.json" with { type: "json" };
|
|
import type { Api, KnownProvider, Model, Usage } from "./types";
|
|
|
|
/**
|
|
* Static bundled model registry loaded from `models.json`.
|
|
*
|
|
* This module intentionally exposes compile-time defaults only.
|
|
* It does not include runtime discovery, models.dev overlays, or on-disk cache state.
|
|
*
|
|
* For runtime-aware resolution, use `createModelManager()` / `resolveProviderModels()`.
|
|
*/
|
|
const modelRegistry: Map<string, Map<string, Model<Api>>> = new Map();
|
|
for (const [provider, models] of Object.entries(MODELS)) {
|
|
const providerModels = new Map<string, Model<Api>>();
|
|
for (const [id, model] of Object.entries(models)) {
|
|
providerModels.set(id, enrichModelThinking(model as Model<Api>));
|
|
}
|
|
modelRegistry.set(provider, providerModels);
|
|
}
|
|
|
|
export type GeneratedProvider = keyof typeof MODELS;
|
|
|
|
export function getBundledModel(provider: GeneratedProvider, modelId: string): Model<Api> {
|
|
const providerModels = modelRegistry.get(provider);
|
|
return providerModels?.get(modelId) as Model<Api>;
|
|
}
|
|
|
|
export function getBundledProviders(): KnownProvider[] {
|
|
return Array.from(modelRegistry.keys()) as KnownProvider[];
|
|
}
|
|
|
|
export function getBundledModels(provider: GeneratedProvider): Model<Api>[] {
|
|
const models = modelRegistry.get(provider);
|
|
return models ? (Array.from(models.values()) as Model<Api>[]) : [];
|
|
}
|
|
|
|
export function calculateCost<TApi extends Api>(model: Model<TApi>, usage: Usage): Usage["cost"] {
|
|
usage.cost.input = (model.cost.input / 1000000) * usage.input;
|
|
usage.cost.output = (model.cost.output / 1000000) * usage.output;
|
|
usage.cost.cacheRead = (model.cost.cacheRead / 1000000) * usage.cacheRead;
|
|
usage.cost.cacheWrite = (model.cost.cacheWrite / 1000000) * usage.cacheWrite;
|
|
usage.cost.total = usage.cost.input + usage.cost.output + usage.cost.cacheRead + usage.cost.cacheWrite;
|
|
return usage.cost;
|
|
}
|
|
/**
|
|
* Check if two models are equal by comparing both their id and provider.
|
|
* Returns false if either model is null or undefined.
|
|
*/
|
|
export function modelsAreEqual<TApi extends Api>(
|
|
a: Model<TApi> | null | undefined,
|
|
b: Model<TApi> | null | undefined,
|
|
): boolean {
|
|
if (!a || !b) return false;
|
|
return a.id === b.id && a.provider === b.provider;
|
|
}
|