import assert from 'node:assert/strict'; import { readFileSync } from 'node:fs'; import { fileURLToPath } from 'node:url'; import test from 'node:test'; import { isPiggyModelId, piggyDefaultModelId, piggyInferenceBaseUrl, piggyModelCatalogue, } from '../src/agent/models'; const modelsJson = JSON.parse( readFileSync(fileURLToPath(new URL('../src/agent/models.json', import.meta.url)), 'utf8'), ) as { providers: Record; }; test('every id in the picker is one the provider actually registers', () => { // The whole point of a curated shortlist is that nothing in it 404s. The // catalogue and models.json are the same five models by construction, and // this is what keeps them that way when someone adds a sixth to one file. const registered = (modelsJson.providers['prime-inference']?.models ?? []).map( (model) => model.id, ); const offered = piggyModelCatalogue().map((option) => option.id); assert.deepEqual(offered, registered); assert.ok(offered.length >= 4, 'the picker should offer a real choice, not just the default'); for (const id of offered) { // Prime Inference ids are always provider-qualified. A bare model name is // the classic copy-and-paste error and it fails as a 404 at the endpoint. assert.match(id, /^[a-zA-Z0-9._-]+\/[a-zA-Z0-9._-]+$/, `${id} is not provider-qualified`); assert.ok(isPiggyModelId(id)); } }); test('the default is in the catalogue and there is exactly one of it', () => { const catalogue = piggyModelCatalogue(); const defaults = catalogue.filter((option) => option.isDefault); assert.equal(defaults.length, 1); assert.equal(defaults[0]?.id, piggyDefaultModelId()); assert.equal(piggyDefaultModelId(), 'nvidia/nemotron-3-nano-30b-a3b'); assert.equal(isPiggyModelId('nvidia/nemotron-3-nano-30b-a3b'), true); assert.equal(isPiggyModelId('nvidia/nemotron-9000'), false); }); test('the picker can price and size every choice', () => { for (const option of piggyModelCatalogue()) { // Dollars per million tokens, NOT cents: the field names say so, and this // is the one money field in PIG that is not an integer of cents. A price // of 0 here would render as "free" in the picker, which no model is. assert.ok(option.costPerMTokIn > 0, `${option.id} has no input price`); assert.ok(option.costPerMTokOut > 0, `${option.id} has no output price`); assert.ok(option.costPerMTokOut >= option.costPerMTokIn, `${option.id} prices output too low`); assert.ok(option.contextWindow >= 100_000, `${option.id} is too small for a CRM transcript`); assert.ok(option.label.length > 0); assert.ok((option.hint ?? '').length > 0, `${option.id} would render as a blank picker row`); } }); test('the default is the cheapest thing on offer', () => { // The panel is docked on every page, so the default is the price of a typo. // If a costlier model ever becomes the default it should be a deliberate act // that fails this test first. const catalogue = piggyModelCatalogue(); const cheapest = [...catalogue].sort((a, b) => a.costPerMTokIn - b.costPerMTokIn)[0]; assert.equal(cheapest?.id, piggyDefaultModelId()); }); test('the catalogue cannot be reordered by a caller', () => { // It is serialised to the browser on every session; one sort() at a call // site would reorder the picker for every other session in the process. const first = piggyModelCatalogue(); first.reverse(); assert.equal(piggyModelCatalogue()[0]?.id, piggyDefaultModelId()); }); test('the provider points at Prime Inference', () => { assert.equal(piggyInferenceBaseUrl(), 'https://api.pinference.ai/api/v1'); });