Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.
JavaScript 3d-generationai-agentsanimationavatardigital-humangenerative-aiglbgltfimage-to-3dllmmcpmcp-servermodel-context-protocolsolanatext-to-3dthreejsweb-componentswebglwebxrx402
import { describe, it, expect } from 'vitest';
import {
MODEL_CATALOG,
modelSupportsTools,
isModelModerationGated,
isPaidModel,
usableModels,
DEFAULT_FREE_MODEL,
DEFAULT_PROVIDER_ORDER,
PROVIDER_MODEL_DEFAULTS,
OPENROUTER_SIBLINGS,
ANON_PROVIDER_LIST,
MAX_FALLBACK_ATTEMPTS,
TOTAL_BUDGET_MS,
} from '../api/_lib/chat-models.js';
const GRANITE = 'ibm-granite/granite-4.1-8b';
// A catalogued model that is deliberately never auto-selected.
const GATED = 'claude-mythos-5';
// Models removed from the catalog because they will never succeed: OpenRouter
// 404 "No endpoints found" / no tool-capable endpoint. They must never appear
// in any routing list.
const DEAD_ROUTES = [
'mistralai/mistral-7b-instruct:free',
'meta-llama/llama-3.2-3b-instruct:free',
// The OpenRouter non-free 'openai/gpt-oss-120b' used to sit here, but the
// same string is Groq's live id for GPT-OSS 120B (catalogued under groq since
// Groq retired Llama), so it is a real route now, not a dead one.
// Retired by OpenRouter in July 2026. Every one of these was live in the
// catalog when its endpoint disappeared, which silently killed the whole
// OpenRouter free lane and took the /chat app down with it.
'openai/gpt-oss-120b:free',
'meta-llama/llama-3.3-70b-instruct:free',
'nousresearch/hermes-3-llama-3.1-405b:free',
'google/gemma-3-27b-it:free',
'qwen/qwen3-coder:free',
];
describe('chat-models catalog', () => {
it('does not carry permanently-broken routes', () => {
for (const dead of DEAD_ROUTES) {
expect(MODEL_CATALOG[dead], `${dead} should be absent`).toBeUndefined();
}
});
it('every catalogued model declares a provider and tool capability', () => {
for (const [id, meta] of Object.entries(MODEL_CATALOG)) {
expect(meta.provider, `${id} provider`).toBeTruthy();
expect(typeof meta.tools, `${id} tools`).toBe('boolean');
}
});
it('marks a restricted-access model moderation-gated and tool-capable', () => {
expect(isModelModerationGated(GATED)).toBe(true);
expect(modelSupportsTools(GATED)).toBe(true);
});
});
describe('usableModels (route selector)', () => {
const ALL = Object.keys(MODEL_CATALOG);
it('a tool-required request never returns a non-tool model', () => {
// Inject a hypothetical non-tool model id and confirm it is filtered.
const candidates = [...ALL, 'meta-llama/llama-3.2-3b-instruct:free'];
const picked = usableModels(candidates, { requireTools: true });
for (const m of picked) {
expect(modelSupportsTools(m), `${m} must support tools`).toBe(true);
}
// The unknown/non-tool id is dropped.
expect(picked).not.toContain('meta-llama/llama-3.2-3b-instruct:free');
});
it('excludes moderation-gated models from auto selection by default', () => {
const picked = usableModels(ALL, { requireTools: true });
expect(picked).not.toContain(GATED);
});
it('includes gated models only when explicitly allowed', () => {
const picked = usableModels([GATED], { allowGated: true });
expect(picked).toContain(GATED);
});
it('drops unknown models entirely', () => {
expect(usableModels(['totally-made-up-model'])).toEqual([]);
});
});
describe('free-first ordering', () => {
it('every free provider ranks ahead of every paid provider', () => {
// Free providers (Groq, OpenRouter, NVIDIA NIM, SambaNova, Mistral,
// Z.AI) always lead; the paid keys (Anthropic, OpenAI, Grok) are
// last-resort backstops only reached when every free lane has failed.
expect(DEFAULT_PROVIDER_ORDER).toEqual(['groq', 'openrouter', 'nvidia', 'sambanova', 'mistral', 'zai', 'anthropic', 'openai', 'grok']);
const free = ['groq', 'openrouter', 'nvidia', 'sambanova', 'mistral', 'zai'];
const paid = ['anthropic', 'openai', 'grok'];
for (const f of free) {
for (const p of paid) {
expect(DEFAULT_PROVIDER_ORDER.indexOf(f), `${f} before ${p}`).toBeLessThan(DEFAULT_PROVIDER_ORDER.indexOf(p));
}
}
});
it('does not lead the free tier with the moderation-gated model', () => {
expect(DEFAULT_FREE_MODEL).not.toBe(GATED);
expect(isModelModerationGated(DEFAULT_FREE_MODEL)).toBe(false);
expect(modelSupportsTools(DEFAULT_FREE_MODEL)).toBe(true);
});
it('OpenRouter siblings are all live, tool-capable, non-gated', () => {
for (const m of OPENROUTER_SIBLINGS) {
expect(MODEL_CATALOG[m], `${m} catalogued`).toBeDefined();
expect(modelSupportsTools(m)).toBe(true);
expect(isModelModerationGated(m)).toBe(false);
}
});
it('every provider default is a real, usable, tool-capable model', () => {
for (const [provider, model] of Object.entries(PROVIDER_MODEL_DEFAULTS)) {
expect(MODEL_CATALOG[model], `${provider} default ${model}`).toBeDefined();
expect(MODEL_CATALOG[model].provider).toBe(provider);
expect(modelSupportsTools(model)).toBe(true);
}
});
it('anonymous callers are clamped to free tiers plus the credits-funded Vertex Gemini anchor', () => {
expect(ANON_PROVIDER_LIST).toEqual(['groq', 'openrouter', 'nvidia', 'sambanova', 'mistral', 'zai', 'vertex-gemini']);
// The free third-party lanes lead; the funded Vertex anchor is the
// last-resort rung so an anon caller never 503s just because every free
// tier is rate-limited at once.
expect(ANON_PROVIDER_LIST[ANON_PROVIDER_LIST.length - 1]).toBe('vertex-gemini');
// No paid third-party provider is ever exposed to anon callers.
expect(ANON_PROVIDER_LIST).not.toContain('openai');
expect(ANON_PROVIDER_LIST).not.toContain('anthropic');
expect(ANON_PROVIDER_LIST).not.toContain('vertex-anthropic');
});
});
describe('paid/BYOK model gating (OpenRouter Granite)', () => {
it('the Granite lane is catalogued, tool-capable, and flagged paid', () => {
expect(MODEL_CATALOG[GRANITE], 'granite catalogued').toBeDefined();
expect(MODEL_CATALOG[GRANITE].provider).toBe('openrouter');
expect(modelSupportsTools(GRANITE)).toBe(true);
expect(isPaidModel(GRANITE)).toBe(true);
});
it('isPaidModel is false for free and unknown models', () => {
expect(isPaidModel(DEFAULT_FREE_MODEL)).toBe(false);
expect(isPaidModel('llama-3.3-70b-versatile')).toBe(false);
expect(isPaidModel('totally-made-up-model')).toBe(false);
});
it('the paid model is never in an auto-selected free path', () => {
// Not a per-provider default, not an OpenRouter sibling, not the free model.
expect(Object.values(PROVIDER_MODEL_DEFAULTS)).not.toContain(GRANITE);
expect(OPENROUTER_SIBLINGS).not.toContain(GRANITE);
expect(DEFAULT_FREE_MODEL).not.toBe(GRANITE);
});
it('no free-provider default is a paid model (anon can never auto-hit one)', () => {
for (const provider of ANON_PROVIDER_LIST) {
const model = PROVIDER_MODEL_DEFAULTS[provider];
expect(isPaidModel(model), `${provider} default ${model} must be free`).toBe(false);
}
});
});
describe('retired NVIDIA NIM functions', () => {
// NIM still lists nemotron-3-super-120b-a12b but answers 404 "Function not found"
// on completions (observed 2026-10-24), which left anonymous chat with no
// working provider once Groq throttled. The direct NIM default must be a live model.
it('the nvidia default is not the retired super-120b function', () => {
expect(PROVIDER_MODEL_DEFAULTS.nvidia).not.toBe('nvidia/nemotron-3-super-120b-a12b');
});
});
describe('bounded fallback chain', () => {
it('caps attempts and wall-clock to prevent provider churn', () => {
expect(MAX_FALLBACK_ATTEMPTS).toBeGreaterThanOrEqual(2);
expect(MAX_FALLBACK_ATTEMPTS).toBeLessThanOrEqual(4);
// Budget must leave streaming headroom under the 60s function limit.
expect(TOTAL_BUDGET_MS).toBeGreaterThan(0);
expect(TOTAL_BUDGET_MS).toBeLessThan(60_000);
});
});
describe('anonModelAllowed', () => {
it('allows no explicit model, catalogued free models and OpenRouter :free ids', async () => {
const { anonModelAllowed } = await import('../api/_lib/chat-models.js');
expect(anonModelAllowed(undefined)).toBe(true);
expect(anonModelAllowed('llama-3.3-70b')).toBe(true);
expect(anonModelAllowed('example-vendor/example-model:free')).toBe(true);
});
it('rejects catalogued paid models and uncatalogued ids that would reach the platform key', async () => {
const { anonModelAllowed } = await import('../api/_lib/chat-models.js');
expect(anonModelAllowed(GRANITE)).toBe(false);
expect(anonModelAllowed('example-vendor/uncatalogued-paid-model')).toBe(false);
});
});