71 lines
2.1 KiB
TypeScript
71 lines
2.1 KiB
TypeScript
/**
|
|
* Model resolution and handling utilities
|
|
*/
|
|
import modelsData from "../models.json";
|
|
|
|
export const models = modelsData;
|
|
|
|
/**
|
|
* Resolve a model by ID or handle
|
|
* @param modelIdentifier - Can be either a model ID (e.g., "opus") or a full handle (e.g., "anthropic/claude-opus-4-1-20250805")
|
|
* @returns The model handle if found, null otherwise
|
|
*/
|
|
export function resolveModel(modelIdentifier: string): string | null {
|
|
const byId = models.find((m) => m.id === modelIdentifier);
|
|
if (byId) return byId.handle;
|
|
|
|
const byHandle = models.find((m) => m.handle === modelIdentifier);
|
|
if (byHandle) return byHandle.handle;
|
|
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* Get the default model handle
|
|
*/
|
|
export function getDefaultModel(): string {
|
|
const defaultModel = models.find((m) => m.isDefault);
|
|
if (defaultModel) return defaultModel.handle;
|
|
|
|
const firstModel = models[0];
|
|
if (!firstModel) {
|
|
throw new Error("No models available in models.json");
|
|
}
|
|
return firstModel.handle;
|
|
}
|
|
|
|
/**
|
|
* Format available models for error messages
|
|
*/
|
|
export function formatAvailableModels(): string {
|
|
return models.map((m) => ` ${m.id.padEnd(20)} ${m.handle}`).join("\n");
|
|
}
|
|
|
|
/**
|
|
* Get model info by ID or handle
|
|
* @param modelIdentifier - Can be either a model ID (e.g., "opus") or a full handle (e.g., "anthropic/claude-opus-4-1-20250805")
|
|
* @returns The model info if found, null otherwise
|
|
*/
|
|
export function getModelInfo(modelIdentifier: string) {
|
|
const byId = models.find((m) => m.id === modelIdentifier);
|
|
if (byId) return byId;
|
|
|
|
const byHandle = models.find((m) => m.handle === modelIdentifier);
|
|
if (byHandle) return byHandle;
|
|
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* Get updateArgs for a model by ID or handle
|
|
* @param modelIdentifier - Can be either a model ID (e.g., "opus") or a full handle (e.g., "anthropic/claude-opus-4-1-20250805")
|
|
* @returns The updateArgs if found, undefined otherwise
|
|
*/
|
|
export function getModelUpdateArgs(
|
|
modelIdentifier?: string,
|
|
): Record<string, unknown> | undefined {
|
|
if (!modelIdentifier) return undefined;
|
|
const modelInfo = getModelInfo(modelIdentifier);
|
|
return modelInfo?.updateArgs;
|
|
}
|