@juspay/neurolink
Version:
The pipe layer of an AI nervous system: one interface connecting provider neurons to your application, across three inference types — generate, stream and decide. `decide` returns typed, calibrated judgements from a non-generative model (~400ms, ~$0.00002
48 lines (47 loc) • 1.98 kB
JavaScript
/**
* Named model-id families from `model-families.json`. Each family is a list
* of patterns, case-insensitive unless the family is listed in
* `caseSensitiveFamilies`; gateway ids carry arbitrary prefixes and suffixes
* (`vertex_ai/claude-sonnet-5@20260203`), so exact ids can't cover them.
*/
import { getProviderRules } from "./registry.js";
const compiled = new Map();
/** A family's compiled patterns; throws when the family is missing. */
export function getModelFamilyPatterns(name) {
let family = compiled.get(name);
if (!family) {
const rules = getProviderRules("model-families");
const sources = rules.modelFamilies?.[name];
if (!sources) {
throw new Error(`Provider rules file "model-families.json" has no modelFamilies.${name}`);
}
const flags = rules.caseSensitiveFamilies?.includes(name) ? "" : "i";
family = sources.map((source) => new RegExp(source, flags));
compiled.set(name, family);
}
return family;
}
/** Whether a model id matches any pattern of a family. */
export function inModelFamily(name, modelId) {
return getModelFamilyPatterns(name).some((pattern) => pattern.test(modelId));
}
const compiledRules = new WeakMap();
/** The first rule whose case-insensitive `match` pattern matches the model id. */
export function firstModelRule(rules, modelId) {
return rules.find((rule) => {
let pattern = compiledRules.get(rule);
if (!pattern) {
pattern = new RegExp(rule.match, "i");
compiledRules.set(rule, pattern);
}
return pattern.test(modelId);
});
}
/** A copy of a named list of exact model ids from model-families.json; throws when missing. */
export function getModelList(name) {
const list = getProviderRules("model-families").modelLists?.[name];
if (!list) {
throw new Error(`Provider rules file "model-families.json" has no modelLists.${name}`);
}
return [...list];
}