Files
openmaic/OpenMAIC/lib/ai/model-aliases.ts
2026-08-16 14:58:47 +08:00

24 lines
993 B
TypeScript

const MODEL_ID_ALIASES: ReadonlyMap<string, string> = new Map([['openai:gpt-5.6-sol', 'gpt-5.6']]);
/** Resolve aliases used for local catalog, settings, capability, and usage lookups. */
export function getCanonicalModelId(providerId: string, modelId: string): string {
return MODEL_ID_ALIASES.get(`${providerId}:${modelId}`) ?? modelId;
}
export function modelIdsMatch(providerId: string, left: string, right: string): boolean {
return getCanonicalModelId(providerId, left) === getCanonicalModelId(providerId, right);
}
/** Find a model using canonical IDs without changing the model ID sent on the wire. */
export function findModelById<T extends { id: string }>(
providerId: string,
models: readonly T[] | undefined,
modelId: string,
): T | undefined {
const canonicalModelId = getCanonicalModelId(providerId, modelId);
return (
models?.find((model) => model.id === canonicalModelId) ??
models?.find((model) => modelIdsMatch(providerId, model.id, modelId))
);
}